MailUp - Version 2.0.2

Version Notes

Changelog:


  • a bug with "newsletter only" subscribers was solved

Download this release

Release Info

Developer Sevenlike
Extension MailUp
Version 2.0.2
Comparing to
See all releases


Code changes from version 2.0.0 to 2.0.2

app/code/local/SevenLike/MailUp/Helper/Data.php CHANGED
@@ -1,205 +1,205 @@
1
  <?php
2
  class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
3
 
4
- public static function getCustomersData() {
5
- Mage::log('Getting customers data', 0);
6
- $dateFormat = 'm/d/y h:i:s';
7
- $lastDateTime = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-7*3600*24);
8
- $thirtyDaysAgo = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-30*3600*24);
9
- $twelveMonthsAgo = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-365*3600*24);
10
-
11
- $toSend = array();
12
-
13
- //ottengo la collection con tutti i clienti
14
- $customerCollection = Mage::getModel('customer/customer')->getCollection();
15
- foreach ($customerCollection as $customer) {
16
- $currentCustomerId = $customer->getId();
17
  $i = $customer->getEmail();
18
- Mage::log('Customer with id '.$currentCustomerId, 0);
19
- $customer = Mage::getModel('customer/customer')->load($currentCustomerId);
20
-
21
- //recupero gli ordini del cliente corrente
22
- $allOrdersTotalAmount = 0;
23
- $allOrdersDateTimes = array();
24
- $allOrdersTotals = array();
25
- $allOrdersIds = array();
26
- $allProductsIds = array();
27
- $last30daysOrdersAmount = 0;
28
- $last12monthsOrdersAmount = 0;
29
  $lastShipmentOrderId = null;
30
  $lastShipmentOrderDate = null;
31
 
32
- Mage::log('Parsing orders of customer with id '.$currentCustomerId, 0);
33
- $orders = Mage::getModel('sales/order')
34
- ->getCollection()
35
- ->addAttributeToFilter('customer_id', $currentCustomerId);
36
- foreach ($orders as $order) {
37
- $currentOrderTotal = floatval($order->getGrandTotal());
38
- $allOrdersTotalAmount += $currentOrderTotal;
39
-
40
- $currentOrderCreationDate = $order->getCreatedAt();
41
- if ($currentOrderCreationDate > $thirtyDaysAgo) {
42
- $last30daysOrdersAmount += $currentOrderTotal;
43
-
44
- }
45
- if ($currentOrderCreationDate > $twelveMonthsAgo) {
46
- $last12monthsOrdersAmount += $currentOrderTotal;
47
- }
48
-
49
- $currentOrderTotal = self::_formatPrice($currentOrderTotal);
50
-
51
- $currentOrderId = $order->getIncrementId();
52
- $allOrdersTotals[$currentOrderId] = $currentOrderTotal;
53
- $allOrdersDateTimes[$currentOrderId] = $currentOrderCreationDate;
54
- $allOrdersIds[$currentOrderId] = $currentOrderId;
55
-
56
  if ($order->hasShipments() and ($order->getId()>$lastShipmentOrderId)) {
57
  $lastShipmentOrderId = $order->getId();
58
  $lastShipmentOrderDate = self::_retriveDateFromDatetime($order->getCreatedAt());
59
  }
60
 
61
- $items = $order->getAllItems();
62
- foreach ($items as $item) {
63
- $allProductsIds[] = $item->getProductId();
64
- }
65
- }
66
-
67
- $toSend[$i]['TotaleFatturatoUltimi30gg'] = self::_formatPrice($last30daysOrdersAmount);
68
- $toSend[$i]['TotaleFatturatoUltimi12Mesi'] = self::_formatPrice($last12monthsOrdersAmount);
69
- $toSend[$i]['IDTuttiProdottiAcquistati'] = implode(',', $allProductsIds);
70
-
71
- ksort($allOrdersDateTimes);
72
- ksort($allOrdersTotals);
73
- ksort($allOrdersIds);
74
-
75
- //recupero i carrelli abbandonati del cliente
76
- Mage::log('Parsing abandoned carts of customer with id '.$currentCustomerId, 0);
77
- $cartCollection = Mage::getResourceModel('reports/quote_collection');
78
- $cartCollection->prepareForAbandonedReport(array(1));
79
- $cartCollection->addFieldToFilter('customer_id', $currentCustomerId);
80
- $cartCollection->load();
81
-
82
- $datetimeCart = null;
83
- if (! empty($cartCollection)) {
84
- $lastCart = end($cartCollection);
85
-
86
- $toSend[$i]['TotaleCarrelloAbbandonato'] = '';
87
- $toSend[$i]['DataCarrelloAbbandonato'] = '';
88
- $toSend[$i]['IDCarrelloAbbandonato'] = '';
89
-
90
- if (! empty($lastCart)) {
91
- Mage::log('Customer with id '.$currentCustomerId .' has abandoned cart', 0);
92
- $datetimeCart = $lastCart->getUpdatedAt();
93
- $toSend[$i]['TotaleCarrelloAbbandonato'] = self::_formatPrice($lastCart->getGrandTotal());
94
- $toSend[$i]['DataCarrelloAbbandonato'] = self::_retriveDateFromDatetime($datetimeCart);
95
- $toSend[$i]['IDCarrelloAbbandonato'] = $lastCart->getId();
96
- }
97
- }
98
-
99
- $toSend[$i]['IDUltimoOrdineSpedito'] = $lastShipmentOrderId;
100
- $toSend[$i]['DataUltimoOrdineSpedito'] = $lastShipmentOrderDate;
101
-
102
- $lastOrderDateTime = end($allOrdersDateTimes);
103
-
104
- if ($customer->getUpdatedAt() > $lastDateTime
105
- || $lastOrderDateTime > $lastDateTime
106
- || ($datetimeCart && $datetimeCart > $lastDateTime))
107
- {
108
- Mage::log('Adding customer with id '.$currentCustomerId, 0);
109
-
110
- $toSend[$i]['nome'] = $customer->getFirstname();
111
- $toSend[$i]['cognome'] = $customer->getLastname();
112
- $toSend[$i]['email'] = $customer->getEmail();
113
- $toSend[$i]['IDCliente'] = $currentCustomerId;
114
-
115
- $toSend[$i]['registeredDate'] = self::_retriveDateFromDatetime($customer->getCreatedAt());
116
-
117
- //controllo se iscritto o meno alla newsletter
118
- if (Mage::getModel('newsletter/subscriber')->loadByCustomer($customer)->isSubscribed()) {
119
- $toSend[$i]['subscribed'] = 'yes';
120
- } else {
121
- $toSend[$i]['subscribed'] = 'no';
122
- }
123
-
124
- //recupero i dati dal default billing address
125
- $customerAddressId = $customer->getDefaultBilling();
126
- if ($customerAddressId) {
127
- $address = Mage::getModel('customer/address')->load($customerAddressId);
128
- $toSend[$i]['azienda'] = $address->getData('company');
129
- $toSend[$i]['paese'] = $address->getCountry();
130
- $toSend[$i]['città'] = $address->getData('city');
131
- $toSend[$i]['regione'] = $address->getData('region');
132
- $regionId = $address->getData('region_id');
133
- $regionModel = Mage::getModel('directory/region')->load($regionId);
134
- $regionCode = $regionModel->getCode();
135
- $toSend[$i]['provincia'] = $regionCode;
136
- $toSend[$i]['cap'] = $address->getData('postcode');
137
- $toSend[$i]['indirizzo'] = $address->getData('street');
138
- $toSend[$i]['fax'] = $address->getData('fax');
139
- $toSend[$i]['telefono'] = $address->getData('telephone');
140
- }
141
-
142
- $toSend[$i]['DataUltimoOrdine'] = self::_retriveDateFromDatetime($lastOrderDateTime);
143
- $toSend[$i]['TotaleUltimoOrdine'] = end($allOrdersTotals);
144
- $toSend[$i]['IDUltimoOrdine'] = end($allOrdersIds);
145
-
146
- $toSend[$i]['TotaleFatturato'] = self::_formatPrice($allOrdersTotalAmount);
147
-
148
- //ottengo gli id di prodotti e categorie (dell'ultimo ordine)
149
- $lastOrder = Mage::getModel('sales/order')->loadByIncrementId(end($allOrdersIds));
150
- $items = $lastOrder->getAllItems();
151
- $productIds = array();
152
- $categoryIds = array();
153
- foreach ($items as $item) {
154
- $productId = $item->getProductId();
155
- $productIds[] = $productId;
156
- $product = Mage::getModel('catalog/product')->load($productId);
157
- if ($product->getCategoryIds()) {
158
- $categoryIds[] = implode(',', $product->getCategoryIds());
159
- }
160
- }
161
-
162
- $toSend[$i]['IDProdottiUltimoOrdine'] = implode(',', $productIds);
163
- $toSend[$i]['IDCategorieUltimoOrdine'] = implode(',', $categoryIds);
164
- }
165
-
166
- //unsetto la variabile
167
- unset($customer);
168
- }
169
-
170
- Mage::log('Parsing subscribers', 0);
171
- $subscriberCollection = Mage::getModel('newsletter/subscriber')
172
- ->getCollection()
173
- ->useOnlySubscribed()
174
- ->addFieldToFilter('customer_id', 0);
175
-
176
- foreach ($subscriberCollection as $subscriber) {
177
- $subscriber = Mage::getModel('newsletter/subscriber')->load($subscriber->getId());
178
- $toSend[$i]['nome'] = '';
179
- $toSend[$i]['cognome'] = '';
180
- $toSend[$i]['email'] = $subscriber->getEmail();
181
- $toSend[$i]['subscribed'] = 'yes';
182
-
183
- $i++;
184
- }
185
-
186
- Mage::log('End getting customers data', 0);
187
-
188
- return $toSend;
189
- }
190
-
191
- private static function _formatPrice($price) {
192
- return number_format($price, 2, ',', '');
193
- }
194
-
195
- private static function _retriveDateFromDatetime($datetime) {
196
- if ($datetime && !empty($datetime)) {
197
- $exploded = explode(' ', $datetime);
198
- return $exploded[0];
199
- }
200
- return '';
201
- }
202
-
203
  public function generateAndSendCustomers($mailupCustomerIds, $post = null)
