Mailigen_Synchronizer - Version 1.2.6

Version Notes

- Added ability to sync customers and newsletter per website
- Added Webhooks Secret Key to verifying request, sent from Maligen
- Bugfixes

Download this release

Release Info

Developer Thomas Nelson
Extension Mailigen_Synchronizer
Version 1.2.6
Comparing to
See all releases


Code changes from version 1.2.0 to 1.2.6

Files changed (20) hide show
  1. app/code/community/Mailigen/Synchronizer/Block/Adminhtml/Newsletter/Secretkey.php +80 -0
  2. app/code/community/Mailigen/Synchronizer/Block/Adminhtml/Newsletter/Webhooks.php +45 -0
  3. app/code/community/Mailigen/Synchronizer/Helper/Data.php +181 -9
  4. app/code/community/Mailigen/Synchronizer/Model/Customer.php +9 -5
  5. app/code/community/Mailigen/Synchronizer/Model/List.php +8 -2
  6. app/code/community/Mailigen/Synchronizer/Model/Mailigen.php +199 -145
  7. app/code/community/Mailigen/Synchronizer/Model/Newsletter/Merge/Field.php +11 -7
  8. app/code/community/Mailigen/Synchronizer/Model/Observer.php +192 -149
  9. app/code/community/Mailigen/Synchronizer/Model/Resource/Customer/Collection.php +5 -1
  10. app/code/community/Mailigen/Synchronizer/Model/Resource/Iterator/Batched.php +57 -9
  11. app/code/community/Mailigen/Synchronizer/Model/Resource/Subscriber/Collection.php +11 -1
  12. app/code/community/Mailigen/Synchronizer/Model/System/Config/Backend/Newsletter/List.php +15 -6
  13. app/code/community/Mailigen/Synchronizer/controllers/Adminhtml/MailigenController.php +14 -0
  14. app/code/community/Mailigen/Synchronizer/controllers/WebhookController.php +12 -5
  15. app/code/community/Mailigen/Synchronizer/etc/config.xml +1 -1
  16. app/code/community/Mailigen/Synchronizer/etc/system.xml +22 -0
  17. app/code/community/Mailigen/Synchronizer/sql/mailigen_synchronizer_setup/mysql4-upgrade-1.2.1-1.2.2.php +21 -0
  18. lib/mailigen/MGAPI.class.php +16 -12
  19. package.xml +19 -18
  20. {app/code/community/Mailigen/Synchronizer → skin/adminhtml/default/default/mailigen_synchronizer}/Mailigen_webhooks_setup_instruction.jpg +0 -0
app/code/community/Mailigen/Synchronizer/Block/Adminhtml/Newsletter/Secretkey.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Block_Adminhtml_Newsletter_Secretkey
11
+ extends Mage_Adminhtml_Block_Abstract
12
+ implements Varien_Data_Form_Element_Renderer_Interface
13
+ {
14
+ /**
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
17
+ */
18
+ public function render(Varien_Data_Form_Element_Abstract $element)
19
+ {
20
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
21
+ $helper = Mage::helper('mailigen_synchronizer');
22
+ $storeId = $helper->getScopeStoreId();
23
+
24
+ $webhooksSecretKey = $helper->getWebhooksSecretKey($storeId);
25
+ if (empty($webhooksSecretKey)) {
26
+ $webhooksSecretKey = $helper->generateWebhooksSecretKey($storeId);
27
+ }
28
+
29
+ $html = '<table cellspacing="0" class="form-list">
30
+ <tr>
31
+ <td class="label">' . $helper->__('Mailigen Webhooks Secret Key') . '</td>
32
+ <td class="value">
33
+ <span id="webhooks_secret_key">' . $webhooksSecretKey . '</span>
34
+ </td>
35
+ <td class="scope-label">' . $this->_getGenerateButton() . '</td>
36
+ <td></td>
37
+ </tr>
38
+ </table>';
39
+
40
+ return $html;
41
+ }
42
+
43
+ /**
44
+ * Get generate webhooks secret key button html
45
+ *
46
+ * @return string
47
+ */
48
+ protected function _getGenerateButton()
49
+ {
50
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
51
+ $helper = Mage::helper('mailigen_synchronizer');
52
+
53
+ $generateWebhooksSecretKeyUrl = Mage::helper('adminhtml')->getUrl('*/mailigen/generateSecretKey', array(
54
+ 'storeId' => $helper->getScopeStoreId()
55
+ ));
56
+ $buttonJs = '<script type="text/javascript">
57
+ //<![CDATA[
58
+ function generateWebhooksSecretKey() {
59
+ new Ajax.Request("' . $generateWebhooksSecretKeyUrl . '", {
60
+ method: "get",
61
+ onSuccess: function(transport){
62
+ if (transport.responseText){
63
+ $("webhooks_secret_key").update(transport.responseText);
64
+ }
65
+ }
66
+ });
67
+ }
68
+ //]]>
69
+ </script>';
70
+
71
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
72
+ ->setData(array(
73
+ 'id' => 'generate_webhooks_secret_key_button',
74
+ 'label' => $this->helper('adminhtml')->__('Generate New Secret Key'),
75
+ 'onclick' => 'javascript:generateWebhooksSecretKey(); return false;'
76
+ ));
77
+
78
+ return $buttonJs . $button->toHtml();
79
+ }
80
+ }
app/code/community/Mailigen/Synchronizer/Block/Adminhtml/Newsletter/Webhooks.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mailigen_Synchronizer
5
+ *
6
+ * @category Mailigen
7
+ * @package Mailigen_Synchronizer
8
+ * @author Maksim Soldatjonok <maksold@gmail.com>
9
+ */
10
+ class Mailigen_Synchronizer_Block_Adminhtml_Newsletter_Webhooks
11
+ extends Mage_Adminhtml_Block_Abstract
12
+ implements Varien_Data_Form_Element_Renderer_Interface
13
+ {
14
+ /**
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
17
+ */
18
+ public function render(Varien_Data_Form_Element_Abstract $element)
19
+ {
20
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
21
+ $helper = Mage::helper('mailigen_synchronizer');
22
+ $storeId = $helper->getScopeStoreId();
23
+
24
+ $webhooksUrl = Mage::app()->getStore($storeId)->getBaseUrl() . 'mailigen/webhook/';
25
+ $webhooksSetupImg = $this->getSkinUrl('mailigen_synchronizer/Mailigen_webhooks_setup_instruction.jpg');
26
+ $webhooksSetupText = $helper->__('Mailigen webhooks setup instruction');
27
+
28
+ $html = '<table cellspacing="0" class="form-list">
29
+ <tr>
30
+ <td class="label">' . $helper->__('Mailigen Webhooks URL') . '</td>
31
+ <td class="value with-tooltip">
32
+ <a href="' . $webhooksUrl . '" target="_blank">' . $webhooksUrl . '</a>
33
+ <div class="field-tooltip"><div>
34
+ <img src="' . $webhooksSetupImg . '" alt="' . $webhooksSetupText . '" title="' . $webhooksSetupText . '" style="width:800px;"/>
35
+ </div></div>
36
+ <p class="note"><span>' . $helper->__('This URL you should use in Mailigen, to configure webhooks.') . '</span></p>
37
+ </td>
38
+ <td class="scope-label"></td>
39
+ <td></td>
40
+ </tr>
41
+ </table>';
42
+
43
+ return $html;
44
+ }
45
+ }
app/code/community/Mailigen/Synchronizer/Helper/Data.php CHANGED
@@ -16,21 +16,36 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
16
  const XML_PATH_NEWSLETTER_AUTOSYNC = 'mailigen_synchronizer/newsletter/autosync';
17
  const XML_PATH_NEWSLETTER_HANDLE_DEFAULT_EMAILS = 'mailigen_synchronizer/newsletter/handle_default_emails';
18
  const XML_PATH_NEWSLETTER_WEBHOOKS = 'mailigen_synchronizer/newsletter/webhooks';
 
19
  const XML_PATH_CUSTOMERS_CONTACT_LIST = 'mailigen_synchronizer/customers/contact_list';
20
  const XML_PATH_CUSTOMERS_NEW_LIST_TITLE = 'mailigen_synchronizer/customers/new_list_title';
21
  const XML_PATH_CUSTOMERS_AUTOSYNC = 'mailigen_synchronizer/customers/autosync';
22
  const XML_PATH_SYNC_MANUAL = 'mailigen_synchronizer/sync/manual';
23
  const XML_PATH_SYNC_STOP = 'mailigen_synchronizer/sync/stop';
24
 
25
- protected $_mgapi = null;
 
26
 
27
  /**
28
  * @param null $storeId
29
  * @return bool
 
30
  */
31
  public function isEnabled($storeId = null)
32
  {
33
- return Mage::getStoreConfigFlag(self::XML_PATH_ENABLED, $storeId);
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
 
36
  /**
@@ -39,6 +54,7 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
39
  */
40
  public function getApiKey($storeId = null)
41
  {
 
42
  return Mage::getStoreConfig(self::XML_PATH_API_KEY, $storeId);
43
  }
44
 
@@ -48,6 +64,7 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
48
  */
49
  public function getNewsletterContactList($storeId = null)
50
  {
 
51
  return Mage::getStoreConfig(self::XML_PATH_NEWSLETTER_CONTACT_LIST, $storeId);
52
  }
53
 
@@ -57,7 +74,19 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
57
  */
58
  public function canAutoSyncNewsletter($storeId = null)
59
  {
60
- return Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_AUTOSYNC, $storeId);
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
 
63
  /**
@@ -66,6 +95,7 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
66
  */
67
  public function canNewsletterHandleDefaultEmails($storeId = null)
68
  {
 
69
  return Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_HANDLE_DEFAULT_EMAILS, $storeId);
70
  }
71
 
@@ -75,15 +105,50 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
75
  */
76
  public function enabledWebhooks($storeId = null)
77
  {
 
78
  return Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_WEBHOOKS, $storeId);
79
  }
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  /**
82
  * @param null $storeId
83
  * @return mixed
84
  */
85
  public function getCustomersContactList($storeId = null)
86
  {
 
87
  return Mage::getStoreConfig(self::XML_PATH_CUSTOMERS_CONTACT_LIST, $storeId);
88
  }
89
 
@@ -93,20 +158,34 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
93
  */
94
  public function canAutoSyncCustomers($storeId = null)
95
  {
96
- return Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMERS_AUTOSYNC, $storeId);
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
  /**
100
- * @return MGAPI|null
 
101
  */
102
- public function getMailigenApi()
103
  {
104
- if (is_null($this->_mgapi)) {
 
105
  require_once Mage::getBaseDir('lib') . '/mailigen/MGAPI.class.php';
106
- $this->_mgapi = new MGAPI($this->getApiKey());
107
  }
108
 
109
- return $this->_mgapi;
110
  }
111
 
112
  /**
@@ -159,6 +238,86 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
159
  return $result;
160
  }
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  /**
163
  * @param $datetime
164
  * @param bool $full
@@ -192,4 +351,17 @@ class Mailigen_Synchronizer_Helper_Data extends Mage_Core_Helper_Abstract
192
  if (!$full) $string = array_slice($string, 0, 1);
193
  return $string ? implode(', ', $string) . ' ago' : 'just now';
194
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  }
16
  const XML_PATH_NEWSLETTER_AUTOSYNC = 'mailigen_synchronizer/newsletter/autosync';
17
  const XML_PATH_NEWSLETTER_HANDLE_DEFAULT_EMAILS = 'mailigen_synchronizer/newsletter/handle_default_emails';
18
  const XML_PATH_NEWSLETTER_WEBHOOKS = 'mailigen_synchronizer/newsletter/webhooks';
19
+ const XML_PATH_NEWSLETTER_WEBHOOKS_SECRET_KEY = 'mailigen_synchronizer/newsletter/webhooks_secret_key';
20
  const XML_PATH_CUSTOMERS_CONTACT_LIST = 'mailigen_synchronizer/customers/contact_list';
21
  const XML_PATH_CUSTOMERS_NEW_LIST_TITLE = 'mailigen_synchronizer/customers/new_list_title';
22
  const XML_PATH_CUSTOMERS_AUTOSYNC = 'mailigen_synchronizer/customers/autosync';
23
  const XML_PATH_SYNC_MANUAL = 'mailigen_synchronizer/sync/manual';
24
  const XML_PATH_SYNC_STOP = 'mailigen_synchronizer/sync/stop';
25
 
26
+ protected $_mgapi = array();
27
+ protected $_storeIds = null;
28
 
29
  /**
30
  * @param null $storeId
31
  * @return bool
32
+ * @todo Check, where this function is used
33
  */
34
  public function isEnabled($storeId = null)
