Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding new column in Sales Order View Items in Magento Admin

Tags:

admin

magento

In the admin interface of Magento I need to modify the tables in the Sales / Order / View order so that it shows, besides the products name, their manufacturer as well.

I'm trying to look for the file to modify to make that happen. I thought I would find a section with all the columns that are displayed in app/code/core/Mage/Sales/Block/Order/Item/Renderer/Default.php but by inspecting it there seem to be no reference to the columns/product attributes.

I also tried to modify app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml by changing

<?php echo $this->getColumnHtml($_item, 'name') ?>

into

<?php echo $this->getColumnHtml($_item, 'manufacturer') ?>

but it changed nothing, so I suppose that file is not involved...

Can anybody please point me to the right file to modify?

Thank you!

like image 884
fdierre Avatar asked Nov 28 '22 04:11

fdierre


2 Answers

After quite a lot of browsing through the code and with some help from a collegue, we found out the two file to change for adding a column to such view:

  • app/design/adminhtml/default/default/template/sales/order/view/items.phtml for adding the table header

  • app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml for filling the column with data.

I'm not really experienced with Magento but I guess that, in order to do a "clean job", one should not directly modify those files but override them instead.

EDIT

  • app/design/adminhtml/default/default/template/downloadable/sales/order/view/items/renderer/downloadable.phtml for filling the column with data for downloadable products.
like image 76
fdierre Avatar answered Dec 06 '22 06:12

fdierre


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

<?xml version="1.0"?>
<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>
    <referenceBlock name="order_items">
        <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="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>
            </argument>
        </arguments>
        <block class="Namespace\Module\Block\Adminhtml\DefaultRenderer" as="default" 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="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>
            </argument>
        </arguments>
        </block>   
    </referenceBlock>     
</body>

` I have added new column with name repair. now you have to add value for that column. so you have to override '\Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer' file in your block and in getColumnHtml() method you have to add your value for that column.

like image 37
Khodu Vaishnav Avatar answered Dec 06 '22 07:12

Khodu Vaishnav