Pure360 - Version 1.1.3

Version Notes

1.1.3
- Added support for SUPEE-6788
- Remove LF and CR characters from lists csv rows;
- Fix bug Abandoned carts are triggered only 1 time for each customer in magento 1.9;
- Fix JavaScript problems so that the checkbox for subscribe displays also in magento 1.9 rwd theme;
- Changed text encoding for emails to UTF-8 when necessary so that sending one2one always works with pure360;

1.1.2
- Allow Response API to be accessed via HTTPS
- Also allow HTTP API access

1.1.1
- Opt out removal syncronisation fix

1.1.0
- Username/password check when changing API URL
- Increased the page refresh time in Cron job page
- Newsletter signup checkbox should not be checked by default if the use has already opted-out

1.0.4
- List opt-out support extended

1.0.3
- Stability fixes
- Verbose error handling
- List Sync fixes

1.0.2
- Dropdown values synced properly
- Boolean Yes/No synced
- Data consistency
- UI tweaks
- Admin routing updated

1.0.1
- Magento Connect compliance

Download this release

Release Info

Developer Stewart Waller
Extension Pure360
Version 1.1.3
Comparing to
See all releases


Code changes from version 1.0.2 to 1.1.3

Files changed (59) hide show
  1. app/code/community/Pure360/Cart/Helper/Data.php +1 -1
  2. app/code/community/Pure360/Cart/Job/Trigger.php +19 -21
  3. app/code/community/Pure360/Cart/controllers/AjaxController.php +1 -1
  4. app/code/community/Pure360/Cart/etc/config.xml +10 -10
  5. app/code/community/Pure360/Cart/sql/pure360_cart_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} +0 -0
  6. app/code/community/Pure360/Cart/sql/pure360_cart_setup/mysql4-upgrade-1.1.2-1.1.3.php +45 -0
  7. app/code/community/Pure360/Common/Helper/Api.php +21 -4
  8. app/code/community/Pure360/Common/Helper/Data.php +15 -4
  9. app/code/community/Pure360/Common/Helper/File.php +2 -1
  10. app/code/community/Pure360/Common/controllers/AjaxController.php +1 -1
  11. app/code/community/Pure360/Common/etc/config.xml +10 -10
  12. app/code/community/Pure360/Cron/Model/Observer.php +3 -0
  13. app/code/community/Pure360/Cron/controllers/AjaxController.php +1 -1
  14. app/code/community/Pure360/Cron/etc/config.xml +10 -10
  15. app/code/community/Pure360/Cron/sql/pure360_cron_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} +0 -0
  16. app/code/community/Pure360/Email/Model/Email/Message.php +45 -3
  17. app/code/community/Pure360/Email/etc/config.xml +10 -10
  18. app/code/community/Pure360/Email/sql/pure360_email_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} +0 -0
  19. app/code/community/Pure360/List/Helper/Api.php +4 -3
  20. app/code/community/Pure360/List/Helper/Data.php +23 -0
  21. app/code/community/Pure360/List/Job/Sync.php +213 -9
  22. app/code/community/Pure360/List/Model/Customer.php +5 -15
  23. app/code/community/Pure360/List/Model/Optout.php +17 -0
  24. app/code/community/Pure360/List/Model/Resource/Optout.php +28 -0
  25. app/code/community/Pure360/List/Model/Resource/Optout/Collection.php +56 -0
  26. app/code/community/Pure360/List/Model/Subscriber.php +55 -0
  27. app/code/community/Pure360/List/controllers/AjaxController.php +1 -1
  28. app/code/community/Pure360/List/etc/config.xml +18 -10
  29. app/code/community/Pure360/List/sql/pure360_list_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} +43 -15
  30. app/code/community/Pure360/List/sql/pure360_list_setup/mysql4-upgrade-1.0.3-1.0.4.php +30 -0
  31. app/code/community/Pure360/Newsletter/Block/Checkout/Onepage/Newsletter.php +13 -3
  32. app/code/community/Pure360/Newsletter/Helper/Api.php +40 -30
  33. app/code/community/Pure360/Newsletter/Model/Subscriber.php +48 -52
  34. app/code/community/Pure360/Newsletter/etc/config.xml +12 -12
  35. app/code/community/Pure360/Newsletter/sql/pure360_newsletter_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} +0 -0
  36. app/design/adminhtml/default/default/layout/pure360_cart.xml +8 -8
  37. app/design/adminhtml/default/default/layout/pure360_common.xml +8 -8
  38. app/design/adminhtml/default/default/layout/pure360_cron.xml +7 -7
  39. app/design/adminhtml/default/default/layout/pure360_email.xml +7 -7
  40. app/design/adminhtml/default/default/layout/pure360_list.xml +14 -14
  41. app/design/adminhtml/default/default/layout/pure360_newsletter.xml +7 -7
  42. app/design/adminhtml/default/default/template/pure360/common/about.phtml +8 -8
  43. app/design/adminhtml/default/default/template/pure360/common/disabled.phtml +10 -10
  44. app/design/adminhtml/default/default/template/pure360/common/error.phtml +10 -10
  45. app/design/adminhtml/default/default/template/pure360/common/jsinit.phtml +16 -16
  46. app/design/adminhtml/default/default/template/pure360/email/transactional.phtml +69 -69
  47. app/design/frontend/base/default/layout/pure360/cart.xml +10 -10
  48. app/design/frontend/base/default/layout/pure360/newsletter.xml +11 -11
  49. app/design/frontend/base/default/template/pure360/cart/email/order/items.phtml +85 -85
  50. app/design/frontend/base/default/template/pure360/cart/email/order/items/order/default.phtml +111 -111
  51. app/design/frontend/base/default/template/pure360/newsletter/jsinit.phtml +2 -2
  52. app/etc/modules/Pure360_Cart.xml +11 -11
  53. app/locale/en_US/template/email/pure360/abandoned_cart.html +37 -37
  54. app/locale/en_US/template/email/pure360/abandoned_cart_guest.html +37 -37
  55. js/mage/adminhtml/pure360/common.js +5 -1
  56. js/mage/adminhtml/pure360/cron.js +1 -1
  57. lib/Pure360/Client.php +34 -30
  58. lib/Pure360/Session.php +2 -1
  59. package.xml +40 -9
app/code/community/Pure360/Cart/Helper/Data.php CHANGED
@@ -29,7 +29,7 @@ class Pure360_Cart_Helper_Data extends Pure360_Common_Helper_Data
29
  $storeIds = Mage::helper('pure360_common')->getStoreIdsForScope($scope, $scopeId);
30
 
31
  $sql = "UPDATE $table
32
- SET pure360_trigger_count = -1
33
  WHERE is_active = 1
34
  AND store_id IN (". implode(",", $storeIds) .")";
35
 
29
  $storeIds = Mage::helper('pure360_common')->getStoreIdsForScope($scope, $scopeId);
30
 
31
  $sql = "UPDATE $table
32
+ SET pure360_trigger_id = -1
33
  WHERE is_active = 1
34
  AND store_id IN (". implode(",", $storeIds) .")";
35
 
app/code/community/Pure360/Cart/Job/Trigger.php CHANGED
@@ -36,9 +36,9 @@ class Pure360_Cart_Job_Trigger extends Pure360_Cron_Job_Abstract
36
  $this->max_cart_size = Mage::helper('pure360_common')->getScopedConfig('pure360_cart/' . $filter . 'settings/max_cart_size', $scope, $scopeId);
37
  $this->processed = array();
38
 
39
- for($i = 1; $i <= 3; $i++)
40
  {
41
- $triggerName = 'trigger' . ($i);
42
  $triggerEnabled = Mage::helper('pure360_common')->getScopedConfig('pure360_cart/' . $filter . $triggerName . '/enabled', $scope, $scopeId);
43
 
44
  if($triggerEnabled)
@@ -62,13 +62,14 @@ class Pure360_Cart_Job_Trigger extends Pure360_Cron_Job_Abstract
62
  }
63
  }
64
 
65
- $quotes = $this->getQuotesForTrigger($scope, $scopeId, $triggerDelay, $i);
66
 
67
  foreach($quotes as $quote)
68
  {
69
- // Increment trigger count
70
- $this->incrementTriggerCount($quote);
71
- $quote->setPure360TriggerCount($quote->getPure360TriggerCount()+1);
 
72
 
73
  // Store Id as processed
74
  $this->processed[] = $quote->getEntityId();
@@ -147,9 +148,6 @@ class Pure360_Cart_Job_Trigger extends Pure360_Cron_Job_Abstract
147
  $to = date('Y-m-d H:i:s', $lastTime);
148
  $collection->addFieldToFilter('updated_at', array('to' => $to));
149
 
150
- // Add triggerNumber filter
151
- $collection->addFieldToFilter('pure360_trigger_count', array('eq' => ($triggerNumber - 1)));
152
-
153
  // Add processed filter
154
  if(!empty($this->processed))
155
  {
@@ -157,29 +155,29 @@ class Pure360_Cart_Job_Trigger extends Pure360_Cron_Job_Abstract
157
  }
158
 
159
  // Add order and limit
160
- $collection->getSelect()->order('updated_at asc')->limit($this->max_cart_size);
 
 
161
 
162
  return $collection;
163
  }
164
 
165
  /**
166
- * Increments trigger count by one
167
  *
168
  * @param Mage_Sales_Model_Quote $quote
169
  */