35
  {
36
+ if (is_null($storeId)) {
37
+ $storeIds = $this->getStoreIds();
38
+ if (count($storeIds) > 0) {
39
+ foreach ($storeIds as $_storeId) {
40
+ if (Mage::getStoreConfigFlag(self::XML_PATH_ENABLED, $_storeId)) {
41
+ return true;
42
+ }
43
+ }
44
+ }
45
+ return false;
46
+ } else {
47
+ return Mage::getStoreConfigFlag(self::XML_PATH_ENABLED, $storeId);
48
+ }
49
  }
50
 
51
  /**
54
  */
55
  public function getApiKey($storeId = null)
56
  {
57
+ $storeId = is_null($storeId) ? $this->getDefaultStoreId() : $storeId;
58
  return Mage::getStoreConfig(self::XML_PATH_API_KEY, $storeId);
59
  }
60
 
64
  */
65
  public function getNewsletterContactList($storeId = null)
66
  {
67
+ $storeId = is_null($storeId) ? $this->getDefaultStoreId() : $storeId;
68
  return Mage::getStoreConfig(self::XML_PATH_NEWSLETTER_CONTACT_LIST, $storeId);
69
  }
70
 
74
  */
75
  public function canAutoSyncNewsletter($storeId = null)
76
  {
77
+ if (is_null($storeId)) {
78
+ $storeIds = $this->getStoreIds();
79
+ if (count($storeIds) > 0) {
80
+ foreach ($storeIds as $_storeId) {
81
+ if (Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_AUTOSYNC, $_storeId)) {
82
+ return true;
83
+ }
84
+ }
85
+ }
86
+ return false;
87
+ } else {
88
+ return Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_AUTOSYNC, $storeId);
89
+ }
90
  }
91
 
92
  /**
95
  */
96
  public function canNewsletterHandleDefaultEmails($storeId = null)
97
  {
98
+ $storeId = is_null($storeId) ? $this->getDefaultStoreId() : $storeId;
99
  return Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_HANDLE_DEFAULT_EMAILS, $storeId);
100
  }
101
 
105
  */
106
  public function enabledWebhooks($storeId = null)
107
  {
108
+ $storeId = is_null($storeId) ? $this->getDefaultStoreId() : $storeId;
109
  return Mage::getStoreConfigFlag(self::XML_PATH_NEWSLETTER_WEBHOOKS, $storeId);
110
  }
111
 
112
+ /**
113
+ * @param null $storeId
114
+ * @return mixed
115
+ */
116
+ public function getWebhooksSecretKey($storeId = null)
117
+ {
118
+ $storeId = is_null($storeId) ? $this->getDefaultStoreId() : $storeId;
119
+ return Mage::getStoreConfig(self::XML_PATH_NEWSLETTER_WEBHOOKS_SECRET_KEY, $storeId);
120
+ }
121
+
122
+ /**
123
+ * @param null $storeId
124
+ * @return string
125
+ */
126
+ public function generateWebhooksSecretKey($storeId = null)
127
+ {
128
+ $config = new Mage_Core_Model_Config();
129
+
130
+ $secretKey = bin2hex(openssl_random_pseudo_bytes(24));
131
+
132
+ if (is_null($storeId) || $storeId == Mage_Core_Model_App::ADMIN_STORE_ID) {
133
+ $config->saveConfig(self::XML_PATH_NEWSLETTER_WEBHOOKS_SECRET_KEY, $secretKey);
134
+ }
135
+ else {
136
+ $store = Mage::getModel('core/store')->load($storeId);
137
+ $scopeId = $store->getWebsiteId();
138
+ $config->saveConfig(self::XML_PATH_NEWSLETTER_WEBHOOKS_SECRET_KEY, $secretKey, 'websites', $scopeId);
139
+ }
140
+ $config->cleanCache();
141
+
142
+ return $secretKey;
143
+ }
144
+
145
  /**
146
  * @param null $storeId
147
  * @return mixed
148
  */
149
  public function getCustomersContactList($storeId = null)
150
  {
151
+ $storeId = is_null($storeId) ? $this->getDefaultStoreId() : $storeId;
152
  return Mage::getStoreConfig(self::XML_PATH_CUSTOMERS_CONTACT_LIST, $storeId);
153
  }
154
 
158
  */
159
  public function canAutoSyncCustomers($storeId = null)
160
  {
161
+ if (is_null($storeId)) {
162
+ $storeIds = $this->getStoreIds();
163
+ if (count($storeIds) > 0) {
164
+ foreach ($storeIds as $_storeId) {
165
+ if (Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMERS_AUTOSYNC, $_storeId)) {
166
+ return true;
167
+ }
168
+ }
169
+ }
170
+ return false;
171
+ } else {
172
+ return Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMERS_AUTOSYNC, $storeId);
173
+ }
174
  }
175
 
176
  /**
177
+ * @param null $storeId
178
+ * @return MGAPI|mixed
179
  */
180
+ public function getMailigenApi($storeId = null)
181
  {
182
+ $storeId = is_null($storeId) ? $this->getDefaultStoreId() : $storeId;
183
+ if (!isset($this->_mgapi[$storeId])) {
184
  require_once Mage::getBaseDir('lib') . '/mailigen/MGAPI.class.php';
185
+ $this->_mgapi[$storeId] = new MGAPI($this->getApiKey($storeId), false, true);
186
  }
187
 
188
+ return $this->_mgapi[$storeId];
189
  }
190
 
191
  /**
238
  return $result;
239
  }
240
 
241
+ /**
242
+ * Get Store ids with enable Mailigen Sync
243
+ * @return array
244
+ */
245
+ public function getStoreIds()
246
+ {
247
+ if (is_null($this->_storeIds)) {
248
+ $this->_storeIds = array();
249
+ $websites = Mage::app()->getWebsites();
250
+ foreach ($websites as $_website) {
251
+ $storeId = $_website->getDefaultGroup()->getDefaultStore()->getId();
252
+ if ($this->isEnabled($storeId)) {
253
+ array_push($this->_storeIds, $storeId);
254
+ }
255
+ }
256
+ }
257
+
258
+ return $this->_storeIds;
259
+ }
260
+
261
+ /**
262
+ * @return array
263
+ */
264
+ public function getNewsletterContactLists()
265
+ {
266
+ $storesIds = $this->getStoreIds();
267
+ $result = array();
268
+ foreach ($storesIds as $_storeId) {
269
+ $list = $this->getNewsletterContactList($_storeId);
270
+ if (strlen($list) > 0) {
271
+ $result[$_storeId] = $list;
272
+ }
273
+ }
274
+
275
+ return $result;
276
+ }
277
+
278
+ /**
279
+ * @return array
280
+ */
281
+ public function getCustomerContactLists()
282
+ {
283
+ $storesIds = $this->getStoreIds();
284
+ $result = array();
285
+ foreach ($storesIds as $_storeId) {
286
+ $list = $this->getCustomersContactList($_storeId);
287
+ if (strlen($list) > 0) {
288
+ $result[$_storeId] = $list;
289
+ }
290
+ }
291
+
292
+ return $result;
293
+ }
294
+
295
+ /**
296
+ * @return mixed
297
+ */
298
+ public function getDefaultStoreId()
299
+ {
300
+ return Mage::app()->getWebsite()->getDefaultGroup()->getDefaultStoreId();
301
+ }
302
+
303
+ /**
304
+ * @return int
305
+ */
306
+ public function getScopeStoreId()
307
+ {
308
+ if (strlen($code = Mage::getSingleton('adminhtml/config_data')->getStore())) // store level
309
+ {
310
+ return Mage::getModel('core/store')->load($code)->getId();
311
+ } elseif (strlen($code = Mage::getSingleton('adminhtml/config_data')->getWebsite())) // website level
312
+ {
313
+ $website_id = Mage::getModel('core/website')->load($code)->getId();
314
+ return Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
315
+ } else // default level
316
+ {
317
+ return Mage_Core_Model_App::ADMIN_STORE_ID;
318
+ }
319
+ }
320
+
321
  /**
322
  * @param $datetime
323
  * @param bool $full
351
  if (!$full) $string = array_slice($string, 0, 1);
352
  return $string ? implode(', ', $string) . ' ago' : 'just now';
353
  }
354
+
355
+ /**
356
+ * @param $data
357
+ * @param $signature
358
+ * @param null $storeId
359
+ * @return bool
360
+ */
361
+ public function verifySignature($data, $signature, $storeId = null)
362
+ {
363
+ $secretKey = $this->getWebhooksSecretKey($storeId);
364
+ $hash = hash_hmac('sha1', $data, $secretKey);
365
+ return $signature === 'sha1=' . $hash;
366
+ }
367
  }
app/code/community/Mailigen/Synchronizer/Model/Customer.php CHANGED
@@ -20,11 +20,14 @@ class Mailigen_Synchronizer_Model_Customer extends Mage_Core_Model_Abstract
20
  }
21
 
22
  /**
 
23
  * @return int
24
  */
