Version Notes
* Error/bug fix - on product categories update
* Support for old Magento Enterprise editions
Download this release
Release Info
Developer | Adar |
Extension | autocompleteplus_autosuggest |
Version | 2.0.8.7 |
Comparing to | |
See all releases |
Code changes from version 2.0.8.6 to 2.0.8.7
- app/code/local/Autocompleteplus/Autosuggest/Model/Catalog.php +1092 -1092
- app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Fulltext/Collection.php +209 -209
- app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/Autocompleteplus/PushController.php +4 -2
- app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/Autocompleteplus/RedirectController.php +8 -4
- app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsController.php +713 -713
- app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsbyidController.php +70 -70
- app/code/local/Autocompleteplus/Autosuggest/controllers/ResultController.php +6 -6
- app/code/local/Autocompleteplus/Autosuggest/etc/config.xml +1 -1
- app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.4-2.0.5.5.php +108 -78
- app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.6.1-2.0.6.4.php +16 -5
- app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.2-2.0.7.3.php +57 -50
- app/design/frontend/base/default/template/autocompleteplus/catalog/product/list.phtml +1 -1
- package.xml +7 -5
app/code/local/Autocompleteplus/Autosuggest/Model/Catalog.php
CHANGED
@@ -1,1093 +1,1093 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Autocompleteplus_Autosuggest_Model_Catalog extends Mage_Core_Model_Abstract{
|
4 |
-
private $imageField;
|
5 |
-
private $standardImageFields;
|
6 |
-
private $useAttributes;
|
7 |
-
private $attributes;
|
8 |
-
private $currency;
|
9 |
-
private $pageNum;
|
10 |
-
|
11 |
-
public function renderCatalogXml($startInd, $count, $storeId='', $orders='', $month_interval='', $checksum=''){
|
12 |
-
|
13 |
-
$this->_initCatalogCommonFields($storeId);
|
14 |
-
|
15 |
-
if(!$startInd){
|
16 |
-
$startInd=0;
|
17 |
-
}
|
18 |
-
|
19 |
-
//maxim products on one page is 10000
|
20 |
-
if(!$count||$count>10000){
|
21 |
-
$count=10000;
|
22 |
-
}
|
23 |
-
//retrieving page number
|
24 |
-
$this->pageNum=floor(($startInd/$count));
|
25 |
-
|
26 |
-
$mage=Mage::getVersion();
|
27 |
-
$ext=Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
28 |
-
|
29 |
-
$xml='<?xml version="1.0"?>';
|
30 |
-
$xml.='<catalog version="'.$ext.'" magento="'.$mage.'">';
|
31 |
-
|
32 |
-
$collection=Mage::getModel('catalog/product')->getCollection();
|
33 |
-
if(isset($storeId)&& $storeId!=''){
|
34 |
-
$collection->addStoreFilter($storeId);
|
35 |
-
$store_id = $storeId;
|
36 |
-
} else {
|
37 |
-
$store_id = Mage::app()->getStore()->getStoreId();
|
38 |
-
}
|
39 |
-
|
40 |
-
//setting page+products on the page
|
41 |
-
$collection->getSelect()->limit($count,$startInd);//->limitPage($pageNum, $count);//setPage($pageNum, $count)->load();
|
42 |
-
$collection->load();
|
43 |
-
|
44 |
-
// number of orderes per product section
|
45 |
-
if (isset($orders) && $orders == '1'){
|
46 |
-
$product_id_list = array();
|
47 |
-
foreach ($collection as $product){
|
48 |
-
$product_id_list[] = $product->getId();
|
49 |
-
}
|
50 |
-
|
51 |
-
if(isset($month_interval)&& $month_interval!=''){
|
52 |
-
$month_interval = $month_interval;
|
53 |
-
} else {
|
54 |
-
$month_interval = 12;
|
55 |
-
}
|
56 |
-
$orders_per_product = $this->_getOrdersPerProduct($store_id, $product_id_list, $month_interval);
|
57 |
-
} else {// end - number of orderes per product section
|
58 |
-
$orders_per_product = null;
|
59 |
-
}
|
60 |
-
|
61 |
-
$this->_root_category_id = Mage::app()->getStore($store_id)->getRootCategoryId();
|
62 |
-
|
63 |
-
if(isset($checksum) && $checksum != ''){
|
64 |
-
$is_checksum = $checksum;
|
65 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
66 |
-
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
67 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
68 |
-
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
69 |
-
} else {
|
70 |
-
$is_checksum = 0;
|
71 |
-
$helper = null;
|
72 |
-
$_tableprefix = null;
|
73 |
-
$write = null;
|
74 |
-
$read = null;
|
75 |
-
}
|
76 |
-
|
77 |
-
foreach ($collection as $product) {
|
78 |
-
$productCollData=$product->getData();
|
79 |
-
try{
|
80 |
-
$productModel=Mage::getModel('catalog/product')
|
81 |
-
->setStore($storeId)->setStoreId($storeId)
|
82 |
-
->load($productCollData['entity_id']);
|
83 |
-
} catch (Exception $e){
|
84 |
-
continue;
|
85 |
-
}
|
86 |
-
$prodId =$productModel->getId();
|
87 |
-
$sku =$productModel->getSku();
|
88 |
-
$row=$this->renderProductXmlRow($productModel,$orders_per_product);
|
89 |
-
$xml.=$row;
|
90 |
-
if ($is_checksum && $helper){
|
91 |
-
if ($helper->isChecksumTableExists()){
|
92 |
-
$checksum = $helper->calculateChecksum($productModel);
|
93 |
-
$helper->updateSavedProductChecksum($_tableprefix, $read, $write, $prodId, $sku, $store_id, $checksum);
|
94 |
-
}
|
95 |
-
}
|
96 |
-
}
|
97 |
-
$xml.='</catalog>';
|
98 |
-
return $xml;
|
99 |
-
}
|
100 |
-
|
101 |
-
public function renderUpdatesCatalogXml($count,$from,$to,$storeId){
|
102 |
-
$storeQ='';
|
103 |
-
|
104 |
-
if($storeId!=''){
|
105 |
-
$storeQ = 'AND store_id='.$storeId;
|
106 |
-
}else{
|
107 |
-
$storeId = Mage::app()->getStore()->getStoreId();
|
108 |
-
}
|
109 |
-
$this->_initCatalogCommonFields($storeId);
|
110 |
-
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
111 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
112 |
-
|
113 |
-
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
114 |
-
$sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_batches` WHERE update_date BETWEEN ? AND ? '.$storeQ. ' order by update_date' . ' LIMIT '.$count;
|
115 |
-
$updates=$read->fetchAll($sql,array($from,$to));
|
116 |
-
|
117 |
-
$mage=Mage::getVersion();
|
118 |
-
$ext=Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
119 |
-
$this->_root_category_id = Mage::app()->getStore($storeId)->getRootCategoryId();
|
120 |
-
|
121 |
-
$xml='<?xml version="1.0"?>';
|
122 |
-
$xml.='<catalog fromdatetime="'.$from.'" version="'.$ext.'" magento="'.$mage.'">';
|
123 |
-
foreach ($updates as $batch) {
|
124 |
-
if($batch['action']=='update'){
|
125 |
-
$productId = $batch['product_id'];
|
126 |
-
$sku = $batch['sku'];
|
127 |
-
$batchStoreId = $batch['store_id'];
|
128 |
-
|
129 |
-
if($storeId!=$batchStoreId){
|
130 |
-
$this->currency = Mage::app()->getStore($batchStoreId)->getCurrentCurrencyCode();
|
131 |
-
}
|
132 |
-
|
133 |
-
$productModel = null;
|
134 |
-
|
135 |
-
if($productId!=null){
|
136 |
-
// load product by id
|
137 |
-
try{
|
138 |
-
$productModel=Mage::getModel('catalog/product')
|
139 |
-
->setStoreId($batchStoreId)
|
140 |
-
->load($productId);
|
141 |
-
}catch (Exception $e){
|
142 |
-
$batch['action'] = 'remove';
|
143 |
-
$xml.=$this->_makeRemoveRow($batch);
|
144 |
-
continue;
|
145 |
-
}
|
146 |
-
}else{
|
147 |
-
// product not found - changing action to remove
|
148 |
-
$batch['action'] = 'remove';
|
149 |
-
$xml.=$this->_makeRemoveRow($batch);
|
150 |
-
continue;
|
151 |
-
|
152 |
-
/*
|
153 |
-
* FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
|
154 |
-
*/
|
155 |
-
// $productModel=Mage::getModel('catalog/product')
|
156 |
-
// ->loadByAttribute('sku', $sku)
|
157 |
-
// ->setStoreId($batchStoreId);
|
158 |
-
}
|
159 |
-
|
160 |
-
if($productModel==null){
|
161 |
-
continue;
|
162 |
-
}
|
163 |
-
|
164 |
-
$updatedate = $batch['update_date'];
|
165 |
-
$action = $batch['action'];
|
166 |
-
$xmlAttrs='action="'.$action.'" updatedate="'.$updatedate.'" storeid="'.$storeId.'"' ;
|
167 |
-
// $xmlAttrs='action="'.$action.'" updatedate="'.$updatedate.'"';
|
168 |
-
$xml.=$this->renderProductXmlRow($productModel,null,$xmlAttrs);
|
169 |
-
}else{
|
170 |
-
$xml.=$this->_makeRemoveRow($batch);
|
171 |
-
}
|
172 |
-
|
173 |
-
}
|
174 |
-
$xml.='</catalog>';
|
175 |
-
return $xml;
|
176 |
-
}
|
177 |
-
|
178 |
-
public function renderCatalogFromIds($count,$fromId,$storeId){
|
179 |
-
|
180 |
-
$this->_initCatalogCommonFields($storeId);
|
181 |
-
|
182 |
-
$mage = Mage::getVersion();
|
183 |
-
$ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
184 |
-
$xml = '<catalog version="'.$ext.'" magento="'.$mage.'">';
|
185 |
-
|
186 |
-
$_productCollection = Mage::getModel('catalog/product')->getCollection()
|
187 |
-
->addStoreFilter($storeId)
|
188 |
-
->addAttributeToSelect('*')
|
189 |
-
->addAttributeToFilter('entity_id', array('from' => $fromId));
|
190 |
-
|
191 |
-
$_productCollection->getSelect()->limit($count);
|
192 |
-
|
193 |
-
//add media gallery to collection
|
194 |
-
|
195 |
-
$action= 'getfromid';
|
196 |
-
|
197 |
-
foreach($_productCollection as $product){
|
198 |
-
if($product){
|
199 |
-
$id = $product->getId();
|
200 |
-
$lastUpdateddt = $product->getUpdatedAt();
|
201 |
-
|
202 |
-
$xmlAttrTemplate = 'last_updated="%s" get_by_id_status="1" action="%s" storeid="%s"';
|
203 |
-
$xmlAttrs = sprintf($xmlAttrTemplate,
|
204 |
-
$lastUpdateddt,
|
205 |
-
$action,
|
206 |
-
$storeId
|
207 |
-
);
|
208 |
-
|
209 |
-
$xml .= $this->renderProductXmlRow($product, null, $xmlAttrs);
|
210 |
-
|
211 |
-
} else {
|
212 |
-
$xml .= '<product action="' . $action . '" product="' . $id . '" get_by_id_status="0"></product>';
|
213 |
-
}
|
214 |
-
|
215 |
-
}
|
216 |
-
|
217 |
-
$xml.='</catalog>';
|
218 |
-
|
219 |
-
return $xml;
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Creates an XML representation of catalog by ids
|
224 |
-
* @param array $ids
|
225 |
-
* @param integer $storeId
|
226 |
-
* @return string
|
227 |
-
*/
|
228 |
-
public function renderCatalogByIds($ids, $storeId = 0)
|
229 |
-
{
|
230 |
-
|
231 |
-
$this->_initCatalogCommonFields($storeId);
|
232 |
-
|
233 |
-
$mage = Mage::getVersion();
|
234 |
-
$ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
235 |
-
$xml = '<catalog version="'.$ext.'" magento="'.$mage.'">';
|
236 |
-
|
237 |
-
$_productCollection = Mage::getModel('catalog/product')->getCollection()
|
238 |
-
//->addStoreFilter($storeId)
|
239 |
-
//->addAttributeToSelect('*')
|
240 |
-
->addAttributeToFilter('entity_id', array(
|
241 |
-
'in' => $ids
|
242 |
-
));
|
243 |
-
|
244 |
-
$this->_root_category_id = Mage::app()->getStore($storeId)->getRootCategoryId();
|
245 |
-
|
246 |
-
$action= 'getbyid';
|
247 |
-
|
248 |
-
foreach($ids as $id){
|
249 |
-
|
250 |
-
$productModel=Mage::getModel('catalog/product')
|
251 |
-
->setStoreId($storeId)
|
252 |
-
->load($id);
|
253 |
-
|
254 |
-
if($productModel->getId()){
|
255 |
-
|
256 |
-
$lastUpdateddt=$productModel->getUpdatedAt();
|
257 |
-
|
258 |
-
$xmlAttrs='last_updated="'.$lastUpdateddt.'" get_by_id_status="1" action="'.$action.'" storeid="'.$storeId.'"' ;
|
259 |
-
|
260 |
-
$xml.=$this->renderProductXmlRow($productModel,null,$xmlAttrs);
|
261 |
-
|
262 |
-
}else{
|
263 |
-
$xml.='<product action="'.$action.'" product="'.$id.'" get_by_id_status="0"></product>';
|
264 |
-
}
|
265 |
-
|
266 |
-
}
|
267 |
-
|
268 |
-
$xml.='</catalog>';
|
269 |
-
|
270 |
-
return $xml;
|
271 |
-
}
|
272 |
-
|
273 |
-
public function getCategoryMap()
|
274 |
-
{
|
275 |
-
if(!$this->_categories){
|
276 |
-
Mage::log('creating categories once',false,'pjackson.log');
|
277 |
-
$categoryMap = array();
|
278 |
-
$categories = Mage::getModel('catalog/category')->getCollection()->load();
|
279 |
-
|
280 |
-
foreach($categories as $category){
|
281 |
-
$categoryMap[] = new Varien_Object(array(
|
282 |
-
'id'=>$category->getId(),
|
283 |
-
'path'=>$category->getPath(),
|
284 |
-
'parent_id'=>$category->getParentId()
|
285 |
-
));
|
286 |
-
}
|
287 |
-
|
288 |
-
$this->_categories = $categoryMap;
|
289 |
-
}
|
290 |
-
|
291 |
-
return $this->_categories;
|
292 |
-
}
|
293 |
-
|
294 |
-
public function getCategoryPathsByProduct(Mage_Catalog_Model_Product $product)
|
295 |
-
{
|
296 |
-
$productCategories = $product->getCategoryIds();
|
297 |
-
$root_category_id = $this->_root_category_id;
|
298 |
-
$paths = array_map(function($category) use ($productCategories, $root_category_id) {
|
299 |
-
if(in_array($category->getId(), $productCategories)){
|
300 |
-
$path = explode('/', $category->getPath());
|
301 |
-
//we don't want the root category for the entire site
|
302 |
-
array_shift($path);
|
303 |
-
if ($root_category_id && is_array($path) && $path[0] != $root_category_id){
|
304 |
-
return array();
|
305 |
-
}
|
306 |
-
//we want more specific categories first
|
307 |
-
return implode(':', array_reverse($path));
|
308 |
-
}
|
309 |
-
}, $this->getCategoryMap());
|
310 |
-
|
311 |
-
return array_filter($paths);
|
312 |
-
}
|
313 |
-
|
314 |
-
public function renderProductXmlRow($productModel,$orders_per_product,$xmlAttrs='action="insert"')
|
315 |
-
{
|
316 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
317 |
-
$categories = $this->getCategoryPathsByProduct($productModel);
|
318 |
-
$price = $this->_getPrice($productModel);
|
319 |
-
$sku = $productModel->getSku();
|
320 |
-
$stock_status = $productModel->isInStock();
|
321 |
-
$stockItem = $productModel->getStockItem();
|
322 |
-
|
323 |
-
if($stockItem){
|
324 |
-
if($stockItem->getIsInStock() && $stock_status){
|
325 |
-
$sell=1;
|
326 |
-
}else{
|
327 |
-
$sell=0;
|
328 |
-
}
|
329 |
-
}else{
|
330 |
-
if($stock_status){
|
331 |
-
$sell=1;
|
332 |
-
}else{
|
333 |
-
$sell=0;
|
334 |
-
}
|
335 |
-
}
|
336 |
-
|
337 |
-
$productUrl = ''; // getting the product's url according to the store_id
|
338 |
-
|
339 |
-
$is_getUrlPath_supported = true;
|
340 |
-
if (method_exists('Mage' , 'getVersionInfo')){ // getUrlPath is not supported on EE 1.13... & 1.14...
|
341 |
-
$edition_info = Mage::getVersionInfo();
|
342 |
-
if ($edition_info['major'] == 1 && $edition_info['minor'] >= 13){
|
343 |
-
$is_getUrlPath_supported = false;
|
344 |
-
}
|
345 |
-
}
|
346 |
-
|
347 |
-
if (method_exists($productModel, 'getUrlPath') && $is_getUrlPath_supported){
|
348 |
-
$productUrl = $productModel->getUrlPath();
|
349 |
-
if ($productUrl != ''){
|
350 |
-
$productUrl = Mage::getUrl($productUrl);
|
351 |
-
}
|
352 |
-
}
|
353 |
-
if ($productUrl == '' && method_exists($productModel, 'getProductUrl')){
|
354 |
-
$productUrl = $productModel->getProductUrl();
|
355 |
-
// $pattern = '/\?___.*/';
|
356 |
-
// $productUrl = preg_replace($pattern, '', $productUrl);
|
357 |
-
}
|
358 |
-
if ($productUrl == '') {
|
359 |
-
$productUrl = Mage::helper('catalog/product')->getProductUrl($productModel->getId());
|
360 |
-
}
|
361 |
-
|
362 |
-
$prodId = $productModel->getId();
|
363 |
-
$prodDesc = $productModel->getDescription();
|
364 |
-
$prodShortDesc = $productModel->getShortDescription();
|
365 |
-
$prodName = $productModel->getName();
|
366 |
-
$visibility = $productModel->getVisibility();
|
367 |
-
|
368 |
-
if(defined('Mage_Catalog_Model_Product_Status::STATUS_ENABLED')){
|
369 |
-
if ($productModel->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED){
|
370 |
-
$product_status = 1;
|
371 |
-
} else {
|
372 |
-
$product_status = 0;
|
373 |
-
}
|
374 |
-
} else {
|
375 |
-
if ($productModel->getStatus() == 1){
|
376 |
-
$product_status = 1;
|
377 |
-
} else {
|
378 |
-
$product_status = 0;
|
379 |
-
}
|
380 |
-
}
|
381 |
-
|
382 |
-
try{
|
383 |
-
if(in_array($this->imageField,$this->standardImageFields)){
|
384 |
-
$prodImage =Mage::helper('catalog/image')->init($productModel, $this->imageField);
|
385 |
-
}else{
|
386 |
-
$function='get'.$this->imageField;
|
387 |
-
$prodImage =$productModel->$function();
|
388 |
-
}
|
389 |
-
|
390 |
-
try{
|
391 |
-
$product_media_config = Mage::getModel('catalog/product_media_config');
|
392 |
-
$product_base_image = $product_media_config->getMediaUrl($productModel->getImage());
|
393 |
-
} catch (Exception $e){
|
394 |
-
$product_base_image = '';
|
395 |
-
}
|
396 |
-
|
397 |
-
}catch(Exception $e){
|
398 |
-
$prodImage='';
|
399 |
-
$product_base_image = '';
|
400 |
-
}
|
401 |
-
|
402 |
-
if($productModel->getTypeID()=='configurable'){
|
403 |
-
$configurableAttributes=$this->_getConfigurableAttributes($productModel);
|
404 |
-
|
405 |
-
$configurableChildren = $this->_getConfigurableChildren($productModel);
|
406 |
-
|
407 |
-
// getting all children's ids
|
408 |
-
$configurable_children_ids = array();
|
409 |
-
foreach($configurableChildren as $child_product){
|
410 |
-
$configurable_children_ids[] = $child_product->getId();
|
411 |
-
}
|
412 |
-
|
413 |
-
// getting sellable option for the configurable product
|
414 |
-
if ($sell){ // Configurable is in stock
|
415 |
-
$is_in_stock_child_exist = false;
|
416 |
-
foreach($configurableChildren as $child_product){
|
417 |
-
if ($child_product->getStockItem()->getIsInStock()){
|
418 |
-
if (method_exists($child_product, 'isSaleable') && !$child_product->isSaleable()){
|
419 |
-
// the simple product is probably disabled (because its in stock)
|
420 |
-
continue;
|
421 |
-
}
|
422 |
-
$is_in_stock_child_exist = true;
|
423 |
-
break;
|
424 |
-
}
|
425 |
-
}
|
426 |
-
if (!$is_in_stock_child_exist){
|
427 |
-
# Configurable is in stock, but has no in stock children
|
428 |
-
$sell = 0;
|
429 |
-
}
|
430 |
-
}
|
431 |
-
|
432 |
-
try{
|
433 |
-
$priceRange=$this->_getPriceRange($productModel);
|
434 |
-
}catch(Exception $e){
|
435 |
-
$priceRange='price_min="" price_max=""';
|
436 |
-
}
|
437 |
-
} else if ($productModel->getTypeID() == 'simple'){
|
438 |
-
$simple_product_parents = $this->_getSimpleProductParent($productModel);
|
439 |
-
$priceRange='price_min="" price_max=""';
|
440 |
-
}else{
|
441 |
-
$priceRange='price_min="" price_max=""';
|
442 |
-
}
|
443 |
-
|
444 |
-
$num_of_orders = ($orders_per_product != null && array_key_exists($prodId, $orders_per_product)) ? $orders_per_product[$prodId] : 0;
|
445 |
-
$row='<product '.$priceRange.' id="'.$prodId.'" type="'.$productModel->getTypeID().'" currency="'.$this->currency.'" visibility="'.$visibility.'" price="'.$price.'" url="'.$productUrl.'" thumbs="'.$prodImage.'" base_image="'.$product_base_image.'" selleable="'.$sell.'" '.$xmlAttrs.' >';
|
446 |
-
$row.='<description><![CDATA['.$prodDesc.']]></description>';
|
447 |
-
$row.='<short><![CDATA['.$prodShortDesc.']]></short>';
|
448 |
-
$row.='<name><![CDATA['.$prodName.']]></name>';
|
449 |
-
$row.='<sku><![CDATA['.$sku.']]></sku>';
|
450 |
-
|
451 |
-
$summaryData = Mage::getModel('review/review_summary')
|
452 |
-
->setStoreId($productModel->getStoreId())
|
453 |
-
->load($prodId);
|
454 |
-
if (($summaryData['rating_summary'] || $summaryData['rating_summary'] == 0) && $summaryData['rating_summary'] != ''){
|
455 |
-
$row.='<review><![CDATA['.$summaryData['rating_summary'].']]></review>';
|
456 |
-
$row.='<reviews_count><![CDATA['.$summaryData['reviews_count'].']]></reviews_count>';
|
457 |
-
}
|
458 |
-
|
459 |
-
$new_from_date = $productModel->getNewsFromDate();
|
460 |
-
$new_to_date = $productModel->getNewsToDate();
|
461 |
-
if ($new_from_date){
|
462 |
-
$row.='<newfrom><![CDATA['.Mage::getModel('core/date')->timestamp($new_from_date).']]></newfrom>';
|
463 |
-
if ($new_to_date){
|
464 |
-
$row.='<newto><![CDATA['.Mage::getModel('core/date')->timestamp($new_to_date).']]></newto>';
|
465 |
-
}
|
466 |
-
}
|
467 |
-
|
468 |
-
$row.= '<purchase_popularity><![CDATA['.$num_of_orders.']]></purchase_popularity>';
|
469 |
-
$row.='<product_status><![CDATA['.$product_status.']]></product_status>';
|
470 |
-
|
471 |
-
try{
|
472 |
-
$row.='<creation_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getCreatedAt()).']]></creation_date>';
|
473 |
-
$row.='<updated_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getUpdatedAt()).']]></updated_date>';
|
474 |
-
} catch(Exception $e){
|
475 |
-
}
|
476 |
-
|
477 |
-
if($this->useAttributes!='0'){
|
478 |
-
foreach($this->attributes as $attr){
|
479 |
-
$action=$attr->getAttributeCode();
|
480 |
-
$is_filterable=$attr->getis_filterable();
|
481 |
-
$attribute_label = $attr->getStoreLabel($productModel->getStoreId());
|
482 |
-
|
483 |
-
if($attr->getfrontend_input()=='select'){
|
484 |
-
if($productModel->getData($action)){
|
485 |
-
if (method_exists($productModel, 'getAttributeText')){
|
486 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
487 |
-
<attribute_values><![CDATA['.$productModel->getAttributeText($action).']]></attribute_values>
|
488 |
-
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
489 |
-
</attribute>';
|
490 |
-
} else {
|
491 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
492 |
-
<attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
|
493 |
-
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
494 |
-
</attribute>';
|
495 |
-
}
|
496 |
-
}
|
497 |
-
}elseif($attr->getfrontend_input()=='textarea'){
|
498 |
-
if($productModel->getData($action)){
|
499 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
500 |
-
<attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
|
501 |
-
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
502 |
-
</attribute>';
|
503 |
-
}
|
504 |
-
}elseif($attr->getfrontend_input()=='price'){
|
505 |
-
if($productModel->getData($action)){
|
506 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
507 |
-
<attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
|
508 |
-
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
509 |
-
</attribute>';
|
510 |
-
}
|
511 |
-
}elseif($attr->getfrontend_input()=='text'){
|
512 |
-
if($productModel->getData($action)){
|
513 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
514 |
-
<attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
|
515 |
-
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
516 |
-
</attribute>';
|
517 |
-
}
|
518 |
-
}elseif($attr->getfrontend_input()=='multiselect'){
|
519 |
-
if($productModel->getData($action)){
|
520 |
-
$values=$productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
|
521 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
522 |
-
<attribute_values><![CDATA['.$values.']]></attribute_values>
|
523 |
-
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
524 |
-
</attribute>';
|
525 |
-
}
|
526 |
-
}
|
527 |
-
}
|
528 |
-
|
529 |
-
if($productModel->getTypeID()=='configurable' && count($configurableAttributes)>0){
|
530 |
-
$configural_attributes = array();
|
531 |
-
foreach($configurableAttributes as $attrName=>$confAttrN){
|
532 |
-
if(is_array($confAttrN) && array_key_exists('values',$confAttrN)){
|
533 |
-
$configural_attributes[] = $attrName;
|
534 |
-
$values=implode(' , ',$confAttrN['values']);
|
535 |
-
$row.='<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
|
536 |
-
}
|
537 |
-
}
|
538 |
-
$simple_products_price = $this->_getSimpleProductsPriceOfConfigurable($productModel, $configurableChildren);
|
539 |
-
|
540 |
-
if (!empty($configural_attributes)){
|
541 |
-
$product_variation = '<variants>';
|
542 |
-
try{
|
543 |
-
foreach($configurableChildren as $child_product){
|
544 |
-
if (!in_array($productModel->getStoreId(), $child_product->getStoreIds())){
|
545 |
-
continue;
|
546 |
-
}
|
547 |
-
|
548 |
-
$is_variant_in_stock = ($child_product->getStockItem()->getIsInStock()) ? 1 : 0;
|
549 |
-
|
550 |
-
if (method_exists($child_product, 'isSaleable')){
|
551 |
-
$is_variant_sellable = ($child_product->isSaleable()) ? 1 : 0;
|
552 |
-
} else {
|
553 |
-
$is_variant_sellable = '';
|
554 |
-
// $is_variant_sellable = (Mage::getModel('catalog/product')
|
555 |
-
// ->setStore($productModel->getStoreId())
|
556 |
-
// ->setStoreId($productModel->getStoreId())
|
557 |
-
// ->load($child_product->getId())
|
558 |
-
// ->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
|
559 |
-
}
|
560 |
-
|
561 |
-
if (method_exists($child_product, 'getVisibility')){
|
562 |
-
$is_variant_visible = ($child_product->getVisibility()) ? 1 : 0;
|
563 |
-
} else {
|
564 |
-
$is_variant_visible = '';
|
565 |
-
// $is_variant_visible = (Mage::getModel('catalog/product')
|
566 |
-
// ->setStore($productModel->getStoreId())
|
567 |
-
// ->setStoreId($productModel->getStoreId())
|
568 |
-
// ->load($child_product->getId())
|
569 |
-
// ->getVisibility());
|
570 |
-
}
|
571 |
-
|
572 |
-
$variant_price = (array_key_exists($child_product->getId(), $simple_products_price)) ?
|
573 |
-
$simple_products_price[$child_product->getId()] : '';
|
574 |
-
|
575 |
-
$product_variation .= '<variant id="'.$child_product->getId().'" type="'.$child_product->getTypeID().
|
576 |
-
'" visibility="'.$is_variant_visible.'" is_in_stock="'.$is_variant_in_stock.'" is_seallable="'.$is_variant_sellable.'" price="'.$variant_price.'">';
|
577 |
-
$product_variation .= '<name><![CDATA['.$child_product->getName().']]></name>';
|
578 |
-
|
579 |
-
$attributes = $child_product->getAttributes();
|
580 |
-
foreach ($attributes as $attribute) {
|
581 |
-
if (!$attribute['is_configurable'] || !in_array($attribute['store_label'], $configural_attributes)){ // || !$attribute->getIsVisibleOnFront()
|
582 |
-
continue;
|
583 |
-
}
|
584 |
-
|
585 |
-
$product_variation .= '<variant_attribute is_configurable="1" is_filterable="'.$attribute->getis_filterable().
|
586 |
-
'" name="'.$attribute['store_label'].'" name_code="'.$attribute->getId().
|
587 |
-
'" value_code="'.$child_product->getData($attribute->getAttributeCode()).
|
588 |
-
'"><![CDATA['.$attribute->getFrontend()->getValue($child_product).
|
589 |
-
']]></variant_attribute>';
|
590 |
-
}
|
591 |
-
$product_variation .= '</variant>';
|
592 |
-
}
|
593 |
-
} catch(Exception $e ){
|
594 |
-
}
|
595 |
-
$product_variation .= '</variants>';
|
596 |
-
$row.=$product_variation;
|
597 |
-
}
|
598 |
-
|
599 |
-
$row.='<simpleproducts><![CDATA['.implode(',',$configurable_children_ids).']]></simpleproducts>';
|
600 |
-
}
|
601 |
-
|
602 |
-
if($productModel->getTypeID() == 'simple'){
|
603 |
-
$row.='<product_parents><![CDATA['.implode(',',$simple_product_parents).']]></product_parents>';
|
604 |
-
}
|
605 |
-
}
|
606 |
-
|
607 |
-
$row.='<categories><![CDATA[' . implode(';', $categories) . ']]></categories>';
|
608 |
-
$row.='</product>';
|
609 |
-
return $helper->escapeXml($row);
|
610 |
-
}
|
611 |
-
|
612 |
-
private function _makeUpdateRow($batch,$attributes){
|
613 |
-
|
614 |
-
$productId = $batch['product_id'];
|
615 |
-
|
616 |
-
$sku = $batch['sku'];
|
617 |
-
|
618 |
-
$storeId = $batch['store_id'];
|
619 |
-
|
620 |
-
$updatedate = $batch['update_date'];
|
621 |
-
|
622 |
-
$action = $batch['action'];
|
623 |
-
|
624 |
-
$currency=Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
|
625 |
-
|
626 |
-
if($productId!=null){
|
627 |
-
|
628 |
-
$productModel=Mage::getModel('catalog/product')
|
629 |
-
|
630 |
-
->setStoreId($storeId)
|
631 |
-
|
632 |
-
->load($productId);
|
633 |
-
|
634 |
-
if($productModel==null){
|
635 |
-
|
636 |
-
return '';
|
637 |
-
|
638 |
-
}
|
639 |
-
|
640 |
-
}else{
|
641 |
-
|
642 |
-
/*
|
643 |
-
|
644 |
-
* FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
|
645 |
-
|
646 |
-
*/
|
647 |
-
|
648 |
-
$productModel=Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
|
649 |
-
|
650 |
-
if($productModel==null){
|
651 |
-
|
652 |
-
return '';
|
653 |
-
|
654 |
-
}
|
655 |
-
|
656 |
-
$productModel = $productModel->setStoreId($storeId);
|
657 |
-
|
658 |
-
$productId=$productModel->getId();
|
659 |
-
}
|
660 |
-
|
661 |
-
if($productModel==null){
|
662 |
-
|
663 |
-
return '';
|
664 |
-
|
665 |
-
}
|
666 |
-
|
667 |
-
$price =$this->getPrice($productModel);
|
668 |
-
|
669 |
-
$sku =$productModel->getSku();
|
670 |
-
|
671 |
-
$status =$productModel->isInStock();
|
672 |
-
|
673 |
-
$stockItem = $productModel->getStockItem();
|
674 |
-
|
675 |
-
$categoriesNames='';
|
676 |
-
|
677 |
-
$categories = $productModel->getCategoryCollection()
|
678 |
-
->addAttributeToSelect('name');
|
679 |
-
|
680 |
-
foreach($categories as $category) {
|
681 |
-
$categoriesNames.=$category->getName().':'.$category->getId().';';
|
682 |
-
}
|
683 |
-
|
684 |
-
if($stockItem->getIsInStock()&&$status)
|
685 |
-
{
|
686 |
-
$sell=1;
|
687 |
-
}else{
|
688 |
-
$sell=0;
|
689 |
-
}
|
690 |
-
|
691 |
-
$productUrl =Mage::helper('catalog/product')->getProductUrl($productId);
|
692 |
-
|
693 |
-
$prodId =$productModel->getId();
|
694 |
-
|
695 |
-
$prodDesc =$productModel->getDescription();
|
696 |
-
|
697 |
-
$prodShortDesc =$productModel->getShortDescription();
|
698 |
-
|
699 |
-
$prodName =$productModel->getName();
|
700 |
-
|
701 |
-
$visibility =$productModel->getVisibility();
|
702 |
-
|
703 |
-
try{
|
704 |
-
|
705 |
-
if(in_array($this->imageField,$this->standardImageFields)){
|
706 |
-
|
707 |
-
$prodImage =Mage::helper('catalog/image')->init($productModel, $this->imageField);
|
708 |
-
|
709 |
-
}else{
|
710 |
-
|
711 |
-
$function='get'.$this->imageField;
|
712 |
-
|
713 |
-
$prodImage =$productModel->$function();
|
714 |
-
|
715 |
-
}
|
716 |
-
|
717 |
-
}catch(Exception $e){
|
718 |
-
|
719 |
-
$prodImage='';
|
720 |
-
|
721 |
-
}
|
722 |
-
|
723 |
-
if($productModel->getTypeID()=='configurable'){
|
724 |
-
|
725 |
-
$configurableAttributes=$this->_getConfigurableAttributes($productModel);
|
726 |
-
|
727 |
-
try{
|
728 |
-
|
729 |
-
$priceRange=$this->_getPriceRange($productModel);
|
730 |
-
|
731 |
-
}catch(Exception $e){
|
732 |
-
|
733 |
-
$priceRange='price_min="" price_max=""';
|
734 |
-
|
735 |
-
}
|
736 |
-
|
737 |
-
}else{
|
738 |
-
|
739 |
-
$priceRange='price_min="" price_max=""';
|
740 |
-
|
741 |
-
}
|
742 |
-
|
743 |
-
$row='<product '.$priceRange.' id="'.$prodId.'" type="'.$productModel->getTypeID().'" updatedate="'.$updatedate.'" currency="'.$currency.'" storeid="'.$storeId.'" visibility="'.$visibility.'" price="'.$price.'" url="'.$productUrl.'" thumbs="'.$prodImage.'" selleable="'.$sell.'" action="'.$action.'" >';
|
744 |
-
|
745 |
-
$row.='<description><![CDATA['.$prodDesc.']]></description>';
|
746 |
-
|
747 |
-
$row.='<short><![CDATA['.$prodShortDesc.']]></short>';
|
748 |
-
|
749 |
-
$row.='<name><![CDATA['.$prodName.']]></name>';
|
750 |
-
|
751 |
-
$row.='<sku><![CDATA['.$sku.']]></sku>';
|
752 |
-
|
753 |
-
if($attributes!=null){
|
754 |
-
|
755 |
-
foreach($attributes as $attr){
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
$action=$attr->getAttributeCode();
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
$is_filterable=$attr->getis_filterable();
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
if($attr->getfrontend_input()=='select'){
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
if($productModel->getData($action)){
|
772 |
-
|
773 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getAttributeText($action).']]></attribute>';
|
774 |
-
|
775 |
-
}
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
}elseif($attr->getfrontend_input()=='textarea'){
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
if($productModel->getData($action)){
|
784 |
-
|
785 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
|
786 |
-
|
787 |
-
}
|
788 |
-
|
789 |
-
}elseif($attr->getfrontend_input()=='price'){
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
if($productModel->getData($action)){
|
794 |
-
|
795 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
|
796 |
-
|
797 |
-
}
|
798 |
-
|
799 |
-
}elseif($attr->getfrontend_input()=='text'){
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
if($productModel->getData($action)){
|
804 |
-
|
805 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
|
806 |
-
|
807 |
-
}
|
808 |
-
|
809 |
-
}elseif($attr->getfrontend_input()=='multiselect'){
|
810 |
-
|
811 |
-
if($productModel->getData($action)){
|
812 |
-
|
813 |
-
$values=$productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'"><![CDATA['.$values.']]></attribute>';
|
818 |
-
|
819 |
-
}
|
820 |
-
|
821 |
-
}
|
822 |
-
|
823 |
-
}
|
824 |
-
|
825 |
-
if($productModel->getTypeID()=='configurable' && count($configurableAttributes)>0){
|
826 |
-
|
827 |
-
foreach($configurableAttributes as $attrName=>$confAttrN){
|
828 |
-
|
829 |
-
if(is_array($confAttrN) && array_key_exists('values',$confAttrN)){
|
830 |
-
|
831 |
-
$values=implode(' , ',$confAttrN['values']);
|
832 |
-
|
833 |
-
$row.='<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
|
834 |
-
|
835 |
-
}
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
}
|
840 |
-
|
841 |
-
}
|
842 |
-
|
843 |
-
}
|
844 |
-
|
845 |
-
$row.='<categories><![CDATA['.$categoriesNames.']]></categories>';
|
846 |
-
|
847 |
-
$row.='</product>';
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
return $row;
|
852 |
-
|
853 |
-
}
|
854 |
-
|
855 |
-
private function _makeRemoveRow($batch){
|
856 |
-
$updatedate = $batch['update_date'];
|
857 |
-
$action = $batch['action'];
|
858 |
-
$sku = $batch['sku'];
|
859 |
-
$productId = $batch['product_id'];
|
860 |
-
$storeId = $batch['store_id'];
|
861 |
-
|
862 |
-
$row='<product updatedate="'.$updatedate.'" action="'.$action.'" id="'.$productId.'" storeid="'.$storeId.'">';
|
863 |
-
$row.='<sku><![CDATA['.$sku.']]></sku>';
|
864 |
-
$row.='<id><![CDATA['.$productId.']]></id>';
|
865 |
-
$row.='</product>';
|
866 |
-
return $row;
|
867 |
-
}
|
868 |
-
|
869 |
-
private function _getConfigurableChildren($product){
|
870 |
-
|
871 |
-
$childProducts = Mage::getModel('catalog/product_type_configurable')
|
872 |
-
->getUsedProducts(null,$product);
|
873 |
-
return $childProducts;
|
874 |
-
}
|
875 |
-
|
876 |
-
private function _getSimpleProductParent($product){
|
877 |
-
try{
|
878 |
-
$parent_products_ids_list = Mage::getModel('catalog/product_type_configurable')
|
879 |
-
->getParentIdsByChild($product->getId());
|
880 |
-
|
881 |
-
return $parent_products_ids_list;
|
882 |
-
} catch(Exception $e){
|
883 |
-
return array();
|
884 |
-
}
|
885 |
-
}
|
886 |
-
|
887 |
-
private function _getConfigurableAttributes($product){
|
888 |
-
|
889 |
-
try{
|
890 |
-
// Collect options applicable to the configurable product
|
891 |
-
$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
|
892 |
-
|
893 |
-
$attributeOptions = array();
|
894 |
-
|
895 |
-
foreach ($productAttributeOptions as $productAttribute) {
|
896 |
-
$attributeFull = Mage::getModel('eav/config')->getAttribute('catalog_product', $productAttribute['attribute_code']);
|
897 |
-
|
898 |
-
foreach ($productAttribute['values'] as $attribute) {
|
899 |
-
$attributeOptions[$productAttribute['store_label']]['values'][] = $attribute['store_label'];
|
900 |
-
|
901 |
-
}
|
902 |
-
|
903 |
-
$attributeOptions[$productAttribute['store_label']]['is_filterable']=$attributeFull['is_filterable'];
|
904 |
-
$attributeOptions[$productAttribute['store_label']]['frontend_input']=$attributeFull['frontend_input'];
|
905 |
-
}
|
906 |
-
return $attributeOptions;
|
907 |
-
|
908 |
-
}catch(Exception $e){
|
909 |
-
return array();
|
910 |
-
}
|
911 |
-
|
912 |
-
}
|
913 |
-
|
914 |
-
private function _getPriceRange($product){
|
915 |
-
$max = '';
|
916 |
-
$min = '';
|
917 |
-
|
918 |
-
$pricesByAttributeValues = array();
|
919 |
-
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
|
920 |
-
$basePrice = $product->getFinalPrice();
|
921 |
-
$items = $attributes->getItems();
|
922 |
-
if (is_array($items)){
|
923 |
-
foreach ($items as $attribute){
|
924 |
-
$prices = $attribute->getPrices();
|
925 |
-
if (is_array($prices)){
|
926 |
-
foreach ($prices as $price){
|
927 |
-
if ($price['is_percent']){ //if the price is specified in percents
|
928 |
-
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
|
929 |
-
}
|
930 |
-
else { //if the price is absolute value
|
931 |
-
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
|
932 |
-
}
|
933 |
-
}
|
934 |
-
}
|
935 |
-
}
|
936 |
-
}
|
937 |
-
|
938 |
-
$simple = $product->getTypeInstance()->getUsedProducts();
|
939 |
-
foreach ($simple as $sProduct){
|
940 |
-
$totalPrice = $basePrice;
|
941 |
-
foreach ($attributes as $attribute){
|
942 |
-
$value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
|
943 |
-
if (isset($pricesByAttributeValues[$value])){
|
944 |
-
$totalPrice += $pricesByAttributeValues[$value];
|
945 |
-
}
|
946 |
-
}
|
947 |
-
if(!$max || $totalPrice > $max)
|
948 |
-
$max = $totalPrice;
|
949 |
-
if(!$min || $totalPrice < $min)
|
950 |
-
$min = $totalPrice;
|
951 |
-
}
|
952 |
-
$priceRange='price_min="'.$min.'" price_max="'.$max.'"';
|
953 |
-
return $priceRange;
|
954 |
-
}
|
955 |
-
|
956 |
-
private function _getSimpleProductsPriceOfConfigurable($product, $configurable_children){
|
957 |
-
$simple_products_price = array();
|
958 |
-
$pricesByAttributeValues = array();
|
959 |
-
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
|
960 |
-
$basePrice = $product->getFinalPrice();
|
961 |
-
$items = $attributes->getItems();
|
962 |
-
if (is_array($items)){
|
963 |
-
foreach ($items as $attribute){
|
964 |
-
$prices = $attribute->getPrices();
|
965 |
-
if (is_array($prices)){
|
966 |
-
foreach ($prices as $price){
|
967 |
-
if ($price['is_percent']){ //if the price is specified in percents
|
968 |
-
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
|
969 |
-
}
|
970 |
-
else { //if the price is absolute value
|
971 |
-
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
|
972 |
-
}
|
973 |
-
}
|
974 |
-
}
|
975 |
-
}
|
976 |
-
}
|
977 |
-
|
978 |
-
foreach ($configurable_children as $sProduct){
|
979 |
-
$totalPrice = $basePrice;
|
980 |
-
foreach ($attributes as $attribute){
|
981 |
-
$value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
|
982 |
-
if (isset($pricesByAttributeValues[$value])){
|
983 |
-
$totalPrice += $pricesByAttributeValues[$value];
|
984 |
-
}
|
985 |
-
}
|
986 |
-
$simple_products_price[$sProduct->getId()] = $totalPrice;
|
987 |
-
}
|
988 |
-
return $simple_products_price;
|
989 |
-
}
|
990 |
-
|
991 |
-
private function _getOrdersPerProduct($store_id, $product_id_list, $month_interval){
|
992 |
-
|
993 |
-
if (count($product_id_list) <= 0)
|
994 |
-
|
995 |
-
return null;
|
996 |
-
|
997 |
-
$id_str = implode(',', $product_id_list);
|
998 |
-
|
999 |
-
$query = Mage::getResourceModel('sales/order_item_collection');
|
1000 |
-
|
1001 |
-
$select = $query->getSelect()->reset(Zend_Db_Select::COLUMNS)
|
1002 |
-
|
1003 |
-
->columns(array('product_id','SUM(qty_ordered)'))
|
1004 |
-
|
1005 |
-
->where(new Zend_Db_Expr('store_id = ' . $store_id))
|
1006 |
-
|
1007 |
-
->where(new Zend_Db_Expr('product_id IN ('.$id_str.')'))
|
1008 |
-
|
1009 |
-
->where(new Zend_Db_Expr('created_at BETWEEN NOW() - INTERVAL '.$month_interval.' MONTH AND NOW()'))
|
1010 |
-
|
1011 |
-
->group(array('product_id'));
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
$resource = Mage::getSingleton('core/resource');
|
1016 |
-
|
1017 |
-
$readConnection = $resource->getConnection('core_read');
|
1018 |
-
|
1019 |
-
$results = $readConnection->fetchAll($select);
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
$orders_per_product = array();
|
1024 |
-
|
1025 |
-
foreach ($results as $res){
|
1026 |
-
|
1027 |
-
$orders_per_product[$res['product_id']] = (int)$res['SUM(qty_ordered)'];
|
1028 |
-
|
1029 |
-
}
|
1030 |
-
|
1031 |
-
return $orders_per_product;
|
1032 |
-
|
1033 |
-
}
|
1034 |
-
|
1035 |
-
private function _getPrice($product){
|
1036 |
-
$price = 0;
|
1037 |
-
$helper=Mage::helper('autocompleteplus_autosuggest');
|
1038 |
-
if ($product->getTypeId()=='grouped'){
|
1039 |
-
$helper->prepareGroupedProductPrice($product);
|
1040 |
-
$_minimalPriceValue = $product->getPrice();
|
1041 |
-
if($_minimalPriceValue){
|
1042 |
-
$price=$_minimalPriceValue;
|
1043 |
-
}
|
1044 |
-
}elseif($product->getTypeId()=='bundle'){
|
1045 |
-
if(!$product->getFinalPrice()){
|
1046 |
-
$price=$helper->getBundlePrice($product);
|
1047 |
-
}else{
|
1048 |
-
$price=$product->getFinalPrice();
|
1049 |
-
}
|
1050 |
-
}else{
|
1051 |
-
$price =$product->getFinalPrice();
|
1052 |
-
}
|
1053 |
-
if(!$price){
|
1054 |
-
$price=0;
|
1055 |
-
}
|
1056 |
-
return $price;
|
1057 |
-
}
|
1058 |
-
|
1059 |
-
/**
|
1060 |
-
|
1061 |
-
* @param $storeId
|
1062 |
-
|
1063 |
-
*/
|
1064 |
-
|
1065 |
-
private function _initCatalogCommonFields($storeId)
|
1066 |
-
{
|
1067 |
-
$this->imageField=Mage::getStoreConfig('autocompleteplus/config/imagefield');
|
1068 |
-
|
1069 |
-
if (!$this->imageField) {
|
1070 |
-
$this->imageField = 'thumbnail';
|
1071 |
-
}
|
1072 |
-
|
1073 |
-
$this->useAttributes = Mage::getStoreConfig('autocompleteplus/config/attributes');
|
1074 |
-
|
1075 |
-
$this->currency = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
|
1076 |
-
|
1077 |
-
$this->standardImageFields = array('image', 'small_image', 'thumbnail');
|
1078 |
-
|
1079 |
-
$productScheme = Mage::getModel('catalog/product');
|
1080 |
-
|
1081 |
-
if($this->useAttributes!='0'){
|
1082 |
-
$this->attributes = Mage::getResourceModel('eav/entity_attribute_collection')
|
1083 |
-
|
1084 |
-
->setEntityTypeFilter($productScheme->getResource()->getTypeId())
|
1085 |
-
|
1086 |
-
->addFieldToFilter('is_user_defined', '1') // This can be changed to any attribute code
|
1087 |
-
|
1088 |
-
->load(false);
|
1089 |
-
}
|
1090 |
-
|
1091 |
-
}
|
1092 |
-
|
1093 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Autocompleteplus_Autosuggest_Model_Catalog extends Mage_Core_Model_Abstract{
|
4 |
+
private $imageField;
|
5 |
+
private $standardImageFields;
|
6 |
+
private $useAttributes;
|
7 |
+
private $attributes;
|
8 |
+
private $currency;
|
9 |
+
private $pageNum;
|
10 |
+
|
11 |
+
public function renderCatalogXml($startInd, $count, $storeId='', $orders='', $month_interval='', $checksum=''){
|
12 |
+
|
13 |
+
$this->_initCatalogCommonFields($storeId);
|
14 |
+
|
15 |
+
if(!$startInd){
|
16 |
+
$startInd=0;
|
17 |
+
}
|
18 |
+
|
19 |
+
//maxim products on one page is 10000
|
20 |
+
if(!$count||$count>10000){
|
21 |
+
$count=10000;
|
22 |
+
}
|
23 |
+
//retrieving page number
|
24 |
+
$this->pageNum=floor(($startInd/$count));
|
25 |
+
|
26 |
+
$mage=Mage::getVersion();
|
27 |
+
$ext=Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
28 |
+
|
29 |
+
$xml='<?xml version="1.0"?>';
|
30 |
+
$xml.='<catalog version="'.$ext.'" magento="'.$mage.'">';
|
31 |
+
|
32 |
+
$collection=Mage::getModel('catalog/product')->getCollection();
|
33 |
+
if(isset($storeId)&& $storeId!=''){
|
34 |
+
$collection->addStoreFilter($storeId);
|
35 |
+
$store_id = $storeId;
|
36 |
+
} else {
|
37 |
+
$store_id = Mage::app()->getStore()->getStoreId();
|
38 |
+
}
|
39 |
+
|
40 |
+
//setting page+products on the page
|
41 |
+
$collection->getSelect()->limit($count,$startInd);//->limitPage($pageNum, $count);//setPage($pageNum, $count)->load();
|
42 |
+
$collection->load();
|
43 |
+
|
44 |
+
// number of orderes per product section
|
45 |
+
if (isset($orders) && $orders == '1'){
|
46 |
+
$product_id_list = array();
|
47 |
+
foreach ($collection as $product){
|
48 |
+
$product_id_list[] = $product->getId();
|
49 |
+
}
|
50 |
+
|
51 |
+
if(isset($month_interval)&& $month_interval!=''){
|
52 |
+
$month_interval = $month_interval;
|
53 |
+
} else {
|
54 |
+
$month_interval = 12;
|
55 |
+
}
|
56 |
+
$orders_per_product = $this->_getOrdersPerProduct($store_id, $product_id_list, $month_interval);
|
57 |
+
} else {// end - number of orderes per product section
|
58 |
+
$orders_per_product = null;
|
59 |
+
}
|
60 |
+
|
61 |
+
$this->_root_category_id = Mage::app()->getStore($store_id)->getRootCategoryId();
|
62 |
+
|
63 |
+
if(isset($checksum) && $checksum != ''){
|
64 |
+
$is_checksum = $checksum;
|
65 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
66 |
+
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
67 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
68 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
69 |
+
} else {
|
70 |
+
$is_checksum = 0;
|
71 |
+
$helper = null;
|
72 |
+
$_tableprefix = null;
|
73 |
+
$write = null;
|
74 |
+
$read = null;
|
75 |
+
}
|
76 |
+
|
77 |
+
foreach ($collection as $product) {
|
78 |
+
$productCollData=$product->getData();
|
79 |
+
try{
|
80 |
+
$productModel=Mage::getModel('catalog/product')
|
81 |
+
->setStore($storeId)->setStoreId($storeId)
|
82 |
+
->load($productCollData['entity_id']);
|
83 |
+
} catch (Exception $e){
|
84 |
+
continue;
|
85 |
+
}
|
86 |
+
$prodId =$productModel->getId();
|
87 |
+
$sku =$productModel->getSku();
|
88 |
+
$row=$this->renderProductXmlRow($productModel,$orders_per_product);
|
89 |
+
$xml.=$row;
|
90 |
+
if ($is_checksum && $helper){
|
91 |
+
if ($helper->isChecksumTableExists()){
|
92 |
+
$checksum = $helper->calculateChecksum($productModel);
|
93 |
+
$helper->updateSavedProductChecksum($_tableprefix, $read, $write, $prodId, $sku, $store_id, $checksum);
|
94 |
+
}
|
95 |
+
}
|
96 |
+
}
|
97 |
+
$xml.='</catalog>';
|
98 |
+
return $xml;
|
99 |
+
}
|
100 |
+
|
101 |
+
public function renderUpdatesCatalogXml($count,$from,$to,$storeId){
|
102 |
+
$storeQ='';
|
103 |
+
|
104 |
+
if($storeId!=''){
|
105 |
+
$storeQ = 'AND store_id='.$storeId;
|
106 |
+
}else{
|
107 |
+
$storeId = Mage::app()->getStore()->getStoreId();
|
108 |
+
}
|
109 |
+
$this->_initCatalogCommonFields($storeId);
|
110 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
111 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
112 |
+
|
113 |
+
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
114 |
+
$sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_batches` WHERE update_date BETWEEN ? AND ? '.$storeQ. ' order by update_date' . ' LIMIT '.$count;
|
115 |
+
$updates=$read->fetchAll($sql,array($from,$to));
|
116 |
+
|
117 |
+
$mage=Mage::getVersion();
|
118 |
+
$ext=Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
119 |
+
$this->_root_category_id = Mage::app()->getStore($storeId)->getRootCategoryId();
|
120 |
+
|
121 |
+
$xml='<?xml version="1.0"?>';
|
122 |
+
$xml.='<catalog fromdatetime="'.$from.'" version="'.$ext.'" magento="'.$mage.'">';
|
123 |
+
foreach ($updates as $batch) {
|
124 |
+
if($batch['action']=='update'){
|
125 |
+
$productId = $batch['product_id'];
|
126 |
+
$sku = $batch['sku'];
|
127 |
+
$batchStoreId = $batch['store_id'];
|
128 |
+
|
129 |
+
if($storeId!=$batchStoreId){
|
130 |
+
$this->currency = Mage::app()->getStore($batchStoreId)->getCurrentCurrencyCode();
|
131 |
+
}
|
132 |
+
|
133 |
+
$productModel = null;
|
134 |
+
|
135 |
+
if($productId!=null){
|
136 |
+
// load product by id
|
137 |
+
try{
|
138 |
+
$productModel=Mage::getModel('catalog/product')
|
139 |
+
->setStoreId($batchStoreId)
|
140 |
+
->load($productId);
|
141 |
+
}catch (Exception $e){
|
142 |
+
$batch['action'] = 'remove';
|
143 |
+
$xml.=$this->_makeRemoveRow($batch);
|
144 |
+
continue;
|
145 |
+
}
|
146 |
+
}else{
|
147 |
+
// product not found - changing action to remove
|
148 |
+
$batch['action'] = 'remove';
|
149 |
+
$xml.=$this->_makeRemoveRow($batch);
|
150 |
+
continue;
|
151 |
+
|
152 |
+
/*
|
153 |
+
* FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
|
154 |
+
*/
|
155 |
+
// $productModel=Mage::getModel('catalog/product')
|
156 |
+
// ->loadByAttribute('sku', $sku)
|
157 |
+
// ->setStoreId($batchStoreId);
|
158 |
+
}
|
159 |
+
|
160 |
+
if($productModel==null){
|
161 |
+
continue;
|
162 |
+
}
|
163 |
+
|
164 |
+
$updatedate = $batch['update_date'];
|
165 |
+
$action = $batch['action'];
|
166 |
+
$xmlAttrs='action="'.$action.'" updatedate="'.$updatedate.'" storeid="'.$storeId.'"' ;
|
167 |
+
// $xmlAttrs='action="'.$action.'" updatedate="'.$updatedate.'"';
|
168 |
+
$xml.=$this->renderProductXmlRow($productModel,null,$xmlAttrs);
|
169 |
+
}else{
|
170 |
+
$xml.=$this->_makeRemoveRow($batch);
|
171 |
+
}
|
172 |
+
|
173 |
+
}
|
174 |
+
$xml.='</catalog>';
|
175 |
+
return $xml;
|
176 |
+
}
|
177 |
+
|
178 |
+
public function renderCatalogFromIds($count,$fromId,$storeId){
|
179 |
+
|
180 |
+
$this->_initCatalogCommonFields($storeId);
|
181 |
+
|
182 |
+
$mage = Mage::getVersion();
|
183 |
+
$ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
184 |
+
$xml = '<catalog version="'.$ext.'" magento="'.$mage.'">';
|
185 |
+
|
186 |
+
$_productCollection = Mage::getModel('catalog/product')->getCollection()
|
187 |
+
->addStoreFilter($storeId)
|
188 |
+
->addAttributeToSelect('*')
|
189 |
+
->addAttributeToFilter('entity_id', array('from' => $fromId));
|
190 |
+
|
191 |
+
$_productCollection->getSelect()->limit($count);
|
192 |
+
|
193 |
+
//add media gallery to collection
|
194 |
+
|
195 |
+
$action= 'getfromid';
|
196 |
+
|
197 |
+
foreach($_productCollection as $product){
|
198 |
+
if($product){
|
199 |
+
$id = $product->getId();
|
200 |
+
$lastUpdateddt = $product->getUpdatedAt();
|
201 |
+
|
202 |
+
$xmlAttrTemplate = 'last_updated="%s" get_by_id_status="1" action="%s" storeid="%s"';
|
203 |
+
$xmlAttrs = sprintf($xmlAttrTemplate,
|
204 |
+
$lastUpdateddt,
|
205 |
+
$action,
|
206 |
+
$storeId
|
207 |
+
);
|
208 |
+
|
209 |
+
$xml .= $this->renderProductXmlRow($product, null, $xmlAttrs);
|
210 |
+
|
211 |
+
} else {
|
212 |
+
$xml .= '<product action="' . $action . '" product="' . $id . '" get_by_id_status="0"></product>';
|
213 |
+
}
|
214 |
+
|
215 |
+
}
|
216 |
+
|
217 |
+
$xml.='</catalog>';
|
218 |
+
|
219 |
+
return $xml;
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Creates an XML representation of catalog by ids
|
224 |
+
* @param array $ids
|
225 |
+
* @param integer $storeId
|
226 |
+
* @return string
|
227 |
+
*/
|
228 |
+
public function renderCatalogByIds($ids, $storeId = 0)
|
229 |
+
{
|
230 |
+
|
231 |
+
$this->_initCatalogCommonFields($storeId);
|
232 |
+
|
233 |
+
$mage = Mage::getVersion();
|
234 |
+
$ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
235 |
+
$xml = '<catalog version="'.$ext.'" magento="'.$mage.'">';
|
236 |
+
|
237 |
+
$_productCollection = Mage::getModel('catalog/product')->getCollection()
|
238 |
+
//->addStoreFilter($storeId)
|
239 |
+
//->addAttributeToSelect('*')
|
240 |
+
->addAttributeToFilter('entity_id', array(
|
241 |
+
'in' => $ids
|
242 |
+
));
|
243 |
+
|
244 |
+
$this->_root_category_id = Mage::app()->getStore($storeId)->getRootCategoryId();
|
245 |
+
|
246 |
+
$action= 'getbyid';
|
247 |
+
|
248 |
+
foreach($ids as $id){
|
249 |
+
|
250 |
+
$productModel=Mage::getModel('catalog/product')
|
251 |
+
->setStoreId($storeId)
|
252 |
+
->load($id);
|
253 |
+
|
254 |
+
if($productModel->getId()){
|
255 |
+
|
256 |
+
$lastUpdateddt=$productModel->getUpdatedAt();
|
257 |
+
|
258 |
+
$xmlAttrs='last_updated="'.$lastUpdateddt.'" get_by_id_status="1" action="'.$action.'" storeid="'.$storeId.'"' ;
|
259 |
+
|
260 |
+
$xml.=$this->renderProductXmlRow($productModel,null,$xmlAttrs);
|
261 |
+
|
262 |
+
}else{
|
263 |
+
$xml.='<product action="'.$action.'" product="'.$id.'" get_by_id_status="0"></product>';
|
264 |
+
}
|
265 |
+
|
266 |
+
}
|
267 |
+
|
268 |
+
$xml.='</catalog>';
|
269 |
+
|
270 |
+
return $xml;
|
271 |
+
}
|
272 |
+
|
273 |
+
public function getCategoryMap()
|
274 |
+
{
|
275 |
+
if(!$this->_categories){
|
276 |
+
Mage::log('creating categories once',false,'pjackson.log');
|
277 |
+
$categoryMap = array();
|
278 |
+
$categories = Mage::getModel('catalog/category')->getCollection()->load();
|
279 |
+
|
280 |
+
foreach($categories as $category){
|
281 |
+
$categoryMap[] = new Varien_Object(array(
|
282 |
+
'id'=>$category->getId(),
|
283 |
+
'path'=>$category->getPath(),
|
284 |
+
'parent_id'=>$category->getParentId()
|
285 |
+
));
|
286 |
+
}
|
287 |
+
|
288 |
+
$this->_categories = $categoryMap;
|
289 |
+
}
|
290 |
+
|
291 |
+
return $this->_categories;
|
292 |
+
}
|
293 |
+
|
294 |
+
public function getCategoryPathsByProduct(Mage_Catalog_Model_Product $product)
|
295 |
+
{
|
296 |
+
$productCategories = $product->getCategoryIds();
|
297 |
+
$root_category_id = $this->_root_category_id;
|
298 |
+
$paths = array_map(function($category) use ($productCategories, $root_category_id) {
|
299 |
+
if(in_array($category->getId(), $productCategories)){
|
300 |
+
$path = explode('/', $category->getPath());
|
301 |
+
//we don't want the root category for the entire site
|
302 |
+
array_shift($path);
|
303 |
+
if ($root_category_id && is_array($path) && $path[0] != $root_category_id){
|
304 |
+
return array();
|
305 |
+
}
|
306 |
+
//we want more specific categories first
|
307 |
+
return implode(':', array_reverse($path));
|
308 |
+
}
|
309 |
+
}, $this->getCategoryMap());
|
310 |
+
|
311 |
+
return array_filter($paths);
|
312 |
+
}
|
313 |
+
|
314 |
+
public function renderProductXmlRow($productModel,$orders_per_product,$xmlAttrs='action="insert"')
|
315 |
+
{
|
316 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
317 |
+
$categories = $this->getCategoryPathsByProduct($productModel);
|
318 |
+
$price = $this->_getPrice($productModel);
|
319 |
+
$sku = $productModel->getSku();
|
320 |
+
$stock_status = $productModel->isInStock();
|
321 |
+
$stockItem = $productModel->getStockItem();
|
322 |
+
|
323 |
+
if($stockItem){
|
324 |
+
if($stockItem->getIsInStock() && $stock_status){
|
325 |
+
$sell=1;
|
326 |
+
}else{
|
327 |
+
$sell=0;
|
328 |
+
}
|
329 |
+
}else{
|
330 |
+
if($stock_status){
|
331 |
+
$sell=1;
|
332 |
+
}else{
|
333 |
+
$sell=0;
|
334 |
+
}
|
335 |
+
}
|
336 |
+
|
337 |
+
$productUrl = ''; // getting the product's url according to the store_id
|
338 |
+
|
339 |
+
$is_getUrlPath_supported = true;
|
340 |
+
if (method_exists('Mage' , 'getVersionInfo')){ // getUrlPath is not supported on EE 1.13... & 1.14...
|
341 |
+
$edition_info = Mage::getVersionInfo();
|
342 |
+
if ($edition_info['major'] == 1 && $edition_info['minor'] >= 13){
|
343 |
+
$is_getUrlPath_supported = false;
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
if (method_exists($productModel, 'getUrlPath') && $is_getUrlPath_supported){
|
348 |
+
$productUrl = $productModel->getUrlPath();
|
349 |
+
if ($productUrl != ''){
|
350 |
+
$productUrl = Mage::getUrl($productUrl);
|
351 |
+
}
|
352 |
+
}
|
353 |
+
if ($productUrl == '' && method_exists($productModel, 'getProductUrl')){
|
354 |
+
$productUrl = $productModel->getProductUrl();
|
355 |
+
// $pattern = '/\?___.*/';
|
356 |
+
// $productUrl = preg_replace($pattern, '', $productUrl);
|
357 |
+
}
|
358 |
+
if ($productUrl == '') {
|
359 |
+
$productUrl = Mage::helper('catalog/product')->getProductUrl($productModel->getId());
|
360 |
+
}
|
361 |
+
|
362 |
+
$prodId = $productModel->getId();
|
363 |
+
$prodDesc = $productModel->getDescription();
|
364 |
+
$prodShortDesc = $productModel->getShortDescription();
|
365 |
+
$prodName = $productModel->getName();
|
366 |
+
$visibility = $productModel->getVisibility();
|
367 |
+
|
368 |
+
if(defined('Mage_Catalog_Model_Product_Status::STATUS_ENABLED')){
|
369 |
+
if ($productModel->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED){
|
370 |
+
$product_status = 1;
|
371 |
+
} else {
|
372 |
+
$product_status = 0;
|
373 |
+
}
|
374 |
+
} else {
|
375 |
+
if ($productModel->getStatus() == 1){
|
376 |
+
$product_status = 1;
|
377 |
+
} else {
|
378 |
+
$product_status = 0;
|
379 |
+
}
|
380 |
+
}
|
381 |
+
|
382 |
+
try{
|
383 |
+
if(in_array($this->imageField,$this->standardImageFields)){
|
384 |
+
$prodImage =Mage::helper('catalog/image')->init($productModel, $this->imageField);
|
385 |
+
}else{
|
386 |
+
$function='get'.$this->imageField;
|
387 |
+
$prodImage =$productModel->$function();
|
388 |
+
}
|
389 |
+
|
390 |
+
try{
|
391 |
+
$product_media_config = Mage::getModel('catalog/product_media_config');
|
392 |
+
$product_base_image = $product_media_config->getMediaUrl($productModel->getImage());
|
393 |
+
} catch (Exception $e){
|
394 |
+
$product_base_image = '';
|
395 |
+
}
|
396 |
+
|
397 |
+
}catch(Exception $e){
|
398 |
+
$prodImage='';
|
399 |
+
$product_base_image = '';
|
400 |
+
}
|
401 |
+
|
402 |
+
if($productModel->getTypeID()=='configurable'){
|
403 |
+
$configurableAttributes=$this->_getConfigurableAttributes($productModel);
|
404 |
+
|
405 |
+
$configurableChildren = $this->_getConfigurableChildren($productModel);
|
406 |
+
|
407 |
+
// getting all children's ids
|
408 |
+
$configurable_children_ids = array();
|
409 |
+
foreach($configurableChildren as $child_product){
|
410 |
+
$configurable_children_ids[] = $child_product->getId();
|
411 |
+
}
|
412 |
+
|
413 |
+
// getting sellable option for the configurable product
|
414 |
+
if ($sell){ // Configurable is in stock
|
415 |
+
$is_in_stock_child_exist = false;
|
416 |
+
foreach($configurableChildren as $child_product){
|
417 |
+
if ($child_product->getStockItem()->getIsInStock()){
|
418 |
+
if (method_exists($child_product, 'isSaleable') && !$child_product->isSaleable()){
|
419 |
+
// the simple product is probably disabled (because its in stock)
|
420 |
+
continue;
|
421 |
+
}
|
422 |
+
$is_in_stock_child_exist = true;
|
423 |
+
break;
|
424 |
+
}
|
425 |
+
}
|
426 |
+
if (!$is_in_stock_child_exist){
|
427 |
+
# Configurable is in stock, but has no in stock children
|
428 |
+
$sell = 0;
|
429 |
+
}
|
430 |
+
}
|
431 |
+
|
432 |
+
try{
|
433 |
+
$priceRange=$this->_getPriceRange($productModel);
|
434 |
+
}catch(Exception $e){
|
435 |
+
$priceRange='price_min="" price_max=""';
|
436 |
+
}
|
437 |
+
} else if ($productModel->getTypeID() == 'simple'){
|
438 |
+
$simple_product_parents = $this->_getSimpleProductParent($productModel);
|
439 |
+
$priceRange='price_min="" price_max=""';
|
440 |
+
}else{
|
441 |
+
$priceRange='price_min="" price_max=""';
|
442 |
+
}
|
443 |
+
|
444 |
+
$num_of_orders = ($orders_per_product != null && array_key_exists($prodId, $orders_per_product)) ? $orders_per_product[$prodId] : 0;
|
445 |
+
$row='<product '.$priceRange.' id="'.$prodId.'" type="'.$productModel->getTypeID().'" currency="'.$this->currency.'" visibility="'.$visibility.'" price="'.$price.'" url="'.$productUrl.'" thumbs="'.$prodImage.'" base_image="'.$product_base_image.'" selleable="'.$sell.'" '.$xmlAttrs.' >';
|
446 |
+
$row.='<description><![CDATA['.$prodDesc.']]></description>';
|
447 |
+
$row.='<short><![CDATA['.$prodShortDesc.']]></short>';
|
448 |
+
$row.='<name><![CDATA['.$prodName.']]></name>';
|
449 |
+
$row.='<sku><![CDATA['.$sku.']]></sku>';
|
450 |
+
|
451 |
+
$summaryData = Mage::getModel('review/review_summary')
|
452 |
+
->setStoreId($productModel->getStoreId())
|
453 |
+
->load($prodId);
|
454 |
+
if (($summaryData['rating_summary'] || $summaryData['rating_summary'] == 0) && $summaryData['rating_summary'] != ''){
|
455 |
+
$row.='<review><![CDATA['.$summaryData['rating_summary'].']]></review>';
|
456 |
+
$row.='<reviews_count><![CDATA['.$summaryData['reviews_count'].']]></reviews_count>';
|
457 |
+
}
|
458 |
+
|
459 |
+
$new_from_date = $productModel->getNewsFromDate();
|
460 |
+
$new_to_date = $productModel->getNewsToDate();
|
461 |
+
if ($new_from_date){
|
462 |
+
$row.='<newfrom><![CDATA['.Mage::getModel('core/date')->timestamp($new_from_date).']]></newfrom>';
|
463 |
+
if ($new_to_date){
|
464 |
+
$row.='<newto><![CDATA['.Mage::getModel('core/date')->timestamp($new_to_date).']]></newto>';
|
465 |
+
}
|
466 |
+
}
|
467 |
+
|
468 |
+
$row.= '<purchase_popularity><![CDATA['.$num_of_orders.']]></purchase_popularity>';
|
469 |
+
$row.='<product_status><![CDATA['.$product_status.']]></product_status>';
|
470 |
+
|
471 |
+
try{
|
472 |
+
$row.='<creation_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getCreatedAt()).']]></creation_date>';
|
473 |
+
$row.='<updated_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getUpdatedAt()).']]></updated_date>';
|
474 |
+
} catch(Exception $e){
|
475 |
+
}
|
476 |
+
|
477 |
+
if($this->useAttributes!='0'){
|
478 |
+
foreach($this->attributes as $attr){
|
479 |
+
$action=$attr->getAttributeCode();
|
480 |
+
$is_filterable=$attr->getis_filterable();
|
481 |
+
$attribute_label = $attr->getStoreLabel($productModel->getStoreId());
|
482 |
+
|
483 |
+
if($attr->getfrontend_input()=='select'){
|
484 |
+
if($productModel->getData($action)){
|
485 |
+
if (method_exists($productModel, 'getAttributeText')){
|
486 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
487 |
+
<attribute_values><![CDATA['.$productModel->getAttributeText($action).']]></attribute_values>
|
488 |
+
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
489 |
+
</attribute>';
|
490 |
+
} else {
|
491 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
492 |
+
<attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
|
493 |
+
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
494 |
+
</attribute>';
|
495 |
+
}
|
496 |
+
}
|
497 |
+
}elseif($attr->getfrontend_input()=='textarea'){
|
498 |
+
if($productModel->getData($action)){
|
499 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
500 |
+
<attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
|
501 |
+
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
502 |
+
</attribute>';
|
503 |
+
}
|
504 |
+
}elseif($attr->getfrontend_input()=='price'){
|
505 |
+
if($productModel->getData($action)){
|
506 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
507 |
+
<attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
|
508 |
+
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
509 |
+
</attribute>';
|
510 |
+
}
|
511 |
+
}elseif($attr->getfrontend_input()=='text'){
|
512 |
+
if($productModel->getData($action)){
|
513 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
514 |
+
<attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
|
515 |
+
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
516 |
+
</attribute>';
|
517 |
+
}
|
518 |
+
}elseif($attr->getfrontend_input()=='multiselect'){
|
519 |
+
if($productModel->getData($action)){
|
520 |
+
$values=$productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
|
521 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
|
522 |
+
<attribute_values><![CDATA['.$values.']]></attribute_values>
|
523 |
+
<attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
|
524 |
+
</attribute>';
|
525 |
+
}
|
526 |
+
}
|
527 |
+
}
|
528 |
+
|
529 |
+
if($productModel->getTypeID()=='configurable' && count($configurableAttributes)>0){
|
530 |
+
$configural_attributes = array();
|
531 |
+
foreach($configurableAttributes as $attrName=>$confAttrN){
|
532 |
+
if(is_array($confAttrN) && array_key_exists('values',$confAttrN)){
|
533 |
+
$configural_attributes[] = $attrName;
|
534 |
+
$values=implode(' , ',$confAttrN['values']);
|
535 |
+
$row.='<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
|
536 |
+
}
|
537 |
+
}
|
538 |
+
$simple_products_price = $this->_getSimpleProductsPriceOfConfigurable($productModel, $configurableChildren);
|
539 |
+
|
540 |
+
if (!empty($configural_attributes)){
|
541 |
+
$product_variation = '<variants>';
|
542 |
+
try{
|
543 |
+
foreach($configurableChildren as $child_product){
|
544 |
+
if (!in_array($productModel->getStoreId(), $child_product->getStoreIds())){
|
545 |
+
continue;
|
546 |
+
}
|
547 |
+
|
548 |
+
$is_variant_in_stock = ($child_product->getStockItem()->getIsInStock()) ? 1 : 0;
|
549 |
+
|
550 |
+
if (method_exists($child_product, 'isSaleable')){
|
551 |
+
$is_variant_sellable = ($child_product->isSaleable()) ? 1 : 0;
|
552 |
+
} else {
|
553 |
+
$is_variant_sellable = '';
|
554 |
+
// $is_variant_sellable = (Mage::getModel('catalog/product')
|
555 |
+
// ->setStore($productModel->getStoreId())
|
556 |
+
// ->setStoreId($productModel->getStoreId())
|
557 |
+
// ->load($child_product->getId())
|
558 |
+
// ->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
|
559 |
+
}
|
560 |
+
|
561 |
+
if (method_exists($child_product, 'getVisibility')){
|
562 |
+
$is_variant_visible = ($child_product->getVisibility()) ? 1 : 0;
|
563 |
+
} else {
|
564 |
+
$is_variant_visible = '';
|
565 |
+
// $is_variant_visible = (Mage::getModel('catalog/product')
|
566 |
+
// ->setStore($productModel->getStoreId())
|
567 |
+
// ->setStoreId($productModel->getStoreId())
|
568 |
+
// ->load($child_product->getId())
|
569 |
+
// ->getVisibility());
|
570 |
+
}
|
571 |
+
|
572 |
+
$variant_price = (array_key_exists($child_product->getId(), $simple_products_price)) ?
|
573 |
+
$simple_products_price[$child_product->getId()] : '';
|
574 |
+
|
575 |
+
$product_variation .= '<variant id="'.$child_product->getId().'" type="'.$child_product->getTypeID().
|
576 |
+
'" visibility="'.$is_variant_visible.'" is_in_stock="'.$is_variant_in_stock.'" is_seallable="'.$is_variant_sellable.'" price="'.$variant_price.'">';
|
577 |
+
$product_variation .= '<name><![CDATA['.$child_product->getName().']]></name>';
|
578 |
+
|
579 |
+
$attributes = $child_product->getAttributes();
|
580 |
+
foreach ($attributes as $attribute) {
|
581 |
+
if (!$attribute['is_configurable'] || !in_array($attribute['store_label'], $configural_attributes)){ // || !$attribute->getIsVisibleOnFront()
|
582 |
+
continue;
|
583 |
+
}
|
584 |
+
|
585 |
+
$product_variation .= '<variant_attribute is_configurable="1" is_filterable="'.$attribute->getis_filterable().
|
586 |
+
'" name="'.$attribute['store_label'].'" name_code="'.$attribute->getId().
|
587 |
+
'" value_code="'.$child_product->getData($attribute->getAttributeCode()).
|
588 |
+
'"><![CDATA['.$attribute->getFrontend()->getValue($child_product).
|
589 |
+
']]></variant_attribute>';
|
590 |
+
}
|
591 |
+
$product_variation .= '</variant>';
|
592 |
+
}
|
593 |
+
} catch(Exception $e ){
|
594 |
+
}
|
595 |
+
$product_variation .= '</variants>';
|
596 |
+
$row.=$product_variation;
|
597 |
+
}
|
598 |
+
|
599 |
+
$row.='<simpleproducts><![CDATA['.implode(',',$configurable_children_ids).']]></simpleproducts>';
|
600 |
+
}
|
601 |
+
|
602 |
+
if($productModel->getTypeID() == 'simple'){
|
603 |
+
$row.='<product_parents><![CDATA['.implode(',',$simple_product_parents).']]></product_parents>';
|
604 |
+
}
|
605 |
+
}
|
606 |
+
|
607 |
+
$row.='<categories><![CDATA[' . implode(';', $categories) . ']]></categories>';
|
608 |
+
$row.='</product>';
|
609 |
+
return $helper->escapeXml($row);
|
610 |
+
}
|
611 |
+
|
612 |
+
private function _makeUpdateRow($batch,$attributes){
|
613 |
+
|
614 |
+
$productId = $batch['product_id'];
|
615 |
+
|
616 |
+
$sku = $batch['sku'];
|
617 |
+
|
618 |
+
$storeId = $batch['store_id'];
|
619 |
+
|
620 |
+
$updatedate = $batch['update_date'];
|
621 |
+
|
622 |
+
$action = $batch['action'];
|
623 |
+
|
624 |
+
$currency=Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
|
625 |
+
|
626 |
+
if($productId!=null){
|
627 |
+
|
628 |
+
$productModel=Mage::getModel('catalog/product')
|
629 |
+
|
630 |
+
->setStoreId($storeId)
|
631 |
+
|
632 |
+
->load($productId);
|
633 |
+
|
634 |
+
if($productModel==null){
|
635 |
+
|
636 |
+
return '';
|
637 |
+
|
638 |
+
}
|
639 |
+
|
640 |
+
}else{
|
641 |
+
|
642 |
+
/*
|
643 |
+
|
644 |
+
* FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
|
645 |
+
|
646 |
+
*/
|
647 |
+
|
648 |
+
$productModel=Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
|
649 |
+
|
650 |
+
if($productModel==null){
|
651 |
+
|
652 |
+
return '';
|
653 |
+
|
654 |
+
}
|
655 |
+
|
656 |
+
$productModel = $productModel->setStoreId($storeId);
|
657 |
+
|
658 |
+
$productId=$productModel->getId();
|
659 |
+
}
|
660 |
+
|
661 |
+
if($productModel==null){
|
662 |
+
|
663 |
+
return '';
|
664 |
+
|
665 |
+
}
|
666 |
+
|
667 |
+
$price =$this->getPrice($productModel);
|
668 |
+
|
669 |
+
$sku =$productModel->getSku();
|
670 |
+
|
671 |
+
$status =$productModel->isInStock();
|
672 |
+
|
673 |
+
$stockItem = $productModel->getStockItem();
|
674 |
+
|
675 |
+
$categoriesNames='';
|
676 |
+
|
677 |
+
$categories = $productModel->getCategoryCollection()
|
678 |
+
->addAttributeToSelect('name');
|
679 |
+
|
680 |
+
foreach($categories as $category) {
|
681 |
+
$categoriesNames.=$category->getName().':'.$category->getId().';';
|
682 |
+
}
|
683 |
+
|
684 |
+
if($stockItem->getIsInStock()&&$status)
|
685 |
+
{
|
686 |
+
$sell=1;
|
687 |
+
}else{
|
688 |
+
$sell=0;
|
689 |
+
}
|
690 |
+
|
691 |
+
$productUrl =Mage::helper('catalog/product')->getProductUrl($productId);
|
692 |
+
|
693 |
+
$prodId =$productModel->getId();
|
694 |
+
|
695 |
+
$prodDesc =$productModel->getDescription();
|
696 |
+
|
697 |
+
$prodShortDesc =$productModel->getShortDescription();
|
698 |
+
|
699 |
+
$prodName =$productModel->getName();
|
700 |
+
|
701 |
+
$visibility =$productModel->getVisibility();
|
702 |
+
|
703 |
+
try{
|
704 |
+
|
705 |
+
if(in_array($this->imageField,$this->standardImageFields)){
|
706 |
+
|
707 |
+
$prodImage =Mage::helper('catalog/image')->init($productModel, $this->imageField);
|
708 |
+
|
709 |
+
}else{
|
710 |
+
|
711 |
+
$function='get'.$this->imageField;
|
712 |
+
|
713 |
+
$prodImage =$productModel->$function();
|
714 |
+
|
715 |
+
}
|
716 |
+
|
717 |
+
}catch(Exception $e){
|
718 |
+
|
719 |
+
$prodImage='';
|
720 |
+
|
721 |
+
}
|
722 |
+
|
723 |
+
if($productModel->getTypeID()=='configurable'){
|
724 |
+
|
725 |
+
$configurableAttributes=$this->_getConfigurableAttributes($productModel);
|
726 |
+
|
727 |
+
try{
|
728 |
+
|
729 |
+
$priceRange=$this->_getPriceRange($productModel);
|
730 |
+
|
731 |
+
}catch(Exception $e){
|
732 |
+
|
733 |
+
$priceRange='price_min="" price_max=""';
|
734 |
+
|
735 |
+
}
|
736 |
+
|
737 |
+
}else{
|
738 |
+
|
739 |
+
$priceRange='price_min="" price_max=""';
|
740 |
+
|
741 |
+
}
|
742 |
+
|
743 |
+
$row='<product '.$priceRange.' id="'.$prodId.'" type="'.$productModel->getTypeID().'" updatedate="'.$updatedate.'" currency="'.$currency.'" storeid="'.$storeId.'" visibility="'.$visibility.'" price="'.$price.'" url="'.$productUrl.'" thumbs="'.$prodImage.'" selleable="'.$sell.'" action="'.$action.'" >';
|
744 |
+
|
745 |
+
$row.='<description><![CDATA['.$prodDesc.']]></description>';
|
746 |
+
|
747 |
+
$row.='<short><![CDATA['.$prodShortDesc.']]></short>';
|
748 |
+
|
749 |
+
$row.='<name><![CDATA['.$prodName.']]></name>';
|
750 |
+
|
751 |
+
$row.='<sku><![CDATA['.$sku.']]></sku>';
|
752 |
+
|
753 |
+
if($attributes!=null){
|
754 |
+
|
755 |
+
foreach($attributes as $attr){
|
756 |
+
|
757 |
+
|
758 |
+
|
759 |
+
$action=$attr->getAttributeCode();
|
760 |
+
|
761 |
+
|
762 |
+
|
763 |
+
$is_filterable=$attr->getis_filterable();
|
764 |
+
|
765 |
+
|
766 |
+
|
767 |
+
if($attr->getfrontend_input()=='select'){
|
768 |
+
|
769 |
+
|
770 |
+
|
771 |
+
if($productModel->getData($action)){
|
772 |
+
|
773 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getAttributeText($action).']]></attribute>';
|
774 |
+
|
775 |
+
}
|
776 |
+
|
777 |
+
|
778 |
+
|
779 |
+
}elseif($attr->getfrontend_input()=='textarea'){
|
780 |
+
|
781 |
+
|
782 |
+
|
783 |
+
if($productModel->getData($action)){
|
784 |
+
|
785 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
|
786 |
+
|
787 |
+
}
|
788 |
+
|
789 |
+
}elseif($attr->getfrontend_input()=='price'){
|
790 |
+
|
791 |
+
|
792 |
+
|
793 |
+
if($productModel->getData($action)){
|
794 |
+
|
795 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
|
796 |
+
|
797 |
+
}
|
798 |
+
|
799 |
+
}elseif($attr->getfrontend_input()=='text'){
|
800 |
+
|
801 |
+
|
802 |
+
|
803 |
+
if($productModel->getData($action)){
|
804 |
+
|
805 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
|
806 |
+
|
807 |
+
}
|
808 |
+
|
809 |
+
}elseif($attr->getfrontend_input()=='multiselect'){
|
810 |
+
|
811 |
+
if($productModel->getData($action)){
|
812 |
+
|
813 |
+
$values=$productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
|
814 |
+
|
815 |
+
|
816 |
+
|
817 |
+
$row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'"><![CDATA['.$values.']]></attribute>';
|
818 |
+
|
819 |
+
}
|
820 |
+
|
821 |
+
}
|
822 |
+
|
823 |
+
}
|
824 |
+
|
825 |
+
if($productModel->getTypeID()=='configurable' && count($configurableAttributes)>0){
|
826 |
+
|
827 |
+
foreach($configurableAttributes as $attrName=>$confAttrN){
|
828 |
+
|
829 |
+
if(is_array($confAttrN) && array_key_exists('values',$confAttrN)){
|
830 |
+
|
831 |
+
$values=implode(' , ',$confAttrN['values']);
|
832 |
+
|
833 |
+
$row.='<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
|
834 |
+
|
835 |
+
}
|
836 |
+
|
837 |
+
|
838 |
+
|
839 |
+
}
|
840 |
+
|
841 |
+
}
|
842 |
+
|
843 |
+
}
|
844 |
+
|
845 |
+
$row.='<categories><![CDATA['.$categoriesNames.']]></categories>';
|
846 |
+
|
847 |
+
$row.='</product>';
|
848 |
+
|
849 |
+
|
850 |
+
|
851 |
+
return $row;
|
852 |
+
|
853 |
+
}
|
854 |
+
|
855 |
+
private function _makeRemoveRow($batch){
|
856 |
+
$updatedate = $batch['update_date'];
|
857 |
+
$action = $batch['action'];
|
858 |
+
$sku = $batch['sku'];
|
859 |
+
$productId = $batch['product_id'];
|
860 |
+
$storeId = $batch['store_id'];
|
861 |
+
|
862 |
+
$row='<product updatedate="'.$updatedate.'" action="'.$action.'" id="'.$productId.'" storeid="'.$storeId.'">';
|
863 |
+
$row.='<sku><![CDATA['.$sku.']]></sku>';
|
864 |
+
$row.='<id><![CDATA['.$productId.']]></id>';
|
865 |
+
$row.='</product>';
|
866 |
+
return $row;
|
867 |
+
}
|
868 |
+
|
869 |
+
private function _getConfigurableChildren($product){
|
870 |
+
|
871 |
+
$childProducts = Mage::getModel('catalog/product_type_configurable')
|
872 |
+
->getUsedProducts(null,$product);
|
873 |
+
return $childProducts;
|
874 |
+
}
|
875 |
+
|
876 |
+
private function _getSimpleProductParent($product){
|
877 |
+
try{
|
878 |
+
$parent_products_ids_list = Mage::getModel('catalog/product_type_configurable')
|
879 |
+
->getParentIdsByChild($product->getId());
|
880 |
+
|
881 |
+
return $parent_products_ids_list;
|
882 |
+
} catch(Exception $e){
|
883 |
+
return array();
|
884 |
+
}
|
885 |
+
}
|
886 |
+
|
887 |
+
private function _getConfigurableAttributes($product){
|
888 |
+
|
889 |
+
try{
|
890 |
+
// Collect options applicable to the configurable product
|
891 |
+
$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
|
892 |
+
|
893 |
+
$attributeOptions = array();
|
894 |
+
|
895 |
+
foreach ($productAttributeOptions as $productAttribute) {
|
896 |
+
$attributeFull = Mage::getModel('eav/config')->getAttribute('catalog_product', $productAttribute['attribute_code']);
|
897 |
+
|
898 |
+
foreach ($productAttribute['values'] as $attribute) {
|
899 |
+
$attributeOptions[$productAttribute['store_label']]['values'][] = $attribute['store_label'];
|
900 |
+
|
901 |
+
}
|
902 |
+
|
903 |
+
$attributeOptions[$productAttribute['store_label']]['is_filterable']=$attributeFull['is_filterable'];
|
904 |
+
$attributeOptions[$productAttribute['store_label']]['frontend_input']=$attributeFull['frontend_input'];
|
905 |
+
}
|
906 |
+
return $attributeOptions;
|
907 |
+
|
908 |
+
}catch(Exception $e){
|
909 |
+
return array();
|
910 |
+
}
|
911 |
+
|
912 |
+
}
|
913 |
+
|
914 |
+
private function _getPriceRange($product){
|
915 |
+
$max = '';
|
916 |
+
$min = '';
|
917 |
+
|
918 |
+
$pricesByAttributeValues = array();
|
919 |
+
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
|
920 |
+
$basePrice = $product->getFinalPrice();
|
921 |
+
$items = $attributes->getItems();
|
922 |
+
if (is_array($items)){
|
923 |
+
foreach ($items as $attribute){
|
924 |
+
$prices = $attribute->getPrices();
|
925 |
+
if (is_array($prices)){
|
926 |
+
foreach ($prices as $price){
|
927 |
+
if ($price['is_percent']){ //if the price is specified in percents
|
928 |
+
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
|
929 |
+
}
|
930 |
+
else { //if the price is absolute value
|
931 |
+
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
|
932 |
+
}
|
933 |
+
}
|
934 |
+
}
|
935 |
+
}
|
936 |
+
}
|
937 |
+
|
938 |
+
$simple = $product->getTypeInstance()->getUsedProducts();
|
939 |
+
foreach ($simple as $sProduct){
|
940 |
+
$totalPrice = $basePrice;
|
941 |
+
foreach ($attributes as $attribute){
|
942 |
+
$value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
|
943 |
+
if (isset($pricesByAttributeValues[$value])){
|
944 |
+
$totalPrice += $pricesByAttributeValues[$value];
|
945 |
+
}
|
946 |
+
}
|
947 |
+
if(!$max || $totalPrice > $max)
|
948 |
+
$max = $totalPrice;
|
949 |
+
if(!$min || $totalPrice < $min)
|
950 |
+
$min = $totalPrice;
|
951 |
+
}
|
952 |
+
$priceRange='price_min="'.$min.'" price_max="'.$max.'"';
|
953 |
+
return $priceRange;
|
954 |
+
}
|
955 |
+
|
956 |
+
private function _getSimpleProductsPriceOfConfigurable($product, $configurable_children){
|
957 |
+
$simple_products_price = array();
|
958 |
+
$pricesByAttributeValues = array();
|
959 |
+
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
|
960 |
+
$basePrice = $product->getFinalPrice();
|
961 |
+
$items = $attributes->getItems();
|
962 |
+
if (is_array($items)){
|
963 |
+
foreach ($items as $attribute){
|
964 |
+
$prices = $attribute->getPrices();
|
965 |
+
if (is_array($prices)){
|
966 |
+
foreach ($prices as $price){
|
967 |
+
if ($price['is_percent']){ //if the price is specified in percents
|
968 |
+
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
|
969 |
+
}
|
970 |
+
else { //if the price is absolute value
|
971 |
+
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
|
972 |
+
}
|
973 |
+
}
|
974 |
+
}
|
975 |
+
}
|
976 |
+
}
|
977 |
+
|
978 |
+
foreach ($configurable_children as $sProduct){
|
979 |
+
$totalPrice = $basePrice;
|
980 |
+
foreach ($attributes as $attribute){
|
981 |
+
$value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
|
982 |
+
if (isset($pricesByAttributeValues[$value])){
|
983 |
+
$totalPrice += $pricesByAttributeValues[$value];
|
984 |
+
}
|
985 |
+
}
|
986 |
+
$simple_products_price[$sProduct->getId()] = $totalPrice;
|
987 |
+
}
|
988 |
+
return $simple_products_price;
|
989 |
+
}
|
990 |
+
|
991 |
+
private function _getOrdersPerProduct($store_id, $product_id_list, $month_interval){
|
992 |
+
|
993 |
+
if (count($product_id_list) <= 0)
|
994 |
+
|
995 |
+
return null;
|
996 |
+
|
997 |
+
$id_str = implode(',', $product_id_list);
|
998 |
+
|
999 |
+
$query = Mage::getResourceModel('sales/order_item_collection');
|
1000 |
+
|
1001 |
+
$select = $query->getSelect()->reset(Zend_Db_Select::COLUMNS)
|
1002 |
+
|
1003 |
+
->columns(array('product_id','SUM(qty_ordered)'))
|
1004 |
+
|
1005 |
+
->where(new Zend_Db_Expr('store_id = ' . $store_id))
|
1006 |
+
|
1007 |
+
->where(new Zend_Db_Expr('product_id IN ('.$id_str.')'))
|
1008 |
+
|
1009 |
+
->where(new Zend_Db_Expr('created_at BETWEEN NOW() - INTERVAL '.$month_interval.' MONTH AND NOW()'))
|
1010 |
+
|
1011 |
+
->group(array('product_id'));
|
1012 |
+
|
1013 |
+
|
1014 |
+
|
1015 |
+
$resource = Mage::getSingleton('core/resource');
|
1016 |
+
|
1017 |
+
$readConnection = $resource->getConnection('core_read');
|
1018 |
+
|
1019 |
+
$results = $readConnection->fetchAll($select);
|
1020 |
+
|
1021 |
+
|
1022 |
+
|
1023 |
+
$orders_per_product = array();
|
1024 |
+
|
1025 |
+
foreach ($results as $res){
|
1026 |
+
|
1027 |
+
$orders_per_product[$res['product_id']] = (int)$res['SUM(qty_ordered)'];
|
1028 |
+
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
return $orders_per_product;
|
1032 |
+
|
1033 |
+
}
|
1034 |
+
|
1035 |
+
private function _getPrice($product){
|
1036 |
+
$price = 0;
|
1037 |
+
$helper=Mage::helper('autocompleteplus_autosuggest');
|
1038 |
+
if ($product->getTypeId()=='grouped'){
|
1039 |
+
$helper->prepareGroupedProductPrice($product);
|
1040 |
+
$_minimalPriceValue = $product->getPrice();
|
1041 |
+
if($_minimalPriceValue){
|
1042 |
+
$price=$_minimalPriceValue;
|
1043 |
+
}
|
1044 |
+
}elseif($product->getTypeId()=='bundle'){
|
1045 |
+
if(!$product->getFinalPrice()){
|
1046 |
+
$price=$helper->getBundlePrice($product);
|
1047 |
+
}else{
|
1048 |
+
$price=$product->getFinalPrice();
|
1049 |
+
}
|
1050 |
+
}else{
|
1051 |
+
$price =$product->getFinalPrice();
|
1052 |
+
}
|
1053 |
+
if(!$price){
|
1054 |
+
$price=0;
|
1055 |
+
}
|
1056 |
+
return $price;
|
1057 |
+
}
|
1058 |
+
|
1059 |
+
/**
|
1060 |
+
|
1061 |
+
* @param $storeId
|
1062 |
+
|
1063 |
+
*/
|
1064 |
+
|
1065 |
+
private function _initCatalogCommonFields($storeId)
|
1066 |
+
{
|
1067 |
+
$this->imageField=Mage::getStoreConfig('autocompleteplus/config/imagefield');
|
1068 |
+
|
1069 |
+
if (!$this->imageField) {
|
1070 |
+
$this->imageField = 'thumbnail';
|
1071 |
+
}
|
1072 |
+
|
1073 |
+
$this->useAttributes = Mage::getStoreConfig('autocompleteplus/config/attributes');
|
1074 |
+
|
1075 |
+
$this->currency = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
|
1076 |
+
|
1077 |
+
$this->standardImageFields = array('image', 'small_image', 'thumbnail');
|
1078 |
+
|
1079 |
+
$productScheme = Mage::getModel('catalog/product');
|
1080 |
+
|
1081 |
+
if($this->useAttributes!='0'){
|
1082 |
+
$this->attributes = Mage::getResourceModel('eav/entity_attribute_collection')
|
1083 |
+
|
1084 |
+
->setEntityTypeFilter($productScheme->getResource()->getTypeId())
|
1085 |
+
|
1086 |
+
->addFieldToFilter('is_user_defined', '1') // This can be changed to any attribute code
|
1087 |
+
|
1088 |
+
->load(false);
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
}
|
1092 |
+
|
1093 |
}
|
app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Fulltext/Collection.php
CHANGED
@@ -1,210 +1,210 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Magento
|
4 |
-
*
|
5 |
-
* NOTICE OF LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* DISCLAIMER
|
16 |
-
*
|
17 |
-
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
-
* versions in the future. If you wish to customize Magento for your
|
19 |
-
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
-
*
|
21 |
-
* @category Mage
|
22 |
-
* @package Mage_CatalogSearch
|
23 |
-
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
|
24 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
-
*/
|
26 |
-
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Fulltext Collection
|
30 |
-
*
|
31 |
-
* @category Mage
|
32 |
-
* @package Mage_CatalogSearch
|
33 |
-
* @author Magento Core Team <core@magentocommerce.com>
|
34 |
-
*/
|
35 |
-
class Autocompleteplus_Autosuggest_Model_Resource_Fulltext_Collection extends Mage_Catalog_Model_Resource_Product_Collection
|
36 |
-
{
|
37 |
-
private $list_ids = array();
|
38 |
-
private $is_fulltext_enabled = false;
|
39 |
-
|
40 |
-
private $is_layered_enabled = false;
|
41 |
-
|
42 |
-
public function __construct($resource = null, array $args = array()) {
|
43 |
-
$layered = Mage::getStoreConfig('autocompleteplus/config/layered');
|
44 |
-
if (isset($layered) && $layered == '1') {
|
45 |
-
$this->is_layered_enabled = true;
|
46 |
-
}
|
47 |
-
parent::__construct($resource, $args);
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* Retrieve query model object
|
52 |
-
*
|
53 |
-
* @return Mage_CatalogSearch_Model_Query
|
54 |
-
*/
|
55 |
-
protected function _getQuery()
|
56 |
-
{
|
57 |
-
if ($this->is_layered_enabled) {
|
58 |
-
// do nothing
|
59 |
-
} else {
|
60 |
-
return Mage::helper('catalogsearch')->getQuery();
|
61 |
-
}
|
62 |
-
}
|
63 |
-
|
64 |
-
/* compatibility with GoMage extension */
|
65 |
-
public function getSearchedEntityIds(){
|
66 |
-
return $this->list_ids;
|
67 |
-
}
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Add search query filter
|
71 |
-
*
|
72 |
-
* @param string $query
|
73 |
-
* @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
|
74 |
-
*/
|
75 |
-
public function addSearchFilter($query)
|
76 |
-
{
|
77 |
-
if ($this->is_layered_enabled) {
|
78 |
-
// do nothing
|
79 |
-
} else {
|
80 |
-
$helper=Mage::helper('autocompleteplus_autosuggest');
|
81 |
-
// $enabledFulltext=$helper->getConfigDataByFullPath('autocompleteplus/config/enabled_fulltext');
|
82 |
-
|
83 |
-
$key = $helper->getUUID();
|
84 |
-
$storeId = Mage::app()->getStore()->getStoreId();
|
85 |
-
|
86 |
-
$server_end_point = $helper->getServerEndPoint();
|
87 |
-
if ($server_end_point){
|
88 |
-
$url_domain = $server_end_point . '/ma_search';
|
89 |
-
} else {
|
90 |
-
$url_domain = 'http://magento.instantsearchplus.com/ma_search';
|
91 |
-
}
|
92 |
-
|
93 |
-
$extension_version = Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
94 |
-
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
95 |
-
$url = $url_domain.'?q='.urlencode($query).'&p=1&products_per_page=1000&v='.$extension_version.'&store_id='.$storeId.'&UUID='.$key.'&h='.$site_url;
|
96 |
-
|
97 |
-
$resp = $helper->sendCurl($url);
|
98 |
-
$response_json = json_decode($resp);
|
99 |
-
if (array_key_exists('fulltext_disabled', $response_json)){
|
100 |
-
$enabledFulltext = !$response_json->fulltext_disabled;
|
101 |
-
} else {
|
102 |
-
$enabledFulltext = false;
|
103 |
-
}
|
104 |
-
if ($enabledFulltext){
|
105 |
-
$enabledFulltext = ((array_key_exists('id_list', $response_json)) &&
|
106 |
-
(array_key_exists('total_results', $response_json))) ? true : false;
|
107 |
-
}
|
108 |
-
Mage::getSingleton('core/session')->unsIsFullTextEnable();
|
109 |
-
Mage::getSingleton('core/session')->unsIspSearchAlternatives();
|
110 |
-
Mage::getSingleton('core/session')->unsIspSearchResultsFor();
|
111 |
-
|
112 |
-
if ($enabledFulltext){
|
113 |
-
$this->is_fulltext_enabled = true;
|
114 |
-
// InstantSearch+ js file will be injected to the search result page
|
115 |
-
Mage::getSingleton('core/session')->setIsFullTextEnable(true);
|
116 |
-
// recording the query for the current 'core/session' to check it when injecting the magento_full_text.js
|
117 |
-
Mage::getSingleton('core/session')->setIspUrlEncodeQuery(urlencode($query));
|
118 |
-
|
119 |
-
if (array_key_exists('alternatives', $response_json) && $response_json->alternatives){
|
120 |
-
Mage::getSingleton('core/session')->setIspSearchAlternatives($response_json->alternatives);
|
121 |
-
} else {
|
122 |
-
Mage::getSingleton('core/session')->setIspSearchAlternatives(false);
|
123 |
-
}
|
124 |
-
if (array_key_exists('results_for', $response_json) && $response_json->results_for){
|
125 |
-
Mage::getSingleton('core/session')->setIspSearchResultsFor($response_json->results_for);
|
126 |
-
} else {
|
127 |
-
Mage::getSingleton('core/session')->setIspSearchResultsFor(false);
|
128 |
-
}
|
129 |
-
|
130 |
-
if($response_json->total_results){
|
131 |
-
$id_list = $response_json->id_list;
|
132 |
-
$product_ids = array();
|
133 |
-
//validate received ids
|
134 |
-
foreach($id_list as $id){
|
135 |
-
if($id != null && is_numeric($id)){
|
136 |
-
$product_ids[] = $id;
|
137 |
-
}
|
138 |
-
}
|
139 |
-
$this->list_ids = $product_ids;
|
140 |
-
$idStr = (count($product_ids)>0) ? implode(',',$product_ids) : '0';
|
141 |
-
}else{
|
142 |
-
$idStr = '0';
|
143 |
-
}
|
144 |
-
|
145 |
-
if (array_key_exists('server_endpoint', $response_json)){
|
146 |
-
if ($server_end_point != $response_json->server_endpoint){
|
147 |
-
$helper->setServerEndPoint($response_json->server_endpoint);
|
148 |
-
}
|
149 |
-
}
|
150 |
-
|
151 |
-
$this->getSelect()->where('e.entity_id IN ('.$idStr.')');
|
152 |
-
}else{
|
153 |
-
Mage::getSingleton('core/session')->setIsFullTextEnable(false);
|
154 |
-
$this->is_fulltext_enabled = false;
|
155 |
-
}
|
156 |
-
|
157 |
-
if(!$enabledFulltext){
|
158 |
-
//adding if fulltext search disabled then write regular flow
|
159 |
-
Mage::getSingleton('catalogsearch/fulltext')->prepareResult();
|
160 |
-
|
161 |
-
$this->getSelect()->joinInner(
|
162 |
-
array('search_result' => $this->getTable('catalogsearch/result')),
|
163 |
-
$this->getConnection()->quoteInto(
|
164 |
-
'search_result.product_id=e.entity_id AND search_result.query_id=?',
|
165 |
-
$this->_getQuery()->getId()
|
166 |
-
),
|
167 |
-
array('relevance' => 'relevance')
|
168 |
-
);
|
169 |
-
|
170 |
-
}
|
171 |
-
}
|
172 |
-
return $this;
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Set Order field
|
177 |
-
*
|
178 |
-
* @param string $attribute
|
179 |
-
* @param string $dir
|
180 |
-
* @return Mage_Catalog_Model_Resource_Product_Collection
|
181 |
-
*/
|
182 |
-
public function setOrder($attribute, $dir = parent::SORT_ORDER_ASC){
|
183 |
-
if ($this->is_layered_enabled) {
|
184 |
-
// do nothing
|
185 |
-
} else {
|
186 |
-
if($this->is_fulltext_enabled && $attribute == 'relevance'){
|
187 |
-
$dir = parent::SORT_ORDER_ASC;
|
188 |
-
$id_str = (count($this->list_ids) > 0) ? implode(',', $this->list_ids) : '0';
|
189 |
-
if (!empty($id_str)) {
|
190 |
-
$sort = "FIELD(e.entity_id, {$id_str}) {$dir}";
|
191 |
-
$this->getSelect()->order(new Zend_Db_Expr($sort));
|
192 |
-
}
|
193 |
-
} else {
|
194 |
-
return parent::setOrder($attribute, $dir);
|
195 |
-
}
|
196 |
-
}
|
197 |
-
|
198 |
-
return $this;
|
199 |
-
}
|
200 |
-
|
201 |
-
/**
|
202 |
-
* Stub method for campatibility with other search engines
|
203 |
-
*
|
204 |
-
* @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
|
205 |
-
*/
|
206 |
-
public function setGeneralDefaultQuery()
|
207 |
-
{
|
208 |
-
return $this;
|
209 |
-
}
|
210 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_CatalogSearch
|
23 |
+
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Fulltext Collection
|
30 |
+
*
|
31 |
+
* @category Mage
|
32 |
+
* @package Mage_CatalogSearch
|
33 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
34 |
+
*/
|
35 |
+
class Autocompleteplus_Autosuggest_Model_Resource_Fulltext_Collection extends Mage_Catalog_Model_Resource_Product_Collection
|
36 |
+
{
|
37 |
+
private $list_ids = array();
|
38 |
+
private $is_fulltext_enabled = false;
|
39 |
+
|
40 |
+
private $is_layered_enabled = false;
|
41 |
+
|
42 |
+
public function __construct($resource = null, array $args = array()) {
|
43 |
+
$layered = Mage::getStoreConfig('autocompleteplus/config/layered');
|
44 |
+
if (isset($layered) && $layered == '1') {
|
45 |
+
$this->is_layered_enabled = true;
|
46 |
+
}
|
47 |
+
parent::__construct($resource, $args);
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Retrieve query model object
|
52 |
+
*
|
53 |
+
* @return Mage_CatalogSearch_Model_Query
|
54 |
+
*/
|
55 |
+
protected function _getQuery()
|
56 |
+
{
|
57 |
+
if ($this->is_layered_enabled) {
|
58 |
+
// do nothing
|
59 |
+
} else {
|
60 |
+
return Mage::helper('catalogsearch')->getQuery();
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
/* compatibility with GoMage extension */
|
65 |
+
public function getSearchedEntityIds(){
|
66 |
+
return $this->list_ids;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Add search query filter
|
71 |
+
*
|
72 |
+
* @param string $query
|
73 |
+
* @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
|
74 |
+
*/
|
75 |
+
public function addSearchFilter($query)
|
76 |
+
{
|
77 |
+
if ($this->is_layered_enabled) {
|
78 |
+
// do nothing
|
79 |
+
} else {
|
80 |
+
$helper=Mage::helper('autocompleteplus_autosuggest');
|
81 |
+
// $enabledFulltext=$helper->getConfigDataByFullPath('autocompleteplus/config/enabled_fulltext');
|
82 |
+
|
83 |
+
$key = $helper->getUUID();
|
84 |
+
$storeId = Mage::app()->getStore()->getStoreId();
|
85 |
+
|
86 |
+
$server_end_point = $helper->getServerEndPoint();
|
87 |
+
if ($server_end_point){
|
88 |
+
$url_domain = $server_end_point . '/ma_search';
|
89 |
+
} else {
|
90 |
+
$url_domain = 'http://magento.instantsearchplus.com/ma_search';
|
91 |
+
}
|
92 |
+
|
93 |
+
$extension_version = Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
94 |
+
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
95 |
+
$url = $url_domain.'?q='.urlencode($query).'&p=1&products_per_page=1000&v='.$extension_version.'&store_id='.$storeId.'&UUID='.$key.'&h='.$site_url;
|
96 |
+
|
97 |
+
$resp = $helper->sendCurl($url);
|
98 |
+
$response_json = json_decode($resp);
|
99 |
+
if (array_key_exists('fulltext_disabled', $response_json)){
|
100 |
+
$enabledFulltext = !$response_json->fulltext_disabled;
|
101 |
+
} else {
|
102 |
+
$enabledFulltext = false;
|
103 |
+
}
|
104 |
+
if ($enabledFulltext){
|
105 |
+
$enabledFulltext = ((array_key_exists('id_list', $response_json)) &&
|
106 |
+
(array_key_exists('total_results', $response_json))) ? true : false;
|
107 |
+
}
|
108 |
+
Mage::getSingleton('core/session')->unsIsFullTextEnable();
|
109 |
+
Mage::getSingleton('core/session')->unsIspSearchAlternatives();
|
110 |
+
Mage::getSingleton('core/session')->unsIspSearchResultsFor();
|
111 |
+
|
112 |
+
if ($enabledFulltext){
|
113 |
+
$this->is_fulltext_enabled = true;
|
114 |
+
// InstantSearch+ js file will be injected to the search result page
|
115 |
+
Mage::getSingleton('core/session')->setIsFullTextEnable(true);
|
116 |
+
// recording the query for the current 'core/session' to check it when injecting the magento_full_text.js
|
117 |
+
Mage::getSingleton('core/session')->setIspUrlEncodeQuery(urlencode($query));
|
118 |
+
|
119 |
+
if (array_key_exists('alternatives', $response_json) && $response_json->alternatives){
|
120 |
+
Mage::getSingleton('core/session')->setIspSearchAlternatives($response_json->alternatives);
|
121 |
+
} else {
|
122 |
+
Mage::getSingleton('core/session')->setIspSearchAlternatives(false);
|
123 |
+
}
|
124 |
+
if (array_key_exists('results_for', $response_json) && $response_json->results_for){
|
125 |
+
Mage::getSingleton('core/session')->setIspSearchResultsFor($response_json->results_for);
|
126 |
+
} else {
|
127 |
+
Mage::getSingleton('core/session')->setIspSearchResultsFor(false);
|
128 |
+
}
|
129 |
+
|
130 |
+
if($response_json->total_results){
|
131 |
+
$id_list = $response_json->id_list;
|
132 |
+
$product_ids = array();
|
133 |
+
//validate received ids
|
134 |
+
foreach($id_list as $id){
|
135 |
+
if($id != null && is_numeric($id)){
|
136 |
+
$product_ids[] = $id;
|
137 |
+
}
|
138 |
+
}
|
139 |
+
$this->list_ids = $product_ids;
|
140 |
+
$idStr = (count($product_ids)>0) ? implode(',',$product_ids) : '0';
|
141 |
+
}else{
|
142 |
+
$idStr = '0';
|
143 |
+
}
|
144 |
+
|
145 |
+
if (array_key_exists('server_endpoint', $response_json)){
|
146 |
+
if ($server_end_point != $response_json->server_endpoint){
|
147 |
+
$helper->setServerEndPoint($response_json->server_endpoint);
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
$this->getSelect()->where('e.entity_id IN ('.$idStr.')');
|
152 |
+
}else{
|
153 |
+
Mage::getSingleton('core/session')->setIsFullTextEnable(false);
|
154 |
+
$this->is_fulltext_enabled = false;
|
155 |
+
}
|
156 |
+
|
157 |
+
if(!$enabledFulltext){
|
158 |
+
//adding if fulltext search disabled then write regular flow
|
159 |
+
Mage::getSingleton('catalogsearch/fulltext')->prepareResult();
|
160 |
+
|
161 |
+
$this->getSelect()->joinInner(
|
162 |
+
array('search_result' => $this->getTable('catalogsearch/result')),
|
163 |
+
$this->getConnection()->quoteInto(
|
164 |
+
'search_result.product_id=e.entity_id AND search_result.query_id=?',
|
165 |
+
$this->_getQuery()->getId()
|
166 |
+
),
|
167 |
+
array('relevance' => 'relevance')
|
168 |
+
);
|
169 |
+
|
170 |
+
}
|
171 |
+
}
|
172 |
+
return $this;
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Set Order field
|
177 |
+
*
|
178 |
+
* @param string $attribute
|
179 |
+
* @param string $dir
|
180 |
+
* @return Mage_Catalog_Model_Resource_Product_Collection
|
181 |
+
*/
|
182 |
+
public function setOrder($attribute, $dir = parent::SORT_ORDER_ASC){
|
183 |
+
if ($this->is_layered_enabled) {
|
184 |
+
// do nothing
|
185 |
+
} else {
|
186 |
+
if($this->is_fulltext_enabled && $attribute == 'relevance'){
|
187 |
+
$dir = parent::SORT_ORDER_ASC;
|
188 |
+
$id_str = (count($this->list_ids) > 0) ? implode(',', $this->list_ids) : '0';
|
189 |
+
if (!empty($id_str)) {
|
190 |
+
$sort = "FIELD(e.entity_id, {$id_str}) {$dir}";
|
191 |
+
$this->getSelect()->order(new Zend_Db_Expr($sort));
|
192 |
+
}
|
193 |
+
} else {
|
194 |
+
return parent::setOrder($attribute, $dir);
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
return $this;
|
199 |
+
}
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Stub method for campatibility with other search engines
|
203 |
+
*
|
204 |
+
* @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
|
205 |
+
*/
|
206 |
+
public function setGeneralDefaultQuery()
|
207 |
+
{
|
208 |
+
return $this;
|
209 |
+
}
|
210 |
}
|
app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/Autocompleteplus/PushController.php
CHANGED
@@ -2,7 +2,8 @@
|
|
2 |
|
3 |
class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_PushController extends Mage_Adminhtml_Controller_Action
|
4 |
{
|
5 |
-
public function startpushAction()
|
|
|
6 |
$response = $this->getResponse();
|
7 |
|
8 |
$service = Mage::getModel('autocompleteplus_autosuggest/service');
|
@@ -12,7 +13,8 @@ class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_PushController ext
|
|
12 |
$response->sendResponse();
|
13 |
}
|
14 |
|
15 |
-
protected function _isAllowed()
|
|
|
16 |
return Mage::getSingleton('admin/session')->isAllowed('system/config/autocompleteplus');
|
17 |
}
|
18 |
|
2 |
|
3 |
class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_PushController extends Mage_Adminhtml_Controller_Action
|
4 |
{
|
5 |
+
public function startpushAction()
|
6 |
+
{
|
7 |
$response = $this->getResponse();
|
8 |
|
9 |
$service = Mage::getModel('autocompleteplus_autosuggest/service');
|
13 |
$response->sendResponse();
|
14 |
}
|
15 |
|
16 |
+
protected function _isAllowed()
|
17 |
+
{
|
18 |
return Mage::getSingleton('admin/session')->isAllowed('system/config/autocompleteplus');
|
19 |
}
|
20 |
|
app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/Autocompleteplus/RedirectController.php
CHANGED
@@ -5,11 +5,13 @@ class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_RedirectController
|
|
5 |
const ISP_SITE_URL = 'https://magento.instantsearchplus.com/';
|
6 |
const REDIRECT_STATUS_CODE = 302;
|
7 |
|
8 |
-
protected function _construct()
|
|
|
9 |
$this->helper = Mage::helper('autocompleteplus_autosuggest');
|
10 |
}
|
11 |
|
12 |
-
public function gotoAction()
|
|
|
13 |
$kwys = $this->helper->getBothKeys();
|
14 |
$response = $this->getResponse();
|
15 |
|
@@ -18,7 +20,8 @@ class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_RedirectController
|
|
18 |
$response->sendResponse();
|
19 |
}
|
20 |
|
21 |
-
protected function _getIspLoginUrl($kwys)
|
|
|
22 |
$uuid = $kwys['uuid'];
|
23 |
$authkey = $kwys['authkey'];
|
24 |
|
@@ -29,7 +32,8 @@ class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_RedirectController
|
|
29 |
return self::ISP_SITE_URL . "ma_dashboard?site_id=$uuid&authentication_key=$authkey";
|
30 |
}
|
31 |
|
32 |
-
protected function _isAllowed()
|
|
|
33 |
return Mage::getSingleton('admin/session')->isAllowed('system/config/autocompleteplus');
|
34 |
}
|
35 |
}
|
5 |
const ISP_SITE_URL = 'https://magento.instantsearchplus.com/';
|
6 |
const REDIRECT_STATUS_CODE = 302;
|
7 |
|
8 |
+
protected function _construct()
|
9 |
+
{
|
10 |
$this->helper = Mage::helper('autocompleteplus_autosuggest');
|
11 |
}
|
12 |
|
13 |
+
public function gotoAction()
|
14 |
+
{
|
15 |
$kwys = $this->helper->getBothKeys();
|
16 |
$response = $this->getResponse();
|
17 |
|
20 |
$response->sendResponse();
|
21 |
}
|
22 |
|
23 |
+
protected function _getIspLoginUrl($kwys)
|
24 |
+
{
|
25 |
$uuid = $kwys['uuid'];
|
26 |
$authkey = $kwys['authkey'];
|
27 |
|
32 |
return self::ISP_SITE_URL . "ma_dashboard?site_id=$uuid&authentication_key=$authkey";
|
33 |
}
|
34 |
|
35 |
+
protected function _isAllowed()
|
36 |
+
{
|
37 |
return Mage::getSingleton('admin/session')->isAllowed('system/config/autocompleteplus');
|
38 |
}
|
39 |
}
|
app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsController.php
CHANGED
@@ -1,713 +1,713 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* InstantSearchPlus (Autosuggest)
|
4 |
-
|
5 |
-
*
|
6 |
-
* NOTICE OF LICENSE
|
7 |
-
*
|
8 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
-
* that is available through the world-wide-web at this URL:
|
10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
11 |
-
*
|
12 |
-
* @category Mage
|
13 |
-
* @package InstantSearchPlus
|
14 |
-
* @copyright Copyright (c) 2014 Fast Simon (http://www.instantsearchplus.com)
|
15 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
16 |
-
*/
|
17 |
-
class Autocompleteplus_Autosuggest_ProductsController extends Mage_Core_Controller_Front_Action
|
18 |
-
{
|
19 |
-
protected $_storeId;
|
20 |
-
const MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION = 250;
|
21 |
-
|
22 |
-
public function sendAction(){
|
23 |
-
set_time_limit (1800);
|
24 |
-
|
25 |
-
$post = $this->getRequest()->getParams();
|
26 |
-
|
27 |
-
$startInd = $post['offset'];
|
28 |
-
|
29 |
-
$count = $post['count'];
|
30 |
-
|
31 |
-
$storeId=isset($post['store']) ? $post['store'] : '';
|
32 |
-
if ($storeId == ''){
|
33 |
-
$storeId=isset($post['store_id']) ? $post['store_id'] : '';
|
34 |
-
}
|
35 |
-
|
36 |
-
$orders=isset($post['orders']) ? $post['orders'] : '';
|
37 |
-
|
38 |
-
$month_interval=isset($post['month_interval']) ? $post['month_interval'] : '';
|
39 |
-
|
40 |
-
$checksum=isset($post['checksum']) ? $post['checksum'] : '';
|
41 |
-
|
42 |
-
$catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
|
43 |
-
|
44 |
-
$xml=$catalogModel->renderCatalogXml($startInd,$count,$storeId,$orders,$month_interval,$checksum);
|
45 |
-
|
46 |
-
header('Content-type: text/xml');
|
47 |
-
echo $xml;
|
48 |
-
die;
|
49 |
-
}
|
50 |
-
|
51 |
-
public function sendupdatedAction(){
|
52 |
-
|
53 |
-
date_default_timezone_set('Asia/Jerusalem');
|
54 |
-
|
55 |
-
set_time_limit (1800);
|
56 |
-
|
57 |
-
$post = $this->getRequest()->getParams();
|
58 |
-
|
59 |
-
$count = $post['count'];
|
60 |
-
|
61 |
-
if(!isset($post['from'])){
|
62 |
-
$returnArr=array(
|
63 |
-
'status'=>'failure',
|
64 |
-
'error_code'=>'767',
|
65 |
-
'error_details'=>'The "from" parameter is mandatory'
|
66 |
-
);
|
67 |
-
echo json_encode($returnArr);
|
68 |
-
die;
|
69 |
-
}
|
70 |
-
$from = $post['from'];
|
71 |
-
|
72 |
-
if(isset($post['to'])){
|
73 |
-
$to = $post['to'];
|
74 |
-
}else{
|
75 |
-
$to = strtotime('now');
|
76 |
-
}
|
77 |
-
|
78 |
-
$storeId='';
|
79 |
-
|
80 |
-
if(isset($post['store_id'])){
|
81 |
-
$storeId = $post['store_id'];
|
82 |
-
}
|
83 |
-
|
84 |
-
$catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
|
85 |
-
|
86 |
-
$xml=$catalogModel->renderUpdatesCatalogXml($count,$from,$to,$storeId);
|
87 |
-
|
88 |
-
header('Content-type: text/xml');
|
89 |
-
echo $xml;
|
90 |
-
die;
|
91 |
-
|
92 |
-
}
|
93 |
-
|
94 |
-
private function __checkAccess(){
|
95 |
-
|
96 |
-
$post = $this->getRequest()->getParams();
|
97 |
-
|
98 |
-
$key=Mage::getModel('autocompleteplus_autosuggest/observer')->getUUID();
|
99 |
-
|
100 |
-
if(isset($post['key'])&&$post['key']==$key){
|
101 |
-
return true;
|
102 |
-
}else{
|
103 |
-
return false;
|
104 |
-
}
|
105 |
-
|
106 |
-
}
|
107 |
-
|
108 |
-
public function checkinstallAction(){
|
109 |
-
|
110 |
-
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
111 |
-
|
112 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
113 |
-
|
114 |
-
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
115 |
-
|
116 |
-
$sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
|
117 |
-
|
118 |
-
$licenseData=$read->fetchAll($sql);
|
119 |
-
|
120 |
-
$key=$licenseData[0]['licensekey'];
|
121 |
-
|
122 |
-
if(strlen($key)>0&&$key!='failed'){
|
123 |
-
echo 'the key exists';
|
124 |
-
}else{
|
125 |
-
echo 'no key inside';
|
126 |
-
}
|
127 |
-
|
128 |
-
}
|
129 |
-
|
130 |
-
public function versAction(){
|
131 |
-
$mage = Mage::getVersion();
|
132 |
-
$ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
133 |
-
try{
|
134 |
-
$num_of_products = Mage::getModel('catalog/product')->getCollection()
|
135 |
-
->addStoreFilter(Mage::app()->getStore()->getStoreId())
|
136 |
-
->getSize();
|
137 |
-
} catch (Exception $e){
|
138 |
-
$num_of_products = -1;
|
139 |
-
}
|
140 |
-
|
141 |
-
if (method_exists('Mage' , 'getEdition')){
|
142 |
-
$edition = Mage::getEdition();
|
143 |
-
} else {
|
144 |
-
$edition = 'Community';
|
145 |
-
}
|
146 |
-
|
147 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
148 |
-
$uuid = $helper->getUUID();
|
149 |
-
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
150 |
-
$store_id = Mage::app()->getStore()->getStoreId();
|
151 |
-
|
152 |
-
$result = array('mage' => $mage,
|
153 |
-
'ext' => $ext,
|
154 |
-
'num_of_products' => $num_of_products,
|
155 |
-
'edition' => $edition,
|
156 |
-
'uuid' => $uuid,
|
157 |
-
'site_url' => $site_url,
|
158 |
-
'store_id' => $store_id
|
159 |
-
);
|
160 |
-
|
161 |
-
$post = $this->getRequest()->getParams();
|
162 |
-
|
163 |
-
if (array_key_exists('modules', $post))
|
164 |
-
$get_modules = $post['modules'];
|
165 |
-
else
|
166 |
-
$get_modules = false;
|
167 |
-
if ($get_modules){
|
168 |
-
try{
|
169 |
-
$modules_array = array();
|
170 |
-
foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module) {
|
171 |
-
if ($module->codePool != 'core' && $module->active == 'true'){
|
172 |
-
$modules_array[$name] = $module;
|
173 |
-
}
|
174 |
-
}
|
175 |
-
} catch (Exception $e){
|
176 |
-
$modules_array = array();
|
177 |
-
}
|
178 |
-
$result['modules'] = $modules_array;
|
179 |
-
}
|
180 |
-
echo json_encode($result);die;
|
181 |
-
}
|
182 |
-
|
183 |
-
public function getNumOfProductsAction()
|
184 |
-
{
|
185 |
-
$catalogReport = Mage::getModel('autocompleteplus_autosuggest/catalogreport');
|
186 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
187 |
-
|
188 |
-
$result = array('num_of_products' => $catalogReport->getEnabledProductsCount(),
|
189 |
-
'num_of_disabled_products' => $catalogReport->getDisabledProductsCount(),
|
190 |
-
'num_of_searchable_products' => $catalogReport->getSearchableProductsCount(),
|
191 |
-
'num_of_searchable_products2' => $catalogReport->getSearchableProducts2Count(),
|
192 |
-
'uuid' => $helper->getUUID(),
|
193 |
-
'site_url' => $helper->getConfigDataByFullPath('web/unsecure/base_url'),
|
194 |
-
'store_id' => $catalogReport->getCurrentStoreId()
|
195 |
-
);
|
196 |
-
|
197 |
-
$this->getResponse()->setHeader('Content-type', 'application/json');
|
198 |
-
$this->getResponse()->setBody(json_encode($result));
|
199 |
-
}
|
200 |
-
|
201 |
-
public function getConflictAction(){
|
202 |
-
$post = $this->getRequest()->getParams();
|
203 |
-
if (array_key_exists('all', $post))
|
204 |
-
$get_all_conflicts = $post['all'];
|
205 |
-
else
|
206 |
-
$get_all_conflicts = false;
|
207 |
-
|
208 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
209 |
-
if ($get_all_conflicts){
|
210 |
-
$result = $helper->getExtensionConflict(true);
|
211 |
-
}else{
|
212 |
-
$result = $helper->getExtensionConflict();
|
213 |
-
}
|
214 |
-
echo json_encode($result);die;
|
215 |
-
}
|
216 |
-
|
217 |
-
public function getstoresAction(){
|
218 |
-
|
219 |
-
$helper=Mage::helper('autocompleteplus_autosuggest');
|
220 |
-
|
221 |
-
echo $helper->getMultiStoreDataJson();
|
222 |
-
die;
|
223 |
-
}
|
224 |
-
|
225 |
-
public function updateemailAction(){
|
226 |
-
|
227 |
-
$helper=Mage::helper('autocompleteplus_autosuggest');
|
228 |
-
|
229 |
-
$data = $this->getRequest()->getPost();
|
230 |
-
|
231 |
-
$email=$data['email'];
|
232 |
-
$uuid=$helper->getUUID();
|
233 |
-
|
234 |
-
Mage::getModel('core/config')->saveConfig('autocompleteplus/config/store_email',$email);
|
235 |
-
|
236 |
-
$params=array(
|
237 |
-
'uuid'=>$uuid,
|
238 |
-
'email'=>$email
|
239 |
-
);
|
240 |
-
|
241 |
-
$command="http://magento.autocompleteplus.com/ext_update_email";
|
242 |
-
|
243 |
-
$res=$helper->sendPostCurl($command,$params);
|
244 |
-
|
245 |
-
$result=json_decode($res);
|
246 |
-
|
247 |
-
if($result->status=='OK'){
|
248 |
-
echo 'Your email address was updated!';
|
249 |
-
}
|
250 |
-
}
|
251 |
-
|
252 |
-
public function updatesitemapAction(){
|
253 |
-
|
254 |
-
$helper=Mage::helper('autocompleteplus_autosuggest');
|
255 |
-
|
256 |
-
$key=$helper->getUUID();
|
257 |
-
|
258 |
-
$url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
|
259 |
-
|
260 |
-
if($key!='InstallFailedUUID' && $key!='failed'){
|
261 |
-
|
262 |
-
$stemapUrl='Sitemap:http://magento.instantsearchplus.com/ext_sitemap?u='.$key.PHP_EOL;
|
263 |
-
|
264 |
-
$robotsPath=Mage::getBaseDir().DS.'robots.txt';
|
265 |
-
|
266 |
-
$write=false;
|
267 |
-
|
268 |
-
if(file_exists($robotsPath)){
|
269 |
-
if( strpos(file_get_contents($robotsPath),$stemapUrl) == false) {
|
270 |
-
$write=true;
|
271 |
-
}
|
272 |
-
}else{
|
273 |
-
|
274 |
-
if(is_writable(Mage::getBaseDir())){
|
275 |
-
|
276 |
-
//create robots sitemap
|
277 |
-
file_put_contents($robotsPath,$stemapUrl);
|
278 |
-
}else{
|
279 |
-
|
280 |
-
//write message that directory is not writteble
|
281 |
-
$command="http://magento.autocompleteplus.com/install_error";
|
282 |
-
|
283 |
-
$data=array();
|
284 |
-
$data['site']=$url;
|
285 |
-
$data['msg']='Directory '.Mage::getBaseDir().' is not writable.';
|
286 |
-
$res=$helper->sendPostCurl($command,$data);
|
287 |
-
}
|
288 |
-
}
|
289 |
-
|
290 |
-
if($write){
|
291 |
-
if(is_writable($robotsPath)){
|
292 |
-
|
293 |
-
//append sitemap
|
294 |
-
file_put_contents($robotsPath, $stemapUrl, FILE_APPEND | LOCK_EX);
|
295 |
-
}else{
|
296 |
-
//write message that file is not writteble
|
297 |
-
$command="http://magento.autocompleteplus.com/install_error";
|
298 |
-
|
299 |
-
$data=array();
|
300 |
-
$data['site']=$url;
|
301 |
-
$data['msg']='File '.$robotsPath.' is not writable.';
|
302 |
-
$res=$helper->sendPostCurl($command,$data);
|
303 |
-
}
|
304 |
-
}
|
305 |
-
|
306 |
-
}
|
307 |
-
}
|
308 |
-
|
309 |
-
protected function _setUUID($key){
|
310 |
-
|
311 |
-
try{
|
312 |
-
|
313 |
-
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
314 |
-
|
315 |
-
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
316 |
-
|
317 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
318 |
-
|
319 |
-
$tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
|
320 |
-
|
321 |
-
if(!$tblExist){return;}
|
322 |
-
|
323 |
-
$sqlFetch ='SELECT * FROM '. $_tableprefix.'autocompleteplus_config WHERE id = 1';
|
324 |
-
|
325 |
-
$updates=$write->fetchAll($sqlFetch);
|
326 |
-
|
327 |
-
if($updates&&count($updates)!=0){
|
328 |
-
|
329 |
-
$sql='UPDATE '. $_tableprefix.'autocompleteplus_config SET licensekey=? WHERE id = 1';
|
330 |
-
|
331 |
-
$write->query($sql, array($key));
|
332 |
-
|
333 |
-
}else{
|
334 |
-
|
335 |
-
$sql='INSERT INTO '. $_tableprefix.'autocompleteplus_config (licensekey) VALUES (?)';
|
336 |
-
|
337 |
-
$write->query($sql, array($key));
|
338 |
-
|
339 |
-
}
|
340 |
-
|
341 |
-
|
342 |
-
}catch(Exception $e){
|
343 |
-
Mage::log($e->getMessage(),null,'autocompleteplus.log');
|
344 |
-
}
|
345 |
-
|
346 |
-
}
|
347 |
-
|
348 |
-
public function getIspUuidAction(){
|
349 |
-
|
350 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
351 |
-
|
352 |
-
echo $helper->getUUID();
|
353 |
-
}
|
354 |
-
|
355 |
-
public function geterrormessageAction(){
|
356 |
-
|
357 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
358 |
-
|
359 |
-
echo $helper->getErrormessage();
|
360 |
-
}
|
361 |
-
|
362 |
-
public function setIspUuidAction(){
|
363 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
364 |
-
$url_domain = 'http://magento.instantsearchplus.com/update_uuid';
|
365 |
-
$storeId = Mage::app()->getStore()->getStoreId();
|
366 |
-
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
367 |
-
$url = $url_domain . '?store_id=' . $storeId . '&site_url=' . $site_url;
|
368 |
-
|
369 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
370 |
-
$resp = $helper->sendCurl($url);
|
371 |
-
$response_json = json_decode($resp);
|
372 |
-
|
373 |
-
if (array_key_exists('uuid', $response_json)){
|
374 |
-
if (strlen($response_json->uuid) == 36 && substr_count($response_json->uuid, '-') == 4){
|
375 |
-
$this->_setUUID($response_json->uuid);
|
376 |
-
}
|
377 |
-
}
|
378 |
-
}
|
379 |
-
|
380 |
-
public function checkDeletedAction(){
|
381 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
382 |
-
if (!$helper->isChecksumTableExists()){
|
383 |
-
return;
|
384 |
-
}
|
385 |
-
$time_stamp = time();
|
386 |
-
|
387 |
-
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
388 |
-
$table_prefix = (string)Mage::getConfig()->getTablePrefix();
|
389 |
-
|
390 |
-
$post = $this->getRequest()->getParams();
|
391 |
-
if (array_key_exists('store_id', $post)){
|
392 |
-
$store_id = $post['store_id'];
|
393 |
-
}else{
|
394 |
-
$store_id = Mage::app()->getStore()->getStoreId(); // default
|
395 |
-
}
|
396 |
-
|
397 |
-
$sql_fetch = 'SELECT identifier FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE store_id=?';
|
398 |
-
$updates = $read->fetchPairs($sql_fetch, array($store_id)); // empty array if fails
|
399 |
-
if (empty($updates)){
|
400 |
-
return;
|
401 |
-
}
|
402 |
-
|
403 |
-
$checksum_ids = array_keys($updates); // array of all checksum table identifiers
|
404 |
-
$collection = Mage::getResourceModel('catalog/product_collection');
|
405 |
-
$collection->addFieldToFilter('entity_id',array('in'=>$checksum_ids));
|
406 |
-
$found_ids = $collection->getAllIds();
|
407 |
-
|
408 |
-
$removed_products_list = array_diff($checksum_ids, $found_ids); // list of identifiers that are not present in the store (removed at some point)
|
409 |
-
$removed_ids = array();
|
410 |
-
|
411 |
-
// removing non-existing identifiers from checksum table
|
412 |
-
if (!empty($removed_products_list)){
|
413 |
-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
414 |
-
$sql_delete = 'DELETE FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier IN (' . implode(',', $removed_products_list) . ')';
|
415 |
-
$write->query($sql_delete);
|
416 |
-
|
417 |
-
foreach ($removed_products_list as $product_id){
|
418 |
-
$helper->deleteProductFromTables($read, $write, $table_prefix, $product_id, $store_id);
|
419 |
-
$removed_ids[] = $product_id;
|
420 |
-
}
|
421 |
-
}
|
422 |
-
|
423 |
-
$args = array('removed_ids' => $removed_ids,
|
424 |
-
'uuid' => $helper->getUUID(),
|
425 |
-
'store_id' => $store_id,
|
426 |
-
'latency' => time() - $time_stamp, // seconds
|
427 |
-
);
|
428 |
-
echo json_encode($args); // returning the summary
|
429 |
-
}
|
430 |
-
|
431 |
-
public function checksumAction(){
|
432 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
433 |
-
|
434 |
-
$checksum_server = $helper->getServerUrl();
|
435 |
-
if (!$helper->isChecksumTableExists()){
|
436 |
-
$helper->ispErrorLog('checksum table not exist');
|
437 |
-
exit(json_encode(array('status' => 'checksum table not exist')));
|
438 |
-
}
|
439 |
-
$max_exe_time = -1;
|
440 |
-
|
441 |
-
$post = $this->getRequest()->getParams();
|
442 |
-
if (array_key_exists('store_id', $post)){
|
443 |
-
$store_id = $post['store_id'];
|
444 |
-
}else{
|
445 |
-
$store_id = Mage::app()->getStore()->getStoreId(); // default
|
446 |
-
}
|
447 |
-
if (array_key_exists('count', $post)){
|
448 |
-
$count = $post['count'];
|
449 |
-
}else{
|
450 |
-
$count = self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION; // default
|
451 |
-
}
|
452 |
-
if (array_key_exists('offset', $post))
|
453 |
-
$start_index = $post['offset'];
|
454 |
-
else
|
455 |
-
$start_index = 0; // default
|
456 |
-
if (array_key_exists('timeout', $post))
|
457 |
-
$php_timeout = $post['timeout'];
|
458 |
-
else
|
459 |
-
$php_timeout = -1; // default
|
460 |
-
if (array_key_exists('is_single', $post))
|
461 |
-
$is_single = $post['is_single'];
|
462 |
-
else
|
463 |
-
$is_single = 0; // default
|
464 |
-
|
465 |
-
if ($count > self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION && $php_timeout != -1){
|
466 |
-
$max_exe_time = ini_get('max_execution_time');
|
467 |
-
ini_set('max_execution_time', $php_timeout); // 1 hour ~ 60*60
|
468 |
-
}
|
469 |
-
|
470 |
-
$uuid = $helper->getUUID();
|
471 |
-
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
472 |
-
|
473 |
-
$collection = Mage::getModel('catalog/product')->getCollection();
|
474 |
-
if ($store_id){
|
475 |
-
$collection->addStoreFilter($store_id);
|
476 |
-
}
|
477 |
-
$num_of_products = $collection->getSize();
|
478 |
-
|
479 |
-
if ($count + $start_index > $num_of_products){
|
480 |
-
$count = $num_of_products - $start_index;
|
481 |
-
}
|
482 |
-
|
483 |
-
// sending log to the server
|
484 |
-
$log_msg = 'Update checksum is starting...';
|
485 |
-
$log_msg .= (' number of products in this store: ' . $num_of_products . ' | from: ' . $start_index . ', to: ' . ($start_index + $count));
|
486 |
-
$server_url = $checksum_server . '/magento_logging_record';
|
487 |
-
$request = $server_url . '?uuid=' . $uuid . '&site_url=' . $site_url . '&msg=' . urlencode($log_msg);
|
488 |
-
if ($store_id)
|
489 |
-
$request .= '&store_id=' . $store_id;
|
490 |
-
$resp = $helper->sendCurl($request);
|
491 |
-
|
492 |
-
$start_time = time();
|
493 |
-
$num_of_updated_checksum = 0;
|
494 |
-
if($count > self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION){
|
495 |
-
$iter = $start_index;
|
496 |
-
while ($iter < $count){
|
497 |
-
// start updating the checksum table if needed
|
498 |
-
$num_of_updated_checksum += $helper->compareProductsChecksum($iter, self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION, $store_id);
|
499 |
-
$iter += self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION;
|
500 |
-
}
|
501 |
-
} else {
|
502 |
-
// start updating the checksum table if needed
|
503 |
-
$num_of_updated_checksum = $helper->compareProductsChecksum($start_index, $count, $store_id);
|
504 |
-
}
|
505 |
-
|
506 |
-
$process_time = time() - $start_time;
|
507 |
-
// sending confirmation/summary to the server
|
508 |
-
$args = array( 'uuid' => $uuid,
|
509 |
-
'site_url' => $site_url,
|
510 |
-
'store_id' => $store_id,
|
511 |
-
'updated_checksum' => $num_of_updated_checksum,
|
512 |
-
'total_checksum' => $count,
|
513 |
-
'num_of_products' => $num_of_products,
|
514 |
-
'start_index' => $start_index,
|
515 |
-
'end_index' => $start_index + $count,
|
516 |
-
'count' => $count,
|
517 |
-
'ext_version' => (string)Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version,
|
518 |
-
'mage_version' => Mage::getVersion(),
|
519 |
-
'latency' => $process_time, // seconds
|
520 |
-
);
|
521 |
-
if ($is_single)
|
522 |
-
$args['is_single'] = 1;
|
523 |
-
echo json_encode($args); // returning the summary
|
524 |
-
|
525 |
-
$resp = $helper->sendCurl($checksum_server . '/magento_checksum_iterator?' . http_build_query($args));
|
526 |
-
|
527 |
-
if ($max_exe_time != -1){ // restore php max execution time
|
528 |
-
ini_set('max_execution_time', $max_exe_time);
|
529 |
-
}
|
530 |
-
}
|
531 |
-
|
532 |
-
public function connectionAction(){
|
533 |
-
exit('1');
|
534 |
-
}
|
535 |
-
|
536 |
-
public function changeSerpAction(){
|
537 |
-
try {
|
538 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
539 |
-
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
540 |
-
define("SOAP_WSDL", $site_url . '/api/?wsdl');
|
541 |
-
define("SOAP_USER", "instant_search");
|
542 |
-
define("SOAP_PASS", "Rilb@kped3");
|
543 |
-
|
544 |
-
$client = new SoapClient(SOAP_WSDL, array('trace' => 1, 'cache_wsdl' => 0));
|
545 |
-
$session = $client->login(SOAP_USER, SOAP_PASS);
|
546 |
-
|
547 |
-
$post = $this->getRequest()->getParams();
|
548 |
-
if (array_key_exists('new_serp', $post)){
|
549 |
-
$is_new_serp = $post['new_serp'];
|
550 |
-
}else{
|
551 |
-
$is_new_serp = '0'; // default
|
552 |
-
}
|
553 |
-
|
554 |
-
if (array_key_exists('store_id', $post)){
|
555 |
-
$store_id = $post['store_id'];
|
556 |
-
$scope_name = 'stores';
|
557 |
-
}else{ // default
|
558 |
-
$store_id = '0';
|
559 |
-
$scope_name = 'default';
|
560 |
-
}
|
561 |
-
|
562 |
-
try {
|
563 |
-
|
564 |
-
if ($is_new_serp == 'status'){
|
565 |
-
$current_state = $client->call($session, 'autocompleteplus_autosuggest.getLayeredSearchConfig', array($store_id));
|
566 |
-
echo json_encode(array('current_status' => $current_state));
|
567 |
-
return;
|
568 |
-
}
|
569 |
-
|
570 |
-
if ($is_new_serp == '1'){
|
571 |
-
$status = $client->call($session, 'autocompleteplus_autosuggest.setLayeredSearchOn', array($scope_name, $store_id));
|
572 |
-
} else {
|
573 |
-
$status = $client->call($session, 'autocompleteplus_autosuggest.setLayeredSearchOff', array($scope_name, $store_id));
|
574 |
-
}
|
575 |
-
$new_state= $client->call($session, 'autocompleteplus_autosuggest.getLayeredSearchConfig', array($store_id));
|
576 |
-
|
577 |
-
$resp = array('request_state' => $is_new_serp,
|
578 |
-
'new_state' => $new_state,
|
579 |
-
'site_url' => $site_url,
|
580 |
-
'status' => $status
|
581 |
-
);
|
582 |
-
echo json_encode($resp);
|
583 |
-
|
584 |
-
} catch (SoapFault $exception) {
|
585 |
-
echo json_encode(array('status' => 'exception: ' . print_r($exception, true)));
|
586 |
-
return;
|
587 |
-
}
|
588 |
-
|
589 |
-
} catch (Exception $e){
|
590 |
-
echo json_encode(array('status' => 'exception: ' . print_r($e, true)));
|
591 |
-
throw $e;
|
592 |
-
}
|
593 |
-
}
|
594 |
-
|
595 |
-
public function pushbulkAction(){
|
596 |
-
|
597 |
-
set_time_limit (1800);
|
598 |
-
|
599 |
-
$post = $this->getRequest()->getParams();
|
600 |
-
|
601 |
-
// $enabled= Mage::getStoreConfig('autocompleteplus/config/enabled');
|
602 |
-
// if($enabled=='0'){
|
603 |
-
// die('The user has disabled autocompleteplus.');
|
604 |
-
// }
|
605 |
-
|
606 |
-
$helper = Mage::helper('autocompleteplus_autosuggest');
|
607 |
-
|
608 |
-
if(!isset($post['pushid'])){
|
609 |
-
|
610 |
-
echo json_encode(array('success'=>false,'message'=>'Missing pushid!'));
|
611 |
-
die;
|
612 |
-
}
|
613 |
-
|
614 |
-
$pushid = $post['pushid'];
|
615 |
-
|
616 |
-
$pusher = Mage::getModel('autocompleteplus_autosuggest/pusher')->load($pushid);
|
617 |
-
|
618 |
-
$sent=$pusher->getSent();
|
619 |
-
|
620 |
-
if($sent==1){
|
621 |
-
echo json_encode(array('success'=>false,'message'=>'push is in process'));
|
622 |
-
die;
|
623 |
-
}elseif($sent==2){
|
624 |
-
echo json_encode(array('success'=>false,'message'=>'push was already sent'));
|
625 |
-
die;
|
626 |
-
}else{
|
627 |
-
$pusher->setSent(1);
|
628 |
-
|
629 |
-
$pusher->save();
|
630 |
-
}
|
631 |
-
|
632 |
-
$offset = $pusher->getoffset();
|
633 |
-
|
634 |
-
$count = 100;
|
635 |
-
|
636 |
-
$storeId=$pusher->getstore_id();
|
637 |
-
|
638 |
-
$to_send = $pusher->getto_send();
|
639 |
-
|
640 |
-
$total_batches = $pusher->gettotal_batches();
|
641 |
-
|
642 |
-
$catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
|
643 |
-
|
644 |
-
$xml=$catalogModel->renderCatalogXml($offset,$count,$storeId,'','','');
|
645 |
-
|
646 |
-
$url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
|
647 |
-
|
648 |
-
// setting post data and command url
|
649 |
-
$data['uuid'] = $helper->getUUID();
|
650 |
-
$data['site_url'] = $url;
|
651 |
-
$data['store_id'] = $storeId;
|
652 |
-
$data['authentication_key'] = $helper->getKey();
|
653 |
-
$data['total_batches'] = $total_batches;
|
654 |
-
$data['batch_number'] = $pusher->getbatch_number();
|
655 |
-
|
656 |
-
if ($offset+$count > $to_send) {
|
657 |
-
$data['is_last'] = 1;
|
658 |
-
|
659 |
-
$count=$to_send-$offset;
|
660 |
-
// error_log('IS LAST ' . $data['is_last']);
|
661 |
-
}
|
662 |
-
|
663 |
-
$data['products'] = $xml;
|
664 |
-
|
665 |
-
$server_url = $helper->getServerUrl();
|
666 |
-
$cmd_url = $server_url . '/magento_fetch_products';
|
667 |
-
|
668 |
-
// sending products
|
669 |
-
$res2 = $helper->sendPostCurl($cmd_url, $data);
|
670 |
-
|
671 |
-
unset($data['products']);
|
672 |
-
|
673 |
-
Mage::log(print_r($data,true), null, 'autocomplete.log',true);
|
674 |
-
Mage::log(print_r($res2,true), null, 'autocomplete.log',true);
|
675 |
-
|
676 |
-
if($res2=='ok'){
|
677 |
-
$pusher->setSent(2);
|
678 |
-
|
679 |
-
$pusher->save();
|
680 |
-
|
681 |
-
$nextPushId=$helper->getPushId();
|
682 |
-
|
683 |
-
$nextPushUrl='';
|
684 |
-
|
685 |
-
if($nextPushId!=''){
|
686 |
-
$nextPushUrl=$helper->getPushUrl($nextPushId);
|
687 |
-
}
|
688 |
-
|
689 |
-
$totalPushes= Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->count();
|
690 |
-
|
691 |
-
$updatedStatus='Syncing: push '.$nextPushId.'/'.$totalPushes;
|
692 |
-
|
693 |
-
$updatedSuccessStatus='Successfully synced '.$count.' products';
|
694 |
-
|
695 |
-
echo json_encode(
|
696 |
-
array(
|
697 |
-
'success'=>true,
|
698 |
-
'updatedStatus'=>$updatedStatus,
|
699 |
-
'updatedSuccessStatus'=>$updatedSuccessStatus,
|
700 |
-
'message'=>'',
|
701 |
-
'nextPushUrl'=>$nextPushUrl,
|
702 |
-
'count'=>$count
|
703 |
-
)
|
704 |
-
);
|
705 |
-
|
706 |
-
die;
|
707 |
-
}else{
|
708 |
-
echo json_encode(array('success'=>false,'message'=>$res2));
|
709 |
-
die;
|
710 |
-
}
|
711 |
-
}
|
712 |
-
|
713 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* InstantSearchPlus (Autosuggest)
|
4 |
+
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
*
|
12 |
+
* @category Mage
|
13 |
+
* @package InstantSearchPlus
|
14 |
+
* @copyright Copyright (c) 2014 Fast Simon (http://www.instantsearchplus.com)
|
15 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
16 |
+
*/
|
17 |
+
class Autocompleteplus_Autosuggest_ProductsController extends Mage_Core_Controller_Front_Action
|
18 |
+
{
|
19 |
+
protected $_storeId;
|
20 |
+
const MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION = 250;
|
21 |
+
|
22 |
+
public function sendAction(){
|
23 |
+
set_time_limit (1800);
|
24 |
+
|
25 |
+
$post = $this->getRequest()->getParams();
|
26 |
+
|
27 |
+
$startInd = $post['offset'];
|
28 |
+
|
29 |
+
$count = $post['count'];
|
30 |
+
|
31 |
+
$storeId=isset($post['store']) ? $post['store'] : '';
|
32 |
+
if ($storeId == ''){
|
33 |
+
$storeId=isset($post['store_id']) ? $post['store_id'] : '';
|
34 |
+
}
|
35 |
+
|
36 |
+
$orders=isset($post['orders']) ? $post['orders'] : '';
|
37 |
+
|
38 |
+
$month_interval=isset($post['month_interval']) ? $post['month_interval'] : '';
|
39 |
+
|
40 |
+
$checksum=isset($post['checksum']) ? $post['checksum'] : '';
|
41 |
+
|
42 |
+
$catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
|
43 |
+
|
44 |
+
$xml=$catalogModel->renderCatalogXml($startInd,$count,$storeId,$orders,$month_interval,$checksum);
|
45 |
+
|
46 |
+
header('Content-type: text/xml');
|
47 |
+
echo $xml;
|
48 |
+
die;
|
49 |
+
}
|
50 |
+
|
51 |
+
public function sendupdatedAction(){
|
52 |
+
|
53 |
+
date_default_timezone_set('Asia/Jerusalem');
|
54 |
+
|
55 |
+
set_time_limit (1800);
|
56 |
+
|
57 |
+
$post = $this->getRequest()->getParams();
|
58 |
+
|
59 |
+
$count = $post['count'];
|
60 |
+
|
61 |
+
if(!isset($post['from'])){
|
62 |
+
$returnArr=array(
|
63 |
+
'status'=>'failure',
|
64 |
+
'error_code'=>'767',
|
65 |
+
'error_details'=>'The "from" parameter is mandatory'
|
66 |
+
);
|
67 |
+
echo json_encode($returnArr);
|
68 |
+
die;
|
69 |
+
}
|
70 |
+
$from = $post['from'];
|
71 |
+
|
72 |
+
if(isset($post['to'])){
|
73 |
+
$to = $post['to'];
|
74 |
+
}else{
|
75 |
+
$to = strtotime('now');
|
76 |
+
}
|
77 |
+
|
78 |
+
$storeId='';
|
79 |
+
|
80 |
+
if(isset($post['store_id'])){
|
81 |
+
$storeId = $post['store_id'];
|
82 |
+
}
|
83 |
+
|
84 |
+
$catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
|
85 |
+
|
86 |
+
$xml=$catalogModel->renderUpdatesCatalogXml($count,$from,$to,$storeId);
|
87 |
+
|
88 |
+
header('Content-type: text/xml');
|
89 |
+
echo $xml;
|
90 |
+
die;
|
91 |
+
|
92 |
+
}
|
93 |
+
|
94 |
+
private function __checkAccess(){
|
95 |
+
|
96 |
+
$post = $this->getRequest()->getParams();
|
97 |
+
|
98 |
+
$key=Mage::getModel('autocompleteplus_autosuggest/observer')->getUUID();
|
99 |
+
|
100 |
+
if(isset($post['key'])&&$post['key']==$key){
|
101 |
+
return true;
|
102 |
+
}else{
|
103 |
+
return false;
|
104 |
+
}
|
105 |
+
|
106 |
+
}
|
107 |
+
|
108 |
+
public function checkinstallAction(){
|
109 |
+
|
110 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
111 |
+
|
112 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
113 |
+
|
114 |
+
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
115 |
+
|
116 |
+
$sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
|
117 |
+
|
118 |
+
$licenseData=$read->fetchAll($sql);
|
119 |
+
|
120 |
+
$key=$licenseData[0]['licensekey'];
|
121 |
+
|
122 |
+
if(strlen($key)>0&&$key!='failed'){
|
123 |
+
echo 'the key exists';
|
124 |
+
}else{
|
125 |
+
echo 'no key inside';
|
126 |
+
}
|
127 |
+
|
128 |
+
}
|
129 |
+
|
130 |
+
public function versAction(){
|
131 |
+
$mage = Mage::getVersion();
|
132 |
+
$ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
|
133 |
+
try{
|
134 |
+
$num_of_products = Mage::getModel('catalog/product')->getCollection()
|
135 |
+
->addStoreFilter(Mage::app()->getStore()->getStoreId())
|
136 |
+
->getSize();
|
137 |
+
} catch (Exception $e){
|
138 |
+
$num_of_products = -1;
|
139 |
+
}
|
140 |
+
|
141 |
+
if (method_exists('Mage' , 'getEdition')){
|
142 |
+
$edition = Mage::getEdition();
|
143 |
+
} else {
|
144 |
+
$edition = 'Community';
|
145 |
+
}
|
146 |
+
|
147 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
148 |
+
$uuid = $helper->getUUID();
|
149 |
+
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
150 |
+
$store_id = Mage::app()->getStore()->getStoreId();
|
151 |
+
|
152 |
+
$result = array('mage' => $mage,
|
153 |
+
'ext' => $ext,
|
154 |
+
'num_of_products' => $num_of_products,
|
155 |
+
'edition' => $edition,
|
156 |
+
'uuid' => $uuid,
|
157 |
+
'site_url' => $site_url,
|
158 |
+
'store_id' => $store_id
|
159 |
+
);
|
160 |
+
|
161 |
+
$post = $this->getRequest()->getParams();
|
162 |
+
|
163 |
+
if (array_key_exists('modules', $post))
|
164 |
+
$get_modules = $post['modules'];
|
165 |
+
else
|
166 |
+
$get_modules = false;
|
167 |
+
if ($get_modules){
|
168 |
+
try{
|
169 |
+
$modules_array = array();
|
170 |
+
foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module) {
|
171 |
+
if ($module->codePool != 'core' && $module->active == 'true'){
|
172 |
+
$modules_array[$name] = $module;
|
173 |
+
}
|
174 |
+
}
|
175 |
+
} catch (Exception $e){
|
176 |
+
$modules_array = array();
|
177 |
+
}
|
178 |
+
$result['modules'] = $modules_array;
|
179 |
+
}
|
180 |
+
echo json_encode($result);die;
|
181 |
+
}
|
182 |
+
|
183 |
+
public function getNumOfProductsAction()
|
184 |
+
{
|
185 |
+
$catalogReport = Mage::getModel('autocompleteplus_autosuggest/catalogreport');
|
186 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
187 |
+
|
188 |
+
$result = array('num_of_products' => $catalogReport->getEnabledProductsCount(),
|
189 |
+
'num_of_disabled_products' => $catalogReport->getDisabledProductsCount(),
|
190 |
+
'num_of_searchable_products' => $catalogReport->getSearchableProductsCount(),
|
191 |
+
'num_of_searchable_products2' => $catalogReport->getSearchableProducts2Count(),
|
192 |
+
'uuid' => $helper->getUUID(),
|
193 |
+
'site_url' => $helper->getConfigDataByFullPath('web/unsecure/base_url'),
|
194 |
+
'store_id' => $catalogReport->getCurrentStoreId()
|
195 |
+
);
|
196 |
+
|
197 |
+
$this->getResponse()->setHeader('Content-type', 'application/json');
|
198 |
+
$this->getResponse()->setBody(json_encode($result));
|
199 |
+
}
|
200 |
+
|
201 |
+
public function getConflictAction(){
|
202 |
+
$post = $this->getRequest()->getParams();
|
203 |
+
if (array_key_exists('all', $post))
|
204 |
+
$get_all_conflicts = $post['all'];
|
205 |
+
else
|
206 |
+
$get_all_conflicts = false;
|
207 |
+
|
208 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
209 |
+
if ($get_all_conflicts){
|
210 |
+
$result = $helper->getExtensionConflict(true);
|
211 |
+
}else{
|
212 |
+
$result = $helper->getExtensionConflict();
|
213 |
+
}
|
214 |
+
echo json_encode($result);die;
|
215 |
+
}
|
216 |
+
|
217 |
+
public function getstoresAction(){
|
218 |
+
|
219 |
+
$helper=Mage::helper('autocompleteplus_autosuggest');
|
220 |
+
|
221 |
+
echo $helper->getMultiStoreDataJson();
|
222 |
+
die;
|
223 |
+
}
|
224 |
+
|
225 |
+
public function updateemailAction(){
|
226 |
+
|
227 |
+
$helper=Mage::helper('autocompleteplus_autosuggest');
|
228 |
+
|
229 |
+
$data = $this->getRequest()->getPost();
|
230 |
+
|
231 |
+
$email=$data['email'];
|
232 |
+
$uuid=$helper->getUUID();
|
233 |
+
|
234 |
+
Mage::getModel('core/config')->saveConfig('autocompleteplus/config/store_email',$email);
|
235 |
+
|
236 |
+
$params=array(
|
237 |
+
'uuid'=>$uuid,
|
238 |
+
'email'=>$email
|
239 |
+
);
|
240 |
+
|
241 |
+
$command="http://magento.autocompleteplus.com/ext_update_email";
|
242 |
+
|
243 |
+
$res=$helper->sendPostCurl($command,$params);
|
244 |
+
|
245 |
+
$result=json_decode($res);
|
246 |
+
|
247 |
+
if($result->status=='OK'){
|
248 |
+
echo 'Your email address was updated!';
|
249 |
+
}
|
250 |
+
}
|
251 |
+
|
252 |
+
public function updatesitemapAction(){
|
253 |
+
|
254 |
+
$helper=Mage::helper('autocompleteplus_autosuggest');
|
255 |
+
|
256 |
+
$key=$helper->getUUID();
|
257 |
+
|
258 |
+
$url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
|
259 |
+
|
260 |
+
if($key!='InstallFailedUUID' && $key!='failed'){
|
261 |
+
|
262 |
+
$stemapUrl='Sitemap:http://magento.instantsearchplus.com/ext_sitemap?u='.$key.PHP_EOL;
|
263 |
+
|
264 |
+
$robotsPath=Mage::getBaseDir().DS.'robots.txt';
|
265 |
+
|
266 |
+
$write=false;
|
267 |
+
|
268 |
+
if(file_exists($robotsPath)){
|
269 |
+
if( strpos(file_get_contents($robotsPath),$stemapUrl) == false) {
|
270 |
+
$write=true;
|
271 |
+
}
|
272 |
+
}else{
|
273 |
+
|
274 |
+
if(is_writable(Mage::getBaseDir())){
|
275 |
+
|
276 |
+
//create robots sitemap
|
277 |
+
file_put_contents($robotsPath,$stemapUrl);
|
278 |
+
}else{
|
279 |
+
|
280 |
+
//write message that directory is not writteble
|
281 |
+
$command="http://magento.autocompleteplus.com/install_error";
|
282 |
+
|
283 |
+
$data=array();
|
284 |
+
$data['site']=$url;
|
285 |
+
$data['msg']='Directory '.Mage::getBaseDir().' is not writable.';
|
286 |
+
$res=$helper->sendPostCurl($command,$data);
|
287 |
+
}
|
288 |
+
}
|
289 |
+
|
290 |
+
if($write){
|
291 |
+
if(is_writable($robotsPath)){
|
292 |
+
|
293 |
+
//append sitemap
|
294 |
+
file_put_contents($robotsPath, $stemapUrl, FILE_APPEND | LOCK_EX);
|
295 |
+
}else{
|
296 |
+
//write message that file is not writteble
|
297 |
+
$command="http://magento.autocompleteplus.com/install_error";
|
298 |
+
|
299 |
+
$data=array();
|
300 |
+
$data['site']=$url;
|
301 |
+
$data['msg']='File '.$robotsPath.' is not writable.';
|
302 |
+
$res=$helper->sendPostCurl($command,$data);
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
protected function _setUUID($key){
|
310 |
+
|
311 |
+
try{
|
312 |
+
|
313 |
+
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
314 |
+
|
315 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
316 |
+
|
317 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
318 |
+
|
319 |
+
$tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
|
320 |
+
|
321 |
+
if(!$tblExist){return;}
|
322 |
+
|
323 |
+
$sqlFetch ='SELECT * FROM '. $_tableprefix.'autocompleteplus_config WHERE id = 1';
|
324 |
+
|
325 |
+
$updates=$write->fetchAll($sqlFetch);
|
326 |
+
|
327 |
+
if($updates&&count($updates)!=0){
|
328 |
+
|
329 |
+
$sql='UPDATE '. $_tableprefix.'autocompleteplus_config SET licensekey=? WHERE id = 1';
|
330 |
+
|
331 |
+
$write->query($sql, array($key));
|
332 |
+
|
333 |
+
}else{
|
334 |
+
|
335 |
+
$sql='INSERT INTO '. $_tableprefix.'autocompleteplus_config (licensekey) VALUES (?)';
|
336 |
+
|
337 |
+
$write->query($sql, array($key));
|
338 |
+
|
339 |
+
}
|
340 |
+
|
341 |
+
|
342 |
+
}catch(Exception $e){
|
343 |
+
Mage::log($e->getMessage(),null,'autocompleteplus.log');
|
344 |
+
}
|
345 |
+
|
346 |
+
}
|
347 |
+
|
348 |
+
public function getIspUuidAction(){
|
349 |
+
|
350 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
351 |
+
|
352 |
+
echo $helper->getUUID();
|
353 |
+
}
|
354 |
+
|
355 |
+
public function geterrormessageAction(){
|
356 |
+
|
357 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
358 |
+
|
359 |
+
echo $helper->getErrormessage();
|
360 |
+
}
|
361 |
+
|
362 |
+
public function setIspUuidAction(){
|
363 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
364 |
+
$url_domain = 'http://magento.instantsearchplus.com/update_uuid';
|
365 |
+
$storeId = Mage::app()->getStore()->getStoreId();
|
366 |
+
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
367 |
+
$url = $url_domain . '?store_id=' . $storeId . '&site_url=' . $site_url;
|
368 |
+
|
369 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
370 |
+
$resp = $helper->sendCurl($url);
|
371 |
+
$response_json = json_decode($resp);
|
372 |
+
|
373 |
+
if (array_key_exists('uuid', $response_json)){
|
374 |
+
if (strlen($response_json->uuid) == 36 && substr_count($response_json->uuid, '-') == 4){
|
375 |
+
$this->_setUUID($response_json->uuid);
|
376 |
+
}
|
377 |
+
}
|
378 |
+
}
|
379 |
+
|
380 |
+
public function checkDeletedAction(){
|
381 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
382 |
+
if (!$helper->isChecksumTableExists()){
|
383 |
+
return;
|
384 |
+
}
|
385 |
+
$time_stamp = time();
|
386 |
+
|
387 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
388 |
+
$table_prefix = (string)Mage::getConfig()->getTablePrefix();
|
389 |
+
|
390 |
+
$post = $this->getRequest()->getParams();
|
391 |
+
if (array_key_exists('store_id', $post)){
|
392 |
+
$store_id = $post['store_id'];
|
393 |
+
}else{
|
394 |
+
$store_id = Mage::app()->getStore()->getStoreId(); // default
|
395 |
+
}
|
396 |
+
|
397 |
+
$sql_fetch = 'SELECT identifier FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE store_id=?';
|
398 |
+
$updates = $read->fetchPairs($sql_fetch, array($store_id)); // empty array if fails
|
399 |
+
if (empty($updates)){
|
400 |
+
return;
|
401 |
+
}
|
402 |
+
|
403 |
+
$checksum_ids = array_keys($updates); // array of all checksum table identifiers
|
404 |
+
$collection = Mage::getResourceModel('catalog/product_collection');
|
405 |
+
$collection->addFieldToFilter('entity_id',array('in'=>$checksum_ids));
|
406 |
+
$found_ids = $collection->getAllIds();
|
407 |
+
|
408 |
+
$removed_products_list = array_diff($checksum_ids, $found_ids); // list of identifiers that are not present in the store (removed at some point)
|
409 |
+
$removed_ids = array();
|
410 |
+
|
411 |
+
// removing non-existing identifiers from checksum table
|
412 |
+
if (!empty($removed_products_list)){
|
413 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
414 |
+
$sql_delete = 'DELETE FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier IN (' . implode(',', $removed_products_list) . ')';
|
415 |
+
$write->query($sql_delete);
|
416 |
+
|
417 |
+
foreach ($removed_products_list as $product_id){
|
418 |
+
$helper->deleteProductFromTables($read, $write, $table_prefix, $product_id, $store_id);
|
419 |
+
$removed_ids[] = $product_id;
|
420 |
+
}
|
421 |
+
}
|
422 |
+
|
423 |
+
$args = array('removed_ids' => $removed_ids,
|
424 |
+
'uuid' => $helper->getUUID(),
|
425 |
+
'store_id' => $store_id,
|
426 |
+
'latency' => time() - $time_stamp, // seconds
|
427 |
+
);
|
428 |
+
echo json_encode($args); // returning the summary
|
429 |
+
}
|
430 |
+
|
431 |
+
public function checksumAction(){
|
432 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
433 |
+
|
434 |
+
$checksum_server = $helper->getServerUrl();
|
435 |
+
if (!$helper->isChecksumTableExists()){
|
436 |
+
$helper->ispErrorLog('checksum table not exist');
|
437 |
+
exit(json_encode(array('status' => 'checksum table not exist')));
|
438 |
+
}
|
439 |
+
$max_exe_time = -1;
|
440 |
+
|
441 |
+
$post = $this->getRequest()->getParams();
|
442 |
+
if (array_key_exists('store_id', $post)){
|
443 |
+
$store_id = $post['store_id'];
|
444 |
+
}else{
|
445 |
+
$store_id = Mage::app()->getStore()->getStoreId(); // default
|
446 |
+
}
|
447 |
+
if (array_key_exists('count', $post)){
|
448 |
+
$count = $post['count'];
|
449 |
+
}else{
|
450 |
+
$count = self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION; // default
|
451 |
+
}
|
452 |
+
if (array_key_exists('offset', $post))
|
453 |
+
$start_index = $post['offset'];
|
454 |
+
else
|
455 |
+
$start_index = 0; // default
|
456 |
+
if (array_key_exists('timeout', $post))
|
457 |
+
$php_timeout = $post['timeout'];
|
458 |
+
else
|
459 |
+
$php_timeout = -1; // default
|
460 |
+
if (array_key_exists('is_single', $post))
|
461 |
+
$is_single = $post['is_single'];
|
462 |
+
else
|
463 |
+
$is_single = 0; // default
|
464 |
+
|
465 |
+
if ($count > self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION && $php_timeout != -1){
|
466 |
+
$max_exe_time = ini_get('max_execution_time');
|
467 |
+
ini_set('max_execution_time', $php_timeout); // 1 hour ~ 60*60
|
468 |
+
}
|
469 |
+
|
470 |
+
$uuid = $helper->getUUID();
|
471 |
+
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
472 |
+
|
473 |
+
$collection = Mage::getModel('catalog/product')->getCollection();
|
474 |
+
if ($store_id){
|
475 |
+
$collection->addStoreFilter($store_id);
|
476 |
+
}
|
477 |
+
$num_of_products = $collection->getSize();
|
478 |
+
|
479 |
+
if ($count + $start_index > $num_of_products){
|
480 |
+
$count = $num_of_products - $start_index;
|
481 |
+
}
|
482 |
+
|
483 |
+
// sending log to the server
|
484 |
+
$log_msg = 'Update checksum is starting...';
|
485 |
+
$log_msg .= (' number of products in this store: ' . $num_of_products . ' | from: ' . $start_index . ', to: ' . ($start_index + $count));
|
486 |
+
$server_url = $checksum_server . '/magento_logging_record';
|
487 |
+
$request = $server_url . '?uuid=' . $uuid . '&site_url=' . $site_url . '&msg=' . urlencode($log_msg);
|
488 |
+
if ($store_id)
|
489 |
+
$request .= '&store_id=' . $store_id;
|
490 |
+
$resp = $helper->sendCurl($request);
|
491 |
+
|
492 |
+
$start_time = time();
|
493 |
+
$num_of_updated_checksum = 0;
|
494 |
+
if($count > self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION){
|
495 |
+
$iter = $start_index;
|
496 |
+
while ($iter < $count){
|
497 |
+
// start updating the checksum table if needed
|
498 |
+
$num_of_updated_checksum += $helper->compareProductsChecksum($iter, self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION, $store_id);
|
499 |
+
$iter += self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION;
|
500 |
+
}
|
501 |
+
} else {
|
502 |
+
// start updating the checksum table if needed
|
503 |
+
$num_of_updated_checksum = $helper->compareProductsChecksum($start_index, $count, $store_id);
|
504 |
+
}
|
505 |
+
|
506 |
+
$process_time = time() - $start_time;
|
507 |
+
// sending confirmation/summary to the server
|
508 |
+
$args = array( 'uuid' => $uuid,
|
509 |
+
'site_url' => $site_url,
|
510 |
+
'store_id' => $store_id,
|
511 |
+
'updated_checksum' => $num_of_updated_checksum,
|
512 |
+
'total_checksum' => $count,
|
513 |
+
'num_of_products' => $num_of_products,
|
514 |
+
'start_index' => $start_index,
|
515 |
+
'end_index' => $start_index + $count,
|
516 |
+
'count' => $count,
|
517 |
+
'ext_version' => (string)Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version,
|
518 |
+
'mage_version' => Mage::getVersion(),
|
519 |
+
'latency' => $process_time, // seconds
|
520 |
+
);
|
521 |
+
if ($is_single)
|
522 |
+
$args['is_single'] = 1;
|
523 |
+
echo json_encode($args); // returning the summary
|
524 |
+
|
525 |
+
$resp = $helper->sendCurl($checksum_server . '/magento_checksum_iterator?' . http_build_query($args));
|
526 |
+
|
527 |
+
if ($max_exe_time != -1){ // restore php max execution time
|
528 |
+
ini_set('max_execution_time', $max_exe_time);
|
529 |
+
}
|
530 |
+
}
|
531 |
+
|
532 |
+
public function connectionAction(){
|
533 |
+
exit('1');
|
534 |
+
}
|
535 |
+
|
536 |
+
public function changeSerpAction(){
|
537 |
+
try {
|
538 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
539 |
+
$site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
540 |
+
define("SOAP_WSDL", $site_url . '/api/?wsdl');
|
541 |
+
define("SOAP_USER", "instant_search");
|
542 |
+
define("SOAP_PASS", "Rilb@kped3");
|
543 |
+
|
544 |
+
$client = new SoapClient(SOAP_WSDL, array('trace' => 1, 'cache_wsdl' => 0));
|
545 |
+
$session = $client->login(SOAP_USER, SOAP_PASS);
|
546 |
+
|
547 |
+
$post = $this->getRequest()->getParams();
|
548 |
+
if (array_key_exists('new_serp', $post)){
|
549 |
+
$is_new_serp = $post['new_serp'];
|
550 |
+
}else{
|
551 |
+
$is_new_serp = '0'; // default
|
552 |
+
}
|
553 |
+
|
554 |
+
if (array_key_exists('store_id', $post)){
|
555 |
+
$store_id = $post['store_id'];
|
556 |
+
$scope_name = 'stores';
|
557 |
+
}else{ // default
|
558 |
+
$store_id = '0';
|
559 |
+
$scope_name = 'default';
|
560 |
+
}
|
561 |
+
|
562 |
+
try {
|
563 |
+
|
564 |
+
if ($is_new_serp == 'status'){
|
565 |
+
$current_state = $client->call($session, 'autocompleteplus_autosuggest.getLayeredSearchConfig', array($store_id));
|
566 |
+
echo json_encode(array('current_status' => $current_state));
|
567 |
+
return;
|
568 |
+
}
|
569 |
+
|
570 |
+
if ($is_new_serp == '1'){
|
571 |
+
$status = $client->call($session, 'autocompleteplus_autosuggest.setLayeredSearchOn', array($scope_name, $store_id));
|
572 |
+
} else {
|
573 |
+
$status = $client->call($session, 'autocompleteplus_autosuggest.setLayeredSearchOff', array($scope_name, $store_id));
|
574 |
+
}
|
575 |
+
$new_state= $client->call($session, 'autocompleteplus_autosuggest.getLayeredSearchConfig', array($store_id));
|
576 |
+
|
577 |
+
$resp = array('request_state' => $is_new_serp,
|
578 |
+
'new_state' => $new_state,
|
579 |
+
'site_url' => $site_url,
|
580 |
+
'status' => $status
|
581 |
+
);
|
582 |
+
echo json_encode($resp);
|
583 |
+
|
584 |
+
} catch (SoapFault $exception) {
|
585 |
+
echo json_encode(array('status' => 'exception: ' . print_r($exception, true)));
|
586 |
+
return;
|
587 |
+
}
|
588 |
+
|
589 |
+
} catch (Exception $e){
|
590 |
+
echo json_encode(array('status' => 'exception: ' . print_r($e, true)));
|
591 |
+
throw $e;
|
592 |
+
}
|
593 |
+
}
|
594 |
+
|
595 |
+
public function pushbulkAction(){
|
596 |
+
|
597 |
+
set_time_limit (1800);
|
598 |
+
|
599 |
+
$post = $this->getRequest()->getParams();
|
600 |
+
|
601 |
+
// $enabled= Mage::getStoreConfig('autocompleteplus/config/enabled');
|
602 |
+
// if($enabled=='0'){
|
603 |
+
// die('The user has disabled autocompleteplus.');
|
604 |
+
// }
|
605 |
+
|
606 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
607 |
+
|
608 |
+
if(!isset($post['pushid'])){
|
609 |
+
|
610 |
+
echo json_encode(array('success'=>false,'message'=>'Missing pushid!'));
|
611 |
+
die;
|
612 |
+
}
|
613 |
+
|
614 |
+
$pushid = $post['pushid'];
|
615 |
+
|
616 |
+
$pusher = Mage::getModel('autocompleteplus_autosuggest/pusher')->load($pushid);
|
617 |
+
|
618 |
+
$sent=$pusher->getSent();
|
619 |
+
|
620 |
+
if($sent==1){
|
621 |
+
echo json_encode(array('success'=>false,'message'=>'push is in process'));
|
622 |
+
die;
|
623 |
+
}elseif($sent==2){
|
624 |
+
echo json_encode(array('success'=>false,'message'=>'push was already sent'));
|
625 |
+
die;
|
626 |
+
}else{
|
627 |
+
$pusher->setSent(1);
|
628 |
+
|
629 |
+
$pusher->save();
|
630 |
+
}
|
631 |
+
|
632 |
+
$offset = $pusher->getoffset();
|
633 |
+
|
634 |
+
$count = 100;
|
635 |
+
|
636 |
+
$storeId=$pusher->getstore_id();
|
637 |
+
|
638 |
+
$to_send = $pusher->getto_send();
|
639 |
+
|
640 |
+
$total_batches = $pusher->gettotal_batches();
|
641 |
+
|
642 |
+
$catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
|
643 |
+
|
644 |
+
$xml=$catalogModel->renderCatalogXml($offset,$count,$storeId,'','','');
|
645 |
+
|
646 |
+
$url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
|
647 |
+
|
648 |
+
// setting post data and command url
|
649 |
+
$data['uuid'] = $helper->getUUID();
|
650 |
+
$data['site_url'] = $url;
|
651 |
+
$data['store_id'] = $storeId;
|
652 |
+
$data['authentication_key'] = $helper->getKey();
|
653 |
+
$data['total_batches'] = $total_batches;
|
654 |
+
$data['batch_number'] = $pusher->getbatch_number();
|
655 |
+
|
656 |
+
if ($offset+$count > $to_send) {
|
657 |
+
$data['is_last'] = 1;
|
658 |
+
|
659 |
+
$count=$to_send-$offset;
|
660 |
+
// error_log('IS LAST ' . $data['is_last']);
|
661 |
+
}
|
662 |
+
|
663 |
+
$data['products'] = $xml;
|
664 |
+
|
665 |
+
$server_url = $helper->getServerUrl();
|
666 |
+
$cmd_url = $server_url . '/magento_fetch_products';
|
667 |
+
|
668 |
+
// sending products
|
669 |
+
$res2 = $helper->sendPostCurl($cmd_url, $data);
|
670 |
+
|
671 |
+
unset($data['products']);
|
672 |
+
|
673 |
+
Mage::log(print_r($data,true), null, 'autocomplete.log',true);
|
674 |
+
Mage::log(print_r($res2,true), null, 'autocomplete.log',true);
|
675 |
+
|
676 |
+
if($res2=='ok'){
|
677 |
+
$pusher->setSent(2);
|
678 |
+
|
679 |
+
$pusher->save();
|
680 |
+
|
681 |
+
$nextPushId=$helper->getPushId();
|
682 |
+
|
683 |
+
$nextPushUrl='';
|
684 |
+
|
685 |
+
if($nextPushId!=''){
|
686 |
+
$nextPushUrl=$helper->getPushUrl($nextPushId);
|
687 |
+
}
|
688 |
+
|
689 |
+
$totalPushes= Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->count();
|
690 |
+
|
691 |
+
$updatedStatus='Syncing: push '.$nextPushId.'/'.$totalPushes;
|
692 |
+
|
693 |
+
$updatedSuccessStatus='Successfully synced '.$count.' products';
|
694 |
+
|
695 |
+
echo json_encode(
|
696 |
+
array(
|
697 |
+
'success'=>true,
|
698 |
+
'updatedStatus'=>$updatedStatus,
|
699 |
+
'updatedSuccessStatus'=>$updatedSuccessStatus,
|
700 |
+
'message'=>'',
|
701 |
+
'nextPushUrl'=>$nextPushUrl,
|
702 |
+
'count'=>$count
|
703 |
+
)
|
704 |
+
);
|
705 |
+
|
706 |
+
die;
|
707 |
+
}else{
|
708 |
+
echo json_encode(array('success'=>false,'message'=>$res2));
|
709 |
+
die;
|
710 |
+
}
|
711 |
+
}
|
712 |
+
|
713 |
+
}
|
app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsbyidController.php
CHANGED
@@ -1,71 +1,71 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* InstantSearchPlus (Autosuggest)
|
4 |
-
*
|
5 |
-
* NOTICE OF LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
-
* that is available through the world-wide-web at this URL:
|
9 |
-
* http://opensource.org/licenses/osl-3.0.php
|
10 |
-
*
|
11 |
-
* @category Mage
|
12 |
-
* @package InstantSearchPlus
|
13 |
-
* @copyright Copyright (c) 2014 Fast Simon (http://www.instantsearchplus.com)
|
14 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
-
*/
|
16 |
-
class Autocompleteplus_Autosuggest_ProductsbyidController extends Mage_Core_Controller_Front_Action
|
17 |
-
{
|
18 |
-
const PHP_SCRIPT_TIMEOUT = 1800;
|
19 |
-
const MISSING_PARAMETER = 767;
|
20 |
-
const STATUS_FAILURE = 'failure';
|
21 |
-
|
22 |
-
public function preDispatch()
|
23 |
-
{
|
24 |
-
parent::preDispatch();
|
25 |
-
set_time_limit(self::PHP_SCRIPT_TIMEOUT);
|
26 |
-
}
|
27 |
-
|
28 |
-
public function getbyidAction()
|
29 |
-
{
|
30 |
-
$request = $this->getRequest();
|
31 |
-
$response = $this->getResponse();
|
32 |
-
$storeId = $request->getParam('store', 1);
|
33 |
-
$id = $request->getParam('id');
|
34 |
-
|
35 |
-
if(!$id){
|
36 |
-
$returnArr = array(
|
37 |
-
'status' => self::STATUS_FAILURE,
|
38 |
-
'error_code' => self::MISSING_PARAMETER,
|
39 |
-
'error_details' => $this->__('The "id" parameter is mandatory')
|
40 |
-
);
|
41 |
-
$response->setHeader('Content-type', 'application/json');
|
42 |
-
$response->setHttpResponseCode(400);
|
43 |
-
$response->setBody(json_encode($returnArr));
|
44 |
-
return;
|
45 |
-
}
|
46 |
-
|
47 |
-
$ids = explode(',', $id);
|
48 |
-
$catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
|
49 |
-
$xml = $catalogModel->renderCatalogByIds($ids, $storeId);
|
50 |
-
|
51 |
-
$response->clearHeaders();
|
52 |
-
$response->setHeader('Content-type', 'text/xml');
|
53 |
-
$response->setBody($xml);
|
54 |
-
}
|
55 |
-
|
56 |
-
public function getfromidAction()
|
57 |
-
{
|
58 |
-
$request = $this->getRequest();
|
59 |
-
$response = $this->getResponse();
|
60 |
-
$fromId = $request->getParam('id', 0);
|
61 |
-
$storeId = $request->getParam('store', 1);
|
62 |
-
$count = $request->getParam('count', 100);
|
63 |
-
|
64 |
-
$catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
|
65 |
-
$xml = $catalogModel->renderCatalogFromIds($count, $fromId, $storeId);
|
66 |
-
|
67 |
-
$response->clearHeaders();
|
68 |
-
$response->setHeader('Content-type', 'text/xml');
|
69 |
-
$response->setBody($xml);
|
70 |
-
}
|
71 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* InstantSearchPlus (Autosuggest)
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is available through the world-wide-web at this URL:
|
9 |
+
* http://opensource.org/licenses/osl-3.0.php
|
10 |
+
*
|
11 |
+
* @category Mage
|
12 |
+
* @package InstantSearchPlus
|
13 |
+
* @copyright Copyright (c) 2014 Fast Simon (http://www.instantsearchplus.com)
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
class Autocompleteplus_Autosuggest_ProductsbyidController extends Mage_Core_Controller_Front_Action
|
17 |
+
{
|
18 |
+
const PHP_SCRIPT_TIMEOUT = 1800;
|
19 |
+
const MISSING_PARAMETER = 767;
|
20 |
+
const STATUS_FAILURE = 'failure';
|
21 |
+
|
22 |
+
public function preDispatch()
|
23 |
+
{
|
24 |
+
parent::preDispatch();
|
25 |
+
set_time_limit(self::PHP_SCRIPT_TIMEOUT);
|
26 |
+
}
|
27 |
+
|
28 |
+
public function getbyidAction()
|
29 |
+
{
|
30 |
+
$request = $this->getRequest();
|
31 |
+
$response = $this->getResponse();
|
32 |
+
$storeId = $request->getParam('store', 1);
|
33 |
+
$id = $request->getParam('id');
|
34 |
+
|
35 |
+
if(!$id){
|
36 |
+
$returnArr = array(
|
37 |
+
'status' => self::STATUS_FAILURE,
|
38 |
+
'error_code' => self::MISSING_PARAMETER,
|
39 |
+
'error_details' => $this->__('The "id" parameter is mandatory')
|
40 |
+
);
|
41 |
+
$response->setHeader('Content-type', 'application/json');
|
42 |
+
$response->setHttpResponseCode(400);
|
43 |
+
$response->setBody(json_encode($returnArr));
|
44 |
+
return;
|
45 |
+
}
|
46 |
+
|
47 |
+
$ids = explode(',', $id);
|
48 |
+
$catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
|
49 |
+
$xml = $catalogModel->renderCatalogByIds($ids, $storeId);
|
50 |
+
|
51 |
+
$response->clearHeaders();
|
52 |
+
$response->setHeader('Content-type', 'text/xml');
|
53 |
+
$response->setBody($xml);
|
54 |
+
}
|
55 |
+
|
56 |
+
public function getfromidAction()
|
57 |
+
{
|
58 |
+
$request = $this->getRequest();
|
59 |
+
$response = $this->getResponse();
|
60 |
+
$fromId = $request->getParam('id', 0);
|
61 |
+
$storeId = $request->getParam('store', 1);
|
62 |
+
$count = $request->getParam('count', 100);
|
63 |
+
|
64 |
+
$catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
|
65 |
+
$xml = $catalogModel->renderCatalogFromIds($count, $fromId, $storeId);
|
66 |
+
|
67 |
+
$response->clearHeaders();
|
68 |
+
$response->setHeader('Content-type', 'text/xml');
|
69 |
+
$response->setBody($xml);
|
70 |
+
}
|
71 |
}
|
app/code/local/Autocompleteplus/Autosuggest/controllers/ResultController.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once(Mage::getModuleDir('controllers','Mage_CatalogSearch') . DS . 'ResultController.php');
|
4 |
-
|
5 |
-
class Autocompleteplus_Autosuggest_ResultController extends Mage_CatalogSearch_ResultController
|
6 |
-
{
|
7 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once(Mage::getModuleDir('controllers','Mage_CatalogSearch') . DS . 'ResultController.php');
|
4 |
+
|
5 |
+
class Autocompleteplus_Autosuggest_ResultController extends Mage_CatalogSearch_ResultController
|
6 |
+
{
|
7 |
}
|
app/code/local/Autocompleteplus/Autosuggest/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Autocompleteplus_Autosuggest>
|
5 |
-
<version>2.0.8.
|
6 |
<url>http://autocompleteplus.com/</url>
|
7 |
<modulename>Autocompleteplus_Autosuggest</modulename>
|
8 |
</Autocompleteplus_Autosuggest>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Autocompleteplus_Autosuggest>
|
5 |
+
<version>2.0.8.7</version>
|
6 |
<url>http://autocompleteplus.com/</url>
|
7 |
<modulename>Autocompleteplus_Autosuggest</modulename>
|
8 |
</Autocompleteplus_Autosuggest>
|
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.4-2.0.5.5.php
CHANGED
@@ -3,86 +3,116 @@ $installer = $this;
|
|
3 |
|
4 |
$installer->startSetup();
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
->
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
'
|
47 |
-
|
48 |
-
'
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
'
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
'
|
63 |
-
|
64 |
-
'
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
$installer->getConnection()->dropTable($table->getName());
|
80 |
-
|
81 |
}
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
$installer->getConnection()->createTable($table);
|
86 |
-
|
87 |
$installer->endSetup();
|
88 |
|
3 |
|
4 |
$installer->startSetup();
|
5 |
|
6 |
+
// getEdition exist from version 1.12, LICENSE_EE.txt file only exists in EE edition, we need the condition to work on EE version less then 1.11.x.x
|
7 |
+
if (!method_exists('Mage' , 'getEdition') && file_exists('LICENSE_EE.txt') && method_exists('Mage' , 'getVersion') && version_compare(Mage::getVersion(), '1.10.0.0.', '<') === true){
|
8 |
+
$res=$installer->run("
|
9 |
+
|
10 |
+
DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_pusher')};
|
11 |
+
|
12 |
+
CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_pusher')} (
|
13 |
+
|
14 |
+
`id` INT UNSIGNED NOT NULL auto_increment,
|
15 |
+
|
16 |
+
`store_id` INT UNSIGNED NOT NULL,
|
17 |
+
|
18 |
+
`to_send` INT UNSIGNED NOT NULL,
|
19 |
+
|
20 |
+
`offset` INT UNSIGNED NOT NULL,
|
21 |
+
|
22 |
+
`total_batches` INT UNSIGNED NOT NULL,
|
23 |
+
|
24 |
+
`batch_number` INT UNSIGNED NOT NULL,
|
25 |
+
|
26 |
+
`sent` INT UNSIGNED NOT NULL,
|
27 |
+
|
28 |
+
PRIMARY KEY (`id`)
|
29 |
+
|
30 |
+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
|
31 |
+
|
32 |
+
");
|
33 |
+
} else {
|
34 |
+
$table = $installer->getConnection()->newTable($installer->getTable('autocompleteplus_autosuggest/pusher'))
|
35 |
+
|
36 |
+
->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
37 |
+
|
38 |
+
'identity' => true,
|
39 |
+
|
40 |
+
'unsigned' => true,
|
41 |
+
|
42 |
+
'nullable' => false,
|
43 |
+
|
44 |
+
'primary' => true
|
45 |
+
|
46 |
+
), 'Id')
|
47 |
+
|
48 |
+
->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
49 |
+
|
50 |
+
'nullable' => false,
|
51 |
+
|
52 |
+
'unsigned' => true
|
53 |
+
|
54 |
+
))
|
55 |
+
|
56 |
+
->addColumn('to_send', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
57 |
+
|
58 |
+
'nullable' => false,
|
59 |
+
|
60 |
+
'unsigned' => true
|
61 |
+
|
62 |
+
), 'Amount left to send')
|
63 |
+
|
64 |
+
->addColumn('offset', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
65 |
+
|
66 |
+
'nullable' => false,
|
67 |
+
|
68 |
+
'unsigned' => true
|
69 |
+
|
70 |
+
))
|
71 |
+
|
72 |
+
->addColumn('total_batches', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
73 |
+
|
74 |
+
'nullable' => false,
|
75 |
+
|
76 |
+
'unsigned' => true
|
77 |
+
|
78 |
+
))
|
79 |
+
|
80 |
+
->addColumn('batch_number', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
81 |
+
|
82 |
+
'nullable' => false,
|
83 |
+
|
84 |
+
'unsigned' => true
|
85 |
+
|
86 |
+
))
|
87 |
+
|
88 |
+
->addColumn('sent', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
89 |
+
|
90 |
+
'nullable' => false,
|
91 |
+
|
92 |
+
'unsigned' => true
|
93 |
+
|
94 |
+
));
|
95 |
+
|
96 |
+
/* TODO:
|
97 |
+
* src: http://inchoo.net/magento/delete-test-orders-in-magento/
|
98 |
+
* src: http://magento.stackexchange.com/questions/6752/any-way-to-add-block-on-only-enterprise-editions
|
99 |
+
* if ($executionPath == 'old') {
|
100 |
+
$isTableExists = $connection->showTableStatus($table);
|
101 |
+
} else {
|
102 |
+
$isTableExists = $connection->isTableExists($table);
|
103 |
+
}
|
104 |
+
*/
|
105 |
+
|
106 |
+
if ($installer->getConnection()->isTableExists($table->getName())) {
|
107 |
+
|
108 |
+
$installer->getConnection()->dropTable($table->getName());
|
109 |
+
|
110 |
}
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
$installer->getConnection()->createTable($table);
|
|
|
|
|
115 |
}
|
116 |
|
|
|
|
|
|
|
|
|
117 |
$installer->endSetup();
|
118 |
|
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.6.1-2.0.6.4.php
CHANGED
@@ -12,13 +12,24 @@ $storeMail = $helper->getConfigDataByFullPath('autocompleteplus/config/store_ema
|
|
12 |
$multistoreJson = $helper->getMultiStoreDataJson();
|
13 |
|
14 |
// Checking config table values
|
15 |
-
|
16 |
-
|
17 |
-
$
|
|
|
|
|
|
|
|
|
|
|
18 |
} else {
|
19 |
-
$
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
|
|
|
22 |
$data = array();
|
23 |
if ($config && isset($config['licensekey'])) {
|
24 |
$data['uuid'] = $config['licensekey'];
|
@@ -77,7 +88,7 @@ try {
|
|
77 |
$stemapUrl='Sitemap:http://magento.instantsearchplus.com/ext_sitemap?u='.$key.PHP_EOL;
|
78 |
$robotsPath=Mage::getBaseDir().DS.'robots.txt';
|
79 |
if (file_exists($robotsPath)) {
|
80 |
-
if (strpos($
|
81 |
if(is_writable($robotsPath)){
|
82 |
//append sitemap
|
83 |
file_put_contents($robotsPath, $stemapUrl, FILE_APPEND | LOCK_EX);
|
12 |
$multistoreJson = $helper->getMultiStoreDataJson();
|
13 |
|
14 |
// Checking config table values
|
15 |
+
// getEdition exist from version 1.12, LICENSE_EE.txt file only exists in EE edition, we need the condition to work on EE version less then 1.11.x.x
|
16 |
+
if (!method_exists('Mage' , 'getEdition') && file_exists('LICENSE_EE.txt') && method_exists('Mage' , 'getVersion') && version_compare(Mage::getVersion(), '1.10.0.0.', '<') === true){
|
17 |
+
if ($installer->getConnection()->showTableStatus($this->getTable('autocompleteplus_config'))) {
|
18 |
+
$config_arr = Mage::getModel('autocompleteplus_autosuggest/config')->getCollection()->getData();
|
19 |
+
$config = $config_arr[0];
|
20 |
+
} else {
|
21 |
+
$config = false;
|
22 |
+
}
|
23 |
} else {
|
24 |
+
if ($installer->getConnection()->isTableExists($this->getTable('autocompleteplus_config'))) {
|
25 |
+
$config_arr = Mage::getModel('autocompleteplus_autosuggest/config')->getCollection()->getData();
|
26 |
+
$config = $config_arr[0];
|
27 |
+
} else {
|
28 |
+
$config = false;
|
29 |
+
}
|
30 |
}
|
31 |
|
32 |
+
|
33 |
$data = array();
|
34 |
if ($config && isset($config['licensekey'])) {
|
35 |
$data['uuid'] = $config['licensekey'];
|
88 |
$stemapUrl='Sitemap:http://magento.instantsearchplus.com/ext_sitemap?u='.$key.PHP_EOL;
|
89 |
$robotsPath=Mage::getBaseDir().DS.'robots.txt';
|
90 |
if (file_exists($robotsPath)) {
|
91 |
+
if (strpos(file_get_contents($robotsPath),$stemapUrl) == false){
|
92 |
if(is_writable($robotsPath)){
|
93 |
//append sitemap
|
94 |
file_put_contents($robotsPath, $stemapUrl, FILE_APPEND | LOCK_EX);
|
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.2-2.0.7.3.php
CHANGED
@@ -1,51 +1,58 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
$installer = $this;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
$
|
44 |
-
|
45 |
-
$
|
46 |
-
$
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
// getEdition exist from version 1.12, LICENSE_EE.txt file only exists in EE edition, we need the condition to work on EE version less then 1.11.x.x
|
6 |
+
if (!method_exists('Mage' , 'getEdition') && file_exists('LICENSE_EE.txt') && method_exists('Mage' , 'getVersion') && version_compare(Mage::getVersion(), '1.10.0.0.', '<') === true){
|
7 |
+
$is_table_exist = $installer->getConnection()->showTableStatus($this->getTable('autocompleteplus_batches'));
|
8 |
+
} else {
|
9 |
+
$is_table_exist = $installer->getConnection()->isTableExists($this->getTable('autocompleteplus_batches'));
|
10 |
+
}
|
11 |
+
if ($is_table_exist) {
|
12 |
+
try{
|
13 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
14 |
+
$_tableprefix = (string)Mage::getConfig()->getTablePrefix();
|
15 |
+
$query = 'SHOW FIELDS FROM `'.$_tableprefix.'autocompleteplus_batches` WHERE Field = \'update_date\'';
|
16 |
+
// $query = 'DESCRIBE `'.$_tableprefix.'autocompleteplus_batches`'.' \'update_date\'';
|
17 |
+
|
18 |
+
$result = $read->fetchAll($query);
|
19 |
+
if (!empty($result) && array_key_exists('Type', $result[0])){
|
20 |
+
if (!(substr($result[0]['Type'], 0, 3) == 'int')){ // check if variable 'update_date' type is not Integer
|
21 |
+
|
22 |
+
$installer->startSetup();
|
23 |
+
// rebuild the autocompleteplus_batches table
|
24 |
+
$res=$installer->run("
|
25 |
+
DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_batches')};
|
26 |
+
|
27 |
+
CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_batches')} (
|
28 |
+
`id` int(11) NOT NULL auto_increment,
|
29 |
+
`product_id` INT NULL,
|
30 |
+
`store_id` INT NOT NULL,
|
31 |
+
`update_date` INT DEFAULT NULL,
|
32 |
+
`action` VARCHAR( 255 ) NOT NULL,
|
33 |
+
`sku` VARCHAR( 255 ) NOT NULL,
|
34 |
+
PRIMARY KEY (`id`)
|
35 |
+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
|
36 |
+
|
37 |
+
");
|
38 |
+
$installer->endSetup();
|
39 |
+
}
|
40 |
+
}
|
41 |
+
} catch (Exception $e) {
|
42 |
+
$errMsg = $e->getMessage();
|
43 |
+
Mage::log('Install failed with a message: ' . $errMsg, null, 'autocomplete.log',true);
|
44 |
+
|
45 |
+
$command = "http://magento.instantsearchplus.com/install_error";
|
46 |
+
$helper = Mage::helper('autocompleteplus_autosuggest');
|
47 |
+
//getting site url
|
48 |
+
$url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
|
49 |
+
|
50 |
+
$data = array();
|
51 |
+
$data['site'] = $url;
|
52 |
+
$data['msg'] = $errMsg;
|
53 |
+
$data['f'] = '2.0.7.3';
|
54 |
+
$res = $helper->sendPostCurl($command, $data);
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
?>
|
app/design/frontend/base/default/template/autocompleteplus/catalog/product/list.phtml
CHANGED
@@ -39,7 +39,7 @@ try{
|
|
39 |
<?php
|
40 |
$helper=Mage::helper('autocompleteplus_autosuggest');
|
41 |
$server_url = $helper->getServerUrl();
|
42 |
-
$url = $server_url . '/ma_load_search_page?isp_platform=magento';
|
43 |
$resp = $helper->sendCurl($url);
|
44 |
$response_json = json_decode($resp);
|
45 |
echo $response_json->html;
|
39 |
<?php
|
40 |
$helper=Mage::helper('autocompleteplus_autosuggest');
|
41 |
$server_url = $helper->getServerUrl();
|
42 |
+
$url = $server_url . '/ma_load_search_page?isp_platform=magento&r=002';
|
43 |
$resp = $helper->sendCurl($url);
|
44 |
$response_json = json_decode($resp);
|
45 |
echo $response_json->html;
|
package.xml
CHANGED
@@ -1,18 +1,20 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>autocompleteplus_autosuggest</name>
|
4 |
-
<version>2.0.8.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.autocompleteplus.com/privacy">AC+</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>AutoComplete+ InstantSearch</summary>
|
10 |
<description>AutoComplete+ InstantSearch triples visitor conversion, optimizes search, and offers promotions through state-of-the-art contextual suggestions dropdown. Since suggestions are lightning fast, accurate, and contextual - visitors find exactly what they want - faster.</description>
|
11 |
-
<notes>*
|
|
|
|
|
12 |
<authors><author><name>Adar</name><user>Adar</user><email>magento@autocompleteplus.com</email></author></authors>
|
13 |
-
<date>
|
14 |
-
<time>
|
15 |
-
<contents><target name="magelocal"><dir name="Autocompleteplus"><dir name="Autosuggest"><dir name="Adminhtml"><dir name="Model"><file name="Attributes.php" hash="4fc7b546eb9cbff0b5067bc09fb62597"/><file name="Button.php" hash="afd78d0d80b4af60ea70fcfcffea5d8b"/></dir></dir><dir name="Block"><dir name="Adminhtml"><file name="Button.php" hash="2f302e3591671c3d7c153f0f7977c64c"/><file name="Process.php" hash="e50cf29c2b8893817eb0de4aeacf9ba3"/><file name="Sync.php" hash="0329b6920b67a5c05b38fafe7142df48"/></dir><file name="Autocomplete.php" hash="3a63d5c743d8dda3552f8c0b717c8d2e"/><file name="Autocorrection.php" hash="08da843c04cf9176cefb8588a0da3e77"/><file name="Inject.php" hash="b3e5663b46b64b8b8bc0483b01508848"/><file name="Notifications.php" hash="825fcc830917a22aff36e859fd63b16f"/></dir><dir name="Helper"><file name="Data.php" hash="3c1934354d5144cd33de0e4a3da63777"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Attributes.php" hash="1e321486e5c3bea159e4a7d8a79926ab"/></dir><dir name="Api"><file name="V2.php" hash="f7bfd6626466de0fe860484ab2bc7a00"/></dir><file name="Api.php" hash="4dd5882dcfd219087c1cec3cff46f7a9"/><file name="Catalog.php" hash="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>autocompleteplus_autosuggest</name>
|
4 |
+
<version>2.0.8.7</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.autocompleteplus.com/privacy">AC+</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>AutoComplete+ InstantSearch</summary>
|
10 |
<description>AutoComplete+ InstantSearch triples visitor conversion, optimizes search, and offers promotions through state-of-the-art contextual suggestions dropdown. Since suggestions are lightning fast, accurate, and contextual - visitors find exactly what they want - faster.</description>
|
11 |
+
<notes>* Error/bug fix - on product categories update
|
12 |
+
* Support for old Magento Enterprise editions
|
13 |
+
</notes>
|
14 |
<authors><author><name>Adar</name><user>Adar</user><email>magento@autocompleteplus.com</email></author></authors>
|
15 |
+
<date>2016-01-04</date>
|
16 |
+
<time>12:51:46</time>
|
17 |
+
<contents><target name="magelocal"><dir name="Autocompleteplus"><dir name="Autosuggest"><dir name="Adminhtml"><dir name="Model"><file name="Attributes.php" hash="4fc7b546eb9cbff0b5067bc09fb62597"/><file name="Button.php" hash="afd78d0d80b4af60ea70fcfcffea5d8b"/></dir></dir><dir name="Block"><dir name="Adminhtml"><file name="Button.php" hash="2f302e3591671c3d7c153f0f7977c64c"/><file name="Process.php" hash="e50cf29c2b8893817eb0de4aeacf9ba3"/><file name="Sync.php" hash="0329b6920b67a5c05b38fafe7142df48"/></dir><file name="Autocomplete.php" hash="3a63d5c743d8dda3552f8c0b717c8d2e"/><file name="Autocorrection.php" hash="08da843c04cf9176cefb8588a0da3e77"/><file name="Inject.php" hash="b3e5663b46b64b8b8bc0483b01508848"/><file name="Notifications.php" hash="825fcc830917a22aff36e859fd63b16f"/></dir><dir name="Helper"><file name="Data.php" hash="3c1934354d5144cd33de0e4a3da63777"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Attributes.php" hash="1e321486e5c3bea159e4a7d8a79926ab"/></dir><dir name="Api"><file name="V2.php" hash="f7bfd6626466de0fe860484ab2bc7a00"/></dir><file name="Api.php" hash="4dd5882dcfd219087c1cec3cff46f7a9"/><file name="Catalog.php" hash="5dad567812712a0c4b645e83f8454c75"/><file name="Catalogreport.php" hash="05f88adba656366d814f259056f92c73"/><file name="Config.php" hash="57d8e278d1cd13fea31504ee8f8ee304"/><file name="Layer.php" hash="ef1b5ddaa4fd12354e349d64f09ba1af"/><dir name="Mysql4"><dir name="Config"><file name="Collection.php" hash="110486b53b74e5b1cba1d552814a4b7c"/></dir><file name="Config.php" hash="991a9f1e674756a0a57577febb2f48cd"/><dir name="Fulltext"><file name="Collection.php" hash="709f6d0a955ec7bc1d31c577858101e6"/></dir><file name="Fulltext.php" hash="eada3fc83bd7976d8e3a38f8bb6e0e5f"/><dir name="Notifications"><file name="Collection.php" hash="d306a8690255ba7c444d30f94f780df4"/></dir><file name="Notifications.php" hash="c74b9b6a8f639318c828d3d5984bcf5d"/><dir name="Pusher"><file name="Collection.php" hash="28f0c11f2a3dd26fd06c508a342becd9"/></dir><file name="Pusher.php" hash="9337bd6a280f35f4694e7a1351f39e7d"/></dir><file name="Notifications.php" hash="6467b4765964afba40e452e564c7347d"/><file name="Observer.php" hash="7f5e4891ff139789998808a49dfd1e24"/><file name="Pusher.php" hash="cb55bd677f131dc4370429c2cb485be9"/><dir name="Resource"><dir name="Fulltext"><file name="Collection.php" hash="7ee2e9c81abfb36ab48db380fec378d2"/></dir></dir><file name="Service.php" hash="2c1e4d7764f7d99d2f54e442f3652918"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Autocompleteplus"><file name="PushController.php" hash="ec366543519b206339ca39ce3320ad12"/><file name="RedirectController.php" hash="a63c7811b54470e26dcd1c22d707e67b"/></dir></dir><dir name="CatalogSearch"><file name="ResultController.php" hash="67333080dc7d7cf748667b53616f1457"/></dir><file name="CatalogsearchController.php" hash="0327c979fc357504147d7caff7079d69"/><file name="CategoriesController.php" hash="8f120263586178c0c96e4cb74aea8f00"/><file name="LayeredController.php" hash="f43274329a4e8cfbae6c994beea25653"/><file name="ProductsController.php" hash="520bae5c425916af7cb6e8213b298a0f"/><file name="ProductsbyidController.php" hash="01b8cb9288325ad41248a8eb3fbb906a"/><file name="ResultController.php" hash="f47c5e0c7af08e43af83942a6f418ce7"/><file name="SearchesController.php" hash="344ab1717d1b25d746d033074ae22ade"/></dir><dir name="etc"><file name="adminhtml.xml" hash="34b9d24ddc4565311f6cc83d7e337478"/><file name="api.xml" hash="25ab859fc8312c4aa308f2e3306c6b66"/><file name="cache.xml" hash="b57472bc9410d67af3843825fba5b420"/><file name="config.xml" hash="fad3b2068f9f5f93c4468168855b678f"/><file name="config_no_fulltext.xml" hash="50a757335937264e0886bf2b6ac72288"/><file name="config_with_crontab.xml" hash="3ea8556899a84435c11c6f526bccec27"/><file name="system.xml" hash="6bed22fbdfc336254126cf4a8c49aa09"/><file name="wsdl.xml" hash="97b1503c710c79376cd85e7f971c1587"/></dir><dir name="sql"><dir name="autosuggest_setup"><file name="mysql4-install-2.0.1.1.php" hash="fd4018c6752ba72af7af2f5f14a0dc12"/><file name="mysql4-upgrade-2.0.1.3-2.0.2.2.php" hash="275c674ba7ef38beb03d20dd16c56d79"/><file name="mysql4-upgrade-2.0.2.5-2.0.2.6.php" hash="4db99239287c64410ac1d7abf6517b59"/><file name="mysql4-upgrade-2.0.4.6-2.0.4.7.php" hash="9a37396d35fec0e3b911455ec61b18d6"/><file name="mysql4-upgrade-2.0.5.4-2.0.5.5.php" hash="eb50a1aaf9d639495776dc8501b2e74c"/><file name="mysql4-upgrade-2.0.5.6-2.0.5.7.php" hash="6a77ea58afed1b6937f0c6d0aa831392"/><file name="mysql4-upgrade-2.0.6.1-2.0.6.4.php" hash="021610876715ce0f3612a6cd67aa405a"/><file name="mysql4-upgrade-2.0.7.0-2.0.7.1.php" hash="02c07e5d0c94299165dce4bd140ee547"/><file name="mysql4-upgrade-2.0.7.2-2.0.7.3.php" hash="feb6039afe42f1c0087c59cf97c4c4e3"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Autocompleteplus_Autosuggest.xml" hash="e2279cfe50ac070fcfabcf9d327a25fc"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="autocompleteplus.xml" hash="286290139b776909e423c0f4c346d82a"/></dir><dir name="template"><dir name="autocompleteplus"><dir name="catalog"><dir name="layer"><file name="view.phtml" hash="57066d2ac5fa051c15c3ed8bb43b5d08"/></dir><dir name="product"><file name="list.phtml" hash="7fb8c4cc511d991bf4e5bc16740b1f39"/></dir></dir><file name="inject.phtml" hash="8cdcb15176db3b14c9c135e87d31e7ad"/><file name="inject_new.phtml" hash="e1e8e050631fe65417edb7a8f25155c8"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="autocompleteplus"><file name="notifications.phtml" hash="c1d08659e65020dcb9e62cf8bc28f73b"/><file name="notifications_old.php" hash="8824edf5a99aa011a1d123233b6a513d"/><dir name="system"><dir name="config"><file name="button.phtml" hash="4762e2343ede91cdee6ecdbf1fd85030"/><file name="sync.phtml" hash="e0392aac8584e98ef4260419750e1cbb"/></dir></dir></dir></dir><dir name="layout"><file name="autocompleteplus.xml" hash="939f8a52905dfef7b81a0f4552042376"/></dir></dir></dir></dir></target></contents>
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
20 |
</package>
|