170
- private function incrementTriggerCount($quote)
171
  {
172
- $resource = Mage::getSingleton('core/resource');
173
- $write = $resource->getConnection('core_write');
174
- $table = $resource->getTableName('sales/quote');
175
- $createdAt = $quote->getCreatedAt();
176
- $updatedAt = $quote->getUpdatedAt();
177
- $entityId = $quote->getEntityId();
178
 
179
  $sql = "UPDATE $table
180
- SET created_at = '$createdAt',
181
- updated_at = '$updatedAt',
182
- pure360_trigger_count = pure360_trigger_count+1
183
  WHERE entity_id = $entityId";
184
 
185
  $write->query($sql);
36
  $this->max_cart_size = Mage::helper('pure360_common')->getScopedConfig('pure360_cart/' . $filter . 'settings/max_cart_size', $scope, $scopeId);
37
  $this->processed = array();
38
 
39
+ for($triggerId = 1; $triggerId <= 3; $triggerId++)
40
  {
41
+ $triggerName = 'trigger' . ($triggerId);
42
  $triggerEnabled = Mage::helper('pure360_common')->getScopedConfig('pure360_cart/' . $filter . $triggerName . '/enabled', $scope, $scopeId);
43
 
44
  if($triggerEnabled)
62
  }
63
  }
64
 
65
+ $quotes = $this->getQuotesForTrigger($scope, $scopeId, $triggerDelay, $triggerId);
66
 
67
  foreach($quotes as $quote)
68
  {
69
+
70
+ $quote->setPure360TriggerId($triggerId);
71
+ // Update Trigger Id and date
72
+ $this->updateTriggerIdAndTriggerDate($quote);
73
 
74
  // Store Id as processed
75
  $this->processed[] = $quote->getEntityId();
148
  $to = date('Y-m-d H:i:s', $lastTime);
149
  $collection->addFieldToFilter('updated_at', array('to' => $to));
150
 
 
 
 
151
  // Add processed filter
152
  if(!empty($this->processed))
153
  {
155
  }
156
 
157
  // Add order and limit
158
+ $collection->getSelect()
159
+ ->where(new Zend_Db_Expr('pure360_trigger_id = '.($triggerNumber - 1).' OR updated_at > pure360_trigger_dt')) // Add triggerNumber filter
160
+ ->order('updated_at asc')->limit($this->max_cart_size);
161
 
162
  return $collection;
163
  }
164
 
165
  /**
166
+ * Update trigger id and trigger date
167
  *
168
  * @param Mage_Sales_Model_Quote $quote
169
  */