25
- public function updateCustomersOrderInfo(){
26
- $customerIds = Mage::getModel('customer/customer')->getCollection()->getAllIds();
27
- $customerFlatIds = $this->getCollection()->getAllIds();
 
 
28
  $newCustomerFlatIds = array_diff($customerIds, $customerFlatIds);
29
 
30
  if (count($newCustomerFlatIds) > 0) {
@@ -61,7 +64,7 @@ class Mailigen_Synchronizer_Model_Customer extends Mage_Core_Model_Abstract
61
  * Sum all orders grand total
62
  */
63
  $totalGrandTotal = 0;
64
- if ($orders->count() > 0) {
65
  foreach ($orders as $_order) {
66
  $totalGrandTotal += $_order->getGrandTotal();
67
  }
@@ -78,10 +81,11 @@ class Mailigen_Synchronizer_Model_Customer extends Mage_Core_Model_Abstract
78
  $this->_newCustomersOrderInfoData[] = array(
79
  'id' => $customer->getId(),
80
  'email' => $customer->getEmail(),
 
81
  'lastorderdate' => $orders && $lastOrder ? $helper->getFormattedDate($lastOrder->getCreatedAt()) : '',
82
  'valueoflastorder' => $orders && $lastOrder ? (float)$lastOrder->getGrandTotal() : '',
83
  'totalvalueoforders' => (float)$totalGrandTotal,
84
- 'totalnumberoforders' => (int)$orders->count(),
85
  'numberofitemsincart' => $quote ? (int)$quote->getItemsQty() : '',
86
  'valueofcurrentcart' => $quote ? (float)$quote->getGrandTotal() : '',
87
  'lastitemincartaddingdate' => $quote ? $helper->getFormattedDate($quote->getUpdatedAt()) : '',
20
  }
21
 
22
  /**
23
+ * @param int|null $websiteId
24
  * @return int
25
  */
26
+ public function updateCustomersOrderInfo($websiteId = null){
27
+ $customerIds = Mage::getModel('customer/customer')->getCollection()
28
+ ->addAttributeToFilter('website_id', $websiteId)
29
+ ->getAllIds();
30
+ $customerFlatIds = $this->getCollection()->getAllIds(false, false, $websiteId);
31
  $newCustomerFlatIds = array_diff($customerIds, $customerFlatIds);
32
 
33
  if (count($newCustomerFlatIds) > 0) {
64
  * Sum all orders grand total
65
  */
66
  $totalGrandTotal = 0;
67
+ if ($orders->getSize() > 0) {
68
  foreach ($orders as $_order) {
69
  $totalGrandTotal += $_order->getGrandTotal();
70
  }
81
  $this->_newCustomersOrderInfoData[] = array(
82
  'id' => $customer->getId(),
83
  'email' => $customer->getEmail(),
84
+ 'website_id' => $customer->getWebsiteId(),
85
  'lastorderdate' => $orders && $lastOrder ? $helper->getFormattedDate($lastOrder->getCreatedAt()) : '',
86
  'valueoflastorder' => $orders && $lastOrder ? (float)$lastOrder->getGrandTotal() : '',
87
  'totalvalueoforders' => (float)$totalGrandTotal,
88
+ 'totalnumberoforders' => (int)$orders->getSize(),
89
  'numberofitemsincart' => $quote ? (int)$quote->getItemsQty() : '',
90
  'valueofcurrentcart' => $quote ? (float)$quote->getGrandTotal() : '',
91
  'lastitemincartaddingdate' => $quote ? $helper->getFormattedDate($quote->getUpdatedAt()) : '',
app/code/community/Mailigen/Synchronizer/Model/List.php CHANGED
@@ -27,7 +27,10 @@ class Mailigen_Synchronizer_Model_List extends Mage_Core_Model_Abstract
27
  public function getLists($load = false)
28
  {
29
  if (is_null($this->_lists) || $load) {
30
- $api = Mage::helper('mailigen_synchronizer')->getMailigenApi();
 
 
 
31
  $this->_lists = $api->lists();
32
  }
33
  return $this->_lists;
@@ -74,6 +77,9 @@ class Mailigen_Synchronizer_Model_List extends Mage_Core_Model_Abstract
74
 
75
  /** @var $logger Mailigen_Synchronizer_Helper_Log */
76
  $logger = Mage::helper('mailigen_synchronizer/log');
 
 
 
77
 
78
  $options = array(
79
  'permission_reminder' => ' ',
@@ -83,7 +89,7 @@ class Mailigen_Synchronizer_Model_List extends Mage_Core_Model_Abstract
83
  'has_email_type_option' => true
84
  );
85
 
86
- $api = Mage::helper('mailigen_synchronizer')->getMailigenApi();
87
  $retval = $api->listCreate($newListName, $options);
88
 
89
  if ($api->errorCode) {
27
  public function getLists($load = false)
28
  {
29
  if (is_null($this->_lists) || $load) {
30
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
31
+ $helper = Mage::helper('mailigen_synchronizer');
32
+ $storeId = $helper->getScopeStoreId();
33
+ $api = $helper->getMailigenApi($storeId);
34
  $this->_lists = $api->lists();
35
  }
36
  return $this->_lists;
77
 
78
  /** @var $logger Mailigen_Synchronizer_Helper_Log */
79
  $logger = Mage::helper('mailigen_synchronizer/log');
80
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
81
+ $helper = Mage::helper('mailigen_synchronizer');
82
+ $storeId = $helper->getScopeStoreId();
83
 
84
  $options = array(
85
  'permission_reminder' => ' ',
89
  'has_email_type_option' => true
90
  );
91
 
92
+ $api = $helper->getMailigenApi($storeId);
93
  $retval = $api->listCreate($newListName, $options);
94
 
95
  if ($api->errorCode) {
app/code/community/Mailigen/Synchronizer/Model/Mailigen.php CHANGED
@@ -32,30 +32,40 @@ class Mailigen_Synchronizer_Model_Mailigen extends Mage_Core_Model_Abstract
32
  /**
33
  * @var array
34
  */
35
- protected $_customersLog = array(
36
- 'update_success_count' => 0,
37
- 'update_error_count' => 0,
38
- 'update_errors' => array(),
39
- 'update_count' => 0,
40
- 'remove_success_count' => 0,
41
- 'remove_error_count' => 0,
42
- 'remove_errors' => array(),
43
- 'remove_count' => 0,
44
- );
45
 
46
  /**
47
  * @var array
48
  */
49
- protected $_newsletterLog = array(
50
- 'subscriber_success_count' => 0,
51
- 'subscriber_error_count' => 0,
52
- 'subscriber_errors' => array(),
53
- 'subscriber_count' => 0,
54
- 'unsubscriber_success_count' => 0,
55
- 'unsubscriber_error_count' => 0,
56
- 'unsubscriber_errors' => array(),
57
- 'unsubscriber_count' => 0,
58
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  public function syncNewsletter()
61
  {
@@ -63,66 +73,85 @@ class Mailigen_Synchronizer_Model_Mailigen extends Mage_Core_Model_Abstract
63
  $logger = Mage::helper('mailigen_synchronizer/log');
64
  /** @var $helper Mailigen_Synchronizer_Helper_Data */
65
  $helper = Mage::helper('mailigen_synchronizer');
66
- $logger->log('Newsletter synchronization started');
67
- $this->_newsletterListId = $helper->getNewsletterContactList();
68
- if (!$this->_newsletterListId) {
69
- Mage::throwException("Newsletter contact list isn't selected");
70
- }
71
-
72
 
73
  /**
74
- * Create or update Merge fields
75
  */
76
- Mage::getModel('mailigen_synchronizer/newsletter_merge_field')->createMergeFields();
77
- $logger->log('Newsletter merge fields created and updated');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
 
80
- /**
81
- * Update subscribers in Mailigen
82
- */
83
- /** @var $subscribers Mailigen_Synchronizer_Model_Resource_Subscriber_Collection */
84
- $subscribers = Mage::getResourceSingleton('mailigen_synchronizer/subscriber_collection')
85
- ->getSubscribers(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
86
- if (count($subscribers) > 0) {
87
- $logger->log("Started updating subscribers in Mailigen");
88
- $iterator = Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
89
- $subscribers,
90
- array($this, '_prepareSubscriberData'),
91
- array($this, '_updateSubscribersInMailigen'),
92
- 100,
93
- 10000
94
- );
95
  /**
96
- * Reschedule task, to run after 2 min
97
  */
98
- if ($iterator == 0) {
99
- Mage::getModel('mailigen_synchronizer/schedule')->createJob(2);
100
- $this->_writeResultLogs();
101
- $logger->log("Reschedule task, to update subscribers in Mailigen after 2 min");
102
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
- $logger->log("Finished updating subscribers in Mailigen");
105
- }
106
- else {
107
- $logger->log("No subscribers to sync with Mailigen");
108
- }
109
- unset($subscribers);
110
 
111
- /**
112
- * Log subscribers info
113
- */
114
- $this->_writeResultLogs();
115
 
116
- /**
117
- * @todo Update unsubscribers in Mailigen
118
- */
119
 
120
- /**
121
- * Log unsubscribers info
122
- */
123
- $this->_writeResultLogs();
 
 
124
 
125
- $logger->log('Newsletter synchronization finished');
 
 
 
126
  }
127
 
128
  /**
@@ -219,102 +248,127 @@ class Mailigen_Synchronizer_Model_Mailigen extends Mage_Core_Model_Abstract
219
  $logger = Mage::helper('mailigen_synchronizer/log');
220
  /** @var $helper Mailigen_Synchronizer_Helper_Data */
221
  $helper = Mage::helper('mailigen_synchronizer');
222
- $logger->log('Customers synchronization started');
223
- $this->_customersListId = $helper->getCustomersContactList();
224
- if (!$this->_customersListId) {
225
- Mage::throwException("Customer contact list isn't selected");
226
- }
227
-
228
 
229
  /**
230
- * Create or update Merge fields
231
  */
232
- Mage::getModel('mailigen_synchronizer/customer_merge_field')->createMergeFields();
233
- $logger->log('Customer merge fields created and updated');
 
 
 
234
 
 
235
 
236
- /**
237
- * Update customers order info
238
- */
239
- $updatedCustomers = Mage::getModel('mailigen_synchronizer/customer')->updateCustomersOrderInfo();
240
- $logger->log("Updated $updatedCustomers customers in flat table");
 
 
241
 
242
 
243
- /**
244
- * Update Customers in Mailigen
245
- */
246
- $updateCustomerIds = Mage::getModel('mailigen_synchronizer/customer')->getCollection()->getAllIds(0, 0);
247
- /** @var $updateCustomers Mage_Customer_Model_Resource_Customer_Collection */
248
- $updateCustomers = Mage::getModel('mailigen_synchronizer/customer')->getCustomerCollection($updateCustomerIds);
249
- if (count($updateCustomerIds) > 0 && $updateCustomers) {
250
- $logger->log("Started updating customers in Mailigen");
251
- $iterator = Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
252
- $updateCustomers,
253
- array($this, '_prepareCustomerDataForUpdate'),
254
- array($this, '_updateCustomersInMailigen'),
255
- 100,
256
- 10000
257
- );
258
  /**
259
- * Reschedule task, to run after 2 min
260
  */
261
- if ($iterator == 0) {
262
- Mage::getModel('mailigen_synchronizer/schedule')->createJob(2);
263
- $this->_writeResultLogs();
264
- $logger->log("Reschedule task, to update customers in Mailigen after 2 min");
265
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  }
267
- $logger->log("Finished updating customers in Mailigen");
268
- }
269
- unset($updateCustomerIds, $updateCustomers);
270
 
271
- /**
272
- * Log update info
273
- */
274
- $this->_writeResultLogs();
275
 
276
 
277
- /**
278
- * Remove Customers from Mailigen
279
- */
280
- /** @var $removeCustomer Mailigen_Synchronizer_Model_Resource_Customer_Collection */
281
- $removeCustomers = Mage::getModel('mailigen_synchronizer/customer')->getCollection()
282
- ->addFieldToFilter('is_removed', 1)
283
- ->addFieldToFilter('is_synced', 0)
284
- ->addFieldToSelect(array('id', 'email'));
285
- if ($removeCustomers && count($removeCustomers) > 0) {
286
- $logger->log("Started removing customers from Mailigen");
287
- $iterator = Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
288
- $removeCustomers,
289
- array($this, '_prepareCustomerDataForRemove'),
290
- array($this, '_removeCustomersFromMailigen'),
291
- 100,
292
- 10000
293
- );
294
  /**
295
- * Reschedule task, to run after 2 min
296
  */
297
- if ($iterator == 0) {
298
- Mage::getModel('mailigen_synchronizer/schedule')->createJob(2);
299
- $this->_writeResultLogs();
300
- $logger->log("Reschedule task to remove customers in Mailigen after 2 min");
301
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  }
303
- $logger->log("Finished removing customers from Mailigen");
304
- }
305
- unset($removeCustomers);
306
 
307
- /**
308
- * Remove synced and removed customers from Flat table
309
- */
310
- Mage::getModel('mailigen_synchronizer/customer')->removeSyncedAndRemovedCustomers();
311
 
312
- /**
313
- * Log remove info
314
- */
315
- $this->_writeResultLogs();
 
 
 
 
 
316
 
317
- $logger->log('Customers synchronization finished');
318
  }
319
 
320
  /**
32
  /**
33
  * @var array
34
  */
35
+ protected $_customersLog = array();
 
 
 
 
 
 
 
 
 
36
 
37
  /**
38
  * @var array
39
  */
40
+ protected $_newsletterLog = array();
41
+
42
+ protected function _resetNewsletterLog()
43
+ {
44
+ $this->_newsletterLog = array(
45
+ 'subscriber_success_count' => 0,
46
+ 'subscriber_error_count' => 0,
47
+ 'subscriber_errors' => array(),
48
+ 'subscriber_count' => 0,
49
+ 'unsubscriber_success_count' => 0,
50
+ 'unsubscriber_error_count' => 0,
51
+ 'unsubscriber_errors' => array(),
52
+ 'unsubscriber_count' => 0,
53
+ );
54
+ }
55
+
56
+ protected function _resetCustomerLog()
57
+ {
58
+ $this->_customersLog = array(
59
+ 'update_success_count' => 0,
60
+ 'update_error_count' => 0,
61
+ 'update_errors' => array(),
62
+ 'update_count' => 0,
63
+ 'remove_success_count' => 0,
64
+ 'remove_error_count' => 0,
65
+ 'remove_errors' => array(),
66
+ 'remove_count' => 0,
67
+ );
68
+ }
69
 
70
  public function syncNewsletter()
71
  {
73
  $logger = Mage::helper('mailigen_synchronizer/log');
74
  /** @var $helper Mailigen_Synchronizer_Helper_Data */
75
  $helper = Mage::helper('mailigen_synchronizer');
76
+ /** @var $emulation Mage_Core_Model_App_Emulation */
77
+ $emulation = Mage::getModel('core/app_emulation');
 
 
 
 
78
 
79
  /**
80
+ * Get Newsletter lists per store
81
  */
82
+ $newsletterLists = $helper->getNewsletterContactLists();
83
+ if (count($newsletterLists) <= 0) {
84
+ $logger->log("Newsletter contact list isn't selected");
85
+ return;
86
+ }
87
+
88
+ $logger->log('Newsletter synchronization started for Store Ids: ' . implode(', ', array_keys($newsletterLists)));
89
+
90
+ foreach ($newsletterLists as $_storeId => $newsletterListId) {
91
+ $logger->log('Newsletter synchronization started for Store Id: ' . $_storeId);
92
+
93
+ $environment = $emulation->startEnvironmentEmulation($_storeId);
94
+ $this->_newsletterListId = $newsletterListId;
95
+ $this->_resetNewsletterLog();
96
+
97
+
98
+ /**
99
+ * Create or update Merge fields
100
+ */
101
+ Mage::getModel('mailigen_synchronizer/newsletter_merge_field')->createMergeFields();
102
+ $logger->log('Newsletter merge fields created and updated');
103
 
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  /**
106
+ * Update subscribers in Mailigen
107
  */
108
+ /** @var $subscribers Mailigen_Synchronizer_Model_Resource_Subscriber_Collection */
109
+ $subscribers = Mage::getResourceModel('mailigen_synchronizer/subscriber_collection')
110
+ ->getSubscribers(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED, 0, $_storeId);
111
+ if ($subscribers->getSize() > 0) {
112
+ $logger->log("Started updating subscribers in Mailigen");
113
+ $iterator = Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
114
+ $subscribers,
115
+ array($this, '_prepareSubscriberData'),
116
+ array($this, '_updateSubscribersInMailigen'),
117
+ 100,
118
+ 10000
119
+ );
120
+ /**
121
+ * Reschedule task, to run after 2 min
122
+ */
123
+ if ($iterator == 0) {
124
+ Mage::getModel('mailigen_synchronizer/schedule')->createJob(2);
125
+ $this->_writeResultLogs();
126
+ $logger->log("Reschedule task, to update subscribers in Mailigen after 2 min");
127
+ return;
128
+ }
129
+ $logger->log("Finished updating subscribers in Mailigen");
130
+ } else {
131
+ $logger->log("No subscribers to sync with Mailigen");
132
  }
133
+ unset($subscribers);
 
 
 
 
 
134
 
135
+ /**
136
+ * Log subscribers info
137
+ */
138
+ $this->_writeResultLogs();
139
 
140
+ /**
141
+ * @todo Update unsubscribers in Mailigen
142
+ */
143
 
144
+ /**
145
+ * Log unsubscribers info
146
+ */
147
+ // $this->_writeResultLogs();
148
+
149
+ $emulation->stopEnvironmentEmulation($environment);
150
 
151
+ $logger->log('Newsletter synchronization finished for Store Id: ' . $_storeId);
152
+ }
153
+
154
+ $logger->log('Newsletter synchronization finished for Store Ids: ' . implode(', ', array_keys($newsletterLists)));
155
  }
156
 
157
  /**
248
  $logger = Mage::helper('mailigen_synchronizer/log');
249
  /** @var $helper Mailigen_Synchronizer_Helper_Data */
250
  $helper = Mage::helper('mailigen_synchronizer');
251
+ /** @var $customerHelper Mailigen_Synchronizer_Helper_Customer */
252
+ $customerHelper = Mage::helper('mailigen_synchronizer/customer');
253
+ /** @var $emulation Mage_Core_Model_App_Emulation */
254
+ $emulation = Mage::getModel('core/app_emulation');
 
 
255
 
256
  /**
257
+ * Get Customer lists per store
258
  */
259
+ $customerLists = $helper->getCustomerContactLists();
260
+ if (count($customerLists) <= 0) {
261
+ $logger->log("Customer contact list isn't selected");
262
+ return;
263
+ }
264
 
265
+ $logger->log('Customer synchronization started for Store Ids: ' . implode(', ', array_keys($customerLists)));
266
 
267
+ foreach ($customerLists as $_storeId => $customerListId) {
268
+ $logger->log('Customer synchronization started for Store Id: ' . $_storeId);
269
+
270
+ $websiteId = $customerHelper->getWebsite($_storeId)->getWebsiteId();
271
+ $environment = $emulation->startEnvironmentEmulation($_storeId);
272
+ $this->_customersListId = $customerListId;
273
+ $this->_resetCustomerLog();
274
 
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  /**
277
+ * Create or update Merge fields
278
  */
279
+ Mage::getModel('mailigen_synchronizer/customer_merge_field')->createMergeFields();
280
+ $logger->log('Customer merge fields created and updated');
281
+
282
+
283
+ /**
284
+ * Update customers order info
285
+ */
286
+ $updatedCustomers = Mage::getModel('mailigen_synchronizer/customer')->updateCustomersOrderInfo($websiteId);
287
+ $logger->log("Updated $updatedCustomers customers in flat table");
288
+
289
+
290
+ /**
291
+ * Update Customers in Mailigen
292
+ */
293
+ $updateCustomerIds = Mage::getModel('mailigen_synchronizer/customer')->getCollection()
294
+ ->getAllIds(0, 0, $websiteId);
295
+ /** @var $updateCustomers Mage_Customer_Model_Resource_Customer_Collection */
296
+ $updateCustomers = Mage::getModel('mailigen_synchronizer/customer')->getCustomerCollection($updateCustomerIds);
297
+ if (count($updateCustomerIds) > 0 && $updateCustomers) {
298
+ $logger->log("Started updating customers in Mailigen");
299
+ $iterator = Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
300
+ $updateCustomers,
301
+ array($this, '_prepareCustomerDataForUpdate'),
302
+ array($this, '_updateCustomersInMailigen'),
303
+ 100,
304
+ 10000
305
+ );
306
+ /**
307
+ * Reschedule task, to run after 2 min
308
+ */
309
+ if ($iterator == 0) {
310
+ Mage::getModel('mailigen_synchronizer/schedule')->createJob(2);
311
+ $this->_writeResultLogs();
312
+ $logger->log("Reschedule task, to update customers in Mailigen after 2 min");
313
+ return;
314
+ }
315
+ $logger->log("Finished updating customers in Mailigen");
316
  }
317
+ unset($updateCustomerIds, $updateCustomers);
 
 
318
 
319
+ /**
320
+ * Log update info
321
+ */
322
+ $this->_writeResultLogs();
323
 
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  /**
326
+ * Remove Customers from Mailigen
327
  */
328
+ /** @var $removeCustomer Mailigen_Synchronizer_Model_Resource_Customer_Collection */
329
+ $removeCustomers = Mage::getModel('mailigen_synchronizer/customer')->getCollection()
330
+ ->addFieldToFilter('is_removed', 1)
331
+ ->addFieldToFilter('is_synced', 0)
332
+ ->addFieldToFilter('website_id', $websiteId)
333
+ ->addFieldToSelect(array('id', 'email'));
334
+ if ($removeCustomers && $removeCustomers->getSize() > 0) {
335
+ $logger->log("Started removing customers from Mailigen");
336
+ $iterator = Mage::getSingleton('mailigen_synchronizer/resource_iterator_batched')->walk(
337
+ $removeCustomers,
338
+ array($this, '_prepareCustomerDataForRemove'),
339
+ array($this, '_removeCustomersFromMailigen'),
340
+ 100,
341
+ 10000
342
+ );
343
+ /**
344
+ * Reschedule task, to run after 2 min
345
+ */
346
+ if ($iterator == 0) {
347
+ Mage::getModel('mailigen_synchronizer/schedule')->createJob(2);
348
+ $this->_writeResultLogs();
349
+ $logger->log("Reschedule task to remove customers in Mailigen after 2 min");
350
+ return;
351
+ }
352
+ $logger->log("Finished removing customers from Mailigen");
353
  }
354
+ unset($removeCustomers);
 
 
355
 
356
+ /**
357
+ * Remove synced and removed customers from Flat table
358
+ */
359
+ Mage::getModel('mailigen_synchronizer/customer')->removeSyncedAndRemovedCustomers();
360
 
361
+ /**
362
+ * Log remove info
363
+ */
364
+ $this->_writeResultLogs();
365
+
366
+ $emulation->stopEnvironmentEmulation($environment);
367
+
368
+ $logger->log('Customer synchronization finished for Store Id: ' . $_storeId);
369
+ }
370
 
371
+ $logger->log('Customer synchronization finished for Store Ids: ' . implode(', ', array_keys($customerLists)));
372
  }
373
 
374
  /**
app/code/community/Mailigen/Synchronizer/Model/Newsletter/Merge/Field.php CHANGED
@@ -39,17 +39,20 @@ class Mailigen_Synchronizer_Model_Newsletter_Merge_Field extends Mage_Core_Model
39
  );
40
  }
41
 
42
- public function createMergeFields()
 
 
 
43
  {
44
  /** @var $helper Mailigen_Synchronizer_Helper_Data */
45
  $helper = Mage::helper('mailigen_synchronizer');
46
- $api = $helper->getMailigenApi();
47
- $listId = $helper->getNewsletterContactList();
48
  if (empty($listId)) {
49
  Mage::throwException("Newsletter contact list isn't selected");
50
  }
51
 
52
- $createdFields = $this->_getCreatedMergeFields();
53
  $newFields = $this->_getMergeFieldsConfig();
54
 
55
  foreach ($newFields as $tag => $options) {
@@ -67,14 +70,15 @@ class Mailigen_Synchronizer_Model_Newsletter_Merge_Field extends Mage_Core_Model
67
  }
68
 
69
  /**
 
70
  * @return array
71
  */
72
- protected function _getCreatedMergeFields()
73
  {
74
  /** @var $helper Mailigen_Synchronizer_Helper_Data */
75
  $helper = Mage::helper('mailigen_synchronizer');
76
- $api = $helper->getMailigenApi();
77
- $listId = $helper->getNewsletterContactList();
78
 
79
  $createdMergeFields = array();
80
  $tmpCreatedMergeFields = $api->listMergeVars($listId);
39
  );
40
  }
41
 
42
+ /**
43
+ * @param null $storeId
44
+ */
45
+ public function createMergeFields($storeId = null)
46
  {
47
  /** @var $helper Mailigen_Synchronizer_Helper_Data */
48
  $helper = Mage::helper('mailigen_synchronizer');
49
+ $api = $helper->getMailigenApi($storeId);
50
+ $listId = $helper->getNewsletterContactList($storeId);
51
  if (empty($listId)) {
52
  Mage::throwException("Newsletter contact list isn't selected");
53
  }
54
 
55
+ $createdFields = $this->_getCreatedMergeFields($storeId);
56
  $newFields = $this->_getMergeFieldsConfig();
57
 
58
  foreach ($newFields as $tag => $options) {
70
  }
71
 
72
  /**
73
+ * @param null $storeId
74
  * @return array
75
  */
76
+ protected function _getCreatedMergeFields($storeId = null)
77
  {
78
  /** @var $helper Mailigen_Synchronizer_Helper_Data */
79
  $helper = Mage::helper('mailigen_synchronizer');
80
+ $api = $helper->getMailigenApi($storeId);
81
+ $listId = $helper->getNewsletterContactList($storeId);
82
 
83
  $createdMergeFields = array();
84
  $tmpCreatedMergeFields = $api->listMergeVars($listId);
app/code/community/Mailigen/Synchronizer/Model/Observer.php CHANGED
@@ -28,76 +28,80 @@ class Mailigen_Synchronizer_Model_Observer
28
  $logger = Mage::helper('mailigen_synchronizer/log');
29
  $subscriber = $observer->getDataObject();
30
 
31
- if ($helper->isEnabled() && $subscriber
32
- && ($subscriber->getIsStatusChanged() == true || $subscriber->getOrigData('subscriber_status') != $subscriber->getData('subscriber_status'))
33
- ) {
34
- $api = $helper->getMailigenApi();
35
- $newsletterListId = $helper->getNewsletterContactList();
36
- if (!$newsletterListId) {
37
- $logger->log('Newsletter contact list isn\'t selected');
38
- return;
39
- }
40
- $email_address = $subscriber->getSubscriberEmail();
41
-
42
- /**
43
- * Create or update Merge fields
44
- */
45
- Mage::getModel('mailigen_synchronizer/newsletter_merge_field')->createMergeFields();
46
- $logger->log('Newsletter merge fields created and updated');
47
 
48
- if ($subscriber->getSubscriberStatus() === Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
49
  /**
50
- * Subscribe newsletter
51
  */
52
- /** @var $customerHelper Mailigen_Synchronizer_Helper_Customer */
53
- $customerHelper = Mage::helper('mailigen_synchronizer/customer');
54
-
55
- // Prepare Merge vars
56
- $website = $customerHelper->getWebsite($subscriber->getStoreId());
57
- $merge_vars = array(
58
- 'EMAIL' => $subscriber->getSubscriberEmail(),
59
- 'WEBSITEID' => $website ? $website->getId() : 0,
60
- 'TYPE' => $customerHelper->getSubscriberType(1),
61
- 'STOREID' => $subscriber->getStoreId(),
62
- 'STORELANGUAGE' => $customerHelper->getStoreLanguage($subscriber->getStoreId()),
63
- );
64
-
65
- // If is a customer we also grab firstname and lastname
66
- if ($subscriber->getCustomerId()) {
67
- $customer = Mage::getModel('customer/customer')->load($subscriber->getCustomerId());
68
- $merge_vars['FNAME'] = $customer->getFirstname();
69
- $merge_vars['LNAME'] = $customer->getLastname();
70
- $merge_vars['TYPE'] = $customerHelper->getSubscriberType(2);
71
- }
 
 
 
 
 
 
 
72
 
73
- $send_welcome = $helper->canNewsletterHandleDefaultEmails();
74
 
75
- $retval = $api->listSubscribe($newsletterListId, $email_address, $merge_vars, 'html', false, true, $send_welcome);
76
- $logger->log('Subscribed newsletter with email: ' . $email_address);
77
- }
78
- elseif ($subscriber->getSubscriberStatus() === Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) {
79
- /**
80
- * Unsubscribe newsletter
81
- */
82
- $send_goodbye = $helper->canNewsletterHandleDefaultEmails();
83
- $retval = $api->listUnsubscribe($newsletterListId, $email_address, false, $send_goodbye, true);
84
- $logger->log('Unsubscribed newsletter with email: ' . $email_address);
85
- } else {
86
- // @todo Check Not Activated or Removed status?
87
- $retval = null;
88
- }
89
 
90
- if ($retval) {
91
- // Set subscriber synced
92
- Mage::getModel('mailigen_synchronizer/newsletter')->updateIsSynced($subscriber->getId(), true);
93
 
94
- // Set customer not synced
95
- if ($subscriber->getCustomerId()) {
96
- Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($subscriber->getCustomerId());
 
 
 
97
  }
98
- } elseif (!is_null($retval)) {
99
- $logger->log("Unable to (un)subscribe newsletter with email: $email_address. $api->errorCode: $api->errorMessage");
100
  }
 
 
101
  }
102
  }
103
 
@@ -112,30 +116,35 @@ class Mailigen_Synchronizer_Model_Observer
112
  $logger = Mage::helper('mailigen_synchronizer/log');
113
  $subscriber = $observer->getDataObject();
114
 
115
- if ($helper->isEnabled() && $subscriber) {
116
- $api = $helper->getMailigenApi();
117
- $newsletterListId = $helper->getNewsletterContactList();
118
- if (!$newsletterListId) {
119
- $logger->log('Newsletter contact list isn\'t selected');
120
- return;
121
- }
122
- $email_address = $subscriber->getSubscriberEmail();
123
-
124
- /**
125
- * Remove subscriber
126
- */
127
- $send_goodbye = $helper->canNewsletterHandleDefaultEmails();
128
- $retval = $api->listUnsubscribe($newsletterListId, $email_address, true, $send_goodbye, true);
129
- $logger->log('Remove subscriber with email: ' . $email_address);
130
-
131
- if ($retval) {
132
- // Set customer not synced
133
- if ($subscriber->getCustomerId()) {
134
- Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($subscriber->getCustomerId());
 
 
 
 
 
135
  }
136
- } elseif (!is_null($retval)) {
137
- $logger->log("Unable to remove subscriber with email: $email_address. $api->errorCode: $api->errorMessage");
138
  }
 
 
139
  }
140
  }
141
 
@@ -194,32 +203,44 @@ class Mailigen_Synchronizer_Model_Observer
194
  $helper = Mage::helper('mailigen_synchronizer');
195
  /** @var $mailigenSchedule Mailigen_Synchronizer_Model_Schedule */
196
  $mailigenSchedule = Mage::getModel('mailigen_synchronizer/schedule');
 
 
 
 
 
197
  $removeCache = false;
198
 
199
  /**
200
  * Create new newsletter list
201
  */
202
- $newsletterNewListName = Mage::getStoreConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_NEW_LIST_TITLE);
203
- if ($newsletterNewListName) {
204
  if ($mailigenSchedule->countPendingOrRunningJobs() == 0) {
205
  $newListValue = $list->createNewList($newsletterNewListName);
206
  if ($newListValue) {
207
- $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_CONTACT_LIST, $newListValue, 'default', 0);
208
  $removeCache = true;
 
 
 
 
 
 
 
209
  }
210
  }
211
- $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_NEW_LIST_TITLE, '', 'default', 0);
212
  }
213
 
214
  /**
215
  * Create new customers list
216
  */
217
- $customersNewListName = Mage::getStoreConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_NEW_LIST_TITLE);
218
- if ($customersNewListName) {
219
  if ($mailigenSchedule->countPendingOrRunningJobs() == 0) {
220
  $newListValue = $list->createNewList($customersNewListName);
221
  if ($newListValue) {
222
- $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_CONTACT_LIST, $newListValue, 'default', 0);
223
  $removeCache = true;
224
 
225
  /**
@@ -230,15 +251,16 @@ class Mailigen_Synchronizer_Model_Observer
230
  $customer->setCustomersNotSynced();
231
  }
232
  }
233
- $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_NEW_LIST_TITLE, '', 'default', 0);
234
  }
235
 
236
  /**
237
  * Check if user selected the same contact lists for newsletter and customers
 
238
  */
239
- if ($helper->getNewsletterContactList() == $helper->getCustomersContactList() && $helper->getNewsletterContactList() != '') {
240
  Mage::getSingleton('adminhtml/session')->addError("Please select different contact lists for newsletter and customers");
241
- $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_CONTACT_LIST, '', 'default', 0);
242
  $removeCache = true;
243
  }
244
 
@@ -271,9 +293,13 @@ class Mailigen_Synchronizer_Model_Observer
271
  */
272
  public function customerDeleteAfter(Varien_Event_Observer $observer)
273
  {
274
- $customer = $observer->getDataObject();
275
- if ($customer && $customer->getId()) {
276
- Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId(), 1);
 
 
 
 
277
  }
278
  }
279
 
@@ -282,70 +308,79 @@ class Mailigen_Synchronizer_Model_Observer
282
  */
283
  public function customerSaveAfter(Varien_Event_Observer $observer)
284
  {
285
- $customer = $observer->getDataObject();
286
- if ($customer && $customer->getId()) {
287
- Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
288
-
289
- /** @var $helper Mailigen_Synchronizer_Helper_Data */
290
- $helper = Mage::helper('mailigen_synchronizer');
291
- $newsletterListId = $helper->getNewsletterContactList();
292
-
293
- /**
294
- * Check if Customer Firstname, Lastname or Email was changed
295
- */
296
- if ($customer->getIsSubscribed() && $customer->hasDataChanges() && $helper->isEnabled() && !empty($newsletterListId)) {
297
- $origCustomerData = $customer->getOrigData();
298
 
299
- $nameChanged = ((isset($origCustomerData['firstname']) && $origCustomerData['firstname'] != $customer->getFirstname())
300
- || (isset($origCustomerData['lastname']) && $origCustomerData['lastname'] != $customer->getLastname()));
301
- $emailChanged = (isset($origCustomerData['email']) && !empty($origCustomerData['email']) && $origCustomerData['email'] != $customer->getEmail());
302
 
303
  /**
304
- * Set subscriber not synced, if customer Firstname, Lastname changed
305
  */
306
- if ($nameChanged && !$emailChanged) {
307
- $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
308
- if ($subscriber->getId()) {
309
- Mage::getModel('mailigen_synchronizer/newsletter')->updateIsSynced($subscriber->getId(), false);
 
 
 
 
 
 
 
 
 
 
 
310
  }
311
- }
312
 
313
- /**
314
- * Unsubscribe with old email
315
- */
316
- if ($emailChanged) {
317
- $oldEmail = $origCustomerData['email'];
318
- $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($oldEmail);
319
-
320
- if ($subscriber->getId()) {
321
- /** @var $logger Mailigen_Synchronizer_Helper_Log */
322
- $logger = Mage::helper('mailigen_synchronizer/log');
323
- $api = $helper->getMailigenApi();
324
-
325
- /**
326
- * Remove subscriber
327
- */
328
- $send_goodbye = $helper->canNewsletterHandleDefaultEmails();
329
- $retval = $api->listUnsubscribe($newsletterListId, $oldEmail, true, $send_goodbye, true);
330
- $logger->log('Remove subscriber with email: ' . $oldEmail);
331
-
332
- if (!$retval) {
333
- $logger->log("Unable to remove subscriber with email: $oldEmail. $api->errorCode: $api->errorMessage");
 
334
  }
335
  }
336
  }
337
  }
 
 
338
  }
339
  }
 
340
  /**
341
  * @param Varien_Event_Observer $observer
342
  */
343
  public function customerAddressSaveAfter(Varien_Event_Observer $observer)
344
  {
345
- $customerAddress = $observer->getDataObject();
346
- $customer = $customerAddress->getCustomer();
347
- if ($customer && $customer->getId()) {
348
- Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
 
 
 
 
349
  }
350
  }
351
 
@@ -354,9 +389,13 @@ class Mailigen_Synchronizer_Model_Observer
354
  */
355
  public function customerLogin(Varien_Event_Observer $observer)
356
  {
357
- $customer = $observer->getCustomer();
358
- if ($customer && $customer->getId()) {
359
- Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
 
 
 
 
360
  }
361
  }
362
 
@@ -365,9 +404,13 @@ class Mailigen_Synchronizer_Model_Observer
365
  */
366
  public function salesOrderSaveAfter(Varien_Event_Observer $observer)
367
  {
368
- $order = $observer->getOrder();
369
- if ($order && $order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE && $order->getCustomerId()) {
370
- Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($order->getCustomerId());
 
 
 
 
371
  }
372
  }
373
  }
28
  $logger = Mage::helper('mailigen_synchronizer/log');
29
  $subscriber = $observer->getDataObject();
30
 
31
+ try {
32
+ if ($subscriber && $helper->isEnabled($subscriber->getStoreId())
33
+ && ($subscriber->getIsStatusChanged() == true || $subscriber->getOrigData('subscriber_status') != $subscriber->getData('subscriber_status'))
34
+ ) {
35
+ $storeId = $subscriber->getStoreId();
36
+ $api = $helper->getMailigenApi($storeId);
37
+ $newsletterListId = $helper->getNewsletterContactList($storeId);
38
+ if (!$newsletterListId) {
39
+ $logger->log('Newsletter contact list isn\'t selected');
40
+ return;
41
+ }
42
+ $email_address = $subscriber->getSubscriberEmail();
 
 
 
 
43
 
 
44
  /**
45
+ * Create or update Merge fields
46
  */
47
+ Mage::getModel('mailigen_synchronizer/newsletter_merge_field')->createMergeFields($storeId);
48
+ $logger->log('Newsletter merge fields created and updated');
49
+
50
+ if ($subscriber->getSubscriberStatus() === Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
51
+ /**
52
+ * Subscribe newsletter
53
+ */
54
+ /** @var $customerHelper Mailigen_Synchronizer_Helper_Customer */
55
+ $customerHelper = Mage::helper('mailigen_synchronizer/customer');
56
+
57
+ // Prepare Merge vars
58
+ $website = $customerHelper->getWebsite($storeId);
59
+ $merge_vars = array(
60
+ 'EMAIL' => $subscriber->getSubscriberEmail(),
61
+ 'WEBSITEID' => $website ? $website->getId() : 0,
62
+ 'TYPE' => $customerHelper->getSubscriberType(1),
63
+ 'STOREID' => $storeId,
64
+ 'STORELANGUAGE' => $customerHelper->getStoreLanguage($storeId),
65
+ );
66
+
67
+ // If is a customer we also grab firstname and lastname
68
+ if ($subscriber->getCustomerId()) {
69
+ $customer = Mage::getModel('customer/customer')->load($subscriber->getCustomerId());
70
+ $merge_vars['FNAME'] = $customer->getFirstname();
71
+ $merge_vars['LNAME'] = $customer->getLastname();
72
+ $merge_vars['TYPE'] = $customerHelper->getSubscriberType(2);
73
+ }
74
 
75
+ $send_welcome = $helper->canNewsletterHandleDefaultEmails($storeId);
76
 
77
+ $retval = $api->listSubscribe($newsletterListId, $email_address, $merge_vars, 'html', false, true, $send_welcome);
78
+ $logger->log('Subscribed newsletter with email: ' . $email_address);
79
+ } elseif ($subscriber->getSubscriberStatus() === Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) {
80
+ /**
81
+ * Unsubscribe newsletter
82
+ */
83
+ $send_goodbye = $helper->canNewsletterHandleDefaultEmails($storeId);
84
+ $retval = $api->listUnsubscribe($newsletterListId, $email_address, false, $send_goodbye, true);
85
+ $logger->log('Unsubscribed newsletter with email: ' . $email_address);
86
+ } else {
87
+ // @todo Check Not Activated or Removed status?
88
+ $retval = null;
89
+ }
 
90
 
91
+ if ($retval) {
92
+ // Set subscriber synced
93
+ Mage::getModel('mailigen_synchronizer/newsletter')->updateIsSynced($subscriber->getId(), true);
94
 
95
+ // Set customer not synced
96
+ if ($subscriber->getCustomerId()) {
97
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($subscriber->getCustomerId());
98
+ }
99
+ } elseif (!is_null($retval)) {
100
+ $logger->log("Unable to (un)subscribe newsletter with email: $email_address. $api->errorCode: $api->errorMessage");
101
  }
 
 
102
  }
103
+ } catch (Exception $e) {
104
+ $logger->logException($e);
105
  }
106
  }
