About Club osCommerce

Showcasing osCommerce…the good, the bad and the ugly!

StumbleUpon It! DIGG It!

osCommerce Previously Purchased

Written By Gary on Jun 15 2010 · Comments (1)

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!


Contacted today by someone who wanted the ability to show customers what they have already purchased (whilst browsing the site). In other words display a "You have already purchased this" warning message at the top of the product info page etc etc.

The first thing to know is that we need to have the customer logged in as without their customer ID there is no way to grab the needed information.

The next thing to know is that we need to join together two database tables; orders & orders_products

It's really very straightforward;

1. customer logs in
2. we join the orders and orders_products table and grab the needed product IDs of the already purchased items
3. we place these into an array
4. we check the product Id whilst the customer is browsing the store, against the array. If the numbers match, show the message

All in all, this was 10 minutes work to get a viable solution. Of course, it could be cleaned up and made better (eg, show the "you've bought" message elsewhere such as the shopping_cart page, or in the products_new module etc), but for now all that is needed is the message on the product_info.php page, and it works OK.

1 Comment

  1. Note that I have now cleaned up the code a bit and blogged here; http://www.clubosc.com/you-already-purchased-this-item.html

    Comment by Gary — July 29, 2010 @ 2:02 pm


Leave a comment

RSS feed for comments on this post

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!