From 9ab49e924768fef08f8061c40f02f9b28d32222f Mon Sep 17 00:00:00 2001 From: Felix Delval Date: Sat, 24 Mar 2018 17:31:13 +0100 Subject: [PATCH 1/4] Return 0 as default quantity when stock index table does not exists --- .../Magento/InventoryIndexer/Model/GetStockItemData.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/InventoryIndexer/Model/GetStockItemData.php b/app/code/Magento/InventoryIndexer/Model/GetStockItemData.php index 18b55d4e479c5..f7b7adf3b8d6d 100644 --- a/app/code/Magento/InventoryIndexer/Model/GetStockItemData.php +++ b/app/code/Magento/InventoryIndexer/Model/GetStockItemData.php @@ -58,7 +58,11 @@ public function execute(string $sku, int $stockId) ->where(IndexStructure::SKU . ' = ?', $sku); try { - return $connection->fetchRow($select) ?: null; + if ($connection->isTableExists($stockItemTableName)) { + return $connection->fetchRow($select) ?: null; + } + + return null; } catch (\Exception $e) { throw new LocalizedException(__( 'Could not receive Stock Item data' From b337cf42e7c37ec64e407569fe2db13e3af12d9e Mon Sep 17 00:00:00 2001 From: Felix Delval Date: Mon, 26 Mar 2018 22:28:14 +0200 Subject: [PATCH 2/4] Updating the test to match new behaviour --- .../GetStockItemData/GetStockItemDataTest.php | 9 +++------ dev/tests/integration/phpunit.xml.dist | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/InventorySales/Test/Integration/GetStockItemData/GetStockItemDataTest.php b/app/code/Magento/InventorySales/Test/Integration/GetStockItemData/GetStockItemDataTest.php index 8069485f816c0..4e97239e37319 100644 --- a/app/code/Magento/InventorySales/Test/Integration/GetStockItemData/GetStockItemDataTest.php +++ b/app/code/Magento/InventorySales/Test/Integration/GetStockItemData/GetStockItemDataTest.php @@ -48,13 +48,10 @@ public function testGetStockItemData(string $sku, int $stockId, $expectedData) self::assertEquals($expectedData, $stockItemData); } - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Could not receive Stock Item data - */ - public function testGetStockItemDataException() + public function testGetStockItemDataReturnNullWhenTableDoesNotExists() { - $this->getStockItemData->execute('SKU-1', 10); + $stockItemData = $this->getStockItemData->execute('SKU-1', 10); + self::assertEquals(null, $stockItemData); } /** diff --git a/dev/tests/integration/phpunit.xml.dist b/dev/tests/integration/phpunit.xml.dist index 56d3b870c5f55..ae4edcc431c19 100644 --- a/dev/tests/integration/phpunit.xml.dist +++ b/dev/tests/integration/phpunit.xml.dist @@ -54,7 +54,7 @@ - + From eec3d09dd23d9e60585e5729e331c8385feedbf8 Mon Sep 17 00:00:00 2001 From: Felix Delval Date: Mon, 26 Mar 2018 22:31:19 +0200 Subject: [PATCH 3/4] Reverting change to phpunit.xml.dist --- dev/tests/integration/phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/phpunit.xml.dist b/dev/tests/integration/phpunit.xml.dist index ae4edcc431c19..56d3b870c5f55 100644 --- a/dev/tests/integration/phpunit.xml.dist +++ b/dev/tests/integration/phpunit.xml.dist @@ -54,7 +54,7 @@ - + From 40a2bebb53d14f006ed1ccc02a25029565da22e9 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Wed, 28 Mar 2018 18:06:15 +0300 Subject: [PATCH 4/4] Fix assertNull instead of assertEquals --- .../Integration/GetStockItemData/GetStockItemDataTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/InventorySales/Test/Integration/GetStockItemData/GetStockItemDataTest.php b/app/code/Magento/InventorySales/Test/Integration/GetStockItemData/GetStockItemDataTest.php index 4e97239e37319..622e9b3280ebe 100644 --- a/app/code/Magento/InventorySales/Test/Integration/GetStockItemData/GetStockItemDataTest.php +++ b/app/code/Magento/InventorySales/Test/Integration/GetStockItemData/GetStockItemDataTest.php @@ -48,10 +48,10 @@ public function testGetStockItemData(string $sku, int $stockId, $expectedData) self::assertEquals($expectedData, $stockItemData); } - public function testGetStockItemDataReturnNullWhenTableDoesNotExists() + public function testGetStockItemDataReturnNullWhenTableDoesNotExist() { $stockItemData = $this->getStockItemData->execute('SKU-1', 10); - self::assertEquals(null, $stockItemData); + self::assertNull($stockItemData); } /**