2013-12-14 56 views
-1

我發現此以下代碼在stackoverflow,它使訪問信息頁面只登錄客戶,這是非常有用的。我想對此做一個改進。信息頁面只能由特定的客戶羣訪問。顯示信息頁面只登錄和特定的客戶羣

if (isset($this->request->get['information_id']) && $this->request->get['information_id'] == '{ID}') 
{ 
    //If the information_id is provided and it matches the ID you wish to protect 
    if (!$this->customer->isLogged()) { 
     //If the customer is not logged in already, redirect them to the login page 
     //Use $this->session->data['redirect'] to redirect them back to this page after logging in 
     $this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' . $this->request->get['information_id']); 
     //Do the redirect 
     $this->redirect($this->url->link('account/login', '', 'SSL')); 
    } 
} 

代碼來源:Is it possible to require a login for an OpenCart Information page, and ONLY the information page?

回答

0

更新你的第二個if條件如下圖所示:

if (isset($this->request->get['information_id']) && $this->request->get['information_id'] == '{ID}') { 

    if (!$this->customer->isLogged() || $this->customer->getCustomerGroupId() != 1) { //where '1' is your customer groupid for which you want to give access.. 

     $this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' . $this->request->get['information_id']); 
     $this->redirect($this->url->link('account/login', '', 'SSL')); 
    } 
} 

$this->customer->getCustomerGroupId() - 返回你的客戶組ID。

祝你有美好的一天:)!

+0

工作得很好。感謝這兩位編碼人員。 – Asif

+0

出錯了。重定向是好的,但向所有客戶羣顯示。幫幫我!!! – Asif

+0

if(!$ this-> customer-> isLogged()'||'$ this-> customer-> getCustomerGroupId()!= 1){ - 更新..請找到我更新的答案。早些時候我使用'AND'而不是'OR'。 –