SALESmanago - Version 1.1.0

Version Notes

SALESmanago Marketing Automation integration.

Download this release

Release Info

Developer Benhauer Sp. z o.o. Sp. K.
Extension SALESmanago
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.5.1 to 1.1.0

CHANGELOG.md DELETED
@@ -1,64 +0,0 @@
1
- Magento integration v1.5.1 (Released: 21.11.2016)
2
- Changes:
3
- - New monitoring code
4
-
5
- --------------------------------------------------
6
- Magento integration v1.5.0 (Released: 09.11.2016)
7
- Added:
8
- - Register tags,
9
- - Newsletter tags,
10
- - Purchase tags,
11
- - New method to upsert Vendor platform and version to support account
12
- - Translations, MultiLanguage: Polish, English, Spanish, German, Russian
13
- - New other event: Wishlist,
14
-
15
- Improvements:
16
- - More details in events,
17
-
18
- Fixed:
19
- - Installation bug - creating directories instead files,
20
- --------------------------------------------------
21
- Magento integration v0.1.2.1 (Released: 04.04.2016)
22
- -Fixes:
23
- OptIn after anonymous client purchase
24
- --------------------------------------------------
25
- Magento integration v0.1.2 (Released: 16.02.2016)
26
- Added:
27
- - Register form with address fields - compatibility
28
- BugFixes:
29
- - Profile and address editing in Magento make changes in SalesManago,
30
- - Registering by form with address fields,
31
- - Synchronizing contact details in salesmanago,
32
- --------------------------------------------------
33
- Magento integration v0.1.1 (Released: 29.07.2015)
34
- Added:
35
- - Profile and address editing in Magento make changes in SalesManago
36
- --------------------------------------------------
37
- Magento integration v0.1.0 (Released: 24.07.2015)
38
- Added:
39
- - creating SMclient cookie after login and registering
40
- --------------------------------------------------
41
- Magento integration v0.0.8 (Released: 05.05.2015)
42
- Added:
43
- - cart events for unregistered users (with smclient cookie)
44
- --------------------------------------------------
45
- Magento integration v0.0.7 (Released: 12.03.2015)
46
- Added:
47
- - enable/disable module
48
- - when newsletter requires confirm, contact is sent to sm as optout.
49
- --------------------------------------------------
50
- Magento integration v0.0.6 (Released: 20.01.2015)
51
- Added:
52
- - optin callback support
53
- - birthday date is sent to SM
54
- --------------------------------------------------
55
- Magento integration v0.0.5 (Released: 21.11.2014)
56
- Added:
57
- - support subscription form
58
- - admin subscription managment integrated with SM
59
-
60
- Bugfixes:
61
- - address, phone etc. not send to SM
62
- - cookie not created after guest purchase
63
- - tracking code not shown in newest magento
64
- - bad price for CART event
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SalesManago/Tracking/Block/Layer.php CHANGED
@@ -53,23 +53,11 @@ class SalesManago_Tracking_Block_Layer extends Mage_Core_Block_Template
53
  }
54
 
55
 
56
- public function getTagsRegistration(){
57
- $tags = Mage::getStoreConfig('salesmanago_tracking/general/tagsRegistration');
58
  $tags = explode(',', $tags);
59
  return $tags;
60
  }
61
-
62
- public function getTagsNewsletter(){
63
- $tags = Mage::getStoreConfig('salesmanago_tracking/general/tagsNewsletter');
64
- $tags = explode(',', $tags);
65
- return $tags;
66
- }
67
-
68
- public function getTagsPurchase(){
69
- $tags = Mage::getStoreConfig('salesmanago_tracking/general/tagsPurchase');
70
- $tags = explode(',', $tags);
71
- return $tags;
72
- }
73
 
74
  public function getClientSalesManagoId(){
75
  if(Mage::getSingleton('customer/session')->isLoggedIn()) {
53
  }
54
 
55
 
56
+ public function getTags(){
57
+ $tags = Mage::getStoreConfig('salesmanago_tracking/general/tags');
58
  $tags = explode(',', $tags);
59
  return $tags;
60
  }
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  public function getClientSalesManagoId(){
63
  if(Mage::getSingleton('customer/session')->isLoggedIn()) {
app/code/community/SalesManago/Tracking/Helper/Data.php CHANGED
@@ -32,7 +32,230 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
32
  }
33
  }
34
  }
35
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  public function salesmanagoOrderSync($orderDetails){
37
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
38
  if($active == 1) {
@@ -40,22 +263,31 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
40
  $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
41
  $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
42
  $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
43
- $registerTags = explode(",", Mage::getStoreConfig('salesmanago_tracking/general/tagsPurchase'));
44
-
45
- $productsIdsList = array();
46
- $productsNamesList = array();
47
 
48
  $items = $orderDetails->getAllVisibleItems();
 
49
  foreach ($items as $item) {
50
- array_push($productsIdsList, $item->getProduct()->getId());
51
- array_push($productsNamesList, $item->getProduct()->getName());
52
  }
53
 
54
  $customerEmail = $orderDetails->getCustomerEmail();
 
 
55
  $grandTotal = $orderDetails->getBaseGrandTotal();
56
  $incrementOrderId = $orderDetails->getIncrementId();
 
 
 
 
 
 
 
57
  $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($customerEmail)->getData();
 
 
58
  $orderData = $orderDetails->getData();
 
 
59
  $customerDetails = $orderDetails->getBillingAddress();
60
 
61
  $data = array();
@@ -67,8 +299,9 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
67
  $data['address']['zipCode'] = $customerDetails->getPostcode();
68
  $data['address']['city'] = $customerDetails->getCity();
69
  $data['address']['country'] = $customerDetails->getCountryId();
 
70
  $data['customerEmail'] = $customerEmail;
71
- $data['tags'] = $registerTags;
72
 
73
  if (isset($orderData['customer_dob']) && !empty($orderData['customer_dob'])) {
74
  $dataArray = date_parse($orderData['customer_dob']);
@@ -83,9 +316,8 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
83
  $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customerEmail);
84
  $status = $subscriber->isSubscribed();
85
  if ($status) $data['is_subscribed'] = true;
86
- else $data['is_subscribed'] = false;
87
  } else {
88
- $data['is_subscribed'] = false; //after purchase
89
  }
90
 
91
 
@@ -93,6 +325,7 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
93
  if ($r == false || (isset($r['success']) && $r['success'] == false)) {
94
  $data['status'] = 0;
95
  $data['action'] = 1; //rejestracja
 
96
  }
97
 
98
 
@@ -114,18 +347,30 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
114
  'email' => $customerEmail,
115
  'contactEvent' => array(
116
  'date' => $dateTime->format('c'),
117
- 'products' => implode(',', $productsIdsList),
118
  'contactExtEventType' => 'PURCHASE',
119
  'value' => $grandTotal,
120
- 'detail1' => implode(",", $productsNamesList),
 
 
 
 
121
  'externalId' => $incrementOrderId,
122
  ),
123
  );
124
-
125
  $json = json_encode($data_to_json);
126
  $result = $this->_doPostRequest('https://' . $endPoint . '/api/contact/addContactExtEvent', $json);
127
  $r = json_decode($result, true);
128
 
 
 
 
 
 
 
 
 
 
129
  return $r;
130
  }
131
  }
@@ -139,6 +384,7 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
139
  $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
140
  $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
141
  $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
 
142
  $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
143
 
144
  $apiKey = md5(time() . $apiSecret);
@@ -153,20 +399,22 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
153
  'name' => $data['name'],
154
  'fax' => $data['fax'],
155
  'company' => $data['company'],
156
- 'phone' => $data['telephone'],
157
  'address' => array(
158
- 'streetAddress' => $data['street'],
159
- 'zipCode' => $data['postcode'],
160
- 'city' => $data['city'],
161
- 'country' => $data['country'],
162
  ),
163
  ),
164
  'owner' => $ownerEmail,
165
  'async' => false,
166
- 'tags' => $data['tags'],
167
  );
 
 
 
168
 
169
- if (!$data['is_subscribed']) {
170
  $data_to_json['forceOptOut'] = true;
171
  $data_to_json['forceOptIn'] = false;
172
  } else {
@@ -178,6 +426,22 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
178
  $data_to_json['birthday'] = $data['birthday'];
179
  }
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  $json = json_encode($data_to_json);
182
  $result = $this->_doPostRequest('https://' . $endPoint . '/api/contact/upsert', $json);
183
 
@@ -194,19 +458,14 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
194
  public function _setCustomerData($customer){
195
  $data = array();
196
  $subscription_status = 0;
197
- foreach ($customer->getAddresses() as $address) {
198
- $data = $address->toArray();
199
- }
200
-
201
  $data['customerEmail'] = $customer['email'];
202
  $data['entity_id'] = $customer['entity_id'];
203
 
204
  $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer['email']);
205
  $subscription_status = $subscriber->isSubscribed();
206
 
207
- if(isset($customer['firstname']) && isset($customer['lastname']) && isset($customer['middlename'])){
208
- $data['name'] = $customer['firstname'].' '.$data['middlename'].' '.$customer['lastname'];
209
- } else {
210
  $data['name'] = $customer['firstname'].' '.$customer['lastname'];
211
  }
212
 
@@ -222,8 +481,6 @@ class SalesManago_Tracking_Helper_Data extends Mage_Core_Helper_Abstract{
222
  $data['birthday'] = $year . $month . $day;
223
  }
224
 
225
- $data['country']=$data['country_id'].' '.$data['region'];
226
-
227
  return $data;
228
  }
229
 
32
  }
33
  }
34
  }
