- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Getting the ordered product and quantity in the Order Grid but empty values in the CSV, Magento 2.3
I have created a php file in ui>component>listing>column> Product.php
<?php namespace Custom\AddOrderInfo\Ui\Component\Listing\Column; use \Magento\Sales\Api\OrderRepositoryInterface; use \Magento\Framework\View\Element\UiComponent\ContextInterface; use \Magento\Framework\View\Element\UiComponentFactory; use \Magento\Ui\Component\Listing\Columns\Column; use \Magento\Framework\Api\SearchCriteriaBuilder; class Products extends Column { protected $_orderRepository; protected $_searchCriteria; public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = [], array $data = []) { $this->_orderRepository = $orderRepository; $this->_searchCriteria = $criteria; parent::__construct($context, $uiComponentFactory, $components, $data); } public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as &$items) { $productArr = []; $order = $this->_orderRepository->get($items["entity_id"]); foreach ($order->getAllVisibleItems() as $item) { $productArr[] = $item->getSku(); $item->getSize(); } $items['products'] = implode(' - ', $productArr); } unset($productArr); } return $dataSource; } }
now i am getting the products in the grid and same done for Quantity.
But When exporting the csv file I am getting the null values for product and quantity. Anyone can Help please?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Getting the ordered product and quantity in the Order Grid but empty values in the CSV, Magento
Hi @hira_ahmed ,
For export functionality /vendor/magento/module-ui/Model/Export/ is responsible to export data. so you need to look in to this core file and override below two file and customize as per your requirement.
/vendor/magento/module-ui/Model/Export/ConvertToCsv.php /vendor/magento/module-ui/Model/Export/ConvertToXml.php
You need to override both files.
Then, you need to add custom code on function getCsvFile()
And you need to add Quantity column to sales order grid to render data
For more info: https://magento.stackexchange.com/a/225482
You can also use following Magento extension if need more customised column in the sales order grid.
https://amasty.com/extended-order-grid-for-magento-2.html
I hope it will help you!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Getting the ordered product and quantity in the Order Grid but empty values in the CSV, Magento
With Magento 2 Extended Order Grid extension you can add the following to the order grid:
- product image
- quantity ordered
- product name
- product SKU
But that is far from all features this extension has. If you're like me, a non-technical person, this extension is great since you can configure everything in the admin with no code editing.