osCommerce: How to Limit a Products Quantity in Cart

Posted in Did you know? on August 8th, 2008

Justin RainsWelcome! Thank you for visiting!
Please Subscribe to my full feed.

I have a magazine site and to make life easier I wanted to only allow customers to order 2 years for their subscription. I found a contribution that added in admin support and lets you vary the amount per product. I just did not need that level of control. I want to limit you to two years, no matter what product. Here’s what I did to do this in the osCommerce shopping cart.

First, find this code in shopping_cart.php:

if (STOCK_CHECK == 'true') {
$stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
if (tep_not_null($stock_check)) {
$any_out_of_stock = 1;

$products_name .= $stock_check;
}
}

After that code add this code in:


if ($products[$i]['quantity'] > 2) {
$products_name .= " - Too many years ordered, Maximum of 2 Years“;
$products[$i][’quantity’] = “2″;
$cart->remove($products[$i][’id’]); // remove this new item from the cart session
$cart->add_cart($products[$i][’id’],2,$products[$i][’attributes’]); // update the qty
}

As you can see I have hard coded two years and also the text that is displayed. To change the amount simply change the three occurrences of 2 in my sample code.

I hope this is of help to others who do not need the per-item quantity control. Feel free to add a comment.


Related Posts:



2 Comments »

  1. Gravatar

    How did you manage to even find that contribution. I’ve been using oscommerce for about 4 years now and nowadays it’s hard to find a contribution on the oscommerce forums because there are just too many!

    Comment by T Shirt Guy — August 28, 2008 @ 8:53 pm

  2. Gravatar

    T Shirt Guy: I didn’t find the contribution I coded it myself. Let me know if you need any coding done for osCommerce I have written 10 or so contributions :)

    Comment by Justin — August 28, 2008 @ 9:05 pm


RSS feed for comments on this post. TrackBack URI



Leave a comment




  • I Share

      Share Feed: Subscribe
  • Recent Visitors

  • Blogroll

  • Cool Stuff