SimpleRelevance_Integration - Version 1.5.1

Version Notes

-- version 1.5.1
Updated for wider Magento support

-- version 1.5.0
Updated for our new API with SSL

-- version 1.0.4
Security Update

-- version 1.0.3
what 1.0.2 should be

-- version 1.0.2
better url support

-- version 1.0.1
Making all request async by default

-- version 1.0.0
Rename of dict parameter on inventory items

-- version 0.0.9
Category IDS names instead of integers when sending inventory items

-- version 0.0.8
Allowing to send ALL products and customers on each save

-- version 0.0.7
Bug fix on auto submit products and users on Magento 1.6.2.0

-- version 0.0.6
Correcting but on orders export (timestamp)

-- version 0.0.5
Automatic Customer and Product submission

-- version 0.0.4
Bug fixes, new data on product import, debug facility

-- version 0.0.1
First release

Download this release

Release Info

Developer SimpleRelevance
Extension SimpleRelevance_Integration
Version 1.5.1
Comparing to
See all releases


Code changes from version 1.0.4 to 1.5.1

Files changed (27) hide show
  1. app/code/community/SimpleRelevance/Integration/Helper/Data.php +52 -54
  2. app/code/community/SimpleRelevance/Integration/Helper/Data.php~ +0 -99
  3. app/code/community/SimpleRelevance/Integration/Model/Api.php +146 -183
  4. app/code/community/SimpleRelevance/Integration/Model/Api.php~ +0 -256
  5. app/code/community/SimpleRelevance/Integration/Model/Observer.php +126 -108
  6. app/code/community/SimpleRelevance/Integration/Model/Observer.php~ +0 -230
  7. app/code/community/SimpleRelevance/Integration/Model/Prediction.php +0 -9
  8. app/code/community/SimpleRelevance/Integration/Model/Prediction.php~ +0 -22
  9. app/code/community/SimpleRelevance/Integration/Model/Purchase.php +35 -34
  10. app/code/community/SimpleRelevance/Integration/controllers/Adminhtml/ExportController.php +157 -116
  11. app/code/community/SimpleRelevance/Integration/controllers/Adminhtml/IndexController.php~ +0 -9
  12. app/code/community/SimpleRelevance/Integration/controllers/Adminhtml/InputController.php~ +0 -22
  13. app/code/community/SimpleRelevance/Integration/controllers/IndexController.php +0 -76
  14. app/code/community/SimpleRelevance/Integration/controllers/IndexController.php~ +0 -63
  15. app/code/community/SimpleRelevance/Integration/controllers/InputController.php +0 -47
  16. app/code/community/SimpleRelevance/Integration/controllers/InputController.php~ +0 -44
  17. app/code/community/SimpleRelevance/Integration/demo.phtml +0 -11
  18. app/code/community/SimpleRelevance/Integration/demo.phtml~ +0 -16
  19. app/code/community/SimpleRelevance/Integration/etc/config.xml~ +0 -110
  20. app/code/community/SimpleRelevance/Integration/etc/system.xml +13 -4
  21. {skin → app/design}/adminhtml/default/default/simple_relevance/css.css +0 -0
  22. {skin → app/design}/adminhtml/default/default/simple_relevance/images/box-tab.png +0 -0
  23. {skin → app/design}/adminhtml/default/default/simple_relevance/images/simplerelevance-header.png +0 -0
  24. {skin → app/design}/adminhtml/default/default/simple_relevance/js.js +0 -0
  25. app/etc/modules/SimpleRelevance_Integration.xml +1 -1
  26. app/locale/en_US/SimpleRelevance_Integration.csv +1 -1
  27. package.xml +46 -6
app/code/community/SimpleRelevance/Integration/Helper/Data.php CHANGED
@@ -9,42 +9,42 @@
9
  class SimpleRelevance_Integration_Helper_Data extends Mage_Core_Helper_Abstract
