increasingly_key - Version 1.0.1

Version Notes

dddd

Download this release

Release Info

Developer Increasingly
Extension increasingly_key
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (40) hide show
  1. app/code/community/Increasingly/Analytics/Block/Addtocart.php +46 -0
  2. app/code/community/Increasingly/Analytics/Block/Adminhtml/DataIntegration.php +178 -0
  3. app/code/community/Increasingly/Analytics/Block/Cart.php +161 -0
  4. app/code/community/Increasingly/Analytics/Block/Category.php +68 -0
  5. app/code/community/Increasingly/Analytics/Block/Element.php +69 -0
  6. app/code/community/Increasingly/Analytics/Block/Embed.php +63 -0
  7. app/code/community/Increasingly/Analytics/Block/Pagetype.php +80 -0
  8. app/code/community/Increasingly/Analytics/Block/Product.php +92 -0
  9. app/code/community/Increasingly/Analytics/Block/Track.php +63 -0
  10. app/code/community/Increasingly/Analytics/Helper/Data.php +337 -0
  11. app/code/community/Increasingly/Analytics/Helper/DateFormatter.php +38 -0
  12. app/code/community/Increasingly/Analytics/Helper/PriceFormatter.php +170 -0
  13. app/code/community/Increasingly/Analytics/Helper/ProductFormatter.php +197 -0
  14. app/code/community/Increasingly/Analytics/Model/Base.php +52 -0
  15. app/code/community/Increasingly/Analytics/Model/Bundle.php +36 -0
  16. app/code/community/Increasingly/Analytics/Model/DataIntegration.php +65 -0
  17. app/code/community/Increasingly/Analytics/Model/Meta/Product.php +509 -0
  18. app/code/community/Increasingly/Analytics/Model/Mysql4/Bundle.php +40 -0
  19. app/code/community/Increasingly/Analytics/Model/Mysql4/Bundle/Collection.php +40 -0
  20. app/code/community/Increasingly/Analytics/Model/Observer.php +513 -0
  21. app/code/community/Increasingly/Analytics/Model/Product.php +42 -0
  22. app/code/community/Increasingly/Analytics/controllers/AddbundletocartController.php +245 -0
  23. app/code/community/Increasingly/Analytics/controllers/Adminhtml/DataIntegrationController.php +125 -0
  24. app/code/community/Increasingly/Analytics/controllers/ProductsApiController.php +156 -0
  25. app/code/community/Increasingly/Analytics/etc/config.xml +249 -0
  26. app/code/community/Increasingly/Analytics/sql/setup/mysql-install-1.0.0.php +29 -0
  27. app/design/adminhtml/default/default/layout/increasingly_analytics.xml +8 -0
  28. app/design/adminhtml/default/default/template/increasingly/dataintegration.phtml +104 -0
  29. app/design/frontend/base/default/layout/increasingly_analytics.xml +226 -0
  30. app/design/frontend/base/default/template/increasingly/addtocart.phtml +62 -0
  31. app/design/frontend/base/default/template/increasingly/cart.phtml +67 -0
  32. app/design/frontend/base/default/template/increasingly/category.phtml +38 -0
  33. app/design/frontend/base/default/template/increasingly/element.phtml +40 -0
  34. app/design/frontend/base/default/template/increasingly/embed.phtml +35 -0
  35. app/design/frontend/base/default/template/increasingly/pagetype.phtml +65 -0
  36. app/design/frontend/base/default/template/increasingly/product.phtml +76 -0
  37. app/design/frontend/base/default/template/increasingly/track.phtml +71 -0
  38. app/etc/modules/Increasingly_Analytics.xml +12 -0
  39. package.xml +54 -0
  40. skin/adminhtml/default/default/increasingly/loader.gif +0 -0
