How to Set Category Page as Home Page in Prestashop

时光怂恿深爱的人放手 提交于 2019-12-03 09:59:15

问题


I am having http://example.com/index.php as my home page. My Category Page URL is http://example.com/index.php?id_category=10&controller=category

Now, I need to redirect my homepage to Category Page. I tried in Preferences > SEO & URL's > Set Shop URL > Base URI as index.php?id_category=10&controller=category

Now, the page is redirecting to my Category Url but the page is not opening. the URL is showing like this http://example.com/index.php?id_category=10&controller=category/index.php?


回答1:


You are doing it the wrong way. Do it as followed:

A) Easy but not recommended Way:

1) Open Controllers/IndexController.php

2) Modify function initContent as 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 Way:

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

class IndexController extends IndexControllerCore 
{

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

    }
}

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

Notes :

1) The above code is to give you idea, it may or may not work. Please do adjustment according to your needs.

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

Hope this will help.




回答2:


It's my way:

  1. Create file override/controllers/front/IndexController.php
  2. Writing:

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

  1. save
  2. remove file cache/class_index.php
  3. profit!


来源:https://stackoverflow.com/questions/19012800/how-to-set-category-page-as-home-page-in-prestashop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!