Targetbay_Tracking - Version 5.1.1

Version Notes

Making every interaction count and engaging customers with relevant messages will improve the chances of conversion exponentially. You can profile and segment users based on various parameters and actions, the data from which will form the basis for your customer engagement objectives.You can create triggers based on customer engagement objectives to deliver personalized messages. Your newsletter campaigns can also be personalized to deliver better customer engagement results. And all of this can be achieved with the help of our ecommerce-based email personalization platform.

Download this release

Release Info

Developer Targetbay
Extension Targetbay_Tracking
Version 5.1.1
Comparing to
See all releases


Version 5.1.1

Files changed (88) hide show
  1. app/code/community/Targetbay/Tracking/Block/Product/Product.php +51 -0
  2. app/code/community/Targetbay/Tracking/Block/Product/Review.php +19 -0
  3. app/code/community/Targetbay/Tracking/Block/Session/Tracking.php +19 -0
  4. app/code/community/Targetbay/Tracking/Block/Tracking.php +22 -0
  5. app/code/community/Targetbay/Tracking/Helper/Data.php +1433 -0
  6. app/code/community/Targetbay/Tracking/Model/Api2/Cartitem.php +9 -0
  7. app/code/community/Targetbay/Tracking/Model/Api2/Cartitem/Rest/Admin/V1.php +59 -0
  8. app/code/community/Targetbay/Tracking/Model/Api2/Cartitem/Rest/Guest/V1.php +60 -0
  9. app/code/community/Targetbay/Tracking/Model/Api2/Category.php +9 -0
  10. app/code/community/Targetbay/Tracking/Model/Api2/Category/Rest/Admin/V1.php +36 -0
  11. app/code/community/Targetbay/Tracking/Model/Api2/Category/Rest/Guest/V1.php +36 -0
  12. app/code/community/Targetbay/Tracking/Model/Api2/Createsubscription.php +9 -0
  13. app/code/community/Targetbay/Tracking/Model/Api2/Createsubscription/Rest/Admin/V1.php +99 -0
  14. app/code/community/Targetbay/Tracking/Model/Api2/Createsubscription/Rest/Guest/V1.php +99 -0
  15. app/code/community/Targetbay/Tracking/Model/Api2/Customer.php +9 -0
  16. app/code/community/Targetbay/Tracking/Model/Api2/Customer/Rest/Admin/V1.php +31 -0
  17. app/code/community/Targetbay/Tracking/Model/Api2/Customer/Rest/Guest/V1.php +31 -0
  18. app/code/community/Targetbay/Tracking/Model/Api2/Orders/Rest/Admin/V1.php +40 -0
  19. app/code/community/Targetbay/Tracking/Model/Api2/Orders/Rest/Guest/V1.php +40 -0
  20. app/code/community/Targetbay/Tracking/Model/Api2/Product/Rest/Admin/V1.php +103 -0
  21. app/code/community/Targetbay/Tracking/Model/Api2/Product/Rest/Admin/V1.php~ +102 -0
  22. app/code/community/Targetbay/Tracking/Model/Api2/Product/Rest/Guest/V1.php +170 -0
  23. app/code/community/Targetbay/Tracking/Model/Api2/Review.php +9 -0
  24. app/code/community/Targetbay/Tracking/Model/Api2/Review/Rest/Admin/V1.php +73 -0
  25. app/code/community/Targetbay/Tracking/Model/Api2/Review/Rest/Guest/V1.php +73 -0
  26. app/code/community/Targetbay/Tracking/Model/Api2/Shipment.php +9 -0
  27. app/code/community/Targetbay/Tracking/Model/Api2/Shipment/Rest/Admin/V1.php +33 -0
  28. app/code/community/Targetbay/Tracking/Model/Api2/Shipment/Rest/Guest/V1.php +33 -0
  29. app/code/community/Targetbay/Tracking/Model/Api2/Stores.php +9 -0
  30. app/code/community/Targetbay/Tracking/Model/Api2/Stores/Rest/Admin/V1.php +30 -0
  31. app/code/community/Targetbay/Tracking/Model/Api2/Stores/Rest/Guest/V1.php +30 -0
  32. app/code/community/Targetbay/Tracking/Model/Api2/Subscriber.php +9 -0
  33. app/code/community/Targetbay/Tracking/Model/Api2/Subscriber/Rest/Admin/V1.php +34 -0
  34. app/code/community/Targetbay/Tracking/Model/Api2/Subscriber/Rest/Guest/V1.php +34 -0
  35. app/code/community/Targetbay/Tracking/Model/Api2/Totalcartiteminfo.php +9 -0
  36. app/code/community/Targetbay/Tracking/Model/Api2/Totalcartiteminfo/Rest/Admin/V1.php +33 -0
  37. app/code/community/Targetbay/Tracking/Model/Api2/Totalcartiteminfo/Rest/Guest/V1.php +33 -0
  38. app/code/community/Targetbay/Tracking/Model/Api2/Totalcategoryinfo.php +9 -0
  39. app/code/community/Targetbay/Tracking/Model/Api2/Totalcategoryinfo/Rest/Admin/V1.php +21 -0
  40. app/code/community/Targetbay/Tracking/Model/Api2/Totalcategoryinfo/Rest/Guest/V1.php +21 -0
  41. app/code/community/Targetbay/Tracking/Model/Api2/Totalcustomerinfo.php +9 -0
  42. app/code/community/Targetbay/Tracking/Model/Api2/Totalcustomerinfo/Rest/Admin/V1.php +21 -0
  43. app/code/community/Targetbay/Tracking/Model/Api2/Totalcustomerinfo/Rest/Guest/V1.php +21 -0
  44. app/code/community/Targetbay/Tracking/Model/Api2/Totalinfo.php +9 -0
  45. app/code/community/Targetbay/Tracking/Model/Api2/Totalinfo/Rest/Admin/V1.php +23 -0
  46. app/code/community/Targetbay/Tracking/Model/Api2/Totalinfo/Rest/Guest/V1.php +23 -0
  47. app/code/community/Targetbay/Tracking/Model/Api2/Totalorderinfo.php +9 -0
  48. app/code/community/Targetbay/Tracking/Model/Api2/Totalorderinfo/Rest/Admin/V1.php +21 -0
  49. app/code/community/Targetbay/Tracking/Model/Api2/Totalorderinfo/Rest/Guest/V1.php +21 -0
  50. app/code/community/Targetbay/Tracking/Model/Api2/Totalproductinfo.php +9 -0
  51. app/code/community/Targetbay/Tracking/Model/Api2/Totalproductinfo/Rest/Admin/V1.php +35 -0
  52. app/code/community/Targetbay/Tracking/Model/Api2/Totalproductinfo/Rest/Guest/V1.php +35 -0
  53. app/code/community/Targetbay/Tracking/Model/Api2/Totalreviewinfo.php +9 -0
  54. app/code/community/Targetbay/Tracking/Model/Api2/Totalreviewinfo/Rest/Admin/V1.php +21 -0
  55. app/code/community/Targetbay/Tracking/Model/Api2/Totalreviewinfo/Rest/Guest/V1.php +21 -0
  56. app/code/community/Targetbay/Tracking/Model/Api2/Totalshipmentinfo.php +9 -0
  57. app/code/community/Targetbay/Tracking/Model/Api2/Totalshipmentinfo/Rest/Admin/V1.php +24 -0
  58. app/code/community/Targetbay/Tracking/Model/Api2/Totalshipmentinfo/Rest/Guest/V1.php +24 -0
  59. app/code/community/Targetbay/Tracking/Model/Api2/Totalsubscriberinfo.php +9 -0
  60. app/code/community/Targetbay/Tracking/Model/Api2/Totalsubscriberinfo/Rest/Admin/V1.php +21 -0
  61. app/code/community/Targetbay/Tracking/Model/Api2/Totalsubscriberinfo/Rest/Guest/V1.php +21 -0
  62. app/code/community/Targetbay/Tracking/Model/Api2/Totalwishlistinfo.php +9 -0
  63. app/code/community/Targetbay/Tracking/Model/Api2/Totalwishlistinfo/Rest/Admin/V1.php +34 -0
  64. app/code/community/Targetbay/Tracking/Model/Api2/Totalwishlistinfo/Rest/Guest/V1.php +34 -0
  65. app/code/community/Targetbay/Tracking/Model/Api2/Updatesubscription.php +9 -0
  66. app/code/community/Targetbay/Tracking/Model/Api2/Updatesubscription/Rest/Admin/V1.php +78 -0
  67. app/code/community/Targetbay/Tracking/Model/Api2/Updatesubscription/Rest/Guest/V1.php +85 -0
  68. app/code/community/Targetbay/Tracking/Model/Api2/Wishlist.php +9 -0
  69. app/code/community/Targetbay/Tracking/Model/Api2/Wishlist/Rest/Admin/V1.php +30 -0
  70. app/code/community/Targetbay/Tracking/Model/Api2/Wishlist/Rest/Guest/V1.php +30 -0
  71. app/code/community/Targetbay/Tracking/Model/Customer.php +50 -0
  72. app/code/community/Targetbay/Tracking/Model/Observer.php +976 -0
  73. app/code/community/Targetbay/Tracking/Model/Subscriber.php +97 -0
  74. app/code/community/Targetbay/Tracking/Model/System/Config/Source/Page.php +99 -0
  75. app/code/community/Targetbay/Tracking/Model/System/Config/Source/Status.php +35 -0
  76. app/code/community/Targetbay/Tracking/Model/System/Config/Source/Tracking.php +31 -0
  77. app/code/community/Targetbay/Tracking/Model/System/Config/Source/Version.php +27 -0
  78. app/code/community/Targetbay/Tracking/Model/System/Config/Source/Yesno.php +21 -0
  79. app/code/community/Targetbay/Tracking/controllers/IndexController.php +47 -0
  80. app/code/community/Targetbay/Tracking/etc/api2.xml +615 -0
  81. app/code/community/Targetbay/Tracking/etc/config.xml +493 -0
  82. app/code/community/Targetbay/Tracking/etc/system.xml +161 -0
  83. app/design/frontend/base/default/layout/tracking.xml +26 -0
  84. app/design/frontend/base/default/template/tracking/product/review.phtml +44 -0
  85. app/design/frontend/base/default/template/tracking/session/tracking.phtml +4 -0
  86. app/design/frontend/base/default/template/tracking/tracking.phtml +120 -0
  87. app/etc/modules/Targetbay_Tracking.xml +17 -0
  88. package.xml +18 -0
