Question

I need to add the additional column in the table the field is already in the table i don't want to create it. Field name in table is additional_data in sales_order_item table. The below showed image is admin panel order items listing image.

Now the line items showing Order Line item

Need Output as Order Line item need to show

After updating with below answer with my coulumn name Tax code and added the block tax_code.phtml

In sales_order_view.xml

<referenceContainer name="left">
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Tabs" name="sales_order_tabs">
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" name="order_tab_info" template="Magento_Sales::order/view/tab/info.phtml">
                    <block class="Magento\Sales\Block\Adminhtml\Order\View\Messages" name="order_messages"/>
                    <block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
                        <container name="extra_customer_info"/>
                    </block>
                    <container name="order_additional_info"/>
                    <block class="Magento\Sales\Block\Adminhtml\Order\View\Items" name="order_items" template="Magento_Sales::order/view/items.phtml">
                        <arguments>
                            <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="taxcode" xsi:type="string" translate="true">Tax Code</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>
                            </argument>
                        </arguments>
                        <block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" name="default_order_items_renderer" template="Magento_Sales::order/view/items/renderer/default.phtml">
                            <arguments>
                                <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="taxcode" xsi:type="string" translate="false">col-taxcode</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>
                                </argument>
                            </arguments>
                        </block>
                        <block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
                        <block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>
                        <block class="Magento\Framework\View\Element\Text\ListText" name="order_item_extra_info"/>
                        <block class="Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn" name="tax_code" template="Magento_Sales::items/column/tax_code.phtml" group="column" />

                    </block>

                    <container name="payment_additional_info" htmlTag="div" htmlClass="order-payment-additional" />
                    <block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
                    <block class="Magento\Sales\Block\Adminhtml\Order\View\History" name="order_history" template="Magento_Sales::order/view/history.phtml"/>
                    <block class="Magento\Backend\Block\Template" name="gift_options" template="Magento_Sales::order/giftoptions.phtml">
                        <block class="Magento\Sales\Block\Adminhtml\Order\View\Giftmessage" name="order_giftmessage" template="Magento_Sales::order/view/giftmessage.phtml"/>
                    </block>
                    <block class="Magento\Sales\Block\Adminhtml\Order\Totals" name="order_totals" template="Magento_Sales::order/totals.phtml">
                        <block class="Magento\Sales\Block\Adminhtml\Order\Totals\Tax" name="tax" template="Magento_Sales::order/totals/tax.phtml"/>
                    </block>
                </block>
                <action method="addTab">
                    <argument name="name" xsi:type="string">order_info</argument>
                    <argument name="block" xsi:type="string">order_tab_info</argument>
                </action>
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Invoices" name="sales_order_invoice.grid.container"/>
                <action method="addTab">
                    <argument name="name" xsi:type="string">order_invoices</argument>
                    <argument name="block" xsi:type="string">sales_order_invoice.grid.container</argument>
                </action>
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Creditmemos" name="sales_order_creditmemo.grid.container"/>
                <action method="addTab">
                    <argument name="name" xsi:type="string">order_creditmemos</argument>
                    <argument name="block" xsi:type="string">sales_order_creditmemo.grid.container</argument>
                </action>
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Shipments" name="sales_order_shipment.grid.container"/>
                <action method="addTab">
                    <argument name="name" xsi:type="string">order_shipments</argument>
                    <argument name="block" xsi:type="string">sales_order_shipment.grid.container</argument>
                </action>
                <action method="addTab">
                    <argument name="name" xsi:type="string">order_history</argument>
                    <argument name="block" xsi:type="string">Magento\Sales\Block\Adminhtml\Order\View\Tab\History</argument>
                </action>
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Transactions" name="sales_transactions.grid.container"/>
                <action method="addTab">
                    <argument name="name" xsi:type="string">order_transactions</argument>
                    <argument name="block" xsi:type="string">sales_transactions.grid.container</argument>
                </action>
            </block>
        </referenceContainer>

In template/items/columns/tax_code.phtml

<span><?= /* @escapeNotVerified */ __($block->getItem()->getData('additional_data')) ?></span>

enter image description here

Was it helpful?

Solution

Update your layout file (overrite defaul.phml)

