How to Make Some CMS Pages Private in PrestaShop - Top Programming Questions and Answers?

Posted On: Sep 14, 2018

Categories: Shopping Carts & Platforms

With the passage of time, shopping experience from online store is changing drastically. There was a time when there are only a few shopping carts with just a few options but now the trend is completely changed. The biggest example is that even social media like Facebook is allowing merchants to sell their products. While shopping carts are allowing their users to edit the source code and make it according to the own choice. So merchants are using several techniques to get the maximum advantage out of it.

The idea that is now trending in the market is to hide the shop from general public i.e. they will only see a login page and they need to give the credentials to get into it. Some other merchants allow access to only certain pages of the store and blocking the rest. The idea is very useful for those shop owners who have a strong customer base with limited inventory. So they are allowing access to buy from the store to only their VIP users.

To make the shops private, merchants always search to find a way to get their store private. This features in not available by default and users have to either pay for a private shop module and add some tweaks himself to get it done.

In below, we have listed some problems and their solutions related to Private Shop.

Question No. 1: Hi, I want to write my own private shop module. The requirements is that the visitors will be redirected to the login page when they want to visit the website.

Answer: The solution is very simple and you don’t need to write up a new module. Just some core modification will help;

Goto
classescontrollerFrontController.php

Find the function
public function init()

Paste the below mentioned code after
parent::init();


if (!$this->context->customer->isLogged() && $this->php_self != 'authentication' && $this->php_self != 'password')
Tools::redirect('index.php?controller=authentication?back=my-account'); 

Question No. 2: Hello! I want to make a new module for private hide shop. I have experience of developing module. So I just need some hints on this.

Answer: You can use header hook that will be displayed on sign in/sign up page. Also have to use some other scripts to hide all the other section of website.

Question No. 3: I have a PrestaShop store with version 1.6. I want to category X that should be only accessible to customer group Z. When I implemented it, and tried to go into class without login, it gave me the error. Is it possible to show a login form for this, so that it will not give me the error?

Answer: You can do it by modifying the categorycontroller.php file, no third parties needed.

 

Locate this

              if(!$this->category->checkAccess($this->context->customer->id))

              {

                      header('HTTP/1.1 403 Forbidden');

                      header('Status: 403 Forbidden');

                      $this->errors[]=Tools::displayError('You do not have access to this category.');

                      $this->customer_access =false;

              }

And change it to:

if(!$this->category->checkAccess($this->context->customer->id))

              {

                      Tools::redirect($this->context->link->getPageLink('authentication'));

              }v

Question No. 4: Hi, I want to hide a CMS page from viewing by the visitors. How it is possible?

Answer: you can use simple if condition in cms.tpl file, 

something like

 

{if $logged}

CONTENTS OF CMS.TPL HERE

{/if}

add another if condition

 

instead of {$cms->content} use this:

{if $smarty.get.id_cms==40}{if $logged}    {$cms->content}{else}    {l s='access forbidden, please log in first to view this page'}{/if}{else}   {$cms->content}{/if}

After doing this, recompile theme (advance parameters > performance tab in Back office)

Question No. 5: I want to create a sign up and login page at the start of my store so that only the registered and logged in customers can get into the store.

Answer: There are two solutions for this. Paid and Free. Check that which one can help you.

Paid: Install a Private shop module on your store that will allow these feature to you.

Free: The other way is to create customer groups. All the people can see your products but they can’t view the price or order the product until they are added to that allowed customer group. Although this solution can’t hide the products. So paid solution will be better.

For more information on this, go here; Tab: customers -> groups and customers -> customers.

Note: These questions are answered by top community developers and do not reflect FMEModules.