bakte Posted December 7, 2012 Share Posted December 7, 2012 Hello, I am trying to set up facebook meta OG for my website, but i can't retrieve image from products for my like button. It seems to have change from < 1.5. Any hints ? Thanks a lot ! Link to comment Share on other sites More sharing options...
clayton29657 Posted December 7, 2012 Share Posted December 7, 2012 Hey bakte take a look at design hause blog with this info hope it helps. just change the url i dont want to link up http :// blog dot dh42 dot com/prestashop-and-og-tags/ Link to comment Share on other sites More sharing options...
Dh42 Posted December 7, 2012 Share Posted December 7, 2012 Ok, this is what you would need to do. You have to override the front controller. Make an override for the preProcess class like this. public function preProcess() { if (page =="product"){ $product = new Product($_GET['id_product'], false, intval($cookie->id_lang)); if (Validate::isLoadedObject($product)) self::$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'); self::$smarty->assign('cover', $cover); } } Then in your page put if (page =="product") <meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')}"> {else} <meta property="og:image" content="{$logo_url}"> {/if} Link to comment Share on other sites More sharing options...
bakte Posted December 12, 2012 Author Share Posted December 12, 2012 Hello Dh42, Thanks for your answer, but it doesn't seems to work. Only the {$logo_url} parse even on a product page! Link to comment Share on other sites More sharing options...
Dh42 Posted December 12, 2012 Share Posted December 12, 2012 opps, the if statement breaks it, this works, I tested it public function preProcess() { $product = new Product($_GET['id_product'], false, intval($cookie->id_lang)); if (Validate::isLoadedObject($product)) self::$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'); self::$smarty->assign('cover', $cover); } Link to comment Share on other sites More sharing options...
Jeevan Posted May 1, 2013 Share Posted May 1, 2013 Can you please explain in wich file ( name ) I should put both codes. Link to comment Share on other sites More sharing options...
TheFunkyOrchard Posted May 28, 2013 Share Posted May 28, 2013 I also need to know which file this is in, please? Could one of the OPs let us know? I'm using Prestashop4.0, but may move to 5 eventually, so it would also be useful to know whether the same changes will work in 5? Link to comment Share on other sites More sharing options...
Dh42 Posted May 28, 2013 Share Posted May 28, 2013 YOu can either make an override for the front controller or place it directly in the front controller. Read this, http://blog.dh42.com/using-the-product-image-in-og-tags/ Link to comment Share on other sites More sharing options...
TheFunkyOrchard Posted May 28, 2013 Share Posted May 28, 2013 Can you please explain in wich file ( name ) I should put both codes. Hey Jeevan. I've found the answer. It's the header.tpl fil. Good article here: http://blog.dh42.com/prestashop-and-og-tags/ Link to comment Share on other sites More sharing options...
Dh42 Posted May 28, 2013 Share Posted May 28, 2013 The link you posted will not make the product image be available, it will use your logo for the product picture. The one I posted shows you how to override the front controller class and add to the preprocess class so that the product image is retrieved during the load of the header of the page. Link to comment Share on other sites More sharing options...
TheFunkyOrchard Posted May 29, 2013 Share Posted May 29, 2013 The link you posted will not make the product image be available, it will use your logo for the product picture. It tells you how to change it from the logo to a product image! (You only glanced at it didn't you ) The one I posted shows you how to override the front controller class and add to the preprocess class so that the product image is retrieved during the load of the header of the page. Your reply to the forum hadn't actually turned up when I sent my second message. I'm too tired to actually follow the link you posted now. Can you answer my question from my previous comment though? The stuff you originally posted a couple of years ago - which file is it in? Link to comment Share on other sites More sharing options...
PrestaFanBoy Posted September 8, 2013 Share Posted September 8, 2013 (edited) The link you posted will not make the product image be available, it will use your logo for the product picture. The one I posted shows you how to override the front controller class and add to the preprocess class so that the product image is retrieved during the load of the header of the page. Hello Dh42, this solution posted above is not working for PS 1.5.3.1:( What I have done is replaced the existing preprocess code in frontcontroller.php with the code shown above. And place the og tag code in header.tpl under header hook. Is there anything that I missed? Im getting server error. Thanks for any suggestion. PrestaFanBoy Edited September 8, 2013 by PrestaFanBoy (see edit history) Link to comment Share on other sites More sharing options...
Dh42 Posted September 8, 2013 Share Posted September 8, 2013 What server error are you getting? Link to comment Share on other sites More sharing options...
Dh42 Posted September 8, 2013 Share Posted September 8, 2013 I just checked it out and I see what you mean. I don't have any installations of 1.5.3.1 any where, so I tested this on 1.5.4.1 and it should fix you up. I added this to the initContent of the front controller If(isset($_GET['id_product'])){ $product = new Product($_GET['id_product'], false, intval($this->context->language->id)); if (Validate::isLoadedObject($product)) self::$smarty->assign('product', $product); $images = $product->getImages(intval($this->context->language->id)); 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']); [spam-filter] if (!isset($cover)) $cover = array('id_image' => Language::getIsoById($this->context->language->id).'_default', 'legend' => 'No picture', 'title' => 'No picture'); self::$smarty->assign('cover', $cover); Then in the code you put in the theme file I changed image to <meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')}"> If you are not using large_default, you will have to change the image from that. 3 Link to comment Share on other sites More sharing options...
PrestaFanBoy Posted September 10, 2013 Share Posted September 10, 2013 I just checked it out and I see what you mean. I don't have any installations of 1.5.3.1 any where, so I tested this on 1.5.4.1 and it should fix you up. I added this to the initContent of the front controller If(isset($_GET['id_product'])){ $product = new Product($_GET['id_product'], false, intval($this->context->language->id)); if (Validate::isLoadedObject($product)) self::$smarty->assign('product', $product); $images = $product->getImages(intval($this->context->language->id)); 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']); [spam-filter] if (!isset($cover)) $cover = array('id_image' => Language::getIsoById($this->context->language->id).'_default', 'legend' => 'No picture', 'title' => 'No picture'); self::$smarty->assign('cover', $cover); Then in the code you put in the theme file I changed image to <meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')}"> If you are not using large_default, you will have to change the image from that. Hello Dh42, Your fix seems to be working. Now im able to see associated images sharing to Facebook. Thank you very much.. PrestaFanBoy Link to comment Share on other sites More sharing options...
ElangLiar Posted November 17, 2013 Share Posted November 17, 2013 I just checked it out and I see what you mean. I don't have any installations of 1.5.3.1 any where, so I tested this on 1.5.4.1 and it should fix you up. I added this to the initContent of the front controller If(isset($_GET['id_product'])){ $product = new Product($_GET['id_product'], false, intval($this->context->language->id)); if (Validate::isLoadedObject($product)) self::$smarty->assign('product', $product); $images = $product->getImages(intval($this->context->language->id)); 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']); [spam-filter] if (!isset($cover)) $cover = array('id_image' => Language::getIsoById($this->context->language->id).'_default', 'legend' => 'No picture', 'title' => 'No picture'); self::$smarty->assign('cover', $cover); Then in the code you put in the theme file I changed image to <meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')}"> If you are not using large_default, you will have to change the image from that. Hi, where can i add this script? please help thank you Link to comment Share on other sites More sharing options...
YiannisK Posted November 24, 2013 Share Posted November 24, 2013 (edited) first part at /classes/controller/FrontController.php near 413 line second part at /themes/your_theme/header.tpl My changes for header.tpl {if $page_name == 'product'} <meta property="og:type" content="product" /> <meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')}"> {/if} {if $page_name != 'product'} <meta property="og:type" content="website" /> <meta property="og:image" content="{$img_ps_dir}logo-1.jpg"> {/if} PS: Thanks a lot for your help! Edited November 24, 2013 by joss54 (see edit history) Link to comment Share on other sites More sharing options...
ps3z Posted September 1, 2015 Share Posted September 1, 2015 first part at /classes/controller/FrontController.php near 413 line second part at /themes/your_theme/header.tpl My changes for header.tpl {if $page_name == 'product'} <meta property="og:type" content="product" /> <meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')}"> {/if} {if $page_name != 'product'} <meta property="og:type" content="website" /> <meta property="og:image" content="{$img_ps_dir}logo-1.jpg"> {/if} PS: Thanks a lot for your help! i would to use different size for facebookshares.its recommended 600x315 size, as default its using large_default images. i will set the size specially for it. is there possible to use as named facebook_default ? Regards Matt Link to comment Share on other sites More sharing options...
Recommended Posts