Post by mystifier » Mon Aug 30, 2010 5:29 pm

My client, whose shop (1.4.8/1.4.9) has not been running long, reported that the 'Products Purchased Report' didn't tally.

On quick investigation, what is being reported is complete rubbish.

Very different result to:

Code: Select all

SELECT
  order_product.name,
  order_product.model,
  order_product.price,
  SUM(order_product.quantity) AS Qty,
  COUNT(order_product.product_id) AS Orders,
  SUM(order_product.total) AS Total,
  `order`.order_status_id
FROM
  `order`
  INNER JOIN order_product
    ON `order`.order_id = order_product.order_id
WHERE
  `order`.order_status_id > 0
GROUP BY
  order_product.name
ORDER BY
  order_product.name
Last edited by i2Paq on Tue Aug 31, 2010 1:16 pm, edited 1 time in total.
Reason: Title adjusted

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by Qphoria » Mon Aug 30, 2010 9:10 pm

I think the confusion with this report is that it automatically includes the total of the product + the options, but only shows it as the product

So you will see you have an ipod for 100 sold 10 times. But the total is like 1450 instead of 1000 because some people bought the 80GB and some bought the 200GB version. I've not looked into in much so there still may indeed be a real problem, but on quick tests I saw the correct values updating

What are you seeing wrong with it

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by mystifier » Mon Aug 30, 2010 9:58 pm

My stab at a query above returns sensible data but the Products Purchased report shows very different results that don't account at all (and I think grouping all options for a product is fine).

One problem (but not the entire problem) is that the way that they use 'model' (which I didn't impose) means that the values are not always unique whereas the Product Name is.

Among other things, the provided report contains SUM(op.total + op.tax), but op.tax holds tax RATE (17.5) so this should be SUM(op.total+op.total*op.tax/100)

I will implement my above query which they are happy makes sense. I find it odd that there don't appear to be other complaints about the report so can't decide whether I should add mine as a Free Extension alternative.

I make shortest query to return existing report fields correctly:

Code: Select all

SELECT
  order_product.name, order_product.model,
  SUM(order_product.quantity) AS Quantity,
  SUM(order_product.total) AS Total,
  `order`.order_status_id, order_product.product_id
FROM  `order` INNER JOIN order_product ON `order`.order_id = order_product.order_id
WHERE `order`.order_status_id > 0
GROUP BY order_product.product_id
ORDER BY order_product.name

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by mystifier » Tue Aug 31, 2010 6:53 am

Simplest fix for me in admin/model/report/purchased.php is to change:

Code: Select all

$query = $this->db->query("SELECT op.name, op.model, SUM(op.quantity) AS quantity, SUM(op.total + op.tax) AS total FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (op.order_id = o.order_id) WHERE o.order_status_id > '0' GROUP BY model ORDER BY total DESC LIMIT " . (int)$start . "," . (int)$limit);

To:

Code: Select all

$query = $this->db->query("SELECT op.name, op.model, SUM(op.quantity) AS quantity, SUM(op.total+op.total*op.tax/100) AS total FROM `" . DB_PREFIX . "order` o INNER JOIN " . DB_PREFIX . "order_product op ON (op.order_id = o.order_id) WHERE o.order_status_id > 0 GROUP BY op.product_id ORDER BY total DESC LIMIT " . (int)$start . "," . (int)$limit);
... and in same file, to get correct pagination, I changed:

Code: Select all

$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` GROUP BY model");
To:

Code: Select all

$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` GROUP BY product_id");

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by ha33y » Wed Oct 06, 2010 8:35 pm

Same problem here in 1.4.9.1 the product report was giving me a totally wrong total, your fix worked for me thank you for your work! :)

New member

Posts

Joined
Fri Sep 24, 2010 8:03 pm
Who is online

Users browsing this forum: No registered users and 4 guests