Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Preventing exorbitant qty's in cart


boxtel

Recommended Posts

Posted

this is the function in your shopping_cart.php class to update the quantity:

 

function update_quantity($products_id, $quantity = '', $attributes = '') {

global $customer_id;

 

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

 

if ($quantity < (tep_get_products_stock($products_id)+1)) {

 

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

// update database

if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

 

if (is_array($attributes)) {

reset($attributes);

while (list($option, $value) = each($attributes)) {

$this->contents[$products_id]['attributes'][$option] = $value;

// update database

if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");

}

}

}

}

 

 

as you can see, I have added the condition :

 

if ($quantity < (tep_get_products_stock($products_id)+1)) {

 

 

that means that I will not add more than I have in stock.

 

you can also say :

 

if ($quantity <= 999) {

 

 

if there is no limit to the quantity, you can order 99999999999999999999999 items while the price reverts back to the price of 1 item. And you can even checkout with that amount and price.

Treasurer MFC

  • 2 weeks later...

Archived

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

×
×
  • Create New...