Fix duplicit orders in subscriber stats summary
[PREMIUM-145]
This commit is contained in:
committed by
Veljko V
parent
1a1f594e72
commit
9d391bf8ae
@ -12,6 +12,8 @@ use MailPoet\Newsletter\Statistics\WooCommerceRevenue;
|
|||||||
use MailPoet\WooCommerce\Helper as WCHelper;
|
use MailPoet\WooCommerce\Helper as WCHelper;
|
||||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||||
|
|
||||||
|
use function MailPoetVendor\array_column;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends Repository<SubscriberEntity>
|
* @extends Repository<SubscriberEntity>
|
||||||
*/
|
*/
|
||||||
@ -66,21 +68,21 @@ class SubscriberStatisticsRepository extends Repository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$currency = $this->wcHelper->getWoocommerceCurrency();
|
$currency = $this->wcHelper->getWoocommerceCurrency();
|
||||||
$result = $this->entityManager
|
$purchases = $this->entityManager->createQueryBuilder()
|
||||||
->createQueryBuilder()
|
->select('stats.orderPriceTotal')
|
||||||
->select('SUM(stats.orderPriceTotal) AS total, COUNT(stats.id) AS cnt')
|
|
||||||
->from(StatisticsWooCommercePurchaseEntity::class, 'stats')
|
->from(StatisticsWooCommercePurchaseEntity::class, 'stats')
|
||||||
->where('stats.subscriber = :subscriber')
|
->where('stats.subscriber = :subscriber')
|
||||||
->andWhere('stats.orderCurrency = :currency')
|
->andWhere('stats.orderCurrency = :currency')
|
||||||
->setParameter('subscriber', $subscriber)
|
->setParameter('subscriber', $subscriber)
|
||||||
->setParameter('currency', $currency)
|
->setParameter('currency', $currency)
|
||||||
|
->groupBy('stats.orderId, stats.orderPriceTotal')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getSingleResult();
|
->getResult();
|
||||||
|
$sum = array_sum(array_column($purchases, 'orderPriceTotal'));
|
||||||
return new WooCommerceRevenue(
|
return new WooCommerceRevenue(
|
||||||
$currency,
|
$currency,
|
||||||
(float)$result['total'],
|
(float)$sum,
|
||||||
(int)$result['cnt'],
|
count($purchases),
|
||||||
$this->wcHelper
|
$this->wcHelper
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user