Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Initial Cart Quantity Value


lockett104

Recommended Posts

After hours of testing and trying to get this to work, I am about stumped. My products are sold in cases and each case happens to vary in regards to quantity, some have 12, 24, and others have 72 units. I have read other posts and I realize how to get the initial value to be something other than 1 in the cart after clicking the add to cart button by editing the includes\application_top.php file and altering the line of code:

$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $attributes))+$product_quantity+1, $attributes);
But, you can see in orange, where I also added the variable $product_quantity, which I decided to use a select statement to select the products_quantity value from the products table.
$product_quantity = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$HTTP_POST_VARS['products_id'] . "'");
Using the default quantity seemed easier than adding another column to my products table and this will work for me, because I have turned of the stock checking in my store. I tried if statements and could never get the cart to distinguish between the different values. All I need is for the cart to recognize what quantity each case contains and to populate the shopping cart quantity with that value when the product is added.

One more thing, I also have been modifying the includes\classes\shopping_cart.php file, so that the quantities will only go by the increments of the case. For example, on line 126

if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity)) {

$quantity = ceil(intval($quantity)/12)*12;

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

This formula makes it count by increments of 12, but it does no good if the product has cases of 24 or 72. I tried an if statement that (attempted) to distinguish if the value was equal to 12 or 24 or 72, but I could never get it to truely recognize each value. If anyone could point me in the right direction or give any tips I would REALLY appreciate it, honestly.

 

Chad

Chad Lockett

no outside links in signatures allowed

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...