app/code/community/Targetbay/Tracking/Block/Product/Product.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ if(class_exists("TM_RichSnippets_Block_Product", true)) {
8
+ class Targetbay_Tracking_Block_Product_Product extends TM_RichSnippets_Block_Product
9
+ {
10
+ /*JSON code*/
11
+
12
+ public function getJsonSnippetsProduct()
13
+ {
14
+ $data = array(
15
+ '@context' => 'http://schema.org',
16
+ '@type' => 'Product',
17
+ 'name' => $this->getProduct()->getName(),
18
+ 'image' => (string)Mage::helper('catalog/image')->init($this->getProduct(), 'image'),
19
+ 'description' => $this->getProduct()->getShortDescription(),
20
+ 'sku' => $this->getProduct()->getSku(),
21
+ 'offers' => array(
22
+ '@type' => 'Offer',
23
+ 'availability' => $this->getStockStatusUrl(),
24
+ 'price' => $this->getPriceValues(),
25
+ 'priceCurrency' => Mage::app()->getStore()->getCurrentCurrency()->getCode()
26
+ )
27
+ );
28
+
29
+ $aggregateRating = Mage::helper('tracking')->getRichSnippets();
30
+ if($aggregateRating['average_score'] != 0) {
31
+ $data['aggregateRating']['@type'] = 'AggregateRating';
32
+ $data['aggregateRating']['bestRating'] = '100';
33
+ $data['aggregateRating']['ratingValue'] = $aggregateRating['average_score'];
34
+ $data['aggregateRating']['reviewCount'] = $aggregateRating['reviews_count'];
35
+ $data['aggregateRating']['ratingCount'] = $aggregateRating['reviews_count'];
36
+ }
37
+
38
+ if (is_array($this->getPriceValues())) {
39
+ unset($data['offers']['price']);
40
+
41
+ $getPriceValues = $this->getPriceValues();
42
+ $data['offers']['@type'] = 'AggregateOffer';
43
+ $data['offers']['lowPrice'] = $getPriceValues[0];
44
+ $data['offers']['highPrice'] = $getPriceValues[1];
45
+
46
+ }
47
+
48
+ return Mage::helper('core')->jsonEncode($data);
49
+ }
50
+ }
51
+ }
app/code/community/Targetbay/Tracking/Block/Product/Review.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Block_Product_Review extends Mage_Core_Block_Template
8
+ {
9
+ /**
10
+ * Rendered the tracking review template if tracking enabled
11
+ *
12
+ * @see Mage_Core_Block_Template::_construct()
13
+ */
14
+ public function _construct()
15
+ {
16
+ parent::_construct();
17
+ $this->setTemplate('tracking/product/review.phtml');
18
+ }
19
+ }
app/code/community/Targetbay/Tracking/Block/Session/Tracking.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Block_Session_Tracking extends Mage_Core_Block_Template
8
+ {
9
+
10
+ /**
11
+ * Rendered the tracking template if tracking enabled
12
+ *
13
+ * @see Mage_Core_Block_Template::_construct()
14
+ */
15
+ public function _construct()
16
+ {
17
+ parent::_construct();
18
+ }
19
+ }
app/code/community/Targetbay/Tracking/Block/Tracking.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Block_Tracking extends Mage_Core_Block_Template
8
+ {
9
+
10
+ /**
11
+ * Rendered the tracking template if tracking enabled
12
+ *
13
+ * @see Mage_Core_Block_Template::_construct()
14
+ */
15
+ public function _construct()
16
+ {
17
+ parent::_construct();
18
+ if (Mage::helper('tracking')->trackingEnabled()) {
19
+ $this->setTemplate('tracking/tracking.phtml');
20
+ }
21
+ }
22
+ }
app/code/community/Targetbay/Tracking/Helper/Data.php ADDED
@@ -0,0 +1,1433 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Helper_Data extends Mage_Core_Helper_Abstract
8
+ {
9
+ public $cookie;
10
+ public $date;
11
+
12
+ CONST ANONYMOUS_USER = 'anonymous';
13
+ // page types
14
+ CONST ALL_PAGES = 'all';
15
+ CONST PAGE_VISIT = 'page-visit';
16
+ CONST PRODUCT_VIEW = 'product-view';
17
+ CONST CATEGORY_VIEW = 'category-view';
18
+ CONST DELETE_PRODUCT = "delete-product";
19
+ CONST UPDATE_PRODUCT = 'update-product';
20
+ CONST ADD_PRODUCT = 'add-product';
21
+ CONST CREATE_ACCOUNT = 'create-account';
22
+ CONST ADMIN_ACTIVATE_ACCOUNT = 'admin-activate-customer-account';
23
+ CONST LOGIN = 'login';
24
+ CONST LOGOUT = 'logout';
25
+ CONST ADDTOCART = 'add-to-cart';
26
+ CONST REMOVECART = 'remove-to-cart';
27
+ CONST UPDATECART = 'update-cart';
28
+ CONST ORDER_ITEMS = 'ordered-items';
29
+ CONST BILLING = 'billing';
30
+ CONST SHIPPING = 'shipping';
31
+ CONST PAGE_REFERRAL = 'referrer';
32
+ CONST CHECKOUT = 'checkout';
33
+ CONST CATALOG_SEARCH = 'searched';
34
+ CONST WISHLIST = 'wishlist';
35
+ CONST UPDATE_WISHLIST = 'update-wishlist';
36
+ CONST REMOVE_WISHLIST = 'remove-wishlist';
37
+ CONST ONESTEPCHECKOUT_ADDRESS = 'onestepcheckout';
38
+ CONST CART_INDEX = 'checkout-cart';
39
+ CONST SUBSCRIBE_CUSTOMER = 'user-subscribe';
40
+ CONST CUSTOMER_ADDRESS = 'change-user-address';
41
+ CONST CUSTOMER_ACCOUNT = 'change-user-account-info';
42
+ CONST CREATE_ADDRESS = 'new';
43
+ CONST UPDATE_ADDRESS = 'edit';
44
+ CONST RATINGS_STATS = 'ratings-stats';
45
+ CONST QUESTION_STATS = 'qa-stats';
46
+
47
+ // subscription status
48
+ CONST STATUS_SUBSCRIBED = 1;
49
+ CONST STATUS_NOT_ACTIVE = 2;
50
+ CONST STATUS_UNSUBSCRIBED = 3;
51
+ CONST STATUS_UNCONFIRMED = 4;
52
+
53
+ // product stock status
54
+ CONST IN_STOCK = 'in-stock';
55
+ CONST OUT_OF_STOCK = 'out-stock';
56
+
57
+ // order fullfillment process
58
+ CONST ORDER_SHIPMENT = 'shipment';
59
+ CONST ORDER_INVOICE = 'invoice';
60
+ CONST ORDER_REFUND = 'creditmemo';
61
+
62
+ CONST HOST_STAGE = 'https://stage.targetbay.com/api/v1/webhooks/';
63
+ CONST HOST_LIVE = 'https://app.targetbay.com/api/v1/webhooks/';
64
+ CONST HOST_DEV = 'https://dev.targetbay.com/api/v1/webhooks/';
65
+
66
+ CONST API_STAGE = 'stage';
67
+ CONST API_LIVE = 'app';
68
+ CONST API_DEV = 'dev';
69
+ CONST DEFAULT_TIMEOUT = 30;
70
+
71
+ /**
72
+ * Initialize object
73
+ */
74
+ public function __construct()
75
+ {
76
+ $this->cookie = Mage::getModel('core/cookie');
77
+ $this->date = Mage::getModel('core/date');
78
+ }
79
+
80
+ /**
81
+ * Check module is enabled or not
82
+ *
83
+ * @return boolean
84
+ */
85
+ public function trackingEnabled()
86
+ {
87
+ return (bool)Mage::getStoreConfig('targetbay_tracking/tracking_groups/enabled');
88
+ }
89
+
90
+ /**
91
+ * Get Target bay Host
92
+ *
93
+ * @return mixed
94
+ */
95
+ public function getHostname()
96
+ {
97
+ return Mage::getStoreConfig('targetbay_tracking/tracking_groups/hostname');
98
+ }
99
+
100
+ /**
101
+ * Get TargetbayToken
102
+ *
103
+ * @return mixed
104
+ */
105
+ public function getApiToken()
106
+ {
107
+ return Mage::getStoreConfig('targetbay_tracking/tracking_groups/api_token');
108
+ }
109
+
110
+ /**
111
+ * Get TargetBayIndex
112
+ *
113
+ * @return mixed
114
+ */
115
+ public function getApiIndex()
116
+ {
117
+ return Mage::getStoreConfig('targetbay_tracking/tracking_groups/api_index');
118
+ }
119
+
120
+ /**
121
+ * Get getApiStatus
122
+ *
123
+ * @return mixed
124
+ */
125
+ public function getApiStatus()
126
+ {
127
+ $apiStatus = Mage::getStoreConfig('targetbay_tracking/tracking_groups/api_status');
128
+ if($apiStatus) {
129
+ return $apiStatus;
130
+ } else {
131
+ return self::API_LIVE;
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Get the Session Tracking Js
137
+ *
138
+ * @return mixed
139
+ */
140
+ public function getReviewPageSize()
141
+ {
142
+ $reviewSize = Mage::getStoreConfig('targetbay_tracking/tracking_groups/reviews_per_page');
143
+ if($reviewSize){
144
+ $reviewSize = $reviewSize;
145
+ } else {
146
+ $reviewSize = 10;
147
+ }
148
+ return $reviewSize;
149
+ }
150
+
151
+ /**
152
+ * Get the email status
153
+ *
154
+ * @return mixed
155
+ */
156
+ public function getEmailStatus()
157
+ {
158
+ $emailStatus = Mage::getStoreConfig('targetbay_tracking/tracking_groups/disable_email');
159
+ if($emailStatus){
160
+ $emailStatus = $emailStatus;
161
+ } else {
162
+ $emailStatus = 1;
163
+ }
164
+ return $emailStatus;
165
+ }
166
+
167
+ /**
168
+ * Get TargetBay tracking type
169
+ *
170
+ * @return mixed
171
+ */
172
+ public function getTrackingType()
173
+ {
174
+ return Mage::getStoreConfig('targetbay_tracking/tracking_groups/tracking_type');
175
+ }
176
+
177
+ /**
178
+ * Print the log or not
179
+ *
180
+ * @return mixed
181
+ */
182
+ public function logEnabled()
183
+ {
184
+ return Mage::getStoreConfig('targetbay_tracking/tracking_groups/debug');
185
+ }
186
+
187
+ /**
188
+ * Get the log file name from configurations
189
+ */
190
+ public function getLogFileName()
191
+ {
192
+ return Mage::getStoreConfig('targetbay_tracking/tracking_groups/debug_file');
193
+ }
194
+
195
+ /**
196
+ * Get the availabe pages from configurations
197
+ *
198
+ * @return multitype:
199
+ */
200
+ public function availablePageTypes()
201
+ {
202
+ $types = (string) Mage::getStoreConfig('targetbay_tracking/tracking_groups/page_types');
203
+ $typesArray = explode(',', $types);
204
+ return $typesArray;
205
+ }
206
+
207
+ /**
208
+ * Get Tracking Code
209
+ *
210
+ * @return mixed
211
+ */
212
+ public function getTrackingScript()
213
+ {
214
+ return Mage::getStoreConfig('targetbay_tracking/tracking_groups/tracking_script');
215
+ }
216
+
217
+ /**
218
+ * Check the page configurations
219
+ *
220
+ * @param unknown $pageType
221
+ * @return boolean
222
+ */
223
+ public function canTrackPages($pageType)
224
+ {
225
+ if (!$this->trackingEnabled()) {
226
+ $this->debug('Tracking Module is Not Enabled. Please enable a Module');
227
+ return false;
228
+ }
229
+ $availabelPages = $this->availablePageTypes();
230
+ if (in_array(self::ALL_PAGES, $availabelPages)) {
231
+ return true;
232
+ }
233
+ if (!in_array($pageType, $availabelPages)) {
234
+ $this->debug("'$pageType'" . 'page is not enabled');
235
+ return false;
236
+ }
237
+ return true;
238
+ }
239
+
240
+ /**
241
+ * Get the customer data based on the action
242
+ *
243
+ * @param unknown $customer
244
+ * @param unknown $action
245
+ * @return unknown
246
+ */
247
+ public function getCustomerData($customer, $action)
248
+ {
249
+ try {
250
+ switch ($action) {
251
+ case self::LOGIN:
252
+ $data = $this->getCustomerSessionId($customer);
253
+ $data['login_date'] = $this->date->date('Y-m-d');
254
+ break;
255
+ case self::LOGOUT:
256
+ $data['session_id'] = Mage::getSingleton('core/session')->getCustomerSessionId();
257
+ $data['logout_date'] = $this->date->date('Y-m-d');
258
+ Mage::getSingleton('core/session')->unsTrackingSessionId();
259
+ Mage::getSingleton('core/session')->unsCustomerSessionId();
260
+ break;
261
+ case self::CREATE_ACCOUNT:
262
+ $data = $this->getCustomerSessionId($customer);
263
+ $data['firstname'] = $customer->getFirstname();
264
+ $data['lastname'] = $customer->getLastname();
265
+ $data['subscription_status'] = $this->getSubscriptionStatus($customer->getId());
266
+ $data['account_created'] = $this->date->date('Y-m-d');
267
+ break;
268
+ }
269
+ $data['user_id'] = $customer->getId();
270
+ $data['user_name'] = $customer->getName();
271
+ $data['user_mail'] = $customer->getEmail();
272
+ $data['timestamp'] = strtotime($this->date->date('Y-m-d'));
273
+ $data['ip_address'] = Mage::helper('core/http')->getRemoteAddr();
274
+ return $data;
275
+ } catch (Exception $e) {
276
+ $this->debug('Error message:'.$e->getMessage());
277
+ return;
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Get the customer subscription status
283
+ *
284
+ * @param unknown $customerId
285
+ * @return string
286
+ */
287
+ public function getSubscriptionStatus($customerId)
288
+ {
289
+ try {
290
+ $customerData = Mage::getModel('customer/customer')->load($customerId);
291
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($customerData);
292
+ if ($subscriber->getSubscriberStatus() == self::STATUS_UNSUBSCRIBED) {
293
+ $status = 'Unsubscribed';
294
+ } elseif ($subscriber->getSubscriberStatus() == self::STATUS_SUBSCRIBED) {
295
+ $status = 'Subscribed';
296
+ } elseif ($subscriber->getSubscriberStatus() == self::STATUS_UNCONFIRMED) {
297
+ $status = 'Unconfirmed';
298
+ } elseif ($subscriber->getSubscriberStatus() == self::STATUS_NOT_ACTIVE) {
299
+ $status = 'Not Activated';
300
+ } else {
301
+ $status = '';
302
+ }
303
+ return $status;
304
+ } catch (Exception $e) {
305
+ $this->debug('Error message:'.$e->getMessage());
306
+ return;
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Get the customer session info
312
+ *
313
+ * @param unknown $customerId
314
+ * @return string
315
+ */
316
+ public function getCustomerSessionId($customer)
317
+ {
318
+ $data = array();
319
+ try {
320
+ $visitorData = Mage::getSingleton('core/session')->getVisitorData();
321
+ $session = $visitorData['session_id'] . strtotime(date('Y-m-d H:i:s'));
322
+ $data['session_id'] = $session;
323
+
324
+ $trackingType = $this->getTrackingType();
325
+ if ($trackingType == 1):
326
+ $data['previous_session_id'] = $this->cookie->get('targetbay_session_id');
327
+ else:
328
+ $data['previous_session_id'] = $this->cookie->get('trackingsession');
329
+ endif;
330
+
331
+ Mage::getSingleton('core/session')->setCustomerSessionId($session);
332
+ return $data;
333
+ } catch (Exception $e) {
334
+ $this->debug('Error message:'.$e->getMessage());
335
+ return;
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Check the order placed by registered user or not
341
+ *
342
+ * @param unknown $quoteId
343
+ * @return boolean|Mage_Core_Model_Abstract
344
+ */
345
+ public function isRegisterCheckout($order)
346
+ {
347
+ $checkoutMethod = Mage::getModel('sales/quote')->load($order->getQuoteId())->getCheckoutMethod(true);
348
+ if ($checkoutMethod != 'register')
349
+ return false;
350
+ return Mage::getModel('customer/customer')->load($order->getCustomerId());
351
+ }
352
+
353
+ /**
354
+ * Basic visit info
355
+ *
356
+ * @return string
357
+ */
358
+ public function visitInfo()
359
+ {
360
+ $data = array();
361
+ try {
362
+ $customer = Mage::getSingleton('customer/session');
363
+ $data['user_name'] = $customer->isLoggedIn() ? $customer->getCustomer()->getName() : self::ANONYMOUS_USER;
364
+ $data['user_email'] = $customer->isLoggedIn() ? $customer->getCustomer()->getEmail() : self::ANONYMOUS_USER;
365
+ $trackingType = $this->getTrackingType();
366
+ $moduleName = Mage::app()->getRequest()->getModuleName();
367
+
368
+ if (($moduleName == 'catalogsearch') && ($customer->isLoggedIn())) {
369
+ $user_id = $customer->getCustomer()->getId();
370
+ } else {
371
+ $user_id = $customer->isLoggedIn() ? $customer->getCustomer()->getId() : $this->cookie->get('targetbay_session_id');
372
+ }
373
+
374
+ if ($trackingType == 1):
375
+ $data['already_tracked'] = true;
376
+ $data['user_id'] = $user_id;
377
+ $data['session_id'] = $customer->isLoggedIn() ? Mage::getSingleton('core/session')->getCustomerSessionId() : $this->cookie->get('targetbay_session_id');
378
+ else:
379
+ if (!$this->cookie->get('trackingsession')) {
380
+ $userId = Mage::getSingleton('core/session')->getTrackingSessionId();
381
+ } else {
382
+ $userId = $this->cookie->get('trackingsession');
383
+ }
384
+ $data['user_id'] = $customer->isLoggedIn() ? $customer->getCustomer()->getId() : $userId;
385
+ $data['session_id'] = $customer->isLoggedIn() ? Mage::getSingleton('core/session')->getCustomerSessionId() : Mage::getSingleton('core/session')->getTrackingSessionId();
386
+ endif;
387
+
388
+ $data['page_url'] = Mage::helper('core/url')->getCurrentUrl();
389
+ $data['ip_address'] = Mage::helper('core/http')->getRemoteAddr();
390
+ $data['user_agent'] = Mage::helper('core/http')->getHttpUserAgent();
391
+ $data['utm_sources'] = $this->cookie->get('utm_source') ? $this->cookie->get('utm_source') : '';
392
+ $data['utm_token'] = $this->cookie->get('utm_token') ? $this->cookie->get('utm_token') : '';
393
+ $pageTitle = Mage::app()->getLayout()->getBlock('head') ? Mage::app()->getLayout()->getBlock('head')->getTitle() : Mage::getSingleton('checkout/session')->getTitle();
394
+ $data['page_title'] = addslashes($pageTitle);
395
+ return $data;
396
+ } catch (Exception $e) {
397
+ $this->debug('Error message:'.$e->getMessage());
398
+ return;
399
+ }
400
+ }
401
+
402
+ /**
403
+ * Push the referer url
404
+ *
405
+ * @return boolean
406
+ */
407
+ public function getRefererData()
408
+ {
409
+ try {
410
+ $isSecure = Mage::app()->getFrontController()->getRequest()->isSecure();
411
+ if($isSecure) {
412
+ $currentUrl = Mage::getUrl('', array('_secure'=>true));
413
+ } else {
414
+ $currentUrl = Mage::getUrl('');
415
+ }
416
+ $referer = Mage::helper('core/http')->getHttpReferer() ? Mage::helper('core/http')->getHttpReferer() : $currentUrl;
417
+ if (strpos($referer, $currentUrl) !== false) {
418
+ return false; // base url and referer url matches.
419
+ }
420
+ $data = $this->visitInfo();
421
+ $data['referrer_url'] = $referer;
422
+ return $data;
423
+ } catch (Exception $e) {
424
+ $this->debug('Error message:'.$e->getMessage());
425
+ return;
426
+ }
427
+ }
428
+
429
+ /**
430
+ * Push the page info using Varien_Http_Client
431
+ *
432
+ * @return string
433
+ */
434
+ public function postPageInfo($url, $jsondata)
435
+ {
436
+ $client = new Varien_Http_Client();
437
+ $client->setUri($url);
438
+ $client->setConfig(array(
439
+ 'maxredirects' => 0,
440
+ 'timeout' => 1
441
+ ));
442
+ $client->setRawData(utf8_encode($jsondata));
443
+
444
+ try {
445
+ $this->debug("Endpoint Url =>$url");
446
+ $this->debug("Request =>");
447
+ $this->debug($jsondata);
448
+ $response = $client->request(Varien_Http_Client::POST)->getBody();
449
+ $this->debug("Response =>");
450
+ $this->debug ( print_r($response, true) );
451
+ return $response;
452
+ } catch (Exception $e) {
453
+ $this->debug('Error message '.$e->getMessage());
454
+ return;
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Remove the cookies
460
+ */
461
+ public function removeCookies()
462
+ {
463
+ $this->cookie->delete('trackingsession');
464
+ $this->cookie->delete('trackingid');
465
+ $this->cookie->delete('trackingemail');
466
+ $this->cookie->delete('trackingname');
467
+ $this->cookie->delete('trackingorderid');
468
+ $this->cookie->delete('utm_source');
469
+ $this->cookie->delete('utm_token');
470
+ $this->cookie->delete('targetbay_session_id');
471
+ $this->cookie->delete('user_loggedin');
472
+ $this->cookie->delete('afterlogin_session_id');
473
+ }
474
+
475
+ /**
476
+ * Get the cart info
477
+ *
478
+ * @return string
479
+ */
480
+ public function getCartInfo()
481
+ {
482
+ $data = array();
483
+ try {
484
+ $customer = Mage::getSingleton('customer/session');
485
+ $checkout = Mage::getSingleton('checkout/session')->getQuote();
486
+ $trackingType = $this->getTrackingType();
487
+ if ($trackingType == 1):
488
+ $data['user_id'] = $customer->isLoggedIn() ? $customer->getCustomer()->getId() : $this->cookie->get('targetbay_session_id');
489
+ $data['session_id'] = $customer->isLoggedIn() ? Mage::getSingleton('core/session')->getCustomerSessionId() : $this->cookie->get('targetbay_session_id');
490
+ else:
491
+ $data['user_id'] = $customer->isLoggedIn() ? $customer->getId() : Mage::getSingleton('core/session')->getTrackingSessionId();
492
+ $data['session_id'] = $customer->isLoggedIn() ? Mage::getSingleton('core/session')->getCustomerSessionId() : Mage::getSingleton('core/session')->getTrackingSessionId();
493
+ endif;
494
+
495
+ $data['user_name'] = $customer->isLoggedIn() ? $customer->getCustomer()->getName() : Targetbay_Tracking_Helper_Data::ANONYMOUS_USER;
496
+ $data['user_mail'] = $customer->isLoggedIn() ? $customer->getCustomer()->getEmail() : Targetbay_Tracking_Helper_Data::ANONYMOUS_USER;
497
+
498
+ $data['order_id'] = Mage::getSingleton('checkout/session')->getQuoteId();
499
+ $data['utm_sources'] = $this->cookie->get('utm_source') ? $this->cookie->get('utm_source') : '';
500
+ $data['utm_token'] = $this->cookie->get('utm_token') ? $this->cookie->get('utm_token') : '';
501
+ $data['timestamp'] = strtotime($this->date->date('Y-m-d'));
502
+ $pageTitle = Mage::app()->getLayout()->getBlock('head') ? Mage::app()->getLayout()->getBlock('head')->getTitle() : Mage::getSingleton('checkout/session')->getTitle();
503
+ $data['page_title'] = addslashes($pageTitle);
504
+ return $data;
505
+ } catch (Exception $e) {
506
+ $this->debug('Error message '.$e->getMessage());
507
+ return;
508
+ }
509
+ }
510
+
511
+ /**
512
+ * Get the common info for quote or order, billing and shipping
513
+ *
514
+ * @param unknown $order
515
+ * @return string
516
+ */
517
+ public function getSessionInfo($object)
518
+ {
519
+ $data = array();
520
+ try {
521
+ $trackingType = $this->getTrackingType();
522
+ if ($trackingType == 1):
523
+ $data['user_id'] = $object->getCustomerId() ? $object->getCustomerId() : $this->cookie->get('targetbay_session_id');
524
+ $data['session_id'] = Mage::getSingleton('customer/session')->isLoggedIn() ? Mage::getSingleton('core/session')->getCustomerSessionId() : $this->cookie->get('targetbay_session_id');
525
+ else:
526
+ $data['user_id'] = $object->getCustomerId() ? $object->getCustomerId() : Mage::getSingleton('core/session')->getTrackingSessionId();
527
+ $data['session_id'] = Mage::getSingleton('customer/session')->isLoggedIn() ? Mage::getSingleton('core/session')->getCustomerSessionId() : Mage::getSingleton('core/session')->getTrackingSessionId();
528
+ endif;
529
+
530
+ $data['utm_sources'] = $this->cookie->get('utm_source') ? $this->cookie->get('utm_source') : '';
531
+ $data['utm_token'] = $this->cookie->get('utm_token') ? $this->cookie->get('utm_token') : '';
532
+ $data['timestamp'] = strtotime($this->date->date('Y-m-d'));
533
+ $pageTitle = Mage::app()->getLayout()->getBlock('head') ? Mage::app()->getLayout()->getBlock('head')->getTitle() : Mage::getSingleton('checkout/session')->getTitle();
534
+ $data['page_title'] = addslashes($pageTitle);
535
+ return $data;
536
+ } catch (Exception $e) {
537
+ $this->debug('Error message '.$e->getMessage());
538
+ return;
539
+ }
540
+ }
541
+
542
+ /**
543
+ * Get the Order data
544
+ *
545
+ * @param unknown $object
546
+ * @return string
547
+ */
548
+ public function getInfo($object)
549
+ {
550
+ try {
551
+ $customer = $object->getCustomer();
552
+ $items = $object->getAllVisibleItems();
553
+ $data = $this->getSessionInfo($object);
554
+ $data['first_name'] = $object->getCustomerFirstname();
555
+ $data['last_name'] = $object->getCustomerLastname();
556
+ $guestUsername = $object->getCustomerFirstname().' '.$object->getCustomerLastname();
557
+ $gName = !empty($guestUsername) ? $guestUsername : self::ANONYMOUS_USER;
558
+ $data['user_name'] = $object->getCustomerIsGuest() ? $gName : $data['first_name'] . ' ' . $data['last_name'];
559
+ $data['user_mail'] = $object->getCustomerEmail();
560
+ $data['order_id'] = $object->getId();
561
+ $data['order_price'] = $object->getSubtotal();
562
+ $data['order_quantity'] = $object->getData('total_qty_ordered');
563
+ $data['shipping_method'] = $object->getData('shipping_description');
564
+ $data['shipping_price'] = $object->getData('shipping_amount');
565
+ $data['tax_amount'] = $object->getData('tax_amount');
566
+ $data['payment_method'] = $object->getPayment()->getMethodInstance()->getTitle();
567
+ $data['cart_items'] = $this->getOrderItemsInfo($object);
568
+ return $data;
569
+ } catch (Exception $e) {
570
+ $this->debug('Error message '.$e->getMessage());
571
+ return;
572
+ }
573
+ }
574
+
575
+ /**
576
+ * Collect the order items info
577
+ *
578
+ * @param unknown $order
579
+ * @return multitype:unknown
580
+ */
581
+ public function getOrderItemsInfo($order, $orderExportApi = false)
582
+ {
583
+ $dataItems = array();
584
+ try {
585
+ $items = $order->getAllVisibleItems();
586
+ foreach ($items as $orderItem) {
587
+ $dataItem = $this->getItemInfo($orderItem);
588
+ if ($customOptions = $this->getCustomOptionsInfo($orderItem, $orderExportApi))
589
+ $dataItem['attributes'] = $customOptions;
590
+ $dataItems[] = $dataItem;
591
+ }
592
+ return $dataItems;
593
+ } catch (Exception $e) {
594
+ $this->debug('Error message '.$e->getMessage());
595
+ return;
596
+ }
597
+ }
598
+
599
+ /**
600
+ * Collect the order payment info
601
+ *
602
+ * @param unknown $order
603
+ * @return multitype:unknown
604
+ */
605
+ public function getPaymentInfo($orderId, $orderExportApi = false)
606
+ {
607
+ $paymentTitle = '';$paymentMethod = '';
608
+ try {
609
+ $paymentCollection = Mage::getModel('sales/order_payment')->getCollection()->addFieldToFilter('parent_id', $orderId);
610
+ foreach ($paymentCollection as $paymentDetails) {
611
+ $paymentMethod = $paymentDetails->getMethod();
612
+ }
613
+
614
+ $store = Mage::app()->getStore();
615
+ $path = 'payment/' . $paymentMethod . '/title';
616
+ $paymentTitle = Mage::getStoreConfig($path, $store);
617
+ return $paymentTitle;
618
+ } catch (Exception $e) {
619
+ $this->debug('Error message '.$e->getMessage());
620
+ return;
621
+ }
622
+ }
623
+
624
+ /**
625
+ * Get the item info
626
+ *
627
+ * @param unknown $item
628
+ * @return unknown
629
+ */
630
+ public function getItemInfo($item, $actionType = false)
631
+ {
632
+ $dataItem = array();
633
+ try {
634
+ $product = Mage::getModel('catalog/product')->load($item->getData('product_id'));
635
+ $dataItem['type'] = $item->getProductType();
636
+ $dataItem['product_id'] = $item->getProductId();
637
+ $dataItem['product_sku'] = $item->getSku();
638
+ $dataItem['product_name'] = addslashes($item->getName());
639
+ $dataItem['price'] = $actionType ? $item->getProduct()->getPrice() : $item->getPrice();
640
+ $dataItem['special_price'] = $product->getSpecialPrice();
641
+ $qty = $actionType ? $item->getProduct()->getQty() : $item->getQty();
642
+ $dataItem['productimg'] = $this->getImageUrl($product, 'image');
643
+
644
+ $dataItem['category'] = $this->getProductCategory($product);
645
+ $dataItem['category_name'] = $this->getProductCategoryName($product);
646
+ $dataItem['quantity'] = ($item->getData('qty_ordered')) ? $item->getData('qty_ordered') : $qty;
647
+ $dataItem['page_url'] = Mage::getUrl($product->getUrlPath());
648
+ return $dataItem;
649
+ } catch (Exception $e) {
650
+ $this->debug('Error message '.$e->getMessage());
651
+ return;
652
+ }
653
+ }
654
+
655
+ /**
656
+ * Get the product categories
657
+ *
658
+ * @param unknown $product
659
+ * @return unknown
660
+ */
661
+ public function getProductCategoryName($product)
662
+ {
663
+ $categoryIds = $product->getCategoryIds();
664
+
665
+ $productCategories = array();
666
+ $categoryName = '';
667
+
668
+ if (count($categoryIds)) {
669
+ foreach ($categoryIds as $categoryId) {
670
+ $_category = Mage::getModel('catalog/category')->load($categoryId);
671
+ $productCategories[] = $_category->getName();
672
+ }
673
+
674
+ $categoryName = implode(',', $productCategories);
675
+ }
676
+
677
+ return $categoryName;
678
+ }
679
+
680
+ /**
681
+ * Get the product categories
682
+ *
683
+ * @param unknown $product
684
+ * @return unknown
685
+ */
686
+ public function getProductCategory($product)
687
+ {
688
+ $categoryIds = $product->getCategoryIds();
689
+ $productCategories = array();
690
+ $categoryId = '';
691
+ if (count($categoryIds)) {
692
+
693
+ foreach ($categoryIds as $categoryId) {
694
+ $_category = Mage::getModel('catalog/category')->load($categoryId);
695
+ $productCategories[] = $_category->getName();
696
+ }
697
+
698
+ $categoryId = implode(',', $categoryIds);
699
+ }
700
+
701
+ return $categoryId;
702
+ }
703
+
704
+ /**
705
+ * Get the item custom options
706
+ *
707
+ * @param unknown $item
708
+ * @return boolean|unknown|number
709
+ */
710
+ public function getCustomOptionsInfo($item, $orderExportApi)
711
+ {
712
+ try {
713
+ $customOptions = $orderExportApi ? $item->getProductOptions() : $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
714
+
715
+ if (empty($customOptions['options']) && empty($customOptions['attributes_info']))
716
+ return false;
717
+ $superAttributeInfo = isset($customOptions['attributes_info']) ? $this->getOptionValues($customOptions['attributes_info']) : array();
718
+ $customOptionInfo = isset($customOptions['options']) ? $this->getOptionValues($customOptions['options']) : array();
719
+ $optionsData = array_merge($superAttributeInfo, $customOptionInfo);
720
+ return $optionsData;
721
+ } catch (Exception $e) {
722
+ $this->debug('Error message '.$e->getMessage());
723
+ return;
724
+ }
725
+ }
726
+
727
+ /**
728
+ * Get the options values
729
+ *
730
+ * @param unknown $options
731
+ * @return multitype:unknown
732
+ */
733
+ public function getOptionValues($options)
734
+ {
735
+ $optionData = array();
736
+ try {
737
+ foreach ($options as $option) {
738
+ $data['label'] = $option['label'];
739
+ $data['value'] = $option['value'];
740
+ $optionData[] = $data;
741
+ }
742
+ return $optionData;
743
+ } catch (Exception $e) {
744
+ $this->debug('Error message '.$e->getMessage());
745
+ return;
746
+ }
747
+ }
748
+
749
+ /**
750
+ * Get the order or quote address by address type.
751
+ *
752
+ * @param unknown $object
753
+ * @param unknown $type
754
+ * @return string
755
+ */
756
+ public function getAddressData($object, $type)
757
+ {
758
+ try {
759
+ $address = ($type == self::SHIPPING) ? $object->getShippingAddress() : $object->getBillingAddress();
760
+ $addressData = $this->getSessionInfo($object);
761
+ $addressData['first_name'] = $address->getFirstname();
762
+ $addressData['last_name'] = $address->getLastname();
763
+ $guestUsername = $address->getFirstname().' '.$address->getLastname();
764
+ $gName = !empty($guestUsername) ? $guestUsername : self::ANONYMOUS_USER;
765
+ $addressData['user_name'] = $object->getCustomerIsGuest() ? $gName : $addressData['first_name'] . ' ' . $addressData['last_name'];
766
+ $addressData['order_id'] = $object->getId();
767
+ $addressData['user_mail'] = $object->getCustomerEmail();
768
+ $addressData['address1'] = $address->getStreet(1);
769
+ $addressData['address2'] = $address->getStreet(2);
770
+ $addressData['city'] = $address->getCity();
771
+ $addressData['state'] = $address->getRegion();
772
+ $addressData['zipcode'] = $address->getPostcode();
773
+ if($address->getCountryId()) {
774
+ $countryName = Mage::getModel('directory/country')->loadByCode($address->getCountryId())->getName();
775
+ } else {
776
+ $countryName = '';
777
+ }
778
+ $addressData['country'] = isset($countryName) ? $countryName : $address->getCountryId();
779
+ $addressData['phone'] = $address->getTelephone();
780
+ return $addressData;
781
+ } catch (Exception $e) {
782
+ $this->debug('Error message '.$e->getMessage());
783
+ return;
784
+ }
785
+ }
786
+
787
+ /**
788
+ * Get the product info
789
+ *
790
+ * @param unknown $product
791
+ * @return string
792
+ */
793
+ public function getProductData($product)
794
+ {
795
+ $configOptions = array();$customOptions = array();$data = array();
796
+ try {
797
+ $data['image_url'][] = $this->getProductImages($product);
798
+ $data['entity_id'] = $product->getId();
799
+ $data['attribute_set_id'] = $product->getEntityTypeId();
800
+ $data['type_id'] = $product->getTypeId();
801
+ $data['sku'] = $product->getSku();
802
+ $data['product_status'] = $product->getStatus();
803
+ $data['currency_type'] = Mage::app()->getStore()->getCurrentCurrencyCode();
804
+
805
+ $data['stock_count'] = -1;
806
+
807
+ if ($stock = $product->getData('stock_data')) {
808
+ $data['stock_count'] = !empty($stock['is_in_stock']) ? $stock['qty'] : -1;
809
+ }
810
+
811
+ $data['visibility'] = $product->getVisibility();
812
+ $data['description'] = $product->getDescription();
813
+ $data['price'] = $product->getPrice();
814
+ $data['special_price'] = $product->getSpecialPrice();
815
+ $data['weight'] = $product->getWeight();
816
+ $data['name'] = addslashes($product->getName());
817
+
818
+ $data['category'] = $this->getProductCategory($product);
819
+ $data['url_key'] = $product->getUrlKey();
820
+ $data['full_url_key'] = $product->getProductUrl();
821
+
822
+ if ($configData = $product->getData('configurable_attributes_data')) {
823
+ $configOptions = $this->productOptions($configData, 'label');
824
+ }
825
+ if ($custOptions = $product->getData('product_options')) {
826
+ $customOptions = $this->productOptions($custOptions);
827
+ }
828
+ $options = array_merge($configOptions, $customOptions);
829
+ if (!empty($options))
830
+ $data['attributes'] = $options;
831
+ return $data;
832
+ } catch (Exception $e) {
833
+ $this->debug('Error message '.$e->getMessage());
834
+ return;
835
+ }
836
+ }
837
+
838
+ /**
839
+ * Get the product options when saving product
840
+ *
841
+ * @param unknown $configData
842
+ * @param string $customOption
843
+ * @return multitype:multitype:unknown
844
+ */
845
+ public function productOptions($configData, $customOption = 'title')
846
+ {
847
+ $options = array();
848
+ try {
849
+ foreach ($configData as $cdata) {
850
+ $attrLabel = $cdata[$customOption];
851
+ if (!isset($cdata['values'])) {
852
+ $options[] = array(
853
+ 'label' => $attrLabel,
854
+ 'value' => $attrLabel
855
+ );
856
+ continue;
857
+ }
858
+ foreach ($cdata['values'] as $val) {
859
+ $attrVal = $val[$customOption];
860
+ $options[] = array(
861
+ 'label' => $attrLabel,
862
+ 'value' => $attrVal
863
+ );
864
+ }
865
+ }
866
+ return $options;
867
+ } catch (Exception $e) {
868
+ $this->debug('Error message '.$e->getMessage());
869
+ return;
870
+ }
871
+ }
872
+
873
+ /**
874
+ * Get the product images
875
+ *
876
+ * @param unknown $product
877
+ * @return string
878
+ */
879
+ public function getProductImages($product)
880
+ {
881
+ $images = array();
882
+ try {
883
+ $images['url'] = $this->getImageUrl($product, 'image');
884
+ $images['position'] = 1;
885
+ $images['thumbnail_image'] = $this->getImageUrl($product, 'small_image');
886
+ $images['medium_image'] = $this->getImageUrl($product, 'thumbnail');
887
+ return $images;
888
+ } catch (Exception $e) {
889
+ $this->debug('Error message '.$e->getMessage());
890
+ return;
891
+ }
892
+ }
893
+
894
+ /**
895
+ * Get the Product image url
896
+ *
897
+ * @param unknown $product
898
+ * @param unknown $imageType
899
+ * @return string
900
+ */
901
+ public function getImageUrl($product, $imageType)
902
+ {
903
+ if($product->getData($imageType)) {
904
+ $imgPath = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $product->getData($imageType);
905
+ } else {
906
+ $imgPath = '';
907
+ }
908
+
909
+ return $imgPath;
910
+ }
911
+
912
+ /**
913
+ * Check the order full fillment
914
+ *
915
+ * @return boolean
916
+ */
917
+ public function isFullFillmentProcess($params)
918
+ {
919
+ if (isset($params[self::ORDER_SHIPMENT]) || isset($params[self::ORDER_INVOICE]) || isset($params[self::ORDER_REFUND]))
920
+ return true;
921
+ return false;
922
+ }
923
+
924
+ /**
925
+ * Get the wishlist product info
926
+ *
927
+ * @param unknown $productId
928
+ * @return string
929
+ */
930
+ public function getWishlistProductInfo($productId)
931
+ {
932
+ $data = array();
933
+ try {
934
+ $product = Mage::getModel('catalog/product')->load($productId);
935
+ $qty = 1;
936
+
937
+ $data['type'] = $product->getTypeId();
938
+ $data['product_id'] = $product->getId();
939
+ $data['product_sku'] = $product->getSku();
940
+ $data['name'] = addslashes($product->getName());
941
+ $data['price'] = $product->getPrice();
942
+ $data['special_price'] = $product->getSpecialPrice();
943
+ $data['productimg'] = $this->getImageUrl($product, 'image');
944
+
945
+ $data['category'] = $this->getProductCategory($product);
946
+ $data['category_name'] = $this->getProductCategoryName($product);
947
+ $data['quantity'] = (Mage::app()->getRequest()->getParam('qty')) ? Mage::app()->getRequest()->getParam('qty') : $qty;
948
+ $data['page_url'] = Mage::getUrl($product->getUrlPath());
949
+
950
+ return $data;
951
+ } catch (Exception $e) {
952
+ $this->debug('Error message '.$e->getMessage());
953
+ return;
954
+ }
955
+ }
956
+
957
+ /**
958
+ * Collect the wishlist items info
959
+ *
960
+ * @param unknown $productIds
961
+ * @return multitype:unknown
962
+ */
963
+ public function getWishlistItemsInfo($wishlistInfo)
964
+ {
965
+ $dataItems = array();
966
+ try {
967
+ $wishlistItemCollection = $wishlistInfo->setStoreId(1)->getItemCollection();
968
+
969
+ foreach ($wishlistItemCollection as $id => $wishlistItem) {
970
+ $product = $wishlistItem->getProduct();
971
+ $dataItem = $this->wishlistProductInfo($product);
972
+ $dataItems[$id] = $dataItem;
973
+ }
974
+ return $dataItems;
975
+ } catch (Exception $e) {
976
+ $this->debug('Error message '.$e->getMessage());
977
+ return;
978
+ }
979
+ }
980
+
981
+ /**
982
+ * Collect the wishlist items product info
983
+ *
984
+ * @param unknown $productIds
985
+ * @return multitype:unknown
986
+ */
987
+ public function wishlistProductInfo($product)
988
+ {
989
+ $dataItem = array();
990
+ try {
991
+ $product = Mage::getModel('catalog/product')->load($product->getData('entity_id'));
992
+ $dataItem['type'] = $product->getTypeId();
993
+ $dataItem['product_id'] = $product->getId();
994
+ $dataItem['product_name'] = addslashes($product->getName());
995
+ $dataItem['price'] = $product->getPrice();
996
+ $dataItem['special_price'] = $product->getSpecialPrice();
997
+ $dataItem['productimg'] = $this->getImageUrl($product, 'image');
998
+ $dataItem['category'] = $this->getProductCategory($product);
999
+ $dataItem['category_name'] = $this->getProductCategoryName($product);
1000
+ $dataItem['page_url'] = Mage::getUrl($product->getUrlPath());
1001
+ return $dataItem;
1002
+ } catch (Exception $e) {
1003
+ $this->debug('Error message '.$e->getMessage());
1004
+ return;
1005
+ }
1006
+
1007
+ }
1008
+
1009
+ /**
1010
+ *
1011
+ * @param unknown $order
1012
+ * @param unknown $params
1013
+ * @return unknown|boolean
1014
+ */
1015
+ public function getFullFillmentData($order, $params)
1016
+ {
1017
+ $shipmetItems = array();
1018
+ $shipmentsInfo = array();
1019
+ try {
1020
+ if (isset($params[self::ORDER_SHIPMENT])) {
1021
+ $shipmentsInfo['order_id'] = $order->getId();
1022
+ $shipmentsInfo['order_status'] = $order->getStatus();
1023
+ $shipmentsInfo['total_ordered_qty'] = (int)$order->getData('total_qty_ordered');
1024
+ $shipmentsInfo['user_id'] = $order->getData('customer_is_guest') ? self::ANONYMOUS_USER : $order->getData('customer_id');
1025
+ $shipmentsInfo['user_mail'] = $order->getData('customer_is_guest') ? $order->getData('customer_email') : $order->getData('customer_email');
1026
+ $shipmentsInfo['created_at'] = $order->getData('updated_at');
1027
+
1028
+ foreach ($order->getAllVisibleItems() as $item) {
1029
+ if ($item->getQtyShipped() == '')
1030
+ continue;
1031
+ $shipmentItemInfo['product_id'] = $item->getProductId();
1032
+ $shipmentItemInfo['name'] = addslashes($item->getName());
1033
+ $shipmentItemInfo['sku'] = $item->getSku();
1034
+ $shipmentItemInfo['qty_ordered'] = (int)$item->getQtyOrdered();
1035
+ $shipmentItemInfo['qty_shipped'] = (int)$item->getQtyShipped();
1036
+ $shipmetItems[] = $shipmentItemInfo;
1037
+ }
1038
+ $shipmentsInfo['shipment_items'] = $shipmetItems;
1039
+ return $shipmentsInfo;
1040
+ }
1041
+ } catch (Exception $e) {
1042
+ $this->debug('Error message '.$e->getMessage());
1043
+ return;
1044
+ }
1045
+ }
1046
+
1047
+ /**
1048
+ * Stop the page visit for already tracked events
1049
+ *
1050
+ * @return multitype:string
1051
+ */
1052
+ public function eventAlreadyTracked($eventName)
1053
+ {
1054
+ $stopAction = array(
1055
+ 'cms_index_index',
1056
+ 'catalog_category_view',
1057
+ 'catalog_product_view',
1058
+ 'catalogsearch_result_index',
1059
+ 'catalogsearch_ajax_suggest',
1060
+ 'checkout_cart_add',
1061
+ 'checkout_cart_index',
1062
+ 'checkout_cart_updatePost',
1063
+ 'checkout_cart_remove',
1064
+ 'customer_account_create',
1065
+ 'customer_account_loginPost',
1066
+ 'customer_account_logout',
1067
+ 'customer_account_logoutSuccess',
1068
+ 'customer_account_createPost',
1069
+ 'checkout_onepage_index',
1070
+ 'onestepcheckout_index_index',
1071
+ 'firecheckout_index_index',
1072
+ 'checkout_onepage_saveBilling',
1073
+ 'checkout_onepage_saveShipping',
1074
+ 'checkout_onepage_saveShippingMethod',
1075
+ 'checkout_onepage_savePayment',
1076
+ 'checkout_onepage_getAdditional',
1077
+ 'checkout_onepage_progress',
1078
+ 'checkout_onepage_saveOrder'
1079
+ );
1080
+ return in_array($eventName, $stopAction);
1081
+ }
1082
+
1083
+ /**
1084
+ * debugging
1085
+ *
1086
+ * @param unknown $mess
1087
+ */
1088
+ public function debug($mess, $logFile = null)
1089
+ {
1090
+ if ($this->logEnabled())
1091
+ Mage::log($mess, null, $logFile ? $logFile : $this->getLogFileName());
1092
+ }
1093
+
1094
+ /**
1095
+ * debugging
1096
+ *
1097
+ * @param unknown $mess
1098
+ */
1099
+ public function getProductVersion()
1100
+ {
1101
+ return (string)Mage::getConfig()->getModuleConfig('Targetbay_Tracking')->version;
1102
+ }
1103
+
1104
+ /**
1105
+ * Visiting page info
1106
+ *
1107
+ * @param Varien_Event_Observer $observer
1108
+ *
1109
+ * @return void
1110
+ */
1111
+ public function getPageVisitData()
1112
+ {
1113
+ Mage::getModel('tracking/observer')->setCookieValues();
1114
+
1115
+ // Set Token Values
1116
+ if (isset($_GET['utm_source']) && !$this->cookie->get('utm_source')) {
1117
+ $this->cookie->set('utm_source', $_GET['utm_source'], null, null, null, null, false);
1118
+ }
1119
+
1120
+ if (isset($_GET['token']) && !$this->cookie->get('utm_token')) {
1121
+ $this->cookie->set('utm_token', $_GET['token'], null, null, null, null, false);
1122
+ }
1123
+
1124
+ // Page Visit Tracking
1125
+ $data = $this->visitInfo();
1126
+
1127
+ return $data;
1128
+ }
1129
+
1130
+ /**
1131
+ * Category view page
1132
+ *
1133
+ * @param Varien_Event_Observer $observer
1134
+ *
1135
+ * @return void
1136
+ */
1137
+ public function getCategoryViewData()
1138
+ {
1139
+ $category = Mage::registry('current_category');
1140
+ $data = $this->visitInfo();
1141
+ $data['category_id'] = $category->getId();
1142
+ $data['category_url'] = $category->getUrl();
1143
+ $data['category_name'] = $category->getName();
1144
+
1145
+ return $data;
1146
+ }
1147
+
1148
+ /**
1149
+ * Product view page
1150
+ *
1151
+ * @param Varien_Event_Observer $observer
1152
+ *
1153
+ * @return void
1154
+ */
1155
+ public function getProductViewData()
1156
+ {
1157
+ $data = array();
1158
+ // Get the base visit info
1159
+ try {
1160
+ $data = $this->visitInfo();
1161
+ $product = Mage::registry('product');
1162
+ $categoryIds = $product->getCategoryIds();
1163
+ if (count($categoryIds)) {
1164
+ $firstCategoryId = $categoryIds[0];
1165
+ $_category = Mage::getModel('catalog/category')->load($firstCategoryId);
1166
+ $data['category'] = $_category->getName();
1167
+ }
1168
+ $data['product_id'] = $product->getId();
1169
+ $data['product_name'] = addslashes($product->getName());
1170
+ $data['price'] = $product->getPrice();
1171
+ $data['special_price'] = $product->getSpecialPrice();
1172
+ $data['productimg'] = $product->getImageUrl();
1173
+ $data['stock'] = self::OUT_OF_STOCK;
1174
+ $stock = $product->getStockItem();
1175
+ if ($stock->getIsInStock()) {
1176
+ $data['stock'] = self::IN_STOCK;
1177
+ }
1178
+ return $data;
1179
+ } catch (Exception $e) {
1180
+ $this->debug('Error message '.$e->getMessage());
1181
+ return;
1182
+ }
1183
+ }
1184
+
1185
+ /**
1186
+ * Get the page info for static page
1187
+ *
1188
+ * @return string
1189
+ */
1190
+ public function getPageInfo()
1191
+ {
1192
+ $controllername = Mage::app()->getRequest()->getControllerName();
1193
+ $moduleName = Mage::app()->getRequest()->getModuleName();
1194
+
1195
+ if ($moduleName == 'cms') {
1196
+ $data = $this->getPageVisitData();
1197
+ } elseif ($controllername == 'category') {
1198
+ $data = $this->getCategoryViewData();
1199
+ } elseif ($controllername == 'product') {
1200
+ $data = $this->getProductViewData();
1201
+ }
1202
+ $data['index_name'] = $this->getApiIndex();
1203
+
1204
+ return $data;
1205
+ }
1206
+
1207
+ /**
1208
+ * Get the api url for static pages
1209
+ *
1210
+ * @return string
1211
+ */
1212
+ public function getApiUrl()
1213
+ {
1214
+ $controllername = Mage::app()->getRequest()->getControllerName();
1215
+ $moduleName = Mage::app()->getRequest()->getModuleName();
1216
+ $endPointUrl = '';
1217
+
1218
+ if ($moduleName == 'cms') {
1219
+ $type = 'page-visit';
1220
+ $endPointUrl = $this->getHostname() . $type . '?api_token=' . $this->getApiToken();
1221
+ } elseif ($controllername == 'category') {
1222
+ $type = 'category-view';
1223
+ $endPointUrl = $this->getHostname() . $type . '?api_token=' . $this->getApiToken();
1224
+ } elseif ($controllername == 'product') {
1225
+ $type = 'product-view';
1226
+ $endPointUrl = $this->getHostname() . $type . '?api_token=' . $this->getApiToken();
1227
+ }
1228
+
1229
+ return $endPointUrl;
1230
+ }
1231
+
1232
+ /**
1233
+ * Get the quote items
1234
+ *
1235
+ * @param $items
1236
+ * @param $orderExportApi
1237
+ * @return unknown
1238
+ */
1239
+ public function getQuoteItems($items, $orderExportApi = false)
1240
+ {
1241
+ $dataItems = array();
1242
+ try {
1243
+ foreach ($items as $item) {
1244
+ $dataItem = $this->getItemInfo($item);
1245
+ if ($customOptions = $this->getCustomOptionsInfo($item, $orderExportApi))
1246
+ $dataItem['attributes'] = $customOptions;
1247
+ $dataItems[$item->getId()] = $dataItem;
1248
+ }
1249
+ return $dataItems;
1250
+ } catch (Exception $e) {
1251
+ $this->debug('Error message '.$e->getMessage());
1252
+ return;
1253
+ }
1254
+ }
1255
+
1256
+ /**
1257
+ * Get the customer address data based on the action
1258
+ *
1259
+ * @param unknown $addressId
1260
+ * @return unknown
1261
+ */
1262
+ public function getCustomerAddressData($addressId)
1263
+ {
1264
+ $data = array();
1265
+ try {
1266
+ $address = Mage::getModel('customer/address');
1267
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
1268
+ $data['user_id'] = $customer->getId();
1269
+ $data['user_name'] = $customer->getName();
1270
+ $data['user_mail'] = $customer->getEmail();
1271
+ if ($addressId) {
1272
+ $existsAddress = $address->load($addressId);
1273
+ $data['address_id'] = $addressId;
1274
+ $data['old_address'] = $this->getExistingAddressData($existsAddress);
1275
+ }
1276
+ $data['new_address'] = $this->getNewAddressData();
1277
+ $data['timestamp'] = strtotime($this->date->date('Y-m-d'));
1278
+ $data['ip_address'] = Mage::helper('core/http')->getRemoteAddr();
1279
+ $data['user_agent'] = Mage::helper('core/http')->getHttpUserAgent();
1280
+ return $data;
1281
+ } catch (Exception $e) {
1282
+ $this->debug('Error message '.$e->getMessage());
1283
+ return;
1284
+ }
1285
+ }
1286
+
1287
+ /**
1288
+ * Get the customer address data based on the action
1289
+ *
1290
+ * @return multitype:unknown
1291
+ */
1292
+ public function getNewAddressData()
1293
+ {
1294
+ $request = Mage::app()->getRequest();
1295
+ $addressData = array();
1296
+ try {
1297
+ $addressData['firstname'] = $request->getParam('firstname');
1298
+ $addressData['lastname'] = $request->getParam('lastname');
1299
+ $addressData['company'] = $request->getParam('company');
1300
+ $addressData['street'] = implode('', $request->getParam('street'));
1301
+ $addressData['city'] = $request->getParam('city');
1302
+ $addressData['region_id'] = $request->getParam('region_id');
1303
+ $addressData['region'] = $request->getParam('region');
1304
+ $addressData['postcode'] = $request->getParam('postcode');
1305
+ $addressData['country_id'] = $request->getParam('country_id');
1306
+ $addressData['telephone'] = $request->getParam('telephone');
1307
+ return $addressData;
1308
+ } catch (Exception $e) {
1309
+ $this->debug('Error message '.$e->getMessage());
1310
+ return;
1311
+ }
1312
+ }
1313
+
1314
+ /**
1315
+ * Get the customer existing address data
1316
+ *
1317
+ * @return multitype:unknown
1318
+ */
1319
+ public function getExistingAddressData($existsAddress)
1320
+ {
1321
+ $addressData = array();
1322
+ try {
1323
+ $addressData['firstname'] = $existsAddress->getFirstname();
1324
+ $addressData['lastname'] = $existsAddress->getLastname();
1325
+ $addressData['company'] = $existsAddress->getCompany();
1326
+ $addressData['street'] = $existsAddress->getStreet();
1327
+ $addressData['city'] = $existsAddress->getCity();
1328
+ $addressData['region_id'] = $existsAddress->getRegionId();
1329
+ $addressData['region'] = $existsAddress->getRegion();
1330
+ $addressData['postcode'] = $existsAddress->getPostcode();
1331
+ $addressData['country_id'] = $existsAddress->getCountryId();
1332
+ $addressData['telephone'] = $existsAddress->getTelephone();
1333
+ return $addressData;
1334
+ } catch (Exception $e) {
1335
+ $this->debug('Error message '.$e->getMessage());
1336
+ return;
1337
+ }
1338
+ }
1339
+
1340
+ /**
1341
+ * Get the targetbay review count and rating for product
1342
+ *
1343
+ * @return array
1344
+ */
1345
+ public function getRichSnippets()
1346
+ {
1347
+ $data = array();
1348
+ $responseData = '';
1349
+ $controllername = Mage::app()->getRequest()->getControllerName();
1350
+ $moduleName = Mage::app()->getRequest()->getModuleName();
1351
+ try {
1352
+ $type = self::RATINGS_STATS;
1353
+ $apiToken = '?api_token=' . $this->getApiToken();
1354
+ $feedUrl = $this->getHostname() . $type . $apiToken;
1355
+ $data['index_name'] = $this->getApiIndex();
1356
+ if($moduleName == 'catalog' && $controllername == 'product') {
1357
+ $productId = Mage::registry('product')->getId();
1358
+ $data['product_id'] = $productId;
1359
+ }
1360
+
1361
+ $jsondata = json_encode($data);
1362
+ $response = $this->postPageInfo($feedUrl, $jsondata);
1363
+
1364
+ $body = json_decode($response);
1365
+ if(!empty($body)) {
1366
+ $averageScore = $body->reviews_average;
1367
+ $reviewsCount = $body->reviews_count;
1368
+ $reviewsDetails = $body->reviews;
1369
+ $responseData = array( "average_score" => $averageScore, "reviews_count" => $reviewsCount, "reviews" => $reviewsDetails);
1370
+ return $responseData;
1371
+ }
1372
+ } catch(Exception $e) {
1373
+ $this->debug('Error message '.$e->getMessage());
1374
+ return;
1375
+ }
1376
+ }
1377
+
1378
+ /**
1379
+ * Get the targetbay review count and dynamic ids
1380
+ *
1381
+ * @return array
1382
+ */
1383
+ public function getTargetbayReviewId()
1384
+ {
1385
+ $itemRefData = array();
1386
+ $itemRef = '';
1387
+ try {
1388
+ $trackingSnippet = $this->getRichSnippets();
1389
+ if($trackingSnippet['reviews_count'] > 0) {
1390
+ foreach($trackingSnippet['reviews'] as $key => $aggregateReviewDetails) {
1391
+ $itemRefData[]= 'tb-review-'.$key;
1392
+ }
1393
+ $itemRef = implode(' ', $itemRefData);
1394
+ }
1395
+ return $itemRef;
1396
+ } catch(Exception $e) {
1397
+ $this->debug('Error message '.$e->getMessage());
1398
+ return;
1399
+ }
1400
+ }
1401
+
1402
+ /**
1403
+ * Get the targetbay review count and rating for product
1404
+ *
1405
+ * @return array
1406
+ */
1407
+ public function getSiteReviewSnippets()
1408
+ {
1409
+ $data = array();
1410
+ $responseData = '';
1411
+ try {
1412
+ $type = self::RATINGS_STATS;
1413
+ $apiToken = '?api_token=' . $this->getApiToken();
1414
+ $feedUrl = $this->getHostname() . $type . $apiToken;
1415
+ $data['index_name'] = $this->getApiIndex();
1416
+
1417
+ $jsondata = json_encode($data);
1418
+ $response = $this->postPageInfo($feedUrl, $jsondata);
1419
+
1420
+ $body = json_decode($response);
1421
+ if(!empty($body)) {
1422
+ $averageScore = $body->reviews_average;
1423
+ $reviewsCount = $body->reviews_count;
1424
+ $reviewsDetails = $body->reviews;
1425
+ $responseData = array( "average_score" => $averageScore, "reviews_count" => $reviewsCount, "reviews" => $reviewsDetails);
1426
+ return $responseData;
1427
+ }
1428
+ } catch(Exception $e) {
1429
+ $this->debug('Error message '.$e->getMessage());
1430
+ return;
1431
+ }
1432
+ }
1433
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Cartitem.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Cartitem extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Cartitem/Rest/Admin/V1.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Cartitem_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Cartitem {
8
+
9
+ /**
10
+ * Retrieve cart items
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $cartItems = $cartItemData = array();
16
+ $quoteCollection = $this->getQuoteCollectionQuery();
17
+ $cartItems = array();
18
+ foreach ($quoteCollection as $id => $quoteInfo) {
19
+ $quoteId = $quoteInfo['entity_id'];
20
+ $quote = Mage::getModel('sales/quote')->setId($quoteId);
21
+ $items = $quote->getAllVisibleItems();
22
+ if(count($items) > 0) {
23
+ $cartItems[$id]['entity_id'] = $quoteInfo['entity_id'];
24
+ $cartItems[$id]['customer_id'] = $quoteInfo['customer_id'];
25
+ $cartItems[$id]['customer_email'] = $quoteInfo['customer_email'];
26
+ $cartItems[$id]['abandonded_at'] = $quoteInfo['updated_at'];
27
+ $cartItems[$id]['cart_items'] = Mage::helper ( 'tracking' )->getQuoteItems ( $items);
28
+ }
29
+ }
30
+
31
+ return $cartItems;
32
+ }
33
+
34
+ public function getQuoteCollectionQuery() {
35
+
36
+ $page_num = Mage::app()->getRequest()->getParam('page');
37
+ $limit = Mage::app()->getRequest()->getParam('limit');
38
+ $start = 1;$offset = 100;
39
+
40
+ $page_num = ($page_num) ? $page_num : $start;
41
+ $limit = ($limit) ? $limit : $offset;
42
+
43
+ $quoteTable = Mage::getSingleton('core/resource')->getTableName('sales/quote_item');
44
+ $collection = Mage::getResourceModel ( 'sales/quote_collection' )
45
+ ->addFieldToSelect(array(
46
+ 'customer_id',
47
+ 'customer_firstname',
48
+ 'customer_lastname',
49
+ 'customer_email',
50
+ 'updated_at'))
51
+ ->addFieldToFilter('customer_email', array('neq' => ''))
52
+ ->addFieldToFilter('customer_id', array('neq' => ''));
53
+ ;
54
+ $collection->getSelect()->join(array('Q2'=> $quoteTable), '`main_table`.`entity_id` = `Q2`.`quote_id`', array('*'))->group('Q2.quote_id');
55
+
56
+ $collection->getSelect()->limit($limit, $page_num);
57
+ return $collection;
58
+ }
59
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Cartitem/Rest/Guest/V1.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Cartitem_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Cartitem {
8
+
9
+ /**
10
+ * Retrieve cart items
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $cartItems = $cartItemData = array();
16
+ $quoteCollection = $this->getQuoteCollectionQuery();
17
+ $cartItems = array();
18
+ foreach ($quoteCollection as $id => $quoteInfo) {
19
+ $quoteId = $quoteInfo['entity_id'];
20
+ $quote = Mage::getModel('sales/quote')->setId($quoteId);
21
+ $items = $quote->getAllVisibleItems();
22
+ if(count($items) > 0) {
23
+ $cartItems[$id]['entity_id'] = $quoteInfo['entity_id'];
24
+ $cartItems[$id]['customer_id'] = $quoteInfo['customer_id'];
25
+ $cartItems[$id]['customer_email'] = $quoteInfo['customer_email'];
26
+ $cartItems[$id]['abandonded_at'] = $quoteInfo['updated_at'];
27
+ $cartItems[$id]['cart_items'] = Mage::helper ( 'tracking' )->getQuoteItems ( $items);
28
+ }
29
+ }
30
+
31
+ return $cartItems;
32
+ }
33
+
34
+ public function getQuoteCollectionQuery() {
35
+
36
+ $page_num = Mage::app()->getRequest()->getParam('page');
37
+ $limit = Mage::app()->getRequest()->getParam('limit');
38
+ $start = 1;$offset = 100;
39
+
40
+ $page_num = ($page_num) ? $page_num : $start;
41
+
42
+ $limit = ($limit) ? $limit : $offset;
43
+
44
+ $quoteTable = Mage::getSingleton('core/resource')->getTableName('sales/quote_item');
45
+ $collection = Mage::getResourceModel ( 'sales/quote_collection' )
46
+ ->addFieldToSelect(array(
47
+ 'customer_id',
48
+ 'customer_firstname',
49
+ 'customer_lastname',
50
+ 'customer_email',
51
+ 'updated_at'))
52
+ ->addFieldToFilter('customer_email', array('neq' => ''))
53
+ ->addFieldToFilter('customer_id', array('neq' => ''));
54
+ ;
55
+ $collection->getSelect()->join(array('Q2'=> $quoteTable), '`main_table`.`entity_id` = `Q2`.`quote_id`', array('*'))->group('Q2.quote_id');
56
+
57
+ $collection->getSelect()->limit($limit, $page_num);
58
+ return $collection;
59
+ }
60
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Category.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Category extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Category/Rest/Admin/V1.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Category_Rest_Admin_V1 extends Mage_Api2_Model_Resource {
8
+
9
+ /**
10
+ * Retrieve list of categories
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $model = Mage::getModel('catalog/category');
16
+ $model->setStoreId($this->_getStore()->getId());
17
+ $collection = $model->getCollection()
18
+ ->addAttributeToSelect(array_keys(
19
+ $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ)
20
+ ));
21
+ $this->_applyCollectionModifiers($collection);
22
+ $categoryData = array();
23
+
24
+ foreach ( $collection as $category ) {
25
+ $categoryData[$category->getId()] = $category->toArray();
26
+ $categoryDetail = Mage::getModel('catalog/category')->load($category->getId());
27
+ $storeIds = $categoryDetail->getStoreIds();
28
+ $categoryData[$category->getId()]['store_id'] = $storeIds;
29
+ $categoryIds = $categoryDetail->getPathIds();
30
+ $storesDetail = Mage::getModel('core/store')->getCollection()->loadByCategoryIds($categoryIds);
31
+ $websiteIds = array_unique($storesDetail->getColumnValues('website_id'));
32
+ $categoryData[$category->getId()]['website_id'] = $websiteIds;
33
+ }
34
+ return $categoryData;
35
+ }
36
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Category/Rest/Guest/V1.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Category_Rest_Guest_V1 extends Mage_Api2_Model_Resource {
8
+
9
+ /**
10
+ * Retrieve list of categories
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $model = Mage::getModel('catalog/category');
16
+ $model->setStoreId($this->_getStore()->getId());
17
+ $collection = $model->getCollection()
18
+ ->addAttributeToSelect(array_keys(
19
+ $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ)
20
+ ));
21
+ $this->_applyCollectionModifiers($collection);
22
+ $categoryData = array();
23
+
24
+ foreach ( $collection as $category ) {
25
+ $categoryData[$category->getId()] = $category->toArray();
26
+ $categoryDetail = Mage::getModel('catalog/category')->load($category->getId());
27
+ $storeIds = $categoryDetail->getStoreIds();
28
+ $categoryData[$category->getId()]['store_id'] = $storeIds;
29
+ $categoryIds = $categoryDetail->getPathIds();
30
+ $storesDetail = Mage::getModel('core/store')->getCollection()->loadByCategoryIds($categoryIds);
31
+ $websiteIds = array_unique($storesDetail->getColumnValues('website_id'));
32
+ $categoryData[$category->getId()]['website_id'] = $websiteIds;
33
+ }
34
+ return $categoryData;
35
+ }
36
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Createsubscription.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Createsubscription extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Createsubscription/Rest/Admin/V1.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Createsubscription_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Createsubscription {
8
+
9
+ /**
10
+ * Get the newsletter subscription
11
+ *
12
+ * @param array $data
13
+ * @see Mage_Api2_Model_Resource::_create()
14
+ */
15
+ public function _create(array $data) {
16
+ $session = Mage::getSingleton('core/session');
17
+ $customerSession = Mage::getSingleton('customer/session');
18
+
19
+ if (Mage::app()->getRequest()->getParam('email')) {
20
+
21
+ $email = (string) Mage::app()->getRequest()->getParam('email');
22
+ $message = array();
23
+ try {
24
+ if (!Zend_Validate::is($email, 'EmailAddress')) {
25
+ return 'Please enter a valid email address.';
26
+ }
27
+
28
+ if (Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_ALLOW_GUEST_SUBSCRIBE_FLAG) != 1 &&
29
+ !$customerSession->isLoggedIn()) {
30
+ return 'Sorry, but administrator denied subscription for guests. Please register.';
31
+ }
32
+
33
+ $ownerId = Mage::getModel('newsletter/subscriber')
34
+ ->loadByEmail($email)
35
+ ->getId();
36
+ if ($ownerId !== null && $ownerId != $customerSession->getId()) {
37
+ return 'This email address is already exists.';
38
+ }
39
+
40
+ $status = Mage::getModel('newsletter/subscriber')->subscribe($email);
41
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
42
+ return 'Confirmation request has been sent.';
43
+ }
44
+ else {
45
+ return 'Thank you for your subscription.';
46
+ }
47
+ } catch (\Exception $e) {
48
+ Mage::helper('tracking')->debug($e->getMessage());
49
+ }
50
+ } else {
51
+ return 'Please enter a valid email address.';
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Get the newsletter subscription
57
+ *
58
+ * @return array
59
+ */
60
+ public function _retrieveCollection() {
61
+ $session = Mage::getSingleton('core/session');
62
+ $customerSession = Mage::getSingleton('customer/session');
63
+
64
+ if (Mage::app()->getRequest()->getParam('email')) {
65
+
66
+ $email = (string) Mage::app()->getRequest()->getParam('email');
67
+ $message = array();
68
+ try {
69
+ if (!Zend_Validate::is($email, 'EmailAddress')) {
70
+ return 'Please enter a valid email address.';
71
+ }
72
+
73
+ if (Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_ALLOW_GUEST_SUBSCRIBE_FLAG) != 1 &&
74
+ !$customerSession->isLoggedIn()) {
75
+ return 'Sorry, but administrator denied subscription for guests. Please register.';
76
+ }
77
+
78
+ $ownerId = Mage::getModel('newsletter/subscriber')
79
+ ->loadByEmail($email)
80
+ ->getId();
81
+ if ($ownerId !== null && $ownerId != $customerSession->getId()) {
82
+ return 'This email address is already exists.';
83
+ }
84
+
85
+ $status = Mage::getModel('newsletter/subscriber')->subscribe($email);
86
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
87
+ return 'Confirmation request has been sent.';
88
+ }
89
+ else {
90
+ return 'Thank you for your subscription.';
91
+ }
92
+ } catch (\Exception $e) {
93
+ Mage::helper('tracking')->debug($e->getMessage());
94
+ }
95
+ } else {
96
+ return 'Please enter a valid email address.';
97
+ }
98
+ }
99
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Createsubscription/Rest/Guest/V1.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Createsubscription_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Createsubscription {
8
+
9
+ /**
10
+ * Get the newsletter subscription
11
+ *
12
+ * @param array $data
13
+ * @see Mage_Api2_Model_Resource::_create()
14
+ */
15
+ public function _create(array $data) {
16
+ $session = Mage::getSingleton('core/session');
17
+ $customerSession = Mage::getSingleton('customer/session');
18
+
19
+ if (Mage::app()->getRequest()->getParam('email')) {
20
+
21
+ $email = (string) Mage::app()->getRequest()->getParam('email');
22
+ $message = array();
23
+ try {
24
+ if (!Zend_Validate::is($email, 'EmailAddress')) {
25
+ return 'Please enter a valid email address.';
26
+ }
27
+
28
+ if (Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_ALLOW_GUEST_SUBSCRIBE_FLAG) != 1 &&
29
+ !$customerSession->isLoggedIn()) {
30
+ return 'Sorry, but administrator denied subscription for guests. Please register.';
31
+ }
32
+
33
+ $ownerId = Mage::getModel('newsletter/subscriber')
34
+ ->loadByEmail($email)
35
+ ->getId();
36
+ if ($ownerId !== null && $ownerId != $customerSession->getId()) {
37
+ return 'This email address is already exists.';
38
+ }
39
+
40
+ $status = Mage::getModel('newsletter/subscriber')->subscribe($email);
41
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
42
+ return 'Confirmation request has been sent.';
43
+ }
44
+ else {
45
+ return 'Thank you for your subscription.';
46
+ }
47
+ } catch (\Exception $e) {
48
+ Mage::helper('tracking')->debug($e->getMessage());
49
+ }
50
+ } else {
51
+ return 'Please enter a valid email address.';
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Get the newsletter subscription
57
+ *
58
+ * @return array
59
+ */
60
+ public function _retrieveCollection() {
61
+ $session = Mage::getSingleton('core/session');
62
+ $customerSession = Mage::getSingleton('customer/session');
63
+
64
+ if (Mage::app()->getRequest()->getParam('email')) {
65
+
66
+ $email = (string) Mage::app()->getRequest()->getParam('email');
67
+ $message = array();
68
+ try {
69
+ if (!Zend_Validate::is($email, 'EmailAddress')) {
70
+ return 'Please enter a valid email address.';
71
+ }
72
+
73
+ if (Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_ALLOW_GUEST_SUBSCRIBE_FLAG) != 1 &&
74
+ !$customerSession->isLoggedIn()) {
75
+ return 'Sorry, but administrator denied subscription for guests. Please register.';
76
+ }
77
+
78
+ $ownerId = Mage::getModel('newsletter/subscriber')
79
+ ->loadByEmail($email)
80
+ ->getId();
81
+ if ($ownerId !== null && $ownerId != $customerSession->getId()) {
82
+ return 'This email address is already exists.';
83
+ }
84
+
85
+ $status = Mage::getModel('newsletter/subscriber')->subscribe($email);
86
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
87
+ return 'Confirmation request has been sent.';
88
+ }
89
+ else {
90
+ return 'Thank you for your subscription.';
91
+ }
92
+ } catch (\Exception $e) {
93
+ Mage::helper('tracking')->debug($e->getMessage());
94
+ }
95
+ } else {
96
+ return 'Please enter a valid email address.';
97
+ }
98
+ }
99
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Customer.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Customer extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Customer/Rest/Admin/V1.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Customer_Rest_Admin_V1 extends Mage_Customer_Model_Api2_Customer {
8
+
9
+ /**
10
+ * Retrieve list of categories
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $page = Mage::app()->getRequest()->getParam('page');
16
+ $limit = Mage::app()->getRequest()->getParam('limit');
17
+
18
+ $pageSize = ($page) ? $page : '';
19
+ $pageLimit = ($limit) ? $limit : '';
20
+
21
+ $pageSize = (($page-1)*$limit);
22
+
23
+ $collection = Mage::getResourceModel('customer/customer_collection');
24
+ $collection->addAttributeToSelect(array_keys(
25
+ $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ)
26
+ ));
27
+ $collection->getSelect()->limit($pageLimit, $pageSize);
28
+ $customers = $collection->load()->toArray();
29
+ return $customers;
30
+ }
31
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Customer/Rest/Guest/V1.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Customer_Rest_Guest_V1 extends Mage_Customer_Model_Api2_Customer {
8
+
9
+ /**
10
+ * Retrieve list of categories
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $page = Mage::app()->getRequest()->getParam('page');
16
+ $limit = Mage::app()->getRequest()->getParam('limit');
17
+
18
+ $pageSize = ($page) ? $page : '';
19
+ $pageLimit = ($limit) ? $limit : '';
20
+
21
+ $pageSize = (($page-1)*$limit);
22
+
23
+ $collection = Mage::getResourceModel('customer/customer_collection');
24
+ $collection->addAttributeToSelect(array_keys(
25
+ $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ)
26
+ ));
27
+ $collection->getSelect()->limit($pageLimit, $pageSize);
28
+ $customers = $collection->load()->toArray();
29
+ return $customers;
30
+ }
31
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Orders/Rest/Admin/V1.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Orders_Rest_Admin_V1 extends Mage_Sales_Model_Api2_Order_Rest {
8
+
9
+ /**
10
+ * Get orders list
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $collection = $this->_getCollectionForRetrieve ();
16
+
17
+ if ($this->_isPaymentMethodAllowed ()) {
18
+ $this->_addPaymentMethodInfo ( $collection );
19
+ }
20
+ if ($this->_isGiftMessageAllowed ()) {
21
+ $this->_addGiftMessageInfo ( $collection );
22
+ }
23
+ $this->_addTaxInfo ( $collection );
24
+
25
+ $ordersData = array ();
26
+
27
+ foreach ( $collection->getItems () as $order ) {
28
+ $ordersData [$order->getId ()] = $order->toArray ();
29
+ $storeId = $order->getStoreId();
30
+ $ordersData [$order->getId ()]['store_id'] = $storeId;
31
+ $ordersData [$order->getId ()]['website_id'] = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
32
+ $ordersData [$order->getId ()] ['payment_method'] = Mage::helper ( 'tracking' )->getPaymentInfo ( $order->getId (), true );
33
+ $ordersData [$order->getId ()] [Targetbay_Tracking_Helper_Data::BILLING] = Mage::helper ( 'tracking' )->getAddressData ( $order, Targetbay_Tracking_Helper_Data::BILLING );
34
+ $ordersData [$order->getId ()] [Targetbay_Tracking_Helper_Data::SHIPPING] = Mage::helper ( 'tracking' )->getAddressData ( $order, Targetbay_Tracking_Helper_Data::SHIPPING );
35
+ $ordersData [$order->getId ()] ['cart_items'] = Mage::helper ( 'tracking' )->getOrderItemsInfo ( $order, true );
36
+ }
37
+ return $ordersData;
38
+ }
39
+ }
40
+
app/code/community/Targetbay/Tracking/Model/Api2/Orders/Rest/Guest/V1.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Orders_Rest_Guest_V1 extends Mage_Sales_Model_Api2_Order_Rest {
8
+
9
+ /**
10
+ * Get orders list
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $collection = $this->_getCollectionForRetrieve ();
16
+
17
+ if ($this->_isPaymentMethodAllowed ()) {
18
+ $this->_addPaymentMethodInfo ( $collection );
19
+ }
20
+ if ($this->_isGiftMessageAllowed ()) {
21
+ $this->_addGiftMessageInfo ( $collection );
22
+ }
23
+ $this->_addTaxInfo ( $collection );
24
+
25
+ $ordersData = array ();
26
+
27
+ foreach ( $collection->getItems () as $order ) {
28
+ $ordersData [$order->getId ()] = $order->toArray ();
29
+ $storeId = $order->getStoreId();
30
+ $ordersData [$order->getId ()]['store_id'] = $storeId;
31
+ $ordersData [$order->getId ()]['website_id'] = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
32
+ $ordersData [$order->getId ()] ['payment_method'] = Mage::helper ( 'tracking' )->getPaymentInfo ( $order->getId (), true );
33
+ $ordersData [$order->getId ()] [Targetbay_Tracking_Helper_Data::BILLING] = Mage::helper ( 'tracking' )->getAddressData ( $order, Targetbay_Tracking_Helper_Data::BILLING );
34
+ $ordersData [$order->getId ()] [Targetbay_Tracking_Helper_Data::SHIPPING] = Mage::helper ( 'tracking' )->getAddressData ( $order, Targetbay_Tracking_Helper_Data::SHIPPING );
35
+ $ordersData [$order->getId ()] ['cart_items'] = Mage::helper ( 'tracking' )->getOrderItemsInfo ( $order, true );
36
+ }
37
+ return $ordersData;
38
+ }
39
+ }
40
+
app/code/community/Targetbay/Tracking/Model/Api2/Product/Rest/Admin/V1.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Product_Rest_Admin_V1 extends Mage_Catalog_Model_Api2_Product_Rest {
8
+
9
+ // Product type configurable.
10
+ CONST CONFIGURABLE_PRODUCT = 'configurable';
11
+ CONST BUNDLE_PRODUCT = 'bundle';
12
+
13
+ /**
14
+ * Retrieve list of products
15
+ *
16
+ * @return array
17
+ */
18
+ protected function _retrieveCollection() {
19
+ /**
20
+ *
21
+ * @var $collection Mage_Catalog_Model_Resource_Product_Collection
22
+ */
23
+ $collection = Mage::getResourceModel('catalog/product_collection');
24
+ $store = $this->_getStore();
25
+ $collection->setStoreId($store->getId());
26
+ $collection->addAttributeToSelect(array_keys($this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ)));
27
+ $collection->addStoreFilter($store->getId())->addPriceData($this->_getCustomerGroupId(), $store->getWebsiteId())->addAttributeToSelect(array_diff($availableAttributes, $entityOnlyAttributes))->addAttributeToFilter('visibility', array(
28
+ 'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
29
+ ))->addAttributeToFilter('status', array(
30
+ 'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
31
+ ));
32
+ $this->_applyCategoryFilter($collection);
33
+ $this->_applyCollectionModifiers( $collection);
34
+ $products = $collection->load()->toArray();
35
+
36
+ foreach($products as $id => $data) {
37
+ $product = Mage::getModel('catalog/product')->load($id);
38
+ $stockItem = Mage::getModel('cataloginventory/stock_item');
39
+ $stockItem->loadByProduct($product);
40
+ $products[$id]['qty'] = $stockItem->getQty();
41
+
42
+ /**
43
+ *
44
+ * @var $category Get product categories
45
+ */
46
+ $products[$id]['meta_keyword'] = (string) Mage::helper('tracking')->getProductCategory($product);
47
+ $products[$id]['category_id'] = (string) Mage::helper('tracking')->getProductCategory($product);
48
+ $products[$id]['related_product_id'] = implode(',', $product->getRelatedProductIds());
49
+ $products[$id]['upsell_product_id'] = implode(',', $product->getUpSellProductIds());
50
+ $products[$id]['crosssell_product_id'] = implode(',', $product->getCrossSellProducts());
51
+ $products[$id]['visibility'] = $product->getVisibility();
52
+ $products[$id]['status'] = $product->getStatus();
53
+ $products[$id]['website_id'] = $product->getWebsiteIds();
54
+ $products[$id]['store_id'] = $product->getStoreIds();
55
+ $products[$id]['price'] = Mage::helper('core')->currency($product->getPrice(), true, false);
56
+ $products[$id]['special_price'] = Mage::helper('core')->currency($product->getSpecialPrice(), true, false);
57
+ $products[$id]['image_url'] = (string) Mage::helper('catalog/image')->init($product, 'image');
58
+
59
+ $configOptions = array();
60
+ $customOptions = array();
61
+ $childProductData = array();
62
+
63
+ if($product->getTypeId() == self::CONFIGURABLE_PRODUCT) {
64
+ if($productAttributeOptions = Mage::getModel('catalog/product')->load($product->getId())->getTypeInstance (true)->getConfigurableAttributesAsArray($product)) {
65
+ $configOptions = Mage::helper('tracking')->productOptions($productAttributeOptions, 'label');
66
+ }
67
+
68
+ $childProducts = $product->getTypeInstance()->getUsedProductIds();
69
+ foreach($childProducts as $childProductId) {
70
+ $childProductDetails = Mage::getModel('catalog/product')->load($childProductId);
71
+ $childProductData[$childProductId] = Mage::helper('tracking')->getProductData($childProductDetails);
72
+ $childProductData[$childProductId]['parent_id'] = $product->getId();
73
+ }
74
+ $products[$id]['child_items'] = $childProductData;
75
+ $products[$id]['parent_id'] = $product->getId();
76
+ }
77
+
78
+ if($product->getTypeId() == self::BUNDLE_PRODUCT) {
79
+ $collection = $product->getTypeInstance(true)
80
+ ->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
81
+
82
+ foreach($collection as $item) {
83
+ $childProductId = $item->getId();
84
+ $childProductDetails = Mage::getModel('catalog/product')->load($item->getId());
85
+ $childProductData[$childProductId] = Mage::helper('tracking')->getProductData($childProductDetails);
86
+ $childProductData[$childProductId]['parent_id'] = $product->getId();
87
+ }
88
+ $products[$id]['child_items'] = $childProductData;
89
+ $products[$id]['parent_id'] = $product->getId();
90
+ }
91
+ s
92
+ if($custOptions = Mage::getModel('catalog/product')->load($product->getId())->getOptions()) {
93
+ $customOptions = Mage::helper('tracking')->productOptions($custOptions);
94
+ }
95
+ $options = array_merge($configOptions, $customOptions);
96
+
97
+ if (!empty($options))
98
+ $products[$id]['attributes'] = $options;
99
+ }
100
+
101
+ return $products;
102
+ }
103
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Product/Rest/Admin/V1.php~ ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Product_Rest_Admin_V1 extends Mage_Catalog_Model_Api2_Product_Rest {
8
+
9
+ // Product type configurable.
10
+ CONST CONFIGURABLE_PRODUCT = 'configurable';
11
+ CONST BUNDLE_PRODUCT = 'bundle';
12
+
13
+ /**
14
+ * Retrieve list of products
15
+ *
16
+ * @return array
17
+ */
18
+ protected function _retrieveCollection() {
19
+ /**
20
+ *
21
+ * @var $collection Mage_Catalog_Model_Resource_Product_Collection
22
+ */
23
+ $collection = Mage::getResourceModel('catalog/product_collection');
24
+ $store = $this->_getStore();
25
+ $collection->setStoreId($store->getId());
26
+ $collection->addAttributeToSelect(array_keys($this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ)));
27
+ $collection->addStoreFilter($store->getId())->addPriceData($this->_getCustomerGroupId(), $store->getWebsiteId())->addAttributeToSelect(array_diff($availableAttributes, $entityOnlyAttributes))->addAttributeToFilter('visibility', array(
28
+ 'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
29
+ ))->addAttributeToFilter('status', array(
30
+ 'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
31
+ ));
32
+ $this->_applyCategoryFilter($collection);
33
+ $this->_applyCollectionModifiers( $collection);
34
+ $products = $collection->load()->toArray();
35
+
36
+ foreach($products as $id => $data) {
37
+ $product = Mage::getModel('catalog/product')->load($id);
38
+ $stockItem = Mage::getModel('cataloginventory/stock_item');
39
+ $stockItem->loadByProduct($product);
40
+ $products[$id]['qty'] = $stockItem->getQty();
41
+
42
+ /**
43
+ *
44
+ * @var $category Get product categories
45
+ */
46
+ $products[$id]['meta_keyword'] = (string) Mage::helper('tracking')->getProductCategory($product);
47
+ $products[$id]['category_id'] = (string) Mage::helper('tracking')->getProductCategory($product);
48
+ $products[$id]['related_product_id'] = implode(',', $product->getRelatedProductIds());
49
+ $products[$id]['upsell_product_id'] = implode(',', $product->getUpSellProductIds());
50
+ $products[$id]['crosssell_product_id'] = implode(',', $product->getCrossSellProducts());
51
+ $products[$id]['visibility'] = $product->getVisibility();
52
+ $products[$id]['status'] = $product->getStatus();
53
+ $products[$id]['website_id'] = $product->getWebsiteIds();
54
+ $products[$id]['store_id'] = $product->getStoreIds();
55
+ $products[$id]['special_price'] = Mage::helper('core')->currency($product->getSpecialPrice(), true, false);
56
+ $products[$id]['image_url'] = (string) Mage::helper('catalog/image')->init($product, 'image');
57
+
58
+ $configOptions = array();
59
+ $customOptions = array();
60
+ $childProductData = array();
61
+
62
+ if($product->getTypeId() == self::CONFIGURABLE_PRODUCT) {
63
+ if($productAttributeOptions = Mage::getModel('catalog/product')->load($product->getId())->getTypeInstance (true)->getConfigurableAttributesAsArray($product)) {
64
+ $configOptions = Mage::helper('tracking')->productOptions($productAttributeOptions, 'label');
65
+ }
66
+
67
+ $childProducts = $product->getTypeInstance()->getUsedProductIds();
68
+ foreach($childProducts as $childProductId) {
69
+ $childProductDetails = Mage::getModel('catalog/product')->load($childProductId);
70
+ $childProductData[$childProductId] = Mage::helper('tracking')->getProductData($childProductDetails);
71
+ $childProductData[$childProductId]['parent_id'] = $product->getId();
72
+ }
73
+ $products[$id]['child_items'] = $childProductData;
74
+ $products[$id]['parent_id'] = $product->getId();
75
+ }
76
+
77
+ if($product->getTypeId() == self::BUNDLE_PRODUCT) {
78
+ $collection = $product->getTypeInstance(true)
79
+ ->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
80
+
81
+ foreach($collection as $item) {
82
+ $childProductId = $item->getId();
83
+ $childProductDetails = Mage::getModel('catalog/product')->load($item->getId());
84
+ $childProductData[$childProductId] = Mage::helper('tracking')->getProductData($childProductDetails);
85
+ $childProductData[$childProductId]['parent_id'] = $product->getId();
86
+ }
87
+ $products[$id]['child_items'] = $childProductData;
88
+ $products[$id]['parent_id'] = $product->getId();
89
+ }
90
+ s
91
+ if($custOptions = Mage::getModel('catalog/product')->load($product->getId())->getOptions()) {
92
+ $customOptions = Mage::helper('tracking')->productOptions($custOptions);
93
+ }
94
+ $options = array_merge($configOptions, $customOptions);
95
+
96
+ if (!empty($options))
97
+ $products[$id]['attributes'] = $options;
98
+ }
99
+
100
+ return $products;
101
+ }
102
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Product/Rest/Guest/V1.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Product_Rest_Guest_V1 extends Mage_Catalog_Model_Api2_Product_Rest {
8
+
9
+ // Product type configurable.
10
+ CONST CONFIGURABLE_PRODUCT = 'configurable';
11
+ CONST BUNDLE_PRODUCT = 'bundle';
12
+
13
+ /**
14
+ * Retrieve list of products
15
+ *
16
+ * @return array
17
+ */
18
+ protected function _retrieveCollection() {
19
+ /**
20
+ *
21
+ * @var $collection Mage_Catalog_Model_Resource_Product_Collection
22
+ */
23
+ $collection = Mage::getResourceModel('catalog/product_collection');
24
+ $store = $this->_getStore();
25
+ $entityOnlyAttributes = $this->getEntityOnlyAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ);
26
+ $availableAttributes = array_keys($this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ));
27
+
28
+ // available attributes not contain image attribute, but it needed for get image_url
29
+ $availableAttributes[] = 'image';
30
+ $collection->addStoreFilter($store->getId())->addPriceData($this->_getCustomerGroupId(), $store->getWebsiteId())->addAttributeToSelect(array_diff($availableAttributes, $entityOnlyAttributes))->addAttributeToFilter('visibility', array(
31
+ 'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
32
+ ))->addAttributeToFilter('status', array(
33
+ 'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
34
+ ));
35
+ $this->_applyCategoryFilter($collection);
36
+ $this->_applyCollectionModifiers($collection);
37
+ $products = $collection->load();
38
+
39
+ /**
40
+ *
41
+ * @var Mage_Catalog_Model_Product $product
42
+ */
43
+ foreach($products as $product) {
44
+ $this->_setProduct($product);
45
+ $this->_prepareProductForResponse($product);
46
+ }
47
+ return $products->toArray();
48
+ }
49
+
50
+ /**
51
+ * Add special fields to product get response
52
+ *
53
+ * @param Mage_Catalog_Model_Product $product
54
+ */
55
+ protected function _prepareProductForResponse(Mage_Catalog_Model_Product $product) {
56
+ /**
57
+ *
58
+ * @var $productHelper Mage_Catalog_Helper_Product
59
+ */
60
+ $productHelper = Mage::helper('catalog/product');
61
+ $productData = $product->getData();
62
+ $product->setWebsiteId($this->_getStore()->getWebsiteId());
63
+ // customer group is required in product for correct prices calculation
64
+ $product->setCustomerGroupId($this->_getCustomerGroupId());
65
+ // calculate prices
66
+ $finalPrice = $product->getFinalPrice();
67
+ $productData['regular_price_with_tax'] = $this->_applyTaxToPrice($product->getPrice(), true);
68
+ $productData['regular_price_without_tax'] = $this->_applyTaxToPrice($product->getPrice(), false);
69
+ $productData['final_price_with_tax'] = $this->_applyTaxToPrice($finalPrice, true);
70
+ $productData['final_price_without_tax'] = $this->_applyTaxToPrice($finalPrice, false);
71
+
72
+ $productData['is_saleable'] = $product->getIsSalable();
73
+ $productData['image_url'] = (string) Mage::helper('catalog/image')->init($product, 'image');
74
+ $productData['visibility'] = $product->getVisibility();
75
+ $productData['status'] = $product->getStatus();
76
+ $productData['website_id'] = $product->getWebsiteIds();
77
+ $productData['store_id'] = $product->getStoreIds();
78
+ $productData['url'] = $product->getUrlKey();
79
+ $productData['url_key'] = $product->getUrlKey();
80
+ $productData['special_price'] = Mage::helper('core')->currency($product->getSpecialPrice(), true, false);
81
+
82
+ /**
83
+ *
84
+ * @var $category Get product categories
85
+ */
86
+ $productData['meta_keyword'] = (string) Mage::helper('tracking')->getProductCategory($product);
87
+ $productData['category_id'] = (string) Mage::helper('tracking')->getProductCategory($product);
88
+ $productData['related_product_id'] = implode(',', $product->getRelatedProductIds());
89
+ $productData['upsell_product_id'] = implode(',', $product->getUpSellProductIds());
90
+ $productData['crosssell_product_id'] = implode(',', $product->getCrossSellProducts());
91
+
92
+ if($this->getActionType() == self::ACTION_TYPE_ENTITY) {
93
+ // define URLs
94
+ $productData['url'] = $productHelper->getProductUrl($product->getId());
95
+
96
+ /**
97
+ *
98
+ * @var $cartHelper Mage_Checkout_Helper_Cart
99
+ */
100
+ $cartHelper = Mage::helper('checkout/cart');
101
+ $productData['buy_now_url'] = $cartHelper->getAddUrl($product);
102
+
103
+ /**
104
+ *
105
+ * @var $stockItem Mage_CatalogInventory_Model_Stock_Item
106
+ */
107
+ $stockItem = $product->getStockItem();
108
+ if(!$stockItem) {
109
+ $stockItem = Mage::getModel('cataloginventory/stock_item');
110
+ $stockItem->loadByProduct($product);
111
+ }
112
+ $productData['is_in_stock'] = $stockItem->getIsInStock();
113
+
114
+ /**
115
+ *
116
+ * @var $reviewModel Mage_Review_Model_Review
117
+ */
118
+ $reviewModel = Mage::getModel('review/review');
119
+ $productData['total_reviews_count'] = $reviewModel->getTotalReviews($product->getId(), true, $this->_getStore()->getId());
120
+ $productData['tier_price'] = $this->_getTierPrice();
121
+ $productData['has_custom_options'] = count($product->getOptions()) > 0;
122
+ } else {
123
+ // remove tier price from response
124
+ $product->unsetData('tier_price');
125
+ unset($productData['tier_price']);
126
+ }
127
+
128
+ // Added the custom options and configurable products options
129
+ $configOptions = array();
130
+ $customOptions = array();
131
+ $childProductData = array();
132
+
133
+ if($product->getTypeId() == self::CONFIGURABLE_PRODUCT) {
134
+ if($productAttributeOptions = Mage::getModel('catalog/product')->load($product->getId())->getTypeInstance(true)->getConfigurableAttributesAsArray($product)) {
135
+ $configOptions = Mage::helper('tracking')->productOptions($productAttributeOptions, 'label');
136
+ }
137
+
138
+ $childProducts = $product->getTypeInstance()->getUsedProductIds();
139
+ foreach($childProducts as $childProductId) {
140
+ $childProductDetails = Mage::getModel('catalog/product')->load($childProductId);
141
+ $childProductData[$childProductId] = Mage::helper('tracking')->getProductData($childProductDetails);
142
+ $childProductData[$childProductId]['parent_id'] = $product->getId();
143
+ }
144
+ $productData['child_items'] = $childProductData;
145
+ $productData['parent_id'] = $product->getId();
146
+ }
147
+ if($product->getTypeId() == self::BUNDLE_PRODUCT) {
148
+ $collection = $product->getTypeInstance(true)
149
+ ->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
150
+
151
+ foreach($collection as $item) {
152
+ $childProductId = $item->getId();
153
+ $childProductDetails = Mage::getModel('catalog/product')->load($item->getId());
154
+ $childProductData[$childProductId] = Mage::helper('tracking')->getProductData($childProductDetails);
155
+ $childProductData[$childProductId]['parent_id'] = $product->getId();
156
+ }
157
+ $productData['child_items'] = $childProductData;
158
+ $productData['parent_id'] = $product->getId();
159
+ }
160
+ if($custOptions = Mage::getModel('catalog/product')->load($product->getId())->getOptions()) {
161
+ $customOptions = Mage::helper('tracking')->productOptions($custOptions);
162
+ }
163
+ $options = array_merge($configOptions, $customOptions);
164
+
165
+ if(!empty ($options)) {
166
+ $productData['attributes'] = $options;
167
+ }
168
+ $product->addData($productData);
169
+ }
170
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Review.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Review extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Review/Rest/Admin/V1.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Review_Rest_Admin_V1 extends Mage_Api2_Model_Resource {
8
+
9
+ /**
10
+ * Retrieve review
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+
16
+ $page_num = Mage::app()->getRequest()->getParam('page');
17
+ $limit = Mage::app()->getRequest()->getParam('limit');
18
+
19
+ $reviewCollection = Mage::getModel('review/review')->getResourceCollection()
20
+ ->setDateOrder()
21
+ ->addRateVotes()
22
+ ->load();
23
+ $reviewCollection->getSelect()->limit($limit, $page_num);
24
+
25
+ $review_data = array();
26
+ $review_datas = array();
27
+ $sku = '';
28
+ foreach($reviewCollection as $review)
29
+ {
30
+ $storeId = Mage::getModel('review/review')->load($review->getId())->getStoreId();
31
+ $product = Mage::getModel ( 'catalog/product' )->load($review->getEntityPkValue());
32
+ $sku = $product->getSku();
33
+
34
+ if($sku) {
35
+ $ratingCollection = Mage::getModel('rating/rating_option_vote')
36
+ ->getResourceCollection()
37
+ ->setReviewFilter($review->getId());
38
+
39
+
40
+ $rating_val = "";
41
+ $option = "";
42
+ $option_value = '';
43
+ foreach($ratingCollection as $rating)
44
+ {
45
+
46
+ $option = $rating->getOptionId();
47
+ $rating_val = $rating->getRatingId();
48
+
49
+ if(!empty($option_value) && $option_value != '')
50
+ $option_value = $option_value."@".$rating_val.":".$option;
51
+ else
52
+ $option_value = $rating_val.":".$option;
53
+
54
+ }
55
+
56
+ $review_data['entity_id'] = $review->getId();
57
+ $review_data['product_id'] = $review->getEntityPkValue();
58
+ $review_data['sku'] = $sku;
59
+ $review_data['title'] = $review->getTitle();
60
+ $review_data['detail'] = $review->getDetail();
61
+ $review_data['nickname'] = $review->getNickname();
62
+ $review_data['store_id'] = $storeId;
63
+ $review_data['website_id'] = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
64
+ $review_data['customer_id'] = $review->getCustomer_id();
65
+ $review_data['option_id'] = $option_value;
66
+ $review_data['created_at'] = Mage::helper('core')->formatDate($review->getCreated_at(), 'long');
67
+ $review_data['status_id'] = $review->getStatus_id();
68
+ $review_datas[$review->getId()][] = $review_data;
69
+ }
70
+ }
71
+ return $review_datas;
72
+ }
73
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Review/Rest/Guest/V1.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Review_Rest_Guest_V1 extends Mage_Api2_Model_Resource {
8
+
9
+ /**
10
+ * Retrieve review
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+
16
+ $page_num = Mage::app()->getRequest()->getParam('page');
17
+ $limit = Mage::app()->getRequest()->getParam('limit');
18
+
19
+ $reviewCollection = Mage::getModel('review/review')->getResourceCollection()
20
+ ->setDateOrder()
21
+ ->addRateVotes()
22
+ ->load();
23
+ $reviewCollection->getSelect()->limit($limit, $page_num);
24
+
25
+ $review_data = array();
26
+ $review_datas = array();
27
+ $sku = '';
28
+ foreach($reviewCollection as $review)
29
+ {
30
+ $storeId = Mage::getModel('review/review')->load($review->getId())->getStoreId();
31
+ $product = Mage::getModel ( 'catalog/product' )->load($review->getEntityPkValue());
32
+ $sku = $product->getSku();
33
+
34
+ if($sku) {
35
+ $ratingCollection = Mage::getModel('rating/rating_option_vote')
36
+ ->getResourceCollection()
37
+ ->setReviewFilter($review->getId());
38
+
39
+
40
+ $rating_val = "";
41
+ $option = "";
42
+ $option_value = '';
43
+ foreach($ratingCollection as $rating)
44
+ {
45
+
46
+ $option = $rating->getOptionId();
47
+ $rating_val = $rating->getRatingId();
48
+
49
+ if(!empty($option_value) && $option_value != '')
50
+ $option_value = $option_value."@".$rating_val.":".$option;
51
+ else
52
+ $option_value = $rating_val.":".$option;
53
+
54
+ }
55
+ $review_data['entity_id'] = $review->getId();
56
+ $review_data['product_id'] = $review->getEntityPkValue();
57
+ $review_data['sku'] = $sku;
58
+ $review_data['title'] = $review->getTitle();
59
+ $review_data['detail'] = $review->getDetail();
60
+ $review_data['nickname'] = $review->getNickname();
61
+ $review_data['store_id'] = $storeId;
62
+ $review_data['website_id'] = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
63
+ $review_data['customer_id'] = $review->getCustomer_id();
64
+ $review_data['option_id'] = $option_value;
65
+ $review_data['created_at'] = Mage::helper('core')->formatDate($review->getCreated_at(), 'long');
66
+ $review_data['status_id'] = $review->getStatus_id();
67
+ $review_datas[$review->getId()][] = $review_data;
68
+ }
69
+ }
70
+
71
+ return $review_datas;
72
+ }
73
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Shipment.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Shipment extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Shipment/Rest/Admin/V1.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Shipment_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Shipment {
8
+
9
+ /**
10
+ * Get orders list
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $collection = Mage::getModel('sales/order_shipment')->getCollection();
16
+ $collection->addAttributeToFilter('created_at', array(
17
+ 'gt' => new Zend_Db_Expr('SUBDATE(CURRENT_TIMESTAMP, INTERVAL 6 HOUR)')));
18
+
19
+ $shipmentData = array ();
20
+ $params['shipment'] = true;
21
+ foreach ($collection->getItems() as $order) {
22
+ //$shipmentData [$order->getId()] = $order->toArray();
23
+ $orderId = $order->getOrderId();
24
+ $orderInfo = Mage::getModel('sales/order')->load($orderId);
25
+ $storeId = $orderInfo->getStoreId();
26
+ $shipmentData[$order->getId()] = Mage::helper('tracking')->getFullFillmentData($orderInfo, $params);
27
+ $shipmentData[$order->getId()]['store_id'] = $storeId;
28
+ $shipmentData[$order->getId()]['website_id'] = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
29
+ }
30
+ return $shipmentData;
31
+ }
32
+ }
33
+
app/code/community/Targetbay/Tracking/Model/Api2/Shipment/Rest/Guest/V1.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Shipment_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Shipment {
8
+
9
+ /**
10
+ * Get orders list
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $collection = Mage::getModel('sales/order_shipment')->getCollection();
16
+ $collection->addAttributeToFilter('created_at', array(
17
+ 'gt' => new Zend_Db_Expr('SUBDATE(CURRENT_TIMESTAMP, INTERVAL 6 HOUR)')));
18
+
19
+ $shipmentData = array ();
20
+ $params['shipment']=true;
21
+ foreach ($collection->getItems() as $order) {
22
+ //$shipmentData [$order->getId()] = $order->toArray();
23
+ $orderId = $order->getOrderId();
24
+ $orderInfo = Mage::getModel('sales/order')->load($orderId);
25
+ $storeId = $orderInfo->getStoreId();
26
+ $shipmentData[$order->getId()] = Mage::helper('tracking')->getFullFillmentData($orderInfo, $params);
27
+ $shipmentData[$order->getId()]['store_id'] = $storeId;
28
+ $shipmentData[$order->getId()]['website_id'] = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
29
+ }
30
+ return $shipmentData;
31
+ }
32
+ }
33
+
app/code/community/Targetbay/Tracking/Model/Api2/Stores.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Stores extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Stores/Rest/Admin/V1.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Stores_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Stores {
8
+
9
+ /**
10
+ * Retrieve stores
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $storeData = array();
16
+ $storeVal = array();
17
+ $storeCollection = Mage::getModel('core/store')->getCollection();
18
+ foreach($storeCollection as $store) {
19
+ $storeId = $store->getStoreId();
20
+ $storeVal['store_id'] = Mage::app()->getStore($storeId)->getId();
21
+ $storeVal['store_name'] = Mage::app()->getStore($storeId)->getName();
22
+ $storeVal['website_id'] = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
23
+ $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
24
+ $website = Mage::getModel('core/website')->load($websiteId);
25
+ $storeVal['website_name'] = $website->getName();
26
+ $storeData[] = $storeVal;
27
+ }
28
+ return $storeData;
29
+ }
30
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Stores/Rest/Guest/V1.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Stores_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Stores {
8
+
9
+ /**
10
+ * Retrieve wishlist items
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $storeData = array();
16
+ $storeVal = array();
17
+ $storeCollection = Mage::getModel('core/store')->getCollection();
18
+ foreach($storeCollection as $store) {
19
+ $storeId = $store->getStoreId();
20
+ $storeVal['store_id'] = Mage::app()->getStore($storeId)->getId();
21
+ $storeVal['store_name'] = Mage::app()->getStore($storeId)->getName();
22
+ $storeVal['website_id'] = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
23
+ $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
24
+ $website = Mage::getModel('core/website')->load($websiteId);
25
+ $storeVal['website_name'] = $website->getName();
26
+ $storeData[] = $storeVal;
27
+ }
28
+ return $storeData;
29
+ }
30
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Subscriber.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Subscriber extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Subscriber/Rest/Admin/V1.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Subscriber_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Subscriber {
8
+
9
+ /**
10
+ * Retrieve susbcriber list
11
+ *
12
+ * @return array
13
+ */
14
+ public function _retrieveCollection() {
15
+ $subscribers = array();
16
+ $subscriberData = array();
17
+
18
+ $page_num = Mage::app()->getRequest()->getParam('page');
19
+ $limit = Mage::app()->getRequest()->getParam('limit');
20
+
21
+ $subscriptionCollection = Mage::getModel('newsletter/subscriber')->getCollection();
22
+ $subscriptionCollection->getSelect()->limit($limit, $page_num);
23
+
24
+ foreach($subscriptionCollection as $subscriber) {
25
+ $subscribers['subscriber_id'] = $subscriber->getSubscriberId();
26
+ $subscribers['store_id'] = $subscriber->getStoreId();
27
+ $subscribers['customer_id'] = $subscriber->getCustomerId();
28
+ $subscribers['subscriber_email'] = $subscriber->getSubscriberEmail();
29
+ $subscribers['subscriber_status'] = $subscriber->getSubscriberStatus();
30
+ $subscriberData[] = $subscribers;
31
+ }
32
+ return $subscriberData;
33
+ }
34
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Subscriber/Rest/Guest/V1.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Subscriber_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Subscriber {
8
+
9
+ /**
10
+ * Retrieve susbcriber list
11
+ *
12
+ * @return array
13
+ */
14
+ public function _retrieveCollection() {
15
+ $subscribers = array();
16
+ $subscriberData = array();
17
+
18
+ $page_num = Mage::app()->getRequest()->getParam('page');
19
+ $limit = Mage::app()->getRequest()->getParam('limit');
20
+
21
+ $subscriptionCollection = Mage::getModel('newsletter/subscriber')->getCollection();
22
+ $subscriptionCollection->getSelect()->limit($limit, $page_num);
23
+
24
+ foreach($subscriptionCollection as $subscriber) {
25
+ $subscribers['subscriber_id'] = $subscriber->getSubscriberId();
26
+ $subscribers['store_id'] = $subscriber->getStoreId();
27
+ $subscribers['customer_id'] = $subscriber->getCustomerId();
28
+ $subscribers['subscriber_email'] = $subscriber->getSubscriberEmail();
29
+ $subscribers['subscriber_status'] = $subscriber->getSubscriberStatus();
30
+ $subscriberData[] = $subscribers;
31
+ }
32
+ return $subscriberData;
33
+ }
34
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcartiteminfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcartiteminfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcartiteminfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcartiteminfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalcartiteminfo {
8
+
9
+ /**
10
+ * Get the total count info of cartitem
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+
16
+ $quoteTable = Mage::getSingleton('core/resource')->getTableName('sales/quote_item');
17
+ $collection = Mage::getResourceModel( 'sales/quote_collection' )
18
+ ->addFieldToSelect(array(
19
+ 'customer_id',
20
+ 'customer_firstname',
21
+ 'customer_lastname',
22
+ 'customer_email',
23
+ 'updated_at'))
24
+ ->addFieldToFilter('customer_email', array('neq' => ''))
25
+ ->addFieldToFilter('customer_id', array('neq' => ''));
26
+ ;
27
+ $collection->getSelect()->join(array('Q2'=> $quoteTable), '`main_table`.`entity_id` = `Q2`.`quote_id`', array('*'))->group('Q2.quote_id');
28
+
29
+ $totals = array('total_cartitems' => count($collection));
30
+
31
+ return json_encode($totals);
32
+ }
33
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcartiteminfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcartiteminfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalcartiteminfo {
8
+
9
+ /**
10
+ * Get the total count info of cartitem
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+
16
+ $quoteTable = Mage::getSingleton('core/resource')->getTableName('sales/quote_item');
17
+ $collection = Mage::getResourceModel( 'sales/quote_collection' )
18
+ ->addFieldToSelect(array(
19
+ 'customer_id',
20
+ 'customer_firstname',
21
+ 'customer_lastname',
22
+ 'customer_email',
23
+ 'updated_at'))
24
+ ->addFieldToFilter('customer_email', array('neq' => ''))
25
+ ->addFieldToFilter('customer_id', array('neq' => ''));
26
+ ;
27
+ $collection->getSelect()->join(array('Q2'=> $quoteTable), '`main_table`.`entity_id` = `Q2`.`quote_id`', array('*'))->group('Q2.quote_id');
28
+
29
+ $totals = array('total_cartitems' => count($collection));
30
+
31
+ return json_encode($totals);
32
+ }
33
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcategoryinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcategoryinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcategoryinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcategoryinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalcategoryinfo {
8
+
9
+ /**
10
+ * Get the total count info of category
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_category' => Mage::getModel( 'catalog/category' )->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcategoryinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcategoryinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalcategoryinfo {
8
+
9
+ /**
10
+ * Get the total count info of category
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array(
16
+ 'total_category' => Mage::getModel( 'catalog/category' )->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcustomerinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcustomerinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcustomerinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcustomerinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalcustomerinfo {
8
+
9
+ /**
10
+ * Get the total count info of Customer
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_customers' => Mage::getModel('customer/customer')->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalcustomerinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalcustomerinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalcustomerinfo {
8
+
9
+ /**
10
+ * Get the total count info of Customer
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_customers' => Mage::getModel('customer/customer')->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalinfo {
8
+
9
+ /**
10
+ * Get the total count info of orders,products and customers
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_products' => Mage::getModel('catalog/product')->getCollection()->getSize(),
17
+ 'total_customers' => Mage::getModel('customer/customer')->getCollection()->getSize(),
18
+ 'total_orders' => Mage::getModel('sales/order')->getCollection()->getSize()
19
+ );
20
+
21
+ return json_encode($totals);
22
+ }
23
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalinfo {
8
+
9
+ /**
10
+ * Get the total count info of orders,products and customers
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_products' => Mage::getModel('catalog/product')->getCollection()->getSize(),
17
+ 'total_customers' => Mage::getModel('customer/customer')->getCollection()->getSize(),
18
+ 'total_orders' => Mage::getModel('sales/order')->getCollection()->getSize()
19
+ );
20
+
21
+ return json_encode($totals);
22
+ }
23
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalorderinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalorderinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalorderinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalorderinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalorderinfo {
8
+
9
+ /**
10
+ * Get the total count info of orders
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_orders' => Mage::getModel('sales/order')->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalorderinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalorderinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalorderinfo {
8
+
9
+ /**
10
+ * Get the total count info of orders
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_orders' => Mage::getModel('sales/order')->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalproductinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalproductinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalproductinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalproductinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalproductinfo {
8
+
9
+ /**
10
+ * Get the total count info of Products
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+
16
+ $collection = Mage::getResourceModel('catalog/product_collection');
17
+ $store = $this->_getStore();
18
+ $entityOnlyAttributes = $this->getEntityOnlyAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ);
19
+ $availableAttributes = array_keys($this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ));
20
+
21
+ // available attributes not contain image attribute, but it needed for get image_url
22
+ $availableAttributes[] = 'image';
23
+ $collection->addAttributeToSelect(array_diff($availableAttributes, $entityOnlyAttributes))->addAttributeToFilter('visibility', array(
24
+ 'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
25
+ ))->addAttributeToFilter('status', array(
26
+ 'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
27
+ ));
28
+
29
+ $totals = array (
30
+ 'total_products' => $collection->getSize()
31
+ );
32
+
33
+ return json_encode ( $totals );
34
+ }
35
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalproductinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalproductinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalproductinfo {
8
+
9
+ /**
10
+ * Get the total count info of Products
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+
16
+ $collection = Mage::getResourceModel('catalog/product_collection');
17
+ $store = $this->_getStore();
18
+ $entityOnlyAttributes = $this->getEntityOnlyAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ);
19
+ $availableAttributes = array_keys($this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ));
20
+
21
+ // available attributes not contain image attribute, but it needed for get image_url
22
+ $availableAttributes[] = 'image';
23
+ $collection->addAttributeToSelect(array_diff($availableAttributes, $entityOnlyAttributes))->addAttributeToFilter('visibility', array(
24
+ 'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
25
+ ))->addAttributeToFilter('status', array(
26
+ 'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
27
+ ));
28
+
29
+ $totals = array (
30
+ 'total_products' => $collection->getSize()
31
+ );
32
+
33
+ return json_encode ( $totals );
34
+ }
35
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalreviewinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalreviewinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalreviewinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalreviewinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalreviewinfo {
8
+
9
+ /**
10
+ * Get the total count of reviews
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_reviews' => Mage::getModel('review/review')->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalreviewinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalreviewinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalreviewinfo {
8
+
9
+ /**
10
+ * Get the total count of reviews
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array (
16
+ 'total_reviews' => Mage::getModel('review/review')->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalshipmentinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalshipmentinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalshipmentinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalshipmentinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalshipmentinfo {
8
+
9
+ /**
10
+ * Get the total count info of shipment orders
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+
16
+ $shipmentCollection = Mage::getModel('sales/order_shipment')->getCollection();
17
+ $shipmentCollection->addAttributeToFilter('created_at', array(
18
+ 'gt' => new Zend_Db_Expr('SUBDATE(CURRENT_TIMESTAMP, INTERVAL 6 HOUR)')));
19
+
20
+ $totals = array('total_shipped_orders' => count($shipmentCollection));
21
+
22
+ return json_encode($totals);
23
+ }
24
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalshipmentinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalshipmentinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalshipmentinfo {
8
+
9
+ /**
10
+ * Get the total count info of shipment orders
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+
16
+ $shipmentCollection = Mage::getModel('sales/order_shipment')->getCollection();
17
+ $shipmentCollection->addAttributeToFilter('created_at', array(
18
+ 'gt' => new Zend_Db_Expr('SUBDATE(CURRENT_TIMESTAMP, INTERVAL 6 HOUR)')));
19
+
20
+ $totals = array('total_shipped_orders' => count($shipmentCollection));
21
+
22
+ return json_encode($totals);
23
+ }
24
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalsubscriberinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalsubscriberinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalsubscriberinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalsubscriberinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalsubscriberinfo {
8
+
9
+ /**
10
+ * Get the total count info of subscriber
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array(
16
+ 'total_subscriber' => Mage::getModel('newsletter/subscriber')->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalsubscriberinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalsubscriberinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalsubscriberinfo {
8
+
9
+ /**
10
+ * Get the total count info of subscriber
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+ $totals = array(
16
+ 'total_subscriber' => Mage::getModel('newsletter/subscriber')->getCollection()->getSize()
17
+ );
18
+
19
+ return json_encode($totals);
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalwishlistinfo.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalwishlistinfo extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalwishlistinfo/Rest/Admin/V1.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalwishlistinfo_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Totalwishlistinfo {
8
+
9
+ /**
10
+ * Get the total count info of wishlist
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+
16
+ $wishlistCollection = Mage::getModel('wishlist/wishlist')->getCollection();
17
+ $i = 0; $count = '';
18
+
19
+ foreach($wishlistCollection as $id => $wishlist) {
20
+ $wishlistInfo = Mage::getModel('wishlist/wishlist')->loadByCustomer($wishlist->getCustomerId());
21
+ $wishlistItemCollection = $wishlistInfo->setStoreId(1)->getItemCollection();
22
+ if ($wishlistItemCollection->getSize() > 0) {
23
+ $count = $i+1;
24
+ $i++;
25
+ }
26
+ }
27
+
28
+ $totals = array (
29
+ 'total_wishlist' => $count
30
+ );
31
+
32
+ return json_encode($totals);
33
+ }
34
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Totalwishlistinfo/Rest/Guest/V1.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Totalwishlistinfo_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Totalwishlistinfo {
8
+
9
+ /**
10
+ * Get the total count info of wishlist
11
+ *
12
+ * @see Mage_Api2_Model_Resource::_retrieveCollection()
13
+ */
14
+ public function _retrieveCollection() {
15
+
16
+ $wishlistCollection = Mage::getModel('wishlist/wishlist')->getCollection();
17
+ $i = 0; $count = '';
18
+
19
+ foreach($wishlistCollection as $id => $wishlist) {
20
+ $wishlistInfo = Mage::getModel('wishlist/wishlist')->loadByCustomer($wishlist->getCustomerId());
21
+ $wishlistItemCollection = $wishlistInfo->setStoreId(1)->getItemCollection();
22
+ if ($wishlistItemCollection->getSize() > 0) {
23
+ $count = $i+1;
24
+ $i++;
25
+ }
26
+ }
27
+
28
+ $totals = array (
29
+ 'total_wishlist' => $count
30
+ );
31
+
32
+ return json_encode($totals);
33
+ }
34
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Updatesubscription.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Updatesubscription extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Updatesubscription/Rest/Admin/V1.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Targetbay_Tracking_Model_Api2_Updatesubscription_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Updatesubscription {
3
+
4
+ /**
5
+ * Get the newsletter subscription
6
+ *
7
+ * @param array $data
8
+ * @see Mage_Api2_Model_Resource::_create()
9
+ */
10
+ public function _create(array $data) {
11
+ $email = Mage::app()->getRequest()->getParam('email');
12
+ $status = Mage::app()->getRequest()->getParam('status');
13
+
14
+ if($email == '' || $status == '')
15
+ return false;
16
+
17
+ if ($email != '' && $status != '') {
18
+ try {
19
+ $subscriberData = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
20
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
21
+ $subscriberTable = $subscriberData->setSubscriberStatus($status)
22
+ ->save();
23
+ Mage::helper('newsletter')->sendConfirmationSuccessEmail();
24
+ return 'Thank you for your subscription.';
25
+ } else {
26
+ $subscriberTable = $subscriberData->setSubscriberStatus($status)
27
+ ->save();
28
+ Mage::helper('newsletter')->sendUnsubscriptionEmail();
29
+ return 'You have been unsubscribed';
30
+ }
31
+ } catch (Exception $e) {
32
+ Mage::helper('tracking')->debug($e->getMessage());
33
+ }
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Get the newsletter subscription
39
+ *
40
+ * @return array
41
+ */
42
+ public function _retrieveCollection() {
43
+ $email = Mage::app()->getRequest()->getParam('email');
44
+ $status = Mage::app()->getRequest()->getParam('status');
45
+
46
+ if($email == '' || $status == '')
47
+ return false;
48
+ if ($email != '' && $status != '') {
49
+ try {
50
+ $customerData = Mage::getModel('customer/customer')
51
+ ->setWebsiteId(1)
52
+ ->loadByEmail($email);
53
+
54
+ $newsletterCustomer = Mage::getModel('newsletter/subscriber')->loadByCustomer($customerData);
55
+ if($newsletterCustomer->getId()) {
56
+ $newsletterCustomer->setCustomerId($newsletterCustomer->getId());
57
+ $newsletterCustomer->setStatus($status);
58
+ $newsletterCustomer->save();
59
+ }
60
+
61
+ $subscriberData = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
62
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
63
+ $subscriberTable = $subscriberData->setSubscriberStatus($status)
64
+ ->save();
65
+ Mage::getModel('newsletter/subscriber')->sendConfirmationSuccessEmail();
66
+ return 'Thank you for your subscription.';
67
+ } else {
68
+ $subscriberTable = $subscriberData->setSubscriberStatus($status)
69
+ ->save();
70
+ Mage::getModel('newsletter/subscriber')->sendUnsubscriptionEmail();
71
+ return 'You have been unsubscribed';
72
+ }
73
+ } catch (Exception $e) {
74
+ Mage::helper('tracking')->debug($e->getMessage());
75
+ }
76
+ }
77
+ }
78
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Updatesubscription/Rest/Guest/V1.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Updatesubscription_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Updatesubscription {
8
+
9
+ /**
10
+ * Get the newsletter subscription
11
+ *
12
+ * @param array $data
13
+ * @see Mage_Api2_Model_Resource::_create()
14
+ */
15
+ public function _create(array $data) {
16
+ $email = Mage::app()->getRequest()->getParam('email');
17
+ $status = Mage::app()->getRequest()->getParam('status');
18
+
19
+ if($email == '' || $status == '')
20
+ return false;
21
+
22
+ if ($email != '' && $status != '') {
23
+ try {
24
+ $subscriberData = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
25
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
26
+ $subscriberTable = $subscriberData->setSubscriberStatus($status)
27
+ ->save();
28
+ Mage::helper('newsletter')->sendConfirmationSuccessEmail();
29
+ return 'Thank you for your subscription.';
30
+ } else {
31
+ $subscriberTable = $subscriberData->setSubscriberStatus($status)
32
+ ->save();
33
+ Mage::helper('newsletter')->sendUnsubscriptionEmail();
34
+ return 'You have been unsubscribed';
35
+ }
36
+ } catch (Exception $e) {
37
+ Mage::helper('tracking')->debug($e->getMessage());
38
+ }
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Get the newsletter subscription
44
+ *
45
+ * @return array
46
+ */
47
+ public function _retrieveCollection() {
48
+
49
+ $email = Mage::app()->getRequest()->getParam('email');
50
+ $status = Mage::app()->getRequest()->getParam('status');
51
+
52
+ if($email == '' || $status == '')
53
+ return false;
54
+
55
+ if ($email != '' && $status != '') {
56
+ try {
57
+ $customerData = Mage::getModel('customer/customer')
58
+ ->setWebsiteId(1)
59
+ ->loadByEmail($email);
60
+
61
+ $newsletterCustomer = Mage::getModel('newsletter/subscriber')->loadByCustomer($customerData);
62
+ if($newsletterCustomer->getId()) {
63
+ $newsletterCustomer->setCustomerId($newsletterCustomer->getId());
64
+ $newsletterCustomer->setStatus($status);
65
+ $newsletterCustomer->save();
66
+ }
67
+
68
+ $subscriberData = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
69
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
70
+ $subscriberTable = $subscriberData->setSubscriberStatus($status)
71
+ ->save();
72
+ Mage::getModel('newsletter/subscriber')->sendConfirmationSuccessEmail();
73
+ return 'Thank you for your subscription.';
74
+ } else {
75
+ $subscriberTable = $subscriberData->setSubscriberStatus($status)
76
+ ->save();
77
+ Mage::getModel('newsletter/subscriber')->sendUnsubscriptionEmail();
78
+ return 'You have been unsubscribed';
79
+ }
80
+ } catch (Exception $e) {
81
+ Mage::helper('tracking')->debug($e->getMessage());
82
+ }
83
+ }
84
+ }
85
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Wishlist.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Wishlist extends Mage_Api2_Model_Resource
8
+ {
9
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Wishlist/Rest/Admin/V1.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Wishlist_Rest_Admin_V1 extends Targetbay_Tracking_Model_Api2_Wishlist {
8
+
9
+ /**
10
+ * Retrieve wishlist items
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $customerId = '';
16
+ $wishlistData = array();
17
+ $wishlistCollection = Mage::getModel('wishlist/wishlist')->getCollection();
18
+ foreach($wishlistCollection as $id => $wishlist) {
19
+ $wishlistInfo = Mage::getModel('wishlist/wishlist')->loadByCustomer($wishlist->getCustomerId());
20
+ $wishlistItemCollection = $wishlistInfo->setStoreId(1)->getItemCollection();
21
+ if ($wishlistItemCollection->getSize() > 0) {
22
+ $wishlistData[$id]['wishlist_id'] = $wishlistInfo['wishlist_id'];
23
+ $wishlistData[$id]['customer_id'] = $wishlistInfo['customer_id'];
24
+ $wishlistData[$id]['updated_at'] = $wishlistInfo['updated_at'];
25
+ $wishlistData[$id]['item_details'] = Mage::helper ( 'tracking' )->getWishlistItemsInfo ( $wishlistInfo);
26
+ }
27
+ }
28
+ return $wishlistData;
29
+ }
30
+ }
app/code/community/Targetbay/Tracking/Model/Api2/Wishlist/Rest/Guest/V1.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Api2_Wishlist_Rest_Guest_V1 extends Targetbay_Tracking_Model_Api2_Wishlist {
8
+
9
+ /**
10
+ * Retrieve wishlist items
11
+ *
12
+ * @return array
13
+ */
14
+ protected function _retrieveCollection() {
15
+ $customerId = '';
16
+ $wishlistData = array();
17
+ $wishlistCollection = Mage::getModel('wishlist/wishlist')->getCollection();
18
+ foreach($wishlistCollection as $id => $wishlist) {
19
+ $wishlistInfo = Mage::getModel('wishlist/wishlist')->loadByCustomer($wishlist->getCustomerId());
20
+ $wishlistItemCollection = $wishlistInfo->setStoreId(1)->getItemCollection();
21
+ if ($wishlistItemCollection->getSize() > 0) {
22
+ $wishlistData[$id]['wishlist_id'] = $wishlistInfo['wishlist_id'];
23
+ $wishlistData[$id]['customer_id'] = $wishlistInfo['customer_id'];
24
+ $wishlistData[$id]['updated_at'] = $wishlistInfo['updated_at'];
25
+ $wishlistData[$id]['item_details'] = Mage::helper ( 'tracking' )->getWishlistItemsInfo ( $wishlistInfo);
26
+ }
27
+ }
28
+ return $wishlistData;
29
+ }
30
+ }
app/code/community/Targetbay/Tracking/Model/Customer.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Customer extends Mage_Customer_Model_Customer
8
+ {
9
+ /**#@+
10
+ * Configuration pathes for email templates and identities
11
+ */
12
+ const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template';
13
+ const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template';
14
+ const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template';
15
+ /**#@-*/
16
+
17
+ /**
18
+ * Send email with new account related information
19
+ *
20
+ * @param string $type
21
+ * @param string $backUrl
22
+ * @param string $storeId
23
+ * @throws Mage_Core_Exception
24
+ * @return Mage_Customer_Model_Customer
25
+ */
26
+ public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
27
+ {
28
+ $emailStatus = Mage::helper('tracking')->getEmailStatus();
29
+ if($emailStatus == 1)
30
+ return false;
31
+
32
+ $types = array(
33
+ 'registered' => self::XML_PATH_REGISTER_EMAIL_TEMPLATE, // welcome email, when confirmation is disabled
34
+ 'confirmed' => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE, // welcome email, when confirmation is enabled
35
+ 'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE, // email with confirmation link
36
+ );
37
+ if (!isset($types[$type])) {
38
+ Mage::throwException(Mage::helper('customer')->__('Wrong transactional account email type'));
39
+ }
40
+
41
+ if (!$storeId) {
42
+ $storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
43
+ }
44
+
45
+ $this->_sendEmailTemplate($types[$type], self::XML_PATH_REGISTER_EMAIL_IDENTITY,
46
+ array('customer' => $this, 'back_url' => $backUrl), $storeId);
47
+
48
+ return $this;
49
+ }
50
+ }
app/code/community/Targetbay/Tracking/Model/Observer.php ADDED
@@ -0,0 +1,976 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Observer
8
+ {
9
+ private $apiToken;
10
+ private $indexName;
11
+ private $targetbayHost;
12
+ private $helper;
13
+
14
+ /**
15
+ * Get the credentials from store configurations
16
+ */
17
+ public function __construct()
18
+ {
19
+ $this->helper = Mage::helper('tracking');
20
+ $this->apiToken = '?api_token=' . $this->helper->getApiToken();
21
+ $this->indexName = $this->helper->getApiIndex();
22
+ $this->targetbayHost = $this->helper->getHostname();
23
+
24
+ $sess = Mage::getSingleton('core/session')->getTrackingSessionId();
25
+ if (!$this->helper->cookie->get('trackingsession')) {
26
+ $visitor_data = Mage::getSingleton('core/session')->getVisitorData();
27
+ $trackingsession = $visitor_data['visitor_id'] . strtotime(date('Y-m-d H:i:s'));
28
+ Mage::getSingleton('core/session')->setTrackingSessionId($trackingsession);
29
+ }
30
+
31
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
32
+ Mage::getModel('core/cookie')->set('user_loggedin', true, null, null, null, null, false);
33
+ Mage::getModel('core/cookie')->set('afterlogin_session_id', Mage::getSingleton('core/session')->getCustomerSessionId(), null, null, null, null, false);
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Set the cookie values for user differentiate.
39
+ */
40
+ public function setCookieValues()
41
+ {
42
+ // For anonymous user
43
+ $customerName = Targetbay_Tracking_Helper_Data::ANONYMOUS_USER;
44
+ $customerEmail = Targetbay_Tracking_Helper_Data::ANONYMOUS_USER;
45
+ if (!$this->helper->cookie->get('trackingid')) {
46
+ $customerId = Mage::getSingleton('core/session')->getTrackingSessionId();
47
+ }
48
+
49
+ // for logged user
50
+ if (Mage::app()->isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) {
51
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
52
+ $customerName = $customer->getName();
53
+ $customerId = $customer->getId();
54
+ $customerEmail = $customer->getEmail();
55
+ }
56
+
57
+ // ToDo: Do we need this?
58
+ $trackingId = empty($customerId) ? '' : $this->helper->cookie->set('trackingid', $customerId, null, null, null, null, false);
59
+
60
+ $this->helper->cookie->set('trackingemail', $customerEmail, null, null, null, null, false);
61
+ $this->helper->cookie->set('trackingname', $customerName, null, null, null, null, false);
62
+
63
+ $quoteId = Mage::getSingleton('checkout/session')->getQuoteId() ? Mage::getSingleton('checkout/session')->getQuoteId() : '';
64
+ $this->helper->cookie->set('trackingorderid', $quoteId, null, null, null, null, false);
65
+
66
+ if (!$this->helper->cookie->get('trackingsession')) {
67
+ $this->helper->cookie->set('trackingsession', Mage::getSingleton('core/session')->getTrackingSessionId(), null, null, null, null, false);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Visiting page info
73
+ *
74
+ * @param Varien_Event_Observer $observer
75
+ *
76
+ * @return void
77
+ */
78
+ public function pushPageVisitData(Varien_Event_Observer $observer)
79
+ {
80
+ $request = Mage::app()->getRequest();
81
+
82
+ $currenturi = sprintf("%s/%s/%s", $request->getModuleName(), $request->getControllerName(), $request->getActionName());
83
+
84
+ $triggers = array(
85
+ 'checkout/onepage/savePayment',
86
+ 'checkout/onepage/saveOrder',
87
+ 'checkout/onepage/success',
88
+ 'onestepcheckout/index/saveAddressOnestepcheckout',
89
+ 'onestepcheckout/index/save_shipping',
90
+ 'onestepcheckout/index/is_valid_email'
91
+ );
92
+
93
+ if (in_array($currenturi, $triggers))
94
+ return false;
95
+
96
+ $this->setCookieValues();
97
+
98
+ // Page referrer Tracking
99
+ $this->pushReferralData();
100
+
101
+ if ($this->helper->eventAlreadyTracked($observer->getEvent()->getControllerAction()->getFullActionName())) {
102
+ return false;
103
+ }
104
+
105
+ // Set Token Values
106
+ if (isset($_GET['utm_source']) && !$this->helper->cookie->get('utm_source')) {
107
+ $this->helper->cookie->set('utm_source', $_GET['utm_source'], null, null, null, null, false);
108
+ }
109
+
110
+ if (isset($_GET['token']) && !$this->helper->cookie->get('utm_token')) {
111
+ $this->helper->cookie->set('utm_token', $_GET['token'], null, null, null, null, false);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Visiting page info
117
+ *
118
+ * @param Varien_Event_Observer $observer
119
+ *
120
+ * @return void
121
+ */
122
+ public function cmsPageVisit(Varien_Event_Observer $observer)
123
+ {
124
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::PAGE_VISIT)) {
125
+ return false;
126
+ }
127
+
128
+ // Set Token Values
129
+ if (isset($_GET['utm_source']) && !$this->helper->cookie->get('utm_source')) {
130
+ $this->helper->cookie->set('utm_source', $_GET['utm_source'], null, null, null, null, false);
131
+ }
132
+
133
+ if (isset($_GET['token']) && !$this->helper->cookie->get('utm_token')) {
134
+ $this->helper->cookie->set('utm_token', $_GET['token'], null, null, null, null, false);
135
+ }
136
+
137
+ $request = Mage::app()->getRequest();
138
+ $trackingType = $this->helper->getTrackingType();
139
+ $identifier = Mage::getSingleton('cms/page')->getIdentifier();
140
+ $moduleName = $request->getModuleName();
141
+
142
+ // Page Visit Tracking
143
+ $data = $this->helper->visitInfo();
144
+ if ($trackingType == 1 && ($request->getControllerName() == 'product' || $request->getControllerName() == 'category' || $moduleName == 'cms'))
145
+ return false;
146
+
147
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::PAGE_VISIT);
148
+ return;
149
+ }
150
+
151
+ /**
152
+ * Add to cart
153
+ *
154
+ * @param Varien_Event_Observer $observer
155
+ *
156
+ * @return void
157
+ */
158
+ public function pushAddToCart(Varien_Event_Observer $observer)
159
+ {
160
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::ADDTOCART)) {
161
+ return false;
162
+ }
163
+ Mage::getSingleton('checkout/session')->setTitle('Shopping cart');
164
+
165
+ //$item = $observer->getEvent()->getQuoteItem();
166
+ //if ($item->getParentItem())
167
+ //$item = $item->getParentItem();
168
+
169
+ $productInfo = $observer->getProduct();
170
+
171
+ $productEventInfo = $observer->getEvent()->getProduct();
172
+ $quote = Mage::getModel('checkout/cart')->getQuote();
173
+ $item = $quote->getItemByProduct( $productEventInfo );
174
+
175
+ if($productInfo->getData('type_id') == 'grouped') {
176
+ $productIds = Mage::app()->getRequest()->getParam('super_group');
177
+ $dataItem = array(); $productData= array();
178
+ foreach($productIds as $id => $qty) {
179
+ if($qty < 1)
180
+ continue;
181
+ $product = Mage::getModel('catalog/product')->load($id);
182
+ $productData['type'] = $product->getTypeId();
183
+ $productData['product_id'] = $id;
184
+ $productData['product_sku'] = $product->getSku();
185
+ $productData['product_name'] = addslashes($product->getName());
186
+ $productData['price'] = $product->getPrice()*$qty;
187
+ $productData['special_price'] = $product->getSpecialPrice();
188
+ $productData['productimg'] = $this->helper->getImageUrl($product, 'image');
189
+
190
+ $productData['category'] = $this->helper->getProductCategory($product);
191
+ $productData['category_name'] = $this->helper->getProductCategoryName($product);
192
+ $productData['quantity'] = $qty;
193
+ $productData['page_url'] = Mage::getUrl($product->getUrlPath());
194
+ $productData['attributes'] = '';
195
+ $dataItem[] = $productData;
196
+ }
197
+ $data = $this->helper->getCartInfo();
198
+ $data['product_type'] = $productInfo->getData('type_id');
199
+ $data['cart_item'] = $dataItem;
200
+ } else{
201
+ $data = array_merge($this->helper->getCartInfo(), $this->helper->getItemInfo($item, Targetbay_Tracking_Helper_Data::ADDTOCART));
202
+ $data['product_type'] = $item->getProductType();
203
+ $data['price'] = $item->getProduct()->getFinalPrice();
204
+ if ($customOptions = $this->helper->getCustomOptionsInfo($item, null)) {
205
+ $data['attributes'] = $customOptions;
206
+ }
207
+ }
208
+
209
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::ADDTOCART);
210
+
211
+ return;
212
+ }
213
+
214
+ /**
215
+ * Capture the Update cart event
216
+ *
217
+ * @param Varien_Event_Observer $observer
218
+ *
219
+ * @return void
220
+ */
221
+ public function pushUpdateCartData(Varien_Event_Observer $observer)
222
+ {
223
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::UPDATECART)) {
224
+ return false;
225
+ }
226
+ $items = $observer->getEvent()->getCart()->getQuote()->getAllVisibleItems();
227
+ $requestInfo = $observer->getEvent()->getInfo();
228
+ $data = $this->helper->getCartInfo();
229
+
230
+ foreach ($items as $item) {
231
+ $newQty = $requestInfo[$item->getId()]['qty'];
232
+ $oldQty = $item->getQty();
233
+ if ($newQty == 0 || ($newQty == $oldQty)) {
234
+ continue;
235
+ }
236
+ $itemData = $this->helper->getItemInfo($item);
237
+
238
+ unset($itemData['quantity']);
239
+ $newitemData = $itemData;
240
+ $newitemData['old_quantity'] = $oldQty;
241
+ $newitemData['new_quantity'] = $newQty;
242
+ $data['cart_items'][] = $newitemData;
243
+ }
244
+
245
+ if (isset($data['cart_items'])) {
246
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::UPDATECART);
247
+ }
248
+
249
+ return;
250
+ }
251
+
252
+ /**
253
+ * Push the empty cart actions data
254
+ *
255
+ * @param Varien_Event_Observer $observer
256
+ *
257
+ * @return void|boolean
258
+ */
259
+ public function pushEmptyCartData(Varien_Event_Observer $observer)
260
+ {
261
+ $updateAction = (string)Mage::app()->getRequest()->getParam('update_cart_action');
262
+ if ($updateAction != 'empty_cart') {
263
+ return false;
264
+ }
265
+ $items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
266
+ foreach ($items as $item) {
267
+ $this->removeCartItem($item);
268
+ }
269
+
270
+ return;
271
+ }
272
+
273
+ /**
274
+ * Push the remove cart item data
275
+ *
276
+ * @param Varien_Event_Observer $observer
277
+ */
278
+ public function pushRemoveCartItemData(Varien_Event_Observer $observer)
279
+ {
280
+ $this->removeCartItem($observer->getEvent()->getQuoteItem());
281
+ }
282
+
283
+ /**
284
+ * Remove the cart item
285
+ *
286
+ * @param unknown $item
287
+ *
288
+ * @return void|boolean
289
+ */
290
+ public function removeCartItem($item)
291
+ {
292
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::REMOVECART)) {
293
+ return false;
294
+ }
295
+ $data = array_merge($this->helper->getCartInfo(), $this->helper->getItemInfo($item));
296
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::REMOVECART);
297
+
298
+ return;
299
+ }
300
+
301
+ /**
302
+ * Observe the checkout page
303
+ *
304
+ * @param Varien_Event_Observer $observer
305
+ *
306
+ * @return void|boolean
307
+ */
308
+ public function pushCheckoutPageData(Varien_Event_Observer $observer)
309
+ {
310
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::CHECKOUT)) {
311
+ return false;
312
+ }
313
+
314
+ if ($this->helper->eventAlreadyTracked($observer->getEvent()->getControllerAction()->getFullActionName())) {
315
+ return false;
316
+ }
317
+
318
+ // Set Token Values
319
+ if (isset($_GET['utm_source']) && !$this->helper->cookie->get('utm_source')) {
320
+ $this->helper->cookie->set('utm_source', $_GET['utm_source'], null, null, null, null, false);
321
+ }
322
+
323
+ if (isset($_GET['token']) && !$this->helper->cookie->get('utm_token')) {
324
+ $this->helper->cookie->set('utm_token', $_GET['token'], null, null, null, null, false);
325
+ }
326
+
327
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
328
+
329
+ $data = $this->helper->getCartInfo();
330
+ $data['cart_items'] = $this->helper->getOrderItemsInfo($quote);
331
+ $data['total_qty'] = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
332
+ $data['total_amount'] = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
333
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::CHECKOUT);
334
+
335
+ return;
336
+ }
337
+
338
+ /**
339
+ * Push billing info when user enter the billing in checkout
340
+ *
341
+ * @param Varien_Event_Observer $observer
342
+ *
343
+ * @return void|boolean
344
+ */
345
+ public function pushBillingAddressData(Varien_Event_Observer $observer)
346
+ {
347
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::BILLING)) {
348
+ return false;
349
+ }
350
+ Mage::getSingleton('checkout/session')->setTitle('Checkout Billing');
351
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
352
+ $billingInfo = $this->helper->getAddressData($quote, Targetbay_Tracking_Helper_Data::BILLING);
353
+ $this->pushPages($billingInfo, Targetbay_Tracking_Helper_Data::BILLING);
354
+
355
+ return;
356
+ }
357
+
358
+ /**
359
+ * Push shipping info when user enter the shipping in checkout
360
+ *
361
+ * @param Varien_Event_Observer $observer
362
+ *
363
+ * @return void|boolean
364
+ */
365
+ public function pushShippingAddressData(Varien_Event_Observer $observer)
366
+ {
367
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::SHIPPING)) {
368
+ return false;
369
+ }
370
+ Mage::getSingleton('checkout/session')->setTitle('Checkout Shipping');
371
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
372
+ $shippingInfo = $this->helper->getAddressData($quote, Targetbay_Tracking_Helper_Data::SHIPPING);
373
+ $this->pushPages($shippingInfo, Targetbay_Tracking_Helper_Data::SHIPPING);
374
+
375
+ return;
376
+ }
377
+
378
+ /**
379
+ * Order data
380
+ *
381
+ * @param Varien_Event_Observer $observer
382
+ * @return Targetbay_Tracking_Model_Observer
383
+ *
384
+ * @return void|boolean
385
+ */
386
+ public function pushOrderData(Varien_Event_Observer $observer)
387
+ {
388
+ if (!Mage::registry('order_pushed')) {
389
+ Mage::register('order_pushed', true);
390
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::ORDER_ITEMS)) {
391
+ return false;
392
+ }
393
+ $order = $observer->getEvent()->getOrder();
394
+ $params = Mage::app()->getFrontController()->getRequest()->getParams();
395
+
396
+ if ($this->pushShipmentData($order, $params))
397
+ return false; // order shipment process so no need to make order submit api.
398
+
399
+ // Captute the customer registration.
400
+ if ($customer = $this->helper->isRegisterCheckout($order)) {
401
+ $this->pushRegisterData($customer);
402
+ }
403
+
404
+ // Order Data Push to the Tag Manager
405
+ $orderInfo = $this->helper->getInfo($order);
406
+ $this->pushPages($orderInfo, Targetbay_Tracking_Helper_Data::ORDER_ITEMS);
407
+ }
408
+
409
+ return;
410
+ }
411
+
412
+ /**
413
+ * Push the shipment data
414
+ *
415
+ * @param unknown $order
416
+ * @param unknown $params
417
+ * @return boolean
418
+ */
419
+ public function pushShipmentData($order, $params) {
420
+ if ($this->helper->isFullFillmentProcess($params)) {
421
+ $data = $this->helper->getFullFillmentData($order, $params);
422
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::ORDER_SHIPMENT);
423
+ return true;
424
+ }
425
+
426
+ return false;
427
+ }
428
+
429
+ /**
430
+ * Push the order shipment data
431
+ *
432
+ * @param Varien_Event_Observer $observer
433
+ * @return Targetbay_Tracking_Model_Observer
434
+ * @return boolean
435
+ */
436
+ public function pushOrderShipmentData(Varien_Event_Observer $observer)
437
+ {
438
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::ORDER_SHIPMENT)) {
439
+ return false;
440
+ }
441
+
442
+ $shipment = $observer->getEvent()->getShipment();
443
+ $order = $shipment->getOrder();
444
+ $params = Mage::app()->getFrontController()->getRequest()->getParams();
445
+
446
+ if ($this->helper->isFullFillmentProcess($params)) {
447
+ $data = $this->helper->getFullFillmentData($order, $params);
448
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::ORDER_SHIPMENT);
449
+ }
450
+ return;
451
+ }
452
+
453
+ /**
454
+ * Push billing and shipping info when user enter into onestepcheckout
455
+ *
456
+ * @param Varien_Event_Observer $observer
457
+ *
458
+ * @return void|boolean
459
+ */
460
+ public function pushCheckoutAddressData(Varien_Event_Observer $observer)
461
+ {
462
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::ONESTEPCHECKOUT_ADDRESS)) {
463
+ return false;
464
+ }
465
+ Mage::getSingleton('checkout/session')->setTitle('OneStepCheckout');
466
+
467
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
468
+ $billingInfo = $this->helper->getAddressData($quote, Targetbay_Tracking_Helper_Data::BILLING);
469
+ $this->pushPages($billingInfo, Targetbay_Tracking_Helper_Data::BILLING);
470
+
471
+ $shippingInfo = $this->helper->getAddressData($quote, Targetbay_Tracking_Helper_Data::SHIPPING);
472
+ $this->pushPages($shippingInfo, Targetbay_Tracking_Helper_Data::SHIPPING);
473
+
474
+ return;
475
+ }
476
+
477
+ /**
478
+ * Push the data when customer loggedin
479
+ *
480
+ * @param Varien_Event_Observer $observer
481
+ *
482
+ * @return void|boolean
483
+ */
484
+ public function customerLoginPushData(Varien_Event_Observer $observer)
485
+ {
486
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::LOGIN)) {
487
+ return false;
488
+ }
489
+ if (!$observer->getCustomer()) {
490
+ return false;
491
+ }
492
+ $data = $this->helper->getCustomerData($observer->getCustomer(), Targetbay_Tracking_Helper_Data::LOGIN);
493
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::LOGIN);
494
+
495
+ return;
496
+ }
497
+
498
+ /**
499
+ * Push the data when customer logout
500
+ *
501
+ * @param Varien_Event_Observer $observer
502
+ *
503
+ * @return void|boolean
504
+ */
505
+ public function customerLogoutPushData(Varien_Event_Observer $observer)
506
+ {
507
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::LOGOUT)) {
508
+ return false;
509
+ }
510
+ $data = $this->helper->getCustomerData($observer->getCustomer(), Targetbay_Tracking_Helper_Data::LOGOUT);
511
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::LOGOUT);
512
+
513
+ // Remove all Cookies
514
+ $this->helper->removeCookies();
515
+
516
+ return;
517
+ }
518
+
519
+ /**
520
+ * Registration observer
521
+ *
522
+ * @param Varien_Event_Observer $observer
523
+ */
524
+ public function customerRegisterPushData(Varien_Event_Observer $observer)
525
+ {
526
+ $this->pushRegisterData($observer->getCustomer());
527
+ }
528
+
529
+ /**
530
+ * Push the registration data
531
+ *
532
+ * @param unknown $customer
533
+ *
534
+ * @return void|boolean
535
+ */
536
+ public function pushRegisterData($customer)
537
+ {
538
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::CREATE_ACCOUNT)) {
539
+ return false;
540
+ }
541
+ $data = $this->helper->getCustomerData($customer, Targetbay_Tracking_Helper_Data::CREATE_ACCOUNT);
542
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::CREATE_ACCOUNT);
543
+
544
+ return;
545
+ }
546
+
547
+ /**
548
+ * Push the newslettter subscription data
549
+ *
550
+ * @param Varien_Event_Observer $observer
551
+ *
552
+ * @return void|boolean
553
+ */
554
+ public function pushSubscriptionData(Varien_Event_Observer $observer)
555
+ {
556
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::SUBSCRIBE_CUSTOMER)) {
557
+ return false;
558
+ }
559
+
560
+ $webstieId = Mage::app()->getStore()->getWebsiteId();
561
+ $customerModel = Mage::getModel('customer/customer');
562
+
563
+ if (Mage::app()->getRequest()->getParam('email')) {
564
+ $email = Mage::app()->getRequest()->getParam('email');
565
+ $customerData = $customerModel->setWebsiteId($webstieId)->loadByEmail($email);
566
+ $customerId = $customerData->getEntityId();
567
+ } else {
568
+ $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
569
+ $customerData = $customerModel->load($customerId);
570
+ $email = '';
571
+ }
572
+
573
+ $data = $this->helper->visitInfo();
574
+
575
+ if (empty($email)) {
576
+ $subscriberFactory = Mage::getModel('newsletter/subscriber')->loadByCustomer($customerData);
577
+
578
+ if ($subscriberFactory->getSubscriberStatus() == Targetbay_Tracking_Helper_Data::STATUS_UNSUBSCRIBED) {
579
+ $status = 'Unsubscribed';
580
+ } elseif ($subscriberFactory->getSubscriberStatus() == Targetbay_Tracking_Helper_Data::STATUS_SUBSCRIBED) {
581
+ $status = 'Subscribed';
582
+ } elseif ($subscriberFactory->getSubscriberStatus() == Targetbay_Tracking_Helper_Data::STATUS_UNCONFIRMED) {
583
+ $status = 'Unconfirmed';
584
+ } elseif ($subscriberFactory->getSubscriberStatus() == Targetbay_Tracking_Helper_Data::STATUS_NOT_ACTIVE) {
585
+ $status = 'Not Activated';
586
+ } else {
587
+ $status = Mage::app()->getRequest()->getParam('status');
588
+ }
589
+ } else {
590
+ $status = '';
591
+ }
592
+
593
+ $status = !empty($email) ? 'Subscribed' : $status;
594
+ $data['user_mail'] = Mage::getSingleton('customer/session')->isLoggedIn() ? Mage::getSingleton('customer/session')->getCustomer()->getEmail() : $email;
595
+ $data['subscription_status'] = $status;
596
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::SUBSCRIBE_CUSTOMER);
597
+
598
+ return;
599
+ }
600
+
601
+ /**
602
+ * Admin Account Activation observer
603
+ *
604
+ * @param Varien_Event_Observer $observer
605
+ */
606
+ public function customerAdminConfirmData(Varien_Event_Observer $observer)
607
+ {
608
+ $customer_info = $observer->getCustomer()->getData();
609
+ $data = array_merge($this->helper->visitInfo(), $customer_info);
610
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::ADMIN_ACTIVATE_ACCOUNT);
611
+
612
+ return;
613
+ }
614
+
615
+ /**
616
+ * Add and update product
617
+ *
618
+ * @param Varien_Event_Observer $observer
619
+ *
620
+ * @return void
621
+ */
622
+ public function pushProductData(Varien_Event_Observer $observer)
623
+ {
624
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::ADD_PRODUCT)) {
625
+ return false;
626
+ }
627
+ $param = Mage::app()->getRequest()->getParams();
628
+ $product = $observer->getEvent()->getProduct();
629
+ if ($product->getId()) {
630
+ $type = Targetbay_Tracking_Helper_Data::ADD_PRODUCT;
631
+ if ($param['id']) {
632
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::UPDATE_PRODUCT)) {
633
+ return false;
634
+ }
635
+ $type = Targetbay_Tracking_Helper_Data::UPDATE_PRODUCT;
636
+ }
637
+ $data = $this->helper->getProductData($product);
638
+ $this->pushPages($data, $type);
639
+ }
640
+
641
+ return;
642
+ }
643
+
644
+ /**
645
+ * Delete product
646
+ *
647
+ * @param Varien_Event_Observer $observer
648
+ *
649
+ * @return void
650
+ */
651
+ public function pushDeleteProductData(Varien_Event_Observer $observer)
652
+ {
653
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::DELETE_PRODUCT)) {
654
+ return false;
655
+ }
656
+ $params = Mage::app()->getRequest()->getParams();
657
+
658
+ if ($params) {
659
+ $data['entity_id'] = Mage::app()->getRequest()->getParam('id');
660
+ $data['user_name'] = Targetbay_Tracking_Helper_Data::ANONYMOUS_USER;
661
+ $data['user_id'] = strtotime(date('Y-m-d H:i:s'));
662
+ $data['session_id'] = strtotime(date('Y-m-d H:i:s'));
663
+ if ($this->helper->cookie->get('trackingsession')) {
664
+ $data['user_id'] = $this->helper->cookie->get('trackingsession');
665
+ $data['session_id'] = $this->helper->cookie->get('trackingsession');
666
+ }
667
+ $data['date'] = $this->helper->date->date('Y-m-d');
668
+ $data['timestamp'] = strtotime($this->helper->date->date('Y-m-d'));
669
+ $data['time'] = $this->helper->date->date('H:i');
670
+ $data['user_mail'] = Targetbay_Tracking_Helper_Data::ANONYMOUS_USER;
671
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::DELETE_PRODUCT);
672
+ }
673
+
674
+ return;
675
+ }
676
+
677
+ /**
678
+ * Category view page
679
+ *
680
+ * @param Varien_Event_Observer $observer
681
+ *
682
+ * @return void
683
+ */
684
+ public function pushCategoryViewData(Varien_Event_Observer $observer)
685
+ {
686
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::CATEGORY_VIEW)) {
687
+ return false;
688
+ }
689
+ $category = Mage::registry('current_category');
690
+ $data = $this->helper->visitInfo();
691
+ $data['category_id'] = $category->getId();
692
+ $data['category_url'] = $category->getUrl();
693
+ $data['category_name'] = $category->getName();
694
+
695
+ $trackingType = $this->helper->getTrackingType();
696
+ if ($trackingType != 1):
697
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::CATEGORY_VIEW);
698
+ endif;
699
+
700
+ return;
701
+ }
702
+
703
+ /**
704
+ * Product view page
705
+ *
706
+ * @param Varien_Event_Observer $observer
707
+ *
708
+ * @return void
709
+ */
710
+ public function pushProductViewData(Varien_Event_Observer $observer)
711
+ {
712
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::PRODUCT_VIEW)) {
713
+ return false;
714
+ }
715
+
716
+ // Get the base visit info
717
+ $data = $this->helper->visitInfo();
718
+ $product = Mage::registry('product');
719
+ $categoryIds = $product->getCategoryIds();
720
+ if (count($categoryIds)) {
721
+ $firstCategoryId = $categoryIds[0];
722
+ $_category = Mage::getModel('catalog/category')->load($firstCategoryId);
723
+ $data['category'] = $_category->getName();
724
+ }
725
+ $data['product_id'] = $product->getId();
726
+ $data['product_name'] = $product->getName();
727
+ $data['price'] = $product->getPrice();
728
+ $data['productimg'] = $product->getImageUrl();
729
+ $data['stock'] = Targetbay_Tracking_Helper_Data::OUT_OF_STOCK;
730
+ $stock = $product->getStockItem();
731
+ if ($stock->getIsInStock()) {
732
+ $data['stock'] = Targetbay_Tracking_Helper_Data::IN_STOCK;
733
+ }
734
+
735
+ $trackingType = $this->helper->getTrackingType();
736
+ if ($trackingType != 1):
737
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::PRODUCT_VIEW);
738
+ endif;
739
+
740
+ return;
741
+ }
742
+
743
+ /**
744
+ * Push the searhced query string
745
+ *
746
+ * @param Varien_Event_Observer $observer
747
+ *
748
+ * @return void
749
+ */
750
+ public function pushSearchQueryData(Varien_Event_Observer $observer)
751
+ {
752
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::CATALOG_SEARCH)) {
753
+ return false;
754
+ }
755
+ $keyword = Mage::app()->getRequest()->getParam('q');
756
+ if (empty($keyword)) {
757
+ return false;
758
+ }
759
+ $data = $this->helper->visitInfo();
760
+ $data['keyword'] = $keyword;
761
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::CATALOG_SEARCH);
762
+
763
+ return;
764
+ }
765
+
766
+ /**
767
+ * Add the Wishlist
768
+ *
769
+ * @param Varien_Event_Observer $observer
770
+ *
771
+ * @return void
772
+ */
773
+ public function pushAddWishlistData($observer)
774
+ {
775
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::WISHLIST)) {
776
+ return false;
777
+ }
778
+ $wishlistItems = $observer->getEvent()->getItems();
779
+ $item_info = array();
780
+
781
+ foreach ($wishlistItems as $item) {
782
+ if ($item->getParentItem())
783
+ $item = $item->getParentItem();
784
+
785
+ $item_info = $this->helper->getWishlistProductInfo($item->getData('product_id'));
786
+
787
+ $data = array_merge($this->helper->visitInfo(), $item_info);
788
+ $data['item_id'] = $item->getWishlistItemId();
789
+ if ($customOptions = $this->helper->getCustomOptionsInfo($item, null)) {
790
+ $data['attributes'] = $customOptions;
791
+ }
792
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::WISHLIST);
793
+ }
794
+
795
+ return;
796
+
797
+ }
798
+
799
+ /**
800
+ * Update the Wishlist items
801
+ *
802
+ * @param Varien_Event_Observer $observer
803
+ */
804
+ public function pushUpdateWishlistData(Varien_Event_Observer $observer)
805
+ {
806
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::UPDATE_WISHLIST)) {
807
+ return false;
808
+ }
809
+
810
+ $controller = $observer->getEvent()->getControllerAction();
811
+ $request = $controller->getRequest();
812
+ $wishlistId = Mage::app()->getRequest()->getParam('wishlist_id');
813
+ $wishlistDesc = Mage::app()->getRequest()->getParam('description');
814
+ $wishlistQty = Mage::app()->getRequest()->getParam('qty');
815
+
816
+ $data = $this->helper->visitInfo();
817
+ $items = array();
818
+ $data['wishlist_id'] = $wishlistId;
819
+
820
+ foreach ($wishlistDesc as $id => $item) {
821
+ $wishlistItem = Mage::getModel('wishlist/item')->load($id);
822
+ $items[$id]['item_id'] = $id;
823
+ $items[$id]['product_id'] = $wishlistItem->getProductId();
824
+ $items[$id]['store_id'] = $wishlistItem->getStoreId();
825
+ $items[$id]['description'] = $item;
826
+ $items[$id]['qty'] = $wishlistQty[$id];
827
+ }
828
+
829
+ $data['wishlist_items'] = $items;
830
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::UPDATE_WISHLIST);
831
+
832
+ return;
833
+ }
834
+
835
+ /**
836
+ * Remove the Wishlist items
837
+ *
838
+ * @param Varien_Event_Observer $observer
839
+ */
840
+ public function removeWhislistItem(Varien_Event_Observer $observer)
841
+ {
842
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::REMOVE_WISHLIST)) {
843
+ return false;
844
+ }
845
+
846
+ $controller = $observer->getEvent()->getControllerAction();
847
+ $request = $controller->getRequest();
848
+
849
+ $user = Mage::getSingleton('admin/session');
850
+
851
+ $id = (int)Mage::app()->getRequest()->getParam('item');
852
+ $item = Mage::getModel('wishlist/item')->load($id);
853
+
854
+ if (!$item->getId()) {
855
+ return false;
856
+ }
857
+
858
+ $wishlist = Mage::getModel('wishlist/wishlist')->load($item->getWishlistId());
859
+
860
+ if (!$wishlist) {
861
+ return false;
862
+ } else {
863
+ $data = $this->helper->visitInfo();
864
+ $data['item_id'] = $id;
865
+ $data['product_id'] = $item->getProductId();
866
+ $data['store_id'] = $item->getStoreId();
867
+ $data['wishlist_id'] = $item->getWishlistId();
868
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::REMOVE_WISHLIST);
869
+ }
870
+
871
+ return;
872
+ }
873
+
874
+ /**
875
+ * Visiting page info
876
+ *
877
+ * @param Varien_Event_Observer $observer
878
+ *
879
+ * @return void
880
+ */
881
+ public function pushCartData(Varien_Event_Observer $observer)
882
+ {
883
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::CART_INDEX)) {
884
+ return false;
885
+ }
886
+
887
+ // Set Token Values
888
+ if (isset($_GET['utm_source']) && !$this->helper->cookie->get('utm_source')) {
889
+ $this->helper->cookie->set('utm_source', $_GET['utm_source'], null, null, null, null, false);
890
+ }
891
+
892
+ if (isset($_GET['token']) && !$this->helper->cookie->get('utm_token')) {
893
+ $this->helper->cookie->set('utm_token', $_GET['token'], null, null, null, null, false);
894
+ }
895
+
896
+ // Page Visit Tracking
897
+ $data = $this->helper->visitInfo();
898
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::CART_INDEX);
899
+
900
+ return;
901
+ }
902
+
903
+ /**
904
+ * Push customer address data
905
+ *
906
+ * @param Varien_Event_Observer $observer
907
+ *
908
+ * @return void
909
+ */
910
+ public function pushCustomerAddressData(Varien_Event_Observer $observer)
911
+ {
912
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::CUSTOMER_ADDRESS)) {
913
+ return false;
914
+ }
915
+ $addressId = Mage::app()->getRequest()->getParam('id');
916
+ $data = $this->helper->getCustomerAddressData($addressId);
917
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::CUSTOMER_ADDRESS);
918
+ return;
919
+ }
920
+
921
+ /**
922
+ * Push customer account data
923
+ *
924
+ * @param Varien_Event_Observer $observer
925
+ *
926
+ * @return void
927
+ */
928
+ public function pushCustomerAccountData(Varien_Event_Observer $observer)
929
+ {
930
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::CUSTOMER_ACCOUNT)) {
931
+ return false;
932
+ }
933
+ Mage::getSingleton('customer/session')->setTitle('Account Information');
934
+ $data = $this->helper->visitInfo();
935
+ $data['customer_id'] = Mage::getSingleton('customer/session')->getCustomer()->getId();
936
+ $data['firstname'] = Mage::getSingleton('customer/session')->getCustomer()->getFirstname();
937
+ $data['lastname'] = Mage::getSingleton('customer/session')->getCustomer()->getLastname();
938
+ $data['email'] = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
939
+ $data['account_updated'] = Mage::getModel('core/date')->date('Y-m-d');
940
+ $this->pushPages($data, Targetbay_Tracking_Helper_Data::CUSTOMER_ACCOUNT);
941
+ return;
942
+ }
943
+
944
+ /**
945
+ * Push the referrer data.
946
+ *
947
+ * @return boolean
948
+ */
949
+ public function pushReferralData()
950
+ {
951
+ if (!$this->helper->canTrackPages(Targetbay_Tracking_Helper_Data::PAGE_REFERRAL)) {
952
+ return false;
953
+ }
954
+ if ($referrerData = $this->helper->getRefererData()) {
955
+ $this->pushPages($referrerData, Targetbay_Tracking_Helper_Data::PAGE_REFERRAL);
956
+ }
957
+ }
958
+
959
+ /**
960
+ * API Calls
961
+ *
962
+ * @param unknown $data
963
+ * @param unknown $type
964
+ */
965
+ public function pushPages($data, $type)
966
+ {
967
+ $endPointUrl = $this->targetbayHost . $type . $this->apiToken;
968
+ $data['index_name'] = $this->indexName;
969
+ try {
970
+ $res = $this->helper->postPageInfo($endPointUrl, json_encode($data));
971
+ }
972
+ catch (Exception $e) {
973
+ $this->helper->debug($type ."ERROR:" . $e->getMessage());
974
+ }
975
+ }
976
+ }
app/code/community/Targetbay/Tracking/Model/Subscriber.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_Subscriber extends Mage_Newsletter_Model_Subscriber
8
+ {
9
+ const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'newsletter/subscription/confirm_email_template';
10
+ const XML_PATH_CONFIRM_EMAIL_IDENTITY = 'newsletter/subscription/confirm_email_identity';
11
+ const XML_PATH_SUCCESS_EMAIL_TEMPLATE = 'newsletter/subscription/success_email_template';
12
+ const XML_PATH_SUCCESS_EMAIL_IDENTITY = 'newsletter/subscription/success_email_identity';
13
+ const XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE = 'newsletter/subscription/un_email_template';
14
+ const XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY = 'newsletter/subscription/un_email_identity';
15
+
16
+
17
+ /**
18
+ * Sends out confirmation success email
19
+ *
20
+ * @return Mage_Newsletter_Model_Subscriber
21
+ */
22
+ public function sendConfirmationSuccessEmail()
23
+ {
24
+ $emailStatus = Mage::helper('tracking')->getEmailStatus();
25
+
26
+ if($emailStatus == 1)
27
+ return false;
28
+
29
+ if ($this->getImportMode()) {
30
+ return $this;
31
+ }
32
+
33
+ if(!Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE)
34
+ || !Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY)
35
+ ) {
36
+ return $this;
37
+ }
38
+
39
+ $translate = Mage::getSingleton('core/translate');
40
+ /* @var $translate Mage_Core_Model_Translate */
41
+ $translate->setTranslateInline(false);
42
+
43
+ $email = Mage::getModel('core/email_template');
44
+
45
+ $email->sendTransactional(
46
+ Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
47
+ Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
48
+ $this->getEmail(),
49
+ $this->getName(),
50
+ array('subscriber'=>$this)
51
+ );
52
+
53
+ $translate->setTranslateInline(true);
54
+
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * Sends out unsubsciption email
60
+ *
61
+ * @return Mage_Newsletter_Model_Subscriber
62
+ */
63
+ public function sendUnsubscriptionEmail()
64
+ {
65
+ $emailStatus = Mage::helper('tracking')->getEmailStatus();
66
+
67
+ if($emailStatus == 1)
68
+ return false;
69
+
70
+ if ($this->getImportMode()) {
71
+ return $this;
72
+ }
73
+ if(!Mage::getStoreConfig(self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE)
74
+ || !Mage::getStoreConfig(self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY)
75
+ ) {
76
+ return $this;
77
+ }
78
+
79
+ $translate = Mage::getSingleton('core/translate');
80
+ /* @var $translate Mage_Core_Model_Translate */
81
+ $translate->setTranslateInline(false);
82
+
83
+ $email = Mage::getModel('core/email_template');
84
+
85
+ $email->sendTransactional(
86
+ Mage::getStoreConfig(self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE),
87
+ Mage::getStoreConfig(self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY),
88
+ $this->getEmail(),
89
+ $this->getName(),
90
+ array('subscriber'=>$this)
91
+ );
92
+
93
+ $translate->setTranslateInline(true);
94
+
95
+ return $this;
96
+ }
97
+ }
app/code/community/Targetbay/Tracking/Model/System/Config/Source/Page.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_System_Config_Source_Page
8
+ {
9
+ /**
10
+ * Page Options configurations
11
+ *
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return array(
17
+ array(
18
+ 'value' => Targetbay_Tracking_Helper_Data::ALL_PAGES,
19
+ 'label' => Mage::helper('adminhtml')->__('All Pages')
20
+ ),
21
+ array(
22
+ 'value' => Targetbay_Tracking_Helper_Data::ADD_PRODUCT,
23
+ 'label' => Mage::helper('adminhtml')->__('Add Product')
24
+ ),
25
+ array(
26
+ 'value' => Targetbay_Tracking_Helper_Data::DELETE_PRODUCT,
27
+ 'label' => Mage::helper('adminhtml')->__('Delete Product')
28
+ ),
29
+ array(
30
+ 'value' => Targetbay_Tracking_Helper_Data::UPDATE_PRODUCT,
31
+ 'label' => Mage::helper('adminhtml')->__('Update Product')
32
+ ),
33
+ array(
34
+ 'value' => Targetbay_Tracking_Helper_Data::PAGE_VISIT,
35
+ 'label' => Mage::helper('adminhtml')->__('Page Visit')
36
+ ),
37
+ array(
38
+ 'value' => Targetbay_Tracking_Helper_Data::CATEGORY_VIEW,
39
+ 'label' => Mage::helper('adminhtml')->__('Category View')
40
+ ),
41
+ array(
42
+ 'value' => Targetbay_Tracking_Helper_Data::PRODUCT_VIEW,
43
+ 'label' => Mage::helper('adminhtml')->__('Product View')
44
+ ),
45
+ array(
46
+ 'value' => Targetbay_Tracking_Helper_Data::CATALOG_SEARCH,
47
+ 'label' => Mage::helper('adminhtml')->__('Search Page')
48
+ ),
49
+ array(
50
+ 'value' => Targetbay_Tracking_Helper_Data::CREATE_ACCOUNT,
51
+ 'label' => Mage::helper('adminhtml')->__('Create Account')
52
+ ),
53
+ array(
54
+ 'value' => Targetbay_Tracking_Helper_Data::LOGIN,
55
+ 'label' => Mage::helper('adminhtml')->__('Login')
56
+ ),
57
+ array(
58
+ 'value' => Targetbay_Tracking_Helper_Data::LOGOUT,
59
+ 'label' => Mage::helper('adminhtml')->__('Logout')
60
+ ),
61
+ array(
62
+ 'value' => Targetbay_Tracking_Helper_Data::ADDTOCART,
63
+ 'label' => Mage::helper('adminhtml')->__('Add to cart')
64
+ ),
65
+ array(
66
+ 'value' => Targetbay_Tracking_Helper_Data::UPDATECART,
67
+ 'label' => Mage::helper('adminhtml')->__('Update cart')
68
+ ),
69
+ array(
70
+ 'value' => Targetbay_Tracking_Helper_Data::REMOVECART,
71
+ 'label' => Mage::helper('adminhtml')->__('Remove Cart')
72
+ ),
73
+ array(
74
+ 'value' => Targetbay_Tracking_Helper_Data::CHECKOUT,
75
+ 'label' => Mage::helper('adminhtml')->__('Checkout')
76
+ ),
77
+ array(
78
+ 'value' => Targetbay_Tracking_Helper_Data::BILLING,
79
+ 'label' => Mage::helper('adminhtml')->__('Billing page')
80
+ ),
81
+ array(
82
+ 'value' => Targetbay_Tracking_Helper_Data::SHIPPING,
83
+ 'label' => Mage::helper('adminhtml')->__('Shipping page')
84
+ ),
85
+ array(
86
+ 'value' => Targetbay_Tracking_Helper_Data::ORDER_ITEMS,
87
+ 'label' => Mage::helper('adminhtml')->__('Order page')
88
+ ),
89
+ array(
90
+ 'value' => Targetbay_Tracking_Helper_Data::PAGE_REFERRAL,
91
+ 'label' => Mage::helper('adminhtml')->__('Referrer page')
92
+ ),
93
+ array (
94
+ 'value' => Targetbay_Tracking_Helper_Data::WISHLIST,
95
+ 'label' => Mage::helper ( 'adminhtml' )->__ ( 'Wishlist page' )
96
+ )
97
+ );
98
+ }
99
+ }
app/code/community/Targetbay/Tracking/Model/System/Config/Source/Status.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_System_Config_Source_Status
8
+ {
9
+ /**
10
+ * Magento version configurations
11
+ *
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return array(
17
+ array(
18
+ 'value' => '',
19
+ 'label' => __('Please Select')
20
+ ),
21
+ array(
22
+ 'value' => 'dev',
23
+ 'label' => __('Development')
24
+ ),
25
+ array(
26
+ 'value' => 'stage',
27
+ 'label' => __('Stage')
28
+ ),
29
+ array(
30
+ 'value' => 'app',
31
+ 'label' => __('Production')
32
+ )
33
+ );
34
+ }
35
+ }
app/code/community/Targetbay/Tracking/Model/System/Config/Source/Tracking.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_System_Config_Source_Tracking
8
+ {
9
+ /**
10
+ * Page Options configurations
11
+ *
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return array(
17
+ array(
18
+ 'value' => '',
19
+ 'label' => Mage::helper('adminhtml')->__('Please Select')
20
+ ),
21
+ array(
22
+ 'value' => 0,
23
+ 'label' => Mage::helper('adminhtml')->__('Automatic')
24
+ ),
25
+ array(
26
+ 'value' => 1,
27
+ 'label' => Mage::helper('adminhtml')->__('Manual')
28
+ )
29
+ );
30
+ }
31
+ }
app/code/community/Targetbay/Tracking/Model/System/Config/Source/Version.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_System_Config_Source_Version
8
+ {
9
+ /**
10
+ * Magento version configurations
11
+ *
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return array(
17
+ array(
18
+ 'value' => 'v1',
19
+ 'label' => __('Magento1.x')
20
+ ),
21
+ array(
22
+ 'value' => 'v2',
23
+ 'label' => __('Magento2.x')
24
+ )
25
+ );
26
+ }
27
+ }
app/code/community/Targetbay/Tracking/Model/System/Config/Source/Yesno.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_Model_System_Config_Source_Yesno
8
+ {
9
+ /**
10
+ * Magento mail configurations
11
+ *
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ return array(
17
+ array('value' => 1, 'label'=>Mage::helper('adminhtml')->__('Yes')),
18
+ array('value' => 2, 'label'=>Mage::helper('adminhtml')->__('No')),
19
+ );
20
+ }
21
+ }
app/code/community/Targetbay/Tracking/controllers/IndexController.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * @author Targetbay
4
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
5
+ * @package Targetbay_Tracking
6
+ */
7
+ class Targetbay_Tracking_IndexController extends Mage_Core_Controller_Front_Action
8
+ {
9
+ public function reloadAction()
10
+ {
11
+ if (Mage::getSingleton('customer/session')->isLoggedIn())
12
+ return false;
13
+
14
+ try {
15
+ $quoteId = Mage::app()->getRequest()->getParam('quote_id');
16
+ $store_id = Mage::app()->getStore()->getId();
17
+
18
+ $checkout = Mage::getSingleton('checkout/session');
19
+ $cust = Mage::getSingleton('customer/session');
20
+ $chkQuote = Mage::helper('checkout/cart')->getQuote();
21
+ $helper = Mage::helper('tracking');
22
+
23
+ if(empty($quoteId))
24
+ $this->_redirectAfterReload();
25
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
26
+ if ($quote->getId()) {
27
+ $quote->setIsActive(1)
28
+ ->save();
29
+ Mage::getSingleton('checkout/session')->replaceQuote($quote);
30
+ }
31
+ } catch (Exception $e) {
32
+ $helper->debug("ERROR: " . $e->getMessage());
33
+ }
34
+
35
+ return $this->_redirectAfterReload();
36
+ }
37
+
38
+ private function _redirectAfterReload()
39
+ {
40
+ $url = 'checkout/cart/';
41
+
42
+ return $this->_redirect(
43
+ $url,
44
+ array('_secure' => Mage::app()->getStore()->isCurrentlySecure())
45
+ );
46
+ }
47
+ }
app/code/community/Targetbay/Tracking/etc/api2.xml ADDED
@@ -0,0 +1,615 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /*
4
+ * @author Targetbay
5
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
6
+ * @package Targetbay_Tracking
7
+ */
8
+ -->
9
+ <config>
10
+ <api2>
11
+ <resource_groups>
12
+ <tracking translate="title" module="targetbay_tracking">
13
+ <title>Totalcounts for Tagrgetbay</title>
14
+ <sort_order>10</sort_order>
15
+ </tracking>
16
+ </resource_groups>
17
+ <resources>
18
+ <tracking translate="title" module="targetbay_tracking">
19
+ <group>tracking</group>
20
+ <model>tracking/api2_totalinfo</model>
21
+ <title>Totalcounts</title>
22
+ <sort_order>10</sort_order>
23
+ <privileges>
24
+ <guest>
25
+ <retrieve>1</retrieve>
26
+ </guest>
27
+ </privileges>
28
+ <routes>
29
+ <route_collection>
30
+ <route>/targetbay/totalcounts</route>
31
+ <action_type>collection</action_type>
32
+ </route_collection>
33
+ </routes>
34
+ <versions>1</versions>
35
+ </tracking>
36
+ <tracking_productcount translate="title" module="targetbay_tracking">
37
+ <group>tracking</group>
38
+ <model>tracking/api2_totalproductinfo</model>
39
+ <title>Total Product Counts</title>
40
+ <sort_order>20</sort_order>
41
+ <privileges>
42
+ <guest>
43
+ <retrieve>1</retrieve>
44
+ </guest>
45
+ </privileges>
46
+ <routes>
47
+ <route_collection>
48
+ <route>/targetbay/totalproductcounts</route>
49
+ <action_type>collection</action_type>
50
+ </route_collection>
51
+ </routes>
52
+ <versions>1</versions>
53
+ </tracking_productcount>
54
+ <tracking_product translate="title" module="targetbay_tracking">
55
+ <group>tracking</group>
56
+ <model>tracking/api2_product</model>
57
+ <working_model>catalog/product</working_model>
58
+ <title>Targetbay Export Products</title>
59
+ <sort_order>30</sort_order>
60
+ <privileges>
61
+ <guest>
62
+ <retrieve>1</retrieve>
63
+ </guest>
64
+ </privileges>
65
+ <attributes
66
+ translate="entity_id type_id attribute_set_id stock_data image_url is_saleable total_reviews_count url buy_now_url has_custom_options is_in_stock regular_price_with_tax regular_price_without_tax final_price_with_tax final_price_without_tax use_config_gift_message_available use_config_gift_wrapping_available url_key_create_redirect addional_attributes"
67
+ module="api2">
68
+ <entity_id>Product ID</entity_id>
69
+ <type_id>Product Type</type_id>
70
+ <attribute_set_id>Attribute Set</attribute_set_id>
71
+ <stock_data>Inventory Data</stock_data>
72
+ <image_url>Default Image</image_url>
73
+ <is_saleable>Salability Status</is_saleable>
74
+ <total_reviews_count>Total Reviews Count</total_reviews_count>
75
+ <url>Product URL</url>
76
+ <url_key>Product URL Key</url_key>
77
+ <buy_now_url>Buy Now URL</buy_now_url>
78
+ <has_custom_options>Has Custom Options</has_custom_options>
79
+ <is_in_stock>Stock Status</is_in_stock>
80
+ <special_price>Special price</special_price>
81
+ <regular_price_with_tax>Regular Price With Tax
82
+ </regular_price_with_tax>
83
+ <regular_price_without_tax>Regular Price Without Tax
84
+ </regular_price_without_tax>
85
+ <final_price_with_tax>Final Price With Tax</final_price_with_tax>
86
+ <final_price_without_tax>Final Price Without Tax
87
+ </final_price_without_tax>
88
+ <use_config_gift_message_available>Use Config Settings for Allow
89
+ Gift Message
90
+ </use_config_gift_message_available>
91
+ <use_config_gift_wrapping_available>Use Config Settings for Allow
92
+ Gift Wrapping
93
+ </use_config_gift_wrapping_available>
94
+ <url_key_create_redirect>Create Permanent Redirect for old URL
95
+ </url_key_create_redirect>
96
+ <qty>Product Qty</qty>
97
+ <visibility>Product Viibility</visibility>
98
+ <status>Product Status</status>
99
+ <website_id>Website Id</website_id>
100
+ <store_id>Store Id</store_id>
101
+ <child_items>Child Product Items</child_items>
102
+ <parent_id>Parent Product Id</parent_id>
103
+ <category_id>Category Id</category_id>
104
+ <related_product_id>Related Product Id</related_product_id>
105
+ <upsell_product_id>Upsell Product Id</upsell_product_id>
106
+ <crosssell_product_id>Crosssell Product Id</crosssell_product_id>
107
+ <addional_attributes>Additional attributes</addional_attributes>
108
+ </attributes>
109
+ <routes>
110
+ <route_collection>
111
+ <route>/targetbay/products</route>
112
+ <action_type>collection</action_type>
113
+ </route_collection>
114
+ </routes>
115
+ <versions>1</versions>
116
+ </tracking_product>
117
+ <tracking_ordercount translate="title" module="targetbay_tracking">
118
+ <group>tracking</group>
119
+ <model>tracking/api2_totalorderinfo</model>
120
+ <title>Total Order Counts</title>
121
+ <sort_order>40</sort_order>
122
+ <privileges>
123
+ <guest>
124
+ <retrieve>1</retrieve>
125
+ </guest>
126
+ </privileges>
127
+ <routes>
128
+ <route_collection>
129
+ <route>/targetbay/totalordercounts</route>
130
+ <action_type>collection</action_type>
131
+ </route_collection>
132
+ </routes>
133
+ <versions>1</versions>
134
+ </tracking_ordercount>
135
+ <tracking_orders translate="title" module="targetbay_tracking">
136
+ <group>tracking</group>
137
+ <model>tracking/api2_orders</model>
138
+ <title>Targetbay Export Orders</title>
139
+ <sort_order>40</sort_order>
140
+ <privileges>
141
+ <guest>
142
+ <retrieve>1</retrieve>
143
+ </guest>
144
+ </privileges>
145
+ <attributes
146
+ translate="entity_id increment_id created_at status shipping_description _payment_method base_currency_code store_currency_code store_name remote_ip store_to_order_rate subtotal subtotal_incl_tax discount_amount base_grand_total grand_total shipping_amount shipping_tax_amount shipping_incl_tax tax_amount _tax_name _tax_rate coupon_code base_discount_amount base_subtotal base_shipping_amount base_shipping_tax_amount base_tax_amount total_paid base_total_paid total_refunded base_total_refunded base_subtotal_incl_tax base_total_due total_due shipping_discount_amount base_shipping_discount_amount discount_description customer_balance_amount base_customer_balance_amount base_customer_balance_amount _gift_message _order_comments customer_id"
147
+ module="api2">
148
+ <entity_id>Order ID (internal)</entity_id>
149
+ <increment_id>Order ID</increment_id>
150
+ <created_at>Order Date</created_at>
151
+ <status>Order Status</status>
152
+ <website_id>Website Id</website_id>
153
+ <store_id>Store Id</store_id>
154
+ <shipping_description>Shipping Method</shipping_description>
155
+ <payment_method>Payment Method</payment_method>
156
+ <base_currency_code>Base Currency</base_currency_code>
157
+ <store_currency_code>Order Currency</store_currency_code>
158
+ <store_name>Store Name</store_name>
159
+ <remote_ip>Placed from IP</remote_ip>
160
+ <store_to_order_rate>Store Currency to Order Currency Rate
161
+ </store_to_order_rate>
162
+ <subtotal>Subtotal</subtotal>
163
+ <subtotal_incl_tax>Subtotal Including Tax</subtotal_incl_tax>
164
+ <discount_amount>Discount</discount_amount>
165
+ <base_grand_total>Grand Total to Be Charged</base_grand_total>
166
+ <grand_total>Grand Total</grand_total>
167
+ <shipping_amount>Shipping Amount</shipping_amount>
168
+ <shipping_tax_amount>Shipping Including Tax</shipping_tax_amount>
169
+ <shipping_incl_tax>Shipping Tax</shipping_incl_tax>
170
+ <tax_amount>Tax Amount</tax_amount>
171
+ <_tax_name>Tax Name</_tax_name>
172
+ <_tax_rate>Tax Rate</_tax_rate>
173
+ <coupon_code>Coupon Code</coupon_code>
174
+ <base_discount_amount>Base Discount</base_discount_amount>
175
+ <base_subtotal>Base Subtotal</base_subtotal>
176
+ <base_shipping_amount>Base Shipping</base_shipping_amount>
177
+ <base_shipping_tax_amount>Base Shipping Tax
178
+ </base_shipping_tax_amount>
179
+ <base_tax_amount>Base Tax Amount</base_tax_amount>
180
+ <total_paid>Total Paid</total_paid>
181
+ <base_total_paid>Base Total Paid</base_total_paid>
182
+ <total_refunded>Total Refunded</total_refunded>
183
+ <base_total_refunded>Base Total Refunded</base_total_refunded>
184
+ <base_subtotal_incl_tax>Base Subtotal Including Tax
185
+ </base_subtotal_incl_tax>
186
+ <base_total_due>Base Total Due</base_total_due>
187
+ <total_due>Total Due</total_due>
188
+ <shipping_discount_amount>Shipping Discount
189
+ </shipping_discount_amount>
190
+ <base_shipping_discount_amount>Base Shipping Discount
191
+ </base_shipping_discount_amount>
192
+ <discount_description>Discount Description</discount_description>
193
+ <customer_balance_amount>Customer Balance</customer_balance_amount>
194
+ <base_customer_balance_amount>Base Customer Balance
195
+ </base_customer_balance_amount>
196
+ <_gift_message>Gift Message</_gift_message>
197
+ <_order_comments>Order Comments</_order_comments>
198
+ <customer_id>Customer ID</customer_id>
199
+ <cart_items>Order Items</cart_items>
200
+ <billing>Billing Info</billing>
201
+ <shipping>Shipping Info </shipping>
202
+ </attributes>
203
+ <routes>
204
+ <route_collection>
205
+ <route>/targetbay/orders</route>
206
+ <action_type>collection</action_type>
207
+ </route_collection>
208
+ </routes>
209
+ <versions>1</versions>
210
+ </tracking_orders>
211
+ <tracking_categorycount translate="title" module="targetbay_tracking">
212
+ <group>tracking</group>
213
+ <model>tracking/api2_totalcategoryinfo</model>
214
+ <title>Total Category Counts</title>
215
+ <sort_order>50</sort_order>
216
+ <privileges>
217
+ <guest>
218
+ <retrieve>1</retrieve>
219
+ </guest>
220
+ </privileges>
221
+ <routes>
222
+ <route_collection>
223
+ <route>/targetbay/totalcategorycounts</route>
224
+ <action_type>collection</action_type>
225
+ </route_collection>
226
+ </routes>
227
+ <versions>1</versions>
228
+ </tracking_categorycount>
229
+ <tracking_category translate="title" module="targetbay_tracking">
230
+ <group>tracking</group>
231
+ <model>tracking/api2_category</model>
232
+ <title>Targetbay Export Categories</title>
233
+ <sort_order>60</sort_order>
234
+ <privileges>
235
+ <guest>
236
+ <retrieve>1</retrieve>
237
+ </guest>
238
+ </privileges>
239
+ <attributes>
240
+ <entity_id>Category ID</entity_id>
241
+ <name>Name</name>
242
+ <parent_id>Category Parent ID</parent_id>
243
+ <is_active>Active</is_active>
244
+ <level>Level</level>
245
+ <position>Position</position>
246
+ <children>Children Ids</children>
247
+ <url_key>URL key</url_key>
248
+ <website_id>Website Id</website_id>
249
+ <store_id>Store ID</store_id>
250
+ </attributes>
251
+ <routes>
252
+ <route_collection>
253
+ <route>/targetbay/categories</route>
254
+ <action_type>collection</action_type>
255
+ </route_collection>
256
+ </routes>
257
+ <versions>1</versions>
258
+ </tracking_category>
259
+ <tracking_customercount translate="title" module="targetbay_tracking">
260
+ <group>tracking</group>
261
+ <model>tracking/api2_totalcustomerinfo</model>
262
+ <title>Total Customer Counts</title>
263
+ <sort_order>70</sort_order>
264
+ <privileges>
265
+ <guest>
266
+ <retrieve>1</retrieve>
267
+ </guest>
268
+ </privileges>
269
+ <routes>
270
+ <route_collection>
271
+ <route>/targetbay/totalcustomercounts</route>
272
+ <action_type>collection</action_type>
273
+ </route_collection>
274
+ </routes>
275
+ <versions>1</versions>
276
+ </tracking_customercount>
277
+ <tracking_customer translate="title" module="targetbay_tracking">
278
+ <group>tracking</group>
279
+ <model>tracking/api2_customer</model>
280
+ <title>Targetbay Export Customer</title>
281
+ <sort_order>75</sort_order>
282
+ <privileges>
283
+ <guest>
284
+ <retrieve>1</retrieve>
285
+ </guest>
286
+ </privileges>
287
+ <attributes>
288
+ <entity_id>Customer ID</entity_id>
289
+ <firstname>First Name</firstname>
290
+ <lastname>Last Name</lastname>
291
+ <email>Email</email>
292
+ <website_id>Associate to Website</website_id>
293
+ <store_id>Store Id</store_id>
294
+ <customer_group>Customer Group</customer_group>
295
+ <subcription_status>Subcription</subcription_status>
296
+ <billing_address>Billing info</billing_address>
297
+ <shipping_address>Shipping info</shipping_address>
298
+ <additional_address>Address info</additional_address>
299
+ <created_at>Created From</created_at>
300
+ </attributes>
301
+ <routes>
302
+ <route_collection>
303
+ <route>/targetbay/customer</route>
304
+ <action_type>collection</action_type>
305
+ </route_collection>
306
+ </routes>
307
+ <versions>1</versions>
308
+ </tracking_customer>
309
+ <tracking_cartitemcount translate="title" module="targetbay_tracking">
310
+ <group>tracking</group>
311
+ <model>tracking/api2_totalcartiteminfo</model>
312
+ <title>Total CartItem Counts</title>
313
+ <sort_order>80</sort_order>
314
+ <privileges>
315
+ <guest>
316
+ <retrieve>1</retrieve>
317
+ </guest>
318
+ </privileges>
319
+ <routes>
320
+ <route_collection>
321
+ <route>/targetbay/totalcartitemcounts</route>
322
+ <action_type>collection</action_type>
323
+ </route_collection>
324
+ </routes>
325
+ <versions>1</versions>
326
+ </tracking_cartitemcount>
327
+ <tracking_cartitem translate="title" module="targetbay_tracking">
328
+ <group>tracking</group>
329
+ <model>tracking/api2_cartitem</model>
330
+ <title>Targetbay Export Cart Items</title>
331
+ <sort_order>90</sort_order>
332
+ <privileges>
333
+ <guest>
334
+ <retrieve>1</retrieve>
335
+ </guest>
336
+ </privileges>
337
+ <attributes>
338
+ <entity_id>Quote ID</entity_id>
339
+ <customer_id>Customer Id</customer_id>
340
+ <customer_email>Customer Email</customer_email>
341
+ <abandonded_at>Update At</abandonded_at>
342
+ <item_id>Item Id</item_id>
343
+ <cart_items>Cart Items</cart_items>
344
+ </attributes>
345
+ <routes>
346
+ <route_collection>
347
+ <route>/targetbay/cartitems</route>
348
+ <action_type>collection</action_type>
349
+ </route_collection>
350
+ </routes>
351
+ <versions>1</versions>
352
+ </tracking_cartitem>
353
+ <tracking_wishlistcount translate="title" module="targetbay_tracking">
354
+ <group>tracking</group>
355
+ <model>tracking/api2_totalwishlistinfo</model>
356
+ <title>Total Wishlist Counts</title>
357
+ <sort_order>110</sort_order>
358
+ <privileges>
359
+ <guest>
360
+ <retrieve>1</retrieve>
361
+ </guest>
362
+ </privileges>
363
+ <routes>
364
+ <route_collection>
365
+ <route>/targetbay/totalwishlistcounts</route>
366
+ <action_type>collection</action_type>
367
+ </route_collection>
368
+ </routes>
369
+ <versions>1</versions>
370
+ </tracking_wishlistcount>
371
+ <tracking_wishlist translate="title" module="targetbay_tracking">
372
+ <group>tracking</group>
373
+ <model>tracking/api2_wishlist</model>
374
+ <title>Targetbay Export Wishlist Items</title>
375
+ <sort_order>120</sort_order>
376
+ <privileges>
377
+ <guest>
378
+ <retrieve>1</retrieve>
379
+ </guest>
380
+ </privileges>
381
+ <attributes>
382
+ <wishlist_id>Wishlist ID</wishlist_id>
383
+ <customer_id>Customer ID</customer_id>
384
+ <updated_at>Updated At</updated_at>
385
+ <item_details>Item Details</item_details>
386
+ <website_id>Website Id</website_id>
387
+ <store_id>Store Id</store_id>
388
+ </attributes>
389
+ <routes>
390
+ <route_collection>
391
+ <route>/targetbay/wishlistitem</route>
392
+ <action_type>collection</action_type>
393
+ </route_collection>
394
+ </routes>
395
+ <versions>1</versions>
396
+ </tracking_wishlist>
397
+ <tracking_reviewcount translate="title" module="targetbay_tracking">
398
+ <group>tracking</group>
399
+ <model>tracking/api2_totalreviewinfo</model>
400
+ <title>Total Review Counts</title>
401
+ <sort_order>130</sort_order>
402
+ <privileges>
403
+ <guest>
404
+ <retrieve>1</retrieve>
405
+ </guest>
406
+ </privileges>
407
+ <routes>
408
+ <route_collection>
409
+ <route>/targetbay/totalreviewcount</route>
410
+ <action_type>collection</action_type>
411
+ </route_collection>
412
+ </routes>
413
+ <versions>1</versions>
414
+ </tracking_reviewcount>
415
+ <tracking_review translate="title" module="targetbay_tracking">
416
+ <group>tracking</group>
417
+ <model>tracking/api2_review</model>
418
+ <title>Targetbay Export Review</title>
419
+ <sort_order>140</sort_order>
420
+ <privileges>
421
+ <guest>
422
+ <retrieve>1</retrieve>
423
+ </guest>
424
+ </privileges>
425
+ <attributes>
426
+ <review_id>Review ID</review_id>
427
+ <customer_id>Customer ID</customer_id>
428
+ <title>Review title</title>
429
+ <detail>Review detail</detail>
430
+ <nickname>Customer Name</nickname>
431
+ <website_id>Website Id</website_id>
432
+ <store_id>Store Id</store_id>
433
+ </attributes>
434
+ <routes>
435
+ <route_collection>
436
+ <route>/targetbay/reviews</route>
437
+ <action_type>collection</action_type>
438
+ </route_collection>
439
+ </routes>
440
+ <versions>1</versions>
441
+ </tracking_review>
442
+ <tracking_createsubscription translate="title" module="targetbay_tracking">
443
+ <group>tracking</group>
444
+ <model>tracking/api2_createsubscription</model>
445
+ <title>Create Newsletter Subscription</title>
446
+ <sort_order>150</sort_order>
447
+ <privileges>
448
+ <guest>
449
+ <create>1</create>
450
+ <retrieve>1</retrieve>
451
+ </guest>
452
+ </privileges>
453
+ <attributes>
454
+ <email_id>Email ID</email_id>
455
+ <status>Status</status>
456
+ <website_id>Website Id</website_id>
457
+ <store_id>Store Id</store_id>
458
+ </attributes>
459
+ <routes>
460
+ <route_collection>
461
+ <route>/targetbay/create</route>
462
+ <action_type>collection</action_type>
463
+ </route_collection>
464
+ </routes>
465
+ <versions>1</versions>
466
+ </tracking_createsubscription>
467
+ <tracking_updatesubscription translate="title" module="targetbay_tracking">
468
+ <group>tracking</group>
469
+ <model>tracking/api2_updatesubscription</model>
470
+ <title>Update Subscription</title>
471
+ <sort_order>155</sort_order>
472
+ <privileges>
473
+ <guest>
474
+ <create>1</create>
475
+ <retrieve>1</retrieve>
476
+ </guest>
477
+ </privileges>
478
+ <attributes>
479
+ <email_id>Email ID</email_id>
480
+ <status>Status</status>
481
+ <website_id>Website Id</website_id>
482
+ <store_id>Store Id</store_id>
483
+ </attributes>
484
+ <routes>
485
+ <route_collection>
486
+ <route>/targetbay/update</route>
487
+ <action_type>collection</action_type>
488
+ </route_collection>
489
+ </routes>
490
+ <versions>1</versions>
491
+ </tracking_updatesubscription>
492
+ <tracking_shipmentcount translate="title" module="targetbay_tracking">
493
+ <group>tracking</group>
494
+ <model>tracking/api2_totalshipmentinfo</model>
495
+ <title>Total Shipment Counts</title>
496
+ <sort_order>160</sort_order>
497
+ <privileges>
498
+ <guest>
499
+ <retrieve>1</retrieve>
500
+ </guest>
501
+ </privileges>
502
+ <routes>
503
+ <route_collection>
504
+ <route>/targetbay/totalshipmentcount</route>
505
+ <action_type>collection</action_type>
506
+ </route_collection>
507
+ </routes>
508
+ <versions>1</versions>
509
+ </tracking_shipmentcount>
510
+ <tracking_shipment translate="title" module="targetbay_tracking">
511
+ <group>tracking</group>
512
+ <model>tracking/api2_shipment</model>
513
+ <title>Targetbay Export Shipment</title>
514
+ <sort_order>165</sort_order>
515
+ <privileges>
516
+ <guest>
517
+ <retrieve>1</retrieve>
518
+ </guest>
519
+ </privileges>
520
+ <attributes module="api2">
521
+ <order_id>Order ID (internal)</order_id>
522
+ <increment_id>Order ID</increment_id>
523
+ <created_at>Order Date</created_at>
524
+ <order_status>Order Status</order_status>
525
+ <website_id>Website Id</website_id>
526
+ <store_id>Store Id</store_id>
527
+ <total_ordered_qty>Total ordered quantity</total_ordered_qty>
528
+ <updated_at>Order Shipment Created Date</updated_at>
529
+ <user_id>Customer Id</user_id>
530
+ <user_mail>Customer Mail</user_mail>
531
+ <product_id>Product Id</product_id>
532
+ <name>Product Name</name>
533
+ <sku>Product Sku</sku>
534
+ <qty_ordered>Total item quantity</qty_ordered>
535
+ <shipment_items>Order Items</shipment_items>
536
+ <cart_items>Order Items</cart_items>
537
+ </attributes>
538
+ <routes>
539
+ <route_collection>
540
+ <route>/targetbay/shipment</route>
541
+ <action_type>collection</action_type>
542
+ </route_collection>
543
+ </routes>
544
+ <versions>1</versions>
545
+ </tracking_shipment>
546
+ <tracking_stores translate="title" module="targetbay_tracking">
547
+ <group>tracking</group>
548
+ <model>tracking/api2_stores</model>
549
+ <title>Targetbay Export Stores</title>
550
+ <sort_order>170</sort_order>
551
+ <privileges>
552
+ <guest>
553
+ <retrieve>1</retrieve>
554
+ </guest>
555
+ </privileges>
556
+ <attributes>
557
+ <store_id>Store ID</store_id>
558
+ <store_name>Store Name</store_name>
559
+ <website_id>Website Id</website_id>
560
+ <website_name>Website Name</website_name>
561
+ </attributes>
562
+ <routes>
563
+ <route_collection>
564
+ <route>/targetbay/stores</route>
565
+ <action_type>collection</action_type>
566
+ </route_collection>
567
+ </routes>
568
+ <versions>1</versions>
569
+ </tracking_stores>
570
+ <tracking_subscribercount translate="title" module="targetbay_tracking">
571
+ <group>tracking</group>
572
+ <model>tracking/api2_totalsubscriberinfo</model>
573
+ <title>Total Subscriber Counts</title>
574
+ <sort_order>175</sort_order>
575
+ <privileges>
576
+ <guest>
577
+ <retrieve>1</retrieve>
578
+ </guest>
579
+ </privileges>
580
+ <routes>
581
+ <route_collection>
582
+ <route>/targetbay/totalsubscribercount</route>
583
+ <action_type>collection</action_type>
584
+ </route_collection>
585
+ </routes>
586
+ <versions>1</versions>
587
+ </tracking_subscribercount>
588
+ <tracking_subscriber translate="title" module="targetbay_tracking">
589
+ <group>tracking</group>
590
+ <model>tracking/api2_subscriber</model>
591
+ <title>Subscriber</title>
592
+ <sort_order>180</sort_order>
593
+ <privileges>
594
+ <guest>
595
+ <retrieve>1</retrieve>
596
+ </guest>
597
+ </privileges>
598
+ <attributes>
599
+ <subscriber_id>Subscriber Id</subscriber_id>
600
+ <store_id>Store ID</store_id>
601
+ <customer_id>Customer ID</customer_id>
602
+ <subscriber_email>Subscriber Email</subscriber_email>
603
+ <subscriber_status>Subscriber Status</subscriber_status>
604
+ </attributes>
605
+ <routes>
606
+ <route_collection>
607
+ <route>/targetbay/subscriber</route>
608
+ <action_type>collection</action_type>
609
+ </route_collection>
610
+ </routes>
611
+ <versions>1</versions>
612
+ </tracking_subscriber>
613
+ </resources>
614
+ </api2>
615
+ </config>
app/code/community/Targetbay/Tracking/etc/config.xml ADDED
@@ -0,0 +1,493 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /*
4
+ * @author Targetbay
5
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
6
+ * @package Targetbay_Tracking
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Targetbay_Tracking>
12
+ <version>5.1.1</version>
13
+ </Targetbay_Tracking>
14
+ </modules>
15
+ <frontend>
16
+ <routers>
17
+ <tracking>
18
+ <use>standard</use>
19
+ <args>
20
+ <module>Targetbay_Tracking</module>
21
+ <frontName>tracking</frontName>
22
+ </args>
23
+ </tracking>
24
+ </routers>
25
+ <layout>
26
+ <updates>
27
+ <tracking>
28
+ <file>tracking.xml</file>
29
+ </tracking>
30
+ </updates>
31
+ </layout>
32
+ <events>
33
+ <controller_action_postdispatch>
34
+ <observers>
35
+ <pagevisit>
36
+ <type>singleton</type>
37
+ <class>tracking/observer</class>
38
+ <method>pushPageVisitData</method>
39
+ </pagevisit>
40
+ </observers>
41
+ </controller_action_postdispatch>
42
+ </events>
43
+ </frontend>
44
+ <global>
45
+ <blocks>
46
+ <richsnippets>
47
+ <rewrite>
48
+ <product>Targetbay_Tracking_Block_Product_Product</product>
49
+ </rewrite>
50
+ </richsnippets>
51
+ <tracking>
52
+ <class>Targetbay_Tracking_Block</class>
53
+ </tracking>
54
+ </blocks>
55
+ <helpers>
56
+ <tracking>
57
+ <class>Targetbay_Tracking_Helper</class>
58
+ </tracking>
59
+ </helpers>
60
+ <models>
61
+ <tracking>
62
+ <class>Targetbay_Tracking_Model</class>
63
+ <resourceModel>tracking_mysql4</resourceModel>
64
+ </tracking>
65
+ <customer>
66
+ <rewrite>
67
+ <customer>Targetbay_Tracking_Model_Customer</customer>
68
+ </rewrite>
69
+ </customer>
70
+ <newsletter>
71
+ <rewrite>
72
+ <subscriber>Targetbay_Tracking_Model_Subscriber</subscriber>
73
+ </rewrite>
74
+ </newsletter>
75
+ </models>
76
+ <events>
77
+ <!-- cms page event -->
78
+ <controller_action_postdispatch_cms_index_index>
79
+ <observers>
80
+ <cms_page_index>
81
+ <type>singleton</type>
82
+ <class>tracking/observer</class>
83
+ <method>cmsPageVisit</method>
84
+ </cms_page_index>
85
+ </observers>
86
+ </controller_action_postdispatch_cms_index_index>
87
+
88
+ <!-- static page event -->
89
+ <controller_action_postdispatch_cms_page_view>
90
+ <observers>
91
+ <cms_page_view>
92
+ <type>singleton</type>
93
+ <class>tracking/observer</class>
94
+ <method>cmsPageVisit</method>
95
+ </cms_page_view>
96
+ </observers>
97
+ </controller_action_postdispatch_cms_page_view>
98
+
99
+ <!-- cart add event -->
100
+ <checkout_cart_add_product_complete>
101
+ <observers>
102
+ <sales_quote_add_item_handler>
103
+ <type>singleton</type>
104
+ <class>tracking/observer</class>
105
+ <method>pushAddToCart</method>
106
+ </sales_quote_add_item_handler>
107
+ </observers>
108
+ </checkout_cart_add_product_complete>
109
+
110
+ <!-- cart remove item -->
111
+ <sales_quote_remove_item>
112
+ <observers>
113
+ <sales_quote_remove_item_handler>
114
+ <type>singleton</type>
115
+ <class>tracking/observer</class>
116
+ <method>pushRemoveCartItemData</method>
117
+ </sales_quote_remove_item_handler>
118
+ </observers>
119
+ </sales_quote_remove_item>
120
+
121
+ <!-- cart update event -->
122
+ <checkout_cart_update_items_before>
123
+ <observers>
124
+ <update_cart_observer>
125
+ <type>singleton</type>
126
+ <class>tracking/observer</class>
127
+ <method>pushUpdateCartData</method>
128
+ </update_cart_observer>
129
+ </observers>
130
+ </checkout_cart_update_items_before>
131
+
132
+ <!-- cart empty action -->
133
+ <controller_action_predispatch_checkout_cart_updatePost>
134
+ <observers>
135
+ <empty_cart_observer>
136
+ <type>singleton</type>
137
+ <class>tracking/observer</class>
138
+ <method>pushEmptyCartData</method>
139
+ </empty_cart_observer>
140
+ </observers>
141
+ </controller_action_predispatch_checkout_cart_updatePost>
142
+
143
+ <!-- create order event -->
144
+ <sales_order_save_after>
145
+ <observers>
146
+ <sales_order_place_after>
147
+ <type>singleton</type>
148
+ <class>tracking/observer</class>
149
+ <method>pushOrderData</method>
150
+ </sales_order_place_after>
151
+ </observers>
152
+ </sales_order_save_after>
153
+
154
+ <!-- create shipment event >
155
+ <sales_order_shipment_save_after>
156
+ <observers>
157
+ <sales_order_shipment_after>
158
+ <type>singleton</type>
159
+ <class>tracking/observer</class>
160
+ <method>pushOrderShipmentData</method>
161
+ </sales_order_shipment_after>
162
+ </observers>
163
+ </sales_order_shipment_save_after-->
164
+
165
+ <!-- customer login event -->
166
+ <customer_login>
167
+ <observers>
168
+ <customer_login_handler>
169
+ <type>model</type>
170
+ <class>tracking/observer</class>
171
+ <method>customerLoginPushData</method>
172
+ </customer_login_handler>
173
+ </observers>
174
+ </customer_login>
175
+
176
+ <!-- customer logout event -->
177
+ <customer_logout>
178
+ <observers>
179
+ <customer_logout_handler>
180
+ <type>model</type>
181
+ <class>tracking/observer</class>
182
+ <method>customerLogoutPushData</method>
183
+ </customer_logout_handler>
184
+ </observers>
185
+ </customer_logout>
186
+
187
+ <!-- customer register event -->
188
+ <customer_register_success>
189
+ <observers>
190
+ <customer_register_success_handler>
191
+ <type>model</type>
192
+ <class>tracking/observer</class>
193
+ <method>customerRegisterPushData</method>
194
+ </customer_register_success_handler>
195
+ </observers>
196
+ </customer_register_success>
197
+
198
+ <!-- customer change address -->
199
+ <controller_action_postdispatch_customer_address_formPost>
200
+ <observers>
201
+ <customer_change_address_handler>
202
+ <type>model</type>
203
+ <class>tracking/observer</class>
204
+ <method>pushCustomerAddressData</method>
205
+ </customer_change_address_handler>
206
+ </observers>
207
+ </controller_action_postdispatch_customer_address_formPost>
208
+
209
+ <!-- customer change account information -->
210
+ <controller_action_postdispatch_customer_account_editPost>
211
+ <observers>
212
+ <customer_change_address_handler>
213
+ <type>model</type>
214
+ <class>tracking/observer</class>
215
+ <method>pushCustomerAccountData</method>
216
+ </customer_change_address_handler>
217
+ </observers>
218
+ </controller_action_postdispatch_customer_account_editPost>
219
+
220
+ <!-- admin confirm customer registeration event -->
221
+ <adminhtml_customer_save_after>
222
+ <observers>
223
+ <customer_account_activation>
224
+ <type>model</type>
225
+ <class>tracking/observer</class>
226
+ <method>customerAdminConfirmData</method>
227
+ </customer_account_activation>
228
+ </observers>
229
+ </adminhtml_customer_save_after>
230
+
231
+ <!-- newsletter save event -->
232
+ <controller_action_postdispatch_newsletter_subscriber_new>
233
+ <observers>
234
+ <subscribe_newsletter_handler>
235
+ <type>model</type>
236
+ <class>tracking/observer</class>
237
+ <method>pushSubscriptionData</method>
238
+ </subscribe_newsletter_handler>
239
+ </observers>
240
+ </controller_action_postdispatch_newsletter_subscriber_new>
241
+
242
+ <controller_action_postdispatch_newsletter_manage_save>
243
+ <observers>
244
+ <subscribe_newsletter_handler>
245
+ <type>model</type>
246
+ <class>tracking/observer</class>
247
+ <method>pushSubscriptionData</method>
248
+ </subscribe_newsletter_handler>
249
+ </observers>
250
+ </controller_action_postdispatch_newsletter_manage_save>
251
+
252
+ <!-- catalog product save event -->
253
+ <catalog_product_save_after>
254
+ <observers>
255
+ <catalog_product_save_before_handler>
256
+ <type>singleton</type>
257
+ <class>tracking/observer</class>
258
+ <method>pushProductData</method>
259
+ </catalog_product_save_before_handler>
260
+ </observers>
261
+ </catalog_product_save_after>
262
+
263
+ <!-- catalog product delete event -->
264
+ <catalog_product_delete_before>
265
+ <observers>
266
+ <catalog_product_delete_before_handler>
267
+ <type>singleton</type>
268
+ <class>tracking/observer</class>
269
+ <method>pushDeleteProductData</method>
270
+ </catalog_product_delete_before_handler>
271
+ </observers>
272
+ </catalog_product_delete_before>
273
+
274
+ <!-- checkout steps starts -->
275
+ <controller_action_postdispatch_checkout_cart_index>
276
+ <observers>
277
+ <checkout_cart>
278
+ <type>singleton</type>
279
+ <class>tracking/observer</class>
280
+ <method>pushCartData</method>
281
+ </checkout_cart>
282
+ </observers>
283
+ </controller_action_postdispatch_checkout_cart_index>
284
+
285
+ <controller_action_postdispatch_firecheckout_index_index>
286
+ <observers>
287
+ <firecheckout_index>
288
+ <type>singleton</type>
289
+ <class>tracking/observer</class>
290
+ <method>pushCheckoutPageData</method>
291
+ </firecheckout_index>
292
+ </observers>
293
+ </controller_action_postdispatch_firecheckout_index_index>
294
+
295
+ <controller_action_postdispatch_onestepcheckout_index_index>
296
+ <observers>
297
+ <onestepcheckout_index>
298
+ <type>singleton</type>
299
+ <class>tracking/observer</class>
300
+ <method>pushCheckoutPageData</method>
301
+ </onestepcheckout_index>
302
+ </observers>
303
+ </controller_action_postdispatch_onestepcheckout_index_index>
304
+
305
+ <controller_action_postdispatch_checkout_onepage_index>
306
+ <observers>
307
+ <checkout_index>
308
+ <type>singleton</type>
309
+ <class>tracking/observer</class>
310
+ <method>pushCheckoutPageData</method>
311
+ </checkout_index>
312
+ </observers>
313
+ </controller_action_postdispatch_checkout_onepage_index>
314
+
315
+ <controller_action_postdispatch_checkout_onepage_saveShippingMethod>
316
+ <observers>
317
+ <checkout_saveshippingmethod_after>
318
+ <type>singleton</type>
319
+ <class>tracking/observer</class>
320
+ <method>saveShippingMethod</method>
321
+ </checkout_saveshippingmethod_after>
322
+ </observers>
323
+ </controller_action_postdispatch_checkout_onepage_saveShippingMethod>
324
+
325
+ <controller_action_postdispatch_checkout_onepage_savePayment>
326
+ <observers>
327
+ <checkout_savepayment_after>
328
+ <type>singleton</type>
329
+ <class>tracking/observer</class>
330
+ <method>savePayment</method>
331
+ </checkout_savepayment_after>
332
+ </observers>
333
+ </controller_action_postdispatch_checkout_onepage_savePayment>
334
+
335
+ <sales_convert_quote_to_order>
336
+ <observers>
337
+ <sales_order_place_before>
338
+ <type>singleton</type>
339
+ <class>tracking/observer</class>
340
+ <method>pushCheckoutAddressData</method>
341
+ </sales_order_place_before>
342
+ </observers>
343
+ </sales_convert_quote_to_order>
344
+ <!-- checkout steps ends -->
345
+
346
+ <!-- product view event -->
347
+ <controller_action_postdispatch_catalog_product_view>
348
+ <observers>
349
+ <catalog_product_view_after>
350
+ <type>singleton</type>
351
+ <class>tracking/observer</class>
352
+ <method>pushProductViewData</method>
353
+ </catalog_product_view_after>
354
+ </observers>
355
+ </controller_action_postdispatch_catalog_product_view>
356
+
357
+ <!-- category view event -->
358
+ <controller_action_postdispatch_catalog_category_view>
359
+ <observers>
360
+ <catalog_category_view_after>
361
+ <type>singleton</type>
362
+ <class>tracking/observer</class>
363
+ <method>pushCategoryViewData</method>
364
+ </catalog_category_view_after>
365
+ </observers>
366
+ </controller_action_postdispatch_catalog_category_view>
367
+
368
+ <!-- catalog search event -->
369
+ <controller_action_postdispatch_catalogsearch_result_index>
370
+ <observers>
371
+ <catalogsearch>
372
+ <type>singleton</type>
373
+ <class>tracking/observer</class>
374
+ <method>pushSearchQueryData</method>
375
+ </catalogsearch>
376
+ </observers>
377
+ </controller_action_postdispatch_catalogsearch_result_index>
378
+
379
+ <!-- wishlist item capture -->
380
+ <wishlist_product_add_after>
381
+ <observers>
382
+ <wishlist>
383
+ <class>tracking/observer</class>
384
+ <method>pushAddWishlistData</method>
385
+ </wishlist>
386
+ </observers>
387
+ </wishlist_product_add_after>
388
+
389
+ <controller_action_predispatch_wishlist_index_update>
390
+ <observers>
391
+ <wishlist_index_update>
392
+ <type>singleton</type>
393
+ <class>tracking/observer</class>
394
+ <method>pushUpdateWishlistData</method>
395
+ </wishlist_index_update>
396
+ </observers>
397
+ </controller_action_predispatch_wishlist_index_update>
398
+
399
+ <controller_action_predispatch_wishlist_index_remove>
400
+ <observers>
401
+ <wishlist_index_remove>
402
+ <type>singleton</type>
403
+ <class>tracking/observer</class>
404
+ <method>removeWhislistItem</method>
405
+ </wishlist_index_remove>
406
+ </observers>
407
+ </controller_action_predispatch_wishlist_index_remove>
408
+
409
+ <controller_action_predispatch_wishlist_index_index>
410
+ <observers>
411
+ <wishlist_index_index>
412
+ <type>singleton</type>
413
+ <class>tracking/observer</class>
414
+ <method>cmsPageVisit</method>
415
+ </wishlist_index_index>
416
+ </observers>
417
+ </controller_action_predispatch_wishlist_index_index>
418
+
419
+ <controller_action_postdispatch_sales_order_history>
420
+ <observers>
421
+ <sales_order_history>
422
+ <type>singleton</type>
423
+ <class>tracking/observer</class>
424
+ <method>cmsPageVisit</method>
425
+ </sales_order_history>
426
+ </observers>
427
+ </controller_action_postdispatch_sales_order_history>
428
+
429
+ <controller_action_postdispatch_sales_order_view>
430
+ <observers>
431
+ <sales_order_view>
432
+ <type>singleton</type>
433
+ <class>tracking/observer</class>
434
+ <method>cmsPageVisit</method>
435
+ </sales_order_view>
436
+ </observers>
437
+ </controller_action_postdispatch_sales_order_view>
438
+
439
+ <controller_action_postdispatch_review_customer_index>
440
+ <observers>
441
+ <review_customer_index>
442
+ <type>singleton</type>
443
+ <class>tracking/observer</class>
444
+ <method>cmsPageVisit</method>
445
+ </review_customer_index>
446
+ </observers>
447
+ </controller_action_postdispatch_review_customer_index>
448
+ </events>
449
+ </global>
450
+
451
+
452
+ <!-- Added default values -->
453
+ <default>
454
+ <targetbay_tracking>
455
+ <tracking_groups>
456
+ <enabled>1</enabled>
457
+ <hostname><![CDATA[http://dev.targetbay.com/api/v1/webhooks/]]></hostname>
458
+ <message_js><![CDATA[http://dev.targetbay.com/js/tb-messages.js]]></message_js>
459
+ <review_js><![CDATA[http://dev.targetbay.com/js/tb-reviews.js]]></review_js>
460
+ <api_token>6e1c1435-ccc9-45e4-9eb6-a1a7bbbaf2e9</api_token>
461
+ <api_index>cccc8aea-ebcd-5466-8698-3657a3aa1169</api_index>
462
+ <debug>1</debug>
463
+ <debug_file>tracking.log</debug_file>
464
+ <page_types>all</page_types>
465
+ </tracking_groups>
466
+ </targetbay_tracking>
467
+ </default>
468
+
469
+
470
+ <!-- ACL for tracking configurations -->
471
+ <adminhtml>
472
+ <acl>
473
+ <resources>
474
+ <admin>
475
+ <children>
476
+ <system>
477
+ <children>
478
+ <config>
479
+ <children>
480
+ <targetbay_tracking translate="title"
481
+ module="tracking">
482
+ <title>Tracking</title>
483
+ </targetbay_tracking>
484
+ </children>
485
+ </config>
486
+ </children>
487
+ </system>
488
+ </children>
489
+ </admin>
490
+ </resources>
491
+ </acl>
492
+ </adminhtml>
493
+ </config>
app/code/community/Targetbay/Tracking/etc/system.xml ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /*
4
+ * @author Targetbay
5
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
6
+ * @package Targetbay_Tracking
7
+ */
8
+ -->
9
+ <config>
10
+ <tabs>
11
+ <tracking translate="label" module="tracking">
12
+ <label>tracking</label>
13
+ <sort_order>100</sort_order>
14
+ </tracking>
15
+ </tabs>
16
+ <sections>
17
+ <targetbay_tracking translate="label" module="tracking">
18
+ <label>Tracking Configurations</label>
19
+ <tab>tracking</tab>
20
+ <sort_order>1001</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>1</show_in_store>
24
+ <groups>
25
+ <tracking_groups translate="label" module="tracking">
26
+ <label>Tracking Setup</label>
27
+ <frontend_type>text</frontend_type>
28
+ <sort_order>10</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ <expanded>1</expanded>
33
+ <fields>
34
+ <enabled translate="label">
35
+ <label>Enable Module:</label>
36
+ <comment>Enable or disable the tracking module.</comment>
37
+ <frontend_type>select</frontend_type>
38
+ <source_model>adminhtml/system_config_source_enabledisable
39
+ </source_model>
40
+ <sort_order>10</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </enabled>
45
+ <hostname translate="label">
46
+ <label>Hostname</label>
47
+ <comment>Enter hostname to track (ie: example.com).</comment>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>20</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </hostname>
54
+
55
+ <api_token translate="label">
56
+ <label>Api Token</label>
57
+ <comment></comment>
58
+ <frontend_type>text</frontend_type>
59
+ <sort_order>80</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>1</show_in_store>
63
+ </api_token>
64
+
65
+ <api_index translate="label">
66
+ <label>Api Index</label>
67
+ <comment></comment>
68
+ <frontend_type>text</frontend_type>
69
+ <sort_order>140</sort_order>
70
+ <show_in_default>1</show_in_default>
71
+ <show_in_website>1</show_in_website>
72
+ <show_in_store>1</show_in_store>
73
+ </api_index>
74
+
75
+ <api_status translate="label">
76
+ <label>Api Status</label>
77
+ <frontend_type>select</frontend_type>
78
+ <source_model>tracking/system_config_source_status</source_model>
79
+ <sort_order>145</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
+ </api_status>
84
+
85
+ <page_types translate="label">
86
+ <label>Select Page Types</label>
87
+ <frontend_type>multiselect</frontend_type>
88
+ <source_model>tracking/system_config_source_page</source_model>
89
+ <sort_order>160</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>
93
+ </page_types>
94
+
95
+ <tracking_type translate="label">
96
+ <label>Select Tracking Type</label>
97
+ <frontend_type>select</frontend_type>
98
+ <source_model>tracking/system_config_source_tracking</source_model>
99
+ <sort_order>162</sort_order>
100
+ <show_in_default>1</show_in_default>
101
+ <show_in_website>1</show_in_website>
102
+ <show_in_store>1</show_in_store>
103
+ <comment>Full Page Cache enabled in site choose manual or choose automatic</comment>
104
+ </tracking_type>
105
+
106
+ <tracking_script translate="label">
107
+ <label>Tracking Script</label>
108
+ <frontend_type>textarea</frontend_type>
109
+ <sort_order>180</sort_order>
110
+ <show_in_default>1</show_in_default>
111
+ <show_in_website>1</show_in_website>
112
+ <show_in_store>1</show_in_store>
113
+ </tracking_script>
114
+
115
+ <reviews_per_page translate="label">
116
+ <label>Reviews per page</label>
117
+ <frontend_type>text</frontend_type>
118
+ <sort_order>176</sort_order>
119
+ <show_in_default>1</show_in_default>
120
+ <show_in_website>1</show_in_website>
121
+ <show_in_store>1</show_in_store>
122
+ </reviews_per_page>
123
+
124
+ <disable_email translate="label">
125
+ <label>Disable Email:</label>
126
+ <comment>Yes - Disable magento customer welcome mail.</comment>
127
+ <frontend_type>select</frontend_type>
128
+ <source_model>tracking/system_config_source_yesno</source_model>
129
+ <sort_order>180</sort_order>
130
+ <show_in_default>1</show_in_default>
131
+ <show_in_website>1</show_in_website>
132
+ <show_in_store>1</show_in_store>
133
+ </disable_email>
134
+
135
+ <debug translate="label">
136
+ <label>Enable Debug:</label>
137
+ <comment>Enable or disable the Debugging.</comment>
138
+ <frontend_type>select</frontend_type>
139
+ <source_model>adminhtml/system_config_source_enabledisable
140
+ </source_model>
141
+ <sort_order>182</sort_order>
142
+ <show_in_default>1</show_in_default>
143
+ <show_in_website>1</show_in_website>
144
+ <show_in_store>1</show_in_store>
145
+ </debug>
146
+
147
+ <debug_file translate="label">
148
+ <label>Log File Name</label>
149
+ <comment>Log the info</comment>
150
+ <frontend_type>text</frontend_type>
151
+ <sort_order>200</sort_order>
152
+ <show_in_default>1</show_in_default>
153
+ <show_in_website>1</show_in_website>
154
+ <show_in_store>1</show_in_store>
155
+ </debug_file>
156
+ </fields>
157
+ </tracking_groups>
158
+ </groups>
159
+ </targetbay_tracking>
160
+ </sections>
161
+ </config>
app/design/frontend/base/default/layout/tracking.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /*
4
+ * @author Targetbay
5
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
6
+ * @package Targetbay_Tracking
7
+ */
8
+ -->
9
+ <layout version="1.0.0">
10
+ <default>
11
+ <reference name="before_body_end">
12
+ <block type="tracking/tracking" name="innpltracking" as="innpltracking" />
13
+ </reference>
14
+ </default>
15
+ <catalog_product_view>
16
+ <reference name="product.info.tabs">
17
+ <action method="unsetChild">
18
+ <child>review</child>
19
+ </action>
20
+ </reference>
21
+ <reference name="product.info.additional">
22
+ <remove name="product.reviews"/>
23
+ <block type="tracking/product_review" name="innpl-product-review" before="-" as="innpl-product-review" />
24
+ </reference>
25
+ </catalog_product_view>
26
+ </layout>
app/design/frontend/base/default/template/tracking/product/review.phtml ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="targetbay_reviews"></div>
2
+ <?php $product = Mage::registry('current_product'); ?>
3
+ <?php $_helper = $this->helper('catalog/output'); ?>
4
+ <?php $richSnippets = Mage::helper('tracking')->getRichSnippets(); ?>
5
+
6
+ <?php $productSku = $_helper->productAttribute($product, $product->getSku(), 'sku'); ?>
7
+ <?php $productName = $_helper->productAttribute($product, $product->getName(), 'name'); ?>
8
+ <?php if(!empty($richSnippets) && $richSnippets['average_score'] > 0): ?>
9
+ <div id="<?php echo $productSku; ?>" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
10
+ <span itemprop="bestRating" content="5"></span>
11
+ <span itemprop="ratingValue" content="<?php echo $richSnippets['average_score']; ?>"></span>
12
+ <span itemprop="reviewCount" content="<?php echo $richSnippets['reviews_count']; ?>"></span>
13
+ <div itemprop="itemReviewed" itemscope itemtype="http://schema.org/Thing">
14
+ <span itemprop="name" content="<?php echo $productName; ?>"></span>
15
+ </div>
16
+ </div>
17
+ <?php if($richSnippets['reviews_count'] > 0): ?>
18
+ <?php foreach($richSnippets['reviews'] as $key => $aggregateReviewDetails): ?>
19
+ <?php $reviewId = $aggregateReviewDetails->_id; ?>
20
+ <?php $reviewTitle = $aggregateReviewDetails->_source->review_title; ?>
21
+ <?php $review = $aggregateReviewDetails->_source->review; ?>
22
+ <?php $timestamp = $aggregateReviewDetails->_source->timestamp; ?>
23
+ <?php $reviewRating = $aggregateReviewDetails->_source->review_rating; ?>
24
+ <?php $userName = $aggregateReviewDetails->_source->user_name; ?>
25
+ <div itemprop="review" id="<?php echo 'tb-review-'.$key; ?>" itemscope itemtype="http://schema.org/Review" data-reviewid="<?php echo $reviewId; ?>">
26
+ <span itemprop="name" content="<?php echo $reviewTitle; ?>"></span>
27
+ <span itemprop="description" content="<?php echo $review; ?>"></span>
28
+ <span itemprop="datePublished" content="<?php echo date('m/d/Y', $timestamp); ?>"></span>
29
+ <div itemprop="itemReviewed" itemscope itemtype="http://schema.org/Thing">
30
+ <span itemprop="name" content="<?php echo $productName; ?>"></span>
31
+ </div>
32
+ <div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
33
+ <span itemprop="ratingValue" content="<?php echo $reviewRating; ?>"></span>
34
+ <span itemprop="bestRating" content="5"></span>
35
+ </div>
36
+ <div itemprop="author" itemscope itemtype="http://schema.org/Thing">
37
+ <span itemprop="name" content="<?php echo $userName; ?>"></span>
38
+ </div>
39
+ </div>
40
+ <?php endforeach; ?>
41
+ <?php endif; ?>
42
+ <?php else: ?>
43
+ <div id="<?php echo $productSku; ?>"></div>
44
+ <?php endif; ?>
app/design/frontend/base/default/template/tracking/session/tracking.phtml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ //echo Mage::helper ( 'tracking' )->getSessionTrackingJs ();
3
+
4
+ ?>
app/design/frontend/base/default/template/tracking/tracking.phtml ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $pageVisitData = ''; $pageVisitUrl = ''; $trackingTypeVal = '';
3
+ $pname = ''; $pid = ''; $purl = ''; $pimage = '';
4
+ $controllerData = array('index','category','product');
5
+ $controllername = Mage::app()->getRequest()->getControllerName();
6
+ $modulename = Mage::app()->getRequest()->getModuleName();
7
+ $trackingHelper = Mage::helper('tracking');
8
+ $userSession = Mage::getSingleton('customer/session');
9
+
10
+ $hostUrl = $trackingHelper->getHostname();
11
+ $apiToken = $trackingHelper->getApiToken();
12
+ $apiKey = $trackingHelper->getApiIndex();
13
+ $apiStatus = $trackingHelper->getApiStatus();
14
+ $vistorId = Mage::getSingleton('core/session')->getTrackingSessionId();
15
+ $vistorName = Targetbay_Tracking_Helper_Data::ANONYMOUS_USER;
16
+
17
+ $moduleVersion = $trackingHelper->getProductVersion();
18
+ $trackingType = $trackingHelper->getTrackingType();
19
+
20
+ if($trackingType == 1) :
21
+ $pageVisitUrl = $trackingHelper->getApiUrl();
22
+ $pageVisitData = $trackingHelper->getPageInfo();
23
+ $trackingTypeVal = $trackingType;
24
+ endif;
25
+
26
+ if($modulename == 'catalog' && $controllername == 'product') {
27
+ $product = Mage::registry('current_product');
28
+ $pname = addslashes($product->getName());
29
+ $pid = $product->getId();
30
+ $pimage = $trackingHelper->getImageUrl($product, 'image');
31
+ $purl = Mage::getUrl().$product->getUrlPath();
32
+ }
33
+ $trackingScript = $trackingHelper->getTrackingScript();
34
+
35
+ if($trackingScript) {
36
+ $trackingCode = $trackingScript;
37
+ } else {
38
+ $trackingCode = 'tbTrack: true,
39
+ tbMessage: true,
40
+ tbReview: {
41
+ tbSiteReview: true,
42
+ tbProductReview: true,
43
+ tbBulkReview: true,
44
+ tbQa: true
45
+ }';
46
+ }
47
+ ?>
48
+
49
+ <div id="targetbay_message"></div>
50
+ <div id="targetbay_site_reviews"></div>
51
+
52
+ <script type="text/javascript">
53
+ tbConfig = {
54
+ apiStatus: '<?php echo $apiStatus; ?>',
55
+ apiKey: '<?php echo $apiKey;?>',
56
+ apiToken: '<?php echo $apiToken;?>',
57
+ apiUrl: '<?php echo $hostUrl;?>',
58
+ apiVersion: 'v1',
59
+ trackingType: '<?php echo $trackingType;?>',
60
+ moduleVersion:'<?php echo $moduleVersion; ?>',
61
+ productName: '<?php echo $pname; ?>',
62
+ productId: '<?php echo $pid; ?>',
63
+ productImageUrl: '<?php echo $pimage; ?>',
64
+ productUrl: '<?php echo $purl; ?>',
65
+ userId: '<?php echo $userSession->isLoggedIn()?$userSession->getId():$vistorId?>',
66
+ userMail: '<?php echo $userSession->isLoggedIn()?$userSession->getCustomer()->getEmail():''?>',
67
+ userName: '<?php echo $userSession->isLoggedIn()?$userSession->getCustomer()->getName():$vistorName?>',
68
+ userAvatar: '',
69
+ pageUrl: '<?php echo $pageVisitUrl;?>',
70
+ pageData: '<?php echo json_encode($pageVisitData);?>',
71
+ <?php echo $trackingCode; ?>
72
+
73
+ };
74
+ (function (d, u, tb) {
75
+ var s = d.scripts[0],
76
+ i = u.length, g;
77
+ while (i--) {
78
+ g = d.createElement('script');
79
+ g.src = 'https://' + tb.apiStatus + '.targetbay.com/js/tb-' + u[i] + '.js';
80
+ g.type = 'text/javascript';
81
+ g.async = 'true';
82
+ s.parentNode.insertBefore(g, s);
83
+ }
84
+ })(document, [
85
+ 'track'
86
+ ], tbConfig);
87
+ </script>
88
+ <?php $siteReviewSnippets = $trackingHelper->getSiteReviewSnippets();?>
89
+ <?php if(!empty($siteReviewSnippets) && $siteReviewSnippets['average_score'] > 0): ?>
90
+ <div itemscope itemtype="http://schema.org/Organization">
91
+ <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
92
+ <span itemprop="bestRating" content="5"></span>
93
+ <span itemprop="ratingValue" content="<?php echo $siteReviewSnippets['average_score']; ?>"></span>
94
+ <span itemprop="reviewCount" content="<?php echo $siteReviewSnippets['reviews_count']; ?>"></span>
95
+ </div>
96
+ <?php if($siteReviewSnippets['reviews_count'] > 0): ?>
97
+ <?php foreach($siteReviewSnippets['reviews'] as $key => $aggregateReviewDetails): ?>
98
+ <?php $reviewId = $aggregateReviewDetails->_id; ?>
99
+ <?php $reviewTitle = $aggregateReviewDetails->_source->title; ?>
100
+ <?php $review = $aggregateReviewDetails->_source->message;; ?>
101
+ <?php $timestamp = $aggregateReviewDetails->_source->timestamp; ?>
102
+ <?php $reviewRating = $aggregateReviewDetails->_source->review_rating; ?>
103
+ <?php $userName = $aggregateReviewDetails->_source->user_name; ?>
104
+
105
+ <div itemprop="review" id="<?php echo 'tb-site-review-'.$key; ?>" itemscope itemtype="http://schema.org/Review" data-reviewid="<?php echo $reviewId; ?>">
106
+ <span itemprop="name" content="<?php echo $reviewTitle; ?>"></span>
107
+ <span itemprop="description" content="<?php echo $review; ?>"></span>
108
+ <span itemprop="datePublished" content="<?php echo date('m/d/Y', $timestamp); ?>"></span>
109
+ <div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
110
+ <span itemprop="ratingValue" content="<?php echo $reviewRating; ?>"></span>
111
+ <span itemprop="bestRating" content="5"></span>
112
+ </div>
113
+ <div itemprop="author" itemscope itemtype="http://schema.org/Thing">
114
+ <span itemprop="name" content="<?php echo $userName; ?>"></span>
115
+ </div>
116
+ </div>
117
+ <?php endforeach; ?>
118
+ <?php endif; ?>
119
+ </div>
120
+ <?php endif; ?>
app/etc/modules/Targetbay_Tracking.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /*
4
+ * @author Targetbay
5
+ * @copyright 2016 Sathishkumar Mariappan <sathishkumar.m@innoppl.com>
6
+ * @package Targetbay_Tracking
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Targetbay_Tracking>
12
+ <active>true</active>
13
+ <codePool>community</codePool>
14
+ <version>5.1.1</version>
15
+ </Targetbay_Tracking>
16
+ </modules>
17
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Targetbay_Tracking</name>
4
+ <version>5.1.1</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Targetbay's Personalization platform continuously profiles in real-time, opening up the scope for behavioral targeting.</summary>
10
+ <description>Making every interaction count and engaging customers with relevant messages will improve the chances of conversion exponentially. You can profile and segment users based on various parameters and actions, the data from which will form the basis for your customer engagement objectives.You can create triggers based on customer engagement objectives to deliver personalized messages. Your newsletter campaigns can also be personalized to deliver better customer engagement results. And all of this can be achieved with the help of our ecommerce-based email personalization platform.</description>
11
+ <notes>Making every interaction count and engaging customers with relevant messages will improve the chances of conversion exponentially. You can profile and segment users based on various parameters and actions, the data from which will form the basis for your customer engagement objectives.You can create triggers based on customer engagement objectives to deliver personalized messages. Your newsletter campaigns can also be personalized to deliver better customer engagement results. And all of this can be achieved with the help of our ecommerce-based email personalization platform.</notes>
12
+ <authors><author><name>Targetbay</name><user>Targetbay</user><email>sathishkumar.m@innoppl.com</email></author></authors>
13
+ <date>2017-01-16</date>
14
+ <time>06:53:56</time>
15
+ <contents><target name="magecommunity"><dir name="Targetbay"><dir name="Tracking"><dir name="Block"><dir name="Product"><file name="Product.php" hash="790ea5df53326319216cf7a8c4ad8c81"/><file name="Review.php" hash="14f60843424127913bc8f1d8b0b7ac88"/></dir><dir name="Session"><file name="Tracking.php" hash="bead621eadabe0428a99f12ff4f4f60a"/></dir><file name="Tracking.php" hash="d78910db0d380d8f9c88dd55e4a174ed"/></dir><dir name="Helper"><file name="Data.php" hash="e8cb3842674c1a51cf8407d58e7456e5"/></dir><dir name="Model"><dir name="Api2"><dir name="Cartitem"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="e249ac528ec557cc6736387ff85e26ec"/></dir><dir name="Guest"><file name="V1.php" hash="45876ad828c254a3a6bb808bd9174f29"/></dir></dir></dir><file name="Cartitem.php" hash="f0de9fec4777d78a8d621b92295650ae"/><dir name="Category"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="74764d41a1d32bfb0ad4825d40e8cf46"/></dir><dir name="Guest"><file name="V1.php" hash="2dfc77fcf40841a6fbcb4e92b18c5cbe"/></dir></dir></dir><file name="Category.php" hash="37c664ba07ff52d64787ba635492b862"/><dir name="Createsubscription"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="7d1b2e26e7a5a37459f31dd5b0cb6741"/></dir><dir name="Guest"><file name="V1.php" hash="6c94923e0e86c75b90268e70f91ddb38"/></dir></dir></dir><file name="Createsubscription.php" hash="45dc64e2c1c37293f13a9eab8edd94d0"/><dir name="Customer"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="296c8a85e3c4ba7a0cacf6a0c80c5d06"/></dir><dir name="Guest"><file name="V1.php" hash="1ca174a22acfe731c0e70777c098b4f3"/></dir></dir></dir><file name="Customer.php" hash="6e4adecce83bf453e977a837ed77b0a4"/><dir name="Orders"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="f5b3a992b2e9486558ff8ddd7fd597dc"/></dir><dir name="Guest"><file name="V1.php" hash="a60f6181469b7e5dec6080956674e7e5"/></dir></dir></dir><dir name="Product"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="227c45f1d669a62c85e96a23636ed9f1"/><file name="V1.php~" hash="cb0e0f6f152441bfbd489588a5299b20"/></dir><dir name="Guest"><file name="V1.php" hash="af33a4ecf52229145f59b2b9bad096bc"/></dir></dir></dir><dir name="Review"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="60f0e620b10d0c9bc336bd47236af4f0"/></dir><dir name="Guest"><file name="V1.php" hash="71009313e064b458923062c0ee5b9ad4"/></dir></dir></dir><file name="Review.php" hash="2d6fb0e0141fc73f61e2a586e2fa895d"/><dir name="Shipment"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="eab736400f2275a32603e0b3f1d4351c"/></dir><dir name="Guest"><file name="V1.php" hash="8607da53bca20022f1781ee159b2fc3c"/></dir></dir></dir><file name="Shipment.php" hash="17756fb5e6411bbb27fd0806ce156d74"/><dir name="Stores"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="27e7e2b3fd927e91456b9e529b226522"/></dir><dir name="Guest"><file name="V1.php" hash="8dd09e20ffaef75837bfc00ccbc1c282"/></dir></dir></dir><file name="Stores.php" hash="f5eb4d00382b03c2418f83eb8b7d0ad3"/><dir name="Subscriber"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="65f5f38d5521687b6a106e29a502b7c9"/></dir><dir name="Guest"><file name="V1.php" hash="1fb1e146c1398d2858f5a088a1d59d16"/></dir></dir></dir><file name="Subscriber.php" hash="43f2f4f9c8b01b07f3130cf7488342d1"/><dir name="Totalcartiteminfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="65dffb80d635d17d5599a9ee1a61a35e"/></dir><dir name="Guest"><file name="V1.php" hash="c4ce67530cc5ddd7e306a1f95250a00c"/></dir></dir></dir><file name="Totalcartiteminfo.php" hash="b0b10b2a6d42ddecd0e4d97834090be7"/><dir name="Totalcategoryinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="be76b164dbb7cc439a1bbd8a9aa82a53"/></dir><dir name="Guest"><file name="V1.php" hash="d6ea3c89fa7e7396614d983c026c7907"/></dir></dir></dir><file name="Totalcategoryinfo.php" hash="06b6428e59e402ad92f8404e42ce5b35"/><dir name="Totalcustomerinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="def08bb44fc493c15b0a98c5717f68a8"/></dir><dir name="Guest"><file name="V1.php" hash="e0efa78eff478bf0204da6b2f5c95659"/></dir></dir></dir><file name="Totalcustomerinfo.php" hash="fdf343e2d69375826c94e5ce3988cc01"/><dir name="Totalinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="0bf6291950d09e4feea261b3e75ab5a4"/></dir><dir name="Guest"><file name="V1.php" hash="d853313e63bd6708c5669dd42cb51e1b"/></dir></dir></dir><file name="Totalinfo.php" hash="c5a797bd61744e897cefe6287fce5d7d"/><dir name="Totalorderinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="ce01e5d386310382fbc9b06531194b45"/></dir><dir name="Guest"><file name="V1.php" hash="b24afbd009b16df4106af72c475d0ca0"/></dir></dir></dir><file name="Totalorderinfo.php" hash="69d3cb8c8d07d53b43561050ba182580"/><dir name="Totalproductinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="f5519b587214660983da9c76ed472240"/></dir><dir name="Guest"><file name="V1.php" hash="e10ed910edb0cc8981e89302ed03d65f"/></dir></dir></dir><file name="Totalproductinfo.php" hash="5724d79872c49cc2950c93489dbd3b6b"/><dir name="Totalreviewinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="7d753cc08978ac86022bbb5754095064"/></dir><dir name="Guest"><file name="V1.php" hash="192f46027f72e1a668a30ab7d44cadf5"/></dir></dir></dir><file name="Totalreviewinfo.php" hash="fa652146fdf0c6939cd6ef36ca5ca696"/><dir name="Totalshipmentinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="041b6b543d49b78710f71791511955d6"/></dir><dir name="Guest"><file name="V1.php" hash="5ec014ecc06ea8a72c8188acb1340308"/></dir></dir></dir><file name="Totalshipmentinfo.php" hash="d1db98b2163db7453c6a32804482c074"/><dir name="Totalsubscriberinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="908a9d13f2a65b0bae45e9b35e00d232"/></dir><dir name="Guest"><file name="V1.php" hash="230ad7202d191bd9e93c1b9fd41f12bd"/></dir></dir></dir><file name="Totalsubscriberinfo.php" hash="6932199b92398c7a08026fc045b34182"/><dir name="Totalwishlistinfo"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="f938b29721d1b20cdd0d4ea7a6a6aac8"/></dir><dir name="Guest"><file name="V1.php" hash="5f44c6b021e6910458ff6140358540a1"/></dir></dir></dir><file name="Totalwishlistinfo.php" hash="9d24d05506d74208a72322f91fc03c7a"/><dir name="Updatesubscription"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="f1014aaec990673e76dec42e66d52a33"/></dir><dir name="Guest"><file name="V1.php" hash="76639c8508b730322b8d5d29bbfe7ff8"/></dir></dir></dir><file name="Updatesubscription.php" hash="1dc100c9b09c83fed1f2b343107f7a2b"/><dir name="Wishlist"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="666cf3408575628734771774afeeb915"/></dir><dir name="Guest"><file name="V1.php" hash="44671ff4a131b0fc35751440b0c03790"/></dir></dir></dir><file name="Wishlist.php" hash="41015ddf11163ec6efc21ca02d48b3eb"/></dir><file name="Customer.php" hash="4d8a9b5726458a01b0cf4eedee27f84f"/><file name="Observer.php" hash="96408f95c08e597b5078bdae2f580b2f"/><file name="Subscriber.php" hash="7c9a69c0340d85fb78149b2d1e5a3f6f"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Page.php" hash="9f110c8010f7274aee995030dbcf37e4"/><file name="Status.php" hash="17aed527b9c4b30f2d4350cf64b3a50a"/><file name="Tracking.php" hash="be2a32ac4523ee58de1b82c228796731"/><file name="Version.php" hash="27118fa886e6c21aa259d399d211b82d"/><file name="Yesno.php" hash="b99b00ea683b4c7be69c2b17b3cacae8"/></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="43a69e4f131f7f42b68ed36988c85526"/></dir><dir name="etc"><file name="api2.xml" hash="0df41f76a730b175db2506c97d9dbb8a"/><file name="config.xml" hash="9bb407597203357998c5ba8131b6c1ca"/><file name="system.xml" hash="7cdf4973563deb45cfea65683603ea7c"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="tracking.xml" hash="b6c90bd1d9edff73db3a1c227046b191"/></dir><dir name="template"><dir name="tracking"><dir><dir name="product"><file name="review.phtml" hash="18722f60f77ea24e1c49c1c320e8a44d"/></dir><dir name="session"><file name="tracking.phtml" hash="5e946c9e929f6b324de083e014ede6a3"/></dir></dir><file name="tracking.phtml" hash="0a2460789061c52de21f853ab80db9ad"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Targetbay_Tracking.xml" hash="b0f324d391c606c536c063e9ebe910a9"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>7.0.11</max></php></required></dependencies>
18
+ </package>