Hivewyre_Magentoconnector - Version 1.0.0

Version Notes

First release version.

Download this release

Release Info

Developer Eduardo De León
Extension Hivewyre_Magentoconnector
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (27) hide show
  1. app/code/community/Hivewyre/.DS_Store +0 -0
  2. app/code/community/Hivewyre/Magentoconnector/.DS_Store +0 -0
  3. app/code/community/Hivewyre/Magentoconnector/Block/Abstract.php +32 -0
  4. app/code/community/Hivewyre/Magentoconnector/Block/Adminhtml/System/Config/Fieldset/Ajaxcalls.php +15 -0
  5. app/code/community/Hivewyre/Magentoconnector/Block/Adminhtml/System/Config/Fieldset/Info.php +15 -0
  6. app/code/community/Hivewyre/Magentoconnector/Block/Conversion.php +48 -0
  7. app/code/community/Hivewyre/Magentoconnector/Block/Tracking.php +21 -0
  8. app/code/community/Hivewyre/Magentoconnector/Helper/Data.php +240 -0
  9. app/code/community/Hivewyre/Magentoconnector/Model/Api/Abstract.php +121 -0
  10. app/code/community/Hivewyre/Magentoconnector/Model/Api/Accounts.php +103 -0
  11. app/code/community/Hivewyre/Magentoconnector/Model/Config.php +33 -0
  12. app/code/community/Hivewyre/Magentoconnector/Model/Config/Segmentsdropdown.php +19 -0
  13. app/code/community/Hivewyre/Magentoconnector/Model/Config/Websitesdropdown.php +19 -0
  14. app/code/community/Hivewyre/Magentoconnector/controllers/Adminhtml/MagentoconnectorController.php +92 -0
  15. app/code/community/Hivewyre/Magentoconnector/etc/adminhtml.xml +35 -0
  16. app/code/community/Hivewyre/Magentoconnector/etc/config.xml +71 -0
  17. app/code/community/Hivewyre/Magentoconnector/etc/system.xml +203 -0
  18. app/design/adminhtml/default/default/template/hivewyre_magentoconnector/.DS_Store +0 -0
  19. app/design/adminhtml/default/default/template/hivewyre_magentoconnector/system/.DS_Store +0 -0
  20. app/design/adminhtml/default/default/template/hivewyre_magentoconnector/system/config/.DS_Store +0 -0
  21. app/design/adminhtml/default/default/template/hivewyre_magentoconnector/system/config/fieldset/ajaxcalls.phtml +210 -0
  22. app/design/adminhtml/default/default/template/hivewyre_magentoconnector/system/config/fieldset/info.phtml +7 -0
  23. app/design/frontend/base/default/layout/hivewyre_magentoconnector.xml +26 -0
  24. app/design/frontend/base/default/template/hivewyre_magentoconnector/conversion.phtml +9 -0
  25. app/design/frontend/base/default/template/hivewyre_magentoconnector/tracking.phtml +9 -0
  26. app/etc/modules/Hivewyre_Magentoconnector.xml +20 -0
  27. package.xml +95 -0
