Version Notes
Choice AI plugin
Download this release
Release Info
Developer | MineWhat Inc. |
Extension | choiceai |
Version | 1.0.12 |
Comparing to | |
See all releases |
Code changes from version 1.0.11 to 1.0.12
- app/code/community/ChoiceAI/Personalisation/controllers/ApiController.php +12 -3
- app/code/community/ChoiceAI/Personalisation/etc/config.xml +10 -1
- app/code/community/ChoiceAI/Personalisation/sql/personalisation_setup/install-1.0.12.php +31 -0
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch.php +275 -275
- app/code/local/ChoiceAI/Search/etc/config.xml +1 -1
- app/code/local/ChoiceAI/Searchcore/etc/config.xml +1 -1
- app/design/frontend/base/default/template/choiceai/personalisation/base/script.phtml +39 -39
- app/design/frontend/default/default/template/choiceai/personalisation/base/script.phtml +38 -38
- lib/ChoiceAI/Service.php +181 -181
- package.xml +4 -4
app/code/community/ChoiceAI/Personalisation/controllers/ApiController.php
CHANGED
@@ -88,7 +88,16 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
88 |
$responseObj['message'] = 'Invalid request';
|
89 |
}
|
90 |
|
91 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
$this->getResponse()
|
93 |
->setBody(json_encode($responseObj))
|
94 |
->setHttpResponseCode(200)
|
@@ -119,7 +128,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
119 |
$order = Mage::getModel('sales/order')->load($orderId, 'increment_id');
|
120 |
|
121 |
$extras = $this->getRequest()->getParam('extras');
|
122 |
-
$debug = $this->getRequest()->getParam('
|
123 |
if($extras && strlen($extras)) {
|
124 |
$extras = explode(',', $extras);
|
125 |
for($i = 0;$i < sizeof($extras);$i++) {
|
@@ -315,7 +324,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
315 |
);
|
316 |
|
317 |
$extras = $this->getRequest()->getParam('extras');
|
318 |
-
$debug = $this->getRequest()->getParam('
|
319 |
|
320 |
if($extras && strlen($extras)) {
|
321 |
$extras = explode(',', $extras);
|
88 |
$responseObj['message'] = 'Invalid request';
|
89 |
}
|
90 |
|
91 |
+
if(isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME'])){
|
92 |
+
$storeUrl = $_SERVER['REQUEST_SCHEME'] ."://". $_SERVER['SERVER_NAME'];
|
93 |
+
} else{
|
94 |
+
$storeUrl = Mage::getBaseUrl();
|
95 |
+
}
|
96 |
+
$responseObj['store_url'] = $storeUrl;
|
97 |
+
$responseObj['installed'] = '1';
|
98 |
+
$responseObj['api_version'] = self::API_VERSION;
|
99 |
+
$responseObj['plugin_version'] = (string)Mage::getConfig()->getNode('modules/ChoiceAI_Personalisation/version');
|
100 |
+
$responseObj['magento_version'] = Mage::getVersion();
|
101 |
$this->getResponse()
|
102 |
->setBody(json_encode($responseObj))
|
103 |
->setHttpResponseCode(200)
|
128 |
$order = Mage::getModel('sales/order')->load($orderId, 'increment_id');
|
129 |
|
130 |
$extras = $this->getRequest()->getParam('extras');
|
131 |
+
$debug = $this->getRequest()->getParam('mwdebug', 'false') === 'true';
|
132 |
if($extras && strlen($extras)) {
|
133 |
$extras = explode(',', $extras);
|
134 |
for($i = 0;$i < sizeof($extras);$i++) {
|
324 |
);
|
325 |
|
326 |
$extras = $this->getRequest()->getParam('extras');
|
327 |
+
$debug = $this->getRequest()->getParam('mwdebug', 'false') === 'true';
|
328 |
|
329 |
if($extras && strlen($extras)) {
|
330 |
$extras = explode(',', $extras);
|
app/code/community/ChoiceAI/Personalisation/etc/config.xml
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
<config>
|
11 |
<modules>
|
12 |
<ChoiceAI_Personalisation>
|
13 |
-
<version>
|
14 |
</ChoiceAI_Personalisation>
|
15 |
</modules>
|
16 |
<global>
|
@@ -43,6 +43,15 @@
|
|
43 |
</admin_system_config_changed_section_choiceai_personalisation>
|
44 |
</events>
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
</global>
|
47 |
<frontend>
|
48 |
<routers>
|
10 |
<config>
|
11 |
<modules>
|
12 |
<ChoiceAI_Personalisation>
|
13 |
+
<version>1.0.12</version>
|
14 |
</ChoiceAI_Personalisation>
|
15 |
</modules>
|
16 |
<global>
|
43 |
</admin_system_config_changed_section_choiceai_personalisation>
|
44 |
</events>
|
45 |
|
46 |
+
|
47 |
+
<resources>
|
48 |
+
<personalisation_setup>
|
49 |
+
<setup>
|
50 |
+
<module>ChoiceAI_Personalisation</module>
|
51 |
+
</setup>
|
52 |
+
</personalisation_setup>
|
53 |
+
</resources>
|
54 |
+
|
55 |
</global>
|
56 |
<frontend>
|
57 |
<routers>
|
app/code/community/ChoiceAI/Personalisation/sql/personalisation_setup/install-1.0.12.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: harkirat
|
5 |
+
* Date: 13/7/17
|
6 |
+
* Time: 2:47 PM
|
7 |
+
*/
|
8 |
+
|
9 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
10 |
+
|
11 |
+
$installer = $this;
|
12 |
+
|
13 |
+
$installer->startSetup();
|
14 |
+
$pluginVersion = "1.0.12";
|
15 |
+
$magentoVersion = Mage::getVersion();
|
16 |
+
|
17 |
+
if(isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME'])){
|
18 |
+
$storeUrl = $_SERVER['REQUEST_SCHEME'] ."://". $_SERVER['SERVER_NAME'];
|
19 |
+
} else{
|
20 |
+
$storeUrl = Mage::getBaseUrl();
|
21 |
+
}
|
22 |
+
|
23 |
+
$ctx = stream_context_create(array('http'=>
|
24 |
+
array(
|
25 |
+
'timeout' => 5, //Wait for only 5 secs at max
|
26 |
+
)
|
27 |
+
));
|
28 |
+
|
29 |
+
file_get_contents("https://app.choice.ai/stats/magentoinstall?installed=1&store_url=".$storeUrl."&magento_version=".$magentoVersion."&plugin_version=".$pluginVersion, false, $ctx);
|
30 |
+
|
31 |
+
$installer->endSetup();
|
app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch.php
CHANGED
@@ -1,276 +1,276 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ChoiceAI engine.
|
5 |
-
*
|
6 |
-
* @package ChoiceAI_Search
|
7 |
-
* @copyright Copyright (c) MineWhat
|
8 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
-
*/
|
10 |
-
class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Search_Model_Resource_Engine_Abstract
|
11 |
-
{
|
12 |
-
/**
|
13 |
-
* Initializes search engine.
|
14 |
-
*
|
15 |
-
* @see
|
16 |
-
*/
|
17 |
-
public function __construct()
|
18 |
-
{
|
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'){
|
26 |
-
$result[$facetName] = array();
|
27 |
-
$count = 0;
|
28 |
-
$facetKey ='';
|
29 |
-
foreach($facetlist['values'] as $value){
|
30 |
-
if($count++ % 2 == 0){
|
31 |
-
$facetKey = $value;
|
32 |
-
}else{
|
33 |
-
$result[$facetName][$facetKey]=$value;
|
34 |
-
}
|
35 |
-
}
|
36 |
-
}else if($facetlist["type"]=='facet_ranges'){
|
37 |
-
$result[$facetName] = array();
|
38 |
-
$count = 0;
|
39 |
-
$facetKey = '';
|
40 |
-
$gap = floatval($facetlist['values']['gap']);
|
41 |
-
foreach($facetlist['values']['counts'] as $value){
|
42 |
-
if($count++ % 2 == 0){
|
43 |
-
$facetKey = floatval($value);
|
44 |
-
}else{
|
45 |
-
$result[$facetName]['['.$facetKey.' TO '.($facetKey + $gap).']']=$value;
|
46 |
-
}
|
47 |
-
}
|
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)){
|
60 |
-
foreach($facets as $facetKey=>$facetValue){
|
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();
|
81 |
-
$facets["attribute"] = $stringFacets;
|
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 |
-
|
100 |
-
/**
|
101 |
-
* Prepares sort fields.
|
102 |
-
*
|
103 |
-
* @param array $sortBy
|
104 |
-
* @return array
|
105 |
-
*/
|
106 |
-
protected function _prepareSortFields($sortBy=array())
|
107 |
-
{
|
108 |
-
$sort =array();
|
109 |
-
if(!isset($sortBy) || sizeof($sortBy) == 0) {
|
110 |
-
$sortParameter = array_key_exists('order',$_GET)?$_GET['order']:null;
|
111 |
-
$sortBy = (!is_null($sortParameter))?
|
112 |
-
array(array($sortParameter => (isset($_GET['dir']) && $_GET['dir'] == 'desc')?'desc':'asc')): array();
|
113 |
-
$sessionSort = Mage::getSingleton('catalog/session')->getSortOrder();
|
114 |
-
$sessionDir = Mage::getSingleton('catalog/session')->getSortDirection();
|
115 |
-
$sortBy = (is_null($sortBy)|| sizeof($sortBy) == 0) && !is_null($sessionSort) ?
|
116 |
-
array(array($sessionSort => ($sessionDir === 'desc')?'desc':'asc')):$sortBy;
|
117 |
-
}
|
118 |
-
|
119 |
-
foreach($sortBy as $value){
|
120 |
-
foreach($value as $sortKey=>$sortValue){
|
121 |
-
if($sortKey != "position" && $sortKey != "relevance"){
|
122 |
-
if($sortValue == 'asc'){
|
123 |
-
$sort[$sortKey] = 1;
|
124 |
-
}else{
|
125 |
-
$sort[$sortKey] = -1;
|
126 |
-
}
|
127 |
-
}
|
128 |
-
}
|
129 |
-
}
|
130 |
-
return $sort;
|
131 |
-
}
|
132 |
-
|
133 |
-
|
134 |
-
public function getStats($data){
|
135 |
-
$stats = $data->getStats();
|
136 |
-
if(isset($stats) && is_array($stats)){
|
137 |
-
return $stats;
|
138 |
-
}
|
139 |
-
return array();
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* prepare limitN
|
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) &&
|
177 |
-
sizeof($multiselectValue) && $multiselectValue[0] == 'true')?true:false;
|
178 |
-
$limit = $this->_prepareLimit($params);
|
179 |
-
if(isset($_GET['p'])){
|
180 |
-
$page = ((int)$_GET['p'] > 0)?((int)$_GET['p'] - 1)* $limit:0;
|
181 |
-
}else{
|
182 |
-
$page = 0;
|
183 |
-
}
|
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 |
-
else
|
238 |
-
{
|
239 |
-
$getParamsToSend['isnew'] = true;
|
240 |
-
}
|
241 |
-
|
242 |
-
// Calls Client.php in lib
|
243 |
-
$data = $this->client
|
244 |
-
->setOffset($page)
|
245 |
-
->setLimit($limit)
|
246 |
-
->setOtherOptions($getParamsToSend)
|
247 |
-
->setDebug(false)
|
248 |
-
->setSort($this->_prepareSortFields(array_key_exists('sort_by', $params)?$params['sort_by']:array()))
|
249 |
-
->search();
|
250 |
-
if (!$data instanceof ChoiceAI_ResultSet) {
|
251 |
-
return array();
|
252 |
-
}
|
253 |
-
|
254 |
-
// if($data->getSpellCheckQuery()) {
|
255 |
-
// // Not being read anywhere, so why setting it?
|
256 |
-
// Mage::unregister('spellcheckQuery');
|
257 |
-
// Mage::register('spellcheckQuery', $data->getSpellCheckQuery());
|
258 |
-
// }
|
259 |
-
|
260 |
-
|
261 |
-
/* @var $data ChoiceAI_ResultSet */
|
262 |
-
$result = array(
|
263 |
-
'total_count' => $data->getTotalHits(),
|
264 |
-
'result' => $this->_prepareResponse($data),
|
265 |
-
'stats' => $this->getStats($data)
|
266 |
-
);
|
267 |
-
$result['facets'] = $this->_prepareFacetsQueryResponse($data->getFacets());
|
268 |
-
// Seems unused
|
269 |
-
Mage::unregister('start');
|
270 |
-
Mage::register('start', $page* Mage::getStoreConfig('catalog/frontend/grid_per_page'));
|
271 |
-
return $result;
|
272 |
-
}
|
273 |
-
|
274 |
-
}
|
275 |
-
|
276 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* ChoiceAI engine.
|
5 |
+
*
|
6 |
+
* @package ChoiceAI_Search
|
7 |
+
* @copyright Copyright (c) MineWhat
|
8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
+
*/
|
10 |
+
class ChoiceAI_Search_Model_Resource_Engine_ChoiceAIsearch extends ChoiceAI_Search_Model_Resource_Engine_Abstract
|
11 |
+
{
|
12 |
+
/**
|
13 |
+
* Initializes search engine.
|
14 |
+
*
|
15 |
+
* @see
|
16 |
+
*/
|
17 |
+
public function __construct()
|
18 |
+
{
|
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'){
|
26 |
+
$result[$facetName] = array();
|
27 |
+
$count = 0;
|
28 |
+
$facetKey ='';
|
29 |
+
foreach($facetlist['values'] as $value){
|
30 |
+
if($count++ % 2 == 0){
|
31 |
+
$facetKey = $value;
|
32 |
+
}else{
|
33 |
+
$result[$facetName][$facetKey]=$value;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
}else if($facetlist["type"]=='facet_ranges'){
|
37 |
+
$result[$facetName] = array();
|
38 |
+
$count = 0;
|
39 |
+
$facetKey = '';
|
40 |
+
$gap = floatval($facetlist['values']['gap']);
|
41 |
+
foreach($facetlist['values']['counts'] as $value){
|
42 |
+
if($count++ % 2 == 0){
|
43 |
+
$facetKey = floatval($value);
|
44 |
+
}else{
|
45 |
+
$result[$facetName]['['.$facetKey.' TO '.($facetKey + $gap).']']=$value;
|
46 |
+
}
|
47 |
+
}
|
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)){
|
60 |
+
foreach($facets as $facetKey=>$facetValue){
|
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();
|
81 |
+
$facets["attribute"] = $stringFacets;
|
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 |
+
|
100 |
+
/**
|
101 |
+
* Prepares sort fields.
|
102 |
+
*
|
103 |
+
* @param array $sortBy
|
104 |
+
* @return array
|
105 |
+
*/
|
106 |
+
protected function _prepareSortFields($sortBy=array())
|
107 |
+
{
|
108 |
+
$sort =array();
|
109 |
+
if(!isset($sortBy) || sizeof($sortBy) == 0) {
|
110 |
+
$sortParameter = array_key_exists('order',$_GET)?$_GET['order']:null;
|
111 |
+
$sortBy = (!is_null($sortParameter))?
|
112 |
+
array(array($sortParameter => (isset($_GET['dir']) && $_GET['dir'] == 'desc')?'desc':'asc')): array();
|
113 |
+
$sessionSort = Mage::getSingleton('catalog/session')->getSortOrder();
|
114 |
+
$sessionDir = Mage::getSingleton('catalog/session')->getSortDirection();
|
115 |
+
$sortBy = (is_null($sortBy)|| sizeof($sortBy) == 0) && !is_null($sessionSort) ?
|
116 |
+
array(array($sessionSort => ($sessionDir === 'desc')?'desc':'asc')):$sortBy;
|
117 |
+
}
|
118 |
+
|
119 |
+
foreach($sortBy as $value){
|
120 |
+
foreach($value as $sortKey=>$sortValue){
|
121 |
+
if($sortKey != "position" && $sortKey != "relevance"){
|
122 |
+
if($sortValue == 'asc'){
|
123 |
+
$sort[$sortKey] = 1;
|
124 |
+
}else{
|
125 |
+
$sort[$sortKey] = -1;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
130 |
+
return $sort;
|
131 |
+
}
|
132 |
+
|
133 |
+
|
134 |
+
public function getStats($data){
|
135 |
+
$stats = $data->getStats();
|
136 |
+
if(isset($stats) && is_array($stats)){
|
137 |
+
return $stats;
|
138 |
+
}
|
139 |
+
return array();
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* prepare limitN
|
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) &&
|
177 |
+
sizeof($multiselectValue) && $multiselectValue[0] == 'true')?true:false;
|
178 |
+
$limit = $this->_prepareLimit($params);
|
179 |
+
if(isset($_GET['p'])){
|
180 |
+
$page = ((int)$_GET['p'] > 0)?((int)$_GET['p'] - 1)* $limit:0;
|
181 |
+
}else{
|
182 |
+
$page = 0;
|
183 |
+
}
|
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 |
+
else
|
238 |
+
{
|
239 |
+
$getParamsToSend['isnew'] = true;
|
240 |
+
}
|
241 |
+
|
242 |
+
// Calls Client.php in lib
|
243 |
+
$data = $this->client
|
244 |
+
->setOffset($page)
|
245 |
+
->setLimit($limit)
|
246 |
+
->setOtherOptions($getParamsToSend)
|
247 |
+
->setDebug(false)
|
248 |
+
->setSort($this->_prepareSortFields(array_key_exists('sort_by', $params)?$params['sort_by']:array()))
|
249 |
+
->search();
|
250 |
+
if (!$data instanceof ChoiceAI_ResultSet) {
|
251 |
+
return array();
|
252 |
+
}
|
253 |
+
|
254 |
+
// if($data->getSpellCheckQuery()) {
|
255 |
+
// // Not being read anywhere, so why setting it?
|
256 |
+
// Mage::unregister('spellcheckQuery');
|
257 |
+
// Mage::register('spellcheckQuery', $data->getSpellCheckQuery());
|
258 |
+
// }
|
259 |
+
|
260 |
+
|
261 |
+
/* @var $data ChoiceAI_ResultSet */
|
262 |
+
$result = array(
|
263 |
+
'total_count' => $data->getTotalHits(),
|
264 |
+
'result' => $this->_prepareResponse($data),
|
265 |
+
'stats' => $this->getStats($data)
|
266 |
+
);
|
267 |
+
$result['facets'] = $this->_prepareFacetsQueryResponse($data->getFacets());
|
268 |
+
// Seems unused
|
269 |
+
Mage::unregister('start');
|
270 |
+
Mage::register('start', $page* Mage::getStoreConfig('catalog/frontend/grid_per_page'));
|
271 |
+
return $result;
|
272 |
+
}
|
273 |
+
|
274 |
+
}
|
275 |
+
|
276 |
?>
|
app/code/local/ChoiceAI/Search/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<ChoiceAI_Search>
|
5 |
-
<version>
|
6 |
</ChoiceAI_Search>
|
7 |
</modules>
|
8 |
<global>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<ChoiceAI_Search>
|
5 |
+
<version>1.0.12</version>
|
6 |
</ChoiceAI_Search>
|
7 |
</modules>
|
8 |
<global>
|
app/code/local/ChoiceAI/Searchcore/etc/config.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<config>
|
2 |
<modules>
|
3 |
<ChoiceAI_Searchcore>
|
4 |
-
<version>
|
5 |
</ChoiceAI_Searchcore>
|
6 |
</modules>
|
7 |
<global>
|
1 |
<config>
|
2 |
<modules>
|
3 |
<ChoiceAI_Searchcore>
|
4 |
+
<version>1.0.12</version>
|
5 |
</ChoiceAI_Searchcore>
|
6 |
</modules>
|
7 |
<global>
|
app/design/frontend/base/default/template/choiceai/personalisation/base/script.phtml
CHANGED
@@ -1,40 +1,40 @@
|
|
1 |
-
<?php echo Mage::helper('choiceai_personalisation')->getBaseScript() ?>
|
2 |
-
<?php
|
3 |
-
$user = $this->getUser();
|
4 |
-
if($user) {
|
5 |
-
$email = $user->getEmail();
|
6 |
-
if ($email && strlen($email) > 0) {
|
7 |
-
?>
|
8 |
-
<script type="text/javascript">
|
9 |
-
//<![CDATA[
|
10 |
-
window._caiapi = window._caiapi || [];
|
11 |
-
_caiapi.push(['trackUser', '<?php echo $email ?>']);
|
12 |
-
//]]>
|
13 |
-
</script>
|
14 |
-
<?php
|
15 |
-
}
|
16 |
-
}
|
17 |
-
|
18 |
-
$cart = Mage::getModel('checkout/cart')->getQuote();
|
19 |
-
$cart_items = array();
|
20 |
-
foreach ($cart->getAllVisibleItems() as $item) {
|
21 |
-
$cart_item = array();
|
22 |
-
$cart_item['pid'] = $item->getProductId();
|
23 |
-
$cart_item['sku'] = $item->getSku();
|
24 |
-
$cart_item['name'] = $item->getProduct()->getName();
|
25 |
-
$cart_item['price'] = $item->getProduct()->getPrice();
|
26 |
-
$cart_item['final_price'] = $item->getProduct()->getFinalPrice();
|
27 |
-
$cart_item['special_price'] = $item->getProduct()->getSpecialPrice();
|
28 |
-
$cart_item['type'] = $item->getProduct()->getTypeId();
|
29 |
-
$cart_item['qty'] = $item->getQty();
|
30 |
-
$cart_items[] = $cart_item;
|
31 |
-
}
|
32 |
-
?>
|
33 |
-
|
34 |
-
<script type="text/javascript">
|
35 |
-
//<![CDATA[
|
36 |
-
window._mwuserid = '<?php echo Mage::registry("caiuid")?>';
|
37 |
-
window.CAI_CART_ITEMS = <?php echo json_encode($cart_items); ?>;
|
38 |
-
window.CAI_MAGENTO_ADDTOCART_FORM_KEY = '<?php echo Mage::getSingleton('core/session')->getFormKey()?>';
|
39 |
-
//]]>
|
40 |
</script>
|
1 |
+
<?php echo Mage::helper('choiceai_personalisation')->getBaseScript() ?>
|
2 |
+
<?php
|
3 |
+
$user = $this->getUser();
|
4 |
+
if($user) {
|
5 |
+
$email = $user->getEmail();
|
6 |
+
if ($email && strlen($email) > 0) {
|
7 |
+
?>
|
8 |
+
<script type="text/javascript">
|
9 |
+
//<![CDATA[
|
10 |
+
window._caiapi = window._caiapi || [];
|
11 |
+
_caiapi.push(['trackUser', '<?php echo $email ?>']);
|
12 |
+
//]]>
|
13 |
+
</script>
|
14 |
+
<?php
|
15 |
+
}
|
16 |
+
}
|
17 |
+
|
18 |
+
$cart = Mage::getModel('checkout/cart')->getQuote();
|
19 |
+
$cart_items = array();
|
20 |
+
foreach ($cart->getAllVisibleItems() as $item) {
|
21 |
+
$cart_item = array();
|
22 |
+
$cart_item['pid'] = $item->getProductId();
|
23 |
+
$cart_item['sku'] = $item->getSku();
|
24 |
+
$cart_item['name'] = $item->getProduct()->getName();
|
25 |
+
$cart_item['price'] = $item->getProduct()->getPrice();
|
26 |
+
$cart_item['final_price'] = $item->getProduct()->getFinalPrice();
|
27 |
+
$cart_item['special_price'] = $item->getProduct()->getSpecialPrice();
|
28 |
+
$cart_item['type'] = $item->getProduct()->getTypeId();
|
29 |
+
$cart_item['qty'] = $item->getQty();
|
30 |
+
$cart_items[] = $cart_item;
|
31 |
+
}
|
32 |
+
?>
|
33 |
+
|
34 |
+
<script type="text/javascript">
|
35 |
+
//<![CDATA[
|
36 |
+
window._mwuserid = '<?php echo Mage::registry("caiuid")?>';
|
37 |
+
window.CAI_CART_ITEMS = <?php echo json_encode($cart_items); ?>;
|
38 |
+
window.CAI_MAGENTO_ADDTOCART_FORM_KEY = '<?php echo Mage::getSingleton('core/session')->getFormKey()?>';
|
39 |
+
//]]>
|
40 |
</script>
|
app/design/frontend/default/default/template/choiceai/personalisation/base/script.phtml
CHANGED
@@ -1,39 +1,39 @@
|
|
1 |
-
<?php echo Mage::helper('choiceai_personalisation')->getBaseScript() ?>
|
2 |
-
<?php
|
3 |
-
$user = $this->getUser();
|
4 |
-
if($user) {
|
5 |
-
$email = $user->getEmail();
|
6 |
-
if ($email && strlen($email) > 0) {
|
7 |
-
?>
|
8 |
-
<script type="text/javascript">
|
9 |
-
//<![CDATA[
|
10 |
-
window._caiapi = window._caiapi || [];
|
11 |
-
_caiapi.push(['trackUser', '<?php echo $email ?>']);
|
12 |
-
//]]>
|
13 |
-
</script>
|
14 |
-
<?php
|
15 |
-
}
|
16 |
-
}
|
17 |
-
|
18 |
-
$cart = Mage::getModel('checkout/cart')->getQuote();
|
19 |
-
$cart_items = array();
|
20 |
-
foreach ($cart->getAllVisibleItems() as $item) {
|
21 |
-
$cart_item = array();
|
22 |
-
$cart_item['pid'] = $item->getProductId();
|
23 |
-
$cart_item['sku'] = $item->getSku();
|
24 |
-
$cart_item['name'] = $item->getProduct()->getName();
|
25 |
-
$cart_item['price'] = $item->getProduct()->getPrice();
|
26 |
-
$cart_item['final_price'] = $item->getProduct()->getFinalPrice();
|
27 |
-
$cart_item['special_price'] = $item->getProduct()->getSpecialPrice();
|
28 |
-
$cart_item['type'] = $item->getProduct()->getTypeId();
|
29 |
-
$cart_item['qty'] = $item->getQty();
|
30 |
-
$cart_items[] = $cart_item;
|
31 |
-
}
|
32 |
-
?>
|
33 |
-
|
34 |
-
<script type="text/javascript">
|
35 |
-
//<![CDATA[
|
36 |
-
window.CAI_CART_ITEMS = <?php echo json_encode($cart_items); ?>;
|
37 |
-
window.CAI_MAGENTO_ADDTOCART_FORM_KEY = '<?php echo Mage::getSingleton('core/session')->getFormKey()?>';
|
38 |
-
//]]>
|
39 |
</script>
|
1 |
+
<?php echo Mage::helper('choiceai_personalisation')->getBaseScript() ?>
|
2 |
+
<?php
|
3 |
+
$user = $this->getUser();
|
4 |
+
if($user) {
|
5 |
+
$email = $user->getEmail();
|
6 |
+
if ($email && strlen($email) > 0) {
|
7 |
+
?>
|
8 |
+
<script type="text/javascript">
|
9 |
+
//<![CDATA[
|
10 |
+
window._caiapi = window._caiapi || [];
|
11 |
+
_caiapi.push(['trackUser', '<?php echo $email ?>']);
|
12 |
+
//]]>
|
13 |
+
</script>
|
14 |
+
<?php
|
15 |
+
}
|
16 |
+
}
|
17 |
+
|
18 |
+
$cart = Mage::getModel('checkout/cart')->getQuote();
|
19 |
+
$cart_items = array();
|
20 |
+
foreach ($cart->getAllVisibleItems() as $item) {
|
21 |
+
$cart_item = array();
|
22 |
+
$cart_item['pid'] = $item->getProductId();
|
23 |
+
$cart_item['sku'] = $item->getSku();
|
24 |
+
$cart_item['name'] = $item->getProduct()->getName();
|
25 |
+
$cart_item['price'] = $item->getProduct()->getPrice();
|
26 |
+
$cart_item['final_price'] = $item->getProduct()->getFinalPrice();
|
27 |
+
$cart_item['special_price'] = $item->getProduct()->getSpecialPrice();
|
28 |
+
$cart_item['type'] = $item->getProduct()->getTypeId();
|
29 |
+
$cart_item['qty'] = $item->getQty();
|
30 |
+
$cart_items[] = $cart_item;
|
31 |
+
}
|
32 |
+
?>
|
33 |
+
|
34 |
+
<script type="text/javascript">
|
35 |
+
//<![CDATA[
|
36 |
+
window.CAI_CART_ITEMS = <?php echo json_encode($cart_items); ?>;
|
37 |
+
window.CAI_MAGENTO_ADDTOCART_FORM_KEY = '<?php echo Mage::getSingleton('core/session')->getFormKey()?>';
|
38 |
+
//]]>
|
39 |
</script>
|
lib/ChoiceAI/Service.php
CHANGED
@@ -1,181 +1,181 @@
|
|
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 |
-
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;
|
24 |
-
}
|
25 |
-
|
26 |
-
|
27 |
-
/**
|
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 |
-
foreach ($sorts as $sortKey => $sortValue) {
|
39 |
-
if($sortKey)
|
40 |
-
$sortString = "&caiSortBy=".$sortKey;
|
41 |
-
}
|
42 |
-
return $sortString;
|
43 |
-
}
|
44 |
-
|
45 |
-
|
46 |
-
/**
|
47 |
-
* function to get queryParam
|
48 |
-
* @param mixed $ruleset string
|
49 |
-
* @return String query
|
50 |
-
*/
|
51 |
-
function getQueryParam($params = array())
|
52 |
-
{
|
53 |
-
// ty is setting the type of search
|
54 |
-
if ($params['ruleset'] == 'browse') {
|
55 |
-
return 'ty=clistpage';
|
56 |
-
} else {
|
57 |
-
return 'ty=csearch&q=' . rawurlencode($params['query']);
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* function to prepare Url
|
63 |
-
* @param mixed $params array
|
64 |
-
* @param mixed $address string
|
65 |
-
* @return String url
|
66 |
-
*/
|
67 |
-
function prepare_url($params = array(), $address = "")
|
68 |
-
{
|
69 |
-
$url = $address
|
70 |
-
. "?c=" . $params['context']
|
71 |
-
. "&org=" . $params['org']
|
72 |
-
. "&from=" . (isset($params['start']) ? $params['start'] : 0)
|
73 |
-
. "&size=" . (isset($params['limit']) ? $params['limit'] : 20);
|
74 |
-
$url = $url . '&' . $this->getQueryParam($params);
|
75 |
-
|
76 |
-
// da
|
77 |
-
// to be sent only if some count is there, regarding the current state, about results of screen before when the request was made
|
78 |
-
if (isset($_GET['ct']) && $_GET['ct'] != "0")
|
79 |
-
$url .= "&da=" . Mage::helper('core')->jsonEncode(array("lpimpressions" => $_GET['ct']));
|
80 |
-
else
|
81 |
-
$url .= "&da={}";
|
82 |
-
|
83 |
-
if (Mage::registry("expId")) {
|
84 |
-
$url .= "&existingPage=" . Mage::registry("expId");
|
85 |
-
}
|
86 |
-
|
87 |
-
// Facets, passing the facets from cache
|
88 |
-
if(isset($params['facets'])){
|
89 |
-
$url .= "&facets=".$params['facets'];
|
90 |
-
}
|
91 |
-
|
92 |
-
if (isset($params['sort']))
|
93 |
-
$url .= $this->getSorting($params['sort']);
|
94 |
-
if (isset($params['others']))
|
95 |
-
$url .= $this->getOptions($params['others']);
|
96 |
-
|
97 |
-
return $url;
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
*
|
102 |
-
* function to fire search query
|
103 |
-
* Harkirat: Earlier in place of apiType, there was "$spellcheck = false"
|
104 |
-
*
|
105 |
-
*/
|
106 |
-
public function search($params, $address, $apiType = false)
|
107 |
-
{
|
108 |
-
$url = $this->prepare_url($params, $address);
|
109 |
-
|
110 |
-
$opts = array(
|
111 |
-
'http' => array(
|
112 |
-
'timeout' => 30
|
113 |
-
)
|
114 |
-
);
|
115 |
-
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
116 |
-
$opts['http']['header'] = "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
|
117 |
-
}
|
118 |
-
|
119 |
-
$context = stream_context_create($opts);
|
120 |
-
$response = file_get_contents($url, false, $context);
|
121 |
-
|
122 |
-
$choiceaiResponse = null;
|
123 |
-
if (isset($response)) {
|
124 |
-
$response = Mage::helper('core')->jsonDecode($response);
|
125 |
-
$uidData = $response['uid'];
|
126 |
-
if (isset($uidData)) {
|
127 |
-
$uid = explode( ',', $uidData );
|
128 |
-
Mage::register("caiuid",$uid[0],true);
|
129 |
-
}
|
130 |
-
|
131 |
-
$data = $response['data'];
|
132 |
-
|
133 |
-
if ($apiType == "choice") {
|
134 |
-
$data = $response['data']['automations'];
|
135 |
-
if (isset($data[0]))
|
136 |
-
$data = $data[0];
|
137 |
-
else
|
138 |
-
$data = array();
|
139 |
-
} else {
|
140 |
-
$data = $response['data'];
|
141 |
-
}
|
142 |
-
|
143 |
-
// tagsList, catPaths
|
144 |
-
if (isset($data['tagsList'])) {
|
145 |
-
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "tagsList") === false)
|
146 |
-
$_SERVER['REDIRECT_QUERY_STRING'] .= "&tagsList=" . Mage::helper('core')->jsonEncode($data['tagsList']);
|
147 |
-
|
148 |
-
// Mage::register("tagsList", Mage::helper('core')->jsonEncode($data['tagsList']), true);
|
149 |
-
}
|
150 |
-
if (isset($data['catPaths'])) {
|
151 |
-
if(empty($data['catPaths'])){
|
152 |
-
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "catPaths") === false)
|
153 |
-
$_SERVER['REDIRECT_QUERY_STRING'] .= "&catPaths={}";
|
154 |
-
|
155 |
-
// Mage::register("catPaths", "{}", true);
|
156 |
-
}
|
157 |
-
else{
|
158 |
-
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "catPaths") === false)
|
159 |
-
$_SERVER['REDIRECT_QUERY_STRING'] .= "&catPaths=" . Mage::helper('core')->jsonEncode($data['catPaths']);
|
160 |
-
|
161 |
-
// Mage::register("catPaths", Mage::helper('core')->jsonEncode($data['catPaths']), true);
|
162 |
-
}
|
163 |
-
}
|
164 |
-
|
165 |
-
// for lpimpressions
|
166 |
-
if (isset($data['ids'])) {
|
167 |
-
Mage::register("prodCountNow", count($data['ids']), true);
|
168 |
-
}
|
169 |
-
if (isset($data['passback']) && !empty($data['passback'])) {
|
170 |
-
Mage::register("passback", $data['passback'], true);
|
171 |
-
}
|
172 |
-
|
173 |
-
$choiceaiResponse = new ChoiceAI_ResultSet($data);
|
174 |
-
|
175 |
-
}
|
176 |
-
|
177 |
-
return $choiceaiResponse;
|
178 |
-
}
|
179 |
-
}
|
180 |
-
|
181 |
-
?>
|
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 |
+
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;
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
/**
|
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 |
+
foreach ($sorts as $sortKey => $sortValue) {
|
39 |
+
if($sortKey)
|
40 |
+
$sortString = "&caiSortBy=".$sortKey;
|
41 |
+
}
|
42 |
+
return $sortString;
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
/**
|
47 |
+
* function to get queryParam
|
48 |
+
* @param mixed $ruleset string
|
49 |
+
* @return String query
|
50 |
+
*/
|
51 |
+
function getQueryParam($params = array())
|
52 |
+
{
|
53 |
+
// ty is setting the type of search
|
54 |
+
if ($params['ruleset'] == 'browse') {
|
55 |
+
return 'ty=clistpage';
|
56 |
+
} else {
|
57 |
+
return 'ty=csearch&q=' . rawurlencode($params['query']);
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* function to prepare Url
|
63 |
+
* @param mixed $params array
|
64 |
+
* @param mixed $address string
|
65 |
+
* @return String url
|
66 |
+
*/
|
67 |
+
function prepare_url($params = array(), $address = "")
|
68 |
+
{
|
69 |
+
$url = $address
|
70 |
+
. "?c=" . $params['context']
|
71 |
+
. "&org=" . $params['org']
|
72 |
+
. "&from=" . (isset($params['start']) ? $params['start'] : 0)
|
73 |
+
. "&size=" . (isset($params['limit']) ? $params['limit'] : 20);
|
74 |
+
$url = $url . '&' . $this->getQueryParam($params);
|
75 |
+
|
76 |
+
// da
|
77 |
+
// to be sent only if some count is there, regarding the current state, about results of screen before when the request was made
|
78 |
+
if (isset($_GET['ct']) && $_GET['ct'] != "0")
|
79 |
+
$url .= "&da=" . Mage::helper('core')->jsonEncode(array("lpimpressions" => $_GET['ct']));
|
80 |
+
else
|
81 |
+
$url .= "&da={}";
|
82 |
+
|
83 |
+
if (Mage::registry("expId")) {
|
84 |
+
$url .= "&existingPage=" . Mage::registry("expId");
|
85 |
+
}
|
86 |
+
|
87 |
+
// Facets, passing the facets from cache
|
88 |
+
if(isset($params['facets'])){
|
89 |
+
$url .= "&facets=".$params['facets'];
|
90 |
+
}
|
91 |
+
|
92 |
+
if (isset($params['sort']))
|
93 |
+
$url .= $this->getSorting($params['sort']);
|
94 |
+
if (isset($params['others']))
|
95 |
+
$url .= $this->getOptions($params['others']);
|
96 |
+
|
97 |
+
return $url;
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
*
|
102 |
+
* function to fire search query
|
103 |
+
* Harkirat: Earlier in place of apiType, there was "$spellcheck = false"
|
104 |
+
*
|
105 |
+
*/
|
106 |
+
public function search($params, $address, $apiType = false)
|
107 |
+
{
|
108 |
+
$url = $this->prepare_url($params, $address);
|
109 |
+
|
110 |
+
$opts = array(
|
111 |
+
'http' => array(
|
112 |
+
'timeout' => 30
|
113 |
+
)
|
114 |
+
);
|
115 |
+
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
116 |
+
$opts['http']['header'] = "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
|
117 |
+
}
|
118 |
+
|
119 |
+
$context = stream_context_create($opts);
|
120 |
+
$response = file_get_contents($url, false, $context);
|
121 |
+
|
122 |
+
$choiceaiResponse = null;
|
123 |
+
if (isset($response)) {
|
124 |
+
$response = Mage::helper('core')->jsonDecode($response);
|
125 |
+
$uidData = $response['uid'];
|
126 |
+
if (isset($uidData)) {
|
127 |
+
$uid = explode( ',', $uidData );
|
128 |
+
Mage::register("caiuid",$uid[0],true);
|
129 |
+
}
|
130 |
+
|
131 |
+
$data = $response['data'];
|
132 |
+
|
133 |
+
if ($apiType == "choice") {
|
134 |
+
$data = $response['data']['automations'];
|
135 |
+
if (isset($data[0]))
|
136 |
+
$data = $data[0];
|
137 |
+
else
|
138 |
+
$data = array();
|
139 |
+
} else {
|
140 |
+
$data = $response['data'];
|
141 |
+
}
|
142 |
+
|
143 |
+
// tagsList, catPaths
|
144 |
+
if (isset($data['tagsList'])) {
|
145 |
+
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "tagsList") === false)
|
146 |
+
$_SERVER['REDIRECT_QUERY_STRING'] .= "&tagsList=" . Mage::helper('core')->jsonEncode($data['tagsList']);
|
147 |
+
|
148 |
+
// Mage::register("tagsList", Mage::helper('core')->jsonEncode($data['tagsList']), true);
|
149 |
+
}
|
150 |
+
if (isset($data['catPaths'])) {
|
151 |
+
if(empty($data['catPaths'])){
|
152 |
+
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "catPaths") === false)
|
153 |
+
$_SERVER['REDIRECT_QUERY_STRING'] .= "&catPaths={}";
|
154 |
+
|
155 |
+
// Mage::register("catPaths", "{}", true);
|
156 |
+
}
|
157 |
+
else{
|
158 |
+
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && strpos($_SERVER['REDIRECT_QUERY_STRING'], "catPaths") === false)
|
159 |
+
$_SERVER['REDIRECT_QUERY_STRING'] .= "&catPaths=" . Mage::helper('core')->jsonEncode($data['catPaths']);
|
160 |
+
|
161 |
+
// Mage::register("catPaths", Mage::helper('core')->jsonEncode($data['catPaths']), true);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
// for lpimpressions
|
166 |
+
if (isset($data['ids'])) {
|
167 |
+
Mage::register("prodCountNow", count($data['ids']), true);
|
168 |
+
}
|
169 |
+
if (isset($data['passback']) && !empty($data['passback'])) {
|
170 |
+
Mage::register("passback", $data['passback'], true);
|
171 |
+
}
|
172 |
+
|
173 |
+
$choiceaiResponse = new ChoiceAI_ResultSet($data);
|
174 |
+
|
175 |
+
}
|
176 |
+
|
177 |
+
return $choiceaiResponse;
|
178 |
+
}
|
179 |
+
}
|
180 |
+
|
181 |
+
?>
|
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>Choice AI plugin</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-
|
14 |
-
<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="
|
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.12</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>Choice AI plugin</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-13</date>
|
14 |
+
<time>14:52:34</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="c024fba9214158ffa069444e6dcaf936"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2fc12bb0874c8f39963f1593b3954d2e"/><file name="config.xml" hash="9fa56c376f528455c0c1d12f7b8286b6"/><file name="system.xml" hash="6f4674088b4c392cc06f5a70f383fd54"/></dir><dir name="sql"><dir name="personalisation_setup"><file name="install-1.0.12.php" hash="40e64ff22ba466f54cf59d0f6ca171c2"/></dir></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="b7b8fc08b9433b81cbdc48e715299076"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="a9ff8724be0873d2b309b39a156bbd3d"/></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="46df20f6fdedd61fa5a58d149e9d4ac8"/></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="d3ede493e0b67663569c18d8b3fe01ae"/></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="24af1501042170add901ae6746381c81"/></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="ec453c2d474c0dbd46c6e1c04b1645e0"/></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>
|