How can we add new column with custom data in the “Order Export CSV” like discount amount, coupon code, Product Attributes?
Solved! Go to Solution.
Hello,
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
https://magento.stackexchange.com/questions/162635/which-observer-to-use-after-success-order-on-mage...
Important : DO NOT work in core files, you have to override all the files in your module.
Please let me know if you still found any issue.
Problem solved? Please give kudos and accept answer as Solution.
Thanks & Regards,
Vishal
@vishalsanwar86There is not an easy answer to it. You would have to create your custom module to achieve what exact you are looking for or override the core module to achieve your requirement.
You can also look for order export extension on Marketplace if any of those fulfill your requirement.
Problem solved? Please give kudos and accept answer as Solution.
@Tarandeep Singh I am agree with you It will achieve with a custom module . but I want to know, which controller or Model is used to generate CSV, I will override those classes.
OR
If you provide me proper flow of it, It would be great.
Thanks
Vishal
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'"
after that it calls the below controller :
/admin/mui/export/gridToCsv/
URL is :
http://localhost/magento217/admin/mui/export/gridToCsv/key/7285903361a2ec5c704331f9a8ca060625069c21cb4931a8c33b213178bcc8e7/?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.
Can you please help me out?
Hello,
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
https://magento.stackexchange.com/questions/162635/which-observer-to-use-after-success-order-on-mage...
Important : DO NOT work in core files, you have to override all the files in your module.
Please let me know if you still found any issue.
Problem solved? Please give kudos and accept answer as Solution.
Thanks & Regards,
Vishal
@vishalsanwar86Thank you for sharing your code. This will definitely help someone.
Problem solved? Please give Kudos and accept answer as Solution.