Post by Brite Light LEDs » Wed Apr 16, 2014 11:32 pm

Is there a code i can use which will place the current product price into the meta description which will show when the link is shared?

Automotive Lighting upgrades
http://www.BriteLightLEDs.co.uk


User avatar
Active Member

Posts

Joined
Wed Apr 25, 2012 12:47 am

Post by tacobandito » Thu Apr 17, 2014 12:36 am

Sure. If this is a one off, you could just run an sql query with a little php..

This is definitely not the most well written as this was a really quick job, but does work.

Code: Select all


<?php 
################
# Written By:  #
# Lawrence Shea#
# for OpenCart #
#AddPriceToMeta#
################


include 'config.php';

# VARIABLES #

$tagline = 'Get it now for';
$currency = '$';

# VARIABLES #

    	$connect = mysql_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWORD);
		mysql_select_db(DB_DATABASE,$connect);

        $data = mysql_query("SELECT * FROM `".DB_PREFIX."product` WHERE 1") 
		or die(mysql_error()); 

		while($row = mysql_fetch_assoc($data)) { ?>

			<?php $price = $row["price"]; $price = explode('.',$price); $pid = $row["product_id"]; 

			echo '===GOT NEW PRODUCT===<br>Product ID ->'.$pid.'<br><br>';

			echo 'Got Price of '.$price[0].' For Product Id '.$pid.'<br><br>';



			$data1 = mysql_query("SELECT * FROM `".DB_PREFIX."product_description` WHERE `product_id`=$pid") 
		or die(mysql_error()); 

		while($row2 = mysql_fetch_assoc($data1)) {

			 $meta = $row2["meta_description"];

			 echo 'Got Meta Description '.$meta.'For Product Id '.$pid.'<br><br>';

			 $metaprice = $meta.' '.$tagline.' '.$currency.$price[0];

			 mysql_query("UPDATE `".DB_PREFIX."product_description` SET `meta_description`='$metaprice' WHERE `product_id`=$pid") or die(mysql_error());

			 echo 'Changed Meta Description '.$metaprice.'<br><br>';


		}

		}

?>

I've also included this as a .php file. It needs to be placed into the root directory of your opencart install, and then run. Once you've done that, you should remove it from the server.

As with anything that directly edits your DB, you should first make a backup. I am not responsible for anything bad that happens to your DB if you choose to run this script.

You should only run this once
, because there's no check in place for multiple runs, and it will just continually add the price to the end of the description... so you would get something like...

'META_DESCRIPTION' Get it now for only $100 Get it now for only $100 Get it now for only $100 Get it now for only $100 Get it now for only $100 Get it now for only $100 Get it now for only $100 Get it now for only $100...etc..

Attachments

Adds price to meta description


[module] PayPal Pro w/Recurring Profiles FREE
[module] 1 Click "Amazon Style" Checkout w/PayPal Pro FREE
[module] Adjustable PayPal Pro Fee FREE
[module] Add Sample To Cart LITE FREE
The guide to fixing just about everything wrong with OpenCart FREE!
Add INFINITE SCROLL to your homepage for FREE!
Live update product price for FREE!
Dynamic generation of Opencart coupon, FREE!
Hire me


User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by billynoah » Thu Apr 17, 2014 2:09 am

or simply execute the following sql query in phpmyadmin or your sql client:

Code: Select all

update `product_description` pd inner join `product` p on pd.product_id = p.`product_id` set pd.`meta_description` = p.`price`;
if you want a tagline and the currency formatted you can add it by concatenating strings and formatting the price like this:

Code: Select all

update `product_description` pd inner join `product` p on pd.product_id = p.`product_id` set pd.`meta_description` = concat("get ", pd.`name`, " for only $", format(p.`price`,2));

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Brite Light LEDs » Thu Apr 17, 2014 4:13 am

by doing this will i loose any current text that im using in the meta description ?

Automotive Lighting upgrades
http://www.BriteLightLEDs.co.uk


User avatar
Active Member

Posts

Joined
Wed Apr 25, 2012 12:47 am

Post by billynoah » Thu Apr 17, 2014 5:17 am

