Facebook “LIKE” on your osCommerce shop

Jan asks;

possible to put the new like button on osc

Yep, and it’s super simple, using this quick and dirty code.

Step 1: Add this code to your header, footer, or wherever you want the like button to show;


Step 3: Add this code to the bottom of either /includes/footer.php (pre rc3) or includes/template_bottom.php (rc3), making sure to substitute “your app id” with your actual app id;




Code needs to be cleaned up for real use, but this should give you enough of an idea to be able to do what you need to do.

Manufacturers in osCommerce

Yesterday, I was asked to quote on making some changes to the Manufacturer system in osCommerce. At the moment it is quite limited as all you can do is add the Manufacturer Name, Logo and URL. These then show in an infoBox, based on the manufacturer of the product that you are looking at;

I was asked to quote on adding a PDF per manufacturer and a system for adding “sales info” and a “manufacturer description” per language for each manufacturer. All this to then be shown in the individual manufacturer page (per language) in the osCommerce shop.

A normal manufacturer page looks like this.

I needed to change this quite a bit, as so;

Basically displaying the two blocks of text, the homepage link, the PDF and the Manufacturer Name (instead of “Let’s See What We Have Here”).

Pretty straightforward, I cooked up my own solution for all of it, and the code as it stands is rough but workable – it’s what is known as “proof of concept” code. Once this client make a buying decision then I will clean it up and make it available for all.

Here’s the new Admin manufacturer page;

osCommerce -> Admin -> Manufacturers -> BUG -> Fixed

I’ve been working on the manufacturers page of the osCommerce Admin section to get some “proof of concept” code working.

Whilst working on it, I couldn’t understand why the manufacturers image kept disappearing. On closer inspection I found some buggy code which I have now fixed.

Github Commit.

Basically, the image was uploading nothing, and overwriting the existing image if a Manufacturer was edited (eg, changing the name, adding a URL etc).

If you don’t understand Github, here’s the fix;

Find this:

