juanmlg Posted April 14, 2013 Share Posted April 14, 2013 I want to add the subcategories menu of a category inside each subcategory of this category (similar to a tab menu inside each category) . I know I need to modify the category.tpl file, and the code maybe similar to: {foreach from=$subcategories item=subcategory} <li > <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" class="cat_name">{$subcategory.name|escape:'htmlall':'UTF-8'}</a> </li> {/foreach} But this code doesnt works inside a subcategory,needs some modifications. You can see more info about my question here: http://www.prestashop.com/forums/topic/228708-subcategories-menu-inside-a-subcategory/page__p__1123841#entry1123841 any help? Thanks so so much. Link to comment Share on other sites More sharing options...
juanmlg Posted April 14, 2013 Author Share Posted April 14, 2013 nothing? Link to comment Share on other sites More sharing options...
NemoPS Posted April 15, 2013 Share Posted April 15, 2013 I'm not sure i completely understood what you want to achieve. Do you want to get a list of the sibling categories of the current ones? I mean, brothers and sisters of the current subcategory? Link to comment Share on other sites More sharing options...
juanmlg Posted April 16, 2013 Author Share Posted April 16, 2013 I'm not sure i completely understood what you want to achieve. Do you want to get a list of the sibling categories of the current ones? I mean, brothers and sisters of the current subcategory? Yes! Exactly. I want to show the brothers and sisters subcategories of the current subcategory for make a "tab menu". Link to comment Share on other sites More sharing options...
NemoPS Posted April 16, 2013 Share Posted April 16, 2013 Ok, let's try something: In category.tpl, add this line where you want the list to appear: {hook h='category' id_category=$category->id} We are creating a new hook and passing the category ID as a parameter. Now create a new module, add registerHook('category') in the install function, then create hookCategory like this public function hookCategory($params) { $id_parent = $params['id_parent']; $parent_category = new category($id_parent); $children = $parent_category->getSubcategories($this->context->language->id); // finally, assign them to smarty and return a tpl } Of course, you might want to add some kind of switch to target specific categories only, this is just a rough idea 1 Link to comment Share on other sites More sharing options...
juanmlg Posted April 17, 2013 Author Share Posted April 17, 2013 (edited) <p> <br>Ok, let's try something:<br> <br> In category.tpl, add this line where you want the list to appear:<br> <br> {hook h='category' id_category=$category->id}<br> <br> We are creating a new hook and passing the category ID as a parameter.<br> <br> Now create a new module, add registerHook('category') in the install function, then create hookCategory like this<br> <br> <br> public function hookCategory($params)<br> {<br> $id_parent = $params['id_parent'];<br> $parent_category = new category($id_parent);<br> $children = $parent_category->getSubcategories($this->context->language->id);<br> // finally, assign them to smarty and return a tpl<br> <br> }<br> <br> <br> Of course, you might want to add some kind of switch to target specific categories only, this is just a rough idea <img alt="" class="bbc_emoticon" src="http://www.prestashop.com/forums/public/style_emoticons/default/smile.png"><br> Thanks so much! I am going to try this. It seems difficult but not impossible. Thanks again. Edited April 17, 2013 by Voltiosin (see edit history) Link to comment Share on other sites More sharing options...
airbag76 Posted July 2, 2014 Share Posted July 2, 2014 Hi,I'm trying to apply the Nemo1 tips with some modifies.I add in category.tpl the following row {hook h='category' id_category=$subcategory.id_category} Then I create a module with this function public function hookCategory($params) { $id_category = $params['id_category']; $category[] = new Category($id_category); global $smarty; $smarty->assign(array('category'=> $category)); return $this->display(__FILE__, 'mymodule.tpl'); } and I make this tpl file {if isset($category)} {$category.name} {/if} But when I reload the page I have this error"Fatal error: Cannot use object of type Category as array in..."Please someone can tell me what wrong?Thanks Link to comment Share on other sites More sharing options...
NemoPS Posted July 3, 2014 Share Posted July 3, 2014 You have to use $category->name Link to comment Share on other sites More sharing options...
airbag76 Posted July 3, 2014 Share Posted July 3, 2014 Hi Nemo, thanks for your reply. But I've still problem... Here the modificated code - In category tpl: {hook h='category' category=$subcategory} - In the new module: public function hookCategory($params) { $category = $params['category']; $children = $category->getSubcategories($this->context->language->id); ...other code here return $this->display(__FILE__, 'subcategoriesmenuoncategory.tpl'); } but when I reload the page I have a fatal error: "Fatal error: Call to a member function getSubcategories() on a non-object in..." I'm passing the object "category", why I can't invoke the metode "getSubcategories"? Thanks Link to comment Share on other sites More sharing options...
NemoPS Posted July 4, 2014 Share Posted July 4, 2014 Are you sure $subcategory represents a valid category object there? if not you have to instantiate a new one using new Category()... etc Link to comment Share on other sites More sharing options...
airbag76 Posted July 4, 2014 Share Posted July 4, 2014 Hi Nemo1, I resolved so: public function hookCategory($params) { $category = $params['category']; $id_category = $category['id_category']; $parent_category = new Category($id_category); $children = $parent_category->getSubcategories($this->context->language->id); // finally, assign them to smarty and return a tpl global $smarty; $smarty->assign('category', $category); $smarty->assign('children', $children); $this->context->controller->addCSS($this->_path.'css/menucategory.css'); return $this->display(__FILE__, 'menucategory.tpl'); } It's strange, because I passed an object. Thanks for all Link to comment Share on other sites More sharing options...
NemoPS Posted July 4, 2014 Share Posted July 4, 2014 Small advice: do not use globals, use $this->context->variablename instead, smarty in this case Link to comment Share on other sites More sharing options...
airbag76 Posted July 6, 2014 Share Posted July 6, 2014 Hi Nemo, first thank for all helpful tips. Now I have a problem with css. T_T I tried to add CSS in any way but seems it ignores me. I tried with: Tools::addCSS(($this->_path).'css/menucategory.css', 'all'); and so with: $this->context->controller->addCSS(($this->_path).'css/menucategory.css', 'all'); and also with: public function hookHeader() { $this->context->controller->addCSS(($this->_path).'css/menucategory.css', 'all'); } I cleared the cache and compile smarty folders but nothing, my css isn't loaded. Any suggest? My prestashop version is 1.5.6.2 Thanks Link to comment Share on other sites More sharing options...
vekia Posted July 6, 2014 Share Posted July 6, 2014 is your module associated with hookdisplayHeader ? Link to comment Share on other sites More sharing options...
airbag76 Posted July 6, 2014 Share Posted July 6, 2014 Hi Vekia, I think no, how I can see it? I added in category.tpl "{hook h='category' category=$subcategory}" and than I created a new module with this function: public function hookCategory($params) { $category = $params['category']; $id_category = $category['id_category']; $parent_category = new Category($id_category); $children = $parent_category->getSubcategories($this->context->language->id); $this->context->smarty->assign('category', $category); $this->context->smarty->assign('children', $children); if ($this->psversion()==5 || $this->psversion()==6){ $this->context->controller->addCSS(($this->_path).'css/menucategory.css', 'all'); } else { Tools::addCSS(($this->_path).'css/menucategory.css', 'all'); } return $this->display(__FILE__, 'menucategory.tpl'); } I forgot something? Thanks Link to comment Share on other sites More sharing options...
NemoPS Posted July 7, 2014 Share Posted July 7, 2014 Of course, that method must be used inside displayHookHeader in order to work properly Link to comment Share on other sites More sharing options...
vekia Posted July 7, 2014 Share Posted July 7, 2014 go to modules > positions and transplant your module to hookdisplayHeader (use anchor button to open transplant form) Link to comment Share on other sites More sharing options...
airbag76 Posted July 9, 2014 Share Posted July 9, 2014 Thanks guys, now it work very fine Someone is so kindly to explain me why the method must be used inside displayHookHeader.Thanks for all Link to comment Share on other sites More sharing options...
vekia Posted July 9, 2014 Share Posted July 9, 2014 displayhookheader is a place to include css / js librariers all other hooks are wrong place to include css / js files if you will check page structure you will see that libraries are included in <head></head> section of your website not in left / right columns or sth Link to comment Share on other sites More sharing options...
YT Low Posted September 27, 2014 Share Posted September 27, 2014 Hi, I follow the code above. But I couldn't get it work. I can't see any output in my category page. Could you paste all code / files that you have modified? Thanks in advanced!!! Link to comment Share on other sites More sharing options...
stejob Posted November 6, 2014 Share Posted November 6, 2014 Hi. I would also like to see all code. I tried to do this. But I guess I don't know how to make the module exactly. I cant get it to install with just that code. Thanks in advance 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