Skip to content

Commit abbfc7f

Browse files
committed
[MCP-584] Invert Config method, update Test and move Option field
1 parent a5e15e4 commit abbfc7f

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

app/code/Magento/Quote/Model/Config.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
/**
1313
* Class Config
14+
* Toggles Inventory check via Config option
1415
* @package Magento\Quote\Model
1516
*/
1617
class Config
1718
{
18-
const XML_PATH_DISABLED = 'cataloginventory/item_options/disabled';
19+
const XML_PATH_INVENTORY_CHECK_ENABLED = 'cataloginventory/options/enable_inventory_check';
1920

2021
/** @var ScopeConfigInterface */
2122
private $config;
@@ -33,8 +34,8 @@ public function __construct(ScopeConfigInterface $config)
3334
* Check if Inventory check is disabled
3435
* @return bool
3536
*/
36-
public function isDisabled(): bool
37+
public function isEnabled(): bool
3738
{
38-
return (bool)$this->config->getValue(self::XML_PATH_DISABLED);
39+
return (bool)$this->config->getValue(self::XML_PATH_INVENTORY_CHECK_ENABLED);
3940
}
4041
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ protected function _assignProducts(): self
291291
}
292292
if (!$item->isDeleted()) {
293293
$item->setQtyOptions($qtyOptions)->setProduct($product);
294-
if (!$this->config->isDisabled()) {
294+
if ($this->config->isEnabled()) {
295295
$item->checkData();
296296
}
297297
}

app/code/Magento/Quote/Test/Unit/Model/ResourceModel/Quote/Item/ConfigTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,30 @@ protected function setUp(): void
3333
$this->config = new Config($this->configMock);
3434
}
3535

36+
/**
37+
* @return void
38+
*/
39+
public function testIsEnabled()
40+
{
41+
$this->assertEquals(true, $this->config->isEnabled());
42+
}
43+
3644
/**
3745
* @return void
3846
*/
3947
public function testIsDisabled()
4048
{
41-
$this->configMock->expects($this->once())->method('getValue');
42-
$this->config->isDisabled();
49+
$this->setUpForDisabled();
50+
$this->assertEquals(false, $this->config->isEnabled());
51+
}
52+
53+
/**
54+
* @return void
55+
*/
56+
private function setUpForDisabled()
57+
{
58+
$this->configMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
59+
$this->configMock->method('getValue')->willReturn('0');
60+
$this->config = new Config($this->configMock);
4361
}
4462
}

app/code/Magento/Quote/etc/adminhtml/system.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<system>
1010
<section id="cataloginventory">
1111
<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>
12+
<group id="options">
13+
<field id="enable_inventory_check" translate="label" type="select" sortOrder="60" showInDefault="1" canRestore="1">
14+
<label> Enable Inventory Check On Cart Load</label>
1515
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1616
</field>
1717
</group>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
99
<default>
1010
<cataloginventory>
11-
<item_options>
12-
<disabled>0</disabled>
13-
</item_options>
11+
<options>
12+
<enable_inventory_check>0</enable_inventory_check>
13+
</options>
1414
</cataloginventory>
1515
</default>
1616
</config>

0 commit comments

Comments
 (0)