170
+ private function updateTriggerIdAndTriggerDate($quote)
171
  {
172
+ $resource = Mage::getSingleton('core/resource');
173
+ $write = $resource->getConnection('core_write');
174
+ $table = $resource->getTableName('sales/quote');
175
+ $entityId = $quote->getEntityId();
176
+ $triggerId = $quote->getPure360TriggerId();
 
177
 
178
  $sql = "UPDATE $table
179
+ SET pure360_trigger_id = $triggerId,
180
+ pure360_trigger_dt = NOW()
 
181
  WHERE entity_id = $entityId";
182
 
183
  $write->query($sql);
app/code/community/Pure360/Cart/controllers/AjaxController.php CHANGED
@@ -4,7 +4,7 @@
4
  * @package Pure360\Cart
5
  * @copyright 2013 Pure360.com
6
  */
7
- class Pure360_Cart_AjaxController extends Mage_Adminhtml_Controller_Action
8
  {
9
 
10
  /**
4
  * @package Pure360\Cart
5
  * @copyright 2013 Pure360.com
6
  */
7
+ class Pure360_Cart_AjaxController extends Mage_Core_Controller_Front_Action
8
  {
9
 
10
  /**
app/code/community/Pure360/Cart/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Pure360_Cart>
5
- <version>1.0.2</version>
6
  </Pure360_Cart>
7
  </modules>
8
  <global>
@@ -107,15 +107,15 @@
107
  </layout>
108
  </adminhtml>
109
  <admin>
110
- <routers>
111
- <pure360_cart>
112
- <use>admin</use>
113
- <args>
114
- <module>Pure360_Cart</module>
115
- <frontName>pure360_cart</frontName>
116
- </args>
117
- </pure360_cart>
118
- </routers>
119
  </admin>
120
  <default>
121
  <pure360_cart>
2
  <config>
3
  <modules>
4
  <Pure360_Cart>
5
+ <version>1.1.3</version>
6
  </Pure360_Cart>
7
  </modules>
8
  <global>
107
  </layout>
108
  </adminhtml>
109
  <admin>
110
+ <routers>
111
+ <adminhtml>
112
+ <args>
113
+ <modules>
114
+ <pure360_cart before="Mage_Adminhtml">Pure360_Cart_Adminhtml</pure360_cart>
115
+ </modules>
116
+ </args>
117
+ </adminhtml>
118
+ </routers>
119
  </admin>
120
  <default>
121
  <pure360_cart>
app/code/community/Pure360/Cart/sql/pure360_cart_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} RENAMED
File without changes
app/code/community/Pure360/Cart/sql/pure360_cart_setup/mysql4-upgrade-1.1.2-1.1.3.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ /* @var $installer Mage_Sales_Model_Mysql4_Setup */
5
+
6
+ $installer->startSetup();
7
+
8
+ try {
9
+ $installer->run("
10
+ ALTER TABLE {$installer->getTable('sales/quote')}
11
+ CHANGE pure360_trigger_count pure360_trigger_id INT(11);
12
+ ");
13
+ } catch (Exception $e) {
14
+ //
15
+ }
16
+
17
+ try {
18
+ $installer->run("
19
+ ALTER TABLE {$installer->getTable('sales/quote')}
20
+ DROP INDEX IDX_PURE360_CART_TRIG_CNT,
21
+ ADD INDEX IDX_PURE360_CART_TRIG_ID(pure360_trigger_id);
22
+ ");
23
+ } catch (Exception $e) {
24
+ //
25
+ }
26
+
27
+ try {
28
+ $installer->run("
29
+ ALTER TABLE {$installer->getTable('sales/quote')}
30
+ ADD COLUMN pure360_trigger_dt TIMESTAMP DEFAULT '0000-00-00 00:00:00';
31
+ ");
32
+ } catch (Exception $e) {
33
+ //
34
+ }
35
+
36
+ try {
37
+ $installer->run("
38
+ UPDATE {$installer->getTable('sales/quote')}
39
+ SET pure360_trigger_dt = NOW();
40
+ ");
41
+ } catch (Exception $e) {
42
+ //
43
+ }
44
+
45
+ $installer->endSetup();
app/code/community/Pure360/Common/Helper/Api.php CHANGED
@@ -82,15 +82,32 @@ class Pure360_Common_Helper_Api extends Mage_Core_Helper_Abstract
82
  }
83
 
84
  /**
85
- *
 
 
86
  * @param type $url
87
  * @return string
88
  */
89
  public function getWsdl($url)
90
  {
91
- $domain = str_replace("http://", "", $url);
92
- $paint_domain = str_replace("response", "paint", $domain);
93
- $wsdl = "http://" . $paint_domain . '/' . $paint_domain . '/ctrlPaintLiteral.wsdl';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  return $wsdl;
96
  }
82
  }
83
 
84
  /**
85
+ * Generate the WSDL url, replacing the response domain with paint if needed
86
+ *
87
+ *
88
  * @param type $url
89
  * @return string
90
  */
91
  public function getWsdl($url)
92
  {
93
+ $urlParts = parse_url($url);
94
+ $defaults = array(
95
+ 'host' => '',
96
+ 'scheme' => 'http',
97
+ 'wsdl' => 'ctrlPaintLiteral.wsdl'
98
+ );
99
+
100
+ if (array_key_exists('host', $urlParts))
101
+ {
102
+ $domainParts = explode('.', $urlParts['host']);
103
+ $paintDomain = preg_replace('/^response$/i', 'paint', $domainParts, 1);
104
+ $host = implode('.', $paintDomain);
105
+ $urlParts['host'] = $host;
106
+ }
107
+ // Add any defaults
108
+ $urlParts = array_merge($defaults, $urlParts);
109
+ // Create the path to the WSDL using the correct Scheme and Host
110
+ $wsdl = "${urlParts['scheme']}://${urlParts['host']}/${urlParts['host']}/${urlParts['wsdl']}";
111
 
112
  return $wsdl;
113
  }
app/code/community/Pure360/Common/Helper/Data.php CHANGED
@@ -410,12 +410,21 @@ class Pure360_Common_Helper_Data extends Mage_Core_Helper_Abstract
410
  * @param string|null $file
411
  * @return bool|void
412
  */
413
- public function writeError($message, $file = 'error')
414
  {
415
- if (is_object($message) && $message instanceOf Exception)
 
 
 
 
 
 
 
 
416
  {
417
- $message = $message->getMessage();
418
  }
 
419
  if ($this->isNoticesEnabled())
420
  {
421
  if (Mage::getSingleton('admin/session')->isLoggedIn())
@@ -423,12 +432,14 @@ class Pure360_Common_Helper_Data extends Mage_Core_Helper_Abstract
423
  /* @var $message Mage_Core_Model_Message_Error */
424
  $message = Mage::getSingleton('core/message')->error("[Pure360] {$message}");
425
  Mage::getSingleton('adminhtml/session')->addMessage($message);
 
426
  } else
427
  {
428
  Mage::getSingleton('core/session')->addError("[Pure360] {$message}");
429
  }
430
  }
431
- return $this->writeLog($message, $file, Zend_Log::ERR);
 
432
  }
433
 
434
  /**
410
  * @param string|null $file
411
  * @return bool|void
412
  */
413
+ public function writeError($error, $file = 'error')
414
  {
415
+ $message = '';
416
+ $backtrace = '';
417
+
418
+ if (is_object($error) && $error instanceOf Exception)
419
+ {
420
+ $message = $error->getMessage();
421
+ $backtrace = '\n' . $error->getTraceAsString();
422
+
423
+ } else
424
  {
425
+ $message = $error;
426
  }
427
+
428
  if ($this->isNoticesEnabled())
429
  {
430
  if (Mage::getSingleton('admin/session')->isLoggedIn())
432
  /* @var $message Mage_Core_Model_Message_Error */
433
  $message = Mage::getSingleton('core/message')->error("[Pure360] {$message}");
434
  Mage::getSingleton('adminhtml/session')->addMessage($message);
435
+
436
  } else
437
  {
438
  Mage::getSingleton('core/session')->addError("[Pure360] {$message}");
439
  }
440
  }
441
+
442
+ return $this->writeLog($message . $backtrace, $file, Zend_Log::ERR);
443
  }
444
 
445
  /**
app/code/community/Pure360/Common/Helper/File.php CHANGED
@@ -165,7 +165,8 @@ class Pure360_Common_Helper_File extends Mage_Core_Helper_Abstract
165
  */
166
  public function outputCSV($filepath, $csv)
167
  {
168
-
 
169
  // Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
170
  $handle = fopen($filepath, "a");
171
 
165
  */
166
  public function outputCSV($filepath, $csv)
167
  {
168
+ $csv = preg_replace(array("/\r/", "/\n/"), " ", $csv);
169
+
170
  // Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
171
  $handle = fopen($filepath, "a");
172
 
app/code/community/Pure360/Common/controllers/AjaxController.php CHANGED
@@ -4,7 +4,7 @@
4
  * @package Pure360\Common
5
  * @copyright 2013 Pure360.com
6
  */
7
- class Pure360_Common_AjaxController extends Mage_Adminhtml_Controller_Action
8
  {
9
 
10
  /**
4
  * @package Pure360\Common
5
  * @copyright 2013 Pure360.com
6
  */
7
+ class Pure360_Common_AjaxController extends Mage_Core_Controller_Front_Action
8
  {
9
 
10
  /**
app/code/community/Pure360/Common/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Pure360_Common>
5
- <version>1.0.2</version>
6
  </Pure360_Common>
7
  </modules>
8
  <global>
@@ -97,15 +97,15 @@
97
  </layout>
98
  </adminhtml>
99
  <admin>
100
- <routers>
101
- <pure360_common>
102
- <use>admin</use>
103
- <args>
104
- <module>Pure360_Common</module>
105
- <frontName>pure360</frontName>
106
- </args>
107
- </pure360_common>
108
- </routers>
109
  </admin>
110
  <default>
111
  <pure360>
2
  <config>
3
  <modules>
4
  <Pure360_Common>
5
+ <version>1.1.2</version>
6
  </Pure360_Common>
7
  </modules>
8
  <global>
97
  </layout>
98
  </adminhtml>
99
  <admin>
100
+ <routers>
101
+ <adminhtml>
102
+ <args>
103
+ <modules>
104
+ <pure360_common after="Mage_Adminhtml">Pure360_Common_Adminhtml</pure360_common>
105
+ </modules>
106
+ </args>
107
+ </adminhtml>
108
+ </routers>
109
  </admin>
110
  <default>
111
  <pure360>
app/code/community/Pure360/Cron/Model/Observer.php CHANGED
@@ -222,6 +222,7 @@ class Pure360_Cron_Model_Observer extends Mage_Core_Model_Abstract
222
  $job->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS);
223
  $job->setFinishedAt($finish);
224
  $job->save();
 
225
  } catch(Pure360_Exception_ValidationException $ve)
226
  {
227
  $errorMessage = $ve->getMessage() . ': ';
@@ -230,9 +231,11 @@ class Pure360_Cron_Model_Observer extends Mage_Core_Model_Abstract
230
  {
231
  $errorMessage .= $error . ' [' . $message . "]; \n";
232
  }
 
233
  } catch(Exception $e)
234
  {
235
  $errorMessage = $e->getMessage();
 
236
  }
237
 
238
  if(!is_null($errorMessage))
222
  $job->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS);
223
  $job->setFinishedAt($finish);
224
  $job->save();
225
+
226
  } catch(Pure360_Exception_ValidationException $ve)
227
  {
228
  $errorMessage = $ve->getMessage() . ': ';
231
  {
232
  $errorMessage .= $error . ' [' . $message . "]; \n";
233
  }
234
+
235
  } catch(Exception $e)
236
  {
237
  $errorMessage = $e->getMessage();
238
+ Mage::helper('pure360_common')->writeError($e);
239
  }
240
 
241
  if(!is_null($errorMessage))
app/code/community/Pure360/Cron/controllers/AjaxController.php CHANGED
@@ -4,7 +4,7 @@
4
  * @package Pure360\Cron
5
  * @copyright 2013 Pure360.com
6
  */
7
- class Pure360_Cron_AjaxController extends Mage_Adminhtml_Controller_Action
8
  {
9
 
10
  /**
4
  * @package Pure360\Cron
5
  * @copyright 2013 Pure360.com
6
  */
7
+ class Pure360_Cron_AjaxController extends Mage_Core_Controller_Front_Action
8
  {
9
 
10
  /**
app/code/community/Pure360/Cron/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Pure360_Cron>
5
- <version>1.0.2</version>
6
  </Pure360_Cron>
7
  </modules>
8
  <global>
@@ -102,15 +102,15 @@
102
  </layout>
103
  </adminhtml>
104
  <admin>
105
- <routers>
106
- <pure360_cron>
107
- <use>admin</use>
108
- <args>
109
- <module>Pure360_Cron</module>
110
- <frontName>pure360_cron</frontName>
111
- </args>
112
- </pure360_cron>
113
- </routers>
114
  </admin>
115
  <default>
116
  <pure360_cron>
2
  <config>
3
  <modules>
4
  <Pure360_Cron>
5
+ <version>1.1.2</version>
6
  </Pure360_Cron>
7
  </modules>
8
  <global>
102
  </layout>
103
  </adminhtml>
104
  <admin>
105
+ <routers>
106
+ <adminhtml>
107
+ <args>
108
+ <modules>
109
+ <pure360_cron after="Mage_Adminhtml">Pure360_Cron_Adminhtml</pure360_cron>
110
+ </modules>
111
+ </args>
112
+ </adminhtml>
113
+ </routers>
114
  </admin>
115
  <default>
116
  <pure360_cron>
app/code/community/Pure360/Cron/sql/pure360_cron_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} RENAMED
File without changes
app/code/community/Pure360/Email/Model/Email/Message.php CHANGED
@@ -135,7 +135,28 @@ class Pure360_Email_Model_Email_Message extends Mage_Core_Model_Email_Template
135
 
136
  $this->setUseAbsoluteLinks(true);
137
  $text = $this->getProcessedTemplate($variables, true);
138
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  try
140
  {
141
  // Create API Client for current context
@@ -145,11 +166,32 @@ class Pure360_Email_Model_Email_Message extends Mage_Core_Model_Email_Template
145
  $password = Mage::helper('pure360_common')->getModuleGroupKeyValue('pure360', 'settings_transactional', 'password', $storeId);
146
  $client = Mage::helper('pure360_common/api')->getClient($url, $username, $password);
147
 
148
- // Send using Pure360 One2One
149
  $messageSubject = $this->getProcessedTemplateSubject($variables);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  $messageName = $templateId;
151
  $messageBodyHtml = $this->isPlain() ? null : $text;
152
- $messageBodyPlain = $this->isPlain() ? $text : null;
153
  $toAddress = $variables['email'];
154
  $fromAddress = $this->getSenderEmail();
155
  $fromDesc = $this->getSenderName();
135
 
136
  $this->setUseAbsoluteLinks(true);
137
  $text = $this->getProcessedTemplate($variables, true);
138
+ $plainText = $text;
139
+
140
+ if(!$this->isPlain())
141
+ {
142
+
143
+ $searchPatterns = array(
144
+ '/<style.*>.*<\/style>/Usi',
145
+ '/<p.*>/Ui',
146
+ '/<\/p>/i',
147
+ '/<br.*\/?>/i',
148
+ '/<[^>]+>/Usi',
149
+ );
150
+ $replaceValues = array(
151
+ '',
152
+ "\r\n\r\n",
153
+ "\r\n",
154
+ "\r\n",
155
+ '',
156
+ );
157
+ $plainText = preg_replace($searchPatterns, $replaceValues, $plainText);
158
+ }
159
+
160
  try
161
  {
162
  // Create API Client for current context
166
  $password = Mage::helper('pure360_common')->getModuleGroupKeyValue('pure360', 'settings_transactional', 'password', $storeId);
167
  $client = Mage::helper('pure360_common/api')->getClient($url, $username, $password);
168
 
169
+ $context = $client->getcontext();
170
  $messageSubject = $this->getProcessedTemplateSubject($variables);
171
+
172
+ if (strpos($context["defaultLanguage"],'UTF-8') !== false )
173
+ {
174
+ // check if $text is already UTF-8 encoded
175
+ if (utf8_encode(utf8_decode($text)) !== $text){
176
+ $text = utf8_encode($text);
177
+ }
178
+
179
+ // check if $plainText is already UTF-8 encoded
180
+ if (utf8_encode(utf8_decode($plainText)) !== $plainText){
181
+ $plainText = utf8_encode($plainText);
182
+ }
183
+
184
+ // check if $messageSubject is already UTF-8 encoded
185
+ if (utf8_encode(utf8_decode($messageSubject)) !== $messageSubject){
186
+ $messageSubject = utf8_encode($messageSubject);
187
+ }
188
+ }
189
+
190
+ // Send using Pure360 One2One
191
+ // Todo: allow modification of the plain text message. Currently, only stripping the tags out of the HTML message.
192
  $messageName = $templateId;
193
  $messageBodyHtml = $this->isPlain() ? null : $text;
194
+ $messageBodyPlain = $this->isPlain() ? $text : $plainText;
195
  $toAddress = $variables['email'];
196
  $fromAddress = $this->getSenderEmail();
197
  $fromDesc = $this->getSenderName();
app/code/community/Pure360/Email/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Pure360_Email>
5
- <version>1.0.2</version>
6
  </Pure360_Email>
7
  </modules>
8
  <global>
@@ -96,15 +96,15 @@
96
  </layout>
97
  </adminhtml>
98
  <admin>
99
- <routers>
100
- <pure360_email>
101
- <use>admin</use>
102
- <args>
103
- <module>Pure360_Email</module>
104
- <frontName>pure360_email</frontName>
105
- </args>
106
- </pure360_email>
107
- </routers>
108
  </admin>
109
  <default>
110
  <pure360_email>
2
  <config>
3
  <modules>
4
  <Pure360_Email>
5
+ <version>1.1.2</version>
6
  </Pure360_Email>
7
  </modules>
8
  <global>
96
  </layout>
97
  </adminhtml>
98
  <admin>
99
+ <routers>
100
+ <adminhtml>
101
+ <args>
102
+ <modules>
103
+ <pure360_email after="Mage_Adminhtml">Pure360_Email_Adminhtml</pure360_email>
104
+ </modules>
105
+ </args>
106
+ </adminhtml>
107
+ </routers>
108
  </admin>
109
  <default>
110
  <pure360_email>
app/code/community/Pure360/Email/sql/pure360_email_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} RENAMED
File without changes
app/code/community/Pure360/List/Helper/Api.php CHANGED
@@ -189,7 +189,8 @@ class Pure360_List_Helper_Api extends Pure360_Common_Helper_Api
189
  {
190
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
191
 
192
- $listData = array();
 
193
 
194
  // Search to see if a lists already exists with this name
195
  $searchOutput = $client->campaign->marketingList->_search(array("listName" => $listName));
@@ -335,7 +336,7 @@ class Pure360_List_Helper_Api extends Pure360_Common_Helper_Api
335
  {
336
  $domain = Mage::helper('pure360_common')->getModuleGroupKeyValue('pure360', 'settings', 'api_url');
337
  }
338
- $domain = str_replace("http://", "", $domain);
339
 
340
  $successTrackingToken = $list->getSuccessTrackingToken();
341
  $successTrackingToken = empty($successTrackingToken) ? 'magento' : $successTrackingToken;
@@ -354,7 +355,7 @@ class Pure360_List_Helper_Api extends Pure360_Common_Helper_Api
354
 
355
  $curl = curl_init();
356
 
357
- curl_setopt($curl, CURLOPT_URL, 'http://' . $domain . '/_act/tracking.php');
358
  curl_setopt($curl, CURLOPT_HEADER, false);
359
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
360
  curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
189
  {
190
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
191
 
192
+ $listData = array();
193
+ $status = null;
194
 
195
  // Search to see if a lists already exists with this name
196
  $searchOutput = $client->campaign->marketingList->_search(array("listName" => $listName));
336
  {
337
  $domain = Mage::helper('pure360_common')->getModuleGroupKeyValue('pure360', 'settings', 'api_url');
338
  }
339
+ //$domain = str_replace("http://", "", $domain);
340
 
341
  $successTrackingToken = $list->getSuccessTrackingToken();
342
  $successTrackingToken = empty($successTrackingToken) ? 'magento' : $successTrackingToken;
355
 
356
  $curl = curl_init();
357
 
358
+ curl_setopt($curl, CURLOPT_URL, $domain . '/_act/tracking.php');
359
  curl_setopt($curl, CURLOPT_HEADER, false);
360
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
361
  curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
app/code/community/Pure360/List/Helper/Data.php CHANGED
@@ -406,6 +406,29 @@ class Pure360_List_Helper_Data extends Pure360_Common_Helper_Data
406
  return $list;
407
  }
408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  public function toDate($value)
410
  {
411
  $date = date_create($value);
406
  return $list;
407
  }
408
 
409
+ /**
410
+ * Add email address to optout list
411
+ * @param string $email
412
+ * @param integer $storeId
413
+ */
414
+ public function listOptout($email, $storeId)
415
+ {
416
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
417
+
418
+ $list = $this->getListForStore($storeId);
419
+
420
+ /* @var $job Pure360_List_Model_Optout */
421
+ $optout = Mage::getModel('pure360_list/optout');
422
+ $optout->setData('scope', $list->getScope());
423
+ $optout->setData('scope_id', $list->getScopeId());
424
+ $optout->setData('email', $email);
425
+ $optout->setCreatedAt(time());
426
+ $optout->setUpdatedAt(time());
427
+ $optout->save();
428
+
429
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - end');
430
+ }
431
+
432
  public function toDate($value)
433
  {
434
  $date = date_create($value);
app/code/community/Pure360/List/Job/Sync.php CHANGED
@@ -58,6 +58,7 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
58
 
59
  // Set status to syncing
60
  $list->rows = 0;
 
61
  $list->setListStatus(Pure360_List_Model_List::LIST_STATUS_SYNCING);
62
  $list->save();
63
 
@@ -67,6 +68,9 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
67
  // Export all Subscribers next
68
  $this->exportSubscriberList($list);
69
 
 
 
 
70
  // Sync List
71
  if($list->rows > 0)
72
  {
@@ -80,11 +84,19 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
80
  $list->save();
81
  }
82
 
 
 
 
 
 
 
83
  // Finally perform a logout
84
  $this->client->logout();
85
 
86
  // Update message with rows uploaded
87
- $this->_data->setData('message', $list->rows . ' rows uploaded ');
 
 
88
 
89
  // Save list data
90
  $this->_data->save();
@@ -273,7 +285,9 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
273
 
274
  unset($currentBatch);
275
  } while($condition == $batchSize && $list->rows < $this->max_sync_size);
276
-
 
 
277
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - end');
278
  }
279
 
@@ -292,7 +306,7 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
292
  ;
293
 
294
  // Add Default Select
295
- $collection
296
  ->addAttributeToSelect('email')
297
  ->addAttributeToSelect('store_id')
298
  ->addAttributeToSelect('website_id')
@@ -300,7 +314,7 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
300
  ->addAttributeToSelect('subscriber_status')
301
  ->addAttributeToSelect('subscription_date')
302
  ;
303
-
304
  // Add Custom Select
305
  foreach($list->getListFields() as $field)
306
  {
@@ -409,7 +423,12 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
409
  }
410
 
411
  // Get the option label
412
- $val = Mage::getResourceSingleton('customer/customer')->getAttribute($key)->getSource()->getOptionText($val);
 
 
 
 
 
413
 
414
  // Convert back to string
415
  if(is_array($val))
@@ -505,7 +524,9 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
505
 
506
  unset($currentBatch);
507
  } while($condition == $batchSize && $list->rows <= $this->max_sync_size);
508
-
 
 
509
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - end');
510
  }
511
 
@@ -520,6 +541,7 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
520
 
521
  // Configure Collection
522
  $collection = Mage::getModel('newsletter/subscriber')->getCollection()
 
523
  ->addFieldToFilter('main_table.customer_id', array('eq' => 0))
524
  ->addFieldToFilter('subscriber_status', array('eq' => Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED))
525
  ->addStoreFilter($storeIds);
@@ -582,6 +604,110 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
582
  return $dataToSend;
583
  }
584
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585
  private function uploadList(&$list)
586
  {
587
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
@@ -601,6 +727,8 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
601
  $count = count($files);
602
  $page = 1;
603
 
 
 
604
  // Create file
605
  $api->createFile($this->client, $fileCategory, $fileName, $count, "Y");
606
 
@@ -611,7 +739,7 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
611
  $api->uploadFileChunk($this->client, $fileCategory, $fileName, $page, $chunkData, "base64");
612
  $page++;
613
  }
614
-
615
  reset($files);
616
 
617
  // Create/Append list
@@ -639,12 +767,44 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
639
 
640
  $count = 0;
641
 
642
- // Mark customers as synced
643
  foreach($files as $filename)
644
  {
645
  $dataArray = Mage::helper('pure360_common/file')->readCsv($filename);
 
 
 
 
 
 
 
 
 
 
 
646
 
647
- if(strstr($filename, 'subscribe'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
648
  {
649
  $emails = array();
650
 
@@ -674,6 +834,7 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
674
  $stmt->execute();
675
  }
676
  }
 
677
  } else
678
  {
679
  $ids = array();
@@ -724,6 +885,49 @@ class Pure360_List_Job_Sync extends Pure360_Cron_Job_Abstract
724
  return;
725
  }
726
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
727
  private function cleanup($list)
728
  {
729
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
58
 
59
  // Set status to syncing
60
  $list->rows = 0;
61
+ $list->optout_rows = 0;
62
  $list->setListStatus(Pure360_List_Model_List::LIST_STATUS_SYNCING);
63
  $list->save();
64
 
68
  // Export all Subscribers next
69
  $this->exportSubscriberList($list);
70
 
71
+ // Finally all Optouts
72
+ $this->exportOptoutList($list);
73
+
74
  // Sync List
75
  if($list->rows > 0)
76
  {
84
  $list->save();
85
  }
86
 
87
+ // Upload Optouts
88
+ if($list->optout_rows > 0)
89
+ {
90
+ $this->uploadOptouts($list);
91
+ }
92
+
93
  // Finally perform a logout
94
  $this->client->logout();
95
 
96
  // Update message with rows uploaded
97
+ $this->_data->setData('message', $list->rows . ' rows processed, ' . $list->optout_rows . ' rows opted out ');
98
+
99
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' message: '. $list->rows . ' rows processed, ' . $list->optout_rows . ' rows opted out ');
100
 
101
  // Save list data
102
  $this->_data->save();
285
 
286
  unset($currentBatch);
287
  } while($condition == $batchSize && $list->rows < $this->max_sync_size);
288
+
289
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ .' FilePath where data is temporarily saved - '.$filePath);
290
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ .' Number of rows to sync - '. $list->rows);
291
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - end');
292
  }
293
 
306
  ;
307
 
308
  // Add Default Select
309
+ $collection->distinct(true)
310
  ->addAttributeToSelect('email')
311
  ->addAttributeToSelect('store_id')
312
  ->addAttributeToSelect('website_id')
314
  ->addAttributeToSelect('subscriber_status')
315
  ->addAttributeToSelect('subscription_date')
316
  ;
317
+
318
  // Add Custom Select
319
  foreach($list->getListFields() as $field)
320
  {
423
  }
424
 
425
  // Get the option label
426
+ $attr = Mage::getResourceSingleton('customer/customer')->getAttribute($key);
427
+
428
+ if(!empty($attr))
429
+ {
430
+ $val = $attr->getSource()->getOptionText($val);
431
+ }
432
 
433
  // Convert back to string
434
  if(is_array($val))
524
 
525
  unset($currentBatch);
526
  } while($condition == $batchSize && $list->rows <= $this->max_sync_size);
527
+
528
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ .' FilePath where data is temporarily saved - '.$filePath);
529
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ .' Number of rows to sync - '. $list->rows);
530
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - end');
531
  }