35
+ /*
36
+ * BK Changes to Sales Manago Module.
37
+ * Redeem Coupon via API to SalesManago
38
+ * @author: Carlos Alonso de Linaje Garcia
39
+ */
40
+ public function salesmanagoRedeemCoupon($customerEmail,$couponCode)
41
+ {
42
+ $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
43
+ if ($active == 1)
44
+ {
45
+ $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
46
+ $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
47
+ $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
48
+ $apiKey = md5(time() . $apiSecret);
49
+ $data_to_json = array(
50
+ 'apiKey' => $apiKey,
51
+ 'clientId' => $clientId,
52
+ 'email' => $customerEmail,
53
+ 'coupon' => $couponCode,
54
+ );
55
+ $json = json_encode($data_to_json);
56
+ $result = $this->_doPostRequest('https://' . $endPoint . '/api/contact/useContactCoupon', $json);
57
+ $r = json_decode($result, true);
58
+
59
+ return $r;
60
+ }
61
+ return false;
62
+ }
63
+ /*
64
+ * BK Changes to Sales Manago Module.
65
+ * Calc Total Sales of Customer
66
+ * @author: Carlos Alonso de Linaje Garcia
67
+ */
68
+ protected function _calcTotal($fromDate = null,$toDate,$customerEmail)
69
+ {
70
+ $orders = Mage::getModel('sales/order')->getCollection()
71
+ ->addAttributeToFilter('status', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED))
72
+ ->addAttributeToFilter('customer_email', $customerEmail);
73
+ if ($fromDate != null)
74
+ $orders->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate));
75
+ else
76
+ $orders->addAttributeToFilter('created_at', array('to'=>$toDate));
77
+
78
+ $totalSales = 0;
79
+ foreach ($orders->getData() as $data)
80
+ {
81
+ $totalSales += $data['grand_total'];
82
+ }
83
+ return $totalSales;
84
+ }
85
+ /*
86
+ * BK Changes to Sales Manago Module.
87
+ * Send Sales Totals via API to SalesManago
88
+ * @author: Carlos Alonso de Linaje Garcia
89
+ */
90
+ public function salesmanagoSalesSync ($orderDetails)
91
+ {
92
+ $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
93
+ if($active == 1) {
94
+
95
+ $customerEmail = $orderDetails->getCustomerEmail();
96
+ $month = date("m", Mage::getModel('core/date')->timestamp(time()));
97
+ $year = date("Y", Mage::getModel('core/date')->timestamp(time()));
98
+ $toDate = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
99
+
100
+ //Getting Sales of the month
101
+ $fromDate = date('Y-m-1 H:i:s', Mage::getModel('core/date')->timestamp(time()));
102
+ $totalSales_month = $this->_calcTotal($fromDate,$toDate,$customerEmail);
103
+ $JanuarySales = $this->_calcTotal(date($year.'-1-1'),$toDate,$customerEmail);
104
+
105
+ //Getting Sales of the Q, T and Semester.
106
+ switch ($month) {
107
+ case 1:
108
+ case 2:
109
+ case 3:
110
+ $data_to_json = array(
111
+ 'Sales_'.$year.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST))
112
+ => $JanuarySales,
113
+ 'Sales_'.$year.'_M'.$month.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $totalSales_month,
114
+ 'Sales_'.$year.'_1T_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
115
+ 'Sales_'.$year.'_1Q_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
116
+ 'Sales_'.$year.'_1S_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
117
+ );
118
+ break;
119
+ case 4:
120
+ $AprilSales = $this->_calcTotal(date($year.'-4-1'),$toDate,$customerEmail);
121
+ $data_to_json = array(
122
+ 'Sales_'.$year.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
123
+ 'Sales_'.$year.'_M'.$month.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $totalSales_month,
124
+ 'Sales_'.$year.'_2T_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $AprilSales,
125
+ 'Sales_'.$year.'_1Q_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
126
+ 'Sales_'.$year.'_1S_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
127
+ );
128
+ break;
129
+ case 5:
130
+ case 6:
131
+ $AprilSales = $this->_calcTotal(date($year.'-4-1'),$toDate,$customerEmail);
132
+ $MaySales = $this->_calcTotal(date($year.'-5-1'),$toDate,$customerEmail);
133
+ $data_to_json = array(
134
+ 'Sales_'.$year.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
135
+ 'Sales_'.$year.'_M'.$month.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $totalSales_month,
136
+ 'Sales_'.$year.'_2T_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $AprilSales,
137
+ 'Sales_'.$year.'_2Q_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $MaySales,
138
+ 'Sales_'.$year.'_1S_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
139
+ );
140
+ break;
141
+ case 7:
142
+ case 8:
143
+ $JulySales = $this->_calcTotal(date($year.'-7-1'),$toDate,$customerEmail);
144
+ $MaySales = $this->_calcTotal(date($year.'-5-1'),$toDate,$customerEmail);
145
+ $data_to_json = array(
146
+ 'Sales_'.$year.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
147
+ 'Sales_'.$year.'_M'.$month.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $totalSales_month,
148
+ 'Sales_'.$year.'_3T_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JulySales,
149
+ 'Sales_'.$year.'_2Q_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $MaySales,
150
+ 'Sales_'.$year.'_2S_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JulySales,
151
+ );
152
+ break;
153
+ case 9:
154
+ $JulySales = $this->_calcTotal(date($year.'-7-1'),$toDate,$customerEmail);
155
+ $SeptSales = $this->_calcTotal(date($year.'-9-1'),$toDate,$customerEmail);
156
+ $data_to_json = array(
157
+ 'Sales_'.$year.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
158
+ 'Sales_'.$year.'_M'.$month.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $totalSales_month,
159
+ 'Sales_'.$year.'_3T_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JulySales,
160
+ 'Sales_'.$year.'_3Q_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $SeptSales,
161
+ 'Sales_'.$year.'_2S_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JulySales,
162
+ );
163
+ break;
164
+ case 10:
165
+ case 11:
166
+ case 12:
167
+ $JulySales = $this->_calcTotal(date($year.'-7-1'),$toDate,$customerEmail);
168
+ $SeptSales = $this->_calcTotal(date($year.'-9-1'),$toDate,$customerEmail);
169
+ $OctSales = $this->_calcTotal(date($year.'-10-1'),$toDate,$customerEmail);
170
+ $data_to_json = array(
171
+ 'Sales_'.$year.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JanuarySales,
172
+ 'Sales_'.$year.'_M'.$month.'_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $totalSales_month,
173
+ 'Sales_'.$year.'_4T_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $OctSales,
174
+ 'Sales_'.$year.'_3Q_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $SeptSales,
175
+ 'Sales_'.$year.'_2S_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) => $JulySales,
176
+ );
177
+ break;
178
+ } //end Switch Months calculation
179
+ $r = $this->_SendUpsertPropertiesJson($data_to_json,$customerEmail);
180
+
181
+ return $r;
182
+
183
+ }
184
+ }
185
+ /*
186
+ * BK Changes to Sales Manago Module.
187
+ * Send Upsert Api Call
188
+ * @author: Carlos Alonso de Linaje Garcia
189
+ */
190
+ protected function _SendUpsertPropertiesJson($data,$email)
191
+ {
192
+ $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
193
+ $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
194
+ $apiKey = md5(time() . $apiSecret);
195
+ $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
196
+ $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
197
+ $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
198
+
199
+ $data_to_json = array(
200
+ 'apiKey' => $apiKey,
201
+ 'clientId' => $clientId,
202
+ 'requestTime' => time(),
203
+ 'contact' => array(
204
+ 'email' => $email,
205
+ 'state' => 'CUSTOMER',
206
+ ),
207
+ 'sha' => sha1($apiKey . $clientId . $apiSecret),
208
+ 'owner' => $ownerEmail,
209
+ );
210
+ $data_to_json['properties'] = $data;
211
+ $json = json_encode($data_to_json);
212
+ $result = $this->_doPostRequest('https://' . $endPoint . '/api/contact/upsert', $json);
213
+ $r = json_decode($result, true);
214
+
215
+ return $r;
216
+ }
217
+ /*
218
+ * BK Changes to Sales Manago Module.
219
+ * Send Event Review.
220
+ * @author: Carlos Alonso de Linaje Garcia
221
+ */
222
+ public function salesmanagoReviewSync($review)
223
+ {
224
+ $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
225
+ if($active == 1) {
226
+ Mage::log('salesmanagoReviewSync');
227
+ $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
228
+ $apiKey = md5(time() . $apiSecret);
229
+ $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
230
+ $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
231
+ $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
232
+ $dateTime = new DateTime('NOW');
233
+
234
+ $customerEmail = Mage::getModel('customer/customer')->load($review['customer_id'])->getEmail();
235
+
236
+ $data_to_json = array(
237
+ 'apiKey' => $apiKey,
238
+ 'clientId' => $clientId,
239
+ 'requestTime' => time(),
240
+ 'sha' => sha1($apiKey . $clientId . $apiSecret),
241
+ 'owner' => $ownerEmail,
242
+ 'email' => $customerEmail,
243
+ 'contactEvent' => array(
244
+ 'date' => $dateTime->format('c'),
245
+ 'contactExtEventType' => 'OTHER',
246
+ 'products' => $review['entity_pk_value'],
247
+ 'detail1' => 'review',
248
+ ),
249
+ );
250
+ Mage::log($data_to_json);
251
+ $json = json_encode($data_to_json);
252
+ $result = $this->_doPostRequest('https://' . $endPoint . '/api/contact/addContactExtEvent', $json);
253
+ $r = json_decode($result, true);
254
+
255
+ return $r;
256
+
257
+ }
258
+ }
259
  public function salesmanagoOrderSync($orderDetails){
260
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
261
  if($active == 1) {
263
  $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
264
  $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
265
  $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
 
 
 
 
266
 
267
  $items = $orderDetails->getAllVisibleItems();
268
+ $itemsNamesList = array();
269
  foreach ($items as $item) {
270
+ array_push($itemsNamesList, $item->getProduct()->getId());
 
271
  }
272
 
273
  $customerEmail = $orderDetails->getCustomerEmail();
274
+ $customerFirstname = $orderDetails->getCustomerFirstname();
275
+ $customerLastname = $orderDetails->getCustomerLastname();
276
  $grandTotal = $orderDetails->getBaseGrandTotal();
277
  $incrementOrderId = $orderDetails->getIncrementId();
278
+ //BK Send Payment Method name, Shipping Method name and Shipping Cost on Event.
279
+ $payment_name = $orderDetails->getPayment()->getMethodInstance()->getTitle();;
280
+ $shipping_name = $orderDetails->getShippingDescription();
281
+ $shippment_cost = $orderDetails->getShippingAmount();
282
+ //BK Coupon Code.
283
+ $couponCode = $orderDetails->coupon_code;
284
+
285
  $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($customerEmail)->getData();
286
+
287
+
288
  $orderData = $orderDetails->getData();
289
+
290
+
291
  $customerDetails = $orderDetails->getBillingAddress();
292
 
293
  $data = array();
299
  $data['address']['zipCode'] = $customerDetails->getPostcode();
300
  $data['address']['city'] = $customerDetails->getCity();
301
  $data['address']['country'] = $customerDetails->getCountryId();
302
+
303
  $data['customerEmail'] = $customerEmail;
304
+
305
 
306
  if (isset($orderData['customer_dob']) && !empty($orderData['customer_dob'])) {
307
  $dataArray = date_parse($orderData['customer_dob']);
316
  $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customerEmail);
317
  $status = $subscriber->isSubscribed();
318
  if ($status) $data['is_subscribed'] = true;
 
319
  } else {
320
+ $data['is_subscribed'] = true; //after purchase
321
  }
322
 
323
 
325
  if ($r == false || (isset($r['success']) && $r['success'] == false)) {
326
  $data['status'] = 0;
327
  $data['action'] = 1; //rejestracja
328
+ //$this->_getHelper()->setSalesmanagoCustomerSyncStatus($data);
329
  }
330
 
331
 
347
  'email' => $customerEmail,
348
  'contactEvent' => array(
349
  'date' => $dateTime->format('c'),
350
+ 'products' => implode(',', $itemsNamesList),
351
  'contactExtEventType' => 'PURCHASE',
352
  'value' => $grandTotal,
353
+ //BK Sending Values on detail 1,2 & 3
354
+ 'detail1' => $payment_name,
355
+ 'detail2' => $shipping_name,
356
+ 'detail3' => $shippment_cost,
357
+ 'detail4' => $couponCode,
358
  'externalId' => $incrementOrderId,
359
  ),
360
  );
 
361
  $json = json_encode($data_to_json);
362
  $result = $this->_doPostRequest('https://' . $endPoint . '/api/contact/addContactExtEvent', $json);
363
  $r = json_decode($result, true);
364
 
365
+ //BK Redeem Coupon
366
+ if ($couponCode)
367
+ {
368
+ Mage::log($couponCode);
369
+ $j = $this->salesmanagoRedeemCoupon($customerEmail,$couponCode);
370
+ Mage::log($j);
371
+
372
+ }//BK
373
+
374
  return $r;
375
  }
376
  }
384
  $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
385
  $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
386
  $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
387
+ $tags = Mage::getStoreConfig('salesmanago_tracking/general/tags');
388
  $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
389
 
390
  $apiKey = md5(time() . $apiSecret);
399
  'name' => $data['name'],
400
  'fax' => $data['fax'],
401
  'company' => $data['company'],
402
+ 'phone' => $data['phone'],
403
  'address' => array(
404
+ 'streetAddress' => $data['address']['streetAddress'],
405
+ 'zipCode' => $data['address']['zipCode'],
406
+ 'city' => $data['address']['city'],
407
+ 'country' => $data['address']['country'],
408
  ),
409
  ),
410
  'owner' => $ownerEmail,
411
  'async' => false,
 
412
  );
413
+
414
+
415
+
416
 
417
+ if (!isset($data['is_subscribed'])) {
418
  $data_to_json['forceOptOut'] = true;
419
  $data_to_json['forceOptIn'] = false;
420
  } else {
426
  $data_to_json['birthday'] = $data['birthday'];
427
  }
428
 
