modifying osCommerce – [part 2 – Functions, Cases, Blocks Oh My]

As I stated in my previous article on osCommerce, I did some work that had me modifying osCommerce. The modifications dealt with customizing shipping to be per product ordered. They fell under these categories:

  • Product Display
  • Shopping Cart Behavior
  • Checkout Process

Before We Code

It’s imperative to have a clearly defined plan for what additional data we’re storing. It’s also a good idea to have the database tables already modified.

The only table I ended up modifying was orders_products. I added fields like greeting, customers_shipping_id, discounts, and shipping_date.

There was only one table that I created (that was related to my modification): customers_shipping (customers_shipping_id PK, customer_id, shipping_name, shipping_address1, shipping_address2, shipping_city, shipping_state, shipping_zip)

Product Display

The file we’ll be looking at is product_info.php. Not a lot of osCommerce specific modifications happened here. I just plugged in specific PHP code for the user to select a shipping method, a destination, greeting, and a shipping date.

Shopping Cart

It’s good to understand the process that osC uses for a shopping experience.

Selecting “add to cart” from product_info.php goes through this process:

  1. hits application_top.php with a HTTP GET of action “add_product”.
  2. flies to the switch case statement for $action which is: switch ($HTTP_GET_VARS[‘action’]) {
  3. goes to “add_product”:

The Shopping Cart has a few functions.

Found in includes/classes/shopping_cart.php

restore_contents()—does a restoration of shopping cart contents based on your shopping “basket”—the previous items you added to your cart with a login/password but did not check out.

notes: if you are a guest on the cart and you have products, when you log in their contents are added to your “basket”—as well as each additional product you add to your cart until checkout.

Additions I made here were mainly adding fields to be inserted into the “basket” (customers_shipping_id, greeting, shipping_date, shipping_id) I also changed the cart object that is returned here ($this->contents[$products[‘products_id’]]) to contain shipping_date, shipping_id, greeting and customers_shipping_id.

add_cart($products_id, $qty = ‘1’, $attributes = ‘’, $notify = true)—adds the product to your cart.

notes: if we’re dealing with a logged in session, add it to the basket (database) as well as the cart (sessions)

get_products()—provides a list of all products in the cart.

Once a user has items in the shopping cart, we go to the checkout process:

in includes/classes/order.php you’ll find a few functions.

cart()—transfers what was in the the shopping cart into an order.
query()—writes the order to the DB.
order()—initializes and calls cart()

The order then passes to a payment module, we used Authorize.NET AIM…

Methods in includes/classes/modules/payment/authorizenetaim.php

pre_confirmation_check()—runs a basic CC validation algorithm ( does not actually CHARGE the card )

before_process()—hits VIA cURL and returns $response which is a pipe delimited string that has specifications “here:

To Change what username or password this module uses, the easiest way to go is via /catadmin/ and go to Modules > Payment > AIM


This is where the bulk of the work I did was – the main files we’re dealing with are prefixed with checkout_.

The main pointer I can give with dealing with the checkout_ files is realize they all hit application_top.php first before spitting back to the actual page.

Database Notes

address_book—contains the default billing address for customers. address_book was originally intended for multiple shipping addresses, but not at the product level and didn’t provide enough flexibility.

categories—contains all of the categories and their “parent” categories. some redundancy.

categories_description—all of the names of the categories and their text descriptions that display on individual category pages.

customers—customer database. only really deals with osCommerce logins contains new customer email addresses. only important to osCommerce.

customers_basket—contains “shopping basket” for customers. i added shipping_date, greeting, customers_shipping_id, and shipping_id to this table.

orders—used in displaying order history. is the osCommerce orders table.

orders_products—modified with additions of shipping_date, greeting, users_shipping_id, and shipping_id (users_shipping_id == customers_shipping_id)

In Closing…

osCommerce is not so bad to modify if you have a clear plan. However, I really question some of the methods they use to iterate through products, like no foreach() loops!

My next article will be about analysis of your shopping cart. I’ll show you how to plug osCommerce into Google Analytics so that you can show your stakeholders great data on your store’s success.


About andyhillky
I'm cool.

8 Responses to modifying osCommerce – [part 2 – Functions, Cases, Blocks Oh My]

  1. UnluckyCat says:

    PLAY SOME SKYNYRD! Sorry. It’s a reflex

  2. John says:

    and you thought it would take two more weeks.

    you are the plastic guitar champ

  3. Kassa says:

    Congratulations, Andy! Now you can move on with your life! Haha! Just Kidding.

  4. HelloWorld says:

    Peace people

    We love you

  5. Chris K says:


    Very descriptive and wonderful ideas. Would you have a copy of the mod for trial/use? I am attempting to create a section to OSC cart to allow for a gifting module…that will allow the visitor to send items to multiple addresses. Anyway, beautiful work!


    Chris Kaiser

  6. bofe says:


    I don’t have a copy of the mod – it’s been a long while since I’ve worked with osC.

  7. Bryant says:


    I see that you don’t have a copy of this mod, but would you be willing to do it again? For money of course. I have been searching for this mod for some time.


  8. bofe says:


    Unfortunately, the mod is not publically available. I wrote it for a company I worked for almost 3 years ago.

    I would not be willing to do it again.

    Take care.

%d bloggers like this: