Post by vaanbooch » Tue Mar 13, 2012 9:02 pm

Hello,

I'm trying to integrate a facebook like button on every product/product page. In order to specify the image shown on facebook I should pass a meta tag <meta property="og:image" content="current-product-thumb.jpg" /> from controller/product/product.php to the <head> section of common/header.tpl

Is it possible to pass a variable from a controller to another controller's view?
The OpenCart version is 1.5.1.3.

Thanks in advance!

VaanBooch

Be Easy Web Design


Newbie

Posts

Joined
Thu Dec 08, 2011 8:34 pm

User avatar
Active Member

Posts

Joined
Thu Nov 11, 2010 6:11 pm
Location - New Zealand (Tokomaru, Palmerston North)

Post by vaanbooch » Wed Mar 14, 2012 4:53 pm

Jeremy Fisk wrote:it sure is... but i always grab it in the other controller as well
You mean to get the current product's data in common/header.php again? It's possible, of course, but I wonder if there is a more ellegant way to do it ....

Be Easy Web Design


Newbie

Posts

Joined
Thu Dec 08, 2011 8:34 pm

Post by Jeremy Fisk » Thu Mar 15, 2012 2:23 am

vaanbooch wrote:
Jeremy Fisk wrote:it sure is... but i always grab it in the other controller as well
You mean to get the current product's data in common/header.php again? It's possible, of course, but I wonder if there is a more ellegant way to do it ....
Dunno... but what i often do is put in a get request for the product ID and then grab the corrosponding info from the database

Hand Dryers

Bookstore Mod
QuickShop Module
Restricted Access - Compulsory Login
Template Override - Category Specific (vQmod)
Template Override - Brand Specific (vQmod)
How did you find out about us register question mod
Compulsory Login vQmod
Brands In Top Menu
zoom - Product Image - Auto on hover


User avatar
Active Member

Posts

Joined
Thu Nov 11, 2010 6:11 pm
Location - New Zealand (Tokomaru, Palmerston North)

Post by vaanbooch » Wed Mar 21, 2012 4:01 pm

Thanks Jeremy,

I've made a vqmod and everything went fine. The code is below.

Code: Select all

<modification>
<id>Facebook og:image fix</id>
<version>1.0</version>
<vqmver>1.0.8</vqmver>
<author>www.bewebdesign.be</author> 

<file name="catalog/controller/common/header.php">
	<operation>
		<search position="after"><![CDATA[$this->load->model('catalog/product');]]></search>
		<add><![CDATA[
if (isset($this->request->get['product_id'])) {
			$product_id = $this->request->get['product_id'];
			$product_info = $this->model_catalog_product->getProduct($product_id);

			$this->load->model('tool/image');
			if ($product_info['image']) {
				$this->data['og_image'] = str_replace( ' ', '%20', $this->model_tool_image->resize($product_info['image'],100,100) );
			} else {
				$this->data['og_image'] = 'FULL_PATH_TO_YOUR_DEFAULT_IMAGE';
			}

		} else {
			$this->data['og_image'] = 'FULL_PATH_TO_YOUR_DEFAULT_IMAGE';
		}
]]></add>
	</operation>
</file>
</modification> 
Add in common/header.tpl <head> area:

Code: Select all

<?php if ($og_image) { ?>
<meta property="og:image" content="<?php echo $og_image; ?>" />
<?php } ?>
If we have an active product, its thumbnail is passed to Facebook. If the page is other than product/product, Facebook will use a default image.
Last edited by vaanbooch on Fri Mar 30, 2012 9:37 pm, edited 1 time in total.

Be Easy Web Design


Newbie

Posts

Joined
Thu Dec 08, 2011 8:34 pm

Post by gifo » Wed Mar 21, 2012 7:01 pm

vaanbooch, thanks for code ;) I also had this problem.

solidne agregaty | tanie maszyny budowlane do firmy


User avatar
Newbie

Posts

Joined
Wed Mar 21, 2012 6:55 pm
Location - london

Post by coen1234 » Fri Mar 30, 2012 4:11 pm

I've installed your xml file and the header code as you discriped but i get the following error.

Code: Select all

Catchable fatal error: Argument 1 passed to VQModObject::__construct() must be an instance of DOMNode, null given, called in /home/Mysite/public_html/Mysite/vqmod/vqmod.php on line 580 and defined in /home/Mysite/public_html/Mysite/vqmod/vqmod.php on line 127

Can you please guide me how to do this?

I'm using OC 1.5.2.1

New member

Posts

Joined
Thu Mar 08, 2012 3:05 am

Post by vaanbooch » Fri Mar 30, 2012 9:40 pm

There were missing the obligatory <modification>, etc. fields.
I've corrected the code, you can try it now :-)

Be Easy Web Design


Newbie

Posts

Joined
Thu Dec 08, 2011 8:34 pm

Post by vaanbooch » Tue Apr 17, 2012 4:52 pm

Meanwhile we have made an extended version, which provides:

- Sharing of each Product with it's corresponding Image, Title and Description
- Site Global Image, Title and Description

It can be downloaded here: http://www.opencart.com/index.php?route ... order=DESC

Enjoy!

Be Easy Web Design


Newbie

Posts

Joined
Thu Dec 08, 2011 8:34 pm
Who is online

Users browsing this forum: No registered users and 98 guests