Magento2: Unable to update simple product custom option in cart when quantity is 1

Created on 25 Oct 2018  路  36Comments  路  Source: magento/magento2

Preconditions (*)

  1. Magento CE 2.2.5, Updated(9/19/2019) can be reproduced on 2.3
  2. Although reproduced in 2.2.2-2.2.4
  3. Backorders disabled, minimum order qty is 1.
  4. A simple product with at least one custom option, e.g. size - 1,2,3; price type fixed.

Steps to reproduce (*)

  1. Go to product page and select options and click add to cart. || _Update 9/19/2019_: _The quantity of the product added must be more than a half of its Stock quantity!_ ||
  2. Go to cart and select "Edit/Update Item"
  3. Select different option from original and click update.

Expected result (*)

  1. Redirected back to cart
  2. Product custom option updated.

Actual result (*)

  1. Error message on product page.
    image
    || _Update 9/19/2019_: _(Those messages haven't been observed at now. Only the one below still appears)_ ||
    The requested qty is not available

Notes

It manifests as well if you have configurable product, where associated product has 1 stock, and configurable has custom option. Once selected and added to cart. If you try to update only custom option, the result is the same.

It appears that the code in Magento/Quote/Model/Quote.php#updateItem updates product item or adds new one if product item with matching custom/configurable options does not exist and later removes old item.
Problem is inside updateItem(), call to to addProduct() throws, because actual product qty is 1.

Quote imagine2019 mleu2019 Confirmed P2 ready for dev Reproduced on 2.2.x Reproduced on 2.3.x S2

Most helpful comment

This is still an issue in 2.3.4

All 36 comments

Hi @ikrestov. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [x] Summary of the issue
  • [x] Information on your environment
  • [x] Steps to reproduce
  • [x] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@ikrestov do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [x] yes
  • [ ] no

@magento-engcom-team give me 2.2.5 instance

Hi @ikrestov. Thank you for your request. I'm working on Magento 2.2.5 instance for you

Hi @ikrestov, here is your Magento instance.
Admin access: http://ec2-34-228-235-121.compute-1.amazonaws.com/i-18812-2-2-5//admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@magento-engcom-team
Reproduced.

image
image
image

@magento-engcom-team give me 2.2.5 instance

Hi @ayazwebkul. Thank you for your request. I'm working on Magento 2.2.5 instance for you

Hi @ayazwebkul, here is your Magento instance.
Admin access: http://ec2-34-228-235-121.compute-1.amazonaws.com/i-18812-2-2-5//admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@magento-engcom-team give me 2.2.6 instance

Hi @ayazwebkul. Thank you for your request. I'm working on Magento 2.2.6 instance for you

Hi @ayazwebkul, here is your Magento instance.
Admin access: http://ec2-34-228-235-121.compute-1.amazonaws.com/i-18812-2-2-6//admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

Adding more to the issue reproduction:
The issue can be generated if the product stock quantity is equal to the quantity in cart and then we try to update the cart options, we are getting the error message as We don't have as many "test product" as you requested.
Also, this is not related to qty 1 in stock, it can be reproduced with 50 qty in stock and then adding 50 qty in cart and then editing custom options.
It gives error until the qty is equal to at least double the qty in cart.

@ayazwebkul Thank you for verifying the issue.

Unfortunately, not enough information was provided to created internal ticket. Please consider adding the following:

  • [x] Add "Component: " label(s) to this ticket based on verification result. If uncertain, you may follow the best guess
  • [x] Add "Reproduced on " label(s) to this ticket based on verification result

Once all required information is added, please add label "Issue: Confirmed" again.
Thanks!

@ayazwebkul Thank you for verifying the issue.

Unfortunately, not enough information was provided to created internal ticket. Please consider adding the following:

  • [x] Add "Component: " label(s) to this ticket based on verification result. If uncertain, you may follow the best guess

Once all required information is added, please add label "Issue: Confirmed" again.
Thanks!

@ayazwebkul Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-95948 were created

Hi @ketan-krish. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

Hi @engcom-backlog-andrii. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@magento-engcom-team give me 2.3.0 instance

Hi @engcom-backlog-andrii. Thank you for your request. I'm working on Magento 2.3.0 instance for you

Hi @engcom-backlog-andrii, here is your Magento instance.
Admin access: https://i-18812-2-3-0.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

Refresh

Hi @shikhamis11. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.


imagine2019

Hi @engcom-Bravo. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


mleu2019

@magento I am working on this issue

Hi @shikhamis11. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


is this issue resolved #18812 ? Please let me know the commit or code

Hello,
Did anybody found a solution for this problem ? Thanks

I have updated the magento version to 2.2.9 and it's working fine, maybe you need to update your magento version

@ankursharma1930 thanks for your answer!
In fact I'm already on 2.3.0 and I was forced to migrate from 2.2.5 because of an other feature which was broken and the fix never came out.
That's why I'm looking for a real fix to apply, I don't want to make an other migration as I'm not sure if it's fixed on more recent releases...
I think I'll have to take a look to the differences between 2.2.9 and 2.3.0 and see if I find something....

This is still an issue in 2.3.4

This is still an issue in 2.3.4

yes me also facing

mine :

configure product update also issue ...

i fixed with those plugins

Magento 2.3.4 (tested)

i knew this is not right way but for now it will work (We will check when new version released)

your custom module

Custom/Module/etc/frontend/di.xml

```



<!-- this plugin fix_if_stock_is_one_error_qty_is_not_available -->
<type name="Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList">
    <plugin name="fix_if_stock_is_one_error_qty_is_not_available_quote_item" type="Custom\Module\Plugin\Quote\Item\QuantityValidator\QuoteItemQtyList" disabled="false" sortOrder="10"/>
</type>
Custom\Module\Plugin\Quote\ExtendedItem.php

namespace CustomModulePluginQuote;

use MagentoQuoteModelQuoteItem;

class ExtendedItem
{

/**
 * @param Item $subject
 * @param  $result
 * @param $qty
 * @return mixed
 */
public function afterAddQty(Item $subject,$result,$qty){

    if($subject->getQty()!=$qty)
    {
      $result->setQty($qty);
    }
    return $result;
}

}

Custom\Module\Plugin\Quote\Item\QuantityValidator\QuoteItemQtyList.php

namespace CustomModulePluginQuoteItemQuantityValidator;

use MagentoCatalogInventoryModelQuoteItemQuantityValidatorQuoteItemQtyList as CoreQuoteItemQtyList;

class QuoteItemQtyList
{

/**
 * @param CoreQuoteItemQtyList $subject
 * @param $productId
 * @param $quoteItemId
 * @param $quoteId
 * @param $itemQty
 * @return array
 */
public function beforeGetQty(CoreQuoteItemQtyList $subject,$productId, $quoteItemId, $quoteId, $itemQty)
{

    /**  we are using 0 because original qty was processed */
    if($itemQty!=0){
        $itemQty=0;
    }

    return [$productId, $quoteItemId, $quoteId, $itemQty];
}

}
```

This issue still there in 2.3.5-p1.
Any patches or fixes for this?

i fixed with those plugins

Magento 2.3.4 (tested)

i knew this is not right way but for now it will work (We will check when new version released)

your custom module

Custom/Module/etc/frontend/di.xml

<!-- this plugin fix_if_stock_is_one_error_qty_is_not_available custom options -->
   <type name="Magento\Quote\Model\Quote\Item">
       <plugin name="fix_if_stock_is_one_error_qty_is_not_available" type="Custom\Module\Plugin\Quote\ExtendedItem" disabled="false" sortOrder="10"/>
   </type>


   <!-- this plugin fix_if_stock_is_one_error_qty_is_not_available -->
   <type name="Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList">
       <plugin name="fix_if_stock_is_one_error_qty_is_not_available_quote_item" type="Custom\Module\Plugin\Quote\Item\QuantityValidator\QuoteItemQtyList" disabled="false" sortOrder="10"/>
   </type>

CustomModulePluginQuoteExtendedItem.php

<?php

namespace Custom\Module\Plugin\Quote;

use Magento\Quote\Model\Quote\Item;

class ExtendedItem
{


    /**
     * @param Item $subject
     * @param  $result
     * @param $qty
     * @return mixed
     */
    public function afterAddQty(Item $subject,$result,$qty){

        if($subject->getQty()!=$qty)
        {
          $result->setQty($qty);
        }
        return $result;
    }
}

CustomModulePluginQuoteItemQuantityValidatorQuoteItemQtyList.php

<?php


namespace Custom\Module\Plugin\Quote\Item\QuantityValidator;

use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList as CoreQuoteItemQtyList;

class QuoteItemQtyList
{


    /**
     * @param CoreQuoteItemQtyList $subject
     * @param $productId
     * @param $quoteItemId
     * @param $quoteId
     * @param $itemQty
     * @return array
     */
    public function beforeGetQty(CoreQuoteItemQtyList $subject,$productId, $quoteItemId, $quoteId, $itemQty)
    {

        /**  we are using 0 because original qty was processed */
        if($itemQty!=0){
            $itemQty=0;
        }

        return [$productId, $quoteItemId, $quoteId, $itemQty];
    }
}

This one worked in 2.3.5-p1. Thanks @prabhakaran777

Was this page helpful?
0 / 5 - 0 ratings