From 87a88627de95f2a127d36a7b07c65097be07b6d1 Mon Sep 17 00:00:00 2001 From: Ant Cooper Date: Wed, 9 Oct 2024 11:15:24 +0100 Subject: [PATCH 1/2] Apply Commerce 4 fix to Craft 5 version --- src/templates/widgets/TopCustomers/body.twig | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/templates/widgets/TopCustomers/body.twig b/src/templates/widgets/TopCustomers/body.twig index 76475a1..4b4f678 100755 --- a/src/templates/widgets/TopCustomers/body.twig +++ b/src/templates/widgets/TopCustomers/body.twig @@ -14,7 +14,6 @@ {% for customer in customers %} - {% set userId = craft.commercewidgets.userIdByCustomerId(customer.customerId).userId %} @@ -26,13 +25,9 @@ - {% if userId|length %} - - {{ customer.email }} - - {% else %} - {{ customer.email }} - {% endif %} + + {{ customer.email }} + {{ customer.totalRevenue|currency(commerce.currency) }} {{ customer.totalOrders|number_format() }} From bf47efdca7c08aef72cbf03c05004c58b5d22b15 Mon Sep 17 00:00:00 2001 From: Ant Cooper Date: Tue, 15 Oct 2024 11:17:12 +0100 Subject: [PATCH 2/2] Update getProducts() for new Craft 5 db structure --- src/widgets/ProductsTop.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/widgets/ProductsTop.php b/src/widgets/ProductsTop.php index c255b1a..c1760e8 100644 --- a/src/widgets/ProductsTop.php +++ b/src/widgets/ProductsTop.php @@ -52,8 +52,8 @@ public function getProducts() ) ->select( [ - 'variants.productId as id', - 'variants.sku as sku', + 'variants.primaryOwnerId as id', + 'purchasables.sku as sku', 'SUM(items.total) as totalRevenue', 'count(*) as totalOrdered', ] @@ -69,7 +69,7 @@ public function getProducts() 'LEFT JOIN', '{{%commerce_orders}} orders', 'orders.id = items.orderId' ) ->join( - 'LEFT JOIN', '{{%elements}} elements', 'elements.id = variants.productId' + 'LEFT JOIN', '{{%elements}} elements', 'elements.id = variants.primaryOwnerId' ) ->where(['elements.dateDeleted' => null]) ->andWhere(['orders.isCompleted' => 1]) @@ -81,7 +81,7 @@ public function getProducts() { $query ->andWhere(['orders.orderStatusId' => $this->orderStatusId]) - ->andWhere(['not', ['variants.productId' => null]]); + ->andWhere(['not', ['variants.primaryOwnerId' => null]]); } $result = $query->cache(CommerceWidgets::$plugin->getSettings()->cacheDuration)->all();