Permalink
Browse files

Merge pull request #3105 from mrnfrancesco/patch-issue-3101

Fixed issue 3101
  • Loading branch information...
2 parents 7971316 + 834bb75 commit e30de743e09537ffdb03455f8a0768dc6342d89f @danielkerr danielkerr committed Jun 14, 2015
Showing with 4 additions and 2 deletions.
  1. +4 −2 upload/admin/model/report/customer.php
@@ -95,7 +95,7 @@ public function getTotalCustomersByYear() {
}
public function getOrders($data = array()) {
- $sql = "SELECT c.customer_id, CONCAT(c.firstname, ' ', c.lastname) AS customer, c.email, cgd.name AS customer_group, c.status, COUNT(o.order_id) AS orders, SUM(op.quantity) AS products, SUM(o.total) AS `total` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_product` op ON (o.order_id = op.order_id)LEFT JOIN `" . DB_PREFIX . "customer` c ON (o.customer_id = c.customer_id) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.customer_group_id = cgd.customer_group_id) WHERE o.customer_id > 0 AND cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
+ $sql = "SELECT c.customer_id, CONCAT(c.firstname, ' ', c.lastname) AS customer, c.email, cgd.name AS customer_group, c.status, o.order_id, SUM(op.quantity) as products, SUM(DISTINCT o.total) AS total FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_product` op ON (o.order_id = op.order_id)LEFT JOIN `" . DB_PREFIX . "customer` c ON (o.customer_id = c.customer_id) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.customer_group_id = cgd.customer_group_id) WHERE o.customer_id > 0 AND cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
if (!empty($data['filter_order_status_id'])) {
$sql .= " AND o.order_status_id = '" . (int)$data['filter_order_status_id'] . "'";
@@ -111,7 +111,7 @@ public function getOrders($data = array()) {
$sql .= " AND DATE(o.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'";
}
- $sql .= " GROUP BY o.customer_id ORDER BY total DESC";
+ $sql .= " GROUP BY o.order_id";
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
@@ -125,6 +125,8 @@ public function getOrders($data = array()) {
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
+ $sql = "SELECT t.customer_id, t.customer, t.email, t.customer_group, t.status, COUNT(t.order_id) AS orders, SUM(t.products) AS products, SUM(t.total) AS total FROM (" . $sql . ") AS t GROUP BY t.customer_id ORDER BY total DESC";
+
$query = $this->db->query($sql);
return $query->rows;

0 comments on commit e30de74

Please sign in to comment.