app/code/community/Hivewyre/.DS_Store ADDED
Binary file
app/code/community/Hivewyre/Magentoconnector/.DS_Store ADDED
Binary file
app/code/community/Hivewyre/Magentoconnector/Block/Abstract.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 HiveWyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Block_Abstract extends Mage_Core_Block_Template {
8
+
9
+ /**
10
+ * Verify if module is enabled
11
+ * @return [type]
12
+ * @author edudeleon
13
+ * @date 2016-01-24
14
+ */
15
+ public function _toHtml()
16
+ {
17
+ if (Mage::helper('magentoconnector')->isEnabled()){
18
+ return parent::_toHtml();
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Return Site Id
24
+ * @return [type]
25
+ * @author edudeleon
26
+ * @date 2016-01-24
27
+ */
28
+ public function getSiteId(){
29
+ return Mage::helper('magentoconnector')->getSiteId();
30
+ }
31
+
32
+ }
app/code/community/Hivewyre/Magentoconnector/Block/Adminhtml/System/Config/Fieldset/Ajaxcalls.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 HiveWyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Block_Adminhtml_System_Config_Fieldset_Ajaxcalls
8
+ extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface {
9
+
10
+ protected $_template = 'hivewyre_magentoconnector/system/config/fieldset/ajaxcalls.phtml';
11
+
12
+ public function render(Varien_Data_Form_Element_Abstract $element) {
13
+ return $this->toHtml();
14
+ }
15
+ }
app/code/community/Hivewyre/Magentoconnector/Block/Adminhtml/System/Config/Fieldset/Info.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 HiveWyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Block_Adminhtml_System_Config_Fieldset_Info
8
+ extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface {
9
+
10
+ protected $_template = 'hivewyre_magentoconnector/system/config/fieldset/info.phtml';
11
+
12
+ public function render(Varien_Data_Form_Element_Abstract $element) {
13
+ return $this->toHtml();
14
+ }
15
+ }
app/code/community/Hivewyre/Magentoconnector/Block/Conversion.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 HiveWyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Block_Conversion extends Hivewyre_Magentoconnector_Block_Abstract {
8
+
9
+ private $_order_id;
10
+
11
+ /**
12
+ * Get last order Id
13
+ * @return [type]
14
+ * @author edudeleon
15
+ * @date 2016-01-24
16
+ */
17
+ public function getOrderId(){
18
+ if($this->_order_id == null) {
19
+ $this->_order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
20
+ }
21
+ return $this->_order_id;
22
+ }
23
+
24
+ /**
25
+ * Get order total amount (Excluding shipping costs)
26
+ * @return [type]
27
+ * @author edudeleon
28
+ * @date 2016-01-24
29
+ */
30
+ public function getOrderTotal(){
31
+ $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
32
+
33
+ return $order->getSubtotal();
34
+ }
35
+
36
+ /**
37
+ * Get conversion script URL
38
+ * Used in the frontend
39
+ * @return [type]
40
+ * @author edudeleon
41
+ * @date 2016-03-09
42
+ */
43
+ public function getConversionScriptUrl(){
44
+ $url = Hivewyre_Magentoconnector_Model_Config::HIVEWYRE_TRACKING_URL."/tagcontainer.js?id=".$this->getSiteId()."&type=0&order_id=".$this->getOrderId()."&value=".$this->getOrderTotal();
45
+
46
+ return $url;
47
+ }
48
+ }
app/code/community/Hivewyre/Magentoconnector/Block/Tracking.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 HiveWyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Block_Tracking extends Hivewyre_Magentoconnector_Block_Abstract {
8
+
9
+ /**
10
+ * Get tracking script URL
11
+ * Used in the frontend
12
+ * @return [type]
13
+ * @author edudeleon
14
+ * @date 2016-03-09
15
+ */
16
+ public function getTrackingScriptUrl(){
17
+ $url = Hivewyre_Magentoconnector_Model_Config::HIVEWYRE_TRACKING_URL."/tagcontainer.js?id=".$this->getSiteId()."&type=1";
18
+
19
+ return $url;
20
+ }
21
+ }
app/code/community/Hivewyre/Magentoconnector/Helper/Data.php ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Hivewyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Helper_Data extends Mage_Core_Helper_Abstract
8
+ {
9
+
10
+ #Config paths
11
+ const ENABLED_PATH = 'hivewyre_settings/general/enabled';
12
+ const SITE_ID_PATH = 'hivewyre_settings/general/siteid';
13
+
14
+ /**
15
+ * Check if module is enabled and Site ID is set
16
+ * @param [type] $store
17
+ * @return boolean
18
+ * @author edudeleon
19
+ * @date 2016-01-24
20
+ */
21
+ public function isEnabled($store = null)
22
+ {
23
+ $clientId = $this->getSiteId($store);
24
+ return $clientId && Mage::getStoreConfig(self::ENABLED_PATH, $store);
25
+ }
26
+
27
+ /**
28
+ * Get Site ID
29
+ * @param [type] $store
30
+ * @return [type]
31
+ * @author edudeleon
32
+ * @date 2016-01-24
33
+ */
34
+ public function getSiteId($store = null)
35
+ {
36
+ return Mage::getStoreConfig(self::SITE_ID_PATH, $store);
37
+ }
38
+
39
+ /**
40
+ * Call Method to get Segments and handle the result
41
+ * @return [type]
42
+ * @author edudeleon
43
+ * @date 2016-02-09
44
+ */
45
+ public function getSegments(){
46
+ $categories = array();
47
+ try {
48
+ $accountsApi = Mage::getModel('magentoconnector/api_accounts');
49
+ $segments = $accountsApi->getSegments();
50
+
51
+ if(!empty($segments)){
52
+ foreach ($segments as $value) {
53
+ $categories[$value['id']] = $value['name'];
54
+ }
55
+ }
56
+
57
+ } catch (Exception $ex) {
58
+ $error = array(
59
+ 'success' => FALSE,
60
+ 'msg' => Mage::helper('magentoconnector')->__($ex),
61
+ );
62
+
63
+ }
64
+
65
+ return $categories;
66
+ }
67
+
68
+
69
+ /**
70
+ * Call methdd that registers a new Merchant and handle result
71
+ * @param [type] $email
72
+ * @param [type] $website
73
+ * @param [type] $segment
74
+ * @param [type] $password
75
+ * @return [type]
76
+ * @author edudeleon
77
+ * @date 2016-02-09
78
+ */
79
+ public function registerMerchant($email, $website, $segment, $password){
80
+
81
+ try {
82
+ $accountsApi = Mage::getModel('magentoconnector/api_accounts');
83
+ $result = $accountsApi->registerMerchant($email, $website, $segment, $password);
84
+
85
+ //Checking for Errors
86
+ $error_msg = $this->_getErrorMessages($result);
87
+ if(empty($error_msg)){
88
+ return array(
89
+ 'success' => TRUE,
90
+ 'site_id' => $result['site_id']
91
+ );
92
+ } else {
93
+ return array(
94
+ 'success' => FALSE,
95
+ 'msg' => $error_msg
96
+ );
97
+ }
98
+
99
+ } catch (Exception $ex) {
100
+ $error_msg = Mage::helper('magentoconnector')->__('Connection with Hivewyre API failed') .
101
+ '<br />' . $ex->getCode() . ': ' . $ex->getMessage();
102
+
103
+ return array(
104
+ 'success' => FALSE,
105
+ 'msg' => $error_msg,
106
+ );
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Login user and get list of websites associated to the account.
112
+ * @param [type] $email
113
+ * @param [type] $password
114
+ * @return [type]
115
+ * @author edudeleon
116
+ * @date 2016-02-16
117
+ */
118
+ public function loginMerchant($email, $password){
119
+ try {
120
+ $accountsApi = Mage::getModel('magentoconnector/api_accounts');
121
+ $result = $accountsApi->loginMerchant($email, $password);
122
+
123
+ //Check for Errors
124
+ $error_msg = $this->_getErrorMessages($result);
125
+ if(empty($error_msg)){
126
+
127
+ //Get website list
128
+ $token = $result["token"];
129
+ $result2 = $accountsApi->getMerchantWebsites($token);
130
+
131
+ //Checking errors second call
132
+ $error_msg2 = $this->_getErrorMessages($result2);
133
+ if(empty($error_msg2)){
134
+
135
+ $websites = array();
136
+ if(!empty($result2)){
137
+ $websites[0] = "Select a Website";
138
+ }
139
+ foreach ($result2 as $value) {
140
+ if($value["name_of_rap"] == "None" || $value["name_of_rap"] == NULL){
141
+ $websites[$value['id']] = $value['domain'] . " (Not Connected)";
142
+ } else {
143
+ $websites[$value['id']] = $value['domain'] . " (Connected to ".$value['name_of_rap'].")";
144
+ }
145
+ }
146
+
147
+ return array(
148
+ 'success' => TRUE,
149
+ 'token' => $token,
150
+ 'sites' => $websites
151
+ );
152
+ } else {
153
+ return array(
154
+ 'success' => FALSE,
155
+ 'msg' => $error_msg2
156
+ );
157
+ }
158
+
159
+ } else {
160
+ return array(
161
+ 'success' => FALSE,
162
+ 'msg' => $error_msg
163
+ );
164
+ }
165
+
166
+ } catch (Exception $ex) {
167
+ $error_msg = Mage::helper('magentoconnector')->__('Connection with Hivewyre API failed') .
168
+ '<br />' . $ex->getCode() . ': ' . $ex->getMessage();
169
+
170
+ return array(
171
+ 'success' => FALSE,
172
+ 'msg' => $error_msg,
173
+ );
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Connect Merchant
179
+ * @param [type] $domain_id
180
+ * @param [type] $token
181
+ * @param [type] $rap
182
+ * @return [type]
183
+ * @author edudeleon
184
+ * @date 2016-02-18
185
+ */
186
+ public function connectMerchant($domain_id, $token, $rap){
187
+ try {
188
+ $accountsApi = Mage::getModel('magentoconnector/api_accounts');
189
+ $result = $accountsApi->connectMerchant($domain_id, $token, $rap);
190
+
191
+ //Checking for Errors
192
+ $error_msg = $this->_getErrorMessages($result);
193
+ if(empty($error_msg)){
194
+ return array(
195
+ 'success' => TRUE,
196
+ 'site_id' => $result['site_id']
197
+ );
198
+ } else {
199
+ return array(
200
+ 'success' => FALSE,
201
+ 'msg' => $error_msg,
202
+ );
203
+ }
204
+
205
+ } catch (Exception $ex) {
206
+ $error_msg = Mage::helper('magentoconnector')->__('Connection with Hivewyre API failed') .
207
+ '<br />' . $ex->getCode() . ': ' . $ex->getMessage();
208
+
209
+ return array(
210
+ 'success' => FALSE,
211
+ 'msg' => $error_msg,
212
+ );
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Get error messages
218
+ * @param [type] $result
219
+ * @return [type]
220
+ * @author edudeleon
221
+ * @date 2016-02-16
222
+ */
223
+ private function _getErrorMessages($result){
224
+ //Checking for Errors
225
+ $error_msg = '';
226
+ if(isset($result['errors'])){
227
+ foreach ($result['errors'] as $key => $value) {
228
+ $error_msg .= "[". strtoupper($key) ."] ";
229
+
230
+ foreach ($value as $msg) {
231
+ $error_msg .= $msg;
232
+ }
233
+
234
+ $error_msg .= "</br>";
235
+ }
236
+ }
237
+
238
+ return $error_msg;
239
+ }
240
+ }
app/code/community/Hivewyre/Magentoconnector/Model/Api/Abstract.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Hivewyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Model_Api_Abstract extends Mage_Core_Model_Abstract
8
+ {
9
+
10
+ /**
11
+ * Returns the method URL
12
+ * @param [type] $path
13
+ * @return [type]
14
+ * @author edudeleon
15
+ * @date 2016-02-09
16
+ */
17
+ protected function _getUrl($path)
18
+ {
19
+ return Hivewyre_Magentoconnector_Model_Config::ENDPOINT_URL.$path;
20
+ }
21
+
22
+ /**
23
+ * Return the Authorization String encoded
24
+ * @param [type] $method
25
+ * @param [type] $endpoint
26
+ * @param [type] $data
27
+ * @return [type]
28
+ * @author edudeleon
29
+ * @date 2016-02-09
30
+ */
31
+ private function _getAuthorizationString($method, $endpoint, $data){
32
+ //Get this from config
33
+ $this->public_key = Hivewyre_Magentoconnector_Model_Config::HIVEWYRE_PUBLIC_KEY;
34
+ $this->secret_key = Hivewyre_Magentoconnector_Model_Config::HIVEWYRE_SECRET_KEY;
35
+
36
+ if($data){
37
+ $request_body = utf8_encode(json_encode($data));
38
+ } else {
39
+ $request_body = '';
40
+ }
41
+
42
+ $data_request = $method . "\n" . $endpoint . "\n" . $request_body;
43
+ $encoded_request = 'Hivewyre '.$this->public_key.':'.base64_encode(hash_hmac("sha1", $data_request, $this->secret_key, $raw_output=TRUE));
44
+
45
+ return $encoded_request;
46
+ }
47
+
48
+ /**
49
+ * Makes the API Call
50
+ * @param [type] $endpoint
51
+ * @param string $method
52
+ * @param [type] $data
53
+ * @param boolean $token
54
+ * @return [type]
55
+ * @author edudeleon
56
+ * @date 2016-02-09
57
+ */
58
+ protected function _call($endpoint, $method = 'POST', $data = null, $token = null)
59
+ {
60
+ //Prepare URL
61
+ $url = $this->_getUrl($endpoint);
62
+
63
+ $method = strtoupper($method);
64
+
65
+ //Getting Authorization String
66
+ $auth_string = $this->_getAuthorizationString($method, $endpoint, $data);
67
+
68
+ //Instantiate the
69
+ $client = new Zend_Http_Client($url);
70
+ $client->setMethod($method);
71
+
72
+ //Preparing headers
73
+ $headers = array(
74
+ 'Authorization' => $auth_string,
75
+ 'Content-Type' => 'application/json'
76
+ );
77
+
78
+ if($token){
79
+ $headers['Advertiser-Authorization'] = "Token ".$token;
80
+ }
81
+
82
+ $client->setHeaders($headers);
83
+
84
+ if($method == 'POST' || $method == "PUT" || $method == "PATCH") {
85
+ $client->setRawData(json_encode($data), 'application/json');
86
+ }
87
+
88
+ Mage::log(
89
+ print_r(
90
+ array(
91
+ 'url' => $url,
92
+ 'method' => $method,
93
+ 'headers' => $headers,
94
+ 'data' => json_encode($data),
95
+ ),
96
+ true
97
+ ),
98
+ null,
99
+ 'hivewyre.log'
100
+ );
101
+
102
+ try {
103
+ $response = $client->request();
104
+
105
+ } catch ( Zend_Http_Client_Exception $ex ) {
106
+ Mage::log('Call to ' . $url . ' resulted in: ' . $ex->getMessage(), Zend_Log::ERR, 'hivewyre.log');
107
+ Mage::log('--Last Request: ' . $client->getLastRequest(), Zend_Log::ERR, 'hivewyre.log');
108
+ Mage::log('--Last Response: ' . $client->getLastResponse(), Zend_Log::ERR, 'hivewyre.log');
109
+
110
+ return $ex->getMessage();
111
+ }
112
+
113
+ //Prepare response
114
+ $body = json_decode($response->getBody(), true);
115
+
116
+ //Log response
117
+ Mage::log(var_export($body, true), Zend_Log::DEBUG, 'hivewyre.log');
118
+
119
+ return $body;
120
+ }
121
+ }
app/code/community/Hivewyre/Magentoconnector/Model/Api/Accounts.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Hivewyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Model_Api_Accounts extends Hivewyre_Magentoconnector_Model_Api_Abstract
8
+ {
9
+
10
+ /**
11
+ * Make a request to get the segments.
12
+ * @return [type]
13
+ * @author edudeleon
14
+ * @date 2016-02-09
15
+ */
16
+ public function getSegments(){
17
+
18
+ $response = $this->_call('/external_api/v1/segments','GET');
19
+
20
+ return $response;
21
+ }
22
+
23
+ /**
24
+ * Make a request to accounts method in order to save the a new account
25
+ * @param [type] $email
26
+ * @param [type] $website
27
+ * @param [type] $segment
28
+ * @param [type] $password
29
+ * @param [type] $rap
30
+ * @return [type]
31
+ * @author edudeleon
32
+ * @date 2016-02-09
33
+ */
34
+ public function registerMerchant($email, $website, $segment, $password, $rap = null){
35
+ $data = array(
36
+ 'email' => $email,
37
+ 'password' => $password,
38
+ 'website' => array(
39
+ 'domain' => $website,
40
+ 'segment' => $segment,
41
+ 'rap' => Hivewyre_Magentoconnector_Model_Config::MAGENTO_RAP, //Magento Rap
42
+ )
43
+ );
44
+
45
+ $response = $this->_call('/external_api/v1/accounts', 'POST', $data);
46
+ return $response;
47
+ }
48
+
49
+ /**
50
+ * Login Merchant
51
+ * @param [type] $email
52
+ * @param [type] $password
53
+ * @return [type]
54
+ * @author edudeleon
55
+ * @date 2016-02-16
56
+ */
57
+ public function loginMerchant($email, $password){
58
+
59
+ $data = array(
60
+ 'username' => $email,
61
+ 'password' => $password
62
+ );
63
+
64
+ $response = $this->_call('/external_api/v1/login', 'POST', $data);
65
+
66
+ return $response;
67
+ }
68
+
69
+ /**
70
+ * Get Merchant webisites
71
+ * @param [type] $token
72
+ * @return [type]
73
+ * @author edudeleon
74
+ * @date 2016-02-16
75
+ */
76
+ public function getMerchantWebsites($token){
77
+
78
+ $response = $this->_call('/external_api/v1/advertiser/sites', 'GET', NULL, $token);
79
+
80
+ return $response;
81
+ }
82
+
83
+
84
+ /**
85
+ * Assign RAP to domain/site ID
86
+ * @param [type] $domain_id
87
+ * @param [type] $token
88
+ * @param [type] $rap
89
+ * @return [type]
90
+ * @author edudeleon
91
+ * @date 2016-02-18
92
+ */
93
+ public function connectMerchant($domain_id, $token, $rap){
94
+
95
+ $data = array(
96
+ 'rap' => $rap,
97
+ );
98
+
99
+ $response = $this->_call('/external_api/v1/advertiser/sites/'.$domain_id, 'PATCH', $data, $token);
100
+
101
+ return $response;
102
+ }
103
+ }
app/code/community/Hivewyre/Magentoconnector/Model/Config.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 HiveWyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Model_Config extends Mage_Core_Model_Abstract
8
+ {
9
+ /*
10
+ * API Endpoint
11
+ */
12
+ const ENDPOINT_URL = 'https://clients.hivewyre.com';
13
+
14
+ /*
15
+ * Registered Account Partner
16
+ */
17
+ const MAGENTO_RAP = '1dfc3238c2294c688073f56c64559cb4';
18
+
19
+ /**
20
+ * Hivewyre Public API Key
21
+ */
22
+ const HIVEWYRE_PUBLIC_KEY = "ddb070fe0cf9401fbc4b256e1039fbc0";
23
+
24
+ /**
25
+ * Hivewyre Secret API Key
26
+ */
27
+ const HIVEWYRE_SECRET_KEY = "d8820147c6c1495081017f14f1c2104f";
28
+
29
+ /**
30
+ * Hivewyre tracking URL / Used in frontend header
31
+ */
32
+ const HIVEWYRE_TRACKING_URL = "https://js.b1js.com";
33
+ }
app/code/community/Hivewyre/Magentoconnector/Model/Config/Segmentsdropdown.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Hivewyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Model_Config_Segmentsdropdown
8
+ {
9
+ /**
10
+ * Segments Dropdown
11
+ * @return [type]
12
+ * @author edudeleon
13
+ * @date 2016-01-20
14
+ */
15
+ public function toOptionArray()
16
+ {
17
+ return array();
18
+ }
19
+ }
app/code/community/Hivewyre/Magentoconnector/Model/Config/Websitesdropdown.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Hivewyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Model_Config_Websitesdropdown
8
+ {
9
+ /**
10
+ * Segments Dropdown
11
+ * @return [type]
12
+ * @author edudeleon
13
+ * @date 2016-01-20
14
+ */
15
+ public function toOptionArray()
16
+ {
17
+ return array();
18
+ }
19
+ }
app/code/community/Hivewyre/Magentoconnector/controllers/Adminhtml/MagentoconnectorController.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 HiveWyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+
7
+ class Hivewyre_Magentoconnector_Adminhtml_MagentoconnectorController extends Mage_Adminhtml_Controller_Action
8
+ {
9
+
10
+ /**
11
+ * Returns a list of segments(categories) for website to register
12
+ * @return [type]
13
+ * @author edudeleon
14
+ * @date 2016-02-09
15
+ */
16
+ public function getSegmentsAction()
17
+ {
18
+ $segments = Mage::helper('magentoconnector')->getSegments();
19
+
20
+ $this->getResponse()->clearHeaders()->setHeader('Content-type','application/json', true);
21
+ $this->getResponse()->setBody(json_encode($segments));
22
+ }
23
+
24
+ /**
25
+ * Get params from admin section and calll the method to register new accounts
26
+ * @return [type]
27
+ * @author edudeleon
28
+ * @date 2016-02-09
29
+ */
30
+ public function registerMerchantAction(){
31
+
32
+ $request = Mage::app()->getRequest();
33
+
34
+ $result = Mage::helper('magentoconnector')->registerMerchant(
35
+ $request->getParam('email'),
36
+ $request->getParam('website'),
37
+ $request->getParam('segment'),
38
+ $request->getParam('password')
39
+ );
40
+
41
+ //Validate Success action
42
+ if(!empty($result['success'])){
43
+ Mage::getSingleton('core/session')->addSuccess('Thank you for registering. Please confirm your email.');
44
+ }
45
+
46
+ $this->getResponse()->clearHeaders()->setHeader('Content-type','application/json', true);
47
+ $this->getResponse()->setBody(json_encode($result));
48
+
49
+ }
50
+
51
+ /**
52
+ * Login user and get list of websites associated to the account.
53
+ * @return [type]
54
+ * @author edudeleon
55
+ * @date 2016-02-18
56
+ */
57
+ public function loginMerchantAction(){
58
+ $request = Mage::app()->getRequest();
59
+
60
+ $result = Mage::helper('magentoconnector')->loginMerchant(
61
+ $request->getParam('email'),
62
+ $request->getParam('password')
63
+ );
64
+
65
+ $this->getResponse()->clearHeaders()->setHeader('Content-type','application/json', true);
66
+ $this->getResponse()->setBody(json_encode($result));
67
+ }
68
+
69
+ /**
70
+ * Connect Merchant's account with Hivewyre
71
+ * @return [type]
72
+ * @author edudeleon
73
+ * @date 2016-02-18
74
+ */
75
+ public function connectMerchantAction(){
76
+ $request = Mage::app()->getRequest();
77
+
78
+ $result = Mage::helper('magentoconnector')->connectMerchant(
79
+ $request->getParam('domain_id'),
80
+ $request->getParam('token'),
81
+ $request->getParam('rap')
82
+ );
83
+
84
+ //Validate Success action
85
+ if(!empty($result['success'])){
86
+ Mage::getSingleton('core/session')->addSuccess('Your account has been linked to Magento Successfully.');
87
+ }
88
+
89
+ $this->getResponse()->clearHeaders()->setHeader('Content-type','application/json', true);
90
+ $this->getResponse()->setBody(json_encode($result));
91
+ }
92
+ }
app/code/community/Hivewyre/Magentoconnector/etc/adminhtml.xml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Copyright © 2016 HiveWyre.com
5
+ * FileDescription: File used to declare admin panel sections of the extension
6
+ * @autor eduedeleon
7
+ */
8
+ -->
9
+ <config>
10
+ <acl>
11
+ <resources>
12
+ <all>
13
+ <title>Allow Everything</title>
14
+ </all>
15
+ <admin>
16
+ <children>
17
+ <system>
18
+ <children>
19
+ <config>
20
+ <children>
21
+ <hivewyre_settings>
22
+ <title>Hivewyre</title>
23
+ </hivewyre_settings>
24
+ <hivewyre_iframe>
25
+ <title>Hivewyre</title>
26
+ </hivewyre_iframe>
27
+ </children>
28
+ </config>
29
+ </children>
30
+ </system>
31
+ </children>
32
+ </admin>
33
+ </resources>
34
+ </acl>
35
+ </config>
app/code/community/Hivewyre/Magentoconnector/etc/config.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <!--
3
+ /**
4
+ * Copyright © 2016 HiveWyre.com
5
+ * FileDescription: Module config file
6
+ * @autor eduedeleon
7
+ */
8
+ -->
9
+
10
+ <config>
11
+ <!-- modules node provides basic information about the module -->
12
+ <modules>
13
+ <!-- This node's name has to be the same as module's full name including namespace -->
14
+ <Hivewyre_Magentoconnector>
15
+ <!-- Current version of module -->
16
+ <version>1.0.0</version>
17
+ </Hivewyre_Magentoconnector>
18
+ </modules>
19
+
20
+ <frontend>
21
+
22
+ <!-- Extension Layout -->
23
+ <layout>
24
+ <updates>
25
+ <magentoconnector>
26
+ <file>hivewyre_magentoconnector.xml</file>
27
+ </magentoconnector>
28
+ </updates>
29
+ </layout>
30
+
31
+ </frontend>
32
+
33
+ <!-- Global Section -->
34
+ <global>
35
+
36
+ <!-- Helper declaration -->
37
+ <helpers>
38
+ <magentoconnector>
39
+ <class>Hivewyre_Magentoconnector_Helper</class>
40
+ </magentoconnector>
41
+ </helpers>
42
+
43
+ <!-- Model declaration -->
44
+ <models>
45
+ <magentoconnector>
46
+ <class>Hivewyre_Magentoconnector_Model</class>
47
+ </magentoconnector>
48
+ </models>
49
+
50
+ <!-- Blocks declaration -->
51
+ <blocks>
52
+ <magentoconnector>
53
+ <class>Hivewyre_Magentoconnector_Block</class>
54
+ </magentoconnector>
55
+ </blocks>
56
+
57
+ </global>
58
+
59
+ <!-- Admin Panel Controller -->
60
+ <admin>
61
+ <routers>
62
+ <adminhtml>
63
+ <args>
64
+ <modules>
65
+ <Hivewyre_Magentoconnector before="Mage_Adminhtml">Hivewyre_Magentoconnector_Adminhtml</Hivewyre_Magentoconnector>
66
+ </modules>
67
+ </args>
68
+ </adminhtml>
69
+ </routers>
70
+ </admin>
71
+ </config>
app/code/community/Hivewyre/Magentoconnector/etc/system.xml ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Copyright © 2016 HiveWyre.com
5
+ * FileDescription: File used to configure the admin panel section
6
+ * @autor eduedeleon
7
+ */
8
+ -->
9
+ <config>
10
+ <tabs>
11
+ <!-- Creating the HIVEWYRE left menu section (Tab Id = "hivewyre_config") -->
12
+ <hivewyre_config translate="label" module="magentoconnector">
13
+ <label>Hivewyre</label>
14
+ <sort_order>1</sort_order>
15
+ </hivewyre_config>
16
+ </tabs>
17
+
18
+ <!-- Defining sub-sections under HIVEWYRE Left Menu -->
19
+ <sections>
20
+
21
+ <!-- Hivewyre settings -->
22
+ <hivewyre_settings translate="label" module="magentoconnector" >
23
+ <label>Hivewyre Settings</label>
24
+ <tab>hivewyre_config</tab> <!-- Will be under "hivewyre_config" -->
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>1</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
+ <groups>
31
+
32
+ <!-- Configurations accordion -->
33
+ <general translate="label">
34
+ <label>Configurations</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>10</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ <fields>
41
+ <enabled translate="label">
42
+ <label>Module Enabled</label>
43
+ <frontend_type>select</frontend_type>
44
+ <source_model>adminhtml/system_config_source_yesno</source_model>
45
+ <sort_order>10</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <comment>Hivewyre Module Enabled?</comment>
50
+ </enabled>
51
+
52
+ <siteid translate="label">
53
+ <label>Site ID</label>
54
+ <frontend_type>text</frontend_type>
55
+ <sort_order>20</sort_order>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ <comment>Site ID assigned to your domain. If you still don't have an account, click the Registeration tab below and fill the required information. If you already have an account, please click the Login tab and enter your login information to connect your site with Magento.
60
+ </comment>
61
+ </siteid>
62
+
63
+ <connected_website translate="label">
64
+ <label>Connected Website</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>30</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>1</show_in_store>
70
+ </connected_website>
71
+
72
+ </fields>
73
+ </general>
74
+
75
+ <!-- Hidden Html / Ajax calls -->
76
+ <ajaxcalls>
77
+ <frontend_model>magentoconnector/adminhtml_system_config_fieldset_ajaxcalls</frontend_model>
78
+ <sort_order>20</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>1</show_in_store>
82
+ </ajaxcalls>
83
+
84
+ <!-- Registration accordion -->
85
+ <registration translate="label">
86
+ <label>Registration (Create an account)</label>
87
+ <expanded>0</expanded>
88
+ <frontend_type>text</frontend_type>
89
+ <sort_order>30</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>1</show_in_website>
92
+ <show_in_store>1</show_in_store>
93
+ <fields>
94
+ <email translate="label">
95
+ <label>E-mail</label>
96
+ <frontend_type>text</frontend_type>
97
+ <validate>validate-email</validate>
98
+ <sort_order>10</sort_order>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>1</show_in_website>
101
+ <show_in_store>1</show_in_store>
102
+ </email>
103
+
104
+ <website_name translate="label">
105
+ <label>Website Name</label>
106
+ <frontend_type>text</frontend_type>
107
+ <sort_order>20</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <show_in_store>1</show_in_store>
111
+ <comment>Please enter your website URL without the www preface (ex. Hivewyre.com).</comment>
112
+ </website_name>
113
+
114
+ <segment translate="label">
115
+ <label>Segment</label>
116
+ <frontend_type>select</frontend_type>
117
+ <source_model>magentoconnector/config_segmentsdropdown</source_model>
118
+ <sort_order>30</sort_order>
119
+ <show_in_default>1</show_in_default>
120
+ <show_in_website>1</show_in_website>
121
+ <show_in_store>1</show_in_store>
122
+ <comment>Please select the category that best describes your site.</comment>
123
+ </segment>
124
+
125
+ <password translate="label">
126
+ <label>Password</label>
127
+ <frontend_type>password</frontend_type>
128
+ <sort_order>40</sort_order>
129
+ <show_in_default>1</show_in_default>
130
+ <show_in_website>1</show_in_website>
131
+ <show_in_store>1</show_in_store>
132
+ <comment>The password must be at least 6 characters long. <![CDATA[<button class="register" onclick="registerMerchant(); return false;" style="width: 89%; height: 30px;font-size: 16px;"> Register </button><div id="hivewyre-api-register-results"></div>]]></comment>
133
+ </password>
134
+ </fields>
135
+ </registration>
136
+
137
+ <!-- Login accordion -->
138
+ <login translate="label">
139
+ <label>Login</label>
140
+ <expanded>0</expanded>
141
+ <frontend_type>text</frontend_type>
142
+ <sort_order>40</sort_order>
143
+ <show_in_default>1</show_in_default>
144
+ <show_in_website>1</show_in_website>
145
+ <show_in_store>1</show_in_store>
146
+ <comment>If you have a Hivewyre account already, please enter your email password. Click “Get websites” to get a list of your registered domains that you already added to the Hivewyre Market Insights platform. Choose ONLY websites that are Magento eCommerce sites. Once you have chosen the website to connect with the Market Insights extension, click “connect website” and your site will be connected. </comment>
147
+ <fields>
148
+ <email translate="label">
149
+ <label>E-mail</label>
150
+ <frontend_type>text</frontend_type>
151
+ <sort_order>10</sort_order>
152
+ <show_in_default>1</show_in_default>
153
+ <show_in_website>1</show_in_website>
154
+ <show_in_store>1</show_in_store>
155
+ </email>
156
+
157
+ <password translate="label">
158
+ <label>Password</label>
159
+ <frontend_type>password</frontend_type>
160
+ <sort_order>20</sort_order>
161
+ <show_in_default>1</show_in_default>
162
+ <show_in_website>1</show_in_website>
163
+ <show_in_store>1</show_in_store>
164
+ <comment><![CDATA[<button class="login" onclick="loginMerchant(); return false;" style="margin-left: 70px; height: 25px;"> Get Websites </button><div id="hivewyre-api-login-results"></div>]]></comment>
165
+ </password>
166
+
167
+ <website translate="label">
168
+ <label>Website</label>
169
+ <frontend_type>select</frontend_type>
170
+ <source_model>magentoconnector/config_websitesdropdown</source_model>
171
+ <sort_order>30</sort_order>
172
+ <show_in_default>1</show_in_default>
173
+ <show_in_website>1</show_in_website>
174
+ <show_in_store>1</show_in_store>
175
+ <comment>Please select a website to connect. <![CDATA[<input type="hidden" id="token"/><button class="connect " onclick="connectMerchant(); return false;" style="width: 89%; height: 30px;font-size: 16px;"> Connect Website </button><div id="hivewyre-api-connect-results"></div>]]></comment>
176
+ </website>
177
+ </fields>
178
+ </login>
179
+
180
+ </groups>
181
+ </hivewyre_settings>
182
+
183
+ <!-- Dashbord (Iframe) -->
184
+ <hivewyre_iframe translate="label" module="magentoconnector" >
185
+ <label>Dashboard</label>
186
+ <tab>hivewyre_config</tab> <!-- Will be under "hivewyre_config" -->
187
+ <frontend_type>text</frontend_type>
188
+ <sort_order>2</sort_order>
189
+ <show_in_default>1</show_in_default>
190
+ <show_in_website>1</show_in_website>
191
+ <show_in_store>1</show_in_store>
192
+ <groups>
193
+ <info>
194
+ <frontend_model>magentoconnector/adminhtml_system_config_fieldset_info</frontend_model>
195
+ <sort_order>1</sort_order>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <show_in_store>1</show_in_store>
199
+ </info>
200
+ </groups>
201
+ </hivewyre_iframe>
202
+ </sections>
203
+ </config>
app/design/adminhtml/default/default/template/hivewyre_magentoconnector/.DS_Store ADDED
Binary file
app/design/adminhtml/default/default/template/hivewyre_magentoconnector/system/.DS_Store ADDED
Binary file
app/design/adminhtml/default/default/template/hivewyre_magentoconnector/system/config/.DS_Store ADDED
Binary file
app/design/adminhtml/default/default/template/hivewyre_magentoconnector/system/config/fieldset/ajaxcalls.phtml ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+
3
+ /**
4
+ * Get Dropdown segments (Ajax Call)
5
+ * @return {[type]}
6
+ * @author edudeleon
7
+ * @date 2016-02-09
8
+ */
9
+ function getDropdownSegments() {
10
+ var request = new Ajax.Request('<?php echo $this->getUrl('adminhtml/magentoconnector/getSegments'); ?>', {
11
+ method: 'get',
12
+ onSuccess: function(result) {
13
+
14
+ var options = result.responseJSON;
15
+ if(options.length !== 0){
16
+ for(var k in options){
17
+ var x = document.getElementById("hivewyre_settings_registration_segment");
18
+ var option = document.createElement("option");
19
+ option.value = k;
20
+ option.text = options[k];
21
+ x.add(option);
22
+ }
23
+ }
24
+ }
25
+ });
26
+ }
27
+
28
+ /**
29
+ * Gets the params from the Registration section and makes an Ajax call to register the Merchant
30
+ * @return {[type]}
31
+ * @author edudeleon
32
+ * @date 2016-02-09
33
+ */
34
+ function registerMerchant(){
35
+ var request = new Ajax.Request('<?php echo $this->getUrl('adminhtml/magentoconnector/registerMerchant'); ?>', {
36
+ method: 'get',
37
+ parameters: {
38
+ email: document.getElementById('hivewyre_settings_registration_email').value,
39
+ website: document.getElementById('hivewyre_settings_registration_website_name').value,
40
+ segment: document.getElementById('hivewyre_settings_registration_segment').value,
41
+ password: document.getElementById('hivewyre_settings_registration_password').value,
42
+ },
43
+
44
+ onCreate: function() {
45
+ document.getElementById('hivewyre-api-register-results').innerHTML = '';
46
+ },
47
+
48
+ onSuccess: function(result) {
49
+
50
+ if(!result.responseJSON.success){
51
+ var message = '<ul class = "messages">'+'<li class="error-msg">'+result.responseJSON.msg+'</li>'+'</ul>';
52
+ document.getElementById('hivewyre-api-register-results').innerHTML = message;
53
+
54
+ } else {
55
+ //Set Site ID
56
+ $('hivewyre_settings_general_siteid').value = result.responseJSON.site_id;
57
+
58
+ //Set Website Name
59
+ $('hivewyre_settings_general_connected_website').value = document.getElementById('hivewyre_settings_registration_website_name').value;
60
+
61
+ //Submit Form
62
+ configForm.submit();
63
+ }
64
+ }
65
+ });
66
+
67
+ return false;
68
+ }
69
+
70
+ /**
71
+ * Login merchant and list the available websites
72
+ * @return {[type]}
73
+ * @author edudeleon
74
+ * @date 2016-02-19
75
+ */
76
+ function loginMerchant(){
77
+ var request = new Ajax.Request('<?php echo $this->getUrl('adminhtml/magentoconnector/loginMerchant'); ?>', {
78
+ method: 'get',
79
+ parameters: {
80
+ email: document.getElementById('hivewyre_settings_login_email').value,
81
+ password: document.getElementById('hivewyre_settings_login_password').value,
82
+ },
83
+ onCreate: function() {
84
+ document.getElementById('hivewyre-api-login-results').innerHTML = "";
85
+ },
86
+ onSuccess: function(result) {
87
+
88
+ if(!result.responseJSON.success){
89
+ var message = '<ul class = "messages">'+'<li class="error-msg">'+result.responseJSON.msg+'</li>'+'</ul>';
90
+ document.getElementById('hivewyre-api-login-results').innerHTML = message;
91
+
92
+ } else {
93
+ //clear any msg
94
+ document.getElementById('hivewyre-api-login-results').innerHTML = "";
95
+
96
+ //Clear select options
97
+ $('hivewyre_settings_login_website').select('option').invoke('remove');
98
+
99
+ //Set token value
100
+ document.getElementById('token').value = result.responseJSON.token;
101
+ var websites = result.responseJSON.sites;
102
+
103
+ if(websites.length !== 0){
104
+ for(var k in websites){
105
+ var x = document.getElementById("hivewyre_settings_login_website");
106
+ var option = document.createElement("option");
107
+
108
+ var option_text = websites[k];
109
+ option.value = k;
110
+ option.text = option_text;
111
+
112
+ if(!(option_text.search("Magento.com") != -1 || option_text.search("Not Connected") != -1)){
113
+ option.disabled = true;
114
+ }
115
+
116
+ x.add(option);
117
+ }
118
+ } else {
119
+ var message = '<ul class = "messages">'+'<li class="error-msg">'+"There are no domains available for this account."+'</li>'+'</ul>';
120
+ document.getElementById('hivewyre-api-login-results').innerHTML = message;
121
+ }
122
+
123
+ }
124
+ }
125
+ });
126
+
127
+ return false;
128
+ }
129
+
130
+ /**
131
+ * Connect Magento Store with Hivewyre
132
+ * @return {[type]}
133
+ * @author edudeleon
134
+ * @date 2016-02-19
135
+ */
136
+ function connectMerchant(){
137
+ //Site ID
138
+ var website_select = document.getElementById('hivewyre_settings_login_website');
139
+ var site_id = website_select.value;
140
+ if(!site_id || site_id == 0){
141
+ alert("You need to select a website to connect.");
142
+ return false;
143
+ }
144
+ var website_name = website_select.options[website_select.selectedIndex].text;
145
+
146
+
147
+ //Connect Site
148
+ var request = new Ajax.Request('<?php echo $this->getUrl('adminhtml/magentoconnector/connectMerchant'); ?>', {
149
+ method: 'get',
150
+ parameters: {
151
+ domain_id: site_id,
152
+ token: document.getElementById('token').value,
153
+ rap: '<?php echo Hivewyre_Magentoconnector_Model_Config::MAGENTO_RAP?>'
154
+ },
155
+
156
+ onCreate: function() {
157
+ document.getElementById('hivewyre-api-connect-results').innerHTML = '';
158
+ },
159
+
160
+ onSuccess: function(result) {
161
+ //If fail
162
+ if(!result.responseJSON.success){
163
+ var message = '<ul class = "messages">'+'<li class="error-msg">'+result.responseJSON.msg+'</li>'+'</ul>';
164
+ document.getElementById('hivewyre-api-connect-results').innerHTML = message;
165
+
166
+ //Successfull connection
167
+ } else {
168
+ //Set Site ID
169
+ $('hivewyre_settings_general_siteid').value = result.responseJSON.site_id;
170
+
171
+ //Set Website Name
172
+ website_name = website_name.replace("(Connected to Magento.com)", "");
173
+ website_name = website_name.replace("(Not Connected)", "");
174
+ $('hivewyre_settings_general_connected_website').value = website_name;
175
+
176
+ //Submit Form
177
+ configForm.submit();
178
+ }
179
+ }
180
+ });
181
+
182
+ return false;
183
+ }
184
+
185
+ /**
186
+ * Set website name
187
+ * @author edudeleon
188
+ * @date 2016-02-25
189
+ */
190
+ function setWebisteName(){
191
+ var website_name = document.getElementById('hivewyre_settings_registration_website_name').value;
192
+ if(!website_name){
193
+ $('hivewyre_settings_registration_website_name').value = window.location.hostname;
194
+ }
195
+ }
196
+
197
+ document.observe("dom:loaded", function() {
198
+ //Get segments onload
199
+ getDropdownSegments();
200
+
201
+ //Set sitename if empty
202
+ setWebisteName();
203
+
204
+ // Disable Site Id and Connected fields
205
+ $('hivewyre_settings_general_siteid').setAttribute('readonly','readonly');
206
+ $('hivewyre_settings_general_siteid').addClassName('disabled');
207
+ $('hivewyre_settings_general_connected_website').setAttribute('readonly','readonly');
208
+ $('hivewyre_settings_general_connected_website').addClassName('disabled');
209
+ });
210
+ </script>
app/design/adminhtml/default/default/template/hivewyre_magentoconnector/system/config/fieldset/info.phtml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <!-- Hivewyre Iframe -->
2
+ <fieldset>
3
+
4
+ <h2><a href="<?php echo Hivewyre_Magentoconnector_Model_Config::ENDPOINT_URL ?>" target="_blank" style="float:left;">Open in new tab</a></h2></br>
5
+ <iframe src="<?php echo Hivewyre_Magentoconnector_Model_Config::ENDPOINT_URL ?>" style="width: 100%; height: 480px"></iframe>
6
+
7
+ </fieldset>
app/design/frontend/base/default/layout/hivewyre_magentoconnector.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Copyright © 2016 HiveWyre.com
5
+ * Layout File
6
+ * @autor eduedeleon
7
+ */
8
+ -->
9
+
10
+ <layout version="1.0.0">
11
+ <default>
12
+ <!-- Hivewyre Tracking Block -->
13
+ <reference name="head">
14
+ <block type="magentoconnector/tracking" name="hivewyre_tracking" as="hivewyre_tracking" template="hivewyre_magentoconnector/tracking.phtml"/>
15
+ </reference>
16
+ </default>
17
+
18
+ <!-- Hivewyre Conversion Block -->
19
+ <checkout_onepage_success>
20
+ <reference name="head">
21
+ <remove name="hivewyre_tracking"/>
22
+
23
+ <block type="magentoconnector/conversion" name="hivewyre_conversion" as="hivewyre_conversion" template="hivewyre_magentoconnector/conversion.phtml" />
24
+ </reference>
25
+ </checkout_onepage_success>
26
+ </layout>
app/design/frontend/base/default/template/hivewyre_magentoconnector/conversion.phtml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Hivewyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+ ?>
7
+
8
+ <!-- HiveWyre conversion code -->
9
+ <script src="<?php echo $this->getConversionScriptUrl();?>"></script>
app/design/frontend/base/default/template/hivewyre_magentoconnector/tracking.phtml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Hivewyre.com
4
+ * @autor eduedeleon
5
+ * */
6
+ ?>
7
+
8
+ <!-- HiveWyre tracking code -->
9
+ <script src="<?php echo $this->getTrackingScriptUrl();?>"></script>
app/etc/modules/Hivewyre_Magentoconnector.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Copyright © 2016 HiveWyre.com
5
+ * FileDescription: Module Config
6
+ * @autor eduedeleon
7
+ */
8
+ -->
9
+ <config>
10
+ <!-- the same block we have in module's config.xml -->
11
+ <modules>
12
+ <!-- This node's name has to be the same as module's full name including namespace -->
13
+ <Hivewyre_Magentoconnector>
14
+ <!-- flag indicating weather module is active or not -->
15
+ <active>true</active>
16
+ <!-- code pool -->
17
+ <codePool>community</codePool>
18
+ </Hivewyre_Magentoconnector>
19
+ </modules>
20
+ </config>
package.xml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Hivewyre_Magentoconnector</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The only analytics tool that measures consumers' interactions between your store and your competitors.</summary>
10
+ <description>Know your competitors. Know yourself.&#xD;
11
+ &#xD;
12
+ Compare your site's performance to your competitor's.&#xD;
13
+ &#xD;
14
+ &#xD;
15
+ Compare your site's performance to your competitor's in real-time.&#xD;
16
+ &#xD;
17
+ Make sound business decisions without fear.&#xD;
18
+ &#xD;
19
+ Spend your marketing and advertising budget more effectively.&#xD;
20
+ &#xD;
21
+ &#xD;
22
+ With a seamless installation process, you can have access to more consumer &#xD;
23
+ &#xD;
24
+ data than you ever thought possible -100% FREE.&#xD;
25
+ &#xD;
26
+ This is the only analytical tool out there that shows you how consumers &#xD;
27
+ &#xD;
28
+ are interacting with your Magento site and your competitors' sites. We &#xD;
29
+ &#xD;
30
+ ad over 100-million unique prospective customersmonthly to our data &#xD;
31
+ &#xD;
32
+ co-op, which gives you insights into your eCommerce business like never &#xD;
33
+ &#xD;
34
+ before.&#xD;
35
+ &#xD;
36
+ &#xD;
37
+ What Is This Awesome Data We Have for You?&#xD;
38
+ &#xD;
39
+ With Market Insights, you have real data in real-time on the following:&#xD;
40
+ &#xD;
41
+ &#xD;
42
+ &#xD;
43
+ Awareness Rating - % of consumers in your segment that have visited &#xD;
44
+ &#xD;
45
+ your site for the past 7 days.&#xD;
46
+ &#xD;
47
+ Win Percentage - % of consumers that have visited your site and at &#xD;
48
+ &#xD;
49
+ least one other in your segment, but chose to purchase from you.&#xD;
50
+ &#xD;
51
+ Unique Users - Number of unique users in your segment.&#xD;
52
+ &#xD;
53
+ Top Cross Categories - Visitors within your segment also frequent &#xD;
54
+ &#xD;
55
+ these categories.&#xD;
56
+ &#xD;
57
+ Revenue Per Visitor - The revenue per visitor on your site.&#xD;
58
+ &#xD;
59
+ &#xD;
60
+ &#xD;
61
+ Know your competitors&#xD;
62
+ &#xD;
63
+ Knowledge is power. The knowledge Market Insights data will bring you is &#xD;
64
+ &#xD;
65
+ more informed, confident and shrewd businesses decisions than ever before, &#xD;
66
+ &#xD;
67
+ because for the first time you are seeing a much fuller picture of your &#xD;
68
+ &#xD;
69
+ business, your place in the segment you're in and how consumers within this &#xD;
70
+ &#xD;
71
+ segment are interacting with you and your competitors.&#xD;
72
+ &#xD;
73
+ &#xD;
74
+ Get These Insights Quickly!&#xD;
75
+ &#xD;
76
+ You don't need to leave Magento to set up the Market Insights Extension.&#xD;
77
+ &#xD;
78
+ &#xD;
79
+ We Want Your Feedback&#xD;
80
+ &#xD;
81
+ This is an exciting time for us at Hivewyre! We are proud of our Market &#xD;
82
+ &#xD;
83
+ Insights tool and how it will provide eCommerce owners with powerful data &#xD;
84
+ &#xD;
85
+ that they could never get for free anywhere else. Please reach out to us with &#xD;
86
+ &#xD;
87
+ any questions or comments (marketinsights@hivewyre.com).</description>
88
+ <notes>First release version.</notes>
89
+ <authors><author><name>Eduardo De Le&#xF3;n</name><user>edudeleon</user><email>edudeleon@gmail.com</email></author></authors>
90
+ <date>2016-03-09</date>
91
+ <time>23:07:07</time>
92
+ <contents><target name="magecommunity"><dir name="Hivewyre"><dir name="Magentoconnector"><dir name="Block"><file name="Abstract.php" hash="adc7e2f6141ab0dd4b29db84b2d472e1"/><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Ajaxcalls.php" hash="2932e500f6f51475cff25c4a19041860"/><file name="Info.php" hash="c4e4f2f8ae60f2f60de2d60b34bbc39a"/></dir></dir></dir></dir><file name="Conversion.php" hash="1c3958ae44860b67f81519927e1230ea"/><file name="Tracking.php" hash="62a065d82371ccf7f7be91c353183096"/></dir><dir name="Helper"><file name="Data.php" hash="de8586ce96a1c602c1e69a0905379e3f"/></dir><dir name="Model"><dir name="Api"><file name="Abstract.php" hash="bf52569972f63701097082369c63da61"/><file name="Accounts.php" hash="d9080eee843deea493d3f115bf496c5b"/></dir><dir name="Config"><file name="Segmentsdropdown.php" hash="ad859f5cd713d844d8f74dc1d714f327"/><file name="Websitesdropdown.php" hash="25cf17240801ef32ef322b8b0c9b4362"/></dir><file name="Config.php" hash="af4ea74087ed78d842cf5a3e4f7bc5ff"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="MagentoconnectorController.php" hash="0a6ca352495c801fb1570e01aa3cef4a"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="8005e62add10d1300131815e3a077059"/><file name="config.xml" hash="cf0e5fd5fd4bf35100c7cab095903c0a"/><file name="system.xml" hash="8f91a6466c222d28f04bfe725d10fc8a"/></dir><file name=".DS_Store" hash="84e2e7bcbcec035c3177e2293dcb81de"/></dir><file name=".DS_Store" hash="fc9bd4bdfae9485d49fb0c5e085e567c"/></dir></target><target name="mageetc"><dir name="modules"><file name="Hivewyre_Magentoconnector.xml" hash="a2a3bb2852cc51ab460e27b54188c838"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="hivewyre_magentoconnector.xml" hash="26436730ff1dc6b9cbe6d7c46b9273d1"/></dir><dir name="template"><dir name="hivewyre_magentoconnector"><file name="conversion.phtml" hash="c66ff182b12bd3b522d4a2ebfbdb6952"/><file name="tracking.phtml" hash="02b988afbcffae71d1f418ce4695bd3f"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="hivewyre_magentoconnector"><dir name="system"><dir name="config"><dir name="fieldset"><file name="ajaxcalls.phtml" hash="26e576a12607b6438d71aab2b284f4ba"/><file name="info.phtml" hash="d2ce07862836bcd502ea285236792d8e"/></dir><file name=".DS_Store" hash="445b031dd16e4ede6ad536d3ebde8d3d"/></dir><file name=".DS_Store" hash="bfc3ba4e57655414cea516ff864d5d79"/></dir><file name=".DS_Store" hash="9098b70eecda801dd77538d307120880"/></dir></dir></dir></dir></dir></target></contents>
93
+ <compatible/>
94
+ <dependencies><required><php><min>5.3.0</min><max>7.0.0</max></php></required></dependencies>
95
+ </package>