Skip to content

Commit c0e3687

Browse files
authored
Merge pull request #1294 from mailchimp/5.5
5.5
2 parents 3ad3018 + a004cdd commit c0e3687

19 files changed

+1234
-163
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
_test.php
44
/vendor/
55
blocks/node_modules/*
6-
.editorconfig
6+
.editorconfig
7+
CLAUDE.md

CHANGELOG.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
== Changelog ==
2+
= 5.5 =
3+
* WooCommerce block dependency updates
4+
* Logging enhancements
5+
* Better compatibility when external object cache is detected
6+
* Refactor Connected Sites API connection
7+
* Adds support for Product visibility logic for syncing
28
= 5.4 =
39
* Performance and User Interface improvements
410
* Ability to sync Product Short Description

README.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Tags: ecommerce,email,workflows,mailchimp
44
Donate link: https://mailchimp.com
55
Requires at least: 6.2
66
Tested up to: 6.8
7-
Stable tag: 5.4
7+
Stable tag: 5.5
88
Requires PHP: 7.4
99
WC requires at least: 8.2
10-
WC tested up to: 9.8
10+
WC tested up to: 10.0
1111
License: GPLv2 or later
1212
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1313
Connect your store to your Mailchimp audience to track sales, create targeted emails, send abandoned cart emails, and more.
@@ -78,6 +78,9 @@ At this time, the synchronization of product categories from WooCommerce to Mail
7878
If you are unable to sync or connect with Mailchimp, you can open a ticket on our [Github plugin page](https://github.com/mailchimp/mc-woocommerce/issues). Please provide the version of the plugin and PHP you're using, any fatal errors in the WooCommerce logs (WooCommerce -> Status -> Logs) you're seeing, along with relevant information to the problem you're experiencing.
7979

8080
== Changelog ==
81-
= 5.4 =
82-
* Performance and User Interface improvements
83-
* Ability to sync Product Short Description
81+
= 5.5 =
82+
* WooCommerce block dependency updates
83+
* Logging enhancements
84+
* Better compatibility when external object cache is detected
85+
* Refactor Connected Sites API connection
86+
* Adds support for Product visibility logic for syncing

admin/class-mailchimp-woocommerce-admin.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function disconnect_store() {
8686
* @return bool
8787
*/
8888
private function is_disconnecting() {
89-
return isset( $_REQUEST['mailchimp_woocommerce_disconnect_store'] )
89+
return isset( $_REQUEST['mailchimp_woocommerce_disconnect_store'] )
9090
&& current_user_can( mailchimp_get_allowed_capability() )
9191
&& $_REQUEST['mailchimp_woocommerce_disconnect_store'] == 1
9292
&& isset( $_REQUEST['_disconnect-nonce'] )
@@ -139,7 +139,7 @@ public function enqueue_scripts( $hook ) {
139139
$options = mailchimp_get_admin_options();
140140
$checkbox_default_settings = ( array_key_exists( 'mailchimp_checkbox_defaults', $options ) && ! is_null( $options['mailchimp_checkbox_defaults'] ) ) ? $options['mailchimp_checkbox_defaults'] : 'check';
141141
wp_register_script( $this->plugin_name . 'create-account', plugin_dir_url( __FILE__ ) . 'js/mailchimp-woocommerce-create-account.js', array( 'jquery', 'swal' ), $this->version );
142-
wp_register_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailchimp-woocommerce-admin.js', array( 'jquery', 'swal' ), $this->version );
142+
wp_register_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailchimp-woocommerce-admin.js', array( 'jquery', 'swal' ), $this->version . 'test-122' );
143143
wp_register_script( $this->plugin_name . '-v2', plugin_dir_url( __FILE__ ) . 'v2/assets/js/scripts.js', array( 'jquery', 'swal' ), $this->version );
144144
wp_localize_script(
145145
$this->plugin_name,
@@ -855,7 +855,7 @@ public function validate( $input ) {
855855
// case disconnect
856856
if ( $this->is_disconnecting() ) {
857857
// Disconnect store!
858-
if ( $this->disconnect_store() ) {
858+
if ( $this->disconnect_store() ) {
859859
return array(
860860
'active_tab' => 'api_key',
861861
'mailchimp_api_key' => null,
@@ -1054,7 +1054,8 @@ public function mailchimp_woocommerce_ajax_oauth_finish() {
10541054
// save api_key? If yes, we can skip api key validation for validatePostApiKey();
10551055
$result = json_decode( $response['body'], true);
10561056
$options = \Mailchimp_Woocommerce_DB_Helpers::get_option($this->plugin_name);
1057-
$options['mailchimp_api_key'] = $result['access_token'].'-'.$result['data_center'];
1057+
$api_key = $result['access_token'].'-'.$result['data_center'];
1058+
$options['mailchimp_api_key'] = $api_key;
10581059

10591060
// \Mailchimp_Woocommerce_DB_Helpers::update_option($this->plugin_name, $options); this used to return false!
10601061
// go straight to the DB and update the options to bypass any filters.
@@ -1065,7 +1066,7 @@ public function mailchimp_woocommerce_ajax_oauth_finish() {
10651066
);
10661067
Mailchimp_Woocommerce_Event::track('connect_accounts_oauth:complete', new DateTime());
10671068

1068-
do_action('mailchimp_woocommerce_connected_to_mailchimp');
1069+
do_action('mailchimp_woocommerce_connected_to_mailchimp', $api_key);
10691070

10701071
wp_send_json_success( $response );
10711072
} else {
@@ -1234,7 +1235,8 @@ public function mailchimp_woocommerce_ajax_create_account_signup() {
12341235
Mailchimp_Woocommerce_Event::track('connect_accounts:create_account_complete', new DateTime());
12351236
$result = json_decode( $response['body'], true);
12361237
$options = get_option($this->plugin_name, array());
1237-
$options['mailchimp_api_key'] = $result['data']['oauth_token'].'-'.$result['data']['dc'];
1238+
$api_key = $result['data']['oauth_token'].'-'.$result['data']['dc'];
1239+
$options['mailchimp_api_key'] = $api_key;
12381240
// go straight to the DB and update the options to bypass any filters.
12391241
$wpdb->update(
12401242
$wpdb->options,
@@ -1245,25 +1247,48 @@ public function mailchimp_woocommerce_ajax_create_account_signup() {
12451247
Mailchimp_Woocommerce_Event::track('account:verify_email', new DateTime());
12461248
$response_body->redirect = admin_url('admin.php?page=mailchimp-woocommerce');
12471249

1248-
do_action('mailchimp_woocommerce_connected_to_mailchimp');
1250+
do_action('mailchimp_woocommerce_connected_to_mailchimp', $api_key);
12491251

12501252
wp_send_json_success( $response_body );
12511253
} elseif ( $response['response']['code'] == 404 ) {
12521254
wp_send_json_error( array( 'success' => false ) );
12531255
} else {
1256+
$response_error = json_decode( $response_body->error, true );
12541257
$username = preg_replace( '/[^A-Za-z0-9\-\@\.]/', '', $_POST['data']['username'] );
12551258
$suggestion = wp_remote_get( 'https://woocommerce.mailchimpapp.com/api/usernames/suggestions/' . $username );
12561259
$suggested_username = json_decode( $suggestion['body'] )->data;
1260+
12571261
wp_send_json_error(
12581262
array(
12591263
'success' => false,
1260-
'suggest_login' => true,
1264+
'errors' => $response_error['errors'],
12611265
'suggested_username' => $suggested_username,
1266+
'response' => $response,
1267+
'response_body' => $response_body,
12621268
)
12631269
);
12641270
}
12651271
}
12661272

1273+
public function connect_account_flow_switch_account()
1274+
{
1275+
if (
1276+
current_user_can( mailchimp_get_allowed_capability() )
1277+
&& isset( $_POST['data']['_disconnect-nonce'] )
1278+
&& wp_verify_nonce( $_POST['data']['_disconnect-nonce'], '_disconnect-nonce-' . mailchimp_get_store_id() )
1279+
) {
1280+
$this->disconnect_store();
1281+
\Mailchimp_Woocommerce_DB_Helpers::delete_option('mailchimp-woocommerce-waiting-for-login');
1282+
1283+
return wp_send_json_success(array(
1284+
'success' => true,
1285+
'redirect' => admin_url('admin.php?page=mailchimp-woocommerce')
1286+
));
1287+
} else {
1288+
return wp_send_json_success(array('success' => false, 'message' => 'Failed to disconnect account'));
1289+
}
1290+
}
1291+
12671292
/**
12681293
* @param $input
12691294
*

admin/js/mailchimp-woocommerce-create-account.js

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,45 @@
5555
}
5656
})
5757

58+
59+
$('#js-mc-woocommerce-switch-account').submit((e) => {
60+
e.preventDefault();
61+
62+
$("#js-mc-woocommerce-switch-account-button").attr('disabled', true)
63+
$("#js-mc-woocommerce-switch-account-button .mc-wc-loading").removeClass('hidden')
64+
65+
let formData = $(e.target).serializeArray()
66+
let formDataObject = {};
67+
formData.map(obj => {
68+
let newObj = {}
69+
formDataObject[obj.name] = obj.value
70+
return newObj
71+
})
72+
73+
var data = {
74+
action: 'mailchimp_woocommerce_switch_account',
75+
data: formDataObject
76+
};
77+
78+
$.ajax({
79+
type: "post",
80+
dataType: "json",
81+
url: phpVars.ajaxurl,
82+
data: data,
83+
success: function (response) {
84+
console.log('response', response.data)
85+
if (response.data.success) {
86+
window.location.href = response.data.redirect
87+
} else {
88+
alert(response.data.message)
89+
}
90+
},
91+
error: function (error) {
92+
console.log('error', error)
93+
}
94+
})
95+
});
96+
5897
$('.js-mc-woocommerce-activate-account').submit((e) => {
5998
e.preventDefault();
6099
$("#mc-woocommerce-create-activate-account").attr('disabled', true)
@@ -89,20 +128,35 @@
89128
action:'mailchimp_woocommerce_create_account_signup',
90129
data: postData
91130
};
131+
$('#mc-woocommerce-error-box').empty();
92132
$.ajax({
93133
type : "post",
94134
dataType : "json",
95135
url : phpVars.ajaxurl,
96136
data : data,
97137
success: function(response) {
98-
if (response.data.suggest_login) {
99-
$('.js-mc-woocommerce-activate-account').addClass('hidden')
100-
$("#mc-woocommerce-create-activate-account").attr('disabled', false)
101-
$("#mc-woocommerce-create-activate-account .mc-wc-loading").addClass('hidden')
102-
103-
$('.js-mc-woocommerce-suggest-to-login').removeClass('hidden');
104-
$('.js-mc-woocommerce-email').text(formDataObject.email)
105-
$('.mailchimp-connect').attr('href', response.data.login_link)
138+
console.log('response', response.data)
139+
140+
if (!response.data.success) {
141+
let errorHasUsername = response.data.errors?.some(err => err.field === 'username')
142+
if (errorHasUsername) {
143+
$('.js-mc-woocommerce-activate-account').addClass('hidden')
144+
$("#mc-woocommerce-create-activate-account").attr('disabled', false)
145+
$("#mc-woocommerce-create-activate-account .mc-wc-loading").addClass('hidden')
146+
147+
$('.js-mc-woocommerce-suggest-to-login').removeClass('hidden');
148+
$('.js-mc-woocommerce-email').text(formDataObject.email)
149+
$('.mailchimp-connect').attr('href', response.data.login_link)
150+
} else if (response.data.errors) {
151+
let errorMessage = ''
152+
console.log('errors', response.data.errors)
153+
response.data.errors?.forEach(err => {
154+
errorMessage += `<div class="error">${err.message}</div>`
155+
});
156+
$("#mc-woocommerce-create-activate-account").attr('disabled', false)
157+
$("#mc-woocommerce-create-activate-account .mc-wc-loading").addClass('hidden')
158+
$('#mc-woocommerce-error-box').append(errorMessage)
159+
}
106160
} else {
107161
window.location.href = response.data.redirect
108162
}

admin/v2/templates/connect-accounts/create-account-page.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
if (!$signup_initiated) {
2424
Mailchimp_Woocommerce_Event::track('connect_accounts:view_create_account', new \DateTime());
2525
}
26+
$store_id = mailchimp_get_store_id();
27+
2628
?>
2729
<div id="mc-woocommerce-create-account">
2830
<input type="hidden" name="signup_initiated" value="<?php echo esc_attr(!!$signup_initiated) ?>" />
@@ -293,16 +295,17 @@
293295
</p>
294296
</div>
295297
<div class="box">
298+
<div id="mc-woocommerce-error-box"></div>
296299
<button type="submit" id="mc-woocommerce-create-activate-account" class="button button-primary create-account-save">
297-
<span class="mc-wc-loading hidden">
298-
<svg class="animate-spin" width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
299-
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
300-
stroke-width="4"></circle>
301-
<path class="opacity-75" fill="currentColor"
302-
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
303-
</svg>
304-
</span>
305-
<?php esc_html_e( 'Activate Account', 'mailchimp-for-woocommerce' ); ?>
300+
<span class="mc-wc-loading hidden">
301+
<svg class="animate-spin" width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
302+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
303+
stroke-width="4"></circle>
304+
<path class="opacity-75" fill="currentColor"
305+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
306+
</svg>
307+
</span>
308+
<?php esc_html_e( 'Activate Account', 'mailchimp-for-woocommerce' ); ?>
306309
</button>
307310
</div>
308311
</form>
@@ -369,7 +372,23 @@
369372
<span class="email-opener">Open Outlook</span>
370373
</a>
371374
</div>
372-
</div>
375+
376+
<div class="mc-wc-button-disconnect">
377+
<form id="js-mc-woocommerce-switch-account">
378+
<?php wp_nonce_field( '_disconnect-nonce-' . $store_id, '_disconnect-nonce' ); ?>
379+
<button id="js-mc-woocommerce-switch-account-button" type="submit" class="button create-account-save">
380+
<span class="mc-wc-loading hidden">
381+
<svg class="animate-spin" width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
382+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
383+
stroke-width="4"></circle>
384+
<path class="opacity-75" fill="currentColor"
385+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
386+
</svg>
387+
</span>
388+
<?php esc_html_e('Switch account', 'mailchimp-for-woocommerce' ); ?></button>
389+
</form>
390+
</div>
391+
</div>
373392
<div id="mailchimp_woocommerce_options" class="js-mc-woocommerce-suggest-to-login hidden">
374393
<div class="title"><?php echo esc_html__( 'Login', 'mailchimp-for-woocommerce' ) ?></div>
375394
<p class="h4"><?php echo esc_html__( 'It seems account with this email already created. You may try to login with this username.', 'mailchimp-for-woocommerce' ) ?><span class="js-mc-woocommerce-email"></span></p>

0 commit comments

Comments
 (0)