Jump to content

Show Category on front page


Recommended Posts

I want to show category on the front-page(home)

 

I try:

$cc=ControllerFactory::getController('CategoryController');

$cc->category = new Category(8,_USER_ID_LANG_);

$cc->process();

$cc->displayContent();

but get Cannot access protected property CategoryController::$category

 

I also tried to set cookie

$_POST["id_category"]=8;

$cc=ControllerFactory::getController('CategoryController');

$cc->preProcess();

$cc->process();

$cc->displayContent();

but get redirect to directory#8

 

So, how can show a category on the fron page?

Link to comment
Share on other sites

I don't have time right now to try this but it sounds like fun so I'll write what I would try :D

 

If I understand correctly - you are using PS 1.4.x and you want the usual "page" for category 8 to be displayed as the homepage of the store?

 

The home page is the index controller, so that's what you would need to override. One strategy could be to override the

IndexController

and instead of extending the "Core" version of that controller, extend it from

CategoryControlerCore

instead. The main issue would be that this latter class assumes a category id has been POSTed (as in your code above). You would then likely need to override the preProcess() member function to:

 

a) Set the category id in the _POST array, and

B) Prevent Prestashop from rewriting the url to a category one.

 

class IndexController extends CategoryController
{

 public function preProcess()
 {
   // We'll be naughty and fake the category
   $_POST['id_category'] = 8;
   $this->category = new Category((int)Tools::getValue('id_category'), self::$cookie->id_lang);

   FrontController::preProcess();

   if((int)(Configuration::get('PS_REWRITING_SETTINGS')))
           if ($id_category = (int)Tools::getValue('id_category'))
           {
               $rewrite_infos = Category::getUrlRewriteInformations((int)$id_category);

               $default_rewrite = array();
               foreach ($rewrite_infos AS $infos)
                   $default_rewrite[$infos['id_lang']] = self::$link->getCategoryLink((int)$id_category, $infos['link_rewrite'], $infos['id_lang']);

               self::$smarty->assign('lang_rewrite_urls', $default_rewrite);
           }
 }

}

 

I've a feeling it would get messy, but the above would be the most elegant way (in my opinion) of doing it. Worth a shot at the very least ;)

 

The second approach would be to write your own custom

IndexController

class that's based loosely on the

CategoryController

class, but dedicated to only displaying the top-level of a particular category.

 

Paul

Link to comment
Share on other sites

The forum is broken, so I can't edit the above. The first mention of CategoryControllerCore is misspelled.

 

and in the code it should read:

 

[color=#000088]class[/color][color=#000000] [/color][color=#660066]IndexController[/color][color=#000000] [/color][color=#000088]extends[/color][color=#000000] [/color][color=#660066]CategoryControllerCore[/color]
[color=#660066]

[/color]

Link to comment
Share on other sites

Thank you, Paul C , I think you've posted very usefull information. Because of lack of time, I use this yet:

I change CategoryController::$category to public and print category with this function:

function showCat($id)

{

$_POST["id_category"]=$id;

$cc=ControllerFactory::getController('CategoryController');

$cc->category=new Category((int)$id,_USER_ID_LANG_);

$cc->process();

$cc->displayContent();

}

Link to comment
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...