0

I am uploading a csv file and reading the content of the file and updating the table to update product Stock, also I need to update the stock to sync in to elastic search and for that I need to run the indexer, so I'm doing that programmatically. Take a look

  protected $_indexerFactory;
  public function __construct(\Magento\Indexer\Model\IndexerFactory $indexerFactory)
  {
     $this->_indexerFactory = $indexerFactory;
  }
  private function reindexAll(){
        $indexerIds = array(
            'catalog_category_product',
            'catalog_product_category',
            'catalog_product_price',
            'catalog_product_attribute',
            'cataloginventory_stock',
            'catalogrule_product',
            'catalogsearch_fulltext',
        );
        
        

        foreach ($indexerIds as $key=> $indexerId) {
            echo " create index: ".$indexerId."\n";
            $indexer = $this->_indexerFactory->create();
            $indexer->load($indexerId);
            $indexer->reindexAll();
            
        }
        
    }



0

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.