Mage_Laposta_Connect - Version 1.0.0

Version Notes

First release of the Laposta plugin for Magento.

Download this release

Release Info

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


Version 1.0.0

Files changed (29) hide show
  1. app/code/community/Laposta/Connect/Block/Adminhtml/System/Config/Form/Field/Mapfields.php +37 -0
  2. app/code/community/Laposta/Connect/Helper/Customer.php +327 -0
  3. app/code/community/Laposta/Connect/Helper/Data.php +78 -0
  4. app/code/community/Laposta/Connect/Helper/Fields.php +57 -0
  5. app/code/community/Laposta/Connect/Helper/Laposta.php +559 -0
  6. app/code/community/Laposta/Connect/Helper/Subscribe.php +31 -0
  7. app/code/community/Laposta/Connect/Helper/Sync.php +376 -0
  8. app/code/community/Laposta/Connect/Model/Cron.php +17 -0
  9. app/code/community/Laposta/Connect/Model/Field.php +12 -0
  10. app/code/community/Laposta/Connect/Model/List.php +12 -0
  11. app/code/community/Laposta/Connect/Model/Mysql4/Field.php +10 -0
  12. app/code/community/Laposta/Connect/Model/Mysql4/Field/Collection.php +11 -0
  13. app/code/community/Laposta/Connect/Model/Mysql4/List.php +10 -0
  14. app/code/community/Laposta/Connect/Model/Mysql4/List/Collection.php +11 -0
  15. app/code/community/Laposta/Connect/Model/Mysql4/Subscriber.php +10 -0
  16. app/code/community/Laposta/Connect/Model/Mysql4/Subscriber/Collection.php +11 -0
  17. app/code/community/Laposta/Connect/Model/Observer.php +231 -0
  18. app/code/community/Laposta/Connect/Model/Subscriber.php +11 -0
  19. app/code/community/Laposta/Connect/controllers/Adminhtml/LapostaController.php +26 -0
  20. app/code/community/Laposta/Connect/controllers/IndexController.php +11 -0
  21. app/code/community/Laposta/Connect/controllers/SubscribeAllController.php +20 -0
  22. app/code/community/Laposta/Connect/controllers/WebhookController.php +174 -0
  23. app/code/community/Laposta/Connect/etc/adminhtml.xml +42 -0
  24. app/code/community/Laposta/Connect/etc/config.xml +158 -0
  25. app/code/community/Laposta/Connect/etc/system.xml +103 -0
  26. app/code/community/Laposta/Connect/sql/connect_setup/mysql4-install-0.1.0.php +57 -0
  27. app/etc/modules/Laposta_Connect.xml +12 -0
  28. app/locale/en_US/Laposta_Connect.csv +16 -0
  29. package.xml +34 -0