Brite Light LEDs wrote:by doing this will i loose any current text that im using in the meta description ?
I'm not sure who you were adressing here but the sql i provided will replace meta-description. If you need to append to it you can write:

Code: Select all

update `product_description` pd inner join `product` p on pd.product_id = p.`product_id` set pd.`meta_description` = concat(pd.`meta_description`, "get ", pd.`name`, " for only $", format(p.`price`,2));

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by justcurious » Fri Apr 18, 2014 3:46 pm

I'm probably a bit late coming in here, but wouldn't it be a better way to do it via the controller file (catalog/controller/product/product.php):

Find:

Code: Select all

$this->document->setDescription($product_info['meta_description']);
and replace with (including tax):

Code: Select all

$this->document->setDescription($product_info['meta_description'] . 'Get it for only ' . $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))));
or (excluding tax):

Code: Select all

$this->document->setDescription($product_info['meta_description'] . 'Get it for only ' . $this->currency->format($product_info['price']));
If you have specials, then you will need to do some code manipulation to get the special price instead of the regular price.

This way, the price is not hard coded into the description and will update whenever there is a price change.

Google Product Feed - Get your products into Google Shopping. Includes a bulk update facility.
Backup Pro - Backup (on demand or scheduled), Restore and Clone your store.
Freestyle Box - Add multiple information boxes on multiple pages of your store. Includes optional "Code Mode".
View my other extensions


User avatar
Active Member

Posts

Joined
Sat Dec 24, 2011 4:36 pm
Location - UK

Post by Brite Light LEDs » Mon Apr 21, 2014 5:04 am

Tried that just curious, go to EDIT and shows same Metatag description - no price ?

running custom theme

Automotive Lighting upgrades
http://www.BriteLightLEDs.co.uk


User avatar
Active Member

Posts

Joined
Wed Apr 25, 2012 12:47 am

Post by justcurious » Mon Apr 21, 2014 4:36 pm

Brite Light LEDs wrote:Tried that just curious, go to EDIT and shows same Metatag description - no price ?
Yes, thats right. The code you have changed puts the Meta Description information you can see PLUS the price information in the meta description tags on the product page at the store front.

Browse to one of your products, view the source and look for the code:

Code: Select all

<meta name="description" content="Meta Description - Get it for £50" />
It should be near the top of the page within the <head></head> tags

Google Product Feed - Get your products into Google Shopping. Includes a bulk update facility.
Backup Pro - Backup (on demand or scheduled), Restore and Clone your store.
Freestyle Box - Add multiple information boxes on multiple pages of your store. Includes optional "Code Mode".
View my other extensions


User avatar
Active Member

Posts

Joined
Sat Dec 24, 2011 4:36 pm
Location - UK

Post by Brite Light LEDs » Mon Apr 21, 2014 9:23 pm

what i was after was it to show at the end of Descriptions when a link is shared via facebook, as alot of people are not clicking and are asking " how much " on social media

Automotive Lighting upgrades
http://www.BriteLightLEDs.co.uk


User avatar
Active Member

Posts

Joined
Wed Apr 25, 2012 12:47 am

Post by justcurious » Tue Apr 22, 2014 12:48 am

It depends on where the facebook link is getting the description from. If my solution is not working for you, then you will either need to find out which controller file is setting the link description and edit that code in the way I've highlighted above, or you will need to go with tacobandito's script.

If you go with the latter, when you update your prices, you will need to edit the meta descriptions individually; it would require really complex coding to strip out the old price and replace with the new in that situation.

Regards

Google Product Feed - Get your products into Google Shopping. Includes a bulk update facility.
Backup Pro - Backup (on demand or scheduled), Restore and Clone your store.
Freestyle Box - Add multiple information boxes on multiple pages of your store. Includes optional "Code Mode".
View my other extensions


User avatar
Active Member

Posts

Joined
Sat Dec 24, 2011 4:36 pm
Location - UK

User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by justcurious » Tue Apr 22, 2014 5:07 am

Then Brite Lite LEDs needs to find the piece of code in the controller file that allocates the meta description to the Facebook link and change that.

I have no knowledge of how the Facebook links work

