Teapot Creative Posted May 21, 2014 Share Posted May 21, 2014 Hi Looking for a solution to add the default product category id class to the body id of each product. i.e. <body id="product" class="cat?"> "cat?" being the default category id of the product. Code snippet and solution would be great if anyone out there can help..? Kind regards Nick Link to comment Share on other sites More sharing options...
Alex Simonchik BelVG Posted May 21, 2014 Share Posted May 21, 2014 Hi, try this code, this is works for me: <body id="product" class="{if isset($product->id_category_default)}cat{$product->id_category_default}{/if} "> Regards Link to comment Share on other sites More sharing options...
Teapot Creative Posted May 21, 2014 Author Share Posted May 21, 2014 Hi... Did a similar form this post: http://www.prestashop.com/forums/topic/285562-custom-class-for-body-depending-on-category/ as below.. seemed to work great.. Within CategoryController.php's initContent() function you can add something like: 'parent_category_chain' => $this->category->getParentsCategories(), to the "$this->context->smarty->assign(array(" smarty assignment. Then in your header.tpl you can use a foreach loop to only add a category id number where the level_depth of categories is equal to 2 (which would all have a parent category of "home" respectively). <body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}{if $category->id}{if $category->level_depth eq 2} class="cat{$category->id}"{elseif $category->level_depth > 2}{foreach $parent_category_chain as $parent_category_node}{if $parent_category_node.level_depth eq 2} class="cat{$parent_category_node.id_category}"{/if}{/foreach}{/if}{/if}> Link to comment Share on other sites More sharing options...
Tatort Posted February 16, 2017 Share Posted February 16, 2017 (edited) Hello not working on Presta 1.6.1.11 in product page but working on category page... hello litle edit so = Where to Buy / Eastern Europe /Russia > Edinorog LLC What i want is the first category after home. In categoryit's working i kann see my default with: {foreach $parent_category_chain as $parent_category_node} {if $parent_category_node.level_depth eq 2} {assign var=wheretobuy value=$parent_category_node.id_category} {/if} {/foreach} i try with a different value on level_depth but.... Edited February 16, 2017 by Tatort (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now