Skip to content

Commit f665cca

Browse files
MAGETWO-98013: [2.3] Configurable product is displayed as In Stock in product grid when it's set to out of stock
1 parent 7578598 commit f665cca

File tree

6 files changed

+56
-62
lines changed

6 files changed

+56
-62
lines changed

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
<arguments>
8888
<argument name="addFieldStrategies" xsi:type="array">
8989
<item name="websites" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\AddWebsitesFieldToCollection</item>
90-
<item name="quantity_and_stock_status" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\AddQuantityAndStockStatusFieldToCollection</item>
9190
</argument>
9291
<argument name="addFilterStrategies" xsi:type="array">
9392
<item name="store_id" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\AddStoreFieldToCollection</item>

app/code/Magento/Catalog/Ui/DataProvider/Product/AddQuantityAndStockStatusFieldToCollection.php renamed to app/code/Magento/CatalogInventory/Ui/DataProvider/Product/AddIsInStockFieldToCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Catalog\Ui\DataProvider\Product;
8+
namespace Magento\CatalogInventory\Ui\DataProvider\Product;
99

1010
use Magento\Framework\Data\Collection;
1111
use Magento\Ui\DataProvider\AddFieldToCollectionInterface;
1212

1313
/**
14-
* Class AddQuantityAndStockStatusFieldToCollection
14+
* Add is_in_stock field to collection
1515
*/
16-
class AddQuantityAndStockStatusFieldToCollection implements AddFieldToCollectionInterface
16+
class AddIsInStockFieldToCollection implements AddFieldToCollectionInterface
1717
{
1818
/**
1919
* @inheritdoc

app/code/Magento/CatalogInventory/etc/adminhtml/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<arguments>
2424
<argument name="addFieldStrategies" xsi:type="array">
2525
<item name="qty" xsi:type="object">Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFieldToCollection</item>
26+
<item name="quantity_and_stock_status" xsi:type="object">Magento\CatalogInventory\Ui\DataProvider\Product\AddIsInStockFieldToCollection</item>
2627
</argument>
2728
<argument name="addFilterStrategies" xsi:type="array">
2829
<item name="qty" xsi:type="object">Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection</item>

dev/tests/integration/testsuite/Magento/Catalog/Ui/DataProvider/Product/QuantityAndStockStatusTest.php

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77

88
namespace Magento\Catalog\Ui\DataProvider\Product;
99

10-
use Magento\Eav\Setup\EavSetup;
10+
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
11+
use Magento\CatalogInventory\Ui\DataProvider\Product\AddIsInStockFieldToCollection;
1112
use PHPUnit\Framework\TestCase;
1213
use Magento\TestFramework\Helper\Bootstrap;
13-
use Magento\Catalog\Model\Product;
14-
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
15-
use Magento\CatalogInventory\Api\StockItemCriteriaInterface;
16-
use Magento\Catalog\Api\Data\EavAttributeInterface;
1714

1815
/**
19-
* Class QuantityAndStockStatusTest
16+
* Quantity and stock status test
2017
*/
2118
class QuantityAndStockStatusTest extends TestCase
2219
{
@@ -30,53 +27,33 @@ class QuantityAndStockStatusTest extends TestCase
3027
*/
3128
private $objectManager;
3229

33-
/**
34-
* @var int
35-
*/
36-
private $isUsedInGridValue;
37-
3830
/**
3931
* @inheritdoc
4032
*/
4133
protected function setUp()
4234
{
4335
$this->objectManager = Bootstrap::getObjectManager();
44-
$eavSetup = $this->objectManager->create(EavSetup::class);
45-
$this->isUsedInGridValue = $eavSetup->getAttribute(
46-
Product::ENTITY,
47-
self::$quantityAndStockStatus,
48-
EavAttributeInterface::IS_USED_IN_GRID
49-
);
50-
$eavSetup->addAttribute(
51-
Product::ENTITY,
52-
self::$quantityAndStockStatus,
53-
[
54-
EavAttributeInterface::IS_USED_IN_GRID => 1,
55-
]
56-
);
5736
}
5837

5938
/**
6039
* Test product stock status in the products grid column
6140
*
41+
* @magentoDataFixture Magento/Catalog/_files/quantity_and_stock_status_attribute_used_in_grid.php
6242
* @magentoDataFixture Magento/Checkout/_files/simple_product.php
6343
*/
6444
public function testProductStockStatus()
6545
{
66-
$stockItemRepository = $this->objectManager->create(StockItemRepository::class);
67-
68-
/** @var StockItemCriteriaInterface $stockItemCriteria */
69-
$stockItemCriteria = $this->objectManager->create(StockItemCriteriaInterface::class);
70-
71-
$savedStockItem = current($stockItemRepository->getList($stockItemCriteria)
72-
->getItems());
73-
$savedStockItemId = $savedStockItem->getItemId();
46+
$productId = 1;
7447

75-
$savedStockItem->setIsInStock(true);
76-
$savedStockItem->save();
48+
/** @var StockItemRepository $stockItemRepository */
49+
$stockItemRepository = $this->objectManager
50+
->create(StockItemRepository::class);
51+
$stockItem = $stockItemRepository->get($productId);
52+
$stockItem->setIsInStock(false);
53+
$stockItemRepository->save($stockItem);
7754

78-
$savedStockItem->setIsInStock(false);
79-
$savedStockItem->save();
55+
$savedStockItem = $stockItemRepository->get($productId);
56+
$savedStockStatus = $savedStockItem->getData('is_in_stock');
8057

8158
$dataProvider = $this->objectManager->create(
8259
ProductDataProvider::class,
@@ -86,34 +63,15 @@ public function testProductStockStatus()
8663
'requestFieldName' => 'id',
8764
'addFieldStrategies' => [
8865
'quantity_and_stock_status' =>
89-
$this->objectManager->get(AddQuantityAndStockStatusFieldToCollection::class)
66+
$this->objectManager->get(AddIsInStockFieldToCollection::class)
9067
]
9168
]
9269
);
9370

9471
$dataProvider->addField(self::$quantityAndStockStatus);
9572
$data = $dataProvider->getData();
73+
$dataProviderStockStatus = $data['items'][0][self::$quantityAndStockStatus];
9674

97-
$this->assertEquals(
98-
$data['items'][0][self::$quantityAndStockStatus],
99-
$savedStockItem->load($savedStockItemId)
100-
->getData('is_in_stock')
101-
);
102-
}
103-
104-
/**
105-
* @inheritdoc
106-
*/
107-
protected function tearDown()
108-
{
109-
$eavSetup = $this->objectManager->create(EavSetup::class);
110-
$eavSetup->addAttribute(
111-
Product::ENTITY,
112-
self::$quantityAndStockStatus,
113-
[
114-
EavAttributeInterface::IS_USED_IN_GRID => $this->isUsedInGridValue,
115-
]
116-
);
117-
parent::tearDown();
75+
$this->assertEquals($dataProviderStockStatus, $savedStockStatus);
11876
}
11977
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
$eavSetupFactory = $objectManager->create(\Magento\Eav\Setup\EavSetupFactory::class);
10+
/** @var \Magento\Eav\Setup\EavSetup $eavSetup */
11+
$eavSetup = $eavSetupFactory->create();
12+
$eavSetup->updateAttribute(
13+
\Magento\Catalog\Model\Product::ENTITY,
14+
'quantity_and_stock_status',
15+
[
16+
'is_used_in_grid' => 1,
17+
]
18+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
$eavSetupFactory = $objectManager->create(\Magento\Eav\Setup\EavSetupFactory::class);
10+
/** @var \Magento\Eav\Setup\EavSetup $eavSetup */
11+
$eavSetup = $eavSetupFactory->create();
12+
$eavSetup->updateAttribute(
13+
\Magento\Catalog\Model\Product::ENTITY,
14+
'quantity_and_stock_status',
15+
[
16+
'is_used_in_grid' => 0,
17+
]
18+
);

0 commit comments

Comments
 (0)