diff --git a/app/code/Magento/Wishlist/Model/Wishlist.php b/app/code/Magento/Wishlist/Model/Wishlist.php index 72f97fd4b4937..b75ba08476521 100644 --- a/app/code/Magento/Wishlist/Model/Wishlist.php +++ b/app/code/Magento/Wishlist/Model/Wishlist.php @@ -149,6 +149,11 @@ class Wishlist extends AbstractModel implements IdentityInterface */ private $stockConfiguration; + /** + * @var StockRegistryInterface|null + */ + private $stockRegistry; + /** * Constructor * @@ -212,6 +217,7 @@ public function __construct( $this->productRepository = $productRepository; $this->stockConfiguration = $stockConfiguration ?: ObjectManager::getInstance()->get(StockConfigurationInterface::class); + $this->stockRegistry = $stockRegistry ?: ObjectManager::getInstance()->get(StockRegistryInterface::class); } /** @@ -517,7 +523,7 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false } $candidate->setWishlistStoreId($storeId); - $qty = $candidate->getQty() ? $candidate->getQty() : 1; + $qty = $candidate->getQty() ?: $this->getMinSaleQty($candidate); // No null values as qty. Convert zero to 1. $item = $this->_addCatalogProduct($candidate, $qty, $forciblySetQty); $items[] = $item; @@ -782,4 +788,21 @@ public function getIdentities() } return $identities; } + + /** + * Returns min sale qty for product + * + * @param Product $product + * + * @return float + */ + private function getMinSaleQty(Product $product): float + { + $stockItem = $this->stockRegistry->getStockItem( + $product->getId(), + $product->getStore()->getWebsiteId() + ); + + return $stockItem && $stockItem->getMinSaleQty() ? $stockItem->getMinSaleQty() : 1; + } } diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/WishlistTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/WishlistTest.php index 73d0cf4766408..8dcf423bf0467 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Model/WishlistTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Model/WishlistTest.php @@ -262,7 +262,7 @@ public function testUpdateItem($itemId, $buyRequest, $param): void { $storeId = 1; $productId = 1; - $stores = [(new DataObject())->setId($storeId)]; + $stores = [(new DataObject())->setId($storeId)->setWebsiteId(1)]; $newItem = $this->prepareWishlistItem(); @@ -290,13 +290,13 @@ public function testUpdateItem($itemId, $buyRequest, $param): void $instanceType = $this->getMockBuilder(AbstractType::class) ->disableOriginalConstructor() ->getMock(); + $cartCandidate = $this->getMockBuilder(Product::class) + ->disableOriginalConstructor() + ->getMock(); + $cartCandidate->expects($this->any())->method('getStore')->willReturn($stores[0]); $instanceType->expects($this->once()) ->method('processConfiguration') - ->willReturn( - $this->getMockBuilder(Product::class) - ->disableOriginalConstructor() - ->getMock() - ); + ->willReturn($cartCandidate); $newProduct = $this->getMockBuilder( Product::class