Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add new columns to item grid in admin sales_order_view layout #10824

Closed
theodorhanu opened this issue Sep 8, 2017 · 12 comments
Closed
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@theodorhanu
Copy link

I am trying to add a new column to item grid in admin sales/order/view .
The problem is that in the layout the default renderer does not have a name attribute, only the as attribute, thus not allowing to add new column content. Even though I can add new column headers to the layout, using <referenceBlock name="order_items"> directive, I cannot add the column's content using the same aproach.

Preconditions

  1. Magento 2.1.x

Steps to reproduce

  1. Create sales_order_view.xml in custom module's adminhtml layouts folder
  2. Add a column in order_items arguments:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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="test_column" xsi:type="string" translate="true">Test Header</item>
                </argument>
            </arguments>
            <block class="Namespace\Vendor\Block\Adminhtml\Order\Items\Column\TestColumn" name="column_production_id" template="Namespace_Vendor::order/items/column/test_column.phtml" group="column" />
        </referenceBlock>
    </body>
</page>

Expected result

  1. Column content should be displayed according to test_column.phtml

Actual result

  1. Only column headers are added

There should be posibility to add cell renderer using <referenceBlock name="default"> directive, like column addition.
The only solution I find is adding an afterGetColumns plugin to Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer, solutions which does not seem so elegant to me.

@magento-engcom-team magento-engcom-team added G1 Passed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed G1 Passed labels Sep 8, 2017
@okorshenko okorshenko added the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Sep 14, 2017
@Zefiryn
Copy link
Contributor

Zefiryn commented Sep 17, 2017

I am working on it

@magento-engcom-team
Copy link
Contributor

@theodorhanu thank you for your bug report.
We've created internal ticket MAGETWO-75303 to track progress on the issue

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Sep 19, 2017
magento-team pushed a commit that referenced this issue Sep 23, 2017
…block #10936

 - Merge Pull Request #10936 from Zefiryn/magento2:10824
 - Merged commits:
   1. 7c6ff6f
@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-75321

@hervebackstage
Copy link

I can give a go at this one

@hatimeria-artur-jewula
Copy link
Contributor

It's already fixed and merged into develop branch

@okorshenko
Copy link
Contributor

@hervebackstage it would be great to backport this fix to 2.2-develop branch

@hatimeria-artur-jewula
Copy link
Contributor

@hervebackstage you can also try to find all places with missing name and add test to make sure no new blocks like that are added.

magento-team pushed a commit that referenced this issue Sep 29, 2017
…id default renderer block #11076

 - Merge Pull Request #11076 from gsomoza/magento2:10824-2.2
 - Merged commits:
   1. 66d8857
magento-team pushed a commit that referenced this issue Sep 29, 2017
@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-80102

@okorshenko
Copy link
Contributor

Hi @theodorhanu the issue has been fixed in #11076 and will be available in 2.2.1

@okorshenko okorshenko added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Sep 29, 2017
@pptyasar
Copy link

How to make as first column in table @theodorhanu

@VadimLugovoy
Copy link

How to make as first column in table @theodorhanu

Does it possible to set position of the adding custom column?

@theodorhanu
Copy link
Author

theodorhanu commented Apr 29, 2020

It should be possible by adding an afterGetColumns plugin for these two classes
Magento\Sales\Block\Adminhtml\Order\View\Items and Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer and reorder columns based on your needs.

In plugin you can add something like this (should be same for both plugins, only injected class should be changed ):
Add this to app/code/Vendor/Module/etc/adminhtml/di.xml file:

<type name="Magento\Sales\Block\Adminhtml\Order\View\Items">
        <plugin sortOrder="1" name="your-items-plugin-name" type="Vendor\Module\Plugin\Block\Adminhtml\Order\View\ItemsPlugin" />
    </type>

file: app/code/Vendor/Module/Plugin/Block/Adminhtml/Order/View/ItemPlugin.php:

<?php
/**
 * @author 		Theodor Flavian Hanu
 */
namespace Vendor\Module\Plugin\Block\Adminhtml\Order\View;

class ItemsPlugin
{
    public function afterGetColumns(\Magento\Sales\Block\Adminhtml\Order\View\Items $subject, $result) {
        
        $result = uasort($result, function($a, $b){
            //if($a matches condition) return -1;
            //if($b matches condition ) return 1;
            //otherwise keep original order
            return 0;
        });
        return $result;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

9 participants