How to export customers with custom attributes in Magento 2

Magento 2 export CLI

We continue sifting the endless StackExchange desert looking for the most helpful discussion. This time, our attention has been captured by an export-related issue. Transferring customer data from Magento 2 has never been a problem. Unless you change something. In this StackExchange discussion, the author created a custom attribute before moving prospect data from the website. However, the default export tool failed. Below, we shed light on how to fix the problem and export customers with custom attributes in Magento 2 more efficiently. 

'

The Issue

Chirag Patel had to create a custom attribute for Magento 2 customers. He named it “Approve Account” and tried to export customers using the default Magento 2 export tool. However, the standard procedure caused a fatal error. You can see its full text below:

The attribute has this representation under /app/code/Namespace/Module/view/adminhtml/ui_component/customer_listing.xml

Under /app/code/Namespace/Module/setup/installData.php, the corresponding records look as follows:

What Developers Say

Let’s take a look at what other Magento 2 coders think about the problem. According to Dhiren Vasoya, you need to create YES/NO options for customers using a boolean attribute. But Chirag Patel says that it doesn’t solve the problem of exporting customers with custom attributes from Magento 2. The question is still unanswered. 

The Solution

Sanjay Chaudhary recommends trying the below code with the static datatype. He also points to the following consequences: 

Although a static datatype in the custom attribute above solves the problem in the grid export, it may throw an error during reindexing since the attribute type is static. The system looks into the customer_entity table for the specific field but it is not available there. So how to export customers with custom attributes in Magento 2 with no errors?

In Chirag Patel’s case, it is necessary to create a field in the customer_entity table. The new custom attribute should be represented there. Also, Sanjay Chaudhary recommends checking the customer_listing layout in the ui_component directory: you should not place the corresponding records about the attribute there. 

Also, avoid adding the field in indexer.xml. Note that it automatically updates data in the customer_grid_flat table.

All these steps look quite confusing and complicated if you’ve never worked with custom attributes. Moreover, a non-technical user won’t solve this issue. So, is there another way to export customers with custom attributes from Magento 2 without errors?

The Alternative Way

The Magento 2 ecosystem is extremely huge. Its market of extensions is so big that you can find literally everything there. For instance, we described how to enhance the Open Source website with Commerce Features here: Magento 2 Heterogeneity. What about exporting customers with custom attributes? 

Although dozens of export tools are available on the Magento Marketplace, there is one solution that’s worth your attention. Meet the Improved Import & Export module. This tool not only can cope with any custom attribute but also simplifies data transfer processes with numerous features.

For instance, you can entirely automate customer export with the help of cron-based schedules. The module offers predefined intervals and lets you customize them. 

At the same time, it delivers numerous mapping features so that you can not only export your custom attributes but also modify them according to the requirements of the connected platform.

Multiple file formats and sources are under your disposal too. While Magento 2 lets you export customers in a CSV file, the Improved Import & Export extension provides the ability to create a JSON or ODS document. It also enables API data transfers for moving data between the two systems directly. 

And don’t forget that the extension works in two directions. It is not only an export solution but also a reliable import tool that lets you integrate Magento 2 with any external system. 

Send us a message to get more information about the module or follow this link to get your copy:

Get Improved Import & Export Magento 2 Extension

'