MailUp - Version 2.2.0

Version Notes

Changelog:


  • you can now show the subscription checkbox during checkout

  • MailUp webhooks are now supported to manage realtime subscribe/unsubscribe

  • incremental sync was implemented, so that now only modified users are transferred to mailup during scheduled transmissions

  • logs can now be disabled

  • small interface tweeks

Download this release

Release Info

Developer Sevenlike
Extension MailUp
Version 2.2.0
Comparing to
See all releases


Code changes from version 2.1.3 to 2.2.0

Files changed (43) hide show
  1. app/code/local/SevenLike/MailUp/Block/.DS_Store +0 -0
  2. app/code/local/SevenLike/MailUp/Block/Checkout/Subscribe.php +9 -0
  3. app/code/local/SevenLike/MailUp/Helper/.DS_Store +0 -0
  4. app/code/local/SevenLike/MailUp/Helper/Data.php +148 -77
  5. app/code/local/SevenLike/MailUp/Model/Adminhtml/System/Source/Cron/Frequency.php +0 -0
  6. app/code/local/SevenLike/MailUp/Model/Adminhtml/System/Source/Cron/Hours.php +0 -0
  7. app/code/local/SevenLike/MailUp/Model/Consoleurlvalidator.php +0 -0
  8. app/code/local/SevenLike/MailUp/Model/Cron.php +74 -17
  9. app/code/local/SevenLike/MailUp/Model/Lists.php +4 -7
  10. app/code/local/SevenLike/MailUp/Model/MailUp.php +1 -0
  11. app/code/local/SevenLike/MailUp/Model/MailUpWsImport.php +659 -0
  12. app/code/local/SevenLike/MailUp/Model/Mysql14/MailUp.php +0 -0
  13. app/code/local/SevenLike/MailUp/Model/Mysql14/MailUp/Collection.php +0 -0
  14. app/code/local/SevenLike/MailUp/Model/Observer.php +135 -80
  15. app/code/local/SevenLike/MailUp/Model/Webserviceusernamevalidator.php +0 -0
  16. app/code/local/SevenLike/MailUp/Model/Ws.php +1 -646
  17. app/code/local/SevenLike/MailUp/Model/Wssend.php +3 -5
  18. app/code/local/SevenLike/MailUp/controllers/.DS_Store +0 -0
  19. app/code/local/SevenLike/MailUp/controllers/Adminhtml/.DS_Store +0 -0
  20. app/code/local/SevenLike/MailUp/controllers/Adminhtml/ConfigurationController.php +4 -2
  21. app/code/local/SevenLike/MailUp/controllers/Adminhtml/FieldsmappingController.php +3 -1
  22. app/code/local/SevenLike/MailUp/controllers/Adminhtml/FilterController.php +72 -6
  23. app/code/local/SevenLike/MailUp/controllers/Adminhtml/ViewdatatransferlogController.php +14 -0
  24. app/code/local/SevenLike/MailUp/controllers/WebhookController.php +147 -0
  25. app/code/local/SevenLike/MailUp/etc/.DS_Store +0 -0
  26. app/code/local/SevenLike/MailUp/etc/config.xml +59 -10
  27. app/code/local/SevenLike/MailUp/etc/system.xml +38 -3
  28. app/code/local/SevenLike/MailUp/sql/mailup_setup/mysql4-install-0.1.0.php +0 -0
  29. app/code/local/SevenLike/MailUp/sql/mailup_setup/mysql4-upgrade-0.1.0-1.0.0.php +0 -0
  30. app/code/local/SevenLike/MailUp/sql/mailup_setup/mysql4-upgrade-0.3.0-1.0.0.php +0 -0
  31. app/code/local/SevenLike/MailUp/sql/mailup_setup/mysql4-upgrade-1.0.0-1.5.2.php +0 -0
  32. app/code/local/SevenLike/MailUp/sql/mailup_setup/mysql4-upgrade-2.1.3-2.2.0.php +25 -0
  33. app/design/adminhtml/default/default/layout/mailup.xml +18 -1
  34. app/design/adminhtml/default/default/template/sevenlike/mailup/confirm.phtml +14 -38
  35. app/design/adminhtml/default/default/template/sevenlike/mailup/fieldsmapping.phtml +0 -2
  36. app/design/adminhtml/default/default/template/sevenlike/mailup/filter.phtml +4 -23
  37. app/design/adminhtml/default/default/template/sevenlike/mailup/viewdatatransferlog.phtml +72 -0
  38. app/etc/modules/SevenLike_MailUp.xml +0 -0
  39. app/locale/en_US/SevenLike_MailUp.csv +5 -2
  40. app/locale/it_IT/SevenLike_MailUp.csv +11 -3
  41. package.xml +9 -13
  42. skin/adminhtml/default/default/sevenlike/mailup/images/titoli.png +0 -0
  43. skin/adminhtml/default/default/sevenlike/mailup/mailup.css +3 -1
