MailChimp for WooCommerce - Version 1.0.2

Version Description

Download this release

Release Info

Developer MailChimp
Plugin Icon wp plugin MailChimp for WooCommerce
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0.0 to 1.0.2

Files changed (40) hide show
  1. README.md +2 -6
  2. README.txt +40 -5
  3. admin/class-mailchimp-woocommerce-admin.php +10 -6
  4. admin/partials/mailchimp-woocommerce-admin-tabs.php +6 -1
  5. admin/partials/tabs/store_info.php +1 -1
  6. changelog.md +32 -0
  7. includes/api/assets/class-mailchimp-address.php +15 -15
  8. includes/api/assets/class-mailchimp-cart.php +12 -12
  9. includes/api/assets/class-mailchimp-customer.php +19 -19
  10. includes/api/assets/class-mailchimp-line-item.php +9 -9
  11. includes/api/assets/class-mailchimp-order.php +32 -32
  12. includes/api/assets/class-mailchimp-product-variation.php +11 -11
  13. includes/api/assets/class-mailchimp-product.php +15 -15
  14. includes/api/assets/class-mailchimp-store.php +39 -18
  15. includes/api/class-mailchimp-api.php +144 -94
  16. includes/api/class-mailchimp-woocommerce-create-list-submission.php +3 -3
  17. includes/api/class-mailchimp-woocommerce-transform-orders.php +11 -11
  18. includes/api/class-mailchimp-woocommerce-transform-products.php +26 -11
  19. includes/api/errors/class-mailchimp-error.php +1 -1
  20. includes/api/errors/class-mailchimp-server-error.php +1 -1
  21. includes/api/helpers/class-mailchimp-woocommerce-api-currency-codes.php +1 -1
  22. includes/api/helpers/class-mailchimp-woocommerce-api-locales.php +2 -2
  23. includes/class-mailchimp-woocommerce-options.php +3 -3
  24. includes/class-mailchimp-woocommerce-service.php +2 -2
  25. includes/class-mailchimp-woocommerce.php +1 -1
  26. includes/processes/class-mailchimp-woocommerce-abstract-sync.php +10 -4
  27. includes/processes/class-mailchimp-woocommerce-cart-update.php +7 -7
  28. includes/processes/class-mailchimp-woocommerce-process-orders.php +10 -6
  29. includes/processes/class-mailchimp-woocommerce-process-products.php +6 -6
  30. includes/processes/class-mailchimp-woocommerce-single-order.php +8 -3
  31. includes/processes/class-mailchimp-woocommerce-single-product.php +7 -7
  32. includes/slack/Contracts/Http/Interactor.php +2 -2
  33. includes/slack/Core/Commander.php +207 -207
  34. includes/slack/Http/CurlInteractor.php +4 -4
  35. includes/slack/Http/SlackResponse.php +3 -3
  36. includes/slack/Logger.php +2 -2
  37. includes/vendor/queue/classes/worker/wp-worker.php +1 -1
  38. mailchimp-woocommerce.php +35 -7
  39. public/class-mailchimp-woocommerce-public.php +1 -1
  40. public/js/mailchimp-woocommerce-public.js +71 -76
README.md CHANGED
@@ -1,22 +1,18 @@
1
  # MailChimp for Woocommerce Integration
2
 
3
- # Updated 9.23.16 with a fix to delete carts for completed orders.
4
- MailChimp for WooCommerce is a plugin that adds customers and their order information to your MailChimp list. Use WooCommerce data to create targeted campaigns, track sales, recommend products, send Abandoned Cart emails, and more.
5
-
6
  In this article, you’ll learn how to connect MailChimp for WooCommerce.
7
 
8
  #Before You Start#
9
 
10
  **Here are some things to know before you begin this process.**
11
 
12
- - This tutorial is intended for use with a beta version of MailChimp for WooCommerce.
13
  - We recommend you use this plugin in a staging environment before installing on production servers.
14
  - This process requires an API Key from your MailChimp account. If you aren’t sure how to generate a MailChimp API Key, read [About API Keys.](http://kb.mailchimp.com/integrations/api-integrations/about-api-keys)
15
  - This plugin supports MailChimp’s [Abandoned Cart Automation](http://kb.mailchimp.com/automation/create-an-abandoned-cart-workflow) feature.
16
- WooCommerce customers who haven't signed up for marketing emails will appear in the Transactional portion of your list, and cannot be exported. See [View or Export a List.](http://kb.mailchimp.com/lists/managing-subscribers/view-or-export-a-list)
17
  - To switch lists or accounts, you must deactivate and delete the plugin, then re-install it.
18
  - In e-commerce reports and on subscriber profile pages, product variants will display as the parent product.
19
- - This beta version of MailChimp for WooCommerce may have issues displaying grouped orders.
20
 
21
  #Task Roadmap#
22
  **Here’s a brief overview of this multi-step process.**
1
  # MailChimp for Woocommerce Integration
2
 
 
 
 
3
  In this article, you’ll learn how to connect MailChimp for WooCommerce.
4
 
5
  #Before You Start#
6
 
7
  **Here are some things to know before you begin this process.**
8
 
 
9
  - We recommend you use this plugin in a staging environment before installing on production servers.
10
  - This process requires an API Key from your MailChimp account. If you aren’t sure how to generate a MailChimp API Key, read [About API Keys.](http://kb.mailchimp.com/integrations/api-integrations/about-api-keys)
11
  - This plugin supports MailChimp’s [Abandoned Cart Automation](http://kb.mailchimp.com/automation/create-an-abandoned-cart-workflow) feature.
12
+ - WooCommerce customers who haven't signed up for marketing emails will appear in the Transactional portion of your list, and cannot be exported. See [View or Export a List.](http://kb.mailchimp.com/lists/managing-subscribers/view-or-export-a-list)
13
  - To switch lists or accounts, you must deactivate and delete the plugin, then re-install it.
14
  - In e-commerce reports and on subscriber profile pages, product variants will display as the parent product.
15
+
16
 
17
  #Task Roadmap#
18
  **Here’s a brief overview of this multi-step process.**
README.txt CHANGED
@@ -1,13 +1,48 @@
1
- === vextras-woocommerce ===
2
- Contributors: ryanhungate
3
  Tags: ecommerce,email,workflows,mailchimp
4
  Donate link: https://mailchimp.com
5
  Requires at least: 4.3
6
- Tested up to: 4.4.2
7
- Stable tag: 4.4.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- MailChimp - WooCommerce integration.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  == Installation ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === MailChimp for WooCommerce ===
2
+ Contributors: ryanhungate, MailChimp
3
  Tags: ecommerce,email,workflows,mailchimp
4
  Donate link: https://mailchimp.com
5
  Requires at least: 4.3
6
+ Tested up to: 4.6.1
7
+ Stable tag: 4.6.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Connect your store to your MailChimp list to track sales, create targeted emails, send abandoned cart emails, and more.
12
+
13
+ == Description ==
14
+ - MailChimp for WooCommerce is a free plugin that connects your WooCommerce store with your MailChimp account.
15
+ - Your customers and their purchase data are automatically synced with MailChimp, so you can create targeted email campaigns based on buying behavior.
16
+
17
+ You’ll have the power to:
18
+
19
+ - Sync list and purchase data
20
+ - Create abandoned cart Automation workflows
21
+ - Send product recommendations
22
+ - Segment based on purchase history
23
+ - View your results and measure ROI
24
+
25
+ ###A note for current WooCommerce integration users
26
+ This plugin supports our most powerful API 3.0 features, and is intended for users who have not yet integrated their WooCommerce stores with MailChimp.
27
+
28
+ You can run this new integration at the same time as your current WooCommerce integration for MailChimp. However, data from the older integration will display separately in subscriber profiles, and can’t be used with e-commerce features that require API 3.0.
29
 
30
  == Installation ==
31
+ ###Before You Start
32
+ Here are some things to know before you begin this process.
33
+
34
+ - This plugin requires you to have the [WooCommerce plugin](https://woocommerce.com/) already installed and activated in WordPress.
35
+ - Your hosting environment must meet [WooCommerce's minimum requirements](https://docs.woocommerce.com/document/server-requirements), including PHP 5.6 or greater.
36
+ - We recommend you use this plugin in a staging environment before installing it on production servers. To learn more about staging environments, [check out these related Wordpress plugins](https://wordpress.org/plugins/search.php?q=staging).
37
+ - MailChimp for WooCommerce syncs the customer’s first name, last name, email address, and orders.
38
+ - WooCommerce customers who haven't signed up for marketing emails will appear in the **Transactional** portion of your list, and cannot be exported.
39
+
40
+ ###Task Roadmap
41
+ You’ll need to do a few things to connect your WooCommerce store to MailChimp.
42
+
43
+ - Download the plugin.
44
+ - Install the plugin on your WordPress Admin site.
45
+ - Connect the plugin with your MailChimp API Key.
46
+ - Configure your list settings to complete the data sync process.
47
+
48
+ For more information on settings and configuration, please visit our Knowledge Base: [http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce](http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce)
admin/class-mailchimp-woocommerce-admin.php CHANGED
@@ -208,7 +208,7 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
208
  'mailchimp_account_info_username' => null,
209
  );
210
 
211
- $api = new MailChimpApi($data['mailchimp_api_key']);
212
 
213
  $valid = true;
214
 
@@ -263,6 +263,10 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
263
  add_settings_error('mailchimp_store_settings', '', 'As part of the MailChimp Terms of Use, we require a contact email and a physical mailing address.');
264
  }
265
 
 
 
 
 
266
  $this->setData('validation.store_info', false);
267
  return array();
268
  }
@@ -472,7 +476,7 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
472
  }
473
  }
474
 
475
- $submission = new MailChimp_CreateListSubmission();
476
 
477
  // allow the subscribers to choose preferred email type (html or text).
478
  $submission->setEmailTypeOption(true);
@@ -507,7 +511,7 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
507
 
508
  return $list_id;
509
 
510
- } catch (MailChimp_Error $e) {
511
  $this->setData('errors.mailchimp_list', $e->getMessage());
512
  return false;
513
  }
@@ -529,7 +533,7 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
529
 
530
  if (!($store = $this->api()->getStore($site_url))) {
531
  $new = true;
532
- $store = new MailChimp_Store();
533
  }
534
 
535
  $list_id = $this->array_get($data, 'mailchimp_list', false);
@@ -571,11 +575,11 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
571
 
572
  /**
573
  * @param array $data
574
- * @return MailChimp_Address
575
  */
576
  private function address(array $data)
577
  {
578
- $address = new MailChimp_Address();
579
 
580
  if (isset($data['store_street']) && $data['store_street']) {
581
  $address->setAddress1($data['store_street']);
208
  'mailchimp_account_info_username' => null,
209
  );
210
 
211
+ $api = new MailChimp_WooCommerce_MailChimpApi($data['mailchimp_api_key']);
212
 
213
  $valid = true;
214
 
263
  add_settings_error('mailchimp_store_settings', '', 'As part of the MailChimp Terms of Use, we require a contact email and a physical mailing address.');
264
  }
265
 
266
+ if (empty($data['store_phone']) || strlen($data['store_phone']) <= 6) {
267
+ add_settings_error('mailchimp_store_settings', '', 'As part of the MailChimp Terms of Use, we require a valid phone number for your store.');
268
+ }
269
+
270
  $this->setData('validation.store_info', false);
271
  return array();
272
  }
476
  }
477
  }
478
 
479
+ $submission = new MailChimp_WooCommerce_CreateListSubmission();
480
 
481
  // allow the subscribers to choose preferred email type (html or text).
482
  $submission->setEmailTypeOption(true);
511
 
512
  return $list_id;
513
 
514
+ } catch (MailChimp_WooCommerce_Error $e) {
515
  $this->setData('errors.mailchimp_list', $e->getMessage());
516
  return false;
517
  }
533
 
534
  if (!($store = $this->api()->getStore($site_url))) {
535
  $new = true;
536
+ $store = new MailChimp_WooCommerce_Store();
537
  }
538
 
539
  $list_id = $this->array_get($data, 'mailchimp_list', false);
575
 
576
  /**
577
  * @param array $data
578
+ * @return MailChimp_WooCommerce_Address
579
  */
580
  private function address(array $data)
581
  {
582
+ $address = new MailChimp_WooCommerce_Address();
583
 
584
  if (isset($data['store_street']) && $data['store_street']) {
585
  $address->setAddress1($data['store_street']);
admin/partials/mailchimp-woocommerce-admin-tabs.php CHANGED
@@ -24,9 +24,14 @@ if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
24
  $show_sync_tab = true;
25
  }
26
  }
27
-
28
  ?>
29
 
 
 
 
 
 
 
30
  <!-- Create a header in the default WordPress 'wrap' container -->
31
  <div class="wrap">
32
  <div id="icon-themes" class="icon32"></div>
24
  $show_sync_tab = true;
25
  }
26
  }
 
27
  ?>
28
 
29
+ <?php if (!defined('PHP_VERSION_ID') || (PHP_VERSION_ID < 50600)): ?>
30
+ <div class="error notice is-dismissable">
31
+ <p><?php _e('MailChimp says: Please upgrade your PHP version to a minimum of 5.6', 'mailchimp-woocommerce'); ?></p>
32
+ </div>
33
+ <?php endif; ?>
34
+
35
  <!-- Create a header in the default WordPress 'wrap' container -->
36
  <div class="wrap">
37
  <div id="icon-themes" class="icon32"></div>
