Add forceSync link to woocommerce segment
[MAILPOET-1790]
This commit is contained in:
@ -162,6 +162,9 @@ const itemActions = [
|
|||||||
api_version: window.mailpoet_api_version,
|
api_version: window.mailpoet_api_version,
|
||||||
endpoint: 'segments',
|
endpoint: 'segments',
|
||||||
action: 'synchronize',
|
action: 'synchronize',
|
||||||
|
data: {
|
||||||
|
type: item.type,
|
||||||
|
},
|
||||||
}).done(() => {
|
}).done(() => {
|
||||||
MailPoet.Modal.loading(false);
|
MailPoet.Modal.loading(false);
|
||||||
MailPoet.Notice.success(
|
MailPoet.Notice.success(
|
||||||
@ -179,7 +182,7 @@ const itemActions = [
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
display: function display(segment) {
|
display: function display(segment) {
|
||||||
return isWPUsersSegment(segment);
|
return isWPUsersSegment(segment) || isWooCommerceCustomersSegment(segment);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,7 @@ use MailPoet\API\JSON\Error as APIError;
|
|||||||
use MailPoet\Config\AccessControl;
|
use MailPoet\Config\AccessControl;
|
||||||
use MailPoet\Listing;
|
use MailPoet\Listing;
|
||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
|
use MailPoet\Segments\WooCommerce;
|
||||||
use MailPoet\Segments\WP;
|
use MailPoet\Segments\WP;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
@ -23,12 +24,17 @@ class Segments extends APIEndpoint {
|
|||||||
/** @var Listing\Handler */
|
/** @var Listing\Handler */
|
||||||
private $listing_handler;
|
private $listing_handler;
|
||||||
|
|
||||||
|
/** @var WooCommerce */
|
||||||
|
private $woo_commerce_sync;
|
||||||
|
|
||||||
function __construct(
|
function __construct(
|
||||||
Listing\BulkActionController $bulk_action,
|
Listing\BulkActionController $bulk_action,
|
||||||
Listing\Handler $listing_handler
|
Listing\Handler $listing_handler,
|
||||||
|
WooCommerce $woo_commerce
|
||||||
) {
|
) {
|
||||||
$this->bulk_action = $bulk_action;
|
$this->bulk_action = $bulk_action;
|
||||||
$this->listing_handler = $listing_handler;
|
$this->listing_handler = $listing_handler;
|
||||||
|
$this->woo_commerce_sync = $woo_commerce;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($data = array()) {
|
function get($data = array()) {
|
||||||
@ -148,9 +154,13 @@ class Segments extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function synchronize() {
|
function synchronize($data) {
|
||||||
try {
|
try {
|
||||||
WP::synchronizeUsers();
|
if ($data['type'] === Segment::TYPE_WC_USERS) {
|
||||||
|
$this->woo_commerce_sync->synchronizeCustomers();
|
||||||
|
} else {
|
||||||
|
WP::synchronizeUsers();
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
$e->getCode() => $e->getMessage()
|
$e->getCode() => $e->getMessage()
|
||||||
|
Reference in New Issue
Block a user