1

How can we add new column with custom data in the “Order Export CSV” like discount amount, coupon code, Product Attributes?

Vishal Sanwar
  • 59
  • 1
  • 1
  • 10
  • what class method is called when the "Export" button is clicked? The button has this attribute onclick="applyOption;", but I am not able to figrure out what php file is called ultimatley. data-bind="click: applyOption, i18n: 'Export'" Can you please help me out? – Vishal Sanwar Jan 29 '18 at 09:05
  • after that it calls the below controller : /admin/mui/export/gridToCsv/ URL is : http://localhost/magento217/admin/mui/export/gridToCsv/key/?filters%5Bplaceholder%5D=true&search=&namespace=sales_order_grid&selected%5B%5D=3&selected%5B%5D=2 I found the code under the controller is : public function execute() { return $this->fileFactory->create('export.csv', $this->converter->getCsvFile(), 'var'); } Now I am stuck here. – Vishal Sanwar Jan 29 '18 at 09:52

1 Answers1

0

I found solution by myself spend few hours on it. Below steps will clear solution.

1) Create New Column in below xml

vendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml

<column name="custom_product_name" class="Magento\Sales\Ui\Component\Listing\Column\Price">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">textRange</item>
            <item name="visible" xsi:type="boolean">false</item>
            <item name="label" xsi:type="string" translate="true">Custom Product Name</item>
        </item>
    </argument>
</column>

2) alter sales_order_grid table, (Using upgrade Schema)

ALTER TABLE `sales_order_grid` ADD `custom_product_name` VARCHAR( 255 ) NOT NULL ;

Note: column name of table and column name in XML should be same.

3) Run Observer after the place order. StackOverflow - Which observer to use after success order on Magento 2?

Important : DO NOT work in core files, you have to override all the files in your module.

Adeel
  • 2,901
  • 7
  • 24
  • 34
Vishal Sanwar
  • 59
  • 1
  • 1
  • 10