Adestra_MFAbandonedCart - Version 1.0.2

Version Notes

Repackaged as stable.

Download this release

Release Info

Developer Anna Grieve
Extension Adestra_MFAbandonedCart
Version 1.0.2
Comparing to
See all releases


Version 1.0.2

app/code/local/Adestra/MFAbandonedCart/Block/Checkout.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Adestra_MFAbandonedCart_Block_Checkout extends Mage_Core_Block_Template
4
+ {
5
+ // necessary methods
6
+ }
7
+
8
+ ?>
app/code/local/Adestra/MFAbandonedCart/Helper/Data.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Adestra_MFAbandonedCart_Helper
4
+ */
5
+
6
+ class Adestra_MFAbandonedCart_Helper_Data extends Mage_Core_Helper_Abstract{
7
+
8
+
9
+ public function updateCall() {
10
+ return $this->_createCall('update');
11
+ }
12
+
13
+ public function purchaseCall() {
14
+ return $this->_createCall('purchase');
15
+ }
16
+
17
+
18
+ private function _createCall($type = 'update') {
19
+ $url = NULL;
20
+ if (Mage::getStoreConfig('adestra/mfabandonedcart/enabled')) {
21
+ $conversion = Mage::getModel('mfabandonedcart/conversion');
22
+ if ($type == 'update') $conversion->updateCart();
23
+ if ($type == 'purchase') $conversion->checkoutPurchase();
24
+ if ($type == 'purchase' || ($type == 'update' && $conversion->getItemsCount() > 0)) {
25
+ // only build url when purchase call or non empty cart items list.
26
+ $url = $conversion->buildUrl($type);
27
+ if (Mage::getStoreConfig('adestra/mfabandonedcart/debug')) {
28
+ Mage::Log($conversion->_getFullData());
29
+ Mage::Log($url);
30
+ }
31
+ }
32
+ return $this->_formatHtml($url);
33
+ }
34
+
35
+ }
36
+
37
+
38
+ private function _formatHtml($url = NULL) {
39
+ $output = '<div id="mfabandonedcart-conversion" style="display:hidden">';
40
+ if (!empty($url)) {
41
+ $output .= '<img src="'.$url.'" width="0" height="0"></div>';
42
+ }
43
+ $output .= '</div>';
44
+ return $output;
45
+
46
+ }
47
+
48
+ }
app/code/local/Adestra/MFAbandonedCart/Model/Conversion.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Adestra_MFAbandonedCart_Model_Conversion {
3
+
4
+
5
+ private $client_domain;
6
+ private $capture_id; // Basket ID ??
7
+ private $account_id; // MF Client account ID
8
+ private $token; // Magento session
9
+ private $record; // Customer details
10
+ private $email;
11
+ private $order_value;
12
+ private $items; // Array of items
13
+
14
+
15
+ function __construct() {
16
+ $this->account_id = NULL;
17
+ $this->client_domain = NULL;
18
+ $this->capture_id = NULL;
19
+ $this->record = array();
20
+ $this->email = NULL;
21
+ $this->order_value = NULL;
22
+ $this->items = array();
23
+ $this->_updateBasics();
24
+ }
25
+
26
+ private function _updateBasics() {
27
+ $this->account_id = Mage::getStoreConfig('adestra/mfabandonedcart/accountid');
28
+ $this->capture_id = Mage::getStoreConfig('adestra/mfabandonedcart/captureid');
29
+ $this->client_domain = Mage::getStoreConfig('adestra/mfabandonedcart/clientdomain');
30
+ $this->token = Mage::getSingleton("customer/session")->getEncryptedSessionId();
31
+
32
+ }
33
+
34
+ public function updateCart() {
35
+
36
+ // Cart items.
37
+ $this->items = array();
38
+ $cart = Mage::getModel('checkout/cart')->getQuote();
39
+ foreach ($cart->getAllVisibleItems() as $item) {
40
+ $conversion_item = array();
41
+ $conversion_item['ref'] = $item->getProduct()->getSku();
42
+ $conversion_item['value'] = number_format($item->getProduct()->getPrice(), 2, '.', '');
43
+ $conversion_item['name'] = $item->getProduct()->getName();
44
+ $conversion_item['quantity'] = $item->getQty();
45
+ $conversion_item['image_url'] = urlencode($item->getProduct()->getThumbnailUrl());
46
+ $this->items[] = $conversion_item;
47
+ }
48
+
49
+
50
+ // Customer details
51
+ $this->email = $cart->getCustomerEmail();
52
+ $additional_core_fields = explode("\n",Mage::getStoreConfig('adestra/mfabandonedcart/additionalcorefields'));
53
+ $this->record = array();
54
+ foreach($additional_core_fields as $field) {
55
+ $field = trim($field," \r");
56
+ $field = explode("|",$field);
57
+ switch ($field[0]) {
58
+ case 'prefix':
59
+ if ($cart->getCustomerPrefix()) $this->record[$field[1]] = $cart->getCustomerPrefix();
60
+ break;
61
+ case 'firstname':
62
+ if ($cart->getCustomerFirstname()) $this->record[$field[1]] = $cart->getCustomerFirstname();
63
+ break;
64
+ case 'lastname':
65
+ if ($cart->getCustomerLastname()) $this->record[$field[1]] = $cart->getCustomerLastname();
66
+ break;
67
+ case 'company':
68
+ if ($cart->getBillingAddress()->getCompany()) $this->record[$field[1]] = $cart->getBillingAddress()->getCompany();
69
+ break;
70
+ }
71
+ }
72
+ $this->order_value = number_format($cart->getGrandTotal(), 2, '.', '');
73
+
74
+ }
75
+
76
+ public function checkoutPurchase() {
77
+
78
+ // $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
79
+ // $this->items = array();
80
+ //
81
+ // foreach ($order->getAllVisibleItems() as $item) {
82
+ // $conversion_item = array();
83
+ // $conversion_item['ref'] = $item->getSku();
84
+ // $conversion_item['value'] = number_format($item->getPrice(), 2, '.', '');
85
+ // $conversion_item['name'] = $item->getName();
86
+ // $conversion_item['quantity'] = $item->getQtyToInvoice();
87
+ // $this->items[] = $conversion_item;
88
+ // }
89
+ //
90
+ // // Customer details.
91
+ // $this->email = $order->getCustomerEmail();
92
+ // $this->order_value = number_format($order->getGrandTotal(), 2, '.', '');
93
+
94
+
95
+
96
+ }
97
+
98
+ // Helper function to return array of objects
99
+ public function _getFullData() {
100
+ return get_object_vars($this);
101
+ }
102
+
103
+ /*
104
+ * Build url as per documentation: http://new.adestra.com/doc/page/current/index/conversion-captures/capture-implementation
105
+ * Note image urls need to be urlencoded before and item is json encoded.
106
+ */
107
+ public function buildUrl($action = 'update') {
108
+
109
+ $url = $this->client_domain.'q/basket?action='.$action
110
+ .'&account_id='.$this->account_id
111
+ .'&capture_id='.$this->capture_id
112
+ .'&token='.$this->token;
113
+
114
+ if ($action == 'update') {
115
+ $url .= '&email='.$this->email.'&order_value='.$this->order_value;
116
+
117
+ if(!empty($this->record)) {
118
+ $url .= '&record='.str_replace('"','%22',json_encode($this->record));
119
+ }
120
+
121
+ if(!empty($this->items)) {
122
+ foreach ($this->items as $item) {
123
+ $url .= '&item='.str_replace('"','%22',json_encode($item));
124
+ }
125
+ }
126
+ }
127
+
128
+ return $url;
129
+ }
130
+
131
+ // Helper function to workout if basket is empty.
132
+ public function getItemsCount() {
133
+ return count($this->items);
134
+ }
135
+
136
+ }
137
+
138
+ ?>
app/code/local/Adestra/MFAbandonedCart/controllers/IndexController.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Adestra_MFAbandonedCart_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction(){
5
+
6
+ $cart_url = Mage::getUrl('checkout/cart');
7
+ if (isset($_GET['sid'])) $cart_url .= '?SID='.$_GET['sid'];
8
+ header('Location: ' . $cart_url);
9
+
10
+ }
11
+
12
+ }
13
+ ?>
app/code/local/Adestra/MFAbandonedCart/etc/config.xml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Adestra_MFAbandonedCart>
5
+ <version>1.0.2</version>
6
+ </Adestra_MFAbandonedCart>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <mfabandonedcart>
11
+ <class>Adestra_MFAbandonedCart_Helper</class>
12
+ </mfabandonedcart>
13
+ </helpers>
14
+ <blocks>
15
+ <mfabandonedcart>
16
+ <class>Adestra_MFAbandonedCart_Block</class>
17
+ </mfabandonedcart>
18
+ </blocks>
19
+ <models>
20
+ <mfabandonedcart>
21
+ <class>Adestra_MFAbandonedCart_Model</class>
22
+ </mfabandonedcart>
23
+ </models>
24
+ <events>
25
+ <!-- events -->
26
+ </events>
27
+ </global>
28
+ <frontend>
29
+ <layout>
30
+ <updates>
31
+ <mfabandonedcart>
32
+ <file>mfabandonedcart.xml</file>
33
+ </mfabandonedcart>
34
+ </updates>
35
+ </layout>
36
+ <routers>
37
+ <mfabandonedcart>
38
+ <use>standard</use>
39
+ <args>
40
+ <module>Adestra_MFAbandonedCart</module>
41
+ <frontName>mf-abandoned-cart</frontName>
42
+ </args>
43
+ </mfabandonedcart>
44
+ </routers>
45
+ </frontend>
46
+ <default>
47
+ <adestra>
48
+ <abandondedcart>
49
+ <accountid>0</accountid>
50
+ </abandondedcart>
51
+ <abandondedcart>
52
+ <captureid>1</captureid>
53
+ </abandondedcart>
54
+ </adestra>
55
+ </default>
56
+ <adminhtml>
57
+ <acl>
58
+ <resources>
59
+ <admin>
60
+ <children>
61
+ <system>
62
+ <children>
63
+ <config>
64
+ <children>
65
+ <adestra>
66
+ <title>Adestra settings</title>
67
+ </adestra>
68
+ </children>
69
+ </config>
70
+ </children>
71
+ </system>
72
+ </children>
73
+ </admin>
74
+ </resources>
75
+ </acl>
76
+ </adminhtml>
77
+ </config>
app/code/local/Adestra/MFAbandonedCart/etc/system.xml ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <adestra translate="label">
5
+ <label>Adestra</label>
6
+ <tab>general</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>2000</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>0</show_in_store>
12
+ <groups>
13
+ <!-- Abandoned Cart Group -->
14
+ <mfabandonedcart translate="label" module="mfabandonedcart">
15
+ <label>Message Focus Abandoned Cart</label>
16
+ <frontend_type>text</frontend_type>
17
+ <sort_order>-100</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ <expanded>1</expanded>
22
+ <fields>
23
+ <enabled translate="label">
24
+ <label>Enabled</label>
25
+ <frontend_type>select</frontend_type>
26
+ <source_model>adminhtml/system_config_source_yesno</source_model>
27
+ <sort_order>1</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>0</show_in_store>
31
+ </enabled>
32
+ <accountid translate="label">
33
+ <label>Account ID</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>2</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ </accountid>
40
+ <clientdomain translate="label">
41
+ <label>Client domain</label>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>3</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>0</show_in_store>
47
+ <comment><![CDATA[Include trailing slash /.]]></comment>
48
+ </clientdomain>
49
+ <captureid translate="label">
50
+ <label>Capture ID</label>
51
+ <frontend_type>text</frontend_type>
52
+ <sort_order>4</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>0</show_in_store>
56
+ </captureid>
57
+ <additionalcorefields translate="label">
58
+ <label>Additional core fields</label>
59
+ <frontend_type>textarea</frontend_type>
60
+ <sort_order>5</sort_order>
61
+ <rows>5</rows>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>0</show_in_store>
65
+ <comment><![CDATA[Message Focus additional core fields mapping. Use the format {magento_field}|{message_focus_field} and one field mapping per line e.g. firstname|first_name. Additional Magento fields include: prefix, firstname, lastname, company]]></comment>
66
+ </additionalcorefields>
67
+ <debug translate="label">
68
+ <label>Debug</label>
69
+ <frontend_type>select</frontend_type>
70
+ <source_model>adminhtml/system_config_source_yesno</source_model>
71
+ <sort_order>10</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>0</show_in_store>
75
+ <comment><![CDATA[Writes conversion data to system.log.]]></comment>
76
+ </debug>
77
+ </fields>
78
+ <comment><![CDATA[Enter global options for Abandoned Cart.]]></comment>
79
+ </mfabandonedcart>
80
+ </groups>
81
+ </adestra>
82
+ </sections>
83
+ </config>
app/design/frontend/base/default/layout/mfabandonedcart.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <layout version="0.1.0">
4
+
5
+ <checkout_cart_index translate="label">
6
+ <reference name="content">
7
+ <block type="mfabandonedcart/checkout" name="mfabandonedcart" template="mfabandonedcart/checkout/update_action.phtml"/>
8
+ </reference>
9
+ </checkout_cart_index>
10
+
11
+ <checkout_onepage_review translate="label">
12
+ <reference name="checkout.onepage.review.info.items.after">
13
+ <block type="mfabandonedcart/checkout" output="toHtml" name="mfabandonedcart.update" template="mfabandonedcart/checkout/update_action.phtml"/>
14
+ </reference>
15
+ </checkout_onepage_review>
16
+
17
+ <checkout_onepage_success translate="label">
18
+ <reference name="content">
19
+ <block type="mfabandonedcart/checkout" after="checkout.success" output="toHtml" name="mfabandonedcart.purchase" template="mfabandonedcart/checkout/purchase_action.phtml"/>
20
+ </reference>
21
+ </checkout_onepage_success>
22
+
23
+
24
+ <checkout_onepage_shippingmethod>
25
+ <reference name="content">
26
+ <block type="mfabandonedcart/checkout" output="toHtml" name="mfabandonedcart.update" template="mfabandonedcart/checkout/update_action.phtml" after="root"/>
27
+ </reference>
28
+ </checkout_onepage_shippingmethod>
29
+
30
+ <checkout_onepage_index>
31
+ <reference name="checkout.payment.methods">
32
+ <block type="mfabandonedcart/checkout" output="toHtml" name="mfabandonedcart.update" template="mfabandonedcart/checkout/update_action.phtml"/>
33
+ </reference>
34
+ </checkout_onepage_index>
35
+
36
+ </layout>
app/design/frontend/base/default/template/mfabandonedcart/checkout/purchase_action.phtml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Adestra_MFAbandonedCart_Checkout
5
+ *
6
+ */
7
+ ?>
8
+ <?php
9
+ // Creates html for hidden div and image tag with url to Message Focus Conversion Capture.
10
+ echo $this->helper('mfabandonedcart')->purchaseCall();
11
+ ?>
app/design/frontend/base/default/template/mfabandonedcart/checkout/update_action.phtml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Adestra_MFAbandonedCart_Checkout
5
+ *
6
+ */
7
+ ?>
8
+ <?php
9
+ // Creates html for hidden div and image tag with url to Message Focus Conversion Capture.
10
+ echo $this->helper('mfabandonedcart')->updateCall();
11
+ ?>
app/etc/modules/Adestra_MFAbandonedCart.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Adestra_MFAbandonedCart>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Adestra_MFAbandonedCart>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Adestra_MFAbandonedCart</name>
4
+ <version>1.0.2</version>
5
+ <stability>stable</stability>
6
+ <license>GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Adestra Message Focus Abandoned cart</summary>
10
+ <description>Message Focus conversion capture integration module.</description>
11
+ <notes>Repackaged as stable.</notes>
12
+ <authors><author><name>Anna Grieve</name><user>Adestra</user><email>integrations@adestra.com</email></author></authors>
13
+ <date>2013-11-06</date>
14
+ <time>09:45:02</time>
15
+ <contents><target name="magelocal"><dir name="Adestra"><dir name="MFAbandonedCart"><dir name="Block"><file name="Checkout.php" hash="70e50c4ac3ed85eddb01577a131e275c"/></dir><dir name="Helper"><file name="Data.php" hash="5e73c48ff39c3de8d9fafd9f451e2931"/></dir><dir name="Model"><file name="Conversion.php" hash="864677d6d4c21a8343c59107b91ac998"/></dir><dir name="controllers"><file name="IndexController.php" hash="c09e1260e9aee7ad30b25c9ca5e4e646"/></dir><dir name="etc"><file name="config.xml" hash="8cd41e6a5265fa313a2331c6927cd89d"/><file name="system.xml" hash="9ea649f0de6f98188316f378250743a3"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="mfabandonedcart.xml" hash="ffc1de303843a0e960fe101881c83ad8"/></dir><dir name="template"><dir name="mfabandonedcart"><dir name="checkout"><file name="purchase_action.phtml" hash="c79a929292c3ec02c0ab88b27869311c"/><file name="update_action.phtml" hash="9b2b200dc7501a9e181dc02343948b92"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Adestra_MFAbandonedCart.xml" hash="98a24bc0c93f67574a5acc486117e3cc"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5</min><max>1.7</max></package></required></dependencies>
18
+ </package>