仅向已登录和特定客户组显示信息页面


Display information page to only logged in and particular customer group

我在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'));
    }
}

代码来源:是否可能要求登录OpenCart信息页面,而仅登录信息页面?

更新您的第二个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。

祝你今天愉快:)!!