Showing results for 
Search instead for 
Did you mean: 

adding new column in admin/sales/order/ view page

adding new column in admin/sales/order/ view page

I tried this code but it is giving a column at the end of the table, I want this column at the starting of the table (product image)

file : app\code\Product\image\view\adminhtml\layout\sales_order_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
     <referenceBlock name="order_items">
             <argument name="columns" xsi:type="array">
                  <item name="custom_item_column" xsi:type="string" translate="true">Product Image</item>
         <referenceBlock name="default_order_items_renderer">
                    <argument name="columns" xsi:type="array">
                        <item name="product_img" xsi:type="string" translate="true">product_img</item>
             <action method="setTemplate">
                 <argument name="template" translate="true" xsi:type="string">Product_Image::order/view/items/renderer/default.phtml</argument>
file: app\code\Product\image\view\adminhtml\templates\order\view\items\renderer\default.html
<?php /** @var \Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer $block */ ?>
<?php $_item = $block->getItem() ?>
<?php $block->setPriceDataObject($_item) ?><tr>
    <?php $i = 0;
    $columns = $block->getColumns();
    $lastItemNumber = count($columns) ?>    <td>
        <?php $product =  $_item->getProduct();?>
        <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();?>

        <?php  $imagewidth=200;
        $imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image');
        $image_url = $imageHelper->init($product, 'small_image')->setImageFile($product->getSmallImage())->resize($imagewidth, $imageheight)->getUrl();
        ?>        <img src="<?php echo $image_url;?>" />
    <?php foreach ($columns as $columnName => $columnClass):?>
        <?php $i++; ?>        <td class="<?= /* @noEscape */ $columnClass ?><?= /* @noEscape */ ($i === $lastItemNumber ? ' last' : '') ?>"><?= /* @escapeNotVerified */ $block->getColumnHtml($_item, $columnName) ?></td>
    <?php endforeach; ?></tr>



<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Product_Image">
            <module name="Magento_Sales" />

it is working but the thing is i want the product image column at the starting of the column in sales/order/view/ page



Re: adding new column in admin/sales/order/ view page

Hello @shanali35k17e1,


Greetings of the day!


For adding the table header and its value add layout sales_order_view.xml in your theme or module with a new argument.

            <argument name="columns" xsi:type="array">
                <item name="product" xsi:type="string" translate="true">Product</item>
                <item name="status" xsi:type="string" translate="true">Item Status</item>
                <item name="price-original" xsi:type="string" translate="true">Original Price</item>
                <item name="price" xsi:type="string" translate="true">Price</item>
                <item name="ordered-qty" xsi:type="string" translate="true">Qty</item>
                <item name="subtotal" xsi:type="string" translate="true">Subtotal</item>
                <item name="tax-amount" xsi:type="string" translate="true">Tax Amount</item>
                <item name="tax-percent" xsi:type="string" translate="true">Tax Percent</item>
                <item name="discont" xsi:type="string" translate="true">Discount Amount</item>
                <item name="total" xsi:type="string" translate="true">Row Total</item>
                <item name="repair" xsi:type="string" translate="true">Repair</item>
        <block class="Namespace\Module\Block\Adminhtml\DefaultRenderer" as="default" template="Magento_Sales::order/view/items/renderer/default.phtml">
            <argument name="columns" xsi:type="array">
                <item name="product" xsi:type="string" translate="false">col-product</item>
                <item name="status" xsi:type="string" translate="false">col-status</item>
                <item name="price-original" xsi:type="string" translate="false">col-price-original</item>
                <item name="price" xsi:type="string" translate="false">col-price</item>
                <item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
                <item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
                <item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
                <item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
                <item name="discont" xsi:type="string" translate="false">col-discont</item>
                <item name="total" xsi:type="string" translate="false">col-total</item>
                <item name="repair" xsi:type="string" translate="false">col-repair</item>

Add a new column with name repair, now you have to add value to that column. So you have to override the '\Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer' file in your block and in the getColumnHtml() method you have to add your value for that column.


I hope this will help you to solve your issue.

If not, feel free to contact us.


If solved, Click KUDOS and accept it as a solution.

Thank you!

Re: adding new column in admin/sales/order/ view page



Thanks for the insight - some good learnings here.


I'm wondering if it's possible to get a step by step guide on how to override the file and add a value to the newly created column?


Thanks in advance

Re: adding new column in admin/sales/order/ view page

Thanks for sharing, I found a lot of interesting information here. A really good post, very thankful and helpful that you will write many more posts like this one.


AutoZone Employee Login