Version Notes
Initial Code
Download this release
Release Info
Developer | MineWhat Inc. |
Extension | choiceai |
Version | 1.0.10 |
Comparing to | |
See all releases |
Code changes from version 1.0.9 to 1.0.10
- app/code/community/ChoiceAI/Personalisation/Block/Event/Analytics/Listpage.php +26 -0
- app/code/community/ChoiceAI/Personalisation/Block/Event/Analytics/Search.php +26 -0
- app/code/community/ChoiceAI/Personalisation/Block/Searchpage/Addparam.php +20 -0
- app/code/community/ChoiceAI/Personalisation/Model/Observer.php +0 -2
- app/code/community/ChoiceAI/Personalisation/controllers/ApiController.php +503 -43
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/View.php +5 -16
- app/code/local/ChoiceAI/Search/Block/Catalog/Product/List/Toolbar.php +3 -3
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Layer.php +2 -2
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Result.php +1 -1
- app/code/local/ChoiceAI/Search/Helper/Catalogsearch.php +0 -19
- app/code/local/ChoiceAI/Search/Helper/Choiceaisearch.php +0 -1
- app/code/local/ChoiceAI/Search/Helper/Data.php +72 -317
- app/code/local/ChoiceAI/Search/Helper/Productimg.php +43 -0
- app/code/local/ChoiceAI/Search/Model/Catalog/Category.php +1 -2
- app/code/local/ChoiceAI/Search/Model/Catalog/Config.php +13 -12
- app/code/local/ChoiceAI/Search/Model/Catalog/Product/Url.php +73 -0
- app/code/local/ChoiceAI/Search/Model/Resource/Catalog/Product/Collection.php +16 -11
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Abstract.php +5 -294
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch.php +94 -64
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch/Client.php +1 -3
- app/code/local/ChoiceAI/Search/etc/config.xml +5 -47
- app/code/local/ChoiceAI/Searchcore/Helper/Confighelper.php +0 -472
- app/code/local/ChoiceAI/Searchcore/Helper/Constants.php +1 -1
- app/code/local/ChoiceAI/Searchcore/Helper/Data.php +16 -162
- app/code/local/ChoiceAI/Searchcore/Helper/Feedhelper.php +0 -288
- app/code/local/ChoiceAI/Searchcore/Model/Api/Request.php +0 -212
- app/code/local/ChoiceAI/Searchcore/Model/Api/Response.php +0 -165
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task.php +0 -84
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Analyticsimpression.php +0 -49
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Autosuggestindex.php +0 -52
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Feeddetails.php +0 -71
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Searchimpression.php +0 -57
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Searchsetup.php +0 -52
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Supportmail.php +0 -48
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Trackcart.php +0 -46
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Trackorder.php +0 -46
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Triggerfeedupload.php +0 -42
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Updatefeaturefields.php +0 -83
- app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Validatekeys.php +0 -73
- app/code/local/ChoiceAI/Searchcore/Model/Config.php +0 -47
- app/code/local/ChoiceAI/Searchcore/Model/Field.php +0 -342
- app/code/local/ChoiceAI/Searchcore/Model/Observer.php +0 -201
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Attribute.php +0 -27
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Config.php +0 -213
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Config/Collection.php +0 -21
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Field.php +0 -146
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Field/Collection.php +0 -66
- app/code/local/ChoiceAI/Searchcore/Model/Resource/Product/Collection.php +0 -110
- app/code/local/ChoiceAI/Searchcore/etc/config.xml +0 -114
- app/code/local/ChoiceAI/Searchcore/sql/choiceai_searchcore_setup/mysql4-install-1.0.0.php +0 -91
- app/code/local/ChoiceAI/Searchcore/sql/choiceai_searchcore_setup/upgrade-1.0.21-1.0.22.php +0 -46
- app/design/frontend/base/default/layout/choiceai_personalisation.xml +21 -0
- app/design/frontend/base/default/template/choiceai/personalisation/analytics/listpage.phtml +25 -0
- app/design/frontend/base/default/template/choiceai/personalisation/analytics/search.phtml +25 -0
- app/design/frontend/base/default/template/choiceai/personalisation/base/addparam.phtml +34 -0
- lib/ChoiceAI/Client.php +82 -20
- lib/ChoiceAI/Response.php +0 -45
- lib/ChoiceAI/Result.php +4 -4
- lib/ChoiceAI/ResultSet.php +30 -26
- lib/ChoiceAI/Service.php +139 -115
- lib/ChoiceAI/test.php +0 -53
- package.xml +4 -4
app/code/community/ChoiceAI/Personalisation/Block/Event/Analytics/Listpage.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: harkirat
|
5 |
+
* Date: 1/7/17
|
6 |
+
* Time: 3:27 PM
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @category ChoiceAI
|
11 |
+
* @package ChoiceAI_Personalisation
|
12 |
+
* @copyright Copyright (c) MineWhat
|
13 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
14 |
+
*/
|
15 |
+
class ChoiceAI_Personalisation_Block_Event_Analytics_Listpage extends Mage_Core_Block_Template {
|
16 |
+
|
17 |
+
protected function _construct() {
|
18 |
+
parent::_construct();
|
19 |
+
$this->setTemplate('choiceai/personalisation/analytics/listpage.phtml');
|
20 |
+
}
|
21 |
+
|
22 |
+
public function engineStatus(){
|
23 |
+
return Mage::helper('choiceai_search')->isActiveEngine();
|
24 |
+
}
|
25 |
+
|
26 |
+
}
|
app/code/community/ChoiceAI/Personalisation/Block/Event/Analytics/Search.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: harkirat
|
5 |
+
* Date: 1/7/17
|
6 |
+
* Time: 3:37 PM
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @category ChoiceAI
|
11 |
+
* @package ChoiceAI_Personalisation
|
12 |
+
* @copyright Copyright (c) MineWhat
|
13 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
14 |
+
*/
|
15 |
+
class ChoiceAI_Personalisation_Block_Event_Analytics_Search extends Mage_Core_Block_Template {
|
16 |
+
|
17 |
+
protected function _construct() {
|
18 |
+
parent::_construct();
|
19 |
+
$this->setTemplate('choiceai/personalisation/analytics/search.phtml');
|
20 |
+
}
|
21 |
+
|
22 |
+
public function engineStatus(){
|
23 |
+
return Mage::helper('choiceai_search')->isActiveEngine();
|
24 |
+
}
|
25 |
+
|
26 |
+
}
|
app/code/community/ChoiceAI/Personalisation/Block/Searchpage/Addparam.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @category ChoiceAI
|
5 |
+
* @package ChoiceAI_Personalisation
|
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_Personalisation_Block_Searchpage_Addparam extends Mage_Core_Block_Template {
|
10 |
+
|
11 |
+
protected function _construct() {
|
12 |
+
parent::_construct();
|
13 |
+
$this->setTemplate('choiceai/personalisation/base/addparam.phtml');
|
14 |
+
}
|
15 |
+
|
16 |
+
public function engineStatus(){
|
17 |
+
return Mage::helper('choiceai_search')->isActiveEngine();
|
18 |
+
}
|
19 |
+
|
20 |
+
}
|
app/code/community/ChoiceAI/Personalisation/Model/Observer.php
CHANGED
@@ -67,9 +67,7 @@ class ChoiceAI_Personalisation_Model_Observer {
|
|
67 |
->saveRelations();
|
68 |
|
69 |
} catch (Exception $e) {
|
70 |
-
|
71 |
$error_message = $e->getMessage();
|
72 |
-
|
73 |
}
|
74 |
|
75 |
file_get_contents("https://app.choice.ai/stats/magentoinstall?enabled=".$enabled."&api_key=".$api_key."&store_url=".$store_url."&magentoversion=".$magento_version."&error=".$error_message);
|
67 |
->saveRelations();
|
68 |
|
69 |
} catch (Exception $e) {
|
|
|
70 |
$error_message = $e->getMessage();
|
|
|
71 |
}
|
72 |
|
73 |
file_get_contents("https://app.choice.ai/stats/magentoinstall?enabled=".$enabled."&api_key=".$api_key."&store_url=".$store_url."&magentoversion=".$magento_version."&error=".$error_message);
|
app/code/community/ChoiceAI/Personalisation/controllers/ApiController.php
CHANGED
@@ -58,12 +58,10 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
58 |
}
|
59 |
|
60 |
public function configAction() {
|
61 |
-
|
62 |
try {
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
}
|
67 |
|
68 |
$responseObj = array();
|
69 |
|
@@ -103,14 +101,11 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
103 |
->setHeader('Content-type', 'application/json', true);
|
104 |
}
|
105 |
|
106 |
-
return this;
|
107 |
-
|
108 |
}
|
109 |
|
110 |
public function ordersAction() {
|
111 |
-
|
112 |
try {
|
113 |
-
|
114 |
if(!$this->_authorise()) {
|
115 |
return $this;
|
116 |
}
|
@@ -196,9 +191,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
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 |
-
|
200 |
}
|
201 |
-
|
202 |
} catch(Exception $e) {
|
203 |
$this->getResponse()
|
204 |
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
@@ -206,14 +199,11 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
206 |
->setHeader('Content-type', 'application/json', true);
|
207 |
}
|
208 |
|
209 |
-
return this;
|
210 |
-
|
211 |
}
|
212 |
|
213 |
public function productattributesAction() {
|
214 |
-
|
215 |
try {
|
216 |
-
|
217 |
if(!$this->_authorise()) {
|
218 |
return $this;
|
219 |
}
|
@@ -221,9 +211,8 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
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];
|
@@ -289,31 +278,24 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
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 {
|
316 |
-
|
317 |
if(!$this->_authorise()) {
|
318 |
return $this;
|
319 |
}
|
@@ -352,6 +334,8 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
352 |
$product = $this->getFormattedProduct($product, $extras, $debug);
|
353 |
if($product !== null) {
|
354 |
$products[] = $product;
|
|
|
|
|
355 |
}
|
356 |
|
357 |
} else {
|
@@ -360,8 +344,11 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
360 |
$offset = $this->getRequest()->getParam('offset', 1);
|
361 |
|
362 |
$productsCollection = Mage::getModel('catalog/product')->getCollection();
|
|
|
|
|
363 |
$productsCollection
|
364 |
->addAttributeToSelect($attributes)
|
|
|
365 |
->getSelect()->limit($limit, $offset) //we can specify how many products we want to show on this page
|
366 |
;
|
367 |
|
@@ -369,6 +356,8 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
369 |
$product = $this->getFormattedProduct($product, $extras, $debug);
|
370 |
if($product !== null) {
|
371 |
$products[] = $product;
|
|
|
|
|
372 |
}
|
373 |
}
|
374 |
|
@@ -390,14 +379,11 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
390 |
}
|
391 |
|
392 |
return $this;
|
393 |
-
|
394 |
}
|
395 |
|
396 |
|
397 |
public function categoriesAction() {
|
398 |
-
|
399 |
try {
|
400 |
-
|
401 |
if(!$this->_authorise()) {
|
402 |
return $this;
|
403 |
}
|
@@ -408,6 +394,8 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
408 |
'image',
|
409 |
'url',
|
410 |
'level',
|
|
|
|
|
411 |
'is_active',
|
412 |
'created_at',
|
413 |
'updated_at'
|
@@ -418,6 +406,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
418 |
|
419 |
$level = $this->getRequest()->getParam('level');
|
420 |
$active = $this->getRequest()->getParam('active', 'false') === 'true';
|
|
|
421 |
|
422 |
if($level && strlen($level)) {
|
423 |
$level = intval($level);
|
@@ -432,8 +421,10 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
432 |
$category = Mage::getModel('catalog/category')->load($categoryId);
|
433 |
|
434 |
$category = $this->getFormattedCategory($category);
|
435 |
-
if($category !== null) {
|
436 |
$categories[] = $category;
|
|
|
|
|
437 |
}
|
438 |
|
439 |
} else {
|
@@ -455,6 +446,12 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
455 |
;
|
456 |
}
|
457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
$categoriesCollection
|
459 |
->addAttributeToSelect($attributes)
|
460 |
->getSelect()->limit($limit, $offset) //we can specify how many categories we want to show on this page
|
@@ -462,7 +459,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
462 |
|
463 |
foreach($categoriesCollection as $category) {
|
464 |
$category = $this->getFormattedCategory($category);
|
465 |
-
if($category !== null) {
|
466 |
$categories[] = $category;
|
467 |
}
|
468 |
}
|
@@ -474,7 +471,109 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
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)))
|
@@ -483,9 +582,183 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
483 |
}
|
484 |
|
485 |
return $this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
|
|
|
487 |
}
|
488 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
public function usersAction() {
|
490 |
|
491 |
try {
|
@@ -664,11 +937,19 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
664 |
if($debug) {
|
665 |
$attributes = $product->getAttributes();
|
666 |
foreach($attributes as $key => $value) {
|
667 |
-
|
|
|
|
|
|
|
|
|
668 |
}
|
669 |
} else {
|
670 |
foreach($extras as $key) {
|
671 |
-
|
|
|
|
|
|
|
|
|
672 |
}
|
673 |
}
|
674 |
|
@@ -686,10 +967,10 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
686 |
$formattedProduct['cat'][$formattedCategory['id']] = $formattedCategory;
|
687 |
}
|
688 |
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
}
|
694 |
|
695 |
private function getFormattedCategory($category) {
|
@@ -697,31 +978,30 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
697 |
$formattedCategory = null;
|
698 |
|
699 |
try {
|
700 |
-
|
701 |
$formattedCategory = array(
|
702 |
'id' => $category->getId(),
|
703 |
'name' => $category->getName(),
|
704 |
'image' => $category->getImageUrl(),
|
705 |
'url' => $category->getUrl(),
|
706 |
'level' => $category->getLevel(),
|
|
|
|
|
707 |
'is_active' => $category->getIsActive(),
|
708 |
-
'created_at'
|
709 |
-
'updated_at'
|
710 |
);
|
711 |
|
712 |
} catch(Exception $e) {}
|
713 |
|
714 |
return $formattedCategory;
|
715 |
-
|
716 |
}
|
717 |
|
718 |
public function sortbyAction() {
|
719 |
|
720 |
try {
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
}
|
725 |
|
726 |
$sortByOptions = array();
|
727 |
// $attributesData = Mage::getResourceModel('catalog/config')->getAttributesUsedForSortBy();
|
@@ -767,4 +1047,184 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
767 |
return $this;
|
768 |
}
|
769 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
770 |
}
|
58 |
}
|
59 |
|
60 |
public function configAction() {
|
|
|
61 |
try {
|
62 |
+
if(!$this->_authorise()) {
|
63 |
+
return $this;
|
64 |
+
}
|
|
|
65 |
|
66 |
$responseObj = array();
|
67 |
|
101 |
->setHeader('Content-type', 'application/json', true);
|
102 |
}
|
103 |
|
104 |
+
return $this;
|
|
|
105 |
}
|
106 |
|
107 |
public function ordersAction() {
|
|
|
108 |
try {
|
|
|
109 |
if(!$this->_authorise()) {
|
110 |
return $this;
|
111 |
}
|
191 |
->setBody(json_encode(array('orders' => $orders, 'fromDate' => $fromDate, 'toDate' => $toDate, 'version' => self::API_VERSION)))
|
192 |
->setHttpResponseCode(200)
|
193 |
->setHeader('Content-type', 'application/json', true);
|
|
|
194 |
}
|
|
|
195 |
} catch(Exception $e) {
|
196 |
$this->getResponse()
|
197 |
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
199 |
->setHeader('Content-type', 'application/json', true);
|
200 |
}
|
201 |
|
202 |
+
return $this;
|
|
|
203 |
}
|
204 |
|
205 |
public function productattributesAction() {
|
|
|
206 |
try {
|
|
|
207 |
if(!$this->_authorise()) {
|
208 |
return $this;
|
209 |
}
|
211 |
$sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
|
212 |
|
213 |
if(!isset($sections[3])) {
|
214 |
+
// product id
|
215 |
throw new Exception();
|
|
|
216 |
}
|
217 |
|
218 |
$productId = $sections[3];
|
278 |
}
|
279 |
|
280 |
$variants[] = $variant;
|
|
|
281 |
}
|
|
|
282 |
}
|
283 |
|
284 |
$this->getResponse()
|
285 |
->setBody(json_encode(array('product' => $product_info, 'variants' => $variants, 'options' => $options, 'version' => self::API_VERSION)))
|
286 |
->setHttpResponseCode(200)
|
287 |
->setHeader('Content-type', 'application/json', true);
|
|
|
288 |
} catch(Exception $e) {
|
289 |
$this->getResponse()
|
290 |
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
291 |
->setHttpResponseCode(500)
|
292 |
->setHeader('Content-type', 'application/json', true);
|
293 |
}
|
|
|
294 |
return $this;
|
|
|
295 |
}
|
296 |
|
297 |
public function productsAction() {
|
|
|
298 |
try {
|
|
|
299 |
if(!$this->_authorise()) {
|
300 |
return $this;
|
301 |
}
|
334 |
$product = $this->getFormattedProduct($product, $extras, $debug);
|
335 |
if($product !== null) {
|
336 |
$products[] = $product;
|
337 |
+
}else{
|
338 |
+
throw new Exception("Failed to fetch the product");
|
339 |
}
|
340 |
|
341 |
} else {
|
344 |
$offset = $this->getRequest()->getParam('offset', 1);
|
345 |
|
346 |
$productsCollection = Mage::getModel('catalog/product')->getCollection();
|
347 |
+
|
348 |
+
// Get only enabled products
|
349 |
$productsCollection
|
350 |
->addAttributeToSelect($attributes)
|
351 |
+
->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))
|
352 |
->getSelect()->limit($limit, $offset) //we can specify how many products we want to show on this page
|
353 |
;
|
354 |
|
356 |
$product = $this->getFormattedProduct($product, $extras, $debug);
|
357 |
if($product !== null) {
|
358 |
$products[] = $product;
|
359 |
+
}else{
|
360 |
+
throw new Exception("Failed to fetch the product");
|
361 |
}
|
362 |
}
|
363 |
|
379 |
}
|
380 |
|
381 |
return $this;
|
|
|
382 |
}
|
383 |
|
384 |
|
385 |
public function categoriesAction() {
|
|
|
386 |
try {
|
|
|
387 |
if(!$this->_authorise()) {
|
388 |
return $this;
|
389 |
}
|
394 |
'image',
|
395 |
'url',
|
396 |
'level',
|
397 |
+
'path',
|
398 |
+
'is_anchor',
|
399 |
'is_active',
|
400 |
'created_at',
|
401 |
'updated_at'
|
406 |
|
407 |
$level = $this->getRequest()->getParam('level');
|
408 |
$active = $this->getRequest()->getParam('active', 'false') === 'true';
|
409 |
+
$isAnchor = $this->getRequest()->getParam('is_anchor', 'false') === 'true';
|
410 |
|
411 |
if($level && strlen($level)) {
|
412 |
$level = intval($level);
|
421 |
$category = Mage::getModel('catalog/category')->load($categoryId);
|
422 |
|
423 |
$category = $this->getFormattedCategory($category);
|
424 |
+
if($category !== null && $category->id != null && is_array($category)) {
|
425 |
$categories[] = $category;
|
426 |
+
} else{
|
427 |
+
throw new Exception("Category ".$categoryId." not found");
|
428 |
}
|
429 |
|
430 |
} else {
|
446 |
;
|
447 |
}
|
448 |
|
449 |
+
if($isAnchor != null) {
|
450 |
+
$categoriesCollection
|
451 |
+
->addAttributeToFilter('is_anchor', 1) // If you want categories which are shown in search facets
|
452 |
+
;
|
453 |
+
}
|
454 |
+
|
455 |
$categoriesCollection
|
456 |
->addAttributeToSelect($attributes)
|
457 |
->getSelect()->limit($limit, $offset) //we can specify how many categories we want to show on this page
|
459 |
|
460 |
foreach($categoriesCollection as $category) {
|
461 |
$category = $this->getFormattedCategory($category);
|
462 |
+
if($category !== null && is_array($category)) {
|
463 |
$categories[] = $category;
|
464 |
}
|
465 |
}
|
471 |
->setHttpResponseCode(200)
|
472 |
->setHeader('Content-type', 'application/json', true);
|
473 |
|
474 |
+
} catch(\Exception $e) {
|
475 |
+
if($e->getMessage() != null)
|
476 |
+
$message = $e->getMessage();
|
477 |
+
else
|
478 |
+
$message = 'Internal server error';
|
479 |
+
|
480 |
+
$this->getResponse()
|
481 |
+
->setBody(json_encode(array('status' => 'error', 'message' => $message, 'version' => self::API_VERSION)))
|
482 |
+
->setHttpResponseCode(500)
|
483 |
+
->setHeader('Content-type', 'application/json', true);
|
484 |
+
}
|
485 |
+
|
486 |
+
return $this;
|
487 |
+
}
|
488 |
+
|
489 |
+
|
490 |
+
public function facetattributesAction() {
|
491 |
+
try {
|
492 |
+
if(!$this->_authorise()) {
|
493 |
+
return $this;
|
494 |
+
}
|
495 |
+
|
496 |
+
$limit = $this->getRequest()->getParam('limit', 100);
|
497 |
+
$page = $this->getRequest()->getParam('page', 1);
|
498 |
+
$fields = $this->getRequest()->getParam('fields', false);
|
499 |
+
$isFilterable = $this->getRequest()->getParam('is_filterable', false);
|
500 |
+
|
501 |
+
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
|
502 |
+
|
503 |
+
if($isFilterable && is_numeric($isFilterable)){
|
504 |
+
$collection->addFieldToFilter('is_filterable', (int) $isFilterable);
|
505 |
+
} else{
|
506 |
+
// Give only is filterable with results
|
507 |
+
$collection->addFieldToFilter('is_filterable', 1);
|
508 |
+
}
|
509 |
|
510 |
+
// $fieldsToSelect = array(
|
511 |
+
// "attribute_id",
|
512 |
+
// "is_filterable",
|
513 |
+
// "attribute_code",
|
514 |
+
// "frontend_label",
|
515 |
+
// "is_visible",
|
516 |
+
// "is_visible_on_front",
|
517 |
+
// "is_user_defined",
|
518 |
+
// "is_required",
|
519 |
+
// "is_searchable",
|
520 |
+
// "is_filterable_in_search",
|
521 |
+
// "position",
|
522 |
+
// "is_used_for_promo_rules",
|
523 |
+
// "is_used_for_price_rules",
|
524 |
+
// "used_in_product_listing"
|
525 |
+
// );
|
526 |
+
// //@TODO: Mysql error coming up
|
527 |
+
// $collection->addFieldToSelect($fieldsToSelect);
|
528 |
+
|
529 |
+
$collection->setOrder('position', 'ASC');
|
530 |
+
$collection->setPageSize((int) $limit);
|
531 |
+
$collection->setCurPage((int) $page);
|
532 |
+
$collection->load();
|
533 |
+
|
534 |
+
if($limit * ($page-1) < $collection->getSize()) {
|
535 |
+
$allAttrs = array();
|
536 |
+
|
537 |
+
foreach ($collection as $attr) {
|
538 |
+
$newAttr = array();
|
539 |
+
if($fields=="all") {
|
540 |
+
$newAttr['attribute_id'] = $attr->getAttributeId();
|
541 |
+
$newAttr['is_filterable'] = $attr->getIsFilterable();
|
542 |
+
$newAttr['attribute_code'] = $attr->getAttributeCode();
|
543 |
+
$newAttr['frontend_label'] = $attr->getFrontendLabel();
|
544 |
+
$newAttr['is_visible'] = $attr->getIsVisible();
|
545 |
+
$newAttr['is_visible_on_front'] = $attr->getIsVisibleOnFront();
|
546 |
+
$newAttr['is_user_defined'] = $attr->getIsUserDefined();
|
547 |
+
$newAttr['is_required'] = $attr->getIsRequired();
|
548 |
+
$newAttr['is_searchable'] = $attr->getIsSearchable();
|
549 |
+
$newAttr['is_filterable_in_search'] = $attr->getIsFilterableInSearch();
|
550 |
+
$newAttr['position'] = $attr->getPosition();
|
551 |
+
$newAttr['is_used_for_promo_rules'] = $attr->getIsUsedForPromoRules();
|
552 |
+
$newAttr['is_used_for_price_rules'] = $attr->getIsUsedForPriceRules();
|
553 |
+
$newAttr['used_in_product_listing'] = $attr->getUsedInProductListing();
|
554 |
+
} else{
|
555 |
+
$newAttr['attribute_id'] = $attr->getAttributeId();
|
556 |
+
$newAttr['is_filterable'] = $attr->getIsFilterable();
|
557 |
+
$newAttr['attribute_code'] = $attr->getAttributeCode();
|
558 |
+
$newAttr['frontend_label'] = $attr->getFrontendLabel();
|
559 |
+
$newAttr['is_visible'] = $attr->getIsVisible();
|
560 |
+
$newAttr['is_visible_on_front'] = $attr->getIsVisibleOnFront();
|
561 |
+
$newAttr['is_searchable'] = $attr->getIsSearchable();
|
562 |
+
$newAttr['is_filterable_in_search'] = $attr->getIsFilterableInSearch();
|
563 |
+
$newAttr['position'] = $attr->getPosition();
|
564 |
+
$newAttr['used_in_product_listing'] = $attr->getUsedInProductListing();
|
565 |
+
}
|
566 |
+
|
567 |
+
$allAttrs[] = $newAttr;
|
568 |
+
}
|
569 |
+
} else{
|
570 |
+
$allAttrs = array();
|
571 |
+
}
|
572 |
+
|
573 |
+
$this->getResponse()
|
574 |
+
->setBody(json_encode(array('attributes' => $allAttrs, 'version' => self::API_VERSION)))
|
575 |
+
->setHttpResponseCode(200)
|
576 |
+
->setHeader('Content-type', 'application/json', true);
|
577 |
} catch(Exception $e) {
|
578 |
$this->getResponse()
|
579 |
->setBody(json_encode(array('status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
582 |
}
|
583 |
|
584 |
return $this;
|
585 |
+
}
|
586 |
+
|
587 |
+
|
588 |
+
public function modifyfacetattributeAction() {
|
589 |
+
try {
|
590 |
+
if(!$this->_authorise()) {
|
591 |
+
return $this;
|
592 |
+
}
|
593 |
+
|
594 |
+
$facetData = $this->getRequest()->getParam('newData', false);
|
595 |
+
$newFacetData = json_decode($facetData);
|
596 |
+
|
597 |
+
if(!$newFacetData){
|
598 |
+
if ($facetData == "") {
|
599 |
+
$input = file_get_contents('php://input');
|
600 |
+
$input = utf8_encode($input);
|
601 |
+
$newFacetData = json_decode($input)->newData;
|
602 |
+
}
|
603 |
+
}
|
604 |
+
|
605 |
+
if(!$newFacetData && !$newFacetData->attribute_id)
|
606 |
+
throw new Exception("Insufficient data");
|
607 |
+
|
608 |
+
// updates the facet
|
609 |
+
$resourceModel = Mage::getResourceModel('catalog/product_attribute_collection');
|
610 |
+
$attributeObj = $resourceModel->getItemById($newFacetData->attribute_id);
|
611 |
+
|
612 |
+
// Not required anymore
|
613 |
+
unset($newFacetData->attribute_id);
|
614 |
+
|
615 |
+
foreach ($newFacetData as $key => $value) {
|
616 |
+
$attributeObj->setData($key, $value);
|
617 |
+
}
|
618 |
+
$updateStatus = $attributeObj->save();
|
619 |
+
|
620 |
+
if(!$updateStatus)
|
621 |
+
throw new Exception("Couldn't update");
|
622 |
+
|
623 |
+
$this->getResponse()
|
624 |
+
->setBody(json_encode(array("status"=>"ok", 'version' => self::API_VERSION)))
|
625 |
+
->setHttpResponseCode(200)
|
626 |
+
->setHeader('Content-type', 'application/json', true);
|
627 |
+
} catch(Exception $e) {
|
628 |
+
if($e->getMessage())
|
629 |
+
$errorMsg = $e->getMessage();
|
630 |
+
else
|
631 |
+
$errorMsg = "Internal server error";
|
632 |
+
|
633 |
+
$this->getResponse()
|
634 |
+
->setBody(json_encode(array('status' => 'error', 'message' => $errorMsg, 'version' => self::API_VERSION)))
|
635 |
+
->setHttpResponseCode(500)
|
636 |
+
->setHeader('Content-type', 'application/json', true);
|
637 |
+
}
|
638 |
|
639 |
+
return $this;
|
640 |
}
|
641 |
|
642 |
+
// Formats the attribute for save
|
643 |
+
private function _prepareAttributeForSave($data) {
|
644 |
+
/** @var $helperCatalog Mage_Catalog_Helper_Data */
|
645 |
+
$helperCatalog = Mage::helper('catalog');
|
646 |
+
|
647 |
+
if ($data['scope'] == 'global') {
|
648 |
+
$data['is_global'] = Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL;
|
649 |
+
} else if ($data['scope'] == 'website') {
|
650 |
+
$data['is_global'] = Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE;
|
651 |
+
} else {
|
652 |
+
$data['is_global'] = Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE;
|
653 |
+
}
|
654 |
+
|
655 |
+
if (!isset($data['is_configurable'])) {
|
656 |
+
$data['is_configurable'] = 0;
|
657 |
+
}
|
658 |
+
if (!isset($data['is_filterable'])) {
|
659 |
+
$data['is_filterable'] = 1;
|
660 |
+
}
|
661 |
+
if (!isset($data['is_filterable_in_search'])) {
|
662 |
+
$data['is_filterable_in_search'] = 1;
|
663 |
+
}
|
664 |
+
if (!isset($data['apply_to'])) {
|
665 |
+
$data['apply_to'] = array();
|
666 |
+
}
|
667 |
+
// set frontend labels array with store_id as keys
|
668 |
+
if (isset($data['frontend_label']) && is_array($data['frontend_label'])) {
|
669 |
+
$labels = array();
|
670 |
+
foreach ($data['frontend_label'] as $label) {
|
671 |
+
$storeId = $label['store_id'];
|
672 |
+
$labelText = $helperCatalog->stripTags($label['label']);
|
673 |
+
$labels[$storeId] = $labelText;
|
674 |
+
}
|
675 |
+
$data['frontend_label'] = $labels;
|
676 |
+
}
|
677 |
+
// set additional fields
|
678 |
+
if (isset($data['additional_fields']) && is_array($data['additional_fields'])) {
|
679 |
+
$data = array_merge($data, $data['additional_fields']);
|
680 |
+
unset($data['additional_fields']);
|
681 |
+
}
|
682 |
+
//default value
|
683 |
+
if (!empty($data['default_value'])) {
|
684 |
+
$data['default_value'] = $helperCatalog->stripTags($data['default_value']);
|
685 |
+
}
|
686 |
+
|
687 |
+
return $data;
|
688 |
+
}
|
689 |
+
|
690 |
+
|
691 |
+
public function addfacetattributeAction() {
|
692 |
+
try {
|
693 |
+
if(!$this->_authorise()) {
|
694 |
+
return $this;
|
695 |
+
}
|
696 |
+
|
697 |
+
$facetData = $this->getRequest()->getParam('newData', false);
|
698 |
+
$newFacetData = json_decode($facetData);
|
699 |
+
|
700 |
+
if(!$newFacetData){
|
701 |
+
if ($facetData == "") {
|
702 |
+
$input = file_get_contents('php://input');
|
703 |
+
$input = utf8_encode($input);
|
704 |
+
$newFacetData = json_decode($input)->newData;
|
705 |
+
}
|
706 |
+
}
|
707 |
+
$newFacetData = (array)$newFacetData;
|
708 |
+
|
709 |
+
if (!$newFacetData || empty($newFacetData['attribute_code']) || !isset($newFacetData['frontend_label'])) {
|
710 |
+
throw new Exception("Insufficient data");
|
711 |
+
}
|
712 |
+
|
713 |
+
//validate attribute_code
|
714 |
+
if (!preg_match('/^[a-z][a-z_0-9]{0,254}$/', $newFacetData['attribute_code'])) {
|
715 |
+
throw new Exception("Invalid attribute_code");
|
716 |
+
}
|
717 |
+
|
718 |
+
/** @var $model Mage_Catalog_Model_Resource_Eav_Attribute */
|
719 |
+
$model = Mage::getModel('catalog/resource_eav_attribute');
|
720 |
+
/** @var $helper Mage_Catalog_Helper_Product */
|
721 |
+
$helper = Mage::helper('catalog/product');
|
722 |
+
|
723 |
+
|
724 |
+
$newFacetData['source_model'] = $helper->getAttributeSourceModelByInputType('multiselect');
|
725 |
+
$newFacetData['backend_model'] = $helper->getAttributeBackendModelByInputType('multiselect');
|
726 |
+
if (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0) {
|
727 |
+
$newFacetData['backend_type'] = $model->getBackendTypeByInput('multiselect');
|
728 |
+
}
|
729 |
+
|
730 |
+
$newFacetData = $this->_prepareAttributeForSave($newFacetData);
|
731 |
+
|
732 |
+
$entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
|
733 |
+
|
734 |
+
$model->addData($newFacetData);
|
735 |
+
$model->setEntityTypeId($entityTypeId);
|
736 |
+
$model->setIsUserDefined(1);
|
737 |
+
|
738 |
+
$model->save();
|
739 |
+
|
740 |
+
Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG));
|
741 |
+
|
742 |
+
$this->getResponse()
|
743 |
+
->setBody(json_encode(array("status"=>"ok", 'version' => self::API_VERSION)))
|
744 |
+
->setHttpResponseCode(200)
|
745 |
+
->setHeader('Content-type', 'application/json', true);
|
746 |
+
} catch(Exception $e) {
|
747 |
+
if($e->getMessage())
|
748 |
+
$errorMsg = $e->getMessage();
|
749 |
+
else
|
750 |
+
$errorMsg = "Internal server error";
|
751 |
+
|
752 |
+
$this->getResponse()
|
753 |
+
->setBody(json_encode(array('status' => 'error', 'message' => $errorMsg, 'version' => self::API_VERSION)))
|
754 |
+
->setHttpResponseCode(500)
|
755 |
+
->setHeader('Content-type', 'application/json', true);
|
756 |
+
}
|
757 |
+
|
758 |
+
return $this;
|
759 |
+
}
|
760 |
+
|
761 |
+
|
762 |
public function usersAction() {
|
763 |
|
764 |
try {
|
937 |
if($debug) {
|
938 |
$attributes = $product->getAttributes();
|
939 |
foreach($attributes as $key => $value) {
|
940 |
+
// Sanity check, or else crashes without proper error handling
|
941 |
+
$existenceCheck = $product->getResource()->getAttribute($key);
|
942 |
+
|
943 |
+
if($existenceCheck)
|
944 |
+
$formattedProduct['extras'][$key] = $product->getAttributeText($key);
|
945 |
}
|
946 |
} else {
|
947 |
foreach($extras as $key) {
|
948 |
+
// Sanity check, or else crashes without proper error handling
|
949 |
+
$existenceCheck = $product->getResource()->getAttribute($key);
|
950 |
+
|
951 |
+
if($existenceCheck)
|
952 |
+
$formattedProduct['extras'][$key] = $product->getAttributeText($key);
|
953 |
}
|
954 |
}
|
955 |
|
967 |
$formattedProduct['cat'][$formattedCategory['id']] = $formattedCategory;
|
968 |
}
|
969 |
|
970 |
+
return $formattedProduct;
|
971 |
+
} catch(Exception $e) {
|
972 |
+
return NULL;
|
973 |
+
}
|
974 |
}
|
975 |
|
976 |
private function getFormattedCategory($category) {
|
978 |
$formattedCategory = null;
|
979 |
|
980 |
try {
|
|
|
981 |
$formattedCategory = array(
|
982 |
'id' => $category->getId(),
|
983 |
'name' => $category->getName(),
|
984 |
'image' => $category->getImageUrl(),
|
985 |
'url' => $category->getUrl(),
|
986 |
'level' => $category->getLevel(),
|
987 |
+
'path' => $category->getPath(),
|
988 |
+
'is_anchor' => $category->getIsAnchor(),
|
989 |
'is_active' => $category->getIsActive(),
|
990 |
+
'created_at' => $category->getCreatedAt(),
|
991 |
+
'updated_at' => $category->getUpdatedAt()
|
992 |
);
|
993 |
|
994 |
} catch(Exception $e) {}
|
995 |
|
996 |
return $formattedCategory;
|
|
|
997 |
}
|
998 |
|
999 |
public function sortbyAction() {
|
1000 |
|
1001 |
try {
|
1002 |
+
if(!$this->_authorise()) {
|
1003 |
+
return $this;
|
1004 |
+
}
|
|
|
1005 |
|
1006 |
$sortByOptions = array();
|
1007 |
// $attributesData = Mage::getResourceModel('catalog/config')->getAttributesUsedForSortBy();
|
1047 |
return $this;
|
1048 |
}
|
1049 |
|
1050 |
+
public function choicepageAction() {
|
1051 |
+
try{
|
1052 |
+
if(!$this->_authorise()) {
|
1053 |
+
return $this;
|
1054 |
+
}
|
1055 |
+
|
1056 |
+
$responseObj = array();
|
1057 |
+
|
1058 |
+
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
1059 |
+
// Create Choice page
|
1060 |
+
// Expects title, url_path and content
|
1061 |
+
|
1062 |
+
$pageData = $this->getRequest()->getParam('data');
|
1063 |
+
if ($pageData == "") {
|
1064 |
+
$input = file_get_contents('php://input');
|
1065 |
+
$input = utf8_encode($input);
|
1066 |
+
$pageData = json_encode(json_decode($input)->data);
|
1067 |
+
}
|
1068 |
+
$pageData = json_decode($pageData);
|
1069 |
+
$urlPath = $pageData->url_path;
|
1070 |
+
|
1071 |
+
if(!$urlPath){
|
1072 |
+
// What can this poor guy do without the path?
|
1073 |
+
throw new Exception("No urlPath");
|
1074 |
+
}
|
1075 |
+
|
1076 |
+
// Ensure no other existing page contains the same URL path or say "identifier"
|
1077 |
+
$collection = Mage::getModel('cms/page')
|
1078 |
+
->getCollection()
|
1079 |
+
->addFieldToFilter('identifier', $urlPath);
|
1080 |
+
// Not useful anymore
|
1081 |
+
// $existingPages = Mage::getModel('cms/page')->load($collection->getFirstItem()->getId());
|
1082 |
+
|
1083 |
+
// There can be multiple pages with same url path, but different store scope. Let's disable all
|
1084 |
+
foreach ($collection as $existingPage){
|
1085 |
+
// Page already exists && is_active
|
1086 |
+
if($existingPage->getId()) {
|
1087 |
+
// Delete all other pages having same URL
|
1088 |
+
// and then continue adding our new page
|
1089 |
+
// $this->updateChoiceUrl(false, $existingPage->getId(), array("is_active" => 0, "identifier" => $urlPath));
|
1090 |
+
$existingPage->delete();
|
1091 |
+
}
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
// Setting default content if not provided
|
1095 |
+
$pageContent = (!isset($pageData->content)) ? "<script>window._caichoicePage = true;</script><div id='caichoicePage'></div>" : $pageData->content;
|
1096 |
+
|
1097 |
+
// Setting default Title if not available
|
1098 |
+
$pageTitle = (!isset($pageData->title)) ? "Choice.AI" : $pageData->title;
|
1099 |
+
|
1100 |
+
|
1101 |
+
$choicePageData = array(
|
1102 |
+
'title' => $pageTitle,
|
1103 |
+
'root_template' => 'one_column',
|
1104 |
+
//'meta_keywords' => 'meta,keywords',
|
1105 |
+
//'meta_description' => 'meta description',
|
1106 |
+
'identifier' => $urlPath,
|
1107 |
+
//'content_heading' => 'content heading',
|
1108 |
+
'stores' => array(0),//available for all store views
|
1109 |
+
'content' => $pageContent
|
1110 |
+
);
|
1111 |
+
|
1112 |
+
// Create new page
|
1113 |
+
$choicePage = Mage::getModel('cms/page')->setData($choicePageData)->save();
|
1114 |
+
|
1115 |
+
$responseObj["status"] = "ok";
|
1116 |
+
$responseObj["id"] = $choicePage->getId();
|
1117 |
+
} else if ($_SERVER["REQUEST_METHOD"] == "PUT") {
|
1118 |
+
// Update Choice page's URL path
|
1119 |
+
$newPageData = $this->getRequest()->getParam('data');
|
1120 |
+
|
1121 |
+
if ($newPageData == "") {
|
1122 |
+
$input = file_get_contents('php://input');
|
1123 |
+
$input = utf8_encode($input);
|
1124 |
+
$newPageData = json_encode(json_decode($input)->data);
|
1125 |
+
}
|
1126 |
+
$newPageData = json_decode($newPageData);
|
1127 |
+
|
1128 |
+
if ($newPageData == NULL || !isset($newPageData->page_id)) {
|
1129 |
+
throw new Exception();
|
1130 |
+
}
|
1131 |
+
|
1132 |
+
$pageId = $newPageData->page_id;
|
1133 |
+
|
1134 |
+
$this->updateChoiceUrl($newPageData, $pageId);
|
1135 |
+
$responseObj["status"] = "ok";
|
1136 |
+
} else if ($_SERVER["REQUEST_METHOD"] == "DELETE") {
|
1137 |
+
$newPageData = $this->getRequest()->getParam('data');
|
1138 |
+
|
1139 |
+
if ($newPageData == "") {
|
1140 |
+
$input = file_get_contents('php://input');
|
1141 |
+
$input = utf8_encode($input);
|
1142 |
+
$newPageData = json_encode(json_decode($input)->data);
|
1143 |
+
}
|
1144 |
+
$newPageData = json_decode($newPageData);
|
1145 |
+
|
1146 |
+
if ($newPageData == NULL || !isset($newPageData->page_id)) {
|
1147 |
+
throw new Exception();
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
$pageId = $newPageData->page_id;
|
1151 |
+
|
1152 |
+
$pagesCollection = Mage::getModel('cms/page')
|
1153 |
+
->getCollection()
|
1154 |
+
->addFieldToFilter('page_id', array("eq"=> $pageId));
|
1155 |
+
$pageData = Mage::getModel('cms/page')->load($pagesCollection->getFirstItem()->getId());
|
1156 |
+
$pageData->delete();
|
1157 |
+
// Mage::app()->getStore()->resetConfig();
|
1158 |
+
$responseObj["status"] = "ok";
|
1159 |
+
} else {
|
1160 |
+
// Invalid, return error
|
1161 |
+
$responseObj['status'] = 'error';
|
1162 |
+
$responseObj['message'] = 'Invalid request';
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
$responseObj['version'] = self::API_VERSION;
|
1166 |
+
$this->getResponse()
|
1167 |
+
->setBody(json_encode($responseObj))
|
1168 |
+
->setHttpResponseCode(200)
|
1169 |
+
->setHeader('Content-type', 'application/json', true);
|
1170 |
+
} catch(Exception $e) {
|
1171 |
+
$this->getResponse()
|
1172 |
+
->setBody(json_encode(array('emsg'=> $e->getMessage(), 'status' => 'error', 'message' => 'Internal server error', 'version' => self::API_VERSION)))
|
1173 |
+
->setHttpResponseCode(500)
|
1174 |
+
->setHeader('Content-type', 'application/json', true);
|
1175 |
+
}
|
1176 |
+
|
1177 |
+
return this;
|
1178 |
+
}
|
1179 |
+
|
1180 |
+
private function updateChoiceUrl($newPageData, $pageId, $dataToUpdate=false){
|
1181 |
+
// Doesn't allow update without "identifier" field :/
|
1182 |
+
if(!$dataToUpdate) {
|
1183 |
+
// Update case
|
1184 |
+
$dataToUpdate = array();
|
1185 |
+
|
1186 |
+
if (isset($newPageData->url_path)) {
|
1187 |
+
$urlPath = $newPageData->url_path;
|
1188 |
+
|
1189 |
+
// Ensure no other existing page contains the same URL path / "identifier"
|
1190 |
+
$collection = Mage::getModel('cms/page')
|
1191 |
+
->getCollection()
|
1192 |
+
->addFieldToFilter('identifier', $urlPath)
|
1193 |
+
->addFieldToFilter('page_id', array("neq"=> $pageId));
|
1194 |
+
$page = Mage::getModel('cms/page')->load($collection->getFirstItem()->getId());
|
1195 |
+
|
1196 |
+
// URL path already being used?
|
1197 |
+
if ($page->getId())
|
1198 |
+
throw new Exception();
|
1199 |
+
else
|
1200 |
+
$dataToUpdate['identifier'] = $urlPath;
|
1201 |
+
}
|
1202 |
+
|
1203 |
+
if (isset($newPageData->content)) {
|
1204 |
+
$dataToUpdate['content'] = $newPageData->content;
|
1205 |
+
}
|
1206 |
+
|
1207 |
+
if (isset($newPageData->title)) {
|
1208 |
+
$dataToUpdate['title'] = $newPageData->title;
|
1209 |
+
}
|
1210 |
+
}
|
1211 |
+
|
1212 |
+
$dataToUpdate['page_id'] = $pageId;
|
1213 |
+
|
1214 |
+
// Ensuring proper scope per update
|
1215 |
+
$dataToUpdate['stores'] = array(0);
|
1216 |
+
|
1217 |
+
if(!isset($dataToUpdate['identifier'])){
|
1218 |
+
// Get existing "identifier"
|
1219 |
+
$pagesCollection = Mage::getModel('cms/page')
|
1220 |
+
->getCollection()
|
1221 |
+
->addFieldToFilter('page_id', array("eq"=> $pageId));
|
1222 |
+
$pageData = Mage::getModel('cms/page')->load($pagesCollection->getFirstItem()->getId());
|
1223 |
+
|
1224 |
+
$dataToUpdate['identifier'] = $pageData->getIdentifier();
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
return Mage::getModel('cms/page')->setData($dataToUpdate)->save();
|
1228 |
+
}
|
1229 |
+
|
1230 |
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Layer/View.php
CHANGED
@@ -85,35 +85,24 @@ class ChoiceAI_Search_Block_Catalog_Layer_View extends Mage_Catalog_Block_Layer_
|
|
85 |
}
|
86 |
|
87 |
$this->getLayer()->apply();
|
|
|
|
|
88 |
$this->getLayer()->getProductCollection()->load();
|
89 |
} else {
|
90 |
-
|
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 |
-
|
117 |
}
|
118 |
return parent::getLayer();
|
119 |
}
|
85 |
}
|
86 |
|
87 |
$this->getLayer()->apply();
|
88 |
+
|
89 |
+
// Causing a request to the data server, without sort by param
|
90 |
$this->getLayer()->getProductCollection()->load();
|
91 |
} else {
|
92 |
+
parent::_prepareLayout();
|
|
|
93 |
}
|
94 |
|
95 |
return $this;
|
96 |
}
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
/**
|
99 |
* Returns current catalog layer.
|
100 |
*
|
101 |
* @return ChoiceAI_Search_Model_Catalog_Layer|Mage_Catalog_Model_Layer
|
102 |
*/
|
103 |
+
public function getLayer(){
|
|
|
104 |
if (Mage::helper('choiceai_search')->isActiveEngine()) {
|
105 |
+
return Mage::getSingleton('choiceai_search/catalog_layer');
|
106 |
}
|
107 |
return parent::getLayer();
|
108 |
}
|
app/code/local/ChoiceAI/Search/Block/Catalog/Product/List/Toolbar.php
CHANGED
@@ -19,10 +19,10 @@ class ChoiceAI_Search_Block_Catalog_Product_List_Toolbar extends Mage_Catalog_Bl
|
|
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::
|
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();
|
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::helper('choiceai_search')->isActiveEngine()) {
|
23 |
+
if ((!isset($_REQUEST['order']) ||is_null($_REQUEST['order'])) && isset($_SESSION['plist_sort_by'])) {
|
24 |
return $_SESSION['plist_sort_by'];
|
25 |
+
} else if (isset($_SESSION['plist_sort_by']) && isset($_REQUEST['order']) && $_REQUEST['order'] == $_SESSION['plist_sort_by']) {
|
26 |
return $_SESSION['plist_sort_by'];
|
27 |
} else{
|
28 |
return parent::getCurrentOrder();
|
app/code/local/ChoiceAI/Search/Block/Catalogsearch/Layer.php
CHANGED
@@ -43,7 +43,7 @@ class ChoiceAI_Search_Block_Catalogsearch_Layer extends Mage_CatalogSearch_Block
|
|
43 |
{
|
44 |
/** @var $helper ChoiceAI_Search_Helper_Data */
|
45 |
$helper = Mage::helper('choiceai_search');
|
46 |
-
|
47 |
|
48 |
$stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
|
49 |
->setLayer($this->getLayer());
|
@@ -79,7 +79,7 @@ class ChoiceAI_Search_Block_Catalogsearch_Layer extends Mage_CatalogSearch_Block
|
|
79 |
}
|
80 |
|
81 |
$this->getLayer()->apply();
|
82 |
-
|
83 |
}else{
|
84 |
parent::_prepareLayout();
|
85 |
}
|
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());
|
79 |
}
|
80 |
|
81 |
$this->getLayer()->apply();
|
82 |
+
$this->getLayer()->getProductCollection()->load();
|
83 |
}else{
|
84 |
parent::_prepareLayout();
|
85 |
}
|
app/code/local/ChoiceAI/Search/Block/Catalogsearch/Result.php
CHANGED
@@ -15,7 +15,7 @@ class ChoiceAI_Search_Block_Catalogsearch_Result extends Mage_CatalogSearch_Bloc
|
|
15 |
*/
|
16 |
public function setListOrders()
|
17 |
{
|
18 |
-
if(Mage::
|
19 |
$category = Mage::getSingleton('catalog/layer')
|
20 |
->getCurrentCategory();
|
21 |
/* @var $category Mage_Catalog_Model_Category */
|
15 |
*/
|
16 |
public function setListOrders()
|
17 |
{
|
18 |
+
if(Mage::helper('choiceai_search')->isActiveEngine()) {
|
19 |
$category = Mage::getSingleton('catalog/layer')
|
20 |
->getCurrentCategory();
|
21 |
/* @var $category Mage_Catalog_Model_Category */
|
app/code/local/ChoiceAI/Search/Helper/Catalogsearch.php
DELETED
@@ -1,19 +0,0 @@
|
|
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
CHANGED
@@ -11,6 +11,5 @@ class ChoiceAI_Search_Helper_ChoiceAIsearch extends ChoiceAI_Search_Helper_Data
|
|
11 |
public function getEngineConfigData($prefix = '', $website = null)
|
12 |
{
|
13 |
return Mage::helper('choiceai_searchcore')->getEngineConfigData($prefix, $website);
|
14 |
-
|
15 |
}
|
16 |
}
|
11 |
public function getEngineConfigData($prefix = '', $website = null)
|
12 |
{
|
13 |
return Mage::helper('choiceai_searchcore')->getEngineConfigData($prefix, $website);
|
|
|
14 |
}
|
15 |
}
|
app/code/local/ChoiceAI/Search/Helper/Data.php
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
*
|
4 |
* @package ChoiceAI_Search
|
@@ -50,10 +51,10 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
50 |
);
|
51 |
|
52 |
/**
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
public $is_active = NULL;
|
58 |
|
59 |
|
@@ -91,16 +92,6 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
91 |
return $attributeCode;
|
92 |
}
|
93 |
|
94 |
-
/**
|
95 |
-
* Returns cache lifetime in seconds.
|
96 |
-
*
|
97 |
-
* @return int
|
98 |
-
*/
|
99 |
-
public function getCacheLifetime()
|
100 |
-
{
|
101 |
-
return Mage::getStoreConfig('core/cache/lifetime');
|
102 |
-
}
|
103 |
-
|
104 |
/**
|
105 |
* Returns search engine config data.
|
106 |
*
|
@@ -131,7 +122,7 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
131 |
*/
|
132 |
public function getLanguageCodeByLocaleCode($localeCode)
|
133 |
{
|
134 |
-
$localeCode = (string)
|
135 |
if (!$localeCode) {
|
136 |
return false;
|
137 |
}
|
@@ -153,17 +144,6 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
153 |
return $this->_languageCodes[$localeCode];
|
154 |
}
|
155 |
|
156 |
-
/**
|
157 |
-
* Returns store language code.
|
158 |
-
*
|
159 |
-
* @param mixed $store
|
160 |
-
* @return bool
|
161 |
-
*/
|
162 |
-
public function getLanguageCodeByStore($store = null)
|
163 |
-
{
|
164 |
-
return $this->getLanguageCodeByLocaleCode($this->getLocaleCode($store));
|
165 |
-
}
|
166 |
-
|
167 |
/**
|
168 |
* Returns store locale code.
|
169 |
*
|
@@ -175,65 +155,6 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
175 |
return Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store);
|
176 |
}
|
177 |
|
178 |
-
/**
|
179 |
-
* Retrieves all searchable product attributes.
|
180 |
-
* Possibility to filter attributes by backend type.
|
181 |
-
*
|
182 |
-
* @param array $backendType
|
183 |
-
* @return array
|
184 |
-
*/
|
185 |
-
public function getSearchableAttributes($backendType = null)
|
186 |
-
{
|
187 |
-
if (null === $this->_searchableAttributes) {
|
188 |
-
$this->_searchableAttributes = array();
|
189 |
-
$entityType = $this->getEavConfig()->getEntityType('catalog_product');
|
190 |
-
$entity = $entityType->getEntity();
|
191 |
-
|
192 |
-
/* @var $productAttributeCollection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
|
193 |
-
$productAttributeCollection = Mage::getResourceModel('catalog/product_attribute_collection')
|
194 |
-
->setEntityTypeFilter($entityType->getEntityTypeId())
|
195 |
-
->addVisibleFilter()
|
196 |
-
->addToIndexFilter(true);
|
197 |
-
|
198 |
-
$attributes = $productAttributeCollection->getItems();
|
199 |
-
foreach ($attributes as $attribute) {
|
200 |
-
/** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
|
201 |
-
$attribute->setEntity($entity);
|
202 |
-
$this->_searchableAttributes[$attribute->getAttributeCode()] = $attribute;
|
203 |
-
}
|
204 |
-
}
|
205 |
-
|
206 |
-
if (null !== $backendType) {
|
207 |
-
$backendType = (array) $backendType;
|
208 |
-
$attributes = array();
|
209 |
-
foreach ($this->_searchableAttributes as $attribute) {
|
210 |
-
/** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
|
211 |
-
if (in_array($attribute->getBackendType(), $backendType)) {
|
212 |
-
$attributes[$attribute->getAttributeCode()] = $attribute;
|
213 |
-
}
|
214 |
-
}
|
215 |
-
|
216 |
-
return $attributes;
|
217 |
-
}
|
218 |
-
|
219 |
-
return $this->_searchableAttributes;
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Returns seach config data.
|
224 |
-
*
|
225 |
-
* @param string $field
|
226 |
-
* @param mixed $store
|
227 |
-
* @return array
|
228 |
-
*/
|
229 |
-
public function getSearchConfigData($field, $store = null)
|
230 |
-
{
|
231 |
-
$path = 'catalog/search/' . $field;
|
232 |
-
|
233 |
-
return Mage::getStoreConfig($path, $store);
|
234 |
-
}
|
235 |
-
|
236 |
-
|
237 |
/**
|
238 |
* Returns searched parameter as array.
|
239 |
*
|
@@ -245,7 +166,8 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
245 |
{
|
246 |
if (empty($value) ||
|
247 |
(isset($value['from']) && empty($value['from']) &&
|
248 |
-
isset($value['to']) && empty($value['to']))
|
|
|
249 |
return false;
|
250 |
}
|
251 |
|
@@ -276,54 +198,6 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
276 |
return array($field => $value);
|
277 |
}
|
278 |
|
279 |
-
/**
|
280 |
-
* Returns sortable attribute field name (localized if needed).
|
281 |
-
*
|
282 |
-
* @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
|
283 |
-
* @param string $locale
|
284 |
-
* @return string
|
285 |
-
*/
|
286 |
-
public function getSortableAttributeFieldName($attribute, $locale = null)
|
287 |
-
{
|
288 |
-
if (is_string($attribute)) {
|
289 |
-
$this->getSortableAttributes(); // populate sortable attributes if not already set
|
290 |
-
if (!isset($this->_sortableAttributes[$attribute])) {
|
291 |
-
return $attribute;
|
292 |
-
}
|
293 |
-
$attribute = $this->_sortableAttributes[$attribute];
|
294 |
-
}
|
295 |
-
|
296 |
-
$attributeCode = $attribute->getAttributeCode();
|
297 |
-
|
298 |
-
if ($attributeCode != 'score' && !in_array($attribute->getBackendType(), $this->_unlocalizedFieldTypes)) {
|
299 |
-
if (null === $locale) {
|
300 |
-
$locale = $this->getLocaleCode();
|
301 |
-
}
|
302 |
-
$languageCode = $this->getLanguageCodeByLocaleCode($locale);
|
303 |
-
$languageSuffix = $languageCode ? '_' . $languageCode : '';
|
304 |
-
$attributeCode .= $languageSuffix;
|
305 |
-
}
|
306 |
-
|
307 |
-
return 'sort_by_' . $attributeCode;
|
308 |
-
}
|
309 |
-
|
310 |
-
/**
|
311 |
-
* Retrieves all sortable product attributes.
|
312 |
-
*
|
313 |
-
* @return array
|
314 |
-
*/
|
315 |
-
public function getSortableAttributes()
|
316 |
-
{
|
317 |
-
if (null === $this->_sortableAttributes) {
|
318 |
-
$this->_sortableAttributes = Mage::getSingleton('catalog/config')->getAttributesUsedForSortBy();
|
319 |
-
if (array_key_exists('price', $this->_sortableAttributes)) {
|
320 |
-
unset($this->_sortableAttributes['price']); // Price sorting is handled with searchable attribute.
|
321 |
-
}
|
322 |
-
}
|
323 |
-
|
324 |
-
return $this->_sortableAttributes;
|
325 |
-
}
|
326 |
-
|
327 |
/**
|
328 |
* Defines supported languages for snowball filter.
|
329 |
*
|
@@ -346,9 +220,9 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
346 |
// French
|
347 |
'fr' => array('fr_CA', 'fr_FR'),
|
348 |
// German
|
349 |
-
'de' => array('de_DE','de_DE','de_AT'),
|
350 |
// Italian
|
351 |
-
'it' => array('it_IT','it_CH'),
|
352 |
// Norwegian
|
353 |
'nb' => array('nb_NO', 'nn_NO'),
|
354 |
// Portuguese
|
@@ -389,9 +263,9 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
389 |
*
|
390 |
* @return bool
|
391 |
*/
|
392 |
-
public function isActiveEngine()
|
393 |
-
|
394 |
-
if(is_null($this->is_active)) {
|
395 |
$storeConfig = json_decode(Mage::getStoreConfig(self::CONFIG_KEY));
|
396 |
$sortbyObjs = $storeConfig->sortby;
|
397 |
|
@@ -418,6 +292,7 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
418 |
$currentReqPath = str_replace("/index.php/", "/", $currentReqPath);
|
419 |
|
420 |
$isPluginActive = Mage::getStoreConfig(self::IS_ACTIVE) == '1';
|
|
|
421 |
|
422 |
if ($isPluginActive) {
|
423 |
foreach ($sortbyObjs as $sortbyObj) {
|
@@ -425,7 +300,9 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
425 |
if (in_array($currentReqPath, $sortbyObj->rule->paths)) {
|
426 |
$choiceOptions = $this->_getOptionsAddedByChoice($sortbyObj);
|
427 |
|
428 |
-
if (
|
|
|
|
|
429 |
$this->_setDefaultSortOption($sortbyObj, $storeConfig);
|
430 |
break;
|
431 |
}
|
@@ -435,16 +312,27 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
435 |
if (!empty(array_intersect($currentReqParams, $sortbyObj->rule->params))) {
|
436 |
$choiceOptions = $this->_getOptionsAddedByChoice($sortbyObj);
|
437 |
|
438 |
-
|
439 |
-
|
|
|
440 |
$this->_setDefaultSortOption($sortbyObj, $storeConfig);
|
441 |
break;
|
442 |
}
|
443 |
}
|
444 |
}
|
445 |
|
446 |
-
|
447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
}
|
449 |
}
|
450 |
}
|
@@ -452,96 +340,64 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
452 |
return $this->is_active;
|
453 |
}
|
454 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
455 |
// If sort order is default, $_REQUEST["order"] will not exist
|
456 |
// This adds a default value in it
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
}
|
463 |
-
} else if(isset($sortbyObj->override)) {
|
464 |
-
$_REQUEST["order"] = $
|
465 |
-
} else if(isset($
|
466 |
-
|
467 |
-
// This case although seems useless
|
468 |
-
$_REQUEST["order"] = $_SESSION['catalog']['sort_order'];
|
469 |
}
|
|
|
|
|
|
|
|
|
|
|
470 |
}
|
471 |
|
472 |
/**
|
473 |
* @param $sortbyObj
|
474 |
* @return array
|
475 |
*/
|
476 |
-
private function _getOptionsAddedByChoice($sortbyObj)
|
|
|
477 |
$options = array();
|
478 |
|
479 |
-
if(isset($sortbyObj->override)){
|
480 |
// Search case, override all system options with choice
|
481 |
-
|
482 |
-
|
483 |
-
foreach ($caiOptions as $key => $caiOption)
|
484 |
$options[] = $key;
|
485 |
-
} elseif(isset($sortbyObj->extend)) {
|
486 |
-
foreach ($sortbyObj->extend as $key
|
487 |
$options[] = $key;
|
488 |
}
|
489 |
|
490 |
return $options;
|
491 |
}
|
492 |
|
493 |
-
/**
|
494 |
-
* Checks whether request is a navigation
|
495 |
-
*
|
496 |
-
* @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
|
497 |
-
* @return bool
|
498 |
-
*/
|
499 |
-
public function isNavigation() {
|
500 |
-
if($this->_getRequest()->getControllerName() == "category") {
|
501 |
-
return true;
|
502 |
-
}
|
503 |
-
return false;
|
504 |
-
}
|
505 |
-
|
506 |
-
/**
|
507 |
-
* Checks whether request is a resultPage
|
508 |
-
*
|
509 |
-
* @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
|
510 |
-
* @return bool
|
511 |
-
*/
|
512 |
-
public function isSearch() {
|
513 |
-
if($this->_getRequest()->getControllerName() == "result") {
|
514 |
-
return true;
|
515 |
-
}
|
516 |
-
return false;
|
517 |
-
}
|
518 |
-
|
519 |
-
/**
|
520 |
-
* Checks if specified attribute is indexable by search engine.
|
521 |
-
*
|
522 |
-
* @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
|
523 |
-
* @return bool
|
524 |
-
*/
|
525 |
-
public function isAttributeIndexable($attribute)
|
526 |
-
{
|
527 |
-
if ($attribute->getBackendType() == 'varchar' && !$attribute->getBackendModel()) {
|
528 |
-
return true;
|
529 |
-
}
|
530 |
-
|
531 |
-
if ($attribute->getBackendType() == 'int'
|
532 |
-
&& $attribute->getSourceModel() != 'eav/entity_attribute_source_boolean'
|
533 |
-
&& ($attribute->getIsSearchable() || $attribute->getIsFilterable() || $attribute->getIsFilterableInSearch())
|
534 |
-
) {
|
535 |
-
return true;
|
536 |
-
}
|
537 |
-
|
538 |
-
if ($attribute->getIsSearchable() || $attribute->getIsFilterable() || $attribute->getIsFilterableInSearch()) {
|
539 |
-
return true;
|
540 |
-
}
|
541 |
-
|
542 |
-
return false;
|
543 |
-
}
|
544 |
-
|
545 |
/**
|
546 |
* Checks if debug mode is enabled.
|
547 |
*
|
@@ -554,20 +410,9 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
554 |
return array_key_exists('enable_debug_mode', $config) && $config['enable_debug_mode'];
|
555 |
}
|
556 |
|
557 |
-
/**
|
558 |
-
* Method that can be overriden for customing product data indexation.
|
559 |
-
*
|
560 |
-
* @param array $index
|
561 |
-
* @param string $separator
|
562 |
-
* @return array
|
563 |
-
*/
|
564 |
-
public function prepareIndexData($index, $separator = null)
|
565 |
-
{
|
566 |
-
return $index;
|
567 |
-
}
|
568 |
-
|
569 |
/**
|
570 |
* Forces error display.
|
|
|
571 |
*
|
572 |
* @param string $error
|
573 |
*/
|
@@ -577,94 +422,4 @@ class ChoiceAI_Search_Helper_Data extends Mage_Core_Helper_Abstract
|
|
577 |
->addError($error)->getGroupedHtml();
|
578 |
}
|
579 |
|
580 |
-
|
581 |
-
* returns the choiceai site name
|
582 |
-
*
|
583 |
-
* @return String
|
584 |
-
*/
|
585 |
-
public function getSiteName(){
|
586 |
-
$siteKeyLabel = ChoiceAI_Searchcore_Helper_Constants::SITE_KEY;
|
587 |
-
$config = $this->getEngineConfigData($siteKeyLabel);
|
588 |
-
if(array_key_exists($siteKeyLabel, $config) && $config[$siteKeyLabel] != "")
|
589 |
-
return $config[$siteKeyLabel];
|
590 |
-
else {
|
591 |
-
$siteKey = Mage::getResourceModel('choiceai_searchcore/config')
|
592 |
-
->getValue(Mage::app()->getWebsite()->getWebsiteId(),
|
593 |
-
$siteKeyLabel);
|
594 |
-
if(isset($siteKey) && $siteKey != ''){
|
595 |
-
Mage::helper('choiceai_searchcore')->saveConfig(Mage::app()->getWebsite(),
|
596 |
-
array($siteKeyLabel => $siteKey));
|
597 |
-
return $siteKey;
|
598 |
-
} else {
|
599 |
-
if(Mage::getIsDeveloperMode()) {
|
600 |
-
Mage::throwException("ChoiceAI site key is empty");
|
601 |
-
} else {
|
602 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'ChoiceAI site key is not set');
|
603 |
-
return null;
|
604 |
-
}
|
605 |
-
}
|
606 |
-
}
|
607 |
-
}
|
608 |
-
|
609 |
-
/*
|
610 |
-
* returns the choiceai api Key
|
611 |
-
*
|
612 |
-
* @return String
|
613 |
-
*/
|
614 |
-
public function getApiKey(){
|
615 |
-
$apiKeyLabel = ChoiceAI_Searchcore_Helper_Constants::API_KEY;
|
616 |
-
$config = $this->getEngineConfigData($apiKeyLabel);
|
617 |
-
if(array_key_exists($apiKeyLabel, $config) && $config[$apiKeyLabel] != "")
|
618 |
-
return $config[$apiKeyLabel];
|
619 |
-
else {
|
620 |
-
$apiKey = Mage::getResourceModel('choiceai_searchcore/config')
|
621 |
-
->getValue(Mage::app()->getWebsite()->getWebsiteId(), $apiKeyLabel);
|
622 |
-
if(isset($apiKey) && $apiKey != ''){
|
623 |
-
Mage::helper('choiceai_searchcore')->saveConfig(Mage::app()->getWebsite(),
|
624 |
-
array($apiKeyLabel => $apiKey));
|
625 |
-
return $apiKey;
|
626 |
-
} else {
|
627 |
-
if(Mage::getIsDeveloperMode()) {
|
628 |
-
Mage::throwException("ChoiceAI api key is empty");
|
629 |
-
} else {
|
630 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'ChoiceAI Api key is not set');
|
631 |
-
return null;
|
632 |
-
}
|
633 |
-
}
|
634 |
-
}
|
635 |
-
}
|
636 |
-
|
637 |
-
/**
|
638 |
-
* This method checks whether hosted search is active or not
|
639 |
-
* @return boolean
|
640 |
-
*/
|
641 |
-
public function isHostedSearchActive()
|
642 |
-
{
|
643 |
-
$siteKey = null;
|
644 |
-
$apiKey = null;
|
645 |
-
try {
|
646 |
-
$siteKey = $this->getSiteName();
|
647 |
-
$apiKey = $this->getApiKey();
|
648 |
-
} catch(Exception $e) {
|
649 |
-
//ignoring the exception
|
650 |
-
}
|
651 |
-
$searchConf = $this->getEngineConfigData('search');
|
652 |
-
$hostedSearchConf = Mage::helper('choiceai_searchcore')->isConfigTrue(Mage::app()->getWebsite(),ChoiceAI_Searchcore_Helper_Constants::SEARCH_HOSTED_STATUS);
|
653 |
-
$searchModConf = Mage::helper('choiceai_searchcore')->isConfigTrue(Mage::app()->getWebsite(), ChoiceAI_Searchcore_Helper_Constants::SEARCH_MOD_STATUS);
|
654 |
-
$hostedIntStatus = $searchConf[ChoiceAI_Searchcore_Helper_Constants::SEARCH_HOSTED_INT_STATUS];
|
655 |
-
$hostedSearchRedirectUrl = $searchConf[ChoiceAI_Searchcore_Helper_Constants::SEARCH_HOSTED_REDIRECT_URL];
|
656 |
-
return !is_null($siteKey) && !is_null($apiKey) &&
|
657 |
-
$hostedSearchConf && !$searchModConf &&
|
658 |
-
$hostedIntStatus == ChoiceAI_Searchcore_Helper_Constants::SEARCH_HOSTED_INT_COMPLETE &&
|
659 |
-
sizeof($hostedSearchRedirectUrl) > 0;
|
660 |
-
}
|
661 |
-
|
662 |
-
/**
|
663 |
-
* Method to get the hosted redirection url
|
664 |
-
* @return mixed
|
665 |
-
*/
|
666 |
-
public function getHostedRedirectUrl() {
|
667 |
-
$config = $this->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::SEARCH_HOSTED_REDIRECT_URL);
|
668 |
-
return $config[ChoiceAI_Searchcore_Helper_Constants::SEARCH_HOSTED_REDIRECT_URL];
|
669 |
-
}
|
670 |
-
}
|
1 |
<?php
|
2 |
+
|
3 |
/**
|
4 |
*
|
5 |
* @package ChoiceAI_Search
|
51 |
);
|
52 |
|
53 |
/**
|
54 |
+
* Boolean field which stores choiceai active or not
|
55 |
+
*
|
56 |
+
* @var boolean
|
57 |
+
*/
|
58 |
public $is_active = NULL;
|
59 |
|
60 |
|
92 |
return $attributeCode;
|
93 |
}
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
/**
|
96 |
* Returns search engine config data.
|
97 |
*
|
122 |
*/
|
123 |
public function getLanguageCodeByLocaleCode($localeCode)
|
124 |
{
|
125 |
+
$localeCode = (string)$localeCode;
|
126 |
if (!$localeCode) {
|
127 |
return false;
|
128 |
}
|
144 |
return $this->_languageCodes[$localeCode];
|
145 |
}
|
146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
/**
|
148 |
* Returns store locale code.
|
149 |
*
|
155 |
return Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store);
|
156 |
}
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
/**
|
159 |
* Returns searched parameter as array.
|
160 |
*
|
166 |
{
|
167 |
if (empty($value) ||
|
168 |
(isset($value['from']) && empty($value['from']) &&
|
169 |
+
isset($value['to']) && empty($value['to']))
|
170 |
+
) {
|
171 |
return false;
|
172 |
}
|
173 |
|
198 |
return array($field => $value);
|
199 |
}
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
/**
|
202 |
* Defines supported languages for snowball filter.
|
203 |
*
|
220 |
// French
|
221 |
'fr' => array('fr_CA', 'fr_FR'),
|
222 |
// German
|
223 |
+
'de' => array('de_DE', 'de_DE', 'de_AT'),
|
224 |
// Italian
|
225 |
+
'it' => array('it_IT', 'it_CH'),
|
226 |
// Norwegian
|
227 |
'nb' => array('nb_NO', 'nn_NO'),
|
228 |
// Portuguese
|
263 |
*
|
264 |
* @return bool
|
265 |
*/
|
266 |
+
public function isActiveEngine()
|
267 |
+
{
|
268 |
+
if (is_null($this->is_active)) {
|
269 |
$storeConfig = json_decode(Mage::getStoreConfig(self::CONFIG_KEY));
|
270 |
$sortbyObjs = $storeConfig->sortby;
|
271 |
|
292 |
$currentReqPath = str_replace("/index.php/", "/", $currentReqPath);
|
293 |
|
294 |
$isPluginActive = Mage::getStoreConfig(self::IS_ACTIVE) == '1';
|
295 |
+
$choiceOptions = array();
|
296 |
|
297 |
if ($isPluginActive) {
|
298 |
foreach ($sortbyObjs as $sortbyObj) {
|
300 |
if (in_array($currentReqPath, $sortbyObj->rule->paths)) {
|
301 |
$choiceOptions = $this->_getOptionsAddedByChoice($sortbyObj);
|
302 |
|
303 |
+
if (count($choiceOptions) < 1)
|
304 |
+
$this->is_active = true;
|
305 |
+
else if (!isset($_REQUEST["order"]) && is_null($_REQUEST["order"]))
|
306 |
$this->_setDefaultSortOption($sortbyObj, $storeConfig);
|
307 |
break;
|
308 |
}
|
312 |
if (!empty(array_intersect($currentReqParams, $sortbyObj->rule->params))) {
|
313 |
$choiceOptions = $this->_getOptionsAddedByChoice($sortbyObj);
|
314 |
|
315 |
+
if (count($choiceOptions) < 1)
|
316 |
+
$this->is_active = true;
|
317 |
+
else if (!isset($_REQUEST["order"]) || is_null($_REQUEST["order"]))
|
318 |
$this->_setDefaultSortOption($sortbyObj, $storeConfig);
|
319 |
break;
|
320 |
}
|
321 |
}
|
322 |
}
|
323 |
|
324 |
+
Mage::register('expId', $sortbyObj->expId, true);
|
325 |
+
$device = $this->getDevice($_SERVER['HTTP_USER_AGENT']);
|
326 |
+
|
327 |
+
if (count($choiceOptions) && isset($_REQUEST["order"]) && in_array($_REQUEST["order"], $choiceOptions)) {
|
328 |
+
if(isset($sortbyObj) && isset($sortbyObj->device)) {
|
329 |
+
if (in_array("all", $sortbyObj->device) || in_array($device, $sortbyObj->device))
|
330 |
+
$this->is_active = true;
|
331 |
+
else
|
332 |
+
$this->is_active = false;
|
333 |
+
}
|
334 |
+
else
|
335 |
+
$this->is_active = false;
|
336 |
}
|
337 |
}
|
338 |
}
|
340 |
return $this->is_active;
|
341 |
}
|
342 |
|
343 |
+
private function getDevice($userAgent)
|
344 |
+
{
|
345 |
+
if (stripos($userAgent, "ipad") !== false) {
|
346 |
+
return "desktoptablet";
|
347 |
+
// return "tablet";
|
348 |
+
} else if (stripos($userAgent, "android") !== false || stripos($userAgent, "mobile") !== false || stripos($userAgent, "iphone") !== false){
|
349 |
+
return "desktoptablet";
|
350 |
+
// return "mobile";
|
351 |
+
} else
|
352 |
+
return 'desktop';
|
353 |
+
}
|
354 |
+
|
355 |
// If sort order is default, $_REQUEST["order"] will not exist
|
356 |
// This adds a default value in it
|
357 |
+
// author: Harkirat
|
358 |
+
private function _setDefaultSortOption($sortbyObj, $storeConfig)
|
359 |
+
{
|
360 |
+
if (isset($sortbyObj->extend)) {
|
361 |
+
if (count($sortbyObj->extend)) {
|
362 |
+
foreach ($sortbyObj->extend as $optionKey => $optionValue) {
|
363 |
+
$_REQUEST['order'] = $optionKey;
|
364 |
+
break;
|
365 |
+
}
|
366 |
+
} else {
|
367 |
+
$this->is_active = true;
|
368 |
}
|
369 |
+
} else if (isset($sortbyObj->override) && $storeConfig->default_search_sort) {
|
370 |
+
$_REQUEST["order"] = $storeConfig->default_search_sort;
|
371 |
+
} else if (!isset($sortbyObj->override) && !isset($sortbyObj->extend)) {
|
372 |
+
$_REQUEST["order"] = "takeover_mode";
|
|
|
|
|
373 |
}
|
374 |
+
// } else if(isset($_SESSION['catalog']) && isset($_SESSION['catalog']['sort_order'])){
|
375 |
+
// // If prod list page, use the session value
|
376 |
+
// // This case although seems useless
|
377 |
+
// $_REQUEST["order"] = $_SESSION['catalog']['sort_order'];
|
378 |
+
// }
|
379 |
}
|
380 |
|
381 |
/**
|
382 |
* @param $sortbyObj
|
383 |
* @return array
|
384 |
*/
|
385 |
+
private function _getOptionsAddedByChoice($sortbyObj)
|
386 |
+
{
|
387 |
$options = array();
|
388 |
|
389 |
+
if (isset($sortbyObj->override)) {
|
390 |
// Search case, override all system options with choice
|
391 |
+
foreach ($sortbyObj->override as $key => $caiOption)
|
|
|
|
|
392 |
$options[] = $key;
|
393 |
+
} elseif (isset($sortbyObj->extend)) {
|
394 |
+
foreach ($sortbyObj->extend as $key => $option)
|
395 |
$options[] = $key;
|
396 |
}
|
397 |
|
398 |
return $options;
|
399 |
}
|
400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
/**
|
402 |
* Checks if debug mode is enabled.
|
403 |
*
|
410 |
return array_key_exists('enable_debug_mode', $config) && $config['enable_debug_mode'];
|
411 |
}
|
412 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
413 |
/**
|
414 |
* Forces error display.
|
415 |
+
* Used in Abstract.php model's search function
|
416 |
*
|
417 |
* @param string $error
|
418 |
*/
|
422 |
->addError($error)->getGroupedHtml();
|
423 |
}
|
424 |
|
425 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Search/Helper/Productimg.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ChoiceAI_Search_Helper_Productimg extends Mage_ConfigurableSwatches_Helper_Productimg
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Determine if the passed text matches the label of any of the passed product's images
|
7 |
+
*
|
8 |
+
* @param string $text
|
9 |
+
* @param Mage_Catalog_Model_Product $product
|
10 |
+
* @param string $type
|
11 |
+
* @return Varien_Object|null
|
12 |
+
*/
|
13 |
+
// Required to avoid issue where $this->_productImagesByLabel doesn't exist
|
14 |
+
public function getProductImgByLabel($text, $product, $type = null)
|
15 |
+
{
|
16 |
+
$this->indexProductImages($product);
|
17 |
+
|
18 |
+
if (count($this->_productImagesByLabel)) {
|
19 |
+
//Get the product's image array and prepare the text
|
20 |
+
$images = $this->_productImagesByLabel[$product->getId()];
|
21 |
+
$text = Mage_ConfigurableSwatches_Helper_Data::normalizeKey($text);
|
22 |
+
|
23 |
+
$resultImages = array(
|
24 |
+
'standard' => isset($images[$text]) ? $images[$text] : null,
|
25 |
+
'swatch' => isset($images[$text . self::SWATCH_LABEL_SUFFIX]) ? $images[$text . self::SWATCH_LABEL_SUFFIX]
|
26 |
+
: null,
|
27 |
+
);
|
28 |
+
|
29 |
+
if (!is_null($type) && array_key_exists($type, $resultImages)) {
|
30 |
+
$image = $resultImages[$type];
|
31 |
+
} else {
|
32 |
+
$image = (!is_null($resultImages['swatch'])) ? $resultImages['swatch'] : $resultImages['standard'];
|
33 |
+
}
|
34 |
+
} else {
|
35 |
+
$image = null;
|
36 |
+
}
|
37 |
+
|
38 |
+
return $image;
|
39 |
+
}
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
?>
|
app/code/local/ChoiceAI/Search/Model/Catalog/Category.php
CHANGED
@@ -46,7 +46,7 @@ class ChoiceAI_Search_Model_Catalog_Category extends Mage_Catalog_Model_Category
|
|
46 |
if (strpos($currentReqPath, "/index.php/") !== false)
|
47 |
$currentReqPath = str_replace("/index.php/", "/", $currentReqPath);
|
48 |
|
49 |
-
|
50 |
// $isPluginActive = true;
|
51 |
|
52 |
if($isPluginActive) {
|
@@ -69,6 +69,5 @@ class ChoiceAI_Search_Model_Catalog_Category extends Mage_Catalog_Model_Category
|
|
69 |
return Mage::getSingleton('catalog/config')->getAttributeUsedForSortByArray();
|
70 |
else
|
71 |
return parent::getAvailableSortByOptions();
|
72 |
-
|
73 |
}
|
74 |
}
|
46 |
if (strpos($currentReqPath, "/index.php/") !== false)
|
47 |
$currentReqPath = str_replace("/index.php/", "/", $currentReqPath);
|
48 |
|
49 |
+
$isPluginActive = Mage::helper('choiceai_search')->isActiveEngine();
|
50 |
// $isPluginActive = true;
|
51 |
|
52 |
if($isPluginActive) {
|
69 |
return Mage::getSingleton('catalog/config')->getAttributeUsedForSortByArray();
|
70 |
else
|
71 |
return parent::getAvailableSortByOptions();
|
|
|
72 |
}
|
73 |
}
|
app/code/local/ChoiceAI/Search/Model/Catalog/Config.php
CHANGED
@@ -14,10 +14,9 @@ class ChoiceAI_Search_Model_Catalog_Config extends Mage_Catalog_Model_Config
|
|
14 |
public $options = NULL;
|
15 |
|
16 |
/**
|
17 |
-
*
|
18 |
-
* key = code, value = name
|
19 |
*
|
20 |
-
* Note by Harkirat: This function is called in both cases: product list and search
|
21 |
*
|
22 |
* @return array
|
23 |
*/
|
@@ -29,31 +28,29 @@ class ChoiceAI_Search_Model_Catalog_Config extends Mage_Catalog_Model_Config
|
|
29 |
$STORE_CONFIG = json_decode(Mage::getStoreConfig(self::CONFIG_KEY));
|
30 |
$sortbyObjs = $STORE_CONFIG->sortby;
|
31 |
|
32 |
-
//
|
33 |
$currentReqPath = explode("?", $_SERVER['REQUEST_URI'])[0];
|
34 |
|
35 |
-
//
|
36 |
parse_str($_SERVER['QUERY_STRING'], $paramPairs);
|
37 |
-
//
|
38 |
$currentReqParams = array();
|
39 |
if (count($paramPairs)) {
|
40 |
foreach ($paramPairs as $key => $paramPair)
|
41 |
$currentReqParams[] = $key;
|
42 |
}
|
43 |
|
44 |
-
//
|
45 |
-
//
|
46 |
if (strpos($currentReqPath, "/magento/") !== false)
|
47 |
$currentReqPath = str_replace("/magento/", "/", $currentReqPath);
|
48 |
|
49 |
-
//
|
50 |
if (strpos($currentReqPath, "/index.php/") !== false)
|
51 |
$currentReqPath = str_replace("/index.php/", "/", $currentReqPath);
|
52 |
|
53 |
-
$isPluginActive = Mage::getStoreConfig(self::IS_ACTIVE) == '1';
|
54 |
-
// $isPluginActive = true;
|
55 |
|
56 |
-
if (
|
57 |
foreach ($sortbyObjs as $sortbyObj) {
|
58 |
if (isset($sortbyObj->rule)) {
|
59 |
if (isset($sortbyObj->rule->paths)) {
|
@@ -103,12 +100,16 @@ class ChoiceAI_Search_Model_Catalog_Config extends Mage_Catalog_Model_Config
|
|
103 |
} else if(isset($sortbyObj->extend)) {
|
104 |
// Product list page, add system options first, then add/replace ours
|
105 |
|
|
|
|
|
|
|
106 |
foreach ($this->getAttributesUsedForSortBy() as $attribute) {
|
107 |
/* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
|
108 |
$options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
|
109 |
}
|
110 |
|
111 |
// Default options added above, now adding our option/s, which can either override or be a new option
|
|
|
112 |
foreach ($sortbyObj->extend as $key=>$option)
|
113 |
$options[$key] = Mage::helper('catalog')->__($option);
|
114 |
|
14 |
public $options = NULL;
|
15 |
|
16 |
/**
|
17 |
+
* Returns what sort by options are used by Magento, whether in listing or search
|
|
|
18 |
*
|
19 |
+
* Note by Harkirat: This function is called in both cases: product list and search
|
20 |
*
|
21 |
* @return array
|
22 |
*/
|
28 |
$STORE_CONFIG = json_decode(Mage::getStoreConfig(self::CONFIG_KEY));
|
29 |
$sortbyObjs = $STORE_CONFIG->sortby;
|
30 |
|
31 |
+
// Getting URL Path
|
32 |
$currentReqPath = explode("?", $_SERVER['REQUEST_URI'])[0];
|
33 |
|
34 |
+
// Getting param keys in array var $paramPairs
|
35 |
parse_str($_SERVER['QUERY_STRING'], $paramPairs);
|
36 |
+
// Getting query keys
|
37 |
$currentReqParams = array();
|
38 |
if (count($paramPairs)) {
|
39 |
foreach ($paramPairs as $key => $paramPair)
|
40 |
$currentReqParams[] = $key;
|
41 |
}
|
42 |
|
43 |
+
// Refining URL path
|
44 |
+
// My own local installation case: localhost/magento/
|
45 |
if (strpos($currentReqPath, "/magento/") !== false)
|
46 |
$currentReqPath = str_replace("/magento/", "/", $currentReqPath);
|
47 |
|
48 |
+
// Making www.store.com/index.php/abcd => www.store.com/abcd
|
49 |
if (strpos($currentReqPath, "/index.php/") !== false)
|
50 |
$currentReqPath = str_replace("/index.php/", "/", $currentReqPath);
|
51 |
|
|
|
|
|
52 |
|
53 |
+
if (Mage::getStoreConfig(self::IS_ACTIVE) == '1') {
|
54 |
foreach ($sortbyObjs as $sortbyObj) {
|
55 |
if (isset($sortbyObj->rule)) {
|
56 |
if (isset($sortbyObj->rule->paths)) {
|
100 |
} else if(isset($sortbyObj->extend)) {
|
101 |
// Product list page, add system options first, then add/replace ours
|
102 |
|
103 |
+
$options = array(
|
104 |
+
'position' => Mage::helper('catalog')->__('Position')
|
105 |
+
);
|
106 |
foreach ($this->getAttributesUsedForSortBy() as $attribute) {
|
107 |
/* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
|
108 |
$options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
|
109 |
}
|
110 |
|
111 |
// Default options added above, now adding our option/s, which can either override or be a new option
|
112 |
+
// If we add more overrides in future, this will still work
|
113 |
foreach ($sortbyObj->extend as $key=>$option)
|
114 |
$options[$key] = Mage::helper('catalog')->__($option);
|
115 |
|
app/code/local/ChoiceAI/Search/Model/Catalog/Product/Url.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: harkirat
|
5 |
+
* Date: 30/6/17
|
6 |
+
* Time: 8:22 PM
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Magento
|
11 |
+
*
|
12 |
+
* NOTICE OF LICENSE
|
13 |
+
*
|
14 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
15 |
+
* that is bundled with this package in the file LICENSE.txt.
|
16 |
+
* It is also available through the world-wide-web at this URL:
|
17 |
+
* http://opensource.org/licenses/osl-3.0.php
|
18 |
+
* If you did not receive a copy of the license and are unable to
|
19 |
+
* obtain it through the world-wide-web, please send an email
|
20 |
+
* to license@magento.com so we can send you a copy immediately.
|
21 |
+
*
|
22 |
+
* DISCLAIMER
|
23 |
+
*
|
24 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
25 |
+
* versions in the future. If you wish to customize Magento for your
|
26 |
+
* needs please refer to http://www.magento.com for more information.
|
27 |
+
*
|
28 |
+
* @category Mage
|
29 |
+
* @package Mage_Catalog
|
30 |
+
* @copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
|
31 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
32 |
+
*/
|
33 |
+
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Product Url model
|
37 |
+
*
|
38 |
+
* @category Mage
|
39 |
+
* @package Mage_Catalog
|
40 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
41 |
+
*/
|
42 |
+
class ChoiceAI_Search_Model_Catalog_Product_Url extends Mage_Catalog_Model_Product_Url
|
43 |
+
{
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Retrieve Product URL
|
47 |
+
*
|
48 |
+
* @param Mage_Catalog_Model_Product $product
|
49 |
+
* @param bool $useSid forced SID mode
|
50 |
+
* @return string
|
51 |
+
*/
|
52 |
+
public function getProductUrl($product, $useSid = null)
|
53 |
+
{
|
54 |
+
return parent::getProductUrl($product, $useSid);
|
55 |
+
// $toAppend = "cu=cai";
|
56 |
+
//
|
57 |
+
// if (Mage::helper('choiceai_search')->isActiveEngine()) {
|
58 |
+
// // append cu=cai to param
|
59 |
+
// // contains params already
|
60 |
+
// if(strpos($prodUrl, "?") !== false){
|
61 |
+
// // only ? is there which is also the last character of the url
|
62 |
+
// if(substr($prodUrl, -1) == "?")
|
63 |
+
// return $prodUrl.$toAppend;
|
64 |
+
// else
|
65 |
+
// return $prodUrl."&".$toAppend;
|
66 |
+
// } else{
|
67 |
+
// return $prodUrl."?".$toAppend;
|
68 |
+
// }
|
69 |
+
// } else
|
70 |
+
// return $prodUrl;
|
71 |
+
}
|
72 |
+
|
73 |
+
}
|
app/code/local/ChoiceAI/Search/Model/Resource/Catalog/Product/Collection.php
CHANGED
@@ -214,7 +214,7 @@ class ChoiceAI_Search_Model_Resource_Catalog_Product_Collection extends Mage_Cat
|
|
214 |
$params = $this->_getParams();
|
215 |
$params['limit'] = 1;
|
216 |
//$this->_engine->getIdsByQuery($query, $params);
|
217 |
-
|
218 |
//$this->_totalRecords = $this->_engine->getLastNumFound();
|
219 |
}
|
220 |
|
@@ -230,7 +230,7 @@ class ChoiceAI_Search_Model_Resource_Catalog_Product_Collection extends Mage_Cat
|
|
230 |
*/
|
231 |
public function getStats($field)
|
232 |
{
|
233 |
-
|
234 |
}
|
235 |
|
236 |
/**
|
@@ -268,25 +268,30 @@ class ChoiceAI_Search_Model_Resource_Catalog_Product_Collection extends Mage_Cat
|
|
268 |
*/
|
269 |
protected function _beforeLoad()
|
270 |
{
|
271 |
-
|
272 |
$result = $this->_engine->getIdsByQuery($this->qt, $this->_getParams());
|
273 |
$this->_facetedData = isset($result['faceted_data']) ? $result['faceted_data'] : array();
|
274 |
$this->_totalRecords = isset($result['total_count']) ? $result['total_count'] : null;
|
275 |
$this->stats = isset($result["stats"])?$result["stats"] :array();
|
276 |
$this->results = isset($result["results"]) ? $result["results"] : array();
|
277 |
}
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
|
285 |
return parent::_beforeLoad();
|
286 |
}
|
287 |
|
288 |
-
|
289 |
-
|
290 |
/**
|
291 |
* Load collection data into object items
|
292 |
*
|
214 |
$params = $this->_getParams();
|
215 |
$params['limit'] = 1;
|
216 |
//$this->_engine->getIdsByQuery($query, $params);
|
217 |
+
$this->_totalRecords = 1;
|
218 |
//$this->_totalRecords = $this->_engine->getLastNumFound();
|
219 |
}
|
220 |
|
230 |
*/
|
231 |
public function getStats($field)
|
232 |
{
|
233 |
+
return isset($this->stats[$field])?$this->stats[$field]:array();
|
234 |
}
|
235 |
|
236 |
/**
|
268 |
*/
|
269 |
protected function _beforeLoad()
|
270 |
{
|
271 |
+
if ($this->_engine) {
|
272 |
$result = $this->_engine->getIdsByQuery($this->qt, $this->_getParams());
|
273 |
$this->_facetedData = isset($result['faceted_data']) ? $result['faceted_data'] : array();
|
274 |
$this->_totalRecords = isset($result['total_count']) ? $result['total_count'] : null;
|
275 |
$this->stats = isset($result["stats"])?$result["stats"] :array();
|
276 |
$this->results = isset($result["results"]) ? $result["results"] : array();
|
277 |
}
|
278 |
+
|
279 |
+
// Getting IDs of all products with the store
|
280 |
+
// $productIdsArray = Mage::getModel('catalog/product')->getCollection()->getAllIds();
|
281 |
+
foreach($this->results as $result){
|
282 |
+
// Keeping only those products which are in the store!
|
283 |
+
// @TODO: Filter those items if required
|
284 |
+
// if(in_array($result['uniqueId'], $productIdsArray)) {
|
285 |
+
$product = new Mage_Catalog_Model_Product();
|
286 |
+
$result['id'] = $result['uniqueId'];
|
287 |
+
$product->addData($result);
|
288 |
+
$this->_items[$result['id']] = $product;
|
289 |
+
// }
|
290 |
+
}
|
291 |
|
292 |
return parent::_beforeLoad();
|
293 |
}
|
294 |
|
|
|
|
|
295 |
/**
|
296 |
* Load collection data into object items
|
297 |
*
|
app/code/local/ChoiceAI/Search/Model/Resource/Engine/Abstract.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
4 |
*
|
5 |
* @package ChoiceAI_Search
|
6 |
* @copyright Copyright (c) MineWhat
|
@@ -8,33 +8,8 @@
|
|
8 |
*/
|
9 |
abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
10 |
{
|
11 |
-
const DEFAULT_ROWS_LIMIT = 9999;
|
12 |
-
|
13 |
const UNIQUE_KEY = 'unique';
|
14 |
|
15 |
-
/**
|
16 |
-
* @var string List of advanced index fields prefix.
|
17 |
-
*/
|
18 |
-
protected $_advancedIndexFieldsPrefix = '#';
|
19 |
-
|
20 |
-
/**
|
21 |
-
* @var array List of advanced dynamic index fields.
|
22 |
-
*/
|
23 |
-
protected $_advancedDynamicIndexFields = array(
|
24 |
-
'#position_category_',
|
25 |
-
'#price_'
|
26 |
-
);
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @var object Search engine client.
|
30 |
-
*/
|
31 |
-
protected $_client;
|
32 |
-
|
33 |
-
/**
|
34 |
-
* @var array List of dates format.
|
35 |
-
*/
|
36 |
-
protected $_dateFormats = array();
|
37 |
-
|
38 |
/**
|
39 |
* @var array List of default query parameters.
|
40 |
*/
|
@@ -73,11 +48,6 @@ abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
|
73 |
'visibility'
|
74 |
);
|
75 |
|
76 |
-
/**
|
77 |
-
* @var bool Stores search engine availibility
|
78 |
-
*/
|
79 |
-
protected $_test = null;
|
80 |
-
|
81 |
/**
|
82 |
* @var array List of used fields.
|
83 |
*/
|
@@ -104,71 +74,6 @@ abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
|
104 |
return Mage::getSingleton('index/indexer');
|
105 |
}
|
106 |
|
107 |
-
/**
|
108 |
-
* Adds advanced index fields to index data.
|
109 |
-
*
|
110 |
-
* @param array $index
|
111 |
-
* @param int $storeId
|
112 |
-
* @param array $productIds
|
113 |
-
* @return array
|
114 |
-
*/
|
115 |
-
public function addAdvancedIndex($index, $storeId, $productIds = null)
|
116 |
-
{
|
117 |
-
return 1;
|
118 |
-
}
|
119 |
-
|
120 |
-
/**
|
121 |
-
* Checks if advanced index is allowed for current search engine.
|
122 |
-
*
|
123 |
-
* @return bool
|
124 |
-
*/
|
125 |
-
public function allowAdvancedIndex()
|
126 |
-
{
|
127 |
-
return false;
|
128 |
-
|
129 |
-
}
|
130 |
-
|
131 |
-
|
132 |
-
public function cleanIndex()
|
133 |
-
{
|
134 |
-
return $this;
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* Cleans cache.
|
139 |
-
*
|
140 |
-
* @return ChoiceAI_Search_Model_Resource_Engine_Abstract
|
141 |
-
*/
|
142 |
-
public function cleanCache()
|
143 |
-
{
|
144 |
-
return $this->_getIndexer()->getProcessByCode('catalogsearch_fulltext')->cleanCache();
|
145 |
-
|
146 |
-
}
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Returns product visibility ids for search.
|
153 |
-
*
|
154 |
-
* @see Mage_Catalog_Model_Product_Visibility
|
155 |
-
* @return mixed
|
156 |
-
*/
|
157 |
-
public function getAllowedVisibility()
|
158 |
-
{
|
159 |
-
return Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds();
|
160 |
-
}
|
161 |
-
|
162 |
-
/**
|
163 |
-
* Returns advanced index fields prefix.
|
164 |
-
*
|
165 |
-
* @return string
|
166 |
-
*/
|
167 |
-
public function getFieldsPrefix()
|
168 |
-
{
|
169 |
-
return $this->_advancedIndexFieldsPrefix;
|
170 |
-
}
|
171 |
-
|
172 |
/**
|
173 |
* Retrieves product ids for specified query.
|
174 |
*
|
@@ -183,7 +88,7 @@ abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
|
183 |
$params['fields'] = array('id');
|
184 |
$resultTmp = $this->search($query, $params, $type);
|
185 |
if (!empty($resultTmp['ids'])) {
|
186 |
-
foreach ($resultTmp['ids'] as $id) {
|
187 |
$ids[] = $id['uniqueId'];
|
188 |
}
|
189 |
}
|
@@ -192,7 +97,7 @@ abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
|
192 |
'total_count' => (isset($resultTmp['total_count'])) ? $resultTmp['total_count'] : null,
|
193 |
'faceted_data' => (isset($resultTmp['facets'])) ? $resultTmp['facets'] : array(),
|
194 |
'results' => array_key_exists('result', $resultTmp)?$resultTmp["result"]: array(),
|
195 |
-
|
196 |
);
|
197 |
|
198 |
return $result;
|
@@ -218,42 +123,10 @@ abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
|
218 |
return Mage::getResourceModel('choiceai_search/catalog_product_collection')->setEngine($this);
|
219 |
}
|
220 |
|
221 |
-
|
222 |
/**
|
223 |
-
*
|
224 |
*
|
225 |
-
*
|
226 |
-
*/
|
227 |
-
public function isLeyeredNavigationAllowed()
|
228 |
-
{
|
229 |
-
return $this->isLayeredNavigationAllowed();
|
230 |
-
}
|
231 |
-
|
232 |
-
/**
|
233 |
-
* Checks if layered navigation is available for current search engine.
|
234 |
-
*
|
235 |
-
* @return bool
|
236 |
-
*/
|
237 |
-
public function isLayeredNavigationAllowed()
|
238 |
-
{
|
239 |
-
return true;
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* Prepares index data.
|
244 |
-
* Should be overriden in child classes if needed.
|
245 |
-
*
|
246 |
-
* @param $index
|
247 |
-
* @param string $separator
|
248 |
-
* @return array
|
249 |
-
*/
|
250 |
-
public function prepareEntityIndex($index, $separator = null)
|
251 |
-
{
|
252 |
-
return $this->_getHelper()->prepareIndexData($index, $separator);
|
253 |
-
}
|
254 |
-
|
255 |
-
/**
|
256 |
-
* Performs search query and facetting.
|
257 |
*
|
258 |
* @param string $query
|
259 |
* @param array $params
|
@@ -278,46 +151,6 @@ abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
|
278 |
return array();
|
279 |
}
|
280 |
|
281 |
-
/**
|
282 |
-
* Checks search engine availability.
|
283 |
-
* Should be overriden by child classes.
|
284 |
-
*
|
285 |
-
* @return bool
|
286 |
-
*/
|
287 |
-
public function test()
|
288 |
-
{
|
289 |
-
return true;
|
290 |
-
}
|
291 |
-
|
292 |
-
/**
|
293 |
-
* Transforms specified date to basic YYYY-MM-dd format.
|
294 |
-
*
|
295 |
-
* @param int $storeId
|
296 |
-
* @param string $date
|
297 |
-
* @return null|string
|
298 |
-
*/
|
299 |
-
protected function _getDate($storeId, $date = null)
|
300 |
-
{
|
301 |
-
if (!isset($this->_dateFormats[$storeId])) {
|
302 |
-
$timezone = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $storeId);
|
303 |
-
$locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeId);
|
304 |
-
$locale = new Zend_Locale($locale);
|
305 |
-
|
306 |
-
$dateObj = new Zend_Date(null, null, $locale);
|
307 |
-
$dateObj->setTimezone($timezone);
|
308 |
-
$this->_dateFormats[$storeId] = array($dateObj, $locale->getTranslation(null, 'date', $locale));
|
309 |
-
}
|
310 |
-
|
311 |
-
if (is_empty_date($date)) {
|
312 |
-
return null;
|
313 |
-
}
|
314 |
-
|
315 |
-
list($dateObj, $localeDateFormat) = $this->_dateFormats[$storeId];
|
316 |
-
$dateObj->setDate($date, $localeDateFormat);
|
317 |
-
|
318 |
-
return $dateObj->toString('YYYY-MM-dd');
|
319 |
-
}
|
320 |
-
|
321 |
/**
|
322 |
* Returns search helper.
|
323 |
*
|
@@ -328,126 +161,4 @@ abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
|
328 |
return Mage::helper('choiceai_search');
|
329 |
}
|
330 |
|
331 |
-
/**
|
332 |
-
* Returns indexable attribute parameters.
|
333 |
-
*
|
334 |
-
* @return array
|
335 |
-
*/
|
336 |
-
protected function _getIndexableAttributeParams()
|
337 |
-
{
|
338 |
-
if (null === $this->_indexableAttributeParams) {
|
339 |
-
$this->_indexableAttributeParams = array();
|
340 |
-
$attributes = $this->_getHelper()->getSearchableAttributes();
|
341 |
-
foreach ($attributes as $attribute) {
|
342 |
-
/** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
|
343 |
-
$this->_indexableAttributeParams[$attribute->getAttributeCode()] = array(
|
344 |
-
'backend_type' => $attribute->getBackendType(),
|
345 |
-
'frontend_input' => $attribute->getFrontendInput(),
|
346 |
-
'search_weight' => $attribute->getSearchWeight(),
|
347 |
-
'is_searchable' => $attribute->getIsSearchable()
|
348 |
-
);
|
349 |
-
}
|
350 |
-
}
|
351 |
-
|
352 |
-
return $this->_getIndexer()->getProcessByCode('catalogsearch_fulltext')->_getIndexableAttributeParams();
|
353 |
-
}
|
354 |
-
|
355 |
-
/**
|
356 |
-
* Returns store locale code.
|
357 |
-
*
|
358 |
-
* @param int $storeId
|
359 |
-
* @return string
|
360 |
-
*/
|
361 |
-
protected function _getLocaleCode($storeId = null)
|
362 |
-
{
|
363 |
-
return $this->_getHelper()->getLocaleCode($storeId);
|
364 |
-
}
|
365 |
-
|
366 |
-
/**
|
367 |
-
* Transforms specified object to an array.
|
368 |
-
*
|
369 |
-
* @param $object
|
370 |
-
* @return array
|
371 |
-
*/
|
372 |
-
protected function _objectToArray($object)
|
373 |
-
{
|
374 |
-
if (!is_object($object) && !is_array($object)){
|
375 |
-
return $object;
|
376 |
-
}
|
377 |
-
if (is_object($object)){
|
378 |
-
$object = get_object_vars($object);
|
379 |
-
}
|
380 |
-
|
381 |
-
return array_map(array($this, '_objectToArray'), $object);
|
382 |
-
}
|
383 |
-
|
384 |
-
/**
|
385 |
-
* @param array $docsData
|
386 |
-
* @param string $type
|
387 |
-
* @param string $localeCode
|
388 |
-
* @return array
|
389 |
-
*/
|
390 |
-
protected function _prepareDocs($docsData, $type, $localeCode = null)
|
391 |
-
{
|
392 |
-
if (!is_array($docsData) || empty($docsData)) {
|
393 |
-
return array();
|
394 |
-
}
|
395 |
-
|
396 |
-
$docs = array();
|
397 |
-
foreach ($docsData as $entityId => $index) {
|
398 |
-
$index[self::UNIQUE_KEY] = $entityId . '|' . $index['store_id'];
|
399 |
-
$index['id'] = $entityId;
|
400 |
-
$index = $this->_prepareIndexData($index, $localeCode);
|
401 |
-
$docs[] = $this->_createDoc($entityId, $index, $type);
|
402 |
-
}
|
403 |
-
|
404 |
-
return $this->_getIndexer()->getProcessByCode('catalogsearch_fulltext')->_prepareDocs();
|
405 |
-
}
|
406 |
-
|
407 |
-
/**
|
408 |
-
* Prepares index data before indexation.
|
409 |
-
*
|
410 |
-
* @param array $data
|
411 |
-
* @param string $localeCode
|
412 |
-
* @return array
|
413 |
-
*/
|
414 |
-
protected function _prepareIndexData($data, $localeCode = null)
|
415 |
-
{
|
416 |
-
if (!is_array($data) || empty($data)) {
|
417 |
-
return array();
|
418 |
-
}
|
419 |
-
|
420 |
-
foreach ($data as $key => $value) {
|
421 |
-
if (in_array($key, $this->_usedFields)) {
|
422 |
-
continue;
|
423 |
-
} elseif ($key == 'options') {
|
424 |
-
unset($data[$key]);
|
425 |
-
continue;
|
426 |
-
}
|
427 |
-
$field = $this->_getHelper()->getAttributeFieldName($key, $localeCode);
|
428 |
-
$field = str_replace($this->_advancedIndexFieldsPrefix, '', $field);
|
429 |
-
if ($field != $key) {
|
430 |
-
$data[$field] = $value;
|
431 |
-
unset($data[$key]);
|
432 |
-
}
|
433 |
-
}
|
434 |
-
|
435 |
-
return $this->_getIndexer()->getProcessByCode('catalogsearch_fulltext')->_prepareIndexData();
|
436 |
-
}
|
437 |
-
|
438 |
-
/**
|
439 |
-
* Prepares query before search.
|
440 |
-
*
|
441 |
-
* @param mixed $query
|
442 |
-
* @return string
|
443 |
-
*/
|
444 |
-
protected function _prepareSearchConditions($query)
|
445 |
-
{
|
446 |
-
return $query;
|
447 |
-
}
|
448 |
-
|
449 |
-
public function saveEntityIndexes()
|
450 |
-
{
|
451 |
-
return $this;
|
452 |
-
}
|
453 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Search client.
|
4 |
*
|
5 |
* @package ChoiceAI_Search
|
6 |
* @copyright Copyright (c) MineWhat
|
8 |
*/
|
9 |
abstract class ChoiceAI_Search_Model_Resource_Engine_Abstract
|
10 |
{
|
|
|
|
|
11 |
const UNIQUE_KEY = 'unique';
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
/**
|
14 |
* @var array List of default query parameters.
|
15 |
*/
|
48 |
'visibility'
|
49 |
);
|
50 |
|
|
|
|
|
|
|
|
|
|
|
51 |
/**
|
52 |
* @var array List of used fields.
|
53 |
*/
|
74 |
return Mage::getSingleton('index/indexer');
|
75 |
}
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
/**
|
78 |
* Retrieves product ids for specified query.
|
79 |
*
|
88 |
$params['fields'] = array('id');
|
89 |
$resultTmp = $this->search($query, $params, $type);
|
90 |
if (!empty($resultTmp['ids'])) {
|
91 |
+
foreach ($resultTmp['ids'] as $id) {
|
92 |
$ids[] = $id['uniqueId'];
|
93 |
}
|
94 |
}
|
97 |
'total_count' => (isset($resultTmp['total_count'])) ? $resultTmp['total_count'] : null,
|
98 |
'faceted_data' => (isset($resultTmp['facets'])) ? $resultTmp['facets'] : array(),
|
99 |
'results' => array_key_exists('result', $resultTmp)?$resultTmp["result"]: array(),
|
100 |
+
'stats' => array_key_exists('stats', $resultTmp)?$resultTmp["stats"]: array()
|
101 |
);
|
102 |
|
103 |
return $result;
|
123 |
return Mage::getResourceModel('choiceai_search/catalog_product_collection')->setEngine($this);
|
124 |
}
|
125 |
|
|
|
126 |
/**
|
127 |
+
* Performs search query and facetting
|
128 |
*
|
129 |
+
* The main function that does the search!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
*
|
131 |
* @param string $query
|
132 |
* @param array $params
|
151 |
return array();
|
152 |
}
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
/**
|
155 |
* Returns search helper.
|
156 |
*
|
161 |
return Mage::helper('choiceai_search');
|
162 |
}
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
}
|
app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch.php
CHANGED
@@ -19,7 +19,7 @@ class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Sear
|
|
19 |
$this->client = Mage::getResourceSingleton('choiceai_search/engine_choiceaisearch_client');
|
20 |
}
|
21 |
|
22 |
-
|
23 |
$result = array();
|
24 |
foreach ($response as $facetName=>$facetlist) {
|
25 |
if($facetlist["type"]=='facet_fields'){
|
@@ -48,14 +48,12 @@ class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Sear
|
|
48 |
}
|
49 |
}
|
50 |
return $result;
|
51 |
-
|
52 |
}
|
53 |
|
54 |
/**
|
55 |
-
* prepares the facet
|
56 |
*/
|
57 |
public function _prepareFacetsConditions($facets = array()){
|
58 |
-
|
59 |
$stringFacets = array();
|
60 |
$rangeFacets = array();
|
61 |
if(is_array($facets)){
|
@@ -63,20 +61,20 @@ class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Sear
|
|
63 |
if(is_array($facetValue) && $facetValue != null && is_array($facetValue) && sizeof($facetValue) > 0 ){
|
64 |
if(isset($facetValue['from']) && isset($facetValue["to"])){
|
65 |
$facetValues= array();
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
$facetValues['from'] = $eachFacetValue['from'];
|
74 |
$facetValues['to'] = $eachFacetValue['to'];
|
75 |
$stringFacets[$facetKey][] = $facetValues;
|
76 |
} else {
|
77 |
$stringFacets[$facetKey] = $facetValue;
|
78 |
}
|
79 |
-
}
|
80 |
}
|
81 |
}
|
82 |
$facets=array();
|
@@ -84,29 +82,18 @@ class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Sear
|
|
84 |
$facets["range"] = $rangeFacets;
|
85 |
return $facets;
|
86 |
}
|
87 |
-
|
88 |
-
function str_lreplace($search, $replace, $subject)
|
89 |
-
{
|
90 |
-
$pos = strrpos($subject, $search);
|
91 |
-
|
92 |
-
if($pos !== false) {
|
93 |
-
$subject = substr_replace($subject, $replace, $pos, strlen($search));
|
94 |
-
}
|
95 |
-
return $subject;
|
96 |
-
}
|
97 |
|
98 |
protected function _prepareResponse($data){
|
99 |
-
|
100 |
/* @var $response ChoiceAI_ResultSet */
|
101 |
-
if (!$data instanceof ChoiceAI_ResultSet
|
102 |
return array();
|
103 |
-
}
|
104 |
|
105 |
$result = array();
|
106 |
|
107 |
-
foreach ($data->getResults() as $doc) {
|
108 |
-
|
109 |
-
}
|
110 |
return $result;
|
111 |
}
|
112 |
|
@@ -134,11 +121,8 @@ class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Sear
|
|
134 |
if($sortKey != "position" && $sortKey != "relevance"){
|
135 |
if($sortValue == 'asc'){
|
136 |
$sort[$sortKey] = 1;
|
137 |
-
|
138 |
}else{
|
139 |
-
|
140 |
$sort[$sortKey] = -1;
|
141 |
-
|
142 |
}
|
143 |
}
|
144 |
}
|
@@ -160,29 +144,33 @@ class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Sear
|
|
160 |
* @param $params
|
161 |
* @return int|mixed
|
162 |
*/
|
163 |
-
protected function _prepareLimit($params)
|
164 |
-
|
165 |
-
$limitOnSession = Mage::getSingleton('catalog/session')->getLimitPage();
|
166 |
-
if($limitOnSession === "all" || $limitInRequest === "all") {
|
167 |
-
$limitOnSession = 100;
|
168 |
-
}
|
169 |
-
$limit = ($limitInRequest > 0)? (int) $limitInRequest:($limitOnSession > 0? $limitOnSession: ((isset($_GET['mode']) && $_GET['mode'] == 'list')?Mage::getStoreConfig('catalog/frontend/list_per_page'): Mage::getStoreConfig('catalog/frontend/grid_per_page')));
|
170 |
if(array_key_exists("limit", $params)) {
|
171 |
$limit = (int)$params["limit"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
}
|
173 |
-
return $limit;
|
174 |
|
|
|
175 |
}
|
176 |
|
177 |
/**
|
178 |
-
* Performs search and facetting
|
|
|
|
|
179 |
*
|
180 |
* @param string $query
|
181 |
* @param array $params
|
182 |
* @param string $type
|
183 |
* @return array
|
184 |
*/
|
185 |
-
protected function _search($qt, $params = array(), $type = 'product')
|
186 |
{
|
187 |
$multiselectValue = Mage::getConfig()->getNode('default/choiceai/general/multiselect_facet');
|
188 |
$multiselectValue = (!is_null($multiselectValue) &&
|
@@ -196,47 +184,89 @@ class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Sear
|
|
196 |
|
197 |
$facets = $this->_prepareFacetsConditions($params['filters']);
|
198 |
$searchParams = array();
|
199 |
-
$query = Mage::helper('catalogsearch')->getQueryText();
|
200 |
|
201 |
if(isset($query) && $query != ''){
|
202 |
-
$this->client = $this->client->setRuleset('search')->setQuery($query)->setFilters($facets['attribute']);
|
203 |
}else{
|
204 |
$this->client = $this->client->setRuleset('browse')->setCategoryId($params['category'])->setFilters($facets['attribute']);
|
205 |
}
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
->setDebug(false)
|
215 |
->setSort($this->_prepareSortFields(array_key_exists('sort_by', $params)?$params['sort_by']:array()))
|
216 |
-
->search();
|
217 |
if (!$data instanceof ChoiceAI_ResultSet) {
|
218 |
return array();
|
219 |
-
}
|
220 |
-
|
221 |
-
if($data->getSpellCheckQuery()) {
|
222 |
-
Mage::unregister('spellcheckQuery');
|
223 |
-
Mage::register('spellcheckQuery', $data->getSpellCheckQuery());
|
224 |
}
|
225 |
|
226 |
-
|
227 |
-
|
|
|
|
|
|
|
|
|
228 |
|
|
|
229 |
$result = array(
|
230 |
'total_count' => $data->getTotalHits(),
|
231 |
-
'result'=> $this->_prepareResponse($data),
|
232 |
-
'stats'
|
233 |
);
|
234 |
$result['facets'] = $this->_prepareFacetsQueryResponse($data->getFacets());
|
|
|
235 |
Mage::unregister('start');
|
236 |
-
Mage::register('start', $page* Mage::getStoreConfig('catalog/frontend/grid_per_page'));
|
237 |
return $result;
|
238 |
-
}
|
239 |
|
240 |
}
|
241 |
|
242 |
-
?>
|
19 |
$this->client = Mage::getResourceSingleton('choiceai_search/engine_choiceaisearch_client');
|
20 |
}
|
21 |
|
22 |
+
function _prepareFacetsQueryResponse($response = array()){
|
23 |
$result = array();
|
24 |
foreach ($response as $facetName=>$facetlist) {
|
25 |
if($facetlist["type"]=='facet_fields'){
|
48 |
}
|
49 |
}
|
50 |
return $result;
|
|
|
51 |
}
|
52 |
|
53 |
/**
|
54 |
+
* prepares the facet condition
|
55 |
*/
|
56 |
public function _prepareFacetsConditions($facets = array()){
|
|
|
57 |
$stringFacets = array();
|
58 |
$rangeFacets = array();
|
59 |
if(is_array($facets)){
|
61 |
if(is_array($facetValue) && $facetValue != null && is_array($facetValue) && sizeof($facetValue) > 0 ){
|
62 |
if(isset($facetValue['from']) && isset($facetValue["to"])){
|
63 |
$facetValues= array();
|
64 |
+
$eachFacetValue= $facetValue;
|
65 |
+
if(!isset($eachFacetValue['from']) || $eachFacetValue['from'] == "" ){
|
66 |
+
$eachFacetValue['from'] = '0';
|
67 |
+
}
|
68 |
+
if(!isset($eachFacetValue['to']) || $eachFacetValue['to'] == "" ){
|
69 |
+
$eachFacetValue['to'] = '*';
|
70 |
+
}
|
71 |
$facetValues['from'] = $eachFacetValue['from'];
|
72 |
$facetValues['to'] = $eachFacetValue['to'];
|
73 |
$stringFacets[$facetKey][] = $facetValues;
|
74 |
} else {
|
75 |
$stringFacets[$facetKey] = $facetValue;
|
76 |
}
|
77 |
+
}
|
78 |
}
|
79 |
}
|
80 |
$facets=array();
|
82 |
$facets["range"] = $rangeFacets;
|
83 |
return $facets;
|
84 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
protected function _prepareResponse($data){
|
|
|
87 |
/* @var $response ChoiceAI_ResultSet */
|
88 |
+
if (!$data instanceof ChoiceAI_ResultSet || $data->getTotalHits()<=0) {
|
89 |
return array();
|
90 |
+
}
|
91 |
|
92 |
$result = array();
|
93 |
|
94 |
+
foreach ($data->getResults() as $doc) {
|
95 |
+
$result[] =$doc->getHit();
|
96 |
+
}
|
97 |
return $result;
|
98 |
}
|
99 |
|
121 |
if($sortKey != "position" && $sortKey != "relevance"){
|
122 |
if($sortValue == 'asc'){
|
123 |
$sort[$sortKey] = 1;
|
|
|
124 |
}else{
|
|
|
125 |
$sort[$sortKey] = -1;
|
|
|
126 |
}
|
127 |
}
|
128 |
}
|
144 |
* @param $params
|
145 |
* @return int|mixed
|
146 |
*/
|
147 |
+
protected function _prepareLimit($params)
|
148 |
+
{
|
|
|
|
|
|
|
|
|
|
|
149 |
if(array_key_exists("limit", $params)) {
|
150 |
$limit = (int)$params["limit"];
|
151 |
+
}else{
|
152 |
+
$limitInRequest = array_key_exists('limit', $_GET) ? $_GET['limit'] : null;
|
153 |
+
$limitOnSession = Mage::getSingleton('catalog/session')->getLimitPage();
|
154 |
+
if ($limitOnSession === "all" || $limitInRequest === "all") {
|
155 |
+
$limitOnSession = 100;
|
156 |
+
}
|
157 |
+
$limit = ($limitInRequest > 0) ? (int)$limitInRequest : ($limitOnSession > 0 ? $limitOnSession : ((isset($_GET['mode']) && $_GET['mode'] == 'list') ? Mage::getStoreConfig('catalog/frontend/list_per_page') : Mage::getStoreConfig('catalog/frontend/grid_per_page')));
|
158 |
}
|
|
|
159 |
|
160 |
+
return $limit;
|
161 |
}
|
162 |
|
163 |
/**
|
164 |
+
* Performs search and facetting
|
165 |
+
*
|
166 |
+
* Note: Called from app/code/local/ChoiceAI/Search/Model/Resource/Engine/Abstract.php's search function
|
167 |
*
|
168 |
* @param string $query
|
169 |
* @param array $params
|
170 |
* @param string $type
|
171 |
* @return array
|
172 |
*/
|
173 |
+
protected function _search($qt, $params = array(), $type = 'product')
|
174 |
{
|
175 |
$multiselectValue = Mage::getConfig()->getNode('default/choiceai/general/multiselect_facet');
|
176 |
$multiselectValue = (!is_null($multiselectValue) &&
|
184 |
|
185 |
$facets = $this->_prepareFacetsConditions($params['filters']);
|
186 |
$searchParams = array();
|
187 |
+
$query = Mage::helper('catalogsearch')->getQueryText();
|
188 |
|
189 |
if(isset($query) && $query != ''){
|
190 |
+
$this->client = $this->client->setRuleset('search')->setQuery($query)->setFilters($facets['attribute']);
|
191 |
}else{
|
192 |
$this->client = $this->client->setRuleset('browse')->setCategoryId($params['category'])->setFilters($facets['attribute']);
|
193 |
}
|
194 |
+
|
195 |
+
// @TODO: Confirm this, till "?" only right?
|
196 |
+
$urlPath = explode("?", $_SERVER['REQUEST_URI'])[0];
|
197 |
+
|
198 |
+
$paramsString = isset($_SERVER['REDIRECT_QUERY_STRING']) ? $_SERVER['REDIRECT_QUERY_STRING'] : '';
|
199 |
+
|
200 |
+
$getParamsToSend = array(
|
201 |
+
'v'=> 3,
|
202 |
+
'url' => $urlPath
|
203 |
+
);
|
204 |
+
|
205 |
+
// Checking if the following params are available in GET, if yes, we will forward them just as they are
|
206 |
+
$pairs = [
|
207 |
+
'site'=> 'mwc',
|
208 |
+
'expId'=> 'expId',
|
209 |
+
'variantId'=> 'variantId',
|
210 |
+
'mwpreview'=> 'mwpreview',
|
211 |
+
'mwforce'=> 'mwforce',
|
212 |
+
'mwdevice'=> 'mwdevice',
|
213 |
+
'layout'=> 'layout',
|
214 |
+
'uitype'=> 'uitype',
|
215 |
+
'expforce'=> 'expforce',
|
216 |
+
'lrp'=>'lrp',
|
217 |
+
'llp'=>'llp',
|
218 |
+
'catPaths'=> 'catPaths',
|
219 |
+
'tagsList'=> 'tagsList'
|
220 |
+
];
|
221 |
+
|
222 |
+
foreach ($pairs as $getParam => $paramNameForSending) {
|
223 |
+
if (isset($_GET[$getParam]))
|
224 |
+
$getParamsToSend[$paramNameForSending] = $_GET[$getParam];
|
225 |
+
}
|
226 |
+
|
227 |
+
|
228 |
+
if(trim($paramsString) != '')
|
229 |
+
$getParamsToSend['p'] = $paramsString;
|
230 |
+
|
231 |
+
if(isset($_SERVER['HTTP_REFERER']))
|
232 |
+
$getParamsToSend['r'] = $_SERVER['HTTP_REFERER'];
|
233 |
+
|
234 |
+
if(isset($_COOKIE['caicookie']))
|
235 |
+
$getParamsToSend['u'] = $_COOKIE['caicookie'];
|
236 |
+
|
237 |
+
|
238 |
+
// Calls Client.php in lib
|
239 |
+
$data = $this->client
|
240 |
+
->setOffset($page)
|
241 |
+
->setLimit($limit)
|
242 |
+
->setOtherOptions($getParamsToSend)
|
243 |
->setDebug(false)
|
244 |
->setSort($this->_prepareSortFields(array_key_exists('sort_by', $params)?$params['sort_by']:array()))
|
245 |
+
->search();
|
246 |
if (!$data instanceof ChoiceAI_ResultSet) {
|
247 |
return array();
|
|
|
|
|
|
|
|
|
|
|
248 |
}
|
249 |
|
250 |
+
// if($data->getSpellCheckQuery()) {
|
251 |
+
// // Not being read anywhere, so why setting it?
|
252 |
+
// Mage::unregister('spellcheckQuery');
|
253 |
+
// Mage::register('spellcheckQuery', $data->getSpellCheckQuery());
|
254 |
+
// }
|
255 |
+
|
256 |
|
257 |
+
/* @var $data ChoiceAI_ResultSet */
|
258 |
$result = array(
|
259 |
'total_count' => $data->getTotalHits(),
|
260 |
+
'result' => $this->_prepareResponse($data),
|
261 |
+
'stats' => $this->getStats($data)
|
262 |
);
|
263 |
$result['facets'] = $this->_prepareFacetsQueryResponse($data->getFacets());
|
264 |
+
// Seems unused
|
265 |
Mage::unregister('start');
|
266 |
+
Mage::register('start', $page* Mage::getStoreConfig('catalog/frontend/grid_per_page'));
|
267 |
return $result;
|
268 |
+
}
|
269 |
|
270 |
}
|
271 |
|
272 |
+
?>
|
app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch/Client.php
CHANGED
@@ -16,14 +16,12 @@ class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch_Client extends Choice
|
|
16 |
$config = $this->_getHelper()->getEngineConfigData();
|
17 |
$config['context'] = Mage::getStoreConfig(self::CONFIG_API_KEY);
|
18 |
parent::__construct($config);
|
19 |
-
|
20 |
}
|
21 |
|
22 |
protected function _getHelper()
|
23 |
{
|
24 |
return Mage::helper('choiceai_search/choiceaisearch');
|
25 |
}
|
26 |
-
|
27 |
-
|
28 |
}
|
29 |
?>
|
16 |
$config = $this->_getHelper()->getEngineConfigData();
|
17 |
$config['context'] = Mage::getStoreConfig(self::CONFIG_API_KEY);
|
18 |
parent::__construct($config);
|
|
|
19 |
}
|
20 |
|
21 |
protected function _getHelper()
|
22 |
{
|
23 |
return Mage::helper('choiceai_search/choiceaisearch');
|
24 |
}
|
25 |
+
|
|
|
26 |
}
|
27 |
?>
|
app/code/local/ChoiceAI/Search/etc/config.xml
CHANGED
@@ -18,6 +18,7 @@
|
|
18 |
<rewrite>
|
19 |
<config>ChoiceAI_Search_Model_Catalog_Config</config>
|
20 |
<category>ChoiceAI_Search_Model_Catalog_Category</category>
|
|
|
21 |
</rewrite>
|
22 |
</catalog>
|
23 |
</models>
|
@@ -25,11 +26,11 @@
|
|
25 |
<choiceai_search>
|
26 |
<class>ChoiceAI_Search_Helper</class>
|
27 |
</choiceai_search>
|
28 |
-
<
|
29 |
<rewrite>
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
</helpers>
|
34 |
<blocks>
|
35 |
<choiceai_search>
|
@@ -54,48 +55,5 @@
|
|
54 |
</rewrite>
|
55 |
</enterprise_search>
|
56 |
</blocks>
|
57 |
-
<resources>
|
58 |
-
<choiceai_search_setup>
|
59 |
-
<setup>
|
60 |
-
<module>ChoiceAI_Search</module>
|
61 |
-
<class>Mage_Core_Model_Resource_Setup</class>
|
62 |
-
</setup>
|
63 |
-
</choiceai_search_setup>
|
64 |
-
</resources>
|
65 |
</global>
|
66 |
-
<default>
|
67 |
-
<catalog>
|
68 |
-
<search>
|
69 |
-
<choiceai_ruleset>search</choiceai_ruleset>
|
70 |
-
<choiceai_timeout>300</choiceai_timeout>
|
71 |
-
</search>
|
72 |
-
</catalog>
|
73 |
-
<choiceai>
|
74 |
-
<general>
|
75 |
-
<multiselect_facet>true</multiselect_facet>
|
76 |
-
<autosuggest_status>false</autosuggest_status>
|
77 |
-
<autosuggest_skin>#ff8400</autosuggest_skin>
|
78 |
-
<autosuggest_template>1column</autosuggest_template>
|
79 |
-
<autosuggest_max_suggestion>12</autosuggest_max_suggestion>
|
80 |
-
<autosuggest_top_queries_status>false</autosuggest_top_queries_status>
|
81 |
-
<autosuggest_keyword_status>true</autosuggest_keyword_status>
|
82 |
-
<autosuggest_search_scope_status>true</autosuggest_search_scope_status>
|
83 |
-
<autosuggest_max_products>2</autosuggest_max_products>
|
84 |
-
<autosuggest_product_header>Popular Products</autosuggest_product_header>
|
85 |
-
<autosuggest_keyword_header></autosuggest_keyword_header>
|
86 |
-
<autosuggest_search_scope_header></autosuggest_search_scope_header>
|
87 |
-
<autosuggest_show_cart>false</autosuggest_show_cart>
|
88 |
-
<autosuggest_sidecontent>right</autosuggest_sidecontent>
|
89 |
-
<autosuggest_topquery_header></autosuggest_topquery_header>
|
90 |
-
<autosuggest_keyword_header></autosuggest_keyword_header>
|
91 |
-
<autosuggest_search_scope_header></autosuggest_search_scope_header>
|
92 |
-
<autosuggest_pop_product_header>Popular Products</autosuggest_pop_product_header>
|
93 |
-
<search_mod_status>false</search_mod_status>
|
94 |
-
<search_mod_power>search</search_mod_power>
|
95 |
-
<search_hosted_status>false</search_hosted_status>
|
96 |
-
<search_hosted_int_status>false</search_hosted_int_status>
|
97 |
-
<search_hosted_redirect_url></search_hosted_redirect_url>
|
98 |
-
</general>
|
99 |
-
</choiceai>
|
100 |
-
</default>
|
101 |
</config>
|
18 |
<rewrite>
|
19 |
<config>ChoiceAI_Search_Model_Catalog_Config</config>
|
20 |
<category>ChoiceAI_Search_Model_Catalog_Category</category>
|
21 |
+
<product_url>ChoiceAI_Search_Model_Catalog_Product_Url</product_url>
|
22 |
</rewrite>
|
23 |
</catalog>
|
24 |
</models>
|
26 |
<choiceai_search>
|
27 |
<class>ChoiceAI_Search_Helper</class>
|
28 |
</choiceai_search>
|
29 |
+
<configurableswatches>
|
30 |
<rewrite>
|
31 |
+
<productimg>ChoiceAI_Search_Helper_Productimg</productimg>
|
32 |
+
</rewrite>
|
33 |
+
</configurableswatches>
|
34 |
</helpers>
|
35 |
<blocks>
|
36 |
<choiceai_search>
|
55 |
</rewrite>
|
56 |
</enterprise_search>
|
57 |
</blocks>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
</global>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
</config>
|
app/code/local/ChoiceAI/Searchcore/Helper/Confighelper.php
DELETED
@@ -1,472 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
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_Searchcore_Helper_Confighelper extends ChoiceAI_Searchcore_Helper_Data
|
9 |
-
{
|
10 |
-
|
11 |
-
const SITE_KEY = "site_key";
|
12 |
-
|
13 |
-
const API_KEY = "api_key";
|
14 |
-
|
15 |
-
const SECRET_KEY = "secret_key";
|
16 |
-
|
17 |
-
const USERNAME = "username";
|
18 |
-
|
19 |
-
const NEED_FEATURE_FIELD_UPDATION = "need_feature_field_updation";
|
20 |
-
|
21 |
-
const IS_CRON_ENABLED = "cron_enabled";
|
22 |
-
|
23 |
-
const SUBJECT = 'subject';
|
24 |
-
|
25 |
-
const CONTENT = 'content';
|
26 |
-
|
27 |
-
const CC = 'cc';
|
28 |
-
|
29 |
-
|
30 |
-
/**
|
31 |
-
* All possible data type values supported choiceai
|
32 |
-
* @var array
|
33 |
-
*/
|
34 |
-
public static $data_types = array("text", "longText", "link", "decimal", "number", "datetime");
|
35 |
-
|
36 |
-
public function validateAndSaveKeys($website, $requestBody)
|
37 |
-
{
|
38 |
-
$errors = $this->validateKeyParams($requestBody);
|
39 |
-
if (sizeof($errors) > 0) {
|
40 |
-
return $errors;
|
41 |
-
}
|
42 |
-
$requestParams = json_decode($requestBody, true);
|
43 |
-
if (!$requestParams) {
|
44 |
-
$errors['message'] = 'Invalid Request';
|
45 |
-
return $errors;
|
46 |
-
}
|
47 |
-
$response = Mage::getModel("choiceai_searchcore/api_task_validatekeys")
|
48 |
-
->setData(ChoiceAI_Searchcore_Model_Api_Task_Validatekeys::SECRET_KEY, $requestParams[self::SECRET_KEY])
|
49 |
-
->setData(ChoiceAI_Searchcore_Model_Api_Task_Validatekeys::SITE_KEY, $requestParams[self::SITE_KEY])
|
50 |
-
->prepare($website)
|
51 |
-
->process();
|
52 |
-
if (!$response->isSuccess()) {
|
53 |
-
return $response->getErrors();
|
54 |
-
}
|
55 |
-
|
56 |
-
$existingSecretKey = Mage::getResourceModel('choiceai_searchcore/config')
|
57 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Constants::SECRET_KEY);
|
58 |
-
$keyAlreadyExists = !is_null($existingSecretKey);
|
59 |
-
if ($keyAlreadyExists) {
|
60 |
-
$this->flushConfigs($website);
|
61 |
-
}
|
62 |
-
|
63 |
-
Mage::getResourceModel('choiceai_searchcore/config')
|
64 |
-
->setValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Constants::SECRET_KEY,
|
65 |
-
$requestParams[ChoiceAI_Searchcore_Helper_Constants::SECRET_KEY]);
|
66 |
-
Mage::getResourceModel('choiceai_searchcore/config')
|
67 |
-
->setValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Constants::SITE_KEY,
|
68 |
-
$requestParams[ChoiceAI_Searchcore_Helper_Constants::SITE_KEY]);
|
69 |
-
$response = $response->getResponse();
|
70 |
-
Mage::getResourceModel('choiceai_searchcore/config')
|
71 |
-
->setValue($website->getWebsiteId(),
|
72 |
-
ChoiceAI_Searchcore_Helper_Constants::API_KEY,
|
73 |
-
$response[ChoiceAI_Searchcore_Model_Api_Task_Validatekeys::API_KEY]);
|
74 |
-
Mage::getResourceModel('choiceai_searchcore/config')
|
75 |
-
->setValue($website->getWebsiteId(),
|
76 |
-
ChoiceAI_Searchcore_Helper_Constants::USERNAME,
|
77 |
-
$response[ChoiceAI_Searchcore_Model_Api_Task_Validatekeys::USERNAME]);
|
78 |
-
$this->saveConfig(Mage::app()->getWebsite(),
|
79 |
-
array(ChoiceAI_Searchcore_Helper_Constants::API_KEY => $response[ChoiceAI_Searchcore_Model_Api_Task_Validatekeys::API_KEY],
|
80 |
-
ChoiceAI_Searchcore_Helper_Constants::SITE_KEY => $requestParams[ChoiceAI_Searchcore_Helper_Constants::SITE_KEY]));
|
81 |
-
return $errors;
|
82 |
-
}
|
83 |
-
|
84 |
-
public function flushConfigs($website)
|
85 |
-
{
|
86 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::DEBUG, 'Flushing all the configs');
|
87 |
-
$configs = $this->getEngineConfigData('', $website, true);
|
88 |
-
foreach ($configs as $config => $value) {
|
89 |
-
Mage::getConfig()->deleteConfig(ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX .
|
90 |
-
ChoiceAI_Searchcore_Helper_Constants::CONFIG_SEPARATOR .
|
91 |
-
$config,
|
92 |
-
'websites',
|
93 |
-
(int)$website->getWebsiteId());
|
94 |
-
}
|
95 |
-
Mage::getResourceModel('choiceai_searchcore/config')->deleteAll($website->getWebsiteId());
|
96 |
-
|
97 |
-
}
|
98 |
-
|
99 |
-
public function validateKeyParams($requestBody)
|
100 |
-
{
|
101 |
-
$errors = array();
|
102 |
-
$requestParams = json_decode($requestBody, true);
|
103 |
-
if (!$requestParams) {
|
104 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'Invalid request with requestBody' . $requestBody);
|
105 |
-
$errors['message'] = 'Invalid Request';
|
106 |
-
return $errors;
|
107 |
-
}
|
108 |
-
if (!array_key_exists(ChoiceAI_Searchcore_Helper_Constants::SECRET_KEY, $requestParams)) {
|
109 |
-
$errors[ChoiceAI_Searchcore_Helper_Constants::SECRET_KEY] = "Has Empty Data";
|
110 |
-
}
|
111 |
-
if (!array_key_exists(ChoiceAI_Searchcore_Helper_Constants::SITE_KEY, $requestParams)) {
|
112 |
-
$errors[ChoiceAI_Searchcore_Helper_Constants::SITE_KEY] = "Has Empty Data";
|
113 |
-
}
|
114 |
-
return $errors;
|
115 |
-
}
|
116 |
-
|
117 |
-
public function getFeatureFields()
|
118 |
-
{
|
119 |
-
return ChoiceAI_Searchcore_Model_Field::$feature_fields;
|
120 |
-
}
|
121 |
-
|
122 |
-
public function getAllAttributes($fieldNameAsKey = false)
|
123 |
-
{
|
124 |
-
$attributes = Mage::getSingleton('eav/config')
|
125 |
-
->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
|
126 |
-
$fields = array();
|
127 |
-
foreach ($attributes as $attribute) {
|
128 |
-
$attributeType = $attribute->getFrontendInput();
|
129 |
-
$fieldType = $attributeType == 'media_image' ? ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_IMAGE :
|
130 |
-
($attributeType == 'price' ? ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_NUMBER :
|
131 |
-
($attributeType == 'date' ? ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_DATE :
|
132 |
-
ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_STRING));
|
133 |
-
$fieldType = ($attribute->getName() == "created_at") ? ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_DATE : $fieldType;
|
134 |
-
$fieldType = ($attribute->getName() == "updated_at") ? ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_DATE : $fieldType;
|
135 |
-
if ($fieldNameAsKey) {
|
136 |
-
$fields[$attribute->getName()] = array(ChoiceAI_Searchcore_Helper_Constants::FIELD_NAME => $attribute->getName(),
|
137 |
-
ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE => $fieldType);
|
138 |
-
} else {
|
139 |
-
$fields[] = array(ChoiceAI_Searchcore_Helper_Constants::FIELD_NAME => $attribute->getName(),
|
140 |
-
ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE => $fieldType);
|
141 |
-
}
|
142 |
-
}
|
143 |
-
if ($fieldNameAsKey) {
|
144 |
-
$fields['final_price'] = array(ChoiceAI_Searchcore_Helper_Constants::FIELD_NAME => "final_price",
|
145 |
-
ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE => ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_NUMBER);
|
146 |
-
$fields['type_id'] = array(ChoiceAI_Searchcore_Helper_Constants::FIELD_NAME => "type_id",
|
147 |
-
ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE => ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_STRING);
|
148 |
-
} else {
|
149 |
-
$fields[] = array(ChoiceAI_Searchcore_Helper_Constants::FIELD_NAME => "final_price",
|
150 |
-
ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE => ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_NUMBER);
|
151 |
-
$fields[] = array(ChoiceAI_Searchcore_Helper_Constants::FIELD_NAME => "type_id",
|
152 |
-
ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE => ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_STRING);
|
153 |
-
}
|
154 |
-
return $fields;
|
155 |
-
}
|
156 |
-
|
157 |
-
private function getFieldMapping($fields)
|
158 |
-
{
|
159 |
-
$fieldMapping = array();
|
160 |
-
foreach ($fields as $field) {
|
161 |
-
$fieldMapping[$field->getFieldName()] = $field;
|
162 |
-
}
|
163 |
-
return $fieldMapping;
|
164 |
-
}
|
165 |
-
|
166 |
-
/**
|
167 |
-
* @param $fields
|
168 |
-
* @return array
|
169 |
-
*/
|
170 |
-
private function validate($fields)
|
171 |
-
{
|
172 |
-
$errors = array();
|
173 |
-
if (!is_array($fields)) {
|
174 |
-
$errors["message"] = "Expecting theInput data should be an array, Given " . gettype($fields);
|
175 |
-
return $errors;
|
176 |
-
}
|
177 |
-
$existingAttributes = $this->getAllAttributes(true);
|
178 |
-
$featureFields = Mage::getModel('choiceai_searchcore/field')->getFeaturedFields();
|
179 |
-
foreach ($fields as $field) {
|
180 |
-
if (!array_key_exists(ChoiceAI_Searchcore_Model_Field::field_name, $field)) {
|
181 |
-
$errors["extra"] = "Not Present for all the fields";
|
182 |
-
continue;
|
183 |
-
} else if (is_null($field[ChoiceAI_Searchcore_Model_Field::field_name]) ||
|
184 |
-
$field[ChoiceAI_Searchcore_Model_Field::field_name] == ""
|
185 |
-
) {
|
186 |
-
$errors["extra"] = "field Name is empty for some fields";
|
187 |
-
continue;
|
188 |
-
}
|
189 |
-
if (!array_key_exists(ChoiceAI_Searchcore_Model_Field::datatype, $field)) {
|
190 |
-
$errors[$field[ChoiceAI_Searchcore_Model_Field::field_name]] = "Not Present for all the fields";
|
191 |
-
} else if (!in_array($field[ChoiceAI_Searchcore_Model_Field::datatype], ChoiceAI_Searchcore_Model_Field::$data_types)) {
|
192 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'Invalid feature field ' .
|
193 |
-
$field[ChoiceAI_Searchcore_Model_Field::datatype]);
|
194 |
-
$errors[$field[ChoiceAI_Searchcore_Model_Field::field_name]] = "Invalid datatype specified";
|
195 |
-
}
|
196 |
-
|
197 |
-
if (array_key_exists($field[ChoiceAI_Searchcore_Model_Field::field_name], $existingAttributes)) {
|
198 |
-
if (!Mage::getSingleton('choiceai_searchcore/field')->validateDatatype($field[ChoiceAI_Searchcore_Model_Field::datatype], $existingAttributes[$field[ChoiceAI_Searchcore_Model_Field::field_name]][ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE])) {
|
199 |
-
$errors[$field[ChoiceAI_Searchcore_Model_Field::field_name]] = "Field cannot be mapped to " . $field[ChoiceAI_Searchcore_Model_Field::datatype];
|
200 |
-
}
|
201 |
-
}
|
202 |
-
|
203 |
-
if (array_key_exists(ChoiceAI_Searchcore_Model_Field::featured_field, $field)) {
|
204 |
-
if (!array_key_exists($field[ChoiceAI_Searchcore_Model_Field::featured_field], $featureFields)) {
|
205 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'Invalid feature field ' .
|
206 |
-
$field[ChoiceAI_Searchcore_Model_Field::featured_field]);
|
207 |
-
$errors[$field[ChoiceAI_Searchcore_Model_Field::field_name]] = "Invalid feature field specified";
|
208 |
-
} else if (!Mage::getSingleton('choiceai_searchcore/field')->validateDatatype($featureFields[$field[ChoiceAI_Searchcore_Model_Field::featured_field]]["datatype"], $existingAttributes[$field[ChoiceAI_Searchcore_Model_Field::field_name]][ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE])) {
|
209 |
-
$errors[$field[ChoiceAI_Searchcore_Model_Field::field_name]] = "Field cannot be mapped to " . $field[ChoiceAI_Searchcore_Model_Field::datatype];
|
210 |
-
}
|
211 |
-
}
|
212 |
-
}
|
213 |
-
return $errors;
|
214 |
-
}
|
215 |
-
|
216 |
-
public function deleteFields($fields, $website)
|
217 |
-
{
|
218 |
-
$errors = $this->validate($fields);
|
219 |
-
if (sizeof($errors) != 0) {
|
220 |
-
return $errors;
|
221 |
-
}
|
222 |
-
$collection = $this->buildFieldCollection($fields, $website);
|
223 |
-
return Mage::getModel("choiceai_searchcore/field")->saveFields($collection);
|
224 |
-
}
|
225 |
-
|
226 |
-
/**
|
227 |
-
* @param $fields
|
228 |
-
* @param $website
|
229 |
-
* @return array
|
230 |
-
*/
|
231 |
-
public function saveFields($fields, $website)
|
232 |
-
{
|
233 |
-
$errors = $this->validate($fields);
|
234 |
-
if (sizeof($errors) != 0) {
|
235 |
-
return $errors;
|
236 |
-
}
|
237 |
-
$collection = $this->buildFieldCollectionToAdd($fields, $website);
|
238 |
-
$response = Mage::getModel("choiceai_searchcore/field")->saveFields($collection);
|
239 |
-
if (!is_array($response) && $response === true) {
|
240 |
-
Mage::getSingleton('choiceai_searchcore/field')->rebuildConfigCache($website);
|
241 |
-
$this->triggerUpdateFeatureField($website);
|
242 |
-
}
|
243 |
-
}
|
244 |
-
|
245 |
-
|
246 |
-
public function triggerUpdateFeatureField(Mage_Core_Model_Website $website)
|
247 |
-
{
|
248 |
-
Mage::getResourceModel('choiceai_searchcore/config')
|
249 |
-
->setValue($website->getWebsiteId(),
|
250 |
-
ChoiceAI_Searchcore_Helper_Constants::NEED_FEATURE_FIELD_UPDATION,
|
251 |
-
ChoiceAI_Searchcore_Helper_Constants::NEED_FEATURE_FIELD_UPDATION_TRUE);
|
252 |
-
$this->triggerFeedUpload($website);
|
253 |
-
}
|
254 |
-
|
255 |
-
/**
|
256 |
-
* Method to trigger feed upload
|
257 |
-
* @param Mage_Core_Model_Website $website
|
258 |
-
* @return void
|
259 |
-
*/
|
260 |
-
public function triggerFeedUpload(Mage_Core_Model_Website $website)
|
261 |
-
{
|
262 |
-
Mage::getModel('choiceai_searchcore/api_task_triggerfeedupload')
|
263 |
-
->prepare($website)
|
264 |
-
->process();
|
265 |
-
}
|
266 |
-
|
267 |
-
|
268 |
-
private function getFeatureFieldToFieldMapping($fields)
|
269 |
-
{
|
270 |
-
$featureFieldToFieldMapping = array();
|
271 |
-
foreach ($fields as $field) {
|
272 |
-
if ($field instanceof ChoiceAI_Searchcore_Model_Field &&
|
273 |
-
$field->hasData(ChoiceAI_Searchcore_Model_Field::featured_field) &&
|
274 |
-
!is_null($field->getData(ChoiceAI_Searchcore_Model_Field::featured_field))
|
275 |
-
) {
|
276 |
-
$featureFieldToFieldMapping[$field[ChoiceAI_Searchcore_Model_Field::featured_field]] = $field;
|
277 |
-
}
|
278 |
-
}
|
279 |
-
return $featureFieldToFieldMapping;
|
280 |
-
}
|
281 |
-
|
282 |
-
private function buildFieldCollection($fields, $website)
|
283 |
-
{
|
284 |
-
$collection = array();
|
285 |
-
$fieldMapping = $this->getFieldMapping($this->getFields($fields, $website));
|
286 |
-
foreach ($fields as $field) {
|
287 |
-
if (!array_key_exists(ChoiceAI_Searchcore_Model_Field::field_name, $field)) {
|
288 |
-
continue;
|
289 |
-
}
|
290 |
-
if (array_key_exists($field[ChoiceAI_Searchcore_Model_Field::field_name], $fieldMapping)) {
|
291 |
-
$collection[]["delete"] = $fieldMapping[$field[ChoiceAI_Searchcore_Model_Field::field_name]];
|
292 |
-
}
|
293 |
-
}
|
294 |
-
return $collection;
|
295 |
-
}
|
296 |
-
|
297 |
-
private function buildFieldCollectionToAdd($fields, $website)
|
298 |
-
{
|
299 |
-
$collection = array();
|
300 |
-
$fieldMapping = $this->getFieldMapping($this->getFields($fields, $website));
|
301 |
-
$featureFieldToFieldMapping = $this->getFeatureFieldToFieldMapping($fieldMapping);
|
302 |
-
|
303 |
-
foreach ($fields as $field) {
|
304 |
-
if (!array_key_exists(ChoiceAI_Searchcore_Model_Field::field_name, $field)) {
|
305 |
-
continue;
|
306 |
-
}
|
307 |
-
/*
|
308 |
-
All possible test cases
|
309 |
-
1) if field name is present and it was a feature field
|
310 |
-
1.a) if request feature field is equal to selected feature field, dont do anything
|
311 |
-
1.b) if request feature field is not equal to selected feature field, dont do anything
|
312 |
-
1.c) if request field is not a feature field,
|
313 |
-
remove the field name entry from the feature field row, save as different row.
|
314 |
-
|
315 |
-
2) if field name is present and it was not a feature field
|
316 |
-
2.a) if request field is a feature field,
|
317 |
-
remove the field name entry as a normal field and save as feature field
|
318 |
-
2.b) if request field is not a feature field,
|
319 |
-
update the existing field
|
320 |
-
|
321 |
-
3) if field name not present,
|
322 |
-
3.a) if it has feature field, delete it from db and insert the new field
|
323 |
-
3.b) save as a new field
|
324 |
-
*/
|
325 |
-
|
326 |
-
// case 1
|
327 |
-
if (array_key_exists($field[ChoiceAI_Searchcore_Model_Field::field_name], $fieldMapping) &&
|
328 |
-
$fieldMapping[$field[ChoiceAI_Searchcore_Model_Field::field_name]]->hasData(ChoiceAI_Searchcore_Model_Field::featured_field) &&
|
329 |
-
!is_null($fieldMapping[$field[ChoiceAI_Searchcore_Model_Field::field_name]]->getData(ChoiceAI_Searchcore_Model_Field::featured_field))
|
330 |
-
) {
|
331 |
-
//case 1 a)
|
332 |
-
if (array_key_exists(ChoiceAI_Searchcore_Model_Field::featured_field, $field) &&
|
333 |
-
$field[ChoiceAI_Searchcore_Model_Field::featured_field] ==
|
334 |
-
$fieldMapping[$field[ChoiceAI_Searchcore_Model_Field::field_name]][ChoiceAI_Searchcore_Model_Field::featured_field]
|
335 |
-
) {
|
336 |
-
continue;
|
337 |
-
} // case 1 b)
|
338 |
-
else if (array_key_exists(ChoiceAI_Searchcore_Model_Field::featured_field, $field)) {
|
339 |
-
$collection[]["delete"] = $featureFieldToFieldMapping[$field[ChoiceAI_Searchcore_Model_Field::featured_field]];
|
340 |
-
$collection[]["delete"] = $fieldMapping[$field[ChoiceAI_Searchcore_Model_Field::field_name]];
|
341 |
-
$fieldModel = Mage::getModel("choiceai_searchcore/field");
|
342 |
-
$fieldModel->setFeaturedField($field[ChoiceAI_Searchcore_Model_Field::featured_field]);
|
343 |
-
} //case 1 c)
|
344 |
-
else {
|
345 |
-
$collection[]["delete"] = $fieldMapping[$field[ChoiceAI_Searchcore_Model_Field::field_name]];
|
346 |
-
$fieldModel = Mage::getModel("choiceai_searchcore/field");
|
347 |
-
|
348 |
-
}
|
349 |
-
} else if (array_key_exists($field[ChoiceAI_Searchcore_Model_Field::field_name], $fieldMapping)) {
|
350 |
-
//case 2 a)
|
351 |
-
if (array_key_exists(ChoiceAI_Searchcore_Model_Field::featured_field, $field)) {
|
352 |
-
$collection[]["delete"] = $fieldMapping[$field[ChoiceAI_Searchcore_Model_Field::field_name]];
|
353 |
-
$fieldModel = Mage::getModel("choiceai_searchcore/field");
|
354 |
-
$fieldModel->setFeaturedField($field[ChoiceAI_Searchcore_Model_Field::featured_field]);
|
355 |
-
} // case 2 b)
|
356 |
-
else {
|
357 |
-
$fieldModel = $fieldMapping[$field[ChoiceAI_Searchcore_Model_Field::field_name]];
|
358 |
-
}
|
359 |
-
} else {
|
360 |
-
$fieldModel = Mage::getModel("choiceai_searchcore/field");
|
361 |
-
if (array_key_exists(ChoiceAI_Searchcore_Model_Field::featured_field, $field)) {
|
362 |
-
$fieldModel->setFeaturedField($field[ChoiceAI_Searchcore_Model_Field::featured_field]);
|
363 |
-
// case 3 a)
|
364 |
-
if (array_key_exists($field[ChoiceAI_Searchcore_Model_Field::featured_field], $featureFieldToFieldMapping)) {
|
365 |
-
$collection[]["delete"] = $featureFieldToFieldMapping[$field[ChoiceAI_Searchcore_Model_Field::featured_field]];
|
366 |
-
}
|
367 |
-
}
|
368 |
-
|
369 |
-
}
|
370 |
-
$fieldModel->setFieldName($field[ChoiceAI_Searchcore_Model_Field::field_name]);
|
371 |
-
$fieldModel->setDatatype($field[ChoiceAI_Searchcore_Model_Field::datatype]);
|
372 |
-
$fieldModel->setAutosuggest(0);
|
373 |
-
$fieldModel->setWebsiteId($website->getWebsiteId());
|
374 |
-
$fieldModel->setDisplayed(1);
|
375 |
-
$collection[]["add"] = $fieldModel;
|
376 |
-
}
|
377 |
-
return $collection;
|
378 |
-
}
|
379 |
-
|
380 |
-
/**
|
381 |
-
* Method to getFields, if
|
382 |
-
*
|
383 |
-
* @param $fields
|
384 |
-
* @return mixed
|
385 |
-
*/
|
386 |
-
private function getFields($fields, $website)
|
387 |
-
{
|
388 |
-
$inField = array();
|
389 |
-
foreach ($fields as $field) {
|
390 |
-
if ($field[ChoiceAI_Searchcore_Model_Field::field_name] == "") {
|
391 |
-
continue;
|
392 |
-
}
|
393 |
-
$inField[] = "'" . $field[ChoiceAI_Searchcore_Model_Field::field_name] . "'";
|
394 |
-
}
|
395 |
-
$collection = Mage::getResourceModel("choiceai_searchcore/field_collection");
|
396 |
-
|
397 |
-
$collection->getSelect()
|
398 |
-
->where('(' . ChoiceAI_Searchcore_Model_Field::field_name . ' in (' . implode(",", $inField) . ')' . " OR " .
|
399 |
-
ChoiceAI_Searchcore_Model_Field::featured_field . " IS NOT NULL) AND " .
|
400 |
-
ChoiceAI_Searchcore_Model_Field::website_id . " = " . $website->getWebsiteId());
|
401 |
-
return $collection->load();
|
402 |
-
}
|
403 |
-
|
404 |
-
|
405 |
-
/**
|
406 |
-
* Method to update feature fields to choiceai
|
407 |
-
*
|
408 |
-
* @return bool| array
|
409 |
-
*/
|
410 |
-
public function updateFeatureFields(Mage_Core_Model_Website $website)
|
411 |
-
{
|
412 |
-
$response = Mage::getModel("choiceai_searchcore/api_task_updatefeaturefields")
|
413 |
-
->prepare($website)
|
414 |
-
->process();
|
415 |
-
if (!$response->isSuccess()) {
|
416 |
-
Mage::log(Zend_Log::ERR,
|
417 |
-
"Update feature fields failed because of theses errors " . json_encode($response->getErrors()));
|
418 |
-
return $response->getErrors();
|
419 |
-
}
|
420 |
-
return true;
|
421 |
-
}
|
422 |
-
|
423 |
-
public function getNumberOfDocsInChoiceAI(Mage_Core_Model_Website $website)
|
424 |
-
{
|
425 |
-
$response = Mage::getModel('choiceai_searchcore/api_task_feeddetails')
|
426 |
-
->prepare($website)
|
427 |
-
->process();
|
428 |
-
if ($response->isSuccess()) {
|
429 |
-
$response = $response->getResponse();
|
430 |
-
$feedInfo = $response[ChoiceAI_Searchcore_Model_Api_Task_Feeddetails::FEEDINFO];
|
431 |
-
return $feedInfo[ChoiceAI_Searchcore_Model_Api_Task_Feeddetails::NUMDOCS];
|
432 |
-
}
|
433 |
-
return 0;
|
434 |
-
}
|
435 |
-
|
436 |
-
/**
|
437 |
-
* @param Mage_Core_Model_Website $website
|
438 |
-
* @return void
|
439 |
-
*/
|
440 |
-
public function triggerAutoggestIndexing(Mage_Core_Model_Website $website)
|
441 |
-
{
|
442 |
-
if (Mage::helper('core')->isModuleEnabled('ChoiceAI_Searchcore') &&
|
443 |
-
$this->isConfigTrue($website, ChoiceAI_Searchcore_Helper_Constants::AUTOSUGGEST_STATUS)
|
444 |
-
) {
|
445 |
-
//trigger Autosuggest
|
446 |
-
$response = Mage::getModel('choiceai_searchcore/api_task_autosuggestindex')
|
447 |
-
->prepare($website)
|
448 |
-
->process();
|
449 |
-
}
|
450 |
-
}
|
451 |
-
|
452 |
-
public function getCategoryExclusion(Mage_Core_Model_Website $website)
|
453 |
-
{
|
454 |
-
$conf = Mage::helper('choiceai_searchcore')->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::EXCLUDE_CATEGORY, $website, true);
|
455 |
-
$categoryExclusionConf = json_decode($conf[ChoiceAI_Searchcore_Helper_Constants::EXCLUDE_CATEGORY], true);
|
456 |
-
if (!is_array($categoryExclusionConf)) {
|
457 |
-
return array();
|
458 |
-
}
|
459 |
-
$categoryToBeExcluded = array();
|
460 |
-
foreach ($categoryExclusionConf as $eachExclusion) {
|
461 |
-
$categoryToBeExcluded[] = (string)$eachExclusion;
|
462 |
-
}
|
463 |
-
return $categoryToBeExcluded;
|
464 |
-
}
|
465 |
-
|
466 |
-
public function getConfigData($name)
|
467 |
-
{
|
468 |
-
return (string)Mage::getConfig()->getNode("default/" . ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX . "/" . $name);
|
469 |
-
}
|
470 |
-
}
|
471 |
-
|
472 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Helper/Constants.php
CHANGED
@@ -180,7 +180,7 @@ class ChoiceAI_Searchcore_Helper_Constants extends Mage_Core_Helper_Abstract {
|
|
180 |
|
181 |
const FEED_STATUS_UPLOADING = 'UPLOADING';
|
182 |
|
183 |
-
const FEED_STATUS_UPLOADED_SUCCESSFULLY = 'UPLOADED
|
184 |
|
185 |
const FEED_STATUS_UPLOADED_FAILED = 'FAILED';
|
186 |
|
180 |
|
181 |
const FEED_STATUS_UPLOADING = 'UPLOADING';
|
182 |
|
183 |
+
const FEED_STATUS_UPLOADED_SUCCESSFULLY = 'UPLOADED SUCCESSFULLY';
|
184 |
|
185 |
const FEED_STATUS_UPLOADED_FAILED = 'FAILED';
|
186 |
|
app/code/local/ChoiceAI/Searchcore/Helper/Data.php
CHANGED
@@ -36,13 +36,13 @@ class ChoiceAI_Searchcore_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
36 |
*/
|
37 |
public function getEngineConfigData($prefix = '', Mage_Core_Model_Website $website = null, $original = false)
|
38 |
{
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
if(is_null($this->engineConfigData)) {
|
47 |
$this->engineConfigData = Mage::getConfig()
|
48 |
->getNode(ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX, 'websites',
|
@@ -63,171 +63,25 @@ class ChoiceAI_Searchcore_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
63 |
$value = (string)$this->engineConfigData;
|
64 |
}
|
65 |
return array_merge($value,$originalConfig);
|
66 |
-
|
67 |
}
|
68 |
|
69 |
public function getOriginalValue($prefix = '', Mage_Core_Model_Website $website) {
|
70 |
-
|
71 |
->getCollection()
|
72 |
->addScopeFilter('websites', (int)$website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX)
|
73 |
->load();
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
}
|
80 |
-
if ($prefix != '' && preg_match("#^{$prefix}(.*)#", $path, $matches)) {
|
81 |
-
$value[$path] = $data->getValue();
|
82 |
-
}
|
83 |
-
}
|
84 |
-
return $value;
|
85 |
-
}
|
86 |
-
|
87 |
-
|
88 |
-
/**
|
89 |
-
* Method to validate the config save allowed
|
90 |
-
* @param Mage_Core_Model_Website $website
|
91 |
-
* @param $configName
|
92 |
-
* @param $origData
|
93 |
-
* @return string | null
|
94 |
-
*/
|
95 |
-
public function isConfigSaveAllowed(Mage_Core_Model_Website $website, $configName, $value, $origData = true) {
|
96 |
-
if(is_null($value) || is_array($value) || is_object($value)){
|
97 |
-
return "Invalid Value given";
|
98 |
-
}
|
99 |
-
if($configName == ChoiceAI_Searchcore_Helper_Constants::SEARCH_HOSTED_STATUS && $value == ChoiceAI_Searchcore_Helper_Constants::TRUE && $this->isConfigTrue($website, ChoiceAI_Searchcore_Helper_Constants::SEARCH_MOD_STATUS, $origData)) {
|
100 |
-
return "Module search is on";
|
101 |
-
}
|
102 |
-
if($configName == ChoiceAI_Searchcore_Helper_Constants::SEARCH_MOD_STATUS && $value == ChoiceAI_Searchcore_Helper_Constants::TRUE && $this->isConfigTrue($website, ChoiceAI_Searchcore_Helper_Constants::SEARCH_HOSTED_STATUS, $origData)) {
|
103 |
-
return "Hosted search is on";
|
104 |
-
}
|
105 |
-
|
106 |
-
return null;
|
107 |
-
}
|
108 |
-
|
109 |
-
|
110 |
-
/**
|
111 |
-
* @param Mage_Core_Model_Website $website
|
112 |
-
* @param $data
|
113 |
-
* @return void
|
114 |
-
*/
|
115 |
-
public function saveConfig(Mage_Core_Model_Website $website, $data) {
|
116 |
-
foreach($data as $key => $value) {
|
117 |
-
if(!is_null($this->isConfigSaveAllowed($website, $key, $value, true)))
|
118 |
-
continue;
|
119 |
-
Mage::getConfig()
|
120 |
-
->saveConfig(ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX .
|
121 |
-
ChoiceAI_Searchcore_Helper_Constants::CONFIG_SEPARATOR .
|
122 |
-
$key,
|
123 |
-
(string)$value,
|
124 |
-
'websites',
|
125 |
-
(int)$website->getWebsiteId());
|
126 |
-
}
|
127 |
-
}
|
128 |
-
|
129 |
-
public function isConfigTrue(Mage_Core_Model_Website $website, $configName, $origData = false) {
|
130 |
-
$configData = $this->getEngineConfigData($configName, $website, $origData);
|
131 |
-
return array_key_exists($configName, $configData) &&
|
132 |
-
$configData[$configName] == ChoiceAI_Searchcore_Helper_Constants::TRUE;
|
133 |
-
}
|
134 |
-
|
135 |
-
/*
|
136 |
-
* returns the choiceai site name
|
137 |
-
* @return String
|
138 |
-
*/
|
139 |
-
public function getSiteName(){
|
140 |
-
$siteKeyLabel = ChoiceAI_Searchcore_Helper_Constants::SITE_KEY;
|
141 |
-
$config = $this->getEngineConfigData($siteKeyLabel);
|
142 |
-
if(array_key_exists($siteKeyLabel, $config) && $config[$siteKeyLabel] != "")
|
143 |
-
return $config[$siteKeyLabel];
|
144 |
-
else {
|
145 |
-
$siteKey = Mage::getResourceModel('choiceai_searchcore/config')
|
146 |
-
->getValue(Mage::app()->getWebsite()->getWebsiteId(),
|
147 |
-
$siteKeyLabel);
|
148 |
-
if(isset($siteKey) && $siteKey != ''){
|
149 |
-
$this->saveConfig(Mage::app()->getWebsite(),
|
150 |
-
array($siteKeyLabel => $siteKey));
|
151 |
-
return $siteKey;
|
152 |
-
} else {
|
153 |
-
if(Mage::getIsDeveloperMode()) {
|
154 |
-
Mage::throwException("ChoiceAI site key is empty");
|
155 |
-
} else {
|
156 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'ChoiceAI site key is not set');
|
157 |
-
return null;
|
158 |
-
}
|
159 |
}
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
/*
|
164 |
-
* returns the choiceai api Key
|
165 |
-
* @return String
|
166 |
-
*/
|
167 |
-
public function getApiKey(){
|
168 |
-
$apiKeyLabel = ChoiceAI_Searchcore_Helper_Constants::API_KEY;
|
169 |
-
$config = $this->getEngineConfigData($apiKeyLabel);
|
170 |
-
if(array_key_exists($apiKeyLabel, $config) && $config[$apiKeyLabel] != "")
|
171 |
-
return $config[$apiKeyLabel];
|
172 |
-
else {
|
173 |
-
$apiKey = Mage::getResourceModel('choiceai_searchcore/config')
|
174 |
-
->getValue(Mage::app()->getWebsite()->getWebsiteId(), $apiKeyLabel);
|
175 |
-
if(isset($apiKey) && $apiKey != ''){
|
176 |
-
$this->saveConfig(Mage::app()->getWebsite(),
|
177 |
-
array($apiKeyLabel => $apiKey));
|
178 |
-
return $apiKey;
|
179 |
-
} else {
|
180 |
-
if(Mage::getIsDeveloperMode()) {
|
181 |
-
Mage::throwException("ChoiceAI api key is empty");
|
182 |
-
} else {
|
183 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'ChoiceAI Api key is not set');
|
184 |
-
return null;
|
185 |
-
}
|
186 |
}
|
187 |
}
|
|
|
188 |
}
|
189 |
|
190 |
-
/*
|
191 |
-
* decides which module should be given more priority based on the version
|
192 |
-
* @return boolean
|
193 |
-
*/
|
194 |
-
public function isExecutable() {
|
195 |
-
if(Mage::helper('core')->isModuleEnabled('ChoiceAI_Recscore')){
|
196 |
-
$otherModuleVersion = floatval(Mage::getConfig()->getModuleConfig("ChoiceAI_Recscore")->version);
|
197 |
-
$currentModuleVersion = floatval(Mage::getConfig()->getModuleConfig("ChoiceAI_Searchcore")->version);
|
198 |
-
if($this->version_compare($otherModuleVersion, $currentModuleVersion) > 0) {
|
199 |
-
return false;
|
200 |
-
} else if($this->version_compare($otherModuleVersion, $currentModuleVersion) == 0) {
|
201 |
-
return false;
|
202 |
-
}
|
203 |
-
|
204 |
-
}
|
205 |
-
return true;
|
206 |
-
}
|
207 |
-
|
208 |
-
//Compare two sets of versions, where major/minor/etc. releases are separated by dots.
|
209 |
-
//Returns 0 if both are equal, 1 if A > B, and -1 if B < A.
|
210 |
-
public function version_compare($a, $b)
|
211 |
-
{
|
212 |
-
$a = explode(".", rtrim($a, ".0")); //Split version into pieces and remove trailing .0
|
213 |
-
$b = explode(".", rtrim($b, ".0")); //Split version into pieces and remove trailing .0
|
214 |
-
foreach ($a as $depth => $aVal)
|
215 |
-
{ //Iterate over each piece of A
|
216 |
-
if (isset($b[$depth]))
|
217 |
-
{ //If B matches A to this depth, compare the values
|
218 |
-
if ($aVal > $b[$depth]) return 1; //Return A > B
|
219 |
-
else if ($aVal < $b[$depth]) return -1; //Return B > A
|
220 |
-
//An equal result is inconclusive at this point
|
221 |
-
}
|
222 |
-
else
|
223 |
-
{ //If B does not match A to this depth, then A comes after B in sort order
|
224 |
-
return 1; //so return A > B
|
225 |
-
}
|
226 |
-
}
|
227 |
-
//At this point, we know that to the depth that A and B extend to, they are equivalent.
|
228 |
-
//Either the loop ended because A is shorter than B, or both are equal.
|
229 |
-
return (count($a) < count($b)) ? -1 : 0;
|
230 |
-
}
|
231 |
-
|
232 |
}
|
233 |
?>
|
36 |
*/
|
37 |
public function getEngineConfigData($prefix = '', Mage_Core_Model_Website $website = null, $original = false)
|
38 |
{
|
39 |
+
if(is_null($website)) {
|
40 |
+
$website = Mage::app()->getWebsite();
|
41 |
+
}
|
42 |
+
$originalConfig = array();
|
43 |
+
if($original) {
|
44 |
+
$originalConfig = $this->getOriginalValue($prefix, $website);
|
45 |
+
}
|
46 |
if(is_null($this->engineConfigData)) {
|
47 |
$this->engineConfigData = Mage::getConfig()
|
48 |
->getNode(ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX, 'websites',
|
63 |
$value = (string)$this->engineConfigData;
|
64 |
}
|
65 |
return array_merge($value,$originalConfig);
|
|
|
66 |
}
|
67 |
|
68 |
public function getOriginalValue($prefix = '', Mage_Core_Model_Website $website) {
|
69 |
+
$configDataCollection = Mage::getModel('core/config_data')
|
70 |
->getCollection()
|
71 |
->addScopeFilter('websites', (int)$website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX)
|
72 |
->load();
|
73 |
+
$value = array();
|
74 |
+
foreach($configDataCollection as $data) {
|
75 |
+
$path = $data->getPath();
|
76 |
+
if (substr($path, 0, strlen(ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX)) == ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX) {
|
77 |
+
$path = substr($path, strlen(ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_CONFIG_PREFIX) +1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
+
if ($prefix != '' && preg_match("#^{$prefix}(.*)#", $path, $matches)) {
|
80 |
+
$value[$path] = $data->getValue();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
}
|
82 |
}
|
83 |
+
return $value;
|
84 |
}
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
}
|
87 |
?>
|
app/code/local/ChoiceAI/Searchcore/Helper/Feedhelper.php
DELETED
@@ -1,288 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
6 |
-
* @copyright Copyright (c) MineWhat
|
7 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
-
*/
|
9 |
-
|
10 |
-
class ChoiceAI_Searchcore_Helper_Feedhelper extends ChoiceAI_Searchcore_Helper_Data {
|
11 |
-
|
12 |
-
var $categoryMap;
|
13 |
-
|
14 |
-
var $catlevel1List;
|
15 |
-
|
16 |
-
var $attributeToTypeMap;
|
17 |
-
|
18 |
-
var $_rootCategoryIds = array();
|
19 |
-
|
20 |
-
var $_filters;
|
21 |
-
|
22 |
-
protected function array_match($needle, $haystack) {
|
23 |
-
if(!is_array($needle)) {
|
24 |
-
return in_array($needle, $haystack);
|
25 |
-
}
|
26 |
-
|
27 |
-
foreach($needle as $eachNeedle) {
|
28 |
-
if(in_array($eachNeedle, $haystack)) {
|
29 |
-
return true;
|
30 |
-
}
|
31 |
-
}
|
32 |
-
return false;
|
33 |
-
}
|
34 |
-
|
35 |
-
public function getAllFilterableAttributes(Mage_Core_Model_Website $website) {
|
36 |
-
|
37 |
-
$filterableAttributes = array();
|
38 |
-
$stores = $website->getStores();
|
39 |
-
$this->tempCategoriesScanned = array();
|
40 |
-
foreach($stores as $store) {
|
41 |
-
Mage::app()->setCurrentStore($store);
|
42 |
-
$categoryId = $store->getRootCategoryId();
|
43 |
-
$category = Mage::getModel('catalog/category')->load($categoryId);
|
44 |
-
$this->tempCategoriesScanned[] = $categoryId;
|
45 |
-
$filterableAttributes = array_merge($filterableAttributes, $this->getFilterableAttributesForCategory($category));
|
46 |
-
}
|
47 |
-
return array_unique($filterableAttributes);
|
48 |
-
}
|
49 |
-
|
50 |
-
public function getFilterableAttributesForCategory($category) {
|
51 |
-
if(array_key_exists($category->getId(), $this->tempCategoriesScanned)) {
|
52 |
-
return array();
|
53 |
-
} else {
|
54 |
-
$this->tempCategoriesScanned[] = $category->getId();
|
55 |
-
}
|
56 |
-
$filterableAttributes = array();
|
57 |
-
$layer = Mage::getModel("catalog/layer");
|
58 |
-
$layer->setCurrentCategory($category);
|
59 |
-
$attributes = $layer->getFilterableAttributes();
|
60 |
-
foreach ($attributes as $attribute) {
|
61 |
-
$filterableAttributes[] = $attribute->getAttributeCode();
|
62 |
-
}
|
63 |
-
$childrenCategoryIds = $category->getAllChildren();
|
64 |
-
$childrenCategories = Mage::getModel('catalog/category')->getCollection()->addIdFilter($childrenCategoryIds)->load();
|
65 |
-
if(!is_null($childrenCategories)) {
|
66 |
-
foreach ($childrenCategories as $childrenCategory) {
|
67 |
-
$filterableAttributes = array_merge($filterableAttributes, $this->getFilterableAttributesForCategory($childrenCategory));
|
68 |
-
}
|
69 |
-
}
|
70 |
-
return array_unique($filterableAttributes);
|
71 |
-
}
|
72 |
-
|
73 |
-
/**
|
74 |
-
* function to get Category from the category id,
|
75 |
-
* This checks it present in the global array 'categoryMap', if it is not there fetches from db
|
76 |
-
* So that once it gets one category, it doesn't make db call again for the same category
|
77 |
-
*
|
78 |
-
* @param string $category_id
|
79 |
-
* @return Mage_Catalog_Model_Category
|
80 |
-
*/
|
81 |
-
public function getCategory($category_id = ""){
|
82 |
-
if(!isset($this->categoryMap[$category_id])){
|
83 |
-
$category = Mage::getModel('catalog/category')->load($category_id);
|
84 |
-
$this->categoryMap[$category_id] = $category;
|
85 |
-
$parentCategories = $category->getParentCategories();
|
86 |
-
foreach($parentCategories as $parentCategory) {
|
87 |
-
$parentCategory = Mage::getModel('catalog/category')->load($parentCategory->getId());
|
88 |
-
$this->categoryMap[$parentCategory->getId()] = $parentCategory;
|
89 |
-
}
|
90 |
-
return $this->categoryMap[$category_id];
|
91 |
-
}
|
92 |
-
return $this->categoryMap[$category_id];
|
93 |
-
}
|
94 |
-
|
95 |
-
public function getRootCategoryIds(Mage_Core_Model_Website $website) {
|
96 |
-
if(!array_key_exists($website->getWebsiteId(), $this->_rootCategoryIds)) {
|
97 |
-
foreach($website->getStores() as $store) {
|
98 |
-
$this->_rootCategoryIds[$website->getWebsiteId()][] = $store->getRootCategoryId();
|
99 |
-
}
|
100 |
-
}
|
101 |
-
return $this->_rootCategoryIds[$website->getWebsiteId()];
|
102 |
-
}
|
103 |
-
|
104 |
-
public function getCategoryOnLevel($category_ids, $level) {
|
105 |
-
if(!is_array($category_ids)) {
|
106 |
-
return array();
|
107 |
-
}
|
108 |
-
$categoryValues = array();
|
109 |
-
foreach($category_ids as $category_id) {
|
110 |
-
$category = $this->getCategory($category_id);
|
111 |
-
$parentIds = $category->getParentIds();
|
112 |
-
if(!is_null($category) && $category->getLevel() == $level) {
|
113 |
-
$categoryValues = array_merge($categoryValues, array($category->getName()));
|
114 |
-
} else if ($category instanceof Mage_Catalog_Model_Category &&
|
115 |
-
is_array($parentIds) &&
|
116 |
-
(sizeof($parentIds) >0)) {
|
117 |
-
$categoryValues = array_merge($categoryValues, $this->getCategoryOnLevel($parentIds, $level));
|
118 |
-
}
|
119 |
-
}
|
120 |
-
return $categoryValues;
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* method to get all the attributes
|
125 |
-
**/
|
126 |
-
public function getAttributeMapping(){
|
127 |
-
if(isset($this->attributeToTypeMap)){
|
128 |
-
return $this->attributeToTypeMap;
|
129 |
-
} else {
|
130 |
-
$attributes = Mage::getSingleton('eav/config')
|
131 |
-
->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
|
132 |
-
foreach($attributes as $attribute){
|
133 |
-
$this->attributeToTypeMap[$attribute->getAttributeCode()] = $attribute->getFrontendInput();
|
134 |
-
}
|
135 |
-
return $this->attributeToTypeMap;
|
136 |
-
}
|
137 |
-
}
|
138 |
-
|
139 |
-
public function isAttributePresent($attributeName) {
|
140 |
-
$fieldMap = $this->getAttributeMapping();
|
141 |
-
return array_key_exists( $attributeName, $fieldMap);
|
142 |
-
}
|
143 |
-
|
144 |
-
/**
|
145 |
-
* method to get field type of the field
|
146 |
-
* @param $attributeName
|
147 |
-
* @return string
|
148 |
-
*/
|
149 |
-
public function getFieldType($attributeName){
|
150 |
-
$fieldMap = $this->getAttributeMapping();
|
151 |
-
if(array_key_exists( $attributeName, $fieldMap)){
|
152 |
-
return $fieldMap[$attributeName];
|
153 |
-
} else {
|
154 |
-
return "text";
|
155 |
-
}
|
156 |
-
}
|
157 |
-
|
158 |
-
function endsWith($haystack, $needle) {
|
159 |
-
// search forward starting from end minus needle length characters
|
160 |
-
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
|
161 |
-
}
|
162 |
-
|
163 |
-
/*
|
164 |
-
* function to check whether the field is a multiSelect/select or not,
|
165 |
-
* This is optimized method, where it doesn't make a database call to get fieldType
|
166 |
-
* where it fetches from the local variable, which holds the information of field to fieldType mapping
|
167 |
-
* @param string $attributeName
|
168 |
-
* @return bool
|
169 |
-
*/
|
170 |
-
public function isMultiSelect($attributeName = ""){
|
171 |
-
if(!$this->excludeMultiSelectList($attributeName)) {
|
172 |
-
return false;
|
173 |
-
}
|
174 |
-
if( $this->isMultiSelectDatatype($attributeName)||
|
175 |
-
$attributeName == ChoiceAI_Searchcore_Model_Resource_Field::CATEGORY_IDS ||
|
176 |
-
$attributeName == ChoiceAI_Searchcore_Model_Resource_Field::CATEGORY_IDS_NAME ||
|
177 |
-
$attributeName == ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_1_NAME ||
|
178 |
-
$attributeName == ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_2_NAME ||
|
179 |
-
$attributeName == ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_3_NAME ||
|
180 |
-
$this->endsWith($attributeName, 'Associated')){
|
181 |
-
return true;
|
182 |
-
}
|
183 |
-
return false;
|
184 |
-
}
|
185 |
-
|
186 |
-
public function excludeMultiSelectList($attributeName = "") {
|
187 |
-
if($attributeName == "status" || $attributeName == "visibility" || $attributeName == "entity_id" ){
|
188 |
-
return false;
|
189 |
-
}
|
190 |
-
return true;
|
191 |
-
}
|
192 |
-
|
193 |
-
|
194 |
-
public function isMultiSelectDatatype($attributeName = "") {
|
195 |
-
if(!$this->excludeMultiSelectList($attributeName)) {
|
196 |
-
return false;
|
197 |
-
}
|
198 |
-
|
199 |
-
if($this->getFieldType($attributeName) == "select" ||
|
200 |
-
$this->getFieldType($attributeName) == "multiselect") {
|
201 |
-
return true;
|
202 |
-
}
|
203 |
-
return false;
|
204 |
-
}
|
205 |
-
|
206 |
-
public function isImage($attributeName = "") {
|
207 |
-
if($this->getFieldType($attributeName) == "media_image") {
|
208 |
-
return true;
|
209 |
-
}
|
210 |
-
return false;
|
211 |
-
}
|
212 |
-
|
213 |
-
/**
|
214 |
-
* Get all root categories used by all stores.
|
215 |
-
* Note that root categories defined but not used, are not included.
|
216 |
-
*
|
217 |
-
* @return Mage_Catalog_Model_Category[]
|
218 |
-
*/
|
219 |
-
public function getAllRootCategories()
|
220 |
-
{
|
221 |
-
$categories = array();
|
222 |
-
|
223 |
-
/** @var $stores Mage_Searchcore_Model_Store[] */
|
224 |
-
$stores = Mage::app()->getStores();
|
225 |
-
|
226 |
-
foreach ($stores as $store) {
|
227 |
-
$id = $store->getRootCategoryId();
|
228 |
-
if (!isset($categories[$id])) {
|
229 |
-
$categories[$id] = Mage::getModel('catalog/category')->load($id);
|
230 |
-
}
|
231 |
-
}
|
232 |
-
|
233 |
-
return $categories;
|
234 |
-
}
|
235 |
-
|
236 |
-
public function getUniqueId($product, $item=null) {
|
237 |
-
$type= null;
|
238 |
-
if($product->hasData('type_id')) {
|
239 |
-
$type = $product->getData('type_id');
|
240 |
-
}
|
241 |
-
|
242 |
-
switch($type){
|
243 |
-
case 'configurable':
|
244 |
-
$productId = $product->getData('entity_id');
|
245 |
-
break;
|
246 |
-
case 'grouped':
|
247 |
-
$productId = $product->getData('entity_id');
|
248 |
-
break;
|
249 |
-
case 'bundle':
|
250 |
-
$productId = $product->getData('entity_id');
|
251 |
-
break;
|
252 |
-
case 'simple':
|
253 |
-
if ($item != null && $item instanceof Mage_Sales_Model_Order) {
|
254 |
-
if($item->getParentItem() != null) {
|
255 |
-
$productId = $item->getParentItem()->getProductId();
|
256 |
-
return $productId;
|
257 |
-
}
|
258 |
-
}
|
259 |
-
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
|
260 |
-
if(!isset($parentIds) || sizeof($parentIds) == 0) {
|
261 |
-
$parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
|
262 |
-
if(isset($parentIds) && sizeof($parentIds) > 0) {
|
263 |
-
return $parentIds[0];
|
264 |
-
}
|
265 |
-
} else {
|
266 |
-
return $parentIds[0];
|
267 |
-
}
|
268 |
-
$productId = $product->getData('entity_id');
|
269 |
-
break;
|
270 |
-
default:
|
271 |
-
$productId = $product->getData('entity_id');
|
272 |
-
}
|
273 |
-
return $productId;
|
274 |
-
}
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Method to get the filters that need to be excluded in the website
|
278 |
-
* @param Mage_Core_Model_Website $website
|
279 |
-
* @return array
|
280 |
-
*/
|
281 |
-
public function getFilters(Mage_Core_Model_Website $website) {
|
282 |
-
if(!isset($this->_filters)) {
|
283 |
-
$this->_filters = Mage::getResourceModel('choiceai_searchcore/config')->getFilters($website);
|
284 |
-
}
|
285 |
-
return $this->_filters;
|
286 |
-
}
|
287 |
-
|
288 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Request.php
DELETED
@@ -1,212 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Class to make the request to the ChoiceAI api
|
5 |
-
*
|
6 |
-
* @category ChoiceAI
|
7 |
-
* @package ChoiceAI_Searchcore
|
8 |
-
* @copyright Copyright (c) MineWhat
|
9 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
-
*/
|
11 |
-
class ChoiceAI_Searchcore_Model_Api_Request extends Varien_Object {
|
12 |
-
|
13 |
-
/**
|
14 |
-
* end url where the request is firing
|
15 |
-
* @var
|
16 |
-
*/
|
17 |
-
protected $url = "";
|
18 |
-
|
19 |
-
/**
|
20 |
-
* http method
|
21 |
-
* @var
|
22 |
-
*/
|
23 |
-
protected $method = Zend_Http_Client::GET;
|
24 |
-
|
25 |
-
/*
|
26 |
-
* Boolean to check whether the data should be sent as raw data or not
|
27 |
-
*/
|
28 |
-
protected $rawData = false;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* http response type
|
32 |
-
* @var
|
33 |
-
*/
|
34 |
-
protected $response = "";
|
35 |
-
|
36 |
-
/**
|
37 |
-
* headers needed to sent
|
38 |
-
* @var
|
39 |
-
*/
|
40 |
-
protected $headers = array();
|
41 |
-
|
42 |
-
protected $jsonResponse = true;
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Connection timeout to the api calls made to choiceai
|
46 |
-
*/
|
47 |
-
protected $timeout = 30;
|
48 |
-
|
49 |
-
public function isJsonResponse() {
|
50 |
-
return $this->jsonResponse;
|
51 |
-
}
|
52 |
-
|
53 |
-
public function setJsonResponse($value) {
|
54 |
-
if(is_bool($value) && $value == false) {
|
55 |
-
$this->jsonResponse = false;
|
56 |
-
}
|
57 |
-
return $this;
|
58 |
-
}
|
59 |
-
|
60 |
-
public function getHeaders() {
|
61 |
-
return $this->headers;
|
62 |
-
}
|
63 |
-
|
64 |
-
public function setHeaders(array $headers) {
|
65 |
-
$this->headers = $headers;
|
66 |
-
return $this;
|
67 |
-
}
|
68 |
-
|
69 |
-
public function getTimeout() {
|
70 |
-
return $this->timeout;
|
71 |
-
}
|
72 |
-
|
73 |
-
public function setTimeout($timeout) {
|
74 |
-
if(is_int($timeout) && $timeout >= 0) {
|
75 |
-
$this->timeout = $timeout;
|
76 |
-
}
|
77 |
-
return $this;
|
78 |
-
}
|
79 |
-
|
80 |
-
public function setHeader(string $header,string $value) {
|
81 |
-
$this->headers[$header] = $value;
|
82 |
-
return $this;
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Method to get the url
|
87 |
-
*
|
88 |
-
* @return mixed
|
89 |
-
*/
|
90 |
-
protected function getUrl() {
|
91 |
-
return $this->url;
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* setter method to set url variable
|
96 |
-
*
|
97 |
-
* @param $url
|
98 |
-
* @return $this
|
99 |
-
*/
|
100 |
-
public function setUrl($url) {
|
101 |
-
$this->url = $url;
|
102 |
-
return $this;
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Method to get the method
|
107 |
-
*
|
108 |
-
* @return mixed
|
109 |
-
*/
|
110 |
-
protected function getMethod() {
|
111 |
-
return $this->method;
|
112 |
-
}
|
113 |
-
|
114 |
-
/**
|
115 |
-
* setter method to set method variable
|
116 |
-
*
|
117 |
-
* @param $method
|
118 |
-
* @return void
|
119 |
-
*/
|
120 |
-
public function setMethod($method) {
|
121 |
-
$this->method = $method;
|
122 |
-
return $this;
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Method to check whether parameters to be sent as raw parameter
|
127 |
-
*
|
128 |
-
* @return bool
|
129 |
-
*/
|
130 |
-
protected function isRawData() {
|
131 |
-
return $this->rawData;
|
132 |
-
}
|
133 |
-
|
134 |
-
/**
|
135 |
-
* setter method to set rawdata variable
|
136 |
-
*
|
137 |
-
* @param bool $rawData
|
138 |
-
* @return $this
|
139 |
-
*/
|
140 |
-
public function setRawData($rawData= true) {
|
141 |
-
$this->rawData = $rawData;
|
142 |
-
return $this;
|
143 |
-
}
|
144 |
-
|
145 |
-
|
146 |
-
/**
|
147 |
-
* return Zend Rest Client
|
148 |
-
*
|
149 |
-
* @return Zend_Http_Client
|
150 |
-
*/
|
151 |
-
protected function getRestClient(){
|
152 |
-
|
153 |
-
$request = new Zend_Http_Client();
|
154 |
-
$request->setUri($this->getUrl())
|
155 |
-
->setHeaders(array("Accept" => "application/json") + $this->getHeaders())
|
156 |
-
->setMethod($this->getMethod())
|
157 |
-
->setConfig(
|
158 |
-
array(
|
159 |
-
'timeout' => $this->getTimeout()
|
160 |
-
)
|
161 |
-
);
|
162 |
-
if($this->isRawData()) {
|
163 |
-
$params = json_encode($this->getData());
|
164 |
-
$request->setRawData($params, 'application/json');
|
165 |
-
} else if($this->getMethod() == Zend_Http_Client::GET) {
|
166 |
-
$request->setParameterGet($this->getData());
|
167 |
-
} else {
|
168 |
-
$request->setParameterPost($this->getData());
|
169 |
-
}
|
170 |
-
return $request;
|
171 |
-
}
|
172 |
-
|
173 |
-
|
174 |
-
/**
|
175 |
-
* Method which will make the api call
|
176 |
-
*
|
177 |
-
* @return false|ChoiceAI_Searchcore_Model_Api_Response
|
178 |
-
*/
|
179 |
-
public function execute(){
|
180 |
-
try {
|
181 |
-
$request = $this->getRestClient();
|
182 |
-
$raw_response = $request->request();
|
183 |
-
} catch (Zend_Http_Client_Exception $e) {
|
184 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR,
|
185 |
-
sprintf($this->getUrl() ." failed because HTTP error: %s", $e->getMessage()));
|
186 |
-
return Mage::getModel('choiceai_searchcore/api_response')
|
187 |
-
->setErrorMessage(ChoiceAI_Searchcore_Model_Api_Response::SERVER_ERR);
|
188 |
-
}
|
189 |
-
return Mage::getModel("choiceai_searchcore/api_response")
|
190 |
-
->setJsonResponse($this->isJsonResponse())
|
191 |
-
->setResponse($raw_response, $this->getUrl());
|
192 |
-
}
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Method to return string
|
196 |
-
*
|
197 |
-
* @return string
|
198 |
-
*/
|
199 |
-
public function __toString() {
|
200 |
-
|
201 |
-
$parameters = $this->getData();
|
202 |
-
if (count($parameters) > 0) {
|
203 |
-
$parameters_as_string = json_encode($parameters);
|
204 |
-
}
|
205 |
-
return "Request to url " . $this->getUrl() . " with method " . $this->getMethod()
|
206 |
-
. (count($parameters) > 0?(" with parameters " . $parameters_as_string):"");
|
207 |
-
}
|
208 |
-
|
209 |
-
|
210 |
-
}
|
211 |
-
|
212 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Response.php
DELETED
@@ -1,165 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Response extends Varien_Object {
|
10 |
-
|
11 |
-
const SERVER_ERR = 'Unable to reach choiceai server, Please contact support';
|
12 |
-
|
13 |
-
const SERVER_RESPONSE_ERR = 'Invalid response from ChoiceAI, Please contact support';
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Variable to maintain the response successful or not
|
17 |
-
* @var
|
18 |
-
*/
|
19 |
-
protected $success;
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Variable to maintain the response successful or not
|
23 |
-
* @var
|
24 |
-
*/
|
25 |
-
protected $errors = array();
|
26 |
-
|
27 |
-
protected $jsonResponse = true;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Variable to store the response from the api
|
31 |
-
* @var
|
32 |
-
*/
|
33 |
-
protected $response;
|
34 |
-
|
35 |
-
public function isJsonResponse() {
|
36 |
-
|
37 |
-
return $this->jsonResponse;
|
38 |
-
}
|
39 |
-
|
40 |
-
public function setJsonResponse($value) {
|
41 |
-
if(is_bool($value) && $value == false) {
|
42 |
-
$this->jsonResponse = false;
|
43 |
-
}
|
44 |
-
return $this;
|
45 |
-
}
|
46 |
-
|
47 |
-
public function _construct() {
|
48 |
-
$this->success = false;
|
49 |
-
$this->message = "Empty response";
|
50 |
-
$this->response = array();
|
51 |
-
}
|
52 |
-
|
53 |
-
public function setSuccess($success) {
|
54 |
-
if(is_bool($success)) {
|
55 |
-
$this->success = $success;
|
56 |
-
}
|
57 |
-
return $this;
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Method to check exact error message
|
62 |
-
*
|
63 |
-
* @return bool
|
64 |
-
*/
|
65 |
-
public function isSuccess() {
|
66 |
-
return $this->success;
|
67 |
-
}
|
68 |
-
|
69 |
-
public function setErrors($errors = array()) {
|
70 |
-
$this->errors = $errors;
|
71 |
-
return $this;
|
72 |
-
}
|
73 |
-
|
74 |
-
public function getErrors() {
|
75 |
-
return $this->errors;
|
76 |
-
}
|
77 |
-
|
78 |
-
public function setErrorMessage($message) {
|
79 |
-
$this->errors['message'] = $message;
|
80 |
-
return $this;
|
81 |
-
}
|
82 |
-
|
83 |
-
public function setError(string $key, string $value) {
|
84 |
-
$this->errors[$key] = $value;
|
85 |
-
return $this;
|
86 |
-
}
|
87 |
-
|
88 |
-
/**
|
89 |
-
* Method to get Message
|
90 |
-
*
|
91 |
-
* @return string
|
92 |
-
*/
|
93 |
-
public function getMessage() {
|
94 |
-
if(array_key_exists('message', $this->errors)) {
|
95 |
-
return $this->errors['message'];
|
96 |
-
}
|
97 |
-
return null;
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Method to set the message
|
102 |
-
*
|
103 |
-
* @param $message
|
104 |
-
* @return $this
|
105 |
-
*/
|
106 |
-
public function setMessage($message) {
|
107 |
-
$this->errors['message'] = $message;
|
108 |
-
return $this;
|
109 |
-
}
|
110 |
-
|
111 |
-
/**
|
112 |
-
* Method to return the response
|
113 |
-
*
|
114 |
-
* @return array
|
115 |
-
*/
|
116 |
-
public function getResponse() {
|
117 |
-
return $this->response;
|
118 |
-
}
|
119 |
-
|
120 |
-
/**
|
121 |
-
* Method to set the response
|
122 |
-
*
|
123 |
-
* @param Zend_Http_Response $response
|
124 |
-
* @param $url
|
125 |
-
* @return $this
|
126 |
-
*/
|
127 |
-
public function setResponse(Zend_Http_Response $response, $url) {
|
128 |
-
if($response->isSuccessful()) {
|
129 |
-
$this->success = true;
|
130 |
-
$this->setMessage("success");
|
131 |
-
$body = $response->getBody();
|
132 |
-
if(!$this->isJsonResponse()) {
|
133 |
-
#Mage::helper('choiceai_searchcore')->log(Zend_Log::DEBUG, "response from the " . $url . " is successful");
|
134 |
-
$this->setData("body", $body);
|
135 |
-
return $this;
|
136 |
-
}
|
137 |
-
$this->response = json_decode($body, true);
|
138 |
-
#Mage::helper('choiceai_searchcore')->log(Zend_Log::DEBUG, "response from the " . $url . " is " . $body);
|
139 |
-
if($this->response == false || !is_array($this->response) || sizeof($this->response) == 0) {
|
140 |
-
$this->success = false;
|
141 |
-
$this->setMessage("Invalid Authorization credentials");
|
142 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, $url . " api failed cos ". $this->getMessage());
|
143 |
-
return $this;
|
144 |
-
}
|
145 |
-
} else {
|
146 |
-
|
147 |
-
$this->success = false;
|
148 |
-
switch ($response->getStatus()) {
|
149 |
-
case 500:
|
150 |
-
$message = "ChoiceAI API server error, Please contact support \n" . $response->getBody();
|
151 |
-
$this->setMessage("ChoiceAI API server error, Please contact support \n");
|
152 |
-
break;
|
153 |
-
default:
|
154 |
-
$message = "ChoiceAI Unexpected error, Please contact support";
|
155 |
-
$this->setMessage($message);
|
156 |
-
}
|
157 |
-
Mage::helper('choiceai_searchcore')
|
158 |
-
->log(Zend_Log::ERR, $url . " api failed cos ". $response->getStatus() . ":" . $message);
|
159 |
-
}
|
160 |
-
return $this;
|
161 |
-
}
|
162 |
-
|
163 |
-
|
164 |
-
}
|
165 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task.php
DELETED
@@ -1,84 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
6 |
-
* @copyright Copyright (c) MineWhat
|
7 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
-
*/
|
9 |
-
abstract class ChoiceAI_Searchcore_Model_Api_Task extends Varien_Object {
|
10 |
-
|
11 |
-
static $PLATFORM_API_BASE_URL = "https://accounts.choiceaiapi.com/admin/";
|
12 |
-
|
13 |
-
static $RECOMMENDATION_SETTINGS_URL = "https://starwreck.choiceai.com/";
|
14 |
-
|
15 |
-
static $TRACKER_URL = "https://tracker.choiceaiapi.com/";
|
16 |
-
|
17 |
-
const TIMEOUT = 30;
|
18 |
-
|
19 |
-
static $url = "";
|
20 |
-
|
21 |
-
const method = Zend_Http_Client::GET;
|
22 |
-
|
23 |
-
protected $preparationSuccessful;
|
24 |
-
|
25 |
-
protected $errors;
|
26 |
-
|
27 |
-
protected $headers = array();
|
28 |
-
|
29 |
-
protected $isRawData = false;
|
30 |
-
|
31 |
-
const jsonResponse = true;
|
32 |
-
|
33 |
-
public function __construct() {
|
34 |
-
$this->preparationSuccessful = false;
|
35 |
-
$this->errors = array();
|
36 |
-
static::$PLATFORM_API_BASE_URL = Mage::helper('choiceai_searchcore/confighelper')->getConfigData('platform_url');
|
37 |
-
static::$RECOMMENDATION_SETTINGS_URL = Mage::helper('choiceai_searchcore/confighelper')->getConfigData('service_url');
|
38 |
-
static::$TRACKER_URL = Mage::helper('choiceai_searchcore/confighelper')->getConfigData('tracker_url');
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Method to check whether parameters to be sent as raw parameter
|
43 |
-
*
|
44 |
-
* @return bool
|
45 |
-
*/
|
46 |
-
protected function isRawData() {
|
47 |
-
return $this->isRawData;
|
48 |
-
}
|
49 |
-
|
50 |
-
abstract public function prepare(Mage_Core_Model_Website $website);
|
51 |
-
|
52 |
-
abstract protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response);
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Method which will make the api call
|
56 |
-
*
|
57 |
-
* @return false|ChoiceAI_Searchcore_Model_Api_Response
|
58 |
-
*/
|
59 |
-
public function process() {
|
60 |
-
if(!$this->preparationSuccessful) {
|
61 |
-
Mage::helper("choiceai_searchcore")
|
62 |
-
->log(Zend_Log::ERR,
|
63 |
-
sizeof($this->errors == 0)?"prepare method not called":json_encode($this->errors));
|
64 |
-
return Mage::getModel("choiceai_searchcore/api_response")
|
65 |
-
->setErrors(sizeof($this->errors) == 0?array("message" => "prepare method not called"):$this->errors);
|
66 |
-
}
|
67 |
-
$request = Mage::getModel("choiceai_searchcore/api_request")
|
68 |
-
->setUrl(static::$url)
|
69 |
-
->setMethod(static::method)
|
70 |
-
->setHeaders($this->headers)
|
71 |
-
->setTimeout(static::TIMEOUT)
|
72 |
-
->setJsonResponse(static::jsonResponse);
|
73 |
-
if($this->isRawData()) {
|
74 |
-
$request->setRawData(true);
|
75 |
-
}
|
76 |
-
if($this->getData()) {
|
77 |
-
$request->addData($this->getData());
|
78 |
-
}
|
79 |
-
|
80 |
-
return $this->postProcess($request->execute());
|
81 |
-
}
|
82 |
-
|
83 |
-
}
|
84 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Analyticsimpression.php
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
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_Searchcore_Model_Api_Task_Analyticsimpression extends ChoiceAI_Searchcore_Model_Api_Task
|
9 |
-
{
|
10 |
-
|
11 |
-
const method = Zend_Http_Client::GET;
|
12 |
-
|
13 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
14 |
-
$this->preparationSuccessful = true;
|
15 |
-
$this->prepareUrl($website);
|
16 |
-
$this->prepareHeaders($website);
|
17 |
-
return $this;
|
18 |
-
}
|
19 |
-
|
20 |
-
protected function prepareUrl(Mage_Core_Model_Website $website) {
|
21 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
22 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
23 |
-
if(is_null($siteKey)) {
|
24 |
-
$this->preparationSuccessful = false;
|
25 |
-
$this->errors["message"] = "Site key not set";
|
26 |
-
return;
|
27 |
-
}
|
28 |
-
|
29 |
-
static::$url = static::$RECOMMENDATION_SETTINGS_URL . "dashboard/analytics/integrationDetails/" . $siteKey;
|
30 |
-
}
|
31 |
-
|
32 |
-
protected function prepareHeaders(Mage_Core_Model_Website $website) {
|
33 |
-
$username = Mage::getResourceModel("choiceai_searchcore/config")
|
34 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::USERNAME);
|
35 |
-
if(is_null($username)) {
|
36 |
-
$this->preparationSuccessful = false;
|
37 |
-
$this->errors["message"] = "Secret key not set";
|
38 |
-
return;
|
39 |
-
}
|
40 |
-
|
41 |
-
$this->headers["authorization"] = "Basic " . base64_encode($username . ':$uauth');
|
42 |
-
}
|
43 |
-
|
44 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
45 |
-
return $response;
|
46 |
-
}
|
47 |
-
|
48 |
-
}
|
49 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Autosuggestindex.php
DELETED
@@ -1,52 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Task_Autosuggestindex extends ChoiceAI_Searchcore_Model_Api_Task {
|
10 |
-
|
11 |
-
const method = Zend_Http_Client::POST;
|
12 |
-
|
13 |
-
const STATUS = 'status';
|
14 |
-
|
15 |
-
const MESSAGE = 'message';
|
16 |
-
|
17 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
18 |
-
$this->preparationSuccessful = true;
|
19 |
-
$this->prepareUrl($website);
|
20 |
-
$this->prepareHeaders($website);
|
21 |
-
return $this;
|
22 |
-
}
|
23 |
-
|
24 |
-
protected function prepareUrl(Mage_Core_Model_Website $website) {
|
25 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
26 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
27 |
-
if(is_null($siteKey)) {
|
28 |
-
$this->preparationSuccessful = false;
|
29 |
-
$this->errors["message"] = "Site key not set";
|
30 |
-
return;
|
31 |
-
}
|
32 |
-
|
33 |
-
static::$url = static::$PLATFORM_API_BASE_URL . $siteKey . "/build-autosuggest";
|
34 |
-
}
|
35 |
-
|
36 |
-
protected function prepareHeaders(Mage_Core_Model_Website $website) {
|
37 |
-
$apiKey = Mage::getResourceModel("choiceai_searchcore/config")
|
38 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::API_KEY);
|
39 |
-
$secretKey = Mage::getResourceModel("choiceai_searchcore/config")
|
40 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SECRET_KEY);
|
41 |
-
if(is_null($secretKey) || is_null($apiKey)) {
|
42 |
-
$this->preparationSuccessful = false;
|
43 |
-
$this->errors["message"] = "Site key not set";
|
44 |
-
return;
|
45 |
-
}
|
46 |
-
$this->headers["Authorization"] = base64_encode($apiKey.":" .$secretKey);
|
47 |
-
}
|
48 |
-
|
49 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
50 |
-
return $response;
|
51 |
-
}
|
52 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Feeddetails.php
DELETED
@@ -1,71 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Task_Feeddetails extends ChoiceAI_Searchcore_Model_Api_Task {
|
10 |
-
|
11 |
-
const method = Zend_Http_Client::GET;
|
12 |
-
|
13 |
-
const STATUS = 'status';
|
14 |
-
|
15 |
-
const MESSAGE = 'message';
|
16 |
-
|
17 |
-
const FEEDINFO = 'feedInfo';
|
18 |
-
|
19 |
-
const NUMDOCS = 'numDocs';
|
20 |
-
|
21 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
22 |
-
$this->preparationSuccessful = true;
|
23 |
-
$this->prepareUrl($website);
|
24 |
-
$this->prepareHeaders($website);
|
25 |
-
return $this;
|
26 |
-
}
|
27 |
-
|
28 |
-
protected function prepareUrl(Mage_Core_Model_Website $website) {
|
29 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
30 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
31 |
-
if(is_null($siteKey)) {
|
32 |
-
$this->preparationSuccessful = false;
|
33 |
-
$this->errors["message"] = "Site key not set";
|
34 |
-
return;
|
35 |
-
}
|
36 |
-
|
37 |
-
static::$url = static::$PLATFORM_API_BASE_URL . $siteKey . "/feed-info";
|
38 |
-
}
|
39 |
-
|
40 |
-
protected function prepareHeaders(Mage_Core_Model_Website $website) {
|
41 |
-
$apiKey = Mage::getResourceModel("choiceai_searchcore/config")
|
42 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::API_KEY);
|
43 |
-
$secretKey = Mage::getResourceModel("choiceai_searchcore/config")
|
44 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SECRET_KEY);
|
45 |
-
if(is_null($secretKey) || is_null($apiKey)) {
|
46 |
-
$this->preparationSuccessful = false;
|
47 |
-
$this->errors["message"] = "Site key not set";
|
48 |
-
return;
|
49 |
-
}
|
50 |
-
$this->headers["Authorization"] = base64_encode($apiKey.":" .$secretKey);
|
51 |
-
}
|
52 |
-
|
53 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
54 |
-
if(!$response->isSuccess()) {
|
55 |
-
return $response;
|
56 |
-
}
|
57 |
-
$responseObj = $response->getResponse();
|
58 |
-
if(!array_key_exists(self::STATUS, $responseObj) || !array_key_exists(self::FEEDINFO, $responseObj)) {
|
59 |
-
$response->setSuccess(false);
|
60 |
-
$response->setMessage('Invalid response from choiceai');
|
61 |
-
return $response;
|
62 |
-
}
|
63 |
-
if($responseObj[self::STATUS] != 200 || !array_key_exists(self::NUMDOCS, $responseObj[self::FEEDINFO])) {
|
64 |
-
$response->setSuccess(false);
|
65 |
-
$response->setMessage("status code :" .$responseObj[self::STATUS].",".
|
66 |
-
(array_key_exists(self::MESSAGE, $responseObj)?$responseObj[self::MESSAGE]:""));
|
67 |
-
return $response;
|
68 |
-
}
|
69 |
-
return $response;
|
70 |
-
}
|
71 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Searchimpression.php
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Task_Searchimpression extends ChoiceAI_Searchcore_Model_Api_Task
|
10 |
-
{
|
11 |
-
|
12 |
-
const method = Zend_Http_Client::GET;
|
13 |
-
|
14 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
15 |
-
$this->preparationSuccessful = true;
|
16 |
-
$this->prepareUrl($website);
|
17 |
-
$this->prepareHeaders($website);
|
18 |
-
return $this;
|
19 |
-
}
|
20 |
-
|
21 |
-
protected function prepareUrl(Mage_Core_Model_Website $website) {
|
22 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
23 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
24 |
-
if(is_null($siteKey)) {
|
25 |
-
$this->preparationSuccessful = false;
|
26 |
-
$this->errors["message"] = "Site key not set";
|
27 |
-
return;
|
28 |
-
}
|
29 |
-
|
30 |
-
static::$url = static::$RECOMMENDATION_SETTINGS_URL . "dashboard/analytics/hits/" . $siteKey;
|
31 |
-
}
|
32 |
-
|
33 |
-
protected function prepareHeaders(Mage_Core_Model_Website $website) {
|
34 |
-
$username = Mage::getResourceModel("choiceai_searchcore/config")
|
35 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::USERNAME);
|
36 |
-
if(is_null($username)) {
|
37 |
-
$this->preparationSuccessful = false;
|
38 |
-
$this->errors["message"] = "Secret key not set";
|
39 |
-
return;
|
40 |
-
}
|
41 |
-
|
42 |
-
$this->headers["authorization"] = "Basic " . base64_encode($username . ':$uauth');
|
43 |
-
}
|
44 |
-
|
45 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
46 |
-
$respObj = $response->getResponse();
|
47 |
-
if(array_key_exists("FunnelResponse", $respObj)) {
|
48 |
-
if(array_key_exists("Funnels",$respObj["FunnelResponse"])) {
|
49 |
-
return $response;
|
50 |
-
}
|
51 |
-
}
|
52 |
-
$response->setSuccess(false);
|
53 |
-
$response->setErrorMessage("Unexpected response from ChoiceAI server, Contact Support");
|
54 |
-
return $response;
|
55 |
-
}
|
56 |
-
}
|
57 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Searchsetup.php
DELETED
@@ -1,52 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Task_Searchsetup extends ChoiceAI_Searchcore_Model_Api_Task {
|
10 |
-
|
11 |
-
const method = Zend_Http_Client::POST;
|
12 |
-
|
13 |
-
const STATUS = 'status';
|
14 |
-
|
15 |
-
const MESSAGE = 'message';
|
16 |
-
|
17 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
18 |
-
$this->preparationSuccessful = true;
|
19 |
-
$this->prepareUrl($website);
|
20 |
-
$this->prepareHeaders($website);
|
21 |
-
return $this;
|
22 |
-
}
|
23 |
-
|
24 |
-
protected function prepareUrl(Mage_Core_Model_Website $website) {
|
25 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
26 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
27 |
-
if(is_null($siteKey)) {
|
28 |
-
$this->preparationSuccessful = false;
|
29 |
-
$this->errors["message"] = "Site key not set";
|
30 |
-
return;
|
31 |
-
}
|
32 |
-
|
33 |
-
static::$url = static::$PLATFORM_API_BASE_URL . $siteKey . "/complete-search";
|
34 |
-
}
|
35 |
-
|
36 |
-
protected function prepareHeaders(Mage_Core_Model_Website $website) {
|
37 |
-
$apiKey = Mage::getResourceModel("choiceai_searchcore/config")
|
38 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::API_KEY);
|
39 |
-
$secretKey = Mage::getResourceModel("choiceai_searchcore/config")
|
40 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SECRET_KEY);
|
41 |
-
if(is_null($secretKey) || is_null($apiKey)) {
|
42 |
-
$this->preparationSuccessful = false;
|
43 |
-
$this->errors["message"] = "Site key not set";
|
44 |
-
return;
|
45 |
-
}
|
46 |
-
$this->headers["Authorization"] = base64_encode($apiKey.":" .$secretKey);
|
47 |
-
}
|
48 |
-
|
49 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
50 |
-
return $response;
|
51 |
-
}
|
52 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Supportmail.php
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* @category ChoiceAI
|
4 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Task_Supportmail extends ChoiceAI_Searchcore_Model_Api_Task {
|
9 |
-
|
10 |
-
const method = Zend_Http_Client::POST;
|
11 |
-
protected $isRawData = true;
|
12 |
-
|
13 |
-
|
14 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
15 |
-
$this->preparationSuccessful = true;
|
16 |
-
$this->prepareUrl($website);
|
17 |
-
$this->prepareHeaders($website);
|
18 |
-
return $this;
|
19 |
-
}
|
20 |
-
|
21 |
-
protected function prepareUrl(Mage_Core_Model_Website $website) {
|
22 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
23 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
24 |
-
if(is_null($siteKey)) {
|
25 |
-
$this->preparationSuccessful = false;
|
26 |
-
$this->errors["message"] = "Site key not set";
|
27 |
-
return;
|
28 |
-
}
|
29 |
-
|
30 |
-
static::$url = static::$RECOMMENDATION_SETTINGS_URL . "dashboard/mail/support";
|
31 |
-
}
|
32 |
-
|
33 |
-
protected function prepareHeaders(Mage_Core_Model_Website $website) {
|
34 |
-
$username = Mage::getResourceModel("choiceai_searchcore/config")
|
35 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::USERNAME);
|
36 |
-
if(is_null($username)) {
|
37 |
-
$this->preparationSuccessful = false;
|
38 |
-
$this->errors["message"] = "Secret key not set";
|
39 |
-
return;
|
40 |
-
}
|
41 |
-
|
42 |
-
$this->headers["authorization"] = "Basic " . base64_encode($username . ':$uauth');
|
43 |
-
}
|
44 |
-
|
45 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
46 |
-
return $response;
|
47 |
-
}
|
48 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Trackcart.php
DELETED
@@ -1,46 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Task_Trackcart extends ChoiceAI_Searchcore_Model_Api_Task {
|
10 |
-
|
11 |
-
const method = Zend_Http_Client::POST;
|
12 |
-
|
13 |
-
const jsonResponse = false;
|
14 |
-
|
15 |
-
const TIMEOUT = 5;
|
16 |
-
|
17 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
18 |
-
$this->prepareUrl($website);
|
19 |
-
$this->isRawData = true;
|
20 |
-
return $this;
|
21 |
-
}
|
22 |
-
|
23 |
-
protected function prepareUrl(Mage_Core_Model_Website $website)
|
24 |
-
{
|
25 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
26 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
27 |
-
if (is_null($siteKey)) {
|
28 |
-
$this->errors["message"] = "Site key not set";
|
29 |
-
return;
|
30 |
-
}
|
31 |
-
|
32 |
-
$uid = array_key_exists('choiceai_userId', $_COOKIE) ? $_COOKIE['choiceai_userId'] : null;
|
33 |
-
if (!isset($uid) || is_null($uid)) {
|
34 |
-
$this->errors["message"] = "UID Missing";
|
35 |
-
return;
|
36 |
-
}
|
37 |
-
|
38 |
-
static::$url = static::$TRACKER_URL . "v1.0/$siteKey/track/cart/$uid";
|
39 |
-
$this->preparationSuccessful = true;
|
40 |
-
}
|
41 |
-
|
42 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
43 |
-
return $response;
|
44 |
-
}
|
45 |
-
}
|
46 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Trackorder.php
DELETED
@@ -1,46 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Task_Trackorder extends ChoiceAI_Searchcore_Model_Api_Task {
|
10 |
-
|
11 |
-
const method = Zend_Http_Client::POST;
|
12 |
-
|
13 |
-
const jsonResponse = false;
|
14 |
-
|
15 |
-
const TIMEOUT = 5;
|
16 |
-
|
17 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
18 |
-
$this->prepareUrl($website);
|
19 |
-
$this->isRawData = true;
|
20 |
-
return $this;
|
21 |
-
}
|
22 |
-
|
23 |
-
protected function prepareUrl(Mage_Core_Model_Website $website)
|
24 |
-
{
|
25 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
26 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
27 |
-
if (is_null($siteKey)) {
|
28 |
-
$this->errors["message"] = "Site key not set";
|
29 |
-
return;
|
30 |
-
}
|
31 |
-
|
32 |
-
$uid = array_key_exists('choiceai_userId', $_COOKIE) ? $_COOKIE['choiceai_userId'] : null;
|
33 |
-
if (!isset($uid) || is_null($uid)) {
|
34 |
-
$this->errors["message"] = "UID Missing";
|
35 |
-
return;
|
36 |
-
}
|
37 |
-
|
38 |
-
static::$url = static::$TRACKER_URL . "v1.0/$siteKey/track/order/$uid";
|
39 |
-
$this->preparationSuccessful = true;
|
40 |
-
}
|
41 |
-
|
42 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
43 |
-
return $response;
|
44 |
-
}
|
45 |
-
}
|
46 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Triggerfeedupload.php
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* class to validate the secret key and site key with choiceai
|
5 |
-
*
|
6 |
-
* @category ChoiceAI
|
7 |
-
* @package ChoiceAI_Searchcore
|
8 |
-
* @copyright Copyright (c) MineWhat
|
9 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
-
*/
|
11 |
-
class ChoiceAI_Searchcore_Model_Api_Task_Triggerfeedupload extends ChoiceAI_Searchcore_Model_Api_Task {
|
12 |
-
|
13 |
-
const method = Zend_Http_Client::POST;
|
14 |
-
|
15 |
-
const TIMEOUT = 5;
|
16 |
-
|
17 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
18 |
-
$this->preparationSuccessful = true;
|
19 |
-
$this->prepareUrl();
|
20 |
-
$this->prepareParams($website);
|
21 |
-
return $this;
|
22 |
-
}
|
23 |
-
|
24 |
-
protected function prepareUrl() {
|
25 |
-
static::$url = Mage::getBaseUrl()."searchcore/config/productsync";
|
26 |
-
return $this;
|
27 |
-
}
|
28 |
-
|
29 |
-
protected function prepareParams(Mage_Core_Model_Website $website) {
|
30 |
-
$this->setData("site", $website->getName());
|
31 |
-
$this->setData("auth", Mage::getSingleton('choiceai_searchcore/auth')->getAuthKey());
|
32 |
-
return $this;
|
33 |
-
}
|
34 |
-
|
35 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
36 |
-
$response->setSuccess(true);
|
37 |
-
$response->setErrors(array());
|
38 |
-
return $response;
|
39 |
-
}
|
40 |
-
}
|
41 |
-
|
42 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Updatefeaturefields.php
DELETED
@@ -1,83 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Api_Task_Updatefeaturefields extends ChoiceAI_Searchcore_Model_Api_Task {
|
10 |
-
|
11 |
-
const method = Zend_Http_Client::POST;
|
12 |
-
|
13 |
-
const STATUS = 'status';
|
14 |
-
|
15 |
-
const MESSAGE = 'message';
|
16 |
-
|
17 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
18 |
-
$this->preparationSuccessful = true;
|
19 |
-
$this->prepareUrl($website);
|
20 |
-
$this->prepareHeaders($website);
|
21 |
-
$this->prepareData($website);
|
22 |
-
$this->isRawData = true;
|
23 |
-
return $this;
|
24 |
-
}
|
25 |
-
|
26 |
-
protected function prepareUrl(Mage_Core_Model_Website $website) {
|
27 |
-
$siteKey = Mage::getResourceModel("choiceai_searchcore/config")
|
28 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY);
|
29 |
-
if(is_null($siteKey)) {
|
30 |
-
$this->preparationSuccessful = false;
|
31 |
-
$this->errors["message"] = "Site key not set";
|
32 |
-
return;
|
33 |
-
}
|
34 |
-
|
35 |
-
static::$url = static::$PLATFORM_API_BASE_URL . $siteKey . "/field-mapping";
|
36 |
-
}
|
37 |
-
|
38 |
-
protected function prepareHeaders(Mage_Core_Model_Website $website) {
|
39 |
-
$apiKey = Mage::getResourceModel("choiceai_searchcore/config")
|
40 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::API_KEY);
|
41 |
-
$secretKey = Mage::getResourceModel("choiceai_searchcore/config")
|
42 |
-
->getValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Confighelper::SECRET_KEY);
|
43 |
-
if(is_null($secretKey) || is_null($apiKey)) {
|
44 |
-
$this->preparationSuccessful = false;
|
45 |
-
$this->errors["message"] = "Site key not set";
|
46 |
-
return;
|
47 |
-
}
|
48 |
-
$this->headers["Authorization"] = base64_encode($apiKey.":" .$secretKey);
|
49 |
-
}
|
50 |
-
|
51 |
-
protected function prepareData($website) {
|
52 |
-
$featureFields = Mage::getResourceModel("choiceai_searchcore/field_collection")->getFeatureFields($website);
|
53 |
-
$featureFieldMap = array();
|
54 |
-
foreach($featureFields as $field) {
|
55 |
-
if($field[ChoiceAI_Searchcore_Model_Field::featured_field] == ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_IMAGE_URL) {
|
56 |
-
$featureFieldMap[$field[ChoiceAI_Searchcore_Model_Field::featured_field]] = "choiceai_NA";
|
57 |
-
continue;
|
58 |
-
}
|
59 |
-
$featureFieldMap[$field[ChoiceAI_Searchcore_Model_Field::featured_field]] =
|
60 |
-
$field[ChoiceAI_Searchcore_Model_Field::field_name];
|
61 |
-
}
|
62 |
-
$this->setData("fieldMapping", $featureFieldMap);
|
63 |
-
}
|
64 |
-
|
65 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
66 |
-
if(!$response->isSuccess()) {
|
67 |
-
return $response;
|
68 |
-
}
|
69 |
-
$responseObj = $response->getResponse();
|
70 |
-
if(!array_key_exists(self::STATUS, $responseObj)) {
|
71 |
-
$response->setSuccess(false);
|
72 |
-
$response->setMessage('Invalid response from choiceai');
|
73 |
-
return $response;
|
74 |
-
}
|
75 |
-
if($responseObj[self::STATUS] != 200) {
|
76 |
-
$response->setSuccess(false);
|
77 |
-
$response->setMessage("status code :" .$responseObj[self::STATUS].",".
|
78 |
-
(array_key_exists(self::MESSAGE, $responseObj)?$responseObj[self::MESSAGE]:""));
|
79 |
-
return $response;
|
80 |
-
}
|
81 |
-
return $response;
|
82 |
-
}
|
83 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Api/Task/Validatekeys.php
DELETED
@@ -1,73 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* class to validate the secret key and site key with choiceai
|
5 |
-
*
|
6 |
-
* @category ChoiceAI
|
7 |
-
* @package ChoiceAI_Searchcore
|
8 |
-
* @copyright Copyright (c) MineWhat
|
9 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
-
*/
|
11 |
-
class ChoiceAI_Searchcore_Model_Api_Task_Validatekeys extends ChoiceAI_Searchcore_Model_Api_Task {
|
12 |
-
|
13 |
-
const method = Zend_Http_Client::POST;
|
14 |
-
|
15 |
-
const SECRET_KEY = "secretKey";
|
16 |
-
|
17 |
-
const SITE_KEY = "siteKey";
|
18 |
-
|
19 |
-
const API_KEY = 'apiKey';
|
20 |
-
|
21 |
-
const USERNAME = 'username';
|
22 |
-
|
23 |
-
public function prepare(Mage_Core_Model_Website $website) {
|
24 |
-
$this->prepareUrl();
|
25 |
-
$this->prepareHeaders($website);
|
26 |
-
$this->prepareParams();
|
27 |
-
return $this;
|
28 |
-
}
|
29 |
-
|
30 |
-
protected function prepareUrl() {
|
31 |
-
static::$url = static::$RECOMMENDATION_SETTINGS_URL . "dashboard/authenticateMagento";
|
32 |
-
return $this;
|
33 |
-
}
|
34 |
-
|
35 |
-
protected function prepareHeaders() {
|
36 |
-
return $this;
|
37 |
-
}
|
38 |
-
|
39 |
-
protected function prepareParams() {
|
40 |
-
$params = $this->getData();
|
41 |
-
if(!array_key_exists(static::SECRET_KEY, $params)) {
|
42 |
-
$this->preparationSuccessful = false;
|
43 |
-
$this->errors[ChoiceAI_Searchcore_Helper_Confighelper::SECRET_KEY] = "secret key expected";
|
44 |
-
}
|
45 |
-
if(!array_key_exists(static::SITE_KEY, $params)) {
|
46 |
-
$this->preparationSuccessful = false;
|
47 |
-
$this->errors[ChoiceAI_Searchcore_Helper_Confighelper::SITE_KEY] = "site key expected";
|
48 |
-
}
|
49 |
-
if(sizeof($this->getData()) > 2) {
|
50 |
-
$this->preparationSuccessful = false;
|
51 |
-
$this->errors["message"] = "Extra Parameters Present";
|
52 |
-
}
|
53 |
-
if(sizeof($this->errors) == 0) {
|
54 |
-
$this->preparationSuccessful = true;
|
55 |
-
}
|
56 |
-
$this->isRawData = true;
|
57 |
-
return $this;
|
58 |
-
}
|
59 |
-
|
60 |
-
protected function postProcess(ChoiceAI_Searchcore_Model_Api_Response $response) {
|
61 |
-
if(!$response->isSuccess()) {
|
62 |
-
return $response;
|
63 |
-
}
|
64 |
-
$responseObj = $response->getResponse();
|
65 |
-
if(!array_key_exists(self::API_KEY, $responseObj) || !array_key_exists(self::USERNAME, $responseObj)) {
|
66 |
-
$response->setSuccess(false);
|
67 |
-
$response->setMessage('Invalid Combination, Please Refer Docs');
|
68 |
-
}
|
69 |
-
return $response;
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Config.php
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* This class maintains all the configuration w.r.t ChoiceAI with site basis
|
5 |
-
*
|
6 |
-
* @category ChoiceAI
|
7 |
-
* @package ChoiceAI_Searchcore
|
8 |
-
* @copyright Copyright (c) MineWhat
|
9 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
-
*/
|
11 |
-
class ChoiceAI_Searchcore_Model_Config extends Mage_Core_Model_Abstract {
|
12 |
-
|
13 |
-
const KEY = "choiceai_key";
|
14 |
-
|
15 |
-
const VALUE = 'value';
|
16 |
-
|
17 |
-
const WEBSITE_ID = 'website_id';
|
18 |
-
|
19 |
-
const FEED_LOCK_TIME = 'feed_lock_time';
|
20 |
-
|
21 |
-
const FEED_LOCK = 'feed_lock';
|
22 |
-
|
23 |
-
const FEED_LOCK_TRUE = '1';
|
24 |
-
|
25 |
-
const FEED_LOCK_FALSE = '0';
|
26 |
-
|
27 |
-
const FEED_STATUS = 'feed_status';
|
28 |
-
|
29 |
-
const MAX_FEED_LOCK_TIME = 6;
|
30 |
-
|
31 |
-
const LAST_UPLOAD_TIME = 'lastUpload';
|
32 |
-
|
33 |
-
const FILTER_DELIMITER = "|`";
|
34 |
-
|
35 |
-
const FILTER = 'filter';
|
36 |
-
|
37 |
-
/**
|
38 |
-
*
|
39 |
-
* @return void
|
40 |
-
*/
|
41 |
-
protected function _construct()
|
42 |
-
{
|
43 |
-
$this->_init('choiceai_searchcore/config');
|
44 |
-
}
|
45 |
-
}
|
46 |
-
|
47 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Field.php
DELETED
@@ -1,342 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* This class maintains the config of the fields that are needed by choiceai
|
5 |
-
*
|
6 |
-
* @category ChoiceAI
|
7 |
-
* @package ChoiceAI_Searchcore
|
8 |
-
* @copyright Copyright (c) MineWhat
|
9 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
-
*/
|
11 |
-
class ChoiceAI_Searchcore_Model_Field extends Mage_Core_Model_Abstract
|
12 |
-
{
|
13 |
-
|
14 |
-
/**
|
15 |
-
* field name column in db
|
16 |
-
*/
|
17 |
-
const field_name = "field_name";
|
18 |
-
|
19 |
-
/**
|
20 |
-
* datatype column name in db
|
21 |
-
*/
|
22 |
-
const datatype = "datatype";
|
23 |
-
|
24 |
-
/**
|
25 |
-
* autosuggest column name in db
|
26 |
-
*/
|
27 |
-
const autosuggest = "autosuggest";
|
28 |
-
|
29 |
-
/**
|
30 |
-
* featured_field column name in db
|
31 |
-
*/
|
32 |
-
const featured_field = "featured_field";
|
33 |
-
|
34 |
-
/**
|
35 |
-
* displayable column name in db
|
36 |
-
*/
|
37 |
-
const dislayable = "displayed";
|
38 |
-
|
39 |
-
const multivalued = 'multivalued';
|
40 |
-
|
41 |
-
/**
|
42 |
-
* website id column name in db
|
43 |
-
*/
|
44 |
-
const website_id = "website_id";
|
45 |
-
|
46 |
-
const status = 'status';
|
47 |
-
|
48 |
-
/**
|
49 |
-
* All possible data type values supported choiceai
|
50 |
-
* @var array
|
51 |
-
*/
|
52 |
-
public static $data_types = array(ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_TEXT, ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_LONGTEXT,
|
53 |
-
ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_LINK, ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER,
|
54 |
-
ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_DECIMAL, ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_DATE);
|
55 |
-
|
56 |
-
|
57 |
-
public static $displayableFeatureFields = array('title', 'price',
|
58 |
-
'brand', 'color', 'size', 'imageUrl', 'productUrl');
|
59 |
-
|
60 |
-
public static $featurefields = array();
|
61 |
-
|
62 |
-
/**
|
63 |
-
*
|
64 |
-
* @return void
|
65 |
-
*/
|
66 |
-
protected function _construct()
|
67 |
-
{
|
68 |
-
$this->_init('choiceai_searchcore/field');
|
69 |
-
ChoiceAI_Searchcore_Model_Field::$featurefields = $this->getFeaturedFields();
|
70 |
-
|
71 |
-
}
|
72 |
-
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Save fields
|
76 |
-
*
|
77 |
-
* @return void
|
78 |
-
*/
|
79 |
-
public function saveFields($collection)
|
80 |
-
{
|
81 |
-
$this->_getResource()->beginTransaction();
|
82 |
-
try {
|
83 |
-
foreach ($collection as $data) {
|
84 |
-
if (sizeof($data) > 0) {
|
85 |
-
if (array_key_exists("add", $data)) {
|
86 |
-
$data["add"]->save();
|
87 |
-
} else if (array_key_exists("delete", $data)) {
|
88 |
-
$data["delete"]->delete();
|
89 |
-
}
|
90 |
-
}
|
91 |
-
}
|
92 |
-
|
93 |
-
$this->_getResource()->commit();
|
94 |
-
} catch (Exception $e) {
|
95 |
-
$this->_getResource()->rollBack();
|
96 |
-
Mage::helper("choiceai_searchcore")->log(Zend_Log::ERR, "Saving fields failed because " . $e->getMessage());
|
97 |
-
return array('OTHERS' => $e->getMessage());
|
98 |
-
}
|
99 |
-
return true;
|
100 |
-
|
101 |
-
}
|
102 |
-
|
103 |
-
/*
|
104 |
-
* method to get the featured fields
|
105 |
-
*/
|
106 |
-
public function getFeaturedFields()
|
107 |
-
{
|
108 |
-
$featuredFields = array();
|
109 |
-
$featuredFields["uniqueId"] = $this->getField("text", "false", "false");
|
110 |
-
$featuredFields["sellingPrice"] = $this->getField("decimal", "false", "false");
|
111 |
-
$featuredFields["discount"] = $this->getField("decimal", "false", "false");
|
112 |
-
$featuredFields["rating"] = $this->getField("decimal", "false", "false");
|
113 |
-
$featuredFields["brandId"] = $this->getField("text", "false", "false");
|
114 |
-
$featuredFields[ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_1_NAME] =
|
115 |
-
$this->getField("text", "false", "false");
|
116 |
-
$featuredFields[ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_2_NAME] =
|
117 |
-
$this->getField("text", "false", "false");
|
118 |
-
$featuredFields[ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_3_NAME] =
|
119 |
-
$this->getField("text", "false", "false");
|
120 |
-
$featuredFields[ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_4_NAME] =
|
121 |
-
$this->getField("text", "false", "false");
|
122 |
-
$featuredFields[ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_1] =
|
123 |
-
$this->getField("text", "true", "false");
|
124 |
-
$featuredFields[ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_2] =
|
125 |
-
$this->getField("text", "true", "false");
|
126 |
-
$featuredFields[ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_3] =
|
127 |
-
$this->getField("text", "true", "false");
|
128 |
-
$featuredFields[ChoiceAI_Searchcore_Model_Resource_Field::CAT_LEVEL_4] =
|
129 |
-
$this->getField("text", "true", "false");
|
130 |
-
$featuredFields["category"] = $this->getField("text", "true", "true");
|
131 |
-
$featuredFields["subCategory"] = $this->getField("text", "true", "true");
|
132 |
-
$featuredFields["color"] = $this->getField("text", "true", "false");
|
133 |
-
$featuredFields["size"] = $this->getField("text", "true", "false");
|
134 |
-
$featuredFields["availability"] = $this->getField("bool", "false", "false");
|
135 |
-
$featuredFields["description"] = $this->getField("longText", "false", "false");
|
136 |
-
$featuredFields["imageUrl"] = $this->getField("link", "true", "false");
|
137 |
-
$featuredFields["productUrl"] = $this->getField("link", "false", "false");
|
138 |
-
$featuredFields["brand"] = $this->getField("text", "false", "true");
|
139 |
-
$featuredFields["price"] = $this->getField("decimal", "false", "false");
|
140 |
-
$featuredFields["title"] = $this->getField("text", "false", "true");
|
141 |
-
$featuredFields["gender"] = $this->getField("text", "false", "false");
|
142 |
-
$featuredFields["choiceaiVisibility"] = $this->getField("text", "false", "false");
|
143 |
-
return $featuredFields;
|
144 |
-
}
|
145 |
-
|
146 |
-
public function getField($dataType, $multiValued, $autosuggest)
|
147 |
-
{
|
148 |
-
return array(self::status => 1, self::datatype => $dataType,
|
149 |
-
self::multivalued => ($multiValued == "true") ? 1 : 0,
|
150 |
-
self::autosuggest => ($autosuggest == "true") ? 1 : 0);
|
151 |
-
|
152 |
-
}
|
153 |
-
|
154 |
-
public function rebuildConfigCache(Mage_Core_Model_Website $website) {
|
155 |
-
$this->setBrandFieldName($website);
|
156 |
-
$this->setCategoryFieldName($website);
|
157 |
-
$this->setImageUrlFieldName($website);
|
158 |
-
$this->setPriceFieldName($website);
|
159 |
-
$this->setProductUrlFieldName($website);
|
160 |
-
$this->setTitleFieldName($website);
|
161 |
-
}
|
162 |
-
|
163 |
-
public function getPriceFieldName()
|
164 |
-
{
|
165 |
-
$priceFieldConfig =
|
166 |
-
Mage::helper('choiceai_searchcore')->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRICE);
|
167 |
-
if (array_key_exists(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRICE, $priceFieldConfig)) {
|
168 |
-
return $priceFieldConfig[ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRICE];
|
169 |
-
}
|
170 |
-
$this->rebuildConfigCache(Mage::app()->getWebsite());
|
171 |
-
$priceField = $this->_getResource()->getFieldByFeatureField(Mage::app()->getWebsite()->getWebsiteId(),
|
172 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRICE);
|
173 |
-
return $priceField;
|
174 |
-
}
|
175 |
-
|
176 |
-
public function setPriceFieldName(Mage_Core_Model_Website $website) {
|
177 |
-
$priceName = $this->getResource()->getFieldByFeatureField($website->getWebsiteId(),
|
178 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRICE);
|
179 |
-
Mage::helper('choiceai_searchcore')->saveConfig($website,
|
180 |
-
array(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRICE => $priceName));
|
181 |
-
}
|
182 |
-
|
183 |
-
public function getImageUrlFieldName()
|
184 |
-
{
|
185 |
-
$imageUrlFieldName = $this->_getResource()->getFieldByFeatureField(Mage::app()->getWebsite()->getWebsiteId(),
|
186 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_IMAGE_URL);
|
187 |
-
return $imageUrlFieldName;
|
188 |
-
}
|
189 |
-
|
190 |
-
public function setImageUrlFieldName(Mage_Core_Model_Website $website)
|
191 |
-
{
|
192 |
-
$imageField = $this->getResource()->getFieldByFeatureField($website->getWebsiteId(),
|
193 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_IMAGE_URL);
|
194 |
-
Mage::helper('choiceai_searchcore')->saveConfig($website,
|
195 |
-
array(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_IMAGE_URL => $imageField));
|
196 |
-
}
|
197 |
-
|
198 |
-
public function getProductUrlFieldName()
|
199 |
-
{
|
200 |
-
$fieldConfig =
|
201 |
-
Mage::helper('choiceai_searchcore')
|
202 |
-
->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRODUCT_URL);
|
203 |
-
if(array_key_exists(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRODUCT_URL, $fieldConfig)) {
|
204 |
-
return $fieldConfig[ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRODUCT_URL];
|
205 |
-
}
|
206 |
-
$this->rebuildConfigCache(Mage::app()->getWebsite());
|
207 |
-
$productUrl = $this->_getResource()->getFieldByFeatureField(Mage::app()->getWebsite()->getWebsiteId(),
|
208 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRODUCT_URL);
|
209 |
-
return $productUrl;
|
210 |
-
|
211 |
-
}
|
212 |
-
|
213 |
-
public function setProductUrlFieldName(Mage_Core_Model_Website $website)
|
214 |
-
{
|
215 |
-
$productUrlField = $this->getResource()->getFieldByFeatureField($website->getWebsiteId(),
|
216 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRODUCT_URL);
|
217 |
-
Mage::helper('choiceai_searchcore')->saveConfig($website,
|
218 |
-
array(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_PRODUCT_URL => $productUrlField));
|
219 |
-
}
|
220 |
-
|
221 |
-
public function getCategoryFieldName()
|
222 |
-
{
|
223 |
-
$fieldConfig =
|
224 |
-
Mage::helper('choiceai_searchcore')
|
225 |
-
->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_CATEGORY);
|
226 |
-
if(array_key_exists(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_CATEGORY, $fieldConfig)) {
|
227 |
-
return $fieldConfig[ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_CATEGORY];
|
228 |
-
}
|
229 |
-
$this->rebuildConfigCache(Mage::app()->getWebsite());
|
230 |
-
$categoryField = $this->_getResource()->getFieldByFeatureField(Mage::app()->getWebsite()->getWebsiteId(),
|
231 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_CATEGORY);
|
232 |
-
return $categoryField;
|
233 |
-
}
|
234 |
-
|
235 |
-
public function setCategoryFieldName(Mage_Core_Model_Website $website)
|
236 |
-
{
|
237 |
-
$categortField = $this->getResource()->getFieldByFeatureField($website->getWebsiteId(),
|
238 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_CATEGORY);
|
239 |
-
Mage::helper('choiceai_searchcore')->saveConfig($website,
|
240 |
-
array(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_CATEGORY => $categortField));
|
241 |
-
}
|
242 |
-
|
243 |
-
public function getBrandFieldName()
|
244 |
-
{
|
245 |
-
$fieldConfig =
|
246 |
-
Mage::helper('choiceai_searchcore')
|
247 |
-
->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_BRAND);
|
248 |
-
if(array_key_exists(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_BRAND, $fieldConfig)) {
|
249 |
-
return $fieldConfig[ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_BRAND];
|
250 |
-
}
|
251 |
-
$this->rebuildConfigCache(Mage::app()->getWebsite());
|
252 |
-
$brandField = $this->_getResource()->getFieldByFeatureField(Mage::app()->getWebsite()->getWebsiteId(),
|
253 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_BRAND);
|
254 |
-
return $brandField;
|
255 |
-
}
|
256 |
-
|
257 |
-
public function setBrandFieldName(Mage_Core_Model_Website $website)
|
258 |
-
{
|
259 |
-
$brandField = $this->getResource()->getFieldByFeatureField($website->getWebsiteId(),
|
260 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_BRAND);
|
261 |
-
Mage::helper('choiceai_searchcore')->saveConfig($website,
|
262 |
-
array(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_BRAND => $brandField));
|
263 |
-
}
|
264 |
-
|
265 |
-
public function getTitleFieldName()
|
266 |
-
{
|
267 |
-
$fieldConfig =
|
268 |
-
Mage::helper('choiceai_searchcore')
|
269 |
-
->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_TITLE);
|
270 |
-
if(array_key_exists(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_TITLE, $fieldConfig)) {
|
271 |
-
return $fieldConfig[ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_TITLE];
|
272 |
-
}
|
273 |
-
$this->rebuildConfigCache(Mage::app()->getWebsite());
|
274 |
-
$titleField = $this->_getResource()->getFieldByFeatureField(Mage::app()->getWebsite()->getWebsiteId(),
|
275 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_TITLE);
|
276 |
-
return $titleField;
|
277 |
-
}
|
278 |
-
|
279 |
-
public function setTitleFieldName(Mage_Core_Model_Website $website)
|
280 |
-
{
|
281 |
-
$titleField = $this->getResource()->getFieldByFeatureField($website->getWebsiteId(),
|
282 |
-
ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_TITLE);
|
283 |
-
Mage::helper('choiceai_searchcore')->saveConfig($website,
|
284 |
-
array(ChoiceAI_Searchcore_Helper_Constants::FEATURE_FIELD_TITLE => $titleField));
|
285 |
-
}
|
286 |
-
|
287 |
-
public function getImageFields($website)
|
288 |
-
{
|
289 |
-
$conf = Mage::helper('choiceai_searchcore')->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::FIELD_CONF, $website, true);
|
290 |
-
$fieldConf = json_decode($conf[ChoiceAI_Searchcore_Helper_Constants::FIELD_CONF], true);
|
291 |
-
if (!is_array($fieldConf)) {
|
292 |
-
return array();
|
293 |
-
}
|
294 |
-
$imageFields = array();
|
295 |
-
foreach ($fieldConf as $field => $conf) {
|
296 |
-
if (!is_array($conf) || !array_key_exists('image_full', $conf)) {
|
297 |
-
continue;
|
298 |
-
}
|
299 |
-
$imageFields[$field] = Mage::helper('choiceai_searchcore')->isConfigTrue($website, 'image_full') ? true : false;
|
300 |
-
}
|
301 |
-
return $imageFields;
|
302 |
-
}
|
303 |
-
|
304 |
-
public function getCopyFields($website)
|
305 |
-
{
|
306 |
-
$conf = Mage::helper('choiceai_searchcore')->getEngineConfigData(ChoiceAI_Searchcore_Helper_Constants::FIELD_CONF, $website, true);
|
307 |
-
|
308 |
-
$fieldConf = json_decode($conf[ChoiceAI_Searchcore_Helper_Constants::FIELD_CONF], true);
|
309 |
-
if (!is_array($fieldConf)) {
|
310 |
-
return array();
|
311 |
-
}
|
312 |
-
$imageFields = array();
|
313 |
-
foreach ($fieldConf as $field => $conf) {
|
314 |
-
if (!is_array($conf) || !array_key_exists('copy_field', $conf)) {
|
315 |
-
continue;
|
316 |
-
}
|
317 |
-
$imageFields[$field] = $conf['copy_field'];
|
318 |
-
}
|
319 |
-
return $imageFields;
|
320 |
-
}
|
321 |
-
|
322 |
-
public function validateDatatype($choiceaiDatatype, $magentoDatatype)
|
323 |
-
{
|
324 |
-
if ($choiceaiDatatype == ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_TEXT || $choiceaiDatatype == ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_LONGTEXT ||
|
325 |
-
$choiceaiDatatype == ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_LINK
|
326 |
-
) {
|
327 |
-
return true;
|
328 |
-
}
|
329 |
-
if ($choiceaiDatatype == ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER && $magentoDatatype == ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_NUMBER) {
|
330 |
-
return true;
|
331 |
-
}
|
332 |
-
if ($choiceaiDatatype == ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_DECIMAL && $magentoDatatype == ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_NUMBER) {
|
333 |
-
return true;
|
334 |
-
}
|
335 |
-
if ($choiceaiDatatype == ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_DATE && $magentoDatatype == ChoiceAI_Searchcore_Helper_Constants::FIELD_TYPE_DATE) {
|
336 |
-
return true;
|
337 |
-
}
|
338 |
-
return false;
|
339 |
-
}
|
340 |
-
}
|
341 |
-
|
342 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Observer.php
DELETED
@@ -1,201 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Observer {
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Observer method to track the add to cart
|
13 |
-
* @return $this
|
14 |
-
*/
|
15 |
-
public function trackAddToCart(Varien_Event_Observer $observer) {
|
16 |
-
if(!Mage::helper('choiceai_searchcore')->isExecutable()) {
|
17 |
-
return;
|
18 |
-
}
|
19 |
-
$product = $observer->getEvent()->getProduct();
|
20 |
-
if(!$product instanceof Mage_Catalog_Model_Product) {
|
21 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'CART_TRACKER:product is not a valid type');
|
22 |
-
return $this;
|
23 |
-
}
|
24 |
-
$uniqueId = Mage::helper('choiceai_searchcore/feedhelper')->getUniqueId($product);
|
25 |
-
$response = Mage::getModel('choiceai_searchcore/api_task_trackcart')
|
26 |
-
->setData('data', array('pid' => $uniqueId,
|
27 |
-
'visit_type' => 'repeat'))
|
28 |
-
->setData('ip', isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR'])
|
29 |
-
->setData('agent', $_SERVER['HTTP_USER_AGENT'])
|
30 |
-
->prepare(Mage::app()->getWebsite())
|
31 |
-
->process();
|
32 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::DEBUG, "CART_TRACKER: request with uniqueId ".$uniqueId);
|
33 |
-
if(!$response->isSuccess()) {
|
34 |
-
Mage::helper('choiceai_searchcore')
|
35 |
-
->log(Zend_Log::ERR, 'CART_TRACKER:request failed because ' .json_encode($response->getErrors()));
|
36 |
-
}
|
37 |
-
return $this;
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Observer method to track orders
|
42 |
-
* @return $this
|
43 |
-
*/
|
44 |
-
public function trackOrder(Varien_Event_Observer $observer) {
|
45 |
-
if(!Mage::helper('choiceai_searchcore')->isExecutable()) {
|
46 |
-
return;
|
47 |
-
}
|
48 |
-
$payment = $observer->getEvent()->getPayment();
|
49 |
-
/* @var Mage_Sales_Model_Order_Payment */
|
50 |
-
|
51 |
-
if(!$payment instanceof Mage_Sales_Model_Order_Payment) {
|
52 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::ERR, 'ORDER_TRACKER:payment is not a valid type');
|
53 |
-
return $this;
|
54 |
-
}
|
55 |
-
$items = $payment->getOrder()->getAllVisibleItems();
|
56 |
-
|
57 |
-
if(!is_array($items)) {
|
58 |
-
return $this;
|
59 |
-
}
|
60 |
-
|
61 |
-
foreach($items as $item) {
|
62 |
-
if($item instanceof Mage_Sales_Model_Order) {
|
63 |
-
Mage::helper('choiceai_searchcore')
|
64 |
-
->log(Zend_Log::ERR, 'ORDER_TRACKER:request failed because item is of instancetype ' . get_class($item));
|
65 |
-
continue;
|
66 |
-
}
|
67 |
-
$product =$item->getProduct();
|
68 |
-
if(!$product instanceof Mage_Catalog_Model_Product) {
|
69 |
-
return $this;
|
70 |
-
}
|
71 |
-
$uniqueId = Mage::helper('choiceai_searchcore/feedhelper')->getUniqueId($product, $item);
|
72 |
-
$response = Mage::getModel('choiceai_searchcore/api_task_trackorder')
|
73 |
-
->setData('data',
|
74 |
-
array('visit_type' => 'repeat',
|
75 |
-
'pid' => $uniqueId,
|
76 |
-
'qty' => $item->getQtyOrdered(),
|
77 |
-
'price' => $item->getPriceInclTax()))
|
78 |
-
->setData('ip', isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'])
|
79 |
-
->setData('agent', $_SERVER['HTTP_USER_AGENT'])
|
80 |
-
->prepare(Mage::app()->getWebsite())
|
81 |
-
->process();
|
82 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::DEBUG, "ORDER_TRACKER: request with uniqueId ".$uniqueId);
|
83 |
-
|
84 |
-
if(!$response->isSuccess()) {
|
85 |
-
Mage::helper('choiceai_searchcore')
|
86 |
-
->log(Zend_Log::ERR, 'ORDER_TRACKER:request failed because ' . json_encode($response->getErrors()));
|
87 |
-
}
|
88 |
-
Mage::getSingleton('choiceai_searchcore/sync')->addProduct($product);
|
89 |
-
}
|
90 |
-
return $this;
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Method to sync the product catalog through cron
|
95 |
-
* @param Varien_Event_Observer $observer
|
96 |
-
* @return $this
|
97 |
-
*/
|
98 |
-
public function syncFull($observer)
|
99 |
-
{
|
100 |
-
if(!Mage::helper('choiceai_searchcore')->isExecutable()) {
|
101 |
-
return;
|
102 |
-
}
|
103 |
-
$websiteCollection = Mage::getModel('core/website')->getCollection()->load();
|
104 |
-
if(!$websiteCollection instanceof Varien_Data_Collection) {
|
105 |
-
return $this;
|
106 |
-
}
|
107 |
-
foreach ($websiteCollection as $website) {
|
108 |
-
if($website instanceof Mage_Core_Model_Website) {
|
109 |
-
return $this;
|
110 |
-
}
|
111 |
-
Mage::getResourceModel('choiceai_searchcore/config')
|
112 |
-
->setValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Constants::IS_CRON_ENABLED, 1);
|
113 |
-
Mage::getSingleton('choiceai_searchcore/feed_feedmanager')->process(true, $website);
|
114 |
-
}
|
115 |
-
return $this;
|
116 |
-
}
|
117 |
-
|
118 |
-
/*
|
119 |
-
* Method to sync the product incremental catalog through cron
|
120 |
-
* @param Varien_Event_Observer $observer
|
121 |
-
* @return $this
|
122 |
-
*/
|
123 |
-
public function syncIncremental($observer)
|
124 |
-
{
|
125 |
-
if(!Mage::helper('choiceai_searchcore')->isExecutable()) {
|
126 |
-
return;
|
127 |
-
}
|
128 |
-
$websiteCollection = Mage::getModel('core/website')->getCollection()->load();
|
129 |
-
if(!$websiteCollection instanceof Varien_Data_Collection) {
|
130 |
-
return $this;
|
131 |
-
}
|
132 |
-
foreach ($websiteCollection as $website) {
|
133 |
-
if($website instanceof Mage_Core_Model_Website) {
|
134 |
-
return $this;
|
135 |
-
}
|
136 |
-
Mage::getResourceModel('choiceai_searchcore/config')
|
137 |
-
->setValue($website->getWebsiteId(), ChoiceAI_Searchcore_Helper_Constants::IS_CRON_ENABLED, 1);
|
138 |
-
Mage::getSingleton('choiceai_searchcore/feed_feedmanager')->process(false, $website);
|
139 |
-
}
|
140 |
-
return $this;
|
141 |
-
}
|
142 |
-
|
143 |
-
/**
|
144 |
-
* Method to track deleted product
|
145 |
-
* @param Varien_Event_Observer $observer
|
146 |
-
* @return void
|
147 |
-
*/
|
148 |
-
public function trackDelete(Varien_Event_Observer $observer) {
|
149 |
-
if(!Mage::helper('choiceai_searchcore')->isExecutable()) {
|
150 |
-
return $this;
|
151 |
-
}
|
152 |
-
$product = $observer->getEvent()->getDataObject();
|
153 |
-
if(!$product instanceof Mage_Catalog_Model_Product) {
|
154 |
-
return $this;
|
155 |
-
}
|
156 |
-
$parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
|
157 |
-
if(!$parentIds)
|
158 |
-
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
|
159 |
-
|
160 |
-
if(!is_array($parentIds)) {
|
161 |
-
return $this;
|
162 |
-
}
|
163 |
-
|
164 |
-
foreach($parentIds as $parentId) {
|
165 |
-
$parentProduct = Mage::getModel('catalog/product')->load($parentId);
|
166 |
-
if($parentProduct instanceof Mage_Catalog_Model_Product) {
|
167 |
-
return $this;
|
168 |
-
}
|
169 |
-
Mage::getSingleton('choiceai_searchcore/sync')->addProduct($parentProduct);
|
170 |
-
}
|
171 |
-
Mage::getSingleton('choiceai_searchcore/sync')->deleteProduct($product);
|
172 |
-
return $this;
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Method to track deleted product
|
177 |
-
* @param Varien_Event_Observer $observer
|
178 |
-
* @return void
|
179 |
-
*/
|
180 |
-
|
181 |
-
public function catalogInventorySave(Varien_Event_Observer $observer) {
|
182 |
-
if(!Mage::helper('choiceai_searchcore')->isExecutable()) {
|
183 |
-
return;
|
184 |
-
}
|
185 |
-
$_item = $observer->getEvent()->getItem();
|
186 |
-
if(!$_item instanceof Mage_Catalog_Order_Item) {
|
187 |
-
return $this;
|
188 |
-
}
|
189 |
-
$product = $_item->getProduct();
|
190 |
-
if(!$product instanceof Mage_Catalog_Model_Product) {
|
191 |
-
return $this;
|
192 |
-
}
|
193 |
-
Mage::getSingleton('choiceai_searchcore/sync')->addProduct($product);
|
194 |
-
return $this;
|
195 |
-
}
|
196 |
-
|
197 |
-
public function saleOrderCancel(Varien_Event_Observer $observer) {
|
198 |
-
return $this;
|
199 |
-
}
|
200 |
-
}
|
201 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Resource/Attribute.php
DELETED
@@ -1,27 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* @category ChoiceAI
|
4 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Resource_Attribute {
|
9 |
-
|
10 |
-
protected $attributeMap = array();
|
11 |
-
public function getAttributeValue($attributeCode, $value, $product){
|
12 |
-
if(!isset($this->attributeMap[$value])){
|
13 |
-
if(!($product instanceof Mage_Catalog_Model_Product) || Mage::getResourceModel('catalog/product')->getAttribute($attributeCode) == null){
|
14 |
-
return null;
|
15 |
-
}
|
16 |
-
$options = Mage::getResourceModel('catalog/product')->getAttribute($attributeCode)
|
17 |
-
->getSource()->getAllOptions();
|
18 |
-
foreach($options as $option){
|
19 |
-
$this->attributeMap[$option["value"]] = $option["label"];
|
20 |
-
}
|
21 |
-
}
|
22 |
-
return array_key_exists($value, $this->attributeMap)?$this->attributeMap[$value]:null;
|
23 |
-
}
|
24 |
-
|
25 |
-
}
|
26 |
-
|
27 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Resource/Config.php
DELETED
@@ -1,213 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Resource_Config extends Mage_Core_Model_Mysql4_Abstract
|
10 |
-
{
|
11 |
-
|
12 |
-
/**
|
13 |
-
* ChoiceAI Config table Name
|
14 |
-
*
|
15 |
-
* @var string
|
16 |
-
*/
|
17 |
-
protected $_choiceaiConfigTable;
|
18 |
-
|
19 |
-
// date format
|
20 |
-
const DATE_FORMAT = 'Y-m-d H:i:s';
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @return void
|
24 |
-
*/
|
25 |
-
protected function _construct()
|
26 |
-
{
|
27 |
-
$this->_init('choiceai_searchcore/config', 'id');
|
28 |
-
$this->_choiceaiConfigTable = $this->getTable('choiceai_searchcore/config');
|
29 |
-
}
|
30 |
-
|
31 |
-
public function getValues($websiteId, $key) {
|
32 |
-
if(!isset($key) || is_array($key) ){
|
33 |
-
return array();
|
34 |
-
}
|
35 |
-
$adapter = $this->_getReadAdapter();
|
36 |
-
$select = $adapter->select()
|
37 |
-
->from($this->_choiceaiConfigTable, ChoiceAI_Searchcore_Model_Config::VALUE)
|
38 |
-
->where(ChoiceAI_Searchcore_Model_Config::WEBSITE_ID.' = ?', (int)$websiteId)
|
39 |
-
->where(ChoiceAI_Searchcore_Model_Config::KEY.' = ?', $key);
|
40 |
-
$rows = $adapter->fetchAll($select);
|
41 |
-
$values = array();
|
42 |
-
foreach($rows as $row) {
|
43 |
-
if(array_key_exists(ChoiceAI_Searchcore_Model_Config::VALUE, $row)) {
|
44 |
-
$values[] = $row[ChoiceAI_Searchcore_Model_Config::VALUE];
|
45 |
-
}
|
46 |
-
}
|
47 |
-
return $values;
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* @param $website_id
|
52 |
-
* @param $key
|
53 |
-
* @return null|string
|
54 |
-
*/
|
55 |
-
public function getValue($website_id, $key)
|
56 |
-
{
|
57 |
-
$adapter = $this->_getReadAdapter();
|
58 |
-
if(is_array($key)) {
|
59 |
-
$keyValuePair = array();
|
60 |
-
foreach ($key as $eachKey) {
|
61 |
-
$keyValuePair[$eachKey] = $this->getValue($website_id, $eachKey);
|
62 |
-
}
|
63 |
-
return $keyValuePair;
|
64 |
-
}
|
65 |
-
$select = $adapter->select()
|
66 |
-
->from($this->_choiceaiConfigTable, 'value')
|
67 |
-
->where('`'.ChoiceAI_Searchcore_Model_Config::WEBSITE_ID.'` = ?', (int)$website_id)
|
68 |
-
->where('`'.ChoiceAI_Searchcore_Model_Config::KEY.'` = ?', $key);
|
69 |
-
$result = $adapter->fetchOne($select);
|
70 |
-
if($result === false) {
|
71 |
-
return null;
|
72 |
-
}
|
73 |
-
return $result;
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* @param int $website_id
|
78 |
-
* @param string $key
|
79 |
-
* @param string $value
|
80 |
-
* @return void
|
81 |
-
*/
|
82 |
-
public function setValue($website_id, $key, $value = null)
|
83 |
-
{
|
84 |
-
if(is_array($key)) {
|
85 |
-
foreach($key as $eachKey => $eachValue) {
|
86 |
-
$this->setValue($website_id, $eachKey, $eachValue);
|
87 |
-
}
|
88 |
-
return;
|
89 |
-
}
|
90 |
-
if (!isset($value) || $value == "" || !isset($key) || $key == "") {
|
91 |
-
return;
|
92 |
-
}
|
93 |
-
|
94 |
-
$config = Mage::getModel('choiceai_searchcore/config')->getCollection()
|
95 |
-
->addFieldToFilter(ChoiceAI_Searchcore_Model_Config::KEY, $key)
|
96 |
-
->addFieldToFilter(ChoiceAI_Searchcore_Model_Config::WEBSITE_ID, (int)$website_id)
|
97 |
-
->getFirstItem();
|
98 |
-
|
99 |
-
$config->setWebsiteId($website_id)
|
100 |
-
->setChoiceAIKey($key)
|
101 |
-
->setValue($value)
|
102 |
-
->save();
|
103 |
-
}
|
104 |
-
|
105 |
-
public function updateValues($websiteId, $key, $values = array()) {
|
106 |
-
$this->deleteKey($websiteId, $key);
|
107 |
-
$this->beginTransaction();
|
108 |
-
foreach($values as $eachValue) {
|
109 |
-
Mage::getModel('choiceai_searchcore/config')
|
110 |
-
->setWebsiteId($websiteId)
|
111 |
-
->setChoiceAIKey($key)
|
112 |
-
->setValue($eachValue)
|
113 |
-
->save();
|
114 |
-
}
|
115 |
-
$this->commit();
|
116 |
-
}
|
117 |
-
|
118 |
-
public function deleteKey($websiteId, $key) {
|
119 |
-
$write = Mage::getSingleton("core/resource")->getConnection("core_write");
|
120 |
-
$query = "DELETE FROM choiceai_recommendation_conf WHERE " . ChoiceAI_Searchcore_Model_Config::KEY . " = :key"
|
121 |
-
. " and " . ChoiceAI_Searchcore_Model_Config::WEBSITE_ID . " = :website_id";
|
122 |
-
$binds = array(
|
123 |
-
ChoiceAI_Searchcore_Model_Config::KEY => $key,
|
124 |
-
ChoiceAI_Searchcore_Model_Config::WEBSITE_ID => $websiteId
|
125 |
-
);
|
126 |
-
$write->query($query, $binds);
|
127 |
-
|
128 |
-
}
|
129 |
-
|
130 |
-
public function lockSite($website_id) {
|
131 |
-
$this->setValue($website_id, array(
|
132 |
-
ChoiceAI_Searchcore_Model_Config::FEED_LOCK => ChoiceAI_Searchcore_Model_Config::FEED_LOCK_TRUE,
|
133 |
-
ChoiceAI_Searchcore_Model_Config::FEED_LOCK_TIME => date(self::DATE_FORMAT)));
|
134 |
-
|
135 |
-
}
|
136 |
-
|
137 |
-
|
138 |
-
public function unLockSite($website_id) {
|
139 |
-
$this->setValue($website_id, ChoiceAI_Searchcore_Model_Config::FEED_LOCK,
|
140 |
-
ChoiceAI_Searchcore_Model_Config::FEED_LOCK_FALSE);
|
141 |
-
}
|
142 |
-
|
143 |
-
/**
|
144 |
-
* Method will check whether there is a feed lock or not
|
145 |
-
* @param $website_id
|
146 |
-
* @return bool
|
147 |
-
*/
|
148 |
-
public function isLock($website_id) {
|
149 |
-
//fetch the values for feedlock, feed lock time from db
|
150 |
-
$feedLockDetails = $this->getValue($website_id,
|
151 |
-
array(ChoiceAI_Searchcore_Model_Config::FEED_LOCK, ChoiceAI_Searchcore_Model_Config::FEED_LOCK_TIME));
|
152 |
-
//fetch feed lock from @var feedLockDetails
|
153 |
-
$feedLock = array_key_exists(ChoiceAI_Searchcore_Model_Config::FEED_LOCK, $feedLockDetails)?
|
154 |
-
$feedLockDetails[ChoiceAI_Searchcore_Model_Config::FEED_LOCK]:null;
|
155 |
-
if(is_null($feedLock) || $feedLock == ChoiceAI_Searchcore_Model_Config::FEED_LOCK_FALSE){
|
156 |
-
return false;
|
157 |
-
}
|
158 |
-
// Ignoring the feed Lock, if the feed has been locked more than $maxFeedLockTime
|
159 |
-
if($feedLock == ChoiceAI_Searchcore_Model_Config::FEED_LOCK_TRUE &&
|
160 |
-
array_key_exists(ChoiceAI_Searchcore_Model_Config::FEED_LOCK_TIME, $feedLockDetails)) {
|
161 |
-
$feedLockTime = $feedLockDetails[ChoiceAI_Searchcore_Model_Config::FEED_LOCK_TIME];
|
162 |
-
$date = strtotime($feedLockTime);
|
163 |
-
$currentTime = strtotime(date(self::DATE_FORMAT));
|
164 |
-
$diff = abs($date - $currentTime);
|
165 |
-
$maxFeedLockTime = Mage::getConfig()->getNode('default/choiceai/general/max_feed_lock_feed');
|
166 |
-
if(is_null($maxFeedLockTime)) {
|
167 |
-
$maxFeedLockTime = ChoiceAI_Searchcore_Model_Config::MAX_FEED_LOCK_TIME;
|
168 |
-
}
|
169 |
-
if(round($diff / ( 60 * 60 )) > $maxFeedLockTime) {
|
170 |
-
return false;
|
171 |
-
}
|
172 |
-
}
|
173 |
-
return true;
|
174 |
-
}
|
175 |
-
|
176 |
-
/**
|
177 |
-
* Method to get all the filters
|
178 |
-
* @param Mage_Core_Model_Website $website
|
179 |
-
* @return array
|
180 |
-
*/
|
181 |
-
public function getFilters(Mage_Core_Model_Website $website) {
|
182 |
-
$values = Mage::getResourceModel('choiceai_searchcore/config')->getValues($website->getWebsiteId(),
|
183 |
-
ChoiceAI_Searchcore_Model_Config::FILTER);
|
184 |
-
$filters = array();
|
185 |
-
foreach($values as $value) {
|
186 |
-
$explodedValues = explode(ChoiceAI_Searchcore_Model_Config::FILTER_DELIMITER, $value);
|
187 |
-
if(sizeof($explodedValues) < 2) {
|
188 |
-
continue;
|
189 |
-
}
|
190 |
-
$filters[$explodedValues[0]] = $explodedValues[1];
|
191 |
-
}
|
192 |
-
return $filters;
|
193 |
-
}
|
194 |
-
|
195 |
-
public function saveGlobalConfig(Mage_Core_Model_Website $website, $values = array()) {
|
196 |
-
foreach($values as $key => $value ) {
|
197 |
-
}
|
198 |
-
}
|
199 |
-
|
200 |
-
public function deleteAll($websiteId) {
|
201 |
-
$write = Mage::getSingleton("core/resource")->getConnection("core_write");
|
202 |
-
$query = "DELETE FROM choiceai_recommendation_conf WHERE " . ChoiceAI_Searchcore_Model_Config::WEBSITE_ID . " = :website_id";
|
203 |
-
$binds = array(
|
204 |
-
'website_id' => $websiteId
|
205 |
-
);
|
206 |
-
$write->query($query, $binds);
|
207 |
-
}
|
208 |
-
|
209 |
-
public function getGlobalConfig(Mage_Core_Model_Website $website, $keys =array()) {
|
210 |
-
}
|
211 |
-
}
|
212 |
-
|
213 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Resource/Config/Collection.php
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Resource_Config_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
10 |
-
{
|
11 |
-
/**
|
12 |
-
*/
|
13 |
-
public function _construct()
|
14 |
-
{
|
15 |
-
$this->_init('choiceai_searchcore/config');
|
16 |
-
}
|
17 |
-
|
18 |
-
|
19 |
-
}
|
20 |
-
|
21 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Resource/Field.php
DELETED
@@ -1,146 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Resource_Field extends Mage_Core_Model_Mysql4_Abstract
|
10 |
-
{
|
11 |
-
|
12 |
-
const CAT_LEVEL_1 = "categoryLevel1";
|
13 |
-
|
14 |
-
const CAT_LEVEL_2 = "categoryLevel2";
|
15 |
-
|
16 |
-
const CAT_LEVEL_3 = "categoryLevel3";
|
17 |
-
|
18 |
-
const CAT_LEVEL_4 = "categoryLevel4";
|
19 |
-
|
20 |
-
const CAT_LEVEL_1_NAME = "catlevel1Name";
|
21 |
-
|
22 |
-
const CAT_LEVEL_2_NAME = "catlevel2Name";
|
23 |
-
|
24 |
-
const CAT_LEVEL_3_NAME = "catlevel3Name";
|
25 |
-
|
26 |
-
const CAT_LEVEL_4_NAME = "catlevel4Name";
|
27 |
-
|
28 |
-
const CATEGORY_IDS_NAME = "categoryIds";
|
29 |
-
|
30 |
-
const CATEGORY_IDS = "category_ids";
|
31 |
-
|
32 |
-
const CATEGORY_NAME = "category";
|
33 |
-
|
34 |
-
const AVAILABILITY = 'availability';
|
35 |
-
|
36 |
-
const QTY_ASSOCIATED = "qtyAssociated";
|
37 |
-
|
38 |
-
const AVAILABILITY_ASSOCIATED = "availabilityAssociated";
|
39 |
-
|
40 |
-
const QTY_MANAGE_ASSOCIATED = "manage_stockAssociated";
|
41 |
-
|
42 |
-
const QTY_CONFIG_USE_MANAGE_STOCK = "use_config_manage_stock";
|
43 |
-
|
44 |
-
const QTY_CONFIG_USE_MANAGE_STOCK_ASSOCIATED = "use_config_manage_stockAssociated";
|
45 |
-
|
46 |
-
const QTY = "qty";
|
47 |
-
|
48 |
-
const QTY_MANAGE = "manage_stock";
|
49 |
-
/**
|
50 |
-
* ChoiceAI Field Config table Name
|
51 |
-
*
|
52 |
-
* @var string
|
53 |
-
*/
|
54 |
-
protected $_choiceaiFieldTable;
|
55 |
-
|
56 |
-
/**
|
57 |
-
* @return void
|
58 |
-
*/
|
59 |
-
protected function _construct()
|
60 |
-
{
|
61 |
-
$this->_init('choiceai_searchcore/field', 'id');
|
62 |
-
$this->_choiceaiFieldTable = $this->getTable('choiceai_searchcore/field');
|
63 |
-
}
|
64 |
-
|
65 |
-
public function getTableName() {
|
66 |
-
return $this->_choiceaiFieldTable;
|
67 |
-
}
|
68 |
-
|
69 |
-
public function getFieldByFeatureField($websiteId, $featureField){
|
70 |
-
$adapter = $this->_getReadAdapter();
|
71 |
-
|
72 |
-
$select = $adapter->select()
|
73 |
-
->from($this->_choiceaiFieldTable, ChoiceAI_Searchcore_Model_Field::field_name)
|
74 |
-
->where('`'.ChoiceAI_Searchcore_Model_Field::website_id.'` = ?', (int)$websiteId)
|
75 |
-
->where('`'.ChoiceAI_Searchcore_Model_Field::featured_field.'` = ?', $featureField);
|
76 |
-
|
77 |
-
$result = $adapter->fetchOne($select);
|
78 |
-
if($result == false) {
|
79 |
-
return null;
|
80 |
-
}
|
81 |
-
return $result;
|
82 |
-
}
|
83 |
-
|
84 |
-
public function getDisplayableFields(Mage_Core_Model_Website $website) {
|
85 |
-
$fields = $this->getDisplayableFieldCollection($website);
|
86 |
-
if(count($fields) == 0) {
|
87 |
-
return $this->setDefaultFields($website)
|
88 |
-
->getDisplayableFieldCollection($website);
|
89 |
-
}
|
90 |
-
return $fields;
|
91 |
-
}
|
92 |
-
|
93 |
-
protected function getDisplayableFieldCollection(Mage_Core_Model_Website $website) {
|
94 |
-
return Mage::getModel("choiceai_searchcore/field")
|
95 |
-
->getCollection()
|
96 |
-
->addFieldsDisplayFilter()
|
97 |
-
->addWebsiteFilter($website)
|
98 |
-
->load();
|
99 |
-
}
|
100 |
-
|
101 |
-
public function setDefaultFields(Mage_Core_Model_Website $website) {
|
102 |
-
$_writer = $this->_getWriteAdapter();
|
103 |
-
$_writer->query($this->getDefaultFieldInsertStatement($website));
|
104 |
-
return $this;
|
105 |
-
}
|
106 |
-
|
107 |
-
public function getDefaultFieldInsertStatement(Mage_Core_Model_Website $website) {
|
108 |
-
$websiteId = $website->getWebsiteId();
|
109 |
-
if(is_null($websiteId)) {
|
110 |
-
return "";
|
111 |
-
}
|
112 |
-
$fieldTable = Mage::getResourceModel('choiceai_searchcore/field')->getTableName();
|
113 |
-
return "
|
114 |
-
INSERT INTO `{$fieldTable}` (`website_id`, `field_name`, `datatype`, `autosuggest`, `featured_field`, `multivalued`, `displayed`)
|
115 |
-
VALUES
|
116 |
-
({$websiteId}, 'name', 'text', 1, 'title', 0, 1),
|
117 |
-
({$websiteId}, 'final_price', 'decimal', 0, 'price', 0, 1),
|
118 |
-
({$websiteId}, 'price', 'decimal', 0, NULL, 0, 1),
|
119 |
-
({$websiteId}, 'brand', 'text', 0, 'brand', 0, 1),
|
120 |
-
({$websiteId}, 'color', 'text', 0, 'color', 1, 1),
|
121 |
-
({$websiteId}, 'size', 'text', 0, 'size', 1, 1),
|
122 |
-
({$websiteId}, 'image', 'link', 0, 'imageUrl', 1, 1),
|
123 |
-
({$websiteId}, 'url_path', 'link', 0, 'productUrl', 0, 1),
|
124 |
-
({$websiteId}, 'gender', 'text', 0, 'gender', 0, 1),
|
125 |
-
({$websiteId}, 'description', 'longText', 0, 'description', 0, 1),
|
126 |
-
({$websiteId}, 'catlevel1Name', 'text', 0, 'catlevel1Name', 0, 0),
|
127 |
-
({$websiteId}, 'catlevel2Name', 'text', 0, 'catlevel2Name', 0, 0),
|
128 |
-
({$websiteId}, 'catlevel3Name', 'text', 0, 'catlevel3Name', 0, 0),
|
129 |
-
({$websiteId}, 'catlevel4Name', 'text', 0, 'catlevel4Name', 0, 0),
|
130 |
-
({$websiteId}, 'categoryLevel1', 'text', 0, NULL, 1, 0),
|
131 |
-
({$websiteId}, 'categoryLevel2', 'text', 0, NULL, 1, 0),
|
132 |
-
({$websiteId}, 'categoryLevel3', 'text', 0, NULL, 1, 0),
|
133 |
-
({$websiteId}, 'categoryLevel4', 'text', 0, NULL, 1, 0),
|
134 |
-
({$websiteId}, 'created_at', 'date', 0, NULL, 0, 1),
|
135 |
-
({$websiteId}, 'availability', 'bool', 0, 'availability', 0, 0),
|
136 |
-
({$websiteId}, 'status', 'number', 0, NULL, 0, 0),
|
137 |
-
({$websiteId}, 'visibility', 'number', 0, NULL, 0, 0),
|
138 |
-
({$websiteId}, 'qty', 'number', 0, NULL, 0, 0),
|
139 |
-
({$websiteId}, 'categoryIds', 'longText', 0, NULL, 1, 0),
|
140 |
-
({$websiteId}, 'category', 'text', 0, 'category', 1, 0),
|
141 |
-
({$websiteId}, 'uniqueId', 'longText', 0, NULL, 0, 0),
|
142 |
-
({$websiteId}, 'entity_id', 'longText', 0, NULL, 0, 0);";
|
143 |
-
}
|
144 |
-
}
|
145 |
-
|
146 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Resource/Field/Collection.php
DELETED
@@ -1,66 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Resource_Field_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
10 |
-
{
|
11 |
-
/**
|
12 |
-
*/
|
13 |
-
public function _construct()
|
14 |
-
{
|
15 |
-
$this->_init('choiceai_searchcore/field');
|
16 |
-
}
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Method to add fields to display filter
|
20 |
-
*
|
21 |
-
* @return void
|
22 |
-
*/
|
23 |
-
public function addFieldsDisplayFilter() {
|
24 |
-
$this->addFieldToFilter(ChoiceAI_Searchcore_Model_Field::dislayable,1);
|
25 |
-
return $this;
|
26 |
-
}
|
27 |
-
|
28 |
-
public function addWebsiteFilter(Mage_Core_Model_Website $website) {
|
29 |
-
$this->addFieldToFilter(ChoiceAI_Searchcore_Model_Field::website_id, $website->getWebsiteId());
|
30 |
-
return $this;
|
31 |
-
}
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Method to get field collection as array
|
35 |
-
*
|
36 |
-
* @return array
|
37 |
-
*/
|
38 |
-
public function __asArray() {
|
39 |
-
$fields = array();
|
40 |
-
foreach($this->_items as $item) {
|
41 |
-
$field = array();
|
42 |
-
$field[ChoiceAI_Searchcore_Model_Field::field_name] = $item->getFieldName();
|
43 |
-
$field[ChoiceAI_Searchcore_Model_Field::datatype] = $item->getDatatype();
|
44 |
-
$field[ChoiceAI_Searchcore_Model_Field::autosuggest] = $item->getAutosuggest();
|
45 |
-
$featureField = $item->getFeaturedField();
|
46 |
-
if(isset($featureField)) {
|
47 |
-
$field[ChoiceAI_Searchcore_Model_Field::featured_field] = $featureField;
|
48 |
-
}
|
49 |
-
$fields[] = $field;
|
50 |
-
}
|
51 |
-
return $fields;
|
52 |
-
}
|
53 |
-
|
54 |
-
public function getFeatureFields(Mage_Core_Model_Website $website) {
|
55 |
-
$this->getSelect()->where(ChoiceAI_Searchcore_Model_Field::featured_field. " IS NOT NULL AND ".
|
56 |
-
ChoiceAI_Searchcore_Model_Field::website_id . " = " . $website->getWebsiteId());
|
57 |
-
return $this->load();
|
58 |
-
}
|
59 |
-
|
60 |
-
public function getFields(Mage_Core_Model_Website $website) {
|
61 |
-
$this->getSelect()->where(ChoiceAI_Searchcore_Model_Field::website_id . " = " . $website->getWebsiteId());
|
62 |
-
return $this->load();
|
63 |
-
}
|
64 |
-
}
|
65 |
-
|
66 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/Model/Resource/Product/Collection.php
DELETED
@@ -1,110 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* @category ChoiceAI
|
4 |
-
* @package ChoiceAI_Searchcore
|
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_Searchcore_Model_Resource_Product_Collection extends
|
9 |
-
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection{
|
10 |
-
|
11 |
-
protected function _construct()
|
12 |
-
{
|
13 |
-
parent::_construct();
|
14 |
-
}
|
15 |
-
|
16 |
-
public function isEnabledFlat()
|
17 |
-
{
|
18 |
-
return false;
|
19 |
-
}
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Merge colle
|
23 |
-
* @param $collection1
|
24 |
-
* @param $collection2
|
25 |
-
* @return mixed
|
26 |
-
*/
|
27 |
-
public function mergeCollection($collection) {
|
28 |
-
foreach($collection as $product) {
|
29 |
-
if(!array_key_exists($product->getEntityId(), $this->_items)) {
|
30 |
-
$this->addItem($product);
|
31 |
-
}
|
32 |
-
}
|
33 |
-
return $this;
|
34 |
-
}
|
35 |
-
|
36 |
-
/**
|
37 |
-
* sets collection is loaded
|
38 |
-
* @return $this
|
39 |
-
*/
|
40 |
-
public function virtuallyLoad() {
|
41 |
-
$this->_setIsLoaded(true);
|
42 |
-
return $this;
|
43 |
-
}
|
44 |
-
|
45 |
-
public function addIncrementalUploadFiltersToAdd(Mage_Core_Model_Website $website, $fromDate,
|
46 |
-
$toDate, $productIds = array()) {
|
47 |
-
$this->_addBasicFilterToUpload($website);
|
48 |
-
$this->addAttributeToFilter(array(
|
49 |
-
array( 'attribute' => 'updated_at',
|
50 |
-
'from' => $fromDate,
|
51 |
-
'to' => $toDate,
|
52 |
-
'date' => true
|
53 |
-
),
|
54 |
-
array( 'attribute' => 'entity_id',
|
55 |
-
'in' => $productIds
|
56 |
-
)
|
57 |
-
));
|
58 |
-
Mage::helper('choiceai_searchcore')->log(Zend_Log::DEBUG, (string)$this->getSelect());
|
59 |
-
return $this;
|
60 |
-
}
|
61 |
-
|
62 |
-
public function addIncrementalUploadFiltersToDelete(Mage_Core_Model_Website $website, $fromDate, $toDate) {
|
63 |
-
$this->addAttributeToSelect('entity_id');
|
64 |
-
$this->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
|
65 |
-
$this->addAttributeToFilter(array(
|
66 |
-
array( 'attribute' => 'updated_at',
|
67 |
-
'from' => $fromDate,
|
68 |
-
'to' => $toDate,
|
69 |
-
'date' => true
|
70 |
-
)
|
71 |
-
));
|
72 |
-
return $this;
|
73 |
-
|
74 |
-
}
|
75 |
-
|
76 |
-
protected function _addBasicFilterToUpload(Mage_Core_Model_Website $website)
|
77 |
-
{
|
78 |
-
$adapter = Mage::getSingleton("core/resource");
|
79 |
-
$visiblityCondition = array('in' => array(2,3,4));
|
80 |
-
$_catalogInventoryTable = method_exists($adapter, 'getTableName')
|
81 |
-
? $adapter->getTableName('cataloginventory_stock_item') : 'cataloginventory_stock_item';
|
82 |
-
$stockfields = array("qty" => "qty", "manage_stock" => "manage_stock",
|
83 |
-
"use_config_manage_stock" => "use_config_manage_stock", "is_in_stock" => "is_in_stock");
|
84 |
-
|
85 |
-
$this
|
86 |
-
->addWebsiteFilter($website->getWebsiteId())
|
87 |
-
->addAttributeToSelect('*')
|
88 |
-
->joinTable($_catalogInventoryTable, 'product_id=entity_id', $stockfields, null, 'left')
|
89 |
-
->addAttributeToFilter('status',1)
|
90 |
-
->addCategoryIds()
|
91 |
-
->addAttributeToFilter('visibility',$visiblityCondition)
|
92 |
-
->addPriceData(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID, $website->getWebsiteId());
|
93 |
-
|
94 |
-
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this);
|
95 |
-
#Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($this);
|
96 |
-
return $this;
|
97 |
-
}
|
98 |
-
|
99 |
-
|
100 |
-
/**
|
101 |
-
* method to get the catalog collection
|
102 |
-
*
|
103 |
-
*/
|
104 |
-
public function addFullUploadFilters(Mage_Core_Model_Website $website) {
|
105 |
-
$this->_addBasicFilterToUpload($website);
|
106 |
-
return $this;
|
107 |
-
}
|
108 |
-
}
|
109 |
-
|
110 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/etc/config.xml
CHANGED
@@ -5,13 +5,6 @@
|
|
5 |
</ChoiceAI_Searchcore>
|
6 |
</modules>
|
7 |
<global>
|
8 |
-
<resources>
|
9 |
-
<choiceai_searchcore_setup>
|
10 |
-
<setup>
|
11 |
-
<module>ChoiceAI_Searchcore</module>
|
12 |
-
</setup>
|
13 |
-
</choiceai_searchcore_setup>
|
14 |
-
</resources>
|
15 |
<helpers>
|
16 |
<choiceai_searchcore>
|
17 |
<class>ChoiceAI_Searchcore_Helper</class>
|
@@ -20,114 +13,7 @@
|
|
20 |
<models>
|
21 |
<choiceai_searchcore>
|
22 |
<class>ChoiceAI_Searchcore_Model</class>
|
23 |
-
<resourceModel>choiceai_searchcore_resource</resourceModel>
|
24 |
</choiceai_searchcore>
|
25 |
-
<choiceai_searchcore_resource>
|
26 |
-
<class>ChoiceAI_Searchcore_Model_Resource</class>
|
27 |
-
<entities>
|
28 |
-
<config>
|
29 |
-
<table>choiceai_recommendation_conf</table>
|
30 |
-
</config>
|
31 |
-
<field>
|
32 |
-
<table>choiceai_field_conf</table>
|
33 |
-
</field>
|
34 |
-
<sync>
|
35 |
-
<table>choiceai_product_sync</table>
|
36 |
-
</sync>
|
37 |
-
</entities>
|
38 |
-
</choiceai_searchcore_resource>
|
39 |
</models>
|
40 |
-
<blocks>
|
41 |
-
<choiceai_searchcore>
|
42 |
-
<class>ChoiceAI_Searchcore_Block</class>
|
43 |
-
</choiceai_searchcore>
|
44 |
-
</blocks>
|
45 |
-
<events>
|
46 |
-
<controller_action_predispatch_choiceai_searchcore>
|
47 |
-
<observers>
|
48 |
-
<choiceai_searchcore_auth>
|
49 |
-
<type>singleton</type>
|
50 |
-
<class>choiceai_searchcore/auth</class>
|
51 |
-
<method>authorize</method>
|
52 |
-
</choiceai_searchcore_auth>
|
53 |
-
</observers>
|
54 |
-
</controller_action_predispatch_choiceai_searchcore>
|
55 |
-
<checkout_cart_add_product_complete>
|
56 |
-
<observers>
|
57 |
-
<choiceai_searchcore_cart_tracker>
|
58 |
-
<type>singleton</type>
|
59 |
-
<class>choiceai_searchcore/observer</class>
|
60 |
-
<method>trackAddToCart</method>
|
61 |
-
</choiceai_searchcore_cart_tracker>
|
62 |
-
</observers>
|
63 |
-
</checkout_cart_add_product_complete>
|
64 |
-
<sales_order_payment_place_end>
|
65 |
-
<observers>
|
66 |
-
<choiceai_searchcore_order_tracker>
|
67 |
-
<type>singleton</type>
|
68 |
-
<class>choiceai_searchcore/observer</class>
|
69 |
-
<method>trackOrder</method>
|
70 |
-
</choiceai_searchcore_order_tracker>
|
71 |
-
</observers>
|
72 |
-
</sales_order_payment_place_end>
|
73 |
-
<catalog_product_delete_before>
|
74 |
-
<observers>
|
75 |
-
<choiceai_searchcore_order_tracker>
|
76 |
-
<type>singleton</type>
|
77 |
-
<class>choiceai_searchcore/observer</class>
|
78 |
-
<method>trackDelete</method>
|
79 |
-
</choiceai_searchcore_order_tracker>
|
80 |
-
</observers>
|
81 |
-
</catalog_product_delete_before>
|
82 |
-
<catalog_product_delete_commit_after>
|
83 |
-
<observers>
|
84 |
-
<choiceai_searchcore_order_tracker>
|
85 |
-
<type>singleton</type>
|
86 |
-
<class>choiceai_searchcore/observer</class>
|
87 |
-
<method>trackDelete</method>
|
88 |
-
</choiceai_searchcore_order_tracker>
|
89 |
-
</observers>
|
90 |
-
</catalog_product_delete_commit_after>
|
91 |
-
<cataloginventory_stock_item_save_commit_after>
|
92 |
-
<observers>
|
93 |
-
<choiceai_searchcore_catalog_inventory_save>
|
94 |
-
<type>singleton</type>
|
95 |
-
<class>choiceai_searchcore/observer</class>
|
96 |
-
<method>catalogInventorySave</method>
|
97 |
-
</choiceai_searchcore_catalog_inventory_save>
|
98 |
-
</observers>
|
99 |
-
</cataloginventory_stock_item_save_commit_after>
|
100 |
-
<sales_order_item_cancel>
|
101 |
-
<observers>
|
102 |
-
<choiceai_searchcore_order_cancel>
|
103 |
-
<type>singleton</type>
|
104 |
-
<class>choiceai_searchcore/observer</class>
|
105 |
-
<method>catalogInventorySave</method>
|
106 |
-
</choiceai_searchcore_order_cancel>
|
107 |
-
</observers>
|
108 |
-
</sales_order_item_cancel>
|
109 |
-
</events>
|
110 |
</global>
|
111 |
-
<default>
|
112 |
-
<choiceai>
|
113 |
-
<general>
|
114 |
-
<price>final_price</price>
|
115 |
-
<productUrl>url_path</productUrl>
|
116 |
-
<max_feed_lock_feed>2</max_feed_lock_feed>
|
117 |
-
<include_out_of_stock>true</include_out_of_stock>
|
118 |
-
<include_child_product>true</include_child_product>
|
119 |
-
<include_taxonomy_nodes>false</include_taxonomy_nodes>
|
120 |
-
<include_taxonomy_mapping>false</include_taxonomy_mapping>
|
121 |
-
<include_out_of_stock_from_non_cache>false</include_out_of_stock_from_non_cache>
|
122 |
-
<include_only_enabled_child_product>true</include_only_enabled_child_product>
|
123 |
-
<include_out_of_stock_child_product>false</include_out_of_stock_child_product>
|
124 |
-
<field_conf>{}</field_conf>
|
125 |
-
<exclude_category>[]</exclude_category>
|
126 |
-
<tracker_url>https://tracker.choiceaiapi.com/</tracker_url>
|
127 |
-
<platform_url>https://accounts.choiceaiapi.com/admin/</platform_url>
|
128 |
-
<service_url>https://starwreck.choiceaiapi.com/</service_url>
|
129 |
-
<feed_url>https://feed.choiceaiapi.com/</feed_url>
|
130 |
-
</general>
|
131 |
-
</choiceai>
|
132 |
-
</default>
|
133 |
</config>
|
5 |
</ChoiceAI_Searchcore>
|
6 |
</modules>
|
7 |
<global>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
<helpers>
|
9 |
<choiceai_searchcore>
|
10 |
<class>ChoiceAI_Searchcore_Helper</class>
|
13 |
<models>
|
14 |
<choiceai_searchcore>
|
15 |
<class>ChoiceAI_Searchcore_Model</class>
|
|
|
16 |
</choiceai_searchcore>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
</models>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
</global>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</config>
|
app/code/local/ChoiceAI/Searchcore/sql/choiceai_searchcore_setup/mysql4-install-1.0.0.php
DELETED
@@ -1,91 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
$installer = $this;
|
5 |
-
/* @var $installer Mage_Searchcore_Model_Resource_Setup */
|
6 |
-
|
7 |
-
$installer->startSetup();
|
8 |
-
|
9 |
-
$configTable = $installer->getTable('choiceai_recommendation_conf');
|
10 |
-
$fieldTable = $installer->getTable('choiceai_field_conf');
|
11 |
-
$productSyncTable = $installer->getTable('choiceai_product_sync');
|
12 |
-
|
13 |
-
$installer->run("
|
14 |
-
|
15 |
-
CREATE TABLE IF NOT EXISTS `{$fieldTable}` (
|
16 |
-
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
17 |
-
`website_id` tinyint(5) unsigned NOT NULL,
|
18 |
-
`field_name` varchar(100) NOT NULL DEFAULT '',
|
19 |
-
`datatype` varchar(20) NOT NULL DEFAULT '',
|
20 |
-
`autosuggest` tinyint(1) NOT NULL DEFAULT '0',
|
21 |
-
`featured_field` varchar(100) DEFAULT NULL,
|
22 |
-
`multivalued` tinyint(1) NOT NULL DEFAULT '0',
|
23 |
-
`displayed` tinyint(1) NOT NULL DEFAULT '1',
|
24 |
-
PRIMARY KEY (`id`),
|
25 |
-
UNIQUE KEY `website_id` (`website_id`,`field_name`)
|
26 |
-
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
27 |
-
|
28 |
-
CREATE TABLE IF NOT EXISTS `{$configTable}` (
|
29 |
-
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
30 |
-
`website_id` smallint(5) unsigned NOT NULL,
|
31 |
-
`key` varchar(50) NOT NULL DEFAULT '',
|
32 |
-
`value` varchar(50) DEFAULT NULL,
|
33 |
-
PRIMARY KEY (`id`)
|
34 |
-
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
35 |
-
|
36 |
-
CREATE TABLE IF NOT EXISTS `{$productSyncTable}` (
|
37 |
-
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
38 |
-
`product_id` int(10) unsigned NOT NULL,
|
39 |
-
`website_id` smallint(5) unsigned NOT NULL,
|
40 |
-
`synced` tinyint(1) NOT NULL DEFAULT '0',
|
41 |
-
`updated_time` datetime DEFAULT NULL,
|
42 |
-
`sync_time` datetime DEFAULT NULL,
|
43 |
-
`operation` enum('ADD','DELETE') NOT NULL DEFAULT 'ADD',
|
44 |
-
PRIMARY KEY (`id`),
|
45 |
-
UNIQUE KEY `product_id` (`product_id`,`website_id`)
|
46 |
-
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
47 |
-
");
|
48 |
-
|
49 |
-
$websiteCollection = Mage::getModel('core/website')->getCollection()->load();
|
50 |
-
foreach($websiteCollection as $website) {
|
51 |
-
$websiteId = $website->getWebsiteId();
|
52 |
-
if(is_null($websiteId)) {
|
53 |
-
continue;
|
54 |
-
}
|
55 |
-
$fieldTable = Mage::getResourceModel('choiceai_searchcore/field')->getTableName();
|
56 |
-
$insertQuery = "
|
57 |
-
INSERT INTO `{$fieldTable}` (`website_id`, `field_name`, `datatype`, `autosuggest`, `featured_field`, `multivalued`, `displayed`)
|
58 |
-
VALUES
|
59 |
-
({$websiteId}, 'name', 'text', 1, 'title', 0, 1),
|
60 |
-
({$websiteId}, 'final_price', 'decimal', 0, 'price', 0, 1),
|
61 |
-
({$websiteId}, 'price', 'decimal', 0, NULL, 0, 1),".
|
62 |
-
(Mage::helper('choiceai_searchcore/feedhelper')->isAttributePresent('brand')?"({$websiteId}, 'brand', 'text', 0, 'brand', 0, 1),":"").
|
63 |
-
(Mage::helper('choiceai_searchcore/feedhelper')->isAttributePresent('color')?"({$websiteId}, 'color', 'text', 0, 'color', 1, 1),":"").
|
64 |
-
(Mage::helper('choiceai_searchcore/feedhelper')->isAttributePresent('size')?"({$websiteId}, 'size', 'text', 0, 'size', 1, 1),":"").
|
65 |
-
"({$websiteId}, 'image', 'link', 0, 'imageUrl', 1, 1),
|
66 |
-
({$websiteId}, 'url_path', 'link', 0, 'productUrl', 0, 1),
|
67 |
-
({$websiteId}, 'gender', 'text', 0, 'gender', 0, 1),
|
68 |
-
({$websiteId}, 'description', 'longText', 0, 'description', 0, 1),
|
69 |
-
({$websiteId}, 'catlevel1Name', 'text', 0, 'catlevel1Name', 0, 0),
|
70 |
-
({$websiteId}, 'catlevel2Name', 'text', 0, 'catlevel2Name', 0, 0),
|
71 |
-
({$websiteId}, 'catlevel3Name', 'text', 0, 'catlevel3Name', 0, 0),
|
72 |
-
({$websiteId}, 'catlevel4Name', 'text', 0, 'catlevel4Name', 0, 0),
|
73 |
-
({$websiteId}, 'categoryLevel1', 'text', 0, NULL, 1, 0),
|
74 |
-
({$websiteId}, 'categoryLevel2', 'text', 0, NULL, 1, 0),
|
75 |
-
({$websiteId}, 'categoryLevel3', 'text', 0, NULL, 1, 0),
|
76 |
-
({$websiteId}, 'categoryLevel4', 'text', 0, NULL, 1, 0),
|
77 |
-
({$websiteId}, 'created_at', 'date', 0, NULL, 0, 1),
|
78 |
-
({$websiteId}, 'availability', 'bool', 0, 'availability', 0, 0),
|
79 |
-
({$websiteId}, 'status', 'number', 0, NULL, 0, 0),
|
80 |
-
({$websiteId}, 'visibility', 'number', 0, NULL, 0, 0),
|
81 |
-
({$websiteId}, 'qty', 'number', 0, NULL, 0, 0),
|
82 |
-
({$websiteId}, 'categoryIds', 'longText', 0, NULL, 1, 0),
|
83 |
-
({$websiteId}, 'category', 'text', 0, 'category', 1, 0),
|
84 |
-
({$websiteId}, 'uniqueId', 'longText', 0, NULL, 0, 0),
|
85 |
-
({$websiteId}, 'type_id', 'longText', 0, NULL, 0, 0),
|
86 |
-
({$websiteId}, 'entity_id', 'longText', 0, NULL, 0, 0)
|
87 |
-
ON DUPLICATE KEY UPDATE `field_name`=`field_name`;";
|
88 |
-
$installer->run($insertQuery);
|
89 |
-
}
|
90 |
-
$installer->endSetup();
|
91 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/ChoiceAI/Searchcore/sql/choiceai_searchcore_setup/upgrade-1.0.21-1.0.22.php
DELETED
@@ -1,46 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
$installer = $this;
|
3 |
-
/* @var $installer Mage_Searchcore_Model_Resource_Setup */
|
4 |
-
|
5 |
-
$installer->startSetup();
|
6 |
-
$fieldTable = $installer->getTable('choiceai_field_conf');
|
7 |
-
$configTable = $installer->getTable('choiceai_recommendation_conf');
|
8 |
-
try {
|
9 |
-
$installer->run("ALTER TABLE `{$configTable}` CHANGE `key` `choiceai_key` VARCHAR(50)");
|
10 |
-
} catch (Exception $e) {
|
11 |
-
//ignore the exceptions
|
12 |
-
}
|
13 |
-
|
14 |
-
$websiteCollection = Mage::getModel('core/website')->getCollection()->load();
|
15 |
-
foreach($websiteCollection as $website) {
|
16 |
-
$websiteId = $website->getWebsiteId();
|
17 |
-
if (is_null($websiteId)) {
|
18 |
-
continue;
|
19 |
-
}
|
20 |
-
$fieldTable = Mage::getResourceModel('choiceai_searchcore/field')->getTableName();
|
21 |
-
$insertQuery = "
|
22 |
-
INSERT INTO `{$fieldTable}` (`website_id`, `field_name`, `datatype`, `autosuggest`, `featured_field`, `multivalued`, `displayed`)
|
23 |
-
VALUES
|
24 |
-
({$websiteId}, '" . ChoiceAI_Searchcore_Model_Resource_Field::QTY_MANAGE_ASSOCIATED . "',
|
25 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER . "', 0, NULL, 1, 0),
|
26 |
-
({$websiteId}, '" .ChoiceAI_Searchcore_Model_Resource_Field::QTY_ASSOCIATED . "',
|
27 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER . "', 0, NULL, 1, 0),
|
28 |
-
({$websiteId}, '" .ChoiceAI_Searchcore_Model_Resource_Field::QTY_CONFIG_USE_MANAGE_STOCK_ASSOCIATED. "',
|
29 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER . "', 0, NULL, 1, 0),
|
30 |
-
({$websiteId}, 'statusAssociated',
|
31 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER . "', 0, NULL, 1, 0),
|
32 |
-
({$websiteId}, '" .ChoiceAI_Searchcore_Model_Resource_Field::AVAILABILITY_ASSOCIATED . "',
|
33 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_BOOL . "', 0, NULL, 1, 0),
|
34 |
-
({$websiteId}, '" .ChoiceAI_Searchcore_Model_Resource_Field::QTY_MANAGE . "',
|
35 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER . "', 0, NULL, 0, 0),
|
36 |
-
({$websiteId}, '" .ChoiceAI_Searchcore_Model_Resource_Field::QTY_CONFIG_USE_MANAGE_STOCK . "',
|
37 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER . "', 0, NULL, 0, 0),
|
38 |
-
({$websiteId}, '" .ChoiceAI_Searchcore_Model_Resource_Field::QTY . "',
|
39 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_NUMBER . "', 0, NULL, 0, 0),
|
40 |
-
({$websiteId}, 'type_id',
|
41 |
-
'" .ChoiceAI_Searchcore_Helper_Constants::CHOICEAI_DATATYPE_LONGTEXT . "', 0, NULL, 0, 1)
|
42 |
-
ON DUPLICATE KEY UPDATE `field_name`=`field_name`;";
|
43 |
-
$installer->run($insertQuery);
|
44 |
-
}
|
45 |
-
|
46 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/design/frontend/base/default/layout/choiceai_personalisation.xml
CHANGED
@@ -21,6 +21,24 @@
|
|
21 |
</reference>
|
22 |
</checkout_cart_index>
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
<!-- <checkout_onepage_success>
|
25 |
<reference name="head">
|
26 |
<block type="choiceai_personalisation/event_checkout_onepage_success" name="choiceai_personalisation_event_checkout_onepage_success" />
|
@@ -34,6 +52,9 @@
|
|
34 |
<reference name="head">
|
35 |
<block type="choiceai_personalisation/event_checkout_onepage_success" name="choiceai_personalisation_event_checkout_onepage_success" />
|
36 |
</reference>
|
|
|
|
|
|
|
37 |
</default>
|
38 |
|
39 |
</layout>
|
21 |
</reference>
|
22 |
</checkout_cart_index>
|
23 |
|
24 |
+
<catalog_category_default>
|
25 |
+
<reference name="before_body_end">
|
26 |
+
<block type="choiceai_personalisation/event_analytics_listpage" name="choiceai_personalisation_event_analytics_listpage" />
|
27 |
+
</reference>
|
28 |
+
</catalog_category_default>
|
29 |
+
|
30 |
+
<catalog_category_layered>
|
31 |
+
<reference name="before_body_end">
|
32 |
+
<block type="choiceai_personalisation/event_analytics_listpage" name="choiceai_personalisation_event_analytics_listpage" />
|
33 |
+
</reference>
|
34 |
+
</catalog_category_layered>
|
35 |
+
|
36 |
+
<catalogsearch_result_index>
|
37 |
+
<reference name="before_body_end">
|
38 |
+
<block type="choiceai_personalisation/event_analytics_search" name="choiceai_personalisation_event_analytics_search" />
|
39 |
+
</reference>
|
40 |
+
</catalogsearch_result_index>
|
41 |
+
|
42 |
<!-- <checkout_onepage_success>
|
43 |
<reference name="head">
|
44 |
<block type="choiceai_personalisation/event_checkout_onepage_success" name="choiceai_personalisation_event_checkout_onepage_success" />
|
52 |
<reference name="head">
|
53 |
<block type="choiceai_personalisation/event_checkout_onepage_success" name="choiceai_personalisation_event_checkout_onepage_success" />
|
54 |
</reference>
|
55 |
+
<reference name="before_body_end">
|
56 |
+
<block type="choiceai_personalisation/searchpage_addparam" name="choiceai_personalisation_searchpage_addparam" />
|
57 |
+
</reference>
|
58 |
</default>
|
59 |
|
60 |
</layout>
|
app/design/frontend/base/default/template/choiceai/personalisation/analytics/listpage.phtml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Passing passback if received from server
|
3 |
+
if(Mage::registry("expId") && !Mage::registry("passback")) { ?>
|
4 |
+
<script type="text/javascript">
|
5 |
+
window._caiExistingPage = '<?php echo Mage::registry("expId") ?>';
|
6 |
+
</script>
|
7 |
+
<?php
|
8 |
+
}
|
9 |
+
if (Mage::registry("passback")) { ?>
|
10 |
+
<script type="text/javascript">
|
11 |
+
//<![CDATA[
|
12 |
+
window._caiapi = window._caiapi || [];
|
13 |
+
window._caiExistingPage = '<?php echo Mage::registry("passback")["expId"] ?>';
|
14 |
+
_caiapi.push(['trackExperiment', <?php echo Mage::helper('core')->jsonEncode(Mage::registry("passback")) ?>]);
|
15 |
+
//]]>
|
16 |
+
</script>
|
17 |
+
<?php
|
18 |
+
}
|
19 |
+
?>
|
20 |
+
|
21 |
+
<script type="text/javascript">
|
22 |
+
//<![CDATA[
|
23 |
+
window._caity = <?php echo $this->engineStatus() ? '"clistpage"' : '"category"' ?>;
|
24 |
+
//]]>
|
25 |
+
</script>
|
app/design/frontend/base/default/template/choiceai/personalisation/analytics/search.phtml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Passing passback if received from server
|
3 |
+
if(Mage::registry("expId") && !Mage::registry("passback")) { ?>
|
4 |
+
<script type="text/javascript">
|
5 |
+
window._caiExistingPage = '<?php echo Mage::registry("expId") ?>';
|
6 |
+
</script>
|
7 |
+
<?php
|
8 |
+
}
|
9 |
+
if (Mage::registry("passback")) { ?>
|
10 |
+
<script type="text/javascript">
|
11 |
+
//<![CDATA[
|
12 |
+
window._caiapi = window._caiapi || [];
|
13 |
+
window._caiExistingPage = '<?php echo Mage::registry("passback")["expId"] ?>';
|
14 |
+
_caiapi.push(['trackExperiment', <?php echo Mage::helper('core')->jsonEncode(Mage::registry("passback")) ?>]);
|
15 |
+
//]]>
|
16 |
+
</script>
|
17 |
+
<?php
|
18 |
+
}
|
19 |
+
?>
|
20 |
+
|
21 |
+
<script type="text/javascript">
|
22 |
+
//<![CDATA[
|
23 |
+
window._caity = <?php echo $this->engineStatus() ? '"csearch"' : '"search"' ?>;
|
24 |
+
//]]>
|
25 |
+
</script>
|
app/design/frontend/base/default/template/choiceai/personalisation/base/addparam.phtml
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- not to be executed as it will give wrong result-->
|
2 |
+
<?php if (false && $this->engineStatus()) : ?>
|
3 |
+
<script type="text/javascript">
|
4 |
+
var searchInput = document.getElementById("search_mini_form");
|
5 |
+
|
6 |
+
<?php if(Mage::registry("tagsList") != '') : ?>
|
7 |
+
var input = document.createElement("input");
|
8 |
+
input.name = "tagsList";
|
9 |
+
input.type = "hidden";
|
10 |
+
input.value = "<?php echo Mage::registry("tagsList"); ?>";
|
11 |
+
|
12 |
+
searchInput.appendChild(input);
|
13 |
+
<?php endif; ?>
|
14 |
+
|
15 |
+
<?php if(Mage::registry("catPaths") && Mage::registry("catPaths") != "") : ?>
|
16 |
+
var input2 = document.createElement("input");
|
17 |
+
input2.name = "catPaths";
|
18 |
+
input2.type = "hidden";
|
19 |
+
input2.value = '<?php echo Mage::registry("catPaths"); ?>';
|
20 |
+
|
21 |
+
searchInput.appendChild(input2);
|
22 |
+
<?php endif; ?>
|
23 |
+
|
24 |
+
|
25 |
+
<?php if(Mage::registry("prodCountNow") != '') : ?>
|
26 |
+
var input3 = document.createElement("input");
|
27 |
+
input3.name = "ct";
|
28 |
+
input3.type = "hidden";
|
29 |
+
input3.value = <?php echo Mage::registry("prodCountNow"); ?>;
|
30 |
+
|
31 |
+
searchInput.appendChild(input3);
|
32 |
+
<?php endif; ?>
|
33 |
+
</script>
|
34 |
+
<?php endif; ?>
|
lib/ChoiceAI/Client.php
CHANGED
@@ -30,6 +30,12 @@ class ChoiceAI_Client {
|
|
30 |
|
31 |
protected $address = '';
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
/**
|
34 |
* Number of seconds after a timeout occurs for every request
|
35 |
* If using indexing of file large value necessary.
|
@@ -57,7 +63,12 @@ class ChoiceAI_Client {
|
|
57 |
*/
|
58 |
public function __construct(array $config = array()) {
|
59 |
$this->setConfig($config);
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
61 |
}
|
62 |
|
63 |
/**
|
@@ -152,11 +163,7 @@ class ChoiceAI_Client {
|
|
152 |
* @return ChoiceAI_Client Client object
|
153 |
*/
|
154 |
public function setOffset($pg = 0){
|
155 |
-
|
156 |
-
$this->params['start'] = $pg;
|
157 |
-
}else{
|
158 |
-
$this->params['start'] = 10;
|
159 |
-
}
|
160 |
return $this;
|
161 |
}
|
162 |
|
@@ -166,12 +173,7 @@ class ChoiceAI_Client {
|
|
166 |
* @return ChoiceAI_Client Client object
|
167 |
*/
|
168 |
public function setLimit($limit = 20){
|
169 |
-
|
170 |
-
$this->params['limit'] = $limit;
|
171 |
-
}else{
|
172 |
-
$this->params['limit'] = 20;
|
173 |
-
}
|
174 |
-
|
175 |
return $this;
|
176 |
}
|
177 |
|
@@ -195,9 +197,11 @@ class ChoiceAI_Client {
|
|
195 |
* @return ChoiceAI_Client Client object
|
196 |
*/
|
197 |
public function setSort($sorts = array()){
|
198 |
-
if(
|
199 |
$this->params['sort'] = $sorts;
|
200 |
-
}
|
|
|
|
|
201 |
return $this;
|
202 |
}
|
203 |
|
@@ -283,10 +287,55 @@ class ChoiceAI_Client {
|
|
283 |
$this->params['multiSelectFacet'] = $multiSelectFacet;
|
284 |
}
|
285 |
return $this;
|
286 |
-
|
287 |
}
|
288 |
|
289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
/**
|
291 |
*
|
292 |
* Search through ChoiceAI api
|
@@ -294,11 +343,24 @@ class ChoiceAI_Client {
|
|
294 |
* @return ChoiceAI_ResultSet object
|
295 |
*/
|
296 |
public function search() {
|
297 |
-
$service = new
|
298 |
$this->params["context"] = $this->getContext();
|
299 |
-
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
}
|
302 |
|
303 |
-
|
304 |
-
}
|
30 |
|
31 |
protected $address = '';
|
32 |
|
33 |
+
protected $choiceaiResponse = null;
|
34 |
+
|
35 |
+
protected $setFacets = null;
|
36 |
+
|
37 |
+
protected $inStoreChoice = '';
|
38 |
+
|
39 |
/**
|
40 |
* Number of seconds after a timeout occurs for every request
|
41 |
* If using indexing of file large value necessary.
|
63 |
*/
|
64 |
public function __construct(array $config = array()) {
|
65 |
$this->setConfig($config);
|
66 |
+
|
67 |
+
//inStoreChoice
|
68 |
+
$this->inStoreChoice = $this->_config['transport'].'://datav3.choice.ai/widget/v4/getInStoreChoice';
|
69 |
+
|
70 |
+
//tagProducts
|
71 |
+
$this->address = $this->_config['transport'].'://datav3.choice.ai/widget/v4/getTagProducts';
|
72 |
}
|
73 |
|
74 |
/**
|
163 |
* @return ChoiceAI_Client Client object
|
164 |
*/
|
165 |
public function setOffset($pg = 0){
|
166 |
+
$this->params['start'] = $pg;
|
|
|
|
|
|
|
|
|
167 |
return $this;
|
168 |
}
|
169 |
|
173 |
* @return ChoiceAI_Client Client object
|
174 |
*/
|
175 |
public function setLimit($limit = 20){
|
176 |
+
$this->params['limit'] = $limit;
|
|
|
|
|
|
|
|
|
|
|
177 |
return $this;
|
178 |
}
|
179 |
|
197 |
* @return ChoiceAI_Client Client object
|
198 |
*/
|
199 |
public function setSort($sorts = array()){
|
200 |
+
if(is_array($sorts) && count($sorts)){
|
201 |
$this->params['sort'] = $sorts;
|
202 |
+
}else{
|
203 |
+
$this->params['sort'] = array("");
|
204 |
+
}
|
205 |
return $this;
|
206 |
}
|
207 |
|
287 |
$this->params['multiSelectFacet'] = $multiSelectFacet;
|
288 |
}
|
289 |
return $this;
|
|
|
290 |
}
|
291 |
|
292 |
|
293 |
+
/**
|
294 |
+
* function to get facets
|
295 |
+
* @param mixed $param array
|
296 |
+
* @return $facetstring string
|
297 |
+
*/
|
298 |
+
public function getFilters()
|
299 |
+
{
|
300 |
+
$allSysFacets = Mage::app()->getCache()->load("sysFacets");
|
301 |
+
|
302 |
+
// Saving facets to cache if not present already
|
303 |
+
if (!$allSysFacets || count($allSysFacets) <= 0) {
|
304 |
+
$allSysFacets = array();
|
305 |
+
|
306 |
+
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
|
307 |
+
$collection->addFieldToSelect("attribute_code");
|
308 |
+
$collection->addFieldToFilter(
|
309 |
+
array("is_filterable", "is_filterable_in_search"),
|
310 |
+
array(
|
311 |
+
array("eq"=>1),
|
312 |
+
array("eq"=>1)
|
313 |
+
)
|
314 |
+
);
|
315 |
+
$collection->load();
|
316 |
+
|
317 |
+
foreach ($collection as $attr)
|
318 |
+
$allSysFacets[] = $attr->getAttributeCode();
|
319 |
+
|
320 |
+
$cache = Mage::app()->getCache();
|
321 |
+
$cache->save(Mage::helper('core')->jsonEncode($allSysFacets), "sysFacets", array("facets"));
|
322 |
+
} else {
|
323 |
+
$allSysFacets = Mage::helper('core')->jsonDecode($allSysFacets);
|
324 |
+
}
|
325 |
+
|
326 |
+
if (count($_GET)) {
|
327 |
+
$appliedFacets = array();
|
328 |
+
foreach ($allSysFacets as $facet) {
|
329 |
+
if (isset($_GET[$facet]))
|
330 |
+
$appliedFacets[$facet] = $_GET[$facet];
|
331 |
+
}
|
332 |
+
|
333 |
+
// return '&facets=' . Mage::helper('core')->jsonEncode($appliedFacets);
|
334 |
+
if (count($appliedFacets))
|
335 |
+
$this->setFacets = Mage::helper('core')->jsonEncode($appliedFacets);
|
336 |
+
}
|
337 |
+
}
|
338 |
+
|
339 |
/**
|
340 |
*
|
341 |
* Search through ChoiceAI api
|
343 |
* @return ChoiceAI_ResultSet object
|
344 |
*/
|
345 |
public function search() {
|
346 |
+
$service = new ChoiceAI_Service();
|
347 |
$this->params["context"] = $this->getContext();
|
348 |
+
$this->params["org"] = explode("_", $this->params["context"])[0];
|
349 |
+
|
350 |
+
// Checks and sets facets in $this->setFacets
|
351 |
+
$this->getFilters();
|
352 |
+
|
353 |
+
if(is_null($this->choiceaiResponse)) {
|
354 |
+
if ((int)$this->params['start'] > 0 || $this->setFacets != null) {
|
355 |
+
$this->params["facets"] = $this->setFacets;
|
356 |
+
$this->choiceaiResponse = $service->search($this->params, $this->address, "tag");
|
357 |
+
} else {
|
358 |
+
$this->choiceaiResponse = $service->search($this->params, $this->inStoreChoice, "choice");
|
359 |
+
}
|
360 |
+
return $this->choiceaiResponse;
|
361 |
+
} else {
|
362 |
+
return $this->choiceaiResponse;
|
363 |
+
}
|
364 |
}
|
365 |
|
366 |
+
}
|
|
lib/ChoiceAI/Response.php
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @copyright Copyright (c) MineWhat
|
5 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
6 |
-
*/
|
7 |
-
|
8 |
-
class ChoiceAIResponse
|
9 |
-
{
|
10 |
-
var $results=array();
|
11 |
-
|
12 |
-
public function __construct($results){
|
13 |
-
$this->results=$results;
|
14 |
-
}
|
15 |
-
|
16 |
-
/**
|
17 |
-
* function to get products
|
18 |
-
*/
|
19 |
-
|
20 |
-
public function getResults(){
|
21 |
-
return $this->results["response"]["products"];
|
22 |
-
}
|
23 |
-
|
24 |
-
|
25 |
-
/**
|
26 |
-
* get Number of search Results
|
27 |
-
*/
|
28 |
-
public function getNumberOfProducts(){
|
29 |
-
return $this->results["response"]["numberOfProducts"];
|
30 |
-
}
|
31 |
-
|
32 |
-
|
33 |
-
/**
|
34 |
-
* get facets
|
35 |
-
*
|
36 |
-
*/
|
37 |
-
public function getFacets(){
|
38 |
-
return $this->results["facets"];
|
39 |
-
}
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
}
|
44 |
-
|
45 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/ChoiceAI/Result.php
CHANGED
@@ -22,8 +22,8 @@ class ChoiceAI_Result {
|
|
22 |
|
23 |
$this->_hit = $hit;
|
24 |
|
25 |
-
$this->_hit["uniqueId"] = $hit["
|
26 |
-
$this->_hit["entity_id"] = $hit["
|
27 |
|
28 |
if (strpos($this->_hit["image"], 'catalog/product') !== false) {
|
29 |
$this->_hit["image"] = "/" . implode("/", array_slice(explode ( "/", $this->_hit["image"]), -3, 3));
|
@@ -33,7 +33,7 @@ class ChoiceAI_Result {
|
|
33 |
$this->_hit["thumbnail"] = $this->_hit["image"];
|
34 |
|
35 |
$this->_hit["final_price"] = $hit["price"];
|
36 |
-
if(!is_null($hit["oldPrice"]) && $hit["oldPrice"] > 0) {
|
37 |
$this->_hit["price"] = $hit["oldPrice"];
|
38 |
} else {
|
39 |
$this->_hit["price"] = $hit["price"];
|
@@ -49,7 +49,7 @@ class ChoiceAI_Result {
|
|
49 |
* @param string $key Key name
|
50 |
* @return mixed Key value
|
51 |
*/
|
52 |
-
public function __get($key) {
|
53 |
return array_key_exists($key, $this->_hit) ? $this->_hit[$key] : null;
|
54 |
}
|
55 |
|
22 |
|
23 |
$this->_hit = $hit;
|
24 |
|
25 |
+
$this->_hit["uniqueId"] = $hit["pid"];
|
26 |
+
$this->_hit["entity_id"] = $hit["pid"];
|
27 |
|
28 |
if (strpos($this->_hit["image"], 'catalog/product') !== false) {
|
29 |
$this->_hit["image"] = "/" . implode("/", array_slice(explode ( "/", $this->_hit["image"]), -3, 3));
|
33 |
$this->_hit["thumbnail"] = $this->_hit["image"];
|
34 |
|
35 |
$this->_hit["final_price"] = $hit["price"];
|
36 |
+
if(isset($hit["oldPrice"]) && !is_null($hit["oldPrice"]) && $hit["oldPrice"] > 0) {
|
37 |
$this->_hit["price"] = $hit["oldPrice"];
|
38 |
} else {
|
39 |
$this->_hit["price"] = $hit["price"];
|
49 |
* @param string $key Key name
|
50 |
* @return mixed Key value
|
51 |
*/
|
52 |
+
public function __get($key) {
|
53 |
return array_key_exists($key, $this->_hit) ? $this->_hit[$key] : null;
|
54 |
}
|
55 |
|
lib/ChoiceAI/ResultSet.php
CHANGED
@@ -43,7 +43,7 @@ class ChoiceAI_ResultSet implements Iterator, Countable {
|
|
43 |
|
44 |
|
45 |
/**
|
46 |
-
* Loads all data into the results object (
|
47 |
*
|
48 |
* @param array $response
|
49 |
*/
|
@@ -51,12 +51,19 @@ class ChoiceAI_ResultSet implements Iterator, Countable {
|
|
51 |
$this->_response = $response;
|
52 |
|
53 |
$result = $response;
|
54 |
-
$this->_totalHits = $result["
|
55 |
$this->_took = isset($result["searchMetaData"]["queryTime"]) ? $result["searchMetaData"]['queryTime'] : 0;
|
56 |
-
if (isset($result["
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
}
|
62 |
|
@@ -74,8 +81,8 @@ class ChoiceAI_ResultSet implements Iterator, Countable {
|
|
74 |
*
|
75 |
* @return boolean Facet existence
|
76 |
*/
|
|
|
77 |
public function hasFacets() {
|
78 |
-
|
79 |
return isset($this->_response['facets']);
|
80 |
}
|
81 |
|
@@ -86,7 +93,7 @@ class ChoiceAI_ResultSet implements Iterator, Countable {
|
|
86 |
*/
|
87 |
public function getFacets() {
|
88 |
//return isset($this->_response['facets']) ? $this->_response['facets'] : array();
|
89 |
-
return isset($this->_response
|
90 |
}
|
91 |
|
92 |
/**
|
@@ -194,27 +201,24 @@ class ChoiceAI_ResultSet implements Iterator, Countable {
|
|
194 |
* get didYouMean results
|
195 |
*/
|
196 |
public function getSpellSuggestion(){
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
}
|
211 |
-
}
|
212 |
-
|
213 |
}
|
214 |
|
215 |
/**
|
216 |
-
* get stats
|
217 |
-
*/
|
218 |
public function getStats(){
|
219 |
// echo json_encode($this->_response);
|
220 |
return isset($this->_response['stats'])?$this->_response['stats']:null;
|
43 |
|
44 |
|
45 |
/**
|
46 |
+
* Loads all data into the results object (initialisation)
|
47 |
*
|
48 |
* @param array $response
|
49 |
*/
|
51 |
$this->_response = $response;
|
52 |
|
53 |
$result = $response;
|
54 |
+
$this->_totalHits = $result["total"];
|
55 |
$this->_took = isset($result["searchMetaData"]["queryTime"]) ? $result["searchMetaData"]['queryTime'] : 0;
|
56 |
+
if (isset($result["products"])) {
|
57 |
+
if(isset($result["ids"])) {
|
58 |
+
foreach ($result["ids"] as $prodId) {
|
59 |
+
if(isset($result['products'][$prodId]))
|
60 |
+
$this->_results[] = new ChoiceAI_Result($result['products'][$prodId]);
|
61 |
+
}
|
62 |
+
}else {
|
63 |
+
foreach ($result["products"] as $hit) {
|
64 |
+
$this->_results[] = new ChoiceAI_Result($hit);
|
65 |
+
}
|
66 |
+
}
|
67 |
}
|
68 |
}
|
69 |
|
81 |
*
|
82 |
* @return boolean Facet existence
|
83 |
*/
|
84 |
+
// @TODO: Not being used
|
85 |
public function hasFacets() {
|
|
|
86 |
return isset($this->_response['facets']);
|
87 |
}
|
88 |
|
93 |
*/
|
94 |
public function getFacets() {
|
95 |
//return isset($this->_response['facets']) ? $this->_response['facets'] : array();
|
96 |
+
return isset($this->_response) && isset($this->_response['facets']) ? $this->_response['facets'] : array();
|
97 |
}
|
98 |
|
99 |
/**
|
201 |
* get didYouMean results
|
202 |
*/
|
203 |
public function getSpellSuggestion(){
|
204 |
+
$suggests=isset($this->_response['didYouMean'])?$this->_response['didYouMean']:null;
|
205 |
+
|
206 |
+
if(is_null($suggests)||!is_array($suggests)||!sizeof($suggests)>0){
|
207 |
+
return null;
|
208 |
+
}
|
209 |
+
|
210 |
+
foreach($suggests as $suggestion){
|
211 |
+
foreach($suggestion as $suggest_key=>$suggest_value){
|
212 |
+
if($suggest_key=='suggestion'){
|
213 |
+
return $suggest_value;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
}
|
|
|
|
|
|
|
217 |
}
|
218 |
|
219 |
/**
|
220 |
+
* get stats
|
221 |
+
*/
|
222 |
public function getStats(){
|
223 |
// echo json_encode($this->_response);
|
224 |
return isset($this->_response['stats'])?$this->_response['stats']:null;
|
lib/ChoiceAI/Service.php
CHANGED
@@ -6,16 +6,18 @@
|
|
6 |
*/
|
7 |
|
8 |
include("ResultSet.php");
|
|
|
9 |
class ChoiceAI_Service
|
10 |
{
|
11 |
|
12 |
-
public function getOptions($options)
|
13 |
-
|
|
|
14 |
return "";
|
15 |
}
|
16 |
$content = '';
|
17 |
-
foreach($options as $key
|
18 |
-
$content = $content.'&'. rawurlencode($key).'='.rawurlencode($value);
|
19 |
}
|
20 |
|
21 |
return $content;
|
@@ -26,24 +28,40 @@ class ChoiceAI_Service
|
|
26 |
* method to set sort fields
|
27 |
*
|
28 |
*/
|
29 |
-
public function getSorting($sorts)
|
30 |
-
|
31 |
-
$sortString='
|
32 |
-
$startFlag=false;
|
33 |
|
34 |
-
if(is_null($sorts)
|
35 |
return '';
|
36 |
}
|
37 |
|
38 |
-
foreach($sorts as $
|
39 |
-
if($startFlag) {
|
40 |
-
$sortString=$sortString.",";
|
41 |
-
}
|
42 |
-
$startFlag = true;
|
43 |
-
if($sort_value == 1) {
|
44 |
-
$sortString=$sortString.rawurlencode($sort_key." asc");
|
45 |
-
} else {
|
46 |
-
$sortString=$sortString.rawurlencode($sort_key." desc");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
}
|
49 |
|
@@ -51,86 +69,18 @@ class ChoiceAI_Service
|
|
51 |
}
|
52 |
|
53 |
|
54 |
-
|
55 |
-
public function getFacetFields($facets,$filters){
|
56 |
-
|
57 |
-
$facetString="";
|
58 |
-
|
59 |
-
if($facets==null){
|
60 |
-
$facets=array();
|
61 |
-
}
|
62 |
-
foreach($facets as $facet){
|
63 |
-
$facetString=$facetString."&facet.field=";
|
64 |
-
if(array_key_exists($facet,$filters)){
|
65 |
-
if(!is_array($stringFacets[$facet]) || !sizeof($stringFacets[$facet]) > 0){
|
66 |
-
$facetString=$facetString.rawurlencode("{!ex=\"".$facet."\"}");
|
67 |
-
}
|
68 |
-
}
|
69 |
-
$facetString=$facetString.rawurlencode($facet);
|
70 |
-
}
|
71 |
-
|
72 |
-
return $facetString;
|
73 |
-
}
|
74 |
-
|
75 |
-
|
76 |
-
/**
|
77 |
-
* function to get facets
|
78 |
-
* @param mixed $param array
|
79 |
-
* @return $facetstring string
|
80 |
-
*/
|
81 |
-
public function getFilters($filter =array()) {
|
82 |
-
$facetString = '&filter='.rawurlencode(json_encode($filter));
|
83 |
-
return $facetString;
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* function to set String facets
|
88 |
-
* @param $facetkey string
|
89 |
-
* @param mixed $facetvalue array
|
90 |
-
* @param $multiSelectFacet boolean
|
91 |
-
* @return $facetstring string
|
92 |
-
*/
|
93 |
-
public function getAttributeFacets($facetkey = "", $facetValue = array(),$multiSelectFacet = false ){
|
94 |
-
|
95 |
-
$facetString = "(";
|
96 |
-
|
97 |
-
if(!is_array($facetValue) || !sizeof($facetValue) > 0){
|
98 |
-
return "";
|
99 |
-
}
|
100 |
-
|
101 |
-
$flag = false;
|
102 |
-
if($multiSelectFacet)
|
103 |
-
$facetString = $facetString.("{!tag=\"".$facetkey."\"}")."(";
|
104 |
-
foreach($facetValue as $value){
|
105 |
-
$value = str_replace('"','\"',$value);
|
106 |
-
if($flag){
|
107 |
-
$facetString=$facetString." OR ";
|
108 |
-
}
|
109 |
-
$flag=true;
|
110 |
-
if(is_array($value)){
|
111 |
-
$from = isset($value["from"])?$value["from"]:"*";
|
112 |
-
$to = isset($value["to"])?$value["to"]:"*";
|
113 |
-
$facetString=$facetString.$facetkey.":"."[".$from.' TO '.$to."]";
|
114 |
-
} else{
|
115 |
-
$facetString=$facetString.$facetkey.":"."\"".$value."\"";
|
116 |
-
}
|
117 |
-
}
|
118 |
-
|
119 |
-
return $facetString.")";
|
120 |
-
|
121 |
-
}
|
122 |
-
|
123 |
-
|
124 |
/**
|
125 |
* function to get queryParam
|
126 |
* @param mixed $ruleset string
|
127 |
* @return String query
|
128 |
*/
|
129 |
-
function getQueryParam($params = array())
|
130 |
-
|
131 |
-
|
|
|
|
|
132 |
} else {
|
133 |
-
return 'q='.rawurlencode($params['query']);
|
134 |
}
|
135 |
}
|
136 |
|
@@ -140,51 +90,125 @@ class ChoiceAI_Service
|
|
140 |
* @param mixed $address string
|
141 |
* @return String url
|
142 |
*/
|
143 |
-
function prepare_url($params = array(), $address = "")
|
144 |
-
|
145 |
-
$url = $
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
return $url;
|
154 |
}
|
155 |
|
156 |
/**
|
157 |
*
|
158 |
* function to fire search query
|
|
|
159 |
*
|
160 |
*/
|
161 |
-
public function search($params, $address, $
|
|
|
162 |
$url = $this->prepare_url($params, $address);
|
|
|
163 |
$opts = array(
|
164 |
-
'http'=>array(
|
165 |
-
'timeout'=>30
|
166 |
)
|
167 |
);
|
|
|
|
|
|
|
168 |
|
169 |
$context = stream_context_create($opts);
|
170 |
-
$response =file_get_contents($url, false, $context);
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
-
|
173 |
-
if(isset($response)) {
|
174 |
-
$choiceaiResponse=new ChoiceAI_ResultSet(json_decode($response,true));
|
175 |
|
176 |
-
if($
|
177 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
}
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
$
|
183 |
-
return $this->search($params, $address, true);
|
184 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
}
|
186 |
|
187 |
return $choiceaiResponse;
|
188 |
}
|
189 |
}
|
|
|
190 |
?>
|
6 |
*/
|
7 |
|
8 |
include("ResultSet.php");
|
9 |
+
|
10 |
class ChoiceAI_Service
|
11 |
{
|
12 |
|
13 |
+
public function getOptions($options)
|
14 |
+
{
|
15 |
+
if (!isset($options)) {
|
16 |
return "";
|
17 |
}
|
18 |
$content = '';
|
19 |
+
foreach ($options as $key => $value) {
|
20 |
+
$content = $content . '&' . rawurlencode($key) . '=' . rawurlencode($value);
|
21 |
}
|
22 |
|
23 |
return $content;
|
28 |
* method to set sort fields
|
29 |
*
|
30 |
*/
|
31 |
+
public function getSorting($sorts)
|
32 |
+
{
|
33 |
+
$sortString = '';
|
|
|
34 |
|
35 |
+
if (is_null($sorts) || !isset($sorts) || !is_array($sorts) || !sizeof($sorts) > 0) {
|
36 |
return '';
|
37 |
}
|
38 |
|
39 |
+
foreach ($sorts as $sortKey => $sortValue) {
|
40 |
+
// if($startFlag) {
|
41 |
+
// $sortString=$sortString.",";
|
42 |
+
// }
|
43 |
+
// $startFlag = true;
|
44 |
+
// if($sort_value == 1) {
|
45 |
+
// $sortString=$sortString.rawurlencode($sort_key." asc");
|
46 |
+
// } else {
|
47 |
+
// $sortString=$sortString.rawurlencode($sort_key." desc");
|
48 |
+
// }
|
49 |
+
switch ($sortKey) {
|
50 |
+
case $sortKey == "price_high_to_low":
|
51 |
+
$sortString .= "&sortBy=price&sortOrder=desc";
|
52 |
+
break;
|
53 |
+
|
54 |
+
case $sortKey == "price_low_to_high":
|
55 |
+
$sortString .= "&sortBy=price&sortOrder=asc";
|
56 |
+
break;
|
57 |
+
|
58 |
+
case $sortKey == "newest":
|
59 |
+
$sortString .= "&rmodel=newest";
|
60 |
+
break;
|
61 |
+
|
62 |
+
case $sortKey == "bestsellers":
|
63 |
+
$sortString .= "&rmodel=bestsellers";
|
64 |
+
break;
|
65 |
}
|
66 |
}
|
67 |
|
69 |
}
|
70 |
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
/**
|
73 |
* function to get queryParam
|
74 |
* @param mixed $ruleset string
|
75 |
* @return String query
|
76 |
*/
|
77 |
+
function getQueryParam($params = array())
|
78 |
+
{
|
79 |
+
// ty is setting the type of search
|
80 |
+
if ($params['ruleset'] == 'browse') {
|
81 |
+
return 'ty=clistpage';
|
82 |
} else {
|
83 |
+
return 'ty=csearch&q=' . rawurlencode($params['query']);
|
84 |
}
|
85 |
}
|
86 |
|
90 |
* @param mixed $address string
|
91 |
* @return String url
|
92 |
*/
|
93 |
+
function prepare_url($params = array(), $address = "")
|
94 |
+
{
|
95 |
+
$url = $address
|
96 |
+
. "?c=" . $params['context']
|
97 |
+
. "&org=" . $params['org']
|
98 |
+
. "&from=" . (isset($params['start']) ? $params['start'] : 0)
|
99 |
+
. "&size=" . (isset($params['limit']) ? $params['limit'] : 20);
|
100 |
+
$url = $url . '&' . $this->getQueryParam($params);
|
101 |
+
|
102 |
+
// da
|
103 |
+
// to be sent only if some count is there, regarding the current state, about results of screen before when the request was made
|
104 |
+
if (isset($_GET['ct']) && $_GET['ct'] != "0")
|
105 |
+
$url .= "&da=" . Mage::helper('core')->jsonEncode(array("lpimpressions" => $_GET['ct']));
|
106 |
+
else
|
107 |
+
$url .= "&da={}";
|
108 |
+
|
109 |
+
if (Mage::registry("expId")) {
|
110 |
+
$url .= "&existingPage=" . Mage::registry("expId");
|
111 |
+
}
|
112 |
+
|
113 |
+
// Facets, passing the facets from cache
|
114 |
+
if(isset($params['facets'])){
|
115 |
+
$url .= "&facets=".$params['facets'];
|
116 |
+
}
|
117 |
+
|
118 |
+
if (isset($params['sort']))
|
119 |
+
$url .= $this->getSorting($params['sort']);
|
120 |
+
if (isset($params['others']))
|
121 |
+
$url .= $this->getOptions($params['others']);
|
122 |
+
|
123 |
return $url;
|
124 |
}
|
125 |
|
126 |
/**
|
127 |
*
|
128 |
* function to fire search query
|
129 |
+
* Harkirat: Earlier in place of apiType, there was "$spellcheck = false"
|
130 |
*
|
131 |
*/
|
132 |
+
public function search($params, $address, $apiType = false)
|
133 |
+
{
|
134 |
$url = $this->prepare_url($params, $address);
|
135 |
+
|
136 |
$opts = array(
|
137 |
+
'http' => array(
|
138 |
+
'timeout' => 30
|
139 |
)
|
140 |
);
|
141 |
+
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
142 |
+
$opts['http']['header'] = "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
|
143 |
+
}
|
144 |
|
145 |
$context = stream_context_create($opts);
|
146 |
+
$response = file_get_contents($url, false, $context);
|
147 |
+
|
148 |
+
Mage::getSingleton('core/cookie')->set("api_url", $url);
|
149 |
+
|
150 |
+
$choiceaiResponse = null;
|
151 |
+
if (isset($response)) {
|
152 |
+
$response = Mage::helper('core')->jsonDecode($response);
|
153 |
|
154 |
+
$data = $response['data'];
|
|
|
|
|
155 |
|
156 |
+
if ($apiType == "choice") {
|
157 |
+
$data = $response['data']['automations'];
|
158 |
+
if (isset($data[0]))
|
159 |
+
$data = $data[0];
|
160 |
+
else
|
161 |
+
$data = array();
|
162 |
+
} else {
|
163 |
+
$data = $response['data'];
|
164 |
+
}
|
165 |
+
|
166 |
+
// tagsList, catPaths
|
167 |
+
if (isset($data['tagsList'])) {
|
168 |
+
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "tagsList") === false)
|
169 |
+
$_SERVER['REDIRECT_QUERY_STRING'] .= "&tagsList=" . Mage::helper('core')->jsonEncode($data['tagsList']);
|
170 |
+
|
171 |
+
// Mage::register("tagsList", Mage::helper('core')->jsonEncode($data['tagsList']), true);
|
172 |
+
}
|
173 |
+
if (isset($data['catPaths'])) {
|
174 |
+
if(empty($data['catPaths'])){
|
175 |
+
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "catPaths") === false)
|
176 |
+
$_SERVER['REDIRECT_QUERY_STRING'] .= "&catPaths={}";
|
177 |
+
|
178 |
+
// Mage::register("catPaths", "{}", true);
|
179 |
+
}
|
180 |
+
else{
|
181 |
+
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "catPaths") === false)
|
182 |
+
$_SERVER['REDIRECT_QUERY_STRING'] .= "&catPaths=" . Mage::helper('core')->jsonEncode($data['catPaths']);
|
183 |
+
|
184 |
+
// Mage::register("catPaths", Mage::helper('core')->jsonEncode($data['catPaths']), true);
|
185 |
+
}
|
186 |
}
|
187 |
|
188 |
+
// for lpimpressions
|
189 |
+
if (isset($data['ids'])) {
|
190 |
+
Mage::register("prodCountNow", count($data['ids']), true);
|
|
|
191 |
}
|
192 |
+
if (isset($data['passback']) && !empty($data['passback'])) {
|
193 |
+
Mage::register("passback", $data['passback'], true);
|
194 |
+
}
|
195 |
+
|
196 |
+
$choiceaiResponse = new ChoiceAI_ResultSet($data);
|
197 |
+
|
198 |
+
// Not required, spellcheck will be done server-side automagically
|
199 |
+
// if($spellcheck) {
|
200 |
+
// $choiceaiResponse->setSpellCheckQuery($params['query']);
|
201 |
+
// }
|
202 |
+
|
203 |
+
// if((!is_null($choiceaiResponse) && !$spellcheck && $choiceaiResponse->getTotalHits()==0 && !is_null($spellSuggest=$choiceaiResponse->getSpellSuggestion())) ||
|
204 |
+
// (!$spellcheck && $choiceaiResponse->getSpellcheckFrequency()>20 && !is_null($spellSuggest=$choiceaiResponse->getSpellSuggestion()))){
|
205 |
+
// $params['query'] = $spellSuggest;
|
206 |
+
// return $this->search($params, $address, true);
|
207 |
+
// }
|
208 |
}
|
209 |
|
210 |
return $choiceaiResponse;
|
211 |
}
|
212 |
}
|
213 |
+
|
214 |
?>
|
lib/ChoiceAI/test.php
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
include("Client.php");
|
3 |
-
$facetlist=array();
|
4 |
-
$facetValue=array("broad bangles");
|
5 |
-
|
6 |
-
|
7 |
-
$facetValue=array("April");
|
8 |
-
$facetlist["gemstone_month_fq"]=$facetValue;
|
9 |
-
|
10 |
-
|
11 |
-
$facets=array();
|
12 |
-
$facets[]="frame_shape_fq";
|
13 |
-
$facets[]="brand_name_fq";
|
14 |
-
$facets[]="primary_frame_color_fq";
|
15 |
-
$facets[]="price_fq";
|
16 |
-
$facets[]="frame_size_fq";
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
$rangelist=array();
|
21 |
-
$rangeValue=array(array("from"=>"0", "to" => "500000"),array("from"=>"50", "to" => "100"));
|
22 |
-
//$facetlist["price_fq"]=$rangeValue;
|
23 |
-
|
24 |
-
$sortlist=array();
|
25 |
-
$sortlist['name']=1;
|
26 |
-
|
27 |
-
$options = array();
|
28 |
-
$options["stats"] = "price";
|
29 |
-
|
30 |
-
$_config = array(
|
31 |
-
'sitename'=>'cl-sandbox-1375791452266',
|
32 |
-
'apikey'=>'ad93787f2f479e3e63b0161b3877ec7a',
|
33 |
-
);
|
34 |
-
|
35 |
-
|
36 |
-
$choiceai= new ChoiceAI_Client($_config);
|
37 |
-
|
38 |
-
$results = $choiceai->setCond()
|
39 |
-
->setRuleset("search")
|
40 |
-
->setOtherOptions(array('wt'=>'json'))
|
41 |
-
->setFilters($facetlist)
|
42 |
-
->setDebug(true)
|
43 |
-
->setQuery("diamond")
|
44 |
-
->search();
|
45 |
-
|
46 |
-
echo '<br/>'.$results->getTotalHits().'<br/>';
|
47 |
-
foreach($results as $result){
|
48 |
-
echo $result->__get('name')."<br/>";
|
49 |
-
}
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>choiceai</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">osl</license>
|
7 |
<channel>community</channel>
|
@@ -10,9 +10,9 @@
|
|
10 |
<description>Choice AI</description>
|
11 |
<notes>Initial Code</notes>
|
12 |
<authors><author><name>MineWhat Inc.</name><user>rahulb14</user><email>rahulb14@gmail.com</email></author><author><name>MineWhat Inc.</name><user>harkirat</user><email>harkirat1892@gmail.com</email></author></authors>
|
13 |
-
<date>2017-
|
14 |
-
<time>16:
|
15 |
-
<contents><target name="magecommunity"><dir name="ChoiceAI"><dir name="Personalisation"><dir name="Block"><dir name="Base"><file name="Script.php" hash="af614113dea10a0a6d88281f615f1929"/></dir><dir name="Event"><dir name="Catalog"><dir name="Product"><file name="View.php" hash="233ac45484c22ecdf7063071406f71e2"/></dir></dir><dir name="Checkout"><dir name="Cart"><file name="Index.php" hash="e3bc31a08a994d72223d78ebde8a74f0"/></dir><dir name="Onepage"><file name="Success.php" hash="cc242d118e6b06bb3817d95b2322167c"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="8ab9069ffe5aa66ef085124b8ff613d6"/></dir><dir name="Model"><file name="Observer.php" hash="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.5</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>choiceai</name>
|
4 |
+
<version>1.0.10</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">osl</license>
|
7 |
<channel>community</channel>
|
10 |
<description>Choice AI</description>
|
11 |
<notes>Initial Code</notes>
|
12 |
<authors><author><name>MineWhat Inc.</name><user>rahulb14</user><email>rahulb14@gmail.com</email></author><author><name>MineWhat Inc.</name><user>harkirat</user><email>harkirat1892@gmail.com</email></author></authors>
|
13 |
+
<date>2017-07-07</date>
|
14 |
+
<time>16:04:11</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="ChoiceAI"><dir name="Personalisation"><dir name="Block"><dir name="Base"><file name="Script.php" hash="af614113dea10a0a6d88281f615f1929"/></dir><dir name="Event"><dir name="Analytics"><file name="Listpage.php" hash="ebffb194cccf7fab9d6db59028bc7551"/><file name="Search.php" hash="6276c882a46630f77870a262cc158dfd"/></dir><dir name="Catalog"><dir name="Product"><file name="View.php" hash="233ac45484c22ecdf7063071406f71e2"/></dir></dir><dir name="Checkout"><dir name="Cart"><file name="Index.php" hash="e3bc31a08a994d72223d78ebde8a74f0"/></dir><dir name="Onepage"><file name="Success.php" hash="cc242d118e6b06bb3817d95b2322167c"/></dir></dir></dir><dir name="Searchpage"><file name="Addparam.php" hash="895157cf5ac87c294ab18c7b52412082"/></dir></dir><dir name="Helper"><file name="Data.php" hash="8ab9069ffe5aa66ef085124b8ff613d6"/></dir><dir name="Model"><file name="Observer.php" hash="3abfad9965e29886992d6c2e29bd5533"/></dir><dir name="controllers"><file name="ApiController.php" hash="5c34dfbdf2c2139117250f73248141c7"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2fc12bb0874c8f39963f1593b3954d2e"/><file name="config.xml" hash="f743d8ead3776891503ff368ad7e7330"/><file name="system.xml" hash="6f4674088b4c392cc06f5a70f383fd54"/></dir></dir></dir></target><target name="magelocal"><dir name="ChoiceAI"><dir name="Search"><dir name="Block"><dir name="Catalog"><dir name="Layer"><dir name="Filter"><file name="Attribute.php" hash="7920f693a41c71120640e58e425774c4"/><file name="Boolean.php" hash="b4725e9e63c54a5f06e226b2ba07423c"/><file name="Category.php" hash="f9add3a866fd08695fb8541292e345b5"/><file name="Decimal.php" hash="90b1f1b0e78c9fb8192affd726306939"/><file name="Price.php" hash="8a5219290c7773300725e99931dd265e"/></dir><file name="View.php" hash="e6698a73b03ab006859d4788fd770f66"/></dir><dir name="Product"><dir name="List"><file name="Toolbar.php" hash="04fba36c5a57f409b56659a2ba8fb645"/></dir><file name="List.php" hash="3e0b59fca7f65b0d3f6a130eefb801b8"/></dir></dir><dir name="Catalogsearch"><dir name="Enterprise"><file name="Layer.php" hash="76d2e136cfd2bdb8336bebc3e949035b"/></dir><dir name="Layer"><dir name="Filter"><file name="Attribute.php" hash="5d8377049114d7114468d083a06ae574"/></dir></dir><file name="Layer.php" hash="5cff5c396d96294cea2291b0f5f1b9d1"/><file name="Result.php" hash="28d419708e65be095a3905e0cdcdd56d"/></dir></dir><dir name="Helper"><file name="Choiceaisearch.php" hash="052795ea39da743fb0bf77f848b3123a"/><file name="Data.php" hash="1e1d8143831abc6ab7db8363ec34ed02"/><file name="Productimg.php" hash="7def046ff081389229b33285d2dbe6a5"/></dir><dir name="Model"><dir name="Catalog"><file name="Category.php" hash="d2898da3c579c4a8c6aba8ffa9f92e5c"/><file name="Config.php" hash="29bd684be415dfb46a562c4a18ebf93f"/><dir name="Layer"><dir name="Filter"><file name="Attribute.php" hash="67b32680a7471e7a5d2ea210b6c9d612"/><file name="Boolean.php" hash="4de1790d8a6355c512b0a1aee663b8aa"/><file name="Category.php" hash="597c8b4fc8c5ca892456a799302a09a4"/><file name="Decimal.php" hash="fe9ae194e4540352fc7953d6988b09bb"/><file name="Price.php" hash="3c1e0e58d4b6995c3ca66ba6ed9c5987"/></dir></dir><file name="Layer.php" hash="21673a913e8510804df7906f881d7054"/><dir name="Product"><file name="Url.php" hash="13545877391be6a0fbd1b624d43b80f5"/></dir></dir><dir name="Catalogsearch"><dir name="Layer"><dir name="Filter"><file name="Attribute.php" hash="0c08443cd3a964853e2eea7eab7ee550"/></dir></dir><file name="Layer.php" hash="7eb444d700b64d9655d9f5228c995688"/></dir><dir name="Resource"><dir name="Catalog"><dir name="Product"><file name="Collection.php" hash="1976dd848282e00158cabd6d7cf1528f"/></dir></dir><dir name="Engine"><file name="Abstract.php" hash="73c32a6e987875060d1d89692a34444b"/><dir name="Choiceaisearch"><file name="Client.php" hash="384c7d4597140b49912cc6633c4b3a8e"/></dir><file name="Choiceaisearch.php" hash="07dcb7b63bfe8bca0dd73f723f9cc9ee"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="67c129e2fe2159ee911991bba6e0d83f"/></dir></dir><dir name="Searchcore"><dir name="Helper"><file name="Constants.php" hash="aa53ac5d6cdc26e297d36c685cf1217c"/><file name="Data.php" hash="9df2c1f96a67c708bb039dbaf8f9b4d8"/></dir><dir name="etc"><file name="config.xml" hash="5a625a66e36ad56ea606100a2eb29908"/></dir></dir></dir></target><target name="magelib"><dir name="ChoiceAI"><file name="Client.php" hash="e6dfb5d68108d30dea6cf2055337f782"/><file name="Result.php" hash="b95b62cd11facae7f8318ad9e433cb42"/><file name="ResultSet.php" hash="228a8f2bca65527e3c3c68e49357339d"/><file name="Service.php" hash="5f99550891356d3dbaa41343f30dfa89"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="choiceai_personalisation.xml" hash="3f4490bde0510aa3752a51c602451d6c"/></dir><dir name="template"><dir name="choiceai"><dir name="personalisation"><dir name="analytics"><file name="listpage.phtml" hash="ac19a29e9ffb58f5056e1a7a968a626d"/><file name="search.phtml" hash="c7bc6540408024d048c6531d45d4807b"/></dir><dir name="base"><file name="addparam.phtml" hash="e9b7447c5ae2983796ab28c622d3684e"/><file name="script.phtml" hash="60b414f870c4b5bd761bfa2466d73707"/></dir><dir name="event"><dir name="catalog"><dir name="product"><file name="view.phtml" hash="9513eaaa0bda55931dacb6d90b698f31"/></dir></dir><dir name="checkout"><dir name="cart"><file name="index.phtml" hash="6a27ac509cc1c8c78515b025479f135b"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="default"><dir name="default"><dir name="layout"><file name="choiceai_personalisation.xml" hash="95d72912f3b13c5a399e3b2e5b89dba9"/></dir><dir name="template"><dir name="choiceai"><dir name="personalisation"><dir name="base"><file name="script.phtml" hash="ea2860493a07315af34ba80f8c282a84"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ChoiceAI_Personalisation.xml" hash="4bca20179604835e2e0e08298142c8bb"/></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.5</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|