Post by growlbox » Sun May 27, 2012 5:19 pm

Hi guys,

I was wondering if there's a way that i could make some information pages restricted to members only?

New member

Posts

Joined
Sat Jun 11, 2011 6:16 pm

Post by Avvici » Sun May 27, 2012 6:28 pm

Easy to do. Just set up an isLogged check on the page you want it and it will redirect anyone to login if they try and view it. Thing is, the information pages are displayed from an array so you would have to use a conditional before hand.
v1.5.2.1+
So lets see open catalog/controller/information/information.php and find this:

Code: Select all

if (isset($this->request->get['information_id'])) {
			$information_id = $this->request->get['information_id'];
		} else {
			$information_id = 0;
		}
Just under it add this:

Code: Select all

if($information_id == 1){
			
			if (!$this->customer->isLogged()) {
	  	$this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' .  $information_id);
	  
	  		$this->redirect($this->url->link('account/login', '', 'SSL'));
    	} 
		}
This checks for an information ID of 1. If they are not logged it will make them login, then redirect them to the information page they were trying to view. To find the info id's just turn your SEO url off and navigate to the info page you want. Look at the browser bar to see the ID in the URL. Tested and works

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by growlbox » Wed May 30, 2012 2:31 am

Avvici, I would like to thank you for your help. I did not expect any response. I will use your code and see if it works.

New member

Posts

Joined
Sat Jun 11, 2011 6:16 pm

Post by discostu » Tue May 07, 2013 1:50 pm

Hi there, I'm wondering how I can redirect the user to the account/login page with an error message that appears

"you must be logged in to view that page"

Cheers, Stu

Newbie

Posts

Joined
Wed Apr 17, 2013 1:25 pm

Post by Avvici » Tue May 07, 2013 7:58 pm

Easy to do as well. You need only to set the error session and it will display on the login page once they get to it. For example:

Code: Select all

    if($information_id == 1){
             
             if (!$this->customer->isLogged()) {
            $this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' .  $information_id);
         $this->session->data['error'] = "You must login!";
               $this->redirect($this->url->link('account/login', '', 'SSL'));
           }
          } 
And now open up account/login.php and add this code the public function index()

Code: Select all

if (isset($this->session->data['error'])) {
            $this->data['warning'] = $this->session->data['error'];
    
            unset($this->session->data['error']);
        } else {
            $this->data['warning'] = '';
        }      
 

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC
Who is online

Users browsing this forum: No registered users and 28 guests