sjohanna Posted July 8, 2010 Share Posted July 8, 2010 Hi there,I am new to PrestaShop and I am using it for the first time for a project which is not a classic "shop" so I will have to make a few alterations to the code itself (and I am not really a developer).So hopefully you will be able to help me.My first problem is the following.The site has around 20 main categories (restaurants) and each category will have 3-4 subcategories (starters, mains, desserts).But we don't want to show the products only on the Subcategories pages as it adds one more click.We want to show all the products of Restaurant 1 on "Restaurant 1" page but sorted by Subcategories.So we would get:RESTAURANT 1STARTERSDish 1Dish 2Dish 3MAINSDish 1Dish 2Dish 3I already changed a few things on the category.tpl and the subcategories are displayed, but the products are not filtered and are displaying under each subcategory. I suppose there is something to change in Category.php.Here is my code if it can help... I suppose I must add a filter somewhere, but I thought I'd ask before spening 2 hours on that issue.Thank you.Johanna {if $products} {include file=$tpl_dir./product-sort.tpl} {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {$subcategory.name|escape:'htmlall':'UTF-8'} {include file=$tpl_dir./product-list.tpl products=$products} {/foreach} {else} {include file=$tpl_dir./product-list.tpl products=$products} {/if} {include file=$tpl_dir./pagination.tpl} Link to comment Share on other sites More sharing options...
sjohanna Posted July 9, 2010 Author Share Posted July 9, 2010 Any idea anybody?Maybe I should move this post into the Development section?I would take anything even just a tip on which direction to take, a module which does almost the same thing I could work from...Thanks! Link to comment Share on other sites More sharing options...
sjohanna Posted July 12, 2010 Author Share Posted July 12, 2010 I am still searching and not finding...Last try... Nobody could send me in the right direction? Link to comment Share on other sites More sharing options...
SpyrosT Posted July 12, 2010 Share Posted July 12, 2010 Not sure if my solution is really what you need but I think you can do it from BO without a change on the code.So, you have your Categories and Subcategories.Add a product (dish 1) in starters under the RESTAURANT 1 and check the boxes Starters and RESTAURANT 1 to include the Dish 1.In the same way add all your dishes for all.Then go BO> Preferences> Products and will find "Default order by:"Select "Position inside category". Link to comment Share on other sites More sharing options...
sjohanna Posted July 13, 2010 Author Share Posted July 13, 2010 Thanks for your answer!I already did that (I think) but I don't have the titles of the subcategories displaying on the page.I have:RESTAURANTItems from subcategories 1Items from subcategories 2...Because the system is "repeating" the item in both categories...If I can't display the text, I'll just keep it that way... Because I tried different things (if... blabla) and it only repeated all the products under each subtitle... Link to comment Share on other sites More sharing options...
SpyrosT Posted July 13, 2010 Share Posted July 13, 2010 Maybe the mess happens because you have already change the code.Try to put the original file back and use my solution to see if it works for you.Remember to keep a backup copy of your file. Link to comment Share on other sites More sharing options...
sjohanna Posted July 13, 2010 Author Share Posted July 13, 2010 I put back the code the way it was... But the subcategories title are not displayed...Are they displayed for you when you try this option? I feel like the page is only calling the products from "Restaurant 1" and doesn't care if they are also part of subcategories... Link to comment Share on other sites More sharing options...
SpyrosT Posted July 13, 2010 Share Posted July 13, 2010 Ok I forgot to tell you an other one setting.Go to your block categories module and set dynamic off.And remember to set your Maximum depth as you desire. Link to comment Share on other sites More sharing options...
sjohanna Posted July 13, 2010 Author Share Posted July 13, 2010 Sorry.... But the "Block Category" is the category menu on the left sidebar is it?The change you gave me didn't change anything on the Category page itself anyway...On the left menu, I have:Restaurant 1Restaurant 2Restaurant 3Restaurant 4Restaurant 5If I click on Restaurant 2, I have: Restaurant 2 List of the subcategories (links to subcategories pages - Starters, Mains etc.) Sort by drop down List of the products of "Restaurant 2" Salad 1 Salad 2 Risotto PastaWhile I would like:Restaurant 2 List of the subcategories (links to subcategories pages - Starters, Mains etc.) Sort by drop down Starters Salad 1 Salad 2 Mains Risotto PastaI really thing the code should be changed and instead of displaying the items of the category "Restaurant 2" it should display the products of the subcategories of Restaurant 2... and that way, the titles would be there anyway...But it's a bit too advanced for me.Thanks for trying anyway!! Link to comment Share on other sites More sharing options...
SpyrosT Posted July 13, 2010 Share Posted July 13, 2010 Sorry, but I though it was about your categories menu the way you gave the list example.You can take a screen-shot and show on it your issue. Link to comment Share on other sites More sharing options...
sjohanna Posted July 13, 2010 Author Share Posted July 13, 2010 All right, here is a screenshot (design on his way)...So basically, I want the subcategory titles to divide the "items" listed under the "Sort by". Link to comment Share on other sites More sharing options...
sjohanna Posted July 15, 2010 Author Share Posted July 15, 2010 Nobody?I actually want to reproduce what's there: http://www.letseatin.ie/italian/ Link to comment Share on other sites More sharing options...
sjohanna Posted July 21, 2010 Author Share Posted July 21, 2010 I worked on other issues in the last few days, but this functionality is very important for the client...Would anybody show me the right direction?Thanks a million in advance... Link to comment Share on other sites More sharing options...
jkmagic Posted July 31, 2010 Share Posted July 31, 2010 Hi Sjohanna,your idea is simmilar to my project!have you found any solution to this?Thanks on advance Link to comment Share on other sites More sharing options...
sjohanna Posted August 8, 2010 Author Share Posted August 8, 2010 Hi jkmagic...No, no solutions yet, still looking for one!I created a new subject in "Development" but no luck there either.Let me know if you find something, and I'll do the same! Link to comment Share on other sites More sharing options...
jkmagic Posted August 8, 2010 Share Posted August 8, 2010 Of cource i will.Thanks!can you post the siteyou are making? Link to comment Share on other sites More sharing options...
fahad Posted September 5, 2010 Share Posted September 5, 2010 hello hello u people had some luck with it i am trying to do the same thing but i am having no luck i saw ur site sjohanna seems that u came up wit some solution can u help me please as thats the only thing i am left with in my project help me plzz plzzz Link to comment Share on other sites More sharing options...
Niriza Posted March 15, 2011 Share Posted March 15, 2011 hey did u get any solution I am also having the same problem Link to comment Share on other sites More sharing options...
sjohanna Posted March 15, 2011 Author Share Posted March 15, 2011 No, I never got a solution. Let's see if it's possible in Prestashop 1.4, or did you try already ?Johanna Link to comment Share on other sites More sharing options...
Niriza Posted March 16, 2011 Share Posted March 16, 2011 no i haven't tried yet Link to comment Share on other sites More sharing options...
weizemann Posted March 17, 2011 Share Posted March 17, 2011 Hello, sorry my english is not the first language, I modified the file category.php to show all the products would be something they were looking for? Link to comment Share on other sites More sharing options...
sjohanna Posted March 17, 2011 Author Share Posted March 17, 2011 It depends if you have the sub-category titles in between.CATEGORYSUBCATEGORY 1 TITLEProduct 1Product 2Product 3SUBCATEGORY 2 TITLEProduct 1Product 2Product 3etc. Link to comment Share on other sites More sharing options...
deiutz Posted June 5, 2011 Share Posted June 5, 2011 hi guys/girlsnot sure if you got your answer, I assume you did, but anyways I needed it too and I implemented this in my websiteif anybody needs this in the future, please let me know and I'll send you my changes, no problem Link to comment Share on other sites More sharing options...
Niriza Posted June 6, 2011 Share Posted June 6, 2011 yah i need it. So if u can plz share with us. Thank you!! Link to comment Share on other sites More sharing options...
deiutz Posted June 6, 2011 Share Posted June 6, 2011 ok so I hope you can use this. While I am an experienced php developer, I'm not that familiar with smarty so please bare with me Open the root folder of prestashop, you will find there the "category.php" file. Open this file, and at the bottom where you see if (isset($subCategories)) { $smarty->assign(array( 'subcategories_nb_total' => sizeof($subCategories), 'subcategories_nb_half' => ceil(sizeof($subCategories) / 2))); you put in this code if (isset($subCategories)) { $smarty->assign(array( 'subcategories_nb_total' => sizeof($subCategories), 'subcategories_nb_half' => ceil(sizeof($subCategories) / 2))); $subcategory_objects=array(); $smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($subCategories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang) ); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $smarty->assign("subcategories_objects",$subcategory_objects); } so what this does is to make sure you have your subcategory objects passed to the template file, which we will now openit is called category.tpl and you can find it in you theme directory "/themes/theme_name/category.tpl"look for something like <!-- Subcategories --> I believe this is the original code in my theme: {l s='Subcategories'} getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$subcategory.name|escape:'htmlall':'UTF-8'}"> {if $subcategory.id_image} getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}" alt="" /> {else} {/if} getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'} this is what I have replaced it with in order to show the products from subcategories {l s='Subcategories'} {foreach from=$subcategories item=subcategory} {$subcategory.name|escape:'htmlall':'UTF-8'} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file=$tpl_dir./product-list.tpl products=$subcategory_object->getProducts($andr_lang,'1','10')} {/foreach} When you decide to use this, make sure you don't mix up your variable names.You should be able to see this on my website (this link will take you directly to the category where multiple subcategories are displayed) stickere de perete Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 7, 2011 Share Posted June 7, 2011 ok so I hope you can use this. While I am an experienced php developer, I'm not that familiar with smarty so please bare with me Open the root folder of prestashop, you will find there the "category.php" file. Open this file, and at the bottom where you see if (isset($subCategories)) { $smarty->assign(array( 'subcategories_nb_total' => sizeof($subCategories), 'subcategories_nb_half' => ceil(sizeof($subCategories) / 2))); you put in this code if (isset($subCategories)) { $smarty->assign(array( 'subcategories_nb_total' => sizeof($subCategories), 'subcategories_nb_half' => ceil(sizeof($subCategories) / 2))); $subcategory_objects=array(); $smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($subCategories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang) ); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $smarty->assign("subcategories_objects",$subcategory_objects); } so what this does is to make sure you have your subcategory objects passed to the template file, which we will now openit is called category.tpl and you can find it in you theme directory "/themes/theme_name/category.tpl"look for something like <!-- Subcategories --> I believe this is the original code in my theme: {l s='Subcategories'} getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$subcategory.name|escape:'htmlall':'UTF-8'}"> {if $subcategory.id_image} getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}" alt="" /> {else} {/if} getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'} this is what I have replaced it with in order to show the products from subcategories {l s='Subcategories'} {foreach from=$subcategories item=subcategory} {$subcategory.name|escape:'htmlall':'UTF-8'} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file=$tpl_dir./product-list.tpl products=$subcategory_object->getProducts($andr_lang,'1','10')} {/foreach} When you decide to use this, make sure you don't mix up your variable names.You should be able to see this on my website (this link will take you directly to the category where multiple subcategories are displayed) stickere de perete How can I modify this code to work only under simpe condition like: if category/subcategoryID = 3, 45, 67, 34 then applay this modyfication ??thanks,SonnyBoy Link to comment Share on other sites More sharing options...
deiutz Posted June 7, 2011 Share Posted June 7, 2011 I'm not on my development machine right now, but I think you can use this condition in the template (this is not the most efficient way). Assuming you want to do this for 2-3 categories, you can place an IF. For a reasonable number of cases you can you a switch, but I'm not that good with Smarty. I'll exemplify for an IF, you try to do the rest:)1. If you just want subcategory with ID=3 to be displayed {l s='Subcategories'} {foreach from=$subcategories item=subcategory} {$subcategory.name|escape:'htmlall':'UTF-8'} {assign var="subcategory_id" value=$subcategory.id_category} {if $subcategory.id_category == '3' } //this will only display the products in the subcategory with ID = 3 {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file=$tpl_dir./product-list.tpl products=$subcategory_object->getProducts($andr_lang,'1','10')} {/if} {/foreach} 2. if you want to display subcategories only for the category with ID=5 (for example) {l s='Subcategories'} {if $category['id_category'] == '5' } //so only do the following for the category with ID=5 {foreach from=$subcategories item=subcategory} {$subcategory.name|escape:'htmlall':'UTF-8'} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file=$tpl_dir./product-list.tpl products=$subcategory_object->getProducts($andr_lang,'1','10')} {/foreach} {/if} As I said, I can't test the code right now, but it should be a good start Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 7, 2011 Share Posted June 7, 2011 The modyfication doesnt work under Presta 1.4x, unfortunately... Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 9, 2011 Share Posted June 9, 2011 The modyfication doesnt work under Presta 1.4x, unfortunately... deiutz, could you help me to get that work under PS 1.4 ? Link to comment Share on other sites More sharing options...
deiutz Posted June 13, 2011 Share Posted June 13, 2011 hi guys,indeed, i'm running prestashop Version 1.3.2.3unfortunately I can't help you with version 1.4 until I switch to it myself, but I'm not sure when this is going to happenhopefully someone will post a solution for this problem using prestashop 1.4, or someone running 1.4 could update the solution I postedbest of luck Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 13, 2011 Share Posted June 13, 2011 hi guys,indeed, i'm running prestashop Version 1.3.2.3unfortunately I can't help you with version 1.4 until I switch to it myself, but I'm not sure when this is going to happenhopefully someone will post a solution for this problem using prestashop 1.4, or someone running 1.4 could update the solution I postedbest of luck But does your code for ver 1.3 in this post works for sure? Im going to analyse it line by line and try to convert to ps 1.4. Link to comment Share on other sites More sharing options...
deiutz Posted June 13, 2011 Share Posted June 13, 2011 yes it does,take a look here http://magazinul-de-stickere.ro/5-autocolante-animaleas you can see there are 4 subcategories being displayed in the category. I limited each subcategory to only show 4 products. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 13, 2011 Share Posted June 13, 2011 yes it does,take a look here http://magazinul-de-stickere.ro/5-autocolante-animaleas you can see there are 4 subcategories being displayed in the category. I limited each subcategory to only show 4 products. That is exactly what I need to finish the project.... ;( ;( ;(If I apply modification to the php file the site stopped display categories at all .... Link to comment Share on other sites More sharing options...
SonnyBoyII Posted June 28, 2011 Share Posted June 28, 2011 hi guys,indeed, i'm running prestashop Version 1.3.2.3unfortunately I can't help you with version 1.4 until I switch to it myself, but I'm not sure when this is going to happenhopefully someone will post a solution for this problem using prestashop 1.4, or someone running 1.4 could update the solution I postedbest of luck But does your code for ver 1.3 in this post works for sure? Im going to analyse it line by line and try to convert to ps 1.4. THANKS DEIUTZ !!! I have got it working with presta 1.4xhere is my working code for ps1.4.3 :go to Controller/categorycontroller.phpbelow these lines: 'subcategories_nb_total' => sizeof($subCategories), 'subcategories_nb_half' => ceil(sizeof($subCategories) / 2))); put this: 'subcategories_nb_total' => sizeof($subCategories), 'subcategories_nb_half' => ceil(sizeof($subCategories) / 2))); $subcategory_objects=array(); self::$smarty->assign("andr_lang",(int)(self::$cookie->id_lang)); foreach ($subCategories as $subcategory) { $sub=new Category(($subcategory['id_category']),(int)(self::$cookie->id_lang)); $subcategory_objects[$subcategory[id_category]]=$sub; } //var_dump($subcategory_objects); self::$smarty->assign("subcategories_objects",$subcategory_objects); } then in category.tpl file in template directory, my 'subategory' div looks like this: {l s='Subcategories'} {foreach from=$subcategories item=subcategory} {$subcategory.name|escape:'htmlall':'UTF-8'} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="$tpl_dir./product-list.tpl" products=$subcategory_object->getProducts($andr_lang,'1','100')} {/foreach} once again: big thanks, deiutz!regards,SonnyBoy Link to comment Share on other sites More sharing options...
deiutz Posted June 28, 2011 Share Posted June 28, 2011 Thanks SonnyBoy for porting to 1.4 I think most people who will use this will use it on 1.4+Great to see it's working and hopefully you managed this in time for your project Link to comment Share on other sites More sharing options...
w3bsolutions Posted October 24, 2011 Share Posted October 24, 2011 Thanks for this thread man... I managed to make it work in PS 1.4.5.0 limited to 2 parent categories. Just remember in PS 1.4.5 to limit it to a category, instead of {if $category['id_category'] == '5' } //so only do the following for the category with ID=5 use {if $category->id_category == '5'} //so only do the following for the category with ID=5 I think it would be a really nice feature if this was an option for the categories in the BO, to either show the subcategories with their thumbnails or show the subcategories with their products in the same view. That would be awesome. There could also be an option to hide the subcategory from the categories menu block, which is what I did via CSS changing category.tpl so it would assignthe value of the menu name as a class to the li element of the menu (and after do a display:none on those I dont want to show, or a li."categoryname" ul {display:none} to hide all the subcategories from the category menu block because they already show when you click on the parent category with all their products.) Like that a parent category could have multiple subcategories and show all their products in one view (this helps if there are not too many products per subcategory) avoiding a huge list of subcategories on the menu block. Link to comment Share on other sites More sharing options...
rapasoft Posted January 3, 2012 Share Posted January 3, 2012 Big thank you! It works nicely... Link to comment Share on other sites More sharing options...
raza Posted June 4, 2012 Share Posted June 4, 2012 Hello, I'm using prestashop 1.4.8.2 and I have a problem that my first and main category displays the products all of the products of its subcategories instead of showing the subcategories name, Please help me how can I fix it? Link to comment Share on other sites More sharing options...
Omidnag Posted July 3, 2012 Share Posted July 3, 2012 Have any one got this to work with 1.4.6.2? I have tried the code but it didn't work Link to comment Share on other sites More sharing options...
BIgZumo Posted January 7, 2013 Share Posted January 7, 2013 Works Great with PrestaShop 1.5.2.0 but i must edit some lines.... THANK YOU FOR THIS THREAD ! Link to comment Share on other sites More sharing options...
BIgZumo Posted June 23, 2013 Share Posted June 23, 2013 (edited) Here is my Tutorial (Tested with PrestaShop v. 1.5.2.0 AND 1.5.4.1): open this file: controllers/front/CategoryController.php search this lines: if ($subCategories = $this->category->getSubCategories($this->context->language->id)) { insert this code after the: { $subcategory_objects=array(); $this->context->smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($subCategories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang)); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $this->context->smarty->assign("subcategories_objects",$subcategory_objects); save this file and upload. now open the file: themes/"your_theme"/category.tpl search this lines: <div class="content_sortPagiBar"> {include file="$tpl_dir./pagination.tpl"} <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./product-compare.tpl"} {include file="./nbr-product-page.tpl"} </div> </div> insert after the </div></div>: {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="./product-list-sub.tpl" products=$subcategory_object->getProducts('1','1','100')} {/foreach} {else} {include file="./product-list.tpl" products=$products} {/if} save and upload. now open this file: themes/"your_theme"/product-list.tpl search this line: <!-- Products list --> after the line insert this: <h4>{$subcategory.name|escape:'htmlall':'UTF-8'}</h4> search this line: {foreach from=$products item=product name=products} after this line add: {if $products != ''} now search this lines: <a class="button lnk_view" href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}">{l s='View'}</a> </div> </li> after this lines add: {else} No Products in this Category {/if} save the product-list.tpl as product-list-sub.tpl and upload the files. DONE!!! I hope it will works... contact me if you have problems.... sorry for my bad english best regards Edited June 23, 2013 by BIgZumo (see edit history) 5 Link to comment Share on other sites More sharing options...
syntaxed Posted August 13, 2013 Share Posted August 13, 2013 I have no CategoryController.php in my directory. What should I do? Link to comment Share on other sites More sharing options...
Amazzing Posted September 15, 2013 Share Posted September 15, 2013 (edited) ....insert after the </div></div>: {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="./product-list-sub.tpl" products=$subcategory_object->getProducts('1','1','100')} {/foreach} {else} {include file="./product-list.tpl" products=$products} {/if} Thank you, that worked for me, I only modified .tpls in some other way, according to my needs. However, there is one thing that can be improved. Your code sets specific language for displayed data of products ...getProducts('1','1','100')... it is OK, if you use one language on your site, but if you have several languages, you better use a variable instead of '1'. I have replaced '1' with $cart->id_lang and it works fine now even if you use more than 1 language. getProducts($cart->id_lang,'1','100') Edited September 16, 2013 by Amazzing (see edit history) 2 Link to comment Share on other sites More sharing options...
anmihe Posted February 19, 2014 Share Posted February 19, 2014 Hi guys, This kinda works, but it seems only to fetch first sub categories for some, and then all for others. And when moving products from different categories they sometimes stop showing at all...and then just starts to show again when moving product back. Haven't really found a pattern to this yet what categories make. ...any one have this working on 1.5.6.x? Link to comment Share on other sites More sharing options...
anmihe Posted February 19, 2014 Share Posted February 19, 2014 ...and how to get this to work properly with Pagination? 2 Link to comment Share on other sites More sharing options...
sanjogchamling Posted March 18, 2014 Share Posted March 18, 2014 Here is my Tutorial (Tested with PrestaShop v. 1.5.2.0 AND 1.5.4.1): open this file: controllers/front/CategoryController.php search this lines: if ($subCategories = $this->category->getSubCategories($this->context->language->id)) { insert this code after the: { $subcategory_objects=array(); $this->context->smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($subCategories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang)); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $this->context->smarty->assign("subcategories_objects",$subcategory_objects); save this file and upload. now open the file: themes/"your_theme"/category.tpl search this lines: <div class="content_sortPagiBar"> {include file="$tpl_dir./pagination.tpl"} <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./product-compare.tpl"} {include file="./nbr-product-page.tpl"} </div> </div> insert after the </div></div>: {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="./product-list-sub.tpl" products=$subcategory_object->getProducts('1','1','100')} {/foreach} {else} {include file="./product-list.tpl" products=$products} {/if} save and upload. now open this file: themes/"your_theme"/product-list.tpl search this line: <!-- Products list --> after the line insert this: <h4>{$subcategory.name|escape:'htmlall':'UTF-8'}</h4> search this line: {foreach from=$products item=product name=products} after this line add: {if $products != ''} now search this lines: <a class="button lnk_view" href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}">{l s='View'}</a> </div> </li> after this lines add: {else} No Products in this Category {/if} save the product-list.tpl as product-list-sub.tpl and upload the files. DONE!!! I hope it will works... contact me if you have problems.... sorry for my bad english best regards I tried this in Prestashop 1.5.6.0 its not working... Do you have a solution for Ps version 1.5.6 I want something like the following: Sub-category one product 1 product 2 product 3 ... Sub-category two product 1 product 2 product 3 ... Sub-category three product 1 product 2 product 3 ... Sub-category Four product 1 product 2 product 3 ... Thanks in advance.. Link to comment Share on other sites More sharing options...
sanjogchamling Posted March 18, 2014 Share Posted March 18, 2014 Here is my Tutorial (Tested with PrestaShop v. 1.5.2.0 AND 1.5.4.1): open this file: controllers/front/CategoryController.php search this lines: if ($subCategories = $this->category->getSubCategories($this->context->language->id)) { insert this code after the: { $subcategory_objects=array(); $this->context->smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($subCategories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang)); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $this->context->smarty->assign("subcategories_objects",$subcategory_objects); save this file and upload. now open the file: themes/"your_theme"/category.tpl search this lines: <div class="content_sortPagiBar"> {include file="$tpl_dir./pagination.tpl"} <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./product-compare.tpl"} {include file="./nbr-product-page.tpl"} </div> </div> insert after the </div></div>: {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="./product-list-sub.tpl" products=$subcategory_object->getProducts('1','1','100')} {/foreach} {else} {include file="./product-list.tpl" products=$products} {/if} save and upload. now open this file: themes/"your_theme"/product-list.tpl search this line: <!-- Products list --> after the line insert this: <h4>{$subcategory.name|escape:'htmlall':'UTF-8'}</h4> search this line: {foreach from=$products item=product name=products} after this line add: {if $products != ''} now search this lines: <a class="button lnk_view" href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}">{l s='View'}</a> </div> </li> after this lines add: {else} No Products in this Category {/if} save the product-list.tpl as product-list-sub.tpl and upload the files. DONE!!! I hope it will works... contact me if you have problems.... sorry for my bad english best regards Can somebody post the solution for Prestashop v 1.5.6.0 Link to comment Share on other sites More sharing options...
vekia Posted March 21, 2014 Share Posted March 21, 2014 hello solution for 1.5.4, 1.5.2 will work also in 1.5.6 Link to comment Share on other sites More sharing options...
jon88 Posted March 28, 2014 Share Posted March 28, 2014 Its working on 1.5.6, you just have to add one product in the main category Category product 1 Sub-category one product 1 product 2 product 3 ... Sub-category two product 1 product 2 product 3 and so on Link to comment Share on other sites More sharing options...
MedTN Posted June 26, 2014 Share Posted June 26, 2014 (edited) Hello, I'm using the last version prestashop 1.6.0.8 => IT's WORK, PERFECT THX a LOT Edited June 26, 2014 by MedTN (see edit history) Link to comment Share on other sites More sharing options...
Eutanasio Posted October 11, 2014 Share Posted October 11, 2014 It's now working for me at all on PS 1.6. The only difference I found on the code you ask us to change is this line: <a class="button lnk_view" href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}">{l s='View'}</a> </div> </li> But the rest of the files I changed them as explained. The thing is that after doing it, no category pages are loaded, just a blank page.Any options for PS 1.6 users? Thanks Link to comment Share on other sites More sharing options...
thepan Posted November 8, 2014 Share Posted November 8, 2014 Hey everybody. Does anyone have this solution for 1.6.0.9? Also it shows duplicate products when a product is in more then one subcategory. Link to comment Share on other sites More sharing options...
Ganesh Hipparkar Posted November 21, 2014 Share Posted November 21, 2014 (edited) Hello every one, I want to show my subcategories products under parent category . I triyed above soultion in ps 1.5.6.2 but it didn't work for me. http://www.luxishop.cz/index.php check site i have category like following Telephony(main category) -Mobile Phones(sub category) --smartphone(sub sub category) --iphone(sub sub category) I want to show my all sub sub categories(smartphone,iphone etc) products under main (Telephone) and sub category(mobile phone). i also triyed with layered navigation module but no luck Please help i am stuck with this problem since two days. Thanks, Ganesh Edited November 21, 2014 by Ganesh Hipparkar (see edit history) Link to comment Share on other sites More sharing options...
Ganesh Hipparkar Posted November 21, 2014 Share Posted November 21, 2014 hello solution for 1.5.4, 1.5.2 will work also in 1.5.6 Hello vekia, I want to show my subcategories products under parent category . I triyed above soultion in ps 1.5.6.2 but it didn't work for me. http://www.luxishop.cz/index.php check site i have category like following Telephony(main category) -Mobile Phones(sub category) --smartphone(sub sub category) --iphone(sub sub category) I want to show my all sub sub categories(smartphone,iphone etc) products under main (Telephone) and sub category(mobile phone). i also triyed with layered navigation module but no luck Please help i am stuck with this problem since two days. Thanks, Ganesh 1 Link to comment Share on other sites More sharing options...
mavynet Posted February 25, 2015 Share Posted February 25, 2015 It works for 1.6.0.11 also. Just put one product in the parent category. Thx for the solution. Link to comment Share on other sites More sharing options...
sucius Posted February 26, 2015 Share Posted February 26, 2015 Hello, I'm using the last version prestashop 1.6.0.8 => IT's WORK, PERFECT THX a LOT Hi MedTN, I also have 1.6.0.8 but it doesn't work for me at all. For example <a class="button lnk_view" href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}">{l s='View'}</a></div> </li> looks kind of different in my set up. Could you please tell me how you did it? thanks Link to comment Share on other sites More sharing options...
aprex Posted March 23, 2015 Share Posted March 23, 2015 (edited) My solution for displaying all product from subcategories on category page for Prestashop 1.6.0.11 After hours of debug I discovered that blocklayered module can do the trick. Common idea is to show all products filtered by blocklayered. So some configuration is needed. 1. Open <theme_folder>/category.tpl Find lines {if $products} <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {include file="./product-list.tpl" products=$products} <div class="content_sortPagiBar"> <div class="bottom-pagination-content clearfix"> {include file="./product-compare.tpl" paginationId='bottom'} {include file="./pagination.tpl" paginationId='bottom'} </div> </div> {/if} end remove wrapping {if $products}{/if}, so the content needed to be displayed 2. Open <theme_folder>/product-list.tpl Find lines at the bottom of file {addJsDef comparedProductsIds=$compared_products} {/if} and add additional contodion to {if} {addJsDef comparedProductsIds=$compared_products} {else} <ul{if isset($id) && $id} id="{$id}"{/if} class="product_list grid row{if isset($class) && $class} {$class}{/if}"> </ul> {/if} This ul.product_list needed to put content in there by ajax by blocklayered 3. Open <theme_folder>/js/modules/blocklayered/blocklayered.js and find initLayered() function. function initLayered() { initFilters(); initSliders(); initLocationChange(); updateProductUrl(); if (window.location.href.split('#').length == 2 && window.location.href.split('#')[1] != '') { var params = window.location.href.split('#')[1]; reloadContent('&selected_filters='+params); } } Extend condition like this if (window.location.href.split('#').length == 2 && window.location.href.split('#')[1] != '') { var params = window.location.href.split('#')[1]; reloadContent('&selected_filters='+params); } else { // Reload content if no filters enabled, to show all products on category page reloadContent(true); } So when page is loaded and no filters are applied blocklayered will return all products withiout filtering on accessing that page. Also you need to enable diplaying products from subcategories in module configuration. Edited March 23, 2015 by aprex (see edit history) 2 Link to comment Share on other sites More sharing options...
MarkusVisse Posted April 3, 2015 Share Posted April 3, 2015 My solution for displaying all product from subcategories on category page for Prestashop 1.6.0.11 After hours of debug I discovered that blocklayered module can do the trick. Common idea is to show all products filtered by blocklayered. So some configuration is needed. 1. Open <theme_folder>/category.tpl Find lines {if $products} <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {include file="./product-list.tpl" products=$products} <div class="content_sortPagiBar"> <div class="bottom-pagination-content clearfix"> {include file="./product-compare.tpl" paginationId='bottom'} {include file="./pagination.tpl" paginationId='bottom'} </div> </div> {/if} end remove wrapping {if $products}{/if}, so the content needed to be displayed 2. Open <theme_folder>/product-list.tpl Find lines at the bottom of file {addJsDef comparedProductsIds=$compared_products} {/if} and add additional contodion to {if} {addJsDef comparedProductsIds=$compared_products} {else} <ul{if isset($id) && $id} id="{$id}"{/if} class="product_list grid row{if isset($class) && $class} {$class}{/if}"> </ul> {/if} This ul.product_list needed to put content in there by ajax by blocklayered 3. Open <theme_folder>/js/modules/blocklayered/blocklayered.js and find initLayered() function. function initLayered() { initFilters(); initSliders(); initLocationChange(); updateProductUrl(); if (window.location.href.split('#').length == 2 && window.location.href.split('#')[1] != '') { var params = window.location.href.split('#')[1]; reloadContent('&selected_filters='+params); } } Extend condition like this if (window.location.href.split('#').length == 2 && window.location.href.split('#')[1] != '') { var params = window.location.href.split('#')[1]; reloadContent('&selected_filters='+params); } else { // Reload content if no filters enabled, to show all products on category page reloadContent(true); } So when page is loaded and no filters are applied blocklayered will return all products withiout filtering on accessing that page. Also you need to enable diplaying products from subcategories in module configuration. @aprex nice piece of code, but unfortunetaly it does not work on 1.6.0.11 in my case, that is weird as I am triing few different methods and nothing works, even on clean install with default template. Do you have any idea why could it be? 1 Link to comment Share on other sites More sharing options...
aprex Posted April 4, 2015 Share Posted April 4, 2015 @aprex nice piece of code, but unfortunetaly it does not work on 1.6.0.11 in my case, that is weird as I am triing few different methods and nothing works, even on clean install with default template. Do you have any idea why could it be? Have you configured layer navigation module filters? Link to comment Share on other sites More sharing options...
MarkusVisse Posted April 4, 2015 Share Posted April 4, 2015 Have you configured layer navigation module filters? Yes I did, but don't know why when I deleted the filter template and recreated it it worked. Thanks for the solution! Link to comment Share on other sites More sharing options...
dskarbek Posted April 7, 2015 Share Posted April 7, 2015 Hi, Thank you. It works. The only thing I modified was a line: $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang)); to: $sub=new Category(intval($subcategory['id_category']),intval($this->context->language->id)); Best regards, Darek 2 Link to comment Share on other sites More sharing options...
moy2010 Posted April 14, 2015 Share Posted April 14, 2015 Hi, dskarbek. What version of prestashop are you using? Link to comment Share on other sites More sharing options...
dominikprucha Posted April 30, 2015 Share Posted April 30, 2015 Please add instructions for 1.6.0.11 last instruction does not work Link to comment Share on other sites More sharing options...
drunkenmyno Posted May 8, 2015 Share Posted May 8, 2015 My solution for displaying all product from subcategories on category page for Prestashop 1.6.0.11 After hours of debug I discovered that blocklayered module can do the trick. Common idea is to show all products filtered by blocklayered. So some configuration is needed. 1. Open <theme_folder>/category.tpl Find lines {if $products} <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {include file="./product-list.tpl" products=$products} <div class="content_sortPagiBar"> <div class="bottom-pagination-content clearfix"> {include file="./product-compare.tpl" paginationId='bottom'} {include file="./pagination.tpl" paginationId='bottom'} </div> </div> {/if} end remove wrapping {if $products}{/if}, so the content needed to be displayed 2. Open <theme_folder>/product-list.tpl Find lines at the bottom of file {addJsDef comparedProductsIds=$compared_products} {/if} and add additional contodion to {if} {addJsDef comparedProductsIds=$compared_products} {else} <ul{if isset($id) && $id} id="{$id}"{/if} class="product_list grid row{if isset($class) && $class} {$class}{/if}"> </ul> {/if} This ul.product_list needed to put content in there by ajax by blocklayered 3. Open <theme_folder>/js/modules/blocklayered/blocklayered.js and find initLayered() function. function initLayered() { initFilters(); initSliders(); initLocationChange(); updateProductUrl(); if (window.location.href.split('#').length == 2 && window.location.href.split('#')[1] != '') { var params = window.location.href.split('#')[1]; reloadContent('&selected_filters='+params); } } Extend condition like this if (window.location.href.split('#').length == 2 && window.location.href.split('#')[1] != '') { var params = window.location.href.split('#')[1]; reloadContent('&selected_filters='+params); } else { // Reload content if no filters enabled, to show all products on category page reloadContent(true); } So when page is loaded and no filters are applied blocklayered will return all products withiout filtering on accessing that page. Also you need to enable diplaying products from subcategories in module configuration. thx you saved my day this is what i search for Link to comment Share on other sites More sharing options...
dominikprucha Posted July 14, 2015 Share Posted July 14, 2015 pleas upload modified files. thx Link to comment Share on other sites More sharing options...
Nash64 Posted August 2, 2015 Share Posted August 2, 2015 Do you have modifications under 1.6.1.0? 1 Link to comment Share on other sites More sharing options...
aljon ngo Posted August 30, 2015 Share Posted August 30, 2015 (edited) I have successfully done this in prestashop 1.6.1.0 I studied the thread and created my own version, here is my solution first open controllers/front/CategoryController.php find function assignSubcategories() and replace it with this code. protected function assignSubcategories() { if ($sub_categories = $this->category->getSubCategories($this->context->language->id)) { $subcategory_objects=array(); $this->context->smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($sub_categories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang)); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $this->context->smarty->assign("subcategories_objects",$subcategory_objects); $this->context->smarty->assign(array( 'subcategories' => $sub_categories, 'subcategories_nb_total' => count($sub_categories), 'subcategories_nb_half' => ceil(count($sub_categories) / 2) )); } } 2nd step is to open "your theme"/category.tpl and find this code <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {include file="./product-list.tpl" products=$products} Replace it with <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="./product-list-sub.tpl" products=$subcategory_object->getProducts('1','1','100')} {/foreach} {else} {include file="./product-list.tpl" products=$products} {/if} 3rd Step, This is not mentioned in the thread but this is the most important part. copy your product-list.tpl and rename it as product-list-sub.tpl <!-- Products list --> <h4>{$subcategory.name|escape:'htmlall':'UTF-8'}</h4> you can add this code to product-list-sub.tpl to show the name of the category and that's it, Thank you guys. Edited August 30, 2015 by aljon ngo (see edit history) 3 Link to comment Share on other sites More sharing options...
trace Posted September 25, 2015 Share Posted September 25, 2015 (edited) I have successfully done this in prestashop 1.6.1.0 It's not work for me. Please help. Prestashop 1.6.1.0 After disable blocklayared module, it's worked. Edited October 10, 2015 by trace (see edit history) Link to comment Share on other sites More sharing options...
Kda Posted October 19, 2015 Share Posted October 19, 2015 I have successfully done this in prestashop 1.6.1.0 I studied the thread and created my own version, here is my solution first open controllers/front/CategoryController.php find function assignSubcategories() and replace it with this code. protected function assignSubcategories() { if ($sub_categories = $this->category->getSubCategories($this->context->language->id)) { $subcategory_objects=array(); $this->context->smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($sub_categories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang)); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $this->context->smarty->assign("subcategories_objects",$subcategory_objects); $this->context->smarty->assign(array( 'subcategories' => $sub_categories, 'subcategories_nb_total' => count($sub_categories), 'subcategories_nb_half' => ceil(count($sub_categories) / 2) )); } } 2nd step is to open "your theme"/category.tpl and find this code <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {include file="./product-list.tpl" products=$products} Replace it with <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="./product-list-sub.tpl" products=$subcategory_object->getProducts('1','1','100')} {/foreach} {else} {include file="./product-list.tpl" products=$products} {/if} 3rd Step, This is not mentioned in the thread but this is the most important part. copy your product-list.tpl and rename it as product-list-sub.tpl <!-- Products list --> <h4>{$subcategory.name|escape:'htmlall':'UTF-8'}</h4> you can add this code to product-list-sub.tpl to show the name of the category and that's it, Thank you guys. Thank you! you really helped 1 Link to comment Share on other sites More sharing options...
mohuapolley Posted November 27, 2015 Share Posted November 27, 2015 BIgZumo,I have tried the process you have mention above.... but couldn't figure out how will user see the page where all categories are shown? Moreover, how can I add the category link in the horizontal menu? Thanks in advance Link to comment Share on other sites More sharing options...
Cloud Nine Posted March 11, 2016 Share Posted March 11, 2016 (edited) Hi, The code given by aljon ngo is working. Thank you very much. However, products are divided by categories. Do you know how i can display all products orderd by id or date added ? Also, there is no pagination with this code. How can i add pagination ? in product-list.tpl, there is : {include file="./product-list.tpl" products=$products} But it’s not included in product-list-sub.tpl Edited March 11, 2016 by Cloud Nine (see edit history) Link to comment Share on other sites More sharing options...
Cloud Nine Posted March 11, 2016 Share Posted March 11, 2016 (edited) I wanted to display all products. I’ve modified homefeatured in order to display all products from category home with pagination. I know we can use block layered navigation module (see that post) but i have an issue with pagination with this module (see that post) https://www.prestashop.com/forums/topic/330549-display-subcategory-products-in-parent-category/?p=1722811 I’ve use this code : https://www.prestashop.com/forums/topic/471327-pagination-homefeatured-finally-working/ (works on Prestashop 1.6.1.1) I’ve added all products to home with a sql query : INSERT IGNORE INTO ps_category_product SELECT 2, id_product, ((SELECT MAX(position) FROM ps_category_product WHERE id_category = 2) + (@inc := @inc + 1)) FROM ps_product INNER JOIN (SELECT @inc := 0) AS i source : http://stackoverflow.com/questions/24389229/mass-product-category-update-adding-home-category-to-all-products-prestash Edited March 11, 2016 by Cloud Nine (see edit history) Link to comment Share on other sites More sharing options...
reneerd Posted March 28, 2016 Share Posted March 28, 2016 BZ I just want to thank you for the easy to follow formatting. Anyone willing to help others is gold in my book but I think too many of them think most have a similar expertise as them. I have pulled out hair trying to follow some other people. You on the other hand broke it up and laid it out perfectly. Here is my Tutorial (Tested with PrestaShop v. 1.5.2.0 AND 1.5.4.1):open this file: controllers/front/CategoryController.phpsearch this lines: if ($subCategories = $this->category->getSubCategories($this->context->language->id)) { Link to comment Share on other sites More sharing options...
amerbb Posted April 15, 2016 Share Posted April 15, 2016 I tried this its not working... Do you have a solution for prestashop version 1.6.1.4 thanks Link to comment Share on other sites More sharing options...
BertrandETennis Posted June 16, 2016 Share Posted June 16, 2016 Here is my Tutorial (Tested with PrestaShop v. 1.5.2.0 AND 1.5.4.1): open this file: controllers/front/CategoryController.php search this lines: if ($subCategories = $this->category->getSubCategories($this->context->language->id)) { insert this code after the: { $subcategory_objects=array(); $this->context->smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($subCategories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang)); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $this->context->smarty->assign("subcategories_objects",$subcategory_objects); save this file and upload. now open the file: themes/"your_theme"/category.tpl search this lines: <div class="content_sortPagiBar"> {include file="$tpl_dir./pagination.tpl"} <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./product-compare.tpl"} {include file="./nbr-product-page.tpl"} </div> </div> insert after the </div></div>: {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="./product-list-sub.tpl" products=$subcategory_object->getProducts('1','1','100')} {/foreach} {else} {include file="./product-list.tpl" products=$products} {/if} save and upload. now open this file: themes/"your_theme"/product-list.tpl search this line: <!-- Products list --> after the line insert this: <h4>{$subcategory.name|escape:'htmlall':'UTF-8'}</h4> search this line: {foreach from=$products item=product name=products} after this line add: {if $products != ''} now search this lines: <a class="button lnk_view" href="{$product.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}">{l s='View'}</a> </div> </li> after this lines add: {else} No Products in this Category {/if} save the product-list.tpl as product-list-sub.tpl and upload the files. DONE!!! I hope it will works... contact me if you have problems.... sorry for my bad english best regards It worked for me but when I use blocklayered, it use product-list.tpl so everything is broken . Any idea for blocklayered to order subcategories the same way ? Thanks Link to comment Share on other sites More sharing options...
amerobb Posted June 27, 2016 Share Posted June 27, 2016 (edited) Hello everyone , I test this solution in version 1.6.4.1, it gives me an empty list can you help me please !!!!!! Edited June 27, 2016 by amerobb (see edit history) Link to comment Share on other sites More sharing options...
kevdev Posted July 7, 2016 Share Posted July 7, 2016 assuming you're working with aljon ngo's version, the product loop is inside an {if $products} which will be false if there are no product in your (home) category, instant solution is to associate some product to this category, template solution is to get this loop out of the condition. Link to comment Share on other sites More sharing options...
Kerm Posted August 17, 2016 Share Posted August 17, 2016 Hello, if you need show all products from subcategories in parent category, here's what you need to do: This is my own solution to this problem.This solution works great on versions 1.6.1 and higher. Open file classes/Category.php and find function getProducts() Inside at the top of the function code, write this: $id_parent = (int)$this->id; $parent = new Category((int)$id_parent); Below in function find this code: /** Return only the number of products */ if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = '.(int)$this->id. ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''). ($active ? ' AND product_shop.`active` = 1' : ''). ($id_supplier ? 'AND p.id_supplier = '.(int)$id_supplier : ''); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } And replace this code, on this one: /** Return only the number of products */ if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` LEFT JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category) WHERE c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright.' AND c.active = 1 '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''). ($active ? ' AND product_shop.`active` = 1' : ''). ($id_supplier ? 'AND p.id_supplier = '.(int)$id_supplier : ''); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } You simple need add one LEFT JOIN: LEFT JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category) And replace WHERE in sql request on this: WHERE c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright.' AND c.active = 1 Below in function find this code: $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) AS quantity'.(Combination::isFeatureActive() ? ', IFNULL(product_attribute_shop.id_product_attribute, 0) AS id_product_attribute, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity' : '').', pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, image_shop.`id_image` id_image, il.`legend` as legend, m.`name` AS manufacturer_name, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB("'.date('Y-m-d').' 00:00:00", INTERVAL '.(int)$nb_days_new_product.' DAY)) > 0 AS new, product_shop.price AS orderprice FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? ' LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` product_attribute_shop ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop='.(int)$context->shop->id.')':'').' '.Product::sqlStock('p', 0).' INNER JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category AND c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' AND cp.`id_category` = '.(int)$this->id .($active ? ' AND product_shop.`active` = 1' : '') .($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : ''); And replace on this one: $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) AS quantity'.(Combination::isFeatureActive() ? ', IFNULL(product_attribute_shop.id_product_attribute, 0) AS id_product_attribute, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity' : '').', pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, image_shop.`id_image` id_image, il.`legend` as legend, m.`name` AS manufacturer_name, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB("'.date('Y-m-d').' 00:00:00", INTERVAL '.(int)$nb_days_new_product.' DAY)) > 0 AS new, product_shop.price AS orderprice FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` '.Shop::addSqlAssociation('product', 'p'). (Combination::isFeatureActive() ? ' LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` product_attribute_shop ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop='.(int)$context->shop->id.')':'').' '.Product::sqlStock('p', 0).' LEFT JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' AND c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright.' AND c.active = 1 '.($active ? ' AND product_shop.`active` = 1' : '') .($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : ''); Here you need do all the same, add LEFT JOIN and change WHERE section in sql request. Thats all!!! PLEASE NOT: If you use blocklayered module, you dont need this fix, just turn on show product from subcategories in module settings. Also i attach file, you can download this file and upload inside this folder: /override/classes/ Category.php Dont forget delete after this file: /cache/class_index.php If you already have this file inside override folder, you need copy getProducts function from this file and write this function inside your old file. Link to comment Share on other sites More sharing options...
Kerm Posted August 19, 2016 Share Posted August 19, 2016 Small fix. i found bug, you need change: if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total on if ($get_total) { $sql = 'SELECT COUNT(DISTINCT cp.`id_product`) AS total 1 Link to comment Share on other sites More sharing options...
[email protected] Posted August 23, 2016 Share Posted August 23, 2016 Small fix. i found bug, you need change: if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total on if ($get_total) { $sql = 'SELECT COUNT(DISTINCT cp.`id_product`) AS total Nice its work! I use version 1.6.1.0 - http://centrumelektroniki.pl/Art-elektryczne,c533 Link to comment Share on other sites More sharing options...
arpheel Posted November 10, 2016 Share Posted November 10, 2016 Good day everyone! I'm newbie from Prestashop. I'm using Prestashop 1.6.1.7; how can I edit category name and sub category without editing the codes, just using the admin control panel? I just want to maximize the Prestashop as it is without buying modules, due to budget constraint. Thank you and I look forward to hear from you. Link to comment Share on other sites More sharing options...
bonsaiko Posted December 28, 2016 Share Posted December 28, 2016 Thanks. I did as explained but $subcategories_objects seems to be empty... But when I display subcategory, it contains the subcategory, so I don't understand. Could you please help me ? Link to comment Share on other sites More sharing options...
GOKULAN R Posted February 7, 2017 Share Posted February 7, 2017 I find this error Fatal error: Uncaught --> Smarty: Unable to load template file 'F:\01.xamp\htdocs\prestashop/themes/pf_flipcart/./product-list-sub.tpl' in 'F:\01.xamp\htdocs\prestashop/themes/pf_flipcart/category.tpl' <-- thrown in F:\01.xamp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php on line 129 Link to comment Share on other sites More sharing options...
pxlmn Posted May 6, 2017 Share Posted May 6, 2017 HiBased on #67, my solution for Prestashop 1.6.1.7 (maybe cleaner with controller override...) Create a new file CategoryController.php in override/controllers/front/ class CategoryController extends CategoryControllerCore { protected function assignSubcategories() { if ($sub_categories = $this->category->getSubCategories($this->context->language->id)) { $subcategory_objects=array(); $this->context->smarty->assign("andr_lang", $this->context->language->id); foreach ($sub_categories as $subcategory){ $sub = new Category(intval($subcategory['id_category']), $this->context->language->id); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $this->context->smarty->assign("subcategories_objects", $subcategory_objects); $this->context->smarty->assign(array( 'subcategories' => $sub_categories, 'subcategories_nb_total' => count($sub_categories), 'subcategories_nb_half' => ceil(count($sub_categories) / 2) )); } } } Don't forget to delete the cache... Best Link to comment Share on other sites More sharing options...
PureeMaison Posted August 16, 2017 Share Posted August 16, 2017 Hi, Did anyone succeed to do it with Prestashop 1.7 ? Thanks ! Link to comment Share on other sites More sharing options...
FrankSCW Posted November 21, 2017 Share Posted November 21, 2017 (edited) Hi, i need a complete procedure for prestashop 1.6.1.17. I'm try all i read in this post but i'm little confused. Thanks! Ps. sorry for my english. Edited November 21, 2017 by FrankSCW (see edit history) Link to comment Share on other sites More sharing options...
anu Posted January 18, 2018 Share Posted January 18, 2018 Hello .... I'm using Prestashop 1.6.1.17... is it compatible for that code .. it's working but missing header .. Link to comment Share on other sites More sharing options...
Baroszek Posted July 19, 2018 Share Posted July 19, 2018 Maybe somebody got solution this problem in presta 1.7.3 ? Need backup Link to comment Share on other sites More sharing options...
Malcom24 Posted September 7, 2018 Share Posted September 7, 2018 On 30/08/2015 at 7:21 PM, aljon ngo said: I have successfully done this in prestashop 1.6.1.0 I studied the thread and created my own version, here is my solution first open controllers/front/CategoryController.php find function assignSubcategories() and replace it with this code. protected function assignSubcategories() { if ($sub_categories = $this->category->getSubCategories($this->context->language->id)) { $subcategory_objects=array(); $this->context->smarty->assign("andr_lang",intval($cookie->id_lang)); foreach ($sub_categories as $subcategory) { $sub=new Category(intval($subcategory['id_category']),intval($cookie->id_lang)); $subcategory_objects[$subcategory['id_category']]=$sub; } //var_dump($subcategory_objects); $this->context->smarty->assign("subcategories_objects",$subcategory_objects); $this->context->smarty->assign(array( 'subcategories' => $sub_categories, 'subcategories_nb_total' => count($sub_categories), 'subcategories_nb_half' => ceil(count($sub_categories) / 2) )); } } 2nd step is to open "your theme"/category.tpl and find this code <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {include file="./product-list.tpl" products=$products} Replace it with <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix"> {include file="./product-sort.tpl"} {include file="./nbr-product-page.tpl"} </div> <div class="top-pagination-content clearfix"> {include file="./product-compare.tpl"} {include file="$tpl_dir./pagination.tpl"} </div> </div> {if isset($subcategories)} {foreach from=$subcategories item=subcategory} {assign var="subcategory_id" value=$subcategory.id_category} {assign var="subcategory_object" value=$subcategories_objects.$subcategory_id} {include file="./product-list-sub.tpl" products=$subcategory_object->getProducts('1','1','100')} {/foreach} {else} {include file="./product-list.tpl" products=$products} {/if} 3rd Step, This is not mentioned in the thread but this is the most important part. copy your product-list.tpl and rename it as product-list-sub.tpl <!-- Products list --> <h4>{$subcategory.name|escape:'htmlall':'UTF-8'}</h4> you can add this code to product-list-sub.tpl to show the name of the category and that's it, Thank you guys. I have a problem with this solution in 1.6.1 : Product images are not showing, the link appears broken. Please see https://stackoverflow.com/questions/52218895/prestashop-product-images-not-showing-in-category-loop-with-friendly-urls Link to comment Share on other sites More sharing options...
jackyvignon Posted October 15, 2019 Share Posted October 15, 2019 On 7/20/2018 at 12:04 AM, Baroszek said: Maybe somebody got solution this problem in presta 1.7.3 ? Need backup Hi everyone ! This case is so old ! I need this for 1.7.6.1 😅 Anybody has a clue to solve it because older solutions are not working 😕 Cheers ! Link to comment Share on other sites More sharing options...
jackyvignon Posted October 16, 2019 Share Posted October 16, 2019 9 hours ago, ndiaga said: There is a module that does the same for 1.7 but it is for the home page listing. Here it is: Thank you so much ndiaga ! Do you think this module can also do this listing in category page ? Not only in homepage. If so I definitely want to buy it 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