Prevent showing WC Customers UI to new WC website
[MAILPOET-2206]
This commit is contained in:
@@ -106,7 +106,7 @@ class Changelog {
|
|||||||
!in_array($_GET['page'], ['mailpoet-revenue-tracking-permission', 'mailpoet-woocommerce-list-import', 'mailpoet-welcome-wizard', 'mailpoet-migration'])
|
!in_array($_GET['page'], ['mailpoet-revenue-tracking-permission', 'mailpoet-woocommerce-list-import', 'mailpoet-welcome-wizard', 'mailpoet-migration'])
|
||||||
&& !$this->settings->get('woocommerce_import_screen_displayed')
|
&& !$this->settings->get('woocommerce_import_screen_displayed')
|
||||||
&& $this->wooCommerceHelper->isWooCommerceActive()
|
&& $this->wooCommerceHelper->isWooCommerceActive()
|
||||||
&& $this->wooCommerceHelper->getOrdersCount() >= 1
|
&& $this->wooCommerceHelper->getOrdersCountCreatedBefore($this->settings->get('installed_at')) > 0
|
||||||
&& $this->wp->currentUserCan('administrator')
|
&& $this->wp->currentUserCan('administrator')
|
||||||
) {
|
) {
|
||||||
$this->url_helper->redirectTo($this->wp->adminUrl('admin.php?page=mailpoet-woocommerce-list-import'));
|
$this->url_helper->redirectTo($this->wp->adminUrl('admin.php?page=mailpoet-woocommerce-list-import'));
|
||||||
|
@@ -39,7 +39,7 @@ class PrivacyPolicy {
|
|||||||
WPFunctions::get()->__('No identifiable information is otherwise tracked outside this website except for the email address.', 'mailpoet') .
|
WPFunctions::get()->__('No identifiable information is otherwise tracked outside this website except for the email address.', 'mailpoet') .
|
||||||
'</p>'
|
'</p>'
|
||||||
);
|
);
|
||||||
$helper = new WooCommerceHelper(new WPFunctions);
|
$helper = new WooCommerceHelper();
|
||||||
if ($helper->isWooCommerceActive()) {
|
if ($helper->isWooCommerceActive()) {
|
||||||
$content .= (
|
$content .= (
|
||||||
'<p> ' .
|
'<p> ' .
|
||||||
|
@@ -16,7 +16,7 @@ class Analytics extends AbstractExtension {
|
|||||||
public function getFunctions() {
|
public function getFunctions() {
|
||||||
$settings = new SettingsController();
|
$settings = new SettingsController();
|
||||||
$analytics = new AnalyticsGenerator(
|
$analytics = new AnalyticsGenerator(
|
||||||
new Reporter($settings, new WooCommerceHelper(new WPFunctions())),
|
new Reporter($settings, new WooCommerceHelper()),
|
||||||
$settings
|
$settings
|
||||||
);
|
);
|
||||||
return [
|
return [
|
||||||
|
@@ -568,12 +568,4 @@ class Functions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string|null $type
|
|
||||||
* @param string|null $permission
|
|
||||||
* @return object
|
|
||||||
*/
|
|
||||||
function wpCountPosts($type = null, $permission = null) {
|
|
||||||
return wp_count_posts($type, $permission);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,8 @@
|
|||||||
<?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');
|
||||||
}
|
}
|
||||||
@@ -47,11 +35,13 @@ class Helper {
|
|||||||
return get_woocommerce_currency();
|
return get_woocommerce_currency();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrdersCount() {
|
function getOrdersCountCreatedBefore($date_time) {
|
||||||
$counts = $this->wp->wpCountPosts('shop_order');
|
global $wpdb;
|
||||||
return array_reduce((array)$counts, function($sum, $count_for_state) {
|
$result = $wpdb->get_var( "
|
||||||
return $sum + (int)$count_for_state;
|
SELECT DISTINCT count(p.ID) FROM {$wpdb->prefix}posts as p
|
||||||
});
|
WHERE p.post_type = 'shop_order' AND p.post_date < '{$date_time}'
|
||||||
|
" );
|
||||||
|
return (int)$result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRawPrice($price, array $args = []) {
|
function getRawPrice($price, array $args = []) {
|
||||||
|
@@ -42,6 +42,10 @@ class WooCommerceOrder {
|
|||||||
return $this->update(['status' => $status]);
|
return $this->update(['status' => $status]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function withDateCreated($date) {
|
||||||
|
return $this->update(['date_created' => $date]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $customer_data Customer created via WooCommerceCustomer factory
|
* @param array $customer_data Customer created via WooCommerceCustomer factory
|
||||||
* @return $this
|
* @return $this
|
||||||
@@ -88,7 +92,15 @@ class WooCommerceOrder {
|
|||||||
}
|
}
|
||||||
$create_output = $this->tester->cliToArray($cmd);
|
$create_output = $this->tester->cliToArray($cmd);
|
||||||
$order_out = $this->tester->cliToArray("wc shop_order get $create_output[0] --format=json --allow-root --user=admin");
|
$order_out = $this->tester->cliToArray("wc shop_order get $create_output[0] --format=json --allow-root --user=admin");
|
||||||
return json_decode($order_out[0], true);
|
$order = json_decode($order_out[0], true);
|
||||||
|
if (isset($this->data['date_created'])) {
|
||||||
|
wp_update_post([
|
||||||
|
'ID' => $order['id'],
|
||||||
|
'post_date' => $this->data['date_created'],
|
||||||
|
'post_date_gmt' => get_gmt_from_date( $this->data['date_created'] ),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -84,7 +84,9 @@ class WooCommerceListImportPageCest {
|
|||||||
function importListPageRedirectionTest(\AcceptanceTester $I) {
|
function importListPageRedirectionTest(\AcceptanceTester $I) {
|
||||||
$settings_factory = new Settings();
|
$settings_factory = new Settings();
|
||||||
$settings_factory->withWooCommerceListImportPageDisplayed(false);
|
$settings_factory->withWooCommerceListImportPageDisplayed(false);
|
||||||
$order = $this->order_factory->create();
|
$order = $this->order_factory
|
||||||
|
->withDateCreated('2001-08-22T11:11:56') // any time in the past. Must be before the plugin activation
|
||||||
|
->create();
|
||||||
$I->login();
|
$I->login();
|
||||||
$I->amOnMailpoetPage('Emails');
|
$I->amOnMailpoetPage('Emails');
|
||||||
$I->seeInCurrentUrl('wp-admin/admin.php?page=mailpoet-woocommerce-list-import');
|
$I->seeInCurrentUrl('wp-admin/admin.php?page=mailpoet-woocommerce-list-import');
|
||||||
|
@@ -23,7 +23,7 @@ class AnalyticsTest extends \MailPoetTest {
|
|||||||
parent::_before();
|
parent::_before();
|
||||||
$this->settings = new SettingsController();
|
$this->settings = new SettingsController();
|
||||||
$this->analytics = new Analytics(
|
$this->analytics = new Analytics(
|
||||||
new Reporter($this->settings, new WooCommerceHelper(new WPFunctions)),
|
new Reporter($this->settings, new WooCommerceHelper()),
|
||||||
$this->settings
|
$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
|
||||||
|
Reference in New Issue
Block a user