2

I want to add a custom attribute to the admin customer grid. For that, I have added two attributes using ui_component.

The columns show up in the grid but without data from customer_grid_flat (because Magento 2 uses a flat grid table for retrieving data to the grid).

I found the following answer on StackExchange:

add a custom column in customer grid

According to that, I added an indexer.xml file to my custom module:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
    <indexer id="customer_grid" view_id="customer_dummy" class="Magento\Framework\Indexer\Action\Entity" primary="customer">
        <fieldset name="customer" source="Magento\Customer\Model\ResourceModel\Customer\Collection" provider="Magento\Customer\Model\Indexer\AttributeProvider">
            <field name="webshop" xsi:type="filterable" dataType="int"/>
            <field name="aktiv" xsi:type="filterable" dataType="int"/>
        </fieldset>
    </indexer>
</config>

and executed php bin/magento indexer:reindex customer_grid.

Now, I face two different errors in two different conditions:

  1. Please note above indexer attribute view_id. it is customer_dummy (Which is default to native customer module). if I use the same view_id name in my custom module I get error Customer grid index is locked by another reindex process. Skipping

  2. If I use a different view_id name and execute php bin/magento indexer:reindex customer_grid then it shows view_id (in my case it just dummy) view does not exist.

4

Leaving out view_id seems to work:

<indexer id="customer_grid">

This way, the XML will be merged into the existing indexer instead of defining a new indexer.

  • I had the same issue, and your solution helped me to fix the problem. But in my case, I also have this view_id="dummy" in indexer.xml. but this view_id has always been there since I installed my custom extension, and the error wasn't there in the beginning. So I wonder why this view_id suddenly became a problem? – Magento Learner Mar 9 '18 at 10:48
0

According to that, you can added an indexer.xml file to your custom module:

  <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
<indexer id="customer_grid" class="Magento\Framework\Indexer\Action\Entity" primary="customer">
    <fieldset name="customer" source="Magento\Customer\Model\ResourceModel\Customer\Collection" provider="Magento\Customer\Model\Indexer\AttributeProvider">
        <field name="account_number" xsi:type="filterable" dataType="varchar"/>            
    </fieldset>
</indexer>

Must be check your attribute datatype varchar or text etc..

Need to 'is_used_in_grid' => true and in di.xml add

 <preference for="Magento\Customer\Model\Indexer\Source" type="Magento\Customer\Model\ResourceModel\Customer\Collection" />

OR

<virtualType name="Magento\Customer\Model\Indexer\Source" type="Magento\Customer\Model\ResourceModel\Customer\Collection" />

And It's working.

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.