Version Notes
Initial Code
Download this release
Release Info
Developer | MineWhat Inc. |
Extension | choiceai |
Version | 1.0.9 |
Comparing to | |
See all releases |
Code changes from version 1.0.8 to 1.0.9
- app/code/community/ChoiceAI/Personalisation/controllers/ApiController.php +220 -16
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Attribute.php +45 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Boolean.php +20 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Category.php +33 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Decimal.php +45 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Price.php +50 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/View.php +120 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Product/List.php +52 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Product/List/Toolbar.php +34 -0
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Enterprise/Layer.php +115 -0
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Layer.php +115 -0
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Layer/Filter/Attribute.php +46 -0
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Result.php +36 -0
- app/code/local/ChoiceAI/Search/Helper/Catalogsearch.php +19 -0
- app/code/local/ChoiceAI/Search/Helper/Choiceaisearch.php +16 -0
- app/code/local/ChoiceAI/Search/Helper/Data.php +670 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Category.php +74 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Config.php +120 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer.php +37 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Attribute.php +168 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Boolean.php +41 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Category.php +132 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Decimal.php +190 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Price.php +154 -0
- app/code/local/ChoiceAI/Search/Model/Catalogsearch/Layer.php +31 -0
- app/code/local/ChoiceAI/Search/Model/Catalogsearch/Layer/Filter/Attribute.php +16 -0
- app/code/local/ChoiceAI/Search/Model/Resource/Catalog/Product/Collection.php +368 -0
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Abstract.php +453 -0
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch.php +242 -0
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch/Client.php +29 -0
- app/code/local/ChoiceAI/Search/etc/config.xml +101 -0
- app/code/local/ChoiceAI/Searchcore/Helper/Confighelper.php +472 -0
- app/code/local/ChoiceAI/Searchcore/Helper/Constants.php +195 -0
- app/code/local/ChoiceAI/Searchcore/Helper/Data.php +233 -0
- app/code/local/ChoiceAI/Searchcore/Helper/Feedhelper.php +288 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Request.php +212 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Response.php +165 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task.php +84 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Analyticsimpression.php +49 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Autosuggestindex.php +52 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Feeddetails.php +71 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Searchimpression.php +57 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Searchsetup.php +52 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Supportmail.php +48 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Trackcart.php +46 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Trackorder.php +46 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Triggerfeedupload.php +42 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Updatefeaturefields.php +83 -0
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Validatekeys.php +73 -0
- app/code/local/ChoiceAI/Searchcore/Model/Config.php +47 -0
- app/code/local/ChoiceAI/Searchcore/Model/Field.php +342 -0
- app/code/local/ChoiceAI/Searchcore/Model/Observer.php +201 -0
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Attribute.php +27 -0
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Config.php +213 -0
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Config/Collection.php +21 -0
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Field.php +146 -0
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Field/Collection.php +66 -0
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Product/Collection.php +110 -0
- app/code/local/ChoiceAI/Searchcore/etc/config.xml +133 -0
- app/code/local/ChoiceAI/Searchcore/sql/choiceai_searchcore_setup/mysql4-install-1.0.0.php +91 -0
- app/code/local/ChoiceAI/Searchcore/sql/choiceai_searchcore_setup/upgrade-1.0.21-1.0.22.php +46 -0
- app/design/frontend/base/default/template/choiceai/personalisation/base/script.phtml +1 -0
- app/design/frontend/base/default/template/choiceai/personalisation/event/checkout/onepage/success.phtml +0 -21
- app/design/frontend/default/default/template/choiceai/personalisation/base/script.phtml +5 -0
- app/design/frontend/default/default/template/choiceai/personalisation/event/catalog/product/view.phtml +0 -61
- app/design/frontend/default/default/template/choiceai/personalisation/event/checkout/cart/index.phtml +0 -17
- app/design/frontend/default/default/template/choiceai/personalisation/event/checkout/onepage/success.phtml +0 -20
- app/etc/modules/ChoiceAI_Personalisation.xml +8 -0
- lib/ChoiceAI/Client.php +304 -0
- lib/ChoiceAI/Response.php +45 -0
- lib/ChoiceAI/Result.php +65 -0
- lib/ChoiceAI/ResultSet.php +229 -0
- lib/ChoiceAI/Service.php +190 -0
- lib/ChoiceAI/test.php +53 -0
- package.xml +5 -5
app/code/community/ChoiceAI/Personalisation/controllers/ApiController.php
CHANGED
@@ -10,6 +10,8 @@
|
|
10 |
class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_Action {
|
11 |
|
12 |
const CONFIG_API_KEY = 'choiceai_personalisation/settings/api_key';
|
|
|
|
|
13 |
|
14 |
public function _authorise() {
|
15 |
|
@@ -19,7 +21,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
19 |
if(!$API_KEY && strlen($API_KEY) === 0) {
|
20 |
// Api access disabled
|
21 |
$this->getResponse()
|
22 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'API access disabled', 'version' =>
|
23 |
->setHttpResponseCode(403)
|
24 |
->setHeader('Content-type', 'application/json', true);
|
25 |
return false;
|
@@ -36,7 +38,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
36 |
Mage::log('Unable to extract authorization header from request', null, 'choiceai.log');
|
37 |
// Internal server error
|
38 |
$this->getResponse()
|
39 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error, Authorization header not found', 'version' =>
|
40 |
->setHttpResponseCode(500)
|
41 |
->setHeader('Content-type', 'application/json', true);
|
42 |
return false;
|
@@ -45,7 +47,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
45 |
if(trim($authHeader) !== trim($API_KEY)) {
|
46 |
// Api access denied
|
47 |
$this->getResponse()
|
48 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'Api access denied', 'version' =>
|
49 |
->setHttpResponseCode(401)
|
50 |
->setHeader('Content-type', 'application/json', true);
|
51 |
return false;
|
@@ -55,6 +57,56 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
55 |
|
56 |
}
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
public function ordersAction() {
|
59 |
|
60 |
try {
|
@@ -109,7 +161,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
109 |
}
|
110 |
}
|
111 |
|
112 |
-
$responseObj['version'] =
|
113 |
$this->getResponse()
|
114 |
->setBody(json_encode($responseObj))
|
115 |
->setHttpResponseCode(200)
|
@@ -141,7 +193,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
141 |
}
|
142 |
|
143 |
$this->getResponse()
|
144 |
-
->setBody(json_encode(array('orders' => $orders, 'fromDate' => $fromDate, 'toDate' => $toDate, 'version' =>
|
145 |
->setHttpResponseCode(200)
|
146 |
->setHeader('Content-type', 'application/json', true);
|
147 |
|
@@ -149,7 +201,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
149 |
|
150 |
} catch(Exception $e) {
|
151 |
$this->getResponse()
|
152 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' =>
|
153 |
->setHttpResponseCode(500)
|
154 |
->setHeader('Content-type', 'application/json', true);
|
155 |
}
|
@@ -158,6 +210,106 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
158 |
|
159 |
}
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
public function productsAction() {
|
162 |
|
163 |
try {
|
@@ -225,14 +377,14 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
225 |
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
|
226 |
|
227 |
$this->getResponse()
|
228 |
-
->setBody(json_encode(array('products' => $products, 'currency' => $currency, 'version' =>
|
229 |
->setHttpResponseCode(200)
|
230 |
->setHeader('Content-type', 'application/json', true);
|
231 |
|
232 |
|
233 |
} catch(Exception $e) {
|
234 |
$this->getResponse()
|
235 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' =>
|
236 |
->setHttpResponseCode(500)
|
237 |
->setHeader('Content-type', 'application/json', true);
|
238 |
}
|
@@ -318,14 +470,14 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
318 |
}
|
319 |
|
320 |
$this->getResponse()
|
321 |
-
->setBody(json_encode(array('categories' => $categories, 'version' =>
|
322 |
->setHttpResponseCode(200)
|
323 |
->setHeader('Content-type', 'application/json', true);
|
324 |
|
325 |
|
326 |
} catch(Exception $e) {
|
327 |
$this->getResponse()
|
328 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' =>
|
329 |
->setHttpResponseCode(500)
|
330 |
->setHeader('Content-type', 'application/json', true);
|
331 |
}
|
@@ -398,13 +550,13 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
398 |
|
399 |
|
400 |
$this->getResponse()
|
401 |
-
->setBody(json_encode(array('users' => $users, 'version' =>
|
402 |
->setHttpResponseCode(200)
|
403 |
->setHeader('Content-type', 'application/json', true);
|
404 |
|
405 |
} catch(Exception $e) {
|
406 |
$this->getResponse()
|
407 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' =>
|
408 |
->setHttpResponseCode(500)
|
409 |
->setHeader('Content-type', 'application/json', true);
|
410 |
}
|
@@ -429,7 +581,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
429 |
if(!$productId || strlen($productId) <= 0) {
|
430 |
|
431 |
$this->getResponse()
|
432 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'product id required', 'version' =>
|
433 |
->setHttpResponseCode(500)
|
434 |
->setHeader('Content-type', 'application/json', true);
|
435 |
|
@@ -440,7 +592,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
440 |
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $productId);
|
441 |
if($product == null) {
|
442 |
$this->getResponse()
|
443 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'invalid sku', 'version' =>
|
444 |
->setHttpResponseCode(500)
|
445 |
->setHeader('Content-type', 'application/json', true);
|
446 |
return $this;
|
@@ -454,7 +606,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
454 |
$stock = $stockObj->getQty();
|
455 |
|
456 |
$this->getResponse()
|
457 |
-
->setBody(json_encode(array('id' => $productId, 'stock' => $stock, 'version' =>
|
458 |
->setHttpResponseCode(200)
|
459 |
->setHeader('Content-type', 'application/json', true);
|
460 |
|
@@ -462,7 +614,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
462 |
|
463 |
} catch(Exception $e) {
|
464 |
$this->getResponse()
|
465 |
-
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' =>
|
466 |
->setHttpResponseCode(500)
|
467 |
->setHeader('Content-type', 'application/json', true);
|
468 |
}
|
@@ -563,4 +715,56 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
563 |
|
564 |
}
|
565 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
566 |
}
|
10 |
class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_Action {
|
11 |
|
12 |
const CONFIG_API_KEY = 'choiceai_personalisation/settings/api_key';
|
13 |
+
const CONFIG_KEY = 'choiceai_personalisation/settings/config';
|
14 |
+
const API_VERSION = 3;
|
15 |
|
16 |
public function _authorise() {
|
17 |
|
21 |
if(!$API_KEY && strlen($API_KEY) === 0) {
|
22 |
// Api access disabled
|
23 |
$this->getResponse()
|
24 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'API access disabled', 'version' => self::API_VERSION)))
|
25 |
->setHttpResponseCode(403)
|
26 |
->setHeader('Content-type', 'application/json', true);
|
27 |
return false;
|
38 |
Mage::log('Unable to extract authorization header from request', null, 'choiceai.log');
|
39 |
// Internal server error
|
40 |
$this->getResponse()
|
41 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error, Authorization header not found', 'version' => self::API_VERSION)))
|
42 |
->setHttpResponseCode(500)
|
43 |
->setHeader('Content-type', 'application/json', true);
|
44 |
return false;
|
47 |
if(trim($authHeader) !== trim($API_KEY)) {
|
48 |
// Api access denied
|
49 |
$this->getResponse()
|
50 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Api access denied', 'version' => self::API_VERSION)))
|
51 |
->setHttpResponseCode(401)
|
52 |
->setHeader('Content-type', 'application/json', true);
|
53 |
return false;
|
57 |
|
58 |
}
|
59 |
|
60 |
+
public function configAction() {
|
61 |
+
|
62 |
+
try {
|
63 |
+
|
64 |
+
if(!$this->_authorise()) {
|
65 |
+
return $this;
|
66 |
+
}
|
67 |
+
|
68 |
+
$responseObj = array();
|
69 |
+
|
70 |
+
if ($_SERVER["REQUEST_METHOD"] == "GET") {
|
71 |
+
$STORE_CONFIG = Mage::getStoreConfig(self::CONFIG_KEY);
|
72 |
+
$responseObj["status"] = "ok";
|
73 |
+
$responseObj["config"] = json_decode($STORE_CONFIG);
|
74 |
+
} else if ($_SERVER["REQUEST_METHOD"] == "PUT") {
|
75 |
+
$store_config = $this->getRequest()->getParam('config');
|
76 |
+
if($store_config ==""){
|
77 |
+
$input = file_get_contents('php://input');
|
78 |
+
$input = utf8_encode($input);
|
79 |
+
$store_config = json_encode(json_decode($input)->config);
|
80 |
+
}
|
81 |
+
$store_config_json = json_decode($store_config);
|
82 |
+
if ($store_config_json == NULL) {
|
83 |
+
throw new Exception();
|
84 |
+
}
|
85 |
+
Mage::getModel('core/config')->saveConfig(self::CONFIG_KEY, $store_config);
|
86 |
+
Mage::app()->getStore()->resetConfig();
|
87 |
+
$responseObj["status"] = "ok";
|
88 |
+
} else {
|
89 |
+
$responseObj['status'] = 'error';
|
90 |
+
$responseObj['message'] = 'Invalid request';
|
91 |
+
}
|
92 |
+
|
93 |
+
$responseObj['version'] = self::API_VERSION;
|
94 |
+
$this->getResponse()
|
95 |
+
->setBody(json_encode($responseObj))
|
96 |
+
->setHttpResponseCode(200)
|
97 |
+
->setHeader('Content-type', 'application/json', true);
|
98 |
+
|
99 |
+
} catch(Exception $e) {
|
100 |
+
$this->getResponse()
|
101 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
102 |
+
->setHttpResponseCode(500)
|
103 |
+
->setHeader('Content-type', 'application/json', true);
|
104 |
+
}
|
105 |
+
|
106 |
+
return this;
|
107 |
+
|
108 |
+
}
|
109 |
+
|
110 |
public function ordersAction() {
|
111 |
|
112 |
try {
|
161 |
}
|
162 |
}
|
163 |
|
164 |
+
$responseObj['version'] = self::API_VERSION;
|
165 |
$this->getResponse()
|
166 |
->setBody(json_encode($responseObj))
|
167 |
->setHttpResponseCode(200)
|
193 |
}
|
194 |
|
195 |
$this->getResponse()
|
196 |
+
->setBody(json_encode(array('orders' => $orders, 'fromDate' => $fromDate, 'toDate' => $toDate, 'version' => self::API_VERSION)))
|
197 |
->setHttpResponseCode(200)
|
198 |
->setHeader('Content-type', 'application/json', true);
|
199 |
|
201 |
|
202 |
} catch(Exception $e) {
|
203 |
$this->getResponse()
|
204 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
205 |
->setHttpResponseCode(500)
|
206 |
->setHeader('Content-type', 'application/json', true);
|
207 |
}
|
210 |
|
211 |
}
|
212 |
|
213 |
+
public function productattributesAction() {
|
214 |
+
|
215 |
+
try {
|
216 |
+
|
217 |
+
if(!$this->_authorise()) {
|
218 |
+
return $this;
|
219 |
+
}
|
220 |
+
|
221 |
+
$sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
|
222 |
+
|
223 |
+
if(!isset($sections[3])) {
|
224 |
+
|
225 |
+
throw new Exception();
|
226 |
+
|
227 |
+
}
|
228 |
+
|
229 |
+
$productId = $sections[3];
|
230 |
+
|
231 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
232 |
+
|
233 |
+
$product_info = array();
|
234 |
+
|
235 |
+
$product_info["is_available"] = $product->isAvailable();
|
236 |
+
$product_info["name"] = $product->getName();
|
237 |
+
$product_info["id"] = $product->getId();
|
238 |
+
$product_info["sku"] = $product->getSku();
|
239 |
+
$product_info["price"] = $product->getPrice();
|
240 |
+
$product_info["final_price"] = $product->getFinalPrice();
|
241 |
+
$product_info["special_price"] = $product->getSpecialPrice();
|
242 |
+
$product_info["type"] = $product->getTypeId();
|
243 |
+
|
244 |
+
$variants = array();
|
245 |
+
$options = array();
|
246 |
+
|
247 |
+
if ($product->getTypeId() == "configurable") {
|
248 |
+
|
249 |
+
$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
|
250 |
+
$attributeTypes = array();
|
251 |
+
|
252 |
+
foreach ($productAttributeOptions as $productAttribute) {
|
253 |
+
|
254 |
+
$attributes = array();
|
255 |
+
foreach ($productAttribute['values'] as $attribute) {
|
256 |
+
$attributes[] = array(
|
257 |
+
"id" => $attribute["value_index"],
|
258 |
+
"name" => $attribute["store_label"]
|
259 |
+
);
|
260 |
+
}
|
261 |
+
|
262 |
+
$attributeType = $productAttribute["attribute_code"];
|
263 |
+
$options[] = array(
|
264 |
+
"id" => $productAttribute["id"],
|
265 |
+
"key" => $attributeType,
|
266 |
+
"name" => $productAttribute["store_label"],
|
267 |
+
"values" => $attributes,
|
268 |
+
"position" => $productAttribute["position"]
|
269 |
+
);
|
270 |
+
|
271 |
+
$attributeTypes[] = $attributeType;
|
272 |
+
|
273 |
+
}
|
274 |
+
|
275 |
+
$associatedProducts = $product->getTypeInstance()->getUsedProducts();
|
276 |
+
foreach ($associatedProducts as $associatedProduct) {
|
277 |
+
|
278 |
+
$variant = array();
|
279 |
+
$variant["is_available"] = $associatedProduct->isAvailable();
|
280 |
+
$variant["id"] = $associatedProduct->getId();
|
281 |
+
$variant["sku"] = $associatedProduct->getSku();
|
282 |
+
$variant["price"] = $associatedProduct->getPrice();
|
283 |
+
$variant["final_price"] = $associatedProduct->getFinalPrice();
|
284 |
+
$variant["special_price"] = $associatedProduct->getSpecialPrice();
|
285 |
+
|
286 |
+
$associatedProductData = $associatedProduct->getData();
|
287 |
+
foreach ($attributeTypes as $attributeType) {
|
288 |
+
$variant[$attributeType] = $associatedProductData[$attributeType];
|
289 |
+
}
|
290 |
+
|
291 |
+
$variants[] = $variant;
|
292 |
+
|
293 |
+
}
|
294 |
+
|
295 |
+
}
|
296 |
+
|
297 |
+
$this->getResponse()
|
298 |
+
->setBody(json_encode(array('product' => $product_info, 'variants' => $variants, 'options' => $options, 'version' => self::API_VERSION)))
|
299 |
+
->setHttpResponseCode(200)
|
300 |
+
->setHeader('Content-type', 'application/json', true);
|
301 |
+
|
302 |
+
} catch(Exception $e) {
|
303 |
+
$this->getResponse()
|
304 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
305 |
+
->setHttpResponseCode(500)
|
306 |
+
->setHeader('Content-type', 'application/json', true);
|
307 |
+
}
|
308 |
+
|
309 |
+
return $this;
|
310 |
+
|
311 |
+
}
|
312 |
+
|
313 |
public function productsAction() {
|
314 |
|
315 |
try {
|
377 |
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
|
378 |
|
379 |
$this->getResponse()
|
380 |
+
->setBody(json_encode(array('products' => $products, 'currency' => $currency, 'version' => self::API_VERSION)))
|
381 |
->setHttpResponseCode(200)
|
382 |
->setHeader('Content-type', 'application/json', true);
|
383 |
|
384 |
|
385 |
} catch(Exception $e) {
|
386 |
$this->getResponse()
|
387 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
388 |
->setHttpResponseCode(500)
|
389 |
->setHeader('Content-type', 'application/json', true);
|
390 |
}
|
470 |
}
|
471 |
|
472 |
$this->getResponse()
|
473 |
+
->setBody(json_encode(array('categories' => $categories, 'version' => self::API_VERSION)))
|
474 |
->setHttpResponseCode(200)
|
475 |
->setHeader('Content-type', 'application/json', true);
|
476 |
|
477 |
|
478 |
} catch(Exception $e) {
|
479 |
$this->getResponse()
|
480 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
481 |
->setHttpResponseCode(500)
|
482 |
->setHeader('Content-type', 'application/json', true);
|
483 |
}
|
550 |
|
551 |
|
552 |
$this->getResponse()
|
553 |
+
->setBody(json_encode(array('users' => $users, 'version' => self::API_VERSION)))
|
554 |
->setHttpResponseCode(200)
|
555 |
->setHeader('Content-type', 'application/json', true);
|
556 |
|
557 |
} catch(Exception $e) {
|
558 |
$this->getResponse()
|
559 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
560 |
->setHttpResponseCode(500)
|
561 |
->setHeader('Content-type', 'application/json', true);
|
562 |
}
|
581 |
if(!$productId || strlen($productId) <= 0) {
|
582 |
|
583 |
$this->getResponse()
|
584 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'product id required', 'version' => self::API_VERSION)))
|
585 |
->setHttpResponseCode(500)
|
586 |
->setHeader('Content-type', 'application/json', true);
|
587 |
|
592 |
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $productId);
|
593 |
if($product == null) {
|
594 |
$this->getResponse()
|
595 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'invalid sku', 'version' => self::API_VERSION)))
|
596 |
->setHttpResponseCode(500)
|
597 |
->setHeader('Content-type', 'application/json', true);
|
598 |
return $this;
|
606 |
$stock = $stockObj->getQty();
|
607 |
|
608 |
$this->getResponse()
|
609 |
+
->setBody(json_encode(array('id' => $productId, 'stock' => $stock, 'version' => self::API_VERSION)))
|
610 |
->setHttpResponseCode(200)
|
611 |
->setHeader('Content-type', 'application/json', true);
|
612 |
|
614 |
|
615 |
} catch(Exception $e) {
|
616 |
$this->getResponse()
|
617 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
618 |
->setHttpResponseCode(500)
|
619 |
->setHeader('Content-type', 'application/json', true);
|
620 |
}
|
715 |
|
716 |
}
|
717 |
|
718 |
+
public function sortbyAction() {
|
719 |
+
|
720 |
+
try {
|
721 |
+
|
722 |
+
if(!$this->_authorise()) {
|
723 |
+
return $this;
|
724 |
+
}
|
725 |
+
|
726 |
+
$sortByOptions = array();
|
727 |
+
// $attributesData = Mage::getResourceModel('catalog/config')->getAttributesUsedForSortBy();
|
728 |
+
|
729 |
+
// foreach ($attributesData as $attributeData) {
|
730 |
+
// $sortByOptions[$attributeData['attribute_code']] = array(
|
731 |
+
// "attribute_id"=> $attributeData['attribute_id'],
|
732 |
+
// "attribute_code"=> $attributeData['attribute_code'],
|
733 |
+
// "frontend_label"=> $attributeData['frontend_label'],
|
734 |
+
// "store_label"=> $attributeData['store_label']
|
735 |
+
// );
|
736 |
+
// }
|
737 |
+
|
738 |
+
$category = Mage::getModel('catalog/category');
|
739 |
+
|
740 |
+
$attributesData = $category->getAvailableSortByOptions();
|
741 |
+
$defaultSort = $category->getDefaultSortBy();
|
742 |
+
|
743 |
+
$i = 1;
|
744 |
+
|
745 |
+
foreach ($attributesData as $key => $attributeData) {
|
746 |
+
$sortByOptions[] = array(
|
747 |
+
"_id"=> $key,
|
748 |
+
"name"=> $attributeData,
|
749 |
+
"default"=> $key==$defaultSort ? true:false,
|
750 |
+
"order"=> $i
|
751 |
+
);
|
752 |
+
$i++;
|
753 |
+
}
|
754 |
+
|
755 |
+
$this->getResponse()
|
756 |
+
->setBody(json_encode(array('status' => "ok", 'options' => $sortByOptions, 'version' => self::API_VERSION)))
|
757 |
+
->setHttpResponseCode(200)
|
758 |
+
->setHeader('Content-type', 'application/json', true);
|
759 |
+
|
760 |
+
} catch(Exception $e) {
|
761 |
+
$this->getResponse()
|
762 |
+
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
763 |
+
->setHttpResponseCode(500)
|
764 |
+
->setHeader('Content-type', 'application/json', true);
|
765 |
+
}
|
766 |
+
|
767 |
+
return $this;
|
768 |
+
}
|
769 |
+
|
770 |
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Attribute.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @package ChoiceAI_Search
|
5 |
+
* @copyright Copyright (c) MineWhat
|
6 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
7 |
+
*/
|
8 |
+
class ChoiceAI_Search_Block_Catalog_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Abstract
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Defines specific filter model name.
|
12 |
+
*
|
13 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Attribute
|
14 |
+
*/
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
parent::__construct();
|
18 |
+
$this->_filterModelName = 'choiceai_search/catalog_layer_filter_attribute';
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Prepares filter model.
|
23 |
+
*
|
24 |
+
* @return ChoiceAI_Search_Block_Catalog_Layer_Filter_Attribute
|
25 |
+
*/
|
26 |
+
protected function _prepareFilter()
|
27 |
+
{
|
28 |
+
$this->_filter->setAttributeModel($this->getAttributeModel());
|
29 |
+
|
30 |
+
return $this;
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Adds facet condition to filter.
|
35 |
+
*
|
36 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Attribute::addFacetCondition()
|
37 |
+
* @return ChoiceAI_Search_Block_Catalog_Layer_Filter_Attribute
|
38 |
+
*/
|
39 |
+
public function addFacetCondition()
|
40 |
+
{
|
41 |
+
$this->_filter->addFacetCondition();
|
42 |
+
|
43 |
+
return $this;
|
44 |
+
}
|
45 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Boolean.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @package ChoiceAI_Search
|
5 |
+
* @copyright Copyright (c) MineWhat
|
6 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
7 |
+
*/
|
8 |
+
class ChoiceAI_Search_Block_Catalog_Layer_Filter_Boolean extends ChoiceAI_Search_Block_Catalog_Layer_Filter_Attribute
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Defines specific filter model name.
|
12 |
+
*
|
13 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Boolean
|
14 |
+
*/
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
parent::__construct();
|
18 |
+
$this->_filterModelName = 'choiceai_search/catalog_layer_filter_boolean';
|
19 |
+
}
|
20 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Category.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @package ChoiceAI_Search
|
5 |
+
* @copyright Copyright (c) MineWhat
|
6 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
7 |
+
*/
|
8 |
+
class ChoiceAI_Search_Block_Catalog_Layer_Filter_Category extends Mage_Catalog_Block_Layer_Filter_Abstract
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Defines specific filter model name.
|
12 |
+
*
|
13 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Category
|
14 |
+
*/
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
parent::__construct();
|
18 |
+
$this->_filterModelName = 'choiceai_search/catalog_layer_filter_category';
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Adds facet condition to filter.
|
23 |
+
*
|
24 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Category::addFacetCondition()
|
25 |
+
* @return ChoiceAI_Search_Block_Catalog_Layer_Filter_Attribute
|
26 |
+
*/
|
27 |
+
public function addFacetCondition()
|
28 |
+
{
|
29 |
+
$this->_filter->addFacetCondition();
|
30 |
+
|
31 |
+
return $this;
|
32 |
+
}
|
33 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Decimal.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @package ChoiceAI_Search
|
5 |
+
* @copyright Copyright (c) MineWhat
|
6 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
7 |
+
*/
|
8 |
+
class ChoiceAI_Search_Block_Catalog_Layer_Filter_Decimal extends Mage_Catalog_Block_Layer_Filter_Abstract
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Defines specific filter model name.
|
12 |
+
*
|
13 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Decimal
|
14 |
+
*/
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
parent::__construct();
|
18 |
+
$this->_filterModelName = 'choiceai_search/catalog_layer_filter_decimal';
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Prepares filter model.
|
23 |
+
*
|
24 |
+
* @return ChoiceAI_Search_Block_Catalog_Layer_Filter_Decimal
|
25 |
+
*/
|
26 |
+
protected function _prepareFilter()
|
27 |
+
{
|
28 |
+
$this->_filter->setAttributeModel($this->getAttributeModel());
|
29 |
+
|
30 |
+
return $this;
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Adds facet condition to filter.
|
35 |
+
*
|
36 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Decimal::addFacetCondition()
|
37 |
+
* @return ChoiceAI_Search_Block_Catalog_Layer_Filter_Decimal
|
38 |
+
*/
|
39 |
+
public function addFacetCondition()
|
40 |
+
{
|
41 |
+
$this->_filter->addFacetCondition();
|
42 |
+
|
43 |
+
return $this;
|
44 |
+
}
|
45 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Price.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @package ChoiceAI_Search
|
5 |
+
* @copyright Copyright (c) MineWhat
|
6 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
7 |
+
*/
|
8 |
+
class ChoiceAI_Search_Block_Catalog_Layer_Filter_Price extends Mage_Catalog_Block_Layer_Filter_Abstract
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Defines specific filter model name.
|
12 |
+
*
|
13 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Price
|
14 |
+
*/
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
parent::__construct();
|
18 |
+
$this->_filterModelName = 'choiceai_search/catalog_layer_filter_price';
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Prepares filter model.
|
23 |
+
*
|
24 |
+
* @return ChoiceAI_Search_Block_Catalog_Layer_Filter_Price
|
25 |
+
*/
|
26 |
+
protected function _prepareFilter()
|
27 |
+
{
|
28 |
+
$this->_filter->setAttributeModel($this->getAttributeModel());
|
29 |
+
|
30 |
+
return $this;
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Adds facet condition to filter.
|
35 |
+
*
|
36 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Price::addFacetCondition()
|
37 |
+
* @return ChoiceAI_Search_Block_Catalog_Layer_Filter_Price
|
38 |
+
*/
|
39 |
+
public function addFacetCondition()
|
40 |
+
{
|
41 |
+
if (!$this->getRequest()->getParam('price')) {
|
42 |
+
$this->_filter->addFacetCondition();
|
43 |
+
}
|
44 |
+
|
45 |
+
return $this;
|
46 |
+
}
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Layer/View.php
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Overrides default layer view process to define custom filter blocks.
|
4 |
+
*
|
5 |
+
* @package ChoiceAI_Search
|
6 |
+
* @copyright Copyright (c) MineWhat
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
class ChoiceAI_Search_Block_Catalog_Layer_View extends Mage_Catalog_Block_Layer_View
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* Boolean block name.
|
13 |
+
*
|
14 |
+
* @var string
|
15 |
+
*/
|
16 |
+
protected $_booleanFilterBlockName;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Registers current layer in registry.
|
20 |
+
*
|
21 |
+
* @see Mage_Catalog_Block_Product_List::getLayer()
|
22 |
+
*/
|
23 |
+
protected function _construct()
|
24 |
+
{
|
25 |
+
parent::_construct();
|
26 |
+
Mage::unregister('current_layer');
|
27 |
+
Mage::register('current_layer', $this->getLayer());
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Modifies default block names to specific ones if engine is active.
|
32 |
+
*/
|
33 |
+
protected function _initBlocks()
|
34 |
+
{
|
35 |
+
parent::_initBlocks();
|
36 |
+
if (Mage::helper('choiceai_search')->isActiveEngine()) {
|
37 |
+
$this->_categoryBlockName = 'choiceai_search/catalog_layer_filter_category';
|
38 |
+
$this->_attributeFilterBlockName = 'choiceai_search/catalog_layer_filter_attribute';
|
39 |
+
$this->_priceFilterBlockName = 'choiceai_search/catalog_layer_filter_price';
|
40 |
+
$this->_decimalFilterBlockName = 'choiceai_search/catalog_layer_filter_decimal';
|
41 |
+
$this->_booleanFilterBlockName = 'choiceai_search/catalog_layer_filter_boolean';
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Prepares layout if engine is active.
|
47 |
+
* Difference between parent method is addFacetCondition() call on each created block.
|
48 |
+
*
|
49 |
+
* @return ChoiceAI_Search_Block_Catalog_Layer_View
|
50 |
+
*/
|
51 |
+
protected function _prepareLayout()
|
52 |
+
{
|
53 |
+
if (Mage::helper('choiceai_search')->isActiveEngine()) {
|
54 |
+
$stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
|
55 |
+
->setLayer($this->getLayer());
|
56 |
+
|
57 |
+
$categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
|
58 |
+
->setLayer($this->getLayer())
|
59 |
+
->init();
|
60 |
+
|
61 |
+
$this->setChild('layer_state', $stateBlock);
|
62 |
+
$this->setChild('category_filter', $categoryBlock->addFacetCondition());
|
63 |
+
|
64 |
+
$filterableAttributes = $this->_getFilterableAttributes();
|
65 |
+
$filters = array();
|
66 |
+
foreach ($filterableAttributes as $attribute) {
|
67 |
+
if ($attribute->getAttributeCode() == 'price') {
|
68 |
+
$filterBlockName = $this->_priceFilterBlockName;
|
69 |
+
} elseif ($attribute->getBackendType() == 'decimal') {
|
70 |
+
$filterBlockName = $this->_decimalFilterBlockName;
|
71 |
+
} elseif ($attribute->getSourceModel() == 'eav/entity_attribute_source_boolean') {
|
72 |
+
$filterBlockName = $this->_booleanFilterBlockName;
|
73 |
+
} else {
|
74 |
+
$filterBlockName = $this->_attributeFilterBlockName;
|
75 |
+
}
|
76 |
+
|
77 |
+
$filters[$attribute->getAttributeCode() . '_filter'] = $this->getLayout()->createBlock($filterBlockName)
|
78 |
+
->setLayer($this->getLayer())
|
79 |
+
->setAttributeModel($attribute)
|
80 |
+
->init();
|
81 |
+
}
|
82 |
+
|
83 |
+
foreach ($filters as $filterName => $block) {
|
84 |
+
$this->setChild($filterName, $block->addFacetCondition());
|
85 |
+
}
|
86 |
+
|
87 |
+
$this->getLayer()->apply();
|
88 |
+
$this->getLayer()->getProductCollection()->load();
|
89 |
+
} else {
|
90 |
+
parent::_prepareLayout();
|
91 |
+
|
92 |
+
}
|
93 |
+
|
94 |
+
return $this;
|
95 |
+
}
|
96 |
+
|
97 |
+
|
98 |
+
public function getRequest(){
|
99 |
+
$controller = Mage::app()->getFrontController();
|
100 |
+
if ($controller) {
|
101 |
+
$this->_request = $controller->getRequest();
|
102 |
+
} else {
|
103 |
+
throw new Exception(Mage::helper('core')->__("Can't retrieve request object"));
|
104 |
+
}
|
105 |
+
return $this->_request;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Returns current catalog layer.
|
110 |
+
*
|
111 |
+
* @return ChoiceAI_Search_Model_Catalog_Layer|Mage_Catalog_Model_Layer
|
112 |
+
*/
|
113 |
+
public function getLayer()
|
114 |
+
{
|
115 |
+
if (Mage::helper('choiceai_search')->isActiveEngine()) {
|
116 |
+
return Mage::getSingleton('choiceai_search/catalog_layer');
|
117 |
+
}
|
118 |
+
return parent::getLayer();
|
119 |
+
}
|
120 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Product/List.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_Catalog
|
23 |
+
* @copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Product list
|
30 |
+
*
|
31 |
+
* @category Mage
|
32 |
+
* @package Mage_Catalog
|
33 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
34 |
+
*/
|
35 |
+
class ChoiceAI_Search_Block_Catalog_Product_List extends Mage_Catalog_Block_Product_List
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* Get catalog layer model
|
39 |
+
*
|
40 |
+
* @return Mage_Catalog_Model_Layer
|
41 |
+
*/
|
42 |
+
public function getLayer()
|
43 |
+
{
|
44 |
+
/** @var $helper ChoiceAI_Search_Helper_Data */
|
45 |
+
$helper = Mage::helper('choiceai_search');
|
46 |
+
if ($helper->isActiveEngine()) {
|
47 |
+
return Mage::getSingleton('choiceai_search/catalogsearch_layer');
|
48 |
+
}
|
49 |
+
return parent::getLayer();
|
50 |
+
}
|
51 |
+
|
52 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Product/List/Toolbar.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: harkirat
|
5 |
+
* Date: 16/5/17
|
6 |
+
* Time: 6:04 PM
|
7 |
+
*/
|
8 |
+
|
9 |
+
class ChoiceAI_Search_Block_Catalog_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar {
|
10 |
+
|
11 |
+
const IS_ACTIVE = 'choiceai_personalisation/settings/active';
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Set default Order field
|
15 |
+
*
|
16 |
+
* @param string $field
|
17 |
+
* @return Mage_Catalog_Block_Product_List_Toolbar
|
18 |
+
*/
|
19 |
+
public function getCurrentOrder()
|
20 |
+
{
|
21 |
+
// To set currently selected sort by option to extended/overridden one, in case of search/productlist
|
22 |
+
if(Mage::getStoreConfig(self::IS_ACTIVE)=='1') {
|
23 |
+
if (is_null($_REQUEST['order']) && isset($_SESSION['plist_sort_by'])) {
|
24 |
+
return $_SESSION['plist_sort_by'];
|
25 |
+
} else if ($_REQUEST['order'] == $_SESSION['plist_sort_by']) {
|
26 |
+
return $_SESSION['plist_sort_by'];
|
27 |
+
} else{
|
28 |
+
return parent::getCurrentOrder();
|
29 |
+
}
|
30 |
+
} else {
|
31 |
+
return parent::getCurrentOrder();
|
32 |
+
}
|
33 |
+
}
|
34 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalogsearch/Enterprise/Layer.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Overrides default layer view process to define custom filter blocks.
|
4 |
+
*
|
5 |
+
* @package ChoiceAI_Search
|
6 |
+
* @copyright Copyright (c) MineWhat
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
class ChoiceAI_Search_Block_Catalogsearch_Enterprise_Layer extends Enterprise_Search_Block_Catalogsearch_Layer
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* Boolean block name.
|
13 |
+
*
|
14 |
+
* @var string
|
15 |
+
*/
|
16 |
+
protected $_booleanFilterBlockName;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Modifies default block names to specific ones if engine is active.
|
20 |
+
*/
|
21 |
+
protected function _initBlocks()
|
22 |
+
{
|
23 |
+
parent::_initBlocks();
|
24 |
+
|
25 |
+
if (Mage::helper('choiceai_search')->isActiveEngine()) {
|
26 |
+
Mage::unregister('current_layer');
|
27 |
+
Mage::register('current_layer', $this->getLayer());
|
28 |
+
$this->_categoryBlockName = 'choiceai_search/catalog_layer_filter_category';
|
29 |
+
$this->_attributeFilterBlockName = 'choiceai_search/catalogsearch_layer_filter_attribute';
|
30 |
+
$this->_priceFilterBlockName = 'choiceai_search/catalog_layer_filter_price';
|
31 |
+
$this->_decimalFilterBlockName = 'choiceai_search/catalog_layer_filter_decimal';
|
32 |
+
$this->_booleanFilterBlockName = 'choiceai_search/catalog_layer_filter_boolean';
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Prepares layout if engine is active.
|
38 |
+
* Difference between parent method is addFacetCondition() call on each created block.
|
39 |
+
*
|
40 |
+
* @return ChoiceAI_Search_Block_Catalogsearch_Layer
|
41 |
+
*/
|
42 |
+
protected function _prepareLayout()
|
43 |
+
{
|
44 |
+
/** @var $helper ChoiceAI_Search_Helper_Data */
|
45 |
+
$helper = Mage::helper('choiceai_search');
|
46 |
+
if ($helper->isActiveEngine()) {
|
47 |
+
|
48 |
+
$stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
|
49 |
+
->setLayer($this->getLayer());
|
50 |
+
|
51 |
+
$categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
|
52 |
+
->setLayer($this->getLayer())
|
53 |
+
->init();
|
54 |
+
|
55 |
+
$this->setChild('layer_state', $stateBlock);
|
56 |
+
$this->setChild('category_filter', $categoryBlock->addFacetCondition());
|
57 |
+
|
58 |
+
$filterableAttributes = $this->_getFilterableAttributes();
|
59 |
+
$filters = array();
|
60 |
+
foreach ($filterableAttributes as $attribute) {
|
61 |
+
if ($attribute->getAttributeCode() == 'price') {
|
62 |
+
$filterBlockName = $this->_priceFilterBlockName;
|
63 |
+
} elseif ($attribute->getSourceModel() == 'eav/entity_attribute_source_boolean') {
|
64 |
+
$filterBlockName = $this->_booleanFilterBlockName;
|
65 |
+
} elseif ($attribute->getBackendType() == 'decimal') {
|
66 |
+
$filterBlockName = $this->_decimalFilterBlockName;
|
67 |
+
} else {
|
68 |
+
$filterBlockName = $this->_attributeFilterBlockName;
|
69 |
+
}
|
70 |
+
|
71 |
+
$filters[$attribute->getAttributeCode() . '_filter'] = $this->getLayout()->createBlock($filterBlockName)
|
72 |
+
->setLayer($this->getLayer())
|
73 |
+
->setAttributeModel($attribute)
|
74 |
+
->init();
|
75 |
+
}
|
76 |
+
|
77 |
+
foreach ($filters as $filterName => $block) {
|
78 |
+
$this->setChild($filterName, $block->addFacetCondition());
|
79 |
+
}
|
80 |
+
|
81 |
+
$this->getLayer()->apply();
|
82 |
+
$this->getLayer()->getProductCollection()->load();
|
83 |
+
}else{
|
84 |
+
parent::_prepareLayout();
|
85 |
+
}
|
86 |
+
|
87 |
+
return $this;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Checks display availability of layer block.
|
92 |
+
*
|
93 |
+
* @return bool
|
94 |
+
*/
|
95 |
+
public function canShowBlock()
|
96 |
+
{
|
97 |
+
$this->getLayer()->getProductCollection();
|
98 |
+
return ($this->canShowOptions() || count($this->getLayer()->getState()->getFilters()));
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Returns current catalog layer.
|
103 |
+
*
|
104 |
+
* @return ChoiceAI_Search_Model_Catalogsearch_Layer|Mage_Catalog_Model_Layer
|
105 |
+
*/
|
106 |
+
public function getLayer()
|
107 |
+
{
|
108 |
+
/** @var $helper ChoiceAI_Search_Helper_Data */
|
109 |
+
$helper = Mage::helper('choiceai_search');
|
110 |
+
if ($helper->isActiveEngine()) {
|
111 |
+
return Mage::getSingleton('choiceai_search/catalogsearch_layer');
|
112 |
+
}
|
113 |
+
return parent::getLayer();
|
114 |
+
}
|
115 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalogsearch/Layer.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Overrides default layer view process to define custom filter blocks.
|
4 |
+
*
|
5 |
+
* @package ChoiceAI_Search
|
6 |
+
* @copyright Copyright (c) MineWhat
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
class ChoiceAI_Search_Block_Catalogsearch_Layer extends Mage_CatalogSearch_Block_Layer
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* Boolean block name.
|
13 |
+
*
|
14 |
+
* @var string
|
15 |
+
*/
|
16 |
+
protected $_booleanFilterBlockName;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Modifies default block names to specific ones if engine is active.
|
20 |
+
*/
|
21 |
+
protected function _initBlocks()
|
22 |
+
{
|
23 |
+
parent::_initBlocks();
|
24 |
+
|
25 |
+
if (Mage::helper('choiceai_search')->isActiveEngine()) {
|
26 |
+
Mage::unregister('current_layer');
|
27 |
+
Mage::register('current_layer', $this->getLayer());
|
28 |
+
$this->_categoryBlockName = 'choiceai_search/catalog_layer_filter_category';
|
29 |
+
$this->_attributeFilterBlockName = 'choiceai_search/catalogsearch_layer_filter_attribute';
|
30 |
+
$this->_priceFilterBlockName = 'choiceai_search/catalog_layer_filter_price';
|
31 |
+
$this->_decimalFilterBlockName = 'choiceai_search/catalog_layer_filter_decimal';
|
32 |
+
$this->_booleanFilterBlockName = 'choiceai_search/catalog_layer_filter_boolean';
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Prepares layout if engine is active.
|
38 |
+
* Difference between parent method is addFacetCondition() call on each created block.
|
39 |
+
*
|
40 |
+
* @return ChoiceAI_Search_Block_Catalogsearch_Layer
|
41 |
+
*/
|
42 |
+
protected function _prepareLayout()
|
43 |
+
{
|
44 |
+
/** @var $helper ChoiceAI_Search_Helper_Data */
|
45 |
+
$helper = Mage::helper('choiceai_search');
|
46 |
+
if ($helper->isActiveEngine()) {
|
47 |
+
|
48 |
+
$stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
|
49 |
+
->setLayer($this->getLayer());
|
50 |
+
|
51 |
+
$categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
|
52 |
+
->setLayer($this->getLayer())
|
53 |
+
->init();
|
54 |
+
|
55 |
+
$this->setChild('layer_state', $stateBlock);
|
56 |
+
$this->setChild('category_filter', $categoryBlock->addFacetCondition());
|
57 |
+
|
58 |
+
$filterableAttributes = $this->_getFilterableAttributes();
|
59 |
+
$filters = array();
|
60 |
+
foreach ($filterableAttributes as $attribute) {
|
61 |
+
if ($attribute->getAttributeCode() == 'price') {
|
62 |
+
$filterBlockName = $this->_priceFilterBlockName;
|
63 |
+
} elseif ($attribute->getSourceModel() == 'eav/entity_attribute_source_boolean') {
|
64 |
+
$filterBlockName = $this->_booleanFilterBlockName;
|
65 |
+
} elseif ($attribute->getBackendType() == 'decimal') {
|
66 |
+
$filterBlockName = $this->_decimalFilterBlockName;
|
67 |
+
} else {
|
68 |
+
$filterBlockName = $this->_attributeFilterBlockName;
|
69 |
+
}
|
70 |
+
|
71 |
+
$filters[$attribute->getAttributeCode() . '_filter'] = $this->getLayout()->createBlock($filterBlockName)
|
72 |
+
->setLayer($this->getLayer())
|
73 |
+
->setAttributeModel($attribute)
|
74 |
+
->init();
|
75 |
+
}
|
76 |
+
|
77 |
+
foreach ($filters as $filterName => $block) {
|
78 |
+
$this->setChild($filterName, $block->addFacetCondition());
|
79 |
+
}
|
80 |
+
|
81 |
+
$this->getLayer()->apply();
|
82 |
+
$this->getLayer()->getProductCollection()->load();
|
83 |
+
}else{
|
84 |
+
parent::_prepareLayout();
|
85 |
+
}
|
86 |
+
|
87 |
+
return $this;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Checks display availability of layer block.
|
92 |
+
*
|
93 |
+
* @return bool
|
94 |
+
*/
|
95 |
+
public function canShowBlock()
|
96 |
+
{
|
97 |
+
$this->getLayer()->getProductCollection();
|
98 |
+
return ($this->canShowOptions() || count($this->getLayer()->getState()->getFilters()));
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Returns current catalog layer.
|
103 |
+
*
|
104 |
+
* @return ChoiceAI_Search_Model_Catalogsearch_Layer|Mage_Catalog_Model_Layer
|
105 |
+
*/
|
106 |
+
public function getLayer()
|
107 |
+
{
|
108 |
+
/** @var $helper ChoiceAI_Search_Helper_Data */
|
109 |
+
$helper = Mage::helper('choiceai_search');
|
110 |
+
if ($helper->isActiveEngine()) {
|
111 |
+
return Mage::getSingleton('choiceai_search/catalogsearch_layer');
|
112 |
+
}
|
113 |
+
return parent::getLayer();
|
114 |
+
}
|
115 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalogsearch/Layer/Filter/Attribute.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Handles attribute filtering in layered navigation in a query search context.
|
4 |
+
*
|
5 |
+
* @package ChoiceAI_Search
|
6 |
+
* @copyright Copyright (c) MineWhat
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
class ChoiceAI_Search_Block_Catalogsearch_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Abstract
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* Defines specific filter model name.
|
13 |
+
*
|
14 |
+
* @see ChoiceAI_Search_Model_Catalogsearch_Layer_Filter_Attribute
|
15 |
+
*/
|
16 |
+
public function __construct()
|
17 |
+
{
|
18 |
+
parent::__construct();
|
19 |
+
$this->_filterModelName = 'choiceai_search/catalogsearch_layer_filter_attribute';
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Prepares filter model.
|
24 |
+
*
|
25 |
+
* @return ChoiceAI_Search_Block_Catalogsearch_Layer_Filter_Attribute
|
26 |
+
*/
|
27 |
+
protected function _prepareFilter()
|
28 |
+
{
|
29 |
+
$this->_filter->setAttributeModel($this->getAttributeModel());
|
30 |
+
|
31 |
+
return $this;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Adds facet condition to filter.
|
36 |
+
*
|
37 |
+
* @see ChoiceAI_Search_Model_Catalog_Layer_Filter_Attribute::addFacetCondition()
|
38 |
+
* @return ChoiceAI_Search_Block_Catalogsearch_Layer_Filter_Attribute
|
39 |
+
*/
|
40 |
+
public function addFacetCondition()
|
41 |
+
{
|
42 |
+
$this->_filter->addFacetCondition();
|
43 |
+
|
44 |
+
return $this;
|
45 |
+
}
|
46 |
+
}
|
app/code/local/ChoiceAI/Search/Block/Catalogsearch/Result.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: Harkirat
|
5 |
+
* Date: 12/5/17
|
6 |
+
* Time: 12:47 PM
|
7 |
+
*/
|
8 |
+
|
9 |
+
class ChoiceAI_Search_Block_Catalogsearch_Result extends Mage_CatalogSearch_Block_Result {
|
10 |
+
const IS_ACTIVE = 'choiceai_personalisation/settings/active';
|
11 |
+
/**
|
12 |
+
* Set search available list orders
|
13 |
+
*
|
14 |
+
* @return Mage_CatalogSearch_Block_Result
|
15 |
+
*/
|
16 |
+
public function setListOrders()
|
17 |
+
{
|
18 |
+
if(Mage::getStoreConfig(self::IS_ACTIVE)=='1') {
|
19 |
+
$category = Mage::getSingleton('catalog/layer')
|
20 |
+
->getCurrentCategory();
|
21 |
+
/* @var $category Mage_Catalog_Model_Category */
|
22 |
+
$availableOrders = $category->getAvailableSortByOptions();
|
23 |
+
unset($availableOrders['position']);
|
24 |
+
|
25 |
+
// Removed addition of 'Relevance' option here, which is in core functionality
|
26 |
+
$this->getListBlock()
|
27 |
+
->setAvailableOrders($availableOrders)
|
28 |
+
->setDefaultDirection('desc');
|
29 |
+
// ->setSortBy('relevance');
|
30 |
+
}else{
|
31 |
+
return parent::setListOrders();
|
32 |
+
}
|
33 |
+
|
34 |
+
return $this;
|
35 |
+
}
|
36 |
+
}
|
app/code/local/ChoiceAI/Search/Helper/Catalogsearch.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @category ChoiceAI
|
5 |
+
* @package ChoiceAI_Recommendation
|
6 |
+
* @copyright Copyright (c) MineWhat
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
class ChoiceAI_Search_Helper_Catalogsearch extends Mage_CatalogSearch_Helper_Data {
|
10 |
+
|
11 |
+
public function getResultUrl($query = null) {
|
12 |
+
if(Mage::helper('choiceai_search')->isHostedSearchActive()) {
|
13 |
+
$redirectUrl = Mage::helper('choiceai_search')->getHostedRedirectUrl();
|
14 |
+
return $redirectUrl . ((!is_null($query) && $query != "")?($this->getQueryParamName()."=".$query):"");
|
15 |
+
}
|
16 |
+
return parent::getResultUrl($query);
|
17 |
+
}
|
18 |
+
|
19 |
+
}
|
app/code/local/ChoiceAI/Search/Helper/Choiceaisearch.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @package ChoiceAI_Search
|
5 |
+
* @copyright Copyright (c) MineWhat
|
6 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
7 |
+
*/
|
8 |
+
class ChoiceAI_Search_Helper_ChoiceAIsearch extends ChoiceAI_Search_Helper_Data
|
9 |
+
{
|
10 |
+
|
11 |
+
public function getEngineConfigData($prefix = '', $website = null)
|
12 |
+
{
|
13 |
+
return Mage::helper('choiceai_searchcore')->getEngineConfigData($prefix, $website);
|
14 |
+
|
15 |
+
}
|
16 |
+
}
|
app/code/local/ChoiceAI/Search/Helper/Data.php
ADDED
@@ -0,0 +1,670 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|