Jump to content

Major Problem with subcategories


Recommended Posts

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

As 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

24573_mOr74Id1tsJgprToAO3v_t

Link to comment
Share on other sites

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

  • 2 weeks later...

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

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

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

  • 4 months later...

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

  • 3 months later...

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