How to set category page as homepage in Prestashop

I have http://example.com/index.php as my homepage. My category page URL: http://example.com/index.php?id_category=10&controller=category

Now I need to redirect my homepage to the category page. I tried in Preferences> SEO & URL> Set Store URL> Base URI as index.php? Id_category = 10 & controller = category

Now the page is redirected to my category URL, but the page does not open. Does the url look something like this http://example.com/index.php?id_category=10&controller=category/index.php ?

+7
php prestashop
source share
2 answers

You are doing it wrong. Do it as follows:

A) Easy, but not recommended. Way:

1) Open Controllers / IndexController.php

2) Change the initContent function as shown below:

public function initContent() { parent::initContent(); Tools::redirect('index.php?id_category=10&controller=category'); $this->context->smarty->assign('HOOK_HOME', Hook::exec('displayHome')); $this->setTemplate(_PS_THEME_DIR_.'index.tpl'); } 

B) Recommended method:

1) Copy controllers /IndexController.php to override / Controllers / folder 2) Open the copied file and edit as shown below:

 class IndexController extends IndexControllerCore { public function initContent() { Tools::redirect('index.php?id_category=10&controller=category'); } } 

3) Save the file and go to the cache folder. Locate class_index.php if there is one, then delete it. Then check the site if it works fine.

Notes:

1) The above code should give you an idea, it may or may not work. Please customize according to your needs.

2) In the latest versions of Prestashop, all classes are indexed in the class_index.php file. therefore, if you override the controller or class, it may not work until you delete this file. When a new request is made to the server, PS will automatically restore this file for you.

Hope this helps.

+17
source share

This is my way:

  • Create file override / controllers / front / IndexController.php
  • Record:
     class IndexControllerCore extends FrontController {
       public function initContent ()
         {
           Tools :: redirect ('index.php? Id_category = 3 & controller = category');
         }
       }

  1. save
  2. delete cache / class_index.php file
  3. profit!
0
source share

All Articles