429
+ $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($data['customerEmail'])->getData();
430
+
431
+ //BK Change Add a new tag on customer_login
432
+ //BK Change Add a new tag on newsletter subscribe
433
+ $tags=$tags.',last_logged_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST));
434
+ if ($data['is_subscribed'])
435
+ $tags = $tags.',Newsletter_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST));
436
+
437
+ if (!empty($tags)) {
438
+ $tags = explode(",", $tags);
439
+ if (is_array($tags) && count($tags) > 0) {
440
+ $tags = array_map('trim', $tags);
441
+ $data_to_json['tags'] = $tags;
442
+ }
443
+ }
444
+
445
  $json = json_encode($data_to_json);
446
  $result = $this->_doPostRequest('https://' . $endPoint . '/api/contact/upsert', $json);
447
 
458
  public function _setCustomerData($customer){
459
  $data = array();
460
  $subscription_status = 0;
461
+
 
 
 
462
  $data['customerEmail'] = $customer['email'];
463
  $data['entity_id'] = $customer['entity_id'];
464
 
465
  $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer['email']);
466
  $subscription_status = $subscriber->isSubscribed();
467
 
468
+ if(isset($customer['firstname']) && isset($customer['lastname'])){
 
 
469
  $data['name'] = $customer['firstname'].' '.$customer['lastname'];
470
  }
471
 
481
  $data['birthday'] = $year . $month . $day;
482
  }
483
 
 
 
484
  return $data;
485
  }
486
 
app/code/community/SalesManago/Tracking/Model/Customersync.php CHANGED
@@ -1,9 +1,9 @@
1
- <?php
2
- class SalesManago_Tracking_Model_Customersync extends Mage_Core_Model_Abstract
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->_init('tracking/customersync');
8
- }
9
  }
1
+ <?php
2
+ class SalesManago_Tracking_Model_Customersync extends Mage_Core_Model_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->_init('tracking/customersync');
8
+ }
9
  }
app/code/community/SalesManago/Tracking/Model/Observer.php CHANGED
@@ -1,20 +1,41 @@
1
  <?php
2
 
3
- class SalesManago_Tracking_Model_Observer
4
- {
5
-
6
- protected function _getHelper()
7
- {
8
  return Mage::helper('tracking');
9
  }
10
-
11
- public function customer_login($observer)
12
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
14
- if ($active == 1) {
15
- $customer = $observer->getCustomer();
16
 
17
- if (!empty($customer)) {
18
  if (!isset($customer['salesmanago_contact_id']) || empty($customer['salesmanago_contact_id'])) {
19
  $data = $this->_getHelper()->_setCustomerData($customer);
20
 
@@ -36,23 +57,21 @@ class SalesManago_Tracking_Model_Observer
36
  }
37
  }
38
  }
39
- if (!isset($_COOKIE['smclient']) || empty($_COOKIE['smclient'])) {
40
- $period = time() + 36500 * 86400;
41
- $customerData = Mage::getSingleton('customer/session')->getCustomer();
42
- $contactId = $customerData->getSalesmanagoContactId();
43
- $this->_getHelper()->sm_create_cookie('smclient', $contactId, $period);
44
  }
45
  }
46
-
47
- public function customer_register_success($observer)
48
- {
49
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
50
- if ($active == 1) {
51
- $customer = $observer->getCustomer();
52
 
53
- if (!empty($customer) && is_array($customer->getData())) {
54
  $data = $this->_getHelper()->_setCustomerData($customer);
55
- $data['tags'] = explode(",", Mage::getStoreConfig('salesmanago_tracking/general/tagsRegistration'));
56
 
57
  $r = $this->_getHelper()->salesmanagoContactSync($data);
58
 
@@ -71,25 +90,23 @@ class SalesManago_Tracking_Model_Observer
71
  }
72
  }
73
  }
74
- if (!isset($_COOKIE['smclient']) || empty($_COOKIE['smclient'])) {
75
- $period = time() + 36500 * 86400;
76
- $customerData = Mage::getSingleton('customer/session')->getCustomer();
77
- $contactId = $customerData->getSalesmanagoContactId();
78
- $this->_getHelper()->sm_create_cookie('smclient', $contactId, $period);
79
  }
80
-
81
- }
82
-
83
  /*
84
  * Dodanie zdarzenia addContactExtEvent na podsumowaniu zam�wienia z typem PURCHASE
85
  */
86
- public function checkout_onepage_controller_success_action($observer)
87
- {
88
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
89
- if ($active == 1) {
90
  $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
91
  $orderDetails = Mage::getModel('sales/order')->load($orderId);
92
-
93
  $r = $this->_getHelper()->salesmanagoOrderSync($orderDetails);
94
 
95
  if ($r == false || (isset($r['success']) && $r['success'] == false)) {
@@ -102,30 +119,77 @@ class SalesManago_Tracking_Model_Observer
102
  );
103
  $this->_getHelper()->setSalesmanagoCustomerSyncStatus($data);
104
  }
105
-
106
  $eventId = Mage::getSingleton('core/session')->getEventId();
107
  if (isset($eventId) && !empty($eventId)) {
108
  Mage::getSingleton('core/session')->unsEventId();
109
  }
110
  }
111
- }
112
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  /*
114
  * Dodanie (oraz na biezaco modyfikowanie) zdarzenia w koszyku addContactExtEvent z typem CART
115
  */
116
- public function checkout_cart_save_after($observer)
117
- {
118
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
119
- if ($active == 1) {
120
  $cartHelper = Mage::getModel('checkout/cart')->getQuote();
121
- $productsIdsList = array();
122
- $productsNamesList = array();
123
-
124
- $items = $cartHelper->getAllItems();
125
  foreach ($items as $item) {
126
- array_push($productsIdsList, $item->getProduct()->getId());
127
- array_push($productsNamesList, $item->getProduct()->getName());
128
-
129
  }
130
 
131
 
@@ -137,58 +201,56 @@ class SalesManago_Tracking_Model_Observer
137
  $customerEmail = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
138
  $isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
139
  //if (!empty($customerEmail)) {
140
- $apiKey = md5(time() . $apiSecret);
141
- $dateTime = new DateTime('NOW');
142
-
143
 
144
- $data_to_json = array(
145
- 'apiKey' => $apiKey,
146
- 'clientId' => $clientId,
147
- 'requestTime' => time(),
148
- 'sha' => sha1($apiKey . $clientId . $apiSecret),
149
- 'owner' => $ownerEmail,
150
- 'contactEvent' => array(
151
- 'date' => $dateTime->format('c'),
152
- 'contactExtEventType' => 'CART',
153
- 'products' => implode(',', $productsIdsList),
154
- 'value' => $cartHelper->getGrandTotal(),
155
- 'detail1' => implode(",", $productsNamesList),
156
- ),
157
- );
158
 
159
- $eventId = Mage::getSingleton('core/session')->getEventId();
160
 
161
- if (isset($eventId) && !empty($eventId)) {
162
- $data_to_json['contactEvent']['eventId'] = $eventId;
163
- $json = json_encode($data_to_json);
164
- $result = $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/updateContactExtEvent', $json);
165
- } else {
166
- if ($isLoggedIn) {
167
- $data_to_json['email'] = $customerEmail;
168
  } else {
169
- if (!empty($_COOKIE['smclient']))
170
- $data_to_json['contactId'] = $_COOKIE['smclient'];
171
- }
 
 
 
 
172
 
173
- Mage::log(serialize($data_to_json), null, 'mylogfile.log');
174
 
175
- $json = json_encode($data_to_json);
176
- $result = $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/addContactExtEvent', $json);
177
- }
178
 
179
- $r = json_decode($result, true);
180
 
181
- if (!isset($eventId) && isset($r['eventId'])) {
182
- Mage::getSingleton('core/session')->setEventId($r['eventId']);
183
- }
184
  //}
185
  }
186
- }
187
-
188
- public function newsletter_subscriber_save_before($observer)
189
- {
190
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
191
- if ($active == 1) {
192
  $request = Mage::app()->getRequest();
193
  $moduleName = $request->getModuleName();
194
  $controllerName = $request->getControllerName();
@@ -207,7 +269,7 @@ class SalesManago_Tracking_Model_Observer
207
  $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
208
  $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
209
  $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
210
- $newsletterTags = Mage::getStoreConfig('salesmanago_tracking/general/tagsNewsletter');
211
  $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
212
 
213
 
@@ -232,26 +294,22 @@ class SalesManago_Tracking_Model_Observer
232
  'sha' => sha1($apiKey . $clientId . $apiSecret),
233
  'owner' => $ownerEmail,
234
  );
 
 
 
 
235
 
236
- if (!empty($newsletterTags)) {
237
- $newsletterTags = explode(",", $newsletterTags);
238
- if (is_array($newsletterTags) && count($newsletterTags) > 0) {
239
- $newsletterTags = array_map('trim', $newsletterTags);
240
-
241
- }
242
- }
243
 
244
  if ($data['subscriber_status'] == "1" && ($statusChange == true || ($id && $code) || $isAdmin)) {
245
  $data_to_json['forceOptIn'] = true;
246
- $data_to_json['tags'] = $newsletterTags;
247
  } elseif ($data['subscriber_status'] == "3" && ($statusChange == true || ($id && $code) || $isAdmin)) {
248
  $data_to_json['forceOptOut'] = true;
249
- $data_to_json['removeTags'] = $newsletterTags;
250
  } elseif ($actionName == 'massDelete') {
251
  $data_to_json['forceOptOut'] = true;
252
- $data_to_json['removeTags'] = $newsletterTags;
253
  }
254
-
 
 
255
  $json = json_encode($data_to_json);
256
  $result = $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/upsert', $json);
257
 
@@ -272,9 +330,8 @@ class SalesManago_Tracking_Model_Observer
272
  return $r;
273
  }
274
  }
275
- }
276
-
277
- public function newsletter_subscriber_delete_after($observer)
278
  {
279
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
280
  if ($active == 1) {
@@ -320,137 +377,5 @@ class SalesManago_Tracking_Model_Observer
320
  }
321
  }
322
  }
