Version Notes
Fix for redirecting to same product page, if entered qty for product is more than available.
Fix for redundant tracking of new orders.
Download this release
Release Info
Developer | Increasingly |
Extension | increasingly_key |
Version | 1.0.7 |
Comparing to | |
See all releases |
Code changes from version 1.0.6 to 1.0.7
- app/code/community/Increasingly/Analytics/Helper/Data.php~ +351 -0
- app/code/community/Increasingly/Analytics/Model/Observer.php +0 -24
- app/code/community/Increasingly/Analytics/Model/Observer.php~ +545 -0
- app/code/community/Increasingly/Analytics/controllers/AddbundletocartController.php +10 -0
- app/code/community/Increasingly/Analytics/controllers/AddbundletocartController.php~ +297 -0
- app/code/community/Increasingly/Analytics/controllers/ProductsApiController.php +2 -1
- app/code/community/Increasingly/Analytics/controllers/ProductsApiController.php~ +158 -0
- app/code/community/Increasingly/Analytics/etc/config.xml +2 -11
- app/code/community/Increasingly/Analytics/etc/config.xml~ +250 -0
- app/code/community/Increasingly/Analytics/sql/increasingly_analytics_setup/mysql4-install-1.0.7.php +29 -0
- app/design/frontend/base/default/template/increasingly/track.phtml~ +57 -0
- package.xml +7 -5
app/code/community/Increasingly/Analytics/Helper/Data.php~
ADDED
@@ -0,0 +1,351 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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->getTotalPrice();
|
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 |
+
}
|
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 |
+
|
215 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
216 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
217 |
+
|
218 |
+
if(count($userBundleCollection) >= 1){
|
219 |
+
|
220 |
+
foreach($userBundleCollection as $bundle){
|
221 |
+
|
222 |
+
$isProductInBundle = in_array($product_id, explode(',',$bundle->getProductIds()));
|
223 |
+
|
224 |
+
if(!is_null($isProductInBundle) && !empty($isProductInBundle) && $isProductInBundle == true)
|
225 |
+
{
|
226 |
+
$userBundle = Mage::getModel('increasingly_analytics/bundle');
|
227 |
+
$userBundle->setId($bundle->getId())->delete();
|
228 |
+
}
|
229 |
+
|
230 |
+
}
|
231 |
+
}
|
232 |
+
}
|
233 |
+
catch (Exception $e)
|
234 |
+
{
|
235 |
+
Mage::log("Increasingly delete bundle on delete from cart- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
236 |
+
}
|
237 |
+
|
238 |
+
}
|
239 |
+
|
240 |
+
/**Delete bundle when all the items in the cart are deleted
|
241 |
+
**
|
242 |
+
*/
|
243 |
+
public function deleteBundleOnEmptyCart($quote){
|
244 |
+
try {
|
245 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
246 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
247 |
+
$productIds = explode(',', $userBundle->getProductIds);
|
248 |
+
if($quote->getItemsCount() == 0 && count($userBundleCollection) >= 0) {
|
249 |
+
foreach ($userBundleCollection as $userBundle) {
|
250 |
+
$userBundle->delete();
|
251 |
+
|
252 |
+
}
|
253 |
+
}
|
254 |
+
}
|
255 |
+
catch (Exception $e)
|
256 |
+
{
|
257 |
+
Mage::log("Increasingly delete bundle on emptyCart- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
258 |
+
}
|
259 |
+
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Sends event data to increasingly through API
|
264 |
+
*/
|
265 |
+
public function increasinglyApi($importData,$event_type,$method,$api_token,$api_secret)
|
266 |
+
{ Mage::log("Server call".$event_type, null, 'Increasingly_Analytics.log');
|
267 |
+
$result = '';
|
268 |
+
try {
|
269 |
+
$version = (string)Mage::getConfig()->getModuleConfig("Increasingly_Analytics")->version;
|
270 |
+
$data = array(
|
271 |
+
'event_data' => $importData,
|
272 |
+
'event_type'=> $event_type,
|
273 |
+
'method' => $method,
|
274 |
+
'platform' => 'Magento ' . Mage::getEdition() . ' ' . Mage::getVersion(),
|
275 |
+
'token' => $api_token,
|
276 |
+
'version' => $version
|
277 |
+
);
|
278 |
+
// sort data
|
279 |
+
ksort($data);
|
280 |
+
$encodedData = base64_encode(Mage::helper('core')->jsonEncode($data));
|
281 |
+
$signature = md5($encodedData.$api_secret);
|
282 |
+
$url = 'http://localhost:8087/ImportData';
|
283 |
+
$client = new Varien_Http_Client($url);
|
284 |
+
|
285 |
+
$postData = array(
|
286 |
+
'signature' => $signature,
|
287 |
+
'eventData' => $encodedData
|
288 |
+
);
|
289 |
+
$jsonData = json_encode($postData);
|
290 |
+
$client->setRawData($jsonData, 'application/json');
|
291 |
+
$response = $client->request('POST');
|
292 |
+
$result = json_decode($response->getBody());
|
293 |
+
|
294 |
+
if ($response->isError()) {
|
295 |
+
Mage::log($response->getBody(), null, 'Increasingly_Analytics.log');
|
296 |
+
}
|
297 |
+
|
298 |
+
}
|
299 |
+
catch (Exception $e)
|
300 |
+
{
|
301 |
+
Mage::log("Increasingly api call- " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
302 |
+
}
|
303 |
+
return $result;
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Builds a tagging string of the given category including all its parent
|
308 |
+
* categories.
|
309 |
+
* The categories are sorted by their position in the category tree path.
|
310 |
+
*
|
311 |
+
* @param Mage_Catalog_Model_Category $category the category model.
|
312 |
+
*
|
313 |
+
* @return string
|
314 |
+
*/
|
315 |
+
public function buildCategoryString($category)
|
316 |
+
{
|
317 |
+
$data = array();
|
318 |
+
if ($category instanceof Mage_Catalog_Model_Category) {
|
319 |
+
/** @var $categories Mage_Catalog_Model_Category[] */
|
320 |
+
$categories = $category->getParentCategories();
|
321 |
+
$path = $category->getPathInStore();
|
322 |
+
$ids = array_reverse(explode(',', $path));
|
323 |
+
foreach ($ids as $id) {
|
324 |
+
if (isset($categories[$id]) && $categories[$id]->getName()) {
|
325 |
+
$data[] = $categories[$id]->getId();
|
326 |
+
}
|
327 |
+
}
|
328 |
+
}
|
329 |
+
if (!empty($data)) {
|
330 |
+
return DS . implode(DS, $data);
|
331 |
+
} else {
|
332 |
+
return '';
|
333 |
+
}
|
334 |
+
}
|
335 |
+
|
336 |
+
/**
|
337 |
+
* Return the product image version to include in product tagging.
|
338 |
+
*
|
339 |
+
* @param Mage_Core_Model_Store|null $store the store model or null.
|
340 |
+
*
|
341 |
+
* @return string
|
342 |
+
*/
|
343 |
+
public function getProductImageVersion($store = null)
|
344 |
+
{
|
345 |
+
return Mage::getStoreConfig(self::XML_PATH_IMAGE_VERSION, $store);
|
346 |
+
}
|
347 |
+
|
348 |
+
|
349 |
+
|
350 |
+
|
351 |
+
}
|
app/code/community/Increasingly/Analytics/Model/Observer.php
CHANGED
@@ -430,30 +430,6 @@ public function trackNewOrder(Varien_Event_Observer $observer)
|
|
430 |
}
|
431 |
|
432 |
|
433 |
-
/**
|
434 |
-
* Send order update information
|
435 |
-
*
|
436 |
-
*/
|
437 |
-
public function updateOrder(Varien_Event_Observer $observer)
|
438 |
-
{
|
439 |
-
try
|
440 |
-
{
|
441 |
-
$helper = Mage::helper('increasingly_analytics');
|
442 |
-
|
443 |
-
if ($helper->isEnabled())
|
444 |
-
{
|
445 |
-
$order = $observer->getOrder();
|
446 |
-
$orderDetails = $helper->buildOrderDetailsData($order);
|
447 |
-
$helper->increasinglyApi($orderDetails,'order','track',$helper->getApiToken(),$helper->getApiSecret());
|
448 |
-
}
|
449 |
-
|
450 |
-
}
|
451 |
-
catch(Exception $e)
|
452 |
-
{
|
453 |
-
Mage::log("Update order tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
454 |
-
}
|
455 |
-
}
|
456 |
-
|
457 |
/**
|
458 |
* Send product update information
|
459 |
*
|
430 |
}
|
431 |
|
432 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
433 |
/**
|
434 |
* Send product update information
|
435 |
*
|
app/code/community/Increasingly/Analytics/Model/Observer.php~
ADDED
@@ -0,0 +1,545 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
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->getFinalPrice());
|
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->getFinalPrice());
|
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("Remove from cart tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
398 |
+
}
|
399 |
+
|
400 |
+
}
|
401 |
+
|
402 |
+
|
403 |
+
/**
|
404 |
+
* Track new order
|
405 |
+
*
|
406 |
+
*/
|
407 |
+
public function trackNewOrder(Varien_Event_Observer $observer)
|
408 |
+
{
|
409 |
+
try
|
410 |
+
{
|
411 |
+
|
412 |
+
$helper = Mage::helper('increasingly_analytics');
|
413 |
+
|
414 |
+
if ($helper->isEnabled())
|
415 |
+
{
|
416 |
+
$data = array();
|
417 |
+
$order = $observer->getOrder();
|
418 |
+
|
419 |
+
if ($order->getId())
|
420 |
+
{
|
421 |
+
$data = $helper->buildOrderDetailsData($order);
|
422 |
+
$helper->addEvent('track', 'order', $data);
|
423 |
+
}
|
424 |
+
}
|
425 |
+
}
|
426 |
+
catch(Exception $e)
|
427 |
+
{
|
428 |
+
Mage::log("New order tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
429 |
+
}
|
430 |
+
}
|
431 |
+
|
432 |
+
|
433 |
+
/**
|
434 |
+
* Send order update information
|
435 |
+
*
|
436 |
+
*/
|
437 |
+
public function updateOrder(Varien_Event_Observer $observer)
|
438 |
+
{
|
439 |
+
try
|
440 |
+
{
|
441 |
+
$helper = Mage::helper('increasingly_analytics');
|
442 |
+
|
443 |
+
if ($helper->isEnabled())
|
444 |
+
{
|
445 |
+
$order = $observer->getOrder();
|
446 |
+
$orderDetails = $helper->buildOrderDetailsData($order);
|
447 |
+
$helper->increasinglyApi($orderDetails,'order','track',$helper->getApiToken(),$helper->getApiSecret());
|
448 |
+
}
|
449 |
+
|
450 |
+
}
|
451 |
+
catch(Exception $e)
|
452 |
+
{
|
453 |
+
Mage::log("Update order tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
454 |
+
}
|
455 |
+
}
|
456 |
+
|
457 |
+
/**
|
458 |
+
* Send product update information
|
459 |
+
*
|
460 |
+
*/
|
461 |
+
public function productAddOrUpdate(Varien_Event_Observer $observer)
|
462 |
+
{
|
463 |
+
try
|
464 |
+
{
|
465 |
+
$helper = Mage::helper('increasingly_analytics');
|
466 |
+
|
467 |
+
if ($helper->isEnabled())
|
468 |
+
{
|
469 |
+
$productId = $observer->getEvent()->getProduct()->getId();
|
470 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
471 |
+
|
472 |
+
$productFormatHelper = Mage::helper('increasingly_analytics/ProductFormatter');
|
473 |
+
|
474 |
+
$formattedProductInfo = $productFormatHelper->formatProductInfo($product);
|
475 |
+
$helper->increasinglyApi($formattedProductInfo,'product_add_or_update','track',$helper->getApiToken(),$helper->getApiSecret());
|
476 |
+
}
|
477 |
+
|
478 |
+
}
|
479 |
+
catch(Exception $e)
|
480 |
+
{
|
481 |
+
Mage::log("Product Add or Update tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
482 |
+
}
|
483 |
+
}
|
484 |
+
|
485 |
+
/**
|
486 |
+
* Send product delete information
|
487 |
+
*
|
488 |
+
*/
|
489 |
+
public function productDelete(Varien_Event_Observer $observer)
|
490 |
+
{
|
491 |
+
try
|
492 |
+
{
|
493 |
+
$helper = Mage::helper('increasingly_analytics');
|
494 |
+
|
495 |
+
if ($helper->isEnabled()){
|
496 |
+
$productId = $observer->getEvent()->getProduct()->getId();
|
497 |
+
|
498 |
+
$productData = array('product_id' => $productId);
|
499 |
+
$helper->deleteBundleOnProductDeleteFromCart($productId);
|
500 |
+
$helper->increasinglyApi($productData,'product_delete','track',$helper->getApiToken(),$helper->getApiSecret());
|
501 |
+
}
|
502 |
+
|
503 |
+
}
|
504 |
+
catch(Exception $e)
|
505 |
+
{
|
506 |
+
Mage::log("Product delete tracking - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
public function importShippingDetails(Varien_Event_Observer $observer)
|
511 |
+
{
|
512 |
+
try
|
513 |
+
{
|
514 |
+
$helper = Mage::helper('increasingly_analytics');
|
515 |
+
$priceFormatter = Mage::helper('increasingly_analytics/PriceFormatter');
|
516 |
+
|
517 |
+
if ($helper->isEnabled())
|
518 |
+
{
|
519 |
+
$data = array();
|
520 |
+
$carriers = array();
|
521 |
+
$config = Mage::getStoreConfig('carriers', Mage::app()->getStore()->getId());
|
522 |
+
|
523 |
+
foreach ($config as $code => $carrierConfig)
|
524 |
+
{
|
525 |
+
if ($carrierConfig['model'] == 'shipping/carrier_freeshipping')
|
526 |
+
{
|
527 |
+
$data['is_free_shipping_active'] = Mage::getStoreConfigFlag('carriers/'.$code.'/active', $store);
|
528 |
+
$data['free_shipping_subtotal'] = $priceFormatter->format($carrierConfig['free_shipping_subtotal']);
|
529 |
+
$data['free_shipping_title'] = $carrierConfig['title'];
|
530 |
+
}
|
531 |
+
}
|
532 |
+
|
533 |
+
$helper->increasinglyApi($data,'shipping_details_import','track',$helper->getApiToken(),$helper->getApiSecret());
|
534 |
+
|
535 |
+
}
|
536 |
+
|
537 |
+
}
|
538 |
+
catch(Exception $e)
|
539 |
+
{
|
540 |
+
Mage::log("Import shipping details - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
541 |
+
}
|
542 |
+
|
543 |
+
}
|
544 |
+
|
545 |
+
}
|
app/code/community/Increasingly/Analytics/controllers/AddbundletocartController.php
CHANGED
@@ -184,7 +184,11 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
184 |
*
|
185 |
*/
|
186 |
public function addToCart($data){
|
|
|
|
|
187 |
try{
|
|
|
|
|
188 |
$this->cart= Mage::getSingleton('checkout/cart');
|
189 |
|
190 |
if($data[0]["bundle_id"] != null || $data[0]["bundle_id"] || ""){
|
@@ -213,6 +217,7 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
213 |
foreach ($productIds as $productId) {
|
214 |
$product = Mage::getModel('catalog/product');
|
215 |
$product->load($productId);
|
|
|
216 |
$inStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock();
|
217 |
if($inStock){
|
218 |
array_push($inStockProducts, $productId);
|
@@ -228,6 +233,9 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
228 |
foreach ($inStockProducts as $product_id) {
|
229 |
$product = Mage::getModel('catalog/product');
|
230 |
$product->load($product_id);
|
|
|
|
|
|
|
231 |
$this->cart->addProduct($product,array('qty' => $quantity));
|
232 |
$productSuccessStr .= $product->getName().", ";
|
233 |
}
|
@@ -281,6 +289,8 @@ class Increasingly_Analytics_AddbundletocartController extends Mage_Core_Control
|
|
281 |
catch(Exception $e)
|
282 |
{
|
283 |
Mage::log("Increasingly addToCart controller - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
|
|
|
|
284 |
}
|
285 |
|
286 |
}
|
184 |
*
|
185 |
*/
|
186 |
public function addToCart($data){
|
187 |
+
|
188 |
+
$redirectUrl = "";
|
189 |
try{
|
190 |
+
|
191 |
+
$redirectUrl = Mage::app()->getRequest()->getServer('HTTP_REFERER');
|
192 |
$this->cart= Mage::getSingleton('checkout/cart');
|
193 |
|
194 |
if($data[0]["bundle_id"] != null || $data[0]["bundle_id"] || ""){
|
217 |
foreach ($productIds as $productId) {
|
218 |
$product = Mage::getModel('catalog/product');
|
219 |
$product->load($productId);
|
220 |
+
|
221 |
$inStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock();
|
222 |
if($inStock){
|
223 |
array_push($inStockProducts, $productId);
|
233 |
foreach ($inStockProducts as $product_id) {
|
234 |
$product = Mage::getModel('catalog/product');
|
235 |
$product->load($product_id);
|
236 |
+
|
237 |
+
$redirectUrl = $product->getProductUrl();
|
238 |
+
|
239 |
$this->cart->addProduct($product,array('qty' => $quantity));
|
240 |
$productSuccessStr .= $product->getName().", ";
|
241 |
}
|
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 |
|
296 |
}
|
app/code/community/Increasingly/Analytics/controllers/AddbundletocartController.php~
ADDED
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
52 |
+
if($current_page == "checkout_cart_index"){
|
53 |
+
$quote = Mage::getModel('checkout/cart')->getQuote();
|
54 |
+
|
55 |
+
//Get all Cart product Ids
|
56 |
+
$cartProductIds =[];
|
57 |
+
foreach ($quote->getAllItems() as $item) {
|
58 |
+
array_push($cartProductIds, $item->getProduct()->getId());
|
59 |
+
}
|
60 |
+
|
61 |
+
//Get all bundle Product Ids
|
62 |
+
$previousCartProducts = [];
|
63 |
+
for ($x = 0; $x < count($data[0]["params"]); $x++) {
|
64 |
+
array_push($previousCartProducts,trim($data[0]["params"][$x]["product_id"]));
|
65 |
+
}
|
66 |
+
|
67 |
+
//Get all Bundle product Ids that are in cart
|
68 |
+
$result = array_intersect($cartProductIds, $previousCartProducts);
|
69 |
+
$productsToAddToCart = array_diff($previousCartProducts,$result);
|
70 |
+
|
71 |
+
//All bundle products are in cart,add all
|
72 |
+
if(count($result) == count($cartProductIds) && count($result) == count($previousCartProducts) && count($cartProductIds) == count($previousCartProducts)){
|
73 |
+
$this->addToCart($data);
|
74 |
+
}else{
|
75 |
+
|
76 |
+
//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
|
77 |
+
if(count($productsToAddToCart) >= 1){
|
78 |
+
|
79 |
+
//Push the products into instock and out of stock arrays to handle the success and error messages at cart page
|
80 |
+
foreach ($productsToAddToCart as $productId) {
|
81 |
+
$product = Mage::getModel('catalog/product');
|
82 |
+
$product->load($productId);
|
83 |
+
|
84 |
+
//In Stock or Out of stock status of the product
|
85 |
+
$inStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock();
|
86 |
+
if($inStock){
|
87 |
+
|
88 |
+
//Push all the instock products to the inStockProducts array
|
89 |
+
array_push($inStockProducts, $productId);
|
90 |
+
}
|
91 |
+
else{
|
92 |
+
|
93 |
+
//Push all the out of stock products to the outOfStockProducts array
|
94 |
+
array_push($outOfStockProducts, $productId);
|
95 |
+
//Prepare the error message for the products out of stock
|
96 |
+
$productErrorStr .= $product->getName().", ";
|
97 |
+
}
|
98 |
+
}
|
99 |
+
//Add all the instock products to the cart and prepare the success message
|
100 |
+
foreach ($inStockProducts as $product_id) {
|
101 |
+
$this->addTo($product_id,$data);
|
102 |
+
$productSuccessStr .= $product->getName().", ";
|
103 |
+
}
|
104 |
+
//Trim the success message
|
105 |
+
$productSuccessStr = rtrim(trim($productSuccessStr),',');
|
106 |
+
//Trim the error message
|
107 |
+
$productErrorStr = rtrim(trim($productErrorStr),',');
|
108 |
+
//Save the cart
|
109 |
+
$this->cart->save();
|
110 |
+
//Get teh quote
|
111 |
+
$quote = Mage::getModel('checkout/cart')->getQuote();
|
112 |
+
//Add success message
|
113 |
+
if($productSuccessStr != "")
|
114 |
+
Mage::getSingleton('core/session')->addSuccess($productSuccessStr.' added to your shopping cart');
|
115 |
+
//Add error message
|
116 |
+
if($productErrorStr != "")
|
117 |
+
Mage::getSingleton('core/session')->addNotice($productErrorStr.' is out of stock');
|
118 |
+
//Set cart was updated
|
119 |
+
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
|
120 |
+
//Redirect to cart
|
121 |
+
$this->_redirect('checkout/cart');
|
122 |
+
}
|
123 |
+
if(count($productsToAddToCart)==0){
|
124 |
+
//Add all bundled products to the cart when the cart is empty from the cart page and add bundles
|
125 |
+
$this->addToCart($data);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
}else{
|
130 |
+
//Add to bundle from all other pages except cart
|
131 |
+
$this->addToCart($data);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
catch(Exception $e)
|
135 |
+
{
|
136 |
+
$this->_redirect('checkout/cart');
|
137 |
+
}
|
138 |
+
|
139 |
+
|
140 |
+
}
|
141 |
+
/**Adds the product to the cart on click of Add to Basket button
|
142 |
+
*
|
143 |
+
*/
|
144 |
+
public function addTo($productId,$data){
|
145 |
+
try{
|
146 |
+
if($data[0]["bundle_id"] != null || $data[0]["bundle_id"] || ""){
|
147 |
+
$bundle_id = $data[0]["bundle_id"];
|
148 |
+
$productIds = [];
|
149 |
+
$discountPrice = $data[0]["discountPrice"];
|
150 |
+
$totalPrice = $data[0]["totalPrice"];
|
151 |
+
$product = Mage::getModel('catalog/product');
|
152 |
+
$product->load($productId);
|
153 |
+
$this->cart->addProduct($product,array('qty' => 1));
|
154 |
+
|
155 |
+
for ($x = 0; $x < count($data[0]["params"]); $x++) {
|
156 |
+
$productIds[$x] = trim($data[0]["params"][$x]["product_id"]);
|
157 |
+
}
|
158 |
+
$productIdsStr = implode(',',$productIds);
|
159 |
+
|
160 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
161 |
+
$userBundleCollection = Mage::getModel('increasingly_analytics/bundle')->getCollection()
|
162 |
+
->addFieldToFilter('bundle_id', $bundle_id)
|
163 |
+
->addFieldToFilter('increasingly_visitor_id',$cookieValue);
|
164 |
+
|
165 |
+
//Check if bundle already exists,add if not already present
|
166 |
+
if(count($userBundleCollection) < 1){
|
167 |
+
$userBundle = Mage::getModel('increasingly_analytics/bundle');
|
168 |
+
$userBundle->setBundleId(intval($bundle_id));
|
169 |
+
$userBundle->setProductIds($productIdsStr);
|
170 |
+
$userBundle->setIncreasinglyVisitorId($cookieValue);
|
171 |
+
$userBundle->setDiscountPrice($discountPrice);
|
172 |
+
$userBundle->setTotalPrice($totalPrice);
|
173 |
+
$userBundle->save();
|
174 |
+
}
|
175 |
+
}
|
176 |
+
}
|
177 |
+
catch(Exception $e)
|
178 |
+
{
|
179 |
+
Mage::log("Increasingly AddTo cart controller - " . $e->getMessage(), null, 'Increasingly_Analytics.log');
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
/**Adds all the bundled products to the cart from all pages
|
184 |
+
*
|
185 |
+
*/
|
186 |
+
public function addToCart($data){
|
187 |
+
|
188 |
+
$redirectUrl = "";
|
189 |
+
try{
|
190 |
+
|
191 |
+
$redirectUrl = Mage::app()->getRequest()->getServer('HTTP_REFERER');
|
192 |
+
$this->cart= Mage::getSingleton('checkout/cart');
|
193 |
+
|
194 |
+
if($data[0]["bundle_id"] != null || $data[0]["bundle_id"] || ""){
|
195 |
+
|
196 |
+
$bundle_id = $data[0]["bundle_id"];
|
197 |
+
$productIds = [];
|
198 |
+
$discountPrice = $data[0]["discountPrice"];
|
199 |
+
$totalPrice = $data[0]["totalPrice"];
|
200 |
+
$inStockProducts = [];
|
201 |
+
$outOfStockProducts = [];
|
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"]);
|
208 |
+
}
|
209 |
+
|
210 |
+
if(count($productIds) == 1 && $bundle_id == 0){
|
211 |
+
|
212 |
+
$quantity = $data[0]["params"][0]["qty"];
|
213 |
+
}
|
214 |
+
|
215 |
+
|
216 |
+
//Push the products into instock and out of stock arrays to handle the success and error messages at cart page
|
217 |
+
foreach ($productIds as $productId) {
|
218 |
+
$product = Mage::getModel('catalog/product');
|
219 |
+
$product->load($productId);
|
220 |
+
|
221 |
+
$inStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock();
|
222 |
+
if($inStock){
|
223 |
+
array_push($inStockProducts, $productId);
|
224 |
+
}
|
225 |
+
else{
|
226 |
+
array_push($outOfStockProducts, $productId);
|
227 |
+
//Prepare the error message for the products out of stock
|
228 |
+
$productErrorStr .= $product->getName().", ";
|
229 |
+
}
|
230 |
+
}
|
231 |
+
|
232 |
+
//Add all the instock products to the cart and prepare the success message
|
233 |
+
foreach ($inStockProducts as $product_id) {
|
234 |
+
$product = Mage::getModel('catalog/product');
|
235 |
+
$product->load($product_id);
|
236 |
+
|
237 |
+
$redirectUrl = $product->getProductUrl();
|
238 |
+
|
239 |
+
$this->cart->addProduct($product,array('qty' => $quantity));
|
240 |
+
$productSuccessStr .= $product->getName().", ";
|
241 |
+
}
|
242 |
+
|
243 |
+
//Trim the success message
|
244 |
+
$productSuccessStr = rtrim(trim($productSuccessStr),',');
|
245 |
+
|
246 |
+
//Trim the error message
|
247 |
+
$productErrorStr = rtrim(trim($productErrorStr),',');
|
248 |
+
|
249 |
+
//Save all the products added to the cart
|
250 |
+
$this->cart->save();
|
251 |
+
|
252 |
+
//Add the bundles to the database if all the products are in stock
|
253 |
+
if(count($outOfStockProducts) == 0 && count($productIds) > 1 && $bundle_id > 0){
|
254 |
+
|
255 |
+
$productIdsStr = implode(',',$productIds);
|
256 |
+
$cookieValue = Mage::getModel('core/cookie')->get('ivid');
|
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');
|
264 |
+
$userBundle->setBundleId(intval($bundle_id));
|
265 |
+
$userBundle->setProductIds($productIdsStr);
|
266 |
+
$userBundle->setIncreasinglyVisitorId($cookieValue);
|
267 |
+
$userBundle->setDiscountPrice($discountPrice);
|
268 |
+
$userBundle->setTotalPrice($totalPrice);
|
269 |
+
$userBundle->save();
|
270 |
+
}
|
271 |
+
|
272 |
+
//Set cart was updated flag
|
273 |
+
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
|
274 |
+
|
275 |
+
}
|
276 |
+
|
277 |
+
if($productSuccessStr != "")
|
278 |
+
Mage::getSingleton('core/session')->addSuccess($productSuccessStr.' added to your shopping cart');
|
279 |
+
|
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 |
+
|
296 |
+
}
|
297 |
+
}
|
app/code/community/Increasingly/Analytics/controllers/ProductsApiController.php
CHANGED
@@ -88,8 +88,9 @@ class Increasingly_Analytics_ProductsApiController extends Mage_Core_Controller_
|
|
88 |
} catch(Exception $e) {
|
89 |
|
90 |
Mage::log($e->getMessage(), null, 'Increasingly_Analytics.log');
|
|
|
91 |
$this->getResponse()
|
92 |
-
->setBody(json_encode(array('status' => 'error', 'message' =>
|
93 |
->setHttpResponseCode(500)
|
94 |
->setHeader('Content-type', 'application/json', true);
|
95 |
}
|
88 |
} catch(Exception $e) {
|
89 |
|
90 |
Mage::log($e->getMessage(), null, 'Increasingly_Analytics.log');
|
91 |
+
|
92 |
$this->getResponse()
|
93 |
+
->setBody(json_encode(array('status' => 'error', 'message' => $e->getMessage(), 'version' => $version)))
|
94 |
->setHttpResponseCode(500)
|
95 |
->setHeader('Content-type', 'application/json', true);
|
96 |
}
|
app/code/community/Increasingly/Analytics/controllers/ProductsApiController.php~
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
'description',
|
57 |
+
'short_description',
|
58 |
+
'color',
|
59 |
+
'weight',
|
60 |
+
'size'
|
61 |
+
);
|
62 |
+
|
63 |
+
$limit = $this->getRequest()->getParam('limit', 200);
|
64 |
+
$offset = $this->getRequest()->getParam('offset', 1);
|
65 |
+
|
66 |
+
$productsCollection = Mage::getModel('catalog/product')->getCollection();
|
67 |
+
|
68 |
+
$productsCollection->addAttributeToSelect($attributes)->getSelect()->limit($limit, $offset);
|
69 |
+
|
70 |
+
$totalProductCount = Mage::getModel('catalog/product')->getCollection()->count();
|
71 |
+
|
72 |
+
foreach($productsCollection as $product)
|
73 |
+
{
|
74 |
+
$product = $productFormatHelper->formatProductInfo($product);
|
75 |
+
|
76 |
+
if($product !== null)
|
77 |
+
{
|
78 |
+
$products[] = $product;
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
$this->getResponse()
|
83 |
+
->setBody(json_encode(array('products' => $products,'version' => $version, 'total_product_count' => $totalProductCount)))
|
84 |
+
->setHttpResponseCode(200)
|
85 |
+
->setHeader('Content-type', 'application/json', true);
|
86 |
+
|
87 |
+
|
88 |
+
} catch(Exception $e) {
|
89 |
+
|
90 |
+
Mage::log($e->getMessage(), null, 'Increasingly_Analytics.log');
|
91 |
+
|
92 |
+
$this->getResponse()
|
93 |
+
->setBody(json_encode(array('status' => 'error', 'message' => $e->getMessage(), 'version' => $version)))
|
94 |
+
->setHttpResponseCode(500)
|
95 |
+
->setHeader('Content-type', 'application/json', true);
|
96 |
+
}
|
97 |
+
|
98 |
+
return $this;
|
99 |
+
|
100 |
+
}
|
101 |
+
|
102 |
+
private function isRequestAuthorized()
|
103 |
+
{
|
104 |
+
$helper = Mage::helper('increasingly_analytics');
|
105 |
+
|
106 |
+
if ($helper->isEnabled())
|
107 |
+
{
|
108 |
+
$apiKey = $helper->getApiToken();
|
109 |
+
$version = (string)Mage::getConfig()->getModuleConfig("Increasingly_Analytics")->version;
|
110 |
+
|
111 |
+
// Check for api key
|
112 |
+
if(!$apiKey && strlen($apiKey) === 0) {
|
113 |
+
|
114 |
+
$this->getResponse()
|
115 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'API key is missing', 'version' => $version)))
|
116 |
+
->setHttpResponseCode(403)
|
117 |
+
->setHeader('Content-type', 'application/json', true);
|
118 |
+
return false;
|
119 |
+
}
|
120 |
+
|
121 |
+
$authKey = $this->getRequest()->getHeader('authKey');
|
122 |
+
|
123 |
+
if (!$authKey || strlen($authKey) == 0) {
|
124 |
+
$authKey = $this->getRequest()->getParam('authKey');
|
125 |
+
}
|
126 |
+
|
127 |
+
if (!$authKey) {
|
128 |
+
|
129 |
+
$this->getResponse()
|
130 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Error,Authorization header not found', 'version' => $version)))
|
131 |
+
->setHttpResponseCode(500)
|
132 |
+
->setHeader('Content-type', 'application/json', true);
|
133 |
+
return false;
|
134 |
+
}
|
135 |
+
|
136 |
+
if(trim($authKey) !== trim($apiKey)) {
|
137 |
+
|
138 |
+
$this->getResponse()
|
139 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Authorization failed', 'version' => $version)))
|
140 |
+
->setHttpResponseCode(401)
|
141 |
+
->setHeader('Content-type', 'application/json', true);
|
142 |
+
return false;
|
143 |
+
}
|
144 |
+
|
145 |
+
return true;
|
146 |
+
}
|
147 |
+
else {
|
148 |
+
|
149 |
+
$this->getResponse()
|
150 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Increasingly module is disabled', 'version' => $version)))
|
151 |
+
->setHttpResponseCode(403)
|
152 |
+
->setHeader('Content-type', 'application/json', true);
|
153 |
+
return false;
|
154 |
+
}
|
155 |
+
|
156 |
+
}
|
157 |
+
|
158 |
+
}
|
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>
|
@@ -72,16 +72,7 @@
|
|
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>
|
32 |
<config>
|
33 |
<modules>
|
34 |
<Increasingly_Analytics>
|
35 |
+
<version>1.0.7</version>
|
36 |
</Increasingly_Analytics>
|
37 |
</modules>
|
38 |
<global>
|
72 |
<method>trackNewOrder</method>
|
73 |
</place_order>
|
74 |
</observers>
|
75 |
+
</sales_order_place_after>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
<sales_quote_collect_totals_after>
|
77 |
<observers>
|
78 |
<apply_cart_discount>
|
app/code/community/Increasingly/Analytics/etc/config.xml~
ADDED
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.4</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_quote_collect_totals_after>
|
77 |
+
<observers>
|
78 |
+
<apply_cart_discount>
|
79 |
+
<type>singleton</type>
|
80 |
+
<class>Increasingly_Analytics_Model_Observer</class>
|
81 |
+
<method>applyCartDiscount</method>
|
82 |
+
</apply_cart_discount>
|
83 |
+
</observers>
|
84 |
+
</sales_quote_collect_totals_after>
|
85 |
+
<sales_quote_save_after>
|
86 |
+
<observers>
|
87 |
+
<empty_cart>
|
88 |
+
<type>singleton</type>
|
89 |
+
<class>Increasingly_Analytics_Model_Observer</class>
|
90 |
+
<method>empty_cart</method>
|
91 |
+
</empty_cart>
|
92 |
+
</observers>
|
93 |
+
</sales_quote_save_after>
|
94 |
+
<catalog_product_save_commit_after>
|
95 |
+
<observers>
|
96 |
+
<product_update>
|
97 |
+
<type>singleton</type>
|
98 |
+
<class>Increasingly_Analytics_Model_Observer</class>
|
99 |
+
<method>productAddOrUpdate</method>
|
100 |
+
</product_update>
|
101 |
+
</observers>
|
102 |
+
</catalog_product_save_commit_after>
|
103 |
+
<catalog_product_delete_commit_after>
|
104 |
+
<observers>
|
105 |
+
<product_delete>
|
106 |
+
<type>singleton</type>
|
107 |
+
<class>Increasingly_Analytics_Model_Observer</class>
|
108 |
+
<method>productDelete</method>
|
109 |
+
</product_delete>
|
110 |
+
</observers>
|
111 |
+
</catalog_product_delete_commit_after>
|
112 |
+
<admin_system_config_changed_section_carriers>
|
113 |
+
<observers>
|
114 |
+
<import_shipping_details>
|
115 |
+
<type>singleton</type>
|
116 |
+
<class>Increasingly_Analytics_Model_Observer</class>
|
117 |
+
<method>importShippingDetails</method>
|
118 |
+
</import_shipping_details>
|
119 |
+
</observers>
|
120 |
+
</admin_system_config_changed_section_carriers>
|
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 |
+
<bundle>
|
131 |
+
<table>increasingly_analytics_bundle</table>
|
132 |
+
</bundle>
|
133 |
+
</entities>
|
134 |
+
</increasingly_analytics_mysql4>
|
135 |
+
</models>
|
136 |
+
<resources>
|
137 |
+
<increasingly_analytics_setup>
|
138 |
+
<setup>
|
139 |
+
<module>Increasingly_Analytics</module>
|
140 |
+
<class>Increasingly_Analytics_Model_Mysql4_Setup</class>
|
141 |
+
</setup>
|
142 |
+
<connection>
|
143 |
+
<use>core_setup</use>
|
144 |
+
</connection>
|
145 |
+
</increasingly_analytics_setup>
|
146 |
+
<increasingly_analytics_write>
|
147 |
+
<connection>
|
148 |
+
<use>core_write</use>
|
149 |
+
</connection>
|
150 |
+
</increasingly_analytics_write>
|
151 |
+
<increasingly_analytics_read>
|
152 |
+
<connection>
|
153 |
+
<use>core_read</use>
|
154 |
+
</connection>
|
155 |
+
</increasingly_analytics_read>
|
156 |
+
</resources>
|
157 |
+
<blocks>
|
158 |
+
<increasingly_analytics>
|
159 |
+
<class>Increasingly_Analytics_Block</class>
|
160 |
+
</increasingly_analytics>
|
161 |
+
</blocks>
|
162 |
+
<helpers>
|
163 |
+
<increasingly_analytics>
|
164 |
+
<class>Increasingly_Analytics_Helper</class>
|
165 |
+
</increasingly_analytics>
|
166 |
+
</helpers>
|
167 |
+
</global>
|
168 |
+
<frontend>
|
169 |
+
<layout>
|
170 |
+
<updates>
|
171 |
+
<increasingly_analytics>
|
172 |
+
<file>increasingly_analytics.xml</file>
|
173 |
+
</increasingly_analytics>
|
174 |
+
</updates>
|
175 |
+
</layout>
|
176 |
+
<routers>
|
177 |
+
<increasingly_analytics>
|
178 |
+
<use>standard</use>
|
179 |
+
<args>
|
180 |
+
<module>Increasingly_Analytics</module>
|
181 |
+
<frontName>increasingly</frontName>
|
182 |
+
</args>
|
183 |
+
</increasingly_analytics>
|
184 |
+
</routers>
|
185 |
+
<events>
|
186 |
+
<customer_login>
|
187 |
+
<observers>
|
188 |
+
<increasingly_login>
|
189 |
+
<type>singleton</type>
|
190 |
+
<class>Increasingly_Analytics_Model_Observer</class>
|
191 |
+
<method>customerLogin</method>
|
192 |
+
</increasingly_login>
|
193 |
+
</observers>
|
194 |
+
</customer_login>
|
195 |
+
</events>
|
196 |
+
</frontend>
|
197 |
+
<admin>
|
198 |
+
<routers>
|
199 |
+
<adminhtml>
|
200 |
+
<args>
|
201 |
+
<modules>
|
202 |
+
<Increasingly_Analytics before="Mage_adminhtml">Increasingly_Analytics_Adminhtml</Increasingly_Analytics>
|
203 |
+
</modules>
|
204 |
+
</args>
|
205 |
+
</adminhtml>
|
206 |
+
</routers>
|
207 |
+
</admin>
|
208 |
+
<adminhtml>
|
209 |
+
<acl>
|
210 |
+
<resources>
|
211 |
+
<admin>
|
212 |
+
<children>
|
213 |
+
<system>
|
214 |
+
<children>
|
215 |
+
<config>
|
216 |
+
<children>
|
217 |
+
<increasingly_analytics>
|
218 |
+
<title>Increasingly Configuration</title>
|
219 |
+
</increasingly_analytics>
|
220 |
+
</children>
|
221 |
+
</config>
|
222 |
+
</children>
|
223 |
+
</system>
|
224 |
+
</children>
|
225 |
+
</admin>
|
226 |
+
</resources>
|
227 |
+
</acl>
|
228 |
+
<layout>
|
229 |
+
<updates>
|
230 |
+
<increasingly_analytics>
|
231 |
+
<file>increasingly_analytics.xml</file>
|
232 |
+
</increasingly_analytics>
|
233 |
+
</updates>
|
234 |
+
</layout>
|
235 |
+
<menu>
|
236 |
+
<increasingly>
|
237 |
+
<title>Increasingly</title>
|
238 |
+
<sort_order>70</sort_order>
|
239 |
+
<action>adminhtml/DataIntegration/index</action>
|
240 |
+
</increasingly>
|
241 |
+
</menu>
|
242 |
+
</adminhtml>
|
243 |
+
<default>
|
244 |
+
<increasingly_analytics>
|
245 |
+
<settings>
|
246 |
+
<enable>0</enable>
|
247 |
+
</settings>
|
248 |
+
</increasingly_analytics>
|
249 |
+
</default>
|
250 |
+
</config>
|
app/code/community/Increasingly/Analytics/sql/increasingly_analytics_setup/mysql4-install-1.0.7.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~
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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="http://127.0.0.1/js/track.js";n.parentNode.insertBefore(r,n);};
|
44 |
+
|
45 |
+
window.increasingly.loadJs=function(){var t=document;var n=t.getElementsByTagName("script")[0];var r=t.createElement("script");
|
46 |
+
r.type="text/javascript";r.async=true;r.src="http://127.0.0.1/js/increasingly.js";n.parentNode.insertBefore(r,n);};
|
47 |
+
|
48 |
+
increasingly.load();
|
49 |
+
increasingly.loadJs();
|
50 |
+
<?php foreach ($events as $trackEvent) : ?>
|
51 |
+
|
52 |
+
<?php if($trackEvent['method'] == 'track') : ?>
|
53 |
+
increasingly.track("<?php echo $trackEvent['event_type']; ?>", "<?php echo base64_encode(json_encode($trackEvent)); ?>");
|
54 |
+
<?php endif; ?>
|
55 |
+
|
56 |
+
<?php endforeach; ?>
|
57 |
+
</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,13 @@ 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-08-
|
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="5040e70b54e323a88a319d4b8088a47c"/><file name="DateFormatter.php" hash="d8f963bd1f9fe390e038a2065fd5c4c4"/><file name="PriceFormatter.php" hash="9bc46d3afb4612131a29b9a1c2b82fad"/><file name="ProductFormatter.php" hash="4bb2579b007700a808cdcea4fdb978c8"/></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="f069d141e1bdae7c18a711b04aafa996"/><file name="Product.php" hash="f473c25a470a2509b00a4a15ed8b857f"/></dir><dir name="controllers"><file name="AddbundletocartController.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.7</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>Fix for redirecting to same product page, if entered qty for product is more than available.
|
48 |
+

|
49 |
+
Fix for redundant tracking of new orders.</notes>
|
50 |
<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>
|
51 |
+
<date>2016-08-04</date>
|
52 |
+
<time>14:00:04</time>
|
53 |
+
<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="5040e70b54e323a88a319d4b8088a47c"/><file name="Data.php~" hash="ede50838de4fc53665c829bc3ef4e07c"/><file name="DateFormatter.php" hash="d8f963bd1f9fe390e038a2065fd5c4c4"/><file name="PriceFormatter.php" hash="9bc46d3afb4612131a29b9a1c2b82fad"/><file name="ProductFormatter.php" hash="4bb2579b007700a808cdcea4fdb978c8"/></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="8abc968469d1c8f1eee79925a26e2802"/><file name="Observer.php~" hash="f069d141e1bdae7c18a711b04aafa996"/><file name="Product.php" hash="f473c25a470a2509b00a4a15ed8b857f"/></dir><dir name="controllers"><file name="AddbundletocartController.php" hash="d9de59fcb68d0d27326f8ccfa24d1486"/><file name="AddbundletocartController.php~" hash="d9de59fcb68d0d27326f8ccfa24d1486"/><dir name="Adminhtml"><file name="DataIntegrationController.php" hash="0758d4716d337002a8c49f843e06cec2"/></dir><file name="ProductsApiController.php" hash="f6e9868dec4f496762bbeef51f9ee3bf"/><file name="ProductsApiController.php~" hash="f6e9868dec4f496762bbeef51f9ee3bf"/></dir><dir name="etc"><file name="config.xml" hash="e325bfebf76b9645d682714b0569de89"/><file name="config.xml~" hash="4137154b5643c28abbc48f230107ea13"/></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.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"/></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="4473f97cc5aa3a02bf0a87877b14b5eb"/><file name="track.phtml~" hash="e016135e7157214d85e905ebc0f3e1b3"/></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>
|
54 |
<compatible/>
|
55 |
<dependencies><required><php><min>5.2.0</min><max>7.0.7</max></php></required></dependencies>
|
56 |
</package>
|