Closed jzahedieh closed 6 years ago
@jzahedieh, thank you for your report. We've acknowledged the issue and added to our backlog.
@jzahedieh The issue is already fixed in 2.2. Closing ticket for now. Please reopen if you need any further assistance with this.
@magento-engcom-team What are the commits for this issue?
I am facing a similar issue in Magento Commerce Edition - v2.3.5-p1.
@magento-engcom-team What were the commits for this fix?
looks like issue is back on Magento 2.3.5-p2 or maybe never really fixed
Preconditions
Using https://github.com/mageinferno/magento2-docker-compose
Steps to reproduce
Precondition steps
These are for getting the data needed for the proper steps
Proper steps
{ "cartItem": { "sku": "WSH05", "qty": 95, "quote_id": "3", "product_option": { "extension_attributes": { "configurable_item_options": [ { "option_id": "93", "option_value": "50" }, { "option_id": "160", "option_value": "184" } ] } } } }
{ "cartItem": { "sku": "WSH05", "qty": 10, "quote_id": "3", "product_option": { "extension_attributes": { "configurable_item_options": [ { "option_id": "93", "option_value": "50" }, { "option_id": "160", "option_value": "184" } ] } } } }
Expected result
Actual result
{ "message": "We don't have as many \"Bess Yoga Short\" as you requested." }
Analysis
The main problem seems to be
Magento\Quote\Model\Quote\Item\Processor::prepare()
method calling the item classaddQty
method rather than thesetQty
method.addQty
adds the difference to the old value$this->setQty($this->getQty() + $qty);
, so from 95 to 10 it will do 95+10 which is over the available stock level thus the error being triggered.Workaround
It is possible to modify the qty of the item using a PUT request by omitting the product_option object in the payload:
{ "cartItem": { "sku": "WSH05", "qty": 10, "quote_id": "3", } }
The problem with this is that there isn't any error checking so the following will be a valid request:
{ "cartItem": { "sku": "WSH05", "qty": 101, "quote_id": "3" } }
Which causes the following errors to display on the basket/checkout: