magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.52k stars 9.31k forks source link

(Zend_Db_Statement_Exception): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous #10657

Closed RishabhRkRai closed 7 years ago

RishabhRkRai commented 7 years ago

Preconditions

  1. Magento 2.1.7, PHP 7, MySQL 5.7
  2. Nginx Server

Steps to reproduce

  1. 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
  2. Then filter the orders by created at
  3. My codes are look like di.xml `

    `

view/adminhtml/ui-component/sales_order_grid.xml `

Sku text true
</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

  1. Orders grid filter at the give range

Actual result

  1. 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')

tomasinchoo commented 7 years ago

How exactly is this Magento 2 issue?

fooman commented 7 years ago

Closing this issue as this relates to custom code written by you and not Magento's. You might have more luck asking for help in the Magento forums or on StackExchange.

fasaro commented 4 days ago

Error when filtering orders in the Admin

Issue Filtering orders in the Admin by date returns an error.

The exception.log shows:

report.CRITICAL: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous in /path/to/magento/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:90 CopyToggle Text Wrapping Steps to reproduce:

Go to Admin > Sales > Orders.

Set Purchase Date Ascending order in grid, OR Set Purchase Date Filter in filters. An error appears: Something went wrong with processing the default view and we have restored the filter to its original state.

Cause There is an issue with the PayPal Braintree modules.

Solution To solve the issue, apply the patch attached to this article. To download it, scroll down to the end of the article and click the file name, or click the following link:

bundle_3357_filter_order_in_admin_by_date_patch.zip

The patch is compatible with all affected versions and editions.

How to apply the patch For instructions, see How to apply a composer patch provided by Adobe in the support knowledge base.