Adding new column in Sales Order View Items in Magento Admin

前端 未结 6 1654
难免孤独
难免孤独 2021-02-06 17:12

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.

相关标签:
6条回答
  • 2021-02-06 17:23

    I've no magento installation available, but I have some ideas. Maybe the column is not defined inside a template file (phtml), but inside a xml layout file. Just search in the layout/sales.xml file.

    And maybe you have not disabled the magento cache, that's why you don't see any changes.

    0 讨论(0)
  • 2021-02-06 17:25

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

    app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml

    These files are useful.

    0 讨论(0)
  • 2021-02-06 17:34

    http://magentocoder.jigneshpatel.co.in/create-custom-reports-in-magento-admin/

    Should get you most of the way.

    0 讨论(0)
  • 2021-02-06 17:36

    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.

    0 讨论(0)
  • 2021-02-06 17:40

    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.
    0 讨论(0)
  • 2021-02-06 17:41

    Admin grids are ofter controlled by their block. For sales it's the Mage_Adminhtml_Block_Sales_Order_Grid class

    modifying/overriding method _prepareColumns() should do the trick

    0 讨论(0)
提交回复
热议问题