107
 
116
  $logger = Mage::helper('mailigen_synchronizer/log');
117
  $subscriber = $observer->getDataObject();
118
 
119
+ try {
120
+ if ($subscriber && $helper->isEnabled($subscriber->getStoreId())) {
121
+ $storeId = $subscriber->getStoreId();
122
+ $api = $helper->getMailigenApi($storeId);
123
+ $newsletterListId = $helper->getNewsletterContactList($storeId);
124
+ if (!$newsletterListId) {
125
+ $logger->log('Newsletter contact list isn\'t selected');
126
+ return;
127
+ }
128
+ $email_address = $subscriber->getSubscriberEmail();
129
+
130
+ /**
131
+ * Remove subscriber
132
+ */
133
+ $send_goodbye = $helper->canNewsletterHandleDefaultEmails($storeId);
134
+ $retval = $api->listUnsubscribe($newsletterListId, $email_address, true, $send_goodbye, true);
135
+ $logger->log('Remove subscriber with email: ' . $email_address);
136
+
137
+ if ($retval) {
138
+ // Set customer not synced
139
+ if ($subscriber->getCustomerId()) {
140
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($subscriber->getCustomerId());
141
+ }
142
+ } elseif (!is_null($retval)) {
143
+ $logger->log("Unable to remove subscriber with email: $email_address. $api->errorCode: $api->errorMessage");
144
  }
 
 
145
  }
146
+ } catch (Exception $e) {
147
+ $logger->logException($e);
148
  }
