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:
1 2 3 4 5 6 7 8 | 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:
1 2 3 4 5 6 | if ($products[$i]['quantity'] > 2) { $products_name .= "<u> - Too many years ordered, Maximum of 2 Years</u>"; $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.
{ 3 comments… read them below or add one }
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!
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
Great mod, thanks! Works perfectly for my digital media download store.
NOTE: If you copy and paste this code, you’ll need to re-type certain characters (specifically quotes) because the blog formatting makes them unrecognizable to php editors.