admin/partials/tabs/store_info.php CHANGED
@@ -121,7 +121,7 @@ if (!$handler->hasValidApiKey()) {
121
  <select name="<?php echo $this->plugin_name; ?>[store_currency_code]" style="width:30%" required>
122
  <?php
123
  $selected_currency_code = isset($options['store_currency_code']) && !empty($options['store_currency_code']) ? $options['store_currency_code'] : 'USD';
124
- foreach (MailChimp_Api_CurrencyCodes::lists() as $key => $value ) {
125
  echo '<option value="' . esc_attr( $key ) . '" ' . selected($key === $selected_currency_code, true, false ) . '>' . esc_html( $value ) . '</option>';
126
  }
127
  ?>
121
  <select name="<?php echo $this->plugin_name; ?>[store_currency_code]" style="width:30%" required>
122
  <?php
123
  $selected_currency_code = isset($options['store_currency_code']) && !empty($options['store_currency_code']) ? $options['store_currency_code'] : 'USD';
124
+ foreach (MailChimp_WooCommerce_CurrencyCodes::lists() as $key => $value ) {
125
  echo '<option value="' . esc_attr( $key ) . '" ' . selected($key === $selected_currency_code, true, false ) . '>' . esc_html( $value ) . '</option>';
126
  }
127
  ?>
changelog.md CHANGED
@@ -1,3 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ** 0.1.11 **
2
  * removed an extra debug log that was not needed
3
 
1
+ ** 0.1.22 **
2
+ * flag quantity as 1 if the product does not manage inventory
3
+
4
+ ** 0.1.21 **
5
+ * php version check to display warnings < 5.5
6
+
7
+ ** 0.1.19 **
8
+ * fix campaign tracking on new orders
9
+
10
+ ** 0.1.18 **
11
+ * check woocommerce dependency before activating the plugin
12
+
13
+ ** 0.1.17 **
14
+ * fix php version syntax errors for array's
15
+
16
+ ** 0.1.16 **
17
+ * fix namespace conflicts
18
+ * fix free order 0.00 issue
19
+ * fix product variant naming issue
20
+
21
+ ** 0.1.15 **
22
+ * adding special MailChimp header to requests
23
+
24
+ ** 0.1.14 **
25
+ * removing jquery dependencies
26
+
27
+ ** 0.1.13 **
28
+ * fixing a number format issue on total_spent
29
+
30
+ ** 0.1.12 **
31
+ * skipping orders placed through amazon due to seller agreements
32
+
33
  ** 0.1.11 **
34
  * removed an extra debug log that was not needed
35
 
includes/api/assets/class-mailchimp-address.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 3/8/16
9
  * Time: 2:22 PM
10
  */
11
- class MailChimp_Address
12
  {
13
  protected $type;
14
  protected $name;
@@ -54,7 +54,7 @@ class MailChimp_Address
54
 
55
  /**
56
  * @param mixed $name
57
- * @return MailChimp_Address
58
  */
59
  public function setName($name)
60
  {
@@ -73,7 +73,7 @@ class MailChimp_Address
73
 
74
  /**
75
  * @param mixed $address1
76
- * @return MailChimp_Address
77
  */
78
  public function setAddress1($address1)
79
  {
@@ -92,7 +92,7 @@ class MailChimp_Address
92
 
93
  /**
94
  * @param mixed $address2
95
- * @return MailChimp_Address
96
  */
97
  public function setAddress2($address2)
98
  {
@@ -111,7 +111,7 @@ class MailChimp_Address
111
 
112
  /**
113
  * @param mixed $city
114
- * @return MailChimp_Address
115
  */
116
  public function setCity($city)
117
  {
@@ -130,7 +130,7 @@ class MailChimp_Address
130
 
131
  /**
132
  * @param mixed $province
133
- * @return MailChimp_Address
134
  */
135
  public function setProvince($province)
136
  {
@@ -149,7 +149,7 @@ class MailChimp_Address
149
 
150
  /**
151
  * @param mixed $province_code
152
- * @return MailChimp_Address
153
  */
154
  public function setProvinceCode($province_code)
155
  {
@@ -168,7 +168,7 @@ class MailChimp_Address
168
 
169
  /**
170
  * @param mixed $postal_code
171
- * @return MailChimp_Address
172
  */
173
  public function setPostalCode($postal_code)
174
  {
@@ -187,7 +187,7 @@ class MailChimp_Address
187
 
188
  /**
189
  * @param mixed $country
190
- * @return MailChimp_Address
191
  */
192
  public function setCountry($country)
193
  {
@@ -206,7 +206,7 @@ class MailChimp_Address
206
 
207
  /**
208
  * @param mixed $country_code
209
- * @return MailChimp_Address
210
  */
211
  public function setCountryCode($country_code)
212
  {
@@ -225,7 +225,7 @@ class MailChimp_Address
225
 
226
  /**
227
  * @param mixed $longitude
228
- * @return MailChimp_Address
229
  */
230
  public function setLongitude($longitude)
231
  {
@@ -244,7 +244,7 @@ class MailChimp_Address
244
 
245
  /**
246
  * @param mixed $latitude
247
- * @return MailChimp_Address
248
  */
249
  public function setLatitude($latitude)
250
  {
@@ -263,7 +263,7 @@ class MailChimp_Address
263
 
264
  /**
265
  * @param mixed $phone
266
- * @return MailChimp_Address
267
  */
268
  public function setPhone($phone)
269
  {
@@ -282,7 +282,7 @@ class MailChimp_Address
282
 
283
  /**
284
  * @param mixed $company
285
- * @return MailChimp_Address
286
  */
287
  public function setCompany($company)
288
  {
@@ -315,7 +315,7 @@ class MailChimp_Address
315
 
316
  /**
317
  * @param array $data
318
- * @return MailChimp_Address
319
  */
320
  public function fromArray(array $data)
321
  {
8
  * Date: 3/8/16
9
  * Time: 2:22 PM
10
  */
11
+ class MailChimp_WooCommerce_Address
12
  {
13
  protected $type;
14
  protected $name;
54
 
55
  /**
56
  * @param mixed $name
57
+ * @return MailChimp_WooCommerce_Address
58
  */
59
  public function setName($name)
60
  {
73
 
74
  /**
75
  * @param mixed $address1
76
+ * @return MailChimp_WooCommerce_Address
77
  */
78
  public function setAddress1($address1)
79
  {
92
 
93
  /**
94
  * @param mixed $address2
95
+ * @return MailChimp_WooCommerce_Address
96
  */
97
  public function setAddress2($address2)
98
  {
111
 
112
  /**
113
  * @param mixed $city
114
+ * @return MailChimp_WooCommerce_Address
115
  */
116
  public function setCity($city)
117
  {
130
 
131
  /**
132
  * @param mixed $province
133
+ * @return MailChimp_WooCommerce_Address
134
  */
135
  public function setProvince($province)
136
  {
149
 
150
  /**
151
  * @param mixed $province_code
152
+ * @return MailChimp_WooCommerce_Address
153
  */
154
  public function setProvinceCode($province_code)
155
  {
168
 
169
  /**
170
  * @param mixed $postal_code
171
+ * @return MailChimp_WooCommerce_Address
172
  */
173
  public function setPostalCode($postal_code)
174
  {
187
 
188
  /**
189
  * @param mixed $country
190
+ * @return MailChimp_WooCommerce_Address
191
  */
192
  public function setCountry($country)
193
  {
206
 
207
  /**
208
  * @param mixed $country_code
209
+ * @return MailChimp_WooCommerce_Address
210
  */
211
  public function setCountryCode($country_code)
212
  {
225
 
226
  /**
227
  * @param mixed $longitude
228
+ * @return MailChimp_WooCommerce_Address
229
  */
230
  public function setLongitude($longitude)
231
  {
244
 
245
  /**
246
  * @param mixed $latitude
247
+ * @return MailChimp_WooCommerce_Address
248
  */
249
  public function setLatitude($latitude)
250
  {
263
 
264
  /**
265
  * @param mixed $phone
266
+ * @return MailChimp_WooCommerce_Address
267
  */
268
  public function setPhone($phone)
269
  {
282
 
283
  /**
284
  * @param mixed $company
285
+ * @return MailChimp_WooCommerce_Address
286
  */
287
  public function setCompany($company)
288
  {
315
 
316
  /**
317
  * @param array $data
318
+ * @return MailChimp_WooCommerce_Address
319
  */
320
  public function fromArray(array $data)
321
  {
includes/api/assets/class-mailchimp-cart.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 7/15/16
9
  * Time: 1:26 PM
10
  */
11
- class MailChimp_Cart
12
  {
13
  protected $store_id;
14
  protected $id;
@@ -63,10 +63,10 @@ class MailChimp_Cart
63
  }
64
 
65
  /**
66
- * @param MailChimp_Customer $customer
67
  * @return $this
68
  */
69
- public function setCustomer(MailChimp_Customer $customer)
70
  {
71
  $this->customer = $customer;
72
 
@@ -74,12 +74,12 @@ class MailChimp_Cart
74
  }
75
 
76
  /**
77
- * @return MailChimp_Customer
78
  */
79
  public function getCustomer()
80
  {
81
  if (empty($this->customer)) {
82
- $this->customer = new MailChimp_Customer();
83
  }
84
 
85
  return $this->customer;
@@ -190,10 +190,10 @@ class MailChimp_Cart
190
  }
191
 
192
  /**
193
- * @param MailChimp_LineItem $item
194
  * @return $this
195
  */
196
- public function addItem(MailChimp_LineItem $item)
197
  {
198
  $this->lines[] = $item;
199
  return $this;
@@ -245,14 +245,14 @@ class MailChimp_Cart
245
 
246
  /**
247
  * @param array $data
248
- * @return MailChimp_Cart
249
  */
250
  public function fromArray(array $data)
251
  {
252
- $singles = [
253
  'store_id', 'id', 'campaign_id', 'checkout_url',
254
  'currency_code', 'order_total', 'tax_total',
255
- ];
256
 
257
  foreach ($singles as $key) {
258
  if (array_key_exists($key, $data)) {
@@ -261,12 +261,12 @@ class MailChimp_Cart
261
  }
262
 
263
  if (array_key_exists('customer', $data) && is_array($data['customer'])) {
264
- $this->customer = (new MailChimp_Customer())->fromArray($data['customer']);
265
  }
266
 
267
  if (array_key_exists('lines', $data) && is_array($data['lines'])) {
268
  foreach ($data['lines'] as $line_item) {
269
- $this->lines[] = (new MailChimp_LineItem)->fromArray($line_item);
270
  }
271
  }
272
 
8
  * Date: 7/15/16
9
  * Time: 1:26 PM
10
  */
11
+ class MailChimp_WooCommerce_Cart
12
  {
13
  protected $store_id;
14
  protected $id;
63
  }
64
 
65
  /**
66
+ * @param MailChimp_WooCommerce_Customer $customer
67
  * @return $this
68
  */
69
+ public function setCustomer(MailChimp_WooCommerce_Customer $customer)
70
  {
71
  $this->customer = $customer;
72
 
74
  }
75
 
76
  /**
77
+ * @return MailChimp_WooCommerce_Customer
78
  */
79
  public function getCustomer()
80
  {
81
  if (empty($this->customer)) {
82
+ $this->customer = new MailChimp_WooCommerce_Customer();
83
  }
84
 
85
  return $this->customer;
190
  }
191
 
192
  /**
193
+ * @param MailChimp_WooCommerce_LineItem $item
194
  * @return $this
195
  */
196
+ public function addItem(MailChimp_WooCommerce_LineItem $item)
197
  {
198
  $this->lines[] = $item;
199
  return $this;
245
 
246
  /**
247
  * @param array $data
248
+ * @return MailChimp_WooCommerce_Cart
249
  */
250
  public function fromArray(array $data)
251
  {
252
+ $singles = array(
253
  'store_id', 'id', 'campaign_id', 'checkout_url',
254
  'currency_code', 'order_total', 'tax_total',
255
+ );
256
 
257
  foreach ($singles as $key) {
258
  if (array_key_exists($key, $data)) {
261
  }
262
 
263
  if (array_key_exists('customer', $data) && is_array($data['customer'])) {
264
+ $this->customer = (new MailChimp_WooCommerce_Customer())->fromArray($data['customer']);
265
  }
266
 
267
  if (array_key_exists('lines', $data) && is_array($data['lines'])) {
268
  foreach ($data['lines'] as $line_item) {
269
+ $this->lines[] = (new MailChimp_WooCommerce_LineItem)->fromArray($line_item);
270
  }
271
  }
272
 
includes/api/assets/class-mailchimp-customer.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 3/8/16
9
  * Time: 2:16 PM
10
  */
11
- class MailChimp_Customer
12
  {
13
  protected $id = null;
14
  protected $email_address = null;
@@ -47,7 +47,7 @@ class MailChimp_Customer
47
 
48
  /**
49
  * @param null $id
50
- * @return MailChimp_Customer
51
  */
52
  public function setId($id)
53
  {
@@ -66,7 +66,7 @@ class MailChimp_Customer
66
 
67
  /**
68
  * @param null $email_address
69
- * @return MailChimp_Customer
70
  */
71
  public function setEmailAddress($email_address)
72
  {
@@ -85,7 +85,7 @@ class MailChimp_Customer
85
 
86
  /**
87
  * @param null $opt_in_status
88
- * @return MailChimp_Customer
89
  */
90
  public function setOptInStatus($opt_in_status)
91
  {
@@ -104,7 +104,7 @@ class MailChimp_Customer
104
 
105
  /**
106
  * @param null $company
107
- * @return MailChimp_Customer
108
  */
109
  public function setCompany($company)
110
  {
@@ -123,7 +123,7 @@ class MailChimp_Customer
123
 
124
  /**
125
  * @param null $first_name
126
- * @return MailChimp_Customer
127
  */
128
  public function setFirstName($first_name)
129
  {
@@ -142,7 +142,7 @@ class MailChimp_Customer
142
 
143
  /**
144
  * @param null $last_name
145
- * @return MailChimp_Customer
146
  */
147
  public function setLastName($last_name)
148
  {
@@ -161,7 +161,7 @@ class MailChimp_Customer
161
 
162
  /**
163
  * @param null $orders_count
164
- * @return MailChimp_Customer
165
  */
166
  public function setOrdersCount($orders_count)
167
  {
@@ -180,7 +180,7 @@ class MailChimp_Customer
180
 
181
  /**
182
  * @param null $total_spent
183
- * @return MailChimp_Customer
184
  */
185
  public function setTotalSpent($total_spent)
186
  {
@@ -190,21 +190,21 @@ class MailChimp_Customer
190
  }
191
 
192
  /**
193
- * @return MailChimp_Address
194
  */
195
  public function getAddress()
196
  {
197
  if (empty($this->address)) {
198
- $this->address = new MailChimp_Address();
199
  }
200
  return $this->address;
201
  }
202
 
203
  /**
204
- * @param MailChimp_Address $address
205
- * @return MailChimp_Customer
206
  */
207
- public function setAddress(MailChimp_Address $address)
208
  {
209
  $this->address = $address;
210
 
@@ -226,21 +226,21 @@ class MailChimp_Customer
226
  'first_name' => (string) $this->getFirstName(),
227
  'last_name' => (string) $this->getLastName(),
228
  'orders_count' => (int) $this->getOrdersCount(),
229
- 'total_spent' => number_format($this->getTotalSpent(), 2),
230
  'address' => empty($address) ? null : $address,
231
  ));
232
  }
233
 
234
  /**
235
  * @param array $data
236
- * @return MailChimp_Customer
237
  */
238
  public function fromArray(array $data)
239
  {
240
- $singles = [
241
  'id', 'email_address', 'opt_in_status', 'company',
242
  'first_name', 'last_name', 'orders_count', 'total_spent',
243
- ];
244
 
245
  foreach ($singles as $key) {
246
  if (array_key_exists($key, $data)) {
@@ -249,7 +249,7 @@ class MailChimp_Customer
249
  }
250
 
251
  if (array_key_exists('address', $data) && is_array($data['address'])) {
252
- $this->address = (new MailChimp_Address())->fromArray($data['address']);
253
  }
254
 
255
  return $this;
8
  * Date: 3/8/16
9
  * Time: 2:16 PM
10
  */
11
+ class MailChimp_WooCommerce_Customer
12
  {
13
  protected $id = null;
14
  protected $email_address = null;
47
 
48
  /**
49
  * @param null $id
50
+ * @return MailChimp_WooCommerce_Customer
51
  */
52
  public function setId($id)
53
  {
66
 
67
  /**
68
  * @param null $email_address
69
+ * @return MailChimp_WooCommerce_Customer
70
  */
71
  public function setEmailAddress($email_address)
72
  {
85
 
86
  /**
87
  * @param null $opt_in_status
88
+ * @return MailChimp_WooCommerce_Customer
89
  */
90
  public function setOptInStatus($opt_in_status)
91
  {
104
 
105
  /**
106
  * @param null $company
107
+ * @return MailChimp_WooCommerce_Customer
108
  */
109
  public function setCompany($company)
110
  {
123
 
124
  /**
125
  * @param null $first_name
126
+ * @return MailChimp_WooCommerce_Customer
127
  */
128
  public function setFirstName($first_name)
129
  {
142
 
143
  /**
144
  * @param null $last_name
145
+ * @return MailChimp_WooCommerce_Customer
146
  */
147
  public function setLastName($last_name)
148
  {
161
 
162
  /**
163
  * @param null $orders_count
164
+ * @return MailChimp_WooCommerce_Customer
165
  */
166
  public function setOrdersCount($orders_count)
167
  {
180
 
181
  /**
182
  * @param null $total_spent
183
+ * @return MailChimp_WooCommerce_Customer
184
  */
185
  public function setTotalSpent($total_spent)
186
  {
190
  }
191
 
192
  /**
193
+ * @return MailChimp_WooCommerce_Address
194
  */
195
  public function getAddress()
196
  {
197
  if (empty($this->address)) {
198
+ $this->address = new MailChimp_WooCommerce_Address();
199
  }
200
  return $this->address;
201
  }
202
 
203
  /**
204
+ * @param MailChimp_WooCommerce_Address $address
205
+ * @return MailChimp_WooCommerce_Customer
206
  */
207
+ public function setAddress(MailChimp_WooCommerce_Address $address)
208
  {
209
  $this->address = $address;
210
 
226
  'first_name' => (string) $this->getFirstName(),
227
  'last_name' => (string) $this->getLastName(),
228
  'orders_count' => (int) $this->getOrdersCount(),
229
+ 'total_spent' => floatval(number_format($this->getTotalSpent(), 2)),
230
  'address' => empty($address) ? null : $address,
231
  ));
232
  }
233
 
234
  /**
235
  * @param array $data
236
+ * @return MailChimp_WooCommerce_Customer
237
  */
238
  public function fromArray(array $data)
239
  {
240
+ $singles = array(
241
  'id', 'email_address', 'opt_in_status', 'company',
242
  'first_name', 'last_name', 'orders_count', 'total_spent',
243
+ );
244
 
245
  foreach ($singles as $key) {
246
  if (array_key_exists($key, $data)) {
249
  }
250
 
251
  if (array_key_exists('address', $data) && is_array($data['address'])) {
252
+ $this->address = (new MailChimp_WooCommerce_Address())->fromArray($data['address']);
253
  }
254
 
255
  return $this;
includes/api/assets/class-mailchimp-line-item.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 3/8/16
9
  * Time: 2:16 PM
10
  */
11
- class MailChimp_LineItem
12
  {
13
  protected $id;
14
  protected $product_id;
@@ -36,11 +36,11 @@ class MailChimp_LineItem
36
  * @param $variant_id
37
  * @param $quantity
38
  * @param $price
39
- * @return MailChimp_LineItem
40
  */
41
  public static function make($id, $product_id, $variant_id, $quantity, $price)
42
  {
43
- $item = new MailChimp_LineItem();
44
  $item->id = $id;
45
  $item->product_id = $product_id;
46
  $item->product_variant_id = $variant_id;
@@ -60,7 +60,7 @@ class MailChimp_LineItem
60
 
61
  /**
62
  * @param mixed $id
63
- * @return MailChimp_LineItem
64
  */
65
  public function setId($id)
66
  {
@@ -79,7 +79,7 @@ class MailChimp_LineItem
79
 
80
  /**
81
  * @param mixed $product_id
82
- * @return MailChimp_LineItem
83
  */
84
  public function setProductId($product_id)
85
  {
@@ -98,7 +98,7 @@ class MailChimp_LineItem
98
 
99
  /**
100
  * @param mixed $product_variant_id
101
- * @return MailChimp_LineItem
102
  */
103
  public function setProductVariantId($product_variant_id)
104
  {
@@ -117,7 +117,7 @@ class MailChimp_LineItem
117
 
118
  /**
119
  * @param mixed $quantity
120
- * @return MailChimp_LineItem
121
  */
122
  public function setQuantity($quantity)
123
  {
@@ -136,7 +136,7 @@ class MailChimp_LineItem
136
 
137
  /**
138
  * @param mixed $price
139
- * @return MailChimp_LineItem
140
  */
141
  public function setPrice($price)
142
  {
@@ -161,7 +161,7 @@ class MailChimp_LineItem
161
 
162
  /**
163
  * @param array $data
164
- * @return MailChimp_LineItem
165
  */
166
  public function fromArray(array $data)
167
  {
8
  * Date: 3/8/16
9
  * Time: 2:16 PM
10
  */
11
+ class MailChimp_WooCommerce_LineItem
12
  {
13
  protected $id;
14
  protected $product_id;
36
  * @param $variant_id
37
  * @param $quantity
38
  * @param $price
39
+ * @return MailChimp_WooCommerce_LineItem
40
  */
41
  public static function make($id, $product_id, $variant_id, $quantity, $price)
42
  {
43
+ $item = new MailChimp_WooCommerce_LineItem();
44
  $item->id = $id;
45
  $item->product_id = $product_id;
46
  $item->product_variant_id = $variant_id;
60
 
61
  /**
62
  * @param mixed $id
63
+ * @return MailChimp_WooCommerce_LineItem
64
  */
65
  public function setId($id)
66
  {
79
 
80
  /**
81
  * @param mixed $product_id
82
+ * @return MailChimp_WooCommerce_LineItem
83
  */
84
  public function setProductId($product_id)
85
  {
98
 
99
  /**
100
  * @param mixed $product_variant_id
101
+ * @return MailChimp_WooCommerce_LineItem
102
  */
103
  public function setProductVariantId($product_variant_id)
104
  {
117
 
118
  /**
119
  * @param mixed $quantity
120
+ * @return MailChimp_WooCommerce_LineItem
121
  */
122
  public function setQuantity($quantity)
123
  {
136
 
137
  /**
138
  * @param mixed $price
139
+ * @return MailChimp_WooCommerce_LineItem
140
  */
141
  public function setPrice($price)
142
  {
161
 
162
  /**
163
  * @param array $data
164
+ * @return MailChimp_WooCommerce_LineItem
165
  */
166
  public function fromArray(array $data)
167
  {
includes/api/assets/class-mailchimp-order.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 3/8/16
9
  * Time: 2:16 PM
10
  */
11
- class MailChimp_Order
12
  {
13
  protected $id = null;
14
  protected $customer = null;
@@ -24,7 +24,7 @@ class MailChimp_Order
24
  protected $cancelled_at_foreign = null;
25
  protected $shipping_address = null;
26
  protected $billing_address = null;
27
- protected $lines = [];
28
 
29
  /**
30
  * @return array
@@ -49,7 +49,7 @@ class MailChimp_Order
49
 
50
  /**
51
  * @param $id
52
- * @return MailChimp_Order
53
  */
54
  public function setId($id)
55
  {
@@ -67,10 +67,10 @@ class MailChimp_Order
67
  }
68
 
69
  /**
70
- * @param MailChimp_Customer $customer
71
- * @return MailChimp_Order
72
  */
73
- public function setCustomer(MailChimp_Customer $customer)
74
  {
75
  $this->customer = $customer;
76
 
@@ -78,21 +78,21 @@ class MailChimp_Order
78
  }
79
 
80
  /**
81
- * @return null|MailChimp_Customer
82
  */
83
  public function getCustomer()
84
  {
85
  if (empty($this->customer)) {
86
- $this->customer = new MailChimp_Customer();
87
  }
88
  return $this->customer;
89
  }
90
 
91
  /**
92
- * @param MailChimp_LineItem $item
93
  * @return $this
94
  */
95
- public function addItem(MailChimp_LineItem $item)
96
  {
97
  $this->lines[] = $item;
98
  return $this;
@@ -116,7 +116,7 @@ class MailChimp_Order
116
 
117
  /**
118
  * @param null $campaign_id
119
- * @return MailChimp_Order
120
  */
121
  public function setCampaignId($campaign_id)
122
  {
@@ -154,7 +154,7 @@ class MailChimp_Order
154
 
155
  /**
156
  * @param null $fulfillment_status
157
- * @return MailChimp_Order
158
  */
159
  public function setFulfillmentStatus($fulfillment_status)
160
  {
@@ -173,7 +173,7 @@ class MailChimp_Order
173
 
174
  /**
175
  * @param null $currency_code
176
- * @return MailChimp_Order
177
  */
178
  public function setCurrencyCode($currency_code)
179
  {
@@ -192,7 +192,7 @@ class MailChimp_Order
192
 
193
  /**
194
  * @param mixed $order_total
195
- * @return MailChimp_Order
196
  */
197
  public function setOrderTotal($order_total)
198
  {
@@ -211,7 +211,7 @@ class MailChimp_Order
211
 
212
  /**
213
  * @param mixed $tax_total
214
- * @return MailChimp_Order
215
  */
216
  public function setTaxTotal($tax_total)
217
  {
@@ -230,7 +230,7 @@ class MailChimp_Order
230
 
231
  /**
232
  * @param mixed $shipping_total
233
- * @return MailChimp_Order
234
  */
235
  public function setShippingTotal($shipping_total)
236
  {
@@ -297,10 +297,10 @@ class MailChimp_Order
297
  }
298
 
299
  /**
300
- * @param MailChimp_Address $address
301
  * @return $this
302
  */
303
- public function setShippingAddress(MailChimp_Address $address)
304
  {
305
  $this->shipping_address = $address;
306
 
@@ -308,21 +308,21 @@ class MailChimp_Order
308
  }
309
 
310
  /**
311
- * @return MailChimp_Address
312
  */
313
  public function getShippingAddress()
314
  {
315
  if (empty($this->shipping_address)) {
316
- $this->shipping_address = new MailChimp_Address('shipping');
317
  }
318
  return $this->shipping_address;
319
  }
320
 
321
  /**
322
- * @param MailChimp_Address $address
323
  * @return $this
324
  */
325
- public function setBillingAddress(MailChimp_Address $address)
326
  {
327
  $this->billing_address = $address;
328
 
@@ -330,12 +330,12 @@ class MailChimp_Order
330
  }
331
 
332
  /**
333
- * @return MailChimp_Address
334
  */
335
  public function getBillingAddress()
336
  {
337
  if (empty($this->billing_address)) {
338
- $this->billing_address = new MailChimp_Address('billing');
339
  }
340
  return $this->billing_address;
341
  }
@@ -345,7 +345,7 @@ class MailChimp_Order
345
  */
346
  public function toArray()
347
  {
348
- return mailchimp_array_remove_empty(array_filter(array(
349
  'id' => (string) $this->getId(),
350
  'customer' => $this->getCustomer()->toArray(),
351
  'campaign_id' => (string) $this->getCampaignId(),
@@ -361,15 +361,15 @@ class MailChimp_Order
361
  'shipping_address' => $this->getShippingAddress()->toArray(),
362
  'billing_address' => $this->getBillingAddress()->toArray(),
363
  'lines' => array_map(function ($item) {
364
- /** @var MailChimp_LineItem $item */
365
  return $item->toArray();
366
  }, $this->items()),
367
- )));
368
  }
369
 
370
  /**
371
  * @param array $data
372
- * @return MailChimp_Order
373
  */
374
  public function fromArray(array $data)
375
  {
@@ -386,17 +386,17 @@ class MailChimp_Order
386
  }
387
 
388
  if (array_key_exists('shipping_address', $data) && is_array($data['shipping_address'])) {
389
- $this->shipping_address = (new MailChimp_Address())->fromArray($data['shipping_address']);
390
  }
391
 
392
  if (array_key_exists('billing_address', $data) && is_array($data['billing_address'])) {
393
- $this->billing_address = (new MailChimp_Address())->fromArray($data['billing_address']);
394
  }
395
 
396
  if (array_key_exists('lines', $data) && is_array($data['lines'])) {
397
- $this->lines = [];
398
  foreach ($data['lines'] as $line_item) {
399
- $this->lines[] = (new MailChimp_LineItem())->fromArray($line_item);
400
  }
401
  }
402
 
8
  * Date: 3/8/16
9
  * Time: 2:16 PM
10
  */
11
+ class MailChimp_WooCommerce_Order
12
  {
13
  protected $id = null;
14
  protected $customer = null;
24
  protected $cancelled_at_foreign = null;
25
  protected $shipping_address = null;
26
  protected $billing_address = null;
27
+ protected $lines = array();
28
 
29
  /**
30
  * @return array
49
 
50
  /**
51
  * @param $id
52
+ * @return MailChimp_WooCommerce_Order
53
  */
54
  public function setId($id)
55
  {
67
  }
68
 
69
  /**
70
+ * @param MailChimp_WooCommerce_Customer $customer
71
+ * @return MailChimp_WooCommerce_Order
72
  */
73
+ public function setCustomer(MailChimp_WooCommerce_Customer $customer)
74
  {
75
  $this->customer = $customer;
76
 
78
  }
79
 
80
  /**
81
+ * @return null|MailChimp_WooCommerce_Customer
82
  */
83
  public function getCustomer()
84
  {
85
  if (empty($this->customer)) {
86
+ $this->customer = new MailChimp_WooCommerce_Customer();
87
  }
88
  return $this->customer;
89
  }
90
 
91
  /**
92
+ * @param MailChimp_WooCommerce_LineItem $item
93
  * @return $this
94
  */
95
+ public function addItem(MailChimp_WooCommerce_LineItem $item)
96
  {
97
  $this->lines[] = $item;
98
  return $this;
116
 
117
  /**
118
  * @param null $campaign_id
119
+ * @return MailChimp_WooCommerce_Order
120
  */
121
  public function setCampaignId($campaign_id)
122
  {
154
 
155
  /**
156
  * @param null $fulfillment_status
157
+ * @return MailChimp_WooCommerce_Order
158
  */
159
  public function setFulfillmentStatus($fulfillment_status)
160
  {
173
 
174
  /**
175
  * @param null $currency_code
176
+ * @return MailChimp_WooCommerce_Order
177
  */
178
  public function setCurrencyCode($currency_code)
179
  {
192
 
193
  /**
194
  * @param mixed $order_total
195
+ * @return MailChimp_WooCommerce_Order
196
  */
197
  public function setOrderTotal($order_total)
198
  {
211
 
212
  /**
213
  * @param mixed $tax_total
214
+ * @return MailChimp_WooCommerce_Order
215
  */
216
  public function setTaxTotal($tax_total)
217
  {
230
 
231
  /**
232
  * @param mixed $shipping_total
233
+ * @return MailChimp_WooCommerce_Order
234
  */
235
  public function setShippingTotal($shipping_total)
236
  {
297
  }
298
 
299
  /**
300
+ * @param MailChimp_WooCommerce_Address $address
301
  * @return $this
302
  */
303
+ public function setShippingAddress(MailChimp_WooCommerce_Address $address)
304
  {
305
  $this->shipping_address = $address;
306
 
308
  }
309
 
310
  /**
311
+ * @return MailChimp_WooCommerce_Address
312
  */
313
  public function getShippingAddress()
314
  {
315
  if (empty($this->shipping_address)) {
316
+ $this->shipping_address = new MailChimp_WooCommerce_Address('shipping');
317
  }
318
  return $this->shipping_address;
319
  }
320
 
321
  /**
322
+ * @param MailChimp_WooCommerce_Address $address
323
  * @return $this
324
  */
325
+ public function setBillingAddress(MailChimp_WooCommerce_Address $address)
326
  {
327
  $this->billing_address = $address;
328
 
330
  }
331
 
332
  /**
333
+ * @return MailChimp_WooCommerce_Address
334
  */
335
  public function getBillingAddress()
336
  {
337
  if (empty($this->billing_address)) {
338
+ $this->billing_address = new MailChimp_WooCommerce_Address('billing');
339
  }
340
  return $this->billing_address;
341
  }
345
  */
346
  public function toArray()
347
  {
348
+ return mailchimp_array_remove_empty(array(
349
  'id' => (string) $this->getId(),
350
  'customer' => $this->getCustomer()->toArray(),
351
  'campaign_id' => (string) $this->getCampaignId(),
361
  'shipping_address' => $this->getShippingAddress()->toArray(),
362
  'billing_address' => $this->getBillingAddress()->toArray(),
363
  'lines' => array_map(function ($item) {
364
+ /** @var MailChimp_WooCommerce_LineItem $item */
365
  return $item->toArray();
366
  }, $this->items()),
367
+ ));
368
  }
369
 
370
  /**
371
  * @param array $data
372
+ * @return MailChimp_WooCommerce_Order
373
  */
374
  public function fromArray(array $data)
375
  {
386
  }
387
 
388
  if (array_key_exists('shipping_address', $data) && is_array($data['shipping_address'])) {
389
+ $this->shipping_address = (new MailChimp_WooCommerce_Address())->fromArray($data['shipping_address']);
390
  }
391
 
392
  if (array_key_exists('billing_address', $data) && is_array($data['billing_address'])) {
393
+ $this->billing_address = (new MailChimp_WooCommerce_Address())->fromArray($data['billing_address']);
394
  }
395
 
396
  if (array_key_exists('lines', $data) && is_array($data['lines'])) {
397
+ $this->lines = array();
398
  foreach ($data['lines'] as $line_item) {
399
+ $this->lines[] = (new MailChimp_WooCommerce_LineItem())->fromArray($line_item);
400
  }
401
  }
402
 
includes/api/assets/class-mailchimp-product-variation.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 3/8/16
9
  * Time: 2:17 PM
10
  */
11
- class MailChimp_ProductVariation
12
  {
13
  protected $id = null;
14
  protected $title = null;
@@ -48,7 +48,7 @@ class MailChimp_ProductVariation
48
 
49
  /**
50
  * @param null $id
51
- * @return MailChimp_ProductVariation
52
  */
53
  public function setId($id)
54
  {
@@ -67,7 +67,7 @@ class MailChimp_ProductVariation
67
 
68
  /**
69
  * @param null $title
70
- * @return MailChimp_ProductVariation
71
  */
72
  public function setTitle($title)
73
  {
@@ -86,7 +86,7 @@ class MailChimp_ProductVariation
86
 
87
  /**
88
  * @param null $url
89
- * @return MailChimp_ProductVariation
90
  */
91
  public function setUrl($url)
92
  {
@@ -105,7 +105,7 @@ class MailChimp_ProductVariation
105
 
106
  /**
107
  * @param null $sku
108
- * @return MailChimp_ProductVariation
109
  */
110
  public function setSku($sku)
111
  {
@@ -124,7 +124,7 @@ class MailChimp_ProductVariation
124
 
125
  /**
126
  * @param null $price
127
- * @return MailChimp_ProductVariation
128
  */
129
  public function setPrice($price)
130
  {
@@ -143,7 +143,7 @@ class MailChimp_ProductVariation
143
 
144
  /**
145
  * @param null $inventory_quantity
146
- * @return MailChimp_ProductVariation
147
  */
148
  public function setInventoryQuantity($inventory_quantity)
149
  {
@@ -162,7 +162,7 @@ class MailChimp_ProductVariation
162
 
163
  /**
164
  * @param null $image_url
165
- * @return MailChimp_ProductVariation
166
  */
167
  public function setImageUrl($image_url)
168
  {
@@ -181,7 +181,7 @@ class MailChimp_ProductVariation
181
 
182
  /**
183
  * @param null $backorders
184
- * @return MailChimp_ProductVariation
185
  */
186
  public function setBackorders($backorders)
187
  {
@@ -200,7 +200,7 @@ class MailChimp_ProductVariation
200
 
201
  /**
202
  * @param null $visibility
203
- * @return MailChimp_ProductVariation
204
  */
205
  public function setVisibility($visibility)
206
  {
@@ -229,7 +229,7 @@ class MailChimp_ProductVariation
229
 
230
  /**
231
  * @param array $data
232
- * @return MailChimp_ProductVariation
233
  */
234
  public function fromArray(array $data)
235
  {
8
  * Date: 3/8/16
9
  * Time: 2:17 PM
10
  */
11
+ class MailChimp_WooCommerce_ProductVariation
12
  {
13
  protected $id = null;
14
  protected $title = null;
48
 
49
  /**
50
  * @param null $id
51
+ * @return MailChimp_WooCommerce_ProductVariation
52
  */
53
  public function setId($id)
54
  {
67
 
68
  /**
69
  * @param null $title
70
+ * @return MailChimp_WooCommerce_ProductVariation
71
  */
72
  public function setTitle($title)
73
  {
86
 
87
  /**
88
  * @param null $url
89
+ * @return MailChimp_WooCommerce_ProductVariation
90
  */
91
  public function setUrl($url)
92
  {
105
 
106
  /**
107
  * @param null $sku
108
+ * @return MailChimp_WooCommerce_ProductVariation
109
  */
110
  public function setSku($sku)
111
  {
124
 
125
  /**
126
  * @param null $price
127
+ * @return MailChimp_WooCommerce_ProductVariation
128
  */
129
  public function setPrice($price)
130
  {
143
 
144
  /**
145
  * @param null $inventory_quantity
146
+ * @return MailChimp_WooCommerce_ProductVariation
147
  */
148
  public function setInventoryQuantity($inventory_quantity)
149
  {
162
 
163
  /**
164
  * @param null $image_url
165
+ * @return MailChimp_WooCommerce_ProductVariation
166
  */
167
  public function setImageUrl($image_url)
168
  {
181
 
182
  /**
183
  * @param null $backorders
184
+ * @return MailChimp_WooCommerce_ProductVariation
185
  */
186
  public function setBackorders($backorders)
187
  {
200
 
201
  /**
202
  * @param null $visibility
203
+ * @return MailChimp_WooCommerce_ProductVariation
204
  */
205
  public function setVisibility($visibility)
206
  {
229
 
230
  /**
231
  * @param array $data
232
+ * @return MailChimp_WooCommerce_ProductVariation
233
  */
234
  public function fromArray(array $data)
235
  {
includes/api/assets/class-mailchimp-product.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 3/8/16
9
  * Time: 2:17 PM
10
  */
11
- class MailChimp_Product
12
  {
13
  protected $id;
14
  protected $title;
@@ -50,7 +50,7 @@ class MailChimp_Product
50
 
51
  /**
52
  * @param mixed $id
53
- * @return MailChimp_Product
54
  */
55
  public function setId($id)
56
  {
@@ -69,7 +69,7 @@ class MailChimp_Product
69
 
70
  /**
71
  * @param mixed $title
72
- * @return MailChimp_Product
73
  */
74
  public function setTitle($title)
75
  {
@@ -88,7 +88,7 @@ class MailChimp_Product
88
 
89
  /**
90
  * @param null $handle
91
- * @return MailChimp_Product
92
  */
93
  public function setHandle($handle)
94
  {
@@ -107,7 +107,7 @@ class MailChimp_Product
107
 
108
  /**
109
  * @param null $url
110
- * @return MailChimp_Product
111
  */
112
  public function setUrl($url)
113
  {
@@ -126,7 +126,7 @@ class MailChimp_Product
126
 
127
  /**
128
  * @param null $description
129
- * @return MailChimp_Product
130
  */
131
  public function setDescription($description)
132
  {
@@ -145,7 +145,7 @@ class MailChimp_Product
145
 
146
  /**
147
  * @param null $type
148
- * @return MailChimp_Product
149
  */
150
  public function setType($type)
151
  {
@@ -164,7 +164,7 @@ class MailChimp_Product
164
 
165
  /**
166
  * @param null $vendor
167
- * @return MailChimp_Product
168
  */
169
  public function setVendor($vendor)
170
  {
@@ -183,7 +183,7 @@ class MailChimp_Product
183
 
184
  /**
185
  * @param null $image_url
186
- * @return MailChimp_Product
187
  */
188
  public function setImageUrl($image_url)
189
  {
@@ -201,10 +201,10 @@ class MailChimp_Product
201
  }
202
 
203
  /**
204
- * @param MailChimp_ProductVariation $variation
205
- * @return MailChimp_Product
206
  */
207
- public function addVariant(MailChimp_ProductVariation $variation)
208
  {
209
  $this->variants[] = $variation;
210
 
@@ -221,7 +221,7 @@ class MailChimp_Product
221
 
222
  /**
223
  * @param \DateTime $time
224
- * @return MailChimp_Product
225
  */
226
  public function setPublishedAtForeign(\DateTime $time)
227
  {
@@ -253,7 +253,7 @@ class MailChimp_Product
253
 
254
  /**
255
  * @param array $data
256
- * @return MailChimp_Product
257
  */
258
  public function fromArray(array $data)
259
  {
@@ -272,7 +272,7 @@ class MailChimp_Product
272
  if (array_key_exists('variants', $data) && is_array($data['variants'])) {
273
  $this->variants = array();
274
  foreach ($data['variants'] as $variant) {
275
- $this->variants[] = (new MailChimp_ProductVariation())->fromArray($variant);
276
  }
277
  }
278
 
8
  * Date: 3/8/16
9
  * Time: 2:17 PM
10
  */
11
+ class MailChimp_WooCommerce_Product
12
  {
13
  protected $id;
14
  protected $title;
50
 
51
  /**
52
  * @param mixed $id
53
+ * @return MailChimp_WooCommerce_Product
54
  */
55
  public function setId($id)
56
  {
69
 
70
  /**
71
  * @param mixed $title
72
+ * @return MailChimp_WooCommerce_Product
73
  */
74
  public function setTitle($title)
75
  {
88
 
89
  /**
90
  * @param null $handle
91
+ * @return MailChimp_WooCommerce_Product
92
  */
93
  public function setHandle($handle)
94
  {
107
 
108
  /**
109
  * @param null $url
110
+ * @return MailChimp_WooCommerce_Product
111
  */
112
  public function setUrl($url)
113
  {
126
 
127
  /**
128
  * @param null $description
129
+ * @return MailChimp_WooCommerce_Product
130
  */
131
  public function setDescription($description)
132
  {
145
 
146
  /**
147
  * @param null $type
148
+ * @return MailChimp_WooCommerce_Product
149
  */
150
  public function setType($type)
151
  {
164
 
165
  /**
166
  * @param null $vendor
167
+ * @return MailChimp_WooCommerce_Product
168
  */
169
  public function setVendor($vendor)
170
  {
183
 
184
  /**
185
  * @param null $image_url
186
+ * @return MailChimp_WooCommerce_Product
187
  */
188
  public function setImageUrl($image_url)
189
  {
201
  }
202
 
203
  /**
204
+ * @param MailChimp_WooCommerce_ProductVariation $variation
205
+ * @return MailChimp_WooCommerce_Product
206
  */
207
+ public function addVariant(MailChimp_WooCommerce_ProductVariation $variation)
208
  {
209
  $this->variants[] = $variation;
210
 
221
 
222
  /**
223
  * @param \DateTime $time
224
+ * @return MailChimp_WooCommerce_Product
225
  */
226
  public function setPublishedAtForeign(\DateTime $time)
227
  {
253
 
254
  /**
255
  * @param array $data
256
+ * @return MailChimp_WooCommerce_Product
257
  */
258
  public function fromArray(array $data)
259
  {
272
  if (array_key_exists('variants', $data) && is_array($data['variants'])) {
273
  $this->variants = array();
274
  foreach ($data['variants'] as $variant) {
275
+ $this->variants[] = (new MailChimp_WooCommerce_ProductVariation())->fromArray($variant);
276
  }
277
  }
278
 
includes/api/assets/class-mailchimp-store.php CHANGED
@@ -8,9 +8,10 @@
8
  * Date: 3/8/16
9
  * Time: 3:13 PM
10
  */
11
- class MailChimp_Store
12
  {
13
  protected $id = null;
 
14
  protected $list_id = null;
15
  protected $name = null;
16
  protected $domain = null;
@@ -51,7 +52,7 @@ class MailChimp_Store
51
 
52
  /**
53
  * @param null $id
54
- * @return MailChimp_Store
55
  */
56
  public function setId($id)
57
  {
@@ -60,6 +61,25 @@ class MailChimp_Store
60
  return $this;
61
  }
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  /**
64
  * @return null
65
  */
@@ -70,7 +90,7 @@ class MailChimp_Store
70
 
71
  /**
72
  * @param null $list_id
73
- * @return MailChimp_Store
74
  */
75
  public function setListId($list_id)
76
  {
@@ -89,7 +109,7 @@ class MailChimp_Store
89
 
90
  /**
91
  * @param null $name
92
- * @return MailChimp_Store;
93
  */
94
  public function setName($name)
95
  {
@@ -108,7 +128,7 @@ class MailChimp_Store
108
 
109
  /**
110
  * @param null $domain
111
- * @return MailChimp_Store;
112
  */
113
  public function setDomain($domain)
114
  {
@@ -127,7 +147,7 @@ class MailChimp_Store
127
 
128
  /**
129
  * @param null $email_address
130
- * @return MailChimp_Store;
131
  */
132
  public function setEmailAddress($email_address)
133
  {
@@ -146,7 +166,7 @@ class MailChimp_Store
146
 
147
  /**
148
  * @param null $currency_code
149
- * @return MailChimp_Store;
150
  */
151
  public function setCurrencyCode($currency_code)
152
  {
@@ -165,7 +185,7 @@ class MailChimp_Store
165
 
166
  /**
167
  * @param null $money_format
168
- * @return MailChimp_Store;
169
  */
170
  public function setMoneyFormat($money_format)
171
  {
@@ -184,7 +204,7 @@ class MailChimp_Store
184
 
185
  /**
186
  * @param null $primary_locale
187
- * @return MailChimp_Store;
188
  */
189
  public function setPrimaryLocale($primary_locale)
190
  {
@@ -203,7 +223,7 @@ class MailChimp_Store
203
 
204
  /**
205
  * @param null $timezone
206
- * @return MailChimp_Store;
207
  */
208
  public function setTimezone($timezone)
209
  {
@@ -222,7 +242,7 @@ class MailChimp_Store
222
 
223
  /**
224
  * @param null $phone
225
- * @return MailChimp_Store;
226
  */
227
  public function setPhone($phone)
228
  {
@@ -251,21 +271,21 @@ class MailChimp_Store
251
  }
252
 
253
  /**
254
- * @return MailChimp_Address
255
  */
256
  public function getAddress()
257
  {
258
  if (empty($this->address)) {
259
- $this->address = new MailChimp_Address();
260
  }
261
  return $this->address;
262
  }
263
 
264
  /**
265
- * @param MailChimp_Address $address
266
  * @return Store;
267
  */
268
- public function setAddress(MailChimp_Address $address)
269
  {
270
  $this->address = $address;
271
 
@@ -279,6 +299,7 @@ class MailChimp_Store
279
  {
280
  return mailchimp_array_remove_empty(array(
281
  'id' => $this->getId(),
 
282
  'platform' => $this->getPlatform(),
283
  'list_id' => $this->getListId(),
284
  'name' => $this->getName(),
@@ -295,12 +316,12 @@ class MailChimp_Store
295
 
296
  /**
297
  * @param array $data
298
- * @return MailChimp_Store
299
  */
300
  public function fromArray(array $data)
301
  {
302
  $singles = array(
303
- 'id', 'list_id', 'name', 'domain',
304
  'email_address', 'currency_code', 'money_format',
305
  'primary_locale', 'timezone', 'phone', 'platform',
306
  );
@@ -312,7 +333,7 @@ class MailChimp_Store
312
  }
313
 
314
  if (array_key_exists('address', $data)) {
315
- $this->address = (new MailChimp_Address())->fromArray($data['address']);
316
  }
317
 
318
  return $this;
8
  * Date: 3/8/16
9
  * Time: 3:13 PM
10
  */
11
+ class MailChimp_WooCommerce_Store
12
  {
13
  protected $id = null;
14
+ protected $is_syncing = false;
15
  protected $list_id = null;
16
  protected $name = null;
17
  protected $domain = null;
52
 
53
  /**
54
  * @param null $id
55
+ * @return MailChimp_WooCommerce_Store
56
  */
57
  public function setId($id)
58
  {
61
  return $this;
62
  }
63
 
64
+ /**
65
+ * @param $bool
66
+ * @return $this
67
+ */
68
+ public function flagSyncing($bool)
69
+ {
70
+ $this->is_syncing = $bool;
71
+
72
+ return $this;
73
+ }
74
+
75
+ /**
76
+ * @return bool
77
+ */
78
+ public function isSyncing()
79
+ {
80
+ return $this->is_syncing;
81
+ }
82
+
83
  /**
84
  * @return null
85
  */
90
 
91
  /**
92
  * @param null $list_id
93
+ * @return MailChimp_WooCommerce_Store
94
  */
95
  public function setListId($list_id)
96
  {
109
 
110
  /**
111
  * @param null $name
112
+ * @return MailChimp_WooCommerce_Store;
113
  */
114
  public function setName($name)
115
  {
128
 
129
  /**
130
  * @param null $domain
131
+ * @return MailChimp_WooCommerce_Store;
132
  */
133
  public function setDomain($domain)
134
  {
147
 
148
  /**
149
  * @param null $email_address
150
+ * @return MailChimp_WooCommerce_Store;
151
  */
152
  public function setEmailAddress($email_address)
153
  {
166
 
167
  /**
168
  * @param null $currency_code
169
+ * @return MailChimp_WooCommerce_Store;
170
  */
171
  public function setCurrencyCode($currency_code)
172
  {
185
 
186
  /**
187
  * @param null $money_format
188
+ * @return MailChimp_WooCommerce_Store;
189
  */
190
  public function setMoneyFormat($money_format)
191
  {
204
 
205
  /**
206
  * @param null $primary_locale
207
+ * @return MailChimp_WooCommerce_Store;
208
  */
209
  public function setPrimaryLocale($primary_locale)
210
  {
223
 
224
  /**
225
  * @param null $timezone
226
+ * @return MailChimp_WooCommerce_Store;
227
  */
228
  public function setTimezone($timezone)
229
  {
242
 
243
  /**
244
  * @param null $phone
245
+ * @return MailChimp_WooCommerce_Store;
246
  */
247
  public function setPhone($phone)
248
  {
271
  }
272
 
273
  /**
274
+ * @return MailChimp_WooCommerce_Address
275
  */
276
  public function getAddress()
277
  {
278
  if (empty($this->address)) {
279
+ $this->address = new MailChimp_WooCommerce_Address();
280
  }
281
  return $this->address;
282
  }
283
 
284
  /**
285
+ * @param MailChimp_WooCommerce_Address $address
286
  * @return Store;
287
  */
288
+ public function setAddress(MailChimp_WooCommerce_Address $address)
289
  {
290
  $this->address = $address;
291
 
299
  {
300
  return mailchimp_array_remove_empty(array(
301
  'id' => $this->getId(),
302
+ 'is_syncing' => $this->isSyncing(),
303
  'platform' => $this->getPlatform(),
304
  'list_id' => $this->getListId(),
305
  'name' => $this->getName(),
316
 
317
  /**
318
  * @param array $data
319
+ * @return MailChimp_WooCommerce_Store
320
  */
321
  public function fromArray(array $data)
322
  {
323
  $singles = array(
324
+ 'id', 'list_id', 'name', 'domain', 'is_syncing',
325
  'email_address', 'currency_code', 'money_format',
326
  'primary_locale', 'timezone', 'phone', 'platform',
327
  );
333
  }
334
 
335
  if (array_key_exists('address', $data)) {
336
+ $this->address = (new MailChimp_WooCommerce_Address())->fromArray($data['address']);
337
  }
338
 
339
  return $this;
includes/api/class-mailchimp-api.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 11/4/15
9
  * Time: 3:35 PM
10
  */
11
- class MailChimpApi
12
  {
13
  protected $version = '3.0';
14
  protected $data_center = 'us2';
@@ -74,7 +74,7 @@ class MailChimpApi
74
  try {
75
  $profile = $this->get('/');
76
  return $return_profile ? $profile : true;
77
- } catch (MailChimp_Error $e) {
78
  return false;
79
  }
80
  }
@@ -227,10 +227,10 @@ class MailChimpApi
227
  }
228
 
229
  /**
230
- * @param MailChimp_CreateListSubmission $submission
231
  * @return array|bool
232
  */
233
- public function createList(MailChimp_CreateListSubmission $submission)
234
  {
235
  return $this->post('lists', $submission->getSubmission());
236
  }
@@ -369,7 +369,7 @@ class MailChimpApi
369
 
370
  /**
371
  * @param $store_id
372
- * @return MailChimp_Store|bool
373
  */
374
  public function getStore($store_id)
375
  {
@@ -378,8 +378,8 @@ class MailChimpApi
378
  if (!isset($data['id']) || !isset($data['name'])) {
379
  return false;
380
  }
381
- return (new MailChimp_Store)->fromArray($data);
382
- } catch (MailChimp_Error $e) {
383
  return false;
384
  }
385
  }
@@ -399,27 +399,52 @@ class MailChimpApi
399
  $response = array();
400
 
401
  foreach ($data['stores'] as $store_data) {
402
- $response[] = (new MailChimp_Store)->fromArray($store_data);
403
  }
404
 
405
  return $response;
406
- } catch (MailChimp_Error $e) {
407
  return false;
408
  }
409
  }
410
 
411
  /**
412
- * @param MailChimp_Store $store
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  * @param bool $silent
414
- * @return bool|MailChimp_Store
415
  * @throws Exception
416
  */
417
- public function addStore(MailChimp_Store $store, $silent = true)
418
  {
419
  try {
420
  $this->validateStoreSubmission($store);
421
  $data = $this->post("ecommerce/stores", $store->toArray());
422
- return (new MailChimp_Store)->fromArray($data);
423
  } catch (\Exception $e) {
424
  if (!$silent) throw $e;
425
  return false;
@@ -427,17 +452,17 @@ class MailChimpApi
427
  }
428
 
429
  /**
430
- * @param MailChimp_Store $store
431
  * @param bool $silent
432
- * @return bool|MailChimp_Store
433
  * @throws Exception
434
  */
435
- public function updateStore(MailChimp_Store $store, $silent = true)
436
  {
437
  try {
438
  $this->validateStoreSubmission($store);
439
  $data = $this->patch("ecommerce/stores/{$store->getId()}", $store->toArray());
440
- return (new MailChimp_Store)->fromArray($data);
441
  } catch (\Exception $e) {
442
  if (!$silent) throw $e;
443
  return false;
@@ -453,7 +478,7 @@ class MailChimpApi
453
  try {
454
  $this->delete("ecommerce/stores/$store_id");
455
  return true;
456
- } catch (MailChimp_Error $e) {
457
  return false;
458
  }
459
  }
@@ -461,28 +486,28 @@ class MailChimpApi
461
  /**
462
  * @param $store_id
463
  * @param string $customer_id
464
- * @return MailChimp_Customer|bool
465
  */
466
  public function getCustomer($store_id, $customer_id)
467
  {
468
  try {
469
  $data = $this->get("ecommerce/stores/$store_id/customers/$customer_id");
470
- return (new MailChimp_Customer)->fromArray($data);
471
- } catch (MailChimp_Error $e) {
472
  return false;
473
  }
474
  }
475
 
476
  /**
477
- * @param MailChimp_Customer $store
478
- * @return MailChimp_Customer
479
- * @throws MailChimp_Error
480
  */
481
- public function addCustomer(MailChimp_Customer $store)
482
  {
483
  $this->validateStoreSubmission($store);
484
  $data = $this->post("ecommerce/stores", $store->toArray());
485
- return (new MailChimp_Customer)->fromArray($data);
486
  }
487
 
488
  /**
@@ -504,17 +529,17 @@ class MailChimpApi
504
 
505
  /**
506
  * @param $store_id
507
- * @param MailChimp_Cart $cart
508
  * @param bool $silent
509
- * @return bool|MailChimp_Cart
510
- * @throws MailChimp_Error
511
  */
512
- public function addCart($store_id, MailChimp_Cart $cart, $silent = true)
513
  {
514
  try {
515
  $data = $this->post("ecommerce/stores/$store_id/carts", $cart->toArray());
516
- return (new MailChimp_Cart)->setStoreID($store_id)->fromArray($data);
517
- } catch (MailChimp_Error $e) {
518
  if (!$silent) throw $e;
519
  mailchimp_log('api.addCart', $e->getMessage());
520
  return false;
@@ -523,17 +548,17 @@ class MailChimpApi
523
 
524
  /**
525
  * @param $store_id
526
- * @param MailChimp_Cart $cart
527
  * @param bool $silent
528
- * @return bool|MailChimp_Cart
529
- * @throws MailChimp_Error
530
  */
531
- public function updateCart($store_id, MailChimp_Cart $cart, $silent = true)
532
  {
533
  try {
534
  $data = $this->patch("ecommerce/stores/$store_id/carts/{$cart->getId()}", $cart->toArrayForUpdate());
535
- return (new MailChimp_Cart)->setStoreID($store_id)->fromArray($data);
536
- } catch (MailChimp_Error $e) {
537
  if (!$silent) throw $e;
538
  mailchimp_log('api.updateCart', $e->getMessage());
539
  return false;
@@ -543,14 +568,14 @@ class MailChimpApi
543
  /**
544
  * @param $store_id
545
  * @param $id
546
- * @return bool|MailChimp_Cart
547
  */
548
  public function getCart($store_id, $id)
549
  {
550
  try {
551
  $data = $this->get("ecommerce/stores/$store_id/carts/$id");
552
- return (new MailChimp_Cart)->setStoreID($store_id)->fromArray($data);
553
- } catch (MailChimp_Error $e) {
554
  return false;
555
  }
556
  }
@@ -565,25 +590,25 @@ class MailChimpApi
565
  try {
566
  $this->delete("ecommerce/stores/$store_id/carts/$id");
567
  return true;
568
- } catch (MailChimp_Error $e) {
569
  return false;
570
  }
571
  }
572
 
573
  /**
574
  * @param $store_id
575
- * @param MailChimp_Customer $customer
576
  * @param bool $silent
577
- * @return bool|MailChimp_Customer
578
- * @throws MailChimp_Error
579
  */
580
- public function updateCustomer($store_id, MailChimp_Customer $customer, $silent = true)
581
  {
582
  try {
583
  $this->validateStoreSubmission($customer);
584
  $data = $this->patch("ecommerce/stores/$store_id/customers/{$customer->getId()}", $customer->toArray());
585
- return (new MailChimp_Customer)->fromArray($data);
586
- } catch (MailChimp_Error $e) {
587
  if (!$silent) throw $e;
588
  return false;
589
  }
@@ -599,24 +624,26 @@ class MailChimpApi
599
  try {
600
  $this->delete("ecommerce/stores/$store_id/customers/$customer_id");
601
  return true;
602
- } catch (MailChimp_Error $e) {
603
  return false;
604
  }
605
  }
606
 
607
  /**
608
  * @param $store_id
609
- * @param MailChimp_Order $order
610
  * @param bool $silent
611
- * @return bool|MailChimp_Order
612
  * @throws Exception
613
  */
614
- public function addStoreOrder($store_id, MailChimp_Order $order, $silent = true)
615
  {
616
  try {
617
- $this->validateStoreSubmission($order);
 
 
618
  $data = $this->post("ecommerce/stores/$store_id/orders", $order->toArray());
619
- return (new MailChimp_Order)->fromArray($data);
620
  } catch (\Exception $e) {
621
  if (!$silent) throw $e;
622
  mailchimp_log('api.add_order.error', $e->getMessage(), array('submission' => $order->toArray()));
@@ -626,18 +653,20 @@ class MailChimpApi
626
 
627
  /**
628
  * @param $store_id
629
- * @param MailChimp_Order $order
630
  * @param bool $silent
631
- * @return bool|MailChimp_Order
632
  * @throws Exception
633
  */
634
- public function updateStoreOrder($store_id, MailChimp_Order $order, $silent = true)
635
  {
636
  try {
637
- $this->validateStoreSubmission($order);
 
 
638
  $id = $order->getId();
639
  $data = $this->patch("ecommerce/stores/$store_id/orders/$id", $order->toArray());
640
- return (new MailChimp_Order)->fromArray($data);
641
  } catch (\Exception $e) {
642
  if (!$silent) throw $e;
643
  mailchimp_log('api.update_order.error', $e->getMessage(), array('submission' => $order->toArray()));
@@ -648,14 +677,14 @@ class MailChimpApi
648
  /**
649
  * @param $store_id
650
  * @param $order_id
651
- * @return MailChimp_Order|bool
652
  */
653
  public function getStoreOrder($store_id, $order_id)
654
  {
655
  try {
656
  $data = $this->get("ecommerce/stores/$store_id/orders/$order_id");
657
- return (new MailChimp_Order)->fromArray($data);
658
- } catch (MailChimp_Error $e) {
659
  return false;
660
  }
661
  }
@@ -670,7 +699,7 @@ class MailChimpApi
670
  try {
671
  $this->delete("ecommerce/stores/$store_id/orders/$order_id");
672
  return true;
673
- } catch (MailChimp_Error $e) {
674
  return false;
675
  }
676
  }
@@ -678,14 +707,14 @@ class MailChimpApi
678
  /**
679
  * @param $store_id
680
  * @param $product_id
681
- * @return MailChimp_Product|bool
682
  */
683
  public function getStoreProduct($store_id, $product_id)
684
  {
685
  try {
686
  $data = $this->get("ecommerce/stores/$store_id/products/$product_id");
687
- return (new MailChimp_Product)->fromArray($data);
688
- } catch (MailChimp_Error $e) {
689
  return false;
690
  }
691
  }
@@ -709,17 +738,17 @@ class MailChimpApi
709
 
710
  /**
711
  * @param $store_id
712
- * @param MailChimp_Product $product
713
  * @param bool $silent
714
- * @return bool|MailChimp_Product
715
  * @throws Exception
716
  */
717
- public function addStoreProduct($store_id, MailChimp_Product $product, $silent = true)
718
  {
719
  try {
720
  $this->validateStoreSubmission($product);
721
  $data = $this->post("ecommerce/stores/$store_id/products", $product->toArray());
722
- return (new MailChimp_Product)->fromArray($data);
723
  } catch (\Exception $e) {
724
  if (!$silent) throw $e;
725
  mailchimp_log('api.add_product.error', $e->getMessage(), array('submission' => $product->toArray()));
@@ -737,18 +766,34 @@ class MailChimpApi
737
  try {
738
  $this->delete("ecommerce/stores/$store_id/products/$product_id");
739
  return true;
740
- } catch (MailChimp_Error $e) {
741
  return false;
742
  }
743
  }
744
 
745
  /**
746
- * @param MailChimp_Store|MailChimp_Order|MailChimp_Product|MailChimp_Customer $target
747
  * @return bool
748
- * @throws MailChimp_Error
749
  */
750
  protected function validateStoreSubmission($target)
751
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
752
  return true;
753
  }
754
 
@@ -756,7 +801,7 @@ class MailChimpApi
756
  * @param $url
757
  * @param null $params
758
  * @return array|bool
759
- * @throws MailChimp_Error
760
  */
761
  protected function delete($url, $params = null)
762
  {
@@ -773,7 +818,7 @@ class MailChimpApi
773
  * @param $url
774
  * @param null $params
775
  * @return array|bool
776
- * @throws MailChimp_Error
777
  */
778
  protected function get($url, $params = null)
779
  {
@@ -791,7 +836,7 @@ class MailChimpApi
791
  * @param $body
792
  * @return array|mixed|null|object
793
  * @throws Exception
794
- * @throws MailChimp_Error
795
  */
796
  protected function patch($url, $body)
797
  {
@@ -816,22 +861,22 @@ class MailChimpApi
816
  // ah snap, gotta try the file get contents fallback.
817
  mailchimp_log('api.patch.fallback', 'stream', array('curl_version' => curl_version()));
818
 
819
- $context = stream_context_create([
820
- 'http' => [
821
  'method' => 'PATCH',
822
- 'header' => [
823
  'Authorization: Basic '.base64_encode('mailchimp:'.$this->api_key),
824
  'Accept: application/json',
825
  'Content-Type: application/json'
826
- ],
827
  'content' => json_encode($body)
828
- ]
829
- ]);
830
 
831
  $response = file_get_contents($this->url($url), FALSE, $context);
832
 
833
  if ($response === false) {
834
- throw new MailChimp_Error('Invalid patch request');
835
  }
836
 
837
  return json_decode($response, true);
@@ -842,7 +887,7 @@ class MailChimpApi
842
  * @param $url
843
  * @param $body
844
  * @return array|bool
845
- * @throws MailChimp_Error
846
  */
847
  protected function post($url, $body)
848
  {
@@ -860,7 +905,7 @@ class MailChimpApi
860
  * @param $url
861
  * @param $body
862
  * @return array|bool
863
- * @throws MailChimp_Error
864
  */
865
  protected function put($url, $body)
866
  {
@@ -920,6 +965,8 @@ class MailChimpApi
920
  */
921
  protected function applyCurlOptions($method, $url, $params = array())
922
  {
 
 
923
  return array(
924
  CURLOPT_USERPWD => "mailchimp:{$this->api_key}",
925
  CURLOPT_CUSTOMREQUEST => strtoupper($method),
@@ -930,7 +977,10 @@ class MailChimpApi
930
  CURLOPT_TIMEOUT => 30,
931
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
932
  CURLINFO_HEADER_OUT => true,
933
- CURLOPT_HTTPHEADER => ['content-type: application/json']
 
 
 
934
  );
935
  }
936
 
@@ -938,8 +988,8 @@ class MailChimpApi
938
  * @param $curl
939
  * @return array|mixed|null|object
940
  * @throws Exception
941
- * @throws MailChimp_Error
942
- * @throws MailChimp_ServerError
943
  */
944
  protected function processCurlResponse($curl)
945
  {
@@ -950,7 +1000,7 @@ class MailChimpApi
950
  curl_close($curl);
951
 
952
  if ($err) {
953
- throw new MailChimp_Error('CURL error :: '.$err, '500');
954
  }
955
 
956
  $data = json_decode($response, true);
@@ -967,11 +1017,11 @@ class MailChimpApi
967
  }
968
 
969
  if ($info['http_code'] >= 400 && $info['http_code'] <= 500) {
970
- throw new MailChimp_Error($data['title'] .' :: '.$data['detail'], $data['status']);
971
  }
972
 
973
  if ($info['http_code'] >= 500) {
974
- throw new MailChimp_ServerError($data['detail'], $data['status']);
975
  }
976
 
977
  return null;
@@ -980,7 +1030,7 @@ class MailChimpApi
980
  /**
981
  * @param array $data
982
  * @return bool
983
- * @throws MailChimp_Error
984
  */
985
  protected function checkForErrors(array $data)
986
  {
@@ -990,12 +1040,12 @@ class MailChimpApi
990
  foreach ($data['errors'] as $error) {
991
  $message .= '<p>'.$error['field'].': '.$error['message'].'</p>';
992
  }
993
- throw new MailChimp_Error($message, $data['status']);
994
  }
995
 
996
  // make sure the response is correct from the data in the response array
997
  if (isset($data['status']) && $data['status'] >= 400) {
998
- throw new MailChimp_Error($data['detail'], $data['status']);
999
  }
1000
 
1001
  return false;
8
  * Date: 11/4/15
9
  * Time: 3:35 PM
10
  */
11
+ class MailChimp_WooCommerce_MailChimpApi
12
  {
13
  protected $version = '3.0';
14
  protected $data_center = 'us2';
74
  try {
75
  $profile = $this->get('/');
76
  return $return_profile ? $profile : true;
77
+ } catch (MailChimp_WooCommerce_Error $e) {
78
  return false;
79
  }
80
  }
227
  }
228
 
229
  /**
230
+ * @param MailChimp_WooCommerce_CreateListSubmission $submission
231
  * @return array|bool
232
  */
233
+ public function createList(MailChimp_WooCommerce_CreateListSubmission $submission)
234
  {
235
  return $this->post('lists', $submission->getSubmission());
236
  }
369
 
370
  /**
371
  * @param $store_id
372
+ * @return MailChimp_WooCommerce_Store|bool
373
  */
374
  public function getStore($store_id)
375
  {
378
  if (!isset($data['id']) || !isset($data['name'])) {
379
  return false;
380
  }
381
+ return (new MailChimp_WooCommerce_Store)->fromArray($data);
382
+ } catch (MailChimp_WooCommerce_Error $e) {
383
  return false;
384
  }
385
  }
399
  $response = array();
400
 
401
  foreach ($data['stores'] as $store_data) {
402
+ $response[] = (new MailChimp_WooCommerce_Store)->fromArray($store_data);
403
  }
404
 
405
  return $response;
406
+ } catch (MailChimp_WooCommerce_Error $e) {
407
  return false;
408
  }
409
  }
410
 
411
  /**
412
+ * @param $store_id
413
+ * @param $is_syncing
414
+ * @return array|bool|mixed|null|object
415
+ */
416
+ public function flagStoreSync($store_id, $is_syncing)
417
+ {
418
+ try {
419
+ // pull the store to make sure we have one.
420
+ if (!($store = $this->getStore($store_id))) {
421
+ return false;
422
+ }
423
+
424
+ // flag it as ^^^ is_syncing ^^^
425
+ $store->flagSyncing($is_syncing);
426
+
427
+ // patch the store data
428
+ return $this->patch("ecommerce/stores/{$store_id}", $store->toArray());
429
+
430
+ } catch (\Exception $e) {
431
+ mailchimp_log('flag.store_sync', $e->getMessage(). ' :: in '.$e->getFile().' :: on '.$e->getLine());
432
+ }
433
+ return false;
434
+ }
435
+
436
+ /**
437
+ * @param MailChimp_WooCommerce_Store $store
438
  * @param bool $silent
439
+ * @return bool|MailChimp_WooCommerce_Store
440
  * @throws Exception
441
  */
442
+ public function addStore(MailChimp_WooCommerce_Store $store, $silent = true)
443
  {
444
  try {
445
  $this->validateStoreSubmission($store);
446
  $data = $this->post("ecommerce/stores", $store->toArray());
447
+ return (new MailChimp_WooCommerce_Store)->fromArray($data);
448
  } catch (\Exception $e) {
449
  if (!$silent) throw $e;
450
  return false;
452
  }
453
 
454
  /**
455
+ * @param MailChimp_WooCommerce_Store $store
456
  * @param bool $silent
457
+ * @return bool|MailChimp_WooCommerce_Store
458
  * @throws Exception
459
  */
460
+ public function updateStore(MailChimp_WooCommerce_Store $store, $silent = true)
461
  {
462
  try {
463
  $this->validateStoreSubmission($store);
464
  $data = $this->patch("ecommerce/stores/{$store->getId()}", $store->toArray());
465
+ return (new MailChimp_WooCommerce_Store)->fromArray($data);
466
  } catch (\Exception $e) {
467
  if (!$silent) throw $e;
468
  return false;
478
  try {
479
  $this->delete("ecommerce/stores/$store_id");
480
  return true;
481
+ } catch (MailChimp_WooCommerce_Error $e) {
482
  return false;
483
  }
484
  }
486
  /**
487
  * @param $store_id
488
  * @param string $customer_id
489
+ * @return MailChimp_WooCommerce_Customer|bool
490
  */
491
  public function getCustomer($store_id, $customer_id)
492
  {
493
  try {
494
  $data = $this->get("ecommerce/stores/$store_id/customers/$customer_id");
495
+ return (new MailChimp_WooCommerce_Customer)->fromArray($data);
496
+ } catch (MailChimp_WooCommerce_Error $e) {
497
  return false;
498
  }
499
  }
500
 
501
  /**
502
+ * @param MailChimp_WooCommerce_Customer $store
503
+ * @return MailChimp_WooCommerce_Customer
504
+ * @throws MailChimp_WooCommerce_Error
505
  */
506
+ public function addCustomer(MailChimp_WooCommerce_Customer $store)
507
  {
508
  $this->validateStoreSubmission($store);
509
  $data = $this->post("ecommerce/stores", $store->toArray());
510
+ return (new MailChimp_WooCommerce_Customer)->fromArray($data);
511
  }
512
 
513
  /**
529
 
530
  /**
531
  * @param $store_id
532
+ * @param MailChimp_WooCommerce_Cart $cart
533
  * @param bool $silent
534
+ * @return bool|MailChimp_WooCommerce_Cart
535
+ * @throws MailChimp_WooCommerce_Error
536
  */
537
+ public function addCart($store_id, MailChimp_WooCommerce_Cart $cart, $silent = true)
538
  {
539
  try {
540
  $data = $this->post("ecommerce/stores/$store_id/carts", $cart->toArray());
541
+ return (new MailChimp_WooCommerce_Cart)->setStoreID($store_id)->fromArray($data);
542
+ } catch (MailChimp_WooCommerce_Error $e) {
543
  if (!$silent) throw $e;
544
  mailchimp_log('api.addCart', $e->getMessage());
545
  return false;
548
 
549
  /**
550
  * @param $store_id
551
+ * @param MailChimp_WooCommerce_Cart $cart
552
  * @param bool $silent
553
+ * @return bool|MailChimp_WooCommerce_Cart
554
+ * @throws MailChimp_WooCommerce_Error
555
  */
556
+ public function updateCart($store_id, MailChimp_WooCommerce_Cart $cart, $silent = true)
557
  {
558
  try {
559
  $data = $this->patch("ecommerce/stores/$store_id/carts/{$cart->getId()}", $cart->toArrayForUpdate());
560
+ return (new MailChimp_WooCommerce_Cart)->setStoreID($store_id)->fromArray($data);
561
+ } catch (MailChimp_WooCommerce_Error $e) {
562
  if (!$silent) throw $e;
563
  mailchimp_log('api.updateCart', $e->getMessage());
564
  return false;
568
  /**
569
  * @param $store_id
570
  * @param $id
571
+ * @return bool|MailChimp_WooCommerce_Cart
572
  */
573
  public function getCart($store_id, $id)
574
  {
575
  try {
576
  $data = $this->get("ecommerce/stores/$store_id/carts/$id");
577
+ return (new MailChimp_WooCommerce_Cart)->setStoreID($store_id)->fromArray($data);
578
+ } catch (MailChimp_WooCommerce_Error $e) {
579
  return false;
580
  }
581
  }
590
  try {
591
  $this->delete("ecommerce/stores/$store_id/carts/$id");
592
  return true;
593
+ } catch (MailChimp_WooCommerce_Error $e) {
594
  return false;
595
  }
596
  }
597
 
598
  /**
599
  * @param $store_id
600
+ * @param MailChimp_WooCommerce_Customer $customer
601
  * @param bool $silent
602
+ * @return bool|MailChimp_WooCommerce_Customer
603
+ * @throws MailChimp_WooCommerce_Error
604
  */
605
+ public function updateCustomer($store_id, MailChimp_WooCommerce_Customer $customer, $silent = true)
606
  {
607
  try {
608
  $this->validateStoreSubmission($customer);
609
  $data = $this->patch("ecommerce/stores/$store_id/customers/{$customer->getId()}", $customer->toArray());
610
+ return (new MailChimp_WooCommerce_Customer)->fromArray($data);
611
+ } catch (MailChimp_WooCommerce_Error $e) {
612
  if (!$silent) throw $e;
613
  return false;
614
  }
624
  try {
625
  $this->delete("ecommerce/stores/$store_id/customers/$customer_id");
626
  return true;
627
+ } catch (MailChimp_WooCommerce_Error $e) {
628
  return false;
629
  }
630
  }
631
 
632
  /**
633
  * @param $store_id
634
+ * @param MailChimp_WooCommerce_Order $order
635
  * @param bool $silent
636
+ * @return bool|MailChimp_WooCommerce_Order
637
  * @throws Exception
638
  */
639
+ public function addStoreOrder($store_id, MailChimp_WooCommerce_Order $order, $silent = true)
640
  {
641
  try {
642
+ if (!$this->validateStoreSubmission($order)) {
643
+ return false;
644
+ }
645
  $data = $this->post("ecommerce/stores/$store_id/orders", $order->toArray());
646
+ return (new MailChimp_WooCommerce_Order)->fromArray($data);
647
  } catch (\Exception $e) {
648
  if (!$silent) throw $e;
649
  mailchimp_log('api.add_order.error', $e->getMessage(), array('submission' => $order->toArray()));
653
 
654
  /**
655
  * @param $store_id
656
+ * @param MailChimp_WooCommerce_Order $order
657
  * @param bool $silent
658
+ * @return bool|MailChimp_WooCommerce_Order
659
  * @throws Exception
660
  */
661
+ public function updateStoreOrder($store_id, MailChimp_WooCommerce_Order $order, $silent = true)
662
  {
663
  try {
664
+ if (!$this->validateStoreSubmission($order)) {
665
+ return false;
666
+ }
667
  $id = $order->getId();
668
  $data = $this->patch("ecommerce/stores/$store_id/orders/$id", $order->toArray());
669
+ return (new MailChimp_WooCommerce_Order)->fromArray($data);
670
  } catch (\Exception $e) {
671
  if (!$silent) throw $e;
672
  mailchimp_log('api.update_order.error', $e->getMessage(), array('submission' => $order->toArray()));
677
  /**
678
  * @param $store_id
679
  * @param $order_id
680
+ * @return MailChimp_WooCommerce_Order|bool
681
  */
682
  public function getStoreOrder($store_id, $order_id)
683
  {
684
  try {
685
  $data = $this->get("ecommerce/stores/$store_id/orders/$order_id");
686
+ return (new MailChimp_WooCommerce_Order)->fromArray($data);
687
+ } catch (MailChimp_WooCommerce_Error $e) {
688
  return false;
689
  }
690
  }
699
  try {
700
  $this->delete("ecommerce/stores/$store_id/orders/$order_id");
701
  return true;
702
+ } catch (MailChimp_WooCommerce_Error $e) {
703
  return false;
704
  }
705
  }
707
  /**
708
  * @param $store_id
709
  * @param $product_id
710
+ * @return MailChimp_WooCommerce_Product|bool
711
  */
712
  public function getStoreProduct($store_id, $product_id)
713
  {
714
  try {
715
  $data = $this->get("ecommerce/stores/$store_id/products/$product_id");
716
+ return (new MailChimp_WooCommerce_Product)->fromArray($data);
717
+ } catch (MailChimp_WooCommerce_Error $e) {
718
  return false;
719
  }
720
  }
738
 
739
  /**
740
  * @param $store_id
741
+ * @param MailChimp_WooCommerce_Product $product
742
  * @param bool $silent
743
+ * @return bool|MailChimp_WooCommerce_Product
744
  * @throws Exception
745
  */
746
+ public function addStoreProduct($store_id, MailChimp_WooCommerce_Product $product, $silent = true)
747
  {
748
  try {
749
  $this->validateStoreSubmission($product);
750
  $data = $this->post("ecommerce/stores/$store_id/products", $product->toArray());
751
+ return (new MailChimp_WooCommerce_Product)->fromArray($data);
752
  } catch (\Exception $e) {
753
  if (!$silent) throw $e;
754
  mailchimp_log('api.add_product.error', $e->getMessage(), array('submission' => $product->toArray()));
766
  try {
767
  $this->delete("ecommerce/stores/$store_id/products/$product_id");
768
  return true;
769
+ } catch (MailChimp_WooCommerce_Error $e) {
770
  return false;
771
  }
772
  }
773
 
774
  /**
775
+ * @param MailChimp_WooCommerce_Store|MailChimp_WooCommerce_Order|MailChimp_WooCommerce_Product|MailChimp_WooCommerce_Customer $target
776
  * @return bool
777
+ * @throws MailChimp_WooCommerce_Error
778
  */
779
  protected function validateStoreSubmission($target)
780
  {
781
+ if ($target instanceof MailChimp_WooCommerce_Order) {
782
+ return $this->validateStoreOrder($target);
783
+ }
784
+ return true;
785
+ }
786
+
787
+ /**
788
+ * @param MailChimp_WooCommerce_Order $order
789
+ * @return bool
790
+ */
791
+ protected function validateStoreOrder(MailChimp_WooCommerce_Order $order)
792
+ {
793
+ if (mailchimp_string_contains($order->getCustomer()->getEmailAddress(), array('marketplace.amazon.com'))) {
794
+ mailchimp_log('validation.amazon', "Order #{$order->getId()} was placed through Amazon. Skipping!");
795
+ return false;
796
+ }
797
  return true;
798
  }
799
 
801
  * @param $url
802
  * @param null $params
803
  * @return array|bool
804
+ * @throws MailChimp_WooCommerce_Error
805
  */
806
  protected function delete($url, $params = null)
807
  {
818
  * @param $url
819
  * @param null $params
820
  * @return array|bool
821
+ * @throws MailChimp_WooCommerce_Error
822
  */
823
  protected function get($url, $params = null)
824
  {
836
  * @param $body
837
  * @return array|mixed|null|object
838
  * @throws Exception
839
+ * @throws MailChimp_WooCommerce_Error
840
  */
841
  protected function patch($url, $body)
842
  {
861
  // ah snap, gotta try the file get contents fallback.
862
  mailchimp_log('api.patch.fallback', 'stream', array('curl_version' => curl_version()));
863
 
864
+ $context = stream_context_create(array(
865
+ 'http' => array(
866
  'method' => 'PATCH',
867
+ 'header' => array(
868
  'Authorization: Basic '.base64_encode('mailchimp:'.$this->api_key),
869
  'Accept: application/json',
870
  'Content-Type: application/json'
871
+ ),
872
  'content' => json_encode($body)
873
+ )
874
+ ));
875
 
876
  $response = file_get_contents($this->url($url), FALSE, $context);
877
 
878
  if ($response === false) {
879
+ throw new MailChimp_WooCommerce_Error('Invalid patch request');
880
  }
881
 
882
  return json_decode($response, true);
887
  * @param $url
888
  * @param $body
889
  * @return array|bool
890
+ * @throws MailChimp_WooCommerce_Error
891
  */
892
  protected function post($url, $body)
893
  {
905
  * @param $url
906
  * @param $body
907
  * @return array|bool
908
+ * @throws MailChimp_WooCommerce_Error
909
  */
910
  protected function put($url, $body)
911
  {
965
  */
966
  protected function applyCurlOptions($method, $url, $params = array())
967
  {
968
+ //$env = mailchimp_environment_variables();
969
+
970
  return array(
971
  CURLOPT_USERPWD => "mailchimp:{$this->api_key}",
972
  CURLOPT_CUSTOMREQUEST => strtoupper($method),
977
  CURLOPT_TIMEOUT => 30,
978
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
979
  CURLINFO_HEADER_OUT => true,
980
+ CURLOPT_HTTPHEADER => array(
981
+ 'content-type: application/json',
982
+ 'user-agent: MailChimp for WooCommerce',
983
+ )
984
  );
985
  }
986
 
988
  * @param $curl
989
  * @return array|mixed|null|object
990
  * @throws Exception
991
+ * @throws MailChimp_WooCommerce_Error
992
+ * @throws MailChimp_WooCommerce_ServerError
993
  */
994
  protected function processCurlResponse($curl)
995
  {
1000
  curl_close($curl);
1001
 
1002
  if ($err) {
1003
+ throw new MailChimp_WooCommerce_Error('CURL error :: '.$err, '500');
1004
  }
1005
 
1006
  $data = json_decode($response, true);
1017
  }
1018
 
1019
  if ($info['http_code'] >= 400 && $info['http_code'] <= 500) {
1020
+ throw new MailChimp_WooCommerce_Error($data['title'] .' :: '.$data['detail'], $data['status']);
1021
  }
1022
 
1023
  if ($info['http_code'] >= 500) {
1024
+ throw new MailChimp_WooCommerce_ServerError($data['detail'], $data['status']);
1025
  }
1026
 
1027
  return null;
1030
  /**
1031
  * @param array $data
1032
  * @return bool
1033
+ * @throws MailChimp_WooCommerce_Error
1034
  */
1035
  protected function checkForErrors(array $data)
1036
  {
1040
  foreach ($data['errors'] as $error) {
1041
  $message .= '<p>'.$error['field'].': '.$error['message'].'</p>';
1042
  }
1043
+ throw new MailChimp_WooCommerce_Error($message, $data['status']);
1044
  }
1045
 
1046
  // make sure the response is correct from the data in the response array
1047
  if (isset($data['status']) && $data['status'] >= 400) {
1048
+ throw new MailChimp_WooCommerce_Error($data['detail'], $data['status']);
1049
  }
1050
 
1051
  return false;
includes/api/class-mailchimp-woocommerce-create-list-submission.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 7/8/16
9
  * Time: 4:16 PM
10
  */
11
- class MailChimp_CreateListSubmission
12
  {
13
  /**
14
  * @var array
@@ -112,10 +112,10 @@ class MailChimp_CreateListSubmission
112
  }
113
 
114
  /**
115
- * @param MailChimp_Address $address
116
  * @return $this
117
  */
118
- public function setContact(MailChimp_Address $address)
119
  {
120
  $data = array();
121
 
8
  * Date: 7/8/16
9
  * Time: 4:16 PM
10
  */
11
+ class MailChimp_WooCommerce_CreateListSubmission
12
  {
13
  /**
14
  * @var array
112
  }
113
 
114
  /**
115
+ * @param MailChimp_WooCommerce_Address $address
116
  * @return $this
117
  */
118
+ public function setContact(MailChimp_WooCommerce_Address $address)
119
  {
120
  $data = array();
121
 
includes/api/class-mailchimp-woocommerce-transform-orders.php CHANGED
@@ -50,13 +50,13 @@ class MailChimp_WooCommerce_Transform_Orders
50
 
51
  /**
52
  * @param WP_Post $post
53
- * @return MailChimp_Order
54
  */
55
  public function transform(WP_Post $post)
56
  {
57
  $woo = new WC_Order($post);
58
 
59
- $order = new MailChimp_Order();
60
 
61
  $order->setId($woo->id);
62
 
@@ -126,11 +126,11 @@ class MailChimp_WooCommerce_Transform_Orders
126
 
127
  /**
128
  * @param WC_Order $order
129
- * @return MailChimp_Customer
130
  */
131
  public function buildCustomerFromOrder(WC_Order $order)
132
  {
133
- $customer = new MailChimp_Customer();
134
 
135
  $customer->setId(md5(trim(strtolower($order->billing_email))));
136
  $customer->setCompany($order->billing_company);
@@ -147,7 +147,7 @@ class MailChimp_WooCommerce_Transform_Orders
147
  $customer->setOptInStatus($subscribed_on_order);
148
 
149
  // use the info from the order to compile an address.
150
- $address = new MailChimp_Address();
151
  $address->setAddress1($order->billing_address_1);
152
  $address->setAddress2($order->billing_address_2);
153
  $address->setCity($order->billing_city);
@@ -192,12 +192,12 @@ class MailChimp_WooCommerce_Transform_Orders
192
  /**
193
  * @param $key
194
  * @param $order_detail
195
- * @return MailChimp_LineItem
196
  */
197
  protected function buildLineItem($key, $order_detail)
198
  {
199
  // fire up a new MC line item
200
- $item = new MailChimp_LineItem();
201
  $item->setId($key);
202
 
203
  if (isset($order_detail['item_meta']) && is_array($order_detail['item_meta'])) {
@@ -337,7 +337,7 @@ class MailChimp_WooCommerce_Transform_Orders
337
  public function getOrderAddresses(WC_Order $order)
338
  {
339
  // use the info from the order to compile an address.
340
- $billing = new MailChimp_Address();
341
  $billing->setAddress1($order->billing_address_1);
342
  $billing->setAddress2($order->billing_address_2);
343
  $billing->setCity($order->billing_city);
@@ -347,7 +347,7 @@ class MailChimp_WooCommerce_Transform_Orders
347
  $billing->setPhone($order->billing_phone);
348
  $billing->setName('billing');
349
 
350
- $shipping = new MailChimp_Address();
351
  $shipping->setAddress1($order->shipping_address_1);
352
  $shipping->setAddress2($order->shipping_address_2);
353
  $shipping->setCity($order->shipping_city);
@@ -365,11 +365,11 @@ class MailChimp_WooCommerce_Transform_Orders
365
  /**
366
  * @param $user_id
367
  * @param string $type
368
- * @return MailChimp_Address
369
  */
370
  public function getUserAddress($user_id, $type = 'billing')
371
  {
372
- $address = new MailChimp_Address();
373
 
374
  // pull all the meta for this user.
375
  $meta = get_user_meta($user_id);
50
 
51
  /**
52
  * @param WP_Post $post
53
+ * @return MailChimp_WooCommerce_Order
54
  */
55
  public function transform(WP_Post $post)
56
  {
57
  $woo = new WC_Order($post);
58
 
59
+ $order = new MailChimp_WooCommerce_Order();
60
 
61
  $order->setId($woo->id);
62
 
126
 
127
  /**
128
  * @param WC_Order $order
129
+ * @return MailChimp_WooCommerce_Customer
130
  */
131
  public function buildCustomerFromOrder(WC_Order $order)
132
  {
133
+ $customer = new MailChimp_WooCommerce_Customer();
134
 
135
  $customer->setId(md5(trim(strtolower($order->billing_email))));
136
  $customer->setCompany($order->billing_company);
147
  $customer->setOptInStatus($subscribed_on_order);
148
 
149
  // use the info from the order to compile an address.
150
+ $address = new MailChimp_WooCommerce_Address();
151
  $address->setAddress1($order->billing_address_1);
152
  $address->setAddress2($order->billing_address_2);
153
  $address->setCity($order->billing_city);
192
  /**
193
  * @param $key
194
  * @param $order_detail
195
+ * @return MailChimp_WooCommerce_LineItem
196
  */
197
  protected function buildLineItem($key, $order_detail)
198
  {
199
  // fire up a new MC line item
200
+ $item = new MailChimp_WooCommerce_LineItem();
201
  $item->setId($key);
202
 
203
  if (isset($order_detail['item_meta']) && is_array($order_detail['item_meta'])) {
337
  public function getOrderAddresses(WC_Order $order)
338
  {
339
  // use the info from the order to compile an address.
340
+ $billing = new MailChimp_WooCommerce_Address();
341
  $billing->setAddress1($order->billing_address_1);
342
  $billing->setAddress2($order->billing_address_2);
343
  $billing->setCity($order->billing_city);
347
  $billing->setPhone($order->billing_phone);
348
  $billing->setName('billing');
349
 
350
+ $shipping = new MailChimp_WooCommerce_Address();
351
  $shipping->setAddress1($order->shipping_address_1);
352
  $shipping->setAddress2($order->shipping_address_2);
353
  $shipping->setCity($order->shipping_city);
365
  /**
366
  * @param $user_id
367
  * @param string $type
368
+ * @return MailChimp_WooCommerce_Address
369
  */
370
  public function getUserAddress($user_id, $type = 'billing')
371
  {
372
+ $address = new MailChimp_WooCommerce_Address();
373
 
374
  // pull all the meta for this user.
375
  $meta = get_user_meta($user_id);
includes/api/class-mailchimp-woocommerce-transform-products.php CHANGED
@@ -40,7 +40,7 @@ class MailChimp_WooCommerce_Transform_Products
40
 
41
  /**
42
  * @param WP_Post $post
43
- * @return MailChimp_Product
44
  */
45
  public function transform(WP_Post $post)
46
  {
@@ -52,7 +52,7 @@ class MailChimp_WooCommerce_Transform_Products
52
 
53
  $is_variant = count($variants) > 1;
54
 
55
- $product = new MailChimp_Product();
56
 
57
  $product->setId($woo->get_id());
58
  $product->setHandle($post->post_name);
@@ -64,7 +64,7 @@ class MailChimp_WooCommerce_Transform_Products
64
 
65
  foreach ($variants as $variant) {
66
 
67
- $product_variant = $this->variant($is_variant, $variant);
68
 
69
  $product_variant_title = $product_variant->getTitle();
70
 
@@ -87,9 +87,10 @@ class MailChimp_WooCommerce_Transform_Products
87
  /**
88
  * @param $is_variant
89
  * @param WP_Post $post
90
- * @return MailChimp_ProductVariation
 
91
  */
92
- public function variant($is_variant, $post)
93
  {
94
  if ($post instanceof WC_Product || $post instanceof WC_Product_Variation) {
95
  $woo = $post;
@@ -101,21 +102,35 @@ class MailChimp_WooCommerce_Transform_Products
101
  }
102
  }
103
 
104
- $variant = new MailChimp_ProductVariation();
105
 
106
  $variant->setId($woo->get_id());
107
  $variant->setUrl($woo->get_permalink());
108
- $variant->setTitle($woo->get_title());
109
  $variant->setBackorders($woo->backorders_allowed());
110
  $variant->setImageUrl(get_the_post_thumbnail_url($post));
111
- $variant->setInventoryQuantity(($woo->managing_stock() ? $woo->get_stock_quantity() : 0));
112
  $variant->setPrice($woo->get_price());
113
  $variant->setSku($woo->get_sku());
114
 
115
  if ($woo instanceof WC_Product_Variation) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  $variant->setVisibility(($woo->variation_is_visible() ? 'visible' : ''));
117
  } else {
118
  $variant->setVisibility(($woo->is_visible() ? 'visible' : ''));
 
119
  }
120
 
121
  return $variant;
@@ -166,7 +181,7 @@ class MailChimp_WooCommerce_Transform_Products
166
 
167
  /**
168
  * @param $id
169
- * @return MailChimp_Product
170
  */
171
  public static function deleted($id)
172
  {
@@ -174,12 +189,12 @@ class MailChimp_WooCommerce_Transform_Products
174
  $api = mailchimp_get_api();
175
 
176
  if (!($product = $api->getStoreProduct($store_id, "deleted_{$id}"))) {
177
- $product = new MailChimp_Product();
178
 
179
  $product->setId("deleted_{$id}");
180
  $product->setTitle("deleted_{$id}");
181
 
182
- $variant = new MailChimp_ProductVariation();
183
  $variant->setId("deleted_{$id}");
184
  $variant->setTitle("deleted_{$id}");
185
 
40
 
41
  /**
42
  * @param WP_Post $post
43
+ * @return MailChimp_WooCommerce_Product
44
  */
45
  public function transform(WP_Post $post)
46
  {
52
 
53
  $is_variant = count($variants) > 1;
54
 
55
+ $product = new MailChimp_WooCommerce_Product();
56
 
57
  $product->setId($woo->get_id());
58
  $product->setHandle($post->post_name);
64
 
65
  foreach ($variants as $variant) {
66
 
67
+ $product_variant = $this->variant($is_variant, $variant, $woo->get_title());
68
 
69
  $product_variant_title = $product_variant->getTitle();
70
 
87
  /**
88
  * @param $is_variant
89
  * @param WP_Post $post
90
+ * @param string $fallback_title
91
+ * @return MailChimp_WooCommerce_ProductVariation
92
  */
93
+ public function variant($is_variant, $post, $fallback_title = null)
94
  {
95
  if ($post instanceof WC_Product || $post instanceof WC_Product_Variation) {
96
  $woo = $post;
102
  }
103
  }
104
 
105
+ $variant = new MailChimp_WooCommerce_ProductVariation();
106
 
107
  $variant->setId($woo->get_id());
108
  $variant->setUrl($woo->get_permalink());
 
109
  $variant->setBackorders($woo->backorders_allowed());
110
  $variant->setImageUrl(get_the_post_thumbnail_url($post));
111
+ $variant->setInventoryQuantity(($woo->managing_stock() ? $woo->get_stock_quantity() : 1));
112
  $variant->setPrice($woo->get_price());
113
  $variant->setSku($woo->get_sku());
114
 
115
  if ($woo instanceof WC_Product_Variation) {
116
+
117
+ $variation_title = $woo->get_title();
118
+ if (empty($variation_title)) $variation_title = $fallback_title;
119
+
120
+ $title = array($variation_title);
121
+
122
+ foreach ($woo->get_variation_attributes() as $attribute => $value) {
123
+ if (is_string($value)) {
124
+ $name = ucfirst(str_replace(array('attribute_pa_', 'attribute_'), '', $attribute));
125
+ $title[] = "$name = $value";
126
+ }
127
+ }
128
+
129
+ $variant->setTitle(implode(' :: ', $title));
130
  $variant->setVisibility(($woo->variation_is_visible() ? 'visible' : ''));
131
  } else {
132
  $variant->setVisibility(($woo->is_visible() ? 'visible' : ''));
133
+ $variant->setTitle($woo->get_title());
134
  }
135
 
136
  return $variant;
181
 
182
  /**
183
  * @param $id
184
+ * @return MailChimp_WooCommerce_Product
185
  */
186
  public static function deleted($id)
187
  {
189
  $api = mailchimp_get_api();
190
 
191
  if (!($product = $api->getStoreProduct($store_id, "deleted_{$id}"))) {
192
+ $product = new MailChimp_WooCommerce_Product();
193
 
194
  $product->setId("deleted_{$id}");
195
  $product->setTitle("deleted_{$id}");
196
 
197
+ $variant = new MailChimp_WooCommerce_ProductVariation();
198
  $variant->setId("deleted_{$id}");
199
  $variant->setTitle("deleted_{$id}");
200
 
includes/api/errors/class-mailchimp-error.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 6/18/15
9
  * Time: 11:13 AM
10
  */
11
- class MailChimp_Error extends \Exception
12
  {
13
 
14
  }
8
  * Date: 6/18/15
9
  * Time: 11:13 AM
10
  */
11
+ class MailChimp_WooCommerce_Error extends \Exception
12
  {
13
 
14
  }
includes/api/errors/class-mailchimp-server-error.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 6/18/15
9
  * Time: 11:13 AM
10
  */
11
- class MailChimp_ServerError extends \Exception
12
  {
13
 
14
  }
8
  * Date: 6/18/15
9
  * Time: 11:13 AM
10
  */
11
+ class MailChimp_WooCommerce_ServerError extends \Exception
12
  {
13
 
14
  }
includes/api/helpers/class-mailchimp-woocommerce-api-currency-codes.php CHANGED
@@ -8,7 +8,7 @@
8
  * Date: 7/12/16
9
  * Time: 1:38 PM
10
  */
11
- class MailChimp_Api_CurrencyCodes
12
  {
13
  /**
14
  * @return array
8
  * Date: 7/12/16
9
  * Time: 1:38 PM
10
  */
11
+ class MailChimp_WooCommerce_CurrencyCodes
12
  {
13
  /**
14
  * @return array
includes/api/helpers/class-mailchimp-woocommerce-api-locales.php CHANGED
@@ -15,7 +15,7 @@ class MailChimp_Api_Locales
15
  */
16
  public function all()
17
  {
18
- return [
19
  "af_NA"=> "Afrikaans (Namibia)",
20
  "af_ZA"=> "Afrikaans (South Africa)",
21
  "af"=> "Afrikaans",
@@ -450,7 +450,7 @@ class MailChimp_Api_Locales
450
  "yo"=> "Yoruba",
451
  "zu_ZA"=> "Zulu (South Africa)",
452
  "zu"=> "Zulu"
453
- ];
454
  }
455
 
456
  /**
15
  */
16
  public function all()
17
  {
18
+ return array(
19
  "af_NA"=> "Afrikaans (Namibia)",
20
  "af_ZA"=> "Afrikaans (South Africa)",
21
  "af"=> "Afrikaans",
450
  "yo"=> "Yoruba",
451
  "zu_ZA"=> "Zulu (South Africa)",
452
  "zu"=> "Zulu"
453
+ );
454
  }
455
 
456
  /**
includes/class-mailchimp-woocommerce-options.php CHANGED
@@ -11,7 +11,7 @@
11
  abstract class MailChimp_Woocommerce_Options
12
  {
13
  /**
14
- * @var MailChimpApi
15
  */
16
  protected $api;
17
  protected $plugin_name = 'mailchimp-woocommerce';
@@ -210,12 +210,12 @@ abstract class MailChimp_Woocommerce_Options
210
  }
211
 
212
  /**
213
- * @return MailChimpApi
214
  */
215
  public function api()
216
  {
217
  if (empty($this->api)) {
218
- $this->api = new MailChimpApi($this->getOption('mailchimp_api_key', false));
219
  }
220
 
221
  return $this->api;
11
  abstract class MailChimp_Woocommerce_Options
12
  {
13
  /**
14
+ * @var MailChimp_WooCommerce_MailChimpApi
15
  */
16
  protected $api;
17
  protected $plugin_name = 'mailchimp-woocommerce';
210
  }
211
 
212
  /**
213
+ * @return MailChimp_WooCommerce_MailChimpApi
214
  */
215
  public function api()
216
  {
217
  if (empty($this->api)) {
218
+ $this->api = new MailChimp_WooCommerce_MailChimpApi($this->getOption('mailchimp_api_key', false));
219
  }
220
 
221
  return $this->api;
includes/class-mailchimp-woocommerce-service.php CHANGED
@@ -99,7 +99,6 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
99
  if ($this->cart && !empty($this->cart)) {
100
 
101
  $this->cart_was_submitted = true;
102
-
103
  // grab the cookie data that could play important roles in the submission
104
  $campaign = $this->getCampaignTrackingID();
105
 
@@ -125,7 +124,7 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
125
  if ('product' == $post->post_type) {
126
  wp_queue(new MailChimp_WooCommerce_Single_Product($post_id), 5);
127
  } elseif ('shop_order' == $post->post_type) {
128
- wp_queue(new MailChimp_WooCommerce_Single_Order($post_id, null, null));
129
  }
130
  }
131
 
@@ -187,6 +186,7 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
187
  if (empty($cookie)) {
188
  $cookie = $this->getWooSession('mailchimp_tracking_id', false);
189
  }
 
190
  return $cookie;
191
  }
192
 
99
  if ($this->cart && !empty($this->cart)) {
100
 
101
  $this->cart_was_submitted = true;
 
102
  // grab the cookie data that could play important roles in the submission
103
  $campaign = $this->getCampaignTrackingID();
104
 
124
  if ('product' == $post->post_type) {
125
  wp_queue(new MailChimp_WooCommerce_Single_Product($post_id), 5);
126
  } elseif ('shop_order' == $post->post_type) {
127
+ $this->handleOrderStatusChanged($post_id);
128
  }
129
  }
130
 
186
  if (empty($cookie)) {
187
  $cookie = $this->getWooSession('mailchimp_tracking_id', false);
188
  }
189
+
190
  return $cookie;
191
  }
192
 
includes/class-mailchimp-woocommerce.php CHANGED
@@ -180,7 +180,7 @@ class MailChimp_Woocommerce {
180
 
181
  /** Require all the mailchimp api asset classes */
182
  require_once $path . 'includes/api/assets/class-mailchimp-address.php';
183
- require_once $path . 'includes/api/assets/class-mailchimp-cart.php';
184
  require_once $path . 'includes/api/assets/class-mailchimp-customer.php';
185
  require_once $path . 'includes/api/assets/class-mailchimp-line-item.php';
186
  require_once $path . 'includes/api/assets/class-mailchimp-order.php';
180
 
181
  /** Require all the mailchimp api asset classes */
182
  require_once $path . 'includes/api/assets/class-mailchimp-address.php';
183
+ require_once $path . 'includes/api/assets/class-mailchimp-cart.php';
184
  require_once $path . 'includes/api/assets/class-mailchimp-customer.php';
185
  require_once $path . 'includes/api/assets/class-mailchimp-line-item.php';
186
  require_once $path . 'includes/api/assets/class-mailchimp-order.php';
includes/processes/class-mailchimp-woocommerce-abstract-sync.php CHANGED
@@ -16,7 +16,7 @@ abstract class MailChimp_WooCommerce_Abtstract_Sync extends WP_Job
16
  private $api;
17
 
18
  /**
19
- * @var MailChimpApi
20
  */
21
  private $mc;
22
 
@@ -116,6 +116,9 @@ abstract class MailChimp_WooCommerce_Abtstract_Sync extends WP_Job
116
  $this->setData('sync.syncing', true);
117
  $this->setData('sync.started_at', time());
118
 
 
 
 
119
  return $this;
120
  }
121
 
@@ -124,11 +127,14 @@ abstract class MailChimp_WooCommerce_Abtstract_Sync extends WP_Job
124
  */
125
  public function flagStopSync()
126
  {
 
 
127
  // this is the last thing we're doing so it's complete as of now.
128
  $this->setData('sync.syncing', false);
129
  $this->setData('sync.completed_at', time());
130
 
131
- mailchimp_log('sync.completed', "Finished Sync :: ".date('D, M j, Y g:i A'));
 
132
 
133
  return $this;
134
  }
@@ -311,12 +317,12 @@ abstract class MailChimp_WooCommerce_Abtstract_Sync extends WP_Job
311
  }
312
 
313
  /**
314
- * @return MailChimpApi
315
  */
316
  protected function mailchimp()
317
  {
318
  if (empty($this->mc)) {
319
- $this->mc = new MailChimpApi($this->getOption('mailchimp_api_key'));
320
  }
321
  return $this->mc;
322
  }
16
  private $api;
17
 
18
  /**
19
+ * @var MailChimp_WooCommerce_MailChimpApi
20
  */
21
  private $mc;
22
 
116
  $this->setData('sync.syncing', true);
117
  $this->setData('sync.started_at', time());
118
 
119
+ // flag the store as syncing
120
+ mailchimp_get_api()->flagStoreSync(mailchimp_get_store_id(), true);
121
+
122
  return $this;
123
  }
124
 
127
  */
128
  public function flagStopSync()
129
  {
130
+ mailchimp_log('sync.completed', "Finished Sync :: ".date('D, M j, Y g:i A'));
131
+
132
  // this is the last thing we're doing so it's complete as of now.
133
  $this->setData('sync.syncing', false);
134
  $this->setData('sync.completed_at', time());
135
 
136
+ // flag the store as sync_finished
137
+ mailchimp_get_api()->flagStoreSync(mailchimp_get_store_id(), false);
138
 
139
  return $this;
140
  }
317
  }
318
 
319
  /**
320
+ * @return MailChimp_WooCommerce_MailChimpApi
321
  */
322
  protected function mailchimp()
323
  {
324
  if (empty($this->mc)) {
325
+ $this->mc = new MailChimp_WooCommerce_MailChimpApi($this->getOption('mailchimp_api_key'));
326
  }
327
  return $this->mc;
328
  }
includes/processes/class-mailchimp-woocommerce-cart-update.php CHANGED
@@ -56,7 +56,7 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
56
  }
57
 
58
  /**
59
- * @return bool|MailChimp_Cart
60
  */
61
  public function process()
62
  {
@@ -68,7 +68,7 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
68
 
69
  $this->cart_data = json_decode($this->cart_data, true);
70
 
71
- $api = new MailChimpApi($options['mailchimp_api_key']);
72
 
73
  // delete it and the add it back.
74
  $api->deleteCartByID($store_id, $this->unique_id);
@@ -78,12 +78,12 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
78
  return false;
79
  }
80
 
81
- $customer = new MailChimp_Customer();
82
  $customer->setId($this->unique_id);
83
  $customer->setEmailAddress($this->email);
84
  $customer->setOptInStatus(false);
85
 
86
- $cart = new MailChimp_Cart();
87
  $cart->setId($this->unique_id);
88
  $cart->setCampaignID($this->campaign_id);
89
  $cart->setCheckoutUrl(wc_get_checkout_url());
@@ -125,7 +125,7 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
125
  // let's loop through each item, verify that we have the product or not.
126
  // if not, we will add it.
127
  foreach ($products as $item) {
128
- /** @var MailChimp_LineItem $item */
129
  $transformer = new MailChimp_WooCommerce_Single_Product($item->getProductID());
130
  if (!$transformer->api()->getStoreProduct($store_id, $item->getProductId())) {
131
  $transformer->handle();
@@ -152,13 +152,13 @@ class MailChimp_WooCommerce_Cart_Update extends WP_Job
152
  /**
153
  * @param string $hash
154
  * @param $item
155
- * @return MailChimp_LineItem
156
  */
157
  protected function transformLineItem($hash, $item)
158
  {
159
  $product = new WC_Product($item['product_id']);
160
 
161
- $line = new MailChimp_LineItem();
162
  $line->setId($hash);
163
  $line->setProductId($item['product_id']);
164
 
56
  }
57
 
58
  /**
59
+ * @return bool|MailChimp_WooCommerce_Cart
60
  */
61
  public function process()
62
  {
68
 
69
  $this->cart_data = json_decode($this->cart_data, true);
70
 
71
+ $api = new MailChimp_WooCommerce_MailChimpApi($options['mailchimp_api_key']);
72
 
73
  // delete it and the add it back.
74
  $api->deleteCartByID($store_id, $this->unique_id);
78
  return false;
79
  }
80
 
81
+ $customer = new MailChimp_WooCommerce_Customer();
82
  $customer->setId($this->unique_id);
83
  $customer->setEmailAddress($this->email);
84
  $customer->setOptInStatus(false);
85
 
86
+ $cart = new MailChimp_WooCommerce_Cart();
87
  $cart->setId($this->unique_id);
88
  $cart->setCampaignID($this->campaign_id);
89
  $cart->setCheckoutUrl(wc_get_checkout_url());
125
  // let's loop through each item, verify that we have the product or not.
126
  // if not, we will add it.
127
  foreach ($products as $item) {
128
+ /** @var MailChimp_WooCommerce_LineItem $item */
129
  $transformer = new MailChimp_WooCommerce_Single_Product($item->getProductID());
130
  if (!$transformer->api()->getStoreProduct($store_id, $item->getProductId())) {
131
  $transformer->handle();
152
  /**
153
  * @param string $hash
154
  * @param $item
155
+ * @return MailChimp_WooCommerce_LineItem
156
  */
157
  protected function transformLineItem($hash, $item)
158
  {
159
  $product = new WC_Product($item['product_id']);
160
 
161
+ $line = new MailChimp_WooCommerce_LineItem();
162
  $line->setId($hash);
163
  $line->setProductId($item['product_id']);
164
 
includes/processes/class-mailchimp-woocommerce-process-orders.php CHANGED
@@ -25,13 +25,13 @@ class MailChimp_WooCommerce_Process_Orders extends MailChimp_WooCommerce_Abtstra
25
  }
26
 
27
  /**
28
- * @param MailChimp_Order $item
29
  *
30
  * @return mixed
31
  */
32
  protected function iterate($item)
33
  {
34
- if ($item instanceof MailChimp_Order) {
35
 
36
  // since we're syncing the customer for the first time, this is where we need to add the override
37
  // for subscriber status. We don't get the checkbox until this plugin is actually installed and working!
@@ -52,16 +52,20 @@ class MailChimp_WooCommerce_Process_Orders extends MailChimp_WooCommerce_Abtstra
52
  // make the call
53
  $response = $this->mailchimp()->$call($this->store_id, $item, false);
54
 
 
 
 
 
55
  mailchimp_log('sync.orders.success', $log);
56
 
57
  $this->items[] = array('response' => $response, 'item' => $item);
58
 
59
  return $response;
60
 
61
- } catch (MailChimp_Error $e) {
62
- mailchimp_log('sync.orders.error', "$call :: MailChimp_Error :: {$e->getMessage()}");
63
- } catch (MailChimp_ServerError $e) {
64
- mailchimp_log('sync.orders.error', "$call :: MailChimp_ServerError :: {$e->getMessage()}");
65
  } catch (Exception $e) {
66
  mailchimp_log('sync.orders.error', "$call :: Uncaught Exception :: {$e->getMessage()}");
67
  }
25
  }
26
 
27
  /**
28
+ * @param MailChimp_WooCommerce_Order $item
29
  *
30
  * @return mixed
31
  */
32
  protected function iterate($item)
33
  {
34
+ if ($item instanceof MailChimp_WooCommerce_Order) {
35
 
36
  // since we're syncing the customer for the first time, this is where we need to add the override
37
  // for subscriber status. We don't get the checkbox until this plugin is actually installed and working!
52
  // make the call
53
  $response = $this->mailchimp()->$call($this->store_id, $item, false);
54
 
55
+ if (empty($response)) {
56
+ return $response;
57
+ }
58
+
59
  mailchimp_log('sync.orders.success', $log);
60
 
61
  $this->items[] = array('response' => $response, 'item' => $item);
62
 
63
  return $response;
64
 
65
+ } catch (MailChimp_WooCommerce_Error $e) {
66
+ mailchimp_log('sync.orders.error', "$call :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
67
+ } catch (MailChimp_WooCommerce_ServerError $e) {
68
+ mailchimp_log('sync.orders.error', "$call :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
69
  } catch (Exception $e) {
70
  mailchimp_log('sync.orders.error', "$call :: Uncaught Exception :: {$e->getMessage()}");
71
  }
includes/processes/class-mailchimp-woocommerce-process-products.php CHANGED
@@ -24,13 +24,13 @@ class MailChimp_WooCommerce_Process_Products extends MailChimp_WooCommerce_Abtst
24
  }
25
 
26
  /**
27
- * @param MailChimp_Product $item
28
  *
29
  * @return mixed
30
  */
31
  protected function iterate($item) {
32
 
33
- if ($item instanceof MailChimp_Product) {
34
 
35
  // need to run the delete option on this before submitting because the API does not support PATCH yet.
36
  $this->mailchimp()->deleteStoreProduct($this->store_id, $item->getId());
@@ -46,10 +46,10 @@ class MailChimp_WooCommerce_Process_Products extends MailChimp_WooCommerce_Abtst
46
 
47
  return $response;
48
 
49
- } catch (MailChimp_Error $e) {
50
- mailchimp_log('sync.products.error', "addStoreProduct :: MailChimp_Error :: {$e->getMessage()}");
51
- } catch (MailChimp_ServerError $e) {
52
- mailchimp_log('sync.products.error', "addStoreProduct :: MailChimp_ServerError :: {$e->getMessage()}");
53
  } catch (Exception $e) {
54
  mailchimp_log('sync.products.error', "addStoreProduct :: Uncaught Exception :: {$e->getMessage()}");
55
  }
24
  }
25
 
26
  /**
27
+ * @param MailChimp_WooCommerce_Product $item
28
  *
29
  * @return mixed
30
  */
31
  protected function iterate($item) {
32
 
33
+ if ($item instanceof MailChimp_WooCommerce_Product) {
34
 
35
  // need to run the delete option on this before submitting because the API does not support PATCH yet.
36
  $this->mailchimp()->deleteStoreProduct($this->store_id, $item->getId());
46
 
47
  return $response;
48
 
49
+ } catch (MailChimp_WooCommerce_Error $e) {
50
+ mailchimp_log('sync.products.error', "addStoreProduct :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
51
+ } catch (MailChimp_WooCommerce_ServerError $e) {
52
+ mailchimp_log('sync.products.error', "addStoreProduct :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
53
  } catch (Exception $e) {
54
  mailchimp_log('sync.products.error', "addStoreProduct :: Uncaught Exception :: {$e->getMessage()}");
55
  }
includes/processes/class-mailchimp-woocommerce-single-order.php CHANGED
@@ -52,7 +52,7 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
52
  if (!empty($store_id) && is_array($options) && isset($options['mailchimp_api_key'])) {
53
 
54
  $job = new MailChimp_WooCommerce_Transform_Orders();
55
- $api = new MailChimpApi($options['mailchimp_api_key']);
56
 
57
  // set the campaign ID
58
  $job->campaign_id = $this->campaign_id;
@@ -76,13 +76,18 @@ class MailChimp_WooCommerce_Single_Order extends WP_Job
76
 
77
  $log = "$call :: #{$order->getId()} :: email: {$order->getCustomer()->getEmailAddress()}";
78
 
 
 
 
 
 
79
  mailchimp_log('order_submit.submitting', $log);
80
 
81
  // update or create
82
  $api_response = $api->$call($store_id, $order, false);
83
 
84
- if (!empty($job->campaign_id)) {
85
- $log .= ' :: campaign id '.$job->campaign_id;
86
  }
87
 
88
  mailchimp_log('order_submit.success', $log);
52
  if (!empty($store_id) && is_array($options) && isset($options['mailchimp_api_key'])) {
53
 
54
  $job = new MailChimp_WooCommerce_Transform_Orders();
55
+ $api = new MailChimp_WooCommerce_MailChimpApi($options['mailchimp_api_key']);
56
 
57
  // set the campaign ID
58
  $job->campaign_id = $this->campaign_id;
76
 
77
  $log = "$call :: #{$order->getId()} :: email: {$order->getCustomer()->getEmailAddress()}";
78
 
79
+ if (!empty($this->campaign_id) && $call === 'addStoreOrder') {
80
+ $log .= ' :: campaign id '.$this->campaign_id;
81
+ $order->setCampaignId($this->campaign_id);
82
+ }
83
+
84
  mailchimp_log('order_submit.submitting', $log);
85
 
86
  // update or create
87
  $api_response = $api->$call($store_id, $order, false);
88
 
89
+ if (empty($api_response)) {
90
+ return $api_response;
91
  }
92
 
93
  mailchimp_log('order_submit.success', $log);
includes/processes/class-mailchimp-woocommerce-single-product.php CHANGED
@@ -37,7 +37,7 @@ class MailChimp_WooCommerce_Single_Product extends WP_Job
37
  }
38
 
39
  /**
40
- * @return MailChimp_Product
41
  * @throws Exception
42
  */
43
  public function process()
@@ -60,10 +60,10 @@ class MailChimp_WooCommerce_Single_Product extends WP_Job
60
 
61
  return $product;
62
 
63
- } catch (MailChimp_Error $e) {
64
- mailchimp_log('product_submit.error', "addStoreProduct :: MailChimp_Error :: {$e->getMessage()}");
65
- } catch (MailChimp_ServerError $e) {
66
- mailchimp_log('product_submit.error', "addStoreProduct :: MailChimp_ServerError :: {$e->getMessage()}");
67
  } catch (Exception $e) {
68
  mailchimp_log('product_submit.error', "addStoreProduct :: Uncaught Exception :: {$e->getMessage()}");
69
  }
@@ -72,7 +72,7 @@ class MailChimp_WooCommerce_Single_Product extends WP_Job
72
  }
73
 
74
  /**
75
- * @return MailChimpApi
76
  */
77
  public function api()
78
  {
@@ -82,7 +82,7 @@ class MailChimp_WooCommerce_Single_Product extends WP_Job
82
  $options = get_option('mailchimp-woocommerce', array());
83
 
84
  if (!empty($this->store_id) && is_array($options) && isset($options['mailchimp_api_key'])) {
85
- return $this->api = new MailChimpApi($options['mailchimp_api_key']);
86
  }
87
 
88
  throw new \RuntimeException('The MailChimp API is not currently configured!');
37
  }
38
 
39
  /**
40
+ * @return MailChimp_WooCommerce_Product
41
  * @throws Exception
42
  */
43
  public function process()
60
 
61
  return $product;
62
 
63
+ } catch (MailChimp_WooCommerce_Error $e) {
64
+ mailchimp_log('product_submit.error', "addStoreProduct :: MailChimp_WooCommerce_Error :: {$e->getMessage()}");
65
+ } catch (MailChimp_WooCommerce_ServerError $e) {
66
+ mailchimp_log('product_submit.error', "addStoreProduct :: MailChimp_WooCommerce_ServerError :: {$e->getMessage()}");
67
  } catch (Exception $e) {
68
  mailchimp_log('product_submit.error', "addStoreProduct :: Uncaught Exception :: {$e->getMessage()}");
69
  }
72
  }
73
 
74
  /**
75
+ * @return MailChimp_WooCommerce_MailChimpApi
76
  */
77
  public function api()
78
  {
82
  $options = get_option('mailchimp-woocommerce', array());
83
 
84
  if (!empty($this->store_id) && is_array($options) && isset($options['mailchimp_api_key'])) {
85
+ return $this->api = new MailChimp_WooCommerce_MailChimpApi($options['mailchimp_api_key']);
86
  }
87
 
88
  throw new \RuntimeException('The MailChimp API is not currently configured!');
includes/slack/Contracts/Http/Interactor.php CHANGED
@@ -10,7 +10,7 @@ interface Interactor {
10
  * @param array $headers
11
  * @return \Frlnc\Slack\Contracts\Http\Response
12
  */
13
- public function get($url, array $parameters = [], array $headers = []);
14
 
15
  /**
16
  * Send a post request to a URL.
@@ -21,7 +21,7 @@ interface Interactor {
21
  * @param array $headers
22
  * @return \Frlnc\Slack\Contracts\Http\Response
23
  */
24
- public function post($url, array $urlParameters = [], array $postParameters = [], array $headers = []);
25
 
26
  /**
27
  * Sets the response factory to use.
10
  * @param array $headers
11
  * @return \Frlnc\Slack\Contracts\Http\Response
12
  */
13
+ public function get($url, array $parameters = array(), array $headers = array());
14
 
15
  /**
16
  * Send a post request to a URL.
21
  * @param array $headers
22
  * @return \Frlnc\Slack\Contracts\Http\Response
23
  */
24
+ public function post($url, array $urlParameters = array(), array $postParameters = array(), array $headers = array());
25
 
26
  /**
27
  * Sets the response factory to use.
includes/slack/Core/Commander.php CHANGED
@@ -10,410 +10,410 @@ class Commander {
10
  *
11
  * @var array
12
  */
13
- protected static $defaultHeaders = [];
14
 
15
  /**
16
  * The commands.
17
  *
18
  * @var array
19
  */
20
- protected static $commands = [
21
- 'api.test' => [
22
  'endpoint' => '/api.test',
23
  'token' => false
24
- ],
25
- 'auth.test' => [
26
  'endpoint' => '/auth.test',
27
  'token' => true
28
- ],
29
- 'channels.archive' => [
30
  'token' => true,
31
  'endpoint' => '/channels.archive'
32
- ],
33
- 'channels.create' => [
34
  'token' => true,
35
  'endpoint' => '/channels.create'
36
- ],
37
- 'channels.history' => [
38
  'token' => true,
39
  'endpoint' => '/channels.history'
40
- ],
41
- 'channels.info' => [
42
  'token' => true,
43
  'endpoint' => '/channels.info'
44
- ],
45
- 'channels.invite' => [
46
  'token' => true,
47
  'endpoint' => '/channels.invite'
48
- ],
49
- 'channels.join' => [
50
  'token' => true,
51
  'endpoint' => '/channels.join'
52
- ],
53
- 'channels.kick' => [
54
  'token' => true,
55
  'endpoint' => '/channels.kick'
56
- ],
57
- 'channels.leave' => [
58
  'token' => true,
59
  'endpoint' => '/channels.leave'
60
- ],
61
- 'channels.list' => [
62
  'token' => true,
63
  'endpoint' => '/channels.list'
64
- ],
65
- 'channels.mark' => [
66
  'token' => true,
67
  'endpoint' => '/channels.mark'
68
- ],
69
- 'channels.rename' => [
70
  'token' => true,
71
  'endpoint' => '/channels.rename'
72
- ],
73
- 'channels.setPurpose' => [
74
  'token' => true,
75
  'endpoint' => '/channels.setPurpose',
76
- 'format' => [
77
  'purpose'
78
- ]
79
- ],
80
- 'channels.setTopic' => [
81
  'token' => true,
82
  'endpoint' => '/channels.setTopic',
83
- 'format' => [
84
  'topic'
85
- ]
86
- ],
87
- 'channels.unarchive' => [
88
  'token' => true,
89
  'endpoint' => '/channels.unarchive'
90
- ],
91
- 'chat.delete' => [
92
  'token' => true,
93
  'endpoint' => '/chat.delete'
94
- ],
95
- 'chat.postMessage' => [
96
  'token' => true,
97
  'endpoint' => '/chat.postMessage',
98
- 'format' => [
99
  'text',
100
  'username'
101
- ]
102
- ],
103
- 'chat.update' => [
104
  'token' => true,
105
  'endpoint' => '/chat.update',
106
- 'format' => [
107
  'text'
108
- ]
109
- ],
110
- 'dnd.endDnd' => [
111
  'token' => true,
112
  'endpoint' => '/dnd.endDnd'
113
- ],
114
- 'dnd.endSnooze' => [
115
  'token' => true,
116
  'endpoint' => '/dnd.endSnooze'
117
- ],
118
- 'dnd.info' => [
119
  'token' => true,
120
  'endpoint' => '/dnd.info'
121
- ],
122
- 'dnd.setSnooze' => [
123
  'token' => true,
124
  'endpoint' => '/dnd.setSnooze'
125
- ],
126
- 'dnd.teamInfo' => [
127
  'token' => true,
128
  'endpoint' => '/dnd.teamInfo'
129
- ],
130
- 'emoji.list' => [
131
  'token' => true,
132
  'endpoint' => '/emoji.list'
133
- ],
134
- 'files.comments.add' => [
135
  'token' => true,
136
  'endpoint' => '/files.comments.add'
137
- ],
138
- 'files.comments.delete' => [
139
  'token' => true,
140
  'endpoint' => '/files.comments.delete'
141
- ],
142
- 'files.comments.edit' => [
143
  'token' => true,
144
  'endpoint' => '/files.comments.edit'
145
- ],
146
- 'files.delete' => [
147
  'token' => true,
148
  'endpoint' => '/files.delete'
149
- ],
150
- 'files.info' => [
151
  'token' => true,
152
  'endpoint' => '/files.info'
153
- ],
154
- 'files.list' => [
155
  'token' => true,
156
  'endpoint' => '/files.list'
157
- ],
158
- 'files.revokePublicURL' => [
159
  'token' => true,
160
  'endpoint' => '/files.revokePublicURL'
161
- ],
162
- 'files.sharedPublcURL' => [
163
  'token' => true,
164
  'endpoint' => '/files.sharedPublcURL'
165
- ],
166
- 'files.upload' => [
167
  'token' => true,
168
  'endpoint' => '/files.upload',
169
  'post' => true,
170
- 'headers' => [
171
  'Content-Type' => 'multipart/form-data'
172
- ],
173
- 'format' => [
174
  'filename',
175
  'title',
176
  'initial_comment'
177
- ]
178
- ],
179
- 'groups.archive' => [
180
  'token' => true,
181
  'endpoint' => '/groups.archive'
182
- ],
183
- 'groups.close' => [
184
  'token' => true,
185
  'endpoint' => '/groups.close'
186
- ],
187
- 'groups.create' => [
188
  'token' => true,
189
  'endpoint' => '/groups.create',
190
- 'format' => [
191
  'name'
192
- ]
193
- ],
194
- 'groups.createChild' => [
195
  'token' => true,
196
  'endpoint' => '/groups.createChild'
197
- ],
198
- 'groups.history' => [
199
  'token' => true,
200
  'endpoint' => '/groups.history'
201
- ],
202
- 'groups.info' => [
203
  'token' => true,
204
  'endpoint' => '/groups.info'
205
- ],
206
- 'groups.invite' => [
207
  'token' => true,
208
  'endpoint' => '/groups.invite'
209
- ],
210
- 'groups.kick' => [
211
  'token' => true,
212
  'endpoint' => '/groups.kick'
213
- ],
214
- 'groups.leave' => [
215
  'token' => true,
216
  'endpoint' => '/groups.leave'
217
- ],
218
- 'groups.list' => [
219
  'token' => true,
220
  'endpoint' => '/groups.list'
221
- ],
222
- 'groups.mark' => [
223
  'token' => true,
224
  'endpoint' => '/groups.mark'
225
- ],
226
- 'groups.open' => [
227
  'token' => true,
228
  'endpoint' => '/groups.open'
229
- ],
230
- 'groups.rename' => [
231
  'token' => true,
232
  'endpoint' => '/groups.rename'
233
- ],
234
- 'groups.setPurpose' => [
235
  'token' => true,
236
  'endpoint' => '/groups.setPurpose',
237
- 'format' => [
238
  'purpose'
239
- ]
240
- ],
241
- 'groups.setTopic' => [
242
  'token' => true,
243
  'endpoint' => '/groups.setTopic',
244
- 'format' => [
245
  'topic'
246
- ]
247
- ],
248
- 'groups.unarchive' => [
249
  'token' => true,
250
  'endpoint' => '/groups.unarchive'
251
- ],
252
- 'im.close' => [
253
  'token' => true,
254
  'endpoint' => '/im.close'
255
- ],
256
- 'im.history' => [
257
  'token' => true,
258
  'endpoint' => '/im.history'
259
- ],
260
- 'im.list' => [
261
  'token' => true,
262
  'endpoint' => '/im.list'
263
- ],
264
- 'im.mark' => [
265
  'token' => true,
266
  'endpoint' => '/im.mark'
267
- ],
268
- 'im.open' => [
269
  'token' => true,
270
  'endpoint' => '/im.open'
271
- ],
272
- 'mpim.close' => [
273
  'token' => true,
274
  'endpoint' => '/mpim.close'
275
- ],
276
- 'mpmim.history' => [
277
  'token' => true,
278
  'endpoint' => '/mpmim.history'
279
- ],
280
- 'mpim.list' => [
281
  'token' => true,
282
  'endpoint' => '/mpim.list'
283
- ],
284
- 'mpim.mark' => [
285
  'token' => true,
286
  'endpoint' => '/mpim.mark'
287
- ],
288
- 'mpim.open' => [
289
  'token' => true,
290
  'endpoint' => '/mpim.open'
291
- ],
292
- 'oauth.access' => [
293
  'token' => false,
294
  'endpoint' => '/oauth.access'
295
- ],
296
- 'pins.add' => [
297
  'token' => true,
298
  'endpoint' => '/pins.add'
299
- ],
300
- 'pins.list' => [
301
  'token' => true,
302
  'endpoint' => '/pins.list'
303
- ],
304
- 'pins.remove' => [
305
  'token' => true,
306
  'endpoint' => '/pins.remove'
307
- ],
308
- 'reactions.add' => [
309
  'token' => true,
310
  'endpoint' => '/reactions.add'
311
- ],
312
- 'reactions.get' => [
313
  'token' => true,
314
  'endpoint' => '/reactions.get'
315
- ],
316
- 'reactions.list' => [
317
  'token' => true,
318
  'endpoint' => '/reactions.list'
319
- ],
320
- 'reactions.remove' => [
321
  'token' => true,
322
  'endpoint' => '/reactions.remove'
323
- ],
324
- 'rtm.start' => [
325
  'token' => true,
326
  'endpoint' => '/rtm.start'
327
- ],
328
- 'search.all' => [
329
  'token' => true,
330
  'endpoint' => '/search.all'
331
- ],
332
- 'search.files' => [
333
  'token' => true,
334
  'endpoint' => '/search.files'
335
- ],
336
- 'search.messages' => [
337
  'token' => true,
338
  'endpoint' => '/search.messages'
339
- ],
340
- 'stars.add' => [
341
  'token' => true,
342
  'endpoint' => '/stars.add'
343
- ],
344
- 'stars.list' => [
345
  'token' => true,
346
  'endpoint' => '/stars.list'
347
- ],
348
- 'stars.remove' => [
349
  'token' => true,
350
  'endpoint' => '/stars.remove'
351
- ],
352
- 'team.accessLogs' => [
353
  'token' => true,
354
  'endpoint' => '/team.accessLogs'
355
- ],
356
- 'team.info' => [
357
  'token' => true,
358
  'endpoint' => '/team.info'
359
- ],
360
- 'team.integrationLogs' => [
361
  'token' => true,
362
  'endpoint' => '/team.integrationLogs'
363
- ],
364
- 'usergroups.create' => [
365
  'token' => true,
366
  'endpoint' => '/usergroups.create'
367
- ],
368
- 'usergroups.disable' => [
369
  'token' => true,
370
  'endpoint' => '/usergroups.disable'
371
- ],
372
- 'usergroups.enable' => [
373
  'token' => true,
374
  'endpoint' => '/usergroups.enable'
375
- ],
376
- 'usergroups.list' => [
377
  'token' => true,
378
  'endpoint' => '/usergroups.list'
379
- ],
380
- 'usergroups.update' => [
381
  'token' => true,
382
  'endpoint' => '/usergroups.update'
383
- ],
384
- 'usergroups.users.list' => [
385
  'token' => true,
386
  'endpoint' => '/usergroups.users.list'
387
- ],
388
- 'usergroups.users.update' => [
389
  'token' => true,
390
  'endpoint' => '/usergroups.users.update'
391
- ],
392
- 'users.getPresence' => [
393
  'token' => true,
394
  'endpoint' => '/users.getPresence'
395
- ],
396
- 'users.info' => [
397
  'token' => true,
398
  'endpoint' => '/users.info'
399
- ],
400
- 'users.list' => [
401
  'token' => true,
402
  'endpoint' => '/users.list'
403
- ],
404
- 'users.setActive' => [
405
  'token' => true,
406
  'endpoint' => '/users.setActive'
407
- ],
408
- 'users.setPresence' => [
409
  'token' => true,
410
  'endpoint' => '/users.setPresence'
411
- ],
412
- 'users.admin.invite' => [
413
  'token' => true,
414
  'endpoint' => '/users.admin.invite'
415
- ]
416
- ];
417
 
418
  /**
419
  * The base URL.
@@ -453,7 +453,7 @@ class Commander {
453
  * @param array $parameters
454
  * @return \Frlnc\Slack\Contracts\Http\Response
455
  */
456
- public function execute($command, array $parameters = [])
457
  {
458
  if (!isset(self::$commands[$command]))
459
  throw new InvalidArgumentException("The command '{$command}' is not currently supported");
@@ -461,21 +461,21 @@ class Commander {
461
  $command = self::$commands[$command];
462
 
463
  if ($command['token'])
464
- $parameters = array_merge($parameters, ['token' => $this->token]);
465
 
466
  if (isset($command['format']))
467
  foreach ($command['format'] as $format)
468
  if (isset($parameters[$format]))
469
  $parameters[$format] = self::format($parameters[$format]);
470
 
471
- $headers = [];
472
  if (isset($command['headers']))
473
  $headers = $command['headers'];
474
 
475
  $url = self::$baseUrl . $command['endpoint'];
476
 
477
  if (isset($command['post']) && $command['post'])
478
- return $this->interactor->post($url, [], $parameters, $headers);
479
 
480
  return $this->interactor->get($url, $parameters, $headers);
481
  }
10
  *
11
  * @var array
12
  */
13
+ protected static $defaultHeaders = array();
14
 
15
  /**
16
  * The commands.
17
  *
18
  * @var array
19
  */
20
+ protected static $commands = array(
21
+ 'api.test' => array(
22
  'endpoint' => '/api.test',
23
  'token' => false
24
+ ),
25
+ 'auth.test' => array(
26
  'endpoint' => '/auth.test',
27
  'token' => true
28
+ ),
29
+ 'channels.archive' => array(
30
  'token' => true,
31
  'endpoint' => '/channels.archive'
32
+ ),
33
+ 'channels.create' => array(
34
  'token' => true,
35
  'endpoint' => '/channels.create'
36
+ ),
37
+ 'channels.history' => array(
38
  'token' => true,
39
  'endpoint' => '/channels.history'
40
+ ),
41
+ 'channels.info' => array(
42
  'token' => true,
43
  'endpoint' => '/channels.info'
44
+ ),
45
+ 'channels.invite' => array(
46
  'token' => true,
47
  'endpoint' => '/channels.invite'
48
+ ),
49
+ 'channels.join' => array(
50
  'token' => true,
51
  'endpoint' => '/channels.join'
52
+ ),
53
+ 'channels.kick' => array(
54
  'token' => true,
55
  'endpoint' => '/channels.kick'
56
+ ),
57
+ 'channels.leave' => array(
58
  'token' => true,
59
  'endpoint' => '/channels.leave'
60
+ ),
61
+ 'channels.list' => array(
62
  'token' => true,
63
  'endpoint' => '/channels.list'
64
+ ),
65
+ 'channels.mark' => array(
66
  'token' => true,
67
  'endpoint' => '/channels.mark'
68
+ ),
69
+ 'channels.rename' => array(
70
  'token' => true,
71
  'endpoint' => '/channels.rename'
72
+ ),
73
+ 'channels.setPurpose' => array(
74
  'token' => true,
75
  'endpoint' => '/channels.setPurpose',
76
+ 'format' => array(
77
  'purpose'
78
+ ),
79
+ ),
80
+ 'channels.setTopic' => array(
81
  'token' => true,
82
  'endpoint' => '/channels.setTopic',
83
+ 'format' => array(
84
  'topic'
85
+ )
86
+ ),
87
+ 'channels.unarchive' => array(
88
  'token' => true,
89
  'endpoint' => '/channels.unarchive'
90
+ ),
91
+ 'chat.delete' => array(
92
  'token' => true,
93
  'endpoint' => '/chat.delete'
94
+ ),
95
+ 'chat.postMessage' => array(
96
  'token' => true,
97
  'endpoint' => '/chat.postMessage',
98
+ 'format' => array(
99
  'text',
100
  'username'
101
+ ),
102
+ ),
103
+ 'chat.update' => array(
104
  'token' => true,
105
  'endpoint' => '/chat.update',
106
+ 'format' => array(
107
  'text'
108
+ )
109
+ ),
110
+ 'dnd.endDnd' => array(
111
  'token' => true,
112
  'endpoint' => '/dnd.endDnd'
113
+ ),
114
+ 'dnd.endSnooze' => array(
115
  'token' => true,
116
  'endpoint' => '/dnd.endSnooze'
117
+ ),
118
+ 'dnd.info' => array(
119
  'token' => true,
120
  'endpoint' => '/dnd.info'
121
+ ),
122
+ 'dnd.setSnooze' => array(
123
  'token' => true,
124
  'endpoint' => '/dnd.setSnooze'
125
+ ),
126
+ 'dnd.teamInfo' => array(
127
  'token' => true,
128
  'endpoint' => '/dnd.teamInfo'
129
+ ),
130
+ 'emoji.list' => array(
131
  'token' => true,
132
  'endpoint' => '/emoji.list'
133
+ ),
134
+ 'files.comments.add' => array(
135
  'token' => true,
136
  'endpoint' => '/files.comments.add'
137
+ ),
138
+ 'files.comments.delete' => array(
139
  'token' => true,
140
  'endpoint' => '/files.comments.delete'
141
+ ),
142
+ 'files.comments.edit' => array(
143
  'token' => true,
144
  'endpoint' => '/files.comments.edit'
145
+ ),
146
+ 'files.delete' => array(
147
  'token' => true,
148
  'endpoint' => '/files.delete'
149
+ ),
150
+ 'files.info' => array(
151
  'token' => true,
152
  'endpoint' => '/files.info'
153
+ ),
154
+ 'files.list' => array(
155
  'token' => true,
156
  'endpoint' => '/files.list'
157
+ ),
158
+ 'files.revokePublicURL' => array(
159
  'token' => true,
160
  'endpoint' => '/files.revokePublicURL'
161
+ ),
162
+ 'files.sharedPublcURL' => array(
163
  'token' => true,
164
  'endpoint' => '/files.sharedPublcURL'
165
+ ),
166
+ 'files.upload' => array(
167
  'token' => true,
168
  'endpoint' => '/files.upload',
169
  'post' => true,
170
+ 'headers' => array(
171
  'Content-Type' => 'multipart/form-data'
172
+ ),
173
+ 'format' => array(
174
  'filename',
175
  'title',
176
  'initial_comment'
177
+ ),
178
+ ),
179
+ 'groups.archive' => array(
180
  'token' => true,
181
  'endpoint' => '/groups.archive'
182
+ ),
183
+ 'groups.close' => array(
184
  'token' => true,
185
  'endpoint' => '/groups.close'
186
+ ),
187
+ 'groups.create' => array(
188
  'token' => true,
189
  'endpoint' => '/groups.create',
190
+ 'format' => array(
191
  'name'
192
+ ),
193
+ ),
194
+ 'groups.createChild' => array(
195
  'token' => true,
196
  'endpoint' => '/groups.createChild'
197
+ ),
198
+ 'groups.history' => array(
199
  'token' => true,
200
  'endpoint' => '/groups.history'
201
+ ),
202
+ 'groups.info' => array(
203
  'token' => true,
204
  'endpoint' => '/groups.info'
205
+ ),
206
+ 'groups.invite' => array(
207
  'token' => true,
208
  'endpoint' => '/groups.invite'
209
+ ),
210
+ 'groups.kick' => array(
211
  'token' => true,
212
  'endpoint' => '/groups.kick'
213
+ ),
214
+ 'groups.leave' => array(
215
  'token' => true,
216
  'endpoint' => '/groups.leave'
217
+ ),
218
+ 'groups.list' => array(
219
  'token' => true,
220
  'endpoint' => '/groups.list'
221
+ ),
222
+ 'groups.mark' => array(
223
  'token' => true,
224
  'endpoint' => '/groups.mark'
225
+ ),
226
+ 'groups.open' => array(
227
  'token' => true,
228
  'endpoint' => '/groups.open'
229
+ ),
230
+ 'groups.rename' => array(
231
  'token' => true,
232
  'endpoint' => '/groups.rename'
233
+ ),
234
+ 'groups.setPurpose' => array(
235
  'token' => true,
236
  'endpoint' => '/groups.setPurpose',
237
+ 'format' => array(
238
  'purpose'
239
+ ),
240
+ ),
241
+ 'groups.setTopic' => array(
242
  'token' => true,
243
  'endpoint' => '/groups.setTopic',
244
+ 'format' => array(
245
  'topic'
246
+ ),
247
+ ),
248
+ 'groups.unarchive' => array(
249
  'token' => true,
250
  'endpoint' => '/groups.unarchive'
251
+ ),
252
+ 'im.close' => array(
253
  'token' => true,
254
  'endpoint' => '/im.close'
255
+ ),
256
+ 'im.history' => array(
257
  'token' => true,
258
  'endpoint' => '/im.history'
259
+ ),
260
+ 'im.list' => array(
261
  'token' => true,
262
  'endpoint' => '/im.list'
263
+ ),
264
+ 'im.mark' => array(
265
  'token' => true,
266
  'endpoint' => '/im.mark'
267
+ ),
268
+ 'im.open' => array(
269
  'token' => true,
270
  'endpoint' => '/im.open'
271
+ ),
272
+ 'mpim.close' => array(
273
  'token' => true,
274
  'endpoint' => '/mpim.close'
275
+ ),
276
+ 'mpmim.history' => array(
277
  'token' => true,
278
  'endpoint' => '/mpmim.history'
279
+ ),
280
+ 'mpim.list' => array(
281
  'token' => true,
282
  'endpoint' => '/mpim.list'
283
+ ),
284
+ 'mpim.mark' => array(
285
  'token' => true,
286
  'endpoint' => '/mpim.mark'
287
+ ),
288
+ 'mpim.open' => array(
289
  'token' => true,
290
  'endpoint' => '/mpim.open'
291
+ ),
292
+ 'oauth.access' => array(
293
  'token' => false,
294
  'endpoint' => '/oauth.access'
295
+ ),
296
+ 'pins.add' => array(
297
  'token' => true,
298
  'endpoint' => '/pins.add'
299
+ ),
300
+ 'pins.list' => array(
301
  'token' => true,
302
  'endpoint' => '/pins.list'
303
+ ),
304
+ 'pins.remove' => array(
305
  'token' => true,
306
  'endpoint' => '/pins.remove'
307
+ ),
308
+ 'reactions.add' => array(
309
  'token' => true,
310
  'endpoint' => '/reactions.add'
311
+ ),
312
+ 'reactions.get' => array(
313
  'token' => true,
314
  'endpoint' => '/reactions.get'
315
+ ),
316
+ 'reactions.list' => array(
317
  'token' => true,
318
  'endpoint' => '/reactions.list'
319
+ ),
320
+ 'reactions.remove' => array(
321
  'token' => true,
322
  'endpoint' => '/reactions.remove'
323
+ ),
324
+ 'rtm.start' => array(
325
  'token' => true,
326
  'endpoint' => '/rtm.start'
327
+ ),
328
+ 'search.all' => array(
329
  'token' => true,
330
  'endpoint' => '/search.all'
331
+ ),
332
+ 'search.files' => array(
333
  'token' => true,
334
  'endpoint' => '/search.files'
335
+ ),
336
+ 'search.messages' => array(
337
  'token' => true,
338
  'endpoint' => '/search.messages'
339
+ ),
340
+ 'stars.add' => array(
341
  'token' => true,
342
  'endpoint' => '/stars.add'
343
+ ),
344
+ 'stars.list' => array(
345
  'token' => true,
346
  'endpoint' => '/stars.list'
347
+ ),
348
+ 'stars.remove' => array(
349
  'token' => true,
350
  'endpoint' => '/stars.remove'
351
+ ),
352
+ 'team.accessLogs' => array(
353
  'token' => true,
354
  'endpoint' => '/team.accessLogs'
355
+ ),
356
+ 'team.info' => array(
357
  'token' => true,
358
  'endpoint' => '/team.info'
359
+ ),
360
+ 'team.integrationLogs' => array(
361
  'token' => true,
362
  'endpoint' => '/team.integrationLogs'
363
+ ),
364
+ 'usergroups.create' => array(
365
  'token' => true,
366
  'endpoint' => '/usergroups.create'
367
+ ),
368
+ 'usergroups.disable' => array(
369
  'token' => true,
370
  'endpoint' => '/usergroups.disable'
371
+ ),
372
+ 'usergroups.enable' => array(
373
  'token' => true,
374
  'endpoint' => '/usergroups.enable'
375
+ ),
376
+ 'usergroups.list' => array(
377
  'token' => true,
378
  'endpoint' => '/usergroups.list'
379
+ ),
380
+ 'usergroups.update' => array(
381
  'token' => true,
382
  'endpoint' => '/usergroups.update'
383
+ ),
384
+ 'usergroups.users.list' => array(
385
  'token' => true,
386
  'endpoint' => '/usergroups.users.list'
387
+ ),
388
+ 'usergroups.users.update' => array(
389
  'token' => true,
390
  'endpoint' => '/usergroups.users.update'
391
+ ),
392
+ 'users.getPresence' => array(
393
  'token' => true,
394
  'endpoint' => '/users.getPresence'
395
+ ),
396
+ 'users.info' => array(
397
  'token' => true,
398
  'endpoint' => '/users.info'
399
+ ),
400
+ 'users.list' => array(
401
  'token' => true,
402
  'endpoint' => '/users.list'
403
+ ),
404
+ 'users.setActive' => array(
405
  'token' => true,
406
  'endpoint' => '/users.setActive'
407
+ ),
408
+ 'users.setPresence' => array(
409
  'token' => true,
410
  'endpoint' => '/users.setPresence'
411
+ ),
412
+ 'users.admin.invite' => array(
413
  'token' => true,
414
  'endpoint' => '/users.admin.invite'
415
+ ),
416
+ );
417
 
418
  /**
419
  * The base URL.
453
  * @param array $parameters
454
  * @return \Frlnc\Slack\Contracts\Http\Response
455
  */
456
+ public function execute($command, array $parameters = array())
457
  {
458
  if (!isset(self::$commands[$command]))
459
  throw new InvalidArgumentException("The command '{$command}' is not currently supported");
461
  $command = self::$commands[$command];
462
 
463
  if ($command['token'])
464
+ $parameters = array_merge($parameters, array('token' => $this->token));
465
 
466
  if (isset($command['format']))
467
  foreach ($command['format'] as $format)
468
  if (isset($parameters[$format]))
469
  $parameters[$format] = self::format($parameters[$format]);
470
 
471
+ $headers = array();
472
  if (isset($command['headers']))
473
  $headers = $command['headers'];
474
 
475
  $url = self::$baseUrl . $command['endpoint'];
476
 
477
  if (isset($command['post']) && $command['post'])
478
+ return $this->interactor->post($url, array(), $parameters, $headers);
479
 
480
  return $this->interactor->get($url, $parameters, $headers);
481
  }
includes/slack/Http/CurlInteractor.php CHANGED
@@ -14,7 +14,7 @@ class CurlInteractor implements \Frlnc\Slack\Contracts\Http\Interactor {
14
  /**
15
  * {@inheritdoc}
16
  */
17
- public function get($url, array $parameters = [], array $headers = [])
18
  {
19
  $request = $this->prepareRequest($url, $parameters, $headers);
20
 
@@ -24,7 +24,7 @@ class CurlInteractor implements \Frlnc\Slack\Contracts\Http\Interactor {
24
  /**
25
  * {@inheritdoc}
26
  */
27
- public function post($url, array $urlParameters = [], array $postParameters = [], array $headers = [])
28
  {
29
  $request = $this->prepareRequest($url, $urlParameters, $headers);
30
 
@@ -42,7 +42,7 @@ class CurlInteractor implements \Frlnc\Slack\Contracts\Http\Interactor {
42
  * @param array $headers [description]
43
  * @return resource
44
  */
45
- protected static function prepareRequest($url, $parameters = [], $headers = [])
46
  {
47
  $request = curl_init();
48
 
@@ -79,7 +79,7 @@ class CurlInteractor implements \Frlnc\Slack\Contracts\Http\Interactor {
79
  else
80
  {
81
  $header_text = substr($headers, 0, strpos($headers, "\r\n\r\n"));
82
- $headers = [];
83
 
84
  foreach (explode("\r\n", $header_text) as $i => $line)
85
  if ($i === 0)
14
  /**
15
  * {@inheritdoc}
16
  */
17
+ public function get($url, array $parameters = array(), array $headers = array())
18
  {
19
  $request = $this->prepareRequest($url, $parameters, $headers);
20
 
24
  /**
25
  * {@inheritdoc}
26
  */
27
+ public function post($url, array $urlParameters = array(), array $postParameters = array(), array $headers = array())
28
  {
29
  $request = $this->prepareRequest($url, $urlParameters, $headers);
30
 
42
  * @param array $headers [description]
43
  * @return resource
44
  */
45
+ protected static function prepareRequest($url, $parameters = array(), $headers = array())
46
  {
47
  $request = curl_init();
48
 
79
  else
80
  {
81
  $header_text = substr($headers, 0, strpos($headers, "\r\n\r\n"));
82
+ $headers = array();
83
 
84
  foreach (explode("\r\n", $header_text) as $i => $line)
85
  if ($i === 0)
includes/slack/Http/SlackResponse.php CHANGED
@@ -28,7 +28,7 @@ class SlackResponse implements \Frlnc\Slack\Contracts\Http\Response, \JsonSerial
28
  * @param array $headers
29
  * @param integer $statusCode
30
  */
31
- public function __construct($body, array $headers = [], $statusCode = 404)
32
  {
33
  $this->body = json_decode($body, true);
34
  $this->headers = $headers;
@@ -74,11 +74,11 @@ class SlackResponse implements \Frlnc\Slack\Contracts\Http\Response, \JsonSerial
74
  */
75
  public function toArray()
76
  {
77
- return [
78
  'status_code' => $this->getStatusCode(),
79
  'headers' => $this->getHeaders(),
80
  'body' => $this->getBody()
81
- ];
82
  }
83
 
84
  }
28
  * @param array $headers
29
  * @param integer $statusCode
30
  */
31
+ public function __construct($body, array $headers = array(), $statusCode = 404)
32
  {
33
  $this->body = json_decode($body, true);
34
  $this->headers = $headers;
74
  */
75
  public function toArray()
76
  {
77
+ return array(
78
  'status_code' => $this->getStatusCode(),
79
  'headers' => $this->getHeaders(),
80
  'body' => $this->getBody()
81
+ );
82
  }
83
 
84
  }
includes/slack/Logger.php CHANGED
@@ -80,10 +80,10 @@ class Logger
80
  }
81
 
82
  try {
83
- $this->commander->execute('chat.postMessage', [
84
  'channel' => '#'.$this->channel,
85
  'text' => $message
86
- ]);
87
  } catch (\Exception $e) {
88
 
89
  }
80
  }
81
 
82
  try {
83
+ $this->commander->execute('chat.postMessage', array(
84
  'channel' => '#'.$this->channel,
85
  'text' => $message
86
+ ));
87
  } catch (\Exception $e) {
88
 
89
  }
includes/vendor/queue/classes/worker/wp-worker.php CHANGED
@@ -83,4 +83,4 @@ if ( ! class_exists( 'WP_Worker' ) ) {
83
  }
84
 
85
  }
86
- }
83
  }
84
 
85
  }
86
+ }
mailchimp-woocommerce.php CHANGED
@@ -9,14 +9,14 @@
9
  * that starts the plugin.
10
  *
11
  * @link https://mailchimp.com
12
- * @since 1.0.0
13
  * @package MailChimp_Woocommerce
14
  *
15
  * @wordpress-plugin
16
- * Plugin Name: MailChimp WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: MailChimp - WooCommerce plugin
19
- * Version: 1.0.0
20
  * Author: MailChimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
@@ -37,7 +37,7 @@ function mailchimp_environment_variables() {
37
  return (object) array(
38
  'repo' => 'master',
39
  'environment' => 'production',
40
- 'version' => '0.1.11',
41
  'slack_token' => false,
42
  'slack_channel' => 'mc-woo',
43
  );
@@ -51,12 +51,12 @@ function mailchimp_get_store_id() {
51
  }
52
 
53
  /**
54
- * @return bool|MailChimpApi
55
  */
56
  function mailchimp_get_api() {
57
  if (($options = get_option('mailchimp-woocommerce', false)) && is_array($options)) {
58
  if (isset($options['mailchimp_api_key'])) {
59
- return new MailChimpApi($options['mailchimp_api_key']);
60
  }
61
  }
62
  return false;
@@ -149,7 +149,17 @@ function mailchimp_get_timezone_list() {
149
  * The code that runs during plugin activation.
150
  * This action is documented in includes/class-mailchimp-woocommerce-activator.php
151
  */
152
- function activate_mailchimp_woocommerce() {
 
 
 
 
 
 
 
 
 
 
153
  require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-woocommerce-activator.php';
154
 
155
  MailChimp_Woocommerce_Activator::activate();
@@ -238,6 +248,24 @@ function mailchimp_log($action, $message, $data = array())
238
  ));
239
  }
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce' );
242
  register_deactivation_hook( __FILE__, 'deactivate_mailchimp_woocommerce' );
243
 
9
  * that starts the plugin.
10
  *
11
  * @link https://mailchimp.com
12
+ * @since 1.0.2
13
  * @package MailChimp_Woocommerce
14
  *
15
  * @wordpress-plugin
16
+ * Plugin Name: MailChimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: MailChimp - WooCommerce plugin
19
+ * Version: 1.0.2
20
  * Author: MailChimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
37
  return (object) array(
38
  'repo' => 'master',
39
  'environment' => 'production',
40
+ 'version' => '1.0.2',
41
  'slack_token' => false,
42
  'slack_channel' => 'mc-woo',
43
  );
51
  }
52
 
53
  /**
54
+ * @return bool|MailChimp_WooCommerce_MailChimpApi
55
  */
56
  function mailchimp_get_api() {
57
  if (($options = get_option('mailchimp-woocommerce', false)) && is_array($options)) {
58
  if (isset($options['mailchimp_api_key'])) {
59
+ return new MailChimp_WooCommerce_MailChimpApi($options['mailchimp_api_key']);
60
  }
61
  }
62
  return false;
149
  * The code that runs during plugin activation.
150
  * This action is documented in includes/class-mailchimp-woocommerce-activator.php
151
  */
152
+ function activate_mailchimp_woocommerce()
153
+ {
154
+ // if we don't have woocommerce we need to display a horrible error message before the plugin is installed.
155
+ if (!is_plugin_active('woocommerce/woocommerce.php')) {
156
+ // Deactivate the plugin
157
+ deactivate_plugins(__FILE__);
158
+ $error_message = __('The MailChimp For WooCommerce plugin requires the <a href="http://wordpress.org/extend/plugins/woocommerce/">WooCommerce</a> plugin to be active!', 'woocommerce');
159
+ wp_die($error_message);
160
+ }
161
+
162
+ // ok we can activate this thing.
163
  require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-woocommerce-activator.php';
164
 
165
  MailChimp_Woocommerce_Activator::activate();
248
  ));
249
  }
250
 
251
+ /**
252
+ * Determine if a given string contains a given substring.
253
+ *
254
+ * @param string $haystack
255
+ * @param string|array $needles
256
+ * @return bool
257
+ */
258
+ function mailchimp_string_contains($haystack, $needles)
259
+ {
260
+ foreach ((array) $needles as $needle) {
261
+ if ($needle != '' && mb_strpos($haystack, $needle) !== false) {
262
+ return true;
263
+ }
264
+ }
265
+
266
+ return false;
267
+ }
268
+
269
  register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce' );
270
  register_deactivation_hook( __FILE__, 'deactivate_mailchimp_woocommerce' );
271
 
public/class-mailchimp-woocommerce-public.php CHANGED
@@ -96,7 +96,7 @@ class MailChimp_Woocommerce_Public {
96
  * class.
97
  */
98
 
99
- wp_register_script($this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailchimp-woocommerce-public.js', array( 'jquery' ), $this->version, false);
100
 
101
  wp_localize_script($this->plugin_name, 'public_data', array(
102
  'site_url' => site_url(),
96
  * class.
97
  */
98
 
99
+ wp_register_script($this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailchimp-woocommerce-public.js', array(), $this->version, false);
100
 
101
  wp_localize_script($this->plugin_name, 'public_data', array(
102
  'site_url' => site_url(),
public/js/mailchimp-woocommerce-public.js CHANGED
@@ -1,38 +1,52 @@
1
  var mailchimp;
2
  var mailchimp_cart;
3
  var mailchimp_public_data;
 
4
 
5
- (function( $ ) {
6
- 'use strict';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- /**
9
- * All of the code for your public-facing JavaScript source
10
- * should reside in this file.
11
- *
12
- * Note: It has been assumed you will write jQuery code here, so the
13
- * $ function reference has been prepared for usage within the scope
14
- * of this function.
15
- *
16
- * This enables you to define handlers, for when the DOM is ready:
17
- *
18
- * $(function() {
19
- *
20
- * });
21
- *
22
- * When the window is loaded:
23
- *
24
- * $( window ).load(function() {
25
- *
26
- * });
27
- *
28
- * ...and/or other possibilities.
29
- *
30
- * Ideally, it is not considered best practise to attach more than a
31
- * single DOM-ready or window-load handler for a particular page.
32
- * Although scripts in the WordPress core, Plugins and Themes may be
33
- * practising this, we should strive to set a better example in our own work.
34
- */
35
 
 
 
 
 
 
36
  var requestTransport = null;
37
  var scriptTagCounter = 1, head;
38
  var storageLife = "30";
@@ -253,60 +267,41 @@ var mailchimp_public_data;
253
  return this.regex_email.test(email);
254
  };
255
 
256
- $(document).on("blur", "#billing_email",function() {
257
- var user = $("#billing_email").val();
258
- if (!mailchimp_cart.valueEmail(user)) {
259
- return false;
260
- }
261
- mailchimp_cart.setEmail(user);
262
-
263
- $.ajax({
264
- beforeSend: function (xhrObj) {
265
- xhrObj.setRequestHeader("Content-Type", "application/json");
266
- xhrObj.setRequestHeader("Accept", "application/json");
267
- },
268
- crossDomain: true,
269
- dataType: "json",
270
- type: 'POST',
271
- url: mailchimp_public_data.site_url+'?mailchimp-woocommerce[action]=submit-email&mailchimp-woocommerce[submission][email]='+user,
272
- data: {},
273
- success: function (responseData, textStatus, jqXHR) {
274
- console.log('email saved', responseData);
275
- },
276
- error: function (responseData, textStatus, errorThrown) {
277
- mailchimp_cart.post_error = errorThrown;
278
- console.log('error while saving email', responseData);
279
- }
280
- });
281
- });
282
-
283
  return this;
284
  }
285
 
286
  mailchimp_cart = new MailChimpCart();
 
 
 
287
 
288
- var qsc = mailchimpUtils.getQueryStringVars();
289
 
290
  // MailChimp Data //
291
  if (qsc.mc_cid !== undefined && qsc.mc_eid !== undefined) {
292
- $.ajax({
293
- beforeSend: function (xhrObj) {
294
- xhrObj.setRequestHeader("Content-Type", "application/json");
295
- xhrObj.setRequestHeader("Accept", "application/json");
296
- },
297
- crossDomain: true,
298
- dataType: "json",
299
- type: 'POST',
300
- url: mailchimp_public_data.site_url+'?mailchimp-woocommerce[action]=track-campaign&mailchimp-woocommerce[submission][campaign_id]='+qsc.mc_cid[0]+'&mailchimp-woocommerce[submission][email_id]='+qsc.mc_eid[0],
301
- data: {},
302
- success: function (responseData, textStatus, jqXHR) {
303
- console.log('campaign data saved', responseData);
304
- },
305
- error: function (responseData, textStatus, errorThrown) {
306
- mailchimp_cart.post_error = errorThrown;
307
- console.log('error while saving campaign data', responseData);
308
- }
309
- });
310
  }
311
 
312
- })( jQuery );
 
 
 
 
 
 
 
 
 
 
1
  var mailchimp;
2
  var mailchimp_cart;
3
  var mailchimp_public_data;
4
+ var mailchimp_billing_email;
5
 
6
+ var mailchimpReady = function(f){
7
+ /in/.test(document.readyState)?setTimeout('mailchimpReady('+f+')',9):f()
8
+ };
9
+
10
+ function mailchimpHandleBillingEmail() {
11
+
12
+ var billing_email = document.querySelector('#billing_email');
13
+ var user = undefined !== billing_email ? billing_email.value : '';
14
+
15
+ if (!mailchimp_cart.valueEmail(user)) {
16
+ return false;
17
+ }
18
+
19
+ mailchimp_cart.setEmail(user);
20
+
21
+ try {
22
+ var submit_email_url = mailchimp_public_data.site_url+
23
+ '?mailchimp-woocommerce[action]=submit-email&mailchimp-woocommerce[submission][email]='+user;
24
+
25
+ var submit_email_request = new XMLHttpRequest();
26
+
27
+ submit_email_request.open('POST', submit_email_url, true);
28
+
29
+ submit_email_request.onload = function() {
30
+ if (submit_email_request.status >= 200 && submit_email_request.status < 400) {
31
+ console.log('success', submit_email_request.responseText);
32
+ } else {
33
+ console.log('error', submit_email_request.responseText);
34
+ }
35
+ };
36
+
37
+ submit_email_request.onerror = function() {
38
+ console.log('submit email error', submit_email_request.responseText);
39
+ };
40
 
41
+ submit_email_request.setRequestHeader('Content-Type', 'application/json');
42
+ submit_email_request.setRequestHeader('Accept', 'application/json');
43
+ submit_email_request.send();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ } catch (e) {console.log('mailchimp_campaign_tracking.error', e);}
46
+ }
47
+
48
+ (function() {
49
+ 'use strict';
50
  var requestTransport = null;
51
  var scriptTagCounter = 1, head;
52
  var storageLife = "30";
267
  return this.regex_email.test(email);
268
  };
269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  return this;
271
  }
272
 
273
  mailchimp_cart = new MailChimpCart();
274
+ })();
275
+
276
+ mailchimpReady(function(){
277
 
278
+ var qsc = mailchimp.utils.getQueryStringVars();
279
 
280
  // MailChimp Data //
281
  if (qsc.mc_cid !== undefined && qsc.mc_eid !== undefined) {
282
+ var post_campaign_tracking_url = mailchimp_public_data.site_url+
283
+ '?mailchimp-woocommerce[action]=track-campaign&mailchimp-woocommerce[submission][campaign_id]='+
284
+ qsc.mc_cid[0]+
285
+ '&mailchimp-woocommerce[submission][email_id]='+
286
+ qsc.mc_eid[0];
287
+
288
+ try {
289
+ var post_campaign_request = new XMLHttpRequest();
290
+ post_campaign_request.open('POST', post_campaign_tracking_url, true);
291
+ post_campaign_request.setRequestHeader('Content-Type', 'application/json');
292
+ post_campaign_request.setRequestHeader('Accept', 'application/json');
293
+ post_campaign_request.send(data);
294
+ } catch (e) {console.log('mailchimp_campaign_tracking.error', e);}
 
 
 
 
 
295
  }
296
 
297
+ mailchimp_billing_email = document.querySelector('#billing_email');
298
+
299
+ if (mailchimp_billing_email) {
300
+ mailchimp_billing_email.onblur = function() {
301
+ mailchimpHandleBillingEmail();
302
+ };
303
+ mailchimp_billing_email.onfocus = function() {
304
+ mailchimpHandleBillingEmail();
305
+ };
306
+ }
307
+ });