Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Setting upper and lower limits for 'quantity'


Guest

Recommended Posts

Posted

I needed to set the minimum order to 1 and the maximum to 30 (those are kilos, waiting for osc new 'weight unit switch' available as tutorial but not available in the dist osc.2.2). I tweaked /catalog/includes/classes/shopping_cart.php

line 110:

function update_quantity($products_id,...

 

after the line

 

      if (empty($quantity)) return true; // nothing needs to be updated if theres no quantity, so we return true..

 

and before the line

 

      $this->contents[$products_id] = array('qty' => $quantity);

 

I added this code:

 

// set min and max quantity for min and max order weight
if ($quantity < 1 || $quantity > 30) return true; // quantity exceeds order weight range - nothing needs to be updated in this case, so we return true..

 

so if user tries to set the quantity to 0.9 or 30.1 the quantity remains unchanged, as if they never tried to change it.

 

 

Another hack, very specific to what I need, deals with rounded quantity. The shop I'm setting up sells items by weight, but some items per units, for which I need an min.X number of them to reach the minimum 1kg order and a max.Y number to reach the limit of 30kg order.

 

I've added this bit of code just after the one above for the specific item (identified by its own id):

 

// round ITEM-X to units
if ($products_id == 2) { // ID of the item in question
 $quantity = round($quantity); // item sold in units - we round up $quantity..
 if ($quantity < 10) $quantity = 10; // quantity exceeds min order weight range - we set it to the min..
 if ($quantity > 300) $quantity = 300; // quantity exceeds max order weight range - we set it to the max..
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...