Smartify_Smartify - Version 1.0.0

Version Notes

This is a stable and tested version

Download this release

Release Info

Developer Thomas Pouncy
Extension Smartify_Smartify
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Smartify/.DS_Store ADDED
Binary file
app/code/local/Smartify/Smartify/Helper/Data.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Created on Oct 26, 2011
4
+ *
5
+ * To change the template for this generated file go to
6
+ * Window - Preferences - PHPeclipse - PHP - Code Templates
7
+ */
8
+ class Smartify_Smartify_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {
10
+
11
+ }
12
+ ?>
app/code/local/Smartify/Smartify/Model/Config.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Smartify_Smartify_Model_Config extends Mage_Core_Model_Abstract
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value' => "https://api.getsmartifystaging.com", 'label' => 'Staging'),
8
+ array('value' => "http://api.getsmartifydev.com:3000", 'label' => 'Development'),
9
+ array('value' => "https://api.getsmartify.com", 'label' => 'Production')
10
+ );
11
+ }
12
+
13
+
14
+ }
app/code/local/Smartify/Smartify/Model/Observer.php ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Smartify_Smartify_Model_Observer extends Mage_Core_Model_Abstract
3
+ {
4
+ const SMARTIFY_EXTENSION_VERSION = "1.0.0";
5
+ const SMARTIFY_EXTENSION_STORE = "magento";
6
+ const SMARTIFY_EXTENSION_DOMAIN = "https://api.getsmartify.com";
7
+ const SMARTIFY_API_VERSION = 1;
8
+ const SMARTIFY_MAGENTO_PATH = "/api/v1/retail/orders/";
9
+ const SMARTIFY_OAUTH_TOKEN_PATH = "/oauth/token";
10
+
11
+
12
+ function domain_name(){
13
+ if(Mage::getStoreConfig('smartify_options/setup/endpoint') == null){
14
+ return "" . self::SMARTIFY_EXTENSION_DOMAIN;
15
+ } else {
16
+ return "" . Mage::getStoreConfig('smartify_options/setup/endpoint');
17
+ }
18
+ }
19
+
20
+ function api_url($action_name){
21
+ return "" . $this->domain_name() . self::SMARTIFY_MAGENTO_PATH . $action_name;
22
+ }
23
+
24
+
25
+ // Get the Oauth Access token
26
+ function get_oauth_access_token(){
27
+ $url = "" . $this->domain_name() . self::SMARTIFY_OAUTH_TOKEN_PATH;
28
+ $access_key = Mage::getStoreConfig('smartify_options/setup/oauth_access_key');
29
+ $secret_key = Mage::getStoreConfig('smartify_options/setup/oauth_secret');
30
+
31
+ $data = array();
32
+ $data['grant_type'] = "client_credentials";
33
+ $data['client_id'] = $access_key;
34
+ $data['client_secret'] = $secret_key;
35
+
36
+ $ch = curl_init($url);
37
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
38
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
39
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
40
+
41
+ $result = json_decode(curl_exec($ch));
42
+
43
+ return $result->{'access_token'};
44
+ }
45
+
46
+ // Do a POST sending data as a json object
47
+ function do_json_post_request($url, $data){
48
+ $token = $this->get_oauth_access_token();
49
+ $data_string = json_encode($data);
50
+
51
+ $ch = curl_init($url);
52
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
53
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
54
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
55
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
56
+ 'Content-Type: application/json',
57
+ 'Content-Length: ' . strlen($data_string),
58
+ 'Authorization: Bearer ' . $token
59
+ ));
60
+
61
+ $result = curl_exec($ch);
62
+ return $observer;
63
+ }
64
+
65
+ // will take a category id and output the category tree for the leaf category
66
+ function getParentCategories($cat_id){
67
+ $cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($cat_id);
68
+ $parent_cat = $cat->getParentCategory();
69
+ if($parent_cat->getLevel() <= 1){
70
+ return '' . $cat->getName();
71
+ } else {
72
+ $str = $this->getParentCategories($parent_cat->getId());
73
+ return $str . '/' . $cat->getName();
74
+ }
75
+ }
76
+
77
+ // data sent with a shopping cart object
78
+ function quoteData($quote){
79
+ $cart_data = array();
80
+ $cart_data['id'] = $quote->getId();
81
+ $cart_data['total_price_before_discounts'] = $quote->getBaseSubtotal();
82
+ $cart_data['total_price_after_discounts'] = $quote->getBaseSubtotalWithDiscount();
83
+ $cart_data['currency'] = $quote->getBaseCurrencyCode();
84
+ $cart_data['is_active'] = $quote->getIsActive();
85
+ $cart_items = array();
86
+ foreach($quote->getAllItems() as $item) {
87
+ $node = array();
88
+ $prod = $item->getProduct();
89
+ if($item->getParentItemId() == null){
90
+ $node['name'] = $item->getName();
91
+ $node['sku'] = $item->getSku();
92
+ $node['description'] = trim( preg_replace( '/\s+/', ' ', strip_tags(Mage::getModel('catalog/product')->load($prod->getId())->getDescription()) ) );
93
+ $node['qty'] = (int)$item->getQty();
94
+ $categories = array();
95
+ foreach ($prod->getCategoryIds() as $category_id) {
96
+ $categories[] = $this->getParentCategories($category_id);
97
+ }
98
+ $node['categories'] = array_unique($categories);
99
+ $node['unit_price'] = $item->getBasePrice();
100
+ $node['total_price_before_discounts'] = null;
101
+ $node['total_price_after_discounts'] = $item->getBaseRowTotal();
102
+ $node['currency'] = $quote->getBaseCurrencyCode();
103
+
104
+ $cart_items[] = $node;
105
+ }
106
+ }
107
+
108
+ $cart_data['items'] = $cart_items;
109
+ return $cart_data;
110
+ }
111
+
112
+ function orderData($order){
113
+ $order_data = array();
114
+ $order_data['id'] = $order->getId();
115
+ $order_data['grand_total'] = $order->getBaseGrandTotal();
116
+ $order_data['subtotal'] = $order->getBaseSubtotal();
117
+ $order_data['shipping_cost'] = $order->getBaseShippingAmount();
118
+ $order_data['tax_amount'] = $order->getBaseTaxAmount();
119
+ $order_data['currency'] = $order->getBaseCurrencyCode();
120
+ $order_data['cart_id'] = $order->getQuoteId();
121
+ $order_data['status'] = $order->getStatus();
122
+ $order_data['state'] = $order->getState();
123
+ return $order_data;
124
+ }
125
+
126
+ function userData(){
127
+ $user_data = array();
128
+ $user_data['id'] = Mage::getSingleton('customer/session')->getCustomer()->getId();
129
+ $user_data['checkout_session_id'] = Mage::getSingleton('checkout/session')->getSessionId();
130
+ return $user_data;
131
+ }
132
+
133
+ function generalData(){
134
+ $gen_data = array();
135
+ $gen_data['smartify_config_id'] = Mage::getStoreConfig('smartify_options/setup/config_id');
136
+ $gen_data['time'] = time();
137
+ $gen_data['smartify_extension_version'] = self::SMARTIFY_EXTENSION_VERSION;
138
+ $gen_data['smartify_extension_platform'] = self::SMARTIFY_EXTENSION_STORE;
139
+ $gen_data['smartify_api_version'] = self::SMARTIFY_API_VERSION;
140
+ return $gen_data;
141
+ }
142
+
143
+ // Callback for updating a cart
144
+ public function updateQuote($observer){
145
+ if(Mage::getStoreConfig('smartify_options/setup/enabled') == true){
146
+ if (isset($observer['quote']) && ($observer['quote']->getIsActive() != false)) {
147
+ $data = array();
148
+ $data['general'] = $this->generalData();
149
+ $data['user'] = $this->userData();
150
+ $data['cart'] = $this->quoteData($observer['quote']);
151
+
152
+ $url = $this->api_url("cart_changed");
153
+ $this->do_json_post_request($url, $data);
154
+ }
155
+ }
156
+ return $observer;
157
+ }
158
+
159
+ // Callback for updating an order
160
+ public function updateOrder($observer){
161
+ if(Mage::getStoreConfig('smartify_options/setup/enabled') == true){
162
+ if (isset($observer['order'])) {
163
+ $data = array();
164
+ $quote = Mage::getModel('sales/quote')->load($observer['order']->getQuoteId());
165
+ $data['general'] = $this->generalData();
166
+ $data['user'] = $this->userData();
167
+ $data['cart'] = $this->quoteData($quote);
168
+ $data['order'] = $this->orderData($observer['order']);
169
+
170
+ $url = $this->api_url("order_changed");
171
+ $this->do_json_post_request($url, $data);
172
+ }
173
+ }
174
+ return $observer;
175
+ }
176
+
177
+
178
+
179
+ }
180
+ ?>
app/code/local/Smartify/Smartify/etc/adminhtml.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <acl>
3
+ <resources>
4
+ <admin>
5
+ <children>
6
+ <system>
7
+ <children>
8
+ <config>
9
+ <children>
10
+ <smartify_options>
11
+ <title>Smartify Configuration</title>
12
+ </smartify_options>
13
+ </children>
14
+ </config>
15
+ </children>
16
+ </system>
17
+ </children>
18
+ </admin>
19
+ </resources>
20
+ </acl>
21
+ </config>
app/code/local/Smartify/Smartify/etc/config.xml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Smartify_Smartify>
4
+ <version>0.1.0</version>
5
+ </Smartify_Smartify>
6
+ </modules>
7
+
8
+ <frontend>
9
+ <layout>
10
+ <updates>
11
+ <smartify>
12
+ <file>smartify.xml</file>
13
+ </smartify>
14
+ </updates>
15
+ </layout>
16
+ </frontend>
17
+
18
+
19
+ <global>
20
+ <helpers>
21
+ <smartify>
22
+ <class>Smartify_Smartify_Helper</class>
23
+ </smartify>
24
+ </helpers>
25
+ <events>
26
+
27
+ <sales_quote_save_after>
28
+ <observers>
29
+ <smartify_smartify_observer>
30
+ <type>singleton</type>
31
+ <class>Smartify_Smartify_Model_Observer</class>
32
+ <method>updateQuote</method>
33
+ </smartify_smartify_observer>
34
+ </observers>
35
+ </sales_quote_save_after>
36
+
37
+ <sales_order_save_after>
38
+ <observers>
39
+ <smartify_smartify_observer>
40
+ <type>singleton</type>
41
+ <class>Smartify_Smartify_Model_Observer</class>
42
+ <method>updateOrder</method>
43
+ </smartify_smartify_observer>
44
+ </observers>
45
+ </sales_order_save_after>
46
+
47
+
48
+ </events>
49
+ </global>
50
+
51
+ </config>
app/code/local/Smartify/Smartify/etc/system.xml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <tabs>
3
+ <smartifyconfig translate="label" module="smartify">
4
+ <label>Smartify</label>
5
+ <sort_order>99999</sort_order>
6
+ </smartifyconfig>
7
+ </tabs>
8
+ <sections>
9
+ <smartify_options translate="label" module="smartify">
10
+ <label>Smartify Configuration</label>
11
+ <tab>smartifyconfig</tab>
12
+ <frontend_type>text</frontend_type>
13
+ <sort_order>1000</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+
18
+ <groups>
19
+ <setup translate="label">
20
+ <label>General Configuration</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <enabled>
28
+ <label>Enabled</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>10</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </enabled>
36
+ <endpoint translate="label">
37
+ <label>Endpoint</label>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>10</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>1</show_in_website>
42
+ <show_in_store>1</show_in_store>
43
+ </endpoint>
44
+ <config_id>
45
+ <label>Smartify Config ID</label>
46
+ <comment>
47
+ <![CDATA[You should be given this value from your Smartify Contact.]]>
48
+ </comment>
49
+ <frontend_type>text</frontend_type>
50
+ <sort_order>1</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>1</show_in_store>
54
+ </config_id>
55
+
56
+ <oauth_access_key>
57
+ <label>Smartify OAuth Access Key</label>
58
+ <comment>
59
+ <![CDATA[You should be given this value from your Smartify Contact. Do not share it with anyone!]]>
60
+ </comment>
61
+ <frontend_type>text</frontend_type>
62
+ <sort_order>5</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ </oauth_access_key>
67
+
68
+ <oauth_secret>
69
+ <label>Smartify OAuth Secret</label>
70
+ <comment>
71
+ <![CDATA[You should be given this value from your Smartify Contact. Do not share it with anyone!]]>
72
+ </comment>
73
+ <frontend_type>text</frontend_type>
74
+ <sort_order>6</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>1</show_in_website>
77
+ <show_in_store>1</show_in_store>
78
+ </oauth_secret>
79
+
80
+ </fields>
81
+ </setup>
82
+ </groups>
83
+
84
+ </smartify_options>
85
+ </sections>
86
+ </config>
app/design/frontend/base/default/layout/smartify.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <layout version="0.1.0">
2
+ <default>
3
+ <reference name="head">
4
+ <block type="page/html" name="smartify_widget" template="smartify/smartify/widget.phtml" />
5
+ </reference>
6
+ </default>
7
+ </layout>
app/design/frontend/base/default/template/smartify/smartify/widget.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php if(Mage::getStoreConfig('smartify_options/setup/enabled') == true){ ?>
2
+
3
+ <?php if(Mage::getStoreConfig('smartify_options/setup/endpoint') == null){ ?>
4
+ <script type="text/javascript" src="http://widget.getsmartify.com/widget/shareandtell_widget.js?config_id=<?php echo Mage::getStoreConfig('smartify_options/setup/config_id'); ?>&external_user_session=<?php echo Mage::getSingleton('checkout/session')->getSessionId(); ?>" id="shareandtell_script_1"></script>
5
+ <?php } else { ?>
6
+ <script type="text/javascript" src="<?php echo Mage::getStoreConfig('smartify_options/setup/endpoint'); ?>/widget/shareandtell_widget.js?config_id=<?php echo Mage::getStoreConfig('smartify_options/setup/config_id'); ?>&external_user_session=<?php echo Mage::getSingleton('checkout/session')->getSessionId(); ?>" id="shareandtell_script_1"></script>
7
+ <?php } ?>
8
+ <?php } ?>
app/etc/modules/Smartify_Smartify.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Smartify_Smartify>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ </Smartify_Smartify>
7
+ </modules>
8
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Smartify_Smartify</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This plugin installs and integrates the Smartify widget into your ecommerce site, which helps you to maximize the efficiency of your ad-spend</summary>
10
+ <description>Smartify provides a technology platform to help clients maximize the efficiency of their digital marketing spend by identifying key e-commerce goals, testing various online user experiences and discovering which customer interactions help move our client towards their stated goals. We can help answer questions like "when and how should we interact with our customers to increase their likelihood of purchase?", "can we improve sales of key items without relying on price reductions?", and "which elements of our online shopping experience lead to higher average lifetime value among our specific customer demographic?", just to give a few examples. We build our user experiences by designing and executing complete incentivized campaigns with our specially built tools and years of industry experience. </description>
11
+ <notes>This is a stable and tested version</notes>
12
+ <authors><author><name>Thomas Pouncy</name><user>smartify</user><email>thomas@getsmartify.com</email></author></authors>
13
+ <date>2015-02-04</date>
14
+ <time>17:45:26</time>
15
+ <contents><target name="magelocal"><dir name="Smartify"><dir name="Smartify"><dir name="Helper"><file name="Data.php" hash="2e9d5e12ac8b3fd06f369c9f15bd4b58"/></dir><dir name="Model"><file name="Config.php" hash="b89512d295c9519dbadb43d81e4eeb55"/><file name="Observer.php" hash="a56ebcce596004927ad22e0bd7d02db3"/></dir><dir name="etc"><file name="adminhtml.xml" hash="f9ba98b92c3008a9dc39d007de7ad3ef"/><file name="config.xml" hash="02475487a61431cab42fbcb924481530"/><file name="system.xml" hash="a7294710f0c83051a52397933a01a51d"/></dir></dir><file name=".DS_Store" hash="0be08eb12e189cb860893cbd2b5dcfa1"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="smartify"><dir name="smartify"><file name="widget.phtml" hash="ed3699da17ae5215e34ab624e13615fe"/></dir></dir></dir><dir name="layout"><file name="smartify.xml" hash="f31117b5e8260b08b161a7e27209adf9"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Smartify_Smartify.xml" hash="9998550331270e6248f202bc747ef8fc"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.4.0</min><max>5.6.4</max></php></required></dependencies>
18
+ </package>