Jump to content
thirty bees forum
  • 0

Bug resulting in negative stock despite "deny orders" setting


Question

Posted

I have a product with attributes. I've noticed that sometimes I get negative stock, even though orders should be denied if there isn't enough stock. The setting in the Preferences>Products page is "Deny order" and the Product>Quantities setting is "Default> Deny orders as set in the Products Preferences page".

I've now been able to reproduce the issue.

  1. Customer A places item with combination Y in shopping cart.
  2. Customer B places item with combination Y in shopping cart.
  3. Total of items with combination Y placed in shopping cart by Customers A and B exceeds amount in stock.
  4. Customer A checks out.
  5. Customer B checks out.
  6. Stock is now negative and both customers successfully placed their orders.

17 answers to this question

Recommended Posts

  • 0
Posted

hi, sorry for bump old post, do you found the solution? I'm having this problem too. 2 order in same time, the second customer get error message "order not valid", but the order still go through

  • 0
Posted

I've test several times with fresh install 1.0.4, the problem still there, the second customer get "On backorder (not paid)" on the order status. as you can see I've disable backorder. can this be a bug? I can confirm PS 1.6.1.18 have this problem too.

0_1525482253280_Screenshot from 2018-05-05 08-02-08.png

  • 0
Posted

This surfaced again. The stock of all combinations was 0 and when I visit the product page I am unable to place the product in the cart. So I don't understand how the customer could have bought the product. Does anyone have an idea of how this could have happened?

  • 0
Posted

I don't know where the check of this feature is. If the check is on the addToCart function, then it won't work, when the customer had it already in the cart. It goes like this:

  1. customer 1 puts product in the cart
  2. customer 2 puts product in the cart
  3. customer 1 places the order

I am not sure if it's like that. This is just my assmption...

 

Edit: Sorry that is actually your first post 😅 Is there no check on the checkout?

  • 0
Posted

I am not using the inbuilt setting, so I don't know, how it works. But I am using this on checkout:

    // Check if stock of a product is still available (it could be ordered in the meantime)
    public function initContent() {

        $products_in_cart = $this->context->cart->getProducts();
        $deleted_products = array();

        foreach ($products_in_cart as $product_in_cart) {
            if ($product_in_cart['quantity_available']==0) {
                $this->context->cart->deleteProduct($product_in_cart['id_product'], $product_in_cart['id_product_attribute']);
                $deleted_products[] = $product_in_cart['name'];
            }
        }

        $this->context->smarty->assign(
            array(
                'opc_deleted_products' => $deleted_products,
            )
        );

        parent::initContent();
    }

Maybe it can't help you too...

  • Thanks 1
  • 0
Posted

Thanks, @wakabayashi! The odd thing is that I can't even put it in the shopping cart. I think your assumption is right that it must have been in the shopping cart already when the stock finally reached 0.

@datakick, can I use wakabayashi's code in Chex and where exactly would I put it in there? 

  • 0
Posted

The problem is that order is created "after" payment is already processed. And it's just not possible to NOT create it at this time. The money are already on the way, so we need to track it against some order / customer.

If the stock meanwhile decreased to zero between the product was added to cart and order was paid, the result will be order on backorder. 

It's not possible to fix this problem completely, not without fundamental change to ordering process.There will always be some timespan when this can happen, we can only limit it to the minimum. For example by checking the availability just before the customer is redirected to payment gateway. But with 3DSecure / SCA / SMS confirmations the payment can take a long time, so this issue can still occur. 

Regarding your question -- no, you can't use this with chex. But I'll add this 'last second' availability check to limit this to the minimum. Will be in the next version

  • Like 1
  • Thanks 1
  • 0
Posted

@datakick your are right, this doesn't prevent, if you are at payment. But in our case 9 out of 10 times the issue was like that: 

  1. customer 1 places product x to cart
  2. customer 1 is making a pizza 🍕
  3. customer 2 places product x to cart
  4. customer 2 orders product x
  5. product x is no more available
  6. two hours later customer 1 has eaten his pizza and orders product x

This case is now prevented. For now we have the issue only left if some customer are ordering inside like 5 minutes product x.

My code from above is only a few days old, since we had the "pizza" case a lot in these corona times.

  • Like 1
  • 0
Posted

@Chandra oh ok interesting. As I said this is just my own "solution". 

In my case it's wanted, that customer can order 5, if we have only 4 left. But he shouldn't been able to order 1 if 0 is left. I know very strange 🤣

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...