6 declare(strict_types=1);
27 use Magento\Quote\Api\Data\CartItemInterfaceFactory;
34 use PHPUnit\Framework\TestCase;
45 private $isProductSalableForRequestedQty;
50 private $getProductSalableQty;
55 private $getStockItemConfiguration;
60 private $saveStockItemConfiguration;
65 private $searchCriteriaBuilder;
70 private $cartRepository;
75 private $cleanupReservations;
80 private $productRepository;
85 private $cartManagement;
90 private $cartItemFactory;
95 private $stockRepository;
100 private $storeRepository;
105 private $orderRepository;
115 private $orderManagement;
120 private $storeManager;
129 IsProductSalableForRequestedQtyInterface::class
133 GetStockItemConfigurationInterface::class
136 SaveStockItemConfigurationInterface::class
140 SearchCriteriaBuilder::class
180 $this->assertEquals(8.5, $this->getProductSalableQty->execute($sku, $stockId));
181 $this->assertFalse($this->isProductSalableForRequestedQty->execute($sku, $stockId, 13)->isSalable());
183 $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
184 $stockItemConfiguration->setUseConfigMinQty(
false);
185 $stockItemConfiguration->setMinQty(-4.5);
186 $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
189 $this->assertEquals(8.5, $this->getProductSalableQty->execute($sku, $stockId));
190 $this->assertFalse($this->isProductSalableForRequestedQty->execute($sku, $stockId, 13)->isSalable());
192 $stockItemConfiguration->setUseConfigBackorders(
false);
194 $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
197 $this->assertEquals(13, $this->getProductSalableQty->execute($sku, $stockId));
199 $this->assertTrue($this->isProductSalableForRequestedQty->execute($sku, $stockId, 13)->isSalable());
200 $this->assertFalse($this->isProductSalableForRequestedQty->execute($sku, $stockId, 14)->isSalable());
202 $cart = $this->getCartByStockId($stockId);
203 $product = $this->productRepository->get($sku);
206 $this->cartRepository->save(
$cart);
208 $orderId = $this->cartManagement->placeOrder(
$cart->getId());
209 $this->assertFalse($this->isProductSalableForRequestedQty->execute($sku, $stockId, 1)->isSalable());
210 $this->deleteOrderById((
int)$orderId);
213 $stockItemConfiguration->setMinQty(0);
214 $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
215 $this->assertTrue($this->isProductSalableForRequestedQty->execute($sku, $stockId, 1)->isSalable());
218 $stockItemConfiguration->setMinQty(10);
219 $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
220 $this->assertTrue($this->isProductSalableForRequestedQty->execute($sku, $stockId, 100)->isSalable());
227 private function getCartByStockId(
int $stockId):
CartInterface 230 ->addFilter(
'reserved_order_id',
'test_order_1')
235 $stock = $this->stockRepository->get($stockId);
247 $this->storeManager->setCurrentStore(
$storeCode);
256 private function deleteOrderById(
int $orderId)
258 $this->registry->unregister(
'isSecureArea');
259 $this->registry->register(
'isSecureArea',
true);
260 $this->orderManagement->cancel($orderId);
261 $this->orderRepository->delete($this->orderRepository->get($orderId));
262 $this->registry->unregister(
'isSecureArea');
263 $this->registry->register(
'isSecureArea',
false);
272 private function getCartItem(ProductInterface
$product,
float $quoteItemQty,
int $cartId): CartItemInterface
276 $this->cartItemFactory->create(
292 $this->cleanupReservations->execute();
const BACKORDERS_YES_NONOTIFY
testIsProductOutOfStockAfterPlacingAnOrder()
static getObjectManager()