0

Magento Customer Grid Custom attribute can't export csv and export xml, Showing error, how to add custom attributes to the customer export.

PHP 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/Magento/vendor/magento/framework/View/Element/UiComponentFactory.php on line 220 and defined in /var/www/Magento/vendor/magento/framework/View/Element/UiComponentFactory.php:172\nStack trace:\n#0 /var/www/Magento/vendor/magento/framework/View/Element/UiComponentFactory.php(220): Magento\Framework\View\Element\UiComponentFactory->argumentsResolver('customer_clv', NULL)\n#1 /var/www/Magento/vendor/magento/module-ui/Component/Listing/Columns/Column.php(77): Magento\Framework\View\Element\UiComponentFactory->create('customer_clv', 'decimal', Array)\n#2 /var/www/Magento/vendor/magento/module-ui/Component/MassAction/Filter.php(182): Magento\Ui\Component\Listing\Columns\Column->prepare()\n#3 /var/www/Magento/vendor/magento/module-ui/Component/MassAction/Filter.php(180): Magento\Ui\Component\MassAction\Filte in /var/www/Magento/vendor/magento/framework/View/Element/UiComponentFactory.php on line 172, referer:

customer_listing.xml file containd below code.

<?xml version="1.0" encoding="UTF-8"?> <!-- /** * Copyright © Ourmodule. All rights reserved. * */
--> <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" class="Magento\Customer\Ui\Component\Listing\Columns">
 <column name="customer_clv" class="Ourmodule\Customer\Ui\Component\Listing\Column\Customerclv">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="filter" xsi:type="boolean">true</item>
 <item name="sorting" xsi:type="string">asc</item>
 <item name="sortable" xsi:type="boolean">true</item>
 <item name="editor" xsi:type="string">text</item>
 <item name="label" xsi:type="string" translate="true">Customer Lifetime Value</item>
 <item name="sortOrder" xsi:type="number">81</item>
 </item>
 </argument>
 </column>
 <column name="predicted_average_profit" class="Ourmodule\Customer\Ui\Component\Listing\Column\Customerclv">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="filter" xsi:type="boolean">true</item>
 <item name="sorting" xsi:type="string">asc</item>
 <item name="sortable" xsi:type="boolean">false</item>
 <item name="editor" xsi:type="string">text</item>
 <item name="label" xsi:type="string" translate="true"> Transaction Value</item>
 <item name="sortOrder" xsi:type="number">82</item>
 </item>
 </argument>
 </column>
 <actionsColumn name="actions" class="Ourmodule\Customer\Ui\Component\Listing\Column\ClvActions">
 <settings>
 <indexField>entity_id</indexField>
 </settings>
 </actionsColumn> 
 </columns> </listing>
Hitesh Koshti
1,4454 gold badges18 silver badges38 bronze badges
asked Nov 28, 2018 at 10:03
7
  • For this, first you need to display your custom_attribute in customer listing. after that when you export it will include that new filed. Commented Nov 28, 2018 at 10:08
  • I have added customer listing xml updated question Commented Nov 28, 2018 at 10:21
  • @RamkishanSuthar do yo u have nay idea about this? Commented Nov 28, 2018 at 11:03
  • I just know that you need to add that attribute in listing then it will include in your csv. Magento includes only those fields which are in visible in grid. Commented Nov 28, 2018 at 11:11
  • @RamkishanSuthar so do I have to correct my customer_listing.xml file? for export functionality Commented Nov 28, 2018 at 11:13

1 Answer 1

2

Please do the following steps.

1.Update your di.xml with following code

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
 
 <type name="Magento\Ui\Model\Export\MetadataProvider">
 <plugin name="custom_customer_export" type="Namespace\Module\Model\Plugin\ModifyGridExportPlugin" sortOrder="1" disabled="false"/>
 </type>

2.In the ModifyGridExportPlugin add below code

<?php
namespace Namespace\Module\Model\Plugin;
use \Magento\Sales\Api\OrderRepositoryInterface;
class ModifyGridExportPlugin
{
 private $logger;
 protected $_resource;
 public function __construct(
 \Psr\Log\LoggerInterface $logger,
 \Magento\Framework\App\ResourceConnection $resource
 ) {
 
 $this->_resource = $resource;
 }
 public function afterGetRowData($subject, $result, $document, $fields, $options)
 {
 $i = 0;
 foreach ($fields as $column) {
 if ($column === 'customer_clv') {
 $customerId=$document['entity_id'];
 $value="Test"
 ................
 ................
 
 $result[$i] = $value;
 }
 if ($column === 'predicted_average_profit') {
 $customerId=$document['entity_id'];
 $value="Test"
 ................
 ................
 
 $result[$i] = $value;
 }
 
 $i++;
 continue;
 }
 return $result;
 }
}
?>
answered Jan 17, 2021 at 11:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.