2013-12-14 9 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() - возвращает вашу группу идентификатор клиента.

Имейте приятный день :) !!

+0

Работал очень хорошо. Благодаря кодам. – Asif

+0

Что-то не так. Перенаправление одобрено, но отображается для всей группы клиентов. Помогите!!! – Asif

+0

if (! $ This-> customer-> isLogged() '||' $ this-> customer-> getCustomerGroupId()! = 1) {- обновлено .. найди мой обновленный ответ. раньше я использовал 'AND' вместо' OR'. –

 Смежные вопросы

  • Нет связанных вопросов^_^