mozack Posted August 27, 2010 Share Posted August 27, 2010 Hi,I'm facing some problems to load category and product name in header.tpl. Since the smarty arrays that contains this info are loaded after header.tpl, i cant use the {$product->name} or {$category->name} variables in header.tpl. How can i do that? assign this variables to header?My point is, in header put the category or product name ex.:{if $page == 'category'}{$category->name}{elseif $page=='product'}{$product->name}{else}{l s='Hi something'}{/if}How can i do that?ThanksMozack Link to comment Share on other sites More sharing options...
Patric Posted August 27, 2010 Share Posted August 27, 2010 Topic moved. Link to comment Share on other sites More sharing options...
rocky Posted August 28, 2010 Share Posted August 28, 2010 You'll need to add the following code in header.php before the $smarty->display: if ($page_name == 'category' AND isset($_GET['id_category'])) { $category = new Category($_GET['id_category'], intval($cookie->id_lang)); if (Validate::isLoadedObject($category)) $smarty->assign('category_name', $category->name); } elseif ($page_name == 'product' AND isset($_GET['id_product'])) { $product = new Product($_GET['id_product'], false, intval($cookie->id_lang)); if (Validate::isLoadedObject($product)) $smarty->assign('product_name', $product->name); } then you can add the following to header.tpl: {if isset($category_name)}{$category_name}{elseif isset($product_name)}{$product_name}{else}{l s='Hi something'}{/if} 1 Link to comment Share on other sites More sharing options...
mozack Posted August 28, 2010 Author Share Posted August 28, 2010 Hi Rocky,Thanks, I will try it asap.I will post here the results.Best Regards, and thanks! Link to comment Share on other sites More sharing options...
mozack Posted August 28, 2010 Author Share Posted August 28, 2010 Hi,It works like a charm... I'm sorry but i need one more help. Integrate the cover image of product to load in header as the product name... I was seeing the code but i can not figure it out.Thanks for all your help, RegardsMozack Link to comment Share on other sites More sharing options...
rocky Posted August 29, 2010 Share Posted August 29, 2010 So you want a small product cover image instead of the product name? To do that, you'll need to add the following to header.php: if ($page_name == 'category' AND isset($_GET['id_category'])) { $category = new Category($_GET['id_category'], intval($cookie->id_lang)); if (Validate::isLoadedObject($category)) $smarty->assign('category_name', $category->name); } elseif ($page_name == 'product' AND isset($_GET['id_product'])) { $product = new Product($_GET['id_product'], false, intval($cookie->id_lang)); if (Validate::isLoadedObject($product)) $smarty->assign('product', $product); $images = $product->getImages(intval($cookie->id_lang)); foreach ($images AS $k => $image) if ($image['cover']) { $cover = $image; $cover['id_image'] = intval($product->id).'-'.$cover['id_image']; $cover['id_image_only'] = intval($image['id_image']); } if (!isset($cover)) $cover = array('id_image' => Language::getIsoById($cookie->id_lang).'-default', 'legend' => 'No picture', 'title' => 'No picture'); $smarty->assign('cover', $cover); } then use the following in header.tpl: {if isset($category_name)}{$category_name}{elseif isset($product_name)}<img src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'small')}" title="{$product->name|escape:'htmlall':'UTF-8'}" alt="{$product->name|escape:'htmlall':'UTF-8'}" />{else}{l s='Hi something'}{/if} Link to comment Share on other sites More sharing options...
mozack Posted August 29, 2010 Author Share Posted August 29, 2010 Hi,Thanks for the code. I was forced to make some changes once the code you post have a small error. But i've done it well and now it works.ThanksMozack Link to comment Share on other sites More sharing options...
rocky Posted August 29, 2010 Share Posted August 29, 2010 What was the error I made so I can correct it above? Link to comment Share on other sites More sharing options...
mozack Posted August 29, 2010 Author Share Posted August 29, 2010 Hi,I've corrected the code, and now, the code is: if ($page_name == 'category' AND isset($_GET['id_category'])) { $category = new Category($_GET['id_category'], intval($cookie->id_lang)); if (Validate::isLoadedObject($category)) $smarty->assign('category_name', $category->name); } elseif ($page_name == 'product' AND isset($_GET['id_product'])) { $product = new Product($_GET['id_product'], false, intval($cookie->id_lang)); if (Validate::isLoadedObject($product)) $smarty->assign('product_name', $product->name); $images = $product->getImages(intval($cookie->id_lang)); foreach ($images AS $k => $image) if ($image['cover']) { $cover = $image; $cover['id_image'] = intval($product->id).'-'.$cover['id_image']; $cover['id_image_only'] = intval($image['id_image']); } if (!isset($cover)) $cover = array('id_image' => Language::getIsoById($cookie->id_lang).'-default', 'legend' => 'No picture', 'title' => 'No picture'); $smarty->assign('cover', $cover); } I think the problem was one }Thanks for your help, everything is right now...Regards Link to comment Share on other sites More sharing options...
rocky Posted August 29, 2010 Share Posted August 29, 2010 Thanks. I've corrected my code above so no-one else will encounter the error.Please edit your first post and add [sOLVED] to the front of the title. Link to comment Share on other sites More sharing options...
rocky Posted September 8, 2011 Share Posted September 8, 2011 By request, here's an override that does this modification in PrestaShop v1.4.4. Category and Product Name in Header TPL for PrestaShop v1.4.4.zip Link to comment Share on other sites More sharing options...
Wezzo Posted September 13, 2011 Share Posted September 13, 2011 Hi there, Thanks for this thread, its exactly what I was looking for... I have followed the instructions as listed above and downloaded the override function, but still no luck. the output gives me: http://127.0.0.1/prestashop/-small/.jpg no product id is pulled through. Any advice? PS. I am using PS 1.4.4 Thanks Link to comment Share on other sites More sharing options...
mr10 Posted September 28, 2011 Share Posted September 28, 2011 this does not work when using seo-friendly URL's, only when using product.php?id_product=xx does someone have any idea how to get this to work with sep-friendly urls? thank you Link to comment Share on other sites More sharing options...
mr10 Posted September 28, 2011 Share Posted September 28, 2011 sorry, i put in override/controllers instead of override/classes (confusing because of name frontcontroller) now it works. but if you want to get the cover image, you need to add code from post above (and add self:: before smarty assign) so after: if (Validate::isLoadedObject($product)) self::$smarty->assign('product_name', $product->name); place: $images = $product->getImages(intval($cookie->id_lang)); foreach ($images AS $k => $image) { if ($image['cover']) { $cover = $image; $cover['id_image'] = intval($product->id).'-'.$cover['id_image']; $cover['id_image_only'] = intval($image['id_image']); } } if (!isset($cover)) $cover = array('id_image' => Language::getIsoById($cookie->id_lang).'-default', 'legend' => 'No picture', 'title' => 'No picture'); self::$smarty->assign('cover', $cover); and in header.tpl: {if isset($product_name)}<meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'list')}" />{/if} it gives you: <meta property="og:image" content="http://easypeas.be/173-list/.jpg" /> but that is a valid image hope this will help 2 Link to comment Share on other sites More sharing options...
phpimran Posted January 23, 2012 Share Posted January 23, 2012 HI, rocky, i want to achieve the same thing but i cant. i have been using prestashop 1.4.6.2 please help. Link to comment Share on other sites More sharing options...
aduarte Posted January 31, 2012 Share Posted January 31, 2012 HI guys, my name is Abner and im new here.. i m also looking for this to work on 1.4.6.2.. any help would appriciated Link to comment Share on other sites More sharing options...
brandonc503 Posted May 10, 2012 Share Posted May 10, 2012 (edited) Sorry got lost, does it got in header.php, or frontcontroller? cause if (Validate::isLoadedObject($product)) isent found in eather. Edited May 10, 2012 by brandonc503 (see edit history) Link to comment Share on other sites More sharing options...
deviant666 Posted June 21, 2012 Share Posted June 21, 2012 sorry, i put in override/controllers instead of override/classes (confusing because of name frontcontroller) now it works. but if you want to get the cover image, you need to add code from post above (and add self:: before smarty assign) so after: if (Validate::isLoadedObject($product)) self::$smarty->assign('product_name', $product->name); place: $images = $product->getImages(intval($cookie->id_lang)); foreach ($images AS $k => $image) { if ($image['cover']) { $cover = $image; $cover['id_image'] = intval($product->id).'-'.$cover['id_image']; $cover['id_image_only'] = intval($image['id_image']); } } if (!isset($cover)) $cover = array('id_image' => Language::getIsoById($cookie->id_lang).'-default', 'legend' => 'No picture', 'title' => 'No picture'); self::$smarty->assign('cover', $cover); and in header.tpl: {if isset($product_name)}<meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'list')}" />{/if} it gives you: <meta property="og:image" content="http://easypeas.be/173-list/.jpg" /> but that is a valid image hope this will help Hello. Can you helo me to display category image instead of category title in header ? Link to comment Share on other sites More sharing options...
orwell Posted June 24, 2012 Share Posted June 24, 2012 This works great ! Very helpful information, which is helping me to understand how prestashop works a little more ! Link to comment Share on other sites More sharing options...
PEPPE83 Posted October 10, 2012 Share Posted October 10, 2012 any suggestion for the product description? when i share a product link on facebook the product description is blank (i dont use the shot description). sorry for my bad english. Link to comment Share on other sites More sharing options...
Consultor SEO - jlmora Posted December 3, 2012 Share Posted December 3, 2012 (edited) Hi, i want to show canonical link in header (header.tpl) <!-- canonical --> {if $page_name == 'index' or $page_name == 'search'} <link rel="canonical" href="{$base_dir}" /> {elseif $page_name == 'category' or $page_name == 'best-sales' or $page_name == 'cart' or $page_name == 'discount' or $page_name == 'manufacturer' or $page_name == 'new-products' or $page_name == 'prices-drop'} <link rel="canonical" href="{$base_dir}{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}" /> {else} <link rel="canonical" href="{$base_dir}{$product->id_category_default}-{$request_uri|substr:1|regex_replace:'/\/(.*)/':''|regex_replace:'/\?(.*)/':''}" /> {/if} But {$product->id_category_default} is not accesible from header.tpl Edited December 3, 2012 by jlmora (see edit history) Link to comment Share on other sites More sharing options...
m4rcel82 Posted January 4, 2013 Share Posted January 4, 2013 Hi! I'm a little confused. I don't know where exactly to put the PHP code for assigning the smarty variables. You wrote: "You'll need to add the following code in header.php before the $smarty->display" My header.php file contains only the following two lines: $controller = new FrontController(); $controller->displayHeader(); The assignment of the variables doesn't work when I put the code anywhere in this file. I'm using PrestaShop™ 1.4.4.1. Thanks for a little help! Link to comment Share on other sites More sharing options...
m4rcel82 Posted January 6, 2013 Share Posted January 6, 2013 Hi. I could solve my problem without editing any php file. I just put this code in my header.tpl file: {php} $product = new Product($_GET['id_product'], false, intval($cookie->id_lang)); $images = $product->getImages(intval($cookie->id_lang)); foreach ($images AS $k => $image) if ($image['cover']) { $cover = $image; $cover['id_image'] = intval($product->id).'-'.$cover['id_image']; $cover['id_image_only'] = intval($image['id_image']); echo("<meta property='og:image' content='img/p/".$cover['id_image']."-large.jpg' />"); } {/php} Link to comment Share on other sites More sharing options...
INTJP Posted October 22, 2014 Share Posted October 22, 2014 Hi Rocky, I know this is an old post but I am still using an old version of prestashop :-( I am looking to do something similar in my header : {if $page_name == 'product'}{$product->reference|escape:'htmlall':'UTF-8'} {$category->name|escape:'htmlall':'UTF-8'} {else} {l s='Hi something'}{/if} Any idea how I should proceed ? Thanks for your help. You'll need to add the following code in header.php before the $smarty->display: if ($page_name == 'category' AND isset($_GET['id_category'])){ $category = new Category($_GET['id_category'], intval($cookie->id_lang)); if (Validate::isLoadedObject($category)) $smarty->assign('category_name', $category->name);}elseif ($page_name == 'product' AND isset($_GET['id_product'])){ $product = new Product($_GET['id_product'], false, intval($cookie->id_lang)); if (Validate::isLoadedObject($product)) $smarty->assign('product_name', $product->name);} then you can add the following to header.tpl: {if isset($category_name)}{$category_name}{elseif isset($product_name)}{$product_name}{else}{l s='Hi something'}{/if} Link to comment Share on other sites More sharing options...
Denver Prophit Jr. Posted May 24, 2015 Share Posted May 24, 2015 What if you want to output the product category name in product.tpl to get category attribute inserted for schema product and schema offer? Link to comment Share on other sites More sharing options...
Denver Prophit Jr. Posted May 24, 2015 Share Posted May 24, 2015 I figured it out: <p id="product_category"><label>{l s='Category:'}</label> <span class="editable" itemprop="category">{$category->name|escape:'html':'UTF-8'}</span></p> Link to comment Share on other sites More sharing options...
Denver Prophit Jr. Posted May 24, 2015 Share Posted May 24, 2015 The https://schema.org/Product -> category still isn't being picked up. I have valid markup. I've created an issue at https://github.com/schemaorg/schemaorg/issues/536 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