Rejoiner - Version 1.2.4

Version Notes

Pass "new customers" to Rejoiner

Download this release

Release Info

Developer Mike
Extension Rejoiner
Version 1.2.4
Comparing to
See all releases


Code changes from version 1.2.3 to 1.2.4

app/code/community/Rejoiner/Acr/Block/Product.php CHANGED
@@ -7,6 +7,8 @@ class Rejoiner_Acr_Block_Product extends Rejoiner_Acr_Block_Base
7
public function getCurrentProductInfo()
8
{
9
$product = Mage::registry('current_product');
10
$imageHelper = Mage::helper('catalog/image');
11
$rejoinerHelper = Mage::helper('rejoiner_acr');
12
$mediaUrl = Mage::getBaseUrl('media');
@@ -43,7 +45,8 @@ class Rejoiner_Acr_Block_Product extends Rejoiner_Acr_Block_Base
43
'price' => $this->_convertPriceToCents((string) $product->getPrice()),
44
'product_id' => (string) $product->getSku(),
45
'product_url' => (string) $product->getProductUrl(),
46
- 'category' => $categories
47
);
48
return str_replace('\\/', '/', json_encode($productData));
49
}
7
public function getCurrentProductInfo()
8
{
9
$product = Mage::registry('current_product');
10
+ $stocklevel = (int)Mage::getModel('cataloginventory/stock_item')
11
+ ->loadByProduct($product)->getQty();
12
$imageHelper = Mage::helper('catalog/image');
13
$rejoinerHelper = Mage::helper('rejoiner_acr');
14
$mediaUrl = Mage::getBaseUrl('media');
45
'price' => $this->_convertPriceToCents((string) $product->getPrice()),
46
'product_id' => (string) $product->getSku(),
47
'product_url' => (string) $product->getProductUrl(),
48
+ 'category' => $categories,
49
+ 'stock' => $stocklevel
50
);
51
return str_replace('\\/', '/', json_encode($productData));
52
}
app/code/community/Rejoiner/Acr/Model/Observer.php CHANGED
@@ -2,58 +2,119 @@
2
class Rejoiner_Acr_Model_Observer
3
{
4
const REJOINER_API_URL = 'https://app.rejoiner.com';
5
- const REJOINER_API_REQUEST_PATH = '/api/1.0/site/%s/lead/convert';
6
const REJOINER_API_LOG_FILE = 'rejoiner_api.log';
7
8
- const XML_PATH_REJOINER_API_KEY = 'checkout/rejoiner_acr/api_key';
9
- const XML_PATH_REJOINER_API_SECRET = 'checkout/rejoiner_acr/api_secret';
10
- const XML_PATH_REJOINER_API_SITE_ID = 'checkout/rejoiner_acr/site_id';
11
12
- public function trackOrderSuccessConversion(Varien_Event_Observer $observer)
13
{
14
$apiKey = Mage::getStoreConfig(self::XML_PATH_REJOINER_API_KEY);
15
$apiSecret = utf8_encode(Mage::getStoreConfig(self::XML_PATH_REJOINER_API_SECRET));
16
-
17
if ($apiKey && $apiSecret) {
18
/** @var Mage_Checkout_Model_Session $session */
19
$lastOrderId = $observer->getEvent()->getData('order_ids');
20
/** @var Mage_Sales_Model_Order $order */
21
$order = Mage::getModel('sales/order')->load($lastOrderId[0]);
22
- $customerEmail = $order->getBillingAddress()->getEmail();
23
-
24
$siteId = Mage::getStoreConfig(self::XML_PATH_REJOINER_API_SITE_ID);
25
- $requestPath = sprintf(self::REJOINER_API_REQUEST_PATH, $siteId);
26
- $requestBody = utf8_encode(sprintf('{"email": "%s"}', $customerEmail));
27
- $hmacData = utf8_encode(implode("\n", array(Varien_Http_Client::POST, $requestPath, $requestBody)));
28
29
- $codedApiSecret = base64_encode(hash_hmac('sha1', $hmacData, $apiSecret, true));
30
- $authorization = sprintf('Rejoiner %s:%s', $apiKey , $codedApiSecret);
31
- $client = new Varien_Http_Client(self::REJOINER_API_URL . $requestPath);
32
- $client->setRawData($requestBody);
33
- $client->setHeaders(array('Authorization' => $authorization, 'Content-type' => 'application/json;' ));
34
- try{
35
- $response = $client->request(Varien_Http_Client::POST);
36
- switch ($response->getStatus()) {
37
- case '200':
38
- Mage::log(print_r($response->getStatus(), true) . ' Everything is alright.', null, self::REJOINER_API_LOG_FILE);
39
- break;
40
- case '400':
41
- Mage::log(print_r($response->getStatus(), true) . ' required params were not specified and/or the body was malformed', null, self::REJOINER_API_LOG_FILE);
42
- break;
43
- case '403':
44
- Mage::log(print_r($response->getStatus(), true) . ' failed authentication and/or incorrect signature', null, self::REJOINER_API_LOG_FILE);
45
- break;
46
- case '500':
47
- Mage::log(print_r($response->getStatus(), true) . ' internal error, contact us for details', null, self::REJOINER_API_LOG_FILE);
48
- break;
49
- default:
50
- Mage::log(print_r($response->getStatus(), true) . ' unexpected response code', null, self::REJOINER_API_LOG_FILE);
51
- break;
52
- }
53
- } catch (Exception $e) {
54
- Mage::log($e->getMessage(), null, 'exception.log');
55
}
56
}
57
}
58
59
/**
2
class Rejoiner_Acr_Model_Observer
3
{
4
const REJOINER_API_URL = 'https://app.rejoiner.com';
5
+ const REJOINER_API_CONVERT_REQUEST_PATH = '/api/1.0/site/%s/lead/convert';
6
+ const REJOINER_API_ADD_TO_LIST_REQUEST_PATH = '/api/1.0/site/%s/contact_add';
7
const REJOINER_API_LOG_FILE = 'rejoiner_api.log';
8
9
+ const XML_PATH_REJOINER_API_KEY = 'checkout/rejoiner_acr/api_key';
10
+ const XML_PATH_REJOINER_API_SECRET = 'checkout/rejoiner_acr/api_secret';
11
+ const XML_PATH_REJOINER_API_SITE_ID = 'checkout/rejoiner_acr/site_id';
12
+ const XML_PATH_REJOINER_API_DEBUGGER = 'checkout/rejoiner_acr/debug_enabled';
13
+ const XML_PATH_REJOINER_PASS_NEW_CUSTOMERS = 'checkout/rejoiner_acr/passing_new_customers';
14
+ const XML_PATH_REJOINER_LIST_ID = 'checkout/rejoiner_acr/list_id';
15
16
+ /**
17
+ * @param Varien_Event_Observer $observer
18
+ * @return $this
19
+ */
20
+ public function trackOrderSuccess(Varien_Event_Observer $observer)
21
{
22
$apiKey = Mage::getStoreConfig(self::XML_PATH_REJOINER_API_KEY);
23
$apiSecret = utf8_encode(Mage::getStoreConfig(self::XML_PATH_REJOINER_API_SECRET));
24
if ($apiKey && $apiSecret) {
25
/** @var Mage_Checkout_Model_Session $session */
26
$lastOrderId = $observer->getEvent()->getData('order_ids');
27
/** @var Mage_Sales_Model_Order $order */
28
$order = Mage::getModel('sales/order')->load($lastOrderId[0]);
29
+ if (!$order->getId()) {
30
+ return $this;
31
+ }
32
+ $customerEmail = $order->getCustomerEmail();
33
$siteId = Mage::getStoreConfig(self::XML_PATH_REJOINER_API_SITE_ID);
34
+ $this->convert($apiKey, $apiSecret, $siteId, $customerEmail);
35
+ if (Mage::getStoreConfig(self::XML_PATH_REJOINER_PASS_NEW_CUSTOMERS) && Mage::getStoreConfig(self::XML_PATH_REJOINER_LIST_ID)) {
36
+ $this->addToList($apiKey, $apiSecret, $siteId, $order);
37
+ }
38
+ }
39
+ return $this;
40
+ }
41
42
+ /**
43
+ * @param $apiKey
44
+ * @param $apiSecret
45
+ * @param $siteId
46
+ * @param $customerEmail
47
+ * @return $this
48
+ */
49
+ private function convert($apiKey, $apiSecret, $siteId, $customerEmail)
50
+ {
51
+ $requestBody = utf8_encode(sprintf('{"email": "%s"}', $customerEmail));
52
+ $requestPath = sprintf(self::REJOINER_API_CONVERT_REQUEST_PATH, $siteId);
53
+ $hmacData = utf8_encode(implode("\n", array(Varien_Http_Client::POST, $requestPath, $requestBody)));
54
+ $codedApiSecret = base64_encode(hash_hmac('sha1', $hmacData, $apiSecret, true));
55
+ $authorization = sprintf('Rejoiner %s:%s', $apiKey , $codedApiSecret);
56
+ $client = new Varien_Http_Client(self::REJOINER_API_URL . $requestPath);
57
+ $client->setRawData($requestBody);
58
+ $client->setHeaders(array('Authorization' => $authorization, 'Content-type' => 'application/json;' ));
59
+ $this->sendRequest($client);
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * @param $apiKey
65
+ * @param $apiSecret
66
+ * @param $siteId
67
+ * @param $order Mage_Sales_Model_Order
68
+ * @return $this
69
+ */
70
+ private function addToList($apiKey, $apiSecret, $siteId, $order)
71
+ {
72
+ $listId = Mage::getStoreConfig(self::XML_PATH_REJOINER_LIST_ID);
73
+ if (!$listId) {
74
+ return $this;
75
+ }
76
+ $data = array(
77
+ 'email' => $order->getCustomerEmail(),
78
+ 'list_id' => $listId,
79
+ 'first_name' => $order->getCustomerFirstname()
80
+ );
81
+ $requestBody = utf8_encode(json_encode($data));
82
+ $requestPath = sprintf(self::REJOINER_API_ADD_TO_LIST_REQUEST_PATH, $siteId);
83
+ $hmacData = utf8_encode(implode("\n", array(Varien_Http_Client::POST, $requestPath, $requestBody)));
84
+ $codedApiSecret = base64_encode(hash_hmac('sha1', $hmacData, $apiSecret, true));
85
+ $authorization = sprintf('Rejoiner %s:%s', $apiKey , $codedApiSecret);
86
+ $client = new Varien_Http_Client(self::REJOINER_API_URL . $requestPath);
87
+ $client->setRawData($requestBody);
88
+ $client->setHeaders(array('Authorization' => $authorization, 'Content-type' => 'application/json;' ));
89
+ $this->sendRequest($client);
90
+ return $this;
91
+ }
92
+
93
+ private function sendRequest($client)
94
+ {
95
+ try{
96
+ $response = $client->request(Varien_Http_Client::POST);
97
+ switch ($response->getStatus() && Mage::getStoreConfig(self::XML_PATH_REJOINER_API_DEBUGGER)) {
98
+ case '200':
99
+ Mage::log(print_r($response->getStatus(), true) . ' Everything is alright.', null, self::REJOINER_API_LOG_FILE);
100
+ break;
101
+ case '400':
102
+ Mage::log(print_r($response->getStatus(), true) . ' required params were not specified and/or the body was malformed', null, self::REJOINER_API_LOG_FILE);
103
+ break;
104
+ case '403':
105
+ Mage::log(print_r($response->getStatus(), true) . ' failed authentication and/or incorrect signature', null, self::REJOINER_API_LOG_FILE);
106
+ break;
107
+ case '500':
108
+ Mage::log(print_r($response->getStatus(), true) . ' internal error, contact us for details', null, self::REJOINER_API_LOG_FILE);
109
+ break;
110
+ default:
111
+ Mage::log(print_r($response->getStatus(), true) . ' unexpected response code', null, self::REJOINER_API_LOG_FILE);
112
+ break;
113
}
114
+ } catch (Exception $e) {
115
+ Mage::log($e->getMessage(), null, 'exception.log');
116
}
117
+ return $this;
118
}
119
120
/**
app/code/community/Rejoiner/Acr/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
<config>
3
<modules>
4
<Rejoiner_Acr>
5
- <version>1.2.3</version>
6
</Rejoiner_Acr>
7
</modules>
8
<global>
@@ -52,7 +52,7 @@
52
<observers>
53
<rejoiner_order_success>
54
<class>rejoiner_acr/observer</class>
55
- <method>trackOrderSuccessConversion</method>
56
</rejoiner_order_success>
57
</observers>
58
</checkout_onepage_controller_success_action>
2
<config>
3
<modules>
4
<Rejoiner_Acr>
5
+ <version>1.2.4</version>
6
</Rejoiner_Acr>
7
</modules>
8
<global>
52
<observers>
53
<rejoiner_order_success>
54
<class>rejoiner_acr/observer</class>
55
+ <method>trackOrderSuccess</method>
56
</rejoiner_order_success>
57
</observers>
58
</checkout_onepage_controller_success_action>
app/code/community/Rejoiner/Acr/etc/system.xml CHANGED
@@ -54,6 +54,25 @@
54
<show_in_website>1</show_in_website>
55
<show_in_store>1</show_in_store>
56
</domain>
57
<track_numbers>
58
<label>Track Phone Numbers</label>
59
<frontend_type>select</frontend_type>
54
<show_in_website>1</show_in_website>
55
<show_in_store>1</show_in_store>
56
</domain>
57
+ <passing_new_customers>
58
+ <label>Pass "new customers" to Rejoiner</label>
59
+ <frontend_type>select</frontend_type>
60
+ <comment></comment>
61
+ <source_model>adminhtml/system_config_source_yesno</source_model>
62
+ <sort_order>60</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
+ </passing_new_customers>
67
+ <list_id translate="label">
68
+ <label>List ID</label>
69
+ <depends><passing_new_customers>1</passing_new_customers></depends>
70
+ <frontend_type>text</frontend_type>
71
+ <sort_order>65</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>1</show_in_store>
75
+ </list_id>
76
<track_numbers>
77
<label>Track Phone Numbers</label>
78
<frontend_type>select</frontend_type>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
<?xml version="1.0"?>
2
<package>
3
<name>Rejoiner</name>
4
- <version>1.2.3</version>
5
<stability>stable</stability>
6
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
<channel>community</channel>
8
<extends/>
9
<summary>Rejoiner Cart Abandonment Remarketing</summary>
10
<description>Turn abandoned carts into 15% more sales with Rejoiner.</description>
11
- <notes>Passing product categories as array</notes>
12
<authors><author><name>Mike</name><user>rejoiner</user><email>mike@rejoiner.com</email></author></authors>
13
- <date>2016-11-03</date>
14
- <time>13:28:27</time>
15
- <contents><target name="mageetc"><dir name="modules"><file name="Rejoiner_Acr.xml" hash="1aad3601804cead81b6e687dfcb5b83f"/></dir></target><target name="magecommunity"><dir name="Rejoiner"><dir name="Acr"><dir name="Block"><dir name="Adminhtml"><dir name="Custom"><file name="Form.php" hash="9aa505a9a27584d241fcfae803ca5d1a"/></dir><dir name="Form"><dir name="Field"><file name="Source.php" hash="4cfc6c0c33e5090efb825c68bd46f3b2"/></dir></dir><file name="Notification.php" hash="9755c2b45ce39bfa6e731fad9210a9c8"/><dir name="Preinstalled"><file name="Form.php" hash="9a7928e2e659e7b337fc54f0cdcc6c7a"/></dir></dir><file name="Base.php" hash="955a15b1881e5f8c298424f4b5fe4082"/><file name="Conversion.php" hash="b42b63140dbb7e67cd1dd224e8319b50"/><file name="Customer.php" hash="b36ce8e354fdddc514faab724d5a8e2f"/><file name="Product.php" hash="c44351a0d0283631463c14d4e132da8f"/><file name="Snippets.php" hash="cb634e2b368fe54e160618b4651b7c12"/></dir><dir name="Helper"><file name="Data.php" hash="4c00ecfd1fe47d15fe661a46d54831d4"/></dir><dir name="Model"><file name="Notification.php" hash="fcaa63417db72268528fed03066ff808"/><file name="Observer.php" hash="aa49bd5d35234bf43973e6f578dba942"/><dir name="Resource"><file name="Setup.php" hash="48f66ad159e3d10a21cc04a980ca923e"/></dir><dir name="System"><dir name="Config"><dir name="Source"><file name="Salesrule.php" hash="43ec14e93984bf1160900754f61668f5"/></dir></dir></dir></dir><dir name="controllers"><file name="AddbyskuController.php" hash="78bc6382ac0f8d59020fa924f6e238c2"/><file name="AddtocartController.php" hash="4eb895c63658ba68c94952178a8bbb1c"/><dir name="Adminhtml"><file name="RejoinerController.php" hash="0c1a1df3d91d5596ae4026c484a4bd1f"/></dir></dir><dir name="etc"><file name="config.xml" hash="b8534a384aa77213a745c12073f8d2cb"/><file name="system.xml" hash="13cdcf93f5638abf82c1499db974dec5"/></dir><dir name="sql"><dir name="rejoiner_setup"><file name="mysql4-install-1.0.0.0.php" hash="8d9a21c9c09fe44c6fe51ddd2106e3e0"/><file name="mysql4-upgrade-1.0.0.0-1.0.1.0.php" hash="36cc70cc6dd37aab7f3c460e0af58d59"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="rejoiner_acr.xml" hash="03be091dcc6dfc203871ecd4bddad362"/></dir><dir name="template"><dir name="rejoiner_acr"><file name="base.phtml" hash="98288f08530dfd42edb75ec6558f65b4"/><file name="conversion.phtml" hash="ebe3e1c4cba407bd73f74dd551e82bcf"/><file name="customer.phtml" hash="8037067aa44942175b660c1f3af0ff1f"/><file name="product.phtml" hash="f52bf4de76279a5a07711d8430031187"/><file name="tracking.phtml" hash="786720850765d3296c6e4cb5e7baf521"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="rejoiner_acr.xml" hash="eae0005d21a98027d5be43ab548f220d"/></dir><dir name="template"><dir name="rejoiner_acr"><file name="notification.phtml" hash="3a3872e6434bf7d2ca7fa0edfe6f9726"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Rejoiner_Acr.csv" hash="9015e31d97b9bc4746bc0a5241f8013b"/></dir></target></contents>
16
<compatible/>
17
<dependencies><required><php><min>5.2.0</min><max>7.0.9</max></php></required></dependencies>
18
</package>
1
<?xml version="1.0"?>
2
<package>
3
<name>Rejoiner</name>
4
+ <version>1.2.4</version>
5
<stability>stable</stability>
6
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
<channel>community</channel>
8
<extends/>
9
<summary>Rejoiner Cart Abandonment Remarketing</summary>
10
<description>Turn abandoned carts into 15% more sales with Rejoiner.</description>
11
+ <notes>Pass "new customers" to Rejoiner</notes>
12
<authors><author><name>Mike</name><user>rejoiner</user><email>mike@rejoiner.com</email></author></authors>
13
+ <date>2017-08-09</date>
14
+ <time>14:03:29</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Rejoiner_Acr.xml" hash="1aad3601804cead81b6e687dfcb5b83f"/></dir></target><target name="magecommunity"><dir name="Rejoiner"><dir name="Acr"><dir name="Block"><dir name="Adminhtml"><dir name="Custom"><file name="Form.php" hash="9aa505a9a27584d241fcfae803ca5d1a"/></dir><dir name="Form"><dir name="Field"><file name="Source.php" hash="4cfc6c0c33e5090efb825c68bd46f3b2"/></dir></dir><file name="Notification.php" hash="9755c2b45ce39bfa6e731fad9210a9c8"/><dir name="Preinstalled"><file name="Form.php" hash="9a7928e2e659e7b337fc54f0cdcc6c7a"/></dir></dir><file name="Base.php" hash="955a15b1881e5f8c298424f4b5fe4082"/><file name="Conversion.php" hash="b42b63140dbb7e67cd1dd224e8319b50"/><file name="Customer.php" hash="b36ce8e354fdddc514faab724d5a8e2f"/><file name="Product.php" hash="8bd509a13e7ed83d33e055c7df2e3c3b"/><file name="Snippets.php" hash="cb634e2b368fe54e160618b4651b7c12"/></dir><dir name="Helper"><file name="Data.php" hash="4c00ecfd1fe47d15fe661a46d54831d4"/></dir><dir name="Model"><file name="Notification.php" hash="fcaa63417db72268528fed03066ff808"/><file name="Observer.php" hash="bb41e94324d7736d7956d8371f973221"/><dir name="Resource"><file name="Setup.php" hash="48f66ad159e3d10a21cc04a980ca923e"/></dir><dir name="System"><dir name="Config"><dir name="Source"><file name="Salesrule.php" hash="43ec14e93984bf1160900754f61668f5"/></dir></dir></dir></dir><dir name="controllers"><file name="AddbyskuController.php" hash="78bc6382ac0f8d59020fa924f6e238c2"/><file name="AddtocartController.php" hash="4eb895c63658ba68c94952178a8bbb1c"/><dir name="Adminhtml"><file name="RejoinerController.php" hash="0c1a1df3d91d5596ae4026c484a4bd1f"/></dir></dir><dir name="etc"><file name="config.xml" hash="288480dd3ecf1e9af12b1ed52c5a6a21"/><file name="system.xml" hash="cc218e743edf2a6a0620e024024556a6"/></dir><dir name="sql"><dir name="rejoiner_setup"><file name="mysql4-install-1.0.0.0.php" hash="8d9a21c9c09fe44c6fe51ddd2106e3e0"/><file name="mysql4-upgrade-1.0.0.0-1.0.1.0.php" hash="36cc70cc6dd37aab7f3c460e0af58d59"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="rejoiner_acr.xml" hash="03be091dcc6dfc203871ecd4bddad362"/></dir><dir name="template"><dir name="rejoiner_acr"><file name="base.phtml" hash="98288f08530dfd42edb75ec6558f65b4"/><file name="conversion.phtml" hash="ebe3e1c4cba407bd73f74dd551e82bcf"/><file name="customer.phtml" hash="8037067aa44942175b660c1f3af0ff1f"/><file name="product.phtml" hash="f52bf4de76279a5a07711d8430031187"/><file name="tracking.phtml" hash="786720850765d3296c6e4cb5e7baf521"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="rejoiner_acr.xml" hash="eae0005d21a98027d5be43ab548f220d"/></dir><dir name="template"><dir name="rejoiner_acr"><file name="notification.phtml" hash="3a3872e6434bf7d2ca7fa0edfe6f9726"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Rejoiner_Acr.csv" hash="9015e31d97b9bc4746bc0a5241f8013b"/></dir></target></contents>
16
<compatible/>
17
<dependencies><required><php><min>5.2.0</min><max>7.0.9</max></php></required></dependencies>
18
</package>