Skip to content

Commit b183cb6

Browse files
committed
[MCP-584] Disables Inventory check on Quote load
1 parent 70d1517 commit b183cb6

File tree

5 files changed

+133
-2
lines changed

5 files changed

+133
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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\Framework\App\Config\ScopeConfigInterface;
11+
12+
/**
13+
* Class Config
14+
* @package Magento\Quote\Model
15+
*/
16+
class Config
17+
{
18+
const XML_PATH_DISABLED = 'cataloginventory/item_options/disabled';
19+
20+
/** @var ScopeConfigInterface */
21+
private $config;
22+
23+
/**
24+
* Config constructor.
25+
* @param ScopeConfigInterface $config
26+
*/
27+
public function __construct(ScopeConfigInterface $config)
28+
{
29+
$this->config = $config;
30+
}
31+
32+
/**
33+
* Check if Inventory check is disabled
34+
* @return bool
35+
*/
36+
public function isDisabled(): bool
37+
{
38+
return (bool)$this->config->getValue(self::XML_PATH_DISABLED);
39+
}
40+
}

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro
6363
*/
6464
private $recollectQuote = false;
6565

66+
/**
67+
* @var \Magento\Quote\Model\Config
68+
*/
69+
private $config;
70+
6671
/**
6772
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
6873
* @param \Psr\Log\LoggerInterface $logger
@@ -75,6 +80,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\VersionContro
7580
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
7681
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
7782
* @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
83+
* @param \Magento\Quote\Model\Config|null $config
7884
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7985
*/
8086
public function __construct(
@@ -88,7 +94,8 @@ public function __construct(
8894
\Magento\Quote\Model\Quote\Config $quoteConfig,
8995
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
9096
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null,
91-
\Magento\Store\Model\StoreManagerInterface $storeManager = null
97+
\Magento\Store\Model\StoreManagerInterface $storeManager = null,
98+
\Magento\Quote\Model\Config $config = null
9299
) {
93100
parent::__construct(
94101
$entityFactory,
@@ -102,6 +109,8 @@ public function __construct(
102109
$this->_itemOptionCollectionFactory = $itemOptionCollectionFactory;
103110
$this->_productCollectionFactory = $productCollectionFactory;
104111
$this->_quoteConfig = $quoteConfig;
112+
$this->config = $config ?:
113+
\Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Quote\Model\Config::class);
105114

106115
// Backward compatibility constructor parameters
107116
$this->storeManager = $storeManager ?:
@@ -282,7 +291,9 @@ protected function _assignProducts(): self
282291
}
283292
if (!$item->isDeleted()) {
284293
$item->setQtyOptions($qtyOptions)->setProduct($product);
285-
$item->checkData();
294+
if (!$this->config->isDisabled()) {
295+
$item->checkData();
296+
}
286297
}
287298
}
288299
if ($this->recollectQuote && $this->_quote) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\Test\Unit\Model\ResourceModel\Quote\Item;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Quote\Model\Config;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class ConfigTest extends TestCase
15+
{
16+
/**
17+
* @var Config
18+
*/
19+
private $config;
20+
21+
/**
22+
* @var \PHPUnit\Framework\MockObject\MockObject
23+
*/
24+
private $configMock;
25+
26+
/**
27+
* @inheritDoc
28+
*/
29+
protected function setUp(): void
30+
{
31+
$this->configMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
32+
$this->configMock->method('getValue')->willReturn('1');
33+
$this->config = new Config($this->configMock);
34+
}
35+
36+
/**
37+
* @return void
38+
*/
39+
public function testIsDisabled()
40+
{
41+
$this->configMock->expects($this->once())->method('getValue');
42+
$this->config->isDisabled();
43+
}
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
9+
<system>
10+
<section id="cataloginventory">
11+
<tab>catalog</tab>
12+
<group id="item_options" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
13+
<field id="disabled" translate="label" type="select" sortOrder="15" showInDefault="1" canRestore="1">
14+
<label>Inventory check is Disabled</label>
15+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
16+
</field>
17+
</group>
18+
</section>
19+
</system>
20+
</config>

app/code/Magento/Quote/etc/config.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
9+
<default>
10+
<cataloginventory>
11+
<item_options>
12+
<disabled>0</disabled>
13+
</item_options>
14+
</cataloginventory>
15+
</default>
16+
</config>

0 commit comments

Comments
 (0)