Magento2: [Magento 2.1.2] Wrong error message in cart after entering invalid discount code with product stock qty = 1 (only for simple variant products)

Created on 28 Oct 2016  路  13Comments  路  Source: magento/magento2

Tested on last magento 2 version 2.1.2 and Luma sample data.

Preconditions

  1. Set a simple variant product qty to 1.

    With sample data i used

    http://luma.kamiceria.com/tiffany-fitness-tee.html

    with blue color and xs size (sku WS09-XS-Blue)

Steps to reproduce

  1. Add above product WS09-XS-Blue to cart
  2. Go to cart
  3. Add invalid discount code like 'xxx'

Expected result

  1. Magento shows error message

    'The coupon code "xxx" is not valid.'

Actual result

  1. Magento shows error messages

    'The` coupon code "xxx" is not valid.' ->OK

    'We don't have as many "Tiffany Fitness Tee" as you requested.' ->BUG
Checkout Format is valid Ready for Work bug report

Most helpful comment

It seems to be if there is not 2 * the number of items in your cart in stock, then the error happens.
eg.
if the item qty in-stock is 6 then
if you have 3 items in your cart and enter invalid discount there's no error.
if you have 4 items in your cart and enter invalid discount you get the error.

probably to do with the discount function copying the cart or something.

All 13 comments

Hi, thank you for your reporting. Internal ticket is created MAGETWO-60352

Ok the bug is reported, but when you fix it?

Unfortunately, we don't have time estimates for this bugfix now

Thank you, i hope you find the time to fix it asap.

Do you know if this bug is fixed on 2.1.3?

Can confirm the problem still happens in 2.1.3.

It seems to be if there is not 2 * the number of items in your cart in stock, then the error happens.
eg.
if the item qty in-stock is 6 then
if you have 3 items in your cart and enter invalid discount there's no error.
if you have 4 items in your cart and enter invalid discount you get the error.

probably to do with the discount function copying the cart or something.

Hi I have a similar issue, and it seems related.
I have a product with stock qty = 6.
I add this product to my cart with qty more than 3 (eg: 4)

Now I add another product.

It seems that magento will perform several qty check for items, and each loop will add double qty.
I don't know exactly but here one of my trace :

#0  Magento\Quote\Model\Quote\Item->setQty() called at [/httpdocs/vendor/magento/module-quote/Model/Quote/Item.php:325]
#1  Magento\Quote\Model\Quote\Item->addQty() called at [/httpdocs/vendor/magento/module-quote/Model/Quote/Item/Processor.php:100]
#2  Magento\Quote\Model\Quote\Item\Processor->prepare() called at [/httpdocs/vendor/magento/module-quote/Model/Quote.php:1617]
#3  Magento\Quote\Model\Quote->addProduct() called at [/httpdocs/vendor/magento/module-quote/Model/Quote.php:1722]
#4  Magento\Quote\Model\Quote->updateItem() called at [/httpdocs/vendor/magento/module-quote/Model/Quote/Item/CartItemPersister.php:72]
#5  Magento\Quote\Model\Quote\Item\CartItemPersister->save() called at [/httpdocs/vendor/magento/module-quote/Model/QuoteRepository/SaveHandler.php:69]
#6  Magento\Quote\Model\QuoteRepository\SaveHandler->save() called at [/httpdocs/vendor/magento/module-quote/Model/QuoteRepository.php:161]
#7  Magento\Quote\Model\QuoteRepository->save() called at [/httpdocs/vendor/magento/module-checkout/Model/Cart.php:574]
#8  Magento\Checkout\Model\Cart->save() called at [/httpdocs/app/code/TeoJasmin/Catalog/Plugin/Magento/Checkout/Controller/Cart/Add.php:151]

Then magento will call "sales_quote_item_qty_set_after" event and check for quantities in

  • Magento\CatalogInventory\Model\Quote\Item\QuantityValidator

So for example :
I add my product1 with quantity 6. (this product has a stock qty of 6)
In my quote, I can see the item1 with quantity 6.

Now when I a product2 with quantity whatever (eg: 1), if I do some logging in QuantityValidator::validate (around line 64) the first time the qty of item1 is 6, and after it will be 12...

I think Magento should not double check, and moreover should setQty instead of add qty to existing item qty.

Hope this will help to track down this bug...

@veloraven
@olysenko
@allMagentoStaff
just say that we have to fix your (billions) bugs by ourself!

Any feedback from the Magento team on this one yet?

I've found a configuration work-around for this bug.

In Stores > Configuration,
Catalog > Inventory

Product Stock Options: Backorder 'allow qty below 0'.

As long as you are still managing stock and hiding out of stock products, the user will still be able to add products with 1+ stock to basket and the promo code issue wont present itself.

Once the product reaches zero stock it will go to out of stock and not be available as usual.

Its a plaster though which has potential for a user to add a higher quantity than you have in stock, so we still need a core update from Mage.

@tomdollarmpd Sure we need that magento team fix it asap.
@olysenko Please reassign this issue to a magento staff user.

@LucScu, thank you for your report.
The issue is already fixed in 2.2.0

Was this page helpful?
0 / 5 - 0 ratings