From b22b9518155fa639b08ab524a7815f69612063f9 Mon Sep 17 00:00:00 2001
From: Leonid Poluianov <46716220+le0n4ik@users.noreply.github.com>
Date: Tue, 19 Mar 2024 09:59:21 -0500
Subject: [PATCH] MDEE-735: Product data feed crashes when MSI is disabled
(#404)
* MDEE-735: Product data feed crashes when MSI is disabled
---
.../Model/Plugin/StockStatusUpdater.php | 10 +-
.../Product/InventoryDataProvider.php | 48 ++++---
.../Model/Query/CatalogInventoryQuery.php | 2 +
.../Query/CatalogInventoryStockQuery.php | 79 ++++++++++++
.../CatalogInventoryStockQueryInterface.php | 25 ++++
.../Model/Query/InventoryData.php | 12 +-
CatalogInventoryDataExporter/etc/di.xml | 1 +
.../Model/Provider/StockStatus.php | 18 ++-
.../Query/CatalogInventoryStockQuery.php | 118 ++++++++++++++++++
.../Model/Query/InventoryStockQuery.php | 8 +-
.../AbstractInventoryTestHelper.php | 19 +++
.../Integration/ExportStockStatusTest.php | 50 ++++----
.../Integration/PartialReindexCheckTest.php | 36 ++----
.../UnassignProductFromStockTest.php | 12 +-
InventoryDataExporter/composer.json | 7 ++
InventoryDataExporter/etc/di.xml | 2 +-
16 files changed, 353 insertions(+), 94 deletions(-)
create mode 100644 CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php
create mode 100644 CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQueryInterface.php
create mode 100644 InventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php
diff --git a/CatalogInventoryDataExporter/Model/Plugin/StockStatusUpdater.php b/CatalogInventoryDataExporter/Model/Plugin/StockStatusUpdater.php
index 86ba52e7..1a9529c3 100644
--- a/CatalogInventoryDataExporter/Model/Plugin/StockStatusUpdater.php
+++ b/CatalogInventoryDataExporter/Model/Plugin/StockStatusUpdater.php
@@ -6,13 +6,6 @@
namespace Magento\CatalogInventoryDataExporter\Model\Plugin;
-use Magento\Framework\App\ResourceConnection;
-use Magento\Framework\Indexer\IndexerRegistry;
-use Magento\InventoryApi\Api\Data\SourceItemInterface;
-use Magento\InventoryApi\Api\SourceItemsSaveInterface;
-use Magento\Catalog\Model\ProductRepository;
-use Magento\Indexer\Model\IndexerFactory;
-use Magento\DataExporter\Model\Logging\CommerceDataExportLoggerInterface as LoggerInterface;
use Magento\InventoryIndexer\Model\ResourceModel\UpdateIsSalable;
use Magento\InventoryMultiDimensionalIndexerApi\Model\IndexName;
@@ -44,7 +37,8 @@ public function __construct(
*/
public function afterExecute(
UpdateIsSalable $subject,
- $result, IndexName $indexName,
+ $result,
+ IndexName $indexName,
array $dataForUpdate,
string $connectionName
): void {
diff --git a/CatalogInventoryDataExporter/Model/Provider/Product/InventoryDataProvider.php b/CatalogInventoryDataExporter/Model/Provider/Product/InventoryDataProvider.php
index fec050cc..7b593779 100644
--- a/CatalogInventoryDataExporter/Model/Provider/Product/InventoryDataProvider.php
+++ b/CatalogInventoryDataExporter/Model/Provider/Product/InventoryDataProvider.php
@@ -7,10 +7,13 @@
namespace Magento\CatalogInventoryDataExporter\Model\Provider\Product;
+use Magento\CatalogInventoryDataExporter\Model\Query\CatalogInventoryStockQueryInterface;
use Magento\CatalogInventoryDataExporter\Model\Query\CatalogInventoryQuery;
use Magento\CatalogInventoryDataExporter\Model\Query\InventoryData;
+use Magento\CatalogInventoryDataExporter\Model\Query\CatalogInventoryStockQuery;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Module\ModuleList;
+use Magento\Framework\App\ObjectManager;
/**
* Provide inventory stock status data depending on current Inventory Management system
@@ -28,17 +31,31 @@ class InventoryDataProvider
/**
* Provide inventory data when MSI modules enabled
*
+ * @deprecated Not used anymore. Left for BC
+ * @see \Magento\CatalogInventoryDataExporter\Model\Query\CatalogInventoryStockQueryInterface
* @var InventoryData
*/
private InventoryData $inventoryData;
/**
- * Provide inventory data when only Legacy Inventory modules enabled
- *
+ * @deprecated Not used anymore. Left for BC
+ * @see \Magento\CatalogInventoryDataExporter\Model\Query\CatalogInventoryStockQueryInterface
* @var CatalogInventoryQuery
*/
private CatalogInventoryQuery $catalogInventoryQuery;
+ /**
+ * Provide inventory data
+ *
+ * @var CatalogInventoryStockQueryInterface
+ */
+ private CatalogInventoryStockQueryInterface $catalogInventoryStockQuery;
+
+ /**
+ * @deprecated Not used anymore. Left for BC
+ * @see \Magento\CatalogInventoryDataExporter\Model\Query\CatalogInventoryStockQueryInterface
+ * @var ModuleList
+ */
private ModuleList $moduleList;
/**
@@ -46,22 +63,29 @@ class InventoryDataProvider
* @param InventoryData $inventoryData
* @param CatalogInventoryQuery $catalogInventoryQuery
* @param ModuleList $moduleList
+ * @param CatalogInventoryStockQueryInterface|null $catalogInventoryStockQuery
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
ResourceConnection $resourceConnection,
InventoryData $inventoryData,
CatalogInventoryQuery $catalogInventoryQuery,
- ModuleList $moduleList
+ ModuleList $moduleList,
+ ?CatalogInventoryStockQueryInterface $catalogInventoryStockQuery
) {
$this->resourceConnection = $resourceConnection;
$this->inventoryData = $inventoryData;
$this->catalogInventoryQuery = $catalogInventoryQuery;
$this->moduleList = $moduleList;
+ $this->catalogInventoryStockQuery = $catalogInventoryStockQuery
+ ?? ObjectManager::getInstance()->get(CatalogInventoryStockQuery::class);
}
/**
* @param array $feedItems
* @return array
+ * @throws \Zend_Db_Select_Exception
+ * @throws \Zend_Db_Statement_Exception
*/
public function get(array $feedItems): array
{
@@ -78,11 +102,7 @@ public function get(array $feedItems): array
}
$connection = $this->resourceConnection->getConnection();
- if ($this->isMSIEnabled()) {
- $select = $this->inventoryData->get($queryArguments);
- } else {
- $select = $this->catalogInventoryQuery->getInStock($queryArguments);
- }
+ $select = $this->catalogInventoryStockQuery->getInStock($queryArguments);
if (!$select) {
return $output;
}
@@ -95,14 +115,6 @@ public function get(array $feedItems): array
return $output;
}
- /**
- * @return bool
- */
- private function isMSIEnabled(): bool
- {
- return $this->moduleList->getOne('Magento_InventoryIndexer') !== null;
- }
-
/**
* Format output
*
@@ -119,10 +131,10 @@ private function format(array $row) : array
}
/**
- * @param $item
+ * @param array $item
* @return string
*/
- private function getKey($item): string
+ private function getKey(array $item): string
{
return $item['productId'] . '-' . $item['storeViewCode'];
}
diff --git a/CatalogInventoryDataExporter/Model/Query/CatalogInventoryQuery.php b/CatalogInventoryDataExporter/Model/Query/CatalogInventoryQuery.php
index d1b7fd34..076880d5 100644
--- a/CatalogInventoryDataExporter/Model/Query/CatalogInventoryQuery.php
+++ b/CatalogInventoryDataExporter/Model/Query/CatalogInventoryQuery.php
@@ -14,6 +14,8 @@
* Class CatalogInventoryQuery
*
* Gets information about product inventory
+ * @deprecated use CatalogInventoryStockQueryInterface to get stock status
+ * @see \Magento\CatalogInventoryDataExporter\Model\Query\CatalogInventoryStockQueryInterface
*/
class CatalogInventoryQuery
{
diff --git a/CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php b/CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php
new file mode 100644
index 00000000..8739ce92
--- /dev/null
+++ b/CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php
@@ -0,0 +1,79 @@
+resourceConnection = $resourceConnection;
+ }
+
+ /**
+ * Get table name
+ *
+ * @param string $tableName
+ * @return string
+ */
+ private function getTable(string $tableName) : string
+ {
+ return $this->resourceConnection->getTableName($tableName);
+ }
+
+ /**
+ * Get query with information about in_stock status
+ *
+ * @param array $arguments
+ * @return Select
+ */
+ public function getInStock(array $arguments) : Select
+ {
+ $productIds = isset($arguments['productId']) ? $arguments['productId'] : [];
+ $storeViewCodes = isset($arguments['storeViewCode']) ? $arguments['storeViewCode'] : [];
+ $connection = $this->resourceConnection->getConnection();
+ $select = $connection->select()
+ ->from(['cpe' => $this->getTable('catalog_product_entity')], '')
+ ->joinCross(
+ ['s' => $this->getTable('store')],
+ ''
+ )
+ ->joinInner(
+ ['csi' => $this->getTable('cataloginventory_stock_status')],
+ "cpe.entity_id = csi.product_id",
+ ''
+ )
+ ->columns(
+ [
+ 'productId' => 'csi.product_id',
+ 'storeViewCode' => 's.code',
+ 'qty' => 'csi.qty',
+ 'is_in_stock' => 'csi.stock_status'
+ ]
+ )
+ ->where('s.code IN (?)', $storeViewCodes)
+ ->where('csi.product_id IN (?)', $productIds);
+ return $select;
+ }
+}
diff --git a/CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQueryInterface.php b/CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQueryInterface.php
new file mode 100644
index 00000000..1d61ba2a
--- /dev/null
+++ b/CatalogInventoryDataExporter/Model/Query/CatalogInventoryStockQueryInterface.php
@@ -0,0 +1,25 @@
+resourceConnection = $resourceConnection;
$this->logger = $logger;
- $defaultStockProvider = $defaultStockProvider ??
- ObjectManager::getInstance()->get(DefaultStockProviderInterface::class);
- $this->defaultStockId = $defaultStockProvider->getId();
+ $this->defaultStockId = Stock::DEFAULT_STOCK_ID;
}
/**
diff --git a/CatalogInventoryDataExporter/etc/di.xml b/CatalogInventoryDataExporter/etc/di.xml
index 6b9f911d..e06d88ee 100644
--- a/CatalogInventoryDataExporter/etc/di.xml
+++ b/CatalogInventoryDataExporter/etc/di.xml
@@ -11,6 +11,7 @@
catalog_product_entity
+
diff --git a/InventoryDataExporter/Model/Provider/StockStatus.php b/InventoryDataExporter/Model/Provider/StockStatus.php
index 678e2211..7f19bc89 100644
--- a/InventoryDataExporter/Model/Provider/StockStatus.php
+++ b/InventoryDataExporter/Model/Provider/StockStatus.php
@@ -75,12 +75,13 @@ public function __construct(
*/
public function get(array $values): array
{
- $skus = \array_column($values, 'sku');
+ // For stock statuses we are operating with product ids
+ $ids = \array_column($values, 'sku');
$connection = $this->resourceConnection->getConnection();
$output = [];
try {
- $select = $this->query->getQuery($skus);
+ $select = $this->query->getQuery($ids);
// $select can be null if no stocks exists except default
if ($select) {
$cursor = $connection->query($select);
@@ -89,7 +90,7 @@ public function get(array $values): array
}
}
- $select = $this->query->getQueryForDefaultStock($skus);
+ $select = $this->query->getQueryForDefaultStock($ids);
$cursor = $connection->query($select);
while ($row = $cursor->fetch()) {
$output[] = $this->fillWithDefaultValues($row);
@@ -112,8 +113,15 @@ public function get(array $values): array
*/
private function fillWithDefaultValues(array $row): array
{
- if (!isset($row['qty'], $row['isSalable'], $row['sku'], $row['stockId'], $row['manageStock'],
- $row['useConfigManageStock'], $row['backorders'], $row['useConfigBackorders'])) {
+ if (!isset($row['qty'],
+ $row['isSalable'],
+ $row['sku'],
+ $row['stockId'],
+ $row['manageStock'],
+ $row['useConfigManageStock'],
+ $row['backorders'],
+ $row['useConfigBackorders'])
+ ) {
throw new \RuntimeException("missed required field: " . \var_export($row, true));
}
// set updated at
diff --git a/InventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php b/InventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php
new file mode 100644
index 00000000..e5499c4d
--- /dev/null
+++ b/InventoryDataExporter/Model/Query/CatalogInventoryStockQuery.php
@@ -0,0 +1,118 @@
+resourceConnection = $resourceConnection;
+ $this->logger = $logger;
+ $defaultStockProvider = $defaultStockProvider ??
+ ObjectManager::getInstance()->get(DefaultStockProviderInterface::class);
+ $this->defaultStockId = $defaultStockProvider->getId();
+ }
+
+ /**
+ * Get is_salable data from inventory
+ *
+ * @param array $arguments
+ * @return Select|null
+ * @throws \Zend_Db_Select_Exception
+ */
+ public function getInStock($arguments): ?Select
+ {
+ $productIds = $arguments['productId'] ?? [];
+ $connection = $this->resourceConnection->getConnection();
+
+ $stocks = $connection->select()
+ ->from(
+ ['channel' => $this->resourceConnection->getTableName('inventory_stock_sales_channel')],
+ ['stock_id' => 'channel.stock_id']
+ )
+ ->joinInner(
+ ['w' => $this->resourceConnection->getTableName('store_website')],
+ 'channel.code = w.code',
+ ['website_ids' => ' GROUP_CONCAT(DISTINCT w.website_id)']
+ )
+ ->where('channel.type = ?', 'website')
+ ->group('stock_id');
+
+ $union = [];
+ foreach ($stocks->query()->fetchAll() as $stock) {
+ $select = $connection->select()
+ ->from(
+ ['e' => $this->resourceConnection->getTableName('catalog_product_entity')],
+ ['productId' => 'e.entity_id']
+ );
+
+ $stockId = (int)$stock['stock_id'];
+ if ($stockId === $this->defaultStockId) {
+ // to fix performance issue with `inventory_stock_1` view that doesn't have proper index
+ $select->joinInner(
+ ['i' => $this->resourceConnection->getTableName('cataloginventory_stock_status')],
+ 'e.entity_id = i.product_id',
+ ['is_in_stock' => 'i.stock_status', 'quantity' => 'i.qty']
+ );
+ } else {
+ $select->joinInner(
+ ['i' => $this->resourceConnection->getTableName(sprintf('inventory_stock_%s', $stockId))],
+ 'e.sku = i.sku',
+ ['is_in_stock' => 'i.is_salable', 'i.quantity']
+ );
+ }
+
+ $select
+ ->joinInner(
+ ['pw' => $this->resourceConnection->getTableName('catalog_product_website')],
+ 'pw.product_id = e.entity_id',
+ []
+ )
+ ->joinCross(
+ ['s' => $this->resourceConnection->getTableName('store')],
+ ['storeViewCode' => 's.code']
+ )
+ ->where('e.entity_id IN (?)', $productIds)
+ ->where('pw.website_id IN (?)', explode(',', $stock['website_ids']))
+ ->where('s.website_id IN (?)', explode(',', $stock['website_ids']))
+ ->group('e.entity_id')
+ ->group('s.store_id');
+ $union[] = $select;
+ }
+
+ if (!$union) {
+ $this->logger->error(
+ "No stocks found for website sales channel. Cannot obtain stock status."
+ );
+ return null;
+ }
+ return $connection->select()->union($union, Select::SQL_UNION_ALL);
+ }
+}
diff --git a/InventoryDataExporter/Model/Query/InventoryStockQuery.php b/InventoryDataExporter/Model/Query/InventoryStockQuery.php
index 16d2f1e7..5af836f7 100644
--- a/InventoryDataExporter/Model/Query/InventoryStockQuery.php
+++ b/InventoryDataExporter/Model/Query/InventoryStockQuery.php
@@ -56,8 +56,8 @@ private function getTable(string $tableName): string
* Get query for provider
*
* @param array $productIds
- * @param bool $defaultStock
* @return Select|null
+ * @throws \Zend_Db_Select_Exception
*/
public function getQuery(array $productIds): ?Select
{
@@ -118,17 +118,17 @@ public function getQuery(array $productIds): ?Select
/**
* Get data for default stock: "inventory_stock_1" is a view used as a fallback
*
- * @param array $skus
+ * @param array $productIds
* @return Select
* @see \Magento\InventoryCatalog\Setup\Patch\Schema\CreateLegacyStockStatusView
*/
- public function getQueryForDefaultStock(array $skus): Select
+ public function getQueryForDefaultStock(array $productIds): Select
{
$connection = $this->resourceConnection->getConnection();
$stockId = $this->defaultStockProvider->getId();
return $connection->select()
->from(['isi' => $this->getTable(sprintf('inventory_stock_%s', $stockId))], [])
- ->where('isi.sku IN (?)', $skus)
+ ->where('isi.product_id IN (?)', $productIds)
->joinInner(
[
'stock_item' => $this->resourceConnection->getTableName('cataloginventory_stock_item'),
diff --git a/InventoryDataExporter/Test/Integration/AbstractInventoryTestHelper.php b/InventoryDataExporter/Test/Integration/AbstractInventoryTestHelper.php
index ee0e03ea..adbc76b3 100644
--- a/InventoryDataExporter/Test/Integration/AbstractInventoryTestHelper.php
+++ b/InventoryDataExporter/Test/Integration/AbstractInventoryTestHelper.php
@@ -9,7 +9,9 @@
namespace Magento\InventoryDataExporter\Test\Integration;
+use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\ResourceConnection;
+use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Indexer\Model\Indexer;
use Magento\TestFramework\Helper\Bootstrap;
use function PHPUnit\Framework\assertEmpty;
@@ -37,6 +39,11 @@ abstract class AbstractInventoryTestHelper extends \PHPUnit\Framework\TestCase
*/
protected $indexer;
+ /**
+ * @var ProductRepositoryInterface
+ */
+ private mixed $productRepository;
+
/**
* Setup tests
* @throws \Throwable
@@ -45,6 +52,7 @@ protected function setUp(): void
{
$this->resource = Bootstrap::getObjectManager()->create(ResourceConnection::class);
$this->indexer = Bootstrap::getObjectManager()->create(Indexer::class);
+ $this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
$this->indexer->load(self::STOCK_STATUS_FEED_INDEXER);
$this->reindexStockStatusDataExporterTable();
@@ -93,4 +101,15 @@ private function truncateStockStatusDataExporterIndexTable(): void
$changeLogTable = $this->indexer->getView()->getChangelog()->getName();
$connection->truncateTable($changeLogTable);
}
+
+ /**
+ * @param string $sku
+ * @return int|null
+ * @throws NoSuchEntityException
+ */
+ public function getProductId(string $sku): ?int
+ {
+ $product = $this->productRepository->get($sku);
+ return (int)$product->getId();
+ }
}
diff --git a/InventoryDataExporter/Test/Integration/ExportStockStatusTest.php b/InventoryDataExporter/Test/Integration/ExportStockStatusTest.php
index 2e0e79b3..6cbc5a10 100644
--- a/InventoryDataExporter/Test/Integration/ExportStockStatusTest.php
+++ b/InventoryDataExporter/Test/Integration/ExportStockStatusTest.php
@@ -14,7 +14,7 @@
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*/
-class ExportStockStatusTest extends \PHPUnit\Framework\TestCase
+class ExportStockStatusTest extends AbstractInventoryTestHelper
{
/**
* @var Processor
@@ -35,17 +35,22 @@ protected function setUp(): void
*/
public function testExportStockStatuses()
{
+ $productsSkus = [
+ 'product_in_EU_stock_with_2_sources',
+ 'product_in_Global_stock_with_3_sources',
+ 'product_with_default_stock_only',
+ 'product_in_default_and_2_EU_sources',
+ 'product_with_disabled_manage_stock',
+ 'product_with_enabled_backorders',
+ 'product_in_US_stock_with_disabled_source'
+ ];
+ $products = [];
+ foreach ($productsSkus as $sku) {
+ $products[] = ['sku' => $this->getProductId($sku)];
+ }
$actualStockStatus = $this->processor->process(
'inventoryStockStatus',
- [
- ['sku' => 'product_in_EU_stock_with_2_sources'],
- ['sku' => 'product_in_Global_stock_with_3_sources'],
- ['sku' => 'product_with_default_stock_only'],
- ['sku' => 'product_in_default_and_2_EU_sources'],
- ['sku' => 'product_with_disabled_manage_stock'],
- ['sku' => 'product_with_enabled_backorders'],
- ['sku' => 'product_in_US_stock_with_disabled_source'],
- ]
+ $products
);
$actualStockStatusFormatted = [];
@@ -74,20 +79,23 @@ public function testExportStockStatuses()
*/
public function testExportStockStatusesWithReservations()
{
+ $productsSkus = [
+ 'product_in_EU_stock_with_2_sources',
+ 'product_in_Global_stock_with_3_sources',
+ 'product_with_default_stock_only',
+ 'product_in_default_and_2_EU_sources',
+ 'product_with_disabled_manage_stock',
+ 'product_with_enabled_backorders',
+ 'product_in_US_stock_with_disabled_source'
+ ];
+ $products = [];
+ foreach ($productsSkus as $sku) {
+ $products[] = ['sku' => $this->getProductId($sku)];
+ }
$actualStockStatus = $this->processor->process(
'inventoryStockStatus',
- [
- ['sku' => 'product_in_EU_stock_with_2_sources'],
- ['sku' => 'product_in_Global_stock_with_3_sources'],
- ['sku' => 'product_with_default_stock_only'],
- ['sku' => 'product_in_default_and_2_EU_sources'],
- ['sku' => 'product_with_disabled_manage_stock'],
- ['sku' => 'product_with_enabled_backorders'],
- ['sku' => 'product_in_US_stock_with_disabled_source'],
- ]
+ $products
);
-
- $actualStockStatusFormatted = [];
foreach ($actualStockStatus as $stockStatus) {
$actualStockStatusFormatted[$stockStatus['stockId']][$stockStatus['sku']] = $stockStatus;
}
diff --git a/InventoryDataExporter/Test/Integration/PartialReindexCheckTest.php b/InventoryDataExporter/Test/Integration/PartialReindexCheckTest.php
index 491fd3d9..38a9d76a 100644
--- a/InventoryDataExporter/Test/Integration/PartialReindexCheckTest.php
+++ b/InventoryDataExporter/Test/Integration/PartialReindexCheckTest.php
@@ -10,22 +10,18 @@
use Magento\DataExporter\Model\FeedInterface;
use Magento\DataExporter\Model\FeedPool;
-use Magento\Indexer\Model\Indexer;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory;
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
use Magento\InventoryCatalogApi\Api\BulkSourceUnassignInterface;
use Magento\TestFramework\Helper\Bootstrap;
-use PHPUnit\Framework\TestCase;
/**
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*/
-class PartialReindexCheckTest extends TestCase
+class PartialReindexCheckTest extends AbstractInventoryTestHelper
{
- private const STOCK_STATUS_FEED_INDEXER = 'inventory_data_exporter_stock_status';
-
/**
* @var FeedInterface
*/
@@ -46,21 +42,17 @@ class PartialReindexCheckTest extends TestCase
*/
private $bulkSourceUnassign;
- /**
- * @var Indexer
- */
- protected $indexer;
-
/**
* @inheritDoc
*/
protected function setUp(): void
{
+ parent::setUp();
+
$this->stockStatusFeed = Bootstrap::getObjectManager()->get(FeedPool::class)->getFeed('inventoryStockStatus');
$this->sourceItemsFactory = Bootstrap::getObjectManager()->get(SourceItemInterfaceFactory::class);
$this->sourceItemsSave = Bootstrap::getObjectManager()->get(SourceItemsSaveInterface::class);
$this->bulkSourceUnassign = Bootstrap::getObjectManager()->get(BulkSourceUnassignInterface::class);
- $this->indexer = Bootstrap::getObjectManager()->create(Indexer::class);
}
/**
@@ -78,7 +70,8 @@ public function testSourceItemQtyUpdated()
]]);
$this->sourceItemsSave->execute([$sourceItem]);
- $this->runIndexer([$sku]);
+ $productId = $this->getProductId($sku);
+ $this->emulatePartialReindexBehavior([$productId]);
$feedData = $this->getFeedData([$sku]);
@@ -124,8 +117,11 @@ public function testSourceBulkUnassign()
$skus,
['eu-1', 'default']
);
-
- $this->runIndexer($skus);
+ $productIds = [];
+ foreach ($skus as $sku) {
+ $productIds[] = $this->getProductId($sku);
+ }
+ $this->emulatePartialReindexBehavior($productIds);
$feedData = $this->getFeedData($skus);
@@ -207,16 +203,4 @@ private function getFeedData(array $skus): array
}
return $output;
}
-
- /**
- * Run the indexer to extract stock item data
- *
- * @param array $skus
- * @return void
- */
- private function runIndexer(array $skus = []) : void
- {
- $this->indexer->load(self::STOCK_STATUS_FEED_INDEXER);
- $this->indexer->reindexList($skus);
- }
}
diff --git a/InventoryDataExporter/Test/Integration/UnassignProductFromStockTest.php b/InventoryDataExporter/Test/Integration/UnassignProductFromStockTest.php
index 57b9a0f0..1a963b7c 100644
--- a/InventoryDataExporter/Test/Integration/UnassignProductFromStockTest.php
+++ b/InventoryDataExporter/Test/Integration/UnassignProductFromStockTest.php
@@ -15,7 +15,6 @@
use Magento\InventoryCatalogApi\Api\BulkSourceUnassignInterface;
use Magento\InventoryCatalogApi\Model\SourceItemsProcessorInterface;
use Magento\TestFramework\Helper\Bootstrap;
-use PHPUnit\Framework\TestCase;
/**
* @magentoDbIsolation disabled
@@ -63,8 +62,8 @@ public function testSourceItemStockUnassigned(string $sku, array $sourcesToLeave
{
$sourceItems = $this->getSourcesData($sku, $sourcesToLeave);
$this->sourceItemProcessor->execute($sku, $sourceItems);
-
- $this->emulatePartialReindexBehavior([$sku]);
+ $productId = $this->getProductId($sku);
+ $this->emulatePartialReindexBehavior([$productId]);
$feedData = $this->getFeedData([$sku]);
$this->verifyResults($feedData, $sku, $expectedData);
@@ -86,8 +85,11 @@ public function testSourceItemsBulkUnassign(array $skus, array $sourcesToUnassig
$skus,
$sourcesToUnassign
);
-
- $this->emulatePartialReindexBehavior($skus);
+ $productIds = [];
+ foreach ($skus as $sku) {
+ $productIds[] = $this->getProductId($sku);
+ }
+ $this->emulatePartialReindexBehavior($productIds);
$feedData = $this->getFeedData($skus);
foreach ($skus as $sku) {
diff --git a/InventoryDataExporter/composer.json b/InventoryDataExporter/composer.json
index 218555b6..f1f01a15 100644
--- a/InventoryDataExporter/composer.json
+++ b/InventoryDataExporter/composer.json
@@ -14,14 +14,21 @@
"Magento\\InventoryDataExporter\\": ""
}
},
+ "suggest": {
+ "magento/module-inventory-indexer": "*",
+ "magento/module-inventory-multi-dimensional-indexer-api": ">=1.2.1"
+ },
"require": {
"php": "~8.1.0||~8.2.0||~8.3.0",
"magento/framework": ">=103.0.4",
"magento/module-catalog-inventory": ">=100.4.4",
"magento/module-catalog": ">=104.0.4",
+ "magento/module-store": ">=101.1.4",
"magento/module-inventory": ">=1.2.2",
"magento/module-inventory-api": ">=1.2.2",
"magento/module-inventory-catalog-api": ">=1.3.2",
+ "magento/module-inventory-sales": ">=1.3.0",
+ "magento/module-catalog-inventory-data-exporter": "self.version",
"magento/module-data-exporter": "self.version",
"magento/module-query-xml": "self.version"
}
diff --git a/InventoryDataExporter/etc/di.xml b/InventoryDataExporter/etc/di.xml
index 94944685..44c11bec 100644
--- a/InventoryDataExporter/etc/di.xml
+++ b/InventoryDataExporter/etc/di.xml
@@ -18,7 +18,7 @@
Magento\InventoryDataExporter\Model\Indexer\StockStatusFeedIndexMetadata
-
+
inventoryStockStatus