Add getOrdersCount() to WooCommerce helper
[MAILPOET-1732]
This commit is contained in:
committed by
M. Shull
parent
74bee5ec1e
commit
29e2cebce3
@ -8,13 +8,17 @@ use MailPoet\Settings\SettingsController;
|
|||||||
use MailPoet\WooCommerce\Helper as WooCommerceHelper;
|
use MailPoet\WooCommerce\Helper as WooCommerceHelper;
|
||||||
use MailPoetVendor\Twig\Extension\AbstractExtension;
|
use MailPoetVendor\Twig\Extension\AbstractExtension;
|
||||||
use MailPoetVendor\Twig\TwigFunction;
|
use MailPoetVendor\Twig\TwigFunction;
|
||||||
|
use \MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Analytics extends AbstractExtension {
|
class Analytics extends AbstractExtension {
|
||||||
public function getFunctions() {
|
public function getFunctions() {
|
||||||
$settings = new SettingsController();
|
$settings = new SettingsController();
|
||||||
$analytics = new AnalyticsGenerator(new Reporter($settings, new WooCommerceHelper), $settings);
|
$analytics = new AnalyticsGenerator(
|
||||||
|
new Reporter($settings, new WooCommerceHelper(new WPFunctions())),
|
||||||
|
$settings
|
||||||
|
);
|
||||||
return array(
|
return array(
|
||||||
new TwigFunction(
|
new TwigFunction(
|
||||||
'get_analytics_data',
|
'get_analytics_data',
|
||||||
|
@ -532,4 +532,13 @@ class Functions {
|
|||||||
global $wpdb;
|
global $wpdb;
|
||||||
return $wpdb->parse_db_host($host);
|
return $wpdb->parse_db_host($host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|null $type
|
||||||
|
* @param string|null $permission
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
function wpCountPosts($type = null, $permission = null) {
|
||||||
|
return wp_count_posts($type, $permission);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\WooCommerce;
|
namespace MailPoet\WooCommerce;
|
||||||
|
|
||||||
|
use MailPoet\WP\Functions;
|
||||||
|
|
||||||
class Helper {
|
class Helper {
|
||||||
|
|
||||||
|
/** @var Functions */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
|
function __construct(Functions $wp = null) {
|
||||||
|
if (!$wp) {
|
||||||
|
$wp = Functions::get();
|
||||||
|
}
|
||||||
|
$this->wp = $wp;
|
||||||
|
}
|
||||||
|
|
||||||
function isWooCommerceActive() {
|
function isWooCommerceActive() {
|
||||||
return class_exists('WooCommerce');
|
return class_exists('WooCommerce');
|
||||||
}
|
}
|
||||||
@ -21,4 +34,11 @@ class Helper {
|
|||||||
function wcGetProduct($the_product = false) {
|
function wcGetProduct($the_product = false) {
|
||||||
return wc_get_product($the_product);
|
return wc_get_product($the_product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOrdersCount() {
|
||||||
|
$counts = $this->wp->wpCountPosts('shop_order');
|
||||||
|
return array_reduce((array)$counts, function($sum, $count_for_state) {
|
||||||
|
return $sum + (int)$count_for_state;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ use Codeception\Stub;
|
|||||||
use Codeception\Stub\Expected;
|
use Codeception\Stub\Expected;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
use MailPoet\WooCommerce\Helper as WooCommerceHelper;
|
use MailPoet\WooCommerce\Helper as WooCommerceHelper;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class AnalyticsTest extends \MailPoetTest {
|
class AnalyticsTest extends \MailPoetTest {
|
||||||
|
|
||||||
@ -21,7 +22,10 @@ class AnalyticsTest extends \MailPoetTest {
|
|||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
$this->settings = new SettingsController();
|
$this->settings = new SettingsController();
|
||||||
$this->analytics = new Analytics(new Reporter($this->settings, new WooCommerceHelper), $this->settings);
|
$this->analytics = new Analytics(
|
||||||
|
new Reporter($this->settings, new WooCommerceHelper(new WPFunctions)),
|
||||||
|
$this->settings
|
||||||
|
);
|
||||||
// Remove premium plugin hooks so that tests pass also with premium active
|
// Remove premium plugin hooks so that tests pass also with premium active
|
||||||
remove_all_filters(Analytics::ANALYTICS_FILTER);
|
remove_all_filters(Analytics::ANALYTICS_FILTER);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class MenuTest extends \MailPoetTest {
|
|||||||
|
|
||||||
function testItChecksMailpoetAPIKey() {
|
function testItChecksMailpoetAPIKey() {
|
||||||
$renderer = Stub::make(new Renderer());
|
$renderer = Stub::make(new Renderer());
|
||||||
$menu = new Menu($renderer, new AccessControl(new Functions()), new SettingsController(), new Functions(), new WooCommerceHelper, new ServicesChecker, new UserFlagsController);
|
$menu = $this->getMenu($renderer);
|
||||||
|
|
||||||
$_REQUEST['page'] = 'mailpoet-newsletters';
|
$_REQUEST['page'] = 'mailpoet-newsletters';
|
||||||
$checker = Stub::make(
|
$checker = Stub::make(
|
||||||
@ -66,7 +66,7 @@ class MenuTest extends \MailPoetTest {
|
|||||||
|
|
||||||
function testItChecksPremiumKey() {
|
function testItChecksPremiumKey() {
|
||||||
$renderer = Stub::make(new Renderer());
|
$renderer = Stub::make(new Renderer());
|
||||||
$menu = new Menu($renderer, new AccessControl(new Functions()), new SettingsController(), new Functions(), new WooCommerceHelper, new ServicesChecker, new UserFlagsController);
|
$menu = $this->getMenu($renderer);
|
||||||
|
|
||||||
$_REQUEST['page'] = 'mailpoet-newsletters';
|
$_REQUEST['page'] = 'mailpoet-newsletters';
|
||||||
$checker = Stub::make(
|
$checker = Stub::make(
|
||||||
@ -85,4 +85,16 @@ class MenuTest extends \MailPoetTest {
|
|||||||
$menu->checkPremiumKey($checker);
|
$menu->checkPremiumKey($checker);
|
||||||
expect($menu->premium_key_valid)->false();
|
expect($menu->premium_key_valid)->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getMenu(Renderer $renderer) {
|
||||||
|
return new Menu(
|
||||||
|
$renderer,
|
||||||
|
new AccessControl(),
|
||||||
|
new SettingsController(),
|
||||||
|
new Functions(),
|
||||||
|
new WooCommerceHelper(new Functions()),
|
||||||
|
new ServicesChecker,
|
||||||
|
new UserFlagsController
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user