I'm trying to show additional column in the order view -> information
page this is the url page : rootDomain/admin_an2/sales/order/view/order_id/40/key
.
From what I understand this data is coming from the sales_order_item
table, now I have added additional column to that table called expected_delivery_time
But I don't know how can show it there?
I found out that this UI is created from here : `/rootProject/vendor/magento/module-sales/view/adminhtml/templates/order/view/items.phtml
<?php
/**
* @var \Magento\Sales\Block\Adminhtml\Order\View\Items $block
*/
$_order = $block->getOrder() ?>
<div class="admin__table-wrapper">
<table class="data-table admin__table-primary edit-order-table">
<thead>
<tr class="headings">
<?php $i = 0;
$columns = $block->getColumns();
$lastItemNumber = count($columns) ?>
<?php foreach ($columns as $columnName => $columnTitle):?>
<?php $i++; ?>
<th class="col-<?php /* @noEscape */ echo $columnName ?><?php /* @noEscape */ echo ($i === $lastItemNumber ? ' last' : '')?>"><span><?php /* @noEscape */ echo $columnTitle ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<?php $_items = $block->getItemsCollection();?>
<?php $i = 0; foreach ($_items as $_item):?>
<?php if ($_item->getParentItem()) {
continue;
} else {
$i++;
}?>
<tbody class="<?php /* @noEscape */ echo $i%2 ? 'even' : 'odd' ?>">
<?php echo $block->getItemHtml($_item) ?>
<?php echo $block->getItemExtraInfoHtml($_item) ?>
</tbody>
<?php endforeach; ?>
</table>
</div>
I tried to find a block Items
class.
I get the getColumn()
:
/**
* @return array
*/
public function getColumns()
{
$columns = array_key_exists('columns', $this->_data) ? $this->_data['columns'] : [];
return $columns;
}
How to add my column to the $this->_data['columns']
? getting stuck here.
any idea?
Best Answer
After a several hours finally I have found the solution. Here is the step :
create layout
view/adminhtml/layout/sales_order_view.xml
like this :create plugin to override the method for showing the expected delivery date :
use\Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer
etc config :
that's it.