krislicky Posted June 1, 2010 Share Posted June 1, 2010 Hey there, I really hope someone can help with this as I'm tearing my hair out!A client has asked if all the subcategories of the second level of categories can be shown within the 3rd level of subcategories. I think I explained that strangely. Go here:http://www.yankeestore.co.uk/130-allAs you can see, there are no subcategories for this section, but my client would like the images for all of the other subcategories within this parent group to be displayed i.e. this particular category would always show all, fresh, fruit, floral, food & spice and festive, as would be the same for each of these.Could anyone shed any light on this?Ive attached a file to demonstrate how it would look because I dont think im being very clear Link to comment Share on other sites More sharing options...
krislicky Posted June 2, 2010 Author Share Posted June 2, 2010 seriously? no-one? Link to comment Share on other sites More sharing options...
rocky Posted June 2, 2010 Share Posted June 2, 2010 So you want the subcategories of the parent category displayed when there are no subcategories for the current category? To do that, try changing line 50 of category.php from: $subCategories = $category->getSubCategories(intval($cookie->id_lang)); to: $subCategories = $category->getSubCategories(intval($cookie->id_lang)); if (sizeof($subCategories) == 0 AND intval($category->id_parent) > 1) { $parentCategory = new Category(intval($category->id_parent), intval($cookie->id_lang)); $subCategories = $parentCategory->getSubCategories(intval($cookie->id_lang)); } Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted June 10, 2010 Share Posted June 10, 2010 Once again Rocky... you did it !Now, on my subcategory page (A1), I can show all other subcategories of parent (A2, A3, A4, ....).Next question : how can I show this also on a product page ? Link to comment Share on other sites More sharing options...
rocky Posted June 10, 2010 Share Posted June 10, 2010 You'll need to add similar code to product.php to pass in the subcategories. Something like: $category = new Category($product->id_category_default, intval($cookie->id_lang)); $subCategories = $category->getSubCategories(intval($cookie->id_lang)); if (sizeof($subCategories) == 0 AND intval($category->id_parent) > 1) { $parentCategory = new Category(intval($category->id_parent), intval($cookie->id_lang)); $subCategories = $parentCategory->getSubCategories(intval($cookie->id_lang)); } Then you'll have to copy the subcategory code from category.tpl into product.tpl. Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted June 10, 2010 Share Posted June 10, 2010 Thank you !Where should I put your code in product.php ?I have added it at line 172.The problem is that now the category ID of a product is its default category ID.And that's making the breadcrumb and other things go wrong.Also in $category, some arrays are now x3 when they should be single.Thanks for your help.... Link to comment Share on other sites More sharing options...
rocky Posted June 10, 2010 Share Posted June 10, 2010 I forgot to include id_lang when creating the Category object above. I've updated the code. It should fix the array instead of single problem.You could replace $product->id_category_default above with: intval($cookie->last_visited_category) They are the only two categories you have access to from the product page. Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted June 16, 2010 Share Posted June 16, 2010 This could help a lot.The problem is that my {$cookie} says : Cookie Object (0)Damn ! Link to comment Share on other sites More sharing options...
Rom Soul Posted November 1, 2010 Share Posted November 1, 2010 Hi Rocky, Emmanuel,Here I come several months after the topic, am I too late ?I have the 2 same targets as Emmanuel :- target 1 : on the page for subcategory=A1, display links list A1,A2,A3... instead of [no subcategories] : done, thanks to the piece of code above, i.e. thanks to you !- target 2 : on the page for product X in subcat A1, display again links list A1, A2, A3... TO DO !I tried hard to understand where to insert the code you gave, Rocky, but I am afraid Smarty still remains this far a foreign language to me ... I'm working hard on it !So if you Emmanuel or Rocky, can indicate me what I did wrong, this is what I did, and how I got... no results :In product.php, I turned line 170 : if (!$category) $category = new Category($product->id_category_default, intval($cookie->id_lang)); into : $category = new Category(intval($cookie->last_visited_category) , intval($cookie->id_lang)); $subCategories = $category->getSubCategories(intval($cookie->id_lang)); if (sizeof($subCategories) == 0 AND intval($category->id_parent) > 1) { $parentCategory = new Category(intval($category->id_parent), intval($cookie->id_lang)); $subCategories = $parentCategory->getSubCategories(intval($cookie->id_lang)); } and in product.tpl, I added : > {if isset($subcategories)} </pre> <ul> {foreach from=$subcategories item=subcategory} getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'} {/foreach} </ul> <br>{else} <br> no subategories defined, go back to school<br>{/if What did I miss ?... Link to comment Share on other sites More sharing options...
lagachette Posted February 8, 2011 Share Posted February 8, 2011 Hello,I got the same problem.I succeed to do the part 1 but in the part 2 the $subcategories still empty while the $category contains data.Any ideas?Thanks Link to comment Share on other sites More sharing options...
Rom Soul Posted February 9, 2011 Share Posted February 9, 2011 Sorry Lagachette,I sent desperate PMs, but never got my answer for part 2, and eventually had to display something else in my submenu Good luck : if you find the solution, I am still interested ! 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