Mage_Laposta_Connect - Version 1.0.3

Version Notes

- Additional logging
- Updated subscribe mechanism
- Fix for updates from Laposta not being stored correctly

Download this release

Release Info

Developer Merten van Gerven
Extension Mage_Laposta_Connect
Version 1.0.3
Comparing to
See all releases


Code changes from version 1.0.2 to 1.0.3

app/code/community/Laposta/Connect/Helper/Customer.php CHANGED
@@ -45,7 +45,11 @@ class Laposta_Connect_Helper_Customer extends Mage_Core_Helper_Abstract
45
  /**
46
  * @var array
47
  */
48
- protected $methodMapSet = array();
 
 
 
 
49
 
50
  /**
51
  * @var array
@@ -155,7 +159,7 @@ class Laposta_Connect_Helper_Customer extends Mage_Core_Helper_Abstract
155
  }
156
 
157
  if (!isset($this->methodMapSet[$name])) {
158
- return $this;
159
  }
160
 
161
  $method = $this->methodMapSet[$name];
@@ -261,6 +265,31 @@ class Laposta_Connect_Helper_Customer extends Mage_Core_Helper_Abstract
261
  return $gender;
262
  }
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  /**
265
  * Get the date of the customers last order
266
  *
@@ -296,6 +325,22 @@ class Laposta_Connect_Helper_Customer extends Mage_Core_Helper_Abstract
296
  return $address->getData('telephone');
297
  }
298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  /**
300
  * Get the customer company name
301
  *
@@ -312,6 +357,22 @@ class Laposta_Connect_Helper_Customer extends Mage_Core_Helper_Abstract
312
  return $address->getData('company');
313
  }
314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  /**
316
  * Get the name that corresponds thte customer group id.
317
  *
45
  /**
46
  * @var array
47
  */
48
+ protected $methodMapSet = array(
49
+ 'gender' => 'setGender',
50
+ 'telephone' => 'setTelephone',
51
+ 'company' => 'setCompany',
52
+ );
53
 
54
  /**
55
  * @var array
159
  }
160
 
161
  if (!isset($this->methodMapSet[$name])) {
162
+ return $this->setCustomerAttribute($name, $value);
163
  }
164
 
165
  $method = $this->methodMapSet[$name];
265
  return $gender;
266
  }
267
 
268
+ /**
269
+ * Set the textual customer gender
270
+ *
271
+ * @return string
272
+ */
273
+ protected function setGender($value)
274
+ {
275
+ $options = $this->getCustomer()->getAttribute('gender')->getSource()->getAllOptions(false);
276
+ $genderId = '';
277
+
278
+ foreach ($options as $option) {
279
+ if ($option['label'] != $value) {
280
+ continue;
281
+ }
282
+
283
+ $genderId = $option['value'];
284
+
285
+ break;
286
+ }
287
+
288
+ $this->setCustomerAttribute('gender', $genderId);
289
+
290
+ return $this;
291
+ }
292
+
293
  /**
294
  * Get the date of the customers last order
295
  *
325
  return $address->getData('telephone');
326
  }
327
 
328
+ /**
329
+ * Set the customer telephone number
330
+ *
331
+ * @return string
332
+ */
333
+ protected function setTelephone($value)
334
+ {
335
+ $address = $this->getCustomer()->getPrimaryBillingAddress();
336
+
337
+ if (!$address instanceof Mage_Customer_Model_Address) {
338
+ return '';
339
+ }
340
+
341
+ return $address->setData('telephone', $value);
342
+ }
343
+
344
  /**
345
  * Get the customer company name
346
  *
357
  return $address->getData('company');
358
  }
359
 
360
+ /**
361
+ * Set the customer company name
362
+ *
363
+ * @return string
364
+ */
365
+ protected function setCompany($value)
366
+ {
367
+ $address = $this->getCustomer()->getPrimaryBillingAddress();
368
+
369
+ if (!$address instanceof Mage_Customer_Model_Address) {
370
+ return '';
371
+ }
372
+
373
+ return $address->setData('company', $value);
374
+ }
375
+
376
  /**
377
  * Get the name that corresponds thte customer group id.
378
  *
app/code/community/Laposta/Connect/Helper/Laposta.php CHANGED
@@ -86,9 +86,12 @@ class Laposta_Connect_Helper_Laposta extends Mage_Core_Helper_Abstract
86
  'state' => $subscribed ? 'active' : 'unsubscribed',
87
  'custom_fields' => $this->denormalizeFields($listId, $fields),
88
  );
 
 
 
89
  $result = $member->create($data);
90
 
91
- $this->log(__METHOD__, $result);
92
 
93
  return $result['member']['member_id'];
94
  }
86
  'state' => $subscribed ? 'active' : 'unsubscribed',
87
  'custom_fields' => $this->denormalizeFields($listId, $fields),
88
  );
89
+
90
+ $this->log(__METHOD__ . ' Sending: ', $data);
91
+
92
  $result = $member->create($data);
93
 
94
+ $this->log(__METHOD__ . ' Received: ', $result);
95
 
96
  return $result['member']['member_id'];
97
  }
app/code/community/Laposta/Connect/controllers/WebhookController.php CHANGED
@@ -105,8 +105,6 @@ class Laposta_Connect_WebhookController extends Mage_Core_Controller_Front_Actio
105
  */
