I have modified the order grid layout by adding this code in:
vendor/magento/module-sales/view/adminhtml/ui_components/salesordergrid.xml
<column name="order_items" class="Magento\Sales\Ui\Component\Listing\Column\Items">
<settings>
<filter>textRange</filter>
<label translate="true">Items</label>
</settings>
</column>
The "item" column is displaying now .
I created a class called
Magento\Sales\Ui\Component\Listing\Column\Items.php
See Below code:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Ui\Component\Listing\Column;
use Magento\Framework\Escaper;
use Magento\Ui\Component\Listing\Columns\Column;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory;
/**
* Class Items
*/
class Items extends Column
{
/**
* @var Escaper
*/
protected $escaper;
/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param Escaper $escaper
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
Escaper $escaper,
array $components = [],
array $data = []
) {
$this->escaper = $escaper;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$item[$this->getData('name')] = "test";/*nl2br($this->escaper->escapeHtml($item[$this->getData('name')]));*/
}
}
return $dataSource;
}
}
How do I get access to the product data for the current order to display it in the column ?
Right now I just have a place holder string : "test" outputted for every row.
$item[$this->getData('name')] = "test";
What class/method do I need to call to output the product data instead e.g.
$item[$this->getData('name')]
= function that returns order product data .