Add WooCommerce revenues to computed statistics
[MAILPOET-1853]
This commit is contained in:
@ -6,6 +6,7 @@ use MailPoet\Settings\SettingsController;
|
|||||||
use MailPoet\Tasks\Sending as SendingTask;
|
use MailPoet\Tasks\Sending as SendingTask;
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
use MailPoet\Util\Security;
|
use MailPoet\Util\Security;
|
||||||
|
use MailPoet\WooCommerce\Helper as WCHelper;
|
||||||
use MailPoet\WP\Emoji;
|
use MailPoet\WP\Emoji;
|
||||||
use function MailPoet\Util\array_column;
|
use function MailPoet\Util\array_column;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
@ -587,6 +588,27 @@ class Newsletter extends Model {
|
|||||||
$result[$name] = !empty($row->cnt) ? (int)$row->cnt : 0;
|
$result[$name] = !empty($row->cnt) ? (int)$row->cnt : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WooCommerce revenues
|
||||||
|
$woocommerce_helper = new WCHelper();
|
||||||
|
if ($woocommerce_helper->isWooCommerceActive()) {
|
||||||
|
$currency = $woocommerce_helper->getWoocommerceCurrency();
|
||||||
|
$row = StatisticsWooCommercePurchases::selectExpr('SUM(order_price_total) AS total')
|
||||||
|
->where([
|
||||||
|
'newsletter_id' => $this->id,
|
||||||
|
'order_currency' => $currency,
|
||||||
|
])
|
||||||
|
->findOne();
|
||||||
|
|
||||||
|
$revenue = !empty($row->total) ? (float)$row->total : 0.0;
|
||||||
|
$result['revenue'] = [
|
||||||
|
'currency' => $currency,
|
||||||
|
'value' => $revenue,
|
||||||
|
'formatted' => $woocommerce_helper->getRawPrice($revenue, ['currency' => $currency]),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$result['revenue'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +35,19 @@ class Helper {
|
|||||||
return wc_get_product($the_product);
|
return wc_get_product($the_product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getWoocommerceCurrency() {
|
||||||
|
return get_woocommerce_currency();
|
||||||
|
}
|
||||||
|
|
||||||
function getOrdersCount() {
|
function getOrdersCount() {
|
||||||
$counts = $this->wp->wpCountPosts('shop_order');
|
$counts = $this->wp->wpCountPosts('shop_order');
|
||||||
return array_reduce((array)$counts, function($sum, $count_for_state) {
|
return array_reduce((array)$counts, function($sum, $count_for_state) {
|
||||||
return $sum + (int)$count_for_state;
|
return $sum + (int)$count_for_state;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRawPrice($price, array $args = []) {
|
||||||
|
$html_price = $this->wcPrice($price, $args);
|
||||||
|
return html_entity_decode(strip_tags($html_price));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user