app/code/community/Laposta/Connect/Block/Adminhtml/System/Config/Form/Field/Mapfields.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * System configuration form field renderer for mapping MergeVars fields with Magento
5
+ * attributes.
6
+ *
7
+ * @category Ebizmarts
8
+ * @package Ebizmarts_MageMonkey
9
+ * @author Ebizmarts Team <info@ebizmarts.com>
10
+ */
11
+ class Laposta_Connect_Block_Adminhtml_System_Config_Form_Field_Mapfields
12
+ extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
13
+ {
14
+
15
+ public function __construct()
16
+ {
17
+ $this->addColumn(
18
+ 'magento',
19
+ array(
20
+ 'label' => Mage::helper('lapostaconnect')->__('Customer'),
21
+ 'style' => 'width:120px',
22
+ )
23
+ );
24
+
25
+ $this->addColumn(
26
+ 'laposta',
27
+ array(
28
+ 'label' => Mage::helper('lapostaconnect')->__('Laposta'),
29
+ 'style' => 'width:120px',
30
+ )
31
+ );
32
+
33
+ $this->_addAfter = false;
34
+ $this->_addButtonLabel = Mage::helper('lapostaconnect')->__('Add field');
35
+ parent::__construct();
36
+ }
37
+ }
app/code/community/Laposta/Connect/Helper/Customer.php ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Laposta_Connect_Helper_Customer
5
+ *
6
+ * @property string $firstname
7
+ * @property string $lastname
8
+ * @property string $email
9
+ * @property string $password_hash
10
+ * @property string $default_billing
11
+ * @property string $default_shipping
12
+ * @property string $created_in
13
+ * @property string $store_id
14
+ * @property string $group_id
15
+ * @property string $website_id
16
+ * @property string $prefix
17
+ * @property string $middlename
18
+ * @property string $suffix
19
+ * @property string $dob
20
+ * @property string $taxvat
21
+ * @property string $confirmation
22
+ * @property string $gender
23
+ * @property string $created_at
24
+ */
25
+ class Laposta_Connect_Helper_Customer extends Mage_Core_Helper_Abstract
26
+ {
27
+ /**
28
+ * @var Mage_Customer_Model_Customer
29
+ */
30
+ protected $customer;
31
+
32
+ /**
33
+ * @var array
34
+ */
35
+ protected $methodMapGet = array(
36
+ 'billing_address' => 'getBillingAddress',
37
+ 'shipping_address' => 'getShippingAddress',
38
+ 'gender' => 'getGender',
39
+ 'date_of_purchase' => 'getLastPurchaseDate',
40
+ 'telephone' => 'getTelephone',
41
+ 'company' => 'getCompany',
42
+ 'group_name' => 'getCustomerGroupName',
43
+ );
44
+
45
+ /**
46
+ * @var array
47
+ */
48
+ protected $methodMapSet = array();
49
+
50
+ /**
51
+ * @var array
52
+ */
53
+ protected $attributeMap = array();
54
+
55
+ /**
56
+ * @return Mage_Customer_Model_Customer
57
+ */
58
+ public function getCustomer()
59
+ {
60
+ return $this->customer;
61
+ }
62
+
63
+ /**
64
+ * @param Mage_Customer_Model_Customer $customer
65
+ *
66
+ * @return $this
67
+ */
68
+ public function setCustomer(Mage_Customer_Model_Customer $customer)
69
+ {
70
+ $this->customer = $customer;
71
+
72
+ return $this;
73
+ }
74
+
75
+ /**
76
+ * Magic getter hook to get() method.
77
+ *
78
+ * @param string $name
79
+ *
80
+ * @return mixed
81
+ * @throws RuntimeException
82
+ */
83
+ public function __get($name)
84
+ {
85
+ return $this->get($name);
86
+ }
87
+
88
+ /**
89
+ * Magic setter hook to set() method.
90
+ *
91
+ * @param string $name
92
+ * @param string $value
93
+ *
94
+ * @return mixed
95
+ */
96
+ public function __set($name, $value)
97
+ {
98
+ return $this->set($name, $value);
99
+ }
100
+
101
+ /**
102
+ * Resolve a list of properties.
103
+ *
104
+ * @param array $list
105
+ *
106
+ * @return array
107
+ */
108
+ public function resolve(array $list = array())
109
+ {
110
+ $result = array();
111
+
112
+ foreach ($list as $property) {
113
+ $result[$property] = $this->get($property);
114
+ }
115
+
116
+ return $result;
117
+ }
118
+
119
+ /**
120
+ * Resolve a data value for the customer.
121
+ *
122
+ * @param string $name
123
+ *
124
+ * @return mixed
125
+ * @throws RuntimeException
126
+ */
127
+ public function get($name)
128
+ {
129
+ if (!$this->customer instanceof Mage_Customer_Model_Customer) {
130
+ throw new RuntimeException("Customer has not been set. Unable to resolve value for '$name'");
131
+ }
132
+
133
+ if (!isset($this->methodMapGet[$name])) {
134
+ return $this->getCustomerAttribute($name);
135
+ }
136
+
137
+ $method = $this->methodMapGet[$name];
138
+
139
+ return $this->$method();
140
+ }
141
+
142
+ /**
143
+ * Set a data value for the customer
144
+ *
145
+ * @param string $name
146
+ * @param mixed $value
147
+ *
148
+ * @return $this
149
+ * @throws RuntimeException
150
+ */
151
+ public function set($name, $value)
152
+ {
153
+ if (!$this->customer instanceof Mage_Customer_Model_Customer) {
154
+ throw new RuntimeException("Customer has not been set. Unable to set value for '$name'");
155
+ }
156
+
157
+ if (!isset($this->methodMapSet[$name])) {
158
+ return $this;
159
+ }
160
+
161
+ $method = $this->methodMapSet[$name];
162
+
163
+ $this->$method($value);
164
+
165
+ return $this;
166
+ }
167
+
168
+ /**
169
+ * Get a customer attribute by name
170
+ *
171
+ * @param string $name
172
+ *
173
+ * @return mixed
174
+ */
175
+ protected function getCustomerAttribute($name)
176
+ {
177
+ if (isset($this->attributeMap[$name])) {
178
+ $name = $this->attributeMap[$name];
179
+ }
180
+
181
+ $value = $this->getCustomer()->getData($name);
182
+
183
+ return $value;
184
+ }
185
+
186
+ /**
187
+ * Set a customer attribute by name
188
+ *
189
+ * @param string $name
190
+ * @param mixed $value
191
+ *
192
+ * @return $this
193
+ */
194
+ protected function setCustomerAttribute($name, $value)
195
+ {
196
+ if (isset($this->attributeMap[$name])) {
197
+ $name = $this->attributeMap[$name];
198
+ }
199
+
200
+ $this->getCustomer()->setData($name, $value);
201
+
202
+ return $this;
203
+ }
204
+
205
+ /**
206
+ * Get the billing address
207
+ *
208
+ * @return string
209
+ */
210
+ protected function getBillingAddress()
211
+ {
212
+ return $this->formatAddress($this->getCustomer()->getPrimaryBillingAddress());
213
+ }
214
+
215
+ /**
216
+ * Get the shipping address
217
+ *
218
+ * @return string
219
+ */
220
+ protected function getShippingAddress()
221
+ {
222
+ return $this->formatAddress($this->getCustomer()->getPrimaryShippingAddress());
223
+ }
224
+
225
+ /**
226
+ * Created a formatted address string
227
+ *
228
+ * @param mixed $address
229
+ *
230
+ * @return string
231
+ */
232
+ protected function formatAddress($address)
233
+ {
234
+ if (!$address instanceof Mage_Customer_Model_Address) {
235
+ return '';
236
+ }
237
+
238
+ $street = $address->getStreet(-1);
239
+ $city = $address->getData('city');
240
+ $region = $address->getRegion();
241
+ $postcode = $address->getData('postcode');
242
+ $country = $address->getCountryModel()->getName();
243
+
244
+ return trim(implode("\n", array($street, $postcode . ' ' . $city, $region, $country)));
245
+ }
246
+
247
+ /**
248
+ * Get the textual customer gender
249
+ *
250
+ * @return string
251
+ */
252
+ protected function getGender()
253
+ {
254
+ $genderId = $this->getCustomerAttribute('gender');
255
+ $gender = $this->getCustomer()->getAttribute('gender')->getSource()->getOptionText($genderId);
256
+
257
+ if ($gender === false) {
258
+ $gender = '';
259
+ }
260
+
261
+ return $gender;
262
+ }
263
+
264
+ /**
265
+ * Get the date of the customers last order
266
+ *
267
+ * @return string
268
+ */
269
+ protected function getLastPurchaseDate()
270
+ {
271
+ $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter(
272
+ 'customer_id',
273
+ $this->getCustomer()->getId()
274
+ )->addAttributeToSort('created_at', 'DESC')->setPageSize(1);
275
+
276
+ if ($orders->count() === 0) {
277
+ return '';
278
+ }
279
+
280
+ return $orders->getFirstItem()->getData('created_at');
281
+ }
282
+
283
+ /**
284
+ * Get the customer telephone number
285
+ *
286
+ * @return string
287
+ */
288
+ protected function getTelephone()
289
+ {
290
+ $address = $this->getCustomer()->getPrimaryBillingAddress();
291
+
292
+ if (!$address instanceof Mage_Customer_Model_Address) {
293
+ return '';
294
+ }
295
+
296
+ return $address->getData('telephone');
297
+ }
298
+
299
+ /**
300
+ * Get the customer company name
301
+ *
302
+ * @return string
303
+ */
304
+ protected function getCompany()
305
+ {
306
+ $address = $this->getCustomer()->getPrimaryBillingAddress();
307
+
308
+ if (!$address instanceof Mage_Customer_Model_Address) {
309
+ return '';
310
+ }
311
+
312
+ return $address->getData('company');
313
+ }
314
+
315
+ /**
316
+ * Get the name that corresponds thte customer group id.
317
+ *
318
+ * @return string
319
+ */
320
+ protected function getCustomerGroupName()
321
+ {
322
+ $groupId = $this->getCustomerAttribute('group_id');
323
+ $group = Mage::getModel('customer/group')->load($groupId);
324
+
325
+ return $group->getData('customer_group_code');
326
+ }
327
+ }
app/code/community/Laposta/Connect/Helper/Data.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Laposta_Connect_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ /**
6
+ * Utility to check if admin is logged in
7
+ *
8
+ * @return bool
9
+ */
10
+ public function isAdmin()
11
+ {
12
+ return Mage::getSingleton('admin/session')->isLoggedIn();
13
+ }
14
+
15
+ /**
16
+ * Check if Magento is EE
17
+ *
18
+ * @return bool
19
+ */
20
+ public function isEnterprise()
21
+ {
22
+ return is_object(Mage::getConfig()->getNode('global/models/enterprise_enterprise'));
23
+ }
24
+
25
+ /**
26
+ * Check if Laposta plugin is enabled
27
+ *
28
+ * @return $this
29
+ */
30
+ public function isLapostaEnabled()
31
+ {
32
+ return $this->config('enable_log') === '1';
33
+ }
34
+
35
+ /**
36
+ * Get module configuration value
37
+ *
38
+ * @param string $value
39
+ * @param string $store
40
+ *
41
+ * @return mixed Configuration setting
42
+ */
43
+ public function config($value, $store = null)
44
+ {
45
+ $store = is_null($store) ? Mage::app()->getStore() : $store;
46
+
47
+ $configscope = Mage::app()->getRequest()->getParam('store');
48
+ if ($configscope && ($configscope !== 'undefined')) {
49
+ $store = $configscope;
50
+ }
51
+
52
+ return Mage::getStoreConfig("lapostaconnect/laposta/$value", $store);
53
+ }
54
+
55
+ /**
56
+ * Logging facility
57
+ *
58
+ * @param mixed $data Message to save to file
59
+ * @param string $filename log filename, default is <Laposta.log>
60
+ *
61
+ * @return Mage_Core_Model_Log_Adapter
62
+ */
63
+ public function log($data, $filename = 'Laposta.log')
64
+ {
65
+ if ($this->config('enable_log') === '1') {
66
+ if ($data instanceof Exception) {
67
+ $data = array(
68
+ 'exception' => get_class($data),
69
+ 'message' => $data->getMessage(),
70
+ 'line' => $data->getLine(),
71
+ 'file' => $data->getFile(),
72
+ );
73
+ }
74
+
75
+ return Mage::getModel('core/log_adapter', $filename)->log($data);
76
+ }
77
+ }
78
+ }
app/code/community/Laposta/Connect/Helper/Fields.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Helper_Fields extends Mage_Core_Helper_Abstract
5
+ {
6
+ /**
7
+ * @var array
8
+ */
9
+ protected $cache = array();
10
+
11
+ /**
12
+ * @var bool
13
+ */
14
+ protected $initialized = false;
15
+
16
+ /**
17
+ * Warm up the cache for easier data retrieval
18
+ */
19
+ protected function initialize()
20
+ {
21
+ if ($this->initialized) {
22
+ return;
23
+ }
24
+
25
+ /** @var $fields Laposta_Connect_Model_Mysql4_Field_Collection */
26
+ $fields = Mage::getModel('lapostaconnect/field')->getCollection()->load();
27
+
28
+ /** @var $field Laposta_Connect_Model_Field */
29
+ foreach ($fields as $field) {
30
+ $listId = $field->getData('list_id');
31
+ $fieldName = $field->getData('field_name');
32
+ $lapostaTag = $field->getData('laposta_tag');
33
+
34
+ $this->cache[$listId][$fieldName] = $lapostaTag;
35
+ }
36
+
37
+ $this->initialized = true;
38
+ }
39
+
40
+ /**
41
+ * Retrieve a list of field_name => laposta_tag relations by listId
42
+ *
43
+ * @param int $listId
44
+ *
45
+ * @return array
46
+ */
47
+ public function getByListId($listId)
48
+ {
49
+ $this->initialize();
50
+
51
+ if (!isset($this->cache[$listId])) {
52
+ return array();
53
+ }
54
+
55
+ return $this->cache[$listId];
56
+ }
57
+ }
app/code/community/Laposta/Connect/Helper/Laposta.php ADDED
@@ -0,0 +1,559 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once Mage::getBaseDir('lib') . '/Laposta/Laposta.php';
4
+
5
+ class Laposta_Connect_Helper_Laposta extends Mage_Core_Helper_Abstract
6
+ {
7
+ const FIELD_TYPE_TEXT = 'text';
8
+
9
+ const FIELD_TYPE_NUMERIC = 'numeric';
10
+
11
+ const FIELD_TYPE_DATE = 'date';
12
+
13
+ const FIELD_TYPE_SELECT_SINGLE = 'select_single';
14
+
15
+ const FIELD_TYPE_SELECT_MULTI = 'select_multiple';
16
+
17
+ /**
18
+ * @param $apiKey
19
+ */
20
+ public function setApiToken($apiKey)
21
+ {
22
+ Laposta::setApiKey($apiKey);
23
+ }
24
+
25
+ /**
26
+ * Get all groups from the API
27
+ *
28
+ * @return array
29
+ */
30
+ public function getGroups()
31
+ {
32
+ }
33
+
34
+ /**
35
+ * Get all contacts from the API
36
+ *
37
+ * @return array
38
+ */
39
+ public function getContacts()
40
+ {
41
+ }
42
+
43
+ /**
44
+ * Add a new group
45
+ *
46
+ * @param string $title
47
+ *
48
+ * @return string
49
+ */
50
+ public function addGroup($title)
51
+ {
52
+ $list = new Laposta_List();
53
+ $result = $list->create(
54
+ array(
55
+ 'name' => $title,
56
+ )
57
+ );
58
+
59
+ $this->log(__METHOD__, $result);
60
+
61
+ return $result['list']['list_id'];
62
+ }
63
+
64
+ /**
65
+ * Add a new contact
66
+ *
67
+ * @param string $listId
68
+ * @param string $ip
69
+ * @param string $email
70
+ * @param array $fields
71
+ * @param bool $subscribed
72
+ *
73
+ * @return string
74
+ */
75
+ public function addContact($listId, $ip, $email, $fields = array(), $subscribed = false)
76
+ {
77
+ $member = new Laposta_Member($listId);
78
+ $source = Mage::getBaseUrl(
79
+ Mage_Core_Model_Store::URL_TYPE_LINK,
80
+ Mage::app()->getStore()->isCurrentlySecure()
81
+ );
82
+ $data = array(
83
+ 'ip' => $this->resolveIp($ip),
84
+ 'email' => $email,
85
+ 'source_url' => $source,
86
+ 'state' => $subscribed ? 'active' : 'unsubscribed',
87
+ 'custom_fields' => $this->denormalizeFields($listId, $fields),
88
+ );
89
+ $result = $member->create($data);
90
+
91
+ $this->log(__METHOD__, $result);
92
+
93
+ return $result['member']['member_id'];
94
+ }
95
+
96
+ /**
97
+ * Denormalize member data fields for Laposta
98
+ *
99
+ * @param string $listId
100
+ * @param array $data
101
+ *
102
+ * @return array
103
+ */
104
+ protected function denormalizeFields($listId, $data)
105
+ {
106
+ // TODO: Map customer data to laposta field tags
107
+
108
+ return $data;
109
+ }
110
+
111
+ /**
112
+ * Normalize member data fields received from Laposta
113
+ *
114
+ * @param string $listId
115
+ * @param array $data
116
+ *
117
+ * @return array
118
+ */
119
+ protected function normalizeFields($listId, $data)
120
+ {
121
+ // TODO: Map laposta field tags to customer data
122
+
123
+ return $data;
124
+ }
125
+
126
+ /**
127
+ * Resolve a valid IP address.
128
+ *
129
+ * @param string $ip
130
+ *
131
+ * @return string
132
+ */
133
+ protected function resolveIp($ip)
134
+ {
135
+ if (!empty($ip)) {
136
+ return $ip;
137
+ }
138
+
139
+ if (isset($_SERVER['REMOTE_ADDR'])) {
140
+ return $_SERVER['REMOTE_ADDR'];
141
+ }
142
+
143
+ return '127.0.0.1';
144
+ }
145
+
146
+ /**
147
+ * Update an existing contact
148
+ *
149
+ * @param string $listId
150
+ * @param string $memberId
151
+ * @param string $ip
152
+ * @param string $email
153
+ * @param array $data
154
+ * @param bool $subscribed
155
+ *
156
+ * @return $this
157
+ */
158
+ public function updateContact($listId, $memberId, $ip, $email, $data = array(), $subscribed = false)
159
+ {
160
+ $member = new Laposta_Member($listId);
161
+ $source = Mage::getBaseUrl(
162
+ Mage_Core_Model_Store::URL_TYPE_LINK,
163
+ Mage::app()->getStore()->isCurrentlySecure()
164
+ );
165
+ $data = array(
166
+ 'ip' => $this->resolveIp($ip),
167
+ 'email' => $email,
168
+ 'source_url' => $source,
169
+ 'state' => $subscribed ? 'active' : 'unsubscribed',
170
+ 'custom_fields' => $this->denormalizeFields($listId, $data),
171
+ );
172
+ $result = $member->update($memberId, $data);
173
+
174
+ $this->log(__METHOD__, $result);
175
+
176
+ return $this;
177
+ }
178
+
179
+ /**
180
+ * Modify an existing group
181
+ *
182
+ * @param string $listId
183
+ * @param string $title
184
+ *
185
+ * @return $this
186
+ */
187
+ public function updateGroup($listId, $title)
188
+ {
189
+ $list = new Laposta_List();
190
+ $result = $list->update(
191
+ $listId,
192
+ array(
193
+ 'name' => $title,
194
+ )
195
+ );
196
+
197
+ $this->log(__METHOD__, $result);
198
+
199
+ return $this;
200
+ }
201
+
202
+ /**
203
+ * Add a field to a group
204
+ *
205
+ * @param string $listId
206
+ * @param string $name
207
+ * @param string $type
208
+ * @param array $options
209
+ * @param string $defaultValue
210
+ * @param bool $required
211
+ * @param bool $showInForm
212
+ * @param bool $showInList
213
+ *
214
+ * @return string
215
+ */
216
+ public function addField(
217
+ $listId,
218
+ $name,
219
+ $type = self::FIELD_TYPE_TEXT,
220
+ $options = array(),
221
+ $defaultValue = '',
222
+ $required = false,
223
+ $showInForm = true,
224
+ $showInList = true
225
+ ) {
226
+ $lapField = new Laposta_Field($listId);
227
+ $meta = array(
228
+ 'name' => $name,
229
+ 'datatype' => $type,
230
+ 'defaultvalue' => $defaultValue,
231
+ 'required' => $required ? 'true' : 'false',
232
+ 'in_form' => $showInForm ? 'true' : 'false',
233
+ 'in_list' => $showInList ? 'true' : 'false',
234
+ );
235
+
236
+ if ($type === self::FIELD_TYPE_SELECT_MULTI || $type === self::FIELD_TYPE_SELECT_SINGLE) {
237
+ $meta['options'] = $options;
238
+ }
239
+
240
+ $result = $lapField->create($meta);
241
+
242
+ $this->log(__METHOD__, $result);
243
+
244
+ return array(
245
+ 'id' => $result['field']['field_id'],
246
+ 'tag' => $result['field']['tag'],
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Update a field on a group
252
+ *
253
+ * @param string $listId
254
+ * @param string $fieldId
255
+ * @param string $name
256
+ * @param string $type
257
+ * @param array $options
258
+ * @param string $defaultValue
259
+ * @param bool $required
260
+ * @param bool $showInForm
261
+ * @param bool $showInList
262
+ *
263
+ * @return $this
264
+ */
265
+ public function updateField(
266
+ $listId,
267
+ $fieldId,
268
+ $name,
269
+ $type = self::FIELD_TYPE_TEXT,
270
+ $options = array(),
271
+ $defaultValue = '',
272
+ $required = false,
273
+ $showInForm = true,
274
+ $showInList = true
275
+ ) {
276
+ $lapField = new Laposta_Field($listId);
277
+ $data = array(
278
+ 'name' => $name,
279
+ 'datatype' => $type,
280
+ 'defaultvalue' => $defaultValue,
281
+ 'required' => $required ? 'true' : 'false',
282
+ 'in_form' => $showInForm ? 'true' : 'false',
283
+ 'in_list' => $showInList ? 'true' : 'false',
284
+ );
285
+
286
+ if ($type === self::FIELD_TYPE_SELECT_MULTI || $type === self::FIELD_TYPE_SELECT_SINGLE) {
287
+ $data['options'] = $options;
288
+ }
289
+
290
+ $result = $lapField->update($fieldId, $data);
291
+
292
+ $this->log(__METHOD__, $result);
293
+
294
+ return $result['field']['tag'];
295
+ }
296
+
297
+ /**
298
+ * Remove a field
299
+ *
300
+ * @param string $listId
301
+ * @param string $fieldId
302
+ *
303
+ * @return $this
304
+ */
305
+ public function removeField($listId, $fieldId)
306
+ {
307
+ $lapField = new Laposta_Field($listId);
308
+ $result = $lapField->delete($fieldId);
309
+
310
+ $this->log(__METHOD__, $result);
311
+
312
+ return $this;
313
+ }
314
+
315
+ /**
316
+ * Get a single group by its identifier
317
+ *
318
+ * @param string $listId
319
+ *
320
+ * @return array
321
+ */
322
+ public function getGroup($listId)
323
+ {
324
+ $list = new Laposta_List();
325
+ $result = $list->get($listId);
326
+
327
+ $this->log(__METHOD__, $result);
328
+
329
+ return $result['list'];
330
+ }
331
+
332
+ /**
333
+ * Get a single contact by its identifier
334
+ *
335
+ * @param string $listId
336
+ * @param string $memberId
337
+ *
338
+ * @return array
339
+ */
340
+ public function getContact($listId, $memberId)
341
+ {
342
+ $member = new Laposta_Member($listId);
343
+ $result = $member->get($memberId);
344
+
345
+ $this->log(__METHOD__, $result);
346
+
347
+ return $this->normalizeContact($result);
348
+ }
349
+
350
+ /**
351
+ * Convert data from the source into a native contact object.
352
+ *
353
+ * @param array $data
354
+ *
355
+ * @return Contact
356
+ * @throws RuntimeException
357
+ */
358
+ public function normalizeContact(array $data)
359
+ {
360
+ if (!isset($data['memeber'])) {
361
+ return $data;
362
+ }
363
+
364
+ $data['member']['custom_fields'] = $this->normalizeFields(
365
+ $data['member']['list_id'],
366
+ $data['member']['custom_fields']
367
+ );
368
+
369
+ return $data;
370
+ }
371
+
372
+ /**
373
+ * Get a list of fields for the given groupId
374
+ *
375
+ * @param string $listId
376
+ *
377
+ * @return array
378
+ */
379
+ public function getFields($listId)
380
+ {
381
+ $field = new Laposta_Field($listId);
382
+ $result = $field->all();
383
+
384
+ return $result['data'];
385
+ }
386
+
387
+ /**
388
+ * Remove all lists.
389
+ *
390
+ * @param string $listId
391
+ *
392
+ * @return $this
393
+ */
394
+ public function removeLists($listId)
395
+ {
396
+ $list = new Laposta_List();
397
+ $result = $list->delete($listId);
398
+
399
+ $this->log(__METHOD__, $result);
400
+
401
+ return $this;
402
+ }
403
+
404
+ /**
405
+ * Add a webhook
406
+ *
407
+ * @param string $listId
408
+ * @param string $hookUrl
409
+ *
410
+ * @return array
411
+ */
412
+ public function addHook($listId, $hookUrl)
413
+ {
414
+ $hooks = array();
415
+ $events = array(
416
+ 'subscribed',
417
+ 'modified',
418
+ 'deactivated',
419
+ );
420
+
421
+ foreach ($events as $event) {
422
+ $hook = new Laposta_Webhook($listId);
423
+
424
+ $result = $hook->create(
425
+ array(
426
+ 'event' => $event,
427
+ 'url' => $hookUrl,
428
+ 'blocked' => 'false',
429
+ )
430
+ );
431
+
432
+ $this->log(__METHOD__, $result);
433
+
434
+ $hooks[] = $result['webhook']['webhook_id'];
435
+ }
436
+
437
+ return $hooks;
438
+ }
439
+
440
+ /**
441
+ * Remove a webhook
442
+ *
443
+ * @param string $listId
444
+ * @param string $hookId
445
+ *
446
+ * @return $this
447
+ */
448
+ public function removeHook($listId, $hookId)
449
+ {
450
+ $hook = new Laposta_Webhook($listId);
451
+ $result = $hook->delete($hookId);
452
+
453
+ $this->log(__METHOD__, $result);
454
+
455
+ return $this;
456
+ }
457
+
458
+ /**
459
+ * Get a list of all webhooks
460
+ *
461
+ * @param string $listId
462
+ * @param string $filter
463
+ *
464
+ * @return array
465
+ */
466
+ public function getHooks($listId, $filter = '')
467
+ {
468
+ $hook = new Laposta_Webhook($listId);
469
+ $result = $hook->all();
470
+
471
+ if (empty($filter)) {
472
+ return $result['data'];
473
+ }
474
+
475
+ /*
476
+ * Remove entries that don't match the filter
477
+ */
478
+ foreach ($result['data'] as $index => $data) {
479
+ if (isset($data['webhook']['url']) && strpos($data['webhook']['url'], $filter) !== false) {
480
+ continue;
481
+ }
482
+
483
+ unset($result['data'][$index]);
484
+ }
485
+
486
+ return $result['data'];
487
+ }
488
+
489
+ /**
490
+ * Disable all webhooks.
491
+ *
492
+ * @param string $listId
493
+ * @param string $filter
494
+ *
495
+ * @return $this
496
+ */
497
+ public function disableHooks($listId, $filter = '')
498
+ {
499
+ $hooks = $this->getHooks($listId, $filter);
500
+ $hook = new Laposta_Webhook($listId);
501
+
502
+ foreach ($hooks as $data) {
503
+ $result = $hook->update(
504
+ $data['webhook']['webhook_id'],
505
+ array('blocked' => 'true')
506
+ );
507
+
508
+ $this->log(__METHOD__, $result);
509
+ }
510
+
511
+ return $this;
512
+ }
513
+
514
+ /**
515
+ * Re-enable all webhooks.
516
+ *
517
+ * @param string $listId
518
+ * @param string $filter
519
+ *
520
+ * @return $this
521
+ */
522
+ public function enableHooks($listId, $filter = '')
523
+ {
524
+ $hooks = $this->getHooks($listId, $filter);
525
+ $hook = new Laposta_Webhook($listId);
526
+
527
+ foreach ($hooks as $data) {
528
+ $result = $hook->update(
529
+ $data['webhook']['webhook_id'],
530
+ array('blocked' => 'false')
531
+ );
532
+
533
+ $this->log(__METHOD__, $result);
534
+ }
535
+
536
+ return $this;
537
+ }
538
+
539
+ protected function log($method, $result = array())
540
+ {
541
+ Mage::helper('lapostaconnect')->log(
542
+ array(
543
+ 'method' => $method,
544
+ 'result' => $result,
545
+ )
546
+ );
547
+ }
548
+
549
+ /**
550
+ * Remove a contact
551
+ *
552
+ * @param $listId
553
+ * @param $memberId
554
+ */
555
+ public function removeContact($listId, $memberId)
556
+ {
557
+
558
+ }
559
+ }
app/code/community/Laposta/Connect/Helper/Subscribe.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Laposta_Connect_Helper_Subscribe extends Mage_Core_Helper_Abstract
4
+ {
5
+ public function refreshSubscriberList($listId)
6
+ {
7
+ /** @var $customerCollection Mage_Customer_Model_Entity_Customer_Collection */
8
+ $customerCollection = Mage::getModel('customer/customer')->getCollection();
9
+
10
+ /** @var $subscriberCollection Laposta_Connect_Model_Mysql4_Subscriber_Collection */
11
+ $subscriberCollection = Mage::getModel('lapostaconnect/subscriber')->getCollection();
12
+
13
+ $subscribed = array_flip($subscriberCollection->getColumnValues('customer_id'));
14
+
15
+ /** @var $customer Mage_Customer_Model_Entity_Customer */
16
+ foreach ($customerCollection as $customer) {
17
+ $customerId = $customer->getEntityId();
18
+
19
+ if (isset($subscribed[$customerId])) {
20
+ continue;
21
+ }
22
+
23
+ $subscriber = $subscriberCollection->getNewEmptyItem();
24
+ $subscriber->setListId($listId);
25
+ $subscriber->setCustomerId($customerId);
26
+ $subscriber->setUpdatedTime($subscriberCollection->formatDate(time()));
27
+
28
+ $subscriber->save();
29
+ }
30
+ }
31
+ }
app/code/community/Laposta/Connect/Helper/Sync.php ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Laposta_Connect_Helper_Sync extends Mage_Core_Helper_Abstract
4
+ {
5
+ /**
6
+ * @var array array(
7
+ * 'type' => Laposta_Connect_Helper_Laposta::FIELD_TYPE_TEXT,
8
+ * 'options' => array(),
9
+ * 'default' => '',
10
+ * 'required' => false,
11
+ * 'showInForm' => false,
12
+ * 'showInList' => true,
13
+ * )
14
+ */
15
+ protected $fieldConfigMap = array(
16
+ 'dob' => array(
17
+ 'type' => Laposta_Connect_Helper_Laposta::FIELD_TYPE_DATE,
18
+ ),
19
+ 'gender' => array(
20
+ 'type' => Laposta_Connect_Helper_Laposta::FIELD_TYPE_SELECT_SINGLE,
21
+ 'options' => array('', 'Male', 'Female'),
22
+ ),
23
+ 'store_id' => array(
24
+ 'type' => Laposta_Connect_Helper_Laposta::FIELD_TYPE_NUMERIC,
25
+ ),
26
+ 'website_id' => array(
27
+ 'type' => Laposta_Connect_Helper_Laposta::FIELD_TYPE_NUMERIC,
28
+ ),
29
+ 'date_of_purchase' => array(
30
+ 'type' => Laposta_Connect_Helper_Laposta::FIELD_TYPE_DATE,
31
+ ),
32
+ 'group_id' => array(
33
+ 'type' => Laposta_Connect_Helper_Laposta::FIELD_TYPE_NUMERIC,
34
+ ),
35
+ );
36
+
37
+ /**
38
+ * @var array
39
+ */
40
+ protected $defaultFieldConfig = array(
41
+ 'type' => Laposta_Connect_Helper_Laposta::FIELD_TYPE_TEXT,
42
+ 'options' => array(),
43
+ 'default' => '',
44
+ 'required' => false,
45
+ 'showInForm' => false,
46
+ 'showInList' => true,
47
+ );
48
+
49
+ /**
50
+ * @return string
51
+ */
52
+ protected function resolveApiKey()
53
+ {
54
+ return Mage::helper('lapostaconnect')->config('api_key');
55
+ }
56
+
57
+ /**
58
+ * Sync the list configuration with Laposta
59
+ *
60
+ * @param Laposta_Connect_Model_List $list
61
+ *
62
+ * @return $this
63
+ */
64
+ public function syncList(Laposta_Connect_Model_List $list)
65
+ {
66
+ if (Mage::helper('lapostaconnect')->config('active') !== '1') {
67
+ return $this;
68
+ }
69
+
70
+ if (strtotime($list->getUpdatedTime()) <= strtotime($list->getSyncTime())) {
71
+ return $this;
72
+ }
73
+
74
+ /** @var $laposta Laposta_Connect_Helper_Laposta */
75
+ $laposta = Mage::helper('lapostaconnect/laposta');
76
+ $laposta->setApiToken($this->resolveApiKey());
77
+
78
+ $lapostaId = $list->getLapostaId();
79
+ $listName = $list->getListName();
80
+
81
+ if (empty($listName)) {
82
+ $listName = '(Empty List Name - Magento)';
83
+
84
+ $list->setListName($listName);
85
+ }
86
+
87
+ if (empty($lapostaId)) {
88
+ $lapostaId = $laposta->addGroup($listName);
89
+
90
+ $list->setLapostaId($lapostaId);
91
+ }
92
+ else {
93
+ $laposta->updateGroup($lapostaId, $listName);
94
+ }
95
+
96
+ $this->resetWebhooks($list);
97
+
98
+ $list->setSyncTime(Mage::getModel('lapostaconnect/list')->getCollection()->formatDate(time()));
99
+
100
+ return $this;
101
+ }
102
+
103
+ /**
104
+ * Reset the webhooks with a new token
105
+ *
106
+ * @param Laposta_Connect_Model_List $list
107
+ *
108
+ * @return $this
109
+ */
110
+ protected function resetWebhooks(Laposta_Connect_Model_List $list)
111
+ {
112
+ /** @var $laposta Laposta_Connect_Helper_Laposta */
113
+ $laposta = Mage::helper('lapostaconnect/laposta');
114
+ $laposta->setApiToken($this->resolveApiKey());
115
+
116
+ $lapostaListId = $list->getLapostaId();
117
+ $current = $laposta->getHooks($lapostaListId, Mage::getBaseUrl());
118
+ $token = $list->getData('webhook_token');
119
+
120
+ if (empty($token)) {
121
+ $token = base_convert(rand(PHP_INT_MAX / 3, PHP_INT_MAX), 10, 36);
122
+ }
123
+
124
+ $hookUrl = Mage::getBaseUrl() . 'lapostaconnect/webhook?t=' . $token;
125
+
126
+ foreach ($current as $hookData) {
127
+ if (!isset($hookData['webhook']['webhook_id'])) {
128
+ continue;
129
+ }
130
+
131
+ $laposta->removeHook($lapostaListId, $hookData['webhook']['webhook_id']);
132
+ }
133
+
134
+ $laposta->addHook($lapostaListId, $hookUrl);
135
+
136
+ $list->setWebhookToken($token);
137
+
138
+ return $this;
139
+ }
140
+
141
+ /**
142
+ * Sync fields with laposta
143
+ *
144
+ * @param Laposta_Connect_Model_List $list
145
+ * @param Laposta_Connect_Model_Mysql4_Field_Collection $fields
146
+ *
147
+ * @return $this
148
+ */
149
+ public function syncFields(
150
+ Laposta_Connect_Model_List $list,
151
+ Laposta_Connect_Model_Mysql4_Field_Collection $fields
152
+ ) {
153
+ if (Mage::helper('lapostaconnect')->config('active') !== '1') {
154
+ return $this;
155
+ }
156
+
157
+ $lapostaListId = $list->getLapostaId();
158
+
159
+ if (empty($lapostaListId) || $fields->count() === 0) {
160
+ return $this;
161
+ }
162
+
163
+ /** @var $laposta Laposta_Connect_Helper_Laposta */
164
+ $laposta = Mage::helper('lapostaconnect/laposta');
165
+ $laposta->setApiToken($this->resolveApiKey());
166
+
167
+ $current = $this->resolveCurrentFields($lapostaListId);
168
+ $synchronised = array();
169
+
170
+ /** @var $field Laposta_Connect_Model_Field */
171
+ foreach ($fields as $field) {
172
+ $lapostaFieldId = $field->getLapostaId();
173
+ $synchronised[] = $lapostaFieldId;
174
+
175
+ if (!empty($lapostaFieldId) && strtotime($field->getUpdatedTime()) <= strtotime($field->getSyncTime())
176
+ ) {
177
+ continue;
178
+ }
179
+
180
+ $fieldName = $field->getFieldName();
181
+ $fieldConfig = $this->resolveFieldConfig($fieldName);
182
+ $fieldRelation = $field->getFieldRelation();
183
+
184
+ // TODO: Use field type and field options resolver
185
+ if (empty($lapostaFieldId)) {
186
+ $result = $laposta->addField(
187
+ $lapostaListId,
188
+ $fieldRelation,
189
+ $fieldConfig['type'],
190
+ $fieldConfig['options'],
191
+ $fieldConfig['default'],
192
+ $fieldConfig['required'],
193
+ $fieldConfig['showInForm'],
194
+ $fieldConfig['showInList']
195
+ );
196
+
197
+ $lapostaFieldId = $result['id'];
198
+ $lapostaFieldTag = $result['tag'];
199
+
200
+ $field->setLapostaId($lapostaFieldId);
201
+ }
202
+ else {
203
+ $lapostaFieldTag = $laposta->updateField(
204
+ $lapostaListId,
205
+ $lapostaFieldId,
206
+ $fieldRelation,
207
+ $fieldConfig['type'],
208
+ $fieldConfig['options'],
209
+ $fieldConfig['default'],
210
+ $fieldConfig['required'],
211
+ $fieldConfig['showInForm'],
212
+ $fieldConfig['showInList']
213
+ );
214
+ }
215
+
216
+ $field->setLapostaTag(trim($lapostaFieldTag, '{}'));
217
+ $field->setSyncTime($fields->formatDate(time()));
218
+ }
219
+
220
+ $remove = array_diff($current, $synchronised);
221
+
222
+ foreach ($remove as $lapostaFieldId) {
223
+ $laposta->removeField($lapostaListId, $lapostaFieldId);
224
+ }
225
+
226
+ return $this;
227
+ }
228
+
229
+ /**
230
+ * Resolve the field configuration
231
+ *
232
+ * @param string $fieldName
233
+ *
234
+ * @return array
235
+ */
236
+ protected function resolveFieldConfig($fieldName)
237
+ {
238
+ $result = $this->defaultFieldConfig;
239
+
240
+ if (isset($this->fieldConfigMap[$fieldName])) {
241
+ $result = array_replace($result, $this->fieldConfigMap[$fieldName]);
242
+ }
243
+
244
+ return $result;
245
+ }
246
+
247
+ /**
248
+ * Get the list of fields registered with Laposta for the given list id.
249
+ *
250
+ * @param string $lapostaListId
251
+ *
252
+ * @return array
253
+ */
254
+ protected function resolveCurrentFields($lapostaListId)
255
+ {
256
+ /** @var $laposta Laposta_Connect_Helper_Laposta */
257
+ $laposta = Mage::helper('lapostaconnect/laposta');
258
+ $laposta->setApiToken($this->resolveApiKey());
259
+
260
+ $current = $laposta->getFields($lapostaListId);
261
+
262
+ if (empty($current) || !is_array($current)) {
263
+ return array();
264
+ }
265
+
266
+ $result = array();
267
+
268
+ foreach ($current as $field) {
269
+ if (!isset($field['field']['field_id'])) {
270
+ continue;
271
+ }
272
+
273
+ $result[] = $field['field']['field_id'];
274
+ }
275
+
276
+ return $result;
277
+ }
278
+
279
+ /**
280
+ * Synchronise the subscribers
281
+ *
282
+ * @param Laposta_Connect_Model_Mysql4_Subscriber_Collection $subscribers
283
+ *
284
+ * @return $this
285
+ */
286
+ public function syncSubscribers(
287
+ Laposta_Connect_Model_Mysql4_Subscriber_Collection $subscribers
288
+ ) {
289
+ if (Mage::helper('lapostaconnect')->config('active') !== '1') {
290
+ return $this;
291
+ }
292
+
293
+ /** @var $laposta Laposta_Connect_Helper_Laposta */
294
+ $laposta = Mage::helper('lapostaconnect/laposta');
295
+ $laposta->setApiToken($this->resolveApiKey());
296
+
297
+ /** @var $lists Laposta_Connect_Model_Mysql4_List_Collection */
298
+ $lists = Mage::getModel('lapostaconnect/list')->getCollection();
299
+ $listIdMap = array_combine(
300
+ $lists->getColumnValues('list_id'),
301
+ $lists->getColumnValues('laposta_id')
302
+ );
303
+
304
+ foreach ($listIdMap as $lapostaListId) {
305
+ $laposta->disableHooks($lapostaListId, Mage::getBaseUrl());
306
+ }
307
+
308
+ /** @var $fieldsHelper Laposta_Connect_Helper_Fields */
309
+ $fieldsHelper = Mage::helper('lapostaconnect/Fields');
310
+
311
+ /** @var $newsletterSubscribers Mage_Newsletter_Model_Mysql4_Subscriber_Collection */
312
+ $newsletterSubscribers = Mage::getModel('newsletter/subscriber')->getCollection();
313
+
314
+ /** @var $subscriber Laposta_Connect_Model_Subscriber */
315
+ foreach ($subscribers as $subscriber) {
316
+ $customerId = $subscriber->getCustomerId();
317
+ $lapostaMemberId = $subscriber->getLapostaId();
318
+ $lapostaListId = $listIdMap[$subscriber->getListId()];
319
+
320
+ if (empty($customerId) && empty($lapostaMemberId)) {
321
+ $subscriber->delete($subscriber);
322
+
323
+ continue;
324
+ }
325
+
326
+ if (empty($customerId)) {
327
+ $laposta->removeContact($lapostaListId, $lapostaMemberId);
328
+ }
329
+ else {
330
+ /** @var $customer Mage_Customer_Model_Customer */
331
+ $customer = Mage::getModel('customer/customer')->load($customerId);
332
+ /** @var $customerHelper Laposta_Connect_Helper_Customer */
333
+ $customerHelper = Mage::helper('lapostaconnect/customer');
334
+ $customerHelper->setCustomer($customer);
335
+
336
+ $fields = $fieldsHelper->getByListId($subscriber->getListId());
337
+ $data = array_combine(
338
+ array_values($fields),
339
+ array_values($customerHelper->resolve(array_keys($fields)))
340
+ );
341
+
342
+ $newsletter = $newsletterSubscribers->getItemByColumnValue('customer_id', $customerId);
343
+ $subscribed = false;
344
+
345
+ if ($newsletter instanceof Mage_Newsletter_Model_Subscriber) {
346
+ $status = $newsletter->getData('subscriber_status');
347
+ $statusWhiteList = array(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
348
+
349
+ if (Mage::helper('lapostaconnect')->config('subscribe_unconfirmed') === '1') {
350
+ $statusWhiteList[] = Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED;
351
+ }
352
+
353
+ $subscribed = in_array($status, $statusWhiteList) ? true : false;
354
+ }
355
+
356
+ if (empty($lapostaMemberId)) {
357
+ $lapostaId = $laposta->addContact($lapostaListId, '', $customer->getEmail(), $data, $subscribed);
358
+
359
+ $subscriber->setData('laposta_id', $lapostaId);
360
+ }
361
+ else {
362
+ $laposta->updateContact($lapostaListId, $lapostaMemberId, '', $customer->getEmail(), $data, $subscribed);
363
+ }
364
+
365
+ $subscriber->setSyncTime($subscribers->formatDate(time()));
366
+ $subscriber->save();
367
+ }
368
+ }
369
+
370
+ foreach ($listIdMap as $lapostaListId) {
371
+ $laposta->enableHooks($lapostaListId, Mage::getBaseUrl());
372
+ }
373
+
374
+ return $this;
375
+ }
376
+ }
app/code/community/Laposta/Connect/Model/Cron.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_Cron
5
+ {
6
+ /**
7
+ *
8
+ */
9
+ public static function export()
10
+ {
11
+ /** @var $subscribers Laposta_Connect_Model_Mysql4_Subscriber_Collection */
12
+ $subscribers = Mage::getModel('lapostaconnect/subscriber')->getCollection();
13
+ // $subscribers->getSelect()->where('`updated_time` > `sync_time`')->orWhere('`sync_time` IS NULL');
14
+
15
+ Mage::helper('lapostaconnect/sync')->syncSubscribers($subscribers);
16
+ }
17
+ }
app/code/community/Laposta/Connect/Model/Field.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_Field extends Mage_Core_Model_Abstract
5
+ {
6
+ public function _construct()
7
+ {
8
+ parent::_construct();
9
+
10
+ $this->_init('lapostaconnect/field');
11
+ }
12
+ }
app/code/community/Laposta/Connect/Model/List.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_List extends Mage_Core_Model_Abstract
5
+ {
6
+ public function _construct()
7
+ {
8
+ parent::_construct();
9
+
10
+ $this->_init('lapostaconnect/list');
11
+ }
12
+ }
app/code/community/Laposta/Connect/Model/Mysql4/Field.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_Mysql4_Field extends Mage_Core_Model_Mysql4_Abstract
5
+ {
6
+ public function _construct()
7
+ {
8
+ $this->_init('lapostaconnect/field', 'field_id');
9
+ }
10
+ }
app/code/community/Laposta/Connect/Model/Mysql4/Field/Collection.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_Mysql4_Field_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
5
+ {
6
+ public function _construct()
7
+ {
8
+ //parent::_construct():
9
+ $this->_init('lapostaconnect/field');
10
+ }
11
+ }
app/code/community/Laposta/Connect/Model/Mysql4/List.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_Mysql4_List extends Mage_Core_Model_Mysql4_Abstract
5
+ {
6
+ public function _construct()
7
+ {
8
+ $this->_init('lapostaconnect/list', 'list_id');
9
+ }
10
+ }
app/code/community/Laposta/Connect/Model/Mysql4/List/Collection.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_Mysql4_List_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
5
+ {
6
+ public function _construct()
7
+ {
8
+ //parent::_construct():
9
+ $this->_init('lapostaconnect/list');
10
+ }
11
+ }
app/code/community/Laposta/Connect/Model/Mysql4/Subscriber.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_Mysql4_Subscriber extends Mage_Core_Model_Mysql4_Abstract
5
+ {
6
+ public function _construct()
7
+ {
8
+ $this->_init('lapostaconnect/subscriber', 'subscriber_id');
9
+ }
10
+ }
app/code/community/Laposta/Connect/Model/Mysql4/Subscriber/Collection.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_Model_Mysql4_Subscriber_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
5
+ {
6
+ public function _construct()
7
+ {
8
+ //parent::_construct():
9
+ $this->_init('lapostaconnect/subscriber');
10
+ }
11
+ }
app/code/community/Laposta/Connect/Model/Observer.php ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Events Observer model
5
+ *
6
+ * @category Laposta
7
+ * @package Laposta_Connect
8
+ */
9
+ class Laposta_Connect_Model_Observer
10
+ {
11
+ /**
12
+ * Handle subscribe event
13
+ *
14
+ * @param Varien_Event_Observer $observer
15
+ *
16
+ * @return void
17
+ */
18
+ public function handleCustomerSave(Varien_Event_Observer $observer)
19
+ {
20
+ $customer = $observer->getEvent()->getCustomer();
21
+
22
+ if (!$customer instanceof Mage_Customer_Model_Customer) {
23
+ return;
24
+ }
25
+
26
+ /** @var $collection Laposta_Connect_Model_Mysql4_Subscriber_Collection */
27
+ $collection = Mage::getModel('lapostaconnect/subscriber')->getCollection();
28
+ $subscriber = $collection->getItemByColumnValue('customer_id', $customer->getId());
29
+
30
+ if (!$subscriber instanceof Laposta_Connect_Model_Subscriber) {
31
+ /** @var $lists Laposta_Connect_Model_Mysql4_List_Collection */
32
+ $lists = Mage::getModel('lapostaconnect/list')->getCollection();
33
+ /** @var $list Laposta_Connect_Model_List */
34
+ $list = $lists->setOrder('list_id')->getFirstItem();
35
+
36
+ if (!$list instanceof Laposta_Connect_Model_List) {
37
+ return;
38
+ }
39
+
40
+ $subscriber = $collection->getNewEmptyItem();
41
+ $subscriber->setListId($list->getListId());
42
+ $subscriber->setCustomerId($customer->getEntityId());
43
+ }
44
+
45
+ if ($subscriber->getData('customer_id') != '') {
46
+ $subscriber->setUpdatedTime($collection->formatDate(time()));
47
+ $subscriber->save();
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Handle subscribe event
53
+ *
54
+ * @param Varien_Event_Observer $observer
55
+ *
56
+ * @return void
57
+ */
58
+ public function handleCustomerDelete(Varien_Event_Observer $observer)
59
+ {
60
+ $customer = $observer->getEvent()->getCustomer();
61
+
62
+ if (!$customer instanceof Mage_Customer_Model_Customer) {
63
+ return;
64
+ }
65
+
66
+ /** @var $collection Laposta_Connect_Model_Mysql4_Subscriber_Collection */
67
+ $collection = Mage::getModel('lapostaconnect/subscriber')->getCollection();
68
+ $subscriber = $collection->getItemsByColumnValue('customer_id', $customer->getEntityId());
69
+
70
+ if (!$subscriber instanceof Laposta_Connect_Model_Subscriber || $subscriber->isEmpty()) {
71
+ return;
72
+ }
73
+
74
+ $subscriber->setCustomerId('');
75
+ $subscriber->setUpdatedTime($collection->formatDate(time()));
76
+ $subscriber->save();
77
+ }
78
+
79
+ /**
80
+ * Handle subscribe event
81
+ *
82
+ * @param Varien_Event_Observer $observer
83
+ *
84
+ * @return void
85
+ */
86
+ public function handleSaveConfig(Varien_Event_Observer $observer)
87
+ {
88
+ $list = $this->handleSaveListConfig();
89
+
90
+ if (!$list instanceof Laposta_Connect_Model_List) {
91
+ return;
92
+ }
93
+
94
+ $this->handleSaveFieldsConfig($list);
95
+ }
96
+
97
+ /**
98
+ * Store and sync the list configuration
99
+ *
100
+ * @return Laposta_Connect_Model_List|null
101
+ */
102
+ protected function handleSaveListConfig()
103
+ {
104
+ $listName = Mage::helper('lapostaconnect')->config('list_name');
105
+ $subscribeCustomers = false;
106
+
107
+ /** @var $lists Laposta_Connect_Model_Mysql4_List_Collection */
108
+ $lists = Mage::getModel('lapostaconnect/list')->getCollection();
109
+ /** @var $list Laposta_Connect_Model_List */
110
+ $list = $lists->setOrder('list_id')->getFirstItem();
111
+
112
+ if (!$list instanceof Laposta_Connect_Model_List) {
113
+ $list = $lists->getNewEmptyItem();
114
+ $subscribeCustomers = true;
115
+
116
+ $lists->addItem($list);
117
+ }
118
+
119
+ $list->setListName($listName);
120
+ $list->setUpdatedTime($lists->formatDate(time()));
121
+
122
+ /*
123
+ * Save here to ensure list_id is generated for new list entries
124
+ */
125
+ $list->save();
126
+
127
+ try {
128
+ /** @var $syncHelper Laposta_Connect_Helper_Sync */
129
+ $syncHelper = Mage::helper('lapostaconnect/sync');
130
+ $syncHelper->syncList($list);
131
+ }
132
+ catch (Exception $e) {
133
+ Mage::helper('lapostaconnect')->log($e);
134
+ }
135
+
136
+ $list->save();
137
+
138
+ if ($subscribeCustomers) {
139
+ Mage::helper('lapostaconnect/subscribe')->refreshSubscriberList($list->getListId());
140
+ }
141
+
142
+ return $list;
143
+ }
144
+
145
+ /**
146
+ * Store and sync field mappings
147
+ *
148
+ * @param Laposta_Connect_Model_List $list
149
+ *
150
+ * @return void
151
+ */
152
+ protected function handleSaveFieldsConfig(
153
+ Laposta_Connect_Model_List $list
154
+ ) {
155
+ $fieldsMap = $this->resolveFieldsMap();
156
+ $added = array();
157
+ $updated = array();
158
+ $removed = array();
159
+ $skipped = array();
160
+ /** @var $fields Laposta_Connect_Model_Mysql4_Field_Collection */
161
+ $fields = Mage::getModel('lapostaconnect/field')->getCollection();
162
+
163
+ $fields->addFilter('list_id', $list->getListId());
164
+
165
+ /** @var $field Laposta_Connect_Model_Field */
166
+ foreach ($fields as $key => $field) {
167
+ $fieldName = $field->getFieldName();
168
+
169
+ if (!isset($fieldsMap[$fieldName])) {
170
+ $removed[$fieldName] = $field;
171
+ $fields->removeItemByKey($key);
172
+ $field->delete();
173
+
174
+ continue;
175
+ }
176
+
177
+ $field->setFieldRelation($fieldsMap[$fieldName]);
178
+ $field->setUpdatedTime($fields->formatDate(time()));
179
+ $updated[$fieldName] = $field;
180
+ }
181
+
182
+ $fieldsMap = array_diff_key($fieldsMap, $updated, $removed, $skipped);
183
+
184
+ /**
185
+ * Add the remaining entries in fieldsMap
186
+ */
187
+ foreach ($fieldsMap as $fieldName => $fieldRelation) {
188
+ $field = $fields->getNewEmptyItem();
189
+ $field->setListId($list->getListId());
190
+ $field->setFieldName($fieldName);
191
+ $field->setFieldRelation($fieldRelation);
192
+ $field->setUpdatedTime($fields->formatDate(time()));
193
+
194
+ $fields->addItem($field);
195
+ $added[$fieldName] = $field;
196
+ }
197
+
198
+ try {
199
+ /** @var $syncHelper Laposta_Connect_Helper_Sync */
200
+ $syncHelper = Mage::helper('lapostaconnect/sync');
201
+ $syncHelper->syncFields($list, $fields);
202
+ }
203
+ catch (Exception $e) {
204
+ Mage::helper('lapostaconnect')->log($e);
205
+ }
206
+
207
+ $fields->save();
208
+ }
209
+
210
+ /**
211
+ * Resolve the fields map
212
+ *
213
+ * @return array
214
+ */
215
+ protected function resolveFieldsMap()
216
+ {
217
+ $list = unserialize(Mage::helper('lapostaconnect')->config('map_fields'));
218
+
219
+ if ($list === false) {
220
+ return array();
221
+ }
222
+
223
+ $result = array();
224
+
225
+ foreach ($list as $mapping) {
226
+ $result[$mapping['magento']] = $mapping['laposta'];
227
+ }
228
+
229
+ return $result;
230
+ }
231
+ }
app/code/community/Laposta/Connect/Model/Subscriber.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Laposta_Connect_Model_Subscriber extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+
9
+ $this->_init('lapostaconnect/subscriber');
10
+ }
11
+ }
app/code/community/Laposta/Connect/controllers/Adminhtml/LapostaController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Laposta_Connect_Adminhtml_LapostaController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * Initialize action
7
+ *
8
+ * @return Mage_Adminhtml_Controller_Action
9
+ */
10
+ protected function _initAction()
11
+ {
12
+ $this->_title($this->__('Newsletter'))
13
+ ->_title($this->__('Laposta'));
14
+
15
+ $this->loadLayout();
16
+ $this->_setActiveMenu('newsletter/lapostaconnect');
17
+
18
+ return $this;
19
+ }
20
+
21
+ public function indexAction()
22
+ {
23
+ $this->loadLayout();
24
+ $this->renderLayout();
25
+ }
26
+ }
app/code/community/Laposta/Connect/controllers/IndexController.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Laposta_Connect_IndexController extends Mage_Core_Controller_Front_Action
5
+ {
6
+ public function indexAction()
7
+ {
8
+ $this->loadLayout();
9
+ $this->renderLayout();
10
+ }
11
+ }
app/code/community/Laposta/Connect/controllers/SubscribeAllController.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Laposta webhooks controller
5
+ *
6
+ * @category Laposta
7
+ * @package Laposta_Connect
8
+ */
9
+ class Laposta_Connect_SubscribeAllController extends Mage_Core_Controller_Front_Action
10
+ {
11
+
12
+ /**
13
+ * Entry point for all webhook operations
14
+ */
15
+ public function indexAction()
16
+ {
17
+ Laposta_Connect_Model_Cron::export();
18
+ }
19
+
20
+ }
app/code/community/Laposta/Connect/controllers/WebhookController.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Laposta webhooks controller
5
+ *
6
+ * @category Laposta
7
+ * @package Laposta_Connect
8
+ */
9
+ class Laposta_Connect_WebhookController extends Mage_Core_Controller_Front_Action
10
+ {
11
+
12
+ /**
13
+ * Entry point for all webhook operations
14
+ */
15
+ public function indexAction()
16
+ {
17
+ $listToken = Mage::app()->getRequest()->getParam('t');
18
+ $data = $this->getInputStream();
19
+
20
+ $this->consumeEvents($listToken, $data);
21
+ }
22
+
23
+ /**
24
+ * Consume the given events to update contacts in google.
25
+ *
26
+ * @param string $listToken
27
+ * @param string $eventsJson
28
+ *
29
+ * @throws \RuntimeException
30
+ * @throws \Exception
31
+ * @return $this
32
+ */
33
+ public function consumeEvents($listToken, $eventsJson)
34
+ {
35
+ $listToken = filter_var($listToken, FILTER_SANITIZE_STRING);
36
+ $decoded = json_decode($eventsJson, true);
37
+
38
+ /** @var $lists Laposta_Connect_Model_Mysql4_List_Collection */
39
+ $lists = Mage::getModel('lapostaconnect/list')->getCollection();
40
+ /** @var $list Laposta_Connect_Model_List */
41
+ $list = $lists->getItemsByColumnValue('webhook_token', $listToken);
42
+
43
+ if (!$list instanceof Laposta_Connect_Model_List) {
44
+ return $this->log("Unable to consume events. '$listToken' is not a valid webhook token.");
45
+ }
46
+
47
+ $this->log("Consuming events for client '$listToken'", $eventsJson);
48
+
49
+ if ($decoded === false) {
50
+ return $this->log("Events data could not be parsed. Input is not valid JSON.");
51
+ }
52
+
53
+ if (!isset($decoded['data']) || !is_array($decoded['data'])) {
54
+ return $this;
55
+ }
56
+
57
+ foreach ($decoded['data'] as $event) {
58
+ try {
59
+ $this->consumeEvent($event, $list);
60
+ }
61
+ catch (Exception $e) {
62
+ $this->log("{$e->getMessage()} on line '{$e->getLine()}' of '{$e->getFile()}'");
63
+ }
64
+ }
65
+
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * Retrieve date from the input stream
71
+ *
72
+ * @return mixed
73
+ * @throws InvalidArgumentException
74
+ */
75
+ public function getInputStream()
76
+ {
77
+ $source = @fopen('php://input', 'r');
78
+
79
+ if (!is_resource($source)) {
80
+ throw new InvalidArgumentException('Expected parameter 1 to be an open-able resource');
81
+ }
82
+
83
+ $data = null;
84
+
85
+ while ($buffer = fread($source, 1024)) {
86
+ $data .= $buffer;
87
+ }
88
+
89
+ fclose($source);
90
+
91
+ return $data;
92
+ }
93
+
94
+ /**
95
+ * Submit a log entry
96
+ *
97
+ * @param string $message
98
+ * @param mixed $data
99
+ *
100
+ * @return $this
101
+ */
102
+ protected function log($message, $data = null)
103
+ {
104
+ var_dump($message, $data);
105
+
106
+ Mage::helper('lapostaconnect')->log(
107
+ array(
108
+ 'message' => $message,
109
+ 'data' => $data,
110
+ )
111
+ );
112
+
113
+ return $this;
114
+ }
115
+
116
+ /**
117
+ * Consume an event from Laposta
118
+ *
119
+ * @param array $event
120
+ * @param Laposta_Connect_Model_List $list
121
+ *
122
+ * @return $this
123
+ */
124
+ protected function consumeEvent($event, Laposta_Connect_Model_List $list)
125
+ {
126
+ if (empty($event['type']) || $event['type'] !== 'member' || !isset($event['data'])) {
127
+ return $this;
128
+ }
129
+ if (!isset($event['data']['list_id']) || !isset($event['data']['member_id'])) {
130
+ return $this;
131
+ }
132
+
133
+ $listId = $event['data']['list_id'];
134
+ $memberId = $event['data']['member_id'];
135
+ $status = isset($event['data']['state']) ? $event['data']['state'] : 'cleaned';
136
+
137
+ if ($list->getData('laposta_id') !== $listId) {
138
+ return $this->log("Resolved list id '{$list->getData('laposta_id')}' does not match provided list id '$listId'.");
139
+ }
140
+
141
+ /** @var $subscribers Laposta_Connect_Model_Mysql4_Subscriber_Collection */
142
+ $subscribers = Mage::getModel('lapostaconnect/subscriber')->getCollection();
143
+ /** @var $subscriber Laposta_Connect_Model_Subscriber */
144
+ $subscriber = $subscribers->getItemByColumnValue('laposta_id', $memberId);
145
+
146
+ if (!$subscriber instanceof Laposta_Connect_Model_Subscriber) {
147
+ return $this->log("Subscriber for laposta id '$memberId' not found.");
148
+ }
149
+
150
+ /** @var $customer Mage_Customer_Model_Customer */
151
+ $customer = Mage::getModel('customer/customer')->load($subscriber->getData('customer_id'));
152
+
153
+ if (!$customer instanceof Mage_Customer_Model_Customer) {
154
+ return $this->log("Customer for subscriber with laposta id '$memberId' not found.");
155
+ }
156
+
157
+ /** @var $newsletterSubscriberModel Mage_Newsletter_Model_Subscriber */
158
+ $newsletterSubscriberModel = Mage::getModel('newsletter/subscriber');
159
+ /** @var $newsletterSubscriber Mage_Newsletter_Model_Subscriber */
160
+ $newsletterSubscriber = $newsletterSubscriberModel->loadByCustomer($customer);
161
+
162
+ var_dump($newsletterSubscriber);
163
+
164
+ if ($status !== 'active') {
165
+ $newsletterSubscriber->unsubscribe();
166
+
167
+ return $this;
168
+ }
169
+
170
+ $newsletterSubscriber->subscribeCustomer($customer);
171
+
172
+ return $this;
173
+ }
174
+ }
app/code/community/Laposta/Connect/etc/adminhtml.xml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <newsletter>
5
+ <children>
6
+ <lapostaconnect translate="title" module="connect">
7
+ <title>Laposta</title>
8
+ <action>lapostaconnect/adminhtml_laposta</action>
9
+ </lapostaconnect>
10
+ </children>
11
+ </newsletter>
12
+ </menu>
13
+ <acl>
14
+ <resources>
15
+ <all>
16
+ <title>Allow Everything</title>
17
+ </all>
18
+ <admin>
19
+ <children>
20
+ <newsletter>
21
+ <children>
22
+ <lapostaconnect translate="title">
23
+ <title>Laposta</title>
24
+ </lapostaconnect>
25
+ </children>
26
+ </newsletter>
27
+ <system>
28
+ <children>
29
+ <config>
30
+ <children>
31
+ <lapostaconnect translate="title">
32
+ <title>Laposta Configuration</title>
33
+ </lapostaconnect>
34
+ </children>
35
+ </config>
36
+ </children>
37
+ </system>
38
+ </children>
39
+ </admin>
40
+ </resources>
41
+ </acl>
42
+ </config>
app/code/community/Laposta/Connect/etc/config.xml ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Laposta_Connect>
5
+ <version>0.1.0</version>
6
+ <depends>
7
+ <!-- no dependencies -->
8
+ </depends>
9
+ </Laposta_Connect>
10
+ </modules>
11
+ <frontend>
12
+ <routers>
13
+ <lapostaconnect>
14
+ <use>standard</use>
15
+ <args>
16
+ <module>Laposta_Connect</module>
17
+ <frontName>lapostaconnect</frontName>
18
+ </args>
19
+ </lapostaconnect>
20
+ </routers>
21
+ <layout>
22
+ <updates>
23
+ <lapostaconnect>
24
+ <file>lapostaconnect.xml</file>
25
+ </lapostaconnect>
26
+ </updates>
27
+ </layout>
28
+ <events>
29
+ <customer_save_after>
30
+ <observers>
31
+ <lapostaconnect_customer_save>
32
+ <class>lapostaconnect/observer</class>
33
+ <method>handleCustomerSave</method>
34
+ </lapostaconnect_customer_save>
35
+ </observers>
36
+ </customer_save_after>
37
+ <customer_delete_after>
38
+ <observers>
39
+ <lapostaconnect_customer_delete>
40
+ <class>lapostaconnect/observer</class>
41
+ <method>handleCustomerDelete</method>
42
+ </lapostaconnect_customer_delete>
43
+ </observers>
44
+ </customer_delete_after>
45
+ </events>
46
+ </frontend>
47
+ <global>
48
+ <models>
49
+ <lapostaconnect>
50
+ <class>Laposta_Connect_Model</class>
51
+ <resourceModel>lapostaconnect_mysql4</resourceModel>
52
+ </lapostaconnect>
53
+ <lapostaconnect_mysql4>
54
+ <class>Laposta_Connect_Model_Mysql4</class>
55
+ <entities>
56
+ <subscriber>
57
+ <table>laposta_subscriber</table>
58
+ </subscriber>
59
+ <field>
60
+ <table>laposta_field</table>
61
+ </field>
62
+ <list>
63
+ <table>laposta_list</table>
64
+ </list>
65
+ </entities>
66
+ </lapostaconnect_mysql4>
67
+ </models>
68
+ <resources>
69
+ <lapostaconnect_setup>
70
+ <setup>
71
+ <module>Laposta_Connect</module>
72
+ </setup>
73
+ <connection>
74
+ <use>core_setup</use>
75
+ </connection>
76
+ </lapostaconnect_setup>
77
+ <lapostaconnect_write>
78
+ <connection>
79
+ <use>core_write</use>
80
+ </connection>
81
+ </lapostaconnect_write>
82
+ <lapostaconnect_read>
83
+ <connection>
84
+ <use>core_read</use>
85
+ </connection>
86
+ </lapostaconnect_read>
87
+ </resources>
88
+ <blocks>
89
+ <lapostaconnect>
90
+ <class>Laposta_Connect_Block</class>
91
+ </lapostaconnect>
92
+ </blocks>
93
+ <helpers>
94
+ <lapostaconnect>
95
+ <class>Laposta_Connect_Helper</class>
96
+ </lapostaconnect>
97
+ </helpers>
98
+ <extraconfig />
99
+ </global>
100
+ <admin>
101
+ <routers>
102
+ <lapostaconnect>
103
+ <use>admin</use>
104
+ <args>
105
+ <module>Laposta_Connect</module>
106
+ <frontName>lapostaconnect</frontName>
107
+ </args>
108
+ </lapostaconnect>
109
+ </routers>
110
+ </admin>
111
+ <adminhtml>
112
+ <events>
113
+ <admin_system_config_changed_section_lapostaconnect>
114
+ <observers>
115
+ <laposta_save_config>
116
+ <class>lapostaconnect/observer</class>
117
+ <method>handleSaveConfig</method>
118
+ </laposta_save_config>
119
+ </observers>
120
+ </admin_system_config_changed_section_lapostaconnect>
121
+ <customer_save_after>
122
+ <observers>
123
+ <lapostaconnect_customer_save>
124
+ <class>lapostaconnect/observer</class>
125
+ <method>handleCustomerSave</method>
126
+ </lapostaconnect_customer_save>
127
+ </observers>
128
+ </customer_save_after>
129
+ <customer_delete_after>
130
+ <observers>
131
+ <lapostaconnect_customer_delete>
132
+ <class>lapostaconnect/observer</class>
133
+ <method>handleCustomerDelete</method>
134
+ </lapostaconnect_customer_delete>
135
+ </observers>
136
+ </customer_delete_after>
137
+ </events>
138
+ </adminhtml>
139
+ <default>
140
+ <lapostaconnect>
141
+ <laposta>
142
+ <active>1</active>
143
+ <list_name>Magento</list_name>
144
+ <subscribe_unconfirmed>0</subscribe_unconfirmed>
145
+ <map_fields><![CDATA[a:13:{s:18:"_1393726014715_715";a:2:{s:7:"magento";s:9:"firstname";s:7:"laposta";s:10:"First Name";}s:17:"_1393726026086_86";a:2:{s:7:"magento";s:8:"lastname";s:7:"laposta";s:9:"Last Name";}s:18:"_1393726027925_925";a:2:{s:7:"magento";s:3:"dob";s:7:"laposta";s:13:"Date of Birth";}s:17:"_1393726029077_77";a:2:{s:7:"magento";s:15:"billing_address";s:7:"laposta";s:15:"Billing Address";}s:18:"_1393726030363_363";a:2:{s:7:"magento";s:16:"shipping_address";s:7:"laposta";s:16:"Shipping Address";}s:18:"_1393726070252_252";a:2:{s:7:"magento";s:6:"gender";s:7:"laposta";s:6:"Gender";}s:16:"_1393726077000_0";a:2:{s:7:"magento";s:8:"store_id";s:7:"laposta";s:8:"Store ID";}s:17:"_1393726086092_92";a:2:{s:7:"magento";s:10:"website_id";s:7:"laposta";s:10:"Website ID";}s:18:"_1393726099686_686";a:2:{s:7:"magento";s:16:"date_of_purchase";s:7:"laposta";s:13:"Last Purchase";}s:18:"_1393726143760_760";a:2:{s:7:"magento";s:8:"group_id";s:7:"laposta";s:8:"Group ID";}s:17:"_1393726160081_81";a:2:{s:7:"magento";s:9:"telephone";s:7:"laposta";s:9:"Telephone";}s:18:"_1393726169267_267";a:2:{s:7:"magento";s:7:"company";s:7:"laposta";s:7:"Company";}s:18:"_1394139695375_375";a:2:{s:7:"magento";s:10:"group_name";s:7:"laposta";s:5:"Group";}}]]></map_fields>
146
+ <enable_log>1</enable_log>
147
+ </laposta>
148
+ </lapostaconnect>
149
+ </default>
150
+ <crontab>
151
+ <jobs>
152
+ <lapostaconnect_export_subscribers>
153
+ <schedule><cron_expr>*/5 * * * *</cron_expr></schedule>
154
+ <run><model>lapostaconnect/cron::export</model></run>
155
+ </lapostaconnect_export_subscribers>
156
+ </jobs>
157
+ </crontab>
158
+ </config>
app/code/community/Laposta/Connect/etc/system.xml ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <lapostaconnect translate="label" module="lapostaconnect">
5
+ <label><![CDATA[Laposta]]></label>
6
+ <sort_order>350</sort_order>
7
+ </lapostaconnect>
8
+ </tabs>
9
+ <sections>
10
+ <lapostaconnect translate="label">
11
+ <class>laposta-section</class>
12
+ <label>Laposta Configuration</label>
13
+ <header_css>laposta-header</header_css>
14
+ <tab>lapostaconnect</tab>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>10</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <groups>
21
+ <laposta translate="label">
22
+ <label>Laposta Connection &amp; Synchronisation Settings</label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>50</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ <expanded>1</expanded>
29
+ <fields>
30
+ <active translate="label">
31
+ <label>Enabled</label>
32
+ <frontend_type>select</frontend_type>
33
+ <source_model>adminhtml/system_config_source_yesno</source_model>
34
+ <sort_order>10</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </active>
39
+ <api_key translate="label comment">
40
+ <label>Laposta API Key</label>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>20</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>0</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ <comment>
47
+ <![CDATA[<a href="https://app.laposta.nl/config/c.connect/s.apikey/" target="_blank">https://app.laposta.nl/config/c.connect/s.apikey/</a>]]></comment>
48
+ </api_key>
49
+ <list_name translate="label comment">
50
+ <label>Laposta List Name</label>
51
+ <frontend_type>text</frontend_type>
52
+ <sort_order>30</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>0</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ <comment><![CDATA[]]></comment>
57
+ </list_name>
58
+ <subscribe_unconfirmed translate="label">
59
+ <label>Allow Unconfirmed</label>
60
+ <frontend_type>select</frontend_type>
61
+ <source_model>adminhtml/system_config_source_yesno</source_model>
62
+ <sort_order>35</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>0</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ <comment>
67
+ <![CDATA[
68
+ Allowing unconfirmed subscriptions may lead to a higher spam rating. Caution is advised.
69
+ ]]>
70
+ </comment>
71
+ </subscribe_unconfirmed>
72
+ <map_fields translate="label comment">
73
+ <label>Customer Fields Mapping</label>
74
+ <frontend_model>lapostaconnect/adminhtml_system_config_form_field_mapfields</frontend_model>
75
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
76
+ <sort_order>40</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>0</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ <comment>
81
+ <![CDATA[
82
+ <strong>Available customer fields:</strong> firstname, lastname, dob, billing_address,
83
+ shipping_address, gender, store_id, website_id, date_of_purchase, group_name
84
+ group_id, telephone, company
85
+ ]]>
86
+ </comment>
87
+ </map_fields>
88
+ <enable_log translate="label comment">
89
+ <label>Enable Logging</label>
90
+ <frontend_type>select</frontend_type>
91
+ <source_model>adminhtml/system_config_source_yesno</source_model>
92
+ <sort_order>124</sort_order>
93
+ <show_in_default>1</show_in_default>
94
+ <show_in_website>0</show_in_website>
95
+ <show_in_store>1</show_in_store>
96
+ <comment>File is {{base_dir}}/var/log/Laposta.log</comment>
97
+ </enable_log>
98
+ </fields>
99
+ </laposta>
100
+ </groups>
101
+ </lapostaconnect>
102
+ </sections>
103
+ </config>
app/code/community/Laposta/Connect/sql/connect_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run(
8
+ "
9
+ CREATE TABLE IF NOT EXISTS {$this->getTable('subscriber')} (
10
+ `subscriber_id` int(11) unsigned NOT NULL auto_increment,
11
+ `list_id` int(11) unsigned NOT NULL default 1,
12
+ `customer_id` varchar(255) NOT NULL default '',
13
+ `laposta_id` varchar(255) NOT NULL default '',
14
+ `updated_time` datetime NULL,
15
+ `sync_time` datetime NULL,
16
+ PRIMARY KEY (`subscriber_id`),
17
+ INDEX `list_id` (`list_id`),
18
+ INDEX `customer_id` (`customer_id`),
19
+ INDEX `laposta_id` (`laposta_id`)
20
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
21
+ "
22
+ );
23
+
24
+ $installer->run(
25
+ "
26
+ CREATE TABLE IF NOT EXISTS {$this->getTable('field')} (
27
+ `field_id` int(11) unsigned NOT NULL auto_increment,
28
+ `list_id` int(11) unsigned NOT NULL default 1,
29
+ `field_name` varchar(255) NOT NULL default '',
30
+ `field_relation` varchar(255) NOT NULL default '',
31
+ `laposta_id` varchar(255) NOT NULL default '',
32
+ `laposta_tag` varchar(255) NOT NULL default '',
33
+ `updated_time` datetime NULL,
34
+ `sync_time` datetime NULL,
35
+ PRIMARY KEY (`field_id`),
36
+ INDEX `list_id` (`list_id`),
37
+ INDEX `laposta_id` (`laposta_id`)
38
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
39
+ "
40
+ );
41
+
42
+ $installer->run(
43
+ "
44
+ CREATE TABLE IF NOT EXISTS {$this->getTable('list')} (
45
+ `list_id` int(11) unsigned NOT NULL auto_increment,
46
+ `list_name` varchar(255) NOT NULL default '',
47
+ `laposta_id` varchar(255) NOT NULL default '',
48
+ `webhook_token` varchar(255) NOT NULL default '',
49
+ `updated_time` datetime NULL,
50
+ `sync_time` datetime NULL,
51
+ PRIMARY KEY (`list_id`),
52
+ INDEX `webhook_token` (`webhook_token`)
53
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
54
+ "
55
+ );
56
+
57
+ $installer->endSetup();
app/etc/modules/Laposta_Connect.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Laposta_Connect>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Newsletter />
9
+ </depends>
10
+ </Laposta_Connect>
11
+ </modules>
12
+ </config>
app/locale/en_US/Laposta_Connect.csv ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ;Config settings
2
+ "Enabled","Enabled"
3
+ "API Key","API Key"
4
+ "General Subscription","General Subscription"
5
+ "Additional Lists","Additional Lists"
6
+ "Customer Fields Mapping", "Customer Fields Mapping"
7
+
8
+ ;Notification messages
9
+
10
+ ;Additional translations
11
+ "members", "members"
12
+ "Customer", "Customer"
13
+ "Laposta", "Laposta"
14
+ "Add field", "Add field"
15
+ "Username:", "Username:"
16
+ "-- Disabled --", "-- Disabled --"
package.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Mage_Laposta_Connect</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Synchronise customers that are subscribed to your newsletter with your Laposta email marketing account.</summary>
10
+ <description>&lt;h2&gt;Summary&lt;/h2&gt;&#xD;
11
+ &lt;p&gt;This extension links your web shop customers that have subscribed to your newsletter with your account on Laposta's email marketing system.&lt;/p&gt;&#xD;
12
+ &#xD;
13
+ &lt;h2&gt;Requirements&lt;/h2&gt;&#xD;
14
+ &lt;p&gt;This extension requires Magento CE v1.5 or greater and makes use of Magento's built in cron (automated script execution at regular intervals). An account with Laposta is also required, of course.&lt;/p&gt;&#xD;
15
+ &#xD;
16
+ &lt;h2&gt;Installation&lt;/h2&gt;&#xD;
17
+ &lt;p&gt;This extension is installable via the Magento Connect Manager.&lt;/p&gt;&#xD;
18
+ &lt;p&gt;Please follow the instruction provided by Magento for installing and maintaing extensions.&lt;/p&gt;&#xD;
19
+ &lt;p&gt;&lt;strong&gt;Remember:&lt;/strong&gt; Once you have installed the plugin please log out of the admin panel and log in again. You may also need to clear Magento's storage cache (System &gt; Cache Management) before the plugin becomes available for configuration and usage.&lt;/p&gt;&#xD;
20
+ &#xD;
21
+ &lt;h2&gt;Configuration and Usage&lt;/h2&gt;&#xD;
22
+ &lt;p&gt;To configure your extension and start the synchronization process please go to System &gt; Configuration. In the left menu you should have a Laposta section with a Laposta Configuration link.&lt;/p&gt;&#xD;
23
+ &lt;p&gt;Aside from providiing your Laposta API key this extension will work out of the box though we encourage you to provide a Laposta List Name of your choosing to be able to identify your mailing list within Laposta.&lt;/p&gt;&#xD;
24
+ &#xD;
25
+ &lt;h2&gt;Questions&lt;/h2&gt;&#xD;
26
+ &lt;p&gt;Please see the FAQ section for questions.&lt;/p&gt;</description>
27
+ <notes>First release of the Laposta plugin for Magento.</notes>
28
+ <authors><author><name>Merten van Gerven</name><user>mertenvg</user><email>merten@codeblanche.com</email></author></authors>
29
+ <date>2014-03-20</date>
30
+ <time>12:33:00</time>
31
+ <contents><target name="magecommunity"><dir name="Laposta"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Mapfields.php" hash="2c88b8a08121c09ba5748f631205a282"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="8a54f573c56f8ce9e248506bb9514561"/><file name="Data.php" hash="8f9e28d0f28f9375385432d227ec1d06"/><file name="Fields.php" hash="51bc0aa26167219b038c04b3babb19af"/><file name="Laposta.php" hash="9085c0c80dcd314d402bfc960b8f861e"/><file name="Subscribe.php" hash="f58bc248ee3b4d229b58de8b4efbccf3"/><file name="Sync.php" hash="ad94bd49cf666fb99fa043bef1ba8bcf"/></dir><dir name="Model"><file name="Cron.php" hash="7a6a22b317282c049f5fa10a59622d58"/><file name="Field.php" hash="42e1857bdb7d90b31be189e2921ac8fd"/><file name="List.php" hash="99f590a5e5ea3b1a14869c641f49eaed"/><dir name="Mysql4"><dir name="Field"><file name="Collection.php" hash="f8133202231937b1ec14d8cdc39903fe"/></dir><file name="Field.php" hash="c49743d6acd1d4ce2b69aadf22838839"/><dir name="List"><file name="Collection.php" hash="fcc556452fff91bb3e9f933c68fff630"/></dir><file name="List.php" hash="6fef1b36f5d3a5560f83bafe205be614"/><dir name="Subscriber"><file name="Collection.php" hash="05db928eb656f132e4fa16ac740ce3c5"/></dir><file name="Subscriber.php" hash="9f73d39e97d4a19f8d8ad3c19f83a699"/></dir><file name="Observer.php" hash="72c09576c05ddb5cc0f0a05b0278b953"/><file name="Subscriber.php" hash="cba5176e53a7dcab9b9014190f13485d"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="LapostaController.php" hash="cc2a0d62caf63469258042e3b29616e4"/></dir><file name="IndexController.php" hash="7577e30abee9624d59901edb5cecd3e9"/><file name="SubscribeAllController.php" hash="160ac8e5229bb1003d7220116a9b06f7"/><file name="WebhookController.php" hash="dbdb6706b908bffd29e5d69f97c6809f"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d8ae83f3fe59f6806f11109bdb1b5cc8"/><file name="config.xml" hash="955fc3a1b19aab532d4ac39cbbad488f"/><file name="system.xml" hash="6ee7d5de56541573f16a2caf94dc0418"/></dir><dir name="sql"><dir name="connect_setup"><file name="mysql4-install-0.1.0.php" hash="96c1911d06392a5e9496829411102479"/></dir></dir></dir></dir></target><target name="magelocal"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="lapostaconnect.xml" hash=""/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Laposta_Connect.xml" hash="ab7675e19ea96d39c5980bee835f0e76"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Laposta_Connect.csv" hash="4f8f28790602cdd01633c0bb00f70585"/></dir></target></contents>
32
+ <compatible/>
33
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
34
+ </package>