323
-
324
- public function customer_data_edit($observer)
325
- {
326
- $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
327
- if ($active == 1) {
328
- if (Mage::getSingleton('customer/session')->isLoggedIn()) {
329
- $customer = Mage::getSingleton('customer/session')->getCustomer();
330
-
331
- if (isset($customer['salesmanago_contact_id']) && !empty($customer['salesmanago_contact_id'])) {
332
-
333
- $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
334
- $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
335
- $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
336
- $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
337
- $apiKey = md5(time() . $apiSecret);
338
- $contactId = $customer->getSalesmanagoContactId();
339
-
340
- foreach ($customer->getAddresses() as $address) {
341
- $data = $address->toArray();
342
- }
343
-
344
- $street = $address->getStreet(1) . ' ' . $address->getStreet(2);
345
-
346
- if (isset($data['firstname']) && isset($data['lastname']) && isset($data['middlename'])) {
347
- $data['name'] = $data['firstname'] . ' ' . $data['middlename'] . ' ' . $data['lastname'];
348
- } else {
349
- $data['name'] = $data['firstname'] . ' ' . $data['lastname'];
350
- }
351
-
352
- $data_to_json = array(
353
- 'apiKey' => $apiKey,
354
- 'clientId' => $clientId,
355
- 'requestTime' => time(),
356
- 'sha' => sha1($apiKey . $clientId . $apiSecret),
357
- 'contactId' => $contactId,
358
- 'contact' => array(
359
- 'name' => $data['name'],
360
- 'fax' => $data['fax'],
361
- 'company' => $data['company'],
362
- 'phone' => $data['telephone'],
363
- 'address' => array(
364
- 'streetAddress' => $street,
365
- 'zipCode' => $data['postcode'],
366
- 'city' => $data['city'],
367
- 'country' => $data['country_id'],
368
- ),
369
- ),
370
- 'owner' => $ownerEmail,
371
- 'async' => false,
372
- );
373
-
374
- $json = json_encode($data_to_json);
375
- $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/update', $json);
376
- }
377
- }
378
- }
379
- }
380
-
381
- public function adminSystemConfigChangedSectionSalesmanago_tracking($observer)
382
- {
383
- $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
384
- $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
385
- $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
386
- $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
387
- $apiKey = md5(time() . $apiSecret);
388
- $version = Mage::getVersion();
389
-
390
- $data_to_json = array(
391
- 'apiKey' => $apiKey,
392
- 'clientId' => $clientId,
393
- 'requestTime' => time(),
394
- 'sha' => sha1($apiKey . $clientId . $apiSecret),
395
- 'owner' => $ownerEmail,
396
- 'tags' => ["MAGENTO_1"],
397
- 'properties' => array("platform"=>"Magento", "version"=>$version),
398
- );
399
-
400
- $json = json_encode($data_to_json);
401
- $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/upsertVendorToSupport', $json);
402
- }
403
-
404
- public function wishlist_event($observer)
405
- {
406
- $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
407
- if ($active == 1) {
408
- $isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
409
- if ($isLoggedIn) {
410
- $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
411
- $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
412
- $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
413
- $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
414
- $apiKey = md5(time() . $apiSecret);
415
- $dateTime = new DateTime('NOW');
416
- $customer = Mage::getSingleton('customer/session')->getCustomer();
417
- $product = $observer->getEvent()->getItems()[0]->getProduct();
418
- $productId = $product->getId();
419
- $productName = $product->getName();
420
- $productValue = round($product->getPrice(), 2);
421
-
422
-
423
- $data_to_json = array(
424
- 'apiKey' => $apiKey,
425
- 'clientId' => $clientId,
426
- 'requestTime' => time(),
427
- 'sha' => sha1($apiKey . $clientId . $apiSecret),
428
- 'owner' => $ownerEmail,
429
- 'contactEvent' => array(
430
- 'date' => $dateTime->format('c'),
431
- 'contactExtEventType' => 'OTHER',
432
- 'products' => $productId,
433
- 'value' => $productValue,
434
- 'detail1' => $productName,
435
- 'description' => 'WISHLIST',
436
- ),
437
- );
438
-
439
-
440
- if ($isLoggedIn) {
441
- $data_to_json['email'] = $customer->getEmail();
442
- $json = json_encode($data_to_json);
443
- } else {
444
- if (!isset($_COOKIE['smclient']) || empty($_COOKIE['smclient'])){
445
- $data_to_json['contactId'] = $_COOKIE['smclient'];
446
- $json = json_encode($data_to_json);
447
- }
448
- }
449
-
450
- if(!empty($json))
451
- $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/upsertVendorToSupport', $json);
452
- }
453
- }
454
- }
455
  }
456
 
1
  <?php
2
 
3
+ class SalesManago_Tracking_Model_Observer {
4
+
5
+ protected function _getHelper(){
 
 
6
  return Mage::helper('tracking');
7
  }
8
+
9
+ /*
10
+ * BK Changes to Sales Manago Module.
11
+ * Adding Observer to Review event.
12
+ * Will send Sales Manago API If a customer review is approved.
13
+ * @author:Carlos Alonso de Linaje.
14
+ * @date: 28/Oct/2015
15
+ */
16
+ public function review_save_after($observer)
17
+ {
18
+ $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
19
+ if($active == 1) {
20
+ $object = $observer->getEvent()->getObject();
21
+ $review = $object->getData();
22
+ //Only send data if is a Customer (not just Guest)
23
+ //And if the review is approved
24
+ if ($review['status_id']==1 && array_key_exists('customer_id', $review))
25
+ {
26
+ $r =$this->_getHelper()->salesmanagoReviewSync($review);
27
+ return $r;
28
+ Mage::log($r);
29
+ }
30
+ }
31
+ return false;
32
+ }
33
+ public function customer_login($observer) {
34
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
35
+ if($active == 1) {
36
+ $customer = $observer->getCustomer()->getData();
37
 
38
+ if (is_array($customer) && !empty($customer)) {
39
  if (!isset($customer['salesmanago_contact_id']) || empty($customer['salesmanago_contact_id'])) {
40
  $data = $this->_getHelper()->_setCustomerData($customer);
41
 
57
  }
58
  }
59
  }
60
+ if(!isset($_COOKIE['smclient']) || empty($_COOKIE['smclient'])){
61
+ $period = time() + 36500 * 86400;
62
+ $customerData = Mage::getSingleton('customer/session')->getCustomer();
63
+ $contactId = $customerData->getSalesmanagoContactId();
64
+ $this->_getHelper()->sm_create_cookie('smclient', $contactId, $period);
65
  }
66
  }
67
+
68
+ public function customer_register_success($observer) {
 
69
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
70
+ if($active == 1) {
71
+ $customer = $observer->getCustomer()->getData();
72
 
73
+ if (is_array($customer) && !empty($customer)) {
74
  $data = $this->_getHelper()->_setCustomerData($customer);
 
75
 
76
  $r = $this->_getHelper()->salesmanagoContactSync($data);
77
 
90
  }
91
  }
92
  }
93
+ if(!isset($_COOKIE['smclient']) || empty($_COOKIE['smclient'])){
94
+ $period = time() + 36500 * 86400;
95
+ $customerData = Mage::getSingleton('customer/session')->getCustomer();
96
+ $contactId = $customerData->getSalesmanagoContactId();
97
+ $this->_getHelper()->sm_create_cookie('smclient', $contactId, $period);
98
  }
99
+
100
+ }
101
+
102
  /*
103
  * Dodanie zdarzenia addContactExtEvent na podsumowaniu zam�wienia z typem PURCHASE
104
  */
105
+ public function checkout_onepage_controller_success_action($observer){
 
106
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
107
+ if($active == 1) {
108
  $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
109
  $orderDetails = Mage::getModel('sales/order')->load($orderId);
 
110
  $r = $this->_getHelper()->salesmanagoOrderSync($orderDetails);
111
 
112
  if ($r == false || (isset($r['success']) && $r['success'] == false)) {
119
  );
120
  $this->_getHelper()->setSalesmanagoCustomerSyncStatus($data);
121
  }
122
+ $this->_getHelper()->salesmanagoSalesSync($orderDetails);
123
  $eventId = Mage::getSingleton('core/session')->getEventId();
124
  if (isset($eventId) && !empty($eventId)) {
125
  Mage::getSingleton('core/session')->unsEventId();
126
  }
127
  }
128
+ }
129
+
130
+ /*
131
+ * BK Changes to Sales Manago Module.
132
+ * Adding Observer to Whislist event.
133
+ * Will Save WishList products on customer's Custom Details
134
+ * @author:Carlos Alonso de Linaje.
135
+ * @date: 17/Oct/2015
136
+ */
137
+ public function wishlist_item_collection_products_after_load($observer)
138
+ {
139
+ Mage::log('whislist');
140
+ $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
141
+ if($active == 1)
142
+ {
143
+ $_itemCollection = Mage::helper('wishlist')->getWishlistItemCollection();
144
+ foreach ($_itemCollection as $_item)
145
+ {
146
+ $_products .= $_item->getProduct()->getId().',';
147
+ }
148
+
149
+ $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
150
+ $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
151
+ $apiKey = md5(time() . $apiSecret);
152
+ $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
153
+ $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
154
+ $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
155
+
156
+ $data_to_json = array(
157
+ 'apiKey' => $apiKey,
158
+ 'clientId' => $clientId,
159
+ 'requestTime' => time(),
160
+ 'contact' => array(
161
+ 'email' => $email,
162
+ 'state' => 'CUSTOMER',
163
+ ),
164
+ 'sha' => sha1($apiKey . $clientId . $apiSecret),
165
+ 'owner' => $ownerEmail,
166
+ );
167
+ //BK Change Add a new tag on newsletter subscribe
168
+ $data_to_json['properties'] = array(
169
+ 'WhislistDate_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) =>
170
+ Mage::getModel('core/date')->date('Y-m-d H:i:s'),
171
+ 'WhislistProducts_'.str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)) =>
172
+ $_products
173
+ );
174
+
175
+ $json = json_encode($data_to_json);
176
+ $result = $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/upsert', $json);
177
+ $r = json_decode($result, true);
178
+ return $r;
179
+ }
180
+ }
181
+
182
  /*
183
  * Dodanie (oraz na biezaco modyfikowanie) zdarzenia w koszyku addContactExtEvent z typem CART
184
  */
185
+ public function checkout_cart_save_after($observer){
 
186
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
187
+ if($active == 1) {
188
  $cartHelper = Mage::getModel('checkout/cart')->getQuote();
189
+ $items = $cartHelper->getAllVisibleItems();
190
+ $itemsNamesList = array();
 
 
191
  foreach ($items as $item) {
192
+ array_push($itemsNamesList, $item->getProduct()->getId());
 
 
193
  }
194
 
195
 
201
  $customerEmail = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
202
  $isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
203
  //if (!empty($customerEmail)) {
204
+ $apiKey = md5(time() . $apiSecret);
205
+ $dateTime = new DateTime('NOW');
 
206
 
207
+ $data_to_json = array(
208
+ 'apiKey' => $apiKey,
209
+ 'clientId' => $clientId,
210
+ 'requestTime' => time(),
211
+ 'sha' => sha1($apiKey . $clientId . $apiSecret),
212
+ 'owner' => $ownerEmail,
213
+ 'contactEvent' => array(
214
+ 'date' => $dateTime->format('c'),
215
+ 'contactExtEventType' => 'CART',
216
+ 'products' => implode(',', $itemsNamesList),
217
+ 'value' => $cartHelper->getGrandTotal(),
218
+ ),
219
+ );
 
220
 
221
+ $eventId = Mage::getSingleton('core/session')->getEventId();
222
 
223
+ if (isset($eventId) && !empty($eventId)) {
224
+ $data_to_json['contactEvent']['eventId'] = $eventId;
225
+ $json = json_encode($data_to_json);
226
+ $result = $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/updateContactExtEvent', $json);
 
 
 
227
  } else {
228
+ if($isLoggedIn){
229
+ $data_to_json['email'] = $customerEmail;
230
+ }
231
+ else {
232
+ if(!empty($_COOKIE['smclient']))
233
+ $data_to_json['contactId'] = $_COOKIE['smclient'];
234
+ }
235
 
236
+ Mage::log(serialize($data_to_json), null, 'mylogfile.log');
237
 
238
+ $json = json_encode($data_to_json);
239
+ $result = $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/addContactExtEvent', $json);
240
+ }
241
 
242
+ $r = json_decode($result, true);
243
 
244
+ if (!isset($eventId) && isset($r['eventId'])) {
245
+ Mage::getSingleton('core/session')->setEventId($r['eventId']);
246
+ }
247
  //}
248
  }
249
+ }
250
+
251
+ public function newsletter_subscriber_save_before($observer){
 
252
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
253
+ if($active == 1) {
254
  $request = Mage::app()->getRequest();
255
  $moduleName = $request->getModuleName();
256
  $controllerName = $request->getControllerName();
269
  $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
270
  $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
271
  $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
272
+ $tags = Mage::getStoreConfig('salesmanago_tracking/general/tags');
273
  $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
274
 
275
 
294
  'sha' => sha1($apiKey . $clientId . $apiSecret),
295
  'owner' => $ownerEmail,
296
  );
297
+ //BK Change Add a new tag on newsletter subscribe
298
+ $data_to_json['tags'] = array('Newsletter_'.
299
+ str_replace('.','_',parse_url(Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB), PHP_URL_HOST)));
300
+ //Mage::log($data_to_json);
301
 
 
 
 
 
 
 
 
302
 
303
  if ($data['subscriber_status'] == "1" && ($statusChange == true || ($id && $code) || $isAdmin)) {
304
  $data_to_json['forceOptIn'] = true;
 
305
  } elseif ($data['subscriber_status'] == "3" && ($statusChange == true || ($id && $code) || $isAdmin)) {
306
  $data_to_json['forceOptOut'] = true;
 
307
  } elseif ($actionName == 'massDelete') {
308
  $data_to_json['forceOptOut'] = true;
 
309
  }
