Skip to content

Commit 1845bcf

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 8d20946 commit 1845bcf

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use Magento\Ui\DataProvider\AddFieldToCollectionInterface;
1212

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +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>
26+
<item name="quantity_and_stock_status" xsi:type="object">Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityAndStockStatusFieldToCollection</item>
2727
</argument>
2828
<argument name="addFilterStrategies" xsi:type="array">
2929
<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: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
12-
use Magento\CatalogInventory\Ui\DataProvider\Product\AddIsInStockFieldToCollection;
12+
use Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityAndStockStatusFieldToCollection;
1313
use PHPUnit\Framework\TestCase;
1414
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\CatalogInventory\Api\StockItemCriteriaInterface;
16+
use Magento\CatalogInventory\Api\StockRegistryInterface;
1517

1618
/**
1719
* Quantity and stock status test
@@ -44,19 +46,16 @@ protected function setUp()
4446
*/
4547
public function testProductStockStatus()
4648
{
47-
/** @var ProductRepositoryInterface $productRepository */
48-
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
49-
$product = $productRepository->get('simple');
50-
$productId = $product->getId();
51-
5249
/** @var StockItemRepository $stockItemRepository */
5350
$stockItemRepository = $this->objectManager->create(StockItemRepository::class);
5451

55-
$stockItem = $stockItemRepository->get($productId);
52+
/** @var StockRegistryInterface $stockRegistry */
53+
$stockRegistry = $this->objectManager->create(StockRegistryInterface::class);
54+
55+
$stockItem = $stockRegistry->getStockItemBySku('simple');
5656
$stockItem->setIsInStock(false);
5757
$stockItemRepository->save($stockItem);
58-
$savedStockItem = $stockItemRepository->get($productId);
59-
$savedStockStatus = $savedStockItem->getData('is_in_stock');
58+
$savedStockStatus = (int)$stockItem->getIsInStock();
6059

6160
$dataProvider = $this->objectManager->create(
6261
ProductDataProvider::class,
@@ -66,7 +65,7 @@ public function testProductStockStatus()
6665
'requestFieldName' => 'id',
6766
'addFieldStrategies' => [
6867
'quantity_and_stock_status' =>
69-
$this->objectManager->get(AddIsInStockFieldToCollection::class)
68+
$this->objectManager->get(AddQuantityAndStockStatusFieldToCollection::class)
7069
]
7170
]
7271
);

0 commit comments

Comments
 (0)