@Sunil PatelHi, I tried to see how your solution works to see which one could be best, but I'm havin a problem, blank page :
mod_fcgid: stderr: PHP Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 134217736 bytes)
Though I only have one order in sandbox site.
Any idea on what could be wrong ?
I can see why I get the error, there are some errors in your code like :
& in :
foreach ($dataSource['data']['items'] as & $item) {
= // value; in :
$dataSource['data']['items'][$i]['tax_amount'] = // value;
...
As for now I cannot manage to make it work
OK, I get it quite better, I have to replace
// valuewith the tax amount, but that's where I'm stuck, can not retrieve tax_amount from orders table.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Vendor\Name\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 TaxAmount
* @package GenteRecInc\AnkaaCms\Ui\Component\Listing\Column
*/
class TaxAmount extends Column
{
/**
* @var OrderRepositoryInterface
*/
protected $_orderRepository;
/**
* @var SearchCriteriaBuilder
*/
protected $_searchCriteria;
/**
* TaxAmount constructor.
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param OrderRepositoryInterface $orderRepository
* @param SearchCriteriaBuilder $criteria
* @param array $components
* @param array $data
*/
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);
}
/**
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$order = $this->_orderRepository->get($item["entity_id"]);
$item['tax_amount'] = $order->getData("tax_amount");
}
}
return $dataSource;
}
}