Jump to content

[SOLVED] Getting parent category id


Recommended Posts

Hi everybody,

I had no problems to get the id of the current category, in order to show a specific background on each category. But i would like to show the same background on each sub-product of these categories.

That's why i need to get the id of the parent category on my products template.

Hope this is clear enough.. ;)
Thanks in advance for your help !

Link to comment
Share on other sites

Thanks rocky for your quick reply ! I definitely need {$product->id_category_default} because people might come to products from other pages than categories so {$cookie->last_visited_category} will no function very well.

{$product->id_category_default} Works well in the product.tpl template but not in the header.tpl (I would like to add the id as a CSS class in the body). Is there any way to get the properties in the header ?

Thanks a lot,

Link to comment
Share on other sites

Unfortunately, I don't think there is any clean way to get it. The only way I can think of is to edit header.php and add the following code before the $smarty->display:

if (isset($_GET['id_product']))
{
  $product = new Product($_GET['id_product']);
  $smarty->assign('id_category_default', $product->id_category_default);
}

Link to comment
Share on other sites

  • 1 month later...

hi i'm work of the categories block but i want to

1- if in a main category and sub category see -> main category links in the block. no see another categories. or sub categories.

simple

in the index.html(over made) have links at the main categories. and click another and in the category. block is displaying this categories->subcategories and clicks the subcategories displaying in the block again main categories -> subcategories.

Sorry some english
thx

Link to comment
Share on other sites

if(isset($category->id_parent)){ //i'm tried too variable and no comes parent of the $_GET['id_category']
       $id_c = $category->id_parent; // i'm tried too variable and no comes parent of the $_GET['id_category']
       }else{
       $id_c = 1;
       }

               $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $id_c);



i'm pasted the my editted blockcategories .php please help no comes parent id

Link to comment
Share on other sites

Try:

$id_parent = 1;

if (isset($_GET['id_category']))
{
       $category = new Category($_GET['id_category']);

       if (Validate::isLoadedObject($category))
               $id_parent = $category->id_parent;
}

$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'), $id_parent);

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