|
16 | 16 | * Shopping cart model
|
17 | 17 | *
|
18 | 18 | * @api
|
| 19 | + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) |
19 | 20 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
20 | 21 | * @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead
|
21 | 22 | * @see \Magento\Quote\Api\Data\CartInterface
|
@@ -365,20 +366,10 @@ protected function _getProductRequest($requestInfo)
|
365 | 366 | public function addProduct($productInfo, $requestInfo = null)
|
366 | 367 | {
|
367 | 368 | $product = $this->_getProduct($productInfo);
|
368 |
| - $request = $this->_getProductRequest($requestInfo); |
369 | 369 | $productId = $product->getId();
|
370 | 370 |
|
371 | 371 | if ($productId) {
|
372 |
| - $stockItem = $this->stockRegistry->getStockItem($productId, $product->getStore()->getWebsiteId()); |
373 |
| - $minimumQty = $stockItem->getMinSaleQty(); |
374 |
| - //If product quantity is not specified in request and there is set minimal qty for it |
375 |
| - if ($minimumQty |
376 |
| - && $minimumQty > 0 |
377 |
| - && !$request->getQty() |
378 |
| - ) { |
379 |
| - $request->setQty($minimumQty); |
380 |
| - } |
381 |
| - |
| 372 | + $request = $this->getQtyRequest($product, $requestInfo); |
382 | 373 | try {
|
383 | 374 | $this->_eventManager->dispatch(
|
384 | 375 | 'checkout_cart_product_add_before',
|
@@ -438,8 +429,9 @@ public function addProductsByIds($productIds)
|
438 | 429 | }
|
439 | 430 | $product = $this->_getProduct($productId);
|
440 | 431 | if ($product->getId() && $product->isVisibleInCatalog()) {
|
| 432 | + $request = $this->getQtyRequest($product); |
441 | 433 | try {
|
442 |
| - $this->getQuote()->addProduct($product); |
| 434 | + $this->getQuote()->addProduct($product, $request); |
443 | 435 | } catch (\Exception $e) {
|
444 | 436 | $allAdded = false;
|
445 | 437 | }
|
@@ -762,4 +754,27 @@ private function getRequestInfoFilter()
|
762 | 754 | }
|
763 | 755 | return $this->requestInfoFilter;
|
764 | 756 | }
|
| 757 | + |
| 758 | + /** |
| 759 | + * Get request quantity |
| 760 | + * |
| 761 | + * @param Product $product |
| 762 | + * @param \Magento\Framework\DataObject|int|array $request |
| 763 | + * @return int|DataObject |
| 764 | + */ |
| 765 | + private function getQtyRequest($product, $request = 0) |
| 766 | + { |
| 767 | + $request = $this->_getProductRequest($request); |
| 768 | + $stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId()); |
| 769 | + $minimumQty = $stockItem->getMinSaleQty(); |
| 770 | + //If product quantity is not specified in request and there is set minimal qty for it |
| 771 | + if ($minimumQty |
| 772 | + && $minimumQty > 0 |
| 773 | + && !$request->getQty() |
| 774 | + ) { |
| 775 | + $request->setQty($minimumQty); |
| 776 | + } |
| 777 | + |
| 778 | + return $request; |
| 779 | + } |
765 | 780 | }
|
0 commit comments