app/code/community/Increasingly/Analytics/Block/Addtocart.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Adds the `add-to-cart` script.
30
+ *
31
+ */
32
+ class Increasingly_Analytics_Block_Addtocart extends Mage_Core_Block_Template
33
+ {
34
+ /**
35
+ * Render script if the module is enabled for the current store.
36
+ *
37
+ * @return string
38
+ */
39
+ protected function _toHtml()
40
+ {
41
+ if (!Mage::helper('increasingly_analytics')->isEnabled()) {
42
+ return '';
43
+ }
44
+ return parent::_toHtml();
45
+ }
46
+ }
app/code/community/Increasingly/Analytics/Block/Adminhtml/DataIntegration.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Add import model and view for enabling increasingly
29
+ *
30
+ *
31
+ */
32
+ class Increasingly_Analytics_Block_Adminhtml_DataIntegration extends Mage_Adminhtml_Block_Widget_Form_Container
33
+ {
34
+ /**
35
+ * Set template for the data import from Magento to Increasingly API
36
+ */
37
+ protected function _construct()
38
+ {
39
+ parent::_construct();
40
+ $this->setTemplate('increasingly/dataintegration.phtml');
41
+ }
42
+
43
+ /**
44
+ * Get import model instance
45
+ *
46
+ * @return Increasingly_Analytics_Model_Import
47
+ */
48
+ public function getImport()
49
+ {
50
+ return Mage::getSingleton('increasingly_analytics/DataIntegration');
51
+ }
52
+
53
+ /**
54
+ * @return Increasingly Analytics Installation Status
55
+ */
56
+ public function renderIncreasinglyEnableStatus($selected=0)
57
+ {
58
+ $options=array();
59
+ $options[]=array('label'=>'Yes','value'=>1);
60
+ $options[]=array('label'=>'No','value'=>0);
61
+
62
+ $html=$this->_getSelectHtml('increasingly_analytics_settings_enable',$options,$selected,'select','increasingly_analytics_settings_enable');
63
+ return $html;
64
+ }
65
+
66
+ /**
67
+ * @return Increasingly Analytics Admin Settings Select widget
68
+ */
69
+ private function _getSelectHtml($name,$options,$default=0,$class='',$id='')
70
+ {
71
+ $select='<select name="'.$name.'" id="'.$id.'" onchange=loadHtmlFields(this.value) class="'.$class.'">';
72
+ foreach ($options as $option)
73
+ {
74
+ $selected='';
75
+ if($option['value']==$default)
76
+ {
77
+ $selected='selected';
78
+ }
79
+ $select.='<option value="'.$option['value'].'" '.$selected.'>'.$option['label'].'</option>';
80
+ }
81
+
82
+ $select.='</select>';
83
+
84
+ return $select;
85
+ }
86
+
87
+ /**
88
+ * Render script if the module is enabled for the current store.
89
+ *
90
+ * @return string
91
+ */
92
+ protected function _toHtml()
93
+ {
94
+ $html = parent::_toHtml();
95
+ return $html;
96
+ }
97
+
98
+ /**
99
+ * Return element html
100
+ *
101
+ * @param Varien_Data_Form_Element_Abstract $element
102
+ * @return string
103
+ */
104
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
105
+ {
106
+ return $this->_toHtml();
107
+ }
108
+
109
+ /**
110
+ * Render Increasingly analytics store admin UX for setting the configurations.
111
+ *
112
+ * @return string
113
+ */
114
+ public function getHtmlFields($selected=0)
115
+ {
116
+ $htmlContent = '';
117
+ $display = 'display:display';
118
+ $importButtonClass = 'scalable';
119
+ $isEnabledOrDisabled = 'enabled';
120
+
121
+ if($selected == 0)
122
+ {
123
+ $display = 'display:none';
124
+ $importButtonClass = 'disabled';
125
+ $isEnabledOrDisabled = 'disabled';
126
+ }
127
+
128
+ $htmlContent ='<tr id="row_increasingly_analytics_settings_api_key" style="'.$display.'">';
129
+ $htmlContent = $htmlContent . '<td class="label"><label for="increasingly_analytics_settings_api_key"> API Key</label></td>';
130
+ $htmlContent = $htmlContent . '<td class="value"><input id="increasingly_analytics_settings_api_key"';
131
+ $htmlContent = $htmlContent . 'name="increasingly_analytics_settings_api_key"';
132
+ $htmlContent = $htmlContent . 'value="'.Mage::getStoreConfig('increasingly_analytics/settings/api_key').'"';
133
+ $htmlContent = $htmlContent . 'class="input-text" type="text"/></td></tr>';
134
+
135
+ $htmlContent = $htmlContent . '<tr id="row_increasingly_analytics_settings_api_secret" style="'.$display.'">';
136
+ $htmlContent = $htmlContent . '<td class="label"><label for="increasingly_analytics_settings_api_secret"> API Secret</label></td>';
137
+ $htmlContent = $htmlContent . '<td class="value"><input id="increasingly_analytics_settings_api_secret"';
138
+ $htmlContent = $htmlContent . 'name="increasingly_analytics_settings_api_secret"';
139
+ $htmlContent = $htmlContent . 'value="'.Mage::getStoreConfig('increasingly_analytics/settings/api_secret').'"';
140
+ $htmlContent = $htmlContent . 'class="input-text" type="text"/></td></tr>';
141
+
142
+ $htmlContent = $htmlContent . '<tr id="row_increasingly_analytics_settings_import" style="'.$display.'">';
143
+ $htmlContent = $htmlContent . '<td class="label"><label for="increasingly_analytics_settings_import"> Import orders</label></td>';
144
+ $htmlContent = $htmlContent . '<td class="value"><div style="float: left;">';
145
+
146
+ if($selected == 0)
147
+ {
148
+ $htmlContent = $htmlContent . '<p>Please enable the extension to import order data to increasingly by providing API key and secret received while registering to increasingly.</p>';
149
+ }
150
+ else
151
+ {
152
+ $htmlContent = $htmlContent . '<h3>Importing your historical data</h3><p>';
153
+ $htmlContent = $htmlContent . 'Increasingly will consider previous order data for analysis to recommend product bundles.';
154
+ $htmlContent = $htmlContent . '</p></div><div style="clear:both"></div>';
155
+
156
+ $htmlContent = $htmlContent . '<button id="increasingly_button" title="Import data" type="button" class="'.$importButtonClass.'"';
157
+ $htmlContent = $htmlContent . 'onclick="javascript:import_increasingly(); return false;" '.$isEnabledOrDisabled.'>';
158
+ $htmlContent = $htmlContent . '<span><span><span>Import data</span></span></span></button>';
159
+ }
160
+
161
+ $htmlContent = $htmlContent . '<div style="clear:both"></div><div id="increasingly_import_status"></div>';
162
+ $htmlContent = $htmlContent . '<div style="clear:both"></div></td></tr>';
163
+
164
+ $html=$htmlContent;
165
+
166
+ return $html;
167
+
168
+ }
169
+
170
+ /**
171
+ * Return Import action url for button
172
+ * @return string
173
+ */
174
+ public function getOrderImportUrl()
175
+ {
176
+ return Mage::helper('adminhtml')->getUrl("*/*/importOrder", array('isAsync'=> true));
177
+ }
178
+ }
app/code/community/Increasingly/Analytics/Block/Cart.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Shopping cart content tagging block.
30
+ * Adds meta-data to the HTML document for shopping cart content.
31
+ */
32
+ class Increasingly_Analytics_Block_Cart extends Mage_Checkout_Block_Cart_Abstract
33
+ {
34
+
35
+ /**
36
+ * Render shopping cart content as hidden meta data if the module is
37
+ * enabled for the current store.
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ if (!Mage::helper('increasingly_analytics')->isEnabled()) {
44
+ return '';
45
+ }
46
+ return parent::_toHtml();
47
+ }
48
+
49
+ /**
50
+ * Returns the product id for a quote item.
51
+ * Always try to find the "parent" product ID if the product is a child of
52
+ * another product type. We do this because it is the parent product that
53
+ * we tag on the product page, and the child does not always have it's own
54
+ * product page. This is important because it is the tagged info on the
55
+ * product page that is used to generate product bundles.
56
+ *
57
+ * @param Mage_Sales_Model_Quote_Item $item the quote item model.
58
+ *
59
+ * @return int|string
60
+ */
61
+ public function getProductId($item)
62
+ {
63
+ $parentItem = $item->getOptionByCode('product_type');
64
+ if (!is_null($parentItem)) {
65
+ return $parentItem->getProductId();
66
+ } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
67
+ /** @var Mage_Catalog_Model_Product_Type_Configurable $model */
68
+ $model = Mage::getModel('catalog/product_type_configurable');
69
+ $parentIds = $model->getParentIdsByChild($item->getProductId());
70
+ $attributes = $item->getBuyRequest()->getData('super_attribute');
71
+ // If the product has a configurable parent, we assume we should tag
72
+ // the parent. If there are many parent IDs, we are safer to tag the
73
+ // products own ID.
74
+ if (count($parentIds) === 1 && !empty($attributes)) {
75
+ return $parentIds[0];
76
+ }
77
+ }
78
+ return $item->getProductId();
79
+ }
80
+
81
+ /**
82
+ * Returns the name for a quote item.
83
+ * Configurable products will have their chosen options added to their name.
84
+ * Bundle products will have their chosen child product names added.
85
+ * Grouped products will have their parent product name prepended.
86
+ * All others will have their own name only.
87
+ *
88
+ * @param Mage_Sales_Model_Quote_Item $item the quote item model.
89
+ *
90
+ * @return string
91
+ */
92
+ public function getProductName($item)
93
+ {
94
+ $name = $item->getName();
95
+ $optNames = array();
96
+
97
+ if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
98
+ /** @var Mage_Catalog_Model_Product_Type_Configurable $model */
99
+ $model = Mage::getModel('catalog/product_type_configurable');
100
+ $parentIds = $model->getParentIdsByChild($item->getProductId());
101
+ // If the product has a configurable parent, we assume we should tag
102
+ // the parent. If there are many parent IDs, we are safer to tag the
103
+ // products own name alone.
104
+ if (count($parentIds) === 1) {
105
+ $attributes = $item->getBuyRequest()->getData('super_attribute');
106
+ if (is_array($attributes)) {
107
+ foreach ($attributes as $id => $value) {
108
+ /** @var Mage_Catalog_Model_Resource_Eav_Attribute $attribute */
109
+ $attribute = Mage::getModel('catalog/resource_eav_attribute')
110
+ ->load($id);
111
+ $label = $attribute->getSource()->getOptionText($value);
112
+ if (!empty($label)) {
113
+ $optNames[] = $label;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
119
+ /* @var $helper Mage_Catalog_Helper_Product_Configuration */
120
+ $helper = Mage::helper('catalog/product_configuration');
121
+ foreach ($helper->getConfigurableOptions($item) as $opt) {
122
+ if (isset($opt['value']) && is_string($opt['value'])) {
123
+ $optNames[] = $opt['value'];
124
+ }
125
+ }
126
+ } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
127
+ $type = $item->getProduct()->getTypeInstance(true);
128
+ $opts = $type->getOrderOptions($item->getProduct());
129
+ if (isset($opts['bundle_options']) && is_array($opts['bundle_options'])) {
130
+ foreach ($opts['bundle_options'] as $opt) {
131
+ if (isset($opt['value']) && is_array($opt['value'])) {
132
+ foreach ($opt['value'] as $val) {
133
+ $qty = '';
134
+ if (isset($val['qty']) && is_int($val['qty'])) {
135
+ $qty .= $val['qty'] . ' x ';
136
+ }
137
+ if (isset($val['title']) && is_string($val['title'])) {
138
+ $optNames[] = $qty . $val['title'];
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
145
+ $config = $item->getBuyRequest()->getData('super_product_config');
146
+ if (isset($config['product_id'])) {
147
+ /** @var Mage_Catalog_Model_Product $parent */
148
+ $parent = Mage::getModel('catalog/product')
149
+ ->load($config['product_id']);
150
+ $parentName = $parent->getName();
151
+ if (!empty($parentName)) {
152
+ $name = $parentName.' - '.$name;
153
+ }
154
+ }
155
+ }
156
+ if (!empty($optNames)) {
157
+ $name .= ' (' . implode(', ', $optNames) . ')';
158
+ }
159
+ return $name;
160
+ }
161
+ }
app/code/community/Increasingly/Analytics/Block/Category.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Current category tagging block.
30
+ * Adds meta-data to the HTML document for the current catalog category
31
+ * (including parent categories).
32
+ */
33
+ class Increasingly_Analytics_Block_Category extends Mage_Core_Block_Template
34
+ {
35
+ /**
36
+ * @var string Cached category string.
37
+ */
38
+ protected $_category;
39
+
40
+ /**
41
+ * Render category string as hidden meta data if the module is enabled for
42
+ * the current store.
43
+ *
44
+ * @return string
45
+ */
46
+ protected function _toHtml()
47
+ {
48
+ if (!Mage::helper('increasingly_analytics')->isEnabled()) {
49
+ return '';
50
+ }
51
+ return parent::_toHtml();
52
+ }
53
+
54
+ /**
55
+ * Return the current product category string for the category tagging.
56
+ *
57
+ * @return string
58
+ */
59
+ public function getCategory()
60
+ {
61
+ if (!$this->_category) {
62
+ $category = Mage::registry('current_category');
63
+ $this->_category = Mage::helper('increasingly_analytics')
64
+ ->buildCategoryString($category);
65
+ }
66
+ return $this->_category;
67
+ }
68
+ }
app/code/community/Increasingly/Analytics/Block/Element.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Increasingly element block.
30
+ * Used to render placeholder elements that display the product bundles.
31
+ *
32
+ * @method string getDivId() Return the id of the element (defined in layout).
33
+ */
34
+ class Increasingly_Analytics_Block_Element extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Default id assigned to the element if none is set in the layout xml.
38
+ */
39
+ const DEFAULT_ID = 'missingDivIdParameter';
40
+
41
+ /**
42
+ * Render HTML placeholder element for the product bundles if the
43
+ * module is enabled for the current store.
44
+ *
45
+ * @return string
46
+ */
47
+ protected function _toHtml()
48
+ {
49
+ if (!Mage::helper('increasingly_analytics')->isEnabled()) {
50
+ return '';
51
+ }
52
+ return parent::_toHtml();
53
+ }
54
+
55
+ /**
56
+ * Return the id of the element. If none is defined in the layout xml,
57
+ * then set a default one.
58
+ *
59
+ * @return string
60
+ */
61
+ public function getElementId()
62
+ {
63
+ $id = $this->getDivId();
64
+ if ($id === null) {
65
+ $id = self::DEFAULT_ID;
66
+ }
67
+ return $id;
68
+ }
69
+ }
app/code/community/Increasingly/Analytics/Block/Embed.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Increasingly embed script block.
29
+ * Adds JavaScript to the document HEAD that takes care of the meta-data gathering
30
+ * and displaying of product bundles
31
+ */
32
+ class Increasingly_Analytics_Block_Embed extends Mage_Core_Block_Template
33
+ {
34
+ const DEFAULT_SERVER_ADDRESS = 'www.increasingly.co';
35
+
36
+ /**
37
+ * Render JavaScript that handles the data gathering and displaying of
38
+ * product bundles if the module is enabled for the current store.
39
+ *
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ if (!Mage::helper('increasingly_analytics')->isEnabled()) {
45
+ return '';
46
+ }
47
+ return parent::_toHtml();
48
+ }
49
+
50
+ /**
51
+ * Gets the Increasingly server address.
52
+ * This is either taken from the local environment if exists or else it
53
+ *
54
+ * @return string the url.
55
+ */
56
+ public function getServerAddress()
57
+ {
58
+ return Mage::app()->getRequest()->getEnv(
59
+ 'INCREASINGLY_SERVER_URL',
60
+ self::DEFAULT_SERVER_ADDRESS
61
+ );
62
+ }
63
+ }
app/code/community/Increasingly/Analytics/Block/Pagetype.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Solutions Ltd <magento@Increasingly.com>
24
+ * @copyright Copyright (c) 2013-2015 Increasingly Solutions Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Increasingly meta block.
29
+ * Used to render meta tag elements to to the HTML document
30
+ */
31
+ class Increasingly_Analytics_Block_Pagetype extends Mage_Core_Block_Template
32
+ {
33
+ /**
34
+ * Render meta tags if the module is enabled for the current store.
35
+ *
36
+ * @return string
37
+ */
38
+ protected function _toHtml()
39
+ {
40
+ if (!Mage::helper('increasingly_analytics')->isEnabled()) {
41
+ return '';
42
+ }
43
+ return parent::_toHtml();
44
+ }
45
+
46
+
47
+ /**
48
+ * Returns the current page type of the Increasingly extension.
49
+ *
50
+ * @return string the page type
51
+ */
52
+ public function getCurrentPageType()
53
+ {
54
+ $pageIdentifier = Mage::app()->getFrontController()->getAction()->getFullActionName();
55
+ return $pageIdentifier;
56
+ }
57
+
58
+ /**
59
+ * Returns the current API key of the Increasingly extension.
60
+ *
61
+ * @return string the API key for the current store.
62
+ */
63
+ public function getAPIKey()
64
+ {
65
+ return substr(
66
+ Mage::app()->getStore()->getConfig('general/locale/code'), 0, 2);
67
+ }
68
+
69
+ /**
70
+ * Returns the current Form key of the user.
71
+ *
72
+ * @return string the Form key for adding the product bundles to the cart.
73
+ */
74
+ public function getFormKey()
75
+ {
76
+ $request = $this->getRequest();
77
+ $formKey = Mage::getSingleton('core/session')->getFormKey();
78
+ return $formKey;
79
+ }
80
+ }
app/code/community/Increasingly/Analytics/Block/Product.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Product tagging block.
30
+ * Adds meta-data to the HTML document for the currently viewed product.
31
+ *
32
+ */
33
+ class Increasingly_Analytics_Block_Product extends Mage_Catalog_Block_Product_Abstract
34
+ {
35
+ /**
36
+ * @var Increasingly_Analytics_Model_Meta_Product runtime cache for the product meta.
37
+ */
38
+ protected $_product;
39
+
40
+ /**
41
+ * @var string runtime cache for the current category path string.
42
+ */
43
+ protected $_currentCategory;
44
+
45
+ /**
46
+ * Render product info as hidden meta data if the module is enabled for the
47
+ * current store.
48
+ * If it is a "bundle" product with fixed price type, then do not render.
49
+ * These are not supported due to their child products not having prices
50
+ * available.
51
+ *
52
+ * @return string
53
+ */
54
+ protected function _toHtml()
55
+ {
56
+ if (!Mage::helper('increasingly_analytics')->isEnabled()) {
57
+ return '';
58
+ }
59
+ return parent::_toHtml();
60
+ }
61
+
62
+ /**
63
+ * Returns the product meta data to tag.
64
+ *
65
+ * @return Increasingly_Analytics_Model_Meta_Product the meta data.
66
+ */
67
+ public function getMetaProduct()
68
+ {
69
+ if ($this->_product === null) {
70
+ /** @var Increasingly_Analytics_Model_Meta_Product $model */
71
+ $model = Mage::getModel('increasingly_analytics/meta_product');
72
+ $model->loadData($this->getProduct());
73
+ $this->_product = $model;
74
+ }
75
+ return $this->_product;
76
+ }
77
+
78
+ /**
79
+ * Returns the current category under which the product is viewed.
80
+ *
81
+ * @return string the category path or empty if not found.
82
+ */
83
+ public function getCurrentCategory()
84
+ {
85
+ if (!$this->_currentCategory) {
86
+ $category = Mage::registry('current_category');
87
+ $this->_currentCategory = Mage::helper('increasingly_analytics')
88
+ ->buildCategoryString($category);
89
+ }
90
+ return $this->_currentCategory;
91
+ }
92
+ }
app/code/community/Increasingly/Analytics/Block/Track.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Tracks events to send it to increasingly
29
+ */
30
+ class Increasingly_Analytics_Block_Track extends Mage_Core_Block_Template
31
+ {
32
+ /**
33
+ * key in session storage
34
+ */
35
+ const DATA_KEY = "increasingly_events";
36
+
37
+ /**
38
+ * Get tracking events to track them to increasingly api
39
+ * @return array
40
+ */
41
+ public function getTrackingEvents()
42
+ {
43
+ $helper = Mage::helper('increasingly_analytics');
44
+ $events = (array)Mage::getSingleton('core/session')->getData(self::DATA_KEY);
45
+
46
+ // clear data from session
47
+ Mage::getSingleton('core/session')->setData(self::DATA_KEY,'');
48
+ return array_filter($events);
49
+ }
50
+
51
+ /**
52
+ * Render category string as hidden meta data if the module is enabled for
53
+ * the current store.
54
+ *
55
+ * @return string
56
+ */
57
+ protected function _toHtml()
58
+ {
59
+ $html = parent::_toHtml();
60
+ if(Mage::helper('increasingly_analytics')->isEnabled())
61
+ return $html;
62
+ }
63
+ }
app/code/community/Increasingly/Analytics/Helper/Data.php ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Helper class provides api call functionality and building order details, track events etc.
29
+ */
30
+ class Increasingly_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
31
+ {
32
+ /**
33
+ * Path to store config installation ID.
34
+ */
35
+ const XML_PATH_INSTALLATION_ID = 'increasingly_analytics/installation/id';
36
+
37
+ /**
38
+ * Path to store config Increasingly product image version.
39
+ */
40
+ const XML_PATH_IMAGE_VERSION = 'increasingly_analytics/image_options/image_version';
41
+
42
+ /**
43
+ * @var string the name of the cookie where the Increasingly ID can be found.
44
+ */
45
+ const COOKIE_NAME = '2c_cId';
46
+
47
+ /**
48
+ * @var string the name of the cookie where the Increasingly ID can be found.
49
+ */
50
+ const VISITOR_HASH_ALGO = 'sha256';
51
+ /**
52
+ * Get session instance
53
+ *
54
+ * @return Mage_Core_Model_Session
55
+ */
56
+ public function getSession()
57
+ {
58
+ return Mage::getSingleton('core/session');
59
+ }
60
+
61
+ /**
62
+ * Check if increasingly module is enabled
63
+ *
64
+ * @return boolean
65
+ */
66
+ public function isEnabled()
67
+ {
68
+ return Mage::getStoreConfig('increasingly_analytics/settings/enable');
69
+ }
70
+
71
+ /**
72
+ * Get API Token from configuration
73
+ *
74
+ * @return string
75
+ */
76
+ public function getApiToken()
77
+ {
78
+ return Mage::getStoreConfig('increasingly_analytics/settings/api_key');
79
+ }
80
+
81
+ /**
82
+ * Get API Secret from configuration
83
+ *
84
+ * @return string
85
+ */
86
+ public function getApiSecret()
87
+ {
88
+ return Mage::getStoreConfig('increasingly_analytics/settings/api_secret');
89
+ }
90
+
91
+ /**
92
+ * Add event for tracking
93
+ *
94
+ */
95
+ public function addEvent($method, $type, $data)
96
+ {
97
+ $event_data = array();
98
+
99
+ if ($this->getSession()->getData(Increasingly_Analytics_Block_Track::DATA_KEY) != '')
100
+ {
101
+ $event_data = (array)$this->getSession()->getData(Increasingly_Analytics_Block_Track::DATA_KEY);
102
+ }
103
+
104
+ $version = (string)Mage::getConfig()->getModuleConfig("Increasingly_Analytics")->version;
105
+
106
+ $currentEvent = array(
107
+ 'event_data' => $data,
108
+ 'event_type' => $type,
109
+ 'method' => $method,
110
+ 'platform' => 'Magento ' . Mage::getEdition() . ' ' . Mage::getVersion(),
111
+ 'token' => $this->getApiToken(),
112
+ 'version' => $version
113
+ );
114
+
115
+ array_push($event_data, $currentEvent);
116
+ $this->getSession()->setData(Increasingly_Analytics_Block_Track::DATA_KEY, $event_data);
117
+ }
118
+
119
+ /**
120
+ * Get order details and sort them
121
+ * @param Mage_Sales_Model_Order $order
122
+ * @return array
123
+ */
124
+ public function buildOrderDetailsData($order)
125
+ {
126
+ $priceFormatter = Mage::helper('increasingly_analytics/PriceFormatter');
127
+ $data = array(
128
+ 'order_id' => $order->getIncrementId(),
129
+ 'order_status' => $order->getStatus(),
130
+ 'order_amount' => $priceFormatter->format($order->getGrandTotal()),
131
+ 'shipping_amount' => $priceFormatter->format($order->getShippingAmount()),
132
+ 'tax_amount' => $priceFormatter->format($order->getTaxAmount()),
133
+ 'items' => array(),
134
+ 'shipping_method' => $order->getShippingDescription(),
135
+ 'currency_code' => $order->getOrderCurrencyCode(),
136
+ 'payment_method' => $order->getPayment()->getMethodInstance()->getTitle()
137
+ );
138
+
139
+ if($order->getCustomerIsGuest()){
140
+ $data['customer_email'] = $order->getCustomerEmail();
141
+ $data['customer_first_name'] = $order->getCustomerFirstname();
142
+ $data['customer_last_name'] = $order->getCustomerLastname();
143
+ $data['customer_name'] = $order->getCustomerFirstname(). ' '. $order->getCustomerLastname();
144
+ }
145
+ else {
146
+ $data['customer_email'] = $order->getCustomerEmail();
147
+ $data['customer_first_name'] = $order->getBillingAddress()->getFirstname();
148
+ $data['customer_last_name'] = $order->getBillingAddress()->getLastname();
149
+ $data['customer_name'] = $order->getBillingAddress()->getName();
150
+ }
151
+ if ($order->getDiscountAmount()) {
152
+ $data['discount_amount'] = $priceFormatter->format($order->getDiscountAmount());
153
+ }
154
+ if ($order->getCouponCode()) {
155
+ $data['coupons'] = $order->getCouponCode();
156
+ }
157
+ if($order->getRemoteIp()){
158
+ $data['user_ip'] = $order->getRemoteIp();
159
+ }
160
+ if ($order->getCreatedAt()) {
161
+ $data['order_time'] = $order->getCreatedAt();
162
+ }
163
+ foreach ($order->getAllItems() as $item)
164
+ {
165
+ $dataItem = array(
166
+ 'product_id' => $item->getProductId(),
167
+ 'product_price' => $priceFormatter->format($item->getPrice()) ? $priceFormatter->format($item->getPrice()) :
168
+ $priceFormatter->format($item->getProduct()->getFinalPrice()),
169
+ 'product_name' => $item->getName(),
170
+ 'product_url' => $item->getProduct()->getProductUrl(),
171
+ 'product_sku' => $item->getSku(),
172
+ 'qty' => (int)$item->getQtyOrdered(),
173
+ 'product_type' => $item->getProductType()
174
+ );
175
+ $data['items'][] = $dataItem;
176
+ }
177
+
178
+ $data['bundles'] = $this->formBundleJson();
179
+ return $data;
180
+ }
181
+
182
+ /**Form json data for sending the bundle details to the Increasingly API
183
+ **
184
+ */
185
+ public function formBundleJson(){
186
+ try {
187
+ $bundleData = [];
188
+ $cookieValue = Mage::getModel('core/cookie')->get('ivid');
189
+ $userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
190
+ ->addFieldToFilter('increasingly_visitor_id',$cookieValue);
191
+ foreach($userBundleCollection as $userBundle){
192
+ $userBundle->getBundleId();
193
+ $userBundle->getDiscountPrice();
194
+ $userBundle->getTotalSpecialPrice();
195
+ array_push($bundleData,
196
+ array('id' => $userBundle->getBundleId(),
197
+ 'discountPrice' => $userBundle->getDiscountPrice(),
198
+ 'totalSpecialPrice' => $userBundle->getTotalSpecialPrice()
199
+ ));
200
+ }
201
+ }
202
+ catch (Exception $e)
203
+ {
204
+ Mage::log("Increasingly form bundle json- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
205
+ }
206
+ return $bundleData;
207
+ }
208
+
209
+ /**Delete bundle when the products in the cart are deleted
210
+ **
211
+ */
212
+ public function deleteBundleOnProductDeleteFromCart($product_id){
213
+ try {
214
+ $cookieValue = Mage::getModel('core/cookie')->get('ivid');
215
+ $userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
216
+ if(count($userBundleCollection) >= 1){
217
+ $userBundle = Mage::getModel('increasingly_analytics/bundle');
218
+ $userBundle->setId($userBundleCollection->getFirstItem()->getId())->delete();
219
+ $userBundle->save($cookieValue);
220
+ }
221
+ }
222
+ catch (Exception $e)
223
+ {
224
+ Mage::log("Increasingly delete bundle on delete from cart- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
225
+ }
226
+
227
+ }
228
+
229
+ /**Delete bundle when all the items in the cart are deleted
230
+ **
231
+ */
232
+ public function deleteBundleOnEmptyCart($quote){
233
+ try {
234
+ $cookieValue = Mage::getModel('core/cookie')->get('ivid');
235
+ $userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
236
+ $productIds = explode(',', $userBundle->getProductIds);
237
+ if($quote->getItemsCount() == 0 && count($userBundleCollection) >= 0) {
238
+ foreach ($userBundleCollection as $userBundle) {
239
+ $userBundle->delete();
240
+
241
+ }
242
+ }
243
+ }
244
+ catch (Exception $e)
245
+ {
246
+ Mage::log("Increasingly delete bundle on emptyCart- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
247
+ }
248
+
249
+ }
250
+
251
+ /**
252
+ * Sends event data to increasingly through API
253
+ */
254
+ public function increasinglyApi($importData,$event_type,$method,$api_token,$api_secret)
255
+ {
256
+ $result = '';
257
+ try {
258
+ $version = (string)Mage::getConfig()->getModuleConfig("Increasingly_Analytics")->version;
259
+ $data = array(
260
+ 'event_data' => $importData,
261
+ 'event_type'=> $event_type,
262
+ 'method' => $method,
263
+ 'platform' => 'Magento ' . Mage::getEdition() . ' ' . Mage::getVersion(),
264
+ 'token' => $api_token,
265
+ 'version' => $version
266
+ );
267
+ // sort data
268
+ ksort($data);
269
+ $encodedData = base64_encode(Mage::helper('core')->jsonEncode($data));
270
+ $signature = md5($encodedData.$api_secret);
271
+ $url = 'http://optimizedby.increasingly.co/ImportData';
272
+ $client = new Varien_Http_Client($url);
273
+ Mage::log($data,null, 'Increasingly_Analytics.log');
274
+ $postData = array(
275
+ 'signature' => $signature,
276
+ 'eventData' => $encodedData
277
+ );
278
+ $jsonData = json_encode($postData);
279
+ $client->setRawData($jsonData, 'application/json');
280
+ $response = $client->request('POST');
281
+ $result = json_decode($response->getBody());
282
+ if ($response->isError()) {
283
+ Mage::log($response->getBody(), null, 'Increasingly_Analytics.log');
284
+ }
285
+
286
+ }
287
+ catch (Exception $e)
288
+ {
289
+ Mage::log("Increasingly api call- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
290
+ }
291
+ return $result;
292
+ }
293
+
294
+ /**
295
+ * Builds a tagging string of the given category including all its parent
296
+ * categories.
297
+ * The categories are sorted by their position in the category tree path.
298
+ *
299
+ * @param Mage_Catalog_Model_Category $category the category model.
300
+ *
301
+ * @return string
302
+ */
303
+ public function buildCategoryString($category)
304
+ {
305
+ $data = array();
306
+ if ($category instanceof Mage_Catalog_Model_Category) {
307
+ /** @var $categories Mage_Catalog_Model_Category[] */
308
+ $categories = $category->getParentCategories();
309
+ $path = $category->getPathInStore();
310
+ $ids = array_reverse(explode(',', $path));
311
+ foreach ($ids as $id) {
312
+ if (isset($categories[$id]) && $categories[$id]->getName()) {
313
+ $data[] = $categories[$id]->getId();
314
+ }
315
+ }
316
+ }
317
+ if (!empty($data)) {
318
+ return DS . implode(DS, $data);
319
+ } else {
320
+ return '';
321
+ }
322
+ }
323
+
324
+ /**
325
+ * Return the product image version to include in product tagging.
326
+ *
327
+ * @param Mage_Core_Model_Store|null $store the store model or null.
328
+ *
329
+ * @return string
330
+ */
331
+ public function getProductImageVersion($store = null)
332
+ {
333
+ return Mage::getStoreConfig(self::XML_PATH_IMAGE_VERSION, $store);
334
+ }
335
+
336
+
337
+ }
app/code/community/Increasingly/Analytics/Helper/DateFormatter.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Helper class to Format date
30
+ */
31
+ class Increasingly_Analytics_Helper_DateFormatter extends Mage_Core_Helper_Abstract
32
+ {
33
+ public function getFormattedDate($date)
34
+ {
35
+ // 2016-04-22 08:41:46
36
+ return date_format(date_create($date), "Y-m-d H:i:s");
37
+ }
38
+ }
app/code/community/Increasingly/Analytics/Helper/PriceFormatter.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Helper class to Format price
29
+ */
30
+ class Increasingly_Analytics_Helper_PriceFormatter extends Mage_Core_Helper_Abstract
31
+ {
32
+ public function format($price)
33
+ {
34
+ return number_format($price, 2, '.', '');
35
+ }
36
+ /**
37
+ * Formats price into Increasingly format, e.g. 1000.99.
38
+ *
39
+ * @param string|int|float $price the price to format.
40
+ *
41
+ * @return string
42
+ */
43
+ public function getFormattedPrice($price)
44
+ {
45
+ return number_format($price, 2, '.', '');
46
+ }
47
+
48
+ /**
49
+ * Gets the unit price for a product model including taxes.
50
+ *
51
+ * @param Mage_Catalog_Model_Product $product the product model.
52
+ *
53
+ * @return float
54
+ */
55
+ public function getProductPriceInclTax($product)
56
+ {
57
+ return $this->_getProductPrice($product, false, true);
58
+ }
59
+
60
+ /**
61
+ * Get the final price for a product model including taxes.
62
+ *
63
+ * @param Mage_Catalog_Model_Product $product the product model.
64
+ *
65
+ * @return float
66
+ */
67
+ public function getProductFinalPriceInclTax($product)
68
+ {
69
+ return $this->_getProductPrice($product, true, true);
70
+ }
71
+
72
+ /**
73
+ * Get unit/final price for a product model.
74
+ *
75
+ * @param Mage_Catalog_Model_Product $product the product model.
76
+ * @param bool $finalPrice if final price.
77
+ * @param bool $inclTax if tax is to be included.
78
+ *
79
+ * @return float
80
+ */
81
+ protected function _getProductPrice($product, $finalPrice = false, $inclTax = true)
82
+ {
83
+ $price = 0;
84
+
85
+ switch ($product->getTypeId()) {
86
+ case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
87
+ // Get the bundle product "from" price.
88
+ $price = $product->getPriceModel()
89
+ ->getTotalPrices($product, 'min', $inclTax);
90
+ break;
91
+
92
+ case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
93
+ // Get the grouped product "starting at" price.
94
+ /** @var $tmpProduct Mage_Catalog_Model_Product */
95
+ $tmpProduct = Mage::getModel('catalog/product')
96
+ ->getCollection()
97
+ ->addAttributeToSelect(
98
+ Mage::getSingleton('catalog/config')
99
+ ->getProductAttributes()
100
+ )
101
+ ->addAttributeToFilter('entity_id', $product->getId())
102
+ ->setPage(1, 1)
103
+ ->addMinimalPrice()
104
+ ->addTaxPercents()
105
+ ->load()
106
+ ->getFirstItem();
107
+ if ($tmpProduct) {
108
+ $price = $tmpProduct->getMinimalPrice();
109
+ if ($inclTax) {
110
+ $price = Mage::helper('tax')
111
+ ->getPrice($tmpProduct, $price, true);
112
+ }
113
+ }
114
+ break;
115
+
116
+ default:
117
+ $price = $finalPrice
118
+ ? $product->getFinalPrice()
119
+ : $product->getPrice();
120
+ if ($inclTax) {
121
+ $price = Mage::helper('tax')
122
+ ->getPrice($product, $price, true);
123
+ }
124
+ break;
125
+ }
126
+ return $price;
127
+ }
128
+
129
+ /**
130
+ * @param float $price
131
+ * @param Mage_Core_Model_Store $store
132
+ * @return float
133
+ */
134
+ public function convertToDefaultCurrency($price, Mage_Core_Model_Store $store)
135
+ {
136
+ if (!is_numeric($price)) {
137
+ Mage::log(
138
+ sprintf(
139
+ 'price must be a numeric value in %s, got %s.',
140
+ __CLASS__,
141
+ $price
142
+ ),
143
+ Zend_Log::WARN,
144
+ Increasingly_Analytics_Model_Base::LOG_FILE_NAME
145
+ );
146
+ $price = 0;
147
+ }
148
+ return Mage::helper('directory')->currencyConvert(
149
+ $price,
150
+ $store->getBaseCurrency()->getCode(),
151
+ $store->getDefaultCurrency()->getCode()
152
+ );
153
+ }
154
+
155
+ /**
156
+ * Get the final price in base currency for an ordered item including
157
+ * taxes as discounts.
158
+ *
159
+ * @param Mage_Sales_Model_Order_Item $item the item model.
160
+ *
161
+ * @return float
162
+ */
163
+ public function getItemFinalPriceInclTax(Mage_Sales_Model_Order_Item $item)
164
+ {
165
+ $price = $item->getBaseRowTotal() + $item->getBaseTaxAmount() + $item->getBaseHiddenTaxAmount() - $item->getBaseDiscountAmount();
166
+ return $price;
167
+ }
168
+ }
169
+
170
+
app/code/community/Increasingly/Analytics/Helper/ProductFormatter.php ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Formats product details to be sent to increasingly
29
+ */
30
+ class Increasingly_Analytics_Helper_ProductFormatter extends Mage_Core_Helper_Abstract
31
+ {
32
+
33
+ public function formatProductInfo($product)
34
+ {
35
+ $productData = null;
36
+
37
+ try
38
+ {
39
+ $priceFormatter = Mage::helper('increasingly_analytics/PriceFormatter');
40
+ $dateFormatter = Mage::helper('increasingly_analytics/DateFormatter');
41
+
42
+ $productData = array(
43
+ 'product_id' => $product->getId(),
44
+ 'product_sku' => $product->getSku(),
45
+ 'product_name' => $product->getName(),
46
+ 'categories' => array(),
47
+ //'currency' => Mage::app()->getStore()->getDefaultCurrencyCode(),
48
+ 'product_price' => $priceFormatter->format($product->getPrice()),
49
+ 'special_price' => $priceFormatter->format($product->getSpecialPrice()),
50
+ 'product_url' => $product->getProductUrl(),
51
+ 'description' => $product->getShortDescription(),
52
+ 'status' => (int)$product->getStatus(),
53
+ 'product_type' => $product->getTypeId(),
54
+ 'created_at' => $dateFormatter->getFormattedDate($product->getCreatedAt()),
55
+ 'updated_at' => $dateFormatter->getFormattedDate($product->getUpdatedAt())
56
+ );
57
+
58
+ $productDefaultImage = $product->getData('image');
59
+ if(!empty($productDefaultImage) && $productDefaultImage !== 'no_selection')
60
+ {
61
+ $productData['image_url'] = $product->getImageUrl();
62
+ }
63
+ else
64
+ {
65
+ $productData['image_url'] = '';
66
+ }
67
+ $manufacturer = $product->getAttributeText('manufacturer');
68
+ if(strlen($manufacturer) > 0 && $manufacturer != false)
69
+ {
70
+ $productData['manufacturer'] = $manufacturer;
71
+ }
72
+
73
+ $color = $product->getAttributeText('color');
74
+ if(strlen($color) > 0 && $color != false)
75
+ {
76
+ $productData['color'] = $color;
77
+ }
78
+
79
+ $weight = $product->getWeight();
80
+ if(strlen($weight) > 0 && $weight != false)
81
+ {
82
+ $productData['weight'] = $weight;
83
+ }
84
+
85
+ $size = $product->getAttributeText('size');
86
+ if(strlen($size) > 0 && $size != false)
87
+ {
88
+ $productData['size'] = $size;
89
+ }
90
+
91
+ if($productData['product_type'] == "configurable")
92
+ {
93
+ $configurableProducts = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($productData['product_id']);
94
+ $configurable_items = array();
95
+ foreach($configurableProducts as $key=>$configurableProductList)
96
+ {
97
+ foreach($configurableProductList as $itemValue)
98
+ {
99
+ $configurable_items[] = $itemValue;
100
+ }
101
+ }
102
+ $productData['associated_products'] = $configurable_items;
103
+ }
104
+
105
+ if($productData['product_type'] == "grouped")
106
+ {
107
+
108
+ $groupedProducts = Mage::getModel('catalog/product_type_grouped')->getChildrenIds($productData['product_id']);
109
+ $grouped_items = array();
110
+
111
+ foreach($groupedProducts as $key=>$groupedProductList)
112
+ {
113
+ foreach($groupedProductList as $itemValue)
114
+ {
115
+ $grouped_items[] = $itemValue;
116
+ }
117
+ }
118
+ $productData['associated_products'] = $grouped_items;
119
+ }
120
+
121
+ if($productData['product_type'] == "bundle")
122
+ {
123
+ $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
124
+ $product->getTypeInstance(true)->getOptionsIds($product), $product);
125
+
126
+ $bundled_items = array();
127
+ foreach($selectionCollection as $option)
128
+ {
129
+ $bundled_items[] = $option->getId();
130
+ }
131
+ $productData['associated_products'] = $bundled_items;
132
+ }
133
+
134
+ $relatedProducts = $product->getRelatedProductIds();
135
+ if(count($relatedProducts) > 0)
136
+ {
137
+ $productData['related_products'] = $relatedProducts;
138
+ }
139
+
140
+ $upSellProducts = $product->getUpSellProductIds();
141
+ if(count($upSellProducts) > 0)
142
+ {
143
+ $productData['up_sell_products'] = $upSellProducts;
144
+ }
145
+
146
+ $crossSellProducts = $product->getCrossSellProductIds();
147
+ if(count($crossSellProducts) > 0)
148
+ {
149
+ $productData['cross_sell_products'] = $crossSellProducts;
150
+ }
151
+
152
+ // get stock info
153
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
154
+ $productData['qty'] = (int)$stock->getQty();
155
+
156
+ $categories = $product->getCategoryCollection()
157
+ ->addAttributeToSelect('id')
158
+ ->addAttributeToSelect('name');
159
+
160
+ foreach($categories as $category)
161
+ {
162
+ $categoryInfo = array();
163
+ $categoryInfo['id'] = $category->getId();
164
+ $categoryInfo['name'] = $category->getName();
165
+ $productData['categories'][] = $categoryInfo;
166
+ }
167
+
168
+ $otherImages = $product->getMediaGalleryImages();
169
+
170
+ if($otherImages == '' || count($otherImages) == 0)
171
+ {
172
+ $productImage_Data = Mage::getModel('catalog/product')->load($product->getId());
173
+ $otherImages = $productImage_Data->getMediaGalleryImages();
174
+ }
175
+
176
+ if(count($otherImages) > 1)
177
+ {
178
+ foreach($otherImages as $img)
179
+ {
180
+ if($img->getFile() != $productDefaultImage)
181
+ {
182
+ $productData['other_image_list'][] = $img->getUrl();
183
+ }
184
+ }
185
+ }
186
+ }
187
+ catch(Exception $e)
188
+ {
189
+ Mage::log($e, null, 'Increasingly_Analytics.log');
190
+ }
191
+
192
+ return $productData;
193
+ }
194
+
195
+ }
196
+
197
+
app/code/community/Increasingly/Analytics/Model/Base.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class Increasingly_Analytics_Model_Base extends Mage_Core_Model_Abstract
28
+ {
29
+
30
+ /**
31
+ * Log file for plugin related messages.
32
+ */
33
+ const LOG_FILE_NAME = 'increasingly_analytics.log';
34
+
35
+ /**
36
+ * Returns a protected/private property value by invoking it's public getter.
37
+ *
38
+ * The getter names are assumed to be the property name in camel case with preceding word "get".
39
+ *
40
+ * @param string $name the property name.
41
+ * @return mixed the property value.
42
+ * @throws IncreasinglyException if public getter does not exist.
43
+ */
44
+ public function __get($name)
45
+ {
46
+ $getter = 'get'.str_replace('_', '', $name);
47
+ if (method_exists($this, $getter)) {
48
+ return $this->{$getter}();
49
+ }
50
+ throw new IncreasinglyException(sprintf('Property `%s.%s` is not defined.', get_class($this), $name));
51
+ }
52
+ }
app/code/community/Increasingly/Analytics/Model/Bundle.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class Increasingly_Analytics_Model_Bundle extends Mage_Core_Model_Abstract
28
+ {
29
+ public function _construct()
30
+ {
31
+ parent::_construct();
32
+ $this->_init('increasingly_analytics/bundle');
33
+ }
34
+ }
35
+
36
+ ?>
app/code/community/Increasingly/Analytics/Model/DataIntegration.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Model which gets previous orders details from Magento for exporting it to Increasingly
29
+ *
30
+ */
31
+ class Increasingly_Analytics_Model_DataIntegration extends Mage_Core_Model_Abstract
32
+ {
33
+ private $_totalOrders = 0;
34
+ private $_totalDataChunks = 0;
35
+ private $_chunkItems = 200;
36
+
37
+ public function _construct()
38
+ {
39
+ $this->_totalOrders = Mage::getModel('sales/order')->getCollection()->getSize();
40
+ $this->_totalDataChunks = (int)ceil($this->_totalOrders / $this->_chunkItems);
41
+ }
42
+
43
+ /**
44
+ * Get order details
45
+ *
46
+ * @param int
47
+ * @return Varien_Data_Collection
48
+ */
49
+ public function getOrderDetails($chunkId)
50
+ {
51
+ return Mage::getModel('sales/order')
52
+ ->getCollection()
53
+ ->setPageSize($this->_chunkItems)
54
+ ->setCurPage($chunkId + 1);
55
+ }
56
+
57
+ /**
58
+ * Total data chunk size
59
+ * @return int
60
+ */
61
+ public function getChunks()
62
+ {
63
+ return $this->_totalDataChunks;
64
+ }
65
+ }
app/code/community/Increasingly/Analytics/Model/Meta/Product.php ADDED
@@ -0,0 +1,509 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Meta data class which holds information about a product.
30
+ * This is used during the order confirmation API request and the product
31
+ * history export.
32
+ *
33
+ */
34
+ class Increasingly_Analytics_Model_Meta_Product extends Increasingly_Analytics_Model_Base
35
+ {
36
+ /**
37
+ * Product "in stock" tagging string.
38
+ */
39
+ const PRODUCT_IN_STOCK = 'InStock';
40
+
41
+ /**
42
+ * Product "out of stock" tagging string.
43
+ */
44
+ const PRODUCT_OUT_OF_STOCK = 'OutOfStock';
45
+
46
+ /**
47
+ * Product "can be directly added to cart" tag string.
48
+ */
49
+ const PRODUCT_ADD_TO_CART = 'add-to-cart';
50
+
51
+ /**
52
+ * @var string the absolute url to the product page in the shop frontend.
53
+ */
54
+ protected $_url;
55
+
56
+ /**
57
+ * @var string the product's unique identifier.
58
+ */
59
+ protected $_productId;
60
+
61
+ /**
62
+ * @var string the name of the product.
63
+ */
64
+ protected $_name;
65
+
66
+ /**
67
+ * @var string the absolute url the one of the product images in frontend.
68
+ */
69
+ protected $_imageUrl;
70
+
71
+ /**
72
+ * @var string the product price including possible discounts and taxes.
73
+ */
74
+ protected $_price;
75
+
76
+ /**
77
+ * @var string the product list price without discounts but incl taxes.
78
+ */
79
+ protected $_listPrice;
80
+
81
+ /**
82
+ * @var string the currency code (ISO 4217) the product is sold in.
83
+ */
84
+ protected $_currencyCode;
85
+
86
+ /**
87
+ * @var string the availability of the product, i.e. is in stock or not.
88
+ */
89
+ protected $_availability;
90
+
91
+ /**
92
+ * @var array the tags for the product.
93
+ */
94
+ protected $_tags = array(
95
+ 'tag1' => array(),
96
+ 'tag2' => array(),
97
+ 'tag3' => array(),
98
+ );
99
+
100
+ /**
101
+ * @var array the categories the product is located in.
102
+ */
103
+ protected $_categories = array();
104
+
105
+ /**
106
+ * @var string the product short description.
107
+ */
108
+ protected $_shortDescription;
109
+
110
+ /**
111
+ * @var string the product description.
112
+ */
113
+ protected $_description;
114
+
115
+ /**
116
+ * @var string the product brand name.
117
+ */
118
+ protected $_brand;
119
+
120
+ /**
121
+ * @var string the product publication date in the shop.
122
+ */
123
+ protected $_datePublished;
124
+
125
+ /**
126
+ * @inheritdoc
127
+ */
128
+ protected function _construct()
129
+ {
130
+ $this->_init('increasingly_analytics/meta_product');
131
+ }
132
+
133
+ /**
134
+ * @inheritdoc
135
+ */
136
+ public function getValidationRules()
137
+ {
138
+ return array(
139
+ array(
140
+ array(
141
+ '_url',
142
+ '_productId',
143
+ '_name',
144
+ '_imageUrl',
145
+ '_price',
146
+ '_listPrice',
147
+ '_currencyCode',
148
+ '_availability'
149
+ ),
150
+ 'required'
151
+ )
152
+ );
153
+ }
154
+
155
+ /**
156
+ * Loads the product info from a Magento product model.
157
+ *
158
+ * @param Mage_Catalog_Model_Product $product the product model.
159
+ * @param Mage_Core_Model_Store|null $store the store to get the product data for.
160
+ */
161
+ public function loadData(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store = null)
162
+ {
163
+ if (is_null($store)) {
164
+ $store = Mage::app()->getStore();
165
+ }
166
+
167
+ /** @var Increasingly_Analytics_Helper_Price $priceHelper */
168
+ $priceHelper = Mage::helper('increasingly_analytics/priceFormatter');
169
+
170
+ $this->_url = $this->buildUrl($product, $store);
171
+ $this->_productId = $product->getId();
172
+ $this->_name = $product->getName();
173
+ $this->_imageUrl = $this->buildImageUrl($product, $store);
174
+ $this->_price = $priceHelper->convertToDefaultCurrency($priceHelper->getProductFinalPriceInclTax($product), $store);
175
+ $this->_listPrice = $priceHelper->convertToDefaultCurrency($priceHelper->getProductPriceInclTax($product), $store);
176
+ $this->_currencyCode = $store->getDefaultCurrency()->getCode();
177
+ $this->_availability = $product->isAvailable()
178
+ ? self::PRODUCT_IN_STOCK
179
+ : self::PRODUCT_OUT_OF_STOCK;
180
+ $this->_categories = $this->buildCategories($product);
181
+
182
+ // Optional properties.
183
+
184
+ if ($product->hasData('short_description')) {
185
+ $this->_shortDescription = $product->getData('short_description');
186
+ }
187
+ if ($product->hasData('description')) {
188
+ $this->_description = $product->getData('description');
189
+ }
190
+ if ($product->hasData('manufacturer')) {
191
+ $this->_brand = $product->getAttributeText('manufacturer');
192
+ }
193
+ if (($tags = $this->buildTags($product, $store)) !== array()) {
194
+ $this->_tags['tag1'] = $tags;
195
+ }
196
+ if ($product->hasData('created_at')) {
197
+ $this->_datePublished = $product->getData('created_at');
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Builds the "tag1" tags.
203
+ *
204
+ * These include any "tag/tag" model names linked to the product, as well
205
+ * as a special "add-to-cart" tag if the product can be added to the
206
+ * cart directly without any choices, i.e. it is a non-configurable simple
207
+ * product.
208
+ * This special tag can then be used in the store frontend to enable a
209
+ * "add to cart" button in the product bundling.
210
+ *
211
+ * @param Mage_Catalog_Model_Product $product the product model.
212
+ * @param Mage_Core_Model_Store $store the store model.
213
+ *
214
+ * @return array
215
+ */
216
+ protected function buildTags(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store)
217
+ {
218
+ $tags = array();
219
+
220
+ if (Mage::helper('core')->isModuleEnabled('Mage_Tag')) {
221
+ $tagCollection = Mage::getModel('tag/tag')
222
+ ->getCollection()
223
+ ->addPopularity()
224
+ ->addStatusFilter(Mage_Tag_Model_Tag::STATUS_APPROVED)
225
+ ->addProductFilter($product->getId())
226
+ ->setFlag('relation', true)
227
+ ->addStoreFilter($store->getId())
228
+ ->setActiveFilter();
229
+ foreach ($tagCollection as $tag) {
230
+ /** @var Mage_Tag_Model_Tag $tag */
231
+ $tags[] = $tag->getName();
232
+ }
233
+ }
234
+
235
+ if (!$product->canConfigure()) {
236
+ $tags[] = self::PRODUCT_ADD_TO_CART;
237
+ }
238
+
239
+ return $tags;
240
+ }
241
+
242
+ /**
243
+ * Builds the absolute store front url for the product page.
244
+ *
245
+ * The url includes the "___store" GET parameter in order for the Increasingly
246
+ * crawler to distinguish between stores that do not have separate domains
247
+ * or paths.
248
+ *
249
+ * @param Mage_Catalog_Model_Product $product the product model.
250
+ * @param Mage_Core_Model_Store $store the store model.
251
+ *
252
+ * @return string
253
+ */
254
+ protected function buildUrl(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store)
255
+ {
256
+ // Unset the cached url first, as it won't include the `___store` param
257
+ // if it's cached. We need to define the specific store view in the url
258
+ // in case the same domain is used for all sites.
259
+ $product->unsetData('url');
260
+ return $product
261
+ ->getUrlInStore(
262
+ array(
263
+ '_increasinglyid' => true,
264
+ '_ignore_category' => true,
265
+ '_store' => $store->getCode(),
266
+ )
267
+ );
268
+ }
269
+
270
+ /**
271
+ * Builds the product absolute image url for the store and returns it.
272
+ * The image version is primarily taken from the store config, but falls
273
+ * back the the base image if nothing is configured.
274
+ *
275
+ * @param Mage_Catalog_Model_Product $product the product model.
276
+ * @param Mage_Core_Model_Store $store the store model.
277
+ *
278
+ * @return null|string
279
+ */
280
+ protected function buildImageUrl(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store)
281
+ {
282
+ $url = null;
283
+ /** @var Increasingly_Analytics_Helper_Data $helper */
284
+ $helper = Mage::helper('increasingly_analytics');
285
+ $imageVersion = $helper->getProductImageVersion($store);
286
+ $img = $product->getData($imageVersion);
287
+ $img = $this->isValidImage($img) ? $img : $product->getData('image');
288
+ if ($this->isValidImage($img)) {
289
+ // We build the image url manually in order get the correct base
290
+ // url, even if this product is populated in the backend.
291
+ $baseUrl = rtrim($store->getBaseUrl('media'), '/');
292
+ $file = str_replace(DS, '/', $img);
293
+ $file = ltrim($file, '/');
294
+ $url = $baseUrl.'/catalog/product/'.$file;
295
+ }
296
+ return $url;
297
+ }
298
+
299
+ /**
300
+ * Return array of categories for the product.
301
+ * The items in the array are strings combined of the complete category
302
+ * path to the products own category.
303
+ *
304
+ * Structure:
305
+ * array (
306
+ * /Electronics/Computers
307
+ * )
308
+ *
309
+ * @param Mage_Catalog_Model_Product $product the product model.
310
+ *
311
+ * @return array
312
+ */
313
+ protected function buildCategories(Mage_Catalog_Model_Product $product)
314
+ {
315
+ $data = array();
316
+
317
+ /** @var Increasingly_Analytics_Helper_Data $helper */
318
+ $helper = Mage::helper('increasingly_analytics');
319
+ $categoryCollection = $product->getCategoryCollection();
320
+ foreach ($categoryCollection as $category) {
321
+ $categoryString = $helper->buildCategoryString($category);
322
+ if (!empty($categoryString)) {
323
+ $data[] = $categoryString;
324
+ }
325
+ }
326
+
327
+ return $data;
328
+ }
329
+
330
+ /**
331
+ * Checks if the given image file path is valid.
332
+ *
333
+ * @param string $image the image file path.
334
+ *
335
+ * @return bool
336
+ */
337
+ protected function isValidImage($image)
338
+ {
339
+ return (!empty($image) && $image !== 'no_selection');
340
+ }
341
+
342
+ /**
343
+ * Returns the absolute url to the product page in the shop frontend.
344
+ *
345
+ * @return string the url.
346
+ */
347
+ public function getUrl()
348
+ {
349
+ return $this->_url;
350
+ }
351
+
352
+ /**
353
+ * Returns the product's unique identifier.
354
+ *
355
+ * @return int|string the ID.
356
+ */
357
+ public function getProductId()
358
+ {
359
+ return $this->_productId;
360
+ }
361
+
362
+ /**
363
+ * Setter for the product's unique identifier.
364
+ *
365
+ * @param int|string $productId the ID.
366
+ */
367
+ public function setProductId($productId)
368
+ {
369
+ $this->_productId = $productId;
370
+ }
371
+
372
+ /**
373
+ * Returns the name of the product.
374
+ *
375
+ * @return string the name.
376
+ */
377
+ public function getName()
378
+ {
379
+ return $this->_name;
380
+ }
381
+
382
+ /**
383
+ * Returns the absolute url the one of the product images in the frontend.
384
+ *
385
+ * @return string the url.
386
+ */
387
+ public function getImageUrl()
388
+ {
389
+ return $this->_imageUrl;
390
+ }
391
+
392
+ /**
393
+ * Returns the price of the product including possible discounts and taxes.
394
+ *
395
+ * @return float the price.
396
+ */
397
+ public function getPrice()
398
+ {
399
+ return $this->_price;
400
+ }
401
+
402
+ /**
403
+ * Returns the list price of the product without discounts but incl taxes.
404
+ *
405
+ * @return float the price.
406
+ */
407
+ public function getListPrice()
408
+ {
409
+ return $this->_listPrice;
410
+ }
411
+
412
+ /**
413
+ * Returns the currency code (ISO 4217) the product is sold in.
414
+ *
415
+ * @return string the currency ISO code.
416
+ */
417
+ public function getCurrencyCode()
418
+ {
419
+ return $this->_currencyCode;
420
+ }
421
+
422
+ /**
423
+ * Returns the availability of the product, i.e. if it is in stock or not.
424
+ *
425
+ * @return string the availability, either "InStock" or "OutOfStock".
426
+ */
427
+ public function getAvailability()
428
+ {
429
+ return $this->_availability;
430
+ }
431
+
432
+ /**
433
+ * Returns the tags for the product.
434
+ *
435
+ * @return array the tags array, e.g. array('tag1' => array("winter", "shoe")).
436
+ */
437
+ public function getTags()
438
+ {
439
+ return $this->_tags;
440
+ }
441
+
442
+ /**
443
+ * Returns the categories the product is located in.
444
+ *
445
+ * @return array list of category strings, e.g. array("/shoes/winter").
446
+ */
447
+ public function getCategories()
448
+ {
449
+ return $this->_categories;
450
+ }
451
+
452
+ /**
453
+ * Returns the product short description.
454
+ *
455
+ * @return string the short description.
456
+ */
457
+ public function getShortDescription()
458
+ {
459
+ return $this->_shortDescription;
460
+ }
461
+
462
+ /**
463
+ * Returns the product description.
464
+ *
465
+ * @return string the description.
466
+ */
467
+ public function getDescription()
468
+ {
469
+ return $this->_description;
470
+ }
471
+
472
+ /**
473
+ * Returns the product brand name.
474
+ *
475
+ * @return string the brand name.
476
+ */
477
+ public function getBrand()
478
+ {
479
+ return $this->_brand;
480
+ }
481
+
482
+ /**
483
+ * Returns the product publication date in the shop.
484
+ *
485
+ * @return string the date.
486
+ */
487
+ public function getDatePublished()
488
+ {
489
+ return $this->_datePublished;
490
+ }
491
+
492
+ /**
493
+ * Returns the full product description,
494
+ * i.e. both the "short" and "normal" descriptions concatenated.
495
+ *
496
+ * @return string the full descriptions.
497
+ */
498
+ public function getFullDescription()
499
+ {
500
+ $descriptions = array();
501
+ if (!empty($this->_shortDescription)) {
502
+ $descriptions[] = $this->_shortDescription;
503
+ }
504
+ if (!empty($this->_description)) {
505
+ $descriptions[] = $this->_description;
506
+ }
507
+ return implode(' ', $descriptions);
508
+ }
509
+ }
app/code/community/Increasingly/Analytics/Model/Mysql4/Bundle.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class Increasingly_Analytics_Model_Mysql4_Bundle extends Mage_Core_Model_Mysql4_Abstract
28
+ {
29
+ /**
30
+ increasingly_analytics_bundle table initialization
31
+ *
32
+ *
33
+ */
34
+ public function _construct()
35
+ {
36
+ $this->_init('increasingly_analytics/increasingly_analytics_bundle','id');
37
+ }
38
+ }
39
+
40
+ ?>
app/code/community/Increasingly/Analytics/Model/Mysql4/Bundle/Collection.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ Increasingly_Analytics_Model_Mysql4_Bundle_Collection stores the bundle and product details in the cart
29
+ *
30
+ *
31
+ */
32
+ class Increasingly_Analytics_Model_Mysql4_Bundle_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
33
+ {
34
+ public function _construct()
35
+ {
36
+ $this->_init('increasingly_analytics/bundle');
37
+ }
38
+ }
39
+
40
+ ?>
app/code/community/Increasingly/Analytics/Model/Observer.php ADDED
@@ -0,0 +1,513 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Catch events and track them to increasingly api
29
+ *
30
+ */
31
+ class Increasingly_Analytics_Model_Observer
32
+ {
33
+ /**
34
+ * Identify customer after login
35
+ *
36
+ * @param Varien_Event_Observer $observer
37
+ * @return void
38
+ */
39
+ public function customerLogin(Varien_Event_Observer $observer)
40
+ {
41
+ try
42
+ {
43
+ $helper = Mage::helper('increasingly_analytics');
44
+
45
+ if ($helper->isEnabled())
46
+ {
47
+ $customer = $observer->getEvent()->getCustomer();
48
+ $data = array(
49
+ 'customer_email' => $customer->getEmail(),
50
+ 'customer_first_name' => $customer->getFirstname(),
51
+ 'customer_last_name' => $customer->getLastname(),
52
+ 'customer_name' => $customer->getName()
53
+ );
54
+
55
+ $helper->addEvent('track', 'login',$data);
56
+ }
57
+ }
58
+ catch(Exception $e)
59
+ {
60
+ Mage::log("Customer login tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Track page views
66
+ */
67
+ public function trackPageView(Varien_Event_Observer $observer)
68
+ {
69
+ try
70
+ {
71
+ $helper = Mage::helper('increasingly_analytics');
72
+ $priceFormatter = Mage::helper('increasingly_analytics/PriceFormatter');
73
+
74
+ if ($helper->isEnabled())
75
+ {
76
+ $action = (string)$observer->getEvent()->getAction()->getFullActionName();
77
+
78
+ if ($this->_isRejected($action)) {
79
+ return;
80
+ }
81
+
82
+ // homepage page
83
+ if ($action == 'cms_index_index' || $action == 'cms_page_view') {
84
+ $title = Mage::getSingleton('cms/page')->getTitle();
85
+ $data = array('page_title' => $title);
86
+ $helper->addEvent('track', 'home_page_visit', $data);
87
+ return;
88
+ }
89
+
90
+ // category view page
91
+ if($action == 'catalog_category_view') {
92
+ $category = Mage::registry('current_category');
93
+ $data = array(
94
+ 'category_id' => $category->getId(),
95
+ 'category_name' => $category->getName()
96
+ );
97
+ $helper->addEvent('track', 'category_page_visit', $data);
98
+ return;
99
+ }
100
+ // product view page
101
+ if ($action == 'catalog_product_view') {
102
+ $product = Mage::registry('current_product');
103
+ $data = array(
104
+ 'product_id' => $product->getId(),
105
+ 'product_name' => $product->getName(),
106
+ 'product_price' => $priceFormatter->format($product->getFinalPrice()),
107
+ 'product_url' => $product->getProductUrl(),
108
+ 'product_sku' => $product->getSku(),
109
+ );
110
+
111
+ if($product->getImage())
112
+ $data['product_image_url'] = (string)Mage::helper('catalog/image')->init($product, 'image');
113
+
114
+ if(count($product->getCategoryIds())) {
115
+ $categories = array();
116
+ $collection = $product->getCategoryCollection()->addAttributeToSelect('*');
117
+ foreach ($collection as $category) {
118
+ $categories[] = array(
119
+ 'category_id' => $category->getId(),
120
+ 'category_name' => $category->getName()
121
+ );
122
+ }
123
+ $data['categories'] = $categories;
124
+ }
125
+ $helper->addEvent('track', 'product_page_visit', $data);
126
+ return;
127
+ }
128
+
129
+ // Catalog search page
130
+ if ($action == 'catalogsearch_result_index') {
131
+ $query = Mage::helper('catalogsearch')->getQuery();
132
+ if ($text = $query->getQueryText()) {
133
+ $resultCount = Mage::app()->getLayout()->getBlock('search.result')->getResultCount();
134
+ $params = array(
135
+ 'query' => $text,
136
+ 'result_count' => $resultCount
137
+ );
138
+ $helper->addEvent('track', 'search_page', $params);
139
+ return;
140
+ }
141
+ }
142
+ }
143
+ }
144
+ catch(Exception $e)
145
+ {
146
+ Mage::log("Page View tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
147
+ }
148
+ }
149
+
150
+
151
+ /**
152
+ * List of events that we don't want to track
153
+ *
154
+ * @param string event
155
+ */
156
+ private function _isRejected($event)
157
+ {
158
+ return in_array(
159
+ $event,
160
+ array('catalogsearch_advanced_result', 'catalogsearch_advanced_index')
161
+ );
162
+ }
163
+
164
+ /**
165
+ * Adding to cart
166
+ * "checkout_cart_product_add_after"
167
+ */
168
+ public function addToCart(Varien_Event_Observer $observer)
169
+ {
170
+ try
171
+ {
172
+ /**
173
+ * @var Mage_Sales_Model_Quote_Item
174
+ */
175
+ $item = $observer->getQuoteItem();
176
+ $product = $item->getProduct();
177
+ $cartProduct = $observer->getProduct();
178
+ if ($cartProduct->isGrouped()) {
179
+ $options = Mage::app()->getRequest()->getParam('super_group');
180
+ if (is_array($options)) {
181
+ foreach ($options as $productId => $qty) {
182
+ $this->_addToCart((int)$productId, $cartProduct, (int)$qty);
183
+ }
184
+ }
185
+ } elseif($cartProduct->isConfigurable()) {
186
+ $this->_addToCart($product->getId(), $cartProduct, (int)$cartProduct->getCartQty());
187
+ } else {
188
+ $this->_addToCart($cartProduct->getId(), $cartProduct, (int)$cartProduct->getCartQty());
189
+ }
190
+ }
191
+ catch(Exception $e)
192
+ {
193
+ Mage::log("Add to cart tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
194
+ }
195
+ }
196
+
197
+ /**
198
+ * Add to cart
199
+ */
200
+ private function _addToCart($productId, $cartProduct, $qty) {
201
+
202
+ $helper = Mage::helper('increasingly_analytics');
203
+ $priceFormatter = Mage::helper('increasingly_analytics/PriceFormatter');
204
+ $product = Mage::getModel('catalog/product')->load($productId);
205
+ Mage::log($product->getPrice()*0.80, null, 'Increasingly_Analytics.log');
206
+ $product->setSpecialPrice( ($product->getPrice() * .80) );
207
+ $product->setData('special_price', 99.99);
208
+ $product->save();
209
+ if ($helper->isEnabled()){
210
+ $data = array(
211
+ 'product_id' => $cartProduct->getId(),
212
+ 'product_name' => $cartProduct->getName(),
213
+ 'product_url' => $cartProduct->getProductUrl(),
214
+ 'product_sku' => $cartProduct->getSku(),
215
+ 'product_type' => $cartProduct->getTypeId(),
216
+ 'qty' => $qty,
217
+ 'product_price' => $priceFormatter->format($cartProduct->getFinalPrice())
218
+ );
219
+
220
+ if ($cartProduct->isGrouped() || $cartProduct->isConfigurable()) {
221
+ $product = Mage::getModel('catalog/product')->load($productId);
222
+
223
+ $data['product_price'] = $priceFormatter->format($product->getFinalPrice());
224
+ $data['option_product_id'] = $product->getId();
225
+ $data['option_product_sku'] = $product->getSku();
226
+ $data['option_product_name'] = $product->getName();
227
+ $data['option_product_price'] = $priceFormatter->format($product->getFinalPrice());
228
+ }
229
+
230
+ if(Mage::getSingleton('customer/session')->isLoggedIn()) {
231
+ $data['is_logged_in'] = true;
232
+ }
233
+ else {
234
+ $data['is_logged_in'] = false;
235
+ }
236
+ $helper->addEvent('track', 'add_to_cart', $data);
237
+ }
238
+
239
+ }
240
+
241
+ /**
242
+ * Removing item from shopping cart
243
+ *
244
+ * @param Varien_Event_Observer $observer
245
+ * @return void
246
+ */
247
+ public function removeFromCart(Varien_Event_Observer $observer)
248
+ {
249
+ try
250
+ {
251
+ $helper = Mage::helper('increasingly_analytics');
252
+
253
+ if ($helper->isEnabled())
254
+ {
255
+ $item = $observer->getQuoteItem();
256
+ $product = $item->getProduct();
257
+
258
+ $data = array(
259
+ 'product_id' => $product->getId()
260
+ );
261
+
262
+ if(Mage::getSingleton('customer/session')->isLoggedIn()) {
263
+ $data['is_logged_in'] = true;
264
+ }
265
+ else {
266
+ $data['is_logged_in'] = false;
267
+ }
268
+ $helper->deleteBundleOnProductDeleteFromCart($product->getId());
269
+ $helper->addEvent('track', 'remove_from_cart', $data);
270
+ }
271
+
272
+ }
273
+ catch(Exception $e)
274
+ {
275
+ Mage::log("Remove from cart tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Empty cart handler to delete all products from bundle
281
+ */
282
+ public function empty_cart(Varien_Event_Observer $observer){
283
+ $helper = Mage::helper('increasingly_analytics');
284
+
285
+ $quote = $observer->getEvent()->getQuote();
286
+ if($quote->getItemsCount() == 0) {
287
+ $helper->deleteBundleOnEmptyCart($quote);
288
+ }
289
+ }
290
+ /**
291
+ * applyCartDiscount to shopping cart
292
+ *
293
+ * @param Varien_Event_Observer $observer
294
+ * @return void
295
+ */
296
+ public function applyCartDiscount(Varien_Event_Observer $observer)
297
+ {
298
+ try
299
+ {
300
+ $bundle_product_ids = [];
301
+ $quote_product_ids = [];
302
+ $cookieValue = Mage::getModel('core/cookie')->get('ivid');
303
+ $userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
304
+ $items = $observer->getEvent()->getQuote()->getAllItems();
305
+ $eligibleProducts = [];
306
+ $discount = 0;
307
+ foreach ($items as $item) {
308
+ array_push($quote_product_ids, $item->getProductId());
309
+ }
310
+ foreach ($userBundleCollection as $bundle) {
311
+ //First Bundle products
312
+ $bundle_product_ids = explode(',', $bundle->getProductIds());
313
+ $productsIds = array_intersect($quote_product_ids, $bundle_product_ids);
314
+ if(count($productsIds) == count($bundle_product_ids) )
315
+ $discount += $bundle->getDiscountPrice();
316
+ }
317
+
318
+ if($discount > 0){
319
+ $quote=$observer->getEvent()->getQuote();
320
+ $quoteid=$quote->getId();
321
+ $discountAmount=$discount;
322
+ if($quoteid) {
323
+ if($discountAmount>0) {
324
+ $total=$quote->getBaseSubtotal();
325
+ $quote->setSubtotal(0);
326
+ $quote->setBaseSubtotal(0);
327
+
328
+ $quote->setSubtotalWithDiscount(0);
329
+ $quote->setBaseSubtotalWithDiscount(0);
330
+
331
+ $quote->setGrandTotal(0);
332
+ $quote->setBaseGrandTotal(0);
333
+
334
+
335
+ $canAddItems = $quote->isVirtual()? ('billing') : ('shipping');
336
+ foreach ($quote->getAllAddresses() as $address) {
337
+
338
+ $address->setSubtotal(0);
339
+ $address->setBaseSubtotal(0);
340
+
341
+ $address->setGrandTotal(0);
342
+ $address->setBaseGrandTotal(0);
343
+
344
+ $address->collectTotals();
345
+
346
+ $quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
347
+ $quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());
348
+
349
+ $quote->setSubtotalWithDiscount(
350
+ (float) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()
351
+ );
352
+ $quote->setBaseSubtotalWithDiscount(
353
+ (float) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()
354
+ );
355
+
356
+ $quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
357
+ $quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
358
+
359
+ $quote ->save();
360
+
361
+ $quote->setGrandTotal($quote->getBaseSubtotal()-$discountAmount)
362
+ ->setBaseGrandTotal($quote->getBaseSubtotal()-$discountAmount)
363
+ ->setSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
364
+ ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
365
+ ->save();
366
+
367
+
368
+ if($address->getAddressType()==$canAddItems) {
369
+ //echo $address->setDiscountAmount; exit;
370
+ $address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount()-$discountAmount);
371
+ $address->setGrandTotal((float) $address->getGrandTotal()-$discountAmount);
372
+ $address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount()-$discountAmount);
373
+ $address->setBaseGrandTotal((float) $address->getBaseGrandTotal()-$discountAmount);
374
+ if($address->getDiscountDescription()){
375
+ $address->setDiscountAmount(-($address->getDiscountAmount()-$discountAmount));
376
+ $address->setDiscountDescription($address->getDiscountDescription().', Custom Discount');
377
+ $address->setBaseDiscountAmount(-($address->getBaseDiscountAmount()-$discountAmount));
378
+ }else {
379
+ $address->setDiscountAmount(-($discountAmount));
380
+ $address->setDiscountDescription('Custom Discount');
381
+ $address->setBaseDiscountAmount(-($discountAmount));
382
+ }
383
+ $address->save();
384
+ }//end: if
385
+ } //end: foreach
386
+ //echo $quote->getGrandTotal();
387
+
388
+ foreach($quote->getAllItems() as $item){
389
+ //We apply discount amount based on the ratio between the GrandTotal and the RowTotal
390
+ $rat=$item->getPriceInclTax()/$total;
391
+ $ratdisc=$discountAmount*$rat;
392
+ $item->setDiscountAmount(($item->getDiscountAmount()+$ratdisc) * $item->getQty());
393
+ $item->setBaseDiscountAmount(($item->getBaseDiscountAmount()+$ratdisc) * $item->getQty())->save();
394
+ }
395
+ }
396
+ }
397
+ }
398
+ }
399
+ catch(Exception $e)
400
+ {
401
+ Mage::log("Remove from cart tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
402
+ }
403
+
404
+ }
405
+
406
+
407
+ /**
408
+ * Track new order
409
+ *
410
+ */
411
+ public function trackNewOrder(Varien_Event_Observer $observer)
412
+ {
413
+ try
414
+ {
415
+
416
+ $helper = Mage::helper('increasingly_analytics');
417
+
418
+ if ($helper->isEnabled())
419
+ {
420
+ $data = array();
421
+ $order = $observer->getOrder();
422
+
423
+ if ($order->getId())
424
+ {
425
+ $data = $helper->buildOrderDetailsData($order);
426
+ $helper->addEvent('track', 'order', $data);
427
+ }
428
+ }
429
+ }
430
+ catch(Exception $e)
431
+ {
432
+ Mage::log("New order tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
433
+ }
434
+ }
435
+
436
+
437
+ /**
438
+ * Send order update information
439
+ *
440
+ */
441
+ public function updateOrder(Varien_Event_Observer $observer)
442
+ {
443
+ try
444
+ {
445
+ $helper = Mage::helper('increasingly_analytics');
446
+
447
+ if ($helper->isEnabled())
448
+ {
449
+ $order = $observer->getOrder();
450
+ $orderDetails = $helper->buildOrderDetailsData($order);
451
+ $helper->increasinglyApi($orderDetails,'order','track',$helper->getApiToken(),$helper->getApiSecret());
452
+ }
453
+
454
+ }
455
+ catch(Exception $e)
456
+ {
457
+ Mage::log("Update order tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
458
+ }
459
+ }
460
+
461
+ /**
462
+ * Send product update information
463
+ *
464
+ */
465
+ public function productAddOrUpdate(Varien_Event_Observer $observer)
466
+ {
467
+ try
468
+ {
469
+ $helper = Mage::helper('increasingly_analytics');
470
+
471
+ if ($helper->isEnabled())
472
+ {
473
+ $productId = $observer->getEvent()->getProduct()->getId();
474
+ $product = Mage::getModel('catalog/product')->load($productId);
475
+
476
+ $productFormatHelper = Mage::helper('increasingly_analytics/ProductFormatter');
477
+
478
+ $formattedProductInfo = $productFormatHelper->formatProductInfo($product);
479
+ $helper->increasinglyApi($formattedProductInfo,'product_add_or_update','track',$helper->getApiToken(),$helper->getApiSecret());
480
+ }
481
+
482
+ }
483
+ catch(Exception $e)
484
+ {
485
+ Mage::log("Product Add or Update tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
486
+ }
487
+ }
488
+
489
+ /**
490
+ * Send product delete information
491
+ *
492
+ */
493
+ public function productDelete(Varien_Event_Observer $observer)
494
+ {
495
+ try
496
+ {
497
+ $helper = Mage::helper('increasingly_analytics');
498
+
499
+ if ($helper->isEnabled()){
500
+ $productId = $observer->getEvent()->getProduct()->getId();
501
+
502
+ $productData = array('product_id' => $productId);
503
+ $helper->deleteBundleOnProductDeleteFromCart($productId);
504
+ $helper->increasinglyApi($productData,'product_delete','track',$helper->getApiToken(),$helper->getApiSecret());
505
+ }
506
+
507
+ }
508
+ catch(Exception $e)
509
+ {
510
+ Mage::log("Product delete tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
511
+ }
512
+ }
513
+ }
app/code/community/Increasingly/Analytics/Model/Product.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Product model that extends the Magento catalog product model.
30
+ * Used to define custom product collection in product exports to Increasingly.
31
+ *
32
+ */
33
+ class Increasingly_Analytics_Model_Product extends Mage_Catalog_Model_Product
34
+ {
35
+ /**
36
+ * @inheritdoc
37
+ */
38
+ protected function _construct()
39
+ {
40
+ $this->_init('increasingly_analytics/product');
41
+ }
42
+ }
app/code/community/Increasingly/Analytics/controllers/AddbundletocartController.php ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Returns product details to increasingly on API call
29
+ */
30
+
31
+ require_once 'Mage/Checkout/controllers/CartController.php';
32
+ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Controller_Front_Action
33
+ {
34
+ public $cart;
35
+ /***Index cart for add to cart
36
+ *
37
+ */
38
+ public function indexAction ()
39
+ {
40
+ try
41
+ {
42
+ $this->cart = Mage::getSingleton('checkout/cart');
43
+ $data = $_POST["jsonData"];
44
+ $data = json_decode($data,TRUE);
45
+ $current_page = $data[0]["current_page"];
46
+ $product = Mage::getModel('catalog/product');
47
+ $inStockProducts = [];
48
+ $outOfStockProducts = [];
49
+ $productErrorStr = "";
50
+ $productSuccessStr = "";
51
+ if($current_page == "checkout_cart_index"){
52
+ $quote = Mage::getModel('checkout/cart')->getQuote();
53
+
54
+ //Get all Cart product Ids
55
+ $cartProductIds =[];
56
+ foreach ($quote->getAllItems() as $item) {
57
+ array_push($cartProductIds, $item->getProduct()->getId());
58
+ }
59
+
60
+ //Get all bundle Product Ids
61
+ $previousCartProducts = [];
62
+ for ($x = 0; $x < count($data[0]["params"]); $x++) {
63
+ array_push($previousCartProducts,trim($data[0]["params"][$x]["product_id"]));
64
+ }
65
+
66
+ //Get all Bundle product Ids that are in cart
67
+ $result = array_intersect($cartProductIds, $previousCartProducts);
68
+ $productsToAddToCart = array_diff($previousCartProducts,$result);
69
+
70
+ //All bundle products are in cart,add all
71
+ if(count($result) == count($cartProductIds) && count($result) == count($previousCartProducts) && count($cartProductIds) == count($previousCartProducts)){
72
+ $this->addToCart($data);
73
+ }else{
74
+
75
+ //Not all bundled products are in the cart,add only products from the bundle to cart that doesn't exists in cart and dont add bundles to the database
76
+ if(count($productsToAddToCart) >= 1){
77
+
78
+ //Push the products into instock and out of stock arrays to handle the success and error messages at cart page
79
+ foreach ($productsToAddToCart as $productId) {
80
+ $product = Mage::getModel('catalog/product');
81
+ $product->load($productId);
82
+
83
+ //In Stock or Out of stock status of the product
84
+ $inStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock();
85
+ if($inStock){
86
+
87
+ //Push all the instock products to the inStockProducts array
88
+ array_push($inStockProducts, $productId);
89
+ }
90
+ else{
91
+
92
+ //Push all the out of stock products to the outOfStockProducts array
93
+ array_push($outOfStockProducts, $productId);
94
+ //Prepare the error message for the products out of stock
95
+ $productErrorStr .= $product->getName().", ";
96
+ }
97
+ }
98
+ //Add all the instock products to the cart and prepare the success message
99
+ foreach ($inStockProducts as $product_id) {
100
+ $this->addTo($product_id,$data);
101
+ $productSuccessStr .= $product->getName().", ";
102
+ }
103
+ //Trim the success message
104
+ $productSuccessStr = rtrim(trim($productSuccessStr),',');
105
+ //Trim the error message
106
+ $productErrorStr = rtrim(trim($productErrorStr),',');
107
+ //Save the cart
108
+ $this->cart->save();
109
+ //Get teh quote
110
+ $quote = Mage::getModel('checkout/cart')->getQuote();
111
+ //Add success message
112
+ if($productSuccessStr != "")
113
+ Mage::getSingleton('core/session')->addSuccess($productSuccessStr.' added to your shopping cart');
114
+ //Add error message
115
+ if($productErrorStr != "")
116
+ Mage::getSingleton('core/session')->addNotice($productErrorStr.' is out of stock');
117
+ //Set cart was updated
118
+ Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
119
+ //Redirect to cart
120
+ $this->_redirect('checkout/cart');
121
+ }
122
+ if(count($productsToAddToCart)==0){
123
+ //Add all bundled products to the cart when the cart is empty from the cart page and add bundles
124
+ $this->addToCart($data);
125
+ }
126
+ }
127
+
128
+ }else{
129
+ //Add to bundle from all other pages except cart
130
+ $this->addToCart($data);
131
+ }
132
+ }
133
+ catch(Exception $e)
134
+ {
135
+ $this->_redirect('checkout/cart');
136
+ }
137
+
138
+
139
+ }
140
+ /**Adds the product to the cart on click of Add to Basket button
141
+ *
142
+ */
143
+ public function addTo($productId,$data){
144
+ try{
145
+ if($data[0]["bundle_id"] != null || $data[0]["bundle_id"] || ""){
146
+ $bundle_id = $data[0]["bundle_id"];
147
+ $productIds = [];
148
+ $discountPrice = $data[0]["discountPrice"];
149
+ $totalSpecialPrice = $data[0]["totalSpecialPrice"];
150
+ $product = Mage::getModel('catalog/product');
151
+ $product->load($productId);
152
+ $this->cart->addProduct($product,array('qty' => 1));
153
+ }
154
+ }
155
+ catch(Exception $e)
156
+ {
157
+ Mage::log("Increasingly AddTo cart controller - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
158
+ }
159
+ }
160
+
161
+ /**Adds all the bundled products to the cart from all pages
162
+ *
163
+ */
164
+ public function addToCart($data){
165
+ try{
166
+ $this->cart= Mage::getSingleton('checkout/cart');
167
+
168
+ if($data[0]["bundle_id"] != null || $data[0]["bundle_id"] || ""){
169
+ $bundle_id = $data[0]["bundle_id"];
170
+ $productIds = [];
171
+ $discountPrice = $data[0]["discountPrice"];
172
+ $totalSpecialPrice = $data[0]["totalSpecialPrice"];
173
+ $inStockProducts = [];
174
+ $outOfStockProducts = [];
175
+ $productErrorStr = "";
176
+ $productSuccessStr = "";
177
+ for ($x = 0; $x < count($data[0]["params"]); $x++) {
178
+ $productIds[$x] = trim($data[0]["params"][$x]["product_id"]);
179
+ }
180
+ //Push the products into instock and out of stock arrays to handle the success and error messages at cart page
181
+ foreach ($productIds as $productId) {
182
+ $product = Mage::getModel('catalog/product');
183
+ $product->load($productId);
184
+ $inStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock();
185
+ if($inStock){
186
+ array_push($inStockProducts, $productId);
187
+ }
188
+ else{
189
+ array_push($outOfStockProducts, $productId);
190
+ //Prepare the error message for the products out of stock
191
+ $productErrorStr .= $product->getName().", ";
192
+ }
193
+ }
194
+ //Add all the instock products to the cart and prepare the success message
195
+ foreach ($inStockProducts as $product_id) {
196
+ $product = Mage::getModel('catalog/product');
197
+ $product->load($product_id);
198
+ $this->cart->addProduct($product,array('qty' => 1));
199
+ $productSuccessStr .= $product->getName().", ";
200
+ }
201
+ //Trim the success message
202
+ $productSuccessStr = rtrim(trim($productSuccessStr),',');
203
+ //Trim the error message
204
+ $productErrorStr = rtrim(trim($productErrorStr),',');
205
+ //Save all the products added to the cart
206
+ $this->cart->save();
207
+ //Add the bundles to the database if all the products are in stock
208
+ if(count($outOfStockProducts) == 0){
209
+ $productIdsStr = implode(',',$productIds);
210
+ $cookieValue = Mage::getModel('core/cookie')->get('ivid');
211
+ $userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
212
+ ->addFieldToFilter('bundle_id', $bundle_id)
213
+ ->addFieldToFilter('increasingly_visitor_id',$cookieValue);
214
+
215
+ //Check if bundle already exists,add if not already present
216
+ if(count($userBundleCollection) < 1){
217
+ $userBundle = Mage::getModel('increasingly_analytics/bundle');
218
+ $userBundle->setBundleId(intval($bundle_id));
219
+ $userBundle->setProductIds($productIdsStr);
220
+ $userBundle->setIncreasinglyVisitorId($cookieValue);
221
+ $userBundle->setDiscountPrice($discountPrice);
222
+ $userBundle->setTotalSpecialPrice($totalSpecialPrice);
223
+ $userBundle->save();
224
+ }
225
+ //Set cart was updated flag
226
+ Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
227
+
228
+ }
229
+ if($productSuccessStr != "")
230
+ Mage::getSingleton('core/session')->addSuccess($productSuccessStr.' added to your shopping cart');
231
+ //Error message for the out of stock products
232
+ if($productErrorStr != "")
233
+ Mage::getSingleton('core/session')->addNotice($productErrorStr.' is out of stock');
234
+ //Redirect to the cart
235
+ $this->_redirect('checkout/cart');
236
+
237
+ }
238
+ }
239
+ catch(Exception $e)
240
+ {
241
+ Mage::log("Increasingly addToCart controller - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
242
+ }
243
+
244
+ }
245
+ }
app/code/community/Increasingly/Analytics/controllers/Adminhtml/DataIntegrationController.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * controller for sending data to increasingly
29
+ */
30
+ class Increasingly_Analytics_Adminhtml_DataIntegrationController extends Mage_Adminhtml_Controller_Action
31
+ {
32
+ /**
33
+ * load increasingly config UI on menu click
34
+ */
35
+ public function indexAction()
36
+ {
37
+ $this->loadLayout()->_setActiveMenu('increasingly');
38
+ $this->renderLayout();
39
+ }
40
+
41
+ public function saveConfigDetailsAction()
42
+ {
43
+ $session = Mage::getSingleton('core/session');
44
+ try
45
+ {
46
+
47
+ $isIncreasinglyEnabled = $this->getRequest()->getPost('increasingly_analytics_settings_enable');
48
+ $apiKey = $this->getRequest()->getPost('increasingly_analytics_settings_api_key');
49
+ $apiSecret = $this->getRequest()->getPost('increasingly_analytics_settings_api_secret');
50
+
51
+ if ($isIncreasinglyEnabled == 1 && (empty($apiKey) || empty($apiSecret)))
52
+ {
53
+ Mage::throwException($this->__('Invalid form data. The api key and secret are missing!'));
54
+ }
55
+
56
+ $helper = Mage::helper('increasingly_analytics');
57
+
58
+ $data = array('is_api_enabled' => (boolean)$isIncreasinglyEnabled);
59
+
60
+ $result = $helper->increasinglyApi($data,'validate_api','track',$apiKey,$apiSecret);
61
+
62
+ if($result != null && $result != '' && $result->status == 'success' && json_decode($result->data)->isValidUser == 'true')
63
+ {
64
+ $configDetails = Mage::getModel('core/config');
65
+ $configDetails->saveConfig('increasingly_analytics/settings/enable', $isIncreasinglyEnabled, 'default', 0);
66
+ $configDetails->saveConfig('increasingly_analytics/settings/api_key', $apiKey, 'default', 0);
67
+ $configDetails->saveConfig('increasingly_analytics/settings/api_secret', $apiSecret, 'default', 0);
68
+ $configDetails=Mage::getModel('core/config');
69
+
70
+ $data['store_name'] = Mage::app()->getStore()->getName();
71
+ $data['store_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
72
+ $helper->increasinglyApi($data,'save_api_enable_status','track',$apiKey,$apiSecret);
73
+
74
+ $session->addSuccess('The configuration has been saved.');
75
+ }
76
+ else
77
+ {
78
+ Mage::log('Invalid user - '. $result, null, 'Increasingly_Analytics.log');
79
+ $session->addWarning('An error occurred while saving this configuration:');
80
+ }
81
+
82
+ }
83
+ catch (Exception $e)
84
+ {
85
+ Mage::log($e->getMessage(), null, 'Increasingly_Analytics.log');
86
+ $session->addException($e,'An error occurred while saving this configuration:');
87
+ }
88
+
89
+ $this->_redirect('*/*/index');
90
+ }
91
+
92
+ /**
93
+ * Import previous order data
94
+ * @return void
95
+ */
96
+ public function importOrderAction()
97
+ {
98
+
99
+ try
100
+ {
101
+ $helper = Mage::helper('increasingly_analytics');
102
+ $import = Mage::getSingleton('increasingly_analytics/DataIntegration');
103
+ $chunkId = (int)$this->getRequest()->getParam('chunk_id');
104
+
105
+ $orders = $import->getOrderDetails($chunkId);
106
+ $orderDetailsForImport = array();
107
+
108
+ foreach ($orders as $order)
109
+ {
110
+ if ($order->getId())
111
+ {
112
+ $orderDetails = $helper->buildOrderDetailsData($order);
113
+ array_push($orderDetailsForImport, $orderDetails);
114
+ }
115
+ }
116
+
117
+ $result = $helper->increasinglyApi($orderDetailsForImport,'order','import',$helper->getApiToken(),$helper->getApiSecret());
118
+
119
+ }
120
+ catch (Exception $e)
121
+ {
122
+ Mage::log("Import previous order data - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
123
+ }
124
+ }
125
+ }
app/code/community/Increasingly/Analytics/controllers/ProductsApiController.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * Returns product details to increasingly on API call
29
+ */
30
+
31
+ class Increasingly_Analytics_ProductsApiController extends Mage_Core_Controller_Front_Action
32
+ {
33
+
34
+ public function productsAction()
35
+ {
36
+ try
37
+ {
38
+ $version = (string)Mage::getConfig()->getModuleConfig("Increasingly_Analytics")->version;
39
+
40
+ if(!$this->isRequestAuthorized())
41
+ {
42
+ return $this;
43
+ }
44
+
45
+ $products = array();
46
+ $productFormatHelper = Mage::helper('increasingly_analytics/ProductFormatter');
47
+
48
+ $attributes = array(
49
+ 'name',
50
+ 'sku',
51
+ 'image',
52
+ 'manufacturer',
53
+ 'price',
54
+ 'final_price',
55
+ 'special_price',
56
+ 'short_description',
57
+ 'color',
58
+ 'weight',
59
+ 'size'
60
+ );
61
+
62
+ $limit = $this->getRequest()->getParam('limit', 200);
63
+ $offset = $this->getRequest()->getParam('offset', 1);
64
+
65
+ $productsCollection = Mage::getModel('catalog/product')->getCollection();
66
+
67
+ $productsCollection->addAttributeToSelect($attributes)->getSelect()->limit($limit, $offset);
68
+
69
+ $totalProductCount = Mage::getModel('catalog/product')->getCollection()->count();
70
+
71
+ foreach($productsCollection as $product)
72
+ {
73
+ $product = $productFormatHelper->formatProductInfo($product);
74
+
75
+ if($product !== null)
76
+ {
77
+ $products[] = $product;
78
+ }
79
+ }
80
+
81
+ $this->getResponse()
82
+ ->setBody(json_encode(array('products' => $products,'version' => $version, 'total_product_count' => $totalProductCount)))
83
+ ->setHttpResponseCode(200)
84
+ ->setHeader('Content-type', 'application/json', true);
85
+
86
+
87
+ } catch(Exception $e) {
88
+
89
+ Mage::log($e->getMessage(), null, 'Increasingly_Analytics.log');
90
+ $this->getResponse()
91
+ ->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => $version)))
92
+ ->setHttpResponseCode(500)
93
+ ->setHeader('Content-type', 'application/json', true);
94
+ }
95
+
96
+ return $this;
97
+
98
+ }
99
+
100
+ private function isRequestAuthorized()
101
+ {
102
+ $helper = Mage::helper('increasingly_analytics');
103
+
104
+ if ($helper->isEnabled())
105
+ {
106
+ $apiKey = $helper->getApiToken();
107
+ $version = (string)Mage::getConfig()->getModuleConfig("Increasingly_Analytics")->version;
108
+
109
+ // Check for api key
110
+ if(!$apiKey && strlen($apiKey) === 0) {
111
+
112
+ $this->getResponse()
113
+ ->setBody(json_encode(array('status' => 'error', 'message' => 'API key is missing', 'version' => $version)))
114
+ ->setHttpResponseCode(403)
115
+ ->setHeader('Content-type', 'application/json', true);
116
+ return false;
117
+ }
118
+
119
+ $authKey = $this->getRequest()->getHeader('authKey');
120
+
121
+ if (!$authKey || strlen($authKey) == 0) {
122
+ $authKey = $this->getRequest()->getParam('authKey');
123
+ }
124
+
125
+ if (!$authKey) {
126
+
127
+ $this->getResponse()
128
+ ->setBody(json_encode(array('status' => 'error', 'message' => 'Error,Authorization header not found', 'version' => $version)))
129
+ ->setHttpResponseCode(500)
130
+ ->setHeader('Content-type', 'application/json', true);
131
+ return false;
132
+ }
133
+
134
+ if(trim($authKey) !== trim($apiKey)) {
135
+
136
+ $this->getResponse()
137
+ ->setBody(json_encode(array('status' => 'error', 'message' => 'Authorization failed', 'version' => $version)))
138
+ ->setHttpResponseCode(401)
139
+ ->setHeader('Content-type', 'application/json', true);
140
+ return false;
141
+ }
142
+
143
+ return true;
144
+ }
145
+ else {
146
+
147
+ $this->getResponse()
148
+ ->setBody(json_encode(array('status' => 'error', 'message' => 'Increasingly module is disabled', 'version' => $version)))
149
+ ->setHttpResponseCode(403)
150
+ ->setHeader('Content-type', 'application/json', true);
151
+ return false;
152
+ }
153
+
154
+ }
155
+
156
+ }
app/code/community/Increasingly/Analytics/etc/config.xml ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ -->
27
+ <!--
28
+ /**
29
+ * @package Increasingly_Analytics
30
+ */
31
+ -->
32
+ <config>
33
+ <modules>
34
+ <Increasingly_Analytics>
35
+ <version>1.0.0</version>
36
+ </Increasingly_Analytics>
37
+ </modules>
38
+ <global>
39
+ <events>
40
+ <controller_action_layout_generate_blocks_after>
41
+ <observers>
42
+ <page_view>
43
+ <class>Increasingly_Analytics_Model_Observer</class>
44
+ <method>trackPageView</method>
45
+ <type>singleton</type>
46
+ </page_view>
47
+ </observers>
48
+ </controller_action_layout_generate_blocks_after>
49
+ <checkout_cart_product_add_after>
50
+ <observers>
51
+ <add_to_cart>
52
+ <type>singleton</type>
53
+ <class>Increasingly_Analytics_Model_Observer</class>
54
+ <method>addToCart</method>
55
+ </add_to_cart>
56
+ </observers>
57
+ </checkout_cart_product_add_after>
58
+ <sales_quote_remove_item>
59
+ <observers>
60
+ <remove_from_cart>
61
+ <type>singleton</type>
62
+ <class>Increasingly_Analytics_Model_Observer</class>
63
+ <method>removeFromCart</method>
64
+ </remove_from_cart>
65
+ </observers>
66
+ </sales_quote_remove_item>
67
+ <sales_order_place_after>
68
+ <observers>
69
+ <place_order>
70
+ <type>singleton</type>
71
+ <class>Increasingly_Analytics_Model_Observer</class>
72
+ <method>trackNewOrder</method>
73
+ </place_order>
74
+ </observers>
75
+ </sales_order_place_after>
76
+ <sales_order_save_after>
77
+ <observers>
78
+ <update_order>
79
+ <type>singleton</type>
80
+ <class>Increasingly_Analytics_Model_Observer</class>
81
+ <method>updateOrder</method>
82
+ </update_order>
83
+ </observers>
84
+ </sales_order_save_after>
85
+ <sales_quote_collect_totals_after>
86
+ <observers>
87
+ <apply_cart_discount>
88
+ <type>singleton</type>
89
+ <class>Increasingly_Analytics_Model_Observer</class>
90
+ <method>applyCartDiscount</method>
91
+ </apply_cart_discount>
92
+ </observers>
93
+ </sales_quote_collect_totals_after>
94
+ <sales_quote_save_after>
95
+ <observers>
96
+ <empty_cart>
97
+ <type>singleton</type>
98
+ <class>Increasingly_Analytics_Model_Observer</class>
99
+ <method>empty_cart</method>
100
+ </empty_cart>
101
+ </observers>
102
+ </sales_quote_save_after>
103
+ <catalog_product_save_commit_after>
104
+ <observers>
105
+ <product_update>
106
+ <type>singleton</type>
107
+ <class>Increasingly_Analytics_Model_Observer</class>
108
+ <method>productAddOrUpdate</method>
109
+ </product_update>
110
+ </observers>
111
+ </catalog_product_save_commit_after>
112
+ <catalog_product_delete_commit_after>
113
+ <observers>
114
+ <product_delete>
115
+ <type>singleton</type>
116
+ <class>Increasingly_Analytics_Model_Observer</class>
117
+ <method>productDelete</method>
118
+ </product_delete>
119
+ </observers>
120
+ </catalog_product_delete_commit_after>
121
+ </events>
122
+ <models>
123
+ <increasingly_analytics>
124
+ <class>Increasingly_Analytics_Model</class>
125
+ <resourceModel>increasingly_analytics_mysql4</resourceModel>
126
+ </increasingly_analytics>
127
+ <increasingly_analytics_mysql4>
128
+ <class>Increasingly_Analytics_Model_Mysql4</class>
129
+ <entities>
130
+ <increasingly_analytics_bundle>
131
+ <table>increasingly_analytics_bundle</table>
132
+ </increasingly_analytics_bundle>
133
+ </entities>
134
+ </increasingly_analytics_mysql4>
135
+ </models>
136
+ <resources>
137
+ <increasingly_analytics_setup>
138
+ <setup>
139
+ <module>Increasingly_Analytics</module>
140
+ </setup>
141
+ <connection>
142
+ <use>core_setup</use>
143
+ </connection>
144
+ </increasingly_analytics_setup>
145
+ <increasingly_analytics_write>
146
+ <connection>
147
+ <use>core_write</use>
148
+ </connection>
149
+ </increasingly_analytics_write>
150
+ <increasingly_analytics_read>
151
+ <connection>
152
+ <use>core_read</use>
153
+ </connection>
154
+ </increasingly_analytics_read>
155
+ </resources>
156
+ <blocks>
157
+ <increasingly_analytics>
158
+ <class>Increasingly_Analytics_Block</class>
159
+ </increasingly_analytics>
160
+ </blocks>
161
+ <helpers>
162
+ <increasingly_analytics>
163
+ <class>Increasingly_Analytics_Helper</class>
164
+ </increasingly_analytics>
165
+ </helpers>
166
+ </global>
167
+ <frontend>
168
+ <layout>
169
+ <updates>
170
+ <increasingly_analytics>
171
+ <file>increasingly_analytics.xml</file>
172
+ </increasingly_analytics>
173
+ </updates>
174
+ </layout>
175
+ <routers>
176
+ <increasingly_analytics>
177
+ <use>standard</use>
178
+ <args>
179
+ <module>Increasingly_Analytics</module>
180
+ <frontName>increasingly</frontName>
181
+ </args>
182
+ </increasingly_analytics>
183
+ </routers>
184
+ <events>
185
+ <customer_login>
186
+ <observers>
187
+ <increasingly_login>
188
+ <type>singleton</type>
189
+ <class>Increasingly_Analytics_Model_Observer</class>
190
+ <method>customerLogin</method>
191
+ </increasingly_login>
192
+ </observers>
193
+ </customer_login>
194
+ </events>
195
+ </frontend>
196
+ <admin>
197
+ <routers>
198
+ <adminhtml>
199
+ <args>
200
+ <modules>
201
+ <Increasingly_Analytics before="Mage_adminhtml">Increasingly_Analytics_Adminhtml</Increasingly_Analytics>
202
+ </modules>
203
+ </args>
204
+ </adminhtml>
205
+ </routers>
206
+ </admin>
207
+ <adminhtml>
208
+ <acl>
209
+ <resources>
210
+ <admin>
211
+ <children>
212
+ <system>
213
+ <children>
214
+ <config>
215
+ <children>
216
+ <increasingly_analytics>
217
+ <title>Increasingly Configuration</title>
218
+ </increasingly_analytics>
219
+ </children>
220
+ </config>
221
+ </children>
222
+ </system>
223
+ </children>
224
+ </admin>
225
+ </resources>
226
+ </acl>
227
+ <layout>
228
+ <updates>
229
+ <increasingly_analytics>
230
+ <file>increasingly_analytics.xml</file>
231
+ </increasingly_analytics>
232
+ </updates>
233
+ </layout>
234
+ <menu>
235
+ <increasingly>
236
+ <title>Increasingly</title>
237
+ <sort_order>70</sort_order>
238
+ <action>adminhtml/DataIntegration/index</action>
239
+ </increasingly>
240
+ </menu>
241
+ </adminhtml>
242
+ <default>
243
+ <increasingly_analytics>
244
+ <settings>
245
+ <enable>0</enable>
246
+ </settings>
247
+ </increasingly_analytics>
248
+ </default>
249
+ </config>
app/code/community/Increasingly/Analytics/sql/setup/mysql-install-1.0.0.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ CREATE TABLE IF NOT EXISTS {$this->getTable('increasingly_analytics_bundle')} (
10
+
11
+ `id` int NOT NULL auto_increment,
12
+
13
+ `bundle_id` int NOT NULL default 0,
14
+
15
+ `product_ids` varchar(100) NOT NULL,
16
+
17
+ `increasingly_visitor_id` varchar(100) NOT NULL,
18
+
19
+ `discount_price` decimal(12,4) NULL,
20
+
21
+ 'total_special_price' decimal(12,4) NOT NULL,
22
+
23
+ PRIMARY KEY (`id`)
24
+
25
+ );
26
+
27
+ ");
28
+
29
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/increasingly_analytics.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout>
3
+ <adminhtml_dataintegration_index>
4
+ <reference name="content">
5
+ <block type="increasingly_analytics/adminhtml_DataIntegration" template="increasingly/dataintegration.phtml" name="increasingly.dataintegration"/>
6
+ </reference>
7
+ </adminhtml_dataintegration_index>
8
+ </layout>
app/design/adminhtml/default/default/template/increasingly/dataintegration.phtml ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $import = $this->getImport(); ?>
2
+ <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
3
+ <script type="text/javascript">
4
+ jQuery.noConflict();
5
+
6
+ function import_increasingly()
7
+ {
8
+ var total_chunks = <?php echo $import->getChunks(); ?>;
9
+ var chunk_percentage = 100;
10
+
11
+ if(total_chunks > 0)
12
+ {
13
+ var chunk_percentage = (100 / total_chunks);
14
+ }
15
+
16
+ // Disable button
17
+ jQuery('#increasingly_button').addClass('disabled').attr('disabled', 'disabled');
18
+
19
+ var sync_chunk = function(chunk_id){
20
+ progress_percentage = Math.round(chunk_id * chunk_percentage);
21
+ update_import_progress_msg('Please wait... '+progress_percentage+'% done', true);
22
+
23
+ // add form_key for magento controller check
24
+ data = {'chunk_id': chunk_id, 'form_key': window.FORM_KEY};
25
+
26
+ jQuery.post('<?php echo $this->getOrderImportUrl(); ?>', data, function(response) {
27
+ new_chunk_id = chunk_id + 1;
28
+ if(new_chunk_id < total_chunks)
29
+ {
30
+ setTimeout(function(){
31
+ sync_chunk(new_chunk_id);
32
+ }, 150)
33
+ }
34
+ else
35
+ {
36
+ update_import_progress_msg("<span style='color: green;'>Data import is completed! Data will appear in Increasingly in few minutes.</span>", false);
37
+ jQuery('#increasingly_button').removeClass('disabled').addClass('success');
38
+ }
39
+
40
+ });
41
+
42
+ }
43
+
44
+ var update_import_progress_msg = function(message, show_loader_img){
45
+ if (show_loader_img)
46
+ message = '<img src="<?php echo $this->getSkinUrl("increasingly/loader.gif"); ?>" />' + message;
47
+ jQuery('#increasingly_import_status').html(message);
48
+ }
49
+ sync_chunk(0);
50
+ }
51
+
52
+ function loadHtmlFields(selected)
53
+ {
54
+ if(selected == 1)
55
+ {
56
+ $('row_increasingly_analytics_settings_api_key').show();
57
+ $('row_increasingly_analytics_settings_api_secret').show();
58
+ $('row_increasingly_analytics_settings_import').show();
59
+ }
60
+ else
61
+ {
62
+ $('row_increasingly_analytics_settings_api_key').hide();
63
+ $('row_increasingly_analytics_settings_api_secret').hide();
64
+ $('row_increasingly_analytics_settings_import').hide();
65
+ }
66
+
67
+ }
68
+ </script>
69
+
70
+ <div class="content-header">
71
+ <table cellspacing="0">
72
+ <tr>
73
+ <td>
74
+ <h3 class="increasingly-header">Increasingly Settings</h3>
75
+ </td>
76
+ <td class="form-buttons">
77
+ <button id="btnSaveConfigDetails" title="Save Config" type="button" class="scalable save"
78
+ onclick="data_integration_form.submit()" style=""><span><span><span>Save Config</span></span></span></button>
79
+ </td>
80
+ </tr>
81
+ </table>
82
+ </div>
83
+
84
+ <?php
85
+ $adminobj= new Mage_Adminhtml_Block_Template();
86
+ $formkey=$adminobj->getFormKey();
87
+ ?>
88
+
89
+ <form id="data_integration_form" name="data_integration_form" method="post" action="<?php echo $this->getUrl('*/*/saveConfigDetails')?>" enctype="multipart/form-data">
90
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
91
+
92
+ <table cellspacing="0" class="form-list">
93
+ <tbody>
94
+
95
+ <tr id="row_increasingly_analytics_settings_enable">
96
+ <td class="label"><label for="increasingly_analytics_settings_enable">Enabled</label></td>
97
+ <td class="value"><?php echo $this->renderIncreasinglyEnableStatus(Mage::getStoreConfig('increasingly_analytics/settings/enable'))?></td>
98
+ </tr>
99
+
100
+ <?php echo $this->getHtmlFields(Mage::getStoreConfig('increasingly_analytics/settings/enable')) ?>
101
+
102
+ </tbody>
103
+ </table>
104
+ </form>
app/design/frontend/base/default/layout/increasingly_analytics.xml ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout version="1.0.0">
3
+ <default>
4
+ <reference name="head">
5
+ <block type="increasingly_analytics/track" name="increasingly.analytics" template="increasingly/track.phtml" after="-" />
6
+ </reference>
7
+ <!-- Adds Increasingly page type tags to head -->
8
+ <reference name="head">
9
+ <block type="increasingly_analytics/pagetype" name="increasingly.pagetype" template="increasingly/pagetype.phtml"/>
10
+ </reference>
11
+ <!-- Adds Increasingly embed script to head -->
12
+ <reference name="head">
13
+ <block type="increasingly_analytics/embed" name="increasingly.embed" template="increasingly/embed.phtml"/>
14
+ </reference>
15
+
16
+ <!-- Adds Increasingly `add-to-cart` script to head -->
17
+ <reference name="head">
18
+ <block type="increasingly_analytics/addtocart" name="increasingly.addtocart" template="increasingly/addtocart.phtml"/>
19
+ </reference>
20
+
21
+ <!--Tag Increasingly shopping cart -->
22
+ <reference name="after_body_start">
23
+ <block type="increasingly_analytics/cart" name="increasingly.cart" template="increasingly/cart.phtml"/>
24
+ </reference>
25
+ </default>
26
+ <!-- Tag category -->
27
+ <catalog_category_default>
28
+ <update handle="increasingly_analytics_category" />
29
+ </catalog_category_default>
30
+ <catalog_category_layered>
31
+ <update handle="increasingly_analytics_category" />
32
+ </catalog_category_layered>
33
+ <increasingly_analytics_category>
34
+ <reference name="after_body_start">
35
+ <block type="increasingly_analytics/category" name="increasingly.category" template="increasingly/category.phtml"/>
36
+ </reference>
37
+ </increasingly_analytics_category>
38
+
39
+ <!-- Tag product -->
40
+ <catalog_product_view>
41
+ <reference name="after_body_start">
42
+ <block type="increasingly_analytics/product" name="increasingly.product" template="increasingly/product.phtml"/>
43
+ </reference>
44
+ </catalog_product_view>
45
+
46
+ <!-- Tag checkout -->
47
+ <!-- <checkout_onepage_success>
48
+ <reference name="after_body_start">
49
+ <block type="increasingly_analytics/order" name="increasingly.order" template="increasingly/order.phtml"/>
50
+ </reference>
51
+ </checkout_onepage_success> -->
52
+
53
+ <!-- All pages -->
54
+ <default>
55
+ <!-- Adds 1 content placeholder first in page content section -->
56
+ <reference name="content">
57
+ <block type="increasingly_analytics/element" name="increasingly.page.top" before="-"
58
+ template="increasingly/element.phtml">
59
+ <action method="setData">
60
+ <name>div_id</name>
61
+ <value>increasingly-page-top</value>
62
+ </action>
63
+ </block>
64
+ </reference>
65
+ <!-- Adds 1 content placeholder to left sidebar -->
66
+ <reference name="left">
67
+ <block type="increasingly_analytics/element" name="increasingly.column.left" before="-"
68
+ template="increasingly/element.phtml">
69
+ <action method="setData">
70
+ <name>div_id</name>
71
+ <value>increasingly-column-left</value>
72
+ </action>
73
+ </block>
74
+ </reference>
75
+ <!-- Adds 1 content placeholder to right sidebar -->
76
+ <reference name="right">
77
+ <block type="increasingly_analytics/element" name="increasingly.column.right" after="-"
78
+ template="increasingly/element.phtml">
79
+ <action method="setData">
80
+ <name>div_id</name>
81
+ <value>increasingly-column-right</value>
82
+ </action>
83
+ </block>
84
+ </reference>
85
+ </default>
86
+
87
+
88
+ <!-- Custom handle for displaying 1 content placeholder last in page content section -->
89
+ <increasingly_analytics_page_default_footer>
90
+ <reference name="content">
91
+ <block type="increasingly_analytics/element" name="increasingly.page.footer" after="-"
92
+ template="increasingly/element.phtml">
93
+ <action method="setData">
94
+ <name>div_id</name>
95
+ <value>increasingly-page-footer</value>
96
+ </action>
97
+ </block>
98
+ </reference>
99
+ </increasingly_analytics_page_default_footer>
100
+
101
+ <!-- Home page -->
102
+ <cms_index_index>
103
+ <!-- Add 4 content placeholders after the home page content -->
104
+ <reference name="content">
105
+ <block type="increasingly_analytics/element" name="increasingly.page.home1" after="-"
106
+ template="increasingly/element.phtml">
107
+ <action method="setData">
108
+ <name>div_id</name>
109
+ <value>frontpage-increasingly-1</value>
110
+ </action>
111
+ </block>
112
+ </reference>
113
+ </cms_index_index>
114
+ <!-- Shopping cart checkout page -->
115
+ <checkout_cart_index>
116
+ <!-- Adds 3 content placeholders after the cart content -->
117
+ <reference name="content">
118
+ <block type="increasingly_analytics/element" name="increasingly.page.cart1" after="checkout.cart"
119
+ template="increasingly/element.phtml">
120
+ <action method="setData">
121
+ <name>div_id</name>
122
+ <value>increasingly-page-cart1</value>
123
+ </action>
124
+ </block>
125
+ </reference>
126
+ </checkout_cart_index>
127
+
128
+ <sales_quote_collect_totals_after>
129
+ <observers>
130
+ <class>Custom_Module_Model_Observer</class>
131
+ <method>collectTotals</method>
132
+ </observers>
133
+ </sales_quote_collect_totals_after>
134
+
135
+ <!-- Product page -->
136
+ <catalog_product_view>
137
+ <!-- Adds 3 content placeholders after the product info -->
138
+ <reference name="content">
139
+ <block type="increasingly_analytics/element" name="increasingly.page.product1" after="product.info"
140
+ template="increasingly/element.phtml">
141
+ <action method="setData">
142
+ <name>div_id</name>
143
+ <value>increasingly-page-product1</value>
144
+ </action>
145
+ </block>
146
+ </reference>
147
+ <reference name="product.info.addtocart">
148
+ <block type="increasingly_analytics/element" name="increasingly.catalog.product1" after="product.info.addtocart" template="increasingly/element.phtml">
149
+ <action method="setData">
150
+ <name>div_id</name>
151
+ <value>increasingly-catalog-product1</value>
152
+ </action>
153
+ </block>
154
+ </reference>
155
+ </catalog_product_view>
156
+
157
+ <MY_HANDLE_catalog_product_view>
158
+ <reference name="content">
159
+ <!-- <remove name="product.info.addto"/> -->
160
+ <remove name="product.info.availability"/>
161
+ <remove name="product.info.sharing"/>
162
+ <remove name="product.info.addtocartqty"/>
163
+ <remove name="product.tierprices" />
164
+ <remove name="product.info.upsell" />
165
+ <remove name="product.clone_prices" />
166
+ <remove name="product.tag.list" />
167
+ </reference>
168
+ </MY_HANDLE_catalog_product_view>
169
+ <!-- Category page -->
170
+ <catalog_category_default>
171
+ <update handle="increasingly_analytics_catalog_category" />
172
+ </catalog_category_default>
173
+ <catalog_category_layered>
174
+ <update handle="increasingly_analytics_catalog_category" />
175
+ </catalog_category_layered>
176
+ <increasingly_analytics_catalog_category>
177
+ <!-- Adds 2 content placeholders; 1 before and 1 after the products -->
178
+ <reference name="content">
179
+ <block type="increasingly_analytics/element" name="increasingly.page.category1" after="category.products"
180
+ template="increasingly/element.phtml">
181
+ <action method="setData">
182
+ <name>div_id</name>
183
+ <value>increasingly-page-category1</value>
184
+ </action>
185
+ </block>
186
+ <!-- <block type="increasingly_analytics/element" name="increasingly.page.category2" after="category.products"
187
+ template="increasingly/element.phtml">
188
+ <action method="setData">
189
+ <name>div_id</name>
190
+ <value>increasingly-page-category2</value>
191
+ </action>
192
+ </block> -->
193
+ </reference>
194
+ </increasingly_analytics_catalog_category>
195
+
196
+
197
+ <!-- 404 Not found page -->
198
+ <cms_index_noroute>
199
+ <reference name="content">
200
+ <block type="increasingly_analytics/element" name="increasingly.page.notfound1" after="-"
201
+ template="increasingly/element.phtml">
202
+ <action method="setData">
203
+ <name>div_id</name>
204
+ <value>notfound-increasingly-1</value>
205
+ </action>
206
+ </block>
207
+ </reference>
208
+ </cms_index_noroute>
209
+ <!-- Order confirmation page -->
210
+ <checkout_onepage_success>
211
+ <reference name="content">
212
+ <block type="increasingly_analytics/element" name="increasingly.page.orderconfirmation1" after="-" template="increasingly/element.phtml">
213
+ <action method="setData">
214
+ <name>div_id</name>
215
+ <value>thankyou-increasingly-1</value>
216
+ </action>
217
+ </block>
218
+ <block type="increasingly_analytics/element" name="increasingly.page.orderconfirmation2" after="increasingly.page.orderconfirmation1" template="increasingly/element.phtml">
219
+ <action method="setData">
220
+ <name>div_id</name>
221
+ <value>thankyou-increasingly-2</value>
222
+ </action>
223
+ </block>
224
+ </reference>
225
+ </checkout_onepage_success>
226
+ </layout>
app/design/frontend/base/default/template/increasingly/addtocart.phtml ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ ?>
28
+
29
+ <?php
30
+ $formAction = Mage::getUrl('checkout/cart/add');
31
+ $formKey = Mage::getSingleton('core/session')->getFormKey();
32
+ ?>
33
+
34
+ <!-- Increasingly `add-to-cart` Script -->
35
+ <script type="text/javascript">
36
+ if (typeof Increasingly === "undefined") {
37
+ var Increasingly = {};
38
+ }
39
+ Increasingly.addProductToCart = function (productId) {
40
+ var form = document.createElement("form");
41
+ form.setAttribute("method", "post");
42
+ form.setAttribute("action", "<?php echo $formAction; ?>");
43
+
44
+ var hiddenFields = {
45
+ "product": productId,
46
+ "form_key": "<?php echo $formKey; ?>"
47
+ };
48
+
49
+ for(var key in hiddenFields) {
50
+ if(hiddenFields.hasOwnProperty(key)) {
51
+ var hiddenField = document.createElement("input");
52
+ hiddenField.setAttribute("type", "hidden");
53
+ hiddenField.setAttribute("name", key);
54
+ hiddenField.setAttribute("value", hiddenFields[key]);
55
+ form.appendChild(hiddenField);
56
+ }
57
+ }
58
+
59
+ document.body.appendChild(form);
60
+ form.submit();
61
+ };
62
+ </script>
app/design/frontend/base/default/template/increasingly/cart.phtml ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ ?>
28
+
29
+ <?php
30
+ /**
31
+ * @var $this Increasingly_Analytics_Block_Cart
32
+ * @var $increasinglyHelper Increasingly_Analytics_Helper_Data
33
+ * @var $increasinglyPriceHelper Increasingly_Analytics_Helper_Price
34
+ */
35
+ $items = $this->getItems();
36
+ $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
37
+ $increasinglyHelper = Mage::helper('increasingly_analytics');
38
+ $increasinglyPriceHelper = Mage::helper('increasingly_analytics/priceFormatter');
39
+ $cookieValue = Mage::getModel('core/cookie')->get('ivid');
40
+ if(Mage::getModel('increasingly_analytics/bundle2')){
41
+ $userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
42
+ ->addFieldToFilter('increasingly_visitor_id',$cookieValue);
43
+ $userBundelDetails = [];
44
+
45
+ foreach($userBundleCollection as $bundle){
46
+ $cart_bundle_details["id"] = $bundle->getId();
47
+ $cart_bundle_details["products"] = $bundle->getProductIds();
48
+ array_push($userBundelDetails, $cart_bundle_details);
49
+ }
50
+ }
51
+ ?>
52
+
53
+ <!-- Increasingly Cart Tagging -->
54
+ <div class="increasingly_cart" style="display:none">
55
+ <?php foreach ($items as $item): ?>
56
+ <div class="line_item">
57
+ <span class="product_id"><?php echo (int)$this->getProductId($item); ?></span>
58
+ <span class="quantity"><?php echo (int)$item->getQty(); ?></span>
59
+ <span class="name"><?php echo $increasinglyHelper->escapeHtml($this->getProductName($item)); ?></span>
60
+ <span class="unit_price"><?php echo $increasinglyPriceHelper->getFormattedPrice($item->getPriceInclTax()); ?></span>
61
+ <span class="price_currency_code"><?php echo strtoupper($currency); ?></span>
62
+ </div>
63
+ <?php endforeach; ?>
64
+ <div class="cart_bundle_details"><?php echo json_encode($userBundelDetails)?></div>
65
+ </div>
66
+
67
+
app/design/frontend/base/default/template/increasingly/category.phtml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ ?>
28
+
29
+ <?php
30
+ /**
31
+ * @var $this Increasingly_Analytics_Block_Category
32
+ * @var $increasinglyHelper Increasingly_Analytics_Helper_Data
33
+ */
34
+ $increasinglyHelper = Mage::helper('increasingly_analytics');
35
+ ?>
36
+
37
+ <!-- Increasingly Category Tagging -->
38
+ <div class="increasingly_category" style="display:none"><?php echo $increasinglyHelper->escapeHtml($this->getCategory()); ?></div>
app/design/frontend/base/default/template/increasingly/element.phtml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ ?>
28
+
29
+ <?php
30
+ /**
31
+ * @var $this Increasingly_Analytics_Block_Element
32
+ * @var $increasinglyHelper Increasingly_Analytics_Helper_Data
33
+ */
34
+ $increasinglyHelper = Mage::helper('increasingly_analytics');
35
+ $id = $increasinglyHelper->escapeHtml(($this->getElementId()));
36
+
37
+ ?>
38
+
39
+ <div class="increasingly_element" id="<?php echo $increasinglyHelper->escapeHtml($this->getElementId()); ?>"></div>
40
+
app/design/frontend/base/default/template/increasingly/embed.phtml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package frontend_base_default
23
+ * @author Nosto Solutions Ltd <magento@nosto.com>
24
+ * @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ ?>
28
+ <!-- Increasingly Analytics Tagging Script -->
29
+
30
+ <!--<script type="text/javascript">
31
+ // var b = "increasinglyjs";
32
+ // increasinglyjs.init('<?php echo $this->getAccountName(); ?>', {
33
+ // host: '<?php echo $this->getServerAddress() ?>'
34
+ // });
35
+ </script>-->
app/design/frontend/base/default/template/increasingly/pagetype.phtml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package frontend_base_default
23
+ * @author Increasingly_Analytics Solutions Ltd <magento@nosto.com>
24
+ * @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ ?>
28
+
29
+ <?php
30
+ /**
31
+ * Magento
32
+ *
33
+ * NOTICE OF LICENSE
34
+ *
35
+ * This source file is subject to the Open Software License (OSL 3.0)
36
+ * that is bundled with this package in the file LICENSE.txt.
37
+ * It is also available through the world-wide-web at this URL:
38
+ * http://opensource.org/licenses/osl-3.0.php
39
+ * If you did not receive a copy of the license and are unable to
40
+ * obtain it through the world-wide-web, please send an email
41
+ * to license@magentocommerce.com so we can send you a copy immediately.
42
+ *
43
+ * DISCLAIMER
44
+ *
45
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
46
+ * versions in the future. If you wish to customize Magento for your
47
+ * needs please refer to http://www.magentocommerce.com for more information.
48
+ *
49
+ * @category Increasingly
50
+ * @package Increasingly_Analytics
51
+ * @author Increasingly Pvt Ltd
52
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
53
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
54
+ */
55
+ /**
56
+ * @var $this Increasingly_Analytics_Block_Meta
57
+ * @var $helper Increasingly_Analytics__Helper_Data
58
+ */
59
+ $helper = Mage::helper('increasingly_analytics');
60
+ ?>
61
+
62
+ <!-- Increasingly Page Tags -->
63
+ <div name="increasingly-page-type" content="<?php echo $this->getCurrentPageType(); ?>"></div>
64
+ <div id="increasingly-api-key" content="<?php echo $helper->getApiToken(); ?>"></div>
65
+ <div id="increasingly-form-key" content="<?php echo $this->getFormKey(); ?>"></div>
app/design/frontend/base/default/template/increasingly/product.phtml ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ ?>
28
+
29
+ <?php
30
+
31
+ /**
32
+ * @var $this Increasingly_Analytics_Block_Product
33
+ * @var $helper Increasingly_Analytics_Helper_Data
34
+ * @var $priceHelper Increasingly_Analytics_Helper_Price
35
+ * @var $dateHelper Increasingly_Analytics_Helper_Date
36
+ */
37
+ $product = $this->getMetaProduct();
38
+ $helper = Mage::helper('increasingly_analytics');
39
+ $priceHelper = Mage::helper('increasingly_analytics/priceFormatter');
40
+ $dateHelper = Mage::helper('increasingly_analytics/dateFormatter');
41
+
42
+ ?>
43
+ <!-- Increasingly Product Tagging -->
44
+ <div class="increasingly_product" style="display:none">
45
+
46
+ <!-- <span class="url"><?php echo $product->getUrl(); ?></span> -->
47
+ <span class="product_id"><?php echo $product->getProductId(); ?></span>
48
+ <!-- <span class="name"><?php echo $helper->escapeHtml($product->getName()); ?></span>
49
+ <span class="image_url"><?php echo $product->getImageUrl(); ?></span>
50
+ <span class="price"><?php echo $priceHelper->getFormattedPrice($product->getPrice()); ?></span>
51
+ <span class="price_currency_code"><?php echo $product->getCurrencyCode(); ?></span>
52
+ <span class="availability"><?php echo $product->getAvailability(); ?></span>
53
+ <?php foreach ($product->getCategories() as $category): ?>
54
+ <span class="category"><?php echo $helper->escapeHtml($category); ?></span>
55
+ <?php endforeach; ?>
56
+ <?php if ($product->getFullDescription()): ?>
57
+ <span class="description"><?php echo $helper->escapeHtml($product->getFullDescription()); ?></span>
58
+ <?php endif; ?>
59
+ <?php if ($product->getListPrice()): ?>
60
+ <span class="list_price"><?php echo $priceHelper->getFormattedPrice($product->getListPrice()); ?></span>
61
+ <?php endif; ?>
62
+ <?php if ($product->getBrand()): ?>
63
+ <span class="brand"><?php echo $helper->escapeHtml($product->getBrand()); ?></span>
64
+ <?php endif; ?>
65
+ <?php foreach ($product->getTags() as $type => $tags): ?>
66
+ <?php foreach ($tags as $tag): ?>
67
+ <span class="<?php echo $helper->quoteEscape($type); ?>"><?php echo $helper->escapeHtml($tag); ?></span>
68
+ <?php endforeach; ?>
69
+ <?php endforeach; ?>
70
+ <?php if ($product->getDatePublished()): ?>
71
+ <span class="date_published"><?php echo $dateHelper->getFormattedDate($product->getDatePublished()); ?></span>
72
+ <?php endif; ?> -->
73
+ </div>
74
+ <?php if ($this->getCurrentCategory()): ?>
75
+ <div class="increasingly_category" style="display:none"><?php echo $helper->escapeHtml($this->getCurrentCategory()); ?></div>
76
+ <?php endif; ?>
app/design/frontend/base/default/template/increasingly/track.phtml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Increasingly
22
+ * @package Increasingly_Analytics
23
+ * @author Increasingly Pvt Ltd
24
+ * @copyright Copyright (c) 2015-2016 Increasingly Ltd (http://www.increasingly.co)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ ?>
28
+ <?php $helper = Mage::helper('increasingly_analytics'); ?>
29
+ <?php $events = $this->getTrackingEvents(); ?>
30
+
31
+ <script type="text/javascript">
32
+ $(document).on("click", "#btnaddtobasket", function () {
33
+ var tmpl = mageTemplate('#mage-template');
34
+ var data = {
35
+ data: {
36
+ name: 'John',
37
+ location: 'New York'
38
+ }
39
+ };
40
+ $('#target').after(
41
+ tmpl(data)
42
+ );
43
+ });
44
+ window.increasingly=window.increasingly||[],window.increasingly.queue=[],window.increasingly.methods=["identify","track"],
45
+ window.increasingly.filter=function(e){return function(){a=Array.prototype.slice.call(arguments);a.unshift(e);window.increasingly.queue.push(a);}};
46
+
47
+ for(var i=0;window.increasingly.methods.length>i;i++)
48
+ {
49
+ var mthd=window.increasingly.methods[i];
50
+ window.increasingly[mthd]=window.increasingly.filter(mthd);
51
+ }
52
+
53
+ window.increasingly.load=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
54
+ r.type="text/javascript";r.async=true;r.src="http://www.increasingly.co/js/track.js";n.parentNode.insertBefore(r,n);};
55
+
56
+ window.increasingly.loadJs=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
57
+ r.type="text/javascript";r.async=true;r.src="http://www.increasingly.co/js/increasingly.js";n.parentNode.insertBefore(r,n);};
58
+
59
+
60
+
61
+
62
+ increasingly.load();
63
+ increasingly.loadJs();
64
+ <?php foreach ($events as $trackEvent) : ?>
65
+
66
+ <?php if($trackEvent['method'] == 'track') : ?>
67
+ increasingly.track("<?php echo $trackEvent['event_type']; ?>", "<?php echo base64_encode(json_encode($trackEvent)); ?>");
68
+ <?php endif; ?>
69
+
70
+ <?php endforeach; ?>
71
+ </script>
app/etc/modules/Increasingly_Analytics.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <config>
3
+ <modules>
4
+ <Increasingly_Analytics>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Checkout/>
9
+ </depends>
10
+ </Increasingly_Analytics>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Increasingly_Analytics</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Increase basket size using personalised smart bundling&#xD;
10
+ </summary>
11
+ <description>Increasingly - Smart product bundling for Magento&#xD;
12
+ &#xD;
13
+ Increasingly is a predictive selling technology. We increase your basket size.&#xD;
14
+ &#xD;
15
+ Overview&#xD;
16
+ &#xD;
17
+ Our smart product bundling platform drives up your basket size +12% by using cutting edge machine learning.&#xD;
18
+ &#xD;
19
+ Amazon &amp; several other large online retailers have long used product bundles as a way to drive up Average Order Value. They are able to do this because of their scale &amp; technical resources. Increasingly delivers the power of bundling straight into your store, helping you drive up basket size.&#xD;
20
+ &#xD;
21
+ It&#x2019;s simple &amp; easy to integrate yet delivers powerful results. &#xD;
22
+ &#xD;
23
+ Key Features&#xD;
24
+ &#xD;
25
+ Personalised bundles: Our powerful algorithms drive personalised bundling experiences for your customers based on their behaviour, intent &amp; propensity to purchase.&#xD;
26
+ &#xD;
27
+ Dynamic Discounting: You can set discounts on bundles or allow our system to determine instances for discounting based on the customer's likelihood to buy.&#xD;
28
+ &#xD;
29
+ Products together optimisation: Bundles are constantly tested on page to make sure that only the best performing bundles are shown.&#xD;
30
+ &#xD;
31
+ Stock responsive: As your catalogue changes, so do your bundles. Out-of-stock bundles are automatically &amp; instantly eliminated, giving your customers the best experience possible.&#xD;
32
+ &#xD;
33
+ Mobile ready: Works on any device, any screen size &amp; can also be integrated into a mobile app.&#xD;
34
+ &#xD;
35
+ Brand and Category filtering: Full control within the dashboard. Don&#x2019;t want to run bundles on a category, SKU or a brand? Increasingly has filtering built in to protect any filtering you may require.&#xD;
36
+ &#xD;
37
+ Why Increasingly?&#xD;
38
+ &#xD;
39
+ We are 100% focussed on helping retailers grow basket size using smart product bundling. ALL we do is bundling &amp; so we spend ALL our time working on it &#x2013; that&#x2019;s what makes our results so amazing.&#xD;
40
+ &#xD;
41
+ We only charge you a percentage of the uplift we deliver to you, so the solution pays for itself while delivering you new revenue.&#xD;
42
+ &#xD;
43
+ It's free to try &amp; we have a 14-day trial where you can test it for no-risk to you. It&#x2019;s easy to setup and customise.&#xD;
44
+ &#xD;
45
+ We have a dashboard which provides you with in depth analytics and insights on what's sells together &amp; allows you to administer and manage your bundles.&#xD;
46
+ </description>
47
+ <notes>dddd</notes>
48
+ <authors><author><name>Increasingly</name><user>Increasingly</user><email>renu@increasingly.co</email></author><author><name>Increasingly</name><user>Increasingly</user><email>shree@increasingly.co</email></author></authors>
49
+ <date>2016-06-09</date>
50
+ <time>16:51:30</time>
51
+ <contents><target name="magecommunity"><dir name="Increasingly"><dir name="Analytics"><dir name="Block"><file name="Addtocart.php" hash="3429b60b501c7681a3c79fd46138b787"/><dir name="Adminhtml"><file name="DataIntegration.php" hash="b7c543b33f563ef458d403df94c62a4c"/></dir><file name="Cart.php" hash="56c9f503b7c55d835cbd93c675dcc338"/><file name="Category.php" hash="3b87f305e0957dd1fdace455c1f0fa7c"/><file name="Element.php" hash="8d533705e7a3c1ada7d775a6d9282f43"/><file name="Embed.php" hash="5ba08a6642ed22d8bb1a84ab0501f8dc"/><file name="Pagetype.php" hash="5dc81c7c184031629399c7c5a982036e"/><file name="Product.php" hash="2da759eb9bd2bf13e5a8a92087981206"/><file name="Track.php" hash="aa6a9d870f14c4e3721675658dfb276e"/></dir><dir name="Helper"><file name="Data.php" hash="6d6fe43c72cf7baf91de7145c98df1a3"/><file name="DateFormatter.php" hash="d8f963bd1f9fe390e038a2065fd5c4c4"/><file name="PriceFormatter.php" hash="9bc46d3afb4612131a29b9a1c2b82fad"/><file name="ProductFormatter.php" hash="24324a2207485f281bdeba654c08a34c"/></dir><dir name="Model"><file name="Base.php" hash="957cc5bb083e9b49b5468c986a1e846a"/><file name="Bundle.php" hash="767a26eaefaed893d163737d64930933"/><file name="DataIntegration.php" hash="ff9dc202ea17e49ceaba09c6190492cd"/><dir name="Meta"><file name="Product.php" hash="6a037e5325193fae3147fc1a9891606c"/></dir><dir name="Mysql4"><dir name="Bundle"><file name="Collection.php" hash="021c49a92767b78e238477a3dc8da783"/></dir><file name="Bundle.php" hash="13baace5753c59b86a032f5b5e379830"/></dir><file name="Observer.php" hash="efd64c4e950498032cd7481a5c5d0817"/><file name="Product.php" hash="f473c25a470a2509b00a4a15ed8b857f"/></dir><dir name="controllers"><file name="AddbundletocartController.php" hash="a8d13fcbd249ebb8112f32c6e6edb5ad"/><dir name="Adminhtml"><file name="DataIntegrationController.php" hash="21110e0a5908740f13716967e652908e"/></dir><file name="ProductsApiController.php" hash="58c7e54788361cc25bdc1b49a2d86e09"/></dir><dir name="etc"><file name="config.xml" hash="222b073dbe641b013cd241760a380037"/></dir><dir name="sql"><dir name="setup"><file name="mysql-install-1.0.0.php" hash="130ffdfffab451f5d41fd6eb758841ee"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="increasingly"><file name="dataintegration.phtml" hash="8a730e566c21b2155d6f3e4ca73a1b6d"/></dir></dir><dir name="layout"><file name="increasingly_analytics.xml" hash="d859a26dba5142f02e514f28f507891c"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="increasingly"><file name="addtocart.phtml" hash="e3af2445ac014887b3072cf85dd81d4f"/><file name="cart.phtml" hash="9db284236bf7ffafc1d5aa8d5f46ba8d"/><file name="category.phtml" hash="75e77b9d1cbbd1e0129c0c10737461e6"/><file name="element.phtml" hash="c5f1cbbc02801009247409890172ca4e"/><file name="embed.phtml" hash="52cde76a239e3084ce3a1254b004a742"/><file name="pagetype.phtml" hash="9cbb3b6bd97f865da70c5ca860121a31"/><file name="product.phtml" hash="14d24b0ced5abc85619aa3538b21f2f7"/><file name="track.phtml" hash="b878cc208fe87e800d52bb6a97355d60"/></dir></dir><dir name="layout"><file name="increasingly_analytics.xml" hash="78766218deed3d60d4ab0fdee7729b91"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Increasingly_Analytics.xml" hash="d285a9ae62b5b0624b727e341fe8e005"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="increasingly"><file name="loader.gif" hash="a51c5608d01acf32df728f299767f82b"/></dir></dir></dir></dir></target></contents>
52
+ <compatible/>
53
+ <dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php></required></dependencies>
54
+ </package>
skin/adminhtml/default/default/increasingly/loader.gif ADDED
Binary file