0

I have a problem with the default Magento core function. I really don't know whether it is a conflict with any other modules.

When we go to the customer menu in admin and select any customer from the list then click on the order tab in the customer details page. I can see that the loading image is rotating, there is no customer order I can see.

I have checked in the console there is a 500 internal server error. I have go to the class file path(vendor/magento/module-customer/Block/Adminhtml/Edit/Tab/Orders.php) and echo the SQL query.

SELECT DISTINCT `main_table`.`entity_id`, `main_table`.`increment_id`, `main_table`.`customer_id`, `main_table`.`created_at`, 
`main_table`.`grand_total`, `main_table`.`order_currency_code`, `main_table`.`store_id`, `main_table`.`billing_name`, 
`main_table`.`shipping_name`, `sales_order`.`coupon_code`, 
group_concat(DISTINCT `sales_order_item`.sku SEPARATOR ", ") AS `sku`, 
group_concat(DISTINCT `sales_order_item`.name SEPARATOR ",\n") AS `name`, 
group_concat(DISTINCT `sales_order_item`.product_options SEPARATOR "|| ") AS `product_options`, 
`sales_order_item`.`qty_ordered`, `sales_order_item`.`qty_invoiced`, `sales_order_item`.`qty_shipped`, `sales_order_item`.`qty_canceled`, 
`sales_order_item`.`qty_refunded` 
FROM `sales_order_grid` AS `main_table` 
LEFT JOIN `sales_order` ON main_table.entity_id = sales_order.entity_id 
INNER JOIN `sales_order_item` ON main_table.entity_id = sales_order_item.order_id WHERE (`customer_id` = '73922') 
GROUP BY `main_table`.`entity_id`

The error code appears on PHPMyAdmin when I run the code

Error in the query (1052): Column 'customer_id' in where clause is ambiguous

This is the right SQL Query

SELECT DISTINCT `main_table`.*, `sales_order`.`coupon_code`, 
group_concat(DISTINCT `sales_order_item`.sku SEPARATOR ", ") AS `sku`, 
group_concat(DISTINCT `sales_order_item`.name SEPARATOR ",\n") AS `name`, 
group_concat(DISTINCT `sales_order_item`.product_options SEPARATOR "|| ") AS `product_options`, 
`sales_order_item`.`qty_ordered`, `sales_order_item`.`qty_invoiced`, `sales_order_item`.`qty_shipped`, 
`sales_order_item`.`qty_canceled`, `sales_order_item`.`qty_refunded` 
FROM `sales_order_grid` AS `main_table` 
LEFT JOIN `sales_order` ON main_table.entity_id = sales_order.entity_id 
INNER JOIN `sales_order_item` ON main_table.entity_id = sales_order_item.order_id 
WHERE (`main_table`.`customer_id` = '73922') 
GROUP BY `main_table`.`entity_id`, `sales_order_item`.`qty_ordered`, `sales_order_item`.`qty_invoiced`, `sales_order_item`.`qty_shipped`, 
`sales_order_item`.`qty_canceled`, `sales_order_item`.`qty_refunded`

How can I convert the order.php query to this one?

9
  • you must have added some column, my guess is you edited collection file. let me know if you did. we can work on separate module for that Nov 21, 2019 at 14:33
  • I didn't edit that file. Nov 21, 2019 at 14:47
  • try disabling your custom modules. then check Nov 21, 2019 at 15:37
  • Thank you Ali Hussain for your valuable comments. Let me check with your way. Nov 22, 2019 at 6:49
  • When I disable and enable third-party modules. Then it showing the orders on the customer details page. Thank you again. Nov 22, 2019 at 7:32

1 Answer 1

0

Just add addFilterToMap for customer_id in the similar file, where joining happens with other tables.

class Collection extends OriginalCollection
{
  protected function _initSelect()
  {
    $this->addFilterToMap('customer_id', 'main_table.customer_id'); //add this in your similar function.
    return parent::_initSelect();
  }

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.