Jump to content

Member only pages using the CMS Prestashop 1.6


cinny2205
 Share

Recommended Posts

Hi,

 

you can override the init() function of your CmsController.php file by adding something like:

if (!$this->context->customer->isLogged())
   Tools::redirect('the page you want');

or send this logged state from cmsController to your template by smarty

 

$this->smarty->assign(array(
'logged' => $this->context->customer->isLogged()
));

 

and add a condition in your template cms.tpl

{if $logged}
display cms 
{else}
display custom message
{/if}

if you that works for few cms page, add a condition on cms page id

  • Like 1

Share this post


Link to post
Share on other sites

  • 4 weeks later...

Hi!

 

I have done how fred-vinepresta suggested in his posts. So all my cms pages now are accessible only for logged users. I would like that only one page has restriced access while all over the other ones are public. If, for example, my cms page which has to be accessible only for logged users has id=6, what do i have to do?

Share this post


Link to post
Share on other sites

  • 3 months later...
  • 3 years later...

I have to do this also to my store with only one CMS page, and this was the solution for me.

In prestashop 1.6 modify the file CmsController.php just above this line:

parent::initContent();

I add this code

if (!$this->context->customer->isLogged() && $this->cms->id == 6) {
        Tools::redirect('index.php?controller=authentication');
        }

the first line is a conditional to check if the customer is not logged and if the page CMS is they required is the one I need to protect for only customer registered in my case is the page 6.

in cas the conditions is true, will be redirected to the login page.

Comparing with the code made more above for other was not working because is missing the double "&&" and the "$this->cms->" and also the open and close { } for the if conditional, with this everything is working fine.

Edited by wilebaldo (see edit history)

Share this post


Link to post
Share on other sites

  • 6 months later...
On 12/6/2018 at 12:15 AM, wilebaldo said:

I add this code

if (!$this->context->customer->isLogged() && $this->cms->id == 6) {
        Tools::redirect('index.php?controller=authentication');
        }

 

Hi there!

Is there a way for the customer to automatically go back to cms 6 page after authentification ?

I tried somthing like that but it failed...

Tools::redirect('index.php?controller=authentication?back=/content/29-my-page/')
Edited by Pat_07
syntax error (see edit history)

Share this post


Link to post
Share on other sites

I also tried the syntax below, but once again after authentification it led me to home page

 
			{Tools::redirect('index.php?controller=authentication?back=$link->getCMSLink(9)')}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More