10
  {
11
 
12
- /**
13
- * Get module User-Agent to use on API requests
14
- *
15
- * @return string
16
- */
17
- public function getUserAgent()
18
- {
19
- $modules = Mage::getConfig()->getNode('modules')->children();
20
- $modulesArray = (array)$modules;
21
 
22
- $mageType = (array_key_exists('Enterprise_Enterprise', $modulesArray))? 'EE' : 'CE' ;
23
- $v = (string)Mage::getConfig()->getNode('modules/SimpleRelevance_Integration/version');
24
 
25
- return (string)'SimpleRelevance' . $v . '/Mage'. $mageType . Mage::getVersion();
26
- }
27
 
28
- /**
29
- * Retrieve configuration data from database
30
- *
31
- * @param string $value Value to get
32
- * @return mixed
33
- */
34
- public function config($value)
35
- {
36
- return Mage::getStoreConfig("simple_relevance/general/$value");
37
- }
38
 
39
- /**
40
- * Check module status
41
- *
42
- * @return bool
43
- */
44
- public function enabled()
45
- {
46
- return (bool)((int)$this->config('active') === 1);
47
- }
48
 
49
  /**
50
  * Return produt dict params to send to the API
@@ -55,47 +55,45 @@ class SimpleRelevance_Integration_Helper_Data extends Mage_Core_Helper_Abstract
55
  public function getProductDict(Mage_Catalog_Model_Product $product)
56
  {
57
  $smallImageUrl = '';
58
- if($product->getSmallImage()){
59
- try{
60
- //$smallImageUrl = Mage::helper('catalog/image')->init($product, 'small_image')->resize(75);
61
- $smallImageUrl = Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getSmallImage() );
62
- }catch(Exception $e){
63
  Mage::logException($e);
64
  }
65
  }
 
66
  $baseImageUrl = '';
67
- if($product->getImage()){
68
- try{
69
- //$baseImageUrl = Mage::helper('catalog/image')->init($product, 'image');
70
- $baseImageUrl = Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getImage() );
71
- }catch(Exception $e){
72
  Mage::logException($e);
73
  }
74
  }
75
 
76
- //Category names
77
  $categoryIds = $product->getCategoryIds();
78
  $categories = array();
79
- if(is_array($categoryIds) && !empty($categoryIds)){
80
- foreach($categoryIds as $_catId){
81
 
82
  $cat = Mage::getModel('catalog/category')->load($_catId);
83
  if($cat->getId()){
84
  $categories []= $cat->getName();
85
  }
86
-
87
  }
88
  }
89
 
90
  $dict = array(
91
- 'item_url' => $product->getProductUrl(),
92
- 'price' => $product->getPrice(),
93
- 'sku' => $product->getSku(),
94
- 'categories' => $categories,
95
- 'image_url_small' => (string)$smallImageUrl,
96
- 'image_url' => (string)$baseImageUrl,
97
- 'description' => $product->getDescription(),
98
- );
99
  return $dict;
100
  }
101
  }
9
  class SimpleRelevance_Integration_Helper_Data extends Mage_Core_Helper_Abstract
10
  {
11
 
12
+ /**
13
+ * Get module User-Agent to use on API requests
14
+ *
15
+ * @return string
16
+ */
17
+ public function getUserAgent()
18
+ {
19
+ $modules = Mage::getConfig()->getNode('modules')->children();
20
+ $modulesArray = (array)$modules;
21
 
22
+ $mageType = (array_key_exists('Enterprise_Enterprise', $modulesArray))? 'EE' : 'CE' ;
23
+ $v = (string)Mage::getConfig()->getNode('modules/SimpleRelevance_Integration/version');
24
 
25
+ return (string)'SimpleRelevance' . $v . '/Mage'. $mageType . Mage::getVersion();
26
+ }
27
 
28
+ /**
29
+ * Retrieve configuration data from database
30
+ *
31
+ * @param string $value Value to get
32
+ * @return mixed
33
+ */
34
+ public function config($value)
35
+ {
36
+ return Mage::getStoreConfig("simple_relevance/general/$value");
37
+ }
38
 
39
+ /**
40
+ * Check module status
41
+ *
42
+ * @return bool
43
+ */
44
+ public function enabled()
45
+ {
46
+ return (bool)((int)$this->config('active') === 1);
47
+ }
48
 
49
  /**
50
  * Return produt dict params to send to the API
55
  public function getProductDict(Mage_Catalog_Model_Product $product)
56
  {
57
  $smallImageUrl = '';
58
+ if($product->getSmallImage()) {
59
+ try {
60
+ $smallImageUrl = Mage::helper('catalog/image')->init($product, 'small_image')->resize(75);
61
+ } catch(Exception $e) {
 
62
  Mage::logException($e);
63
  }
64
  }
65
+
66
  $baseImageUrl = '';
67
+ if ($product->getImage()) {
68
+ try {
69
+ $baseImageUrl = Mage::helper('catalog/image')->init($product, 'image');
70
+ } catch(Exception $e) {
 
71
  Mage::logException($e);
72
  }
73
  }
74
 
75
+ // Category names
76
  $categoryIds = $product->getCategoryIds();
77
  $categories = array();
78
+ if (is_array($categoryIds) && !empty($categoryIds)) {
79
+ foreach($categoryIds as $_catId) {
80
 
81
  $cat = Mage::getModel('catalog/category')->load($_catId);
82
  if($cat->getId()){
83
  $categories []= $cat->getName();
84
  }
 
85
  }
86
  }
87
 
88
  $dict = array(
89
+ 'item_url' => $product->getUrlPath(),
90
+ 'price' => $product->getPrice(),
91
+ 'sku' => $product->getSku(),
92
+ 'categories' => $categories,
93
+ 'image_url_small' => (string)$smallImageUrl,
94
+ 'image_url' => (string)$baseImageUrl,
95
+ 'description' => $product->getDescription(),
96
+ );
97
  return $dict;
98
  }
99
  }
app/code/community/SimpleRelevance/Integration/Helper/Data.php~ DELETED
@@ -1,99 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * SimpleRelevance Integration main helper
5
- *
6
- * @category SimpleRelevance
7
- * @package SimpleRelevance_Integration
8
- */
9
- class SimpleRelevance_Integration_Helper_Data extends Mage_Core_Helper_Abstract
10
- {
11
-
12
- /**
13
- * Get module User-Agent to use on API requests
14
- *
15
- * @return string
16
- */
17
- public function getUserAgent()
18
- {
19
- $modules = Mage::getConfig()->getNode('modules')->children();
20
- $modulesArray = (array)$modules;
21
-
22
- $mageType = (array_key_exists('Enterprise_Enterprise', $modulesArray))? 'EE' : 'CE' ;
23
- $v = (string)Mage::getConfig()->getNode('modules/SimpleRelevance_Integration/version');
24
-
25
- return (string)'SimpleRelevance' . $v . '/Mage'. $mageType . Mage::getVersion();
26
- }
27
-
28
- /**
29
- * Retrieve configuration data from database
30
- *
31
- * @param string $value Value to get
32
- * @return mixed
33
- */
34
- public function config($value)
35
- {
36
- return Mage::getStoreConfig("simple_relevance/general/$value");
37
- }
38
-
39
- /**
40
- * Check module status
41
- *
42
- * @return bool
43
- */
44
- public function enabled()
45
- {
46
- return (bool)((int)$this->config('active') === 1);
47
- }
48
-
49
- /**
50
- * Return produt dict params to send to the API
51
- *
52
- * @param Mage_Catalog_Model_Product
53
- * @return array
54
- */
55
- public function getProductDict(Mage_Catalog_Model_Product $product)
56
- {
57
- $smallImageUrl = '';
58
- if($product->getSmallImage()){
59
- try{
60
- $smallImageUrl = Mage::helper('catalog/image')->init($product, 'small_image')->resize(75);
61
- }catch(Exception $e){
62
- Mage::logException($e);
63
- }
64
- }
65
- $baseImageUrl = '';
66
- if($product->getImage()){
67
- try{
68
- $baseImageUrl = Mage::helper('catalog/image')->init($product, 'image');
69
- }catch(Exception $e){
70
- Mage::logException($e);
71
- }
72
- }
73
-
74
- //Category names
75
- $categoryIds = $product->getCategoryIds();
76
- $categories = array();
77
- if(is_array($categoryIds) && !empty($categoryIds)){
78
- foreach($categoryIds as $_catId){
79
-
80
- $cat = Mage::getModel('catalog/category')->load($_catId);
81
- if($cat->getId()){
82
- $categories []= $cat->getName();
83
- }
84
-
85
- }
86
- }
87
-
88
- $dict = array(
89
- 'item_url' => $product->getUrlPath(),
90
- 'price' => $product->getPrice(),
91
- 'sku' => $product->getSku(),
92
- 'categories' => $categories,
93
- 'image_url_small' => (string)$smallImageUrl,
94
- 'image_url' => (string)$baseImageUrl,
95
- 'description' => $product->getDescription(),
96
- );
97
- return $dict;
98
- }
99
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/Model/Api.php CHANGED
@@ -8,234 +8,195 @@
8
  */
9
  class SimpleRelevance_Integration_Model_Api
10
  {
11
- /**
12
- * API version number
13
- *
14
- * @var string
15
- */
16
- public $version = '2';
17
-
18
- /**
19
- * Error Message storage
20
- *
21
- * @var string
22
- */
23
  public $errorMessage;
24
 
25
- /**
26
- * Error Code storage
27
- *
28
- * @var integer
29
- */
30
  public $errorCode;
31
 
32
- /**
33
- * Cache the user api_key so we only have to log in once per client instantiation
34
- *
35
- * @var string SimpleRelevance API key
36
- */
37
  public $api_key;
38
 
39
- /**
40
- * This decides whether the request will wait for completion or start a task and return immediately.
41
- * Can be 0 (wait) or 1 (asynchronous)
42
- *
43
- * @var int
44
- */
 
 
 
 
 
 
 
45
  public $async = 1;
46
 
47
- /**
48
- * STS API URL
49
- *
50
- * @var string
51
- */
52
  public $apiUrl;
53
 
54
  /**
55
  * Setup data
56
  *
57
- * @param string $apikey Your SimpleRelevance apikey
58
- * @param string $secure Whether or not this should use a secure connection
59
  */
60
- function __construct($apikey = null)
61
  {
62
- if($apikey){
63
- $this->setApiKey($apikey);
64
- }
65
  }
66
 
67
- /**
68
- * Api key setter
69
- *
70
- * @param string $key API Key
71
- * @return SimpleRelevance_Integration_Model_Api
72
- */
73
- public function setApiKey($key)
74
- {
75
- $this->api_key = $key;
76
-
77
  $this->apiUrl = "https://www.simplerelevance.com/api/v{$this->version}/";
78
-
79
  return $this;
80
- }
81
-
82
- /**
83
- * Action: POST
84
- * Parameters:
85
- * api_key - email tech@simplerelevance.com if you do not have an api key.
86
- * item_id (optional-see below) - ID of the item clicked.
87
- * user_id (optional-see below) - ID of the user clicking the item.
88
- * timestamp (optional) - UTC Timestamp for the click. If not supplied, the current date/time will be used. Format is like “01/31/2011 14:54:53”.
89
- * price (optional) - can be a float
90
- * email (optional) - if you do not include a user_id, you can identify a user by email address
91
- * item_name (optional) - if you do not include an item_id, you can identify an item by the name with which you input it into SimpleRelevance
92
- * item_type (optional) - if you are matching by name and not item_id, supplying the same value here which you used on the inital input into SimpleRelevance will help find your item.
93
- * zipcode (optional) - if the user is not yet in the system, this zipcode will help determine the user’s location.
94
- * Notes: the timestamp is used to differentiate multiple actions with the same deal and user. If you don’t supply one, the SimpleRelevance system will not create save a new user action, and will simply update the old one with whatever new data you supply (price, for instance).
95
- */
96
- public function postClicks()
97
- {
98
- }
99
-
100
- /**
101
- * Action: POST
102
- * Parameters:
103
- * All parameters and notes from the CLICKS hook apply here.
104
- */
105
- public function postPurchases($data = array())
106
- {
107
- return $this->_callServer('purchases', 'post', $data);
108
- }
109
-
110
- /**
111
- * Action: POST
112
- * Parameters:
113
- * api_key
114
- * item_name - The item’s name - this should be unique across your database if possible.
115
- * item_id - a unique ID for the item from your database.
116
- * item_type (optional) - this helps the SimpleRelevance system find semantic data for your item. You can use any string you want here, but ‘business’ should be used for actual, real-world businesses.
117
- * data_dict - a json encoded dictionary. This can have any attributes at all that apply to your item; the more the better. See below for the list of reserved attribute names - these help SimpleRelevance create semantic connections about your items. Note that these include ‘starts’ and ‘expires’, in case your items are time sensitive.
118
- */
119
- public function postItems($itemData = array())
120
- {
121
- return $this->_callServer('items', 'post', $itemData);
122
- }
123
-
124
- /**
125
- * Action: POST
126
- *
127
- */
128
- public function postUsers($userData = array())
129
- {
130
- return $this->_callServer('users', 'post', $userData);
131
- }
132
-
133
-
134
-
135
- /**
136
- * Action: GET
137
- * Parameters:
138
- * api_key
139
- * email - The email address of the user to return deals for
140
- * market - the general city or location for which you want items returned. Leave this blank for locationless predictions.
141
- * num_per (optional) - for business items, the number of items to return per business. For products, the number of products to return per leaf category.
142
- * starts (optional) - if you have set it when uploading the item data, then only items with a starts value after the one given here will be included in the prediction.
143
- * expires (optional) - if you have set it in the data dict when uploading item data, then only items with an expires value after the one given here will be included in the prediction.
144
- * Notes:
145
- * all returns have the key "data" unless there has been an error.
146
- * data points to a list of recommendation items.
147
- * each recommendation item has
148
- * position - starting at 0, the lower the position, the more highly recommended the item.
149
- * If positions are the same, both items come from the same business! If your items are not related to businesses and you are not using the reserved key "business_name", or if you set parameter num_per=1, this should not happen.
150
- * id_type - describes whether the item id number is from our database or yours - if you supply external ids when uploading items, which is currently a requirement, we will always return those same ids
151
- * id - the item id, hopefully of type "external" so that you can easily find it in your database*
152
- * @return string JSON dictionary
153
- */
154
- public function getItems()
155
- {
156
- }
157
 
158
  /**
159
- * Actually connect to the server and call the requested methods
160
- *
161
- * @param string $method
162
- * @param array OPTIONAL $params
163
- * @return object|false
164
  */
165
- protected function _callServer($method, $call, $params = array())
166
  {
 
 
 
167
 
168
- $this->errorMessage = null;
169
- $this->errorCode = null;
170
-
171
- $data = array();
 
 
 
 
 
 
 
 
 
172
 
173
- //Add API_KEY to request params
174
- $data['api_key'] = $this->api_key;
175
 
176
- //This decides whether the request will wait for completion
177
- //or start a task and return immediately. Can be 0 (wait) or 1 (asynchronous)
178
- $data['async'] = $this->async;
179
 
180
- //Request data
181
- $data['data'] = json_encode(array($params), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
 
 
 
 
 
 
 
 
 
 
182
 
183
- $url = $this->apiUrl . $method;
184
 
185
- $this->_log($url);
186
- $this->_log($data);
187
 
188
- $requestParams = http_build_query($data);
 
 
 
 
 
 
 
 
 
 
 
189
 
190
  $curlSession = curl_init();
191
 
192
- if($call == 'post'){
193
- curl_setopt($curlSession, CURLOPT_POST, TRUE);
194
- curl_setopt($curlSession, CURLOPT_POSTFIELDS, $requestParams);
195
- }
196
-
197
- curl_setopt($curlSession, CURLOPT_USERAGENT, Mage::helper('simple_relevance')->getUserAgent());
198
- curl_setopt($curlSession, CURLOPT_URL, $url);
199
- curl_setopt($curlSession, CURLOPT_HEADER, FALSE);
200
-
201
- curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
202
 
203
- $result = curl_exec($curlSession);
 
 
 
 
204
 
205
- $this->_log($result);
 
 
 
 
 
 
 
 
206
 
207
- if(!$result){
208
- $errstr = curl_error($curlSession);
209
- $errno = curl_errno($curlSession);
210
 
211
- $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
 
 
 
212
  $this->errorCode = "-99";
213
  return false;
214
- }
215
 
216
  // Check that a connection was made
217
  if (curl_error($curlSession)) {
218
- $this->errorMessage = curl_error($curlSession);
219
  $this->errorCode = "-99";
220
  return false;
221
  }
222
 
223
- $httpCode = curl_getinfo($curlSession, CURLINFO_HTTP_CODE);
224
 
225
- curl_close($curlSession);
226
 
227
- if($httpCode != 200){
 
 
228
 
229
- Mage::log($result, null, 'SimpleRelevance_Erros.log');
230
- Mage::log($httpCode, null, 'SimpleRelevance_Erros.log');
231
-
232
- $this->errorMessage = $result;
233
  $this->errorCode = "-99";
234
- return false;
235
- }
236
-
237
- return $result;
238
 
 
239
  }
240
 
241
  /**
@@ -244,13 +205,15 @@ class SimpleRelevance_Integration_Model_Api
244
  * @param mixed $data
245
  * @return void
246
  */
247
- protected function _log($text)
248
  {
249
- if(!Mage::getStoreConfigFlag('simple_relevance/general/debug')){
250
- return;
251
- }
252
 
253
- Mage::log($text, null, 'SimpleRelevance_Integration.log');
254
- }
255
 
256
  }
 
 
8
  */
9
  class SimpleRelevance_Integration_Model_Api
10
  {
11
+ /**
12
+ * API version number
13
+ *
14
+ * @var string
15
+ */
16
+ public $version = '3';
17
+
18
+ /**
19
+ * Error Message storage
20
+ *
21
+ * @var string
22
+ */
23
  public $errorMessage;
24
 
25
+ /**
26
+ * Error Code storage
27
+ *
28
+ * @var integer
29
+ */
30
  public $errorCode;
31
 
32
+ /**
33
+ * User API key
34
+ *
35
+ * @var string SimpleRelevance API key
36
+ */
37
  public $api_key;
38
 
39
+ /**
40
+ * User site_name
41
+ *
42
+ * @var string SimpleRelevance site name
43
+ */
44
+ public $site_name;
45
+
46
+ /**
47
+ * This decides whether the request will wait for completion or start a task and return immediately.
48
+ * Can be 0 (wait) or 1 (asynchronous)
49
+ *
50
+ * @var int
51
+ */
52
  public $async = 1;
53
 
54
+ /**
55
+ * STS API URL
56
+ *
57
+ * @var string
58
+ */
59
  public $apiUrl;
60
 
61
  /**
62
  * Setup data
63
  *
64
+ * @param array $api_sitename_arr An array of [API key, site name]
 
65
  */
66
+ function __construct($api_sitename_arr)
67
  {
68
+ if ($api_sitename_arr[0] && $api_sitename_arr[1]) {
69
+ $this->setUpAPI($api_sitename_arr[0], $api_sitename_arr[1]);
70
+ }
71
  }
72
 
73
+ /**
74
+ * API key setter
75
+ *
76
+ * @param string $key API Key
77
+ * @return SimpleRelevance_Integration_Model_Api
78
+ */
79
+ public function setUpAPI($key, $name)
80
+ {
81
+ $this->api_key = $key;
82
+ $this->site_name = $name;
83
  $this->apiUrl = "https://www.simplerelevance.com/api/v{$this->version}/";
 
84
  return $this;
85
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  /**
88
+ * Action: POST
89
+ * Post purchases.
 
 
 
90
  */
91
+ public function postPurchases($data = array())
92
  {
93
+ $data_json = json_encode($data, JSON_FORCE_OBJECT | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
94
+ return $this->_callServer('actions', 'post', $data_json);
95
+ }
96
 
97
+ /**
98
+ * Action: POST
99
+ * Post items.
100
+ */
101
+ public function postItems($itemData = array())
102
+ {
103
+ $data = array();
104
+ $data['async'] = $this->async;
105
+ $data['api_key'] = $this->api_key;
106
+ $data['site_name'] = $this->site_name;
107
+ $data['item_name'] = $itemData['item_name'];
108
+ $data['item_id'] = $itemData['item_id'];
109
+ $data['data_dict'] = $itemData['data_dict'];
110
 
111
+ $data_json = json_encode($data, JSON_FORCE_OBJECT | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
 
112
 
113
+ return $this->_callServer('items', 'post', $data_json);
114
+ }
 
115
 
116
+ /**
117
+ * Action: POST
118
+ * Post users.
119
+ */
120
+ public function postUsers($userData = array())
121
+ {
122
+ $data = array();
123
+ $data['async'] = $this->async;
124
+ $data['api_key'] = $this->api_key;
125
+ $data['site_name'] = $this->site_name;
126
+ $data['email'] = $userData['email'];
127
+ $data['user_id'] = $userData['user_id'];
128
 
129
+ $data_json = json_encode($data, JSON_FORCE_OBJECT | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
130
 
131
+ return $this->_callServer('users', 'post', $data_json);
132
+ }
133
 
134
+ /**
135
+ * Connect to the server and call the requested methods
136
+ *
137
+ * @param string $method
138
+ * @param array OPTIONAL $payload
139
+ * @return object|false
140
+ */
141
+ protected function _callServer($method, $call, $payload = array())
142
+ {
143
+ $this->errorMessage = null;
144
+ $this->errorCode = null;
145
+ $url = $this->apiUrl . $method . '/';
146
 
147
  $curlSession = curl_init();
148
 
149
+ $auth_token = base64_encode($this->site_name . ':' . $this->api_key);
150
+ $headers = array('Authorization: Basic ' . $auth_token, 'Content-Type: application/json');
 
 
 
 
 
 
 
 
151
 
152
+ if ($call == 'post') {
153
+ curl_setopt($curlSession, CURLOPT_POST, true);
154
+ curl_setopt($curlSession, CURLOPT_POSTFIELDS, $payload);
155
+ curl_setopt($curlSession, CURLOPT_FRESH_CONNECT, true);
156
+ }
157
 
158
+ curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
159
+ curl_setopt($curlSession, CURLOPT_FOLLOWLOCATION, true);
160
+ curl_setopt($curlSession, CURLOPT_CONNECTTIMEOUT, 5);
161
+ curl_setopt($curlSession, CURLOPT_TIMEOUT, 45);
162
+ curl_setopt($curlSession, CURLOPT_MAXREDIRS, 5);
163
+ curl_setopt($curlSession, CURLOPT_USERAGENT, Mage::helper('simple_relevance')->getUserAgent());
164
+ curl_setopt($curlSession, CURLOPT_URL, $url);
165
+ curl_setopt($curlSession, CURLOPT_HEADER, false);
166
+ curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);
167
 
168
+ $result = curl_exec($curlSession);
169
+ $this->_log($result);
 
170
 
171
+ if (!$result) {
172
+ $errstr = curl_error($curlSession);
173
+ $errno = curl_errno($curlSession);
174
+ $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
175
  $this->errorCode = "-99";
176
  return false;
177
+ }
178
 
179
  // Check that a connection was made
180
  if (curl_error($curlSession)) {
181
+ $this->errorMessage = curl_error($curlSession);
182
  $this->errorCode = "-99";
183
  return false;
184
  }
185
 
186
+ $httpCode = curl_getinfo($curlSession, CURLINFO_HTTP_CODE);
187
 
188
+ curl_close($curlSession);
189
 
190
+ if ($httpCode != 200 && $httpCode != 201) {
191
+ Mage::log($result, null, 'SimpleRelevance_Errors.log');
192
+ Mage::log($httpCode, null, 'SimpleRelevance_Errors.log');
193
 
194
+ $this->errorMessage = $result;
 
 
 
195
  $this->errorCode = "-99";
196
+ return false;
197
+ }
 
 
198
 
199
+ return $result;
200
  }
201
 
202
  /**
205
  * @param mixed $data
206
  * @return void
207
  */
208
+ public function _log($text)
209
  {
210
+ if (!Mage::getStoreConfigFlag('simple_relevance/general/debug')) {
211
+ return;
212
+ }
213
 
214
+ Mage::log($text, null, 'SimpleRelevance_Integration.log');
215
+ }
216
 
217
  }
218
+
219
+ ?>
app/code/community/SimpleRelevance/Integration/Model/Api.php~ DELETED
@@ -1,256 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Simple Relevance API wrapper
5
- *
6
- * @category SimpleRelevance
7
- * @package SimpleRelevance_Integration
8
- */
9
- class SimpleRelevance_Integration_Model_Api
10
- {
11
- /**
12
- * API version number
13
- *
14
- * @var string
15
- */
16
- public $version = '2';
17
-
18
- /**
19
- * Error Message storage
20
- *
21
- * @var string
22
- */
23
- public $errorMessage;
24
-
25
- /**
26
- * Error Code storage
27
- *
28
- * @var integer
29
- */
30
- public $errorCode;
31
-
32
- /**
33
- * Cache the user api_key so we only have to log in once per client instantiation
34
- *
35
- * @var string SimpleRelevance API key
36
- */
37
- public $api_key;
38
-
39
- /**
40
- * This decides whether the request will wait for completion or start a task and return immediately.
41
- * Can be 0 (wait) or 1 (asynchronous)
42
- *
43
- * @var int
44
- */
45
- public $async = 1;
46
-
47
- /**
48
- * STS API URL
49
- *
50
- * @var string
51
- */
52
- public $apiUrl;
53
-
54
- /**
55
- * Setup data
56
- *
57
- * @param string $apikey Your SimpleRelevance apikey
58
- * @param string $secure Whether or not this should use a secure connection
59
- */
60
- function __construct($apikey = null)
61
- {
62
- if($apikey){
63
- $this->setApiKey($apikey);
64
- }
65
- }
66
-
67
- /**
68
- * Api key setter
69
- *
70
- * @param string $key API Key
71
- * @return SimpleRelevance_Integration_Model_Api
72
- */
73
- public function setApiKey($key)
74
- {
75
- $this->api_key = $key;
76
-
77
- $this->apiUrl = "http://www.simplerelevance.com/api/v{$this->version}/";
78
-
79
- return $this;
80
- }
81
-
82
- /**
83
- * Action: POST
84
- * Parameters:
85
- * api_key - email tech@simplerelevance.com if you do not have an api key.
86
- * item_id (optional-see below) - ID of the item clicked.
87
- * user_id (optional-see below) - ID of the user clicking the item.
88
- * timestamp (optional) - UTC Timestamp for the click. If not supplied, the current date/time will be used. Format is like “01/31/2011 14:54:53”.
89
- * price (optional) - can be a float
90
- * email (optional) - if you do not include a user_id, you can identify a user by email address
91
- * item_name (optional) - if you do not include an item_id, you can identify an item by the name with which you input it into SimpleRelevance
92
- * item_type (optional) - if you are matching by name and not item_id, supplying the same value here which you used on the inital input into SimpleRelevance will help find your item.
93
- * zipcode (optional) - if the user is not yet in the system, this zipcode will help determine the user’s location.
94
- * Notes: the timestamp is used to differentiate multiple actions with the same deal and user. If you don’t supply one, the SimpleRelevance system will not create save a new user action, and will simply update the old one with whatever new data you supply (price, for instance).
95
- */
96
- public function postClicks()
97
- {
98
- }
99
-
100
- /**
101
- * Action: POST
102
- * Parameters:
103
- * All parameters and notes from the CLICKS hook apply here.
104
- */
105
- public function postPurchases($data = array())
106
- {
107
- return $this->_callServer('purchases', 'post', $data);
108
- }
109
-
110
- /**
111
- * Action: POST
112
- * Parameters:
113
- * api_key
114
- * item_name - The item’s name - this should be unique across your database if possible.
115
- * item_id - a unique ID for the item from your database.
116
- * item_type (optional) - this helps the SimpleRelevance system find semantic data for your item. You can use any string you want here, but ‘business’ should be used for actual, real-world businesses.
117
- * data_dict - a json encoded dictionary. This can have any attributes at all that apply to your item; the more the better. See below for the list of reserved attribute names - these help SimpleRelevance create semantic connections about your items. Note that these include ‘starts’ and ‘expires’, in case your items are time sensitive.
118
- */
119
- public function postItems($itemData = array())
120
- {
121
- return $this->_callServer('items', 'post', $itemData);
122
- }
123
-
124
- /**
125
- * Action: POST
126
- *
127
- */
128
- public function postUsers($userData = array())
129
- {
130
- return $this->_callServer('users', 'post', $userData);
131
- }
132
-
133
-
134
-
135
- /**
136
- * Action: GET
137
- * Parameters:
138
- * api_key
139
- * email - The email address of the user to return deals for
140
- * market - the general city or location for which you want items returned. Leave this blank for locationless predictions.
141
- * num_per (optional) - for business items, the number of items to return per business. For products, the number of products to return per leaf category.
142
- * starts (optional) - if you have set it when uploading the item data, then only items with a starts value after the one given here will be included in the prediction.
143
- * expires (optional) - if you have set it in the data dict when uploading item data, then only items with an expires value after the one given here will be included in the prediction.
144
- * Notes:
145
- * all returns have the key "data" unless there has been an error.
146
- * data points to a list of recommendation items.
147
- * each recommendation item has
148
- * position - starting at 0, the lower the position, the more highly recommended the item.
149
- * If positions are the same, both items come from the same business! If your items are not related to businesses and you are not using the reserved key "business_name", or if you set parameter num_per=1, this should not happen.
150
- * id_type - describes whether the item id number is from our database or yours - if you supply external ids when uploading items, which is currently a requirement, we will always return those same ids
151
- * id - the item id, hopefully of type "external" so that you can easily find it in your database*
152
- * @return string JSON dictionary
153
- */
154
- public function getItems()
155
- {
156
- }
157
-
158
- /**
159
- * Actually connect to the server and call the requested methods
160
- *
161
- * @param string $method
162
- * @param array OPTIONAL $params
163
- * @return object|false
164
- */
165
- protected function _callServer($method, $call, $params = array())
166
- {
167
-
168
- $this->errorMessage = null;
169
- $this->errorCode = null;
170
-
171
- $data = array();
172
-
173
- //Add API_KEY to request params
174
- $data['api_key'] = $this->api_key;
175
-
176
- //This decides whether the request will wait for completion
177
- //or start a task and return immediately. Can be 0 (wait) or 1 (asynchronous)
178
- $data['async'] = $this->async;
179
-
180
- //Request data
181
- $data['data'] = json_encode(array($params), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
182
-
183
- $url = $this->apiUrl . $method;
184
-
185
- $this->_log($url);
186
- $this->_log($data);
187
-
188
- $requestParams = http_build_query($data);
189
-
190
- $curlSession = curl_init();
191
-
192
- if($call == 'post'){
193
- curl_setopt($curlSession, CURLOPT_POST, TRUE);
194
- curl_setopt($curlSession, CURLOPT_POSTFIELDS, $requestParams);
195
- }
196
-
197
- curl_setopt($curlSession, CURLOPT_USERAGENT, Mage::helper('simple_relevance')->getUserAgent());
198
- curl_setopt($curlSession, CURLOPT_URL, $url);
199
- curl_setopt($curlSession, CURLOPT_HEADER, FALSE);
200
-
201
- curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
202
-
203
- $result = curl_exec($curlSession);
204
-
205
- $this->_log($result);
206
-
207
- if(!$result){
208
- $errstr = curl_error($curlSession);
209
- $errno = curl_errno($curlSession);
210
-
211
- $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
212
- $this->errorCode = "-99";
213
- return false;
214
- }
215
-
216
- // Check that a connection was made
217
- if (curl_error($curlSession)) {
218
- $this->errorMessage = curl_error($curlSession);
219
- $this->errorCode = "-99";
220
- return false;
221
- }
222
-
223
- $httpCode = curl_getinfo($curlSession, CURLINFO_HTTP_CODE);
224
-
225
- curl_close($curlSession);
226
-
227
- if($httpCode != 200){
228
-
229
- Mage::log($result, null, 'SimpleRelevance_Erros.log');
230
- Mage::log($httpCode, null, 'SimpleRelevance_Erros.log');
231
-
232
- $this->errorMessage = $result;
233
- $this->errorCode = "-99";
234
- return false;
235
- }
236
-
237
- return $result;
238
-
239
- }
240
-
241
- /**
242
- * Log data to debug log file
243
- *
244
- * @param mixed $data
245
- * @return void
246
- */
247
- protected function _log($text)
248
- {
249
- if(!Mage::getStoreConfigFlag('simple_relevance/general/debug')){
250
- return;
251
- }
252
-
253
- Mage::log($text, null, 'SimpleRelevance_Integration.log');
254
- }
255
-
256
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/Model/Observer.php CHANGED
@@ -8,93 +8,94 @@
8
  */
9
  class SimpleRelevance_Integration_Model_Observer
10
  {
 
11
 
12
- protected $_block;
13
-
14
- /**
15
- * Add option to MassAction block in adminhtml
16
- *
17
- */
18
- public function massaction($observer)
19
- {
20
  $block = $observer->getEvent()->getBlock();
21
- $action = $block->getRequest()->getControllerName();
22
 
23
- if( !Mage::helper('simple_relevance')->enabled() ){
24
- return $this;
25
- }
26
 
27
- if(get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction') {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- $this->_block = $block;
 
30
 
31
- switch($action){
32
- case 'customer':
33
- $this->_addMassItem('massCustomer');
34
- break;
35
- case 'catalog_product':
36
- $this->_addMassItem('massInventory');
37
- break;
38
- case 'sales_order':
39
- $this->_addMassItem('massOrder');
40
- break;
41
- }
 
 
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
 
 
 
 
 
 
 
44
  }
45
 
46
- return $observer;
47
- }
48
-
49
- /**
50
- * Add item to block
51
- *
52
- * @param string $action
53
- * @return SimpleRelevance_Integration_Model_Observer
54
- */
55
- protected function _addMassItem($action)
56
- {
57
- $this->_block->addItem('simple_relevance_send', array(
58
- 'label' => Mage::helper('simple_relevance')->__('Submit to SimpleRelevance'),
59
- 'url' => Mage::helper('adminhtml')->getUrl("simple_relevance/adminhtml_export/{$action}")
60
- ));
61
- }
62
-
63
- /**
64
- * Send new order to SimpleRelevance API
65
- *
66
- * @param Varien_Event_Observer $observer
67
- * @return void
68
- */
69
- public function pushPurchase(Varien_Event_Observer $observer)
70
- {
71
-
72
- if( !Mage::helper('simple_relevance')->enabled() ){
73
- return $this;
74
- }
75
-
76
- $orderId = (int)(Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId());
77
-
78
- if($orderId){
79
- $order = Mage::getModel('sales/order')->load($orderId);
80
- }
81
-
82
- if($order->getId()){
83
-
84
- $purchase = Mage::getModel('simple_relevance/purchase', $order);
85
- $postData = $purchase->getPostData();
86
-
87
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
88
- $api->async = 1;
89
-
90
- foreach($postData['items'] as $p){
91
- $api->postPurchases($p);
92
- }
93
-
94
- }
95
-
96
- return $this;
97
- }
98
 
99
  /**
100
  * Automatically send customer when creating one.
@@ -104,55 +105,72 @@ class SimpleRelevance_Integration_Model_Observer
104
  */
105
  public function pushCustomer(Varien_Event_Observer $observer)
106
  {
107
- if( !Mage::helper('simple_relevance')->enabled() ){
108
- return $this;
109
- }
110
 
111
- $customer = $observer->getEvent()->getCustomer();
 
112
 
113
- //if($customer->isObjectNew() OR !$customer->getOrigData()){
114
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
115
 
116
- $api->async = 1;
 
 
 
117
 
118
- $customerData = array(
119
- 'email' => $customer->getEmail(),
120
- 'user_id' => $customer->getId(),
121
- );
122
- $api->postUsers($customerData);
123
- //}
 
124
  }
125
 
126
  /**
127
- * Automatically send Catalog-Product when creating one.
128
  *
129
  * @param Varien_Event_Observer $observer
130
  * @return void
131
  */
132
  public function pushItem(Varien_Event_Observer $observer)
133
  {
134
- if( !Mage::helper('simple_relevance')->enabled() ){
135
- return $this;
136
- }
137
-
138
- $product = $observer->getEvent()->getProduct();
 
139
 
140
- //if($product->isObjectNew() OR !$product->getOrigData()){
141
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
 
142
 
143
- $api->async = 1;
 
144
 
145
- $dict = Mage::helper('simple_relevance')->getProductDict($product);
 
 
146
 
147
- $data = array(
148
- 'item_name' => $product->getName(),
149
- 'item_id' => $product->getId(),
150
- 'data_dict' => $dict,
151
- );
152
 
153
- $api->postItems($data);
154
- //}
 
 
 
155
 
 
 
 
 
 
 
 
156
  }
157
-
158
  }
 
 
8
  */
9
  class SimpleRelevance_Integration_Model_Observer
10
  {
11
+ protected $_block;
12
 
13
+ /**
14
+ * Add option to MassAction block in adminhtml
15
+ *
16
+ */
17
+ public function massaction($observer)
18
+ {
 
 
19
  $block = $observer->getEvent()->getBlock();
20
+ $action = $block->getRequest()->getControllerName();
21
 
22
+ if (!Mage::helper('simple_relevance')->enabled()) {
23
+ return $this;
24
+ }
25
 
26
+ if (get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction') {
27
+ $this->_block = $block;
28
+
29
+ switch ($action) {
30
+ case 'customer':
31
+ $this->_addMassItem('massCustomer');
32
+ break;
33
+ case 'catalog_product':
34
+ $this->_addMassItem('massInventory');
35
+ break;
36
+ case 'sales_order':
37
+ $this->_addMassItem('massOrder');
38
+ break;
39
+ }
40
+ }
41
 
42
+ return $observer;
43
+ }
44
 
45
+ /**
46
+ * Add item to block
47
+ *
48
+ * @param string $action
49
+ * @return SimpleRelevance_Integration_Model_Observer
50
+ */
51
+ protected function _addMassItem($action)
52
+ {
53
+ $this->_block->addItem('simple_relevance_send', array(
54
+ 'label' => Mage::helper('simple_relevance')->__('Send to SimpleRelevance'),
55
+ 'url' => Mage::helper('adminhtml')->getUrl("simple_relevance/adminhtml_export/{$action}")
56
+ ));
57
+ }
58
 
59
+ /**
60
+ * Send new order to SimpleRelevance API
61
+ *
62
+ * @param Varien_Event_Observer $observer
63
+ * @return void
64
+ */
65
+ public function pushPurchase(Varien_Event_Observer $observer)
66
+ {
67
+ if (!Mage::helper('simple_relevance')->enabled()) {
68
+ return $this;
69
+ }
70
+
71
+ try {
72
+
73
+ $orderId = (int)(Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId());
74
+
75
+ if ($orderId) {
76
+ $order = Mage::getModel('sales/order')->load($orderId);
77
+
78
+ if ($order->getId()) {
79
+ $purchase = Mage::getModel('simple_relevance/purchase', $order);
80
+ $postData = $purchase->getPostData();
81
+
82
+ $api_arr = array(Mage::helper('simple_relevance')->config('apikey'), Mage::helper('simple_relevance')->config('sitename'));
83
+ $api = Mage::getModel('simple_relevance/api', $api_arr);
84
 
85
+ foreach ($postData['items'] as $p) {
86
+ $api->postPurchases($p);
87
+ }
88
+ }
89
+ }
90
+
91
+ return $this;
92
  }
93
 
94
+ catch (Exception $e) {
95
+ $api->_log($e->getMessage());
96
+ return $this;
97
+ }
98
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
  /**
101
  * Automatically send customer when creating one.
105
  */
106
  public function pushCustomer(Varien_Event_Observer $observer)
107
  {
108
+ if (!Mage::helper('simple_relevance')->enabled()) {
109
+ return $this;
110
+ }
111
 
112
+ try {
113
+ $customer = $observer->getEvent()->getCustomer();
114
 
115
+ $api_arr = array(Mage::helper('simple_relevance')->config('apikey'), Mage::helper('simple_relevance')->config('sitename'));
116
+ $api = Mage::getModel('simple_relevance/api', $api_arr);
117
 
118
+ $customerData = array(
119
+ 'email' => $customer->getEmail(),
120
+ 'user_id' => $customer->getId(),
121
+ );
122
 
123
+ $api->postUsers($customerData);
124
+ }
125
+
126
+ catch (Exception $e) {
127
+ $api->_log($e->getMessage());
128
+ return $this;
129
+ }
130
  }
131
 
132
  /**
133
+ * Automatically send Catalog-Product when creating or modifying it.
134
  *
135
  * @param Varien_Event_Observer $observer
136
  * @return void
137
  */
138
  public function pushItem(Varien_Event_Observer $observer)
139
  {
140
+ if (!Mage::helper('simple_relevance')->enabled()) {
141
+ return $this;
142
+ }
143
+
144
+ try {
145
+ $product = $observer->getEvent()->getProduct();
146
 
147
+ $api_arr = array(Mage::helper('simple_relevance')->config('apikey'), Mage::helper('simple_relevance')->config('sitename'));
148
+ $api = Mage::getModel('simple_relevance/api', $api_arr);
149
+ $dict = Mage::helper('simple_relevance')->getProductDict($product);
150
 
151
+ // categories should be a string of ';'-separated values
152
+ $category_str = "";
153
 
154
+ foreach ($dict['categories'] as $category) {
155
+ $category_str = $category_str . $category . ';';
156
+ }
157
 
158
+ $dict['categories'] = $category_str;
 
 
 
 
159
 
160
+ $data = array(
161
+ 'item_name' => $product->getName(),
162
+ 'item_id' => $product->getId(),
163
+ 'data_dict' => $dict,
164
+ );
165
 
166
+ $api->postItems($data);
167
+ }
168
+
169
+ catch (Exception $e) {
170
+ $api->_log($e->getMessage());
171
+ return $this;
172
+ }
173
  }
 
174
  }
175
+
176
+ ?>
app/code/community/SimpleRelevance/Integration/Model/Observer.php~ DELETED
@@ -1,230 +0,0 @@
1
- <?php
2
- include_once 'avro.php';
3
- /**
4
- * SimpleRelevance Integration Events observer model
5
- *
6
- * @category SimpleRelevance
7
- * @package SimpleRelevance_Integration
8
- */
9
- class SimpleRelevance_Integration_Model_Observer
10
- {
11
-
12
- protected $_block;
13
-
14
- /**
15
- * Add option to MassAction block in adminhtml
16
- *
17
- */
18
- public function massaction($observer)
19
- {
20
- $block = $observer->getEvent()->getBlock();
21
- $action = $block->getRequest()->getControllerName();
22
-
23
- if( !Mage::helper('simple_relevance')->enabled() ){
24
- return $this;
25
- }
26
-
27
- if(get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction') {
28
-
29
- $this->_block = $block;
30
-
31
- switch($action){
32
- case 'customer':
33
- $this->_addMassItem('massCustomer');
34
- break;
35
- case 'catalog_product':
36
- $this->_addMassItem('massInventory');
37
- break;
38
- case 'sales_order':
39
- $this->_addMassItem('massOrder');
40
- break;
41
- }
42
-
43
-
44
- }
45
-
46
- return $observer;
47
- }
48
-
49
- /**
50
- * Add item to block
51
- *
52
- * @param string $action
53
- * @return SimpleRelevance_Integration_Model_Observer
54
- */
55
- protected function _addMassItem($action)
56
- {
57
- $this->_block->addItem('simple_relevance_send', array(
58
- 'label' => Mage::helper('simple_relevance')->__('Submit to SimpleRelevance'),
59
- 'url' => Mage::helper('adminhtml')->getUrl("simple_relevance/adminhtml_export/{$action}")
60
- ));
61
- }
62
-
63
- /**
64
- * Send new order to SimpleRelevance API
65
- *
66
- * @param Varien_Event_Observer $observer
67
- * @return void
68
- */
69
- public function pushPurchase(Varien_Event_Observer $observer)
70
- {
71
-
72
- if( !Mage::helper('simple_relevance')->enabled() ){
73
- return $this;
74
- }
75
-
76
- $orderId = (int)(Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId());
77
-
78
- if($orderId){
79
- $order = Mage::getModel('sales/order')->load($orderId);
80
- }
81
-
82
- if($order->getId()){
83
-
84
- $purchase = Mage::getModel('simple_relevance/purchase', $order);
85
- $postData = $purchase->getPostData();
86
-
87
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
88
- $api->async = 1;
89
-
90
- foreach($postData['items'] as $p){
91
- // XCOM
92
- $fabricMessage = $this->prepareOrderFabric($p,$p);
93
- $topic = "/listing/create";
94
- $this->pushToFabric($fabricMessage,$topic);
95
-
96
- $api->postPurchases($p);
97
- }
98
-
99
- }
100
-
101
- return $this;
102
- }
103
-
104
- /**
105
- * Automatically send customer when creating one.
106
- *
107
- * @param Varien_Event_Observer $observer
108
- * @return void
109
- */
110
- public function pushCustomer(Varien_Event_Observer $observer)
111
- {
112
- if( !Mage::helper('simple_relevance')->enabled() ){
113
- return $this;
114
- }
115
-
116
- $customer = $observer->getEvent()->getCustomer();
117
-
118
- //if($customer->isObjectNew() OR !$customer->getOrigData()){
119
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
120
-
121
- $api->async = 1;
122
-
123
- $customerData = array(
124
- 'email' => $customer->getEmail(),
125
- 'user_id' => $customer->getId(),
126
- );
127
-
128
- // XCOM
129
- $fabricMessage = $this->prepareUserFabric($customer,array());
130
- $topic = "/listing/create";
131
- $this->pushToFabric($fabricMessage,$topic);
132
-
133
- $api->postUsers($customerData);
134
- //}
135
- }
136
-
137
- /**
138
- * Automatically send Catalog-Product when creating one.
139
- *
140
- * @param Varien_Event_Observer $observer
141
- * @return void
142
- */
143
- public function pushItem(Varien_Event_Observer $observer)
144
- {
145
- if( !Mage::helper('simple_relevance')->enabled() ){
146
- return $this;
147
- }
148
-
149
- $product = $observer->getEvent()->getProduct();
150
-
151
- //if($product->isObjectNew() OR !$product->getOrigData()){
152
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
153
-
154
- $api->async = 1;
155
-
156
- $dict = Mage::helper('simple_relevance')->getProductDict($product);
157
-
158
- $data = array(
159
- 'item_name' => $product->getName(),
160
- 'item_id' => $product->getId(),
161
- 'data_dict' => $dict,
162
- );
163
-
164
- // XCOM
165
- $fabricMessage = $this->prepareItemFabric($product,$dict);
166
- $topic = "/listing/create";
167
- $this->pushToFabric($fabricMessage,$topic);
168
-
169
- // Regular HTTP
170
- $api->postItems($data);
171
- //}
172
-
173
- }
174
-
175
- public function prepareItemFabric($p,$pdict) {
176
- // Set up an item
177
- $data = json_encode(array($pdict), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
178
- $message = array("objName"=>$p->getName(),"objId"=>$p->getId(),"objInfo"=>$data,"objType"=>"items");
179
- Mage::log($message, null, 'SimpleRelevance_Integration.log');
180
- return $message;
181
- }
182
- public function prepareUserFabric($p,$pdict) {
183
- // Set up an item
184
- $data = json_encode(array($pdict), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
185
- $message = array("objName"=>$p->getEmail(),"objId"=>$p->getId(),"objInfo"=>$data,"objType"=>"users");
186
- Mage::log($message, null, 'SimpleRelevance_Integration.log');
187
- return $message;
188
- }
189
- public function prepareOrderFabric($p,$pdict) {
190
- // Set up an item
191
- $data = json_encode(array($pdict), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
192
- $message = array("objName"=>"purchase","objId"=>"purchase","objInfo"=>$data,"objType"=>"purchases");
193
- Mage::log($message, null, 'SimpleRelevance_Integration.log');
194
- return $message;
195
- }
196
-
197
- public function pushToFabric($message,$topic) {
198
- //$schema_uri = "https://api.x.com/ocl/listing/create/1.0.0";
199
- // $schema_uri = "https://api.x.com/ocl/marketplace/profile/get/1.0.0";
200
- // $content = file_get_contents($schema_uri);
201
- // yes, it's a fake schema. so sue me.
202
- $content = '{"type": "record", "namespace": "com.x.marketplace.v1", "name": "GetProfile", "fields": [{"type": "string", "name": "objName"},{"type": "string", "name": "objInfo"},{"type": "string", "name": "objId"},{"type": "string", "name": "objType"}]}';
203
-
204
- $schema = AvroSchema::parse($content);
205
- $datum_writer= new AvroIODatumWriter($schema);
206
- $write_io = new AvroStringIO();
207
- $encoder = new AvroIOBinaryEncoder($write_io);
208
-
209
- $datum_writer->write($message,$encoder);
210
- $ch = curl_init();
211
-
212
- // The URL is the host:port for the XFabric, plus the topic
213
- curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.x.com/fabric/".$topic); //marketplace/profile/get");
214
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
215
- curl_setopt($ch, CURLOPT_HEADER, true);
216
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
217
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
218
- curl_setopt($ch, CURLOPT_POST, 1);
219
-
220
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: avro/binary", "Authorization: Bearer ICwoRtY/wbjKQFVr+slzhHLrDar30UN6pH2zSTfPzHAojifpdSrj1Wlslo/W2jvljG3mFhWb", "X-XC-SCHEMA-VERSION: 1.0.0", "X-XC-DESTINATION-ID: GL15hWzfFvbraOlHj/r4AJa0Jzs+Fin7wWhs1xNGUDjcvd+sToB9iBgaR8MaHEmT17tz25i8"));
221
-
222
-
223
- // Our message
224
- curl_setopt($ch, CURLOPT_POSTFIELDS, $write_io->string());
225
- $response = curl_exec($ch);
226
- Mage::log("FABRIC RESPONSE", null, 'SimpleRelevance_Integration.log');
227
- Mage::log($response, null, 'SimpleRelevance_Integration.log');
228
- }
229
-
230
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/Model/Prediction.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
- class SimpleRelevance_Integration_Model_Prediction
3
- extends Mage_Core_Model_Abstract
4
- {
5
- protected function _construct()
6
- {
7
- $this->_init('simpleRelevance_integration/prediction');
8
- }
9
- }
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/Model/Prediction.php~ DELETED
@@ -1,22 +0,0 @@
1
- <?php
2
-
3
- class SimpleRelevance_Integration_Model_Prediction
4
- {
5
- public function handle() {
6
- Mage::log($_POST, null, 'SimpleRelevance_Integration.log');
7
- if (!empty($_POST)) // checking if a post has been completed
8
- {
9
- $headers = apache_request_headers();
10
-
11
- foreach ($headers as $header => $value) {
12
- Mage::log($header.":".$value, null, 'SimpleRelevance_Integration.log');
13
- }
14
- Mage::log("POST", null, 'SimpleRelevance_Integration.log');
15
- Mage::log($_POST, null, 'SimpleRelevance_Integration.log');
16
-
17
- }
18
- }
19
- }
20
- $classname = "SimpleRelevance_Integration_Model_Prediction";
21
- $classname::handle();
22
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/Model/Purchase.php CHANGED
@@ -8,46 +8,47 @@
8
  */
9
  class SimpleRelevance_Integration_Model_Purchase
10
  {
11
- protected $_order = null;
12
 
13
  function __construct(Mage_Sales_Model_Order $order)
14
  {
15
- $this->_order = $order;
16
  }
17
 
18
- /**
19
- * Return post data array to be sent to SimpleRelevance API
20
- *
21
- * @return array
22
- */
23
- public function getPostData()
24
- {
25
- $data = array();
26
- $data ['items'] = $this->getItems();
27
-
28
- return $data;
29
- }
30
-
31
- /**
32
- * Get items purchased on this order
33
- *
34
- * @return array
35
- */
36
- public function getItems()
37
- {
38
- $items = array();
39
 
 
 
 
 
 
 
 
 
40
  $date = Mage::getModel('core/date')->date('m/d/Y H:i:s', $this->_order->getCreatedAt());
41
 
42
- foreach($this->_order->getItemsCollection() as $item){
43
- $items []= array(
44
- 'price' => (float)$item->getRowTotalInclTax(),
45
- 'item_id' => $item->getProductId(),
46
- 'email' => $this->_order->getCustomerEmail(),
47
- 'timestamp' => $date
48
- );
49
- }
50
-
51
- return $items;
52
- }
 
53
  }
 
 
8
  */
9
  class SimpleRelevance_Integration_Model_Purchase
10
  {
11
+ protected $_order = null;
12
 
13
  function __construct(Mage_Sales_Model_Order $order)
14
  {
15
+ $this->_order = $order;
16
  }
17
 
18
+ /**
19
+ * Return post data array to be sent to SimpleRelevance API
20
+ *
21
+ * @return array
22
+ */
23
+ public function getPostData()
24
+ {
25
+ $data = array();
26
+ $data['items'] = $this->getItems();
27
+ return $data;
28
+ }
 
 
 
 
 
 
 
 
 
 
29
 
30
+ /**
31
+ * Get items purchased on this order
32
+ *
33
+ * @return array
34
+ */
35
+ public function getItems()
36
+ {
37
+ $items = array();
38
  $date = Mage::getModel('core/date')->date('m/d/Y H:i:s', $this->_order->getCreatedAt());
39
 
40
+ foreach ($this->_order->getItemsCollection() as $item) {
41
+ $items [] = array(
42
+ 'price' => (float)$item->getRowTotalInclTax(),
43
+ 'item_id' => $item->getProductId(),
44
+ 'email' => $this->_order->getCustomerEmail(),
45
+ 'timestamp' => $date,
46
+ 'action_type' => 1
47
+ );
48
+ }
49
+
50
+ return $items;
51
+ }
52
  }
53
+
54
+ ?>
app/code/community/SimpleRelevance/Integration/controllers/Adminhtml/ExportController.php CHANGED
@@ -9,138 +9,179 @@
9
  class SimpleRelevance_Integration_Adminhtml_ExportController extends Mage_Adminhtml_Controller_Action
10
  {
11
 
12
- /**
13
- * Mass send customers to SimpleRelevance
14
- *
15
- */
16
- public function massCustomerAction()
17
- {
18
- $customers = $this->getRequest()->getPost('customer', array());
19
- $sent = 0;
20
- $notSent = 0;
21
-
22
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
23
-
24
- foreach ($customers as $customerId) {
25
- $customer = Mage::getModel('customer/customer')->load($customerId);
26
-
27
- $customerData = array(
28
- 'email' => $customer->getEmail(),
29
- 'user_id' => $customer->getId(),
30
- );
31
-
32
- $result = $api->postUsers($customerData);
33
-
34
- if (!$api->errorCode) {
35
- $sent++;
36
- } else {
37
- $this->_getSession()->addError($this->__('Error on customer #%s, - %s -', $customer->getId(), $api->errorMessage));
38
- $notSent++;
 
 
 
39
  }
40
- }
41
- if ($notSent) {
 
 
 
 
 
 
 
42
  if ($sent) {
43
- $this->_getSession()->addError($this->__('%s customer(s) were not sent.', $notSent));
44
- } else {
45
- $this->_getSession()->addError($this->__('No customer(s) were sent successfully.'));
46
  }
47
  }
48
- if ($sent) {
49
- $this->_getSession()->addSuccess($this->__('%s customer(s) have been sent successfully.', $sent));
 
 
50
  }
 
51
  $this->_redirect('adminhtml/customer/index');
52
- }
53
-
54
- /**
55
- * Mass send Catalog/Products to SimpleRelevance
56
- *
57
- */
58
- public function massInventoryAction()
59
- {
60
- $products = $this->getRequest()->getPost('product', array());
61
- $sent = 0;
62
- $notSent = 0;
63
-
64
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
65
-
66
- foreach ($products as $productId) {
67
- $product = Mage::getModel('catalog/product')->load($productId);
68
-
69
- $dict = Mage::helper('simple_relevance')->getProductDict($product);
70
-
71
- $data = array(
72
- 'item_name' => $product->getName(),
73
- 'item_id' => $product->getId(),
74
- 'data_dict' => $dict,
75
- );
76
-
77
- $result = $api->postItems($data);
78
-
79
- if (!$api->errorCode) {
80
- $sent++;
81
- } else {
82
- $this->_getSession()->addError($this->__('Error on items #%s, - %s -', $product->getId(), $api->errorMessage));
83
- $notSent++;
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
- }
86
- if ($notSent) {
 
 
 
 
 
 
87
  if ($sent) {
88
- $this->_getSession()->addError($this->__('%s item(s) were not sent.', $notSent));
89
- } else {
90
- $this->_getSession()->addError($this->__('No item(s) were sent successfully.'));
91
  }
92
  }
93
- if ($sent) {
94
- $this->_getSession()->addSuccess($this->__('%s item(s) have been sent successfully.', $sent));
 
 
95
  }
 
96
  $this->_redirect('adminhtml/catalog_product/index');
97
- }
98
-
99
- /**
100
- * Mass send Order items (user actions) to SimpleRelevance
101
- *
102
- */
103
- public function massOrderAction()
104
- {
105
- $orders = $this->getRequest()->getPost('order_ids', array());
106
- $sent = 0;
107
- $notSent = 0;
108
-
109
- $api = Mage::getModel('simple_relevance/api', Mage::helper('simple_relevance')->config('apikey'));
110
- $api->async = 1;
111
-
112
- foreach ($orders as $orderId){
113
- $order = Mage::getModel('sales/order')->load($orderId);
114
-
115
- if(!$order->getId()){
116
- continue;
117
- }
118
-
119
- $purchase = Mage::getModel('simple_relevance/purchase', $order);
120
- $postData = $purchase->getPostData();
121
-
122
- foreach($postData['items'] as $p){
123
- $result = $api->postPurchases($p);
124
- }
125
-
126
- if (!$api->errorCode) {
127
- $sent++;
128
- } else {
129
- $this->_getSession()->addError($this->__('Error on order #%s, - %s -', $order->getId(), $api->errorMessage));
130
- $notSent++;
 
 
131
  }
132
- }
133
- if ($notSent) {
 
 
 
 
 
 
 
134
  if ($sent) {
135
- $this->_getSession()->addError($this->__('%s order(s) were not sent.', $notSent));
136
- } else {
137
- $this->_getSession()->addError($this->__('No order(s) were sent successfully.'));
138
  }
139
  }
140
- if ($sent) {
141
- $this->_getSession()->addSuccess($this->__('%s order(s) have been sent successfully.', $sent));
 
 
142
  }
143
- $this->_redirect('adminhtml/sales_order/index');
144
- }
145
 
 
 
146
  }
 
 
9
  class SimpleRelevance_Integration_Adminhtml_ExportController extends Mage_Adminhtml_Controller_Action
10
  {
11
 
12
+ /**
13
+ * Mass send customers to SimpleRelevance
14
+ *
15
+ */
16
+ public function massCustomerAction()
17
+ {
18
+ try {
19
+ $customers = $this->getRequest()->getPost('customer', array());
20
+ $sent = 0;
21
+ $notSent = 0;
22
+
23
+ $api_arr = array(Mage::helper('simple_relevance')->config('apikey'), Mage::helper('simple_relevance')->config('sitename'));
24
+ $api = Mage::getModel('simple_relevance/api', $api_arr);
25
+
26
+ foreach ($customers as $customerId) {
27
+ $customer = Mage::getModel('customer/customer')->load($customerId);
28
+
29
+ $customerData = array(
30
+ 'email' => $customer->getEmail(),
31
+ 'user_id' => $customer->getId(),
32
+ );
33
+
34
+ $result = $api->postUsers($customerData);
35
+
36
+ if (!$api->errorCode) {
37
+ $sent++;
38
+ } else {
39
+ $this->_getSession()->addError($this->__('Error on customer #%s, - %s -', $customer->getId(), $api->errorMessage));
40
+ $notSent++;
41
+ }
42
  }
43
+
44
+ if ($notSent) {
45
+ if ($sent) {
46
+ $this->_getSession()->addError($this->__('%s customer(s) were not sent.', $notSent));
47
+ } else {
48
+ $this->_getSession()->addError($this->__('No customer(s) were sent successfully.'));
49
+ }
50
+ }
51
+
52
  if ($sent) {
53
+ $this->_getSession()->addSuccess($this->__('%s customer(s) have been sent successfully.', $sent));
 
 
54
  }
55
  }
56
+
57
+ catch (Exception $e) {
58
+ $api->_log($e->getMessage());
59
+ $this->_redirect('adminhtml/customer/index');
60
  }
61
+
62
  $this->_redirect('adminhtml/customer/index');
63
+ }
64
+
65
+ /**
66
+ * Mass send Catalog/Products to SimpleRelevance
67
+ *
68
+ */
69
+ public function massInventoryAction()
70
+ {
71
+ try {
72
+ $products = $this->getRequest()->getPost('product', array());
73
+ $sent = 0;
74
+ $notSent = 0;
75
+
76
+ $api_arr = array(Mage::helper('simple_relevance')->config('apikey'), Mage::helper('simple_relevance')->config('sitename'));
77
+ $api = Mage::getModel('simple_relevance/api', $api_arr);
78
+
79
+ foreach ($products as $productId) {
80
+ $product = Mage::getModel('catalog/product')->load($productId);
81
+
82
+ $dict = Mage::helper('simple_relevance')->getProductDict($product);
83
+
84
+ // categories should be a string of ';'-separated values
85
+ $category_str = "";
86
+
87
+ foreach ($dict['categories'] as $category) {
88
+ $category_str = $category_str . $category . ';';
89
+ }
90
+
91
+ $dict['categories'] = $category_str;
92
+
93
+ $data = array(
94
+ 'item_name' => $product->getName(),
95
+ 'item_id' => $product->getId(),
96
+ 'data_dict' => $dict,
97
+ );
98
+
99
+ $result = $api->postItems($data);
100
+
101
+ if (!$api->errorCode) {
102
+ $sent++;
103
+ } else {
104
+ $this->_getSession()->addError($this->__('Error on items #%s, - %s -', $product->getId(), $api->errorMessage));
105
+ $notSent++;
106
+ }
107
  }
108
+ if ($notSent) {
109
+ if ($sent) {
110
+ $this->_getSession()->addError($this->__('%s item(s) were not sent.', $notSent));
111
+ } else {
112
+ $this->_getSession()->addError($this->__('No item(s) were sent successfully.'));
113
+ }
114
+ }
115
+
116
  if ($sent) {
117
+ $this->_getSession()->addSuccess($this->__('%s item(s) have been sent successfully.', $sent));
 
 
118
  }
119
  }
120
+
121
+ catch (Exception $e) {
122
+ $api->_log($e->getMessage());
123
+ $this->_redirect('adminhtml/catalog_product/index');
124
  }
125
+
126
  $this->_redirect('adminhtml/catalog_product/index');
127
+ }
128
+
129
+ /**
130
+ * Mass send Order items (user actions) to SimpleRelevance
131
+ *
132
+ */
133
+ public function massOrderAction()
134
+ {
135
+ try {
136
+ $orders = $this->getRequest()->getPost('order_ids', array());
137
+ $sent = 0;
138
+ $notSent = 0;
139
+
140
+ $api_arr = array(Mage::helper('simple_relevance')->config('apikey'), Mage::helper('simple_relevance')->config('sitename'));
141
+ $api = Mage::getModel('simple_relevance/api', $api_arr);
142
+
143
+ foreach ($orders as $orderId) {
144
+ $order = Mage::getModel('sales/order')->load($orderId);
145
+
146
+ if (!$order->getId()) {
147
+ continue;
148
+ }
149
+
150
+ $purchase = Mage::getModel('simple_relevance/purchase', $order);
151
+ $postData = $purchase->getPostData();
152
+
153
+ foreach($postData['items'] as $p) {
154
+ $result = $api->postPurchases($p);
155
+ }
156
+
157
+ if (!$api->errorCode) {
158
+ $sent++;
159
+ } else {
160
+ $this->_getSession()->addError($this->__('Error on order #%s, - %s -', $order->getId(), $api->errorMessage));
161
+ $notSent++;
162
+ }
163
  }
164
+
165
+ if ($notSent) {
166
+ if ($sent) {
167
+ $this->_getSession()->addError($this->__('%s order(s) were not sent.', $notSent));
168
+ } else {
169
+ $this->_getSession()->addError($this->__('No order(s) were sent successfully.'));
170
+ }
171
+ }
172
+
173
  if ($sent) {
174
+ $this->_getSession()->addSuccess($this->__('%s order(s) have been sent successfully.', $sent));
 
 
175
  }
176
  }
177
+
178
+ catch (Exception $e) {
179
+ $api->_log($e->getMessage());
180
+ $this->_redirect('adminhtml/sales_order/index');
181
  }
 
 
182
 
183
+ $this->_redirect('adminhtml/sales_order/index');
184
+ }
185
  }
186
+
187
+ ?>
app/code/community/SimpleRelevance/Integration/controllers/Adminhtml/IndexController.php~ DELETED
@@ -1,9 +0,0 @@
1
- class Magentotutorial_Helloworld_IndexController extends Mage_Core_Controller_Front_Action {
2
-
3
- public function indexAction() {
4
-
5
- echo 'Hello Index!';
6
-
7
- }
8
-
9
- }
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/controllers/Adminhtml/InputController.php~ DELETED
@@ -1,22 +0,0 @@
1
- <?php
2
-
3
- class SimpleRelevance_Integration_Model_Prediction
4
- {
5
- public function handle() {
6
- Mage::log($_POST, null, 'SimpleRelevance_Integration.log');
7
- if (!empty($_POST)) // checking if a post has been completed
8
- {
9
- $headers = apache_request_headers();
10
-
11
- foreach ($headers as $header => $value) {
12
- Mage::log($header.":".$value, null, 'SimpleRelevance_Integration.log');
13
- }
14
- Mage::log("POST", null, 'SimpleRelevance_Integration.log');
15
- Mage::log($_POST, null, 'SimpleRelevance_Integration.log');
16
-
17
- }
18
- }
19
- }
20
- $classname = "SimpleRelevance_Integration_Model_Prediction";
21
- $classname::handle();
22
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/controllers/IndexController.php DELETED
@@ -1,76 +0,0 @@
1
- <?php
2
- include_once 'avro.php';
3
-
4
- class SimpleRelevance_Integration_IndexController extends Mage_Core_Controller_Front_Action {
5
-
6
- public function indexAction() {
7
- $email = "no email given";
8
- foreach ($this->getRequest()->getParams() as $key=>$value) {
9
- if ($key=="email") {
10
- $this->send_prediction_request($value);
11
- $email = $value;
12
- }
13
- }
14
- $this->loadLayout();
15
- $block = $this->getLayout()->getBlock('root');
16
- $block->setData('email',$email);
17
-
18
- $connection = new Mongo("mongodb://sr_xfabric2:eatingcats@ds033047.mongolab.com:33047/sr_xfabric_demo");
19
- $db = $connection->sr_xfabric_demo;
20
- $collection = $db->predictions2;
21
- $query = array('email'=>$email);
22
-
23
- $v= $collection->findOne( $query );
24
- Mage::log("dbRESPONSE".$v, null, 'SimpleRelevance_Integration.log');
25
- $deal1id=$v["deal1id"];
26
- $deal2id=$v["deal2id"];
27
- $deal3id=$v["deal3id"];
28
- Mage::log("dbRESPONSE".$deal1id, null, 'SimpleRelevance_Integration.log');
29
- $items = array($deal1id,$deal2id,$deal3id);
30
- $c=0;
31
- foreach ($items as $item){
32
- $c = $c + 1;
33
- $product = Mage::getModel('catalog/product')->load($item);
34
- $title = $product->getName();
35
- $img_url = $product->getImageUrl();
36
- $desc = $product->getDescription();
37
- $block->setData("title$c",$title);
38
- $block->setData("img$c",$img_url);
39
- $block->setData("desc$c",$desc);
40
- }
41
-
42
-
43
- $this->renderLayout();
44
-
45
- }
46
-
47
- public function send_prediction_request($email) {
48
- $content = '{"type": "record", "namespace": "com.x.marketplace.v1", "name": "GetProfile", "fields": [{"type": "string", "name": "email"}]}';
49
- $message = array("email"=>$email);
50
- $schema = AvroSchema::parse($content);
51
- $datum_writer= new AvroIODatumWriter($schema);
52
- $write_io = new AvroStringIO();
53
- $encoder = new AvroIOBinaryEncoder($write_io);
54
-
55
- $datum_writer->write($message,$encoder);
56
- $ch = curl_init();
57
-
58
- // The URL is the host:port for the XFabric, plus the topic
59
- curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.x.com/fabric/order/search"); //marketplace/profile/get");
60
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
61
- curl_setopt($ch, CURLOPT_HEADER, true);
62
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
63
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
64
- curl_setopt($ch, CURLOPT_POST, 1);
65
-
66
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: avro/binary", "Authorization: Bearer ICwoRtY/wbjKQFVr+slzhHLrDar30UN6pH2zSTfPzHAojifpdSrj1Wlslo/W2jvljG3mFhWb", "X-XC-SCHEMA-VERSION: 1.0.0", "X-XC-DESTINATION-ID: GL15hWzfFvbraOlHj/r4AJa0Jzs+Fin7wWhs1xNGUDjcvd+sToB9iBgaR8MaHEmT17tz25i8"));
67
-
68
-
69
- // Our message
70
- curl_setopt($ch, CURLOPT_POSTFIELDS, $write_io->string());
71
- $response = curl_exec($ch);
72
- Mage::log("FABRIC RESPONSE", null, 'SimpleRelevance_Integration.log');
73
- Mage::log($response, null, 'SimpleRelevance_Integration.log');
74
- }
75
-
76
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/controllers/IndexController.php~ DELETED
@@ -1,63 +0,0 @@
1
- <?php
2
- include_once 'avro.php';
3
- class SimpleRelevance_Integration_IndexController extends Mage_Core_Controller_Front_Action {
4
-
5
- public function indexAction() {
6
- $email = "no email given";
7
- foreach ($this->getRequest()->getParams() as $key=>$value) {
8
- if ($key=="email") {
9
- $this->send_prediction_request($value);
10
- $email = $value;
11
- }
12
- }
13
- $this->loadLayout();
14
- $block = $this->getLayout()->getBlock('root');
15
- $block->setData('email',$email);
16
- //$pred = Mage::getModel('simple_relevance/prediction');
17
- //$pred_obj = Mage::getModel('simpleRelevance_integration/prediction');
18
- //$pred_obj->setEmail($email);
19
-
20
- $frontend_id = Mage::getModel('core/cookie')->get('frontend');
21
- Mage::log("frontend: ".$frontend_id, null, 'SimpleRelevance_Integration.log');
22
-
23
- $cookiePath = Mage::getModel('core/cookie')->getPath();
24
- $cookieDomain = Mage::getModel('core/cookie')->getDomain();
25
- Mage::log("cookieinfo: ".$cookiePath.":".$cookieDomain, null, 'SimpleRelevance_Integration.log');
26
-
27
- $test=Mage::getModel('core/cookie')->get("test");
28
- Mage::log("got cookie".$test, null, 'SimpleRelevance_Integration.log');
29
- $block->setData('test',$test);
30
- $this->renderLayout();
31
-
32
- }
33
-
34
- public function send_prediction_request($email) {
35
- $content = '{"type": "record", "namespace": "com.x.marketplace.v1", "name": "GetProfile", "fields": [{"type": "string", "name": "email"}]}';
36
- $message = array("email"=>$email);
37
- $schema = AvroSchema::parse($content);
38
- $datum_writer= new AvroIODatumWriter($schema);
39
- $write_io = new AvroStringIO();
40
- $encoder = new AvroIOBinaryEncoder($write_io);
41
-
42
- $datum_writer->write($message,$encoder);
43
- $ch = curl_init();
44
-
45
- // The URL is the host:port for the XFabric, plus the topic
46
- curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.x.com/fabric/order/search"); //marketplace/profile/get");
47
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
48
- curl_setopt($ch, CURLOPT_HEADER, true);
49
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
50
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
51
- curl_setopt($ch, CURLOPT_POST, 1);
52
-
53
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: avro/binary", "Authorization: Bearer ICwoRtY/wbjKQFVr+slzhHLrDar30UN6pH2zSTfPzHAojifpdSrj1Wlslo/W2jvljG3mFhWb", "X-XC-SCHEMA-VERSION: 1.0.0", "X-XC-DESTINATION-ID: GL15hWzfFvbraOlHj/r4AJa0Jzs+Fin7wWhs1xNGUDjcvd+sToB9iBgaR8MaHEmT17tz25i8"));
54
-
55
-
56
- // Our message
57
- curl_setopt($ch, CURLOPT_POSTFIELDS, $write_io->string());
58
- $response = curl_exec($ch);
59
- Mage::log("FABRIC RESPONSE", null, 'SimpleRelevance_Integration.log');
60
- Mage::log($response, null, 'SimpleRelevance_Integration.log');
61
- }
62
-
63
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/controllers/InputController.php DELETED
@@ -1,47 +0,0 @@
1
- <?php
2
- include_once 'avro.php';
3
-
4
- class SimpleRelevance_Integration_InputController extends Mage_Core_Controller_Front_Action
5
- {
6
- public function handleAction() {
7
- $post_data = file_get_contents("php://input");
8
- $headers = getallheaders();
9
-
10
- $message = $this->handle_incoming($post_data,$headers);
11
- Mage::log("message", null, 'SimpleRelevance_Integration.log');
12
- Mage::log($message, null, 'SimpleRelevance_Integration.log');
13
-
14
- $connection = new Mongo("mongodb://sr_xfabric2:eatingcats@ds033047.mongolab.com:33047/sr_xfabric_demo");
15
- $db = $connection->sr_xfabric_demo;
16
- $collection = $db->predictions2;
17
- $deal1id=$message["deal1id"];
18
- $deal2id=$message["deal2id"];
19
- $deal3id=$message["deal3id"];
20
- $email=$message["email"];
21
-
22
- Mage::log("about to save data ", null, 'SimpleRelevance_Integration.log');
23
- Mage::log($deal1id, null, 'SimpleRelevance_Integration.log');
24
- $obj = array("deal1id"=>$deal1id,"deal2id"=>$deal2id,"deal3id"=>$deal3id,"email"=>$email);
25
-
26
- $collection->insert($obj);
27
-
28
- }
29
-
30
- public function handle_incoming($post_data,$headers) {
31
- Mage::log($headers["Authorization"], null, 'SimpleRelevance_Integration.log');
32
- $fabric_token = "Bearer MFyMOIXmj/u8tubkTLKDlw6/voyKwr1FZKzTmE9LYtDXq/w7HpB9oi2j7zsOHegNdaDRl8Yr";
33
-
34
- if ($headers["Authorization"] != $fabric_token) {
35
- Mage::log("Bad Auth!", null, 'SimpleRelevance_Integration.log');
36
- return false;
37
- }
38
- Mage::log("Good Auth!", null, 'SimpleRelevance_Integration.log');
39
- $content = '{"type": "record", "namespace": "com.x.marketplace.v1", "name": "GetProfile", "fields": [{"type": "string", "name": "deal1id"},{"type": "string", "name": "deal2id"},{"type": "string", "name": "deal3id"},{"type": "string", "name": "email"}]}';
40
- $schema = AvroSchema::parse($content);
41
- $datum_reader = new AvroIODatumReader($schema);
42
- $read_io = new AvroStringIO($post_data);
43
- $decoder = new AvroIOBinaryDecoder($read_io);
44
- $message = $datum_reader->read($decoder);
45
- return $message;
46
- }
47
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/controllers/InputController.php~ DELETED
@@ -1,44 +0,0 @@
1
- <?php
2
- include_once 'avro.php';
3
-
4
- class SimpleRelevance_Integration_InputController extends Mage_Core_Controller_Front_Action
5
- {
6
- public function handleAction() {
7
- $post_data = file_get_contents("php://input");
8
- $headers = getallheaders();
9
-
10
- $message = $this->handle_incoming($post_data,$headers);
11
- Mage::log("setting cookie!", null, 'SimpleRelevance_Integration.log');
12
- $frontend_id = Mage::getModel('core/cookie')->get('frontend');
13
- Mage::log("frontend: ".$frontend_id, null, 'SimpleRelevance_Integration.log');
14
- Mage::getModel('core/cookie')->set("test", "yes", 5400);
15
- $test=Mage::getModel('core/cookie')->get("test");
16
- $cookiePath = Mage::getModel('core/cookie')->getPath();
17
- $cookieDomain = Mage::getModel('core/cookie')->getDomain();
18
- Mage::log("got 1 cookie".$test, null, 'SimpleRelevance_Integration.log');
19
- Mage::log("cookieinfo: ".$cookiePath.":".$cookieDomain, null, 'SimpleRelevance_Integration.log');
20
- Mage::log("message", null, 'SimpleRelevance_Integration.log');
21
- Mage::log($message, null, 'SimpleRelevance_Integration.log');
22
-
23
-
24
- }
25
-
26
- public function handle_incoming($post_data,$headers) {
27
- Mage::log($headers["Authorization"], null, 'SimpleRelevance_Integration.log');
28
- $fabric_token = "Bearer MFyMOIXmj/u8tubkTLKDlw6/voyKwr1FZKzTmE9LYtDXq/w7HpB9oi2j7zsOHegNdaDRl8Yr";
29
-
30
- if ($headers["Authorization"] != $fabric_token) {
31
- Mage::log("Bad Auth!", null, 'SimpleRelevance_Integration.log');
32
- return false;
33
- }
34
- Mage::log("Good Auth!", null, 'SimpleRelevance_Integration.log');
35
- $content = '{"type": "record", "namespace": "com.x.marketplace.v1", "name": "GetProfile", "fields": [{"type": "string", "name": "data"}]}';
36
- $schema = AvroSchema::parse($content);
37
- $datum_reader = new AvroIODatumReader($schema);
38
- $read_io = new AvroStringIO($post_data);
39
- $decoder = new AvroIOBinaryDecoder($read_io);
40
- $message = $datum_reader->read($decoder);
41
- $decoded = json_decode($message["data"],true);
42
- return $decoded;
43
- }
44
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/demo.phtml DELETED
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml">
4
- <head>
5
- <title>SimpleRelevance XFabric Demo</title>
6
- <meta name="generator" content="BBEdit 9.2" />
7
- </head>
8
- <body>
9
- <b>helllllooooooo, nurse!</b>
10
- </body>
11
- </html>
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/demo.phtml~ DELETED
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml">
4
- <head>
5
- <title>SimpleRelevance XFabric Demo</title>
6
- <meta name="generator" content="BBEdit 9.2" />
7
- <style type="text/css">
8
- body {
9
- background-color:#f00;
10
- }
11
- </style>
12
- </head>
13
- <body>
14
-
15
- </body>
16
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/etc/config.xml~ DELETED
@@ -1,110 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <SimpleRelevance_Integration>
5
- <version>1.0.1</version>
6
- </SimpleRelevance_Integration>
7
- </modules>
8
- <global>
9
- <models>
10
- <simple_relevance>
11
- <class>SimpleRelevance_Integration_Model</class>
12
- </simple_relevance>
13
- </models>
14
- <blocks>
15
- <simple_relevance>
16
- <class>SimpleRelevance_Integration_Block</class>
17
- </simple_relevance>
18
- </blocks>
19
- <helpers>
20
- <simple_relevance>
21
- <class>SimpleRelevance_Integration_Helper</class>
22
- </simple_relevance>
23
- </helpers>
24
- <events>
25
- <customer_save_after>
26
- <observers>
27
- <simplerelevance_push_customer>
28
- <class>simple_relevance/observer</class>
29
- <method>pushCustomer</method>
30
- </simplerelevance_push_customer>
31
- </observers>
32
- </customer_save_after>
33
- <catalog_product_save_after>
34
- <observers>
35
- <simplerelevance_push_item>
36
- <class>simple_relevance/observer</class>
37
- <method>pushItem</method>
38
- </simplerelevance_push_item>
39
- </observers>
40
- </catalog_product_save_after>
41
- </events>
42
- </global>
43
- <frontend>
44
- <translate>
45
- <modules>
46
- <SimpleRelevance_Integration>
47
- <files>
48
- <default>SimpleRelevance_Integration.csv</default>
49
- </files>
50
- </SimpleRelevance_Integration>
51
- </modules>
52
- </translate>
53
- <routers>
54
- <simple_relevance>
55
- <use>standard</use>
56
- <args>
57
- <module>SimpleRelevance_Integration</module>
58
- <frontName>simple_relevance</frontName>
59
- </args>
60
- </simple_relevance>
61
- </routers>
62
- <events>
63
- <checkout_onepage_controller_success_action>
64
- <observers>
65
- <simplerelevane_purchases>
66
- <class>simple_relevance/observer</class>
67
- <method>pushPurchase</method>
68
- </simplerelevane_purchases>
69
- </observers>
70
- </checkout_onepage_controller_success_action>
71
- </events>
72
- </frontend>
73
- <adminhtml>
74
- <events>
75
- <core_block_abstract_prepare_layout_before>
76
- <observers>
77
- <add_button>
78
- <type>model</type>
79
- <class>simple_relevance/observer</class>
80
- <method>massaction</method>
81
- </add_button>
82
- </observers>
83
- </core_block_abstract_prepare_layout_before>
84
- </events>
85
- <layout>
86
- <updates>
87
- <simple_relevance>
88
- <file>simple_relevance.xml</file>
89
- </simple_relevance>
90
- </updates>
91
- </layout>
92
- <translate>
93
- <modules>
94
- <SimpleRelevance_Integration>
95
- <files>
96
- <default>SimpleRelevance_Integration.csv</default>
97
- </files>
98
- </SimpleRelevance_Integration>
99
- </modules>
100
- </translate>
101
- </adminhtml>
102
- <default>
103
- <simple_relevance>
104
- <general>
105
- <active>0</active>
106
- <debug>0</debug>
107
- </general>
108
- </simple_relevance>
109
- </default>
110
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/SimpleRelevance/Integration/etc/system.xml CHANGED
@@ -12,7 +12,7 @@
12
  <show_in_store>1</show_in_store>
13
  <groups>
14
  <general translate="label comment">
15
- <label>SimpleRelevance integration</label>
16
  <frontend_type>text</frontend_type>
17
  <show_in_default>1</show_in_default>
18
  <show_in_website>1</show_in_website>
@@ -27,20 +27,29 @@
27
  <show_in_website>1</show_in_website>
28
  <show_in_store>1</show_in_store>
29
  </active>
 
 
 
 
 
 
 
 
 
30
  <apikey translate="label comment">
31
  <label>API Key</label>
32
  <frontend_type>text</frontend_type>
33
- <sort_order>20</sort_order>
34
  <show_in_default>1</show_in_default>
35
  <show_in_website>0</show_in_website>
36
  <show_in_store>1</show_in_store>
37
- <comment><![CDATA[Your SimpleRelevance API Key.<br />You can find it on your SimpleRelevance admin panel under <i>Help and Support -> Your API Key</i>]]></comment>
38
  </apikey>
39
  <debug translate="label comment">
40
  <label>Debug Mode</label>
41
  <frontend_type>select</frontend_type>
42
  <source_model>adminhtml/system_config_source_yesno</source_model>
43
- <sort_order>30</sort_order>
44
  <show_in_default>1</show_in_default>
45
  <show_in_website>1</show_in_website>
46
  <show_in_store>1</show_in_store>
12
  <show_in_store>1</show_in_store>
13
  <groups>
14
  <general translate="label comment">
15
+ <label>SimpleRelevance Integration</label>
16
  <frontend_type>text</frontend_type>
17
  <show_in_default>1</show_in_default>
18
  <show_in_website>1</show_in_website>
27
  <show_in_website>1</show_in_website>
28
  <show_in_store>1</show_in_store>
29
  </active>
30
+ <sitename translate="label comment">
31
+ <label>Site Name</label>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>20</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ <comment><![CDATA[Your SimpleRelevance site name.<br />You can find it on your SimpleRelevance dashboard under <i>Account -> Site name</i>]]></comment>
38
+ </sitename>
39
  <apikey translate="label comment">
40
  <label>API Key</label>
41
  <frontend_type>text</frontend_type>
42
+ <sort_order>30</sort_order>
43
  <show_in_default>1</show_in_default>
44
  <show_in_website>0</show_in_website>
45
  <show_in_store>1</show_in_store>
46
+ <comment><![CDATA[Your SimpleRelevance API Key.<br />You can find it on your SimpleRelevance dashboard under <i>Account -> API Key</i>]]></comment>
47
  </apikey>
48
  <debug translate="label comment">
49
  <label>Debug Mode</label>
50
  <frontend_type>select</frontend_type>
51
  <source_model>adminhtml/system_config_source_yesno</source_model>
52
+ <sort_order>40</sort_order>
53
  <show_in_default>1</show_in_default>
54
  <show_in_website>1</show_in_website>
55
  <show_in_store>1</show_in_store>
{skin → app/design}/adminhtml/default/default/simple_relevance/css.css RENAMED
File without changes
{skin → app/design}/adminhtml/default/default/simple_relevance/images/box-tab.png RENAMED
File without changes
{skin → app/design}/adminhtml/default/default/simple_relevance/images/simplerelevance-header.png RENAMED
File without changes
{skin → app/design}/adminhtml/default/default/simple_relevance/js.js RENAMED
File without changes
app/etc/modules/SimpleRelevance_Integration.xml CHANGED
@@ -3,7 +3,7 @@
3
  <modules>
4
  <SimpleRelevance_Integration>
5
  <active>true</active>
6
- <codePool>community</codePool>
7
  <depends>
8
  <Mage_Sales />
9
  <Mage_Customer />
3
  <modules>
4
  <SimpleRelevance_Integration>
5
  <active>true</active>
6
+ <codePool>local</codePool>
7
  <depends>
8
  <Mage_Sales />
9
  <Mage_Customer />
app/locale/en_US/SimpleRelevance_Integration.csv CHANGED
@@ -1,3 +1,3 @@
1
  "SimpleRelevance Configuration","SimpleRelevance Configuration"
2
  "SimpleRelevance integration","SimpleRelevance integration"
3
- "Your SimpleRelevance API Key.<br />You can find it on your SimpleRelevance admin panel under <i>Help and Support -> Your API Key</i>","Your SimpleRelevance API Key.<br />You can find it on your SimpleRelevance admin panel under <i>Help and Support -> Your API Key</i>"
1
  "SimpleRelevance Configuration","SimpleRelevance Configuration"
2
  "SimpleRelevance integration","SimpleRelevance integration"
3
+ "Your SimpleRelevance API Key.<br />You can find it on your SimpleRelevance dashboard under <i>Account -> API Key</i>","Your SimpleRelevance API Key.<br />You can find it on your SimpleRelevance dashboard under <i>Account -> API Key</i>"
package.xml CHANGED
@@ -1,18 +1,58 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>SimpleRelevance_Integration</name>
4
- <version>1.0.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>SimpleRelevance integration module</summary>
10
  <description>Featuring customers, products and orders.</description>
11
- <notes>REQUIRED FIX - all communication now over https, http is turned off for simplerelevance.com. </notes>
12
- <authors><author><name>Eli Albert</name><user>elialbert</user><email>eli@simplerelevance.com</email></author></authors>
13
- <date>2012-07-19</date>
14
- <time>20:52:39</time>
15
- <contents><target name="magecommunity"><dir name="SimpleRelevance"><dir name="Integration"><dir name="Helper"><file name="Data.php" hash="e2e82d1e985bfd9b03d279d6ad972563"/><file name="Data.php~" hash="233ecf0f4a4ced6fd04e1d9a37e0936c"/></dir><dir name="Model"><file name="Api.php" hash="3934912a2263bc0ae9f4c0e5d8fbeebd"/><file name="Api.php~" hash="dadb3d39091ef38b2465c566fcbacb38"/><file name="Observer.php" hash="8a247ca67158af2d63c737bdabac53b4"/><file name="Observer.php~" hash="d495ea4fccaede3fd1d9a83e69327839"/><file name="Prediction.php" hash="09830c9269d4b7b30e4ad37d4e7f6792"/><file name="Prediction.php~" hash="ab5d9acea6e208d0ccc5c62a19215179"/><file name="Purchase.php" hash="dae8d7e715381a9ec160123f27800b15"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ExportController.php" hash="840104daa154dab436ab043f8ea217af"/><file name="IndexController.php~" hash="968a495beece48514394bd597ee32d83"/><file name="InputController.php~" hash="ab5d9acea6e208d0ccc5c62a19215179"/></dir><file name="IndexController.php" hash="304464e66af0b1aeedd61d98ceb2d9e8"/><file name="IndexController.php~" hash="599e35006f80ffd08201ebb5e921d8d4"/><file name="InputController.php" hash="f5324ef04aa854ef8b4b5edd3063c056"/><file name="InputController.php~" hash="f649b3bbffb2da9a8fd94e0dc7faf594"/></dir><file name="demo.phtml" hash="e7c307f0014af936fe8c1a97154e4daa"/><file name="demo.phtml~" hash="9366e20fa2eb6ec04d2e66d9e995caf6"/><dir name="etc"><file name="adminhtml.xml" hash="18e9829f6252920f6bf01a5340377b3a"/><file name="config.xml" hash="3ba8219cb93dba44fb1a1e7bcfadcd49"/><file name="config.xml~" hash="3ba8219cb93dba44fb1a1e7bcfadcd49"/><file name="system.xml" hash="638f6aac1d2d19b8b9d9ca4fed0065f5"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="simple_relevance.xml" hash="f0d73f30b7aeff70f63b295327ac906c"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SimpleRelevance_Integration.xml" hash="6ad0b704a9e62de159f09babfe2482d5"/></dir></target><target name="magelocale"><dir name="en_US"><file name="SimpleRelevance_Integration.csv" hash="05e3ba1c882990c307dbe510bc0bea36"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="simple_relevance"><file name="css.css" hash="c354dd9c0e48bdb99089b1756058efc1"/><dir name="images"><file name="box-tab.png" hash="208977131fcbe078f10af53295ac686c"/><file name="simplerelevance-header.png" hash="c25099645618a32b8fdb8d4d7786cf2c"/></dir><file name="js.js" hash="5831e6e503ebd86f93e07230b56a6d2f"/></dir></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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>SimpleRelevance_Integration</name>
4
+ <version>1.5.1</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>SimpleRelevance integration module</summary>
10
  <description>Featuring customers, products and orders.</description>
11
+ <notes>-- version 1.5.1&#xD;
12
+ Updated for wider Magento support&#xD;
13
+ &#xD;
14
+ -- version 1.5.0&#xD;
15
+ Updated for our new API with SSL&#xD;
16
+ &#xD;
17
+ -- version 1.0.4&#xD;
18
+ Security Update&#xD;
19
+ &#xD;
20
+ -- version 1.0.3&#xD;
21
+ what 1.0.2 should be&#xD;
22
+ &#xD;
23
+ -- version 1.0.2&#xD;
24
+ better url support&#xD;
25
+ &#xD;
26
+ -- version 1.0.1&#xD;
27
+ Making all request async by default&#xD;
28
+ &#xD;
29
+ -- version 1.0.0&#xD;
30
+ Rename of dict parameter on inventory items&#xD;
31
+ &#xD;
32
+ -- version 0.0.9&#xD;
33
+ Category IDS names instead of integers when sending inventory items&#xD;
34
+ &#xD;
35
+ -- version 0.0.8&#xD;
36
+ Allowing to send ALL products and customers on each save&#xD;
37
+ &#xD;
38
+ -- version 0.0.7&#xD;
39
+ Bug fix on auto submit products and users on Magento 1.6.2.0&#xD;
40
+ &#xD;
41
+ -- version 0.0.6&#xD;
42
+ Correcting but on orders export (timestamp)&#xD;
43
+ &#xD;
44
+ -- version 0.0.5&#xD;
45
+ Automatic Customer and Product submission&#xD;
46
+ &#xD;
47
+ -- version 0.0.4&#xD;
48
+ Bug fixes, new data on product import, debug facility&#xD;
49
+ &#xD;
50
+ -- version 0.0.1&#xD;
51
+ First release</notes>
52
+ <authors><author><name>SimpleRelevance DEV team</name><user>simplerelevance</user><email>info@simplerelevance.com</email></author></authors>
53
+ <date>2013-09-09</date>
54
+ <time>20:33:32</time>
55
+ <contents><target name="magecommunity"><dir name="SimpleRelevance"><dir name="Integration"><dir name="Helper"><file name="Data.php" hash="d7c238082d54ce8aabc291b0ffab862c"/></dir><dir name="Model"><file name="Api.php" hash="7f666e0591fcdd3b78758cfbe33b6cea"/><file name="Observer.php" hash="8d35a597184cf902c2a6c859d3286c00"/><file name="Purchase.php" hash="3b657564042c912e89488ff0d29c3091"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ExportController.php" hash="ef9863bba66c9b2ba088553fa4725a65"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="18e9829f6252920f6bf01a5340377b3a"/><file name="config.xml" hash="3ba8219cb93dba44fb1a1e7bcfadcd49"/><file name="system.xml" hash="d94f64025adb391d15393943482834ed"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="simple_relevance.xml" hash="f0d73f30b7aeff70f63b295327ac906c"/></dir><dir name="simple_relevance"><file name="css.css" hash="c354dd9c0e48bdb99089b1756058efc1"/><dir name="images"><file name="box-tab.png" hash="208977131fcbe078f10af53295ac686c"/><file name="simplerelevance-header.png" hash="c25099645618a32b8fdb8d4d7786cf2c"/></dir><file name="js.js" hash="5831e6e503ebd86f93e07230b56a6d2f"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SimpleRelevance_Integration.xml" hash="0edc0425053fc8bb7dd3dde28b651a53"/></dir></target><target name="magelocale"><dir name="en_US"><file name="SimpleRelevance_Integration.csv" hash="62ea0be4e1c074ee5d975c0dc4a8dc77"/></dir></target></contents>
56
  <compatible/>
57
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
58
  </package>