This issue appeared because dynamic category reindexer loaded categories for just 2 stores: base store (0) and default store (1) and since categories wasn’t enabled there, reindexer just skipped these categories.
--- Model/Indexer/DynamicCategory/Action/DoReindex.php
+++ Model/Indexer/DynamicCategory/Action/DoReindex.php
@@ -89,7 +89,8 @@
foreach ($this->storeManager->getStores() as $store) {
$storeId = (int) $store->getId();
- $categories = $this->getCategories((int) $store->getRootCategoryId(), $categoryIds);
+
+ $categories = $this->getCategories((int) $store->getRootCategoryId(), $categoryIds, $storeId);
foreach ($categories as $categoryId => $dynamicConditions) {
$amastyRule->setConditions(null);
$amastyRule->setConditionsSerialized($dynamicConditions);
@@ -120,9 +121,10 @@
/**
* @return array ['category_id' => 'conditions', ...]
*/
- private function getCategories(int $rootCategoryId, ?array $categoryIds): array
+ private function getCategories(int $rootCategoryId, ?array $categoryIds, $storeId): array
{
$categoryCollection = $this->categoryCollectionFactory->create();
+ $categoryCollection->setStoreId($storeId);
$categoryCollection->addAttributeToFilter('amlanding_is_dynamic', 1);
$categoryCollection->addFieldToFilter([
['attribute' => 'path', 'like' => '1/' . $rootCategoryId . '/%'],
--- Model/Indexer/DynamicCategory/Indexer/SyncIndexedData.php
+++ Model/Indexer/DynamicCategory/Indexer/SyncIndexedData.php
@@ -21,6 +21,7 @@
use Magento\Framework\DB\Adapter\DeadlockException;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\DB\Select;
+use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;
/**
@@ -34,6 +35,11 @@
private $getStoresForRootCategory;
/**
+ * @var StoreManagerInterface
+ */
+ private $storeManager;
+
+ /**
* @var ResourceConnection
*/
private $resourceConnection;
@@ -75,6 +81,7 @@
CategoryIndex $categoryIndex,
SortIds $sortIds,
LoggerInterface $logger,
+ StoreManagerInterface $storeManager,
?DependencyModifier $dependencyModifier = null // TODO move to not optional
) {
$this->getStoresForRootCategory = $getStoresForRootCategory;
@@ -83,6 +90,7 @@
$this->categoryIndex = $categoryIndex;
$this->sortIds = $sortIds;
$this->logger = $logger;
+ $this->storeManager = $storeManager;
$this->dependencyModifier = $dependencyModifier ?? ObjectManager::getInstance()->get(DependencyModifier::class);
}
@@ -101,7 +109,19 @@
}
$isModified = false;
- foreach ($this->getCategories($categoryIds) as $categoryId => $categoryData) {
+
+ $categories = [];
+ foreach ($this->storeManager->getStores() as $store) {
+ $storeId = (int)$store->getId();
+ foreach ($this->getCategories($categoryIds, $storeId) as $categoryId => $categoryData) {
+ if (isset($categories[$categoryId])) {
+ continue;
+ }
+ $categories[$categoryId] = $categoryData;
+ }
+ }
+
+ foreach ($categories as $categoryId => $categoryData) {
if ($this->executeCategory($categoryId, $categoryData)) {
$isModified = true;
}
@@ -161,9 +181,10 @@
/**
* @return array ['category_id' => ['amasty_category_product_sort' => value, 'path' => value], ...]
*/
- private function getCategories(?array $categoryIds): array
+ private function getCategories(?array $categoryIds, $storeId): array
{
$categoryCollection = $this->categoryCollectionFactory->create();
+ $categoryCollection->setStoreId($storeId);
$categoryCollection->addAttributeToFilter('amlanding_is_dynamic', 1);
$categoryCollection->addIsActiveFilter();
if ($categoryIds !== null) {