How to export customers with custom attributes in Magento 2
We continue sifting the endless StackExchange desert in an attempt to discover 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
Below, we shed light on how to fix the problem and export customers with custom attributes in Magento 2. We provide the solution from the StackExchange discussion. You will find a method that helped its author export customers with custom attributes from Magento 2. Note that it requires coding experience to be implemented. Thus, non-technical users won’t be able to satisfy similar business goals with this approach. Therefore, we also deliver an absolutely different way of transferring any custom buyer data from Magento 2 based on the Improved Import & Export module. The tool lets you work with any custom attributes and also delivers numerous other features that simplify data transfer processes.
Table of contents
- 1 The Issue
- 2 What Developers Say
- 3 The Solution
- 4 The Alternative Way
- 5 Magento 2 Customer Import FAQ
- 5.1 How to import and export customers with custom attributes to Magento 2 automatically?
- 5.2 How to import and export customers with custom attributes to Magento 2 from external systems?
- 5.3 How to import and export customers with custom attributes to Magento 2 via API?
- 5.4 How to import and export customers with custom attributes to Magento 2 via ODS files?
- 5.5 How to import and export customers with custom attributes to Magento 2 via XLSX files?
- 5.6 How to import and export customers with custom attributes to Magento 2 via JSON files?
- 5.7 How to import customers with custom attributes to Magento 2 via compressed files?
- 5.8 How to import customers with custom attributes to Magento 2 from Google Sheets?
- 5.9 How to import and export customers with custom attributes to Magento 2 from Dropbox?
- 5.10 How to import and export customers with custom attributes to Magento 2 from Google Drive?
The Issue
1 |
Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Framework\View\Element\UiComponentFactory::argumentsResolver() must be of the type array, null given, called in /var/www/html/tgbl222/vendor/magento/framework/View/Element/UiComponentFactory.php on line 220 and defined in /var/www/html/tgbl222/vendor/magento/framework/View/Element/UiComponentFactory.php:172 Stack trace: #0 /var/www/html/tgbl222/vendor/magento/framework/View/Element/UiComponentFactory.php(220): Magento\Framework\View\Element\UiComponentFactory->argumentsResolver('approve_account', NULL) #1 /var/www/html/tgbl222/vendor/magento/module-ui/Component/Listing/Columns/Column.php(77): Magento\Framework\View\Element\UiComponentFactory->create('approve_account', 'int', Array) #2 /var/www/html/tgbl222/vendor/magento/module-ui/Component/MassAction/Filter.php(184): Magento\Ui\Component\Listing\Columns\Column->prepare() #3 /var/www/html/tgbl222/generated/code/Magento/Ui/Component/MassAction/Filter/Interceptor.php(63): Magento\Ui\Component\MassAction\Filter->p in /var/www/html/tgbl222/vendor/magento/framework/View/Element/UiComponentFactory.php on line 172 |
The attribute has this representation under /app/code/Namespace/Module/view/adminhtml/ui_component/customer_listing.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <columns name="customer_columns"> <column name="approve_account"> <argument name="data" xsi:type="array"> <item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Yesno</item> <item name="config" xsi:type="array"> <item name="filter" xsi:type="string">select</item> <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item> <item name="dataType" xsi:type="string">select</item> <item name="label" xsi:type="string" translate="true">Account Active</item> <item name="sortOrder" xsi:type="number">280</item> </item> </argument> </column> </columns> |
Under /app/code/Namespace/Module/setup/installData.php, the corresponding records look as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/** * {@inheritdoc} */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); /** * Customer attributes */ /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); /** @var $attributeSet AttributeSet */ $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); /** * Create customer attribute account_approve */ $customerSetup->addAttribute(Customer::ENTITY, self::APPROVE_ACCOUNT, [ 'type' => 'int', 'label' => 'Approve Account', 'input' => 'select', "source" => "RBC\Customersegment\Model\Config\Source\CustomerYesNoOptions", 'required' => false, 'default' => '1', 'visible' => true, 'user_defined' => true, 'sort_order' => 215, 'position' => 215, 'system' => false, ]); $approve_account = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, self::APPROVE_ACCOUNT) ->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['adminhtml_customer','customer_account_create','customer_account_edit'], ]); $approve_account->save(); $setup->endSetup(); } |
What Developers Say
Let’s take a look at what other Magento 2 coders think about the problem. According to
The Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$customerSetup->addAttribute(Customer::ENTITY, self::APPROVE_ACCOUNT, [ 'type' => 'static', 'label' => 'Approve Account', 'input' => 'select', "source" => "RBC\Customersegment\Model\Config\Source\CustomerYesNoOptions", 'required' => false, 'default' => '1', 'visible' => true, 'user_defined' => true, 'sort_order' => 215, 'position' => 215, 'system' => false, ]); |
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.
Get Improved Import & Export Magento 2 Extension
Magento 2 Customer Import FAQ
Let’s take a look at other nuances of importing and exporting customer data with custom attributes in Magento 2 with the help of the Improved Import & Export Magento 2 extension.
How to import and export customers with custom attributes to Magento 2 automatically?
If you need to transfer custom customer attributes to or from Magento 2 on a regular basis, it is necessary to install a third-party tool. Unfortunately, the default import/export solutions don’t let you create import jobs that run on schedule. Therefore, we recommend you use the Improved Import & Export extension to import customers with custom attributes to Magento 2 automatically. The extension leverages cron so that you can create a schedule of updates. Next, the module does everything for you importing and exporting data at a specified time.
How to import and export customers with custom attributes to Magento 2 from external systems?
While the default Magento 2 import mechanisms block the import of third-party data that doesn’t follow the system’s requirements, you can use the Improved Import & Export extension to circumvent these restrictions. The module lets you create a mapping scheme matching any external values to the default Magento 2 attributes. Consequently, any external data is easily adapted to the native standards of your e-commerce website. The most intriguing aspect is that you do everything right in your admin. It is also possible to apply mapping to export processes to generate the output your partners require. Thus, the Improved Import & Export extension lets you freely transfer customers with custom attributes from your website.
How to import and export customers with custom attributes to Magento 2 via API?
You need to use the Improved Import & Export Magento 2 extension to import customers with custom attributes to Magento 2 via API. Our extension lets you create the connection between the two systems transferring any data, including customers with custom attributes. Any import job provides an interface where you can specify the parameters necessary to put the two systems together. Note that it is possible to create a bi-directional API connection with our module.
How to import and export customers with custom attributes to Magento 2 via ODS files?
If the custom customer data is stored in an ODS file, you no longer need to convert it to a CSV file to fit the Magento 2 requirements. With the Improved Import & Export Magento 2 extension, it is possible to import ODS files to your ecommerce website without any necessity to run the conversion. You can also export customers with custom attributes using this file format.
How to import and export customers with custom attributes to Magento 2 via XLSX files?
If the custom customer data is stored in an XLSX file, you no longer need to convert it to a CSV file to fit the Magento 2 requirements. With the Improved Import & Export Magento 2 extension, it is possible to import XLSX files to your ecommerce website without any necessity to run the conversion. You can also export customers with custom attributes using this file format.
How to import and export customers with custom attributes to Magento 2 via JSON files?
If the custom customer data is stored in an ODS file, you no longer need to convert it to a CSV file to fit the Magento 2 requirements. With the Improved Import & Export Magento 2 extension, it is possible to import JSON files to your ecommerce website without any necessity to run the conversion. You can also export customers with custom attributes using this file format.
How to import customers with custom attributes to Magento 2 via compressed files?
If the custom customer data is stored in a compressed file, you can also transfer it to Magento 2 with the help of the Improved Import & Export extension. However, there are two requirements to follow. Firstly, your file archive should be in a ZIP or TAR format. Secondly, the compressed data should be stored in a CSV, XML, ODS, XLSX, or JSON file.
How to import customers with custom attributes to Magento 2 from Google Sheets?
If your customers with custom attributes are stored in Google Sheets, it is no longer a problem. There is no need to export it from the service and then transfer the output to Magento 2. The Improved Import & Export lets you move the corresponding information straight from Google Sheets to your e-commerce website. It is only necessary to specify the address of the corresponding data table.
How to import and export customers with custom attributes to Magento 2 from Dropbox?
In addition to Google Sheets, the Improved Import & Export module lets you transfer customers with custom attributes to Magento 2 from Dropbox. Your data should be stored in CSV, XML, ODS, XLSX, or JSON. If it is a compressed file, it should be in a ZIP or TAR format. You can use this file storage as your export destination.
How to import and export customers with custom attributes to Magento 2 from Google Drive?
In addition to Google Sheets and Dropbox, the Improved Import & Export module lets you transfer customers with custom attributes to Magento 2 from Google Drive. Your data should be stored in CSV, XML, ODS, XLSX, or JSON. If it is a compressed file, it should be in a ZIP or TAR format. You can use this file storage as your export destination.