149
  }
150
 
203
  $helper = Mage::helper('mailigen_synchronizer');
204
  /** @var $mailigenSchedule Mailigen_Synchronizer_Model_Schedule */
205
  $mailigenSchedule = Mage::getModel('mailigen_synchronizer/schedule');
206
+ /** @var $configData Mage_Adminhtml_Model_Config_Data */
207
+ $configData = Mage::getSingleton('adminhtml/config_data');
208
+ $scope = $configData->getScope();
209
+ $scopeId = $configData->getScopeId();
210
+ $storeId = Mage::app()->getWebsite($scopeId)->getDefaultGroup()->getDefaultStore()->getId();
211
  $removeCache = false;
212
 
213
  /**
214
  * Create new newsletter list
215
  */
216
+ $newsletterNewListName = Mage::getStoreConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_NEW_LIST_TITLE, $storeId);
217
+ if (is_string($newsletterNewListName) && strlen($newsletterNewListName) > 0) {
218
  if ($mailigenSchedule->countPendingOrRunningJobs() == 0) {
219
  $newListValue = $list->createNewList($newsletterNewListName);
220
  if ($newListValue) {
221
+ $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_CONTACT_LIST, $newListValue, $scope, $scopeId);
222
  $removeCache = true;
223
+
224
+ /**
225
+ * Set newsletter not synced on contact list change
226
+ */
227
+ /** @var $newsletter Mailigen_Synchronizer_Model_Newsletter */
228
+ $newsletter = Mage::getModel('mailigen_synchronizer/newsletter');
229
+ $newsletter->setNewsletterNotSynced();
230
  }
231
  }
