3

Can anyone let me know how to remove existing columns from Admin->Sales->Order->View->Items Grid? Moreover, I also need to add a new column in the same grid, please find attached screenshot for your reference: order view page items grid

I have tried to override vendor/magento/module-sales/view/adminhtml/layout/sales_order_view.xml file in my module and removed some of the columns but it throws the following error.

[2018-10-02 09:18:58] main.CRITICAL: The element 'order_items' already has a child with alias 'default' {"exception":"[object] (Magento\\Framework\\Exception\\LocalizedException(code: 0): The element 'order_items' already has a child with alias 'default' at /var/www/html/bannerbuzzmagento2/vendor/magento/framework/Data/Structure.php:611)"} []
[2018-10-02 09:18:59] main.CRITICAL: Invalid block type: Namespace\Module\Block\Adminhtml\DefaultRenderer {"exception":"[object] (Magento\\Framework\\Exception\\LocalizedException(code: 0): Invalid block type: Namespace\\Module\\Block\\Adminhtml\\DefaultRenderer at /var/www/html/bannerbuzzmagento2/vendor/magento/framework/View/Layout/Generator/Block.php:275, ReflectionException(code: -1): Class Namespace\\Module\\Block\\Adminhtml\\DefaultRenderer does not exist at /var/www/html/bannerbuzzmagento2/vendor/magento/framework/Code/Reader/ClassReader.php:19)"} []
1
  • I am talking about Order View page items grid not order grid. Oct 2, 2018 at 9:30

3 Answers 3

3

You can Try this its work for me.

Add sales_order_view.xml file in your custom module Packagename/Modulename/view/adminhtml/layout and remove column as per your requirement.

<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="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="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>
1

You need to override sales_order_view in your theme or in your module.

vendor/magento/module-sales/view/adminhtml/layout/sales_order_view.xml

<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="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="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"/>

After override you can add, edit or delete column as per your requirement.

Still you have any query let me know.

7
  • I can add new column by this way but i cannot remove column, please let me know how to achieve that? Oct 2, 2018 at 12:27
  • Please try once remove column in core and check after that it's working fine. I have already checked it. Oct 2, 2018 at 12:29
  • directly with core? Oct 2, 2018 at 12:58
  • Not directly in core i have giving an example you have to override it into theme which i have already mention in my answer's first line. Oct 8, 2018 at 6:06
  • You need to check it. Oct 8, 2018 at 6:06
1

I finally got solution, I had to override <referenceContainer name="left"> section from sales_order_view.xml in my custom module and put only necessary columns in it.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .