Rename osCommerce Files

Has anyone ever thought about renaming osCommerce page filenames and directory names and other things? This may be a decent way to solve some problems that osCommerce shop owners experience.

For many years, my own osCommerce store has had a different name for the product_info.php page, which has lead to greater SEO benefits. But that’s another reason…

For this post I am more interested in making osCommerce harder for a “hacker” to hack. For starters, read a previous post on this blog for an overview on some ideas and methods. Here’s some more ideas hunt google or the osCommerce forum if you need code examples on how to do any of this);

1. Why advertise that your site is osCommerce?
Of course, to the experienced eye, it is easy to tell whether a site is running osC or not. But why advertise the fact.

Is your site saying “powered by oscommerce” on it? Remove it!

Is your site using the oscsid variable? OSCsid – a small change, but well worth it? Why not change that to the zencart sid? Or creloaded? Or one of your own. It doesn’t really matter what you use for an SID – and it is easy to change in osCommerce…

2. Change the filenames!
Why would you keep the filenames the same as standard osCommerce? Of course, you’ll probably need to keep index.php the same in order for your site to show up when your URL in input, but even this is easily changable! As for the rest, it’s very simple. Rename the file, rename it’s corresponding language file, make the same change in the file at includes/filenames.php

3. Change the dirnames!
Change the Directory names! Why keep the name “includes” – it could as easily be “inc” or “incl” or “zippy” or “brian”. Just rename it and make the corresponding change in BOTH configure.php files.

I hear you saying, “that’s all well and good Gary, but what about contributions, won’t this break them”? The answer to this is maybe it will, if the contribution is not correctly written. The same goes for templates – if they are correctly written, they will still work.

Note that I am not saying that changing names of things is a great protection against anything, but if you make your website harder for a layman to know what software is running it, you MAY find they move onto the next website quicker, leaving your site alone.

osCommerce Quiz?

An osCommerce Quiz for you to think about;