532
 
541
 
542
  // Configure Collection
543
  $collection = Mage::getModel('newsletter/subscriber')->getCollection()
544
+ ->distinct(true)
545
  ->addFieldToFilter('main_table.customer_id', array('eq' => 0))
546
  ->addFieldToFilter('subscriber_status', array('eq' => Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED))
547
  ->addStoreFilter($storeIds);
604
  return $dataToSend;
605
  }
606
 
607
+ private function exportOptoutList(&$list)
608
+ {
609
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
610
+
611
+ $resource = Mage::getSingleton('core/resource');
612
+
613
+ // Get handle for write
614
+ $write = $resource->getConnection('core_write');
615
+
616
+ // Clean invalid optouts
617
+ $optoutTable = $resource->getTableName('pure360_optout');
618
+ $subscriberTable = $resource->getTableName('newsletter_subscriber');
619
+
620
+ $stmt = $write->prepare("DELETE e FROM $optoutTable AS e " .
621
+ " LEFT JOIN $subscriberTable AS s ON (s.subscriber_email = e.email) " .
622
+ " WHERE s.subscriber_status = :status AND e.scope = :scope AND e.scope_id = :scopeId ");
623
+
624
+ $status = Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
625
+
626
+ $stmt->bindParam(":status", $status, PDO::PARAM_INT);
627
+ $stmt->bindParam(":scope", $list->getScope(), PDO::PARAM_STR);
628
+ $stmt->bindParam(":scopeId", $list->getScopeId(), PDO::PARAM_INT);
629
+
630
+ $stmt->execute();
631
+
632
+ // Export optout list
633
+ $fileSlug = $list->fileSlug . '__OPTOUT__';
634
+
635
+ $file_ext = '.csv';
636
+ $batchNum = 1;
637
+ $batchSize = self::CHUNK_SIZE;
638
+ $firstEmail = null;
639
+
640
+ do
641
+ {
642
+ $time_start = microtime(true);
643
+ $currentBatch = $this->getOptoutBatch($list, $batchSize, $batchNum);
644
+ $condition = count($currentBatch);
645
+ $filePath = Mage::helper('pure360_common/file')->getFilePath($fileSlug . $batchNum . $file_ext);
646
+
647
+ $firstRow = reset($currentBatch);
648
+
649
+ if(empty($firstRow) || $firstEmail == $firstRow)
650
+ {
651
+ break;
652
+ } else
653
+ {
654
+ $firstEmail = $firstRow;
655
+ }
656
+
657
+ foreach($currentBatch as $email)
658
+ {
659
+ if($list->optout_rows < $this->max_sync_size)
660
+ {
661
+ Mage::helper('pure360_common/file')->outputCSV($filePath, array($email));
662
+ $list->optout_rows++;
663
+ } else
664
+ {
665
+ break;
666
+ }
667
+ }
668
+
669
+ $time_end = microtime(true);
670
+ $time_in_seconds = $time_end - $time_start;
671
+
672
+ Mage::helper('pure360_list')->writeDebug('Exported Optout Batch ' . $batchNum . ' in ' . $time_in_seconds . ' seconds - (' . memory_get_usage() . ') to ' . $filePath);
673
+
674
+ $batchNum++;
675
+
676
+ unset($currentBatch);
677
+ } while($condition == $batchSize && $list->optout_rows <= $this->max_sync_size);
678
+
679
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ .' FilePath where data is temporarily saved - '.$filePath);
680
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ .' Number of rows to sync - '. $list->rows);
681
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - end');
682
+ }
683
+
684
+ private function getOptoutBatch($list, $batchSize = 0, $batchNum = 1)
685
+ {
686
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
687
+
688
+ $emails = array();
689
+
690
+ // Configure Collection
691
+ $collection = Mage::getModel('pure360_list/optout')->getCollection()
692
+ ->distinct(true)
693
+ ->addScopeFilter($list->getScope(), $list->getScopeId());
694
+
695
+ // Add paging for batch operation
696
+ $collection->setCurPage($batchNum)->setPageSize($batchSize);
697
+
698
+ // Get email for each item in collection
699
+ foreach($collection as $row)
700
+ {
701
+ $emails[] = $row->getEmail();
702
+ }
703
+
704
+ unset($collection);
705
+
706
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - end');
707
+
708
+ return $emails;
709
+ }
710
+
711
  private function uploadList(&$list)