[php]if ($manufacturers_image = new upload(‘manufacturers_image’, DIR_FS_CATALOG_IMAGES)) {
tep_db_query(“update ” . TABLE_MANUFACTURERS . ” set manufacturers_image = ‘” . $manufacturers_image->filename . “‘ where manufacturers_id = ‘” . (int)$manufacturers_id . “‘”);

Change to this:

[php]$manufacturers_image = new upload(‘manufacturers_image’);
if ($manufacturers_image->parse() && $manufacturers_image->save()) {
tep_db_query(“update ” . TABLE_MANUFACTURERS . ” set manufacturers_image = ‘” . $manufacturers_image->filename . “‘ where manufacturers_id = ‘” . (int)$manufacturers_id . “‘”);

This bug definitely exists in all versions of osCommerce upto and including the latest Github release of rc3. I have not tested manufacturers in osC v3.

Time to update my own osCommerce site

Mainly, my experience with osCommerce comes from helping other shop owners to realise their dreams of running a successful shop. That could be anything from coding up a bespoke shipping module, to supplying a complete osCommerce shop with a bespoke design.

Another part of my business involves selling templates for osCommerce. I was one of the first template providers (I started selling these even before Template Monster) and have not really done any work on my own site for many years. What this means is that the site is a bit stale and the available templates are also now quite outdated. I sell these templates via an osCommerce shop.

So, my intention over the next couple of weeks is to update my osCommerce site to the latest rc3 with a bunch of my own contributions installed. Because I am so busy I need to fit this in around my clients, otherwise I would just spend a couple days coming up with a design and then integrate it.

Once my new design is completed and integrated, I’ll then start to refresh the templates I offer. What I shall probably do is just stop selling all of the templates I presently offer, and come up with one new design each week.

I’m also going to start selling scripts and other osCommerce related services – such as installation, hosting and management services.

Should be an interesting time. For anyone interested here is how my present osCommerce site looks;

As I said it’s now a bit dated, and definitely needs an upgrade! Only problem is that I am more of a coder than a designer, so my idea for the new site is to keep it fairly simple and geometric rather than too graphicy. We’ll see how it works out.

Using cURL instead of file functions

Some hosts don’t allow the possibility of using the file functions that are built into PHP.

A URL can be used as a filename with this function if the fopen wrappers have been enabled.

So, if the fopen wrappers are turned off, you have no chance of using an external URL to get information (an example would be to get shipping rates from a 3rd party in order to calculate the correct postage).

So, I’m going to show you how I updated a clients codebase to use cURL…it’s really easy.


The non-working portion of code is this;

[php]$url = “http://drc.edeliver.com.au/ratecalc.asp?Pickup_Postcode=$frompcode&Destination_Postcode=$topcode&Country=$dest_country&Weight=$sweight&Service_Type=AIR&Height=$sheight&Width=$swidth&Length=$slength&Quantity=$shipping_num_boxes”;
$myfile = file($url);
foreach($myfile as $vals)
$bits = split(“=”, $vals);
$$bits[0] = $bits[1];

This is basically setting some parameters and requesting a file from AUS POST (an Australian Postage Company). The file contains text which delivers the postage rate to be charged, and some other info that we don’t need.

However because my clients host has the fopen wrappers turned off this was producing an error a bit like this;

Warning: file() [function.file]: URL file-access is disabled in the server configuration in public_html/includes/modules/shipping/auspost.php on line 68

I tried a couple of ways to get around this using htaccess or php.ini, but neither of these worked. So my only option was to recode the problem area of the module to make it use cURL.

You can check if cURL is installed on your server by using the server page in your osCommerce Admin Area. As I had not used cURL before, I spent a little familiaring myself with it, and then just jumped into the code feet-first. With a little tinkering I got it to work.


You can read more about cURL here. The basic idea is to open up a connection from your site to another, grab the needed values and then close the connection.

Code Changes

Step 1. Initialize the cURL session

[php]$my_curl = curl_init();[/php]

This is easy enough to understand, I’d have thought.

Step 2. Set the URL of the page to be opened

[php]curl_setopt($my_curl, CURLOPT_URL, ‘http://drc.edeliver.com.au/ratecalc.asp?Pickup_Postcode=’ . $frompcode . ‘&Destination_Postcode=’. $topcode .’&Country=’. $dest_country .’&Weight=’. $sweight .’&Service_Type=AIR&Height=’. $sheight .’&Width=’. $swidth .’&Length=’. $slength .’&Quantity=’. $shipping_num_boxes);[/php]

Again, this is easy enough. It’s the same code as the problematic codebase – but set out slightly differently as I prefer my code like this.

Step 3. Ask cURL to return the results in a variable

[php]curl_setopt($my_curl, CURLOPT_RETURNTRANSFER, 1);
$my_contents = curl_exec($my_curl);[/php]

At this point, $my_contents consists of the text that is returned by Aus Post. Which is problematic, as we need to get it into an array for useable purposes! But first, let’s close the cURL connection;

Step 4. Close the connection

[php]curl_close ($my_curl);[/php]

Step 5. Get the $my_contents into an array

[php]$my_contents = explode(” “, $my_contents);[/php]

Here we are “exploding” the text in the variable using a space.

Step 6. Use the individual array pieces as needed

[php]foreach($my_contents as $vals)
$bits = split(“=”, $vals);
$$bits[0] = $bits[1];

This was part of the standard codebase, but I have made it use $my_contents to work with.

So, the full new cURL code goes like this:

[php]$my_curl = curl_init();
curl_setopt($my_curl, CURLOPT_URL, ‘http://drc.edeliver.com.au/ratecalc.asp?Pickup_Postcode=’ . $frompcode . ‘&Destination_Postcode=’. $topcode .’&Country=’. $dest_country .’&Weight=’. $sweight .’&Service_Type=AIR&Height=’. $sheight .’&Width=’. $swidth .’&Length=’. $slength .’&Quantity=’. $shipping_num_boxes);
curl_setopt($my_curl, CURLOPT_RETURNTRANSFER, 1);
$my_contents= curl_exec($my_curl);
curl_close ($my_curl);

$my_contents= explode(” “, $my_contents);
foreach($my_contents as $vals)
$bits = split(“=”, $vals);
$$bits[0] = $bits[1];

I hope that this made some sort of sense and will help anyone in the future. There are lots of cURL tutorials available if you want more detailed information. Good luck!

Please note, that I am nowhere near knowledgable on cURL, and this post is just to show that it can be done, and done quite easily by anyone with just a little PHP knowledge and the ability to search Google.

osQuantum – is it all over?

Over at the osQuantum Forum, there have been rumblings of discontent based on the lack of updates regarding the release of the osQuantum cart…

Today, vGer has posted a summary of where the osQuantum project is, and it’s not sounding good…

Leadership (mine) has been lacking. I fully admit to that. I have a long-standing illness which sometimes flares up and gets much worse. That situation has become permanent and not temporary. I have been running at half steam or less since around October of last year.

Pass on the Leadership to someone who can handle it! Easy?

We haven’t been able to get the coding done which we would have hoped to get done by now, and this is why we cannot give a release date. We have been doing our best to bring new highly qualified coders into the team, but so far have not been successful and so this is delaying us.


We have brought two new people into the Team who are proving to be very useful team members – James Wilkins and David Graham – but we do need some highly qualified coders in MVC and OOP programming.

What can I say? There are no decent coders on the osQuantum team since the departure of Chemo. Is it possible that the problems of last year have tainted the project with regards to bringing in new talent?

We are fully aware of the people who have been supporting us and waiting developments, but all I can tell you is that we have been doing all we can given our limited resources.

It’s very easy to open the codebase to everyone, then allow those users to contribute to development. Github is a very useful tool, also SVN as well as other options for this.

With a closed codebase, it’s surely impossible to move forwards.

I wonder if a working codebase even exists at this point – any of the osQuantum team like to show me some code?

osCommerce Style Sheet? Use Colorzilla Firefox.

Sean asks;

I’ve got a bit of trouble with editing the colours in stylesheet.css.

I don’t have a problem with hex colours or even putting them into the stylesheet, my problem is I don’t know which bit is which. Is there are a chart or something where I can refer to different bits of the oscommerce main page with the code that controls the colors for it?

Really easily, assuming you are using Firefox, or can install Firefox. Use the “colorzilla” plugin, which allows you to point at an area of the page and it will tell you what .css is being used.

In this image, you can see that the red outlined area, is made up of a td.smallText (look at the bottom grey browser bar) – and so this (smallText) is what you would change in the stylesheet to affect the style.

Expedite Fee Per Shipping Method

A while back I posted about a solution to add an expedite fee. It works well, but is available on a per checkout basis rather than on a per shipping method basis.

In other words, there is no possibility to say;

– if you choose flat rate expedited, that’ll be an extra $5
– if you choose table rate expedited, that’ll be an extra $10

Instead, it was just one set fee for all methods.

For a recent client, I set about making a new system of expedited fees, on a per shipping method basis. I made it possible to add an extra fee to each shipping module.

Here is a screenshot of it in action;

And here is the extra input needed, screenshot from the admin shipping module editing page.

So you can easily see that for this shipping method, I charge $0 (free shipping) with an optional $9 upgrade for Fedex shipping. The two selection fields show right next to each other in the checkout_shipping.php page. Same for “flat rate”, I set $5 as the usual charge, with an option to pay $10 for expedited.

Doing it this way does involve a little more work, but is much more flexible than simply setting an overall expedited fee per checkout.

Easiest install ever! FCK Editor

3 steps to installing a WYSIWYG (What You See Is What You Get) editor for product descriptions in osCommerce.

Step 1. Go to ckeditor.com and download the latest Editor Release (CK Editor, which has superseded FCK Editor)…

Step 2. Unzip it all, then upload the fckeditor folder and all it’s contents to your admin directory.

Step 3.
2.2 and older: Amend admin/categories.php
2.3 and newer: Amend admin/includes/template_top.php

Find this:
< script language="javascript" src="includes/general.js" >< /script >

Add after it:
< script src="ckeditor/ckeditor.js" >< /script >

Amend admin/categories.php

Find this:
tep_draw_textarea_field(‘products_description[‘ . $languages[$i][‘id’] . ‘]’, ‘soft’, ’70’, ’15’, (isset($products_description[$languages[$i][‘id’]]) ? stripslashes($products_description[$languages[$i][‘id’]]) : tep_get_products_description($pInfo->products_id, $languages[$i][‘id’])));

Change it to this:
tep_draw_textarea_field(‘products_description[‘ . $languages[$i][‘id’] . ‘]’, ‘soft’, ’70’, ’15’, (isset($products_description[$languages[$i][‘id’]]) ? stripslashes($products_description[$languages[$i][‘id’]]) : tep_get_products_description($pInfo->products_id, $languages[$i][‘id’])),’ class=”ckeditor”‘);

Upload it and refresh the category (prodcut adding/editing) page. You should see the newly installed Editor looking like this:

Easy as 123…now go and use underlines, bold, colours to make your product descriptions really stand out 😉

Customer Group? SPPC? Something else!

I have a long term client, whose site has absolutely loads of contributions, including some big ones such as “Quantity Price Breaks Per Product” and many other small tweaks here and there.

The client wanted the ability to set up 1 particular group of customers who get charged more than the standard group. Basically a bit like a wholesale discount, but in reverse.

As the site has so many changes to almost all the files, I decided that installing Customer Groups or SPPC would be too much work, so I set out to make my own, cleanly coded solution.

Step 1. Allow the ability to set each customer to “pro” or leave as “standard”. I did this using a flag system in the admin/customers.php page;

Step 2. Allow the ability to make the “pro” customer get a % increase. I did this by making a new configuration definitiion;

Step 3. Recode login to start a session to see if the customer is “pro”.

Step 4. If the session exists, increase all prices by the % increase. This involved changing code in a few files, from the top of my head;

a. includes/classes/shopping_cart.php
b. includes/modules/order_total/ot_total.php
c. includes/modules/order_total/ot_subtotal.php
d. checkout_process.php

All in all, this took a couple hours to code up, much of which was spent making test orders to be certain that “standard” customers get charged the standard price, and “pro” customers get charged the pro price.

Interesting little project!