I've came up with a solution that works with http://www.opencart.com/index.php?route ... on_id=1701.
All original credit goes to Asif_mahmood for the original creation of Facebook & twitter share module.
I don't take any credit for his work, I was just like the rest of you trying to figure how to make this work between Facebook Posts with the correct Product Image.
Also this is for Facebook only, you can add Twitter by using Asif_mahmood Opencart Mod or by getting source code directly from Twitter.
Thanks and enjoy!
Place the share button anywhere in your product TPL file.
Code: Select all
<a name="fb_share" type="icon_link" share_url="<?php echo CURRENT_URL; ?>">Share Me!</a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript">
</script>
Add this code to your catalog/controller/product/product.php file around line: 211
Find :
Code: Select all
foreach ($results as $result) {
$this->data['images'][] = array(
'popup' => $this->model_tool_image->resize($result['image'] , $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
);
Add this just below:
Code: Select all
$this->document->addFBMeta('og:image', $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')) );
}
At the top of your system/library/document.php
Replace this:
Code: Select all
<?php
final class Document {
public $title;
public $description;
public $keywords;
public $base;
public $charset = 'utf-8';
public $language = 'en-gb';
public $direction = 'ltr';
public $links = array();
public $styles = array();
public $scripts = array();
public $breadcrumbs = array();
Code: Select all
<?php
final class Document {
public $title;
public $description;
public $keywords;
public $base;
public $charset = 'utf-8';
public $language = 'en-gb';
public $direction = 'ltr';
public $links = array();
public $styles = array();
public $scripts = array();
public $breadcrumbs = array();
public $fbMeta = array();
Then add this in the same system/library/document.php around line: 26
Find this:
Code: Select all
public function getKeywords() {
return $this->keywords;
}
Add this just below:
Code: Select all
public function addFBMeta($property , $content ) {
$this->fbMeta[] = array(
'property' => $property,
'content' => $content
);
}
public function getFBMeta () {
return $this->fbMeta;
}
Add this to your templates common/header.tpl file
At the top of your header.tpl find the meta description call:
Code: Select all
<?php if ($description) { ?>
<meta name="description" content="<?php echo $description; ?>" />
<?php } ?>
Replace it with this:
Code: Select all
<fb:share-button class="meta">
<meta name="medium" content="mult"/>
<?php foreach ($this->document->getFBMeta() as $fbMeta) { ?>
<meta property="<?php echo $fbMeta['property'] ?>" content="<?php echo $fbMeta['content']; ?>" />
<?php } ?>
<?php if ($description) { ?>
<meta name="description" content="<?php echo $description; ?>" />
<?php } ?>
</fb:share-button>
That's it your done!! Fully tested and working 100% in Opencart 1.5.1
http://www.doawebdesigns.com