|
15 | 15 | * Shopping cart model
|
16 | 16 | *
|
17 | 17 | * @api
|
| 18 | + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) |
18 | 19 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
19 | 20 | * @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead
|
20 | 21 | */
|
@@ -354,22 +355,10 @@ protected function _getProductRequest($requestInfo)
|
354 | 355 | public function addProduct($productInfo, $requestInfo = null)
|
355 | 356 | {
|
356 | 357 | $product = $this->_getProduct($productInfo);
|
357 |
| - $request = $this->_getProductRequest($requestInfo); |
358 | 358 | $productId = $product->getId();
|
359 | 359 |
|
360 | 360 | 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); |
373 | 362 | try {
|
374 | 363 | $result = $this->getQuote()->addProduct($product, $request);
|
375 | 364 | } catch (\Magento\Framework\Exception\LocalizedException $e) {
|
@@ -425,8 +414,9 @@ public function addProductsByIds($productIds)
|
425 | 414 | }
|
426 | 415 | $product = $this->_getProduct($productId);
|
427 | 416 | if ($product->getId() && $product->isVisibleInCatalog()) {
|
| 417 | + $request = $this->getQtyRequest($product); |
428 | 418 | try {
|
429 |
| - $this->getQuote()->addProduct($product); |
| 419 | + $this->getQuote()->addProduct($product, $request); |
430 | 420 | } catch (\Exception $e) {
|
431 | 421 | $allAdded = false;
|
432 | 422 | }
|
@@ -747,4 +737,26 @@ private function getRequestInfoFilter()
|
747 | 737 | }
|
748 | 738 | return $this->requestInfoFilter;
|
749 | 739 | }
|
| 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 | + } |
750 | 762 | }
|
0 commit comments