Jump to content

How to modify subcategories?


Recommended Posts

Hello everyone,
I'm having major problems with my subcategories actually with Books category that have like 15 subcategories. When I click on Books category it list me with a list of subcategories like : Drama, Novel, History etc. And it should right. The problem is that I need like 15 subcategory pictures for it and when I put all the pcitures needed it look chaotic. I was wondering if it is possible to implement a feature that would display random books in the middle of the page instead of list of subcategories like it does now when I click on Books.
Thanks.

Link to comment
Share on other sites

Thanks Rocky,
do not want to be rude, but this one didnt helped me because I already have what I want on a home page. Problem is in subcategories. You know when you click on main category you get a list of subcategories with descriptions a pictures. My main category is Books, and have like 15 subcategories under Books category. What I want is to get rid of the subcategory pictures and instead of it put a random display of products in Book category. When a buyer wants to buy a Crime Book he should navigate to that subcategory trough category block on the left. Subcategory pictures are good idea if you have 2 or 3 subcategories under main category but having more than 5 become quite confusing and finding suitable pictures for subcategories can be quite a task and yet not to have visual effect that is required from a professional looking store.
Thank you very much for your support Rocky. Its not a first time you helped me :D

Link to comment
Share on other sites

this doesn't give you random products, but it will get rid of the images while keeping the links to the subcategories

in prestashop/themes//category.tpl
remove or comment out lines 27-34

make a backup of the file and try this out and see if it is suitable
I don't have make subcategories in my shop to see what it looks like

if you want to get rid of the image and link all together
remove or comment out lines 20-41

Link to comment
Share on other sites

I'm still not sure that I fully understand you. Do you want to display a few random products above the listings where the subcategories usually are? You can do this by adding the following code to category.php after line 59 ($cat_products = ...):

$random_products = $category->getProducts(intval($cookie->id_lang), 1, 1000, $orderBy, $orderWay, false, true, true, 4);


This code chooses 4 random products from the current category. You can then pass the random products into category.tpl:

$smarty->assign(array(
   'random_products' => (isset($random_products) AND $random_products) ? $random_products : NULL,
   'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL,
   'id_category' => intval($category->id),
   'id_category_parent' => intval($category->id_parent),
   'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)),
   'path' => Tools::getPath(intval($category->id), $category->name)
));



Then you can change the <!-- Subcategories --> section of category.tpl in your theme's directory to:

<!-- Subcategories -->

{l s='Random Products'}

   {foreach from=$random_products item=random_product}

           <a href="{$link->getProductLink($random_product.id_product, $random_product.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$random_product.name|escape:'htmlall':'UTF-8'}">
               {if $random_product.id_image}
                   <img src="{$link->getImageLink($random_product.link_rewrite, $random_product.id_image, 'medium')}" alt="" />
               {else}
                   <img src="{$img_prod_dir}default-medium.jpg" alt="">
               {/if}



           <a href="{$link->getProductLink($random_product.id_product, $random_product.link_rewrite)|escape:'htmlall':'UTF-8'}">{$random_product.name|truncate:25|escape:'htmlall':'UTF-8'}

   {/foreach}






Sorry if this isn't what you want. It is hard for me to help when I don't understand exactly what is wanted.

Link to comment
Share on other sites

Rocky you did it again. Thats what I wanted. You understood me perfectly and we are almost there. One more line of code and it will be perfect. As you know I have Main Category Books and I have the following subcategories : Crime Novels, Philosophy, History etc. Since Main Category Books doesn't have any listed books is it possible to pull random products from Crime Novels, Philosophy and History from those subcategories to be listed when a customer click on Books. Basically is it possible to get subcategory products to be listed in the parent category. As you put it only products from the current category is listed.
Example Books --> Crime --> Agatha Christie : Now Agatha Christie subcategory has 3 books and I want them to be displayed once in a while when a customer click on Books or Crime. Is this possible?
Thank you.

Link to comment
Share on other sites

Here's what I've come up with. Change line 418 of classes/Category.php from:

WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').'



to:

LEFT JOIN `'._DB_PREFIX_.'category` c ON (c.`id_category` = p.`id_category_default`)        
WHERE '.($random ? 'c.`id_parent` = '.intval($this->id):'cp.`id_category` = '.intval($this->id)).($active ? ' AND p.`active` = 1' : '').'



and on line 406, change SELECT to SELECT DISTINCT

Link to comment
Share on other sites

Try this instead:

LEFT JOIN `'._DB_PREFIX_.'category` c ON (c.`id_category` = p.`id_category_default`)        
WHERE cp.`id_category` = '.intval($this->id).($random ? ' OR c.`id_parent` = '.intval($this->id):'').($active ? ' AND p.`active` = 1' : '').'

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