Magento Indexer: How to include it in a few steps?

Learn how to include the Magento indexer

Here the following steps help you how to include indexer to Magento 2,

Step 1: Form indexer class

Step 2: Form etc/indexer.xml files

Get a complete eCommerce package to excel your business greatly with Magento solutions!!!

In order to improve the performance of your store, Magento modifies the products and more. As data changes, the changed data should be refreshed or re-indexed.

Magento Indexer: It all starts here

The Magento database table has a very sophisticated design that stores a lot of business data (including catalog data, price, user, stores, and more). In order to improve the performance of the store, it collects Magento data in the additional tables using encoders.

In this article, I will show you how to include indexer to Magento 2

Form indexer class

<?php

namespace Webnexs\Training\Model\Indexer;

class Custom implements \Magento\Indexer\Model\ActionInterface, \Magento\Framework\Mview\ActionInterface

{

   public function executeFull();  //logic

   public function executeList($ids);   //logic

   public function executeRow($id);   //logic

   public function execute($ids);  //logic

}

Form etc/indexer.xml files

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Indexer/etc/indexer.xsd">

   <indexer id="Webnexs_indexer" view_id="Webnexs_indexer" class="Webnexs\Training\Model\Indexer\Custom">

       <title translate="true">Custom Indexer</title>

       <description translate="true">Custom Indexer</description>

   </indexer>

</config>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Mview/etc/mview.xsd">

<view id=" Webnexs_indexer" class="Webnexs\Training\Model\Indexer\Custom" group="indexer">

   <subscriptions>

       <table name="sales_order_flat" entity_column="order_id" />

   </subscriptions>

</view>

Finally, announce the view of the table (Webnexs_indexer) that tracks the table (example: sales table). Please create a file. Please create the file Webnexs / Training / etc / mview.xml:

So when an order is placed, the custom indexer will calculate your logic based on the coding class.

The following steps are a short process that adds a custom Indexer seamlessly. With this guide, you can easily manage custom code on Magento 2. Each store has a custom Indexer for Magento 2 with many attributes

Magento 2 Indexer


Posted

in

, ,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *