3

I created a custom column "product_name" in sales/order grid,

When I am sorting this column grid showing error:

Item (Magento\Framework\View\Element\UiComponent\DataProvider\Document) with the same id "146" already exist

My collection code is :

 parent::_initSelect();
        $joinTable = $this->getTable('mg_dispatch_date');
        $joinTable2 =$this->getTable('customer_entity_varchar');
        $joinTable3 = $this->getTable('catalog_product_entity_varchar');
        $this->getSelect()->join($joinTable . ' as mdd', 'main_table.entity_id = mdd.order_id', array('*')); 
        $this->getSelect()->join($joinTable2. ' as fn', 'main_table.customer_id = fn.entity_id and fn.attribute_id = 177',array('value'));
       $this->getSelect()->join($joinTable3.' as cpev','main_table.entity_id = cpev.entity_id', array('*'));  
        return $this;

and sales_order_item.xml code is :

<column name="product_name" class="Magecoder\Customerref\Ui\Component\Listing\Column\Productname">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">

            <item name="filter" xsi:type="boolean">false</item>
            <item name="sortable" xsi:type="boolean">true</item>
                    <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                    <item name="visible" xsi:type="boolean">true</item> 
                    <item name="label" xsi:type="string" translate="true">Product Name</item>
                </item>
            </argument>
        </column>

Please help is anyone have suggestion, Thanks in Advance.

1 Answer 1

0

There are not the filters by product attribute_id and store_id in the query. It is the reason for result has several rows for each product.

Also, the order can be contains many products - you can use GROUP_CONCAT for compose all product name in one row for each order.

If you don't want to show all order's products for the order row you can add

$this->getSelect()->group('main_table.entity_id');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.