310
+
311
+
312
+
313
  $json = json_encode($data_to_json);
314
  $result = $this->_getHelper()->_doPostRequest('https://' . $endPoint . '/api/contact/upsert', $json);
315
 
330
  return $r;
331
  }
332
  }
333
+ }
334
+ public function newsletter_subscriber_delete_after($observer)
 
335
  {
336
  $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
337
  if ($active == 1) {
377
  }
378
  }
379
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  }
381
 
app/code/community/SalesManago/Tracking/Model/Resource/Customersync.php CHANGED
@@ -1,7 +1,7 @@
1
- <?php
2
- class SalesManago_Tracking_Model_Resource_Customersync extends Mage_Core_Model_Resource_Db_Abstract {
3
-
4
- protected function _construct() {
5
- $this->_init('tracking/customersync', 'customer_sync_id');
6
- }
7
  }
1
+ <?php
2
+ class SalesManago_Tracking_Model_Resource_Customersync extends Mage_Core_Model_Resource_Db_Abstract {
3
+
4
+ protected function _construct() {
5
+ $this->_init('tracking/customersync', 'customer_sync_id');
6
+ }
7
  }
app/code/community/SalesManago/Tracking/Model/Resource/Customersync/Collection.php CHANGED
@@ -1,8 +1,8 @@
1
- <?php
2
- class SalesManago_Tracking_Model_Resource_Customersync_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
3
- {
4
- public function _construct()
5
- {
6
- $this->_init('tracking/customersync');
7
- }
8
  }
1
+ <?php
2
+ class SalesManago_Tracking_Model_Resource_Customersync_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ $this->_init('tracking/customersync');
7
+ }
8
  }
app/code/community/SalesManago/Tracking/Model/Resource/Setup.php CHANGED
@@ -1,5 +1,5 @@
1
- <?php
2
-
3
- class SalesManago_Tracking_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
4
- {
5
  }
1
+ <?php
2
+
3
+ class SalesManago_Tracking_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
4
+ {
5
  }
app/code/community/SalesManago/Tracking/controllers/CustomerController.php CHANGED
@@ -1,242 +1,242 @@
1
- <?php
2
- class SalesManago_Tracking_CustomerController extends Mage_Core_Controller_Front_Action{
3
-
4
- protected function _getHelper(){
5
- return Mage::helper('tracking');
6
- }
7
-
8
- public function exportAction(){
9
- $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
10
- if($active == 1) {
11
- $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
12
- $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
13
- $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
14
- $tags = Mage::getStoreConfig('salesmanago_tracking/general/tags');
15
- $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
16
-
17
- $key = $this->getRequest()->getParam('key');
18
-
19
- if (isset($key) && isset($apiSecret) && $key == sha1($apiSecret)) {
20
-
21
- $apiKey = md5(time() . $apiSecret);
22
-
23
- $data_to_json = array(
24
- 'apiKey' => $apiKey,
25
- 'clientId' => $clientId,
26
- 'requestTime' => time(),
27
- 'sha' => sha1($apiKey . $clientId . $apiSecret),
28
-
29
- 'upsertDetails' => array(),
30
- 'owner' => $ownerEmail,
31
- );
32
-
33
- $collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
34
-
35
- $i = 0;
36
- foreach ($collection as $item) {
37
- if (!isset($item['salesmanago_contact_id']) || empty($item['salesmanago_contact_id']) || $item['salesmanago_contact_id'] == 0) {
38
- $status = Mage::getModel('newsletter/subscriber')->loadByEmail($item['email'])->isSubscribed();
39
-
40
- if ($status) {
41
- $data_to_json['upsertDetails'][$i]['forceOptIn'] = true;
42
- } else {
43
- $data_to_json['upsertDetails'][$i]['forceOptOut'] = true;
44
- }
45
- $data_to_json['upsertDetails'][$i]['contact']['email'] = $item['email'];
46
- $data_to_json['upsertDetails'][$i]['contact']['name'] = $item['firstname'] . ' ' . $item['lastname'];
47
-
48
- $i++;
49
- }
50
- }
51
-
52
- $json = json_encode($data_to_json);
53
- $result = $this->_do_post_request('https://' . $endPoint . '/api/contact/batchupsert', $json);
54
-
55
- $r = json_decode($result, true);
56
-
57
- $return = array();
58
- if (isset($r['success']) && $r['success'] == true && isset($r['contactIds']) && is_array($r['contactIds'])) {
59
- foreach ($r['contactIds'] as $key => $value) {
60
- $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($key);
61
- try {
62
- $return[$key]['msg'] = 'Successfully added';
63
- $customer->setData('salesmanago_contact_id', $value)->save();
64
- } catch (Exception $e) {
65
- $return[$key]['msg'] = 'Upsert error';
66
- Mage::log($e->getMessage());
67
- }
68
- }
69
- } else {
70
- $return['msg'] = 'BatchUpsert error';
71
- }
72
- return $return;
73
- }
74
- }
75
- }
76
-
77
- public function syncAction(){
78
- $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
79
- if($active == 1) {
80
- $key = $this->getRequest()->getParam('key');
81
- $action = $this->getRequest()->getParam('action');
82
-
83
- $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
84
- $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
85
- $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
86
- $tags = Mage::getStoreConfig('salesmanago_tracking/general/tags');
87
- $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
88
-
89
- if (isset($key) && isset($apiSecret) && $key == sha1($apiSecret)) {
90
- $model = Mage::getModel('tracking/customersync');
91
- $collection = $model->getCollection()->addFieldToFilter('status', 0);
92
- $dateTime = new DateTime('NOW');
93
-
94
- foreach ($collection as $item) {
95
- if (!isset($action) || !ctype_digit($action)) {
96
- $action = $item->getAction();
97
- }
98
- $counter = $item->getCounter();
99
-
100
- if ($counter < 5) {
101
- switch ($action) {
102
- case 1: //register
103
- $customer = Mage::getModel('customer/customer')->load($item->getCustomerId())->getData();
104
- $data = $this->_getHelper()->_setCustomerData($customer);
105
-
106
- $r = $this->_getHelper()->salesmanagoContactSync($data);
107
-
108
- if ($r == false || (isset($r['success']) && $r['success'] == false)) {
109
- try {
110
- $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setId($item->getCustomerSyncId())->save();
111
- } catch (Exception $e) {
112
- Mage::log($e->getMessage());
113
- }
114
- } elseif (isset($r['success']) && $r['success'] == true) {
115
- try {
116
- $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setStatus(1)->setId($item->getCustomerSyncId())->save();
117
- } catch (Exception $e) {
118
- Mage::log($e->getMessage());
119
- }
120
- }
121
-
122
- break;
123
- case 2: //login
124
- $customer = Mage::getModel('customer/customer')->load($item->getCustomerId())->getData();
125
-
126
- if (!isset($customer['salesmanago_contact_id']) || empty($customer['salesmanago_contact_id'])) {
127
- $data = $this->_getHelper()->_setCustomerData($customer);
128
-
129
- $r = $this->_getHelper()->salesmanagoContactSync($data);
130
-
131
- if ($r == false || (isset($r['success']) && $r['success'] == false)) {
132
- try {
133
- $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setId($item->getCustomerSyncId())->save();
134
- } catch (Exception $e) {
135
- Mage::log($e->getMessage());
136
- }
137
- } elseif (isset($r['success']) && $r['success'] == true) {
138
- try {
139
- $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setStatus(1)->setId($item->getCustomerSyncId())->save();
140
- } catch (Exception $e) {
141
- Mage::log($e->getMessage());
142
- }
143
- }
144
- }
145
- break;
146
- case 3: //order purchase
147
- $orderId = $item->getOrderId();
148
- $orderDetails = Mage::getModel('sales/order')->load($orderId);
149
-
150
- $r = $this->_getHelper()->salesmanagoOrderSync($orderDetails);
151
-
152
- if ($r == false || (isset($r['success']) && $r['success'] == false)) {
153
- try {
154
- $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setId($item->getCustomerSyncId())->save();
155
- } catch (Exception $e) {
156
- Mage::log($e->getMessage());
157
- }
158
- } elseif (isset($r['success']) && $r['success'] == true) {
159
- try {
160
- $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setStatus(1)->setId($item->getCustomerSyncId())->save();
161
- } catch (Exception $e) {
162
- Mage::log($e->getMessage());
163
- }
164
- }
165
- break;
166
- case 4: //newsletter subscribe / unsubscribe
167
- $status = Mage::getModel('newsletter/subscriber')->loadByEmail($item->getEmail())->isSubscribed();
168
-
169
- $apiKey = md5(time() . $apiSecret);
170
-
171
- $data_to_json = array(
172
- 'apiKey' => $apiKey,
173
- 'clientId' => $clientId,
174
- 'requestTime' => time(),
175
- 'email' => $item->getEmail(),
176
- 'sha' => sha1($apiKey . $clientId . $apiSecret),
177
- 'owner' => $ownerEmail,
178
- );
179
-
180
- if ($status) {
181
- $data_to_json['forceOptIn'] = true;
182
- } else {
183
- $data_to_json['forceOptOut'] = true;
184
- }
185
-
186
- $json = json_encode($data_to_json);
187
- $result = $this->_do_post_request('https://' . $endPoint . '/api/contact/update', $json);
188
-
189
- $r = json_decode($result, true);
190
-
191
- if ($r == false || (isset($r['success']) && $r['success'] == false)) {
192
- try {
193
- $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setId($item->getCustomerSyncId())->save();
194
- } catch (Exception $e) {
195
- Mage::log($e->getMessage());
196
- }
197
- } elseif (isset($r['success']) && $r['success'] == true) {
198
- try {
199
- $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setStatus(1)->setId($item->getCustomerSyncId())->save();
200
- } catch (Exception $e) {
201
- Mage::log($e->getMessage());
202
- }
203
- }
204
- break;
205
- default:
206
- break;
207
- }
208
- }
209
- }
210
- }
211
- }
212
- }
213
-
214
- private function _do_post_request($url, $data) {
215
- $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
216
- if($active == 1) {
217
- $connection_timeout = Mage::getStoreConfig('salesmanago_tracking/general/connection_timeout');
218
-
219
- $ch = curl_init($url);
220
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
221
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
222
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
223
- if (isset($connection_timeout) && !empty($connection_timeout)) {
224
- curl_setopt($ch, CURLOPT_TIMEOUT_MS, $connection_timeout);
225
- }
226
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
227
-
228
- $result = curl_exec($ch);
229
-
230
- if (curl_errno($ch) > 0) {
231
- if (curl_errno($ch) == 28) {
232
- Mage::log("TIMEOUT ERROR NO: " . curl_errno($ch));
233
- } else {
234
- Mage::log("ERROR NO: " . curl_errno($ch));
235
- }
236
- return false;
237
- }
238
-
239
- return $result;
240
- }
241
- }
242
  }