<referenceContainer name="left">
    <block class="Magento\Sales\Block\Adminhtml\Order\View\Tabs" name="sales_order_tabs">
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" name="order_tab_info" template="Magento_Sales::order/view/tab/info.phtml">
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Messages" name="order_messages"/>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
                <container name="extra_customer_info"/>
            </block>
            <container name="order_additional_info"/>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Items" name="order_items" template="Magento_Sales::order/view/items.phtml">
                <arguments>
                    <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="additional-data" xsi:type="string" translate="true">Tax Code</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>
                    </argument>
                </arguments>
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" name="default_order_items_renderer" template="VendoreName_ModuleNaem::order/view/items/renderer/default.phtml"><!-- here add your module name -->
                    <arguments>
                        <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="additional-data" xsi:type="string" translate="false">col-taxcode</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>
                        </argument>
                    </arguments>
                </block>
                <block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
                <block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>
                <block class="Magento\Framework\View\Element\Text\ListText" name="order_item_extra_info"/>
                <block class="Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn" name="tax_code" template="Magento_Sales::items/column/tax_code.phtml" group="column" />

            </block>

            <container name="payment_additional_info" htmlTag="div" htmlClass="order-payment-additional" />
            <block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\History" name="order_history" template="Magento_Sales::order/view/history.phtml"/>
            <block class="Magento\Backend\Block\Template" name="gift_options" template="Magento_Sales::order/giftoptions.phtml">
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Giftmessage" name="order_giftmessage" template="Magento_Sales::order/view/giftmessage.phtml"/>
            </block>
            <block class="Magento\Sales\Block\Adminhtml\Order\Totals" name="order_totals" template="Magento_Sales::order/totals.phtml">
                <block class="Magento\Sales\Block\Adminhtml\Order\Totals\Tax" name="tax" template="Magento_Sales::order/totals/tax.phtml"/>
            </block>
        </block>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_info</argument>
            <argument name="block" xsi:type="string">order_tab_info</argument>
        </action>
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Invoices" name="sales_order_invoice.grid.container"/>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_invoices</argument>
            <argument name="block" xsi:type="string">sales_order_invoice.grid.container</argument>
        </action>
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Creditmemos" name="sales_order_creditmemo.grid.container"/>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_creditmemos</argument>
            <argument name="block" xsi:type="string">sales_order_creditmemo.grid.container</argument>
        </action>
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Shipments" name="sales_order_shipment.grid.container"/>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_shipments</argument>
            <argument name="block" xsi:type="string">sales_order_shipment.grid.container</argument>
        </action>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_history</argument>
            <argument name="block" xsi:type="string">Magento\Sales\Block\Adminhtml\Order\View\Tab\History</argument>
        </action>
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Transactions" name="sales_transactions.grid.container"/>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_transactions</argument>
            <argument name="block" xsi:type="string">sales_transactions.grid.container</argument>
        </action>
    </block>
</referenceContainer>

After that add this file in your module

app/code/VendoreName/ModuleNaem/view/adminhtml/templates/order/view/items/renderer

default.phtml

<?php $_item = $block->getItem() ?>
<?php $block->setPriceDataObject($_item) ?>
<tr>
    <?php $i = 0;
    $columns = $block->getColumns();
    $lastItemNumber = count($columns) ?>
    <?php foreach ($columns as $columnName => $columnClass) : ?>
        <?php $i++; ?>
        <td class="<?= /* @noEscape */ $columnClass ?><?= /* @noEscape */ ($i === $lastItemNumber ? ' last' : '') ?>">
            <?= $block->getColumnHtml($_item, $columnName) ?>
            <?php
                if ($columnName == "additional-data") {
                    echo $_item->getAdditionalData();
                }

            ?>
        </td>
    <?php endforeach; ?>
</tr>

I Hope This Helps You.

OTHER TIPS

You need to add/create 'sales_order_view.xml' file in your custom module (please create if not exist any) at below path:

app/code/Namespace/Modulename/view/adminhtml/layout/sales_order_view.xml

In this file you need to put below code:

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>      
        <referenceContainer name="left">
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Tabs" name="sales_order_tabs">
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" name="order_tab_info" template="Magento_Sales::order/view/tab/info.phtml">        
                    <block class="Magento\Sales\Block\Adminhtml\Order\View\Items" name="order_items" template="Magento_Sales::order/view/items.phtml">
                        <arguments>
                            <argument name="columns" xsi:type="array">
                                <item name="column_name" xsi:type="string" translate="true">My Column</item>
                            </argument>
                        </arguments>
                        <block class="Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn" name="my_column" template="Namespace_Modulename::mycolumn.phtml" group="column"/> 
                    </block>
                </block>
            </block>
        </referenceContainer>
    </body>
</page> 

Then, you need to create mycolumn.phtml file at below path:

app/code/Namespace/Modulename/view/adminhtml/templates/mycolumn.phtml

In mycolumn.phtml file you can put code like below:

<?php if ($_item = $block->getItem()) : ?>
     <div class="admin__field">
            <div class="admin__field">
                 <span><?= /* @escapeNotVerified */ __($_item->getAdditionalData()) ?></span>
           </div>
    </div>
<?php endif; ?>

That's it! Please check and let me know if you need any further help.

Happy to help!

Thanks,

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top