Skip to content

Products Ordered Report - Not grouped by product #22087

@nicholasscottfish

Description

@nicholasscottfish

Preconditions (*)

  1. Magento 2.2.3

Steps to reproduce (*)

  1. In the Magento 2 admin go to Reports -> Products -> Ordered
  2. Select a date range where you know you have sold products spanning across multiple orders
  3. Select 'Show By' year
  4. Hit refresh

Expected result (*)

  1. I would expect to see a list of products sold per year, grouped by product with a total quantity

Actual result (*)

  1. I see a list of products sold per year, with multiple entries for a single product on a per order basis

Discussion

From what I can see in the source code, this still appears to be an issue in Magento 2.3.* and I can't see any related issues, if there are then please forgive me.

I have created a temporary patch file for this:

diff --git a/Model/ResourceModel/Product/Sold/Collection.php b/Model/ResourceModel/Product/Sold/Collection.php
index 61dc77d1..8b91fdb2 100644
--- a/Model/ResourceModel/Product/Sold/Collection.php
+++ b/Model/ResourceModel/Product/Sold/Collection.php
@@ -66,7 +66,7 @@ class Collection extends \Magento\Reports\Model\ResourceModel\Order\Collection
         $this->getSelect()->reset()->from(
             ['order_items' => $this->getTable('sales_order_item')],
             [
-                'ordered_qty' => 'order_items.qty_ordered',
+                'ordered_qty' => 'SUM(order_items.qty_ordered)',
                 'order_items_name' => 'order_items.name',
                 'order_items_sku' => 'order_items.sku'
             ]
@@ -76,8 +76,10 @@ class Collection extends \Magento\Reports\Model\ResourceModel\Order\Collection
             []
         )->where(
             'order_items.parent_item_id IS NULL'
+        )->group(
+            'order_items.product_id'
         )->having(
-            'order_items.qty_ordered > ?',
+            'SUM(order_items.qty_ordered) > ?',
             0
         );
         return $this;

I will raise a PR if other people are experiencing this issue, any feedback would be welcome.

Regards,

Nick

Metadata

Metadata

Labels

Component: ReportsEvent: dmcdindia1Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions