Deconstructing an osCommerce Shipping Module

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:
  1. function keys()

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

PHP:
  1. function remove()

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:
  1. function install()

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

PHP:
  1. function check()

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

PHP:
  1. function quote($method = '')

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

PHP:
  1. function flat()

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

PHP:
  1. class flat

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 phpbuilder.com).

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:
  1. define('MODULE_SHIPPING_FLAT_TEXT_WAY', 'Best Way');

to this:

PHP:
  1. define('MODULE_SHIPPING_FLAT_TEXT_WAY', '1 set cost for all products');

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.

Posted in Uncategorized
  • Adrienne

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

  • 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.

  • Gary

    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 ;)

  • http://www.arlisa-bijoux.com 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! :)

  • http://www.colinna.com 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.

  • Gary

    "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?


Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive - and you get a link from my homepage to your site. Cheers!