Related Products in osCommerce

By | June 7, 2012

My next project (which is to be done at some point before the end of the coming weekend) is to implement a system of “related products”. There are loads of already made addons that can relate one product to another and so on…

But none of them are good enough to put into my clients site. So I determined to code a “related products” module that better fits the needs of the Site Owner.


Each product needs the ability to be related to a small number of any products, in 3 categories;

  • “Worse” products. These are products that are similar to the product being looked at, but may be less expensive.
  • “Better” products. The inverse of the above.
  • “Related” products. Products that have a very close alternative, but don’t really class as “worse” or “better”.

Special handling of the better/worse products

If a product (blue widget) has a better version (blue turbo widget), and this is assigned, then also assigned must be the blue widget as a “worse” product than the turbo widget. Hope that makes sense ?

A fairly straightforward system, that won’t take very long to code up

The general idea is to (somewhat) replicate the 2.3.1 larger images system and add 3 more similarly coded pieces to categories.php to add the relationships between products. In the shop side, I will then create three new modules based on products_id, and grab the “better”, “worse” and “related” products and show them in appropriate places.

I’ll update the post over the weekend as I get bits and pieces of this coded up.

11 thoughts on “Related Products in osCommerce

  1. Gary Post author

    Admin function is complete.

    Works well to add/delete product IDs in any (or all at the same time!) of the 3 categories; “worse”, “better”, “related”…

  2. steph

    So interesting! 🙂
    this is going to be a very good way to keep users on the site if the landing product is not quite right..

    One small addition could be that it checked if the rellated product is in stock and activated.. maybe even make sure that “worse” acctually is cheaper (in case the good product has a special price, discount etc)

    This function is really going to give a face to face, humant intelligence kind of feel to a site..

  3. Isa

    I agree that this sounds very interesting indeed 🙂 A very clever way to promote more products.
    I look forward to read more about it.

  4. Gary Post author

    So here is a mockup that the client would like to happen in the shop;


    As you can see, it is a box that shows a random selection of “better”, “worse”, “related” products to the one being looked at.

    My next task is to create a module that pulls the data and displays it correctly. As I set up the overall module to use three different database tables, I need to do an interesting MySQL query called “union“.

  5. Gary Post author

    And now here is the code module;


    Pretty close match!

  6. Gary Post author

    Code is now LIVE on the shop for which it was written…

    I may yet change the basis of the mod from 3 separate DB tables to 1 table. We’ll see how it goes for a little while…

  7. Steph

    Ok.. first couple of impressions and feedback since this was installed, are very positive!

    The code seems solid, and stable.
    I had feared that it would take very long to create the links between the products, but with the smart backwards linking, it is much faster than expected.

    The idea is that if a product is marked as a cheaper alternative to the viewed product, then the viewed product is automatically marked as a better alternative to the cheaper product. very smart!

    Also there is an option to just link products as rellated. This has no backwards linking, witch i innitially thought was a mistake, but it turns out that it might be a good idea..

    After using this mod for a few days, i figured that is is very important to keep the custommer in mind.. what would the custommer be mostly interested in?
    Don’t use it just to show bettter or cheaper products.. they really have to be alternatives to the problem the user is trying to solve with the product they are looking at.

    If the user is looking at at an automatic BBQ grill, don’t relate cheaper BBQ gloves.. The user is looking for a BBQ Grill, don’t confuse them.. when they have done their choice, and ultimatelly added on to the cart, THEN you can cross sell.
    Gary has done a really cool feature for that, that is not annoying for the custommer, and shows what others also have bought – but only after the product has been added to the cart:

  8. Gary Post author

    Many thanks for the feedback Steph 🙂 You raise a very good point that hardly any osCommerce store owner has thought about…the “customer flow” at the “product buying” stage. I’ll make a blog post on it, to expand the idea…

    For anyone wanting to see the module, have a visit at Stephs shop.

  9. Isa

    Hi Gary
    I took a peek at Stephs site to see it in action, it’s very neat looking and works like a charm, but most importantly it’s a clever addition that any shop owner should add to their shop. 🙂 Well done.
    Great looking shop btw Steph 🙂

    I was thinking that a shop like Stephs could also benefit from a “frequently bought together” option like they do at amazon for example, with two or three products put together, perhaps discounted if bought together. Just a thought.

  10. Steph

    @Isa, thanks for your words, and good idea with the frequently bought together feature.

    I’d be a bit afraid to overcrowd the product info page, but on the other hand, i also think that the very bold aproach mentioned above about solving a prolem for the user, realle depends on the users problem..

    To hang on to the examble above, some times the user might really need a grill, and presenting him/her with grill accesories would be a distraction..

    On the other hand, a user might have a grill and need accessories. The situation is entirelly different, and would bennefit of a “other also bought” or “frewuently bought together” function..

    It is a tricky situation, and maybe one that will need some further thinking, and ofcourse a feeling of ones custommers..

  11. Gary Post author

    Isa – don’t give Steph more ideas! 😀

Leave a Reply

Your email address will not be published.