232
+ $config->deleteConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_NEWSLETTER_NEW_LIST_TITLE, $scope, $scopeId);
233
  }
234
 
235
  /**
236
  * Create new customers list
237
  */
238
+ $customersNewListName = Mage::getStoreConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_NEW_LIST_TITLE, $storeId);
239
+ if (is_string($customersNewListName) && strlen($customersNewListName) > 0) {
240
  if ($mailigenSchedule->countPendingOrRunningJobs() == 0) {
241
  $newListValue = $list->createNewList($customersNewListName);
242
  if ($newListValue) {
243
+ $config->saveConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_CONTACT_LIST, $newListValue, $scope, $scopeId);
244
  $removeCache = true;
245
 
246
  /**
251
  $customer->setCustomersNotSynced();
252
  }
253
  }
254
+ $config->deleteConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_NEW_LIST_TITLE, $scope, $scopeId);
255
  }
256
 
257
  /**
258
  * Check if user selected the same contact lists for newsletter and customers
259
+ * @todo Check contact lists per each scope
260
  */
261
+ if ($helper->getNewsletterContactList($storeId) == $helper->getCustomersContactList($storeId) && $helper->getNewsletterContactList($storeId) != '') {
262
  Mage::getSingleton('adminhtml/session')->addError("Please select different contact lists for newsletter and customers");
263
+ $config->deleteConfig(Mailigen_Synchronizer_Helper_Data::XML_PATH_CUSTOMERS_CONTACT_LIST, $scope, $scopeId);
264
  $removeCache = true;
265
  }
266
 
293
  */
294
  public function customerDeleteAfter(Varien_Event_Observer $observer)
295
  {
296
+ try {
297
+ $customer = $observer->getDataObject();
298
+ if ($customer && $customer->getId()) {
299
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId(), 1);
300
+ }
301
+ } catch (Exception $e) {
302
+ Mage::helper('mailigen_synchronizer/log')->logException($e);
303
  }
304
  }
305
 
308
  */
309
  public function customerSaveAfter(Varien_Event_Observer $observer)
310
  {
311
+ try {
312
+ $customer = $observer->getDataObject();
313
+ if ($customer && $customer->getId()) {
314
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
 
 
 
 
 
 
 
 
 
315
 
316
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
317
+ $helper = Mage::helper('mailigen_synchronizer');
318
+ $newsletterListId = $helper->getNewsletterContactList();
319
 
320
  /**
321
+ * Check if Customer Firstname, Lastname or Email was changed
322
  */
323
+ if ($customer->getIsSubscribed() && $customer->hasDataChanges() && $helper->isEnabled() && !empty($newsletterListId)) {
324
+ $origCustomerData = $customer->getOrigData();
325
+
326
+ $nameChanged = ((isset($origCustomerData['firstname']) && $origCustomerData['firstname'] != $customer->getFirstname())
327
+ || (isset($origCustomerData['lastname']) && $origCustomerData['lastname'] != $customer->getLastname()));
328
+ $emailChanged = (isset($origCustomerData['email']) && !empty($origCustomerData['email']) && $origCustomerData['email'] != $customer->getEmail());
329
+
330
+ /**
331
+ * Set subscriber not synced, if customer Firstname, Lastname changed
332
+ */
333
+ if ($nameChanged && !$emailChanged) {
334
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
335
+ if ($subscriber->getId()) {
336
+ Mage::getModel('mailigen_synchronizer/newsletter')->updateIsSynced($subscriber->getId(), false);
337
+ }
338
  }
 
339
 
340
+ /**
341
+ * Unsubscribe customer with old email
342
+ */
343
+ if ($emailChanged) {
344
+ $oldEmail = $origCustomerData['email'];
345
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($oldEmail);
346
+
347
+ if ($subscriber->getId()) {
348
+ /** @var $logger Mailigen_Synchronizer_Helper_Log */
349
+ $logger = Mage::helper('mailigen_synchronizer/log');
350
+ $api = $helper->getMailigenApi();
351
+
352
+ /**
353
+ * Remove subscriber
354
+ */
355
+ $send_goodbye = $helper->canNewsletterHandleDefaultEmails();
356
+ $retval = $api->listUnsubscribe($newsletterListId, $oldEmail, true, $send_goodbye, true);
357
+ $logger->log('Remove subscriber with email: ' . $oldEmail);
358
+
359
+ if (!$retval) {
360
+ $logger->log("Unable to remove subscriber with email: $oldEmail. $api->errorCode: $api->errorMessage");
361
+ }
362
  }
363
  }
364
  }
365
  }
366
+ } catch (Exception $e) {
367
+ Mage::helper('mailigen_synchronizer/log')->logException($e);
368
  }
369
  }
370
+
371
  /**
372
  * @param Varien_Event_Observer $observer
373
  */
374
  public function customerAddressSaveAfter(Varien_Event_Observer $observer)
375
  {
376
+ try {
377
+ $customerAddress = $observer->getDataObject();
378
+ $customer = $customerAddress->getCustomer();
379
+ if ($customer && $customer->getId()) {
380
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
381
+ }
382
+ } catch (Exception $e) {
383
+ Mage::helper('mailigen_synchronizer/log')->logException($e);
384
  }
385
  }
386
 
389
  */
390
  public function customerLogin(Varien_Event_Observer $observer)
391
  {
392
+ try {
393
+ $customer = $observer->getCustomer();
394
+ if ($customer && $customer->getId()) {
395
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($customer->getId());
396
+ }
397
+ } catch (Exception $e) {
398
+ Mage::helper('mailigen_synchronizer/log')->logException($e);
399
  }
400
  }
401
 
404
  */
405
  public function salesOrderSaveAfter(Varien_Event_Observer $observer)
406
  {
407
+ try {
408
+ $order = $observer->getOrder();
409
+ if ($order && $order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE && $order->getCustomerId()) {
410
+ Mage::getModel('mailigen_synchronizer/customer')->setCustomerNotSynced($order->getCustomerId());
411
+ }
412
+ } catch (Exception $e) {
413
+ Mage::helper('mailigen_synchronizer/log')->logException($e);
414
  }
415
  }
416
  }
app/code/community/Mailigen/Synchronizer/Model/Resource/Customer/Collection.php CHANGED
@@ -19,9 +19,10 @@ class Mailigen_Synchronizer_Model_Resource_Customer_Collection extends Mage_Core
19
  *
20
  * @param bool $is_synced
21
  * @param bool $is_removed
 
22
  * @return array
23
  */
24
- public function getAllIds($is_synced = false, $is_removed = false)
25
  {
26
  $idsSelect = clone $this->getSelect();
27
  $idsSelect->reset(Zend_Db_Select::ORDER);
@@ -35,6 +36,9 @@ class Mailigen_Synchronizer_Model_Resource_Customer_Collection extends Mage_Core
35
  if (is_int($is_removed)) {
36
  $idsSelect->where('is_removed = ?', $is_removed);
37
  }
 
 
 
38
 
39
  $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table');
40
  return $this->getConnection()->fetchCol($idsSelect);
19
  *
20
  * @param bool $is_synced
21
  * @param bool $is_removed
22
+ * @param int $website_id
23
  * @return array
24
  */
25
+ public function getAllIds($is_synced = false, $is_removed = false, $website_id = null)
26
  {
27
  $idsSelect = clone $this->getSelect();
28
  $idsSelect->reset(Zend_Db_Select::ORDER);
36
  if (is_int($is_removed)) {
37
  $idsSelect->where('is_removed = ?', $is_removed);
38
  }
39
+ if (!is_null($website_id)) {
40
+ $idsSelect->where('website_id = ?', $website_id);
41
+ }
42
 
43
  $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table');
44
  return $this->getConnection()->fetchCol($idsSelect);
app/code/community/Mailigen/Synchronizer/Model/Resource/Iterator/Batched.php CHANGED
@@ -11,6 +11,16 @@ class Mailigen_Synchronizer_Model_Resource_Iterator_Batched extends Varien_Objec
11
  {
12
  const DEFAULT_BATCH_SIZE = 250;
13
 
 
 
 
 
 
 
 
 
 
 
14
  /**
15
  * @param $collection
16
  * @param array $callbackForIndividual
@@ -21,16 +31,21 @@ class Mailigen_Synchronizer_Model_Resource_Iterator_Batched extends Varien_Objec
21
  */
22
  public function walk($collection, array $callbackForIndividual, array $callbackAfterBatch, $batchSize = null, $batchLimit = null)
23
  {
24
- if (!$batchSize) {
25
- $batchSize = self::DEFAULT_BATCH_SIZE;
26
  }
27
 
28
- $collection->setPageSize($batchSize);
 
 
29
 
30
  $currentPage = 1;
31
- $pages = $collection->getLastPageNumber();
 
 
32
 
33
  do {
 
34
  $collection->setCurPage($currentPage);
35
  $collection->load();
36
 
@@ -39,18 +54,51 @@ class Mailigen_Synchronizer_Model_Resource_Iterator_Batched extends Varien_Objec
39
  }
40
 
41
  if (!empty($callbackAfterBatch)) {
42
- $collectionInfo = array('currentPage' => $currentPage, 'pages' => $pages, 'pageSize' => $batchSize);
43
  call_user_func($callbackAfterBatch, $collectionInfo);
44
  }
45
 
46
- if (is_int($batchLimit) && $currentPage * $batchSize >= $batchLimit) {
47
- return 0;
 
 
 
48
  }
49
 
50
- $currentPage++;
51
- $collection->clear();
52
  } while ($currentPage <= $pages);
53
 
54
  return 1;
55
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
11
  {
12
  const DEFAULT_BATCH_SIZE = 250;
13
 
14
+ /**
15
+ * @var null
16
+ */
17
+ protected $_collectionCount = null;
18
+
19
+ /**
20
+ * @var int
21
+ */
22
+ protected $_batchSize = self::DEFAULT_BATCH_SIZE;
23
+
24
  /**
25
  * @param $collection
26
  * @param array $callbackForIndividual
31
  */
32
  public function walk($collection, array $callbackForIndividual, array $callbackAfterBatch, $batchSize = null, $batchLimit = null)
33
  {
34
+ if (!is_null($batchSize)) {
35
+ $this->_batchSize = $batchSize;
36
  }
37
 
38
+ $this->_collectionCount = $collection->getSelectCountSql();
39
+
40
+ $collection->setPageSize($this->_batchSize);
41
 
42
  $currentPage = 1;
43
+ $origCurrentPage = 1;
44
+ $pages = $this->_getPagesSize();
45
+ $origPages = $collection->getLastPageNumber();
46
 
47
  do {
48
+ $collection->clear();
49
  $collection->setCurPage($currentPage);
50
  $collection->load();
51
 
54
  }
55
 
56
  if (!empty($callbackAfterBatch)) {
57
+ $collectionInfo = array('currentPage' => $origCurrentPage, 'pages' => $origPages, 'pageSize' => $this->_batchSize);
58
  call_user_func($callbackAfterBatch, $collectionInfo);
59
  }
60
 
61
+ if (is_int($batchLimit)) {
62
+ $batchLimit -= $this->_batchSize;
63
+ if ($batchLimit <= 0) {
64
+ return 0;
65
+ }
66
  }
67
 
68
+ $origCurrentPage++;
69
+ $this->_recalcPages($currentPage, $pages);
70
  } while ($currentPage <= $pages);
71
 
72
  return 1;
73
  }
74
+
75
+ /**
76
+ * @return float
77
+ */
78
+ protected function _getPagesSize()
79
+ {
80
+ $count = $this->_collectionCount->query()->fetchColumn();
81
+ return ceil($count/$this->_batchSize);
82
+ }
83
+
84
+ /**
85
+ * @param $currentPage
86
+ * @param $pages
87
+ */
88
+ protected function _recalcPages(&$currentPage, &$pages)
89
+ {
90
+ $_pages = $this->_getPagesSize();
91
+ $pagesDiff = $_pages - $pages;
92
+ if ($pagesDiff < 0) {
93
+ $pages = $_pages;
94
+ $currentPage += $pagesDiff;
95
+ }
96
+ elseif ($pagesDiff >= 0) {
97
+ $currentPage++;
98
+ }
99
+
100
+ if ($currentPage <= 0) {
101
+ $currentPage = 1;
102
+ }
103
+ }
104
  }
app/code/community/Mailigen/Synchronizer/Model/Resource/Subscriber/Collection.php CHANGED
@@ -10,7 +10,13 @@
10
  class Mailigen_Synchronizer_Model_Resource_Subscriber_Collection extends Mage_Newsletter_Model_Resource_Subscriber_Collection
11
  {
12
 
13
- public function getSubscribers($status = null, $synced = 0)
 
 
 
 
 
 
14
  {
15
  $collection = $this->showCustomerInfo(true)
16
  ->addSubscriberTypeField()
@@ -21,6 +27,10 @@ class Mailigen_Synchronizer_Model_Resource_Subscriber_Collection extends Mage_Ne
21
  $collection->addFieldToFilter('subscriber_status', $status);
22
  }
23
 
 
 
 
 
24
  return $collection;
25
  }
26
  }
10
  class Mailigen_Synchronizer_Model_Resource_Subscriber_Collection extends Mage_Newsletter_Model_Resource_Subscriber_Collection
11
  {
12
 
13
+ /**
14
+ * @param null $status
15
+ * @param int $synced
16
+ * @param null $storeId
17
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
18
+ */
19
+ public function getSubscribers($status = null, $synced = 0, $storeId = null)
20
  {
21
  $collection = $this->showCustomerInfo(true)
22
  ->addSubscriberTypeField()
27
  $collection->addFieldToFilter('subscriber_status', $status);
28
  }
29
 
30
+ if (!is_null($storeId)) {
31
+ $collection->addFieldToFilter('store_id', $storeId);
32
+ }
33
+
34
  return $collection;
35
  }
36
  }
