Deconstructing an osCommerce Shipping Module

By | July 23, 2008

Shipping is just about the easiest thing to learn to code in osCommerce – what I am going to do in this post is deconstruct a shipping module so that you learn a little bit about how it works…

The module we are looking at is /includes/modules/shipping/flat.php – starting from the bottom I will attempt to explain each “function”.

[php]function keys()[/php]

This function returns some values from the database. These values are determined by the “install” function.

[php]function remove()[/php]

This function removes (which is why it is called “remove”!) values from the database when you uninstall the module from within your admin section.

[php]function install()[/php]

This function, guess what, install values to the database when you install the module from within your admin section.

[php]function check()[/php]

This function checks the values in the database that are linked to the module.

[php]function quote($method = ”)[/php]

This function outputs a shipping quotation to the checkout_shipping.php page if the module is installed.

[php]function flat()[/php]

This is the main “parent” function that controls all the other functions and passes information to those functions.

[php]class flat[/php]

The overall class, which allows us to use the above functions logically.

Classes are nothing more than a collection of variables and functions acting on those variables. They provide a means of thinking about things in real world terms. In other words they describe an object. An object, or instance, of a class is an actual “living, breathing” structure of that class. Let’s say we want to describe a bicycle. A proper class of a bicycle might have the variables $pedals, $chain, $front wheel, $rear wheel, $brakes, and $handle_bars. Functions of the bicycle would include Stop(), Accelerate(), Coast(), TurnLeft() and TurnRight(). You can think of your script as the entity operating that bike. The function Accelerate() could be passed an argument such as $Braking_Force and use that information along with the defined instance variables (probably $brakes and $wheels) and output some result back to your script.
For more reading on classes, click here (external link to

Changing Text in Shipping Modules

Some things that are in UPPER CASE, like this MODULE_SHIPPING_FLAT_TEXT_TITLE is a defined piece of language…which means that it can be changed in the linked language file – NOT in the actual shipping module. The language files are found within the languages structure – for “flat.php”, the language file is at;
/includes/languages/english/modules/shipping/flat.php – simply change the wording to reflect what you want on the page. If you wanted to change the description from “best way” to “1 set cost for all products”, you would change this:

[php]define(‘MODULE_SHIPPING_FLAT_TEXT_WAY’, ‘Best Way’);[/php]

to this:

[php]define(‘MODULE_SHIPPING_FLAT_TEXT_WAY’, ‘1 set cost for all products’);[/php]

Other things that are in UPPER CASE are found in the database – it was added when we installed the Module using the “install” function. These are controlled from within your Admin section.

I hope that this short blog post was useful – in the future I will create a shipping module from scratch and show you how it’s done. If anyone has an idea for a shipping module, please comment below.

6 thoughts on “Deconstructing an osCommerce Shipping Module

  1. Adrienne

    Thank you very much, this was exactly what I was looking for 🙂

  2. Morne

    Where’s the part where you “Deconstruct” the module? All you did was give a definition of the function names.
    I’m sorry to say this is not a useful article by any stretch of the imagination.

  3. Gary Post author

    If you would, please rework the blog post and send to me, will be very happy to post it up and give you full credit. Look forward to it 😉

  4. Isa

    Thanks for posting this Gary. I found this to be a very interesting read as I’m always on the lookout for step by step explanations. Thumbs up! 🙂

  5. Sam Balette

    I fully agree with Morne.
    I find the answer from Gary very rude.
    Is sad to observe all these morons writing blogs instead of learning.

  6. Gary Post author

    “Is sad to observe all these morons writing blogs instead of learning.”

    Is it more sad for you to comment on one of these morons blogs?

Leave a Reply

Your email address will not be published.