Skip to content

Commit ce7faf6

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'origin/2.3-develop' into batch-35-forwardport-2.3-develop
2 parents 1698afc + 83ada52 commit ce7faf6

File tree

8 files changed

+70
-30
lines changed

8 files changed

+70
-30
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@
425425
<label>Web</label>
426426
<tab>general</tab>
427427
<resource>Magento_Config::web</resource>
428-
<group id="url" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="0" showInStore="0">
428+
<group id="url" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
429429
<label>Url Options</label>
430430
<field id="use_store" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
431431
<label>Add Store Code to Urls</label>
@@ -435,7 +435,7 @@
435435
<![CDATA[<strong style="color:red">Warning!</strong> When using Store Code in URLs, in some cases system may not work properly if URLs without Store Codes are specified in the third party services (e.g. PayPal etc.).]]>
436436
</comment>
437437
</field>
438-
<field id="redirect_to_base" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
438+
<field id="redirect_to_base" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
439439
<label>Auto-redirect to Base URL</label>
440440
<source_model>Magento\Config\Model\Config\Source\Web\Redirect</source_model>
441441
<comment>I.e. redirect from http://example.com/store/ to http://www.example.com/store/</comment>

app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public function process(Select $select)
5656
['stock' => $stockStatusTable],
5757
sprintf('stock.product_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
5858
[]
59-
)->where('stock.stock_status = ?', Stock::STOCK_IN_STOCK);
59+
)
60+
->where('stock.stock_status = ?', Stock::STOCK_IN_STOCK)
61+
->where('stock.website_id = ?', 0);
6062
}
6163

6264
return $select;

