News:

AbanteCart v1.4.2 is released.

Main Menu
support

"Subtract Stock" not working..

Started by bs135, June 20, 2012, 04:07:44 AM

Previous topic - Next topic

bs135

In manual: Admin User Manual > Catalog menu > Products  > Options Tab
QuoteSubtract Stock: If the "Subtract Stock" dropdown is enabled AbanteCart will automatically decrease the quantity you have left from this product according to the quantity ordered. This is usually set to Yes unless you have unlimited quantity of this product or the product is a service you offer.

I set "Subtract Stock" is "Yes".  But when a order is completely, the product quantity is not change. I use AbanteCart 1.0.2.

Please help me..

Thanks

abolabo

hello
it's a bug

we will fix it in next release.

you can do this manually.
open file core/lib/cart.php in text editor and find this (line 146)

if ($option_value_query['subtract'] && (!$option_value_query['quantity'] || ($option_value_query['quantity'] < $quantity))) {
$stock = FALSE;
}

and replace this by

if (!$option_value_query['subtract'] && (!$option_value_query['quantity'] || ($option_value_query['quantity'] < $quantity))) {
$stock = FALSE;
}

"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

bs135

I fixed but it's still the same.
I mean, after ordering, the quantity of products has not been subtracted in the total.

bs135

It's not automatically decrease the quantity after ordering.
Please help me.

abolabo

#4
need decrease to zero?
But what exactly?
Total quantity of product or product option quantity?
i checked - quantity in product option decreased after order confirm.
Please, explain what result you are expecting.
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

bs135

My quantity in product option is not decreased after order confirm.  :(

I view my database, table 'ac_products', value of field 'subtract' is '1' for all products.
But in table 'ac_order_products', value of field 'subtract' is '0' for all products.

And in file \storefront\model\checkout\order.php - line 150:
Why hasn't it update 'subtract' value for 'ac_order_products'.

foreach ($data['products'] as $product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_products
SET order_id = '" . (int)$order_id . "',
product_id = '" . (int)$product['product_id'] . "',
name = '" . $this->db->escape($product['name']) . "',
model = '" . $this->db->escape($product['model']) . "',
price = '" . (float)$product['price'] . "',
total = '" . (float)$product['total'] . "',
tax = '" . (float)$product['tax'] . "',
quantity = '" . (int)$product['quantity'] . "'");



Please help me.?

abolabo

Quote from: bs135 on June 23, 2012, 05:40:57 AM
My quantity in product option is not decreased after order confirm.  :(

I view my database, table 'ac_products', value of field 'subtract' is '1' for all products.
But in table 'ac_order_products', value of field 'subtract' is '0' for all products.

And in file \storefront\model\checkout\order.php - line 150:
Why hasn't it update 'subtract' value for 'ac_order_products'.

foreach ($data['products'] as $product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_products
SET order_id = '" . (int)$order_id . "',
product_id = '" . (int)$product['product_id'] . "',
name = '" . $this->db->escape($product['name']) . "',
model = '" . $this->db->escape($product['model']) . "',
price = '" . (float)$product['price'] . "',
total = '" . (float)$product['total'] . "',
tax = '" . (float)$product['tax'] . "',
quantity = '" . (int)$product['quantity'] . "'");



Please help me.?

wait. quantity of product option you have to look in control_panel->catalog->products->options. not in general section. Total quantity and quantities of some kinds of this product are not the same. If you decide to set options for product total quantity will ignore.


You show me code that write quantity in order. Please check line 220 in the same model file:


$order_option_query = $this->db->query("SELECT *
FROM " . DB_PREFIX . "order_options
WHERE order_id = '" . (int)$order_id . "'
AND order_product_id = '" . (int)$product['order_product_id'] . "'");

foreach ($order_option_query->rows as $option) {
$this->db->query("UPDATE " . DB_PREFIX . "product_option_values
  SET quantity = (quantity - " . (int)$product['quantity'] . ")
  WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "'
        AND subtract = '1'");
}
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

bs135

I checked with a product with some options. It work. The quantity of the kind of this product decreased after order confirm.

But a product without option, the Total quantity of this product not decreased after order confirm.
Please show me how to setup that feature.

I saw the code in same model file, line 215:
This code checked 'subtract' value in database table 'ac_order_products' to Subtract the quantity in table 'ac_products'.
But I viewed my database, value of field 'subtract' is '0' in table 'ac_order_products', and is '1' in table 'ac_products'.


$order_product_query = $this->db->query("SELECT *
FROM " . DB_PREFIX . "order_products
WHERE order_id = '" . (int)$order_id . "'");

foreach ($order_product_query->rows as $product) {
if ($product['subtract']) {
$this->db->query("UPDATE " . DB_PREFIX . "products
SET quantity = (quantity - " . (int)$product['quantity'] . ")
WHERE product_id = '" . (int)$product['product_id'] . "'");
}

bs135

I checked with a product with some options. It work. The quantity of the kind of this product decreased after order confirm.

But a product without option, the Total quantity of this product not decreased after order confirm.
Please show me how to setup that feature.

abolabo

Quote from: bs135 on June 23, 2012, 09:13:23 PM
I checked with a product with some options. It work. The quantity of the kind of this product decreased after order confirm.

But a product without option, the Total quantity of this product not decreased after order confirm.
Please show me how to setup that feature.

I saw the code in same model file, line 215:
This code checked 'subtract' value in database table 'ac_order_products' to Subtract the quantity in table 'ac_products'.
But I viewed my database, value of field 'subtract' is '0' in table 'ac_order_products', and is '1' in table 'ac_products'.


$order_product_query = $this->db->query("SELECT *
FROM " . DB_PREFIX . "order_products
WHERE order_id = '" . (int)$order_id . "'");

foreach ($order_product_query->rows as $product) {
if ($product['subtract']) {
$this->db->query("UPDATE " . DB_PREFIX . "products
SET quantity = (quantity - " . (int)$product['quantity'] . ")
WHERE product_id = '" . (int)$product['product_id'] . "'");
}


Yes, you are right. it's a bug. Need to write

foreach ($order_product_query->rows as $product) {
if ( !$product['subtract']) {
$this->db->query("UPDATE " . DB_PREFIX . "products
SET quantity = (quantity - " . (int)$product['quantity'] . ")
WHERE product_id = '" . (int)$product['product_id'] . "'");
}


i mean " if ( !$product['subtract']) {". If we enable subtract for product we don't need decrease quantity of it... and otherwise...
it's stupid mistake.
Thank you.
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

bs135


Forum Rules Code of conduct
AbanteCart.com 2010 -