204
  {
205
  $MailUpWsSend = Mage::getModel('mailup/wssend');
@@ -207,12 +207,12 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
207
  $MailUpWsSend = Mage::getModel('mailup/ws');
208
  $wsImport = new MailUpWsImport();
209
  $accessKey = $wsSend->loginFromId();
210
-
211
  if (empty($mailupCustomerIds)) return false;
212
  if ($post === null) {
213
  // chiamata da cron, popolo con i dati del gruppo "magento" di default
214
  $post['mailupIdList'] = Mage::getStoreConfig('newsletter/mailup/list');
215
-
216
  $tmp = new SevenLike_MailUp_Model_Lists;
217
  $tmp = $tmp->toOptionArray();
218
  foreach ($tmp as $t) {
@@ -223,7 +223,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
223
  }
224
  }
225
  unset($tmp); unset($t);
226
-
227
  $post['mailupGroupId'] = "";
228
  foreach ($post["groups"] as $tmp_id_group=>$tmp_group_name) {
229
  if ($tmp_group_name == "MAGENTO") {
@@ -232,7 +232,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
232
  }
233
  }
234
  unset($tmp_id_group); unset($tmp_group_name);
235
-
236
  if (!strlen($post['mailupGroupId'])) {
237
  $newGroup = array(
238
  "idList" => $post['mailupIdList'],
@@ -243,7 +243,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
243
  $post['mailupGroupId'] = $wsImport->CreaGruppo($newGroup);
244
  }
245
  }
246
-
247
  $customersData = SevenLike_MailUp_Helper_Data::getCustomersData();
248
 
249
  if ($accessKey === false) {
@@ -265,7 +265,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
265
  foreach ($subscriber as $k=>$v) {
266
  if (!strlen($subscriber[$k])) $subscriber[$k] = "-";
267
  }
268
-
269
  if (@$fields_mapping["Company"]) $tmp[$fields_mapping["Company"]] = '<campo'.$fields_mapping["Company"].'>'. $subscriber['azienda'] .'</campo'.$fields_mapping["Company"].'>';
270
  if (@$fields_mapping["City"]) $tmp[$fields_mapping["City"]] = '<campo'.$fields_mapping["City"].'>'. $subscriber['città'] .'</campo'.$fields_mapping["City"].'>';
271
  if (@$fields_mapping["Province"]) $tmp[$fields_mapping["Province"]] = '<campo'.$fields_mapping["Province"].'>'. $subscriber['provincia'] .'</campo'.$fields_mapping["Province"].'>';
@@ -290,7 +290,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
290
  if (@$fields_mapping["TotalOrderedLast12m"]) $tmp[$fields_mapping["TotalOrderedLast12m"]] = '<campo'.$fields_mapping["TotalOrderedLast12m"].'>'. $subscriber['TotaleFatturatoUltimi12Mesi'] .'</campo'.$fields_mapping["TotalOrderedLast12m"].'>';
291
  if (@$fields_mapping["TotalOrderedLast30d"]) $tmp[$fields_mapping["TotalOrderedLast30d"]] = '<campo'.$fields_mapping["TotalOrderedLast30d"].'>'. $subscriber['TotaleFatturatoUltimi30gg'] .'</campo'.$fields_mapping["TotalOrderedLast30d"].'>';
292
  if (@$fields_mapping["AllOrderedProductIDs"]) $tmp[$fields_mapping["AllOrderedProductIDs"]] = '<campo'.$fields_mapping["AllOrderedProductIDs"].'>'. $subscriber['IDTuttiProdottiAcquistati'] .'</campo'.$fields_mapping["AllOrderedProductIDs"].'>';
293
-
294
  $last_field = max(array_keys($tmp));
295
  for ($i=1; $i<$last_field; $i++) {
296
  if (!isset($tmp[$i])) $tmp[$i] = "<campo{$i}>-</campo{$i}>";
@@ -318,7 +318,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
318
 
319
  $groupId = $wsImport->CreaGruppo($newGroup);
320
  }
321
-
322
  $importProcessData = array(
323
  "idList" => $idList,
324
  "listGUID" => $listGUID,
@@ -334,7 +334,7 @@ class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
334
  "replaceGroups" => "0",
335
  "idConfirmNL" => "0"
336
  );
337
-
338
  //avvio l'importazione su mailup
339
  $processID = $wsImport->newImportProcess($importProcessData);
340
 
1
  <?php
2
  class SevenLike_MailUp_Helper_Data extends Mage_Core_Helper_Abstract {
3
 
4
+ public static function getCustomersData() {
5
+ Mage::log('Getting customers data', 0);
6
+ $dateFormat = 'm/d/y h:i:s';
7
+ $lastDateTime = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-7*3600*24);
8
+ $thirtyDaysAgo = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-30*3600*24);
9
+ $twelveMonthsAgo = date($dateFormat, Mage::getModel('core/date')->timestamp(time())-365*3600*24);
10
+
11
+ $toSend = array();
12
+
13
+ //ottengo la collection con tutti i clienti
14
+ $customerCollection = Mage::getModel('customer/customer')->getCollection();
15
+ foreach ($customerCollection as $customer) {
16
+ $currentCustomerId = $customer->getId();
17
  $i = $customer->getEmail();
18
+ Mage::log('Customer with id '.$currentCustomerId, 0);
19
+ $customer = Mage::getModel('customer/customer')->load($currentCustomerId);
20
+
21
+ //recupero gli ordini del cliente corrente
22
+ $allOrdersTotalAmount = 0;
23
+ $allOrdersDateTimes = array();
24
+ $allOrdersTotals = array();
25
+ $allOrdersIds = array();
26
+ $allProductsIds = array();
27
+ $last30daysOrdersAmount = 0;
28
+ $last12monthsOrdersAmount = 0;
29
  $lastShipmentOrderId = null;
30
  $lastShipmentOrderDate = null;
31
 
32
+ Mage::log('Parsing orders of customer with id '.$currentCustomerId, 0);
33
+ $orders = Mage::getModel('sales/order')
34
+ ->getCollection()
35
+ ->addAttributeToFilter('customer_id', $currentCustomerId);
36
+ foreach ($orders as $order) {
37
+ $currentOrderTotal = floatval($order->getGrandTotal());
38
+ $allOrdersTotalAmount += $currentOrderTotal;
39
+
40
+ $currentOrderCreationDate = $order->getCreatedAt();
41
+ if ($currentOrderCreationDate > $thirtyDaysAgo) {
42
+ $last30daysOrdersAmount += $currentOrderTotal;
43
+
44
+ }
45
+ if ($currentOrderCreationDate > $twelveMonthsAgo) {
46
+ $last12monthsOrdersAmount += $currentOrderTotal;
47
+ }
48
+
49
+ $currentOrderTotal = self::_formatPrice($currentOrderTotal);
50
+
51
+ $currentOrderId = $order->getIncrementId();
52
+ $allOrdersTotals[$currentOrderId] = $currentOrderTotal;
53
+ $allOrdersDateTimes[$currentOrderId] = $currentOrderCreationDate;
54
+ $allOrdersIds[$currentOrderId] = $currentOrderId;
55
+
56
  if ($order->hasShipments() and ($order->getId()>$lastShipmentOrderId)) {
57
  $lastShipmentOrderId = $order->getId();
58
  $lastShipmentOrderDate = self::_retriveDateFromDatetime($order->getCreatedAt());
59
  }
60
 
61
+ $items = $order->getAllItems();
62
+ foreach ($items as $item) {
63
+ $allProductsIds[] = $item->getProductId();
64
+ }
65
+ }
66
+
67
+ $toSend[$i]['TotaleFatturatoUltimi30gg'] = self::_formatPrice($last30daysOrdersAmount);
68
+ $toSend[$i]['TotaleFatturatoUltimi12Mesi'] = self::_formatPrice($last12monthsOrdersAmount);
69
+ $toSend[$i]['IDTuttiProdottiAcquistati'] = implode(',', $allProductsIds);
70
+
71
+ ksort($allOrdersDateTimes);
72
+ ksort($allOrdersTotals);
73
+ ksort($allOrdersIds);
74
+
75
+ //recupero i carrelli abbandonati del cliente
76
+ Mage::log('Parsing abandoned carts of customer with id '.$currentCustomerId, 0);
77
+ $cartCollection = Mage::getResourceModel('reports/quote_collection');
78
+ $cartCollection->prepareForAbandonedReport(array(1));
79
+ $cartCollection->addFieldToFilter('customer_id', $currentCustomerId);
80
+ $cartCollection->load();
81
+
82
+ $datetimeCart = null;
83
+ if (! empty($cartCollection)) {
84
+ $lastCart = end($cartCollection);
85
+
86
+ $toSend[$i]['TotaleCarrelloAbbandonato'] = '';
87
+ $toSend[$i]['DataCarrelloAbbandonato'] = '';
88
+ $toSend[$i]['IDCarrelloAbbandonato'] = '';
89
+
90
+ if (! empty($lastCart)) {
91
+ Mage::log('Customer with id '.$currentCustomerId .' has abandoned cart', 0);
92
+ $datetimeCart = $lastCart->getUpdatedAt();
93
+ $toSend[$i]['TotaleCarrelloAbbandonato'] = self::_formatPrice($lastCart->getGrandTotal());
94
+ $toSend[$i]['DataCarrelloAbbandonato'] = self::_retriveDateFromDatetime($datetimeCart);
95
+ $toSend[$i]['IDCarrelloAbbandonato'] = $lastCart->getId();
96
+ }
97
+ }
98
+
99
+ $toSend[$i]['IDUltimoOrdineSpedito'] = $lastShipmentOrderId;
100
+ $toSend[$i]['DataUltimoOrdineSpedito'] = $lastShipmentOrderDate;
101
+
102
+ $lastOrderDateTime = end($allOrdersDateTimes);
103
+
104
+ if ($customer->getUpdatedAt() > $lastDateTime
105
+ || $lastOrderDateTime > $lastDateTime
106
+ || ($datetimeCart && $datetimeCart > $lastDateTime))
107
+ {
108
+ Mage::log('Adding customer with id '.$currentCustomerId, 0);
109
+
110
+ $toSend[$i]['nome'] = $customer->getFirstname();
111
+ $toSend[$i]['cognome'] = $customer->getLastname();
112
+ $toSend[$i]['email'] = $customer->getEmail();
113
+ $toSend[$i]['IDCliente'] = $currentCustomerId;
114
+
115
+ $toSend[$i]['registeredDate'] = self::_retriveDateFromDatetime($customer->getCreatedAt());
116
+
117
+ //controllo se iscritto o meno alla newsletter
118
+ if (Mage::getModel('newsletter/subscriber')->loadByCustomer($customer)->isSubscribed()) {
119
+ $toSend[$i]['subscribed'] = 'yes';
120
+ } else {
121
+ $toSend[$i]['subscribed'] = 'no';
122
+ }
123
+
124
+ //recupero i dati dal default billing address
125
+ $customerAddressId = $customer->getDefaultBilling();
126
+ if ($customerAddressId) {
127
+ $address = Mage::getModel('customer/address')->load($customerAddressId);
128
+ $toSend[$i]['azienda'] = $address->getData('company');
129
+ $toSend[$i]['paese'] = $address->getCountry();
130
+ $toSend[$i]['città'] = $address->getData('city');
131
+ $toSend[$i]['regione'] = $address->getData('region');
132
+ $regionId = $address->getData('region_id');
133
+ $regionModel = Mage::getModel('directory/region')->load($regionId);
134
+ $regionCode = $regionModel->getCode();
135
+ $toSend[$i]['provincia'] = $regionCode;
136
+ $toSend[$i]['cap'] = $address->getData('postcode');
137
+ $toSend[$i]['indirizzo'] = $address->getData('street');
138
+ $toSend[$i]['fax'] = $address->getData('fax');
139
+ $toSend[$i]['telefono'] = $address->getData('telephone');
140
+ }
141
+
142
+ $toSend[$i]['DataUltimoOrdine'] = self::_retriveDateFromDatetime($lastOrderDateTime);
143
+ $toSend[$i]['TotaleUltimoOrdine'] = end($allOrdersTotals);
144
+ $toSend[$i]['IDUltimoOrdine'] = end($allOrdersIds);
145
+
146
+ $toSend[$i]['TotaleFatturato'] = self::_formatPrice($allOrdersTotalAmount);
147
+
148
+ //ottengo gli id di prodotti e categorie (dell'ultimo ordine)
149
+ $lastOrder = Mage::getModel('sales/order')->loadByIncrementId(end($allOrdersIds));
150
+ $items = $lastOrder->getAllItems();
151
+ $productIds = array();
152
+ $categoryIds = array();
153
+ foreach ($items as $item) {
154
+ $productId = $item->getProductId();
155
+ $productIds[] = $productId;
156
+ $product = Mage::getModel('catalog/product')->load($productId);
157
+ if ($product->getCategoryIds()) {
158
+ $categoryIds[] = implode(',', $product->getCategoryIds());
159
+ }
160
+ }
161
+
162
+ $toSend[$i]['IDProdottiUltimoOrdine'] = implode(',', $productIds);
163
+ $toSend[$i]['IDCategorieUltimoOrdine'] = implode(',', $categoryIds);
164
+ }
165
+
166
+ //unsetto la variabile
167
+ unset($customer);
168
+ }
169
+
170
+ Mage::log('Parsing subscribers', 0);
171
+ $subscriberCollection = Mage::getModel('newsletter/subscriber')
172
+ ->getCollection()
173
+ ->useOnlySubscribed()
174
+ ->addFieldToFilter('customer_id', 0);
175
+
176
+ foreach ($subscriberCollection as $subscriber) {
177
+ $subscriber = Mage::getModel('newsletter/subscriber')->load($subscriber->getId());
178
+ $i = $subscriber->getEmail();
179
+ if (isset($toSend[$i])) continue;
180
+ $toSend[$i]['nome'] = '';
181
+ $toSend[$i]['cognome'] = '';
182
+ $toSend[$i]['email'] = $i;
183
+ $toSend[$i]['subscribed'] = 'yes';
184
+ }
185
+
186
+ Mage::log('End getting customers data', 0);
187
+
188
+ return $toSend;
189
+ }
190
+
191
+ private static function _formatPrice($price) {
192
+ return number_format($price, 2, ',', '');
193
+ }
194
+
195
+ private static function _retriveDateFromDatetime($datetime) {
196
+ if ($datetime && !empty($datetime)) {
197
+ $exploded = explode(' ', $datetime);
198
+ return $exploded[0];
199
+ }
200
+ return '';
201
+ }
202
+
203
  public function generateAndSendCustomers($mailupCustomerIds, $post = null)
204
  {
205
  $MailUpWsSend = Mage::getModel('mailup/wssend');
207
  $MailUpWsSend = Mage::getModel('mailup/ws');
208
  $wsImport = new MailUpWsImport();
209
  $accessKey = $wsSend->loginFromId();
210
+
211
  if (empty($mailupCustomerIds)) return false;
212
  if ($post === null) {
213
  // chiamata da cron, popolo con i dati del gruppo "magento" di default
214
  $post['mailupIdList'] = Mage::getStoreConfig('newsletter/mailup/list');
215
+
216
  $tmp = new SevenLike_MailUp_Model_Lists;
217
  $tmp = $tmp->toOptionArray();
218
  foreach ($tmp as $t) {
223
  }
224
  }
225
  unset($tmp); unset($t);
226
+
227
  $post['mailupGroupId'] = "";
228
  foreach ($post["groups"] as $tmp_id_group=>$tmp_group_name) {
229
  if ($tmp_group_name == "MAGENTO") {
232
  }
233
  }
234
  unset($tmp_id_group); unset($tmp_group_name);
235
+
236
  if (!strlen($post['mailupGroupId'])) {
237
  $newGroup = array(
238
  "idList" => $post['mailupIdList'],
243
  $post['mailupGroupId'] = $wsImport->CreaGruppo($newGroup);
244
  }
245
  }
246
+
247
  $customersData = SevenLike_MailUp_Helper_Data::getCustomersData();
248
 
249
  if ($accessKey === false) {
265
  foreach ($subscriber as $k=>$v) {
266
  if (!strlen($subscriber[$k])) $subscriber[$k] = "-";
267
  }
268
+
269
  if (@$fields_mapping["Company"]) $tmp[$fields_mapping["Company"]] = '<campo'.$fields_mapping["Company"].'>'. $subscriber['azienda'] .'</campo'.$fields_mapping["Company"].'>';
270
  if (@$fields_mapping["City"]) $tmp[$fields_mapping["City"]] = '<campo'.$fields_mapping["City"].'>'. $subscriber['città'] .'</campo'.$fields_mapping["City"].'>';
271
  if (@$fields_mapping["Province"]) $tmp[$fields_mapping["Province"]] = '<campo'.$fields_mapping["Province"].'>'. $subscriber['provincia'] .'</campo'.$fields_mapping["Province"].'>';
290
  if (@$fields_mapping["TotalOrderedLast12m"]) $tmp[$fields_mapping["TotalOrderedLast12m"]] = '<campo'.$fields_mapping["TotalOrderedLast12m"].'>'. $subscriber['TotaleFatturatoUltimi12Mesi'] .'</campo'.$fields_mapping["TotalOrderedLast12m"].'>';
291
  if (@$fields_mapping["TotalOrderedLast30d"]) $tmp[$fields_mapping["TotalOrderedLast30d"]] = '<campo'.$fields_mapping["TotalOrderedLast30d"].'>'. $subscriber['TotaleFatturatoUltimi30gg'] .'</campo'.$fields_mapping["TotalOrderedLast30d"].'>';
292
  if (@$fields_mapping["AllOrderedProductIDs"]) $tmp[$fields_mapping["AllOrderedProductIDs"]] = '<campo'.$fields_mapping["AllOrderedProductIDs"].'>'. $subscriber['IDTuttiProdottiAcquistati'] .'</campo'.$fields_mapping["AllOrderedProductIDs"].'>';
293
+
294
  $last_field = max(array_keys($tmp));
295
  for ($i=1; $i<$last_field; $i++) {
296
  if (!isset($tmp[$i])) $tmp[$i] = "<campo{$i}>-</campo{$i}>";
318
 
319
  $groupId = $wsImport->CreaGruppo($newGroup);
320
  }
321
+
322
  $importProcessData = array(
323
  "idList" => $idList,
324
  "listGUID" => $listGUID,
334
  "replaceGroups" => "0",
335
  "idConfirmNL" => "0"
336
  );
337
+
338
  //avvio l'importazione su mailup
339
  $processID = $wsImport->newImportProcess($importProcessData);
340
 
app/code/local/SevenLike/MailUp/Model/Observer.php CHANGED
@@ -76,23 +76,23 @@ class SevenLike_MailUp_Model_Observer
76
  public function leggiUtente($observer)
77
  {
78
  $model = $observer->getEvent()->getModel();
79
-
80
- $WSDLUrl = 'http://services.mailupnet.it/MailupReport.asmx?WSDL';
81
- $user = Mage::getStoreConfig('newsletter/mailup/username_ws');
82
- $password = Mage::getStoreConfig('newsletter/mailup/password_ws');
83
- $headers = array('User' => $user, 'Password' => $password);
84
- $header = new SOAPHeader($this->ns, 'Authentication', $headers);
85
- $soapclient = new SoapClient($WSDLUrl, array('trace' => 1, 'exceptions' => 0));
86
- $soapclient->__setSoapHeaders($this->header);
87
 
88
  $loginData = array ('user' => Mage::getStoreConfig('newsletter/mailup/username_ws'),
89
  'pwd' => Mage::getStoreConfig('newsletter/mailup/password_ws'),
90
  'consoleId' => substr(Mage::getStoreConfig('newsletter/mailup/username_ws'), 1));
91
  $result = get_object_vars($soapclient->LoginFromId($loginData));
92
  $xml = simplexml_load_string($result['LoginFromIdResult']);
93
- $errorCode = $xml->errorCode->__toString();
94
- $errorDescription = $xml->errorDescription->__toString();
95
- $accessKey = $xml->accessKey->__toString();
96
 
97
  $result = $soapclient->ReportByUser(array(
98
  "accessKey" => $accessKey,
76
  public function leggiUtente($observer)
77
  {
78
  $model = $observer->getEvent()->getModel();
79
+
80
+ $WSDLUrl = 'http://services.mailupnet.it/MailupReport.asmx?WSDL';
81
+ $user = Mage::getStoreConfig('newsletter/mailup/username_ws');
82
+ $password = Mage::getStoreConfig('newsletter/mailup/password_ws');
83
+ $headers = array('User' => $user, 'Password' => $password);
84
+ $header = new SOAPHeader("http://ws.mailupnet.it/", 'Authentication', $headers);
85
+ $soapclient = new SoapClient($WSDLUrl, array('trace' => 1, 'exceptions' => 0));
86
+ $soapclient->__setSoapHeaders($header);
87
 
88
  $loginData = array ('user' => Mage::getStoreConfig('newsletter/mailup/username_ws'),
89
  'pwd' => Mage::getStoreConfig('newsletter/mailup/password_ws'),
90
  'consoleId' => substr(Mage::getStoreConfig('newsletter/mailup/username_ws'), 1));
91
  $result = get_object_vars($soapclient->LoginFromId($loginData));
92
  $xml = simplexml_load_string($result['LoginFromIdResult']);
93
+ $errorCode = (string)$xml->errorCode;
94
+ $errorDescription = (string)$xml->errorDescription;
95
+ $accessKey = (string)$xml->accessKey;
96
 
97
  $result = $soapclient->ReportByUser(array(
98
  "accessKey" => $accessKey,
app/code/local/SevenLike/MailUp/controllers/Adminhtml/FilterController.php CHANGED
@@ -77,7 +77,7 @@ class SevenLike_MailUp_Adminhtml_FilterController extends Mage_Adminhtml_Control
77
 
78
  //lancio il download del file
79
  header("Content-type: application/csv");
80
- header("Content-Disposition: attachment;Filename=clienti_filtrati.csv");
81
  echo $file;
82
  }
83
 
77
 
78
  //lancio il download del file
79
  header("Content-type: application/csv");
80
+ header("Content-Disposition: attachment;Filename=filtered_customers.csv");
81
  echo $file;
82
  }
83
 
app/code/local/SevenLike/MailUp/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <SevenLike_MailUp>
6
- <version>1.5.6</version>
7
  </SevenLike_MailUp>
8
  </modules>
9
 
3
  <config>
4
  <modules>
5
  <SevenLike_MailUp>
6
+ <version>2.0.2</version>
7
  </SevenLike_MailUp>
8
  </modules>
9
 
app/design/adminhtml/default/default/template/sevenlike/mailup/filter.phtml CHANGED
@@ -395,13 +395,13 @@ if ($accessKey === false || strlen(Mage::getStoreConfig('newsletter/mailup/list'
395
  echo '<input name="'.$array[0].'" type="hidden" value="'.$array[1].'" />';
396
  }
397
  echo '<p class="parscefil">'.$filter_name.' &raquo;</p>';
398
- echo '<input type="submit" value="'.$this->__('Set hint').'" />';
399
  echo '</form>';
400
  echo '&nbsp;';
401
  echo '<form name="deleteForm_'.$filter_name.'" action="'.$this->getUrl('*/*/deleteFilterHint').'" method="post">';
402
  echo '<input name="form_key" type="hidden" value="'. Mage::getSingleton('core/session')->getFormKey() .'" />';
403
  echo '<input name="filter_name" type="hidden" value="'. $filter_name .'" />';
404
- echo '<input type="submit" name="delete" onclick="if(confirm(\''.$this->__('Do you really want to delete this filter hint?').'\')==true){this.submit();}return false;" value="'.$this->__('Delete hint').'" />';
405
  echo '</form>';
406
  echo '</td></tr>';
407
  } ?>
395
  echo '<input name="'.$array[0].'" type="hidden" value="'.$array[1].'" />';
396
  }
397
  echo '<p class="parscefil">'.$filter_name.' &raquo;</p>';
398
+ echo '<input class="form-button" type="submit" value="'.$this->__('Set hint').'" />';
399
  echo '</form>';
400
  echo '&nbsp;';
401
  echo '<form name="deleteForm_'.$filter_name.'" action="'.$this->getUrl('*/*/deleteFilterHint').'" method="post">';
402
  echo '<input name="form_key" type="hidden" value="'. Mage::getSingleton('core/session')->getFormKey() .'" />';
403
  echo '<input name="filter_name" type="hidden" value="'. $filter_name .'" />';
404
+ echo '<input class="form-button" type="submit" name="delete" onclick="if(confirm(\''.$this->__('Do you really want to delete this filter hint?').'\')==true){this.submit();}return false;" value="'.$this->__('Delete hint').'" />';
405
  echo '</form>';
406
  echo '</td></tr>';
407
  } ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>MailUp</name>
4
- <version>2.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/academic.php">Academic Free License (AFL)</license>
7
  <channel>community</channel>
@@ -47,12 +47,12 @@
47
  &lt;p&gt;&lt;br /&gt;Ad esempio un sito di ecommerce potrebbe alimentare il DB di MailUp con informazioni sugli acquisti e MailUp potr&amp;agrave; quindi inviare, ad esempio dopo 7 giorni dall'acquisto, un messaggio di costumer satisfaction oppure l'invito ad acquistare un prodotto correlato.&lt;/p&gt;</description>
48
  <notes>Changelog:&lt;br /&gt;&#xD;
49
  &lt;ul&gt;&#xD;
50
- &lt;li&gt;Automatic synchronization (via customizable Magento crons) of all customers/subscribers with a new "MAGENTO" group in the selected list.&lt;/li&gt;&#xD;
51
  &lt;/ul&gt;</notes>
52
  <authors><author><name>Sevenlike</name><user>sevenlike</user><email>moduli-magento@sevenlike.com</email></author></authors>
53
- <date>2012-06-04</date>
54
- <time>2012-06-04</time>
55
- <contents><target name="magelocal"><dir name="SevenLike"><dir name="MailUp"><dir name="Block"><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="Helper"><file name="Data.php" hash="6ad008113139ac367a22ad049e0632f3"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="System"><dir name="Source"><dir name="Cron"><file name="Frequency.php" hash="57c892490ca67de41b2d5d4d043761b9"/><file name="Hours.php" hash="3f9ec0f1233b4468ed86b4eba050602e"/></dir></dir></dir></dir><file name="Cron.php" hash="4123ac2606add1be880f497b67597e6c"/><file name="Lists.php" hash="28b44514b3d3c325945f0fc8a83df4ec"/><file name="MailUp.php" hash="2829fb8a8ad6317ce5b2a28a2fe0149d"/><dir name="Mysql14"><dir name="MailUp"><file name="Collection.php" hash="1435c91e677f7b668079373599aae3eb"/></dir><file name="MailUp.php" hash="4e6e23f0eccdfe35776d1e8eab68692a"/></dir><file name="Observer.php" hash="8882bcd505d163cd96c3e260494d7800"/><dir name="System"><dir name="Source"><dir name="Cron"><file name="Frequency.php" hash="0a9ee4aacdcf270eb192f5b32e1e4a26"/><file name="Hours.php" hash="029b0d2d998c7e246333ee7bff64661a"/></dir></dir></dir><file name="Ws.php" hash="c6968947b0950b52f0fbeeddf347ad8c"/><file name="Wssend.php" hash="bbda3b6dcfbe8af129aa24431757605e"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FieldsmappingController.php" hash="0e4ef6aca47bbbd1d1881ce02465a688"/><file name="FilterController.php" hash="496b739241dcbf4db8ae32804da5a5b1"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="etc"><file name="config.xml" hash="bdd88d1039c2f2b5b748a3188c606487"/><file name="system.xml" hash="c9e10400e27057dacf2e3f9d18f6ed21"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="sql"><dir name="mailup_setup"><file name="mysql4-install-0.1.0.php" hash="46770fc0e2204faeba2b82c975fc6fb8"/><file name="mysql4-upgrade-0.1.0-1.0.0.php" hash="8fb23d8f3c3d38661aa50697f23e98c7"/><file name="mysql4-upgrade-0.3.0-1.0.0.php" hash="89080c835857a5dd135da5608a77ced1"/><file name="mysql4-upgrade-1.0.0-1.5.2.php" hash="d88d151e34f9ddba5bdc7d8c8cc21f97"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="sevenlike"><dir name="mailup"><file name="confirm.phtml" hash="b6e4af2eb21000d218648abc3b2f7caf"/><file name="fieldsmapping.phtml" hash="6d31a300cf8774c94219a38b95635486"/><file name="filter.phtml" hash="9323b59d4b1214ab9d025a3eee106399"/></dir></dir></dir><dir name="layout"><file name="mailup.xml" hash="37a171055aedfb552cb261dede1e0037"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SevenLike_MailUp.xml" hash="8377b55193e7524ca9572ed4dc2dca62"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="sevenlike"><dir name="mailup"><dir name="images"><file name="titoli.png" hash="95a7996cd77d3413fd048018095aec6e"/></dir><file name="mailup.css" hash="37febcfd87a78148d5962da507c62ecc"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="SevenLike_MailUp.csv" hash="7388cfb49cf963f78f59c24633027f67"/></dir><dir name="it_IT"><file name="SevenLike_MailUp.csv" hash="53b451a3b28669f6bebfa8f39e391302"/></dir></target></contents>
56
  <compatible/>
57
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
58
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>MailUp</name>
4
+ <version>2.0.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/academic.php">Academic Free License (AFL)</license>
7
  <channel>community</channel>
47
  &lt;p&gt;&lt;br /&gt;Ad esempio un sito di ecommerce potrebbe alimentare il DB di MailUp con informazioni sugli acquisti e MailUp potr&amp;agrave; quindi inviare, ad esempio dopo 7 giorni dall'acquisto, un messaggio di costumer satisfaction oppure l'invito ad acquistare un prodotto correlato.&lt;/p&gt;</description>
48
  <notes>Changelog:&lt;br /&gt;&#xD;
49
  &lt;ul&gt;&#xD;
50
+ &lt;li&gt;a bug with "newsletter only" subscribers was solved&lt;/li&gt;&#xD;
51
  &lt;/ul&gt;</notes>
52
  <authors><author><name>Sevenlike</name><user>sevenlike</user><email>moduli-magento@sevenlike.com</email></author></authors>
53
+ <date>2012-06-05</date>
54
+ <time>2012-06-05</time>
55
+ <contents><target name="magelocal"><dir name="SevenLike"><dir name="MailUp"><dir name="Block"><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="Helper"><file name="Data.php" hash="1ae5853d15dd56cf872fe3abd97f0307"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="System"><dir name="Source"><dir name="Cron"><file name="Frequency.php" hash="57c892490ca67de41b2d5d4d043761b9"/><file name="Hours.php" hash="3f9ec0f1233b4468ed86b4eba050602e"/></dir></dir></dir></dir><file name="Cron.php" hash="4123ac2606add1be880f497b67597e6c"/><file name="Lists.php" hash="28b44514b3d3c325945f0fc8a83df4ec"/><file name="MailUp.php" hash="2829fb8a8ad6317ce5b2a28a2fe0149d"/><dir name="Mysql14"><dir name="MailUp"><file name="Collection.php" hash="1435c91e677f7b668079373599aae3eb"/></dir><file name="MailUp.php" hash="4e6e23f0eccdfe35776d1e8eab68692a"/></dir><file name="Observer.php" hash="d80ff2dada129c29708be3de7bcf27bf"/><dir name="System"><dir name="Source"><dir name="Cron"><file name="Frequency.php" hash="0a9ee4aacdcf270eb192f5b32e1e4a26"/><file name="Hours.php" hash="029b0d2d998c7e246333ee7bff64661a"/></dir></dir></dir><file name="Ws.php" hash="c6968947b0950b52f0fbeeddf347ad8c"/><file name="Wssend.php" hash="bbda3b6dcfbe8af129aa24431757605e"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FieldsmappingController.php" hash="0e4ef6aca47bbbd1d1881ce02465a688"/><file name="FilterController.php" hash="b449d54d6e573b38bc618eea1519e1ae"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="etc"><file name="config.xml" hash="f94de27f3441889f32e45c2298f06be2"/><file name="system.xml" hash="c9e10400e27057dacf2e3f9d18f6ed21"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir><dir name="sql"><dir name="mailup_setup"><file name="mysql4-install-0.1.0.php" hash="46770fc0e2204faeba2b82c975fc6fb8"/><file name="mysql4-upgrade-0.1.0-1.0.0.php" hash="8fb23d8f3c3d38661aa50697f23e98c7"/><file name="mysql4-upgrade-0.3.0-1.0.0.php" hash="89080c835857a5dd135da5608a77ced1"/><file name="mysql4-upgrade-1.0.0-1.5.2.php" hash="d88d151e34f9ddba5bdc7d8c8cc21f97"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="sevenlike"><dir name="mailup"><file name="confirm.phtml" hash="b6e4af2eb21000d218648abc3b2f7caf"/><file name="fieldsmapping.phtml" hash="6d31a300cf8774c94219a38b95635486"/><file name="filter.phtml" hash="2d8918fea5ffb7ea36686a9d5ea2e9b6"/></dir></dir></dir><dir name="layout"><file name="mailup.xml" hash="37a171055aedfb552cb261dede1e0037"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SevenLike_MailUp.xml" hash="8377b55193e7524ca9572ed4dc2dca62"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="sevenlike"><dir name="mailup"><dir name="images"><file name="titoli.png" hash="95a7996cd77d3413fd048018095aec6e"/></dir><file name="mailup.css" hash="37febcfd87a78148d5962da507c62ecc"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="SevenLike_MailUp.csv" hash="7388cfb49cf963f78f59c24633027f67"/></dir><dir name="it_IT"><file name="SevenLike_MailUp.csv" hash="53b451a3b28669f6bebfa8f39e391302"/></dir></target></contents>
56
  <compatible/>
57
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
58
  </package>