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”.
This function returns some values from the database. These values are determined by the “install” function.
This function removes (which is why it is called “remove”!) values from the database when you uninstall the module from within your admin section.
This function, guess what, install values to the database when you install the module from within your admin section.
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.
This is the main “parent” function that controls all the other functions and passes information to those functions.
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]define(‘MODULE_SHIPPING_FLAT_TEXT_WAY’, ‘Best Way’);[/php]
[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.