Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: "Subtract Stock" not working..  (Read 16785 times)

Offline bs135

  • Newbie
  • *
  • Posts: 27
  • Karma: +4/-0
    • View Profile
"Subtract Stock" not working..
« on: June 20, 2012, 04:07:44 AM »
In manual: Admin User Manual > Catalog menu > Products  > Options Tab
Quote
Subtract 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

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: "Subtract Stock" not working..
« Reply #1 on: June 20, 2012, 07:56:07 AM »
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)

Code: [Select]
if ($option_value_query['subtract'] && (!$option_value_query['quantity'] || ($option_value_query['quantity'] < $quantity))) {
$stock = FALSE;
}
and replace this by

Code: [Select]
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

Offline bs135

  • Newbie
  • *
  • Posts: 27
  • Karma: +4/-0
    • View Profile
Re: "Subtract Stock" not working..
« Reply #2 on: June 20, 2012, 09:11:53 AM »
I fixed but it's still the same.
I mean, after ordering, the quantity of products has not been subtracted in the total.

Offline bs135

  • Newbie
  • *
  • Posts: 27
  • Karma: +4/-0
    • View Profile
Re: "Subtract Stock" not working..
« Reply #3 on: June 22, 2012, 03:21:00 AM »
It's not automatically decrease the quantity after ordering.
Please help me.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: "Subtract Stock" not working..
« Reply #4 on: June 22, 2012, 04:07:24 AM »
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.
« Last Edit: June 22, 2012, 04:24:41 AM by abolabo »
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline bs135

  • Newbie
  • *
  • Posts: 27
  • Karma: +4/-0
    • View Profile
Re: "Subtract Stock" not working..
« Reply #5 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'.
Code: [Select]
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.?

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: "Subtract Stock" not working..
« Reply #6 on: June 23, 2012, 09:04:21 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'.
Code: [Select]
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:

Code: [Select]
$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

Offline bs135

  • Newbie
  • *
  • Posts: 27
  • Karma: +4/-0
    • View Profile
Re: "Subtract Stock" not working..
« Reply #7 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'.

Code: [Select]
$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'] . "'");
}

Offline bs135

  • Newbie
  • *
  • Posts: 27
  • Karma: +4/-0
    • View Profile
Re: "Subtract Stock" not working..
« Reply #8 on: June 27, 2012, 08:19:05 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.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: "Subtract Stock" not working..
« Reply #9 on: July 11, 2012, 08:04:16 AM »
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'.

Code: [Select]
$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

Code: [Select]
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

Offline bs135

  • Newbie
  • *
  • Posts: 27
  • Karma: +4/-0
    • View Profile
Re: "Subtract Stock" not working..
« Reply #10 on: July 14, 2012, 05:06:58 AM »
thank you very much

 

Powered by SMFPacks Social Login Mod