Skip to content

Commit a71acec

Browse files
committed
Fixed minimum qty allowed in wishlist
1 parent 302f6c5 commit a71acec

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

app/code/Magento/Wishlist/Model/Wishlist.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ class Wishlist extends AbstractModel implements IdentityInterface
149149
*/
150150
private $stockConfiguration;
151151

152+
/**
153+
* @var StockRegistryInterface|null
154+
*/
155+
private $stockRegistry;
156+
152157
/**
153158
* Constructor
154159
*
@@ -212,6 +217,7 @@ public function __construct(
212217
$this->productRepository = $productRepository;
213218
$this->stockConfiguration = $stockConfiguration
214219
?: ObjectManager::getInstance()->get(StockConfigurationInterface::class);
220+
$this->stockRegistry = $stockRegistry ?: ObjectManager::getInstance()->get(StockRegistryInterface::class);
215221
}
216222

217223
/**
@@ -517,7 +523,7 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false
517523
}
518524
$candidate->setWishlistStoreId($storeId);
519525

520-
$qty = $candidate->getQty() ? $candidate->getQty() : 1;
526+
$qty = $candidate->getQty() ?: $this->getMinSaleQty($candidate);
521527
// No null values as qty. Convert zero to 1.
522528
$item = $this->_addCatalogProduct($candidate, $qty, $forciblySetQty);
523529
$items[] = $item;
@@ -782,4 +788,21 @@ public function getIdentities()
782788
}
783789
return $identities;
784790
}
791+
792+
/**
793+
* Returns min sale qty for product
794+
*
795+
* @param Product $product
796+
*
797+
* @return float
798+
*/
799+
private function getMinSaleQty(Product $product): float
800+
{
801+
$stockItem = $this->stockRegistry->getStockItem(
802+
$product->getId(),
803+
$product->getStore()->getWebsiteId()
804+
);
805+
806+
return $stockItem && $stockItem->getMinSaleQty() ? $stockItem->getMinSaleQty() : 1;
807+
}
785808
}

app/code/Magento/Wishlist/Test/Unit/Model/WishlistTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function testUpdateItem($itemId, $buyRequest, $param): void
262262
{
263263
$storeId = 1;
264264
$productId = 1;
265-
$stores = [(new DataObject())->setId($storeId)];
265+
$stores = [(new DataObject())->setId($storeId)->setWebsiteId(1)];
266266

267267
$newItem = $this->prepareWishlistItem();
268268

@@ -290,13 +290,13 @@ public function testUpdateItem($itemId, $buyRequest, $param): void
290290
$instanceType = $this->getMockBuilder(AbstractType::class)
291291
->disableOriginalConstructor()
292292
->getMock();
293+
$cartCandidate = $this->getMockBuilder(Product::class)
294+
->disableOriginalConstructor()
295+
->getMock();
296+
$cartCandidate->expects($this->any())->method('getStore')->willReturn($stores[0]);
293297
$instanceType->expects($this->once())
294298
->method('processConfiguration')
295-
->willReturn(
296-
$this->getMockBuilder(Product::class)
297-
->disableOriginalConstructor()
298-
->getMock()
299-
);
299+
->willReturn($cartCandidate);
300300

301301
$newProduct = $this->getMockBuilder(
302302
Product::class

0 commit comments

Comments
 (0)