Curebit_SocialReferrals - Version 0.1.0

Version Notes

Includes Curebit product integration

Download this release

Release Info

Developer Curebit
Extension Curebit_SocialReferrals
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Curebit/SocialReferrals/Block/Main.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * General checkout success Curebit integration class
4
+ *
5
+ * @category Curebit
6
+ * @package Curebit_SocialReferrals
7
+ */
8
+ class Curebit_SocialReferrals_Block_Main extends Mage_Core_Block_Template
9
+ {
10
+ const SERVER = 'https://www.curebit.com';
11
+ const DEFAULT_JS_URL = '/public/%s/purchases/create_magento.js';
12
+ const DEFAULT_JS_INCLUDE = '/javascripts/api/all-%s.js';
13
+ const VERSION_STRING = '0.2';
14
+
15
+ /**
16
+ * Retrieve information from configuration
17
+ *
18
+ * @param string $field
19
+ * @return mixed
20
+ */
21
+ public function getConfigData($field)
22
+ {
23
+ $path = 'checkout/curebit/'.$field;
24
+ return Mage::getStoreConfig($path);
25
+ }
26
+
27
+ public function isEnabled()
28
+ {
29
+ return ($this->getConfigData('enabled') && $this->getSiteId() != "" ? true : false);
30
+ }
31
+
32
+ public function getSiteId()
33
+ {
34
+ return trim($this->getConfigData('site_id'));
35
+ }
36
+
37
+ public function getCurebitJsUrl()
38
+ {
39
+ return sprintf(self::SERVER . self::DEFAULT_JS_URL, $this->getSiteId());
40
+ }
41
+
42
+ public function getCurebitApiVersion()
43
+ {
44
+ return self::VERSION_STRING;
45
+ }
46
+
47
+ public function getCustomerId()
48
+ {
49
+ return Mage::getSingleton('customer/session')->getCustomerId();
50
+ }
51
+
52
+ public function getJSCode($order)
53
+ {
54
+ if (is_numeric($order)) {
55
+ $order = Mage::getModel('sales/order')->load($order);
56
+ }
57
+ /* @var $order Mage_Sales_Model_Order */
58
+
59
+ $curebitI = 0;
60
+ $curebitItems = '';
61
+ foreach ($order->getAllItems() as $curebitItem) {
62
+ $curebitItems .= sprintf('purchase[items_attributes][%d][product_id]=%s&', $curebitI, urlencode($curebitItem->getProductId()));
63
+ $curebitItems .= sprintf('purchase[items_attributes][%d][price]=%.2f&', $curebitI, urlencode($curebitItem->getPrice()));
64
+ $curebitItems .= sprintf('purchase[items_attributes][%d][quantity]=%d&', $curebitI, urlencode($curebitItem->getQtyOrdered()));
65
+ $curebitI++;
66
+ }
67
+ $curebitItems = substr($curebitItems, 0, -1);
68
+
69
+ $res = '<script type="text/javascript" src=\''.$this->getCurebitJsUrl().
70
+ '?v='.urlencode($this->getCurebitApiVersion()).
71
+ '&purchase[customer_id]='.urlencode($this->getCustomerId()).
72
+ '&purchase[order_number]='.$order->getIncrementId().
73
+ '&purchase[subtotal]='.urlencode(sprintf("%.2f", $order->getSubtotal())).
74
+ '&purchase[order_date]='.urlencode($order->getCreatedAt()).
75
+ '&purchase[customer_email]='.urlencode($order->getCustomerEmail()).
76
+ '&'.$curebitItems.'\'></script>';
77
+ return $res;
78
+ }
79
+ public function getJSIncludeUrl()
80
+ {
81
+ return sprintf(self::SERVER . self::DEFAULT_JS_INCLUDE, $this->getCurebitApiVersion());
82
+ }
83
+ public function getProductJSCode($order)
84
+ {
85
+ if (is_numeric($order)) {
86
+ $order = Mage::getModel('sales/order')->load($order);
87
+ }
88
+
89
+ $curebitProducts = '';
90
+ $productPushJs = <<<EOS
91
+ products.push({
92
+ url: '%s', /*REQUIRED VARIABLE */
93
+ image_url: '%s', /* REQUIRED VARIABLE */
94
+ title: %s, /* REQUIRED VARIABLE */
95
+ product_id: %s, /* REQUIRED VARIABLE */
96
+ price: %.2f /* OPTIONAL VARIABLE */
97
+ });
98
+
99
+ EOS;
100
+ foreach ($order->getAllItems() as $curebitItem) {
101
+ $product = Mage::getModel('catalog/product')->load($curebitItem->getProductId());
102
+ $curebitProducts .= sprintf($productPushJs,
103
+ $product->getProductUrl(), // dont use json_encode for urls since forward slash gets escaped
104
+ $product->getImageUrl(), // dont use json_encode for urls since forward slash gets escaped
105
+ json_encode($product->getName()), // automatically quotes
106
+ json_encode($product->getId()), // automatically quotes
107
+ json_encode($product->getPrice()) // automatically quotes
108
+ ); // $product->getShortDescription()
109
+
110
+ }
111
+
112
+ $template = <<<EOS
113
+ <script type="text/javascript">
114
+ curebit.init({site_id: '%s'});
115
+ var products = [];
116
+ %s
117
+ curebit.register_products(products);
118
+ </script>
119
+ EOS;
120
+ return sprintf($template, $this->getSiteId(), $curebitProducts);
121
+ }
122
+
123
+
124
+
125
+ }
app/code/community/Curebit/SocialReferrals/Block/Multishipping/Success.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Multishipping checkout success Curebit integration
5
+ *
6
+ * @category Curebit
7
+ * @package Curebit_SocialReferrals
8
+ */
9
+ class Curebit_SocialReferrals_Block_Multishipping_Success extends Curebit_SocialReferrals_Block_Main
10
+ {
11
+
12
+ protected function _construct()
13
+ {
14
+ $this->setTemplate('curebit/multishipping/success.phtml');
15
+ parent::_construct();
16
+ }
17
+
18
+ public function getOrderIds()
19
+ {
20
+ $ids = $this->getData('order_ids');
21
+ if ($ids && is_array($ids)) {
22
+ return $ids;
23
+ }
24
+ return false;
25
+ }
26
+ }
app/code/community/Curebit/SocialReferrals/Block/Success.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Checkout success Curebit integration
4
+ *
5
+ * @category Curebit
6
+ * @package Curebit_SocialReferrals
7
+ */
8
+
9
+ class Curebit_SocialReferrals_Block_Success extends Curebit_SocialReferrals_Block_Main
10
+ {
11
+ private $_order = null;
12
+
13
+ protected function _construct()
14
+ {
15
+ $this->setTemplate('curebit/success.phtml');
16
+ parent::_construct();
17
+ }
18
+
19
+ public function getOrder()
20
+ {
21
+ if ($this->_order === null) {
22
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
23
+ if ($orderId) {
24
+ $order = Mage::getModel('sales/order')->load($orderId);
25
+ if ($order->getId()) {
26
+ $this->_order = $order;
27
+ }
28
+ }
29
+ }
30
+ return $this->_order;
31
+ }
32
+
33
+ public function getOrderId()
34
+ {
35
+ return $this->getOrder()->getIncrementId();
36
+ }
37
+ }
app/code/community/Curebit/SocialReferrals/Helper/Data.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Help module helper
4
+ *
5
+ * @category Curebit
6
+ * @package Curebit_SocialReferrals
7
+ */
8
+ class Curebit_SocialReferrals_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {
10
+
11
+
12
+ }
app/code/community/Curebit/SocialReferrals/etc/config.xml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Curebit_SocialReferrals>
5
+ <version>0.1.0</version>
6
+ </Curebit_SocialReferrals>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <curebit_socialreferrals><class>Curebit_SocialReferrals_Block</class></curebit_socialreferrals>
11
+ </blocks>
12
+
13
+ <helpers>
14
+ <curebit_socialreferrals>
15
+ <class>Curebit_SocialReferrals_Helper</class>
16
+ </curebit_socialreferrals>
17
+ </helpers>
18
+ </global>
19
+ <frontend>
20
+ <layout>
21
+ <updates>
22
+ <curebit>
23
+ <file>curebit.xml</file>
24
+ </curebit>
25
+ </updates>
26
+ </layout>
27
+ </frontend>
28
+
29
+ <default>
30
+ <checkout>
31
+ <curebit>
32
+ <enabled>0</enabled>
33
+ <site_id></site_id>
34
+ </curebit>
35
+ </checkout>
36
+ </default>
37
+ </config>
app/code/community/Curebit/SocialReferrals/etc/system.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <checkout>
5
+ <groups>
6
+ <curebit translate="label">
7
+ <label>Curebit Integration</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>1</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <enabled translate="label">
15
+ <label>Enabled</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ </enabled>
23
+ <site_id translate="label">
24
+ <label>Curebit Site ID</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>5</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </site_id>
31
+ </fields>
32
+ </curebit>
33
+ </groups>
34
+ </checkout>
35
+ </sections>
36
+ </config>
app/design/frontend/base/default/layout/curebit.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_success>
4
+ <reference name="before_body_end">
5
+ <block type="curebit_socialreferrals/success" name="curebit_socialreferrals_success" />
6
+ </reference>
7
+ </checkout_onepage_success>
8
+ </layout>
app/design/frontend/base/default/template/curebit/multishipping/success.phtml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php if ($this->isEnabled()): ?>
2
+ <!-- Begin Curebit integration code -->
3
+ <?php echo $this->getJSCode($this->getOrder()); ?>
4
+ <script src="<?php echo $this->getJSIncludeUrl(); ?>" type="text/javascript"></script>
5
+ <?php echo $this->getProductJSCode($this->getOrder()); ?>
6
+ <!-- End Curebit integration code -->
7
+ <?php endif; ?>
app/design/frontend/base/default/template/curebit/success.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php if ($this->isEnabled()): ?>
2
+ <!-- Begin Curebit integration code -->
3
+ <?php echo $this->getJSCode($this->getOrder()); ?>
4
+ <!-- End Curebit integration code -->
5
+ <?php endif; ?>
app/design/frontend/default/default/layout/curebit.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_success>
4
+ <reference name="before_body_end">
5
+ <block type="curebit_socialreferrals/success" name="curebit_socialreferrals_success" />
6
+
7
+ </reference>
8
+ </checkout_onepage_success>
9
+ </layout>
app/design/frontend/default/default/template/curebit/multishipping/success.phtml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->isEnabled()): ?>
2
+ <!-- Begin Curebit integration code -->
3
+ <?php
4
+ $_orderIds = $this->getOrderIds();
5
+ foreach ($_orderIds as $orderId => $incrementId) {
6
+ echo $this->getJSCode($orderId)."\n\r";
7
+ }
8
+ ?>
9
+ <!-- End Curebit integration code -->
10
+ <?php endif; ?>
app/design/frontend/default/default/template/curebit/success.phtml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php if ($this->isEnabled()): ?>
2
+ <!-- Begin Curebit integration code -->
3
+ <?php echo $this->getJSCode($this->getOrder()); ?>
4
+ <script src="<?php echo $this->getJSIncludeUrl(); ?>" type="text/javascript"></script>
5
+ <?php echo $this->getProductJSCode($this->getOrder()); ?>
6
+ <!-- End Curebit integration code -->
7
+ <?php endif; ?>
app/etc/modules/Curebit_SocialReferrals.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Curebit_SocialReferrals>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Checkout />
9
+ </depends>
10
+ </Curebit_SocialReferrals>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Curebit_SocialReferrals</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>MIT</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Curebit Social Referrals System</summary>
10
+ <description>Curebit enables your Magento store to attract new customers by offering them special deals in exchange for sharing with their friends. This checkout extension provides links for them to share their purchase on Facebook, Twitter, and Email and encourages them to bring in new customers for you. Using Curebit, you help your customers drive more referral sales per dollar than traditional marketing and advertising. See more at Curebit.com</description>
11
+ <notes>Includes Curebit product integration</notes>
12
+ <authors><author><name>Curebit</name><user>curebit</user><email>support@curebit.com</email></author></authors>
13
+ <date>2011-09-01</date>
14
+ <time>23:57:39</time>
15
+ <contents><target name="magecommunity"><dir name="Curebit"><dir name="SocialReferrals"><dir name="Block"><file name="Main.php" hash="ad919bb209b254d3c2cf8ffc4d44d7b2"/><dir name="Multishipping"><file name="Success.php" hash="892867044769e57f69683a2b929b43a7"/></dir><file name="Success.php" hash="1f13e053a90f96427e41632ad0149d7c"/></dir><dir name="Helper"><file name="Data.php" hash="ce69927dbd91e308a57cddfef0117c9d"/></dir><dir name="etc"><file name="config.xml" hash="8b3016acc3120a6724016fe7a00999dc"/><file name="system.xml" hash="cd1a8019e7a5735ee138b640e2e28629"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="curebit"><dir name="multishipping"><file name="success.phtml" hash="e45132549109038a0cd67e9242ac2830"/></dir><file name="success.phtml" hash="f22053f7b154fa34d3712b3b0f1cd27c"/></dir></dir><dir name="layout"><file name="curebit.xml" hash="c8eb2501fddaf87a23d388f26a7e4f7a"/></dir></dir></dir><dir name="default"><dir name="default"><dir name="template"><dir name="curebit"><dir name="multishipping"><file name="success.phtml" hash="b14387acc5551ed32362b1c4d194dc7d"/></dir><file name="success.phtml" hash="e45132549109038a0cd67e9242ac2830"/></dir></dir><dir name="layout"><file name="curebit.xml" hash="08299908691bb6c3dbcfe9ab880d1d54"/></dir></dir></dir></dir></target><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Curebit_SocialReferrals.xml" hash="6700db18a8a8afb33d8f4e7d67e13f7a"/></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>