712
  {
713
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
727
  $count = count($files);
728
  $page = 1;
729
 
730
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ .' Number of chunks - '.$count);
731
+
732
  // Create file
733
  $api->createFile($this->client, $fileCategory, $fileName, $count, "Y");
734
 
739
  $api->uploadFileChunk($this->client, $fileCategory, $fileName, $page, $chunkData, "base64");
740
  $page++;
741
  }
742
+
743
  reset($files);
744
 
745
  // Create/Append list
767
 
768
  $count = 0;
769
 
 
770
  foreach($files as $filename)
771
  {
772
  $dataArray = Mage::helper('pure360_common/file')->readCsv($filename);
773
+
774
+ // Remove optouts
775
+ if(strstr($filename, 'OPTOUT'))
776
+ {
777
+ $emails = array();
778
+
779
+ foreach($dataArray as $dataRow)
780
+ {
781
+ // Email should always be the only column for optout
782
+ $emails[] = $dataRow[0];
783
+ }
784
 
785
+ // Update Sync Statuses.
786
+ $optoutTable = $resource->getTableName('pure360_optout');
787
+ $email = null;
788
+
789
+ foreach($emails as $emailKey => $email)
790
+ {
791
+ if(empty($email))
792
+ {
793
+ unset($emails[$emailKey]);
794
+
795
+ } else
796
+ {
797
+ $emails[$emailKey] = addslashes($email);
798
+ }
799
+ }
800
+ $sql = "DELETE FROM $optoutTable
801
+ WHERE `email` IN ('".implode("','",$emails)."')
802
+ AND `scope` = '".addslashes($list->getScope())."'
803
+ AND `scope_id` = '".addslashes($list->getScopeId())."' ";
804
+ $write->query($sql);
805
+
806
+ // Mark subscribers as synced
807
+ } else if(strstr($filename, 'subscribe'))
808
  {
809
  $emails = array();
810
 
834
  $stmt->execute();
835
  }
836
  }
837
+ // Mark customers as synced
838
  } else
839
  {
840
  $ids = array();
885
  return;
886
  }
887
 
888
+ private function uploadOptouts(&$list)
889
+ {
890
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
891
+
892
+ // Get list properties
893
+ $listName = '__OPTOUT__';
894
+ $listFields = array('email');
895
+ $files = Mage::helper('pure360_common/file')->getFilenamesForSlug($list->fileSlug . '__OPTOUT__');
896
+
897
+ /* @var $api Pure360_List_Helper_Api */
898
+ $api = Mage::helper('pure360_list/api');
899
+
900
+ // Setup file transfer
901
+ $context = $this->client->getContext();
902
+ $fileCategory = "PAINT";
903
+ $fileName = $context['beanId'] . '__OPTOUT__';
904
+ $count = count($files);
905
+ $page = 1;
906
+
907
+ // Create file
908
+ $api->createFile($this->client, $fileCategory, $fileName, $count, "Y");
909
+
910
+ // Upload chunks
911
+ foreach($files as $filename)
912
+ {
913
+ $chunkData = Mage::helper('pure360_common/file')->readFile($filename, true);
914
+ $api->uploadFileChunk($this->client, $fileCategory, $fileName, $page, $chunkData, "base64");
915
+ $page++;
916
+ }
917
+
918
+ reset($files);
919
+
920
+ // Create/Append list
921
+ $api->createAppendReplaceList($this->client, $listName, $listFields);
922
+
923
+ // Load file data onto list
924
+ $api->loadFileData($this->client, $fileCategory, $fileName, $listName);
925
+
926
+ Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - end');
927
+
928
+ return;
929
+ }
930
+
931
  private function cleanup($list)
