Coluccini Posted May 20, 2013 Share Posted May 20, 2013 Hi, I thought that this would be simple, but I've already spent 3 hours trying to find the answer without luck! I want to display the default category name of each product listed in product-list.tpl. I've followed this example from TWDesign, but it only works at the product page (and it seems that is not showing default category but the top category). Can you at least help me to modify that example so it works on product-list as well? Thanks! Link to comment Share on other sites More sharing options...
vekia Posted May 20, 2013 Share Posted May 20, 2013 what prestashop version you use? it's important in this case Link to comment Share on other sites More sharing options...
Coluccini Posted May 20, 2013 Author Share Posted May 20, 2013 Well, I found a solution (although I'm not sure if it is the best solution): On controllers/front/CategoryController.php I've added the next two lines inside the foreach from assignProductList() $cat = new Category($product['id_category_default'], $this->context->language->id); $product["category_defaul_name"] = $cat->name; This way you can user $product.category_defaul_name on product-list.tpl 1 Link to comment Share on other sites More sharing options...
Coluccini Posted May 20, 2013 Author Share Posted May 20, 2013 (edited) Hi Vekia, I'm using 1.5.x. Do you think there is a better solution? Edited May 20, 2013 by Coluccini (see edit history) Link to comment Share on other sites More sharing options...
Coluccini Posted May 21, 2013 Author Share Posted May 21, 2013 Well, it seems that the default category name it was always there (I'm not sure how I miss it the thousand times I check the product array content) You can use this to print it out {$product.category_default} Link to comment Share on other sites More sharing options...
vekia Posted May 21, 2013 Share Posted May 21, 2013 As far as i know {$product.category_default} shows id, not name, so in this case you have to create object with category Link to comment Share on other sites More sharing options...
Coluccini Posted May 22, 2013 Author Share Posted May 22, 2013 It shows the ID at the product page, but if you look the getProducts() function at Classes/Category.php the SQL query has cl.`name` AS category_default on the SELECT clause, where cl is category_lang. If you're using layered navigation, you have to add that and the LEFT JOIN into the module's SQL query or you'll loose the category after filtering. Link to comment Share on other sites More sharing options...
vekia Posted May 22, 2013 Share Posted May 22, 2013 I marked this thread as solved thanks for your solution and suggestions i really appreciate it regards 1 Link to comment Share on other sites More sharing options...
mdusamaansari Posted April 2, 2014 Share Posted April 2, 2014 I marked this thread as solved thanks for your solution and suggestions i really appreciate it regards Hi Vekia, Can you give me the editions to be made on files? I cannot understand what Coluccini posted. Thanks in advance. Link to comment Share on other sites More sharing options...
sitte Posted April 22, 2015 Share Posted April 22, 2015 (edited) Hello. I'm reopening post because it's about the same case as mine. In prestashop 1.6.0.6 on product-list I have access to $product['category'] value. It's the category name but without polish accents. Is it a bug or I'm trying to use it improperly? From what I tested category_default displays category name with accents on homepage but on category page it's not defined at all. Edited April 22, 2015 by sitte (see edit history) Link to comment Share on other sites More sharing options...
sitte Posted April 23, 2015 Share Posted April 23, 2015 (edited) Ok. I found the way if somebody needs it. Tested on Prestashop 1.6.0.6 1. Overrride FrontController: Create new file: /override/classes/controller/FrontController.php with content: <?php class FrontController extends FrontControllerCore { public function init() { parent::init(); $kategorie=Category::getRootCategory()->getSimpleCategories(1); //1 is default language foreach ($kategorie AS $kategoria) $ListaKategorii[$kategoria[id_category]]=$kategoria['name']; self::$smarty->assign('kategorie', $ListaKategorii); } } 2. make frontController override work. I don't know why it's necessary. I thought it should work without this but: change /cache/class_index.php into this: 'FrontController' => array ( 'path' => 'override/classes/controller/FrontController.php', 'type' => 'class', ), 3. Use code: {$kategorie[$product['id_category_default']]} as default kategory name in product-list.tpl foreach function. It works for category and home pages and with filtered module. Edited April 23, 2015 by sitte (see edit history) 2 Link to comment Share on other sites More sharing options...
mlarino Posted May 11, 2015 Share Posted May 11, 2015 (edited) Thanks site! I was able to modify the file with your code and make it work, the only problem is that I am using 2 languages in my store, and this code only uses one language, the default (1). How could I make it work in 2 languages? So it loads the category name in Spanish and English. Thanks! ----- SOLVED: change the language ID (1) to: ($this->context->language->id) ----- Is it possible to use the same code: {$kategorie[$product['id_category_default']]} in the product.tpl title? right now it breaks the website, what do I nee dto modify to make it work in product pages? Thanks! Edited May 11, 2015 by mlarino (see edit history) 1 Link to comment Share on other sites More sharing options...
nosnevetzy Posted August 20, 2015 Share Posted August 20, 2015 Thanks sitte! It works! Prestashop 1.6+ Link to comment Share on other sites More sharing options...
iqit-commerce Posted August 29, 2015 Share Posted August 29, 2015 It is also possible do do it without core files modifications {if isset($product.id_category_default)} {assign var='catname' value=Category::getCategoryInformations(array($product.id_category_default))} {$catname[$product.id_category_default].name} {/if} 4 Link to comment Share on other sites More sharing options...
vekia Posted August 29, 2015 Share Posted August 29, 2015 this is for 1.6.x only right? ps 1.5.x doest have getCategoryInformations function in category controller Link to comment Share on other sites More sharing options...
ventura Posted August 30, 2015 Share Posted August 30, 2015 In 1.6 {$product.category|replace:"-":" "|escape:'html':'UTF-8'} Link to comment Share on other sites More sharing options...
vekia Posted August 31, 2015 Share Posted August 31, 2015 hello from your code i can read that $product.category variable contains string that is "seo" friendly, without specials characters, spaces etc? Link to comment Share on other sites More sharing options...
iqit-commerce Posted August 31, 2015 Share Posted August 31, 2015 this is for 1.6.x only right? ps 1.5.x doest have getCategoryInformations function in category controller Yes it is for ps 1.6 Link to comment Share on other sites More sharing options...
garyjj127 Posted September 15, 2015 Share Posted September 15, 2015 Are there simplified instructions for this not it's been solved? I have tried adding {if isset($product.id_category_default)}{assign var='catname' value=Category::getCategoryInformations(array($product.id_category_default))}{$catname[$product.id_category_default].name}{/if} I just end up with: Fatal error: Cannot use object of type Product as array in /var/www/vhosts/MYSITE/httpdocs/tools/smarty/sysplugins/smarty_internal_templatebase.php(171) : eval()'d code on line 344 Link to comment Share on other sites More sharing options...
kehezen Posted April 7, 2016 Share Posted April 7, 2016 (edited) Hi people, please why do I get the category friendly-url-alias instead of its name when I paste this following code into product.tpl ? <a href="{$link->getCategoryLink($product->id_category_default,$product->category)}" title="{$product->category}">{$product->category}</a> I'm actually struggling with displaying a product's parent category name. This is so sad. Edited April 7, 2016 by kehezen (see edit history) Link to comment Share on other sites More sharing options...
kehezen Posted April 7, 2016 Share Posted April 7, 2016 (edited) hello from your code i can read that $product.category variable contains string that is "seo" friendly, without specials characters, spaces etc? or is it that ? In my case, the category name is "Hélène Derrida" the friendly URL alias is "helene-derrida" and what is output is "helene-derrida". So what's going on ? Is there really no EASY way to fetch this ? If don't wanna sound mad, but actually I am. This is such a waste of time. Edited April 7, 2016 by kehezen (see edit history) Link to comment Share on other sites More sharing options...
Iazel Posted April 29, 2016 Share Posted April 29, 2016 (edited) Hi people, please why do I get the category friendly-url-alias instead of its name when I paste this following code into product.tpl ? <a href="{$link->getCategoryLink($product->id_category_default,$product->category)}" title="{$product->category}">{$product->category}</a> I'm actually struggling with displaying a product's parent category name. This is so sad. I had this exact same problem. It turns out that in prestashop 1.6 we have the `$category` object available in `product.tpl`. Therefore your example will be: <a href="{$link->getCategoryLink($category)}" title="{$category->name}">{$category->name}</a> Edited April 29, 2016 by Iazel (see edit history) Link to comment Share on other sites More sharing options...
premsuganesh Posted August 26, 2016 Share Posted August 26, 2016 Hi people, i assign product for root category and subcategory, i go to front office when i click root category after display all products for product listing page,how to display product for sub category wise in product listing page? for example, Womem->root category, tops->subcategoryname, display tops category products, Dresses->subcategory name, display Dresses category products Link to comment Share on other sites More sharing options...
premsuganesh Posted August 29, 2016 Share Posted August 29, 2016 we have a color switches setup for prestashop product page. but how to setup the product name to be changed based on the color selection in prestashop ? see this url :http://thepremises.org/dev/egos_shoes/en/shoe-women/67-shoe-limegreen.html#/15-size-36/10-color-green Link to comment Share on other sites More sharing options...
milaonline Posted June 13, 2017 Share Posted June 13, 2017 I think this is similar question: I would like do display default category thumbnail or icon visible on hover in .product-image-container in product-list.tpl Link to comment Share on other sites More sharing options...
dasteralo Posted September 13, 2017 Share Posted September 13, 2017 Hello, I am using this code {if isset($product.id_category_default)} {assign var='catname' value=Category::getCategoryInformations(array($product.id_category_default))} {$catname[$product.id_category_default].name} {/if} That works perfectly but what is the link to the default category ?Thank you.regards 1 Link to comment Share on other sites More sharing options...
gothw Posted December 13, 2017 Share Posted December 13, 2017 On 29/8/2015 at 6:31 PM, iqit-commerce said: It is also possible do do it without core files modifications {if isset($product.id_category_default)} {assign var='catname' value=Category::getCategoryInformations(array($product.id_category_default))} {$catname[$product.id_category_default].name} {/if} This works, perfectly, but anybody knows how to show the category image instead the name? Thanks Link to comment Share on other sites More sharing options...
uniparfum Posted February 13, 2018 Share Posted February 13, 2018 On 13/12/2017 at 11:40 AM, gothw said: This works, perfectly, but anybody knows how to show the category image instead the name? Thanks Where to put this code please to show the parent category on the products listing? Link to comment Share on other sites More sharing options...
gaur_ayush1421 Posted March 4, 2020 Share Posted March 4, 2020 On 12/13/2017 at 10:10 PM, gothw said: This works, perfectly, but anybody knows how to show the category image instead the name? Thanks On 12/13/2017 at 10:10 PM, gothw said: This works, perfectly, but anybody knows how to show the category image instead the name? Thanks where in put this code. i am in catalog/listing/category.tpl put thi code but not any chenges in my product page.. please give me better solustion..? thank You Link to comment Share on other sites More sharing options...
slavenja Posted September 5, 2020 Share Posted September 5, 2020 For Prestashop 1.6.24 - https://intopsite.ru/optimiziruem-kartochku-tovara-prestashop-1-6-x.html Link to comment Share on other sites More sharing options...
yngwie1978 Posted September 30, 2020 Share Posted September 30, 2020 Hello, need the same solution to show category name in product list for prestashop 1.7 Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now