Skip to content

Commit 5dc2a5a

Browse files
committed
MCP-584: Disable Inventory check on Quote Load
- [MCP-614] Fix new Integration test for disabled Inventory check
1 parent 7846a3c commit 5dc2a5a

File tree

2 files changed

+110
-227
lines changed

2 files changed

+110
-227
lines changed

dev/tests/integration/testsuite/Magento/CatalogInventory/Api/OutOfStockItemSaveTest.php

Lines changed: 0 additions & 227 deletions
This file was deleted.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Model;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\Quote\Api\CartManagementInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
18+
use PHPUnit\Framework\TestCase;
19+
20+
class QuoteManagementWithInventoryCheckDisabledTest extends TestCase
21+
{
22+
/**
23+
* @var ObjectManagerInterface
24+
*/
25+
private $objectManager;
26+
27+
/** @var ProductRepositoryInterface $productRepository */
28+
private $productRepository;
29+
30+
/**
31+
* @var GetQuoteByReservedOrderId
32+
*/
33+
private $getQuoteByReservedOrderId;
34+
35+
/**
36+
* @var CartManagementInterface
37+
*/
38+
private $cartManagement;
39+
40+
protected function setUp(): void
41+
{
42+
$this->objectManager = Bootstrap::getObjectManager();
43+
$this->cartManagement = $this->objectManager->get(CartManagementInterface::class);
44+
$this->getQuoteByReservedOrderId = $this->objectManager->get(GetQuoteByReservedOrderId::class);
45+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
46+
}
47+
48+
/**
49+
* @magentoDataFixture Magento/Sales/_files/quote_with_purchase_order.php
50+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
51+
* @return void
52+
*/
53+
public function testSaveWithZeroQuantityAndInventoryCheckDisabled()
54+
{
55+
$poNumber = '12345678';
56+
$quote = $this->getQuoteByReservedOrderId->execute('test_order_1');
57+
$quote->getPayment()->setPoNumber($poNumber);
58+
$quote->collectTotals()->save();
59+
60+
/** @var ProductInterface $product */
61+
$product = $this->productRepository->get($quote->getItems()[0]->getSku(), false, null, true);
62+
63+
$this->productRepository->save($product);
64+
65+
$stockItem = $product->getExtensionAttributes()->getStockItem();
66+
$stockItem->setQty(0);
67+
$stockItem->setIsInStock(0);
68+
69+
/** @var StockItemRepositoryInterface $stockItemRepository */
70+
$stockItemRepository = $this->objectManager->get(StockItemRepositoryInterface::class);
71+
$stockItemRepository->save($stockItem);
72+
73+
$this->expectExceptionObject(
74+
new LocalizedException(__('Some of the products are out of stock.'))
75+
);
76+
$this->cartManagement->placeOrder($quote->getId());
77+
}
78+
79+
80+
/**
81+
* @magentoDataFixture Magento/Sales/_files/quote_with_purchase_order.php
82+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
83+
* @return void
84+
*/
85+
public function testSaveWithPositiveQuantityAndInventoryCheckDisabled()
86+
{
87+
$poNumber = '12345678';
88+
$quote = $this->getQuoteByReservedOrderId->execute('test_order_1');
89+
$quote->getPayment()->setPoNumber($poNumber);
90+
$quote->collectTotals()->save();
91+
92+
/** @var ProductInterface $product */
93+
$product = $this->productRepository->get($quote->getItems()[0]->getSku(), false, null, true);
94+
95+
$this->productRepository->save($product);
96+
97+
$stockItem = $product->getExtensionAttributes()->getStockItem();
98+
$stockItem->setQty(100);
99+
$stockItem->setIsInStock(0);
100+
101+
/** @var StockItemRepositoryInterface $stockItemRepository */
102+
$stockItemRepository = $this->objectManager->get(StockItemRepositoryInterface::class);
103+
$stockItemRepository->save($stockItem);
104+
105+
$this->expectExceptionObject(
106+
new LocalizedException(__('Some of the products are out of stock.'))
107+
);
108+
$this->cartManagement->placeOrder($quote->getId());
109+
}
110+
}

0 commit comments

Comments
 (0)