Trackset - Version 1.0.0

Version Notes

Initial release

Download this release

Release Info

Developer Sevenlike
Extension Trackset
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Sevenlike/Trackset/Block/Tracksetcode.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sevenlike_Trackset_Block_Tracksetcode extends Mage_Core_Block_Text
4
+ {
5
+ public function __construct()
6
+ {
7
+ if (!isset($_SESSION["__sevenlike_trackset"])) $_SESSION["__sevenlike_trackset"] = array();
8
+ if (!isset($_SESSION["__sevenlike_trackset"]["cart"])) $_SESSION["__sevenlike_trackset"]["cart"] = array();
9
+ if (!isset($_SESSION["__sevenlike_trackset"]["order_to_send"])) $_SESSION["__sevenlike_trackset"]["order_to_send"] = null;
10
+
11
+ return parent::__construct();
12
+ }
13
+
14
+ /**
15
+ * @return array
16
+ */
17
+ protected function processCart()
18
+ {
19
+ $session = Mage::getSingleton("checkout/session");
20
+ $quote = $session->getQuote();
21
+
22
+ $modified = array();
23
+ foreach ($quote->getAllItems() as $item) {
24
+ $sku = $item->getSku();
25
+ if (!isset($_SESSION["__sevenlike_trackset"]["cart"][$sku])) {
26
+ $_SESSION["__sevenlike_trackset"]["cart"][$sku] = 0;
27
+ }
28
+
29
+ $qty_difference = $item->getQty() - $_SESSION["__sevenlike_trackset"]["cart"][$sku];
30
+ if ($qty_difference == 0) continue;
31
+
32
+ $modified[$sku] = $qty_difference;
33
+ $_SESSION["__sevenlike_trackset"]["cart"][$sku] = $item->getQty();
34
+ }
35
+
36
+ return $modified;
37
+ }
38
+
39
+ /**
40
+ * @return string
41
+ */
42
+ protected function _toHtml()
43
+ {
44
+ $account_id = Mage::getStoreConfig("trackset/config/account_id");
45
+ $client_version = Mage::getStoreConfig("trackset/config/client_version");
46
+ $enable_ecommerce_tracking = Mage::getStoreConfig("trackset/config/enable_ecommerce_tracking");
47
+ $referer = addslashes(@$_SERVER["HTTP_REFERER"]);
48
+
49
+ $https = isset($_SERVER["HTTPS"]) ? "s" : "";
50
+ $return = "<!-- Inizio Codice Conversion Lab -->";
51
+
52
+ switch ($client_version) {
53
+ case "5";
54
+ $return .= '
55
+ <script language="JavaScript" type="text/javascript">
56
+ var us="' . $account_id . '2";
57
+ </script>
58
+ <script language="JavaScript" src="http' . $https . '://conversionlab.trackset.com/track/tsend.js" type="text/javascript"></script>
59
+ <noscript>
60
+ <a href="http://www.trackset.it/">
61
+ <img alt="Web Analytics" src="http' . $https . '://conversionlab.trackset.com/track/cl.gif?md5=' . $account_id . '" />
62
+ </a>
63
+ </noscript>';
64
+ break;
65
+ default:
66
+ $return .= '<!-- TRACKSET CLIENT VERSION NOT SUPPORTED -->';
67
+ return $return;
68
+ }
69
+
70
+ if (!$enable_ecommerce_tracking) return $return;
71
+
72
+ $quote = Mage::getSingleton("checkout/session")->getQuote();
73
+ $quote_id = $quote->getId();
74
+ $products_still_in_cart = array();
75
+ foreach ($quote->getAllItems() as $item) {
76
+ $sku = $item->getSku();
77
+ $products_still_in_cart[] = $sku;
78
+ if (!isset($_SESSION["__sevenlike_trackset"]["cart"][$sku])) {
79
+ $_SESSION["__sevenlike_trackset"]["cart"][$sku] = 0;
80
+ }
81
+
82
+ $qty_difference = $item->getQty() - $_SESSION["__sevenlike_trackset"]["cart"][$sku];
83
+ if ($qty_difference == 0) continue;
84
+
85
+ $name = addslashes($item->getName());
86
+ $category = $item->getProduct()->getCategoryIds();
87
+ if ($category) {
88
+ $category = $category[0];
89
+ $category = Mage::getModel('catalog/category')->load($category)->getName();
90
+ $category = addslashes($category);
91
+ } else {
92
+ $category = "";
93
+ }
94
+
95
+ $return .= "<script language='JavaScript' type='text/javascript'>sendevent('_addItem', '$quote_id', '$sku', '$name', '$category', '{$item->getCalculationPrice()}', {$item->getQty()}, '$referer');</script>";
96
+ $_SESSION["__sevenlike_trackset"]["cart"][$sku] = $item->getQty();
97
+ }
98
+
99
+ foreach($_SESSION["__sevenlike_trackset"]["cart"] as $sku=>$qty) {
100
+ if (!in_array($sku, $products_still_in_cart)) {
101
+ unset($_SESSION["__sevenlike_trackset"]["cart"][$sku]);
102
+ $product = Mage::getModel("catalog/product")->load($sku, "sku");
103
+ $return .= "<script language='JavaScript' type='text/javascript'>sendevent('_addItem', '$quote_id', '$sku', '', '', '{$product->getPrice()}', 0, '$referer');</script>";
104
+ }
105
+ }
106
+
107
+ if ($_SESSION["__sevenlike_trackset"]["order_to_send"]) {
108
+ $order = Mage::getModel("sales/order")->loadByIncrementId($_SESSION["__sevenlike_trackset"]["order_to_send"]);
109
+ $shipping_address = $order->getShippingAddress();
110
+ $city = addslashes($shipping_address->getCity());
111
+ $return .= "<script language='JavaScript' type='text/javascript'>sendevent('_addTransaction', '{$order->getIncrementId()}', '{$order->getQuoteId()}', '{$order->getGrandTotal()}', '{$order->getTaxAmount()}', '{$order->getShippingAmount()}', 1, '{$shipping_address->getCountryId()}','$city');</script>";
112
+ unset($_SESSION["__sevenlike_trackset"]["order_to_send"]);
113
+ }
114
+
115
+ $return .= "<!-- Fine Codice Conversion Lab -->";
116
+ return $return;
117
+ }
118
+ }
app/code/local/Sevenlike/Trackset/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Sevenlike_Trackset_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+
app/code/local/Sevenlike/Trackset/Model/Adminhtml/System/Source/Clientversions.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sevenlike_Trackset_Model_Adminhtml_System_Source_Clientversions
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array(
9
+ "label" => 5,
10
+ "value" => 5
11
+ ),
12
+ array(
13
+ "label" => 6,
14
+ "value" => 6
15
+ ),
16
+ );
17
+ }
18
+ }
app/code/local/Sevenlike/Trackset/Model/Adminhtml/System/Source/Yesno.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sevenlike_Trackset_Model_Adminhtml_System_Source_Yesno
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array(
9
+ "label" => "Yes",
10
+ "value" => 1
11
+ ),
12
+ array(
13
+ "label" => "No",
14
+ "value" => 0
15
+ ),
16
+ );
17
+ }
18
+ }
app/code/local/Sevenlike/Trackset/Model/Observer.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Sevenlike_Trackset_Model_Observer
4
+ {
5
+ public function orderIsConfirmed($observer)
6
+ {
7
+ try {
8
+ $_SESSION["__sevenlike_trackset"]["order_to_send"] = $observer->getEvent()->getOrder()->getIncrementId();
9
+ } catch (Exception $e) {}
10
+
11
+ unset($_SESSION["__sevenlike_trackset"]["cart"]);
12
+ }
13
+ }
app/code/local/Sevenlike/Trackset/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <trackset translate="title" module="trackset">
12
+ <title>Trackset Section</title>
13
+ <sort_order>100</sort_order>
14
+ </trackset>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/local/Sevenlike/Trackset/etc/config.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sevenlike_Trackset>
5
+ <version>0.1.0</version>
6
+ </Sevenlike_Trackset>
7
+ </modules>
8
+ <frontend>
9
+ <layout>
10
+ <updates>
11
+ <trackset>
12
+ <file>trackset.xml</file>
13
+ </trackset>
14
+ </updates>
15
+ </layout>
16
+ </frontend>
17
+ <global>
18
+ <blocks>
19
+ <trackset>
20
+ <class>Sevenlike_Trackset_Block</class>
21
+ </trackset>
22
+ </blocks>
23
+ <helpers>
24
+ <trackset>
25
+ <class>Sevenlike_Trackset_Helper</class>
26
+ </trackset>
27
+ </helpers>
28
+ <events>
29
+ <sales_order_place_after>
30
+ <observers>
31
+ <tracksetplaceorderafter>
32
+ <type>singleton</type>
33
+ <class>Sevenlike_Trackset_Model_Observer</class>
34
+ <method>orderIsConfirmed</method>
35
+ </tracksetplaceorderafter>
36
+ </observers>
37
+ </sales_order_place_after>
38
+ </events>
39
+ </global>
40
+ </config>
app/code/local/Sevenlike/Trackset/etc/system.xml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <trackset translate="label" module="trackset">
5
+ <label>Trackset</label>
6
+ <tab>general</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>10000</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <config translate="label">
14
+ <label>Trackset configuration</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>0</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <account_id translate="label">
22
+ <label>Account ID</label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>10</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ <comment><![CDATA[You can find your account ID under Trackset ConversionLab console -> Account -> Account & login -> Track Code]]></comment>
29
+ </account_id>
30
+ <client_version translate="label">
31
+ <label>Client version</label>
32
+ <frontend_type>select</frontend_type>
33
+ <source_model>Sevenlike_Trackset_Model_Adminhtml_System_Source_Clientversions</source_model>
34
+ <sort_order>20</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </client_version>
39
+ <enable_ecommerce_tracking>
40
+ <label>Enable e-commerce tracking</label>
41
+ <frontend_type>select</frontend_type>
42
+ <source_model>Sevenlike_Trackset_Model_Adminhtml_System_Source_Yesno</source_model>
43
+ <sort_order>30</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ </enable_ecommerce_tracking>
48
+ </fields>
49
+ </config>
50
+ </groups>
51
+ </trackset>
52
+ </sections>
53
+ </config>
app/design/frontend/base/default/layout/trackset.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="before_body_end">
5
+ <block type="trackset/tracksetcode" name="trackset_code" as="trackset_code" />
6
+ </reference>
7
+ </default>
8
+ </layout>
app/etc/modules/Sevenlike_Trackset.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sevenlike_Trackset>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <version>0.1.0</version>
8
+ </Sevenlike_Trackset>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Trackset</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/academic.php">Academic Free License (AFL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Enables integration between Magento and Trackset Conversionlab.</summary>
10
+ <description>It supports general tracking, add/remove items to/from cart and completed transaction tracking.</description>
11
+ <notes>Initial release</notes>
12
+ <authors><author><name>Sevenlike</name><user>sevenlike</user><email>info@sevenlike.com</email></author></authors>
13
+ <date>2012-10-02</date>
14
+ <time>09:23:10</time>
15
+ <contents><target name="magelocal"><dir name="Sevenlike"><dir name="Trackset"><dir name="Block"><file name="Tracksetcode.php" hash="62734a08282d472ff5553cbf9e86b8fb"/></dir><dir name="Helper"><file name="Data.php" hash="dc259d6db79493ea84cfc7d0844ec10c"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="System"><dir name="Source"><file name="Clientversions.php" hash="6e1a8768b2fec142073c83b0fa3b0a63"/><file name="Yesno.php" hash="7932f569dbd03025c4937a29933bba7f"/></dir></dir></dir><file name="Observer.php" hash="496d0dfbf83294f7f4c0bc53e7c6b26e"/></dir><dir name="etc"><file name="adminhtml.xml" hash="e6d2eff3a220b86bf9c9626e8d4d2e95"/><file name="config.xml" hash="532ccfde3c6a572842bcb8ead58aec0b"/><file name="system.xml" hash="ad3eb40787b94316a121d02fc427e45a"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sevenlike_Trackset.xml" hash="6c21042b7e6ed972262bb1ec4ea11e67"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="trackset.xml" hash="77bd8b22e1623c74c24f16ba1e8c95fc"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>