1

I'm currently experiencing an issue on Magento 2.2.5. We have a number of simple products that have a minimum order qty set as 100.

If I view on of these simple products, we'll call this Product A. I can see the qty field defaults to 100 and when I add the item to the basket, it adds 100. This is working correctly.

The issue occurs when I have another product (Product B) and Product B has Product A set against it as a related item. If I tick the box to add Product A to the basket at the same time as Product B, it adds both products to the basket but there is an error message on the cart page as it has only added 1 Product A instead of 100.

Am I missing a simple setting or is it a bug in Magento?

Thanks

  • That looks like a bug. The core function addProductsByIds in model Magento\Checkout\Model\Cart doesn't check for minimumQty – subroutines Dec 5 '18 at 5:33
0

This is Magento default bug. I just checked and solved the bug and create a pull request in Git.

Please check commit: 28b8863

Override vendor/magento/module-checkout/Model/Cart.php

Pass request qty to the addProduct() in addProductsByIds() function

$request = null;
$stockItem = $this->stockRegistry->getStockItem($productId, $product->getStore()->getWebsiteId());
$minimumQty = $stockItem->getMinSaleQty();
if ($minimumQty && $minimumQty > 0) {
    $request = $minimumQty;
}
try {
    $this->getQuote()->addProduct($product, $request);
} catch (\Exception $e) {
    $allAdded = false;
}

Final addProductsByIds() function look like:

public function addProductsByIds($productIds)
{
    $allAvailable = true;
    $allAdded = true;

    if (!empty($productIds)) {
        foreach ($productIds as $productId) {
            $productId = (int)$productId;
            if (!$productId) {
                continue;
            }
            $product = $this->_getProduct($productId);
            if ($product->getId() && $product->isVisibleInCatalog()) {
                $request = null;
                $stockItem = $this->stockRegistry->getStockItem($productId, $product->getStore()->getWebsiteId());
                $minimumQty = $stockItem->getMinSaleQty();
                if ($minimumQty && $minimumQty > 0) {
                    $request = $minimumQty;
                }
                try {
                    $this->getQuote()->addProduct($product, $request);
                } catch (\Exception $e) {
                    $allAdded = false;
                }
            } else {
                $allAvailable = false;
            }
        }

        if (!$allAvailable) {
            $this->messageManager->addError(__("We don't have some of the products you want."));
        }
        if (!$allAdded) {
            $this->messageManager->addError(__("We don't have as many of some products as you want."));
        }
    }
    return $this;
}

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.