1

i am looking for a way to change the mode of Magento 2 Indexer.

The way it was done in Mage 1 :

$pCollection = Mage::getSingleton('index/indexer')->getProcessesCollection();

        foreach ($pCollection as $process) {
            $process->setMode(Mage_Index_Model_Process::MODE_MANUAL)->save();
            //$process->setMode(Mage_Index_Model_Process::MODE_REAL_TIME)->save();
        }

Is this even possible in Magento 2 ?

2

Now in Magento 2 we have two modes: "on save" and "on schedule".

See example code that switch fulltext indexer to on save mode.

    /** @var \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry */
    $indexerRegistry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
        ->get(\Magento\Framework\Indexer\IndexerRegistry::class);
    $indexerRegistry->get(Fulltext::INDEXER_ID)->setScheduled(false);
| improve this answer | |
  • i want to change the mode of all indexers to "on schedule" can u give me that part ? – Me7z Oct 13 '16 at 7:38
2

You can set the mode via command line

php bin/magento indexer:set-mode {realtime|schedule} [indexer-name]

“realtime” is equal to “Update on Save” and “schedule” is equal to “Update by Schedule”.

| improve this answer | |
0

You can use this code based on : Magento\Indexer\Controller\Adminhtml\Indexer\MassChangelog

foreach ($indexerIds as $indexerId) {
    /** @var \Magento\Framework\Indexer\IndexerInterface $model */
    $model = $this->_objectManager->get('Magento\Framework\Indexer\IndexerRegistry')->get($indexerId);
    $model->setScheduled(true);
}

IndexerIds can be retrieve on the code or by Magento command :

design_config_grid                       Design Config Grid
customer_grid                            Customer Grid
catalog_category_product                 Category Products
catalog_product_category                 Product Categories
catalog_product_price                    Product Price
catalog_product_attribute                Product EAV
catalogrule_rule                         Catalog Rule Product
catalogrule_product                      Catalog Product Rule
cataloginventory_stock                   Stock
catalogsearch_fulltext                   Catalog Search
targetrule_product_rule                  Product/Target Rule
targetrule_rule_product                  Target Rule/Product
salesrule_rule                           Sales Rule
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.