Google Product Feed - Get your products into Google Shopping. Includes a bulk update facility.
Backup Pro - Backup (on demand or scheduled), Restore and Clone your store.
Freestyle Box - Add multiple information boxes on multiple pages of your store. Includes optional "Code Mode".
View my other extensions


User avatar
Active Member

Posts

Joined
Sat Dec 24, 2011 4:36 pm
Location - UK

Post by Brite Light LEDs » Thu May 01, 2014 8:05 am

the price was not even showing in metatag within admin cp , with this code added

Automotive Lighting upgrades
http://www.BriteLightLEDs.co.uk


User avatar
Active Member

Posts

Joined
Wed Apr 25, 2012 12:47 am

Post by justcurious » Thu May 01, 2014 3:32 pm

The script that I posted does not change the meta description in the database, it just takes two pieces of data (the meta description and the price) and puts them together each time the user looks at a particular page in the same way that the other data is put together when a user browses to the page (for example, the product title, product description, price, VAT etc - they're not combined in the database, just put together dynamically).

The purpose of the script I proposed was to add the price to the (hidden) meta description tag which is on the store product page and often used by Google as the snippet in the search results. You won't see the combined result in the Admin Control Panel.

I thought that was what you wanted. You've since clarified your requirement.

Can you post a couple of screenshots of what is appearing on screen and what you want to see?

I think that tacobanditos solution would work for you, but it will be a royal pain whenever you update your prices.

Google Product Feed - Get your products into Google Shopping. Includes a bulk update facility.
Backup Pro - Backup (on demand or scheduled), Restore and Clone your store.
Freestyle Box - Add multiple information boxes on multiple pages of your store. Includes optional "Code Mode".
View my other extensions


User avatar
Active Member

Posts

Joined
Sat Dec 24, 2011 4:36 pm
Location - UK

Post by Brite Light LEDs » Fri May 02, 2014 12:32 am

I really am Lost, could you show a screenshot how it works your end, to display if this what i am after?

Automotive Lighting upgrades
http://www.BriteLightLEDs.co.uk


User avatar
Active Member

Posts

Joined
Wed Apr 25, 2012 12:47 am

Post by tacobandito » Fri May 02, 2014 8:50 am

justcurious wrote:I think that tacobanditos solution would work for you, but it will be a royal pain whenever you update your prices.
My one-off solution would certainly make it slightly more time consuming to update a price, as you would need to edit the meta description along with the price when those change, or when adding new products.

That said, even I'm suggesting that you use justcurious's solution. It's better than mine.

[module] PayPal Pro w/Recurring Profiles FREE
[module] 1 Click "Amazon Style" Checkout w/PayPal Pro FREE
[module] Adjustable PayPal Pro Fee FREE
[module] Add Sample To Cart LITE FREE
The guide to fixing just about everything wrong with OpenCart FREE!
Add INFINITE SCROLL to your homepage for FREE!
Live update product price for FREE!
Dynamic generation of Opencart coupon, FREE!
Hire me


User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by justcurious » Fri May 02, 2014 10:09 pm

@Brite Light LEDs
Meta Description is an HTML tag designed to allow website owners to put a short description in the website code to help the search engines work out what your page is about.

Over time, Google has started using this description as the "snippet" in the search results when there is not much information actually showing on the page.

Although the Meta Description is included in the HTML, it is not displayed anywhere on the page.

To use an example from your own website:

Image
In the search results, you can see that for the home page, the "snippet" is the same as your meta description, but for the product "BMW E60/E61LCI Angel Eye 5w 7000k White CREE LED ...", Google has used information from the product description as it has judged that the product description provides better information than the meta description.

Here is how the HTML appears. This is the section of HTML that the code that I suggested earlier would affect:

Image
There is a different section of code that creates your Facebook Links - that is what you need to edit. Do you have an extension that creates the fb links for you?

Google Product Feed - Get your products into Google Shopping. Includes a bulk update facility.
Backup Pro - Backup (on demand or scheduled), Restore and Clone your store.
Freestyle Box - Add multiple information boxes on multiple pages of your store. Includes optional "Code Mode".
View my other extensions


User avatar
Active Member

Posts

Joined
Sat Dec 24, 2011 4:36 pm
Location - UK
Who is online

Users browsing this forum: No registered users and 337 guests