Version Notes
Added bundle cart tracking feature
Fixed the issue of deleting bundles on orders from the user cart.
Download this release
Release Info
Developer | Increasingly |
Extension | increasingly_key |
Version | 1.0.15 |
Comparing to | |
See all releases |
Code changes from version 1.0.14 to 1.0.15
- app/code/community/Increasingly/Analytics/Helper/Data.php +56 -9
- app/code/community/Increasingly/Analytics/Helper/Data.php~ +398 -0
- app/code/community/Increasingly/Analytics/Model/Observer.php +31 -17
- app/code/community/Increasingly/Analytics/Model/Observer.php~ +535 -0
- app/code/community/Increasingly/Analytics/controllers/AddbundletocartController.php +26 -8
- app/code/community/Increasingly/Analytics/controllers/ProductsImportApiController.php +11 -1
- app/code/community/Increasingly/Analytics/etc/config.xml +1 -1
- app/code/community/Increasingly/Analytics/sql/increasingly_analytics_setup/mysql4-install-1.0.15.php +29 -0
- app/design/frontend/base/default/template/increasingly/track.phtml +2 -2
- app/design/frontend/base/default/template/increasingly/track.phtml~ +59 -0
- package.xml +6 -5
app/code/community/Increasingly/Analytics/Helper/Data.php
CHANGED
@@ -183,15 +183,15 @@ class Increasingly_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
|
|
183 |
**
|
184 |
*/
|
185 |
public function formBundleJson(){
|
|
|
|
|
186 |
try {
|
187 |
-
|
188 |
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
189 |
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
|
190 |
->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
191 |
-
|
192 |
-
|
193 |
-
$userBundle->getDiscountPrice();
|
194 |
-
$userBundle->getTotalPrice();
|
195 |
array_push($bundleData,
|
196 |
array('id' => $userBundle->getBundleId(),
|
197 |
'discountPrice' => $userBundle->getDiscountPrice(),
|
@@ -200,8 +200,14 @@ class Increasingly_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
|
|
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 |
}
|
@@ -224,7 +230,12 @@ class Increasingly_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
|
|
224 |
if(!is_null($isProductInBundle) && !empty($isProductInBundle) && $isProductInBundle == true)
|
225 |
{
|
226 |
$userBundle = Mage::getModel('increasingly_analytics/bundle');
|
227 |
-
|
|
|
|
|
|
|
|
|
|
|
228 |
}
|
229 |
|
230 |
}
|
@@ -247,7 +258,12 @@ class Increasingly_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
|
|
247 |
//$productIds = explode(',', $userBundle->getProductIds);
|
248 |
if($quote->getItemsCount() == 0 && count($userBundleCollection) >= 0) {
|
249 |
foreach ($userBundleCollection as $userBundle) {
|
|
|
|
|
|
|
|
|
250 |
$userBundle->delete();
|
|
|
251 |
|
252 |
}
|
253 |
}
|
@@ -259,6 +275,31 @@ class Increasingly_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
|
|
259 |
|
260 |
}
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
/**
|
263 |
* Sends event data to increasingly through API
|
264 |
*/
|
@@ -279,7 +320,7 @@ class Increasingly_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
|
|
279 |
ksort($data);
|
280 |
$encodedData = base64_encode(Mage::helper('core')->jsonEncode($data));
|
281 |
$signature = md5($encodedData.$api_secret);
|
282 |
-
$url = 'https://optimizedby.increasingly.co/ImportData';
|
283 |
$client = new Varien_Http_Client($url);
|
284 |
|
285 |
$postData = array(
|
@@ -297,8 +338,14 @@ class Increasingly_Analytics_Helper_Data extends Mage_Core_Helper_Abstract
|
|
297 |
|
298 |
}
|
299 |
catch (Exception $e)
|
300 |
-
{
|
301 |
Mage::log("Increasingly api call- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
}
|
303 |
return $result;
|
304 |
}
|
183 |
**
|
184 |
*/
|
185 |
public function formBundleJson(){
|
186 |
+
|
187 |
+
$bundleData = [];
|
188 |
try {
|
189 |
+
|
190 |
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
191 |
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
|
192 |
->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
193 |
+
|
194 |
+
foreach($userBundleCollection as $userBundle){
|
|
|
|
|
195 |
array_push($bundleData,
|
196 |
array('id' => $userBundle->getBundleId(),
|
197 |
'discountPrice' => $userBundle->getDiscountPrice(),
|
200 |
}
|
201 |
}
|
202 |
catch (Exception $e)
|
203 |
+
{
|
204 |
Mage::log("Increasingly form bundle json- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
205 |
+
$error_info = array(
|
206 |
+
'method' => 'OrderTrackingformBundleJson',
|
207 |
+
'error_message' => $e->getMessage()
|
208 |
+
);
|
209 |
+
|
210 |
+
$this->addEvent('track', 'track_error', $error_info);
|
211 |
}
|
212 |
return $bundleData;
|
213 |
}
|
230 |
if(!is_null($isProductInBundle) && !empty($isProductInBundle) && $isProductInBundle == true)
|
231 |
{
|
232 |
$userBundle = Mage::getModel('increasingly_analytics/bundle');
|
233 |
+
$cart_bundle_data = array(
|
234 |
+
'bundle_id' => $bundle->getBundleId()
|
235 |
+
);
|
236 |
+
$userBundle->setId($bundle->getId())->delete();
|
237 |
+
|
238 |
+
$this->addEvent('track', 'bundle_delete_from_cart', $cart_bundle_data);
|
239 |
}
|
240 |
|
241 |
}
|
258 |
//$productIds = explode(',', $userBundle->getProductIds);
|
259 |
if($quote->getItemsCount() == 0 && count($userBundleCollection) >= 0) {
|
260 |
foreach ($userBundleCollection as $userBundle) {
|
261 |
+
|
262 |
+
$cart_bundle_data = array(
|
263 |
+
'bundle_id' => $userBundle->getBundleId()
|
264 |
+
);
|
265 |
$userBundle->delete();
|
266 |
+
$this->addEvent('track', 'bundle_delete_from_cart', $cart_bundle_data);
|
267 |
|
268 |
}
|
269 |
}
|
275 |
|
276 |
}
|
277 |
|
278 |
+
/**Delete bundle when the items in the cart are purchased
|
279 |
+
**
|
280 |
+
*/
|
281 |
+
public function deleteBundleOnPurchase()
|
282 |
+
{
|
283 |
+
try
|
284 |
+
{
|
285 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
286 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
287 |
+
|
288 |
+
if(count($userBundleCollection) >= 0)
|
289 |
+
{
|
290 |
+
foreach ($userBundleCollection as $userBundle)
|
291 |
+
{
|
292 |
+
$userBundle->delete();
|
293 |
+
}
|
294 |
+
}
|
295 |
+
}
|
296 |
+
catch (Exception $e)
|
297 |
+
{
|
298 |
+
Mage::log("Increasingly delete bundle on purchase - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
299 |
+
}
|
300 |
+
|
301 |
+
}
|
302 |
+
|
303 |
/**
|
304 |
* Sends event data to increasingly through API
|
305 |
*/
|
320 |
ksort($data);
|
321 |
$encodedData = base64_encode(Mage::helper('core')->jsonEncode($data));
|
322 |
$signature = md5($encodedData.$api_secret);
|
323 |
+
$url = 'https://optimizedby.increasingly.co/ImportData';
|
324 |
$client = new Varien_Http_Client($url);
|
325 |
|
326 |
$postData = array(
|
338 |
|
339 |
}
|
340 |
catch (Exception $e)
|
341 |
+
{
|
342 |
Mage::log("Increasingly api call- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
343 |
+
$error_info = array(
|
344 |
+
'method' => 'increasinglyapimethod',
|
345 |
+
'error_message' => $e->getMessage()
|
346 |
+
);
|
347 |
+
|
348 |
+
$this->addEvent('track', 'track_error', $error_info);
|
349 |
}
|
350 |
return $result;
|
351 |
}
|
app/code/community/Increasingly/Analytics/Helper/Data.php~
ADDED
@@ -0,0 +1,398 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
187 |
+
$bundleData = [];
|
188 |
+
try {
|
189 |
+
|
190 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
191 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
|
192 |
+
->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
193 |
+
|
194 |
+
foreach($userBundleCollection as $userBundle){
|
195 |
+
array_push($bundleData,
|
196 |
+
array('id' => $userBundle->getBundleId(),
|
197 |
+
'discountPrice' => $userBundle->getDiscountPrice(),
|
198 |
+
'totalPrice' => $userBundle->getTotalPrice()
|
199 |
+
));
|
200 |
+
}
|
201 |
+
}
|
202 |
+
catch (Exception $e)
|
203 |
+
{
|
204 |
+
Mage::log("Increasingly form bundle json- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
205 |
+
$error_info = array(
|
206 |
+
'method' => 'OrderTrackingformBundleJson',
|
207 |
+
'error_message' => $e->getMessage()
|
208 |
+
);
|
209 |
+
|
210 |
+
$this->addEvent('track', 'track_error', $error_info);
|
211 |
+
}
|
212 |
+
return $bundleData;
|
213 |
+
}
|
214 |
+
|
215 |
+
/**Delete bundle when the products in the cart are deleted
|
216 |
+
**
|
217 |
+
*/
|
218 |
+
public function deleteBundleOnProductDeleteFromCart($product_id){
|
219 |
+
try {
|
220 |
+
|
221 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
222 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
223 |
+
|
224 |
+
if(count($userBundleCollection) >= 1){
|
225 |
+
|
226 |
+
foreach($userBundleCollection as $bundle){
|
227 |
+
|
228 |
+
$isProductInBundle = in_array($product_id, explode(',',$bundle->getProductIds()));
|
229 |
+
|
230 |
+
if(!is_null($isProductInBundle) && !empty($isProductInBundle) && $isProductInBundle == true)
|
231 |
+
{
|
232 |
+
$userBundle = Mage::getModel('increasingly_analytics/bundle');
|
233 |
+
$cart_bundle_data = array(
|
234 |
+
'bundle_id' => $bundle->getBundleId()
|
235 |
+
);
|
236 |
+
$userBundle->setId($bundle->getId())->delete();
|
237 |
+
|
238 |
+
$this->addEvent('track', 'bundle_delete_from_cart', $cart_bundle_data);
|
239 |
+
}
|
240 |
+
|
241 |
+
}
|
242 |
+
}
|
243 |
+
}
|
244 |
+
catch (Exception $e)
|
245 |
+
{
|
246 |
+
Mage::log("Increasingly delete bundle on delete from cart- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
247 |
+
}
|
248 |
+
|
249 |
+
}
|
250 |
+
|
251 |
+
/**Delete bundle when all the items in the cart are deleted
|
252 |
+
**
|
253 |
+
*/
|
254 |
+
public function deleteBundleOnEmptyCart($quote){
|
255 |
+
try {
|
256 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
257 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
258 |
+
//$productIds = explode(',', $userBundle->getProductIds);
|
259 |
+
if($quote->getItemsCount() == 0 && count($userBundleCollection) >= 0) {
|
260 |
+
foreach ($userBundleCollection as $userBundle) {
|
261 |
+
|
262 |
+
$cart_bundle_data = array(
|
263 |
+
'bundle_id' => $userBundle->getBundleId()
|
264 |
+
);
|
265 |
+
$userBundle->delete();
|
266 |
+
$this->addEvent('track', 'bundle_delete_from_cart', $cart_bundle_data);
|
267 |
+
|
268 |
+
}
|
269 |
+
}
|
270 |
+
}
|
271 |
+
catch (Exception $e)
|
272 |
+
{
|
273 |
+
Mage::log("Increasingly delete bundle on emptyCart- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
274 |
+
}
|
275 |
+
|
276 |
+
}
|
277 |
+
|
278 |
+
/**Delete bundle when the items in the cart are purchased
|
279 |
+
**
|
280 |
+
*/
|
281 |
+
public function deleteBundleOnPurchase()
|
282 |
+
{
|
283 |
+
try
|
284 |
+
{
|
285 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
286 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
287 |
+
|
288 |
+
if(count($userBundleCollection) >= 0)
|
289 |
+
{
|
290 |
+
foreach ($userBundleCollection as $userBundle)
|
291 |
+
{
|
292 |
+
$userBundle->delete();
|
293 |
+
}
|
294 |
+
}
|
295 |
+
}
|
296 |
+
catch (Exception $e)
|
297 |
+
{
|
298 |
+
Mage::log("Increasingly delete bundle on purchase - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
299 |
+
}
|
300 |
+
|
301 |
+
}
|
302 |
+
|
303 |
+
/**
|
304 |
+
* Sends event data to increasingly through API
|
305 |
+
*/
|
306 |
+
public function increasinglyApi($importData,$event_type,$method,$api_token,$api_secret)
|
307 |
+
{
|
308 |
+
$result = '';
|
309 |
+
try {
|
310 |
+
$version = (string)Mage::getConfig()->getModuleConfig("Increasingly_Analytics")->version;
|
311 |
+
$data = array(
|
312 |
+
'event_data' => $importData,
|
313 |
+
'event_type'=> $event_type,
|
314 |
+
'method' => $method,
|
315 |
+
'platform' => 'Magento ' . Mage::getEdition() . ' ' . Mage::getVersion(),
|
316 |
+
'token' => $api_token,
|
317 |
+
'version' => $version
|
318 |
+
);
|
319 |
+
// sort data
|
320 |
+
ksort($data);
|
321 |
+
$encodedData = base64_encode(Mage::helper('core')->jsonEncode($data));
|
322 |
+
$signature = md5($encodedData.$api_secret);
|
323 |
+
$url = 'https://optimizedby.increasingly.co/ImportData';
|
324 |
+
$client = new Varien_Http_Client($url);
|
325 |
+
|
326 |
+
$postData = array(
|
327 |
+
'signature' => $signature,
|
328 |
+
'eventData' => $encodedData
|
329 |
+
);
|
330 |
+
$jsonData = json_encode($postData);
|
331 |
+
$client->setRawData($jsonData, 'application/json');
|
332 |
+
$response = $client->request('POST');
|
333 |
+
$result = json_decode($response->getBody());
|
334 |
+
|
335 |
+
if ($response->isError()) {
|
336 |
+
Mage::log($response->getBody(), null, 'Increasingly_Analytics.log');
|
337 |
+
}
|
338 |
+
|
339 |
+
}
|
340 |
+
catch (Exception $e)
|
341 |
+
{
|
342 |
+
Mage::log("Increasingly api call- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
343 |
+
$error_info = array(
|
344 |
+
'method' => 'increasinglyapimethod',
|
345 |
+
'error_message' => $e->getMessage()
|
346 |
+
);
|
347 |
+
|
348 |
+
$this->addEvent('track', 'track_error', $error_info);
|
349 |
+
}
|
350 |
+
return $result;
|
351 |
+
}
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Builds a tagging string of the given category including all its parent
|
355 |
+
* categories.
|
356 |
+
* The categories are sorted by their position in the category tree path.
|
357 |
+
*
|
358 |
+
* @param Mage_Catalog_Model_Category $category the category model.
|
359 |
+
*
|
360 |
+
* @return string
|
361 |
+
*/
|
362 |
+
public function buildCategoryString($category)
|
363 |
+
{
|
364 |
+
$data = array();
|
365 |
+
if ($category instanceof Mage_Catalog_Model_Category) {
|
366 |
+
/** @var $categories Mage_Catalog_Model_Category[] */
|
367 |
+
$categories = $category->getParentCategories();
|
368 |
+
$path = $category->getPathInStore();
|
369 |
+
$ids = array_reverse(explode(',', $path));
|
370 |
+
foreach ($ids as $id) {
|
371 |
+
if (isset($categories[$id]) && $categories[$id]->getName()) {
|
372 |
+
$data[] = $categories[$id]->getId();
|
373 |
+
}
|
374 |
+
}
|
375 |
+
}
|
376 |
+
if (!empty($data)) {
|
377 |
+
return DS . implode(DS, $data);
|
378 |
+
} else {
|
379 |
+
return '';
|
380 |
+
}
|
381 |
+
}
|
382 |
+
|
383 |
+
/**
|
384 |
+
* Return the product image version to include in product tagging.
|
385 |
+
*
|
386 |
+
* @param Mage_Core_Model_Store|null $store the store model or null.
|
387 |
+
*
|
388 |
+
* @return string
|
389 |
+
*/
|
390 |
+
public function getProductImageVersion($store = null)
|
391 |
+
{
|
392 |
+
return Mage::getStoreConfig(self::XML_PATH_IMAGE_VERSION, $store);
|
393 |
+
}
|
394 |
+
|
395 |
+
|
396 |
+
|
397 |
+
|
398 |
+
}
|
app/code/community/Increasingly/Analytics/Model/Observer.php
CHANGED
@@ -82,7 +82,7 @@ class Increasingly_Analytics_Model_Observer
|
|
82 |
// homepage page
|
83 |
if ($action == 'cms_index_index' || $action == 'cms_page_view') {
|
84 |
$title = Mage::getSingleton('cms/page')->getTitle();
|
85 |
-
|
86 |
$helper->addEvent('track', 'home_page_visit', $data);
|
87 |
return;
|
88 |
}
|
@@ -207,7 +207,7 @@ class Increasingly_Analytics_Model_Observer
|
|
207 |
'product_id' => $cartProduct->getId(),
|
208 |
'product_name' => $cartProduct->getName(),
|
209 |
'product_url' => $cartProduct->getProductUrl(),
|
210 |
-
|
211 |
'product_type' => $cartProduct->getTypeId(),
|
212 |
'qty' => $qty,
|
213 |
'product_price' => $priceFormatter->format($cartProduct->getFinalPrice())
|
@@ -290,7 +290,7 @@ class Increasingly_Analytics_Model_Observer
|
|
290 |
* @return void
|
291 |
*/
|
292 |
public function applyCartDiscount(Varien_Event_Observer $observer)
|
293 |
-
{
|
294 |
try
|
295 |
{
|
296 |
$bundle_product_ids = [];
|
@@ -381,7 +381,7 @@ class Increasingly_Analytics_Model_Observer
|
|
381 |
} //end: foreach
|
382 |
//echo $quote->getGrandTotal();
|
383 |
|
384 |
-
foreach($quote->getAllItems() as $item){
|
385 |
//We apply discount amount based on the ratio between the GrandTotal and the RowTotal
|
386 |
$rat=$item->getPriceInclTax()/$total;
|
387 |
$ratdisc=$discountAmount*$rat;
|
@@ -393,8 +393,15 @@ class Increasingly_Analytics_Model_Observer
|
|
393 |
}
|
394 |
}
|
395 |
catch(Exception $e)
|
396 |
-
{
|
397 |
-
Mage::log("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
}
|
399 |
|
400 |
}
|
@@ -406,26 +413,33 @@ class Increasingly_Analytics_Model_Observer
|
|
406 |
*/
|
407 |
public function trackNewOrder(Varien_Event_Observer $observer)
|
408 |
{
|
|
|
409 |
try
|
410 |
{
|
411 |
|
412 |
-
|
413 |
|
414 |
if ($helper->isEnabled())
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
|
|
424 |
}
|
425 |
-
|
426 |
catch(Exception $e)
|
427 |
-
{
|
428 |
Mage::log("New order tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
|
|
|
|
|
|
|
|
|
|
429 |
}
|
430 |
}
|
431 |
|
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 |
}
|
207 |
'product_id' => $cartProduct->getId(),
|
208 |
'product_name' => $cartProduct->getName(),
|
209 |
'product_url' => $cartProduct->getProductUrl(),
|
210 |
+
'product_sku' => $cartProduct->getSku(),
|
211 |
'product_type' => $cartProduct->getTypeId(),
|
212 |
'qty' => $qty,
|
213 |
'product_price' => $priceFormatter->format($cartProduct->getFinalPrice())
|
290 |
* @return void
|
291 |
*/
|
292 |
public function applyCartDiscount(Varien_Event_Observer $observer)
|
293 |
+
{
|
294 |
try
|
295 |
{
|
296 |
$bundle_product_ids = [];
|
381 |
} //end: foreach
|
382 |
//echo $quote->getGrandTotal();
|
383 |
|
384 |
+
foreach($quote->getAllItems() as $item){
|
385 |
//We apply discount amount based on the ratio between the GrandTotal and the RowTotal
|
386 |
$rat=$item->getPriceInclTax()/$total;
|
387 |
$ratdisc=$discountAmount*$rat;
|
393 |
}
|
394 |
}
|
395 |
catch(Exception $e)
|
396 |
+
{
|
397 |
+
Mage::log("Apply discount method - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
398 |
+
$error_info = array(
|
399 |
+
'method' => 'ApplyDiscountMethod',
|
400 |
+
'error_message' => $e->getMessage()
|
401 |
+
);
|
402 |
+
|
403 |
+
$helper = Mage::helper('increasingly_analytics');
|
404 |
+
$helper->addEvent('track', 'track_error', $error_info);
|
405 |
}
|
406 |
|
407 |
}
|
413 |
*/
|
414 |
public function trackNewOrder(Varien_Event_Observer $observer)
|
415 |
{
|
416 |
+
$helper = Mage::helper('increasingly_analytics');
|
417 |
try
|
418 |
{
|
419 |
|
420 |
+
|
421 |
|
422 |
if ($helper->isEnabled())
|
423 |
+
{
|
424 |
+
$data = array();
|
425 |
+
$order = $observer->getOrder();
|
426 |
|
427 |
+
if ($order->getId())
|
428 |
+
{
|
429 |
+
$data = $helper->buildOrderDetailsData($order);
|
430 |
+
$helper->addEvent('track', 'order', $data);
|
431 |
+
$helper->deleteBundleOnPurchase();
|
432 |
+
}
|
433 |
}
|
434 |
+
}
|
435 |
catch(Exception $e)
|
436 |
+
{
|
437 |
Mage::log("New order tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
438 |
+
$error_info = array(
|
439 |
+
'method' => 'trackNewOrderMethod',
|
440 |
+
'error_message' => $e->getMessage()
|
441 |
+
);
|
442 |
+
$helper->addEvent('track', 'track_error', $error_info);
|
443 |
}
|
444 |
}
|
445 |
|
app/code/community/Increasingly/Analytics/Model/Observer.php~
ADDED
@@ -0,0 +1,535 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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->getPrice()),
|
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 |
+
if ($helper->isEnabled()){
|
206 |
+
$data = array(
|
207 |
+
'product_id' => $cartProduct->getId(),
|
208 |
+
'product_name' => $cartProduct->getName(),
|
209 |
+
'product_url' => $cartProduct->getProductUrl(),
|
210 |
+
'product_sku' => $cartProduct->getSku(),
|
211 |
+
'product_type' => $cartProduct->getTypeId(),
|
212 |
+
'qty' => $qty,
|
213 |
+
'product_price' => $priceFormatter->format($cartProduct->getFinalPrice())
|
214 |
+
);
|
215 |
+
|
216 |
+
if ($cartProduct->isGrouped() || $cartProduct->isConfigurable()) {
|
217 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
218 |
+
|
219 |
+
$data['product_price'] = $priceFormatter->format($product->getPrice());
|
220 |
+
$data['option_product_id'] = $product->getId();
|
221 |
+
$data['option_product_sku'] = $product->getSku();
|
222 |
+
$data['option_product_name'] = $product->getName();
|
223 |
+
$data['option_product_price'] = $priceFormatter->format($product->getPrice());
|
224 |
+
}
|
225 |
+
|
226 |
+
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
|
227 |
+
$data['is_logged_in'] = true;
|
228 |
+
}
|
229 |
+
else {
|
230 |
+
$data['is_logged_in'] = false;
|
231 |
+
}
|
232 |
+
$helper->addEvent('track', 'add_to_cart', $data);
|
233 |
+
}
|
234 |
+
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Removing item from shopping cart
|
239 |
+
*
|
240 |
+
* @param Varien_Event_Observer $observer
|
241 |
+
* @return void
|
242 |
+
*/
|
243 |
+
public function removeFromCart(Varien_Event_Observer $observer)
|
244 |
+
{
|
245 |
+
try
|
246 |
+
{
|
247 |
+
$helper = Mage::helper('increasingly_analytics');
|
248 |
+
|
249 |
+
if ($helper->isEnabled())
|
250 |
+
{
|
251 |
+
$item = $observer->getQuoteItem();
|
252 |
+
$product = $item->getProduct();
|
253 |
+
|
254 |
+
$data = array(
|
255 |
+
'product_id' => $product->getId()
|
256 |
+
);
|
257 |
+
|
258 |
+
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
|
259 |
+
$data['is_logged_in'] = true;
|
260 |
+
}
|
261 |
+
else {
|
262 |
+
$data['is_logged_in'] = false;
|
263 |
+
}
|
264 |
+
$helper->deleteBundleOnProductDeleteFromCart($product->getId());
|
265 |
+
$helper->addEvent('track', 'remove_from_cart', $data);
|
266 |
+
}
|
267 |
+
|
268 |
+
}
|
269 |
+
catch(Exception $e)
|
270 |
+
{
|
271 |
+
Mage::log("Remove from cart tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
272 |
+
}
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Empty cart handler to delete all products from bundle
|
277 |
+
*/
|
278 |
+
public function empty_cart(Varien_Event_Observer $observer){
|
279 |
+
$helper = Mage::helper('increasingly_analytics');
|
280 |
+
|
281 |
+
$quote = $observer->getEvent()->getQuote();
|
282 |
+
if($quote->getItemsCount() == 0) {
|
283 |
+
$helper->deleteBundleOnEmptyCart($quote);
|
284 |
+
}
|
285 |
+
}
|
286 |
+
/**
|
287 |
+
* applyCartDiscount to shopping cart
|
288 |
+
*
|
289 |
+
* @param Varien_Event_Observer $observer
|
290 |
+
* @return void
|
291 |
+
*/
|
292 |
+
public function applyCartDiscount(Varien_Event_Observer $observer)
|
293 |
+
{
|
294 |
+
try
|
295 |
+
{
|
296 |
+
$bundle_product_ids = [];
|
297 |
+
$quote_product_ids = [];
|
298 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
299 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
300 |
+
$items = $observer->getEvent()->getQuote()->getAllItems();
|
301 |
+
$eligibleProducts = [];
|
302 |
+
$discount = 0;
|
303 |
+
foreach ($items as $item) {
|
304 |
+
array_push($quote_product_ids, $item->getProductId());
|
305 |
+
}
|
306 |
+
foreach ($userBundleCollection as $bundle) {
|
307 |
+
//First Bundle products
|
308 |
+
$bundle_product_ids = explode(',', $bundle->getProductIds());
|
309 |
+
$productsIds = array_intersect($quote_product_ids, $bundle_product_ids);
|
310 |
+
if(count($productsIds) == count($bundle_product_ids) )
|
311 |
+
$discount += $bundle->getDiscountPrice();
|
312 |
+
}
|
313 |
+
|
314 |
+
if($discount > 0){
|
315 |
+
$quote=$observer->getEvent()->getQuote();
|
316 |
+
$quoteid=$quote->getId();
|
317 |
+
$discountAmount=$discount;
|
318 |
+
if($quoteid) {
|
319 |
+
if($discountAmount>0) {
|
320 |
+
$total=$quote->getBaseSubtotal();
|
321 |
+
$quote->setSubtotal(0);
|
322 |
+
$quote->setBaseSubtotal(0);
|
323 |
+
|
324 |
+
$quote->setSubtotalWithDiscount(0);
|
325 |
+
$quote->setBaseSubtotalWithDiscount(0);
|
326 |
+
|
327 |
+
$quote->setGrandTotal(0);
|
328 |
+
$quote->setBaseGrandTotal(0);
|
329 |
+
|
330 |
+
|
331 |
+
$canAddItems = $quote->isVirtual()? ('billing') : ('shipping');
|
332 |
+
foreach ($quote->getAllAddresses() as $address) {
|
333 |
+
|
334 |
+
$address->setSubtotal(0);
|
335 |
+
$address->setBaseSubtotal(0);
|
336 |
+
|
337 |
+
$address->setGrandTotal(0);
|
338 |
+
$address->setBaseGrandTotal(0);
|
339 |
+
|
340 |
+
$address->collectTotals();
|
341 |
+
|
342 |
+
$quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
|
343 |
+
$quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());
|
344 |
+
|
345 |
+
$quote->setSubtotalWithDiscount(
|
346 |
+
(float) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()
|
347 |
+
);
|
348 |
+
$quote->setBaseSubtotalWithDiscount(
|
349 |
+
(float) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()
|
350 |
+
);
|
351 |
+
|
352 |
+
$quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
|
353 |
+
$quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
|
354 |
+
|
355 |
+
$quote ->save();
|
356 |
+
|
357 |
+
$quote->setGrandTotal($quote->getBaseSubtotal()-$discountAmount)
|
358 |
+
->setBaseGrandTotal($quote->getBaseSubtotal()-$discountAmount)
|
359 |
+
->setSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
|
360 |
+
->setBaseSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
|
361 |
+
->save();
|
362 |
+
|
363 |
+
|
364 |
+
if($address->getAddressType()==$canAddItems) {
|
365 |
+
//echo $address->setDiscountAmount; exit;
|
366 |
+
$address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount()-$discountAmount);
|
367 |
+
$address->setGrandTotal((float) $address->getGrandTotal()-$discountAmount);
|
368 |
+
$address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount()-$discountAmount);
|
369 |
+
$address->setBaseGrandTotal((float) $address->getBaseGrandTotal()-$discountAmount);
|
370 |
+
if($address->getDiscountDescription()){
|
371 |
+
$address->setDiscountAmount(-($address->getDiscountAmount()-$discountAmount));
|
372 |
+
$address->setDiscountDescription($address->getDiscountDescription().', Custom Discount');
|
373 |
+
$address->setBaseDiscountAmount(-($address->getBaseDiscountAmount()-$discountAmount));
|
374 |
+
}else {
|
375 |
+
$address->setDiscountAmount(-($discountAmount));
|
376 |
+
$address->setDiscountDescription('Custom Discount');
|
377 |
+
$address->setBaseDiscountAmount(-($discountAmount));
|
378 |
+
}
|
379 |
+
$address->save();
|
380 |
+
}//end: if
|
381 |
+
} //end: foreach
|
382 |
+
//echo $quote->getGrandTotal();
|
383 |
+
|
384 |
+
foreach($quote->getAllItems() as $item){
|
385 |
+
//We apply discount amount based on the ratio between the GrandTotal and the RowTotal
|
386 |
+
$rat=$item->getPriceInclTax()/$total;
|
387 |
+
$ratdisc=$discountAmount*$rat;
|
388 |
+
$item->setDiscountAmount(($item->getDiscountAmount()+$ratdisc) * $item->getQty());
|
389 |
+
$item->setBaseDiscountAmount(($item->getBaseDiscountAmount()+$ratdisc) * $item->getQty())->save();
|
390 |
+
}
|
391 |
+
}
|
392 |
+
}
|
393 |
+
}
|
394 |
+
}
|
395 |
+
catch(Exception $e)
|
396 |
+
{
|
397 |
+
Mage::log("Apply discount method - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
398 |
+
$error_info = array(
|
399 |
+
'method' => 'ApplyDiscountMethod',
|
400 |
+
'error_message' => $e->getMessage()
|
401 |
+
);
|
402 |
+
|
403 |
+
$helper = Mage::helper('increasingly_analytics');
|
404 |
+
$helper->addEvent('track', 'track_error', $error_info);
|
405 |
+
}
|
406 |
+
|
407 |
+
}
|
408 |
+
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Track new order
|
412 |
+
*
|
413 |
+
*/
|
414 |
+
public function trackNewOrder(Varien_Event_Observer $observer)
|
415 |
+
{
|
416 |
+
$helper = Mage::helper('increasingly_analytics');
|
417 |
+
try
|
418 |
+
{
|
419 |
+
|
420 |
+
|
421 |
+
|
422 |
+
if ($helper->isEnabled())
|
423 |
+
{
|
424 |
+
$data = array();
|
425 |
+
$order = $observer->getOrder();
|
426 |
+
|
427 |
+
if ($order->getId())
|
428 |
+
{
|
429 |
+
$data = $helper->buildOrderDetailsData($order);
|
430 |
+
$helper->addEvent('track', 'order', $data);
|
431 |
+
$helper->deleteBundleOnPurchase();
|
432 |
+
}
|
433 |
+
}
|
434 |
+
}
|
435 |
+
catch(Exception $e)
|
436 |
+
{
|
437 |
+
Mage::log("New order tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
438 |
+
$error_info = array(
|
439 |
+
'method' => 'trackNewOrderMethod',
|
440 |
+
'error_message' => $e->getMessage()
|
441 |
+
);
|
442 |
+
$helper->addEvent('track', 'track_error', $error_info);
|
443 |
+
}
|
444 |
+
}
|
445 |
+
|
446 |
+
|
447 |
+
/**
|
448 |
+
* Send product update information
|
449 |
+
*
|
450 |
+
*/
|
451 |
+
public function productAddOrUpdate(Varien_Event_Observer $observer)
|
452 |
+
{
|
453 |
+
try
|
454 |
+
{
|
455 |
+
$helper = Mage::helper('increasingly_analytics');
|
456 |
+
|
457 |
+
if ($helper->isEnabled())
|
458 |
+
{
|
459 |
+
$productId = $observer->getEvent()->getProduct()->getId();
|
460 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
461 |
+
|
462 |
+
$productFormatHelper = Mage::helper('increasingly_analytics/ProductFormatter');
|
463 |
+
|
464 |
+
$formattedProductInfo = $productFormatHelper->formatProductInfo($product);
|
465 |
+
$helper->increasinglyApi($formattedProductInfo,'product_add_or_update','track',$helper->getApiToken(),$helper->getApiSecret());
|
466 |
+
}
|
467 |
+
|
468 |
+
}
|
469 |
+
catch(Exception $e)
|
470 |
+
{
|
471 |
+
Mage::log("Product Add or Update tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
472 |
+
}
|
473 |
+
}
|
474 |
+
|
475 |
+
/**
|
476 |
+
* Send product delete information
|
477 |
+
*
|
478 |
+
*/
|
479 |
+
public function productDelete(Varien_Event_Observer $observer)
|
480 |
+
{
|
481 |
+
try
|
482 |
+
{
|
483 |
+
$helper = Mage::helper('increasingly_analytics');
|
484 |
+
|
485 |
+
if ($helper->isEnabled()){
|
486 |
+
$productId = $observer->getEvent()->getProduct()->getId();
|
487 |
+
|
488 |
+
$productData = array('product_id' => $productId);
|
489 |
+
$helper->deleteBundleOnProductDeleteFromCart($productId);
|
490 |
+
$helper->increasinglyApi($productData,'product_delete','track',$helper->getApiToken(),$helper->getApiSecret());
|
491 |
+
}
|
492 |
+
|
493 |
+
}
|
494 |
+
catch(Exception $e)
|
495 |
+
{
|
496 |
+
Mage::log("Product delete tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
497 |
+
}
|
498 |
+
}
|
499 |
+
|
500 |
+
public function importShippingDetails(Varien_Event_Observer $observer)
|
501 |
+
{
|
502 |
+
try
|
503 |
+
{
|
504 |
+
$helper = Mage::helper('increasingly_analytics');
|
505 |
+
$priceFormatter = Mage::helper('increasingly_analytics/PriceFormatter');
|
506 |
+
|
507 |
+
if ($helper->isEnabled())
|
508 |
+
{
|
509 |
+
$data = array();
|
510 |
+
$carriers = array();
|
511 |
+
$config = Mage::getStoreConfig('carriers', Mage::app()->getStore()->getId());
|
512 |
+
|
513 |
+
foreach ($config as $code => $carrierConfig)
|
514 |
+
{
|
515 |
+
if ($carrierConfig['model'] == 'shipping/carrier_freeshipping')
|
516 |
+
{
|
517 |
+
$data['is_free_shipping_active'] = Mage::getStoreConfigFlag('carriers/'.$code.'/active', $store);
|
518 |
+
$data['free_shipping_subtotal'] = $priceFormatter->format($carrierConfig['free_shipping_subtotal']);
|
519 |
+
$data['free_shipping_title'] = $carrierConfig['title'];
|
520 |
+
}
|
521 |
+
}
|
522 |
+
|
523 |
+
$helper->increasinglyApi($data,'shipping_details_import','track',$helper->getApiToken(),$helper->getApiSecret());
|
524 |
+
|
525 |
+
}
|
526 |
+
|
527 |
+
}
|
528 |
+
catch(Exception $e)
|
529 |
+
{
|
530 |
+
Mage::log("Import shipping details - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
531 |
+
}
|
532 |
+
|
533 |
+
}
|
534 |
+
|
535 |
+
}
|
app/code/community/Increasingly/Analytics/controllers/AddbundletocartController.php
CHANGED
@@ -184,7 +184,10 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
184 |
*
|
185 |
*/
|
186 |
public function addToCart($data){
|
187 |
-
|
|
|
|
|
|
|
188 |
$redirectUrl = "";
|
189 |
try{
|
190 |
|
@@ -202,6 +205,8 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
202 |
$productErrorStr = "";
|
203 |
$productSuccessStr = "";
|
204 |
$quantity = 1;
|
|
|
|
|
205 |
|
206 |
for ($x = 0; $x < count($data[0]["params"]); $x++) {
|
207 |
$productIds[$x] = trim($data[0]["params"][$x]["product_id"]);
|
@@ -257,7 +262,7 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
257 |
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
|
258 |
->addFieldToFilter('bundle_id', $bundle_id)
|
259 |
->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
260 |
-
|
261 |
//Check if bundle already exists,add if not already present
|
262 |
if(count($userBundleCollection) < 1){
|
263 |
$userBundle = Mage::getModel('increasingly_analytics/bundle');
|
@@ -270,8 +275,9 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
270 |
}
|
271 |
|
272 |
//Set cart was updated flag
|
273 |
-
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
|
274 |
-
|
|
|
275 |
}
|
276 |
|
277 |
if($productSuccessStr != "")
|
@@ -280,16 +286,28 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
280 |
//Error message for the out of stock products
|
281 |
if($productErrorStr != "")
|
282 |
Mage::getSingleton('core/session')->addNotice($productErrorStr.' is out of stock');
|
283 |
-
|
284 |
//Redirect to the cart
|
285 |
$this->_redirect('checkout/cart');
|
286 |
|
287 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
}
|
289 |
catch(Exception $e)
|
290 |
-
{
|
291 |
Mage::log("Increasingly addToCart controller - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
292 |
-
Mage::getSingleton('core/session')->addNotice($e->getMessage());
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
$this->_redirectUrl($redirectUrl);
|
294 |
}
|
295 |
|
184 |
*
|
185 |
*/
|
186 |
public function addToCart($data){
|
187 |
+
|
188 |
+
$helper = Mage::helper('increasingly_analytics');
|
189 |
+
$hasBundleAddedToCartSuccessfully = false;
|
190 |
+
$cart_bundle_data = array();
|
191 |
$redirectUrl = "";
|
192 |
try{
|
193 |
|
205 |
$productErrorStr = "";
|
206 |
$productSuccessStr = "";
|
207 |
$quantity = 1;
|
208 |
+
$cart_bundle_data['bundle_id'] = $bundle_id;
|
209 |
+
$cart_bundle_data['discountPrice'] = $discountPrice;
|
210 |
|
211 |
for ($x = 0; $x < count($data[0]["params"]); $x++) {
|
212 |
$productIds[$x] = trim($data[0]["params"][$x]["product_id"]);
|
262 |
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
|
263 |
->addFieldToFilter('bundle_id', $bundle_id)
|
264 |
->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
265 |
+
|
266 |
//Check if bundle already exists,add if not already present
|
267 |
if(count($userBundleCollection) < 1){
|
268 |
$userBundle = Mage::getModel('increasingly_analytics/bundle');
|
275 |
}
|
276 |
|
277 |
//Set cart was updated flag
|
278 |
+
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
|
279 |
+
$hasBundleAddedToCartSuccessfully = true;
|
280 |
+
$helper->addEvent('track', 'bundle_add_to_cart', $cart_bundle_data);
|
281 |
}
|
282 |
|
283 |
if($productSuccessStr != "")
|
286 |
//Error message for the out of stock products
|
287 |
if($productErrorStr != "")
|
288 |
Mage::getSingleton('core/session')->addNotice($productErrorStr.' is out of stock');
|
289 |
+
|
290 |
//Redirect to the cart
|
291 |
$this->_redirect('checkout/cart');
|
292 |
|
293 |
+
}
|
294 |
+
|
295 |
+
if($hasBundleAddedToCartSuccessfully == false)
|
296 |
+
{
|
297 |
+
$cart_bundle_data['bundle_data'] = $data;
|
298 |
+
$helper->addEvent('track', 'bundle_add_to_cart_failuer', $cart_bundle_data);
|
299 |
+
}
|
300 |
}
|
301 |
catch(Exception $e)
|
302 |
+
{
|
303 |
Mage::log("Increasingly addToCart controller - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
304 |
+
Mage::getSingleton('core/session')->addNotice($e->getMessage());
|
305 |
+
$error_info = array(
|
306 |
+
'method' => 'AddBundleToCartMethod',
|
307 |
+
'error_message' => $e->getMessage()
|
308 |
+
);
|
309 |
+
|
310 |
+
$helper->addEvent('track', 'track_error', $error_info);
|
311 |
$this->_redirectUrl($redirectUrl);
|
312 |
}
|
313 |
|
app/code/community/Increasingly/Analytics/controllers/ProductsImportApiController.php
CHANGED
@@ -108,12 +108,22 @@ class Increasingly_Analytics_ProductsImportApiController extends Mage_Core_Contr
|
|
108 |
{
|
109 |
$productData['description'] = $product->getData('description');
|
110 |
}
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
112 |
if ($product->hasData('short_description') && $productData['short_description'] == null)
|
113 |
{
|
114 |
$productData['short_description'] = $product->getData('short_description');
|
115 |
}
|
116 |
|
|
|
|
|
|
|
|
|
|
|
117 |
if($productData['product_type_name'] == "configurable")
|
118 |
{
|
119 |
$configurableProducts = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($productData['product_id']);
|
108 |
{
|
109 |
$productData['description'] = $product->getData('description');
|
110 |
}
|
111 |
+
|
112 |
+
if($productData['description'] == null || empty($productData['description']))
|
113 |
+
{
|
114 |
+
$productData['description'] = $product->getDescription();
|
115 |
+
}
|
116 |
+
|
117 |
if ($product->hasData('short_description') && $productData['short_description'] == null)
|
118 |
{
|
119 |
$productData['short_description'] = $product->getData('short_description');
|
120 |
}
|
121 |
|
122 |
+
if($productData['short_description'] == null || empty($productData['short_description']))
|
123 |
+
{
|
124 |
+
$productData['short_description'] = $product->getShortDescription();
|
125 |
+
}
|
126 |
+
|
127 |
if($productData['product_type_name'] == "configurable")
|
128 |
{
|
129 |
$configurableProducts = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($productData['product_id']);
|
app/code/community/Increasingly/Analytics/etc/config.xml
CHANGED
@@ -32,7 +32,7 @@
|
|
32 |
<config>
|
33 |
<modules>
|
34 |
<Increasingly_Analytics>
|
35 |
-
<version>1.0.
|
36 |
</Increasingly_Analytics>
|
37 |
</modules>
|
38 |
<global>
|
32 |
<config>
|
33 |
<modules>
|
34 |
<Increasingly_Analytics>
|
35 |
+
<version>1.0.15</version>
|
36 |
</Increasingly_Analytics>
|
37 |
</modules>
|
38 |
<global>
|
app/code/community/Increasingly/Analytics/sql/increasingly_analytics_setup/mysql4-install-1.0.15.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_price` decimal(12,4) NOT NULL,
|
22 |
+
|
23 |
+
PRIMARY KEY (`id`)
|
24 |
+
|
25 |
+
);
|
26 |
+
|
27 |
+
");
|
28 |
+
|
29 |
+
$installer->endSetup();
|
app/design/frontend/base/default/template/increasingly/track.phtml
CHANGED
@@ -41,11 +41,11 @@
|
|
41 |
|
42 |
window.increasingly.load=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
|
43 |
r.type="text/javascript";r.async=true;r.src="//www.increasingly.co/js/track.js";n.parentNode.insertBefore(r,n);};
|
44 |
-
|
45 |
|
46 |
window.increasingly.loadJs=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
|
47 |
r.type="text/javascript";r.async=true;r.src="//www.increasingly.co/js/increasingly.js";n.parentNode.insertBefore(r,n);};
|
48 |
-
|
49 |
|
50 |
increasingly.load();
|
51 |
increasingly.loadJs();
|
41 |
|
42 |
window.increasingly.load=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
|
43 |
r.type="text/javascript";r.async=true;r.src="//www.increasingly.co/js/track.js";n.parentNode.insertBefore(r,n);};
|
44 |
+
// Live url //www.increasingly.co/js/track.js
|
45 |
|
46 |
window.increasingly.loadJs=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
|
47 |
r.type="text/javascript";r.async=true;r.src="//www.increasingly.co/js/increasingly.js";n.parentNode.insertBefore(r,n);};
|
48 |
+
// Live url //www.increasingly.co/js/increasingly.js
|
49 |
|
50 |
increasingly.load();
|
51 |
increasingly.loadJs();
|
app/design/frontend/base/default/template/increasingly/track.phtml~
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
33 |
+
window.increasingly=window.increasingly||[],window.increasingly.queue=[],window.increasingly.methods=["identify","track"],
|
34 |
+
window.increasingly.filter=function(e){return function(){a=Array.prototype.slice.call(arguments);a.unshift(e);window.increasingly.queue.push(a);}};
|
35 |
+
|
36 |
+
for(var i=0;window.increasingly.methods.length>i;i++)
|
37 |
+
{
|
38 |
+
var mthd=window.increasingly.methods[i];
|
39 |
+
window.increasingly[mthd]=window.increasingly.filter(mthd);
|
40 |
+
}
|
41 |
+
|
42 |
+
window.increasingly.load=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
|
43 |
+
r.type="text/javascript";r.async=true;r.src="//www.increasingly.co/js/track.js";n.parentNode.insertBefore(r,n);};
|
44 |
+
// Live url //www.increasingly.co/js/track.js
|
45 |
+
|
46 |
+
window.increasingly.loadJs=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
|
47 |
+
r.type="text/javascript";r.async=true;r.src="//www.increasingly.co/js/increasingly.js";n.parentNode.insertBefore(r,n);};
|
48 |
+
// Live url //www.increasingly.co/js/increasingly.js
|
49 |
+
|
50 |
+
increasingly.load();
|
51 |
+
increasingly.loadJs();
|
52 |
+
<?php foreach ($events as $trackEvent) : ?>
|
53 |
+
|
54 |
+
<?php if($trackEvent['method'] == 'track') : ?>
|
55 |
+
increasingly.track("<?php echo $trackEvent['event_type']; ?>", "<?php echo base64_encode(json_encode($trackEvent)); ?>");
|
56 |
+
<?php endif; ?>
|
57 |
+
|
58 |
+
<?php endforeach; ?>
|
59 |
+
</script>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>increasingly_key</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
7 |
<channel>community</channel>
|
@@ -44,11 +44,12 @@ It's free to try & we have a 14-day trial where you can test it for no-risk
|
|
44 |

|
45 |
We have a dashboard which provides you with in depth analytics and insights on what's sells together & allows you to administer and manage your bundles.
|
46 |
</description>
|
47 |
-
<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><author><name>Increasingly</name><user>Increasingly</user><email>satish@increasingly.co</email></author></authors>
|
49 |
-
<date>2016-10-
|
50 |
-
<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="f670440a3f90bfa9a48b406fc37d538c"/><file name="Product.php" hash="2da759eb9bd2bf13e5a8a92087981206"/><file name="Track.php" hash="aa6a9d870f14c4e3721675658dfb276e"/></dir><dir name="Helper"><file name="Data.php" hash="
|
52 |
<compatible/>
|
53 |
<dependencies><required><php><min>5.2.0</min><max>7.0.7</max></php></required></dependencies>
|
54 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>increasingly_key</name>
|
4 |
+
<version>1.0.15</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>
|
44 |

|
45 |
We have a dashboard which provides you with in depth analytics and insights on what's sells together & allows you to administer and manage your bundles.
|
46 |
</description>
|
47 |
+
<notes>Added bundle cart tracking feature
|
48 |
+
Fixed the issue of deleting bundles on orders from the user cart.</notes>
|
49 |
<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><author><name>Increasingly</name><user>Increasingly</user><email>satish@increasingly.co</email></author></authors>
|
50 |
+
<date>2016-10-24</date>
|
51 |
+
<time>10:40:11</time>
|
52 |
+
<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="f670440a3f90bfa9a48b406fc37d538c"/><file name="Product.php" hash="2da759eb9bd2bf13e5a8a92087981206"/><file name="Track.php" hash="aa6a9d870f14c4e3721675658dfb276e"/></dir><dir name="Helper"><file name="Data.php" hash="79b8ebc2b0f8e46b2b5e8a658c93780c"/><file name="Data.php~" hash="79b8ebc2b0f8e46b2b5e8a658c93780c"/><file name="DateFormatter.php" hash="d8f963bd1f9fe390e038a2065fd5c4c4"/><file name="PriceFormatter.php" hash="9bc46d3afb4612131a29b9a1c2b82fad"/><file name="ProductFormatter.php" hash="2fc9d9e7de186379737b477b166e8bf5"/></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="83ad548248f3ebcfc73158ab672cb683"/><file name="Setup.php" hash="664019080c6c0ebdbc50b889eac1e1e0"/></dir><file name="Observer.php" hash="7529c60558f607aa7e479c546995d711"/><file name="Observer.php~" hash="7529c60558f607aa7e479c546995d711"/><file name="Product.php" hash="f473c25a470a2509b00a4a15ed8b857f"/></dir><dir name="controllers"><file name="AddbundletocartController.php" hash="005680ac4e204669f5d12940799ede59"/><dir name="Adminhtml"><file name="DataIntegrationController.php" hash="0758d4716d337002a8c49f843e06cec2"/></dir><file name="ImportLogsController.php" hash="035f739ed0727685f47e7d8405b4448c"/><file name="OrdersApiController.php" hash="30195b469077e96f012538899f7d4f27"/><file name="ProductsApiController.php" hash="5ac96ef4089b835968acdbca3539172a"/><file name="ProductsImportApiController.php" hash="8f3201c1b934c0e5454dfa573337b5e9"/></dir><dir name="etc"><file name="config.xml" hash="8bac59f94209e340fb0554ad5b2cec23"/></dir><dir name="sql"><dir name="increasingly_analytics_setup"><file name="mysql-install-1.0.0.php" hash="bddf4e67e7b69c5604b448e3b1fa27a0"/><file name="mysql4-install-1.0.10.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.11.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.12.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.13.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.14.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.15.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.3.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.4.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.5.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.6.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.7.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.8.php" hash="e857df177cfbb887cece6de0ff5498b6"/><file name="mysql4-install-1.0.9.php" hash="e857df177cfbb887cece6de0ff5498b6"/></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="1c5ee986109cfb4600d3e15057263d36"/><file name="category.phtml" hash="75e77b9d1cbbd1e0129c0c10737461e6"/><file name="element.phtml" hash="c5f1cbbc02801009247409890172ca4e"/><file name="embed.phtml" hash="52cde76a239e3084ce3a1254b004a742"/><file name="pagetype.phtml" hash="fe1a7f313c82f355f14d5f13c284cb28"/><file name="product.phtml" hash="14d24b0ced5abc85619aa3538b21f2f7"/><file name="track.phtml" hash="aed8cda5e868346a974799a52b99ece1"/><file name="track.phtml~" hash="aed8cda5e868346a974799a52b99ece1"/></dir></dir><dir name="layout"><file name="increasingly_analytics.xml" hash="8fdd89adb4a85e83237ada872ba43f88"/></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>
|
53 |
<compatible/>
|
54 |
<dependencies><required><php><min>5.2.0</min><max>7.0.7</max></php></required></dependencies>
|
55 |
</package>
|