diff -Nuar a/vendor/magento/module-catalog/Observer/CategoryProductIndexer.php b/vendor/magento/module-catalog/Observer/CategoryProductIndexer.php index ca87efaa874..b9b0a205ac4 100644 --- a/vendor/magento/module-catalog/Observer/CategoryProductIndexer.php +++ b/vendor/magento/module-catalog/Observer/CategoryProductIndexer.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace Magento\Catalog\Observer; use Magento\Catalog\Model\Indexer\Category\Product\Processor; +use Magento\Catalog\Model\Indexer\Category\Flat\State as FlatState; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; @@ -22,11 +23,21 @@ class CategoryProductIndexer implements ObserverInterface private $processor; /** + * @var FlatState + */ + private $flatState; + + /** * @param Processor $processor + * @param FlatState $flatState */ - public function __construct(Processor $processor) + public function __construct( + Processor $processor, + FlatState $flatState + ) { $this->processor = $processor; + $this->flatState = $flatState; } /** @@ -35,7 +46,7 @@ class CategoryProductIndexer implements ObserverInterface public function execute(Observer $observer): void { $productIds = $observer->getEvent()->getProductIds(); - if (!empty($productIds) && $this->processor->isIndexerScheduled()) { + if (!empty($productIds) && $this->processor->isIndexerScheduled() && $this->flatState->isFlatEnabled()) { $this->processor->markIndexerAsInvalid(); } }