Jump to content

[SOLVED] Getting id_parent in a subcategory


Recommended Posts

First things first - I started using Prestashop only a few weeks ago and have found it to be really good so kudos to the developers! :)

The shop is coming together nicely with new themes, modules, etc. except for one thing that I can't figure out - either because I am tired or can't find it! How do you get the id_parent when you on a subcategory page (when you are not using the tree thing)?

I would like to assign "selected" class to a parent category - this works if you go to a product detail page (product is in a category), e.g.

You are in Home > Laptops > Acer > Acer something - then I would like the Laptops button to be highlighted rather than Acer link (subcategory).

* Accessories
* iphone
* iPods
* Laptops
o Acer
o Toshiba

As far as I can see, the issue is the $currentCategoryId variable

{if $node.id == $currentCategoryId} class="selected"{/if}



Unfortunately, I am struggling to figure out the code in blockcategories.php -particularly line 128 and variable is passed with $smarty->assign('currentCategoryId', intval($_GET['id_category'])); so I guess I need to replace $_GET['id_category'] with something but I just can't figure it out!

Many thanks in advance!

Link to comment
Share on other sites

here is how the path thing works for product page for instance:

in product.php you have:
'path' => ((isset($category->id) AND $category->id) ? Tools::getFullPath(intval($category->id), $product->name) : Tools::getFullPath(intval($product->id_default_category), $product->name))

then check Tools->getFullPath and Tools->getPath

you are able to customize the output in the way you like it

Link to comment
Share on other sites

I also attach another rough idea - a "nice-to-have". so basically, I would be happy to keep the following line in blockcategories.php:

$smarty->assign('currentCategoryId', intval($_GET['id_category']));



... and maybe do another line or two just for the purpose of menu styles? e.g.

$smarty->assign('parentCategoryId', intval(id_parent_from_database));



I don't know how to in the case of Prestashop unfortunately so any advice, etc. would be greatly appreciated! :)

15066_q9dfK4Z5RdxIlajAjB2E_t

Link to comment
Share on other sites

ok here you go:
here is the demo: I won't keep it online for too long in this form
http://demo.ecommy.com/prestashop/category.php?id_category=4

1. modules/blockcategories/blockcategories.php
after:

$smarty->assign('currentCategoryId', intval($_GET['id_category']));


add:

$currentCategoryId = intval($_GET['id_category']);



after:

$smarty->assign('currentCategoryId', intval($cookie->last_visited_category));


add:

$currentCategoryId = intval($cookie->last_visited_category);



above:

$smarty->assign('blockCategTree', $blockCategTree);


add:

        
$topCategoryId = Category::getTopCategory($currentCategoryId, $resultIds);
$smarty->assign('topCategoryId', $topCategoryId);





2. modules/blockcategories/category-tree-branch.tpl
replace:

{$node.name|escape:htmlall:'UTF-8'}


with:

{$node.name|escape:htmlall:'UTF-8'}




3. themes/prestashop/css/global.css
replace:

div#categories_block_left ul.tree a.selected{
   color: #488c40;
   font-weight: bold;
}


with:

div#categories_block_left ul.tree a.selected{
   font-weight: bold;
}

div#categories_block_left ul.tree a#selected2{
   color: #488c40;
   font-weight: bold;
}



4. themes/prestashop/classes/Category.php
after:

    
public function updateGroup($list)
{
       $this->cleanGroups();
       if ($list AND sizeof($list))
           $this->addGroups($list);
}


add:

    
public function getTopCategory($selected, $cats) {
   if(intval($cats[$selected]['id_parent']) > 1) {
     return Category::getTopCategory($cats[$selected]['id_parent'], $cats);
   }
   else {
       return $selected;
   }
}

Link to comment
Share on other sites

  • 7 months later...
  • 1 year later...

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...