Campaignmonitor_Createsend - Version 1.0.8

Version Notes

Improve cron sync

Download this release

Release Info

Developer Campaign Monitor
Extension Campaignmonitor_Createsend
Version 1.0.8
Comparing to
See all releases


Code changes from version 1.0.7 to 1.0.8

Files changed (69) hide show
  1. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Customer/Edit/Grid.php +64 -64
  2. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email.php +35 -35
  3. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/Grid.php +192 -192
  4. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View.php +97 -97
  5. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Abstract.php +31 -31
  6. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Form.php +37 -37
  7. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Clicks.php +56 -56
  8. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Details.php +43 -43
  9. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Html.php +68 -68
  10. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Opens.php +55 -55
  11. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Text.php +49 -49
  12. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tabs.php +26 -26
  13. app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Switcher.php +27 -27
  14. app/code/community/Campaignmonitor/Createsend/Block/AjaxButton/Abstract.php +108 -108
  15. app/code/community/Campaignmonitor/Createsend/Block/CreateExampleSegments.php +23 -23
  16. app/code/community/Campaignmonitor/Createsend/Block/Linkedattributes.php +67 -67
  17. app/code/community/Campaignmonitor/Createsend/Block/Log/Reader.php +44 -44
  18. app/code/community/Campaignmonitor/Createsend/Block/Log/View.php +50 -50
  19. app/code/community/Campaignmonitor/Createsend/Block/OauthPermissionRequest.php +68 -68
  20. app/code/community/Campaignmonitor/Createsend/Block/OauthRedirectUrl.php +48 -48
  21. app/code/community/Campaignmonitor/Createsend/Block/TestApi.php +23 -23
  22. app/code/community/Campaignmonitor/Createsend/Block/Version.php +33 -33
  23. app/code/community/Campaignmonitor/Createsend/Block/Wishlistattributes.php +66 -66
  24. app/code/community/Campaignmonitor/Createsend/Helper/Api.php +254 -254
  25. app/code/community/Campaignmonitor/Createsend/Helper/Config.php +204 -204
  26. app/code/community/Campaignmonitor/Createsend/Helper/Data.php +452 -452
  27. app/code/community/Campaignmonitor/Createsend/Model/Api.php +916 -913
  28. app/code/community/Campaignmonitor/Createsend/Model/Api/Observer.php +351 -351
  29. app/code/community/Campaignmonitor/Createsend/Model/Config/Api.php +35 -35
  30. app/code/community/Campaignmonitor/Createsend/Model/Config/Attributes/Abstract.php +110 -110
  31. app/code/community/Campaignmonitor/Createsend/Model/Config/AuthenticationMethod.php +44 -44
  32. app/code/community/Campaignmonitor/Createsend/Model/Config/Backend/Apikey.php +51 -51
  33. app/code/community/Campaignmonitor/Createsend/Model/Config/Backend/Listid.php +42 -42
  34. app/code/community/Campaignmonitor/Createsend/Model/Config/Backend/Source/Files.php +80 -80
  35. app/code/community/Campaignmonitor/Createsend/Model/Config/ClientSelection.php +26 -26
  36. app/code/community/Campaignmonitor/Createsend/Model/Config/ConflictResolutionMethod.php +44 -44
  37. app/code/community/Campaignmonitor/Createsend/Model/Config/CustomerAttributes.php +311 -311
  38. app/code/community/Campaignmonitor/Createsend/Model/Config/DefaultCustomFields.php +58 -58
  39. app/code/community/Campaignmonitor/Createsend/Model/Config/ExampleSegments.php +218 -218
  40. app/code/community/Campaignmonitor/Createsend/Model/Config/ListFlag.php +20 -20
  41. app/code/community/Campaignmonitor/Createsend/Model/Config/ListSelection.php +26 -26
  42. app/code/community/Campaignmonitor/Createsend/Model/Config/ProductAttributes.php +81 -81
  43. app/code/community/Campaignmonitor/Createsend/Model/Config/Scope.php +93 -93
  44. app/code/community/Campaignmonitor/Createsend/Model/Config/SubscriptionSources.php +44 -44
  45. app/code/community/Campaignmonitor/Createsend/Model/Cron.php +115 -114
  46. app/code/community/Campaignmonitor/Createsend/Model/Customer/Observer.php +557 -557
  47. app/code/community/Campaignmonitor/Createsend/Model/Email.php +38 -38
  48. app/code/community/Campaignmonitor/Createsend/Model/Email/Cron.php +182 -182
  49. app/code/community/Campaignmonitor/Createsend/Model/Email/Template.php +215 -215
  50. app/code/community/Campaignmonitor/Createsend/Model/List/Cron.php +292 -275
  51. app/code/community/Campaignmonitor/Createsend/Model/List/Initial/Cron.php +119 -119
  52. app/code/community/Campaignmonitor/Createsend/Model/Newsletter.php +113 -113
  53. app/code/community/Campaignmonitor/Createsend/Model/Newsletter/Observer.php +34 -34
  54. app/code/community/Campaignmonitor/Createsend/Model/Product/Observer.php +67 -67
  55. app/code/community/Campaignmonitor/Createsend/Model/Resource/Email.php +25 -25
  56. app/code/community/Campaignmonitor/Createsend/Model/Resource/Email/Collection.php +23 -23
  57. app/code/community/Campaignmonitor/Createsend/controllers/Adminhtml/Createsend/ApiController.php +146 -146
  58. app/code/community/Campaignmonitor/Createsend/controllers/Adminhtml/Createsend/EmailController.php +145 -145
  59. app/code/community/Campaignmonitor/Createsend/controllers/Adminhtml/Createsend/SegmentController.php +44 -44
  60. app/code/community/Campaignmonitor/Createsend/controllers/OauthController.php +148 -148
  61. app/code/community/Campaignmonitor/Createsend/controllers/UnsubscribeController.php +67 -67
  62. app/code/community/Campaignmonitor/Createsend/controllers/WebhooksController.php +125 -125
  63. app/code/community/Campaignmonitor/Createsend/etc/adminhtml.xml +61 -61
  64. app/code/community/Campaignmonitor/Createsend/etc/config.xml +292 -292
  65. app/code/community/Campaignmonitor/Createsend/etc/system.xml +340 -340
  66. app/code/community/Campaignmonitor/Createsend/sql/campaignmonitor_createsend_setup/install-1.0.0.php +145 -145
  67. app/code/community/Campaignmonitor/Createsend/sql/campaignmonitor_createsend_setup/install-1.0.1.php +145 -145
  68. app/design/adminhtml/default/default/template/campaignmonitor/createsend/apiclient.phtml +10 -1
  69. package.xml +6 -9
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Customer/Edit/Grid.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Customer_Edit_Grid
19
- extends Campaignmonitor_Createsend_Block_Adminhtml_Email_Grid
20
- implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
- {
22
- public function getTabLabel()
23
- {
24
- /** @noinspection PhpUndefinedMethodInspection */
25
- return parent::getTabLabel();
26
- }
27
-
28
- public function getTabTitle()
29
- {
30
- /** @noinspection PhpUndefinedMethodInspection */
31
- return parent::getTabTitle();
32
- }
33
-
34
- /**
35
- * Can show tab in tabs
36
- *
37
- * @return boolean
38
- */
39
- public function canShowTab()
40
- {
41
- $customer = Mage::registry('current_customer');
42
- return (bool)$customer->getId();
43
- }
44
-
45
- /**
46
- * Tab is hidden
47
- *
48
- * @return boolean
49
- */
50
- public function isHidden()
51
- {
52
- return false;
53
- }
54
-
55
- /**
56
- * Defines after which existing tab, this tab should be rendered.
57
- *
58
- * @return string
59
- */
60
- public function getAfter()
61
- {
62
- return 'tags';
63
- }
64
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Customer_Edit_Grid
19
+ extends Campaignmonitor_Createsend_Block_Adminhtml_Email_Grid
20
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
+ {
22
+ public function getTabLabel()
23
+ {
24
+ /** @noinspection PhpUndefinedMethodInspection */
25
+ return parent::getTabLabel();
26
+ }
27
+
28
+ public function getTabTitle()
29
+ {
30
+ /** @noinspection PhpUndefinedMethodInspection */
31
+ return parent::getTabTitle();
32
+ }
33
+
34
+ /**
35
+ * Can show tab in tabs
36
+ *
37
+ * @return boolean
38
+ */
39
+ public function canShowTab()
40
+ {
41
+ $customer = Mage::registry('current_customer');
42
+ return (bool)$customer->getId();
43
+ }
44
+
45
+ /**
46
+ * Tab is hidden
47
+ *
48
+ * @return boolean
49
+ */
50
+ public function isHidden()
51
+ {
52
+ return false;
53
+ }
54
+
55
+ /**
56
+ * Defines after which existing tab, this tab should be rendered.
57
+ *
58
+ * @return string
59
+ */
60
+ public function getAfter()
61
+ {
62
+ return 'tags';
63
+ }
64
+ }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email.php CHANGED
@@ -1,36 +1,36 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email extends Mage_Adminhtml_Block_Widget_Grid_Container
19
- {
20
- protected $_blockGroup = 'createsend';
21
- protected $_controller = 'adminhtml_email';
22
-
23
- public function __construct()
24
- {
25
- parent::__construct();
26
- $this->_removeButton('add');
27
- }
28
-
29
- /**
30
- * @return string
31
- */
32
- public function getHeaderText()
33
- {
34
- return $this->__('Campaign Monitor - Email Tracking');
35
- }
36
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email extends Mage_Adminhtml_Block_Widget_Grid_Container
19
+ {
20
+ protected $_blockGroup = 'createsend';
21
+ protected $_controller = 'adminhtml_email';
22
+
23
+ public function __construct()
24
+ {
25
+ parent::__construct();
26
+ $this->_removeButton('add');
27
+ }
28
+
29
+ /**
30
+ * @return string
31
+ */
32
+ public function getHeaderText()
33
+ {
34
+ return $this->__('Campaign Monitor - Email Tracking');
35
+ }
36
  }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/Grid.php CHANGED
@@ -1,192 +1,192 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_Grid extends Mage_Adminhtml_Block_Widget_Grid
19
- {
20
- public function __construct()
21
- {
22
- parent::__construct();
23
- $this->setId('createsend_email_grid');
24
- $this->setDefaultSort('sent_at');
25
- $this->setDefaultDir('DESC');
26
- $this->setSaveParametersInSession(true);
27
- $this->setUseAjax(true);
28
- }
29
-
30
- protected function _prepareColumns()
31
- {
32
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
33
- $helper = Mage::helper('createsend');
34
-
35
- $this->addColumn('sent_at',
36
- array(
37
- 'header' => $helper->__('Sent At'),
38
- 'type' => 'datetime',
39
- 'index' => 'sent_at'
40
- )
41
- );
42
-
43
- /** @var Campaignmonitor_Createsend_Model_Email $email */
44
- $email = Mage::getSingleton('createsend/email');
45
-
46
- $this->addColumn("status",
47
- array(
48
- 'header' => $helper->__('Status'),
49
- 'index' => 'status',
50
- 'type' => 'options',
51
- 'options' => array(
52
- $email::STATUS_SENT => $helper->__($email::STATUS_SENT),
53
- $email::STATUS_ACCEPTED => $helper->__($email::STATUS_ACCEPTED),
54
- $email::STATUS_DELIVERED => $helper->__($email::STATUS_DELIVERED),
55
- $email::STATUS_BOUNCED => $helper->__($email::STATUS_BOUNCED),
56
- $email::STATUS_SPAM => $helper->__($email::STATUS_SPAM),
57
- ),
58
- )
59
- );
60
-
61
- $this->addColumn('subject',
62
- array(
63
- 'header' => $helper->__('Subject'),
64
- 'index' => 'subject'
65
- )
66
- );
67
-
68
- $this->addColumn('recipient',
69
- array(
70
- 'header' => $helper->__('Recipient'),
71
- 'index' => 'recipient'
72
- )
73
- );
74
-
75
- if ((Mage::getSingleton('customer/config_share')->isWebsiteScope())
76
- && Mage::app()->getRequest()->getUserParam('id')) {
77
-
78
- $this->addColumn('website',
79
- array(
80
- 'header' => $helper->__('Website'),
81
- 'width' => '100px',
82
- 'sortable' => false,
83
- 'index' => 'website',
84
- 'type' => 'options',
85
- 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash(),
86
- )
87
- );
88
- }
89
-
90
- if (Mage::getSingleton('admin/session')->isAllowed('adminhtml/createsend_email/view')) {
91
- $request = Mage::app()->getRequest();
92
- $customerId = $request->getUserParam('id');
93
- if (!$customerId) {
94
- $customerId = 0;
95
- }
96
-
97
- $this->addColumn('action',
98
- array(
99
- 'header' => $helper->__('Action'),
100
- 'width' => '50px',
101
- 'type' => 'action',
102
- 'getter' => 'getEmailId',
103
- 'actions' => array(
104
- array(
105
- 'caption' => $helper->__('View'),
106
- 'url' => array(
107
- 'base' => 'adminhtml/createsend_email/view',
108
- 'params' => array(
109
- 'customer_id' => $customerId
110
- )
111
- ),
112
- 'field' => 'email_id',
113
- 'data-column' => 'action',
114
- )
115
- ),
116
- 'filter' => false,
117
- 'sortable' => false,
118
- 'is_system' => true,
119
- )
120
- );
121
- }
122
-
123
- return parent::_prepareColumns();
124
- }
125
-
126
- protected function _addColumnFilterToCollection($column)
127
- {
128
- if ($this->getCollection()) {
129
- $cond = $column->getFilter()->getCondition();
130
-
131
- if ($column->getId() == 'website') {
132
- if (!empty($cond)) {
133
- foreach ($cond as $websiteId) {
134
- $website = Mage::app()->getWebsite($websiteId);
135
-
136
- $collection = $this->getCollection();
137
- $conn = $collection->getConnection();
138
-
139
- $collection->getSelect()->where(
140
- new Zend_Db_Expr(
141
- $conn->quoteInto('(scope=?', 'websites')
142
- . ' AND ' .
143
- $conn->quoteInto('scope_id=?)', $websiteId)
144
- . ' OR ' .
145
- $conn->quoteInto('(scope=?', 'stores')
146
- . ' AND ' .
147
- $conn->quoteInto('scope_id in (?))', $website->getStoreIds())
148
- )
149
- );
150
- }
151
- }
152
-
153
- return $this;
154
- }
155
- }
156
-
157
- return parent::_addColumnFilterToCollection($column);
158
- }
159
-
160
- protected function _prepareCollection()
161
- {
162
- /** @var Campaignmonitor_Createsend_Model_Resource_Email_Collection $collection */
163
- $collection = Mage::getModel('createsend/email')->getCollection();
164
-
165
- $request = Mage::app()->getRequest();
166
- $website = $request->getUserParam('website');
167
- $store = $request->getUserParam('store');
168
-
169
- if ($customerId = $request->getUserParam('id')) {
170
- if ($customer = Mage::getSingleton('customer/customer')->load($customerId)) {
171
- $collection = $collection->addFieldToFilter(
172
- 'recipient',
173
- array(
174
- 'like' => '%' . $customer->getEmail() . '%'
175
- )
176
- );
177
- }
178
- } else {
179
- list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')->_getScope($website, $store);
180
- $collection->addFieldToFilter('scope', $scope)->addFieldToFilter('scope_id', $scopeId);
181
- }
182
-
183
- $this->setCollection($collection);
184
-
185
- return parent::_prepareCollection();
186
- }
187
-
188
- public function getGridUrl()
189
- {
190
- return $this->getUrl('adminhtml/createsend_email/grid', array('_current'=>true));
191
- }
192
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_Grid extends Mage_Adminhtml_Block_Widget_Grid
19
+ {
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+ $this->setId('createsend_email_grid');
24
+ $this->setDefaultSort('sent_at');
25
+ $this->setDefaultDir('DESC');
26
+ $this->setSaveParametersInSession(true);
27
+ $this->setUseAjax(true);
28
+ }
29
+
30
+ protected function _prepareColumns()
31
+ {
32
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
33
+ $helper = Mage::helper('createsend');
34
+
35
+ $this->addColumn('sent_at',
36
+ array(
37
+ 'header' => $helper->__('Sent At'),
38
+ 'type' => 'datetime',
39
+ 'index' => 'sent_at'
40
+ )
41
+ );
42
+
43
+ /** @var Campaignmonitor_Createsend_Model_Email $email */
44
+ $email = Mage::getSingleton('createsend/email');
45
+
46
+ $this->addColumn("status",
47
+ array(
48
+ 'header' => $helper->__('Status'),
49
+ 'index' => 'status',
50
+ 'type' => 'options',
51
+ 'options' => array(
52
+ $email::STATUS_SENT => $helper->__($email::STATUS_SENT),
53
+ $email::STATUS_ACCEPTED => $helper->__($email::STATUS_ACCEPTED),
54
+ $email::STATUS_DELIVERED => $helper->__($email::STATUS_DELIVERED),
55
+ $email::STATUS_BOUNCED => $helper->__($email::STATUS_BOUNCED),
56
+ $email::STATUS_SPAM => $helper->__($email::STATUS_SPAM),
57
+ ),
58
+ )
59
+ );
60
+
61
+ $this->addColumn('subject',
62
+ array(
63
+ 'header' => $helper->__('Subject'),
64
+ 'index' => 'subject'
65
+ )
66
+ );
67
+
68
+ $this->addColumn('recipient',
69
+ array(
70
+ 'header' => $helper->__('Recipient'),
71
+ 'index' => 'recipient'
72
+ )
73
+ );
74
+
75
+ if ((Mage::getSingleton('customer/config_share')->isWebsiteScope())
76
+ && Mage::app()->getRequest()->getUserParam('id')) {
77
+
78
+ $this->addColumn('website',
79
+ array(
80
+ 'header' => $helper->__('Website'),
81
+ 'width' => '100px',
82
+ 'sortable' => false,
83
+ 'index' => 'website',
84
+ 'type' => 'options',
85
+ 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash(),
86
+ )
87
+ );
88
+ }
89
+
90
+ if (Mage::getSingleton('admin/session')->isAllowed('adminhtml/createsend_email/view')) {
91
+ $request = Mage::app()->getRequest();
92
+ $customerId = $request->getUserParam('id');
93
+ if (!$customerId) {
94
+ $customerId = 0;
95
+ }
96
+
97
+ $this->addColumn('action',
98
+ array(
99
+ 'header' => $helper->__('Action'),
100
+ 'width' => '50px',
101
+ 'type' => 'action',
102
+ 'getter' => 'getEmailId',
103
+ 'actions' => array(
104
+ array(
105
+ 'caption' => $helper->__('View'),
106
+ 'url' => array(
107
+ 'base' => 'adminhtml/createsend_email/view',
108
+ 'params' => array(
109
+ 'customer_id' => $customerId
110
+ )
111
+ ),
112
+ 'field' => 'email_id',
113
+ 'data-column' => 'action',
114
+ )
115
+ ),
116
+ 'filter' => false,
117
+ 'sortable' => false,
118
+ 'is_system' => true,
119
+ )
120
+ );
121
+ }
122
+
123
+ return parent::_prepareColumns();
124
+ }
125
+
126
+ protected function _addColumnFilterToCollection($column)
127
+ {
128
+ if ($this->getCollection()) {
129
+ $cond = $column->getFilter()->getCondition();
130
+
131
+ if ($column->getId() == 'website') {
132
+ if (!empty($cond)) {
133
+ foreach ($cond as $websiteId) {
134
+ $website = Mage::app()->getWebsite($websiteId);
135
+
136
+ $collection = $this->getCollection();
137
+ $conn = $collection->getConnection();
138
+
139
+ $collection->getSelect()->where(
140
+ new Zend_Db_Expr(
141
+ $conn->quoteInto('(scope=?', 'websites')
142
+ . ' AND ' .
143
+ $conn->quoteInto('scope_id=?)', $websiteId)
144
+ . ' OR ' .
145
+ $conn->quoteInto('(scope=?', 'stores')
146
+ . ' AND ' .
147
+ $conn->quoteInto('scope_id in (?))', $website->getStoreIds())
148
+ )
149
+ );
150
+ }
151
+ }
152
+
153
+ return $this;
154
+ }
155
+ }
156
+
157
+ return parent::_addColumnFilterToCollection($column);
158
+ }
159
+
160
+ protected function _prepareCollection()
161
+ {
162
+ /** @var Campaignmonitor_Createsend_Model_Resource_Email_Collection $collection */
163
+ $collection = Mage::getModel('createsend/email')->getCollection();
164
+
165
+ $request = Mage::app()->getRequest();
166
+ $website = $request->getUserParam('website');
167
+ $store = $request->getUserParam('store');
168
+
169
+ if ($customerId = $request->getUserParam('id')) {
170
+ if ($customer = Mage::getSingleton('customer/customer')->load($customerId)) {
171
+ $collection = $collection->addFieldToFilter(
172
+ 'recipient',
173
+ array(
174
+ 'like' => '%' . $customer->getEmail() . '%'
175
+ )
176
+ );
177
+ }
178
+ } else {
179
+ list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')->_getScope($website, $store);
180
+ $collection->addFieldToFilter('scope', $scope)->addFieldToFilter('scope_id', $scopeId);
181
+ }
182
+
183
+ $this->setCollection($collection);
184
+
185
+ return parent::_prepareCollection();
186
+ }
187
+
188
+ public function getGridUrl()
189
+ {
190
+ return $this->getUrl('adminhtml/createsend_email/grid', array('_current'=>true));
191
+ }
192
+ }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View.php CHANGED
@@ -1,98 +1,98 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_View extends Mage_Adminhtml_Block_Widget_Form_Container
19
- {
20
- protected $_objectId = 'id';
21
- protected $_blockGroup = 'createsend';
22
- protected $_controller = 'adminhtml_email';
23
- protected $_mode = 'view';
24
-
25
- const HEADER_MESSAGE_ID = 'Message ID: %s';
26
-
27
- public function __construct()
28
- {
29
- parent::__construct();
30
-
31
- if ($this->isResendable()) {
32
- $this->_updateButton('save', 'label', Mage::helper('createsend')->__('Resend'));
33
- } else {
34
- $this->_removeButton('save');
35
- }
36
-
37
- $this->_removeButton('reset');
38
- }
39
-
40
- public function getHeaderText()
41
- {
42
- $message = $this->getMessage();
43
-
44
- return sprintf(Mage::helper('createsend')->__(self::HEADER_MESSAGE_ID), htmlentities($message['MessageID']));
45
- }
46
-
47
- public function getBackUrl()
48
- {
49
- $request = Mage::app()->getRequest();
50
- $customerId = $request->getUserParam('customer_id');
51
- if ($customerId) {
52
- return $this->getUrl(
53
- 'adminhtml/customer/edit',
54
- array(
55
- 'id' => $customerId,
56
- '_query' => array('active_tab' => 'createsend_email_grid')
57
- )
58
- );
59
- } else {
60
- return $this->getUrl('adminhtml/createsend_email/index');
61
- }
62
- }
63
-
64
- /**
65
- * Returns the email message object from registry. Message is of the form of an
66
- * array as returned by Campaign Monitor API.
67
- *
68
- * @link https://www.campaignmonitor.com/api/transactional/#message_details
69
- *
70
- * @return array
71
- */
72
- public function getMessage()
73
- {
74
- return Mage::registry('createsend_email');
75
- }
76
-
77
- /**
78
- * Returns true if the message can be resent.
79
- *
80
- * @return bool
81
- */
82
- public function isResendable()
83
- {
84
- $message = $this->getMessage();
85
-
86
- $key = 'CanBeResent';
87
- if (array_key_exists($key, $message)) {
88
- if (is_bool($message[$key])) {
89
- return $message[$key];
90
- } else {
91
- return (mb_strtoupper(trim($message[$key])) === mb_strtoupper("true")) ? TRUE : FALSE;
92
- }
93
- } else {
94
- // Cannot be resent by default
95
- return false;
96
- }
97
- }
98
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_View extends Mage_Adminhtml_Block_Widget_Form_Container
19
+ {
20
+ protected $_objectId = 'id';
21
+ protected $_blockGroup = 'createsend';
22
+ protected $_controller = 'adminhtml_email';
23
+ protected $_mode = 'view';
24
+
25
+ const HEADER_MESSAGE_ID = 'Message ID: %s';
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+
31
+ if ($this->isResendable()) {
32
+ $this->_updateButton('save', 'label', Mage::helper('createsend')->__('Resend'));
33
+ } else {
34
+ $this->_removeButton('save');
35
+ }
36
+
37
+ $this->_removeButton('reset');
38
+ }
39
+
40
+ public function getHeaderText()
41
+ {
42
+ $message = $this->getMessage();
43
+
44
+ return sprintf(Mage::helper('createsend')->__(self::HEADER_MESSAGE_ID), htmlentities($message['MessageID']));
45
+ }
46
+
47
+ public function getBackUrl()
48
+ {
49
+ $request = Mage::app()->getRequest();
50
+ $customerId = $request->getUserParam('customer_id');
51
+ if ($customerId) {
52
+ return $this->getUrl(
53
+ 'adminhtml/customer/edit',
54
+ array(
55
+ 'id' => $customerId,
56
+ '_query' => array('active_tab' => 'createsend_email_grid')
57
+ )
58
+ );
59
+ } else {
60
+ return $this->getUrl('adminhtml/createsend_email/index');
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Returns the email message object from registry. Message is of the form of an
66
+ * array as returned by Campaign Monitor API.
67
+ *
68
+ * @link https://www.campaignmonitor.com/api/transactional/#message_details
69
+ *
70
+ * @return array
71
+ */
72
+ public function getMessage()
73
+ {
74
+ return Mage::registry('createsend_email');
75
+ }
76
+
77
+ /**
78
+ * Returns true if the message can be resent.
79
+ *
80
+ * @return bool
81
+ */
82
+ public function isResendable()
83
+ {
84
+ $message = $this->getMessage();
85
+
86
+ $key = 'CanBeResent';
87
+ if (array_key_exists($key, $message)) {
88
+ if (is_bool($message[$key])) {
89
+ return $message[$key];
90
+ } else {
91
+ return (mb_strtoupper(trim($message[$key])) === mb_strtoupper("true")) ? TRUE : FALSE;
92
+ }
93
+ } else {
94
+ // Cannot be resent by default
95
+ return false;
96
+ }
97
+ }
98
  }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Abstract.php CHANGED
@@ -1,31 +1,31 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- abstract class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
19
- extends Mage_Adminhtml_Block_Widget
20
- {
21
- /**
22
- * Retrieve email details, an array returned by Campaign Monitor API
23
- * @link https://www.campaignmonitor.com/api/transactional/#message_details
24
- *
25
- * @return array
26
- */
27
- public function getEmail()
28
- {
29
- return Mage::registry('createsend_email');
30
- }
31
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ abstract class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
19
+ extends Mage_Adminhtml_Block_Widget
20
+ {
21
+ /**
22
+ * Retrieve email details, an array returned by Campaign Monitor API
23
+ * @link https://www.campaignmonitor.com/api/transactional/#message_details
24
+ *
25
+ * @return array
26
+ */
27
+ public function getEmail()
28
+ {
29
+ return Mage::registry('createsend_email');
30
+ }
31
+ }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Form.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Form extends Mage_Adminhtml_Block_Widget_Form
19
- {
20
- /**
21
- * @return Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Form
22
- */
23
- protected function _prepareForm()
24
- {
25
- $form = new Varien_Data_Form(
26
- array(
27
- 'id' => 'createsend_email_view_form',
28
- 'name' => 'editForm',
29
- 'action' => $this->getUrl('*/*/resend', array('email_id' => $this->getRequest()->getParam('email_id'))),
30
- 'method' => 'get',
31
- )
32
- );
33
-
34
- $form->setUseContainer(true);
35
- $this->setForm($form);
36
- return parent::_prepareForm();
37
- }
38
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Form extends Mage_Adminhtml_Block_Widget_Form
19
+ {
20
+ /**
21
+ * @return Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Form
22
+ */
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(
26
+ array(
27
+ 'id' => 'createsend_email_view_form',
28
+ 'name' => 'editForm',
29
+ 'action' => $this->getUrl('*/*/resend', array('email_id' => $this->getRequest()->getParam('email_id'))),
30
+ 'method' => 'get',
31
+ )
32
+ );
33
+
34
+ $form->setUseContainer(true);
35
+ $this->setForm($form);
36
+ return parent::_prepareForm();
37
+ }
38
  }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Clicks.php CHANGED
@@ -1,56 +1,56 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Clicks
19
- extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
- implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
- {
22
- const TRACK_INDEX = 'Clicks';
23
-
24
- public function getTrackIndex()
25
- {
26
- return self::TRACK_INDEX;
27
- }
28
-
29
- public function getTabLabel()
30
- {
31
- /** @noinspection PhpUndefinedMethodInspection */
32
- return parent::getTabLabel();
33
- }
34
-
35
- public function getTabTitle()
36
- {
37
- /** @noinspection PhpUndefinedMethodInspection */
38
- return parent::getTabTitle();
39
- }
40
-
41
- public function canShowTab()
42
- {
43
- return true;
44
- }
45
-
46
- public function isHidden()
47
- {
48
- /** @var array $email */
49
- $email = $this->getEmail();
50
- if (empty($email['TotalClicks'])) {
51
- return true;
52
- } else {
53
- return false;
54
- }
55
- }
56
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Clicks
19
+ extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
+ {
22
+ const TRACK_INDEX = 'Clicks';
23
+
24
+ public function getTrackIndex()
25
+ {
26
+ return self::TRACK_INDEX;
27
+ }
28
+
29
+ public function getTabLabel()
30
+ {
31
+ /** @noinspection PhpUndefinedMethodInspection */
32
+ return parent::getTabLabel();
33
+ }
34
+
35
+ public function getTabTitle()
36
+ {
37
+ /** @noinspection PhpUndefinedMethodInspection */
38
+ return parent::getTabTitle();
39
+ }
40
+
41
+ public function canShowTab()
42
+ {
43
+ return true;
44
+ }
45
+
46
+ public function isHidden()
47
+ {
48
+ /** @var array $email */
49
+ $email = $this->getEmail();
50
+ if (empty($email['TotalClicks'])) {
51
+ return true;
52
+ } else {
53
+ return false;
54
+ }
55
+ }
56
+ }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Details.php CHANGED
@@ -1,43 +1,43 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Details
19
- extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
- implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
- {
22
- public function getTabLabel()
23
- {
24
- /** @noinspection PhpUndefinedMethodInspection */
25
- return parent::getTabLabel();
26
- }
27
-
28
- public function getTabTitle()
29
- {
30
- /** @noinspection PhpUndefinedMethodInspection */
31
- return parent::getTabTitle();
32
- }
33
-
34
- public function canShowTab()
35
- {
36
- return true;
37
- }
38
-
39
- public function isHidden()
40
- {
41
- return false;
42
- }
43
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Details
19
+ extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
+ {
22
+ public function getTabLabel()
23
+ {
24
+ /** @noinspection PhpUndefinedMethodInspection */
25
+ return parent::getTabLabel();
26
+ }
27
+
28
+ public function getTabTitle()
29
+ {
30
+ /** @noinspection PhpUndefinedMethodInspection */
31
+ return parent::getTabTitle();
32
+ }
33
+
34
+ public function canShowTab()
35
+ {
36
+ return true;
37
+ }
38
+
39
+ public function isHidden()
40
+ {
41
+ return false;
42
+ }
43
+ }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Html.php CHANGED
@@ -1,68 +1,68 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Html
19
- extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
- implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
- {
22
- public function getTabLabel()
23
- {
24
- /** @noinspection PhpUndefinedMethodInspection */
25
- return parent::getTabLabel();
26
- }
27
-
28
- public function getTabTitle()
29
- {
30
- /** @noinspection PhpUndefinedMethodInspection */
31
- return parent::getTabTitle();
32
- }
33
-
34
- public function canShowTab()
35
- {
36
- return true;
37
- }
38
-
39
- public function isHidden()
40
- {
41
- /** @var array $email */
42
- $email = $this->getEmail();
43
- if (empty($email['Message']['Body']['Html'])) {
44
- return true;
45
- } else {
46
- return false;
47
- }
48
- }
49
-
50
- /**
51
- * Returns the url for viewing the Email Body given the Email ID (table primary key)
52
- *
53
- * @param int $emailId
54
- * @return string
55
- */
56
- public function getEmailViewUrl($emailId)
57
- {
58
- return $this->getUrl(
59
- 'adminhtml/createsend_email/view',
60
- array(
61
- '_query' => array(
62
- 'email_id' => $emailId,
63
- 'display' => 'body'
64
- )
65
- )
66
- );
67
- }
68
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Html
19
+ extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
+ {
22
+ public function getTabLabel()
23
+ {
24
+ /** @noinspection PhpUndefinedMethodInspection */
25
+ return parent::getTabLabel();
26
+ }
27
+
28
+ public function getTabTitle()
29
+ {
30
+ /** @noinspection PhpUndefinedMethodInspection */
31
+ return parent::getTabTitle();
32
+ }
33
+
34
+ public function canShowTab()
35
+ {
36
+ return true;
37
+ }
38
+
39
+ public function isHidden()
40
+ {
41
+ /** @var array $email */
42
+ $email = $this->getEmail();
43
+ if (empty($email['Message']['Body']['Html'])) {
44
+ return true;
45
+ } else {
46
+ return false;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Returns the url for viewing the Email Body given the Email ID (table primary key)
52
+ *
53
+ * @param int $emailId
54
+ * @return string
55
+ */
56
+ public function getEmailViewUrl($emailId)
57
+ {
58
+ return $this->getUrl(
59
+ 'adminhtml/createsend_email/view',
60
+ array(
61
+ '_query' => array(
62
+ 'email_id' => $emailId,
63
+ 'display' => 'body'
64
+ )
65
+ )
66
+ );
67
+ }
68
+ }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Opens.php CHANGED
@@ -1,56 +1,56 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Opens
19
- extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
- implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
- {
22
- const TRACK_INDEX = 'Opens';
23
-
24
- public function getTrackIndex()
25
- {
26
- return self::TRACK_INDEX;
27
- }
28
-
29
- public function getTabLabel()
30
- {
31
- /** @noinspection PhpUndefinedMethodInspection */
32
- return parent::getTabLabel();
33
- }
34
-
35
- public function getTabTitle()
36
- {
37
- /** @noinspection PhpUndefinedMethodInspection */
38
- return parent::getTabTitle();
39
- }
40
-
41
- public function canShowTab()
42
- {
43
- return true;
44
- }
45
-
46
- public function isHidden()
47
- {
48
- /** @var array $email */
49
- $email = $this->getEmail();
50
- if (empty($email['TotalOpens'])) {
51
- return true;
52
- } else {
53
- return false;
54
- }
55
- }
56
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Opens
19
+ extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
+ {
22
+ const TRACK_INDEX = 'Opens';
23
+
24
+ public function getTrackIndex()
25
+ {
26
+ return self::TRACK_INDEX;
27
+ }
28
+
29
+ public function getTabLabel()
30
+ {
31
+ /** @noinspection PhpUndefinedMethodInspection */
32
+ return parent::getTabLabel();
33
+ }
34
+
35
+ public function getTabTitle()
36
+ {
37
+ /** @noinspection PhpUndefinedMethodInspection */
38
+ return parent::getTabTitle();
39
+ }
40
+
41
+ public function canShowTab()
42
+ {
43
+ return true;
44
+ }
45
+
46
+ public function isHidden()
47
+ {
48
+ /** @var array $email */
49
+ $email = $this->getEmail();
50
+ if (empty($email['TotalOpens'])) {
51
+ return true;
52
+ } else {
53
+ return false;
54
+ }
55
+ }
56
  }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tab/Text.php CHANGED
@@ -1,49 +1,49 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Text
19
- extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
- implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
- {
22
- public function getTabLabel()
23
- {
24
- /** @noinspection PhpUndefinedMethodInspection */
25
- return parent::getTabLabel();
26
- }
27
-
28
- public function getTabTitle()
29
- {
30
- /** @noinspection PhpUndefinedMethodInspection */
31
- return parent::getTabTitle();
32
- }
33
-
34
- public function canShowTab()
35
- {
36
- return true;
37
- }
38
-
39
- public function isHidden()
40
- {
41
- /** @var array $email */
42
- $email = $this->getEmail();
43
- if (empty($email['Message']['Body']['Text'])) {
44
- return true;
45
- } else {
46
- return false;
47
- }
48
- }
49
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tab_Text
19
+ extends Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Abstract
20
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
+ {
22
+ public function getTabLabel()
23
+ {
24
+ /** @noinspection PhpUndefinedMethodInspection */
25
+ return parent::getTabLabel();
26
+ }
27
+
28
+ public function getTabTitle()
29
+ {
30
+ /** @noinspection PhpUndefinedMethodInspection */
31
+ return parent::getTabTitle();
32
+ }
33
+
34
+ public function canShowTab()
35
+ {
36
+ return true;
37
+ }
38
+
39
+ public function isHidden()
40
+ {
41
+ /** @var array $email */
42
+ $email = $this->getEmail();
43
+ if (empty($email['Message']['Body']['Text'])) {
44
+ return true;
45
+ } else {
46
+ return false;
47
+ }
48
+ }
49
+ }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Email/View/Tabs.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
19
- {
20
- public function __construct()
21
- {
22
- parent::__construct();
23
- $this->setId('createsend_email_tabs');
24
- $this->setDestElementId('createsend_email_view_form');
25
- $this->setTitle(Mage::helper('createsend')->__('View Email'));
26
- }
27
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Adminhtml_Email_View_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
19
+ {
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+ $this->setId('createsend_email_tabs');
24
+ $this->setDestElementId('createsend_email_view_form');
25
+ $this->setTitle(Mage::helper('createsend')->__('View Email'));
26
+ }
27
  }
app/code/community/Campaignmonitor/Createsend/Block/Adminhtml/Switcher.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Extends the System Config Switcher to remove unwanted text.
20
- */
21
- class Campaignmonitor_Createsend_Block_Adminhtml_Switcher extends Mage_Adminhtml_Block_System_Config_Switcher
22
- {
23
- protected function _prepareLayout()
24
- {
25
- $this->setTemplate('campaignmonitor/createsend/switcher.phtml');
26
- return Mage_Adminhtml_Block_Template::_prepareLayout();
27
- }
28
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Extends the System Config Switcher to remove unwanted text.
20
+ */
21
+ class Campaignmonitor_Createsend_Block_Adminhtml_Switcher extends Mage_Adminhtml_Block_System_Config_Switcher
22
+ {
23
+ protected function _prepareLayout()
24
+ {
25
+ $this->setTemplate('campaignmonitor/createsend/switcher.phtml');
26
+ return Mage_Adminhtml_Block_Template::_prepareLayout();
27
+ }
28
  }
app/code/community/Campaignmonitor/Createsend/Block/AjaxButton/Abstract.php CHANGED
@@ -1,109 +1,109 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- abstract class Campaignmonitor_Createsend_Block_AjaxButton_Abstract extends Mage_Adminhtml_Block_System_Config_Form_Field
19
- {
20
- /** @var string */
21
- protected $_urlPath;
22
-
23
- /** @var string */
24
- protected $_ajaxUrl;
25
-
26
- /** @var string */
27
- protected $_buttonHtml;
28
-
29
- protected function _construct()
30
- {
31
- parent::_construct();
32
- $this->setTemplate('campaignmonitor/createsend/ajax.phtml');
33
- }
34
-
35
- /**
36
- * Return element html
37
- *
38
- * @param Varien_Data_Form_Element_Abstract $element
39
- * @return string
40
- */
41
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
42
- {
43
- /** @var Mage_Core_Model_Config_Data $configData */
44
- $configData = Mage::getSingleton('adminhtml/config_data');
45
-
46
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
47
- $scopeModel = Mage::getSingleton('createsend/config_scope');
48
- list($scope, $scopeId) = $scopeModel->_getScope($configData->getWebsite(), $configData->getStore());
49
-
50
- $this->_ajaxUrl = $this->getUrl(
51
- $this->_urlPath,
52
- array(
53
- '_query' => array(
54
- 'scope' => $scope,
55
- 'scopeId' => $scopeId,
56
- )
57
- )
58
- );
59
-
60
- $this->setElement($element);
61
-
62
- $button = $this->getLayout()->createBlock('adminhtml/widget_button')
63
- ->setType('button')
64
- ->setLabel($element->getLabel())
65
- ->setOnClick('javascript:' . $this->getAjaxFunction(). '(); return false;')
66
- ->setId($element->getId());
67
-
68
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
69
- $helper = Mage::helper("createsend");
70
-
71
- if (!$helper->isCompleteConfig($scope, $scopeId)) {
72
- $button->setDisabled('disabled');
73
- }
74
-
75
- $this->_buttonHtml = $button->toHtml();
76
-
77
- return $this->_toHtml();
78
- }
79
-
80
- /**
81
- * Returns the Javascript function name for performing the Ajax call.
82
- *
83
- * @return string
84
- */
85
- public function getAjaxFunction()
86
- {
87
- return $this->getElement()->getId() . 'Ajax';
88
- }
89
-
90
- /**
91
- * Returns the AJAX URL to test the API
92
- *
93
- * @return string
94
- */
95
- public function getAjaxUrl()
96
- {
97
- return $this->_ajaxUrl;
98
- }
99
-
100
- /**
101
- * Returns the HTML for the custom API Test button
102
- *
103
- * @return string
104
- */
105
- public function getButtonHtml()
106
- {
107
- return $this->_buttonHtml;
108
- }
109
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ abstract class Campaignmonitor_Createsend_Block_AjaxButton_Abstract extends Mage_Adminhtml_Block_System_Config_Form_Field
19
+ {
20
+ /** @var string */
21
+ protected $_urlPath;
22
+
23
+ /** @var string */
24
+ protected $_ajaxUrl;
25
+
26
+ /** @var string */
27
+ protected $_buttonHtml;
28
+
29
+ protected function _construct()
30
+ {
31
+ parent::_construct();
32
+ $this->setTemplate('campaignmonitor/createsend/ajax.phtml');
33
+ }
34
+
35
+ /**
36
+ * Return element html
37
+ *
38
+ * @param Varien_Data_Form_Element_Abstract $element
39
+ * @return string
40
+ */
41
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
42
+ {
43
+ /** @var Mage_Core_Model_Config_Data $configData */
44
+ $configData = Mage::getSingleton('adminhtml/config_data');
45
+
46
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
47
+ $scopeModel = Mage::getSingleton('createsend/config_scope');
48
+ list($scope, $scopeId) = $scopeModel->_getScope($configData->getWebsite(), $configData->getStore());
49
+
50
+ $this->_ajaxUrl = $this->getUrl(
51
+ $this->_urlPath,
52
+ array(
53
+ '_query' => array(
54
+ 'scope' => $scope,
55
+ 'scopeId' => $scopeId,
56
+ )
57
+ )
58
+ );
59
+
60
+ $this->setElement($element);
61
+
62
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
63
+ ->setType('button')
64
+ ->setLabel($element->getLabel())
65
+ ->setOnClick('javascript:' . $this->getAjaxFunction(). '(); return false;')
66
+ ->setId($element->getId());
67
+
68
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
69
+ $helper = Mage::helper("createsend");
70
+
71
+ if (!$helper->isCompleteConfig($scope, $scopeId)) {
72
+ $button->setDisabled('disabled');
73
+ }
74
+
75
+ $this->_buttonHtml = $button->toHtml();
76
+
77
+ return $this->_toHtml();
78
+ }
79
+
80
+ /**
81
+ * Returns the Javascript function name for performing the Ajax call.
82
+ *
83
+ * @return string
84
+ */
85
+ public function getAjaxFunction()
86
+ {
87
+ return $this->getElement()->getId() . 'Ajax';
88
+ }
89
+
90
+ /**
91
+ * Returns the AJAX URL to test the API
92
+ *
93
+ * @return string
94
+ */
95
+ public function getAjaxUrl()
96
+ {
97
+ return $this->_ajaxUrl;
98
+ }
99
+
100
+ /**
101
+ * Returns the HTML for the custom API Test button
102
+ *
103
+ * @return string
104
+ */
105
+ public function getButtonHtml()
106
+ {
107
+ return $this->_buttonHtml;
108
+ }
109
  }
app/code/community/Campaignmonitor/Createsend/Block/CreateExampleSegments.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor Create Example Segments Button
20
- */
21
- class Campaignmonitor_Createsend_Block_CreateExampleSegments extends Campaignmonitor_Createsend_Block_AjaxButton_Abstract
22
- {
23
- protected $_urlPath = 'adminhtml/createsend_segment/createExamples';
24
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor Create Example Segments Button
20
+ */
21
+ class Campaignmonitor_Createsend_Block_CreateExampleSegments extends Campaignmonitor_Createsend_Block_AjaxButton_Abstract
22
+ {
23
+ protected $_urlPath = 'adminhtml/createsend_segment/createExamples';
24
  }
app/code/community/Campaignmonitor/Createsend/Block/Linkedattributes.php CHANGED
@@ -1,67 +1,67 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Linkedattributes extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
19
- {
20
- protected $magentoOptions;
21
-
22
- public function __construct()
23
- {
24
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
25
- $helper = Mage::helper("createsend");
26
-
27
- $this->addColumn('magento', array(
28
- 'label' => $helper->__('Magento customer attribute'),
29
- 'size' => 28,
30
- ));
31
- $this->_addAfter = false;
32
- $this->_addButtonLabel = $helper->__('Add linked attribute');
33
-
34
- parent::__construct();
35
- $this->setTemplate('campaignmonitor/createsend/system/config/form/field/array_dropdown.phtml');
36
-
37
- $options = Mage::getSingleton('createsend/config_customerAttributes')->toOptionArray();
38
- $this->magentoOptions = array();
39
- foreach ($options as $option) {
40
- $this->magentoOptions[$option['value']] = $option['label'];
41
- }
42
-
43
- asort($this->magentoOptions);
44
- }
45
-
46
- protected function _renderCellTemplate($columnName)
47
- {
48
- if (empty($this->_columns[$columnName])) {
49
- throw new Exception('Wrong column name specified.');
50
- }
51
- $column = $this->_columns[$columnName];
52
- $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
53
-
54
- if ($columnName == 'magento') {
55
- $rendered = '<select name="'.$inputName.'">';
56
- foreach ($this->magentoOptions as $att => $name) {
57
- $rendered .= '<option value="'.$att.'">'. htmlspecialchars($name) .'</option>';
58
- }
59
-
60
- $rendered .= '</select>';
61
- } else {
62
- return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' . ($column['size'] ? 'size="' . $column['size'] . '"' : '') . '/>';
63
- }
64
-
65
- return $rendered;
66
- }
67
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Linkedattributes extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
19
+ {
20
+ protected $magentoOptions;
21
+
22
+ public function __construct()
23
+ {
24
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
25
+ $helper = Mage::helper("createsend");
26
+
27
+ $this->addColumn('magento', array(
28
+ 'label' => $helper->__('Magento customer attribute'),
29
+ 'size' => 28,
30
+ ));
31
+ $this->_addAfter = false;
32
+ $this->_addButtonLabel = $helper->__('Add linked attribute');
33
+
34
+ parent::__construct();
35
+ $this->setTemplate('campaignmonitor/createsend/system/config/form/field/array_dropdown.phtml');
36
+
37
+ $options = Mage::getSingleton('createsend/config_customerAttributes')->toOptionArray();
38
+ $this->magentoOptions = array();
39
+ foreach ($options as $option) {
40
+ $this->magentoOptions[$option['value']] = $option['label'];
41
+ }
42
+
43
+ asort($this->magentoOptions);
44
+ }
45
+
46
+ protected function _renderCellTemplate($columnName)
47
+ {
48
+ if (empty($this->_columns[$columnName])) {
49
+ throw new Exception('Wrong column name specified.');
50
+ }
51
+ $column = $this->_columns[$columnName];
52
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
53
+
54
+ if ($columnName == 'magento') {
55
+ $rendered = '<select name="'.$inputName.'">';
56
+ foreach ($this->magentoOptions as $att => $name) {
57
+ $rendered .= '<option value="'.$att.'">'. htmlspecialchars($name) .'</option>';
58
+ }
59
+
60
+ $rendered .= '</select>';
61
+ } else {
62
+ return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' . ($column['size'] ? 'size="' . $column['size'] . '"' : '') . '/>';
63
+ }
64
+
65
+ return $rendered;
66
+ }
67
+ }
app/code/community/Campaignmonitor/Createsend/Block/Log/Reader.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Log_Reader extends Mage_Core_Model_Config_Data
19
- {
20
- protected function _afterLoad()
21
- {
22
- $directory = Mage::getBaseDir();
23
- $directory .= DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'log';
24
-
25
- $filename = Mage::getStoreConfig(
26
- 'createsend_general/debug/available_logs',
27
- Mage::app()->getStore()
28
- );
29
-
30
- $filename = $directory . DIRECTORY_SEPARATOR . $filename;
31
- $value = '';
32
-
33
- if (file_exists( $filename )) {
34
- $value = file_get_contents( $filename );
35
- }
36
-
37
- $this->setValue(empty($value) ? 'no data found' : $value);
38
-
39
- }
40
-
41
- protected function _beforeSave()
42
- {
43
-
44
- }
45
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Log_Reader extends Mage_Core_Model_Config_Data
19
+ {
20
+ protected function _afterLoad()
21
+ {
22
+ $directory = Mage::getBaseDir();
23
+ $directory .= DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'log';
24
+
25
+ $filename = Mage::getStoreConfig(
26
+ 'createsend_general/debug/available_logs',
27
+ Mage::app()->getStore()
28
+ );
29
+
30
+ $filename = $directory . DIRECTORY_SEPARATOR . $filename;
31
+ $value = '';
32
+
33
+ if (file_exists( $filename )) {
34
+ $value = file_get_contents( $filename );
35
+ }
36
+
37
+ $this->setValue(empty($value) ? 'no data found' : $value);
38
+
39
+ }
40
+
41
+ protected function _beforeSave()
42
+ {
43
+
44
+ }
45
  }
app/code/community/Campaignmonitor/Createsend/Block/Log/View.php CHANGED
@@ -1,51 +1,51 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor OAuth Redirect URL information.
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Block_Log_View extends Mage_Adminhtml_Block_System_Config_Form_Field
23
- {
24
- /**
25
- * Return element html
26
- *
27
- * @param Varien_Data_Form_Element_Abstract $element
28
- * @return string
29
- */
30
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
31
- {
32
-
33
- $style = '<style>';
34
- $style .= '#row_createsend_general_debug_log_content td:nth-child(2) { width: 80% }';
35
- $style .= '#createsend_general_debug_log_content { width: 95%; min-height: 20em; background:#000; color:#20ff20; font-family:Consolas; }';
36
- $style .= '#createsend_general_debug_log_content::selection { background:#0b26da; color:#fff; }';
37
- $style .= '#createsend_general_debug_log_content::-moz-selection { background:#0b26da; color:#fff; }';
38
- $style .= '</style>';
39
-
40
- $script = '<script>';
41
- $script .= 'var logViewer = document.getElementById("createsend_general_debug_log_content");';
42
- $script .= 'logViewer.onclick = function() { logViewer.focus();';
43
- $script .= 'logViewer.select(); };';
44
- $script .= '</script>';
45
-
46
- $html = $element->getAfterElementHtml();
47
- $element->setAfterElementHtml($html . $style . $script);
48
-
49
- return parent::_getElementHtml($element);
50
- }
51
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor OAuth Redirect URL information.
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Block_Log_View extends Mage_Adminhtml_Block_System_Config_Form_Field
23
+ {
24
+ /**
25
+ * Return element html
26
+ *
27
+ * @param Varien_Data_Form_Element_Abstract $element
28
+ * @return string
29
+ */
30
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
31
+ {
32
+
33
+ $style = '<style>';
34
+ $style .= '#row_createsend_general_debug_log_content td:nth-child(2) { width: 80% }';
35
+ $style .= '#createsend_general_debug_log_content { width: 95%; min-height: 20em; background:#000; color:#20ff20; font-family:Consolas; }';
36
+ $style .= '#createsend_general_debug_log_content::selection { background:#0b26da; color:#fff; }';
37
+ $style .= '#createsend_general_debug_log_content::-moz-selection { background:#0b26da; color:#fff; }';
38
+ $style .= '</style>';
39
+
40
+ $script = '<script>';
41
+ $script .= 'var logViewer = document.getElementById("createsend_general_debug_log_content");';
42
+ $script .= 'logViewer.onclick = function() { logViewer.focus();';
43
+ $script .= 'logViewer.select(); };';
44
+ $script .= '</script>';
45
+
46
+ $html = $element->getAfterElementHtml();
47
+ $element->setAfterElementHtml($html . $style . $script);
48
+
49
+ return parent::_getElementHtml($element);
50
+ }
51
  }
app/code/community/Campaignmonitor/Createsend/Block/OauthPermissionRequest.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor OAuth Permission Request Button
20
- *
21
- */
22
-
23
- class Campaignmonitor_Createsend_Block_OauthPermissionRequest extends Mage_Adminhtml_Block_System_Config_Form_Field
24
- {
25
- /**
26
- * Return element html
27
- *
28
- * @param Varien_Data_Form_Element_Abstract $element
29
- * @return string
30
- */
31
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
32
- {
33
- /** @var Mage_Core_Model_Config_Data $configData */
34
- $configData = Mage::getSingleton('adminhtml/config_data');
35
- list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')
36
- ->_getScope($configData->getWebsite(), $configData->getStore());
37
-
38
- // Redirect admin to Campaign Monitor Application Approval Page
39
-
40
- /** @var Campaignmonitor_Createsend_Model_Api $api */
41
- $api = Mage::getModel('createsend/api');
42
- $url = $api->getOauthPermissionRequestUrl($scope, $scopeId);
43
-
44
- $this->setElement($element);
45
-
46
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
47
- $helper = Mage::helper("createsend");
48
-
49
- $button = $this->getLayout()->createBlock('adminhtml/widget_button')
50
- ->setType('button')
51
- ->setLabel($element->getLabel())
52
- //->setOnClick("setLocation('$url')")
53
- ->setOnClick("popWin('$url', '_blank')")
54
- ->setId($element->getId());
55
-
56
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
57
- $scopeModel = Mage::getModel('createsend/config_scope');
58
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
59
-
60
- $clientId = $helper->getOAuthClientId($storeId);
61
- $clientSecret = $helper->getOAuthClientSecret($storeId);
62
- if (empty($clientId) || empty($clientSecret)) {
63
- // Hide if OAuth Client ID or Client Secret is blank
64
- $button->setDisabled('disabled');
65
- }
66
-
67
- return $button->toHtml();
68
- }
69
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor OAuth Permission Request Button
20
+ *
21
+ */
22
+
23
+ class Campaignmonitor_Createsend_Block_OauthPermissionRequest extends Mage_Adminhtml_Block_System_Config_Form_Field
24
+ {
25
+ /**
26
+ * Return element html
27
+ *
28
+ * @param Varien_Data_Form_Element_Abstract $element
29
+ * @return string
30
+ */
31
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
32
+ {
33
+ /** @var Mage_Core_Model_Config_Data $configData */
34
+ $configData = Mage::getSingleton('adminhtml/config_data');
35
+ list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')
36
+ ->_getScope($configData->getWebsite(), $configData->getStore());
37
+
38
+ // Redirect admin to Campaign Monitor Application Approval Page
39
+
40
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
41
+ $api = Mage::getModel('createsend/api');
42
+ $url = $api->getOauthPermissionRequestUrl($scope, $scopeId);
43
+
44
+ $this->setElement($element);
45
+
46
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
47
+ $helper = Mage::helper("createsend");
48
+
49
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
50
+ ->setType('button')
51
+ ->setLabel($element->getLabel())
52
+ //->setOnClick("setLocation('$url')")
53
+ ->setOnClick("popWin('$url', '_blank')")
54
+ ->setId($element->getId());
55
+
56
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
57
+ $scopeModel = Mage::getModel('createsend/config_scope');
58
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
59
+
60
+ $clientId = $helper->getOAuthClientId($storeId);
61
+ $clientSecret = $helper->getOAuthClientSecret($storeId);
62
+ if (empty($clientId) || empty($clientSecret)) {
63
+ // Hide if OAuth Client ID or Client Secret is blank
64
+ $button->setDisabled('disabled');
65
+ }
66
+
67
+ return $button->toHtml();
68
+ }
69
  }
app/code/community/Campaignmonitor/Createsend/Block/OauthRedirectUrl.php CHANGED
@@ -1,49 +1,49 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor OAuth Redirect URL information.
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Block_OauthRedirectUrl extends Mage_Adminhtml_Block_System_Config_Form_Field
23
- {
24
- /**
25
- * Return element html
26
- *
27
- * @param Varien_Data_Form_Element_Abstract $element
28
- * @return string
29
- */
30
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
31
- {
32
- /** @var Mage_Core_Model_Config_Data $configData */
33
- $configData = Mage::getSingleton('adminhtml/config_data');
34
- list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')
35
- ->_getScope($configData->getWebsite(), $configData->getStore());
36
-
37
- /** @var Campaignmonitor_Createsend_Model_Api $api */
38
- $api = Mage::getModel('createsend/api');
39
- $url = $api->getOauthRedirectUri($scope, $scopeId);
40
-
41
- $element->setValue($url);
42
-
43
- // Add a hidden input field to get <depends> working
44
- $html = $element->getAfterElementHtml();
45
- $element->setAfterElementHtml($html . sprintf('<input id="%s" type="hidden" value=""/>', $element->getId()));
46
-
47
- return parent::_getElementHtml($element);
48
- }
49
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor OAuth Redirect URL information.
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Block_OauthRedirectUrl extends Mage_Adminhtml_Block_System_Config_Form_Field
23
+ {
24
+ /**
25
+ * Return element html
26
+ *
27
+ * @param Varien_Data_Form_Element_Abstract $element
28
+ * @return string
29
+ */
30
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
31
+ {
32
+ /** @var Mage_Core_Model_Config_Data $configData */
33
+ $configData = Mage::getSingleton('adminhtml/config_data');
34
+ list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')
35
+ ->_getScope($configData->getWebsite(), $configData->getStore());
36
+
37
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
38
+ $api = Mage::getModel('createsend/api');
39
+ $url = $api->getOauthRedirectUri($scope, $scopeId);
40
+
41
+ $element->setValue($url);
42
+
43
+ // Add a hidden input field to get <depends> working
44
+ $html = $element->getAfterElementHtml();
45
+ $element->setAfterElementHtml($html . sprintf('<input id="%s" type="hidden" value=""/>', $element->getId()));
46
+
47
+ return parent::_getElementHtml($element);
48
+ }
49
  }
app/code/community/Campaignmonitor/Createsend/Block/TestApi.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor Test API Button
20
- */
21
- class Campaignmonitor_Createsend_Block_TestApi extends Campaignmonitor_Createsend_Block_AjaxButton_Abstract
22
- {
23
- protected $_urlPath = 'adminhtml/createsend_api/test';
24
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor Test API Button
20
+ */
21
+ class Campaignmonitor_Createsend_Block_TestApi extends Campaignmonitor_Createsend_Block_AjaxButton_Abstract
22
+ {
23
+ protected $_urlPath = 'adminhtml/createsend_api/test';
24
  }
app/code/community/Campaignmonitor/Createsend/Block/Version.php CHANGED
@@ -1,34 +1,34 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor OAuth Redirect URL information.
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Block_Version extends Mage_Adminhtml_Block_System_Config_Form_Field
23
- {
24
-
25
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
26
- {
27
- return $this->getExtensionVersion();
28
- }
29
-
30
- public function getExtensionVersion()
31
- {
32
- return (string) Mage::getConfig()->getNode()->modules->Campaignmonitor_Createsend->version;
33
- }
34
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor OAuth Redirect URL information.
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Block_Version extends Mage_Adminhtml_Block_System_Config_Form_Field
23
+ {
24
+
25
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
26
+ {
27
+ return $this->getExtensionVersion();
28
+ }
29
+
30
+ public function getExtensionVersion()
31
+ {
32
+ return (string) Mage::getConfig()->getNode()->modules->Campaignmonitor_Createsend->version;
33
+ }
34
  }
app/code/community/Campaignmonitor/Createsend/Block/Wishlistattributes.php CHANGED
@@ -1,66 +1,66 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Block_Wishlistattributes extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
19
- {
20
- protected $magentoOptions;
21
-
22
- public function __construct()
23
- {
24
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
25
- $helper = Mage::helper("createsend");
26
-
27
- $this->addColumn('magento', array(
28
- 'label' => $helper->__('Product attribute'),
29
- 'size' => 28,
30
- ));
31
- $this->_addAfter = false;
32
- $this->_addButtonLabel = $helper->__('Add product attribute');
33
-
34
- parent::__construct();
35
- $this->setTemplate('campaignmonitor/createsend/system/config/form/field/array_dropdown.phtml');
36
-
37
- $options = Mage::getSingleton('createsend/config_productAttributes')->toOptionArray();
38
- $this->magentoOptions = array();
39
- foreach ($options as $option) {
40
- $this->magentoOptions[$option['value']] = $option['label'];
41
- }
42
-
43
- asort($this->magentoOptions);
44
- }
45
-
46
- protected function _renderCellTemplate($columnName)
47
- {
48
- if (empty($this->_columns[$columnName])) {
49
- throw new Exception('Wrong column name specified.');
50
- }
51
- $column = $this->_columns[$columnName];
52
- $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
53
-
54
- if ($columnName == 'magento') {
55
- $rendered = '<select name="'.$inputName.'">';
56
- foreach ($this->magentoOptions as $att => $name) {
57
- $rendered .= '<option value="'.$att.'">'.$name.'</option>';
58
- }
59
- $rendered .= '</select>';
60
- } else {
61
- return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' . ($column['size'] ? 'size="' . $column['size'] . '"' : '') . '/>';
62
- }
63
-
64
- return $rendered;
65
- }
66
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Block_Wishlistattributes extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
19
+ {
20
+ protected $magentoOptions;
21
+
22
+ public function __construct()
23
+ {
24
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
25
+ $helper = Mage::helper("createsend");
26
+
27
+ $this->addColumn('magento', array(
28
+ 'label' => $helper->__('Product attribute'),
29
+ 'size' => 28,
30
+ ));
31
+ $this->_addAfter = false;
32
+ $this->_addButtonLabel = $helper->__('Add product attribute');
33
+
34
+ parent::__construct();
35
+ $this->setTemplate('campaignmonitor/createsend/system/config/form/field/array_dropdown.phtml');
36
+
37
+ $options = Mage::getSingleton('createsend/config_productAttributes')->toOptionArray();
38
+ $this->magentoOptions = array();
39
+ foreach ($options as $option) {
40
+ $this->magentoOptions[$option['value']] = $option['label'];
41
+ }
42
+
43
+ asort($this->magentoOptions);
44
+ }
45
+
46
+ protected function _renderCellTemplate($columnName)
47
+ {
48
+ if (empty($this->_columns[$columnName])) {
49
+ throw new Exception('Wrong column name specified.');
50
+ }
51
+ $column = $this->_columns[$columnName];
52
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
53
+
54
+ if ($columnName == 'magento') {
55
+ $rendered = '<select name="'.$inputName.'">';
56
+ foreach ($this->magentoOptions as $att => $name) {
57
+ $rendered .= '<option value="'.$att.'">'.$name.'</option>';
58
+ }
59
+ $rendered .= '</select>';
60
+ } else {
61
+ return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' . ($column['size'] ? 'size="' . $column['size'] . '"' : '') . '/>';
62
+ }
63
+
64
+ return $rendered;
65
+ }
66
+ }
app/code/community/Campaignmonitor/Createsend/Helper/Api.php CHANGED
@@ -1,255 +1,255 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Helper_Api extends Mage_Core_Helper_Abstract
19
- {
20
- const MAX_CM_SUBSCRIBER_IMPORT = 1000;
21
- const LABEL_SELECT_CLIENT = 'Select Client...';
22
- const LABEL_CREATE_NEW_LIST = 'Create a new list in Campaign Monitor';
23
- const LABEL_ENTER_YOUR_API_KEY = 'Enter your API Key';
24
- const ID_CREATE_NEW_LIST = 'NEW_LIST';
25
-
26
- /**
27
- * Gets all the Campaign Monitor clients for the given scope/scopeId for use in an HTML select.
28
- * The first option will be a 'Select Client...' prompt.
29
- *
30
- * On API Error, returns a single element array with key 'value' => 'error'
31
- *
32
- * @param string $scope
33
- * @param int $scopeId
34
- * @return array|null
35
- */
36
- public function getClients($scope, $scopeId)
37
- {
38
- /** @var $api Campaignmonitor_Createsend_Model_Api */
39
- $api = Mage::getModel('createsend/api');
40
-
41
- $reply = $api->call(
42
- Zend_Http_Client::GET,
43
- "clients",
44
- array(),
45
- array(),
46
- $scope,
47
- $scopeId
48
- );
49
-
50
- $clients = array();
51
- if ($reply['success'] === false) {
52
- Mage::helper('createsend')->log($reply);
53
-
54
- $clients[] = array(
55
- 'value' => 'error',
56
- 'label' => self::LABEL_ENTER_YOUR_API_KEY,
57
- 'message' => sprintf($api::ERR_API_REQUEST, $reply['data']['Message'])
58
- );
59
- } else {
60
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
61
- $helper = Mage::helper('createsend');
62
-
63
- $clients[] = array(
64
- 'value' => '',
65
- 'label' => $helper->__(self::LABEL_SELECT_CLIENT)
66
- );
67
-
68
- foreach ($reply['data'] as $client) {
69
- $clients[] = array(
70
- 'value' => $client['ClientID'],
71
- 'label' => $client['Name']
72
- );
73
- }
74
- }
75
-
76
- return $clients;
77
- }
78
-
79
- /**
80
- * Gets all the Campaign Monitor subscriber lists for the given clientId
81
- * using credentials from given scope/scopeId for use in an HTML select.
82
- * The last option will be a 'Create a new list' option
83
- *
84
- * On API Error, returns a single element array with key 'value' => 'error'
85
- *
86
- * @param string $clientId
87
- * @param string $scope
88
- * @param int $scopeId
89
- * @return array|null
90
- */
91
- public function getLists($clientId, $scope, $scopeId)
92
- {
93
- /** @var $api Campaignmonitor_Createsend_Model_Api */
94
- $api = Mage::getModel('createsend/api');
95
-
96
- $reply = $api->call(
97
- Zend_Http_Client::GET,
98
- "clients/${clientId}/lists",
99
- array(),
100
- array(),
101
- $scope,
102
- $scopeId
103
- );
104
-
105
- $lists = array();
106
- if ($reply['success'] === false) {
107
- Mage::helper('createsend')->log($reply);
108
-
109
- $lists[] = array(
110
- 'value' => 'error',
111
- 'label' => self::LABEL_ENTER_YOUR_API_KEY,
112
- 'message' => sprintf($api::ERR_API_REQUEST, $reply['data']['Message'])
113
- );
114
- } else {
115
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
116
- $helper = Mage::helper('createsend');
117
-
118
- foreach ($reply['data'] as $client) {
119
- $lists[] = array(
120
- 'value' => $client['ListID'],
121
- 'label' => $client['Name']
122
- );
123
- }
124
-
125
- $lists[] = array(
126
- 'value' => self::ID_CREATE_NEW_LIST,
127
- 'label' => $helper->__(self::LABEL_CREATE_NEW_LIST)
128
- );
129
- }
130
-
131
- return $lists;
132
- }
133
-
134
- /**
135
- * Tests the API Key by getting the list of clients.
136
- *
137
- * @param string $scope
138
- * @param int $scopeId
139
- * @return array|null
140
- */
141
- public function testApiKey($scope, $scopeId)
142
- {
143
- /** @var $api Campaignmonitor_Createsend_Model_Api */
144
- $api = Mage::getModel('createsend/api');
145
-
146
- $reply = $api->call(
147
- Zend_Http_Client::GET,
148
- "clients",
149
- array(),
150
- array(),
151
- $scope,
152
- $scopeId
153
- );
154
-
155
- return $reply;
156
- }
157
-
158
- /**
159
- * Lists all Magento subscribers and returns the list in an array compatible with
160
- * the Campaign Monitor API.
161
- *
162
- * @param int $storeId
163
- * @return array
164
- */
165
- public function getSubscribers($storeId)
166
- {
167
- $listData = array();
168
-
169
- /** @var Mage_Newsletter_Model_Subscriber $subscribers */
170
- $subscribers = Mage::getModel('newsletter/subscriber');
171
-
172
- $collection = $subscribers->getCollection()
173
- ->addFieldToFilter('store_id', $storeId)
174
- ->addFieldToFilter('subscriber_status', Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
175
-
176
- /** @var Mage_Newsletter_Model_Subscriber $subscriber */
177
- foreach ($collection as $subscriber) {
178
- $email = $subscriber->getSubscriberEmail();
179
-
180
- $subscriberData['Name'] = "";
181
- $subscriberData['CustomFields'] = Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($subscriber);
182
- $subscriberData['EmailAddress'] = $email;
183
-
184
- $websiteId = Mage::app()->getStore($subscriber->getStoreId())->getWebsiteId();
185
-
186
- /* @var Mage_Customer_Model_Customer $customer */
187
- $customer = Mage::getModel("customer/customer")
188
- ->setWebsiteId($websiteId)
189
- ->loadByEmail($email);
190
-
191
- if ($customer->getId()) {
192
- $subscriberData['Name'] = $customer->getName();
193
-
194
- $subscriberData['CustomFields'] =
195
- Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customer);
196
-
197
- }
198
-
199
- $listData[] = $subscriberData;
200
- }
201
-
202
- return $listData;
203
- }
204
-
205
- /**
206
- * Performs an initial full subscriber sync from Magento to Campaign Monitor
207
- * for a particular store. The check for already synchronized list should be
208
- * done by the caller.
209
- *
210
- * @param $storeId
211
- * @return array|bool|null
212
- */
213
- function performFullSync($storeId)
214
- {
215
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
216
- $helper = Mage::helper('createsend');
217
-
218
- Mage::log( 'performing full sync', null, 'fullsync.log', true );
219
- $listId = $helper->getListId($storeId);
220
- $scope = 'stores';
221
- $scopeId = $storeId;
222
-
223
- /** @var Campaignmonitor_Createsend_Helper_Api $apiHelper */
224
- $apiHelper = Mage::helper('createsend/api');
225
-
226
- $listData = $apiHelper->getSubscribers($storeId);
227
-
228
- /** @var $api Campaignmonitor_Createsend_Model_Api */
229
- $api = Mage::getModel('createsend/api');
230
-
231
- $index = 0;
232
- do {
233
- $partialData = array_slice($listData, $index * self::MAX_CM_SUBSCRIBER_IMPORT, self::MAX_CM_SUBSCRIBER_IMPORT);
234
- $reply = $api->call(
235
- Zend_Http_Client::POST,
236
- "subscribers/{$listId}/import",
237
- array(
238
- 'Subscribers' => $partialData,
239
- 'Resubscribe' => false,
240
- 'QueueSubscriptionBasedAutoResponders' => false,
241
- 'RestartSubscriptionBasedAutoresponders' => true
242
- ),
243
- array(),
244
- $scope,
245
- $scopeId
246
- );
247
- } while (
248
- $reply['success'] !== false
249
- &&
250
- count($listData) > (($index++ * self::MAX_CM_SUBSCRIBER_IMPORT) + self::MAX_CM_SUBSCRIBER_IMPORT)
251
- );
252
-
253
- return $reply;
254
- }
255
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Helper_Api extends Mage_Core_Helper_Abstract
19
+ {
20
+ const MAX_CM_SUBSCRIBER_IMPORT = 1000;
21
+ const LABEL_SELECT_CLIENT = 'Select Client...';
22
+ const LABEL_CREATE_NEW_LIST = 'Create a new list in Campaign Monitor';
23
+ const LABEL_ENTER_YOUR_API_KEY = 'Enter your API Key';
24
+ const ID_CREATE_NEW_LIST = 'NEW_LIST';
25
+
26
+ /**
27
+ * Gets all the Campaign Monitor clients for the given scope/scopeId for use in an HTML select.
28
+ * The first option will be a 'Select Client...' prompt.
29
+ *
30
+ * On API Error, returns a single element array with key 'value' => 'error'
31
+ *
32
+ * @param string $scope
33
+ * @param int $scopeId
34
+ * @return array|null
35
+ */
36
+ public function getClients($scope, $scopeId)
37
+ {
38
+ /** @var $api Campaignmonitor_Createsend_Model_Api */
39
+ $api = Mage::getModel('createsend/api');
40
+
41
+ $reply = $api->call(
42
+ Zend_Http_Client::GET,
43
+ "clients",
44
+ array(),
45
+ array(),
46
+ $scope,
47
+ $scopeId
48
+ );
49
+
50
+ $clients = array();
51
+ if ($reply['success'] === false) {
52
+ Mage::helper('createsend')->log($reply);
53
+
54
+ $clients[] = array(
55
+ 'value' => 'error',
56
+ 'label' => self::LABEL_ENTER_YOUR_API_KEY,
57
+ 'message' => sprintf($api::ERR_API_REQUEST, $reply['data']['Message'])
58
+ );
59
+ } else {
60
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
61
+ $helper = Mage::helper('createsend');
62
+
63
+ $clients[] = array(
64
+ 'value' => '',
65
+ 'label' => $helper->__(self::LABEL_SELECT_CLIENT)
66
+ );
67
+
68
+ foreach ($reply['data'] as $client) {
69
+ $clients[] = array(
70
+ 'value' => $client['ClientID'],
71
+ 'label' => $client['Name']
72
+ );
73
+ }
74
+ }
75
+
76
+ return $clients;
77
+ }
78
+
79
+ /**
80
+ * Gets all the Campaign Monitor subscriber lists for the given clientId
81
+ * using credentials from given scope/scopeId for use in an HTML select.
82
+ * The last option will be a 'Create a new list' option
83
+ *
84
+ * On API Error, returns a single element array with key 'value' => 'error'
85
+ *
86
+ * @param string $clientId
87
+ * @param string $scope
88
+ * @param int $scopeId
89
+ * @return array|null
90
+ */
91
+ public function getLists($clientId, $scope, $scopeId)
92
+ {
93
+ /** @var $api Campaignmonitor_Createsend_Model_Api */
94
+ $api = Mage::getModel('createsend/api');
95
+
96
+ $reply = $api->call(
97
+ Zend_Http_Client::GET,
98
+ "clients/${clientId}/lists",
99
+ array(),
100
+ array(),
101
+ $scope,
102
+ $scopeId
103
+ );
104
+
105
+ $lists = array();
106
+ if ($reply['success'] === false) {
107
+ Mage::helper('createsend')->log($reply);
108
+
109
+ $lists[] = array(
110
+ 'value' => 'error',
111
+ 'label' => self::LABEL_ENTER_YOUR_API_KEY,
112
+ 'message' => sprintf($api::ERR_API_REQUEST, $reply['data']['Message'])
113
+ );
114
+ } else {
115
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
116
+ $helper = Mage::helper('createsend');
117
+
118
+ foreach ($reply['data'] as $client) {
119
+ $lists[] = array(
120
+ 'value' => $client['ListID'],
121
+ 'label' => $client['Name']
122
+ );
123
+ }
124
+
125
+ $lists[] = array(
126
+ 'value' => self::ID_CREATE_NEW_LIST,
127
+ 'label' => $helper->__(self::LABEL_CREATE_NEW_LIST)
128
+ );
129
+ }
130
+
131
+ return $lists;
132
+ }
133
+
134
+ /**
135
+ * Tests the API Key by getting the list of clients.
136
+ *
137
+ * @param string $scope
138
+ * @param int $scopeId
139
+ * @return array|null
140
+ */
141
+ public function testApiKey($scope, $scopeId)
142
+ {
143
+ /** @var $api Campaignmonitor_Createsend_Model_Api */
144
+ $api = Mage::getModel('createsend/api');
145
+
146
+ $reply = $api->call(
147
+ Zend_Http_Client::GET,
148
+ "clients",
149
+ array(),
150
+ array(),
151
+ $scope,
152
+ $scopeId
153
+ );
154
+
155
+ return $reply;
156
+ }
157
+
158
+ /**
159
+ * Lists all Magento subscribers and returns the list in an array compatible with
160
+ * the Campaign Monitor API.
161
+ *
162
+ * @param int $storeId
163
+ * @return array
164
+ */
165
+ public function getSubscribers($storeId)
166
+ {
167
+ $listData = array();
168
+
169
+ /** @var Mage_Newsletter_Model_Subscriber $subscribers */
170
+ $subscribers = Mage::getModel('newsletter/subscriber');
171
+
172
+ $collection = $subscribers->getCollection()
173
+ ->addFieldToFilter('store_id', $storeId)
174
+ ->addFieldToFilter('subscriber_status', Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
175
+
176
+ /** @var Mage_Newsletter_Model_Subscriber $subscriber */
177
+ foreach ($collection as $subscriber) {
178
+ $email = $subscriber->getSubscriberEmail();
179
+
180
+ $subscriberData['Name'] = "";
181
+ $subscriberData['CustomFields'] = Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($subscriber);
182
+ $subscriberData['EmailAddress'] = $email;
183
+
184
+ $websiteId = Mage::app()->getStore($subscriber->getStoreId())->getWebsiteId();
185
+
186
+ /* @var Mage_Customer_Model_Customer $customer */
187
+ $customer = Mage::getModel("customer/customer")
188
+ ->setWebsiteId($websiteId)
189
+ ->loadByEmail($email);
190
+
191
+ if ($customer->getId()) {
192
+ $subscriberData['Name'] = $customer->getName();
193
+
194
+ $subscriberData['CustomFields'] =
195
+ Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customer);
196
+
197
+ }
198
+
199
+ $listData[] = $subscriberData;
200
+ }
201
+
202
+ return $listData;
203
+ }
204
+
205
+ /**
206
+ * Performs an initial full subscriber sync from Magento to Campaign Monitor
207
+ * for a particular store. The check for already synchronized list should be
208
+ * done by the caller.
209
+ *
210
+ * @param $storeId
211
+ * @return array|bool|null
212
+ */
213
+ function performFullSync($storeId)
214
+ {
215
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
216
+ $helper = Mage::helper('createsend');
217
+
218
+ Mage::log( 'performing full sync', null, 'fullsync.log', true );
219
+ $listId = $helper->getListId($storeId);
220
+ $scope = 'stores';
221
+ $scopeId = $storeId;
222
+
223
+ /** @var Campaignmonitor_Createsend_Helper_Api $apiHelper */
224
+ $apiHelper = Mage::helper('createsend/api');
225
+
226
+ $listData = $apiHelper->getSubscribers($storeId);
227
+
228
+ /** @var $api Campaignmonitor_Createsend_Model_Api */
229
+ $api = Mage::getModel('createsend/api');
230
+
231
+ $index = 0;
232
+ do {
233
+ $partialData = array_slice($listData, $index * self::MAX_CM_SUBSCRIBER_IMPORT, self::MAX_CM_SUBSCRIBER_IMPORT);
234
+ $reply = $api->call(
235
+ Zend_Http_Client::POST,
236
+ "subscribers/{$listId}/import",
237
+ array(
238
+ 'Subscribers' => $partialData,
239
+ 'Resubscribe' => false,
240
+ 'QueueSubscriptionBasedAutoResponders' => false,
241
+ 'RestartSubscriptionBasedAutoresponders' => true
242
+ ),
243
+ array(),
244
+ $scope,
245
+ $scopeId
246
+ );
247
+ } while (
248
+ $reply['success'] !== false
249
+ &&
250
+ count($listData) > (($index++ * self::MAX_CM_SUBSCRIBER_IMPORT) + self::MAX_CM_SUBSCRIBER_IMPORT)
251
+ );
252
+
253
+ return $reply;
254
+ }
255
  }
app/code/community/Campaignmonitor/Createsend/Helper/Config.php CHANGED
@@ -1,204 +1,204 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Helper_Config extends Mage_Core_Helper_Abstract
19
- {
20
- const FLAG_STATUS_NEW = 'new';
21
- const FLAG_STATUS_PROCESSING = 'processing';
22
- const FLAG_STATUS_DONE = 'done';
23
-
24
- const FLAG_PROCESS_RUNNING = 'running';
25
- const FLAG_PROCESS_STOPPED = 'stopped';
26
-
27
- const INDEX_INITIAL_SYNC = 'initialSync';
28
- const INDEX_CUSTOM_FIELDS = 'customFields';
29
- const INDEX_EXAMPLE_SEGMENTS = 'exampleSegments';
30
-
31
- /**
32
- * Adds the default customer and product attributes to the magento configuration setting for this scope.
33
- * Returns the number of attributes added.
34
- *
35
- * @param string $scope
36
- * @param int $scopeId
37
- * @return int
38
- */
39
- function createDefaultCustomFields($scope, $scopeId)
40
- {
41
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
42
- $helper = Mage::helper('createsend');
43
-
44
- /** @var Campaignmonitor_Createsend_Model_Config_DefaultCustomFields $defaultSource */
45
- $defaultSource = Mage::getSingleton('createsend/config_defaultCustomFields');
46
-
47
- $linkedAttributes = @unserialize(
48
- $helper->getScopedConfig(
49
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_M_TO_CM_ATTRIBUTES,
50
- $scope,
51
- $scopeId
52
- )
53
- );
54
- $defaultCustomerAttributes = $defaultSource->getDefaultCustomerAttributes();
55
- $newLinkedAttributes = $this->addDefaultAttributes($linkedAttributes, $defaultCustomerAttributes);
56
- Mage::getConfig()->saveConfig(
57
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_M_TO_CM_ATTRIBUTES,
58
- @serialize($newLinkedAttributes),
59
- $scope,
60
- $scopeId
61
- );
62
-
63
- $productAttributes = @unserialize(
64
- $helper->getScopedConfig(
65
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES,
66
- $scope,
67
- $scopeId
68
- )
69
- );
70
- $defaultProductAttributes = $defaultSource->getDefaultProductAttributes();
71
- $newProductAttributes = $this->addDefaultAttributes($productAttributes, $defaultProductAttributes);
72
- Mage::getConfig()->saveConfig(
73
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES,
74
- @serialize($newProductAttributes),
75
- $scope,
76
- $scopeId
77
- );
78
-
79
- $oldCount = count($linkedAttributes) + count($productAttributes);
80
- $newCount = count($newLinkedAttributes) + count($newProductAttributes);
81
-
82
- return ($newCount - $oldCount);
83
- }
84
-
85
- /**
86
- * Returns the duplicate custom attributes (if any).
87
- * Returns an empty array if no duplicate custom attributes found.
88
- *
89
- * @param string $configPath The system configuration path for the attributes
90
- * @param string $scope
91
- * @param int $scopeId
92
- * @return array
93
- */
94
- function getDuplicateAttributes($configPath, $scope, $scopeId)
95
- {
96
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
97
- $helper = Mage::helper('createsend');
98
-
99
- $duplicateAttributes = array();
100
-
101
- $customerAttributes = @unserialize(
102
- $helper->getScopedConfig(
103
- $configPath,
104
- $scope,
105
- $scopeId
106
- )
107
- );
108
-
109
- $usedAttributes = array();
110
- foreach ($customerAttributes as $attr) {
111
- $value = $attr['magento'];
112
-
113
- if (in_array($value, $usedAttributes)) {
114
- // Already used, add it to the duplicate list
115
- $duplicateAttributes[] = $value;
116
- } else {
117
- $usedAttributes[] = $value;
118
- }
119
- }
120
-
121
- return $duplicateAttributes;
122
- }
123
-
124
- /**
125
- * Adds values from $defaultAttributes into $attributes if not yet in array
126
- *
127
- * @param array $attributes
128
- * @param array $defaultAttributes
129
- * @return array
130
- */
131
- protected function addDefaultAttributes($attributes, $defaultAttributes)
132
- {
133
- if (!is_array($attributes)) {
134
- $attributes = array();
135
- }
136
-
137
- foreach ($defaultAttributes as $attr) {
138
- $addAttribute = array('magento' => $attr);
139
- if (in_array($addAttribute, $attributes) === FALSE) {
140
- $attributes[] = $addAttribute;
141
- }
142
- }
143
-
144
- return $attributes;
145
- }
146
-
147
- /**
148
- * Loads the flag given the flag class.
149
- *
150
- * @param string $flagClass
151
- * @return Mage_Core_Model_Flag
152
- */
153
- protected function loadFlag($flagClass)
154
- {
155
- /** @var Mage_Core_Model_Flag $flagModel */
156
- $flagModel = Mage::getModel($flagClass);
157
- $flagModel->loadSelf();
158
-
159
- return $flagModel;
160
- }
161
-
162
- /**
163
- * Adds data to the flag with an index key. Existing data for the key will be overwritten.
164
- * Data for other keys will remain untouched.
165
- *
166
- * @param string $flagClass
167
- * @param string $key
168
- * @param string $listData
169
- * @throws Exception
170
- */
171
- public function addFlagData($flagClass, $key, $listData)
172
- {
173
- $flagModel = $this->loadFlag($flagClass);
174
-
175
- /** @var array $flagData */
176
- $flagData = $flagModel->getFlagData();
177
- if ($flagData === null) {
178
- $flagData = array();
179
- }
180
- $flagData[$key] = $listData;
181
-
182
- $flagModel->setFlagData($flagData)->save();
183
- }
184
-
185
- /**
186
- * Retrieves flag data given the flag class and the index key.
187
- *
188
- * @param string $flagClass
189
- * @param string $key
190
- * @return mixed
191
- */
192
- public function getFlagData($flagClass, $key)
193
- {
194
- $flagModel = $this->loadFlag($flagClass);
195
-
196
- $flagData = $flagModel->getFlagData();
197
-
198
- if (is_array($flagData) && array_key_exists($key, $flagData)) {
199
- return $flagData[$key];
200
- } else {
201
- return FALSE;
202
- }
203
- }
204
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Helper_Config extends Mage_Core_Helper_Abstract
19
+ {
20
+ const FLAG_STATUS_NEW = 'new';
21
+ const FLAG_STATUS_PROCESSING = 'processing';
22
+ const FLAG_STATUS_DONE = 'done';
23
+
24
+ const FLAG_PROCESS_RUNNING = 'running';
25
+ const FLAG_PROCESS_STOPPED = 'stopped';
26
+
27
+ const INDEX_INITIAL_SYNC = 'initialSync';
28
+ const INDEX_CUSTOM_FIELDS = 'customFields';
29
+ const INDEX_EXAMPLE_SEGMENTS = 'exampleSegments';
30
+
31
+ /**
32
+ * Adds the default customer and product attributes to the magento configuration setting for this scope.
33
+ * Returns the number of attributes added.
34
+ *
35
+ * @param string $scope
36
+ * @param int $scopeId
37
+ * @return int
38
+ */
39
+ function createDefaultCustomFields($scope, $scopeId)
40
+ {
41
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
42
+ $helper = Mage::helper('createsend');
43
+
44
+ /** @var Campaignmonitor_Createsend_Model_Config_DefaultCustomFields $defaultSource */
45
+ $defaultSource = Mage::getSingleton('createsend/config_defaultCustomFields');
46
+
47
+ $linkedAttributes = @unserialize(
48
+ $helper->getScopedConfig(
49
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_M_TO_CM_ATTRIBUTES,
50
+ $scope,
51
+ $scopeId
52
+ )
53
+ );
54
+ $defaultCustomerAttributes = $defaultSource->getDefaultCustomerAttributes();
55
+ $newLinkedAttributes = $this->addDefaultAttributes($linkedAttributes, $defaultCustomerAttributes);
56
+ Mage::getConfig()->saveConfig(
57
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_M_TO_CM_ATTRIBUTES,
58
+ @serialize($newLinkedAttributes),
59
+ $scope,
60
+ $scopeId
61
+ );
62
+
63
+ $productAttributes = @unserialize(
64
+ $helper->getScopedConfig(
65
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES,
66
+ $scope,
67
+ $scopeId
68
+ )
69
+ );
70
+ $defaultProductAttributes = $defaultSource->getDefaultProductAttributes();
71
+ $newProductAttributes = $this->addDefaultAttributes($productAttributes, $defaultProductAttributes);
72
+ Mage::getConfig()->saveConfig(
73
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES,
74
+ @serialize($newProductAttributes),
75
+ $scope,
76
+ $scopeId
77
+ );
78
+
79
+ $oldCount = count($linkedAttributes) + count($productAttributes);
80
+ $newCount = count($newLinkedAttributes) + count($newProductAttributes);
81
+
82
+ return ($newCount - $oldCount);
83
+ }
84
+
85
+ /**
86
+ * Returns the duplicate custom attributes (if any).
87
+ * Returns an empty array if no duplicate custom attributes found.
88
+ *
89
+ * @param string $configPath The system configuration path for the attributes
90
+ * @param string $scope
91
+ * @param int $scopeId
92
+ * @return array
93
+ */
94
+ function getDuplicateAttributes($configPath, $scope, $scopeId)
95
+ {
96
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
97
+ $helper = Mage::helper('createsend');
98
+
99
+ $duplicateAttributes = array();
100
+
101
+ $customerAttributes = @unserialize(
102
+ $helper->getScopedConfig(
103
+ $configPath,
104
+ $scope,
105
+ $scopeId
106
+ )
107
+ );
108
+
109
+ $usedAttributes = array();
110
+ foreach ($customerAttributes as $attr) {
111
+ $value = $attr['magento'];
112
+
113
+ if (in_array($value, $usedAttributes)) {
114
+ // Already used, add it to the duplicate list
115
+ $duplicateAttributes[] = $value;
116
+ } else {
117
+ $usedAttributes[] = $value;
118
+ }
119
+ }
120
+
121
+ return $duplicateAttributes;
122
+ }
123
+
124
+ /**
125
+ * Adds values from $defaultAttributes into $attributes if not yet in array
126
+ *
127
+ * @param array $attributes
128
+ * @param array $defaultAttributes
129
+ * @return array
130
+ */
131
+ protected function addDefaultAttributes($attributes, $defaultAttributes)
132
+ {
133
+ if (!is_array($attributes)) {
134
+ $attributes = array();
135
+ }
136
+
137
+ foreach ($defaultAttributes as $attr) {
138
+ $addAttribute = array('magento' => $attr);
139
+ if (in_array($addAttribute, $attributes) === FALSE) {
140
+ $attributes[] = $addAttribute;
141
+ }
142
+ }
143
+
144
+ return $attributes;
145
+ }
146
+
147
+ /**
148
+ * Loads the flag given the flag class.
149
+ *
150
+ * @param string $flagClass
151
+ * @return Mage_Core_Model_Flag
152
+ */
153
+ protected function loadFlag($flagClass)
154
+ {
155
+ /** @var Mage_Core_Model_Flag $flagModel */
156
+ $flagModel = Mage::getModel($flagClass);
157
+ $flagModel->loadSelf();
158
+
159
+ return $flagModel;
160
+ }
161
+
162
+ /**
163
+ * Adds data to the flag with an index key. Existing data for the key will be overwritten.
164
+ * Data for other keys will remain untouched.
165
+ *
166
+ * @param string $flagClass
167
+ * @param string $key
168
+ * @param string $listData
169
+ * @throws Exception
170
+ */
171
+ public function addFlagData($flagClass, $key, $listData)
172
+ {
173
+ $flagModel = $this->loadFlag($flagClass);
174
+
175
+ /** @var array $flagData */
176
+ $flagData = $flagModel->getFlagData();
177
+ if ($flagData === null) {
178
+ $flagData = array();
179
+ }
180
+ $flagData[$key] = $listData;
181
+
182
+ $flagModel->setFlagData($flagData)->save();
183
+ }
184
+
185
+ /**
186
+ * Retrieves flag data given the flag class and the index key.
187
+ *
188
+ * @param string $flagClass
189
+ * @param string $key
190
+ * @return mixed
191
+ */
192
+ public function getFlagData($flagClass, $key)
193
+ {
194
+ $flagModel = $this->loadFlag($flagClass);
195
+
196
+ $flagData = $flagModel->getFlagData();
197
+
198
+ if (is_array($flagData) && array_key_exists($key, $flagData)) {
199
+ return $flagData[$key];
200
+ } else {
201
+ return FALSE;
202
+ }
203
+ }
204
+ }
app/code/community/Campaignmonitor/Createsend/Helper/Data.php CHANGED
@@ -1,452 +1,452 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Helper_Data extends Mage_Core_Helper_Data
19
- {
20
- const LOGFILE = "campaignmonitor_createsend.log";
21
-
22
- const XML_PATH_WEBHOOK_ID = 'createsend_general/api/webhook_id';
23
- const XML_PATH_LIST_ID = 'createsend_general/api/list_id';
24
- const XML_PATH_NEW_LIST_NAME = 'createsend_general/api/new_list_name';
25
- const XML_PATH_AUTHENTICATION_METHOD = 'createsend_general/api/authentication_method';
26
- const XML_PATH_API_ID = 'createsend_general/api/api_key';
27
- const XML_PATH_API_CLIENT_ID = 'createsend_general/api/api_client_id';
28
- const XML_PATH_OAUTH_CLIENT_ID = 'createsend_general/api/oauth_client_id';
29
- const XML_PATH_OAUTH_CLIENT_SECRET = 'createsend_general/api/oauth_client_secret';
30
- const XML_PATH_MAX_WISHLIST_ITEMS = 'createsend_customers/wishlists/max_wishlist_items';
31
- const XML_PATH_WEBHOOK_ENABLED = 'createsend_general/advanced/webhook_enabled';
32
- const XML_PATH_OAUTH_ACCESS_TOKEN = 'createsend_general/api/oauth_access_token';
33
- const XML_PATH_OAUTH_ACCESS_TOKEN_EXPIRY_DATE = 'createsend_general/api/oauth_access_token_expiry_date';
34
- const XML_PATH_OAUTH_REFRESH_TOKEN = 'createsend_general/api/oauth_refresh_token';
35
- const XML_PATH_TRANSACTIONAL_EMAIL_ENABLED = 'createsend_transactional/emails/transactional_email_enabled';
36
- const XML_PATH_EMAIL_RETENTION_DAYS = 'createsend_transactional/emails/transactional_email_retention_days';
37
- const XML_PATH_SUBSCRIBER_SYNC_ENABLED = 'createsend_general/advanced/subscriber_synchronisation_enabled';
38
- const XML_PATH_SUBSCRIBER_SYNC_RESOLUTION_METHOD = 'createsend_general/advanced/subscriber_synchronisation_resolution_method';
39
- const XML_PATH_SUBSCRIBER_SYNC_PREFERRED_SOURCE = 'createsend_general/advanced/subscriber_synchronisation_preferred_source';
40
- const XML_PATH_MAGENTO_CRON_ENABLED = 'createsend_general/advanced/magento_cron_enabled';
41
- const XML_PATH_LOGGING = 'createsend_general/advanced/logging';
42
- const XML_PATH_M_TO_CM_ATTRIBUTES = 'createsend_customers/attributes/m_to_cm_attributes';
43
- const XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES = 'createsend_customers/wishlists/wishlist_product_attributes';
44
-
45
- protected $canLog = null;
46
-
47
- /**
48
- * Logs all extension specific notices to a separate file
49
- *
50
- * @param string $message The message to log
51
- * @param int $level The log level (defined in the Zend_Log class)
52
- */
53
- public function log($message, $level = Zend_Log::DEBUG)
54
- {
55
- if ($this->canLog()) {
56
- Mage::log($message, $level, self::LOGFILE);
57
- }
58
- }
59
-
60
- /**
61
- * @return bool
62
- */
63
- public function canLog()
64
- {
65
- if ($this->canLog === null) {
66
- $this->canLog = Mage::getStoreConfig(self::XML_PATH_LOGGING);
67
- }
68
- return $this->canLog;
69
- }
70
-
71
- /**
72
- * Returns the authentication method configuration value.
73
- * No need to trim as value comes from source model and not from user input.
74
- *
75
- * @param mixed $store Get the configuration value for this store code or ID
76
- * @return string
77
- */
78
- public function getAuthenticationMethod($store = null)
79
- {
80
- return Mage::getStoreConfig(self::XML_PATH_AUTHENTICATION_METHOD, $store);
81
- }
82
-
83
- /**
84
- * Returns a sanitized version of the API key configuration value
85
- *
86
- * @param string $scope
87
- * @param int $scopeId
88
- * @return string
89
- */
90
- public function getApiKey($scope, $scopeId)
91
- {
92
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
93
- $scopeModel = Mage::getSingleton('createsend/config_scope');
94
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
95
-
96
- return urlencode(trim($this->getStoreConfig(self::XML_PATH_API_ID, $storeId)));
97
- }
98
-
99
- /**
100
- * Returns a sanitized version of the API key Client ID configuration value
101
- *
102
- * @param mixed $store Get the configuration value for this store code or ID
103
- * @return string
104
- */
105
- public function getApiClientId($store = null)
106
- {
107
- return urlencode(trim(Mage::getStoreConfig(self::XML_PATH_API_CLIENT_ID, $store)));
108
- }
109
-
110
- /**
111
- * Returns a sanitized version of the list id configuration value
112
- *
113
- * @param mixed $store Get the configuration value for this store code or ID
114
- * @return string
115
- */
116
- public function getListId($store = null)
117
- {
118
- // Get value from database directly, bypassing the config cache
119
- // because we are saving the config value using Mage:getConfig()->saveConfig()
120
- return urlencode(trim($this->getStoreConfig(self::XML_PATH_LIST_ID, $store)));
121
- }
122
-
123
- /**
124
- * Returns the new list name configuration value.
125
- *
126
- * @param mixed $store
127
- * @return string
128
- */
129
- public function getNewListName($store = null)
130
- {
131
- return trim(Mage::getStoreConfig(self::XML_PATH_NEW_LIST_NAME, $store));
132
- }
133
-
134
- /**
135
- * Returns the OAuth Client ID configuration value
136
- *
137
- * @param mixed $store Get the configuration value for this store code or ID
138
- * @return string
139
- */
140
- public function getOAuthClientId($store = null)
141
- {
142
- return trim(Mage::getStoreConfig(self::XML_PATH_OAUTH_CLIENT_ID, $store));
143
- }
144
-
145
- /**
146
- * Returns the OAuth Client Secret configuration value
147
- *
148
- * @param mixed $store Get the configuration value for this store code or ID
149
- * @return string
150
- */
151
- public function getOAuthClientSecret($store = null)
152
- {
153
- return trim(Mage::getStoreConfig(self::XML_PATH_OAUTH_CLIENT_SECRET, $store));
154
- }
155
-
156
- /**
157
- * Returns the OAuth Access Token configuration value
158
- *
159
- * @param mixed $store Get the configuration value for this store code or ID
160
- * @return string
161
- */
162
- public function getOAuthAccessToken($store = null)
163
- {
164
- return $this->getStoreConfig(self::XML_PATH_OAUTH_ACCESS_TOKEN, $store);
165
- }
166
-
167
- /**
168
- * Returns the OAuth Access Token configuration value in the specified store
169
- *
170
- * @param mixed $store Get the configuration value for this store code or ID
171
- * @return string
172
- */
173
- public function getOAuthAccessTokenExpiryDate($store = null)
174
- {
175
- return $this->getStoreConfig(self::XML_PATH_OAUTH_ACCESS_TOKEN_EXPIRY_DATE, $store);
176
- }
177
-
178
- /**
179
- * Returns the OAuth Refresh Token in the specified store
180
- *
181
- * @param mixed $store Get the configuration value for this store code or ID
182
- * @return string
183
- */
184
- public function getOAuthRefreshToken($store = null)
185
- {
186
- return $this->getStoreConfig(self::XML_PATH_OAUTH_REFRESH_TOKEN, $store);
187
- }
188
-
189
- /**
190
- * Returns the Max Wish list items
191
- *
192
- * @param mixed $store Get the configuration value for this store code or ID
193
- * @return int
194
- */
195
- public function getMaxWistlistItems($store = null)
196
- {
197
- return Mage::getStoreConfig(self::XML_PATH_MAX_WISHLIST_ITEMS, $store);
198
- }
199
-
200
- /**
201
- * Returns the Wishlist product attributes for the custom fields
202
- *
203
- * @param mixed $store Get the configuration value for this store code or ID
204
- * @return int
205
- */
206
- public function getProductAttributes($store = null)
207
- {
208
- return Mage::getStoreConfig(self::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES, $store);
209
- }
210
-
211
- /**
212
- * Returns the Webhook enabled configuration value
213
- *
214
- * @param mixed $store Get the configuration value for this store code or ID
215
- * @return bool
216
- */
217
- public function isWebhookEnabled($store = null)
218
- {
219
- return Mage::getStoreConfigFlag(self::XML_PATH_WEBHOOK_ENABLED, $store);
220
- }
221
-
222
- /**
223
- * Returns the Transactional Email configuration value
224
- *
225
- * @param mixed $store Get the configuration value for this store code or ID
226
- * @return bool
227
- */
228
- public function isTransactionalEmailsEnabled($store = null)
229
- {
230
- return Mage::getStoreConfigFlag(self::XML_PATH_TRANSACTIONAL_EMAIL_ENABLED, $store);
231
- }
232
-
233
- /**
234
- * Returns the Subscriber Synchronisation Enabled configuration value
235
- *
236
- * @param mixed $store Get the configuration value for this store code or ID
237
- * @return bool
238
- */
239
- public function isSubscriberSynchronisationEnabled($store = null)
240
- {
241
- return Mage::getStoreConfigFlag(self::XML_PATH_SUBSCRIBER_SYNC_ENABLED, $store);
242
- }
243
-
244
- /**
245
- * Returns the Subscriber Synchronisation Resolution Method configuration value
246
- *
247
- * @param mixed $store Get the configuration value for this store code or ID
248
- * @return string
249
- */
250
- public function getSubscriberSynchronisationResolutionMethod($store = null)
251
- {
252
- return Mage::getStoreConfig(self::XML_PATH_SUBSCRIBER_SYNC_RESOLUTION_METHOD, $store);
253
- }
254
-
255
- /**
256
- * Returns the Subscriber Synchronisation Preferred Source configuration value
257
- *
258
- * @param mixed $store Get the configuration value for this store code or ID
259
- * @return mixed
260
- */
261
- public function getSubscriberSynchronisationPreferredSource($store = null)
262
- {
263
- return Mage::getStoreConfig(self::XML_PATH_SUBSCRIBER_SYNC_PREFERRED_SOURCE, $store);
264
- }
265
-
266
- /**
267
- * Returns the Magento Cron Enabled configuration value
268
- *
269
- * @param mixed $store Get the configuration value for this store code or ID
270
- * @return bool
271
- */
272
- public function isMagentoCronEnabled($store = null)
273
- {
274
- return Mage::getStoreConfigFlag(self::XML_PATH_MAGENTO_CRON_ENABLED, $store);
275
- }
276
-
277
- /**
278
- * Returns the Transactional Email Header Retention Days configuration value
279
- *
280
- * @param mixed $store Get the configuration value for this store code or ID
281
- * @return int
282
- */
283
- public function getEmailRetentionDays($store = null)
284
- {
285
- return Mage::getStoreConfig(self::XML_PATH_EMAIL_RETENTION_DAYS, $store);
286
- }
287
-
288
- /**
289
- * Returns the Campaign Monitor Client ID
290
- *
291
- * @param mixed $store Get the configuration value for this store code or ID
292
- * @return null|string
293
- */
294
- public function getClientId($store)
295
- {
296
- return $this->getApiClientId($store);
297
- }
298
-
299
- /**
300
- * Saves the token data for OAuth API
301
- *
302
- * @param array $data Array containing the access token ($data['access_token']),
303
- * expiry period in seconds ($data['expires_in'])
304
- * and refresh token ($data['refresh_token'])
305
- * @param string $scope
306
- * @param int $scopeId
307
- * @return bool
308
- */
309
- public function saveOauthTokenData(array $data, $scope, $scopeId)
310
- {
311
- if (empty($data['access_token'])) {
312
- return false;
313
- }
314
-
315
- $now = new DateTime();
316
- $expiry = $now->add(DateInterval::createFromDateString($data['expires_in'] . ' seconds'));
317
-
318
- /** @var Mage_Core_Model_Config $configSingleton */
319
- $configSingleton = Mage::getConfig();
320
-
321
- $configSingleton->saveConfig(
322
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_OAUTH_ACCESS_TOKEN,
323
- $data['access_token'], $scope, $scopeId
324
- );
325
-
326
- $configSingleton->saveConfig(
327
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_OAUTH_ACCESS_TOKEN_EXPIRY_DATE,
328
- $expiry->format('Y-m-d H:i:s O'), $scope, $scopeId
329
- );
330
-
331
- $configSingleton->saveConfig(
332
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_OAUTH_REFRESH_TOKEN,
333
- $data['refresh_token'], $scope, $scopeId
334
- );
335
-
336
- return true;
337
- }
338
-
339
- /**
340
- * Returns true if the configuration for the specified scope/scopeId is complete.
341
- *
342
- * @param string $scope
343
- * @param int $scopeId
344
- * @return bool
345
- */
346
- function isCompleteConfig($scope, $scopeId)
347
- {
348
- $reply = true;
349
-
350
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
351
- $scopeModel = Mage::getSingleton('createsend/config_scope');
352
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
353
-
354
- $authenticationMethod = $this->getAuthenticationMethod($storeId);
355
- switch ($authenticationMethod) {
356
- case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_API_KEY:
357
- $apiKey = $this->getApiKey($scope, $scopeId);
358
-
359
- if (!$apiKey) {
360
- $reply = false;
361
- }
362
- break;
363
-
364
- case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_OAUTH:
365
- $clientId = $this->getOAuthClientId($storeId);
366
- $clientSecret = $this->getOAuthClientSecret($storeId);
367
- $oauthAccessToken = $this->getOAuthAccessToken($storeId);
368
-
369
- if (!$clientId || !$clientSecret || !$oauthAccessToken) {
370
- $reply = false;
371
- }
372
- break;
373
-
374
- default:
375
- $reply = false;
376
- break;
377
-
378
- }
379
-
380
- $listId = $this->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID, $scope, $scopeId);
381
-
382
- if ($listId === false) {
383
- $reply = false;
384
- }
385
-
386
- return $reply;
387
- }
388
-
389
- /**
390
- * Gets the appropriate configuration value from the database, given the path and store code or ID.
391
- * If the configuration is not found in the store scope, the value for website scope and default scope
392
- * will be retrieved.
393
- *
394
- * This function is written to work the same way as Mage::getStoreConfig() except that it does not
395
- * use the config cache. This function should be used if there are config settings that
396
- * were saved directly using Mage::getConfig()->saveConfig()
397
- *
398
- * @param string $path
399
- * @param mixed $store
400
- * @return mixed|null
401
- */
402
- public function getStoreConfig($path, $store)
403
- {
404
- $configValue = $this->getScopedConfig($path, 'stores', Mage::app()->getStore($store)->getId());
405
- if ($configValue === false) {
406
- $configValue = $this->getScopedConfig($path, 'websites', Mage::app()->getStore($store)->getWebsiteId());
407
- if ($configValue === false) {
408
- $configValue = $this->getScopedConfig($path, 'default', Mage_Core_Model_App::ADMIN_STORE_ID);
409
- if ($configValue === false) {
410
- $configValue = null;
411
- }
412
- }
413
- }
414
-
415
- return $configValue;
416
- }
417
-
418
- /**
419
- * Gets the appropriate configuration value from the database, given the path, scope and ID. Uses similar logic
420
- * to the method Mage_Core_Model_Resource_Config::deleteConfig(), and should only be used when querying a config
421
- * value known to be in the DB and where scope must be known.
422
- *
423
- * @param string $path the tree path
424
- * @param string $scope default, website or store scope
425
- * @param int $scopeId The ID of the scoped reference
426
- * @return mixed
427
- */
428
- public function getScopedConfig($path, $scope, $scopeId)
429
- {
430
- /** @var Mage_Core_Model_Resource $resource */
431
- $resource = Mage::getSingleton('core/resource');
432
- /** @var Magento_Db_Adapter_Pdo_Mysql $db */
433
- // Uses the core_write table instead of core_read to get up to date information as config is iteratively saved.
434
- $db = $resource->getConnection(
435
- Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE
436
- );
437
-
438
- $coreConfigTable = $resource->getTableName('core/config_data');
439
- $select = $db->select()
440
- ->from($coreConfigTable, 'value')
441
- ->where('path = ?', $path)
442
- ->where('scope = ?', $scope)
443
- ->where('scope_id = ?', $scopeId);
444
-
445
- $value = $db->fetchOne($select);
446
- if ($value !== null) {
447
- return $value;
448
- }
449
-
450
- return false;
451
- }
452
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Helper_Data extends Mage_Core_Helper_Data
19
+ {
20
+ const LOGFILE = "campaignmonitor_createsend.log";
21
+
22
+ const XML_PATH_WEBHOOK_ID = 'createsend_general/api/webhook_id';
23
+ const XML_PATH_LIST_ID = 'createsend_general/api/list_id';
24
+ const XML_PATH_NEW_LIST_NAME = 'createsend_general/api/new_list_name';
25
+ const XML_PATH_AUTHENTICATION_METHOD = 'createsend_general/api/authentication_method';
26
+ const XML_PATH_API_ID = 'createsend_general/api/api_key';
27
+ const XML_PATH_API_CLIENT_ID = 'createsend_general/api/api_client_id';
28
+ const XML_PATH_OAUTH_CLIENT_ID = 'createsend_general/api/oauth_client_id';
29
+ const XML_PATH_OAUTH_CLIENT_SECRET = 'createsend_general/api/oauth_client_secret';
30
+ const XML_PATH_MAX_WISHLIST_ITEMS = 'createsend_customers/wishlists/max_wishlist_items';
31
+ const XML_PATH_WEBHOOK_ENABLED = 'createsend_general/advanced/webhook_enabled';
32
+ const XML_PATH_OAUTH_ACCESS_TOKEN = 'createsend_general/api/oauth_access_token';
33
+ const XML_PATH_OAUTH_ACCESS_TOKEN_EXPIRY_DATE = 'createsend_general/api/oauth_access_token_expiry_date';
34
+ const XML_PATH_OAUTH_REFRESH_TOKEN = 'createsend_general/api/oauth_refresh_token';
35
+ const XML_PATH_TRANSACTIONAL_EMAIL_ENABLED = 'createsend_transactional/emails/transactional_email_enabled';
36
+ const XML_PATH_EMAIL_RETENTION_DAYS = 'createsend_transactional/emails/transactional_email_retention_days';
37
+ const XML_PATH_SUBSCRIBER_SYNC_ENABLED = 'createsend_general/advanced/subscriber_synchronisation_enabled';
38
+ const XML_PATH_SUBSCRIBER_SYNC_RESOLUTION_METHOD = 'createsend_general/advanced/subscriber_synchronisation_resolution_method';
39
+ const XML_PATH_SUBSCRIBER_SYNC_PREFERRED_SOURCE = 'createsend_general/advanced/subscriber_synchronisation_preferred_source';
40
+ const XML_PATH_MAGENTO_CRON_ENABLED = 'createsend_general/advanced/magento_cron_enabled';
41
+ const XML_PATH_LOGGING = 'createsend_general/advanced/logging';
42
+ const XML_PATH_M_TO_CM_ATTRIBUTES = 'createsend_customers/attributes/m_to_cm_attributes';
43
+ const XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES = 'createsend_customers/wishlists/wishlist_product_attributes';
44
+
45
+ protected $canLog = null;
46
+
47
+ /**
48
+ * Logs all extension specific notices to a separate file
49
+ *
50
+ * @param string $message The message to log
51
+ * @param int $level The log level (defined in the Zend_Log class)
52
+ */
53
+ public function log($message, $level = Zend_Log::DEBUG)
54
+ {
55
+ if ($this->canLog()) {
56
+ Mage::log($message, $level, self::LOGFILE);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * @return bool
62
+ */
63
+ public function canLog()
64
+ {
65
+ if ($this->canLog === null) {
66
+ $this->canLog = Mage::getStoreConfig(self::XML_PATH_LOGGING);
67
+ }
68
+ return $this->canLog;
69
+ }
70
+
71
+ /**
72
+ * Returns the authentication method configuration value.
73
+ * No need to trim as value comes from source model and not from user input.
74
+ *
75
+ * @param mixed $store Get the configuration value for this store code or ID
76
+ * @return string
77
+ */
78
+ public function getAuthenticationMethod($store = null)
79
+ {
80
+ return Mage::getStoreConfig(self::XML_PATH_AUTHENTICATION_METHOD, $store);
81
+ }
82
+
83
+ /**
84
+ * Returns a sanitized version of the API key configuration value
85
+ *
86
+ * @param string $scope
87
+ * @param int $scopeId
88
+ * @return string
89
+ */
90
+ public function getApiKey($scope, $scopeId)
91
+ {
92
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
93
+ $scopeModel = Mage::getSingleton('createsend/config_scope');
94
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
95
+
96
+ return urlencode(trim($this->getStoreConfig(self::XML_PATH_API_ID, $storeId)));
97
+ }
98
+
99
+ /**
100
+ * Returns a sanitized version of the API key Client ID configuration value
101
+ *
102
+ * @param mixed $store Get the configuration value for this store code or ID
103
+ * @return string
104
+ */
105
+ public function getApiClientId($store = null)
106
+ {
107
+ return urlencode(trim(Mage::getStoreConfig(self::XML_PATH_API_CLIENT_ID, $store)));
108
+ }
109
+
110
+ /**
111
+ * Returns a sanitized version of the list id configuration value
112
+ *
113
+ * @param mixed $store Get the configuration value for this store code or ID
114
+ * @return string
115
+ */
116
+ public function getListId($store = null)
117
+ {
118
+ // Get value from database directly, bypassing the config cache
119
+ // because we are saving the config value using Mage:getConfig()->saveConfig()
120
+ return urlencode(trim($this->getStoreConfig(self::XML_PATH_LIST_ID, $store)));
121
+ }
122
+
123
+ /**
124
+ * Returns the new list name configuration value.
125
+ *
126
+ * @param mixed $store
127
+ * @return string
128
+ */
129
+ public function getNewListName($store = null)
130
+ {
131
+ return trim(Mage::getStoreConfig(self::XML_PATH_NEW_LIST_NAME, $store));
132
+ }
133
+
134
+ /**
135
+ * Returns the OAuth Client ID configuration value
136
+ *
137
+ * @param mixed $store Get the configuration value for this store code or ID
138
+ * @return string
139
+ */
140
+ public function getOAuthClientId($store = null)
141
+ {
142
+ return trim(Mage::getStoreConfig(self::XML_PATH_OAUTH_CLIENT_ID, $store));
143
+ }
144
+
145
+ /**
146
+ * Returns the OAuth Client Secret configuration value
147
+ *
148
+ * @param mixed $store Get the configuration value for this store code or ID
149
+ * @return string
150
+ */
151
+ public function getOAuthClientSecret($store = null)
152
+ {
153
+ return trim(Mage::getStoreConfig(self::XML_PATH_OAUTH_CLIENT_SECRET, $store));
154
+ }
155
+
156
+ /**
157
+ * Returns the OAuth Access Token configuration value
158
+ *
159
+ * @param mixed $store Get the configuration value for this store code or ID
160
+ * @return string
161
+ */
162
+ public function getOAuthAccessToken($store = null)
163
+ {
164
+ return $this->getStoreConfig(self::XML_PATH_OAUTH_ACCESS_TOKEN, $store);
165
+ }
166
+
167
+ /**
168
+ * Returns the OAuth Access Token configuration value in the specified store
169
+ *
170
+ * @param mixed $store Get the configuration value for this store code or ID
171
+ * @return string
172
+ */
173
+ public function getOAuthAccessTokenExpiryDate($store = null)
174
+ {
175
+ return $this->getStoreConfig(self::XML_PATH_OAUTH_ACCESS_TOKEN_EXPIRY_DATE, $store);
176
+ }
177
+
178
+ /**
179
+ * Returns the OAuth Refresh Token in the specified store
180
+ *
181
+ * @param mixed $store Get the configuration value for this store code or ID
182
+ * @return string
183
+ */
184
+ public function getOAuthRefreshToken($store = null)
185
+ {
186
+ return $this->getStoreConfig(self::XML_PATH_OAUTH_REFRESH_TOKEN, $store);
187
+ }
188
+
189
+ /**
190
+ * Returns the Max Wish list items
191
+ *
192
+ * @param mixed $store Get the configuration value for this store code or ID
193
+ * @return int
194
+ */
195
+ public function getMaxWistlistItems($store = null)
196
+ {
197
+ return Mage::getStoreConfig(self::XML_PATH_MAX_WISHLIST_ITEMS, $store);
198
+ }
199
+
200
+ /**
201
+ * Returns the Wishlist product attributes for the custom fields
202
+ *
203
+ * @param mixed $store Get the configuration value for this store code or ID
204
+ * @return int
205
+ */
206
+ public function getProductAttributes($store = null)
207
+ {
208
+ return Mage::getStoreConfig(self::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES, $store);
209
+ }
210
+
211
+ /**
212
+ * Returns the Webhook enabled configuration value
213
+ *
214
+ * @param mixed $store Get the configuration value for this store code or ID
215
+ * @return bool
216
+ */
217
+ public function isWebhookEnabled($store = null)
218
+ {
219
+ return Mage::getStoreConfigFlag(self::XML_PATH_WEBHOOK_ENABLED, $store);
220
+ }
221
+
222
+ /**
223
+ * Returns the Transactional Email configuration value
224
+ *
225
+ * @param mixed $store Get the configuration value for this store code or ID
226
+ * @return bool
227
+ */
228
+ public function isTransactionalEmailsEnabled($store = null)
229
+ {
230
+ return Mage::getStoreConfigFlag(self::XML_PATH_TRANSACTIONAL_EMAIL_ENABLED, $store);
231
+ }
232
+
233
+ /**
234
+ * Returns the Subscriber Synchronisation Enabled configuration value
235
+ *
236
+ * @param mixed $store Get the configuration value for this store code or ID
237
+ * @return bool
238
+ */
239
+ public function isSubscriberSynchronisationEnabled($store = null)
240
+ {
241
+ return Mage::getStoreConfigFlag(self::XML_PATH_SUBSCRIBER_SYNC_ENABLED, $store);
242
+ }
243
+
244
+ /**
245
+ * Returns the Subscriber Synchronisation Resolution Method configuration value
246
+ *
247
+ * @param mixed $store Get the configuration value for this store code or ID
248
+ * @return string
249
+ */
250
+ public function getSubscriberSynchronisationResolutionMethod($store = null)
251
+ {
252
+ return Mage::getStoreConfig(self::XML_PATH_SUBSCRIBER_SYNC_RESOLUTION_METHOD, $store);
253
+ }
254
+
255
+ /**
256
+ * Returns the Subscriber Synchronisation Preferred Source configuration value
257
+ *
258
+ * @param mixed $store Get the configuration value for this store code or ID
259
+ * @return mixed
260
+ */
261
+ public function getSubscriberSynchronisationPreferredSource($store = null)
262
+ {
263
+ return Mage::getStoreConfig(self::XML_PATH_SUBSCRIBER_SYNC_PREFERRED_SOURCE, $store);
264
+ }
265
+
266
+ /**
267
+ * Returns the Magento Cron Enabled configuration value
268
+ *
269
+ * @param mixed $store Get the configuration value for this store code or ID
270
+ * @return bool
271
+ */
272
+ public function isMagentoCronEnabled($store = null)
273
+ {
274
+ return Mage::getStoreConfigFlag(self::XML_PATH_MAGENTO_CRON_ENABLED, $store);
275
+ }
276
+
277
+ /**
278
+ * Returns the Transactional Email Header Retention Days configuration value
279
+ *
280
+ * @param mixed $store Get the configuration value for this store code or ID
281
+ * @return int
282
+ */
283
+ public function getEmailRetentionDays($store = null)
284
+ {
285
+ return Mage::getStoreConfig(self::XML_PATH_EMAIL_RETENTION_DAYS, $store);
286
+ }
287
+
288
+ /**
289
+ * Returns the Campaign Monitor Client ID
290
+ *
291
+ * @param mixed $store Get the configuration value for this store code or ID
292
+ * @return null|string
293
+ */
294
+ public function getClientId($store)
295
+ {
296
+ return $this->getApiClientId($store);
297
+ }
298
+
299
+ /**
300
+ * Saves the token data for OAuth API
301
+ *
302
+ * @param array $data Array containing the access token ($data['access_token']),
303
+ * expiry period in seconds ($data['expires_in'])
304
+ * and refresh token ($data['refresh_token'])
305
+ * @param string $scope
306
+ * @param int $scopeId
307
+ * @return bool
308
+ */
309
+ public function saveOauthTokenData(array $data, $scope, $scopeId)
310
+ {
311
+ if (empty($data['access_token'])) {
312
+ return false;
313
+ }
314
+
315
+ $now = new DateTime();
316
+ $expiry = $now->add(DateInterval::createFromDateString($data['expires_in'] . ' seconds'));
317
+
318
+ /** @var Mage_Core_Model_Config $configSingleton */
319
+ $configSingleton = Mage::getConfig();
320
+
321
+ $configSingleton->saveConfig(
322
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_OAUTH_ACCESS_TOKEN,
323
+ $data['access_token'], $scope, $scopeId
324
+ );
325
+
326
+ $configSingleton->saveConfig(
327
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_OAUTH_ACCESS_TOKEN_EXPIRY_DATE,
328
+ $expiry->format('Y-m-d H:i:s O'), $scope, $scopeId
329
+ );
330
+
331
+ $configSingleton->saveConfig(
332
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_OAUTH_REFRESH_TOKEN,
333
+ $data['refresh_token'], $scope, $scopeId
334
+ );
335
+
336
+ return true;
337
+ }
338
+
339
+ /**
340
+ * Returns true if the configuration for the specified scope/scopeId is complete.
341
+ *
342
+ * @param string $scope
343
+ * @param int $scopeId
344
+ * @return bool
345
+ */
346
+ function isCompleteConfig($scope, $scopeId)
347
+ {
348
+ $reply = true;
349
+
350
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
351
+ $scopeModel = Mage::getSingleton('createsend/config_scope');
352
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
353
+
354
+ $authenticationMethod = $this->getAuthenticationMethod($storeId);
355
+ switch ($authenticationMethod) {
356
+ case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_API_KEY:
357
+ $apiKey = $this->getApiKey($scope, $scopeId);
358
+
359
+ if (!$apiKey) {
360
+ $reply = false;
361
+ }
362
+ break;
363
+
364
+ case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_OAUTH:
365
+ $clientId = $this->getOAuthClientId($storeId);
366
+ $clientSecret = $this->getOAuthClientSecret($storeId);
367
+ $oauthAccessToken = $this->getOAuthAccessToken($storeId);
368
+
369
+ if (!$clientId || !$clientSecret || !$oauthAccessToken) {
370
+ $reply = false;
371
+ }
372
+ break;
373
+
374
+ default:
375
+ $reply = false;
376
+ break;
377
+
378
+ }
379
+
380
+ $listId = $this->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID, $scope, $scopeId);
381
+
382
+ if ($listId === false) {
383
+ $reply = false;
384
+ }
385
+
386
+ return $reply;
387
+ }
388
+
389
+ /**
390
+ * Gets the appropriate configuration value from the database, given the path and store code or ID.
391
+ * If the configuration is not found in the store scope, the value for website scope and default scope
392
+ * will be retrieved.
393
+ *
394
+ * This function is written to work the same way as Mage::getStoreConfig() except that it does not
395
+ * use the config cache. This function should be used if there are config settings that
396
+ * were saved directly using Mage::getConfig()->saveConfig()
397
+ *
398
+ * @param string $path
399
+ * @param mixed $store
400
+ * @return mixed|null
401
+ */
402
+ public function getStoreConfig($path, $store)
403
+ {
404
+ $configValue = $this->getScopedConfig($path, 'stores', Mage::app()->getStore($store)->getId());
405
+ if ($configValue === false) {
406
+ $configValue = $this->getScopedConfig($path, 'websites', Mage::app()->getStore($store)->getWebsiteId());
407
+ if ($configValue === false) {
408
+ $configValue = $this->getScopedConfig($path, 'default', Mage_Core_Model_App::ADMIN_STORE_ID);
409
+ if ($configValue === false) {
410
+ $configValue = null;
411
+ }
412
+ }
413
+ }
414
+
415
+ return $configValue;
416
+ }
417
+
418
+ /**
419
+ * Gets the appropriate configuration value from the database, given the path, scope and ID. Uses similar logic
420
+ * to the method Mage_Core_Model_Resource_Config::deleteConfig(), and should only be used when querying a config
421
+ * value known to be in the DB and where scope must be known.
422
+ *
423
+ * @param string $path the tree path
424
+ * @param string $scope default, website or store scope
425
+ * @param int $scopeId The ID of the scoped reference
426
+ * @return mixed
427
+ */
428
+ public function getScopedConfig($path, $scope, $scopeId)
429
+ {
430
+ /** @var Mage_Core_Model_Resource $resource */
431
+ $resource = Mage::getSingleton('core/resource');
432
+ /** @var Magento_Db_Adapter_Pdo_Mysql $db */
433
+ // Uses the core_write table instead of core_read to get up to date information as config is iteratively saved.
434
+ $db = $resource->getConnection(
435
+ Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE
436
+ );
437
+
438
+ $coreConfigTable = $resource->getTableName('core/config_data');
439
+ $select = $db->select()
440
+ ->from($coreConfigTable, 'value')
441
+ ->where('path = ?', $path)
442
+ ->where('scope = ?', $scope)
443
+ ->where('scope_id = ?', $scopeId);
444
+
445
+ $value = $db->fetchOne($select);
446
+ if ($value !== null) {
447
+ return $value;
448
+ }
449
+
450
+ return false;
451
+ }
452
+ }
app/code/community/Campaignmonitor/Createsend/Model/Api.php CHANGED
@@ -1,913 +1,916 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Responsible for making calls and getting responses from the Campaign Monitor API.
20
- * Uses the key authorization mechanism (see the link for further information)
21
- *
22
- * @link https://www.campaignmonitor.com/api/getting-started/
23
- */
24
- class Campaignmonitor_Createsend_Model_Api
25
- {
26
- const API_BASE_URL = 'https://api.createsend.com/';
27
- const API_PATH = 'api/v3.1/';
28
- const API_OAUTH_PATH = 'oauth/';
29
-
30
- const CODE_SUBSCRIBER_NOT_IN_LIST = 203;
31
- const CODE_DUPLICATE_SEGMENT_TITLE = 275;
32
- const CODE_INVALID_SEGMENT_RULES = 277;
33
- const CODE_FIELD_KEY_EXISTS = 255;
34
-
35
- const ERR_API_REQUEST = 'API Error: %s';
36
- const ERR_INVALID_HTTP_METHOD = 'The method "%s" is not an acceptable HTTP method';
37
- const ERR_INVALID_AUTH_METHOD = 'The method "%s" is not an acceptable Authentication method';
38
- const ERR_INVALID_JSON = 'The following response is not valid JSON: "%s"';
39
- const ERR_ID_REQUIRED = 'The "%s" data is required to make this call';
40
- const ERR_NO_LIST_ID_AT_SCOPE = 'There is no list ID defined at this %s/%s scope. Cannot create webhook';
41
- const ERR_CANNOT_UPDATE_WEBHOOK = 'API Error: Cannot update webhook (%s)';
42
- const ERR_CANNOT_LIST_WEBHOOKS = 'API Error: Cannot list webhook (%s)';
43
-
44
- const ERR_CANNOT_CREATE_CUSTOM_FIELD = 'API Error: Cannot create custom field: (%1$s): %2$s';
45
- const ERR_CREATE_CUSTOM_FIELDS = 'Please create these custom fields on the Campaign Monitor list: %s';
46
- const ERR_SEGMENT_EXISTS = 'A segment with the same title already exists on this list.';
47
- const ERR_UNABLE_TO_CREATE_SEGMENT = 'Unable to create segment (%1$s): %2$s';
48
- const LOG_SEGMENT_CREATED = 'Segment successfully created (%s).';
49
-
50
- const LOG_API_REQUEST = 'API Request %s @ %s: %s';
51
- const LOG_API_RESPONSE = 'API Response (%s) @ %s: %s';
52
- const LOG_CREATED_WEBHOOK = 'Created webhook with ID "%s"';
53
- const LOG_DELETED_WEBHOOK = 'Deleted webhook with ID "%s"';
54
- const LOG_WEBHOOKS_NOT_ENABLED = 'Webhooks not enabled.';
55
-
56
- const WEBHOOK_EVENT_SUBSCRIBE = 'Subscribe';
57
- const WEBHOOK_EVENT_UPDATE = 'Update';
58
- const WEBHOOK_EVENT_DEACTIVATE = 'Deactivate';
59
-
60
- const SUBSCRIBER_STATUS_ACTIVE = 'Active';
61
- const SUBSCRIBER_STATUS_DELETED = 'Deleted';
62
-
63
- const WEBHOOK_STATUS_ACTIVE = 'Active';
64
- const WEBHOOK_STATUS_UNSUBSCRIBED = 'Unsubscribed';
65
- const WEBHOOK_STATUS_DELETED = 'Deleted';
66
-
67
- const WEBHOOK_PAYLOAD_FORMAT_JSON = 'Json';
68
-
69
- const OAUTH_API_TOKEN_REQUEST = 'oauth_token';
70
-
71
- const FIELD_TYPE_TEXT = 'Text';
72
- const FIELD_TYPE_NUMBER = 'Number';
73
- const FIELD_TYPE_DATE = 'Date';
74
- const FIELD_TYPE_SELECT_ONE = 'MultiSelectOne';
75
- const FIELD_TYPE_SELECT_MANY = 'MultiSelectMany';
76
- const FIELD_TYPE_COUNTRY = 'Country';
77
-
78
- const CM_MAX_CUSTOM_FIELD_LENGTH = 100;
79
- const CM_CUSTOM_FIELD_PREFIX = 'Magento ';
80
-
81
- const WISHLIST_CUSTOM_FIELD_PREFIX = 'Wishlist Item';
82
- const WISHLIST_CUSTOM_FIELD_PATTERN = '%1$s %2$s %3$s';
83
-
84
- const USER_AGENT_STRING = 'CM_Magento_Extension; Magento %s; Extension %s; List ID %s';
85
-
86
- // Methods used by the API
87
- /** @var array */
88
- protected $_supportedMethods = array(
89
- Zend_Http_Client::DELETE,
90
- Zend_Http_Client::GET,
91
- Zend_Http_Client::POST,
92
- Zend_Http_Client::PUT
93
- );
94
-
95
- // Permissions to be requested when authenticating via OAuth
96
- /** @var array */
97
- protected $_oauthPermissions = array(
98
- 'ManageLists',
99
- 'ImportSubscribers',
100
- 'ViewTransactional',
101
- 'SendTransactional'
102
- );
103
-
104
- /**
105
- * Returns the URL for the OAuth Controller
106
- *
107
- * @param string $scope
108
- * @param int $scopeId
109
- * @return string
110
- */
111
- public function getOauthRedirectUri($scope, $scopeId)
112
- {
113
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
114
- $scopeModel = Mage::getModel('createsend/config_scope');
115
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
116
-
117
- $url = Mage::getUrl(
118
- 'createsend/oauth/getToken',
119
- array(
120
- '_nosid' => true,
121
- '_store' => $storeId,
122
- '_type' => 'direct_link'
123
- )
124
- );
125
-
126
- return $url;
127
- }
128
-
129
- /**
130
- * Returns the URL Address for the Campaign Monitor OAuth Permission Request Page,
131
- * including all the GET parameters required by the Campaign Monitor API for OAuth
132
- *
133
- * @link https://www.campaignmonitor.com/api/getting-started/#authenticating_with_oauth
134
- *
135
- * @param string $scope
136
- * @param int $scopeId
137
- * @return string
138
- */
139
- public function getOauthPermissionRequestUrl($scope, $scopeId)
140
- {
141
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
142
- $helper = Mage::helper('createsend');
143
-
144
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
145
- $scopeModel = Mage::getModel('createsend/config_scope');
146
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
147
-
148
- return self::API_BASE_URL . self::API_OAUTH_PATH . '?' . http_build_query (
149
- array(
150
- 'type' => 'web_server',
151
- 'client_id' => $helper->getOAuthClientId($storeId),
152
- 'redirect_uri' => $this->getOauthRedirectUri($scope, $scopeId),
153
- 'scope' => implode(',', $this->_oauthPermissions),
154
- 'state' => implode(',', array($scope, $scopeId))
155
- )
156
- );
157
- }
158
-
159
- /**
160
- * Calculate the version of Magento through a checking of arbitrary magento characteristics.
161
- *
162
- * @return string
163
- */
164
- public function getMagentoVersion()
165
- {
166
- $version = Mage::getVersion();
167
- $edition = 'ce';
168
-
169
- // If the version is above 1.6.0.0 it might be professional or enterprise.
170
- if (version_compare($version, '1.6.0.0', '>=')) {
171
-
172
- try {
173
- // Calculate whether the install has gift cards. if it doesn't, it's community.
174
- $hasGiftcards = false;
175
- try {
176
- $hasGiftcards = Mage::getModel('enterprise_giftcard/giftcard');
177
- } catch (Exception $exception) {
178
-
179
- }
180
-
181
- if ($hasGiftcards) {
182
- // Check whether the installation has the enterprise search observer. Only enterprise has this.
183
- $hasSolr = Mage::getModel('enterprise_search/observer');
184
-
185
- if ($hasSolr) {
186
- $edition = 'ee';
187
- } else {
188
- $edition = 'pe';
189
- }
190
- } else {
191
- $edition = 'ce';
192
- }
193
- } catch(Exception $e){
194
- Mage::logException($e);
195
- }
196
-
197
- }
198
-
199
- return sprintf('%s %s', $edition, $version);
200
- }
201
-
202
- /**
203
- * Responsible for providing an interface to the API and parsing the data returned from the API into a manageable
204
- * format.
205
- *
206
- * If the API returns a JSON object that is just a string that string will be in the [data][Message] key. This key
207
- * is also responsible for error messages if the API request fails as well as error messages the API returns.
208
- *
209
- * Returns an array of the form
210
- * [success] => bool
211
- * [status_code] => int
212
- * [data] => array
213
- * [Message] => string
214
- * [DataA] => Returned field
215
- * [DataB] => Returned field
216
- *
217
- * @param string $method The HTTP method to use. Accepted methods are defined at the top of this class and constants
218
- * are available in the Zend_Http_Client class.
219
- * @param string $endpoint The API endpoint to query; for example: lists/1eax88123c7cedasdas70fd05saxqwbf
220
- * @param array $postFields An array of fields to send the end point
221
- * @param array $queryParams An array of URI query parameters to append to the URI
222
- * @param string $scope 'default' | 'websites' | 'stores'
223
- * @param int $scopeId The id of the scope
224
- *
225
- * @return array|null
226
- */
227
- public function call($method, $endpoint, $postFields = array(), $queryParams = array(), $scope, $scopeId)
228
- {
229
- /** @var array $data */
230
- $data = array(
231
- 'success' => false,
232
- 'status_code' => null,
233
- 'data' => null
234
- );
235
-
236
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
237
- $helper = Mage::helper('createsend');
238
-
239
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
240
- $scopeModel = Mage::getModel('createsend/config_scope');
241
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
242
-
243
- $authenticationMethod = $helper->getAuthenticationMethod($storeId);
244
- if ($endpoint === 'token') {
245
- $authenticationMethod = self::OAUTH_API_TOKEN_REQUEST;
246
- }
247
-
248
- $apiKeyOrToken = '';
249
-
250
- switch ($authenticationMethod) {
251
- case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_API_KEY:
252
- $apiKeyOrToken = $helper->getApiKey($scope, $scopeId);
253
-
254
- if (!$apiKeyOrToken) {
255
- $data['data']['Message'] = 'No API key set in configuration';
256
- return $data;
257
- }
258
-
259
- break;
260
-
261
- case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_OAUTH:
262
- $expiry = new DateTime($helper->getOAuthAccessTokenExpiryDate($storeId));
263
- $now = new DateTime();
264
- if ($now > $expiry) {
265
- $this->_refreshToken($scope, $scopeId, $storeId);
266
- }
267
-
268
- $apiKeyOrToken = $helper->getOAuthAccessToken($storeId);
269
-
270
- if (!$apiKeyOrToken) {
271
- $data['data']['Message'] = 'No OAuth Token yet. Please request and allow OAuth permission first.';
272
- return $data;
273
- }
274
-
275
- break;
276
- }
277
-
278
- $mageVersion = strtoupper($this->getMagentoVersion());
279
- $extVersion = Mage::getConfig()->getModuleConfig("Campaignmonitor_Createsend")->version;
280
- $listId = $helper->getListId($storeId);
281
-
282
- $userAgent = sprintf(self::USER_AGENT_STRING, $mageVersion, $extVersion, $listId);
283
-
284
- $response = $this->_callApi($authenticationMethod, $apiKeyOrToken, $method, $endpoint, $postFields,
285
- $queryParams, $userAgent);
286
- if (!$response) {
287
- $data['data']['Message'] = 'An error occurred during the request.';
288
- return $data;
289
- }
290
-
291
- $data['success'] = $response->isSuccessful();
292
-
293
- // Get the response content. The response will either be a JSON encoded object or nothing, depending on the
294
- // call. The only situation in which content is not JSON is a request URI without a .json file suffix.
295
- if (stripos($response->getHeader('content-type'), 'application/json') !== null) {
296
- try {
297
- $returnContent = Zend_Json::decode($response->getBody());
298
-
299
- // The API sometimes returns a string, not an array.
300
- if (is_array($returnContent)) {
301
- $data['data'] = $returnContent;
302
- } else {
303
- $data['data'] = array('Message' => $returnContent);
304
- }
305
- } catch (Zend_Json_Exception $e) {
306
- $helper->log(sprintf(self::ERR_INVALID_JSON, $response->getBody()));
307
- }
308
- }
309
-
310
- $data['status_code'] = $response->getStatus();
311
- return $data;
312
- }
313
-
314
- /**
315
- * Responsible for making the actual calls to the API. The authorization method is either "API Key" or "OAuth"
316
- * authorisation method, and documentation can be found at the link below.
317
- *
318
- * @link https://www.campaignmonitor.com/api/
319
- *
320
- * @param string $authenticationMethod The Authentication Method to be used for the request ('api_key' or 'oauth')
321
- * @param string $apiKeyOrToken The API key or OAuth Access Token required to make the API request
322
- * @param string $method The HTTP Method for the request. Valid methods are documented at the top of the class
323
- * @param string $endpoint The endpoint to make the request of
324
- * @param array $postFields The fields that should be posted to the end point
325
- * @param array $queryParams Any query params that should be appended to the request
326
- * @param string $userAgent HTTP User-Agent to use
327
- *
328
- * @return Zend_Http_Response
329
- * @throws Mage_Core_Exception if the method given is not an accepted method
330
- * @throws Zend_Http_Client_Exception if something goes wrong during the connection
331
- */
332
- protected function _callApi($authenticationMethod, $apiKeyOrToken, $method, $endpoint,
333
- $postFields = array(), $queryParams = array(), $userAgent)
334
- {
335
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
336
- $helper = Mage::helper('createsend');
337
-
338
- if (in_array($method, $this->_supportedMethods) === false) {
339
- Mage::throwException(sprintf(self::ERR_INVALID_HTTP_METHOD, $method));
340
- }
341
-
342
- // Construct the client
343
- $client = new Zend_Http_Client();
344
- $client->setMethod($method);
345
- $client->setConfig(array('useragent' => $userAgent));
346
-
347
- $uri = self::API_BASE_URL . self::API_PATH . $endpoint . '.json';
348
-
349
- switch ($authenticationMethod) {
350
- case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_API_KEY:
351
- $client->setAuth($apiKeyOrToken, null, Zend_Http_Client::AUTH_BASIC);
352
- break;
353
-
354
- case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_OAUTH:
355
- $client->setHeaders('Authorization', 'Bearer ' . $apiKeyOrToken);
356
- break;
357
-
358
- case self::OAUTH_API_TOKEN_REQUEST:
359
- $uri = self::API_BASE_URL . self::API_OAUTH_PATH . $endpoint;
360
- break;
361
-
362
- default:
363
- Mage::throwException(sprintf(self::ERR_INVALID_AUTH_METHOD, $authenticationMethod));
364
- break;
365
- }
366
-
367
- if (count($queryParams) > 0) {
368
- $uri .= '?' . http_build_query($queryParams);
369
- }
370
- $client->setUri($uri);
371
-
372
- $payload = Zend_Json::encode($postFields);
373
-
374
- // Optionally set the POST payload
375
- if ($method === Zend_Http_Client::POST) {
376
- $client->setRawData($payload, 'application/json');
377
- }
378
-
379
- // Log the request for debugging
380
- $helper->log(
381
- sprintf(self::LOG_API_REQUEST, $method, $client->getUri()->__toString(), $payload),
382
- Zend_Log::DEBUG
383
- );
384
-
385
- try {
386
- $response = $client->request();
387
- } catch (Zend_Http_Client_Exception $e) {
388
- $helper->log($e->getMessage(), Zend_Log::WARN);
389
- return false;
390
- }
391
-
392
- // Log response
393
- $helper->log(
394
- sprintf(self::LOG_API_RESPONSE, $response->getStatus(), $client->getUri()->__toString(), $response->getBody()),
395
- Zend_Log::DEBUG
396
- );
397
-
398
- return $response;
399
- }
400
-
401
- /**
402
- * Refreshes and saves the OAuth Access Token
403
- *
404
- * @param string $scope
405
- * @param int $scopeId
406
- * @param int $storeId
407
- * @return bool
408
- */
409
- protected function _refreshToken($scope, $scopeId, $storeId)
410
- {
411
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
412
- $helper = Mage::helper('createsend');
413
-
414
- // refresh access token
415
- $response = $this->call(
416
- Zend_Http_Client::POST,
417
- 'token',
418
- array(),
419
- array(
420
- 'grant_type' => 'refresh_token',
421
- 'refresh_token' => $helper->getOAuthRefreshToken($storeId),
422
- ),
423
- $scope,
424
- $scopeId
425
- );
426
-
427
- return $helper->saveOauthTokenData($response['data'], $scope, $scopeId);
428
- }
429
-
430
- /**
431
- * Updates the webhooks based for scope/scopeId.
432
- *
433
- * @param string $scope
434
- * @param int $scopeId
435
- * @return array|null
436
- */
437
- public function updateWebhooks($scope, $scopeId)
438
- {
439
- $data = array(
440
- 'success' => false,
441
- 'data' => null
442
- );
443
-
444
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
445
- $scopeModel = Mage::getModel('createsend/config_scope');
446
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
447
- $store = Mage::app()->getStore($storeId);
448
-
449
- $webhookUrl = Mage::getUrl('createsend/webhooks/index', array('_store' => $store));
450
-
451
- /** @var Mage_Core_Model_Config $configSingleton */
452
- $configSingleton = Mage::getConfig();
453
-
454
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
455
- $helper = Mage::helper('createsend');
456
-
457
- $webhookEnabled = $helper->isWebhookEnabled($storeId);
458
-
459
- // Magento's normal config system will inherit all values from whatever parent object sets them. While this
460
- // is OK for usage we cannot delete or manipulate a webhook based on an inherited value. Therefore we call
461
- // a method that directly queries the core_config_data table, based on the scope values in the request.
462
- $listId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID, $scope, $scopeId);
463
-
464
- if ($listId === false) {
465
- $data['data']['Message'] = sprintf(self::ERR_NO_LIST_ID_AT_SCOPE, $scope, $scopeId);
466
- return $data;
467
- }
468
-
469
- /** @var Campaignmonitor_Createsend_Model_Api $api */
470
- $api = Mage::getModel('createsend/api');
471
-
472
- $this->deleteAllWebhooks($listId, $scope, $scopeId);
473
-
474
- if ($webhookEnabled) {
475
- $result = $api->call(
476
- Zend_Http_Client::POST,
477
- "lists/{$listId}/webhooks",
478
- array(
479
- 'Events' => array(
480
- Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_SUBSCRIBE,
481
- Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_UPDATE,
482
- Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_DEACTIVATE
483
- ),
484
- 'Url' => $webhookUrl,
485
- 'PayloadFormat' => Campaignmonitor_Createsend_Model_Api::WEBHOOK_PAYLOAD_FORMAT_JSON
486
- ),
487
- array(),
488
- $scope,
489
- $scopeId
490
- );
491
-
492
- if ($result['success'] === false) {
493
- return $result;
494
- }
495
-
496
- $configSingleton->saveConfig(
497
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID,
498
- $result['data']['Message'], $scope, $scopeId
499
- );
500
-
501
- $helper->log(sprintf(self::LOG_CREATED_WEBHOOK, $result['data']['Message']));
502
-
503
- $data['success'] = true;
504
- $data['data']['Message'] = sprintf(self::LOG_CREATED_WEBHOOK, $result['data']['Message']);
505
- } else {
506
- $data['success'] = true;
507
- $data['data']['Message'] = self::LOG_WEBHOOKS_NOT_ENABLED;
508
- }
509
-
510
- return $data;
511
- }
512
-
513
- /**
514
- * Deletes all webhooks registered for the list.
515
- *
516
- * @param string $listId Campaign Monitor List ID
517
- * @param string $scope
518
- * @param int $scopeId
519
- */
520
- public function deleteAllWebhooks($listId, $scope, $scopeId)
521
- {
522
- /** @var Campaignmonitor_Createsend_Model_Api $api */
523
- $api = Mage::getModel('createsend/api');
524
-
525
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
526
- $helper = Mage::helper("createsend");
527
-
528
- // Get webhook id from config data and try to remove it
529
- $webhookId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
530
- if ($webhookId !== false) {
531
- Mage::getConfig()->deleteConfig($helper::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
532
- $this->_deleteWebhook($listId, $webhookId, $scope, $scopeId);
533
- }
534
-
535
- // Then try to remove all other remaining webhooks, if any
536
- $result = $api->call(
537
- Zend_Http_Client::GET,
538
- "lists/{$listId}/webhooks",
539
- array(),
540
- array(),
541
- $scope,
542
- $scopeId
543
- );
544
-
545
- if ($result['success'] !== false) {
546
- foreach ($result['data'] as $webhookData) {
547
- $webhookId = $webhookData['WebhookID'];
548
- $this->_deleteWebhook($listId, $webhookId, $scope, $scopeId);
549
- }
550
- }
551
- }
552
-
553
- /**
554
- * Deletes a webhook previously registered in Campaign Monitor.
555
- *
556
- * @param string $listId Campaign Monitor List ID
557
- * @param string $webhookId The webhook to de-register
558
- * @param string $scope
559
- * @param int $scopeId
560
- * @return array|null
561
- */
562
- protected function _deleteWebhook($listId, $webhookId, $scope, $scopeId)
563
- {
564
- /** @var Campaignmonitor_Createsend_Model_Api $api */
565
- $api = Mage::getModel('createsend/api');
566
-
567
- /** @var Mage_Core_Model_Config $configSingleton */
568
- $configSingleton = Mage::getConfig();
569
-
570
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
571
- $helper = Mage::helper('createsend');
572
-
573
- $result = $api->call(
574
- Zend_Http_Client::DELETE,
575
- "lists/{$listId}/webhooks/{$webhookId}",
576
- array(),
577
- array(),
578
- $scope,
579
- $scopeId
580
- );
581
-
582
- if ($result['success'] === false) {
583
- return $result;
584
- } else {
585
- $helper->log(sprintf(self::LOG_DELETED_WEBHOOK, $webhookId), Zend_Log::NOTICE);
586
- }
587
-
588
- $savedWebhookId = $helper->getScopedConfig(
589
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID, $scope, $scopeId
590
- );
591
-
592
- if ($savedWebhookId === $webhookId) {
593
- $configSingleton->deleteConfig($helper::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
594
- }
595
-
596
- return $result;
597
- }
598
-
599
- /**
600
- * Subscribes an email address to CM. The list ID will be retrieved from the configuration using the scope/scopeId.
601
- *
602
- * @param string $email The email address to subscribe
603
- * @param string $scope
604
- * @param int $scopeId
605
- * @return array|null
606
- */
607
- public function subscribe($email, $scope, $scopeId)
608
- {
609
- $subscriberData = array(
610
- 'EmailAddress' => $email,
611
- 'Resubscribe' => true,
612
- 'RestartSubscriptionBasedAutoresponders' => true
613
- );
614
-
615
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
616
- $helper = Mage::helper("createsend");
617
-
618
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
619
- $scopeModel = Mage::getModel('createsend/config_scope');
620
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
621
- $websiteId = $scopeModel->getWebsiteIdFromScope($scope, $scopeId);
622
-
623
- /* @var Mage_Customer_Model_Customer $customer */
624
- $customer = Mage::getModel("customer/customer")
625
- ->setWebsiteId($websiteId)
626
- ->loadByEmail($email);
627
-
628
- if ($customer->getId()) {
629
- $subscriberData['Name'] = $customer->getName();
630
- }
631
-
632
- $subscriberData['CustomFields'] =
633
- Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customer);
634
-
635
- return $this->call(
636
- Zend_Http_Client::POST,
637
- 'subscribers/' . $helper->getListId($storeId),
638
- $subscriberData,
639
- array(),
640
- $scope,
641
- $scopeId
642
- );
643
-
644
- Mage::log( print_r( $subscriberData, true ), null, 'subscribe.log', true );
645
- }
646
-
647
- /**
648
- * Un-subscribes an email address from CM list of scope/scopeId
649
- *
650
- * @param string $email The email to un-subscribe from CM
651
- * @param string $scope
652
- * @param int $scopeId
653
- * @return array|null
654
- */
655
- public function unsubscribe($email, $scope, $scopeId)
656
- {
657
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
658
- $helper = Mage::helper("createsend");
659
-
660
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
661
- $scopeModel = Mage::getModel('createsend/config_scope');
662
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
663
-
664
-
665
- return $this->call(
666
- Zend_Http_Client::POST,
667
- "subscribers/{$helper->getListId($storeId)}/unsubscribe",
668
- array(
669
- 'EmailAddress' => $email
670
- ),
671
- array(),
672
- $scope,
673
- $scopeId
674
- );
675
- }
676
-
677
- /**
678
- * Returns the Campaign Monitor Custom Field name with the prefix and truncated to max length
679
- *
680
- * @param $fieldName
681
- * @return string
682
- */
683
- public function formatCustomFieldName($fieldName)
684
- {
685
- $customName = self::CM_CUSTOM_FIELD_PREFIX . $fieldName;
686
-
687
- // Return only up to CM_MAX_CUSTOM_FIELD_LENGTH characters to avoid error
688
- return substr($customName, 0, self::CM_MAX_CUSTOM_FIELD_LENGTH);
689
- }
690
-
691
- /**
692
- * Creates a Campaign Monitor custom field on the list defined in the scope/scopeid using the API.
693
- *
694
- * @param string $fieldName The name of the custom field to be created.
695
- * @param string $dataType Data Type, can be either: Text, Number, Date, MultiSelectOne, MultiSelectMany, Country or USState.
696
- * @param array $options Array of options if type is MultiSelectOne or MultiSelectMany
697
- * @param bool $isVisibleInPreferenceCenter Whether the field should be visible in the subscriber preference center.
698
- * @param string $scope Scope
699
- * @param int $scopeId Scope ID
700
- * @return array|null
701
- */
702
- public function createCustomField($fieldName, $dataType, $options, $isVisibleInPreferenceCenter, $scope, $scopeId)
703
- {
704
- $params = array(
705
- 'FieldName' => $this->formatCustomFieldName($fieldName),
706
- 'DataType' => $dataType,
707
- 'VisibleInPreferenceCenter' => $isVisibleInPreferenceCenter,
708
- );
709
- if (is_array($options) && count($options)
710
- && ($dataType == self::FIELD_TYPE_SELECT_ONE || $dataType == self::FIELD_TYPE_SELECT_MANY)
711
- ){
712
- $params['Options'] = $options;
713
- }
714
-
715
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
716
- $helper = Mage::helper("createsend");
717
-
718
- $listId = $helper->getScopedConfig($helper::XML_PATH_LIST_ID, $scope, $scopeId);
719
-
720
- return $this->call(
721
- Zend_Http_Client::POST,
722
- "lists/{$listId}/customfields",
723
- $params,
724
- array(),
725
- $scope,
726
- $scopeId
727
- );
728
- }
729
-
730
- /**
731
- * Creates Campaign Monitor customer custom fields on the list id defined in the scope.
732
- *
733
- * @param string $scope
734
- * @param int $scopeId
735
- * @return array List of errors, grouped by error message
736
- */
737
- public function createCustomerCustomFields($scope, $scopeId)
738
- {
739
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
740
- $helper = Mage::helper('createsend');
741
-
742
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
743
- $scopeModel = Mage::getSingleton('createsend/config_scope');
744
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
745
-
746
- /** @var Campaignmonitor_Createsend_Model_Config_CustomerAttributes $attrSource */
747
- $attrSource = Mage::getSingleton('createsend/config_customerAttributes');
748
-
749
- $linkedAttributes = @unserialize(Mage::getStoreConfig($helper::XML_PATH_M_TO_CM_ATTRIBUTES, $storeId));
750
-
751
- $errors = array();
752
-
753
- foreach ($linkedAttributes as $la) {
754
-
755
- $la['magento'] = htmlspecialchars( $la['magento'] );
756
- $magentoAtt = $la['magento'];
757
- $cmAtt = $attrSource->getCustomFieldName($la['magento'], true);
758
- $dataType = $attrSource->getFieldType($magentoAtt);
759
- $options = $attrSource->getFieldOptions($magentoAtt);
760
-
761
- $reply = $this->createCustomField(
762
- $cmAtt,
763
- $dataType,
764
- $options,
765
- false,
766
- $scope,
767
- $scopeId
768
- );
769
-
770
- if ($reply['success'] === false) {
771
- // Ignore 'field name already exists' errors
772
- if ($reply['data']['Code'] != self::CODE_FIELD_KEY_EXISTS) {
773
- $message = $reply['data']['Message'];
774
-
775
- if (!isset($errors[$message])) {
776
- $errors[$message] = array();
777
- }
778
-
779
- $errors[$message][] = $this->formatCustomFieldName($cmAtt);
780
- }
781
- }
782
- }
783
-
784
- return $errors;
785
- }
786
-
787
- /**
788
- * Creates Campaign Monitor wishlist custom fields on the list id defined in the scope.
789
- *
790
- * @param string $scope
791
- * @param int $scopeId
792
- * @return array List of errors, grouped by error message
793
- */
794
- public function createWishlistCustomFields($scope, $scopeId)
795
- {
796
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
797
- $helper = Mage::helper('createsend');
798
-
799
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
800
- $scopeModel = Mage::getSingleton('createsend/config_scope');
801
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
802
-
803
- /** @var Campaignmonitor_Createsend_Model_Config_ProductAttributes $attrSource */
804
- $attrSource = Mage::getSingleton('createsend/config_productAttributes');
805
-
806
- // Create wishlist custom fields
807
- $maxWishlistItems = $helper->getMaxWistlistItems($storeId);
808
- $productAttributes = @unserialize(Mage::getStoreConfig($helper::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES, $storeId));
809
-
810
- if (empty($productAttributes) && empty($maxWishlistItems)) {
811
- return array();
812
- }
813
-
814
- $options = array();
815
- $errors = array();
816
-
817
- foreach ($productAttributes as $pa) {
818
- $magentoAtt = $pa['magento'];
819
- $cmAtt = $attrSource->getCustomFieldName($pa['magento'], true);
820
- $dataType = $attrSource->getFieldType($magentoAtt);
821
-
822
- for ($i = 1; $i <= $maxWishlistItems; $i++) {
823
- $fieldName = sprintf(self::WISHLIST_CUSTOM_FIELD_PATTERN, self::WISHLIST_CUSTOM_FIELD_PREFIX, $i, $cmAtt);
824
- $reply = $this->createCustomField(
825
- $fieldName,
826
- $dataType,
827
- $options,
828
- false,
829
- $scope,
830
- $scopeId
831
- );
832
-
833
- if ($reply['success'] === false) {
834
- // Ignore 'field name already exists' errors
835
- if ($reply['data']['Code'] != self::CODE_FIELD_KEY_EXISTS) {
836
- $message = $reply['data']['Message'];
837
-
838
- if (!isset($errors[$message])) {
839
- $errors[$message] = array();
840
- }
841
-
842
- $errors[$message][] = $this->formatCustomFieldName($cmAtt);
843
- }
844
- }
845
- }
846
- }
847
-
848
- return $errors;
849
- }
850
-
851
- /**
852
- * Creates all the example segments as defined in Campaignmonitor_Createsend_Model_Config_ExampleSegments.
853
- * Returns an array of status and message per segment creation call.
854
- *
855
- * @param string $scope
856
- * @param int $scopeId
857
- * @return array
858
- */
859
- public function createExampleSegments($scope, $scopeId)
860
- {
861
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
862
- $helper = Mage::helper("createsend");
863
-
864
- $listId = $helper->getScopedConfig($helper::XML_PATH_LIST_ID, $scope, $scopeId);
865
-
866
- $segments = Mage::getSingleton('createsend/config_exampleSegments')->getExampleSegments();
867
-
868
- /** @var array $response */
869
- $responses = array();
870
-
871
- foreach ($segments as $segmentKey => $segment) {
872
- $reply = $this->call(
873
- Zend_Http_Client::POST,
874
- 'segments/' . $listId,
875
- $segment,
876
- array(),
877
- $scope,
878
- $scopeId
879
- );
880
-
881
- $status = 'success';
882
- if ($reply['success'] === false) {
883
- $status = 'error';
884
- $message = sprintf(self::ERR_UNABLE_TO_CREATE_SEGMENT, $segment['Title'], $reply['data']['Message']);
885
- switch ($reply['data']['Code']) {
886
- case self::CODE_DUPLICATE_SEGMENT_TITLE:
887
- $status = 'warning';
888
- $message .= ' -- ' . self::ERR_SEGMENT_EXISTS;
889
- break;
890
- case self::CODE_INVALID_SEGMENT_RULES:
891
- $pos = strpos($segmentKey, ':');
892
- if ($pos === FALSE) {
893
- $requiredFields = $segmentKey;
894
- } else {
895
- $requiredFields = substr($segmentKey, $pos + 1);
896
- }
897
-
898
- $message .= ' -- ' . sprintf(self::ERR_CREATE_CUSTOM_FIELDS, $requiredFields);
899
- break;
900
- }
901
- } else {
902
- $message = sprintf(self::LOG_SEGMENT_CREATED, $segment['Title']);
903
- }
904
-
905
- $responses[] = array(
906
- 'status' => $status,
907
- 'message' => $message
908
- );
909
- }
910
-
911
- return $responses;
912
- }
913
- }
 
 
 
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Responsible for making calls and getting responses from the Campaign Monitor API.
20
+ * Uses the key authorization mechanism (see the link for further information)
21
+ *
22
+ * @link https://www.campaignmonitor.com/api/getting-started/
23
+ */
24
+ class Campaignmonitor_Createsend_Model_Api
25
+ {
26
+ const API_BASE_URL = 'https://api.createsend.com/';
27
+ const API_PATH = 'api/v3.1/';
28
+ const API_OAUTH_PATH = 'oauth/';
29
+
30
+ const CODE_SUBSCRIBER_NOT_IN_LIST = 203;
31
+ const CODE_DUPLICATE_SEGMENT_TITLE = 275;
32
+ const CODE_INVALID_SEGMENT_RULES = 277;
33
+ const CODE_FIELD_KEY_EXISTS = 255;
34
+
35
+ const ERR_API_REQUEST = 'API Error: %s';
36
+ const ERR_INVALID_HTTP_METHOD = 'The method "%s" is not an acceptable HTTP method';
37
+ const ERR_INVALID_AUTH_METHOD = 'The method "%s" is not an acceptable Authentication method';
38
+ const ERR_INVALID_JSON = 'The following response is not valid JSON: "%s"';
39
+ const ERR_ID_REQUIRED = 'The "%s" data is required to make this call';
40
+ const ERR_NO_LIST_ID_AT_SCOPE = 'There is no list ID defined at this %s/%s scope. Cannot create webhook';
41
+ const ERR_CANNOT_UPDATE_WEBHOOK = 'API Error: Cannot update webhook (%s)';
42
+ const ERR_CANNOT_LIST_WEBHOOKS = 'API Error: Cannot list webhook (%s)';
43
+
44
+ const ERR_CANNOT_CREATE_CUSTOM_FIELD = 'API Error: Cannot create custom field: (%1$s): %2$s';
45
+ const ERR_CREATE_CUSTOM_FIELDS = 'Please create these custom fields on the Campaign Monitor list: %s';
46
+ const ERR_SEGMENT_EXISTS = 'A segment with the same title already exists on this list.';
47
+ const ERR_UNABLE_TO_CREATE_SEGMENT = 'Unable to create segment (%1$s): %2$s';
48
+ const LOG_SEGMENT_CREATED = 'Segment successfully created (%s).';
49
+
50
+ const LOG_API_REQUEST = 'API Request %s @ %s: %s';
51
+ const LOG_API_RESPONSE = 'API Response (%s) @ %s: %s';
52
+ const LOG_CREATED_WEBHOOK = 'Created webhook with ID "%s"';
53
+ const LOG_DELETED_WEBHOOK = 'Deleted webhook with ID "%s"';
54
+ const LOG_WEBHOOKS_NOT_ENABLED = 'Webhooks not enabled.';
55
+
56
+ const WEBHOOK_EVENT_SUBSCRIBE = 'Subscribe';
57
+ const WEBHOOK_EVENT_UPDATE = 'Update';
58
+ const WEBHOOK_EVENT_DEACTIVATE = 'Deactivate';
59
+
60
+ const SUBSCRIBER_STATUS_ACTIVE = 'Active';
61
+ const SUBSCRIBER_STATUS_DELETED = 'Deleted';
62
+
63
+ const WEBHOOK_STATUS_ACTIVE = 'Active';
64
+ const WEBHOOK_STATUS_UNSUBSCRIBED = 'Unsubscribed';
65
+ const WEBHOOK_STATUS_DELETED = 'Deleted';
66
+
67
+ const WEBHOOK_PAYLOAD_FORMAT_JSON = 'Json';
68
+
69
+ const OAUTH_API_TOKEN_REQUEST = 'oauth_token';
70
+
71
+ const FIELD_TYPE_TEXT = 'Text';
72
+ const FIELD_TYPE_NUMBER = 'Number';
73
+ const FIELD_TYPE_DATE = 'Date';
74
+ const FIELD_TYPE_SELECT_ONE = 'MultiSelectOne';
75
+ const FIELD_TYPE_SELECT_MANY = 'MultiSelectMany';
76
+ const FIELD_TYPE_COUNTRY = 'Country';
77
+
78
+ const CM_MAX_CUSTOM_FIELD_LENGTH = 100;
79
+ const CM_CUSTOM_FIELD_PREFIX = 'Magento ';
80
+
81
+ const WISHLIST_CUSTOM_FIELD_PREFIX = 'Wishlist Item';
82
+ const WISHLIST_CUSTOM_FIELD_PATTERN = '%1$s %2$s %3$s';
83
+
84
+ const USER_AGENT_STRING = 'CM_Magento_Extension; Magento %s; Extension %s; List ID %s';
85
+
86
+ // Methods used by the API
87
+ /** @var array */
88
+ protected $_supportedMethods = array(
89
+ Zend_Http_Client::DELETE,
90
+ Zend_Http_Client::GET,
91
+ Zend_Http_Client::POST,
92
+ Zend_Http_Client::PUT
93
+ );
94
+
95
+ // Permissions to be requested when authenticating via OAuth
96
+ /** @var array */
97
+ protected $_oauthPermissions = array(
98
+ 'ManageLists',
99
+ 'ImportSubscribers',
100
+ 'ViewTransactional',
101
+ 'SendTransactional'
102
+ );
103
+
104
+ /**
105
+ * Returns the URL for the OAuth Controller
106
+ *
107
+ * @param string $scope
108
+ * @param int $scopeId
109
+ * @return string
110
+ */
111
+ public function getOauthRedirectUri($scope, $scopeId)
112
+ {
113
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
114
+ $scopeModel = Mage::getModel('createsend/config_scope');
115
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
116
+
117
+ $url = Mage::getUrl(
118
+ 'createsend/oauth/getToken',
119
+ array(
120
+ '_nosid' => true,
121
+ '_store' => $storeId,
122
+ '_type' => 'direct_link'
123
+ )
124
+ );
125
+
126
+ return $url;
127
+ }
128
+
129
+ /**
130
+ * Returns the URL Address for the Campaign Monitor OAuth Permission Request Page,
131
+ * including all the GET parameters required by the Campaign Monitor API for OAuth
132
+ *
133
+ * @link https://www.campaignmonitor.com/api/getting-started/#authenticating_with_oauth
134
+ *
135
+ * @param string $scope
136
+ * @param int $scopeId
137
+ * @return string
138
+ */
139
+ public function getOauthPermissionRequestUrl($scope, $scopeId)
140
+ {
141
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
142
+ $helper = Mage::helper('createsend');
143
+
144
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
145
+ $scopeModel = Mage::getModel('createsend/config_scope');
146
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
147
+
148
+ return self::API_BASE_URL . self::API_OAUTH_PATH . '?' . http_build_query (
149
+ array(
150
+ 'type' => 'web_server',
151
+ 'client_id' => $helper->getOAuthClientId($storeId),
152
+ 'redirect_uri' => $this->getOauthRedirectUri($scope, $scopeId),
153
+ 'scope' => implode(',', $this->_oauthPermissions),
154
+ 'state' => implode(',', array($scope, $scopeId))
155
+ )
156
+ );
157
+ }
158
+
159
+ /**
160
+ * Calculate the version of Magento through a checking of arbitrary magento characteristics.
161
+ *
162
+ * @return string
163
+ */
164
+ public function getMagentoVersion()
165
+ {
166
+ $version = Mage::getVersion();
167
+ $edition = 'ce';
168
+
169
+ if (version_compare($version, '1.7.0.0', '>=')) {
170
+ // version 1.7 has a special method for finding the edition
171
+ $edition = Mage::getEdition();
172
+
173
+ return sprintf('%s %s', $edition, $version);
174
+ }
175
+
176
+ // If the version is above 1.6.0.0 it might be professional or enterprise.
177
+ if (version_compare($version, '1.6.0.0', '>=')) {
178
+
179
+ try {
180
+ // Calculate whether the install has gift cards. if it doesn't, it's community.
181
+ $hasGiftcards = false;
182
+ try {
183
+ $hasGiftcards = Mage::getModel('enterprise_giftcard/giftcard');
184
+ } catch (Exception $exception) {
185
+ return sprintf('%s %s', $edition, $version);
186
+ }
187
+
188
+ if ($hasGiftcards) {
189
+ // Check whether the installation has the enterprise search observer. Only enterprise has this.
190
+ $hasSolr = Mage::getModel('enterprise_search/observer');
191
+
192
+ if ($hasSolr) {
193
+ $edition = 'ee';
194
+ } else {
195
+ $edition = 'pe';
196
+ }
197
+ } else {
198
+ $edition = 'ce';
199
+ }
200
+ } catch(Exception $e){
201
+ Mage::logException($e);
202
+ }
203
+ }
204
+ return sprintf('%s %s', $edition, $version);
205
+ }
206
+
207
+ /**
208
+ * Responsible for providing an interface to the API and parsing the data returned from the API into a manageable
209
+ * format.
210
+ *
211
+ * If the API returns a JSON object that is just a string that string will be in the [data][Message] key. This key
212
+ * is also responsible for error messages if the API request fails as well as error messages the API returns.
213
+ *
214
+ * Returns an array of the form
215
+ * [success] => bool
216
+ * [status_code] => int
217
+ * [data] => array
218
+ * [Message] => string
219
+ * [DataA] => Returned field
220
+ * [DataB] => Returned field
221
+ *
222
+ * @param string $method The HTTP method to use. Accepted methods are defined at the top of this class and constants
223
+ * are available in the Zend_Http_Client class.
224
+ * @param string $endpoint The API endpoint to query; for example: lists/1eax88123c7cedasdas70fd05saxqwbf
225
+ * @param array $postFields An array of fields to send the end point
226
+ * @param array $queryParams An array of URI query parameters to append to the URI
227
+ * @param string $scope 'default' | 'websites' | 'stores'
228
+ * @param int $scopeId The id of the scope
229
+ *
230
+ * @return array|null
231
+ */
232
+ public function call($method, $endpoint, $postFields = array(), $queryParams = array(), $scope, $scopeId)
233
+ {
234
+ /** @var array $data */
235
+ $data = array(
236
+ 'success' => false,
237
+ 'status_code' => null,
238
+ 'data' => null
239
+ );
240
+
241
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
242
+ $helper = Mage::helper('createsend');
243
+
244
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
245
+ $scopeModel = Mage::getModel('createsend/config_scope');
246
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
247
+
248
+ $authenticationMethod = $helper->getAuthenticationMethod($storeId);
249
+ if ($endpoint === 'token') {
250
+ $authenticationMethod = self::OAUTH_API_TOKEN_REQUEST;
251
+ }
252
+
253
+ $apiKeyOrToken = '';
254
+
255
+ switch ($authenticationMethod) {
256
+ case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_API_KEY:
257
+ $apiKeyOrToken = $helper->getApiKey($scope, $scopeId);
258
+
259
+ if (!$apiKeyOrToken) {
260
+ $data['data']['Message'] = 'No API key set in configuration';
261
+ return $data;
262
+ }
263
+
264
+ break;
265
+
266
+ case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_OAUTH:
267
+ $expiry = new DateTime($helper->getOAuthAccessTokenExpiryDate($storeId));
268
+ $now = new DateTime();
269
+ if ($now > $expiry) {
270
+ $this->_refreshToken($scope, $scopeId, $storeId);
271
+ }
272
+
273
+ $apiKeyOrToken = $helper->getOAuthAccessToken($storeId);
274
+
275
+ if (!$apiKeyOrToken) {
276
+ $data['data']['Message'] = 'No OAuth Token yet. Please request and allow OAuth permission first.';
277
+ return $data;
278
+ }
279
+
280
+ break;
281
+ }
282
+
283
+ $mageVersion = strtoupper($this->getMagentoVersion());
284
+ $extVersion = Mage::getConfig()->getModuleConfig("Campaignmonitor_Createsend")->version;
285
+ $listId = $helper->getListId($storeId);
286
+
287
+ $userAgent = sprintf(self::USER_AGENT_STRING, $mageVersion, $extVersion, $listId);
288
+
289
+ $response = $this->_callApi($authenticationMethod, $apiKeyOrToken, $method, $endpoint, $postFields,
290
+ $queryParams, $userAgent);
291
+ if (!$response) {
292
+ $data['data']['Message'] = 'An error occurred during the request.';
293
+ return $data;
294
+ }
295
+
296
+ $data['success'] = $response->isSuccessful();
297
+
298
+ // Get the response content. The response will either be a JSON encoded object or nothing, depending on the
299
+ // call. The only situation in which content is not JSON is a request URI without a .json file suffix.
300
+ if (stripos($response->getHeader('content-type'), 'application/json') !== null) {
301
+ try {
302
+ $returnContent = Zend_Json::decode($response->getBody());
303
+
304
+ // The API sometimes returns a string, not an array.
305
+ if (is_array($returnContent)) {
306
+ $data['data'] = $returnContent;
307
+ } else {
308
+ $data['data'] = array('Message' => $returnContent);
309
+ }
310
+ } catch (Zend_Json_Exception $e) {
311
+ $helper->log(sprintf(self::ERR_INVALID_JSON, $response->getBody()));
312
+ }
313
+ }
314
+
315
+ $data['status_code'] = $response->getStatus();
316
+ return $data;
317
+ }
318
+
319
+ /**
320
+ * Responsible for making the actual calls to the API. The authorization method is either "API Key" or "OAuth"
321
+ * authorisation method, and documentation can be found at the link below.
322
+ *
323
+ * @link https://www.campaignmonitor.com/api/
324
+ *
325
+ * @param string $authenticationMethod The Authentication Method to be used for the request ('api_key' or 'oauth')
326
+ * @param string $apiKeyOrToken The API key or OAuth Access Token required to make the API request
327
+ * @param string $method The HTTP Method for the request. Valid methods are documented at the top of the class
328
+ * @param string $endpoint The endpoint to make the request of
329
+ * @param array $postFields The fields that should be posted to the end point
330
+ * @param array $queryParams Any query params that should be appended to the request
331
+ * @param string $userAgent HTTP User-Agent to use
332
+ *
333
+ * @return Zend_Http_Response
334
+ * @throws Mage_Core_Exception if the method given is not an accepted method
335
+ * @throws Zend_Http_Client_Exception if something goes wrong during the connection
336
+ */
337
+ protected function _callApi($authenticationMethod, $apiKeyOrToken, $method, $endpoint,
338
+ $postFields = array(), $queryParams = array(), $userAgent)
339
+ {
340
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
341
+ $helper = Mage::helper('createsend');
342
+
343
+ if (in_array($method, $this->_supportedMethods) === false) {
344
+ Mage::throwException(sprintf(self::ERR_INVALID_HTTP_METHOD, $method));
345
+ }
346
+
347
+ // Construct the client
348
+ $client = new Zend_Http_Client();
349
+ $client->setMethod($method);
350
+ $client->setConfig(array('useragent' => $userAgent));
351
+
352
+ $uri = self::API_BASE_URL . self::API_PATH . $endpoint . '.json';
353
+
354
+ switch ($authenticationMethod) {
355
+ case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_API_KEY:
356
+ $client->setAuth($apiKeyOrToken, null, Zend_Http_Client::AUTH_BASIC);
357
+ break;
358
+
359
+ case Campaignmonitor_Createsend_Model_Config_AuthenticationMethod::AUTHENTICATION_METHOD_OAUTH:
360
+ $client->setHeaders('Authorization', 'Bearer ' . $apiKeyOrToken);
361
+ break;
362
+
363
+ case self::OAUTH_API_TOKEN_REQUEST:
364
+ $uri = self::API_BASE_URL . self::API_OAUTH_PATH . $endpoint;
365
+ break;
366
+
367
+ default:
368
+ Mage::throwException(sprintf(self::ERR_INVALID_AUTH_METHOD, $authenticationMethod));
369
+ break;
370
+ }
371
+
372
+ if (count($queryParams) > 0) {
373
+ $uri .= '?' . http_build_query($queryParams);
374
+ }
375
+ $client->setUri($uri);
376
+
377
+ $payload = Zend_Json::encode($postFields);
378
+
379
+ // Optionally set the POST payload
380
+ if ($method === Zend_Http_Client::POST) {
381
+ $client->setRawData($payload, 'application/json');
382
+ }
383
+
384
+ // Log the request for debugging
385
+ $helper->log(
386
+ sprintf(self::LOG_API_REQUEST, $method, $client->getUri()->__toString(), $payload),
387
+ Zend_Log::DEBUG
388
+ );
389
+
390
+ try {
391
+ $response = $client->request();
392
+ } catch (Zend_Http_Client_Exception $e) {
393
+ $helper->log($e->getMessage(), Zend_Log::WARN);
394
+ return false;
395
+ }
396
+
397
+ // Log response
398
+ $helper->log(
399
+ sprintf(self::LOG_API_RESPONSE, $response->getStatus(), $client->getUri()->__toString(), $response->getBody()),
400
+ Zend_Log::DEBUG
401
+ );
402
+
403
+ return $response;
404
+ }
405
+
406
+ /**
407
+ * Refreshes and saves the OAuth Access Token
408
+ *
409
+ * @param string $scope
410
+ * @param int $scopeId
411
+ * @param int $storeId
412
+ * @return bool
413
+ */
414
+ protected function _refreshToken($scope, $scopeId, $storeId)
415
+ {
416
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
417
+ $helper = Mage::helper('createsend');
418
+
419
+ // refresh access token
420
+ $response = $this->call(
421
+ Zend_Http_Client::POST,
422
+ 'token',
423
+ array(),
424
+ array(
425
+ 'grant_type' => 'refresh_token',
426
+ 'refresh_token' => $helper->getOAuthRefreshToken($storeId),
427
+ ),
428
+ $scope,
429
+ $scopeId
430
+ );
431
+
432
+ return $helper->saveOauthTokenData($response['data'], $scope, $scopeId);
433
+ }
434
+
435
+ /**
436
+ * Updates the webhooks based for scope/scopeId.
437
+ *
438
+ * @param string $scope
439
+ * @param int $scopeId
440
+ * @return array|null
441
+ */
442
+ public function updateWebhooks($scope, $scopeId)
443
+ {
444
+ $data = array(
445
+ 'success' => false,
446
+ 'data' => null
447
+ );
448
+
449
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
450
+ $scopeModel = Mage::getModel('createsend/config_scope');
451
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
452
+ $store = Mage::app()->getStore($storeId);
453
+
454
+ $webhookUrl = Mage::getUrl('createsend/webhooks/index', array('_store' => $store));
455
+
456
+ /** @var Mage_Core_Model_Config $configSingleton */
457
+ $configSingleton = Mage::getConfig();
458
+
459
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
460
+ $helper = Mage::helper('createsend');
461
+
462
+ $webhookEnabled = $helper->isWebhookEnabled($storeId);
463
+
464
+ // Magento's normal config system will inherit all values from whatever parent object sets them. While this
465
+ // is OK for usage we cannot delete or manipulate a webhook based on an inherited value. Therefore we call
466
+ // a method that directly queries the core_config_data table, based on the scope values in the request.
467
+ $listId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID, $scope, $scopeId);
468
+
469
+ if ($listId === false) {
470
+ $data['data']['Message'] = sprintf(self::ERR_NO_LIST_ID_AT_SCOPE, $scope, $scopeId);
471
+ return $data;
472
+ }
473
+
474
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
475
+ $api = Mage::getModel('createsend/api');
476
+
477
+ $this->deleteAllWebhooks($listId, $scope, $scopeId);
478
+
479
+ if ($webhookEnabled) {
480
+ $result = $api->call(
481
+ Zend_Http_Client::POST,
482
+ "lists/{$listId}/webhooks",
483
+ array(
484
+ 'Events' => array(
485
+ Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_SUBSCRIBE,
486
+ Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_UPDATE,
487
+ Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_DEACTIVATE
488
+ ),
489
+ 'Url' => $webhookUrl,
490
+ 'PayloadFormat' => Campaignmonitor_Createsend_Model_Api::WEBHOOK_PAYLOAD_FORMAT_JSON
491
+ ),
492
+ array(),
493
+ $scope,
494
+ $scopeId
495
+ );
496
+
497
+ if ($result['success'] === false) {
498
+ return $result;
499
+ }
500
+
501
+ $configSingleton->saveConfig(
502
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID,
503
+ $result['data']['Message'], $scope, $scopeId
504
+ );
505
+
506
+ $helper->log(sprintf(self::LOG_CREATED_WEBHOOK, $result['data']['Message']));
507
+
508
+ $data['success'] = true;
509
+ $data['data']['Message'] = sprintf(self::LOG_CREATED_WEBHOOK, $result['data']['Message']);
510
+ } else {
511
+ $data['success'] = true;
512
+ $data['data']['Message'] = self::LOG_WEBHOOKS_NOT_ENABLED;
513
+ }
514
+
515
+ return $data;
516
+ }
517
+
518
+ /**
519
+ * Deletes all webhooks registered for the list.
520
+ *
521
+ * @param string $listId Campaign Monitor List ID
522
+ * @param string $scope
523
+ * @param int $scopeId
524
+ */
525
+ public function deleteAllWebhooks($listId, $scope, $scopeId)
526
+ {
527
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
528
+ $api = Mage::getModel('createsend/api');
529
+
530
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
531
+ $helper = Mage::helper("createsend");
532
+
533
+ // Get webhook id from config data and try to remove it
534
+ $webhookId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
535
+ if ($webhookId !== false) {
536
+ Mage::getConfig()->deleteConfig($helper::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
537
+ $this->_deleteWebhook($listId, $webhookId, $scope, $scopeId);
538
+ }
539
+
540
+ // Then try to remove all other remaining webhooks, if any
541
+ $result = $api->call(
542
+ Zend_Http_Client::GET,
543
+ "lists/{$listId}/webhooks",
544
+ array(),
545
+ array(),
546
+ $scope,
547
+ $scopeId
548
+ );
549
+
550
+ if ($result['success'] !== false) {
551
+ foreach ($result['data'] as $webhookData) {
552
+ $webhookId = $webhookData['WebhookID'];
553
+ $this->_deleteWebhook($listId, $webhookId, $scope, $scopeId);
554
+ }
555
+ }
556
+ }
557
+
558
+ /**
559
+ * Deletes a webhook previously registered in Campaign Monitor.
560
+ *
561
+ * @param string $listId Campaign Monitor List ID
562
+ * @param string $webhookId The webhook to de-register
563
+ * @param string $scope
564
+ * @param int $scopeId
565
+ * @return array|null
566
+ */
567
+ protected function _deleteWebhook($listId, $webhookId, $scope, $scopeId)
568
+ {
569
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
570
+ $api = Mage::getModel('createsend/api');
571
+
572
+ /** @var Mage_Core_Model_Config $configSingleton */
573
+ $configSingleton = Mage::getConfig();
574
+
575
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
576
+ $helper = Mage::helper('createsend');
577
+
578
+ $result = $api->call(
579
+ Zend_Http_Client::DELETE,
580
+ "lists/{$listId}/webhooks/{$webhookId}",
581
+ array(),
582
+ array(),
583
+ $scope,
584
+ $scopeId
585
+ );
586
+
587
+ if ($result['success'] === false) {
588
+ return $result;
589
+ } else {
590
+ $helper->log(sprintf(self::LOG_DELETED_WEBHOOK, $webhookId), Zend_Log::NOTICE);
591
+ }
592
+
593
+ $savedWebhookId = $helper->getScopedConfig(
594
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID, $scope, $scopeId
595
+ );
596
+
597
+ if ($savedWebhookId === $webhookId) {
598
+ $configSingleton->deleteConfig($helper::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
599
+ }
600
+
601
+ return $result;
602
+ }
603
+
604
+ /**
605
+ * Subscribes an email address to CM. The list ID will be retrieved from the configuration using the scope/scopeId.
606
+ *
607
+ * @param string $email The email address to subscribe
608
+ * @param string $scope
609
+ * @param int $scopeId
610
+ * @return array|null
611
+ */
612
+ public function subscribe($email, $scope, $scopeId)
613
+ {
614
+ $subscriberData = array(
615
+ 'EmailAddress' => $email,
616
+ 'Resubscribe' => true,
617
+ 'RestartSubscriptionBasedAutoresponders' => true
618
+ );
619
+
620
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
621
+ $helper = Mage::helper("createsend");
622
+
623
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
624
+ $scopeModel = Mage::getModel('createsend/config_scope');
625
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
626
+ $websiteId = $scopeModel->getWebsiteIdFromScope($scope, $scopeId);
627
+
628
+ /* @var Mage_Customer_Model_Customer $customer */
629
+ $customer = Mage::getModel("customer/customer")
630
+ ->setWebsiteId($websiteId)
631
+ ->loadByEmail($email);
632
+
633
+ if ($customer->getId()) {
634
+ $subscriberData['Name'] = $customer->getName();
635
+ }
636
+
637
+ $subscriberData['CustomFields'] =
638
+ Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customer);
639
+
640
+ return $this->call(
641
+ Zend_Http_Client::POST,
642
+ 'subscribers/' . $helper->getListId($storeId),
643
+ $subscriberData,
644
+ array(),
645
+ $scope,
646
+ $scopeId
647
+ );
648
+ }
649
+
650
+ /**
651
+ * Un-subscribes an email address from CM list of scope/scopeId
652
+ *
653
+ * @param string $email The email to un-subscribe from CM
654
+ * @param string $scope
655
+ * @param int $scopeId
656
+ * @return array|null
657
+ */
658
+ public function unsubscribe($email, $scope, $scopeId)
659
+ {
660
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
661
+ $helper = Mage::helper("createsend");
662
+
663
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
664
+ $scopeModel = Mage::getModel('createsend/config_scope');
665
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
666
+
667
+
668
+ return $this->call(
669
+ Zend_Http_Client::POST,
670
+ "subscribers/{$helper->getListId($storeId)}/unsubscribe",
671
+ array(
672
+ 'EmailAddress' => $email
673
+ ),
674
+ array(),
675
+ $scope,
676
+ $scopeId
677
+ );
678
+ }
679
+
680
+ /**
681
+ * Returns the Campaign Monitor Custom Field name with the prefix and truncated to max length
682
+ *
683
+ * @param $fieldName
684
+ * @return string
685
+ */
686
+ public function formatCustomFieldName($fieldName)
687
+ {
688
+ $customName = self::CM_CUSTOM_FIELD_PREFIX . $fieldName;
689
+
690
+ // Return only up to CM_MAX_CUSTOM_FIELD_LENGTH characters to avoid error
691
+ return substr($customName, 0, self::CM_MAX_CUSTOM_FIELD_LENGTH);
692
+ }
693
+
694
+ /**
695
+ * Creates a Campaign Monitor custom field on the list defined in the scope/scopeid using the API.
696
+ *
697
+ * @param string $fieldName The name of the custom field to be created.
698
+ * @param string $dataType Data Type, can be either: Text, Number, Date, MultiSelectOne, MultiSelectMany, Country or USState.
699
+ * @param array $options Array of options if type is MultiSelectOne or MultiSelectMany
700
+ * @param bool $isVisibleInPreferenceCenter Whether the field should be visible in the subscriber preference center.
701
+ * @param string $scope Scope
702
+ * @param int $scopeId Scope ID
703
+ * @return array|null
704
+ */
705
+ public function createCustomField($fieldName, $dataType, $options, $isVisibleInPreferenceCenter, $scope, $scopeId)
706
+ {
707
+ $params = array(
708
+ 'FieldName' => $this->formatCustomFieldName($fieldName),
709
+ 'DataType' => $dataType,
710
+ 'VisibleInPreferenceCenter' => $isVisibleInPreferenceCenter,
711
+ );
712
+ if (is_array($options) && count($options)
713
+ && ($dataType == self::FIELD_TYPE_SELECT_ONE || $dataType == self::FIELD_TYPE_SELECT_MANY)
714
+ ){
715
+ $params['Options'] = $options;
716
+ }
717
+
718
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
719
+ $helper = Mage::helper("createsend");
720
+
721
+ $listId = $helper->getScopedConfig($helper::XML_PATH_LIST_ID, $scope, $scopeId);
722
+
723
+ return $this->call(
724
+ Zend_Http_Client::POST,
725
+ "lists/{$listId}/customfields",
726
+ $params,
727
+ array(),
728
+ $scope,
729
+ $scopeId
730
+ );
731
+ }
732
+
733
+ /**
734
+ * Creates Campaign Monitor customer custom fields on the list id defined in the scope.
735
+ *
736
+ * @param string $scope
737
+ * @param int $scopeId
738
+ * @return array List of errors, grouped by error message
739
+ */
740
+ public function createCustomerCustomFields($scope, $scopeId)
741
+ {
742
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
743
+ $helper = Mage::helper('createsend');
744
+
745
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
746
+ $scopeModel = Mage::getSingleton('createsend/config_scope');
747
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
748
+
749
+ /** @var Campaignmonitor_Createsend_Model_Config_CustomerAttributes $attrSource */
750
+ $attrSource = Mage::getSingleton('createsend/config_customerAttributes');
751
+
752
+ $linkedAttributes = @unserialize(Mage::getStoreConfig($helper::XML_PATH_M_TO_CM_ATTRIBUTES, $storeId));
753
+
754
+ $errors = array();
755
+
756
+ foreach ($linkedAttributes as $la) {
757
+
758
+ $la['magento'] = htmlspecialchars( $la['magento'] );
759
+ $magentoAtt = $la['magento'];
760
+ $cmAtt = $attrSource->getCustomFieldName($la['magento'], true);
761
+ $dataType = $attrSource->getFieldType($magentoAtt);
762
+ $options = $attrSource->getFieldOptions($magentoAtt);
763
+
764
+ $reply = $this->createCustomField(
765
+ $cmAtt,
766
+ $dataType,
767
+ $options,
768
+ false,
769
+ $scope,
770
+ $scopeId
771
+ );
772
+
773
+ if ($reply['success'] === false) {
774
+ // Ignore 'field name already exists' errors
775
+ if ($reply['data']['Code'] != self::CODE_FIELD_KEY_EXISTS) {
776
+ $message = $reply['data']['Message'];
777
+
778
+ if (!isset($errors[$message])) {
779
+ $errors[$message] = array();
780
+ }
781
+
782
+ $errors[$message][] = $this->formatCustomFieldName($cmAtt);
783
+ }
784
+ }
785
+ }
786
+
787
+ return $errors;
788
+ }
789
+
790
+ /**
791
+ * Creates Campaign Monitor wishlist custom fields on the list id defined in the scope.
792
+ *
793
+ * @param string $scope
794
+ * @param int $scopeId
795
+ * @return array List of errors, grouped by error message
796
+ */
797
+ public function createWishlistCustomFields($scope, $scopeId)
798
+ {
799
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
800
+ $helper = Mage::helper('createsend');
801
+
802
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
803
+ $scopeModel = Mage::getSingleton('createsend/config_scope');
804
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
805
+
806
+ /** @var Campaignmonitor_Createsend_Model_Config_ProductAttributes $attrSource */
807
+ $attrSource = Mage::getSingleton('createsend/config_productAttributes');
808
+
809
+ // Create wishlist custom fields
810
+ $maxWishlistItems = $helper->getMaxWistlistItems($storeId);
811
+ $productAttributes = @unserialize(Mage::getStoreConfig($helper::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES, $storeId));
812
+
813
+ if (empty($productAttributes) && empty($maxWishlistItems)) {
814
+ return array();
815
+ }
816
+
817
+ $options = array();
818
+ $errors = array();
819
+
820
+ foreach ($productAttributes as $pa) {
821
+ $magentoAtt = $pa['magento'];
822
+ $cmAtt = $attrSource->getCustomFieldName($pa['magento'], true);
823
+ $dataType = $attrSource->getFieldType($magentoAtt);
824
+
825
+ for ($i = 1; $i <= $maxWishlistItems; $i++) {
826
+ $fieldName = sprintf(self::WISHLIST_CUSTOM_FIELD_PATTERN, self::WISHLIST_CUSTOM_FIELD_PREFIX, $i, $cmAtt);
827
+ $reply = $this->createCustomField(
828
+ $fieldName,
829
+ $dataType,
830
+ $options,
831
+ false,
832
+ $scope,
833
+ $scopeId
834
+ );
835
+
836
+ if ($reply['success'] === false) {
837
+ // Ignore 'field name already exists' errors
838
+ if ($reply['data']['Code'] != self::CODE_FIELD_KEY_EXISTS) {
839
+ $message = $reply['data']['Message'];
840
+
841
+ if (!isset($errors[$message])) {
842
+ $errors[$message] = array();
843
+ }
844
+
845
+ $errors[$message][] = $this->formatCustomFieldName($cmAtt);
846
+ }
847
+ }
848
+ }
849
+ }
850
+
851
+ return $errors;
852
+ }
853
+
854
+ /**
855
+ * Creates all the example segments as defined in Campaignmonitor_Createsend_Model_Config_ExampleSegments.
856
+ * Returns an array of status and message per segment creation call.
857
+ *
858
+ * @param string $scope
859
+ * @param int $scopeId
860
+ * @return array
861
+ */
862
+ public function createExampleSegments($scope, $scopeId)
863
+ {
864
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
865
+ $helper = Mage::helper("createsend");
866
+
867
+ $listId = $helper->getScopedConfig($helper::XML_PATH_LIST_ID, $scope, $scopeId);
868
+
869
+ $segments = Mage::getSingleton('createsend/config_exampleSegments')->getExampleSegments();
870
+
871
+ /** @var array $response */
872
+ $responses = array();
873
+
874
+ foreach ($segments as $segmentKey => $segment) {
875
+ $reply = $this->call(
876
+ Zend_Http_Client::POST,
877
+ 'segments/' . $listId,
878
+ $segment,
879
+ array(),
880
+ $scope,
881
+ $scopeId
882
+ );
883
+
884
+ $status = 'success';
885
+ if ($reply['success'] === false) {
886
+ $status = 'error';
887
+ $message = sprintf(self::ERR_UNABLE_TO_CREATE_SEGMENT, $segment['Title'], $reply['data']['Message']);
888
+ switch ($reply['data']['Code']) {
889
+ case self::CODE_DUPLICATE_SEGMENT_TITLE:
890
+ $status = 'warning';
891
+ $message .= ' -- ' . self::ERR_SEGMENT_EXISTS;
892
+ break;
893
+ case self::CODE_INVALID_SEGMENT_RULES:
894
+ $pos = strpos($segmentKey, ':');
895
+ if ($pos === FALSE) {
896
+ $requiredFields = $segmentKey;
897
+ } else {
898
+ $requiredFields = substr($segmentKey, $pos + 1);
899
+ }
900
+
901
+ $message .= ' -- ' . sprintf(self::ERR_CREATE_CUSTOM_FIELDS, $requiredFields);
902
+ break;
903
+ }
904
+ } else {
905
+ $message = sprintf(self::LOG_SEGMENT_CREATED, $segment['Title']);
906
+ }
907
+
908
+ $responses[] = array(
909
+ 'status' => $status,
910
+ 'message' => $message
911
+ );
912
+ }
913
+
914
+ return $responses;
915
+ }
916
+ }
app/code/community/Campaignmonitor/Createsend/Model/Api/Observer.php CHANGED
@@ -1,351 +1,351 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Responsible for taking action using the api model as a result of some dispatched Magento event
20
- */
21
- class Campaignmonitor_Createsend_Model_Api_Observer
22
- {
23
- const ERR_CANNOT_CREATE_SUBSCRIBER = 'Api Error: Could not create subscription for "%s" ("%s")';
24
- const ERR_NO_EMAIL_PARAMETER = 'There was no email parameter supplied in this request';
25
-
26
- const MSG_CANNOT_CREATE_SUBSCRIBER = 'Could not create subscriber "%s": An api error occurred: %s';
27
-
28
- const LOG_ADD_SUBSCRIBER = 'Adding newsletter subscription via frontend Sign up block for "%s"';
29
- const LOG_CUSTOMER_NOT_LOGGED_IN = 'Not subscribed, customer is not logged in: "%s"';
30
-
31
- const MSG_NEW_LIST_CREATED = 'New Campaign Monitor list created.';
32
- const MSG_CONNECT_SUCCESS = 'Your Magento account has been successfully connected, please allow some time for your data to be synced.';
33
- const MSG_PRE_CREATED_CONFIG = 'To help get you started we\'ve already mapped some of your subscriber data and created pre-packaged segments in Campaign Monitor, <a href="https://login.createsend.com/l" target="_blank">log in to your account</a> to check them out.';
34
-
35
- const SUBSCRIBER_DEFAULT_NAME = '(Guest)';
36
-
37
- /**
38
- * Updates the Deactivate webhook on a config change based on the value of that config
39
- *
40
- * @param Varien_Event_Observer $observer
41
- * @listen admin_system_config_changed_section_createsend_general
42
- * @throws Mage_Core_Exception if the API returns a bad result
43
- */
44
- public function checkConfig(Varien_Event_Observer $observer)
45
- {
46
- list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')
47
- ->_getScope($observer->getWebsite(), $observer->getStore());
48
-
49
- $request = Mage::app()->getRequest();
50
- $section = $request->getUserParam('section');
51
- $website = $request->getUserParam('website');
52
- $store = $request->getUserParam('store');
53
-
54
- /** @var Mage_Core_Model_Config_Data $configData */
55
- $configData = Mage::getModel('adminhtml/config_data')
56
- ->setSection($section)
57
- ->setWebsite($website)
58
- ->setStore($store)
59
- ->load();
60
-
61
- // Do nothing unless there is a LIST ID configured for this scope.
62
- if (!isset($configData[Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID])) {
63
- return;
64
- }
65
-
66
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
67
- $helper = Mage::helper('createsend');
68
-
69
- $listId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID, $scope, $scopeId);
70
-
71
- // Create new list if requested
72
- /** @var Campaignmonitor_Createsend_Helper_Api $apiHelper */
73
- $apiHelper = Mage::helper('createsend/api');
74
-
75
- if ($listId === $apiHelper::ID_CREATE_NEW_LIST
76
- && isset($configData[Campaignmonitor_Createsend_Helper_Data::XML_PATH_NEW_LIST_NAME])) {
77
-
78
- $newList = $configData[Campaignmonitor_Createsend_Helper_Data::XML_PATH_NEW_LIST_NAME];
79
-
80
- /** @var $api Campaignmonitor_Createsend_Model_Api */
81
- $api = Mage::getModel('createsend/api');
82
-
83
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $configScope */
84
- $configScope = Mage::getSingleton('createsend/config_scope');
85
- $storeId = $configScope->getStoreIdFromScope($scope, $scopeId);
86
-
87
- $clientId = $helper->getApiClientId($storeId);
88
- $params = array(
89
- 'Title' => $newList
90
- );
91
- $reply = $api->call(
92
- Zend_Http_Client::POST,
93
- "lists/${clientId}",
94
- $params,
95
- array(),
96
- $scope,
97
- $scopeId
98
- );
99
-
100
- if ($reply['success'] === false) {
101
- Mage::getSingleton('adminhtml/session')->addError(
102
- sprintf($api::ERR_API_REQUEST, $reply['data']['Message'])
103
- );
104
- } else {
105
- // Successfully created new list, save the List ID
106
- $listId = $reply['data']['Message'];
107
- Mage::getConfig()->saveConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID, $listId, $scope, $scopeId);
108
- }
109
- }
110
-
111
- /** @var Campaignmonitor_Createsend_Model_Api $api */
112
- $api = Mage::getModel('createsend/api');
113
-
114
- // Check if API config is complete and complete list set up
115
- if ($helper->isCompleteConfig($scope, $scopeId)) {
116
- /** @var Campaignmonitor_Createsend_Helper_Config $configHelper */
117
- $configHelper = Mage::helper('createsend/config');
118
-
119
- $flagClass = 'createsend/config_listFlag';
120
- $listFlagData = $configHelper->getFlagData($flagClass, $listId);
121
- if ($listFlagData === FALSE) {
122
- // Display message the first time list set up is complete
123
- Mage::getSingleton('adminhtml/session')->addSuccess(self::MSG_CONNECT_SUCCESS);
124
- Mage::getSingleton('adminhtml/session')->addSuccess(self::MSG_PRE_CREATED_CONFIG);
125
-
126
- $listFlagData = array(
127
- 'scope' => $scope,
128
- 'scopeId' => $scopeId,
129
- );
130
-
131
- $configHelper->addFlagData($flagClass, $listId, $listFlagData);
132
- }
133
-
134
- if ($helper->isSubscriberSynchronisationEnabled()) {
135
- // Set the flag to synchronise the list for the first time
136
- if (!array_key_exists(Campaignmonitor_Createsend_Helper_Config::INDEX_INITIAL_SYNC, $listFlagData)) {
137
- $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_INITIAL_SYNC] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_NEW;
138
- $configHelper->addFlagData($flagClass, $listId, $listFlagData);
139
- }
140
- }
141
-
142
- // Auto-create custom fields if not yet done for the List ID
143
- if (!array_key_exists(Campaignmonitor_Createsend_Helper_Config::INDEX_CUSTOM_FIELDS, $listFlagData)
144
- || $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_CUSTOM_FIELDS] === Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_NEW
145
- ) {
146
- $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_CUSTOM_FIELDS] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_PROCESSING;
147
- $configHelper->addFlagData($flagClass, $listId, $listFlagData);
148
-
149
- // Add default custom fields in configuration
150
- /** @var Campaignmonitor_Createsend_Model_Customer_Observer $observer */
151
- $observer = Mage::getModel('createsend/customer_observer');
152
- $observer->createAllCustomFields($scope, $scopeId);
153
-
154
- $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_CUSTOM_FIELDS] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_DONE;
155
- $configHelper->addFlagData($flagClass, $listId, $listFlagData);
156
- }
157
-
158
- // Auto-create example segments if not yet done for the List ID
159
- if (!array_key_exists(Campaignmonitor_Createsend_Helper_Config::INDEX_EXAMPLE_SEGMENTS, $listFlagData)
160
- || $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_EXAMPLE_SEGMENTS] === Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_NEW
161
- ) {
162
- $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_EXAMPLE_SEGMENTS] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_PROCESSING;
163
- $configHelper->addFlagData($flagClass, $listId, $listFlagData);
164
-
165
- $responses = $api->createExampleSegments($scope, $scopeId);
166
-
167
- foreach ($responses as $response) {
168
- switch ($response['status']) {
169
- case 'warning':
170
- Mage::getSingleton('adminhtml/session')->addWarning($response['message']);
171
- break;
172
- case 'error':
173
- Mage::getSingleton('adminhtml/session')->addError($response['message']);
174
- break;
175
- }
176
- }
177
-
178
- $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_EXAMPLE_SEGMENTS] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_DONE;
179
- $configHelper->addFlagData($flagClass, $listId, $listFlagData);
180
- }
181
- }
182
-
183
- $webhookId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
184
- $webhookEnabled = $helper->isWebhookEnabled($store);
185
-
186
- // Create webhook if none found on this scope
187
- if ($webhookEnabled && $webhookId === false) {
188
- $result = $api->updateWebhooks($scope, $scopeId);
189
- if ($result['success'] === false) {
190
- Mage::throwException(
191
- sprintf(Campaignmonitor_Createsend_Model_Api::ERR_CANNOT_UPDATE_WEBHOOK, $result['data']['Message'])
192
- );
193
- }
194
- } else {
195
- if (!$webhookEnabled && $webhookId !== false) {
196
- // There is a stored webhook ID for this scope, but webhooks are disabled,
197
- // so delete all registered webhooks for this scope
198
- $api->deleteAllWebhooks($listId, $scope, $scopeId);
199
- }
200
- }
201
- }
202
-
203
- /**
204
- * Responsible for handling the updating of users in Campaign Monitor before they are updated in Magento.
205
- *
206
- * @param Varien_Event_Observer $observer
207
- * @listen controller_action_predispatch_adminhtml_newsletter_subscriber_massUnsubscribe
208
- */
209
- public function massUnsubscribeUsers(Varien_Event_Observer $observer)
210
- {
211
- /** @var Mage_Core_Controller_Request_Http $request */
212
- $subscribers = $observer->getControllerAction()->getRequest()->getPost('subscriber');
213
- if (!is_array($subscribers)) {
214
- Mage::getModel('adminhtml/session')
215
- ->addNotice('Could not unsubscribe subscribers from Createsend: No subscribers selected');
216
- return;
217
- }
218
-
219
- foreach ($subscribers as $subscriber) {
220
- /** @var Mage_Newsletter_Model_Subscriber $newsletter */
221
- $newsletter = Mage::getModel('newsletter/subscriber');
222
- $newsletter->load($subscriber);
223
-
224
- if ($newsletter->getCustomerId() != 0) {
225
- // Registered customer
226
- $scope = 'stores';
227
- $scopeId = $newsletter->getStoreId();
228
- } else {
229
- if ($newsletter->getStoreId()) {
230
- $scope = 'stores';
231
- $scopeId = $newsletter->getStoreId();
232
- } else {
233
- // Guest user, use default scope (cannot get storeId from subscribeNewUser() observer)
234
- $scope = 'default';
235
- $scopeId = 0;
236
- }
237
- }
238
-
239
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
240
- $scopeModel = Mage::getModel('createsend/config_scope');
241
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
242
-
243
- Mage::getModel('createsend/api')->call(
244
- Zend_Http_Client::POST,
245
- "subscribers/" . Mage::helper('createsend')->getListId($storeId) . "/unsubscribe",
246
- array(
247
- 'EmailAddress' => $newsletter->getEmail()
248
- ),
249
- array(),
250
- $scope,
251
- $scopeId
252
- );
253
- }
254
- }
255
-
256
- /**
257
- * Subscribes a new user when given a request event
258
- *
259
- * @param Varien_Event_Observer $observer
260
- * @listen controller_action_predispatch_newsletter_subscriber_new
261
- */
262
- public function subscribeNewUser(Varien_Event_Observer $observer)
263
- {
264
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
265
- $helper = Mage::helper('createsend');
266
- $email = $observer->getControllerAction()->getRequest()->getPost('email');
267
-
268
- // If the parameter is missing, do nothing
269
- if (!$email) {
270
- $helper->log(self::ERR_NO_EMAIL_PARAMETER, Zend_Log::WARN);
271
- return;
272
- }
273
-
274
- $subscriberData = array(
275
- 'Name' => self::SUBSCRIBER_DEFAULT_NAME,
276
- 'EmailAddress' => $email,
277
- 'Resubscribe' => true,
278
- 'RestartSubscriptionBasedAutoresponders' => true
279
- );
280
-
281
- // $observer scope always returns default/0
282
- $scope = 'default';
283
- $scopeId = 0;
284
-
285
- /** @var Mage_Customer_Helper_Data $customerHelper */
286
- $customerHelper = Mage::helper('customer');
287
- if ($customerHelper->isLoggedIn()) {
288
- /** @var Mage_Customer_Model_Customer $customerModel */
289
- $customerModel = $customerHelper->getCustomer();
290
- $subscriberData['Name'] = $customerModel->getName();
291
- $subscriberData['CustomFields'] = Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customerModel);
292
-
293
- // Use store scope only if customer is using the same email address.
294
- // Otherwise, use default/0 as above
295
- if (strcasecmp($email, $customerModel->getEmail()) === 0) {
296
- $scope = 'stores';
297
- // TODO: use current store id?
298
- $scopeId = $customerModel->getStoreId();
299
- }
300
- } else {
301
- /** @var Mage_Customer_Model_Customer $customer */
302
- $customer = Mage::getModel("customer/customer");
303
- $customer->setWebsiteId(Mage::app()->getWebsite('admin')->getId());
304
- $customer->loadByEmail($email);
305
- $subscriberData['CustomFields'] = Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customer);
306
-
307
- if ($customer->getId()) {
308
- // Do not subscribe to newsletter if customer is not logged in and a customer email is used.
309
- // Magento does not subscribe a registered customer to newsletter if customer is not logged in.
310
- $helper->log(sprintf(self::LOG_CUSTOMER_NOT_LOGGED_IN, $email), Zend_Log::WARN);
311
-
312
- return;
313
- } else {
314
- $scope = 'stores';
315
- $scopeId = Mage::app()->getStore()->getId();
316
- }
317
- }
318
-
319
- $helper->log(sprintf(self::LOG_ADD_SUBSCRIBER, $email));
320
-
321
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
322
- $scopeModel = Mage::getModel('createsend/config_scope');
323
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
324
-
325
- /** @var Campaignmonitor_Createsend_Model_Api $api */
326
- $api = Mage::getModel('createsend/api');
327
-
328
- $result = $api->call(
329
- Zend_Http_Client::POST,
330
- 'subscribers/' . $helper->getListId($storeId),
331
- $subscriberData,
332
- array(),
333
- $scope,
334
- $scopeId
335
- );
336
-
337
- if (!$result['success']) {
338
- // We don't know what the API is going to return to the user. For safety we indicate to the user it was
339
- // an API error, but log the API error as a warning.
340
- Mage::getSingleton('core/session')->addError(
341
- sprintf(self::MSG_CANNOT_CREATE_SUBSCRIBER, $email)
342
- );
343
-
344
- // Log more detailed information for debugging
345
- $helper->log(
346
- sprintf(self::ERR_CANNOT_CREATE_SUBSCRIBER, $email, $result['data']['Message']),
347
- Zend_Log::WARN
348
- );
349
- }
350
- }
351
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Responsible for taking action using the api model as a result of some dispatched Magento event
20
+ */
21
+ class Campaignmonitor_Createsend_Model_Api_Observer
22
+ {
23
+ const ERR_CANNOT_CREATE_SUBSCRIBER = 'Api Error: Could not create subscription for "%s" ("%s")';
24
+ const ERR_NO_EMAIL_PARAMETER = 'There was no email parameter supplied in this request';
25
+
26
+ const MSG_CANNOT_CREATE_SUBSCRIBER = 'Could not create subscriber "%s": An api error occurred: %s';
27
+
28
+ const LOG_ADD_SUBSCRIBER = 'Adding newsletter subscription via frontend Sign up block for "%s"';
29
+ const LOG_CUSTOMER_NOT_LOGGED_IN = 'Not subscribed, customer is not logged in: "%s"';
30
+
31
+ const MSG_NEW_LIST_CREATED = 'New Campaign Monitor list created.';
32
+ const MSG_CONNECT_SUCCESS = 'Your Magento account has been successfully connected, please allow some time for your data to be synced.';
33
+ const MSG_PRE_CREATED_CONFIG = 'To help get you started we\'ve already mapped some of your subscriber data and created pre-packaged segments in Campaign Monitor, <a href="https://login.createsend.com/l" target="_blank">log in to your account</a> to check them out.';
34
+
35
+ const SUBSCRIBER_DEFAULT_NAME = '(Guest)';
36
+
37
+ /**
38
+ * Updates the Deactivate webhook on a config change based on the value of that config
39
+ *
40
+ * @param Varien_Event_Observer $observer
41
+ * @listen admin_system_config_changed_section_createsend_general
42
+ * @throws Mage_Core_Exception if the API returns a bad result
43
+ */
44
+ public function checkConfig(Varien_Event_Observer $observer)
45
+ {
46
+ list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')
47
+ ->_getScope($observer->getWebsite(), $observer->getStore());
48
+
49
+ $request = Mage::app()->getRequest();
50
+ $section = $request->getUserParam('section');
51
+ $website = $request->getUserParam('website');
52
+ $store = $request->getUserParam('store');
53
+
54
+ /** @var Mage_Core_Model_Config_Data $configData */
55
+ $configData = Mage::getModel('adminhtml/config_data')
56
+ ->setSection($section)
57
+ ->setWebsite($website)
58
+ ->setStore($store)
59
+ ->load();
60
+
61
+ // Do nothing unless there is a LIST ID configured for this scope.
62
+ if (!isset($configData[Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID])) {
63
+ return;
64
+ }
65
+
66
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
67
+ $helper = Mage::helper('createsend');
68
+
69
+ $listId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID, $scope, $scopeId);
70
+
71
+ // Create new list if requested
72
+ /** @var Campaignmonitor_Createsend_Helper_Api $apiHelper */
73
+ $apiHelper = Mage::helper('createsend/api');
74
+
75
+ if ($listId === $apiHelper::ID_CREATE_NEW_LIST
76
+ && isset($configData[Campaignmonitor_Createsend_Helper_Data::XML_PATH_NEW_LIST_NAME])) {
77
+
78
+ $newList = $configData[Campaignmonitor_Createsend_Helper_Data::XML_PATH_NEW_LIST_NAME];
79
+
80
+ /** @var $api Campaignmonitor_Createsend_Model_Api */
81
+ $api = Mage::getModel('createsend/api');
82
+
83
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $configScope */
84
+ $configScope = Mage::getSingleton('createsend/config_scope');
85
+ $storeId = $configScope->getStoreIdFromScope($scope, $scopeId);
86
+
87
+ $clientId = $helper->getApiClientId($storeId);
88
+ $params = array(
89
+ 'Title' => $newList
90
+ );
91
+ $reply = $api->call(
92
+ Zend_Http_Client::POST,
93
+ "lists/{$clientId}",
94
+ $params,
95
+ array(),
96
+ $scope,
97
+ $scopeId
98
+ );
99
+
100
+ if ($reply['success'] === false) {
101
+ Mage::getSingleton('adminhtml/session')->addError(
102
+ sprintf($api::ERR_API_REQUEST, $reply['data']['Message'])
103
+ );
104
+ } else {
105
+ // Successfully created new list, save the List ID
106
+ $listId = $reply['data']['Message'];
107
+ Mage::getConfig()->saveConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID, $listId, $scope, $scopeId);
108
+ }
109
+ }
110
+
111
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
112
+ $api = Mage::getModel('createsend/api');
113
+
114
+ // Check if API config is complete and complete list set up
115
+ if ($helper->isCompleteConfig($scope, $scopeId)) {
116
+ /** @var Campaignmonitor_Createsend_Helper_Config $configHelper */
117
+ $configHelper = Mage::helper('createsend/config');
118
+
119
+ $flagClass = 'createsend/config_listFlag';
120
+ $listFlagData = $configHelper->getFlagData($flagClass, $listId);
121
+ if ($listFlagData === FALSE) {
122
+ // Display message the first time list set up is complete
123
+ Mage::getSingleton('adminhtml/session')->addSuccess(self::MSG_CONNECT_SUCCESS);
124
+ Mage::getSingleton('adminhtml/session')->addSuccess(self::MSG_PRE_CREATED_CONFIG);
125
+
126
+ $listFlagData = array(
127
+ 'scope' => $scope,
128
+ 'scopeId' => $scopeId,
129
+ );
130
+
131
+ $configHelper->addFlagData($flagClass, $listId, $listFlagData);
132
+ }
133
+
134
+ if ($helper->isSubscriberSynchronisationEnabled()) {
135
+ // Set the flag to synchronise the list for the first time
136
+ if (!array_key_exists(Campaignmonitor_Createsend_Helper_Config::INDEX_INITIAL_SYNC, $listFlagData)) {
137
+ $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_INITIAL_SYNC] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_NEW;
138
+ $configHelper->addFlagData($flagClass, $listId, $listFlagData);
139
+ }
140
+ }
141
+
142
+ // Auto-create custom fields if not yet done for the List ID
143
+ if (!array_key_exists(Campaignmonitor_Createsend_Helper_Config::INDEX_CUSTOM_FIELDS, $listFlagData)
144
+ || $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_CUSTOM_FIELDS] === Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_NEW
145
+ ) {
146
+ $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_CUSTOM_FIELDS] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_PROCESSING;
147
+ $configHelper->addFlagData($flagClass, $listId, $listFlagData);
148
+
149
+ // Add default custom fields in configuration
150
+ /** @var Campaignmonitor_Createsend_Model_Customer_Observer $observer */
151
+ $observer = Mage::getModel('createsend/customer_observer');
152
+ $observer->createAllCustomFields($scope, $scopeId);
153
+
154
+ $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_CUSTOM_FIELDS] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_DONE;
155
+ $configHelper->addFlagData($flagClass, $listId, $listFlagData);
156
+ }
157
+
158
+ // Auto-create example segments if not yet done for the List ID
159
+ if (!array_key_exists(Campaignmonitor_Createsend_Helper_Config::INDEX_EXAMPLE_SEGMENTS, $listFlagData)
160
+ || $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_EXAMPLE_SEGMENTS] === Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_NEW
161
+ ) {
162
+ $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_EXAMPLE_SEGMENTS] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_PROCESSING;
163
+ $configHelper->addFlagData($flagClass, $listId, $listFlagData);
164
+
165
+ $responses = $api->createExampleSegments($scope, $scopeId);
166
+
167
+ foreach ($responses as $response) {
168
+ switch ($response['status']) {
169
+ case 'warning':
170
+ Mage::getSingleton('adminhtml/session')->addWarning($response['message']);
171
+ break;
172
+ case 'error':
173
+ Mage::getSingleton('adminhtml/session')->addError($response['message']);
174
+ break;
175
+ }
176
+ }
177
+
178
+ $listFlagData[Campaignmonitor_Createsend_Helper_Config::INDEX_EXAMPLE_SEGMENTS] = Campaignmonitor_Createsend_Helper_Config::FLAG_STATUS_DONE;
179
+ $configHelper->addFlagData($flagClass, $listId, $listFlagData);
180
+ }
181
+ }
182
+
183
+ $webhookId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
184
+ $webhookEnabled = $helper->isWebhookEnabled($store);
185
+
186
+ // Create webhook if none found on this scope
187
+ if ($webhookEnabled && $webhookId === false) {
188
+ $result = $api->updateWebhooks($scope, $scopeId);
189
+ if ($result['success'] === false) {
190
+ Mage::throwException(
191
+ sprintf(Campaignmonitor_Createsend_Model_Api::ERR_CANNOT_UPDATE_WEBHOOK, $result['data']['Message'])
192
+ );
193
+ }
194
+ } else {
195
+ if (!$webhookEnabled && $webhookId !== false) {
196
+ // There is a stored webhook ID for this scope, but webhooks are disabled,
197
+ // so delete all registered webhooks for this scope
198
+ $api->deleteAllWebhooks($listId, $scope, $scopeId);
199
+ }
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Responsible for handling the updating of users in Campaign Monitor before they are updated in Magento.
205
+ *
206
+ * @param Varien_Event_Observer $observer
207
+ * @listen controller_action_predispatch_adminhtml_newsletter_subscriber_massUnsubscribe
208
+ */
209
+ public function massUnsubscribeUsers(Varien_Event_Observer $observer)
210
+ {
211
+ /** @var Mage_Core_Controller_Request_Http $request */
212
+ $subscribers = $observer->getControllerAction()->getRequest()->getPost('subscriber');
213
+ if (!is_array($subscribers)) {
214
+ Mage::getModel('adminhtml/session')
215
+ ->addNotice('Could not unsubscribe subscribers from Createsend: No subscribers selected');
216
+ return;
217
+ }
218
+
219
+ foreach ($subscribers as $subscriber) {
220
+ /** @var Mage_Newsletter_Model_Subscriber $newsletter */
221
+ $newsletter = Mage::getModel('newsletter/subscriber');
222
+ $newsletter->load($subscriber);
223
+
224
+ if ($newsletter->getCustomerId() != 0) {
225
+ // Registered customer
226
+ $scope = 'stores';
227
+ $scopeId = $newsletter->getStoreId();
228
+ } else {
229
+ if ($newsletter->getStoreId()) {
230
+ $scope = 'stores';
231
+ $scopeId = $newsletter->getStoreId();
232
+ } else {
233
+ // Guest user, use default scope (cannot get storeId from subscribeNewUser() observer)
234
+ $scope = 'default';
235
+ $scopeId = 0;
236
+ }
237
+ }
238
+
239
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
240
+ $scopeModel = Mage::getModel('createsend/config_scope');
241
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
242
+
243
+ Mage::getModel('createsend/api')->call(
244
+ Zend_Http_Client::POST,
245
+ "subscribers/" . Mage::helper('createsend')->getListId($storeId) . "/unsubscribe",
246
+ array(
247
+ 'EmailAddress' => $newsletter->getEmail()
248
+ ),
249
+ array(),
250
+ $scope,
251
+ $scopeId
252
+ );
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Subscribes a new user when given a request event
258
+ *
259
+ * @param Varien_Event_Observer $observer
260
+ * @listen controller_action_predispatch_newsletter_subscriber_new
261
+ */
262
+ public function subscribeNewUser(Varien_Event_Observer $observer)
263
+ {
264
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
265
+ $helper = Mage::helper('createsend');
266
+ $email = $observer->getControllerAction()->getRequest()->getPost('email');
267
+
268
+ // If the parameter is missing, do nothing
269
+ if (!$email) {
270
+ $helper->log(self::ERR_NO_EMAIL_PARAMETER, Zend_Log::WARN);
271
+ return;
272
+ }
273
+
274
+ $subscriberData = array(
275
+ 'Name' => self::SUBSCRIBER_DEFAULT_NAME,
276
+ 'EmailAddress' => $email,
277
+ 'Resubscribe' => true,
278
+ 'RestartSubscriptionBasedAutoresponders' => true
279
+ );
280
+
281
+ // $observer scope always returns default/0
282
+ $scope = 'default';
283
+ $scopeId = 0;
284
+
285
+ /** @var Mage_Customer_Helper_Data $customerHelper */
286
+ $customerHelper = Mage::helper('customer');
287
+ if ($customerHelper->isLoggedIn()) {
288
+ /** @var Mage_Customer_Model_Customer $customerModel */
289
+ $customerModel = $customerHelper->getCustomer();
290
+ $subscriberData['Name'] = $customerModel->getName();
291
+ $subscriberData['CustomFields'] = Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customerModel);
292
+
293
+ // Use store scope only if customer is using the same email address.
294
+ // Otherwise, use default/0 as above
295
+ if (strcasecmp($email, $customerModel->getEmail()) === 0) {
296
+ $scope = 'stores';
297
+ // TODO: use current store id?
298
+ $scopeId = $customerModel->getStoreId();
299
+ }
300
+ } else {
301
+ /** @var Mage_Customer_Model_Customer $customer */
302
+ $customer = Mage::getModel("customer/customer");
303
+ $customer->setWebsiteId(Mage::app()->getWebsite('admin')->getId());
304
+ $customer->loadByEmail($email);
305
+ $subscriberData['CustomFields'] = Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customer);
306
+
307
+ if ($customer->getId()) {
308
+ // Do not subscribe to newsletter if customer is not logged in and a customer email is used.
309
+ // Magento does not subscribe a registered customer to newsletter if customer is not logged in.
310
+ $helper->log(sprintf(self::LOG_CUSTOMER_NOT_LOGGED_IN, $email), Zend_Log::WARN);
311
+
312
+ return;
313
+ } else {
314
+ $scope = 'stores';
315
+ $scopeId = Mage::app()->getStore()->getId();
316
+ }
317
+ }
318
+
319
+ $helper->log(sprintf(self::LOG_ADD_SUBSCRIBER, $email));
320
+
321
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
322
+ $scopeModel = Mage::getModel('createsend/config_scope');
323
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
324
+
325
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
326
+ $api = Mage::getModel('createsend/api');
327
+
328
+ $result = $api->call(
329
+ Zend_Http_Client::POST,
330
+ 'subscribers/' . $helper->getListId($storeId),
331
+ $subscriberData,
332
+ array(),
333
+ $scope,
334
+ $scopeId
335
+ );
336
+
337
+ if (!$result['success']) {
338
+ // We don't know what the API is going to return to the user. For safety we indicate to the user it was
339
+ // an API error, but log the API error as a warning.
340
+ Mage::getSingleton('core/session')->addError(
341
+ sprintf(self::MSG_CANNOT_CREATE_SUBSCRIBER, $email, '')
342
+ );
343
+
344
+ // Log more detailed information for debugging
345
+ $helper->log(
346
+ sprintf(self::ERR_CANNOT_CREATE_SUBSCRIBER, $email, $result['data']['Message']),
347
+ Zend_Log::WARN
348
+ );
349
+ }
350
+ }
351
+ }
app/code/community/Campaignmonitor/Createsend/Model/Config/Api.php CHANGED
@@ -1,36 +1,36 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_Api
19
- {
20
- /**
21
- * @param Varien_Event_Observer $observer
22
- */
23
- public function addJavascriptBlock($observer)
24
- {
25
- $controller = $observer->getAction();
26
- $layout = $controller->getLayout();
27
-
28
- // Load only if in our section
29
- $params = $controller->getRequest()->getParams();
30
- if (array_key_exists('section', $params) && $params['section'] === 'createsend_general') {
31
- $block = $layout->createBlock('adminhtml/template');
32
- $block->setTemplate('campaignmonitor/createsend/apiclient.phtml');
33
- $layout->getBlock('js')->append($block);
34
- }
35
- }
36
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_Api
19
+ {
20
+ /**
21
+ * @param Varien_Event_Observer $observer
22
+ */
23
+ public function addJavascriptBlock($observer)
24
+ {
25
+ $controller = $observer->getAction();
26
+ $layout = $controller->getLayout();
27
+
28
+ // Load only if in our section
29
+ $params = $controller->getRequest()->getParams();
30
+ if (array_key_exists('section', $params) && $params['section'] === 'createsend_general') {
31
+ $block = $layout->createBlock('adminhtml/template');
32
+ $block->setTemplate('campaignmonitor/createsend/apiclient.phtml');
33
+ $layout->getBlock('js')->append($block);
34
+ }
35
+ }
36
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/Attributes/Abstract.php CHANGED
@@ -1,110 +1,110 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- abstract class Campaignmonitor_Createsend_Model_Config_Attributes_Abstract
19
- {
20
- /** @var array $_fields */
21
- protected $_fields;
22
-
23
- /** @var array $_customFieldNameMapping Custom field name for Magento attributes ["magento" => "campaignmonitor"] */
24
- protected $_customFieldNameMapping;
25
-
26
- /**
27
- * @return array
28
- */
29
- public function toOptionArray()
30
- {
31
- $optionArray = array();
32
-
33
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
34
- $helper = Mage::helper('createsend');
35
-
36
- foreach ($this->_fields as $key => $field) {
37
- $optionArray[] = array('value' => $key, 'label' => $helper->__($field['label']));
38
- }
39
-
40
- return $optionArray;
41
- }
42
-
43
- /**
44
- * Returns the field type for the attribute from the $_fields array.
45
- * Returns null if not found.
46
- *
47
- * @param $field
48
- * @return string|null
49
- */
50
- public function getFieldType($field)
51
- {
52
- if (isset($this->_fields[$field])) {
53
- return $this->_fields[$field]['type'];
54
- } else {
55
- return null;
56
- }
57
- }
58
-
59
- /**
60
- * Returns the display/frontend name for the attribute from the $_fields array.
61
- * Returns null if not found.
62
- *
63
- * @param $field
64
- * @return string|null
65
- */
66
- public function getFieldLabel($field)
67
- {
68
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
69
- $helper = Mage::helper('createsend');
70
-
71
- if (isset($this->_fields[$field])) {
72
- return $helper->__($this->_fields[$field]['label']);
73
- } else {
74
- return null;
75
- }
76
- }
77
-
78
- /**
79
- * Returns an array of string options for the field.
80
- * If the field is not a MultiSelectOne/MultiSelectMany, an empty array should be returned.
81
- * This function should be overridden if the subclass has attributes that are select options.
82
- *
83
- * @param string $field
84
- * @return array
85
- */
86
- public function getFieldOptions($field)
87
- {
88
- return array();
89
- }
90
-
91
- /**
92
- * Returns the Campaign Monitor custom field name given the Magento attribute name.
93
- *
94
- * @param string $field The Magento attribute name
95
- * @param bool $returnDefault If true, returns the default value. Otherwise, returns null.
96
- * @return null|string
97
- */
98
- public function getCustomFieldName($field, $returnDefault = true)
99
- {
100
- if (array_key_exists($field, $this->_customFieldNameMapping)) {
101
- return $this->_customFieldNameMapping[$field];
102
- } else {
103
- if ($returnDefault) {
104
- return $field;
105
- } else {
106
- return null;
107
- }
108
- }
109
- }
110
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ abstract class Campaignmonitor_Createsend_Model_Config_Attributes_Abstract
19
+ {
20
+ /** @var array $_fields */
21
+ protected $_fields;
22
+
23
+ /** @var array $_customFieldNameMapping Custom field name for Magento attributes ["magento" => "campaignmonitor"] */
24
+ protected $_customFieldNameMapping;
25
+
26
+ /**
27
+ * @return array
28
+ */
29
+ public function toOptionArray()
30
+ {
31
+ $optionArray = array();
32
+
33
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
34
+ $helper = Mage::helper('createsend');
35
+
36
+ foreach ($this->_fields as $key => $field) {
37
+ $optionArray[] = array('value' => $key, 'label' => $helper->__($field['label']));
38
+ }
39
+
40
+ return $optionArray;
41
+ }
42
+
43
+ /**
44
+ * Returns the field type for the attribute from the $_fields array.
45
+ * Returns null if not found.
46
+ *
47
+ * @param $field
48
+ * @return string|null
49
+ */
50
+ public function getFieldType($field)
51
+ {
52
+ if (isset($this->_fields[$field])) {
53
+ return $this->_fields[$field]['type'];
54
+ } else {
55
+ return null;
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Returns the display/frontend name for the attribute from the $_fields array.
61
+ * Returns null if not found.
62
+ *
63
+ * @param $field
64
+ * @return string|null
65
+ */
66
+ public function getFieldLabel($field)
67
+ {
68
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
69
+ $helper = Mage::helper('createsend');
70
+
71
+ if (isset($this->_fields[$field])) {
72
+ return $helper->__($this->_fields[$field]['label']);
73
+ } else {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Returns an array of string options for the field.
80
+ * If the field is not a MultiSelectOne/MultiSelectMany, an empty array should be returned.
81
+ * This function should be overridden if the subclass has attributes that are select options.
82
+ *
83
+ * @param string $field
84
+ * @return array
85
+ */
86
+ public function getFieldOptions($field)
87
+ {
88
+ return array();
89
+ }
90
+
91
+ /**
92
+ * Returns the Campaign Monitor custom field name given the Magento attribute name.
93
+ *
94
+ * @param string $field The Magento attribute name
95
+ * @param bool $returnDefault If true, returns the default value. Otherwise, returns null.
96
+ * @return null|string
97
+ */
98
+ public function getCustomFieldName($field, $returnDefault = true)
99
+ {
100
+ if (array_key_exists($field, $this->_customFieldNameMapping)) {
101
+ return $this->_customFieldNameMapping[$field];
102
+ } else {
103
+ if ($returnDefault) {
104
+ return $field;
105
+ } else {
106
+ return null;
107
+ }
108
+ }
109
+ }
110
+ }
app/code/community/Campaignmonitor/Createsend/Model/Config/AuthenticationMethod.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor authentication type selector
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Model_Config_AuthenticationMethod
23
- {
24
- const AUTHENTICATION_METHOD_API_KEY = 'api_key';
25
- const AUTHENTICATION_METHOD_OAUTH = 'oauth';
26
-
27
- /**
28
- * @return array
29
- */
30
- public function toOptionArray()
31
- {
32
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
33
- $helper = Mage::helper('createsend');
34
- return array(
35
- array(
36
- 'value' => self::AUTHENTICATION_METHOD_API_KEY,
37
- 'label' => $helper->__('API Key')
38
- ),
39
- array(
40
- 'value' => self::AUTHENTICATION_METHOD_OAUTH,
41
- 'label' => $helper->__('OAuth')
42
- ),
43
- );
44
- }
45
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor authentication type selector
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Model_Config_AuthenticationMethod
23
+ {
24
+ const AUTHENTICATION_METHOD_API_KEY = 'api_key';
25
+ const AUTHENTICATION_METHOD_OAUTH = 'oauth';
26
+
27
+ /**
28
+ * @return array
29
+ */
30
+ public function toOptionArray()
31
+ {
32
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
33
+ $helper = Mage::helper('createsend');
34
+ return array(
35
+ array(
36
+ 'value' => self::AUTHENTICATION_METHOD_API_KEY,
37
+ 'label' => $helper->__('API Key')
38
+ ),
39
+ array(
40
+ 'value' => self::AUTHENTICATION_METHOD_OAUTH,
41
+ 'label' => $helper->__('OAuth')
42
+ ),
43
+ );
44
+ }
45
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/Backend/Apikey.php CHANGED
@@ -1,52 +1,52 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_Backend_Apikey extends Mage_Core_Model_Config_Data
19
- {
20
- const ERR_INVALID_API_KEY = 'Invalid API Key: %s';
21
- const MSG_VALID_API_KEY = 'Valid API Key.';
22
- /**
23
- *
24
- * @return Mage_Core_Model_Abstract
25
- */
26
- protected function _afterSave()
27
- {
28
- $request = Mage::app()->getRequest();
29
- $website = $request->getUserParam('website');
30
- $store = $request->getUserParam('store');
31
- list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')->_getScope($website, $store);
32
-
33
- /** @var Campaignmonitor_Createsend_Helper_Api $apiHelper */
34
- $apiHelper = Mage::helper('createsend/api');
35
-
36
- // Test API Key by getting the list of clients
37
- $reply = $apiHelper->testApiKey($scope, $scopeId);
38
-
39
- if ($reply['success'] === false) {
40
- Mage::getSingleton('adminhtml/session')->addError(
41
- sprintf(self::ERR_INVALID_API_KEY, $reply['data']['Message'])
42
- );
43
- } else {
44
- // Display success message only when value is changed
45
- if ($this->isValueChanged()) {
46
- Mage::getSingleton('adminhtml/session')->addSuccess(sprintf(self::MSG_VALID_API_KEY));
47
- }
48
- }
49
-
50
- return parent::_afterSave();
51
- }
52
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_Backend_Apikey extends Mage_Core_Model_Config_Data
19
+ {
20
+ const ERR_INVALID_API_KEY = 'Invalid API Key: %s';
21
+ const MSG_VALID_API_KEY = 'Valid API Key.';
22
+ /**
23
+ *
24
+ * @return Mage_Core_Model_Abstract
25
+ */
26
+ protected function _afterSave()
27
+ {
28
+ $request = Mage::app()->getRequest();
29
+ $website = $request->getUserParam('website');
30
+ $store = $request->getUserParam('store');
31
+ list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')->_getScope($website, $store);
32
+
33
+ /** @var Campaignmonitor_Createsend_Helper_Api $apiHelper */
34
+ $apiHelper = Mage::helper('createsend/api');
35
+
36
+ // Test API Key by getting the list of clients
37
+ $reply = $apiHelper->testApiKey($scope, $scopeId);
38
+
39
+ if ($reply['success'] === false) {
40
+ Mage::getSingleton('adminhtml/session')->addError(
41
+ sprintf(self::ERR_INVALID_API_KEY, $reply['data']['Message'])
42
+ );
43
+ } else {
44
+ // Display success message only when value is changed
45
+ if ($this->isValueChanged()) {
46
+ Mage::getSingleton('adminhtml/session')->addSuccess(sprintf(self::MSG_VALID_API_KEY));
47
+ }
48
+ }
49
+
50
+ return parent::_afterSave();
51
+ }
52
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/Backend/Listid.php CHANGED
@@ -1,43 +1,43 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_Backend_Listid extends Mage_Core_Model_Config_Data
19
- {
20
- /**
21
- * If the List ID value is changed, delete all webhooks associated with the old List ID
22
- *
23
- * @return Mage_Core_Model_Abstract
24
- */
25
- protected function _afterSave()
26
- {
27
- if ($this->isValueChanged()) {
28
- $oldListId = $this->getOldValue();
29
-
30
- $request = Mage::app()->getRequest();
31
- $website = $request->getUserParam('website');
32
- $store = $request->getUserParam('store');
33
- list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')->_getScope($website, $store);
34
-
35
- /** @var Campaignmonitor_Createsend_Model_Api $api */
36
- $api = Mage::getModel('createsend/api');
37
-
38
- $api->deleteAllWebhooks($oldListId, $scope, $scopeId);
39
- }
40
-
41
- return parent::_afterSave();
42
- }
43
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_Backend_Listid extends Mage_Core_Model_Config_Data
19
+ {
20
+ /**
21
+ * If the List ID value is changed, delete all webhooks associated with the old List ID
22
+ *
23
+ * @return Mage_Core_Model_Abstract
24
+ */
25
+ protected function _afterSave()
26
+ {
27
+ if ($this->isValueChanged()) {
28
+ $oldListId = $this->getOldValue();
29
+
30
+ $request = Mage::app()->getRequest();
31
+ $website = $request->getUserParam('website');
32
+ $store = $request->getUserParam('store');
33
+ list($scope, $scopeId) = Mage::getSingleton('createsend/config_scope')->_getScope($website, $store);
34
+
35
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
36
+ $api = Mage::getModel('createsend/api');
37
+
38
+ $api->deleteAllWebhooks($oldListId, $scope, $scopeId);
39
+ }
40
+
41
+ return parent::_afterSave();
42
+ }
43
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/Backend/Source/Files.php CHANGED
@@ -1,81 +1,81 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_Backend_Source_Files extends Mage_Core_Model_Config_Data
19
- {
20
- /**
21
- * Options getter
22
- *
23
- * @return array
24
- */
25
- public function toOptionArray()
26
- {
27
- $directory = Mage::getBaseDir();
28
- $directory .= DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'log';
29
-
30
- if (is_dir( $directory )) {
31
- $files = array_diff( scandir( $directory ), array( '..', '.' ) );
32
-
33
- if (!empty( $files )) {
34
-
35
- $options = array();
36
- foreach ($files as $filename) {
37
- $options[] = array( 'value' => $filename, 'label' => Mage::helper( 'adminhtml' )->__( $filename ) );
38
- }
39
-
40
- return $options;
41
- }
42
- }
43
-
44
-
45
- return array(
46
- array( 'value' => 0, 'label' => Mage::helper( 'adminhtml' )->__( 'No log files found' ) ),
47
- );
48
-
49
-
50
- }
51
-
52
- /**
53
- * Get options in "key-value" format
54
- *
55
- * @return array
56
- */
57
- public function toArray()
58
- {
59
- $directory = Mage::getBaseDir();
60
- $directory .= DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'log';
61
-
62
- if (is_dir( $directory )) {
63
- $files = array_diff( scandir( $directory ), array( '..', '.' ) );
64
-
65
- if (!empty( $files )) {
66
-
67
- $options = array();
68
- foreach ($files as $filename) {
69
- $options[] = Mage::helper( 'adminhtml' )->__( $filename );
70
- }
71
-
72
- return $options;
73
- }
74
- }
75
-
76
- return array(
77
- 0 => Mage::helper('adminhtml')->__('One'),
78
- 1 => Mage::helper('adminhtml')->__('Two'),
79
- );
80
- }
81
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_Backend_Source_Files extends Mage_Core_Model_Config_Data
19
+ {
20
+ /**
21
+ * Options getter
22
+ *
23
+ * @return array
24
+ */
25
+ public function toOptionArray()
26
+ {
27
+ $directory = Mage::getBaseDir();
28
+ $directory .= DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'log';
29
+
30
+ if (is_dir( $directory )) {
31
+ $files = array_diff( scandir( $directory ), array( '..', '.' ) );
32
+
33
+ if (!empty( $files )) {
34
+
35
+ $options = array();
36
+ foreach ($files as $filename) {
37
+ $options[] = array( 'value' => $filename, 'label' => Mage::helper( 'adminhtml' )->__( $filename ) );
38
+ }
39
+
40
+ return $options;
41
+ }
42
+ }
43
+
44
+
45
+ return array(
46
+ array( 'value' => 0, 'label' => Mage::helper( 'adminhtml' )->__( 'No log files found' ) ),
47
+ );
48
+
49
+
50
+ }
51
+
52
+ /**
53
+ * Get options in "key-value" format
54
+ *
55
+ * @return array
56
+ */
57
+ public function toArray()
58
+ {
59
+ $directory = Mage::getBaseDir();
60
+ $directory .= DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'log';
61
+
62
+ if (is_dir( $directory )) {
63
+ $files = array_diff( scandir( $directory ), array( '..', '.' ) );
64
+
65
+ if (!empty( $files )) {
66
+
67
+ $options = array();
68
+ foreach ($files as $filename) {
69
+ $options[] = Mage::helper( 'adminhtml' )->__( $filename );
70
+ }
71
+
72
+ return $options;
73
+ }
74
+ }
75
+
76
+ return array(
77
+ 0 => Mage::helper('adminhtml')->__('One'),
78
+ 1 => Mage::helper('adminhtml')->__('Two'),
79
+ );
80
+ }
81
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/ClientSelection.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_ClientSelection
19
- {
20
- /**
21
- * @return array
22
- */
23
- public function toOptionArray()
24
- {
25
- return array();
26
- }
27
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_ClientSelection
19
+ {
20
+ /**
21
+ * @return array
22
+ */
23
+ public function toOptionArray()
24
+ {
25
+ return array();
26
+ }
27
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/ConflictResolutionMethod.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor authentication type selector
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Model_Config_ConflictResolutionMethod
23
- {
24
- const RESOLUTION_METHOD_TIMESTAMP = 'timestamp';
25
- const RESOLUTION_METHOD_SOURCE = 'source';
26
-
27
- /**
28
- * @return array
29
- */
30
- public function toOptionArray()
31
- {
32
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
33
- $helper = Mage::helper('createsend');
34
- return array(
35
- array(
36
- 'value' => self::RESOLUTION_METHOD_TIMESTAMP,
37
- 'label' => $helper->__('Timestamp')
38
- ),
39
- array(
40
- 'value' => self::RESOLUTION_METHOD_SOURCE,
41
- 'label' => $helper->__('Preferred Source')
42
- ),
43
- );
44
- }
45
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor authentication type selector
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Model_Config_ConflictResolutionMethod
23
+ {
24
+ const RESOLUTION_METHOD_TIMESTAMP = 'timestamp';
25
+ const RESOLUTION_METHOD_SOURCE = 'source';
26
+
27
+ /**
28
+ * @return array
29
+ */
30
+ public function toOptionArray()
31
+ {
32
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
33
+ $helper = Mage::helper('createsend');
34
+ return array(
35
+ array(
36
+ 'value' => self::RESOLUTION_METHOD_TIMESTAMP,
37
+ 'label' => $helper->__('Timestamp')
38
+ ),
39
+ array(
40
+ 'value' => self::RESOLUTION_METHOD_SOURCE,
41
+ 'label' => $helper->__('Preferred Source')
42
+ ),
43
+ );
44
+ }
45
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/CustomerAttributes.php CHANGED
@@ -1,311 +1,311 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Product attributes to be included in the custom fields to be sent to Campaign Monitor
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Model_Config_CustomerAttributes
23
- extends Campaignmonitor_Createsend_Model_Config_Attributes_Abstract
24
- {
25
- const ADDRESS_FIELD_PREFIX = 'FONTIS-';
26
-
27
- /** @var array $_customFieldNameMapping */
28
- protected $_customFieldNameMapping = array(
29
- 'confirmation' => 'Customer Email Is Confirmed',
30
- 'created_at' => 'Customer Date Created',
31
- 'created_in' => 'Customer Created From Store',
32
- 'customer_activated' => 'Customer Account Activated',
33
- 'dob' => 'Customer Date Of Birth',
34
- 'firstname' => 'Customer First Name',
35
- 'gender' => 'Customer Gender',
36
- 'group_id' => 'Customer Group',
37
- 'lastname' => 'Customer Last Name',
38
- 'middlename' => 'Customer Middle Name',
39
- 'prefix' => 'Customer Prefix',
40
- 'store_id' => 'Store',
41
- 'suffix' => 'Customer Suffix',
42
- 'taxvat' => 'Customer Tax/VAT Number',
43
- 'website_id' => 'Customer Website',
44
- 'FONTIS-billing-firstname' => 'Billing Customer First Name',
45
- 'FONTIS-billing-lastname' => 'Billing Customer Last Name',
46
- 'FONTIS-shipping-firstname' => 'Shipping Customer First Name',
47
- 'FONTIS-shipping-lastname' => 'Shipping Customer Last Name',
48
- );
49
-
50
- // Put all extra custom attributes here (Do not put billing and sales attributes here)
51
- /** @var array $_extraAttributes */
52
- protected $_extraAttributes = array(
53
- 'FONTIS-has-account' => array(
54
- 'label' => 'Has Customer Account',
55
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE,
56
- 'options' => array('Yes', 'No')
57
- ),
58
- 'FONTIS-number-of-wishlist-items' => array(
59
- 'label' => 'Number of Wishlist Items',
60
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
61
- )
62
- );
63
-
64
- /** @var array $_excludedAttributes */
65
- protected $_excludedAttributes = array(
66
- 'entity_type_id',
67
- 'entity_id',
68
- 'attribute_set_id',
69
- 'password_hash',
70
- 'increment_id',
71
- 'updated_at',
72
- 'email',
73
- 'default_billing',
74
- 'default_shipping',
75
- 'disable_auto_group_change',
76
- 'rp_token',
77
- 'rp_token_created_at',
78
- );
79
-
80
- // Attribute name to be displayed in Magento
81
- /** @var array $_attributeNames */
82
- protected $_attributeNames = array(
83
- 'store_id' => 'Store',
84
- 'group_id' => 'Customer Group',
85
- 'website_id' => 'Website',
86
- 'created_at' => 'Date Created',
87
- );
88
-
89
- /** @var array $_addressFields */
90
- protected $_addressFields = array(
91
- 'firstname' => 'First Name',
92
- 'lastname' => 'Last Name',
93
- 'company' => 'Company',
94
- 'telephone' => 'Phone',
95
- 'fax' => 'Fax',
96
- 'street' => 'Street',
97
- 'city' => 'City',
98
- 'region_id' => 'State/Province',
99
- 'postcode' => 'Zip/Postal Code',
100
- 'country_id' => 'Country',
101
- );
102
-
103
- /** @var array $_addressTypes */
104
- protected $_addressTypes = array(
105
- 'billing' => 'Billing',
106
- 'shipping' => 'Shipping',
107
- );
108
-
109
- /** @var array $_salesAttributes */
110
- protected $_salesAttributes = array(
111
- 'FONTIS-sales-last-order-value' => array(
112
- 'label' => 'Last Order Value',
113
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
114
- ),
115
- 'FONTIS-sales-last-order-date' => array(
116
- 'label' => 'Last Order Date',
117
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_DATE
118
- ),
119
- 'FONTIS-sales-average-order-value' => array(
120
- 'label' => 'Average Order Value',
121
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
122
- ),
123
- 'FONTIS-sales-total-order-value' => array(
124
- 'label' => 'Total Order Value',
125
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
126
- ),
127
- 'FONTIS-sales-total-number-of-orders' => array(
128
- 'label' => 'Total Number Of Orders',
129
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
130
- ),
131
- 'FONTIS-sales-total-number-of-products-ordered' => array(
132
- 'label' => 'Total Quantity Ordered',
133
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
134
- ),
135
- 'FONTIS-sales-first-order-date' => array(
136
- 'label' => 'First Order Date',
137
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_DATE
138
- ),
139
- );
140
-
141
- public function __construct()
142
- {
143
- $this->_fields = array();
144
-
145
- // Add extra attributes
146
- $this->_fields = array_merge($this->_fields, $this->_extraAttributes);
147
-
148
- /** @var Mage_Customer_Model_Customer $customerModel */
149
- $customerModel = Mage::getModel('customer/customer');
150
- $magentoAttributes = $customerModel->getAttributes();
151
-
152
- foreach (array_keys($magentoAttributes) as $att) {
153
- $attribute = $customerModel->getAttribute($att);
154
-
155
- if (!in_array($att, $this->_excludedAttributes)) {
156
- $label = $attribute->getFrontendLabel();
157
-
158
- // give nicer names to the attributes
159
- if (isset($this->_attributeNames[$att])) {
160
- $name = $this->_attributeNames[$att];
161
- } elseif (!empty($label)) {
162
- $name = $attribute->getFrontendLabel();
163
- } else {
164
- $name = $att;
165
- }
166
-
167
- // Get the attribute type for Campaign Monitor
168
- if ($attribute->getFrontendInput() === 'date' || $attribute->getFrontendInput() === 'datetime') {
169
- $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_DATE;
170
- } elseif ($attribute->getBackendType() == 'int' && $attribute->getFrontendInput() == 'text') {
171
- $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER;
172
- } elseif ($attribute->getBackendType() == 'decimal') {
173
- $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER;
174
- } elseif ($att == 'gender' || $att == 'confirmation') {
175
- $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE;
176
- } elseif ($this->isBooleanAttribute($attribute)) {
177
- $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE;
178
- } else {
179
- $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT;
180
- }
181
-
182
- // Populate the field list
183
- $this->_fields[$att] = array(
184
- 'label' => $name,
185
- 'type' => $type
186
- );
187
- if ($type === Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE) {
188
- if ($att == 'confirmation') {
189
- $this->_fields[$att]['options'] = array('Yes', 'No');
190
- } else {
191
- $allOptions = $attribute->getSource()->getAllOptions(false);
192
-
193
- $options = array();
194
- foreach ($allOptions as $option) {
195
- $options[] = $option['label'];
196
- }
197
-
198
- $this->_fields[$att]['options'] = $options;
199
- }
200
- }
201
- }
202
- }
203
- asort($this->_fields);
204
-
205
- $this->_fields = array_merge($this->_fields, $this->getAddressFields('Billing'));
206
- $this->_fields = array_merge($this->_fields, $this->getAddressFields('Shipping'));
207
-
208
- $this->_fields = array_merge($this->_fields, $this->_salesAttributes);
209
- }
210
-
211
- /**
212
- * Returns true if the attribute type is boolean based on source model.
213
- * Returns false otherwise.
214
- *
215
- * @param Mage_Customer_Model_Entity_Attribute $attribute
216
- * @return bool
217
- */
218
- public function isBooleanAttribute($attribute)
219
- {
220
- return $attribute->getSourceModel()
221
- && $attribute->getSourceModel() == 'eav/entity_attribute_source_boolean';
222
- }
223
-
224
- /**
225
- * Returns all attribute option labels in an array
226
- *
227
- * @param string $field
228
- * @return array
229
- */
230
- public function getFieldOptions($field)
231
- {
232
- if (array_key_exists($field, $this->_fields)
233
- && $this->_fields[$field]['type'] == Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE) {
234
-
235
- return $this->_fields[$field]['options'];
236
- } else {
237
- return array();
238
- }
239
- }
240
-
241
- /**
242
- * Returns an array of address attributes based on address type
243
- *
244
- * @param string $addressType "Billing" or "Shipping"
245
- * @return array
246
- */
247
- protected function getAddressFields($addressType)
248
- {
249
- $fields = array();
250
-
251
- foreach ($this->_addressFields as $att => $label) {
252
- $fields[self::ADDRESS_FIELD_PREFIX . strtolower($addressType) . '-' . $att] = array(
253
- 'label' => sprintf('%s Address: %s', $addressType, $label),
254
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
255
- );
256
- }
257
-
258
- return $fields;
259
- }
260
-
261
- /**
262
- * Returns the Campaign Monitor custom field name given the Magento attribute name.
263
- *
264
- * @param string $field The Magento attribute name
265
- * @param bool $returnDefault If true, returns the default value. Otherwise, returns null.
266
- * @return null|string
267
- */
268
- public function getCustomFieldName($field, $returnDefault = true)
269
- {
270
- $custom = parent::getCustomFieldName($field, false);
271
- if ($custom !== null) {
272
- return $custom;
273
- }
274
-
275
- if (array_key_exists($field, $this->_attributeNames)) {
276
- return $this->_attributeNames[$field];
277
- }
278
-
279
- if (array_key_exists($field, $this->_extraAttributes)) {
280
- return $this->_extraAttributes[$field]['label'];
281
- }
282
-
283
- if (array_key_exists($field, $this->_salesAttributes)) {
284
- return $this->_salesAttributes[$field]['label'];
285
- }
286
-
287
- foreach ($this->_addressTypes as $addressType => $addressTypeLabel) {
288
- $typePrefix = self::ADDRESS_FIELD_PREFIX . $addressType . '-';
289
-
290
- // Check if the field is one of these address types
291
- if (0 === strpos($field, $typePrefix)) {
292
- // Remove the prefix from the field name
293
- $addressField = substr($field, strlen($typePrefix));
294
-
295
- if (array_key_exists($addressField, $this->_addressFields)) {
296
- $addressFieldLabel = $this->_addressFields[$addressField];
297
-
298
- return sprintf('%s %s', $addressTypeLabel, $addressFieldLabel);
299
- } else {
300
- return sprintf('%s %s', $addressTypeLabel, ucwords($addressField));
301
- }
302
- }
303
- }
304
-
305
- if ($returnDefault) {
306
- return ucwords($field);
307
- } else {
308
- return null;
309
- }
310
- }
311
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Product attributes to be included in the custom fields to be sent to Campaign Monitor
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Model_Config_CustomerAttributes
23
+ extends Campaignmonitor_Createsend_Model_Config_Attributes_Abstract
24
+ {
25
+ const ADDRESS_FIELD_PREFIX = 'FONTIS-';
26
+
27
+ /** @var array $_customFieldNameMapping */
28
+ protected $_customFieldNameMapping = array(
29
+ 'confirmation' => 'Customer Email Is Confirmed',
30
+ 'created_at' => 'Customer Date Created',
31
+ 'created_in' => 'Customer Created From Store',
32
+ 'customer_activated' => 'Customer Account Activated',
33
+ 'dob' => 'Customer Date Of Birth',
34
+ 'firstname' => 'Customer First Name',
35
+ 'gender' => 'Customer Gender',
36
+ 'group_id' => 'Customer Group',
37
+ 'lastname' => 'Customer Last Name',
38
+ 'middlename' => 'Customer Middle Name',
39
+ 'prefix' => 'Customer Prefix',
40
+ 'store_id' => 'Store',
41
+ 'suffix' => 'Customer Suffix',
42
+ 'taxvat' => 'Customer Tax/VAT Number',
43
+ 'website_id' => 'Customer Website',
44
+ 'FONTIS-billing-firstname' => 'Billing Customer First Name',
45
+ 'FONTIS-billing-lastname' => 'Billing Customer Last Name',
46
+ 'FONTIS-shipping-firstname' => 'Shipping Customer First Name',
47
+ 'FONTIS-shipping-lastname' => 'Shipping Customer Last Name',
48
+ );
49
+
50
+ // Put all extra custom attributes here (Do not put billing and sales attributes here)
51
+ /** @var array $_extraAttributes */
52
+ protected $_extraAttributes = array(
53
+ 'FONTIS-has-account' => array(
54
+ 'label' => 'Has Customer Account',
55
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE,
56
+ 'options' => array('Yes', 'No')
57
+ ),
58
+ 'FONTIS-number-of-wishlist-items' => array(
59
+ 'label' => 'Number of Wishlist Items',
60
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
61
+ )
62
+ );
63
+
64
+ /** @var array $_excludedAttributes */
65
+ protected $_excludedAttributes = array(
66
+ 'entity_type_id',
67
+ 'entity_id',
68
+ 'attribute_set_id',
69
+ 'password_hash',
70
+ 'increment_id',
71
+ 'updated_at',
72
+ 'email',
73
+ 'default_billing',
74
+ 'default_shipping',
75
+ 'disable_auto_group_change',
76
+ 'rp_token',
77
+ 'rp_token_created_at',
78
+ );
79
+
80
+ // Attribute name to be displayed in Magento
81
+ /** @var array $_attributeNames */
82
+ protected $_attributeNames = array(
83
+ 'store_id' => 'Store',
84
+ 'group_id' => 'Customer Group',
85
+ 'website_id' => 'Website',
86
+ 'created_at' => 'Date Created',
87
+ );
88
+
89
+ /** @var array $_addressFields */
90
+ protected $_addressFields = array(
91
+ 'firstname' => 'First Name',
92
+ 'lastname' => 'Last Name',
93
+ 'company' => 'Company',
94
+ 'telephone' => 'Phone',
95
+ 'fax' => 'Fax',
96
+ 'street' => 'Street',
97
+ 'city' => 'City',
98
+ 'region_id' => 'State/Province',
99
+ 'postcode' => 'Zip/Postal Code',
100
+ 'country_id' => 'Country',
101
+ );
102
+
103
+ /** @var array $_addressTypes */
104
+ protected $_addressTypes = array(
105
+ 'billing' => 'Billing',
106
+ 'shipping' => 'Shipping',
107
+ );
108
+
109
+ /** @var array $_salesAttributes */
110
+ protected $_salesAttributes = array(
111
+ 'FONTIS-sales-last-order-value' => array(
112
+ 'label' => 'Last Order Value',
113
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
114
+ ),
115
+ 'FONTIS-sales-last-order-date' => array(
116
+ 'label' => 'Last Order Date',
117
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_DATE
118
+ ),
119
+ 'FONTIS-sales-average-order-value' => array(
120
+ 'label' => 'Average Order Value',
121
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
122
+ ),
123
+ 'FONTIS-sales-total-order-value' => array(
124
+ 'label' => 'Total Order Value',
125
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
126
+ ),
127
+ 'FONTIS-sales-total-number-of-orders' => array(
128
+ 'label' => 'Total Number Of Orders',
129
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
130
+ ),
131
+ 'FONTIS-sales-total-number-of-products-ordered' => array(
132
+ 'label' => 'Total Quantity Ordered',
133
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
134
+ ),
135
+ 'FONTIS-sales-first-order-date' => array(
136
+ 'label' => 'First Order Date',
137
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_DATE
138
+ ),
139
+ );
140
+
141
+ public function __construct()
142
+ {
143
+ $this->_fields = array();
144
+
145
+ // Add extra attributes
146
+ $this->_fields = array_merge($this->_fields, $this->_extraAttributes);
147
+
148
+ /** @var Mage_Customer_Model_Customer $customerModel */
149
+ $customerModel = Mage::getModel('customer/customer');
150
+ $magentoAttributes = $customerModel->getAttributes();
151
+
152
+ foreach (array_keys($magentoAttributes) as $att) {
153
+ $attribute = $customerModel->getAttribute($att);
154
+
155
+ if (!in_array($att, $this->_excludedAttributes)) {
156
+ $label = $attribute->getFrontendLabel();
157
+
158
+ // give nicer names to the attributes
159
+ if (isset($this->_attributeNames[$att])) {
160
+ $name = $this->_attributeNames[$att];
161
+ } elseif (!empty($label)) {
162
+ $name = $attribute->getFrontendLabel();
163
+ } else {
164
+ $name = $att;
165
+ }
166
+
167
+ // Get the attribute type for Campaign Monitor
168
+ if ($attribute->getFrontendInput() === 'date' || $attribute->getFrontendInput() === 'datetime') {
169
+ $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_DATE;
170
+ } elseif ($attribute->getBackendType() == 'int' && $attribute->getFrontendInput() == 'text') {
171
+ $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER;
172
+ } elseif ($attribute->getBackendType() == 'decimal') {
173
+ $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER;
174
+ } elseif ($att == 'gender' || $att == 'confirmation') {
175
+ $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE;
176
+ } elseif ($this->isBooleanAttribute($attribute)) {
177
+ $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE;
178
+ } else {
179
+ $type = Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT;
180
+ }
181
+
182
+ // Populate the field list
183
+ $this->_fields[$att] = array(
184
+ 'label' => $name,
185
+ 'type' => $type
186
+ );
187
+ if ($type === Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE) {
188
+ if ($att == 'confirmation') {
189
+ $this->_fields[$att]['options'] = array('Yes', 'No');
190
+ } else {
191
+ $allOptions = $attribute->getSource()->getAllOptions(false);
192
+
193
+ $options = array();
194
+ foreach ($allOptions as $option) {
195
+ $options[] = $option['label'];
196
+ }
197
+
198
+ $this->_fields[$att]['options'] = $options;
199
+ }
200
+ }
201
+ }
202
+ }
203
+ asort($this->_fields);
204
+
205
+ $this->_fields = array_merge($this->_fields, $this->getAddressFields('Billing'));
206
+ $this->_fields = array_merge($this->_fields, $this->getAddressFields('Shipping'));
207
+
208
+ $this->_fields = array_merge($this->_fields, $this->_salesAttributes);
209
+ }
210
+
211
+ /**
212
+ * Returns true if the attribute type is boolean based on source model.
213
+ * Returns false otherwise.
214
+ *
215
+ * @param Mage_Customer_Model_Entity_Attribute $attribute
216
+ * @return bool
217
+ */
218
+ public function isBooleanAttribute($attribute)
219
+ {
220
+ return $attribute->getSourceModel()
221
+ && $attribute->getSourceModel() == 'eav/entity_attribute_source_boolean';
222
+ }
223
+
224
+ /**
225
+ * Returns all attribute option labels in an array
226
+ *
227
+ * @param string $field
228
+ * @return array
229
+ */
230
+ public function getFieldOptions($field)
231
+ {
232
+ if (array_key_exists($field, $this->_fields)
233
+ && $this->_fields[$field]['type'] == Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_SELECT_ONE) {
234
+
235
+ return $this->_fields[$field]['options'];
236
+ } else {
237
+ return array();
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Returns an array of address attributes based on address type
243
+ *
244
+ * @param string $addressType "Billing" or "Shipping"
245
+ * @return array
246
+ */
247
+ protected function getAddressFields($addressType)
248
+ {
249
+ $fields = array();
250
+
251
+ foreach ($this->_addressFields as $att => $label) {
252
+ $fields[self::ADDRESS_FIELD_PREFIX . strtolower($addressType) . '-' . $att] = array(
253
+ 'label' => sprintf('%s Address: %s', $addressType, $label),
254
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
255
+ );
256
+ }
257
+
258
+ return $fields;
259
+ }
260
+
261
+ /**
262
+ * Returns the Campaign Monitor custom field name given the Magento attribute name.
263
+ *
264
+ * @param string $field The Magento attribute name
265
+ * @param bool $returnDefault If true, returns the default value. Otherwise, returns null.
266
+ * @return null|string
267
+ */
268
+ public function getCustomFieldName($field, $returnDefault = true)
269
+ {
270
+ $custom = parent::getCustomFieldName($field, false);
271
+ if ($custom !== null) {
272
+ return $custom;
273
+ }
274
+
275
+ if (array_key_exists($field, $this->_attributeNames)) {
276
+ return $this->_attributeNames[$field];
277
+ }
278
+
279
+ if (array_key_exists($field, $this->_extraAttributes)) {
280
+ return $this->_extraAttributes[$field]['label'];
281
+ }
282
+
283
+ if (array_key_exists($field, $this->_salesAttributes)) {
284
+ return $this->_salesAttributes[$field]['label'];
285
+ }
286
+
287
+ foreach ($this->_addressTypes as $addressType => $addressTypeLabel) {
288
+ $typePrefix = self::ADDRESS_FIELD_PREFIX . $addressType . '-';
289
+
290
+ // Check if the field is one of these address types
291
+ if (0 === strpos($field, $typePrefix)) {
292
+ // Remove the prefix from the field name
293
+ $addressField = substr($field, strlen($typePrefix));
294
+
295
+ if (array_key_exists($addressField, $this->_addressFields)) {
296
+ $addressFieldLabel = $this->_addressFields[$addressField];
297
+
298
+ return sprintf('%s %s', $addressTypeLabel, $addressFieldLabel);
299
+ } else {
300
+ return sprintf('%s %s', $addressTypeLabel, ucwords($addressField));
301
+ }
302
+ }
303
+ }
304
+
305
+ if ($returnDefault) {
306
+ return ucwords($field);
307
+ } else {
308
+ return null;
309
+ }
310
+ }
311
+ }
app/code/community/Campaignmonitor/Createsend/Model/Config/DefaultCustomFields.php CHANGED
@@ -1,58 +1,58 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_DefaultCustomFields
19
- {
20
- protected $_defaultCustomerAttributes = array(
21
- 'FONTIS-has-account',
22
- 'created_in',
23
- 'group_id',
24
- 'created_at',
25
- 'firstname',
26
- 'lastname',
27
- 'dob',
28
- 'gender',
29
- 'confirmation',
30
- 'website_id',
31
- 'store_id',
32
- 'FONTIS-sales-average-order-value',
33
- 'FONTIS-sales-first-order-date',
34
- 'FONTIS-sales-last-order-value',
35
- 'FONTIS-sales-last-order-date',
36
- 'FONTIS-sales-total-order-value',
37
- 'FONTIS-sales-total-number-of-orders',
38
- 'FONTIS-sales-total-number-of-products-ordered',
39
- 'FONTIS-number-of-wishlist-items',
40
- );
41
-
42
- protected $_defaultProductAttributes = array(
43
- 'name',
44
- 'price',
45
- 'short_description',
46
- 'sku',
47
- );
48
-
49
- public function getDefaultCustomerAttributes()
50
- {
51
- return $this->_defaultCustomerAttributes;
52
- }
53
-
54
- public function getDefaultProductAttributes()
55
- {
56
- return $this->_defaultProductAttributes;
57
- }
58
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_DefaultCustomFields
19
+ {
20
+ protected $_defaultCustomerAttributes = array(
21
+ 'FONTIS-has-account',
22
+ 'created_in',
23
+ 'group_id',
24
+ 'created_at',
25
+ 'firstname',
26
+ 'lastname',
27
+ 'dob',
28
+ 'gender',
29
+ 'confirmation',
30
+ 'website_id',
31
+ 'store_id',
32
+ 'FONTIS-sales-average-order-value',
33
+ 'FONTIS-sales-first-order-date',
34
+ 'FONTIS-sales-last-order-value',
35
+ 'FONTIS-sales-last-order-date',
36
+ 'FONTIS-sales-total-order-value',
37
+ 'FONTIS-sales-total-number-of-orders',
38
+ 'FONTIS-sales-total-number-of-products-ordered',
39
+ 'FONTIS-number-of-wishlist-items',
40
+ );
41
+
42
+ protected $_defaultProductAttributes = array(
43
+ 'name',
44
+ 'price',
45
+ 'short_description',
46
+ 'sku',
47
+ );
48
+
49
+ public function getDefaultCustomerAttributes()
50
+ {
51
+ return $this->_defaultCustomerAttributes;
52
+ }
53
+
54
+ public function getDefaultProductAttributes()
55
+ {
56
+ return $this->_defaultProductAttributes;
57
+ }
58
+ }
app/code/community/Campaignmonitor/Createsend/Model/Config/ExampleSegments.php CHANGED
@@ -1,218 +1,218 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_ExampleSegments
19
- {
20
- /**
21
- * Returns Example Segments to be created in Campaign Monitor
22
- *
23
- * The keys of the return array correspond to the custom field(s) that are required for
24
- * creating the example segment.
25
- *
26
- * The array keys should be in the format: [<Rule name> :] <RequireField1> [, <RequiredField2> [...]]
27
- * The Rule name along with the colon (:) can be omitted if the required fields combination is unique.
28
- *
29
- * The required fields will be displayed to the user along with the error message
30
- * when the segment creation results in a CODE_INVALID_SEGMENT_RULES error
31
- * (happens when custom fields are non-existent) to let the user know
32
- * which fields are missing.
33
- *
34
- * See Campaign Monitor API for segment definition format:
35
- *
36
- * @link https://www.campaignmonitor.com/api/segments/
37
- *
38
- * @return array
39
- */
40
- public function getExampleSegments()
41
- {
42
- /** @var Campaignmonitor_Createsend_Model_Api $api */
43
- $api = Mage::getModel('createsend/api');
44
-
45
- /** @var Campaignmonitor_Createsend_Model_Config_CustomerAttributes $customerAttributes */
46
- $customerAttributes = Mage::getSingleton('createsend/config_customerAttributes');
47
-
48
- $cmHasCustomerAccount = $api->formatCustomFieldName(
49
- $customerAttributes->getCustomFieldName('FONTIS-has-account', true)
50
- );
51
- $cmAverageOrderValue = $api->formatCustomFieldName(
52
- $customerAttributes->getCustomFieldName('FONTIS-sales-average-order-value', true)
53
- );
54
- $cmTotalNumberOfOrders = $api->formatCustomFieldName(
55
- $customerAttributes->getCustomFieldName('FONTIS-sales-total-number-of-orders', true)
56
- );
57
- $cmTotalOrderValue = $api->formatCustomFieldName(
58
- $customerAttributes->getCustomFieldName('FONTIS-sales-total-order-value', true)
59
- );
60
- $cmCustomerGender = $api->formatCustomFieldName(
61
- $customerAttributes->getCustomFieldName('gender', true)
62
- );
63
- $cmWishlistItemCount = $api->formatCustomFieldName(
64
- $customerAttributes->getCustomFieldName('FONTIS-number-of-wishlist-items', true)
65
- );
66
-
67
- $sampleSegments = array(
68
- "All subscribers: $cmHasCustomerAccount" => array(
69
- 'Title' => 'All subscribers',
70
- 'RuleGroups' => array(
71
- array(
72
- 'Rules' => array(
73
- array(
74
- 'RuleType' => $cmHasCustomerAccount,
75
- 'Clause' => 'EQUALS Yes'
76
- )
77
- )
78
- )
79
- )
80
- ),
81
- "Big spenders: $cmAverageOrderValue" => array(
82
- 'Title' => 'Big spenders',
83
- 'RuleGroups' => array(
84
- array(
85
- 'Rules' => array(
86
- array(
87
- 'RuleType' => $cmAverageOrderValue,
88
- 'Clause' => 'GREATER_THAN_OR_EQUAL 500'
89
- )
90
- )
91
- )
92
- )
93
- ),
94
- "Frequent Buyers: $cmTotalNumberOfOrders" => array(
95
- 'Title' => 'Frequent Buyers',
96
- 'RuleGroups' => array(
97
- array(
98
- 'Rules' => array(
99
- array(
100
- 'RuleType' => $cmTotalNumberOfOrders,
101
- 'Clause' => 'GREATER_THAN_OR_EQUAL 5'
102
- )
103
- )
104
- )
105
- )
106
- ),
107
- "VIPs: $cmTotalNumberOfOrders, $cmTotalOrderValue" => array(
108
- 'Title' => 'VIPs',
109
- 'RuleGroups' => array(
110
- array(
111
- 'Rules' => array(
112
- array(
113
- 'RuleType' => $cmTotalNumberOfOrders,
114
- 'Clause' => 'GREATER_THAN_OR_EQUAL 5'
115
- )
116
- )
117
- ),
118
- array(
119
- 'Rules' => array(
120
- array(
121
- 'RuleType' => $cmTotalOrderValue,
122
- 'Clause' => 'GREATER_THAN_OR_EQUAL 500'
123
- )
124
- )
125
- )
126
- )
127
- ),
128
- "Subscribers that haven’t purchased: $cmHasCustomerAccount, $cmTotalNumberOfOrders" => array(
129
- 'Title' => 'Subscribers that haven’t purchased',
130
- 'RuleGroups' => array(
131
- array(
132
- 'Rules' => array(
133
- array(
134
- 'RuleType' => $cmHasCustomerAccount,
135
- 'Clause' => 'EQUALS Yes'
136
- )
137
- )
138
- ),
139
- array(
140
- 'Rules' => array(
141
- array(
142
- 'RuleType' => $cmTotalNumberOfOrders,
143
- 'Clause' => 'EQUALS 0'
144
- )
145
- )
146
- )
147
- )
148
- ),
149
- "First time customers: $cmTotalNumberOfOrders" => array(
150
- 'Title' => 'First time customers',
151
- 'RuleGroups' => array(
152
- array(
153
- 'Rules' => array(
154
- array(
155
- 'RuleType' => $cmTotalNumberOfOrders,
156
- 'Clause' => 'EQUALS 1'
157
- )
158
- )
159
- )
160
- )
161
- ),
162
- "All customers: $cmTotalNumberOfOrders" => array(
163
- 'Title' => 'All customers',
164
- 'RuleGroups' => array(
165
- array(
166
- 'Rules' => array(
167
- array(
168
- 'RuleType' => $cmTotalNumberOfOrders,
169
- 'Clause' => 'GREATER_THAN_OR_EQUAL 1'
170
- )
171
- )
172
- )
173
- )
174
- ),
175
- "Customers with a wishlist: $cmWishlistItemCount" => array(
176
- 'Title' => 'Customers with a wishlist',
177
- 'RuleGroups' => array(
178
- array(
179
- 'Rules' => array(
180
- array(
181
- 'RuleType' => $cmWishlistItemCount,
182
- 'Clause' => 'GREATER_THAN_OR_EQUAL 1'
183
- )
184
- )
185
- )
186
- )
187
- ),
188
- "Males: $cmCustomerGender" => array(
189
- 'Title' => 'Males',
190
- 'RuleGroups' => array(
191
- array(
192
- 'Rules' => array(
193
- array(
194
- 'RuleType' => $cmCustomerGender,
195
- 'Clause' => 'EQUALS Male'
196
- )
197
- )
198
- )
199
- )
200
- ),
201
- "Females: $cmCustomerGender" => array(
202
- 'Title' => 'Females',
203
- 'RuleGroups' => array(
204
- array(
205
- 'Rules' => array(
206
- array(
207
- 'RuleType' => $cmCustomerGender,
208
- 'Clause' => 'EQUALS Female'
209
- )
210
- )
211
- )
212
- )
213
- ),
214
- );
215
-
216
- return $sampleSegments;
217
- }
218
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_ExampleSegments
19
+ {
20
+ /**
21
+ * Returns Example Segments to be created in Campaign Monitor
22
+ *
23
+ * The keys of the return array correspond to the custom field(s) that are required for
24
+ * creating the example segment.
25
+ *
26
+ * The array keys should be in the format: [<Rule name> :] <RequireField1> [, <RequiredField2> [...]]
27
+ * The Rule name along with the colon (:) can be omitted if the required fields combination is unique.
28
+ *
29
+ * The required fields will be displayed to the user along with the error message
30
+ * when the segment creation results in a CODE_INVALID_SEGMENT_RULES error
31
+ * (happens when custom fields are non-existent) to let the user know
32
+ * which fields are missing.
33
+ *
34
+ * See Campaign Monitor API for segment definition format:
35
+ *
36
+ * @link https://www.campaignmonitor.com/api/segments/
37
+ *
38
+ * @return array
39
+ */
40
+ public function getExampleSegments()
41
+ {
42
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
43
+ $api = Mage::getModel('createsend/api');
44
+
45
+ /** @var Campaignmonitor_Createsend_Model_Config_CustomerAttributes $customerAttributes */
46
+ $customerAttributes = Mage::getSingleton('createsend/config_customerAttributes');
47
+
48
+ $cmHasCustomerAccount = $api->formatCustomFieldName(
49
+ $customerAttributes->getCustomFieldName('FONTIS-has-account', true)
50
+ );
51
+ $cmAverageOrderValue = $api->formatCustomFieldName(
52
+ $customerAttributes->getCustomFieldName('FONTIS-sales-average-order-value', true)
53
+ );
54
+ $cmTotalNumberOfOrders = $api->formatCustomFieldName(
55
+ $customerAttributes->getCustomFieldName('FONTIS-sales-total-number-of-orders', true)
56
+ );
57
+ $cmTotalOrderValue = $api->formatCustomFieldName(
58
+ $customerAttributes->getCustomFieldName('FONTIS-sales-total-order-value', true)
59
+ );
60
+ $cmCustomerGender = $api->formatCustomFieldName(
61
+ $customerAttributes->getCustomFieldName('gender', true)
62
+ );
63
+ $cmWishlistItemCount = $api->formatCustomFieldName(
64
+ $customerAttributes->getCustomFieldName('FONTIS-number-of-wishlist-items', true)
65
+ );
66
+
67
+ $sampleSegments = array(
68
+ "All subscribers: $cmHasCustomerAccount" => array(
69
+ 'Title' => 'All subscribers',
70
+ 'RuleGroups' => array(
71
+ array(
72
+ 'Rules' => array(
73
+ array(
74
+ 'RuleType' => $cmHasCustomerAccount,
75
+ 'Clause' => 'EQUALS Yes'
76
+ )
77
+ )
78
+ )
79
+ )
80
+ ),
81
+ "Big spenders: $cmAverageOrderValue" => array(
82
+ 'Title' => 'Big spenders',
83
+ 'RuleGroups' => array(
84
+ array(
85
+ 'Rules' => array(
86
+ array(
87
+ 'RuleType' => $cmAverageOrderValue,
88
+ 'Clause' => 'GREATER_THAN_OR_EQUAL 500'
89
+ )
90
+ )
91
+ )
92
+ )
93
+ ),
94
+ "Frequent Buyers: $cmTotalNumberOfOrders" => array(
95
+ 'Title' => 'Frequent Buyers',
96
+ 'RuleGroups' => array(
97
+ array(
98
+ 'Rules' => array(
99
+ array(
100
+ 'RuleType' => $cmTotalNumberOfOrders,
101
+ 'Clause' => 'GREATER_THAN_OR_EQUAL 5'
102
+ )
103
+ )
104
+ )
105
+ )
106
+ ),
107
+ "VIPs: $cmTotalNumberOfOrders, $cmTotalOrderValue" => array(
108
+ 'Title' => 'VIPs',
109
+ 'RuleGroups' => array(
110
+ array(
111
+ 'Rules' => array(
112
+ array(
113
+ 'RuleType' => $cmTotalNumberOfOrders,
114
+ 'Clause' => 'GREATER_THAN_OR_EQUAL 5'
115
+ )
116
+ )
117
+ ),
118
+ array(
119
+ 'Rules' => array(
120
+ array(
121
+ 'RuleType' => $cmTotalOrderValue,
122
+ 'Clause' => 'GREATER_THAN_OR_EQUAL 500'
123
+ )
124
+ )
125
+ )
126
+ )
127
+ ),
128
+ "Subscribers that haven’t purchased: $cmHasCustomerAccount, $cmTotalNumberOfOrders" => array(
129
+ 'Title' => 'Subscribers that haven’t purchased',
130
+ 'RuleGroups' => array(
131
+ array(
132
+ 'Rules' => array(
133
+ array(
134
+ 'RuleType' => $cmHasCustomerAccount,
135
+ 'Clause' => 'EQUALS Yes'
136
+ )
137
+ )
138
+ ),
139
+ array(
140
+ 'Rules' => array(
141
+ array(
142
+ 'RuleType' => $cmTotalNumberOfOrders,
143
+ 'Clause' => 'EQUALS 0'
144
+ )
145
+ )
146
+ )
147
+ )
148
+ ),
149
+ "First time customers: $cmTotalNumberOfOrders" => array(
150
+ 'Title' => 'First time customers',
151
+ 'RuleGroups' => array(
152
+ array(
153
+ 'Rules' => array(
154
+ array(
155
+ 'RuleType' => $cmTotalNumberOfOrders,
156
+ 'Clause' => 'EQUALS 1'
157
+ )
158
+ )
159
+ )
160
+ )
161
+ ),
162
+ "All customers: $cmTotalNumberOfOrders" => array(
163
+ 'Title' => 'All customers',
164
+ 'RuleGroups' => array(
165
+ array(
166
+ 'Rules' => array(
167
+ array(
168
+ 'RuleType' => $cmTotalNumberOfOrders,
169
+ 'Clause' => 'GREATER_THAN_OR_EQUAL 1'
170
+ )
171
+ )
172
+ )
173
+ )
174
+ ),
175
+ "Customers with a wishlist: $cmWishlistItemCount" => array(
176
+ 'Title' => 'Customers with a wishlist',
177
+ 'RuleGroups' => array(
178
+ array(
179
+ 'Rules' => array(
180
+ array(
181
+ 'RuleType' => $cmWishlistItemCount,
182
+ 'Clause' => 'GREATER_THAN_OR_EQUAL 1'
183
+ )
184
+ )
185
+ )
186
+ )
187
+ ),
188
+ "Males: $cmCustomerGender" => array(
189
+ 'Title' => 'Males',
190
+ 'RuleGroups' => array(
191
+ array(
192
+ 'Rules' => array(
193
+ array(
194
+ 'RuleType' => $cmCustomerGender,
195
+ 'Clause' => 'EQUALS Male'
196
+ )
197
+ )
198
+ )
199
+ )
200
+ ),
201
+ "Females: $cmCustomerGender" => array(
202
+ 'Title' => 'Females',
203
+ 'RuleGroups' => array(
204
+ array(
205
+ 'Rules' => array(
206
+ array(
207
+ 'RuleType' => $cmCustomerGender,
208
+ 'Clause' => 'EQUALS Female'
209
+ )
210
+ )
211
+ )
212
+ )
213
+ ),
214
+ );
215
+
216
+ return $sampleSegments;
217
+ }
218
+ }
app/code/community/Campaignmonitor/Createsend/Model/Config/ListFlag.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_ListFlag extends Mage_Core_Model_Flag
19
- {
20
- protected $_flagCode = 'createsend_lists';
21
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_ListFlag extends Mage_Core_Model_Flag
19
+ {
20
+ protected $_flagCode = 'createsend_lists';
21
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/ListSelection.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Config_ListSelection
19
- {
20
- /**
21
- * @return array
22
- */
23
- public function toOptionArray()
24
- {
25
- return array();
26
- }
27
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Config_ListSelection
19
+ {
20
+ /**
21
+ * @return array
22
+ */
23
+ public function toOptionArray()
24
+ {
25
+ return array();
26
+ }
27
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/ProductAttributes.php CHANGED
@@ -1,82 +1,82 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Product attributes to be included in the custom fields to be sent to Campaign Monitor
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Model_Config_ProductAttributes
23
- extends Campaignmonitor_Createsend_Model_Config_Attributes_Abstract
24
- {
25
- /** @var array $_customFieldNameMapping */
26
- protected $_customFieldNameMapping = array(
27
- // Define custom field names for product attributes here
28
- // 'short_description'
29
- );
30
-
31
- protected $_fields = array(
32
- 'name' => array(
33
- 'label' => 'Name',
34
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
35
- ),
36
- 'price' => array(
37
- 'label' => 'Price',
38
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
39
- ),
40
- 'short_description' => array(
41
- 'label' => 'Description',
42
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
43
- ),
44
- 'sku' => array(
45
- 'label' => 'SKU',
46
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
47
- ),
48
- 'url_key' => array(
49
- 'label' => 'URL Key',
50
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
51
- ),
52
- 'url_path' => array(
53
- 'label' => 'URL Path',
54
- 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
55
- ),
56
- );
57
-
58
- /**
59
- * Returns the Campaign Monitor custom field name given the Magento attribute name.
60
- *
61
- * @param string $field The Magento attribute name
62
- * @param bool $returnDefault If true, returns the default value. Otherwise, returns null.
63
- * @return null|string
64
- */
65
- public function getCustomFieldName($field, $returnDefault = true)
66
- {
67
- $custom = parent::getCustomFieldName($field, false);
68
- if ($custom !== null) {
69
- return $custom;
70
- }
71
-
72
- if (array_key_exists($field, $this->_fields)) {
73
- return $this->_fields[$field]['label'];
74
- }
75
-
76
- if ($returnDefault) {
77
- return ucwords($field);
78
- } else {
79
- return null;
80
- }
81
- }
82
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Product attributes to be included in the custom fields to be sent to Campaign Monitor
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Model_Config_ProductAttributes
23
+ extends Campaignmonitor_Createsend_Model_Config_Attributes_Abstract
24
+ {
25
+ /** @var array $_customFieldNameMapping */
26
+ protected $_customFieldNameMapping = array(
27
+ // Define custom field names for product attributes here
28
+ // 'short_description'
29
+ );
30
+
31
+ protected $_fields = array(
32
+ 'name' => array(
33
+ 'label' => 'Name',
34
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
35
+ ),
36
+ 'price' => array(
37
+ 'label' => 'Price',
38
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_NUMBER
39
+ ),
40
+ 'short_description' => array(
41
+ 'label' => 'Description',
42
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
43
+ ),
44
+ 'sku' => array(
45
+ 'label' => 'SKU',
46
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
47
+ ),
48
+ 'url_key' => array(
49
+ 'label' => 'URL Key',
50
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
51
+ ),
52
+ 'url_path' => array(
53
+ 'label' => 'URL Path',
54
+ 'type' => Campaignmonitor_Createsend_Model_Api::FIELD_TYPE_TEXT
55
+ ),
56
+ );
57
+
58
+ /**
59
+ * Returns the Campaign Monitor custom field name given the Magento attribute name.
60
+ *
61
+ * @param string $field The Magento attribute name
62
+ * @param bool $returnDefault If true, returns the default value. Otherwise, returns null.
63
+ * @return null|string
64
+ */
65
+ public function getCustomFieldName($field, $returnDefault = true)
66
+ {
67
+ $custom = parent::getCustomFieldName($field, false);
68
+ if ($custom !== null) {
69
+ return $custom;
70
+ }
71
+
72
+ if (array_key_exists($field, $this->_fields)) {
73
+ return $this->_fields[$field]['label'];
74
+ }
75
+
76
+ if ($returnDefault) {
77
+ return ucwords($field);
78
+ } else {
79
+ return null;
80
+ }
81
+ }
82
  }
app/code/community/Campaignmonitor/Createsend/Model/Config/Scope.php CHANGED
@@ -1,93 +1,93 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Provides _getScope function for getting scope and scope id given a website and/or store.
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Model_Config_Scope
23
- {
24
- /**
25
- * Get the scope from $website or $store
26
- *
27
- * @param string $website
28
- * @param string $store
29
- * @return array
30
- */
31
- public function _getScope($website, $store)
32
- {
33
- // This code is duplicated from the _getScope method in adminhtml/core_config. It is duplicated because
34
- // that method is protected and we have need to determine the scope using the same logic.
35
- if ($store) {
36
- $scope = 'stores';
37
- $scopeId = (int)Mage::getConfig()->getNode('stores/' . $store . '/system/store/id');
38
- } elseif ($website) {
39
- $scope = 'websites';
40
- $scopeId = (int)Mage::getConfig()->getNode('websites/' . $website . '/system/website/id');
41
- } else {
42
- $scope = 'default';
43
- $scopeId = Mage_Core_Model_App::ADMIN_STORE_ID;
44
- }
45
-
46
- return array($scope, $scopeId);
47
- }
48
-
49
- /**
50
- * Returns the Website Id given the scope/scopeId
51
- *
52
- * @param string $scope
53
- * @param int $scopeId
54
- * @return int
55
- */
56
- public function getWebsiteIdFromScope($scope, $scopeId)
57
- {
58
- $websiteId = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID)->getWebsiteId();
59
-
60
- if ($scope === 'websites') {
61
- $websiteId = $scopeId;
62
- } elseif ($scope === 'stores') {
63
- $websiteId = Mage::app()->getStore($scopeId)->getWebsiteId();
64
- }
65
-
66
- return $websiteId;
67
- }
68
-
69
- /**
70
- * Returns the Store Id given the scope/scopeId
71
- *
72
- * @param string $scope
73
- * @param int $scopeId
74
- * @return int
75
- * @throws Mage_Core_Exception
76
- */
77
- public function getStoreIdFromScope($scope, $scopeId)
78
- {
79
- $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
80
-
81
- if ($scope === 'websites') {
82
- try {
83
- $storeId = Mage::app()->getWebsite($scopeId)->getDefaultGroup()->getDefaultStoreId();
84
- } catch (Exception $e) {
85
- // Use admin store id as above
86
- }
87
- } elseif ($scope === 'stores') {
88
- $storeId = $scopeId;
89
- }
90
-
91
- return $storeId;
92
- }
93
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Provides _getScope function for getting scope and scope id given a website and/or store.
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Model_Config_Scope
23
+ {
24
+ /**
25
+ * Get the scope from $website or $store
26
+ *
27
+ * @param string $website
28
+ * @param string $store
29
+ * @return array
30
+ */
31
+ public function _getScope($website, $store)
32
+ {
33
+ // This code is duplicated from the _getScope method in adminhtml/core_config. It is duplicated because
34
+ // that method is protected and we have need to determine the scope using the same logic.
35
+ if ($store) {
36
+ $scope = 'stores';
37
+ $scopeId = (int)Mage::getConfig()->getNode('stores/' . $store . '/system/store/id');
38
+ } elseif ($website) {
39
+ $scope = 'websites';
40
+ $scopeId = (int)Mage::getConfig()->getNode('websites/' . $website . '/system/website/id');
41
+ } else {
42
+ $scope = 'default';
43
+ $scopeId = Mage_Core_Model_App::ADMIN_STORE_ID;
44
+ }
45
+
46
+ return array($scope, $scopeId);
47
+ }
48
+
49
+ /**
50
+ * Returns the Website Id given the scope/scopeId
51
+ *
52
+ * @param string $scope
53
+ * @param int $scopeId
54
+ * @return int
55
+ */
56
+ public function getWebsiteIdFromScope($scope, $scopeId)
57
+ {
58
+ $websiteId = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID)->getWebsiteId();
59
+
60
+ if ($scope === 'websites') {
61
+ $websiteId = $scopeId;
62
+ } elseif ($scope === 'stores') {
63
+ $websiteId = Mage::app()->getStore($scopeId)->getWebsiteId();
64
+ }
65
+
66
+ return $websiteId;
67
+ }
68
+
69
+ /**
70
+ * Returns the Store Id given the scope/scopeId
71
+ *
72
+ * @param string $scope
73
+ * @param int $scopeId
74
+ * @return int
75
+ * @throws Mage_Core_Exception
76
+ */
77
+ public function getStoreIdFromScope($scope, $scopeId)
78
+ {
79
+ $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
80
+
81
+ if ($scope === 'websites') {
82
+ try {
83
+ $storeId = Mage::app()->getWebsite($scopeId)->getDefaultGroup()->getDefaultStoreId();
84
+ } catch (Exception $e) {
85
+ // Use admin store id as above
86
+ }
87
+ } elseif ($scope === 'stores') {
88
+ $storeId = $scopeId;
89
+ }
90
+
91
+ return $storeId;
92
+ }
93
+ }
app/code/community/Campaignmonitor/Createsend/Model/Config/SubscriptionSources.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Campaign Monitor authentication type selector
20
- *
21
- */
22
- class Campaignmonitor_Createsend_Model_Config_SubscriptionSources
23
- {
24
- const SOURCE_CAMPAIGN_MONITOR = 'cm';
25
- const SOURCE_MAGENTO = 'magento';
26
-
27
- /**
28
- * @return array
29
- */
30
- public function toOptionArray()
31
- {
32
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
33
- $helper = Mage::helper('createsend');
34
- return array(
35
- array(
36
- 'value' => self::SOURCE_CAMPAIGN_MONITOR,
37
- 'label' => $helper->__('Campaign Monitor')
38
- ),
39
- array(
40
- 'value' => self::SOURCE_MAGENTO,
41
- 'label' => $helper->__('Magento')
42
- ),
43
- );
44
- }
45
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Campaign Monitor authentication type selector
20
+ *
21
+ */
22
+ class Campaignmonitor_Createsend_Model_Config_SubscriptionSources
23
+ {
24
+ const SOURCE_CAMPAIGN_MONITOR = 'cm';
25
+ const SOURCE_MAGENTO = 'magento';
26
+
27
+ /**
28
+ * @return array
29
+ */
30
+ public function toOptionArray()
31
+ {
32
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
33
+ $helper = Mage::helper('createsend');
34
+ return array(
35
+ array(
36
+ 'value' => self::SOURCE_CAMPAIGN_MONITOR,
37
+ 'label' => $helper->__('Campaign Monitor')
38
+ ),
39
+ array(
40
+ 'value' => self::SOURCE_MAGENTO,
41
+ 'label' => $helper->__('Magento')
42
+ ),
43
+ );
44
+ }
45
  }
app/code/community/Campaignmonitor/Createsend/Model/Cron.php CHANGED
@@ -1,115 +1,116 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- abstract class Campaignmonitor_Createsend_Model_Cron
19
- {
20
- const LOG_ITERATOR_START = 'Scope Iterator Start.';
21
- const LOG_ITERATOR_END = 'Scope Iterator End.';
22
- const LOG_ITERATOR_ITEM = 'Calling %1$s for %2$s...';
23
-
24
- /**
25
- * The method to register in config.xml for Magento cron.
26
- * Only executes the runJob method if cron is enabled in configuration.
27
- */
28
- public function runFromMagentoCron()
29
- {
30
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
31
- $helper = Mage::helper('createsend');
32
-
33
- $useMagentoCron = $helper->isMagentoCronEnabled(Mage_Core_Model_App::ADMIN_STORE_ID);
34
-
35
- if ($useMagentoCron) {
36
- $this->runJob();
37
- }
38
- }
39
-
40
- /**
41
- * Subclasses must implement this method which will be executed if cron is enabled
42
- *
43
- * @return mixed
44
- */
45
- abstract function runJob();
46
-
47
- /**
48
- * Executes function(s) in $functions array for all scopes where $configPath configuration value is defined
49
- * (not inherited) and $helper->$helperConfig($storeId) is true.
50
- *
51
- * Passes the values for the configuration value for $configPath ($configValue), $scope and $scopeId
52
- * to the function(s), in this order.
53
- *
54
- * $functions array should be in the form of:
55
- *
56
- * <pre>
57
- * array(
58
- * array(
59
- * 'class' => $object,
60
- * 'method' => 'method1',
61
- * ),
62
- * array(
63
- * 'class' => $object,
64
- * 'method' => 'method2',
65
- * ),
66
- * )
67
- * </pre>
68
- *
69
- * @param string $configPath The path to the configuration value, eg. 'createsend_general/api/list_id'
70
- * @param string $helperConfigChecker The name of the helper method which determines if the function(s) should
71
- * should be executed for the particular scope/scopeId
72
- * @param array $functions An array of object and method pair(s) to execute by calling call_user_func_array()
73
- */
74
- public function iterateScopes($configPath, $helperConfigChecker, array $functions = array())
75
- {
76
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
77
- $helper = Mage::helper('createsend');
78
-
79
- $helper->log(self::LOG_ITERATOR_START);
80
-
81
- // Get all scopes where List ID is defined (not inherited)
82
- $configModel = Mage::getModel('core/config_data')->getCollection()
83
- ->addFieldToFilter('path', $configPath)
84
- ->addFieldToSelect('value')
85
- ->addFieldToSelect('scope')
86
- ->addFieldToSelect('scope_id');
87
-
88
- foreach ($configModel as $config) {
89
- $configValue = $config->getValue();
90
- $scope = $config->getScope();
91
- $scopeId = $config->getScopeId();
92
-
93
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
94
- $scopeModel = Mage::getModel('createsend/config_scope');
95
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
96
-
97
- $configEnabled = call_user_func_array(array($helper, $helperConfigChecker), array($storeId));
98
- if ($configEnabled) {
99
- foreach ($functions as $function) {
100
- $object = $function['class'];
101
- $method = $function['method'];
102
-
103
- $helper->log(sprintf(self::LOG_ITERATOR_ITEM, $method, $configValue));
104
-
105
- call_user_func_array(
106
- array($object, $method),
107
- array($configValue, $scope, $scopeId)
108
- );
109
- }
110
- }
111
- }
112
-
113
- $helper->log(self::LOG_ITERATOR_END);
114
- }
 
115
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ abstract class Campaignmonitor_Createsend_Model_Cron
19
+ {
20
+ const LOG_ITERATOR_START = 'Scope Iterator Start.';
21
+ const LOG_ITERATOR_END = 'Scope Iterator End.';
22
+ const LOG_ITERATOR_ITEM = 'Calling %1$s for %2$s...';
23
+
24
+ /**
25
+ * The method to register in config.xml for Magento cron.
26
+ * Only executes the runJob method if cron is enabled in configuration.
27
+ */
28
+ public function runFromMagentoCron()
29
+ {
30
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
31
+ $helper = Mage::helper('createsend');
32
+
33
+ $useMagentoCron = $helper->isMagentoCronEnabled(Mage_Core_Model_App::ADMIN_STORE_ID);
34
+
35
+ if ($useMagentoCron) {
36
+
37
+ $this->runJob();
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Subclasses must implement this method which will be executed if cron is enabled
43
+ *
44
+ * @return mixed
45
+ */
46
+ public abstract function runJob();
47
+
48
+ /**
49
+ * Executes function(s) in $functions array for all scopes where $configPath configuration value is defined
50
+ * (not inherited) and $helper->$helperConfig($storeId) is true.
51
+ *
52
+ * Passes the values for the configuration value for $configPath ($configValue), $scope and $scopeId
53
+ * to the function(s), in this order.
54
+ *
55
+ * $functions array should be in the form of:
56
+ *
57
+ * <pre>
58
+ * array(
59
+ * array(
60
+ * 'class' => $object,
61
+ * 'method' => 'method1',
62
+ * ),
63
+ * array(
64
+ * 'class' => $object,
65
+ * 'method' => 'method2',
66
+ * ),
67
+ * )
68
+ * </pre>
69
+ *
70
+ * @param string $configPath The path to the configuration value, eg. 'createsend_general/api/list_id'
71
+ * @param string $helperConfigChecker The name of the helper method which determines if the function(s) should
72
+ * should be executed for the particular scope/scopeId
73
+ * @param array $functions An array of object and method pair(s) to execute by calling call_user_func_array()
74
+ */
75
+ public function iterateScopes($configPath, $helperConfigChecker, array $functions = array())
76
+ {
77
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
78
+ $helper = Mage::helper('createsend');
79
+
80
+ $helper->log(self::LOG_ITERATOR_START);
81
+
82
+ // Get all scopes where List ID is defined (not inherited)
83
+ $configModel = Mage::getModel('core/config_data')->getCollection()
84
+ ->addFieldToFilter('path', $configPath)
85
+ ->addFieldToSelect('value')
86
+ ->addFieldToSelect('scope')
87
+ ->addFieldToSelect('scope_id');
88
+
89
+ foreach ($configModel as $config) {
90
+ $configValue = $config->getValue();
91
+ $scope = $config->getScope();
92
+ $scopeId = $config->getScopeId();
93
+
94
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
95
+ $scopeModel = Mage::getModel('createsend/config_scope');
96
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
97
+
98
+ $configEnabled = call_user_func_array(array($helper, $helperConfigChecker), array($storeId));
99
+ if ($configEnabled) {
100
+ foreach ($functions as $function) {
101
+ $object = $function['class'];
102
+ $method = $function['method'];
103
+
104
+ $helper->log(sprintf(self::LOG_ITERATOR_ITEM, $method, $configValue));
105
+
106
+ call_user_func_array(
107
+ array($object, $method),
108
+ array($configValue, $scope, $scopeId)
109
+ );
110
+ }
111
+ }
112
+ }
113
+
114
+ $helper->log(self::LOG_ITERATOR_END);
115
+ }
116
  }
app/code/community/Campaignmonitor/Createsend/Model/Customer/Observer.php CHANGED
@@ -1,557 +1,557 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Responsible for taking action on Createsend as a result of some customer action.
20
- */
21
- class Campaignmonitor_Createsend_Model_Customer_Observer
22
- {
23
- const MSG_CUSTOM_FIELDS_CREATED = 'Campaign Monitor custom fields created.';
24
- const MSG_CANNOT_DELETE_CORE_CUSTOM_FIELDS = 'You cannot remove a core custom field. Core custom fields restored.';
25
- const MSG_DUPLICATE_CUSTOMER_FIELDS = 'You have defined duplicate customer attributes: %s';
26
- const MSG_DUPLICATE_PRODUCT_FIELDS = 'You have defined duplicate wishlist product attributes: %s';
27
-
28
-
29
- /**
30
- * Updates the subscription status of a user on campaign monitor based on user data in Magento
31
- *
32
- * @param Varien_Event_Observer $observer
33
- * @listen customer_save_before
34
- * @listen sales_order_save_after
35
- * @listen wishlist_product_add_after
36
- */
37
- public function checkSubscriptionStatus($observer)
38
- {
39
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
40
- $helper = Mage::helper("createsend");
41
- $event = $observer->getEvent();
42
- /** @var Mage_Customer_Model_Customer $customer */
43
- $customer = $event->getCustomer();
44
-
45
- if (!$customer) {
46
- $order = $event->getOrder();
47
- if ($order) {
48
- $customerId = $order->getCustomerId();
49
-
50
- if (!$customerId) {
51
- return;
52
- }
53
-
54
- $customer = Mage::getModel('customer/customer')->load($customerId);
55
- } else {
56
- $eventData = $event->getData();
57
- $items = $eventData['items'];
58
-
59
- if (count($items) > 0) {
60
- /** @var Mage_Wishlist_Model_Item $item */
61
- $item = $items[0];
62
- $itemData = $item->getData();
63
- /** @var Mage_Wishlist_Model_Wishlist $wishlist */
64
- $wishlist = $itemData['wishlist'];
65
- $wishlistData = $wishlist->getData();
66
- $customerId = $wishlistData['customer_id'];
67
-
68
- if (!$customerId) {
69
- return;
70
- }
71
-
72
- $customer = Mage::getModel('customer/customer')->load($customerId);
73
- }
74
- }
75
- }
76
-
77
- $name = $customer->getName();
78
- $newEmail = $customer->getEmail();
79
- $subscribed = $customer->getIsSubscribed();
80
- $oldEmail = Mage::getModel('customer/customer')->load($customer->getId())->getEmail();
81
-
82
- // if subscribed is NULL (i.e. because the form didn't set it one way
83
- // or the other), get the existing value from the database
84
- if ($subscribed === null) {
85
- $subscribed = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer)->isSubscribed();
86
- }
87
-
88
- $customFields = Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customer);
89
-
90
- /** @var Campaignmonitor_Createsend_Model_Api $api */
91
- $api = Mage::getModel('createsend/api');
92
-
93
- $scope = 'stores';
94
- $scopeId = $customer->getStoreId();
95
-
96
- $storeId = $customer->getStoreId();
97
-
98
- if ($subscribed) {
99
- /* If the customer either:
100
- 1) Already exists (i.e. has an old email address)
101
- 2) Has changed their email address
102
- unsubscribe their old address. */
103
- if ($oldEmail && $newEmail !== $oldEmail) {
104
- $api->call(
105
- Zend_Http_Client::POST,
106
- "subscribers/{$helper->getListId($storeId)}/unsubscribe",
107
- array(
108
- 'EmailAddress' => $oldEmail
109
- ),
110
- array(),
111
- $scope,
112
- $scopeId
113
- );
114
- }
115
-
116
- // Resubscribing during the adding process; otherwise someone who was unsubscribed will remain unsubscribed
117
- $api->call(
118
- Zend_Http_Client::POST,
119
- 'subscribers/' . $helper->getListId($storeId),
120
- array(
121
- 'EmailAddress' => $newEmail,
122
- 'Name' => $name,
123
- 'CustomFields' => $customFields,
124
- 'Resubscribe' => true,
125
- 'RestartSubscriptionBasedAutoresponders' => true
126
- ),
127
- array(),
128
- $scope,
129
- $scopeId
130
- );
131
-
132
- } else {
133
- $api->call(
134
- Zend_Http_Client::POST,
135
- "subscribers/{$helper->getListId($storeId)}/unsubscribe",
136
- array(
137
- 'EmailAddress' => $oldEmail
138
- ),
139
- array(),
140
- $scope,
141
- $scopeId
142
- );
143
- }
144
- }
145
-
146
- /**
147
- * Unsubscribes a customer when they are deleted.
148
- *
149
- * @param Varien_Event_Observer $observer
150
- * @listen customer_delete_before
151
- */
152
- public function customerDeleted($observer)
153
- {
154
- $customer = $observer->getEvent()->getCustomer();
155
- $email = $customer->getEmail();
156
-
157
- $scope = 'stores';
158
- $scopeId = $customer->getStoreId();
159
-
160
- /** @var Campaignmonitor_Createsend_Model_Api $api */
161
- $api = Mage::getModel('createsend/api');
162
-
163
- $api->unsubscribe($email, $scope, $scopeId);
164
- }
165
-
166
- /**
167
- * Creates custom fields in Campaign Monitor based on custom field mapping defined by Magento admin
168
- *
169
- * @param Varien_Event_Observer $observer
170
- * @listen admin_system_config_changed_section_createsend_customer
171
- * @throws Mage_Core_Exception if the API returns a bad result
172
- */
173
- public function createCustomFields(Varien_Event_Observer $observer)
174
- {
175
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
176
- $scopeModel = Mage::getSingleton('createsend/config_scope');
177
- list($scope, $scopeId) = $scopeModel->_getScope($observer->getWebsite(), $observer->getStore());
178
-
179
- /** @var Campaignmonitor_Createsend_Helper_Config $apiHelper */
180
- $apiHelper = Mage::helper('createsend/config');
181
-
182
- // Check that there haven't been duplicate custom fields
183
- $duplicateCustomerAttributes = $apiHelper->getDuplicateAttributes(
184
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_M_TO_CM_ATTRIBUTES,
185
- $scope,
186
- $scopeId
187
- );
188
- if (count($duplicateCustomerAttributes)) {
189
- // Show warning if admin tries to add the same custom field multiple times
190
- Mage::getSingleton('adminhtml/session')->addWarning(
191
- sprintf(
192
- self::MSG_DUPLICATE_CUSTOMER_FIELDS,
193
- implode(
194
- ', ',
195
- $this->getAttributeLabels($duplicateCustomerAttributes, 'createsend/config_customerAttributes')
196
- )
197
- )
198
- );
199
- }
200
-
201
- // Check that there haven't been duplicate product fields
202
- $duplicateProductAttributes = $apiHelper->getDuplicateAttributes(
203
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES,
204
- $scope,
205
- $scopeId
206
- );
207
- if (count($duplicateProductAttributes)) {
208
- // Show warning if admin tries to add the same custom product field multiple times
209
- Mage::getSingleton('adminhtml/session')->addWarning(
210
- sprintf(
211
- self::MSG_DUPLICATE_PRODUCT_FIELDS,
212
- implode(
213
- ', ',
214
- $this->getAttributeLabels($duplicateProductAttributes, 'createsend/config_productAttributes')
215
- )
216
- )
217
- );
218
- }
219
-
220
- // Do not allow deleting of default/'core' custom fields
221
- $newFieldCount = $apiHelper->createDefaultCustomFields($scope, $scopeId);
222
- if ($newFieldCount > 0) {
223
- // Show warning message when a default/core custom field was attempted to be deleted
224
- Mage::getSingleton('adminhtml/session')->addWarning(self::MSG_CANNOT_DELETE_CORE_CUSTOM_FIELDS);
225
- }
226
-
227
- if ($observer->hasDataChanges()) {
228
- // Create customer custom fields
229
- $this->createAllCustomFields($scope, $scopeId);
230
- }
231
- }
232
-
233
- /**
234
- * Returns all the attribute labels for the list of attributes in $attributes
235
- * using the source model $classSpec
236
- *
237
- * @param array $attributes List of customer/product attributes
238
- * @param string $classSpec of class Campaignmonitor_Createsend_Model_Config_Attributes_Abstract
239
- * @return array
240
- */
241
- protected function getAttributeLabels($attributes, $classSpec)
242
- {
243
- /** @var Campaignmonitor_Createsend_Model_Config_Attributes_Abstract $source */
244
- $source = Mage::getModel($classSpec);
245
-
246
- $labels = array();
247
- foreach ($attributes as $attribute) {
248
- $labels[] = $source->getFieldLabel($attribute);
249
- }
250
-
251
- return $labels;
252
- }
253
-
254
- /**
255
- * Creates custom fields in Campaign Monitor for the scope/scopeId
256
- *
257
- * @param string $scope
258
- * @param int $scopeId
259
- * @throws Mage_Core_Exception
260
- */
261
- public function createAllCustomFields($scope, $scopeId)
262
- {
263
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
264
- $helper = Mage::helper('createsend');
265
-
266
- /** @var Campaignmonitor_Createsend_Model_Api $api */
267
- $api = Mage::getModel('createsend/api');
268
-
269
- $customerErrors = $api->createCustomerCustomFields($scope, $scopeId);
270
- $wishlistErrors = $api->createWishlistCustomFields($scope, $scopeId);
271
-
272
- $errors = array_merge_recursive($customerErrors, $wishlistErrors);
273
-
274
- if (count($errors)) {
275
- foreach ($errors as $error => $fields) {
276
- $errorMsg = sprintf(
277
- $api::ERR_CANNOT_CREATE_CUSTOM_FIELD,
278
- implode(', ', $fields),
279
- $error
280
- );
281
-
282
- Mage::getSingleton('adminhtml/session')->addError($errorMsg);
283
- }
284
- }
285
- }
286
-
287
- /**
288
- * Generate an array of custom fields based on a config setting and customer data.
289
- * Customer data includes purchase and wish list products data.
290
- *
291
- * @param Mage_Customer_Model_Customer $customer
292
- * @return array
293
- */
294
- public static function generateCustomFields($customer)
295
- {
296
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
297
- $helper = Mage::helper('createsend');
298
-
299
- /** @var Campaignmonitor_Createsend_Model_Api $api */
300
- $api = Mage::getModel('createsend/api');
301
-
302
- /** @var Campaignmonitor_Createsend_Model_Config_CustomerAttributes $attrSource */
303
- $attrSource = Mage::getSingleton('createsend/config_customerAttributes');
304
-
305
- if ($customer->getId()) {
306
- $storeId = $customer->getStoreId();
307
- } else {
308
- $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
309
- }
310
- $linkedAttributes = @unserialize(Mage::getStoreConfig($helper::XML_PATH_M_TO_CM_ATTRIBUTES, $storeId));
311
-
312
- $customFields = array();
313
- if (!empty($linkedAttributes)) {
314
- if ($customer->getId()) {
315
- $customerData = $customer->getData();
316
-
317
- } else {
318
- $customerData = array();
319
-
320
- }
321
- foreach ($linkedAttributes as $la) {
322
- $magentoAtt = $la['magento'];
323
- $cmAtt = $api->formatCustomFieldName($attrSource->getCustomFieldName($la['magento'], true));
324
- Mage::log($cmAtt);
325
-
326
-
327
- // try and translate IDs to names where possible
328
- if ($magentoAtt == 'group_id') {
329
- if ($customer->getId()) {
330
- $d = Mage::getModel('customer/group')->load($customer->getGroupId())->getData();
331
- if (array_key_exists('customer_group_code', $d)) {
332
- $customFields[] = array("Key" => $cmAtt, "Value" => $d['customer_group_code']);
333
- }
334
- }
335
- } elseif ($magentoAtt == 'website_id') {
336
- if ($customer->getId()) {
337
- $d = Mage::app()->getWebsite($customer->getWebsiteId())->getData();
338
- if (array_key_exists('name', $d)) {
339
- $customFields[] = array("Key" => $cmAtt, "Value" => $d['name']);
340
- }
341
- }
342
- } elseif ($magentoAtt == 'store_id') {
343
- if ($customer->getId()) {
344
- $d = Mage::app()->getStore($customer->getStoreId())->getData();
345
- if (array_key_exists('name', $d)) {
346
- $customFields[] = array("Key" => $cmAtt, "Value" => $d['name']);
347
- }
348
- }
349
- } elseif ($magentoAtt == 'gender') {
350
-
351
- $gender = "";
352
- if (array_key_exists($gender, $customerData)){
353
- $gender = $customer->getAttribute($magentoAtt)->getSource()->getOptionText($customerData[$magentoAtt]);
354
- }
355
-
356
- $customFields[] = array("Key" => $cmAtt, "Value" => $gender);
357
- } elseif ($magentoAtt == 'confirmation') {
358
- // This attribute should have been named confirmation_key
359
- // If not yet confirmed, this attribute will contain the confirmation key
360
- // Once confirmed, this attribute will be empty
361
- $confirmed = empty($customerData[$magentoAtt]) ? 'Yes' : 'No';
362
- $customFields[] = array("Key" => $cmAtt, "Value" => $confirmed);
363
- } elseif ($magentoAtt == 'FONTIS-has-account') {
364
- if ($customer->getId()) {
365
- $customFields[] = array('Key' => $cmAtt, 'Value' => 'Yes');
366
- } else {
367
- $customFields[] = array('Key' => $cmAtt, 'Value' => 'No');
368
- }
369
- } elseif ($magentoAtt == 'FONTIS-number-of-wishlist-items') {
370
- if ($customer->getId()) {
371
- /** @var Mage_Wishlist_Model_Wishlist $wishList */
372
- $wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer);
373
-
374
- $customFields[] = array('Key' => $cmAtt, 'Value' => $wishList->getItemsCount());
375
- }
376
- } elseif (strncmp('FONTIS-sales', $magentoAtt, 12) == 0) {
377
- $purchaseData = array();
378
-
379
- if ($customer->getId()) {
380
- if (strncmp('FONTIS-sales-last-order', $magentoAtt, 23) == 0) {
381
- // get last order
382
- $lastOrder = self::_getEndOrder(
383
- $customer->getId(), 'DESC', array(
384
- 'grand_total',
385
- 'created_at'
386
- )
387
- );
388
- $purchaseData['last-order-value'] = $lastOrder->getGrandTotal();
389
- $purchaseData['last-order-date'] = $lastOrder->getCreatedAt();
390
- } elseif (strncmp('FONTIS-sales-first-order', $magentoAtt, 24) == 0) {
391
- // get first order
392
- $firstOrder = self::_getEndOrder($customer->getId(), 'ASC', array('created_at'));
393
- $purchaseData['first-order-date'] = $firstOrder->getCreatedAt();
394
- } else {
395
- $orderCollection = Mage::getModel('sales/order')->getCollection()
396
- ->addFieldToFilter('customer_id', $customer->getId())
397
- ->addFieldToFilter('status', array('neq' => 'canceled'))
398
- ->addAttributeToSelect('grand_total')
399
- ->addAttributeToSelect('total_qty_ordered');
400
-
401
- $orderTotals = $orderCollection->getColumnValues('grand_total');
402
-
403
- // get total order value
404
- $purchaseData['total-order-value'] = array_sum($orderTotals);
405
-
406
- // get total number of orders
407
- $purchaseData['total-number-of-orders'] = count($orderTotals);
408
-
409
- // get average order value
410
- if ($purchaseData['total-number-of-orders'] > 0) {
411
- $purchaseData['average-order-value'] =
412
- round($purchaseData['total-order-value'] / $purchaseData['total-number-of-orders'], 4);
413
- } else {
414
- $purchaseData['average-order-value'] = 0;
415
- }
416
-
417
- // get total number of products ordered
418
- $productTotals = $orderCollection->getColumnValues('total_qty_ordered');
419
- $purchaseData['total-number-of-products-ordered'] = array_sum($productTotals);
420
- }
421
-
422
- $purchaseAtt = substr($magentoAtt, 13, strlen($magentoAtt));
423
- $customFields[] = array("Key" => $cmAtt, "Value" => $purchaseData[$purchaseAtt]);
424
- }
425
-
426
- } elseif (strncmp('FONTIS', $magentoAtt, 6) == 0) {
427
- if ($customer->getId()) {
428
- if (strncmp('FONTIS-billing', $magentoAtt, 14) == 0) {
429
- $d = $customer->getDefaultBillingAddress();
430
- if ($d) {
431
- $d = $d->getData();
432
- $addressAtt = substr($magentoAtt, 15, strlen($magentoAtt));
433
- }
434
- } else {
435
- $d = $customer->getDefaultShippingAddress();
436
- if ($d) {
437
- $d = $d->getData();
438
- $addressAtt = substr($magentoAtt, 16, strlen($magentoAtt));
439
- }
440
- }
441
-
442
- if ($d && $addressAtt == 'region_id') {
443
- if (array_key_exists('region_id', $d)) {
444
- $region = Mage::getModel('directory/region')->load($d['region_id']);
445
- $customFields[] = array("Key" => $cmAtt, "Value" => $region->getName());
446
- }
447
- } elseif ($d) {
448
- if (array_key_exists($addressAtt, $d)) {
449
- $customFields[] = array("Key" => $cmAtt, "Value" => $d[$addressAtt]);
450
- }
451
- }
452
- }
453
- } else {
454
- if (array_key_exists($magentoAtt, $customerData)) {
455
-
456
- $attribute = $customer->getAttribute($magentoAtt);
457
- if ($attribute->getFrontendInput() == 'select' || $attribute->getSourceModel()) {
458
- $label = $attribute->getSource()->getOptionText($customerData[$magentoAtt]);
459
- $customFields[] = array("Key" => $cmAtt, "Value" => $label);
460
- } else {
461
- $customFields[] = array("Key" => $cmAtt, "Value" => $customerData[$magentoAtt]);
462
- }
463
- }
464
- }
465
- }
466
- }
467
-
468
- if ($customer->getId()) {
469
- /** @var Campaignmonitor_Createsend_Model_Config_ProductAttributes $attrSource */
470
- $attrSource = Mage::getSingleton('createsend/config_productAttributes');
471
-
472
- $productAttributes = @unserialize(
473
- Mage::getStoreConfig($helper::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES, $storeId)
474
- );
475
-
476
- /** @var Mage_Wishlist_Model_Wishlist $wishList */
477
- $wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer);
478
- $wishListItemCollection = $wishList->getItemCollection();
479
-
480
- $maxWishlistItems = $helper->getMaxWistlistItems($storeId);
481
-
482
- if (!empty($productAttributes) & !empty($maxWishlistItems)) {
483
- $count = 0;
484
- foreach ($wishListItemCollection as $item) {
485
- if ($count >= $maxWishlistItems) {
486
- break;
487
- }
488
-
489
- $count++;
490
- $product = $item->getProduct();
491
-
492
- foreach ($productAttributes as $pa) {
493
- $magentoAtt = $pa['magento'];
494
- $cmAtt = $attrSource->getCustomFieldName($pa['magento'], true);
495
-
496
- if (strncmp($magentoAtt, "price", 5) == 0) {
497
- $value = $product->getFinalPrice();
498
- } else {
499
- $value = $product->getData($magentoAtt);
500
- }
501
-
502
- $customFields[] = array(
503
- "Key" => $api->formatCustomFieldName(
504
- sprintf(
505
- $api::WISHLIST_CUSTOM_FIELD_PATTERN, $api::WISHLIST_CUSTOM_FIELD_PREFIX, $count, $cmAtt
506
- )
507
- ),
508
- "Value" => $value
509
- );
510
- }
511
- }
512
-
513
-
514
-
515
- // Clear out other items, if any
516
- for ($i = $count + 1; $i <= $maxWishlistItems; $i++) {
517
- foreach ($productAttributes as $pa) {
518
- $cmAtt = $attrSource->getCustomFieldName($pa['magento'], true);
519
-
520
- $customFields[] = array(
521
- "Key" => $api->formatCustomFieldName(
522
- sprintf($api::WISHLIST_CUSTOM_FIELD_PATTERN, $api::WISHLIST_CUSTOM_FIELD_PREFIX, $i, $cmAtt)
523
- ),
524
- "Clear" => true
525
- );
526
- }
527
- }
528
- }
529
- }
530
-
531
- return $customFields;
532
- }
533
-
534
- /**
535
- * Returns the first or last order of customer given the customer's customerId.
536
- * Excludes cancelled orders.
537
- *
538
- * @param int $customerId Customer ID
539
- * @param string $sortOrder Use "ASC" to return first order, "DESC" to return last order
540
- * @param array $selectFields fields to be selected
541
- * @return Mage_Sales_Model_Order
542
- */
543
- protected static function _getEndOrder($customerId, $sortOrder, $selectFields) {
544
- /** @var Mage_Sales_Model_Order[]|Mage_Sales_Model_Resource_Order_Collection $orders */
545
- $orders = Mage::getModel('sales/order')->getCollection()
546
- ->addAttributeToFilter('customer_id', $customerId)
547
- ->addFieldToFilter('status', array('neq' => 'canceled'))
548
- ->addAttributeToSort('created_at', $sortOrder)
549
- ->setPageSize(1);
550
-
551
- foreach ($selectFields as $field) {
552
- $orders->addFieldToSelect($field);
553
- }
554
-
555
- return $orders->getFirstItem();
556
- }
557
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Responsible for taking action on Createsend as a result of some customer action.
20
+ */
21
+ class Campaignmonitor_Createsend_Model_Customer_Observer
22
+ {
23
+ const MSG_CUSTOM_FIELDS_CREATED = 'Campaign Monitor custom fields created.';
24
+ const MSG_CANNOT_DELETE_CORE_CUSTOM_FIELDS = 'You cannot remove a core custom field. Core custom fields restored.';
25
+ const MSG_DUPLICATE_CUSTOMER_FIELDS = 'You have defined duplicate customer attributes: %s';
26
+ const MSG_DUPLICATE_PRODUCT_FIELDS = 'You have defined duplicate wishlist product attributes: %s';
27
+
28
+
29
+ /**
30
+ * Updates the subscription status of a user on campaign monitor based on user data in Magento
31
+ *
32
+ * @param Varien_Event_Observer $observer
33
+ * @listen customer_save_before
34
+ * @listen sales_order_save_after
35
+ * @listen wishlist_product_add_after
36
+ */
37
+ public function checkSubscriptionStatus($observer)
38
+ {
39
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
40
+ $helper = Mage::helper("createsend");
41
+ $event = $observer->getEvent();
42
+ /** @var Mage_Customer_Model_Customer $customer */
43
+ $customer = $event->getCustomer();
44
+
45
+ if (!$customer) {
46
+ $order = $event->getOrder();
47
+ if ($order) {
48
+ $customerId = $order->getCustomerId();
49
+
50
+ if (!$customerId) {
51
+ return;
52
+ }
53
+
54
+ $customer = Mage::getModel('customer/customer')->load($customerId);
55
+ } else {
56
+ $eventData = $event->getData();
57
+ $items = $eventData['items'];
58
+
59
+ if (count($items) > 0) {
60
+ /** @var Mage_Wishlist_Model_Item $item */
61
+ $item = $items[0];
62
+ $itemData = $item->getData();
63
+ /** @var Mage_Wishlist_Model_Wishlist $wishlist */
64
+ $wishlist = $itemData['wishlist'];
65
+ $wishlistData = $wishlist->getData();
66
+ $customerId = $wishlistData['customer_id'];
67
+
68
+ if (!$customerId) {
69
+ return;
70
+ }
71
+
72
+ $customer = Mage::getModel('customer/customer')->load($customerId);
73
+ }
74
+ }
75
+ }
76
+
77
+ $name = $customer->getName();
78
+ $newEmail = $customer->getEmail();
79
+ $subscribed = $customer->getIsSubscribed();
80
+ $oldEmail = Mage::getModel('customer/customer')->load($customer->getId())->getEmail();
81
+
82
+ // if subscribed is NULL (i.e. because the form didn't set it one way
83
+ // or the other), get the existing value from the database
84
+ if ($subscribed === null) {
85
+ $subscribed = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer)->isSubscribed();
86
+ }
87
+
88
+ $customFields = Campaignmonitor_Createsend_Model_Customer_Observer::generateCustomFields($customer);
89
+
90
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
91
+ $api = Mage::getModel('createsend/api');
92
+
93
+ $scope = 'stores';
94
+ $scopeId = $customer->getStoreId();
95
+
96
+ $storeId = $customer->getStoreId();
97
+
98
+ if ($subscribed) {
99
+ /* If the customer either:
100
+ 1) Already exists (i.e. has an old email address)
101
+ 2) Has changed their email address
102
+ unsubscribe their old address. */
103
+ if ($oldEmail && $newEmail !== $oldEmail) {
104
+ $api->call(
105
+ Zend_Http_Client::POST,
106
+ "subscribers/{$helper->getListId($storeId)}/unsubscribe",
107
+ array(
108
+ 'EmailAddress' => $oldEmail
109
+ ),
110
+ array(),
111
+ $scope,
112
+ $scopeId
113
+ );
114
+ }
115
+
116
+ // Resubscribing during the adding process; otherwise someone who was unsubscribed will remain unsubscribed
117
+ $api->call(
118
+ Zend_Http_Client::POST,
119
+ 'subscribers/' . $helper->getListId($storeId),
120
+ array(
121
+ 'EmailAddress' => $newEmail,
122
+ 'Name' => $name,
123
+ 'CustomFields' => $customFields,
124
+ 'Resubscribe' => true,
125
+ 'RestartSubscriptionBasedAutoresponders' => true
126
+ ),
127
+ array(),
128
+ $scope,
129
+ $scopeId
130
+ );
131
+
132
+ } else {
133
+ $api->call(
134
+ Zend_Http_Client::POST,
135
+ "subscribers/{$helper->getListId($storeId)}/unsubscribe",
136
+ array(
137
+ 'EmailAddress' => $oldEmail
138
+ ),
139
+ array(),
140
+ $scope,
141
+ $scopeId
142
+ );
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Unsubscribes a customer when they are deleted.
148
+ *
149
+ * @param Varien_Event_Observer $observer
150
+ * @listen customer_delete_before
151
+ */
152
+ public function customerDeleted($observer)
153
+ {
154
+ $customer = $observer->getEvent()->getCustomer();
155
+ $email = $customer->getEmail();
156
+
157
+ $scope = 'stores';
158
+ $scopeId = $customer->getStoreId();
159
+
160
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
161
+ $api = Mage::getModel('createsend/api');
162
+
163
+ $api->unsubscribe($email, $scope, $scopeId);
164
+ }
165
+
166
+ /**
167
+ * Creates custom fields in Campaign Monitor based on custom field mapping defined by Magento admin
168
+ *
169
+ * @param Varien_Event_Observer $observer
170
+ * @listen admin_system_config_changed_section_createsend_customer
171
+ * @throws Mage_Core_Exception if the API returns a bad result
172
+ */
173
+ public function createCustomFields(Varien_Event_Observer $observer)
174
+ {
175
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
176
+ $scopeModel = Mage::getSingleton('createsend/config_scope');
177
+ list($scope, $scopeId) = $scopeModel->_getScope($observer->getWebsite(), $observer->getStore());
178
+
179
+ /** @var Campaignmonitor_Createsend_Helper_Config $apiHelper */
180
+ $apiHelper = Mage::helper('createsend/config');
181
+
182
+ // Check that there haven't been duplicate custom fields
183
+ $duplicateCustomerAttributes = $apiHelper->getDuplicateAttributes(
184
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_M_TO_CM_ATTRIBUTES,
185
+ $scope,
186
+ $scopeId
187
+ );
188
+ if (count($duplicateCustomerAttributes)) {
189
+ // Show warning if admin tries to add the same custom field multiple times
190
+ Mage::getSingleton('adminhtml/session')->addWarning(
191
+ sprintf(
192
+ self::MSG_DUPLICATE_CUSTOMER_FIELDS,
193
+ implode(
194
+ ', ',
195
+ $this->getAttributeLabels($duplicateCustomerAttributes, 'createsend/config_customerAttributes')
196
+ )
197
+ )
198
+ );
199
+ }
200
+
201
+ // Check that there haven't been duplicate product fields
202
+ $duplicateProductAttributes = $apiHelper->getDuplicateAttributes(
203
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES,
204
+ $scope,
205
+ $scopeId
206
+ );
207
+ if (count($duplicateProductAttributes)) {
208
+ // Show warning if admin tries to add the same custom product field multiple times
209
+ Mage::getSingleton('adminhtml/session')->addWarning(
210
+ sprintf(
211
+ self::MSG_DUPLICATE_PRODUCT_FIELDS,
212
+ implode(
213
+ ', ',
214
+ $this->getAttributeLabels($duplicateProductAttributes, 'createsend/config_productAttributes')
215
+ )
216
+ )
217
+ );
218
+ }
219
+
220
+ // Do not allow deleting of default/'core' custom fields
221
+ $newFieldCount = $apiHelper->createDefaultCustomFields($scope, $scopeId);
222
+ if ($newFieldCount > 0) {
223
+ // Show warning message when a default/core custom field was attempted to be deleted
224
+ Mage::getSingleton('adminhtml/session')->addWarning(self::MSG_CANNOT_DELETE_CORE_CUSTOM_FIELDS);
225
+ }
226
+
227
+ if ($observer->hasDataChanges()) {
228
+ // Create customer custom fields
229
+ $this->createAllCustomFields($scope, $scopeId);
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Returns all the attribute labels for the list of attributes in $attributes
235
+ * using the source model $classSpec
236
+ *
237
+ * @param array $attributes List of customer/product attributes
238
+ * @param string $classSpec of class Campaignmonitor_Createsend_Model_Config_Attributes_Abstract
239
+ * @return array
240
+ */
241
+ protected function getAttributeLabels($attributes, $classSpec)
242
+ {
243
+ /** @var Campaignmonitor_Createsend_Model_Config_Attributes_Abstract $source */
244
+ $source = Mage::getModel($classSpec);
245
+
246
+ $labels = array();
247
+ foreach ($attributes as $attribute) {
248
+ $labels[] = $source->getFieldLabel($attribute);
249
+ }
250
+
251
+ return $labels;
252
+ }
253
+
254
+ /**
255
+ * Creates custom fields in Campaign Monitor for the scope/scopeId
256
+ *
257
+ * @param string $scope
258
+ * @param int $scopeId
259
+ * @throws Mage_Core_Exception
260
+ */
261
+ public function createAllCustomFields($scope, $scopeId)
262
+ {
263
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
264
+ $helper = Mage::helper('createsend');
265
+
266
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
267
+ $api = Mage::getModel('createsend/api');
268
+
269
+ $customerErrors = $api->createCustomerCustomFields($scope, $scopeId);
270
+ $wishlistErrors = $api->createWishlistCustomFields($scope, $scopeId);
271
+
272
+ $errors = array_merge_recursive($customerErrors, $wishlistErrors);
273
+
274
+ if (count($errors)) {
275
+ foreach ($errors as $error => $fields) {
276
+ $errorMsg = sprintf(
277
+ $api::ERR_CANNOT_CREATE_CUSTOM_FIELD,
278
+ implode(', ', $fields),
279
+ $error
280
+ );
281
+
282
+ Mage::getSingleton('adminhtml/session')->addError($errorMsg);
283
+ }
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Generate an array of custom fields based on a config setting and customer data.
289
+ * Customer data includes purchase and wish list products data.
290
+ *
291
+ * @param Mage_Customer_Model_Customer $customer
292
+ * @return array
293
+ */
294
+ public static function generateCustomFields($customer)
295
+ {
296
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
297
+ $helper = Mage::helper('createsend');
298
+
299
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
300
+ $api = Mage::getModel('createsend/api');
301
+
302
+ /** @var Campaignmonitor_Createsend_Model_Config_CustomerAttributes $attrSource */
303
+ $attrSource = Mage::getSingleton('createsend/config_customerAttributes');
304
+
305
+ if ($customer->getId()) {
306
+ $storeId = $customer->getStoreId();
307
+ } else {
308
+ $storeId = Mage_Core_Model_App::ADMIN_STORE_ID;
309
+ }
310
+ $linkedAttributes = @unserialize(Mage::getStoreConfig($helper::XML_PATH_M_TO_CM_ATTRIBUTES, $storeId));
311
+
312
+ $customFields = array();
313
+ if (!empty($linkedAttributes)) {
314
+ if ($customer->getId()) {
315
+ $customerData = $customer->getData();
316
+
317
+ } else {
318
+ $customerData = array();
319
+
320
+ }
321
+ foreach ($linkedAttributes as $la) {
322
+ $magentoAtt = $la['magento'];
323
+ $cmAtt = $api->formatCustomFieldName($attrSource->getCustomFieldName($la['magento'], true));
324
+ Mage::log($cmAtt);
325
+
326
+
327
+ // try and translate IDs to names where possible
328
+ if ($magentoAtt == 'group_id') {
329
+ if ($customer->getId()) {
330
+ $d = Mage::getModel('customer/group')->load($customer->getGroupId())->getData();
331
+ if (array_key_exists('customer_group_code', $d)) {
332
+ $customFields[] = array("Key" => $cmAtt, "Value" => $d['customer_group_code']);
333
+ }
334
+ }
335
+ } elseif ($magentoAtt == 'website_id') {
336
+ if ($customer->getId()) {
337
+ $d = Mage::app()->getWebsite($customer->getWebsiteId())->getData();
338
+ if (array_key_exists('name', $d)) {
339
+ $customFields[] = array("Key" => $cmAtt, "Value" => $d['name']);
340
+ }
341
+ }
342
+ } elseif ($magentoAtt == 'store_id') {
343
+ if ($customer->getId()) {
344
+ $d = Mage::app()->getStore($customer->getStoreId())->getData();
345
+ if (array_key_exists('name', $d)) {
346
+ $customFields[] = array("Key" => $cmAtt, "Value" => $d['name']);
347
+ }
348
+ }
349
+ } elseif ($magentoAtt == 'gender') {
350
+
351
+ $gender = "";
352
+ if (array_key_exists($gender, $customerData)){
353
+ $gender = $customer->getAttribute($magentoAtt)->getSource()->getOptionText($customerData[$magentoAtt]);
354
+ }
355
+
356
+ $customFields[] = array("Key" => $cmAtt, "Value" => $gender);
357
+ } elseif ($magentoAtt == 'confirmation') {
358
+ // This attribute should have been named confirmation_key
359
+ // If not yet confirmed, this attribute will contain the confirmation key
360
+ // Once confirmed, this attribute will be empty
361
+ $confirmed = empty($customerData[$magentoAtt]) ? 'Yes' : 'No';
362
+ $customFields[] = array("Key" => $cmAtt, "Value" => $confirmed);
363
+ } elseif ($magentoAtt == 'FONTIS-has-account') {
364
+ if ($customer->getId()) {
365
+ $customFields[] = array('Key' => $cmAtt, 'Value' => 'Yes');
366
+ } else {
367
+ $customFields[] = array('Key' => $cmAtt, 'Value' => 'No');
368
+ }
369
+ } elseif ($magentoAtt == 'FONTIS-number-of-wishlist-items') {
370
+ if ($customer->getId()) {
371
+ /** @var Mage_Wishlist_Model_Wishlist $wishList */
372
+ $wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer);
373
+
374
+ $customFields[] = array('Key' => $cmAtt, 'Value' => $wishList->getItemsCount());
375
+ }
376
+ } elseif (strncmp('FONTIS-sales', $magentoAtt, 12) == 0) {
377
+ $purchaseData = array();
378
+
379
+ if ($customer->getId()) {
380
+ if (strncmp('FONTIS-sales-last-order', $magentoAtt, 23) == 0) {
381
+ // get last order
382
+ $lastOrder = self::_getEndOrder(
383
+ $customer->getId(), 'DESC', array(
384
+ 'grand_total',
385
+ 'created_at'
386
+ )
387
+ );
388
+ $purchaseData['last-order-value'] = $lastOrder->getGrandTotal();
389
+ $purchaseData['last-order-date'] = $lastOrder->getCreatedAt();
390
+ } elseif (strncmp('FONTIS-sales-first-order', $magentoAtt, 24) == 0) {
391
+ // get first order
392
+ $firstOrder = self::_getEndOrder($customer->getId(), 'ASC', array('created_at'));
393
+ $purchaseData['first-order-date'] = $firstOrder->getCreatedAt();
394
+ } else {
395
+ $orderCollection = Mage::getModel('sales/order')->getCollection()
396
+ ->addFieldToFilter('customer_id', $customer->getId())
397
+ ->addFieldToFilter('status', array('neq' => 'canceled'))
398
+ ->addAttributeToSelect('grand_total')
399
+ ->addAttributeToSelect('total_qty_ordered');
400
+
401
+ $orderTotals = $orderCollection->getColumnValues('grand_total');
402
+
403
+ // get total order value
404
+ $purchaseData['total-order-value'] = array_sum($orderTotals);
405
+
406
+ // get total number of orders
407
+ $purchaseData['total-number-of-orders'] = count($orderTotals);
408
+
409
+ // get average order value
410
+ if ($purchaseData['total-number-of-orders'] > 0) {
411
+ $purchaseData['average-order-value'] =
412
+ round($purchaseData['total-order-value'] / $purchaseData['total-number-of-orders'], 4);
413
+ } else {
414
+ $purchaseData['average-order-value'] = 0;
415
+ }
416
+
417
+ // get total number of products ordered
418
+ $productTotals = $orderCollection->getColumnValues('total_qty_ordered');
419
+ $purchaseData['total-number-of-products-ordered'] = array_sum($productTotals);
420
+ }
421
+
422
+ $purchaseAtt = substr($magentoAtt, 13, strlen($magentoAtt));
423
+ $customFields[] = array("Key" => $cmAtt, "Value" => $purchaseData[$purchaseAtt]);
424
+ }
425
+
426
+ } elseif (strncmp('FONTIS', $magentoAtt, 6) == 0) {
427
+ if ($customer->getId()) {
428
+ if (strncmp('FONTIS-billing', $magentoAtt, 14) == 0) {
429
+ $d = $customer->getDefaultBillingAddress();
430
+ if ($d) {
431
+ $d = $d->getData();
432
+ $addressAtt = substr($magentoAtt, 15, strlen($magentoAtt));
433
+ }
434
+ } else {
435
+ $d = $customer->getDefaultShippingAddress();
436
+ if ($d) {
437
+ $d = $d->getData();
438
+ $addressAtt = substr($magentoAtt, 16, strlen($magentoAtt));
439
+ }
440
+ }
441
+
442
+ if ($d && $addressAtt == 'region_id') {
443
+ if (array_key_exists('region_id', $d)) {
444
+ $region = Mage::getModel('directory/region')->load($d['region_id']);
445
+ $customFields[] = array("Key" => $cmAtt, "Value" => $region->getName());
446
+ }
447
+ } elseif ($d) {
448
+ if (array_key_exists($addressAtt, $d)) {
449
+ $customFields[] = array("Key" => $cmAtt, "Value" => $d[$addressAtt]);
450
+ }
451
+ }
452
+ }
453
+ } else {
454
+ if (array_key_exists($magentoAtt, $customerData)) {
455
+
456
+ $attribute = $customer->getAttribute($magentoAtt);
457
+ if ($attribute->getFrontendInput() == 'select' || $attribute->getSourceModel()) {
458
+ $label = $attribute->getSource()->getOptionText($customerData[$magentoAtt]);
459
+ $customFields[] = array("Key" => $cmAtt, "Value" => $label);
460
+ } else {
461
+ $customFields[] = array("Key" => $cmAtt, "Value" => $customerData[$magentoAtt]);
462
+ }
463
+ }
464
+ }
465
+ }
466
+ }
467
+
468
+ if ($customer->getId()) {
469
+ /** @var Campaignmonitor_Createsend_Model_Config_ProductAttributes $attrSource */
470
+ $attrSource = Mage::getSingleton('createsend/config_productAttributes');
471
+
472
+ $productAttributes = @unserialize(
473
+ Mage::getStoreConfig($helper::XML_PATH_WISHLIST_PRODUCT_ATTRIBUTES, $storeId)
474
+ );
475
+
476
+ /** @var Mage_Wishlist_Model_Wishlist $wishList */
477
+ $wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer);
478
+ $wishListItemCollection = $wishList->getItemCollection();
479
+
480
+ $maxWishlistItems = $helper->getMaxWistlistItems($storeId);
481
+
482
+ if (!empty($productAttributes) & !empty($maxWishlistItems)) {
483
+ $count = 0;
484
+ foreach ($wishListItemCollection as $item) {
485
+ if ($count >= $maxWishlistItems) {
486
+ break;
487
+ }
488
+
489
+ $count++;
490
+ $product = $item->getProduct();
491
+
492
+ foreach ($productAttributes as $pa) {
493
+ $magentoAtt = $pa['magento'];
494
+ $cmAtt = $attrSource->getCustomFieldName($pa['magento'], true);
495
+
496
+ if (strncmp($magentoAtt, "price", 5) == 0) {
497
+ $value = $product->getFinalPrice();
498
+ } else {
499
+ $value = $product->getData($magentoAtt);
500
+ }
501
+
502
+ $customFields[] = array(
503
+ "Key" => $api->formatCustomFieldName(
504
+ sprintf(
505
+ $api::WISHLIST_CUSTOM_FIELD_PATTERN, $api::WISHLIST_CUSTOM_FIELD_PREFIX, $count, $cmAtt
506
+ )
507
+ ),
508
+ "Value" => $value
509
+ );
510
+ }
511
+ }
512
+
513
+
514
+
515
+ // Clear out other items, if any
516
+ for ($i = $count + 1; $i <= $maxWishlistItems; $i++) {
517
+ foreach ($productAttributes as $pa) {
518
+ $cmAtt = $attrSource->getCustomFieldName($pa['magento'], true);
519
+
520
+ $customFields[] = array(
521
+ "Key" => $api->formatCustomFieldName(
522
+ sprintf($api::WISHLIST_CUSTOM_FIELD_PATTERN, $api::WISHLIST_CUSTOM_FIELD_PREFIX, $i, $cmAtt)
523
+ ),
524
+ "Clear" => true
525
+ );
526
+ }
527
+ }
528
+ }
529
+ }
530
+
531
+ return $customFields;
532
+ }
533
+
534
+ /**
535
+ * Returns the first or last order of customer given the customer's customerId.
536
+ * Excludes cancelled orders.
537
+ *
538
+ * @param int $customerId Customer ID
539
+ * @param string $sortOrder Use "ASC" to return first order, "DESC" to return last order
540
+ * @param array $selectFields fields to be selected
541
+ * @return Mage_Sales_Model_Order
542
+ */
543
+ protected static function _getEndOrder($customerId, $sortOrder, $selectFields) {
544
+ /** @var Mage_Sales_Model_Order[]|Mage_Sales_Model_Resource_Order_Collection $orders */
545
+ $orders = Mage::getModel('sales/order')->getCollection()
546
+ ->addAttributeToFilter('customer_id', $customerId)
547
+ ->addFieldToFilter('status', array('neq' => 'canceled'))
548
+ ->addAttributeToSort('created_at', $sortOrder)
549
+ ->setPageSize(1);
550
+
551
+ foreach ($selectFields as $field) {
552
+ $orders->addFieldToSelect($field);
553
+ }
554
+
555
+ return $orders->getFirstItem();
556
+ }
557
+ }
app/code/community/Campaignmonitor/Createsend/Model/Email.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Email extends Mage_Core_Model_Abstract
19
- {
20
- const STATUS_SENT = 'Sent';
21
- const STATUS_ACCEPTED = 'Accepted';
22
- const STATUS_DELIVERED = 'Delivered';
23
- const STATUS_BOUNCED = 'Bounced';
24
- const STATUS_SPAM = 'Spam';
25
-
26
- static $statusCodes = array(
27
- self::STATUS_SENT => 'Sent',
28
- self::STATUS_ACCEPTED => 'Accepted',
29
- self::STATUS_DELIVERED => 'Delivered',
30
- self::STATUS_BOUNCED => 'Bounced',
31
- self::STATUS_SPAM => 'Spam'
32
- );
33
-
34
- protected function _construct()
35
- {
36
- $this->_init('createsend/email');
37
- }
38
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Email extends Mage_Core_Model_Abstract
19
+ {
20
+ const STATUS_SENT = 'Sent';
21
+ const STATUS_ACCEPTED = 'Accepted';
22
+ const STATUS_DELIVERED = 'Delivered';
23
+ const STATUS_BOUNCED = 'Bounced';
24
+ const STATUS_SPAM = 'Spam';
25
+
26
+ static $statusCodes = array(
27
+ self::STATUS_SENT => 'Sent',
28
+ self::STATUS_ACCEPTED => 'Accepted',
29
+ self::STATUS_DELIVERED => 'Delivered',
30
+ self::STATUS_BOUNCED => 'Bounced',
31
+ self::STATUS_SPAM => 'Spam'
32
+ );
33
+
34
+ protected function _construct()
35
+ {
36
+ $this->_init('createsend/email');
37
+ }
38
+ }
app/code/community/Campaignmonitor/Createsend/Model/Email/Cron.php CHANGED
@@ -1,182 +1,182 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Email_Cron extends Campaignmonitor_Createsend_Model_Cron
19
- {
20
- const ERR_API_ERROR = 'API Error: %s';
21
- const MAX_EMAIL_PER_REQUEST = 200;
22
- const MAX_REQUEST_LOOPS = 100; // To prevent endless loops in the email retrieval process
23
- const DATE_MIN = '1972-01-01 00:00:00';
24
-
25
- const LOG_DELETING_EMAILS = 'Deleting email sent before %1$s for scope/scopeId (%2$s/%3$s)...';
26
- const LOG_ROWS_DELETED = '%d email rows deleted.';
27
-
28
- /**
29
- * Performs email headers download for all scopes w/ non-inherited List ID
30
- */
31
- public function runJob()
32
- {
33
- $this->iterateScopes(
34
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID,
35
- 'isTransactionalEmailsEnabled',
36
- array(
37
- array(
38
- 'class' => $this,
39
- 'method' => '_downloadEmailFromCM',
40
- ),
41
- array(
42
- 'class' => $this,
43
- 'method' => '_performEmailTableMaintenance',
44
- ),
45
- )
46
- );
47
- }
48
-
49
- /**
50
- * Downloads email headers for scope/scopeId
51
- *
52
- * @param string $listId Unused in this function because List ID is not required for sending transactional emails
53
- * @param string $scope The configuration Scope for which to perform this action
54
- * @param int $scopeId The configuration Scope ID for which to perform this action
55
- */
56
- protected function _downloadEmailFromCM($listId, $scope, $scopeId)
57
- {
58
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
59
- $helper = Mage::helper('createsend');
60
-
61
- /** @var Campaignmonitor_Createsend_Model_Api $api */
62
- $api = Mage::getSingleton('createsend/api');
63
-
64
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
65
- $scopeModel = Mage::getModel('createsend/config_scope');
66
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
67
-
68
- /** @var array $params */
69
- $params = array(
70
- 'clientID' => $helper->getClientId($storeId),
71
- 'count' => self::MAX_EMAIL_PER_REQUEST,
72
- );
73
-
74
- // Get last message id for this scope/scopeId from the database
75
- /** @var array $row */
76
- $row = Mage::getModel('createsend/email')->getCollection()
77
- ->addFieldToFilter('scope', $scope)
78
- ->addFieldToFilter('scope_id', $scopeId)
79
- ->setOrder('sent_at', 'DESC')
80
- ->setPageSize(1)
81
- ->getFirstItem();
82
-
83
- $lastMessageId = null;
84
- $lastMessageDate = self::DATE_MIN;
85
- if ($row) {
86
- $lastMessageId = $row['message_id'];
87
- $lastMessageDate = $row['sent_at'];
88
-
89
- $params['sentAfterID'] = $lastMessageId;
90
- }
91
-
92
- $loopCount = 0;
93
- do {
94
- // Get "Message timeline" from CM
95
- $result = $api->call(
96
- Zend_Http_Client::GET,
97
- "transactional/messages",
98
- array(),
99
- $params,
100
- $scope,
101
- $scopeId
102
- );
103
-
104
- $count = 0;
105
- if ($result['success'] !== false) {
106
- foreach ($result['data'] as $message) {
107
- $count++;
108
-
109
- /** @var Campaignmonitor_Createsend_Model_Email $email */
110
- $email = Mage::getModel('createsend/email');
111
- $email->setMessageId($message['MessageID']);
112
- $email->setStatus($message['Status']);
113
- $email->setSentAt($message['SentAt']);
114
- $email->setRecipient(iconv_mime_decode($message['Recipient']));
115
- $email->setSender($message['From']);
116
- $email->setSubject(iconv_mime_decode($message['Subject']));
117
- $email->setTotalOpens($message['TotalOpens']);
118
- $email->setTotalClicks($message['TotalClicks']);
119
- $email->setCanBeResent($message['CanBeResent']);
120
- $email->setScope($scope);
121
- $email->setScopeId($scopeId);
122
- $email->save();
123
-
124
- // Compare dates, don't assume message dates are in order
125
- if ($message['SentAt'] >= $lastMessageDate) {
126
- $lastMessageId = $message['MessageID'];
127
- $lastMessageDate = $message['SentAt'];
128
- }
129
- }
130
-
131
- $params['sentAfterID'] = $lastMessageId;
132
- } else {
133
- $helper->log(sprintf(self::ERR_API_ERROR, var_export($result, true)), Zend_Log::ERR);
134
- }
135
-
136
- } while (($count >= self::MAX_EMAIL_PER_REQUEST) && (++$loopCount < self::MAX_REQUEST_LOOPS));
137
- }
138
-
139
- /**
140
- * Deletes all email with sent_at earlier than the email retention days configuration
141
- * for the given scope/scopeId.
142
- *
143
- * @param string $listId Unused in this function because List ID is not required for sending transactional emails
144
- * @param string $scope The configuration Scope for which to perform this action
145
- * @param int $scopeId The configuration Scope ID for which to perform this action
146
- */
147
- protected function _performEmailTableMaintenance($listId, $scope, $scopeId)
148
- {
149
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
150
- $helper = Mage::helper('createsend');
151
-
152
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
153
- $scopeModel = Mage::getModel('createsend/config_scope');
154
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
155
-
156
- $retentionDays = $helper->getEmailRetentionDays($storeId);
157
-
158
- $daysAgo = Mage::getModel('core/date')->timestamp(strtotime(sprintf('%d days ago', $retentionDays)));
159
- $daysAgoStr = date('Y-m-d', $daysAgo);
160
-
161
- $helper->log(
162
- sprintf(self::LOG_DELETING_EMAILS, $daysAgoStr, $scope, $scopeId),
163
- Zend_Log::DEBUG
164
- );
165
-
166
- /** @var Varien_Data_Collection_Db $collection */
167
- $collection = Mage::getModel('createsend/email')->getCollection()
168
- ->addFieldToFilter('scope', $scope)
169
- ->addFieldToFilter('scope_id', $scopeId)
170
- ->addFieldToFilter('sent_at', array('lt' => $daysAgoStr))
171
- ->load();
172
-
173
- $count = 0;
174
- /** @var Campaignmonitor_Createsend_Model_Email $email */
175
- foreach ($collection as $email) {
176
- $email->delete();
177
- $count++;
178
- }
179
-
180
- $helper->log(sprintf(self::LOG_ROWS_DELETED, $count), Zend_Log::DEBUG);
181
- }
182
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Email_Cron extends Campaignmonitor_Createsend_Model_Cron
19
+ {
20
+ const ERR_API_ERROR = 'API Error: %s';
21
+ const MAX_EMAIL_PER_REQUEST = 200;
22
+ const MAX_REQUEST_LOOPS = 100; // To prevent endless loops in the email retrieval process
23
+ const DATE_MIN = '1972-01-01 00:00:00';
24
+
25
+ const LOG_DELETING_EMAILS = 'Deleting email sent before %1$s for scope/scopeId (%2$s/%3$s)...';
26
+ const LOG_ROWS_DELETED = '%d email rows deleted.';
27
+
28
+ /**
29
+ * Performs email headers download for all scopes w/ non-inherited List ID
30
+ */
31
+ public function runJob()
32
+ {
33
+ $this->iterateScopes(
34
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID,
35
+ 'isTransactionalEmailsEnabled',
36
+ array(
37
+ array(
38
+ 'class' => $this,
39
+ 'method' => '_downloadEmailFromCM',
40
+ ),
41
+ array(
42
+ 'class' => $this,
43
+ 'method' => '_performEmailTableMaintenance',
44
+ ),
45
+ )
46
+ );
47
+ }
48
+
49
+ /**
50
+ * Downloads email headers for scope/scopeId
51
+ *
52
+ * @param string $listId Unused in this function because List ID is not required for sending transactional emails
53
+ * @param string $scope The configuration Scope for which to perform this action
54
+ * @param int $scopeId The configuration Scope ID for which to perform this action
55
+ */
56
+ protected function _downloadEmailFromCM($listId, $scope, $scopeId)
57
+ {
58
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
59
+ $helper = Mage::helper('createsend');
60
+
61
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
62
+ $api = Mage::getSingleton('createsend/api');
63
+
64
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
65
+ $scopeModel = Mage::getModel('createsend/config_scope');
66
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
67
+
68
+ /** @var array $params */
69
+ $params = array(
70
+ 'clientID' => $helper->getClientId($storeId),
71
+ 'count' => self::MAX_EMAIL_PER_REQUEST,
72
+ );
73
+
74
+ // Get last message id for this scope/scopeId from the database
75
+ /** @var array $row */
76
+ $row = Mage::getModel('createsend/email')->getCollection()
77
+ ->addFieldToFilter('scope', $scope)
78
+ ->addFieldToFilter('scope_id', $scopeId)
79
+ ->setOrder('sent_at', 'DESC')
80
+ ->setPageSize(1)
81
+ ->getFirstItem();
82
+
83
+ $lastMessageId = null;
84
+ $lastMessageDate = self::DATE_MIN;
85
+ if ($row) {
86
+ $lastMessageId = $row['message_id'];
87
+ $lastMessageDate = $row['sent_at'];
88
+
89
+ $params['sentAfterID'] = $lastMessageId;
90
+ }
91
+
92
+ $loopCount = 0;
93
+ do {
94
+ // Get "Message timeline" from CM
95
+ $result = $api->call(
96
+ Zend_Http_Client::GET,
97
+ "transactional/messages",
98
+ array(),
99
+ $params,
100
+ $scope,
101
+ $scopeId
102
+ );
103
+
104
+ $count = 0;
105
+ if ($result['success'] !== false) {
106
+ foreach ($result['data'] as $message) {
107
+ $count++;
108
+
109
+ /** @var Campaignmonitor_Createsend_Model_Email $email */
110
+ $email = Mage::getModel('createsend/email');
111
+ $email->setMessageId($message['MessageID']);
112
+ $email->setStatus($message['Status']);
113
+ $email->setSentAt($message['SentAt']);
114
+ $email->setRecipient(iconv_mime_decode($message['Recipient']));
115
+ $email->setSender($message['From']);
116
+ $email->setSubject(iconv_mime_decode($message['Subject']));
117
+ $email->setTotalOpens($message['TotalOpens']);
118
+ $email->setTotalClicks($message['TotalClicks']);
119
+ $email->setCanBeResent($message['CanBeResent']);
120
+ $email->setScope($scope);
121
+ $email->setScopeId($scopeId);
122
+ $email->save();
123
+
124
+ // Compare dates, don't assume message dates are in order
125
+ if ($message['SentAt'] >= $lastMessageDate) {
126
+ $lastMessageId = $message['MessageID'];
127
+ $lastMessageDate = $message['SentAt'];
128
+ }
129
+ }
130
+
131
+ $params['sentAfterID'] = $lastMessageId;
132
+ } else {
133
+ $helper->log(sprintf(self::ERR_API_ERROR, var_export($result, true)), Zend_Log::ERR);
134
+ }
135
+
136
+ } while (($count >= self::MAX_EMAIL_PER_REQUEST) && (++$loopCount < self::MAX_REQUEST_LOOPS));
137
+ }
138
+
139
+ /**
140
+ * Deletes all email with sent_at earlier than the email retention days configuration
141
+ * for the given scope/scopeId.
142
+ *
143
+ * @param string $listId Unused in this function because List ID is not required for sending transactional emails
144
+ * @param string $scope The configuration Scope for which to perform this action
145
+ * @param int $scopeId The configuration Scope ID for which to perform this action
146
+ */
147
+ protected function _performEmailTableMaintenance($listId, $scope, $scopeId)
148
+ {
149
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
150
+ $helper = Mage::helper('createsend');
151
+
152
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
153
+ $scopeModel = Mage::getModel('createsend/config_scope');
154
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
155
+
156
+ $retentionDays = $helper->getEmailRetentionDays($storeId);
157
+
158
+ $daysAgo = Mage::getModel('core/date')->timestamp(strtotime(sprintf('%d days ago', $retentionDays)));
159
+ $daysAgoStr = date('Y-m-d', $daysAgo);
160
+
161
+ $helper->log(
162
+ sprintf(self::LOG_DELETING_EMAILS, $daysAgoStr, $scope, $scopeId),
163
+ Zend_Log::DEBUG
164
+ );
165
+
166
+ /** @var Varien_Data_Collection_Db $collection */
167
+ $collection = Mage::getModel('createsend/email')->getCollection()
168
+ ->addFieldToFilter('scope', $scope)
169
+ ->addFieldToFilter('scope_id', $scopeId)
170
+ ->addFieldToFilter('sent_at', array('lt' => $daysAgoStr))
171
+ ->load();
172
+
173
+ $count = 0;
174
+ /** @var Campaignmonitor_Createsend_Model_Email $email */
175
+ foreach ($collection as $email) {
176
+ $email->delete();
177
+ $count++;
178
+ }
179
+
180
+ $helper->log(sprintf(self::LOG_ROWS_DELETED, $count), Zend_Log::DEBUG);
181
+ }
182
+ }
app/code/community/Campaignmonitor/Createsend/Model/Email/Template.php CHANGED
@@ -1,215 +1,215 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Email_Template extends Mage_Core_Model_Email_Template
19
- {
20
- const ERR_CANNOT_SEND_EMAIL = 'Cannot send email via Campaign Monitor Transactional API: %s';
21
-
22
- /**
23
- * Overrides the Mage_Core_Model_Email_Template send() method to send email via Campaign Monitor Transactional API.
24
- * Some of the code are from the original parent send() method. Unused code from the original method are
25
- * commented out for reference.
26
- *
27
- * @param array|string $email E-mail(s)
28
- * @param array|string|null $name receiver name(s)
29
- * @param array $variables Template variables
30
- * @return bool
31
- * @throws Exception when the letter cannot be sent because it it not valid
32
- */
33
- public function send($email, $name = null, array $variables = array())
34
- {
35
-
36
-
37
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
38
- $helper = Mage::helper("createsend");
39
-
40
- $storeId = Mage::app()->getStore()->getStoreId();
41
-
42
- // Only send emails through Campaign Monitor is the admin has selected to do so
43
- $transactionalEmailEnabled = $helper->isTransactionalEmailsEnabled($storeId);
44
- if ($transactionalEmailEnabled == false) {
45
- return parent::send($email, $name, $variables);
46
- }
47
-
48
- if (!$this->isValidForSend()) {
49
- Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
50
- return false;
51
- }
52
-
53
- $emails = array_values((array) $email);
54
- $names = is_array($name) ? $name : (array)$name;
55
- $names = array_values($names);
56
- foreach ($emails as $key => $email) {
57
- if (!isset($names[$key])) {
58
- $names[$key] = substr($email, 0, strpos($email, '@'));
59
- }
60
- }
61
-
62
- $variables['email'] = reset($emails);
63
- $variables['name'] = reset($names);
64
-
65
- // TODO: Partition into logical groups such as "Orders", "Shipments"
66
- $group = 'Magento';
67
-
68
- $emailData = array(
69
- 'Subject' => null,
70
- 'From' => null,
71
- 'ReplyTo' => null,
72
- 'To' => null,
73
- 'CC' => null,
74
- 'BCC' => $this->_bccEmails,
75
- 'Html' => '',
76
- 'Text' => '',
77
- 'Attachments' => null,
78
- 'TrackOpens' => true,
79
- 'TrackClicks' => true,
80
- 'InlineCSS' => true,
81
- 'Group' => $group // Used for grouping email for reporting
82
- );
83
-
84
- $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
85
- switch ($setReturnPath) {
86
- case 1:
87
- $returnPathEmail = $this->getSenderEmail();
88
- break;
89
- case 2:
90
- $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
91
- break;
92
- default:
93
- $returnPathEmail = null;
94
- break;
95
- }
96
-
97
- if ($returnPathEmail !== null) {
98
- $emailData['ReplyTo'] = $returnPathEmail;
99
- }
100
-
101
- $recipients = array();
102
- foreach ($emails as $key => $email) {
103
- $recipients[] = $names[$key] . '<' . $email . '>';
104
- }
105
-
106
- $emailData['To'] = $recipients;
107
-
108
- $this->setUseAbsoluteLinks(true);
109
- $text = $this->getProcessedTemplate($variables, true);
110
-
111
- if ($this->isPlain()) {
112
- $emailData['Text'] = $text;
113
- } else {
114
- $emailData['Html'] = $text;
115
- }
116
-
117
- $emailData['Subject'] = $this->getProcessedTemplateSubject($variables);
118
- $emailData['From'] = '"' . $this->getSenderName() . '" <' . $this->getSenderEmail() .'>';
119
-
120
- try {
121
- $this->_send($emailData, $variables);
122
- $this->_mail = null;
123
- } catch (Exception $e) {
124
-
125
-
126
- return parent::send($email, $name, $variables);
127
- }
128
-
129
- return true;
130
- }
131
-
132
- /**
133
- * Sends a 'classic email' using the Campaign Monitor Transactional Email API.
134
- *
135
- * @link https://www.campaignmonitor.com/api/transactional/#send_a_basic_email
136
- *
137
- * Expects an array of the form:
138
- * <pre>
139
- * {
140
- * "Subject": "Thanks for signing up to web app 123",
141
- * "From": "Mike Smith <mike@webapp123.com>",
142
- * "ReplyTo": "support@webapp123.com",
143
- * "To": [
144
- * "Joe Smith <joesmith@example.com>",
145
- * "jamesmith@example.com"
146
- * ],
147
- * "CC": [
148
- * "Joe Smith <joesmith@example.com>"
149
- * ],
150
- * "BCC": null,
151
- * "Html": "",
152
- * "Text": "",
153
- * "Attachments": [
154
- * {
155
- * "Type": "application/pdf",
156
- * "Name": "Invoice.pdf",
157
- * "Content": "base64encoded"
158
- * }
159
- * ],
160
- * "TrackOpens": true,
161
- * "TrackClicks": true,
162
- * "InlineCSS": true,
163
- * "Group": "Password Reset",
164
- * "AddRecipientsToListID": "62eaaa0338245ca68e5e93daa6f591e9"
165
- * }
166
- * </pre>
167
- *
168
- * @param array $emailData Data to send
169
- * @param array $variables Template variables
170
- * @throws Exception
171
- */
172
- protected function _send(array $emailData, array $variables = array())
173
- {
174
-
175
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
176
- $helper = Mage::helper('createsend');
177
-
178
- /** @var Campaignmonitor_Createsend_Model_Api $api */
179
- $api = Mage::getModel('createsend/api');
180
-
181
- // Use current store's configuration to send the email
182
- $storeId = Mage::app()->getStore()->getStoreId();
183
-
184
- if ($storeId) {
185
- $scope = 'stores';
186
- $scopeId = $storeId;
187
- } else {
188
- $scope = 'default';
189
- $scopeId = 0;
190
- }
191
-
192
- $result = $api->call(
193
- Zend_Http_Client::POST,
194
- 'transactional/classicEmail/send',
195
- $emailData,
196
- array(
197
- 'clientID' => $helper->getClientId($storeId)
198
- ),
199
- $scope,
200
- $scopeId
201
- );
202
-
203
- if (!$result['success']) {
204
- $notice = 'Couldn\'t send email through campaign monitor but your email was sent through magento though';
205
-
206
- if (!empty( $result['data'] )) {
207
- $notice .= ' ';
208
- $notice .= $result['data']['Message'];
209
- }
210
- Mage::getSingleton('core/session')->addNotice($notice);
211
- // throw new Exception($result['data']['Message']);
212
-
213
- }
214
- }
215
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Email_Template extends Mage_Core_Model_Email_Template
19
+ {
20
+ const ERR_CANNOT_SEND_EMAIL = 'Cannot send email via Campaign Monitor Transactional API: %s';
21
+
22
+ /**
23
+ * Overrides the Mage_Core_Model_Email_Template send() method to send email via Campaign Monitor Transactional API.
24
+ * Some of the code are from the original parent send() method. Unused code from the original method are
25
+ * commented out for reference.
26
+ *
27
+ * @param array|string $email E-mail(s)
28
+ * @param array|string|null $name receiver name(s)
29
+ * @param array $variables Template variables
30
+ * @return bool
31
+ * @throws Exception when the letter cannot be sent because it it not valid
32
+ */
33
+ public function send($email, $name = null, array $variables = array())
34
+ {
35
+
36
+
37
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
38
+ $helper = Mage::helper("createsend");
39
+
40
+ $storeId = Mage::app()->getStore()->getStoreId();
41
+
42
+ // Only send emails through Campaign Monitor is the admin has selected to do so
43
+ $transactionalEmailEnabled = $helper->isTransactionalEmailsEnabled($storeId);
44
+ if ($transactionalEmailEnabled == false) {
45
+ return parent::send($email, $name, $variables);
46
+ }
47
+
48
+ if (!$this->isValidForSend()) {
49
+ Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
50
+ return false;
51
+ }
52
+
53
+ $emails = array_values((array) $email);
54
+ $names = is_array($name) ? $name : (array)$name;
55
+ $names = array_values($names);
56
+ foreach ($emails as $key => $email) {
57
+ if (!isset($names[$key])) {
58
+ $names[$key] = substr($email, 0, strpos($email, '@'));
59
+ }
60
+ }
61
+
62
+ $variables['email'] = reset($emails);
63
+ $variables['name'] = reset($names);
64
+
65
+ // TODO: Partition into logical groups such as "Orders", "Shipments"
66
+ $group = 'Magento';
67
+
68
+ $emailData = array(
69
+ 'Subject' => null,
70
+ 'From' => null,
71
+ 'ReplyTo' => null,
72
+ 'To' => null,
73
+ 'CC' => null,
74
+ 'BCC' => $this->_bccEmails,
75
+ 'Html' => '',
76
+ 'Text' => '',
77
+ 'Attachments' => null,
78
+ 'TrackOpens' => true,
79
+ 'TrackClicks' => true,
80
+ 'InlineCSS' => true,
81
+ 'Group' => $group // Used for grouping email for reporting
82
+ );
83
+
84
+ $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
85
+ switch ($setReturnPath) {
86
+ case 1:
87
+ $returnPathEmail = $this->getSenderEmail();
88
+ break;
89
+ case 2:
90
+ $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
91
+ break;
92
+ default:
93
+ $returnPathEmail = null;
94
+ break;
95
+ }
96
+
97
+ if ($returnPathEmail !== null) {
98
+ $emailData['ReplyTo'] = $returnPathEmail;
99
+ }
100
+
101
+ $recipients = array();
102
+ foreach ($emails as $key => $email) {
103
+ $recipients[] = $names[$key] . '<' . $email . '>';
104
+ }
105
+
106
+ $emailData['To'] = $recipients;
107
+
108
+ $this->setUseAbsoluteLinks(true);
109
+ $text = $this->getProcessedTemplate($variables, true);
110
+
111
+ if ($this->isPlain()) {
112
+ $emailData['Text'] = $text;
113
+ } else {
114
+ $emailData['Html'] = $text;
115
+ }
116
+
117
+ $emailData['Subject'] = $this->getProcessedTemplateSubject($variables);
118
+ $emailData['From'] = '"' . $this->getSenderName() . '" <' . $this->getSenderEmail() .'>';
119
+
120
+ try {
121
+ $this->_send($emailData, $variables);
122
+ $this->_mail = null;
123
+ } catch (Exception $e) {
124
+
125
+
126
+ return parent::send($email, $name, $variables);
127
+ }
128
+
129
+ return true;
130
+ }
131
+
132
+ /**
133
+ * Sends a 'classic email' using the Campaign Monitor Transactional Email API.
134
+ *
135
+ * @link https://www.campaignmonitor.com/api/transactional/#send_a_basic_email
136
+ *
137
+ * Expects an array of the form:
138
+ * <pre>
139
+ * {
140
+ * "Subject": "Thanks for signing up to web app 123",
141
+ * "From": "Mike Smith <mike@webapp123.com>",
142
+ * "ReplyTo": "support@webapp123.com",
143
+ * "To": [
144
+ * "Joe Smith <joesmith@example.com>",
145
+ * "jamesmith@example.com"
146
+ * ],
147
+ * "CC": [
148
+ * "Joe Smith <joesmith@example.com>"
149
+ * ],
150
+ * "BCC": null,
151
+ * "Html": "",
152
+ * "Text": "",
153
+ * "Attachments": [
154
+ * {
155
+ * "Type": "application/pdf",
156
+ * "Name": "Invoice.pdf",
157
+ * "Content": "base64encoded"
158
+ * }
159
+ * ],
160
+ * "TrackOpens": true,
161
+ * "TrackClicks": true,
162
+ * "InlineCSS": true,
163
+ * "Group": "Password Reset",
164
+ * "AddRecipientsToListID": "62eaaa0338245ca68e5e93daa6f591e9"
165
+ * }
166
+ * </pre>
167
+ *
168
+ * @param array $emailData Data to send
169
+ * @param array $variables Template variables
170
+ * @throws Exception
171
+ */
172
+ protected function _send(array $emailData, array $variables = array())
173
+ {
174
+
175
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
176
+ $helper = Mage::helper('createsend');
177
+
178
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
179
+ $api = Mage::getModel('createsend/api');
180
+
181
+ // Use current store's configuration to send the email
182
+ $storeId = Mage::app()->getStore()->getStoreId();
183
+
184
+ if ($storeId) {
185
+ $scope = 'stores';
186
+ $scopeId = $storeId;
187
+ } else {
188
+ $scope = 'default';
189
+ $scopeId = 0;
190
+ }
191
+
192
+ $result = $api->call(
193
+ Zend_Http_Client::POST,
194
+ 'transactional/classicEmail/send',
195
+ $emailData,
196
+ array(
197
+ 'clientID' => $helper->getClientId($storeId)
198
+ ),
199
+ $scope,
200
+ $scopeId
201
+ );
202
+
203
+ if (!$result['success']) {
204
+ $notice = 'Couldn\'t send email through campaign monitor but your email was sent through magento though';
205
+
206
+ if (!empty( $result['data'] )) {
207
+ $notice .= ' ';
208
+ $notice .= $result['data']['Message'];
209
+ }
210
+ Mage::getSingleton('core/session')->addNotice($notice);
211
+ // throw new Exception($result['data']['Message']);
212
+
213
+ }
214
+ }
215
+ }
app/code/community/Campaignmonitor/Createsend/Model/List/Cron.php CHANGED
@@ -1,276 +1,293 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_List_Cron extends Campaignmonitor_Createsend_Model_Cron
19
- {
20
- const SYNC_INCLUSION_PERIOD = 'yesterday'; // Relative date/time format
21
- const ERR_API_ERROR = 'API Error: %s';
22
-
23
- /**
24
- * Performs list subscribers synchronisation for all scopes w/ non-inherited List ID
25
- */
26
- public function runJob()
27
- {
28
- $this->iterateScopes(
29
- Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID,
30
- 'isSubscriberSynchronisationEnabled',
31
- array(
32
- array(
33
- 'class' => $this,
34
- 'method' => '_synchroniseFromCm',
35
- ),
36
- )
37
- );
38
-
39
- $this->synchroniseFromMagento();
40
- }
41
-
42
- /**
43
- * Synchronises list subscribers using Campaign Monitor subscribers as base list.
44
- *
45
- * @link https://www.campaignmonitor.com/api/lists/#active_subscribers
46
- *
47
- * @param string $listId The ID of the Campaign Monitor list to synchronise
48
- * @param string $scope
49
- * @param int $scopeId
50
- */
51
- public function _synchroniseFromCm($listId, $scope, $scopeId)
52
- {
53
- $dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime(self::SYNC_INCLUSION_PERIOD));
54
- $yesterday = date('Y-m-d', $dateTimestamp);
55
-
56
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
57
- $helper = Mage::helper('createsend');
58
-
59
- /** @var Campaignmonitor_Createsend_Model_Api $api */
60
- $api = Mage::getSingleton('createsend/api');
61
-
62
- // Get List of Active Subscribers
63
- $result = $api->call(
64
- Zend_Http_Client::GET,
65
- "lists/{$listId}/active",
66
- array(),
67
- array('date' => $yesterday),
68
- $scope,
69
- $scopeId
70
- );
71
-
72
- if ($result['success'] !== false) {
73
- foreach ($result['data']['Results'] as $subscriber) {
74
- $email = $subscriber['EmailAddress'];
75
-
76
- /** @var Mage_Newsletter_Model_Subscriber $mageNewsletter */
77
- $mageNewsletter = Mage::getModel('newsletter/subscriber');
78
- $mageNewsletter->loadByEmail($email);
79
-
80
- if (!$mageNewsletter->isSubscribed() || $mageNewsletter->getId() === null) {
81
- $mageTimestamp = null;
82
- if ($mageNewsletter->getId() !== null) {
83
- $mageTime = Mage::getModel('core/date')->timestamp($mageNewsletter->getChangeStatusAt());
84
- $mageTimestamp = date('Y-m-d H:i:s', $mageTime);
85
- }
86
-
87
- // CM in local time
88
- $cmTimestamp = null;
89
- if (isset($subscriber['Date'])) {
90
- $cmTimestamp = $subscriber['Date'];
91
- }
92
-
93
- $this->_applyResolutionMethod(
94
- Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_CAMPAIGN_MONITOR,
95
- $email, $mageTimestamp, $cmTimestamp, $scope, $scopeId
96
- );
97
- }
98
- }
99
- } else {
100
- $helper->log(sprintf(self::ERR_API_ERROR, $result['data']['Message']), Zend_Log::ERR);
101
- }
102
- }
103
-
104
- /**
105
- * Synchronises list subscribers using Magento subscribers from all stores as the base list.
106
- *
107
- */
108
- public function synchroniseFromMagento()
109
- {
110
- $stores = Mage::app()->getStores(true);
111
- foreach ($stores as $storeId => $store) {
112
- $this->_synchroniseFromMagento($storeId);
113
- }
114
- }
115
-
116
- /**
117
- * Synchronises list subscribers using Magento newsletter subscribers from the particular store as the base list.
118
- *
119
- * @param int $storeId
120
- */
121
- public function _synchroniseFromMagento($storeId)
122
- {
123
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
124
- $helper = Mage::helper('createsend');
125
-
126
- $listId = $helper->getListId($storeId);
127
- $scope = 'stores';
128
- $scopeId = $storeId;
129
-
130
- /* @var Mage_Newsletter_Model_Subscriber $subscribers */
131
- $mageNewsletter = Mage::getModel('newsletter/subscriber');
132
-
133
- $collection = $mageNewsletter->getCollection()
134
- ->addFieldToFilter('store_id', $storeId)
135
- ->addFieldToFilter('subscriber_status', Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
136
-
137
- foreach ($collection as $subscriber) {
138
- $email = $subscriber->getEmail();
139
-
140
- /** @var Campaignmonitor_Createsend_Model_Api $api */
141
- $api = Mage::getSingleton('createsend/api');
142
-
143
- // Check CM subscriber status
144
- $result = $api->call(
145
- Zend_Http_Client::GET,
146
- "subscribers/{$listId}",
147
- array(),
148
- array('email' => $email),
149
- $scope,
150
- $scopeId
151
- );
152
-
153
-
154
-
155
- if ($result['success'] || (isset($result['data']['Code'] ) && $result['data']['Code'] == $api::CODE_SUBSCRIBER_NOT_IN_LIST)) {
156
- if (isset($result['data']['State'])) {
157
- $subscriptionState = $result['data']['State'];
158
- } else {
159
- $subscriptionState = $api::SUBSCRIBER_STATUS_DELETED;
160
- }
161
-
162
- if ($subscriptionState !== $api::SUBSCRIBER_STATUS_ACTIVE) {
163
- // Convert to local time
164
- $mageTime = Mage::getModel('core/date')->timestamp($subscriber->getChangeStatusAt());
165
- $mageTimeStamp = date('Y-m-d H:i:s', $mageTime);
166
-
167
- // CM in local time
168
- $cmTimestamp = null;
169
- if (isset($result['data']['Date'])) {
170
- $cmTimestamp = $result['data']['Date'];
171
- }
172
-
173
- $this->_applyResolutionMethod(
174
- Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_MAGENTO,
175
- $email, $mageTimeStamp, $cmTimestamp, $scope, $scopeId
176
- );
177
- }
178
- }
179
- }
180
- }
181
-
182
- /**
183
- * Performs conflict resolution based on source list and resolution method of scope/scopeId
184
- *
185
- * @param string $source The source where the email address is subscribed
186
- * @param string $email The email address to be subscribed/unsubscribed
187
- * @param string $mageTimestamp Date when magento newsletter subscription was last updated, format: 'Y-m-d H:i:s'
188
- * @param string $cmTimestamp Date when CM list subscription was last updated, format: 'Y-m-d H:i:s'
189
- * @param string $scope
190
- * @param int $scopeId
191
- */
192
- protected function _applyResolutionMethod($source, $email, $mageTimestamp, $cmTimestamp, $scope, $scopeId)
193
- {
194
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
195
- $helper = Mage::helper('createsend');
196
-
197
- $helper->log(
198
- sprintf('RESOLVE (%s): From(%s); Magento(%s); CM(%s)', $email, $source, $mageTimestamp, $cmTimestamp)
199
- );
200
-
201
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
202
- $scopeModel = Mage::getModel('createsend/config_scope');
203
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
204
-
205
- $resolutionMethod = $helper->getSubscriberSynchronisationResolutionMethod($storeId);
206
-
207
- switch ($resolutionMethod) {
208
- case Campaignmonitor_Createsend_Model_Config_ConflictResolutionMethod::RESOLUTION_METHOD_TIMESTAMP:
209
- if ($mageTimestamp === null) {
210
- $this->_preferCM($source, $email, $storeId);
211
- } elseif ($cmTimestamp === null) {
212
- $this->_preferMagento($source, $email, $scope, $scopeId);
213
- } elseif ($mageTimestamp < $cmTimestamp) {
214
- $this->_preferCM($source, $email, $storeId);
215
- } else {
216
- $this->_preferMagento($source, $email, $scope, $scopeId);
217
- }
218
-
219
- break;
220
-
221
- case Campaignmonitor_Createsend_Model_Config_ConflictResolutionMethod::RESOLUTION_METHOD_SOURCE:
222
- $preferredSource = $helper->getSubscriberSynchronisationPreferredSource($storeId);
223
-
224
- switch ($preferredSource) {
225
- case Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_MAGENTO:
226
- $this->_preferMagento($source, $email, $scope, $scopeId);
227
- break;
228
-
229
- case Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_CAMPAIGN_MONITOR:
230
- default: // If not set, use CM as preferred source
231
- $this->_preferCM($source, $email, $storeId);
232
- break;
233
- }
234
- break;
235
- }
236
- }
237
-
238
- /**
239
- * Uses the CM subscription status to update Magento newsletter subscription
240
- *
241
- * @param string $source The source where the email address is subscribed
242
- * @param string $email The email address to be subscribed/unsubscribed
243
- * @param int $storeId Store ID of the Magento newsletter object
244
- */
245
- protected function _preferCM($source, $email, $storeId)
246
- {
247
- /** @var Campaignmonitor_Createsend_Model_Newsletter $newsletter */
248
- $newsletter = Mage::getModel('createsend/newsletter');
249
-
250
- if ($source === Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_CAMPAIGN_MONITOR) {
251
- $newsletter->subscribe($email, $storeId);
252
- } else {
253
- $newsletter->unsubscribe($email);
254
- }
255
- }
256
-
257
- /**
258
- * Uses the Magento newsletter subscription status to update CM subscription
259
- *
260
- * @param string $source The source where the email address is subscribed
261
- * @param string $email The email address to be subscribed/unsubscribed
262
- * @param string $scope
263
- * @param int $scopeId
264
- */
265
- protected function _preferMagento($source, $email, $scope, $scopeId)
266
- {
267
- /** @var Campaignmonitor_Createsend_Model_Api $api */
268
- $api = Mage::getModel('createsend/api');
269
-
270
- if ($source === Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_CAMPAIGN_MONITOR) {
271
- $api->unsubscribe($email, $scope, $scopeId);
272
- } else {
273
- $api->subscribe($email, $scope, $scopeId);
274
- }
275
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_List_Cron extends Campaignmonitor_Createsend_Model_Cron
19
+ {
20
+ const SYNC_INCLUSION_PERIOD = 'yesterday'; // Relative date/time format
21
+ const ERR_API_ERROR = 'API Error: %s';
22
+
23
+ /**
24
+ * Performs list subscribers synchronisation for all scopes w/ non-inherited List ID
25
+ */
26
+ public function runJob()
27
+ {
28
+ $this->iterateScopes(
29
+ Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID,
30
+ 'isSubscriberSynchronisationEnabled',
31
+ array(
32
+ array(
33
+ 'class' => $this,
34
+ 'method' => '_synchroniseFromCm',
35
+ ),
36
+ )
37
+ );
38
+
39
+ $this->synchroniseFromMagento();
40
+ }
41
+
42
+ /**
43
+ * Synchronises list subscribers using Campaign Monitor subscribers as base list.
44
+ *
45
+ * @link https://www.campaignmonitor.com/api/lists/#active_subscribers
46
+ *
47
+ * @param string $listId The ID of the Campaign Monitor list to synchronise
48
+ * @param string $scope
49
+ * @param int $scopeId
50
+ */
51
+ public function _synchroniseFromCm($listId, $scope, $scopeId)
52
+ {
53
+ $dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime(self::SYNC_INCLUSION_PERIOD));
54
+ $yesterday = date('Y-m-d', $dateTimestamp);
55
+
56
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
57
+ $helper = Mage::helper('createsend');
58
+
59
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
60
+ $api = Mage::getSingleton('createsend/api');
61
+
62
+ // Get List of Active Subscribers
63
+ $result = $api->call(
64
+ Zend_Http_Client::GET,
65
+ "lists/{$listId}/active",
66
+ array(),
67
+ array('date' => $yesterday),
68
+ $scope,
69
+ $scopeId
70
+ );
71
+
72
+ if ($result['success'] !== false) {
73
+ foreach ($result['data']['Results'] as $subscriber) {
74
+ $email = $subscriber['EmailAddress'];
75
+
76
+ /** @var Mage_Newsletter_Model_Subscriber $mageNewsletter */
77
+ $mageNewsletter = Mage::getModel('newsletter/subscriber');
78
+ $mageNewsletter->loadByEmail($email);
79
+
80
+ if (!$mageNewsletter->isSubscribed() || $mageNewsletter->getId() === null) {
81
+ $mageTimestamp = null;
82
+ if ($mageNewsletter->getId() !== null) {
83
+ $mageTime = Mage::getModel('core/date')->timestamp($mageNewsletter->getChangeStatusAt());
84
+ $mageTimestamp = date('Y-m-d H:i:s', $mageTime);
85
+ }
86
+
87
+ // CM in local time
88
+ $cmTimestamp = null;
89
+ if (isset($subscriber['Date'])) {
90
+ $cmTimestamp = $subscriber['Date'];
91
+ }
92
+
93
+ $this->_applyResolutionMethod(
94
+ Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_CAMPAIGN_MONITOR,
95
+ $email, $mageTimestamp, $cmTimestamp, $scope, $scopeId
96
+ );
97
+ }
98
+ }
99
+ } else {
100
+ $helper->log(sprintf(self::ERR_API_ERROR, $result['data']['Message']), Zend_Log::ERR);
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Synchronises list subscribers using Magento subscribers from all stores as the base list.
106
+ *
107
+ */
108
+ public function synchroniseFromMagento()
109
+ {
110
+ $stores = Mage::app()->getStores(true);
111
+ foreach ($stores as $storeId => $store) {
112
+ // there is no need to sync admin store
113
+ if ($storeId !== 0) {
114
+ $this->_synchroniseFromMagento($storeId);
115
+ }
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Synchronises list subscribers using Magento newsletter subscribers from the particular store as the base list.
121
+ *
122
+ * @param int $storeId
123
+ */
124
+ public function _synchroniseFromMagento($storeId)
125
+ {
126
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
127
+ $helper = Mage::helper('createsend');
128
+
129
+ $listId = $helper->getListId($storeId);
130
+ $scope = 'stores';
131
+ $scopeId = $storeId;
132
+
133
+ /* @var Mage_Newsletter_Model_Subscriber $subscribers */
134
+ $mageNewsletter = Mage::getModel('newsletter/subscriber');
135
+
136
+ $pagedSize = 100;
137
+ $collection = $mageNewsletter->getCollection('subscriber_id')
138
+ ->addFieldToFilter( 'store_id', $storeId )
139
+ ->addFieldToFilter( 'subscriber_status', Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED );
140
+ $collection->setPageSize($pagedSize);
141
+ $collection->setCurPage(1);
142
+ $lastPage = $collection->getLastPageNumber();
143
+
144
+ if (!empty($collection) && $collection->count() > 0) {
145
+
146
+ for ($i = 1; $i <= $lastPage; $i++) {
147
+
148
+ $collection = $mageNewsletter->getCollection()
149
+ ->addFieldToFilter( 'store_id', $storeId )
150
+ ->addFieldToFilter( 'subscriber_status', Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED );
151
+ $collection->setPageSize($pagedSize);
152
+ $collection->setCurPage($i);
153
+
154
+ foreach ($collection as $subscriber) {
155
+ $email = $subscriber->getEmail();
156
+
157
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
158
+ $api = Mage::getSingleton('createsend/api');
159
+
160
+ // Check CM subscriber status
161
+ $result = $api->call(
162
+ Zend_Http_Client::GET,
163
+ "subscribers/{$listId}",
164
+ array(),
165
+ array('email' => $email),
166
+ $scope,
167
+ $scopeId
168
+ );
169
+
170
+ if ($result['success'] || (isset($result['data']['Code'] ) && $result['data']['Code'] == $api::CODE_SUBSCRIBER_NOT_IN_LIST)) {
171
+ if (isset($result['data']['State'])) {
172
+ $subscriptionState = $result['data']['State'];
173
+ } else {
174
+ $subscriptionState = $api::SUBSCRIBER_STATUS_DELETED;
175
+ }
176
+
177
+ if ($subscriptionState !== $api::SUBSCRIBER_STATUS_ACTIVE) {
178
+ // Convert to local time
179
+ $mageTime = Mage::getModel('core/date')->timestamp($subscriber->getChangeStatusAt());
180
+ $mageTimeStamp = date('Y-m-d H:i:s', $mageTime);
181
+
182
+ // CM in local time
183
+ $cmTimestamp = null;
184
+ if (isset($result['data']['Date'])) {
185
+ $cmTimestamp = $result['data']['Date'];
186
+ }
187
+
188
+ $this->_applyResolutionMethod(
189
+ Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_MAGENTO,
190
+ $email, $mageTimeStamp, $cmTimestamp, $scope, $scopeId
191
+ );
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Performs conflict resolution based on source list and resolution method of scope/scopeId
201
+ *
202
+ * @param string $source The source where the email address is subscribed
203
+ * @param string $email The email address to be subscribed/unsubscribed
204
+ * @param string $mageTimestamp Date when magento newsletter subscription was last updated, format: 'Y-m-d H:i:s'
205
+ * @param string $cmTimestamp Date when CM list subscription was last updated, format: 'Y-m-d H:i:s'
206
+ * @param string $scope
207
+ * @param int $scopeId
208
+ */
209
+ protected function _applyResolutionMethod($source, $email, $mageTimestamp, $cmTimestamp, $scope, $scopeId)
210
+ {
211
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
212
+ $helper = Mage::helper('createsend');
213
+
214
+ $helper->log(
215
+ sprintf('RESOLVE (%s): From(%s); Magento(%s); CM(%s)', $email, $source, $mageTimestamp, $cmTimestamp)
216
+ );
217
+
218
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
219
+ $scopeModel = Mage::getModel('createsend/config_scope');
220
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
221
+
222
+ $resolutionMethod = $helper->getSubscriberSynchronisationResolutionMethod($storeId);
223
+
224
+ switch ($resolutionMethod) {
225
+ case Campaignmonitor_Createsend_Model_Config_ConflictResolutionMethod::RESOLUTION_METHOD_TIMESTAMP:
226
+ if ($mageTimestamp === null) {
227
+ $this->_preferCM($source, $email, $storeId);
228
+ } elseif ($cmTimestamp === null) {
229
+ $this->_preferMagento($source, $email, $scope, $scopeId);
230
+ } elseif ($mageTimestamp < $cmTimestamp) {
231
+ $this->_preferCM($source, $email, $storeId);
232
+ } else {
233
+ $this->_preferMagento($source, $email, $scope, $scopeId);
234
+ }
235
+
236
+ break;
237
+
238
+ case Campaignmonitor_Createsend_Model_Config_ConflictResolutionMethod::RESOLUTION_METHOD_SOURCE:
239
+ $preferredSource = $helper->getSubscriberSynchronisationPreferredSource($storeId);
240
+
241
+ switch ($preferredSource) {
242
+ case Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_MAGENTO:
243
+ $this->_preferMagento($source, $email, $scope, $scopeId);
244
+ break;
245
+
246
+ case Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_CAMPAIGN_MONITOR:
247
+ default: // If not set, use CM as preferred source
248
+ $this->_preferCM($source, $email, $storeId);
249
+ break;
250
+ }
251
+ break;
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Uses the CM subscription status to update Magento newsletter subscription
257
+ *
258
+ * @param string $source The source where the email address is subscribed
259
+ * @param string $email The email address to be subscribed/unsubscribed
260
+ * @param int $storeId Store ID of the Magento newsletter object
261
+ */
262
+ protected function _preferCM($source, $email, $storeId)
263
+ {
264
+ /** @var Campaignmonitor_Createsend_Model_Newsletter $newsletter */
265
+ $newsletter = Mage::getModel('createsend/newsletter');
266
+
267
+ if ($source === Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_CAMPAIGN_MONITOR) {
268
+ $newsletter->subscribe($email, $storeId);
269
+ } else {
270
+ $newsletter->unsubscribe($email);
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Uses the Magento newsletter subscription status to update CM subscription
276
+ *
277
+ * @param string $source The source where the email address is subscribed
278
+ * @param string $email The email address to be subscribed/unsubscribed
279
+ * @param string $scope
280
+ * @param int $scopeId
281
+ */
282
+ protected function _preferMagento($source, $email, $scope, $scopeId)
283
+ {
284
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
285
+ $api = Mage::getModel('createsend/api');
286
+
287
+ if ($source === Campaignmonitor_Createsend_Model_Config_SubscriptionSources::SOURCE_CAMPAIGN_MONITOR) {
288
+ $api->unsubscribe($email, $scope, $scopeId);
289
+ } else {
290
+ $api->subscribe($email, $scope, $scopeId);
291
+ }
292
+ }
293
  }
app/code/community/Campaignmonitor/Createsend/Model/List/Initial/Cron.php CHANGED
@@ -1,119 +1,119 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_List_Initial_Cron extends Campaignmonitor_Createsend_Model_Cron
19
- {
20
- const PROCESS_ID = 'list_initial_cron';
21
-
22
- /**
23
- * Performs list subscribers synchronisation for all scopes w/ non-inherited List ID
24
- */
25
- public function runJob()
26
- {
27
- $this->_fullSync();
28
- }
29
-
30
- /**
31
- * Synchronises list subscribers from Magento to Campaign Monitor
32
- *
33
- */
34
- public function _fullSync()
35
- {
36
- $flagClass = 'createsend/config_listFlag';
37
-
38
-
39
-
40
- /** @var Campaignmonitor_Createsend_Helper_Config $configHelper */
41
- $configHelper = Mage::helper('createsend/config');
42
-
43
- /** @var array $processData */
44
- $processData = $configHelper->getFlagData($flagClass, self::PROCESS_ID);
45
-
46
- if (!is_array($processData)) {
47
- $processData = array(
48
- 'status' => $configHelper::FLAG_PROCESS_STOPPED,
49
- 'start' => null,
50
- 'end' => null,
51
- );
52
- }
53
-
54
-
55
- // Check for stale process
56
- if ($processData['status'] === $configHelper::FLAG_PROCESS_RUNNING) {
57
- $startDate = new DateTime($processData['start']);
58
- $now = new DateTime('now');
59
- $dateDiff = $startDate->diff($now);
60
-
61
- if ($dateDiff->days < 1) {
62
- // running less than one day, not yet stale
63
- return;
64
- }
65
-
66
- // If this stage is reached, process is considered stale.
67
- // Continue processing
68
- }
69
-
70
- // Set and save the flag so that this process does not run more than once
71
- $processData['status'] = $configHelper::FLAG_PROCESS_RUNNING;
72
- $processData['start'] = date('Y-m-d H:i:s');
73
- $configHelper->addFlagData($flagClass, self::PROCESS_ID, $processData);
74
-
75
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
76
- $helper = Mage::helper('createsend');
77
-
78
- /** @var Campaignmonitor_Createsend_Helper_Api $apiHelper */
79
- $apiHelper = Mage::helper('createsend/api');
80
-
81
- $updatedLists = array();
82
-
83
- $stores = Mage::app()->getStores(true);
84
- foreach ($stores as $storeId => $store) {
85
- $listId = $helper->getListId($storeId);
86
-
87
- if (!$listId) {
88
- // Don't have a list to use
89
- continue;
90
- }
91
-
92
- $flagData = $configHelper->getFlagData($flagClass, $listId);
93
-
94
- if (!$flagData) {
95
- // No list data has been saved yet
96
- continue;
97
- }
98
-
99
- if (isset($flagData[$configHelper::INDEX_INITIAL_SYNC]) &&
100
- $flagData[$configHelper::INDEX_INITIAL_SYNC] === $configHelper::FLAG_STATUS_NEW) {
101
- // We have initial sync info and it's in the appropriate state so run the full sync
102
- $apiHelper->performFullSync($storeId);
103
-
104
- $updatedLists[$listId] = true;
105
- }
106
- }
107
-
108
- foreach (array_keys($updatedLists) as $listId) {
109
- // Set flag status to 'done' for all synchronized lists
110
- $listFlagData[$configHelper::INDEX_INITIAL_SYNC] = $configHelper::FLAG_STATUS_DONE;
111
- $configHelper->addFlagData($flagClass, $listId, $listFlagData);
112
- }
113
-
114
- // Done processing, update flag for this process
115
- $processData['status'] = $configHelper::FLAG_PROCESS_STOPPED;
116
- $processData['end'] = date('Y-m-d H:i:s');
117
- $configHelper->addFlagData($flagClass, self::PROCESS_ID, $processData);
118
- }
119
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_List_Initial_Cron extends Campaignmonitor_Createsend_Model_Cron
19
+ {
20
+ const PROCESS_ID = 'list_initial_cron';
21
+
22
+ /**
23
+ * Performs list subscribers synchronisation for all scopes w/ non-inherited List ID
24
+ */
25
+ public function runJob()
26
+ {
27
+ $this->_fullSync();
28
+ }
29
+
30
+ /**
31
+ * Synchronises list subscribers from Magento to Campaign Monitor
32
+ *
33
+ */
34
+ public function _fullSync()
35
+ {
36
+ $flagClass = 'createsend/config_listFlag';
37
+
38
+
39
+
40
+ /** @var Campaignmonitor_Createsend_Helper_Config $configHelper */
41
+ $configHelper = Mage::helper('createsend/config');
42
+
43
+ /** @var array $processData */
44
+ $processData = $configHelper->getFlagData($flagClass, self::PROCESS_ID);
45
+
46
+ if (!is_array($processData)) {
47
+ $processData = array(
48
+ 'status' => $configHelper::FLAG_PROCESS_STOPPED,
49
+ 'start' => null,
50
+ 'end' => null,
51
+ );
52
+ }
53
+
54
+
55
+ // Check for stale process
56
+ if ($processData['status'] === $configHelper::FLAG_PROCESS_RUNNING) {
57
+ $startDate = new DateTime($processData['start']);
58
+ $now = new DateTime('now');
59
+ $dateDiff = $startDate->diff($now);
60
+
61
+ if ($dateDiff->days < 1) {
62
+ // running less than one day, not yet stale
63
+ return;
64
+ }
65
+
66
+ // If this stage is reached, process is considered stale.
67
+ // Continue processing
68
+ }
69
+
70
+ // Set and save the flag so that this process does not run more than once
71
+ $processData['status'] = $configHelper::FLAG_PROCESS_RUNNING;
72
+ $processData['start'] = date('Y-m-d H:i:s');
73
+ $configHelper->addFlagData($flagClass, self::PROCESS_ID, $processData);
74
+
75
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
76
+ $helper = Mage::helper('createsend');
77
+
78
+ /** @var Campaignmonitor_Createsend_Helper_Api $apiHelper */
79
+ $apiHelper = Mage::helper('createsend/api');
80
+
81
+ $updatedLists = array();
82
+
83
+ $stores = Mage::app()->getStores(true);
84
+ foreach ($stores as $storeId => $store) {
85
+ $listId = $helper->getListId($storeId);
86
+
87
+ if (!$listId) {
88
+ // Don't have a list to use
89
+ continue;
90
+ }
91
+
92
+ $flagData = $configHelper->getFlagData($flagClass, $listId);
93
+
94
+ if (!$flagData) {
95
+ // No list data has been saved yet
96
+ continue;
97
+ }
98
+
99
+ if (isset($flagData[$configHelper::INDEX_INITIAL_SYNC]) &&
100
+ $flagData[$configHelper::INDEX_INITIAL_SYNC] === $configHelper::FLAG_STATUS_NEW) {
101
+ // We have initial sync info and it's in the appropriate state so run the full sync
102
+ $apiHelper->performFullSync($storeId);
103
+
104
+ $updatedLists[$listId] = true;
105
+ }
106
+ }
107
+
108
+ foreach (array_keys($updatedLists) as $listId) {
109
+ // Set flag status to 'done' for all synchronized lists
110
+ $listFlagData[$configHelper::INDEX_INITIAL_SYNC] = $configHelper::FLAG_STATUS_DONE;
111
+ $configHelper->addFlagData($flagClass, $listId, $listFlagData);
112
+ }
113
+
114
+ // Done processing, update flag for this process
115
+ $processData['status'] = $configHelper::FLAG_PROCESS_STOPPED;
116
+ $processData['end'] = date('Y-m-d H:i:s');
117
+ $configHelper->addFlagData($flagClass, self::PROCESS_ID, $processData);
118
+ }
119
+ }
app/code/community/Campaignmonitor/Createsend/Model/Newsletter.php CHANGED
@@ -1,113 +1,113 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Newsletter
19
- {
20
- const ERR_NO_EMAIL_FOUND = 'The email "%s" appears to have no matching entries in Magento';
21
- const ERR_USER_SUBSCRIBED = 'The user "%s" is already subscribed in Magento';
22
- const ERR_USER_UNSUBSCRIBED = 'The user "%s" has already unsubscribed in Magento';
23
-
24
- const LOG_SUBSCRIBED_USER = 'Successfully subscribed customer "%s": %s';
25
- const LOG_UNSUBSCRIBED_USER = 'Successfully unsubscribed customer "%s": %s';
26
-
27
- /**
28
- * Subscribes an email address to the Magento newsletter.
29
- *
30
- * @param string $email The email address to subscribe to the Magento newsletter
31
- * @param int $storeId The store ID to set for the newsletter subscription
32
- * @throws Exception if newsletter object cannot be saved
33
- */
34
- public function subscribe($email, $storeId)
35
- {
36
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
37
- $helper = Mage::helper('createsend');
38
-
39
- /** @var Mage_Newsletter_Model_Subscriber $newsletters */
40
- $newsletters = Mage::getModel('newsletter/subscriber');
41
- $newsletters->loadByEmail($email);
42
-
43
- if ($newsletters->getId() === null) {
44
- // Create new subscriber, without sending confirmation email
45
- Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);
46
- $newsletters->loadByEmail($email);
47
-
48
- $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
49
-
50
- /** @var Mage_Customer_Model_Customer $customer */
51
- $customer = Mage::getModel("customer/customer")
52
- ->setWebsiteId($websiteId)
53
- ->loadByEmail($email);
54
-
55
- if ($customer->getId()) {
56
- $newsletters->setCustomerId($customer->getId());
57
- }
58
-
59
- $newsletters->setStoreId($storeId);
60
-
61
- $newsletters->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
62
- $newsletters->save();
63
-
64
- $helper->log(
65
- sprintf(self::LOG_SUBSCRIBED_USER, $newsletters->getCustomerId(), $newsletters->getEmail()),
66
- Zend_Log::DEBUG
67
- );
68
- } else {
69
- if ($newsletters->isSubscribed() === false) {
70
- $newsletters->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
71
- $newsletters->save();
72
-
73
- $helper->log(
74
- sprintf(self::LOG_SUBSCRIBED_USER, $newsletters->getCustomerId(), $newsletters->getEmail()),
75
- Zend_Log::DEBUG
76
- );
77
- } else {
78
- $helper->log(sprintf(self::ERR_USER_SUBSCRIBED, $email), Zend_Log::WARN);
79
- }
80
- }
81
- }
82
-
83
- /**
84
- * Unsubscribes an email address from the Magento newsletter.
85
- *
86
- * @param string $email The email address to unsubscribe from Magento newsletter
87
- */
88
- public function unsubscribe($email)
89
- {
90
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
91
- $helper = Mage::helper('createsend');
92
-
93
- /** @var Mage_Newsletter_Model_Subscriber $newsletters */
94
- $newsletters = Mage::getModel('newsletter/subscriber');
95
- $newsletters->loadByEmail($email);
96
-
97
- if ($newsletters->getId() === null) {
98
- $helper->log(sprintf(self::ERR_NO_EMAIL_FOUND, $email), Zend_Log::WARN);
99
- return;
100
- }
101
-
102
- if ($newsletters->isSubscribed() === false) {
103
- $helper->log(sprintf(self::ERR_USER_UNSUBSCRIBED, $email), Zend_Log::NOTICE);
104
- return;
105
- }
106
-
107
- $newsletters->setImportMode(true)->unsubscribe();
108
- $helper->log(
109
- sprintf(self::LOG_UNSUBSCRIBED_USER, $newsletters->getCustomerId(), $newsletters->getEmail()),
110
- Zend_Log::DEBUG
111
- );
112
- }
113
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Newsletter
19
+ {
20
+ const ERR_NO_EMAIL_FOUND = 'The email "%s" appears to have no matching entries in Magento';
21
+ const ERR_USER_SUBSCRIBED = 'The user "%s" is already subscribed in Magento';
22
+ const ERR_USER_UNSUBSCRIBED = 'The user "%s" has already unsubscribed in Magento';
23
+
24
+ const LOG_SUBSCRIBED_USER = 'Successfully subscribed customer "%s": %s';
25
+ const LOG_UNSUBSCRIBED_USER = 'Successfully unsubscribed customer "%s": %s';
26
+
27
+ /**
28
+ * Subscribes an email address to the Magento newsletter.
29
+ *
30
+ * @param string $email The email address to subscribe to the Magento newsletter
31
+ * @param int $storeId The store ID to set for the newsletter subscription
32
+ * @throws Exception if newsletter object cannot be saved
33
+ */
34
+ public function subscribe($email, $storeId)
35
+ {
36
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
37
+ $helper = Mage::helper('createsend');
38
+
39
+ /** @var Mage_Newsletter_Model_Subscriber $newsletters */
40
+ $newsletters = Mage::getModel('newsletter/subscriber');
41
+ $newsletters->loadByEmail($email);
42
+
43
+ if ($newsletters->getId() === null) {
44
+ // Create new subscriber, without sending confirmation email
45
+ Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);
46
+ $newsletters->loadByEmail($email);
47
+
48
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
49
+
50
+ /** @var Mage_Customer_Model_Customer $customer */
51
+ $customer = Mage::getModel("customer/customer")
52
+ ->setWebsiteId($websiteId)
53
+ ->loadByEmail($email);
54
+
55
+ if ($customer->getId()) {
56
+ $newsletters->setCustomerId($customer->getId());
57
+ }
58
+
59
+ $newsletters->setStoreId($storeId);
60
+
61
+ $newsletters->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
62
+ $newsletters->save();
63
+
64
+ $helper->log(
65
+ sprintf(self::LOG_SUBSCRIBED_USER, $newsletters->getCustomerId(), $newsletters->getEmail()),
66
+ Zend_Log::DEBUG
67
+ );
68
+ } else {
69
+ if ($newsletters->isSubscribed() === false) {
70
+ $newsletters->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
71
+ $newsletters->save();
72
+
73
+ $helper->log(
74
+ sprintf(self::LOG_SUBSCRIBED_USER, $newsletters->getCustomerId(), $newsletters->getEmail()),
75
+ Zend_Log::DEBUG
76
+ );
77
+ } else {
78
+ $helper->log(sprintf(self::ERR_USER_SUBSCRIBED, $email), Zend_Log::WARN);
79
+ }
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Unsubscribes an email address from the Magento newsletter.
85
+ *
86
+ * @param string $email The email address to unsubscribe from Magento newsletter
87
+ */
88
+ public function unsubscribe($email)
89
+ {
90
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
91
+ $helper = Mage::helper('createsend');
92
+
93
+ /** @var Mage_Newsletter_Model_Subscriber $newsletters */
94
+ $newsletters = Mage::getModel('newsletter/subscriber');
95
+ $newsletters->loadByEmail($email);
96
+
97
+ if ($newsletters->getId() === null) {
98
+ $helper->log(sprintf(self::ERR_NO_EMAIL_FOUND, $email), Zend_Log::WARN);
99
+ return;
100
+ }
101
+
102
+ if ($newsletters->isSubscribed() === false) {
103
+ $helper->log(sprintf(self::ERR_USER_UNSUBSCRIBED, $email), Zend_Log::NOTICE);
104
+ return;
105
+ }
106
+
107
+ $newsletters->setImportMode(true)->unsubscribe();
108
+ $helper->log(
109
+ sprintf(self::LOG_UNSUBSCRIBED_USER, $newsletters->getCustomerId(), $newsletters->getEmail()),
110
+ Zend_Log::DEBUG
111
+ );
112
+ }
113
+ }
app/code/community/Campaignmonitor/Createsend/Model/Newsletter/Observer.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Bug fix for Magento newsletter's change_status_at field non-update bug.
20
- */
21
- class Campaignmonitor_Createsend_Model_Newsletter_Observer
22
- {
23
- /**
24
- * Updates the change_status_at field. Fixes a bug in Magento where the field is not updated
25
- * because the field's auto update "ON UPDATE CURRENT_TIMESTAMP" was omitted in recent versions.
26
- *
27
- * @param Varien_Event_Observer $observer
28
- * @listen newsletter_subscriber_save_before
29
- */
30
- public function setChangeStatusAt(Varien_Event_Observer $observer)
31
- {
32
- $subscriber = $observer->getSubscriber();
33
- $subscriber['change_status_at'] = date("Y-m-d H:i:s", time());
34
- }
35
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Bug fix for Magento newsletter's change_status_at field non-update bug.
20
+ */
21
+ class Campaignmonitor_Createsend_Model_Newsletter_Observer
22
+ {
23
+ /**
24
+ * Updates the change_status_at field. Fixes a bug in Magento where the field is not updated
25
+ * because the field's auto update "ON UPDATE CURRENT_TIMESTAMP" was omitted in recent versions.
26
+ *
27
+ * @param Varien_Event_Observer $observer
28
+ * @listen newsletter_subscriber_save_before
29
+ */
30
+ public function setChangeStatusAt(Varien_Event_Observer $observer)
31
+ {
32
+ $subscriber = $observer->getSubscriber();
33
+ $subscriber['change_status_at'] = date("Y-m-d H:i:s", time());
34
+ }
35
  }
app/code/community/Campaignmonitor/Createsend/Model/Product/Observer.php CHANGED
@@ -1,67 +1,67 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Responsible for updating subscribers' custom field values when a product is changed
20
- */
21
- class Campaignmonitor_Createsend_Model_Product_Observer
22
- {
23
- /**
24
- * Updates the (wishlist) custom fields of a user on campaign monitor based on new product data in Magento
25
- *
26
- * @param Varien_Event_Observer $observer
27
- * @listen catalog_product_save_after
28
- */
29
- public function updateWishlistFields($observer)
30
- {
31
- /** @var Mage_Catalog_Model_Product $product */
32
- $product = $observer->getProduct();
33
-
34
- /** @var Campaignmonitor_Createsend_Model_Api $api */
35
- $api = Mage::getModel('createsend/api');
36
-
37
- // Get all subscribers having the product in their wishlists
38
- $wishlistCollection = Mage::getModel('wishlist/item')
39
- ->getCollection()
40
- ->addFieldToFilter('product_id', $product->getId())
41
- ->addFieldToSelect('wishlist_id')
42
- ->join(
43
- array('wishlist' => 'wishlist/wishlist'),
44
- 'main_table.wishlist_id = wishlist.wishlist_id',
45
- array('customer_id')
46
- );
47
-
48
- foreach ($wishlistCollection as $wishlist) {
49
- $customerId = $wishlist->getCustomerId();
50
-
51
- /** @var Mage_Customer_Model_Customer $customer */
52
- $customer = Mage::getSingleton('customer/customer')->load($customerId);
53
- if ($customer) {
54
- /** @var Mage_Newsletter_Model_Subscriber $newsletter */
55
- $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
56
- $isSubscribed = $subscriber->isSubscribed();
57
-
58
- if ($isSubscribed) {
59
- $scope = 'stores';
60
- $scopeId = $subscriber->getStoreId();
61
-
62
- $api->subscribe($subscriber->getSubscriberEmail(), $scope, $scopeId);
63
- }
64
- }
65
- }
66
- }
67
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Responsible for updating subscribers' custom field values when a product is changed
20
+ */
21
+ class Campaignmonitor_Createsend_Model_Product_Observer
22
+ {
23
+ /**
24
+ * Updates the (wishlist) custom fields of a user on campaign monitor based on new product data in Magento
25
+ *
26
+ * @param Varien_Event_Observer $observer
27
+ * @listen catalog_product_save_after
28
+ */
29
+ public function updateWishlistFields($observer)
30
+ {
31
+ /** @var Mage_Catalog_Model_Product $product */
32
+ $product = $observer->getProduct();
33
+
34
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
35
+ $api = Mage::getModel('createsend/api');
36
+
37
+ // Get all subscribers having the product in their wishlists
38
+ $wishlistCollection = Mage::getModel('wishlist/item')
39
+ ->getCollection()
40
+ ->addFieldToFilter('product_id', $product->getId())
41
+ ->addFieldToSelect('wishlist_id')
42
+ ->join(
43
+ array('wishlist' => 'wishlist/wishlist'),
44
+ 'main_table.wishlist_id = wishlist.wishlist_id',
45
+ array('customer_id')
46
+ );
47
+
48
+ foreach ($wishlistCollection as $wishlist) {
49
+ $customerId = $wishlist->getCustomerId();
50
+
51
+ /** @var Mage_Customer_Model_Customer $customer */
52
+ $customer = Mage::getSingleton('customer/customer')->load($customerId);
53
+ if ($customer) {
54
+ /** @var Mage_Newsletter_Model_Subscriber $newsletter */
55
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
56
+ $isSubscribed = $subscriber->isSubscribed();
57
+
58
+ if ($isSubscribed) {
59
+ $scope = 'stores';
60
+ $scopeId = $subscriber->getStoreId();
61
+
62
+ $api->subscribe($subscriber->getSubscriberEmail(), $scope, $scopeId);
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
app/code/community/Campaignmonitor/Createsend/Model/Resource/Email.php CHANGED
@@ -1,26 +1,26 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Resource_Email extends Mage_Core_Model_Resource_Db_Abstract
19
- {
20
- const PK_FIELD = "email_id";
21
-
22
- protected function _construct()
23
- {
24
- $this->_init('createsend/email', self::PK_FIELD);
25
- }
26
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Resource_Email extends Mage_Core_Model_Resource_Db_Abstract
19
+ {
20
+ const PK_FIELD = "email_id";
21
+
22
+ protected function _construct()
23
+ {
24
+ $this->_init('createsend/email', self::PK_FIELD);
25
+ }
26
  }
app/code/community/Campaignmonitor/Createsend/Model/Resource/Email/Collection.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Model_Resource_Email_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
19
- {
20
- protected function _construct()
21
- {
22
- $this->_init('createsend/email');
23
- }
24
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Model_Resource_Email_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
19
+ {
20
+ protected function _construct()
21
+ {
22
+ $this->_init('createsend/email');
23
+ }
24
  }
app/code/community/Campaignmonitor/Createsend/controllers/Adminhtml/Createsend/ApiController.php CHANGED
@@ -1,146 +1,146 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Adminhtml_Createsend_ApiController extends Mage_Adminhtml_Controller_Action
19
- {
20
- const ADMINHTML_SYSTEM_CONFIG_EDIT = 'adminhtml/system_config/edit';
21
-
22
- const ERR_API_CALL_ERROR = 'API Test Error: %s';
23
- const LOG_API_CALL_SUCCESSFUL = 'API Test Successful.';
24
-
25
- /**
26
- * Performs a test API call.
27
- *
28
- * @link https://www.campaignmonitor.com/api/
29
- *
30
- * @return Mage_Core_Controller_Varien_Action
31
- */
32
- public function testAction()
33
- {
34
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
35
- $helper = Mage::helper("createsend");
36
-
37
- $scope = $this->getRequest()->getQuery('scope');
38
- $scopeId = $this->getRequest()->getQuery('scopeId');
39
-
40
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
41
- $scopeModel = Mage::getModel('createsend/config_scope');
42
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
43
-
44
- /** @var Campaignmonitor_Createsend_Model_Api $api */
45
- $api = Mage::getModel('createsend/api');
46
-
47
- $reply = $api->call(
48
- Zend_Http_Client::GET,
49
- 'lists/' . $helper->getListId($storeId),
50
- array(),
51
- array(),
52
- $scope,
53
- $scopeId
54
- );
55
-
56
- if ($reply['success'] === false) {
57
- $jsonData = json_encode(
58
- array(
59
- 'messages' => array(
60
- array(
61
- 'status' => 'error',
62
- 'message' => sprintf(self::ERR_API_CALL_ERROR, $reply['data']['Message'])
63
- )
64
- )
65
- )
66
- );
67
- } else {
68
- $jsonData = json_encode(
69
- array(
70
- 'messages' => array(
71
- array(
72
- 'status' => 'success',
73
- 'message' => self::LOG_API_CALL_SUCCESSFUL
74
- )
75
- )
76
- )
77
- );
78
- }
79
-
80
- $this->getResponse()->setHeader('Content-type', 'application/json');
81
- $this->getResponse()->setBody($jsonData);
82
- }
83
-
84
-
85
- /**
86
- * Returns a list of Campaign Monitor clients given the API Key.
87
- * Also saves the API Key for the scope.
88
- * If there is only one client, the lists for that client is also queried and returned.
89
- * Prints out the client list in JSON format.
90
- */
91
- public function getClientsAction()
92
- {
93
- $scope = $this->getRequest()->getQuery('scope');
94
- $scopeId = $this->getRequest()->getQuery('scopeId');
95
- $apiKey = $this->getRequest()->getQuery('apiKey');
96
-
97
- Mage::getConfig()->saveConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_API_ID, $apiKey, $scope, $scopeId);
98
-
99
- /** @var $apiHelper Campaignmonitor_Createsend_Helper_Api */
100
- $apiHelper = Mage::helper("createsend/api");
101
-
102
- $clients = $apiHelper->getClients($scope, $scopeId);
103
- if ($clients !== null) {
104
- if (count($clients) == 2) {
105
- // Automatically get the lists if only one client
106
- $clients[1]['lists'] = $apiHelper->getLists($clients[1]['value'], $scope, $scopeId);
107
- }
108
- }
109
-
110
- $jsonData = json_encode(
111
- array (
112
- 'status' => 'success',
113
- 'items' => $clients
114
- )
115
- );
116
-
117
- $this->getResponse()->setHeader('Content-type', 'application/json');
118
- $this->getResponse()->setBody($jsonData);
119
- }
120
-
121
- /**
122
- * Returns the Campaign Monitor subscription lists for the client.
123
- * Prints out the lists in JSON format.
124
- */
125
- public function getListsAction()
126
- {
127
- $scope = $this->getRequest()->getQuery('scope');
128
- $scopeId = $this->getRequest()->getQuery('scopeId');
129
- $clientId = $this->getRequest()->getQuery('clientId');
130
-
131
- /** @var $apiHelper Campaignmonitor_Createsend_Helper_Api */
132
- $apiHelper = Mage::helper("createsend/api");
133
-
134
- $lists = $apiHelper->getLists($clientId, $scope, $scopeId);
135
-
136
- $jsonData = json_encode(
137
- array (
138
- 'status' => 'success',
139
- 'items' => $lists
140
- )
141
- );
142
-
143
- $this->getResponse()->setHeader('Content-type', 'application/json');
144
- $this->getResponse()->setBody($jsonData);
145
- }
146
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Adminhtml_Createsend_ApiController extends Mage_Adminhtml_Controller_Action
19
+ {
20
+ const ADMINHTML_SYSTEM_CONFIG_EDIT = 'adminhtml/system_config/edit';
21
+
22
+ const ERR_API_CALL_ERROR = 'API Test Error: %s';
23
+ const LOG_API_CALL_SUCCESSFUL = 'API Test Successful.';
24
+
25
+ /**
26
+ * Performs a test API call.
27
+ *
28
+ * @link https://www.campaignmonitor.com/api/
29
+ *
30
+ * @return Mage_Core_Controller_Varien_Action
31
+ */
32
+ public function testAction()
33
+ {
34
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
35
+ $helper = Mage::helper("createsend");
36
+
37
+ $scope = $this->getRequest()->getQuery('scope');
38
+ $scopeId = $this->getRequest()->getQuery('scopeId');
39
+
40
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
41
+ $scopeModel = Mage::getModel('createsend/config_scope');
42
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
43
+
44
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
45
+ $api = Mage::getModel('createsend/api');
46
+
47
+ $reply = $api->call(
48
+ Zend_Http_Client::GET,
49
+ 'lists/' . $helper->getListId($storeId),
50
+ array(),
51
+ array(),
52
+ $scope,
53
+ $scopeId
54
+ );
55
+
56
+ if ($reply['success'] === false) {
57
+ $jsonData = json_encode(
58
+ array(
59
+ 'messages' => array(
60
+ array(
61
+ 'status' => 'error',
62
+ 'message' => sprintf(self::ERR_API_CALL_ERROR, $reply['data']['Message'])
63
+ )
64
+ )
65
+ )
66
+ );
67
+ } else {
68
+ $jsonData = json_encode(
69
+ array(
70
+ 'messages' => array(
71
+ array(
72
+ 'status' => 'success',
73
+ 'message' => self::LOG_API_CALL_SUCCESSFUL
74
+ )
75
+ )
76
+ )
77
+ );
78
+ }
79
+
80
+ $this->getResponse()->setHeader('Content-type', 'application/json');
81
+ $this->getResponse()->setBody($jsonData);
82
+ }
83
+
84
+
85
+ /**
86
+ * Returns a list of Campaign Monitor clients given the API Key.
87
+ * Also saves the API Key for the scope.
88
+ * If there is only one client, the lists for that client is also queried and returned.
89
+ * Prints out the client list in JSON format.
90
+ */
91
+ public function getClientsAction()
92
+ {
93
+ $scope = $this->getRequest()->getQuery('scope');
94
+ $scopeId = $this->getRequest()->getQuery('scopeId');
95
+ $apiKey = $this->getRequest()->getQuery('apiKey');
96
+
97
+ Mage::getConfig()->saveConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_API_ID, $apiKey, $scope, $scopeId);
98
+
99
+ /** @var $apiHelper Campaignmonitor_Createsend_Helper_Api */
100
+ $apiHelper = Mage::helper("createsend/api");
101
+
102
+ $clients = $apiHelper->getClients($scope, $scopeId);
103
+ if ($clients !== null) {
104
+ if (count($clients) == 2) {
105
+ // Automatically get the lists if only one client
106
+ $clients[1]['lists'] = $apiHelper->getLists($clients[1]['value'], $scope, $scopeId);
107
+ }
108
+ }
109
+
110
+ $jsonData = json_encode(
111
+ array (
112
+ 'status' => 'success',
113
+ 'items' => $clients
114
+ )
115
+ );
116
+
117
+ $this->getResponse()->setHeader('Content-type', 'application/json');
118
+ $this->getResponse()->setBody($jsonData);
119
+ }
120
+
121
+ /**
122
+ * Returns the Campaign Monitor subscription lists for the client.
123
+ * Prints out the lists in JSON format.
124
+ */
125
+ public function getListsAction()
126
+ {
127
+ $scope = $this->getRequest()->getQuery('scope');
128
+ $scopeId = $this->getRequest()->getQuery('scopeId');
129
+ $clientId = $this->getRequest()->getQuery('clientId');
130
+
131
+ /** @var $apiHelper Campaignmonitor_Createsend_Helper_Api */
132
+ $apiHelper = Mage::helper("createsend/api");
133
+
134
+ $lists = $apiHelper->getLists($clientId, $scope, $scopeId);
135
+
136
+ $jsonData = json_encode(
137
+ array (
138
+ 'status' => 'success',
139
+ 'items' => $lists
140
+ )
141
+ );
142
+
143
+ $this->getResponse()->setHeader('Content-type', 'application/json');
144
+ $this->getResponse()->setBody($jsonData);
145
+ }
146
+ }
app/code/community/Campaignmonitor/Createsend/controllers/Adminhtml/Createsend/EmailController.php CHANGED
@@ -1,146 +1,146 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_Adminhtml_Createsend_EmailController extends Mage_Adminhtml_Controller_Action
19
- {
20
- const ERR_UNABLE_TO_RESEND_EMAIL = 'Unable to resend email: %s';
21
- const ERR_EMAIL_NOT_FOUND = 'Email not found.';
22
- const ERR_API_ERROR = 'API Error: %s';
23
- const ERR_EMAIL_CANNOT_BE_RESENT = 'Email cannot be resent';
24
- const LOG_EMAIL_RESENT = 'Email resend status: %s';
25
-
26
- const PATH_EMAIL_VIEW = 'adminhtml/createsend_email/view';
27
- const PATH_EMAIL_INDEX = 'adminhtml/createsend_email/index';
28
-
29
- public function indexAction()
30
- {
31
- $this->loadLayout();
32
- $this->_setActiveMenu('system');
33
- $this->renderLayout();
34
- }
35
-
36
- public function gridAction()
37
- {
38
- $this->loadLayout();
39
- $this->renderLayout();
40
- }
41
-
42
- public function viewAction()
43
- {
44
- $emailId = $this->getRequest()->getParam('email_id');
45
- $display = $this->getRequest()->getParam('display');
46
-
47
- /** @var Campaignmonitor_Createsend_Model_Email $email */
48
- $email = Mage::getModel('createsend/email')->load($emailId);
49
-
50
- $messageId = $email->getMessageId();
51
-
52
- if (empty($messageId)) {
53
- Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_EMAIL_NOT_FOUND));
54
- return $this->_redirectReferer();
55
- }
56
-
57
- /** @var Campaignmonitor_Createsend_Model_Api $api */
58
- $api = Mage::getModel('createsend/api');
59
-
60
- $scope = $email->getScope();
61
- $scopeId = $email->getScopeId();
62
-
63
- $reply = $api->call(
64
- Zend_Http_Client::GET,
65
- "transactional/messages/${messageId}",
66
- array(),
67
- array('statistics' => 'true'),
68
- $scope,
69
- $scopeId
70
- );
71
-
72
- if (!$reply['success']) {
73
- Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_API_ERROR, $reply['data']['Message']));
74
- return $this->_redirectReferer();
75
- }
76
-
77
- $reply['data']['email_id'] = $emailId;
78
-
79
- if ($display === 'body') {
80
- if (isset($reply['data']['Message']['Body']['Html'])) {
81
- print $reply['data']['Message']['Body']['Html'];
82
- } else {
83
- print '';
84
- }
85
- } else {
86
- Mage::register('createsend_email', $reply['data']);
87
-
88
- $this->loadLayout();
89
-
90
- $request = Mage::app()->getRequest();
91
- $customerId = $request->getUserParam('customer_id');
92
- if ($customerId) {
93
- $this->_setActiveMenu('customer');
94
- } else {
95
- $this->_setActiveMenu('system');
96
- }
97
-
98
- return $this->renderLayout();
99
- }
100
- }
101
-
102
- public function resendAction()
103
- {
104
- $emailId = $this->getRequest()->getParam('email_id');
105
-
106
- /** @var Campaignmonitor_Createsend_Model_Email $email */
107
- $email = Mage::getModel('createsend/email')->load($emailId);
108
-
109
- $messageId = $email->getMessageId();
110
-
111
- if (empty($messageId)) {
112
- Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_EMAIL_NOT_FOUND));
113
- return $this->_redirect(self::PATH_EMAIL_VIEW, array('email_id' => $emailId));
114
- }
115
-
116
- if (!$email->getCanBeResent()) {
117
- Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_EMAIL_CANNOT_BE_RESENT));
118
- return $this->_redirect(self::PATH_EMAIL_VIEW, array('email_id' => $emailId));
119
- }
120
-
121
- /** @var Campaignmonitor_Createsend_Model_Api $api */
122
- $api = Mage::getModel('createsend/api');
123
-
124
- $scope = $email->getScope();
125
- $scopeId = $email->getScopeId();
126
-
127
- $reply = $api->call(
128
- Zend_Http_Client::POST,
129
- "transactional/messages/${messageId}/resend",
130
- array(),
131
- array(),
132
- $scope,
133
- $scopeId
134
- );
135
-
136
- if ($reply['success'] !== false) {
137
- Mage::getSingleton('adminhtml/session')
138
- ->addSuccess(sprintf(self::LOG_EMAIL_RESENT, $reply['data']['Status']));
139
- } else {
140
- Mage::getSingleton('adminhtml/session')
141
- ->addError(sprintf(self::ERR_UNABLE_TO_RESEND_EMAIL, $reply['data']['Message']));
142
- }
143
-
144
- return $this->_redirect(self::PATH_EMAIL_VIEW, array('email_id' => $emailId));
145
- }
146
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_Adminhtml_Createsend_EmailController extends Mage_Adminhtml_Controller_Action
19
+ {
20
+ const ERR_UNABLE_TO_RESEND_EMAIL = 'Unable to resend email: %s';
21
+ const ERR_EMAIL_NOT_FOUND = 'Email not found.';
22
+ const ERR_API_ERROR = 'API Error: %s';
23
+ const ERR_EMAIL_CANNOT_BE_RESENT = 'Email cannot be resent';
24
+ const LOG_EMAIL_RESENT = 'Email resend status: %s';
25
+
26
+ const PATH_EMAIL_VIEW = 'adminhtml/createsend_email/view';
27
+ const PATH_EMAIL_INDEX = 'adminhtml/createsend_email/index';
28
+
29
+ public function indexAction()
30
+ {
31
+ $this->loadLayout();
32
+ $this->_setActiveMenu('system');
33
+ $this->renderLayout();
34
+ }
35
+
36
+ public function gridAction()
37
+ {
38
+ $this->loadLayout();
39
+ $this->renderLayout();
40
+ }
41
+
42
+ public function viewAction()
43
+ {
44
+ $emailId = $this->getRequest()->getParam('email_id');
45
+ $display = $this->getRequest()->getParam('display');
46
+
47
+ /** @var Campaignmonitor_Createsend_Model_Email $email */
48
+ $email = Mage::getModel('createsend/email')->load($emailId);
49
+
50
+ $messageId = $email->getMessageId();
51
+
52
+ if (empty($messageId)) {
53
+ Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_EMAIL_NOT_FOUND));
54
+ return $this->_redirectReferer();
55
+ }
56
+
57
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
58
+ $api = Mage::getModel('createsend/api');
59
+
60
+ $scope = $email->getScope();
61
+ $scopeId = $email->getScopeId();
62
+
63
+ $reply = $api->call(
64
+ Zend_Http_Client::GET,
65
+ "transactional/messages/${messageId}",
66
+ array(),
67
+ array('statistics' => 'true'),
68
+ $scope,
69
+ $scopeId
70
+ );
71
+
72
+ if (!$reply['success']) {
73
+ Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_API_ERROR, $reply['data']['Message']));
74
+ return $this->_redirectReferer();
75
+ }
76
+
77
+ $reply['data']['email_id'] = $emailId;
78
+
79
+ if ($display === 'body') {
80
+ if (isset($reply['data']['Message']['Body']['Html'])) {
81
+ print $reply['data']['Message']['Body']['Html'];
82
+ } else {
83
+ print '';
84
+ }
85
+ } else {
86
+ Mage::register('createsend_email', $reply['data']);
87
+
88
+ $this->loadLayout();
89
+
90
+ $request = Mage::app()->getRequest();
91
+ $customerId = $request->getUserParam('customer_id');
92
+ if ($customerId) {
93
+ $this->_setActiveMenu('customer');
94
+ } else {
95
+ $this->_setActiveMenu('system');
96
+ }
97
+
98
+ return $this->renderLayout();
99
+ }
100
+ }
101
+
102
+ public function resendAction()
103
+ {
104
+ $emailId = $this->getRequest()->getParam('email_id');
105
+
106
+ /** @var Campaignmonitor_Createsend_Model_Email $email */
107
+ $email = Mage::getModel('createsend/email')->load($emailId);
108
+
109
+ $messageId = $email->getMessageId();
110
+
111
+ if (empty($messageId)) {
112
+ Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_EMAIL_NOT_FOUND));
113
+ return $this->_redirect(self::PATH_EMAIL_VIEW, array('email_id' => $emailId));
114
+ }
115
+
116
+ if (!$email->getCanBeResent()) {
117
+ Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_EMAIL_CANNOT_BE_RESENT));
118
+ return $this->_redirect(self::PATH_EMAIL_VIEW, array('email_id' => $emailId));
119
+ }
120
+
121
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
122
+ $api = Mage::getModel('createsend/api');
123
+
124
+ $scope = $email->getScope();
125
+ $scopeId = $email->getScopeId();
126
+
127
+ $reply = $api->call(
128
+ Zend_Http_Client::POST,
129
+ "transactional/messages/${messageId}/resend",
130
+ array(),
131
+ array(),
132
+ $scope,
133
+ $scopeId
134
+ );
135
+
136
+ if ($reply['success'] !== false) {
137
+ Mage::getSingleton('adminhtml/session')
138
+ ->addSuccess(sprintf(self::LOG_EMAIL_RESENT, $reply['data']['Status']));
139
+ } else {
140
+ Mage::getSingleton('adminhtml/session')
141
+ ->addError(sprintf(self::ERR_UNABLE_TO_RESEND_EMAIL, $reply['data']['Message']));
142
+ }
143
+
144
+ return $this->_redirect(self::PATH_EMAIL_VIEW, array('email_id' => $emailId));
145
+ }
146
  }
app/code/community/Campaignmonitor/Createsend/controllers/Adminhtml/Createsend/SegmentController.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
- class Campaignmonitor_Createsend_Adminhtml_Createsend_SegmentController extends Mage_Adminhtml_Controller_Action
18
- {
19
- const ADMINHTML_SYSTEM_CONFIG_EDIT = 'adminhtml/system_config/edit';
20
-
21
- /**
22
- * Responsible for creating Campaign Monitor segments.
23
- *
24
- * @link https://www.campaignmonitor.com/api/segments/
25
- *
26
- * @return Mage_Core_Controller_Varien_Action
27
- */
28
- public function createExamplesAction()
29
- {
30
- $scope = $this->getRequest()->getQuery('scope');
31
- $scopeId = $this->getRequest()->getQuery('scopeId');
32
-
33
- /** @var Campaignmonitor_Createsend_Model_Api $api */
34
- $api = Mage::getModel('createsend/api');
35
-
36
- $responses = $api->createExampleSegments($scope, $scopeId);
37
-
38
- print json_encode(
39
- array(
40
- 'messages' => $responses
41
- )
42
- );
43
- }
44
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ class Campaignmonitor_Createsend_Adminhtml_Createsend_SegmentController extends Mage_Adminhtml_Controller_Action
18
+ {
19
+ const ADMINHTML_SYSTEM_CONFIG_EDIT = 'adminhtml/system_config/edit';
20
+
21
+ /**
22
+ * Responsible for creating Campaign Monitor segments.
23
+ *
24
+ * @link https://www.campaignmonitor.com/api/segments/
25
+ *
26
+ * @return Mage_Core_Controller_Varien_Action
27
+ */
28
+ public function createExamplesAction()
29
+ {
30
+ $scope = $this->getRequest()->getQuery('scope');
31
+ $scopeId = $this->getRequest()->getQuery('scopeId');
32
+
33
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
34
+ $api = Mage::getModel('createsend/api');
35
+
36
+ $responses = $api->createExampleSegments($scope, $scopeId);
37
+
38
+ print json_encode(
39
+ array(
40
+ 'messages' => $responses
41
+ )
42
+ );
43
+ }
44
+ }
app/code/community/Campaignmonitor/Createsend/controllers/OauthController.php CHANGED
@@ -1,148 +1,148 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_OauthController extends Mage_Adminhtml_Controller_Action
19
- {
20
- const HTTP_OK = 200;
21
- const HTTP_BAD_REQUEST = 400;
22
- const HTTP_METHOD_NOT_ALLOWED = 405;
23
-
24
- const LOG_TOKEN_REDIRECT = 'Campaign Monitor API Redirect: %s';
25
-
26
- const ERR_OAUTH_EXCHANGE = 'Error in OAuth Exchange: %s';
27
- const ERR_INVALID_SCOPE = 'Invalid state/scope: %s';
28
- const ERR_UNABLE_TO_AUTHENTICATE = 'Unable to authenticate: %s';
29
- const ERR_UNABLE_TO_SAVE_TOKEN = 'Unable to save OAuth Token: %s';
30
- const MSG_OAUTH_TOKEN_SAVED = 'OAuth Token saved.';
31
-
32
- const ADMINHTML_SYSTEM_CONFIG_EDIT = 'adminhtml/system_config/edit';
33
-
34
- // Disable validation of admin url key to allow redirection from frontend to system config section
35
- protected $_publicActions = array('getToken');
36
-
37
- /**
38
- * Responsible for requesting Campaign Monitor OAuth Permission
39
- * and storage of access_token, expires_in and refresh_token.
40
- *
41
- * @link https://www.campaignmonitor.com/api/getting-started/#authenticating_with_oauth
42
- */
43
- public function getTokenAction()
44
- {
45
- $configSection = array('section' => 'createsend_general');
46
-
47
- /** @var $helper Campaignmonitor_Createsend_Helper_Data */
48
- $helper = Mage::helper("createsend");
49
-
50
- /** @var Campaignmonitor_Createsend_Model_Api $api */
51
- $api = Mage::getModel('createsend/api');
52
-
53
- $helper->log(
54
- sprintf(self::LOG_TOKEN_REDIRECT, implode(',', $this->getRequest()->getParams())),
55
- Zend_Log::DEBUG
56
- );
57
-
58
- $request = $this->getRequest();
59
- $state = explode(',', $request->getQuery('state'));
60
-
61
- if (sizeof($state) == 2) {
62
- $scope = $state[0];
63
- $scopeId = $state[1];
64
- } else {
65
- $helper->log(sprintf(self::ERR_INVALID_SCOPE, $state), Zend_Log::DEBUG);
66
-
67
- Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_INVALID_SCOPE, $state));
68
- return $this->_redirect(self::ADMINHTML_SYSTEM_CONFIG_EDIT, $configSection);
69
- }
70
-
71
- /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
72
- $scopeModel = Mage::getModel('createsend/config_scope');
73
- $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
74
- $websiteId = $scopeModel->getWebsiteIdFromScope($scope, $scopeId);
75
-
76
- $store = Mage::app()->getStore($storeId)->getCode();
77
- $website = Mage::app()->getWebsite($websiteId)->getCode();
78
-
79
- $configSection['website'] = $website;
80
- $configSection['store'] = $store;
81
-
82
- $errorMessage = $request->getQuery('error_description');
83
- if (!empty($errorMessage)) {
84
- $helper->log(
85
- sprintf(self::ERR_OAUTH_EXCHANGE, $errorMessage),
86
- Zend_Log::DEBUG
87
- );
88
-
89
- Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_UNABLE_TO_AUTHENTICATE, $errorMessage));
90
- return $this->_redirect(self::ADMINHTML_SYSTEM_CONFIG_EDIT, $configSection);
91
- }
92
-
93
- $reply = $api->call(
94
- Zend_Http_Client::POST,
95
- 'token',
96
- array(),
97
- array(
98
- 'grant_type' => 'authorization_code',
99
- 'client_id' => $helper->getOAuthClientId($storeId),
100
- 'client_secret' => $helper->getOAuthClientSecret($storeId),
101
- 'code' => $request->getQuery('code'),
102
- 'redirect_uri' => $api->getOauthRedirectUri($scope, $scopeId),
103
- ),
104
- $scope,
105
- $scopeId
106
- );
107
-
108
- if (!empty($reply['data']['access_token'])) {
109
- $result = $helper->saveOauthTokenData($reply['data'], $scope, $scopeId);
110
-
111
- if ($result) {
112
- Mage::getSingleton('adminhtml/session')->addSuccess(
113
- sprintf(self::MSG_OAUTH_TOKEN_SAVED, $reply['data']['access_token'])
114
- );
115
- } else {
116
- Mage::getSingleton('adminhtml/session')->addError(
117
- sprintf(self::ERR_UNABLE_TO_SAVE_TOKEN, $reply['data']['access_token'])
118
- );
119
- }
120
-
121
- $webhookId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
122
- $webhookEnabled = $helper->isWebhookEnabled($storeId);
123
-
124
- if ($webhookEnabled && $webhookId === false) {
125
- // Register webhooks after successfully getting the OAuth token
126
- /** @var Campaignmonitor_Createsend_Model_Api $api */
127
- $api = Mage::getModel('createsend/api');
128
- $reply = $api->updateWebhooks($scope, $scopeId);
129
-
130
- if ($reply['success'] === false) {
131
- Mage::getSingleton('adminhtml/session')->addError(
132
- sprintf(Campaignmonitor_Createsend_Model_Api::ERR_CANNOT_UPDATE_WEBHOOK, $reply['data']['Message'])
133
- );
134
- } else {
135
- if ($reply['data']['Message']) {
136
- Mage::getSingleton('adminhtml/session')->addSuccess(sprintf($reply['data']['Message']));
137
- }
138
- }
139
- }
140
- } else {
141
- Mage::getSingleton('adminhtml/session')->addError(
142
- sprintf(self::ERR_UNABLE_TO_AUTHENTICATE, $reply['data']['Message'])
143
- );
144
- }
145
-
146
- return $this->_redirect(self::ADMINHTML_SYSTEM_CONFIG_EDIT, $configSection);
147
- }
148
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_OauthController extends Mage_Adminhtml_Controller_Action
19
+ {
20
+ const HTTP_OK = 200;
21
+ const HTTP_BAD_REQUEST = 400;
22
+ const HTTP_METHOD_NOT_ALLOWED = 405;
23
+
24
+ const LOG_TOKEN_REDIRECT = 'Campaign Monitor API Redirect: %s';
25
+
26
+ const ERR_OAUTH_EXCHANGE = 'Error in OAuth Exchange: %s';
27
+ const ERR_INVALID_SCOPE = 'Invalid state/scope: %s';
28
+ const ERR_UNABLE_TO_AUTHENTICATE = 'Unable to authenticate: %s';
29
+ const ERR_UNABLE_TO_SAVE_TOKEN = 'Unable to save OAuth Token: %s';
30
+ const MSG_OAUTH_TOKEN_SAVED = 'OAuth Token saved.';
31
+
32
+ const ADMINHTML_SYSTEM_CONFIG_EDIT = 'adminhtml/system_config/edit';
33
+
34
+ // Disable validation of admin url key to allow redirection from frontend to system config section
35
+ protected $_publicActions = array('getToken');
36
+
37
+ /**
38
+ * Responsible for requesting Campaign Monitor OAuth Permission
39
+ * and storage of access_token, expires_in and refresh_token.
40
+ *
41
+ * @link https://www.campaignmonitor.com/api/getting-started/#authenticating_with_oauth
42
+ */
43
+ public function getTokenAction()
44
+ {
45
+ $configSection = array('section' => 'createsend_general');
46
+
47
+ /** @var $helper Campaignmonitor_Createsend_Helper_Data */
48
+ $helper = Mage::helper("createsend");
49
+
50
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
51
+ $api = Mage::getModel('createsend/api');
52
+
53
+ $helper->log(
54
+ sprintf(self::LOG_TOKEN_REDIRECT, implode(',', $this->getRequest()->getParams())),
55
+ Zend_Log::DEBUG
56
+ );
57
+
58
+ $request = $this->getRequest();
59
+ $state = explode(',', $request->getQuery('state'));
60
+
61
+ if (sizeof($state) == 2) {
62
+ $scope = $state[0];
63
+ $scopeId = $state[1];
64
+ } else {
65
+ $helper->log(sprintf(self::ERR_INVALID_SCOPE, $state), Zend_Log::DEBUG);
66
+
67
+ Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_INVALID_SCOPE, $state));
68
+ return $this->_redirect(self::ADMINHTML_SYSTEM_CONFIG_EDIT, $configSection);
69
+ }
70
+
71
+ /** @var Campaignmonitor_Createsend_Model_Config_Scope $scopeModel */
72
+ $scopeModel = Mage::getModel('createsend/config_scope');
73
+ $storeId = $scopeModel->getStoreIdFromScope($scope, $scopeId);
74
+ $websiteId = $scopeModel->getWebsiteIdFromScope($scope, $scopeId);
75
+
76
+ $store = Mage::app()->getStore($storeId)->getCode();
77
+ $website = Mage::app()->getWebsite($websiteId)->getCode();
78
+
79
+ $configSection['website'] = $website;
80
+ $configSection['store'] = $store;
81
+
82
+ $errorMessage = $request->getQuery('error_description');
83
+ if (!empty($errorMessage)) {
84
+ $helper->log(
85
+ sprintf(self::ERR_OAUTH_EXCHANGE, $errorMessage),
86
+ Zend_Log::DEBUG
87
+ );
88
+
89
+ Mage::getSingleton('adminhtml/session')->addError(sprintf(self::ERR_UNABLE_TO_AUTHENTICATE, $errorMessage));
90
+ return $this->_redirect(self::ADMINHTML_SYSTEM_CONFIG_EDIT, $configSection);
91
+ }
92
+
93
+ $reply = $api->call(
94
+ Zend_Http_Client::POST,
95
+ 'token',
96
+ array(),
97
+ array(
98
+ 'grant_type' => 'authorization_code',
99
+ 'client_id' => $helper->getOAuthClientId($storeId),
100
+ 'client_secret' => $helper->getOAuthClientSecret($storeId),
101
+ 'code' => $request->getQuery('code'),
102
+ 'redirect_uri' => $api->getOauthRedirectUri($scope, $scopeId),
103
+ ),
104
+ $scope,
105
+ $scopeId
106
+ );
107
+
108
+ if (!empty($reply['data']['access_token'])) {
109
+ $result = $helper->saveOauthTokenData($reply['data'], $scope, $scopeId);
110
+
111
+ if ($result) {
112
+ Mage::getSingleton('adminhtml/session')->addSuccess(
113
+ sprintf(self::MSG_OAUTH_TOKEN_SAVED, $reply['data']['access_token'])
114
+ );
115
+ } else {
116
+ Mage::getSingleton('adminhtml/session')->addError(
117
+ sprintf(self::ERR_UNABLE_TO_SAVE_TOKEN, $reply['data']['access_token'])
118
+ );
119
+ }
120
+
121
+ $webhookId = $helper->getScopedConfig(Campaignmonitor_Createsend_Helper_Data::XML_PATH_WEBHOOK_ID, $scope, $scopeId);
122
+ $webhookEnabled = $helper->isWebhookEnabled($storeId);
123
+
124
+ if ($webhookEnabled && $webhookId === false) {
125
+ // Register webhooks after successfully getting the OAuth token
126
+ /** @var Campaignmonitor_Createsend_Model_Api $api */
127
+ $api = Mage::getModel('createsend/api');
128
+ $reply = $api->updateWebhooks($scope, $scopeId);
129
+
130
+ if ($reply['success'] === false) {
131
+ Mage::getSingleton('adminhtml/session')->addError(
132
+ sprintf(Campaignmonitor_Createsend_Model_Api::ERR_CANNOT_UPDATE_WEBHOOK, $reply['data']['Message'])
133
+ );
134
+ } else {
135
+ if ($reply['data']['Message']) {
136
+ Mage::getSingleton('adminhtml/session')->addSuccess(sprintf($reply['data']['Message']));
137
+ }
138
+ }
139
+ }
140
+ } else {
141
+ Mage::getSingleton('adminhtml/session')->addError(
142
+ sprintf(self::ERR_UNABLE_TO_AUTHENTICATE, $reply['data']['Message'])
143
+ );
144
+ }
145
+
146
+ return $this->_redirect(self::ADMINHTML_SYSTEM_CONFIG_EDIT, $configSection);
147
+ }
148
+ }
app/code/community/Campaignmonitor/Createsend/controllers/UnsubscribeController.php CHANGED
@@ -1,67 +1,67 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- class Campaignmonitor_Createsend_UnsubscribeController extends Mage_Core_Controller_Front_Action
19
- {
20
- //
21
- // /**
22
- // * Responsible for unsubscribing users already unsubscribed by Campaign Monitor.
23
- // *
24
- // * @deprecated in 1.0.0 in favour of Webhooks. See Campaignmonitor_Createsend_WebhooksController.
25
- // */
26
- //
27
- // public function indexAction()
28
- // {
29
- // /** @var $helper Campaignmonitor_Createsend_Helper_Data */
30
- // $helper = Mage::helper("createsend");
31
- // $email = $this->getRequest()->getQuery('email');
32
- //
33
- // // don't do anything if we didn't get the email parameter
34
- // if (!$email) {
35
- // return $this->_redirect('customer/account/');
36
- // }
37
- // /** @var Campaignmonitor_Createsend_Model_Api $api */
38
- // $api = Mage::getModel('createsend/api');
39
- //
40
- // // Check that the email address actually is unsubscribed in Campaign Monitor
41
- // $result = $api->call(
42
- // Zend_Http_Client::GET,
43
- // 'subscribers/' . $helper->getListId(),
44
- // null,
45
- // array(
46
- // 'email' => $email
47
- // )
48
- // );
49
- //
50
- // if ($result['success'] === false) {
51
- // return $this->_redirect('customer/account');
52
- // }
53
- //
54
- // // If customer is unsubscribed in Campaign Monitor mark as such in Magento
55
- // if (in_array($result['Data']['State'], array('Unsubscribed', 'Deleted'))) {
56
- // $helper->log("Unsubscribing $email");
57
- // Mage::getModel('newsletter/subscriber')
58
- // ->loadByEmail($email)
59
- // ->unsubscribe();
60
- // Mage::getSingleton('customer/session')->addSuccess($this->__('You were successfully unsubscribed'));
61
- // } else {
62
- // Mage::getSingleton('customer/session')->addWarning($this->__('Please unsubscribe from Campaign Monitor first'));
63
- // }
64
- //
65
- // return $this->_redirect('customer/account/');
66
- // }
67
- }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Campaignmonitor_Createsend_UnsubscribeController extends Mage_Core_Controller_Front_Action
19
+ {
20
+ //
21
+ // /**
22
+ // * Responsible for unsubscribing users already unsubscribed by Campaign Monitor.
23
+ // *
24
+ // * @deprecated in 1.0.0 in favour of Webhooks. See Campaignmonitor_Createsend_WebhooksController.
25
+ // */
26
+ //
27
+ // public function indexAction()
28
+ // {
29
+ // /** @var $helper Campaignmonitor_Createsend_Helper_Data */
30
+ // $helper = Mage::helper("createsend");
31
+ // $email = $this->getRequest()->getQuery('email');
32
+ //
33
+ // // don't do anything if we didn't get the email parameter
34
+ // if (!$email) {
35
+ // return $this->_redirect('customer/account/');
36
+ // }
37
+ // /** @var Campaignmonitor_Createsend_Model_Api $api */
38
+ // $api = Mage::getModel('createsend/api');
39
+ //
40
+ // // Check that the email address actually is unsubscribed in Campaign Monitor
41
+ // $result = $api->call(
42
+ // Zend_Http_Client::GET,
43
+ // 'subscribers/' . $helper->getListId(),
44
+ // null,
45
+ // array(
46
+ // 'email' => $email
47
+ // )
48
+ // );
49
+ //
50
+ // if ($result['success'] === false) {
51
+ // return $this->_redirect('customer/account');
52
+ // }
53
+ //
54
+ // // If customer is unsubscribed in Campaign Monitor mark as such in Magento
55
+ // if (in_array($result['Data']['State'], array('Unsubscribed', 'Deleted'))) {
56
+ // $helper->log("Unsubscribing $email");
57
+ // Mage::getModel('newsletter/subscriber')
58
+ // ->loadByEmail($email)
59
+ // ->unsubscribe();
60
+ // Mage::getSingleton('customer/session')->addSuccess($this->__('You were successfully unsubscribed'));
61
+ // } else {
62
+ // Mage::getSingleton('customer/session')->addWarning($this->__('Please unsubscribe from Campaign Monitor first'));
63
+ // }
64
+ //
65
+ // return $this->_redirect('customer/account/');
66
+ // }
67
+ }
app/code/community/Campaignmonitor/Createsend/controllers/WebhooksController.php CHANGED
@@ -1,126 +1,126 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
-
18
- /**
19
- * Responsible for handling the webhooks posted by Campaign Monitor
20
- */
21
- class Campaignmonitor_Createsend_WebhooksController extends Mage_Core_Controller_Front_Action
22
- {
23
- const ERR_HOOK_LIST_DOESNT_MATCH = 'The list stored in config "%s" does not match the webhook list "%s"';
24
-
25
- const HTTP_OK = 200;
26
- const HTTP_BAD_REQUEST = 400;
27
- const HTTP_METHOD_NOT_ALLOWED = 405;
28
-
29
- /**
30
- * Process the deactivate webhook
31
- *
32
- * Expects an array of the form:
33
- * [ListID] => fc6d0b8414e11d3a747ea73b05b23737
34
- * [Events] => Array
35
- * [0] => Array
36
- * [Type] => Deactivate
37
- * [Date] => 2010-01-01
38
- * [State] => Unsubscribed
39
- * [EmailAddress] => test@example.org
40
- * [Name] => Test Subscriber
41
- * [CustomFields] => Array
42
- * => Array
43
- * [Key] => website
44
- * [Value] => http://example.org
45
- *
46
- * @throws Zend_Controller_Response_Exception if the response code given is not in range
47
- */
48
- public function indexAction()
49
- {
50
- /** @var Campaignmonitor_Createsend_Helper_Data $helper */
51
- $helper = Mage::helper('createsend');
52
-
53
- $helper->log(
54
- sprintf('Webhook callback: ', implode(',', $this->getRequest()->getParams())),
55
- Zend_Log::DEBUG
56
- );
57
-
58
- // Do nothing if accessed outside of POST action
59
- if ($this->getRequest()->isPost() === false) {
60
- $this->getResponse()->setHttpResponseCode(self::HTTP_METHOD_NOT_ALLOWED);
61
- return;
62
- }
63
-
64
- try {
65
- $hookData = Zend_Json::decode($this->getRequest()->getRawBody());
66
- Mage::log( print_r( $hookData, true ), null, 'webhooks.log', true );
67
- } catch (Zend_Json_Exception $e) {
68
- $helper->log('Error decoding webhook body: ' . $e->getMessage());
69
- $this->getResponse()->setHttpResponseCode(self::HTTP_BAD_REQUEST);
70
- return;
71
- }
72
-
73
- // Get scope/scopeId from the config for the LIST ID supplied by CM
74
- $configModel = Mage::getModel('core/config_data')->getCollection()
75
- ->addFieldToFilter('path', Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID)
76
- ->addFieldToFilter('value', $hookData['ListID'])
77
- ->addFieldToSelect('scope')
78
- ->addFieldToSelect('scope_id')
79
- ->setPageSize(1)
80
- ->getFirstItem();
81
-
82
- if (!$configModel) {
83
- $this->getResponse()->setHttpResponseCode(self::HTTP_BAD_REQUEST);
84
- return;
85
- }
86
-
87
- $scope = $configModel['scope'];
88
- $scopeId = $configModel['scope_id'];
89
-
90
- $storeId = Mage::getModel('createsend/config_scope')->getStoreIdFromScope($scope, $scopeId);
91
-
92
- /** @var Campaignmonitor_Createsend_Model_Newsletter $newsletter */
93
- $newsletter = Mage::getModel('createsend/newsletter');
94
-
95
- foreach ($hookData['Events'] as $event) {
96
- $email = $event['EmailAddress'];
97
-
98
- if ($event['Type'] === Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_SUBSCRIBE) {
99
- $newsletter->subscribe($email, $storeId);
100
- } elseif ($event['Type'] === Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_DEACTIVATE) {
101
- $newsletter->unsubscribe($email);
102
- } elseif ($event['Type'] === Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_UPDATE) {
103
- $oldEmail = $event['OldEmailAddress'];
104
- $state = $event['State'];
105
-
106
- if ($state === Campaignmonitor_Createsend_Model_Api::WEBHOOK_STATUS_ACTIVE) {
107
- if ($oldEmail && $email !== $oldEmail) {
108
- $newsletter->unsubscribe($oldEmail);
109
- }
110
-
111
- $newsletter->subscribe($email, $storeId);
112
- } elseif ($state === Campaignmonitor_Createsend_Model_Api::WEBHOOK_STATUS_UNSUBSCRIBED
113
- || $state === Campaignmonitor_Createsend_Model_Api::WEBHOOK_STATUS_DELETED) {
114
-
115
- if ($oldEmail && $email !== $oldEmail) {
116
- $newsletter->unsubscribe($oldEmail);
117
- }
118
-
119
- $newsletter->unsubscribe($email);
120
- }
121
- }
122
- }
123
-
124
- $this->getResponse()->setHttpResponseCode(self::HTTP_OK);
125
- }
126
  }
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Responsible for handling the webhooks posted by Campaign Monitor
20
+ */
21
+ class Campaignmonitor_Createsend_WebhooksController extends Mage_Core_Controller_Front_Action
22
+ {
23
+ const ERR_HOOK_LIST_DOESNT_MATCH = 'The list stored in config "%s" does not match the webhook list "%s"';
24
+
25
+ const HTTP_OK = 200;
26
+ const HTTP_BAD_REQUEST = 400;
27
+ const HTTP_METHOD_NOT_ALLOWED = 405;
28
+
29
+ /**
30
+ * Process the deactivate webhook
31
+ *
32
+ * Expects an array of the form:
33
+ * [ListID] => fc6d0b8414e11d3a747ea73b05b23737
34
+ * [Events] => Array
35
+ * [0] => Array
36
+ * [Type] => Deactivate
37
+ * [Date] => 2010-01-01
38
+ * [State] => Unsubscribed
39
+ * [EmailAddress] => test@example.org
40
+ * [Name] => Test Subscriber
41
+ * [CustomFields] => Array
42
+ * => Array
43
+ * [Key] => website
44
+ * [Value] => http://example.org
45
+ *
46
+ * @throws Zend_Controller_Response_Exception if the response code given is not in range
47
+ */
48
+ public function indexAction()
49
+ {
50
+ /** @var Campaignmonitor_Createsend_Helper_Data $helper */
51
+ $helper = Mage::helper('createsend');
52
+
53
+ $helper->log(
54
+ sprintf('Webhook callback: ', implode(',', $this->getRequest()->getParams())),
55
+ Zend_Log::DEBUG
56
+ );
57
+
58
+ // Do nothing if accessed outside of POST action
59
+ if ($this->getRequest()->isPost() === false) {
60
+ $this->getResponse()->setHttpResponseCode(self::HTTP_METHOD_NOT_ALLOWED);
61
+ return;
62
+ }
63
+
64
+ try {
65
+ $hookData = Zend_Json::decode($this->getRequest()->getRawBody());
66
+
67
+ } catch (Zend_Json_Exception $e) {
68
+ $helper->log('Error decoding webhook body: ' . $e->getMessage());
69
+ $this->getResponse()->setHttpResponseCode(self::HTTP_BAD_REQUEST);
70
+ return;
71
+ }
72
+
73
+ // Get scope/scopeId from the config for the LIST ID supplied by CM
74
+ $configModel = Mage::getModel('core/config_data')->getCollection()
75
+ ->addFieldToFilter('path', Campaignmonitor_Createsend_Helper_Data::XML_PATH_LIST_ID)
76
+ ->addFieldToFilter('value', $hookData['ListID'])
77
+ ->addFieldToSelect('scope')
78
+ ->addFieldToSelect('scope_id')
79
+ ->setPageSize(1)
80
+ ->getFirstItem();
81
+
82
+ if (!$configModel) {
83
+ $this->getResponse()->setHttpResponseCode(self::HTTP_BAD_REQUEST);
84
+ return;
85
+ }
86
+
87
+ $scope = $configModel['scope'];
88
+ $scopeId = $configModel['scope_id'];
89
+
90
+ $storeId = Mage::getModel('createsend/config_scope')->getStoreIdFromScope($scope, $scopeId);
91
+
92
+ /** @var Campaignmonitor_Createsend_Model_Newsletter $newsletter */
93
+ $newsletter = Mage::getModel('createsend/newsletter');
94
+
95
+ foreach ($hookData['Events'] as $event) {
96
+ $email = $event['EmailAddress'];
97
+
98
+ if ($event['Type'] === Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_SUBSCRIBE) {
99
+ $newsletter->subscribe($email, $storeId);
100
+ } elseif ($event['Type'] === Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_DEACTIVATE) {
101
+ $newsletter->unsubscribe($email);
102
+ } elseif ($event['Type'] === Campaignmonitor_Createsend_Model_Api::WEBHOOK_EVENT_UPDATE) {
103
+ $oldEmail = $event['OldEmailAddress'];
104
+ $state = $event['State'];
105
+
106
+ if ($state === Campaignmonitor_Createsend_Model_Api::WEBHOOK_STATUS_ACTIVE) {
107
+ if ($oldEmail && $email !== $oldEmail) {
108
+ $newsletter->unsubscribe($oldEmail);
109
+ }
110
+
111
+ $newsletter->subscribe($email, $storeId);
112
+ } elseif ($state === Campaignmonitor_Createsend_Model_Api::WEBHOOK_STATUS_UNSUBSCRIBED
113
+ || $state === Campaignmonitor_Createsend_Model_Api::WEBHOOK_STATUS_DELETED) {
114
+
115
+ if ($oldEmail && $email !== $oldEmail) {
116
+ $newsletter->unsubscribe($oldEmail);
117
+ }
118
+
119
+ $newsletter->unsubscribe($email);
120
+ }
121
+ }
122
+ }
123
+
124
+ $this->getResponse()->setHttpResponseCode(self::HTTP_OK);
125
+ }
126
  }
app/code/community/Campaignmonitor/Createsend/etc/adminhtml.xml CHANGED
@@ -1,61 +1,61 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /**
4
- * Campaign Monitor Magento Extension
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Open Software License (OSL 3.0)
9
- * that is available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you are unable to obtain it through the world-wide-web, please
12
- * send an email to license@magento.com and you will be sent a copy.
13
- *
14
- * @package Campaignmonitor_Createsend
15
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
16
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
- */
18
- -->
19
- <config>
20
- <menu>
21
- <system>
22
- <children>
23
- <createsend translate="title" module="createsend">
24
- <title>Campaign Monitor</title>
25
- <sort_order>61</sort_order>
26
- <children>
27
- <createsend_tracking>
28
- <title>Email Tracking</title>
29
- <sort_order>0</sort_order>
30
- <action>adminhtml/createsend_email</action>
31
- </createsend_tracking>
32
- </children>
33
- </createsend>
34
- </children>
35
- </system>
36
- </menu>
37
- <acl>
38
- <resources>
39
- <all>
40
- <title>Allow Everything</title>
41
- </all>
42
- <admin>
43
- <children>
44
- <system>
45
- <children>
46
- <createsend module="createsend">
47
- <title>Campaign Monitor</title>
48
- <children>
49
- <createsend_tracking translate="title" module="createsend">
50
- <title>Email Tracking</title>
51
- <sort_order>20</sort_order>
52
- </createsend_tracking>
53
- </children>
54
- </createsend>
55
- </children>
56
- </system>
57
- </children>
58
- </admin>
59
- </resources>
60
- </acl>
61
- </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Campaign Monitor Magento Extension
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you are unable to obtain it through the world-wide-web, please
12
+ * send an email to license@magento.com and you will be sent a copy.
13
+ *
14
+ * @package Campaignmonitor_Createsend
15
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ -->
19
+ <config>
20
+ <menu>
21
+ <system>
22
+ <children>
23
+ <createsend translate="title" module="createsend">
24
+ <title>Campaign Monitor</title>
25
+ <sort_order>61</sort_order>
26
+ <children>
27
+ <createsend_tracking>
28
+ <title>Email Tracking</title>
29
+ <sort_order>0</sort_order>
30
+ <action>adminhtml/createsend_email</action>
31
+ </createsend_tracking>
32
+ </children>
33
+ </createsend>
34
+ </children>
35
+ </system>
36
+ </menu>
37
+ <acl>
38
+ <resources>
39
+ <all>
40
+ <title>Allow Everything</title>
41
+ </all>
42
+ <admin>
43
+ <children>
44
+ <system>
45
+ <children>
46
+ <createsend module="createsend">
47
+ <title>Campaign Monitor</title>
48
+ <children>
49
+ <createsend_tracking translate="title" module="createsend">
50
+ <title>Email Tracking</title>
51
+ <sort_order>20</sort_order>
52
+ </createsend_tracking>
53
+ </children>
54
+ </createsend>
55
+ </children>
56
+ </system>
57
+ </children>
58
+ </admin>
59
+ </resources>
60
+ </acl>
61
+ </config>
app/code/community/Campaignmonitor/Createsend/etc/config.xml CHANGED
@@ -1,292 +1,292 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /**
4
- * Campaign Monitor Magento Extension
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Open Software License (OSL 3.0)
9
- * that is available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you are unable to obtain it through the world-wide-web, please
12
- * send an email to license@magento.com and you will be sent a copy.
13
- *
14
- * @package Campaignmonitor_Createsend
15
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
16
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
- */
18
- -->
19
- <config>
20
- <modules>
21
- <Campaignmonitor_Createsend>
22
- <version>1.0.7</version>
23
- </Campaignmonitor_Createsend>
24
- </modules>
25
- <adminhtml>
26
- <layout>
27
- <updates>
28
- <campaignmonitor_createsend>
29
- <file>campaignmonitor/createsend.xml</file>
30
- </campaignmonitor_createsend>
31
- </updates>
32
- </layout>
33
- <acl>
34
- <resources>
35
- <admin>
36
- <children>
37
- <system>
38
- <children>
39
- <config>
40
- <children>
41
- <createsend_general>
42
- <title>Campaign Monitor General Section</title>
43
- </createsend_general>
44
- <createsend_customers>
45
- <title>Campaign Monitor Customers Section</title>
46
- </createsend_customers>
47
- <createsend_transactional>
48
- <title>Campaign Monitor Transactional Section</title>
49
- </createsend_transactional>
50
- </children>
51
- </config>
52
- </children>
53
- </system>
54
- </children>
55
- </admin>
56
- </resources>
57
- </acl>
58
- <events>
59
- <controller_action_layout_generate_blocks_after>
60
- <observers>
61
- <campaignmonitor_createsend_addjs>
62
- <type>singleton</type>
63
- <class>createsend/config_api</class>
64
- <method>addJavascriptBlock</method>
65
- </campaignmonitor_createsend_addjs>
66
- </observers>
67
- </controller_action_layout_generate_blocks_after>
68
- </events>
69
- </adminhtml>
70
- <global>
71
- <models>
72
- <createsend>
73
- <class>Campaignmonitor_Createsend_Model</class>
74
- <resourceModel>createsend_resource</resourceModel>
75
- </createsend>
76
- <createsend_resource>
77
- <class>Campaignmonitor_Createsend_Model_Resource</class>
78
- <entities>
79
- <email>
80
- <table>campaignmonitor_createsend_email</table>
81
- </email>
82
- </entities>
83
- </createsend_resource>
84
- <core>
85
- <rewrite>
86
- <email_template>Campaignmonitor_Createsend_Model_Email_Template</email_template>
87
- </rewrite>
88
- </core>
89
- </models>
90
- <resources>
91
- <campaignmonitor_createsend_setup>
92
- <setup>
93
- <module>Campaignmonitor_Createsend</module>
94
- </setup>
95
- <connection>
96
- <use>core_setup</use>
97
- </connection>
98
- </campaignmonitor_createsend_setup>
99
- </resources>
100
- <helpers>
101
- <createsend>
102
- <class>Campaignmonitor_Createsend_Helper</class>
103
- </createsend>
104
- </helpers>
105
- <blocks>
106
- <createsend>
107
- <class>Campaignmonitor_Createsend_Block</class>
108
- </createsend>
109
- </blocks>
110
- <events>
111
- <customer_save_before>
112
- <observers>
113
- <campaignmonitor_createsend_check_subscription_status>
114
- <type>singleton</type>
115
- <class>createsend/customer_observer</class>
116
- <method>checkSubscriptionStatus</method>
117
- </campaignmonitor_createsend_check_subscription_status>
118
- </observers>
119
- </customer_save_before>
120
- <customer_delete_before>
121
- <observers>
122
- <campaignmonitor_createsend_customer_deleted>
123
- <type>singleton</type>
124
- <class>createsend/customer_observer</class>
125
- <method>customerDeleted</method>
126
- </campaignmonitor_createsend_customer_deleted>
127
- </observers>
128
- </customer_delete_before>
129
- <sales_order_save_after>
130
- <observers>
131
- <campaignmonitor_createsend_check_subscription_status>
132
- <type>singleton</type>
133
- <class>createsend/customer_observer</class>
134
- <method>checkSubscriptionStatus</method>
135
- </campaignmonitor_createsend_check_subscription_status>
136
- </observers>
137
- </sales_order_save_after>
138
- <wishlist_product_add_after>
139
- <observers>
140
- <campaignmonitor_createsend_check_subscription_status>
141
- <type>singleton</type>
142
- <class>createsend/customer_observer</class>
143
- <method>checkSubscriptionStatus</method>
144
- </campaignmonitor_createsend_check_subscription_status>
145
- </observers>
146
- </wishlist_product_add_after>
147
- <admin_system_config_changed_section_createsend_general>
148
- <observers>
149
- <campaignmonitor_createsend_update_webhook>
150
- <type>singleton</type>
151
- <class>createsend/api_observer</class>
152
- <method>checkConfig</method>
153
- </campaignmonitor_createsend_update_webhook>
154
- </observers>
155
- </admin_system_config_changed_section_createsend_general>
156
- <admin_system_config_changed_section_createsend_customers>
157
- <observers>
158
- <campaignmonitor_createsend_create_custom_fields>
159
- <type>singleton</type>
160
- <class>createsend/customer_observer</class>
161
- <method>createCustomFields</method>
162
- </campaignmonitor_createsend_create_custom_fields>
163
- </observers>
164
- </admin_system_config_changed_section_createsend_customers>
165
- <controller_action_predispatch_adminhtml_newsletter_subscriber_massUnsubscribe>
166
- <observers>
167
- <campaignmonitor_createsend_update_user_massaction>
168
- <type>singleton</type>
169
- <class>createsend/api_observer</class>
170
- <method>massUnsubscribeUsers</method>
171
- </campaignmonitor_createsend_update_user_massaction>
172
- </observers>
173
- </controller_action_predispatch_adminhtml_newsletter_subscriber_massUnsubscribe>
174
- <controller_action_predispatch_adminhtml_newsletter_subscriber_massDelete>
175
- <observers>
176
- <campaignmonitor_createsend_update_user_massaction>
177
- <type>singleton</type>
178
- <class>createsend/api_observer</class>
179
- <method>massUnsubscribeUsers</method>
180
- </campaignmonitor_createsend_update_user_massaction>
181
- </observers>
182
- </controller_action_predispatch_adminhtml_newsletter_subscriber_massDelete>
183
- <controller_action_predispatch_newsletter_subscriber_new>
184
- <observers>
185
- <campaignmonitor_createsend_subscribe_new_user>
186
- <type>singleton</type>
187
- <class>createsend/api_observer</class>
188
- <method>subscribeNewUser</method>
189
- </campaignmonitor_createsend_subscribe_new_user>
190
- </observers>
191
- </controller_action_predispatch_newsletter_subscriber_new>
192
- <!-- Bug fix for Magento newsletter's change_status_at field non-update bug. -->
193
- <newsletter_subscriber_save_before>
194
- <observers>
195
- <campaignmonitor_createsend_newsletter_change_status_update>
196
- <type>singleton</type>
197
- <class>createsend/newsletter_observer</class>
198
- <method>setChangeStatusAt</method>
199
- </campaignmonitor_createsend_newsletter_change_status_update>
200
- </observers>
201
- </newsletter_subscriber_save_before>
202
- <catalog_product_save_after>
203
- <observers>
204
- <campaignmonitor_createsend_product_update>
205
- <type>singleton</type>
206
- <class>createsend/product_observer</class>
207
- <method>updateWishlistFields</method>
208
- </campaignmonitor_createsend_product_update>
209
- </observers>
210
- </catalog_product_save_after>
211
- </events>
212
- </global>
213
- <admin>
214
- <routers>
215
- <adminhtml>
216
- <args>
217
- <modules>
218
- <Campaignmonitor_Createsend before="Mage_Adminhtml">Campaignmonitor_Createsend_Adminhtml</Campaignmonitor_Createsend>
219
- </modules>
220
- </args>
221
- </adminhtml>
222
- </routers>
223
- </admin>
224
- <frontend>
225
- <routers>
226
- <createsend>
227
- <use>standard</use>
228
- <args>
229
- <module>Campaignmonitor_Createsend</module>
230
- <frontName>createsend</frontName>
231
- </args>
232
- </createsend>
233
- </routers>
234
- </frontend>
235
- <default>
236
- <createsend_general>
237
- <api>
238
- <authentication_method>api_key</authentication_method>
239
- </api>
240
- <advanced>
241
- <logging>1</logging>
242
- <webhook_enabled>1</webhook_enabled>
243
- <subscriber_synchronisation_enabled>1</subscriber_synchronisation_enabled>
244
- <subscriber_synchronisation_resolution_method>timestamp</subscriber_synchronisation_resolution_method>
245
- <magento_cron_enabled>1</magento_cron_enabled>
246
- </advanced>
247
- </createsend_general>
248
- <createsend_customers>
249
- <attributes>
250
- <m_to_cm_attributes>a:19:{i:0;a:1:{s:7:"magento";s:18:"FONTIS-has-account";}i:1;a:1:{s:7:"magento";s:10:"created_in";}i:2;a:1:{s:7:"magento";s:8:"group_id";}i:3;a:1:{s:7:"magento";s:10:"created_at";}i:4;a:1:{s:7:"magento";s:9:"firstname";}i:5;a:1:{s:7:"magento";s:8:"lastname";}i:6;a:1:{s:7:"magento";s:3:"dob";}i:7;a:1:{s:7:"magento";s:6:"gender";}i:8;a:1:{s:7:"magento";s:12:"confirmation";}i:9;a:1:{s:7:"magento";s:10:"website_id";}i:10;a:1:{s:7:"magento";s:8:"store_id";}i:11;a:1:{s:7:"magento";s:32:"FONTIS-sales-average-order-value";}i:12;a:1:{s:7:"magento";s:29:"FONTIS-sales-first-order-date";}i:13;a:1:{s:7:"magento";s:29:"FONTIS-sales-last-order-value";}i:14;a:1:{s:7:"magento";s:28:"FONTIS-sales-last-order-date";}i:15;a:1:{s:7:"magento";s:30:"FONTIS-sales-total-order-value";}i:16;a:1:{s:7:"magento";s:35:"FONTIS-sales-total-number-of-orders";}i:17;a:1:{s:7:"magento";s:45:"FONTIS-sales-total-number-of-products-ordered";}i:18;a:1:{s:7:"magento";s:31:"FONTIS-number-of-wishlist-items";}}</m_to_cm_attributes>
251
- </attributes>
252
- <wishlists>
253
- <max_wishlist_items>1</max_wishlist_items>
254
- <wishlist_product_attributes>a:4:{i:0;a:1:{s:7:"magento";s:4:"name";}i:1;a:1:{s:7:"magento";s:5:"price";}i:2;a:1:{s:7:"magento";s:17:"short_description";}i:3;a:1:{s:7:"magento";s:3:"sku";}}</wishlist_product_attributes>
255
- </wishlists>
256
- </createsend_customers>
257
- <createsend_transactional>
258
- <emails>
259
- <transactional_email_enabled>0</transactional_email_enabled>
260
- <transactional_email_retention_days>90</transactional_email_retention_days>
261
- </emails>
262
- </createsend_transactional>
263
- </default>
264
- <crontab>
265
- <jobs>
266
- <campaignmonitor_createsend_subscriber_synchronise_initial>
267
- <schedule>
268
- <cron_expr>*/5 * * * *</cron_expr>
269
- </schedule>
270
- <run>
271
- <model>createsend/list_initial_cron::runFromMagentoCron</model>
272
- </run>
273
- </campaignmonitor_createsend_subscriber_synchronise_initial>
274
- <campaignmonitor_createsend_subscriber_synchronise>
275
- <schedule>
276
- <cron_expr>0 1 * * *</cron_expr>
277
- </schedule>
278
- <run>
279
- <model>createsend/list_cron::runFromMagentoCron</model>
280
- </run>
281
- </campaignmonitor_createsend_subscriber_synchronise>
282
- <campaignmonitor_createsend_email_download>
283
- <schedule>
284
- <cron_expr>0 * * * *</cron_expr>
285
- </schedule>
286
- <run>
287
- <model>createsend/email_cron::runFromMagentoCron</model>
288
- </run>
289
- </campaignmonitor_createsend_email_download>
290
- </jobs>
291
- </crontab>
292
- </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Campaign Monitor Magento Extension
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you are unable to obtain it through the world-wide-web, please
12
+ * send an email to license@magento.com and you will be sent a copy.
13
+ *
14
+ * @package Campaignmonitor_Createsend
15
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ -->
19
+ <config>
20
+ <modules>
21
+ <Campaignmonitor_Createsend>
22
+ <version>1.0.8</version>
23
+ </Campaignmonitor_Createsend>
24
+ </modules>
25
+ <adminhtml>
26
+ <layout>
27
+ <updates>
28
+ <campaignmonitor_createsend>
29
+ <file>campaignmonitor/createsend.xml</file>
30
+ </campaignmonitor_createsend>
31
+ </updates>
32
+ </layout>
33
+ <acl>
34
+ <resources>
35
+ <admin>
36
+ <children>
37
+ <system>
38
+ <children>
39
+ <config>
40
+ <children>
41
+ <createsend_general>
42
+ <title>Campaign Monitor General Section</title>
43
+ </createsend_general>
44
+ <createsend_customers>
45
+ <title>Campaign Monitor Customers Section</title>
46
+ </createsend_customers>
47
+ <createsend_transactional>
48
+ <title>Campaign Monitor Transactional Section</title>
49
+ </createsend_transactional>
50
+ </children>
51
+ </config>
52
+ </children>
53
+ </system>
54
+ </children>
55
+ </admin>
56
+ </resources>
57
+ </acl>
58
+ <events>
59
+ <controller_action_layout_generate_blocks_after>
60
+ <observers>
61
+ <campaignmonitor_createsend_addjs>
62
+ <type>singleton</type>
63
+ <class>createsend/config_api</class>
64
+ <method>addJavascriptBlock</method>
65
+ </campaignmonitor_createsend_addjs>
66
+ </observers>
67
+ </controller_action_layout_generate_blocks_after>
68
+ </events>
69
+ </adminhtml>
70
+ <global>
71
+ <models>
72
+ <createsend>
73
+ <class>Campaignmonitor_Createsend_Model</class>
74
+ <resourceModel>createsend_resource</resourceModel>
75
+ </createsend>
76
+ <createsend_resource>
77
+ <class>Campaignmonitor_Createsend_Model_Resource</class>
78
+ <entities>
79
+ <email>
80
+ <table>campaignmonitor_createsend_email</table>
81
+ </email>
82
+ </entities>
83
+ </createsend_resource>
84
+ <core>
85
+ <rewrite>
86
+ <email_template>Campaignmonitor_Createsend_Model_Email_Template</email_template>
87
+ </rewrite>
88
+ </core>
89
+ </models>
90
+ <resources>
91
+ <campaignmonitor_createsend_setup>
92
+ <setup>
93
+ <module>Campaignmonitor_Createsend</module>
94
+ </setup>
95
+ <connection>
96
+ <use>core_setup</use>
97
+ </connection>
98
+ </campaignmonitor_createsend_setup>
99
+ </resources>
100
+ <helpers>
101
+ <createsend>
102
+ <class>Campaignmonitor_Createsend_Helper</class>
103
+ </createsend>
104
+ </helpers>
105
+ <blocks>
106
+ <createsend>
107
+ <class>Campaignmonitor_Createsend_Block</class>
108
+ </createsend>
109
+ </blocks>
110
+ <events>
111
+ <customer_save_before>
112
+ <observers>
113
+ <campaignmonitor_createsend_check_subscription_status>
114
+ <type>singleton</type>
115
+ <class>createsend/customer_observer</class>
116
+ <method>checkSubscriptionStatus</method>
117
+ </campaignmonitor_createsend_check_subscription_status>
118
+ </observers>
119
+ </customer_save_before>
120
+ <customer_delete_before>
121
+ <observers>
122
+ <campaignmonitor_createsend_customer_deleted>
123
+ <type>singleton</type>
124
+ <class>createsend/customer_observer</class>
125
+ <method>customerDeleted</method>
126
+ </campaignmonitor_createsend_customer_deleted>
127
+ </observers>
128
+ </customer_delete_before>
129
+ <sales_order_save_after>
130
+ <observers>
131
+ <campaignmonitor_createsend_check_subscription_status>
132
+ <type>singleton</type>
133
+ <class>createsend/customer_observer</class>
134
+ <method>checkSubscriptionStatus</method>
135
+ </campaignmonitor_createsend_check_subscription_status>
136
+ </observers>
137
+ </sales_order_save_after>
138
+ <wishlist_product_add_after>
139
+ <observers>
140
+ <campaignmonitor_createsend_check_subscription_status>
141
+ <type>singleton</type>
142
+ <class>createsend/customer_observer</class>
143
+ <method>checkSubscriptionStatus</method>
144
+ </campaignmonitor_createsend_check_subscription_status>
145
+ </observers>
146
+ </wishlist_product_add_after>
147
+ <admin_system_config_changed_section_createsend_general>
148
+ <observers>
149
+ <campaignmonitor_createsend_update_webhook>
150
+ <type>singleton</type>
151
+ <class>createsend/api_observer</class>
152
+ <method>checkConfig</method>
153
+ </campaignmonitor_createsend_update_webhook>
154
+ </observers>
155
+ </admin_system_config_changed_section_createsend_general>
156
+ <admin_system_config_changed_section_createsend_customers>
157
+ <observers>
158
+ <campaignmonitor_createsend_create_custom_fields>
159
+ <type>singleton</type>
160
+ <class>createsend/customer_observer</class>
161
+ <method>createCustomFields</method>
162
+ </campaignmonitor_createsend_create_custom_fields>
163
+ </observers>
164
+ </admin_system_config_changed_section_createsend_customers>
165
+ <controller_action_predispatch_adminhtml_newsletter_subscriber_massUnsubscribe>
166
+ <observers>
167
+ <campaignmonitor_createsend_update_user_massaction>
168
+ <type>singleton</type>
169
+ <class>createsend/api_observer</class>
170
+ <method>massUnsubscribeUsers</method>
171
+ </campaignmonitor_createsend_update_user_massaction>
172
+ </observers>
173
+ </controller_action_predispatch_adminhtml_newsletter_subscriber_massUnsubscribe>
174
+ <controller_action_predispatch_adminhtml_newsletter_subscriber_massDelete>
175
+ <observers>
176
+ <campaignmonitor_createsend_update_user_massaction>
177
+ <type>singleton</type>
178
+ <class>createsend/api_observer</class>
179
+ <method>massUnsubscribeUsers</method>
180
+ </campaignmonitor_createsend_update_user_massaction>
181
+ </observers>
182
+ </controller_action_predispatch_adminhtml_newsletter_subscriber_massDelete>
183
+ <controller_action_predispatch_newsletter_subscriber_new>
184
+ <observers>
185
+ <campaignmonitor_createsend_subscribe_new_user>
186
+ <type>singleton</type>
187
+ <class>createsend/api_observer</class>
188
+ <method>subscribeNewUser</method>
189
+ </campaignmonitor_createsend_subscribe_new_user>
190
+ </observers>
191
+ </controller_action_predispatch_newsletter_subscriber_new>
192
+ <!-- Bug fix for Magento newsletter's change_status_at field non-update bug. -->
193
+ <newsletter_subscriber_save_before>
194
+ <observers>
195
+ <campaignmonitor_createsend_newsletter_change_status_update>
196
+ <type>singleton</type>
197
+ <class>createsend/newsletter_observer</class>
198
+ <method>setChangeStatusAt</method>
199
+ </campaignmonitor_createsend_newsletter_change_status_update>
200
+ </observers>
201
+ </newsletter_subscriber_save_before>
202
+ <catalog_product_save_after>
203
+ <observers>
204
+ <campaignmonitor_createsend_product_update>
205
+ <type>singleton</type>
206
+ <class>createsend/product_observer</class>
207
+ <method>updateWishlistFields</method>
208
+ </campaignmonitor_createsend_product_update>
209
+ </observers>
210
+ </catalog_product_save_after>
211
+ </events>
212
+ </global>
213
+ <admin>
214
+ <routers>
215
+ <adminhtml>
216
+ <args>
217
+ <modules>
218
+ <Campaignmonitor_Createsend before="Mage_Adminhtml">Campaignmonitor_Createsend_Adminhtml</Campaignmonitor_Createsend>
219
+ </modules>
220
+ </args>
221
+ </adminhtml>
222
+ </routers>
223
+ </admin>
224
+ <frontend>
225
+ <routers>
226
+ <createsend>
227
+ <use>standard</use>
228
+ <args>
229
+ <module>Campaignmonitor_Createsend</module>
230
+ <frontName>createsend</frontName>
231
+ </args>
232
+ </createsend>
233
+ </routers>
234
+ </frontend>
235
+ <default>
236
+ <createsend_general>
237
+ <api>
238
+ <authentication_method>api_key</authentication_method>
239
+ </api>
240
+ <advanced>
241
+ <logging>1</logging>
242
+ <webhook_enabled>1</webhook_enabled>
243
+ <subscriber_synchronisation_enabled>1</subscriber_synchronisation_enabled>
244
+ <subscriber_synchronisation_resolution_method>timestamp</subscriber_synchronisation_resolution_method>
245
+ <magento_cron_enabled>1</magento_cron_enabled>
246
+ </advanced>
247
+ </createsend_general>
248
+ <createsend_customers>
249
+ <attributes>
250
+ <m_to_cm_attributes>a:19:{i:0;a:1:{s:7:"magento";s:18:"FONTIS-has-account";}i:1;a:1:{s:7:"magento";s:10:"created_in";}i:2;a:1:{s:7:"magento";s:8:"group_id";}i:3;a:1:{s:7:"magento";s:10:"created_at";}i:4;a:1:{s:7:"magento";s:9:"firstname";}i:5;a:1:{s:7:"magento";s:8:"lastname";}i:6;a:1:{s:7:"magento";s:3:"dob";}i:7;a:1:{s:7:"magento";s:6:"gender";}i:8;a:1:{s:7:"magento";s:12:"confirmation";}i:9;a:1:{s:7:"magento";s:10:"website_id";}i:10;a:1:{s:7:"magento";s:8:"store_id";}i:11;a:1:{s:7:"magento";s:32:"FONTIS-sales-average-order-value";}i:12;a:1:{s:7:"magento";s:29:"FONTIS-sales-first-order-date";}i:13;a:1:{s:7:"magento";s:29:"FONTIS-sales-last-order-value";}i:14;a:1:{s:7:"magento";s:28:"FONTIS-sales-last-order-date";}i:15;a:1:{s:7:"magento";s:30:"FONTIS-sales-total-order-value";}i:16;a:1:{s:7:"magento";s:35:"FONTIS-sales-total-number-of-orders";}i:17;a:1:{s:7:"magento";s:45:"FONTIS-sales-total-number-of-products-ordered";}i:18;a:1:{s:7:"magento";s:31:"FONTIS-number-of-wishlist-items";}}</m_to_cm_attributes>
251
+ </attributes>
252
+ <wishlists>
253
+ <max_wishlist_items>1</max_wishlist_items>
254
+ <wishlist_product_attributes>a:4:{i:0;a:1:{s:7:"magento";s:4:"name";}i:1;a:1:{s:7:"magento";s:5:"price";}i:2;a:1:{s:7:"magento";s:17:"short_description";}i:3;a:1:{s:7:"magento";s:3:"sku";}}</wishlist_product_attributes>
255
+ </wishlists>
256
+ </createsend_customers>
257
+ <createsend_transactional>
258
+ <emails>
259
+ <transactional_email_enabled>0</transactional_email_enabled>
260
+ <transactional_email_retention_days>90</transactional_email_retention_days>
261
+ </emails>
262
+ </createsend_transactional>
263
+ </default>
264
+ <crontab>
265
+ <jobs>
266
+ <campaignmonitor_createsend_subscriber_synchronise_initial>
267
+ <schedule>
268
+ <cron_expr>*/5 * * * *</cron_expr>
269
+ </schedule>
270
+ <run>
271
+ <model>createsend/list_initial_cron::runFromMagentoCron</model>
272
+ </run>
273
+ </campaignmonitor_createsend_subscriber_synchronise_initial>
274
+ <campaignmonitor_createsend_subscriber_synchronise>
275
+ <schedule>
276
+ <cron_expr>0 1 * * *</cron_expr>
277
+ </schedule>
278
+ <run>
279
+ <model>createsend/list_cron::runFromMagentoCron</model>
280
+ </run>
281
+ </campaignmonitor_createsend_subscriber_synchronise>
282
+ <campaignmonitor_createsend_email_download>
283
+ <schedule>
284
+ <cron_expr>0 * * * *</cron_expr>
285
+ </schedule>
286
+ <run>
287
+ <model>createsend/email_cron::runFromMagentoCron</model>
288
+ </run>
289
+ </campaignmonitor_createsend_email_download>
290
+ </jobs>
291
+ </crontab>
292
+ </config>
app/code/community/Campaignmonitor/Createsend/etc/system.xml CHANGED
@@ -1,340 +1,340 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /**
4
- * Campaign Monitor Magento Extension
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Open Software License (OSL 3.0)
9
- * that is available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you are unable to obtain it through the world-wide-web, please
12
- * send an email to license@magento.com and you will be sent a copy.
13
- *
14
- * @package Campaignmonitor_Createsend
15
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
16
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
- */
18
- -->
19
- <config>
20
- <tabs>
21
- <campaignmonitor translate="label" module="createsend">
22
- <label>Campaign Monitor</label>
23
- <sort_order>101</sort_order>
24
- </campaignmonitor>
25
- </tabs>
26
-
27
- <sections>
28
- <createsend_general translate="label" module="createsend">
29
- <label>General</label>
30
- <tab>campaignmonitor</tab>
31
- <frontend_type>text</frontend_type>
32
- <sort_order>10</sort_order>
33
- <show_in_default>1</show_in_default>
34
- <show_in_website>1</show_in_website>
35
- <show_in_store>1</show_in_store>
36
- <groups>
37
- <api translate="label">
38
- <label>API</label>
39
- <frontend_type>text</frontend_type>
40
- <sort_order>100</sort_order>
41
- <show_in_default>1</show_in_default>
42
- <show_in_website>1</show_in_website>
43
- <show_in_store>1</show_in_store>
44
- <fields>
45
- <api_key translate="label comment">
46
- <label>API Key</label>
47
- <frontend_type>text</frontend_type>
48
- <backend_model>createsend/config_backend_apikey</backend_model>
49
- <sort_order>100</sort_order>
50
- <show_in_default>1</show_in_default>
51
- <show_in_website>1</show_in_website>
52
- <show_in_store>1</show_in_store>
53
- <comment><![CDATA[If you have multiple clients, you can find your client's API key <a href="https://www.campaignmonitor.com/api/getting-started/?#clientid" target="_blank">here</a>.<br />
54
- If you're sending for yourself, you can find your own API key <a href="http://help.campaignmonitor.com/topic.aspx?t=1240" target="_blank">here</a>.
55
- <div id="createsend_api_key_error_message"></div>]]></comment>
56
- </api_key>
57
- <api_client_id translate="label comment">
58
- <label>Select your Campaign Monitor Client</label>
59
- <frontend_type>select</frontend_type>
60
- <backend_model>createsend/config_backend_listid</backend_model>
61
- <source_model>createsend/config_clientSelection</source_model>
62
- <sort_order>110</sort_order>
63
- <show_in_default>1</show_in_default>
64
- <show_in_website>1</show_in_website>
65
- <show_in_store>1</show_in_store>
66
- </api_client_id>
67
- <list_id translate="label comment">
68
- <label>Select a List</label>
69
- <frontend_type>select</frontend_type>
70
- <source_model>createsend/config_listSelection</source_model>
71
- <backend_model>createsend/config_backend_listid</backend_model>
72
- <sort_order>120</sort_order>
73
- <show_in_default>1</show_in_default>
74
- <show_in_website>1</show_in_website>
75
- <show_in_store>1</show_in_store>
76
- <comment>The Campaign Monitor subscriber list your Magento users will subscribe to or unsubscribe from.</comment>
77
- </list_id>
78
- <new_list_name translate="label comment">
79
- <label>Create a new list in Campaign Monitor</label>
80
- <frontend_type>text</frontend_type>
81
- <sort_order>130</sort_order>
82
- <show_in_default>1</show_in_default>
83
- <show_in_website>1</show_in_website>
84
- <show_in_store>1</show_in_store>
85
- <depends><list_id>NEW_LIST</list_id></depends>
86
- <comment>Name this new list</comment>
87
- </new_list_name>
88
-
89
- </fields>
90
- </api>
91
- <advanced translate="label">
92
- <label>Advanced</label>
93
- <frontend_type>text</frontend_type>
94
- <sort_order>200</sort_order>
95
- <show_in_default>1</show_in_default>
96
- <show_in_website>1</show_in_website>
97
- <show_in_store>1</show_in_store>
98
- <fields>
99
- <api_test_button translate="label comment">
100
- <label>Test API</label>
101
- <frontend_type>button</frontend_type>
102
- <frontend_model>campaignmonitor_createsend_block_testApi</frontend_model>
103
- <sort_order>60</sort_order>
104
- <show_in_default>1</show_in_default>
105
- <show_in_website>1</show_in_website>
106
- <show_in_store>1</show_in_store>
107
- <comment>Test your credentials are correct and can connect to Campaign Monitor's API. Make sure to click Save Config after entering your API key before testing.</comment>
108
- </api_test_button>
109
- <create_segment_button translate="label">
110
- <label>Create Example Segments</label>
111
- <frontend_type>button</frontend_type>
112
- <frontend_model>campaignmonitor_createsend_block_createExampleSegments</frontend_model>
113
- <sort_order>70</sort_order>
114
- <show_in_default>1</show_in_default>
115
- <show_in_website>1</show_in_website>
116
- <show_in_store>1</show_in_store>
117
- <comment>Create a set of Campaign Monitor example segments to target sub-groups of subscribers based on conditions.</comment>
118
- </create_segment_button>
119
- <logging translate="label comment">
120
- <label>Enable Logging</label>
121
- <frontend_type>select</frontend_type>
122
- <source_model>adminhtml/system_config_source_yesno</source_model>
123
- <sort_order>80</sort_order>
124
- <show_in_default>1</show_in_default>
125
- <show_in_website>0</show_in_website>
126
- <show_in_store>0</show_in_store>
127
- <comment>Log Campaign Monitor extension information and API requests. Requires Magento logging to be enabled.</comment>
128
- </logging>
129
- <webhook_enabled translate="label comment">
130
- <label>Enable Webhooks</label>
131
- <frontend_type>select</frontend_type>
132
- <source_model>adminhtml/system_config_source_yesno</source_model>
133
- <sort_order>100</sort_order>
134
- <show_in_default>1</show_in_default>
135
- <show_in_website>1</show_in_website>
136
- <show_in_store>1</show_in_store>
137
- <comment>Synchronize subscribes and unsubscribes performed in Campaign Monitor with Magento.</comment>
138
- </webhook_enabled>
139
- <subscriber_synchronisation_enabled translate="label comment">
140
- <label>Enable Batch Subscriber Synchronization</label>
141
- <frontend_type>select</frontend_type>
142
- <source_model>adminhtml/system_config_source_yesno</source_model>
143
- <sort_order>200</sort_order>
144
- <show_in_default>1</show_in_default>
145
- <show_in_website>1</show_in_website>
146
- <show_in_store>1</show_in_store>
147
- <comment>If 'Yes', perform a nightly batch synchronization of list subscribers.</comment>
148
- </subscriber_synchronisation_enabled>
149
- <subscriber_synchronisation_resolution_method translate="label comment">
150
- <label>Subscription Synchronization Conflict Resolution Method</label>
151
- <frontend_type>select</frontend_type>
152
- <source_model>campaignmonitor_createsend_model_config_ConflictResolutionMethod</source_model>
153
- <sort_order>210</sort_order>
154
- <show_in_default>1</show_in_default>
155
- <show_in_website>1</show_in_website>
156
- <show_in_store>1</show_in_store>
157
- <depends><subscriber_synchronisation_enabled>1</subscriber_synchronisation_enabled></depends>
158
- <comment><![CDATA[Set to "Timestamp" to resolve subscription status conflicts by using the latest timestamp found in either Campaign Monitor or Magento.
159
- <br />
160
- Set to "Preferred Source" to resolve subscription status conflicts by choosing Campaign Monitor or Magento.]]></comment>
161
- </subscriber_synchronisation_resolution_method>
162
- <subscriber_synchronisation_preferred_source translate="label comment">
163
- <label>Preferred Source</label>
164
- <frontend_type>select</frontend_type>
165
- <source_model>campaignmonitor_createsend_model_config_SubscriptionSources</source_model>
166
- <sort_order>220</sort_order>
167
- <show_in_default>1</show_in_default>
168
- <show_in_website>1</show_in_website>
169
- <show_in_store>1</show_in_store>
170
- <depends>
171
- <subscriber_synchronisation_enabled>1</subscriber_synchronisation_enabled>
172
- <subscriber_synchronisation_resolution_method>source</subscriber_synchronisation_resolution_method>
173
- </depends>
174
- </subscriber_synchronisation_preferred_source>
175
- <magento_cron_enabled translate="label comment">
176
- <label>Use Magento cron</label>
177
- <frontend_type>select</frontend_type>
178
- <source_model>adminhtml/system_config_source_yesno</source_model>
179
- <sort_order>300</sort_order>
180
- <show_in_default>1</show_in_default>
181
- <show_in_website>0</show_in_website>
182
- <show_in_store>0</show_in_store>
183
- <comment>Perform subscriber synchronization and email retrieval using Magento's cron system. If set to "No," a system cron job will need to be set up.</comment>
184
- </magento_cron_enabled>
185
- <create_segment_button translate="label comment">
186
- <label>Create Example Segments</label>
187
- <frontend_type>button</frontend_type>
188
- <frontend_model>campaignmonitor_createsend_block_createExampleSegments</frontend_model>
189
- <sort_order>700</sort_order>
190
- <show_in_default>1</show_in_default>
191
- <show_in_website>1</show_in_website>
192
- <show_in_store>1</show_in_store>
193
- <comment>Create a set of Campaign Monitor example segments to target sub-groups of subscribers based on purchasing habits.</comment>
194
- </create_segment_button>
195
- </fields>
196
- </advanced>
197
- <debug translate="label">
198
- <label>Developer</label>
199
- <sort_order>500</sort_order>
200
- <show_in_default>1</show_in_default>
201
- <show_in_website>1</show_in_website>
202
- <show_in_store>1</show_in_store>
203
- <fields>
204
- <version translate="label">
205
- <label>Version</label>
206
- <frontend_type>text</frontend_type>
207
- <frontend_model>Campaignmonitor_Createsend_Block_Version</frontend_model>
208
- <sort_order>0</sort_order>
209
- <show_in_default>1</show_in_default>
210
- <show_in_website>1</show_in_website>
211
- <show_in_store>1</show_in_store>
212
- </version>
213
- <available_logs translate="label comment">
214
- <label>Log Files</label>
215
- <frontend_type>select</frontend_type>
216
- <source_model>createsend/config_backend_source_files</source_model>
217
- <sort_order>100</sort_order>
218
- <show_in_default>1</show_in_default>
219
- <show_in_website>1</show_in_website>
220
- <show_in_store>1</show_in_store>
221
- <comment>Select a file to view. The var/log folder needs to be readable</comment>
222
- </available_logs>
223
- <log_content translate="label comment">
224
- <label>Log Content</label>
225
- <frontend_type>textarea</frontend_type>
226
- <backend_model>campaignmonitor_createsend_block_log_reader</backend_model>
227
- <frontend_model>campaignmonitor_createsend_block_log_view</frontend_model>
228
- <sort_order>200</sort_order>
229
- <show_in_default>1</show_in_default>
230
- <show_in_website>1</show_in_website>
231
- <show_in_store>1</show_in_store>
232
- <comment>Select a file then hit Save Config button to see the log content</comment>
233
- </log_content>
234
- </fields>
235
- </debug>
236
- </groups>
237
- </createsend_general>
238
- <createsend_customers translate="label" module="createsend">
239
- <label>Customers</label>
240
- <tab>campaignmonitor</tab>
241
- <frontend_type>text</frontend_type>
242
- <sort_order>20</sort_order>
243
- <show_in_default>1</show_in_default>
244
- <show_in_website>1</show_in_website>
245
- <show_in_store>1</show_in_store>
246
- <groups>
247
- <attributes translate="label">
248
- <label>Attributes</label>
249
- <frontend_type>text</frontend_type>
250
- <sort_order>100</sort_order>
251
- <show_in_default>1</show_in_default>
252
- <show_in_website>1</show_in_website>
253
- <show_in_store>1</show_in_store>
254
- <fields>
255
- <m_to_cm_attributes translate="label comment">
256
- <label>Custom Field Mapping</label>
257
- <frontend_model>campaignmonitor_createsend_block_linkedattributes</frontend_model>
258
- <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
259
- <sort_order>100</sort_order>
260
- <show_in_default>1</show_in_default>
261
- <show_in_website>1</show_in_website>
262
- <show_in_store>1</show_in_store>
263
- </m_to_cm_attributes>
264
- </fields>
265
- </attributes>
266
- <wishlists translate="label">
267
- <label>Wishlists</label>
268
- <frontend_type>text</frontend_type>
269
- <sort_order>200</sort_order>
270
- <show_in_default>1</show_in_default>
271
- <show_in_website>1</show_in_website>
272
- <show_in_store>1</show_in_store>
273
- <fields>
274
- <max_wishlist_items translate="label comment">
275
- <label>Number of wishlist products to include</label>
276
- <frontend_type>text</frontend_type>
277
- <sort_order>100</sort_order>
278
- <show_in_default>1</show_in_default>
279
- <show_in_website>1</show_in_website>
280
- <show_in_store>1</show_in_store>
281
- <validate>validate-zero-or-greater</validate>
282
- <comment>Sets the maximum number of products from a customer's wishlist to send to Campaign Monitor's custom fields. Set to 0 to not send any wishlist data.</comment>
283
- </max_wishlist_items>
284
- <wishlist_product_attributes translate="label">
285
- <label>Custom Field Mapping</label>
286
- <frontend_model>campaignmonitor_createsend_block_wishlistattributes</frontend_model>
287
- <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
288
- <sort_order>200</sort_order>
289
- <show_in_default>1</show_in_default>
290
- <show_in_website>1</show_in_website>
291
- <show_in_store>1</show_in_store>
292
- </wishlist_product_attributes>
293
- </fields>
294
- </wishlists>
295
- </groups>
296
- </createsend_customers>
297
- <createsend_transactional translate="label" module="createsend">
298
- <label>Transactional</label>
299
- <tab>campaignmonitor</tab>
300
- <frontend_type>text</frontend_type>
301
- <sort_order>30</sort_order>
302
- <show_in_default>1</show_in_default>
303
- <show_in_website>1</show_in_website>
304
- <show_in_store>1</show_in_store>
305
- <groups>
306
- <emails translate="label">
307
- <label>Transactional Emails</label>
308
- <frontend_type>text</frontend_type>
309
- <sort_order>100</sort_order>
310
- <show_in_default>1</show_in_default>
311
- <show_in_website>1</show_in_website>
312
- <show_in_store>1</show_in_store>
313
- <fields>
314
- <transactional_email_enabled translate="label comment">
315
- <label>Enable Transactional Emails</label>
316
- <frontend_type>select</frontend_type>
317
- <source_model>adminhtml/system_config_source_yesno</source_model>
318
- <sort_order>100</sort_order>
319
- <show_in_default>1</show_in_default>
320
- <show_in_website>1</show_in_website>
321
- <show_in_store>1</show_in_store>
322
- <comment>Send Magento generated transactional emails via Campaign Monitor. You will be able to view recently sent emails using the Magento Admin Panel.</comment>
323
- </transactional_email_enabled>
324
- <transactional_email_retention_days translate="label comment">
325
- <label>Email Data Retention (days)</label>
326
- <frontend_type>text</frontend_type>
327
- <sort_order>200</sort_order>
328
- <show_in_default>1</show_in_default>
329
- <show_in_website>1</show_in_website>
330
- <show_in_store>1</show_in_store>
331
- <validate>validate-zero-or-greater</validate>
332
- <comment>Number of days to retain email data in Magento. This will determine how long you are able to view emails in the Magento Admin Panel.</comment>
333
- <depends><transactional_email_enabled>1</transactional_email_enabled></depends>
334
- </transactional_email_retention_days>
335
- </fields>
336
- </emails>
337
- </groups>
338
- </createsend_transactional>
339
- </sections>
340
- </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Campaign Monitor Magento Extension
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you are unable to obtain it through the world-wide-web, please
12
+ * send an email to license@magento.com and you will be sent a copy.
13
+ *
14
+ * @package Campaignmonitor_Createsend
15
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ -->
19
+ <config>
20
+ <tabs>
21
+ <campaignmonitor translate="label" module="createsend">
22
+ <label>Campaign Monitor</label>
23
+ <sort_order>101</sort_order>
24
+ </campaignmonitor>
25
+ </tabs>
26
+
27
+ <sections>
28
+ <createsend_general translate="label" module="createsend">
29
+ <label>General</label>
30
+ <tab>campaignmonitor</tab>
31
+ <frontend_type>text</frontend_type>
32
+ <sort_order>10</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>1</show_in_website>
35
+ <show_in_store>1</show_in_store>
36
+ <groups>
37
+ <api translate="label">
38
+ <label>API</label>
39
+ <frontend_type>text</frontend_type>
40
+ <sort_order>100</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ <fields>
45
+ <api_key translate="label comment">
46
+ <label>API Key</label>
47
+ <frontend_type>text</frontend_type>
48
+ <backend_model>createsend/config_backend_apikey</backend_model>
49
+ <sort_order>100</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ <comment><![CDATA[If you have multiple clients, you can find your client's API key <a href="https://www.campaignmonitor.com/api/getting-started/?#clientid" target="_blank">here</a>.<br />
54
+ If you're sending for yourself, you can find your own API key <a href="http://help.campaignmonitor.com/topic.aspx?t=1240" target="_blank">here</a>.
55
+ <div id="createsend_api_key_error_message"></div>]]></comment>
56
+ </api_key>
57
+ <api_client_id translate="label comment">
58
+ <label>Select your Campaign Monitor Client</label>
59
+ <frontend_type>select</frontend_type>
60
+ <backend_model>createsend/config_backend_listid</backend_model>
61
+ <source_model>createsend/config_clientSelection</source_model>
62
+ <sort_order>110</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ </api_client_id>
67
+ <list_id translate="label comment">
68
+ <label>Select a List</label>
69
+ <frontend_type>select</frontend_type>
70
+ <source_model>createsend/config_listSelection</source_model>
71
+ <backend_model>createsend/config_backend_listid</backend_model>
72
+ <sort_order>120</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>1</show_in_store>
76
+ <comment>The Campaign Monitor subscriber list your Magento users will subscribe to or unsubscribe from.</comment>
77
+ </list_id>
78
+ <new_list_name translate="label comment">
79
+ <label>Create a new list in Campaign Monitor</label>
80
+ <frontend_type>text</frontend_type>
81
+ <sort_order>130</sort_order>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>1</show_in_website>
84
+ <show_in_store>1</show_in_store>
85
+ <depends><list_id>NEW_LIST</list_id></depends>
86
+ <comment>Name this new list</comment>
87
+ </new_list_name>
88
+
89
+ </fields>
90
+ </api>
91
+ <advanced translate="label">
92
+ <label>Advanced</label>
93
+ <frontend_type>text</frontend_type>
94
+ <sort_order>200</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ <fields>
99
+ <api_test_button translate="label comment">
100
+ <label>Test API</label>
101
+ <frontend_type>button</frontend_type>
102
+ <frontend_model>campaignmonitor_createsend_block_testApi</frontend_model>
103
+ <sort_order>60</sort_order>
104
+ <show_in_default>1</show_in_default>
105
+ <show_in_website>1</show_in_website>
106
+ <show_in_store>1</show_in_store>
107
+ <comment>Test your credentials are correct and can connect to Campaign Monitor's API. Make sure to click Save Config after entering your API key before testing.</comment>
108
+ </api_test_button>
109
+ <create_segment_button translate="label">
110
+ <label>Create Example Segments</label>
111
+ <frontend_type>button</frontend_type>
112
+ <frontend_model>campaignmonitor_createsend_block_createExampleSegments</frontend_model>
113
+ <sort_order>70</sort_order>
114
+ <show_in_default>1</show_in_default>
115
+ <show_in_website>1</show_in_website>
116
+ <show_in_store>1</show_in_store>
117
+ <comment>Create a set of Campaign Monitor example segments to target sub-groups of subscribers based on conditions.</comment>
118
+ </create_segment_button>
119
+ <logging translate="label comment">
120
+ <label>Enable Logging</label>
121
+ <frontend_type>select</frontend_type>
122
+ <source_model>adminhtml/system_config_source_yesno</source_model>
123
+ <sort_order>80</sort_order>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>0</show_in_website>
126
+ <show_in_store>0</show_in_store>
127
+ <comment>Log Campaign Monitor extension information and API requests. Requires Magento logging to be enabled.</comment>
128
+ </logging>
129
+ <webhook_enabled translate="label comment">
130
+ <label>Enable Webhooks</label>
131
+ <frontend_type>select</frontend_type>
132
+ <source_model>adminhtml/system_config_source_yesno</source_model>
133
+ <sort_order>100</sort_order>
134
+ <show_in_default>1</show_in_default>
135
+ <show_in_website>1</show_in_website>
136
+ <show_in_store>1</show_in_store>
137
+ <comment>Synchronize subscribes and unsubscribes performed in Campaign Monitor with Magento.</comment>
138
+ </webhook_enabled>
139
+ <subscriber_synchronisation_enabled translate="label comment">
140
+ <label>Enable Batch Subscriber Synchronization</label>
141
+ <frontend_type>select</frontend_type>
142
+ <source_model>adminhtml/system_config_source_yesno</source_model>
143
+ <sort_order>200</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>1</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ <comment>If 'Yes', perform a nightly batch synchronization of list subscribers.</comment>
148
+ </subscriber_synchronisation_enabled>
149
+ <subscriber_synchronisation_resolution_method translate="label comment">
150
+ <label>Subscription Synchronization Conflict Resolution Method</label>
151
+ <frontend_type>select</frontend_type>
152
+ <source_model>campaignmonitor_createsend_model_config_ConflictResolutionMethod</source_model>
153
+ <sort_order>210</sort_order>
154
+ <show_in_default>1</show_in_default>
155
+ <show_in_website>1</show_in_website>
156
+ <show_in_store>1</show_in_store>
157
+ <depends><subscriber_synchronisation_enabled>1</subscriber_synchronisation_enabled></depends>
158
+ <comment><![CDATA[Set to "Timestamp" to resolve subscription status conflicts by using the latest timestamp found in either Campaign Monitor or Magento.
159
+ <br />
160
+ Set to "Preferred Source" to resolve subscription status conflicts by choosing Campaign Monitor or Magento.]]></comment>
161
+ </subscriber_synchronisation_resolution_method>
162
+ <subscriber_synchronisation_preferred_source translate="label comment">
163
+ <label>Preferred Source</label>
164
+ <frontend_type>select</frontend_type>
165
+ <source_model>campaignmonitor_createsend_model_config_SubscriptionSources</source_model>
166
+ <sort_order>220</sort_order>
167
+ <show_in_default>1</show_in_default>
168
+ <show_in_website>1</show_in_website>
169
+ <show_in_store>1</show_in_store>
170
+ <depends>
171
+ <subscriber_synchronisation_enabled>1</subscriber_synchronisation_enabled>
172
+ <subscriber_synchronisation_resolution_method>source</subscriber_synchronisation_resolution_method>
173
+ </depends>
174
+ </subscriber_synchronisation_preferred_source>
175
+ <magento_cron_enabled translate="label comment">
176
+ <label>Use Magento cron</label>
177
+ <frontend_type>select</frontend_type>
178
+ <source_model>adminhtml/system_config_source_yesno</source_model>
179
+ <sort_order>300</sort_order>
180
+ <show_in_default>1</show_in_default>
181
+ <show_in_website>0</show_in_website>
182
+ <show_in_store>0</show_in_store>
183
+ <comment>Perform subscriber synchronization and email retrieval using Magento's cron system. If set to "No," a system cron job will need to be set up.</comment>
184
+ </magento_cron_enabled>
185
+ <create_segment_button translate="label comment">
186
+ <label>Create Example Segments</label>
187
+ <frontend_type>button</frontend_type>
188
+ <frontend_model>campaignmonitor_createsend_block_createExampleSegments</frontend_model>
189
+ <sort_order>700</sort_order>
190
+ <show_in_default>1</show_in_default>
191
+ <show_in_website>1</show_in_website>
192
+ <show_in_store>1</show_in_store>
193
+ <comment>Create a set of Campaign Monitor example segments to target sub-groups of subscribers based on purchasing habits.</comment>
194
+ </create_segment_button>
195
+ </fields>
196
+ </advanced>
197
+ <debug translate="label">
198
+ <label>Developer</label>
199
+ <sort_order>500</sort_order>
200
+ <show_in_default>1</show_in_default>
201
+ <show_in_website>1</show_in_website>
202
+ <show_in_store>1</show_in_store>
203
+ <fields>
204
+ <version translate="label">
205
+ <label>Version</label>
206
+ <frontend_type>text</frontend_type>
207
+ <frontend_model>Campaignmonitor_Createsend_Block_Version</frontend_model>
208
+ <sort_order>0</sort_order>
209
+ <show_in_default>1</show_in_default>
210
+ <show_in_website>1</show_in_website>
211
+ <show_in_store>1</show_in_store>
212
+ </version>
213
+ <available_logs translate="label comment">
214
+ <label>Log Files</label>
215
+ <frontend_type>select</frontend_type>
216
+ <source_model>createsend/config_backend_source_files</source_model>
217
+ <sort_order>100</sort_order>
218
+ <show_in_default>1</show_in_default>
219
+ <show_in_website>1</show_in_website>
220
+ <show_in_store>1</show_in_store>
221
+ <comment>Select a file to view. The var/log folder needs to be readable</comment>
222
+ </available_logs>
223
+ <log_content translate="label comment">
224
+ <label>Log Content</label>
225
+ <frontend_type>textarea</frontend_type>
226
+ <backend_model>campaignmonitor_createsend_block_log_reader</backend_model>
227
+ <frontend_model>campaignmonitor_createsend_block_log_view</frontend_model>
228
+ <sort_order>200</sort_order>
229
+ <show_in_default>1</show_in_default>
230
+ <show_in_website>1</show_in_website>
231
+ <show_in_store>1</show_in_store>
232
+ <comment>Select a file then hit Save Config button to see the log content</comment>
233
+ </log_content>
234
+ </fields>
235
+ </debug>
236
+ </groups>
237
+ </createsend_general>
238
+ <createsend_customers translate="label" module="createsend">
239
+ <label>Customers</label>
240
+ <tab>campaignmonitor</tab>
241
+ <frontend_type>text</frontend_type>
242
+ <sort_order>20</sort_order>
243
+ <show_in_default>1</show_in_default>
244
+ <show_in_website>1</show_in_website>
245
+ <show_in_store>1</show_in_store>
246
+ <groups>
247
+ <attributes translate="label">
248
+ <label>Attributes</label>
249
+ <frontend_type>text</frontend_type>
250
+ <sort_order>100</sort_order>
251
+ <show_in_default>1</show_in_default>
252
+ <show_in_website>1</show_in_website>
253
+ <show_in_store>1</show_in_store>
254
+ <fields>
255
+ <m_to_cm_attributes translate="label comment">
256
+ <label>Custom Field Mapping</label>
257
+ <frontend_model>campaignmonitor_createsend_block_linkedattributes</frontend_model>
258
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
259
+ <sort_order>100</sort_order>
260
+ <show_in_default>1</show_in_default>
261
+ <show_in_website>1</show_in_website>
262
+ <show_in_store>1</show_in_store>
263
+ </m_to_cm_attributes>
264
+ </fields>
265
+ </attributes>
266
+ <wishlists translate="label">
267
+ <label>Wishlists</label>
268
+ <frontend_type>text</frontend_type>
269
+ <sort_order>200</sort_order>
270
+ <show_in_default>1</show_in_default>
271
+ <show_in_website>1</show_in_website>
272
+ <show_in_store>1</show_in_store>
273
+ <fields>
274
+ <max_wishlist_items translate="label comment">
275
+ <label>Number of wishlist products to include</label>
276
+ <frontend_type>text</frontend_type>
277
+ <sort_order>100</sort_order>
278
+ <show_in_default>1</show_in_default>
279
+ <show_in_website>1</show_in_website>
280
+ <show_in_store>1</show_in_store>
281
+ <validate>validate-zero-or-greater</validate>
282
+ <comment>Sets the maximum number of products from a customer's wishlist to send to Campaign Monitor's custom fields. Set to 0 to not send any wishlist data.</comment>
283
+ </max_wishlist_items>
284
+ <wishlist_product_attributes translate="label">
285
+ <label>Custom Field Mapping</label>
286
+ <frontend_model>campaignmonitor_createsend_block_wishlistattributes</frontend_model>
287
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
288
+ <sort_order>200</sort_order>
289
+ <show_in_default>1</show_in_default>
290
+ <show_in_website>1</show_in_website>
291
+ <show_in_store>1</show_in_store>
292
+ </wishlist_product_attributes>
293
+ </fields>
294
+ </wishlists>
295
+ </groups>
296
+ </createsend_customers>
297
+ <createsend_transactional translate="label" module="createsend">
298
+ <label>Transactional</label>
299
+ <tab>campaignmonitor</tab>
300
+ <frontend_type>text</frontend_type>
301
+ <sort_order>30</sort_order>
302
+ <show_in_default>1</show_in_default>
303
+ <show_in_website>1</show_in_website>
304
+ <show_in_store>1</show_in_store>
305
+ <groups>
306
+ <emails translate="label">
307
+ <label>Transactional Emails</label>
308
+ <frontend_type>text</frontend_type>
309
+ <sort_order>100</sort_order>
310
+ <show_in_default>1</show_in_default>
311
+ <show_in_website>1</show_in_website>
312
+ <show_in_store>1</show_in_store>
313
+ <fields>
314
+ <transactional_email_enabled translate="label comment">
315
+ <label>Enable Transactional Emails</label>
316
+ <frontend_type>select</frontend_type>
317
+ <source_model>adminhtml/system_config_source_yesno</source_model>
318
+ <sort_order>100</sort_order>
319
+ <show_in_default>1</show_in_default>
320
+ <show_in_website>1</show_in_website>
321
+ <show_in_store>1</show_in_store>
322
+ <comment>Send Magento generated transactional emails via Campaign Monitor. You will be able to view recently sent emails using the Magento Admin Panel.</comment>
323
+ </transactional_email_enabled>
324
+ <transactional_email_retention_days translate="label comment">
325
+ <label>Email Data Retention (days)</label>
326
+ <frontend_type>text</frontend_type>
327
+ <sort_order>200</sort_order>
328
+ <show_in_default>1</show_in_default>
329
+ <show_in_website>1</show_in_website>
330
+ <show_in_store>1</show_in_store>
331
+ <validate>validate-zero-or-greater</validate>
332
+ <comment>Number of days to retain email data in Magento. This will determine how long you are able to view emails in the Magento Admin Panel.</comment>
333
+ <depends><transactional_email_enabled>1</transactional_email_enabled></depends>
334
+ </transactional_email_retention_days>
335
+ </fields>
336
+ </emails>
337
+ </groups>
338
+ </createsend_transactional>
339
+ </sections>
340
+ </config>
app/code/community/Campaignmonitor/Createsend/sql/campaignmonitor_createsend_setup/install-1.0.0.php CHANGED
@@ -1,145 +1,145 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
- try {
18
- // turn on extra customer fields
19
- Mage::getConfig()->saveConfig('customer/address/dob_show', 'opt', 'default', 0);
20
- Mage::getConfig()->saveConfig('customer/address/gender_show', 'opt', 'default', 0);
21
- } catch (Exception $e){
22
- Mage::log($e->getMessage());
23
- }
24
- /** @var $this Mage_Core_Model_Resource_Setup */
25
- $this->startSetup();
26
- $connection = $this->getConnection();
27
-
28
- $emailTableName = $this->getTable("createsend/email");
29
-
30
- $emailTable = $connection->newTable($emailTableName)
31
- ->addColumn('email_id',
32
- Varien_Db_Ddl_Table::TYPE_INTEGER,
33
- null,
34
- array(
35
- 'unsigned' => true,
36
- 'nullable' => false,
37
- 'primary' => true,
38
- 'identity' => true,
39
- ),
40
- 'Email ID'
41
- )
42
- ->addColumn(
43
- 'message_id',
44
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
45
- 64,
46
- array(
47
- 'nullable' => false,
48
- ),
49
- 'Message ID'
50
- )
51
- ->addColumn(
52
- 'status',
53
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
54
- 64,
55
- array(
56
- 'nullable' => false,
57
- ),
58
- 'Status'
59
- )
60
- ->addColumn(
61
- 'sent_at',
62
- Varien_Db_Ddl_Table::TYPE_DATETIME,
63
- null,
64
- array(
65
- 'nullable' => true,
66
- 'default' => null,
67
- ),
68
- 'Date Sent'
69
- )
70
- ->addColumn(
71
- 'recipient',
72
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
73
- 1024,
74
- array(
75
- 'nullable' => false,
76
- ),
77
- 'Recipient'
78
- )
79
- ->addColumn(
80
- 'sender',
81
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
82
- 1024,
83
- array(
84
- 'nullable' => false,
85
- ),
86
- 'Sender'
87
- )
88
- ->addColumn(
89
- 'subject',
90
- Varien_Db_Ddl_Table::TYPE_TEXT,
91
- null,
92
- array(
93
- 'nullable' => false,
94
- ),
95
- 'Subject'
96
- )
97
- ->addColumn(
98
- 'total_opens',
99
- Varien_Db_Ddl_Table::TYPE_INTEGER,
100
- null,
101
- array(
102
- 'nullable' => false,
103
- ),
104
- 'Total Opens'
105
- )
106
- ->addColumn(
107
- 'total_clicks',
108
- Varien_Db_Ddl_Table::TYPE_INTEGER,
109
- null,
110
- array(
111
- 'nullable' => false,
112
- ),
113
- 'Total Clicks'
114
- )
115
- ->addColumn(
116
- 'can_be_resent',
117
- Varien_Db_Ddl_Table::TYPE_BOOLEAN,
118
- null,
119
- array(
120
- 'nullable' => false,
121
- ),
122
- 'Can be Resent'
123
- )
124
- ->addColumn(
125
- 'scope',
126
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
127
- 8,
128
- array(
129
- 'nullable' => false,
130
- ),
131
- 'Scope'
132
- )
133
- ->addColumn(
134
- 'scope_id',
135
- Varien_Db_Ddl_Table::TYPE_INTEGER,
136
- 11,
137
- array(
138
- 'nullable' => false,
139
- ),
140
- 'Scope ID'
141
- );
142
-
143
- $connection->createTable($emailTable);
144
-
145
- $this->endSetup();
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ try {
18
+ // turn on extra customer fields
19
+ Mage::getConfig()->saveConfig('customer/address/dob_show', 'opt', 'default', 0);
20
+ Mage::getConfig()->saveConfig('customer/address/gender_show', 'opt', 'default', 0);
21
+ } catch (Exception $e){
22
+ Mage::log($e->getMessage());
23
+ }
24
+ /** @var $this Mage_Core_Model_Resource_Setup */
25
+ $this->startSetup();
26
+ $connection = $this->getConnection();
27
+
28
+ $emailTableName = $this->getTable("createsend/email");
29
+
30
+ $emailTable = $connection->newTable($emailTableName)
31
+ ->addColumn('email_id',
32
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
33
+ null,
34
+ array(
35
+ 'unsigned' => true,
36
+ 'nullable' => false,
37
+ 'primary' => true,
38
+ 'identity' => true,
39
+ ),
40
+ 'Email ID'
41
+ )
42
+ ->addColumn(
43
+ 'message_id',
44
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
45
+ 64,
46
+ array(
47
+ 'nullable' => false,
48
+ ),
49
+ 'Message ID'
50
+ )
51
+ ->addColumn(
52
+ 'status',
53
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
54
+ 64,
55
+ array(
56
+ 'nullable' => false,
57
+ ),
58
+ 'Status'
59
+ )
60
+ ->addColumn(
61
+ 'sent_at',
62
+ Varien_Db_Ddl_Table::TYPE_DATETIME,
63
+ null,
64
+ array(
65
+ 'nullable' => true,
66
+ 'default' => null,
67
+ ),
68
+ 'Date Sent'
69
+ )
70
+ ->addColumn(
71
+ 'recipient',
72
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
73
+ 1024,
74
+ array(
75
+ 'nullable' => false,
76
+ ),
77
+ 'Recipient'
78
+ )
79
+ ->addColumn(
80
+ 'sender',
81
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
82
+ 1024,
83
+ array(
84
+ 'nullable' => false,
85
+ ),
86
+ 'Sender'
87
+ )
88
+ ->addColumn(
89
+ 'subject',
90
+ Varien_Db_Ddl_Table::TYPE_TEXT,
91
+ null,
92
+ array(
93
+ 'nullable' => false,
94
+ ),
95
+ 'Subject'
96
+ )
97
+ ->addColumn(
98
+ 'total_opens',
99
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
100
+ null,
101
+ array(
102
+ 'nullable' => false,
103
+ ),
104
+ 'Total Opens'
105
+ )
106
+ ->addColumn(
107
+ 'total_clicks',
108
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
109
+ null,
110
+ array(
111
+ 'nullable' => false,
112
+ ),
113
+ 'Total Clicks'
114
+ )
115
+ ->addColumn(
116
+ 'can_be_resent',
117
+ Varien_Db_Ddl_Table::TYPE_BOOLEAN,
118
+ null,
119
+ array(
120
+ 'nullable' => false,
121
+ ),
122
+ 'Can be Resent'
123
+ )
124
+ ->addColumn(
125
+ 'scope',
126
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
127
+ 8,
128
+ array(
129
+ 'nullable' => false,
130
+ ),
131
+ 'Scope'
132
+ )
133
+ ->addColumn(
134
+ 'scope_id',
135
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
136
+ 11,
137
+ array(
138
+ 'nullable' => false,
139
+ ),
140
+ 'Scope ID'
141
+ );
142
+
143
+ $connection->createTable($emailTable);
144
+
145
+ $this->endSetup();
app/code/community/Campaignmonitor/Createsend/sql/campaignmonitor_createsend_setup/install-1.0.1.php CHANGED
@@ -1,145 +1,145 @@
1
- <?php
2
- /**
3
- * Campaign Monitor Magento Extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain it through the world-wide-web, please
11
- * send an email to license@magento.com and you will be sent a copy.
12
- *
13
- * @package Campaignmonitor_Createsend
14
- * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
- */
17
- try {
18
- // turn on extra customer fields
19
- Mage::getConfig()->saveConfig('customer/address/dob_show', 'opt', 'default', 0);
20
- Mage::getConfig()->saveConfig('customer/address/gender_show', 'opt', 'default', 0);
21
- } catch (Exception $e){
22
- Mage::log($e->getMessage());
23
- }
24
- /** @var $this Mage_Core_Model_Resource_Setup */
25
- $this->startSetup();
26
- $connection = $this->getConnection();
27
-
28
- $emailTableName = $this->getTable("createsend/email");
29
-
30
- $emailTable = $connection->newTable($emailTableName)
31
- ->addColumn('email_id',
32
- Varien_Db_Ddl_Table::TYPE_INTEGER,
33
- null,
34
- array(
35
- 'unsigned' => true,
36
- 'nullable' => false,
37
- 'primary' => true,
38
- 'identity' => true,
39
- ),
40
- 'Email ID'
41
- )
42
- ->addColumn(
43
- 'message_id',
44
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
45
- 64,
46
- array(
47
- 'nullable' => false,
48
- ),
49
- 'Message ID'
50
- )
51
- ->addColumn(
52
- 'status',
53
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
54
- 64,
55
- array(
56
- 'nullable' => false,
57
- ),
58
- 'Status'
59
- )
60
- ->addColumn(
61
- 'sent_at',
62
- Varien_Db_Ddl_Table::TYPE_DATETIME,
63
- null,
64
- array(
65
- 'nullable' => true,
66
- 'default' => null,
67
- ),
68
- 'Date Sent'
69
- )
70
- ->addColumn(
71
- 'recipient',
72
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
73
- 1024,
74
- array(
75
- 'nullable' => false,
76
- ),
77
- 'Recipient'
78
- )
79
- ->addColumn(
80
- 'sender',
81
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
82
- 1024,
83
- array(
84
- 'nullable' => false,
85
- ),
86
- 'Sender'
87
- )
88
- ->addColumn(
89
- 'subject',
90
- Varien_Db_Ddl_Table::TYPE_TEXT,
91
- null,
92
- array(
93
- 'nullable' => false,
94
- ),
95
- 'Subject'
96
- )
97
- ->addColumn(
98
- 'total_opens',
99
- Varien_Db_Ddl_Table::TYPE_INTEGER,
100
- null,
101
- array(
102
- 'nullable' => false,
103
- ),
104
- 'Total Opens'
105
- )
106
- ->addColumn(
107
- 'total_clicks',
108
- Varien_Db_Ddl_Table::TYPE_INTEGER,
109
- null,
110
- array(
111
- 'nullable' => false,
112
- ),
113
- 'Total Clicks'
114
- )
115
- ->addColumn(
116
- 'can_be_resent',
117
- Varien_Db_Ddl_Table::TYPE_BOOLEAN,
118
- null,
119
- array(
120
- 'nullable' => false,
121
- ),
122
- 'Can be Resent'
123
- )
124
- ->addColumn(
125
- 'scope',
126
- Varien_Db_Ddl_Table::TYPE_VARCHAR,
127
- 8,
128
- array(
129
- 'nullable' => false,
130
- ),
131
- 'Scope'
132
- )
133
- ->addColumn(
134
- 'scope_id',
135
- Varien_Db_Ddl_Table::TYPE_INTEGER,
136
- 11,
137
- array(
138
- 'nullable' => false,
139
- ),
140
- 'Scope ID'
141
- );
142
-
143
- $connection->createTable($emailTable);
144
-
145
- $this->endSetup();
1
+ <?php
2
+ /**
3
+ * Campaign Monitor Magento Extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain it through the world-wide-web, please
11
+ * send an email to license@magento.com and you will be sent a copy.
12
+ *
13
+ * @package Campaignmonitor_Createsend
14
+ * @copyright Copyright (c) 2015 Campaign Monitor (https://www.campaignmonitor.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ try {
18
+ // turn on extra customer fields
19
+ Mage::getConfig()->saveConfig('customer/address/dob_show', 'opt', 'default', 0);
20
+ Mage::getConfig()->saveConfig('customer/address/gender_show', 'opt', 'default', 0);
21
+ } catch (Exception $e){
22
+ Mage::log($e->getMessage());
23
+ }
24
+ /** @var $this Mage_Core_Model_Resource_Setup */
25
+ $this->startSetup();
26
+ $connection = $this->getConnection();
27
+
28
+ $emailTableName = $this->getTable("createsend/email");
29
+
30
+ $emailTable = $connection->newTable($emailTableName)
31
+ ->addColumn('email_id',
32
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
33
+ null,
34
+ array(
35
+ 'unsigned' => true,
36
+ 'nullable' => false,
37
+ 'primary' => true,
38
+ 'identity' => true,
39
+ ),
40
+ 'Email ID'
41
+ )
42
+ ->addColumn(
43
+ 'message_id',
44
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
45
+ 64,
46
+ array(
47
+ 'nullable' => false,
48
+ ),
49
+ 'Message ID'
50
+ )
51
+ ->addColumn(
52
+ 'status',
53
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
54
+ 64,
55
+ array(
56
+ 'nullable' => false,
57
+ ),
58
+ 'Status'
59
+ )
60
+ ->addColumn(
61
+ 'sent_at',
62
+ Varien_Db_Ddl_Table::TYPE_DATETIME,
63
+ null,
64
+ array(
65
+ 'nullable' => true,
66
+ 'default' => null,
67
+ ),
68
+ 'Date Sent'
69
+ )
70
+ ->addColumn(
71
+ 'recipient',
72
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
73
+ 1024,
74
+ array(
75
+ 'nullable' => false,
76
+ ),
77
+ 'Recipient'
78
+ )
79
+ ->addColumn(
80
+ 'sender',
81
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
82
+ 1024,
83
+ array(
84
+ 'nullable' => false,
85
+ ),
86
+ 'Sender'
87
+ )
88
+ ->addColumn(
89
+ 'subject',
90
+ Varien_Db_Ddl_Table::TYPE_TEXT,
91
+ null,
92
+ array(
93
+ 'nullable' => false,
94
+ ),
95
+ 'Subject'
96
+ )
97
+ ->addColumn(
98
+ 'total_opens',
99
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
100
+ null,
101
+ array(
102
+ 'nullable' => false,
103
+ ),
104
+ 'Total Opens'
105
+ )
106
+ ->addColumn(
107
+ 'total_clicks',
108
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
109
+ null,
110
+ array(
111
+ 'nullable' => false,
112
+ ),
113
+ 'Total Clicks'
114
+ )
115
+ ->addColumn(
116
+ 'can_be_resent',
117
+ Varien_Db_Ddl_Table::TYPE_BOOLEAN,
118
+ null,
119
+ array(
120
+ 'nullable' => false,
121
+ ),
122
+ 'Can be Resent'
123
+ )
124
+ ->addColumn(
125
+ 'scope',
126
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
127
+ 8,
128
+ array(
129
+ 'nullable' => false,
130
+ ),
131
+ 'Scope'
132
+ )
133
+ ->addColumn(
134
+ 'scope_id',
135
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
136
+ 11,
137
+ array(
138
+ 'nullable' => false,
139
+ ),
140
+ 'Scope ID'
141
+ );
142
+
143
+ $connection->createTable($emailTable);
144
+
145
+ $this->endSetup();
app/design/adminhtml/default/default/template/campaignmonitor/createsend/apiclient.phtml CHANGED
@@ -154,6 +154,14 @@
154
 
155
  field.options.length = 0;
156
 
 
 
 
 
 
 
 
 
157
  if (groupCmLists === undefined && data.length > 1) {
158
  // Reset new list group because we want it after the CM lists
159
  if (groupNewList !== undefined) {
@@ -172,12 +180,13 @@
172
  $('createsend_general_api_list_id').insert(groupNewList);
173
  }
174
 
 
175
  var listCount = 0;
176
  var newCount = 0;
177
  data.each(
178
  function(c) {
179
  var selected = false;
180
- if (c.value == savedListId) {
181
  selected = true;
182
  }
183
  var option = new Option(c.label, c.value, selected, selected);
154
 
155
  field.options.length = 0;
156
 
157
+ if (data.length === 1) {
158
+ var emptyList = {};
159
+ emptyList.label = 'No List found';
160
+ emptyList.value = 'No List found';
161
+ data.push(emptyList);
162
+ }
163
+
164
+
165
  if (groupCmLists === undefined && data.length > 1) {
166
  // Reset new list group because we want it after the CM lists
167
  if (groupNewList !== undefined) {
180
  $('createsend_general_api_list_id').insert(groupNewList);
181
  }
182
 
183
+
184
  var listCount = 0;
185
  var newCount = 0;
186
  data.each(
187
  function(c) {
188
  var selected = false;
189
+ if (c.value == savedListId || c.value === 'No List found') {
190
  selected = true;
191
  }
192
  var option = new Option(c.label, c.value, selected, selected);
package.xml CHANGED
@@ -1,9 +1,9 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Campaignmonitor_Createsend</name>
4
- <version>1.0.7</version>
5
  <stability>stable</stability>
6
- <license uri="https://opensource.org/licenses/OSL-3.0">OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Use your rich customer data in Magento to segment your customers and send hyper-targeted personal emails.</summary>
@@ -18,15 +18,12 @@ Research shows that personalized, relevant email marketing campaigns have at lea
18
  - Celebrate an important date, such as a birthday&lt;br /&gt;&lt;br /&gt;&#xD;
19
  &#xD;
20
  Campaign Monitor makes it easy for you to get started by automatically creating segments for you based on what we&#x2019;ve found to be the most actionable audiences in Magento. Use these segments to automate marketing campaigns.</description>
21
- <notes>Transnational emails fixed.&#xD;
22
- Security fixes&#xD;
23
- Added a way to see logs information.&#xD;
24
- &#xD;
25
  </notes>
26
  <authors><author><name>Campaign Monitor</name><user>CampaignMonitor</user><email>vibhor@campaignmonitor.com</email></author></authors>
27
- <date>2017-05-22</date>
28
- <time>20:22:03</time>
29
- <contents><target name="magecommunity"><dir name="Campaignmonitor"><dir name="Createsend"><dir name="Block"><dir name="Adminhtml"><dir name="Customer"><dir name="Edit"><file name="Grid.php" hash="48e28e2303623522c1a29365b94744df"/></dir></dir><dir name="Email"><file name="Grid.php" hash="1693e7a7d2dd6eaf024ed6dda06dafd0"/><dir name="View"><file name="Abstract.php" hash="480c6ac7134e47bf43c4fd6a3213b3c7"/><file name="Form.php" hash="5661cfe457e8526b2c47313fc264cd55"/><dir name="Tab"><file name="Clicks.php" hash="42f4a1ba85451b34617eeecd4a4a34d3"/><file name="Details.php" hash="2b8a673ccbbf0172c6d750259724c910"/><file name="Html.php" hash="ab99f5396dd23e2c874bdcbea2c9f064"/><file name="Opens.php" hash="5c7c80be07535869099b9adb35d4b5a1"/><file name="Text.php" hash="8448dd4755d6b0fac8136188a4259e95"/></dir><file name="Tabs.php" hash="ab071552f0a18c06f6c6b5deba46ad39"/></dir><file name="View.php" hash="da2d91894a55ff5dadcc3052f76ea4a2"/></dir><file name="Email.php" hash="d515199f4b0a380bbdb18ed4646406ab"/><file name="Switcher.php" hash="a652b662a97986b2a6e9d482c4dd91de"/></dir><dir name="AjaxButton"><file name="Abstract.php" hash="c1fc0f3a54612e2a1a29b2334ce7596e"/></dir><file name="CreateExampleSegments.php" hash="275651dd04e7d33aa59979c420c2970b"/><file name="Linkedattributes.php" hash="100e7027a3f81483619eb656dd601c9c"/><dir name="Log"><file name="Reader.php" hash="b56d128b25a6a6cb4174b235b55b25c4"/><file name="View.php" hash="a02950fc5df3c0c73d1ba1f2f386daae"/></dir><file name="OauthPermissionRequest.php" hash="500f081e10b335c5f8a48dc4e66c6cf5"/><file name="OauthRedirectUrl.php" hash="c620189b986869119ef663c1219d3638"/><file name="TestApi.php" hash="18becb7036d41b984e1ef3b8610e9fbe"/><file name="Version.php" hash="08db8b79b25d8abe86c1e24807c8fc3c"/><file name="Wishlistattributes.php" hash="215c9f748b4dc961bb55c855a5cd05a0"/></dir><dir name="Helper"><file name="Api.php" hash="db3ae7b5f34c7e863c57d5709aaa1da5"/><file name="Config.php" hash="a3fb0f14af014d75e408fc7b8d082b20"/><file name="Data.php" hash="19c555bc15be41c0e27ebded59176acf"/></dir><dir name="Model"><dir name="Api"><file name="Observer.php" hash="7ddceb0ca6cd952716cb9551ab220fd7"/></dir><file name="Api.php" hash="12160dd532468da92699280d3eb2d24e"/><dir name="Config"><file name="Api.php" hash="16c3d74c28fa1e1fd7ccd339a01790b2"/><dir name="Attributes"><file name="Abstract.php" hash="a9253efd2e6e57d8a00ce6daf04de7e0"/></dir><file name="AuthenticationMethod.php" hash="90307b668c7ba94867823aba983b2fdc"/><dir name="Backend"><file name="Apikey.php" hash="82d8bafbdcbbb74078bc8427e7569290"/><file name="Listid.php" hash="ebebd820797f3aa4b5bf69e75771a513"/><dir name="Source"><file name="Files.php" hash="1daed498a877e6d0e52be0c0c00d3a54"/></dir></dir><file name="ClientSelection.php" hash="0adc61c13342da28e8a1815f4f65ae0d"/><file name="ConflictResolutionMethod.php" hash="48938666ddfd96e6b3b5c13c01a4c36c"/><file name="CustomerAttributes.php" hash="5cf999910a27b44d4c7747e2e10b4179"/><file name="DefaultCustomFields.php" hash="fbca6fc17b394e5f38511760a10a9aa1"/><file name="ExampleSegments.php" hash="4ab29a0f8a62c18b3d846ae4901ae2fb"/><file name="ListFlag.php" hash="b259912cdf6a68883a58534079f4db71"/><file name="ListSelection.php" hash="763601cc87f4948c0f3ee93eea3093eb"/><file name="ProductAttributes.php" hash="1a3c82d010fa5aec93d56b1bbabf6568"/><file name="Scope.php" hash="f6c06f4344c1db712925314a7dce7c3d"/><file name="SubscriptionSources.php" hash="e9291723ce6420cb9ebfeff4c994372a"/></dir><file name="Cron.php" hash="4eb2cf346c0705237a402d24053c8ea2"/><dir name="Customer"><file name="Observer.php" hash="374a9704ccd78e6e6dfd03b86a0391f1"/></dir><dir name="Email"><file name="Cron.php" hash="00b7d38721fde5732a92d9d733f32439"/><file name="Template.php" hash="fc47a4151312ad77de2cd2d6f26cc618"/></dir><file name="Email.php" hash="b587fc5062c33e2f2b97111e11095b2c"/><dir name="List"><file name="Cron.php" hash="552c2400cf882aaa5d7b3881022292a7"/><dir name="Initial"><file name="Cron.php" hash="7d5037fd6ebdff2662b702f531797741"/></dir></dir><dir name="Newsletter"><file name="Observer.php" hash="0c194bd321eb4ce58d0859d505254a0d"/></dir><file name="Newsletter.php" hash="4bcb7a0970b9e55c905e753990263f56"/><dir name="Product"><file name="Observer.php" hash="70834ac17bd0ff931b9b9334d79980bb"/></dir><dir name="Resource"><dir name="Email"><file name="Collection.php" hash="85165381ae7416ecdb24cd11c88fd591"/></dir><file name="Email.php" hash="42f44bf5cbbbdb5dc6e7f4944dec9cf8"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Createsend"><file name="ApiController.php" hash="3dfa90cd58af3ce08f77dfafc4485885"/><file name="EmailController.php" hash="14bf61eb251af1444335723475d67f38"/><file name="SegmentController.php" hash="d3aaf5498b92589f2a6ca816931a8978"/></dir></dir><file name="OauthController.php" hash="4f20e1a620363465aa33cda712282646"/><file name="UnsubscribeController.php" hash="062e972b753446efc1d226f83952aeda"/><file name="WebhooksController.php" hash="1bcf68eda9e4fa643c149fc96bfb35df"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4b9b24169fc9612fcf941022d7918071"/><file name="config.xml" hash="555843c1dbc8449ed0456724995cf19f"/><file name="system.xml" hash="d6b52009a83b17b56ec9eabec0a5f8fa"/></dir><dir name="sql"><dir name="campaignmonitor_createsend_setup"><file name="install-1.0.0.php" hash="5af34eba2541737bf1701e2a989d7961"/><file name="install-1.0.1.php" hash="5af34eba2541737bf1701e2a989d7961"/><file name="upgrade-1.0.6-1.0.7.php" hash="697031752d360cd6c9b5cb13fc27c5d0"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Campaignmonitor_Createsend.xml" hash="e2b42c271a897551d0750506555af6d4"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="campaignmonitor"><file name="createsend.xml" hash="5e2dbc978680b1631759eb5664303d1b"/></dir></dir><dir name="template"><dir name="campaignmonitor"><dir name="createsend"><file name="ajax.phtml" hash="74eb59c4ad5b2f686536e33c929419ca"/><file name="apiclient.phtml" hash="753efb7fad644b1d4122689cd48123d6"/><dir name="email"><file name="details.phtml" hash="7a280f81e7fc737ab3a44de8fb3bdb01"/><file name="html.phtml" hash="e5c2f2d96fde96eb62887bb0cdb511f5"/><file name="text.phtml" hash="666a3bece1273f29d42044ee3054b08e"/><file name="tracking.phtml" hash="ca3cee04bf39c89001cb654cbc0acf1c"/></dir><file name="switcher.phtml" hash="f0ebd5e04640cba50b022ad77159ae2b"/><dir name="system"><dir name="config"><dir name="form"><dir name="field"><file name="array_dropdown.phtml" hash="9e47b2ee3ce33ca21cc95d2e360ecc77"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mage"><dir name="shell"><file name="campaignmonitor_list.php" hash="a6ef94412cf5f57fd31b4db409ca028d"/><file name="campaignmonitor_email.php" hash="8a1b04a4970e178c04351247de4ec59a"/><file name="campaignmonitor_list_initial.php" hash="5dc090760799d568ab3906c84b7cbc6d"/></dir></target></contents>
30
  <compatible/>
31
  <dependencies><required><php><min>5.2.0</min><max>8.0.0</max></php></required></dependencies>
32
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Campaignmonitor_Createsend</name>
4
+ <version>1.0.8</version>
5
  <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/MIT">MIT</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Use your rich customer data in Magento to segment your customers and send hyper-targeted personal emails.</summary>
18
  - Celebrate an important date, such as a birthday&lt;br /&gt;&lt;br /&gt;&#xD;
19
  &#xD;
20
  Campaign Monitor makes it easy for you to get started by automatically creating segments for you based on what we&#x2019;ve found to be the most actionable audiences in Magento. Use these segments to automate marketing campaigns.</description>
21
+ <notes>Improve cron sync&#xD;
 
 
 
22
  </notes>
23
  <authors><author><name>Campaign Monitor</name><user>CampaignMonitor</user><email>vibhor@campaignmonitor.com</email></author></authors>
24
+ <date>2017-05-26</date>
25
+ <time>22:16:09</time>
26
+ <contents><target name="magecommunity"><dir name="Campaignmonitor"><dir name="Createsend"><dir name="Block"><dir name="Adminhtml"><dir name="Customer"><dir name="Edit"><file name="Grid.php" hash="6a551f577ee9854786cf68270cc8a1ef"/></dir></dir><dir name="Email"><file name="Grid.php" hash="a815f076b8db78edf010db0324fa315e"/><dir name="View"><file name="Abstract.php" hash="cad87927913024bc71b38c0e38d06035"/><file name="Form.php" hash="3c84115cbf3db0f6670b37e0080c8dd3"/><dir name="Tab"><file name="Clicks.php" hash="a2e206a65503859ad9234c37d3ddb212"/><file name="Details.php" hash="4aaf80b1c8ec6efd0c766b7a0a23b979"/><file name="Html.php" hash="60d8189c4f94ddae6a85bef26fff9a76"/><file name="Opens.php" hash="312cf5eda463774092ced374a5e710f0"/><file name="Text.php" hash="4bb8fc1b1d1cedaf59cab9eada898381"/></dir><file name="Tabs.php" hash="1e39d7d4b794b0125f44e85ab9b36e56"/></dir><file name="View.php" hash="e7ce46e2dbab36c218b3b2d740c249df"/></dir><file name="Email.php" hash="ea77be86d1b417f35015ceb4c21e1e1d"/><file name="Switcher.php" hash="4bb25b0878cc6a520c6f1ff76f0ae269"/></dir><dir name="AjaxButton"><file name="Abstract.php" hash="3a5c1f421d09b31ad133a4d23ab3ba4b"/></dir><file name="CreateExampleSegments.php" hash="7da8c0ad40583e06d07ba2e1692886ee"/><file name="Linkedattributes.php" hash="43fb401d2fee10c5c3b083787fac4421"/><dir name="Log"><file name="Reader.php" hash="6b977662d88f8e827c41c26499b0fcf7"/><file name="View.php" hash="c61a419bd291b50d94050894e4aaab10"/></dir><file name="OauthPermissionRequest.php" hash="5b3e841e157fdd29fddb3c882a0c82b1"/><file name="OauthRedirectUrl.php" hash="ab62818bebe2e0637fb32986b259f59e"/><file name="TestApi.php" hash="d101b6e6d3d0c4dfea374fb0eecc7edd"/><file name="Version.php" hash="20b1eacec36d67d8c303b0f00f73a923"/><file name="Wishlistattributes.php" hash="68eec94dd1c5b9cb21d4521f67270f80"/></dir><dir name="Helper"><file name="Api.php" hash="2ffb97ba51ea4822329faea1bf7efb88"/><file name="Config.php" hash="04bb0f0e2da2ee68988d1a1e73afb4eb"/><file name="Data.php" hash="7a565ff3f924777a49dd5c5274db0332"/></dir><dir name="Model"><dir name="Api"><file name="Observer.php" hash="b11f40200cd3003a914b5ca97653a2c9"/></dir><file name="Api.php" hash="f671a36444fb22264dd7f499c7bac938"/><dir name="Config"><file name="Api.php" hash="86205244d40cd709c71fa82dd4e3bf02"/><dir name="Attributes"><file name="Abstract.php" hash="bf8e3ca3b11b65f24203d860596d5b13"/></dir><file name="AuthenticationMethod.php" hash="71c78418bbd0ad61d9bcf524fe915fc1"/><dir name="Backend"><file name="Apikey.php" hash="6e15e789f77ad8318c2166cb83bae1c9"/><file name="Listid.php" hash="39ec28339214c74d9c283dceb6279904"/><dir name="Source"><file name="Files.php" hash="6e9fafc2308d757c9e13d61330a29384"/></dir></dir><file name="ClientSelection.php" hash="9f379699b496e4c989a354b00c68a349"/><file name="ConflictResolutionMethod.php" hash="2e429bb02ffaf001dd1763e4c34f9f64"/><file name="CustomerAttributes.php" hash="058b223daad24c1c0be8ba1cc963f222"/><file name="DefaultCustomFields.php" hash="503ed82b8601782ce0dad5fd67e577f9"/><file name="ExampleSegments.php" hash="6fe6899e76f03775330d6c0282afb750"/><file name="ListFlag.php" hash="aed286313e991ade3d57fa1575a091ee"/><file name="ListSelection.php" hash="9a8e0607bea5d284b4b9884542853e23"/><file name="ProductAttributes.php" hash="ef059d884773d387faefd1cd022186f9"/><file name="Scope.php" hash="99a846aedce5006de9fd6b6a45a1a0d8"/><file name="SubscriptionSources.php" hash="282fcfe0389921be500c2509fa107503"/></dir><file name="Cron.php" hash="7886754fd6183ca6bd3087a73ebdb5da"/><dir name="Customer"><file name="Observer.php" hash="5ead277e165974b80412ccec6e4542e8"/></dir><dir name="Email"><file name="Cron.php" hash="af9a16452353807a9e72d4a8a561dfcb"/><file name="Template.php" hash="6de878bce3a9b76c2918cc61c80297ac"/></dir><file name="Email.php" hash="e43ed671d740c2381d260378031df677"/><dir name="List"><file name="Cron.php" hash="8172902e659d0a066db4fd099d859ca1"/><dir name="Initial"><file name="Cron.php" hash="4dec6934096443858e6bfec2b7b84bed"/></dir></dir><dir name="Newsletter"><file name="Observer.php" hash="75a5edc13c5f83e2e93181e869c1f819"/></dir><file name="Newsletter.php" hash="64a9df892a96d558fcc816783861d34f"/><dir name="Product"><file name="Observer.php" hash="cec315ffaf486537cfc63645ed74227c"/></dir><dir name="Resource"><dir name="Email"><file name="Collection.php" hash="ab74d05430a6d16f915d6801f221bd5f"/></dir><file name="Email.php" hash="a4701a3a612b7ffeef8beca79405b777"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Createsend"><file name="ApiController.php" hash="8396d18e14427373f982d5a0ffcd5461"/><file name="EmailController.php" hash="16d7b0c9d0bd7b32e84d0d7cf7bf925d"/><file name="SegmentController.php" hash="05d62b07a993ccdbd1508166a7db5c43"/></dir></dir><file name="OauthController.php" hash="572741d145f647f44d8efc2ae7bd91b7"/><file name="UnsubscribeController.php" hash="098dcfbe25887ff574f8dc8479553483"/><file name="WebhooksController.php" hash="add147c986a4addf58346869875c8e22"/></dir><dir name="etc"><file name="adminhtml.xml" hash="e598088abd6f1be7dbec4701fb30bd41"/><file name="config.xml" hash="8c51aa76b7d1ebf3a34586551ccc09e0"/><file name="system.xml" hash="6337951ce1b7beae592f32d11d316504"/></dir><dir name="sql"><dir name="campaignmonitor_createsend_setup"><file name="install-1.0.0.php" hash="21b430546ca931cfc5d11b62570d99f2"/><file name="install-1.0.1.php" hash="21b430546ca931cfc5d11b62570d99f2"/><file name="upgrade-1.0.6-1.0.7.php" hash="697031752d360cd6c9b5cb13fc27c5d0"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Campaignmonitor_Createsend.xml" hash="e2b42c271a897551d0750506555af6d4"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="campaignmonitor"><file name="createsend.xml" hash="5e2dbc978680b1631759eb5664303d1b"/></dir></dir><dir name="template"><dir name="campaignmonitor"><dir name="createsend"><file name="ajax.phtml" hash="74eb59c4ad5b2f686536e33c929419ca"/><file name="apiclient.phtml" hash="b3cce68d753b37578bc76842081a6dde"/><dir name="email"><file name="details.phtml" hash="7a280f81e7fc737ab3a44de8fb3bdb01"/><file name="html.phtml" hash="e5c2f2d96fde96eb62887bb0cdb511f5"/><file name="text.phtml" hash="666a3bece1273f29d42044ee3054b08e"/><file name="tracking.phtml" hash="ca3cee04bf39c89001cb654cbc0acf1c"/></dir><file name="switcher.phtml" hash="f0ebd5e04640cba50b022ad77159ae2b"/><dir name="system"><dir name="config"><dir name="form"><dir name="field"><file name="array_dropdown.phtml" hash="9e47b2ee3ce33ca21cc95d2e360ecc77"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mage"><dir name="shell"><file name="campaignmonitor_list.php" hash="a6ef94412cf5f57fd31b4db409ca028d"/><file name="campaignmonitor_email.php" hash="8a1b04a4970e178c04351247de4ec59a"/><file name="campaignmonitor_list_initial.php" hash="5dc090760799d568ab3906c84b7cbc6d"/></dir></target></contents>
27
  <compatible/>
28
  <dependencies><required><php><min>5.2.0</min><max>8.0.0</max></php></required></dependencies>
29
  </package>