Include puchases count in newsletters stats

[PREMIUM-115]
This commit is contained in:
Pavel Dohnal
2019-05-15 15:22:18 +02:00
committed by M. Shull
parent b1448a7025
commit 7f7c98d8cb

View File

@@ -605,6 +605,7 @@ class Newsletter extends Model {
) { ) {
$currency = $woocommerce_helper->getWoocommerceCurrency(); $currency = $woocommerce_helper->getWoocommerceCurrency();
$row = StatisticsWooCommercePurchases::selectExpr('SUM(order_price_total) AS total') $row = StatisticsWooCommercePurchases::selectExpr('SUM(order_price_total) AS total')
->selectExpr('count(*)', 'count')
->where([ ->where([
'newsletter_id' => $this->id, 'newsletter_id' => $this->id,
'order_currency' => $currency, 'order_currency' => $currency,
@@ -612,9 +613,11 @@ class Newsletter extends Model {
->findOne(); ->findOne();
$revenue = !empty($row->total) ? (float)$row->total : 0.0; $revenue = !empty($row->total) ? (float)$row->total : 0.0;
$count = !empty($row->count) ? (int)$row->count : 0;
$result['revenue'] = [ $result['revenue'] = [
'currency' => $currency, 'currency' => $currency,
'value' => $revenue, 'value' => $revenue,
'count' => $count,
'formatted' => $woocommerce_helper->getRawPrice($revenue, ['currency' => $currency]), 'formatted' => $woocommerce_helper->getRawPrice($revenue, ['currency' => $currency]),
]; ];
} else { } else {