Category Archives: osCommerce

osCommerce

How to add Open Graph tags in osCommerce

Yesterday I got tired of the way my shared links on Facebook looked. Facebook grabbed the wrong image and the wrong description, and it looked like crap.

The solution is to add the correct Open Graph tags to your osCommerce header tags. For products you have to edit product_info.php and for categories/front page you need to edit index.php

I’ve heavily modded my distribution and it also started out from the danish osCommerce fork UniqueFree but the principle in adding the Open Graph tags to a standard osCommerce installation is pretty much the same.

The only annoyance about the Open Graph tags is that you need a Facebook App ID for Facebook to accept the tags 100% – it might work without it though, but I haven’t checked. If you haven’t got a Facebook App setup for your page I can recommend this tutorial that shows you how to create an App on Facebook.

Below is the PHP code for my Open Graph tags in product_info.php (in the <head> section)

<meta property=”fb:app_id” content=”YOUR_FACEBOOK_APP_ID!!” >
<meta property=”og:site_name” content=”<?php echo STORE_NAME;?>” >
<meta property=”og:url” content=”<?php echo (‘http://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’]) ;?>” >
<meta property=”og:title” content=”<?php echo $p_pagetitle; ?>” >
<meta property=”og:image” content=”<?php echo tep_href_link(DIR_WS_IMAGES . $product_info[‘products_image’] ); ?>”>
<meta property=”og:description” content=”<?php echo ($meta_desc); ?>”>
<meta property=”og:type” content=”product”>

As I previously mentioned my shop is heavily modded and you probably don’t have alle the above variables in a stock osCommerce installation, so you need to set the following variables to the correct values:

  • $p_pagetitle //Should be set to your page title
  • $meta_desc //Should be your meta description or your short product description

Take a look at how your regular meta tags are generated and set the to variables by copying them.

This is how my og: tags look in my index.php file:

<meta property=”fb:app_id” content=”INSERT_YOUR_FACEBOOK_APP_ID!” >
<meta property=”og:site_name” content=”<?php echo STORE_NAME;?>” >
<meta property=”og:url” content=”<?php echo (‘http://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’]) ;?>” >
<meta property=”og:title” content=”<?php echo $mtitle; ?>” >
<meta property=”og:image” content=”http://www.imania.dk/imania300x300.png?p=1234″>
<meta property=”og:description” content=”<?php echo ($meta_desc); ?>”>
<meta property=”og:type” content=”product”>

In the above you also need to set your own variables for $meta_desc and $mtitle. Since I don’t have proper category photos for all my categories, I’ve chosen to create a logo file instead, so my store logo is displayed when people share my shop’s categories on Facebook, hence the hardcoded og:image property. This is also Remember that the og:image tag should point to an image between 200×200 pixels and 1500×1500 pixels – if you don’t Facebook might ignore the property and choose another image.

Also – if you have a script setup to set the canonical url, you might want to set the og:url property to your canonical url instead of the current url.

If everything is setup correctly, you should now see something similar to this when sharing a link on facebook:

Screenshot

 

If something it doesn’t seem to work, then you can check the source of the page in question to see if the og: tags are generated correctly. If the seem to be ok, you can use the Facebook URL debug tool.

Comments? Questions?

Leave your comments below 🙂

MySQL osCommerce

How to create multiple specials at once in osCommerce using MySQL

Once in a while I set a discount for lots of products at once and the default interface for specials  in the osCommerce Admin interface simply sucks – who has the time to manually add hundreds of products to the list of specials? It’s fine for a single product I guess, but in my usual cases it simply doesn’t cut it.

So if I want to have an opening sale, putting a 40% discount on all products added to the shop after a specific date(let’s say – today, May 2nd), I can do the following (after I make a backup of my database!):

insert into specials (`products_id`,`specials_new_products_price`,`expires_date`) select products_id, products_price * 0.6, “2013-05-11 23:59:59” from products where products.products_date_added > “2013-05-02 00:00:00”

What this does is to add every single product added to the database after May 2nd 2013 at 00:00:00 to the specials table with a products price of 0.6 * the products original price (=a 40% discount). You’ll most likely also want to set an expiry date for the special price and as you can see in the query I set the expiry to the end of May 11th 2013.

Another variation of the above query is to have a sale on all products that are in stock at the moment. This can be accomplished by running the query below.

insert into specials (`products_id`,`specials_new_products_price`,`expires_date`) select products_id, products_price * 0.6, “2013-05-11 23:59:59” from products where products.quantity > 0;

Again, please remember to make a backup of your database before you tinker with it like this. A single typo could completely ruin your shop for good!

That’s it for today. Have fun and please leave a comment if the tips provided here have helped you or you have questions about handling the MySQL queries or making modifications.

Best regards,

Anders

MySQL osCommerce

Managing osCommerce tables using PHPMyAdmin / MySQL

When managing a store with thousands of products, thousands of customers and a bucketload of specials, the standard osCommerce admin interface simply isn’t practical. So instead of clicking, changing a value and clicking again and repeating the process thousands of times I access the osCommerce database directly – dangerous I know, but the only way to change the sort order of every single product at once for instance. So… before doing anything to your osCommerce database in PHPMyAdmin remember to always!(Yes, every time!) make a backup of your database. If you’d like to know the simple way to do it, then leave a comment about it and I’ll post a guide, though Google can probably help you with instructions on how to backup a MySQL database 😉

 

How to change the sort order of thousands of products at once

Changing the default sort order of every product in your store is a good example of what you can do with direct access to your osCommerce MySQL database – it would take days to do manually if you have more than a few products.

Today I decided to do some maintenance and move some of the items I don’t have in stock down the list so my customers see the things I have in stock first. It’s pretty simple as you’ll see below.

So if that sounds appealing to you, just do the following. Open up PhpMyAdmin or log into your MySQL database another way, backup your database and run the following SQL query:

UPDATE `products` SET `products_sort_order` = `products_sort_order` +1 WHERE `products`.`products_quantity` <1;

What the query does is to increase the sort order of all products that aren’t in stock by one. Remember – the higher the sort order, the lower down on the list the products will be listed on your shop.

Obviously you could do the opposite to the same effect and just decrease the sort order for all products that are in stock. Like this:

UPDATE `products` SET `products_sort_order` = `products_sort_order` -1 WHERE `products`.`products_quantity` >0;

 

That’s all I have for you today – I hope it’ll be helpful to someone. If so, please leave a comment below – questions are more than welcome too 🙂 To prove you’re not  a spambot you can use the word bedazzle somewhere in your comment 😉