1

Am re-indexing the Product programmatically every time its name is updated via API. But still, it shows old data. The code which I use to reindex a product,

$indexers = array('catalog_product_category');
$indexer = $this->indexerFactory->create();
foreach($indexers as $indexerId){
    $indexer->load($indexerId)
     ->reindexRow($productid);
}

Also, In Backend, I configured "Update on Save" in Index Management. Is there any other way to do this?

  • It could be that you are running a foreach on a string. try changing the first line to $indexers = array('catalog_product_category'); Also, the catalog_product_category indexer is for category-assignments, you probably need the catalog_product_attribute indexer. Last, with the "Update on Save" option, none of that should be necessary for the name. Have you cleared both the Magento cache and your browser's cache? – mtr.web Apr 5 '18 at 17:14
  • @mtr.web: Thank you for your Quick reply.I made a mistake in the post, Am sending $indexers as an array. Unfortunately, I Could not recommend clearing cache to my customers.While reindexing it takes time to complete, so my product is not coming in frontend for sometime when doing this – Octopus Apr 5 '18 at 17:27
  • Looks like this works: $indexers = [Loading all indexers here]; $indexer = $this->indexerFactory->create(); foreach($indexers as $indexerId){ $indexer->load($indexerId) ->reindexRow($productid); } – Octopus Apr 5 '18 at 17:35

Your Answer

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

Browse other questions tagged or ask your own question.