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>
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. Nov 28, 2018 at 10:08
  • I have added customer listing xml updated question
    – Naveenbos
    Nov 28, 2018 at 10:21
  • @RamkishanSuthar do yo u have nay idea about this?
    – Naveenbos
    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. Nov 28, 2018 at 11:11
  • @RamkishanSuthar so do I have to correct my customer_listing.xml file? for export functionality
    – Naveenbos
    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;
    }
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.