1

I have Magento 2.3.5 installed. Let's say we have 3 of Product A in stock and I add 5 of them to cart. It shows a notification at the cart saying: The requested qty is not available. That is fine and correct.

Then I try to decrease the qty at the cart by setting the qty to 3 and press update button. The update does not work and it throws this dialog: Attention The requested qty is not available. So it seems impossible to change the qty smaller in cart.

Currently only solution is to remove product from cart and re-add it with qty 3 to cart at the product page.

Is there way to fix this so that it is possible to update cart with smaller qty?

2

naviagte to vendor\magento\module-catalog-inventory\Model\Quote\Item\QuantityValidator inside this directory you will see a file with the name QuoteItemQtyList.php

Open it and replace this file with the below code:-

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\CatalogInventory\Model\Quote\Item\QuantityValidator;

class QuoteItemQtyList
{
    /**
     * Product qty's checked
     * data is valid if you check quote item qty and use singleton instance
     *
     * @var array
     */
    protected $_checkedQuoteItems = [];

    /**
     * Get product qty includes information from all quote items
     * Need be used only in singleton mode
     *
     * @param int   $productId
     * @param int   $quoteItemId
     * @param int   $quoteId
     * @param float $itemQty
     *
     * @return int
     */
    public function getQty($productId, $quoteItemId, $quoteId, $itemQty)
    {
        $qty = $itemQty;
        if (isset(
            $this->_checkedQuoteItems[$quoteId][$productId]['qty']
        ) && !in_array(
            $quoteItemId,
            $this->_checkedQuoteItems[$quoteId][$productId]['items']
        )
        ) {
            $qty += $this->_checkedQuoteItems[$quoteId][$productId]['qty'];
        }

        $this->_checkedQuoteItems[$quoteId][$productId]['qty'] = $qty;
        $this->_checkedQuoteItems[$quoteId][$productId]['items'][] = $quoteItemId;

        return $qty;
    }
}

this will do the trick for you let me know if you need any more help

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.