app/code/community/Mailigen/Synchronizer/Model/System/Config/Backend/Newsletter/List.php CHANGED
@@ -23,12 +23,21 @@ class Mailigen_Synchronizer_Model_System_Config_Backend_Newsletter_List extends
23
  $oldValue = $helper->getNewsletterContactList();
24
  $newValue = $this->getValue();
25
 
26
- /**
27
- * Deny config modification, until synchronization will not be finished
28
- */
29
- if ($oldValue != $newValue && $mailigenSchedule->countPendingOrRunningJobs() > 0) {
30
- $this->_dataSaveAllowed = false;
31
- Mage::getSingleton('adminhtml/session')->addNotice($helper->__("You can't change newsletter list until synchronization will not be finished."));
 
 
 
 
 
 
 
 
 
32
  }
33
  }
34
  }
23
  $oldValue = $helper->getNewsletterContactList();
24
  $newValue = $this->getValue();
25
 
26
+ if ($oldValue != $newValue) {
27
+ /**
28
+ * Deny config modification, until synchronization will not be finished
29
+ */
30
+ if ($mailigenSchedule->countPendingOrRunningJobs() > 0) {
31
+ $this->_dataSaveAllowed = false;
32
+ Mage::getSingleton('adminhtml/session')->addNotice($helper->__("You can't change newsletter list until synchronization will not be finished."));
33
+ } else {
34
+ /**
35
+ * Set newsletter not synced on contact list change
36
+ */
37
+ /** @var $newsletter Mailigen_Synchronizer_Model_Newsletter */
38
+ $newsletter = Mage::getModel('mailigen_synchronizer/newsletter');
39
+ $newsletter->setNewsletterNotSynced();
40
+ }
41
  }
42
  }
43
  }
app/code/community/Mailigen/Synchronizer/controllers/Adminhtml/MailigenController.php CHANGED
@@ -88,4 +88,18 @@ class Mailigen_Synchronizer_Adminhtml_MailigenController extends Mage_Adminhtml_
88
 
89
  $this->getResponse()->setBody('1');
90
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
88
 
89
  $this->getResponse()->setBody('1');
90
  }
91
+
92
+ /**
93
+ * Generate new webhooks secret key
94
+ */
95
+ public function generateSecretKeyAction()
96
+ {
97
+ $storeId = $this->getRequest()->getParam('storeId');
98
+
99
+ /** @var $helper Mailigen_Synchronizer_Helper_Data */
100
+ $helper = Mage::helper('mailigen_synchronizer');
101
+ $secretKey = $helper->generateWebhooksSecretKey($storeId);
102
+
103
+ $this->getResponse()->setBody($secretKey);
104
+ }
105
  }
app/code/community/Mailigen/Synchronizer/controllers/WebhookController.php CHANGED
@@ -32,15 +32,22 @@ class Mailigen_Synchronizer_WebhookController extends Mage_Core_Controller_Front
32
  }
33
 
34
  if (!$this->getRequest()->isPost()) {
35
- $this->logger->logWebhook("It's not POST request.");
 
36
  return '';
37
  }
38
 
39
- $this->logger->logWebhook("Webhook called with data: " . $this->getRequest()->getRawBody());
 
 
 
 
 
 
 
40
 
41
  try {
42
- $json = $this->getRequest()->getRawBody();
43
- $json = json_decode($json);
44
 
45
  if (!isset($json->hook) || !isset($json->data)) {
46
  $this->logger->logWebhook('No hook or data in JSON.');
@@ -63,7 +70,7 @@ class Mailigen_Synchronizer_WebhookController extends Mage_Core_Controller_Front
63
  $this->_unsubscribeContact($json->data);
64
  break;
65
  default:
66
- $this->logger->logWebhook('Incorrect JSON');
67
  }
68
  } catch (Exception $e) {
69
  $this->_returnError('Exception: ' . $e->getMessage());
32
  }
33
 
34
  if (!$this->getRequest()->isPost()) {
35
+ $requestMethod = $this->getRequest()->getMethod();
36
+ $this->logger->logWebhook("Request should be a 'POST' method, instead of '{$requestMethod}'.");
37
  return '';
38
  }
39
 
40
+ $data = $this->getRequest()->getRawBody();
41
+ $signature = $this->getRequest()->getHeader('X-Mailigen-Signature');
42
+ if (!$helper->verifySignature($data, $signature)) {
43
+ $this->logger->logWebhook("Data signature is incorrect.");
44
+ return '';
45
+ }
46
+
47
+ $this->logger->logWebhook("Webhook called with data: " . $data);
48
 
