Jump to content

Variable $subcategories ins't set in template category.tpl


MagicFire

Recommended Posts

Hi,

I have a little problem. I would like to show content of subcategories under one category.

 

Tree is:

  • Products
    • Boilers
      • Item 1
      • Item 2
      • ......

      [*]Burner 1

      • Item 1
      • Item 2
      • ......

      [*]Burner 2

      • Item 1
      • Item 2
      • .....

      [*]Accessories

      • Item 1
      • Item 2
      • ....

I'm using the plugin Menu v2.8.6 by Julien Breux to create the main navigation. But there is problem. When I click on the link to the category Products, the page tells that there is no products in this category (that's true, it's only container), but it doesn't show content of subcategories (for example one product for each category).

I found this code:

   if (isset($subCategories) AND !empty($subCategories) AND $subCategories)
{
 self::$smarty->assign('subcategories', $subCategories);
 self::$smarty->assign(array(
  'subcategories_nb_total' => sizeof($subCategories),
  'subcategories_nb_half' => ceil(sizeof($subCategories) / 2)));
}
if ($this->category->id != 1)
 $this->productListAssign();
self::$smarty->assign(array(
 'products' => (isset($this->cat_products) AND $this->cat_products) ? $this->cat_products : NULL,
 'id_category' => (int)($this->category->id),
 'id_category_parent' => (int)($this->category->id_parent),
 'return_category_name' => Tools::safeOutput($this->category->name),
 'path' => Tools::getPath((int)($this->category->id)),
 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
 'categorySize' => Image::getSize('category'),
 'mediumSize' => Image::getSize('medium'),
 'thumbSceneSize' => Image::getSize('thumb_scene'),
 'homeSize' => Image::getSize('home')
));

if (isset(self::$cookie->id_compare))
 self::$smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)self::$cookie->id_compare));
  }
 }

in CategoryController.php

and this:

 {if isset($subcategories)}
 <div id="subcategories">
  <h3>{l s='Subcategories'}</h3>
  <ul class="inline_list">
  {foreach from=$subcategories item=subcategory}
<li>
 <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$subcategory.name|escape:'htmlall':'UTF-8'}">
  {if $subcategory.id_image}
   <img src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />
  {else}
   <img src="{$img_cat_dir}default-medium.jpg" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />
  {/if}
 </a><br />
 <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>
</li>
  {/foreach}
  </ul>
  <br class="clear"/>
 </div>
{/if}

in category.tpl. But I figure out,that in this TPL file the variable $subcategories is not set. Do anybody know why?

 

Thanks

Edited by MagicFire (see edit history)
Link to comment
Share on other sites

Yes, let's call it a preview of items in subcathegory. I want to show one item from each subcategory .But I tried to change variable. So I changed $subCategories with my own $my_products (in the controller I just copy code

{
	 self::$smarty->assign('subcategories', $subCategories);
	 self::$smarty->assign(array(
	  'subcategories_nb_total' => sizeof($subCategories),
	  'subcategories_nb_half' => ceil(sizeof($subCategories) / 2)));
	}

 

to

 

....
$my_products = $this->category->getSubCategories((int)self::$cookie->id_lang);
.....
{
	 self::$smarty->assign('subcategories', $my_products);
	 self::$smarty->assign(array(
	  'subcategories_nb_total' => sizeof($subCategories),
	  'subcategories_nb_half' => ceil(sizeof($subCategories) / 2)));
}

 

with the same code (the original code was untouched) and it works. Not showing the product, but at least I was able to see the PS default "no image included" grey image. I set the description for categories and it was working, but I'm looking for more flexible solution (e.g. fist existing product from the category sound better to me than static text).

Edited by MagicFire (see edit history)
Link to comment
Share on other sites

As far as I can see it that's basically the same code.

 

To display 1 product from each subcategory, you will need to loop through the subcategory list and write a query to get 1 product from that specific category, then change the tpl file according to these modifications.

 

Regards.

 

Robin.

 

The CartExpert Team

Link to comment
Share on other sites

  • 4 weeks later...

using your example:

 

Products (parent category)

  • Boilers (subcategory)
    • Item 1
    • Item 2
    • .....

by default if your "Item 1" is assigned to only "subcategory" it wont display when you are viewing "parent category" but if your "Item 1" is assigned to both, "subcategory" and "parent category" it will display when you are viewing "parent category" and if you click on "subcategory" it will display too

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