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

Posted On: Sep 14, 2018

Categories: Shopping Carts & Platforms

Tags: prestashop , module , private shop

With time, the shopping experience from online stores is changing drastically. There was a time when there were only a few shopping carts with just a few options, but now the trend has completely changed. The biggest example is that even social media like Facebook is allowing merchants to sell their products. Shopping carts allow their users to edit the source code and make it according to their 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 the 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 block 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 stores private. These features are not available by default and users have to either pay for a private shop module or add some tweaks themselves to get it done.

Private shop

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 create a categorise X, which should be only accessible to customer group Z. When I implemented it and tried to go into class without logging in, it gave me an 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'));

              }

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

Answer: You can use a simple if condition in the 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 signup 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 which one can help you.

Paid: Install a Private shop module on your store that will allow these features 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 a 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 FME Modules.

Conclusion

Starting with PrestaShop FME modules can significantly boost your e-commerce store. By installing these modules, you can customize your store, enhance customer experience, and streamline your operations. Whether it's setting up private shops or integrating new features, PrestaShop FME modules make the process seamless and efficient.

Ready to take your PrestaShop store to the next level? Begin with FME modules and transform your online business today!