- Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions
- Magento 2.1.7, PHP 7, MySQL 5.7
- Nginx Server
Steps to reproduce
- I added sku, country_code and product name in the order grid. All works fine but when I filter Orders by Created at it throws following error
- Then filter the orders by created at
- My codes are look like
di.xml
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory"> <plugin name="sales_order_additional_columns" type="Vendor\Sales\Plugin\AddColumnsSalesOrderGridCollection" /> </type>
view/adminhtml/ui-component/sales_order_grid.xml
<column name="sku"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="label" xsi:type="string" translate="true">Sku</item> <item name="filter" xsi:type="string">text</item> <item name="visible" xsi:type="boolean">true</item> </item> </argument> </column> <column name="name"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="label" xsi:type="string" translate="true">Product Name</item> <item name="filter" xsi:type="string">text</item> <item name="visible" xsi:type="boolean">true</item> </item> </argument> </column>
and AddColumnsSalesOrderGridCollection.php
public function aroundGetReport( \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $subject, \Closure $proceed, $requestName ) { $result = $proceed($requestName); if ($requestName == 'sales_order_grid_data_source') { if ($result instanceof $collection) { $collection->getSelect()->join( ["soi" => "sales_order_item"], 'main_table.entity_id = soi.order_id', ['sku' => 'GROUP_CONCAT(DISTINCT soi.sku)', 'name' => 'GROUP_CONCAT(DISTINCT soi.name)' ] )->join( ["soa" => "sales_order_address"], 'main_table.entity_id = soa.parent_id', ['country_id' => 'soa.country_id'] )->group("soa.parent_id"); } return $collection; } }
Expected result
- Orders grid filter at the give range
Actual result
- Following error came
Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous, query was: SELECT COUNT(DISTINCT soa.parent_id) FROM sales_order_grid AS main_table INNER JOIN sales_order_item AS soi ON main_table.entity_id = soi.order_id INNER JOIN sales_order_address AS soa ON main_table.entity_id = soa.parent_id WHERE (created_at >= '2017-07-31 23:00:00') AND (created_at <= '2017-08-25 22:59:59')