932
  {
933
  Mage::helper('pure360_list')->writeDebug(__METHOD__ . ' - start');
app/code/community/Pure360/List/Model/Customer.php CHANGED
@@ -13,24 +13,14 @@ class Pure360_List_Model_Customer extends Mage_Customer_Model_Customer
13
  */
14
  protected function _beforeSave()
15
  {
16
- parent::_beforeSave();
17
-
18
- if (Mage::helper('pure360_list')->isEnabledForStore($this->getStoreId()))
19
  {
20
- $this->setPure360SyncStatus(0);
 
 
 
21
  }
22
-
23
  return $this;
24
  }
25
-
26
- /**
27
- * Processing object after delete data
28
- *
29
- * @return Pure360_List_Model_Customer
30
- */
31
- protected function _afterDelete()
32
- {
33
- parent::_afterDelete();
34
- }
35
  }
36
 
13
  */
14
  protected function _beforeSave()
15
  {
16
+ if(parent::_beforeSave())
 
 
17
  {
18
+ if (Mage::helper('pure360_list')->isEnabledForStore($this->getStoreId()))
19
+ {
20
+ $this->setPure360SyncStatus(0);
21
+ }
22
  }
 
23
  return $this;
24
  }
 
 
 
 
 
 
 
 
 
 
25
  }
26
 
