Jump to content

How to display subcategory name in the home featured product block


Recommended Posts

I am customising the homefeatured block to show products. Everything works fine except I also need to display the subcategory of the product instead of the product name. I am using the following code in homefeatured.php:

function hookHome($params)
   {
       global $smarty;

       $category = new Category(1);
       $nb = intval(Configuration::get('HOME_FEATURED_NBR'));
       $products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));
       $smarty->assign(array('products' => $products, 'homeSize' => Image::getSize('home')));



       global $link;
       $smarty->assign(array(
           'categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true),
           'link' => $link
       ));

   return $this->display(__FILE__, 'homefeatured.tpl');
   }

}



With the code I am able to retrieve the parent category name. But I need the child category name. Please help!

Link to comment
Share on other sites

  • 5 months later...

To show subcategory name in homefeatured module

Replace following line of module->homefeatured->homefeatured.tpl

{$product.name|truncate:27:'...'|escape:'htmlall':'UTF-8'}



with the code

{$product.name|truncate:27:'...'|escape:'htmlall':'UTF-8'}
categorie name-> {$product.category_default}




you have to add {$product.category_default} in foreach loop under li

Link to comment
Share on other sites

Hi Dambie

here is complete code with proper link to subcategorie
I found that this editor skip href="{$link-> and display complete code so I have attached code.txt file please find the attachment for complete code and also let me know if You have any idea why editor skips that code

To show subcategory name in homefeatured module

Replace following line of module->homefeatured->homefeatured.tpl

{$product.name|truncate:27:'...'|escape:'htmlall':'UTF-8'}



with the code

{$product.name|truncate:27:'...'|escape:'htmlall':'UTF-8'}
categorie name-> 
getCategoryLink($product.id_category_default, $category.link_rewrite)}" title="{l s='More about'} {$product.category_default}">[spam-filter]$product.category_default}|escape:'htmlall':'UTF-8'}




you have to add {$product.category_default} in foreach loop under li

code.txt

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...
  • 3 weeks later...
  • 2 months later...

Vivek,

 

Thanks for the code , My prestashop version is 1.3.6 , and with the link

 

<a href="{$link->getCategoryLink($product.id_category_default, $category.link_rewrite)}" title="{l s='More about'} {$product.category_default}">[spam-filter]$product.category_default}|escape:'htmlall':'UTF-8'}</a>

 

It doesn't work ,my hooked featured module is blank

 

help would be apprieciated

Link to comment
Share on other sites

  • 2 years 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...