diff --git a/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Indexer/Fulltext/Action/Full.php b/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Indexer/Fulltext/Action/Full.php index 8a2188676..0e037da0f 100644 --- a/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Indexer/Fulltext/Action/Full.php +++ b/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Indexer/Fulltext/Action/Full.php @@ -18,7 +18,6 @@ use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\ObjectManagerInterface; -use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer; use Magento\Framework\App\ResourceConnection; /** @@ -123,13 +122,7 @@ public function getRelationsByChild($childrenIds) private function addIsVisibleInStoreFilter($select, $storeId) { $rootCategoryId = $this->getRootCategoryId($storeId); - $indexTableName = $this->getTable('catalog_category_product_index'); - - if ($tableMaintainer = $this->objectManager->get(TableMaintainer::class)) { - $indexTableName = $tableMaintainer->getMainTable($storeId); - } - - $indexTable = $this->getTable($indexTableName); + $indexTable = $this->getCategoryProductIndexTable($storeId); $visibilityJoinCond = $this->getConnection()->quoteInto( 'visibility.product_id = e.entity_id AND visibility.store_id = ?', @@ -142,4 +135,27 @@ private function addIsVisibleInStoreFilter($select, $storeId) return $this; } + + /** + * Retrieve category/product index table. + * + * @param int $storeId The store Id + * + * @return string + */ + private function getCategoryProductIndexTable($storeId) + { + // Init table name as legacy table name. + $indexTable = $this->getTable('catalog_category_product_index'); + + try { + // Retrieve table name for the current store Id from the TableMaintainer. + $tableMaintainer = $this->objectManager->get(\Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer::class); + $indexTable = $tableMaintainer->getMainTable($storeId); + } catch (\Exception $exception) { + // Occurs in Magento version where TableMaintainer is not implemented. Will default to legacy table. + } + + return $indexTable; + } } diff --git a/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Indexer/Fulltext/Datasource/CategoryData.php b/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Indexer/Fulltext/Datasource/CategoryData.php index 8cc5f5ec6..9951ac5d9 100644 --- a/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Indexer/Fulltext/Datasource/CategoryData.php +++ b/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Indexer/Fulltext/Datasource/CategoryData.php @@ -21,7 +21,6 @@ use Magento\Store\Model\StoreManagerInterface; use Smile\ElasticsuiteCatalog\Model\ResourceModel\Eav\Indexer\Indexer; use Magento\Framework\ObjectManagerInterface; -use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer; /** * Categories data datasource resource model. @@ -173,10 +172,15 @@ protected function getEavConfig() */ protected function getCategoryProductIndexTable($storeId) { - $indexTable = 'catalog_category_product_index'; - - if ($tableMaintainer = $this->objectManager->get(TableMaintainer::class)) { - $indexTable = $tableMaintainer->getMainTable($storeId); + // Init table name as legacy table name. + $indexTable = $this->getTable('catalog_category_product_index'); + + try { + // Retrieve table name for the current store Id from the TableMaintainer. + $tableMaintainer = $this->objectManager->get(\Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer::class); + $indexTable = $tableMaintainer->getMainTable($storeId); + } catch (\Exception $exception) { + // Occurs in Magento version where TableMaintainer is not implemented. Will default to legacy table. } return $indexTable;