What Category are you looking at?

Sometimes you are not able to tell which Category you are looking at as the template that you are using might have changed (or even removed!) the Categories infobox. I’ve seen a few sites which use a horizontal dropdown menu (eg Easy Menu) which looks good, but takes away the visual representation of where you are. In addition, many sites remove the “breadcrumb”…

So, just how can you find out which Category you are in?

It’s rather easy. osCommerce has a variable called “current_category_id” – it shows the ID of, guess what, the Current Category ID for the product that you are looking at. You can use this such as; <?php echo $current_category_id; ?>

In simple terms, you can use this to show the Name of the Category that you are in, or to construct a breadcrumb etc etc.

Use it to show a banner!

Recently a question was posed in the official osCommerce forum where someone wanted to show a banner on, and only on, 1 particular category. The answer given by some well meaning but ultimately completely incorrect “helper” (aka “oscommerce hack job”) was to use $cPath – well, this would work if, and only if, the category the person wanted to show the banner had did NOT have subcategories, thus;

Imagine we want to show a banner only if the Category ID is 3. With this code; <?php if ($cPath == “3”) echo “banner”; ?> the banner would show on category 3 and any if it’s subcategories. With my idea, <?php if ($current_category_id == “3”) echo “banner”; ?> the banner would show ONLY on category 3 and NONE of it’s subcategories.

Another good reason to use this might be to place a message to your buyers on some Categories – maybe you want to point them towards an upsell or a special offer?

There are lots of little pieces of code like this within osCommerce – it’s always best to try to do what you want using the best piece of code for the job – otherwise you are trying to ram a square peg into a round hole!

HOW TO: make just 1 infobox a different style

There are lots of ways to make osCommerce look different. Here is 1 way to make 1 infoBox look different to the rest – it’s easy – and is done using a CSS (Cascading Style Sheet) “trick”…

Step 1: decide which infoBox to change

In this example, I’m going to change the look of the Categories infoBox. Open up the file /includes/boxes/categories.php and find the following line of code


Change this to:

<td id="categorybox">

Save this file and upload it.


Step 2: Give it some style!

We know that the usual infoBox styling is controlled by three CSS entries;

  1. infoBoxHeading
  2. infoBoxContents
  3. infoBox

So, all we now need to do is use those to control the box we are changing, but we do it using a special CSS “trick”…open up stylesheet.css and scroll right to the very bottom of it. Add the following code;

#categorybox .infoBoxHeading { background: blue; color: yellow; }

Why did we add this code? Well, for starters you can see that the very first piece of code says #categorybox – you’ll remember that in Step 1, we gave this id to the Table Cell (td) that hold the Category Box.

The rest of the code is standard osCommerce style using the existing .infoBoxHeader style definition. In this example, I’ve made the background blue, and the font color yellow. We end up with this:


As you can see, this box is beginning to show the style we want – but some of the style is still showing the standard osCommerce grey colours! Let’s change that…

Add this code to your stylesheet;

#categorybox .infoBox { background: blue; }

We now see the infoBox like this:


Getting closer! Let’s make the background of the box a dark grey and make the text white. Add this code to the stylesheet;

#categorybox .infoBoxContents { background: #aaa; color: white; }

Now the box looks like this:


And we have a problem – the actual links within this box are still the standard black with grey rollover. That’s easy to change, simply add this to the stylesheet;

#categorybox a { color: white;}

This says that any link with our category box should be white. Now the box looks like this – which is almost perfect for the style needed:


The only problem remaining is the goofy little curved corner graphic that is now looking totally wrong. let’s change that to a square corner. This is really easy 😉

Step 3: Get rid the crappy graphic

Open up /includes/classes/boxes.php and find the following code;

'text' => $left_corner),

Change it to:

'text' => ' '),

Now our box looks like this:


Perfect! But the best part is, the rest of the boxes all look as they normally do!


UK Pound Question Mark – HUH?

Changing host is a simple thing – I’m not going to go into great detail about where to find a host, name server changes or any of that.

I have found that moving an osCommerce site can sometimes be problematic – not least because of database issues and the sheer number of files that osCommerce contains. If you have 1000 products, that’s an extra 1000 (or more likely 2000) images to move as well!

Every time that I have moved an osCommerce store recently, I’ve found that the UK pound sign is replaced by a question mark in the database. This means that all prices show for example ?45.99 instead of £45.99 – also any and all orders that were paid for in pounds, now show the problem question mark instead 🙁

I’ve hunted Google and see lots of this problem – it appears to be MySQL related. No matter, it’s easy to fix in osCommerce (let’s assume you have your database/store up and running on the new host and you now need to fix those pesky £ ? errors)…

Step 1: Fixing the Shop Prices

Go to your Admin Area and then Localization > Currencies. Select UK Pounds and press edit. Change the ? to a £ and press update.

Step 2: Fixing all the existing orders

Hopefully you have PHPMyAdmin as part of your hosting package, it comes as standard with cPanel and Plesk. Run this SQL Command:

UPDATE `orders_total` SET `text` = REPLACE(`text`, "?", "£");

That’s all there is too it. Your shop is now fixed 😀

Update price based on attributes

Lilotanni asks;

When there are attributes assigned to a product and the attribute has money value to them. I wanted the base price to update automatically before the customer add it to cart.

As in if the base price is $200.00 and the attribute is -$10.00, when the customer chooses -$10.00, the displayed price would changed to $190.00 and so on if there are more attributes. I’ve been trying to do that and have gotten no where. Could you help me out?

Well, you need to use javascript.  I’d have had a go at using jQuery to update the price based on attributes, but even easier – there is already an existing contribution!

Check out http://www.oscommerce.com/community/contributions,1385 – I used the Attrib.Price Update 1.4 version and dropped in the product_info.php page directly.

It worked first time 🙂  Good luck with your osCommerce Store.

Stripos used in RC2

In one place, stripos is used in RC2.  Stripos is PHP5 only, so many shops will break when used on a host that is not up-to-date.

The solution is to find every instance of stripos, and change it to strpos (which is backwards PHP compatible).  I believe the only code you will need to change is in the file;

admin/backup.php around line 252.

HOW TO: show number of products in cart

Shwoing the number of products in osCommerce cart is very simple;

echo $cart->count_contents();

This will show the total number of items in a persons cart.

You can go further with this and say something like;

You have <?php echo $cart->count_contents(); ?> items in your cart.

But this will not be grammatically correct if only 1 item is in the cart, In this case we say;

You have <?php echo $cart->count_contents(); ?> <?php echo $cart->count_contents() == “1” ? “item ” : “items ” ; ?> in your cart.

Now the code will determine whether to say “item” or “items” depending upon the number of items in the cart.