app/code/Magento/CatalogInventory/Observer/ProcessInventoryDataObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function prepareQuantityAndStockStatus(StockItemInterface $stockItem, ar
9797
) {
9898
unset($quantityAndStockStatus['is_in_stock']);
9999
}
100-
if (isset($quantityAndStockStatus['qty'])
100+
if (array_key_exists('qty', $quantityAndStockStatus)
101101
&& $stockItem->getQty() == $quantityAndStockStatus['qty']
102102
) {
103103
unset($quantityAndStockStatus['qty']);

app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Product/StockStatusBaseSelectProcessorTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ public function testProcess()
5656
[]
5757
)
5858
->willReturnSelf();
59-
$this->select->expects($this->once())
59+
60+
$this->select->expects($this->exactly(2))
6061
->method('where')
61-
->with('stock.stock_status = ?', Stock::STOCK_IN_STOCK)
62+
->withConsecutive(
63+
['stock.stock_status = ?', Stock::STOCK_IN_STOCK, null],
64+
['stock.website_id = ?', 0, null]
65+
)
6266
->willReturnSelf();
6367

6468
$this->stockStatusBaseSelectProcessor->process($this->select);

app/code/Magento/SampleData/Model/Dependency.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\Config\Composer\Package;
1313
use Magento\Framework\Config\Composer\PackageFactory;
1414
use Magento\Framework\Filesystem;
15-
use Magento\Framework\Filesystem\Directory\ReadInterfaceFactory;
15+
use Magento\Framework\Filesystem\Directory\ReadFactory;
1616

1717
/**
1818
* Sample Data dependency
@@ -40,7 +40,7 @@ class Dependency
4040
private $componentRegistrar;
4141

4242
/**
43-
* @var ReadInterfaceFactory
43+
* @var ReadFactory
4444
*/
4545
private $directoryReadFactory;
4646

@@ -51,21 +51,21 @@ class Dependency
5151
* @param Filesystem $filesystem @deprecated 2.3.0 $directoryReadFactory is used instead
5252
* @param PackageFactory $packageFactory
5353
* @param ComponentRegistrarInterface $componentRegistrar
54-
* @param Filesystem\Directory\ReadInterfaceFactory|null $directoryReadFactory
54+
* @param Filesystem\Directory\ReadFactory|null $directoryReadFactory
5555
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5656
*/
5757
public function __construct(
5858
ComposerInformation $composerInformation,
5959
Filesystem $filesystem,
6060
PackageFactory $packageFactory,
6161
ComponentRegistrarInterface $componentRegistrar,
62-
\Magento\Framework\Filesystem\Directory\ReadInterfaceFactory $directoryReadFactory = null
62+
\Magento\Framework\Filesystem\Directory\ReadFactory $directoryReadFactory = null
6363
) {
6464
$this->composerInformation = $composerInformation;
6565
$this->packageFactory = $packageFactory;
6666
$this->componentRegistrar = $componentRegistrar;
6767
$this->directoryReadFactory = $directoryReadFactory ?:
68-
ObjectManager::getInstance()->get(ReadInterfaceFactory::class);
68+
ObjectManager::getInstance()->get(ReadFactory::class);
6969
}
7070

7171
/**
@@ -123,7 +123,7 @@ private function getModuleComposerPackage($moduleDir)
123123
*/
124124
foreach ([$moduleDir, $moduleDir . DIRECTORY_SEPARATOR . '..'] as $dir) {
125125
/** @var Filesystem\Directory\ReadInterface $directory */
126-
$directory = $this->directoryReadFactory->create(['path' => $dir]);
126+
$directory = $this->directoryReadFactory->create($dir);
127127
if ($directory->isExist('composer.json') && $directory->isReadable('composer.json')) {
128128
/** @var Package $package */
129129
return $this->packageFactory->create(['json' => json_decode($directory->readFile('composer.json'))]);

app/code/Magento/SampleData/Test/Unit/Model/DependencyTest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Filesystem;
1515
use Magento\Framework\Phrase;
1616
use Magento\SampleData\Model\Dependency;
17+
use Magento\Framework\Filesystem\DriverPool;
1718

1819
class DependencyTest extends \PHPUnit\Framework\TestCase
1920
{
@@ -59,7 +60,7 @@ public function testPackagesFromComposerSuggest(
5960
$moduleDirectories
6061
);
6162

62-
$directoryReadFactory = $this->getMockBuilder(Filesystem\Directory\ReadInterfaceFactory::class)
63+
$directoryReadFactory = $this->getMockBuilder(Filesystem\Directory\ReadFactory::class)
6364
->disableOriginalConstructor()
6465
->setMethods(['create'])
6566
->getMock();
@@ -88,7 +89,8 @@ public static function dataPackagesFromComposerSuggest()
8889
'composerJsonGenerator' => function (DependencyTest $test) {
8990
return [
9091
[
91-
['path' => 'app/code/LocalModule'],
92+
'app/code/LocalModule',
93+
DriverPool::FILE,
9294
$test->stubComposerJsonReader(
9395
[
9496
'name' => 'local/module',
@@ -99,11 +101,13 @@ public static function dataPackagesFromComposerSuggest()
99101
)
100102
],
101103
[
102-
['path' => 'app/code/LocalModuleWithoutComposerJson'],
104+
'app/code/LocalModuleWithoutComposerJson',
105+
DriverPool::FILE,
103106
$test->stubFileNotFoundReader()
104107
],
105108
[
106-
['path' => 'vendor/company/module'],
109+
'vendor/company/module',
110+
DriverPool::FILE,
107111
$test->stubComposerJsonReader(
108112
[
109113
'name' => 'company/module',
@@ -114,7 +118,8 @@ public static function dataPackagesFromComposerSuggest()
114118
)
115119
],
116120
[
117-
['path' => 'vendor/company2/module/src/..'],
121+
'vendor/company2/module/src/..',
122+
DriverPool::FILE,
118123
$test->stubComposerJsonReader(
119124
[
120125
'name' => 'company2/module',
@@ -125,19 +130,23 @@ public static function dataPackagesFromComposerSuggest()
125130
)
126131
],
127132
[
128-
['path' => 'vendor/company2/module/src'],
133+
'vendor/company2/module/src',
134+
DriverPool::FILE,
129135
$test->stubFileNotFoundReader()
130136
],
131137
[
132-
['path' => 'vendor/company/module/..'],
138+
'vendor/company/module/..',
139+
DriverPool::FILE,
133140
$test->stubFileNotFoundReader()
134141
],
135142
[
136-
['path' => 'app/code/LocalModuleWithoutComposerJson/..'],
143+
'app/code/LocalModuleWithoutComposerJson/..',
144+
DriverPool::FILE,
137145
$test->stubFileNotFoundReader()
138146
],
139147
[
140-
['path' => 'app/code/LocalModule/..'],
148+
'app/code/LocalModule/..',
149+
DriverPool::FILE,
141150
$test->stubFileNotFoundReader()
142151
],
143152
];

app/code/Magento/SampleData/etc/di.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,4 @@
1515
</argument>
1616
</arguments>
1717
</type>
18-
<virtualType name="Magento\SampleData\Filesystem\Directory\Read" type="Magento\Framework\Filesystem\Directory\Read">
19-
<arguments>
20-
<argument name="driver" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
21-
</arguments>
22-
</virtualType>
23-
<preference for="Magento\Framework\Filesystem\Directory\ReadInterface" type="Magento\SampleData\Filesystem\Directory\Read" />
2418
</config>

dev/tests/api-functional/testsuite/Magento/CatalogInventory/Api/ProductRepositoryInterfaceTest.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
2323
const KEY_PRODUCT_ID = StockStatusInterface::PRODUCT_ID;
2424
const KEY_CUSTOM_ATTRIBUTES = 'custom_attributes';
2525
const KEY_ATTRIBUTE_CODE = \Magento\Eav\Api\Data\AttributeInterface::ATTRIBUTE_CODE;
26-
const CODE_QUANTITY_AND_STOCK_STATUS = 'quantity_and_stock_status';
26+
const KEY_IS_IN_STOCK = 'is_in_stock';
2727

28+
const CODE_QUANTITY_AND_STOCK_STATUS = 'quantity_and_stock_status';
2829
const PRODUCT_SKU = 'sku-test-catalog-inventory';
2930

3031
/**
@@ -159,6 +160,36 @@ public function testSimpleProductCreationWithoutSpecifyingCatalogInventory()
159160
$this->assertTrue($response);
160161
}
161162

163+
/**
164+
* Tests updating product stock item data when previously product was created without specified stock_item
165+
*/
166+
public function testUpdatingQuantity()
167+
{
168+
// create a simple product with catalog inventory
169+
$qty = null;
170+
$productData = $this->getSimpleProductData($qty);
171+
$response = $this->saveProduct($productData);
172+
$stockItemData = $response[self::KEY_EXTENSION_ATTRIBUTES][self::KEY_STOCK_ITEM];
173+
174+
$this->assertEquals($qty, $stockItemData[self::KEY_QTY]);
175+
$this->assertEquals(false, $stockItemData[self::KEY_IS_IN_STOCK]);
176+
177+
// update a created product with catalog inventory
178+
$qty = 1;
179+
$inStock = true;
180+
$response[self::KEY_EXTENSION_ATTRIBUTES][self::KEY_STOCK_ITEM][self::KEY_QTY] = $qty;
181+
$response[self::KEY_EXTENSION_ATTRIBUTES][self::KEY_STOCK_ITEM][self::KEY_IS_IN_STOCK] = $inStock;
182+
$responseUpdated = $this->updateProduct($response);
183+
$stockItemDataUpdated = $responseUpdated[self::KEY_EXTENSION_ATTRIBUTES][self::KEY_STOCK_ITEM];
184+
185+
$this->assertEquals($qty, $stockItemDataUpdated[self::KEY_QTY]);
186+
$this->assertEquals($inStock, $stockItemDataUpdated[self::KEY_IS_IN_STOCK]);
187+
188+
// delete the product; expect that all goes well
189+
$response = $this->deleteProduct($productData[ProductInterface::SKU]);
190+
$this->assertTrue($response);
191+
}
192+
162193
// --- my helpers -----------------------------------------------------------------------------
163194

164195
/**
@@ -195,7 +226,7 @@ protected function getSimpleProductData($qty = 1000)
195226
[self::KEY_ATTRIBUTE_CODE => 'description', 'value' => 'My Product Description'],
196227
[
197228
self::KEY_ATTRIBUTE_CODE => self::CODE_QUANTITY_AND_STOCK_STATUS,
198-
'value' => ['is_in_stock' => true, 'qty' => $qty]
229+
'value' => [self::KEY_IS_IN_STOCK => true, 'qty' => $qty]
199230
],
200231
];
201232
}
@@ -214,7 +245,7 @@ protected function getStockItemData($qty = 1000)
214245
return [
215246
self::KEY_STOCK_ITEM => [
216247
self::KEY_QTY => $qty,
217-
'is_in_stock' => true,
248+
self::KEY_IS_IN_STOCK => true,
218249
'is_qty_decimal' => false,
219250
'show_default_notification_message' => false,
220251
'use_config_min_qty' => true,

0 commit comments

Comments
 (0)