From 032e5a20babdbcc8866570ccbe9271b5cb29d7ee Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Tue, 12 Mar 2019 13:35:21 +0100 Subject: [PATCH] Add forceSync link to woocommerce segment [MAILPOET-1790] --- assets/js/src/segments/list.jsx | 5 ++++- lib/API/JSON/v1/Segments.php | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/assets/js/src/segments/list.jsx b/assets/js/src/segments/list.jsx index 6a00490b61..379ba6c3cc 100644 --- a/assets/js/src/segments/list.jsx +++ b/assets/js/src/segments/list.jsx @@ -162,6 +162,9 @@ const itemActions = [ api_version: window.mailpoet_api_version, endpoint: 'segments', action: 'synchronize', + data: { + type: item.type, + }, }).done(() => { MailPoet.Modal.loading(false); MailPoet.Notice.success( @@ -179,7 +182,7 @@ const itemActions = [ }); }, display: function display(segment) { - return isWPUsersSegment(segment); + return isWPUsersSegment(segment) || isWooCommerceCustomersSegment(segment); }, }, { diff --git a/lib/API/JSON/v1/Segments.php b/lib/API/JSON/v1/Segments.php index 5469675a42..d4350cff84 100644 --- a/lib/API/JSON/v1/Segments.php +++ b/lib/API/JSON/v1/Segments.php @@ -7,6 +7,7 @@ use MailPoet\API\JSON\Error as APIError; use MailPoet\Config\AccessControl; use MailPoet\Listing; use MailPoet\Models\Segment; +use MailPoet\Segments\WooCommerce; use MailPoet\Segments\WP; use MailPoet\WP\Functions as WPFunctions; @@ -23,12 +24,17 @@ class Segments extends APIEndpoint { /** @var Listing\Handler */ private $listing_handler; + /** @var WooCommerce */ + private $woo_commerce_sync; + function __construct( Listing\BulkActionController $bulk_action, - Listing\Handler $listing_handler + Listing\Handler $listing_handler, + WooCommerce $woo_commerce ) { $this->bulk_action = $bulk_action; $this->listing_handler = $listing_handler; + $this->woo_commerce_sync = $woo_commerce; } function get($data = array()) { @@ -148,9 +154,13 @@ class Segments extends APIEndpoint { } } - function synchronize() { + function synchronize($data) { try { - WP::synchronizeUsers(); + if ($data['type'] === Segment::TYPE_WC_USERS) { + $this->woo_commerce_sync->synchronizeCustomers(); + } else { + WP::synchronizeUsers(); + } } catch (\Exception $e) { return $this->errorResponse(array( $e->getCode() => $e->getMessage()