106
  protected function log($message, $data = null)
107
  {
108
- var_dump($message, $data);
109
-
110
  Mage::helper('lapostaconnect')->log(
111
  array(
112
  'message' => $message,
@@ -158,24 +156,41 @@ class Laposta_Connect_WebhookController extends Mage_Core_Controller_Front_Actio
158
  return $this->log("Customer for subscriber with laposta id '$memberId' not found.");
159
  }
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  /** @var $newsletterSubscriberModel Mage_Newsletter_Model_Subscriber */
162
  $newsletterSubscriberModel = Mage::getModel('newsletter/subscriber');
163
  /** @var $newsletterSubscriber Mage_Newsletter_Model_Subscriber */
164
  $newsletterSubscriber = $newsletterSubscriberModel->loadByCustomer($customer);
165
-
166
- var_dump($newsletterSubscriber);
 
167
 
168
  if ($status !== 'active') {
 
169
  $newsletterSubscriber->unsubscribe();
170
 
171
- return $this->log("Customer '{$customer->getEmail()}' for subscriber with laposta id '$memberId' has been unsubscribed.");
172
-
173
- return $this;
174
  }
 
 
 
175
 
176
- $newsletterSubscriber->subscribe($customer->getEmail());
 
177
 
178
- return $this->log("Customer '{$customer->getEmail()}' for subscriber with laposta id '$memberId' has been subscribed.");
179
 
180
  return $this;
181
  }
105
  */
106
  protected function log($message, $data = null)
107
  {
 
 
108
  Mage::helper('lapostaconnect')->log(
109
  array(
110
  'message' => $message,
156
  return $this->log("Customer for subscriber with laposta id '$memberId' not found.");
157
  }
158
 
159
+ /** @var $fieldsHelper Laposta_Connect_Helper_Fields */
160
+ $fieldsHelper = Mage::helper('lapostaconnect/Fields');
161
+ $fields = $fieldsHelper->getByListId($subscriber->getListId());
162
+
163
+ /** @var $customerHelper Laposta_Connect_Helper_Customer */
164
+ $customerHelper = Mage::helper('lapostaconnect/customer');
165
+
166
+ $customerHelper->setCustomer($customer);
167
+ $customerHelper->email = $event['data']['email'];
168
+ foreach ($fields as $fieldName => $lapostaTag) {
169
+ $customerHelper->$fieldName = $event['data']['custom_fields'][$lapostaTag];
170
+ }
171
+
172
  /** @var $newsletterSubscriberModel Mage_Newsletter_Model_Subscriber */
173
  $newsletterSubscriberModel = Mage::getModel('newsletter/subscriber');
174
  /** @var $newsletterSubscriber Mage_Newsletter_Model_Subscriber */
175
  $newsletterSubscriber = $newsletterSubscriberModel->loadByCustomer($customer);
176
+ $newsletterSubscriber->setCustomerId($subscriber->getData('customer_id'));
177
+ $newsletterSubscriber->setEmail($customer->getEmail());
178
+ $newsletterSubscriber->setStoreId($customer->getStore()->getId());
179
 
180
  if ($status !== 'active') {
181
+ $customer->setIsSubscribed(false);
182
  $newsletterSubscriber->unsubscribe();
183
 
184
+ $this->log("Customer '{$customer->getEmail()}' for subscriber with laposta id '$memberId' has been unsubscribed.");
 
 
185
  }
186
+ else {
187
+ $customer->setIsSubscribed(true);
188
+ $newsletterSubscriber->subscribeCustomer($customer);
189
 
190
+ $this->log("Customer '{$customer->getEmail()}' for subscriber with laposta id '$memberId' has been subscribed.");
191
+ }
192
 
193
+ $customer->save();
194
 
195
  return $this;
196
  }
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mage_Laposta_Connect</name>
4
- <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -24,13 +24,14 @@
24
  &#xD;
25
  &lt;h2&gt;Questions&lt;/h2&gt;&#xD;
26
  &lt;p&gt;Please see the FAQ section for questions.&lt;/p&gt;</description>
27
- <notes>- Filter updated subscribers with updates since last sync time&#xD;
28
- - Fixed erroneous Laposta webhook handler&#xD;
 
29
  </notes>
30
  <authors><author><name>Merten van Gerven</name><user>mertenvg</user><email>merten@codeblanche.com</email></author></authors>
31
- <date>2014-05-13</date>
32
- <time>11:43:09</time>
33
- <contents><target name="magecommunity"><dir name="Laposta"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Mapfields.php" hash="2c88b8a08121c09ba5748f631205a282"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="8a54f573c56f8ce9e248506bb9514561"/><file name="Data.php" hash="8f9e28d0f28f9375385432d227ec1d06"/><file name="Fields.php" hash="51bc0aa26167219b038c04b3babb19af"/><file name="Laposta.php" hash="9085c0c80dcd314d402bfc960b8f861e"/><file name="Subscribe.php" hash="f58bc248ee3b4d229b58de8b4efbccf3"/><file name="Sync.php" hash="ad94bd49cf666fb99fa043bef1ba8bcf"/></dir><dir name="Model"><file name="Cron.php" hash="270a2289a1de1bc678dfc4e6264c095b"/><file name="Field.php" hash="42e1857bdb7d90b31be189e2921ac8fd"/><file name="List.php" hash="99f590a5e5ea3b1a14869c641f49eaed"/><dir name="Mysql4"><dir name="Field"><file name="Collection.php" hash="f8133202231937b1ec14d8cdc39903fe"/></dir><file name="Field.php" hash="c49743d6acd1d4ce2b69aadf22838839"/><dir name="List"><file name="Collection.php" hash="fcc556452fff91bb3e9f933c68fff630"/></dir><file name="List.php" hash="6fef1b36f5d3a5560f83bafe205be614"/><dir name="Subscriber"><file name="Collection.php" hash="05db928eb656f132e4fa16ac740ce3c5"/></dir><file name="Subscriber.php" hash="9f73d39e97d4a19f8d8ad3c19f83a699"/></dir><file name="Observer.php" hash="1f22b2201a11543b725bc76f133b803d"/><file name="Subscriber.php" hash="cba5176e53a7dcab9b9014190f13485d"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="LapostaController.php" hash="cc2a0d62caf63469258042e3b29616e4"/></dir><file name="IndexController.php" hash="7577e30abee9624d59901edb5cecd3e9"/><file name="SubscribeAllController.php" hash="160ac8e5229bb1003d7220116a9b06f7"/><file name="WebhookController.php" hash="f31bcf69d894e4dd8562f6f5a8f3ddf0"/></dir><dir name="etc"><file name="adminhtml.xml" hash="71f985837d4b79e3db94c529bfee1e47"/><file name="config.xml" hash="325b71820df2ffd4b265810cb7c680f6"/><file name="system.xml" hash="6ee7d5de56541573f16a2caf94dc0418"/></dir><dir name="sql"><dir name="connect_setup"><file name="mysql4-install-0.1.0.php" hash="96c1911d06392a5e9496829411102479"/></dir></dir></dir></dir></target><target name="magelocal"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="lapostaconnect.xml" hash=""/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Laposta_Connect.xml" hash="ab7675e19ea96d39c5980bee835f0e76"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Laposta_Connect.csv" hash="4f8f28790602cdd01633c0bb00f70585"/></dir></target></contents>
34
  <compatible/>
35
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
36
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mage_Laposta_Connect</name>
4
+ <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
24
  &#xD;
25
  &lt;h2&gt;Questions&lt;/h2&gt;&#xD;
26
  &lt;p&gt;Please see the FAQ section for questions.&lt;/p&gt;</description>
27
+ <notes>- Additional logging&#xD;
28
+ - Updated subscribe mechanism&#xD;
29
+ - Fix for updates from Laposta not being stored correctly&#xD;
30
  </notes>
31
  <authors><author><name>Merten van Gerven</name><user>mertenvg</user><email>merten@codeblanche.com</email></author></authors>
32
+ <date>2014-05-16</date>
33
+ <time>14:00:23</time>
34
+ <contents><target name="magecommunity"><dir name="Laposta"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Mapfields.php" hash="2c88b8a08121c09ba5748f631205a282"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="ef0a5dff85fd77de92a0fefe06fddc60"/><file name="Data.php" hash="8f9e28d0f28f9375385432d227ec1d06"/><file name="Fields.php" hash="51bc0aa26167219b038c04b3babb19af"/><file name="Laposta.php" hash="6d7c3f204a79f7f01727e8fa80d66b10"/><file name="Subscribe.php" hash="f58bc248ee3b4d229b58de8b4efbccf3"/><file name="Sync.php" hash="ad94bd49cf666fb99fa043bef1ba8bcf"/></dir><dir name="Model"><file name="Cron.php" hash="270a2289a1de1bc678dfc4e6264c095b"/><file name="Field.php" hash="42e1857bdb7d90b31be189e2921ac8fd"/><file name="List.php" hash="99f590a5e5ea3b1a14869c641f49eaed"/><dir name="Mysql4"><dir name="Field"><file name="Collection.php" hash="f8133202231937b1ec14d8cdc39903fe"/></dir><file name="Field.php" hash="c49743d6acd1d4ce2b69aadf22838839"/><dir name="List"><file name="Collection.php" hash="fcc556452fff91bb3e9f933c68fff630"/></dir><file name="List.php" hash="6fef1b36f5d3a5560f83bafe205be614"/><dir name="Subscriber"><file name="Collection.php" hash="05db928eb656f132e4fa16ac740ce3c5"/></dir><file name="Subscriber.php" hash="9f73d39e97d4a19f8d8ad3c19f83a699"/></dir><file name="Observer.php" hash="1f22b2201a11543b725bc76f133b803d"/><file name="Subscriber.php" hash="cba5176e53a7dcab9b9014190f13485d"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="LapostaController.php" hash="cc2a0d62caf63469258042e3b29616e4"/></dir><file name="IndexController.php" hash="7577e30abee9624d59901edb5cecd3e9"/><file name="SubscribeAllController.php" hash="160ac8e5229bb1003d7220116a9b06f7"/><file name="WebhookController.php" hash="0526b02b319fc31cd8c8a3e9789ba358"/></dir><dir name="etc"><file name="adminhtml.xml" hash="71f985837d4b79e3db94c529bfee1e47"/><file name="config.xml" hash="325b71820df2ffd4b265810cb7c680f6"/><file name="system.xml" hash="6ee7d5de56541573f16a2caf94dc0418"/></dir><dir name="sql"><dir name="connect_setup"><file name="mysql4-install-0.1.0.php" hash="96c1911d06392a5e9496829411102479"/></dir></dir></dir></dir></target><target name="magelocal"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="lapostaconnect.xml" hash=""/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Laposta_Connect.xml" hash="ab7675e19ea96d39c5980bee835f0e76"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Laposta_Connect.csv" hash="4f8f28790602cdd01633c0bb00f70585"/></dir></target></contents>
35
  <compatible/>
36
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
37
  </package>