Professio_BudgetMailer - Version 1.0.4

Version Notes

1.0.4 - Changed copyright years, removed contact & list models to simpler the workflow, replaced custom magento budgetmailer api with BudgetMailer PHP API, translation & template updates
1.0.3 - Various bug fixes, and simplifications
1.0.2 - PHP bug fix: using empty() in write context
1.0.1 - Repacking for Magento Connect
1.0.0 - Initial version

Download this release

Release Info

Developer J.S. Diertens
Extension Professio_BudgetMailer
Version 1.0.4
Comparing to
See all releases


Code changes from version 1.0.3 to 1.0.4

Files changed (76) hide show
  1. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact.php +0 -145
  2. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Edit.php +0 -88
  3. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Edit/Form.php +0 -51
  4. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Edit/Tab/Form.php +0 -310
  5. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Edit/Tabs.php +0 -71
  6. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Grid.php +0 -277
  7. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Customer/Tab.php +18 -37
  8. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Export.php +28 -0
  9. app/code/community/Professio/BudgetMailer/Block/Adminhtml/Helper/Column/Renderer/Parent.php +0 -95
  10. app/code/community/Professio/BudgetMailer/Block/Adminhtml/List.php +0 -46
  11. app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Edit.php +0 -82
  12. app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Edit/Form.php +0 -51
  13. app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Edit/Tab/Form.php +0 -110
  14. app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Edit/Tabs.php +0 -68
  15. app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Grid.php +0 -222
  16. app/code/community/Professio/BudgetMailer/Block/CheckoutAgreements.php +33 -17
  17. app/code/community/Professio/BudgetMailer/Block/Newsletter.php +12 -23
  18. app/code/community/Professio/BudgetMailer/Block/Subscribe.php +4 -4
  19. app/code/community/Professio/BudgetMailer/Block/Subscribe/Mini.php +13 -9
  20. app/code/community/Professio/BudgetMailer/Controller/Adminhtml/BudgetMailer.php +9 -33
  21. app/code/community/Professio/BudgetMailer/Exception.php +4 -4
  22. app/code/community/Professio/BudgetMailer/Form/Element/Tags.php +0 -103
  23. app/code/community/Professio/BudgetMailer/Helper/Config.php +91 -31
  24. app/code/community/Professio/BudgetMailer/Helper/Data.php +10 -23
  25. app/code/community/Professio/BudgetMailer/Helper/Mapper.php +87 -408
  26. app/code/community/Professio/BudgetMailer/Model/Client.php +53 -857
  27. app/code/community/Professio/BudgetMailer/Model/Config/Source/Account.php +12 -8
  28. app/code/community/Professio/BudgetMailer/Model/Config/Source/Address.php +4 -4
  29. app/code/community/Professio/BudgetMailer/Model/Config/Source/Delete.php +13 -4
  30. app/code/community/Professio/BudgetMailer/Model/Config/Source/Delete/Address.php +4 -4
  31. app/code/community/Professio/BudgetMailer/Model/Config/Source/List.php +20 -22
  32. app/code/community/Professio/BudgetMailer/Model/Config/Source/Update.php +4 -4
  33. app/code/community/Professio/BudgetMailer/Model/Contact.php +0 -600
  34. app/code/community/Professio/BudgetMailer/Model/Exporter.php +255 -314
  35. app/code/community/Professio/BudgetMailer/Model/Importer.php +0 -505
  36. app/code/community/Professio/BudgetMailer/Model/List.php +0 -138
  37. app/code/community/Professio/BudgetMailer/Model/Observer.php +186 -267
  38. app/code/community/Professio/BudgetMailer/Model/Resource/Contact.php +0 -156
  39. app/code/community/Professio/BudgetMailer/Model/Resource/Contact/Collection.php +0 -79
  40. app/code/community/Professio/BudgetMailer/Model/Resource/List.php +0 -72
  41. app/code/community/Professio/BudgetMailer/Model/Resource/List/Collection.php +0 -177
  42. app/code/community/Professio/BudgetMailer/Model/Resource/Setup.php +4 -4
  43. app/code/community/Professio/BudgetMailer/controllers/Adminhtml/Budgetmailer/ContactController.php +0 -510
  44. app/code/community/Professio/BudgetMailer/controllers/Adminhtml/BudgetmailerController.php +16 -229
  45. app/code/community/Professio/BudgetMailer/controllers/ManageController.php +23 -42
  46. app/code/community/Professio/BudgetMailer/controllers/SubscriberController.php +33 -61
  47. app/code/community/Professio/BudgetMailer/controllers/WebhookController.php +0 -145
  48. app/code/community/Professio/BudgetMailer/etc/adminhtml.xml +22 -36
  49. app/code/community/Professio/BudgetMailer/etc/config.xml +20 -30
  50. app/code/community/Professio/BudgetMailer/etc/system.xml +16 -27
  51. app/code/community/Professio/BudgetMailer/sql/budgetmailer_setup/install-1.0.0.php +4 -4
  52. app/code/community/Professio/BudgetMailer/sql/budgetmailer_setup/mysql4-upgrade-1.0.1-1.0.2.php +41 -0
  53. app/code/community/Professio/BudgetMailer/sql/budgetmailer_setup_uninstall.sql +10 -6
  54. app/design/adminhtml/default/default/layout/budgetmailer.xml +10 -78
  55. app/design/adminhtml/default/default/template/budgetmailer/customer/tab.phtml +12 -5
  56. app/design/adminhtml/default/default/template/budgetmailer/export.phtml +38 -0
  57. app/design/frontend/base/default/layout/budgetmailer.xml +4 -4
  58. app/design/frontend/base/default/template/budgetmailer/newsletter.phtml +4 -4
  59. app/design/frontend/base/default/template/budgetmailer/onepage-agreements.phtml +4 -4
  60. app/design/frontend/base/default/template/budgetmailer/subscribe.phtml +5 -5
  61. app/design/frontend/base/default/template/budgetmailer/subscribe/mini.phtml +6 -8
  62. app/design/frontend/rwd/default/layout/budgetmailer.xml +4 -4
  63. app/design/frontend/rwd/default/template/budgetmailer/newsletter.phtml +4 -4
  64. app/design/frontend/rwd/default/template/budgetmailer/onepage-agreements.phtml +4 -4
  65. app/design/frontend/rwd/default/template/budgetmailer/subscribe.phtml +4 -4
  66. app/design/frontend/rwd/default/template/budgetmailer/subscribe/mini.phtml +7 -9
  67. app/etc/modules/Professio_BudgetMailer.xml +1 -1
  68. app/locale/en_US/Professio_BudgetMailer.csv +56 -100
  69. app/locale/nl_NL/Professio_BudgetMailer.csv +69 -111
  70. lib/BudgetMailer/Api/Cache.php +293 -0
  71. lib/BudgetMailer/Api/Client.php +801 -0
  72. lib/BudgetMailer/Api/Client/Http.php +548 -0
  73. lib/BudgetMailer/Api/Client/RestJson.php +143 -0
  74. lib/BudgetMailer/Api/Config.php +111 -0
  75. lib/BudgetMailer/LICENSE +21 -0
  76. package.xml +7 -6
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact.php DELETED
@@ -1,145 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Admin contact block
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_Contact
25
- extends Mage_Adminhtml_Block_Widget_Grid_Container
26
- {
27
- /**
28
- * Contact - prepare widget
29
- */
30
- public function __construct()
31
- {
32
- $this->_controller = 'adminhtml_contact';
33
- $this->_blockGroup = 'budgetmailer';
34
-
35
- parent::__construct();
36
-
37
- $this->_headerText = Mage::helper('budgetmailer')->__('Contact');
38
-
39
- unset($this->_buttons[0]['add']);
40
-
41
- $this->_addButton(
42
- 'delete_orphans',
43
- array(
44
- 'label' => Mage::helper('budgetmailer')
45
- ->__('Delete Orphans'),
46
- 'onclick' => 'setLocation(\''
47
- . $this->getDeleteOrphansUrl() .'\')',
48
- 'class' => '',
49
- )
50
- );
51
-
52
- $this->_addButton(
53
- 'export_customers',
54
- array(
55
- 'label' => Mage::helper('budgetmailer')
56
- ->__('Export Magento Customers'),
57
- 'onclick' => 'setLocation(\''
58
- . $this->getCustomersExportUrl() .'\')',
59
- 'class' => '',
60
- )
61
- );
62
-
63
- $this->_addButton(
64
- 'export_subscribers',
65
- array(
66
- 'label' => Mage::helper('budgetmailer')
67
- ->__('Export Magento Newsletter Subscribers'),
68
- 'onclick' => 'setLocation(\''
69
- . $this->getSubscribersExportUrl() .'\')',
70
- 'class' => '',
71
- )
72
- );
73
-
74
- $this->_addButton(
75
- 'export_unregistered',
76
- array(
77
- 'label' => Mage::helper('budgetmailer')
78
- ->__('Export unregistered Customers'),
79
- 'onclick' => 'setLocation(\''
80
- . $this->getUnregisteredExportUrl() .'\')',
81
- 'class' => '',
82
- )
83
- );
84
-
85
- $this->_addButton(
86
- 'import_budgetmailer',
87
- array(
88
- 'label' => Mage::helper('budgetmailer')
89
- ->__('Import BudgetMailer Contacts'),
90
- 'onclick' => 'setLocation(\''
91
- . $this->getBudgetmailerImportUrl() .'\')',
92
- 'class' => '',
93
- )
94
- );
95
- }
96
-
97
- /**
98
- * Get budgetmailer import url
99
- * @return string
100
- */
101
- protected function getBudgetmailerImportUrl()
102
- {
103
- return $this->getUrl('*/budgetmailer/importbudgetmailer');
104
- }
105
-
106
- /**
107
- * Get customers export url
108
- *
109
- * @return string
110
- */
111
- protected function getCustomersExportUrl()
112
- {
113
- return $this->getUrl('*/budgetmailer/exportcustomers');
114
- }
115
-
116
- /**
117
- * Get delete orphans url
118
- *
119
- * @return string
120
- */
121
- protected function getDeleteOrphansUrl()
122
- {
123
- return $this->getUrl('*/budgetmailer/deleteorphans');
124
- }
125
-
126
- /**
127
- * Get subscribers export url
128
- *
129
- * @return string
130
- */
131
- protected function getSubscribersExportUrl()
132
- {
133
- return $this->getUrl('*/budgetmailer/exportsubscribers');
134
- }
135
-
136
- /**
137
- * Get unregistered customers export url
138
- *
139
- * @return string
140
- */
141
- protected function getUnregisteredExportUrl()
142
- {
143
- return $this->getUrl('*/budgetmailer/exportunregistered');
144
- }
145
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Edit.php DELETED
@@ -1,88 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Contact edit
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_Contact_Edit
25
- extends Mage_Adminhtml_Block_Widget_Form_Container
26
- {
27
- /**
28
- * Constructor
29
- *
30
- * @return void
31
- */
32
- public function __construct()
33
- {
34
- parent::__construct();
35
-
36
- $this->_blockGroup = 'budgetmailer';
37
- $this->_controller = 'adminhtml_contact';
38
-
39
- $this->_updateButton(
40
- 'save',
41
- 'label',
42
- Mage::helper('budgetmailer')->__('Save Contact')
43
- );
44
-
45
- $this->_updateButton(
46
- 'delete',
47
- 'label', Mage::helper('budgetmailer')->__('Delete Contact')
48
- );
49
-
50
- $this->_addButton(
51
- 'saveandcontinue',
52
- array(
53
- 'label' => Mage::helper('budgetmailer')
54
- ->__('Save And Continue Edit'),
55
- 'onclick' => 'saveAndContinueEdit()',
56
- 'class' => 'save',
57
- ),
58
- -100
59
- );
60
-
61
- $this->_formScripts[] = "
62
- function saveAndContinueEdit(){
63
- editForm.submit($('edit_form').action+'back/edit/');
64
- }
65
- ";
66
- }
67
-
68
- /**
69
- * Get the edit form header
70
- *
71
- * @return string
72
- */
73
- public function getHeaderText()
74
- {
75
- if (Mage::registry('current_contact')
76
- && Mage::registry('current_contact')->getId()) {
77
- return Mage::helper('budgetmailer')
78
- ->__(
79
- "Edit Contact '%s'",
80
- $this->escapeHtml(
81
- Mage::registry('current_contact')->getEmail()
82
- )
83
- );
84
- } else {
85
- return Mage::helper('budgetmailer')->__('Add Contact');
86
- }
87
- }
88
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Edit/Form.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Contact edit form
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_Contact_Edit_Form
25
- extends Mage_Adminhtml_Block_Widget_Form
26
- {
27
- /**
28
- * Prepare form
29
- *
30
- * @return Professio_BudgetMailer_Block_Adminhtml_Contact_Edit_Form
31
- */
32
- protected function _prepareForm()
33
- {
34
- $form = new Varien_Data_Form(
35
- array(
36
- 'id' => 'edit_form',
37
- 'action' => $this->getUrl(
38
- '*/*/save',
39
- array('id' => $this->getRequest()->getParam('id'))
40
- ),
41
- 'method' => 'post',
42
- 'enctype' => 'multipart/form-data'
43
- )
44
- );
45
-
46
- $form->setUseContainer(true);
47
- $this->setForm($form);
48
-
49
- return parent::_prepareForm();
50
- }
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Edit/Tab/Form.php DELETED
@@ -1,310 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Contact edit tab form
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_Contact_Edit_Tab_Form
25
- extends Mage_Adminhtml_Block_Widget_Form
26
- {
27
- /**
28
- * @var array form fields definitions
29
- */
30
- protected $_fields = array(
31
- array(
32
- 'budgetmailer_id',
33
- 'text',
34
- array(
35
- 'label' => 'Budgetmailer ID',
36
- 'name' => 'budgetmailer_id',
37
- //'required' => true,
38
- //'class' => 'required-entry',
39
- 'readonly' => true,
40
- )
41
- ),
42
- array(
43
- 'email',
44
- 'text',
45
- array(
46
- 'label' => 'Email',
47
- 'name' => 'email',
48
- 'required' => true,
49
- 'class' => 'required-entry',
50
- )
51
- ),
52
- array(
53
- 'company_name',
54
- 'text',
55
- array(
56
- 'label' => 'Company',
57
- 'name' => 'company_name',
58
- 'required' => false,
59
- )
60
- ),
61
- array(
62
- 'first_name',
63
- 'text',
64
- array(
65
- 'label' => 'First Name',
66
- 'name' => 'first_name',
67
- 'required' => false,
68
- )
69
- ),
70
- array(
71
- 'insertion',
72
- 'text',
73
- array(
74
- 'label' => 'Insertion',
75
- 'name' => 'insertion',
76
- 'required' => false,
77
- )
78
- ),
79
- array(
80
- 'last_name',
81
- 'text',
82
- array(
83
- 'label' => 'Last Name',
84
- 'name' => 'last_name',
85
- 'required' => false,
86
- )
87
- ),
88
- array(
89
- 'sex',
90
- 'select',
91
- array(
92
- 'label' => 'Sex',
93
- 'name' => 'sex',
94
- 'required' => false,
95
- 'values' => array(
96
- array(
97
- 'value' => 0,
98
- 'label' => ''
99
- ),
100
- array(
101
- 'value' => 1,
102
- 'label' => 'Male'
103
- ),
104
- array(
105
- 'value' => 2,
106
- 'label' => 'Female'
107
- ),
108
- ),
109
- )
110
- ),
111
- array(
112
- 'address',
113
- 'text',
114
- array(
115
- 'label' => 'Address',
116
- 'name' => 'address',
117
- 'required' => false,
118
- )
119
- ),
120
- array(
121
- 'postal_code',
122
- 'text',
123
- array(
124
- 'label' => 'Postal Code',
125
- 'name' => 'postal_code',
126
- 'required' => false,
127
- )
128
- ),
129
- array(
130
- 'city',
131
- 'text',
132
- array(
133
- 'label' => 'City',
134
- 'name' => 'city',
135
- 'required' => false,
136
- )
137
- ),
138
- array(
139
- 'country_code',
140
- 'text',
141
- array(
142
- 'label' => 'Country Code',
143
- 'name' => 'country_code',
144
- 'required' => false,
145
- )
146
- ),
147
- array(
148
- 'telephone',
149
- 'text',
150
- array(
151
- 'label' => 'Telephone',
152
- 'name' => 'telephone',
153
- 'required' => false,
154
- )
155
- ),
156
- array(
157
- 'mobile',
158
- 'text',
159
- array(
160
- 'label' => 'Mobile',
161
- 'name' => 'mobile',
162
- 'required' => false,
163
- )
164
- ),
165
- array(
166
- 'remarks',
167
- 'textarea',
168
- array(
169
- 'label' => 'Remarks',
170
- 'name' => 'remarks',
171
- 'required' => false,
172
- )
173
- ),
174
- array(
175
- 'tags',
176
- 'budgetmailer_tags',
177
- array(
178
- 'label' => 'Tags',
179
- 'name' => 'tags',
180
- 'required' => false,
181
- )
182
- ),
183
- // array(
184
- // 'unsubscribed',
185
- // 'select',
186
- // array(
187
- // 'label' => 'Unsubscribed',
188
- // 'name' => 'unsubscribed',
189
- // 'readonly' => true,
190
- // 'required' => false,
191
- // 'values'=> array(
192
- // array(
193
- // 'value' => 1,
194
- // 'label' => 'Yes',
195
- // ),
196
- // array(
197
- // 'value' => 0,
198
- // 'label' => 'No',
199
- // ),
200
- // ),
201
- // )
202
- // )
203
- );
204
-
205
- /**
206
- * Prepare the form
207
- *
208
- * @return Professio_BudgetMailer_Block_Adminhtml_Contact_Edit_Tab_Form
209
- */
210
- protected function _prepareForm()
211
- {
212
- $form = new Varien_Data_Form();
213
-
214
- $form->setHtmlIdPrefix('contact_');
215
- $form->setFieldNameSuffix('contact');
216
- $this->setForm($form);
217
-
218
- $fieldset = $form->addFieldset(
219
- 'contact_form',
220
- array(
221
- 'legend' => Mage::helper('budgetmailer')->__('Contact')
222
- )
223
- );
224
-
225
- $fieldset->addType(
226
- 'budgetmailer_tags',
227
- 'Professio_BudgetMailer_Form_Element_Tags'
228
- );
229
-
230
- $values = Mage::getResourceModel('budgetmailer/list_collection')
231
- ->toOptionArray();
232
- array_unshift($values, array('label'=>'', 'value'=>''));
233
-
234
- $fieldset->addField(
235
- 'list_id',
236
- 'hidden',
237
- array(
238
- 'name' => 'list_id',
239
- //'required' => true,
240
- )
241
- );
242
-
243
- $subscribe = Mage::registry('current_contact')
244
- && Mage::registry('current_contact')->getEntityId()
245
- ? !Mage::registry('current_contact')->getUnsubscribed()
246
- : false;
247
-
248
- $fieldset->addField(
249
- 'subscribe',
250
- 'checkbox',
251
- array(
252
- 'label' => Mage::helper('budgetmailer')->__('Subscribe'),
253
- 'name' => 'subscribe',
254
- 'value' => 1,
255
- 'checked' => $subscribe
256
- )
257
- );
258
-
259
- $this->addFields($fieldset);
260
-
261
- $formValues = Mage::registry('current_contact')->getDefaultValues();
262
-
263
- if (!is_array($formValues)) {
264
- $formValues = array();
265
- }
266
-
267
- if (Mage::getSingleton('adminhtml/session')->getContactData()) {
268
- $formValues = array_merge(
269
- $formValues,
270
- Mage::getSingleton('adminhtml/session')->getContactData()
271
- );
272
- Mage::getSingleton('adminhtml/session')->setContactData(null);
273
- } elseif (Mage::registry('current_contact')) {
274
- $formValues = array_merge(
275
- $formValues,
276
- Mage::registry('current_contact')->getData()
277
- );
278
- }
279
-
280
- $form->setValues($formValues);
281
-
282
- return parent::_prepareForm();
283
- }
284
-
285
- /**
286
- * Add fields from definition to fieldset
287
- * @param Varien_Data_Form_Element_Fieldset $fieldset
288
- */
289
- protected function addFields($fieldset)
290
- {
291
- foreach ($this->_fields as $k => $field) {
292
- if (isset($field[2]['label'])) {
293
- $field[2]['label'] = Mage::helper('budgetmailer')
294
- ->__($field[2]['label']);
295
- }
296
-
297
- if (isset($field[2]['values'])) {
298
- foreach ($field[2]['values'] as $k => $v) {
299
- if (isset($v['label'])) {
300
- $field[2]['values'][$k]['label'] =
301
- Mage::helper('budgetmailer')
302
- ->__($v['label']);
303
- }
304
- }
305
- }
306
-
307
- $fieldset->addField($field[0], $field[1], $field[2]);
308
- }
309
- }
310
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Edit/Tabs.php DELETED
@@ -1,71 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Contact edit tabs
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_Contact_Edit_Tabs
25
- extends Mage_Adminhtml_Block_Widget_Tabs
26
- {
27
- /**
28
- * Initialize Tabs
29
- *
30
- * @return void
31
- */
32
- public function __construct()
33
- {
34
- parent::__construct();
35
-
36
- $this->setId('contact_tabs');
37
- $this->setDestElementId('edit_form');
38
- $this->setTitle(Mage::helper('budgetmailer')->__('Contact'));
39
- }
40
-
41
- /**
42
- * Before render html
43
- *
44
- * @return Professio_BudgetMailer_Block_Adminhtml_Contact_Edit_Tabs
45
- */
46
- protected function _beforeToHtml()
47
- {
48
- $this->addTab(
49
- 'form_contact', array(
50
- 'label' => Mage::helper('budgetmailer')->__('Contact'),
51
- 'title' => Mage::helper('budgetmailer')->__('Contact'),
52
- 'content' => $this->getLayout()
53
- ->createBlock(
54
- 'budgetmailer/adminhtml_contact_edit_tab_form'
55
- )->toHtml(),
56
- )
57
- );
58
-
59
- return parent::_beforeToHtml();
60
- }
61
-
62
- /**
63
- * Retrieve contact entity
64
- *
65
- * @return Professio_BudgetMailer_Model_Contact
66
- */
67
- public function getContact()
68
- {
69
- return Mage::registry('current_contact');
70
- }
71
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Contact/Grid.php DELETED
@@ -1,277 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Conctact edit grid
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_Contact_Grid
25
- extends Mage_Adminhtml_Block_Widget_Grid
26
- {
27
- /**
28
- * @var array columns definition
29
- */
30
- protected $_columnsDefinition = array(
31
- array(
32
- 'entity_id',
33
- array(
34
- 'header' => 'Id',
35
- 'index' => 'entity_id',
36
- 'type' => 'number'
37
- )
38
- ),
39
- array(
40
- 'list_id',
41
- array(
42
- 'header' => 'List',
43
- 'index' => 'list_id',
44
- 'type' => 'options',
45
- 'options' => array(),
46
- 'renderer' =>
47
- 'budgetmailer/adminhtml_helper_column_renderer_parent',
48
- 'params' => array(
49
- 'id' => 'getListId'
50
- ),
51
- 'base_link' => 'adminhtml/budgetmailer_list/edit'
52
- )
53
- ),
54
- array(
55
- 'budgetmailer_id',
56
- array(
57
- 'header' => 'Budgetmailer ID',
58
- 'index' => 'budgetmailer_id',
59
- 'type' => 'text',
60
- )
61
- ),
62
- array(
63
- 'email',
64
- array(
65
- 'header' => 'Email',
66
- 'align' => 'left',
67
- 'index' => 'email',
68
- )
69
- ),
70
- array(
71
- 'company_name',
72
- array(
73
- 'header' => 'Company Name',
74
- 'index' => 'company_name',
75
- 'type' => 'text',
76
- )
77
- ),
78
- array(
79
- 'first_name',
80
- array(
81
- 'header' => 'First Name',
82
- 'index' => 'first_name',
83
- 'type' => 'text',
84
- )
85
- ),
86
- array(
87
- 'last_name',
88
- array(
89
- 'header' => 'Last Name',
90
- 'index' => 'last_name',
91
- 'type' => 'text',
92
- )
93
- ),
94
- array(
95
- 'city',
96
- array(
97
- 'header' => 'City',
98
- 'index' => 'city',
99
- 'type' => 'text',
100
- )
101
- ),
102
- array(
103
- 'country_code',
104
- array(
105
- 'header' => 'Country Code',
106
- 'index' => 'country_code',
107
- 'type' => 'text',
108
- )
109
- ),
110
- array(
111
- 'unsubscribed',
112
- array(
113
- 'header' => 'Unsubscribed',
114
- 'index' => 'unsubscribed',
115
- 'type' => 'options',
116
- 'options' => array(
117
- '1' => 'Yes',
118
- '0' => 'No',
119
- )
120
- )
121
- ),
122
- array(
123
- 'action',
124
- array(
125
- 'header' => 'Action',
126
- 'width' => '100',
127
- 'type' => 'action',
128
- 'getter' => 'getId',
129
- 'actions' => array(
130
- array(
131
- 'caption' => 'Edit',
132
- 'url' => array('base' => '*/*/edit'),
133
- 'field' => 'id'
134
- )
135
- ),
136
- 'filter' => false,
137
- 'is_system' => true,
138
- 'sortable' => false,
139
- )
140
- )
141
- );
142
-
143
- /**
144
- * Constructor
145
- *
146
- * @return void
147
- */
148
- public function __construct()
149
- {
150
- parent::__construct();
151
-
152
- $this->setId('contactGrid');
153
- $this->setDefaultSort('entity_id');
154
- $this->setDefaultDir('ASC');
155
- $this->setSaveParametersInSession(true);
156
- $this->setUseAjax(true);
157
- }
158
-
159
- /**
160
- * Prepare collection
161
- *
162
- * @return Professio_BudgetMailer_Block_Adminhtml_Contact_Grid
163
- */
164
- protected function _prepareCollection()
165
- {
166
- $collection = Mage::getModel('budgetmailer/contact')->getCollection();
167
- $this->setCollection($collection);
168
-
169
- return parent::_prepareCollection();
170
- }
171
-
172
- /**
173
- * Prepare grid collection
174
- *
175
- * @return Professio_BudgetMailer_Block_Adminhtml_Contact_Grid
176
- */
177
- protected function _prepareColumns()
178
- {
179
- foreach ($this->_columnsDefinition as $column) {
180
- if (isset($column[1]['header'])) {
181
- $column[1]['header'] = Mage::helper('budgetmailer')
182
- ->__($column[1]['header']);
183
- }
184
-
185
- $this->addColumn($column[0], $column[1]);
186
- }
187
-
188
- $this->getColumn('list_id')->setData(
189
- 'options',
190
- Mage::getResourceModel('budgetmailer/list_collection')
191
- ->toOptionHash()
192
- );
193
-
194
- return parent::_prepareColumns();
195
- }
196
-
197
- /**
198
- * Prepare mass action
199
- *
200
- * @return Professio_BudgetMailer_Block_Adminhtml_Contact_Grid
201
- */
202
- protected function _prepareMassaction()
203
- {
204
- $this->setMassactionIdField('entity_id');
205
- $this->getMassactionBlock()->setFormFieldName('contact');
206
-
207
- // delete, unsubscribe, unsubscribe and delete
208
-
209
- $this->getMassactionBlock()->addItem(
210
- 'delete',
211
- array(
212
- 'label'=> Mage::helper('budgetmailer')->__('Delete from BudgetMailer'),
213
- 'url' => $this->getUrl('*/*/massDelete'),
214
- 'confirm' => Mage::helper('budgetmailer')->__('Are you sure?')
215
- )
216
- );
217
-
218
- $this->getMassactionBlock()->addItem(
219
- 'unsubscribe',
220
- array(
221
- 'label'=> Mage::helper('budgetmailer')->__('Unsubscribe from BudgetMailer'),
222
- 'url' => $this->getUrl('*/*/massUnsubscribe'),
223
- 'confirm' => Mage::helper('budgetmailer')->__('Are you sure?')
224
- )
225
- );
226
-
227
- $this->getMassactionBlock()->addItem(
228
- 'deleteunsubscribe',
229
- array(
230
- 'label'=> Mage::helper('budgetmailer')->__('Delete and Unsubscribe from BudgetMailer'),
231
- 'url' => $this->getUrl('*/*/massDeleteUnsubscribe'),
232
- 'confirm' => Mage::helper('budgetmailer')->__('Are you sure?')
233
- )
234
- );
235
-
236
- $values = Mage::getResourceModel('budgetmailer/list_collection')
237
- ->toOptionHash();
238
- $values = array_reverse($values, true);
239
- $values[''] = '';
240
- $values = array_reverse($values, true);
241
-
242
- return $this;
243
- }
244
-
245
- /**
246
- * Get the row url
247
- *
248
- * @param Professio_BudgetMailer_Model_Contact
249
- * @return string
250
- */
251
- public function getRowUrl($row)
252
- {
253
- return $this->getUrl('*/*/edit', array('id' => $row->getId()));
254
- }
255
-
256
- /**
257
- * Get the grid url
258
- *
259
- * @return string
260
- */
261
- public function getGridUrl()
262
- {
263
- return $this->getUrl('*/*/grid', array('_current' => true));
264
- }
265
-
266
- /**
267
- * After collection load
268
- *
269
- * @return Professio_BudgetMailer_Block_Adminhtml_Contact_Grid
270
- */
271
- protected function _afterLoadCollection()
272
- {
273
- $this->getCollection()->walk('afterLoad');
274
-
275
- parent::_afterLoadCollection();
276
- }
277
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Customer/Tab.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -27,7 +27,7 @@ implements Mage_Adminhtml_Block_Widget_Tab_Interface
27
  {
28
  /**
29
  * Current contact
30
- * @var type Professio_BudgetMailer_Model_Contact
31
  */
32
  protected $_contact;
33
 
@@ -99,25 +99,6 @@ implements Mage_Adminhtml_Block_Widget_Tab_Interface
99
  return 'tags';
100
  }
101
 
102
- /**
103
- * Before to HTML
104
- *
105
- * @return void
106
- */
107
- protected function _beforeToHtml()
108
- {
109
- parent::_beforeToHtml();
110
-
111
- Mage::register('current_contact', $this->getContact());
112
-
113
- $block = $this->getLayout()
114
- ->createBlock(
115
- 'budgetmailer/adminhtml_contact_edit_tab_form',
116
- 'budgetmailer_customer_tab_edit'
117
- );
118
- $this->append($block, 'budgetmailer_customer_tab_edit');
119
- }
120
-
121
  /**
122
  * Get current contact
123
  *
@@ -126,8 +107,12 @@ implements Mage_Adminhtml_Block_Widget_Tab_Interface
126
  protected function getContact()
127
  {
128
  if (!isset($this->_contact)) {
129
- $this->_contact = Mage::getModel('budgetmailer/contact');
130
- $this->_contact->loadByCustomer($this->getCustomer());
 
 
 
 
131
  }
132
 
133
  return $this->_contact;
@@ -150,16 +135,12 @@ implements Mage_Adminhtml_Block_Widget_Tab_Interface
150
  */
151
  public function isSubscribed()
152
  {
153
- return !$this->getContact()->getUnsubscribed();
154
- }
155
-
156
- /**
157
- * Get current contact tags
158
- *
159
- * @return array
160
- */
161
- public function getTags()
162
- {
163
- return $this->getContact()->getTags();
164
  }
165
  }
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
27
  {
28
  /**
29
  * Current contact
30
+ * @var null|stdClass
31
  */
32
  protected $_contact;
33
 
99
  return 'tags';
100
  }
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  /**
103
  * Get current contact
104
  *
107
  protected function getContact()
108
  {
109
  if (!isset($this->_contact)) {
110
+ $client = Mage::getSingleton('budgetmailer/client')
111
+ ->getStoreClient($this->getCustomer()->getStoreId());
112
+
113
+ $this->_contact = $client->getContact(
114
+ $this->getCustomer()->getEmail()
115
+ );
116
  }
117
 
118
  return $this->_contact;
135
  */
136
  public function isSubscribed()
137
  {
138
+ $contact = $this->getContact();
139
+
140
+ if ($contact) {
141
+ return !$contact->unsubscribed;
142
+ }
143
+
144
+ return false;
 
 
 
 
145
  }
146
  }
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Export.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Professio_BudgetMailer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
+ *
12
+ * @category Professio
13
+ * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
+ */
17
+
18
+ /**
19
+ * Export page template
20
+ *
21
+ * @category Professio
22
+ * @package Professio_BudgetMailer
23
+ */
24
+ class Professio_BudgetMailer_Block_Adminhtml_Export
25
+ extends Mage_Adminhtml_Block_Template
26
+ {
27
+
28
+ }
app/code/community/Professio/BudgetMailer/Block/Adminhtml/Helper/Column/Renderer/Parent.php DELETED
@@ -1,95 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Parent entities column renderer
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_Helper_Column_Renderer_Parent
25
- extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Options
26
- {
27
- /**
28
- * Render the column
29
- *
30
- * @param Varien_Object $row
31
- * @return string
32
- */
33
- public function render(Varien_Object $row)
34
- {
35
- $base = $this->getColumn()->getBaseLink();
36
-
37
- if (!$base) {
38
- return parent::render($row);
39
- }
40
-
41
- $options = $this->getColumn()->getOptions();
42
-
43
- if (!empty($options) && is_array($options)) {
44
- return $this->renderOptions($options, $row);
45
- }
46
- }
47
-
48
- /**
49
- * Get params from row
50
- *
51
- * @param array $paramsData
52
- * @param object $row
53
- * @return array
54
- */
55
- public function getParams($paramsData, $row)
56
- {
57
- $params = array();
58
-
59
- if (is_array($paramsData)) {
60
- foreach ($paramsData as $name=>$getter) {
61
- if (is_callable(array($row, $getter))) {
62
- $params[$name] = $row->{$getter}();
63
- }
64
- }
65
- }
66
-
67
- $staticParamsData = $this->getColumn()->getData('static');
68
-
69
- if (is_array($staticParamsData)) {
70
- foreach ($staticParamsData as $key=>$value) {
71
- $params[$key] = $value;
72
- }
73
- }
74
-
75
- return $params;
76
- }
77
-
78
- /**
79
- * Render options...
80
- *
81
- * @param aray $options
82
- * @param type $row
83
- * @return type
84
- */
85
- protected function renderOptions($options, $row)
86
- {
87
- $value = $row->getData($this->getColumn()->getIndex());
88
-
89
- if (isset($options[$value])) {
90
- return $options[$value];
91
- } elseif (in_array($value, $options)) {
92
- return $value;
93
- }
94
- }
95
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/List.php DELETED
@@ -1,46 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List admin block
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_List
25
- extends Mage_Adminhtml_Block_Widget_Grid_Container
26
- {
27
- /**
28
- * Constructor
29
- *
30
- * @return void
31
- */
32
- public function __construct()
33
- {
34
- $this->_controller = 'adminhtml_list';
35
- $this->_blockGroup = 'budgetmailer';
36
-
37
- parent::__construct();
38
-
39
- $this->_headerText = Mage::helper('budgetmailer')->__('List');
40
- $this->_updateButton(
41
- 'add',
42
- 'label',
43
- Mage::helper('budgetmailer')->__('Add List')
44
- );
45
- }
46
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Edit.php DELETED
@@ -1,82 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List admin edit form
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_List_Edit
25
- extends Mage_Adminhtml_Block_Widget_Form_Container
26
- {
27
- /**
28
- * Constructor
29
- *
30
- * @access public
31
- * @return void
32
- */
33
- public function __construct()
34
- {
35
- parent::__construct();
36
-
37
- $this->_blockGroup = 'budgetmailer';
38
- $this->_controller = 'adminhtml_list';
39
-
40
- $this->_updateButton(
41
- 'save', 'label', Mage::helper('budgetmailer')->__('Save List')
42
- );
43
- $this->_updateButton(
44
- 'delete', 'label', Mage::helper('budgetmailer')->__('Delete List')
45
- );
46
-
47
- $this->_addButton(
48
- 'saveandcontinue', array(
49
- 'label' => Mage::helper('budgetmailer')
50
- ->__('Save And Continue Edit'),
51
- 'onclick' => 'saveAndContinueEdit()',
52
- 'class' => 'save',
53
- ),
54
- -100
55
- );
56
-
57
- $this->_formScripts[] = "
58
- function saveAndContinueEdit(){
59
- editForm.submit($('edit_form').action+'back/edit/');
60
- }
61
- ";
62
- }
63
-
64
- /**
65
- * get the edit form header
66
- *
67
- * @return string
68
- */
69
- public function getHeaderText()
70
- {
71
- if (Mage::registry('current_list')
72
- && Mage::registry('current_list')->getId()) {
73
- return Mage::helper('budgetmailer')
74
- ->__(
75
- "Edit List '%s'",
76
- $this->escapeHtml(Mage::registry('current_list')->getName())
77
- );
78
- } else {
79
- return Mage::helper('budgetmailer')->__('Add List');
80
- }
81
- }
82
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Edit/Form.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List edit form
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_List_Edit_Form
25
- extends Mage_Adminhtml_Block_Widget_Form
26
- {
27
- /**
28
- * Prepare form
29
- *
30
- * @return Professio_BudgetMailer_Block_Adminhtml_List_Edit_Form
31
- */
32
- protected function _prepareForm()
33
- {
34
- $form = new Varien_Data_Form(
35
- array(
36
- 'id' => 'edit_form',
37
- 'action' => $this->getUrl(
38
- '*/*/save',
39
- array('id' => $this->getRequest()->getParam('id'))
40
- ),
41
- 'method' => 'post',
42
- 'enctype' => 'multipart/form-data'
43
- )
44
- );
45
-
46
- $form->setUseContainer(true);
47
- $this->setForm($form);
48
-
49
- return parent::_prepareForm();
50
- }
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Edit/Tab/Form.php DELETED
@@ -1,110 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List edit form tab
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_List_Edit_Tab_Form
25
- extends Mage_Adminhtml_Block_Widget_Form
26
- {
27
- /**
28
- * Prepare the form
29
- *
30
- * @return Professio_BudgetMailer_Block_Adminhtml_List_Edit_Tab_Form
31
- */
32
- protected function _prepareForm()
33
- {
34
- $form = new Varien_Data_Form();
35
-
36
- $form->setHtmlIdPrefix('list_');
37
- $form->setFieldNameSuffix('list');
38
-
39
- $this->setForm($form);
40
-
41
- $fieldset = $form->addFieldset(
42
- 'list_form',
43
- array('legend' => Mage::helper('budgetmailer')->__('List'))
44
- );
45
-
46
- $fieldset->addField(
47
- 'budgetmailer_id',
48
- 'text',
49
- array(
50
- 'label' => Mage::helper('budgetmailer')->__('Budgetmailer ID'),
51
- 'name' => 'budgetmailer_id',
52
- 'required' => true,
53
- 'class' => 'required-entry',
54
- )
55
- );
56
-
57
- $fieldset->addField(
58
- 'name',
59
- 'text',
60
- array(
61
- 'label' => Mage::helper('budgetmailer')->__('Name'),
62
- 'name' => 'name',
63
- 'required' => true,
64
- 'class' => 'required-entry',
65
- )
66
- );
67
-
68
- $fieldset->addField(
69
- 'status',
70
- 'select',
71
- array(
72
- 'label' => Mage::helper('budgetmailer')->__('Status'),
73
- 'name' => 'status',
74
- 'values'=> array(
75
- array(
76
- 'value' => 1,
77
- 'label' => Mage::helper('budgetmailer')->__('Enabled'),
78
- ),
79
- array(
80
- 'value' => 0,
81
- 'label' => Mage::helper('budgetmailer')->__('Disabled'),
82
- ),
83
- ),
84
- )
85
- );
86
-
87
- $formValues = Mage::registry('current_list')->getDefaultValues();
88
-
89
- if (!is_array($formValues)) {
90
- $formValues = array();
91
- }
92
-
93
- if (Mage::getSingleton('adminhtml/session')->getListData()) {
94
- $formValues = array_merge(
95
- $formValues,
96
- Mage::getSingleton('adminhtml/session')->getListData()
97
- );
98
- Mage::getSingleton('adminhtml/session')->setListData(null);
99
- } elseif (Mage::registry('current_list')) {
100
- $formValues = array_merge(
101
- $formValues,
102
- Mage::registry('current_list')->getData()
103
- );
104
- }
105
-
106
- $form->setValues($formValues);
107
-
108
- return parent::_prepareForm();
109
- }
110
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Edit/Tabs.php DELETED
@@ -1,68 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List admin edit tabs
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_List_Edit_Tabs
25
- extends Mage_Adminhtml_Block_Widget_Tabs
26
- {
27
- /**
28
- * Constructor
29
- */
30
- public function __construct()
31
- {
32
- parent::__construct();
33
-
34
- $this->setId('list_tabs');
35
- $this->setDestElementId('edit_form');
36
- $this->setTitle(Mage::helper('budgetmailer')->__('List'));
37
- }
38
-
39
- /**
40
- * Before render html
41
- *
42
- * @return Professio_BudgetMailer_Block_Adminhtml_List_Edit_Tabs
43
- */
44
- protected function _beforeToHtml()
45
- {
46
- $this->addTab(
47
- 'form_list', array(
48
- 'label' => Mage::helper('budgetmailer')->__('List'),
49
- 'title' => Mage::helper('budgetmailer')->__('List'),
50
- 'content' => $this->getLayout()
51
- ->createBlock('budgetmailer/adminhtml_list_edit_tab_form')
52
- ->toHtml(),
53
- )
54
- );
55
-
56
- return parent::_beforeToHtml();
57
- }
58
-
59
- /**
60
- * Retrieve list entity
61
- *
62
- * @return Professio_BudgetMailer_Model_List
63
- */
64
- public function getList()
65
- {
66
- return Mage::registry('current_list');
67
- }
68
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/Adminhtml/List/Grid.php DELETED
@@ -1,222 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List admin grid block
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Block_Adminhtml_List_Grid
25
- extends Mage_Adminhtml_Block_Widget_Grid
26
- {
27
- /**
28
- * Constructor
29
- *
30
- * @return void
31
- */
32
- public function __construct()
33
- {
34
- parent::__construct();
35
-
36
- $this->setId('listGrid');
37
- $this->setDefaultSort('entity_id');
38
- $this->setDefaultDir('ASC');
39
- $this->setSaveParametersInSession(true);
40
- $this->setUseAjax(true);
41
- }
42
-
43
- /**
44
- * Prepare collection
45
- *
46
- * @return Professio_BudgetMailer_Block_Adminhtml_List_Grid
47
- */
48
- protected function _prepareCollection()
49
- {
50
- $collection = Mage::getModel('budgetmailer/list')->getCollection();
51
- $this->setCollection($collection);
52
- return parent::_prepareCollection();
53
- }
54
-
55
- /**
56
- * Prepare grid collection
57
- *
58
- * @return Professio_BudgetMailer_Block_Adminhtml_List_Grid
59
- */
60
- protected function _prepareColumns()
61
- {
62
- $this->addColumn(
63
- 'entity_id',
64
- array(
65
- 'header' => Mage::helper('budgetmailer')->__('Id'),
66
- 'index' => 'entity_id',
67
- 'type' => 'number'
68
- )
69
- );
70
-
71
- $this->addColumn(
72
- 'name',
73
- array(
74
- 'header' => Mage::helper('budgetmailer')->__('Name'),
75
- 'align' => 'left',
76
- 'index' => 'name',
77
- )
78
- );
79
-
80
- $this->addColumn(
81
- 'status',
82
- array(
83
- 'header' => Mage::helper('budgetmailer')->__('Status'),
84
- 'index' => 'status',
85
- 'type' => 'options',
86
- 'options' => array(
87
- '1' => Mage::helper('budgetmailer')->__('Enabled'),
88
- '0' => Mage::helper('budgetmailer')->__('Disabled'),
89
- )
90
- )
91
- );
92
-
93
- $this->addColumn(
94
- 'budgetmailer_id', array(
95
- 'header'=> Mage::helper('budgetmailer')->__('Budgetmailer ID'),
96
- 'index' => 'budgetmailer_id',
97
- 'type'=> 'text',
98
-
99
- )
100
- );
101
-
102
- $this->addColumn(
103
- 'created_at',
104
- array(
105
- 'header' => Mage::helper('budgetmailer')->__('Created at'),
106
- 'index' => 'created_at',
107
- 'width' => '120px',
108
- 'type' => 'datetime',
109
- )
110
- );
111
-
112
- $this->addColumn(
113
- 'updated_at',
114
- array(
115
- 'header' => Mage::helper('budgetmailer')->__('Updated at'),
116
- 'index' => 'updated_at',
117
- 'width' => '120px',
118
- 'type' => 'datetime',
119
- )
120
- );
121
-
122
- $this->addColumn(
123
- 'action',
124
- array(
125
- 'header'=> Mage::helper('budgetmailer')->__('Action'),
126
- 'width' => '100',
127
- 'type' => 'action',
128
- 'getter'=> 'getId',
129
- 'actions' => array(
130
- array(
131
- 'caption' => Mage::helper('budgetmailer')->__('Edit'),
132
- 'url' => array('base'=> '*/*/edit'),
133
- 'field' => 'id'
134
- )
135
- ),
136
- 'filter'=> false,
137
- 'is_system' => true,
138
- 'sortable' => false,
139
- )
140
- );
141
-
142
- return parent::_prepareColumns();
143
- }
144
-
145
- /**
146
- * Prepare mass action
147
- *
148
- * @return Professio_BudgetMailer_Block_Adminhtml_List_Grid
149
- */
150
- protected function _prepareMassaction()
151
- {
152
- $this->setMassactionIdField('entity_id');
153
- $this->getMassactionBlock()->setFormFieldName('list');
154
-
155
- $this->getMassactionBlock()->addItem(
156
- 'delete',
157
- array(
158
- 'label'=> Mage::helper('budgetmailer')->__('Delete'),
159
- 'url' => $this->getUrl('*/*/massDelete'),
160
- 'confirm' => Mage::helper('budgetmailer')->__('Are you sure?')
161
- )
162
- );
163
-
164
- $this->getMassactionBlock()->addItem(
165
- 'status',
166
- array(
167
- 'label'=> Mage::helper('budgetmailer')->__('Change status'),
168
- 'url' => $this->getUrl(
169
- '*/*/massStatus',
170
- array('_current'=>true)
171
- ),
172
- 'additional' => array(
173
- 'status' => array(
174
- 'name' => 'status',
175
- 'type' => 'select',
176
- 'class' => 'required-entry',
177
- 'label' => Mage::helper('budgetmailer')->__('Status'),
178
- 'values' => array(
179
- '1' => Mage::helper('budgetmailer')->__('Enabled'),
180
- '0' => Mage::helper('budgetmailer')->__('Disabled'),
181
- )
182
- )
183
- )
184
- )
185
- );
186
-
187
- return $this;
188
- }
189
-
190
- /**
191
- * Get the row url
192
- *
193
- * @param Professio_BudgetMailer_Model_List
194
- * @return string
195
- */
196
- public function getRowUrl($row)
197
- {
198
- return $this->getUrl('*/*/edit', array('id' => $row->getId()));
199
- }
200
-
201
- /**
202
- * Get the grid url
203
- *
204
- * @return string
205
- */
206
- public function getGridUrl()
207
- {
208
- return $this->getUrl('*/*/grid', array('_current'=>true));
209
- }
210
-
211
- /**
212
- * After collection load
213
- *
214
- * @return Professio_BudgetMailer_Block_Adminhtml_List_Grid
215
- */
216
- protected function _afterLoadCollection()
217
- {
218
- $this->getCollection()->walk('afterLoad');
219
-
220
- parent::_afterLoadCollection();
221
- }
222
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Block/CheckoutAgreements.php CHANGED
@@ -5,23 +5,25 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
19
- * Override of checkout agreements allowing newsletter sign-up for onepage checkout.
 
20
  *
21
  * @category Professio
22
  * @package Professio_BudgetMailer
23
  */
24
- class Professio_BudgetMailer_Block_CheckoutAgreements extends Mage_Checkout_Block_Agreements
 
25
  {
26
  /**
27
  * Override block template
@@ -30,9 +32,12 @@ class Professio_BudgetMailer_Block_CheckoutAgreements extends Mage_Checkout_Bloc
30
  */
31
  protected function _toHtml()
32
  {
33
- if (substr_count($_SERVER['REQUEST_URI'], 'onepage')) {
 
 
34
  $this->setTemplate('budgetmailer/onepage-agreements.phtml');
35
  }
 
36
  return parent::_toHtml();
37
  }
38
 
@@ -40,13 +45,20 @@ class Professio_BudgetMailer_Block_CheckoutAgreements extends Mage_Checkout_Bloc
40
  * Check if customer is signed up
41
  * @return bool
42
  */
43
- public function isCurrentCustomerSignedUp() {
44
- if(Mage::getSingleton('customer/session')->isLoggedIn()) {
 
45
  $customer = Mage::getSingleton('customer/session')->getCustomer();
46
- $contact = Mage::getModel('budgetmailer/contact');
47
- $contact->loadByCustomer($customer);
48
 
49
- return $contact->getId() > 0;
 
 
 
 
 
 
 
 
50
  }
51
 
52
  return false;
@@ -56,8 +68,9 @@ class Professio_BudgetMailer_Block_CheckoutAgreements extends Mage_Checkout_Bloc
56
  * Check if sign-up is hidden
57
  * @return bool
58
  */
59
- public function isSignupHidden() {
60
- return Professio_BudgetMailer_Model_Config_Source_Account::HIDDENCHECKED
 
61
  == Mage::helper('budgetmailer/config')->getAdvancedCreateAccount();
62
  }
63
 
@@ -65,12 +78,15 @@ class Professio_BudgetMailer_Block_CheckoutAgreements extends Mage_Checkout_Bloc
65
  * Check if sign-up is checked
66
  * @return bool
67
  */
68
- public function isSignupChecked() {
 
69
  $v = Mage::helper('budgetmailer/config')->getAdvancedCreateAccount();
70
 
71
  return
72
- Professio_BudgetMailer_Model_Config_Source_Account::HIDDENCHECKED == $v
73
- || Professio_BudgetMailer_Model_Config_Source_Account::CHECKED == $v;
 
 
74
  }
75
 
76
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
19
+ * Override of checkout agreements allowing newsletter sign-up
20
+ * for onepage checkout.
21
  *
22
  * @category Professio
23
  * @package Professio_BudgetMailer
24
  */
25
+ class Professio_BudgetMailer_Block_CheckoutAgreements
26
+ extends Mage_Checkout_Block_Agreements
27
  {
28
  /**
29
  * Override block template
32
  */
33
  protected function _toHtml()
34
  {
35
+ $uri = filter_input(INPUT_SERVER, 'REQUEST_URI');
36
+
37
+ if (substr_count($uri, 'onepage')) {
38
  $this->setTemplate('budgetmailer/onepage-agreements.phtml');
39
  }
40
+
41
  return parent::_toHtml();
42
  }
43
 
45
  * Check if customer is signed up
46
  * @return bool
47
  */
48
+ public function isCurrentCustomerSignedUp()
49
+ {
50
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
51
  $customer = Mage::getSingleton('customer/session')->getCustomer();
 
 
52
 
53
+ if ($customer) {
54
+ $client = Mage::getSingleton('budgetmailer/client')
55
+ ->getClient();
56
+ $contact = $client->getContact($customer->getEmail());
57
+
58
+ if ($contact && !$contact->unsubscribed) {
59
+ return true;
60
+ }
61
+ }
62
  }
63
 
64
  return false;
68
  * Check if sign-up is hidden
69
  * @return bool
70
  */
71
+ public function isSignupHidden()
72
+ {
73
+ return Professio_BudgetMailer_Model_Config_Source_Account::HIDDENCHECKED
74
  == Mage::helper('budgetmailer/config')->getAdvancedCreateAccount();
75
  }
76
 
78
  * Check if sign-up is checked
79
  * @return bool
80
  */
81
+ public function isSignupChecked()
82
+ {
83
  $v = Mage::helper('budgetmailer/config')->getAdvancedCreateAccount();
84
 
85
  return
86
+ Professio_BudgetMailer_Model_Config_Source_Account::HIDDENCHECKED
87
+ == $v
88
+ || Professio_BudgetMailer_Model_Config_Source_Account::CHECKED
89
+ == $v;
90
  }
91
 
92
  /**
app/code/community/Professio/BudgetMailer/Block/Newsletter.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -60,25 +60,10 @@ class Professio_BudgetMailer_Block_Newsletter extends Mage_Core_Block_Template
60
  return Mage::helper('budgetmailer/config');
61
  }
62
 
63
- /**
64
- * Get current contact
65
- *
66
- * @return Professio_BudgetMailer_Model_Contact
67
- */
68
- protected function getContact()
69
- {
70
- if (!isset($this->_contact)) {
71
- $this->_contact = Mage::getModel('budgetmailer/contact');
72
- $this->_contact->loadByCustomer($this->getCustomer());
73
- }
74
-
75
- return $this->_contact;
76
- }
77
-
78
  /**
79
  * Get current customer
80
  *
81
- * @return Professio_Customer_Model_Customer
82
  */
83
  protected function getCustomer()
84
  {
@@ -93,9 +78,13 @@ class Professio_BudgetMailer_Block_Newsletter extends Mage_Core_Block_Template
93
  public function isSubscribed()
94
  {
95
  if (!isset($this->isSubscribed)) {
96
- $this->isSubscribed = $this->getContact()
97
- && $this->getContact()->getEntityId()
98
- && !$this->getContact()->getUnsubscribed();
 
 
 
 
99
  }
100
 
101
  return $this->isSubscribed;
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
60
  return Mage::helper('budgetmailer/config');
61
  }
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  /**
64
  * Get current customer
65
  *
66
+ * @return Mage_Customer_Model_Customer
67
  */
68
  protected function getCustomer()
69
  {
78
  public function isSubscribed()
79
  {
80
  if (!isset($this->isSubscribed)) {
81
+ $contact = Mage::getSingleton('budgetmailer/client')->getClient()
82
+ ->getContact(
83
+ $this->getCustomer()->getEmail(),
84
+ $this->getConfigHelper()->getGeneralList()
85
+ );
86
+
87
+ $this->isSubscribed = $contact ? !$contact->unsubscribed : false;
88
  }
89
 
90
  return $this->isSubscribed;
app/code/community/Professio/BudgetMailer/Block/Subscribe.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/code/community/Professio/BudgetMailer/Block/Subscribe/Mini.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -46,8 +46,9 @@ extends Mage_Core_Block_Template
46
  * Check if sign-up is hidden
47
  * @return bool
48
  */
49
- public function isSignupHidden() {
50
- return Professio_BudgetMailer_Model_Config_Source_Account::HIDDENCHECKED
 
51
  == Mage::helper('budgetmailer/config')->getAdvancedCreateAccount();
52
  }
53
 
@@ -55,11 +56,14 @@ extends Mage_Core_Block_Template
55
  * Check if sign-up is checked
56
  * @return bool
57
  */
58
- public function isSignupChecked() {
 
59
  $v = Mage::helper('budgetmailer/config')->getAdvancedCreateAccount();
60
 
61
  return
62
- Professio_BudgetMailer_Model_Config_Source_Account::HIDDENCHECKED == $v
63
- || Professio_BudgetMailer_Model_Config_Source_Account::CHECKED == $v;
 
 
64
  }
65
  }
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
46
  * Check if sign-up is hidden
47
  * @return bool
48
  */
49
+ public function isSignupHidden()
50
+ {
51
+ return Professio_BudgetMailer_Model_Config_Source_Account::HIDDENCHECKED
52
  == Mage::helper('budgetmailer/config')->getAdvancedCreateAccount();
53
  }
54
 
56
  * Check if sign-up is checked
57
  * @return bool
58
  */
59
+ public function isSignupChecked()
60
+ {
61
  $v = Mage::helper('budgetmailer/config')->getAdvancedCreateAccount();
62
 
63
  return
64
+ Professio_BudgetMailer_Model_Config_Source_Account::HIDDENCHECKED
65
+ == $v
66
+ || Professio_BudgetMailer_Model_Config_Source_Account::CHECKED
67
+ == $v;
68
  }
69
  }
app/code/community/Professio/BudgetMailer/Controller/Adminhtml/BudgetMailer.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -25,36 +25,12 @@ class Professio_BudgetMailer_Controller_Adminhtml_BudgetMailer
25
  extends Mage_Adminhtml_Controller_Action
26
  {
27
  /**
28
- * Upload file and get the uploaded name
29
- *
30
- * @param string $input
31
- * @param string $destinationFolder
32
- * @param array $data
33
- * @return string
34
  */
35
- protected function _uploadAndGetName($input, $destinationFolder, $data)
36
  {
37
- try{
38
- if (isset($data[$input]['delete'])) {
39
- return '';
40
- } else {
41
- $uploader = new Varien_File_Uploader($input);
42
- $uploader->setAllowRenameFiles(true);
43
- $uploader->setFilesDispersion(true);
44
- $uploader->setAllowCreateFolders(true);
45
- $result = $uploader->save($destinationFolder);
46
- return $result['file'];
47
- }
48
- }
49
- catch (Exception $e) {
50
- if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
51
- throw $e;
52
- } else {
53
- if (isset($data[$input]['value'])) {
54
- return $data[$input]['value'];
55
- }
56
- }
57
- }
58
- return '';
59
  }
60
  }
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
25
  extends Mage_Adminhtml_Controller_Action
26
  {
27
  /**
28
+ * Check if current user is allowed to use this controller.
29
+ * @return boolean
 
 
 
 
30
  */
31
+ protected function _isAllowed()
32
  {
33
+ return Mage::getSingleton('admin/session')
34
+ ->isAllowed('admin/system/convert/professio_budgetmailer');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
  }
app/code/community/Professio/BudgetMailer/Exception.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/code/community/Professio/BudgetMailer/Form/Element/Tags.php DELETED
@@ -1,103 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List collection resource
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Form_Element_Tags
25
- extends Varien_Data_Form_Element_Abstract
26
- {
27
- /**
28
- * Constructor
29
- * @param array $data
30
- */
31
- public function __construct($data)
32
- {
33
- parent::__construct($data);
34
-
35
- $this->setType('budgetmailer_tags');
36
- }
37
-
38
- /**
39
- * Get element html
40
- *
41
- * @return string
42
- */
43
- public function getElementHtml()
44
- {
45
- $html = '<div id="budgetmailer_tags">';
46
- $html .= '<!--<input id="budgetmailer_tags_remove" '
47
- . 'name="tags_remove" type="hidden"/>-->';
48
-
49
- $html .= '<script type="text/javascript">
50
- var $budgetmailer_tags = $("budgetmailer_tags");
51
- //var $budgetmailer_tags_remove = $("budgetmailer_tags_remove");
52
-
53
- function budgetmailer_new(el) {
54
- $budgetmailer_tags.insert("<input name=\"'
55
- . $this->getName()
56
- . '[]\" type=\"text\" value=\"\"/> <button class=\"budgetmailer-remove\" '
57
- . 'onclick=\"return budgetmailer_remove(this);\">'
58
- . Mage::helper('budgetmailer')->__('Remove')
59
- . '</button><br>");
60
-
61
- return false;
62
- }
63
-
64
- function budgetmailer_remove(el) {
65
- var button = $(el);
66
- var input = button.previous("input");
67
- var br = button.next("br");
68
- //var remove = $budgetmailer_tags_remove.getValue();
69
- //$budgetmailer_tags_remove.setValue(remove + "," + input.getValue());
70
-
71
- button.remove();
72
- $(input).remove();
73
- $(br).remove();
74
-
75
- return false;
76
- }
77
- </script>';
78
-
79
- $html .= '<button id="budgetmailer_add" onclick="return '
80
- . 'budgetmailer_new(this);">'
81
- . Mage::helper('budgetmailer')->__('Add Tag')
82
- . '</button><br>';
83
-
84
- if (is_array($this->getValue()) && count($this->getValue())) {
85
- foreach ($this->getValue() as $tag) {
86
- $html .= '<input name="'
87
- . $this->getName()
88
- . '[]" type="text" value="'
89
- . $tag
90
- . '"/> <button class="budgetmailer-remove" '
91
- . 'onclick="return budgetmailer_remove(this);">'
92
- . Mage::helper('budgetmailer')->__('Remove')
93
- . '</button><br>';
94
- }
95
- } else {
96
- $html .= Mage::helper('budgetmailer')->__('No Tags');
97
- }
98
-
99
- $html .= '</div>';
100
-
101
- return $html;
102
- }
103
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Helper/Config.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -44,9 +44,8 @@ class Professio_BudgetMailer_Helper_Config extends Mage_Core_Helper_Abstract
44
 
45
  const CONFIG_PATH_GENERAL_LIST = 'budgetmailer/general/list';
46
 
47
- const CONFIG_PATH_SYNC_CRON = 'budgetmailer/sync/cron';
48
- const CONFIG_PATH_SYNC_WEBHOOK = 'budgetmailer/sync/webhook';
49
- const CONFIG_PATH_SYNC_TTL = 'budgetmailer/sync/ttl';
50
 
51
  /**
52
  * Get address type
@@ -61,8 +60,33 @@ class Professio_BudgetMailer_Helper_Config extends Mage_Core_Helper_Abstract
61
  /**
62
  * Get sign-up configuration while creating an account
63
  */
64
- public function getAdvancedCreateAccount() {
65
- return Mage::getStoreConfig(self::CONFIG_PATH_ADVANCED_ON_CREATE_ACCOUNT);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
 
68
  /**
@@ -109,6 +133,23 @@ class Professio_BudgetMailer_Helper_Config extends Mage_Core_Helper_Abstract
109
  return $c == $v;
110
  }
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  /**
113
  * Get on customer update enabled
114
  *
@@ -138,6 +179,30 @@ class Professio_BudgetMailer_Helper_Config extends Mage_Core_Helper_Abstract
138
  );
139
  }
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  /**
142
  * Get API endpoint
143
  *
@@ -171,49 +236,44 @@ class Professio_BudgetMailer_Helper_Config extends Mage_Core_Helper_Abstract
171
  /**
172
  * Get API list
173
  *
174
- * @return string
 
175
  * @throws Professio_BudgetMailer_Exception
176
  */
177
- public function getGeneralList()
178
  {
179
  $generalList = Mage::getStoreConfig(self::CONFIG_PATH_GENERAL_LIST);
180
 
181
  if (empty($generalList)) {
182
- throw new Professio_BudgetMailer_Exception(
183
- $this->__('BudgetMailer list is not set.')
184
- );
 
 
 
 
185
  }
186
 
187
  return $generalList;
188
  }
189
 
190
  /**
191
- * Get sync cron
192
  *
193
- * @return boolean
194
- */
195
- public function isSyncCronEnabled()
196
- {
197
- return Mage::getStoreConfig(self::CONFIG_PATH_SYNC_CRON);
198
- }
199
-
200
- /**
201
- * Get sync webhook
202
- *
203
- * @return boolean
204
  */
205
- public function isSyncWebhookEnabled()
206
  {
207
- return Mage::getStoreConfig(self::CONFIG_PATH_SYNC_WEBHOOK);
208
  }
209
 
210
  /**
211
- * Get sync ttl
212
  *
213
  * @return integer
214
  */
215
- public function getSyncTtl()
216
  {
217
- return Mage::getStoreConfig(self::CONFIG_PATH_SYNC_TTL);
218
  }
219
  }
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
44
 
45
  const CONFIG_PATH_GENERAL_LIST = 'budgetmailer/general/list';
46
 
47
+ const CONFIG_PATH_CACHE_ENABLED = 'budgetmailer/cache/enabled';
48
+ const CONFIG_PATH_CACHE_TTL = 'budgetmailer/cache/ttl';
 
49
 
50
  /**
51
  * Get address type
60
  /**
61
  * Get sign-up configuration while creating an account
62
  */
63
+ public function getAdvancedCreateAccount()
64
+ {
65
+ return Mage::getStoreConfig(
66
+ self::CONFIG_PATH_ADVANCED_ON_CREATE_ACCOUNT
67
+ );
68
+ }
69
+
70
+ /**
71
+ * Get if selected address type is billing
72
+ *
73
+ * @return boolean
74
+ */
75
+ public function isAddressTypeBilling()
76
+ {
77
+ return $this->getAdvancedAddressType() ==
78
+ Professio_BudgetMailer_Model_Config_Source_Address::BILLING;
79
+ }
80
+
81
+ /**
82
+ * Get if selected address type is shipping
83
+ *
84
+ * @return boolean
85
+ */
86
+ public function isAddressTypeShipping()
87
+ {
88
+ return $this->getAdvancedAddressType() ==
89
+ Professio_BudgetMailer_Model_Config_Source_Address::SHIPPING;
90
  }
91
 
92
  /**
133
  return $c == $v;
134
  }
135
 
136
+ /**
137
+ * Get on customer delete and unsubscribe enabled
138
+ *
139
+ * @return boolean
140
+ */
141
+ public function isAdvancedOnCustomerDeleteUnsubscribeEnabled()
142
+ {
143
+ $c = Professio_BudgetMailer_Model_Config_Source_Delete
144
+ ::ON_DELETE_DEL_UNSUB;
145
+
146
+ $v = Mage::getStoreConfig(
147
+ self::CONFIG_PATH_ADVANCED_ON_CUSTOMER_DELETE
148
+ );
149
+
150
+ return $c == $v;
151
+ }
152
+
153
  /**
154
  * Get on customer update enabled
155
  *
179
  );
180
  }
181
 
182
+ /**
183
+ * Get config for budgetmailer client.
184
+ *
185
+ * @return array associative array
186
+ */
187
+ public function getApiConfig()
188
+ {
189
+ return array(
190
+ 'cache' => $this->isCacheEnabled(),
191
+ 'cacheDir' => Mage::getBaseDir('var') . '/cache/bm/',
192
+ 'endPoint' => $this->getApiEndpoint(),
193
+ 'key' => $this->getApiKey(),
194
+ // name of the budgetmailer list you want to use as a default
195
+ 'list' => $this->getGeneralList(false),
196
+ // your API secret
197
+ 'secret' => $this->getApiSecret(),
198
+ // advanced: socket timeout
199
+ 'timeOutSocket' => 10,
200
+ // advanced: socket stream read timeout
201
+ 'timeOutStream' => 10,
202
+ 'ttl' => $this->getCacheTtl(),
203
+ );
204
+ }
205
+
206
  /**
207
  * Get API endpoint
208
  *
236
  /**
237
  * Get API list
238
  *
239
+ * @param boolean $throwException throw exception if list not set
240
+ * @return null|string null (if false = $throwException) or list string
241
  * @throws Professio_BudgetMailer_Exception
242
  */
243
+ public function getGeneralList($throwException = true)
244
  {
245
  $generalList = Mage::getStoreConfig(self::CONFIG_PATH_GENERAL_LIST);
246
 
247
  if (empty($generalList)) {
248
+ if ($throwException) {
249
+ throw new Professio_BudgetMailer_Exception(
250
+ $this->__('BudgetMailer list is not set.')
251
+ );
252
+ } else {
253
+ $generalList = null;
254
+ }
255
  }
256
 
257
  return $generalList;
258
  }
259
 
260
  /**
261
+ * Get cache enabled
262
  *
263
+ * @return integer
 
 
 
 
 
 
 
 
 
 
264
  */
265
+ public function isCacheEnabled()
266
  {
267
+ return Mage::getStoreConfig(self::CONFIG_PATH_CACHE_ENABLED);
268
  }
269
 
270
  /**
271
+ * Get cache ttl
272
  *
273
  * @return integer
274
  */
275
+ public function getCacheTtl()
276
  {
277
+ return Mage::getStoreConfig(self::CONFIG_PATH_CACHE_TTL);
278
  }
279
  }
app/code/community/Professio/BudgetMailer/Helper/Data.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -112,27 +112,14 @@ class Professio_BudgetMailer_Helper_Data extends Mage_Core_Helper_Abstract
112
  }
113
 
114
  /**
115
- * Get default website id
116
- *
117
- * @return integer
118
  */
119
- public function getDefaultWebsiteId()
120
- {
121
- $resource = Mage::getSingleton('core/resource');
122
- $sql = 'SELECT * FROM ' . $resource->getTableName('core/store')
123
- . ' WHERE `code` = "default"';
124
-
125
- $connection = Mage::getSingleton('core/resource')
126
- ->getConnection('core_read');
127
-
128
- $row = $connection->fetchOne($sql);
129
-
130
- return $row ? $row : 1;
131
- }
132
-
133
  public function getCategoryNamesOfOrderedProducts(
134
  Mage_Customer_Model_Customer $customer
135
- ) {
 
136
  $states = Mage::getSingleton('sales/order_config')
137
  ->getVisibleOnFrontStates();
138
 
@@ -146,7 +133,7 @@ class Professio_BudgetMailer_Helper_Data extends Mage_Core_Helper_Abstract
146
 
147
  $tags = array();
148
 
149
- foreach($collection->getIterator() as $order) {
150
  $tags = array_merge($tags, $this->getOrderTags($order));
151
  }
152
 
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
112
  }
113
 
114
  /**
115
+ * Get list of category names of all ordered products by customer
116
+ * @param Mage_Customer_Model_Customer $customer
117
+ * @return type
118
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  public function getCategoryNamesOfOrderedProducts(
120
  Mage_Customer_Model_Customer $customer
121
+ )
122
+ {
123
  $states = Mage::getSingleton('sales/order_config')
124
  ->getVisibleOnFrontStates();
125
 
133
 
134
  $tags = array();
135
 
136
+ foreach ($collection->getIterator() as $order) {
137
  $tags = array_merge($tags, $this->getOrderTags($order));
138
  }
139
 
app/code/community/Professio/BudgetMailer/Helper/Mapper.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -25,79 +25,34 @@ class Professio_BudgetMailer_Helper_Mapper extends Mage_Core_Helper_Abstract
25
  {
26
  /**
27
  * Address model to contact model
28
- * @var array
29
  */
30
  protected $_addressToContact = array(
31
- 'companyName' => 'company',
32
  // INFO for now not replacing multiple to single line
33
- 'address' => 'street',
34
- 'postalCode' => 'postcode',
35
- 'city' => 'city',
36
- 'countryCode' => 'country_id',
37
- 'telephone' => 'telephone',
38
- );
39
-
40
- /**
41
- * INFO not mapping names, because they are coming from customer model
42
- *
43
- * Address contact to model
44
- * @var array
45
- */
46
- protected $_addressToModel = array(
47
- // 'firstname' => 'first_name',
48
- // 'lastname' => 'last_name',
49
- 'company' => 'company_name',
50
- 'city' => 'city',
51
- 'postcode' => 'postal_code',
52
- 'street' => 'address',
53
- 'telephone' => 'telephone',
54
- 'country_id' => 'country_code'
55
- );
56
-
57
- /**
58
- * Contact to model
59
- * @var array
60
- */
61
- protected $_contactToModel = array(
62
- 'id' => 'budgetmailer_id',
63
- 'list' => 'list_id',
64
-
65
- 'email' => 'email',
66
- // INFO not mapping company name, because the editable one is in address
67
- // kind of need this when saving customer address (on front-end)
68
- 'companyName' => 'company_name',
69
- 'firstName' => 'first_name',
70
- 'insertion' => 'insertion',
71
- 'lastName' => 'last_name',
72
- 'sex' => 'sex',
73
- 'address' => 'address',
74
- 'postalCode' => 'postal_code',
75
  'city' => 'city',
76
- 'countryCode' => 'country_code',
77
  'telephone' => 'telephone',
78
- 'mobile' => 'mobile',
79
- 'remarks' => 'remarks',
80
- 'tags' => 'tags',
81
- 'unsubscribed' => 'unsubscribed',
82
- 'subscribe' => 'subscribe'
83
  );
84
 
85
  /**
86
  * List of countries by id
87
  * @var array
88
  */
89
- protected $_countriesIdIso3 = array();
90
  /**
91
  * List of countries by ISO3 code
92
  * @var array
93
  */
94
- protected $_countriesIso3Id = array();
95
 
96
  /**
97
  * Customer model to API object
98
  * @var array
99
  */
100
- protected $_customerToApi = array(
101
  'email' => 'email',
102
  'firstname' => 'firstName',
103
  'middlename' => 'insertion',
@@ -105,18 +60,6 @@ class Professio_BudgetMailer_Helper_Mapper extends Mage_Core_Helper_Abstract
105
  'sex' => 'gender',
106
  );
107
 
108
- /**
109
- * Customer to contact model
110
- * @var array
111
- */
112
- protected $_customerToModel = array(
113
- 'email' => 'email',
114
- 'firstname' => 'first_name',
115
- 'middlename' => 'insertion',
116
- 'lastname' => 'last_name',
117
- 'gender' => 'sex'
118
- );
119
-
120
  /**
121
  * Map list ids to names
122
  * @var array
@@ -129,48 +72,17 @@ class Professio_BudgetMailer_Helper_Mapper extends Mage_Core_Helper_Abstract
129
  */
130
  protected $_listNameToId;
131
 
132
- /**
133
- * Map list ids to budgetmailer ids
134
- * @var array
135
- */
136
- protected $_listIdToBudgetmailerId;
137
-
138
- /**
139
- * Map list budgetmailer ids to ids
140
- * @var array
141
- */
142
- protected $_listBudgetmailerIdToId;
143
-
144
- /**
145
- * INFO list->primary is not mapped
146
- * List to model
147
- * @var array
148
- */
149
- protected $_listToModel = array(
150
- 'id' => 'budgetmailer_id',
151
- 'list' => 'name',
152
- );
153
-
154
  /**
155
  * Order to model
156
  * @var array
157
  */
158
- protected $_orderToModel = array(
159
  'customer_email' => 'email',
160
- 'customer_firstname' => 'first_name',
161
  'customer_middlename' => 'insertion',
162
- 'customer_lastname' => 'last_name',
163
  );
164
 
165
- /**
166
- * Subscriber to model
167
- * @var array
168
- */
169
- protected $_subscriberToModel = array(
170
- 'subscriber_email' => 'email',
171
- 'subscriber_status' => 'unsubscribed',
172
- );
173
-
174
  /**
175
  * Map address to API contact object
176
  *
@@ -185,7 +97,7 @@ class Professio_BudgetMailer_Helper_Mapper extends Mage_Core_Helper_Abstract
185
  $contactApi = new stdClass();
186
  }
187
 
188
- foreach ($this->_addressToContact as $keyApi => $keyModel) {
189
  $contactApi->{$keyApi} = $address->getData($keyModel);
190
  }
191
 
@@ -195,120 +107,22 @@ class Professio_BudgetMailer_Helper_Mapper extends Mage_Core_Helper_Abstract
195
  return $contactApi;
196
  }
197
 
198
- /**
199
- * Map address model to contact model
200
- *
201
- * @param Mage_Customer_Model_Address_Abstract $address
202
- * @param Professio_BudgetMailer_Model_Contact $contact
203
- */
204
- public function addressToModel(
205
- Mage_Customer_Model_Address_Abstract $address,
206
- Professio_BudgetMailer_Model_Contact $contact
207
- )
208
- {
209
- foreach ($this->_addressToModel as $keyAddress => $keyModel) {
210
- $contact->setData($keyModel, $address->getData($keyAddress));
211
- }
212
-
213
- $contact->setData(
214
- 'country_code',
215
- $this->countryIdToCountryCode($contact->getData('country_code'))
216
- );
217
- }
218
-
219
- /**
220
- * Map API contact object to address model
221
- *
222
- * @param stdClass $contactApi
223
- * @param Mage_Customer_Model_Address $address
224
- */
225
- public function contactToAddress(
226
- $contactApi,
227
- Mage_Customer_Model_Address $address
228
- )
229
- {
230
- foreach ($this->_addressToContact as $keyApi => $keyModel) {
231
- if (isset($contactApi->{$keyApi})) {
232
- $address->setData($keyModel, $contactApi->{$keyApi});
233
- }
234
- }
235
-
236
- $address->setData(
237
- 'country_id',
238
- $this->countryCodeToCountryId($contactApi->countryCode)
239
- );
240
- }
241
-
242
- /**
243
- * Map API contact object to contact model
244
- *
245
- * @param stdClass $contactApi
246
- * @param Professio_BudgetMailer_Model_Contact $contact
247
- */
248
- public function contactToModel(
249
- $contactApi,
250
- Professio_BudgetMailer_Model_Contact $contact
251
- )
252
- {
253
- foreach ($this->_contactToModel as $keyApi => $keyModel) {
254
- if (isset($contactApi->{$keyApi})) {
255
- $contact->setData($keyModel, $contactApi->{$keyApi});
256
- }
257
- }
258
-
259
- $contact->setData(
260
- 'list_id',
261
- $this->listNameToListId($contact->getData('list_id'))
262
- );
263
- }
264
-
265
- /**
266
- * Map contact model to API object
267
- *
268
- * @param Professio_BudgetMailer_Model_Contact $contact
269
- * @param stdClass $contactApi
270
- *
271
- * @return stdClass
272
- */
273
- public function contactToApi(
274
- Professio_BudgetMailer_Model_Contact $contact,
275
- $contactApi = null
276
- )
277
- {
278
- if (!is_object($contactApi)) {
279
- $contactApi = new stdClass();
280
- }
281
-
282
- foreach ($this->_contactToModel as $keyApi => $keyModel) {
283
- $contactApi->{$keyApi} = $contact->getData($keyModel);
284
- }
285
-
286
- $contactApi->sex = (int)$contactApi->sex;
287
- $contactApi->unsubscribed = (bool)$contactApi->unsubscribed;
288
-
289
- // $contact->setData(
290
- // 'list', $this->listIdToName($contact->getData('list'))
291
- // );
292
-
293
- return $contactApi;
294
- }
295
-
296
  /**
297
  * Map country code to country id
298
  *
299
- * @param string $iso3
300
  *
301
  * @return string
302
  */
303
- public function countryCodeToCountryId($iso3)
304
  {
305
- if (!isset($this->_countriesIso3Id[$iso3])) {
306
  $country = Mage::getModel('directory/country')
307
- ->loadByCode($iso3, 3);
308
- $this->_countriesIso3Id[$iso3] = $country->getId();
309
  }
310
 
311
- return $this->_countriesIso3Id[$iso3];
312
  }
313
 
314
  /**
@@ -320,12 +134,12 @@ class Professio_BudgetMailer_Helper_Mapper extends Mage_Core_Helper_Abstract
320
  */
321
  public function countryIdToCountryCode($countryId)
322
  {
323
- if (!isset($this->_countriesIdIso3[$countryId])) {
324
  $country = Mage::getModel('directory/country')->load($countryId);
325
- $this->_countriesIdIso3[$countryId] = $country->getIso3Code();
326
  }
327
 
328
- return $this->_countriesIdIso3[$countryId];
329
  }
330
 
331
  /**
@@ -334,7 +148,7 @@ class Professio_BudgetMailer_Helper_Mapper extends Mage_Core_Helper_Abstract
334
  * @param Mage_Customer_Model_Customer $customer
335
  * @param stdClass $contactApi
336
  */
337
- public function customerToApi(
338
  Mage_Customer_Model_Customer $customer,
339
  $contactApi = null
340
  )
@@ -343,229 +157,94 @@ class Professio_BudgetMailer_Helper_Mapper extends Mage_Core_Helper_Abstract
343
  $contactApi = new stdClass();
344
  }
345
 
346
- foreach ($this->_customerToApi as $keyModel => $keyApi) {
347
  $contactApi->{$keyApi} = $customer->getData($keyModel);
348
  }
349
 
350
- if (Professio_BudgetMailer_Model_Config_Source_Address::BILLING
351
- == Mage::helper('budgetmailer/config')->getAdvancedAddressType()) {
352
- $address = $customer->getDefaultBillingAddress();
353
- } elseif (Professio_BudgetMailer_Model_Config_Source_Address::SHIPPING
354
- == Mage::helper('budgetmailer/config')->getAdvancedAddressType()) {
355
- $address = $customer->getDefaultShippingAddress();
356
- } else {
357
- $address = false;
358
- }
359
-
360
- if ($address && $address->getId()) {
361
- $this->addressToContact($address, $contactApi);
 
 
 
 
 
 
362
  }
363
 
364
  return $contactApi;
365
  }
366
 
367
  /**
368
- * Map customer model to contact model
369
- *
370
- * @param Mage_Customer_Model_Customer $customer
371
- * @param Professio_BudgetMailer_Model_Contact $contact
372
  */
373
- public function customerToModel(
374
- Mage_Customer_Model_Customer $customer,
375
- Professio_BudgetMailer_Model_Contact $contact
376
  )
377
  {
378
- foreach ($this->_customerToModel as $keyCustomer => $keyModel) {
379
- $contact->setData($keyModel, $customer->getData($keyCustomer));
380
  }
381
- }
382
-
383
- /**
384
- * Prepare list maps
385
- */
386
- public function initListsMap()
387
- {
388
- // INFO in case of initiation of lists collection,
389
- // we don't want to try load list collection again
390
- if (Mage::registry('budgetmailer_list_initiation')) {
391
- return;
392
  }
393
 
394
- if (!isset($this->_listIdToName)) {
395
- $list = Mage::getModel('budgetmailer/list');
396
- $collection = $list->getCollection();
397
- $collection->load();
398
-
399
- foreach ($collection->getIterator() as $list) {
400
- $this->_listIdToName[$list->getEntityId()] = $list->getName();
401
- $this->_listNameToId[$list->getName()] = $list->getEntityId();
402
-
403
- $this->_listBudgetmailerIdToId[$list->getBudgetmailerId()] =
404
- $list->getEntityId();
405
- $this->_listIdToBudgetmailerId[$list->getEntityId()] =
406
- $list->getBudgetmailerId();
407
  }
408
- }
409
- }
410
-
411
- /**
412
- * Map list API object to list model
413
- * @param stdClass $listApi
414
- * @param Professio_BudgetMailer_Model_List $list
415
- */
416
- public function listToModel(
417
- $listApi, Professio_BudgetMailer_Model_List $list
418
- )
419
- {
420
- foreach ($this->_listToModel as $keyApi => $keyModel) {
421
- if (isset($listApi->{$keyApi})) {
422
- $list->setData($keyModel, $listApi->{$keyApi});
423
  }
424
  }
425
 
426
- if (0 == (int)$list->getEntityId()) {
427
- $list->setData(
428
- 'entity_id',
429
- $this->listBudgetmailerIdToListId($list->getEntityId())
430
- );
431
- }
432
- }
433
-
434
- /**
435
- * Get list id by name
436
- *
437
- * @param string $name
438
- *
439
- * @return integer
440
- */
441
- public function listNameToListId($name)
442
- {
443
- $this->initListsMap();
444
-
445
- return isset($this->_listNameToId[$name])
446
- ? $this->_listNameToId[$name] : null;
447
- }
448
-
449
- /**
450
- * Get list id by budgetmailer id
451
- *
452
- * @param string $budgetmailerId
453
- *
454
- * @return integer
455
- */
456
- public function listBudgetmailerIdToListId($budgetmailerId)
457
- {
458
- $this->initListsMap();
459
-
460
- return isset($this->_listBudgetmailerIdToId[$budgetmailerId])
461
- ? $this->_listBudgetmailerIdToId[$budgetmailerId] : null;
462
- }
463
-
464
- /**
465
- * Get list budgetmailer id by id
466
- * @param integer $listId
467
- */
468
- public function listIdToBudgetmailerId($listId)
469
- {
470
- $this->initListsMap();
471
-
472
- return isset($this->_listIdToBudgetmailerId[$listId])
473
- ? $this->_listIdToBudgetmailerId[$listId] : null;
474
- }
475
-
476
- /**
477
- * Get list name by id
478
- *
479
- * @param integer $listId
480
- *
481
- * @return string
482
- */
483
- public function listIdToName($listId)
484
- {
485
- $this->initListsMap();
486
-
487
- return isset($this->_listIdToName[$listId])
488
- ? $this->_listIdToName[$listId] : null;
489
  }
490
 
491
  /**
492
- * Map list model to API object
493
- * @param Professio_BudgetMailer_Model_List $list
494
- * @param stdClass $listApi
 
495
  */
496
- public function listToApi(
497
- Professio_BudgetMailer_Model_List $list,
498
- $listApi = null
499
  )
500
  {
501
- if (!is_object($listApi)) {
502
- $listApi = new stdClass();
503
  }
504
 
505
- foreach ($this->_listToModel as $keyApi => $keyModel) {
506
- $listApi->{$keyApi} = $list->getData($keyModel);
507
- }
508
 
509
- $list->setData('id', $this->listIdToBudgetmailerId($listApi->id));
510
- }
511
-
512
- /**
513
- * Map order model to contact model
514
- *
515
- * @param Mage_Sales_Model_Order $order
516
- * @param Professio_BudgetMailer_Model_Contact $contact
517
- */
518
- public function orderToModel(
519
- Mage_Sales_Model_Order $order,
520
- Professio_BudgetMailer_Model_Contact $contact
521
- )
522
- {
523
- foreach ($this->_orderToModel as $keyOrder => $keyModel) {
524
- $contact->setData(
525
- $keyModel, $order->getData($keyOrder)
526
- );
527
- }
528
- }
529
-
530
- /**
531
- * Map subscriber model to contact model
532
- *
533
- * @param Mage_Newsletter_Model_Subscriber $subscriber
534
- * @param Professio_BudgetMailer_Model_Contact $contact
535
- */
536
- public function subscriberToModel(
537
- Mage_Newsletter_Model_Subscriber $subscriber,
538
- Professio_BudgetMailer_Model_Contact $contact
539
- )
540
- {
541
- foreach ($this->_subscriberToModel as $keySubscriber => $keyModel) {
542
- $contact->setData(
543
- $keyModel, $subscriber->getData($keySubscriber)
544
- );
545
-
546
- $contact->status = !$contact->status;
547
- }
548
- }
549
-
550
- public function prepareContactApi($contactApiNew)
551
- {
552
- foreach ($contactApiNew as $k => $v) {
553
- if (is_null($v)) {
554
- unset($contactApiNew->{$k});
555
- }
556
- }
557
-
558
- if (isset($contactApiNew->tags) && (
559
- !is_array($contactApiNew->tags) || !count($contactApiNew->tags)
560
- || $contactApiNew->tags == '[]'
561
- )
562
- ) {
563
- Mage::log('prepare unset tags');
564
- unset($contactApiNew->tags);
565
- }
566
-
567
- if (empty($contactApiNew->address)) {
568
- unset($contactApiNew->address);
569
- }
570
  }
571
  }
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
25
  {
26
  /**
27
  * Address model to contact model
28
+ * @var array
29
  */
30
  protected $_addressToContact = array(
31
+ 'company' => 'companyName',
32
  // INFO for now not replacing multiple to single line
33
+ 'street' => 'address',
34
+ 'postcode' => 'postalCode',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  'city' => 'city',
36
+ 'country_id' => 'countryCode',
37
  'telephone' => 'telephone',
 
 
 
 
 
38
  );
39
 
40
  /**
41
  * List of countries by id
42
  * @var array
43
  */
44
+ protected $_countriesIdIso = array();
45
  /**
46
  * List of countries by ISO3 code
47
  * @var array
48
  */
49
+ protected $_countriesIsoId = array();
50
 
51
  /**
52
  * Customer model to API object
53
  * @var array
54
  */
55
+ protected $_customerToContact = array(
56
  'email' => 'email',
57
  'firstname' => 'firstName',
58
  'middlename' => 'insertion',
60
  'sex' => 'gender',
61
  );
62
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  /**
64
  * Map list ids to names
65
  * @var array
72
  */
73
  protected $_listNameToId;
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  /**
76
  * Order to model
77
  * @var array
78
  */
79
+ protected $_orderToContact = array(
80
  'customer_email' => 'email',
81
+ 'customer_firstname' => 'firstName',
82
  'customer_middlename' => 'insertion',
83
+ 'customer_lastname' => 'lastName',
84
  );
85
 
 
 
 
 
 
 
 
 
 
86
  /**
87
  * Map address to API contact object
88
  *
97
  $contactApi = new stdClass();
98
  }
99
 
100
+ foreach ($this->_addressToContact as $keyModel => $keyApi) {
101
  $contactApi->{$keyApi} = $address->getData($keyModel);
102
  }
103
 
107
  return $contactApi;
108
  }
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  /**
111
  * Map country code to country id
112
  *
113
+ * @param string $iso
114
  *
115
  * @return string
116
  */
117
+ public function countryCodeToCountryId($iso)
118
  {
119
+ if (!isset($this->_countriesIsoId[$iso])) {
120
  $country = Mage::getModel('directory/country')
121
+ ->loadByCode($iso);
122
+ $this->_countriesIsoId[$iso] = $country->getCountryId();
123
  }
124
 
125
+ return $this->_countriesIsoId[$iso];
126
  }
127
 
128
  /**
134
  */
135
  public function countryIdToCountryCode($countryId)
136
  {
137
+ if (!isset($this->_countriesIdIso[$countryId])) {
138
  $country = Mage::getModel('directory/country')->load($countryId);
139
+ $this->_countriesIdIso[$countryId] = $country->getIso3Code();
140
  }
141
 
142
+ return $this->_countriesIdIso[$countryId];
143
  }
144
 
145
  /**
148
  * @param Mage_Customer_Model_Customer $customer
149
  * @param stdClass $contactApi
150
  */
151
+ public function customerToContact(
152
  Mage_Customer_Model_Customer $customer,
153
  $contactApi = null
154
  )
157
  $contactApi = new stdClass();
158
  }
159
 
160
+ foreach ($this->_customerToContact as $keyModel => $keyApi) {
161
  $contactApi->{$keyApi} = $customer->getData($keyModel);
162
  }
163
 
164
+ if (Mage::helper('budgetmailer/config')
165
+ ->isAdvancedOnAddressUpdateEnabled()) {
166
+ if (Professio_BudgetMailer_Model_Config_Source_Address::BILLING
167
+ == Mage::helper('budgetmailer/config')->getAdvancedAddressType()
168
+ ) {
169
+ $address = $customer->getDefaultBillingAddress();
170
+ } elseif (
171
+ Professio_BudgetMailer_Model_Config_Source_Address::SHIPPING
172
+ == Mage::helper('budgetmailer/config')->getAdvancedAddressType()
173
+ ) {
174
+ $address = $customer->getDefaultShippingAddress();
175
+ } else {
176
+ $address = false;
177
+ }
178
+
179
+ if ($address && $address->getId()) {
180
+ $this->addressToContact($address, $contactApi);
181
+ }
182
  }
183
 
184
  return $contactApi;
185
  }
186
 
187
  /**
188
+ * Map order to contact
189
+ * @param Mage_Sales_Model_Order $order
190
+ * @param stdClass $contactApi
191
+ * @return \stdClass
192
  */
193
+ public function orderToContact(
194
+ Mage_Sales_Model_Order $order,
195
+ $contactApi = null
196
  )
197
  {
198
+ if (!is_object($contactApi)) {
199
+ $contactApi = new stdClass();
200
  }
201
+
202
+ foreach ($this->_orderToContact as $keyOrder => $keyApi) {
203
+ $contactApi->{$keyApi} = $order->getData($keyOrder);
 
 
 
 
 
 
 
 
204
  }
205
 
206
+ if (Mage::helper('budgetmailer/config')
207
+ ->isAdvancedOnAddressUpdateEnabled()) {
208
+ if (Professio_BudgetMailer_Model_Config_Source_Address::BILLING
209
+ == Mage::helper('budgetmailer/config')->getAdvancedAddressType()
210
+ ) {
211
+ $address = $order->getBillingAddress();
212
+ } elseif (
213
+ Professio_BudgetMailer_Model_Config_Source_Address::SHIPPING
214
+ == Mage::helper('budgetmailer/config')->getAdvancedAddressType()
215
+ ) {
216
+ $address = $order->getShippingAddress();
217
+ } else {
218
+ $address = false;
219
  }
220
+
221
+ if ($address && $address->getId()) {
222
+ $this->addressToContact($address, $contactApi);
 
 
 
 
 
 
 
 
 
 
 
 
223
  }
224
  }
225
 
226
+ return $contactApi;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  }
228
 
229
  /**
230
+ * Map subscriber to contact
231
+ * @param Mage_Newsletter_Model_Subscriber $subscriber
232
+ * @param stdClass $contactApi
233
+ * @return \stdClass
234
  */
235
+ public function subscriberToContact(
236
+ Mage_Newsletter_Model_Subscriber $subscriber,
237
+ $contactApi = null
238
  )
239
  {
240
+ if (is_null($contactApi)) {
241
+ $contactApi = new stdClass();
242
  }
243
 
244
+ $contactApi->email = $subscriber->getSubscriberEmail();
245
+ $contactApi->subscribe = ($subscriber->getSubscriberStatus() == 1);
246
+ $contactApi->unsubscribed = !($subscriber->getSubscriberStatus() == 1);
247
 
248
+ return $contactApi;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  }
250
  }
app/code/community/Professio/BudgetMailer/Model/Client.php CHANGED
@@ -5,909 +5,105 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
19
- * API REST-JSON client
20
  *
21
  * @category Professio
22
  * @package Professio_BudgetMailer
23
  */
24
- class Professio_BudgetMailer_Model_Client extends Zend_Rest_Client
 
25
  {
26
- const BULK_DELETE = 0;
27
- const BULK_UNSUB = 1;
28
- const BULK_DELUNSUB = 2;
29
- const BULK_INS = 3;
30
-
31
- /**
32
- * Bulk API method limit
33
- *
34
- * @var integer
35
- */
36
- const LIMIT = 1000;
37
-
38
- /**
39
- * Allowed bulk methods
40
- */
41
- protected $_bulkMethods = array(
42
- self::BULK_DELETE, self::BULK_DELUNSUB, self::BULK_UNSUB, self::BULK_INS
43
- );
44
-
45
- /**
46
- * Caching of API contacts
47
- *
48
- * @var boolean
49
- */
50
- protected $_cachingEnabled = true;
51
-
52
- /**
53
- * Contacts memory cache
54
- *
55
- * @var array
56
- */
57
- protected $_contacts = array();
58
-
59
- /**
60
- * Contacts count in last result
61
- *
62
- * @var integer
63
- */
64
- protected $_contactsCount;
65
-
66
- protected $_totalCount;
67
- protected $_totalFail;
68
- protected $_totalSuccess;
69
-
70
- /**
71
- * API salt
72
- * @var string
73
- */
74
- protected $_salt;
75
-
76
- /**
77
- * API signature
78
- * @var string
79
- */
80
- protected $_signature;
81
-
82
- /**
83
- * API signature (encoded)
84
- * @var string
85
- */
86
- protected $_signatureEncoded;
87
-
88
- /**
89
- * Constructor
90
- *
91
- * @param string|Zend_Uri_Http $uri URI for the web service
92
- *
93
- * @return void
94
- */
95
- public function __construct($uri = null)
96
- {
97
- if (!empty($uri)) {
98
- $this->setUri($uri);
99
- } else {
100
- $this->setUri($this->getConfigHelper()->getApiEndpoint());
101
- }
102
-
103
- //$this->init();
104
- }
105
-
106
- /**
107
- * Override original Zend_Rest_Client::_performPost()...
108
- * force content-type to application/json.
109
- *
110
- * Performs a POST or PUT request. Any data provided is set in the HTTP
111
- * client. String data is pushed in as raw POST data; array or object data
112
- * is pushed in as POST parameters.
113
- *
114
- * @param mixed $method
115
- * @param mixed $data
116
- *
117
- * @return Zend_Http_Response
118
- */
119
- protected function _performPost($method, $data = null)
120
- {
121
- $client = self::getHttpClient();
122
-
123
- if (is_string($data)) {
124
- $client->setRawData($data);
125
- } elseif (is_array($data) || is_object($data)) {
126
- $client->setParameterPost((array) $data);
127
- }
128
-
129
- $client->setHeaders('content-type', 'application/json');
130
-
131
- return $client->request($method);
132
- }
133
-
134
- /**
135
- * Translation wrapper
136
- *
137
- * @param string $s
138
- *
139
- * @return string
140
- */
141
- protected function __($s)
142
- {
143
- return Mage::helper('budgetmailer')->__($s);
144
- }
145
-
146
- /**
147
- * Get cached record
148
- *
149
- * @param string $id
150
- *
151
- * @return mixed
152
- */
153
- protected function getCache($id)
154
- {
155
- /*if (isset($this->contacts[$id]) && is_string($this->contacts[$id])) {
156
- throw new Exception('cache fail');
157
- }*/
158
-
159
- return $this->isCachingEnabled()
160
- && isset($this->_contacts[$id])
161
- ? $this->_contacts[$id] : null;
162
- }
163
-
164
- /**
165
- * Get caching enabled
166
- *
167
- * @return boolean
168
- */
169
- protected function isCachingEnabled()
170
- {
171
- return $this->_cachingEnabled;
172
- }
173
-
174
- /**
175
- * Get config helper
176
- *
177
- * @return Professio_BudgetMailer_Helper_Config
178
- */
179
- protected function getConfigHelper()
180
- {
181
- return Mage::helper('budgetmailer/config');
182
- }
183
-
184
- /**
185
- * Get default list
186
- *
187
- * @return string
188
- */
189
- protected function getList()
190
- {
191
- return $this->getConfigHelper()->getGeneralList();
192
- }
193
-
194
- /**
195
- * Get / generate salt
196
- *
197
- * @return string
198
- */
199
- protected function getSalt($reinit = false)
200
- {
201
- if (!isset($this->salt) || $reinit) {
202
- $this->salt = md5(microtime(true));//mt_rand();
203
- }
204
-
205
- return $this->salt;
206
- }
207
-
208
- /**
209
- * Get / generate signature
210
- *
211
- * @return string
212
- */
213
- protected function getSignature($reinit = false)
214
- {
215
- if (!isset($this->_signature) || $reinit) {
216
- $this->_signature = hash_hmac(
217
- 'sha256',
218
- $this->getSalt($reinit),
219
- $this->getConfigHelper()->getApiSecret(),
220
- true
221
- );
222
- }
223
-
224
- return $this->_signature;
225
- }
226
-
227
- /**
228
- * Get encoded signature
229
- *
230
- * @return string
231
- */
232
- protected function getSignatureEncoded($reinit = false)
233
- {
234
- if (!isset($this->_signatureEncoded) || $reinit) {
235
- $this->_signatureEncoded = rawurlencode(
236
- base64_encode($this->getSignature($reinit))
237
- );
238
- }
239
-
240
- return $this->_signatureEncoded;
241
- }
242
-
243
- /**
244
- * Initiate the http client
245
- *
246
- * @param boolean $reinit regenerate signature
247
- *
248
- * @return void
249
- */
250
- protected function init($reinit = false)
251
- {
252
- $headers = array(
253
- 'Accept' => 'application/json',
254
- 'apikey' => $this->getConfigHelper()->getApiKey(),
255
- 'apisecret' => $this->getConfigHelper()->getApiSecret(),
256
- 'Content-Type' => 'application/json',
257
- // INFO this will regenerate salt if needed
258
- 'signature' => $this->getSignatureEncoded($reinit),
259
- 'salt' => $this->getSalt(),
260
- );
261
-
262
- $this->getHttpClient()->setHeaders($headers);
263
-
264
- $this->log(
265
- 'budgetmailer/client::init() re: ' . ($reinit ? 'yes' : 'no')
266
- . ' headers: ' . json_encode($headers)
267
- );
268
- }
269
-
270
- /**
271
- * Check if memory cache is not too large
272
- */
273
- protected function limitCache()
274
- {
275
- if (count($this->_contacts) > self::LIMIT) {
276
- $this->_contacts = array();
277
- }
278
- }
279
-
280
- /**
281
- * Custom log wrapper - log only if developer mode
282
- *
283
- * @param string $message
284
- */
285
- protected function log($message)
286
- {
287
- if (Mage::getIsDeveloperMode()) {
288
- Mage::log($message);
289
- }
290
- }
291
-
292
- /**
293
- * Set cache
294
- *
295
- * @param mixed $data
296
- * @param string $id
297
- *
298
- * @return Professio_BudgetMailer_Model_Client
299
- */
300
- protected function setCache($data, $id = null)
301
- {
302
- if (!$this->isCachingEnabled()) {
303
- return $this;
304
- }
305
-
306
- if (!$id) {
307
- $id = $data && $data->id ? $data->id : null;
308
- }
309
-
310
- if ($id) {
311
- $this->limitCache();
312
-
313
- /*if (is_string($data)) {
314
- throw new Exception('set cache failed.');
315
- }*/
316
-
317
- $this->_contacts[$id] = $data;
318
- }
319
-
320
- return $this;
321
- }
322
-
323
- /**
324
- * Delete contact API call
325
- *
326
- * @param string $id email or budgetmailer id
327
- * @param null|string $list list name or id or null for default
328
- *
329
- * @return boolean
330
- * @throws Professio_BudgetMailer_Exception
331
- */
332
- public function deleteContact($id, $list = null)
333
- {
334
- $this->init(true);
335
-
336
- if (is_null($list)) {
337
- $list = $this->getList();
338
- }
339
-
340
- $path = '/contacts/' . rawurlencode($list) . '/' . rawurlencode($id);
341
-
342
- $this->log(
343
- 'budgetmailer/client::deleteContact() path: '
344
- . $path . ', list: ' . $list . ', id: ' . $id
345
- );
346
-
347
- $rs = $this->restDelete($path);
348
-
349
- $this->log(
350
- 'budgetmailer/client::deleteContact() result: '
351
- . $rs->getStatus() . ', body: ' . $rs->getBody()
352
- );
353
-
354
- if ($rs->isError()) {
355
- throw new Professio_BudgetMailer_Exception(
356
- Mage::helper('budgetmailer')
357
- ->__('Couldn\'t delete contact from BudgetMailer API.')
358
- );
359
- } else {
360
- if (isset($this->_contacts[$id])) {
361
- unset($this->_contacts[$id]);
362
- }
363
- }
364
-
365
- return true;
366
- }
367
-
368
- /**
369
- * Delete tag from contact API call
370
- *
371
- * @param string $id email or budgetmailer id
372
- * @param string $tag tag
373
- * @param null|string $list list name or id or null for default
374
- *
375
- * @return boolean
376
- * @throws Professio_BudgetMailer_Exception
377
- */
378
- public function deleteTag($id, $tag, $list = null)
379
- {
380
- $this->init(true);
381
-
382
- if (is_null($list)) {
383
- $list = $this->getList();
384
- }
385
-
386
- $path = '/contacts/' . rawurlencode($list) . '/'
387
- . rawurlencode($id) . '/tags/' . rawurlencode($tag);
388
-
389
- $this->log(
390
- 'budgetmailer/client::deleteTag() path: '
391
- . $path . ', list: ' . $list . ', id: ' . $id
392
- );
393
-
394
- $rs = $this->restDelete($path);
395
-
396
- $this->log(
397
- 'budgetmailer/client::deleteTag() result: '
398
- . $rs->getStatus() . ', body: ' . $rs->getBody()
399
- );
400
-
401
- if ($rs->isError()) {
402
- throw new Professio_BudgetMailer_Exception(
403
- Mage::helper('budgetmailer')
404
- ->__('Couldn\'t delete tag from contact from BudgetMailer API.')
405
- );
406
- }
407
-
408
- return true;
409
- }
410
-
411
  /**
412
- * Get single contact from API
413
- *
414
- * @param string $id email or budgetmailer id
415
- * @param null|string $list list name or id or null for default
416
- *
417
- * @return boolean|Professio_BudgetMailer_Model_Contact
418
- * @throws Professio_BudgetMailer_Exception
419
  */
420
- public function getContact($id, $list = null)
421
- {
422
- $this->init(true);
423
-
424
- // try {
425
- // throw new Exception('trace');
426
- // } catch (Exception $e) {
427
- // Mage::logException($e);
428
- // }
429
-
430
- $contactCache = $this->getCache($id);
431
-
432
- if (!is_null($contactCache)) {
433
- $this->log(
434
- 'budgetmailer/client::getContact() cache hit, result: '
435
- . json_encode($contactCache)
436
- );
437
-
438
- return $contactCache;
439
- }
440
-
441
- if (is_null($list)) {
442
- $list = $this->getList();
443
- }
444
-
445
- $path = '/contacts/' . rawurlencode($list) . '/' . rawurlencode($id);
446
-
447
- $this->log(
448
- 'budgetmailer/client::getContact() path: '
449
- . $path . ', list: ' . $list . ', id: ' . $id
450
- );
451
-
452
- $rs = $this->restGet($path);
453
-
454
- $this->log(
455
- 'budgetmailer/client::getContact() result: '
456
- . $rs->getStatus() . ', body: ' . $rs->getBody()
457
- );
458
-
459
- if ($rs->isError()) {
460
- if (404 == $rs->getStatus()) {
461
- $contact = false;
462
- } else {
463
- throw new Professio_BudgetMailer_Exception(
464
- Mage::helper('budgetmailer')
465
- ->__('Couldn\'t get the contact from BudgetMailer API.')
466
- );
467
- }
468
- } else {
469
- $contact = json_decode($rs->getBody());
470
- }
471
-
472
- $this->setCache($contact, $id);
473
-
474
- return $contact;
475
- }
476
-
477
  /**
478
- * Get multiple contacts from API
479
- *
480
- * @param integer $offset
481
- * @param integer $limit
482
- * @param string $sort
483
- * @param boolean $unsubscribed
484
- * @param null|string $list list name or id or null for default
485
- *
486
- * @return boolean|array
487
- * @throws Professio_BudgetMailer_Exception
488
  */
489
- public function getContacts(
490
- $offset = 0,
491
- $limit = 20,
492
- $sort = 'ASC',
493
- $unsubscribed = 'False',
494
- $list = null
495
- )
496
- {
497
- $this->init(true);
498
-
499
- if (is_null($list)) {
500
- $list = $this->getList();
501
- }
502
-
503
- $path = '/contacts/' . rawurlencode($list) . '/';
504
-
505
- $query = array(
506
- 'offset' => $offset,
507
- 'limit' => $limit,
508
- 'sort' => $sort,
509
- 'unsubscribed' => $unsubscribed
510
- );
511
-
512
- foreach ($query as $k => $v) {
513
- if (is_null($v)) {
514
- unset($query[$k]);
515
- }
516
- }
517
-
518
- $this->log(
519
- 'budgetmailer/client::getContacts() path: '
520
- . $path . ', list: ' . $list . ', offset: ' . $offset
521
- . ', limit: ' . $limit . ', sort: ' . $sort . ', unsubscribed: '
522
- . ($unsubscribed ? 'yes' : 'no')
523
- );
524
-
525
- $rs = $this->restGet($path, $query);
526
-
527
- $this->log(
528
- 'budgetmailer/client::getContacts() result: ' . $rs->getStatus()
529
- . ', headers: ' . json_encode($rs->getHeaders())
530
- . ', body: ' . $rs->getBody()
531
- );
532
-
533
- $this->_contactsCount = $rs->getHeader('X-total-count');
534
-
535
- if ($rs->isError()) {
536
- throw new Professio_BudgetMailer_Exception(
537
- Mage::helper('budgetmailer')
538
- ->__('Couldn\'t get contacts from BudgetMailer API.')
539
- );
540
- }
541
-
542
- $contacts = json_decode($rs->getBody());
543
-
544
- return $contacts;
545
- }
546
 
547
  /**
548
- * Get total contacts count
549
- *
550
- * @return integer
551
  */
552
- public function getContactsCount()
553
  {
554
- if (!isset($this->_contactsCount)) {
555
- $this->getContacts(0, 1);
556
- }
557
-
558
- return $this->_contactsCount;
559
  }
560
 
561
  /**
562
- * Get budgetmailer lists API call
563
- *
564
- * @return boolean|array
565
- * @throws Professio_BudgetMailer_Exception
566
  */
567
- public function getLists()
568
  {
569
- $this->init(true);
570
-
571
- $path = '/lists';
572
-
573
- $this->log('budgetmailer/client::getLists() path: ' . $path);
574
-
575
- $rs = $this->restGet($path);
576
 
577
- $this->log(
578
- 'budgetmailer/client::getLists() result: '
579
- . $rs->getStatus() . ', body: ' . $rs->getBody()
580
- );
581
-
582
- if ($rs->isError()) {
583
- throw new Professio_BudgetMailer_Exception(
584
- Mage::helper('budgetmailer')
585
- ->__('Couldn\'t get the lists from BudgetMailer API.')
586
- );
587
- } else {
588
- $lists = json_decode($rs->getBody());
589
- }
590
-
591
- return $lists;
592
  }
593
 
594
  /**
595
- * Get tags for contact API call
596
- *
597
- * @param string $id email or budgetmailer id
598
- * @param null|string $list list name, id, or null for default
599
- *
600
- * @return boolean|array
601
- * @throws Professio_BudgetMailer_Exception
602
  */
603
- public function getTags($id, $list = null)
604
  {
605
- $this->init(true);
606
-
607
- if (is_null($list)) {
608
- $list = $this->getList();
609
- }
610
-
611
- $path = '/contacts/' . rawurlencode($list)
612
- . '/' . rawurlencode($id) . '/tags';
613
-
614
- $this->log(
615
- 'budgetmailer/client::getTags() path: '
616
- . $path . ', list: ' . $list . ', id: ' . $id
617
  );
 
618
 
619
- $rs = $this->restGet($path);
620
-
621
- $this->log(
622
- 'budgetmailer/client::getTags() result: '
623
- . $rs->getStatus() . ', body: ' . $rs->getBody()
624
- );
625
-
626
- if ($rs->isError()) {
627
- throw new Professio_BudgetMailer_Exception(
628
- Mage::helper('budgetmailer')
629
- ->__('Couldn\'t get tags from BudgetMailer API.')
630
- );
631
- }
632
-
633
- return json_decode($rs->getBody());
634
  }
635
 
636
  /**
637
- * Insert new contact ot API
638
- *
639
- * @param object $contact contact to save
640
- * @param null|string $list list name, id, or null for default
641
- *
642
- * @return boolean|object false or returned record from API
643
- * @throws Professio_BudgetMailer_Exception
644
  */
645
- public function postContact($contact, $list = null)
646
  {
647
- $this->init(true);
648
-
649
- if (is_null($list)) {
650
- $list = $this->getList();
651
- }
652
-
653
- $path = '/contacts/' . rawurlencode($list);
654
- $data = json_encode($contact);
655
-
656
- $this->log(
657
- 'budgetmailer/client::postContact() path: '
658
- . $path . ', list: ' . $list . ', contact: ' . $data
659
- );
660
-
661
- $rs = $this->restPost($path, $data);
662
-
663
- $this->log(
664
- 'budgetmailer/client::postContact() result: '
665
- . $rs->getStatus() . ', body: ' . $rs->getBody()
666
- );
667
-
668
- if ($rs->isError()) {
669
- throw new Professio_BudgetMailer_Exception(
670
- Mage::helper('budgetmailer')
671
- ->__('Couldn\'t subscribe contact to BudgetMailer API.')
672
- );
673
- }
674
-
675
- $contact = json_decode($rs->getBody());
676
-
677
- if ($contact) {
678
- $this->setCache($contact);
679
- }
680
-
681
- return $contact;
682
- }
683
-
684
- public function postContacts($contacts, $bulkMethod, $list = null)
685
- {
686
- if (!in_array($bulkMethod, $this->_bulkMethods)) {
687
- throw new Professio_BudgetMailer_Exception(
688
- Mage::helper('budgetmailer')
689
- ->__('Invalid bulk method.')
690
- );
691
- }
692
-
693
- $this->init(true);
694
-
695
- if (is_null($list)) {
696
- $list = $this->getList();
697
- }
698
-
699
- $path = '/contacts/' . rawurlencode($list);
700
-
701
- switch($bulkMethod) {
702
- case self::BULK_DELETE:
703
- $path .= '/bulk-delete';
704
- break;
705
- case self::BULK_UNSUB:
706
- $path .= '/bulk-unsubscribe';
707
- break;
708
- case self::BULK_DELUNSUB:
709
- $path .= '/bulk-delete';
710
- break;
711
- case self::BULK_INS:
712
- $path .= '/bulk-insert';
713
- break;
714
- }
715
-
716
- $data = json_encode($contacts);
717
-
718
- $this->log(
719
- 'budgetmailer/client::postContactsBulk() path: '
720
- . $path . ', list: ' . $list . ', contact: ' . $data
721
- );
722
-
723
- //$rs = $this->restPost($path);
724
-
725
- // INFO not using restPost because of the params reset
726
- // with combination with the get param neded to delete & unsub
727
- $this->_prepareRest($path);
728
-
729
- if (self::BULK_DELUNSUB == $bulkMethod) {
730
- $this->getHttpClient()->setParameterGet('unsubscribe', 'true');
731
- $this->log(
732
- 'budgetmailer/client::postContactsBulk() unsubscribe=true');
733
- } else if (self::BULK_INS == $bulkMethod) {
734
- $this->getHttpClient()->setParameterGet('overwrite', 'true');
735
- $this->log(
736
- 'budgetmailer/client::postContactsBulk() overwrite=true');
737
- }
738
-
739
- $rs = $this->_performPost('POST', $data);
740
-
741
- $this->_totalCount = $rs->getHeader('X-Total-Count');
742
- $this->_totalFail = $rs->getHeader('X-Total-Fail');
743
- $this->_totalSuccess = $rs->getHeader('X-Total-Success');
744
-
745
- $this->log(
746
- 'budgetmailer/client::postContactsBulk() result: ' . $rs->getStatus()
747
- . ', headers: ' . json_encode($rs->getHeaders())
748
- . ', body: ' . $rs->getBody()
749
- );
750
-
751
- if ($rs->isError()) {
752
- throw new Professio_BudgetMailer_Exception(
753
- Mage::helper('budgetmailer')
754
- ->__('Couldn\'t bulk process contacts in BudgetMailer API.')
755
- );
756
- }
757
-
758
- return array(
759
- $this->_totalCount, $this->_totalFail, $this->_totalSuccess,
760
- json_decode($rs->getBody())
761
- );
762
- }
763
-
764
- /**
765
- * Add tags to contact
766
- *
767
- * @param string $id email or budgetamiler id
768
- * @param array $tags tags
769
- * @param null|string $list list name, id, or null for default
770
- *
771
- * @return boolean
772
- * @throws Professio_BudgetMailer_Exception
773
- */
774
- public function postTags($id, $tags, $list = null)
775
- {
776
- $this->init(true);
777
-
778
- if (is_null($list)) {
779
- $list = $this->getList();
780
- }
781
-
782
- $path = '/contacts/' . rawurlencode($list) . '/'
783
- . rawurlencode($id) . '/tags';
784
- $data = json_encode($tags);
785
-
786
- $this->log(
787
- 'budgetmailer/client::postTags() path: '
788
- . $path . ', list: ' . $list . ', id: ' . $id . ', tags: ' . $data
789
- );
790
-
791
- $rs = $this->restPost($path, $data);
792
-
793
- $this->log(
794
- 'budgetmailer/client::postTags() result: '
795
- . $rs->getStatus() . ', body: ' . $rs->getBody()
796
- );
797
-
798
- if ($rs->isError()) {
799
- throw new Professio_BudgetMailer_Exception(
800
- Mage::helper('budgetmailer')
801
- ->__('Couldn\'t post tags to BudgetMailer API.')
802
- );
803
- }
804
-
805
- return true;
806
  }
807
 
808
  /**
809
- * Update contact in API
810
- *
811
- * @param string $id email or budgetamiler id
812
- * @param object $contact contact object
813
- * @param null|string $list list name, id, or null for default
814
- *
815
- * @return boolean|string
816
- * @throws Professio_BudgetMailer_Exception
817
  */
818
- public function putContact($id, $contact, $list = null)
819
  {
820
- $this->init(true);
821
-
822
- if (is_null($list)) {
823
- $list = $this->getList();
824
- }
825
-
826
- $path = '/contacts/' . rawurlencode($list) . '/' . rawurlencode($id);
827
- $data = json_encode($contact);
828
-
829
- $this->log(
830
- 'budgetmailer/client::putContact() path: '
831
- . $path . ', list: ' . $list . ', id: ' . $id . ', contact: '
832
- . $data
833
- );
834
-
835
- $rs = $this->restPut($path, $data);
836
-
837
- $this->log(
838
- 'budgetmailer/client::putContact() result: '
839
- . $rs->getStatus() . ', body: ' . $rs->getBody()
840
- );
841
-
842
- if ($rs->isError()) {
843
- throw new Professio_BudgetMailer_Exception(
844
- Mage::helper('budgetmailer')
845
- ->__('Couldn\'t update contact in BudgetMailer API.')
846
  );
847
- } else {
848
- $this->setCache(json_decode($data), $id);
849
- }
850
-
851
- return json_decode($rs->getBody());
852
- }
853
-
854
- /**
855
- * Test current API credentials
856
- * @return boolean
857
- */
858
- public function testApiCredentials()
859
- {
860
- try {
861
- return $this->getLists();
862
- } catch (Exception $e) {
863
- Mage::logException($e);
864
-
865
- $this->log(
866
- 'budgetmailer/client::testApiCredentials() failed '
867
- . 'with exception: ' . $e->getMessage()
868
  );
869
-
870
- return false;
871
- }
872
- }
873
-
874
- /**
875
- * Overridden prepare rest... replaced self with Zend_Rest_Client
876
- *
877
- * Call a remote REST web service URI and return the Zend_Http_Response object
878
- *
879
- * @param string $path The path to append to the URI
880
- * @throws Zend_Rest_Client_Exception
881
- * @return void
882
- */
883
- private function _prepareRest($path)
884
- {
885
- // Get the URI object and configure it
886
- if (!$this->_uri instanceof Zend_Uri_Http) {
887
- #require_once 'Zend/Rest/Client/Exception.php';
888
- throw new Zend_Rest_Client_Exception('URI object must be set before performing call');
889
- }
890
-
891
- $uri = $this->_uri->getUri();
892
 
893
- if ($path[0] != '/' && $uri[strlen($uri)-1] != '/') {
894
- $path = '/' . $path;
895
  }
896
-
897
- $this->_uri->setPath($path);
898
-
899
- /**
900
- * Get the HTTP client and configure it for the endpoint URI. Do this each time
901
- * because the Zend_Http_Client instance is shared among all Zend_Service_Abstract subclasses.
902
- */
903
- if ($this->_noReset) {
904
- // if $_noReset we do not want to reset on this request,
905
- // but we do on any subsequent request
906
- $this->_noReset = false;
907
- } else {
908
- Zend_Rest_Client::getHttpClient()->resetParameters();
909
- }
910
-
911
- Zend_Rest_Client::getHttpClient()->setUri($this->_uri);
912
  }
913
  }
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
19
+ * Client model
20
  *
21
  * @category Professio
22
  * @package Professio_BudgetMailer
23
  */
24
+ class Professio_BudgetMailer_Model_Client
25
+ extends Mage_Core_Model_Abstract
26
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  /**
28
+ * @var \BudgetMailer\Api\Client
 
 
 
 
 
 
29
  */
30
+ protected $_client;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  /**
32
+ * Hash of clients by store id
33
+ * @var array
 
 
 
 
 
 
 
 
34
  */
35
+ protected $_storeClients = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  /**
38
+ * Constructor: load classes and initiate the client
 
 
39
  */
40
+ public function __construct()
41
  {
42
+ $this->loadClasses();
43
+ $this->init();
 
 
 
44
  }
45
 
46
  /**
47
+ * Load classes of the API client
 
 
 
48
  */
49
+ protected function loadClasses()
50
  {
51
+ $lib = Mage::getBaseDir('lib');
 
 
 
 
 
 
52
 
53
+ // INFO: when using client, load all classes
54
+ require_once $lib . '/BudgetMailer/Api/Client/Http.php';
55
+ require_once $lib . '/BudgetMailer/Api/Client/RestJson.php';
56
+ require_once $lib . '/BudgetMailer/Api/Cache.php';
57
+ require_once $lib . '/BudgetMailer/Api/Client.php';
58
+ require_once $lib . '/BudgetMailer/Api/Config.php';
 
 
 
 
 
 
 
 
 
59
  }
60
 
61
  /**
62
+ * Initiate the client
 
 
 
 
 
 
63
  */
64
+ protected function init()
65
  {
66
+ $config = new \BudgetMailer\Api\Config(
67
+ Mage::helper('budgetmailer/config')->getApiConfig()
 
 
 
 
 
 
 
 
 
 
68
  );
69
+ $cache = new \BudgetMailer\Api\Cache($config);
70
 
71
+ $this->_client = new \BudgetMailer\Api\Client($cache, $config);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
 
74
  /**
75
+ * Get API client
76
+ * @return \BudgetMailer\Api\Client
 
 
 
 
 
77
  */
78
+ public function getClient()
79
  {
80
+ return $this->_client;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
 
83
  /**
84
+ * Get client initialized by configuration for store
85
+ * @param integer $storeId
86
+ * @return \BudgetMailer\Api\Client
 
 
 
 
 
87
  */
88
+ public function getStoreClient($storeId)
89
  {
90
+ if (!isset($this->_storeClients[$storeId])) {
91
+ // INFO start emulation to get right list (from right store)
92
+ $appEmulation = Mage::getSingleton('core/app_emulation');
93
+ $initialEnvironmentInfo = $appEmulation
94
+ ->startEnvironmentEmulation($storeId);
95
+
96
+ $config = new \BudgetMailer\Api\Config(
97
+ Mage::helper('budgetmailer/config')->getApiConfig()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  );
99
+ $cache = new \BudgetMailer\Api\Cache($config);
100
+ $this->_storeClients[$storeId] = new \BudgetMailer\Api\Client(
101
+ $cache, $config
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
 
105
  }
106
+
107
+ return $this->_storeClients[$storeId];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
  }
app/code/community/Professio/BudgetMailer/Model/Config/Source/Account.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -36,15 +36,18 @@ class Professio_BudgetMailer_Model_Config_Source_Account
36
  {
37
  return array(
38
  array(
39
- 'label' => Mage::helper('budgetmailer')->__('Display checked checkbox'),
 
40
  'value' => self::CHECKED
41
  ),
42
  array(
43
- 'label' => Mage::helper('budgetmailer')->__('Display unchecked checkbox'),
 
44
  'value' => self::UNCHECKED
45
  ),
46
  array(
47
- 'label' => Mage::helper('budgetmailer')->__('Don\'t display checkbox, sign-up automatically'),
 
48
  'value' => self::HIDDENCHECKED
49
  ),
50
  );
@@ -63,7 +66,8 @@ class Professio_BudgetMailer_Model_Config_Source_Account
63
  self::UNCHECKED =>
64
  Mage::helper('budgetmailer')->__('Display unchecked checkbox'),
65
  self::HIDDENCHECKED =>
66
- Mage::helper('budgetmailer')->__('Don\'t display checkbox, sign-up automatically'),
 
67
  );
68
  }
69
  }
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
36
  {
37
  return array(
38
  array(
39
+ 'label' => Mage::helper('budgetmailer')
40
+ ->__('Display checked checkbox'),
41
  'value' => self::CHECKED
42
  ),
43
  array(
44
+ 'label' => Mage::helper('budgetmailer')
45
+ ->__('Display unchecked checkbox'),
46
  'value' => self::UNCHECKED
47
  ),
48
  array(
49
+ 'label' => Mage::helper('budgetmailer')
50
+ ->__('Don\'t display checkbox, sign-up automatically'),
51
  'value' => self::HIDDENCHECKED
52
  ),
53
  );
66
  self::UNCHECKED =>
67
  Mage::helper('budgetmailer')->__('Display unchecked checkbox'),
68
  self::HIDDENCHECKED =>
69
+ Mage::helper('budgetmailer')
70
+ ->__('Don\'t display checkbox, sign-up automatically'),
71
  );
72
  }
73
  }
app/code/community/Professio/BudgetMailer/Model/Config/Source/Address.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/code/community/Professio/BudgetMailer/Model/Config/Source/Delete.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -24,6 +24,7 @@
24
  class Professio_BudgetMailer_Model_Config_Source_Delete
25
  {
26
  const ON_DELETE_DELETE = 'delete';
 
27
  const ON_DELETE_IGNORE = 'ignore';
28
 
29
  /**
@@ -38,6 +39,11 @@ class Professio_BudgetMailer_Model_Config_Source_Delete
38
  'label' => Mage::helper('budgetmailer')->__('Delete Contact'),
39
  'value' => self::ON_DELETE_DELETE
40
  ),
 
 
 
 
 
41
  array(
42
  'label' => Mage::helper('budgetmailer')->__('Do nothing'),
43
  'value' => self::ON_DELETE_IGNORE
@@ -55,6 +61,9 @@ class Professio_BudgetMailer_Model_Config_Source_Delete
55
  return array(
56
  self::ON_DELETE_DELETE =>
57
  Mage::helper('budgetmailer')->__('Delete Contact'),
 
 
 
58
  self::ON_DELETE_IGNORE =>
59
  Mage::helper('budgetmailer')->__('Do nothing'),
60
  );
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
24
  class Professio_BudgetMailer_Model_Config_Source_Delete
25
  {
26
  const ON_DELETE_DELETE = 'delete';
27
+ const ON_DELETE_DEL_UNSUB = 'deleteunsub';
28
  const ON_DELETE_IGNORE = 'ignore';
29
 
30
  /**
39
  'label' => Mage::helper('budgetmailer')->__('Delete Contact'),
40
  'value' => self::ON_DELETE_DELETE
41
  ),
42
+ array(
43
+ 'label' => Mage::helper('budgetmailer')
44
+ ->__('Delete and unsubscribe Contact'),
45
+ 'value' => self::ON_DELETE_DEL_UNSUB
46
+ ),
47
  array(
48
  'label' => Mage::helper('budgetmailer')->__('Do nothing'),
49
  'value' => self::ON_DELETE_IGNORE
61
  return array(
62
  self::ON_DELETE_DELETE =>
63
  Mage::helper('budgetmailer')->__('Delete Contact'),
64
+ self::ON_DELETE_DEL_UNSUB =>
65
+ Mage::helper('budgetmailer')
66
+ ->__('Delete and Unsubscribe Contact'),
67
  self::ON_DELETE_IGNORE =>
68
  Mage::helper('budgetmailer')->__('Do nothing'),
69
  );
app/code/community/Professio/BudgetMailer/Model/Config/Source/Delete/Address.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/code/community/Professio/BudgetMailer/Model/Config/Source/List.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -29,14 +29,14 @@ class Professio_BudgetMailer_Model_Config_Source_List
29
  {
30
  if (!isset($this->_lists)) {
31
  try {
32
- $collection = Mage::getModel('budgetmailer/list')
33
- ->getCollection();
34
-
35
- if ($collection) {
36
- $collection->load();
37
- $this->_lists = $collection->getIterator();
38
- } else {
39
- $this->_lists = array();
40
  }
41
  } catch (Exception $e) {
42
  $this->_lists = array();
@@ -64,14 +64,14 @@ class Professio_BudgetMailer_Model_Config_Source_List
64
  $options = array();
65
 
66
  $options[] = array(
67
- 'value' => 0,
68
  'label' => Mage::helper('budgetmailer')->__('Select List')
69
  );
70
 
71
- foreach ($this->getLists() as $list) {
72
  $options[] = array(
73
- 'value' => $list->getBudgetmailerId(),
74
- 'label' => $list->getName()
75
  );
76
  }
77
  }
@@ -89,12 +89,10 @@ class Professio_BudgetMailer_Model_Config_Source_List
89
  static $array;
90
 
91
  if (!isset($array)) {
92
- $array = array();
93
- $array[0] = Mage::helper('budgetmailer')->__('Select List');
94
-
95
- foreach ($this->getLists() as $list) {
96
- $array[$list->getId()] = $list->getName();
97
- }
98
  }
99
 
100
  return $array;
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
29
  {
30
  if (!isset($this->_lists)) {
31
  try {
32
+ $client = Mage::getModel('budgetmailer/client')
33
+ ->getClient();
34
+ $lists = $client->getLists();
35
+
36
+ if (is_array($lists) && count($lists)) {
37
+ foreach ($lists as $list) {
38
+ $this->_lists[$list->id] = $list->list;
39
+ }
40
  }
41
  } catch (Exception $e) {
42
  $this->_lists = array();
64
  $options = array();
65
 
66
  $options[] = array(
67
+ 'value' => '',
68
  'label' => Mage::helper('budgetmailer')->__('Select List')
69
  );
70
 
71
+ foreach ($this->getLists() as $listId => $listName) {
72
  $options[] = array(
73
+ 'value' => $listId,
74
+ 'label' => $listName
75
  );
76
  }
77
  }
89
  static $array;
90
 
91
  if (!isset($array)) {
92
+ $array = array(
93
+ 0 => Mage::helper('budgetmailer')->__('Select List')
94
+ );
95
+ $array = array_merge($array, $this->getLists());
 
 
96
  }
97
 
98
  return $array;
app/code/community/Professio/BudgetMailer/Model/Config/Source/Update.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/code/community/Professio/BudgetMailer/Model/Contact.php DELETED
@@ -1,600 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Contact model
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Model_Contact extends Mage_Core_Model_Abstract
25
- {
26
- /**
27
- * Entity code.
28
- * Can be used as part of method name for entity processing
29
- */
30
- const ENTITY = 'budgetmailer_contact';
31
- const CACHE_TAG = 'budgetmailer_contact';
32
-
33
- /**
34
- * Prefix of model events names
35
- * @var string
36
- */
37
- protected $_eventPrefix = 'budgetmailer_contact';
38
-
39
- /**
40
- * Parameter name in event
41
- * @var string
42
- */
43
- protected $_eventObject = 'contact';
44
-
45
- /**
46
- * Current customer
47
- * @var Mage_Customer_Model_Customer
48
- */
49
- protected $_customer;
50
-
51
- /**
52
- * Constructor
53
- */
54
- public function _construct()
55
- {
56
- parent::_construct();
57
-
58
- $this->_init('budgetmailer/contact');
59
- }
60
-
61
- /**
62
- * Before save contact
63
- *
64
- * @return Professio_BudgetMailer_Model_Contact
65
- */
66
- protected function _beforeSave()
67
- {
68
- parent::_beforeSave();
69
-
70
- $now = Mage::getSingleton('core/date')->gmtDate();
71
-
72
- if ($this->isObjectNew()) {
73
- $this->setCreatedAt($now);
74
- }
75
-
76
- $this->setUpdatedAt($now);
77
-
78
- if (!is_array($this->getTags())) {
79
- $this->setTags(array());
80
- }
81
-
82
- $this->setTags(json_encode($this->getTags()));
83
-
84
- return $this;
85
- }
86
-
87
- /**
88
- * After load - decode json encoded tags to array
89
- *
90
- * @return Professio_BudgetMailer_Model_Contact
91
- */
92
- protected function _afterLoad()
93
- {
94
- parent::_afterLoad();
95
-
96
- $this->setTags($this->decodeTags($this->getTags()));
97
-
98
- return $this;
99
- }
100
-
101
- /**
102
- * Retrieve parent
103
- *
104
- * @return null|Professio_BudgetMailer_Model_List
105
- */
106
- public function getParentList()
107
- {
108
- if (!$this->hasData('_parent_list')) {
109
- if (!$this->getListId()) {
110
- return null;
111
- } else {
112
- $list = Mage::getModel('budgetmailer/list')
113
- ->load($this->getListId());
114
-
115
- if ($list->getId()) {
116
- $this->setData('_parent_list', $list);
117
- } else {
118
- $this->setData('_parent_list', null);
119
- }
120
- }
121
- }
122
-
123
- return $this->getData('_parent_list');
124
- }
125
-
126
- /**
127
- * Get default values
128
- *
129
- * @return array
130
- */
131
- public function getDefaultValues()
132
- {
133
- $values = array();
134
- $values['status'] = 1;
135
-
136
- return $values;
137
- }
138
-
139
- /**
140
- * Delete override, allows delete contact from API
141
- *
142
- * @param boolean $fromApi true = delete from API , false = do nothing
143
- *
144
- * @return Professio_BudgetMailer_Model_Contact
145
- */
146
- public function delete($fromApi = true)
147
- {
148
- $email = $this->getEmail();
149
- // INFO ensure we have loaded email...
150
- if (empty($email)) {
151
- $this->load($this->getEntityId());
152
- }
153
-
154
- // INFO deleting local before API
155
- parent::delete();
156
-
157
- if ($fromApi) {
158
- $this->deleteFromApi();
159
- }
160
-
161
- return $this;
162
- }
163
-
164
- /**
165
- * Load method override ... automatically loading record from API
166
- * if doesn't exist locally
167
- *
168
- * @param integer $id
169
- * @param mixed $field
170
- */
171
- public function load($id, $field = null)
172
- {
173
- Mage::log('budgetmailer/contact::load()');
174
-
175
- parent::load($id, $field);
176
-
177
- Mage::log(
178
- 'budgetmailer/contact::load() orig data: '
179
- . json_encode($this->getOrigData())
180
- );
181
-
182
- if (is_null($this->getOrigData())) {
183
- Mage::log('budgetmailer/contact::load() setting original data.');
184
- $this->setOrigData();
185
- }
186
-
187
- $ttl = time() - Mage::helper('budgetmailer/config')->getSyncTtl();
188
- $updatedAt = strtotime($this->getData('updated_at'));
189
-
190
- if (!$updatedAt || $updatedAt < $ttl) {
191
- $this->loadFromApi();
192
-
193
- Mage::log(
194
- 'budgetmailer/contact::load() after load from api: '
195
- . json_encode($this->getData())
196
- );
197
-
198
- if ($this->getBudgetmailerId()) {
199
- $this->save(false);
200
- }
201
- } else {
202
- Mage::log('budgetmailer/contact::load() no api load');
203
- }
204
- }
205
-
206
- /**
207
- * Save method override - allows save contact to API
208
- *
209
- * @param boolean $useApi true = save to API, false = don't save to API
210
- */
211
- public function save($useApi = true)
212
- {
213
- $changed = false;
214
- $hasId = $this->getEntityId();
215
-
216
- if (!is_null($this->getOrigData())) {
217
- foreach ($this->getData() as $k => $v) {
218
- if ('is_massupdate' == $k) {
219
- continue;
220
- }
221
-
222
- $changed = $this->dataHasChangedFor($k);
223
-
224
- // decode orig value of tags field
225
- if ($changed && 'tags' == $k) {
226
- $ov = $this->getOrigData($k);
227
- $ov = $this->decodeTags($ov);
228
- $v = $this->decodeTags($v);
229
-
230
- $changed = $ov != $v;
231
- }
232
-
233
- if ($changed) {
234
- Mage::log(
235
- 'budgetmailer/contact::save() changed key: '
236
- . $k . ' orig: ' . json_encode($this->getOrigData($k))
237
- . ', now: ' . json_encode($v)
238
- );
239
- break;
240
- }
241
- }
242
- } else {
243
- Mage::log('budgetmailer/contact::save() no orig data...');
244
- // INFO i guess it's new then?!?!?!
245
- $changed = true;
246
- }
247
-
248
- Mage::log(
249
- 'budgetmailer/contact::save() changed: '
250
- . ($changed ? 'yes' : 'no') . ', with data: '
251
- . json_encode($this->getData())
252
- );
253
-
254
- if (!$hasId && $this->getCustomerId()) {
255
- Mage::log('budgetmailer/contact::save() no id.');
256
-
257
- $customer = Mage::getModel('customer/customer')
258
- ->load($this->getCustomerId());
259
- $tags = Mage::helper('budgetmailer')
260
- ->getCategoryNamesOfOrderedProducts($customer);
261
-
262
- Mage::log('budgetmailer/contact::save() tags: ' . json_encode($tags));
263
-
264
- if (count($tags)) {
265
- $this->setTags($tags);
266
- }
267
- } else {
268
- Mage::log('budgetmailer/contact::save() has id.');
269
- }
270
-
271
- if ($useApi && $changed) {
272
- $this->saveToApi();
273
- }
274
-
275
- parent::save();
276
- }
277
-
278
- /**
279
- * Get BudgetMailer client
280
- *
281
- * @return Professio_BudgetMailer_Model_Client
282
- */
283
- protected function getClient()
284
- {
285
- return Mage::getSingleton('budgetmailer/client');
286
- }
287
-
288
- /**
289
- * Get customer for this contact
290
- *
291
- * @return Mage_Customer_Model_Customer
292
- */
293
- protected function getCustomer()
294
- {
295
- if (!isset($this->_customer)) {
296
- if (isset($this->_data['customer_id'])) {
297
- $this->_customer = Mage::getModel('customer/customer')
298
- ->load($this->_data['customer_id']);
299
- } elseif (isset($this->_data['email'])) {
300
- $this->_customer = Mage::getModel('customer/customer')
301
- ->loadByEmail($this->_data['email']);
302
- }
303
- }
304
-
305
- return $this->_customer;
306
- }
307
-
308
- /**
309
- * Get mapper
310
- *
311
- * @return Professio_BudgetMailer_Helper_Mapper
312
- */
313
- protected function getMapper()
314
- {
315
- return Mage::helper('budgetmailer/mapper');
316
- }
317
-
318
- /**
319
- * Load contact by budgetmailer id
320
- *
321
- * @param string $budgetmailerId
322
- * @param boolean $useApi true = try to load from API
323
- *
324
- * @return Professio_BudgetMailer_Model_Contact
325
- */
326
- public function loadByBudgetMailerId($budgetmailerId, $useApi = true)
327
- {
328
- $this->_getResource()->loadByBudgetMailerId($this, $budgetmailerId);
329
-
330
- $ttl = time() - Mage::helper('budgetmailer/config')->getSyncTtl();
331
-
332
- // not found try to load from API
333
- if ($useApi && (
334
- !$this->getData('updated_at')
335
- || $this->getData('updated_at') < $ttl
336
- )
337
- ) {
338
- $this->setBudgetmailerId($budgetmailerId);
339
- $this->load($this->getId());
340
- }
341
-
342
- return $this;
343
- }
344
-
345
- /**
346
- * Load by customer
347
- *
348
- * @param Mage_Customer_Model_Customer $customer
349
- * @param boolean $useApi true = try to load from API
350
- *
351
- * @return Professio_BudgetMailer_Model_Contact
352
- */
353
- public function loadByCustomer($customer, $useApi = true)
354
- {
355
- if (!$customer->getEntityId()) {
356
- $this->setData(array());
357
-
358
- return $this;
359
- }
360
-
361
- $this->_getResource()->loadByCustomer($this, $customer);
362
-
363
- $ttl = time() - Mage::helper('budgetmailer/config')->getSyncTtl();
364
-
365
- // not found try to load from API
366
- if ($useApi && (
367
- !$this->getData('updated_at')
368
- || $this->getData('updated_at') < $ttl
369
- )
370
- ) {
371
- $this->setEmail($customer->getEmail());
372
- $this->setCustomerId($customer->getId());
373
- $this->load($this->getId());
374
- }
375
-
376
- return $this;
377
- }
378
-
379
- /**
380
- * Load by email
381
- * @param string $email
382
- * @param boolean $useApi true = try to load from API
383
- * @return Professio_BudgetMailer_Model_Contact
384
- */
385
- public function loadByEmail($email, $useApi = true)
386
- {
387
- $this->_getResource()->loadByEmail($this, $email);
388
-
389
- $ttl = time() - Mage::helper('budgetmailer/config')->getSyncTtl();
390
-
391
- // not found try to load from API
392
- if ($useApi && (
393
- !$this->getData('updated_at')
394
- || $this->getData('updated_at') < $ttl
395
- )
396
- ) {
397
- $this->setEmail($email);
398
- $this->load($this->getId());
399
- }
400
-
401
- return $this;
402
- }
403
-
404
- /**
405
- * Load by subscriber
406
- *
407
- * @param Mage_Newsletter_Model_Subscriber $subscriber
408
- * @param boolean $useApi true = try to load from API
409
- *
410
- * @return Professio_BudgetMailer_Model_Contact
411
- */
412
- public function loadBySubscriber($subscriber, $useApi = true)
413
- {
414
- if ($subscriber->getCustomer() && $subscriber->getCustomer()->getId()) {
415
- $this->_getResource()
416
- ->loadByCustomer($this, $subscriber->getCustomer());
417
- } else {
418
- $this->_getResource()
419
- ->loadByEmail($this, $subscriber->getEmail());
420
- }
421
-
422
- $ttl = time() - Mage::helper('budgetmailer/config')->getSyncTtl();
423
-
424
- // not found try to load from API
425
- if ($useApi && (
426
- !$this->getData('updated_at')
427
- || $this->getData('updated_at') < $ttl
428
- )
429
- ) {
430
- $this->setEmail($subscriber->getEmail());
431
- $this->load($this->getId());
432
- }
433
-
434
- return $this;
435
- }
436
-
437
- /**
438
- * Delete contact from API
439
- *
440
- * @param null|string $email email or use current contact email
441
- *
442
- * @return boolean
443
- */
444
- public function deleteFromApi($email = null)
445
- {
446
- $email = is_null($email) ? $this->getEmail() : $email;
447
- $list = $this->getList()
448
- ? $this->getMapper()->listIdToBudgetmailerId($this->getList())
449
- : null;
450
-
451
- return $this->getClient()->deleteContact($email, $list);
452
- }
453
-
454
- /**
455
- * Load contact from API - will use either budgetmailer id or email
456
- *
457
- * @return boolean
458
- */
459
- public function loadFromApi()
460
- {
461
- if ($this->getBudgetmailerId()) {
462
- $id = $this->getBudgetmailerId();
463
- } else if ($this->getEmail()) {
464
- $id = $this->getEmail();
465
- } else {
466
- throw new Exception('Don\'t know how to load contact from API.');
467
- }
468
-
469
- if (!$id) {
470
- return false;
471
- }
472
-
473
- $contact = $this->getClient()->getContact($id);
474
- $this->getMapper()->contactToModel($contact, $this);
475
-
476
- return true;
477
- }
478
-
479
- /**
480
- * INFO this method expected subscribe/unsubscribed to be set from outside
481
- *
482
- * Save contact to API
483
- * @return boolean
484
- */
485
- public function saveToApi()
486
- {
487
- Mage::log('budgetmailer/contact::saveToApi() start');
488
-
489
- if ($this->getBudgetmailerId()) {
490
- $id = $this->getBudgetmailerId();
491
- } else {
492
- $id = $this->getEmail();
493
- }
494
-
495
- if (!$id) {
496
- return false;
497
- }
498
-
499
- $contactApi = $this->getClient()->getContact($id);
500
- $contactApiNew = $this->getMapper()->contactToApi($this, $contactApi);
501
-
502
- if (!is_object($contactApi)
503
- || !isset($contactApi->id) || !$contactApi->id
504
- ) {
505
- Mage::log('budgetmailer/contact::saveToApi(): post');
506
-
507
- $this->getMapper()->prepareContactApi($contactApiNew);
508
-
509
- Mage::log(
510
- 'budgetmailer/contact::saveToApi(): '
511
- . json_encode($contactApiNew)
512
- );
513
-
514
- $contactApiNew = $this->getClient()->postContact($contactApiNew);
515
- $this->getMapper()->contactToModel($contactApiNew, $this);
516
-
517
- $this->save(false);
518
- } else {
519
- Mage::log('budgetmailer/contact::saveToApi(): put');
520
-
521
- $list = $this->getList()
522
- ? $this->getMapper()->listIdToBudgetmailerId($this->getList())
523
- : null;
524
-
525
- $this->getClient()->putContact($id, $contactApiNew, $list);
526
- }
527
-
528
- Mage::log('budgetmailer/contact::saveToApi() end');
529
- }
530
-
531
- /**
532
- * Add tags to this contact, and save to API
533
- *
534
- * @param array $orderTags
535
- * @param boolean $useApi true = save to API
536
- *
537
- * @return void
538
- */
539
- public function addTags($orderTags, $useApi = true)
540
- {
541
- if (!is_array($orderTags) || !count($orderTags)) {
542
- return;
543
- }
544
-
545
- $newTags = array();
546
- $tags = $this->getTags();
547
-
548
- if (is_array($tags) && count($tags)) {
549
- foreach ($orderTags as $tag) {
550
- if (!in_array($tag, $tags)) {
551
- $newTags = $orderTags;
552
- }
553
- }
554
- } else {
555
- $newTags = $orderTags;
556
- }
557
-
558
- if (count($newTags)) {
559
- $this->setTags(array_merge($tags, $newTags));
560
- $this->save($useApi);
561
-
562
- $this->getClient()->postTags($this->getBudgetmailerId(), $newTags);
563
- }
564
- }
565
-
566
- /**
567
- * Make sure tags are decoded
568
- * @param mixed $tags string or array
569
- * @return array
570
- */
571
- protected function decodeTags($tags)
572
- {
573
- if (is_string($tags)) {
574
- $tags = json_decode($tags);
575
- } else if (!is_array($tags)) {
576
- $tags = array();
577
- }
578
-
579
- return $tags;
580
- }
581
-
582
- /**
583
- * Collect all category names of the previously ordered customer products
584
- */
585
- public function collectTags()
586
- {
587
- if ($this->getCustomerId()) {
588
- $customer = Mage::getModel('customer/customer')->load(
589
- $this->getCustomerId()
590
- );
591
-
592
- $tags = Mage::helper('budgetmailer')
593
- ->getCategoryNamesOfOrderedProducts($customer);
594
-
595
- if (count($tags)) {
596
- $this->setTags($tags);
597
- }
598
- }
599
- }
600
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Model/Exporter.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -24,95 +24,37 @@
24
  class Professio_BudgetMailer_Model_Exporter
25
  {
26
  /**
27
- * Customers collection
28
- * @var Mage_Customer_Model_Resource_Customer_Collection
29
  */
30
- protected $_customersCollection;
31
-
32
- /**
33
- * Subscribers collection
34
- * @var Mage_Newsletter_Model_Resource_Subscriber_Collection
35
- */
36
- protected $_subscribersCollection;
37
-
38
- /**
39
- * Unregistered customer orders collection
40
- * @var Mage_Sales_Model_Resource_Order_Collection
41
- */
42
- protected $_unregisteredCollection;
43
 
44
  /**
45
  * Get BudgetMailer API client
46
  *
47
- * @return Professio_BudgetMailer_Model_Client
48
  */
49
  protected function getClient()
50
  {
51
- return Mage::getSingleton('budgetmailer/client');
52
- }
53
-
54
- /**
55
- * Get contact model
56
- *
57
- * @return Professio_BudgetMailer_Model_Contact
58
- */
59
- protected function getContact()
60
- {
61
- return Mage::getModel('budgetmailer/contact');
62
- }
63
-
64
- /**
65
- * Prepare and get customers collection
66
- *
67
- * @return Mage_Customer_Model_Resource_Customer_Collection
68
- */
69
- protected function getCustomersCollection()
70
- {
71
- if (!isset($this->_customersCollection)) {
72
- $this->_customersCollection = Mage::getModel('customer/customer')
73
- ->getCollection();
74
- $this->_customersCollection
75
- ->addAttributeToSelect('*')
76
- ->setPageSize(Professio_BudgetMailer_Model_Client::LIMIT);
77
- }
78
-
79
- return $this->_customersCollection;
80
- }
81
-
82
- /**
83
- * Prepare and get subscribers collection
84
- *
85
- * @return Mage_Newsletter_Model_Resource_Subscriber_Collection
86
- */
87
- protected function getSubscribersCollection()
88
- {
89
- if (!isset($this->_subscribersCollection)) {
90
- $this->_subscribersCollection =
91
- Mage::getModel('newsletter/subscriber')->getCollection();
92
- $this->_subscribersCollection
93
- ->setPageSize(Professio_BudgetMailer_Model_Client::LIMIT);
94
- }
95
-
96
- return $this->_subscribersCollection;
97
  }
98
 
99
  /**
100
- * Prepare and get collection of orders from unregistered customers
101
- *
102
- * @return Mage_Sales_Model_Resource_Order_Collection
103
  */
104
- protected function getUnregisteredCollection()
105
  {
106
- if (!isset($this->_unregisteredCollection)) {
107
- $this->_unregisteredCollection =
108
- Mage::getModel('sales/order')->getCollection();
109
- $this->_unregisteredCollection
110
- ->setPageSize(Professio_BudgetMailer_Model_Client::LIMIT);
111
- $this->_unregisteredCollection
112
- ->addAttributeToFilter('customer_id', array('null' => true));
113
  }
114
 
115
- return $this->_unregisteredCollection;
116
  }
117
 
118
  /**
@@ -142,402 +84,401 @@ class Professio_BudgetMailer_Model_Exporter
142
  {
143
  $this->log('budgetmailer/exporter::exportCustomers() start');
144
 
 
145
  $totals = array('total' => 0, 'fail' => 0, 'success' => 0);
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  try {
148
- $total = $this->getCustomersCollection()->getSize();
 
 
 
 
 
 
 
 
149
 
 
 
150
  if ($total > 0) {
151
-
152
  $page = 1;
153
- $pages = ceil(
154
- $total / Professio_BudgetMailer_Model_Client::LIMIT
155
- );
156
 
157
  $this->log(
158
- 'budgetmailer/exporter::exportCustomers() customers: '
159
  . $total . ', customer pages: ' . $pages
160
  );
161
-
162
  do {
163
- $this->getCustomersCollection()->clear();
164
- $this->getCustomersCollection()->setCurPage($page);
165
- $this->getCustomersCollection()->load();
166
 
167
- list($total, $fail, $success) =
168
- $this->exportCustomersPage();
169
-
170
- $totals['total'] += $total;
171
- $totals['fail'] += $fail;
172
- $totals['success'] += $success;
173
 
174
  $page++;
175
  } while ($page <= $pages);
176
  } else {
177
  $this->log(
178
- 'budgetmailer/exporter::exportCustomers() no customers'
179
  );
180
  }
181
- } catch(Exception $e) {
182
  $this->log(
183
- 'budgetmailer/exporter::exportCustomers() failed '
184
  . 'with exception: ' . $e->getMessage()
185
  );
186
 
187
  Mage::logException($e);
188
  }
189
 
190
- $this->log('budgetmailer/exporter::exportCustomers() end');
191
-
192
- return $totals;
193
  }
194
 
195
  /**
196
- * Export single customers page
197
- *
198
- * @param boolean $subscribe (un)subscribe
199
- * @return array
200
  */
201
- protected function exportCustomersPage($subscribe = true)
202
  {
203
- $this->log('budgetmailer/exporter::exportCustomersPage() start');
204
 
205
  try {
206
- $contacts = $emails = array();
207
- $total = $fail = $success = 0;
208
 
209
  foreach (
210
- $this->getCustomersCollection()->getIterator() as $customer
211
  ) {
212
- $contact = $this->getContact();
213
- $contact->loadByCustomer($customer, false);
214
-
215
- if (!$contact->getEntityId()) {
216
- $this->getMapper()->customerToModel($customer, $contact);
217
-
218
- $address = $this->getHelper()
219
- ->getCustomersPrimaryAddress($customer);
220
-
221
- if ($address && $address->getEntityId()) {
222
- $this->getMapper()->addressToModel($address, $contact);
223
- }
224
-
225
- $contact->setCustomerId($customer->getEntityId());
226
- $contact->setEmail($customer->getEmail());
227
-
228
- $contact->setUnsubscribed(!$subscribe);
229
- $contact->setSubscribe($subscribe);
230
- $contact->collectTags();
231
- //$contact->setIsMassupdate(true);
232
- //$contact->save(false);
233
-
234
- $emails[] = $contact->getEmail();
235
- } else {
236
- $contact->setUnsubscribed(!$subscribe);
237
- $contact->setSubscribe($subscribe);
238
  }
239
-
240
- $contacts[] = $this->getMapper()->contactToApi($contact);
241
  }
242
 
243
  if (count($contacts)) {
244
- list($total, $fail, $success, $contactsNew) =
245
- $this->getClient()->postContacts(
246
- $contacts, Professio_BudgetMailer_Model_Client::BULK_INS
247
- );
248
 
249
- if (isset($contactsNew->Success) && is_array($contactsNew->Success)) {
250
- foreach ($contactsNew->Success as $contact) {
251
- Mage::getModel('budgetmailer/importer')
252
- ->importContact($contact);
253
- }
254
- }
255
  }
256
  } catch (Exception $e) {
257
  $this->log(
258
- 'budgetmailer/exporter::exportCustomersPage() failed '
259
  . 'with exception: ' . $e->getMessage()
260
  );
261
 
262
  Mage::logException($e);
263
  }
264
 
265
- $this->log(
266
- 'budgetmailer/exporter::exportCustomersPage() end (total: '
267
- . $total . ', fail: ' . $fail . ', success: ' . $success
268
- );
269
-
270
- return array($total, $fail, $success);
271
  }
272
 
273
  /**
274
- * Export all subscribers to BudgetMailer API
275
- *
276
  * @return array
277
  */
278
  public function exportSubscribers()
279
  {
280
  $this->log('budgetmailer/exporter::exportSubscribers() start');
281
 
 
282
  $totals = array('total' => 0, 'fail' => 0, 'success' => 0);
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  try {
285
- $total = $this->getSubscribersCollection()->getSize();
 
 
 
 
 
 
 
286
 
 
 
287
  if ($total > 0) {
288
  $page = 1;
289
- $pages = ceil(
290
- $total / Professio_BudgetMailer_Model_Client::LIMIT
291
- );
292
 
293
  $this->log(
294
- 'budgetmailer/exporter::exportSubscribers() '
295
- . 'subscribers: ' . $total . ', subscriber pages: '
296
- . $pages
297
  );
298
-
299
  do {
300
- $this->getSubscribersCollection()->clear();
301
- $this->getSubscribersCollection()->setCurPage($page);
302
- $this->getSubscribersCollection()->load();
303
-
304
- list($total, $fail, $success) =
305
- $this->exportSubscribersPage();
306
-
307
- $totals['total'] += $total;
308
- $totals['fail'] += $fail;
309
- $totals['success'] += $success;
310
 
311
  $page++;
312
  } while ($page <= $pages);
313
  } else {
314
  $this->log(
315
- 'budgetmailer/exporter::exportSubscribers() no subscribers'
316
  );
317
  }
318
- } catch(Exception $e) {
319
  $this->log(
320
- 'budgetmailer/exporter::exportSubscribers() failed '
321
  . 'with exception: ' . $e->getMessage()
322
  );
323
 
324
  Mage::logException($e);
325
  }
326
 
327
- $this->log('budgetmailer/exporter::exportSubscribers() end');
328
-
329
- return $totals;
330
  }
331
 
332
  /**
333
- * Export single subscribers page
334
- *
335
- * @param boolean $subscribe (un)subscribe
336
- * @return array
337
  */
338
- protected function exportSubscribersPage($subscribe = true)
339
  {
340
- $this->log('budgetmailer/exporter::exportSubscribersPage() start');
341
 
342
  try {
343
  $contacts = array();
344
- $total = $fail = $success = 0;
345
 
346
  foreach (
347
- $this->getSubscribersCollection()->getIterator() as $subscriber
348
  ) {
349
- $contact = $this->getContact();
350
- $contact->loadBySubscriber($subscriber, false);
351
-
352
- if (!$contact->getEntityId()) {
353
- if ($subscriber->getCustomer()) {
354
- $this->getMapper()
355
- ->customerToModel(
356
- $subscriber->getCustomer(),
357
- $contact
358
- );
359
-
360
- $address = $this->getHelper()
361
- ->getCustomersPrimaryAddress(
362
- $subscriber->getCustomer()
363
- );
364
-
365
- if ($address && $address->getEntityId()) {
366
- $this->getMapper()
367
- ->addressToModel($address, $contact);
368
- }
369
-
370
- $contact->setCustomerId(
371
- $subscriber->getCustomer()->getEntityId()
372
- );
373
- }
374
-
375
- $contact->setEmail($subscriber->getEmail());
376
 
377
- $contact->setUnsubscribed(!$subscribe);
378
- $contact->setSubscribe($subscribe);
379
- //$contact->setIsMassupdate(true);
380
- //$contact->save(false);
381
- } else {
382
- $contact->setUnsubscribed(!$subscribe);
383
- $contact->setSubscribe($subscribe);
384
  }
385
-
386
- $contacts[] = $this->getMapper()->contactToApi($contact);
387
  }
388
 
389
  if (count($contacts)) {
390
- list($total, $fail, $success, $contactsNew) =
391
- $this->getClient()->postContacts(
392
- $contacts, Professio_BudgetMailer_Model_Client::BULK_INS
393
- );
394
 
395
- if (isset($contactsNew->Success) && is_array($contactsNew->Success)) {
396
- foreach ($contactsNew->Success as $contact) {
397
- Mage::getModel('budgetmailer/importer')
398
- ->importContact($contact);
399
- }
400
- }
401
  }
402
  } catch (Exception $e) {
403
  $this->log(
404
- 'budgetmailer/exporter::exportSubscribersPage() failed '
405
  . 'with exception: ' . $e->getMessage()
406
  );
407
 
408
  Mage::logException($e);
409
  }
410
 
411
- $this->log(
412
- 'budgetmailer/exporter::exportSubscribersPage() end (total: '
413
- . $total . ', fail: ' . $fail . ', success: ' . $success
414
- );
415
-
416
- return array($total, $fail, $success);
417
  }
418
 
419
- public function exportUnregistered($subscribe = true)
 
 
 
 
420
  {
421
  $this->log('budgetmailer/exporter::exportUnregistered() start');
422
 
 
423
  $totals = array('total' => 0, 'fail' => 0, 'success' => 0);
424
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  try {
426
- $total = $this->getUnregisteredCollection()->getSize();
 
427
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  if ($total > 0) {
429
  $page = 1;
430
- $pages = ceil(
431
- $total / Professio_BudgetMailer_Model_Client::LIMIT
432
- );
433
 
434
  $this->log(
435
- 'budgetmailer/exporter::exportUnregistered() '
436
- . 'total: ' . $total . ', pages: '
437
- . $pages
438
  );
439
-
440
  do {
441
- $this->getUnregisteredCollection()->clear();
442
- $this->getUnregisteredCollection()->setCurPage($page);
443
- $this->getUnregisteredCollection()->load();
444
-
445
- list($total, $fail, $success) =
446
- $this->exportUnregisteredPage($subscribe);
447
-
448
- $totals['total'] += $total;
449
- $totals['fail'] += $fail;
450
- $totals['success'] += $success;
451
 
452
  $page++;
453
  } while ($page <= $pages);
454
  } else {
455
  $this->log(
456
- 'budgetmailer/exporter::exportUnregistered() no unregistered orders'
457
  );
458
  }
459
- } catch(Exception $e) {
460
  $this->log(
461
- 'budgetmailer/exporter::exportUnregistered() failed '
462
  . 'with exception: ' . $e->getMessage()
463
  );
464
 
465
  Mage::logException($e);
466
  }
467
 
468
- $this->log('budgetmailer/exporter::exportUnregistered() end');
469
-
470
- return $totals;
471
  }
472
 
473
- public function exportUnregisteredPage($subscribe = true)
 
 
 
 
 
 
474
  {
475
- $this->log('budgetmailer/exporter::exportUnregisteredPage() start');
476
-
 
 
477
  try {
478
- $contacts = $emails = array();
479
- $total = $fail = $success = 0;
480
 
481
  foreach (
482
- $this->getUnregisteredCollection()->getIterator() as $order
483
  ) {
484
- $contact = $this->getContact();
485
- $contact->loadByEmail($order->getCustomerOrder(), false);
486
-
487
- if (!$contact->getEntityId()) {
488
- $this->getMapper()->orderToModel($order, $contact);
489
-
490
- $address = $order->getBillingAddress();
491
-
492
- if ($address && $address->getEntityId()) {
493
- $this->getMapper()->addressToModel($address, $contact);
494
- }
495
 
496
- $contact->setUnsubscribed(!$subscribe);
497
- $contact->setSubscribe($subscribe);
498
-
499
- if (Mage::helper('budgetmailer/config')->isAdvancedOnOrderEnabled()) {
500
- $tags = $this->getHelper()->getOrderTags($order);
501
- $contact->setTags($tags);
502
- }
503
-
504
- $emails[] = $contact->getEmail();
505
- } else {
506
- $contact->setUnsubscribed(!$subscribe);
507
- $contact->setSubscribe($subscribe);
508
  }
509
-
510
- $contacts[] = $this->getMapper()->contactToApi($contact);
511
  }
512
 
513
  if (count($contacts)) {
514
- list($total, $fail, $success, $contactsNew) =
515
- $this->getClient()->postContacts(
516
- $contacts, Professio_BudgetMailer_Model_Client::BULK_INS
517
- );
518
 
519
- if (isset($contactsNew->Success) && is_array($contactsNew->Success)) {
520
- foreach ($contactsNew->Success as $contact) {
521
- Mage::getModel('budgetmailer/importer')
522
- ->importContact($contact);
523
- }
524
- }
525
  }
526
  } catch (Exception $e) {
527
  $this->log(
528
- 'budgetmailer/exporter::exportUnregisteredPage() failed '
529
  . 'with exception: ' . $e->getMessage()
530
  );
531
 
532
  Mage::logException($e);
533
  }
534
 
535
- $this->log(
536
- 'budgetmailer/exporter::exportUnregisteredPage() end (total: '
537
- . $total . ', fail: ' . $fail . ', success: ' . $success
538
- );
539
-
540
- return array($total, $fail, $success);
541
  }
542
 
543
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
24
  class Professio_BudgetMailer_Model_Exporter
25
  {
26
  /**
27
+ * List of store ids
28
+ * @var array
29
  */
30
+ protected $_storeIds;
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  /**
33
  * Get BudgetMailer API client
34
  *
35
+ * @return \BudgetMailer\Api\Client
36
  */
37
  protected function getClient()
38
  {
39
+ return Mage::getSingleton('budgetmailer/client')->getClient();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
 
42
  /**
43
+ * Get list of store ids
44
+ * @return array
 
45
  */
46
+ protected function getStoreIds()
47
  {
48
+ if (!isset($this->_storeIds)) {
49
+ $stores = Mage::app()->getStores();
50
+ $this->_storeIds = array();
51
+
52
+ foreach ($stores as $store) {
53
+ $this->_storeIds[] = $store->getId();
54
+ }
55
  }
56
 
57
+ return $this->_storeIds;
58
  }
59
 
60
  /**
84
  {
85
  $this->log('budgetmailer/exporter::exportCustomers() start');
86
 
87
+ $storeIds = $this->getStoreIds();
88
  $totals = array('total' => 0, 'fail' => 0, 'success' => 0);
89
 
90
+ foreach ($storeIds as $storeId) {
91
+ $this->exportCustomersStore($storeId, $totals);
92
+ }
93
+
94
+ $this->log('budgetmailer/exporter::exportCustomers() end');
95
+
96
+ return $totals;
97
+ }
98
+
99
+ /**
100
+ * Export customes from store
101
+ * @param integer $storeId
102
+ * @param array $totals
103
+ */
104
+ public function exportCustomersStore($storeId, &$totals)
105
+ {
106
+ $this->log(
107
+ 'budgetmailer/exporter::exportCustomersStore() start (store id: '
108
+ . $storeId . ').'
109
+ );
110
+
111
  try {
112
+ $client = Mage::getSingleton('budgetmailer/client')
113
+ ->getStoreClient($storeId);
114
+
115
+ $collection = Mage::getModel('customer/customer')
116
+ ->getCollection();
117
+ $collection
118
+ ->addAttributeToSelect('*')
119
+ ->addFieldToFilter('store_id', $storeId)
120
+ ->setPageSize(\BudgetMailer\Api\Client::LIMIT);
121
 
122
+ $total = $collection->getSize();
123
+
124
  if ($total > 0) {
 
125
  $page = 1;
126
+ $pages = ceil($total / \BudgetMailer\Api\Client::LIMIT);
 
 
127
 
128
  $this->log(
129
+ 'budgetmailer/exporter::exportCustomersStore() customers: '
130
  . $total . ', customer pages: ' . $pages
131
  );
132
+
133
  do {
134
+ $collection->clear();
135
+ $collection->setCurPage($page);
136
+ $collection->load();
137
 
138
+ $this->exportCustomersStorePage(
139
+ $client, $collection, $totals
140
+ );
 
 
 
141
 
142
  $page++;
143
  } while ($page <= $pages);
144
  } else {
145
  $this->log(
146
+ 'budgetmailer/exporter::exportCustomersStore() no customers'
147
  );
148
  }
149
+ } catch (Exception $e) {
150
  $this->log(
151
+ 'budgetmailer/exporter::exportCustomersStore() failed '
152
  . 'with exception: ' . $e->getMessage()
153
  );
154
 
155
  Mage::logException($e);
156
  }
157
 
158
+ $this->log('budgetmailer/exporter::exportCustomersStore() end');
 
 
159
  }
160
 
161
  /**
162
+ * Export one page from store customers
163
+ * @param \BudgetMailer\Api\Client $client
164
+ * @param Mage_Customer_Model_Resource_Customer_Collection $collection
165
+ * @param array $totals
166
  */
167
+ public function exportCustomersStorePage($client, $collection, &$totals)
168
  {
169
+ $this->log('budgetmailer/exporter::exportCustomersStorePage() start');
170
 
171
  try {
172
+ $contacts = array();
 
173
 
174
  foreach (
175
+ $collection->getIterator() as $customer
176
  ) {
177
+ $contact = new stdClass();
178
+ $this->getMapper()->customerToContact($customer, $contact);
179
+
180
+ $contact->unsubscribed = false;
181
+ $contact->subscribe = true;
182
+
183
+ $tags = $this->getHelper()
184
+ ->getCategoryNamesOfOrderedProducts($customer);
185
+
186
+ if ($tags) {
187
+ $contact->tags = $tags;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  }
189
+
190
+ $contacts[] = $contact;
191
  }
192
 
193
  if (count($contacts)) {
194
+ list($total, $fail, $success) =
195
+ $client->postContactsBulk($contacts);
 
 
196
 
197
+ $totals['total'] += $total;
198
+ $totals['fail'] += $fail;
199
+ $totals['success'] += $success;
 
 
 
200
  }
201
  } catch (Exception $e) {
202
  $this->log(
203
+ 'budgetmailer/exporter::exportCustomersStorePage() failed '
204
  . 'with exception: ' . $e->getMessage()
205
  );
206
 
207
  Mage::logException($e);
208
  }
209
 
210
+ $this->log('budgetmailer/exporter::exportCustomersStorePage() end');
 
 
 
 
 
211
  }
212
 
213
  /**
214
+ * Export newsletter subscribers
 
215
  * @return array
216
  */
217
  public function exportSubscribers()
218
  {
219
  $this->log('budgetmailer/exporter::exportSubscribers() start');
220
 
221
+ $storeIds = $this->getStoreIds();
222
  $totals = array('total' => 0, 'fail' => 0, 'success' => 0);
223
 
224
+ foreach ($storeIds as $storeId) {
225
+ $this->exportSubscribersStore($storeId, $totals);
226
+ }
227
+
228
+ $this->log('budgetmailer/exporter::exportSubscribers() end');
229
+
230
+ return $totals;
231
+ }
232
+
233
+ /**
234
+ * Export subscribers from store
235
+ * @param integer $storeId
236
+ * @param array $totals
237
+ */
238
+ public function exportSubscribersStore($storeId, &$totals)
239
+ {
240
+ $this->log('budgetmailer/exporter::exportSubscribersStore() start');
241
+
242
  try {
243
+ $client = Mage::getSingleton('budgetmailer/client')
244
+ ->getStoreClient($storeId);
245
+
246
+ $collection = Mage::getModel('newsletter/subscriber')
247
+ ->getCollection();
248
+ $collection
249
+ ->addFieldToFilter('store_id', $storeId)
250
+ ->setPageSize(\BudgetMailer\Api\Client::LIMIT);
251
 
252
+ $total = $collection->getSize();
253
+
254
  if ($total > 0) {
255
  $page = 1;
256
+ $pages = ceil($total / \BudgetMailer\Api\Client::LIMIT);
 
 
257
 
258
  $this->log(
259
+ 'budgetmailer/exporter::exportSubscribersStore() '
260
+ . 'subscribers: ' . $total . ', subscriber pages: ' . $pages
 
261
  );
262
+
263
  do {
264
+ $collection->clear();
265
+ $collection->setCurPage($page);
266
+ $collection->load();
267
+
268
+ $this->exportSubscribersStorePage(
269
+ $client, $collection, $totals
270
+ );
 
 
 
271
 
272
  $page++;
273
  } while ($page <= $pages);
274
  } else {
275
  $this->log(
276
+ 'budgetmailer/exporter::exportSubscribersStore() no subscr.'
277
  );
278
  }
279
+ } catch (Exception $e) {
280
  $this->log(
281
+ 'budgetmailer/exporter::exportSubscribersStore() failed '
282
  . 'with exception: ' . $e->getMessage()
283
  );
284
 
285
  Mage::logException($e);
286
  }
287
 
288
+ $this->log('budgetmailer/exporter::exportSubscribersStore() end');
 
 
289
  }
290
 
291
  /**
292
+ * Export subscribers one page from store subscribers
293
+ * @param \BudgetMailer\Api\Client $client
294
+ * @param Mage_Newsletter_Model_Resource_Subscriber_Collection $collection
295
+ * @param array $totals
296
  */
297
+ public function exportSubscribersStorePage($client, $collection, &$totals)
298
  {
299
+ $this->log('budgetmailer/exporter::exportSubscribersStorePage() start');
300
 
301
  try {
302
  $contacts = array();
 
303
 
304
  foreach (
305
+ $collection->getIterator() as $subscriber
306
  ) {
307
+ $contact = new stdClass();
308
+ $this->getMapper()->subscriberToContact($subscriber, $contact);
309
+
310
+ $contact->unsubscribed = false;
311
+ $contact->subscribe = true;
312
+
313
+ $customer = $subscriber->getCustomer();
314
+
315
+ if ($customer && $customer->getEntityId()) {
316
+ $this->getMapper()->customerToContact($customer, $contact);
317
+
318
+ $tags = $this->getHelper()
319
+ ->getCategoryNamesOfOrderedProducts($customer);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
 
321
+ if ($tags) {
322
+ $contact->tags = $tags;
323
+ }
 
 
 
 
324
  }
325
+
326
+ $contacts[] = $contact;
327
  }
328
 
329
  if (count($contacts)) {
330
+ list($total, $fail, $success) =
331
+ $client->postContactsBulk($contacts);
 
 
332
 
333
+ $totals['total'] += $total;
334
+ $totals['fail'] += $fail;
335
+ $totals['success'] += $success;
 
 
 
336
  }
337
  } catch (Exception $e) {
338
  $this->log(
339
+ 'budgetmailer/exporter::exportCustomersStorePage() failed '
340
  . 'with exception: ' . $e->getMessage()
341
  );
342
 
343
  Mage::logException($e);
344
  }
345
 
346
+ $this->log('budgetmailer/exporter::exportSubscribersStorePage() end');
 
 
 
 
 
347
  }
348
 
349
+ /**
350
+ * Export unregistered customers
351
+ * @return array
352
+ */
353
+ public function exportUnregistered()
354
  {
355
  $this->log('budgetmailer/exporter::exportUnregistered() start');
356
 
357
+ $storeIds = $this->getStoreIds();
358
  $totals = array('total' => 0, 'fail' => 0, 'success' => 0);
359
 
360
+ foreach ($storeIds as $storeId) {
361
+ $this->exportUnregisteredStore($storeId, $totals);
362
+ }
363
+
364
+ $this->log('budgetmailer/exporter::exportUnregistered() end');
365
+
366
+ return $totals;
367
+ }
368
+
369
+ /**
370
+ * Export unregistered customers from one store
371
+ * @param integer $storeId
372
+ * @param array $totals
373
+ */
374
+ public function exportUnregisteredStore($storeId, &$totals)
375
+ {
376
+ $this->log('budgetmailer/exporter::exportUnregisteredStore() start');
377
+
378
  try {
379
+ $client = Mage::getSingleton('budgetmailer/client')
380
+ ->getStoreClient($storeId);
381
 
382
+ $collection = Mage::getModel('sales/order')
383
+ ->getCollection();
384
+ $collection
385
+ ->addAttributeToFilter('customer_id', array('null' => true))
386
+ ->addFieldToFilter('store_id', $storeId)
387
+ ->setPageSize(\BudgetMailer\Api\Client::LIMIT);
388
+
389
+ // avoid duplicates
390
+ $collection->getSelect()->group('main_table.customer_email');
391
+
392
+ $total = $collection->getSize();
393
+
394
  if ($total > 0) {
395
  $page = 1;
396
+ $pages = ceil($total / \BudgetMailer\Api\Client::LIMIT);
 
 
397
 
398
  $this->log(
399
+ 'budgetmailer/exporter::exportUnregisteredStore() '
400
+ . 'orders: ' . $total . ', order pages: ' . $pages
 
401
  );
402
+
403
  do {
404
+ $collection->clear();
405
+ $collection->setCurPage($page);
406
+ $collection->load();
407
+
408
+ $this->exportUnregisteredStorePage(
409
+ $client, $collection, $totals
410
+ );
 
 
 
411
 
412
  $page++;
413
  } while ($page <= $pages);
414
  } else {
415
  $this->log(
416
+ 'budgetmailer/exporter::exportUnregisteredStore() no orders'
417
  );
418
  }
419
+ } catch (Exception $e) {
420
  $this->log(
421
+ 'budgetmailer/exporter::exportUnregisteredStore() failed '
422
  . 'with exception: ' . $e->getMessage()
423
  );
424
 
425
  Mage::logException($e);
426
  }
427
 
428
+ $this->log('budgetmailer/exporter::exportUnregisteredStore() end');
 
 
429
  }
430
 
431
+ /**
432
+ * Export one page of unregistered customers from one store
433
+ * @param \BudgetMailer\Api\Client $client
434
+ * @param Mage_Sales_Model_Resource_Order_Collection $collection
435
+ * @param array $totals
436
+ */
437
+ public function exportUnregisteredStorePage($client, $collection, &$totals)
438
  {
439
+ $this->log(
440
+ 'budgetmailer/exporter::exportUnregisteredStorePage() start'
441
+ );
442
+
443
  try {
444
+ $contacts = array();
 
445
 
446
  foreach (
447
+ $collection->getIterator() as $order
448
  ) {
449
+ $contact = new stdClass();
450
+ $this->getMapper()->orderToContact($order, $contact);
451
+
452
+ $contact->unsubscribed = false;
453
+ $contact->subscribe = true;
454
+
455
+ $tags = $this->getHelper()->getOrderTags($order);
 
 
 
 
456
 
457
+ if ($tags) {
458
+ $contact->tags = $tags;
 
 
 
 
 
 
 
 
 
 
459
  }
460
+
461
+ $contacts[] = $contact;
462
  }
463
 
464
  if (count($contacts)) {
465
+ list($total, $fail, $success) =
466
+ $client->postContactsBulk($contacts);
 
 
467
 
468
+ $totals['total'] += $total;
469
+ $totals['fail'] += $fail;
470
+ $totals['success'] += $success;
 
 
 
471
  }
472
  } catch (Exception $e) {
473
  $this->log(
474
+ 'budgetmailer/exporter::exportUnregisteredStorePage() failed '
475
  . 'with exception: ' . $e->getMessage()
476
  );
477
 
478
  Mage::logException($e);
479
  }
480
 
481
+ $this->log('budgetmailer/exporter::exportSubscribersStorePage() end');
 
 
 
 
 
482
  }
483
 
484
  /**
app/code/community/Professio/BudgetMailer/Model/Importer.php DELETED
@@ -1,505 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Importer model
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Model_Importer
25
- {
26
- const ACTION_INSERT = 'insert';
27
- const ACTION_UPDATE = 'update';
28
- const ACTION_DELETE = 'delete';
29
-
30
- /**
31
- * Cache of all budgetmailer ids in API
32
- * @var array
33
- */
34
- protected $_budgetmailerIds;
35
- /**
36
- * Contacts collection
37
- * @var Professio_BudgetMailer_Model_Resource_Contact_Collection
38
- */
39
- protected $_contactsCollection;
40
-
41
- /**
42
- * Get API client
43
- *
44
- * @return Professio_BudgetMailer_Model_Client
45
- */
46
- protected function getClient()
47
- {
48
- return Mage::getSingleton('budgetmailer/client');
49
- }
50
-
51
- /**
52
- * Get contact
53
- *
54
- * @return Professio_BudgetMailer_Model_Contact
55
- */
56
- protected function getContact()
57
- {
58
- return Mage::getModel('budgetmailer/contact');
59
- }
60
-
61
- /**
62
- * Get contacts collection
63
- *
64
- * @return array
65
- */
66
- protected function getContactsCollection()
67
- {
68
- if (!isset($this->_contactsCollection)) {
69
- $this->_contactsCollection =
70
- Mage::getModel('budgetmailer/contact')->getCollection();
71
- $this->_contactsCollection
72
- ->setPageSize(Professio_BudgetMailer_Model_Client::LIMIT);
73
- $this->_contactsCollection->load();
74
- }
75
-
76
- return $this->_contactsCollection;
77
- }
78
-
79
- /**
80
- * Get mapper
81
- *
82
- * @return Professio_BudgetMailer_Helper_Mapper
83
- */
84
- protected function getMapper()
85
- {
86
- return Mage::helper('budgetmailer/mapper');
87
- }
88
-
89
- /**
90
- * Get all budgetmailer ids from API
91
- *
92
- * @return array
93
- */
94
- protected function getBudgetmailerIds()
95
- {
96
- if (!isset($this->_budgetmailerIds)) {
97
- $this->log('budgetmailer/importer::getBudgetmailerIds() start');
98
-
99
- $this->_budgetmailerIds = array();
100
- $total = $this->getClient()->getContactsCount();
101
-
102
- if ($total > 0) {
103
- $page = 0;
104
- $pages =
105
- ceil($total / Professio_BudgetMailer_Model_Client::LIMIT);
106
-
107
- $this->log(
108
- 'budgetmailer/importer::deleteOrphans() contact pages: '
109
- . $pages
110
- );
111
-
112
- do {
113
- try {
114
- $contactsApi = $this->getClient()->getContacts(
115
- $page * Professio_BudgetMailer_Model_Client::LIMIT,
116
- Professio_BudgetMailer_Model_Client::LIMIT,
117
- 'ASC',
118
- null
119
- );
120
-
121
- foreach ($contactsApi as $contactApi) {
122
- $this->_budgetmailerIds[$contactApi->id] = true;
123
- }
124
-
125
- $page++;
126
- } catch (Exception $e) {
127
- Mage::logException($e);
128
- $this->log(
129
- 'budgetmailer/importer::getBudgetmailerIds() page: '
130
- . $page . ', failed with exception: '
131
- . $e->getMessage()
132
- );
133
- }
134
- } while ($page < $pages);
135
- }
136
-
137
- $this->log(
138
- 'budgetmailer/importer::getBudgetmailerIds() end, data: '
139
- . json_encode(array_keys($this->_budgetmailerIds))
140
- );
141
- }
142
-
143
- return $this->_budgetmailerIds;
144
- }
145
-
146
- /**
147
- * Delete single orphans page
148
- *
149
- * @param integer $page
150
- *
151
- * @return array
152
- */
153
- protected function deleteOrphansPage()
154
- {
155
- $this->log('budgetmailer/importer::deleteOrphansPage() start');
156
-
157
- $totals = array(
158
- 'completed' => 0, 'deleted' => 0, 'failed' => 0, 'skipped' => 0
159
- );
160
-
161
- foreach ($this->getContactsCollection()->getIterator() as $contact) {
162
- try {
163
- $this->log(
164
- 'budgetmailer/importer::deleteOrphansPage() '
165
- . 'checking budgetmailer id: '
166
- . $contact->getBudgetmailerId()
167
- . ', has: '
168
- . (
169
- $this->hasBudgetmailerId($contact->getBudgetmailerId())
170
- ? 'yes' : 'no'
171
- )
172
- );
173
-
174
- if (!$this->hasBudgetmailerId($contact->getBudgetmailerId())) {
175
- $contact->delete(false);
176
-
177
- $totals['deleted']++;
178
- $this->log(
179
- 'budgetmailer/importer::deleteOrphansPage() '
180
- . 'deleted: ' . $contact->getEntityId()
181
- );
182
- } else {
183
- $totals['skipped']++;
184
- $this->log(
185
- 'budgetmailer/importer::deleteOrphansPage() '
186
- . 'skipping: ' . $contact->getEntityId()
187
- );
188
- }
189
-
190
- $totals['completed']++;
191
- } catch(Exception $e) {
192
- $totals['failed']++;
193
- $this->log(
194
- 'budgetmailer/importer::deleteOrphansPage() '
195
- . 'failed: ' . $contact->getEntityId()
196
- . ', with exception: ' . $e->getMessage()
197
- );
198
- Mage::logException($e);
199
- }
200
- }
201
-
202
- $this->log('budgetmailer/importer::deleteOrphansPage() start');
203
-
204
- return $totals;
205
- }
206
-
207
- /**
208
- * Delete all orphan models from database
209
- *
210
- * @return array
211
- */
212
- public function deleteOrphans()
213
- {
214
- $this->log('budgetmailer/importer::deleteOrphans() start');
215
-
216
- $total = $this->getContactsCollection()->getSize();
217
- $totals = array(
218
- 'completed' => 0, 'deleted' => 0, 'failed' => 0, 'skipped' => 0
219
- );
220
-
221
- if ($total > 0) {
222
- $page = 0;
223
- $pages = ceil($total / Professio_BudgetMailer_Model_Client::LIMIT);
224
-
225
- $this->log(
226
- 'budgetmailer/importer::deleteOrphans() local contact pages: '
227
- . $pages
228
- );
229
-
230
- do {
231
- try {
232
- $this->getContactsCollection()->clear();
233
- $this->getContactsCollection()->setCurPage($page);
234
- $this->getContactsCollection()->load();
235
-
236
- $rs = $this->deleteOrphansPage();
237
-
238
- $totals['completed'] += $rs['completed'];
239
- $totals['deleted'] += $rs['deleted'];
240
- $totals['failed'] += $rs['failed'];
241
- $totals['skipped'] += $rs['skipped'];
242
-
243
- $page++;
244
- } catch(Exception $e) {
245
- $this->log(
246
- 'budgetmailer/importer::deleteOrphans() failed page: '
247
- . $page . ', with exception: ' . $e->getMessage()
248
- );
249
- Mage::logException($e);
250
- }
251
- } while ($page <= $pages);
252
-
253
- } else {
254
- $this->log(
255
- 'budgetmailer/importer::deleteOrphans() no local contacts.'
256
- );
257
- }
258
-
259
- return $totals;
260
- }
261
-
262
- /**
263
- * Check if budgetmailer id exists
264
- *
265
- * @param string $id
266
- *
267
- * @return boolean
268
- */
269
- protected function hasBudgetmailerId($id)
270
- {
271
- $this->getBudgetmailerIds();
272
-
273
- return isset($this->_budgetmailerIds[$id]);
274
- }
275
-
276
- /**
277
- * Web hook implementation
278
- *
279
- * @param array $actions actions to process
280
- *
281
- * @return void
282
- */
283
- public function hook($actions)
284
- {
285
- foreach ($actions as $action) {
286
- if (is_object($action) && isset($action->action)) {
287
- $contact = $this->getContact();
288
-
289
- switch($action->action) {
290
- case self::ACTION_DELETE:
291
- $contact->loadByBudgetmailerId($action->contact->id);
292
- $contact->delete(false);
293
- break;
294
- case self::ACTION_INSERT:
295
- $this->getMapper()
296
- ->contactToModel($action->contact, $contact);
297
- $contact->save(false);
298
- break;
299
- case self::ACTION_UPDATE:
300
- $contact->loadByBudgetmailerId($action->contact->id);
301
- $this->getMapper()
302
- ->contactToModel($action->contact, $contact);
303
- $contact->save(false);
304
- break;
305
- default:
306
- throw new Professio_BudgetMailer_Exception(
307
- 'Unexpected hook action.'
308
- );
309
- break;
310
- }
311
- } else {
312
- throw new Professio_BudgetMailer_Exception(
313
- 'Unexpected hook action.'
314
- );
315
- }
316
- }
317
- }
318
-
319
- /**
320
- * Import single contact from API
321
- *
322
- * @param object $contactApi
323
- *
324
- * @return boolean
325
- */
326
- public function importContact($contactApi)
327
- {
328
- $this->log('budgetmailer/importer::importContact() start');
329
-
330
- // INFO we assume there is only one website
331
- $websiteId = Mage::helper('budgetmailer')->getDefaultWebsiteId();
332
-
333
- $contact = $this->getContact();
334
-
335
- $this->log(
336
- 'budgetmailer/importer::importContact() id: ' . $contactApi->id
337
- . ' email: ' . $contactApi->email
338
- );
339
-
340
- if ($contactApi->email) {
341
- $contact->loadByEmail($contactApi->email, false);
342
- }
343
-
344
- if (!$contact->getEntityId() && $contactApi->id) {
345
- $contact->loadByBudgetMailerId($contactApi->id, false);
346
- }
347
-
348
- $this->getMapper()->contactToModel($contactApi, $contact);
349
-
350
- if (!$contact->getCustomerId()) {
351
- $customer = Mage::getModel('customer/customer')
352
- ->setWebsiteId($websiteId)->loadByEmail($contactApi->email);
353
-
354
- $this->log(
355
- 'budgetmailer/importer::importContact() email: '
356
- . $contactApi->email
357
- . ', customer id: '
358
- . $customer->getEntityId()
359
- );
360
-
361
- if ($customer->getEntityId()) {
362
- $contact->setCustomerId($customer->getEntityId());
363
- }
364
- }
365
-
366
- $contact->setIsMassupdate(true);
367
- $contact->save(false);
368
-
369
- $this->log('budgetmailer/importer::importContact() end');
370
-
371
- return true;
372
- }
373
-
374
- /**
375
- * Import single page of contacts
376
- *
377
- * @param integer $page
378
- *
379
- * @return array
380
- */
381
- protected function importContactsPage($page)
382
- {
383
- $this->log(
384
- 'budgetmailer/importer::importContactsPage() start ('
385
- . $page . ')'
386
- );
387
-
388
- $completed = $failed = 0;
389
-
390
- $contactsApi = $this->getClient()->getContacts(
391
- $page * Professio_BudgetMailer_Model_Client::LIMIT,
392
- Professio_BudgetMailer_Model_Client::LIMIT,
393
- 'ASC',
394
- null
395
- );
396
-
397
- if (is_array($contactsApi) && count($contactsApi)) {
398
- foreach ($contactsApi as $contactApi) {
399
- try {
400
- $this->importContact($contactApi);
401
-
402
- $this->log(
403
- 'budgetmailer/importer::importContactsPage() '
404
- . 'saved contact: ' . json_encode($contactApi)
405
- );
406
- } catch(Exception $e) {
407
- Mage::logException($e);
408
- $this->log(
409
- 'budgetmailer/importer::importContactsPage() '
410
- . 'failed contact: ' . json_encode($contactApi)
411
- . ', with exception: ' . $e->getMessage()
412
- );
413
- $failed++;
414
- }
415
-
416
- $completed++;
417
- }
418
- }
419
-
420
- $this->log(
421
- 'budgetmailer/importer::importContactsPage() end, completed: '
422
- . $completed . ', failed: '. $failed
423
- );
424
-
425
- return array('completed' => $completed, 'failed' => $failed);
426
- }
427
-
428
- /**
429
- * Import all contacts from budgetmailer list
430
- *
431
- * @return array
432
- */
433
- public function importContacts()
434
- {
435
- $this->log('budgetmailer/importer::importContacts() start');
436
-
437
- $total = $this->getClient()->getContactsCount();
438
- $totals = array('completed' => 0, 'failed' => 0);
439
-
440
- if ($total > 0) {
441
- $page = 0;
442
- $pages = ceil($total / Professio_BudgetMailer_Model_Client::LIMIT);
443
-
444
- $this->log(
445
- 'budgetmailer/importer::importContacts() subscriber pages: '
446
- . $pages
447
- );
448
-
449
- do {
450
- $rs = $this->importContactsPage($page);
451
-
452
- $totals['completed'] += $rs['completed'];
453
- $totals['failed'] += $rs['failed'];
454
-
455
- $page++;
456
- } while ($page < $pages);
457
- }
458
-
459
- $this->log(
460
- 'budgetmailer/importer::importContacts() end: '
461
- . json_encode($totals)
462
- );
463
-
464
- return $totals;
465
- }
466
-
467
- public function deleteContact($contactApi)
468
- {
469
- $this->log('budgetmailer/importer::deleteContact() start');
470
-
471
- $contact = Mage::getModel('budgetmailer/contact');
472
-
473
- if ($contactApi->email) {
474
- $contact->loadByEmail($contactApi->email, false);
475
- }
476
-
477
- if (!$contact->getEntityId() && $contactApi->id) {
478
- $contact->loadByBudgetMailerId($contactApi->id, false);
479
- }
480
-
481
- if ($contact->getEntityId()) {
482
- $contact->delete();
483
-
484
- return true;
485
- }
486
-
487
- $this->log('budgetmailer/importer::deleteContact() end');
488
-
489
- return false;
490
- }
491
-
492
- /**
493
- * Custom logging method - logging only if in developer mode
494
- *
495
- * @param string $message
496
- *
497
- * @return void
498
- */
499
- protected function log($message)
500
- {
501
- if (Mage::getIsDeveloperMode()) {
502
- Mage::log($message);
503
- }
504
- }
505
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Model/List.php DELETED
@@ -1,138 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List model
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Model_List extends Mage_Core_Model_Abstract
25
- {
26
- /**
27
- * Entity code.
28
- * Can be used as part of method name for entity processing
29
- */
30
- const ENTITY = 'budgetmailer_list';
31
- const CACHE_TAG = 'budgetmailer_list';
32
-
33
- /**
34
- * Prefix of model events names
35
- * @var string
36
- */
37
- protected $_eventPrefix = 'budgetmailer_list';
38
-
39
- /**
40
- * Parameter name in event
41
- * @var string
42
- */
43
- protected $_eventObject = 'list';
44
-
45
- /**
46
- * Constructor
47
- *
48
- * @return void
49
- */
50
- public function _construct()
51
- {
52
- parent::_construct();
53
-
54
- $this->_init('budgetmailer/list');
55
- }
56
-
57
- /**
58
- * Before save list
59
- *
60
- * @return Professio_BudgetMailer_Model_List
61
- */
62
- protected function _beforeSave()
63
- {
64
- parent::_beforeSave();
65
-
66
- $now = Mage::getSingleton('core/date')->gmtDate();
67
-
68
- if ($this->isObjectNew()) {
69
- $this->setCreatedAt($now);
70
- }
71
-
72
- $this->setUpdatedAt($now);
73
-
74
- return $this;
75
- }
76
-
77
- /**
78
- * Retrieve collection
79
- *
80
- * @return Professio_BudgetMailer_Model_Contact_Collection
81
- */
82
- public function getSelectedContactsCollection()
83
- {
84
- if (!$this->hasData('_contact_collection')) {
85
- if (!$this->getId()) {
86
- return new Varien_Data_Collection();
87
- } else {
88
- $collection = Mage::getResourceModel(
89
- 'budgetmailer/contact_collection'
90
- )->addFieldToFilter('list_id', $this->getId());
91
- $this->setData('_contact_collection', $collection);
92
- }
93
- }
94
-
95
- return $this->getData('_contact_collection');
96
- }
97
-
98
- /**
99
- * Get default values
100
- *
101
- * @return array
102
- */
103
- public function getDefaultValues()
104
- {
105
- $values = array();
106
- $values['status'] = 1;
107
-
108
- return $values;
109
- }
110
-
111
- /**
112
- * Load list by budgetmailer id
113
- *
114
- * @param string $budgetmailerId
115
- * @param boolean $useApi true = try to load from API
116
- *
117
- * @return Professio_BudgetMailer_Model_Contact
118
- */
119
- public function loadByBudgetMailerId($budgetmailerId, $useApi = true)
120
- {
121
- $this->_getResource()->loadByBudgetMailerId($this, $budgetmailerId);
122
-
123
- $ttl = time() - Mage::helper('budgetmailer/config')->getSyncTtl();
124
-
125
- // not found try to load from API
126
- if ($useApi && (
127
- !$this->getData('updated_at')
128
- || $this->getData('updated_at') < $ttl
129
- )
130
- ) {
131
- $this->setBudgetmailerId($budgetmailerId);
132
- $this->load($this->getId());
133
- }
134
-
135
- return $this;
136
- }
137
-
138
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Model/Observer.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -21,16 +21,17 @@
21
  * @category Professio
22
  * @package Professio_BudgetMailer
23
  */
 
24
  class Professio_BudgetMailer_Model_Observer
25
  {
26
  /**
27
  * Get BudgetMailer API client
28
  *
29
- * @return Professio_BudgetMailer_Model_Client
30
  */
31
  protected function getClient()
32
  {
33
- return Mage::getSingleton('budgetmailer/client');
34
  }
35
 
36
  /**
@@ -75,6 +76,34 @@ class Professio_BudgetMailer_Model_Observer
75
  }
76
  }
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  /**
79
  * After address save, check if primary and update contact
80
  *
@@ -84,55 +113,49 @@ class Professio_BudgetMailer_Model_Observer
84
  {
85
  $this->log('budgetmailer/observer::addressSaveAfter() start');
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  try {
88
  if (Mage::helper('budgetmailer/config')
89
  ->isAdvancedOnAddressUpdateEnabled()
90
- ) {
91
  $address = $observer->getCustomerAddress();
92
  $customer = $address->getCustomer();
93
 
94
- $this->log(
95
- 'budgetmailer/observer::addressSaveAfter address id: '
96
- . $address->getEntityId()
97
- );
98
-
99
- if ($customer && $customer->getEntityId()) {
100
- $contact = Mage::getModel('budgetmailer/contact')
101
- ->loadByCustomer($customer);
102
-
103
- if ($contact && $contact->getEntityId()) {
104
- $addressPrimary = Mage::helper('budgetmailer')
105
- ->getCustomersPrimaryAddress($customer);
106
-
107
- // check if primary address
108
- if (!$addressPrimary
109
- || ($addressPrimary->getEntityId()
110
- == $address->getEntityId())
111
- ) {
112
  Mage::helper('budgetmailer/mapper')
113
- ->addressToModel($address, $contact);
114
-
115
- $contact->save();
116
-
117
- $this->log(
118
- 'budgetmailer/observer::addressSaveAfter() '
119
- . 'updated contact'
120
- );
121
- } else {
122
- $this->log(
123
- 'budgetmailer/observer::addressSaveAfter() '
124
- . 'DIDN\'T update contact'
125
- );
126
  }
127
  } else {
128
  $this->log(
129
- 'budgetmailer/observer::addressSaveAfter() '
130
- . 'no contact'
131
  );
132
  }
133
  } else {
134
  $this->log(
135
- 'budgetmailer/observer::addressSaveAfter() no customer'
136
  );
137
  }
138
  } else {
@@ -165,14 +188,31 @@ class Professio_BudgetMailer_Model_Observer
165
  try {
166
  if (Mage::helper('budgetmailer/config')
167
  ->isAdvancedOnCustomerDeleteEnabled()
 
 
168
  ) {
169
  $customer = $observer->getCustomer();
 
 
 
 
170
 
171
- $contact = Mage::getModel('budgetmailer/contact');
172
- $contact->loadByCustomer($customer);
173
-
174
- if ($contact->getEntityId()) {
175
- $contact->delete();
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  $this->log(
178
  'budgetmailer/observer::customerDeleteAfter() '
@@ -215,67 +255,51 @@ class Professio_BudgetMailer_Model_Observer
215
  $this->log('budgetmailer/observer::customerSaveAfterAdmin() start');
216
 
217
  try {
218
- $contactData = $this->getRequest()->getPost('contact');
219
-
 
 
 
 
 
 
 
220
  $customer = $observer->getEvent()->getCustomer();
221
- $contact = Mage::getModel('budgetmailer/contact')
222
- ->loadByCustomer($customer);
223
 
224
- $this->log(
225
- 'budgetmailer/observer::customerSaveAfterAdmin() contact: '
226
- . $contact->getEntityId() . ', customer: '
227
- . $customer->getEntityId()
228
- );
229
 
230
- // MAP CONTACT DATA
231
- $hasContactData = is_array($contactData) && count($contactData);
232
 
233
- if ($hasContactData) {
234
- $contactData['unsubscribed'] =
235
- !isset($contactData['subscribe']);
236
- $contact->addData($contactData);
237
-
238
- $this->log(
239
- 'budgetmailer/observer::customerSaveAfterAdmin() '
240
- . 'mapped contact data to contact: '
241
- . json_encode($contactData) . '.'
242
- );
243
- } else {
244
- $this->log(
245
- 'budgetmailer/observer::customerSaveAfterAdmin() '
246
- . 'no contact data.'
247
- );
248
  }
249
 
250
- // MAP CUSTOMER
251
- if (Mage::helper('budgetmailer/config')
252
- ->isAdvancedOnCustomerUpdateEnabled()
253
- ) {
254
- Mage::helper('budgetmailer/mapper')
255
- ->customerToModel($customer, $contact);
256
-
257
- $this->log(
258
- 'budgetmailer/observer::customerSaveAfterAdmin() '
259
- . 'mapped customer to contact.'
260
- );
261
  } else {
262
- $this->log(
263
- 'budgetmailer/observer::customerSaveAfterAdmin() '
264
- . 'customer update disabled.'
265
- );
266
  }
267
 
268
- $this->customerSaveAfterAdminAddress($contact, $customer);
 
269
 
270
- if ($contact->getEntityId()
271
- || ( $hasContactData && isset($contactData['subscribe']) )
272
- ) {
273
- $this->log(
274
- 'budgetmailer/observer::customerSaveAfterAdmin() saving.'
275
- );
276
-
277
- $contact->save();
278
  }
 
279
  } catch (Exception $e) {
280
  $this->getSession()->addError($e->getMessage());
281
  $this->log(
@@ -288,38 +312,6 @@ class Professio_BudgetMailer_Model_Observer
288
  $this->log('budgetmailer/observer::customerSaveAfterAdmin() end');
289
  }
290
 
291
- protected function customerSaveAfterAdminAddress($contact, $customer)
292
- {
293
- // MAP ADDRESS
294
- if (Mage::helper('budgetmailer/config')
295
- ->isAdvancedOnAddressUpdateEnabled()
296
- && $customer && $customer->getEntityId()
297
- ) {
298
- $address = Mage::helper('budgetmailer')
299
- ->getCustomersPrimaryAddress($customer);
300
-
301
- if ($address && $address->getEntityId()) {
302
- $this->log(
303
- 'budgetmailer/observer::customerSaveAfterAdmin()'
304
- . ' mapping address: ' . $address->getEntityId()
305
- );
306
-
307
- Mage::helper('budgetmailer/mapper')
308
- ->addressToModel($address, $contact);
309
- } else {
310
- $this->log(
311
- 'budgetmailer/observer::customerSaveAfterAdmin() '
312
- . 'no address'
313
- );
314
- }
315
- } else {
316
- $this->log(
317
- 'budgetmailer/observer::customerSaveAfterAdmin() '
318
- . 'not mapping address'
319
- );
320
- }
321
- }
322
-
323
  /**
324
  * Front - customer save after. If update of contact by customer is enabled
325
  * update contact. If there is subscribed parameter after registering new
@@ -332,73 +324,43 @@ class Professio_BudgetMailer_Model_Observer
332
  $this->log('budgetmailer/observer::customerSaveAfterFront() start');
333
 
334
  try {
335
- $bmIsSubscribed = $this->getRequest()->get('bm_is_subscribed');
336
- $changed = false;
337
-
338
- $customer = $observer->getEvent()->getCustomer();
339
- $contact = Mage::getModel('budgetmailer/contact')
340
- ->loadByCustomer($customer);
341
-
342
- $this->log(
343
- 'budgetmailer/observer::customerSaveAfterFront() contact: '
344
- . $contact->getEntityId() . ', customer: '
345
- . $customer->getEntityId()
346
- );
347
-
348
- if ($bmIsSubscribed) {
349
- $changed = true;
350
-
351
- $contact->setSubscribe(true);
352
- $contact->setUnsubscribed(false);
353
-
354
- $this->log(
355
- 'budgetmailer/observer::customerSaveAfterFront() '
356
- . 'subscribing.'
357
- );
358
- } else {
359
  $this->log(
360
- 'budgetmailer/observer::customerSaveAfterFront() '
361
- . 'not subscribing.'
362
  );
 
363
  }
364
 
365
- if (Mage::helper('budgetmailer/config')
366
- ->isAdvancedOnCustomerUpdateEnabled()
367
- ) {
368
- if ($contact->getEntityId() || $bmIsSubscribed) {
369
- $changed = true;
370
-
371
- Mage::helper('budgetmailer/mapper')
372
- ->customerToModel($customer, $contact);
373
-
374
- $this->log(
375
- 'budgetmailer/observer::customerSaveAfterFront() '
376
- . 'mapped customer to contact.'
377
- );
378
- } else {
379
- // INFO this was creating contacts without subscribing
380
- $this->log(
381
- 'budgetmailer/observer::customerSaveAfterFront() '
382
- . 'DIDN\'T mapped customer to contact, because '
383
- . 'contact doesnt\'t exist yet..'
384
- );
385
- }
386
- } else {
387
- $this->log(
388
- 'budgetmailer/observer::customerSaveAfterFront() '
389
- . 'customer update disabled.'
390
- );
391
- }
392
 
393
- if ($changed) {
394
- $this->log(
395
- 'budgetmailer/observer::customerSaveAfterFront() saving.'
 
 
 
 
 
 
 
 
396
  );
397
- $contact->save();
398
- } else {
399
- $this->log(
400
- 'budgetmailer/observer::customerSaveAfterFront() not saved.'
 
 
 
401
  );
 
 
 
 
 
402
  }
403
  } catch (Exception $e) {
404
  $this->getSession()->addError($e->getMessage());
@@ -423,49 +385,45 @@ class Professio_BudgetMailer_Model_Observer
423
  $this->log('budgetmailer/observer::salesOrderPlaceAfter() start');
424
 
425
  try {
426
- $budgetmailerSubscribe = Mage::app()->getRequest()
427
  ->getPost('bm_is_subscribed');
428
 
429
- if ($budgetmailerSubscribe) {
430
- $order = $observer->getEvent()->getOrder();
431
- $email = $order->getCustomerEmail();
432
-
433
- $contact = Mage::getModel('budgetmailer/contact');
434
- $contact->loadByEmail($email);
435
-
436
- Mage::helper('budgetmailer/mapper')
437
- ->addressToModel($order->getBillingAddress(), $contact);
438
- Mage::helper('budgetmailer/mapper')
439
- ->orderToModel($order, $contact);
 
 
 
 
 
 
440
 
441
- $contact->setSubscribe(true);
442
- $contact->save();
 
 
 
 
 
 
443
  }
444
-
445
  if (Mage::helper('budgetmailer/config')
446
  ->isAdvancedOnOrderEnabled()) {
447
- $order = $observer->getEvent()->getOrder();
448
- $contact = Mage::getModel('budgetmailer/contact');
449
- $customer = $order->getCustomer();
450
-
451
- $contact->loadByCustomer($customer);
452
-
453
- $this->log(
454
- 'budgetmailer/observer::salesOrderPlaceAfter() order: '
455
- . $order->getEntityId() . ', customer: '
456
- . $customer->getEntityId() . ', contact: '
457
- . $contact->getEntityId()
458
- );
459
-
460
- if ($contact->getEntityId()) {
461
  $orderTags = Mage::helper('budgetmailer')
462
  ->getOrderTags($order);
463
 
464
- $this->log(
465
- 'budgetmailer/observer::salesOrderPlaceAfter() '
466
- . 'adding tags: ' . json_encode($orderTags)
467
- );
468
- $contact->addTags($orderTags, false);
469
  }
470
  } else {
471
  $this->log(
@@ -485,43 +443,9 @@ class Professio_BudgetMailer_Model_Observer
485
  $this->log('budgetmailer/observer::salesOrderPlaceAfter() end');
486
  }
487
 
488
- /**
489
- * Cron method. Periodically delete orphans, and import new contacts
490
- */
491
- public function cron()
492
- {
493
- Mage::log('budgetmailer/observer::cron() start');
494
-
495
- if (Mage::helper('budgetmailer/config')->isSyncCronEnabled()) {
496
- try {
497
- $rs = Mage::getSingleton('budgetmailer/importer')
498
- ->deleteOrphans();
499
- $rs = Mage::getSingleton('budgetmailer/importer')
500
- ->importContacts();
501
-
502
- Mage::log(
503
- ($rs
504
- ? 'budgetmailer/observer::cron() no contacts'
505
- : 'budgetmailer/observer::cron() completed: '
506
- . $rs['completed'] . ', failed: ' . $rs['failed']
507
- )
508
- );
509
- } catch (Exception $e) {
510
- $this->getSession()->addError($e->getMessage());
511
- Mage::log(
512
- 'budgetmailer/observer::cron() failed with exception: '
513
- . $e->getMessage()
514
- );
515
- Mage::logException($e);
516
- }
517
- }
518
-
519
- Mage::log('budgetmailer/observer::cron() end');
520
- }
521
-
522
  /**
523
  * After saving configuration of BudgetMailer - validate API key
524
- * and secret. Initiate lists collection.
525
  *
526
  * @param Varien_Event_Observer $observer
527
  */
@@ -530,21 +454,12 @@ class Professio_BudgetMailer_Model_Observer
530
  $this->log('budgetmailer/observer::afterConfigChange() start');
531
 
532
  try {
533
- $p = $this->getRequest()->getPost();
534
- $t = $this->getClient()
535
- ->testApiCredentials($p['groups']['api']['fields']);
536
-
537
- if (!$t) {
538
  $this->getSession()->addError(
539
  Mage::helper('budgetmailer')
540
  ->__('Invalid API endpoint, key and secret combination.')
541
  );
542
  } else {
543
- // INFO this block could be in testApiCredentials
544
- $list = Mage::getModel('budgetmailer/list');
545
- $collection = $list->getCollection();
546
- $collection->load(false, false, true, true);
547
-
548
  $this->getSession()->addSuccess(
549
  Mage::helper('budgetmailer')
550
  ->__(
@@ -552,6 +467,10 @@ class Professio_BudgetMailer_Model_Observer
552
  )
553
  );
554
  }
 
 
 
 
555
  } catch (Exception $e) {
556
  $this->getSession()->addError($e->getMessage());
557
  $this->log(
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
21
  * @category Professio
22
  * @package Professio_BudgetMailer
23
  */
24
+
25
  class Professio_BudgetMailer_Model_Observer
26
  {
27
  /**
28
  * Get BudgetMailer API client
29
  *
30
+ * @return \BudgetMailer\Api\Client
31
  */
32
  protected function getClient()
33
  {
34
+ return Mage::getSingleton('budgetmailer/client')->getClient();
35
  }
36
 
37
  /**
76
  }
77
  }
78
 
79
+ /**
80
+ * Check if current address is the right type.
81
+ * @param type $address
82
+ * @param type $customer
83
+ */
84
+ protected function isAddressSaveAfter($address, $customer)
85
+ {
86
+ if ($customer->getDefaultBillingAddress()) {
87
+ $billing = $address->getEntityId() == $customer
88
+ ->getDefaultBillingAddress()->getEntityId()
89
+ && Mage::helper('budgetmailer/config')
90
+ ->isAddressTypeBilling();
91
+ } else {
92
+ $billing = false;
93
+ }
94
+
95
+ if ($customer->getDefaultShippingAddress()) {
96
+ $shipping = $address->getEntityId() == $customer
97
+ ->getDefaultShippingAddress()->getEntityId()
98
+ && Mage::helper('budgetmailer/config')
99
+ ->isAddressTypeShipping();
100
+ } else {
101
+ $shipping = false;
102
+ }
103
+
104
+ return $billing || $shipping;
105
+ }
106
+
107
  /**
108
  * After address save, check if primary and update contact
109
  *
113
  {
114
  $this->log('budgetmailer/observer::addressSaveAfter() start');
115
 
116
+ $request = $this->getRequest();
117
+
118
+ if ('customer' == $request->getModuleName()
119
+ && 'account' == $request->getControllerName()
120
+ && 'editPost' == $request->getActionName()
121
+ ) {
122
+ // INFO if saving customer don't fire this event
123
+ $this->log(
124
+ 'budgetmailer/observer::addressSaveAfter() skip duplic. event'
125
+ );
126
+
127
+ return;
128
+ }
129
+
130
  try {
131
  if (Mage::helper('budgetmailer/config')
132
  ->isAdvancedOnAddressUpdateEnabled()
133
+ ) {
134
  $address = $observer->getCustomerAddress();
135
  $customer = $address->getCustomer();
136
 
137
+ if ($this->isAddressSaveAfter($address, $customer)) {
138
+
139
+ if ($customer && $customer->getEntityId()) {
140
+ $client = $this->getClient();
141
+ $contact = $client->getContact($customer->getEmail());
142
+
143
+ if ($contact) {
 
 
 
 
 
 
 
 
 
 
 
144
  Mage::helper('budgetmailer/mapper')
145
+ ->addressToContact(
146
+ $address, $contact
147
+ );
148
+
149
+ $client->putContact($contact->email, $contact);
 
 
 
 
 
 
 
 
150
  }
151
  } else {
152
  $this->log(
153
+ 'budgetmailer/observer::addressSaveAfter() no cust.'
 
154
  );
155
  }
156
  } else {
157
  $this->log(
158
+ 'budgetmailer/observer::addressSaveAfter() wrong type'
159
  );
160
  }
161
  } else {
188
  try {
189
  if (Mage::helper('budgetmailer/config')
190
  ->isAdvancedOnCustomerDeleteEnabled()
191
+ || Mage::helper('budgetmailer/config')
192
+ ->isAdvancedOnCustomerDeleteUnsubscribeEnabled()
193
  ) {
194
  $customer = $observer->getCustomer();
195
+ $client = Mage::getSingleton('budgetmailer/client')
196
+ ->getStoreClient($customer->getStoreId());
197
+ $email = $customer->getEmail();
198
+ $contact = $client->getContact($email);
199
 
200
+ if ($contact) {
201
+ if (Mage::helper('budgetmailer/config')
202
+ ->isAdvancedOnCustomerDeleteUnsubscribeEnabled()) {
203
+ $contact->subscribe = false;
204
+ $contact->unsubscribed = true;
205
+
206
+ $client->putContact($contact->email, $contact);
207
+
208
+ $this->log(
209
+ 'budgetmailer/observer::customerDeleteAfter() '
210
+ . 'unsubscribe / delete contact for customer id: '
211
+ . $customer->getEntityId()
212
+ );
213
+ }
214
+
215
+ $client->deleteContact($email);
216
 
217
  $this->log(
218
  'budgetmailer/observer::customerDeleteAfter() '
255
  $this->log('budgetmailer/observer::customerSaveAfterAdmin() start');
256
 
257
  try {
258
+ if (!Mage::helper('budgetmailer/config')
259
+ ->isAdvancedOnCustomerUpdateEnabled() ) {
260
+ // nothing to do
261
+ $this->log(
262
+ 'budgetmailer/observer::customerSaveAfterAdmin() disabled'
263
+ );
264
+ return;
265
+ }
266
+
267
  $customer = $observer->getEvent()->getCustomer();
268
+ $client = Mage::getSingleton('budgetmailer/client')
269
+ ->getStoreClient($customer->getStoreId());
270
 
271
+ $email = $customer->getOrigData('email')
272
+ ? $customer->getOrigData('email')
273
+ : $customer->getData('email');
 
 
274
 
275
+ $contact = $client->getContact($email);
276
+ $subscribe = $this->getRequest()->getPost('budgetmailer_subscribe');
277
 
278
+ if (!$contact && !$subscribe) {
279
+ // nothing to do 2
280
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
281
  }
282
 
283
+ if (!$contact) {
284
+ $contact = new stdClass();
285
+ $new = true;
 
 
 
 
 
 
 
 
286
  } else {
287
+ // unsub only if contact
288
+ $new = false;
 
 
289
  }
290
 
291
+ Mage::helper('budgetmailer/mapper')
292
+ ->customerToContact($customer, $contact);
293
 
294
+ $contact->subscribe = $subscribe;
295
+ $contact->unsubscribed = !$subscribe;
296
+
297
+ if ($new) {
298
+ $client->postContact($contact);
299
+ } else {
300
+ $client->putContact($email, $contact);
 
301
  }
302
+
303
  } catch (Exception $e) {
304
  $this->getSession()->addError($e->getMessage());
305
  $this->log(
312
  $this->log('budgetmailer/observer::customerSaveAfterAdmin() end');
313
  }
314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  /**
316
  * Front - customer save after. If update of contact by customer is enabled
317
  * update contact. If there is subscribed parameter after registering new
324
  $this->log('budgetmailer/observer::customerSaveAfterFront() start');
325
 
326
  try {
327
+ if (!Mage::helper('budgetmailer/config')
328
+ ->isAdvancedOnCustomerUpdateEnabled() ) {
329
+ // nothing to do
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  $this->log(
331
+ 'budgetmailer/observer::customerSaveAfterFront() disabled'
 
332
  );
333
+ return;
334
  }
335
 
336
+ $client = $this->getClient();
337
+ $customer = $observer->getEvent()->getCustomer();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
 
339
+ $email = $customer->getOrigData('email')
340
+ ? $customer->getOrigData('email')
341
+ : $customer->getData('email');
342
+
343
+ $contact = $client->getContact($email);
344
+
345
+ $subscribe = Mage::app()->getRequest()->getPost('bm_is_subscribed');
346
+
347
+ if ($contact) {
348
+ Mage::helper('budgetmailer/mapper')->customerToContact(
349
+ $customer, $contact
350
  );
351
+
352
+ $client->putContact($email, $contact);
353
+ } else if ($subscribe) {
354
+ $contact = new stdClass();
355
+
356
+ Mage::helper('budgetmailer/mapper')->customerToContact(
357
+ $customer, $contact
358
  );
359
+
360
+ $contact->subscribe = $subscribe;
361
+ $contact->unsubscribed = !$subscribe;
362
+
363
+ $client->postContact($contact);
364
  }
365
  } catch (Exception $e) {
366
  $this->getSession()->addError($e->getMessage());
385
  $this->log('budgetmailer/observer::salesOrderPlaceAfter() start');
386
 
387
  try {
388
+ $subscribe = Mage::app()->getRequest()
389
  ->getPost('bm_is_subscribed');
390
 
391
+ $client = Mage::getSingleton('budgetmailer/client')->getClient();
392
+
393
+ $order = $observer->getEvent()->getOrder();
394
+ $email = $order->getCustomerEmail();
395
+ $contact = $client->getContact($email);
396
+
397
+ if ($subscribe) {
398
+ if (!$contact) {
399
+ $contact = new stdClass();
400
+
401
+ Mage::helper('budgetmailer/mapper')
402
+ ->orderToContact($order, $contact);
403
+
404
+ $new = true;
405
+ } else {
406
+ $new = false;
407
+ }
408
 
409
+ $contact->subscribe = $subscribe;
410
+ $contact->unsubscribed = !$subscribe;
411
+
412
+ if ($new) {
413
+ $client->postContact($contact);
414
+ } else {
415
+ $client->putContact($contact->email, $contact);
416
+ }
417
  }
418
+
419
  if (Mage::helper('budgetmailer/config')
420
  ->isAdvancedOnOrderEnabled()) {
421
+
422
+ if ($contact) {
 
 
 
 
 
 
 
 
 
 
 
 
423
  $orderTags = Mage::helper('budgetmailer')
424
  ->getOrderTags($order);
425
 
426
+ $client->postTags($email, $orderTags);
 
 
 
 
427
  }
428
  } else {
429
  $this->log(
443
  $this->log('budgetmailer/observer::salesOrderPlaceAfter() end');
444
  }
445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  /**
447
  * After saving configuration of BudgetMailer - validate API key
448
+ * and secret. Optionally flush cache (if disabled).
449
  *
450
  * @param Varien_Event_Observer $observer
451
  */
454
  $this->log('budgetmailer/observer::afterConfigChange() start');
455
 
456
  try {
457
+ if (!$this->getClient()->isConnected()) {
 
 
 
 
458
  $this->getSession()->addError(
459
  Mage::helper('budgetmailer')
460
  ->__('Invalid API endpoint, key and secret combination.')
461
  );
462
  } else {
 
 
 
 
 
463
  $this->getSession()->addSuccess(
464
  Mage::helper('budgetmailer')
465
  ->__(
467
  )
468
  );
469
  }
470
+
471
+ if (!Mage::helper('budgetmailer/config')->isCacheEnabled()) {
472
+ $this->getClient()->getCache()->purge();
473
+ }
474
  } catch (Exception $e) {
475
  $this->getSession()->addError($e->getMessage());
476
  $this->log(
app/code/community/Professio/BudgetMailer/Model/Resource/Contact.php DELETED
@@ -1,156 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Contact model
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Model_Resource_Contact
25
- extends Mage_Core_Model_Resource_Db_Abstract
26
- {
27
- /**
28
- * Constructor
29
- */
30
- public function _construct()
31
- {
32
- $this->_init('budgetmailer/contact', 'entity_id');
33
- }
34
-
35
- /**
36
- * Load contact by budgetmailer id
37
- *
38
- * @param Professio_BudgetMailer_Model_Contact $contact
39
- * @param string $budgetmailerId
40
- *
41
- * @return Mage_Customer_Model_Resource_Customer
42
- * @throws Mage_Core_Exception
43
- */
44
- public function loadByBudgetMailerId(
45
- Professio_BudgetMailer_Model_Contact $contact,
46
- $budgetmailerId
47
- )
48
- {
49
- $adapter = $this->_getReadAdapter();
50
- $bind = array('budgetmailer_id' => $budgetmailerId);
51
-
52
- $select = $adapter->select()
53
- ->from(
54
- Mage::getSingleton('core/resource')
55
- ->getTableName('budgetmailer/contact'), array('entity_id')
56
- )
57
- ->where('budgetmailer_id = :budgetmailer_id');
58
-
59
- $contactId = $adapter->fetchOne($select, $bind);
60
-
61
- if ($contactId) {
62
- $this->load($contact, $contactId);
63
- $contact->setOrigData();
64
- } else {
65
- $contact->setData(array());
66
- }
67
-
68
- return $this;
69
- }
70
-
71
- /**
72
- * Load contact by customer
73
- *
74
- * @param Professio_BudgetMailer_Model_Contact $contact
75
- * @param Mage_Customer_Model_Customer $customer
76
- *
77
- * @return Mage_Customer_Model_Resource_Customer
78
- * @throws Mage_Core_Exception
79
- */
80
- public function loadByCustomer(
81
- Professio_BudgetMailer_Model_Contact $contact,
82
- Mage_Customer_Model_Customer $customer
83
- )
84
- {
85
- $adapter = $this->_getReadAdapter();
86
- $bind = array(
87
- 'customer_id' => $customer->getEntityId(),
88
- 'list_id' => Mage::helper('budgetmailer/mapper')
89
- ->listBudgetmailerIdToListId(
90
- Mage::helper('budgetmailer/config')->getGeneralList()
91
- )
92
- );
93
-
94
- $select = $adapter->select()
95
- ->from(
96
- Mage::getSingleton('core/resource')
97
- ->getTableName('budgetmailer/contact'), array('entity_id')
98
- )
99
- ->where('customer_id = :customer_id AND list_id = :list_id');
100
-
101
- $contactId = $adapter->fetchOne($select, $bind);
102
-
103
- if ($contactId) {
104
- Mage::log('resource loadByCustomer() loading');
105
- $this->load($contact, $contactId);
106
- $contact->setOrigData();
107
- } else {
108
- Mage::log('resource loadByCustomer() NOT loading');
109
- $contact->setData(array());
110
- }
111
-
112
- return $this;
113
- }
114
-
115
- /**
116
- * Load contact by email
117
- *
118
- * @param Professio_BudgetMailer_Model_Contact $contact
119
- * @param string $email
120
- *
121
- * @return Mage_Customer_Model_Resource_Customer
122
- * @throws Mage_Core_Exception
123
- */
124
- public function loadByEmail(
125
- Professio_BudgetMailer_Model_Contact $contact,
126
- $email
127
- )
128
- {
129
- $adapter = $this->_getReadAdapter();
130
- $bind = array(
131
- 'email' => $email,
132
- 'list_id' => Mage::helper('budgetmailer/mapper')
133
- ->listBudgetmailerIdToListId(
134
- Mage::helper('budgetmailer/config')->getGeneralList()
135
- )
136
- );
137
-
138
- $select = $adapter->select()
139
- ->from(
140
- Mage::getSingleton('core/resource')
141
- ->getTableName('budgetmailer/contact'), array('entity_id')
142
- )
143
- ->where('email = :email AND list_id = :list_id');
144
-
145
- $contactId = $adapter->fetchOne($select, $bind);
146
-
147
- if ($contactId) {
148
- $this->load($contact, $contactId);
149
- $contact->setOrigData();
150
- } else {
151
- $contact->setData(array());
152
- }
153
-
154
- return $this;
155
- }
156
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Model/Resource/Contact/Collection.php DELETED
@@ -1,79 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List collection resource
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Model_Resource_Contact_Collection
25
- extends Mage_Core_Model_Resource_Db_Collection_Abstract
26
- {
27
- /**
28
- * Something
29
- * @var array
30
- */
31
- protected $_joinedFields = array();
32
-
33
- /**
34
- * Constructor
35
- *
36
- * @return void
37
- */
38
- protected function _construct()
39
- {
40
- parent::_construct();
41
-
42
- $this->_init('budgetmailer/contact');
43
- }
44
-
45
- /**
46
- * Get SQL for get record count. Extra GROUP BY strip added.
47
- *
48
- * @return Varien_Db_Select
49
- */
50
- public function getSelectCountSql()
51
- {
52
- $countSelect = parent::getSelectCountSql();
53
- $countSelect->reset(Zend_Db_Select::GROUP);
54
-
55
- return $countSelect;
56
- }
57
-
58
-
59
- public function idsToBudgetmailerIds($ids)
60
- {
61
- $this->clear();
62
- //$this->addFieldToSelect('budgetmailer_id');
63
- $this->addFieldToFilter(
64
- 'entity_id',
65
- array(
66
- 'in' => $ids
67
- )
68
- );
69
- $this->load();
70
-
71
- $budgetmailerIds = array();
72
-
73
- foreach ($this->getIterator() as $contact) {
74
- $budgetmailerIds[] = $contact->getBudgetmailerId();
75
- }
76
-
77
- return $budgetmailerIds;
78
- }
79
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Model/Resource/List.php DELETED
@@ -1,72 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Resource for list
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Model_Resource_List
25
- extends Mage_Core_Model_Resource_Db_Abstract
26
- {
27
- /**
28
- * Constructor
29
- *
30
- * @return void
31
- */
32
- public function _construct()
33
- {
34
- $this->_init('budgetmailer/list', 'entity_id');
35
- }
36
-
37
- /**
38
- * Load list by budgetmailer id
39
- *
40
- * @param Professio_BudgetMailer_Model_List $list
41
- * @param string $budgetmailerId
42
- *
43
- * @return Mage_Customer_Model_Resource_Customer
44
- * @throws Mage_Core_Exception
45
- */
46
- public function loadByBudgetMailerId(
47
- Professio_BudgetMailer_Model_List $list,
48
- $budgetmailerId
49
- )
50
- {
51
- $adapter = $this->_getReadAdapter();
52
- $bind = array('budgetmailer_id' => $budgetmailerId);
53
-
54
- $select = $adapter->select()
55
- ->from(
56
- Mage::getSingleton('core/resource')
57
- ->getTableName('budgetmailer/list'), array('entity_id')
58
- )
59
- ->where('budgetmailer_id = :budgetmailer_id');
60
-
61
- $listId = $adapter->fetchOne($select, $bind);
62
-
63
- if ($listId) {
64
- $this->load($list, $listId);
65
- $list->setOrigData();
66
- } else {
67
- $list->setData(array());
68
- }
69
-
70
- return $this;
71
- }
72
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Model/Resource/List/Collection.php DELETED
@@ -1,177 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * List collection resource
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Model_Resource_List_Collection
25
- extends Mage_Core_Model_Resource_Db_Collection_Abstract
26
- {
27
- /**
28
- * Something?
29
- * @var array
30
- */
31
- protected $_joinedFields = array();
32
- /**
33
- * Load from API flag
34
- * @var boolean
35
- */
36
- protected $_loadingFromApi;
37
-
38
- /**
39
- * Constructor
40
- *
41
- * @return void
42
- */
43
- protected function _construct()
44
- {
45
- parent::_construct();
46
-
47
- $this->_init('budgetmailer/list');
48
- }
49
-
50
- /**
51
- * Get SQL for get record count. Extra GROUP BY strip added.
52
- *
53
- * @return Varien_Db_Select
54
- */
55
- public function getSelectCountSql()
56
- {
57
- $countSelect = parent::getSelectCountSql();
58
- $countSelect->reset(Zend_Db_Select::GROUP);
59
-
60
- return $countSelect;
61
- }
62
-
63
- /**
64
- * Get BudgetMailer client
65
- * @return Professio_BudgetMailer_Model_Client
66
- */
67
- protected function getClient()
68
- {
69
- return Mage::getSingleton('budgetmailer/client');
70
- }
71
-
72
- /**
73
- * Get mapper
74
- * @return Professio_BudgetMailer_Helper_Mapper
75
- */
76
- protected function getMapper()
77
- {
78
- return Mage::helper('budgetmailer/mapper');
79
- }
80
-
81
- /**
82
- * Load collection
83
- *
84
- * @param boolean $printQuery
85
- * @param boolean $logQuery
86
- * @param boolean $loadFromApi if true and no records -> load from api
87
- *
88
- * @return \Professio_BudgetMailer_Model_Resource_List_Collection
89
- */
90
- public function load(
91
- $printQuery = false, $logQuery = false, $loadFromApi = true,
92
- $forceLoadFromApi = false
93
- )
94
- {
95
- parent::load($printQuery, $logQuery);
96
-
97
- if ( ( !count($this->_items) && $loadFromApi ) || $forceLoadFromApi) {
98
- $this->loadFromApi();
99
- }
100
-
101
- return $this;
102
- }
103
-
104
- /**
105
- * Load list collection from API
106
- *
107
- * @return void
108
- */
109
- public function loadFromApi()
110
- {
111
- if ($this->isLoadingFromApi()) {
112
- return;
113
- }
114
-
115
- $this->setLoadingFromApi(true);
116
- // INFO this prevents cycling out (see mapper)
117
- Mage::register('budgetmailer_list_initiation', true);
118
-
119
- $lists = $this->getClient()->getLists();
120
-
121
- foreach ($lists as $list) {
122
- $model = Mage::getModel('budgetmailer/list');
123
- $model->loadByBudgetmailerId($list->id, false);
124
- $this->getMapper()->listToModel($list, $model);
125
- $model->setIsMassupdate(true);
126
- $model->save();
127
- }
128
-
129
- $this->clear();
130
- //$this->_setIsLoaded(false);
131
- //$this->load(false, false, false);
132
- parent::load(false, false);
133
-
134
- $this->setLoadingFromApi(false);
135
- Mage::unregister('budgetmailer_list_initiation');
136
- }
137
-
138
- /**
139
- * Check if loading from api is in progress.
140
- * Avoid double API loads
141
- *
142
- * @return boolean
143
- */
144
- protected function isLoadingFromApi()
145
- {
146
- return $this->_loadingFromApi;
147
- }
148
-
149
- /**
150
- * Set load from api flag value
151
- *
152
- * @param boolean $v
153
- *
154
- * @return Professio_BudgetMailer_Model_Resource_List_Collection
155
- */
156
- protected function setLoadingFromApi($v)
157
- {
158
- $this->_loadingFromApi = $v;
159
-
160
- return $this;
161
- }
162
-
163
- /**
164
- * Override to option hash
165
- * @return array
166
- */
167
- public function toOptionHash()
168
- {
169
- $h = array();
170
-
171
- foreach ($this as $item) {
172
- $h[$item->getEntityId()] = $item->getName();
173
- }
174
-
175
- return $h;
176
- }
177
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/Model/Resource/Setup.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/code/community/Professio/BudgetMailer/controllers/Adminhtml/Budgetmailer/ContactController.php DELETED
@@ -1,510 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Implementation of backend-end contact controller (CRUD + mass actions)
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_Adminhtml_Budgetmailer_ContactController
25
- extends Professio_BudgetMailer_Controller_Adminhtml_BudgetMailer
26
- {
27
- /**
28
- * Intiate new contact and try to load it by requested id
29
- *
30
- * @return Professio_BudgetMailer_Model_Contact
31
- */
32
- protected function _initContact()
33
- {
34
- $contactId = (int) $this->getRequest()->getParam('id');
35
- $contact = Mage::getModel('budgetmailer/contact');
36
-
37
- if ($contactId) {
38
- $contact->load($contactId);
39
- }
40
-
41
- Mage::register('current_contact', $contact);
42
-
43
- return $contact;
44
- }
45
-
46
- /**
47
- * Check if current user can use this controller
48
- * @return bool
49
- */
50
- protected function _isAllowed()
51
- {
52
- return Mage::getSingleton('admin/session')
53
- ->isAllowed('budgetmailer/contact');
54
- }
55
-
56
- /**
57
- * Displays list of contacts
58
- *
59
- * @return null
60
- */
61
- public function indexAction()
62
- {
63
- $this->loadLayout();
64
-
65
- $this->_title(Mage::helper('budgetmailer')->__('BudgetMailer'))
66
- ->_title(Mage::helper('budgetmailer')->__('Contacts'));
67
-
68
- $this->renderLayout();
69
- }
70
-
71
- /**
72
- * Grid action
73
- *
74
- * @return null
75
- */
76
- public function gridAction()
77
- {
78
- $this->loadLayout()->renderLayout();
79
- }
80
-
81
- /**
82
- * Edit single contact, if doesn't exist redirect to index
83
- *
84
- * @return null
85
- */
86
- public function editAction()
87
- {
88
- $contactId = $this->getRequest()->getParam('id');
89
- $contact = $this->_initContact();
90
-
91
- if ($contactId && !$contact->getId()) {
92
- $this->_getSession()->addError(
93
- Mage::helper('budgetmailer')
94
- ->__('This contact no longer exists.')
95
- );
96
- $this->_redirect('*/*/');
97
-
98
- return;
99
- }
100
-
101
- $data = Mage::getSingleton('adminhtml/session')->getContactData(true);
102
-
103
- if (!empty($data)) {
104
- $contact->setData($data);
105
- }
106
-
107
- Mage::register('contact_data', $contact);
108
-
109
- $this->loadLayout();
110
- $this->_title(Mage::helper('budgetmailer')->__('BudgetMailer'))
111
- ->_title(Mage::helper('budgetmailer')->__('Contacts'));
112
-
113
- if ($contact->getId()) {
114
- $this->_title($contact->getEmail());
115
- } else {
116
- $this->_title(Mage::helper('budgetmailer')->__('Add contact'));
117
- }
118
-
119
- if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
120
- $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
121
- }
122
-
123
- $this->renderLayout();
124
- }
125
-
126
- /**
127
- * Create new contact (same as edit)
128
- */
129
- public function newAction()
130
- {
131
- $this->_forward('edit');
132
- }
133
-
134
- /**
135
- * Handle new/edit POST data and save the model
136
- *
137
- * @return null
138
- */
139
- public function saveAction()
140
- {
141
- if ($data = $this->getRequest()->getPost('contact')) {
142
- try {
143
- $data['tags'] = isset($data['tags']) && is_array($data['tags'])
144
- && count($data['tags']) ? $data['tags'] : array();
145
- $data['unsubscribed'] = !isset($data['subscribe']);
146
-
147
- $contact = $this->_initContact();
148
- $contact->addData($data);
149
- $contact->save();
150
- Mage::getSingleton('adminhtml/session')->addSuccess(
151
- Mage::helper('budgetmailer')->__(
152
- 'Contact was successfully saved'
153
- )
154
- );
155
- Mage::getSingleton('adminhtml/session')->setFormData(false);
156
-
157
- if ($this->getRequest()->getParam('back')) {
158
- $this->_redirect(
159
- '*/*/edit', array('id' => $contact->getId())
160
- );
161
-
162
- return;
163
- }
164
-
165
- $this->_redirect('*/*/');
166
-
167
- return;
168
- } catch (Mage_Core_Exception $e) {
169
- Mage::getSingleton('adminhtml/session')
170
- ->addError($e->getMessage());
171
- Mage::getSingleton('adminhtml/session')
172
- ->setContactData($data);
173
-
174
- $this->_redirect(
175
- '*/*/edit',
176
- array('id' => $this->getRequest()->getParam('id'))
177
- );
178
-
179
- return;
180
- } catch (Exception $e) {
181
- Mage::logException($e);
182
- Mage::getSingleton('adminhtml/session')
183
- ->addError(
184
- Mage::helper('budgetmailer')
185
- ->__('There was a problem saving the contact.')
186
- );
187
- Mage::getSingleton('adminhtml/session')->setContactData($data);
188
-
189
- $this->_redirect(
190
- '*/*/edit',
191
- array('id' => $this->getRequest()->getParam('id'))
192
- );
193
-
194
- return;
195
- }
196
- }
197
-
198
- Mage::getSingleton('adminhtml/session')
199
- ->addError(
200
- Mage::helper('budgetmailer')
201
- ->__('Unable to find contact to save.')
202
- );
203
-
204
- $this->_redirect('*/*/');
205
- }
206
-
207
- /**
208
- * Delete single contact
209
- *
210
- * @return null
211
- */
212
- public function deleteAction()
213
- {
214
- if ($this->getRequest()->getParam('id') > 0) {
215
- try {
216
- $contact = Mage::getModel('budgetmailer/contact');
217
- $contact->setId($this->getRequest()->getParam('id'))->delete();
218
-
219
- Mage::getSingleton('adminhtml/session')->addSuccess(
220
- Mage::helper('budgetmailer')
221
- ->__('Contact was successfully deleted.')
222
- );
223
-
224
- $this->_redirect('*/*/');
225
-
226
- return;
227
- } catch (Mage_Core_Exception $e) {
228
- Mage::getSingleton('adminhtml/session')->addError(
229
- $e->getMessage()
230
- );
231
- $this->_redirect(
232
- '*/*/edit',
233
- array('id' => $this->getRequest()->getParam('id'))
234
- );
235
- } catch (Exception $e) {
236
- Mage::getSingleton('adminhtml/session')
237
- ->addError(
238
- Mage::helper('budgetmailer')
239
- ->__('There was an error deleting contact.')
240
- );
241
- $this->_redirect(
242
- '*/*/edit',
243
- array('id' => $this->getRequest()->getParam('id'))
244
- );
245
- Mage::logException($e);
246
-
247
- return;
248
- }
249
- }
250
-
251
- Mage::getSingleton('adminhtml/session')->addError(
252
- Mage::helper('budgetmailer')
253
- ->__('Could not find contact to delete.')
254
- );
255
-
256
- $this->_redirect('*/*/');
257
- }
258
-
259
- /**
260
- * Delete multiple contacts as mass action
261
- */
262
- public function massDeleteAction()
263
- {
264
- $contactIds = $this->getRequest()->getParam('contact');
265
-
266
- if (!is_array($contactIds)) {
267
- Mage::getSingleton('adminhtml/session')
268
- ->addError(
269
- Mage::helper('budgetmailer')
270
- ->__('Please select contacts to delete.')
271
- );
272
- } else {
273
- try {
274
- $rs = array('total' => 0, 'fail' => 0, 'success' => 0);
275
- $contactIdsChunks = array_chunk(
276
- $contactIds, Professio_BudgetMailer_Model_Client::LIMIT
277
- );
278
-
279
- foreach($contactIdsChunks as $chunk) {
280
- $collection = Mage::getModel('budgetmailer/contact')
281
- ->getCollection();
282
- $collection->addFieldToFilter(
283
- 'entity_id', array('in' => $chunk)
284
- );
285
- $collection->load();
286
-
287
- $contacts = array();
288
- $map = array();
289
-
290
- foreach($collection->getIterator() as $contact) {
291
- $contactApi = new stdClass();
292
- $contactApi->email = $contact->getEmail();
293
-
294
- $contacts[] = $contactApi;
295
- $map[$contact->getEmail()] = $contact->getId();
296
- }
297
-
298
- list($total, $fail, $success, $contactsDeleted)
299
- = Mage::getSingleton('budgetmailer/client')->postContacts(
300
- $contacts, Professio_BudgetMailer_Model_Client::BULK_DELETE
301
- );
302
-
303
- $rs['total'] += $total;
304
- $rs['fail'] += $fail;
305
- $rs['success'] += $success;
306
-
307
- if (isset($contactsDeleted->Success) && is_array($contactsDeleted->Success)) {
308
- foreach($contactsDeleted->Success as $contactApi) {
309
- if (isset($map[$contactApi->email])) {
310
- $contact = Mage::getModel('budgetmailer/contact');
311
- $contact->setEmail($contactApi->email); // set email to avoid reload from API
312
- $contact->setId($map[$contactApi->email]);
313
- $contact->delete(false);
314
- }
315
- }
316
- }
317
- }
318
-
319
- Mage::getSingleton('adminhtml/session')
320
- ->addSuccess(
321
- sprintf(
322
- $this->__(
323
- 'Deleting contacts finished '
324
- . '(completed: %d, fail: %d, success: %d).'
325
- ),
326
- $rs['total'], $rs['fail'], $rs['success']
327
- )
328
- );
329
- } catch (Exception $e) {
330
- Mage::getSingleton('adminhtml/session')
331
- ->addError(
332
- Mage::helper('budgetmailer')
333
- ->__('There was an unexpected error deleting the contact(s).')
334
- );
335
-
336
- Mage::logException($e);
337
- }
338
- }
339
-
340
- $this->_redirect('*/*/index');
341
- }
342
-
343
- /**
344
- * Unsubscribe multiple contacts as mass action
345
- */
346
- public function massUnsubscribeAction()
347
- {
348
- $contactIds = $this->getRequest()->getParam('contact');
349
-
350
- if (!is_array($contactIds)) {
351
- Mage::getSingleton('adminhtml/session')
352
- ->addError(
353
- Mage::helper('budgetmailer')
354
- ->__('Please select contacts to unsubscribe.')
355
- );
356
- } else {
357
- try {
358
- $rs = array('total' => 0, 'fail' => 0, 'success' => 0);
359
- $contactIdsChunks = array_chunk(
360
- $contactIds, Professio_BudgetMailer_Model_Client::LIMIT
361
- );
362
-
363
- foreach($contactIdsChunks as $chunk) {
364
- $collection = Mage::getModel('budgetmailer/contact')
365
- ->getCollection();
366
- $collection->addFieldToFilter(
367
- 'entity_id', array('in' => $chunk)
368
- );
369
- $collection->load();
370
-
371
- $contacts = array();
372
- $map = array();
373
-
374
- foreach($collection->getIterator() as $contact) {
375
- $contactApi = new stdClass();
376
- $contactApi->email = $contact->getEmail();
377
-
378
- $contacts[] = $contactApi;
379
- $map[$contact->getEmail()] = $contact;
380
- }
381
-
382
- list($total, $fail, $success, $contactsDeleted)
383
- = Mage::getSingleton('budgetmailer/client')->postContacts(
384
- $contacts, Professio_BudgetMailer_Model_Client::BULK_UNSUB
385
- );
386
-
387
- $rs['total'] += $total;
388
- $rs['fail'] += $fail;
389
- $rs['success'] += $success;
390
-
391
- if (isset($contactsDeleted->Success) && is_array($contactsDeleted->Success)) {
392
- foreach($contactsDeleted->Success as $contactApi) {
393
- if (isset($map[$contactApi->email])) {
394
- $contact = $map[$contactApi->email];
395
- $contact->setUnsubscribed(true);
396
- $contact->save(false);
397
- }
398
- }
399
- }
400
- }
401
-
402
- Mage::getSingleton('adminhtml/session')
403
- ->addSuccess(
404
- sprintf(
405
- $this->__(
406
- 'Unsubscribing contacts finished '
407
- . '(completed: %d, fail: %d, success: %d).'
408
- ),
409
- $rs['total'], $rs['fail'], $rs['success']
410
- )
411
- );
412
- } catch (Exception $e) {
413
- Mage::getSingleton('adminhtml/session')
414
- ->addError(
415
- Mage::helper('budgetmailer')
416
- ->__('There was an unexpected error unsubscribing the contact(s).')
417
- );
418
-
419
- Mage::logException($e);
420
- }
421
- }
422
-
423
- $this->_redirect('*/*/index');
424
- }
425
-
426
- /**
427
- * Delete and unsubscribe multiple contacts as mass action
428
- */
429
- public function massDeleteUnsubscribeAction()
430
- {
431
-
432
- $contactIds = $this->getRequest()->getParam('contact');
433
-
434
- if (!is_array($contactIds)) {
435
- Mage::getSingleton('adminhtml/session')
436
- ->addError(
437
- Mage::helper('budgetmailer')
438
- ->__('Please select contacts to unsubscribe and delete.')
439
- );
440
- } else {
441
- try {
442
- $rs = array('total' => 0, 'fail' => 0, 'success' => 0);
443
- $contactIdsChunks = array_chunk(
444
- $contactIds, Professio_BudgetMailer_Model_Client::LIMIT
445
- );
446
-
447
- foreach($contactIdsChunks as $chunk) {
448
- $collection = Mage::getModel('budgetmailer/contact')
449
- ->getCollection();
450
- $collection->addFieldToFilter(
451
- 'entity_id', array('in' => $chunk)
452
- );
453
- $collection->load();
454
-
455
- $contacts = array();
456
- $map = array();
457
-
458
- foreach($collection->getIterator() as $contact) {
459
- $contactApi = new stdClass();
460
- $contactApi->email = $contact->getEmail();
461
-
462
- $contacts[] = $contactApi;
463
- $map[$contact->getEmail()] = $contact->getId();
464
- }
465
-
466
- list($total, $fail, $success, $contactsDeleted)
467
- = Mage::getSingleton('budgetmailer/client')->postContacts(
468
- $contacts, Professio_BudgetMailer_Model_Client::BULK_DELUNSUB
469
- );
470
-
471
- $rs['total'] += $total;
472
- $rs['fail'] += $fail;
473
- $rs['success'] += $success;
474
-
475
- if (isset($contactsDeleted->Success) && is_array($contactsDeleted->Success)) {
476
- foreach($contactsDeleted->Success as $contactApi) {
477
- if (isset($map[$contactApi->email])) {
478
- $contact = Mage::getModel('budgetmailer/contact');
479
- $contact->setEmail($contactApi->email); // set email to avoid reload from API
480
- $contact->setId($map[$contactApi->email]);
481
- $contact->delete(false);
482
- }
483
- }
484
- }
485
- }
486
-
487
- Mage::getSingleton('adminhtml/session')
488
- ->addSuccess(
489
- sprintf(
490
- $this->__(
491
- 'Unsubscribing and deleting contacts finished '
492
- . '(completed: %d, fail: %d, success: %d).'
493
- ),
494
- $rs['total'], $rs['fail'], $rs['success']
495
- )
496
- );
497
- } catch (Exception $e) {
498
- Mage::getSingleton('adminhtml/session')
499
- ->addError(
500
- Mage::helper('budgetmailer')
501
- ->__('There was an unexpected error unsubscribing and deleting the contact(s).')
502
- );
503
-
504
- Mage::logException($e);
505
- }
506
- }
507
-
508
- $this->_redirect('*/*/index');
509
- }
510
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/controllers/Adminhtml/BudgetmailerController.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -25,25 +25,15 @@ class Professio_BudgetMailer_Adminhtml_BudgetmailerController
25
  extends Mage_Adminhtml_Controller_Action
26
  {
27
  /**
28
- * Check the permission to run it
29
- *
30
  * @return boolean
31
  */
32
  protected function _isAllowed()
33
  {
34
  return Mage::getSingleton('admin/session')
35
- ->isAllowed('budgetmailer/manage');
36
  }
37
 
38
- /**
39
- * Get importer model
40
- * @return Professio_BudgetMailer_Model_Importer
41
- */
42
- protected function getImporter()
43
- {
44
- return Mage::getSingleton('budgetmailer/importer');
45
- }
46
-
47
  /**
48
  * Get exporter model
49
  * @return Professio_BudgetMailer_Model_Exporter
@@ -62,30 +52,14 @@ extends Mage_Adminhtml_Controller_Action
62
  return Mage::getSingleton('adminhtml/session');
63
  }
64
 
65
- /**
66
- * Delete orphans action
67
- */
68
- public function deleteorphansAction()
69
  {
70
- try {
71
- $rs = $this->getImporter()->deleteOrphans();
72
- $this->getSession()->addSuccess(
73
- sprintf(
74
- $this->__(
75
- 'Delete orphan contacts finished (completed: %d, '
76
- . 'deleted: %d, skipped: %d).'
77
- ),
78
- $rs['completed'], $rs['deleted'], $rs['skipped']
79
- )
80
- );
81
- } catch (Exception $e) {
82
- $this->getSession()->addError(
83
- $this->__('Deleting of orphan contacts failed.')
84
- );
85
- Mage::logException($e);
86
- }
87
 
88
- $this->_redirect('*/budgetmailer_contact/index');
 
 
 
89
  }
90
 
91
  /**
@@ -110,7 +84,7 @@ extends Mage_Adminhtml_Controller_Action
110
  Mage::logException($e);
111
  }
112
 
113
- $this->_redirect('*/budgetmailer_contact/index');
114
  }
115
 
116
  /**
@@ -132,11 +106,11 @@ extends Mage_Adminhtml_Controller_Action
132
  );
133
  } catch (Exception $e) {
134
  $this->getSession()
135
- ->addError($this->__('Newsletter export failed.'));
136
  Mage::logException($e);
137
  }
138
 
139
- $this->_redirect('*/budgetmailer_contact/index');
140
  }
141
 
142
  /**
@@ -162,193 +136,6 @@ extends Mage_Adminhtml_Controller_Action
162
  Mage::logException($e);
163
  }
164
 
165
- $this->_redirect('*/budgetmailer_contact/index');
166
- }
167
-
168
- /**
169
- * Import budgetmailer contacts action
170
- */
171
- public function importbudgetmailerAction()
172
- {
173
- try {
174
- $rs = $this->getImporter()->importContacts();
175
- $this->getSession()
176
- ->addSuccess(
177
- sprintf(
178
- $this->__(
179
- 'BudgetMailer contacts import finished (completed: '
180
- . '%d, failed: %d).'
181
- ),
182
- $rs['completed'], $rs['failed']
183
- )
184
- );
185
- } catch (Exception $e) {
186
- $this->getSession()
187
- ->addError($this->__('BudgetMailer contacts import failed.'));
188
- Mage::logException($e);
189
- }
190
-
191
- $this->_redirect('*/budgetmailer_contact/index');
192
- }
193
-
194
- /**
195
- * Mas subscribe customers or subscribers
196
- */
197
- public function masssubscribeAction()
198
- {
199
- try {
200
- if ($this->getRequest()->getParam('customer')) {
201
- $redirect = '*/customer/index';
202
- $rs = $this->getExporter()->massSubscribeCustomers(
203
- $this->getRequest()->getParam('customer'), true
204
- );
205
-
206
- $message = Mage::helper('budgetmailer')->__(
207
- sprintf(
208
- 'Subscribed %d customer(s) (fail: %d, success: %d).',
209
- $rs['total'], $rs['fail'], $rs['success']
210
- )
211
- );
212
- } elseif ($this->getRequest()->getParam('subscriber')) {
213
- $redirect = '*/newsletter_subscriber/index';
214
- $rs = $this->getExporter()->massSubscribeSubscribers(
215
- $this->getRequest()->getParam('subscriber'), true
216
- );
217
- $message = Mage::helper('budgetmailer')->__(
218
- sprintf(
219
- 'Subscribed %d subscriber(s) (fail: %d, success: %d).',
220
- $rs['total'], $rs['fail'], $rs['success']
221
- )
222
- );
223
- } else {
224
- $rs = false;
225
- $message = Mage::helper('adminhtml')
226
- ->__('Please select some item(s).');
227
- }
228
-
229
- if ($rs) {
230
- Mage::getSingleton('adminhtml/session')->addSuccess($message);
231
- } else {
232
- Mage::getSingleton('adminhtml/session')->addError($message);
233
- }
234
-
235
- if (isset($redirect)) {
236
- $this->_redirect($redirect);
237
- }
238
- } catch(Exception $e) {
239
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
240
- if (!isset($redirect)) {
241
- $redirect = '/';
242
- }
243
- $this->_redirect($redirect);
244
- }
245
- }
246
-
247
- /**
248
- * Mass unsubscribe customers or subscribers
249
- */
250
- public function massunsubscribeAction()
251
- {
252
- try {
253
- if ($this->getRequest()->getParam('customer')) {
254
- $redirect = '*/customer/index';
255
- $rs = $this->getExporter()->massSubscribeCustomers(
256
- $this->getRequest()->getParam('customer'), false
257
- );
258
-
259
- $message = Mage::helper('budgetmailer')->__(
260
- sprintf(
261
- 'Unsubscribed %d customer(s) (fail: %d, success: %d).',
262
- $rs['total'], $rs['fail'], $rs['success']
263
- )
264
- );
265
- } elseif ($this->getRequest()->getParam('subscriber')) {
266
- $redirect = '*/newsletter_subscriber/index';
267
- $rs = $this->getExporter()->massSubscribeSubscribers(
268
- $this->getRequest()->getParam('subscriber'), false
269
- );
270
- $message = Mage::helper('budgetmailer')->__(
271
- sprintf(
272
- 'Unsubscribed %d subscriber(s) '
273
- . '(fail: %d, success: %d).',
274
- $rs['total'], $rs['fail'], $rs['success']
275
- )
276
- );
277
- } else {
278
- $rs = false;
279
- $message = Mage::helper('adminhtml')
280
- ->__('Please select some item(s).');
281
- }
282
-
283
- if ($rs) {
284
- Mage::getSingleton('adminhtml/session')->addSuccess($message);
285
- } else {
286
- Mage::getSingleton('adminhtml/session')->addError($message);
287
- }
288
-
289
- if (isset($redirect)) {
290
- $this->_redirect($redirect);
291
- }
292
- } catch(Exception $e) {
293
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
294
- if (!isset($redirect)) {
295
- $redirect = '/';
296
- }
297
- $this->_redirect($redirect);
298
- }
299
- }
300
-
301
- /**
302
- * Mass delete customers or subscribers
303
- */
304
- public function massdeleteAction()
305
- {
306
- try {
307
- if ($this->getRequest()->getParam('customer')) {
308
- $redirect = '*/customer/index';
309
- $rs = $this->getExporter()->massDeleteCustomers(
310
- $this->getRequest()->getParam('customer'), false
311
- );
312
-
313
- $message = Mage::helper('budgetmailer')->__(
314
- sprintf(
315
- 'Deleted %d customer(s) (fail: %d, success: %d).',
316
- $rs['total'], $rs['fail'], $rs['success']
317
- )
318
- );
319
- } elseif ($this->getRequest()->getParam('subscriber')) {
320
- $redirect = '*/newsletter_subscriber/index';
321
- $rs = $this->getExporter()->massDeleteSubscribers(
322
- $this->getRequest()->getParam('subscriber'), false
323
- );
324
- $message = Mage::helper('budgetmailer')->__(
325
- sprintf(
326
- 'Deleted %d subscriber(s) '
327
- . '(fail: %d, success: %d).',
328
- $rs['total'], $rs['fail'], $rs['success']
329
- )
330
- );
331
- } else {
332
- $rs = false;
333
- $message = Mage::helper('adminhtml')
334
- ->__('Please select some item(s).');
335
- }
336
-
337
- if ($rs) {
338
- Mage::getSingleton('adminhtml/session')->addSuccess($message);
339
- } else {
340
- Mage::getSingleton('adminhtml/session')->addError($message);
341
- }
342
-
343
- if (isset($redirect)) {
344
- $this->_redirect($redirect);
345
- }
346
- } catch(Exception $e) {
347
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
348
- if (!isset($redirect)) {
349
- $redirect = '/';
350
- }
351
- $this->_redirect($redirect);
352
- }
353
  }
354
  }
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
25
  extends Mage_Adminhtml_Controller_Action
26
  {
27
  /**
28
+ * Check if current user is allowed to use this controller.
 
29
  * @return boolean
30
  */
31
  protected function _isAllowed()
32
  {
33
  return Mage::getSingleton('admin/session')
34
+ ->isAllowed('admin/system/convert/professio_budgetmailer');
35
  }
36
 
 
 
 
 
 
 
 
 
 
37
  /**
38
  * Get exporter model
39
  * @return Professio_BudgetMailer_Model_Exporter
52
  return Mage::getSingleton('adminhtml/session');
53
  }
54
 
55
+ public function indexAction()
 
 
 
56
  {
57
+ $this->loadLayout();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
+ $this->_title(Mage::helper('budgetmailer')->__('BudgetMailer'))
60
+ ->_title(Mage::helper('budgetmailer')->__('BudgetMailer'));
61
+
62
+ $this->renderLayout();
63
  }
64
 
65
  /**
84
  Mage::logException($e);
85
  }
86
 
87
+ $this->_redirect('*/budgetmailer/index');
88
  }
89
 
90
  /**
106
  );
107
  } catch (Exception $e) {
108
  $this->getSession()
109
+ ->addError($this->__('Subscribers export failed.'));
110
  Mage::logException($e);
111
  }
112
 
113
+ $this->_redirect('*/budgetmailer/index');
114
  }
115
 
116
  /**
136
  Mage::logException($e);
137
  }
138
 
139
+ $this->_redirect('*/budgetmailer/index');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
141
  }
app/code/community/Professio/BudgetMailer/controllers/ManageController.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -24,13 +24,6 @@
24
  class Professio_BudgetMailer_ManageController
25
  extends Mage_Core_Controller_Front_Action
26
  {
27
- /**
28
- * Current contact
29
- *
30
- * @var Professio_BudgetMailer_Model_Contact
31
- */
32
- protected $_contact;
33
-
34
  /**
35
  * Don't dispatch if there is no customer session
36
  */
@@ -43,21 +36,6 @@ extends Mage_Core_Controller_Front_Action
43
  }
44
  }
45
 
46
- /**
47
- * Get current contact
48
- *
49
- * @return Professio_BudgetMailer_Model_Contact
50
- */
51
- protected function getContact()
52
- {
53
- if (!isset($this->_contact)) {
54
- $this->_contact = Mage::getModel('budgetmailer/contact');
55
- $this->_contact->loadByCustomer($this->getCustomer());
56
- }
57
-
58
- return $this->_contact;
59
- }
60
-
61
  /**
62
  * Get current customer
63
  *
@@ -116,25 +94,28 @@ extends Mage_Core_Controller_Front_Action
116
  $subscribe = $this->getRequest()
117
  ->getParam('budgetmailer_subscribe', false);
118
 
119
- if (!$this->getContact()->getEntityId()) {
120
- Mage::helper('budgetmailer/mapper')->customerToModel(
121
- $this->getCustomer(), $this->getContact()
122
- );
123
-
124
- $address = Mage::helper('budgetmailer')
125
- ->getCustomersPrimaryAddress($this->getCustomer());
126
 
127
- if ($address && $address->getEntityId()) {
128
- Mage::helper('budgetmailer/mapper')->addressToModel(
129
- $address, $this->getContact()
130
- );
131
- }
 
132
  }
133
 
134
- $this->getContact()->setUnsubscribed(!$subscribe);
135
- $this->getContact()->setSubscribe($subscribe);
136
-
137
- $this->getContact()->save();
 
 
 
 
138
 
139
  $this->getCustomerSession()->addSuccess(
140
  $subscribe ?
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
24
  class Professio_BudgetMailer_ManageController
25
  extends Mage_Core_Controller_Front_Action
26
  {
 
 
 
 
 
 
 
27
  /**
28
  * Don't dispatch if there is no customer session
29
  */
36
  }
37
  }
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  /**
40
  * Get current customer
41
  *
94
  $subscribe = $this->getRequest()
95
  ->getParam('budgetmailer_subscribe', false);
96
 
97
+ $client = Mage::getSingleton('budgetmailer/client')->getClient();
98
+ $contact = $client->getContact($this->getCustomer()->getEmail());
99
+
100
+ if (!$contact) {
101
+ $contact = new stdClass();
 
 
102
 
103
+ Mage::helper('budgetmailer/mapper')->customerToContact(
104
+ $this->getCustomer(), $contact
105
+ );
106
+ $new = true;
107
+ } else {
108
+ $new = false;
109
  }
110
 
111
+ $contact->subscribe = $subscribe;
112
+ $contact->unsubscribed = !$subscribe;
113
+
114
+ if ($new) {
115
+ $client->postContact($contact);
116
+ } else {
117
+ $client->putContact($contact->email, $contact);
118
+ }
119
 
120
  $this->getCustomerSession()->addSuccess(
121
  $subscribe ?
app/code/community/Professio/BudgetMailer/controllers/SubscriberController.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -24,27 +24,6 @@
24
  class Professio_BudgetMailer_SubscriberController
25
  extends Mage_Core_Controller_Front_Action
26
  {
27
- /**
28
- * Current contact
29
- * @var Professio_BudgetMailer_Model_Contact
30
- */
31
- protected $_contact;
32
-
33
- /**
34
- * Get current contact
35
- *
36
- * @return Professio_BudgetMailer_Model_Contact
37
- */
38
- protected function getContact()
39
- {
40
- if (!isset($this->_contact)) {
41
- $this->_contact = Mage::getModel('budgetmailer/contact');
42
- // $this->contact->loadByEmail($this->getEmail());
43
- }
44
-
45
- return $this->_contact;
46
- }
47
-
48
  /**
49
  * Get current customer
50
  *
@@ -109,9 +88,8 @@ extends Mage_Core_Controller_Front_Action
109
  }
110
 
111
  /**
112
- * INFO this doesn't allow the have single customer with multiple emails
113
- *
114
  * Handle single subscription
 
115
  *
116
  * @return null
117
  */
@@ -119,45 +97,38 @@ extends Mage_Core_Controller_Front_Action
119
  {
120
  $this->log('budgetmailer/subscriber::subscribe() start');
121
 
122
- if ($this->getCustomer()->getId()) {
123
- $this->log('budgetmailer/subscriber::subscribe() customer');
124
-
125
- $this->getContact()->loadByCustomer($this->getCustomer());
126
-
127
- if (!$this->getContact()->getId()) {
128
- $this->log(
129
- 'budgetmailer/subscriber::subscribe() customer no contact'
130
- );
131
-
132
- $this->getContact()->setCustomerId(
133
- $this->getCustomer()->getId()
134
  );
135
-
136
- $this->getContact()->setEmail($this->getEmail());
137
  }
138
 
139
- $this->getMapper()->customerToModel(
140
- $this->getCustomer(), $this->getContact()
141
- );
142
  } else {
143
- $this->log('budgetmailer/subscriber::subscribe() no customer');
144
-
145
- $this->getContact()->loadByEmail($this->getEmail());
146
-
147
- if (!$this->getContact()->getId()) {
148
- $this->log(
149
- 'budgetmailer/subscriber::subscribe() no customer no '
150
- . 'contact'
151
- );
152
-
153
- $this->getContact()->setEmail($this->getEmail());
154
- }
155
  }
156
 
157
- $this->getContact()->setUnsubscribed(false);
158
- $this->getContact()->setSubscribe(true);
 
 
 
 
 
 
159
 
160
- $this->getContact()->save();
161
  }
162
 
163
  /**
@@ -167,14 +138,15 @@ extends Mage_Core_Controller_Front_Action
167
  */
168
  public function subscribeAction()
169
  {
170
- if ($this->getRequest()->isPost()
171
- && $this->getRequest()->getPost('email')) {
172
  try {
173
  $this->subscribe();
174
  $this->getSession()->addSuccess(
175
  $this->__('The subscription has been saved.')
176
  );
177
  } catch(Exception $e) {
 
 
178
  $this->getSession()->addError(
179
  $this->__(
180
  'An error occurred while saving your subscription.'
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
24
  class Professio_BudgetMailer_SubscriberController
25
  extends Mage_Core_Controller_Front_Action
26
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  /**
28
  * Get current customer
29
  *
88
  }
89
 
90
  /**
 
 
91
  * Handle single subscription
92
+ * INFO this doesn't allow to have single customer with multiple emails
93
  *
94
  * @return null
95
  */
97
  {
98
  $this->log('budgetmailer/subscriber::subscribe() start');
99
 
100
+ $client = Mage::getSingleton('budgetmailer/client')->getClient();
101
+ $email = $this->getEmail();
102
+ $subscribe = true;
103
+
104
+ $contact = $client->getContact($email);
105
+
106
+ if (!$contact) {
107
+ $contact = new stdClass();
108
+
109
+ if ($this->getCustomer() && $this->getCustomer()->getId()) {
110
+ Mage::helper('budgetmailer/mapper')->customerToContact(
111
+ $this->getCustomer(), $contact
112
  );
113
+ } else {
114
+ $contact->email = $email;
115
  }
116
 
117
+ $new = true;
 
 
118
  } else {
119
+ $new = false;
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
 
122
+ $contact->subscribe = $subscribe;
123
+ $contact->unsubscribed = !$subscribe;
124
+
125
+ if ($new) {
126
+ $client->postContact($contact);
127
+ } else {
128
+ $client->putContact($contact->email, $contact);
129
+ }
130
 
131
+ $this->log('budgetmailer/subscriber::subscribe() end');
132
  }
133
 
134
  /**
138
  */
139
  public function subscribeAction()
140
  {
141
+ if ($this->getRequest()->isPost() && $this->getEmail()) {
 
142
  try {
143
  $this->subscribe();
144
  $this->getSession()->addSuccess(
145
  $this->__('The subscription has been saved.')
146
  );
147
  } catch(Exception $e) {
148
+ Mage::logException($e);
149
+
150
  $this->getSession()->addError(
151
  $this->__(
152
  'An error occurred while saving your subscription.'
app/code/community/Professio/BudgetMailer/controllers/WebhookController.php DELETED
@@ -1,145 +0,0 @@
1
- <?php
2
- /**
3
- * Professio_BudgetMailer extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Professio
13
- * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
-
18
- /**
19
- * Implementation of BudgetMailer web hook
20
- *
21
- * @category Professio
22
- * @package Professio_BudgetMailer
23
- */
24
- class Professio_BudgetMailer_WebhookController
25
- extends Mage_Core_Controller_Front_Action
26
- {
27
- protected $_headers = array(
28
- 'APIKEY', 'SALT', 'SIGNATURE'
29
- );
30
-
31
- /**
32
- * Get HTTP headers
33
- * @return array
34
- */
35
- protected function getHeaders()
36
- {
37
- $headers = array();
38
-
39
- foreach ($this->_headers as $k) {
40
- $headers[$k] = $this->getRequest()->getHeader($k);
41
- }
42
-
43
- return $headers;
44
- }
45
-
46
- /**
47
- * Get budgetmailer helper
48
- * @return Professio_BudgetMailer_Helper_Data
49
- */
50
- protected function getHelper()
51
- {
52
- return Mage::helper('budgetmailer');
53
- }
54
-
55
- /**
56
- * Index action - listening for webhook calls.
57
- *
58
- * @return void
59
- */
60
- public function indexAction()
61
- {
62
- Mage::log(
63
- 'budgetmailer/webhook_controller::indexAction() start'
64
- );
65
-
66
- try {
67
- $body = $this->getRequest()->getRawBody();
68
- $actions = json_decode($body);
69
- $actions = is_object($actions) && isset($actions->data)
70
- && is_array($actions->data) && count($actions->data)
71
- ? $actions->data : array();
72
- $headers = $this->getHeaders();
73
-
74
- Mage::log(
75
- 'budgetmailer/webhook_controller::indexAction() '
76
- . 'body: ' . $body . ', actions: ' . json_encode($actions)
77
- . 'headers: ' . json_encode($headers)
78
- );
79
-
80
- list($code, $message) = $this->processHook($actions, $headers);
81
-
82
- $this->getResponse()->setHeader(
83
- $this->getRequest()->getServer('SERVER_PROTOCOL'),
84
- $code, true
85
- );
86
-
87
- $this->getResponse()->setBody($message);
88
-
89
- Mage::log(
90
- 'budgetmailer/webhook_controller::indexAction() message: '
91
- . $message . ', status: ' . $code
92
- );
93
- } catch (Exception $e) {
94
- Mage::logException($e);
95
-
96
- $this->getResponse()->setHeader(
97
- $this->getRequest()->getServer('SERVER_PROTOCOL'),
98
- 500, true
99
- );
100
-
101
- $this->getResponse()->setBody(
102
- Mage::helper('budgetmailer')
103
- ->__('Unexpected error:')
104
- . ' ' . $e->getMessage() . '.'
105
- );
106
-
107
- Mage::log(
108
- 'budgetmailer/webhook_controller::indexAction() exception: '
109
- . $e->getMessage()
110
- );
111
- }
112
-
113
- Mage::log(
114
- 'budgetmailer/webhook_controller::indexAction() end'
115
- );
116
- }
117
-
118
- protected function processHook($actions, $headers)
119
- {
120
- // INFO HTTPS CHECK
121
- if (false && !$this->getRequest()->isSecure()) {
122
- $code = 500;
123
- $message = $this->getHelper()
124
- ->__('This URL works only with HTTPS.');
125
- } else if (
126
- !Mage::helper('budgetmailer/config')->isSyncWebhookEnabled()) {
127
- $code = 503;
128
- $message = $this->getHelper()->__('Webhook disabled.');
129
- } else if (
130
- !$this->getHelper()->checkSignature($headers)) {
131
- $code = 403;
132
- $message = $this->getHelper()->__('Invalid signature.');
133
- } else if (!is_array($actions) || !count($actions)) {
134
- $code = 200;
135
- $message = $this->getHelper()->__('Nothing to do.');
136
- } else {
137
- $code = 200;
138
- $message = $this->getHelper()->__('OK');
139
- Mage::getSingleton('budgetmailer/importer')
140
- ->hook($actions, $headers);
141
- }
142
-
143
- return array($code, $message);
144
- }
145
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Professio/BudgetMailer/etc/adminhtml.xml CHANGED
@@ -6,14 +6,14 @@
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
- * that is bundled with this package in the file LICENSE.txt.
10
  * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/mit-license.php
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
- * @copyright Copyright (c) 2015
16
- * @license http://opensource.org/licenses/mit-license.php MIT License
17
  */
18
  -->
19
  <config>
@@ -30,47 +30,33 @@
30
  </budgetmailer>
31
  </children>
32
  </config>
 
 
 
 
 
 
 
33
  </children>
34
  </system>
35
-
36
- <professio_budgetmailer translate="title" module="budgetmailer">
37
- <title>BudgetMailer</title>
38
- <children>
39
- <contact translate="title" module="budgetmailer">
40
- <title>Contacts</title>
41
- <sort_order>0</sort_order>
42
- </contact>
43
- <!--<list translate="title" module="budgetmailer">
44
- <title>List</title>
45
- <sort_order>10</sort_order>
46
- </list>-->
47
- <massactions translate="title" module="budgetmailer">
48
- <title>Mass Actions</title>
49
- <sort_order>0</sort_order>
50
- </massactions>
51
- </children>
52
- </professio_budgetmailer>
53
  </children>
54
  </admin>
55
  </resources>
56
  </acl>
57
 
58
  <menu>
59
- <professio_budgetmailer translate="title" module="budgetmailer">
60
- <title>BudgetMailer</title>
61
- <sort_order>65</sort_order>
62
  <children>
63
- <contact translate="title" module="budgetmailer">
64
- <title>Contacts</title>
65
- <action>adminhtml/budgetmailer_contact</action>
66
- <sort_order>0</sort_order>
67
- </contact>
68
- <!--<list translate="title" module="budgetmailer">
69
- <title>List</title>
70
- <action>adminhtml/budgetmailer_list</action>
71
- <sort_order>10</sort_order>
72
- </list>-->
73
  </children>
74
- </professio_budgetmailer>
75
  </menu>
76
  </config>
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
+ * that is bundled with this package in the file LICENSE.
10
  * It is also available through the world-wide-web at this URL:
11
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
+ * @copyright Copyright (c) 2015 - 2017
16
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
17
  */
18
  -->
19
  <config>
30
  </budgetmailer>
31
  </children>
32
  </config>
33
+ <convert>
34
+ <children>
35
+ <professio_budgetmailer translate="title" module="budgetmailer">
36
+ <title>BudgetMailer</title>
37
+ </professio_budgetmailer>
38
+ </children>
39
+ </convert>
40
  </children>
41
  </system>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  </children>
43
  </admin>
44
  </resources>
45
  </acl>
46
 
47
  <menu>
48
+ <system>
 
 
49
  <children>
50
+ <convert>
51
+ <children>
52
+ <professio_budgetmailer translate="title" module="budgetmailer">
53
+ <title>BudgetMailer</title>
54
+ <action>adminhtml/budgetmailer</action>
55
+ <sort_order>90</sort_order>
56
+ </professio_budgetmailer>
57
+ </children>
58
+ </convert>
 
59
  </children>
60
+ </system>
61
  </menu>
62
  </config>
app/code/community/Professio/BudgetMailer/etc/config.xml CHANGED
@@ -6,14 +6,14 @@
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
- * that is bundled with this package in the file LICENSE.txt.
10
  * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/mit-license.php
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
- * @copyright Copyright (c) 2015
16
- * @license http://opensource.org/licenses/mit-license.php MIT License
17
  */
18
  -->
19
  <config>
@@ -44,11 +44,11 @@
44
 
45
  <customer_save_after>
46
  <observers>
47
- <budgetmailer_customer_customer_save_after>
48
  <class>budgetmailer/observer</class>
49
  <method>customerSaveAfterAdmin</method>
50
  <type>singleton</type>
51
- </budgetmailer_customer_customer_save_after>
52
  </observers>
53
  </customer_save_after>
54
  </events>
@@ -72,15 +72,6 @@
72
  </translate>
73
  </adminhtml>
74
 
75
- <crontab>
76
- <jobs>
77
- <budgetmailer_cron>
78
- <schedule><cron_expr>0 1 * * *</cron_expr></schedule>
79
- <run><model>budgetmailer/observer::cron</model></run>
80
- </budgetmailer_cron>
81
- </jobs>
82
- </crontab>
83
-
84
  <default>
85
  <budgetmailer>
86
  <api>
@@ -93,11 +84,10 @@
93
  <list></list>
94
  </general>
95
 
96
- <sync>
97
- <cron>1</cron>
98
- <webhook>1</webhook>
99
  <ttl>86400</ttl>
100
- </sync>
101
 
102
  <advanced>
103
  <address_type>billing</address_type>
@@ -115,11 +105,11 @@
115
  <events>
116
  <customer_save_after>
117
  <observers>
118
- <budgetmailer_customer_customer_save_after>
119
  <class>budgetmailer/observer</class>
120
  <method>customerSaveAfterFront</method>
121
  <type>singleton</type>
122
- </budgetmailer_customer_customer_save_after>
123
  </observers>
124
  </customer_save_after>
125
 
@@ -183,36 +173,36 @@
183
  <events>
184
  <customer_address_save_after>
185
  <observers>
186
- <budgetmailer_customer_customer_save_after>
187
  <class>budgetmailer/observer</class>
188
  <method>addressSaveAfter</method>
189
  <type>singleton</type>
190
- </budgetmailer_customer_customer_save_after>
191
  </observers>
192
  </customer_address_save_after>
193
 
194
  <customer_delete_after>
195
  <observers>
196
- <budgetmailer_customer_customer_delete_after>
197
  <class>budgetmailer/observer</class>
198
  <method>customerDeleteAfter</method>
199
  <type>singleton</type>
200
- </budgetmailer_customer_customer_delete_after>
201
  </observers>
202
  </customer_delete_after>
203
  </events>
204
 
205
  <models>
206
- <budgetmailer>
207
- <class>Professio_BudgetMailer_Model</class>
208
- <resourceModel>budgetmailer_resource</resourceModel>
209
- </budgetmailer>
210
  <budgetmailer>
211
  <class>Professio_BudgetMailer_Model</class>
212
  <resourceModel>budgetmailer_resource</resourceModel>
213
  </budgetmailer>
214
  <budgetmailer_resource>
215
  <class>Professio_BudgetMailer_Model_Resource</class>
 
 
 
 
216
  <entities>
217
  <contact>
218
  <table>budgetmailer_contact</table>
@@ -236,7 +226,7 @@
236
 
237
  <modules>
238
  <Professio_BudgetMailer>
239
- <version>1.0.1</version>
240
  </Professio_BudgetMailer>
241
  </modules>
242
 
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
+ * that is bundled with this package in the file LICENSE.
10
  * It is also available through the world-wide-web at this URL:
11
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
+ * @copyright Copyright (c) 2015 - 2017
16
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
17
  */
18
  -->
19
  <config>
44
 
45
  <customer_save_after>
46
  <observers>
47
+ <budgetmailer_customer_save_after>
48
  <class>budgetmailer/observer</class>
49
  <method>customerSaveAfterAdmin</method>
50
  <type>singleton</type>
51
+ </budgetmailer_customer_save_after>
52
  </observers>
53
  </customer_save_after>
54
  </events>
72
  </translate>
73
  </adminhtml>
74
 
 
 
 
 
 
 
 
 
 
75
  <default>
76
  <budgetmailer>
77
  <api>
84
  <list></list>
85
  </general>
86
 
87
+ <cache>
88
+ <enabled>1</enabled>
 
89
  <ttl>86400</ttl>
90
+ </cache>
91
 
92
  <advanced>
93
  <address_type>billing</address_type>
105
  <events>
106
  <customer_save_after>
107
  <observers>
108
+ <budgetmailer_customer_save_after>
109
  <class>budgetmailer/observer</class>
110
  <method>customerSaveAfterFront</method>
111
  <type>singleton</type>
112
+ </budgetmailer_customer_save_after>
113
  </observers>
114
  </customer_save_after>
115
 
173
  <events>
174
  <customer_address_save_after>
175
  <observers>
176
+ <budgetmailer_customer_address_save_after>
177
  <class>budgetmailer/observer</class>
178
  <method>addressSaveAfter</method>
179
  <type>singleton</type>
180
+ </budgetmailer_customer_address_save_after>
181
  </observers>
182
  </customer_address_save_after>
183
 
184
  <customer_delete_after>
185
  <observers>
186
+ <budgetmailer_customer_delete_after>
187
  <class>budgetmailer/observer</class>
188
  <method>customerDeleteAfter</method>
189
  <type>singleton</type>
190
+ </budgetmailer_customer_delete_after>
191
  </observers>
192
  </customer_delete_after>
193
  </events>
194
 
195
  <models>
 
 
 
 
196
  <budgetmailer>
197
  <class>Professio_BudgetMailer_Model</class>
198
  <resourceModel>budgetmailer_resource</resourceModel>
199
  </budgetmailer>
200
  <budgetmailer_resource>
201
  <class>Professio_BudgetMailer_Model_Resource</class>
202
+ <!--
203
+ XXX remove entities in one of next versions
204
+ 1.0.5 or rather 1.0.6 (need them in 1.0.4 for uninstall)
205
+ -->
206
  <entities>
207
  <contact>
208
  <table>budgetmailer_contact</table>
226
 
227
  <modules>
228
  <Professio_BudgetMailer>
229
+ <version>1.0.4</version>
230
  </Professio_BudgetMailer>
231
  </modules>
232
 
app/code/community/Professio/BudgetMailer/etc/system.xml CHANGED
@@ -6,14 +6,14 @@
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
- * that is bundled with this package in the file LICENSE.txt.
10
  * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/mit-license.php
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
- * @copyright Copyright (c) 2015
16
- * @license http://opensource.org/licenses/mit-license.php MIT License
17
  */
18
  -->
19
  <config>
@@ -63,7 +63,7 @@
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
- <comment>Insert your BudgetMailer API Secret. </comment>
67
  </secret>
68
  </fields>
69
  </api>
@@ -89,47 +89,36 @@
89
  </fields>
90
  </general>
91
 
92
- <sync translate="label" module="budgetmailer">
93
- <label>Synchronization</label>
94
  <frontend_type>text</frontend_type>
95
  <sort_order>30</sort_order>
96
  <show_in_default>1</show_in_default>
97
  <show_in_website>1</show_in_website>
98
  <show_in_store>1</show_in_store>
99
  <fields>
100
- <cron translate="label comment" module="budgetmailer">
101
- <label>Use Cron Job</label>
102
  <frontend_type>select</frontend_type>
103
  <source_model>adminhtml/system_config_source_yesno</source_model>
104
  <sort_order>10</sort_order>
105
  <show_in_default>1</show_in_default>
106
  <show_in_website>1</show_in_website>
107
  <show_in_store>1</show_in_store>
108
- <comment>In this mode, data will be synchronized periodically, every day at 1 a.m.</comment>
109
- </cron>
110
 
111
- <webhook translate="label comment" module="budgetmailer">
112
- <label>Use webhook</label>
113
- <frontend_type>select</frontend_type>
114
- <source_model>adminhtml/system_config_source_yesno</source_model>
115
- <sort_order>20</sort_order>
116
- <show_in_default>1</show_in_default>
117
- <show_in_website>1</show_in_website>
118
- <show_in_store>1</show_in_store>
119
- <comment>In this mode, BudgetMailer Contacts will be synchronized by webhook in a real time. However this requires having SSL certificate installed, and Magento configured to use HTTPS protocol.</comment>
120
- </webhook>
121
-
122
- <ttl>
123
- <label>Local data TTL</label>
124
  <frontend_type>text</frontend_type>
125
- <sort_order>30</sort_order>
126
  <show_in_default>1</show_in_default>
127
  <show_in_website>1</show_in_website>
128
  <show_in_store>1</show_in_store>
129
- <comment>Time to live of local contacts data, for both modes. Please do not change this value, unless you understand how this works.</comment>
130
  </ttl>
131
  </fields>
132
- </sync>
133
 
134
  <advanced translate="label" module="budgetmailer">
135
  <label>Advanced</label>
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
+ * that is bundled with this package in the file LICENSE.
10
  * It is also available through the world-wide-web at this URL:
11
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
+ * @copyright Copyright (c) 2015 - 2017
16
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
17
  */
18
  -->
19
  <config>
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
+ <comment>Insert your BudgetMailer API Secret.</comment>
67
  </secret>
68
  </fields>
69
  </api>
89
  </fields>
90
  </general>
91
 
92
+ <cache translate="label" module="budgetmailer">
93
+ <label>Cache</label>
94
  <frontend_type>text</frontend_type>
95
  <sort_order>30</sort_order>
96
  <show_in_default>1</show_in_default>
97
  <show_in_website>1</show_in_website>
98
  <show_in_store>1</show_in_store>
99
  <fields>
100
+ <enabled translate="label comment" module="budgetmailer">
101
+ <label>Cache</label>
102
  <frontend_type>select</frontend_type>
103
  <source_model>adminhtml/system_config_source_yesno</source_model>
104
  <sort_order>10</sort_order>
105
  <show_in_default>1</show_in_default>
106
  <show_in_website>1</show_in_website>
107
  <show_in_store>1</show_in_store>
108
+ <comment>Enable or disable BudgetMailer API client response caching (can save up to 50% of the requests).</comment>
109
+ </enabled>
110
 
111
+ <ttl translate="label comment" module="budgetmailer">
112
+ <label>Cache TTL</label>
 
 
 
 
 
 
 
 
 
 
 
113
  <frontend_type>text</frontend_type>
114
+ <sort_order>20</sort_order>
115
  <show_in_default>1</show_in_default>
116
  <show_in_website>1</show_in_website>
117
  <show_in_store>1</show_in_store>
118
+ <comment>Time to live of the cached results.</comment>
119
  </ttl>
120
  </fields>
121
+ </cache>
122
 
123
  <advanced translate="label" module="budgetmailer">
124
  <label>Advanced</label>
app/code/community/Professio/BudgetMailer/sql/budgetmailer_setup/install-1.0.0.php CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  if (Mage::getIsDeveloperMode()) {
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  if (Mage::getIsDeveloperMode()) {
app/code/community/Professio/BudgetMailer/sql/budgetmailer_setup/mysql4-upgrade-1.0.1-1.0.2.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Professio_BudgetMailer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
+ *
12
+ * @category Professio
13
+ * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
+ */
17
+
18
+ if (Mage::getIsDeveloperMode()) {
19
+ Mage::log('budgetmailer_setup started');
20
+ }
21
+
22
+ $this->startSetup();
23
+
24
+ $rsCont = $this->getConnection()->dropTable(
25
+ $this->getTable('budgetmailer/contact')
26
+ );
27
+ $rsList = $this->getConnection()->dropTable(
28
+ $this->getTable('budgetmailer/list')
29
+ );
30
+
31
+ if (Mage::getIsDeveloperMode()) {
32
+ Mage::log(
33
+ 'budgetmailer_setup $rsCont: ' . $rsCont . ', $rsList: ' . $rsList
34
+ );
35
+ }
36
+
37
+ $this->endSetup();
38
+
39
+ if (Mage::getIsDeveloperMode()) {
40
+ Mage::log('budgetmailer_setup ended');
41
+ }
app/code/community/Professio/BudgetMailer/sql/budgetmailer_setup_uninstall.sql CHANGED
@@ -4,18 +4,22 @@
4
  * NOTICE OF LICENSE
5
  *
6
  * This source file is subject to the MIT License
7
- * that is bundled with this package in the file LICENSE.txt.
8
  * It is also available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/mit-license.php
10
  *
11
  * @category Professio
12
  * @package Professio_BudgetMailer
13
- * @copyright Copyright (c) 2015
14
- * @license http://opensource.org/licenses/mit-license.php MIT License
15
  */
16
 
17
- DROP TABLE budgetmailer_contact;
18
- DROP TABLE budgetmailer_list;
 
 
 
 
19
 
20
  DELETE FROM core_config_data WHERE `path` LIKE 'budgetmailer%';
21
  DELETE FROM core_resource WHERE code = 'budgetmailer_setup';
4
  * NOTICE OF LICENSE
5
  *
6
  * This source file is subject to the MIT License
7
+ * that is bundled with this package in the file LICENSE.
8
  * It is also available through the world-wide-web at this URL:
9
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
10
  *
11
  * @category Professio
12
  * @package Professio_BudgetMailer
13
+ * @copyright Copyright (c) 2015 - 2017
14
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
15
  */
16
 
17
+ -- For versions 1.0.0 - 1.0.3:
18
+
19
+ -- DROP TABLE budgetmailer_contact;
20
+ -- DROP TABLE budgetmailer_list;
21
+
22
+ -- From 1.0.4:
23
 
24
  DELETE FROM core_config_data WHERE `path` LIKE 'budgetmailer%';
25
  DELETE FROM core_resource WHERE code = 'budgetmailer_setup';
app/design/adminhtml/default/default/layout/budgetmailer.xml CHANGED
@@ -6,92 +6,18 @@
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
- * that is bundled with this package in the file LICENSE.txt.
10
  * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/mit-license.php
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
- * @copyright Copyright (c) 2015
16
- * @license http://opensource.org/licenses/mit-license.php MIT License
17
  */
18
  -->
19
  <layout>
20
 
21
- <adminhtml_budgetmailer_contact_index>
22
- <reference name="menu">
23
- <action method="setActive">
24
- <menupath>professio_budgetmailer/contact</menupath>
25
- </action>
26
- </reference>
27
-
28
- <reference name="content">
29
- <block type="budgetmailer/adminhtml_contact" name="contact" />
30
- </reference>
31
- </adminhtml_budgetmailer_contact_index>
32
-
33
- <adminhtml_budgetmailer_contact_grid>
34
- <block type="core/text_list" name="root" output="toHtml">
35
- <block type="budgetmailer/adminhtml_contact_grid" name="contact_grid"/>
36
- </block>
37
- </adminhtml_budgetmailer_contact_grid>
38
-
39
- <!-- Contact add/edit action -->
40
- <adminhtml_budgetmailer_contact_edit>
41
- <update handle="editor"/>
42
-
43
- <reference name="menu">
44
- <action method="setActive">
45
- <menupath>professio_budgetmailer/contact</menupath>
46
- </action>
47
- </reference>
48
-
49
- <reference name="content">
50
- <block type="budgetmailer/adminhtml_contact_edit" name="contact_edit"></block>
51
- </reference>
52
-
53
- <reference name="left">
54
- <block type="budgetmailer/adminhtml_contact_edit_tabs" name="contact_tabs"></block>
55
- </reference>
56
- </adminhtml_budgetmailer_contact_edit>
57
-
58
- <adminhtml_budgetmailer_list_index>
59
- <reference name="menu">
60
- <action method="setActive">
61
- <menupath>professio_budgetmailer/list</menupath>
62
- </action>
63
- </reference>
64
-
65
- <reference name="content">
66
- <block type="budgetmailer/adminhtml_list" name="list" />
67
- </reference>
68
- </adminhtml_budgetmailer_list_index>
69
-
70
- <adminhtml_budgetmailer_list_grid>
71
- <block type="core/text_list" name="root" output="toHtml">
72
- <block type="budgetmailer/adminhtml_list_grid" name="list_grid"/>
73
- </block>
74
- </adminhtml_budgetmailer_list_grid>
75
-
76
- <!-- List add/edit action -->
77
- <adminhtml_budgetmailer_list_edit>
78
- <update handle="editor"/>
79
-
80
- <reference name="menu">
81
- <action method="setActive">
82
- <menupath>professio_budgetmailer/list</menupath>
83
- </action>
84
- </reference>
85
-
86
- <reference name="content">
87
- <block type="budgetmailer/adminhtml_list_edit" name="list_edit"></block>
88
- </reference>
89
-
90
- <reference name="left">
91
- <block type="budgetmailer/adminhtml_list_edit_tabs" name="list_tabs"></block>
92
- </reference>
93
- </adminhtml_budgetmailer_list_edit>
94
-
95
  <adminhtml_customer_edit>
96
  <reference name="customer_edit_tabs">
97
  <action method="addTab">
@@ -101,4 +27,10 @@
101
  </reference>
102
  </adminhtml_customer_edit>
103
 
 
 
 
 
 
 
104
  </layout>
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
+ * that is bundled with this package in the file LICENSE.
10
  * It is also available through the world-wide-web at this URL:
11
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
+ * @copyright Copyright (c) 2015 - 2017
16
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
17
  */
18
  -->
19
  <layout>
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  <adminhtml_customer_edit>
22
  <reference name="customer_edit_tabs">
23
  <action method="addTab">
27
  </reference>
28
  </adminhtml_customer_edit>
29
 
30
+ <adminhtml_budgetmailer_index>
31
+ <reference name="content">
32
+ <block type="budgetmailer/adminhtml_export" name="budgetmailer_export" template="budgetmailer/export.phtml" />
33
+ </reference>
34
+ </adminhtml_budgetmailer_index>
35
+
36
  </layout>
app/design/adminhtml/default/default/template/budgetmailer/customer/tab.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -22,4 +22,11 @@
22
  * @package Professio_BudgetMailer
23
  */
24
  ?>
25
- <?php echo $this->getChildHtml('budgetmailer_customer_tab_edit') ?>
 
 
 
 
 
 
 
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
22
  * @package Professio_BudgetMailer
23
  */
24
  ?>
25
+
26
+ <div class="entry-edit-head">
27
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Newsletter Subscription') ?></h4>
28
+ <div class="form-buttons"></div>
29
+ </div>
30
+ <div class="fieldset">
31
+ <label for="budgetmailer-subscribe"><?php echo $this->__('Subscribed to newsletter?') ?> <input id="budgetmailer-subscribe" name="budgetmailer_subscribe" value="1" type="checkbox"<?php echo $this->isSubscribed() ? ' checked="checked"' : null ?> /></label>
32
+ </div>
app/design/adminhtml/default/default/template/budgetmailer/export.phtml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Professio_BudgetMailer extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
+ *
12
+ * @category Professio
13
+ * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
+ */
17
+
18
+ /**
19
+ * Export page buttons
20
+ *
21
+ * @category Professio
22
+ * @package Professio_BudgetMailer
23
+ */
24
+ ?>
25
+ <div class="content-header">
26
+ <h3 class="icon-head head-adminhtml-import"><?php echo $this->__('BudgetMailer Export') ?></h3>
27
+ <p class="form-buttons">
28
+ <button id="bm_export_customers" title="<?php echo $this->__('Export Customers') ?>" type="button" class="scalable save" onclick="window.location = '<?php print Mage::helper('adminhtml')->getUrl('adminhtml/budgetmailer/exportcustomers') ?>'; return false;">
29
+ <span><span><span><?php echo $this->__('Export Customers') ?></span></span></span>
30
+ </button>
31
+ <button id="bm_export_customers_unreg" title="<?php echo $this->__('Export unregistered Customers') ?>" type="button" class="scalable save" onclick="window.location = '<?php print Mage::helper('adminhtml')->getUrl('adminhtml/budgetmailer/exportunregistered') ?>'; return false;">
32
+ <span><span><span><?php echo $this->__('Export unregistered Customers') ?></span></span></span>
33
+ </button>
34
+ <button id="bm_export_subscribers" title="<?php echo $this->__('Export Newsletter Subscribers') ?>" type="button" class="scalable save" onclick="window.location = '<?php print Mage::helper('adminhtml')->getUrl('adminhtml/budgetmailer/exportsubscribers') ?>'; return false;">
35
+ <span><span><span><?php echo $this->__('Export Newsletter Subscribers') ?></span></span></span>
36
+ </button>
37
+ </p>
38
+ </div>
app/design/frontend/base/default/layout/budgetmailer.xml CHANGED
@@ -6,14 +6,14 @@
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
- * that is bundled with this package in the file LICENSE.txt.
10
  * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/mit-license.php
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
- * @copyright Copyright (c) 2015
16
- * @license http://opensource.org/licenses/mit-license.php MIT License
17
  */
18
  -->
19
  <layout>
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
+ * that is bundled with this package in the file LICENSE.
10
  * It is also available through the world-wide-web at this URL:
11
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
+ * @copyright Copyright (c) 2015 - 2017
16
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
17
  */
18
  -->
19
  <layout>
app/design/frontend/base/default/template/budgetmailer/newsletter.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/design/frontend/base/default/template/budgetmailer/onepage-agreements.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/design/frontend/base/default/template/budgetmailer/subscribe.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -42,7 +42,7 @@ if (!$this->getConfigHelper()->isAdvancedFrontendEnabled()) {
42
  </div>
43
  <div class="input-box">
44
  <input type="text" name="email" id="newsletter"
45
- title="<?php echo $this->__('Sign up for our newsletter') ?>"
46
  class="input-text required-entry validate-email" />
47
  </div>
48
  <div class="actions">
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
42
  </div>
43
  <div class="input-box">
44
  <input type="text" name="email" id="newsletter"
45
+ title="<?php echo $this->__('Sign up for Our newsletter') ?>"
46
  class="input-text required-entry validate-email" />
47
  </div>
48
  <div class="actions">
app/design/frontend/base/default/template/budgetmailer/subscribe/mini.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -27,17 +27,15 @@ if (!$this->getConfigHelper()->isAdvancedFrontendEnabled()) {
27
  }
28
 
29
  $style = $this->isSignupHidden() ? ' style="display: none"' : null;
30
- $checked = $this->isSignupChecked() ? ' checked="checked"' : null;
31
  ?>
32
  <script type="text/javascript">
33
  var bm_li = '<li class="control"<?php print $style ?>>';
34
  bm_li += '<div class="input-box">';
35
- bm_li += '<input<?php print $checked ?> type="checkbox" name="bm_is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="bm_is_subscribed"<?php if($this->getFormData()->getBmIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" />';
36
  bm_li += '</div>';
37
  bm_li += '<label for="bm_is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>';
38
  bm_li += '</li>';
39
- // XXX add dynamically subscribe button here...
40
- //#form-validate .form-list ... append li.control etc
41
 
42
  var bm_list = $$('#form-validate .form-list')[0];
43
 
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
27
  }
28
 
29
  $style = $this->isSignupHidden() ? ' style="display: none"' : null;
30
+ $checked = $this->isSignupChecked() || $this->getFormData()->getBmIsSubscribed() ? ' checked="checked"' : null;
31
  ?>
32
  <script type="text/javascript">
33
  var bm_li = '<li class="control"<?php print $style ?>>';
34
  bm_li += '<div class="input-box">';
35
+ bm_li += '<input<?php print $checked ?> type="checkbox" name="bm_is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="bm_is_subscribed" class="checkbox" />';
36
  bm_li += '</div>';
37
  bm_li += '<label for="bm_is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>';
38
  bm_li += '</li>';
 
 
39
 
40
  var bm_list = $$('#form-validate .form-list')[0];
41
 
app/design/frontend/rwd/default/layout/budgetmailer.xml CHANGED
@@ -6,14 +6,14 @@
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
- * that is bundled with this package in the file LICENSE.txt.
10
  * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/mit-license.php
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
- * @copyright Copyright (c) 2015
16
- * @license http://opensource.org/licenses/mit-license.php MIT License
17
  */
18
  -->
19
  <layout>
6
  * NOTICE OF LICENSE
7
  *
8
  * This source file is subject to the MIT License
9
+ * that is bundled with this package in the file LICENSE.
10
  * It is also available through the world-wide-web at this URL:
11
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
12
  *
13
  * @category Professio
14
  * @package Professio_BudgetMailer
15
+ * @copyright Copyright (c) 2015 - 2017
16
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
17
  */
18
  -->
19
  <layout>
app/design/frontend/rwd/default/template/budgetmailer/newsletter.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/design/frontend/rwd/default/template/budgetmailer/onepage-agreements.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/design/frontend/rwd/default/template/budgetmailer/subscribe.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
app/design/frontend/rwd/default/template/budgetmailer/subscribe/mini.phtml CHANGED
@@ -5,14 +5,14 @@
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE.txt.
9
  * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
- * @copyright Copyright (c) 2015
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
  */
17
 
18
  /**
@@ -27,19 +27,17 @@ if (!$this->getConfigHelper()->isAdvancedFrontendEnabled()) {
27
  }
28
 
29
  $style = $this->isSignupHidden() ? ' style="display: none"' : null;
30
- $checked = $this->isSignupChecked() ? ' checked="checked"' : null;
31
  ?>
32
  <script type="text/javascript">
33
  var bm_li = '<li class="control"<?php print $style ?>>';
34
  bm_li += '<div class="input-box">';
35
- bm_li += '<input<?php print $checked ?> type="checkbox" name="bm_is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="bm_is_subscribed"<?php if($this->getFormData()->getBmIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" />';
36
  bm_li += '</div>';
37
  bm_li += '<label for="bm_is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>';
38
  bm_li += '</li>';
39
- // XXX add dynamically subscribe button here...
40
- //#form-validate .form-list ... append li.control etc
41
 
42
  var bm_list = $$('#form-validate .form-list')[0];
43
 
44
  $(bm_list).insert(bm_li);
45
- </script>
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE.
9
  * It is also available through the world-wide-web at this URL:
10
+ * https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
11
  *
12
  * @category Professio
13
  * @package Professio_BudgetMailer
14
+ * @copyright Copyright (c) 2015 - 2017
15
+ * @license https://gitlab.com/budgetmailer/budgetmailer-mag1/blob/master/LICENSE
16
  */
17
 
18
  /**
27
  }
28
 
29
  $style = $this->isSignupHidden() ? ' style="display: none"' : null;
30
+ $checked = $this->isSignupChecked() || $this->getFormData()->getBmIsSubscribed() ? ' checked="checked"' : null;
31
  ?>
32
  <script type="text/javascript">
33
  var bm_li = '<li class="control"<?php print $style ?>>';
34
  bm_li += '<div class="input-box">';
35
+ bm_li += '<input<?php print $checked ?> type="checkbox" name="bm_is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="bm_is_subscribed" class="checkbox" />';
36
  bm_li += '</div>';
37
  bm_li += '<label for="bm_is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>';
38
  bm_li += '</li>';
 
 
39
 
40
  var bm_list = $$('#form-validate .form-list')[0];
41
 
42
  $(bm_list).insert(bm_li);
43
+ </script>
app/etc/modules/Professio_BudgetMailer.xml CHANGED
@@ -4,7 +4,7 @@
4
  <Professio_BudgetMailer>
5
  <active>true</active>
6
  <codePool>community</codePool>
7
- <version>1.0.1</version>
8
  </Professio_BudgetMailer>
9
  </modules>
10
  </config>
4
  <Professio_BudgetMailer>
5
  <active>true</active>
6
  <codePool>community</codePool>
7
+ <version>1.0.4</version>
8
  </Professio_BudgetMailer>
9
  </modules>
10
  </config>
app/locale/en_US/Professio_BudgetMailer.csv CHANGED
@@ -1,113 +1,69 @@
1
- "Unexpected error:","Unexpected error:"
2
- "This URL works only with HTTPS.","This URL works only with HTTPS."
3
- "Webhook disabled.","Webhook disabled."
4
- "Invalid signature.","Invalid signature."
5
- "Nothing to do.","Nothing to do."
6
- OK,OK
7
- "The subscription has been saved.","The subscription has been saved."
8
  BudgetMailer,BudgetMailer
9
- Contacts,Contacts
10
- "This contact no longer exists.","This contact no longer exists."
11
- "Add contact","Add contact"
12
- "There was a problem saving the contact.","There was a problem saving the contact."
13
- "Unable to find contact to save.","Unable to find contact to save."
14
- "Contact was successfully deleted.","Contact was successfully deleted."
15
- "There was an error deleting contact.","There was an error deleting contact."
16
- "Could not find contact to delete.","Could not find contact to delete."
17
- "Please select contacts to delete.","Please select contacts to delete."
18
- "There was an unexpected error deleting the contact(s).","There was an unexpected error deleting the contact(s)."
19
- "Please select contacts to unsubscribe.","Please select contacts to unsubscribe."
20
- "There was an unexpected error unsubscribing the contact(s).","There was an unexpected error unsubscribing the contact(s)."
21
- "Please select contacts to unsubscribe and delete.","Please select contacts to unsubscribe and delete."
22
- "There was an unexpected error unsubscribing and deleting the contact(s).","There was an unexpected error unsubscribing and deleting the contact(s)."
23
- "Deleting of orphan contacts failed.","Deleting of orphan contacts failed."
24
- "Customers export failed.","Customers export failed."
25
- "Newsletter export failed.","Newsletter export failed."
26
- "Unregistered customers export failed.","Unregistered customers export failed."
27
- "BudgetMailer contacts import failed.","BudgetMailer contacts import failed."
28
- "Please select some item(s).","Please select some item(s)."
29
- "Newsletter Subscription","Newsletter Subscription"
30
- "The subscription has been removed.","The subscription has been removed."
31
- "Save List","Save List"
32
- "Delete List","Delete List"
33
- "Save And Continue Edit","Save And Continue Edit"
34
- "Add List","Add List"
35
- List,List
36
- "Budgetmailer ID","Budgetmailer ID"
37
- Name,Name
38
- Status,Status
39
- Enabled,Enabled
40
- Disabled,Disabled
41
- Id,Id
42
- "Created at","Created at"
43
- "Updated at","Updated at"
44
- Action,Action
45
- Edit,Edit
46
- Delete,Delete
47
- "Are you sure?","Are you sure?"
48
- "Change status","Change status"
49
- "Save Contact","Save Contact"
50
- "Delete Contact","Delete Contact"
51
- "Add Contact","Add Contact"
52
- Contact,Contact
53
- Subscribe,Subscribe
54
- "Delete from BudgetMailer","Delete from BudgetMailer"
55
- "Unsubscribe from BudgetMailer","Unsubscribe from BudgetMailer"
56
- "Delete and Unsubscribe from BudgetMailer","Delete and Unsubscribe from BudgetMailer"
57
  "BudgetMailer Newsletter","BudgetMailer Newsletter"
58
- "Delete Orphans","Delete Orphans"
59
- "Export Magento Customers","Export Magento Customers"
60
- "Export Magento Newsletter Subscribers","Export Magento Newsletter Subscribers"
61
- "Export unregistered Customers","Export unregistered Customers"
62
- "Import BudgetMailer Contacts","Import BudgetMailer Contacts"
63
- "Couldn't delete contact from BudgetMailer API.","Couldn't delete contact from BudgetMailer API."
64
- "Couldn't delete tag from contact from BudgetMailer API.","Couldn't delete tag from contact from BudgetMailer API."
65
- "Couldn't get the contact from BudgetMailer API.","Couldn't get the contact from BudgetMailer API."
66
- "Couldn't get contacts from BudgetMailer API.","Couldn't get contacts from BudgetMailer API."
67
- "Couldn't get the lists from BudgetMailer API.","Couldn't get the lists from BudgetMailer API."
68
- "Couldn't get tags from BudgetMailer API.","Couldn't get tags from BudgetMailer API."
69
- "Couldn't subscribe contact to BudgetMailer API.","Couldn't subscribe contact to BudgetMailer API."
70
- "Invalid bulk method.","Invalid bulk method."
71
- "Couldn't bulk process contacts in BudgetMailer API.","Couldn't bulk process contacts in BudgetMailer API."
72
- "Couldn't post tags to BudgetMailer API.","Couldn't post tags to BudgetMailer API."
73
- "Couldn't update contact in BudgetMailer API.","Couldn't update contact in BudgetMailer API."
74
- "Invalid API endpoint, key and secret combination.","Invalid API endpoint, key and secret combination."
75
- "Billing Address","Billing Address"
76
- "Shipping Address","Shipping Address"
77
- "Do nothing","Do nothing"
78
- "Use new primary address","Use new primary address"
79
  "Display checked checkbox","Display checked checkbox"
80
  "Display unchecked checkbox","Display unchecked checkbox"
81
  "Don't display checkbox, sign-up automatically","Don't display checkbox, sign-up automatically"
 
 
 
 
 
 
82
  "Select List","Select List"
83
  "Update Contact","Update Contact"
84
- Remove,Remove
85
- "Add Tag","Add Tag"
86
- "No Tags","No Tags"
87
- "BudgetMailer list is not set.","BudgetMailer list is not set."
88
- "Sign Up for Newsletter","Sign Up for Newsletter"
 
 
 
89
  "Newsletter Subscription","Newsletter Subscription"
 
 
 
90
  "Subscribed to newsletter?","Subscribed to newsletter?"
 
 
 
 
91
  Back,Back
92
  Save,Save
93
- Newsletter,Newsletter
94
  "Sign Up for Our Newsletter:","Sign Up for Our Newsletter:"
95
- "Sign up for our newsletter","Sign up for our newsletter"
96
  Subscribe,Subscribe
97
- "Email","Email"
98
- "First Name","First Name"
99
- "Insertion","Middle Name"
100
- "Last Name","Last Name"
101
- "Sex","Sex"
102
- "Male","Male",
103
- "Female","Female"
104
- "Address","Address"
105
- "Postal Code","Postal Code"
106
- "City","City"
107
- "Telephone","Telephone"
108
- "Mobile","Mobile"
109
- "Remarks","Notes"
110
- "Tags","Tags"
111
- "Company","Company"
112
- "Company Name","Company Name"
113
- "Country Code","Country Code"
 
 
 
 
 
 
 
1
  BudgetMailer,BudgetMailer
2
+ API,API
3
+ "API Endpoint","API Endpoint"
4
+ "BudgetMailer API Endpoint. Please don't change the URL unless you are instructed to.","BudgetMailer API Endpoint. Please don't change the URL unless you are instructed to."
5
+ "API Key","API Key"
6
+ "Insert your BudgetMailer API Key.","Insert your BudgetMailer API Key."
7
+ "API Secret","API Secret"
8
+ "Insert your BudgetMailer API Secret.","Insert your BudgetMailer API Secret."
9
+ General,General
10
+ "Please select the BudgetMailer List you want to use with Magento.","Please select the BudgetMailer List you want to use with Magento."
11
+ Cache,Cache
12
+ "Enable or disable BudgetMailer API client response caching (can save up to 50% of the requests).","Enable or disable BudgetMailer API client response caching (can save up to 50% of the requests)."
13
+ "Cache TTL","Cache TTL"
14
+ "Time to live of the cached results.","Time to live of the cached results."
15
+ Advanced,Advanced
16
+ "Enable front-end output","Enable front-end output"
17
+ "If disabled, this module, won't have any front-end output.","If disabled, this module, won't have any front-end output."
18
+ "Use Address","Use Address"
19
+ "Select address that will be synchronized.","Select address that will be synchronized."
20
+ "On Primary Address Update","On Primary Address Update"
21
+ "Select address update behaviour.","Select address update behaviour."
22
+ "On Customer Delete","On Customer Delete"
23
+ "Select customer delete behaviour.","Select customer delete behaviour."
24
+ "On Customer Update","On Customer Update"
25
+ "Select customer update behaviour.","Select customer update behaviour."
26
+ "Tag Customers after Order","Tag Customers after Order"
27
+ "If enabled, contact will be tagged by category names of ordered products.","If enabled, contact will be tagged by category names of ordered products."
28
+ "Create an Account Behaviour","Create an Account Behaviour"
29
+ "Select how the newsletter sign-up should look and behave, when creating new account.","Select how the newsletter sign-up should look and behave, when creating new account."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  "BudgetMailer Newsletter","BudgetMailer Newsletter"
31
+ "Click here to view Budgetmailer subscription and contact information for this customer.","Click here to view Budgetmailer subscription and contact information for this customer."
32
+ Remove,Remove
33
+ "Add Tag","Add Tag"
34
+ "No Tags","No Tags"
35
+ "BudgetMailer list is not set.","BudgetMailer list is not set."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  "Display checked checkbox","Display checked checkbox"
37
  "Display unchecked checkbox","Display unchecked checkbox"
38
  "Don't display checkbox, sign-up automatically","Don't display checkbox, sign-up automatically"
39
+ "Billing Address","Billing Address"
40
+ "Shipping Address","Shipping Address"
41
+ "Use new primary address","Use new primary address"
42
+ "Do nothing","Do nothing"
43
+ "Delete Contact","Delete Contact"
44
+ "Delete and unsubscribe Contact","Delete and unsubscribe Contact"
45
  "Select List","Select List"
46
  "Update Contact","Update Contact"
47
+ "Invalid API endpoint, key and secret combination.","Invalid API endpoint, key and secret combination."
48
+ "API endpoint, key and secret combination is valid.","API endpoint, key and secret combination is valid."
49
+ "Customers export finished (completed: %d, fail: %d, success: %d).","Customers export finished (completed: %d, fail: %d, success: %d)."
50
+ "Customers export failed.","Customers export failed."
51
+ "Newsletter Subscribers export finished (completed: %d, fail: %d, success: %d).","Newsletter Subscribers export finished (completed: %d, fail: %d, success: %d)."
52
+ "Subscribers export failed.","Subscribers export failed."
53
+ "Unregistered customers export finished (completed: %d, fail: %d, success: %d).","Unregistered customers export finished (completed: %d, fail: %d, success: %d)."
54
+ "Unregistered customers export failed.","Unregistered customers export failed."
55
  "Newsletter Subscription","Newsletter Subscription"
56
+ "The subscription has been saved.","The subscription has been saved."
57
+ "The subscription has been removed.","The subscription has been removed."
58
+ "An error occurred while saving your subscription.","An error occurred while saving your subscription."
59
  "Subscribed to newsletter?","Subscribed to newsletter?"
60
+ "BudgetMailer Export","BudgetMailer Export"
61
+ "Export Customers","Export Customers"
62
+ "Export unregistered Customers","Export unregistered Customers"
63
+ "Export Newsletter Subscribers","Export Newsletter Subscribers"
64
  Back,Back
65
  Save,Save
66
+ "Sign Up for Newsletter","Sign Up for Newsletter"
67
  "Sign Up for Our Newsletter:","Sign Up for Our Newsletter:"
68
+ Newsletter,Newsletter
69
  Subscribe,Subscribe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/locale/nl_NL/Professio_BudgetMailer.csv CHANGED
@@ -1,111 +1,69 @@
1
- "Unexpected error:","Onverwachte fout:"
2
- "This URL works only with HTTPS.","Deze URL werkt alleen met HTTPS."
3
- "Webhook disabled.","Webhook uitgeschakeld."
4
- "Invalid signature.","Ongeldige handtekening."
5
- "Nothing to do.","Niks te doen."
6
- OK,OK
7
- "The subscription has been saved.","De aanmelding is opgeslagen."
8
- BudgetMailer,BudgetMailer
9
- Contacts,Contacten
10
- "This contact no longer exists.","Dit contact bestaat niet meer."
11
- "Add contact","Contact toevoegen"
12
- "There was a problem saving the contact.","Er was een probleem bij het opslaan van dit contact."
13
- "Unable to find contact to save.","Kan contact niet vinden om op te slaan."
14
- "Contact was successfully deleted.","Contact succesvol verwijderd."
15
- "There was an error deleting contact.","Er ging iets fout bij het verwijderen van het contact."
16
- "Could not find contact to delete.","Kan contact niet vinden om te verwijderen."
17
- "Please select contacts to delete.","Selecteer contacten om te verwijderen."
18
- "There was an unexpected error deleting the contact(s).","Contact(en) verwijderen mislukt. Er is iets onverwachts fout gegaan."
19
- "Please select contacts to unsubscribe.","Selecteer contact(en) om af te melden."
20
- "There was an unexpected error unsubscribing the contact(s).","Contact(en) afmelden en verwijderen mislukt. Er is iets onverwachts fout gegaan."
21
- "Please select contacts to unsubscribe and delete.","Selecteer contact(en) om af te melden en te verwijderen."
22
- "There was an unexpected error unsubscribing and deleting the contact(s).","Contact(en) afmelden en verwijderen mislukt. Er is iets onverwachts fout gegaan."
23
- "Deleting of orphan contacts failed.","Verwijderen van wezen contacten mislukt."
24
- "Customers export failed.","Exporteren contacten mislukt."
25
- "Newsletter export failed.","Exporteren nieuwsbrief aanmeldingen mislukt."
26
- "Unregistered customers export failed.","Exporteren ongeregistreerde klanten mislukt."
27
- "BudgetMailer contacts import failed.","importeren BudgetMailer contacten mislukt."
28
- "Please select some item(s).","Selecteer item(s)."
29
- "Newsletter Subscription","Nieuwsbrief aanmeldingen"
30
- "The subscription has been removed.","De aanmelding is verwijderd."
31
- "Save List","Lijst opslaan"
32
- "Delete List","Verwijdern lijst"
33
- "Save And Continue Edit","Opslaan en verder bewerken"
34
- "Add List","Lijst toevoegen"
35
- List,Lijst
36
- "Budgetmailer ID","BudgetMailer ID"
37
- Name,Naam
38
- Status,Status
39
- Enabled,Ingeschakeld
40
- Disabled,Uitgeschakeld
41
- Id,Id
42
- "Created at","Aangemaakt op"
43
- "Updated at","Gewijzigd op"
44
- Action,Actie
45
- Edit,Bewerk
46
- Delete,Verwijderen
47
- "Are you sure?","Weet je het zeker?"
48
- "Change status","Wijzig status"
49
- "Save Contact","Contact opslaan"
50
- "Delete Contact","Verwijder contact"
51
- "Add Contact","Contact toevoegen"
52
- Contact,Contact
53
- Subscribe,Aanmelden
54
- "Delete from BudgetMailer","Verwijderen in BudgetMailer"
55
- "Unsubscribe from BudgetMailer","Afmelden in BudgetMailer"
56
- "Delete and Unsubscribe from BudgetMailer","Afmelden en verwijderen in BudgetMailer"
57
- "BudgetMailer Newsletter","BudgetMailer Nieuwsbrief"
58
- "Delete Orphans","Verwijder wezen"
59
- "Export Magento Customers","Exporteer Magento klanten"
60
- "Export Magento Newsletter Subscribers","Exporteer Magento nieuwsbrief aanmeldingen"
61
- "Export unregistered Customers","Exporteer ongeregistreerde klanten"
62
- "Import BudgetMailer Contacts","Importeer BudgetMailer contacten"
63
- "Couldn't delete contact from BudgetMailer API.","Kan contact niet verwijderen met BudgetMailer API."
64
- "Couldn't delete tag from contact from BudgetMailer API.","Kan tag van contact niet verwijderen met BudgetMailer API."
65
- "Couldn't get the contact from BudgetMailer API.","Kan contact niet ophalen met BudgetMailer API."
66
- "Couldn't get contacts from BudgetMailer API.","Kan contacten niet ophalen met BudgetMailer API."
67
- "Couldn't get the lists from BudgetMailer API.","Kan lijsten niet ophalen met BudgetMailer API."
68
- "Couldn't get tags from BudgetMailer API.","Kan tags niet ophalen met BudgetMailer API."
69
- "Couldn't subscribe contact to BudgetMailer API.","Kan contact niet aanmelden met BudgetMailer API."
70
- "Invalid bulk method.","Ongeldige bulk-methode."
71
- "Couldn't bulk process contacts in BudgetMailer API.","Kan bulk verwerken contacten met de BudgetMailer API niet uitvoeren"
72
- "Couldn't post tags to BudgetMailer API.","Kan tags niet posten met BudgetMailer API."
73
- "Couldn't update contact in BudgetMailer API.","Kan contact niet wijzigen met BudgetMailer API."
74
- "Invalid API endpoint, key and secret combination.","Ongeldige API endpoint, sleutel en geheime combinatie."
75
- "Billing Address",Facturatieadres
76
- "Shipping Address",Verzendingsadres
77
- "Do nothing","Niks doen"
78
- "Use new primary address","Nieuw hoofdadres gebruiken"
79
- "Display checked checkbox","Geef aangevinkte selectievak weer"
80
- "Display unchecked checkbox","Geef lege selectievak weer"
81
- "Don't display checkbox, sign-up automatically","Geef selectievak niet weer, maar meldt automatisch aan"
82
- "Select List","Selecteer lijst"
83
- "Update Contact","Contact bijwerken"
84
- Remove,Verwijder
85
- "Add Tag","Tag toevoegen"
86
- "No Tags","Geen tags"
87
- "BudgetMailer list is not set.","BudgetMailer lijst niet aangegeven."
88
- "Sign Up for Newsletter","Meld je aan voor nieuwsbrief"
89
- "Subscribed to newsletter?","Aanmelden voor nieuwsbrief?"
90
- Back,Terug
91
- Save,Opslaan
92
- Newsletter,Nieuwsbrief
93
- "Sign Up for Our Newsletter:","Meld je aan voor onze nieuwsbrief:"
94
- "Sign up for our newsletter","Meld je aan voor onze nieuwsbrief"
95
- "Email","E-mailadres"
96
- "First Name","Voornaam"
97
- "Insertion","Tussenvoegsel"
98
- "Last Name","Achternaam"
99
- "Sex","Geslacht"
100
- "Male","Man",
101
- "Female","Vrouw"
102
- "Address","Adres"
103
- "Postal Code","Postcode"
104
- "City","Plaats"
105
- "Telephone","Telefoon"
106
- "Mobile","Mobiel"
107
- "Remarks","Opmerkingen"
108
- "Tags","Tags"
109
- "Company","Bedrijfsnaam"
110
- "Company Name","Bedrijfsnaam"
111
- "Country Code","Landcode"
1
+ BudgetMailer,BudgetMailer
2
+ API,API
3
+ "API Endpoint",API-eindpunt
4
+ "BudgetMailer API Endpoint. Please don't change the URL unless you are instructed to.","BudgetMailer API-eindpunt. Verander deze URL niet tenzij je hier voor gevraagd wordt."
5
+ "API Key",API-sleutel
6
+ "Insert your BudgetMailer API Key.","Voer hier je BudgetMailer API-sleutel in."
7
+ "API Secret","Geheime sleutel"
8
+ "Insert your BudgetMailer API Secret.","Voer hier je geheime sleutel in."
9
+ General,Algemeen
10
+ "Please select the BudgetMailer List you want to use with Magento.","Selecteer de BudgetMailer lijst die je voor Magento wilt gebruiken."
11
+ Cache,Cache
12
+ "Enable or disable BudgetMailer API client response caching (can save up to 50% of the requests).","Schakel BudgetMailer API client response caching in of uit (kan tot 50% van requests besparen)."
13
+ "Cache TTL","Cache TTL"
14
+ "Time to live of the cached results.","Time to live van van gecachte resultaten."
15
+ Advanced,Geavanceerd
16
+ "Enable front-end output","Front-end output inschakelen"
17
+ "If disabled, this module, won't have any front-end output.","Als je dit uitschakelt, dan is er geen fornt-end output"
18
+ "Use Address","Gebruik adres"
19
+ "Select address that will be synchronized.","Gebruik adres dat gesynchroniseerd wordt."
20
+ "On Primary Address Update","Bij wijzigen primaire adres"
21
+ "Select address update behaviour.","Selecteer actie bij wijzigen adres"
22
+ "On Customer Delete","Bij verwijderen klant"
23
+ "Select customer delete behaviour.","Selecteer actie bij verwijderen klant"
24
+ "On Customer Update","Bij wijzigen klant"
25
+ "Select customer update behaviour.","Selecteer actie bij wijzigen klant."
26
+ "Tag Customers after Order","Klant taggen na bestelling"
27
+ "If enabled, contact will be tagged by category names of ordered products.","Als je dit inschakelt, dan worden de categorienamen van de bestelde producten als tag meegestuurd."
28
+ "Create an Account Behaviour","Bij registratie nieuwe account"
29
+ "Select how the newsletter sign-up should look and behave, when creating new account.","Geef hier aan hoe nieuwe registraties zich voor je nieuwsbrief aan kunnen melden"
30
+ "BudgetMailer Newsletter","BudgetMailer Nieuwsbrief"
31
+ "Click here to view Budgetmailer subscription and contact information for this customer.","Klik hier om BudgetMailer "
32
+ Remove,Verwijder
33
+ "Add Tag","Tag toevoegen"
34
+ "No Tags","Geen tags"
35
+ "BudgetMailer list is not set.","BudgetMailer lijst niet aangegeven."
36
+ "Display checked checkbox","Geef aangevinkte selectievak weer"
37
+ "Display unchecked checkbox","Geef lege selectievak weer"
38
+ "Don't display checkbox, sign-up automatically","Geef selectievak niet weer, maar meldt automatisch aan"
39
+ "Billing Address",Facturatieadres
40
+ "Shipping Address",Verzendingsadres
41
+ "Use new primary address","Nieuw hoofdadres gebruiken"
42
+ "Do nothing","Niks doen"
43
+ "Delete Contact","Verwijder contact"
44
+ "Delete and unsubscribe Contact","Verwijder en meld contact af"
45
+ "Select List","Selecteer lijst"
46
+ "Update Contact","Contact bijwerken"
47
+ "Invalid API endpoint, key and secret combination.","Ongeldige API endpoint, sleutel en geheime combinatie."
48
+ "API endpoint, key and secret combination is valid.","API-eindpunt, sleutel en geheime sleutel combinatie is geldig."
49
+ "Customers export finished (completed: %d, fail: %d, success: %d).","Exporteren klanten voltooid (totaal: %d, mislukt %d, success: %d)."
50
+ "Customers export failed.","Exporteren contacten mislukt."
51
+ "Newsletter Subscribers export finished (completed: %d, fail: %d, success: %d).","Exporteren nieuwsbrief aanmeldingen voltooid (totaal: %d, mislukt %d, success: %d)."
52
+ "Subscribers export failed.","Exporteren nieuwsbrief aanmeldingen mislukt."
53
+ "Unregistered customers export finished (completed: %d, fail: %d, success: %d).","Exporteren ongeregistreerde klanten voltooid (totaal: %d, mislukt %d, success: %d)."
54
+ "Unregistered customers export failed.","Exporteren ongeregistreerde klanten mislukt."
55
+ "Newsletter Subscription","Nieuwsbrief aanmeldingen"
56
+ "The subscription has been saved.","De aanmelding is opgeslagen."
57
+ "The subscription has been removed.","De aanmelding is verwijderd."
58
+ "An error occurred while saving your subscription.","Er is iets fout gegaan bij het opslaan van je nieuwsbrief aanmelding."
59
+ "Subscribed to newsletter?","Aanmelden voor nieuwsbrief?"
60
+ "BudgetMailer Export","BudgetMailer Export"
61
+ "Export Customers","Exporteer klanten"
62
+ "Export unregistered Customers","Exporteer ongeregistreerde klanten"
63
+ "Export Newsletter Subscribers","Exporteer nieuwsbrief aanmeldingen"
64
+ Back,Terug
65
+ Save,Opslaan
66
+ "Sign Up for Newsletter","Meld je aan voor nieuwsbrief"
67
+ "Sign Up for Our Newsletter:","Meld je aan voor onze nieuwsbrief:"
68
+ Newsletter,Nieuwsbrief
69
+ Subscribe,Aanmelden
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/BudgetMailer/Api/Cache.php ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BudgetMailer PHP API (https://www.budgetmailer.nl/index.php)
5
+ *
6
+ * @author BudgetMailer <info@budgetmailer.nl>
7
+ * @copyright (c) 2015 - 2017 - BudgetMailer
8
+ * @license https://gitlab.com/budgetmailer/budgetmailer-php-api/blob/master/LICENSE.txt
9
+ * @package BudgetMailer\API\Client
10
+ * @version 1.0.2
11
+ */
12
+
13
+ /**
14
+ * Namespace
15
+ *
16
+ * @package BudgetMailer\Api
17
+ */
18
+ namespace BudgetMailer\Api;
19
+
20
+ /**
21
+ * Cache for BudgetMailer API Client
22
+ *
23
+ * @package BudgetMailer\Api
24
+ */
25
+ class Cache
26
+ {
27
+ const HTACCESS = '.htacess';
28
+ const HTACCESS_CONTENT = 'Deny from all';
29
+ const SUFFIX = '.cache';
30
+
31
+ /**
32
+ * @var string Cache Directory (Must be writeable)
33
+ */
34
+ protected $dir;
35
+ /**
36
+ * @var boolean Enabled Flag
37
+ */
38
+ protected $enabled;
39
+ /**
40
+ * @var integer Time to live for cached Data
41
+ */
42
+ protected $ttl;
43
+
44
+ /**
45
+ * Create new Instance of Cache
46
+ *
47
+ * @param Config $config Configuration
48
+ */
49
+ public function __construct(Config $config)
50
+ {
51
+ $this->setEnabled($config->getCache());
52
+ $this->setDir($config->getCacheDir());
53
+ $this->setTtl($config->getTtl());
54
+ }
55
+
56
+ /**
57
+ * Get Enabled Flag
58
+ *
59
+ * @return boolean
60
+ */
61
+ public function isEnabled()
62
+ {
63
+ return $this->enabled;
64
+ }
65
+
66
+ /**
67
+ * Set Cache Directory
68
+ *
69
+ * @param boolean $enabled Cache Directory (Must be writeable)
70
+ * @return \BudgetMailer\Api\Cache self
71
+ */
72
+ public function setEnabled($enabled)
73
+ {
74
+ $this->enabled = $enabled;
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * Get Cache Directory (Absolute Path)
80
+ *
81
+ * @return string
82
+ */
83
+ public function getDir()
84
+ {
85
+ return $this->dir;
86
+ }
87
+
88
+ /**
89
+ * Set Cache Directory
90
+ *
91
+ * @param string $dir Cache Directory (Must be writeable)
92
+ * @return \BudgetMailer\Api\Cache self
93
+ * @throws \InvalidArgumentException In Case the Directory is not writeable, or .htaccess File can't be created
94
+ */
95
+ public function setDir($dir)
96
+ {
97
+ if (( !is_dir($dir) && !mkdir($dir) ) || !is_writable($dir)) {
98
+ throw new \InvalidArgumentException('Cache directory is not writeable.');
99
+ }
100
+
101
+ $this->checkHtaccess($dir);
102
+ $this->dir = $dir;
103
+
104
+ return $this;
105
+ }
106
+
107
+ /**
108
+ * Set Cache Time to live
109
+ *
110
+ * @param integer $ttl Time to live
111
+ * @return \BudgetMailer\Api\Cache self
112
+ */
113
+ public function setTtl($ttl)
114
+ {
115
+ $this->ttl = $ttl;
116
+ return $this;
117
+ }
118
+
119
+ /**
120
+ * Get Cache Time to live
121
+ *
122
+ * @return integer
123
+ */
124
+ public function getTtl()
125
+ {
126
+ return $this->ttl;
127
+ }
128
+
129
+ /**
130
+ * Check and if not exist create .htaccess File protecting Cache Files
131
+ *
132
+ * @param string $dir Cache Directory (Must be writeable)
133
+ * @return boolean
134
+ * @throws \RuntimeException In case the .htaccess File cannot be written
135
+ */
136
+ protected function checkHtaccess($dir)
137
+ {
138
+ $htaccess = $dir . '.htaccess';
139
+
140
+ if (!is_file($htaccess)) {
141
+ if (!file_put_contents($htaccess, self::HTACCESS_CONTENT)) {
142
+ throw new \RuntimeException('Couldn\'t create .htaccess file in cache directory.');
143
+ }
144
+ }
145
+
146
+ return true;
147
+ }
148
+
149
+ /**
150
+ * Sanitize File Name
151
+ *
152
+ * @param string $filename Un-sanitized File Name
153
+ * @return string Sanitized File Name
154
+ */
155
+ protected function sanitizeFileName($filename)
156
+ {
157
+ $specialChars = array(
158
+ "?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"",
159
+ "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0)
160
+ );
161
+
162
+ $filename = preg_replace("#\x{00a0}#siu", ' ', $filename);
163
+ $filename = str_replace($specialChars, '', $filename);
164
+ $filename = str_replace(array( '%20', '+' ), '-', $filename);
165
+ $filename = preg_replace('/[\r\n\t -]+/', '-', $filename);
166
+ $filename = trim($filename, '.-_');
167
+
168
+ return $this->getDir() . $filename;
169
+ }
170
+
171
+ /**
172
+ * Get all Cache Files and delete them.
173
+ *
174
+ * @return boolean
175
+ */
176
+ public function purge()
177
+ {
178
+ $files = scandir($this->getDir());
179
+
180
+ if (is_array($files) && count($files)) {
181
+ foreach ($files as $file) {
182
+ if (!in_array($file, array('.', '..', '.htaccess'))) {
183
+ unlink($this->getDir() . $file);
184
+ }
185
+ }
186
+ }
187
+
188
+ return true;
189
+ }
190
+
191
+ /**
192
+ * Remove Cached data identified by Key $key from Cache
193
+ *
194
+ * @param string $key Cache ID
195
+ * @return boolean
196
+ * @throws \RuntimeException In case the Cache File cannot be deleted.
197
+ */
198
+ public function remove($key)
199
+ {
200
+ $filename = $this->sanitizeFileName($key);
201
+
202
+ if (is_file($filename)) {
203
+ if (!unlink($filename)) {
204
+ throw new \RuntimeException('Couldn\'t remove the cache key.');
205
+ }
206
+ }
207
+
208
+ return true;
209
+ }
210
+
211
+ /**
212
+ * Set Cache Key
213
+ *
214
+ * @param string $key Cache ID
215
+ * @param mixed $value Any value except false obviously
216
+ * @return boolean
217
+ * @throws \RuntimeException In case the Key cannot be stored
218
+ */
219
+ public function set($key, $value)
220
+ {
221
+ if (!$this->isEnabled()) {
222
+ return false;
223
+ }
224
+
225
+ $filename = $this->sanitizeFileName($key);
226
+
227
+ if (!file_put_contents($filename, serialize($value))) {
228
+ throw new \RuntimeException('Couldn\t write key to cache.');
229
+ }
230
+
231
+ return true;
232
+ }
233
+
234
+ /**
235
+ * Get Cache Key
236
+ *
237
+ * @param string $key Cache ID
238
+ * @return mixed Cached Data or false
239
+ * @throws \RuntimeException In case the file cannot be open, or Content unserialized
240
+ */
241
+ public function get($key)
242
+ {
243
+ if (!$this->isEnabled()) {
244
+ return false;
245
+ }
246
+
247
+ $filename = $this->sanitizeFileName($key);
248
+ $value = false;
249
+
250
+ if ($this->has($key)) {
251
+ $content = file_get_contents($filename);
252
+
253
+ if (!$content) {
254
+ throw new \RuntimeException('Couldn\'t read cache key.');
255
+ }
256
+
257
+ $value = unserialize($content);
258
+
259
+ if (!$value) {
260
+ throw new \RuntimeException('Couldn\'t unserialize cache key.');
261
+ }
262
+ }
263
+
264
+ return $value;
265
+ }
266
+
267
+ /**
268
+ * Check if Key is cached and not too old
269
+ *
270
+ * @param string $key Cache ID
271
+ * @return boolean yes / no
272
+ */
273
+ public function has($key)
274
+ {
275
+ if (!$this->isEnabled()) {
276
+ return false;
277
+ }
278
+
279
+ $filename = $this->sanitizeFileName($key);
280
+
281
+ if (!is_file($filename)) {
282
+ return false;
283
+ }
284
+
285
+ $ttl = time() - $this->getTtl();
286
+
287
+ if ($ttl >= filemtime($filename)) {
288
+ return false;
289
+ }
290
+
291
+ return true;
292
+ }
293
+ }
lib/BudgetMailer/Api/Client.php ADDED
@@ -0,0 +1,801 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BudgetMailer PHP API (https://www.budgetmailer.nl/index.php)
5
+ *
6
+ * @author BudgetMailer <info@budgetmailer.nl>
7
+ * @copyright (c) 2015 - 2017 - BudgetMailer
8
+ * @license https://gitlab.com/budgetmailer/budgetmailer-php-api/blob/master/LICENSE.txt
9
+ * @package BudgetMailer\API\Client
10
+ * @version 1.0.2
11
+ */
12
+
13
+ /**
14
+ * Namespace
15
+ *
16
+ * @package BudgetMailer\Api
17
+ */
18
+ namespace BudgetMailer\Api;
19
+
20
+ use BudgetMailer\Api\Client\RestJson;
21
+
22
+ /**
23
+ * Implementation of BudgetMailers REST-JSON API
24
+ *
25
+ * @package BudgetMailer\Api
26
+ */
27
+ class Client
28
+ {
29
+ const CACHE_KEY_CONTACT = 'bm-contact-';
30
+ const CACHE_KEY_LIST = 'bm-list-';
31
+ const CONTENT_TYPE = 'application/json';
32
+ const LIMIT = 1000;
33
+
34
+ /**
35
+ * @var array default configuration values
36
+ */
37
+ protected static $defaultConfig = array(
38
+ 'cache' => false,
39
+ 'cacheDir' => '',
40
+ 'endPoint' => 'https://api.budgetmailer.com/',
41
+ 'timeOutSocket' => 10,
42
+ 'timeOutStream' => 10,
43
+ 'ttl' => 3600,
44
+ );
45
+
46
+ /**
47
+ * @var Client singleton instance
48
+ */
49
+ protected static $instance;
50
+
51
+ /**
52
+ * @var Cache Simple File Cache
53
+ */
54
+ protected $cache;
55
+
56
+ /**
57
+ * @var Config Configuration
58
+ */
59
+ protected $config;
60
+
61
+ /**
62
+ * @var array HTTP Headers for REST-JSON Request
63
+ */
64
+ protected $headers;
65
+
66
+ /**
67
+ * @var Client\RestJson REST-JSON Client
68
+ */
69
+ protected $restJson;
70
+
71
+ /**
72
+ * @var string Signatures Salt
73
+ */
74
+ protected $salt;
75
+
76
+ /**
77
+ * @var string Requests Signature
78
+ */
79
+ protected $signature;
80
+
81
+ /**
82
+ * @var string Encoded Signature
83
+ */
84
+ protected $signatureEncoded;
85
+
86
+ /**
87
+ * Create new Instance of the BudgetMailer API Client
88
+ *
89
+ * @param Cache $cache Cache
90
+ * @param Config $config Configuration
91
+ * @param RestJson $restJson RestJson Client or null
92
+ */
93
+ public function __construct(Cache $cache, Config $config, RestJson $restJson = null)
94
+ {
95
+ $this->setConfig($config);
96
+
97
+ if (!$restJson) {
98
+ $restJson = new RestJson($config);
99
+ }
100
+
101
+ $this->setCache($cache)
102
+ ->setRestJson($restJson);
103
+ }
104
+
105
+ /**
106
+ * Create new instance of the Client.
107
+ *
108
+ * @param array $configData
109
+ * @return Client
110
+ */
111
+ public static function getInstance(array $configData = array())
112
+ {
113
+ if (!self::$instance) {
114
+ if (!isset($configData['key']) || !isset($configData['list']) || !isset($configData['secret'])) {
115
+ throw new \BadMethodCallException('Config keys "key", "list", and "secret" must be set.');
116
+ }
117
+
118
+ $configData = array_merge(self::$defaultConfig, $configData);
119
+
120
+ $config = new Config($configData);
121
+ $cache = new Cache($config);
122
+
123
+ self::$instance = new self($cache, $config);
124
+ }
125
+
126
+ return self::$instance;
127
+ }
128
+
129
+ /**
130
+ * Get Salt for Request Signature. Salt is only regenerated if its not set
131
+ * already.
132
+ *
133
+ * @return string
134
+ */
135
+ protected function getSalt()
136
+ {
137
+ if (!$this->salt) {
138
+ $this->salt = md5(microtime(true));
139
+ }
140
+
141
+ return $this->salt;
142
+ }
143
+
144
+ /**
145
+ * Get encoded Signature (base64)
146
+ *
147
+ * @return string
148
+ */
149
+ protected function getSignatureEncoded()
150
+ {
151
+ $this->signature = hash_hmac(
152
+ 'sha256',
153
+ $this->getSalt(),
154
+ $this->getConfig()->getSecret(),
155
+ true
156
+ );
157
+
158
+ $this->signatureEncoded = rawurlencode(
159
+ base64_encode($this->signature)
160
+ );
161
+
162
+ return $this->signatureEncoded;
163
+ }
164
+
165
+ /**
166
+ * Get current Configuration
167
+ *
168
+ * @return Config
169
+ */
170
+ public function getConfig()
171
+ {
172
+ return $this->config;
173
+ }
174
+
175
+ /**
176
+ * Set Configuration
177
+ *
178
+ * @param Config $config Configuration
179
+ * @return Client self
180
+ */
181
+ public function setConfig(Config $config)
182
+ {
183
+ $this->config = $config;
184
+ return $this;
185
+ }
186
+
187
+ /**
188
+ * Get Cache
189
+ *
190
+ * @return Cache
191
+ */
192
+ public function getCache()
193
+ {
194
+ return $this->cache;
195
+ }
196
+
197
+ /**
198
+ * Get REST JSON Client
199
+ *
200
+ * @return Client\RestJson REST JSON Client
201
+ */
202
+ public function getRestJson()
203
+ {
204
+ return $this->restJson;
205
+ }
206
+
207
+ /**
208
+ * Set REST JSON Client
209
+ *
210
+ * @param Client\RestJson $restJson REST JSON Client
211
+ * @return \BudgetMailer\Api\Client self
212
+ */
213
+ public function setRestJson(Client\RestJson $restJson)
214
+ {
215
+ $this->restJson = $restJson;
216
+ return $this;
217
+ }
218
+
219
+ /**
220
+ * Set Cache
221
+ *
222
+ * @param \BudgetMailer\Api\Cache $cache cache
223
+ * @return \BudgetMailer\Api\Client self
224
+ */
225
+ public function setCache(Cache $cache)
226
+ {
227
+ $this->cache = $cache;
228
+ return $this;
229
+ }
230
+
231
+ /**
232
+ * Set HTTP Headers for next Request
233
+ *
234
+ * @param array $headers HTTP Headers
235
+ * @return Client self
236
+ */
237
+ protected function setHeaders(array $headers)
238
+ {
239
+ $this->headers = $headers;
240
+ return $this;
241
+ }
242
+
243
+ /**
244
+ * Return HTTP Headers for next Request
245
+ *
246
+ * @return array HTTP Headers
247
+ */
248
+ protected function getHeaders()
249
+ {
250
+ return $this->headers;
251
+ }
252
+
253
+ /**
254
+ * Generate Headers for next Request
255
+ */
256
+ protected function beforeRequest()
257
+ {
258
+ $this->setHeaders(
259
+ array(
260
+ 'Accept' => self::CONTENT_TYPE,
261
+ 'apikey' => $this->getConfig()->getKey(),
262
+ //'apisecret' => $this->getConfig()->getSecret(),
263
+ 'Content-Type' => self::CONTENT_TYPE,
264
+ 'signature' => $this->getSignatureEncoded(),
265
+ 'salt' => $this->getSalt(),
266
+ )
267
+ );
268
+ $this->salt = null; // INFO will regenerate salt for next request
269
+ }
270
+
271
+ /**
272
+ * Filter Contact List ID - if null, then use configured Contact List.
273
+ *
274
+ * @param mixed $list List ID or anything else
275
+ */
276
+ protected function normalizeList($list)
277
+ {
278
+ return rawurlencode(is_null($list) ? $this->getConfig()->getList() : $list);
279
+ }
280
+
281
+ /**
282
+ * Filter API URL (convert relative to absolute).
283
+ *
284
+ * @param mixed $url relative URL
285
+ */
286
+ protected function normalizeUrl($url)
287
+ {
288
+ return $this->getConfig()->getEndPoint() . $url;
289
+ }
290
+
291
+ /**
292
+ * Delete existing Contact from BudgetMailer API
293
+ *
294
+ * @param string $emailOrId BudgetMailer ID or Email
295
+ * @param null|string $list Contact List Name or BudgetMailer ID, null for default
296
+ * @return boolean|null null in Case the Record doesn't exist, otherwise true
297
+ * @throws \RuntimeException In Case of Error other than not found.
298
+ * @throws \InvalidArgumentException In Case the URL is unparsable
299
+ */
300
+ public function deleteContact($emailOrId, $list = null)
301
+ {
302
+ $this->beforeRequest();
303
+
304
+ try {
305
+ $this->restJson->delete(
306
+ $this->normalizeUrl('contacts/' . $this->normalizeList($list) . '/' . rawurlencode($emailOrId)),
307
+ $this->getHeaders(),
308
+ null,
309
+ Client\Http::NO_CONTENT
310
+ );
311
+ $this->getCache()->remove(self::CACHE_KEY_CONTACT . $emailOrId);
312
+ } catch (\RuntimeException $e) {
313
+ if (Client\Http::NOT_FOUND == $e->getCode()) {
314
+ return null;
315
+ }
316
+
317
+ throw $e;
318
+ }
319
+
320
+ return true;
321
+ }
322
+
323
+ /**
324
+ * Delete multiple Contacts from BudgetMailer API.
325
+ *
326
+ * @param array $contacts array of contacts
327
+ * @param null|string $list Contact List Name or BudgetMailer ID, null for default
328
+ * @param boolean $unsubscribe unsubscribe all contacts while deleting them
329
+ * @return boolean
330
+ */
331
+ public function deleteContacts(array $contacts, $list = null, $unsubscribe = false)
332
+ {
333
+ if (count($contacts) > self::LIMIT) {
334
+ throw new \LengthException(
335
+ sprintf(
336
+ 'The maximum number of contacts for bulk methods is %d (%d given).',
337
+ self::LIMIT,
338
+ count($contacts)
339
+ )
340
+ );
341
+ }
342
+
343
+ $this->beforeRequest();
344
+
345
+ $list = $this->normalizeList($list);
346
+ $url = $this->normalizeUrl('contacts/' . $list . '/bulk-delete');
347
+
348
+ if ($unsubscribe) {
349
+ $url .= '?unsubscribe=true';
350
+ }
351
+
352
+ $res = $this->restJson->post($url, $this->getHeaders(), $contacts, Client\Http::OK);
353
+
354
+ $http = $this->restJson->getHttp();
355
+ $return = array(
356
+ $http->getResponseHeader('x-Total-Count'),
357
+ $http->getResponseHeader('x-Total-Fail'),
358
+ $http->getResponseHeader('x-Total-Success'),
359
+ $res
360
+ );
361
+
362
+ foreach ($contacts as $contact) {
363
+ $this->cache->remove(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $contact->email);
364
+ }
365
+
366
+ return $return;
367
+ }
368
+
369
+ //
370
+ // ACTUAL API IMPLEMENTATION:
371
+ //
372
+
373
+ /**
374
+ * Delete Tag from Contact Tags in BudgetMailer API
375
+ *
376
+ * @param string $emailOrId email or budgetmailer id
377
+ * @param string $tag Tag Name to delete
378
+ * @param null|string $list Contact List Name or BudgetMailer ID, null for default
379
+ * @return boolean|null True if tag was deleted, null if didn't exist
380
+ * @throws \RuntimeException In Case the Request fails
381
+ * @throws \InvalidArgumentException In Case the URL is unparsable
382
+ */
383
+ public function deleteTag($emailOrId, $tag, $list = null)
384
+ {
385
+ $this->beforeRequest();
386
+
387
+ try {
388
+ $list = $this->normalizeList($list);
389
+
390
+ $this->restJson->delete(
391
+ $this->normalizeUrl(
392
+ 'contacts/' . $list . '/' . rawurlencode($emailOrId)
393
+ . '/tags/' . rawurlencode($tag)
394
+ ),
395
+ $this->getHeaders(),
396
+ null,
397
+ Client\Http::NO_CONTENT
398
+ );
399
+
400
+ $this->getCache()->remove(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $emailOrId);
401
+ } catch (\RuntimeException $e) {
402
+ if (Client\Http::NOT_FOUND == $e->getCode()) {
403
+ return null;
404
+ }
405
+
406
+ throw $e;
407
+ }
408
+
409
+ return true;
410
+ }
411
+
412
+ /**
413
+ * Get single Contact from Contact List
414
+ *
415
+ * @param string $emailOrId Unique Contact Identifier (both e-mail and BudgetMailer Contact ID is OK)
416
+ * @param string $list null or list id
417
+ * @throws \RuntimeException In Case the Request fails (except not found)
418
+ * @throws \InvalidArgumentException In Case the URL is unparsable
419
+ */
420
+ public function getContact($emailOrId, $list = null)
421
+ {
422
+ $this->beforeRequest();
423
+
424
+ $contact = null;
425
+
426
+ try {
427
+ $list = $this->normalizeList($list);
428
+ $contact = $this->cache->get(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $emailOrId);
429
+
430
+ if (!$contact) {
431
+ $contact = $this->restJson->get(
432
+ $this->normalizeUrl('contacts/' . $list . '/' . rawurlencode($emailOrId)),
433
+ $this->getHeaders(),
434
+ null,
435
+ Client\Http::OK
436
+ );
437
+
438
+ $this->getCache()->set(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $emailOrId, $contact);
439
+ }
440
+ } catch (\RuntimeException $e) {
441
+ if (Client\Http::NOT_FOUND == $e->getCode()) {
442
+ return null;
443
+ }
444
+
445
+ throw $e;
446
+ }
447
+
448
+ return $contact;
449
+ }
450
+
451
+ /**
452
+ * Get multiple Contacts from Contact List
453
+ *
454
+ * @param integer $offset Starting Position
455
+ * @param integer $limit Record Limit (Max. 1000)
456
+ * @param string $sort ASC or DESC
457
+ * @param boolean $unsubscribed Filter subscribed / unsubscribed Contacts
458
+ * @param null|string $list list name or id or null for default
459
+ * @return array
460
+ * @throws \RuntimeException In Case the Request fails
461
+ * @throws \InvalidArgumentException In Case the URL is unparsable
462
+ */
463
+ public function getContacts(
464
+ $offset = 0,
465
+ $limit = 20,
466
+ $sort = 'ASC',
467
+ $unsubscribed = null,
468
+ $list = null
469
+ ) {
470
+ if ($limit > self::LIMIT) {
471
+ throw new \LengthException(
472
+ sprintf(
473
+ 'The maximum number of contacts for bulk methods is %d (%d given).',
474
+ self::LIMIT,
475
+ $limit
476
+ )
477
+ );
478
+ }
479
+
480
+ $this->beforeRequest();
481
+
482
+ $query = array(
483
+ 'sort' => $sort
484
+ );
485
+
486
+ if ($offset > 0) {
487
+ $query['offset'] = $offset;
488
+ }
489
+ if ($limit > 0) {
490
+ $query['limit'] = $limit;
491
+ }
492
+ if (!is_null($unsubscribed)) {
493
+ $query['unsubscribed'] = $unsubscribed ? 'True' : 'False';
494
+ }
495
+
496
+ $data = $this->restJson->get(
497
+ $this->normalizeUrl('contacts/' . $this->normalizeList($list) . '/?' . http_build_query($query)),
498
+ $this->getHeaders(),
499
+ null,
500
+ Client\Http::OK
501
+ );
502
+
503
+ return $data;
504
+ }
505
+
506
+ /**
507
+ * Get available Contact Lists
508
+ *
509
+ * @return array Array of available Lists (Objects)
510
+ * @throws \RuntimeException In Case the Request fails
511
+ * @throws \InvalidArgumentException In Case the URL is unparsable
512
+ */
513
+ public function getLists()
514
+ {
515
+ $this->beforeRequest();
516
+
517
+ $lists = $this->cache->get(self::CACHE_KEY_LIST);
518
+
519
+ if (!$lists) {
520
+ $lists = $this->restJson->get(
521
+ $this->normalizeUrl('lists'),
522
+ $this->getHeaders(),
523
+ null,
524
+ Client\Http::OK
525
+ );
526
+
527
+ $this->cache->set(self::CACHE_KEY_LIST, $lists);
528
+ }
529
+
530
+ return $lists;
531
+ }
532
+
533
+ /**
534
+ * Get Tags of Contact from BudgetMailer API
535
+ *
536
+ * @param string $emailOrId Email or BudgetMailer ID
537
+ * @param null|string $list Contact List Name or null for default
538
+ * @return boolean|array
539
+ * @throws \RuntimeException In Case the Request fails
540
+ * @throws \InvalidArgumentException In Case the URL is unparsable
541
+ */
542
+ public function getTags($emailOrId, $list = null)
543
+ {
544
+ $this->beforeRequest();
545
+
546
+ $data = $this->restJson->get(
547
+ $this->normalizeUrl('contacts/' . $this->normalizeList($list) . '/' . rawurlencode($emailOrId) . '/tags'),
548
+ $this->getHeaders(),
549
+ null,
550
+ Client\Http::OK
551
+ );
552
+
553
+ return $data;
554
+ }
555
+
556
+ /**
557
+ * Create new contact in BudgetMailer Contact List
558
+ *
559
+ * @param object $contact New Contact
560
+ * @param null|string $list Contact List Name or ID, null for default List
561
+ * @return object false or returned record from API
562
+ * @throws \RuntimeException In Case the Request fails
563
+ * @throws \InvalidArgumentException In Case the URL is unparsable
564
+ */
565
+ public function postContact($contact, $list = null)
566
+ {
567
+ $this->beforeRequest();
568
+
569
+ $list = $this->normalizeList($list);
570
+ $contact = $this->restJson->post(
571
+ $this->normalizeUrl('contacts/' . $list),
572
+ $this->getHeaders(),
573
+ $contact,
574
+ Client\Http::CREATED
575
+ );
576
+
577
+ $this->cache->set(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $contact->email, $contact);
578
+
579
+ return $contact;
580
+ }
581
+
582
+ /**
583
+ * Insert multiple Contacts to BudgetMailer API
584
+ *
585
+ * @param array $contacts Array of Contact Objects
586
+ * @param null|string $list Contact List Name or null for default
587
+ * @return boolean
588
+ * @throws \RuntimeException In Case the Request fails
589
+ * @throws \InvalidArgumentException In Case the URL is unparsable
590
+ */
591
+ public function postContacts($contacts, $list = null)
592
+ {
593
+ if (count($contacts) > self::LIMIT) {
594
+ throw new \LengthException(
595
+ sprintf(
596
+ 'The maximum number of contacts for bulk methods is %d (%d given).',
597
+ self::LIMIT,
598
+ count($contacts)
599
+ )
600
+ );
601
+ }
602
+
603
+ $this->beforeRequest();
604
+
605
+ $list = $this->normalizeList($list);
606
+
607
+ $this->restJson->post(
608
+ $this->normalizeUrl('contacts/' . $list . '/bulk'),
609
+ $this->getHeaders(),
610
+ $contacts,
611
+ Client\Http::OK
612
+ );
613
+
614
+ foreach ($contacts as $contact) {
615
+ $this->cache->remove(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $contact->email);
616
+ }
617
+
618
+ return true;
619
+ }
620
+
621
+ /**
622
+ * Insert multiple Contacts to BudgetMailer API and optionally overwrite them (default).
623
+ *
624
+ * @param array $contacts Array of Contact Objects
625
+ * @param null|string $list Contact List Name or null for default
626
+ * @param boolean $overwrite overwrite contacts if they exist
627
+ * @return boolean
628
+ * @throws \RuntimeException In Case the Request fails
629
+ * @throws \InvalidArgumentException In Case the URL is unparsable
630
+ */
631
+ public function postContactsBulk($contacts, $list = null, $overwrite = true)
632
+ {
633
+ if (count($contacts) > self::LIMIT) {
634
+ throw new \LengthException(
635
+ sprintf(
636
+ 'The maximum number of contacts for bulk methods is %d (%d given).',
637
+ self::LIMIT,
638
+ count($contacts)
639
+ )
640
+ );
641
+ }
642
+
643
+ $this->beforeRequest();
644
+
645
+ $list = $this->normalizeList($list);
646
+ $url = $this->normalizeUrl('contacts/' . $list . '/bulk-insert');
647
+
648
+ if ($overwrite) {
649
+ $url .= '?overwrite=true';
650
+ }
651
+
652
+ $res = $this->restJson->post($url, $this->getHeaders(), $contacts, Client\Http::OK);
653
+
654
+ $http = $this->restJson->getHttp();
655
+ $return = array(
656
+ $http->getResponseHeader('x-Total-Count'),
657
+ $http->getResponseHeader('x-Total-Fail'),
658
+ $http->getResponseHeader('x-Total-Success'),
659
+ $res
660
+ );
661
+
662
+ foreach ($contacts as $contact) {
663
+ $this->cache->remove(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $contact->email);
664
+ }
665
+
666
+ return $return;
667
+ }
668
+
669
+ /**
670
+ * Unsubscribe multiple Contacts from BudgetMailer API.
671
+ *
672
+ * @param array $contacts Array of Contact Objects
673
+ * @param null|string $list Contact List Name or null for default
674
+ * @return boolean
675
+ * @throws \RuntimeException In Case the Request fails
676
+ * @throws \InvalidArgumentException In Case the URL is unparsable
677
+ */
678
+ public function postContactsUnsubscribe($contacts, $list = null)
679
+ {
680
+ if (count($contacts) > self::LIMIT) {
681
+ throw new \LengthException(
682
+ sprintf(
683
+ 'The maximum number of contacts for bulk methods is %d (%d given).',
684
+ self::LIMIT,
685
+ count($contacts)
686
+ )
687
+ );
688
+ }
689
+
690
+ $this->beforeRequest();
691
+
692
+ $list = $this->normalizeList($list);
693
+
694
+ $res = $this->restJson->post(
695
+ $this->normalizeUrl('contacts/' . $list . '/bulk-unsubscribe'),
696
+ $this->getHeaders(),
697
+ $contacts,
698
+ Client\Http::OK
699
+ );
700
+
701
+ $http = $this->restJson->getHttp();
702
+ $return = array(
703
+ $http->getResponseHeader('x-Total-Count'),
704
+ $http->getResponseHeader('x-Total-Fail'),
705
+ $http->getResponseHeader('x-Total-Success'),
706
+ $res
707
+ );
708
+
709
+ foreach ($contacts as $contact) {
710
+ $this->cache->remove(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $contact->email);
711
+ }
712
+
713
+ return $return;
714
+ }
715
+
716
+ /**
717
+ * Add Tags to existing Contact
718
+ *
719
+ * @param string $emailOrId Email or BudgetMailer ID
720
+ * @param array $tags tags
721
+ * @param null|string $list Contact List Name or null for default
722
+ * @return boolean
723
+ * @throws \RuntimeException In Case the Request fails
724
+ * @throws \InvalidArgumentException In Case the URL is unparsable
725
+ */
726
+ public function postTags($emailOrId, $tags, $list = null)
727
+ {
728
+ $this->beforeRequest();
729
+
730
+ $list = $this->normalizeList($list);
731
+
732
+ $this->restJson->post(
733
+ $this->normalizeUrl('contacts/' . $list . '/' . rawurlencode($emailOrId) . '/tags'),
734
+ $this->getHeaders(),
735
+ $tags,
736
+ Client\Http::CREATED
737
+ );
738
+
739
+ $this->cache->remove(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $emailOrId);
740
+
741
+ return true;
742
+ }
743
+
744
+ /**
745
+ * Update Contact in BudgetMailer API
746
+ *
747
+ * @param string $emailOrId Email or BudgetMailer ID
748
+ * @param object $contact Contact Data
749
+ * @param null|string $list Contact List Name or null for default
750
+ * @param null|boolean $subscribe Force Subscribe or Unsubscribe, null let API handle it
751
+ * @return boolean true
752
+ * @throws \RuntimeException In Case the Request fails (except not found error)
753
+ * @throws \InvalidArgumentException In Case the URL is unparsable
754
+ */
755
+ public function putContact($emailOrId, $contact, $list = null, $subscribe = null)
756
+ {
757
+ $this->beforeRequest();
758
+
759
+ $list = $this->normalizeList($list);
760
+ $url = $this->normalizeUrl('contacts/' . $list . '/' . rawurlencode($emailOrId));
761
+
762
+ if (!is_null($subscribe)) {
763
+ $url .= '?subscribe=' . ( $subscribe ? 'True' : 'False' );
764
+ }
765
+
766
+ try {
767
+ $this->restJson->put(
768
+ $url,
769
+ $this->getHeaders(),
770
+ $contact,
771
+ Client\Http::OK
772
+ );
773
+
774
+ $this->cache->remove(self::CACHE_KEY_CONTACT . '-' . $list . '-' . $emailOrId);
775
+ } catch (\RuntimeException $e) {
776
+ if (Client\Http::NOT_FOUND == $e->getCode()) {
777
+ return null;
778
+ }
779
+
780
+ throw $e;
781
+ }
782
+
783
+ return true;
784
+ }
785
+
786
+ /**
787
+ * Test current connection credentials.
788
+ *
789
+ * @return boolean
790
+ */
791
+ public function isConnected()
792
+ {
793
+ try {
794
+ $this->cache->remove(self::CACHE_KEY_LIST);
795
+ $this->getLists();
796
+ return true;
797
+ } catch (\Exception $e) {
798
+ return false;
799
+ }
800
+ }
801
+ }
lib/BudgetMailer/Api/Client/Http.php ADDED
@@ -0,0 +1,548 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BudgetMailer PHP API (https://www.budgetmailer.nl/index.php)
5
+ *
6
+ * @author BudgetMailer <info@budgetmailer.nl>
7
+ * @copyright (c) 2015 - 2017 - BudgetMailer
8
+ * @license https://gitlab.com/budgetmailer/budgetmailer-php-api/blob/master/LICENSE.txt
9
+ * @package BudgetMailer\API\Client
10
+ * @version 1.0.2
11
+ */
12
+
13
+ /**
14
+ * Namespace
15
+ *
16
+ * @package BudgetMailer\Api\Client
17
+ */
18
+ namespace BudgetMailer\Api\Client;
19
+
20
+ use BudgetMailer\Api\Config;
21
+
22
+ /**
23
+ * Simplified Socket based HTTP Client
24
+ *
25
+ * @method array delete(string $url, array $headers = array(), string $body = null)
26
+ * @method array get(string $url, array $headers = array(), string $body = null)
27
+ * @method array post(string $url, array $headers = array(), string $body = null)
28
+ * @method array put(string $url, array $headers = array(), string $body = null)
29
+ * @package BudgetMailer\Api\Client
30
+ */
31
+ class Http
32
+ {
33
+ const HEAD_KV_SEP = ':';
34
+ const EOL = "\r\n";
35
+ const EOL2 = "\r\n\r\n";
36
+ const SPACE = ' ';
37
+
38
+ const PORT_HTTP = 80;
39
+ const PORT_HTTPS = 443;
40
+
41
+ const V_10 = 'HTTP/1.0';
42
+ const V_11 = 'HTTP/1.1';
43
+
44
+ const HTTP = 'http';
45
+ const HTTPS = 'https';
46
+ const HOST = 'host';
47
+ const PATH = 'path';
48
+ const PORT = 'port';
49
+ const PROTOCOL = 'scheme';
50
+ const QUERY = 'query';
51
+
52
+ const DELETE = 'DELETE';
53
+ const GET = 'GET';
54
+ const POST = 'POST';
55
+ const PUT = 'PUT';
56
+
57
+ const OK = 200;
58
+ const CREATED = 201;
59
+ const NO_CONTENT = 204;
60
+ const BAD_REQUEST = 400;
61
+ const UNAUTHORIZED = 401;
62
+ const NOT_FOUND = 404;
63
+
64
+ /**
65
+ * @var array Allowed HTTP Methods
66
+ */
67
+ protected $allowedMethods = array(
68
+ self::DELETE, self::GET, self::POST, self::PUT
69
+ );
70
+
71
+ /**
72
+ * @var integer Socket Error Number
73
+ */
74
+ protected $errorCode;
75
+
76
+ /**
77
+ * @var string Socket Error Message
78
+ */
79
+ protected $errorMessage;
80
+
81
+ /**
82
+ * @var boolean Print HTTP Request and Response
83
+ */
84
+ protected $printRr;
85
+
86
+ /**
87
+ * @var string Current HTTP Request
88
+ */
89
+ protected $request;
90
+
91
+ /**
92
+ * @var string Last HTTP Response
93
+ */
94
+ protected $response;
95
+
96
+ /**
97
+ * @var string Last HTTP Response Body
98
+ */
99
+ protected $responseBody;
100
+
101
+ /**
102
+ * @var array Last HTTP Response Status Headers
103
+ */
104
+ protected $responseHeaders;
105
+
106
+ /**
107
+ * @var integer Last HTTP Response Status Code
108
+ */
109
+ protected $responseCode;
110
+
111
+ /**
112
+ * @var string Last HTTP Response Status Message
113
+ */
114
+ protected $responseStatus;
115
+
116
+ /**
117
+ * @var resource Socket
118
+ */
119
+ protected $socket;
120
+
121
+ /**
122
+ * @var array Parsed URL as an associative Array
123
+ */
124
+ protected $urlParsed;
125
+
126
+ /**
127
+ * Create new instance of HTTP Client
128
+ *
129
+ * @param Config $config Config Instance
130
+ */
131
+ public function __construct(Config $config)
132
+ {
133
+ $this->setConfig($config);
134
+ }
135
+
136
+ /**
137
+ * Set Configuration
138
+ *
139
+ * @param \BudgetMailer\Api\Config $config Configuration
140
+ */
141
+ public function setConfig(Config $config)
142
+ {
143
+ $this->config = $config;
144
+ return $this;
145
+ }
146
+
147
+ /**
148
+ * Get Configuration
149
+ *
150
+ * @return \BudgetMailer\Api\Config
151
+ */
152
+ public function getConfig()
153
+ {
154
+ return $this->config;
155
+ }
156
+
157
+ /**
158
+ * Magic Method Implementation
159
+ *
160
+ * Allows short-hand Methods for HTTP Calls: delete(), get(), post(), put()
161
+ * by wrapping-up the request() Method.
162
+ *
163
+ * @param string $method Method Name
164
+ * @param array $args Method Arguments
165
+ * @return mixed Configuration Value or null
166
+ * @see \BudgetMailer\Api\Config::__get()
167
+ * @throws \BadMethodCallException
168
+ */
169
+ public function __call($method, $args)
170
+ {
171
+ if ($this->isAllowedMethod($method)) {
172
+ $args[0] = isset($args[0]) ? $args[0] : '';
173
+ $args[1] = isset($args[1]) ? $args[1] : array();
174
+ $args[2] = isset($args[2]) ? $args[2] : null;
175
+
176
+ return $this->request($args[0], $method, $args[1], $args[2]);
177
+ }
178
+
179
+ throw new \BadMethodCallException('Call to undefined method ' . __CLASS__ . '::' . $method . '().');
180
+ }
181
+
182
+ /**
183
+ * Check if the Method is allowed.
184
+ *
185
+ * @param string $method Method Name
186
+ * @return boolean
187
+ */
188
+ public function isAllowedMethod($method)
189
+ {
190
+ $method = strtoupper($method);
191
+ return in_array($method, $this->allowedMethods);
192
+ }
193
+
194
+ /**
195
+ * Do HTTP Request.
196
+ *
197
+ * This Method do HTTP Request, and stores parsed HTTP Response
198
+ * as this Object Properties. You can do both simple Requests, and or send
199
+ * HTTP Headers and or Body.
200
+ * Workflow: reset Object Properties (e.g. Response), parse URL,
201
+ * normalize URL, open Socket, create HTTP Request, send HTTP Request,
202
+ * read HTTP Response, close Socket, and finally parse HTTP Response.
203
+ *
204
+ * @param string $url Request URL
205
+ * @param string $method HTTP Method
206
+ * @param array $headers HTTP Headers
207
+ * @param string $body HTTP Body
208
+ * @return boolean True in Case the Method get to the End
209
+ * @throws \InvalidArgumentException If the URL is invalid
210
+ * @throws \RunTimeException If there is unexpected value returned in function calls
211
+ */
212
+ public function request($url, $method = self::GET, array $headers = array(), $body = null)
213
+ {
214
+ $this->reset();
215
+ $this->parseUrl($url);
216
+ $this->normalizeUrl();
217
+ $this->openSocket();
218
+ $this->createRequest($method, $headers, $body);
219
+
220
+ if ($this->printRr) {
221
+ echo PHP_EOL . 'HTTP Request: ' . PHP_EOL . $this->request . PHP_EOL;
222
+ }
223
+
224
+ $this->sendRequest($method, $headers, $body);
225
+ $this->readResponse();
226
+
227
+ if ($this->printRr) {
228
+ echo PHP_EOL . 'HTTP Response: ' . PHP_EOL . $this->response . PHP_EOL;
229
+ }
230
+
231
+ $this->closeSocket();
232
+ $this->parseResponse();
233
+
234
+ return true;
235
+ }
236
+
237
+ /**
238
+ * Reset all Client's properties and set them to null.
239
+ */
240
+ protected function reset()
241
+ {
242
+ $this->errorCode = $this->errorMessage = $this->request =
243
+ $this->response = $this->responseBody = $this->responseCode =
244
+ $this->responseHeaders = $this->socket = $this->urlParsed = null;
245
+ }
246
+
247
+ /**
248
+ * Parse given URL and stores the associative Array.
249
+ *
250
+ * @param string $url URL to parse
251
+ * @throws \InvalidArgumentException In case the URL is not parsable.
252
+ */
253
+ protected function parseUrl($url)
254
+ {
255
+ $this->urlParsed = parse_url($url);
256
+
257
+ if (!is_array($this->urlParsed)) {
258
+ throw new \InvalidArgumentException('Unparsable URL.');
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Check the parsed URL, and prepare it for HTTP Request.
264
+ *
265
+ * Workflow: check if Hostname is not missing in parsed URL,
266
+ * check if Port is not missing in parsed URL, check URL Protocol
267
+ * and set the Port accordingly, and prefix URL Query with "?" or set
268
+ * it to null.
269
+ *
270
+ * @throws \InvalidArgumentException In case any URL validation test fails
271
+ */
272
+ protected function normalizeUrl()
273
+ {
274
+ if (!$this->getUrlParsedKey(self::HOST)) {
275
+ throw new \InvalidArgumentException('URL is missing Hostname.');
276
+ }
277
+
278
+ if (!$this->getUrlParsedKey(self::PATH)) {
279
+ $this->urlParsed[self::PATH] = DIRECTORY_SEPARATOR;
280
+ }
281
+
282
+ if (!$this->getUrlParsedKey(self::PROTOCOL)) {
283
+ throw new \InvalidArgumentException('URL is missing Protocol.');
284
+ }
285
+
286
+ if (!$this->getUrlParsedKey(self::PORT)) {
287
+ $this->normalizeUrlPort();
288
+ }
289
+
290
+ $this->urlParsed[self::QUERY] = isset($this->urlParsed[self::QUERY])
291
+ ? '?' . $this->urlParsed[self::QUERY] : null;
292
+ }
293
+
294
+ /**
295
+ * Normalize parsed URL port
296
+ *
297
+ * @throws \InvalidArgumentException if requested protocol is not http(s)
298
+ */
299
+ protected function normalizeUrlPort()
300
+ {
301
+ switch ($this->urlParsed[self::PROTOCOL]) {
302
+ case self::HTTP:
303
+ $this->urlParsed[self::PORT] = self::PORT_HTTP;
304
+ break;
305
+ case self::HTTPS:
306
+ $this->urlParsed[self::PORT] = self::PORT_HTTPS;
307
+ break;
308
+ default:
309
+ throw new \InvalidArgumentException('Allowed URL Protocols are "http" and "https".');
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Open Socket for HTTP Connection.
315
+ *
316
+ * @return resource The newly created Socket
317
+ * @throws \RuntimeException In Case the Socket or its Configuration fails
318
+ */
319
+ protected function openSocket()
320
+ {
321
+ $host = (self::HTTPS == $this->urlParsed[self::PROTOCOL])
322
+ ? 'tls://' . $this->urlParsed[self::HOST]
323
+ : $this->urlParsed[self::HOST];
324
+
325
+ $this->socket = @fsockopen(
326
+ $host,
327
+ $this->urlParsed[self::PORT],
328
+ $this->errorCode,
329
+ $this->errorMessage,
330
+ $this->getConfig()->getTimeOutSocket()
331
+ );
332
+
333
+ if (!$this->socket) {
334
+ throw new \RuntimeException(
335
+ sprintf(
336
+ 'Couldn\'t open Socket for HTTP Connection (Socket Error: %d - %s).',
337
+ $this->errorCode,
338
+ $this->errorMessage
339
+ )
340
+ );
341
+ }
342
+
343
+ if (!stream_set_timeout($this->socket, $this->getConfig()->getTimeOutStream())) {
344
+ throw new \RuntimeException('Couldn\'t set Stream Time-out for HTTP Connection Socket.');
345
+ }
346
+
347
+ return $this->socket;
348
+ }
349
+
350
+ /**
351
+ * Close HTTP Connection Socket.
352
+ *
353
+ * @throws \RuntimeException In Case the Sockect cannot be closed
354
+ */
355
+ protected function closeSocket()
356
+ {
357
+ if (!fclose($this->socket)) {
358
+ throw new \RuntimeException('Couldn\'t close HTTP Connection Socket.');
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Create HTTP Request String from given Arguments.
364
+ *
365
+ * @param string $method HTTP Method
366
+ * @param array $headers HTTP Headers
367
+ * @param string $body HTTP Body
368
+ * @return string HTTP Request
369
+ */
370
+ protected function createRequest($method = self::GET, array &$headers = array(), &$body = null)
371
+ {
372
+ $this->request = strtoupper($method) . self::SPACE . $this->urlParsed['path']
373
+ . $this->urlParsed[self::QUERY] . self::SPACE . self::V_11 . self::EOL
374
+ . 'Host' . self::HEAD_KV_SEP . self::SPACE . $this->urlParsed['host'] . self::EOL
375
+ . 'Connection' . self::HEAD_KV_SEP . self::SPACE . 'Close' . self::EOL;
376
+
377
+ if (in_array(strtoupper($method), array(self::POST, self::PUT))) {
378
+ $this->request .= 'Content-Length' . self::HEAD_KV_SEP
379
+ . self::SPACE . strlen($body) . self::EOL;
380
+ }
381
+
382
+ if (count($headers)) {
383
+ foreach ($headers as $k => $v) {
384
+ $this->request .= $k . self::HEAD_KV_SEP . self::SPACE . $v . self::EOL;
385
+ }
386
+ }
387
+
388
+ $this->request .= self::EOL;
389
+
390
+ if (!is_null($body)) {
391
+ $this->request .= $body;
392
+ }
393
+
394
+ return $this->request;
395
+ }
396
+
397
+ /**
398
+ * Send HTTP Request through openned Socket.
399
+ *
400
+ * @throws \RuntimeException In Case the HTTP Request Send fails
401
+ */
402
+ protected function sendRequest()
403
+ {
404
+ $res = fwrite($this->socket, $this->request);
405
+
406
+ if (!$res) {
407
+ throw new \RuntimeException('Couldn\'t send HTTP Request.');
408
+ }
409
+ }
410
+
411
+ /**
412
+ * Read HTTP Response from Socket
413
+ *
414
+ * @throws \RuntimeException In case the Read fails, or Time-out
415
+ */
416
+ protected function readResponse()
417
+ {
418
+ $this->response = null;
419
+
420
+ // INFO this should only read up to content-length...
421
+ while (!feof($this->socket)) {
422
+ if (!( $res = fgets($this->socket, 128) ) && empty($this->response)) {
423
+ throw new \RuntimeException('Couldn\'t read from HTTP Socket.');
424
+ }
425
+
426
+ if ($res) {
427
+ $this->response .= $res;
428
+ }
429
+ }
430
+
431
+ if (!$this->response) {
432
+ throw new \RuntimeException('Empty HTTP Response.');
433
+ }
434
+ }
435
+
436
+ /**
437
+ * Parse HTTP Response string
438
+ *
439
+ * @throws \RuntimeException In Case the Headers or Body is empty or HTTP Status Code or Message cannot be parsed.
440
+ */
441
+ public function parseResponse()
442
+ {
443
+ list($headers, $this->responseBody) = explode(self::EOL2, $this->response, 2);
444
+
445
+ if (!$headers && !$this->responseBody) {
446
+ throw new \RuntimeException('Invalid HTTP Response: empty Headers and Body.');
447
+ }
448
+
449
+ $headersLines = explode(self::EOL, $headers);
450
+ $this->responseHeaders = array();
451
+
452
+ foreach ($headersLines as $i => $headerLine) {
453
+ if (0 == $i) {
454
+ list(/*$protocol*/, $this->responseCode, $this->responseStatus) =
455
+ explode(self::SPACE, $headerLine, 3);
456
+
457
+ if (!$this->responseCode || !$this->responseStatus) {
458
+ throw new \RuntimeException('Invalid HTTP Response: unknown Status Code and or Message.');
459
+ }
460
+
461
+ continue;
462
+ }
463
+
464
+ list($name, $value) = explode(':', $headerLine, 2);
465
+ $this->responseHeaders[trim($name)] = trim($value);
466
+ }
467
+ }
468
+
469
+ /**
470
+ * Get last Response Body
471
+ *
472
+ * @return string
473
+ */
474
+ public function getResponseBody()
475
+ {
476
+ return $this->responseBody;
477
+ }
478
+
479
+ /**
480
+ * Get last Response Status Code
481
+ *
482
+ * @return string|integer
483
+ */
484
+ public function getResponseCode()
485
+ {
486
+ return $this->responseCode;
487
+ }
488
+
489
+ /**
490
+ * Get last Response Header by key
491
+ *
492
+ * @param string $header header to get
493
+ * @return null|string
494
+ */
495
+ public function getResponseHeader($header)
496
+ {
497
+ return isset($this->responseHeaders[$header]) ? $this->responseHeaders[$header] : null;
498
+ }
499
+
500
+ /**
501
+ * Get multiple response headers
502
+ *
503
+ * @param array $headers array of headers to get
504
+ * @return array
505
+ */
506
+ public function getResponseHeaders($headers)
507
+ {
508
+ $res = array();
509
+
510
+ foreach ($headers as $header) {
511
+ $res[$header] = $this->getResponseHeader($header);
512
+ }
513
+
514
+ return $res;
515
+ }
516
+
517
+ /**
518
+ * Get last Reponse Status Message
519
+ *
520
+ * @return string
521
+ */
522
+ public function getResponseMessage()
523
+ {
524
+ return $this->responseStatus;
525
+ }
526
+
527
+ /**
528
+ * Get key from parsed URL.
529
+ *
530
+ * @param string $key key to get
531
+ * @return mixed value or false
532
+ */
533
+ protected function getUrlParsedKey($key)
534
+ {
535
+ return isset($this->urlParsed[$key]) && $this->urlParsed[$key]
536
+ ? $this->urlParsed[$key] : false;
537
+ }
538
+
539
+ /**
540
+ * Set Print HTTP Requests and Responses Flag
541
+ *
542
+ * @param type $value
543
+ */
544
+ public function setPrintRequestResponse($value)
545
+ {
546
+ $this->printRr = $value;
547
+ }
548
+ }
lib/BudgetMailer/Api/Client/RestJson.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BudgetMailer PHP API (https://www.budgetmailer.nl/index.php)
5
+ *
6
+ * @author BudgetMailer <info@budgetmailer.nl>
7
+ * @copyright (c) 2015 - 2017 - BudgetMailer
8
+ * @license https://gitlab.com/budgetmailer/budgetmailer-php-api/blob/master/LICENSE.txt
9
+ * @package BudgetMailer\API\Client
10
+ * @version 1.0.2
11
+ */
12
+
13
+ /**
14
+ * Namespace
15
+ *
16
+ * @package BudgetMailer\Api\Client
17
+ */
18
+ namespace BudgetMailer\Api\Client;
19
+
20
+ use BudgetMailer\Api\Config;
21
+
22
+ /**
23
+ * Simplified REST-JSON HTTP Client
24
+ *
25
+ * @method mixed delete(string $url, array $headers = array, mixed $body = null, integer $expectedCode = Http::OK)
26
+ * @method mixed get(string $url, array $headers = array, mixed $body = null, integer $expectedCode = Http::OK)
27
+ * @method mixed post(string $url, array $headers = array, mixed $body = null, integer $expectedCode = Http::OK)
28
+ * @method mixed put(string $url, array $headers = array, mixed $body = null, integer $expectedCode = Http::OK)
29
+ * @package BudgetMailer\Api\Client
30
+ */
31
+ class RestJson
32
+ {
33
+ /**
34
+ * @var \BudgetMailer\Api\Client\Http HTTP Client
35
+ */
36
+ protected $http;
37
+
38
+ /**
39
+ * Create new instance of REST-JSON Client.
40
+ *
41
+ * @param Config $config Configuration
42
+ * @param \BudgetMailer\Api\Client\Http $http HTTP Client or null
43
+ */
44
+ public function __construct(Config $config, Http $http = null)
45
+ {
46
+ if (is_null($http)) {
47
+ $http = new Http($config);
48
+ }
49
+
50
+ $this->http = $http;
51
+ }
52
+
53
+ /**
54
+ * Magic Method Implementation.
55
+ *
56
+ * Implements possible HTTP Methods: delete, get, post, and put as
57
+ * virtual methods.
58
+ *
59
+ * @param string $method Called Method Name
60
+ * @param array $args Called Method Arguments
61
+ * @return mixed Decoded JSON String
62
+ * @throws \RuntimeException In Case the Expected Code is not null and HTTP Response Status Code doesn't match
63
+ * @throws \BadMethodCallException In Case the Method is not HTTP Method
64
+ */
65
+ public function __call($method, $args)
66
+ {
67
+ if ($this->http->isAllowedMethod($method)) {
68
+ $args[0] = isset($args[0]) ? $args[0] : ''; // URL
69
+ $args[1] = isset($args[1]) ? $args[1] : array(); // headers
70
+ $args[2] = isset($args[2]) ? $args[2] : null; // body
71
+ $expectedCode = isset($args[3]) ? $args[3] : null; // expected response code
72
+
73
+ if ($args[2]) {
74
+ $args[2] = $this->encode($args[2]);
75
+ }
76
+
77
+ $this->http->request($args[0], $method, $args[1], $args[2]);
78
+
79
+ if (!is_null($expectedCode) && $expectedCode != $this->http->getResponseCode()) {
80
+ throw new \RuntimeException(
81
+ sprintf(
82
+ 'REST-JSON Call failed. Expected Response Code %d, got %d - %s. URL: %s',
83
+ $expectedCode,
84
+ $this->http->getResponseCode(),
85
+ $this->http->getResponseMessage(),
86
+ $args[0]
87
+ ),
88
+ $this->http->getResponseCode()
89
+ );
90
+ }
91
+
92
+ return $this->decode($this->http->getResponseBody());
93
+ }
94
+
95
+ throw new \BadMethodCallException('Call to undefined method ' . __CLASS__ . '::' . $method . '().');
96
+ }
97
+
98
+ /**
99
+ * Decode JSON String
100
+ *
101
+ * @param string $string JSON encoded String
102
+ * @return mixed Decoded JSON String
103
+ * @throws \RuntimeException In Case the decoding fails
104
+ */
105
+ public function decode($string)
106
+ {
107
+ $result = json_decode($string);
108
+
109
+ if (false === $result) {
110
+ throw new \RuntimeException('Can\'t decode JSON string.');
111
+ }
112
+
113
+ return $result;
114
+ }
115
+
116
+ /**
117
+ * Encode JSON String
118
+ *
119
+ * @param mixed $data Data to encode as JSON String
120
+ * @return string JSON encoded Data
121
+ * @throws \RuntimeException In case the encoding fails
122
+ */
123
+ public function encode($data)
124
+ {
125
+ $result = json_encode($data);
126
+
127
+ if (false === $result) {
128
+ throw new \RuntimeException('Can\'t encode data to JSON.');
129
+ }
130
+
131
+ return $result;
132
+ }
133
+
134
+ /**
135
+ * Get HTTP client instance.
136
+ *
137
+ * @return Http
138
+ */
139
+ public function getHttp()
140
+ {
141
+ return $this->http;
142
+ }
143
+ }
lib/BudgetMailer/Api/Config.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BudgetMailer PHP API (https://www.budgetmailer.nl/index.php)
5
+ *
6
+ * @author BudgetMailer <info@budgetmailer.nl>
7
+ * @copyright (c) 2015 - 2017 - BudgetMailer
8
+ * @license https://gitlab.com/budgetmailer/budgetmailer-php-api/blob/master/LICENSE.txt
9
+ * @package BudgetMailer\API\Client
10
+ * @version 1.0.2
11
+ */
12
+
13
+ /**
14
+ * Namespace
15
+ *
16
+ * @package BudgetMailer\Api
17
+ */
18
+ namespace BudgetMailer\Api;
19
+
20
+ /**
21
+ * BudgetMailer API Client Config Wrapper
22
+ *
23
+ * This Class provides simple Interface for BudgetMailer API Client Configuration.
24
+ * You can use either access Configuration Values as Object Properties ($o->cache)
25
+ * thanks to Magic Functions __get() and __set(). Or with getters, listed below.
26
+ *
27
+ * @method boolean getCache()
28
+ * @method string getCacheDir()
29
+ * @method string getEndPoint()
30
+ * @method string getKey()
31
+ * @method string getList()
32
+ * @method string getSecret()
33
+ * @method integer getTtl()
34
+ * @method integer getTimeOutSocket()
35
+ * @method integer getTimeOutStream()
36
+ * @package BudgetMailer\Api
37
+ */
38
+ class Config
39
+ {
40
+ /**
41
+ * @var array Associative Array of the Configuration Values
42
+ */
43
+ protected $config;
44
+
45
+ /**
46
+ * Create new instance of Config
47
+ *
48
+ * @param array $config Configuration as an Associative Array
49
+ */
50
+ public function __construct(array $config)
51
+ {
52
+ $this->setConfig($config);
53
+ }
54
+
55
+ /**
56
+ * Set Configuration
57
+ *
58
+ * @param array $config Configuration as an Associative Array
59
+ */
60
+ public function setConfig(array $config)
61
+ {
62
+ $this->config = $config;
63
+ }
64
+
65
+ /**
66
+ * Magic Method Implementation
67
+ *
68
+ * Converts Part of called Method after "get" to Configuration Key,
69
+ * e.g. "getCache" to "cache", and returns the Value or null.
70
+ *
71
+ * @param string $method Method Name
72
+ * @param array $args Method Arguments
73
+ * @return mixed Configuration Value or null
74
+ * @see \BudgetMailer\Api\Config::__get()
75
+ * @throws \BadMethodCallException
76
+ */
77
+ public function __call($method, $args)
78
+ {
79
+ $get = 'get';
80
+
81
+ if (preg_match('/^' . $get . '/i', $method)) {
82
+ $property = lcfirst(str_replace($get, '', $method));
83
+
84
+ return $this->$property;
85
+ }
86
+
87
+ throw new \BadMethodCallException('Call to undefined method ' . __CLASS__ . '::' . $method . '().');
88
+ }
89
+
90
+ /**
91
+ * Magic Method Implementation - get Object Property.
92
+ *
93
+ * @param string $key requested Property Name
94
+ * @return mixed Property Value or null
95
+ */
96
+ public function __get($key)
97
+ {
98
+ return isset($this->config[$key]) ? $this->config[$key] : null;
99
+ }
100
+
101
+ /**
102
+ * Magic Method Implementation - set Object Property.
103
+ *
104
+ * @param string $key Property Name
105
+ * @param mixed $val Property Value
106
+ */
107
+ public function __set($key, $val)
108
+ {
109
+ $this->config[$key] = $val;
110
+ }
111
+ }
lib/BudgetMailer/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 - 2017 BudgetMailer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package.xml CHANGED
@@ -1,21 +1,22 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Professio_BudgetMailer</name>
4
- <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license>MIT</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Professio BudgetMailer seamlessly implements BudgetMailer API, and flawlessly replace Magento Newsletter.</summary>
10
  <description>Professio BudgetMailer seamlessly implements BudgetMailer API, and flawlessly replace Magento Newsletter.</description>
11
- <notes>1.0.3 - Various bug fixes, and simplifications&#xD;
 
12
  1.0.2 - PHP bug fix: using empty() in write context&#xD;
13
  1.0.1 - Repacking for Magento Connect&#xD;
14
  1.0.0 - Initial version</notes>
15
  <authors><author><name>J.S. Diertens</name><user>budgetmailer</user><email>info@budgetmailer.nl</email></author></authors>
16
- <date>2016-03-15</date>
17
- <time>15:11:38</time>
18
- <contents><target name="magecommunity"><dir name="Professio"><dir name="BudgetMailer"><dir name="Block"><dir name="Adminhtml"><dir name="Contact"><dir name="Edit"><file name="Form.php" hash="84ffb3e0633e9ff1ce93b3606b82a574"/><dir name="Tab"><file name="Form.php" hash="53fb4454290ad4704e80f48520b933dd"/></dir><file name="Tabs.php" hash="469cdd4b84c4733679bbf60f4bd9bbb9"/></dir><file name="Edit.php" hash="a58fbc229ac537be75f85a7e20ce39b2"/><file name="Grid.php" hash="62742a6a68f47a8af89954d86ca5d44c"/></dir><file name="Contact.php" hash="c1e977bc52d59bc4e72f6b6852bb6533"/><dir name="Customer"><file name="Tab.php" hash="11e9f72548a61e33f5012ace80fea2d4"/></dir><dir name="Helper"><dir name="Column"><dir name="Renderer"><file name="Parent.php" hash="5da322afef5caea928d85e90c30c297b"/></dir></dir></dir><dir name="List"><dir name="Edit"><file name="Form.php" hash="fc11a9ee7bd6a3b8bf703569f93f558e"/><dir name="Tab"><file name="Form.php" hash="9391bc1eaa8dd3075317ebcb473d1938"/></dir><file name="Tabs.php" hash="05c4743d5c17319c41f387e8189e6e5c"/></dir><file name="Edit.php" hash="a601e5169eacf2bab6307c56af02727f"/><file name="Grid.php" hash="3cb50bb35c682a35b83f5315946ea898"/></dir><file name="List.php" hash="c805782c8aef4cbce2b8acfacec29119"/></dir><file name="CheckoutAgreements.php" hash="c01af3dc12c5e724e400863bc13c3472"/><file name="Newsletter.php" hash="b9aec616529485c88bfc895c5ab37f4b"/><dir name="Subscribe"><file name="Mini.php" hash="a883b0136a6eb909732adeed87593bd9"/></dir><file name="Subscribe.php" hash="dd55cee6b835ca4292d3776319947485"/></dir><dir name="Controller"><dir name="Adminhtml"><file name="BudgetMailer.php" hash="419ac9d8824cdcf7b3d5040305d41d9b"/></dir></dir><file name="Exception.php" hash="8d5a5578baa52c32c86aab9552367871"/><dir name="Form"><dir name="Element"><file name="Tags.php" hash="1d8c68499bb5a249246c5a96f437f5af"/></dir></dir><dir name="Helper"><file name="Config.php" hash="6db7732d471e9e16cb5ed89a8c06538d"/><file name="Data.php" hash="87b2bfe6bc81dffd8a311444ab2dd627"/><file name="Mapper.php" hash="61bfe1f75edb4e1551bb50a0397d20de"/></dir><dir name="Model"><file name="Client.php" hash="882320e4eb86b75d3fb66ce699552284"/><dir name="Config"><dir name="Source"><file name="Account.php" hash="33d43e4467d8db04b2e15d617236ed85"/><file name="Address.php" hash="4c3210e958e4fdec0cdb7957a60ddffc"/><dir name="Delete"><file name="Address.php" hash="d5fae5c1b2e822d025a00eaeaf6b77e5"/></dir><file name="Delete.php" hash="42c9db5f3a06898dbf9226fe73263c6e"/><file name="List.php" hash="d0ef01f39fe9d92b48ff3c555e7e26d5"/><file name="Update.php" hash="ab92b99a2bce5dc5235b1135b9d00f1e"/></dir></dir><file name="Contact.php" hash="eb69cd4fff7100f1922f42866624b206"/><file name="Exporter.php" hash="e18fae5d19583d267c9dac387d4d7124"/><file name="Importer.php" hash="690e8072c5238f9e555baad995ce4c8f"/><file name="List.php" hash="bd324ba673c963d81de8345242bcc822"/><file name="Observer.php" hash="f07a7d4bebc286ddcdad34aa97e5b631"/><dir name="Resource"><dir name="Contact"><file name="Collection.php" hash="33b6a3514437d48b90d6deadd6deb05c"/></dir><file name="Contact.php" hash="0f02959a67178ab33fe903a60f4e2359"/><dir name="List"><file name="Collection.php" hash="db2d92515fe39a8ad0f1ca144550fd7d"/></dir><file name="List.php" hash="12c23fa0395209c68bdf9d273464c957"/><file name="Setup.php" hash="939f3c5bf1c38b36b9de6984befe53ac"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Budgetmailer"><file name="ContactController.php" hash="3de80dceeff43b3b00adb24a95a2b218"/></dir><file name="BudgetmailerController.php" hash="5ee8a0bf600a256e0d244d3e6edae912"/></dir><file name="ManageController.php" hash="e70082c900d2b7630752787ade582122"/><file name="SubscriberController.php" hash="b9ebaa98346b04d3f19f4864c8d1ec10"/><file name="WebhookController.php" hash="d7803e2cfa237b35bbf34041571fb3dd"/></dir><dir name="etc"><file name="adminhtml.xml" hash="8f88efcafef92b874f44ffc263d1d4fa"/><file name="config.xml" hash="31625b7aff671052d175bdb9fe701916"/><file name="system.xml" hash="231439eb412d6219fb76e6e07443c5f2"/></dir><dir name="sql"><dir name="budgetmailer_setup"><file name="install-1.0.0.php" hash="8854ecf4cce961c84b88f4b3c4cfb715"/></dir><file name="budgetmailer_setup_uninstall.sql" hash="ccf0931d13ee3baa903f77003c77c7c9"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="budgetmailer.xml" hash="3f8fab70b03bfc23ea2c9091b623da48"/></dir><dir name="template"><dir name="budgetmailer"><file name="newsletter.phtml" hash="4c5797708f22751e6565b6da516483a3"/><file name="onepage-agreements.phtml" hash="7d7b2809008c2d832154c291d0c80610"/><dir name="subscribe"><file name="mini.phtml" hash="dd613818725d6d11f59dc6da6bb4821c"/></dir><file name="subscribe.phtml" hash="e1a47e179c4d3d69f6d46e5e03e59d97"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="layout"><file name="budgetmailer.xml" hash="5dd0fd80c51125930ae444922343c694"/></dir><dir name="template"><dir name="budgetmailer"><file name="newsletter.phtml" hash="b25b064f39666aa69eedc91ddc44c95c"/><file name="onepage-agreements.phtml" hash="7d7b2809008c2d832154c291d0c80610"/><dir name="subscribe"><file name="mini.phtml" hash="e3c8fb8758849322af50f790fa2aca2a"/></dir><file name="subscribe.phtml" hash="ed835b8c15de0788617e6331dd135a3d"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="budgetmailer.xml" hash="a4733989973690c7ed4c5216157bd8a6"/></dir><dir name="template"><dir name="budgetmailer"><dir name="customer"><file name="tab.phtml" hash="832eb6b15600c265dd86ab3d59cb7b9f"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Professio_BudgetMailer.xml" hash="e6ef2ac221374863f4bfcbc415b950fe"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Professio_BudgetMailer.csv" hash="fa141b68821fc7a5796c85b7ce7c40d8"/></dir><dir name="nl_NL"><file name="Professio_BudgetMailer.csv" hash="ee64f8c122ab34b7c4f2dcc920a44f09"/></dir></target></contents>
19
  <compatible/>
20
- <dependencies><required><php><min>5.3.0</min><max>7.0.0</max></php></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Professio_BudgetMailer</name>
4
+ <version>1.0.4</version>
5
  <stability>stable</stability>
6
  <license>MIT</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Professio BudgetMailer seamlessly implements BudgetMailer API, and flawlessly replace Magento Newsletter.</summary>
10
  <description>Professio BudgetMailer seamlessly implements BudgetMailer API, and flawlessly replace Magento Newsletter.</description>
11
+ <notes>1.0.4 - Changed copyright years, removed contact &amp; list models to simpler the workflow, replaced custom magento budgetmailer api with BudgetMailer PHP API, translation &amp; template updates&#xD;
12
+ 1.0.3 - Various bug fixes, and simplifications&#xD;
13
  1.0.2 - PHP bug fix: using empty() in write context&#xD;
14
  1.0.1 - Repacking for Magento Connect&#xD;
15
  1.0.0 - Initial version</notes>
16
  <authors><author><name>J.S. Diertens</name><user>budgetmailer</user><email>info@budgetmailer.nl</email></author></authors>
17
+ <date>2017-02-17</date>
18
+ <time>18:27:15</time>
19
+ <contents><target name="magecommunity"><dir name="Professio"><dir name="BudgetMailer"><dir name="Block"><dir name="Adminhtml"><dir name="Customer"><file name="Tab.php" hash="73c693033fe53312bd49998edbfb1dde"/></dir><file name="Export.php" hash="d69336f884a0c0a370439bf745495638"/></dir><file name="CheckoutAgreements.php" hash="4d7366f074e94e24f27bdede87c318dd"/><file name="Newsletter.php" hash="390f399ab3ce5d2b031e48978a11a113"/><dir name="Subscribe"><file name="Mini.php" hash="c0c5faa72a7f6af5ceb6e74bb00f9eff"/></dir><file name="Subscribe.php" hash="392340f45b85be78425ba4ed4b6536b2"/></dir><dir name="Controller"><dir name="Adminhtml"><file name="BudgetMailer.php" hash="71a47dd7fe6f54f6c760d93b7171e7e8"/></dir></dir><file name="Exception.php" hash="8ddaf29011e3ad168e5785fd5c4295ad"/><dir name="Helper"><file name="Config.php" hash="de91f19d79bdd293f8af0060c4a3699e"/><file name="Data.php" hash="88f1f101841d56db0a245335140244b0"/><file name="Mapper.php" hash="f0d2a8b1ad95e87c3a35cff327324472"/></dir><dir name="Model"><file name="Client.php" hash="bcac021549f282eccd306ebfa3adc45d"/><dir name="Config"><dir name="Source"><file name="Account.php" hash="b96a517d97c575b308311d5adffbdc1c"/><file name="Address.php" hash="d973a57e9fd3e0583590834631ef5f5f"/><dir name="Delete"><file name="Address.php" hash="be1328534d8f1661635ca4a54b5fd07b"/></dir><file name="Delete.php" hash="7217472e18eb855db0e5172a18b95a9d"/><file name="List.php" hash="57558139d3a60e6c84ce825d63aa2532"/><file name="Update.php" hash="8221c6dda6bae94093121b33c7c62573"/></dir></dir><file name="Exporter.php" hash="0375aea1c1214f3a1ea05c1c0a6f503e"/><file name="Observer.php" hash="ee3d5622e107e9e54cc68e096abbafaa"/><dir name="Resource"><file name="Setup.php" hash="4fd191fc918a0684d7ec7c3f810ec10b"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="BudgetmailerController.php" hash="d8d26721481b459bab5abc88576e9b9d"/></dir><file name="ManageController.php" hash="8a5675c564bfe47b8fc8d77e6a4a39d7"/><file name="SubscriberController.php" hash="d1a273842a4dc37af32142f4ca748120"/></dir><dir name="etc"><file name="adminhtml.xml" hash="e6d728555e913dc0b8df6dd0651d3ba7"/><file name="config.xml" hash="fb16dc43405556f244b4050d4a5fe746"/><file name="system.xml" hash="2d68aea5665ccaed7214d99a500ef3ca"/></dir><dir name="sql"><dir name="budgetmailer_setup"><file name="install-1.0.0.php" hash="a7ca84b48da486b15b497fe95ef69c00"/><file name="mysql4-upgrade-1.0.1-1.0.2.php" hash="f1861d3e918366e2540ed757d7a6773a"/></dir><file name="budgetmailer_setup_uninstall.sql" hash="86d39a4dbaff08a574e9b5140bbbac3a"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="budgetmailer.xml" hash="ecf5cc3ac7e216d892d5f29aaa1f9e28"/></dir><dir name="template"><dir name="budgetmailer"><dir name="customer"><file name="tab.phtml" hash="b78e55c25ba624420a8c54052f2398c1"/></dir><file name="export.phtml" hash="0e1a50478350859d779120956e546313"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="budgetmailer.xml" hash="bf2acf28772167969b0f7c62fbb111bf"/></dir><dir name="template"><dir name="budgetmailer"><file name="newsletter.phtml" hash="9853aff649a23ed64f4bbfb789a7e72e"/><file name="onepage-agreements.phtml" hash="dfe35b794d49de747791f478ca2e6e5c"/><dir name="subscribe"><file name="mini.phtml" hash="51bd736c251f0ef7630da8affccd2bf1"/></dir><file name="subscribe.phtml" hash="00b9037470721fdebeb107a1528ecd35"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="layout"><file name="budgetmailer.xml" hash="690671b4ccdf472825d763ca83c6414c"/></dir><dir name="template"><dir name="budgetmailer"><file name="newsletter.phtml" hash="a4b4295784949cae143fc3d7bb915f08"/><file name="onepage-agreements.phtml" hash="dfe35b794d49de747791f478ca2e6e5c"/><dir name="subscribe"><file name="mini.phtml" hash="ff86511fc609b654fe9d4963edb7a884"/></dir><file name="subscribe.phtml" hash="32cee72fd5b53d3670c2d4d49a8d511d"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Professio_BudgetMailer.xml" hash="c7ec75b06d90f62d519200a7ae82f5f6"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Professio_BudgetMailer.csv" hash="a2e00b30cbf4912e8548b74f099c2aca"/></dir><dir name="nl_NL"><file name="Professio_BudgetMailer.csv" hash="19bfba29f001f700b12f2b255d9f27aa"/></dir></target><target name="magelib"><dir name="BudgetMailer"><dir name="Api"><file name="Cache.php" hash="21caabe0285de4cf17e2245870448c99"/><dir name="Client"><file name="Http.php" hash="b4d578a12be45bd85d3f9f6a936f41ce"/><file name="RestJson.php" hash="b6ae5bdeb13ebb48bc006c417d935da7"/></dir><file name="Client.php" hash="5edd6731a1e7470cc53b205ace39c0e6"/><file name="Config.php" hash="ae10b8c1afbd59188829186dad894366"/></dir><file name="LICENSE" hash="da767786416c13b5a35e8603f06bada8"/></dir></target></contents>
20
  <compatible/>
21
+ <dependencies><required><php><min>5.3.0</min><max>7.0.8</max></php></required></dependencies>
22
  </package>