app/code/community/Pure360/List/Model/Optout.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package Pure360\List
5
+ * @copyright 2013 Pure360.com
6
+ */
7
+ class Pure360_List_Model_Optout extends Mage_Core_Model_Abstract
8
+ {
9
+
10
+ public function _construct()
11
+ {
12
+ parent::_construct();
13
+
14
+ $this->_init('pure360_list/optout');
15
+ }
16
+
17
+ }
app/code/community/Pure360/List/Model/Resource/Optout.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package Pure360\List
5
+ * @copyright 2013 Pure360.com
6
+ */
7
+ class Pure360_List_Model_Resource_Optout extends Mage_Core_Model_Mysql4_Abstract
8
+ {
9
+
10
+ /**
11
+ * Primary key auto increment flag
12
+ *
13
+ * @var bool
14
+ */
15
+ protected $_isPkAutoIncrement = false;
16
+
17
+ /**
18
+ * Initialize Model
19
+ *
20
+ * @return void
21
+ * @access public
22
+ */
23
+ public function _construct()
24
+ {
25
+ $this->_init('pure360_list/optout', 'optout_id');
26
+ }
27
+
28
+ }
app/code/community/Pure360/List/Model/Resource/Optout/Collection.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package Pure360\List
5
+ * @copyright 2013 Pure360.com
6
+ */
7
+ class Pure360_List_Model_Resource_Optout_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
8
+ {
9
+ const MAX_COLLECTION_SIZE = 5;
10
+
11
+ /**
12
+ * Initialize Model
13
+ *
14
+ * @return void
15
+ * @access public
16
+ */
17
+ public function _construct()
18
+ {
19
+ parent::_construct();
20
+ $this->_init('pure360_list/optout');
21
+ }
22
+
23
+ /**
24
+ * @param string $scope
25
+ * @param integer $scopeIds
26
+ */
27
+ public function addScopeFilter($scope, $scopeId)
28
+ {
29
+ $this->getSelect()->where('scope = ?', $scope);
30
+ $this->getSelect()->where('scope_id = ?', $scopeId);
31
+ return $this;
32
+ }
33
+
34
+ /**
35
+ * Sort order by order created_at date
36
+ *
37
+ * @param string $dir
38
+ */
39
+ public function orderByCreatedAt($dir = self::SORT_ORDER_DESC)
40
+ {
41
+ $this->setOrder('created_at', $dir);
42
+ return $this;
43
+ }
44
+
45
+ /**
46
+ * Sort order by order updated_at date
47
+ *
48
+ * @param string $dir
49
+ */
50
+ public function orderByUpdatedAt($dir = self::SORT_ORDER_DESC)
51
+ {
52
+ $this->setOrder('updated_at', $dir);
53
+ return $this;
54
+ }
55
+
56
+ }
app/code/community/Pure360/List/Model/Subscriber.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package Pure360\List
5
+ * @copyright 2013 Pure360.com
6
+ */
7
+ class Pure360_List_Model_Subscriber extends Mage_Newsletter_Model_Subscriber
8
+ {
9
+
10
+ /**
11
+ * Processing object before save data
12
+ *
13
+ * @return Pure360_Newsletter_Model_Subscriber
14
+ */
15
+ protected function _beforeSave()
16
+ {
17
+ if(parent::_beforeSave())
18
+ {
19
+ if(Mage::helper('pure360_list')->isEnabledForStore($this->getStoreId()))
20
+ {
21
+ $this->setPure360SyncStatus(0);
22
+
23
+ // Trigger Pure360 sync status for customer too
24
+ if($this->getCustomerId() > 0)
25
+ {
26
+ $customer = Mage::getModel('customer/customer')->load($this->getCustomerId());
27
+
28
+ if($customer->getId())
29
+ {
30
+ $customer->save();
31
+ }
32
+ }
33
+ }
34
+ }
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * Processing object after delete data
40
+ *
41
+ * @return Pure360_Newsletter_Model_Subscriber
42
+ */
43
+ protected function _afterDelete()
44
+ {
45
+ if(parent::_afterDelete())
46
+ {
47
+ if(Mage::helper('pure360_list')->isEnabledForStore($this->getStoreId()))
48
+ {
49
+ // Add to optout list to make sure
50
+ Mage::helper('pure360_list')->listOptout($this->getSubscriberEmail(), $this->getStoreId());
51
+ }
52
+ }
53
+ return $this;
54
+ }
55
+ }
app/code/community/Pure360/List/controllers/AjaxController.php CHANGED
@@ -4,7 +4,7 @@
4
  * @package Pure360\List
5
  * @copyright 2013 Pure360.com
6
  */
7
- class Pure360_List_AjaxController extends Mage_Adminhtml_Controller_Action
8
  {
9
  /**
10
  * Save / Update list from request parameters
4
  * @package Pure360\List
5
  * @copyright 2013 Pure360.com
6
  */
7
+ class Pure360_List_AjaxController extends Mage_Core_Controller_Front_Action
8
  {
9
  /**
10
  * Save / Update list from request parameters
app/code/community/Pure360/List/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Pure360_List>
5
- <version>1.0.2</version>
6
  </Pure360_List>
7
  </modules>
8
  <global>
@@ -27,6 +27,9 @@
27
  <list>
28
  <table>pure360_list</table>
29
  </list>
 
 
 
30
  <field>
31
  <table>pure360_list_field</table>
32
  </field>
@@ -43,6 +46,11 @@
43
  <customer>Pure360_List_Model_Customer</customer>
44
  </rewrite>
45
  </customer>
 
 
 
 
 
46
  </models>
47
  <resources>
48
  <pure360_list_setup>
@@ -145,15 +153,15 @@
145
  </layout>
146
  </adminhtml>
147
  <admin>
148
- <routers>
149
- <pure360_list>
150
- <use>admin</use>
151
- <args>
152
- <module>Pure360_List</module>
153
- <frontName>pure360_list</frontName>
154
- </args>
155
- </pure360_list>
156
- </routers>
157
  </admin>
158
  <default>
159
  <pure360_list>
2
  <config>
3
  <modules>
4
  <Pure360_List>
5
+ <version>1.1.2</version>
6
  </Pure360_List>
7
  </modules>
8
  <global>
27
  <list>
28
  <table>pure360_list</table>
29
  </list>
30
+ <optout>
31
+ <table>pure360_optout</table>
32
+ </optout>
33
  <field>
34
  <table>pure360_list_field</table>
35
  </field>
46
  <customer>Pure360_List_Model_Customer</customer>
47
  </rewrite>
48
  </customer>
49
+ <subscriber>
50
+ <rewrite>
51
+ <customer>Pure360_List_Model_Subscriber</customer>
52
+ </rewrite>
53
+ </subscriber>
54
  </models>
55
  <resources>
56
  <pure360_list_setup>
153
  </layout>
154
  </adminhtml>
155
  <admin>
156
+ <routers>
157
+ <adminhtml>
158
+ <args>
159
+ <modules>
160
+ <pure360_list after="Mage_Adminhtml">Pure360_List_Adminhtml</pure360_list>
161
+ </modules>
162
+ </args>
163
+ </adminhtml>
164
+ </routers>
165
  </admin>
166
  <default>
167
  <pure360_list>
app/code/community/Pure360/List/sql/pure360_list_setup/{mysql4-install-1.0.2.php → mysql4-install-1.0.4.php} RENAMED
@@ -5,6 +5,28 @@ $installer = $this;
5
 
6
  $installer->startSetup();
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  try
9
  {
10
  // Create New Table
@@ -103,20 +125,26 @@ foreach($oldAttributes as $oldAttribute)
103
  }
104
 
105
  // Add attributes to customer
106
- $model->addAttribute(
107
- 'customer', 'pure360_sync_status', array(
108
- 'group' => 'Default',
109
- 'type' => 'int',
110
- 'label' => 'Pure360 Sync Status',
111
- 'input' => 'select',
112
- 'source' => 'eav/entity_attribute_source_boolean',
113
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
114
- 'required' => 0,
115
- 'default' => 0,
116
- 'visible_on_front' => 0,
117
- 'used_for_price_rules' => 0,
118
- 'adminhtml_only' => 1,
119
- )
120
- );
 
 
 
 
 
 
121
 
122
  $installer->endSetup();
5
 
6
  $installer->startSetup();
7
 
8
+ try
9
+ {
10
+ // Create New Table
11
+ $installer->run("
12
+ CREATE TABLE IF NOT EXISTS `{$this->getTable('pure360_optout')}` (
13
+ `optout_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Optout Id',
14
+ `scope` varchar(10) DEFAULT 'default' COMMENT 'Scope',
15
+ `scope_id` smallint(5) unsigned NOT NULL COMMENT 'Scope Id',
16
+ `email` varchar(100) COMMENT 'Subscriber email',
17
+ `created_at` timestamp NULL DEFAULT NULL COMMENT 'Created At',
18
+ `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Updated At',
19
+ PRIMARY KEY (`optout_id`),
20
+ KEY `IDX_PURE360_OPTOUT_SCOPE_ID` (`scope_id`),
21
+ KEY `IDX_PURE360_OPTOUT_CREATED_AT` (`created_at`),
22
+ KEY `IDX_PURE360_OPTOUT_UPDATED_AT` (`updated_at`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Pure360 Optout';
24
+ ");
25
+ } catch(Exception $e)
26
+ {
27
+ // throw new RuntimeException('Failed Creating and Populating Table: ' . $e->getMessage());
28
+ }
29
+
30
  try
31
  {
32
  // Create New Table
125
  }
126
 
127
  // Add attributes to customer
128
+ try
129
+ {
130
+ $model->addAttribute(
131
+ 'customer', 'pure360_sync_status', array(
132
+ 'group' => 'Default',
133
+ 'type' => 'int',
134
+ 'label' => 'Pure360 Sync Status',
135
+ 'input' => 'select',
136
+ 'source' => 'eav/entity_attribute_source_boolean',
137
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
138
+ 'required' => 0,
139
+ 'default' => 0,
140
+ 'visible_on_front' => 0,
141
+ 'used_for_price_rules' => 0,
142
+ 'adminhtml_only' => 1,
143
+ )
144
+ );
145
+ } catch(Exception $e)
146
+ {
147
+
148
+ }
149
 
150
  $installer->endSetup();
app/code/community/Pure360/List/sql/pure360_list_setup/mysql4-upgrade-1.0.3-1.0.4.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ /* @var $installer Mage_Sales_Model_Mysql4_Setup */
5
+
6
+ $installer->startSetup();
7
+
8
+ try
9
+ {
10
+ // Create New Table
11
+ $installer->run("
12
+ CREATE TABLE IF NOT EXISTS `{$this->getTable('pure360_optout')}` (
13
+ `optout_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Optout Id',
14
+ `scope` varchar(10) DEFAULT 'default' COMMENT 'Scope',
15
+ `scope_id` smallint(5) unsigned NOT NULL COMMENT 'Scope Id',
16
+ `email` varchar(100) COMMENT 'Subscriber email',
17
+ `created_at` timestamp NULL DEFAULT NULL COMMENT 'Created At',
18
+ `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Updated At',
19
+ PRIMARY KEY (`optout_id`),
20
+ KEY `IDX_PURE360_OPTOUT_SCOPE_ID` (`scope_id`),
21
+ KEY `IDX_PURE360_OPTOUT_CREATED_AT` (`created_at`),
22
+ KEY `IDX_PURE360_OPTOUT_UPDATED_AT` (`updated_at`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Pure360 Optout';
24
+ ");
25
+ } catch(Exception $e)
26
+ {
27
+ // throw new RuntimeException('Failed Creating and Populating Table: ' . $e->getMessage());
28
+ }
29
+
30
+ $installer->endSetup();
app/code/community/Pure360/Newsletter/Block/Checkout/Onepage/Newsletter.php CHANGED
@@ -91,10 +91,20 @@ class Pure360_Newsletter_Block_Checkout_Onepage_Newsletter extends Mage_Checkout
91
  if($this->$methodName())
92
  {
93
  $action = 'show';
94
- if($this->isSubscribed() || $this->isEnabledCheckedByDefault())
95
  {
96
- $checked = 'true';
97
- $value = '1';
 
 
 
 
 
 
 
 
 
 
98
  }
99
  }
100
  }
91
  if($this->$methodName())
92
  {
93
  $action = 'show';
94
+ if(strtolower($method) == 'customer')
95
  {
96
+ if($this->isSubscribed())
97
+ {
98
+ $checked = 'true';
99
+ $value = '1';
100
+ }
101
+ } else
102
+ {
103
+ if($this->isSubscribed() || $this->isEnabledCheckedByDefault())
104
+ {
105
+ $checked = 'true';
106
+ $value = '1';
107
+ }
108
  }
109
  }
110
  }
app/code/community/Pure360/Newsletter/Helper/Api.php CHANGED
@@ -24,10 +24,10 @@ class Pure360_Newsletter_Helper_Api extends Pure360_Common_Helper_Api
24
  {
25
  $domain = Mage::helper('pure360_common')->getModuleGroupKeyValue('pure360', 'settings', 'api_url');
26
  }
27
- $domain = str_replace("http://", "", $domain);
28
 
29
  // Build url
30
- $url = 'http://' . $domain . '/interface/list.php';
31
 
32
  // Get store and webste ids
33
  $storeId = $subscriber->getStoreId();
@@ -79,7 +79,7 @@ class Pure360_Newsletter_Helper_Api extends Pure360_Common_Helper_Api
79
  * @param Mage_Customer_Model_Customer $customer
80
  * @return type
81
  */
82
- public function listSubscribeCustomer($client, $customer, $date)
83
  {
84
  Mage::helper('pure360_newsletter')->writeDebug(__METHOD__ . ' - start');
85
 
@@ -116,50 +116,60 @@ class Pure360_Newsletter_Helper_Api extends Pure360_Common_Helper_Api
116
  $postFields .= '&website=' . urlencode(Mage::app()->getWebsite($websiteId)->getName());
117
  $postFields .= '&store=' . urlencode($store->getName());
118
 
119
- // Process Customer
120
- $salesFields = Mage::helper('pure360_list')->getSalesFields($list);
 
121
 
122
- $salesData = empty($salesFields) ? array() : Mage::helper('pure360_list')->getSalesData($customer, $salesFields);
 
123
 
124
- $groupData = array('customer_group' =>
125
- Mage::helper('pure360_common')->arrayToCsv(
126
- Mage::helper('pure360_list')->getCustomerGroupData($customer)));
127
 
128
- $segmentData = array('customer_segments' =>
129
- Mage::helper('pure360_common')->arrayToCsv(
130
- Mage::helper('pure360_list')->getCustomerSegmentData($customer)));
131
 
132
- $customerData = array_merge($customer->toArray(), $salesData, $groupData, $segmentData);
 
 
133
 
134
- // Get date key lookup:
135
- $dateKeyLookup = Mage::helper('pure360_list')->getDateKeyLookup();
136
 
137
- foreach(Mage::helper('pure360_list')->getListKeys($list) as $key)
138
- {
139
- $val = '';
140
 
141
- if(isset($customerData[$key]))
142
  {
143
- $val = $customerData[$key];
144
- if(!empty($val))
 
145
  {
146
- if(in_array($key, $dateKeyLookup))
 
147
  {
148
- // Format to pure360 list date
149
- $val = Mage::helper('pure360_list')->toDate($val);
 
 
 
150
  }
151
  }
 
 
152
  }
153
 
154
- $postFields .= '&' . $key . '=' . $val;
155
- }
 
 
156
 
157
- if($list->getDoubleOptinEnabled() != 'y')
 
 
158
  {
159
- $postFields .= '&doubleOptin=false';
160
  }
161
-
162
- $postFields .= '&signup_date=' . urlencode(Mage::helper('pure360_list')->toDate($date));
163
  $postFields .= '&email=' . urlencode($customer->getEmail());
164
 
165
  // Do post
24
  {
25
  $domain = Mage::helper('pure360_common')->getModuleGroupKeyValue('pure360', 'settings', 'api_url');
26
  }
27
+ //$domain = str_replace("http://", "", $domain);
28
 
29
  // Build url
30
+ $url = $domain . '/interface/list.php';
31
 
32
  // Get store and webste ids
33
  $storeId = $subscriber->getStoreId();
79
  * @param Mage_Customer_Model_Customer $customer
80
  * @return type
81
  */
82
+ public function listSubscribeCustomer($client, $customer, $date, $subscribe = true)
83
  {
84
  Mage::helper('pure360_newsletter')->writeDebug(__METHOD__ . ' - start');
85
 
116
  $postFields .= '&website=' . urlencode(Mage::app()->getWebsite($websiteId)->getName());
117
  $postFields .= '&store=' . urlencode($store->getName());
118
 
119
+ if($subscribe)
120
+ {
121
+
122
 
123
+ // Process Customer
124
+ $salesFields = Mage::helper('pure360_list')->getSalesFields($list);
125
 
126
+ $salesData = empty($salesFields) ? array() : Mage::helper('pure360_list')->getSalesData($customer, $salesFields);
 
 
127
 
128
+ $groupData = array('customer_group' =>
129
+ Mage::helper('pure360_common')->arrayToCsv(
130
+ Mage::helper('pure360_list')->getCustomerGroupData($customer)));
131
 
132
+ $segmentData = array('customer_segments' =>
133
+ Mage::helper('pure360_common')->arrayToCsv(
134
+ Mage::helper('pure360_list')->getCustomerSegmentData($customer)));
135
 
136
+ $customerData = array_merge($customer->toArray(), $salesData, $groupData, $segmentData);
 
137
 
138
+ // Get date key lookup:
139
+ $dateKeyLookup = Mage::helper('pure360_list')->getDateKeyLookup();
 
140
 
141
+ foreach(Mage::helper('pure360_list')->getListKeys($list) as $key)
142
  {
143
+ $val = '';
144
+
145
+ if(isset($customerData[$key]))
146
  {
147
+ $val = $customerData[$key];
148
+ if(!empty($val))
149
  {
150
+ if(in_array($key, $dateKeyLookup))
151
+ {
152
+ // Format to pure360 list date
153
+ $val = Mage::helper('pure360_list')->toDate($val);
154
+ }
155
  }
156
  }
157
+
158
+ $postFields .= '&' . $key . '=' . $val;
159
  }
160
 
161
+ if($list->getDoubleOptinEnabled() != 'y')
162
+ {
163
+ $postFields .= '&doubleOptin=false';
164
+ }
165
 
166
+ $postFields .= '&signup_date=' . urlencode(Mage::helper('pure360_list')->toDate($date));
167
+
168
+ } else
169
  {
170
+ $postFields .= '&mode=OPTOUT';
171
  }
172
+
 
173
  $postFields .= '&email=' . urlencode($customer->getEmail());
174
 
175
  // Do post
app/code/community/Pure360/Newsletter/Model/Subscriber.php CHANGED
@@ -6,6 +6,7 @@
6
  */
7
  class Pure360_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscriber
8
  {
 
9
  /**
10
  * Override default subscribe action.
11
  */
@@ -18,7 +19,7 @@ class Pure360_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscrib
18
  if($this->getIsStatusChanged() && $this->getStatus() == self::STATUS_SUBSCRIBED)
19
  {
20
  $this->tagSubscription();
21
-
22
  if(Mage::app()->getWebsite()->getCode() !== 'admin')
23
  {
24
  if($callback)
@@ -42,20 +43,44 @@ class Pure360_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscrib
42
  {
43
  if(Mage::helper('pure360_newsletter')->isEnabledForStore($customer->getStoreId()))
44
  {
45
- if($this->getIsStatusChanged() && $this->getStatus() == self::STATUS_SUBSCRIBED)
46
  {
47
- $this->tagSubscription();
48
-
49
- if(Mage::app()->getWebsite()->getCode() !== 'admin')
50
- {
51
- if($callback)
52
  {
53
- $client = Mage::helper('pure360_common/api')->getClientForWebsite();
54
- Mage::helper('pure360_newsletter/api')->listSubscribeCustomer($client, $customer, $this->getSubscriptionDate());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
  }
57
-
58
- $customer->save();
59
  }
60
  }
61
  }
@@ -70,13 +95,13 @@ class Pure360_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscrib
70
  if(parent::unsubscribe())
71
  {
72
  $storeId = $this->getStoreId();
73
-
74
  if($this->getCustomerId())
75
  {
76
  $customer = Mage::getModel('customer/customer')->load($this->getCustomerId());
77
- $storeId = $customer->getStoreId();
78
  }
79
-
80
  if(Mage::helper('pure360_newsletter')->isEnabledForStore($storeId))
81
  {
82
  if($this->getStatus() == self::STATUS_UNSUBSCRIBED)
@@ -89,6 +114,9 @@ class Pure360_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscrib
89
  Mage::helper('pure360_newsletter/api')->listSubscribe($client, $this, false);
90
  }
91
  }
 
 
 
92
  }
93
  }
94
  }
@@ -107,6 +135,8 @@ class Pure360_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscrib
107
  /**
108
  * Suppress default confirmation success email function if Pure360
109
  * module is active.
 
 
110
  */
111
  public function sendConfirmationSuccessEmail()
112
  {
@@ -123,52 +153,18 @@ class Pure360_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscrib
123
  /**
124
  * Suppress default unsubscribe confirmation email function if Pure360
125
  * module is active.
 
 
126
  */
127
  public function sendUnsubscriptionEmail()
128
  {
129
  if(Mage::helper('pure360_newsletter')->isEnabledForStore($this->getStoreId()))
130
  {
131
  return $this;
 
132
  } else
133
  {
134
  return parent::sendUnsubscriptionEmail();
135
  }
136
  }
137
-
138
- /**
139
- * Processing object before save data
140
- *
141
- */
142
- protected function _beforeSave()
143
- {
144
- parent::_beforeSave();
145
-
146
- if(Mage::helper('pure360_newsletter')->isEnabledForStore($this->getStoreId()))
147
- {
148
- $this->setPure360SyncStatus(0);
149
-
150
- // Trigger Pure360 sync status for customer too
151
- if($this->getCustomerId() > 0)
152
- {
153
- $customer = Mage::getModel('customer/customer')->load($this->getCustomerId());
154
- if($customer->getId())
155
- {
156
- $customer->save();
157
- }
158
- }
159
- }
160
-
161
- return $this;
162
- }
163
-
164
- /**
165
- * Processing object after delete data
166
- *
167
- * @return Pure360_Newsletter_Model_Subscriber
168
- */
169
- protected function _afterDelete()
170
- {
171
- parent::_afterDelete();
172
- }
173
-
174
- }
6
  */
7
  class Pure360_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscriber
8
  {
9
+
10
  /**
11
  * Override default subscribe action.
12
  */
19
  if($this->getIsStatusChanged() && $this->getStatus() == self::STATUS_SUBSCRIBED)
20
  {
21
  $this->tagSubscription();
22
+
23
  if(Mage::app()->getWebsite()->getCode() !== 'admin')
24
  {
25
  if($callback)
43
  {
44
  if(Mage::helper('pure360_newsletter')->isEnabledForStore($customer->getStoreId()))
45
  {
46
+ if($this->getIsStatusChanged())
47
  {
48
+ switch($this->getStatus())
49
+ {
50
+ case self::STATUS_SUBSCRIBED:
 
 
51
  {
52
+ $this->tagSubscription();
53
+
54
+ if(Mage::app()->getWebsite()->getCode() !== 'admin')
55
+ {
56
+ if($callback)
57
+ {
58
+ $client = Mage::helper('pure360_common/api')->getClientForWebsite();
59
+ Mage::helper('pure360_newsletter/api')->listSubscribeCustomer($client, $customer, $this->getSubscriptionDate(), true);
60
+ }
61
+ }
62
+
63
+ $customer->save();
64
+ break;
65
+ }
66
+ case self::STATUS_UNSUBSCRIBED:
67
+ {
68
+ if(Mage::app()->getWebsite()->getCode() !== 'admin')
69
+ {
70
+ if($callback)
71
+ {
72
+ $client = Mage::helper('pure360_common/api')->getClientForWebsite();
73
+ Mage::helper('pure360_newsletter/api')->listSubscribeCustomer($client, $customer, $this->getSubscriptionDate(), false);
74
+ }
75
+ }
76
+
77
+ // Add to optout list to make sure
78
+ Mage::helper('pure360_list')->listOptout($this->getSubscriberEmail(), $customer->getStoreId());
79
+
80
+ $customer->save();
81
+ break;
82
  }
83
  }
 
 
84
  }
85
  }
86
  }
95
  if(parent::unsubscribe())
96
  {
97
  $storeId = $this->getStoreId();
98
+
99
  if($this->getCustomerId())
100
  {
101
  $customer = Mage::getModel('customer/customer')->load($this->getCustomerId());
102
+ $storeId = $customer->getStoreId();
103
  }
104
+
105
  if(Mage::helper('pure360_newsletter')->isEnabledForStore($storeId))
106
  {
107
  if($this->getStatus() == self::STATUS_UNSUBSCRIBED)
114
  Mage::helper('pure360_newsletter/api')->listSubscribe($client, $this, false);
115
  }
116
  }
117
+
118
+ // Add to optout list to make sure
119
+ Mage::helper('pure360_list')->listOptout($this->getSubscriberEmail(), $storeId);
120
  }
121
  }
122
  }
135
  /**
136
  * Suppress default confirmation success email function if Pure360
137
  * module is active.
138
+ *
139
+ * @return Pure360_Newsletter_Model_Subscriber
140
  */
141
  public function sendConfirmationSuccessEmail()
142
  {
153
  /**
154
  * Suppress default unsubscribe confirmation email function if Pure360
155
  * module is active.
156
+ *
157
+ * @return Pure360_Newsletter_Model_Subscriber
158
  */
159
  public function sendUnsubscriptionEmail()
160
  {
161
  if(Mage::helper('pure360_newsletter')->isEnabledForStore($this->getStoreId()))
162
  {
163
  return $this;
164
+
165
  } else
166
  {
167
  return parent::sendUnsubscriptionEmail();
168
  }
169
  }
170
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Pure360/Newsletter/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3