Jump to content

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


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

Link to comment
Share on other sites

in category controller you get this

 

 

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)));

}

 

 

so subcategories is seted

Link to comment
Share on other sites

Yes, that's true. Problem is, that corresponding tpl file isn't showing subcategories. But if I replace the $subcategories with for example $my_products, now it is working (with the same code, just change the name of variable). So I guess somewhere during the process between controler and view the variable $subcategories is unseted (I've tested it by condition {if isset($subcategories)} in tpl file ).

Link to comment
Share on other sites

×
×
  • Create New...