Advalo_Tagging - Version 1.1.0

Version Notes

Magento version requirements

Magento 1.7+
PHP 5.3+

Fixed

Fixed: Load sequence for load/ready events.

Download this release

Release Info

Developer Advalo
Extension Advalo_Tagging
Version 1.1.0
Comparing to
See all releases


Version 1.1.0

app/code/community/Advalo/Tagging/.DS_Store ADDED
Binary file
app/code/community/Advalo/Tagging/Block/At.php ADDED
@@ -0,0 +1,6 @@
1
+ <?php
2
+ class Advalo_Tagging_Block_At extends Mage_Core_Block_Template {
3
+
4
+ }
5
+
6
+ ?>
app/code/community/Advalo/Tagging/Helper/Data.php ADDED
@@ -0,0 +1,11 @@
1
+ <?php
2
+
3
+ class Advalo_Tagging_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ public function getNewsletterSubscribed() {
6
+ return Mage::getStoreConfig('advalo_tagging/advalo_events/newsletter_subscribed');
7
+ }
8
+
9
+ }
10
+
11
+ ?>
app/code/community/Advalo/Tagging/Model/.DS_Store ADDED
Binary file
app/code/community/Advalo/Tagging/Model/Page/Observer.php ADDED
@@ -0,0 +1,502 @@
1
+ <?php
2
+
3
+ class Advalo_Tagging_Model_Page_Observer {
4
+
5
+ // This is the AT specification Version
6
+ protected $_version = "1.0.0";
7
+ protected $_user = null;
8
+ protected $_page = null;
9
+ protected $_basket = null;
10
+ protected $_transaction = null;
11
+
12
+ protected function _getRequest() {
13
+ return Mage::app()->getFrontController()->getRequest();
14
+ }
15
+
16
+ /*
17
+ * Returns Controller Name
18
+ */
19
+ protected function _getControllerName() {
20
+ return $this->_getRequest()->getControllerName();
21
+ }
22
+
23
+ protected function _getActionName() {
24
+ return $this->_getRequest()->getActionName();
25
+ }
26
+
27
+ protected function _getModuleName() {
28
+ return $this->_getRequest()->getModuleName();
29
+ }
30
+
31
+ protected function _getRouteName() {
32
+ return $this->_getRequest()->getRouteName();
33
+ }
34
+
35
+ protected function _getCustomer() {
36
+ return Mage::helper('customer')->getCustomer();
37
+ }
38
+
39
+ protected function _getBreadcrumb() {
40
+ return Mage::helper('catalog')->getBreadcrumbPath();
41
+ }
42
+
43
+ protected function _getCategory($category_id) {
44
+ return Mage::getModel('catalog/category')->load($category_id);
45
+ }
46
+
47
+ protected function _getCurrentProduct() {
48
+ return Mage::registry('current_product');
49
+ }
50
+
51
+ protected function _getProduct($productId) {
52
+ return Mage::getModel('catalog/product')->load($productId);
53
+ }
54
+
55
+ protected function _getCurrentCategory() {
56
+ return Mage::registry('current_category');
57
+ }
58
+
59
+ protected function _getCatalogSearch() {
60
+ return Mage::getSingleton('catalogsearch/advanced');
61
+ }
62
+
63
+ protected function _getCheckoutSession() {
64
+ return Mage::getSingleton('checkout/session');
65
+ }
66
+
67
+ protected function _getSalesOrder() {
68
+ return Mage::getModel('sales/order');
69
+ }
70
+
71
+ protected function _getOrderAddress() {
72
+ return Mage::getModel('sales/order_address');
73
+ }
74
+
75
+ /*
76
+ * Determine which page type we're on
77
+ */
78
+
79
+ public function _isHome() {
80
+ if (Mage::app()->getRequest()->getRequestString() == "/") {
81
+ return true;
82
+ } else {
83
+ return false;
84
+ }
85
+ }
86
+
87
+ public function _isContent() {
88
+ if ($this->_getModuleName() == 'cms') {
89
+ return true;
90
+ } else {
91
+ return false;
92
+ }
93
+ }
94
+
95
+ public function _isCategory() {
96
+ if ($this->_getControllerName() == 'category') {
97
+ return true;
98
+ } else {
99
+ return false;
100
+ }
101
+ }
102
+
103
+ public function _isSearch() {
104
+ if ($this->_getModuleName() == 'catalogsearch') {
105
+ return true;
106
+ } else {
107
+ return false;
108
+ }
109
+ }
110
+
111
+ public function _isProduct() {
112
+ $onCatalog = false;
113
+ if(Mage::registry('current_product')) {
114
+ $onCatalog = true;
115
+ }
116
+ return $onCatalog;
117
+ }
118
+
119
+ public function _isBasket() {
120
+ $request = $this->_getRequest();
121
+ $module = $request->getModuleName();
122
+ $controller = $request->getControllerName();
123
+ $action = $request->getActionName();
124
+ if ($module == 'checkout' && $controller == 'cart' && $action == 'index'){
125
+ return true;
126
+ } else {
127
+ return false;
128
+ }
129
+ }
130
+
131
+ public function _isCheckout() {
132
+ if (strpos($this->_getModuleName(), 'checkout') !== false && $this->_getActionName() != 'success') {
133
+ return true;
134
+ } else {
135
+ return false;
136
+ }
137
+ }
138
+
139
+ public function _isConfirmation() {
140
+ if (strpos($this->_getModuleName(), 'checkout') !== false && ($this->_getActionName() == 'success' || $this->_getActionName() == 'checkout_onepage_success' || $this->_getActionName() == 'checkout_multishipping_success')) {
141
+ return true;
142
+ } else {
143
+ return false;
144
+ }
145
+ }
146
+
147
+ /*
148
+ * Get information on pages to pass to front end
149
+ */
150
+
151
+ public function getVersion() {
152
+ return $this->_version;
153
+ }
154
+
155
+ public function getUser() {
156
+ return $this->_user;
157
+ }
158
+
159
+ public function getPage() {
160
+ return $this->_page;
161
+ }
162
+
163
+ public function getBasket() {
164
+ return $this->_basket;
165
+ }
166
+
167
+ public function getTransaction() {
168
+ return $this->_transaction;
169
+ }
170
+
171
+ /*
172
+ * Set the model attributes to be passed front end
173
+ */
174
+
175
+ public function _getPageType() {
176
+ if ($this->_isHome()) {
177
+ return 'home';
178
+ } elseif ($this->_isContent()) {
179
+ return 'content';
180
+ } elseif ($this->_isCategory()) {
181
+ return 'category';
182
+ } elseif ($this->_isSearch()) {
183
+ return 'search';
184
+ } elseif ($this->_isProduct()) {
185
+ return 'product';
186
+ } elseif ($this->_isBasket()) {
187
+ return 'basket';
188
+ } elseif ($this->_isCheckout()) {
189
+ return 'checkout';
190
+ } elseif ($this->_isConfirmation()) {
191
+ return 'confirmation';
192
+ } else {
193
+ return $this->_getModuleName();
194
+ }
195
+ }
196
+
197
+ public function _getPageName() {
198
+ if ($this->_isHome()) {
199
+ return 'home';
200
+ } elseif ($this->_isContent()) {
201
+ return Mage::getSingleton('cms/page')->getTitle();
202
+ } elseif ($this->_isCategory()) {
203
+ $arr = $this->_getBreadcrumb();
204
+ foreach ($arr as $category) {
205
+ $name = $name . '/' . $category['label'];
206
+ }
207
+ return $name;
208
+ } elseif ($this->_isSearch()) {
209
+ return 'search';
210
+ } elseif ($this->_isProduct()) {
211
+ return Mage::registry('current_product')->getName();
212
+ } elseif ($this->_isBasket()) {
213
+ return 'basket';
214
+ } elseif ($this->_isCheckout()) {
215
+ return 'checkout';
216
+ } elseif ($this->_isConfirmation()) {
217
+ return 'confirmation';
218
+ } else {
219
+ return $this->_getModuleName();
220
+ }
221
+ }
222
+
223
+ public function _getPageProduct() {
224
+ $product = $this->_getCurrentProduct();
225
+ if (!$product) return false;
226
+ return $this->_getProductModel($product);
227
+ }
228
+
229
+ public function _getPageListing() {
230
+ $this->_listing = array();
231
+ if ($this->_isCategory()) {
232
+ $category = $this->_getCurrentCategory();
233
+ } elseif ($this->_isSearch()) {
234
+ $category = $this->_getCatalogSearch();
235
+ if (isset($_GET['q'])) {
236
+ $this->_listing['query'] = $_GET['q'];
237
+ }
238
+ }
239
+ }
240
+
241
+ public function _getPageSearch() {
242
+ $search = array();
243
+ $search['query'] = 'empty';
244
+ if (isset($_GET['q'])) {
245
+ $search['query'] = $_GET['q'];
246
+ }
247
+ return $search;
248
+ }
249
+
250
+ public function _setPage() {
251
+ $this->_page = array();
252
+ $this->_page['type'] = $this->_getPageType();
253
+ $this->_page['category'] = $this->_getPageType();
254
+ $this->_page['name'] = $this->_getPageName();
255
+
256
+ if ($this->_isProduct()) {
257
+ $this->_page['product'] = $this->_getPageProduct();
258
+ }
259
+ /*
260
+ if ($this->_isCategory()) {
261
+ $this->_page['listing'] = $this->_getPageListing();
262
+ }
263
+ */
264
+ if ($this->_isSearch()) {
265
+ $this->_page['search'] = $this->_getPageSearch();
266
+ }
267
+
268
+ }
269
+
270
+ // Set the user info
271
+ public function _setUser() {
272
+ $this->_user = array();
273
+ $user = $this->_getCustomer();
274
+ $user_id = $user->getEntityId();
275
+ $newsletter_email = Mage::getSingleton('core/session')->getData('subscriber_email');
276
+
277
+ if ($this->_isConfirmation()) {
278
+ $orderId = $this->_getCheckoutSession()->getLastOrderId();
279
+ if ($orderId) {
280
+ $order = $this->_getSalesOrder()->load($orderId);
281
+ $email = $order->getCustomerEmail();
282
+ }
283
+ } else {
284
+ $email = $user->getEmail();
285
+ }
286
+
287
+ if ($newsletter_email) {
288
+ $this->_user['email'] = $newsletter_email;
289
+ } elseif ($email) {
290
+ $this->_user['email'] = $email;
291
+ }
292
+
293
+ if ($user_id) {
294
+ $this->_user['user_id'] = (string) $user_id;
295
+ }
296
+ }
297
+
298
+ public function _getAddress($address) {
299
+ $billing = array();
300
+ if ($address) {
301
+ $billing['name'] = $address->getName();
302
+ $billing['address3'] = $address->getStreetFull();
303
+ $billing['city'] = $address->getCity();
304
+ $billing['zip'] = $address->getPostcode();
305
+ $billing['country'] = $address->getCountry();
306
+ $state = $address->getRegion();
307
+ $billing['state'] = $state ? $state : '';
308
+ }
309
+ return $billing;
310
+ }
311
+
312
+ public function _getProductStock($product) {
313
+ return (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
314
+ }
315
+
316
+ public function _getCurrency() {
317
+ return Mage::app()->getStore()->getCurrentCurrencyCode();
318
+ }
319
+
320
+ public function _getProductModel($product) {
321
+ $product_model = array();
322
+ $product_model['product_id'] = $product->getId();
323
+ $product_model['sku'] = $product->getSku();
324
+ $product_model['name'] = $product->getName();
325
+ $product_model['unit_price'] = (float) $product->getPrice();
326
+ $product_model['unit_sale_price'] = (float) $product->getFinalPrice();
327
+ $product_model['currency'] = $this->_getCurrency();
328
+ $product_model['stock'] = (int) $this->_getProductStock($product);
329
+
330
+ $categories = $this->_getProductCategories($product);
331
+ if (isset($categories[0])) {
332
+ $product_model['category'] = $categories[0];
333
+ }
334
+ if (isset($categories[1])) {
335
+ $product_model['subcategory'] = $categories[1];
336
+ }
337
+ if (isset($categories[2])) {
338
+ $product_model['subsubcategory'] = $categories[2];
339
+ }
340
+
341
+ return $product_model;
342
+ }
343
+
344
+ public function _getProductCategories($product) {
345
+ $cats = $product->getCategoryIds();
346
+ if ($cats) {
347
+ $category_names = array();
348
+ foreach ($cats as $category_id) {
349
+ $_cat = $this->_getCategory($category_id);
350
+ $category_names[] = $_cat->getName();
351
+ }
352
+ return $category_names;
353
+ } else {
354
+ return false;
355
+ }
356
+ }
357
+
358
+ public function _getLineItems($items, $page_type) {
359
+ $line_items = array();
360
+ foreach($items as $item) {
361
+ $productId = $item->getProductId();
362
+ $product = $this->_getProduct($productId);
363
+ // product needs to be visible
364
+ if ($product->isVisibleInSiteVisibility()) {
365
+ $litem_model = array();
366
+ $litem_model['product'] = $this->_getProductModel($product);
367
+ $litem_model['subtotal'] = (float) $item->getRowTotalInclTax();
368
+ $litem_model['total_discount'] = (float) $item->getDiscountAmount();
369
+
370
+ if ($page_type == 'basket') {
371
+ $litem_model['quantity'] = (float) $item->getQty();
372
+ } else {
373
+ $litem_model['quantity'] = (float) $item->getQtyOrdered();
374
+ }
375
+
376
+ $unit_sale_price_after_discount = $litem_model['product']['unit_sale_price'];
377
+ $unit_sale_price_after_discount = $unit_sale_price_after_discount - ($litem_model['total_discount'] / $litem_model['quantity']);
378
+ $litem_model['product']['unit_sale_price'] = $unit_sale_price_after_discount;
379
+
380
+ array_push($line_items, $litem_model);
381
+ }
382
+ }
383
+ return $line_items;
384
+ }
385
+
386
+ public function _setBasket() {
387
+ $cart = $this->_getCheckoutSession();
388
+
389
+ if (!isset($cart)) {
390
+ return;
391
+ }
392
+
393
+ $basket = array();
394
+ $quote = $cart->getQuote();
395
+
396
+ // Set normal params
397
+ $basket_id = $this->_getCheckoutSession()->getQuoteId();
398
+ if ($basket_id) {
399
+ $basket['id'] = (string) $basket_id;
400
+ }
401
+ $basket['currency'] = $this->_getCurrency();
402
+ $basket['subtotal'] = (float) $quote->getSubtotal();
403
+ $basket['tax'] = (float) $quote->getShippingAddress()->getTaxAmount();
404
+ $basket['subtotal_include_tax'] = (boolean) $this->_doesSubtotalIncludeTax($quote, $basket['tax']);
405
+ $basket['shipping_cost'] = (float) $quote->getShippingAmount();
406
+ $basket['shipping_method'] = $this->_extractShippingMethod($quote);
407
+ $basket['total'] = (float) $quote->getGrandTotal();
408
+
409
+ // Line items
410
+ $items = $quote->getAllItems();
411
+ $basket['items'] = $this->_getLineItems($items, 'basket');
412
+
413
+ $this->_basket = $basket;
414
+ }
415
+
416
+ public function _doesSubtotalIncludeTax($order, $tax) {
417
+ /* Conditions:
418
+ - if tax is zero, then set to false
419
+ - Assume that if grand total is bigger than total after subtracting shipping, then subtotal does NOT include tax
420
+ */
421
+ $grandTotalWithoutShipping = $order->getGrandTotal() - $order->getShippingAmount();
422
+ if ($tax == 0 || $grandTotalWithoutShipping > $order->getSubtotal()) {
423
+ return false;
424
+ } else {
425
+ return true;
426
+ }
427
+ }
428
+
429
+ public function _extractShippingMethod($order) {
430
+ $shipping_method = $order->getShippingMethod();
431
+ return $shipping_method ? $shipping_method : '';
432
+ }
433
+
434
+ public function _setTransaction() {
435
+ $orderId = $this->_getCheckoutSession()->getLastOrderId();
436
+ if ($orderId) {
437
+ $transaction = array();
438
+ $order = $this->_getSalesOrder()->load($orderId);
439
+
440
+ // Get general details
441
+ $transaction['order_id'] = $order->getIncrementId();
442
+ $transaction['currency'] = $this->_getCurrency();
443
+ $transaction['subtotal'] = (float) $order->getSubtotal();
444
+ $transaction['tax'] = (float) $order->getTaxAmount();
445
+ $transaction['subtotal_include_tax'] = $this->_doesSubtotalIncludeTax($order, $transaction['tax']);
446
+ $transaction['payment_type'] = $order->getPayment()->getMethodInstance()->getTitle();
447
+ $transaction['total'] = (float) $order->getGrandTotal();
448
+
449
+ $voucher = $order->getCouponCode();
450
+ $transaction['voucher'] = $voucher ? $voucher : "";
451
+ $voucher_discount = -1 * $order->getDiscountAmount();
452
+ $transaction['voucher_discount'] = $voucher_discount ? $voucher_discount : 0;
453
+
454
+ $transaction['shipping_cost'] = (float) $order->getShippingAmount();
455
+ $transaction['shipping_method'] = $this->_extractShippingMethod($order);
456
+
457
+ // Get addresses
458
+ if (method_exists($order,'getShippingAddress')) {
459
+ $shippingId = $order->getShippingAddress()->getId();
460
+ $shippingAddress = $order->getShippingAddress();
461
+ $transaction['delivery'] = $this->_getAddress($shippingAddress);
462
+ $address = $this->_getOrderAddress()->load($shippingId);
463
+ }
464
+
465
+ $billingAddress = $order->getBillingAddress();
466
+ $transaction['billing'] = $this->_getAddress($billingAddress);
467
+
468
+ // Get items
469
+ $line_items = $order->getAllItems();
470
+ $items = $this->_getLineItems($line_items, 'transaction');
471
+ $transaction['items'] = $items;
472
+
473
+ $this->_transaction = $transaction;
474
+ }
475
+ }
476
+
477
+ public function setAdvaloTagging($observer) {
478
+ $this->_setUser();
479
+ $this->_setPage();
480
+ /*
481
+ if($observer->getEvent()->getControllerAction()->getFullActionName() && ($observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_onepage_success' || $observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_multishipping_success')) {
482
+ $this->_setTransaction();
483
+ } else
484
+ */
485
+ if ($this->_isConfirmation()) {
486
+ $this->_setTransaction();
487
+ } else {
488
+ $this->_setBasket();
489
+ }
490
+
491
+ return $this;
492
+ }
493
+
494
+ public function getSubscriberEmail($observer) {
495
+ $event = $observer->getEvent();
496
+ $model = $event->getSubscriber();
497
+ $subscriber_email = $model->getData(subscriber_email);
498
+ Mage::getSingleton('core/session')->setData('subscriber_email', $subscriber_email);
499
+ }
500
+
501
+ }
502
+ ?>
app/code/community/Advalo/Tagging/Model/Page/to ADDED
@@ -0,0 +1,503 @@
1
+ <?php
2
+
3
+ class Advalo_Tagging_Model_Page_Observer {
4
+
5
+ // This is the AT specification Version
6
+ protected $_version = "1.0.0";
7
+ protected $_user = null;
8
+ protected $_page = null;
9
+ protected $_basket = null;
10
+ protected $_transaction = null;
11
+
12
+ protected function _getRequest() {
13
+ return Mage::app()->getFrontController()->getRequest();
14
+ }
15
+
16
+ /*
17
+ * Returns Controller Name
18
+ */
19
+ protected function _getControllerName() {
20
+ return $this->_getRequest()->getControllerName();
21
+ }
22
+
23
+ protected function _getActionName() {
24
+ return $this->_getRequest()->getActionName();
25
+ }
26
+
27
+ protected function _getModuleName() {
28
+ return $this->_getRequest()->getModuleName();
29
+ }
30
+
31
+ protected function _getRouteName() {
32
+ return $this->_getRequest()->getRouteName();
33
+ }
34
+
35
+ protected function _getCustomer() {
36
+ return Mage::helper('customer')->getCustomer();
37
+ }
38
+
39
+ protected function _getBreadcrumb($module) {
40
+ return Mage::helper('catalog')->getBreadcrumbPath();
41
+ }
42
+
43
+ protected function _getCategory($category_id) {
44
+ return Mage::getModel('catalog/category')->load($category_id);
45
+ }
46
+
47
+ protected function _getCurrentProduct() {
48
+ return Mage::registry('current_product');
49
+ }
50
+
51
+ protected function _getProduct($productId) {
52
+ return Mage::getModel('catalog/product')->load($productId);
53
+ }
54
+
55
+ protected function _getCurrentCategory() {
56
+ return Mage::registry('current_category');
57
+ }
58
+
59
+ protected function _getCatalogSearch() {
60
+ return Mage::getSingleton('catalogsearch/advanced');
61
+ }
62
+
63
+ protected function _getCheckoutSession() {
64
+ return Mage::getSingleton('checkout/session');
65
+ }
66
+
67
+ protected function _getSalesOrder() {
68
+ return Mage::getModel('sales/order');
69
+ }
70
+
71
+ protected function _getOrderAddress() {
72
+ return Mage::getModel('sales/order_address');
73
+ }
74
+
75
+ /*
76
+ * Determine which page type we're on
77
+ */
78
+
79
+ public function _isHome() {
80
+ if (Mage::app()->getRequest()->getRequestString() == "/") {
81
+ return true;
82
+ } else {
83
+ return false;
84
+ }
85
+ }
86
+
87
+ public function _isContent() {
88
+ if ($this->_getModuleName() == 'cms') {
89
+ return true;
90
+ } else {
91
+ return false;
92
+ }
93
+ }
94
+
95
+ public function _isCategory() {
96
+ if ($this->_getControllerName() == 'category') {
97
+ return true;
98
+ } else {
99
+ return false;
100
+ }
101
+ }
102
+
103
+ public function _isSearch() {
104
+ if ($this->_getModuleName() == 'catalogsearch') {
105
+ return true;
106
+ } else {
107
+ return false;
108
+ }
109
+ }
110
+
111
+ public function _isProduct() {
112
+ $onCatalog = false;
113
+ if(Mage::registry('current_product')) {
114
+ $onCatalog = true;
115
+ }
116
+ return $onCatalog;
117
+ }
118
+
119
+ public function _isBasket() {
120
+ $request = $this->_getRequest();
121
+ $module = $request->getModuleName();
122
+ $controller = $request->getControllerName();
123
+ $action = $request->getActionName();
124
+ if ($module == 'checkout' && $controller == 'cart' && $action == 'index'){
125
+ return true;
126
+ } else {
127
+ return false;
128
+ }
129
+ }
130
+
131
+ public function _isCheckout() {
132
+ if (strpos($this->_getModuleName(), 'checkout') !== false && $this->_getActionName() != 'success') {
133
+ return true;
134
+ } else {
135
+ return false;
136
+ }
137
+ }
138
+
139
+ public function _isConfirmation() {
140
+ // default controllerName is "onepage"
141
+ // relax the check, only check if contains checkout
142
+ // somecheckout systems has different prefix/postfix,
143
+ // but all contains checkout
144
+ if (strpos($this->_getModuleName(), 'checkout') !== false && $this->_getActionName() == "success") {
145
+ return true;
146
+ } else {
147
+ return false;
148
+ }
149
+ }
150
+
151
+
152
+ /*
153
+ * Get information on pages to pass to front end
154
+ */
155
+
156
+ public function getVersion() {
157
+ return $this->_version;
158
+ }
159
+
160
+ public function getUser() {
161
+ return $this->_user;
162
+ }
163
+
164
+ public function getPage() {
165
+ return $this->_page;
166
+ }
167
+
168
+ public function getBasket() {
169
+ return $this->_basket;
170
+ }
171
+
172
+ public function getTransaction() {
173
+ return $this->_transaction;
174
+ }
175
+
176
+ /*
177
+ * Set the model attributes to be passed front end
178
+ */
179
+
180
+ public function _getPageType() {
181
+ if ($this->_isHome()) {
182
+ return 'home';
183
+ } elseif ($this->_isContent()) {
184
+ return 'content';
185
+ } elseif ($this->_isCategory()) {
186
+ return 'category';
187
+ } elseif ($this->_isSearch()) {
188
+ return 'search';
189
+ } elseif ($this->_isProduct()) {
190
+ return 'product';
191
+ } elseif ($this->_isBasket()) {
192
+ return 'basket';
193
+ } elseif ($this->_isCheckout()) {
194
+ return 'checkout';
195
+ } elseif ($this->_isConfirmation()) {
196
+ return 'confirmation';
197
+ } else {
198
+ return $this->_getModuleName();
199
+ }
200
+ }
201
+
202
+ public function _getPageName() {
203
+ if ($this->_isHome()) {
204
+ return 'home';
205
+ } elseif ($this->_isContent()) {
206
+ return Mage::getSingleton('cms/page')->getTitle();
207
+ } elseif ($this->_isCategory()) {
208
+ $arr = $this->_getBreadcrumb();
209
+ foreach ($arr as $category) {
210
+ $name = $name . '/' . $category['label'];
211
+ }
212
+ return $name;
213
+ } elseif ($this->_isSearch()) {
214
+ return 'search';
215
+ } elseif ($this->_isProduct()) {
216
+ return 'product';
217
+ } elseif ($this->_isBasket()) {
218
+ return 'basket';
219
+ } elseif ($this->_isCheckout()) {
220
+ return 'checkout';
221
+ } elseif ($this->_isConfirmation()) {
222
+ return 'confirmation';
223
+ } else {
224
+ return $this->_getModuleName();
225
+ }
226
+ }
227
+
228
+ public function _getPageProduct() {
229
+ $product = $this->_getCurrentProduct();
230
+ if (!$product) return false;
231
+ return $this->_getProductModel($product);
232
+ }
233
+
234
+ public function _getPageListing() {
235
+ $this->_listing = array();
236
+ if ($this->_isCategory()) {
237
+ $category = $this->_getCurrentCategory();
238
+ } elseif ($this->_isSearch()) {
239
+ $category = $this->_getCatalogSearch();
240
+ if (isset($_GET['q'])) {
241
+ $this->_listing['query'] = $_GET['q'];
242
+ }
243
+ }
244
+ }
245
+
246
+ public function _getPageSearch() {
247
+ $search = array();
248
+ $search['query'] = 'empty';
249
+ if (isset($_GET['q'])) {
250
+ $search['query'] = $_GET['q'];
251
+ }
252
+ return $search;
253
+ }
254
+
255
+ public function _setPage() {
256
+ $this->_page = array();
257
+ $this->_page['type'] = $this->_getPageType();
258
+
259
+ $this->_page['name'] = $this->_getPageName();
260
+
261
+ if ($this->_isProduct()) {
262
+ $this->_page['product'] = $this->_getPageProduct();
263
+ }
264
+ /*
265
+ if ($this->_isCategory()) {
266
+ $this->_page['listing'] = $this->_getPageListing();
267
+ }
268
+ */
269
+ if ($this->_isSearch()) {
270
+ $this->_page['search'] = $this->_getPageSearch();
271
+ }
272
+
273
+ }
274
+
275
+ // Set the user info
276
+ public function _setUser() {
277
+ $this->_user = array();
278
+ $user = $this->_getCustomer();
279
+ $user_id = $user->getEntityId();
280
+
281
+ if ($this->_isConfirmation()) {
282
+ $orderId = $this->_getCheckoutSession()->getLastOrderId();
283
+ if ($orderId) {
284
+ $order = $this->_getSalesOrder()->load($orderId);
285
+ $email = $order->getCustomerEmail();
286
+ }
287
+ } else {
288
+ $email = $user->getEmail();
289
+ }
290
+
291
+ if ($email) {
292
+ $this->_user['email'] = $email;
293
+ }
294
+
295
+ if ($user_id) {
296
+ $this->_user['user_id'] = (string) $user_id;
297
+ }
298
+ $this->_user['language'] = Mage::getStoreConfig('general/locale/code', Mage::app()->getStore()->getId());;
299
+
300
+ }
301
+
302
+ public function _getAddress($address) {
303
+ $billing = array();
304
+ if ($address) {
305
+ $billing['name'] = $address->getName();
306
+ $billing['address'] = $address->getStreetFull();
307
+ $billing['city'] = $address->getCity();
308
+ $billing['postcode'] = $address->getPostcode();
309
+ $billing['country'] = $address->getCountry();
310
+ $state = $address->getRegion();
311
+ $billing['state'] = $state ? $state : '';
312
+ }
313
+ return $billing;
314
+ }
315
+
316
+ public function _getProductStock($product) {
317
+ return (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
318
+ }
319
+
320
+ public function _getCurrency() {
321
+ return Mage::app()->getStore()->getCurrentCurrencyCode();
322
+ }
323
+
324
+ public function _getProductModel($product) {
325
+ $product_model = array();
326
+ $product_model['product_id'] = $product->getId();
327
+ $product_model['sku'] = $product->getSku();
328
+ $product_model['url'] = $product->getProductUrl();
329
+ $product_model['name'] = $product->getName();
330
+ $product_model['unit_price'] = (float) $product->getPrice();
331
+ $product_model['unit_sale_price'] = (float) $product->getFinalPrice();
332
+ $product_model['currency'] = $this->_getCurrency();
333
+ $product_model['stock'] = (int) $this->_getProductStock($product);
334
+
335
+ $categories = $this->_getProductCategories($product);
336
+ if (isset($categories[0])) {
337
+ $product_model['category'] = $categories[0];
338
+ }
339
+ if (isset($categories[1])) {
340
+ $product_model['subcategory'] = $categories[1];
341
+ }
342
+ if (isset($categories[2])) {
343
+ $product_model['subsubcategory'] = $categories[2];
344
+ }
345
+
346
+ return $product_model;
347
+ }
348
+
349
+ public function _getProductCategories($product) {
350
+ $cats = $product->getCategoryIds();
351
+ if ($cats) {
352
+ $category_names = array();
353
+ foreach ($cats as $category_id) {
354
+ $_cat = $this->_getCategory($category_id);
355
+ $category_names[] = $_cat->getName();
356
+ }
357
+ return $category_names;
358
+ } else {
359
+ return false;
360
+ }
361
+ }
362
+
363
+ public function _getLineItems($items, $page_type) {
364
+ $line_items = array();
365
+ foreach($items as $item) {
366
+ $productId = $item->getProductId();
367
+ $product = $this->_getProduct($productId);
368
+ // product needs to be visible
369
+ if ($product->isVisibleInSiteVisibility()) {
370
+ $litem_model = array();
371
+ $litem_model['product'] = $this->_getProductModel($product);
372
+
373
+
374
+ $litem_model['subtotal'] = (float) $item->getRowTotalInclTax();
375
+ $litem_model['total_discount'] = (float) $item->getDiscountAmount();
376
+
377
+ if ($page_type == 'basket') {
378
+ $litem_model['quantity'] = (float) $item->getQty();
379
+ } else {
380
+ $litem_model['quantity'] = (float) $item->getQtyOrdered();
381
+ }
382
+
383
+ // Recalculate unit_sale_price after voucher applied Github: #35
384
+ // https://github.com/QubitProducts/UniversalVariable-Magento-Extension/issues/35
385
+ $unit_sale_price_after_discount = $litem_model['product']['unit_sale_price'];
386
+ $unit_sale_price_after_discount =
387
+ $unit_sale_price_after_discount - ($litem_model['total_discount'] / $litem_model['quantity']);
388
+ $litem_model['product']['unit_sale_price'] = $unit_sale_price_after_discount;
389
+
390
+ array_push($line_items, $litem_model);
391
+ }
392
+ }
393
+ return $line_items;
394
+ }
395
+
396
+ public function _setBasket() {
397
+ $cart = $this->_getCheckoutSession();
398
+
399
+ if (!isset($cart)) {
400
+ return;
401
+ }
402
+
403
+ $basket = array();
404
+ $quote = $cart->getQuote();
405
+
406
+ // Set normal params
407
+ $basket_id = $this->_getCheckoutSession()->getQuoteId();
408
+ if ($basket_id) {
409
+ $basket['id'] = (string) $basket_id;
410
+ }
411
+ $basket['currency'] = $this->_getCurrency();
412
+ $basket['subtotal'] = (float) $quote->getSubtotal();
413
+ $basket['tax'] = (float) $quote->getShippingAddress()->getTaxAmount();
414
+ $basket['subtotal_include_tax'] = (boolean) $this->_doesSubtotalIncludeTax($quote, $basket['tax']);
415
+ $basket['shipping_cost'] = (float) $quote->getShippingAmount();
416
+ $basket['shipping_method'] = $this->_extractShippingMethod($quote);
417
+ $basket['total'] = (float) $quote->getGrandTotal();
418
+
419
+ // Line items
420
+ $items = $quote->getAllItems();
421
+ $basket['line_items'] = $this->_getLineItems($items, 'basket');
422
+
423
+ $this->_basket = $basket;
424
+ }
425
+
426
+ public function _doesSubtotalIncludeTax($order, $tax) {
427
+ /* Conditions:
428
+ - if tax is zero, then set to false
429
+ - Assume that if grand total is bigger than total after subtracting shipping, then subtotal does NOT include tax
430
+ */
431
+ $grandTotalWithoutShipping = $order->getGrandTotal() - $order->getShippingAmount();
432
+ if ($tax == 0 || $grandTotalWithoutShipping > $order->getSubtotal()) {
433
+ return false;
434
+ } else {
435
+ return true;
436
+ }
437
+ }
438
+
439
+ public function _extractShippingMethod($order) {
440
+ $shipping_method = $order->getShippingMethod();
441
+ return $shipping_method ? $shipping_method : '';
442
+ }
443
+
444
+ public function _setTransaction() {
445
+ $orderId = $this->_getCheckoutSession()->getLastOrderId();
446
+ if ($orderId) {
447
+ $transaction = array();
448
+ $order = $this->_getSalesOrder()->load($orderId);
449
+
450
+ // Get general details
451
+ $transaction['order_id'] = $order->getIncrementId();
452
+ $transaction['currency'] = $this->_getCurrency();
453
+ $transaction['subtotal'] = (float) $order->getSubtotal();
454
+ $transaction['tax'] = (float) $order->getTaxAmount();
455
+ $transaction['subtotal_include_tax'] = $this->_doesSubtotalIncludeTax($order, $transaction['tax']);
456
+ $transaction['payment_type'] = $order->getPayment()->getMethodInstance()->getTitle();
457
+ $transaction['total'] = (float) $order->getGrandTotal();
458
+
459
+ $voucher = $order->getCouponCode();
460
+ $transaction['voucher'] = $voucher ? $voucher : "";
461
+ $voucher_discount = -1 * $order->getDiscountAmount();
462
+ $transaction['voucher_discount'] = $voucher_discount ? $voucher_discount : 0;
463
+
464
+ $transaction['shipping_cost'] = (float) $order->getShippingAmount();
465
+ $transaction['shipping_method'] = $this->_extractShippingMethod($order);
466
+
467
+ // Get addresses
468
+ if (method_exists($order,'getShippingAddress')) {
469
+ $shippingId = $order->getShippingAddress()->getId();
470
+ $shippingAddress = $order->getShippingAddress();
471
+ $transaction['delivery'] = $this->_getAddress($shippingAddress);
472
+ $address = $this->_getOrderAddress()->load($shippingId);
473
+ }
474
+
475
+ $billingAddress = $order->getBillingAddress();
476
+ $transaction['billing'] = $this->_getAddress($billingAddress);
477
+
478
+ // Get items
479
+ $items = $order->getAllItems();
480
+ $line_items = $this->_getLineItems($items, 'transaction');
481
+ $transaction['line_items'] = $line_items;
482
+
483
+ $this->_transaction = $transaction;
484
+ }
485
+ }
486
+
487
+ public function setAdvaloTagging($observer) {
488
+ $this->_setUser();
489
+ $this->_setPage();
490
+
491
+ if (!$this->_isConfirmation()) {
492
+ $this->_setBasket();
493
+ }
494
+
495
+ if ($this->_isConfirmation()) {
496
+ $this->_setTransaction();
497
+ }
498
+ echo json_encode($this->_page);
499
+ return $this;
500
+ }
501
+
502
+ }
503
+ ?>
app/code/community/Advalo/Tagging/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <advalo_tagging translate="title" module="advalo_tagging_main">
12
+ <sort_order>0</sort_order>
13
+ <title>Manage Advalo Script</title>
14
+ </advalo_tagging>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/community/Advalo/Tagging/etc/config.xml ADDED
@@ -0,0 +1,91 @@
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Advalo_Tagging>
5
+ <version>1.0.0</version>
6
+ </Advalo_Tagging>
7
+ </modules>
8
+
9
+ <adminhtml>
10
+ <acl>
11
+ <resources>
12
+ <admin>
13
+ <children>
14
+ <system>
15
+ <children>
16
+ <config>
17
+ <children>
18
+ <advalo_tagging_options>
19
+ <title>AT Module Section</title>
20
+ </advalo_tagging_options>
21
+ </children>
22
+ </config>
23
+ </children>
24
+ </system>
25
+ </children>
26
+ </admin>
27
+ </resources>
28
+ </acl>
29
+ </adminhtml>
30
+
31
+ <global>
32
+ <models>
33
+ <advalo_tagging_main>
34
+ <class>Advalo_Tagging_Model</class>
35
+ </advalo_tagging_main>
36
+ </models>
37
+ <helpers>
38
+ <advalo_tagging_main>
39
+ <class>Advalo_Tagging_Helper</class>
40
+ </advalo_tagging_main>
41
+ </helpers>
42
+ <blocks>
43
+ <advalo_tagging_main>
44
+ <class>Advalo_Tagging_Block</class>
45
+ </advalo_tagging_main>
46
+ </blocks>
47
+ </global>
48
+
49
+ <frontend>
50
+ <!-- Layout -->
51
+ <layout>
52
+ <updates>
53
+ <advalo_tagging>
54
+ <file>advalo/advalo_tagging.xml</file>
55
+ </advalo_tagging>
56
+ </updates>
57
+ </layout>
58
+ <!-- Event -->
59
+ <events>
60
+ <controller_action_layout_load_before>
61
+ <observers>
62
+ <Advalo_Tagging_Model_Page_Observer>
63
+ <type>singleton</type>
64
+ <class>advalo_tagging_main/page_observer</class>
65
+ <method>setAdvaloTagging</method>
66
+ </Advalo_Tagging_Model_Page_Observer>
67
+ </observers>
68
+ </controller_action_layout_load_before>
69
+ <newsletter_subscriber_save_after>
70
+ <observers>
71
+ <Advalo_Tagging_Model_Page_Observer>
72
+ <type>singleton</type>
73
+ <class>advalo_tagging_main/page_observer</class>
74
+ <method>getSubscriberEmail</method>
75
+ </Advalo_Tagging_Model_Page_Observer>
76
+ </observers>
77
+ </newsletter_subscriber_save_after>
78
+ </events>
79
+
80
+ </frontend>
81
+
82
+ <!-- Admin Configuration Default Values -->
83
+ <default>
84
+ <advalo>
85
+ <advalo_tagging_enabled>1</advalo_tagging_enabled>
86
+ </advalo>
87
+ <advalo_events>
88
+ <newsletter_subscribed>newsletter_subscribed</newsletter_subscribed>
89
+ </advalo_events>
90
+ </default>
91
+ </config>
app/code/community/Advalo/Tagging/etc/system.xml ADDED
@@ -0,0 +1,51 @@
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <Advalo_tab translate="label">
5
+ <label>Advalo Tagging</label>
6
+ <sort_order>100</sort_order>
7
+ </Advalo_tab>
8
+ </tabs>
9
+
10
+ <sections>
11
+ <advalo_tagging translate="label">
12
+ <label>Configuration</label>
13
+ <tab>Advalo_tab</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>2</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <Advalo_Tagging_Settings translate="label">
21
+ <label>Advalo Tagging Configuration</label>
22
+ <sort_order>2</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <Advalo_Tagging_Site translate="label">
28
+ <label>Site ID</label>
29
+ <frontend_type>text</frontend_type>
30
+ <config_path>advalo/advalo_site_id</config_path>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </Advalo_Tagging_Site>
36
+ <Advalo_Tagging_Enabled translate="label">
37
+ <label>Enable Tagging</label>
38
+ <frontend_type>select</frontend_type>
39
+ <source_model>adminhtml/system_config_source_yesno</source_model>
40
+ <config_path>advalo/advalo_tagging_enabled</config_path>
41
+ <sort_order>3</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ </Advalo_Tagging_Enabled>
46
+ </fields>
47
+ </Advalo_Tagging_Settings>
48
+ </groups>
49
+ </advalo_tagging>
50
+ </sections>
51
+ </config>
app/design/frontend/base/default/template/advalo/advalo_tagging.phtml ADDED
@@ -0,0 +1,50 @@
1
+ <?php
2
+ $advalo_site_id = Mage::getStoreConfig ( 'advalo/advalo_site_id' );
3
+ $advalo_tagging_enabled = Mage::getStoreConfig ( 'advalo/advalo_tagging_enabled' );
4
+
5
+ $observer = 'advalo_tagging_main/page_observer';
6
+ $mage = Mage::getSingleton ( $observer );
7
+ ?>
8
+
9
+ <?php if ($advalo_tagging_enabled == 1) :?>
10
+ <?php
11
+ // extract variable only when advalo variable is enabled
12
+ $version = $mage->getVersion ();
13
+ $page = $mage->getPage ();
14
+ $user = $mage->getUser ();
15
+ $basket = $mage->getBasket ();
16
+ $transaction = $mage->getTransaction ();
17
+ ?>
18
+
19
+ <script type="text/javascript">
20
+
21
+ <!-- Advalo Variable Start -->
22
+ window.advalo = window.advalo || {};
23
+ window.advalo.version = <?php echo json_encode($version); ?>;
24
+ window.advalo.page = <?php echo json_encode($page); ?>;
25
+ window.advalo.user = <?php echo json_encode($user); ?>;
26
+ <?php if ($basket && $basket['total'] != 0) : ?>
27
+ window.advalo.basket = <?php echo json_encode($basket) ?>;
28
+ <?php endif; ?>
29
+ <?php if ($transaction) : ?>
30
+ window.advalo.transaction = <?php echo json_encode($transaction) ?>;
31
+ <?php endif; ?>
32
+ <!-- Advalo Variable End -->
33
+
34
+ <!-- Advalo Script Start -->
35
+ var _paq = _paq || [];
36
+ (function() {
37
+ var u=('https:' == document.location.protocol ? 'https://' : 'http://') + 'analytics.advalo.com/';
38
+ _paq.push(['setSiteId', '<?php echo $advalo_site_id;?>']);
39
+ _paq.push(['trackPageView', window.advalo]);
40
+ var d=document, g=d.createElement('script');
41
+ g.type='text/javascript';
42
+ g.defer=true;
43
+ g.async=true;
44
+ g.src=u+'advalo.js?site_id=<?php echo $advalo_site_id;?>';
45
+ s=d.getElementsByTagName('script')[0]; s.parentNode.insertBefore(g,s);
46
+ })();
47
+ <!-- Advalo Script End -->
48
+
49
+ </script>
50
+ <?php endif;?>
app/etc/modules/Advalo_all.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version = "1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Advalo_Tagging>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Advalo_Tagging>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Advalo_Tagging</name>
4
+ <version>1.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/lgpl-license.php">LGPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Advalo Pulse for Magento is a plugin to allow easy syncing of data in and out of Advalo Pulse, a SaaS DMP.</summary>
10
+ <description>Advalo Pulse is a SaaS Data Management Platform which allows companies to harness the power of their customer/visitor data in real-time.&#xD;
11
+ </description>
12
+ <notes>Magento version requirements&#xD;
13
+ &#xD;
14
+ Magento 1.7+&#xD;
15
+ PHP 5.3+&#xD;
16
+ &#xD;
17
+ Fixed&#xD;
18
+ &#xD;
19
+ Fixed: Load sequence for load/ready events.&#xD;
20
+ </notes>
21
+ <authors><author><name>Advalo</name><user>advalo</user><email>webmaster@advalo.com</email></author></authors>
22
+ <date>2015-01-06</date>
23
+ <time>16:06:26</time>
24
+ <contents><target name="magecommunity"><dir name="Advalo"><dir name="Tagging"><dir name="Block"><file name="At.php" hash="2f9b28d67ec004b994a6e2bdfbb96fac"/></dir><dir name="Helper"><file name="Data.php" hash="f9e920f75bee7717851911e36481c583"/></dir><dir name="Model"><dir name="Page"><file name="Observer.php" hash="c4f6ac28a5e54f3f63eeea687ba6268b"/><file name="to" hash="9f12d3d7fc55977747a25f6815f92b0a"/></dir><file name=".DS_Store" hash="a52ca6afadcc6a627c69e60fe88dbc81"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4d9aefd59323006f41a00db2f6f126e9"/><file name="config.xml" hash="c9ac624acd5b326f1db760b323f872c2"/><file name="system.xml" hash="55e53293abbc729e5e772b05c512044c"/></dir><file name=".DS_Store" hash="9a07bbeda4fce5709889c78fc0e21dd4"/></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="advalo"><file name="advalo_tagging.phtml" hash="31c89a7c495fd62623165c40b0c92ae8"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Advalo_all.xml" hash="d1dccbed9a24cd832a09d1ee33efff01"/></dir></target></contents>
25
+ <compatible/>
26
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
27
+ </package>