Skip to content

Commit 9dccad1

Browse files
committed
Minimum Qty Allowed in Shopping Cart not working on related product
1 parent 6d856c4 commit 9dccad1

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

app/code/Magento/Checkout/Model/Cart.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Shopping cart model
1616
*
1717
* @api
18+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1819
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1920
* @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead
2021
*/
@@ -354,22 +355,10 @@ protected function _getProductRequest($requestInfo)
354355
public function addProduct($productInfo, $requestInfo = null)
355356
{
356357
$product = $this->_getProduct($productInfo);
357-
$request = $this->_getProductRequest($requestInfo);
358358
$productId = $product->getId();
359359

360360
if ($productId) {
361-
$stockItem = $this->stockRegistry->getStockItem($productId, $product->getStore()->getWebsiteId());
362-
$minimumQty = $stockItem->getMinSaleQty();
363-
//If product quantity is not specified in request and there is set minimal qty for it
364-
if ($minimumQty
365-
&& $minimumQty > 0
366-
&& !$request->getQty()
367-
) {
368-
$request->setQty($minimumQty);
369-
}
370-
}
371-
372-
if ($productId) {
361+
$request = $this->getQtyRequest($product, $requestInfo);
373362
try {
374363
$result = $this->getQuote()->addProduct($product, $request);
375364
} catch (\Magento\Framework\Exception\LocalizedException $e) {
@@ -425,8 +414,9 @@ public function addProductsByIds($productIds)
425414
}
426415
$product = $this->_getProduct($productId);
427416
if ($product->getId() && $product->isVisibleInCatalog()) {
417+
$request = $this->getQtyRequest($product);
428418
try {
429-
$this->getQuote()->addProduct($product);
419+
$this->getQuote()->addProduct($product, $request);
430420
} catch (\Exception $e) {
431421
$allAdded = false;
432422
}
@@ -747,4 +737,26 @@ private function getRequestInfoFilter()
747737
}
748738
return $this->requestInfoFilter;
749739
}
740+
741+
/**
742+
* Get request quantity
743+
*
744+
* @param Product $product
745+
* @param \Magento\Framework\DataObject|int|array $request
746+
* @return int|DataObject
747+
*/
748+
private function getQtyRequest($product, $request = 0)
749+
{
750+
$request = $this->_getProductRequest($request);
751+
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
752+
$minimumQty = $stockItem->getMinSaleQty();
753+
//If product quantity is not specified in request and there is set minimal qty for it
754+
if ($minimumQty
755+
&& $minimumQty > 0
756+
&& !$request->getQty()
757+
) {
758+
$request->setQty($minimumQty);
759+
}
760+
return $request;
761+
}
750762
}

0 commit comments

Comments
 (0)