Jump to content

How to Set Category Page as Home Page?


Recommended Posts

Hi experts !

 

I would like to set category page as home page exactly as it was described here 

 

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

 

The problem is (probably) that the solution is from 2013 and it is not working on Prestashop 1.6

 

In my prestashop 1.6 file  controllers/front/IndexController.php looks like that

class IndexControllerCore extends FrontController
{
    public $php_self = 'index';

    /**
     * Assign template vars related to page content
     * @see FrontController::initContent()
     */
    public function initContent()
    {
        parent::initContent();
        $this->addJS(_THEME_JS_DIR_.'index.js');

        $this->context->smarty->assign(array('HOOK_HOME' => Hook::exec('displayHome'),
            'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'),
            'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent')
        ));
        $this->setTemplate(_PS_THEME_DIR_.'index.tpl');
    }
}

Please help and thanks in advance :)

Maria

Share this post


Link to post
Share on other sites

This seems to work in the index controller, as in the first example on stack exchange.  So it should work in an override class as well.

 

Tools::redirect($this->context->link->getCategoryLink( <your-category-id ));

Share this post


Link to post
Share on other sites

This seems to work in the index controller, as in the first example on stack exchange.  So it should work in an override class as well.

 

Tools::redirect($this->context->link->getCategoryLink( <your-category-id ));

 

Thanks for the help, however it's not working for me it seems. I have the following code now, what am I missing? I cleared cache through the BO as well, but index just gives me the same page as before. It's in override as well, so that doesn't seem to be the issue.

	public function initContent()
	{
	   parent::initContent();
	   Tools::redirect($this->context->link->getCategoryLink( <3 ));
	   $this->context->smarty->assign('HOOK_HOME', Hook::exec('displayHome'));
	   $this->setTemplate(_PS_THEME_DIR_.'index.tpl');
	}

Any suggestions? Would be much appreciated!

Share this post


Link to post
Share on other sites

the variable for the category link should be an integer only and the code after the Tools::redirect shouldn't be there, though I doubt it is being executed.

 

You should also check that the override is being called, you have to delete the class_index.php in the cache directory file, I believe, but I don't use overrides. There are other posts about getting overrides working on this forum.

Share this post


Link to post
Share on other sites

Thanks for the quick reply, I solved it with a solution from Vekia (another topic, lost it)

 

Replace the content of the IndexController.php with the following. Works up to 1.6.1.4 at least:

class IndexControllerCore extends CategoryController
{
 public $php_self = 'index';
/**
 * Assign template vars related to page content
 * @see FrontController::initContent()
 */
 public function init(){
 $_GET['id_category']=3;
 parent::init();
 }
 public function initContent()
 {
 parent::initContent();
 }
}

Change the number '3' to whichever category ID you'd like to redirect.

Share this post


Link to post
Share on other sites

Thanks !   Your solutions works  but right now I have adress of my homepage "www.myshopname.com/en/3-women" rather then simple "www.myshopname.com". Is there a possibility to set homepage to category 3 but preserving at the same time original simple homepage adress ? 

Share this post


Link to post
Share on other sites

Hmm, I would assume it's possible with a htaccess rewrite, but I have no idea how that works. Would be neat if someone could figure that out for us :)

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
×
×
  • Create New...

Important Information

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