Post by Lemontree » Thu Aug 25, 2016 4:52 pm

Hi!

I am looking for a OpenGraph extension that enables you to add a custom OpenGraph specific image to products.

Does this exist? It would be really nice to have that option if I want a more "selling" image for a product than just the main image. So that I can make the shared products look better... :)
Last edited by Lemontree on Mon Aug 29, 2016 9:35 pm, edited 1 time in total.

Newbie

Posts

Joined
Sat Nov 29, 2014 8:38 am

Post by Lemontree » Mon Aug 29, 2016 9:34 pm

Hi!

Figured it out by myself, and want to share if anyone else need this functionality.

This extension adds functionality to have a custom OpenGraph Image for products. If not present, it will use the main image.

This is made for OpenCart 2.2.0.0. Please feel free to comment with suggestions.

I have attached my VQMod-file.

You must add a column to the product table in the database:

Code: Select all

ALTER TABLE `oc_product` ADD `ogimage` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `image`;
To use this mod you also need VQMod installed and this extension:
http://www.opencart.com/index.php?route ... n_id=22963

In the OpenGraph-extension modify the following:

Code: Select all

if ($product_info['image']) {
	$this->document->addOGMeta('property="og:image"', str_replace(' ', '%20', $this->config->get('config_url') . $this->model_tool_image->resize($product_info['image'], 1200, 630)) );
	$this->document->addOGMeta('property="og:image:width"', '1200');
	$this->document->addOGMeta('property="og:image:height"', '630');
} else {
	$this->document->addOGMeta( 'property="og:image"', str_replace(' ', '%20', $this->config->get('config_url') . $this->model_tool_image->resize($this->config->get('config_logo'), 1200, 630)) );
	$this->document->addOGMeta('property="og:image:width"', '1200');
	$this->document->addOGMeta('property="og:image:height"', '630');
}
foreach ($results as $result) {
	$this->document->addOGMeta( 'property="og:image"', str_replace(' ', '%20', $this->config->get('config_url') . $this->model_tool_image->resize($result['image'], 1200, 630)) );
	$this->document->addOGMeta('property="og:image:width"', '1200');
	$this->document->addOGMeta('property="og:image:height"', '630');
}
to this:

Code: Select all

if ($product_info['ogimage']) { 
	$this->document->addOGMeta('property="og:image"', str_replace(' ', '%20', $this->config->get('config_url') . $this->model_tool_image->resize($product_info['ogimage'], 1200, 630)) );
	$this->document->addOGMeta('property="og:image:width"', '1200');
	$this->document->addOGMeta('property="og:image:height"', '630');
} else if ($product_info['image']) {
	$this->document->addOGMeta('property="og:image"', str_replace(' ', '%20', $this->config->get('config_url') . $this->model_tool_image->resize($product_info['image'], 1200, 630)) );
	$this->document->addOGMeta('property="og:image:width"', '1200');
	$this->document->addOGMeta('property="og:image:height"', '630');
} else {
	$this->document->addOGMeta( 'property="og:image"', str_replace(' ', '%20', $this->config->get('config_url') . $this->model_tool_image->resize($this->config->get('config_logo'), 1200, 630)) );
	$this->document->addOGMeta('property="og:image:width"', '1200');
	$this->document->addOGMeta('property="og:image:height"', '630');
}
foreach ($results as $result) {
	$this->document->addOGMeta( 'property="og:image"', str_replace(' ', '%20', $this->config->get('config_url') . $this->model_tool_image->resize($result['image'], 1200, 630)) );
	$this->document->addOGMeta('property="og:image:width"', '1200');
	$this->document->addOGMeta('property="og:image:height"', '630');
}

Attachments

VQMod to add OpenGraph custom image.


Newbie

Posts

Joined
Sat Nov 29, 2014 8:38 am

Post by JOELSULLIVAN » Fri Sep 16, 2016 5:54 am

Hi is usefull, but when i do the code change, doesnt works because the image url is duplicated

The image url that facebook reads is duplicated, here is my problem:

Provided og:image, http://mydomain.com/http://mydomain.com ... 00x630.jpg could not be downloaded because it exceeded the maximum allowed sized of 8Mb or your server was too slow to respond.

Here you can see that my domain looks 2 times in the url that facebook reads for the image.

Please help me, and thanks.

Newbie

Posts

Joined
Fri Sep 16, 2016 5:51 am

Post by Lemontree » Mon Nov 21, 2016 9:56 pm

JOELSULLIVAN wrote:Please help me, and thanks.
Hi! Sorry for the late reply. I may have missed the notification for your post.

I am not sure why this happens on your site, have you found the solution?

This does not happen on my installation, so if anyone else experience this error please share some information/solution.

Thanks.

Newbie

Posts

Joined
Sat Nov 29, 2014 8:38 am
Who is online

Users browsing this forum: No registered users and 4 guests