1
+ <?php
2
+ class SalesManago_Tracking_CustomerController extends Mage_Core_Controller_Front_Action{
3
+
4
+ protected function _getHelper(){
5
+ return Mage::helper('tracking');
6
+ }
7
+
8
+ public function exportAction(){
9
+ $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
10
+ if($active == 1) {
11
+ $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
12
+ $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
13
+ $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
14
+ $tags = Mage::getStoreConfig('salesmanago_tracking/general/tags');
15
+ $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
16
+
17
+ $key = $this->getRequest()->getParam('key');
18
+
19
+ if (isset($key) && isset($apiSecret) && $key == sha1($apiSecret)) {
20
+
21
+ $apiKey = md5(time() . $apiSecret);
22
+
23
+ $data_to_json = array(
24
+ 'apiKey' => $apiKey,
25
+ 'clientId' => $clientId,
26
+ 'requestTime' => time(),
27
+ 'sha' => sha1($apiKey . $clientId . $apiSecret),
28
+
29
+ 'upsertDetails' => array(),
30
+ 'owner' => $ownerEmail,
31
+ );
32
+
33
+ $collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
34
+
35
+ $i = 0;
36
+ foreach ($collection as $item) {
37
+ if (!isset($item['salesmanago_contact_id']) || empty($item['salesmanago_contact_id']) || $item['salesmanago_contact_id'] == 0) {
38
+ $status = Mage::getModel('newsletter/subscriber')->loadByEmail($item['email'])->isSubscribed();
39
+
40
+ if ($status) {
41
+ $data_to_json['upsertDetails'][$i]['forceOptIn'] = true;
42
+ } else {
43
+ $data_to_json['upsertDetails'][$i]['forceOptOut'] = true;
44
+ }
45
+ $data_to_json['upsertDetails'][$i]['contact']['email'] = $item['email'];
46
+ $data_to_json['upsertDetails'][$i]['contact']['name'] = $item['firstname'] . ' ' . $item['lastname'];
47
+
48
+ $i++;
49
+ }
50
+ }
51
+
52
+ $json = json_encode($data_to_json);
53
+ $result = $this->_do_post_request('https://' . $endPoint . '/api/contact/batchupsert', $json);
54
+
55
+ $r = json_decode($result, true);
56
+
57
+ $return = array();
58
+ if (isset($r['success']) && $r['success'] == true && isset($r['contactIds']) && is_array($r['contactIds'])) {
59
+ foreach ($r['contactIds'] as $key => $value) {
60
+ $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($key);
61
+ try {
62
+ $return[$key]['msg'] = 'Successfully added';
63
+ $customer->setData('salesmanago_contact_id', $value)->save();
64
+ } catch (Exception $e) {
65
+ $return[$key]['msg'] = 'Upsert error';
66
+ Mage::log($e->getMessage());
67
+ }
68
+ }
69
+ } else {
70
+ $return['msg'] = 'BatchUpsert error';
71
+ }
72
+ return $return;
73
+ }
74
+ }
75
+ }
76
+
77
+ public function syncAction(){
78
+ $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
79
+ if($active == 1) {
80
+ $key = $this->getRequest()->getParam('key');
81
+ $action = $this->getRequest()->getParam('action');
82
+
83
+ $clientId = Mage::getStoreConfig('salesmanago_tracking/general/client_id');
84
+ $apiSecret = Mage::getStoreConfig('salesmanago_tracking/general/api_secret');
85
+ $ownerEmail = Mage::getStoreConfig('salesmanago_tracking/general/email');
86
+ $tags = Mage::getStoreConfig('salesmanago_tracking/general/tags');
87
+ $endPoint = Mage::getStoreConfig('salesmanago_tracking/general/endpoint');
88
+
89
+ if (isset($key) && isset($apiSecret) && $key == sha1($apiSecret)) {
90
+ $model = Mage::getModel('tracking/customersync');
91
+ $collection = $model->getCollection()->addFieldToFilter('status', 0);
92
+ $dateTime = new DateTime('NOW');
93
+
94
+ foreach ($collection as $item) {
95
+ if (!isset($action) || !ctype_digit($action)) {
96
+ $action = $item->getAction();
97
+ }
98
+ $counter = $item->getCounter();
99
+
100
+ if ($counter < 5) {
101
+ switch ($action) {
102
+ case 1: //register
103
+ $customer = Mage::getModel('customer/customer')->load($item->getCustomerId())->getData();
104
+ $data = $this->_getHelper()->_setCustomerData($customer);
105
+
106
+ $r = $this->_getHelper()->salesmanagoContactSync($data);
107
+
108
+ if ($r == false || (isset($r['success']) && $r['success'] == false)) {
109
+ try {
110
+ $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setId($item->getCustomerSyncId())->save();
111
+ } catch (Exception $e) {
112
+ Mage::log($e->getMessage());
113
+ }
114
+ } elseif (isset($r['success']) && $r['success'] == true) {
115
+ try {
116
+ $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setStatus(1)->setId($item->getCustomerSyncId())->save();
117
+ } catch (Exception $e) {
118
+ Mage::log($e->getMessage());
119
+ }
120
+ }
121
+
122
+ break;
123
+ case 2: //login
124
+ $customer = Mage::getModel('customer/customer')->load($item->getCustomerId())->getData();
125
+
126
+ if (!isset($customer['salesmanago_contact_id']) || empty($customer['salesmanago_contact_id'])) {
127
+ $data = $this->_getHelper()->_setCustomerData($customer);
128
+
129
+ $r = $this->_getHelper()->salesmanagoContactSync($data);
130
+
131
+ if ($r == false || (isset($r['success']) && $r['success'] == false)) {
132
+ try {
133
+ $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setId($item->getCustomerSyncId())->save();
134
+ } catch (Exception $e) {
135
+ Mage::log($e->getMessage());
136
+ }
137
+ } elseif (isset($r['success']) && $r['success'] == true) {
138
+ try {
139
+ $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setStatus(1)->setId($item->getCustomerSyncId())->save();
140
+ } catch (Exception $e) {
141
+ Mage::log($e->getMessage());
142
+ }
143
+ }
144
+ }
145
+ break;
146
+ case 3: //order purchase
147
+ $orderId = $item->getOrderId();
148
+ $orderDetails = Mage::getModel('sales/order')->load($orderId);
149
+
150
+ $r = $this->_getHelper()->salesmanagoOrderSync($orderDetails);
151
+
152
+ if ($r == false || (isset($r['success']) && $r['success'] == false)) {
153
+ try {
154
+ $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setId($item->getCustomerSyncId())->save();
155
+ } catch (Exception $e) {
156
+ Mage::log($e->getMessage());
157
+ }
158
+ } elseif (isset($r['success']) && $r['success'] == true) {
159
+ try {
160
+ $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setStatus(1)->setId($item->getCustomerSyncId())->save();
161
+ } catch (Exception $e) {
162
+ Mage::log($e->getMessage());
163
+ }
164
+ }
165
+ break;
166
+ case 4: //newsletter subscribe / unsubscribe
167
+ $status = Mage::getModel('newsletter/subscriber')->loadByEmail($item->getEmail())->isSubscribed();
168
+
169
+ $apiKey = md5(time() . $apiSecret);
170
+
171
+ $data_to_json = array(
172
+ 'apiKey' => $apiKey,
173
+ 'clientId' => $clientId,
174
+ 'requestTime' => time(),
175
+ 'email' => $item->getEmail(),
176
+ 'sha' => sha1($apiKey . $clientId . $apiSecret),
177
+ 'owner' => $ownerEmail,
178
+ );
179
+
180
+ if ($status) {
181
+ $data_to_json['forceOptIn'] = true;
182
+ } else {
183
+ $data_to_json['forceOptOut'] = true;
184
+ }
185
+
186
+ $json = json_encode($data_to_json);
187
+ $result = $this->_do_post_request('https://' . $endPoint . '/api/contact/update', $json);
188
+
189
+ $r = json_decode($result, true);
190
+
191
+ if ($r == false || (isset($r['success']) && $r['success'] == false)) {
192
+ try {
193
+ $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setId($item->getCustomerSyncId())->save();
194
+ } catch (Exception $e) {
195
+ Mage::log($e->getMessage());
196
+ }
197
+ } elseif (isset($r['success']) && $r['success'] == true) {
198
+ try {
199
+ $model->load($item->getCustomerSyncId())->setCounter($counter + 1)->setUpdateTime($dateTime->format('c'))->setStatus(1)->setId($item->getCustomerSyncId())->save();
200
+ } catch (Exception $e) {
201
+ Mage::log($e->getMessage());
202
+ }
203
+ }
204
+ break;
205
+ default:
206
+ break;
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+
214
+ private function _do_post_request($url, $data) {
215
+ $active = Mage::getStoreConfig('salesmanago_tracking/general/active');
216
+ if($active == 1) {
217
+ $connection_timeout = Mage::getStoreConfig('salesmanago_tracking/general/connection_timeout');
218
+
219
+ $ch = curl_init($url);
220
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
221
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
222
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
223
+ if (isset($connection_timeout) && !empty($connection_timeout)) {
224
+ curl_setopt($ch, CURLOPT_TIMEOUT_MS, $connection_timeout);
225
+ }
226
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
227
+
228
+ $result = curl_exec($ch);
229
+
230
+ if (curl_errno($ch) > 0) {
231
+ if (curl_errno($ch) == 28) {
232
+ Mage::log("TIMEOUT ERROR NO: " . curl_errno($ch));
233
+ } else {
234
+ Mage::log("ERROR NO: " . curl_errno($ch));
235
+ }
236
+ return false;
237
+ }
238
+
239
+ return $result;
240
+ }
241
+ }
242
  }
app/code/community/SalesManago/Tracking/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <SalesManago_Tracking>
5
- <version>1.5.1</version>
6
  </SalesManago_Tracking>
7
  </modules>
8
 
@@ -81,35 +81,24 @@
81
  </salesmanago_tracking_observer>
82
  </observers>
83
  </checkout_cart_save_after>
84
-
85
- <customer_address_save_commit_after>
86
- <observers>
87
- <salesmanago_tracking_observer>
88
- <type>singleton</type>
89
- <class>SalesManago_Tracking_Model_Observer</class>
90
- <method>customer_data_edit</method>
91
- </salesmanago_tracking_observer>
92
- </observers>
93
- </customer_address_save_commit_after>
94
- <admin_system_config_changed_section_salesmanago_tracking>
95
  <observers>
96
- <salesmanago_tracking_observer>
97
- <type>singleton</type>
98
- <class>SalesManago_Tracking_Model_Observer</class>
99
- <method>adminSystemConfigChangedSectionSalesmanago_tracking</method>
100
- </salesmanago_tracking_observer>
101
- </observers>
102
- </admin_system_config_changed_section_salesmanago_tracking>
103
-
104
- <wishlist_product_add_after>
105
  <observers>
106
- <salesmanago_tracking_observer>
107
- <type>singleton</type>
108
- <class>SalesManago_Tracking_Model_Observer</class>
109
- <method>wishlist_event</method>
110
- </salesmanago_tracking_observer>
111
- </observers>
112
- </wishlist_product_add_after>
113
  </events>
114
 
115
  <helpers>
@@ -120,7 +109,7 @@
120
 
121
  <blocks>
122
  <tracking>
123
- <class>SalesManago_Tracking_Block</class>
124
  </tracking>
125
  </blocks>
126
 
@@ -175,20 +164,11 @@
175
  </routers>
176
  </frontend>
177
  <adminhtml>
178
- <translate>
179
- <modules>
180
- <SalesManago_Tracking>
181
- <files>
182
- <default>Salesmanago_Tracking.csv</default>
183
- </files>
184
- </SalesManago_Tracking>
185
- </modules>
186
- </translate>
187
- <acl>
188
- <resources>
189
- <all>
190
  <title>Allow Everything</title>
191
- </all>
192
  <admin>
193
  <children>
194
  <system>
2
  <config>
3
  <modules>
4
  <SalesManago_Tracking>
5
+ <version>0.0.8</version>
6
  </SalesManago_Tracking>
7
  </modules>
8
 
81
  </salesmanago_tracking_observer>
82
  </observers>
83
  </checkout_cart_save_after>
84
+ <wishlist_item_collection_products_after_load>
 
 
 
 
 
 
 
 
 
 
85
  <observers>
86
+ <salesmanago_tracking_observer>
87
+ <type>singleton</type>
88
+ <class>SalesManago_Tracking_Model_Observer</class>
89
+ <method>wishlist_item_collection_products_after_load</method>
90
+ </salesmanago_tracking_observer>
91
+ </observers>
92
+ </wishlist_item_collection_products_after_load>
93
+ <review_save_after>
 
94
  <observers>
95
+ <salesmanago_tracking_observer>
96
+ <type>singleton</type>
97
+ <class>SalesManago_Tracking_Model_Observer</class>
98
+ <method>review_save_after</method>
99
+ </salesmanago_tracking_observer>
100
+ </observers>
101
+ </review_save_after>
102
  </events>
103
 
104
  <helpers>
109
 
110
  <blocks>
111
  <tracking>
112
+ <class>SalesManago_Tracking_Block</class>
113
  </tracking>
114
  </blocks>
115
 
164
  </routers>
165
  </frontend>
166
  <adminhtml>
167
+ <acl>
168
+ <resources>
169
+ <all>
 
 
 
 
 
 
 
 
 
170
  <title>Allow Everything</title>
171
+ </all>
172
  <admin>
173
  <children>
174
  <system>
app/code/community/SalesManago/Tracking/etc/system.xml CHANGED
@@ -8,7 +8,7 @@
8
  </tabs>
9
  <sections>
10
  <salesmanago_tracking translate="label" module="tracking">
11
- <label>Connector settings</label>
12
  <tab>salesmanago</tab>
13
  <frontend_type>text</frontend_type>
14
  <sort_order>10</sort_order>
@@ -17,7 +17,7 @@
17
  <show_in_store>1</show_in_store>
18
  <groups>
19
  <general translate="label" module="tracking">
20
- <label>Connector settings</label>
21
  <sort_order>800</sort_order>
22
  <show_in_default>1</show_in_default>
23
  <show_in_website>1</show_in_website>
@@ -33,7 +33,7 @@
33
  <show_in_store>1</show_in_store>
34
  </client_id>
35
  <api_secret translate="label">
36
- <label>API secret code</label>
37
  <frontend_type>text</frontend_type>
38
  <sort_order>20</sort_order>
39
  <show_in_default>1</show_in_default>
@@ -41,7 +41,7 @@
41
  <show_in_store>1</show_in_store>
42
  </api_secret>
43
  <email translate="label">
44
- <label>Main owner E-mail</label>
45
  <frontend_type>text</frontend_type>
46
  <sort_order>30</sort_order>
47
  <show_in_default>1</show_in_default>
@@ -49,44 +49,26 @@
49
  <show_in_store>1</show_in_store>
50
  </email>
51
  <endpoint translate="label">
52
- <label>End point address</label>
53
  <frontend_type>text</frontend_type>
54
  <sort_order>40</sort_order>
55
  <show_in_default>1</show_in_default>
56
  <show_in_website>1</show_in_website>
57
  <show_in_store>1</show_in_store>
58
  </endpoint>
59
- <tagsNewsletter translate="label">
60
- <label>Newsletter subscription tags</label>
61
  <frontend_type>text</frontend_type>
62
  <sort_order>50</sort_order>
63
  <show_in_default>1</show_in_default>
64
  <show_in_website>1</show_in_website>
65
  <show_in_store>1</show_in_store>
66
- <comment>If you want to use more tags, separate them with a comma</comment>
67
- </tagsNewsletter>
68
- <tagsRegistration translate="label">
69
- <label>Sign up tag</label>
70
- <frontend_type>text</frontend_type>
71
- <sort_order>51</sort_order>
72
- <show_in_default>1</show_in_default>
73
- <show_in_website>1</show_in_website>
74
- <show_in_store>1</show_in_store>
75
- <comment>If you want to use more tags, separate them with a comma</comment>
76
- </tagsRegistration>
77
- <tagsPurchase translate="label">
78
- <label>Purchase tag</label>
79
- <frontend_type>text</frontend_type>
80
- <sort_order>60</sort_order>
81
- <show_in_default>1</show_in_default>
82
- <show_in_website>1</show_in_website>
83
- <show_in_store>1</show_in_store>
84
- <comment>If you want to use more tags, separate them with a comma</comment>
85
- </tagsPurchase>
86
  <additional_js translate="label">
87
- <label>Custom JS code</label>
88
  <frontend_type>text</frontend_type>
89
- <sort_order>80</sort_order>
90
  <show_in_default>1</show_in_default>
91
  <show_in_website>1</show_in_website>
92
  <show_in_store>1</show_in_store>
@@ -94,11 +76,11 @@
94
  <connection_timeout translate="label">
95
  <label>Connection Timeout</label>
96
  <frontend_type>text</frontend_type>
97
- <sort_order>90</sort_order>
98
  <show_in_default>1</show_in_default>
99
  <show_in_website>1</show_in_website>
100
  <show_in_store>1</show_in_store>
101
- <comment>Limit the maximum execution time in ms (optional)</comment>
102
  </connection_timeout>
103
  <active translate="label">
104
  <label>Enabled</label>
8
  </tabs>
9
  <sections>
10
  <salesmanago_tracking translate="label" module="tracking">
11
+ <label>General</label>
12
  <tab>salesmanago</tab>
13
  <frontend_type>text</frontend_type>
14
  <sort_order>10</sort_order>
17
  <show_in_store>1</show_in_store>
18
  <groups>
19
  <general translate="label" module="tracking">
20
+ <label>General</label>
21
  <sort_order>800</sort_order>
22
  <show_in_default>1</show_in_default>
23
  <show_in_website>1</show_in_website>
33
  <show_in_store>1</show_in_store>
34
  </client_id>
35
  <api_secret translate="label">
36
+ <label>Api secret</label>
37
  <frontend_type>text</frontend_type>
38
  <sort_order>20</sort_order>
39
  <show_in_default>1</show_in_default>
41
  <show_in_store>1</show_in_store>
42
  </api_secret>
43
  <email translate="label">
44
+ <label>E-mail</label>
45
  <frontend_type>text</frontend_type>
46
  <sort_order>30</sort_order>
47
  <show_in_default>1</show_in_default>
49
  <show_in_store>1</show_in_store>
50
  </email>
51
  <endpoint translate="label">
52
+ <label>End point</label>
53
  <frontend_type>text</frontend_type>
54
  <sort_order>40</sort_order>
55
  <show_in_default>1</show_in_default>
56
  <show_in_website>1</show_in_website>
57
  <show_in_store>1</show_in_store>
58
  </endpoint>
59
+ <tags translate="label">
60
+ <label>Tags</label>
61
  <frontend_type>text</frontend_type>
62
  <sort_order>50</sort_order>
63
  <show_in_default>1</show_in_default>
64
  <show_in_website>1</show_in_website>
65
  <show_in_store>1</show_in_store>
66
+ <comment>Next tags paste followed by coma</comment>
67
+ </tags>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  <additional_js translate="label">
69
+ <label>Additional JS extract</label>
70
  <frontend_type>text</frontend_type>
71
+ <sort_order>60</sort_order>
72
  <show_in_default>1</show_in_default>
73
  <show_in_website>1</show_in_website>
74
  <show_in_store>1</show_in_store>
76
  <connection_timeout translate="label">
77
  <label>Connection Timeout</label>
78
  <frontend_type>text</frontend_type>
79
+ <sort_order>70</sort_order>
80
  <show_in_default>1</show_in_default>
81
  <show_in_website>1</show_in_website>
82
  <show_in_store>1</show_in_store>
83
+ <comment>The maximum waiting period for script performance in miliseconds (optional)</comment>
84
  </connection_timeout>
85
  <active translate="label">
86
  <label>Enabled</label>
app/design/frontend/base/default/template/salesmanago/tracking/tracking.phtml CHANGED
@@ -4,25 +4,26 @@
4
  $client_salesmanago_id = $this->getClientSalesManagoId();
5
  $additional_js = $this->getAdditionalJs();
6
  $active = $this -> isActive();
7
-
8
- if($active == 1 && !empty($client_id) && !empty($endpoint)){
9
- $trackingScript = "<script type='text/javascript'>\n";
10
- $trackingScript .= "\tvar _smid = '".$client_id."';\n";
11
- if(isset($additional_js) && !empty($additional_js)){
12
- $trackingScript .= "\t".$additional_js."\n";
13
- }
14
- if($client_salesmanago_id){
15
- $trackingScript .= "\tvar _smclientid = '".$client_salesmanago_id."';\n";
16
- }
17
- $trackingScript .= "\t(function(w, r, a, sm, s ) {\n";
18
- $trackingScript .= "\t\tw['SalesmanagoObject'] = r;\n";
19
- $trackingScript .= "\t\tw[r] = w[r] || function () {( w[r].q = w[r].q || [] ).push(arguments)};\n";
20
- $trackingScript .= "\t\tsm = document.createElement('script'); sm.type = 'text/javascript'; sm.async = true; sm.src = a;\n";
21
- $trackingScript .= "\t\ts = document.getElementsByTagName('script')[0];\n";
22
- $trackingScript .= "\t\ts.parentNode.insertBefore(sm, s);\n";
23
- $trackingScript .= "\t\t})(window, 'sm', ('https:' == document.location.protocol ? 'https://' : 'http://') + '".$endpoint."/static/sm.js');\n";
24
- $trackingScript .= "</script>\n";
25
-
26
- echo $trackingScript;
27
- }
 
28
  ?>
4
  $client_salesmanago_id = $this->getClientSalesManagoId();
5
  $additional_js = $this->getAdditionalJs();
6
  $active = $this -> isActive();
7
+
8
+ if($active == 1 && !empty($client_id) && !empty($endpoint)){
9
+ $trackingScript = "<script type='text/javascript'>\n";
10
+ $trackingScript .= "\tvar _smid = '".$client_id."';\n";
11
+ if(isset($additional_js) && !empty($additional_js)){
12
+ $trackingScript .= "\t".$additional_js."\n";
13
+ }
14
+ if($client_salesmanago_id){
15
+ $trackingScript .= "\tvar _smclientid = '".$client_salesmanago_id."';\n";
16
+ }
17
+ $trackingScript .= "\t(function () {\n";
18
+ $trackingScript .= "\t\tvar sm = document.createElement('script');\n";
19
+ $trackingScript .= "\t\tsm.type = 'text/javascript';\n";
20
+ $trackingScript .= "\t\tsm.async = true;\n";
21
+ $trackingScript .= "\t\tsm.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + '".$endpoint."/static/sm.js';\n";
22
+ $trackingScript .= "\t\tvar s = document.getElementsByTagName('script')[0];\n";
23
+ $trackingScript .= "\t\ts.parentNode.insertBefore(sm, s);\n";
24
+ $trackingScript .= "\t})();\n";
25
+ $trackingScript .= "</script>\n";
26
+
27
+ echo $trackingScript;
28
+ }
29
  ?>
app/design/frontend/default/default/template/salesmanago/tracking/tracking.phtml CHANGED
@@ -14,15 +14,16 @@
14
  if($client_salesmanago_id){
15
  $trackingScript .= "\tvar _smclientid = '".$client_salesmanago_id."';\n";
16
  }
17
- $trackingScript .= "\t(function(w, r, a, sm, s ) {\n";
18
- $trackingScript .= "\t\tw['SalesmanagoObject'] = r;\n";
19
- $trackingScript .= "\t\tw[r] = w[r] || function () {( w[r].q = w[r].q || [] ).push(arguments)};\n";
20
- $trackingScript .= "\t\tsm = document.createElement('script'); sm.type = 'text/javascript'; sm.async = true; sm.src = a;\n";
21
- $trackingScript .= "\t\ts = document.getElementsByTagName('script')[0];\n";
 
22
  $trackingScript .= "\t\ts.parentNode.insertBefore(sm, s);\n";
23
- $trackingScript .= "\t\t})(window, 'sm', ('https:' == document.location.protocol ? 'https://' : 'http://') + '".$endpoint."/static/sm.js');\n";
24
  $trackingScript .= "</script>\n";
25
 
26
  echo $trackingScript;
27
  }
28
- ?>
14
  if($client_salesmanago_id){
15
  $trackingScript .= "\tvar _smclientid = '".$client_salesmanago_id."';\n";
16
  }
17
+ $trackingScript .= "\t(function () {\n";
18
+ $trackingScript .= "\t\tvar sm = document.createElement('script');\n";
19
+ $trackingScript .= "\t\tsm.type = 'text/javascript';\n";
20
+ $trackingScript .= "\t\tsm.async = true;\n";
21
+ $trackingScript .= "\t\tsm.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + '".$endpoint."/static/sm.js';\n";
22
+ $trackingScript .= "\t\tvar s = document.getElementsByTagName('script')[0];\n";
23
  $trackingScript .= "\t\ts.parentNode.insertBefore(sm, s);\n";
24
+ $trackingScript .= "\t})();\n";
25
  $trackingScript .= "</script>\n";
26
 
27
  echo $trackingScript;
28
  }
29
+ ?>
app/locale/de_DE/Salesmanago_Tracking.csv DELETED
@@ -1,15 +0,0 @@
1
- "Connector settings","Verbindungseinstellungen"
2
- "SalesManago_Tracking::Enabled","Freigeschaltet"
3
- "Yes","Ja"
4
- "No","Nein"
5
- "Client ID","Kundennummer"
6
- "API secret code","API Geheimnis"
7
- "Main owner E-mail","Main owner E-mail"
8
- "End point address","Endpunkt adresse"
9
- "Newsletter subscription tags","Newsletter abonnement tag"
10
- "Sign up tag","Anmelde tag"
11
- "Purchase tag","Kauf tag"
12
- "Custom JS code","Angepaster JS code"
13
- "Connection Timeout","Verbindungsfehler"
14
- "If you want to use more tags, separate them with a comma","Wenn Sie mehr Label (tag) nutzen möchten, trennen Sie diese durch Kommas"
15
- "Limit the maximum execution time in ms (optional)","Limieteren Sie die maximale Ausfürungszeit ms (fakultativ)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/locale/es_ES/Salesmanago_Tracking.csv DELETED
@@ -1,15 +0,0 @@
1
- "Connector settings","Ajustes o configuración del conector"
2
- "SalesManago_Tracking::Enabled","Habilitado"
3
- "Yes","Sí"
4
- "No","No"
5
- "Client ID","ID del Cliente"
6
- "API secret code","API secret code"
7
- "Main owner E-mail","Main owner E-mail"
8
- "End point address","End point address"
9
- "Newsletter subscription tags","Etiqueta de suscripción a newsletter"
10
- "Sign up tag","Etiqueta de suscripción"
11
- "Purchase tag","Etiqueta de compra"
12
- "Custom JS code","Código JS personalizado"
13
- "Connection Timeout","El tiempo de conexión expiro"
14
- "If you want to use more tags, separate them with a comma","Si necesitas usar mas etiquetas, Separarlas con comas"
15
- "Limit the maximum execution time in ms (optional)","Limitar el tiempo máximo de ejecución en ms (opcional)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/locale/pl_PL/Salesmanago_Tracking.csv DELETED
@@ -1,15 +0,0 @@
1
- "Connector settings","Ustawienia Wtyczki"
2
- "SalesManago_Tracking::Enabled","Włączona"
3
- "Yes","Tak"
4
- "No","Nie"
5
- "Client ID","ID klienta"
6
- "API secret code","Kod Api secret"
7
- "Main owner E-mail","E-mail właściciela"
8
- "End point address","Endpoint"
9
- "Newsletter subscription tags","Tagi newsletter"
10
- "Sign up tag","Tagi rejestracji"
11
- "Purchase tag","Tagi zakupu"
12
- "Custom JS code","Dodatkowy fragment JS"
13
- "Connection Timeout","Czas wykonywania skryptu"
14
- "If you want to use more tags, separate them with a comma","Kolejne tagi wpisuj po przecinku"
15
- "Limit the maximum execution time in ms (optional)","Maksymalny czas oczekiwania na wykonanie skryptu w milisekundach (opcjonalnie)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/locale/ru_RU/Salesmanago_Tracking.csv DELETED
@@ -1,15 +0,0 @@
1
- "Connector settings","Настройка связки"
2
- "SalesManago_Tracking::Enabled","Включен"
3
- "Yes","да"
4
- "No","Нет"
5
- "Client ID","ИН клиента"
6
- "API secret code","API secret code"
7
- "Main owner E-mail","Емейл"
8
- "End point address","End point address"
9
- "Newsletter subscription tags","Тег подписки на рассылку"
10
- "Sign up tag","Тег регестрации"
11
- "Purchase tag","Тег покупки"
12
- "Custom JS code","Пользовательский JS-код"
13
- "Connection Timeout","Время ожидания подключения"
14
- "If you want to use more tags, separate them with a comma","Если Вы хотите использовать несколько тегов, разделяйте их запятой"
15
- "Limit the maximum execution time in ms (optional)","Лимит максимального времени выполнения в ms (дополнительно) "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>SALESmanago</name>
4
- <version>1.5.1</version>
5
  <stability>stable</stability>
6
  <license>ASL</license>
7
  <channel>community</channel>
@@ -9,103 +9,10 @@
9
  <summary>SALESmanago Marketing Automation integration.</summary>
10
  <description>SALESmanago Marketing Automation integration.</description>
11
  <notes>SALESmanago Marketing Automation integration.</notes>
12
- <authors><author><name>Benhauer Sp. z o.o. Sp. K.</name><user>SalesManago</user><email>info@salesmanago.pl</email></author></authors>
13
- <date>2014-02-06</date>
14
- <time>01:51:06</time>
15
- <contents>
16
- <target name="magecommunity">
17
- <dir name="SalesManago">
18
- <dir name="Tracking">
19
- <dir name="Block">
20
- <file name="Layer.php" hash="5564c2dfb2cd62ea3d2f9cba11722718"/>
21
- </dir>
22
- <dir name="Helper">
23
- <file name="Data.php" hash="11f51fb7782d47b1d0245ac43fb5962c"/>
24
- </dir>
25
- <dir name="Model">
26
- <file name="Customersync.php" hash="c2535f600d93d711fc67324bf786b576"/>
27
- <file name="Observer.php" hash="9a75d0f9550f24d4ddcb795b31276d27"/>
28
- <dir name="Resource">
29
- <dir name="Customersync">
30
- <file name="Collection.php" hash="660921ec631893a685e0cacd4b9d07ef"/>
31
- </dir>
32
- <file name="Customersync.php" hash="3f6789e8568fb496e65d23cd6b8c3794"/>
33
- <file name="Setup.php" hash="f196f0e7972b723dfaeecaea7ea0a0ee"/>
34
- </dir>
35
- </dir>
36
- <dir name="controllers">
37
- <file name="CustomerController.php" hash="c0154d7e55d551e1e0c1e8bed796e32e"/>
38
- <dir name="Newsletter">
39
- <file name="SubscriberController.php" hash="e683bda792cd39c11c40ad77d3b1a18e"/>
40
- </dir>
41
- </dir>
42
- <dir name="etc">
43
- <file name="config.xml" hash="d12c4b7723ad2ff49ffca0b2ccdb3460"/>
44
- <file name="system.xml" hash="b0db5f4d20cd98eef017b1da798e59cd"/>
45
- </dir><dir name="sql">
46
- <dir name="tracking_setup">
47
- <file name="mysql4-install-0.0.4.php" hash="efbe2ef2e234e72f8cfb61b02cd79fd8"/>
48
- </dir>
49
- </dir>
50
- </dir>
51
- </dir>
52
- </target>
53
- <target name="mageetc">
54
- <dir name="modules">
55
- <file name="SalesManago_Tracking.xml" hash="14e6da8fc1550fd46dc56ceea822d648"/>
56
- </dir>
57
- </target>
58
- <target name="magedesign">
59
- <dir name="frontend">
60
- <dir name="default">
61
- <dir name="default">
62
- <dir name="layout">
63
- <file name="salesmanago.xml" hash="c8d48e529e20472913b844723b0513a6"/>
64
- </dir>
65
- <dir name="template">
66
- <dir name="salesmanago">
67
- <dir name="tracking">
68
- <file name="tracking.phtml" hash="f39205215f98504187fbfd9e90d477fb"/>
69
- </dir>
70
- </dir>
71
- </dir>
72
- </dir>
73
- </dir>
74
- </dir>
75
- </target>
76
- <target name="magedesign">
77
- <dir name="frontend">
78
- <dir name="base">
79
- <dir name="default">
80
- <dir name="layout">
81
- <file name="salesmanago.xml" hash="c8d48e529e20472913b844723b0513a6"/>
82
- </dir>
83
- <dir name="template">
84
- <dir name="salesmanago">
85
- <dir name="tracking">
86
- <file name="tracking.phtml" hash="f39205215f98504187fbfd9e90d477fb"/>
87
- </dir>
88
- </dir>
89
- </dir>
90
- </dir>
91
- </dir>
92
- </dir>
93
- </target>
94
- <target name="magelocale">
95
- <dir name="de_DE">
96
- <file name="Salesmanago_Tracking.csv"/>
97
- </dir>
98
- <dir name="es_ES">
99
- <file name="Salesmanago_Tracking.csv"/>
100
- </dir>
101
- <dir name="pl_PL">
102
- <file name="Salesmanago_Tracking.csv"/>
103
- </dir>
104
- <dir name="ru_RU">
105
- <file name="Salesmanago_Tracking.csv"/>
106
- </dir>
107
- </target>
108
- </contents>
109
  <compatible/>
110
- <dependencies><required><php><min>5.2.0</min><max>7.2.0</max></php></required></dependencies>
111
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>SALESmanago</name>
4
+ <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license>ASL</license>
7
  <channel>community</channel>
9
  <summary>SALESmanago Marketing Automation integration.</summary>
10
  <description>SALESmanago Marketing Automation integration.</description>
11
  <notes>SALESmanago Marketing Automation integration.</notes>
12
+ <authors><author><name>Benhauer Sp. z o.o. Sp. K.</name><user>SalesManago</user><email>info@salesmanago.pl</email></author><author><name>Carlos Alonso</name><user>delinaje</user><email>carlos@alonsodelinaje.com</email></author></authors>
13
+ <date>2015-12-03</date>
14
+ <time>14:59:25</time>
15
+ <contents><target name="magecommunity"><dir name="SalesManago"><dir name="Tracking"><dir name="Block"><file name="Layer.php" hash="112b431cd5af7e4bec6722b898a3afe3"/></dir><dir name="Helper"><file name="Data.php" hash="488749d250e612845a24edb545c813f7"/></dir><dir name="Model"><file name="Customersync.php" hash="c2535f600d93d711fc67324bf786b576"/><file name="Observer.php" hash="5b3a0353cff1450e52774282f712fdf9"/><dir name="Resource"><dir name="Customersync"><file name="Collection.php" hash="660921ec631893a685e0cacd4b9d07ef"/></dir><file name="Customersync.php" hash="3f6789e8568fb496e65d23cd6b8c3794"/><file name="Setup.php" hash="f196f0e7972b723dfaeecaea7ea0a0ee"/></dir></dir><dir name="controllers"><file name="CustomerController.php" hash="8f45dfe0ab7e33ce6801f58ca8576c52"/><dir name="Newsletter"><file name="SubscriberController.php" hash="790674d2e1a9aab3d0f795688d107cd5"/></dir></dir><dir name="etc"><file name="config.xml" hash="2c5d1fd9d6a8047f2edc8a32296af923"/><file name="system.xml" hash="b4344b259212dd8f83e7ee8163db63f3"/></dir><dir name="sql"><dir name="tracking_setup"><file name="mysql4-install-0.0.4.php" hash="efbe2ef2e234e72f8cfb61b02cd79fd8"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="salesmanago.xml" hash="c8d48e529e20472913b844723b0513a6"/></dir><dir name="template"><dir name="salesmanago"><dir name="tracking"><file name="tracking.phtml" hash="7341fb419c9c86e6d0ec1eba6265d979"/></dir></dir></dir></dir></dir><dir name="default"><dir name="default"><dir name="template"><dir name="salesmanago"><dir name="tracking"><file name="tracking.phtml" hash="7341fb419c9c86e6d0ec1eba6265d979"/></dir></dir></dir><dir name="layout"><file name="salesmanago.xml" hash="c8d48e529e20472913b844723b0513a6"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SalesManago_Tracking.xml" hash="14e6da8fc1550fd46dc56ceea822d648"/></dir></target></contents>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>