The idea behind it, is some how keep a track of what's catalog rules are indexed. If i can run the index of a single rule in a module i can then save some logs and also do them in blocks of 10 for example
It is possible to run the reindex of a single catalog price rule in a module controller for example?
1 Answer
Extending upon this answer, here are some more details on how to reindex, how to get the IDs, and reindexing only what is needed.
ReindexAll can add a lot of overhead, especially on very large catalogs/sites.
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Indexer\Model\IndexerFactory $indexerFactory,
\Magento\Indexer\Model\Indexer\CollectionFactory $indexerCollectionFactory
) {
$this->eavConfigFactory = $eavConfigFactory;
$this->eavSetupFactory = $eavSetupFactory;
$this->customerSetupFactory = $customerSetupFactory;
$this->indexerFactory = $indexerFactory;
$this->indexerCollectionFactory = $indexerCollectionFactory;
parent::__construct($context);
}
Then, when you want to use it:
public function ensureIndexersAreReady()
{
$indexer = $this->indexerFactory->create();
$indexerCollection = $this->indexerCollectionFactory->create();
$ids = $indexerCollection->getAllIds();
foreach ($ids as $id) {
$idx = $indexer->load($id);
if ($id == 'catalogrule_product') {
$idx->reindexAll($id); // this reindexes all
//$idx->reindexRow($id); // or you can use reindexRow according to your need
}
}
}
-
What is $idx? Magento\Indexer\Model\IndexerFactory? And what ID should be passed to reindexRow? A Rule ID? Jun 7, 2018 at 10:08
-
Answer updated can you check please ?– user68116Jun 7, 2018 at 10:10