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.

Manashvi Birla
8,8739 gold badges29 silver badges53 bronze badges
asked Dec 29, 2016 at 10:41

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');

answered Jun 12, 2019 at 14:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.