app/code/local/SevenLike/MailUp/Block/.DS_Store CHANGED
File without changes
app/code/local/SevenLike/MailUp/Block/Checkout/Subscribe.php ADDED
@@ -0,0 +1,9 @@
1
+ <?php
2
+
3
+ class SevenLike_MailUp_Block_Checkout_Subscribe extends Mage_Core_Block_Template
4
+ {
5
+ public function _toHtml()
6
+ {
7
+ return parent::_toHtml();
8
+ }
9
+ }
app/code/local/SevenLike/MailUp/Helper/.DS_Store CHANGED
File without changes
app/code/local/SevenLike/MailUp/Helper/Data.php CHANGED
@@ -2,22 +2,28 @@
2
3
class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
4
{
5
- public static function getCustomersData() {
6
- Mage::log('Getting customers data', 0);
7
$dateFormat = 'm/d/y h:i:s';
8
$lastDateTime = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-7*3600*24);
9
$thirtyDaysAgo = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-30*3600*24);
10
$twelveMonthsAgo = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-365*3600*24);
11
12
$toSend = array();
13
14
- //ottengo la collection con tutti i clienti
15
- $customerCollection = Mage::getModel('customer/customer')->getCollection();
16
- foreach ($customerCollection as $customer) {
17
- $currentCustomerId = $customer->getId();
18
- $i = $customer->getEmail();
19
- Mage::log('Customer with id '.$currentCustomerId, 0);
20
$customer = Mage::getModel('customer/customer')->load($currentCustomerId);
21
22
//recupero gli ordini del cliente corrente
23
$allOrdersTotalAmount = 0;
@@ -30,12 +36,12 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
30
$lastShipmentOrderId = null;
31
$lastShipmentOrderDate = null;
32
33
- Mage::log('Parsing orders of customer with id '.$currentCustomerId, 0);
34
$orders = Mage::getModel('sales/order')
35
->getCollection()
36
->addAttributeToFilter('customer_id', $currentCustomerId);
37
foreach ($orders as $order) {
38
- Mage::log("ORDINE IN STATUS: " . $order->getStatus());
39
if (!in_array($order->getStatus(), array("closed", "complete", "processing"))) continue;
40
$currentOrderTotal = floatval($order->getGrandTotal());
41
$allOrdersTotalAmount += $currentOrderTotal;
@@ -76,7 +82,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
76
ksort($allOrdersIds);
77
78
//recupero i carrelli abbandonati del cliente
79
- Mage::log('Parsing abandoned carts of customer with id '.$currentCustomerId, 0);
80
$cartCollection = Mage::getResourceModel('reports/quote_collection');
81
$cartCollection->prepareForAbandonedReport(array(1));
82
$cartCollection->addFieldToFilter('customer_id', $currentCustomerId);
@@ -91,7 +97,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
91
$toSend[$i]['IDCarrelloAbbandonato'] = '';
92
93
if (! empty($lastCart)) {
94
- Mage::log('Customer with id '.$currentCustomerId .' has abandoned cart', 0);
95
$datetimeCart = $lastCart->getUpdatedAt();
96
$toSend[$i]['TotaleCarrelloAbbandonato'] = self::_formatPrice($lastCart->getGrandTotal());
97
$toSend[$i]['DataCarrelloAbbandonato'] = self::_retriveDateFromDatetime($datetimeCart);
@@ -108,7 +114,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
108
|| $lastOrderDateTime > $lastDateTime
109
|| ($datetimeCart && $datetimeCart > $lastDateTime))
110
{
111
- Mage::log('Adding customer with id '.$currentCustomerId, 0);
112
113
$toSend[$i]['nome'] = $customer->getFirstname();
114
$toSend[$i]['cognome'] = $customer->getLastname();
@@ -163,39 +169,45 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
163
}
164
165
$toSend[$i]['IDProdottiUltimoOrdine'] = implode(',', $productIds);
166
$toSend[$i]['IDCategorieUltimoOrdine'] = implode(',', $categoryIds);
167
}
168
169
//unsetto la variabile
170
unset($customer);
171
}
172
173
- Mage::log('Parsing subscribers', 0);
174
- $subscriberCollection = Mage::getModel('newsletter/subscriber')
175
- ->getCollection()
176
- ->useOnlySubscribed()
177
- ->addFieldToFilter('customer_id', 0);
178
-
179
- foreach ($subscriberCollection as $subscriber) {
180
- $subscriber = Mage::getModel('newsletter/subscriber')->load($subscriber->getId());
181
- $i = $subscriber->getEmail();
182
- if (isset($toSend[$i])) continue;
183
- $toSend[$i]['nome'] = '';
184
- $toSend[$i]['cognome'] = '';
185
- $toSend[$i]['email'] = $i;
186
- $toSend[$i]['subscribed'] = 'yes';
187
}
188
189
- Mage::log('End getting customers data', 0);
190
-
191
return $toSend;
192
}
193
194
- public function generateAndSendCustomers($mailupCustomerIds, $post = null)
195
{
196
- $MailUpWsSend = Mage::getModel('mailup/wssend');
197
$wsSend = new MailUpWsSend();
198
- $MailUpWsSend = Mage::getModel('mailup/ws');
199
$wsImport = new MailUpWsImport();
200
$accessKey = $wsSend->loginFromId();
201
@@ -236,19 +248,72 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
236
}
237
}
238
239
- $customersData = SevenLike_MailUp_Helper_Data::getCustomersData();
240
-
241
if ($accessKey === false) {
242
Mage::throwException('no access key returned');
243
}
244
$fields = $wsSend->GetFields($accessKey);
245
$fields_mapping = $wsImport->getFieldsMapping();
246
247
//preparo l'xml degli iscritti da inviare a mailup (da gestire in base ai filtri)
248
- $xmlData = '<subscribers>';
249
foreach ($mailupCustomerIds as $customerId) {
250
$tmp = array();
251
- $subscriber = $customersData[$customerId['email']];
252
$subscriber["DataCarrelloAbbandonato"] = self::_convertUTCToStoreTimezoneAndFormatForMailup($subscriber["DataCarrelloAbbandonato"]);
253
$subscriber["DataUltimoOrdineSpedito"] = self::_convertUTCToStoreTimezoneAndFormatForMailup($subscriber["DataUltimoOrdineSpedito"]);
254
$subscriber["registeredDate"] = self::_convertUTCToStoreTimezoneAndFormatForMailup($subscriber["registeredDate"]);
@@ -260,7 +325,11 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
260
if (@$fields_mapping["Last"]) $tmp[$fields_mapping["Last"]] = '<campo'.$fields_mapping["Last"].'>'. ((!empty($subscriber['cognome'])) ? $subscriber['cognome'] : '') .'</campo'.$fields_mapping["Last"].'>';
261
262
foreach ($subscriber as $k=>$v) {
263
- if (!strlen($subscriber[$k])) $subscriber[$k] = "-";
264
}
265
266
if (@$fields_mapping["Company"]) $tmp[$fields_mapping["Company"]] = '<campo'.$fields_mapping["Company"].'>'. $subscriber['azienda'] .'</campo'.$fields_mapping["Company"].'>';
@@ -296,52 +365,54 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
296
$tmp = implode("", $tmp);
297
$xmlData .= $tmp;
298
$xmlData .= "</subscriber>\n";
299
- }
300
- $xmlData .= '</subscribers>';
301
-
302
- Mage::log($xmlData, 0);
303
-
304
- //definisco il gruppo a cui aggiungere gli iscritti
305
- $groupId = $post['mailupGroupId'];
306
- $listGUID = $post['mailupListGUID'];
307
- $idList = $post['mailupIdList'];
308
309
- if ($post['mailupNewGroup'] == 1) {
310
- $newGroup = array(
311
- "idList" => $idList,
312
- "listGUID" => $listGUID,
313
- "newGroupName" => $post['mailupNewGroupName']
314
- );
315
316
- $groupId = $wsImport->CreaGruppo($newGroup);
317
}
318
319
- $importProcessData = array(
320
- "idList" => $idList,
321
- "listGUID" => $listGUID,
322
- "idGroup" => $groupId,
323
- "xmlDoc" => $xmlData,
324
- "idGroups" => $groupId,
325
- "importType" => "3",
326
- "mobileInputType" => "2",
327
- "asPending" => "0",
328
- "ConfirmEmail" => "0",
329
- "asOptOut" => "0",
330
- "forceOptIn" => "0",
331
- "replaceGroups" => "0",
332
- "idConfirmNL" => "0"
333
- );
334
335
//avvio l'importazione su mailup
336
- $processID = $wsImport->newImportProcess($importProcessData);
337
-
338
- $process = array(
339
- "idList" => $post['mailupIdList'],
340
- "listGUID" => $post['mailupListGUID'],
341
- "idProcess" => $processID
342
- );
343
-
344
- $wsImport->startProcess($process);
345
}
346
347
private static function _formatPrice($price) {
2
3
class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract
4
{
5
+ public static function getCustomersData($customerCollection = null)
6
+ {
7
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Getting customers data', 0);
8
$dateFormat = 'm/d/y h:i:s';
9
$lastDateTime = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-7*3600*24);
10
$thirtyDaysAgo = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-30*3600*24);
11
$twelveMonthsAgo = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-365*3600*24);
12
13
+ $parseSubscribers = false;
14
$toSend = array();
15
+ if ($customerCollection === null) {
16
+ $customerCollection = Mage::getModel('customer/customer')->getCollection();
17
+ $parseSubscribers = true;
18
+ }
19
+ foreach ($customerCollection as $currentCustomerId) {
20
+ if (is_object($currentCustomerId)) {
21
+ $currentCustomerId = $currentCustomerId->getId();
22
+ }
23
24
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Customer with id '.$currentCustomerId, 0);
25
$customer = Mage::getModel('customer/customer')->load($currentCustomerId);
26
+ $i = $customer->getEmail();
27
28
//recupero gli ordini del cliente corrente
29
$allOrdersTotalAmount = 0;
36
$lastShipmentOrderId = null;
37
$lastShipmentOrderDate = null;
38
39
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Parsing orders of customer with id '.$currentCustomerId, 0);
40
$orders = Mage::getModel('sales/order')
41
->getCollection()
42
->addAttributeToFilter('customer_id', $currentCustomerId);
43
foreach ($orders as $order) {
44
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("ORDINE IN STATUS: " . $order->getStatus());
45
if (!in_array($order->getStatus(), array("closed", "complete", "processing"))) continue;
46
$currentOrderTotal = floatval($order->getGrandTotal());
47
$allOrdersTotalAmount += $currentOrderTotal;
82
ksort($allOrdersIds);
83
84
//recupero i carrelli abbandonati del cliente
85
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Parsing abandoned carts of customer with id '.$currentCustomerId, 0);
86
$cartCollection = Mage::getResourceModel('reports/quote_collection');
87
$cartCollection->prepareForAbandonedReport(array(1));
88
$cartCollection->addFieldToFilter('customer_id', $currentCustomerId);
97
$toSend[$i]['IDCarrelloAbbandonato'] = '';
98
99
if (! empty($lastCart)) {
100
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Customer with id '.$currentCustomerId .' has abandoned cart', 0);
101
$datetimeCart = $lastCart->getUpdatedAt();
102
$toSend[$i]['TotaleCarrelloAbbandonato'] = self::_formatPrice($lastCart->getGrandTotal());
103
$toSend[$i]['DataCarrelloAbbandonato'] = self::_retriveDateFromDatetime($datetimeCart);
114
|| $lastOrderDateTime > $lastDateTime
115
|| ($datetimeCart && $datetimeCart > $lastDateTime))
116
{
117
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Adding customer with id '.$currentCustomerId, 0);
118
119
$toSend[$i]['nome'] = $customer->getFirstname();
120
$toSend[$i]['cognome'] = $customer->getLastname();
169
}
170
171
$toSend[$i]['IDProdottiUltimoOrdine'] = implode(',', $productIds);
172
+ if ($toSend[$i]['IDProdottiUltimoOrdine']) $toSend[$i]['IDProdottiUltimoOrdine'] = ",{$toSend[$i]['IDProdottiUltimoOrdine']},";
173
$toSend[$i]['IDCategorieUltimoOrdine'] = implode(',', $categoryIds);
174
+ if ($toSend[$i]['IDCategorieUltimoOrdine']) $toSend[$i]['IDCategorieUltimoOrdine'] = ",{$toSend[$i]['IDCategorieUltimoOrdine']},";
175
}
176
177
//unsetto la variabile
178
unset($customer);
179
}
180
181
+ /*
182
+ * disabled cause useless in segmentation
183
+ if ($parseSubscribers) {
184
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Parsing subscribers', 0);
185
+ $subscriberCollection = Mage::getModel('newsletter/subscriber')
186
+ ->getCollection()
187
+ ->useOnlySubscribed()
188
+ ->addFieldToFilter('customer_id', 0);
189
+
190
+ foreach ($subscriberCollection as $subscriber) {
191
+ $subscriber = Mage::getModel('newsletter/subscriber')->load($subscriber->getId());
192
+ $i = $subscriber->getEmail();
193
+ if (strlen($i)) continue;
194
+ if (isset($toSend[$i])) continue;
195
+ $toSend[$i]['nome'] = '';
196
+ $toSend[$i]['cognome'] = '';
197
+ $toSend[$i]['email'] = $i;
198
+ $toSend[$i]['subscribed'] = 'yes';
199
+ }
200
}
201
+ */
202
203
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('End getting customers data', 0);
204
return $toSend;
205
}
206
207
+ public static function generateAndSendCustomers($mailupCustomerIds, $post = null, $newsletter_subscribers = null)
208
{
209
$wsSend = new MailUpWsSend();
210
+ require_once dirname(__FILE__) . "/../Model/MailUpWsImport.php";
211
$wsImport = new MailUpWsImport();
212
$accessKey = $wsSend->loginFromId();
213
248
}
249
}
250
251
if ($accessKey === false) {
252
Mage::throwException('no access key returned');
253
}
254
$fields = $wsSend->GetFields($accessKey);
255
$fields_mapping = $wsImport->getFieldsMapping();
256
257
+ //definisco il gruppo a cui aggiungere gli iscritti
258
+ $groupId = $post['mailupGroupId'];
259
+ $listGUID = $post['mailupListGUID'];
260
+ $idList = $post['mailupIdList'];
261
+
262
+ if ($post['mailupNewGroup'] == 1) {
263
+ $newGroup = array(
264
+ "idList" => $idList,
265
+ "listGUID" => $listGUID,
266
+ "newGroupName" => $post['mailupNewGroupName']
267
+ );
268
+
269
+ $groupId = $wsImport->CreaGruppo($newGroup);
270
+ }
271
+
272
+ if (isset($post["send_optin_email_to_new_subscribers"]) and $post["send_optin_email_to_new_subscribers"]) {
273
+ $importProcessData = array(
274
+ "idList" => $idList,
275
+ "listGUID" => $listGUID,
276
+ "idGroup" => $groupId,
277
+ "xmlDoc" => "",
278
+ "idGroups" => $groupId,
279
+ "importType" => 1,
280
+ "mobileInputType" => 2,
281
+ "asPending" => false,
282
+ "ConfirmEmail" => true,
283
+ "asOptOut" => false,
284
+ "forceOptIn" => false,
285
+ "replaceGroups" => false,
286
+ "idConfirmNL" => 0
287
+ );
288
+ } else {
289
+ $importProcessData = array(
290
+ "idList" => $idList,
291
+ "listGUID" => $listGUID,
292
+ "idGroup" => $groupId,
293
+ "xmlDoc" => "",
294
+ "idGroups" => $groupId,
295
+ "importType" => 1,
296
+ "mobileInputType" => 2,
297
+ "asPending" => false,
298
+ "ConfirmEmail" => false,
299
+ "asOptOut" => false,
300
+ "forceOptIn" => false,
301
+ "replaceGroups" => false,
302
+ "idConfirmNL" => 0
303
+ );
304
+ }
305
+
306
//preparo l'xml degli iscritti da inviare a mailup (da gestire in base ai filtri)
307
+ $xmlData = '';
308
+ $subscribers_counter = 0;
309
+ $total_subscribers_to_send = sizeof($mailupCustomerIds);
310
foreach ($mailupCustomerIds as $customerId) {
311
$tmp = array();
312
+ $subscribers_counter++;
313
+ $subscriber = self::getCustomersData(array($customerId));
314
+ $subscriber = array_values($subscriber);
315
+ $subscriber = $subscriber[0];
316
+
317
$subscriber["DataCarrelloAbbandonato"] = self::_convertUTCToStoreTimezoneAndFormatForMailup($subscriber["DataCarrelloAbbandonato"]);
318
$subscriber["DataUltimoOrdineSpedito"] = self::_convertUTCToStoreTimezoneAndFormatForMailup($subscriber["DataUltimoOrdineSpedito"]);
319
$subscriber["registeredDate"] = self::_convertUTCToStoreTimezoneAndFormatForMailup($subscriber["registeredDate"]);
325
if (@$fields_mapping["Last"]) $tmp[$fields_mapping["Last"]] = '<campo'.$fields_mapping["Last"].'>'. ((!empty($subscriber['cognome'])) ? $subscriber['cognome'] : '') .'</campo'.$fields_mapping["Last"].'>';
326
327
foreach ($subscriber as $k=>$v) {
328
+ if (!strlen($subscriber[$k])) {
329
+ $subscriber[$k] = "-";
330
+ } else {
331
+ $subscriber[$k] = str_replace(array("\r\n", "\r", "\n"), " ", $v);
332
+ }
333
}
334
335
if (@$fields_mapping["Company"]) $tmp[$fields_mapping["Company"]] = '<campo'.$fields_mapping["Company"].'>'. $subscriber['azienda'] .'</campo'.$fields_mapping["Company"].'>';
365
$tmp = implode("", $tmp);
366
$xmlData .= $tmp;
367
$xmlData .= "</subscriber>\n";
368
369
+ // ogni 5000 utenti invio i dati
370
+ if ($subscribers_counter == 5000) {
371
+ $importProcessData["xmlDoc"] = "<subscribers>$xmlData</subscribers>";
372
+ $xmlData = "";
373
+ $subscribers_counter = 0;
374
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($importProcessData, 0);
375
+ $processID = $wsImport->newImportProcess($importProcessData);
376
+ if ($processID === false) return false;
377
+ }
378
+ }
379
380
+ //invio gli ultimi utenti
381
+ if (strlen($xmlData)) {
382
+ $importProcessData["xmlDoc"] = "<subscribers>$xmlData</subscribers>";
383
+ $xmlData = "";
384
+ $subscribers_counter = 0;
385
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($importProcessData, 0);
386
+ $processID = $wsImport->newImportProcess($importProcessData);
387
+ if ($processID === false) return false;
388
}
389
390
+ if (isset($newsletter_subscribers) and is_array($newsletter_subscribers) and !empty($newsletter_subscribers)) {
391
+ $subscribers_counter = 0;
392
+ foreach ($newsletter_subscribers as $newsletter_subscriber) {
393
+ $subscribers_counter++;
394
+ $xmlData .= '<subscriber email="' . $newsletter_subscriber . '" Number="" Name=""></subscriber>';
395
+ if ($subscribers_counter == 5000 or $subscribers_counter == $total_subscribers_to_send) {
396
+ $importProcessData["xmlDoc"] = "<subscribers>$xmlData</subscribers>";
397
+ $xmlData = "";
398
+ $subscribers_counter = 0;
399
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($importProcessData, 0);
400
+ $processID = $wsImport->newImportProcess($importProcessData);
401
+ if ($processID === false) return false;
402
+ }
403
+ }
404
+ }
405
406
//avvio l'importazione su mailup
407
+ unset($importProcessData["xmlDoc"]);
408
+ $importProcessData["listsIDs"] = $post['mailupIdList'];
409
+ $importProcessData["listsGUIDs"] = $post['mailupListGUID'];
410
+ $importProcessData["groupsIDs"] = $groupId;
411
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("mailup: StartImportProcesses", 0);
412
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($importProcessData, 0);
413
+ $check = $wsImport->StartImportProcesses($importProcessData);
414
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($check, 0);
415
+ return $check;
416
}
417
418
private static function _formatPrice($price) {
app/code/local/SevenLike/MailUp/Model/Adminhtml/System/Source/Cron/Frequency.php CHANGED
File without changes
app/code/local/SevenLike/MailUp/Model/Adminhtml/System/Source/Cron/Hours.php CHANGED
File without changes
app/code/local/SevenLike/MailUp/Model/Consoleurlvalidator.php CHANGED
File without changes
app/code/local/SevenLike/MailUp/Model/Cron.php CHANGED
@@ -1,30 +1,87 @@
1
<?php
2
3
class SevenLike_MailUp_Model_Cron
4
{
5
- public function run() {
6
- Mage::log('Cron mailup', 0);
7
8
if (Mage::getStoreConfig('newsletter/mailup/enable_cron_export') == 1) {
9
- Mage::log('Cron export enabled', 0);
10
- require_once(dirname(__FILE__) . '/../Helper/Data.php');
11
-
12
- $mailupCustomerIds = array();
13
- $customersData = SevenLike_MailUp_Helper_Data::getCustomersData();
14
- foreach ($customersData as $tmp) {
15
- $status = Mage::getModel('newsletter/subscriber')->loadByEmail($tmp["email"])->getStatus();
16
- if ($status != Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) continue;
17
- $mailupCustomerIds[] = array(
18
- "entity_id" => $tmp["IDCliente"],
19
- "email" => $tmp["email"]
20
- );
21
}
22
23
- SevenLike_MailUp_Helper_Data::generateAndSendCustomers($mailupCustomerIds);
24
} else {
25
- Mage::log('Cron export not enabled', 0);
26
}
27
28
- Mage::log('Cron mailup finished', 0);
29
}
30
}
1
<?php
2
3
+ require_once dirname(__FILE__) . "/MailUpWsImport.php";
4
+ require_once dirname(__FILE__) . "/Wssend.php";
5
class SevenLike_MailUp_Model_Cron
6
{
7
+ public function run()
8
+ {
9
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Cron mailup', 0);
10
11
if (Mage::getStoreConfig('newsletter/mailup/enable_cron_export') == 1) {
12
+ $indexProcess = new Mage_Index_Model_Process();
13
+ $indexProcess->setId("mailupcronrun");
14
+ if ($indexProcess->isLocked()) {
15
+ Mage::log("MAILUP: cron already running or locked");
16
+ return false;
17
}
18
+ $indexProcess->lockAndBlock();
19
20
+ require_once dirname(__FILE__) . '/../Helper/Data.php';
21
+ $db_read = Mage::getSingleton('core/resource')->getConnection('core_read');
22
+ $db_write = Mage::getSingleton('core/resource')->getConnection('core_write');
23
+ $lastsync = gmdate("Y-m-d H:i:s");
24
+
25
+ // reading newsletter subscribers
26
+ //$newsletter_subscriber_table_name = Mage::getSingleton('core/resource')->getTableName('newsletter_subscriber');
27
+ //$newsletter_subscribers = $db_read->fetchAll("SELECT ms.*, ns.subscriber_email FROM mailup_sync ms JOIN $newsletter_subscriber_table_name ns ON (ms.customer_id = ns.subscriber_id) WHERE ms.needs_sync=1 AND ms.entity='subscriber'");
28
+
29
+ // reading customers (jobid == 0, their updates)
30
+ $customers = array();
31
+ $customer_entity_table_name = Mage::getSingleton('core/resource')->getTableName('customer_entity');
32
+ $stmt = $db_read->query("SELECT ms.*, ce.email FROM mailup_sync ms JOIN $customer_entity_table_name ce ON (ms.customer_id = ce.entity_id) WHERE ms.needs_sync=1 AND ms.entity='customer' AND job_id=0");
33
+ while ($row = $stmt->fetch()) {
34
+ $customers[] = $row["customer_id"];
35
+ }
36
+
37
+ // generating and sending data to mailup
38
+ //SevenLike_MailUp_Helper_Data::generateAndSendCustomers($customers, null, $newsletter_subscribers);
39
+ $check = SevenLike_MailUp_Helper_Data::generateAndSendCustomers($customers);
40
+
41
+ // reading and processing jobs
42
+ $jobs = $db_read->fetchAll("SELECT * FROM mailup_sync_jobs WHERE status='queued'");
43
+ foreach ($jobs as $job) {
44
+ $stmt = $db_write->query("UPDATE mailup_sync_jobs SET status='started', start_datetime='" . gmdate("Y-m-d H:i:s") . "' WHERE id={$job["id"]}");
45
+ $customers = array();
46
+ $job['mailupNewGroup'] = 0;
47
+ $job['mailupIdList'] = Mage::getStoreConfig('newsletter/mailup/list');
48
+ $job["mailupGroupId"] = $job["mailupgroupid"];
49
+ $job["send_optin_email_to_new_subscribers"] = $job["send_optin"];
50
+ $tmp = new SevenLike_MailUp_Model_Lists;
51
+ $tmp = $tmp->toOptionArray();
52
+ foreach ($tmp as $t) {
53
+ if ($t["value"] == $job['mailupIdList']) {
54
+ $job['mailupListGUID'] = $t["guid"];
55
+ $job["groups"] = $t["groups"];
56
+ break;
57
+ }
58
+ }
59
+ unset($tmp); unset($t);
60
+ $stmt = $db_read->query("SELECT ms.*, ce.email FROM mailup_sync ms JOIN $customer_entity_table_name ce ON (ms.customer_id = ce.entity_id) WHERE ms.needs_sync=1 AND ms.entity='customer' AND job_id={$job["id"]}");
61
+ while ($row = $stmt->fetch()) {
62
+ $customers[] = $row["customer_id"];
63
+ }
64
+ $check = SevenLike_MailUp_Helper_Data::generateAndSendCustomers($customers, $job);
65
+ if ($check) {
66
+ // saving sync state for customers
67
+ foreach ($customers as $row) {
68
+ $db_write->query("UPDATE mailup_sync SET needs_sync=0, last_sync='$lastsync' WHERE customer_id={$row} AND entity='customer'");
69
+ }
70
+
71
+ // finishing the job also
72
+ $db_write->query("UPDATE mailup_sync_jobs SET status='finished', finish_datetime='" . gmdate("Y-m-d H:i:s") . "' WHERE id={$job["id"]}");
73
+ }
74
+ }
75
+
76
+ $indexProcess->unlock();
77
} else {
78
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Cron export not enabled', 0);
79
}
80
81
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('Cron mailup finished', 0);
82
+ }
83
+
84
+ public static function resendConnectionErrors()
85
+ {
86
}
87
}
app/code/local/SevenLike/MailUp/Model/Lists.php CHANGED
@@ -1,5 +1,7 @@
1
<?php
2
3
class SevenLike_MailUp_Model_Lists
4
{
5
public function toOptionArray() {
@@ -7,16 +9,11 @@ class SevenLike_MailUp_Model_Lists
7
$selectLists = array();
8
9
if (Mage::getStoreConfig('newsletter/mailup/url_console') && Mage::getStoreConfig('newsletter/mailup/username_ws') && Mage::getStoreConfig('newsletter/mailup/password_ws')) {
10
- if (!class_exists("MailUpWsSend")) {
11
- $MailUpWsSend = Mage::getModel('mailup/wssend');
12
- }
13
$wsSend = new MailUpWsSend();
14
$accessKey = $wsSend->loginFromId();
15
16
if ($accessKey !== false) {
17
- if (!class_exists("MailUpWsImport")) {
18
- $MailUpWsImport = Mage::getModel('mailup/ws');
19
- }
20
$wsImport = new MailUpWsImport();
21
22
$xmlString = $wsImport->GetNlList();
@@ -47,7 +44,7 @@ class SevenLike_MailUp_Model_Lists
47
}
48
}
49
} else {
50
- Mage::log('LoginFromId failed', 0);
51
$selectLists[0] = array('value' => 0, 'label'=>$GLOBALS["__sl_mailup_login_error"]);
52
}
53
}
1
<?php
2
3
+ require_once dirname(__FILE__) . "/MailUpWsImport.php";
4
+ require_once dirname(__FILE__) . "/Wssend.php";
5
class SevenLike_MailUp_Model_Lists
6
{
7
public function toOptionArray() {
9
$selectLists = array();
10
11
if (Mage::getStoreConfig('newsletter/mailup/url_console') && Mage::getStoreConfig('newsletter/mailup/username_ws') && Mage::getStoreConfig('newsletter/mailup/password_ws')) {
12
$wsSend = new MailUpWsSend();
13
$accessKey = $wsSend->loginFromId();
14
15
if ($accessKey !== false) {
16
+ require_once dirname(__FILE__) . "/MailUpWsImport.php";
17
$wsImport = new MailUpWsImport();
18
19
$xmlString = $wsImport->GetNlList();
44
}
45
}
46
} else {
47
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log('LoginFromId failed', 0);
48
$selectLists[0] = array('value' => 0, 'label'=>$GLOBALS["__sl_mailup_login_error"]);
49
}
50
}
app/code/local/SevenLike/MailUp/Model/MailUp.php CHANGED
@@ -1,4 +1,5 @@
1
<?php
2
class SevenLike_MailUp_Model_MailUp extends Mage_Core_Model_Abstract
3
{
4
public function _construct()
1
<?php
2
+
3
class SevenLike_MailUp_Model_MailUp extends Mage_Core_Model_Abstract
4
{
5
public function _construct()
app/code/local/SevenLike/MailUp/Model/MailUpWsImport.php ADDED
@@ -0,0 +1,659 @@
1
+ <?php
2
+
3
+ class MailUpWsImport
4
+ {
5
+ protected $ns = "http://ws.mailupnet.it/";
6
+
7
+ //protected $WSDLUrl = "http://g4a0.s03.it/services/WSMailUpImport.asmx?WSDL";
8
+ //protected $headers = array("User" => "a7410", "Password" => "GA6VAN0W");
9
+ protected $rCode;
10
+ private $soapClient;
11
+ private $xmlResponse;
12
+ protected $domResult;
13
+
14
+ function __construct() {
15
+ $urlConsole = Mage::getStoreConfig('newsletter/mailup/url_console');
16
+ $WSDLUrl = 'http://'. $urlConsole .'/services/WSMailUpImport.asmx?WSDL';
17
+ $user = Mage::getStoreConfig('newsletter/mailup/username_ws');
18
+ $password = Mage::getStoreConfig('newsletter/mailup/password_ws');
19
+ $headers = array('User' => $user, 'Password' => $password);
20
+ $this->header = new SOAPHeader($this->ns, 'Authentication', $headers);
21
+
22
+ try {
23
+ $this->soapClient = new SoapClient($WSDLUrl, array('trace' => 1, 'exceptions' => 1, 'connection_timeout' => 10));
24
+ $this->soapClient->__setSoapHeaders($this->header);
25
+ } catch (Exception $e) {
26
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper("mailup")->__("Unable to connect to MailUp console"));
27
+ }
28
+ }
29
+
30
+ function __destruct() {
31
+ unset($this->soapClient);
32
+ }
33
+
34
+ public function getFunctions() {
35
+ print_r($this->soapClient->__getFunctions());
36
+ }
37
+
38
+ public function creaGruppo($newGroup) {
39
+ if (!is_object($this->soapClient)) return false;
40
+ try {
41
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("Mailup: creazione nuovo gruppo");
42
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($newGroup);
43
+ $this->soapClient->CreateGroup($newGroup);
44
+ $this->printLastRequest();
45
+ $this->printLastResponse();
46
+ return $this->readReturnCode('CreateGroup', 'ReturnCode');
47
+ } catch (SoapFault $soapFault) {
48
+ Mage::log('SOAP error', 0);
49
+ Mage::log($soapFault, 0);
50
+ }
51
+ }
52
+
53
+ public function GetNlList() {
54
+ if (!is_object($this->soapClient)) return false;
55
+ try {
56
+ $this->soapClient->GetNlLists();
57
+ $this->printLastRequest();
58
+ $this->printLastResponse();
59
+ $result = $this->soapClient->__getLastResponse();
60
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($result, 0);
61
+ return $result;
62
+ } catch (SoapFault $soapFault) {
63
+ Mage::log('SOAP error', 0);
64
+ Mage::log($soapFault, 0);
65
+ }
66
+ }
67
+
68
+ public function newImportProcess($importProcessData) {
69
+ if (!is_object($this->soapClient)) return false;
70
+ try {
71
+ $this->soapClient->NewImportProcess($importProcessData);
72
+ $returncode = $this->readReturnCode('NewImportProcess', 'ReturnCode');
73
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("mailup: newImportProcess result: $returncode", 0);
74
+ return $returncode;
75
+ } catch (SoapFault $soapFault) {
76
+ Mage::log('SOAP error', 0);
77
+ Mage::log($soapFault, 0);
78
+ return false;
79
+ }
80
+ }
81
+
82
+ public function startProcess($processData) {
83
+ if (!is_object($this->soapClient)) return false;
84
+ try {
85
+ $this->soapClient->StartProcess($processData);
86
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("mailup: ws: startimportprocess", 0);
87
+ return true;
88
+ } catch (SoapFault $soapFault) {
89
+ Mage::log('SOAP error', 0);
90
+ Mage::log($soapFault, 0);
91
+ return false;
92
+ }
93
+ }
94
+
95
+ public function getProcessDetail($processData) {
96
+ if (!is_object($this->soapClient)) return false;
97
+ try {
98
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($this->soapClient->GetProcessDetails($processData), 0);
99
+ } catch (SoapFault $soapFault) {
100
+ Mage::log('SOAP error', 0);
101
+ Mage::log($soapFault, 0);
102
+ }
103
+ }
104
+
105
+ public function startImportProcesses($processData) {
106
+ if (!is_object($this->soapClient)) return false;
107
+ try {
108
+ $this->soapClient->StartImportProcesses($processData);
109
+ $this->printLastRequest();
110
+ $this->printLastResponse();
111
+ return true;
112
+ } catch (SoapFault $soapFault) {
113
+ Mage::log('SOAP error', 0);
114
+ Mage::log($soapFault, 0);
115
+ return false;
116
+ }
117
+ }
118
+
119
+ private function readReturnCode($func, $param) {
120
+ if (!is_object($this->soapClient)) return false;
121
+
122
+ static $func_in = ''; //static variable to test xmlResponse update
123
+ if ($func_in != $func) {//(!isset($this->xmlResponse))
124
+ $func_in = $func;
125
+ //prendi l'XML di ritorno se non l'ho già preso
126
+ $this->xmlResponse = $this->soapClient->__getLastResponse();
127
+
128
+ $dom = new DomDocument();
129
+ $dom->loadXML($this->xmlResponse) or die('File XML non valido!');
130
+ $xmlResult = $dom->getElementsByTagName($func.'Result');
131
+
132
+ $this->domResult = new DomDocument();
133
+ $this->domResult->LoadXML(html_entity_decode($xmlResult->item(0)->nodeValue)) or die('File XML non valido!');
134
+ }
135
+ $rCode = $this->domResult->getElementsByTagName($param);
136
+ return $rCode->item(0)->nodeValue;
137
+ }
138
+
139
+ private function printLastRequest()
140
+ {
141
+ return "";
142
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) $this->soapClient->__getLastRequest();
143
+ }
144
+
145
+ private function printLastResponse()
146
+ {
147
+ return "";
148
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) $this->soapClient->__getLastResponse();
149
+ }
150
+
151
+ public function getCustomersFiltered($request)
152
+ {
153
+ $TIMEZONE_STORE = new DateTimeZone(Mage::getStoreConfig("general/locale/timezone"));
154
+ $TIMEZONE_UTC = new DateTimeZone("UTC");
155
+
156
+ //inizializzo l'array dei clienti
157
+ $customersFiltered = array();
158
+
159
+ if (!$request->getRequest()->getParam('mailupCustomerFilteredMod')) {
160
+ //ottengo la collection con tutti i clienti
161
+ $customerCollection = Mage::getModel('customer/customer')
162
+ ->getCollection()
163
+ ->addAttributeToSelect('entity_id')
164
+ ->addAttributeToSelect('group_id')
165
+ ->addAttributeToSelect('created_at')
166
+ ->getSelect()
167
+ ->query();
168
+
169
+ while ($row = $customerCollection->fetch()) {
170
+ $customersFiltered[] = $row;
171
+ }
172
+
173
+ //se richiesto, seleziono solo quelli iscritti alla newsletter di Magento
174
+ if ($request->getRequest()->getParam('mailupSubscribed') > 0) {
175
+ $tempSubscribed = array();
176
+ foreach ($customersFiltered as $customer) {
177
+ $customerItem = Mage::getModel('customer/customer')->load($customer['entity_id']);
178
+ if (Mage::getModel('newsletter/subscriber')->loadByCustomer($customerItem)->isSubscribed()) {
179
+ $tempSubscribed[] = $customer;
180
+ }
181
+ }
182
+ $customersFiltered = array_intersect($tempSubscribed, $customersFiltered);
183
+ }
184
+
185
+ //FILTRO 1 ACQUISTATO: in base al fatto se ha effettuato o meno acquisti: 0 = tutti, 1 = chi ha acquistato, 2 = chi non ha mai acquistato
186
+ $count = 0;
187
+ $result = array();
188
+ $tempPurchased = array();
189
+ $tempNoPurchased = array();
190
+
191
+ if ($request->getRequest()->getParam('mailupCustomers') > 0) {
192
+ foreach ($customersFiltered as $customer) {
193
+ $result[] = $customer;
194
+
195
+ //filtro gli ordini in base al customer id
196
+ $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
197
+
198
+ //aggiungo il cliente ad un determinato array in base a se ha ordinato o meno
199
+ if ($orders->getData()) {
200
+ $tempPurchased[] = $result[$count];
201
+ } else {
202
+ $tempNoPurchased[] = $result[$count];
203
+ }
204
+
205
+ //unsetto la variabile
206
+ unset($orders); //->unsetData();
207
+
208
+ $count++;
209
+ }
210
+
211
+ if ($request->getRequest()->getParam('mailupCustomers') == 1) {
212
+ $customersFiltered = array_intersect($tempPurchased, $customersFiltered);
213
+ } elseif ($request->getRequest()->getParam('mailupCustomers') == 2) {
214
+ $customersFiltered = array_intersect($tempNoPurchased, $customersFiltered);
215
+ }
216
+ }
217
+ //FINE FILTRO 1 ACQUISTATO: testato OK
218
+
219
+ //FILTRO 2 PRODOTTO ACQUISTATO: in base al fatto se ha acquistato un determinato prodotto
220
+ $count = 0;
221
+ $result = array();
222
+ $tempProduct = array();
223
+
224
+ if ($request->getRequest()->getParam('mailupProductSku')) {
225
+ foreach ($customersFiltered as $customer) {
226
+ $result[] = $customer;
227
+
228
+ //filtro gli ordini in base al customer id
229
+ $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
230
+ $purchasedProduct = 0;
231
+
232
+ $mailupProductId = Mage::getModel('catalog/product')->getIdBySku($request->getRequest()->getParam('mailupProductSku'));
233
+
234
+ foreach ($orders->getData() as $order) {
235
+ if (!in_array($order["status"], array("closed", "complete", "processing"))) continue;
236
+ $orderIncrementId = $order['increment_id'];
237
+
238
+ //carico i dati di ogni ordine
239
+ $orderData = Mage::getModel('sales/order')->loadByIncrementID($orderIncrementId);
240
+ $items = $orderData->getAllItems();
241
+ $ids = array();
242
+ foreach ($items as $itemId => $item) {
243
+ $ids[] = $item->getProductId();
244
+ }
245
+
246
+ if (in_array($mailupProductId, $ids)) {
247
+ $purchasedProduct = 1;
248
+ }
249
+ }
250
+
251
+ //aggiungo il cliente ad un determinato array in base a se ha ordinato o meno
252
+ if ($purchasedProduct == 1) {
253
+ $tempProduct[] = $result[$count];
254
+ }
255
+
256
+ //unsetto la variabile
257
+ unset($orders); //->unsetData();
258
+
259
+ $count++;
260
+ }
261
+
262
+ $customersFiltered = array_intersect($tempProduct, $customersFiltered);
263
+ }
264
+ //FINE FILTRO 2 PRODOTTO ACQUISTATO: testato OK
265
+
266
+
267
+ //FILTRO 3 ACQUISTATO IN CATEGORIA: in base al fatto se ha acquistato almeno un prodotto in una determinata categoria
268
+ $count = 0;
269
+ $result = array();
270
+ $tempCategory = array();
271
+
272
+ if ($request->getRequest()->getParam('mailupCategoryId') > 0) {
273
+ foreach ($customersFiltered as $customer) {
274
+ $result[] = $customer;
275
+
276
+ //filtro gli ordini in base al customer id
277
+ $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
278
+ $purchasedCategory = 0;
279
+
280
+ foreach ($orders->getData() as $order) {
281
+ if (!in_array($order["status"], array("closed", "complete", "processing"))) continue;
282
+ $orderIncrementId = $order['increment_id'];
283
+
284
+ //carico i dati di ogni ordine
285
+ $orderData = Mage::getModel('sales/order')->loadByIncrementID($orderIncrementId);
286
+ $items = $orderData->getAllItems();
287
+ $cat_ids = array();
288
+ foreach ($items as $product) {
289
+ if (in_array($request->getRequest()->getParam('mailupCategoryId'), Mage::getResourceSingleton('catalog/product')->getCategoryIds($product))) {
290
+ $tempCategory[] = $result[$count];
291
+ break 2;
292
+ }
293
+ }
294
+ }
295
+
296
+ unset($orders);
297
+ $count++;
298
+ }
299
+
300
+ $customersFiltered = array_intersect($tempCategory, $customersFiltered);
301
+ }
302
+ //FINE FILTRO 3 ACQUISTATO IN CATEGORIA: testato ok
303
+
304
+
305
+ //FILTRO 4 GRUPPO DI CLIENTI
306
+ $count = 0;
307
+ $result = array();
308
+ $tempGroup = array();
309
+
310
+ if ($request->getRequest()->getParam('mailupCustomerGroupId') > 0) {
311
+ foreach ($customersFiltered as $customer) {
312
+ if ($customer['group_id'] == $request->getRequest()->getParam('mailupCustomerGroupId')) {
313
+ $tempGroup[] = $customer;
314
+ }
315
+ }
316
+
317
+ $customersFiltered = array_intersect($tempGroup, $customersFiltered);
318
+ }
319
+ //FINE FILTRO 4 GRUPPO DI CLIENTI: testato ok
320
+
321
+
322
+ //FILTRO 5 PAESE DI PROVENIENZA
323
+ $count = 0;
324
+ $result = array();
325
+ $tempCountry = array();
326
+
327
+ if ($request->getRequest()->getParam('mailupCountry') != '0') {
328
+ foreach ($customersFiltered as $customer) {
329
+ //ottengo la nazione del primary billing address
330
+ $customerItem = Mage::getModel('customer/customer')->load($customer['entity_id']);
331
+ $customerAddress = $customerItem->getPrimaryBillingAddress();
332
+ $countryId = $customerAddress['country_id'];
333
+
334
+ if ($countryId == $request->getRequest()->getParam('mailupCountry')) {
335
+ $tempCountry[] = $customer;
336
+ }
337
+
338
+ //unsetto la variabile
339
+ unset($customerItem); //->unsetData();
340
+ }
341
+
342
+ $customersFiltered = array_intersect($tempCountry, $customersFiltered);
343
+ }
344
+ //FINE FILTRO 5 PAESE DI PROVENIENZA: testato ok
345
+
346
+
347
+ //FILTRO 6 CAP DI PROVENIENZA
348
+ $count = 0;
349
+ $result = array();
350
+ $tempPostCode = array();
351
+
352
+ if ($request->getRequest()->getParam('mailupPostCode')) {
353
+ foreach ($customersFiltered as $customer) {
354
+ //ottengo la nazione del primary billing address
355
+ $customerItem = Mage::getModel('customer/customer')->load($customer['entity_id']);
356
+ $customerAddress = $customerItem->getPrimaryBillingAddress();
357
+ $postCode = $customerAddress['postcode'];
358
+
359
+ if ($postCode == $request->getRequest()->getParam('mailupPostCode')) {
360
+ $tempPostCode[] = $customer;
361
+ }
362
+
363
+ //unsetto la variabile
364
+ unset($customerItem); //->unsetData();
365
+ }
366
+
367
+ $customersFiltered = array_intersect($tempPostCode, $customersFiltered);
368
+ }
369
+ //FINE FILTRO 6 CAP DI PROVENIENZA: testato ok
370
+
371
+
372
+ //FILTRO 7 DATA CREAZIONE CLIENTE
373
+ $count = 0;
374
+ $result = array();
375
+ $tempDate = array();
376
+
377
+ if ($request->getRequest()->getParam('mailupCustomerStartDate') || $request->getRequest()->getParam('mailupCustomerEndDate') ) {
378
+ foreach ($customersFiltered as $customer) {
379
+ $createdAt = $customer['created_at'];
380
+ $createdAt = new DateTime($createdAt, $TIMEZONE_UTC);
381
+ $createdAt->setTimezone($TIMEZONE_STORE);
382
+ $createdAt = (string)$createdAt->format("Y-m-d H:i:s");
383
+ $filterStart = '';
384
+ $filterEnd = '';
385
+
386
+ if ($request->getRequest()->getParam('mailupCustomerStartDate')) {
387
+ $date = Zend_Locale_Format::getDate($request->getRequest()->getParam('mailupCustomerStartDate'), array('locale'=>Mage::app()->getLocale()->getLocale(), 'date_format'=>Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'fix_date'=>true));
388
+ $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
389
+ $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
390
+ $filterStart = "{$date['year']}-{$date['month']}-{$date['day']} 00:00:00";
391
+ }
392
+ if ($request->getRequest()->getParam('mailupCustomerEndDate')) {
393
+ $date = Zend_Locale_Format::getDate($request->getRequest()->getParam('mailupCustomerEndDate'), array('locale'=>Mage::app()->getLocale()->getLocale(), 'date_format'=>Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'fix_date'=>true));
394
+ $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
395
+ $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
396
+ $filterEnd = "{$date['year']}-{$date['month']}-{$date['day']} 23:59:59";
397
+ }
398
+ if ($filterStart && $filterEnd) {
399
+ //compreso tra start e end date
400
+ if ($createdAt >= $filterStart and $createdAt <= $filterEnd) {
401
+ $tempDate[] = $customer;
402
+ }
403
+ } elseif ($filterStart) {
404
+ // >= di start date
405
+ if ($createdAt >= $filterStart) {
406
+ $tempDate[] = $customer;
407
+ }
408
+ } else {
409
+ // <= di end date
410
+ if ($createdAt <= $filterEnd) {
411
+ $tempDate[] = $customer;
412
+ }
413
+ }
414
+ }
415
+
416
+ $customersFiltered = array_intersect($tempDate, $customersFiltered);
417
+ }
418
+ //FINE FILTRO 7 DATA CREAZIONE CLIENTE: testato ok
419
+
420
+
421
+ //FILTRO 8 TOTALE ACQUISTATO
422
+ $count = 0;
423
+ $result = array();
424
+ $tempTotal = array();
425
+
426
+ if ($request->getRequest()->getParam('mailupTotalAmountValue') > 0) {
427
+ foreach ($customersFiltered as $customer) {
428
+ $result[] = $customer;
429
+
430
+ //filtro gli ordini in base al customer id
431
+ $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
432
+
433
+ $totalOrdered = 0;
434
+
435
+ foreach ($orders->getData() as $order) {
436
+ if (!in_array($order["status"], array("closed", "complete", "processing"))) continue;
437
+ $totalOrdered += $order['subtotal'];
438
+ }
439
+
440
+ if ($totalOrdered == $request->getRequest()->getParam('mailupTotalAmountValue') && $request->getRequest()->getParam('mailupTotalAmountCond') == "eq") {
441
+ $tempTotal[] = $result[$count];
442
+ }
443
+
444
+ if ($totalOrdered > $request->getRequest()->getParam('mailupTotalAmountValue') && $request->getRequest()->getParam('mailupTotalAmountCond') == "gt") {
445
+ $tempTotal[] = $result[$count];
446
+ }
447
+
448
+ if ($totalOrdered < $request->getRequest()->getParam('mailupTotalAmountValue') && $request->getRequest()->getParam('mailupTotalAmountCond') == "lt" ) {
449
+ $tempTotal[] = $result[$count];
450
+ }
451
+
452
+ $count++;
453
+
454
+ //unsetto la variabile
455
+ unset($orders); //->unsetData();
456
+ }
457
+
458
+ $customersFiltered = array_intersect($tempTotal, $customersFiltered);
459
+ }
460
+ //FINE FILTRO 8 TOTALE ACQUISTATO: testato ok
461
+
462
+
463
+ //FILTRO 9 DATA ACQUISTATO
464
+ $count = 0;
465
+ $result = array();
466
+ $tempOrderedDateYes = array();
467
+ $tempOrderedDateNo = array();
468
+
469
+ if ($request->getRequest()->getParam('mailupOrderStartDate') || $request->getRequest()->getParam('mailupOrderEndDate') ) {
470
+ foreach ($customersFiltered as $customer) {
471
+ $result[] = $customer;
472
+
473
+ //filtro gli ordini in base al customer id
474
+ $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
475
+
476
+ $orderedDate = 0;
477
+
478
+ foreach ($orders->getData() as $order) {
479
+ if (!in_array($order["status"], array("closed", "complete", "processing"))) continue;
480
+ $createdAt = $order['created_at'];
481
+ $createdAt = new DateTime($createdAt, $TIMEZONE_UTC);
482
+ $createdAt->setTimezone($TIMEZONE_STORE);
483
+ $createdAt = (string)$createdAt->format("Y-m-d H:i:s");
484
+ $filterStart = '';
485
+ $filterEnd = '';
486
+
487
+ if ($request->getRequest()->getParam('mailupOrderStartDate')) {
488
+ $date = Zend_Locale_Format::getDate($request->getRequest()->getParam('mailupOrderStartDate'), array('locale'=>Mage::app()->getLocale()->getLocale(), 'date_format'=>Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'fix_date'=>true));
489
+ $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
490
+ $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
491
+ $filterStart = "{$date['year']}-{$date['month']}-{$date['day']} 00:00:00";
492
+ }
493
+ if ($request->getRequest()->getParam('mailupOrderEndDate')) {
494
+ $date = Zend_Locale_Format::getDate($request->getRequest()->getParam('mailupOrderEndDate'), array('locale'=>Mage::app()->getLocale()->getLocale(), 'date_format'=>Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'fix_date'=>true));
495
+ $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
496
+ $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
497
+ $filterEnd = "{$date['year']}-{$date['month']}-{$date['day']} 23:59:59";
498
+ }
499
+
500
+ if ($filterStart and $filterEnd) {
501
+ //compreso tra start e end date
502
+ if ($createdAt >= $filterStart and $createdAt <= $filterEnd) {
503
+ $orderedDate = 1;
504
+ }
505
+ } elseif ($filterStart) {
506
+ // >= di start date
507
+ if ($createdAt >= $filterStart) {
508
+ $orderedDate = 1;
509
+ }
510
+ } else {
511
+ // <= di end date
512
+ if ($createdAt <= $filterEnd) {
513
+ $orderedDate = 1;
514
+ }
515
+ }
516
+
517
+ //unsetto la variabile
518
+ unset($orders); //->unsetData();
519
+ }
520
+
521
+ if ($orderedDate == 1) {
522
+ $tempOrderedDateYes[] = $result[$count];
523
+ } else {
524
+ $tempOrderedDateNo[] = $result[$count];
525
+ }
526
+
527
+ $count++;
528
+ }
529
+
530
+ if ($request->getRequest()->getParam('mailupOrderYesNo') == 'yes') {
531
+ $customersFiltered = array_intersect($tempOrderedDateYes, $customersFiltered);
532
+ } else {
533
+ $customersFiltered = array_intersect($tempOrderedDateNo, $customersFiltered);
534
+ }
535
+ }
536
+ //FINE FILTRO 9 DATA ACQUISTATO: testato ok
537
+
538
+ } else {
539
+ //GESTISCO LE MODIFICHE MANUALI
540
+ $count = 0;
541
+ $result = array();
542
+ $tempMod = array();
543
+
544
+ $emails = explode("\n", $request->getRequest()->getParam('mailupCustomerFilteredMod'));
545
+
546
+ foreach ($emails as $email) {
547
+ $email = trim($email);
548
+
549
+ if (strstr($email, '@') !== false) {
550
+ $customerModCollection = Mage::getModel('customer/customer')
551
+ ->getCollection()
552
+ ->addAttributeToSelect('email')
553
+ ->addAttributeToFilter('email', $email);
554
+
555
+ $added = 0;
556
+
557
+ foreach ($customerModCollection as $customerMod) {
558
+ $tempMod[] = $customerMod->toArray();
559
+ $added = 1;
560
+ }
561
+
562
+ if ($added == 0) {
563
+ $tempMod[] = array('entity_id'=>0, 'firstname'=>'', 'lastname'=>'', 'email'=>$email);
564
+ }
565
+ }
566
+ }
567
+
568
+ //$customersFiltered = array_intersect($tempMod, $customersFiltered);
569
+ $customersFiltered = $tempMod;
570
+ }
571
+ //FINE GESTISCO LE MODIFICHE MANUALI
572
+
573
+ return $customersFiltered;
574
+ }
575
+
576
+
577
+ public function getFilterHints() {
578
+ $filter_hints = array();
579
+ try {
580
+ // fetch write database connection that is used in Mage_Core module
581
+ $connectionRead = Mage::getSingleton('core/resource')->getConnection('core_read');
582
+
583
+ // now $write is an instance of Zend_Db_Adapter_Abstract
584
+ $result = $connectionRead->query("select * from mailup_filter_hints");
585
+
586
+ while ($row = $result->fetch()) {
587
+ array_push($filter_hints, array('filter_name' => $row['filter_name'], 'hints' => $row['hints']));
588
+ }
589
+ } catch (Exception $e) {
590
+ Mage::log('Exception: '.$e->getMessage(), 0);
591
+ die($e);
592
+ }
593
+
594
+ return $filter_hints;
595
+ }
596
+
597
+ public function saveFilterHint($filter_name, $post) {
598
+ try {
599
+ $hints = '';
600
+ foreach ($post as $k => $v) {
601
+ if ($v!='' && $k!='form_key') {
602
+ if ($hints!='') {
603
+ $hints .= '|';
604
+ }
605
+ $hints .= $k.'='.$v;
606
+ }
607
+ }
608
+ //(e.g. $hints = 'mailupCustomers=2|mailupSubscribed=1';)
609
+
610
+ $connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
611
+
612
+ $connectionWrite->query("INSERT INTO mailup_filter_hints (filter_name, hints) VALUES ('".$filter_name."', '".$hints."')");
613
+ } catch (Exception $e) {
614
+ Mage::log('Exception: '.$e->getMessage(), 0);
615
+ die($e);
616
+ }
617
+ }
618
+
619
+ public function deleteFilterHint($filter_name) {
620
+ try {
621
+ $connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
622
+
623
+ $connectionWrite->query("DELETE FROM mailup_filter_hints WHERE filter_name LIKE '".$filter_name."'");
624
+ } catch (Exception $e) {
625
+ Mage::log('Exception: '.$e->getMessage(), 0);
626
+ die($e);
627
+ }
628
+ }
629
+
630
+ public function getFieldsMapping() {
631
+ $fieldsMappings = array();
632
+ try {
633
+ $connectionRead = Mage::getSingleton('core/resource')->getConnection('core_read');
634
+ return $connectionRead->fetchPairs("select magento_field_name, mailup_field_id from mailup_fields_mapping");
635
+ } catch (Exception $e) {
636
+ Mage::log('Exception: '.$e->getMessage(), 0);
637
+ die($e);
638
+ }
639
+
640
+ return $fieldsMappings;
641
+ }
642
+
643
+ public function saveFieldMapping($post) {
644
+ try {
645
+ $connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
646
+ $connectionWrite->query("DELETE FROM mailup_fields_mapping");
647
+ foreach ($post as $k => $v) {
648
+ if (strlen($v) == 0) continue;
649
+ $connectionWrite->insert("mailup_fields_mapping", array(
650
+ "magento_field_name" => $k,
651
+ "mailup_field_id" => $v
652
+ ));
653
+ }
654
+ } catch (Exception $e) {
655
+ Mage::log('Exception: '.$e->getMessage(), 0);
656
+ die($e);
657
+ }
658
+ }
659
+ }
app/code/local/SevenLike/MailUp/Model/Mysql14/MailUp.php CHANGED
File without changes
app/code/local/SevenLike/MailUp/Model/Mysql14/MailUp/Collection.php CHANGED
File without changes
app/code/local/SevenLike/MailUp/Model/Observer.php CHANGED
@@ -1,5 +1,7 @@
1
<?php
2
3
class SevenLike_MailUp_Model_Observer
4
{
5
const CRON_STRING_PATH = 'crontab/jobs/sevenlike_mailup/schedule/cron_expr';
@@ -58,49 +60,53 @@ class SevenLike_MailUp_Model_Observer
58
if (isset($GLOBALS["__sl_mailup_leggi_utente"])) return $this;
59
$GLOBALS["__sl_mailup_leggi_utente"] = true;
60
61
- $WSDLUrl = 'http://services.mailupnet.it/MailupReport.asmx?WSDL';
62
- $user = Mage::getStoreConfig('newsletter/mailup/username_ws');
63
- $password = Mage::getStoreConfig('newsletter/mailup/password_ws');
64
- $headers = array('User' => $user, 'Password' => $password);
65
- $header = new SOAPHeader("http://ws.mailupnet.it/", 'Authentication', $headers);
66
- $soapclient = new SoapClient($WSDLUrl, array('trace' => 1, 'exceptions' => 1, 'connection_timeout' => 10));
67
- $soapclient->__setSoapHeaders($header);
68
-
69
- $loginData = array ('user' => Mage::getStoreConfig('newsletter/mailup/username_ws'),
70
- 'pwd' => Mage::getStoreConfig('newsletter/mailup/password_ws'),
71
- 'consoleId' => substr(Mage::getStoreConfig('newsletter/mailup/username_ws'), 1));
72
- $result = get_object_vars($soapclient->LoginFromId($loginData));
73
- $xml = simplexml_load_string($result['LoginFromIdResult']);
74
- $errorCode = (string)$xml->errorCode;
75
- $errorDescription = (string)$xml->errorDescription;
76
- $accessKey = (string)$xml->accessKey;
77
-
78
- $result = $soapclient->ReportByUser(array(
79
- "accessKey" => $accessKey,
80
- "email" => $model->getEmail(),
81
- "listID" => Mage::getStoreConfig('newsletter/mailup/list'),
82
- "messageID" => 0
83
- ));
84
- $result = get_object_vars($result);
85
- $xml = simplexml_load_string($result['ReportByUserResult']);
86
-
87
- $stato_registrazione = (string)$xml->Canali->Email;
88
- Mage::log("stato registrazione: " . $stato_registrazione);
89
- if ($stato_registrazione) {
90
- switch (strtolower($stato_registrazione)) {
91
- case "iscritto":
92
- Mage::getModel('newsletter/subscriber')->loadByEmail($model->getEmail())->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED)->save();
93
- $model->setIsSubscribed(1);
94
- $model->save();
95
- break;
96
- case "in attesa":
97
- Mage::getSingleton('core/session')->addNotice(Mage::helper("mailup")->__("Your subscription is waiting for confirmation"));
98
- break;
99
- default:
100
- Mage::getModel('newsletter/subscriber')->loadByEmail($model->getEmail())->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED)->save();
101
- $model->setIsSubscribed(0);
102
- $model->save();
103
}
104
}
105
106
return $this;
@@ -112,17 +118,17 @@ class SevenLike_MailUp_Model_Observer
112
$GLOBALS["__sl_mailup_invia_utente"] = true;
113
114
$model = $observer->getEvent()->getDataObject();
115
- Mage::log($model->getData());
116
$status = Mage::getModel('newsletter/subscriber')->loadByEmail($model->getEmail())->getStatus();
117
118
$module = Mage::app()->getRequest()->getModuleName();
119
$controller = Mage::app()->getRequest()->getControllerName();
120
$action = Mage::app()->getRequest()->getActionName();
121
-
122
- Mage::log("mailup: invia utente");
123
124
if (($module == "customer" and $controller == "account" and $action == "createpost") or ($module == "checkout" and $controller == "onepage" and $action == "saveOrder")) {
125
- Mage::log("SONO in registrazione, LEGGO PRIMA mailup!");
126
//sono in registrazione, controllo lo stato di subscribe magento, se non risulto iscritto leggo lo status da mailup e se sono iscritto lo salvo su magento prima di continuare
127
if (!$status) {
128
//leggo l'utente da mailup
@@ -137,41 +143,44 @@ class SevenLike_MailUp_Model_Observer
137
$console = Mage::getStoreConfig('newsletter/mailup/url_console');
138
$listId = Mage::getStoreConfig('newsletter/mailup/list');
139
140
- if(!class_exists("MailUpWsImport")) $MailUpWsImport = Mage::getModel('mailup/ws');
141
- $wsImport = new MailUpWsImport();
142
- $xmlString = $wsImport->GetNlList();
143
- if (!$xmlString) return $this;
144
-
145
- $xmlString = html_entity_decode($xmlString);
146
- $startLists = strpos($xmlString, '<Lists>');
147
- $endPos = strpos($xmlString, '</Lists>');
148
- $endLists = $endPos + strlen('</Lists>') - $startLists;
149
- $xmlLists = substr($xmlString, $startLists, $endLists);
150
- $xmlLists = str_replace("&", "&amp;", $xmlLists);
151
- $xml = simplexml_load_string($xmlLists);
152
-
153
- foreach ($xml->List as $list) {
154
- if ($list['idList'] == $listId) {
155
- $listGUID = $list["listGUID"];
156
- break;
157
}
158
}
159
- Mage::log("STATO ISCRIZIONE: $status");
160
- if ($status == 1) {
161
- $ws = "http://{$console}/frontend/Xmlsubscribe.aspx";
162
- } else {
163
- $ws = "http://{$console}/frontend/Xmlunsubscribe.aspx";
164
- }
165
-
166
- $ws .= "?ListGuid=" . rawurlencode($listGUID);
167
- $ws .= "&List=" . rawurlencode($listId);
168
- $ws .= "&Email=" . rawurlencode($model->getEmail());
169
-
170
- try {
171
- Mage::log("mailup invio utente $ws");
172
- $result = @file_get_contents($ws);
173
- Mage::log("mailup risultato invio $result");
174
- } catch (Exception $e) {}
175
176
return $this;
177
}
@@ -194,7 +203,6 @@ class SevenLike_MailUp_Model_Observer
194
return;
195
}
196
197
- require_once dirname(__FILE__) . "/Ws.php";
198
$wsimport = new MailUpWsImport();
199
$mapping = $wsimport->getFieldsMapping();
200
if (empty($mapping)) {
@@ -206,4 +214,51 @@ class SevenLike_MailUp_Model_Observer
206
return;
207
}
208
}
209
}
1
<?php
2
3
+ require_once dirname(__FILE__) . "/MailUpWsImport.php";
4
+ require_once dirname(__FILE__) . "/Wssend.php";
5
class SevenLike_MailUp_Model_Observer
6
{
7
const CRON_STRING_PATH = 'crontab/jobs/sevenlike_mailup/schedule/cron_expr';
60
if (isset($GLOBALS["__sl_mailup_leggi_utente"])) return $this;
61
$GLOBALS["__sl_mailup_leggi_utente"] = true;
62
63
+ try {
64
+ $WSDLUrl = 'http://services.mailupnet.it/MailupReport.asmx?WSDL';
65
+ $user = Mage::getStoreConfig('newsletter/mailup/username_ws');
66
+ $password = Mage::getStoreConfig('newsletter/mailup/password_ws');
67
+ $headers = array('User' => $user, 'Password' => $password);
68
+ $header = new SOAPHeader("http://ws.mailupnet.it/", 'Authentication', $headers);
69
+ $soapclient = new SoapClient($WSDLUrl, array('trace' => 1, 'exceptions' => 1, 'connection_timeout' => 10));
70
+ $soapclient->__setSoapHeaders($header);
71
+
72
+ $loginData = array ('user' => Mage::getStoreConfig('newsletter/mailup/username_ws'),
73
+ 'pwd' => Mage::getStoreConfig('newsletter/mailup/password_ws'),
74
+ 'consoleId' => substr(Mage::getStoreConfig('newsletter/mailup/username_ws'), 1));
75
+ $result = get_object_vars($soapclient->LoginFromId($loginData));
76
+ $xml = simplexml_load_string($result['LoginFromIdResult']);
77
+ $errorCode = (string)$xml->errorCode;
78
+ $errorDescription = (string)$xml->errorDescription;
79
+ $accessKey = (string)$xml->accessKey;
80
+
81
+ $result = $soapclient->ReportByUser(array(
82
+ "accessKey" => $accessKey,
83
+ "email" => $model->getEmail(),
84
+ "listID" => Mage::getStoreConfig('newsletter/mailup/list'),
85
+ "messageID" => 0
86
+ ));
87
+ $result = get_object_vars($result);
88
+ $xml = simplexml_load_string($result['ReportByUserResult']);
89
+
90
+ $stato_registrazione = (string)$xml->Canali->Email;
91
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("stato registrazione: " . $stato_registrazione);
92
+ if ($stato_registrazione) {
93
+ switch (strtolower($stato_registrazione)) {
94
+ case "iscritto":
95
+ Mage::getModel('newsletter/subscriber')->loadByEmail($model->getEmail())->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED)->save();
96
+ $model->setIsSubscribed(1);
97
+ $model->save();
98
+ break;
99
+ case "in attesa":
100
+ Mage::getSingleton('core/session')->addNotice(Mage::helper("mailup")->__("Your subscription is waiting for confirmation"));
101
+ break;
102
+ default:
103
+ Mage::getModel('newsletter/subscriber')->loadByEmail($model->getEmail())->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED)->save();
104
+ $model->setIsSubscribed(0);
105
+ $model->save();
106
+ }
107
}
108
+ } catch (Exception $e) {
109
+ Mage::logException($e);
110
}
111
112
return $this;
118
$GLOBALS["__sl_mailup_invia_utente"] = true;
119
120
$model = $observer->getEvent()->getDataObject();
121
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log($model->getData());
122
$status = Mage::getModel('newsletter/subscriber')->loadByEmail($model->getEmail())->getStatus();
123
124
$module = Mage::app()->getRequest()->getModuleName();
125
$controller = Mage::app()->getRequest()->getControllerName();
126
$action = Mage::app()->getRequest()->getActionName();
127
+
128
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("mailup: invia utente");
129
130
if (($module == "customer" and $controller == "account" and $action == "createpost") or ($module == "checkout" and $controller == "onepage" and $action == "saveOrder")) {
131
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("SONO in registrazione, LEGGO PRIMA mailup!");
132
//sono in registrazione, controllo lo stato di subscribe magento, se non risulto iscritto leggo lo status da mailup e se sono iscritto lo salvo su magento prima di continuare
133
if (!$status) {
134
//leggo l'utente da mailup
143
$console = Mage::getStoreConfig('newsletter/mailup/url_console');
144
$listId = Mage::getStoreConfig('newsletter/mailup/list');
145
146
+ try {
147
+ $wsImport = new MailUpWsImport();
148
+ $xmlString = $wsImport->GetNlList();
149
+ if (!$xmlString) return $this;
150
+
151
+ $xmlString = html_entity_decode($xmlString);
152
+ $startLists = strpos($xmlString, '<Lists>');
153
+ $endPos = strpos($xmlString, '</Lists>');
154
+ $endLists = $endPos + strlen('</Lists>') - $startLists;
155
+ $xmlLists = substr($xmlString, $startLists, $endLists);
156
+ $xmlLists = str_replace("&", "&amp;", $xmlLists);
157
+ $xml = simplexml_load_string($xmlLists);
158
+
159
+ foreach ($xml->List as $list) {
160
+ if ($list['idList'] == $listId) {
161
+ $listGUID = $list["listGUID"];
162
+ break;
163
+ }
164
}
165
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("STATO ISCRIZIONE: $status");
166
+ if ($status == 1) {
167
+ $ws = "http://{$console}/frontend/Xmlsubscribe.aspx";
168
+ } else {
169
+ $ws = "http://{$console}/frontend/Xmlunsubscribe.aspx";
170
+ }
171
+
172
+ $ws .= "?ListGuid=" . rawurlencode($listGUID);
173
+ $ws .= "&List=" . rawurlencode($listId);
174
+ $ws .= "&Email=" . rawurlencode($model->getEmail());
175
+
176
+ try {
177
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("mailup invio utente $ws");
178
+ $result = @file_get_contents($ws);
179
+ if (Mage::getStoreConfig('newsletter/mailup/enable_log')) Mage::log("mailup risultato invio $result");
180
+ } catch (Exception $e) {}
181
+ } catch (Exception $e) {
182
+ Mage::logException($e);
183
}
184
185
return $this;
186
}
203
return;
204
}
205
206
$wsimport = new MailUpWsImport();
207
$mapping = $wsimport->getFieldsMapping();
208
if (empty($mapping)) {
214
return;
215
}
216
}
217
+
218
+ public function subscribeDuringCheckout()
219
+ {
220
+ if (@$_REQUEST["mailup_subscribe2"]) {
221
+ $order_id = Mage::getSingleton("checkout/session")->getLastRealOrderId();
222
+ $order = Mage::getModel("sales/order")->loadByIncrementId($order_id);
223
+ try {
224
+ Mage::getModel("newsletter/subscriber")->subscribe($order->getCustomerEmail());
225
+ } catch (Exception $e) {}
226
+ }
227
+ }
228
+
229
+ public function prepareOrderForDataSync($observer)
230
+ {
231
+ $order = $observer->getEvent()->getOrder();
232
+ $customer_id = $order->getCustomerId();
233
+ if ($customer_id) self::setCustomerForDataSync($customer_id);
234
+ }
235
+
236
+ public function prepareCustomerForDataSync($observer)
237
+ {
238
+ $customer = $observer->getEvent()->getCustomer();
239
+ $customer_id = $customer->getId();
240
+ if ($customer_id) self::setCustomerForDataSync($customer_id);
241
+ }
242
+
243
+ private static function setCustomerForDataSync($customer_id)
244
+ {
245
+ if (!$customer_id) return false;
246
+
247
+ $db_write = Mage::getSingleton('core/resource')->getConnection('core_write');
248
+ try {
249
+ $db_write->insert("mailup_sync", array(
250
+ "customer_id" => $customer_id,
251
+ "entity" => "customer",
252
+ "job_id" => 0,
253
+ "needs_sync" => true,
254
+ "last_sync" => null
255
+ ));
256
+ } catch (Exception $e) {
257
+ $db_write->update("mailup_sync", array(
258
+ "needs_sync" => true
259
+ ), "customer_id=$customer_id AND entity='customer' AND job_id=0");
260
+ }
261
+
262
+ return true;
263
+ }
264
}
app/code/local/SevenLike/MailUp/Model/Webserviceusernamevalidator.php CHANGED
File without changes
app/code/local/SevenLike/MailUp/Model/Ws.php CHANGED
@@ -1,648 +1,3 @@
1
<?php
2
3
- class MailUpWsImport
4
- {
5
- protected $ns = "http://ws.mailupnet.it/";
6
-
7
- //protected $WSDLUrl = "http://g4a0.s03.it/services/WSMailUpImport.asmx?WSDL";
8
- //protected $headers = array("User" => "a7410", "Password" => "GA6VAN0W");
9
- protected $rCode;
10
- private $soapClient;
11
- private $xmlResponse;
12
- protected $domResult;
13
-
14
- function __construct() {
15
- $urlConsole = Mage::getStoreConfig('newsletter/mailup/url_console');
16
- $WSDLUrl = 'http://'. $urlConsole .'/services/WSMailUpImport.asmx?WSDL';
17
- $user = Mage::getStoreConfig('newsletter/mailup/username_ws');
18
- $password = Mage::getStoreConfig('newsletter/mailup/password_ws');
19
- $headers = array('User' => $user, 'Password' => $password);
20
- $this->header = new SOAPHeader($this->ns, 'Authentication', $headers);
21
-
22
- try {
23
- $this->soapClient = new SoapClient($WSDLUrl, array('trace' => 1, 'exceptions' => 1, 'connection_timeout' => 10));
24
- $this->soapClient->__setSoapHeaders($this->header);
25
- } catch (Exception $e) {
26
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper("mailup")->__("Unable to connect to MailUp console"));
27
- }
28
- }
29
-
30
- function __destruct() {
31
- unset($this->soapClient);
32
- }
33
-
34
- public function getFunctions() {
35
- print_r($this->soapClient->__getFunctions());
36
- }
37
-
38
- public function creaGruppo($newGroup) {
39
- if (!is_object($this->soapClient)) return false;
40
- try {
41
- $this->soapClient->CreateGroup($newGroup);
42
- $this-> printLastRequest();
43
- $this->printLastResponse();
44
- return $this->readReturnCode('CreateGroup', 'ReturnCode');
45
- } catch (SoapFault $soapFault) {
46
- Mage::log('SOAP error', 0);
47
- Mage::log($soapFault, 0);
48
- }
49
- }
50
-
51
- public function GetNlList() {
52
- if (!is_object($this->soapClient)) return false;
53
- try {
54
- $this->soapClient->GetNlLists();
55
- $this->printLastRequest();
56
- $this->printLastResponse();
57
- $result = $this->soapClient->__getLastResponse();
58
- Mage::log($result, 0);
59
- return $result;
60
- } catch (SoapFault $soapFault) {
61
- Mage::log('SOAP error', 0);
62
- Mage::log($soapFault, 0);
63
- }
64
- }
65
-
66
- public function newImportProcess($importProcessData) {
67
- if (!is_object($this->soapClient)) return false;
68
- try {
69
- $this->soapClient->NewImportProcess($importProcessData);
70
- return $this->readReturnCode('NewImportProcess', 'ReturnCode');
71
- } catch (SoapFault $soapFault) {
72
- Mage::log('SOAP error', 0);
73
- Mage::log($soapFault, 0);
74
- }
75
- }
76
-
77
- public function startProcess($processData) {
78
- if (!is_object($this->soapClient)) return false;
79
- try {
80
- $this->soapClient->StartProcess($processData);
81
- //echo "<br />ReturnCode: ". $this->readReturnCode("StartProcess","ReturnCode")."<br />";
82
- } catch (SoapFault $soapFault) {
83
- Mage::log('SOAP error', 0);
84
- Mage::log($soapFault, 0);
85
- }
86
- }
87
-
88
- public function getProcessDetail($processData) {
89
- if (!is_object($this->soapClient)) return false;
90
- try {
91
- Mage::log($this->soapClient->GetProcessDetails($processData), 0);
92
- //echo "<br />ReturnCode: ". $this->readReturnCode("GetProcessDetails","ReturnCode")."<br />";
93
- //echo "<br />IsRunning: ". $this->readReturnCode("GetProcessDetails","IsRunning")."<br />";
94
- //echo "<br />StartDate: ". $this->readReturnCode("GetProcessDetails","StartDate")."<br />";
95
- } catch (SoapFault $soapFault) {
96
- Mage::log('SOAP error', 0);
97
- Mage::log($soapFault, 0);
98
- }
99
- }
100
-
101
- public function startImportProcesses($processData) {
102
- if (!is_object($this->soapClient)) return false;
103
- try {
104
- $this->soapClient->StartImportProcesses($processData);
105
- $this-> printLastRequest();
106
- $this->printLastResponse();
107
- //echo "<br />ReturnCode: ". $this->readReturnCode("StartImportProcesses","ReturnCode")."<br />";
108
- } catch (SoapFault $soapFault) {
109
- Mage::log('SOAP error', 0);
110
- Mage::log($soapFault, 0);
111
- }
112
- }
113
-
114
- private function readReturnCode($func, $param) {
115
- if (!is_object($this->soapClient)) return false;
116
-
117
- static $func_in = ''; //static variable to test xmlResponse update
118
- if ($func_in != $func) {//(!isset($this->xmlResponse))
119
- $func_in = $func;
120
- //prendi l'XML di ritorno se non l'ho già preso
121
- $this->xmlResponse = $this->soapClient->__getLastResponse();
122
-
123
- $dom = new DomDocument();
124
- $dom->loadXML($this->xmlResponse) or die('File XML non valido!');
125
- $xmlResult = $dom->getElementsByTagName($func.'Result');
126
-
127
- $this->domResult = new DomDocument();
128
- $this->domResult->LoadXML(html_entity_decode($xmlResult->item(0)->nodeValue)) or die('File XML non valido!');
129
- }
130
- $rCode = $this->domResult->getElementsByTagName($param);
131
- return $rCode->item(0)->nodeValue;
132
- }
133
-
134
- private function printLastRequest() {
135
- //echo "<br>Request :<br>". htmlentities($this->soapClient->__getLastRequest()). "<br>";
136
- }
137
-
138
- private function printLastResponse() {
139
- //echo "<br />XMLResponse: " . $this->soapClient->__getLastResponse() . "<br />";
140
- }
141
-
142
- public function getCustomersFiltered($request) {
143
- $TIMEZONE_STORE = new DateTimeZone(Mage::getStoreConfig("general/locale/timezone"));
144
- $TIMEZONE_UTC = new DateTimeZone("UTC");
145
-
146
- //inizializzo l'array dei clienti
147
- $customersFiltered = array();
148
-
149
- if (!$request->getRequest()->getParam('mailupCustomerFilteredMod')) {
150
- //ottengo la collection con tutti i clienti
151
- $customerCollection = Mage::getModel('customer/customer')
152
- ->getCollection()
153
- ->addAttributeToSelect('entity_id')
154
- ->addAttributeToSelect('group_id')
155
- ->addAttributeToSelect('created_at');
156
-
157
- //inizializzo l'array dei clienti filtrati con tutti i clienti
158
- foreach ($customerCollection as $customer) {
159
- $customersFiltered[] = $customer->toArray();
160
- }
161
-
162
- //se richiesto, seleziono solo quelli iscritti alla newsletter di Magento
163
- if ($request->getRequest()->getParam('mailupSubscribed') > 0) {
164
- $tempSubscribed = array();
165
- foreach ($customersFiltered as $customer) {
166
- $customerItem = Mage::getModel('customer/customer')->load($customer['entity_id']);
167
- if (Mage::getModel('newsletter/subscriber')->loadByCustomer($customerItem)->isSubscribed()) {
168
- $tempSubscribed[] = $customer;
169
- }
170
- }
171
- $customersFiltered = array_intersect($tempSubscribed, $customersFiltered);
172
- }
173
-
174
- //FILTRO 1 ACQUISTATO: in base al fatto se ha effettuato o meno acquisti: 0 = tutti, 1 = chi ha acquistato, 2 = chi non ha mai acquistato
175
- $count = 0;
176
- $result = array();
177
- $tempPurchased = array();
178
- $tempNoPurchased = array();
179
-
180
- if ($request->getRequest()->getParam('mailupCustomers') > 0) {
181
- foreach ($customersFiltered as $customer) {
182
- $result[] = $customer;
183
-
184
- //filtro gli ordini in base al customer id
185
- $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
186
-
187
- //aggiungo il cliente ad un determinato array in base a se ha ordinato o meno
188
- if ($orders->getData()) {
189
- $tempPurchased[] = $result[$count];
190
- } else {
191
- $tempNoPurchased[] = $result[$count];
192
- }
193
-
194
- //unsetto la variabile
195
- unset($orders); //->unsetData();
196
-
197
- $count++;
198
- }
199
-
200
- if ($request->getRequest()->getParam('mailupCustomers') == 1) {
201
- $customersFiltered = array_intersect($tempPurchased, $customersFiltered);
202
- } elseif ($request->getRequest()->getParam('mailupCustomers') == 2) {
203
- $customersFiltered = array_intersect($tempNoPurchased, $customersFiltered);
204
- }
205
- }
206
- //FINE FILTRO 1 ACQUISTATO: testato OK
207
-
208
- //FILTRO 2 PRODOTTO ACQUISTATO: in base al fatto se ha acquistato un determinato prodotto
209
- $count = 0;
210
- $result = array();
211
- $tempProduct = array();
212
-
213
- if ($request->getRequest()->getParam('mailupProductSku')) {
214
- foreach ($customersFiltered as $customer) {
215
- $result[] = $customer;
216
-
217
- //filtro gli ordini in base al customer id
218
- $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
219
- $purchasedProduct = 0;
220
-
221
- $mailupProductId = Mage::getModel('catalog/product')->getIdBySku($request->getRequest()->getParam('mailupProductSku'));
222
-
223
- foreach ($orders->getData() as $order) {
224
- if (!in_array($order["status"], array("closed", "complete", "processing"))) continue;
225
- $orderIncrementId = $order['increment_id'];
226
-
227
- //carico i dati di ogni ordine
228
- $orderData = Mage::getModel('sales/order')->loadByIncrementID($orderIncrementId);
229
- $items = $orderData->getAllItems();
230
- $ids = array();
231
- foreach ($items as $itemId => $item) {
232
- $ids[] = $item->getProductId();
233
- }
234
-
235
- if (in_array($mailupProductId, $ids)) {
236
- $purchasedProduct = 1;
237
- }
238
- }
239
-
240
- //aggiungo il cliente ad un determinato array in base a se ha ordinato o meno
241
- if ($purchasedProduct == 1) {
242
- $tempProduct[] = $result[$count];
243
- }
244
-
245
- //unsetto la variabile
246
- unset($orders); //->unsetData();
247
-
248
- $count++;
249
- }
250
-
251
- $customersFiltered = array_intersect($tempProduct, $customersFiltered);
252
- }
253
- //FINE FILTRO 2 PRODOTTO ACQUISTATO: testato OK
254
-
255
-
256
- //FILTRO 3 ACQUISTATO IN CATEGORIA: in base al fatto se ha acquistato almeno un prodotto in una determinata categoria
257
- $count = 0;
258
- $result = array();
259
- $tempCategory = array();
260
-
261
- if ($request->getRequest()->getParam('mailupCategoryId') > 0) {
262
- foreach ($customersFiltered as $customer) {
263
- $result[] = $customer;
264
-
265
- //filtro gli ordini in base al customer id
266
- $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
267
- $purchasedCategory = 0;
268
-
269
- foreach ($orders->getData() as $order) {
270
- if (!in_array($order["status"], array("closed", "complete", "processing"))) continue;
271
- $orderIncrementId = $order['increment_id'];
272
-
273
- //carico i dati di ogni ordine
274
- $orderData = Mage::getModel('sales/order')->loadByIncrementID($orderIncrementId);
275
- $items = $orderData->getAllItems();
276
- $cat_ids = array();
277
- foreach ($items as $product) {
278
- if (in_array($request->getRequest()->getParam('mailupCategoryId'), Mage::getResourceSingleton('catalog/product')->getCategoryIds($product))) {
279
- $tempCategory[] = $result[$count];
280
- break 2;
281
- }
282
- }
283
- }
284
-
285
- unset($orders);
286
- $count++;
287
- }
288
-
289
- $customersFiltered = array_intersect($tempCategory, $customersFiltered);
290
- }
291
- //FINE FILTRO 3 ACQUISTATO IN CATEGORIA: testato ok
292
-
293
-
294
- //FILTRO 4 GRUPPO DI CLIENTI
295
- $count = 0;
296
- $result = array();
297
- $tempGroup = array();
298
-
299
- if ($request->getRequest()->getParam('mailupCustomerGroupId') > 0) {
300
- foreach ($customersFiltered as $customer) {
301
- if ($customer['group_id'] == $request->getRequest()->getParam('mailupCustomerGroupId')) {
302
- $tempGroup[] = $customer;
303
- }
304
- }
305
-
306
- $customersFiltered = array_intersect($tempGroup, $customersFiltered);
307
- }
308
- //FINE FILTRO 4 GRUPPO DI CLIENTI: testato ok
309
-
310
-
311
- //FILTRO 5 PAESE DI PROVENIENZA
312
- $count = 0;
313
- $result = array();
314
- $tempCountry = array();
315
-
316
- if ($request->getRequest()->getParam('mailupCountry') != '0') {
317
- foreach ($customersFiltered as $customer) {
318
- //ottengo la nazione del primary billing address
319
- $customerItem = Mage::getModel('customer/customer')->load($customer['entity_id']);
320
- $customerAddress = $customerItem->getPrimaryBillingAddress();
321
- $countryId = $customerAddress['country_id'];
322
-
323
- if ($countryId == $request->getRequest()->getParam('mailupCountry')) {
324
- $tempCountry[] = $customer;
325
- }
326
-
327
- //unsetto la variabile
328
- unset($customerItem); //->unsetData();
329
- }
330
-
331
- $customersFiltered = array_intersect($tempCountry, $customersFiltered);
332
- }
333
- //FINE FILTRO 5 PAESE DI PROVENIENZA: testato ok
334
-
335
-
336
- //FILTRO 6 CAP DI PROVENIENZA
337
- $count = 0;
338
- $result = array();
339
- $tempPostCode = array();
340
-
341
- if ($request->getRequest()->getParam('mailupPostCode')) {
342
- foreach ($customersFiltered as $customer) {
343
- //ottengo la nazione del primary billing address
344
- $customerItem = Mage::getModel('customer/customer')->load($customer['entity_id']);
345
- $customerAddress = $customerItem->getPrimaryBillingAddress();
346
- $postCode = $customerAddress['postcode'];
347
-
348
- if ($postCode == $request->getRequest()->getParam('mailupPostCode')) {
349
- $tempPostCode[] = $customer;
350
- }
351
-
352
- //unsetto la variabile
353
- unset($customerItem); //->unsetData();
354
- }
355
-
356
- $customersFiltered = array_intersect($tempPostCode, $customersFiltered);
357
- }
358
- //FINE FILTRO 6 CAP DI PROVENIENZA: testato ok
359
-
360
-
361
- //FILTRO 7 DATA CREAZIONE CLIENTE
362
- $count = 0;
363
- $result = array();
364
- $tempDate = array();
365
-
366
- if ($request->getRequest()->getParam('mailupCustomerStartDate') || $request->getRequest()->getParam('mailupCustomerEndDate') ) {
367
- foreach ($customersFiltered as $customer) {
368
- $createdAt = $customer['created_at'];
369
- $createdAt = new DateTime($createdAt, $TIMEZONE_UTC);
370
- $createdAt->setTimezone($TIMEZONE_STORE);
371
- $createdAt = (string)$createdAt->format("Y-m-d H:i:s");
372
- $filterStart = '';
373
- $filterEnd = '';
374
-
375
- if ($request->getRequest()->getParam('mailupCustomerStartDate')) {
376
- $date = Zend_Locale_Format::getDate($request->getRequest()->getParam('mailupCustomerStartDate'), array('locale'=>Mage::app()->getLocale()->getLocale(), 'date_format'=>Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'fix_date'=>true));
377
- $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
378
- $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
379
- $filterStart = "{$date['year']}-{$date['month']}-{$date['day']} 00:00:00";
380
- }
381
- if ($request->getRequest()->getParam('mailupCustomerEndDate')) {
382
- $date = Zend_Locale_Format::getDate($request->getRequest()->getParam('mailupCustomerEndDate'), array('locale'=>Mage::app()->getLocale()->getLocale(), 'date_format'=>Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'fix_date'=>true));
383
- $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
384
- $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
385
- $filterEnd = "{$date['year']}-{$date['month']}-{$date['day']} 23:59:59";
386
- }
387
- if ($filterStart && $filterEnd) {
388
- //compreso tra start e end date
389
- if ($createdAt >= $filterStart and $createdAt <= $filterEnd) {
390
- $tempDate[] = $customer;
391
- }
392
- } elseif ($filterStart) {
393
- // >= di start date
394
- if ($createdAt >= $filterStart) {
395
- $tempDate[] = $customer;
396
- }
397
- } else {
398
- // <= di end date
399
- if ($createdAt <= $filterEnd) {
400
- $tempDate[] = $customer;
401
- }
402
- }
403
- }
404
-
405
- $customersFiltered = array_intersect($tempDate, $customersFiltered);
406
- }
407
- //FINE FILTRO 7 DATA CREAZIONE CLIENTE: testato ok
408
-
409
-
410
- //FILTRO 8 TOTALE ACQUISTATO
411
- $count = 0;
412
- $result = array();
413
- $tempTotal = array();
414
-
415
- if ($request->getRequest()->getParam('mailupTotalAmountValue') > 0) {
416
- foreach ($customersFiltered as $customer) {
417
- $result[] = $customer;
418
-
419
- //filtro gli ordini in base al customer id
420
- $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
421
-
422
- $totalOrdered = 0;
423
-
424
- foreach ($orders->getData() as $order) {
425
- if (!in_array($order["status"], array("closed", "complete", "processing"))) continue;
426
- $totalOrdered += $order['subtotal'];
427
- }
428
-
429
- if ($totalOrdered == $request->getRequest()->getParam('mailupTotalAmountValue') && $request->getRequest()->getParam('mailupTotalAmountCond') == "eq") {
430
- $tempTotal[] = $result[$count];
431
- }
432
-
433
- if ($totalOrdered > $request->getRequest()->getParam('mailupTotalAmountValue') && $request->getRequest()->getParam('mailupTotalAmountCond') == "gt") {
434
- $tempTotal[] = $result[$count];
435
- }
436
-
437
- if ($totalOrdered < $request->getRequest()->getParam('mailupTotalAmountValue') && $request->getRequest()->getParam('mailupTotalAmountCond') == "lt" ) {
438
- $tempTotal[] = $result[$count];
439
- }
440
-
441
- $count++;
442
-
443
- //unsetto la variabile
444
- unset($orders); //->unsetData();
445
- }
446
-
447
- $customersFiltered = array_intersect($tempTotal, $customersFiltered);
448
- }
449
- //FINE FILTRO 8 TOTALE ACQUISTATO: testato ok
450
-
451
-
452
- //FILTRO 9 DATA ACQUISTATO
453
- $count = 0;
454
- $result = array();
455
- $tempOrderedDateYes = array();
456
- $tempOrderedDateNo = array();
457
-
458
- if ($request->getRequest()->getParam('mailupOrderStartDate') || $request->getRequest()->getParam('mailupOrderEndDate') ) {
459
- foreach ($customersFiltered as $customer) {
460
- $result[] = $customer;
461
-
462
- //filtro gli ordini in base al customer id
463
- $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id', $result[$count]['entity_id']);
464
-
465
- $orderedDate = 0;
466
-
467
- foreach ($orders->getData() as $order) {
468
- if (!in_array($order["status"], array("closed", "complete", "processing"))) continue;
469
- $createdAt = $order['created_at'];
470
- $createdAt = new DateTime($createdAt, $TIMEZONE_UTC);
471
- $createdAt->setTimezone($TIMEZONE_STORE);
472
- $createdAt = (string)$createdAt->format("Y-m-d H:i:s");
473
- $filterStart = '';
474
- $filterEnd = '';
475
-
476
- if ($request->getRequest()->getParam('mailupOrderStartDate')) {
477
- $date = Zend_Locale_Format::getDate($request->getRequest()->getParam('mailupOrderStartDate'), array('locale'=>Mage::app()->getLocale()->getLocale(), 'date_format'=>Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'fix_date'=>true));
478
- $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
479
- $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
480
- $filterStart = "{$date['year']}-{$date['month']}-{$date['day']} 00:00:00";
481
- }
482
- if ($request->getRequest()->getParam('mailupOrderEndDate')) {
483
- $date = Zend_Locale_Format::getDate($request->getRequest()->getParam('mailupOrderEndDate'), array('locale'=>Mage::app()->getLocale()->getLocale(), 'date_format'=>Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'fix_date'=>true));
484
- $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
485
- $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
486
- $filterEnd = "{$date['year']}-{$date['month']}-{$date['day']} 23:59:59";
487
- }
488
-
489
- if ($filterStart and $filterEnd) {
490
- //compreso tra start e end date
491
- if ($createdAt >= $filterStart and $createdAt <= $filterEnd) {
492
- $orderedDate = 1;
493
- }
494
- } elseif ($filterStart) {
495
- // >= di start date
496
- if ($createdAt >= $filterStart) {
497
- $orderedDate = 1;
498
- }
499
- } else {
500
- // <= di end date
501
- if ($createdAt <= $filterEnd) {
502
- $orderedDate = 1;
503
- }
504
- }
505
-
506
- //unsetto la variabile
507
- unset($orders); //->unsetData();
508
- }
509
-
510
- if ($orderedDate == 1) {
511
- $tempOrderedDateYes[] = $result[$count];
512
- } else {
513
- $tempOrderedDateNo[] = $result[$count];
514
- }
515
-
516
- $count++;
517
- }
518
-
519
- if ($request->getRequest()->getParam('mailupOrderYesNo') == 'yes') {
520
- $customersFiltered = array_intersect($tempOrderedDateYes, $customersFiltered);
521
- } else {
522
- $customersFiltered = array_intersect($tempOrderedDateNo, $customersFiltered);
523
- }
524
- }
525
- //FINE FILTRO 9 DATA ACQUISTATO: testato ok
526
-
527
- } else {
528
- //GESTISCO LE MODIFICHE MANUALI
529
- $count = 0;
530
- $result = array();
531
- $tempMod = array();
532
-
533
- $emails = explode("\n", $request->getRequest()->getParam('mailupCustomerFilteredMod'));
534
-
535
- foreach ($emails as $email) {
536
- $email = trim($email);
537
-
538
- if (strstr($email, '@') !== false) {
539
- $customerModCollection = Mage::getModel('customer/customer')
540
- ->getCollection()
541
- ->addAttributeToSelect('email')
542
- ->addAttributeToFilter('email', $email);
543
-
544
- $added = 0;
545
-
546
- foreach ($customerModCollection as $customerMod) {
547
- $tempMod[] = $customerMod->toArray();
548
- $added = 1;
549
- }
550
-
551
- if ($added == 0) {
552
- $tempMod[] = array('entity_id'=>0, 'firstname'=>'', 'lastname'=>'', 'email'=>$email);
553
- }
554
- }
555
- }
556
-
557
- //$customersFiltered = array_intersect($tempMod, $customersFiltered);
558
- $customersFiltered = $tempMod;
559
- }
560
- //FINE GESTISCO LE MODIFICHE MANUALI
561
-
562
- return $customersFiltered;
563
- }
564
-
565
-
566
- public function getFilterHints() {
567
- $filter_hints = array();
568
- try {
569
- // fetch write database connection that is used in Mage_Core module
570
- $connectionRead = Mage::getSingleton('core/resource')->getConnection('core_read');
571
-
572
- // now $write is an instance of Zend_Db_Adapter_Abstract
573
- $result = $connectionRead->query("select * from mailup_filter_hints");
574
-
575
- while ($row = $result->fetch()) {
576
- array_push($filter_hints, array('filter_name' => $row['filter_name'], 'hints' => $row['hints']));
577
- }
578
- } catch (Exception $e) {
579
- Mage::log('Exception: '.$e->getMessage(), 0);
580
- die($e);
581
- }
582
-
583
- return $filter_hints;
584
- }
585
-
586
- public function saveFilterHint($filter_name, $post) {
587
- try {
588
- $hints = '';
589
- foreach ($post as $k => $v) {
590
- if ($v!='' && $k!='form_key') {
591
- if ($hints!='') {
592
- $hints .= '|';
593
- }
594
- $hints .= $k.'='.$v;
595
- }
596
- }
597
- //(e.g. $hints = 'mailupCustomers=2|mailupSubscribed=1';)
598
-
599
- $connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
600
-
601
- $connectionWrite->query("INSERT INTO mailup_filter_hints (filter_name, hints) VALUES ('".$filter_name."', '".$hints."')");
602
- } catch (Exception $e) {
603
- Mage::log('Exception: '.$e->getMessage(), 0);
604
- die($e);
605
- }
606
- }
607
-
608
- public function deleteFilterHint($filter_name) {
609
- try {
610
- $connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
611
-
612
- $connectionWrite->query("DELETE FROM mailup_filter_hints WHERE filter_name LIKE '".$filter_name."'");
613
- } catch (Exception $e) {
614
- Mage::log('Exception: '.$e->getMessage(), 0);
615
- die($e);
616
- }
617
- }
618
-
619
- public function getFieldsMapping() {
620
- $fieldsMappings = array();
621
- try {
622
- $connectionRead = Mage::getSingleton('core/resource')->getConnection('core_read');
623
- return $connectionRead->fetchPairs("select magento_field_name, mailup_field_id from mailup_fields_mapping");
624
- } catch (Exception $e) {
625
- Mage::log('Exception: '.$e->getMessage(), 0);
626
- die($e);
627
- }
628
-
629
- return $fieldsMappings;
630
- }
631
-
632
- public function saveFieldMapping($post) {
633
- try {
634
- $connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
635
- $connectionWrite->query("DELETE FROM mailup_fields_mapping");
636
- foreach ($post as $k => $v) {
637
- if (strlen($v) == 0) continue;
638
- $connectionWrite->insert("mailup_fields_mapping", array(
639
- "magento_field_name" => $k,
640
- "mailup_field_id" => $v
641
- ));
642
- }
643
- } catch (Exception $e) {
644
- Mage::log('Exception: '.$e->getMessage(), 0);
645
- die($e);
646
- }
647
- }
648
- }
1
<?php
2
3
+ // this file is needed for backward compatibility