49
  try {
50
+ $json = json_decode($data);
 
51
 
52
  if (!isset($json->hook) || !isset($json->data)) {
53
  $this->logger->logWebhook('No hook or data in JSON.');
70
  $this->_unsubscribeContact($json->data);
71
  break;
72
  default:
73
+ $this->logger->logWebhook("Hook '{$json->hook}' is not supported");
74
  }
75
  } catch (Exception $e) {
76
  $this->_returnError('Exception: ' . $e->getMessage());
app/code/community/Mailigen/Synchronizer/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Mailigen_Synchronizer>
5
- <version>1.2.0</version>
6
  </Mailigen_Synchronizer>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Mailigen_Synchronizer>
5
+ <version>1.2.6</version>
6
  </Mailigen_Synchronizer>
7
  </modules>
8
  <global>
app/code/community/Mailigen/Synchronizer/etc/system.xml CHANGED
@@ -107,6 +107,28 @@
107
  <show_in_store>0</show_in_store>
108
  <comment><![CDATA[If set to yes, then each time the list on Mailigen changes an update will be sent to Magento store.<br/><b>Warning:</b> You should configure Webhooks in Mailigen account to get it working! Read more details in <a href="http://www.mailigen.com/assets/files/pdf/MailigenSynchronizer-MagentoModul-UserGuide-v1.pdf">documentation</a>.]]></comment>
109
  </webhooks>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  </fields>
111
  </newsletter>
112
  <customers translate="label" module="mailigen_synchronizer">
107
  <show_in_store>0</show_in_store>
108
  <comment><![CDATA[If set to yes, then each time the list on Mailigen changes an update will be sent to Magento store.<br/><b>Warning:</b> You should configure Webhooks in Mailigen account to get it working! Read more details in <a href="http://www.mailigen.com/assets/files/pdf/MailigenSynchronizer-MagentoModul-UserGuide-v1.pdf">documentation</a>.]]></comment>
109
  </webhooks>
110
+ <webhooks_url translate="label">
111
+ <label>Mailigen Webhooks URL</label>
112
+ <frontend_model>mailigen_synchronizer/adminhtml_newsletter_webhooks</frontend_model>
113
+ <sort_order>60</sort_order>
114
+ <show_in_default>1</show_in_default>
115
+ <show_in_website>1</show_in_website>
116
+ <show_in_store>0</show_in_store>
117
+ <depends>
118
+ <webhooks></webhooks>
119
+ </depends>
120
+ </webhooks_url>
121
+ <webhooks_secret_key translate="label">
122
+ <label>Mailigen Webhooks Secret Key</label>
123
+ <frontend_model>mailigen_synchronizer/adminhtml_newsletter_secretkey</frontend_model>
124
+ <sort_order>70</sort_order>
125
+ <show_in_default>1</show_in_default>
126
+ <show_in_website>1</show_in_website>
127
+ <show_in_store>0</show_in_store>
128
+ <depends>
129
+ <webhooks></webhooks>
130
+ </depends>
131
+ </webhooks_secret_key>
132
  </fields>
133
  </newsletter>
134
  <customers translate="label" module="mailigen_synchronizer">
app/code/community/Mailigen/Synchronizer/sql/mailigen_synchronizer_setup/mysql4-upgrade-1.2.1-1.2.2.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mailigen_Synchronizer
4
+ *
5
+ * @category Mailigen
6
+ * @package Mailigen_Synchronizer
7
+ * @author Maksim Soldatjonok <maksold@gmail.com>
8
+ */
9
+ /* @var $installer Mage_Core_Model_Resource_Setup */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ /**
14
+ * Add 'website_id' column to 'mailigen_synchronizer/customer' table
15
+ */
16
+ $installer->run("
17
+ ALTER TABLE {$installer->getTable('mailigen_synchronizer/customer')}
18
+ ADD `website_id` SMALLINT(5) UNSIGNED NOT NULL AFTER `email`;
19
+ ");
20
+
21
+ $installer->endSetup();
lib/mailigen/MGAPI.class.php CHANGED
@@ -29,22 +29,26 @@ class MGAPI {
29
  * Izmantot ssl: false - ne, true - ja
30
  */
31
  var $secure = false;
32
-
33
  /**
34
  * Pieslegties pie MailiGen API
35
- *
36
  * @param string $apikey Jusu MailiGen API atslega
37
- * @param string $secure Izmantot vai neizmantot ssl pieslegšanos
 
38
  */
39
- function MGAPI($apikey, $secure = false) {
40
- $this->secure = $secure;
41
- $this->apiUrl = parse_url("http://api.mailigen.com/" . $this->version . "/?output=php");
42
- if ( isset($GLOBALS["mg_api_key"]) && $GLOBALS["mg_api_key"]!="" ){
43
- $this->api_key = $GLOBALS["mg_api_key"];
44
- } else {
45
- $this->api_key = $GLOBALS["mg_api_key"] = $apikey;
46
- }
47
- }
 
 
 
48
  function setTimeout($seconds){
49
  if (is_int($seconds)){
50
  $this->timeout = $seconds;
29
  * Izmantot ssl: false - ne, true - ja
30
  */
31
  var $secure = false;
32
+
33
  /**
34
  * Pieslegties pie MailiGen API
35
+ *
36
  * @param string $apikey Jusu MailiGen API atslega
37
+ * @param bool $secure Izmantot vai neizmantot ssl pieslegšanos
38
+ * @param bool $force_apikey_update Izmantot jaunu MailiGen API atslegu
39
  */
40
+ function MGAPI($apikey, $secure = false, $force_apikey_update = false)
41
+ {
42
+ $this->secure = $secure;
43
+ $this->apiUrl = parse_url("http://api.mailigen.com/" . $this->version . "/?output=php");
44
+ if ($force_apikey_update) {
45
+ $this->api_key = $GLOBALS["mg_api_key"] = $apikey;
46
+ } elseif (isset($GLOBALS["mg_api_key"]) && $GLOBALS["mg_api_key"] != "") {
47
+ $this->api_key = $GLOBALS["mg_api_key"];
48
+ } else {
49
+ $this->api_key = $GLOBALS["mg_api_key"] = $apikey;
50
+ }
51
+ }
52
  function setTimeout($seconds){
53
  if (is_int($seconds)){
54
  $this->timeout = $seconds;
package.xml CHANGED
@@ -1,30 +1,31 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mailigen_Synchronizer</name>
4
- <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Two-way sync for Magneto newsletter subscribers and one-way sync for Magnento customers</summary>
10
- <description>This extension enables a two-way synchronization between your Magento email newsletter subscriber list and your Mailigen email list, and one-way synchronization between your Magento customer list and your Mailigen email list. It is easy and quick to install and configure, no complex actions or knowledge of programming needed.&amp;#xD;&#xD;
11
- &amp;#xD;&#xD;
12
- Feature-rich synchronization&amp;#xD;&#xD;
13
- &amp;#xD;&#xD;
14
- - Automatic synchronization between your Magento email subscriber list and one of your Mailigen email lists. When users subscribe to the newsletter in Magento, they will be added to the selected Mailigen contact list.&amp;#xD;&#xD;
15
- - Two-way synchronization when it comes to subscriber status change. When users unsubscribe from your Magento list, they will be removed also from your Mailigen list. And vice versa, users will be removed from your Magento list when unsubscribed from your Mailigen list.&amp;#xD;&#xD;
16
- - Automatic synchronization between your Magento customer list and one of your Mailigen email lists. When customer registers in Magento, they will be added to the selected Mailigen contact list.&amp;#xD;&#xD;
17
- - One-way Magento customers synchronization. All customer information (customer address, last login date, items in cart, orders information) from Magento store will be synced with selected Mailigen contact list.&amp;#xD;&#xD;
18
- &amp;#xD;&#xD;
19
- For more detailed information, instructions and usage of this extension, please visit Mailigen Integrations page or contact our support team.&amp;#xD;&#xD;
20
- &amp;#xD;&#xD;
21
- Mailigen provides email and integrated marketing services covering full email automation. See a full integration list in Mailigen Integrations page.</description>
22
- <notes>- Updated Newsletter synchronisation&#xD;
23
- - Added webhooks subscibe/unsubscribe for Newsletter</notes>
 
24
  <authors><author><name>Thomas Nelson</name><user>mailigen</user><email>info@mailigen.com</email></author></authors>
25
- <date>2015-07-19</date>
26
- <time>09:21:59</time>
27
- <contents><target name="magecommunity"><dir name="Mailigen"><dir name="Synchronizer"><dir name="Block"><dir name="Adminhtml"><dir name="Sync"><file name="Information.php" hash="8a56f97404bad86c899294bffe6832af"/></dir></dir><dir name="Newsletter"><dir name="Subscriber"><file name="Grid.php" hash="1a975840b9f1704644cb8228468ad743"/></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="bab800ba2dfd87241f23710115eea670"/><file name="Data.php" hash="2b60a16ebc85f6a6c5ce62452ac2b658"/><file name="Log.php" hash="7cff7048604c0f75be38cbd42e9dc8e3"/></dir><file name="Mailigen_webhooks_setup_instruction.jpg" hash="27dcb35d607a919b2f3e95e2fdb96757"/><dir name="Model"><dir name="Customer"><dir name="Merge"><file name="Field.php" hash="68314df0847063e4053ffb505087b7ea"/></dir></dir><file name="Customer.php" hash="50b7d9768124f3bd9f6da86067a49494"/><file name="List.php" hash="329edb291f38861b7f2b1a79e01a4896"/><file name="Mailigen.php" hash="9db057af2ac82a84a4650db60c457e49"/><dir name="Newsletter"><dir name="Merge"><file name="Field.php" hash="b15e805b125d1d7f779730ff78232997"/></dir><file name="Subscriber.php" hash="0be821ef351f8c9ed9811c1b0054b3a2"/></dir><file name="Newsletter.php" hash="864672a8ce7686376a35eab5979f3c0b"/><file name="Observer.php" hash="ad87b3c9697df755bafefdc044ec0cb2"/><dir name="Resource"><dir name="Customer"><file name="Collection.php" hash="350fd71cb6db7688a932530256856533"/></dir><file name="Customer.php" hash="bb95830ef5e95b4a361a858d081ff4f8"/><dir name="Iterator"><file name="Batched.php" hash="d2b0ec0268773422de00cb6766083753"/></dir><dir name="Subscriber"><file name="Collection.php" hash="8b7b1f361d0257b2bcae0b8a227517f9"/></dir></dir><file name="Schedule.php" hash="6486dc9375bae5555c0e0a9c7a156be5"/><dir name="System"><dir name="Config"><dir name="Backend"><dir name="Customer"><file name="List.php" hash="5370ca37cb8d4f0a268e3ef2e9f4c673"/></dir><dir name="Newsletter"><file name="List.php" hash="05f2ce9cb0954a35cc87f7899164beaa"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="MailigenController.php" hash="5592488f4433d70aa4ceecd1c05f2318"/></dir><file name="WebhookController.php" hash="bca6a15371aea1565ff433b1d523b1e9"/></dir><dir name="data"><dir name="mailigen_synchronizer_setup"><file name="data-install-1.1.0.php" hash="30f1fdb649862fcbbd943aeb7ce65c7f"/></dir></dir><dir name="etc"><file name="config.xml" hash="a33226d20ba64be4b91ee7e1d837a55b"/><file name="system.xml" hash="93d02040f081ad1d8547733ab4e06a17"/></dir><dir name="sql"><dir name="mailigen_synchronizer_setup"><file name="install-1.1.0.php" hash="57ee87c647fca4c728f9ee988be84231"/><file name="mysql4-upgrade-1.1.4-1.2.0.php" hash="569d2880f0b52cda79bb78b632b14690"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mailigen_Synchronizer.xml" hash="4c1560ac5f7042f57bfcf13a0e49bc00"/></dir></target><target name="magelib"><dir name="mailigen"><file name="MGAPI.class.php" hash="16b7712206e95bf61c2cf6f92ef71583"/></dir></target></contents>
28
  <compatible/>
29
  <dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php></required></dependencies>
30
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mailigen_Synchronizer</name>
4
+ <version>1.2.6</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Two-way sync for Magneto newsletter subscribers and one-way sync for Magnento customers</summary>
10
+ <description>This extension enables a two-way synchronization between your Magento email newsletter subscriber list and your Mailigen email list, and one-way synchronization between your Magento customer list and your Mailigen email list. It is easy and quick to install and configure, no complex actions or knowledge of programming needed.&#xD;
11
+ &#xD;
12
+ Feature-rich synchronization&#xD;
13
+ &#xD;
14
+ - Automatic synchronization between your Magento email subscriber list and one of your Mailigen email lists. When users subscribe to the newsletter in Magento, they will be added to the selected Mailigen contact list.&#xD;
15
+ - Two-way synchronization when it comes to subscriber status change. When users unsubscribe from your Magento list, they will be removed also from your Mailigen list. And vice versa, users will be removed from your Magento list when unsubscribed from your Mailigen list.&#xD;
16
+ - Automatic synchronization between your Magento customer list and one of your Mailigen email lists. When customer registers in Magento, they will be added to the selected Mailigen contact list.&#xD;
17
+ - One-way Magento customers synchronization. All customer information (customer address, last login date, items in cart, orders information) from Magento store will be synced with selected Mailigen contact list.&#xD;
18
+ &#xD;
19
+ For more detailed information, instructions and usage of this extension, please visit Mailigen Integrations page or contact our support team.&#xD;
20
+ &#xD;
21
+ Mailigen provides email and integrated marketing services covering full email automation. See a full integration list in Mailigen Integrations page.</description>
22
+ <notes>- Added ability to sync customers and newsletter per website&#xD;
23
+ - Added Webhooks Secret Key to verifying request, sent from Maligen&#xD;
24
+ - Bugfixes</notes>
25
  <authors><author><name>Thomas Nelson</name><user>mailigen</user><email>info@mailigen.com</email></author></authors>
26
+ <date>2016-02-08</date>
27
+ <time>08:20:12</time>
28
+ <contents><target name="magecommunity"><dir name="Mailigen"><dir name="Synchronizer"><dir name="Block"><dir name="Adminhtml"><dir name="Newsletter"><file name="Secretkey.php" hash="d7bd712b8851c592f5f2261046e051db"/><file name="Webhooks.php" hash="d6abad73f516741131b4be64dc487cb7"/></dir><dir name="Sync"><file name="Information.php" hash="8a56f97404bad86c899294bffe6832af"/></dir></dir><dir name="Newsletter"><dir name="Subscriber"><file name="Grid.php" hash="1a975840b9f1704644cb8228468ad743"/></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="bab800ba2dfd87241f23710115eea670"/><file name="Data.php" hash="69c905b568ea180ae89900f9dba84eb8"/><file name="Log.php" hash="7cff7048604c0f75be38cbd42e9dc8e3"/></dir><dir name="Model"><dir name="Customer"><dir name="Merge"><file name="Field.php" hash="68314df0847063e4053ffb505087b7ea"/></dir></dir><file name="Customer.php" hash="ec42dca799c44eea31006186cb66bb17"/><file name="List.php" hash="87d1a6520a69eb73d1d14b056511e7c1"/><file name="Mailigen.php" hash="4ecf27af57d9ef83c2233c9e7118a8b1"/><dir name="Newsletter"><dir name="Merge"><file name="Field.php" hash="55e42de3620d9e171f7933038c56800c"/></dir><file name="Subscriber.php" hash="0be821ef351f8c9ed9811c1b0054b3a2"/></dir><file name="Newsletter.php" hash="864672a8ce7686376a35eab5979f3c0b"/><file name="Observer.php" hash="c6f0c0f779a3e8ce21d24a232e0776b4"/><dir name="Resource"><dir name="Customer"><file name="Collection.php" hash="6007eee7490f2a70f13142ea7b1c58ad"/></dir><file name="Customer.php" hash="bb95830ef5e95b4a361a858d081ff4f8"/><dir name="Iterator"><file name="Batched.php" hash="0ee09a467db4ea633b2742d278217fa6"/></dir><dir name="Subscriber"><file name="Collection.php" hash="89339714c27c422957097e2f6f88023a"/></dir></dir><file name="Schedule.php" hash="6486dc9375bae5555c0e0a9c7a156be5"/><dir name="System"><dir name="Config"><dir name="Backend"><dir name="Customer"><file name="List.php" hash="5370ca37cb8d4f0a268e3ef2e9f4c673"/></dir><dir name="Newsletter"><file name="List.php" hash="eed1702b0b39ca66069a6514537892c9"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="MailigenController.php" hash="64f131ec5cfa94268681c17806e3c6ca"/></dir><file name="WebhookController.php" hash="214283e3f1db6e93cead345f3394b264"/></dir><dir name="data"><dir name="mailigen_synchronizer_setup"><file name="data-install-1.1.0.php" hash="30f1fdb649862fcbbd943aeb7ce65c7f"/></dir></dir><dir name="etc"><file name="config.xml" hash="20c49601beda062f74988f6901979cf2"/><file name="system.xml" hash="78f7385b1230243fda3d41eadca1db9a"/></dir><dir name="sql"><dir name="mailigen_synchronizer_setup"><file name="install-1.1.0.php" hash="57ee87c647fca4c728f9ee988be84231"/><file name="mysql4-upgrade-1.1.4-1.2.0.php" hash="569d2880f0b52cda79bb78b632b14690"/><file name="mysql4-upgrade-1.2.1-1.2.2.php" hash="66e7074f4d0381cf552f8f732dfab7ba"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mailigen_Synchronizer.xml" hash="4c1560ac5f7042f57bfcf13a0e49bc00"/></dir></target><target name="magelib"><dir name="mailigen"><file name="MGAPI.class.php" hash="53a59df05f337b920ef5ba4d52ecdfde"/></dir></target><target name="mageskin"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="mailigen_synchronizer"><file name="Mailigen_webhooks_setup_instruction.jpg" hash="27dcb35d607a919b2f3e95e2fdb96757"/></dir></dir></dir></dir></dir></target></contents>
29
  <compatible/>
30
  <dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php></required></dependencies>
31
  </package>
{app/code/community/Mailigen/Synchronizer → skin/adminhtml/default/default/mailigen_synchronizer}/Mailigen_webhooks_setup_instruction.jpg RENAMED
File without changes