Is it possible to require authorization on the OpenCart information page and ONLY on the information page?

I see many extensions that force you to register before viewing products, etc., but I want to restrict access to a specific page that I created by creating a new information page. Is it possible? I am also not very good at php, so please tell me which files I need to edit and where. Thanks in advance.

+4
source share
1 answer

Try adding this at the top of controller / information / information.php right after declaring the index () function and replace {ID} with the page ID you want to password protect (you can get the ID from the URL or SEO URL from the admin section).

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

I assumed that the info page is not used using SSL in the above example, you will need to change it if there is one.

If you are confused as to where this should go, take a look at controller / account / account.php - I took this code and changed it for specific information p.

+5
source

Source: https://habr.com/ru/post/1446955/


All Articles