switch (tep_get_zone_code($order->delivery[‘country’][‘id’], $order->delivery[‘zone_id’], ”)) {
case ‘HI’:
case ‘AK’:
$extra_cost = ($cart->show_total() * (13/100));
$extra_cost = 0;
switch ($order->delivery[‘country’][‘iso_code_2’]) {
case ‘US’:
$extra_cost = 0;
$extra_cost = ($cart->show_total() * (13/100));

And then an extra piece of code like this, elsewhere in the file…

[php]+ $extra_cost[/php]

I came up with proof of concept code (proof of concept is just that, it shows it work but might not be the most graceful codebase) to illustrate something. Thought it might be interesting for you guys to see some code with no explanation, and find out what the code is for.

So, questions;

1. In which file(s) could this code be placed?
2. Which country/countries add NO cost?
3. Which states add an extra cost?
4. What is the extra cost?

New, Used, Refurbished in osCommerce Product Info

Interesting code question posed on the osCommerce forum so I thought it would make a decent blog post;

Are there any contributions out there which add product information fields in the admin section so that you can list the product as new, used, or refurbished?

Always self code if possible, it’s better and you learn a little bit about the osCommerce engine…

Step 1: Add new input fields to admin/categories.php

Easy enough, basically look at produce model, and copy the code but rename to product_type. Add an extra question in the form;



Next up, an ugly kludge to read the value of each of the options and check the correct one automatically (eg, if you are updating an existing product).

[php]products_type == 0) ? true : false;
$checked1 = ($pInfo->products_type == 1) ? true : false;
$checked2 = ($pInfo->products_type == 2) ? true : false;

Step 2: Add language definitions to admin/includes/english/categories.php

I’m sure you can see what you need to add, from the code above!!!

Step 3: Add new row to DB products table

Add a row called products_type, and make it a smallint of 2 characters (this gives you upto 99 different types in case you need to expand this in the future.

DONE! Here is how it looks;

Now you can do more stuff, how about showing the type of product on the product_info.php page? Certianly possible, but quite complicated as you need two new functions along with a sprintf. But, easy enough, here’s how it looks;

I can maybe show how I did that in a future post, if there is any interest. But if you want to try yourself, here is a few clues;

1. Because all we have in the database is “0” or “1” or “2”, you need to link those numbers to text, so 0 = new, 1 = Old and so on.
2. Once you’ve done that you need to use a sprintf to show some text along with the number.
3. And make a function to change the number into the text that it is linked to.

Remember that this is a quick and easy way of doing this – coded by me in less than 10 minutes – so it might not do everything that you need it do! But it’s a good start on a coding adventure. Good luck!

Shipping Cost Per Country in osCommerce

I was tasked to come up with a way to set 2 shipping rates per country, example;

UK: 1st kilo of weight = £5.00, subsequent half kilo’s £0.75
USA: 1st kilo = £8.00, subsequent half kilo’s £1.25
and so on, for EVERY country, and EVERY price is different!

As every price is different, zones.php nor table.php won’t really work as it would be far too much work to set up 200 zones [ 1 per country ], then add the price/weight ratios in…

So, my idea was to add a couple extra rows in the countries table of the database;


“post” to hold the value of the charge for the 1st kilo and “extra” to hold the value of each half kilo thereafter. Easy as 123. Then I had to amend admin/countries.php to allow me to both show, insert new and edit countries to add the shipping charges. Again, not too difficult. I then had to change the file /includes/classes/order.php to grab the value of the two new database entries based on shipping address. A little more difficult as this class file is quite complicated.

All done? Not by a long shot!

Now I had to create a whole new shipping method, which I called “Clubosc Localization”. This basically grabs the value of the shipping address “post” and “extra”, then multiplies by the appropriate weight to get the correct cost. Here’s the pertinent code from the file;

$error = false;
// up to 1 kgs, charge 1 kilo
$shipping_cost = $order->delivery[‘country’][‘countries_post_cost’];
// over 1 kgs, charge extra per half kilo
if ($shipping_weight > 1) {
$the_weight = $shipping_weight-1; // removing the first kilo
$down = $the_weight/0.5;
$up = ceil($down)*0.5; //making remainder up to next half kilo
$shipping_cost += (($up*2) * $order->delivery[‘country’][‘countries_post_extra’]);
if ($shipping_cost == 0) $error = true;

The $up $down bit might not make much sense, but if you read this previous post, you’ll get an idea of what I am doing with that.

All in all, quite a complicated shipping module, one which needs lots of input in the “countries” table to work properly. I did also put in a check so that an error message is displayed if the $shipping_cost works out to zero (or in other words, the shop owner has not given the country a charge!).


Expedite Fee in osCommerce

So, you might want to charge an extra amount for shipping “expedited” – especially in the run up to Christmas. At the osCommerce forum someone asked for such, and a number of ideas came up. There are some close contributions, eg “gift wrap” (renamed appropriately of course).

My idea was to simply make a copy of the “low order fee” order_total module, and use that. I guesstimated that it would take 10 extra lines of code, so let’s see…

What do we need to do?

1. Add in a checkbox on checkout_shipping.php


2. Add in processing on checkout_shipping.php

[php]if(!empty($HTTP_POST_VARS[‘expedite_fee’])) tep_session_register(‘expedite_fee’);[/php]

3. Destroy the session in checkout_process.php


4. Copy /includes/modules/order_total/ot_loworderfee.php

Open up the file and change ALL instances of “loworderfee” to “expeditefee”
Also change ALL instances of “LOWORDERFEE” to “EXPEDITEFEE”
Also change all instances of “low order” or “Low Order” to “Expedite”

Change this line from:
[php]if ( ($pass == true) && ( ($order->info[‘total’] – $order->info[‘shipping_cost’]) < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) ) {[/php] To: [php]if (($pass == true) && (tep_session_is_registered('expedite_fee'))){[/php] Save the file as expeditefee.php 5. Copy the Language File /includes/languages/english/modules/order_total/ot_loworderfee.php

Open up the file and change ALL instances of “loworderfee” to “expeditefee”
Also change ALL instances of “LOWORDERFEE” to “EXPEDITEFEE”
Also change all instances of “low order” or “Low Order” to “Expedite”

Save the file as expeditefee.php

6. Language addition in /includes/languages/english/checkout_shipping.php
Add this:
[php]define(‘TEXT_EXPEDITE’, ‘Tick this box to expedite your order, costs an extra %s’);[/php]

7. Admin

Go to your shop admin and turn on the new order total module. Give it a unique sort order and make it show underneath the usual shipping charges.

DONE! This took 10 minutes, and consisted of mainly copy/paste code changes of words, along with three new lines of code (obviously I don’t count a simple word change in an existing lline of code as something that is new.

SEO Urls 5 Pro for osCommerce

This is a new version of FWRMedia’s existing SEO Urls contribution. I’ve been beta teting it for the last few days and between a few users found a couple of issues [nothing major] which should be fixed when the final release is made.

The one thing that I really do not like about this module is the URL rewriting (in actual fact lack of rewrite) if the URL to be re-written includes attributes/options. There’s pretty much only 1 link that is completely annoying for me, and I’d like to see it solved before the release is made. But, in case it isn’t, here’s how to replicate the “annoying problem”;

1. Find a product which has options/attributes
2. Add to cart
3. The linkback from the shopping cart list to the product page, includes attributes and is therefore not rewritten. I think this is a mistake (note, I do not think it’s a bug, just a mistake not to rewrite it).

As an example, go here, select options, add to cart, then mousevoer the link back to the product…

How to solve this. Easy, at least in my preview Beta version it is!

Step 1: add a new true/false to the USU-init file…

Add this:
[php]@define(‘SEO_URLS_CART_RETURN’, ‘true’); // true or false
// true = SEO Urls are used from shopping cart link
// false = SEO Urls are NOT used from shopping cart link[/php]

probaby all these will be part of an admin interface rather than in a text file, if that happens, I’ll update the post appropriately.

Step 2: amend existing code in the shopping_cart file…

Find this:
[php] ‘

‘ . tep_image(DIR_WS_IMAGES . $products[$i][‘image’], $products[$i][‘name’], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . ‘

‘ .

‘ . $products[$i][‘name’] . ‘‘;[/php]

Change it to this:

‘ . tep_image(DIR_WS_IMAGES . $products[$i][‘image’], $products[$i][‘name’], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . ‘

‘ .

‘ . $products[$i][‘name’] . ‘‘;[/php]

Save and upload both files. Done!

Now you can decide whether to have the link from the shopping cart rewritten [true] or not [false]. The only downside is that if you select “true”, the link will not contain the selected attributes – but that hardly matters I think.

Anyway, when the contribution comes out it is possible that this (or something like this) will be included in the core code. If not, then you can use my ideas on this page to give yourself more choice.


In actual fact, all we are doing is changing this:

to this:
[php](SEO_URLS_CART_RETURN == ‘true’ ? tep_get_prid($products[$i][‘id’]) : $products[$i][‘id’])[/php]

This uses a TERNARY Operator to grab the value of SEO_URLS_CART_RETURN, and do either of this:[php]tep_get_prid($products[$i][‘id’])[/php] or this: [php]$products[$i][‘id’][/php] based on whether the value of SEO_URLS_CART_RETURN is “true” or not.

So, what is tep_get_prid?

Here is the code, taken from includes/functions/general.php:
// Return a product ID from a product ID with attributes
function tep_get_prid($uprid) {
$pieces = explode(‘{‘, $uprid);

if (is_numeric($pieces[0])) {
return $pieces[0];
} else {
return false;

This is an existing osCommerce function which strips the attribute key[s] and value[s] from the URL. In other words, it would change this:{4}1{3}5 to this:

The part of the URL that controls attributes “{4}1{3}5” has been stripped using the function as it “explodes” the ID like this:

0: 1
1: 4}1
2: 3}5

and then simply outputs the value at “0”, which will be the product ID.


So, add it all up and you can see that what we are doing is putting in a new control “true/false” to use the tep_get_prid function to strip [or not!] the attributes from the URL.

A little clearer now?

osCommerce London – update

So, having made the decision to meet up at London for the osCommerce public meeting, my first task was to book train tickets as there’s no way I’m driving! With that done, and quite cheaply too I might add, I then had to decide on the logistics of getting from my place to the train station (2.5 hours drive), then the train (another 2 hours). As I had never been to London, the experience was novel, especially the tube (underground system) – tip for anyone; try not to mix up “north” and “south” ahem 😉

I finally arrived at the Match Bar after some wandering around the sights and sounds of London. A round of introductions ensued – everyone knew who I was by the name, which was great (or maybe not so great, depending upon how you look at it lol). I met;

– Harald Ponce de Leon
– Mark Evans
– Matthijs vd Vegte
– Jan Zonjee
– Nick Weisser
– Mark from the forum and who has posted on this blog as “enigma1”
– Bruno and his business partner (Presta Shop guys)
– Yubico Guy (there will be a post soon about Yubi Key, their product)
— as well as more whose names I am afraid to say I forget – sorry!

We discussed the past, present and, importantly, the future of osCommerce – with some debate about the commerical aspect of osCommerce [how it is seen by different people], some of the forum characters, some of the people intent on destroying osCommerce and lots of other stuff. It was a worthwhile exercise and great to finally meet up with people who I’ve “known” for a long time but never met in real life.

Some great ideas were brought up, not only for osCommerce, but also for the osCommerce forum – I truly believe that osCommerce will be seen (once again) as something which people will want to use.

Summing up; really great to meet some good guys and would have been nice to see more UK people make an effort to be there, after all, it’s not often that you have the chance to speak with the developers of a software application face-to-face. Watch out for the next osCommerce meeting (coming up soon), which will be a BLAST!

osCommerce London

Friday 11th December. London osCommerce Public Meeting.

osC London

If you can make it, it would be great to meet anyone who uses or develops osCommerce.

You can read more about the osCommerce London meeting here.