autocompleteplus_autosuggest - Version 3.0.0.0

Version Notes

* Newly refactored module in preparation for Magento 2
* Add support for PSR-2
* Fix security issue with API connection
* Fix issue with admin session loading
* Fix issue with application config table migration

Download this release

Release Info

Developer Adar
Extension autocompleteplus_autosuggest
Version 3.0.0.0
Comparing to
See all releases


Code changes from version 2.0.8.8 to 3.0.0.0

Files changed (70) hide show
  1. app/code/local/Autocompleteplus/Autosuggest/Adminhtml/Model/Attributes.php +17 -22
  2. app/code/local/Autocompleteplus/Autosuggest/Adminhtml/Model/Button.php +23 -23
  3. app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Button.php +17 -25
  4. app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Process.php +23 -166
  5. app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Sync.php +23 -15
  6. app/code/local/Autocompleteplus/Autosuggest/Block/Autocomplete.php +49 -47
  7. app/code/local/Autocompleteplus/Autosuggest/Block/Autocorrection.php +24 -24
  8. app/code/local/Autocompleteplus/Autosuggest/Block/Inject.php +58 -52
  9. app/code/local/Autocompleteplus/Autosuggest/Block/Notifications.php +10 -11
  10. app/code/local/Autocompleteplus/Autosuggest/Controller/Abstract.php +14 -0
  11. app/code/local/Autocompleteplus/Autosuggest/Helper/Data.php +354 -352
  12. app/code/local/Autocompleteplus/Autosuggest/Model/Adminhtml/Attributes.php +14 -60
  13. app/code/local/Autocompleteplus/Autosuggest/Model/Api.php +27 -12
  14. app/code/local/Autocompleteplus/Autosuggest/Model/Api/V2.php +4 -1
  15. app/code/local/Autocompleteplus/Autosuggest/Model/Batches.php +9 -0
  16. app/code/local/Autocompleteplus/Autosuggest/Model/Catalog.php +1010 -1129
  17. app/code/local/Autocompleteplus/Autosuggest/Model/Catalogreport.php +19 -14
  18. app/code/local/Autocompleteplus/Autosuggest/Model/Checksum.php +9 -0
  19. app/code/local/Autocompleteplus/Autosuggest/Model/Config.php +346 -3
  20. app/code/local/Autocompleteplus/Autosuggest/Model/Layer.php +25 -18
  21. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Config.php +0 -8
  22. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Config/Collection.php +0 -8
  23. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Fulltext.php +0 -101
  24. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Fulltext/Collection.php +0 -140
  25. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Pusher/Collection.php +0 -10
  26. app/code/local/Autocompleteplus/Autosuggest/Model/Notifications.php +3 -5
  27. app/code/local/Autocompleteplus/Autosuggest/Model/Observer.php +318 -457
  28. app/code/local/Autocompleteplus/Autosuggest/Model/Pusher.php +2 -1
  29. app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Batches.php +12 -0
  30. app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Batches/Collection.php +12 -0
  31. app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Checksum.php +12 -0
  32. app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Checksum/Collection.php +12 -0
  33. app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Fulltext/Collection.php +225 -210
  34. app/code/local/Autocompleteplus/Autosuggest/Model/{Mysql4 → Resource}/Notifications.php +4 -6
  35. app/code/local/Autocompleteplus/Autosuggest/Model/{Mysql4 → Resource}/Notifications/Collection.php +8 -7
  36. app/code/local/Autocompleteplus/Autosuggest/Model/{Mysql4 → Resource}/Pusher.php +7 -4
  37. app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Pusher/Collection.php +9 -0
  38. app/code/local/Autocompleteplus/Autosuggest/Model/Service.php +34 -258
  39. app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/Autocompleteplus/PushController.php +5 -3
  40. app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/Autocompleteplus/RedirectController.php +7 -7
  41. app/code/local/Autocompleteplus/Autosuggest/controllers/CatalogSearch/ResultController.php +5 -3
  42. app/code/local/Autocompleteplus/Autosuggest/controllers/CatalogsearchController.php +12 -15
  43. app/code/local/Autocompleteplus/Autosuggest/controllers/CategoriesController.php +50 -71
  44. app/code/local/Autocompleteplus/Autosuggest/controllers/LayeredController.php +89 -57
  45. app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsController.php +605 -713
  46. app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsbyidController.php +62 -71
  47. app/code/local/Autocompleteplus/Autosuggest/controllers/ResultController.php +7 -7
  48. app/code/local/Autocompleteplus/Autosuggest/controllers/SearchesController.php +40 -47
  49. app/code/local/Autocompleteplus/Autosuggest/etc/config.xml +9 -22
  50. app/code/local/Autocompleteplus/Autosuggest/etc/config_no_fulltext.xml +0 -214
  51. app/code/local/Autocompleteplus/Autosuggest/etc/config_with_crontab.xml +0 -205
  52. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-install-2.0.1.1.php +8 -13
  53. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.1.3-2.0.2.2.php +5 -22
  54. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.2.5-2.0.2.6.php +4 -5
  55. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.4.6-2.0.4.7.php +4 -5
  56. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.4-2.0.5.5.php +40 -57
  57. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.6-2.0.5.7.php +37 -44
  58. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.6.1-2.0.6.4.php +0 -169
  59. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.0-2.0.7.1.php +2 -1
  60. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.2-2.0.7.3.php +93 -58
  61. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.8.8-3.0.0.0.php +24 -0
  62. app/design/adminhtml/default/default/template/autocompleteplus/notifications_old.php +0 -28
  63. app/design/adminhtml/default/default/template/autocompleteplus/system/config/button.phtml +6 -12
  64. app/design/frontend/base/default/layout/autocompleteplus.xml +2 -4
  65. app/design/frontend/base/default/template/autocompleteplus/catalog/product/list.phtml +11 -19
  66. app/design/frontend/base/default/template/autocompleteplus/inject.phtml +3 -58
  67. app/design/frontend/base/default/template/autocompleteplus/inject_new.phtml +0 -3
  68. app/design/frontend/base/default/template/autocompleteplus/process.phtml +136 -0
  69. app/etc/modules/Autocompleteplus_Autosuggest.xml +6 -20
  70. package.xml +11 -9
app/code/local/Autocompleteplus/Autosuggest/Adminhtml/Model/Attributes.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,51 +9,47 @@
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
 
18
  /**
19
- * Used in creating options for Yes|No config value selection
20
- *
21
  */
22
  class Autocompleteplus_Autosuggest_Adminhtml_Model_Attributes
23
  {
24
  public $fields = array();
25
  /**
26
- * Options getter
27
  *
28
  * @return array
29
  */
30
  public function toOptionArray()
31
  {
32
- $this->fields=$this->getOptions();
 
33
  return $this->fields;
34
  }
35
 
36
  public function getOptions()
37
  {
38
  $entityType = Mage::getModel('catalog/product')->getResource()->getEntityType();
39
- $entityTypeId=$entityType->getId();
40
  $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
41
  ->setEntityTypeFilter($entityTypeId)
42
  ->getData();
43
- $result=array();
44
- $result[]=array('value'=>'','label'=>'Choose an attribute');
45
- foreach($attributeInfo as $_key=>$_value)
46
- {
47
- if($_value['is_global'] != "1" || $_value['is_visible']!="1"){
48
- // continue;
49
- }
50
- if(isset($_value['frontend_label'])&&($_value['frontend_label']!='')){
51
- $result[]=array('value'=>$_value['attribute_code'],'label' => $_value['frontend_label']);
52
- }else{
53
- $result[]=array('value'=>$_value['attribute_code'],'label' => $_value['attribute_code']);
54
- }
55
 
 
 
 
 
 
 
 
 
56
  }
 
57
  return $result;
58
  }
59
-
60
- }
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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
 
17
  /**
18
+ * Used in creating options for Yes|No config value selection.
 
19
  */
20
  class Autocompleteplus_Autosuggest_Adminhtml_Model_Attributes
21
  {
22
  public $fields = array();
23
  /**
24
+ * Options getter.
25
  *
26
  * @return array
27
  */
28
  public function toOptionArray()
29
  {
30
+ $this->fields = $this->getOptions();
31
+
32
  return $this->fields;
33
  }
34
 
35
  public function getOptions()
36
  {
37
  $entityType = Mage::getModel('catalog/product')->getResource()->getEntityType();
38
+ $entityTypeId = $entityType->getId();
39
  $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
40
  ->setEntityTypeFilter($entityTypeId)
41
  ->getData();
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ $result = array();
44
+ $result[] = array('value' => '', 'label' => 'Choose an attribute');
45
+ foreach ($attributeInfo as $_key => $_value) {
46
+ if (isset($_value['frontend_label']) && ($_value['frontend_label'] != '')) {
47
+ $result[] = array('value' => $_value['attribute_code'], 'label' => $_value['frontend_label']);
48
+ } else {
49
+ $result[] = array('value' => $_value['attribute_code'], 'label' => $_value['attribute_code']);
50
+ }
51
  }
52
+
53
  return $result;
54
  }
55
+ }
 
app/code/local/Autocompleteplus/Autosuggest/Adminhtml/Model/Button.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,18 +9,17 @@
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
 
18
  /**
19
- * Used in creating options for Yes|No config value selection
20
- *
21
  */
22
  class Autocompleteplus_Autosuggest_Adminhtml_Model_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
23
  {
24
- /*
25
  * Set template
26
  */
27
  protected function _construct()
@@ -29,27 +27,30 @@ class Autocompleteplus_Autosuggest_Adminhtml_Model_Button extends Mage_Adminhtm
29
  parent::_construct();
30
  $this->setTemplate('autocompleteplus/system/config/button.phtml');
31
  }
32
-
33
  /**
34
- * Return element html
 
 
35
  *
36
- * @param Varien_Data_Form_Element_Abstract $element
37
  * @return string
38
  */
39
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
40
  {
 
 
41
  return $this->_toHtml();
42
  }
43
-
44
- public function getUUID(){
45
 
46
- $helper=Mage::helper('autocompleteplus_autosuggest');
 
 
47
 
48
- return $helper->getUUID();
49
  }
50
-
51
  /**
52
- * Return ajax url for button
53
  *
54
  * @return string
55
  */
@@ -57,9 +58,9 @@ class Autocompleteplus_Autosuggest_Adminhtml_Model_Button extends Mage_Adminhtm
57
  {
58
  return Mage::helper('adminhtml')->getUrl('autocompleteplus/products/updateemail');
59
  }
60
-
61
  /**
62
- * Generate button html
63
  *
64
  * @return string
65
  */
@@ -67,12 +68,11 @@ class Autocompleteplus_Autosuggest_Adminhtml_Model_Button extends Mage_Adminhtm
67
  {
68
  $button = $this->getLayout()->createBlock('adminhtml/widget_button')
69
  ->setData(array(
70
- 'id' => 'autocompleteplus_button',
71
- 'label' => $this->helper('adminhtml')->__('Update'),
72
- 'onclick' => 'javascript:updateautocomplete(); return false;'
73
  ));
74
-
75
  return $button->toHtml();
76
  }
77
-
78
- }
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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
 
17
  /**
18
+ * Used in creating options for Yes|No config value selection.
 
19
  */
20
  class Autocompleteplus_Autosuggest_Adminhtml_Model_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
21
  {
22
+ /*
23
  * Set template
24
  */
25
  protected function _construct()
27
  parent::_construct();
28
  $this->setTemplate('autocompleteplus/system/config/button.phtml');
29
  }
30
+
31
  /**
32
+ * Return element html.
33
+ *
34
+ * @param Varien_Data_Form_Element_Abstract $element
35
  *
 
36
  * @return string
37
  */
38
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
39
  {
40
+ $this->setElement($element);
41
+
42
  return $this->_toHtml();
43
  }
 
 
44
 
45
+ public function getUUID()
46
+ {
47
+ $config = Mage::getModel('autocompleteplus_autosuggest/config');
48
 
49
+ return $config->getUUID();
50
  }
51
+
52
  /**
53
+ * Return ajax url for button.
54
  *
55
  * @return string
56
  */
58
  {
59
  return Mage::helper('adminhtml')->getUrl('autocompleteplus/products/updateemail');
60
  }
61
+
62
  /**
63
+ * Generate button html.
64
  *
65
  * @return string
66
  */
68
  {
69
  $button = $this->getLayout()->createBlock('adminhtml/widget_button')
70
  ->setData(array(
71
+ 'id' => 'autocompleteplus_button',
72
+ 'label' => $this->helper('adminhtml')->__('Update'),
73
+ 'onclick' => 'javascript:updateautocomplete(); return false;',
74
  ));
75
+
76
  return $button->toHtml();
77
  }
78
+ }
 
app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Button.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  /**
4
- * InstantSearchPlus (Autosuggest)
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,21 +10,18 @@
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
 
18
  /**
19
- * Used in creating options for Yes|No config value selection
20
  */
21
-
22
  class Autocompleteplus_Autosuggest_Block_Adminhtml_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
23
  {
24
-
25
  /**
26
- * Set Template
27
- * @return void
28
  */
29
  protected function _construct()
30
  {
@@ -33,42 +30,38 @@ class Autocompleteplus_Autosuggest_Block_Adminhtml_Button extends Mage_Adminhtml
33
  }
34
 
35
  /**
36
- * Return element html
 
 
37
  *
38
- * @param Varien_Data_Form_Element_Abstract $element
39
  * @return string
40
  */
41
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
42
  {
 
43
 
44
  return $this->_toHtml();
45
-
46
  }
47
 
48
  public function getUUID()
49
  {
50
- try {
51
- $helper=Mage::helper('autocompleteplus_autosuggest');
52
- return $helper->getUUID();
53
- } catch(Exception $e) {
54
- Mage::log($e->getMessage(),null,'autocomplete.log');
55
- }
56
  }
57
 
58
  /**
59
- * Return ajax url for button
60
  *
61
  * @return string
62
  */
63
-
64
  public function getAjaxCheckUrl()
65
  {
66
-
67
  return Mage::helper('adminhtml')->getUrl('autocompleteplus/products/updateemail');
68
  }
69
 
70
  /**
71
- * Generate button html
72
  *
73
  * @return string
74
  */
@@ -77,12 +70,11 @@ class Autocompleteplus_Autosuggest_Block_Adminhtml_Button extends Mage_Adminhtml
77
  $button = $this->getLayout()->createBlock('adminhtml/widget_button')
78
 
79
  ->setData(array(
80
- 'id' => 'autocompleteplus_button',
81
- 'label' => $this->helper('adminhtml')->__('Update'),
82
- 'onclick' => 'javascript:updateautocomplete(); return false;'
83
  ));
84
 
85
  return $button->toHtml();
86
  }
87
-
88
- }
1
  <?php
2
 
3
  /**
4
+ * InstantSearchPlus (Autosuggest).
5
  *
6
  * NOTICE OF LICENSE
7
  *
10
  * http://opensource.org/licenses/osl-3.0.php
11
  *
12
  * @category Mage
13
+ *
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
 
18
  /**
19
+ * Used in creating options for Yes|No config value selection.
20
  */
 
21
  class Autocompleteplus_Autosuggest_Block_Adminhtml_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
22
  {
 
23
  /**
24
+ * Set Template.
 
25
  */
26
  protected function _construct()
27
  {
30
  }
31
 
32
  /**
33
+ * Return element html.
34
+ *
35
+ * @param Varien_Data_Form_Element_Abstract $element
36
  *
 
37
  * @return string
38
  */
39
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
40
  {
41
+ $this->setElement($element);
42
 
43
  return $this->_toHtml();
 
44
  }
45
 
46
  public function getUUID()
47
  {
48
+ $config = Mage::getModel('autocompleteplus_autosuggest/config');
49
+
50
+ return $config->getUUID();
 
 
 
51
  }
52
 
53
  /**
54
+ * Return ajax url for button.
55
  *
56
  * @return string
57
  */
 
58
  public function getAjaxCheckUrl()
59
  {
 
60
  return Mage::helper('adminhtml')->getUrl('autocompleteplus/products/updateemail');
61
  }
62
 
63
  /**
64
+ * Generate button html.
65
  *
66
  * @return string
67
  */
70
  $button = $this->getLayout()->createBlock('adminhtml/widget_button')
71
 
72
  ->setData(array(
73
+ 'id' => 'autocompleteplus_button',
74
+ 'label' => $this->helper('adminhtml')->__('Update'),
75
+ 'onclick' => 'javascript:updateautocomplete(); return false;',
76
  ));
77
 
78
  return $button->toHtml();
79
  }
80
+ }
 
app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Process.php CHANGED
@@ -1,174 +1,31 @@
1
  <?php
 
2
  class Autocompleteplus_Autosuggest_Block_Adminhtml_Process extends Mage_Adminhtml_Block_System_Config_Form_Field
3
  {
4
- private $_pushConfig;
5
-
6
- protected function _toHtml()
7
  {
8
- $helper = Mage::helper('autocompleteplus_autosuggest');
9
- $this->_pushConfig=array(
10
- 'styles' => array(
11
- 'error' => array(
12
-
13
- 'icon' => Mage::getDesign()->getSkinUrl('images/error_msg_icon.gif'),
14
- 'bg' => '#FDD'
 
 
 
 
 
 
 
 
 
 
15
  ),
16
- 'message' => array(
17
- 'icon' => Mage::getDesign()->getSkinUrl('images/fam_bullet_success.gif'),
18
- 'bg' => '#DDF'
19
- ),
20
- 'loader' => Mage::getDesign()->getSkinUrl('images/ajax-loader.gif')
21
- ),
22
- 'template' => '<li style="#{style}" id="#{id}">'
23
- . '<img id="#{id}_img" src="#{image}" class="v-middle" style="margin-right:5px"/>'
24
- . '<span id="#{id}_status" class="text">#{text}</span>'
25
- . '</li>',
26
- 'text' => $this->__('Processed <strong>%s%% %s/%d</strong> records', '#{percent}', '#{updated}', $this->getBatchItemsCount()),
27
- 'successText' => $this->__('Imported <strong>%s</strong> records', '#{updated}')
28
  );
29
-
30
- echo '<html><head>';
31
- echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
32
- echo '<script type="text/javascript">var FORM_KEY = "'.Mage::getSingleton('core/session')->getFormKey().'";</script>';
33
-
34
- $headBlock = $this->getLayout()->createBlock('page/html_head');
35
- $headBlock->addJs('prototype/prototype.js');
36
- $headBlock->addJs('mage/adminhtml/loader.js');
37
- echo $headBlock->getCssJsHtml();
38
-
39
- echo '<style type="text/css">
40
- ul { list-style-type:none; padding:0; margin:0; }
41
- li { margin-left:0; border:1px solid #ccc; margin:2px; padding:2px 2px 2px 2px; font:normal 12px sans-serif; }
42
- img { margin-right:5px; }
43
- </style>
44
- <title>'.$this->__('Syncing data...').'</title>
45
- </head><body>';
46
- echo '<ul>';
47
- echo '<li>';
48
- echo '<img src="'.Mage::getDesign()->getSkinUrl('images/note_msg_icon.gif').'" class="v-middle" style="margin-right:5px"/>';
49
- echo $this->__("Starting initial store product sync with InstantSearch+");
50
- echo '</li>';
51
- echo '<li style="background-color:#FFD;">';
52
- echo '<img src="'.Mage::getDesign()->getSkinUrl('images/fam_bullet_error.gif').'" class="v-middle" style="margin-right:5px"/>';
53
- echo $this->__("Warning: Please do not close this tab until sync is complete");
54
-
55
- echo '</li>';
56
-
57
- echo '<li id="liFinished" style="display:none;">
58
- <img src="'.$this->getSkinUrl('images/note_msg_icon.gif').'" class="v-middle" style="margin-right:5px"/>
59
- '.$this->__(" Initial Product Sync is finished. ").'
60
- <span id="liFinished_count">0</span>&nbsp;'.$this->__("products were synced").'
61
- </li>';
62
- echo '</ul>';
63
-
64
- $pushId=$helper->getPushId();
65
-
66
- $totalPushes= Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->count();
67
-
68
- $pushUrl='';
69
-
70
- if($pushId!=''){
71
- $pushUrl=$helper->getPushUrl($pushId);
72
- }
73
-
74
- echo '<script type="text/javascript">
75
- var config= '.Mage::helper('core')->jsonEncode($this->_pushConfig).';
76
- config.tpl = new Template(config.template);
77
- config.tplTxt = new Template(config.text);
78
- config.tplSccTxt = new Template(config.successText);
79
-
80
- var url="'.$pushUrl.'";
81
-
82
- var count=0;
83
-
84
- if(url!=""){
85
- sendImportData(url);
86
- }else{
87
- $("liFinished").show();
88
- $("liFinished_count").update(count);
89
- $("synced-rows").hide()
90
- }
91
-
92
-
93
-
94
- function sendImportData(url) {
95
-
96
- if (!$("updatedRows")) {
97
- Element.insert($("liFinished"), {before: config.tpl.evaluate({
98
- style: "background-color: #FFD;",
99
- image: config.styles.loader,
100
- text: "Syncing: push '.$pushId.'/'.$totalPushes.'",
101
- id: "updatedRows"
102
- })});
103
  }
104
-
105
- new Ajax.Request(url, {
106
- method: "get",
107
- onSuccess: function(transport) {
108
-
109
- if (transport.responseText.isJSON()) {
110
- var res=transport.responseText.evalJSON();
111
-
112
- if(!res){
113
- Element.insert($("updatedRows"), {before: config.tpl.evaluate({
114
- style: "background-color:"+config.styles.error.bg,
115
- image: config.styles.error.icon,
116
- text: res.message,
117
- id: "error-"+makeid()
118
- })});
119
- }else{
120
-
121
- if (!$("synced-rows")){
122
- Element.insert($("updatedRows"), {before: config.tpl.evaluate({
123
- style: "background-color:"+config.styles.message.bg,
124
- image: config.styles.message.icon,
125
- text: res.updatedSuccessStatus,
126
- id: "synced-rows"
127
- })});
128
- }else{
129
- $("synced-rows_status").update(res.updatedSuccessStatus);
130
- }
131
-
132
- url=res.nextPushUrl;
133
-
134
- count+=res.count;
135
-
136
- if(url!=""){
137
- $("updatedRows_status").update(res.updatedStatus);
138
- sendImportData(url);
139
- }else{
140
- $("liFinished").show();
141
- $("liFinished_count").update(count);
142
- $("updatedRows").hide()
143
- $("synced-rows").hide()
144
- }
145
-
146
- }
147
- } else {
148
- Element.insert($("updatedRows"), {before: config.tpl.evaluate({
149
- style: "background-color:"+config.styles.error.bg,
150
- image: config.styles.error.icon,
151
- text: transport.responseText.escapeHTML(),
152
- id: "error-"+makeid()
153
- })});
154
- }
155
- }
156
- });
157
  }
158
-
159
- function makeid()
160
- {
161
- var text = "";
162
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
163
-
164
- for( var i=0; i < 5; i++ )
165
- text += possible.charAt(Math.floor(Math.random() * possible.length));
166
-
167
- return text;
168
- }
169
- </script>';
170
-
171
- echo '</body></html>';
172
- }
173
-
174
- }
1
  <?php
2
+
3
  class Autocompleteplus_Autosuggest_Block_Adminhtml_Process extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
+ protected function _construct()
 
 
6
  {
7
+ $configTemplate = <<<TMPL
8
+ <li style="#{style}" id="#{id}">
9
+ <img id="#{id}_img" src="#{image}" class="v-middle" style="margin-right:5px"/>
10
+ <span id="#{id}_status" class="text">#{text}</span>
11
+ </li>
12
+ TMPL;
13
+
14
+ $this->_pushConfig = array(
15
+ 'styles' => array(
16
+ 'error' => array(
17
+ 'icon' => $this->getSkinUrl('images/error_msg_icon.gif'),
18
+ 'bg' => '#FDD',
19
+ ),
20
+ 'message' => array(
21
+ 'icon' => $this->getSkinUrl('images/fam_bullet_success.gif'),
22
+ 'bg' => '#DDF',
23
+ ),
24
  ),
25
+ 'loader' => $this->getSkinUrl('images/ajax-loader.gif'),
26
+ 'template' => $configTemplate,
27
+ 'text' => $this->__('Processed <strong>%s%% %s/%d</strong> records', '#{percent}', '#{updated}', $this->getBatchItemsCount()),
28
+ 'successText' => $this->__('Imported <strong>%s</strong> records', '#{updated}'),
 
 
 
 
 
 
 
 
29
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Sync.php CHANGED
@@ -1,11 +1,10 @@
1
  <?php
2
 
3
  /**
4
- * Yes/no options for sync
5
  */
6
  class Autocompleteplus_Autosuggest_Block_Adminhtml_Sync extends Mage_Adminhtml_Block_System_Config_Form_Field
7
  {
8
-
9
  protected function _construct()
10
  {
11
  parent::_construct();
@@ -13,38 +12,46 @@ class Autocompleteplus_Autosuggest_Block_Adminhtml_Sync extends Mage_Adminhtml_B
13
  }
14
 
15
  /**
 
 
 
16
  *
17
- * Return element html
18
- * @param Varien_Data_Form_Element_Abstract $element
19
  * @return string
20
  */
21
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
22
  {
 
 
23
  return $this->_toHtml();
24
  }
25
 
26
  /**
27
- * Return UUID
 
28
  * @return string
29
  */
30
  public function getUUID()
31
  {
32
- $helper=Mage::helper('autocompleteplus_autosuggest');
33
- return $helper->getUUID();
 
34
  }
35
 
36
  /**
37
- * Reachable or not
 
38
  * @return bool
39
  */
40
  public function getIsReachable()
41
  {
42
- $helper=Mage::helper('autocompleteplus_autosuggest');
 
43
  return $helper->getIsReachable();
44
  }
45
 
46
  /**
47
- * Return ajax url for button
 
48
  * @return string
49
  */
50
  public function getSyncUrl()
@@ -53,18 +60,19 @@ class Autocompleteplus_Autosuggest_Block_Adminhtml_Sync extends Mage_Adminhtml_B
53
  }
54
 
55
  /**
56
- * Generate button html
 
57
  * @return string
58
  */
59
  public function getButtonHtml()
60
  {
61
  $button = $this->getLayout()->createBlock('adminhtml/widget_button')
62
  ->setData(array(
63
- 'id' => 'autocompleteplus_sync',
64
- 'label' => $this->helper('adminhtml')->__('Sync'),
65
- 'onclick' => 'javascript:syncautocomplete(); return false;'
66
  ));
67
 
68
  return $button->toHtml();
69
  }
70
- }
1
  <?php
2
 
3
  /**
4
+ * Yes/no options for sync.
5
  */
6
  class Autocompleteplus_Autosuggest_Block_Adminhtml_Sync extends Mage_Adminhtml_Block_System_Config_Form_Field
7
  {
 
8
  protected function _construct()
9
  {
10
  parent::_construct();
12
  }
13
 
14
  /**
15
+ * Return element html.
16
+ *
17
+ * @param Varien_Data_Form_Element_Abstract $element
18
  *
 
 
19
  * @return string
20
  */
21
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
22
  {
23
+ $this->setElement($element);
24
+
25
  return $this->_toHtml();
26
  }
27
 
28
  /**
29
+ * Return UUID.
30
+ *
31
  * @return string
32
  */
33
  public function getUUID()
34
  {
35
+ $config = Mage::getModel('autocompleteplus_autosuggest/config');
36
+
37
+ return $config->getUUID();
38
  }
39
 
40
  /**
41
+ * Reachable or not.
42
+ *
43
  * @return bool
44
  */
45
  public function getIsReachable()
46
  {
47
+ $helper = Mage::helper('autocompleteplus_autosuggest');
48
+
49
  return $helper->getIsReachable();
50
  }
51
 
52
  /**
53
+ * Return ajax url for button.
54
+ *
55
  * @return string
56
  */
57
  public function getSyncUrl()
60
  }
61
 
62
  /**
63
+ * Generate button html.
64
+ *
65
  * @return string
66
  */
67
  public function getButtonHtml()
68
  {
69
  $button = $this->getLayout()->createBlock('adminhtml/widget_button')
70
  ->setData(array(
71
+ 'id' => 'autocompleteplus_sync',
72
+ 'label' => $this->helper('adminhtml')->__('Sync'),
73
+ 'onclick' => 'javascript:syncautocomplete(); return false;',
74
  ));
75
 
76
  return $button->toHtml();
77
  }
78
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Autocomplete.php CHANGED
@@ -1,55 +1,57 @@
1
  <?php
2
 
3
- class Autocompleteplus_Autosuggest_Block_Autocomplete extends Mage_Core_Block_Abstract {
4
-
5
- protected function _toHtml() {
6
- $is_full_text_wrong_flow = false;
7
- try{
8
- $fulltext_enable = Mage::getSingleton('core/session')->getIsFullTextEnable();
9
- if (!$fulltext_enable){
10
- return '';
11
- }
12
- // checking if the searched query from addSearchFilter() is the same to the current query
13
- $current_search_term = urlencode(self::getRequest()->getParam('q'));
14
- $searched_term = Mage::getSingleton('core/session')->getIspUrlEncodeQuery();
15
- if ($current_search_term != $searched_term){
16
- $is_full_text_wrong_flow = true;
17
- }
18
- } catch (Exception $e){
19
- Mage::log('autocomplete.php _toHtml() Exception => fulltext_enable and query calculations' . $e->getMessage(),null,'autocompleteplus.log');
20
- return '';
21
- }
22
-
23
- $params = array();
24
- if (!$is_full_text_wrong_flow){
25
- try{
26
- $alternatives = Mage::getSingleton('core/session')->getIspSearchAlternatives();
27
- $results_for = Mage::getSingleton('core/session')->getIspSearchResultsFor();
28
- } catch (Exception $e) {
29
- Mage::log('autocomplete.php _toHtml() Exception => results_for and did you mean calculations' . $e->getMessage(),null,'autocompleteplus.log');
30
- return '';
31
- }
32
-
33
- if ($alternatives){
 
 
 
34
  $params['alternatives'] = json_encode($alternatives);
35
  }
36
- if ($results_for) {
37
- $params['results_for'] = urlencode($results_for);
38
- }
39
- } else {
40
- $params['wrong_flow'] = 1;
41
- }
42
-
43
- $magento_version = Mage::getVersion();
44
- $extension_version = (string)Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
45
- $versions = ($params == '') ? 'mage_v=' . $magento_version . '&ext_v=' . $extension_version
46
- : '&mage_v=' . $magento_version . '&ext_v=' . $extension_version;
47
-
48
  Mage::getSingleton('core/session')->unsIsFullTextEnable();
49
  Mage::getSingleton('core/session')->unsIspSearchAlternatives();
50
  Mage::getSingleton('core/session')->unsIspSearchResultsFor();
51
-
52
- return '<script data-cfasync="false" async type="text/javascript" src="https://acp-magento.appspot.com/js/magento_full_text.js?' . http_build_query( $params ) . $versions . '"></script>';
53
- }
54
- }
55
 
 
 
 
1
  <?php
2
 
3
+ class Autocompleteplus_Autosuggest_Block_Autocomplete extends Mage_Core_Block_Abstract
4
+ {
5
+ protected function _toHtml()
6
+ {
7
+ $is_full_text_wrong_flow = false;
8
+ try {
9
+ $fulltext_enable = Mage::getSingleton('core/session')->getIsFullTextEnable();
10
+ if (!$fulltext_enable) {
11
+ return '';
12
+ }
13
+ // checking if the searched query from addSearchFilter() is the same to the current query
14
+ $current_search_term = urlencode(self::getRequest()->getParam('q'));
15
+ $searched_term = Mage::getSingleton('core/session')->getIspUrlEncodeQuery();
16
+ if ($current_search_term != $searched_term) {
17
+ $is_full_text_wrong_flow = true;
18
+ }
19
+ } catch (Exception $e) {
20
+ Mage::log('autocomplete.php _toHtml() Exception => fulltext_enable and query calculations'.$e->getMessage(), null, 'autocompleteplus.log');
21
+
22
+ return '';
23
+ }
24
+
25
+ $params = array();
26
+ if (!$is_full_text_wrong_flow) {
27
+ try {
28
+ $alternatives = Mage::getSingleton('core/session')->getIspSearchAlternatives();
29
+ $results_for = Mage::getSingleton('core/session')->getIspSearchResultsFor();
30
+ } catch (Exception $e) {
31
+ Mage::log('autocomplete.php _toHtml() Exception => results_for and did you mean calculations'.$e->getMessage(), null, 'autocompleteplus.log');
32
+
33
+ return '';
34
+ }
35
+
36
+ if ($alternatives) {
37
  $params['alternatives'] = json_encode($alternatives);
38
  }
39
+ if ($results_for) {
40
+ $params['results_for'] = urlencode($results_for);
41
+ }
42
+ } else {
43
+ $params['wrong_flow'] = 1;
44
+ }
45
+
46
+ $magento_version = Mage::getVersion();
47
+ $extension_version = (string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
48
+ $versions = ($params == '') ? 'mage_v='.$magento_version.'&ext_v='.$extension_version
49
+ : '&mage_v='.$magento_version.'&ext_v='.$extension_version;
50
+
51
  Mage::getSingleton('core/session')->unsIsFullTextEnable();
52
  Mage::getSingleton('core/session')->unsIspSearchAlternatives();
53
  Mage::getSingleton('core/session')->unsIspSearchResultsFor();
 
 
 
 
54
 
55
+ return '<script data-cfasync="false" async type="text/javascript" src="https://acp-magento.appspot.com/js/magento_full_text.js?'.http_build_query($params).$versions.'"></script>';
56
+ }
57
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Autocorrection.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
 
3
- class Autocompleteplus_Autosuggest_Block_Autocorrection extends Mage_Core_Block_Template {
4
 
5
- protected function _prepareLayout() {
6
-
7
- $header = $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText());
8
- if( Mage::registry('search_results_for') ) {
9
- $header = $this->__("No results for '%s', showing results for '%s'", $this->helper('catalogsearch')->getQueryText(), Mage::registry('search_results_for') );
10
- }
11
- $alternatives = '';
12
- if( Mage::registry('search_alternatives') ) {
13
- $links = array();
14
- foreach(Mage::registry('search_alternatives') as $alternative) {
15
- $links[] = '<a href="' . $this->getUrl('catalogsearch/result', array('q' => $alternative)) . '">' . $alternative . '</a>';
16
- }
 
 
17
 
18
- $alternatives = '</h1><strong>' . $this->__('Did you mean:') . '</strong><p>' . implode(', ', $links) . '</p>';
19
- }
20
 
21
- if ( Mage::registry('search_results_for') || Mage::registry('search_alternatives')) {
22
-
23
- $this->getLayout()
24
- ->getBlock('search.result')
25
- ->setHeaderText($header . $alternatives);
26
- }
27
- }
28
- }
1
+ <?php
2
 
 
3
 
4
+ class Autocompleteplus_Autosuggest_Block_Autocorrection extends Mage_Core_Block_Template
5
+ {
6
+ protected function _prepareLayout()
7
+ {
8
+ $header = $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText());
9
+ if (Mage::registry('search_results_for')) {
10
+ $header = $this->__("No results for '%s', showing results for '%s'", $this->helper('catalogsearch')->getQueryText(), Mage::registry('search_results_for'));
11
+ }
12
+ $alternatives = '';
13
+ if (Mage::registry('search_alternatives')) {
14
+ $links = array();
15
+ foreach (Mage::registry('search_alternatives') as $alternative) {
16
+ $links[] = '<a href="'.$this->getUrl('catalogsearch/result', array('q' => $alternative)).'">'.$alternative.'</a>';
17
+ }
18
 
19
+ $alternatives = '</h1><strong>'.$this->__('Did you mean:').'</strong><p>'.implode(', ', $links).'</p>';
20
+ }
21
 
22
+ if (Mage::registry('search_results_for') || Mage::registry('search_alternatives')) {
23
+ $this->getLayout()
24
+ ->getBlock('search.result')
25
+ ->setHeaderText($header.$alternatives);
26
+ }
27
+ }
28
+ }
 
app/code/local/Autocompleteplus/Autosuggest/Block/Inject.php CHANGED
@@ -10,7 +10,8 @@ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart
10
  protected function _construct()
11
  {
12
  $this->_helper = Mage::helper('autocompleteplus_autosuggest');
13
- $this->_uuid = $this->_helper->getUUID();
 
14
 
15
  //do not cache this block
16
  $this->setCacheLifetime(null);
@@ -18,39 +19,37 @@ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart
18
 
19
  /**
20
  * Test to see if admin is logged in
21
- * by swapping session identifier
22
- * @return boolean
23
- * @todo rewrite this to be cleaner
24
  */
25
  protected function _isAdminLoggedIn()
26
  {
27
- try{
28
- //check if adminhtml cookie is set
29
- if(array_key_exists('adminhtml', $_COOKIE)){
30
- //get session path and add dir seperator and content field of cookie as data name with magento "sess_" prefix
31
- $sessionFilePath = Mage::getBaseDir('session').DS.'sess_'.$_COOKIE['adminhtml'];
32
- if (!file_exists($sessionFilePath)){
33
- return false;
34
- }
35
- //write content of file in var
36
- $sessionFile = @file_get_contents($sessionFilePath);
37
-
38
- //save old session
39
- $oldSession = $_SESSION;
40
- //decode adminhtml session
41
- session_decode($sessionFile);
42
- //save session data from $_SESSION
43
- $adminSessionData = $_SESSION;
44
- //set old session back to current session
45
- $_SESSION = $oldSession;
46
-
47
- return array_key_exists('user', $adminSessionData['admin']);
48
  }
49
- } catch (Exception $e){}
 
 
 
 
 
 
 
50
  }
51
 
52
  /**
53
- * Get the current store code
 
54
  * @return string
55
  */
56
  public function getStoreId()
@@ -59,7 +58,8 @@ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart
59
  }
60
 
61
  /**
62
- * Get the Magento version
 
63
  * @return string
64
  */
65
  public function getMagentoVersion()
@@ -68,9 +68,9 @@ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart
68
  }
69
 
70
  /**
71
- * Get the AUTOCOMPLETEPLUS version
 
72
  * @return string
73
- * @todo move to a helper
74
  */
75
  public function getVersion()
76
  {
@@ -78,7 +78,8 @@ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart
78
  }
79
 
80
  /**
81
- * Get the current product
 
82
  * @return Mage_Catalog_Model_Product
83
  */
84
  public function getProduct()
@@ -87,7 +88,8 @@ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart
87
  }
88
 
89
  /**
90
- * UUID getter
 
91
  * @return string
92
  */
93
  public function getUUID()
@@ -96,34 +98,37 @@ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart
96
  }
97
 
98
  /**
99
- * Get the URL of the current product if it exists
100
- * @return string
 
101
  */
102
  public function getProductUrl()
103
  {
104
- if($product = $this->getProduct()){
105
  return urlencode($product->getProductUrl());
106
  }
107
  }
108
 
109
  /**
110
- * Get the current product's SKU if the product exists
 
111
  * @return string
112
  */
113
  public function getProductSku()
114
  {
115
- if($product = $this->getProduct()){
116
  return $product->getSku();
117
  }
118
  }
119
 
120
  /**
121
- * Get the ID of the current product if it exists
 
122
  * @return string
123
  */
124
  public function getProductIdentifier()
125
  {
126
- if($product = $this->getProduct()){
127
  return $product->getId();
128
  }
129
  }
@@ -134,24 +139,25 @@ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart
134
  }
135
 
136
  /**
137
- * Return a formatted string for the <script src> attr
 
138
  * @return string
139
  */
140
  public function getSrc()
141
  {
142
  $parameters = array(
143
- 'mage_v' =>$this->getMagentoVersion(),
144
- 'ext_v' =>$this->getVersion(),
145
- 'store' =>$this->getStoreId(),
146
- 'UUID' =>$this->getUUID(),
147
- 'product_url' =>$this->getProductUrl(),
148
- 'product_sku' =>$this->getProductSku(),
149
- 'product_id' =>$this->getProductIdentifier(),
150
- 'is_admin_user' =>$this->_isAdminLoggedIn(),
151
- 'sessionID' =>$this->_helper->getSessionId(),
152
- 'QuoteID' =>$this->getQuoteId()
153
  );
154
 
155
- return self::AUTOCOMPLETE_JS_URL . '?' . http_build_query($parameters,'','&');
156
  }
157
- }
10
  protected function _construct()
11
  {
12
  $this->_helper = Mage::helper('autocompleteplus_autosuggest');
13
+ $config = Mage::getModel('autocompleteplus_autosuggest/config');
14
+ $this->_uuid = $config->getUUID();
15
 
16
  //do not cache this block
17
  $this->setCacheLifetime(null);
19
 
20
  /**
21
  * Test to see if admin is logged in
22
+ * by swapping session identifier.
23
+ *
24
+ * @return bool
25
  */
26
  protected function _isAdminLoggedIn()
27
  {
28
+ $io = new Varien_Io_File();
29
+ $cookie = Mage::getModel('core/cookie');
30
+ $sessionCookie = $cookie->get('adminhtml');
31
+ $path = $io->getCleanPath(Mage::getBaseDir('session'));
32
+ $sessionFilePath = $path.DS.'sess_'.$sessionCookie;
33
+
34
+ //check if adminhtml cookie is set
35
+ if ($sessionCookie) {
36
+ //get session path and add dir seperator and content field of cookie as data name with magento "sess_" prefix
37
+ if (!$io->fileExists($sessionFilePath)) {
38
+ return false;
 
 
 
 
 
 
 
 
 
 
39
  }
40
+ //write content of file in var
41
+ $io->open(array('path' => $path));
42
+ $sessionFile = $io->read($sessionFilePath);
43
+ if (stripos($sessionFile, 'Mage_Admin_Model_User')) {
44
+ return true;
45
+ }
46
+
47
+ }
48
  }
49
 
50
  /**
51
+ * Get the current store code.
52
+ *
53
  * @return string
54
  */
55
  public function getStoreId()
58
  }
59
 
60
  /**
61
+ * Get the Magento version.
62
+ *
63
  * @return string
64
  */
65
  public function getMagentoVersion()
68
  }
69
 
70
  /**
71
+ * Get the AUTOCOMPLETEPLUS version.
72
+ *
73
  * @return string
 
74
  */
75
  public function getVersion()
76
  {
78
  }
79
 
80
  /**
81
+ * Get the current product.
82
+ *
83
  * @return Mage_Catalog_Model_Product
84
  */
85
  public function getProduct()
88
  }
89
 
90
  /**
91
+ * UUID getter.
92
+ *
93
  * @return string
94
  */
95
  public function getUUID()
98
  }
99
 
100
  /**
101
+ * Get the URL of the current product if it exists.
102
+ *
103
+ * @return string
104
  */
105
  public function getProductUrl()
106
  {
107
+ if ($product = $this->getProduct()) {
108
  return urlencode($product->getProductUrl());
109
  }
110
  }
111
 
112
  /**
113
+ * Get the current product's SKU if the product exists.
114
+ *
115
  * @return string
116
  */
117
  public function getProductSku()
118
  {
119
+ if ($product = $this->getProduct()) {
120
  return $product->getSku();
121
  }
122
  }
123
 
124
  /**
125
+ * Get the ID of the current product if it exists.
126
+ *
127
  * @return string
128
  */
129
  public function getProductIdentifier()
130
  {
131
+ if ($product = $this->getProduct()) {
132
  return $product->getId();
133
  }
134
  }
139
  }
140
 
141
  /**
142
+ * Return a formatted string for the <script src> attr.
143
+ *
144
  * @return string
145
  */
146
  public function getSrc()
147
  {
148
  $parameters = array(
149
+ 'mage_v' => $this->getMagentoVersion(),
150
+ 'ext_v' => $this->getVersion(),
151
+ 'store' => $this->getStoreId(),
152
+ 'UUID' => $this->getUUID(),
153
+ 'product_url' => $this->getProductUrl(),
154
+ 'product_sku' => $this->getProductSku(),
155
+ 'product_id' => $this->getProductIdentifier(),
156
+ 'is_admin_user' => $this->_isAdminLoggedIn(),
157
+ 'sessionID' => $this->_helper->getSessionId(),
158
+ 'QuoteID' => $this->getQuoteId(),
159
  );
160
 
161
+ return self::AUTOCOMPLETE_JS_URL.'?'.http_build_query($parameters, '', '&');
162
  }
163
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Notifications.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,11 +9,10 @@
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
-
18
  class Autocompleteplus_Autosuggest_Block_Notifications extends Mage_Core_Block_Template
19
  {
20
  /**
@@ -25,21 +23,22 @@ class Autocompleteplus_Autosuggest_Block_Notifications extends Mage_Core_Block_T
25
  /** @var Autocompleteplus_Autosuggest_Model_Mysql4_Notifications_Collection $collection */
26
  $collection = Mage::getModel('autocompleteplus_autosuggest/notifications')
27
  ->getCollection();
 
28
  return $collection->addTypeFilter('alert')->addActiveFilter();
29
  }
30
 
31
- public function localhostSynced(){
32
-
33
  $helper = Mage::helper('autocompleteplus_autosuggest');
34
 
35
- $isReachable=$helper->getIsReachable();
36
 
37
- $syncWasStarted=$helper->getIfSyncWasInitiated();
38
 
39
- if(!$isReachable && !$syncWasStarted){
40
  return true;
41
- }else{
42
  return false;
43
  }
44
  }
45
- }
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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_Block_Notifications extends Mage_Core_Block_Template
17
  {
18
  /**
23
  /** @var Autocompleteplus_Autosuggest_Model_Mysql4_Notifications_Collection $collection */
24
  $collection = Mage::getModel('autocompleteplus_autosuggest/notifications')
25
  ->getCollection();
26
+
27
  return $collection->addTypeFilter('alert')->addActiveFilter();
28
  }
29
 
30
+ public function localhostSynced()
31
+ {
32
  $helper = Mage::helper('autocompleteplus_autosuggest');
33
 
34
+ $isReachable = $helper->getIsReachable();
35
 
36
+ $syncWasStarted = $helper->getIfSyncWasInitiated();
37
 
38
+ if (!$isReachable && !$syncWasStarted) {
39
  return true;
40
+ } else {
41
  return false;
42
  }
43
  }
44
+ }
app/code/local/Autocompleteplus/Autosuggest/Controller/Abstract.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Autocompleteplus_Autosuggest_Controller_Abstract extends Mage_Core_Controller_Front_Action
4
+ {
5
+ const PHP_SCRIPT_TIMEOUT = 1800;
6
+ const MISSING_PARAMETER = 767;
7
+ const STATUS_FAILURE = 'failure';
8
+
9
+ public function preDispatch()
10
+ {
11
+ parent::preDispatch();
12
+ set_time_limit(self::PHP_SCRIPT_TIMEOUT);
13
+ }
14
+ }
app/code/local/Autocompleteplus/Autosuggest/Helper/Data.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
  *
5
  * NOTICE OF LICENSE
6
  *
@@ -9,125 +9,103 @@
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
-
17
  class Autocompleteplus_Autosuggest_Helper_Data extends Mage_Core_Helper_Abstract
18
  {
19
- // private $server_url = 'http://0-2vk.acp-magento.appspot.com';
20
  private $server_url = 'http://magento.instantsearchplus.com';
21
 
22
  protected $_authKey;
23
 
24
- public function getServerUrl(){
 
25
  return $this->server_url;
26
  }
27
 
28
- public function getVersion()
 
 
 
 
 
 
 
 
 
 
 
29
  {
30
- return (string)Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
31
  }
32
 
33
- public function getConfigDataByFullPath($path){
 
 
 
34
 
 
 
35
  if (!$row = Mage::getSingleton('core/config_data')->getCollection()->getItemByColumnValue('path', $path)) {
36
  $conf = Mage::getSingleton('core/config')->init()->getXpath('/config/default/'.$path);
37
- if(is_array($conf)){
38
  $value = array_shift($conf);
39
- }else{
40
  return '';
41
  }
42
-
43
  } else {
44
  $value = $row->getValue();
45
  }
46
 
47
  return $value;
48
-
49
  }
50
 
51
- public function getConfigMultiDataByFullPath($path){
 
 
52
 
53
  if (!$rows = Mage::getSingleton('core/config_data')->getCollection()->getItemsByColumnValue('path', $path)) {
54
  $conf = Mage::getSingleton('core/config')->init()->getXpath('/config/default/'.$path);
55
- $value = array_shift($conf);
56
  } else {
57
- $values=array();
58
- foreach($rows as $row){
59
- $values[$row->getScopeId()]=$row->getValue();
60
  }
61
  }
62
 
63
  return $values;
64
-
65
  }
66
 
67
- public function sendCurl($command){
68
-
69
- if(isset($ch)) unset($ch);
 
 
70
 
71
- if(function_exists('curl_setopt')){
72
- $ch = curl_init();
73
  curl_setopt($ch, CURLOPT_URL, $command);
74
  curl_setopt($ch, CURLOPT_HEADER, 0);
75
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
76
  curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
77
- $str=curl_exec($ch);
78
- }else{
79
- $str='failed';
80
  }
81
 
82
  return $str;
83
-
84
-
85
  }
86
 
87
- public function getKey(){
88
-
89
- if(!$this->_authKey){
90
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
91
- $sqlFetch = 'SELECT authkey FROM '. $_tableprefix.'autocompleteplus_config WHERE id = 1 LIMIT 1';
92
- $read = Mage::getSingleton('core/resource')->getConnection('core_read');
93
- $this->_authKey = $read->fetchOne($sqlFetch);
94
  }
95
 
96
- return $this->_authKey;
97
- }
98
-
99
- public function getBothKeys(){
100
-
101
- $read = Mage::getSingleton('core/resource')->getConnection('core_read');
102
-
103
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
104
-
105
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
106
-
107
- $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
108
-
109
- if(!$tblExist){return;}
110
-
111
- $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
112
-
113
- $licenseData=$read->fetchAll($sql);
114
-
115
- $key=$licenseData[0]['licensekey'];
116
-
117
- $authKey= $licenseData[0]['authkey'];
118
-
119
- $res=array('uuid'=>$key,'authkey'=>$authKey);
120
-
121
- return $res;
122
- }
123
-
124
- public static function sendPostCurl($command, $data=array(),$cookie_file='genCookie.txt') {
125
-
126
- if(isset($ch)) unset($ch);
127
-
128
- if(function_exists('curl_setopt')){
129
-
130
- $ch = curl_init();
131
  curl_setopt($ch, CURLOPT_URL, $command);
132
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
133
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
@@ -136,22 +114,20 @@ class Autocompleteplus_Autosuggest_Helper_Data extends Mage_Core_Helper_Abstract
136
  curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
137
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0');
138
  //curl_setopt($ch,CURLOPT_POST,0);
139
- if(!empty($data)){
140
  curl_setopt_array($ch, array(
141
  CURLOPT_POSTFIELDS => $data,
142
  ));
143
  }
144
 
145
-
146
  // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
147
  // 'Connection: Keep-Alive',
148
  // 'Keep-Alive: 800'
149
  // ));
150
 
151
- $str=curl_exec($ch);
152
-
153
- }else{
154
- $str='failed';
155
  }
156
 
157
  return $str;
@@ -164,34 +140,34 @@ class Autocompleteplus_Autosuggest_Helper_Data extends Mage_Core_Helper_Abstract
164
  $prices = array();
165
  foreach ($aProductIds as $ids) {
166
  foreach ($ids as $id) {
167
- try{
168
  $aProduct = Mage::getModel('catalog/product')->load($id);
169
  $prices[] = $aProduct->getPriceModel()->getPrice($aProduct);
170
- } catch (Exception $e){
171
  continue;
172
  }
173
  }
174
  }
175
 
176
  krsort($prices);
177
- try{
178
- if (count($prices) > 0){
179
  $groupedProduct->setPrice($prices[0]);
180
  } else {
181
  $groupedProduct->setPrice(0);
182
  }
183
- } catch (Exception $e){
184
  $groupedProduct->setPrice(0);
185
  }
186
 
187
  // or you can return price
188
  }
189
 
190
- public function getBundlePrice($product) {
191
-
192
- $optionCol= $product->getTypeInstance(true)
193
  ->getOptionsCollection($product);
194
- $selectionCol= $product->getTypeInstance(true)
195
  ->getSelectionsCollection(
196
  $product->getTypeInstance(true)->getOptionsIds($product),
197
  $product
@@ -200,202 +176,195 @@ class Autocompleteplus_Autosuggest_Helper_Data extends Mage_Core_Helper_Abstract
200
  $price = $product->getPrice();
201
 
202
  foreach ($optionCol as $option) {
203
- if($option->required) {
204
  $selections = $option->getSelections();
205
- $selPricesArr=array();
206
 
207
- if(is_array($selections)){
208
-
209
- foreach($selections as $s){
210
- $selPricesArr[]=$s->price;
211
  }
212
 
213
-
214
-
215
  $minPrice = min($selPricesArr);
216
 
217
- if($product->getSpecialPrice() > 0) {
218
- $minPrice *= $product->getSpecialPrice()/100;
219
  }
220
 
221
- $price += round($minPrice,2);
222
-
223
  }
224
  }
225
  }
226
- return $price;
227
 
 
228
  }
229
 
230
- public function getMultiStoreDataJson(){
231
-
232
- $websites=Mage::getModel('core/website')->getCollection();
233
 
234
- $multistoreData=array();
235
- $multistoreJson='';
236
- $useStoreCode=$this->getConfigDataByFullPath('web/url/use_store');
237
- $mage=Mage::getVersion();
238
- $ext=Mage::helper('autocompleteplus_autosuggest')->getVersion();
239
- $version=array('mage'=>$mage,'ext'=>$ext);
240
 
241
  //getting site url
242
- $url=$this->getConfigDataByFullPath('web/unsecure/base_url');
243
 
244
  //getting site owner email
245
- $storeMail=$this->getConfigDataByFullPath('autocompleteplus/config/store_email');
246
-
247
- if(!$storeMail){
248
 
249
- $storeMail=$this->getConfigDataByFullPath('trans_email/ident_general/email');
 
250
  }
251
 
252
- $collection=Mage::getModel('catalog/product')->getCollection();
253
  //$productCount=$collection->count();
254
 
255
-
256
- $storesArr=array();
257
- foreach($websites as $website){
258
- $code=$website->getCode();
259
- $stores=$website->getStores();
260
- foreach($stores as $store){
261
- $storesArr[$store->getStoreId()]=$store->getData();
262
  }
263
  }
264
 
265
- if(count($storesArr)==1){
266
- try{
267
  $dataArr = array(
268
  // 'stores' => array(array_pop($storesArr)),
269
- 'stores' => array_pop($storesArr),
270
- 'version' => $version
271
  );
272
- } catch (Exception $e){
273
  $dataArr = array(
274
- 'stores' => $multistoreData,
275
- 'version' => $version
276
  );
277
- }
278
 
279
- $dataArr['site'] = $url;
280
  $dataArr['email'] = $storeMail;
281
 
282
  $multistoreJson = json_encode($dataArr);
 
 
 
 
283
 
284
- }else{
285
-
286
- $storeUrls=$this->getConfigMultiDataByFullPath('web/unsecure/base_url');
287
- $locales=$this->getConfigMultiDataByFullPath('general/locale/code');
288
- $storeComplete=array();
289
-
290
- foreach($storesArr as $key=>$value){
291
-
292
- if(!$value['is_active']){
293
  continue;
294
  }
295
 
296
- $storeComplete=$value;
297
- if(array_key_exists($key,$locales)){
298
- $storeComplete['lang']=$locales[$key];
299
- }else{
300
- $storeComplete['lang']=$locales[0];
301
  }
302
 
303
- if(array_key_exists($key,$storeUrls)){
304
- $storeComplete['url']=$storeUrls[$key];
305
- }else{
306
- $storeComplete['url']=$storeUrls[0];
307
  }
308
 
309
- if($useStoreCode){
310
- $storeComplete['url']=$storeUrls[0].$value['code'];
311
  }
312
 
313
- $multistoreData[]=$storeComplete;
314
  }
315
 
316
- $dataArr=array(
317
- 'stores'=>$multistoreData,
318
- 'version'=>$version
319
  );
320
 
321
- $dataArr['site']=$url;
322
- $dataArr['email']=$storeMail;
323
  //$dataArr['product_count']=$productCount;
324
 
325
- $multistoreJson=json_encode($dataArr);
326
-
327
  }
328
- Mage::log($multistoreJson,null,'autocomplete.log');
329
 
330
  return $multistoreJson;
331
  }
332
 
333
- public function getExtensionConflict($all_conflicts = false){
 
334
  $all_rewrite_classes = array();
335
  $node_type_list = array('model', 'helper', 'block');
336
 
337
- foreach ($node_type_list as $node_type){
338
  foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module) {
339
- if ($module->codePool == 'core' || $module->active != 'true'){
340
  continue;
341
  }
342
- $config_file_path = Mage::getConfig()->getModuleDir('etc', $name) . DS . 'config.xml';
343
  $config = new Varien_Simplexml_Config();
344
  $config->loadString('<config/>');
345
  $config->loadFile($config_file_path);
346
  $config->extend($config, true);
347
 
348
- $nodes = $config->getNode()->global->{$node_type . 's'};
349
- if (!$nodes)
350
  continue;
351
- foreach($nodes->children() as $node_name => $config) {
352
- if ($config->rewrite){ // there is rewrite for current config
353
- foreach($config->rewrite->children() as $class_tag => $derived_class){
 
354
  $base_class_name = $this->_getMageBaseClass($node_type, $node_name, $class_tag);
355
 
356
  $lead_derived_class = '';
357
- $conf = Mage::getConfig()->getNode()->global->{$node_type . 's'}->{$node_name};
358
- if (isset($conf->rewrite->$class_tag)){
359
- $lead_derived_class = (string)$conf->rewrite->$class_tag;
360
  }
361
- if ($derived_class == ''){
362
  $derived_class = $lead_derived_class;
363
  }
364
 
365
- if (empty($all_rewrite_classes[$base_class_name])){
366
  $all_rewrite_classes[$base_class_name] = array(
367
- 'derived' => array((string)$derived_class),
368
- 'lead' => (string)$lead_derived_class,
369
- 'tag' => $class_tag,
370
- 'name' => array((string)$name)
371
  );
372
- }else{
373
- array_push($all_rewrite_classes[$base_class_name]['derived'], (string)$derived_class);
374
- array_push($all_rewrite_classes[$base_class_name]['name'], (string)$name);
375
  }
376
  }
377
  }
378
  }
379
  }
380
  }
381
- if ($all_conflicts){
382
  return $all_rewrite_classes;
383
  }
384
 
385
  $isp_rewrite_classes = array();
386
  $isp_module_name = 'Autocompleteplus_Autosuggest';
387
- foreach ($all_rewrite_classes as $base => $conflict_info){
388
- if (in_array($isp_module_name, $conflict_info['name'])){ // if isp extension rewrite this base class
389
- if (count($conflict_info['derived']) > 1){ // more then 1 class rewrite this base class => there is a conflict
390
  $isp_rewrite_classes[$base] = $conflict_info;
391
  }
392
  }
393
  }
 
394
  return $isp_rewrite_classes;
395
  }
396
 
397
- protected function _getMageBaseClass($node_type, $node_name, $class_tag){
398
- $config = Mage::getConfig()->getNode()->global->{$node_type . 's'}->$node_name;
 
399
 
400
  if (!empty($config)) {
401
  $className = $config->getClassName();
@@ -406,33 +375,36 @@ class Autocompleteplus_Autosuggest_Helper_Data extends Mage_Core_Helper_Abstract
406
  if (!empty($class_tag)) {
407
  $className .= '_'.$class_tag;
408
  }
 
409
  return uc_words($className);
410
  }
411
 
412
  /**
413
- * Checksum functionality
414
  */
415
- public function isChecksumTableExists(){
416
- $table_prefix = (string)Mage::getConfig()->getTablePrefix();
 
417
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
418
- if ($read->showTableStatus($table_prefix . 'autocompleteplus_checksum')){
419
  return true;
420
  } else {
421
  return false;
422
  }
423
  }
424
 
425
- public function calculateChecksum($product){
426
- $product_id = $product->getId();
427
- $product_title = $product->getName();
428
- $product_description = $product->getDescription();
429
- $product_short_desc = $product->getShortDescription();
430
- $product_url = $product->getUrlPath(); //Mage::helper('catalog/product')->getProductUrl($product_id); | $product->getProductUrl()
431
- $product_visibility = $product->getVisibility();
432
- $product_in_stock = $product->isInStock();
433
- $product_price = (float)$product->getPrice();
434
- try{
435
- $product_thumb_url = '/' . $product->getImage();
 
436
 
437
  // $product_thumb_url = $product->getThumbnailUrl(); //Mage::helper('catalog/image')->init($product, 'thumbnail');
438
  // $thumb_pattern = '/\/[^\/]+(?![^\/]*\/)/';
@@ -441,325 +413,354 @@ class Autocompleteplus_Autosuggest_Helper_Data extends Mage_Core_Helper_Abstract
441
  // } else {
442
  // $product_thumb_url = '';
443
  // }
444
- } catch (Exception $e){
445
  $product_thumb_url = '';
446
  }
447
  $product_type = $product->getTypeID();
448
 
449
- $checksum_string = $product_id . $product_title . $product_description . $product_short_desc . $product_url .
450
- $product_visibility . $product_in_stock . $product_price . $product_thumb_url . $product_type;
451
 
452
  $checksum_md5 = md5($checksum_string);
 
453
  return $checksum_md5;
454
  }
455
 
456
- public function getSavedChecksum($table_prefix, $read, $product_id, $store_id){
457
- $sql_fetch = 'SELECT checksum FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
 
458
  $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
459
- if($updates && (count($updates) != 0)){
460
  return $updates[0]['checksum'];
461
  } else {
462
  return '';
463
  }
464
  }
465
 
466
- public function updateSavedProductChecksum($table_prefix, $read, $write, $product_id, $sku, $store_id, $checksum){
467
- if ($product_id == null || $sku == null){
 
468
  return;
469
  }
470
- $sql_fetch = 'SELECT checksum FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
471
- $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
 
 
 
 
472
 
473
- if($updates && (count($updates) != 0)){
474
- if ($updates[0]['checksum'] != $checksum){
475
- $sql = 'UPDATE '. $table_prefix.'autocompleteplus_checksum SET checksum=? WHERE identifier=? AND store_id=?';
476
- $write->query($sql, array($checksum, $product_id, $store_id));
477
  }
478
- }else{
479
- $sql = 'INSERT INTO '. $table_prefix.'autocompleteplus_checksum (identifier, sku, store_id, checksum) VALUES (?,?,?,?)';
480
- $write->query($sql, array($product_id, $sku, $store_id, $checksum));
 
 
 
481
  }
482
  }
483
 
484
- public function updateDeletedProductChecksum($table_prefix, $read, $write, $product_id, $sku, $store_id){
485
- if ($product_id == null){
 
486
  return;
487
  }
488
- $sql_fetch = 'SELECT * FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
489
- $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
490
 
491
- if($updates && (count($updates) != 0)){
492
- $sql = 'DELETE FROM '. $table_prefix.'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
493
- $write->query($sql, array($product_id, $store_id));
 
 
 
 
 
494
  }
495
  }
496
 
497
- private function setUpdateNeededForProduct($read, $write, $product_id, $product_sku, $store_id){
498
- if ($product_id == null){
 
499
  return;
500
  }
501
- if ($sku == null){
502
- $sku = 'dummy_sku';
503
  }
504
- try{
505
- $table_prefix = (string)Mage::getConfig()->getTablePrefix();
506
  $is_table_exist = $write->showTableStatus($table_prefix.'autocompleteplus_batches');
507
- if (!$is_table_exist) // table not exists
508
  return;
509
-
510
- $sql_fetch = 'SELECT * FROM '. $table_prefix.'autocompleteplus_batches WHERE product_id=? AND store_id=?';
 
511
  $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
512
 
513
- if ($updates && (count($updates) != 0)){
514
- $sql = 'UPDATE '. $table_prefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id=? AND store_id=?';
515
- $write->query($sql, array(strtotime('now'), "update", $product_id, $store_id));
516
- }else{
517
- $sql='INSERT INTO '. $table_prefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
518
- $write->query($sql, array($product_id, $store_id, strtotime('now'), "update", $product_sku));
519
  }
520
-
521
- }catch(Exception $e){
522
- Mage::log('Exception raised in setUpdateNeededForProduct() - ' . $e->getMessage(), null, 'autocompleteplus.log');
523
- $this->ispErrorLog('Exception raised in setUpdateNeededForProduct() - ' . $e->getMessage());
524
  }
525
  }
526
 
527
- public function compareProductsChecksum($from, $count, $store_id = null){
 
528
  $num_of_updates = 0;
529
- if (!$this->isChecksumTableExists())
530
  return;
 
531
 
532
  $products = Mage::getModel('catalog/product')->getCollection();
533
- if ($store_id){
534
  $products->addStoreFilter($store_id);
535
  }
536
  $products->getSelect()->limit($count, $from);
537
  $products->load();
538
 
539
- $table_prefix = (string)Mage::getConfig()->getTablePrefix();
540
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
541
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
542
 
543
  foreach ($products as $product) {
544
- try{
545
  $product_collection_data = $product->getData();
546
  $product_model = Mage::getModel('catalog/product')
547
  ->setStore($store_id)->setStoreId($store_id)
548
  ->load($product_collection_data['entity_id']);
549
-
550
- $current_checksum = $this->getSavedChecksum($table_prefix, $read, $product_model->getId(), $store_id );
551
  $new_checksum = $this->calculateChecksum($product_model);
552
- }catch(Exception $e){
553
- Mage::log('Exception raised in compareProductsChecksum() on id: ' . $product->getId() . ' -> ' . $e->getMessage(), null, 'autocompleteplus.log');
554
- $this->ispErrorLog('Exception raised in compareProductsChecksum() on id: ' . $product->getId() . ' -> ' . $e->getMessage());
 
555
  return 0;
556
  }
557
- if ($current_checksum == '' || $current_checksum != $new_checksum){
558
- $num_of_updates++;
559
  $this->updateSavedProductChecksum($table_prefix, $read, $write, $product_model->getId(), $product_model->getSku(),
560
  $store_id, $new_checksum);
561
  $this->setUpdateNeededForProduct($read, $write, $product_model->getId(), $product_model->getSku(), $store_id);
562
  }
563
  }
 
564
  return $num_of_updates;
565
  }
566
 
567
- public function deleteProductFromTables($read, $write, $table_prefix, $product_id, $store_id){
 
568
  $dt = strtotime('now');
569
  $sku = 'dummy_sku';
570
- $sqlFetch = 'SELECT * FROM '. $table_prefix.'autocompleteplus_batches WHERE product_id = ? AND store_id=?';
571
  $updates = $read->fetchAll($sqlFetch, array($product_id, $store_id));
572
 
573
- if($updates && count($updates) != 0){
574
- $sql = 'UPDATE '. $table_prefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id = ? AND store_id = ?';
575
- $write->query($sql, array($dt, "remove", $product_id, $store_id));
576
  } else {
577
- $sql='INSERT INTO '. $table_prefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
578
- $write->query($sql, array($product_id, $store_id, $dt, "remove", $sku));
579
  }
580
 
581
  $this->updateDeletedProductChecksum($table_prefix, $read, $write, $product_id, $sku, $store_id);
582
  }
583
 
584
- public function ispLog($log){
 
585
  Mage::log($log, null, 'autocompleteplus.log');
586
  }
587
 
588
- public function ispErrorLog($log){
589
- $uuid = $this->getUUID();
590
- $site_url = $this->getConfigDataByFullPath('web/unsecure/base_url');
591
- $store_id = Mage::app()->getStore()->getStoreId();
 
592
 
593
- $server_url = $this->server_url . '/magento_logging_error';
594
- $request = $server_url . '?uuid=' . $uuid . '&site_url=' . $site_url . '&store_id=' . $store_id . '&msg=' . urlencode($log);
595
 
596
  $resp = $this->sendCurl($request);
597
  }
598
 
599
- public function getUUID(){
600
-
601
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
602
 
603
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
604
 
605
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
606
 
607
- $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
608
 
609
- if(!$tblExist){return '';}
 
 
610
 
611
- $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
612
 
613
- $licenseData=$read->fetchAll($sql);
614
 
615
- $key=$licenseData[0]['licensekey'];
616
 
617
  return $key;
618
-
619
  }
620
 
621
- public function getIsReachable(){
622
-
623
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
624
 
625
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
626
 
627
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
628
 
629
- $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
630
 
631
- if(!$tblExist){return '';}
 
 
632
 
633
- $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
634
 
635
- $licenseData=$read->fetchAll($sql);
636
 
637
- $is_reachable=$licenseData[0]['is_reachable'];
638
 
639
  return $is_reachable;
640
-
641
  }
642
-
643
- public function getServerEndPoint(){
644
- try{
 
645
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
646
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
647
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
648
- $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
649
-
650
- if(!$tblExist){
651
  return '';
652
  }
653
-
654
- $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
655
- $licenseData=$read->fetchAll($sql);
656
- if (array_key_exists('server_type', $licenseData[0])){
657
  $key = $licenseData[0]['server_type'];
658
  } else {
659
  $key = '';
660
  }
661
- } catch(Exception $e){
662
  $key = '';
663
  }
 
664
  return $key;
665
  }
666
-
667
- public function setServerEndPoint($end_point){
668
- try{
669
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
 
670
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
671
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
672
- $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
673
-
674
- if(!$tblExist){
675
  return;
676
  }
677
-
678
- $sqlFetch = 'SELECT * FROM '. $_tableprefix.'autocompleteplus_config WHERE id = 1';
679
  $updates = $write->fetchAll($sqlFetch);
680
-
681
- if($updates&&count($updates)!=0){
682
- $sql='UPDATE '. $_tableprefix.'autocompleteplus_config SET server_type=? WHERE id = 1';
683
  $write->query($sql, array($end_point));
684
- }else{
685
- Mage::log('cant update server_type',null,'autocompleteplus.log');
686
  }
687
- }catch(Exception $e){
688
- Mage::log($e->getMessage(),null,'autocompleteplus.log');
689
  }
690
  }
691
 
692
- public function getErrormessage(){
693
-
694
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
695
 
696
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
697
 
698
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
699
 
700
- $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
701
 
702
- if(!$tblExist){return '';}
 
 
703
 
704
- $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
705
 
706
- $licenseData=$read->fetchAll($sql);
707
 
708
- $errormessage=$licenseData[0]['errormessage'];
709
 
710
  return $errormessage;
711
-
712
  }
713
 
714
- public function getIfSyncWasInitiated(){
 
715
  $collection = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection();
716
 
717
- $count=$collection->count();
718
 
719
- if($count==0){
720
  return false;
721
- }else{
722
  return true;
723
  }
724
  }
725
 
726
- public function getPushId(){
727
-
728
  $collection = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()
729
- ->addFilter('sent',0);
730
 
731
  $collection->getSelect()->limit(1);
732
 
733
  $collection->load();
734
 
735
- $id='';
736
 
737
  foreach ($collection as $p) {
738
- $id=$p->getId();
739
  }
740
 
741
  return $id;
742
  }
743
 
744
- public function getPushUrl($id=null){
745
-
746
- if($id==null){
747
- $id=$this->getPushId();
748
  }
749
 
750
- $url=Mage::getUrl();//'',array('pushid'=>$id));
751
 
752
- if (strpos($url, 'index.php') !== FALSE){
753
- $url=$url.'/autocompleteplus/products/pushbulk/pushid/'.$id;
754
- }else{
755
- $url=$url.'index.php/autocompleteplus/products/pushbulk/pushid/'.$id;
756
  }
757
- return $url;
758
 
 
759
  }
760
 
761
- public function escapeXml($xml){
762
- // $pairs = array(
 
763
  // "\x03" => "&#x03;",
764
  // "\x05" => "&#x05;",
765
  // "\x0E" => "&#x0E;",
@@ -767,30 +768,31 @@ class Autocompleteplus_Autosuggest_Helper_Data extends Mage_Core_Helper_Abstract
767
  // );
768
  // $xml = strtr($xml, $pairs);
769
 
770
- $xml=preg_replace('/[\x00-\x1f]/', '', $xml);
 
771
  return $xml;
772
  }
773
 
774
-
775
  /**
776
  * Get the session cookie value
777
- * protected with a salt (the store encryption key)
 
778
  * @return string
779
  */
780
  public function getSessionId()
781
  {
782
- return md5(Mage::app()->getCookie()->get('frontend') . $this->_getEncryptionKey());
783
  }
784
 
785
  /**
786
  * Return encryption key in Magento to use as salt
787
  * Requires getting from configNode so that it is backward
788
- * compatible with later versions
 
789
  * @return string
790
  */
791
  protected function _getEncryptionKey()
792
  {
793
  return (string) Mage::getConfig()->getNode('global/crypt/key');
794
  }
795
-
796
- }
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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_Helper_Data extends Mage_Core_Helper_Abstract
17
  {
18
+ // private $server_url = 'http://0-2vk.acp-magento.appspot.com';
19
  private $server_url = 'http://magento.instantsearchplus.com';
20
 
21
  protected $_authKey;
22
 
23
+ public function getServerUrl()
24
+ {
25
  return $this->server_url;
26
  }
27
 
28
+ public function validateUuid($uuid)
29
+ {
30
+ if (strlen($uuid) == 36
31
+ && substr_count($uuid, '-') == 4
32
+ ) {
33
+ return true;
34
+ }
35
+
36
+ return false;
37
+ }
38
+
39
+ public function getConfig()
40
  {
41
+ return Mage::getModel('autocompleteplus_autosuggest/config');
42
  }
43
 
44
+ public function getVersion()
45
+ {
46
+ return (string) Mage::getConfig()->getModuleConfig('Autocompleteplus_Autosuggest')->version;
47
+ }
48
 
49
+ public function getConfigDataByFullPath($path)
50
+ {
51
  if (!$row = Mage::getSingleton('core/config_data')->getCollection()->getItemByColumnValue('path', $path)) {
52
  $conf = Mage::getSingleton('core/config')->init()->getXpath('/config/default/'.$path);
53
+ if (is_array($conf)) {
54
  $value = array_shift($conf);
55
+ } else {
56
  return '';
57
  }
 
58
  } else {
59
  $value = $row->getValue();
60
  }
61
 
62
  return $value;
 
63
  }
64
 
65
+ public function getConfigMultiDataByFullPath($path)
66
+ {
67
+ $values = array();
68
 
69
  if (!$rows = Mage::getSingleton('core/config_data')->getCollection()->getItemsByColumnValue('path', $path)) {
70
  $conf = Mage::getSingleton('core/config')->init()->getXpath('/config/default/'.$path);
71
+ $values[] = array_shift($conf);
72
  } else {
73
+ foreach ($rows as $row) {
74
+ $values[$row->getScopeId()] = $row->getValue();
 
75
  }
76
  }
77
 
78
  return $values;
 
79
  }
80
 
81
+ public function sendCurl($command)
82
+ {
83
+ if (isset($ch)) {
84
+ unset($ch);
85
+ }
86
 
87
+ if (function_exists('curl_setopt')) {
88
+ $ch = curl_init();
89
  curl_setopt($ch, CURLOPT_URL, $command);
90
  curl_setopt($ch, CURLOPT_HEADER, 0);
91
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
92
  curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
93
+ $str = curl_exec($ch);
94
+ } else {
95
+ $str = 'failed';
96
  }
97
 
98
  return $str;
 
 
99
  }
100
 
101
+ public static function sendPostCurl($command, $data = array(), $cookie_file = 'genCookie.txt')
102
+ {
103
+ if (isset($ch)) {
104
+ unset($ch);
 
 
 
105
  }
106
 
107
+ if (function_exists('curl_setopt')) {
108
+ $ch = curl_init();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  curl_setopt($ch, CURLOPT_URL, $command);
110
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
111
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
114
  curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
115
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0');
116
  //curl_setopt($ch,CURLOPT_POST,0);
117
+ if (!empty($data)) {
118
  curl_setopt_array($ch, array(
119
  CURLOPT_POSTFIELDS => $data,
120
  ));
121
  }
122
 
 
123
  // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
124
  // 'Connection: Keep-Alive',
125
  // 'Keep-Alive: 800'
126
  // ));
127
 
128
+ $str = curl_exec($ch);
129
+ } else {
130
+ $str = 'failed';
 
131
  }
132
 
133
  return $str;
140
  $prices = array();
141
  foreach ($aProductIds as $ids) {
142
  foreach ($ids as $id) {
143
+ try {
144
  $aProduct = Mage::getModel('catalog/product')->load($id);
145
  $prices[] = $aProduct->getPriceModel()->getPrice($aProduct);
146
+ } catch (Exception $e) {
147
  continue;
148
  }
149
  }
150
  }
151
 
152
  krsort($prices);
153
+ try {
154
+ if (count($prices) > 0) {
155
  $groupedProduct->setPrice($prices[0]);
156
  } else {
157
  $groupedProduct->setPrice(0);
158
  }
159
+ } catch (Exception $e) {
160
  $groupedProduct->setPrice(0);
161
  }
162
 
163
  // or you can return price
164
  }
165
 
166
+ public function getBundlePrice($product)
167
+ {
168
+ $optionCol = $product->getTypeInstance(true)
169
  ->getOptionsCollection($product);
170
+ $selectionCol = $product->getTypeInstance(true)
171
  ->getSelectionsCollection(
172
  $product->getTypeInstance(true)->getOptionsIds($product),
173
  $product
176
  $price = $product->getPrice();
177
 
178
  foreach ($optionCol as $option) {
179
+ if ($option->required) {
180
  $selections = $option->getSelections();
181
+ $selPricesArr = array();
182
 
183
+ if (is_array($selections)) {
184
+ foreach ($selections as $s) {
185
+ $selPricesArr[] = $s->price;
 
186
  }
187
 
 
 
188
  $minPrice = min($selPricesArr);
189
 
190
+ if ($product->getSpecialPrice() > 0) {
191
+ $minPrice *= $product->getSpecialPrice() / 100;
192
  }
193
 
194
+ $price += round($minPrice, 2);
 
195
  }
196
  }
197
  }
 
198
 
199
+ return $price;
200
  }
201
 
202
+ public function getMultiStoreDataJson()
203
+ {
204
+ $websites = Mage::getModel('core/website')->getCollection();
205
 
206
+ $multistoreData = array();
207
+ $multistoreJson = '';
208
+ $useStoreCode = $this->getConfigDataByFullPath('web/url/use_store');
209
+ $mage = Mage::getVersion();
210
+ $ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
211
+ $version = array('mage' => $mage, 'ext' => $ext);
212
 
213
  //getting site url
214
+ $url = $this->getConfigDataByFullPath('web/unsecure/base_url');
215
 
216
  //getting site owner email
217
+ $storeMail = $this->getConfigDataByFullPath('autocompleteplus/config/store_email');
 
 
218
 
219
+ if (!$storeMail) {
220
+ $storeMail = $this->getConfigDataByFullPath('trans_email/ident_general/email');
221
  }
222
 
223
+ $collection = Mage::getModel('catalog/product')->getCollection();
224
  //$productCount=$collection->count();
225
 
226
+ $storesArr = array();
227
+ foreach ($websites as $website) {
228
+ $code = $website->getCode();
229
+ $stores = $website->getStores();
230
+ foreach ($stores as $store) {
231
+ $storesArr[$store->getStoreId()] = $store->getData();
 
232
  }
233
  }
234
 
235
+ if (count($storesArr) == 1) {
236
+ try {
237
  $dataArr = array(
238
  // 'stores' => array(array_pop($storesArr)),
239
+ 'stores' => array_pop($storesArr),
240
+ 'version' => $version,
241
  );
242
+ } catch (Exception $e) {
243
  $dataArr = array(
244
+ 'stores' => $multistoreData,
245
+ 'version' => $version,
246
  );
247
+ }
248
 
249
+ $dataArr['site'] = $url;
250
  $dataArr['email'] = $storeMail;
251
 
252
  $multistoreJson = json_encode($dataArr);
253
+ } else {
254
+ $storeUrls = $this->getConfigMultiDataByFullPath('web/unsecure/base_url');
255
+ $locales = $this->getConfigMultiDataByFullPath('general/locale/code');
256
+ $storeComplete = array();
257
 
258
+ foreach ($storesArr as $key => $value) {
259
+ if (!$value['is_active']) {
 
 
 
 
 
 
 
260
  continue;
261
  }
262
 
263
+ $storeComplete = $value;
264
+ if (array_key_exists($key, $locales)) {
265
+ $storeComplete['lang'] = $locales[$key];
266
+ } else {
267
+ $storeComplete['lang'] = $locales[0];
268
  }
269
 
270
+ if (array_key_exists($key, $storeUrls)) {
271
+ $storeComplete['url'] = $storeUrls[$key];
272
+ } else {
273
+ $storeComplete['url'] = $storeUrls[0];
274
  }
275
 
276
+ if ($useStoreCode) {
277
+ $storeComplete['url'] = $storeUrls[0].$value['code'];
278
  }
279
 
280
+ $multistoreData[] = $storeComplete;
281
  }
282
 
283
+ $dataArr = array(
284
+ 'stores' => $multistoreData,
285
+ 'version' => $version,
286
  );
287
 
288
+ $dataArr['site'] = $url;
289
+ $dataArr['email'] = $storeMail;
290
  //$dataArr['product_count']=$productCount;
291
 
292
+ $multistoreJson = json_encode($dataArr);
 
293
  }
 
294
 
295
  return $multistoreJson;
296
  }
297
 
298
+ public function getExtensionConflict($all_conflicts = false)
299
+ {
300
  $all_rewrite_classes = array();
301
  $node_type_list = array('model', 'helper', 'block');
302
 
303
+ foreach ($node_type_list as $node_type) {
304
  foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module) {
305
+ if ($module->codePool == 'core' || $module->active != 'true') {
306
  continue;
307
  }
308
+ $config_file_path = Mage::getConfig()->getModuleDir('etc', $name).DS.'config.xml';
309
  $config = new Varien_Simplexml_Config();
310
  $config->loadString('<config/>');
311
  $config->loadFile($config_file_path);
312
  $config->extend($config, true);
313
 
314
+ $nodes = $config->getNode()->global->{$node_type.'s'};
315
+ if (!$nodes) {
316
  continue;
317
+ }
318
+ foreach ($nodes->children() as $node_name => $config) {
319
+ if ($config->rewrite) { // there is rewrite for current config
320
+ foreach ($config->rewrite->children() as $class_tag => $derived_class) {
321
  $base_class_name = $this->_getMageBaseClass($node_type, $node_name, $class_tag);
322
 
323
  $lead_derived_class = '';
324
+ $conf = Mage::getConfig()->getNode()->global->{$node_type.'s'}->{$node_name};
325
+ if (isset($conf->rewrite->$class_tag)) {
326
+ $lead_derived_class = (string) $conf->rewrite->$class_tag;
327
  }
328
+ if ($derived_class == '') {
329
  $derived_class = $lead_derived_class;
330
  }
331
 
332
+ if (empty($all_rewrite_classes[$base_class_name])) {
333
  $all_rewrite_classes[$base_class_name] = array(
334
+ 'derived' => array((string) $derived_class),
335
+ 'lead' => (string) $lead_derived_class,
336
+ 'tag' => $class_tag,
337
+ 'name' => array((string) $name),
338
  );
339
+ } else {
340
+ array_push($all_rewrite_classes[$base_class_name]['derived'], (string) $derived_class);
341
+ array_push($all_rewrite_classes[$base_class_name]['name'], (string) $name);
342
  }
343
  }
344
  }
345
  }
346
  }
347
  }
348
+ if ($all_conflicts) {
349
  return $all_rewrite_classes;
350
  }
351
 
352
  $isp_rewrite_classes = array();
353
  $isp_module_name = 'Autocompleteplus_Autosuggest';
354
+ foreach ($all_rewrite_classes as $base => $conflict_info) {
355
+ if (in_array($isp_module_name, $conflict_info['name'])) { // if isp extension rewrite this base class
356
+ if (count($conflict_info['derived']) > 1) { // more then 1 class rewrite this base class => there is a conflict
357
  $isp_rewrite_classes[$base] = $conflict_info;
358
  }
359
  }
360
  }
361
+
362
  return $isp_rewrite_classes;
363
  }
364
 
365
+ protected function _getMageBaseClass($node_type, $node_name, $class_tag)
366
+ {
367
+ $config = Mage::getConfig()->getNode()->global->{$node_type.'s'}->$node_name;
368
 
369
  if (!empty($config)) {
370
  $className = $config->getClassName();
375
  if (!empty($class_tag)) {
376
  $className .= '_'.$class_tag;
377
  }
378
+
379
  return uc_words($className);
380
  }
381
 
382
  /**
383
+ * Checksum functionality.
384
  */
385
+ public function isChecksumTableExists()
386
+ {
387
+ $table_prefix = (string) Mage::getConfig()->getTablePrefix();
388
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
389
+ if ($read->showTableStatus($table_prefix.'autocompleteplus_checksum')) {
390
  return true;
391
  } else {
392
  return false;
393
  }
394
  }
395
 
396
+ public function calculateChecksum($product)
397
+ {
398
+ $product_id = $product->getId();
399
+ $product_title = $product->getName();
400
+ $product_description = $product->getDescription();
401
+ $product_short_desc = $product->getShortDescription();
402
+ $product_url = $product->getUrlPath(); //Mage::helper('catalog/product')->getProductUrl($product_id); | $product->getProductUrl()
403
+ $product_visibility = $product->getVisibility();
404
+ $product_in_stock = $product->isInStock();
405
+ $product_price = (float) $product->getPrice();
406
+ try {
407
+ $product_thumb_url = '/'.$product->getImage();
408
 
409
  // $product_thumb_url = $product->getThumbnailUrl(); //Mage::helper('catalog/image')->init($product, 'thumbnail');
410
  // $thumb_pattern = '/\/[^\/]+(?![^\/]*\/)/';
413
  // } else {
414
  // $product_thumb_url = '';
415
  // }
416
+ } catch (Exception $e) {
417
  $product_thumb_url = '';
418
  }
419
  $product_type = $product->getTypeID();
420
 
421
+ $checksum_string = $product_id.$product_title.$product_description.$product_short_desc.$product_url.
422
+ $product_visibility.$product_in_stock.$product_price.$product_thumb_url.$product_type;
423
 
424
  $checksum_md5 = md5($checksum_string);
425
+
426
  return $checksum_md5;
427
  }
428
 
429
+ public function getSavedChecksum($table_prefix, $read, $product_id, $store_id)
430
+ {
431
+ $sql_fetch = 'SELECT checksum FROM '.$table_prefix.'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
432
  $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
433
+ if ($updates && (count($updates) != 0)) {
434
  return $updates[0]['checksum'];
435
  } else {
436
  return '';
437
  }
438
  }
439
 
440
+ public function updateSavedProductChecksum($product_id, $sku, $store_id, $checksum)
441
+ {
442
+ if ($product_id == null || $sku == null) {
443
  return;
444
  }
445
+ $checksumModel = Mage::getModel('autocompleteplus_autosuggest/checksum');
446
+ $collection = $checksumModel->getCollection()
447
+ ->addFieldToFilter('identifier', $product_id)
448
+ ->addFieldToFilter('store_id', $store_id);
449
+
450
+ $row = $collection->getFirstItem();
451
 
452
+ if ($row && $collection->getSize() > 0) {
453
+ if ($row->getChecksum() != $checksum) {
454
+ $row->setChecksum($checksum)->save();
 
455
  }
456
+ } else {
457
+ $checksumModel->setIdentifier($product_id)
458
+ ->setSku($sku)
459
+ ->setStoreId($store_id)
460
+ ->setChecksum($checksum)
461
+ ->save();
462
  }
463
  }
464
 
465
+ public function updateDeletedProductChecksum($table_prefix, $read, $write, $product_id, $sku, $store_id)
466
+ {
467
+ if ($product_id == null) {
468
  return;
469
  }
 
 
470
 
471
+ $checksums = Mage::getModel('autocompleteplus_autosuggest/checksum')->getCollection()
472
+ ->addFieldToFilter('identifier', $product_id)
473
+ ->addFieldToFilter('store_id', $store_id);
474
+
475
+ if ($checksums->getSize() > 0) {
476
+ // @codingStandardsIgnoreLine
477
+ $checksum = $checksums->getFirstItem();
478
+ $checksum->delete();
479
  }
480
  }
481
 
482
+ private function setUpdateNeededForProduct($read, $write, $product_id, $product_sku, $store_id)
483
+ {
484
+ if ($product_id == null) {
485
  return;
486
  }
487
+ if ($product_sku == null) {
488
+ $product_sku = 'dummy_sku';
489
  }
490
+ try {
491
+ $table_prefix = (string) Mage::getConfig()->getTablePrefix();
492
  $is_table_exist = $write->showTableStatus($table_prefix.'autocompleteplus_batches');
493
+ if (!$is_table_exist) { // table not exists
494
  return;
495
+ }
496
+
497
+ $sql_fetch = 'SELECT * FROM '.$table_prefix.'autocompleteplus_batches WHERE product_id=? AND store_id=?';
498
  $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
499
 
500
+ if ($updates && (count($updates) != 0)) {
501
+ $sql = 'UPDATE '.$table_prefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id=? AND store_id=?';
502
+ $write->query($sql, array(strtotime('now'), 'update', $product_id, $store_id));
503
+ } else {
504
+ $sql = 'INSERT INTO '.$table_prefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
505
+ $write->query($sql, array($product_id, $store_id, strtotime('now'), 'update', $product_sku));
506
  }
507
+ } catch (Exception $e) {
508
+ Mage::log('Exception raised in setUpdateNeededForProduct() - '.$e->getMessage(), null, 'autocompleteplus.log');
509
+ $this->ispErrorLog('Exception raised in setUpdateNeededForProduct() - '.$e->getMessage());
 
510
  }
511
  }
512
 
513
+ public function compareProductsChecksum($from, $count, $store_id = null)
514
+ {
515
  $num_of_updates = 0;
516
+ if (!$this->isChecksumTableExists()) {
517
  return;
518
+ }
519
 
520
  $products = Mage::getModel('catalog/product')->getCollection();
521
+ if ($store_id) {
522
  $products->addStoreFilter($store_id);
523
  }
524
  $products->getSelect()->limit($count, $from);
525
  $products->load();
526
 
527
+ $table_prefix = (string) Mage::getConfig()->getTablePrefix();
528
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
529
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
530
 
531
  foreach ($products as $product) {
532
+ try {
533
  $product_collection_data = $product->getData();
534
  $product_model = Mage::getModel('catalog/product')
535
  ->setStore($store_id)->setStoreId($store_id)
536
  ->load($product_collection_data['entity_id']);
537
+
538
+ $current_checksum = $this->getSavedChecksum($table_prefix, $read, $product_model->getId(), $store_id);
539
  $new_checksum = $this->calculateChecksum($product_model);
540
+ } catch (Exception $e) {
541
+ Mage::log('Exception raised in compareProductsChecksum() on id: '.$product->getId().' -> '.$e->getMessage(), null, 'autocompleteplus.log');
542
+ $this->ispErrorLog('Exception raised in compareProductsChecksum() on id: '.$product->getId().' -> '.$e->getMessage());
543
+
544
  return 0;
545
  }
546
+ if ($current_checksum == '' || $current_checksum != $new_checksum) {
547
+ ++$num_of_updates;
548
  $this->updateSavedProductChecksum($table_prefix, $read, $write, $product_model->getId(), $product_model->getSku(),
549
  $store_id, $new_checksum);
550
  $this->setUpdateNeededForProduct($read, $write, $product_model->getId(), $product_model->getSku(), $store_id);
551
  }
552
  }
553
+
554
  return $num_of_updates;
555
  }
556
 
557
+ public function deleteProductFromTables($read, $write, $table_prefix, $product_id, $store_id)
558
+ {
559
  $dt = strtotime('now');
560
  $sku = 'dummy_sku';
561
+ $sqlFetch = 'SELECT * FROM '.$table_prefix.'autocompleteplus_batches WHERE product_id = ? AND store_id=?';
562
  $updates = $read->fetchAll($sqlFetch, array($product_id, $store_id));
563
 
564
+ if ($updates && count($updates) != 0) {
565
+ $sql = 'UPDATE '.$table_prefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id = ? AND store_id = ?';
566
+ $write->query($sql, array($dt, 'remove', $product_id, $store_id));
567
  } else {
568
+ $sql = 'INSERT INTO '.$table_prefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
569
+ $write->query($sql, array($product_id, $store_id, $dt, 'remove', $sku));
570
  }
571
 
572
  $this->updateDeletedProductChecksum($table_prefix, $read, $write, $product_id, $sku, $store_id);
573
  }
574
 
575
+ public function ispLog($log)
576
+ {
577
  Mage::log($log, null, 'autocompleteplus.log');
578
  }
579
 
580
+ public function ispErrorLog($log)
581
+ {
582
+ $uuid = $this->getUUID();
583
+ $site_url = $this->getConfigDataByFullPath('web/unsecure/base_url');
584
+ $store_id = Mage::app()->getStore()->getStoreId();
585
 
586
+ $server_url = $this->server_url.'/magento_logging_error';
587
+ $request = $server_url.'?uuid='.$uuid.'&site_url='.$site_url.'&store_id='.$store_id.'&msg='.urlencode($log);
588
 
589
  $resp = $this->sendCurl($request);
590
  }
591
 
592
+ public function getUUID()
593
+ {
594
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
595
 
596
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
597
 
598
+ $_tableprefix = (string) Mage::getConfig()->getTablePrefix();
599
 
600
+ $tblExist = $write->showTableStatus($_tableprefix.'autocompleteplus_config');
601
 
602
+ if (!$tblExist) {
603
+ return '';
604
+ }
605
 
606
+ $sql = 'SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
607
 
608
+ $licenseData = $read->fetchAll($sql);
609
 
610
+ $key = $licenseData[0]['licensekey'];
611
 
612
  return $key;
 
613
  }
614
 
615
+ public function getIsReachable()
616
+ {
617
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
618
 
619
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
620
 
621
+ $_tableprefix = (string) Mage::getConfig()->getTablePrefix();
622
 
623
+ $tblExist = $write->showTableStatus($_tableprefix.'autocompleteplus_config');
624
 
625
+ if (!$tblExist) {
626
+ return '';
627
+ }
628
 
629
+ $sql = 'SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
630
 
631
+ $licenseData = $read->fetchAll($sql);
632
 
633
+ $is_reachable = $licenseData[0]['is_reachable'];
634
 
635
  return $is_reachable;
 
636
  }
637
+
638
+ public function getServerEndPoint()
639
+ {
640
+ try {
641
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
642
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
643
+ $_tableprefix = (string) Mage::getConfig()->getTablePrefix();
644
+ $tblExist = $write->showTableStatus($_tableprefix.'autocompleteplus_config');
645
+
646
+ if (!$tblExist) {
647
  return '';
648
  }
649
+
650
+ $sql = 'SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
651
+ $licenseData = $read->fetchAll($sql);
652
+ if (array_key_exists('server_type', $licenseData[0])) {
653
  $key = $licenseData[0]['server_type'];
654
  } else {
655
  $key = '';
656
  }
657
+ } catch (Exception $e) {
658
  $key = '';
659
  }
660
+
661
  return $key;
662
  }
663
+
664
+ public function setServerEndPoint($end_point)
665
+ {
666
+ try {
667
+ $_tableprefix = (string) Mage::getConfig()->getTablePrefix();
668
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
669
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
670
+ $tblExist = $write->showTableStatus($_tableprefix.'autocompleteplus_config');
671
+
672
+ if (!$tblExist) {
673
  return;
674
  }
675
+
676
+ $sqlFetch = 'SELECT * FROM '.$_tableprefix.'autocompleteplus_config WHERE id = 1';
677
  $updates = $write->fetchAll($sqlFetch);
678
+
679
+ if ($updates && count($updates) != 0) {
680
+ $sql = 'UPDATE '.$_tableprefix.'autocompleteplus_config SET server_type=? WHERE id = 1';
681
  $write->query($sql, array($end_point));
682
+ } else {
683
+ Mage::log('cant update server_type', null, 'autocompleteplus.log');
684
  }
685
+ } catch (Exception $e) {
686
+ Mage::log($e->getMessage(), null, 'autocompleteplus.log');
687
  }
688
  }
689
 
690
+ public function getErrormessage()
691
+ {
692
  $read = Mage::getSingleton('core/resource')->getConnection('core_read');
693
 
694
  $write = Mage::getSingleton('core/resource')->getConnection('core_write');
695
 
696
+ $_tableprefix = (string) Mage::getConfig()->getTablePrefix();
697
 
698
+ $tblExist = $write->showTableStatus($_tableprefix.'autocompleteplus_config');
699
 
700
+ if (!$tblExist) {
701
+ return '';
702
+ }
703
 
704
+ $sql = 'SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
705
 
706
+ $licenseData = $read->fetchAll($sql);
707
 
708
+ $errormessage = $licenseData[0]['errormessage'];
709
 
710
  return $errormessage;
 
711
  }
712
 
713
+ public function getIfSyncWasInitiated()
714
+ {
715
  $collection = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection();
716
 
717
+ $count = $collection->count();
718
 
719
+ if ($count == 0) {
720
  return false;
721
+ } else {
722
  return true;
723
  }
724
  }
725
 
726
+ public function getPushId()
727
+ {
728
  $collection = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()
729
+ ->addFilter('sent', 0);
730
 
731
  $collection->getSelect()->limit(1);
732
 
733
  $collection->load();
734
 
735
+ $id = '';
736
 
737
  foreach ($collection as $p) {
738
+ $id = $p->getId();
739
  }
740
 
741
  return $id;
742
  }
743
 
744
+ public function getPushUrl($id = null)
745
+ {
746
+ if ($id == null) {
747
+ $id = $this->getPushId();
748
  }
749
 
750
+ $url = Mage::getUrl();//'',array('pushid'=>$id));
751
 
752
+ if (strpos($url, 'index.php') !== false) {
753
+ $url = $url.'/autocompleteplus/products/pushbulk/pushid/'.$id;
754
+ } else {
755
+ $url = $url.'index.php/autocompleteplus/products/pushbulk/pushid/'.$id;
756
  }
 
757
 
758
+ return $url;
759
  }
760
 
761
+ public function escapeXml($xml)
762
+ {
763
+ // $pairs = array(
764
  // "\x03" => "&#x03;",
765
  // "\x05" => "&#x05;",
766
  // "\x0E" => "&#x0E;",
768
  // );
769
  // $xml = strtr($xml, $pairs);
770
 
771
+ $xml = preg_replace('/[\x00-\x1f]/', '', $xml);
772
+
773
  return $xml;
774
  }
775
 
 
776
  /**
777
  * Get the session cookie value
778
+ * protected with a salt (the store encryption key).
779
+ *
780
  * @return string
781
  */
782
  public function getSessionId()
783
  {
784
+ return md5(Mage::app()->getCookie()->get('frontend').$this->_getEncryptionKey());
785
  }
786
 
787
  /**
788
  * Return encryption key in Magento to use as salt
789
  * Requires getting from configNode so that it is backward
790
+ * compatible with later versions.
791
+ *
792
  * @return string
793
  */
794
  protected function _getEncryptionKey()
795
  {
796
  return (string) Mage::getConfig()->getNode('global/crypt/key');
797
  }
798
+ }
 
app/code/local/Autocompleteplus/Autosuggest/Model/Adminhtml/Attributes.php CHANGED
@@ -1,8 +1,7 @@
1
  <?php
2
 
3
  /**
4
- * InstantSearchPlus (Autosuggest)
5
-
6
  *
7
  * NOTICE OF LICENSE
8
  *
@@ -11,94 +10,49 @@
11
  * http://opensource.org/licenses/osl-3.0.php
12
  *
13
  * @category Mage
14
- * @package InstantSearchPlus
15
  * @copyright Copyright (c) 2014 Fast Simon (http://www.instantsearchplus.com)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
19
-
20
  /**
21
-
22
- * Used in creating options for Yes|No config value selection
23
-
24
- *
25
-
26
  */
27
-
28
  class Autocompleteplus_Autosuggest_Model_Adminhtml_Attributes
29
-
30
  {
31
-
32
  public $fields = array();
33
 
34
  /**
35
-
36
- * Options getter
37
-
38
  *
39
-
40
  * @return array
41
-
42
  */
43
-
44
  public function toOptionArray()
45
-
46
  {
47
-
48
- $this->fields=$this->getOptions();
49
 
50
  return $this->fields;
51
-
52
  }
53
 
54
-
55
-
56
  public function getOptions()
57
-
58
  {
59
-
60
  $entityType = Mage::getModel('catalog/product')->getResource()->getEntityType();
61
-
62
- $entityTypeId=$entityType->getId();
63
-
64
  $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
65
-
66
  ->setEntityTypeFilter($entityTypeId)
67
-
68
  ->getData();
69
 
70
- $result=array();
71
-
72
- $result[]=array('value'=>'','label'=>'Choose an attribute');
73
-
74
- foreach($attributeInfo as $_key=>$_value)
75
-
76
- {
77
-
78
- if($_value['is_global'] != "1" || $_value['is_visible']!="1"){
79
-
80
- // continue;
81
-
82
- }
83
-
84
- if(isset($_value['frontend_label'])&&($_value['frontend_label']!='')){
85
-
86
- $result[]=array('value'=>$_value['attribute_code'],'label' => $_value['frontend_label']);
87
-
88
- }else{
89
-
90
- $result[]=array('value'=>$_value['attribute_code'],'label' => $_value['attribute_code']);
91
 
 
 
 
 
 
92
  }
93
-
94
-
95
-
96
  }
97
 
98
  return $result;
99
-
100
  }
101
-
102
-
103
-
104
- }
1
  <?php
2
 
3
  /**
4
+ * InstantSearchPlus (Autosuggest).
 
5
  *
6
  * NOTICE OF LICENSE
7
  *
10
  * http://opensource.org/licenses/osl-3.0.php
11
  *
12
  * @category Mage
13
+ *
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
 
 
18
  /**
19
+ * Used in creating options for Yes|No config value selection.
 
 
 
 
20
  */
 
21
  class Autocompleteplus_Autosuggest_Model_Adminhtml_Attributes
 
22
  {
 
23
  public $fields = array();
24
 
25
  /**
26
+ * Options getter.
 
 
27
  *
 
28
  * @return array
 
29
  */
 
30
  public function toOptionArray()
 
31
  {
32
+ $this->fields = $this->getOptions();
 
33
 
34
  return $this->fields;
 
35
  }
36
 
 
 
37
  public function getOptions()
 
38
  {
 
39
  $entityType = Mage::getModel('catalog/product')->getResource()->getEntityType();
40
+ $entityTypeId = $entityType->getId();
 
 
41
  $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
 
42
  ->setEntityTypeFilter($entityTypeId)
 
43
  ->getData();
44
 
45
+ $result = array();
46
+ $result[] = array('value' => '', 'label' => 'Choose an attribute');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ foreach ($attributeInfo as $_key => $_value) {
49
+ if (isset($_value['frontend_label']) && ($_value['frontend_label'] != '')) {
50
+ $result[] = array('value' => $_value['attribute_code'], 'label' => $_value['frontend_label']);
51
+ } else {
52
+ $result[] = array('value' => $_value['attribute_code'], 'label' => $_value['attribute_code']);
53
  }
 
 
 
54
  }
55
 
56
  return $result;
 
57
  }
58
+ }
 
 
 
app/code/local/Autocompleteplus/Autosuggest/Model/Api.php CHANGED
@@ -1,35 +1,50 @@
1
  <?php
 
2
  class Autocompleteplus_Autosuggest_Model_Api extends Mage_Api_Model_Resource_Abstract
3
  {
4
- public function setLayeredSearchOn($scope, $scope_id) {
5
- $core_config = new Mage_Core_Model_Config();
 
 
 
 
 
6
  try {
7
- $core_config->saveConfig('autocompleteplus/config/layered', "1", $scope, $scope_id);
8
  Mage::app()->getCacheInstance()->cleanType('config');
9
  } catch (Exception $e) {
 
 
10
  return $e->getMessage();
11
  }
12
- return "Done";
 
13
  }
14
 
15
- public function setLayeredSearchOff($scope, $scope_id) {
16
- $core_config = new Mage_Core_Model_Config();
17
  try {
18
- $core_config->saveConfig('autocompleteplus/config/layered', "0", $scope, $scope_id);
19
  Mage::app()->getCacheInstance()->cleanType('config');
20
  } catch (Exception $e) {
 
 
21
  return $e->getMessage();
22
  }
23
- return "Done";
 
24
  }
25
 
26
- public function getLayeredSearchConfig($scope_id) {
 
27
  try {
28
- Mage::app()->getCacheInstance()->cleanType('config');
29
- $layered = Mage::getStoreConfig('autocompleteplus/config/layered', $scope_id);
30
  } catch (Exception $e) {
 
 
31
  return $e->getMessage();
32
  }
 
33
  return $layered;
34
  }
35
- }
1
  <?php
2
+
3
  class Autocompleteplus_Autosuggest_Model_Api extends Mage_Api_Model_Resource_Abstract
4
  {
5
+ protected function _getConfig()
6
+ {
7
+ return Mage::getModel('autocompleteplus_autosuggest/config');
8
+ }
9
+
10
+ public function setLayeredSearchOn($scope, $scopeId)
11
+ {
12
  try {
13
+ $this->_getConfig()->enableLayeredNavigation($scope, $scopeId);
14
  Mage::app()->getCacheInstance()->cleanType('config');
15
  } catch (Exception $e) {
16
+ Mage::logException($e);
17
+
18
  return $e->getMessage();
19
  }
20
+
21
+ return 'Done';
22
  }
23
 
24
+ public function setLayeredSearchOff($scope, $scopeId)
25
+ {
26
  try {
27
+ $this->_getConfig()->disableLayeredNavigation($scope, $scopeId);
28
  Mage::app()->getCacheInstance()->cleanType('config');
29
  } catch (Exception $e) {
30
+ Mage::logException($e);
31
+
32
  return $e->getMessage();
33
  }
34
+
35
+ return 'Done';
36
  }
37
 
38
+ public function getLayeredSearchConfig($scopeId)
39
+ {
40
  try {
41
+ $layered = $this->_getConfig()->getLayeredNavigationStatus($scopeId);
 
42
  } catch (Exception $e) {
43
+ Mage::logException($e);
44
+
45
  return $e->getMessage();
46
  }
47
+
48
  return $layered;
49
  }
50
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Api/V2.php CHANGED
@@ -1,2 +1,5 @@
1
  <?php
2
- class Autocompleteplus_Autosuggest_Model_Api_V2 extends Autocompleteplus_Autosuggest_Model_Api {}
 
 
 
1
  <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Api_V2 extends Autocompleteplus_Autosuggest_Model_Api
4
+ {
5
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Batches.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Batches extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('autocompleteplus_autosuggest/batches');
8
+ }
9
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Catalog.php CHANGED
@@ -1,1129 +1,1010 @@
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
- $categoryMap = array();
277
- $categories = Mage::getModel('catalog/category')->getCollection()->load();
278
-
279
- foreach($categories as $category){
280
- $categoryMap[] = new Varien_Object(array(
281
- 'id'=>$category->getId(),
282
- 'path'=>$category->getPath(),
283
- 'parent_id'=>$category->getParentId()
284
- ));
285
- }
286
-
287
- $this->_categories = $categoryMap;
288
- }
289
-
290
- return $this->_categories;
291
- }
292
-
293
- public function getCategoryPathsByProduct(Mage_Catalog_Model_Product $product)
294
- {
295
- $productCategories = $product->getCategoryIds();
296
- $root_category_id = $this->_root_category_id;
297
- $paths = array_map(function($category) use ($productCategories, $root_category_id) {
298
- if(in_array($category->getId(), $productCategories)){
299
- $path = explode('/', $category->getPath());
300
- //we don't want the root category for the entire site
301
- array_shift($path);
302
- if ($root_category_id && is_array($path) && $path[0] != $root_category_id){
303
- return array();
304
- }
305
- //we want more specific categories first
306
- return implode(':', array_reverse($path));
307
- }
308
- }, $this->getCategoryMap());
309
-
310
- return array_filter($paths);
311
- }
312
-
313
- public function renderProductXmlRow($productModel,$orders_per_product,$xmlAttrs='action="insert"')
314
- {
315
- $helper = Mage::helper('autocompleteplus_autosuggest');
316
- $categories = $this->getCategoryPathsByProduct($productModel);
317
- $price = $this->_getPrice($productModel);
318
- $sku = $productModel->getSku();
319
- $stock_status = $productModel->isInStock();
320
- $stockItem = $productModel->getStockItem();
321
-
322
- if($stockItem){
323
- if($stockItem->getIsInStock() && $stock_status){
324
- $sell=1;
325
- }else{
326
- $sell=0;
327
- }
328
- }else{
329
- if($stock_status){
330
- $sell=1;
331
- }else{
332
- $sell=0;
333
- }
334
- }
335
-
336
- $productUrl = ''; // getting the product's url according to the store_id
337
-
338
- $is_getUrlPath_supported = true;
339
- if (method_exists('Mage' , 'getVersionInfo')){ // getUrlPath is not supported on EE 1.13... & 1.14...
340
- $edition_info = Mage::getVersionInfo();
341
- if ($edition_info['major'] == 1 && $edition_info['minor'] >= 13){
342
- $is_getUrlPath_supported = false;
343
- }
344
- }
345
-
346
- if (method_exists($productModel, 'getUrlPath') && $is_getUrlPath_supported){
347
- $productUrl = $productModel->getUrlPath();
348
- if ($productUrl != ''){
349
- $productUrl = Mage::getUrl($productUrl);
350
- }
351
- }
352
- if ($productUrl == '' && method_exists($productModel, 'getProductUrl')){
353
- $productUrl = $productModel->getProductUrl();
354
- // $pattern = '/\?___.*/';
355
- // $productUrl = preg_replace($pattern, '', $productUrl);
356
- }
357
- if ($productUrl == '') {
358
- $productUrl = Mage::helper('catalog/product')->getProductUrl($productModel->getId());
359
- }
360
-
361
- $prodId = $productModel->getId();
362
- $prodDesc = $productModel->getDescription();
363
- $prodShortDesc = $productModel->getShortDescription();
364
- $prodName = $productModel->getName();
365
- $visibility = $productModel->getVisibility();
366
-
367
- if(defined('Mage_Catalog_Model_Product_Status::STATUS_ENABLED')){
368
- if ($productModel->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED){
369
- $product_status = 1;
370
- } else {
371
- $product_status = 0;
372
- }
373
- } else {
374
- if ($productModel->getStatus() == 1){
375
- $product_status = 1;
376
- } else {
377
- $product_status = 0;
378
- }
379
- }
380
-
381
- try{
382
- if(in_array($this->imageField,$this->standardImageFields)){
383
- $prodImage =Mage::helper('catalog/image')->init($productModel, $this->imageField);
384
- }else{
385
- $function='get'.$this->imageField;
386
- $prodImage =$productModel->$function();
387
- }
388
-
389
- try{
390
- $product_media_config = Mage::getModel('catalog/product_media_config');
391
- $product_base_image = $product_media_config->getMediaUrl($productModel->getImage());
392
- } catch (Exception $e){
393
- $product_base_image = '';
394
- }
395
-
396
- }catch(Exception $e){
397
- $prodImage='';
398
- $product_base_image = '';
399
- }
400
-
401
- $grouped_children_ids = array();
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() == 'grouped'){
438
- $grouped_children = $this->_getGroupedChildren($productModel);
439
- foreach($grouped_children as $child_product){
440
- $grouped_children_ids[] = $child_product->getId();
441
- }
442
- // getting sellable option for the grouped product
443
- if ($sell){ // Grouped is in stock
444
- $is_in_stock_child_exist = false;
445
- foreach($grouped_children as $child_product){
446
- if ($child_product->getStockItem()->getIsInStock()){
447
- if (method_exists($child_product, 'isSaleable') && !$child_product->isSaleable()){
448
- continue;
449
- }
450
- $is_in_stock_child_exist = true;
451
- break;
452
- }
453
- }
454
- if (!$is_in_stock_child_exist){
455
- # Configurable is in stock, but has no in stock children
456
- $sell = 0;
457
- }
458
- }
459
- $priceRange='price_min="" price_max=""';
460
- } else if ($productModel->getTypeID() == 'simple'){
461
- $simple_product_parents = $this->_getSimpleProductParent($productModel);
462
- $priceRange='price_min="" price_max=""';
463
- }else{
464
- $priceRange='price_min="" price_max=""';
465
- }
466
-
467
- $num_of_orders = ($orders_per_product != null && array_key_exists($prodId, $orders_per_product)) ? $orders_per_product[$prodId] : 0;
468
- $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.' >';
469
- $row.='<description><![CDATA['.$prodDesc.']]></description>';
470
- $row.='<short><![CDATA['.$prodShortDesc.']]></short>';
471
- $row.='<name><![CDATA['.$prodName.']]></name>';
472
- $row.='<sku><![CDATA['.$sku.']]></sku>';
473
-
474
- $summaryData = Mage::getModel('review/review_summary')
475
- ->setStoreId($productModel->getStoreId())
476
- ->load($prodId);
477
- if (($summaryData['rating_summary'] || $summaryData['rating_summary'] == 0) && $summaryData['rating_summary'] != ''){
478
- $row.='<review><![CDATA['.$summaryData['rating_summary'].']]></review>';
479
- $row.='<reviews_count><![CDATA['.$summaryData['reviews_count'].']]></reviews_count>';
480
- }
481
-
482
- $new_from_date = $productModel->getNewsFromDate();
483
- $new_to_date = $productModel->getNewsToDate();
484
- if ($new_from_date){
485
- $row.='<newfrom><![CDATA['.Mage::getModel('core/date')->timestamp($new_from_date).']]></newfrom>';
486
- if ($new_to_date){
487
- $row.='<newto><![CDATA['.Mage::getModel('core/date')->timestamp($new_to_date).']]></newto>';
488
- }
489
- }
490
-
491
- $row.= '<purchase_popularity><![CDATA['.$num_of_orders.']]></purchase_popularity>';
492
- $row.='<product_status><![CDATA['.$product_status.']]></product_status>';
493
-
494
- try{
495
- $row.='<creation_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getCreatedAt()).']]></creation_date>';
496
- $row.='<updated_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getUpdatedAt()).']]></updated_date>';
497
- } catch(Exception $e){
498
- }
499
-
500
- if($this->useAttributes!='0'){
501
- foreach($this->attributes as $attr){
502
- $action=$attr->getAttributeCode();
503
- $is_filterable=$attr->getis_filterable();
504
- $attribute_label = $attr->getStoreLabel($productModel->getStoreId());
505
-
506
- if($attr->getfrontend_input()=='select'){
507
- if($productModel->getData($action)){
508
- if (method_exists($productModel, 'getAttributeText')){
509
- try{
510
- $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
511
- <attribute_values><![CDATA['.$productModel->getAttributeText($action).']]></attribute_values>
512
- <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
513
- </attribute>';
514
- } catch(Exception $e){
515
- $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
516
- <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
517
- <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
518
- </attribute>';
519
- }
520
- } else {
521
- $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
522
- <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
523
- <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
524
- </attribute>';
525
- }
526
- }
527
- }elseif($attr->getfrontend_input()=='textarea'){
528
- if($productModel->getData($action)){
529
- $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
530
- <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
531
- <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
532
- </attribute>';
533
- }
534
- }elseif($attr->getfrontend_input()=='price'){
535
- if($productModel->getData($action)){
536
- $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
537
- <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
538
- <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
539
- </attribute>';
540
- }
541
- }elseif($attr->getfrontend_input()=='text'){
542
- if($productModel->getData($action)){
543
- $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
544
- <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
545
- <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
546
- </attribute>';
547
- }
548
- }elseif($attr->getfrontend_input()=='multiselect'){
549
- if($productModel->getData($action)){
550
- $values=$productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
551
- $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
552
- <attribute_values><![CDATA['.$values.']]></attribute_values>
553
- <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
554
- </attribute>';
555
- }
556
- }
557
- }
558
-
559
- if($productModel->getTypeID()=='configurable' && count($configurableAttributes)>0){
560
- $configural_attributes = array();
561
- foreach($configurableAttributes as $attrName=>$confAttrN){
562
- if(is_array($confAttrN) && array_key_exists('values',$confAttrN)){
563
- $configural_attributes[] = $attrName;
564
- $values=implode(' , ',$confAttrN['values']);
565
- $row.='<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
566
- }
567
- }
568
- $simple_products_price = $this->_getSimpleProductsPriceOfConfigurable($productModel, $configurableChildren);
569
-
570
- if (!empty($configural_attributes)){
571
- $product_variation = '<variants>';
572
- try{
573
- foreach($configurableChildren as $child_product){
574
- if (!in_array($productModel->getStoreId(), $child_product->getStoreIds())){
575
- continue;
576
- }
577
-
578
- $is_variant_in_stock = ($child_product->getStockItem()->getIsInStock()) ? 1 : 0;
579
-
580
- if (method_exists($child_product, 'isSaleable')){
581
- $is_variant_sellable = ($child_product->isSaleable()) ? 1 : 0;
582
- } else {
583
- $is_variant_sellable = '';
584
- // $is_variant_sellable = (Mage::getModel('catalog/product')
585
- // ->setStore($productModel->getStoreId())
586
- // ->setStoreId($productModel->getStoreId())
587
- // ->load($child_product->getId())
588
- // ->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
589
- }
590
-
591
- if (method_exists($child_product, 'getVisibility')){
592
- $is_variant_visible = ($child_product->getVisibility()) ? 1 : 0;
593
- } else {
594
- $is_variant_visible = '';
595
- // $is_variant_visible = (Mage::getModel('catalog/product')
596
- // ->setStore($productModel->getStoreId())
597
- // ->setStoreId($productModel->getStoreId())
598
- // ->load($child_product->getId())
599
- // ->getVisibility());
600
- }
601
-
602
- $variant_price = (array_key_exists($child_product->getId(), $simple_products_price)) ?
603
- $simple_products_price[$child_product->getId()] : '';
604
-
605
- $product_variation .= '<variant id="'.$child_product->getId().'" type="'.$child_product->getTypeID().
606
- '" visibility="'.$is_variant_visible.'" is_in_stock="'.$is_variant_in_stock.'" is_seallable="'.$is_variant_sellable.'" price="'.$variant_price.'">';
607
- $product_variation .= '<name><![CDATA['.$child_product->getName().']]></name>';
608
-
609
- $attributes = $child_product->getAttributes();
610
- foreach ($attributes as $attribute) {
611
- if (!$attribute['is_configurable'] || !in_array($attribute['store_label'], $configural_attributes)){ // || !$attribute->getIsVisibleOnFront()
612
- continue;
613
- }
614
-
615
- $product_variation .= '<variant_attribute is_configurable="1" is_filterable="'.$attribute->getis_filterable().
616
- '" name="'.$attribute['store_label'].'" name_code="'.$attribute->getId().
617
- '" value_code="'.$child_product->getData($attribute->getAttributeCode()).
618
- '"><![CDATA['.$attribute->getFrontend()->getValue($child_product).
619
- ']]></variant_attribute>';
620
- }
621
- $product_variation .= '</variant>';
622
- }
623
- } catch(Exception $e ){
624
- }
625
- $product_variation .= '</variants>';
626
- $row.=$product_variation;
627
- }
628
-
629
- $row.='<simpleproducts><![CDATA['.implode(',',$configurable_children_ids).']]></simpleproducts>';
630
- } else if ($productModel->getTypeID()=='grouped' && count($grouped_children_ids)>0){
631
- $row.='<simpleproducts><![CDATA['.implode(',',$grouped_children_ids).']]></simpleproducts>';
632
- }
633
-
634
- if($productModel->getTypeID() == 'simple'){
635
- $row.='<product_parents><![CDATA['.implode(',',$simple_product_parents).']]></product_parents>';
636
- }
637
- }
638
-
639
- $row.='<categories><![CDATA[' . implode(';', $categories) . ']]></categories>';
640
- $row.='</product>';
641
- return $helper->escapeXml($row);
642
- }
643
-
644
- private function _makeUpdateRow($batch,$attributes){
645
-
646
- $productId = $batch['product_id'];
647
-
648
- $sku = $batch['sku'];
649
-
650
- $storeId = $batch['store_id'];
651
-
652
- $updatedate = $batch['update_date'];
653
-
654
- $action = $batch['action'];
655
-
656
- $currency=Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
657
-
658
- if($productId!=null){
659
-
660
- $productModel=Mage::getModel('catalog/product')
661
-
662
- ->setStoreId($storeId)
663
-
664
- ->load($productId);
665
-
666
- if($productModel==null){
667
-
668
- return '';
669
-
670
- }
671
-
672
- }else{
673
-
674
- /*
675
-
676
- * FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
677
-
678
- */
679
-
680
- $productModel=Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
681
-
682
- if($productModel==null){
683
-
684
- return '';
685
-
686
- }
687
-
688
- $productModel = $productModel->setStoreId($storeId);
689
-
690
- $productId=$productModel->getId();
691
- }
692
-
693
- if($productModel==null){
694
-
695
- return '';
696
-
697
- }
698
-
699
- $price =$this->getPrice($productModel);
700
-
701
- $sku =$productModel->getSku();
702
-
703
- $status =$productModel->isInStock();
704
-
705
- $stockItem = $productModel->getStockItem();
706
-
707
- $categoriesNames='';
708
-
709
- $categories = $productModel->getCategoryCollection()
710
- ->addAttributeToSelect('name');
711
-
712
- foreach($categories as $category) {
713
- $categoriesNames.=$category->getName().':'.$category->getId().';';
714
- }
715
-
716
- if($stockItem->getIsInStock()&&$status)
717
- {
718
- $sell=1;
719
- }else{
720
- $sell=0;
721
- }
722
-
723
- $productUrl =Mage::helper('catalog/product')->getProductUrl($productId);
724
-
725
- $prodId =$productModel->getId();
726
-
727
- $prodDesc =$productModel->getDescription();
728
-
729
- $prodShortDesc =$productModel->getShortDescription();
730
-
731
- $prodName =$productModel->getName();
732
-
733
- $visibility =$productModel->getVisibility();
734
-
735
- try{
736
-
737
- if(in_array($this->imageField,$this->standardImageFields)){
738
-
739
- $prodImage =Mage::helper('catalog/image')->init($productModel, $this->imageField);
740
-
741
- }else{
742
-
743
- $function='get'.$this->imageField;
744
-
745
- $prodImage =$productModel->$function();
746
-
747
- }
748
-
749
- }catch(Exception $e){
750
-
751
- $prodImage='';
752
-
753
- }
754
-
755
- if($productModel->getTypeID()=='configurable'){
756
-
757
- $configurableAttributes=$this->_getConfigurableAttributes($productModel);
758
-
759
- try{
760
-
761
- $priceRange=$this->_getPriceRange($productModel);
762
-
763
- }catch(Exception $e){
764
-
765
- $priceRange='price_min="" price_max=""';
766
-
767
- }
768
-
769
- }else{
770
-
771
- $priceRange='price_min="" price_max=""';
772
-
773
- }
774
-
775
- $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.'" >';
776
-
777
- $row.='<description><![CDATA['.$prodDesc.']]></description>';
778
-
779
- $row.='<short><![CDATA['.$prodShortDesc.']]></short>';
780
-
781
- $row.='<name><![CDATA['.$prodName.']]></name>';
782
-
783
- $row.='<sku><![CDATA['.$sku.']]></sku>';
784
-
785
- if($attributes!=null){
786
-
787
- foreach($attributes as $attr){
788
-
789
-
790
-
791
- $action=$attr->getAttributeCode();
792
-
793
-
794
-
795
- $is_filterable=$attr->getis_filterable();
796
-
797
-
798
-
799
- if($attr->getfrontend_input()=='select'){
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->getAttributeText($action).']]></attribute>';
806
-
807
- }
808
-
809
-
810
-
811
- }elseif($attr->getfrontend_input()=='textarea'){
812
-
813
-
814
-
815
- if($productModel->getData($action)){
816
-
817
- $row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
818
-
819
- }
820
-
821
- }elseif($attr->getfrontend_input()=='price'){
822
-
823
-
824
-
825
- if($productModel->getData($action)){
826
-
827
- $row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
828
-
829
- }
830
-
831
- }elseif($attr->getfrontend_input()=='text'){
832
-
833
-
834
-
835
- if($productModel->getData($action)){
836
-
837
- $row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
838
-
839
- }
840
-
841
- }elseif($attr->getfrontend_input()=='multiselect'){
842
-
843
- if($productModel->getData($action)){
844
-
845
- $values=$productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
846
-
847
-
848
-
849
- $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'"><![CDATA['.$values.']]></attribute>';
850
-
851
- }
852
-
853
- }
854
-
855
- }
856
-
857
- if($productModel->getTypeID()=='configurable' && count($configurableAttributes)>0){
858
-
859
- foreach($configurableAttributes as $attrName=>$confAttrN){
860
-
861
- if(is_array($confAttrN) && array_key_exists('values',$confAttrN)){
862
-
863
- $values=implode(' , ',$confAttrN['values']);
864
-
865
- $row.='<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
866
-
867
- }
868
-
869
-
870
-
871
- }
872
-
873
- }
874
-
875
- }
876
-
877
- $row.='<categories><![CDATA['.$categoriesNames.']]></categories>';
878
-
879
- $row.='</product>';
880
-
881
-
882
-
883
- return $row;
884
-
885
- }
886
-
887
- private function _makeRemoveRow($batch){
888
- $updatedate = $batch['update_date'];
889
- $action = $batch['action'];
890
- $sku = $batch['sku'];
891
- $productId = $batch['product_id'];
892
- $storeId = $batch['store_id'];
893
-
894
- $row='<product updatedate="'.$updatedate.'" action="'.$action.'" id="'.$productId.'" storeid="'.$storeId.'">';
895
- $row.='<sku><![CDATA['.$sku.']]></sku>';
896
- $row.='<id><![CDATA['.$productId.']]></id>';
897
- $row.='</product>';
898
- return $row;
899
- }
900
-
901
- private function _getConfigurableChildren($product){
902
-
903
- $childProducts = Mage::getModel('catalog/product_type_configurable')
904
- ->getUsedProducts(null,$product);
905
- return $childProducts;
906
- }
907
-
908
- private function _getGroupedChildren($product){
909
- return $product->getTypeInstance(true)->getAssociatedProducts($product);
910
- }
911
-
912
- private function _getSimpleProductParent($product){
913
- try{
914
- $parent_products_ids_list = Mage::getModel('catalog/product_type_configurable')
915
- ->getParentIdsByChild($product->getId());
916
-
917
- return $parent_products_ids_list;
918
- } catch(Exception $e){
919
- return array();
920
- }
921
- }
922
-
923
- private function _getConfigurableAttributes($product){
924
-
925
- try{
926
- // Collect options applicable to the configurable product
927
- $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
928
-
929
- $attributeOptions = array();
930
-
931
- foreach ($productAttributeOptions as $productAttribute) {
932
- $attributeFull = Mage::getModel('eav/config')->getAttribute('catalog_product', $productAttribute['attribute_code']);
933
-
934
- foreach ($productAttribute['values'] as $attribute) {
935
- $attributeOptions[$productAttribute['store_label']]['values'][] = $attribute['store_label'];
936
-
937
- }
938
-
939
- $attributeOptions[$productAttribute['store_label']]['is_filterable']=$attributeFull['is_filterable'];
940
- $attributeOptions[$productAttribute['store_label']]['frontend_input']=$attributeFull['frontend_input'];
941
- }
942
- return $attributeOptions;
943
-
944
- }catch(Exception $e){
945
- return array();
946
- }
947
-
948
- }
949
-
950
- private function _getPriceRange($product){
951
- $max = '';
952
- $min = '';
953
-
954
- $pricesByAttributeValues = array();
955
- $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
956
- $basePrice = $product->getFinalPrice();
957
- $items = $attributes->getItems();
958
- if (is_array($items)){
959
- foreach ($items as $attribute){
960
- $prices = $attribute->getPrices();
961
- if (is_array($prices)){
962
- foreach ($prices as $price){
963
- if ($price['is_percent']){ //if the price is specified in percents
964
- $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
965
- }
966
- else { //if the price is absolute value
967
- $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
968
- }
969
- }
970
- }
971
- }
972
- }
973
-
974
- $simple = $product->getTypeInstance()->getUsedProducts();
975
- foreach ($simple as $sProduct){
976
- $totalPrice = $basePrice;
977
- foreach ($attributes as $attribute){
978
- $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
979
- if (isset($pricesByAttributeValues[$value])){
980
- $totalPrice += $pricesByAttributeValues[$value];
981
- }
982
- }
983
- if(!$max || $totalPrice > $max)
984
- $max = $totalPrice;
985
- if(!$min || $totalPrice < $min)
986
- $min = $totalPrice;
987
- }
988
- $priceRange='price_min="'.$min.'" price_max="'.$max.'"';
989
- return $priceRange;
990
- }
991
-
992
- private function _getSimpleProductsPriceOfConfigurable($product, $configurable_children){
993
- $simple_products_price = array();
994
- $pricesByAttributeValues = array();
995
- $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
996
- $basePrice = $product->getFinalPrice();
997
- $items = $attributes->getItems();
998
- if (is_array($items)){
999
- foreach ($items as $attribute){
1000
- $prices = $attribute->getPrices();
1001
- if (is_array($prices)){
1002
- foreach ($prices as $price){
1003
- if ($price['is_percent']){ //if the price is specified in percents
1004
- $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
1005
- }
1006
- else { //if the price is absolute value
1007
- $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
1008
- }
1009
- }
1010
- }
1011
- }
1012
- }
1013
-
1014
- foreach ($configurable_children as $sProduct){
1015
- $totalPrice = $basePrice;
1016
- foreach ($attributes as $attribute){
1017
- $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
1018
- if (isset($pricesByAttributeValues[$value])){
1019
- $totalPrice += $pricesByAttributeValues[$value];
1020
- }
1021
- }
1022
- $simple_products_price[$sProduct->getId()] = $totalPrice;
1023
- }
1024
- return $simple_products_price;
1025
- }
1026
-
1027
- private function _getOrdersPerProduct($store_id, $product_id_list, $month_interval){
1028
-
1029
- if (count($product_id_list) <= 0)
1030
-
1031
- return null;
1032
-
1033
- $id_str = implode(',', $product_id_list);
1034
-
1035
- $query = Mage::getResourceModel('sales/order_item_collection');
1036
-
1037
- $select = $query->getSelect()->reset(Zend_Db_Select::COLUMNS)
1038
-
1039
- ->columns(array('product_id','SUM(qty_ordered)'))
1040
-
1041
- ->where(new Zend_Db_Expr('store_id = ' . $store_id))
1042
-
1043
- ->where(new Zend_Db_Expr('product_id IN ('.$id_str.')'))
1044
-
1045
- ->where(new Zend_Db_Expr('created_at BETWEEN NOW() - INTERVAL '.$month_interval.' MONTH AND NOW()'))
1046
-
1047
- ->group(array('product_id'));
1048
-
1049
-
1050
-
1051
- $resource = Mage::getSingleton('core/resource');
1052
-
1053
- $readConnection = $resource->getConnection('core_read');
1054
-
1055
- $results = $readConnection->fetchAll($select);
1056
-
1057
-
1058
-
1059
- $orders_per_product = array();
1060
-
1061
- foreach ($results as $res){
1062
-
1063
- $orders_per_product[$res['product_id']] = (int)$res['SUM(qty_ordered)'];
1064
-
1065
- }
1066
-
1067
- return $orders_per_product;
1068
-
1069
- }
1070
-
1071
- private function _getPrice($product){
1072
- $price = 0;
1073
- $helper=Mage::helper('autocompleteplus_autosuggest');
1074
- if ($product->getTypeId()=='grouped'){
1075
- $helper->prepareGroupedProductPrice($product);
1076
- $_minimalPriceValue = $product->getPrice();
1077
- if($_minimalPriceValue){
1078
- $price=$_minimalPriceValue;
1079
- }
1080
- }elseif($product->getTypeId()=='bundle'){
1081
- if(!$product->getFinalPrice()){
1082
- $price=$helper->getBundlePrice($product);
1083
- }else{
1084
- $price=$product->getFinalPrice();
1085
- }
1086
- }else{
1087
- $price =$product->getFinalPrice();
1088
- }
1089
- if(!$price){
1090
- $price=0;
1091
- }
1092
- return $price;
1093
- }
1094
-
1095
- /**
1096
-
1097
- * @param $storeId
1098
-
1099
- */
1100
-
1101
- private function _initCatalogCommonFields($storeId)
1102
- {
1103
- $this->imageField=Mage::getStoreConfig('autocompleteplus/config/imagefield');
1104
-
1105
- if (!$this->imageField) {
1106
- $this->imageField = 'thumbnail';
1107
- }
1108
-
1109
- $this->useAttributes = Mage::getStoreConfig('autocompleteplus/config/attributes');
1110
-
1111
- $this->currency = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
1112
-
1113
- $this->standardImageFields = array('image', 'small_image', 'thumbnail');
1114
-
1115
- $productScheme = Mage::getModel('catalog/product');
1116
-
1117
- if($this->useAttributes!='0'){
1118
- $this->attributes = Mage::getResourceModel('eav/entity_attribute_collection')
1119
-
1120
- ->setEntityTypeFilter($productScheme->getResource()->getTypeId())
1121
-
1122
- ->addFieldToFilter('is_user_defined', '1') // This can be changed to any attribute code
1123
-
1124
- ->load(false);
1125
- }
1126
-
1127
- }
1128
-
1129
- }
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Catalog extends Mage_Core_Model_Abstract
4
+ {
5
+ private $imageField;
6
+ private $standardImageFields;
7
+ private $useAttributes;
8
+ private $attributes;
9
+ private $currency;
10
+ private $pageNum;
11
+
12
+ public function renderCatalogXml($startInd, $count, $storeId = '', $orders = '', $month_interval = '', $checksum = '')
13
+ {
14
+ $this->_initCatalogCommonFields($storeId);
15
+
16
+ if (!$startInd) {
17
+ $startInd = 0;
18
+ }
19
+
20
+ //maxim products on one page is 10000
21
+ if (!$count || $count > 10000) {
22
+ $count = 10000;
23
+ }
24
+ //retrieving page number
25
+ $this->pageNum = floor(($startInd / $count));
26
+
27
+ $mage = Mage::getVersion();
28
+ $ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
29
+
30
+ $xml = '<?xml version="1.0"?>';
31
+ $xml .= '<catalog version="'.$ext.'" magento="'.$mage.'">';
32
+
33
+ $collection = Mage::getModel('catalog/product')->getCollection();
34
+ if (isset($storeId) && $storeId != '') {
35
+ $collection->addStoreFilter($storeId);
36
+ $store_id = $storeId;
37
+ } else {
38
+ $store_id = Mage::app()->getStore()->getStoreId();
39
+ }
40
+
41
+ //setting page+products on the page
42
+ $collection->getSelect()->limit($count, $startInd);//->limitPage($pageNum, $count);//setPage($pageNum, $count)->load();
43
+ $collection->load();
44
+
45
+ // number of orderes per product section
46
+ if (isset($orders) && $orders == '1') {
47
+ $product_id_list = array();
48
+ foreach ($collection as $product) {
49
+ $product_id_list[] = $product->getId();
50
+ }
51
+
52
+ if (isset($month_interval) && $month_interval != '') {
53
+ $month_interval = $month_interval;
54
+ } else {
55
+ $month_interval = 12;
56
+ }
57
+ $orders_per_product = $this->_getOrdersPerProduct($store_id, $product_id_list, $month_interval);
58
+ } else {
59
+ // end - number of orderes per product section
60
+ $orders_per_product = null;
61
+ }
62
+
63
+ $this->_root_category_id = Mage::app()->getStore($store_id)->getRootCategoryId();
64
+
65
+ if (isset($checksum) && $checksum != '') {
66
+ $is_checksum = $checksum;
67
+ $helper = Mage::helper('autocompleteplus_autosuggest');
68
+ $_tableprefix = (string) Mage::getConfig()->getTablePrefix();
69
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
70
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
71
+ } else {
72
+ $is_checksum = 0;
73
+ $helper = null;
74
+ $_tableprefix = null;
75
+ $write = null;
76
+ $read = null;
77
+ }
78
+
79
+ foreach ($collection as $product) {
80
+ $productCollData = $product->getData();
81
+ try {
82
+ $productModel = Mage::getModel('catalog/product')
83
+ ->setStore($storeId)->setStoreId($storeId)
84
+ ->load($productCollData['entity_id']);
85
+ } catch (Exception $e) {
86
+ continue;
87
+ }
88
+ $prodId = $productModel->getId();
89
+ $sku = $productModel->getSku();
90
+ $row = $this->renderProductXmlRow($productModel, $orders_per_product);
91
+ $xml .= $row;
92
+ if ($is_checksum && $helper) {
93
+ if ($helper->isChecksumTableExists()) {
94
+ $checksum = $helper->calculateChecksum($productModel);
95
+ $helper->updateSavedProductChecksum($_tableprefix, $read, $write, $prodId, $sku, $store_id, $checksum);
96
+ }
97
+ }
98
+ }
99
+ $xml .= '</catalog>';
100
+
101
+ return $xml;
102
+ }
103
+
104
+ public function renderUpdatesCatalogXml($count, $from, $to, $storeId)
105
+ {
106
+ $storeQ = '';
107
+
108
+ if ($storeId != '') {
109
+ $storeQ = 'AND store_id='.$storeId;
110
+ } else {
111
+ $storeId = Mage::app()->getStore()->getStoreId();
112
+ }
113
+ $this->_initCatalogCommonFields($storeId);
114
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
115
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
116
+
117
+ $_tableprefix = (string) Mage::getConfig()->getTablePrefix();
118
+ $sql = 'SELECT * FROM `'.$_tableprefix.'autocompleteplus_batches` WHERE update_date BETWEEN ? AND ? '.$storeQ.' order by update_date'.' LIMIT '.$count;
119
+ $updates = $read->fetchAll($sql, array($from, $to));
120
+
121
+ $mage = Mage::getVersion();
122
+ $ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
123
+ $this->_root_category_id = Mage::app()->getStore($storeId)->getRootCategoryId();
124
+
125
+ $xml = '<?xml version="1.0"?>';
126
+ $xml .= '<catalog fromdatetime="'.$from.'" version="'.$ext.'" magento="'.$mage.'">';
127
+ foreach ($updates as $batch) {
128
+ if ($batch['action'] == 'update') {
129
+ $productId = $batch['product_id'];
130
+ $sku = $batch['sku'];
131
+ $batchStoreId = $batch['store_id'];
132
+
133
+ if ($storeId != $batchStoreId) {
134
+ $this->currency = Mage::app()->getStore($batchStoreId)->getCurrentCurrencyCode();
135
+ }
136
+
137
+ $productModel = null;
138
+
139
+ if ($productId != null) {
140
+ // load product by id
141
+ try {
142
+ $productModel = Mage::getModel('catalog/product')
143
+ ->setStoreId($batchStoreId)
144
+ ->load($productId);
145
+ } catch (Exception $e) {
146
+ $batch['action'] = 'remove';
147
+ $xml .= $this->_makeRemoveRow($batch);
148
+ continue;
149
+ }
150
+ } else {
151
+ // product not found - changing action to remove
152
+ $batch['action'] = 'remove';
153
+ $xml .= $this->_makeRemoveRow($batch);
154
+ continue;
155
+
156
+ /*
157
+ * FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
158
+ */
159
+ // $productModel=Mage::getModel('catalog/product')
160
+ // ->loadByAttribute('sku', $sku)
161
+ // ->setStoreId($batchStoreId);
162
+ }
163
+
164
+ if ($productModel == null) {
165
+ continue;
166
+ }
167
+
168
+ $updatedate = $batch['update_date'];
169
+ $action = $batch['action'];
170
+ $xmlAttrs = 'action="'.$action.'" updatedate="'.$updatedate.'" storeid="'.$storeId.'"';
171
+ // $xmlAttrs='action="'.$action.'" updatedate="'.$updatedate.'"';
172
+ $xml .= $this->renderProductXmlRow($productModel, null, $xmlAttrs);
173
+ } else {
174
+ $xml .= $this->_makeRemoveRow($batch);
175
+ }
176
+ }
177
+ $xml .= '</catalog>';
178
+
179
+ return $xml;
180
+ }
181
+
182
+ public function renderCatalogFromIds($count, $fromId, $storeId)
183
+ {
184
+ $this->_initCatalogCommonFields($storeId);
185
+
186
+ $mage = Mage::getVersion();
187
+ $ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
188
+ $xml = '<catalog version="'.$ext.'" magento="'.$mage.'">';
189
+
190
+ $_productCollection = Mage::getModel('catalog/product')->getCollection()
191
+ ->addStoreFilter($storeId)
192
+ ->addAttributeToSelect('*')
193
+ ->addAttributeToFilter('entity_id', array('from' => $fromId));
194
+
195
+ $_productCollection->getSelect()->limit($count);
196
+
197
+ //add media gallery to collection
198
+
199
+ $action = 'getfromid';
200
+
201
+ foreach ($_productCollection as $product) {
202
+ if ($product) {
203
+ $id = $product->getId();
204
+ $lastUpdateddt = $product->getUpdatedAt();
205
+
206
+ $xmlAttrTemplate = 'last_updated="%s" get_by_id_status="1" action="%s" storeid="%s"';
207
+ $xmlAttrs = sprintf($xmlAttrTemplate,
208
+ $lastUpdateddt,
209
+ $action,
210
+ $storeId
211
+ );
212
+
213
+ $xml .= $this->renderProductXmlRow($product, null, $xmlAttrs);
214
+ } else {
215
+ $xml .= '<product action="'.$action.'" product="'.$id.'" get_by_id_status="0"></product>';
216
+ }
217
+ }
218
+
219
+ $xml .= '</catalog>';
220
+
221
+ return $xml;
222
+ }
223
+
224
+ /**
225
+ * Creates an XML representation of catalog by ids.
226
+ *
227
+ * @param array $ids
228
+ * @param int $storeId
229
+ *
230
+ * @return string
231
+ */
232
+ public function renderCatalogByIds($ids, $storeId = 0)
233
+ {
234
+ $this->_initCatalogCommonFields($storeId);
235
+
236
+ $mage = Mage::getVersion();
237
+ $ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
238
+ $xml = '<catalog version="'.$ext.'" magento="'.$mage.'">';
239
+
240
+ $_productCollection = Mage::getModel('catalog/product')->getCollection()
241
+ //->addStoreFilter($storeId)
242
+ //->addAttributeToSelect('*')
243
+ ->addAttributeToFilter('entity_id', array(
244
+ 'in' => $ids,
245
+ ));
246
+
247
+ $this->_root_category_id = Mage::app()->getStore($storeId)->getRootCategoryId();
248
+
249
+ $action = 'getbyid';
250
+
251
+ foreach ($ids as $id) {
252
+ $productModel = Mage::getModel('catalog/product')
253
+ ->setStoreId($storeId)
254
+ ->load($id);
255
+
256
+ if ($productModel->getId()) {
257
+ $lastUpdateddt = $productModel->getUpdatedAt();
258
+
259
+ $xmlAttrs = 'last_updated="'.$lastUpdateddt.'" get_by_id_status="1" action="'.$action.'" storeid="'.$storeId.'"';
260
+
261
+ $xml .= $this->renderProductXmlRow($productModel, null, $xmlAttrs);
262
+ } else {
263
+ $xml .= '<product action="'.$action.'" product="'.$id.'" get_by_id_status="0"></product>';
264
+ }
265
+ }
266
+
267
+ $xml .= '</catalog>';
268
+
269
+ return $xml;
270
+ }
271
+
272
+ public function getCategoryMap()
273
+ {
274
+ if (!$this->_categories) {
275
+ Mage::log('creating categories once', false, 'pjackson.log');
276
+ $categoryMap = array();
277
+ $categories = Mage::getModel('catalog/category')->getCollection()->load();
278
+
279
+ foreach ($categories as $category) {
280
+ $categoryMap[] = new Varien_Object(array(
281
+ 'id' => $category->getId(),
282
+ 'path' => $category->getPath(),
283
+ 'parent_id' => $category->getParentId(),
284
+ ));
285
+ }
286
+
287
+ $this->_categories = $categoryMap;
288
+ }
289
+
290
+ return $this->_categories;
291
+ }
292
+
293
+ public function getCategoryPathsByProduct(Mage_Catalog_Model_Product $product)
294
+ {
295
+ $productCategories = $product->getCategoryIds();
296
+ $root_category_id = $this->_root_category_id;
297
+ $paths = array_map(function ($category) use ($productCategories, $root_category_id) {
298
+ if (in_array($category->getId(), $productCategories)) {
299
+ $path = explode('/', $category->getPath());
300
+ //we don't want the root category for the entire site
301
+ array_shift($path);
302
+ if ($root_category_id && is_array($path) && $path[0] != $root_category_id) {
303
+ return array();
304
+ }
305
+ //we want more specific categories first
306
+ return implode(':', array_reverse($path));
307
+ }
308
+ }, $this->getCategoryMap());
309
+
310
+ return array_filter($paths);
311
+ }
312
+
313
+ public function renderProductXmlRow($productModel, $orders_per_product, $xmlAttrs = 'action="insert"')
314
+ {
315
+ $helper = Mage::helper('autocompleteplus_autosuggest');
316
+ $categories = $this->getCategoryPathsByProduct($productModel);
317
+ $price = $this->_getPrice($productModel);
318
+ $sku = $productModel->getSku();
319
+ $stock_status = $productModel->isInStock();
320
+ $stockItem = $productModel->getStockItem();
321
+
322
+ if ($stockItem) {
323
+ if ($stockItem->getIsInStock() && $stock_status) {
324
+ $sell = 1;
325
+ } else {
326
+ $sell = 0;
327
+ }
328
+ } else {
329
+ if ($stock_status) {
330
+ $sell = 1;
331
+ } else {
332
+ $sell = 0;
333
+ }
334
+ }
335
+
336
+ $productUrl = ''; // getting the product's url according to the store_id
337
+
338
+ $is_getUrlPath_supported = true;
339
+ if (method_exists('Mage', 'getVersionInfo')) { // getUrlPath is not supported on EE 1.13... & 1.14...
340
+ $edition_info = Mage::getVersionInfo();
341
+ if ($edition_info['major'] == 1 && $edition_info['minor'] >= 13) {
342
+ $is_getUrlPath_supported = false;
343
+ }
344
+ }
345
+
346
+ if (method_exists($productModel, 'getUrlPath') && $is_getUrlPath_supported) {
347
+ $productUrl = $productModel->getUrlPath();
348
+ if ($productUrl != '') {
349
+ $productUrl = Mage::getUrl($productUrl);
350
+ }
351
+ }
352
+ if ($productUrl == '' && method_exists($productModel, 'getProductUrl')) {
353
+ $productUrl = $productModel->getProductUrl();
354
+ // $pattern = '/\?___.*/';
355
+ // $productUrl = preg_replace($pattern, '', $productUrl);
356
+ }
357
+ if ($productUrl == '') {
358
+ $productUrl = Mage::helper('catalog/product')->getProductUrl($productModel->getId());
359
+ }
360
+
361
+ $prodId = $productModel->getId();
362
+ $prodDesc = $productModel->getDescription();
363
+ $prodShortDesc = $productModel->getShortDescription();
364
+ $prodName = $productModel->getName();
365
+ $visibility = $productModel->getVisibility();
366
+
367
+ if (defined('Mage_Catalog_Model_Product_Status::STATUS_ENABLED')) {
368
+ if ($productModel->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
369
+ $product_status = 1;
370
+ } else {
371
+ $product_status = 0;
372
+ }
373
+ } else {
374
+ if ($productModel->getStatus() == 1) {
375
+ $product_status = 1;
376
+ } else {
377
+ $product_status = 0;
378
+ }
379
+ }
380
+
381
+ try {
382
+ if (in_array($this->imageField, $this->standardImageFields)) {
383
+ $prodImage = Mage::helper('catalog/image')->init($productModel, $this->imageField);
384
+ } else {
385
+ $function = 'get'.$this->imageField;
386
+ $prodImage = $productModel->$function();
387
+ }
388
+
389
+ try {
390
+ $product_media_config = Mage::getModel('catalog/product_media_config');
391
+ $product_base_image = $product_media_config->getMediaUrl($productModel->getImage());
392
+ } catch (Exception $e) {
393
+ $product_base_image = '';
394
+ }
395
+ } catch (Exception $e) {
396
+ $prodImage = '';
397
+ $product_base_image = '';
398
+ }
399
+
400
+ if ($productModel->getTypeID() == 'configurable') {
401
+ $configurableAttributes = $this->_getConfigurableAttributes($productModel);
402
+
403
+ $configurableChildren = $this->_getConfigurableChildren($productModel);
404
+
405
+ // getting all children's ids
406
+ $configurable_children_ids = array();
407
+ foreach ($configurableChildren as $child_product) {
408
+ $configurable_children_ids[] = $child_product->getId();
409
+ }
410
+
411
+ // getting sellable option for the configurable product
412
+ if ($sell) { // Configurable is in stock
413
+ $is_in_stock_child_exist = false;
414
+ foreach ($configurableChildren as $child_product) {
415
+ if ($child_product->getStockItem()->getIsInStock()) {
416
+ if (method_exists($child_product, 'isSaleable') && !$child_product->isSaleable()) {
417
+ // the simple product is probably disabled (because its in stock)
418
+ continue;
419
+ }
420
+ $is_in_stock_child_exist = true;
421
+ break;
422
+ }
423
+ }
424
+ if (!$is_in_stock_child_exist) {
425
+ # Configurable is in stock, but has no in stock children
426
+ $sell = 0;
427
+ }
428
+ }
429
+
430
+ try {
431
+ $priceRange = $this->_getPriceRange($productModel);
432
+ } catch (Exception $e) {
433
+ $priceRange = 'price_min="" price_max=""';
434
+ }
435
+ } elseif ($productModel->getTypeID() == 'simple') {
436
+ $simple_product_parents = $this->_getSimpleProductParent($productModel);
437
+ $priceRange = 'price_min="" price_max=""';
438
+ } else {
439
+ $priceRange = 'price_min="" price_max=""';
440
+ }
441
+
442
+ $num_of_orders = ($orders_per_product != null && array_key_exists($prodId, $orders_per_product)) ? $orders_per_product[$prodId] : 0;
443
+ $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.' >';
444
+ $row .= '<description><![CDATA['.$prodDesc.']]></description>';
445
+ $row .= '<short><![CDATA['.$prodShortDesc.']]></short>';
446
+ $row .= '<name><![CDATA['.$prodName.']]></name>';
447
+ $row .= '<sku><![CDATA['.$sku.']]></sku>';
448
+
449
+ $summaryData = Mage::getModel('review/review_summary')
450
+ ->setStoreId($productModel->getStoreId())
451
+ ->load($prodId);
452
+ if (($summaryData['rating_summary'] || $summaryData['rating_summary'] == 0) && $summaryData['rating_summary'] != '') {
453
+ $row .= '<review><![CDATA['.$summaryData['rating_summary'].']]></review>';
454
+ $row .= '<reviews_count><![CDATA['.$summaryData['reviews_count'].']]></reviews_count>';
455
+ }
456
+
457
+ $new_from_date = $productModel->getNewsFromDate();
458
+ $new_to_date = $productModel->getNewsToDate();
459
+ if ($new_from_date) {
460
+ $row .= '<newfrom><![CDATA['.Mage::getModel('core/date')->timestamp($new_from_date).']]></newfrom>';
461
+ if ($new_to_date) {
462
+ $row .= '<newto><![CDATA['.Mage::getModel('core/date')->timestamp($new_to_date).']]></newto>';
463
+ }
464
+ }
465
+
466
+ $row .= '<purchase_popularity><![CDATA['.$num_of_orders.']]></purchase_popularity>';
467
+ $row .= '<product_status><![CDATA['.$product_status.']]></product_status>';
468
+
469
+ try {
470
+ $row .= '<creation_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getCreatedAt()).']]></creation_date>';
471
+ $row .= '<updated_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getUpdatedAt()).']]></updated_date>';
472
+ } catch (Exception $e) {
473
+ }
474
+
475
+ if ($this->useAttributes != '0') {
476
+ foreach ($this->attributes as $attr) {
477
+ $action = $attr->getAttributeCode();
478
+ $is_filterable = $attr->getis_filterable();
479
+ $attribute_label = $attr->getStoreLabel($productModel->getStoreId());
480
+
481
+ if ($attr->getfrontend_input() == 'select') {
482
+ if ($productModel->getData($action)) {
483
+ if (method_exists($productModel, 'getAttributeText')) {
484
+ $row .= '<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
485
+ <attribute_values><![CDATA['.$productModel->getAttributeText($action).']]></attribute_values>
486
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
487
+ </attribute>';
488
+ } else {
489
+ $row .= '<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
490
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
491
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
492
+ </attribute>';
493
+ }
494
+ }
495
+ } elseif ($attr->getfrontend_input() == 'textarea') {
496
+ if ($productModel->getData($action)) {
497
+ $row .= '<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
498
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
499
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
500
+ </attribute>';
501
+ }
502
+ } elseif ($attr->getfrontend_input() == 'price') {
503
+ if ($productModel->getData($action)) {
504
+ $row .= '<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
505
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
506
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
507
+ </attribute>';
508
+ }
509
+ } elseif ($attr->getfrontend_input() == 'text') {
510
+ if ($productModel->getData($action)) {
511
+ $row .= '<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
512
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
513
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
514
+ </attribute>';
515
+ }
516
+ } elseif ($attr->getfrontend_input() == 'multiselect') {
517
+ if ($productModel->getData($action)) {
518
+ $values = $productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
519
+ $row .= '<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
520
+ <attribute_values><![CDATA['.$values.']]></attribute_values>
521
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
522
+ </attribute>';
523
+ }
524
+ }
525
+ }
526
+
527
+ if ($productModel->getTypeID() == 'configurable' && count($configurableAttributes) > 0) {
528
+ $configural_attributes = array();
529
+ foreach ($configurableAttributes as $attrName => $confAttrN) {
530
+ if (is_array($confAttrN) && array_key_exists('values', $confAttrN)) {
531
+ $configural_attributes[] = $attrName;
532
+ $values = implode(' , ', $confAttrN['values']);
533
+ $row .= '<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
534
+ }
535
+ }
536
+ $simple_products_price = $this->_getSimpleProductsPriceOfConfigurable($productModel, $configurableChildren);
537
+
538
+ if (!empty($configural_attributes)) {
539
+ $product_variation = '<variants>';
540
+ try {
541
+ foreach ($configurableChildren as $child_product) {
542
+ if (!in_array($productModel->getStoreId(), $child_product->getStoreIds())) {
543
+ continue;
544
+ }
545
+
546
+ $is_variant_in_stock = ($child_product->getStockItem()->getIsInStock()) ? 1 : 0;
547
+
548
+ if (method_exists($child_product, 'isSaleable')) {
549
+ $is_variant_sellable = ($child_product->isSaleable()) ? 1 : 0;
550
+ } else {
551
+ $is_variant_sellable = '';
552
+ // $is_variant_sellable = (Mage::getModel('catalog/product')
553
+ // ->setStore($productModel->getStoreId())
554
+ // ->setStoreId($productModel->getStoreId())
555
+ // ->load($child_product->getId())
556
+ // ->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
557
+ }
558
+
559
+ if (method_exists($child_product, 'getVisibility')) {
560
+ $is_variant_visible = ($child_product->getVisibility()) ? 1 : 0;
561
+ } else {
562
+ $is_variant_visible = '';
563
+ // $is_variant_visible = (Mage::getModel('catalog/product')
564
+ // ->setStore($productModel->getStoreId())
565
+ // ->setStoreId($productModel->getStoreId())
566
+ // ->load($child_product->getId())
567
+ // ->getVisibility());
568
+ }
569
+
570
+ $variant_price = (array_key_exists($child_product->getId(), $simple_products_price)) ?
571
+ $simple_products_price[$child_product->getId()] : '';
572
+
573
+ $product_variation .= '<variant id="'.$child_product->getId().'" type="'.$child_product->getTypeID().
574
+ '" visibility="'.$is_variant_visible.'" is_in_stock="'.$is_variant_in_stock.'" is_seallable="'.$is_variant_sellable.'" price="'.$variant_price.'">';
575
+ $product_variation .= '<name><![CDATA['.$child_product->getName().']]></name>';
576
+
577
+ $attributes = $child_product->getAttributes();
578
+ foreach ($attributes as $attribute) {
579
+ if (!$attribute['is_configurable'] || !in_array($attribute['store_label'], $configural_attributes)) { // || !$attribute->getIsVisibleOnFront()
580
+ continue;
581
+ }
582
+
583
+ $product_variation .= '<variant_attribute is_configurable="1" is_filterable="'.$attribute->getis_filterable().
584
+ '" name="'.$attribute['store_label'].'" name_code="'.$attribute->getId().
585
+ '" value_code="'.$child_product->getData($attribute->getAttributeCode()).
586
+ '"><![CDATA['.$attribute->getFrontend()->getValue($child_product).
587
+ ']]></variant_attribute>';
588
+ }
589
+ $product_variation .= '</variant>';
590
+ }
591
+ } catch (Exception $e) {
592
+ }
593
+ $product_variation .= '</variants>';
594
+ $row .= $product_variation;
595
+ }
596
+
597
+ $row .= '<simpleproducts><![CDATA['.implode(',', $configurable_children_ids).']]></simpleproducts>';
598
+ }
599
+
600
+ if ($productModel->getTypeID() == 'simple') {
601
+ $row .= '<product_parents><![CDATA['.implode(',', $simple_product_parents).']]></product_parents>';
602
+ }
603
+ }
604
+
605
+ $row .= '<categories><![CDATA['.implode(';', $categories).']]></categories>';
606
+ $row .= '</product>';
607
+
608
+ return $helper->escapeXml($row);
609
+ }
610
+
611
+ private function _makeUpdateRow($batch, $attributes)
612
+ {
613
+ $productId = $batch['product_id'];
614
+
615
+ $sku = $batch['sku'];
616
+
617
+ $storeId = $batch['store_id'];
618
+
619
+ $updatedate = $batch['update_date'];
620
+
621
+ $action = $batch['action'];
622
+
623
+ $currency = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
624
+
625
+ if ($productId != null) {
626
+ $productModel = Mage::getModel('catalog/product')
627
+
628
+ ->setStoreId($storeId)
629
+
630
+ ->load($productId);
631
+
632
+ if ($productModel == null) {
633
+ return '';
634
+ }
635
+ } else {
636
+
637
+ /*
638
+
639
+ * FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
640
+
641
+ */
642
+
643
+ $productModel = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
644
+
645
+ if ($productModel == null) {
646
+ return '';
647
+ }
648
+
649
+ $productModel = $productModel->setStoreId($storeId);
650
+
651
+ $productId = $productModel->getId();
652
+ }
653
+
654
+ if ($productModel == null) {
655
+ return '';
656
+ }
657
+
658
+ $price = $this->getPrice($productModel);
659
+
660
+ $sku = $productModel->getSku();
661
+
662
+ $status = $productModel->isInStock();
663
+
664
+ $stockItem = $productModel->getStockItem();
665
+
666
+ $categoriesNames = '';
667
+
668
+ $categories = $productModel->getCategoryCollection()
669
+ ->addAttributeToSelect('name');
670
+
671
+ foreach ($categories as $category) {
672
+ $categoriesNames .= $category->getName().':'.$category->getId().';';
673
+ }
674
+
675
+ if ($stockItem->getIsInStock() && $status) {
676
+ $sell = 1;
677
+ } else {
678
+ $sell = 0;
679
+ }
680
+
681
+ $productUrl = Mage::helper('catalog/product')->getProductUrl($productId);
682
+
683
+ $prodId = $productModel->getId();
684
+
685
+ $prodDesc = $productModel->getDescription();
686
+
687
+ $prodShortDesc = $productModel->getShortDescription();
688
+
689
+ $prodName = $productModel->getName();
690
+
691
+ $visibility = $productModel->getVisibility();
692
+
693
+ try {
694
+ if (in_array($this->imageField, $this->standardImageFields)) {
695
+ $prodImage = Mage::helper('catalog/image')->init($productModel, $this->imageField);
696
+ } else {
697
+ $function = 'get'.$this->imageField;
698
+
699
+ $prodImage = $productModel->$function();
700
+ }
701
+ } catch (Exception $e) {
702
+ $prodImage = '';
703
+ }
704
+
705
+ if ($productModel->getTypeID() == 'configurable') {
706
+ $configurableAttributes = $this->_getConfigurableAttributes($productModel);
707
+
708
+ try {
709
+ $priceRange = $this->_getPriceRange($productModel);
710
+ } catch (Exception $e) {
711
+ $priceRange = 'price_min="" price_max=""';
712
+ }
713
+ } else {
714
+ $priceRange = 'price_min="" price_max=""';
715
+ }
716
+
717
+ $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.'" >';
718
+
719
+ $row .= '<description><![CDATA['.$prodDesc.']]></description>';
720
+
721
+ $row .= '<short><![CDATA['.$prodShortDesc.']]></short>';
722
+
723
+ $row .= '<name><![CDATA['.$prodName.']]></name>';
724
+
725
+ $row .= '<sku><![CDATA['.$sku.']]></sku>';
726
+
727
+ if ($attributes != null) {
728
+ foreach ($attributes as $attr) {
729
+ $action = $attr->getAttributeCode();
730
+
731
+ $is_filterable = $attr->getis_filterable();
732
+
733
+ if ($attr->getfrontend_input() == 'select') {
734
+ if ($productModel->getData($action)) {
735
+ $row .= '<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getAttributeText($action).']]></attribute>';
736
+ }
737
+ } elseif ($attr->getfrontend_input() == 'textarea') {
738
+ if ($productModel->getData($action)) {
739
+ $row .= '<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
740
+ }
741
+ } elseif ($attr->getfrontend_input() == 'price') {
742
+ if ($productModel->getData($action)) {
743
+ $row .= '<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
744
+ }
745
+ } elseif ($attr->getfrontend_input() == 'text') {
746
+ if ($productModel->getData($action)) {
747
+ $row .= '<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
748
+ }
749
+ } elseif ($attr->getfrontend_input() == 'multiselect') {
750
+ if ($productModel->getData($action)) {
751
+ $values = $productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
752
+
753
+ $row .= '<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'"><![CDATA['.$values.']]></attribute>';
754
+ }
755
+ }
756
+ }
757
+
758
+ if ($productModel->getTypeID() == 'configurable' && count($configurableAttributes) > 0) {
759
+ foreach ($configurableAttributes as $attrName => $confAttrN) {
760
+ if (is_array($confAttrN) && array_key_exists('values', $confAttrN)) {
761
+ $values = implode(' , ', $confAttrN['values']);
762
+
763
+ $row .= '<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
764
+ }
765
+ }
766
+ }
767
+ }
768
+
769
+ $row .= '<categories><![CDATA['.$categoriesNames.']]></categories>';
770
+
771
+ $row .= '</product>';
772
+
773
+ return $row;
774
+ }
775
+
776
+ private function _makeRemoveRow($batch)
777
+ {
778
+ $updatedate = $batch['update_date'];
779
+ $action = $batch['action'];
780
+ $sku = $batch['sku'];
781
+ $productId = $batch['product_id'];
782
+ $storeId = $batch['store_id'];
783
+
784
+ $row = '<product updatedate="'.$updatedate.'" action="'.$action.'" id="'.$productId.'" storeid="'.$storeId.'">';
785
+ $row .= '<sku><![CDATA['.$sku.']]></sku>';
786
+ $row .= '<id><![CDATA['.$productId.']]></id>';
787
+ $row .= '</product>';
788
+
789
+ return $row;
790
+ }
791
+
792
+ private function _getConfigurableChildren($product)
793
+ {
794
+ $childProducts = Mage::getModel('catalog/product_type_configurable')
795
+ ->getUsedProducts(null, $product);
796
+
797
+ return $childProducts;
798
+ }
799
+
800
+ private function _getSimpleProductParent($product)
801
+ {
802
+ try {
803
+ $parent_products_ids_list = Mage::getModel('catalog/product_type_configurable')
804
+ ->getParentIdsByChild($product->getId());
805
+
806
+ return $parent_products_ids_list;
807
+ } catch (Exception $e) {
808
+ return array();
809
+ }
810
+ }
811
+
812
+ private function _getConfigurableAttributes($product)
813
+ {
814
+ try {
815
+ // Collect options applicable to the configurable product
816
+ $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
817
+
818
+ $attributeOptions = array();
819
+
820
+ foreach ($productAttributeOptions as $productAttribute) {
821
+ $attributeFull = Mage::getModel('eav/config')->getAttribute('catalog_product', $productAttribute['attribute_code']);
822
+
823
+ foreach ($productAttribute['values'] as $attribute) {
824
+ $attributeOptions[$productAttribute['store_label']]['values'][] = $attribute['store_label'];
825
+ }
826
+
827
+ $attributeOptions[$productAttribute['store_label']]['is_filterable'] = $attributeFull['is_filterable'];
828
+ $attributeOptions[$productAttribute['store_label']]['frontend_input'] = $attributeFull['frontend_input'];
829
+ }
830
+
831
+ return $attributeOptions;
832
+ } catch (Exception $e) {
833
+ return array();
834
+ }
835
+ }
836
+
837
+ private function _getPriceRange($product)
838
+ {
839
+ $max = '';
840
+ $min = '';
841
+
842
+ $pricesByAttributeValues = array();
843
+ $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
844
+ $basePrice = $product->getFinalPrice();
845
+ $items = $attributes->getItems();
846
+ if (is_array($items)) {
847
+ foreach ($items as $attribute) {
848
+ $prices = $attribute->getPrices();
849
+ if (is_array($prices)) {
850
+ foreach ($prices as $price) {
851
+ if ($price['is_percent']) { //if the price is specified in percents
852
+ $pricesByAttributeValues[$price['value_index']] = (float) $price['pricing_value'] * $basePrice / 100;
853
+ } else { //if the price is absolute value
854
+ $pricesByAttributeValues[$price['value_index']] = (float) $price['pricing_value'];
855
+ }
856
+ }
857
+ }
858
+ }
859
+ }
860
+
861
+ $simple = $product->getTypeInstance()->getUsedProducts();
862
+ foreach ($simple as $sProduct) {
863
+ $totalPrice = $basePrice;
864
+ foreach ($attributes as $attribute) {
865
+ $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
866
+ if (isset($pricesByAttributeValues[$value])) {
867
+ $totalPrice += $pricesByAttributeValues[$value];
868
+ }
869
+ }
870
+ if (!$max || $totalPrice > $max) {
871
+ $max = $totalPrice;
872
+ }
873
+ if (!$min || $totalPrice < $min) {
874
+ $min = $totalPrice;
875
+ }
876
+ }
877
+ $priceRange = 'price_min="'.$min.'" price_max="'.$max.'"';
878
+
879
+ return $priceRange;
880
+ }
881
+
882
+ private function _getSimpleProductsPriceOfConfigurable($product, $configurable_children)
883
+ {
884
+ $simple_products_price = array();
885
+ $pricesByAttributeValues = array();
886
+ $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
887
+ $basePrice = $product->getFinalPrice();
888
+ $items = $attributes->getItems();
889
+ if (is_array($items)) {
890
+ foreach ($items as $attribute) {
891
+ $prices = $attribute->getPrices();
892
+ if (is_array($prices)) {
893
+ foreach ($prices as $price) {
894
+ if ($price['is_percent']) { //if the price is specified in percents
895
+ $pricesByAttributeValues[$price['value_index']] = (float) $price['pricing_value'] * $basePrice / 100;
896
+ } else { //if the price is absolute value
897
+ $pricesByAttributeValues[$price['value_index']] = (float) $price['pricing_value'];
898
+ }
899
+ }
900
+ }
901
+ }
902
+ }
903
+
904
+ foreach ($configurable_children as $sProduct) {
905
+ $totalPrice = $basePrice;
906
+ foreach ($attributes as $attribute) {
907
+ $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
908
+ if (isset($pricesByAttributeValues[$value])) {
909
+ $totalPrice += $pricesByAttributeValues[$value];
910
+ }
911
+ }
912
+ $simple_products_price[$sProduct->getId()] = $totalPrice;
913
+ }
914
+
915
+ return $simple_products_price;
916
+ }
917
+
918
+ private function _getOrdersPerProduct($store_id, $product_id_list, $month_interval)
919
+ {
920
+ if (count($product_id_list) <= 0) {
921
+ return;
922
+ }
923
+
924
+ $id_str = implode(',', $product_id_list);
925
+
926
+ $query = Mage::getResourceModel('sales/order_item_collection');
927
+
928
+ $select = $query->getSelect()->reset(Zend_Db_Select::COLUMNS)
929
+
930
+ ->columns(array('product_id', 'SUM(qty_ordered)'))
931
+
932
+ ->where(new Zend_Db_Expr('store_id = '.$store_id))
933
+
934
+ ->where(new Zend_Db_Expr('product_id IN ('.$id_str.')'))
935
+
936
+ ->where(new Zend_Db_Expr('created_at BETWEEN NOW() - INTERVAL '.$month_interval.' MONTH AND NOW()'))
937
+
938
+ ->group(array('product_id'));
939
+
940
+ $resource = Mage::getSingleton('core/resource');
941
+
942
+ $readConnection = $resource->getConnection('core_read');
943
+
944
+ $results = $readConnection->fetchAll($select);
945
+
946
+ $orders_per_product = array();
947
+
948
+ foreach ($results as $res) {
949
+ $orders_per_product[$res['product_id']] = (int) $res['SUM(qty_ordered)'];
950
+ }
951
+
952
+ return $orders_per_product;
953
+ }
954
+
955
+ private function _getPrice($product)
956
+ {
957
+ $price = 0;
958
+ $helper = Mage::helper('autocompleteplus_autosuggest');
959
+ if ($product->getTypeId() == 'grouped') {
960
+ $helper->prepareGroupedProductPrice($product);
961
+ $_minimalPriceValue = $product->getPrice();
962
+ if ($_minimalPriceValue) {
963
+ $price = $_minimalPriceValue;
964
+ }
965
+ } elseif ($product->getTypeId() == 'bundle') {
966
+ if (!$product->getFinalPrice()) {
967
+ $price = $helper->getBundlePrice($product);
968
+ } else {
969
+ $price = $product->getFinalPrice();
970
+ }
971
+ } else {
972
+ $price = $product->getFinalPrice();
973
+ }
974
+ if (!$price) {
975
+ $price = 0;
976
+ }
977
+
978
+ return $price;
979
+ }
980
+
981
+ /**
982
+ * @param $storeId
983
+ */
984
+ private function _initCatalogCommonFields($storeId)
985
+ {
986
+ $this->imageField = Mage::getStoreConfig('autocompleteplus/config/imagefield');
987
+
988
+ if (!$this->imageField) {
989
+ $this->imageField = 'thumbnail';
990
+ }
991
+
992
+ $this->useAttributes = Mage::getStoreConfig('autocompleteplus/config/attributes');
993
+
994
+ $this->currency = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
995
+
996
+ $this->standardImageFields = array('image', 'small_image', 'thumbnail');
997
+
998
+ $productScheme = Mage::getModel('catalog/product');
999
+
1000
+ if ($this->useAttributes != '0') {
1001
+ $this->attributes = Mage::getResourceModel('eav/entity_attribute_collection')
1002
+
1003
+ ->setEntityTypeFilter($productScheme->getResource()->getTypeId())
1004
+
1005
+ ->addFieldToFilter('is_user_defined', '1') // This can be changed to any attribute code
1006
+
1007
+ ->load(false);
1008
+ }
1009
+ }
1010
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/Model/Catalogreport.php CHANGED
@@ -9,8 +9,9 @@ class Autocompleteplus_Autosuggest_Model_Catalogreport extends Mage_Core_Model_A
9
  try {
10
  $collection = $this->getProductCollectionStoreFilterFactory();
11
  $this->addDisabledFilterToCollection($collection);
 
12
  return $collection->getSize();
13
- } catch(Exception $e) {
14
  return -1;
15
  }
16
  }
@@ -20,8 +21,9 @@ class Autocompleteplus_Autosuggest_Model_Catalogreport extends Mage_Core_Model_A
20
  try {
21
  $collection = $this->getProductCollectionStoreFilterFactory();
22
  $this->addEnabledFilterToCollection($collection);
 
23
  return $collection->getSize();
24
- } catch(Exception $e) {
25
  return -1;
26
  }
27
  }
@@ -32,26 +34,28 @@ class Autocompleteplus_Autosuggest_Model_Catalogreport extends Mage_Core_Model_A
32
  $collection = $this->getProductCollectionStoreFilterFactory();
33
  $this->addEnabledFilterToCollection($collection);
34
  $this->addVisibleInSearchFilterToCollection($collection);
 
35
  return $collection->getSize();
36
- } catch(Exception $e) {
37
  return -1;
38
  }
39
  }
40
 
41
  public function getSearchableProducts2Count()
42
  {
43
- try{
44
  $num_of_searchable_products = Mage::getModel('catalog/product')->getCollection()
45
  ->addStoreFilter($this->getCurrentStoreId())
46
  ->addAttributeToFilter('status', array('eq' => 1)) // Mage_Catalog_Model_Product_Status::STATUS_ENABLED
47
  ->addAttributeToFilter(array(
48
- array('attribute'=>'visibility', 'finset'=>3), // visibility Search
49
- array('attribute'=>'visibility', 'finset'=>4), // visibility Catalog, Search
50
  ))
51
  ->getSize();
 
52
  return $num_of_searchable_products;
53
- } catch (Exception $e){
54
- return -1;
55
  }
56
  }
57
 
@@ -82,19 +86,20 @@ class Autocompleteplus_Autosuggest_Model_Catalogreport extends Mage_Core_Model_A
82
  }
83
 
84
  /**
85
- * Return the current store - can be overridden with post
 
86
  * @return int
87
  */
88
  public function getCurrentStoreId()
89
  {
90
- if(!$this->_storeId){
91
  $post = $this->getRequest()->getParams();
92
  if (array_key_exists('store_id', $post)) {
93
  $this->_storeId = $post['store_id'];
94
- } else if (array_key_exists('store', $post)) {
95
  $this->_storeId = $post['store'];
96
  } else {
97
- $this->_storeId = Mage::app()->getStore()->getStoreId();
98
  }
99
  }
100
 
@@ -103,6 +108,6 @@ class Autocompleteplus_Autosuggest_Model_Catalogreport extends Mage_Core_Model_A
103
 
104
  public function getRequest()
105
  {
106
- return Mage::app()->getRequest();
107
  }
108
- }
9
  try {
10
  $collection = $this->getProductCollectionStoreFilterFactory();
11
  $this->addDisabledFilterToCollection($collection);
12
+
13
  return $collection->getSize();
14
+ } catch (Exception $e) {
15
  return -1;
16
  }
17
  }
21
  try {
22
  $collection = $this->getProductCollectionStoreFilterFactory();
23
  $this->addEnabledFilterToCollection($collection);
24
+
25
  return $collection->getSize();
26
+ } catch (Exception $e) {
27
  return -1;
28
  }
29
  }
34
  $collection = $this->getProductCollectionStoreFilterFactory();
35
  $this->addEnabledFilterToCollection($collection);
36
  $this->addVisibleInSearchFilterToCollection($collection);
37
+
38
  return $collection->getSize();
39
+ } catch (Exception $e) {
40
  return -1;
41
  }
42
  }
43
 
44
  public function getSearchableProducts2Count()
45
  {
46
+ try {
47
  $num_of_searchable_products = Mage::getModel('catalog/product')->getCollection()
48
  ->addStoreFilter($this->getCurrentStoreId())
49
  ->addAttributeToFilter('status', array('eq' => 1)) // Mage_Catalog_Model_Product_Status::STATUS_ENABLED
50
  ->addAttributeToFilter(array(
51
+ array('attribute' => 'visibility', 'finset' => 3), // visibility Search
52
+ array('attribute' => 'visibility', 'finset' => 4), // visibility Catalog, Search
53
  ))
54
  ->getSize();
55
+
56
  return $num_of_searchable_products;
57
+ } catch (Exception $e) {
58
+ return -1;
59
  }
60
  }
61
 
86
  }
87
 
88
  /**
89
+ * Return the current store - can be overridden with post.
90
+ *
91
  * @return int
92
  */
93
  public function getCurrentStoreId()
94
  {
95
+ if (!$this->_storeId) {
96
  $post = $this->getRequest()->getParams();
97
  if (array_key_exists('store_id', $post)) {
98
  $this->_storeId = $post['store_id'];
99
+ } elseif (array_key_exists('store', $post)) {
100
  $this->_storeId = $post['store'];
101
  } else {
102
+ $this->_storeId = Mage::app()->getStore()->getStoreId();
103
  }
104
  }
105
 
108
 
109
  public function getRequest()
110
  {
111
+ return Mage::app()->getRequest();
112
  }
113
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Checksum.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Checksum extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('autocompleteplus_autosuggest/checksum');
8
+ }
9
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Config.php CHANGED
@@ -1,8 +1,351 @@
1
  <?php
 
2
  class Autocompleteplus_Autosuggest_Model_Config extends Mage_Core_Model_Abstract
3
  {
4
- protected function _construct()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  {
6
- $this->_init('autocompleteplus_autosuggest/config');
7
  }
8
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+
3
  class Autocompleteplus_Autosuggest_Model_Config extends Mage_Core_Model_Abstract
4
  {
5
+ protected $_helper = false;
6
+ protected $_apiEndpoint = false;
7
+
8
+ /**
9
+ * Define XML Config paths and states.
10
+ */
11
+ const XML_SEARCH_LAYERED_DISABLED = 0;
12
+ const XML_SEARCH_LAYERED_ENABLED = 1;
13
+ const XML_SEARCH_LAYERED_CONFIG = 'autocompleteplus/config/layered';
14
+ const XML_API_ENDPOINT_CONFIG = 'default/autocompleteplus/config/api_endpoint';
15
+ const XML_STORE_EMAIL_CONFIG = 'autocompleteplus/config/store_email';
16
+ const XML_AUTHORIZATION_KEY_CONFIG = 'autocompleteplus_autosuggest/config/authorization_key';
17
+ const XML_UUID_CONFIG = 'autocompleteplus_autosuggest/config/uuid';
18
+ const XML_SITE_URL_CONFIG = 'autocompleteplus_autosuggest/config/site_url';
19
+ const XML_IS_REACHABLE_CONFIG = 'autocompleteplus_autosuggest/config/is_reachable';
20
+ const XML_ERROR_MESSAGE_CONFIG = 'autocompleteplus_autosuggest/config/error_message';
21
+
22
+ /**
23
+ * Fetch Magento Config Model.
24
+ *
25
+ * @return false|Mage_Core_Model_Config
26
+ */
27
+ protected function _getMageConfig()
28
  {
29
+ return Mage::getModel('core/config');
30
  }
31
+
32
+ /**
33
+ * Fetch API Endpoint URL.
34
+ *
35
+ * @return string|Mage_Core_Model_Config_Element
36
+ */
37
+ public function getEndpoint()
38
+ {
39
+ if (!$this->_apiEndpoint) {
40
+ $this->_apiEndpoint = Mage::getConfig()->getNode(self::XML_API_ENDPOINT_CONFIG);
41
+ }
42
+
43
+ return $this->_apiEndpoint;
44
+ }
45
+
46
+ /**
47
+ * Fetch AA Helper.
48
+ *
49
+ * @return bool|Mage_Core_Helper_Abstract
50
+ */
51
+ protected function _getHelper()
52
+ {
53
+ if (!$this->_helper) {
54
+ $this->_helper = Mage::helper('autocompleteplus_autosuggest');
55
+ }
56
+
57
+ return $this->_helper;
58
+ }
59
+
60
+ /**
61
+ * Enable Layered Navigation.
62
+ *
63
+ * @param string $scope
64
+ * @param int $scopeId
65
+ */
66
+ public function enableLayeredNavigation($scope = 'default', $scopeId = 0)
67
+ {
68
+ $this->_getMageConfig()->saveConfig(self::XML_SEARCH_LAYERED_CONFIG, self::XML_SEARCH_LAYERED_ENABLED, $scope, $scopeId);
69
+ }
70
+
71
+ /**
72
+ * Disable Layered Navigation.
73
+ *
74
+ * @param string $scope
75
+ * @param int $scopeId
76
+ */
77
+ public function disableLayeredNavigation($scope = 'default', $scopeId = 0)
78
+ {
79
+ $this->_getMageConfig()->saveConfig(self::XML_SEARCH_LAYERED_CONFIG, self::XML_SEARCH_LAYERED_DISABLED, $scope, $scopeId);
80
+ }
81
+
82
+ /**
83
+ * Get Layered Navigation Status.
84
+ *
85
+ * @param $scopeId
86
+ *
87
+ * @return mixed
88
+ */
89
+ public function getLayeredNavigationStatus($scopeId)
90
+ {
91
+ return Mage::getStoreConfig(self::XML_SEARCH_LAYERED_CONFIG, $scopeId);
92
+ }
93
+
94
+ /**
95
+ * Set Authorization Key.
96
+ *
97
+ * @param $key
98
+ */
99
+ public function setAuthorizationKey($key)
100
+ {
101
+ $this->_getMageConfig()->saveConfig(self::XML_AUTHORIZATION_KEY_CONFIG, $key);
102
+ }
103
+
104
+ /**
105
+ * Get Authorization Key.
106
+ *
107
+ * @return mixed
108
+ */
109
+ public function getAuthorizationKey()
110
+ {
111
+ return Mage::getStoreConfig(self::XML_AUTHORIZATION_KEY_CONFIG);
112
+ }
113
+
114
+ /**
115
+ * Set UUID.
116
+ *
117
+ * @param $uuid
118
+ */
119
+ public function setUUID($uuid)
120
+ {
121
+ $this->_getMageConfig()->saveConfig(self::XML_UUID_CONFIG, $uuid);
122
+ }
123
+
124
+ /**
125
+ * Get UUID.
126
+ *
127
+ * @return mixed
128
+ */
129
+ public function getUUID()
130
+ {
131
+ return Mage::getStoreConfig(self::XML_UUID_CONFIG);
132
+ }
133
+
134
+ /**
135
+ * Get UUID and Authorization key.
136
+ *
137
+ * @return array
138
+ */
139
+ public function getBothKeys()
140
+ {
141
+ return array('uuid' => $this->getUUID(), 'authkey' => $this->getAuthorizationKey());
142
+ }
143
+
144
+ /**
145
+ * Set Site URL.
146
+ *
147
+ * @param $url
148
+ */
149
+ public function setSiteUrl($url)
150
+ {
151
+ $this->_getMageConfig()->saveConfig(self::XML_SITE_URL_CONFIG, $url);
152
+ }
153
+
154
+ /**
155
+ * Get Site URL.
156
+ *
157
+ * @return mixed
158
+ */
159
+ public function getSiteUrl()
160
+ {
161
+ return Mage::getStoreConfig(self::XML_SITE_URL_CONFIG);
162
+ }
163
+
164
+ /**
165
+ * Set Is Reachable.
166
+ *
167
+ * @param $reachable
168
+ */
169
+ public function setIsReachable($reachable)
170
+ {
171
+ $this->_getMageConfig()->saveConfig(self::XML_IS_REACHABLE_CONFIG, $reachable);
172
+ }
173
+
174
+ /**
175
+ * Get Is Reachable.
176
+ *
177
+ * @return mixed
178
+ */
179
+ public function isReachable()
180
+ {
181
+ return Mage::getStoreConfig(self::XML_IS_REACHABLE_CONFIG);
182
+ }
183
+
184
+ /**
185
+ * Set Error Message.
186
+ *
187
+ * @param $message
188
+ */
189
+ public function setErrorMessage($message)
190
+ {
191
+ $this->_getMageConfig()->saveConfig(self::XML_ERROR_MESSAGE_CONFIG, $message);
192
+ }
193
+
194
+ /**
195
+ * Get Error Message.
196
+ *
197
+ * @return mixed
198
+ */
199
+ public function getErrorMessage()
200
+ {
201
+ return Mage::getStoreConfig(self::XML_ERROR_MESSAGE_CONFIG);
202
+ }
203
+
204
+ /**
205
+ * Get Module Version.
206
+ *
207
+ * @return mixed
208
+ */
209
+ public function getModuleVersion()
210
+ {
211
+ return Mage::getConfig()->getModuleConfig('Autocompleteplus_Autosuggest')->version;
212
+ }
213
+
214
+ /**
215
+ * Generate Config for AutocompletePlus.
216
+ *
217
+ * @param bool $UUID
218
+ *
219
+ * @return $this
220
+ *
221
+ * @throws Zend_Http_Client_Exception
222
+ */
223
+ public function generateConfig($UUID = false)
224
+ {
225
+ $client = new Varien_Http_Client();
226
+ $fileIo = new Varien_Io_File();
227
+ $fileIo->open(array('path' => Mage::getBaseDir()));
228
+ $robotsTxtContent = $fileIo->read('robots.txt');
229
+ $config = array(
230
+ 'adapter' => 'Zend_Http_Client_Adapter_Curl',
231
+ 'curloptions' => array(
232
+ CURLOPT_RETURNTRANSFER => 1,
233
+ ),
234
+ );
235
+ $params = array(
236
+ 'site' => Mage::getBaseUrl(),
237
+ 'email' => Mage::getStoreConfig(self::XML_STORE_EMAIL_CONFIG),
238
+ 'f' => $this->_getHelper()->getVersion(),
239
+ 'multistore' => $this->_getHelper()->getMultiStoreDataJson(),
240
+ );
241
+
242
+ if ($UUID) {
243
+ $params['uuid'] = $UUID;
244
+ }
245
+
246
+ $client->setUri($this->getEndpoint().DS.'install')
247
+ ->setMethod('POST')
248
+ ->setConfig($config);
249
+
250
+ $client->setParameterPost($params);
251
+
252
+ try {
253
+ $response = $client->request();
254
+
255
+ if ($response->isSuccessful()) {
256
+ $responseData = json_decode($response->getBody(), true);
257
+
258
+ /*
259
+ * Validate uuid is less than 50 characters - why?
260
+ * Validate uuid exists
261
+ */
262
+ if (isset($responseData['uuid']) && strlen($responseData['uuid']) > 50) {
263
+ Mage::log('Registration failed - please check response below', null, 'autocomplete.log', true);
264
+ $this->_sendError('Could not get license string.');
265
+
266
+ return false;
267
+ } elseif (!isset($responseData['uuid'])) {
268
+ Mage::log('Registration failed - please check response below', null, 'autocomplete.log', true);
269
+ $this->_sendError('Could not get license string.');
270
+
271
+ return false;
272
+ }
273
+
274
+ $siteMapUrl = 'Sitemap:http://magento.instantsearchplus.com/ext_sitemap?u='.$responseData['uuid'].PHP_EOL;
275
+ if ($fileIo->fileExists('robots.txt')) {
276
+ if (strpos($robotsTxtContent, $siteMapUrl) === false) {
277
+ if ($fileIo->isWriteable('robots.txt')) {
278
+ $fileIo->write('robots.txt', $robotsTxtContent.$siteMapUrl);
279
+ } else {
280
+ //write message that file is not writteble
281
+ $this->_sendError('File '.$fileIo->pwd().DS.'robots.txt is not writable.');
282
+ }
283
+ }
284
+ } else {
285
+ //create file
286
+ if ($fileIo->isWriteable(Mage::getBaseDir())) {
287
+ //create robots sitemap
288
+ $fileIo->write('robots.txt', $siteMapUrl);
289
+ } else {
290
+ //write message that directory is not writeable
291
+ $this->_sendError('Directory '.Mage::getBaseDir().' is not writable..');
292
+ }
293
+ }
294
+ }
295
+ } catch (Exception $e) {
296
+ $responseData['uuid'] = 'failed';
297
+ $errorMessage = $e->getMessage();
298
+ Mage::logException($e);
299
+ Mage::log('Install failed with a message: '.$e->getMessage(), null, 'autocomplete.log', true);
300
+ $this->_sendError($e->getMessage());
301
+ }
302
+
303
+ $this->setAuthorizationKey($responseData['authentication_key']);
304
+ $this->setUUID($responseData['uuid']);
305
+ $this->setSiteUrl(Mage::getBaseUrl());
306
+ $this->setIsReachable($responseData['is_reachable']);
307
+ $this->setErrorMessage(isset($errorMessage) ? $errorMessage : '');
308
+
309
+ Mage::dispatchEvent('autocompleteplus_autosuggest_config_creation_after',
310
+ array('config' => $this, 'response' => $response, 'responseData' => $responseData));
311
+
312
+ return $this;
313
+ }
314
+
315
+ /**
316
+ * Send error to API.
317
+ *
318
+ * @param string $message
319
+ *
320
+ * @return Zend_Http_Response
321
+ *
322
+ * @throws Zend_Http_Client_Exception
323
+ */
324
+ protected function _sendError($message = 'No Message Provided')
325
+ {
326
+ $errClient = new Varien_Http_Client();
327
+ $errClient->setUri($this->getEndpoint().DS.'install_error')
328
+ ->setMethod('POST');
329
+
330
+ $errClient->setParameterPost(array(
331
+ 'site' => Mage::getBaseUrl(),
332
+ 'msg' => $message,
333
+ 'email' => Mage::getStoreConfig(self::XML_STORE_EMAIL_CONFIG),
334
+ 'multistore' => $this->_getHelper()->getMultiStoreDataJson(),
335
+ 'f' => $this->getModuleVersion(),
336
+ ));
337
+
338
+ return $errClient->request();
339
+ }
340
+
341
+ /**
342
+ * Support deprecated functionality - needed? Or can we change the install scripts?
343
+ */
344
+ public function getCollection()
345
+ {
346
+ return new Varien_Object(array(
347
+ 'authkey' => $this->getAuthorizationKey(),
348
+ 'licensekey' => $this->getUUID(),
349
+ ));
350
+ }
351
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Layer.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Magento
4
  *
5
  * NOTICE OF LICENSE
6
  *
@@ -19,17 +19,16 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Mage
22
- * @package Mage_CatalogSearch
23
  * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
-
27
  class Autocompleteplus_Autosuggest_Model_Layer extends Mage_Catalog_Model_Layer
28
  {
29
- const XML_PATH_DISPLAY_LAYER_COUNT = 'catalog/search/use_layered_navigation_count';
30
 
31
  /**
32
- * Get current layer product collection
33
  *
34
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
35
  */
@@ -37,8 +36,7 @@ class Autocompleteplus_Autosuggest_Model_Layer extends Mage_Catalog_Model_Layer
37
  {
38
  if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
39
  $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
40
- }
41
- else {
42
  $collection = Mage::getResourceModel('catalogsearch/fulltext_collection');
43
  $this->prepareProductCollection($collection);
44
  $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
@@ -48,9 +46,10 @@ class Autocompleteplus_Autosuggest_Model_Layer extends Mage_Catalog_Model_Layer
48
  }
49
 
50
  /**
51
- * Prepare product collection
52
  *
53
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
 
54
  * @return Mage_Catalog_Model_Layer
55
  */
56
  public function prepareProductCollection($collection)
@@ -66,11 +65,12 @@ class Autocompleteplus_Autosuggest_Model_Layer extends Mage_Catalog_Model_Layer
66
 
67
  Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
68
  Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
 
69
  return $this;
70
  }
71
 
72
  /**
73
- * Get layer state key
74
  *
75
  * @return string
76
  */
@@ -80,44 +80,51 @@ class Autocompleteplus_Autosuggest_Model_Layer extends Mage_Catalog_Model_Layer
80
  $this->_stateKey = 'Q_'.Mage::helper('catalogsearch')->getQuery()->getId()
81
  .'_'.parent::getStateKey();
82
  }
 
83
  return $this->_stateKey;
84
  }
85
 
86
  /**
87
- * Get default tags for current layer state
88
  *
89
- * @param array $additionalTags
90
- * @return array
 
91
  */
92
  public function getStateTags(array $additionalTags = array())
93
  {
94
  $additionalTags = parent::getStateTags($additionalTags);
95
  $additionalTags[] = Mage_CatalogSearch_Model_Query::CACHE_TAG;
 
96
  return $additionalTags;
97
  }
98
 
99
  /**
100
- * Add filters to attribute collection
 
 
101
  *
102
- * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection $collection
103
- * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection
104
  */
105
  protected function _prepareAttributeCollection($collection)
106
  {
107
  $collection->addIsFilterableInSearchFilter();
 
108
  return $collection;
109
  }
110
 
111
  /**
112
- * Prepare attribute for use in layered navigation
 
 
113
  *
114
- * @param Mage_Eav_Model_Entity_Attribute $attribute
115
- * @return Mage_Eav_Model_Entity_Attribute
116
  */
117
  protected function _prepareAttribute($attribute)
118
  {
119
  $attribute = parent::_prepareAttribute($attribute);
120
  $attribute->setIsFilterable(Mage_Catalog_Model_Layer_Filter_Attribute::OPTIONS_ONLY_WITH_RESULTS);
 
121
  return $attribute;
122
  }
123
  }
1
  <?php
2
  /**
3
+ * Magento.
4
  *
5
  * NOTICE OF LICENSE
6
  *
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Mage
22
+ *
23
  * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
 
26
  class Autocompleteplus_Autosuggest_Model_Layer extends Mage_Catalog_Model_Layer
27
  {
28
+ const XML_PATH_DISPLAY_LAYER_COUNT = 'catalog/search/use_layered_navigation_count';
29
 
30
  /**
31
+ * Get current layer product collection.
32
  *
33
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
34
  */
36
  {
37
  if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
38
  $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
39
+ } else {
 
40
  $collection = Mage::getResourceModel('catalogsearch/fulltext_collection');
41
  $this->prepareProductCollection($collection);
42
  $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
46
  }
47
 
48
  /**
49
+ * Prepare product collection.
50
  *
51
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
52
+ *
53
  * @return Mage_Catalog_Model_Layer
54
  */
55
  public function prepareProductCollection($collection)
65
 
66
  Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
67
  Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
68
+
69
  return $this;
70
  }
71
 
72
  /**
73
+ * Get layer state key.
74
  *
75
  * @return string
76
  */
80
  $this->_stateKey = 'Q_'.Mage::helper('catalogsearch')->getQuery()->getId()
81
  .'_'.parent::getStateKey();
82
  }
83
+
84
  return $this->_stateKey;
85
  }
86
 
87
  /**
88
+ * Get default tags for current layer state.
89
  *
90
+ * @param array $additionalTags
91
+ *
92
+ * @return array
93
  */
94
  public function getStateTags(array $additionalTags = array())
95
  {
96
  $additionalTags = parent::getStateTags($additionalTags);
97
  $additionalTags[] = Mage_CatalogSearch_Model_Query::CACHE_TAG;
98
+
99
  return $additionalTags;
100
  }
101
 
102
  /**
103
+ * Add filters to attribute collection.
104
+ *
105
+ * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection $collection
106
  *
107
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection
 
108
  */
109
  protected function _prepareAttributeCollection($collection)
110
  {
111
  $collection->addIsFilterableInSearchFilter();
112
+
113
  return $collection;
114
  }
115
 
116
  /**
117
+ * Prepare attribute for use in layered navigation.
118
+ *
119
+ * @param Mage_Eav_Model_Entity_Attribute $attribute
120
  *
121
+ * @return Mage_Eav_Model_Entity_Attribute
 
122
  */
123
  protected function _prepareAttribute($attribute)
124
  {
125
  $attribute = parent::_prepareAttribute($attribute);
126
  $attribute->setIsFilterable(Mage_Catalog_Model_Layer_Filter_Attribute::OPTIONS_ONLY_WITH_RESULTS);
127
+
128
  return $attribute;
129
  }
130
  }
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Config.php DELETED
@@ -1,8 +0,0 @@
1
- <?php
2
-
3
- class Autocompleteplus_Autosuggest_Model_Mysql4_Config extends Mage_Core_Model_Resource_Db_Abstract
4
- {
5
- protected function _construct() {
6
- $this->_init('autocompleteplus_autosuggest/config', 'id');
7
- }
8
- }
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Config/Collection.php DELETED
@@ -1,8 +0,0 @@
1
- <?php
2
-
3
- class Autocompleteplus_Autosuggest_Model_Mysql4_Config_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
- {
5
- public function _construct() {
6
- $this->_init('autocompleteplus_autosuggest/config');
7
- }
8
- }
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Fulltext.php DELETED
@@ -1,101 +0,0 @@
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_Model_Mysql4_Fulltext extends Mage_CatalogSearch_Model_Mysql4_Fulltext
18
- {
19
- /**
20
- * Prepare results for query
21
- *
22
- * @param Mage_CatalogSearch_Model_Fulltext $object
23
- * @param string $queryText
24
- * @param Mage_CatalogSearch_Model_Query $query
25
- * @return Mage_CatalogSearch_Model_Mysql4_Fulltext
26
- */
27
- public function prepareResult($object, $queryText, $query)
28
- {
29
- $optimDisabled= Mage::getStoreConfig('autocompleteplus/config/searchoptim');
30
-
31
- if (!$query->getIsProcessed()) {
32
- $searchType = $object->getSearchType($query->getStoreId());
33
-
34
- $stringHelper = Mage::helper('core/string');
35
- /* @var $stringHelper Mage_Core_Helper_String */
36
-
37
- $bind = array(
38
- ':query' => $queryText
39
- );
40
- $like = array();
41
-
42
- $fulltextCond = '';
43
- $likeCond = '';
44
- $separateCond = '';
45
-
46
- if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
47
- || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
48
- $words = $stringHelper->splitWords($queryText, true, $query->getMaxQueryWords());
49
- $likeI = 0;
50
- foreach ($words as $word) {
51
- $like[] = '`s`.`data_index` LIKE :likew' . $likeI;
52
- $bind[':likew' . $likeI] = '%' . $word . '%';
53
- $likeI ++;
54
- }
55
- if ($like) {
56
- $likeCond = '(' . join(' AND ', $like) . ')';
57
- }
58
- }
59
- if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
60
- || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
61
- $fulltextCond = 'MATCH (`s`.`data_index`) AGAINST (:query IN BOOLEAN MODE)';
62
- }
63
- if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE && $likeCond) {
64
- $separateCond = ' OR ';
65
- }
66
-
67
- if($optimDisabled==1){
68
- $sql = sprintf("INSERT INTO `{$this->getTable('catalogsearch/result')}` "
69
- . "(SELECT '%d', `s`.`product_id`, MATCH (`s`.`data_index`) AGAINST (:query IN BOOLEAN MODE) "
70
- . "FROM `{$this->getMainTable()}` AS `s` INNER JOIN `{$this->getTable('catalog/product')}` AS `e`"
71
- . "ON `e`.`entity_id`=`s`.`product_id` WHERE (%s%s%s) AND `s`.`store_id`='%d')"
72
- . " ON DUPLICATE KEY UPDATE `relevance`=VALUES(`relevance`)",
73
- $query->getId(),
74
- $fulltextCond,
75
- $separateCond,
76
- $likeCond,
77
- $query->getStoreId()
78
- );
79
- }else{
80
- $sql = sprintf("INSERT INTO `{$this->getTable('catalogsearch/result')}` "
81
- . "(SELECT STRAIGHT_JOIN '%d', `s`.`product_id`, MATCH (`s`.`data_index`) "
82
- . "AGAINST (:query IN BOOLEAN MODE) FROM `{$this->getMainTable()}` AS `s` "
83
- . "INNER JOIN `{$this->getTable('catalog/product')}` AS `e` "
84
- . "ON `e`.`entity_id`=`s`.`product_id` WHERE (%s%s%s) AND `s`.`store_id`='%d')"
85
- . " ON DUPLICATE KEY UPDATE `relevance`=VALUES(`relevance`)",
86
- $query->getId(),
87
- $fulltextCond,
88
- $separateCond,
89
- $likeCond,
90
- $query->getStoreId()
91
- );
92
- }
93
-
94
- $this->_getWriteAdapter()->query($sql, $bind);
95
-
96
- $query->setIsProcessed(1);
97
- }
98
-
99
- return $this;
100
- }
101
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Fulltext/Collection.php DELETED
@@ -1,140 +0,0 @@
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) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- */
26
-
27
-
28
- class Autocompleteplus_Autosuggest_Model_Mysql4_Fulltext_Collection
29
- extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
30
- {
31
- /**
32
- * Retrieve query model object
33
- *
34
- * @return Mage_CatalogSearch_Model_Query
35
- */
36
- protected function _getQuery()
37
- {
38
- return Mage::helper('catalogsearch')->getQuery();
39
- }
40
-
41
- /**
42
- * Add search query filter
43
- *
44
- * @param Mage_CatalogSearch_Model_Query $query
45
- * @return Mage_CatalogSearch_Model_Mysql4_Search_Collection
46
- */
47
- public function addSearchFilter($query)
48
- {
49
- $helper=Mage::helper('autocompleteplus_autosuggest');
50
-
51
- $enabledFulltext=$helper->getConfigDataByFullPath('autocompleteplus/config/enabled_fulltext');
52
-
53
- if($enabledFulltext){
54
- //add if enabled write here call to api to get ids
55
- $key=$helper->getUUID();
56
-
57
- $storeId = Mage::app()->getStore()->getStoreId();
58
-
59
- $url='http://0-1vk.acp-magento.appspot.com/ma_search?q='.$query.'&p=1&products_per_page=10&v=4.5.44&store_id='.$storeId.'&UUID='.$key;
60
-
61
- $jsonIds=$helper->sendCurl($url);
62
-
63
- $jsonObj=json_decode($jsonIds);
64
-
65
- $totalResults=$jsonObj->total_results;
66
-
67
- if($totalResults){
68
-
69
- $id_list=$jsonObj->id_list;
70
-
71
- $newIdsArr=array();
72
-
73
- //validate received ids
74
- foreach($id_list as $id){
75
- if($id!=null && is_numeric($id)){
76
- $newIdsArr[]=$id;
77
- }
78
- }
79
-
80
- if(count($newIdsArr)>0){
81
- $idStr=implode(',',$newIdsArr);
82
- }else{
83
- $idStr='0';
84
- }
85
-
86
-
87
- }else{
88
- $idStr='0';
89
- }
90
-
91
- $this->getSelect()->where('e.entity_id IN ('.$idStr.')');
92
-
93
- }else{
94
- //adding if fulltext search disabled then write regular flow
95
- Mage::getSingleton('catalogsearch/fulltext')->prepareResult();
96
-
97
- $this->getSelect()->joinInner(
98
- array('search_result' => $this->getTable('catalogsearch/result')),
99
- $this->getConnection()->quoteInto(
100
- 'search_result.product_id=e.entity_id AND search_result.query_id=?',
101
- $this->_getQuery()->getId()
102
- ),
103
- array('relevance' => 'relevance')
104
- );
105
-
106
- }
107
-
108
- return $this;
109
- }
110
-
111
- /**
112
- * Set Order field
113
- *
114
- * @param string $attribute
115
- * @param string $dir
116
- * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection
117
- */
118
- public function setOrder($attribute, $dir='desc')
119
- {
120
-
121
- $helper=Mage::helper('autocompleteplus_autosuggest');
122
-
123
- $enabledFulltext=$helper->getConfigDataByFullPath('autocompleteplus/config/enabled_fulltext');
124
-
125
- if($enabledFulltext){
126
-
127
- }else{
128
-
129
- if ($attribute == 'relevance') {
130
- $this->getSelect()->order("relevance {$dir}");
131
- }
132
- else {
133
- parent::setOrder($attribute, $dir);
134
- }
135
-
136
- }
137
-
138
- return $this;
139
- }
140
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Pusher/Collection.php DELETED
@@ -1,10 +0,0 @@
1
- <?php
2
-
3
- class Autocompleteplus_Autosuggest_Model_Mysql4_Pusher_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
- {
5
- public function _construct() {
6
- $this->_init('autocompleteplus_autosuggest/pusher');
7
- }
8
-
9
-
10
- }
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/Model/Notifications.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,15 +9,14 @@
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
-
18
  class Autocompleteplus_Autosuggest_Model_Notifications extends Mage_Core_Model_Abstract
19
  {
20
  protected function _construct()
21
  {
22
  $this->_init('autocompleteplus_autosuggest/notifications');
23
  }
24
- }
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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_Model_Notifications extends Mage_Core_Model_Abstract
17
  {
18
  protected function _construct()
19
  {
20
  $this->_init('autocompleteplus_autosuggest/notifications');
21
  }
22
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Observer.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
  *
5
  * NOTICE OF LICENSE
6
  *
@@ -9,446 +10,314 @@
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
-
17
  class Autocompleteplus_Autosuggest_Model_Observer extends Mage_Core_Model_Abstract
18
  {
19
-
20
  const AUTOCOMPLETEPLUS_WEBHOOK_URI = 'https://acp-magento.appspot.com/ma_webhook';
21
- const WEBHOOK_CURL_TIMEOUT_LENGTH = 2;
22
-
23
- private $imageField;
24
- private $standardImageFields=array();
25
- private $currency;
26
-
27
- public function adminhtml_controller_catalogrule_prepare_save($observer){
28
-
29
- //Mage::log(print_r($observer,true),null,'autocompleteplus.log');
30
- }
31
-
32
- public function catalogrule_after_apply($observer){
33
-
34
- //Mage::log('apply: '.print_r($observer,true),null,'autocompleteplus.log');
35
- }
36
-
37
-
38
- public function catalog_controller_product_init($observer){
39
-
40
-
41
- try{
42
- $helper=Mage::helper('autocompleteplus_autosuggest');
43
 
44
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
 
 
45
 
46
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
47
-
48
- $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
49
-
50
- if(!$tblExist){return;}
51
-
52
- $keyList=$write->describeTable($_tableprefix.'autocompleteplus_config');
53
-
54
- if(!isset($keyList['site_url'])){return;}
55
-
56
- $sqlFetch ='SELECT * FROM '. $_tableprefix.'autocompleteplus_config WHERE id = 1';
57
-
58
- $config=$write->fetchAll($sqlFetch);
59
-
60
- if(isset($config[0]['site_url'])){
61
-
62
- $old_url=$config[0]['site_url'];
63
-
64
- }else{
65
- $old_url='no_old_url';
66
- }
67
-
68
- if(isset($config[0]['licensekey'])){
69
-
70
- $licensekey=$config[0]['licensekey'];
71
-
72
- }else{
73
- $licensekey='no_uuid';
74
- }
75
-
76
-
77
- //getting site url
78
- $url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
79
-
80
- if($old_url!=$url){
81
-
82
- $command="http://magento.autocompleteplus.com/ext_update_host";
83
- $data=array();
84
- $data['old_url']=$old_url;
85
- $data['new_url']=$url;
86
- $data['uuid']=$licensekey;
87
-
88
- $res=$helper->sendPostCurl($command,$data);
89
-
90
- $result=json_decode($res);
91
-
92
- if(strtolower($result->status)=='ok'){
93
- $sql='UPDATE '. $_tableprefix.'autocompleteplus_config SET site_url=? WHERE id = 1';
94
-
95
- $write->query($sql, array($url));
96
- }
97
-
98
- Mage::log(print_r($res,true),null,'autocompleteplus.log');
99
- }
100
-
101
- }catch(Exception $e){
102
- Mage::log($e->getMessage(),null,'autocompleteplus.log');
103
  }
104
 
105
-
 
106
  }
107
 
108
-
109
- public function catalog_product_save_after_depr($observer){
110
-
111
- $helper=Mage::helper('autocompleteplus_autosuggest');
112
-
113
- $product=$observer->getProduct();
114
- $this->imageField=Mage::getStoreConfig('autocompleteplus/config/imagefield');
115
- if(!$this->imageField){
116
- $this->imageField='thumbnail';
117
- }
118
-
119
- $this->standardImageFields=array('image','small_image','thumbnail');
120
- $this->currency=Mage::app()->getStore()->getCurrentCurrencyCode();
121
-
122
- $domain =Mage::getStoreConfig('web/unsecure/base_url');
123
- $key =$helper->getUUID();
124
-
125
- $mage=Mage::getVersion();
126
- $ext=Mage::helper('autocompleteplus_autosuggest')->getVersion();
127
-
128
- $xml='<?xml version="1.0"?>';
129
-
130
- $xml.='<catalog version="'.$ext.'" magento="'.$mage.'">';
131
-
132
- $xml.=$this->__getProductData($product);
133
-
134
- $xml.='</catalog>';
135
-
136
- $data=array(
137
- 'site'=>$domain,
138
- 'key'=>$key,
139
- 'catalog'=>$xml
140
- );
141
-
142
- $res=$this->__sendUpdate($data);
143
-
144
- Mage::log(print_r($res,true),null,'autocomplete.log');
145
  }
146
 
147
- public function catalog_product_save_after($observer){
148
- date_default_timezone_set('Asia/Jerusalem');
149
-
150
- $product=$observer->getProduct();
151
-
152
- $origData=$observer->getProduct()->getOrigData();
153
-
154
- $storeId=$product->getStoreId();
155
-
156
- $productId=$product->getId();
157
-
158
- $sku=$product->getSku();
159
-
160
- // if ($sku == null || $productId == null){
161
- // Mage::log('catalog_product_save_after - either sku null or identifier is null', null, 'autocompleteplus.log');
162
- // return;
163
- // }
164
-
165
- if(is_array($origData)){
166
- if(array_key_exists('sku',$origData)){
167
-
168
- $oldSku=$origData['sku'];
169
-
170
- if($sku!=$oldSku){
171
-
172
- $this->__writeproductDeletion($oldSku,$productId,$storeId, $product);
173
- }
174
-
175
- }
176
- }
177
-
178
- $dt = strtotime('now');
179
- //$mysqldate = date( 'Y-m-d h:m:s', $dt );
180
-
181
- $simple_product_parents = array();
182
- if ($product->getTypeID() == 'simple'){
183
- $simple_product_parents = Mage::getModel('catalog/product_type_configurable')
184
- ->getParentIdsByChild($product->getId());
185
-
186
- }
187
-
188
- try{
189
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
190
- $read = Mage::getSingleton('core/resource')->getConnection('core_read');
191
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
192
- $tblExist = $write->showTableStatus($_tableprefix.'autocompleteplus_batches');
193
-
194
- if(!$tblExist){return;}
195
- try{
196
- if ($storeId == 0 && method_exists($product, 'getStoreIds')){
197
- $product_stores = $product->getStoreIds();
198
- } else {
199
- $product_stores = array($storeId);
200
- }
201
- } catch (Exception $e){
202
- $product_stores = array($storeId);
203
- }
204
-
205
- foreach ($product_stores as $product_store){
206
- $sqlFetch = 'SELECT * FROM '. $_tableprefix.'autocompleteplus_batches WHERE product_id = ? AND store_id=?';
207
- $updates = $write->fetchAll($sqlFetch, array($productId, $product_store));
208
-
209
- if($updates&&count($updates) != 0){
210
- $sql = 'UPDATE '. $_tableprefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id = ? AND store_id=?';
211
- $write->query($sql, array($dt, "update", $productId, $product_store));
212
- }else{
213
- $sql='INSERT INTO '. $_tableprefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
214
- $write->query($sql, array($productId, $product_store, $dt, "update", $sku));
215
- }
216
- try{
217
- $helper = Mage::helper('autocompleteplus_autosuggest');
218
- if ($helper->isChecksumTableExists()){
219
- $checksum = $helper->calculateChecksum($product);
220
- $helper->updateSavedProductChecksum($_tableprefix, $read, $write, $productId, $sku, $product_store, $checksum);
221
- }
222
- } catch (Exception $e){
223
- Mage::log('checksum failed - ' . $e->getMessage(), null, 'autocompleteplus.log');
224
- }
225
-
226
- // trigger update for simple product's configurable parent
227
- if (!empty($simple_product_parents)){ // simple product has configural parent
228
- foreach ($simple_product_parents as $configurable_product){
229
- $sqlFetch = 'SELECT * FROM '. $_tableprefix.'autocompleteplus_batches WHERE product_id = ? AND store_id=?';
230
- $updates = $read->fetchAll($sqlFetch, array($configurable_product, $product_store));
231
- if (!$updates || (count($updates) == 0) || $updates[0]['action'] != 'remove'){
232
- if($updates && count($updates) != 0){
233
- $sql = 'UPDATE '. $_tableprefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id = ? AND store_id=?';
234
- $write->query($sql, array($dt, "update", $configurable_product, $product_store));
235
- } else {
236
- $sql = 'INSERT INTO '. $_tableprefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
237
- $write->query($sql, array($configurable_product, $product_store, $dt, "update", 'ISP_NO_SKU'));
238
- }
239
- }
240
- }
241
- }
242
  }
243
-
244
- }catch(Exception $e){
245
- Mage::log($e->getMessage(),null,'autocompleteplus.log');
246
  }
247
- }
248
-
249
- private function __getProductData($product){
250
-
251
- $sku =$product->getSku();
252
-
253
- $status=$product->isInStock();
254
  $stockItem = $product->getStockItem();
255
- $storeId=$product->getStoreId();
256
-
257
-
258
- if($stockItem&&$stockItem->getIsInStock()&&$status)
259
- {
260
- $sell=1;
261
- }else{
262
- $sell=0;
263
- }
264
-
265
- $price =$this->getPrice($product);
266
-
267
- $productUrl =Mage::helper('catalog/product')->getProductUrl($product->getId());
268
- $prodDesc =$product->getDescription();
269
- $prodShortDesc =$product->getShortDescription();
270
- $prodName =$product->getName();
271
-
272
- try{
273
-
274
- if(in_array($this->imageField,$this->standardImageFields)){
275
- $prodImage =Mage::helper('catalog/image')->init($product, $this->imageField);
276
- }else{
277
- $function='get'.$this->imageField;
278
- $prodImage =$product->$function();
279
- }
280
-
281
- }catch(Exception $e){
282
- $prodImage='';
283
  }
284
 
 
 
285
 
286
- $visibility =$product->getVisibility();
287
-
288
 
289
- $row='<product store="'.$storeId.'" currency="'.$this->currency.'" visibility="'.$visibility.'" price="'.$price.'" url="'.$productUrl.'" thumbs="'.$prodImage.'" selleable="'.$sell.'" action="update" >';
290
- $row.='<description><![CDATA['.$prodDesc.']]></description>';
291
- $row.='<short><![CDATA['.$prodShortDesc.']]></short>';
292
- $row.='<name><![CDATA['.$prodName.']]></name>';
293
- $row.='<sku><![CDATA['.$sku.']]></sku>';
294
- $row.='</product>';
295
-
296
- return $row;
297
- }
298
 
 
 
 
 
 
 
 
 
299
 
 
 
 
 
300
 
301
- private function __makeSafeString($str){
302
- $str=strip_tags($str);
303
- $str=str_replace('"','',$str);
304
- $str=str_replace("'",'',$str);
305
- $str=str_replace('/','',$str);
306
- $str=str_replace('<','',$str);
307
- $str=str_replace('>','',$str);
308
- $str=str_replace('\\','',$str);
309
- return $str;
310
  }
311
 
312
- private function __sendUpdate($data){
313
-
314
- $ch=curl_init();
315
- $command='http://magento.autocompleteplus.com/update';
316
- curl_setopt($ch, CURLOPT_URL, $command);
317
- curl_setopt($ch, CURLOPT_HEADER, 0);
318
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
319
- curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
320
- //curl_setopt($ch,CURLOPT_POST,0);
321
- if(!empty($data)){
322
- curl_setopt_array($ch, array(
323
- CURLOPT_POSTFIELDS => $data,
324
- ));
325
  }
326
-
327
- return curl_exec($ch);
 
 
 
 
 
 
 
 
 
 
 
328
  }
329
 
330
-
331
- private function getPrice($product){
332
  $price = 0;
333
- $helper=Mage::helper('autocompleteplus_autosuggest');
334
- if ($product->getTypeId()=='grouped'){
335
-
336
  $helper->prepareGroupedProductPrice($product);
337
  $_minimalPriceValue = $product->getPrice();
338
-
339
- if($_minimalPriceValue){
340
- $price=$_minimalPriceValue;
341
  }
342
-
343
- }elseif($product->getTypeId()=='bundle'){
344
-
345
- if(!$product->getFinalPrice()){
346
- $price=$helper->getBundlePrice($product);
347
- }else{
348
- $price=$product->getFinalPrice();
349
  }
350
-
351
- }else{
352
- $price =$product->getFinalPrice();
353
  }
354
-
355
- if(!$price){
356
- $price=0;
357
  }
 
358
  return $price;
359
  }
360
 
361
- public function catalog_product_delete_before($observer){
362
-
363
- $product=$observer->getProduct();
364
-
365
- $storeId=$product->getStoreId();
366
-
367
- $productId=$product->getId();
368
-
369
- $sku=$product->getSku();
 
 
 
370
 
371
- $this->__writeproductDeletion($sku,$productId,$storeId, $product);
 
 
372
 
 
373
  }
374
 
375
- private function __writeproductDeletion($sku, $productId, $storeId, $product = null){
376
- $dt = strtotime('now');
377
- //$mysqldate = date( 'Y-m-d h:m:s', $dt );
378
-
379
- try{
380
- // if ($productId == null){
381
- // Mage::log('__writeproductDeletion - identifier is null', null, 'autocompleteplus.log');
382
- // return;
383
- // }
 
 
 
 
 
 
 
 
384
 
385
- $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
386
 
387
- $read = Mage::getSingleton('core/resource')->getConnection('core_read');
 
 
 
 
388
 
389
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
390
 
391
- $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_batches');
 
 
392
 
393
- if(!$tblExist){return;}
 
394
 
395
- try{
396
- $helper = Mage::helper('autocompleteplus_autosuggest');
397
- if ($helper->isChecksumTableExists()){
398
- try{
399
- if (!$product){
400
- $product = Mage::getModel('catalog/product')->load($productId);
401
- }
402
- if ($storeId == 0 && method_exists($product, 'getStoreIds')){
403
- $product_stores = $product->getStoreIds();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  } else {
405
- $product_stores = array($storeId);
 
 
 
 
 
 
 
406
  }
407
- } catch (Exception $e){
408
- Mage::log('exception raised: ' . $e->getMessage(),null,'autocompleteplus.log');
409
- $product_stores = array($storeId);
410
  }
411
- if ($sku == null){
412
- $sku = 'dummy_sku';
413
- }
414
-
415
- foreach ($product_stores as $product_store){
416
- $sqlFetch = 'SELECT * FROM '. $_tableprefix.'autocompleteplus_batches WHERE product_id = ? AND store_id=?';
417
- $updates = $read->fetchAll($sqlFetch, array($productId, $product_store));
418
-
419
- if($updates && count($updates) != 0){
420
- $sql = 'UPDATE '. $_tableprefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id = ? AND store_id = ?';
421
- $write->query($sql, array($dt, "remove", $productId, $product_store));
422
- } else {
423
- $sql='INSERT INTO '. $_tableprefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
424
- $write->query($sql, array($productId, $product_store, $dt, "remove", $sku));
425
- }
426
 
427
- $helper->updateDeletedProductChecksum($_tableprefix, $read, $write, $productId, $sku, $product_store);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  }
 
429
  }
430
- } catch (Exception $e){
431
- Mage::log('__writeproductDeletion failed on remove - ' . $e->getMessage(), null, 'autocompleteplus.log');
432
  }
433
-
434
- }catch(Exception $e){
435
- Mage::log('__writeproductDeletion: ' . $e->getMessage(),null,'autocompleteplus.log');
436
  }
437
  }
438
 
 
 
 
 
 
 
 
 
 
439
  public function adminSessionUserLoginSuccess()
440
  {
441
  $notifications = array();
442
  /** @var Autocompleteplus_Autosuggest_Helper_Data $helper */
443
- $helper = Mage::helper('autocompleteplus_autosuggest');
444
- $command = "http://magento.autocompleteplus.com/ext_info?u=". $helper->getUUID();
445
  $res = $helper->sendCurl($command);
446
  $result = json_decode($res);
447
  if (isset($result->alerts)) {
448
  foreach ($result->alerts as $alert) {
449
  $notification = array(
450
- 'type' => (string) $alert->type,
451
- 'message' => (string) $alert->message,
452
  'timestamp' => (string) $alert->timestamp,
453
  );
454
  if (isset($alert->subject)) {
@@ -478,21 +347,17 @@ class Autocompleteplus_Autosuggest_Model_Observer extends Mage_Core_Model_Abstra
478
  */
479
  protected function _sendStatusMail($notification)
480
  {
481
-
482
  /** @var Autocompleteplus_Autosuggest_Helper_Data $helper */
483
- $helper = Mage::helper('autocompleteplus_autosuggest');
484
  // Getting site owner email
485
  $storeMail = $helper->getConfigDataByFullPath('autocompleteplus/config/store_email');
486
  if ($storeMail) {
487
- $emailTemplate = Mage::getModel('core/email_template');
488
-
489
  $emailTemplate->loadDefault('autosuggest_status_notification');
490
  $emailTemplate->setTemplateSubject($notification->getSubject());
491
-
492
  // Get General email address (Admin->Configuration->General->Store Email Addresses)
493
  $emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_general/email'));
494
  $emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_general/name'));
495
-
496
  $emailTemplateVariables['message'] = $notification->getMessage();
497
  $emailTemplate->send($storeMail, null, $emailTemplateVariables);
498
  $notification->setIsActive(0)
@@ -501,105 +366,104 @@ class Autocompleteplus_Autosuggest_Model_Observer extends Mage_Core_Model_Abstra
501
  }
502
 
503
  /**
504
- * The generic webhook service caller
505
- * @param Varien_Event_Observer $observer
506
- * @return void
507
  */
508
- public function webhook_service_call($observer)
509
  {
510
  $curl = new Varien_Http_Adapter_Curl();
511
  $curl->setConfig(array(
512
- 'timeout' => static::WEBHOOK_CURL_TIMEOUT_LENGTH
513
  ));
514
-
515
  $curl->write(Zend_Http_Client::GET, $this->_getWebhookObjectUri());
516
  $curl->read();
517
  $curl->close();
518
  }
519
 
520
  /**
521
- * Returns the quote id if it exists, otherwise it will
522
- * return the last order id. This only is set in the session
523
- * when an order has been recently completed. Therefore
524
- * this call may also return null.
525
- * @return string|null
526
  */
527
- public function getQuoteId()
528
  {
529
- if($quoteId = Mage::getSingleton('checkout/session')->getQuoteId()){
530
- return $quoteId;
531
- }
532
-
533
- return $this->getOrder()->getQuoteId();
534
- }
 
 
 
 
 
535
 
536
- /**
537
- * Get the order associated with the previous quote id
538
- * used as a fallback when the quote is no longer available
539
- * @return Mage_Sales_Model_Order
540
- */
541
- public function getOrder()
542
- {
543
- $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
544
- return Mage::getModel('sales/order')->load($orderId);
545
  }
546
 
547
  /**
548
- * Return a label for webhooks based on the current
549
  * controller route. This cannot be handled by layout
550
  * XML because the layout engine may not be init in all
551
- * future uses of the webhook
 
552
  * @return string|void
553
  */
554
  public function getWebhookEventLabel()
555
  {
556
- $request = Mage::app()->getRequest();
557
- $route = $request->getRouteName();
558
  $controller = $request->getControllerName();
559
- $action = $request->getActionName();
560
-
561
- if($route != 'checkout'){
562
  return;
563
  }
564
-
565
- if($controller == 'cart' && $action == 'index'){
566
  return 'cart';
567
  }
568
-
569
- if($controller == 'onepage' && $action == 'index'){
570
  return 'checkout';
571
  }
572
-
573
- if($controller == 'onepage' && $action == 'success'){
574
  return 'success';
575
  }
576
-
577
  }
578
 
579
  /**
580
- * Create the webhook URI
581
- * @return string
 
 
 
 
582
  */
583
- protected function _getWebhookObjectUri()
584
  {
585
- $helper = Mage::helper('autocompleteplus_autosuggest');
 
 
586
 
587
- $parameters = array(
588
- 'event' =>$this->getWebhookEventLabel(),
589
- 'UUID' =>$helper->getUUID(),
590
- 'key' =>$helper->getKey(),
591
- 'store_id' =>Mage::app()->getStore()->getStoreId(),
592
- 'st' =>$helper->getSessionId(),
593
- 'cart_token' =>$this->getQuoteId(),
594
- 'serp' =>'',
595
- 'cart_product' => $this->getCartContentsAsJson()
596
- );
 
 
597
 
598
- return static::AUTOCOMPLETEPLUS_WEBHOOK_URI . '?' . http_build_query($parameters,'','&');
599
  }
600
 
601
  /**
602
- * JSON encode the cart contents
 
603
  * @return string
604
  */
605
  public function getCartContentsAsJson()
@@ -608,49 +472,46 @@ class Autocompleteplus_Autosuggest_Model_Observer extends Mage_Core_Model_Abstra
608
  }
609
 
610
  /**
611
- * Format visible cart contents into a multidimensional keyed array
 
612
  * @return array
613
  */
614
  protected function _getVisibleItems()
615
  {
616
- if($cartItems = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems()){
617
  return $this->_buildCartArray($cartItems);
618
  }
619
-
620
  return $this->_buildCartArray($this->getOrder()->getAllVisibleItems());
621
  }
622
 
623
  /**
624
- * Return a formatted array of quote or order items
625
- * @param array $cartItems
626
- * @todo fork this for quote items vs sales order items
 
627
  * @return array
628
  */
629
  protected function _buildCartArray($cartItems)
630
  {
631
  $items = array();
632
-
633
- foreach($cartItems as $item){
634
- /**
635
- * @todo fix this check by providing separate models for MSMQI and MSMOI
636
- */
637
- if($item instanceof Mage_Sales_Model_Order_Item){
638
- $quantity = (int)$item->getQtyOrdered();
639
  } else {
640
  $quantity = $item->getQty();
641
  }
642
- if (is_object($item->getProduct())){ // Fatal error fix: Call to a member function getId() on a non-object
643
  $items[] = array(
644
- 'product_id' =>$item->getProduct()->getId(),
645
- 'price' =>$item->getProduct()->getFinalPrice(),
646
- 'quantity' =>$quantity,
647
- 'currency' =>Mage::app()->getStore()->getCurrentCurrencyCode(),
648
- 'attribution' =>$item->getAddedFromSearch()
649
  );
650
  }
651
  }
652
 
653
  return $items;
654
  }
655
-
656
- }
1
  <?php
2
+
3
  /**
4
+ * InstantSearchPlus (Autosuggest).
5
  *
6
  * NOTICE OF LICENSE
7
  *
10
  * http://opensource.org/licenses/osl-3.0.php
11
  *
12
  * @category Mage
13
+ *
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_Model_Observer extends Mage_Core_Model_Abstract
18
  {
 
19
  const AUTOCOMPLETEPLUS_WEBHOOK_URI = 'https://acp-magento.appspot.com/ma_webhook';
20
+ const API_UPDATE_URI = 'http://magento.autocompleteplus.com/update';
21
+ const WEBHOOK_CURL_TIMEOUT_LENGTH = 2;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ protected $imageField;
24
+ protected $standardImageFields = array();
25
+ protected $currency;
26
 
27
+ public function _construct()
28
+ {
29
+ $this->imageField = Mage::getStoreConfig('autocompleteplus/config/imagefield');
30
+ if (!$this->imageField) {
31
+ $this->imageField = 'thumbnail';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
34
+ $this->standardImageFields = array('image', 'small_image', 'thumbnail');
35
+ $this->currency = Mage::app()->getStore()->getCurrentCurrencyCode();
36
  }
37
 
38
+ public function getConfig()
39
+ {
40
+ return Mage::getModel('autocompleteplus_autosuggest/config');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  }
42
 
43
+ protected function _generateProductXml($product)
44
+ {
45
+ $catalog = new SimpleXMLElement('<catalog></catalog>');
46
+ try {
47
+ if (in_array($this->imageField, $this->standardImageFields)) {
48
+ $productImage = Mage::helper('catalog/image')->init($product, $this->imageField);
49
+ } else {
50
+ $function = 'get'.$this->imageField;
51
+ $productImage = $product->$function();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
53
+ } catch (Exception $e) {
54
+ $productImage = '';
 
55
  }
56
+ $productUrl = Mage::helper('catalog/product')->getProductUrl($product->getId());
57
+ $status = $product->isInStock();
 
 
 
 
 
58
  $stockItem = $product->getStockItem();
59
+ if ($stockItem && $stockItem->getIsInStock() && $status) {
60
+ $saleable = 1;
61
+ } else {
62
+ $saleable = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
 
65
+ // Add Magento Module Version attribute
66
+ $catalog->addAttribute('version', $this->getConfig()->getModuleVersion());
67
 
68
+ // Add Magento Version attribute
69
+ $catalog->addAttribute('magento', Mage::getVersion());
70
 
71
+ // Create product child
72
+ $productChild = $catalog->addChild('product');
 
 
 
 
 
 
 
73
 
74
+ $productChild->addAttribute('store', $product->getStoreId());
75
+ $productChild->addAttribute('currency', $this->currency);
76
+ $productChild->addAttribute('visibility', $product->getVisibility());
77
+ $productChild->addAttribute('price', $this->_getPrice($product));
78
+ $productChild->addAttribute('url', $productUrl);
79
+ $productChild->addAttribute('thumbs', $productImage);
80
+ $productChild->addAttribute('selleable', $saleable);
81
+ $productChild->addAttribute('action', 'update');
82
 
83
+ $productChild->addChild('description', '<![CDATA['.$product->getDescription().']]>');
84
+ $productChild->addChild('short', '<![CDATA['.$product->getShortDescription().']]>');
85
+ $productChild->addChild('name', '<![CDATA['.$product->getName().']]>');
86
+ $productChild->addChild('sku', '<![CDATA['.$product->getSku().']]>');
87
 
88
+ return $catalog->asXML();
 
 
 
 
 
 
 
 
89
  }
90
 
91
+ public function catalog_product_save_after_depr($observer)
92
+ {
93
+ $helper = Mage::helper('autocompleteplus_autosuggest');
94
+ $product = $observer->getProduct();
95
+ $this->imageField = Mage::getStoreConfig('autocompleteplus/config/imagefield');
96
+ if (!$this->imageField) {
97
+ $this->imageField = 'thumbnail';
 
 
 
 
 
 
98
  }
99
+ $this->standardImageFields = array('image', 'small_image', 'thumbnail');
100
+ $this->currency = Mage::app()->getStore()->getCurrentCurrencyCode();
101
+ $domain = Mage::getStoreConfig('web/unsecure/base_url');
102
+ $key = $this->getConfig()->getUUID();
103
+
104
+ $xml = $this->_generateProductXml($product);
105
+ $data = array(
106
+ 'site' => $domain,
107
+ 'key' => $key,
108
+ 'catalog' => $xml,
109
+ );
110
+ $res = $this->_sendUpdate($data);
111
+ Mage::log($res, null, 'autocomplete.log');
112
  }
113
 
114
+ protected function _getPrice($product)
115
+ {
116
  $price = 0;
117
+ $helper = Mage::helper('autocompleteplus_autosuggest');
118
+ if ($product->getTypeId() == 'grouped') {
 
119
  $helper->prepareGroupedProductPrice($product);
120
  $_minimalPriceValue = $product->getPrice();
121
+ if ($_minimalPriceValue) {
122
+ $price = $_minimalPriceValue;
 
123
  }
124
+ } elseif ($product->getTypeId() == 'bundle') {
125
+ if (!$product->getFinalPrice()) {
126
+ $price = $helper->getBundlePrice($product);
127
+ } else {
128
+ $price = $product->getFinalPrice();
 
 
129
  }
130
+ } else {
131
+ $price = $product->getFinalPrice();
 
132
  }
133
+ if (!$price) {
134
+ $price = 0;
 
135
  }
136
+
137
  return $price;
138
  }
139
 
140
+ protected function _sendUpdate($data)
141
+ {
142
+ $client = new Varien_Http_Client();
143
+ $config = array(
144
+ 'adapter' => 'Zend_Http_Client_Adapter_Curl',
145
+ 'curloptions' => array(
146
+ CURLOPT_RETURNTRANSFER => 1,
147
+ ),
148
+ );
149
+ $client->setUri(self::API_UPDATE_URI)
150
+ ->setMethod('POST')
151
+ ->setConfig($config);
152
 
153
+ if (!empty($data)) {
154
+ $client->setParameterPost($data);
155
+ }
156
 
157
+ return $client->request();
158
  }
159
 
160
+ public function catalog_product_save_after($observer)
161
+ {
162
+ date_default_timezone_set('Asia/Jerusalem');
163
+ $product = $observer->getProduct();
164
+ $origData = $observer->getProduct()->getOrigData();
165
+ $storeId = $product->getStoreId();
166
+ $productId = $product->getId();
167
+ $sku = $product->getSku();
168
+ if (is_array($origData) &&
169
+ array_key_exists('sku', $origData)) {
170
+ $oldSku = $origData['sku'];
171
+ if ($sku != $oldSku) {
172
+ $this->_writeproductDeletion($oldSku, $productId, $storeId, $product);
173
+ }
174
+ }
175
+ $dt = strtotime('now');
176
+ $simple_product_parents = ($product->getTypeID() == 'simple') ? Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId()) : array();
177
 
178
+ $product_stores = ($storeId == 0 && method_exists($product, 'getStoreIds')) ? $product->getStoreIds() : array($storeId);
179
 
180
+ try {
181
+ foreach ($product_stores as $product_store) {
182
+ $updates = Mage::getModel('autocompleteplus_autosuggest/batches')->getCollection()
183
+ ->addFieldToFilter('product_id', $productId)
184
+ ->addFieldToFilter('store_id', $product_store);
185
 
186
+ $updates->getSelect()->limit(1);
187
 
188
+ if ($updates && $updates->getSize() > 0) {
189
+ // @codingStandardsIgnoreLine
190
+ $row = $updates->getFirstItem();
191
 
192
+ $row->setUpdateDate($dt)
193
+ ->setAction('update');
194
 
195
+ // @codingStandardsIgnoreLine
196
+ $row->save();
197
+ } else {
198
+ $batch = Mage::getModel('autocompleteplus_autosuggest/batches');
199
+ $batch->setProductId($productId)
200
+ ->setStoreId($product_store)
201
+ ->setUpdateDate($dt)
202
+ ->setAction('update')
203
+ ->setSku($sku);
204
+
205
+ // @codingStandardsIgnoreLine
206
+ $batch->save();
207
+ }
208
+ try {
209
+ $helper = Mage::helper('autocompleteplus_autosuggest');
210
+ $checksum = $helper->calculateChecksum($product);
211
+ $helper->updateSavedProductChecksum($productId, $sku, $product_store, $checksum);
212
+ } catch (Exception $e) {
213
+ Mage::logException($e);
214
+ }
215
+ // trigger update for simple product's configurable parent
216
+ if (!empty($simple_product_parents)) { // simple product has configural parent
217
+ foreach ($simple_product_parents as $configurable_product) {
218
+ $batches = Mage::getModel('autocompleteplus_autosuggest/batches')->getCollection()
219
+ ->addFieldToFilter('product_id', $configurable_product)
220
+ ->addFieldToFilter('store_id', $product_store);
221
+
222
+ $batches->getSelect()->limit(1);
223
+
224
+ // @codingStandardsIgnoreLine
225
+ $batch = $batches->getFirstItem();
226
+ if ($batch->getSize() > 0) {
227
+ $batch->setUpdateDate($dt)
228
+ ->setAction('update')
229
+ // @codingStandardsIgnoreLine
230
+ ->save();
231
  } else {
232
+ $newBatch = Mage::getModel('autocompleteplus_autosuggest/batches');
233
+ $newBatch->setProductId($configurable_product)
234
+ ->setStoreId($product_store)
235
+ ->setUpdateDate($dt)
236
+ ->setAction('update')
237
+ ->setSku('ISP_NO_SKU')
238
+ // @codingStandardsIgnoreLine
239
+ ->save();
240
  }
 
 
 
241
  }
242
+ }
243
+ }
244
+ } catch (Exception $e) {
245
+ Mage::logException($e);
246
+ }
247
+ }
 
 
 
 
 
 
 
 
 
248
 
249
+ protected function _writeproductDeletion($sku, $productId, $storeId, $product = null)
250
+ {
251
+ $dt = strtotime('now');
252
+ try {
253
+ try {
254
+ $helper = Mage::helper('autocompleteplus_autosuggest');
255
+ try {
256
+ if (!$product) {
257
+ $product = Mage::getModel('catalog/product')->load($productId);
258
+ }
259
+ $product_stores = ($storeId == 0 && method_exists($product, 'getStoreIds')) ? $product->getStoreIds() : array($storeId);
260
+ } catch (Exception $e) {
261
+ Mage::logException($e);
262
+ $product_stores = array($storeId);
263
+ }
264
+ if ($sku == null) {
265
+ $sku = 'dummy_sku';
266
+ }
267
+ foreach ($product_stores as $product_store) {
268
+ $batches = Mage::getModel('autocompleteplus_autosuggest/batches')->getCollection()
269
+ ->addFieldToFilter('product_id', $configurable_product)
270
+ ->addFieldToFilter('store_id', $product_store);
271
+
272
+ // @codingStandardsIgnoreLine
273
+ $batch = $batches->getFirstItem();
274
+ if ($batch->getSize() > 0) {
275
+ $batch->setUpdateDate($dt)
276
+ ->setAction('update')
277
+ // @codingStandardsIgnoreLine
278
+ ->save();
279
+ } else {
280
+ $newBatch = Mage::getModel('autocompleteplus_autosuggest/batches');
281
+ $newBatch->setProductId($configurable_product)
282
+ ->setStoreId($product_store)
283
+ ->setUpdateDate($dt)
284
+ ->setAction('update')
285
+ ->setSku($sku)
286
+ // @codingStandardsIgnoreLine
287
+ ->save();
288
  }
289
+ $helper->updateDeletedProductChecksum($productId, $sku, $product_store);
290
  }
291
+ } catch (Exception $e) {
292
+ Mage::logException($e);
293
  }
294
+ } catch (Exception $e) {
295
+ Mage::logException($e);
 
296
  }
297
  }
298
 
299
+ public function catalog_product_delete_before($observer)
300
+ {
301
+ $product = $observer->getProduct();
302
+ $storeId = $product->getStoreId();
303
+ $productId = $product->getId();
304
+ $sku = $product->getSku();
305
+ $this->_writeproductDeletion($sku, $productId, $storeId, $product);
306
+ }
307
+
308
  public function adminSessionUserLoginSuccess()
309
  {
310
  $notifications = array();
311
  /** @var Autocompleteplus_Autosuggest_Helper_Data $helper */
312
+ $helper = Mage::helper('autocompleteplus_autosuggest');
313
+ $command = 'http://magento.autocompleteplus.com/ext_info?u='.$this->getConfig()->getUUID();
314
  $res = $helper->sendCurl($command);
315
  $result = json_decode($res);
316
  if (isset($result->alerts)) {
317
  foreach ($result->alerts as $alert) {
318
  $notification = array(
319
+ 'type' => (string) $alert->type,
320
+ 'message' => (string) $alert->message,
321
  'timestamp' => (string) $alert->timestamp,
322
  );
323
  if (isset($alert->subject)) {
347
  */
348
  protected function _sendStatusMail($notification)
349
  {
 
350
  /** @var Autocompleteplus_Autosuggest_Helper_Data $helper */
351
+ $helper = Mage::helper('autocompleteplus_autosuggest');
352
  // Getting site owner email
353
  $storeMail = $helper->getConfigDataByFullPath('autocompleteplus/config/store_email');
354
  if ($storeMail) {
355
+ $emailTemplate = Mage::getModel('core/email_template');
 
356
  $emailTemplate->loadDefault('autosuggest_status_notification');
357
  $emailTemplate->setTemplateSubject($notification->getSubject());
 
358
  // Get General email address (Admin->Configuration->General->Store Email Addresses)
359
  $emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_general/email'));
360
  $emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_general/name'));
 
361
  $emailTemplateVariables['message'] = $notification->getMessage();
362
  $emailTemplate->send($storeMail, null, $emailTemplateVariables);
363
  $notification->setIsActive(0)
366
  }
367
 
368
  /**
369
+ * The generic webhook service caller.
370
+ *
371
+ * @param Varien_Event_Observer $observer
372
  */
373
+ public function webhook_service_call()
374
  {
375
  $curl = new Varien_Http_Adapter_Curl();
376
  $curl->setConfig(array(
377
+ 'timeout' => static::WEBHOOK_CURL_TIMEOUT_LENGTH,
378
  ));
 
379
  $curl->write(Zend_Http_Client::GET, $this->_getWebhookObjectUri());
380
  $curl->read();
381
  $curl->close();
382
  }
383
 
384
  /**
385
+ * Create the webhook URI.
386
+ *
387
+ * @return string
 
 
388
  */
389
+ protected function _getWebhookObjectUri()
390
  {
391
+ $helper = Mage::helper('autocompleteplus_autosuggest');
392
+ $parameters = array(
393
+ 'event' => $this->getWebhookEventLabel(),
394
+ 'UUID' => $this->getConfig()->getUUID(),
395
+ 'key' => $this->getConfig()->getAuthorizationKey(),
396
+ 'store_id' => Mage::app()->getStore()->getStoreId(),
397
+ 'st' => $helper->getSessionId(),
398
+ 'cart_token' => $this->getQuoteId(),
399
+ 'serp' => '',
400
+ 'cart_product' => $this->getCartContentsAsJson(),
401
+ );
402
 
403
+ return static::AUTOCOMPLETEPLUS_WEBHOOK_URI.'?'.http_build_query($parameters, '', '&');
 
 
 
 
 
 
 
 
404
  }
405
 
406
  /**
407
+ * Return a label for webhooks based on the current
408
  * controller route. This cannot be handled by layout
409
  * XML because the layout engine may not be init in all
410
+ * future uses of the webhook.
411
+ *
412
  * @return string|void
413
  */
414
  public function getWebhookEventLabel()
415
  {
416
+ $request = Mage::app()->getRequest();
417
+ $route = $request->getRouteName();
418
  $controller = $request->getControllerName();
419
+ $action = $request->getActionName();
420
+ if ($route != 'checkout') {
 
421
  return;
422
  }
423
+ if ($controller == 'cart' && $action == 'index') {
 
424
  return 'cart';
425
  }
426
+ if ($controller == 'onepage' && $action == 'index') {
 
427
  return 'checkout';
428
  }
429
+ if ($controller == 'onepage' && $action == 'success') {
 
430
  return 'success';
431
  }
 
432
  }
433
 
434
  /**
435
+ * Returns the quote id if it exists, otherwise it will
436
+ * return the last order id. This only is set in the session
437
+ * when an order has been recently completed. Therefore
438
+ * this call may also return null.
439
+ *
440
+ * @return string|null
441
  */
442
+ public function getQuoteId()
443
  {
444
+ if ($quoteId = Mage::getSingleton('checkout/session')->getQuoteId()) {
445
+ return $quoteId;
446
+ }
447
 
448
+ return $this->getOrder()->getQuoteId();
449
+ }
450
+
451
+ /**
452
+ * Get the order associated with the previous quote id
453
+ * used as a fallback when the quote is no longer available.
454
+ *
455
+ * @return Mage_Sales_Model_Order
456
+ */
457
+ public function getOrder()
458
+ {
459
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
460
 
461
+ return Mage::getModel('sales/order')->load($orderId);
462
  }
463
 
464
  /**
465
+ * JSON encode the cart contents.
466
+ *
467
  * @return string
468
  */
469
  public function getCartContentsAsJson()
472
  }
473
 
474
  /**
475
+ * Format visible cart contents into a multidimensional keyed array.
476
+ *
477
  * @return array
478
  */
479
  protected function _getVisibleItems()
480
  {
481
+ if ($cartItems = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems()) {
482
  return $this->_buildCartArray($cartItems);
483
  }
484
+
485
  return $this->_buildCartArray($this->getOrder()->getAllVisibleItems());
486
  }
487
 
488
  /**
489
+ * Return a formatted array of quote or order items.
490
+ *
491
+ * @param array $cartItems
492
+ *
493
  * @return array
494
  */
495
  protected function _buildCartArray($cartItems)
496
  {
497
  $items = array();
498
+ foreach ($cartItems as $item) {
499
+ if ($item instanceof Mage_Sales_Model_Order_Item) {
500
+ $quantity = (int) $item->getQtyOrdered();
 
 
 
 
501
  } else {
502
  $quantity = $item->getQty();
503
  }
504
+ if (is_object($item->getProduct())) { // Fatal error fix: Call to a member function getId() on a non-object
505
  $items[] = array(
506
+ 'product_id' => $item->getProduct()->getId(),
507
+ 'price' => $item->getProduct()->getFinalPrice(),
508
+ 'quantity' => $quantity,
509
+ 'currency' => Mage::app()->getStore()->getCurrentCurrencyCode(),
510
+ 'attribution' => $item->getAddedFromSearch(),
511
  );
512
  }
513
  }
514
 
515
  return $items;
516
  }
517
+ }
 
app/code/local/Autocompleteplus/Autosuggest/Model/Pusher.php CHANGED
@@ -1,8 +1,9 @@
1
  <?php
 
2
  class Autocompleteplus_Autosuggest_Model_Pusher extends Mage_Core_Model_Abstract
3
  {
4
  protected function _construct()
5
  {
6
  $this->_init('autocompleteplus_autosuggest/pusher');
7
  }
8
- }
1
  <?php
2
+
3
  class Autocompleteplus_Autosuggest_Model_Pusher extends Mage_Core_Model_Abstract
4
  {
5
  protected function _construct()
6
  {
7
  $this->_init('autocompleteplus_autosuggest/pusher');
8
  }
9
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Batches.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Resource_Batches extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * Resource initialization.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('autocompleteplus_autosuggest/batches', 'id');
11
+ }
12
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Batches/Collection.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Resource_Batches_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * Initialize resource collection.
7
+ */
8
+ public function _construct()
9
+ {
10
+ $this->_init('autocompleteplus_autosuggest/batches');
11
+ }
12
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Checksum.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Resource_Checksum extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * Resource initialization.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('autocompleteplus_autosuggest/checksum', 'identifier');
11
+ }
12
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Checksum/Collection.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Resource_Checksum_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * Initialize resource collection.
7
+ */
8
+ public function _construct()
9
+ {
10
+ $this->_init('autocompleteplus_autosuggest/checksum');
11
+ }
12
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Fulltext/Collection.php CHANGED
@@ -1,210 +1,225 @@
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
+ *
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
+ * Fulltext Collection.
29
+ *
30
+ * @category Mage
31
+ *
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Autocompleteplus_Autosuggest_Model_Resource_Fulltext_Collection extends Mage_Catalog_Model_Resource_Product_Collection
35
+ {
36
+ protected $list_ids = array();
37
+ protected $is_fulltext_enabled = false;
38
+
39
+ protected $is_layered_enabled = false;
40
+
41
+ public function __construct($resource = null, array $args = array())
42
+ {
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
+ return Mage::helper('catalogsearch')->getQuery();
59
+ }
60
+
61
+ return false;
62
+ }
63
+
64
+ /* compatibility with GoMage extension */
65
+ public function getSearchedEntityIds()
66
+ {
67
+ return $this->list_ids;
68
+ }
69
+
70
+ protected function getSession()
71
+ {
72
+ return Mage::getSingleton('core/session');
73
+ }
74
+
75
+ public function clearSessionData()
76
+ {
77
+ $this->getSession()->unsIsFullTextEnable();
78
+ $this->getSession()->unsIspSearchAlternatives();
79
+ $this->getSession()->unsIspSearchResultsFor();
80
+
81
+ return $this;
82
+ }
83
+
84
+ public function setSessionData($responseObj, $query)
85
+ {
86
+ // InstantSearch+ js file will be injected to the search result page
87
+ $this->getSession()->setIsFullTextEnable(true);
88
+ // recording the query for the current 'core/session' to check it when injecting the magento_full_text.js
89
+ $this->getSession()->setIspUrlEncodeQuery(urlencode($query));
90
+
91
+ if (array_key_exists('alternatives', $responseObj) && $responseObj->alternatives) {
92
+ $this->getSession()->setIspSearchAlternatives($responseObj->alternatives);
93
+ } else {
94
+ $this->getSession()->setIspSearchAlternatives(false);
95
+ }
96
+
97
+ if (array_key_exists('results_for', $responseObj) && $responseObj->results_for) {
98
+ $this->getSession()->setIspSearchResultsFor($responseObj->results_for);
99
+ } else {
100
+ $this->getSession()->setIspSearchResultsFor(false);
101
+ }
102
+ }
103
+
104
+ public function prepareDefaultQuery()
105
+ {
106
+ //adding if fulltext search disabled then write regular flow
107
+ Mage::getSingleton('catalogsearch/fulltext')->prepareResult();
108
+
109
+ $this->getSelect()->joinInner(
110
+ array('search_result' => $this->getTable('catalogsearch/result')),
111
+ $this->getConnection()->quoteInto(
112
+ 'search_result.product_id=e.entity_id AND search_result.query_id=?',
113
+ $this->_getQuery()->getId()
114
+ ),
115
+ array('relevance' => 'relevance')
116
+ );
117
+ }
118
+
119
+ /**
120
+ * Add search query filter.
121
+ *
122
+ * @param string $query
123
+ *
124
+ * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
125
+ */
126
+ public function addSearchFilter($query)
127
+ {
128
+ if (!$this->is_layered_enabled) {
129
+ $helper = Mage::helper('autocompleteplus_autosuggest');
130
+ $config = Mage::getModel('autocompleteplus_autosuggest/config');
131
+ $key = $config->getUUID();
132
+ $storeId = Mage::app()->getStore()->getStoreId();
133
+ $server_end_point = $helper->getServerEndPoint();
134
+
135
+ $url_domain = $server_end_point ? $server_end_point.'/ma_search' : 'http://magento.instantsearchplus.com/ma_search';
136
+
137
+ $extension_version = Mage::helper('autocompleteplus_autosuggest')->getVersion();
138
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
139
+ $url = $url_domain.'?q='.urlencode($query).'&p=1&products_per_page=1000&v='.$extension_version.'&store_id='.$storeId.'&UUID='.$key.'&h='.$site_url;
140
+
141
+ $resp = $helper->sendCurl($url);
142
+ $response_json = json_decode($resp);
143
+ $enabledFulltext = array_key_exists('fulltext_disabled', $response_json) ? !$response_json->fulltext_disabled : false;
144
+
145
+ if ($enabledFulltext) {
146
+ $enabledFulltext = ((array_key_exists('id_list', $response_json)) &&
147
+ (array_key_exists('total_results', $response_json))) ? true : false;
148
+ }
149
+
150
+ $this->clearSessionData();
151
+
152
+ if (!$enabledFulltext) {
153
+ Mage::getSingleton('core/session')->setIsFullTextEnable(false);
154
+
155
+ $this->prepareDefaultQuery();
156
+ }
157
+
158
+ if ($enabledFulltext) {
159
+ $this->is_fulltext_enabled = true;
160
+ $this->setSessionData($response_json, $query);
161
+
162
+ if ($response_json->total_results) {
163
+ $id_list = $response_json->id_list;
164
+ $product_ids = array();
165
+ //validate received ids
166
+ foreach ($id_list as $id) {
167
+ if ($id != null && is_numeric($id)) {
168
+ $product_ids[] = $id;
169
+ }
170
+ }
171
+ $this->list_ids = $product_ids;
172
+ $idStr = (count($product_ids) > 0) ? implode(',', $product_ids) : '0';
173
+ } else {
174
+ $idStr = '0';
175
+ }
176
+
177
+ if (array_key_exists('server_endpoint', $response_json)) {
178
+ if ($server_end_point != $response_json->server_endpoint) {
179
+ $helper->setServerEndPoint($response_json->server_endpoint);
180
+ }
181
+ }
182
+
183
+ $this->getSelect()->where('e.entity_id IN ('.$idStr.')');
184
+ }
185
+ }
186
+
187
+ return $this;
188
+ }
189
+
190
+ /**
191
+ * Set Order field.
192
+ *
193
+ * @param string $attribute
194
+ * @param string $dir
195
+ *
196
+ * @return Mage_Catalog_Model_Resource_Product_Collection
197
+ */
198
+ public function setOrder($attribute, $dir = parent::SORT_ORDER_ASC)
199
+ {
200
+ if (!$this->is_layered_enabled) {
201
+ if ($this->is_fulltext_enabled && $attribute == 'relevance') {
202
+ $dir = parent::SORT_ORDER_ASC;
203
+ $id_str = (count($this->list_ids) > 0) ? implode(',', $this->list_ids) : '0';
204
+ if (!empty($id_str)) {
205
+ $sort = "FIELD(e.entity_id, {$id_str}) {$dir}";
206
+ $this->getSelect()->order(new Zend_Db_Expr($sort));
207
+ }
208
+ } else {
209
+ return parent::setOrder($attribute, $dir);
210
+ }
211
+ }
212
+
213
+ return $this;
214
+ }
215
+
216
+ /**
217
+ * Stub method for campatibility with other search engines.
218
+ *
219
+ * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
220
+ */
221
+ public function setGeneralDefaultQuery()
222
+ {
223
+ return $this;
224
+ }
225
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/{Mysql4 → Resource}/Notifications.php RENAMED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,12 +9,11 @@
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
-
18
- class Autocompleteplus_Autosuggest_Model_Mysql4_Notifications extends Mage_Core_Model_Mysql4_Abstract
19
  {
20
  protected function _construct()
21
  {
@@ -39,4 +37,4 @@ class Autocompleteplus_Autosuggest_Model_Mysql4_Notifications extends Mage_Core_
39
  }
40
  }
41
  }
42
- }
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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_Model_Resource_Notifications extends Mage_Core_Model_Resource_Db_Abstract
 
17
  {
18
  protected function _construct()
19
  {
37
  }
38
  }
39
  }
40
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/{Mysql4 → Resource}/Notifications/Collection.php RENAMED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,13 +9,12 @@
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
-
18
- class Autocompleteplus_Autosuggest_Model_Mysql4_Notifications_Collection
19
- extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
  protected function _construct()
22
  {
@@ -25,12 +23,14 @@ class Autocompleteplus_Autosuggest_Model_Mysql4_Notifications_Collection
25
 
26
  /**
27
  * @param string $type
 
28
  * @return $this
29
  */
30
  public function addTypeFilter($type)
31
  {
32
  $this->getSelect()
33
  ->where('type=?', $type);
 
34
  return $this;
35
  }
36
 
@@ -38,6 +38,7 @@ class Autocompleteplus_Autosuggest_Model_Mysql4_Notifications_Collection
38
  {
39
  $this->getSelect()
40
  ->where('is_active=?', 1);
 
41
  return $this;
42
  }
43
- }
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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_Model_Resource_Notifications_Collection
17
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
 
18
  {
19
  protected function _construct()
20
  {
23
 
24
  /**
25
  * @param string $type
26
+ *
27
  * @return $this
28
  */
29
  public function addTypeFilter($type)
30
  {
31
  $this->getSelect()
32
  ->where('type=?', $type);
33
+
34
  return $this;
35
  }
36
 
38
  {
39
  $this->getSelect()
40
  ->where('is_active=?', 1);
41
+
42
  return $this;
43
  }
44
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/{Mysql4 → Resource}/Pusher.php RENAMED
@@ -1,13 +1,16 @@
1
  <?php
2
 
3
- class Autocompleteplus_Autosuggest_Model_Mysql4_Pusher extends Mage_Core_Model_Resource_Db_Abstract
4
  {
5
- protected function _construct() {
 
6
  $this->_init('autocompleteplus_autosuggest/pusher', 'id');
7
  }
8
 
9
- public function truncate() {
 
10
  $this->_getWriteAdapter()->query('TRUNCATE TABLE '.$this->getMainTable());
 
11
  return $this;
12
  }
13
- }
1
  <?php
2
 
3
+ class Autocompleteplus_Autosuggest_Model_Resource_Pusher extends Mage_Core_Model_Resource_Db_Abstract
4
  {
5
+ protected function _construct()
6
+ {
7
  $this->_init('autocompleteplus_autosuggest/pusher', 'id');
8
  }
9
 
10
+ public function truncate()
11
+ {
12
  $this->_getWriteAdapter()->query('TRUNCATE TABLE '.$this->getMainTable());
13
+
14
  return $this;
15
  }
16
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Pusher/Collection.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Model_Resource_Pusher_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('autocompleteplus_autosuggest/pusher');
8
+ }
9
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Service.php CHANGED
@@ -2,278 +2,54 @@
2
 
3
  class Autocompleteplus_Autosuggest_Model_Service
4
  {
5
- public function toSend() {
6
- // Check if Pusher is set
7
- $pusher = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->getData();
8
- if (empty($pusher)) {
9
- $all_stores = Mage::app()->getStores();
10
- foreach ($all_stores as $i => $store) {
11
- $id = Mage::app()->getStore($i)->getId();
12
- $products = count(Mage::getModel('catalog/product')->getCollection()->addStoreFilter($id));
13
- //take all products
14
- //$products = $products > 1000 ? 1000 : $products; // 1000 limit
15
- $total_batches = $products / 100;
16
- $rnd = intval($total_batches);
17
- $total_batches = $total_batches > $rnd ? ++$rnd : $rnd;
18
- $to_push = Mage::getModel('autocompleteplus_autosuggest/pusher');
19
- $to_push->setData('store_id', $id);
20
- $to_push->setData('to_send', $products);
21
- $to_push->setData('offset', 0);
22
- $to_push->setData('batch_number', 1);
23
- $to_push->setData('total_batches', $total_batches);
24
- $to_push->save();
25
- }
26
- $pusher = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->getData();
27
- }
28
- // Sorting pusher array
29
- if (!empty($pusher)){
30
- //usort($pusher, '$this->compare_id');
31
- usort($pusher, array($this, 'compare_id'));
32
- }
33
-
34
- // Count total batches
35
- $total_batches = 0;
36
- foreach ($pusher as $push) {
37
- $total_batches += $push['total_batches'];
38
- }
39
- // Getting auth key
40
- $config_arr = Mage::getModel('autocompleteplus_autosuggest/config')->getCollection()->getData();
41
- $config = $config_arr[0];
42
- $auth_key = $config['authkey'];
43
- $uuid = $config['licensekey'];
44
-
45
- // Calculating store id to send
46
- $batch_number = 0;
47
- $row_batch_num = 0;
48
- $to_send = 0;
49
- $store_id = 0;
50
- $row_id = 0;
51
- foreach ($pusher as $push) {
52
- $to_send = $push['to_send'];
53
- $row_id = $push['id'];
54
- $batch_number += $push['batch_number']; // Calculating overall batch number
55
- if (!$to_send) {
56
- continue; // This one is done, go next
57
- } else {
58
- $offset = $push['offset'];
59
- $store_id = $push['store_id'];
60
- $row_batch_num = $push['batch_number']; // This one is per row and increments by 1
61
- break; // Got one that isn't finished yet, everything is set, roll out!
62
- }
63
- }
64
- // Sending!
65
- if ($to_send) {
66
- $count = $to_send > 100 ? 100 : $to_send;
67
- $helper=Mage::helper('autocompleteplus_autosuggest');
68
- //getting site url
69
- $url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
70
- // Getting XML
71
- $sender = $url . "index.php/autocompleteplus/products/send";
72
- $s_data['offset'] = $offset;
73
- $s_data['count'] = $count;
74
- $s_data['store'] = $store_id;
75
-
76
- $res1 = $helper->sendPostCurl($sender, $s_data);
77
-
78
- // setting post data and command url
79
- $data['uuid'] = $uuid;
80
- $data['site_url'] = $url;
81
- $data['store_id'] = $store_id;
82
- $data['authentication_key'] = $auth_key;
83
- $data['total_batches'] = $total_batches;
84
- $data['batch_number'] = $batch_number;
85
- if ($batch_number == $total_batches) {
86
- $data['is_last'] = 1;
87
- // error_log('IS LAST ' . $data['is_last']);
88
- }
89
- $data['products'] = $res1;
90
-
91
- $cmd_url = 'http://magento.instantsearchplus.com/magento_fetch_products';
92
-
93
-
94
- // sending products
95
- $res2 = $helper->sendPostCurl($cmd_url, $data);
96
-
97
- // updating pusher table
98
- $to_send -= $count;
99
- $to_send = $to_send < 0 ? 0 : $to_send;
100
- $row_batch_num = $to_send == 0 ? $row_batch_num : ++$row_batch_num;
101
- $offset += $count;
102
- $id = $row_id;
103
- $to_save = array('to_send' => $to_send,'offset' => $offset, 'batch_number' => $row_batch_num);
104
- $model = Mage::getModel('autocompleteplus_autosuggest/pusher')->load($id)->addData($to_save);
105
- try {
106
- $model->setId($id)->save();
107
- } catch (Exception $e){
108
- }
109
- } else { // Dismissing the cron
110
- $config_xml_path = Mage::getModuleDir('etc', 'Autocompleteplus_Autosuggest') . '/config.xml';
111
- $config_xml = simplexml_load_file($config_xml_path) or die("Error: Cannot create object");
112
- if (isset($config_xml) && isset($config_xml->crontab)) {
113
- unset($config_xml->crontab);
114
- $config_xml->asXML($config_xml_path);
115
- }
116
- // Cleaning
117
- Mage::app()->cleanCache();
118
- $schedule = Mage::getModel('cron/schedule');
119
- $sch_col = $schedule->getCollection()
120
- ->addFilter('job_code', 'autocompleteplus_autosuggest_toSend');
121
- foreach ($sch_col as $s) {
122
- $s->delete();
123
- }
124
- }
125
- }
126
-
127
- public function populatePusher(){
128
-
129
  $helper = Mage::helper('autocompleteplus_autosuggest');
130
 
131
  $multistoreJson = $helper->getMultiStoreDataJson();
 
 
132
 
133
- $storesInfo=json_decode($multistoreJson);
 
 
 
134
 
 
135
  Mage::getResourceModel('autocompleteplus_autosuggest/pusher')->truncate();
136
- // Check if Pusher is set
137
- $pusher = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->getData();
138
- if (empty($pusher)) {
139
 
140
- if(!is_array($storesInfo->stores)){
141
-
142
- $id = $storesInfo->stores->store_id;
 
143
 
144
- $products = Mage::getModel('catalog/product')
145
- ->getCollection()
146
- ->setStoreId($id)->count();
147
-
148
- // $products = $products > 500 ? 500 : $products; // 1000 limit
149
- $total_batches = $products / 100;
150
- $rnd = intval($total_batches);
151
-
152
- $total_batches = $total_batches > $rnd ? ++$rnd : $rnd;
153
-
154
- $offset=0;
155
-
156
- for($j=1;$j<=$total_batches;$j++){
157
-
158
- $to_push = Mage::getModel('autocompleteplus_autosuggest/pusher');
159
- $to_push->setData('store_id', $id);
160
- $to_push->setData('to_send', $products);
161
- $to_push->setData('offset', $offset);
162
- $to_push->setData('batch_number', $j);
163
- $to_push->setData('total_batches', $total_batches);
164
- $to_push->setData('sent', 0);
165
- $to_push->save();
166
-
167
- $offset+=100;
168
-
169
- }
170
-
171
- }else{
172
- foreach ($storesInfo->stores as $i => $store) {
173
-
174
- $id = $store->store_id;
175
 
176
- $products = Mage::getModel('catalog/product')
177
- ->getCollection()
178
- ->setStoreId($id)->count();
179
-
180
- // $products = $products > 500 ? 500 : $products; // 1000 limit
181
- $total_batches = $products / 100;
182
- $rnd = intval($total_batches);
183
-
184
- $total_batches = $total_batches > $rnd ? ++$rnd : $rnd;
185
-
186
- $offset=0;
187
-
188
- for($j=1;$j<=$total_batches;$j++){
189
-
190
- $to_push = Mage::getModel('autocompleteplus_autosuggest/pusher');
191
- $to_push->setData('store_id', $id);
192
- $to_push->setData('to_send', $products);
193
- $to_push->setData('offset', $offset);
194
- $to_push->setData('batch_number', $j);
195
- $to_push->setData('total_batches', $total_batches);
196
- $to_push->setData('sent', 0);
197
- $to_push->save();
198
-
199
- $offset+=100;
200
-
201
- }
202
-
203
- }
204
-
205
- }
206
  }
 
 
 
 
 
207
  }
208
-
209
- public function toPush($uuid,$auth_key) {
210
-
211
- set_time_limit (18000);
212
-
213
- $helper = Mage::helper('autocompleteplus_autosuggest');
214
-
215
- $multistoreJson = $helper->getMultiStoreDataJson();
216
-
217
- $storesInfo=json_decode($multistoreJson);
218
-
219
- $catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
220
-
221
- if (empty($pusher)) {
222
- //$all_stores = Mage::app()->getStores();
223
- foreach($storesInfo->stores as $store){
224
-
225
- $id = $store->store_id;
226
-
227
- $products = Mage::getModel('catalog/product')
228
- ->getCollection()
229
- ->setStoreId($id)->count();
230
-
231
-
232
- $products = $products > 500 ? 500 : $products; // 1000 limit
233
- $total_batches = $products / 100;
234
-
235
- $startId=0;
236
-
237
- for($i=0;$i<$total_batches; $i++){
238
-
239
- $startId=$i * 100;
240
-
241
- $xml=$catalogModel->renderCatalogXml($startId,100,$id);
242
-
243
- $url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
244
-
245
- // setting post data and command url
246
- $data['uuid'] = $uuid;
247
- $data['site_url'] = $url;
248
- $data['store_id'] = $id;
249
- $data['authentication_key'] = $auth_key;
250
- $data['total_batches'] = $total_batches;
251
- $data['batch_number'] = $startId;
252
- if ($i+1 > $total_batches) {
253
- $data['is_last'] = 1;
254
- // error_log('IS LAST ' . $data['is_last']);
255
- }
256
- $data['products'] = $xml;
257
-
258
- $cmd_url = 'http://magento.instantsearchplus.com/magento_fetch_products';
259
-
260
-
261
- // sending products
262
- $res2 = $helper->sendPostCurl($cmd_url, $data);
263
-
264
- unset($data['products']);
265
-
266
- Mage::log(print_r($data,true), null, 'autocomplete.log',true);
267
- Mage::log(print_r($res2,true), null, 'autocomplete.log',true);
268
- }
269
- }
270
 
271
- }
 
 
272
  }
273
 
274
- private function compare_id($a, $b)
275
  {
276
- if ($a['id'] == $b['id']) return 0;
277
- return ($a['id'] < $b['id']) ? -1 : 1;
278
  }
279
  }
2
 
3
  class Autocompleteplus_Autosuggest_Model_Service
4
  {
5
+ public function populatePusher()
6
+ {
7
+ $inserts = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  $helper = Mage::helper('autocompleteplus_autosuggest');
9
 
10
  $multistoreJson = $helper->getMultiStoreDataJson();
11
+ $storesInfo = json_decode($multistoreJson);
12
+ $stores = is_array($storesInfo->stores) ? $stores : array($stores);
13
 
14
+ $productCollection = Mage::getModel('catalog/product')->getCollection()->setStoreId($id);
15
+ $productsCount = $productCollection->getSize();
16
+ $write = $this->_getWriteAdapter();
17
+ $tableName = $this->_getTable('autocompleteplus_autosuggest/pusher');
18
 
19
+ //truncate the log table
20
  Mage::getResourceModel('autocompleteplus_autosuggest/pusher')->truncate();
 
 
 
21
 
22
+ foreach ($storesInfo->stores as $i => $store) {
23
+ $id = $store->store_id;
24
+ $batches = ceil($productsCount / 100);
25
+ $offset = 0;
26
 
27
+ for ($j = 1;$j <= $batches;++$j) {
28
+ $inserts[] = array(
29
+ 'store_id' => $id,
30
+ 'to_send' => $productsCount,
31
+ 'offset' => $offset,
32
+ 'batch_number' => $j,
33
+ 'total_batches' => $batches,
34
+ 'sent' => 0,
35
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ $offset += 100;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
+ }
40
+
41
+ if ($inserts) {
42
+ $write->insertMultiple($tableName, $inserts);
43
+ }
44
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ protected function _getWriteAdapter()
47
+ {
48
+ return Mage::getSingleton('core/resource')->getConnection('core_write');
49
  }
50
 
51
+ protected function _getTable($resourceName)
52
  {
53
+ return Mage::getSingleton('core/resource')->getTableName($resourceName);
 
54
  }
55
  }
app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/Autocompleteplus/PushController.php CHANGED
@@ -9,7 +9,10 @@ class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_PushController ext
9
  $service = Mage::getModel('autocompleteplus_autosuggest/service');
10
  $service->populatePusher();
11
 
12
- $response->setBody($this->getLayout()->createBlock('autocompleteplus_autosuggest/adminhtml_process')->toHtml());
 
 
 
13
  $response->sendResponse();
14
  }
15
 
@@ -17,5 +20,4 @@ class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_PushController ext
17
  {
18
  return Mage::getSingleton('admin/session')->isAllowed('system/config/autocompleteplus');
19
  }
20
-
21
- }
9
  $service = Mage::getModel('autocompleteplus_autosuggest/service');
10
  $service->populatePusher();
11
 
12
+ $block = $this->getLayout()->createBlock('autocompleteplus_autosuggest/adminhtml_process');
13
+ $block->setTemplate('autocompleteplus/process.phtml');
14
+
15
+ $response->setBody($block->toHtml());
16
  $response->sendResponse();
17
  }
18
 
20
  {
21
  return Mage::getSingleton('admin/session')->isAllowed('system/config/autocompleteplus');
22
  }
23
+ }
 
app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/Autocompleteplus/RedirectController.php CHANGED
@@ -5,14 +5,14 @@ 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
  {
10
- $this->helper = Mage::helper('autocompleteplus_autosuggest');
11
  }
12
 
13
  public function gotoAction()
14
  {
15
- $kwys = $this->helper->getBothKeys();
16
  $response = $this->getResponse();
17
 
18
  $response->clearHeaders();
@@ -25,15 +25,15 @@ class Autocompleteplus_Autosuggest_Adminhtml_Autocompleteplus_RedirectController
25
  $uuid = $kwys['uuid'];
26
  $authkey = $kwys['authkey'];
27
 
28
- if(!isset($uuid) || !isset($authkey)){
29
- return self::ISP_SITE_URL . 'login';
30
  }
31
 
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
- }
5
  const ISP_SITE_URL = 'https://magento.instantsearchplus.com/';
6
  const REDIRECT_STATUS_CODE = 302;
7
 
8
+ protected function _getConfig()
9
  {
10
+ return Mage::getModel('autocompleteplus_autosuggest/config');
11
  }
12
 
13
  public function gotoAction()
14
  {
15
+ $kwys = $this->_getConfig()->getBothKeys();
16
  $response = $this->getResponse();
17
 
18
  $response->clearHeaders();
25
  $uuid = $kwys['uuid'];
26
  $authkey = $kwys['authkey'];
27
 
28
+ if (!isset($uuid) || !isset($authkey)) {
29
+ return self::ISP_SITE_URL.'login';
30
  }
31
 
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/CatalogSearch/ResultController.php CHANGED
@@ -1,13 +1,15 @@
1
  <?php
 
2
  require_once 'Mage/CatalogSearch/controllers/ResultController.php';
3
 
4
  class Autocompleteplus_Autosuggest_CatalogSearch_ResultController extends Mage_CatalogSearch_ResultController
5
  {
6
- public function indexAction() {
 
7
  try {
8
  $layered = Mage::getStoreConfig('autocompleteplus/config/layered');
9
  } catch (Exception $e) {
10
- Mage::log('ResultController::indexAction() exception: ' . $e->getMessage(),null,'autocompleteplus.log');
11
  }
12
  if (isset($layered) && $layered == 1) {
13
  $this->loadLayout();
@@ -16,4 +18,4 @@ class Autocompleteplus_Autosuggest_CatalogSearch_ResultController extends Mage_C
16
  parent::indexAction();
17
  }
18
  }
19
- }
1
  <?php
2
+
3
  require_once 'Mage/CatalogSearch/controllers/ResultController.php';
4
 
5
  class Autocompleteplus_Autosuggest_CatalogSearch_ResultController extends Mage_CatalogSearch_ResultController
6
  {
7
+ public function indexAction()
8
+ {
9
  try {
10
  $layered = Mage::getStoreConfig('autocompleteplus/config/layered');
11
  } catch (Exception $e) {
12
+ Mage::log('ResultController::indexAction() exception: '.$e->getMessage(), null, 'autocompleteplus.log');
13
  }
14
  if (isset($layered) && $layered == 1) {
15
  $this->loadLayout();
18
  parent::indexAction();
19
  }
20
  }
21
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/CatalogsearchController.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Magento
4
  *
5
  * NOTICE OF LICENSE
6
  *
@@ -19,18 +19,18 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Mage
22
- * @package Mage_CatalogSearch
23
  * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
  /**
28
- * Catalog Search Controller
29
  */
30
  class Autocompleteplus_Autosuggest_CatalogSearchController extends Mage_Core_Controller_Front_Action
31
  {
32
  /**
33
- * Retrieve catalog session
34
  *
35
  * @return Mage_Catalog_Model_Session
36
  */
@@ -39,7 +39,7 @@ class Autocompleteplus_Autosuggest_CatalogSearchController extends Mage_Core_Con
39
  return Mage::getSingleton('catalog/session');
40
  }
41
  /**
42
- * Display search result
43
  */
44
  public function indexAction()
45
  {
@@ -55,21 +55,19 @@ class Autocompleteplus_Autosuggest_CatalogSearchController extends Mage_Core_Con
55
  $query->setId(0)
56
  ->setIsActive(1)
57
  ->setIsProcessed(1);
58
- }
59
- else {
60
  if ($query->getId()) {
61
- $query->setPopularity($query->getPopularity()+1);
62
- }
63
- else {
64
  $query->setPopularity(1);
65
  }
66
 
67
- if ($query->getRedirect()){
68
  $query->save();
69
  $this->getResponse()->setRedirect($query->getRedirect());
 
70
  return;
71
- }
72
- else {
73
  $query->prepare();
74
  }
75
  }
@@ -84,8 +82,7 @@ class Autocompleteplus_Autosuggest_CatalogSearchController extends Mage_Core_Con
84
  if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
85
  $query->save();
86
  }
87
- }
88
- else {
89
  $this->_redirectReferer();
90
  }
91
  }
1
  <?php
2
  /**
3
+ * Magento.
4
  *
5
  * NOTICE OF LICENSE
6
  *
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category Mage
22
+ *
23
  * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
  /**
28
+ * Catalog Search Controller.
29
  */
30
  class Autocompleteplus_Autosuggest_CatalogSearchController extends Mage_Core_Controller_Front_Action
31
  {
32
  /**
33
+ * Retrieve catalog session.
34
  *
35
  * @return Mage_Catalog_Model_Session
36
  */
39
  return Mage::getSingleton('catalog/session');
40
  }
41
  /**
42
+ * Display search result.
43
  */
44
  public function indexAction()
45
  {
55
  $query->setId(0)
56
  ->setIsActive(1)
57
  ->setIsProcessed(1);
58
+ } else {
 
59
  if ($query->getId()) {
60
+ $query->setPopularity($query->getPopularity() + 1);
61
+ } else {
 
62
  $query->setPopularity(1);
63
  }
64
 
65
+ if ($query->getRedirect()) {
66
  $query->save();
67
  $this->getResponse()->setRedirect($query->getRedirect());
68
+
69
  return;
70
+ } else {
 
71
  $query->prepare();
72
  }
73
  }
82
  if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
83
  $query->save();
84
  }
85
+ } else {
 
86
  $this->_redirectReferer();
87
  }
88
  }
app/code/local/Autocompleteplus/Autosuggest/controllers/CategoriesController.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,103 +9,83 @@
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
-
18
  class Autocompleteplus_Autosuggest_CategoriesController extends Mage_Core_Controller_Front_Action
19
  {
20
- public function sendAction(){
 
 
21
 
22
- $categories=$this->load_tree();
 
 
23
 
24
- echo json_encode($categories);
25
  }
26
 
27
- private function nodeToArray(Varien_Data_Tree_Node $node , $mediaUrl, $baseUrl, $store)
28
  {
29
- $result = array();
30
-
31
- $thumbnail='';
32
-
33
- try{
34
-
35
- $thumbImg=$node->getThumbnail();
36
-
37
- if($thumbImg!=null){
38
 
39
- $thumbnail=$mediaUrl.'catalog/category/'.$node->getThumbnail();
40
- }
41
- }catch(Exception $e){
42
 
43
- }
 
 
 
 
 
 
 
 
 
 
44
 
45
- $result['category_id'] = $node->getId();
46
- $result['image'] = $mediaUrl.'catalog/category/'.$node->getImage();
47
- $result['thumbnail'] = $thumbnail;
48
- $result['description'] = strip_tags($node->getDescription());
49
- $result['parent_id'] = $node->getParentId();
50
- $result['name'] = $node->getName();
51
- $result['is_active'] = $node->getIsActive();
52
- $result['children'] = array();
53
-
54
- if (method_exists('Mage' , 'getEdition') && Mage::getEdition() == Mage::EDITION_COMMUNITY){
55
- // $result['url_path'] = $baseUrl.$node->getData('url_path');
56
-
57
- $category = Mage::getModel('catalog/category')->setStoreId($store)->load($node->getId());
58
- $result['url_path'] = $category->getUrl();
59
- } else {
60
- $category = Mage::getModel('catalog/category')->setStoreId($store)->load($node->getId());
61
- $result['url_path'] = $category->getUrl();
62
- }
63
-
64
  foreach ($node->getChildren() as $child) {
65
- $result['children'][] = $this->nodeToArray($child,$mediaUrl,$baseUrl, $store);
66
  }
67
 
68
  return $result;
69
  }
70
 
71
- private function load_tree(){
72
-
73
- $tree = Mage::getResourceSingleton('catalog/category_tree')
74
- ->load();
75
-
76
- $post = $this->getRequest()->getParams();
77
-
78
- if (array_key_exists('store', $post))
79
- $store = $post['store'];
80
- else
81
- $store = Mage::app()->getStore()->getStoreId();
82
-
83
- $parentId = Mage::app()->getStore($store)->getRootCategoryId();
84
-
85
- $tree = Mage::getResourceSingleton('catalog/category_tree')
86
- ->load();
87
 
88
  $root = $tree->getNodeById($parentId);
89
 
90
- if($root && $root->getId() == 1) {
91
  $root->setName(Mage::helper('catalog')->__('Root'));
92
  }
93
 
94
  $collection = Mage::getModel('catalog/category')->getCollection()
95
- ->setStoreId($store)
96
- ->addAttributeToSelect('name')
97
- ->addAttributeToSelect('url_path')
98
- ->addAttributeToSelect('image')
99
- ->addAttributeToSelect('thumbnail')
100
- ->addAttributeToSelect('description')
101
- ->addAttributeToFilter('is_active',array('eq'=>true));
102
 
103
  $tree->addCollectionData($collection, true);
104
 
105
- $mediaUrl= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
106
- $baseUrl= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
107
-
108
- return $this->nodeToArray($root,$mediaUrl,$baseUrl, $store);
109
 
 
110
  }
111
-
112
- }
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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_CategoriesController extends Mage_Core_Controller_Front_Action
17
  {
18
+ public function sendAction()
19
+ {
20
+ $categories = $this->loadTree();
21
 
22
+ $response = $this->getResponse();
23
+ $response->clearHeaders();
24
+ $response->setHeader('Content-type', 'application/json');
25
 
26
+ $response->setBody(json_encode($categories));
27
  }
28
 
29
+ protected function nodeToArray(Varien_Data_Tree_Node $node, $mediaUrl, $baseUrl, $store)
30
  {
31
+ $thumbnail = '';
32
+
33
+ try {
34
+ if ($thumbImg = $node->getThumbnail()) {
35
+ $thumbnail = sprintf('%scatalog/category/%s', $mediaUrl, $node->getThumbnail());
36
+ }
37
+ } catch (Exception $e) {
38
+ Mage::logException($e);
39
+ }
40
 
41
+ $category = Mage::getModel('catalog/category')->setStoreId($store)->load($node->getId());
 
 
42
 
43
+ $result = array(
44
+ 'category_id' => $node->getId(),
45
+ 'image' => sprintf('%scatalog/category/%s', $mediaUrl, $node->getImage()),
46
+ 'thumbnail' => $thumbnail,
47
+ 'description' => strip_tags($node->getDescription()),
48
+ 'parent_id' => $node->getParentId(),
49
+ 'name' => $node->getName(),
50
+ 'url_path' => $category->getUrl(),
51
+ 'is_active' => $node->getIsActive(),
52
+ 'children' => array(),
53
+ );
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  foreach ($node->getChildren() as $child) {
56
+ $result['children'][] = $this->nodeToArray($child, $mediaUrl, $baseUrl, $store);
57
  }
58
 
59
  return $result;
60
  }
61
 
62
+ protected function loadTree()
63
+ {
64
+ $storeContext = Mage::app()->getStore()->getStoreId();
65
+ $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
66
+ $store = $this->getRequest()->getParam('store', $storeContext);
67
+ $parentId = Mage::app()->getStore($store)->getRootCategoryId();
 
 
 
 
 
 
 
 
 
 
68
 
69
  $root = $tree->getNodeById($parentId);
70
 
71
+ if ($root && $root->getId() == 1) {
72
  $root->setName(Mage::helper('catalog')->__('Root'));
73
  }
74
 
75
  $collection = Mage::getModel('catalog/category')->getCollection()
76
+ ->setStoreId($store)
77
+ ->addAttributeToSelect('name')
78
+ ->addAttributeToSelect('url_path')
79
+ ->addAttributeToSelect('image')
80
+ ->addAttributeToSelect('thumbnail')
81
+ ->addAttributeToSelect('description')
82
+ ->addAttributeToFilter('is_active', array('eq' => true));
83
 
84
  $tree->addCollectionData($collection, true);
85
 
86
+ $mediaUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
87
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
 
 
88
 
89
+ return $this->nodeToArray($root, $mediaUrl, $baseUrl, $store);
90
  }
91
+ }
 
app/code/local/Autocompleteplus/Autosuggest/controllers/LayeredController.php CHANGED
@@ -1,97 +1,129 @@
1
  <?php
2
- /**
3
- * Layered Controller
4
- */
5
  class Autocompleteplus_Autosuggest_LayeredController extends Mage_Core_Controller_Front_Action
6
  {
7
- public function setLayeredSearchOnAction() {
8
- $authkey = $this->getRequest()->getParam('authentication_key') ? $this->getRequest()->getParam('authentication_key') : "";
9
- $uuid = $this->getRequest()->getParam('uuid') ? $this->getRequest()->getParam('uuid') : "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  if (!$this->valid($uuid, $authkey)) {
11
- echo json_encode(array('status' => 'error: ' . "Authentication failed"));
 
 
12
  return;
13
  }
14
 
15
- $scope = $this->getRequest()->getParam('scope') ? $this->getRequest()->getParam('scope') : 'stores';
16
- $store_id = $this->getRequest()->getParam('store_id') ? $this->getRequest()->getParam('store_id') : '1';
17
-
18
- $core_config = new Mage_Core_Model_Config();
19
  try {
20
- $core_config->saveConfig('autocompleteplus/config/layered', "1", $scope, $store_id);
21
  Mage::app()->getCacheInstance()->cleanType('config');
22
  } catch (Exception $e) {
23
- echo json_encode(array('status' => 'error: ' . print_r($e->getMessage(), true)));
 
 
 
 
24
  return;
25
  }
26
-
27
- $resp = array('new_state' => 1,
28
- 'status' => 'ok'
29
  );
30
- echo json_encode($resp);
31
- return;
32
  }
33
 
34
- public function setLayeredSearchOffAction() {
35
- $authkey = $this->getRequest()->getParam('authentication_key') ? $this->getRequest()->getParam('authentication_key') : "";
36
- $uuid = $this->getRequest()->getParam('uuid') ? $this->getRequest()->getParam('uuid') : "";
 
 
 
 
 
 
37
  if (!$this->valid($uuid, $authkey)) {
38
- echo json_encode(array('status' => 'error: ' . "Authentication failed"));
 
 
 
39
  return;
40
  }
41
 
42
- $scope = $this->getRequest()->getParam('scope') ? $this->getRequest()->getParam('scope') : 'stores';
43
- $store_id = $this->getRequest()->getParam('store_id') ? $this->getRequest()->getParam('store_id') : '1';
44
-
45
- $core_config = new Mage_Core_Model_Config();
46
  try {
47
- $core_config->saveConfig('autocompleteplus/config/layered', "0", $scope, $store_id);
48
  Mage::app()->getCacheInstance()->cleanType('config');
49
  } catch (Exception $e) {
50
- echo json_encode(array('status' => 'error: ' . print_r($e->getMessage(), true)));
 
 
 
 
51
  return;
52
  }
53
-
54
- $resp = array('new_state' => 0,
55
- 'status' => 'ok'
56
  );
57
- echo json_encode($resp);
58
- return;
59
  }
60
 
61
- public function getLayeredSearchConfigAction() {
62
- $authkey = $this->getRequest()->getParam('authentication_key') ? $this->getRequest()->getParam('authentication_key') : "";
63
- $uuid = $this->getRequest()->getParam('uuid') ? $this->getRequest()->getParam('uuid') : "";
 
 
 
 
 
 
64
  if (!$this->valid($uuid, $authkey)) {
65
- echo json_encode(array('status' => 'error: ' . "Authentication failed"));
 
 
66
  return;
67
  }
68
- $store_id = $this->getRequest()->getParam('store_id') ? $this->getRequest()->getParam('store_id') : '1';
69
  try {
70
  Mage::app()->getCacheInstance()->cleanType('config');
71
- $current_state = Mage::getStoreConfig('autocompleteplus/config/layered', $store_id);
72
  } catch (Exception $e) {
73
- echo json_encode(array('status' => 'error: ' . print_r($e->getMessage(), true)));
 
 
 
 
74
  return;
75
  }
76
- echo json_encode(array('current_state' => $current_state));
77
- return;
 
78
  }
79
 
80
- private function valid($uuid, $authkey) {
81
- $valid = false;
82
- try {
83
- $config_arr = Mage::getModel('autocompleteplus_autosuggest/config')->getCollection()->getData();
84
- } catch (Exception $e) {
85
- return $valid;
86
- }
87
- $config = $config_arr[0];
88
- if (isset($config['authkey']) && isset($config['licensekey'])) {
89
- if ($config['authkey'] == $authkey && $config['licensekey'] == $uuid) {
90
- $valid = true;
91
- }
92
- } else {
93
- return $valid;
94
  }
95
- return $valid;
 
96
  }
97
  }
1
  <?php
2
+
 
 
3
  class Autocompleteplus_Autosuggest_LayeredController extends Mage_Core_Controller_Front_Action
4
  {
5
+ public function preDispatch()
6
+ {
7
+ parent::preDispatch();
8
+
9
+ $this->getResponse()->clearHeaders();
10
+ $this->getResponse()->setHeader('Content-type', 'application/json');
11
+ }
12
+
13
+ protected function _getConfig()
14
+ {
15
+ return Mage::getModel('autocompleteplus_autosuggest/config');
16
+ }
17
+
18
+ public function setLayeredSearchOnAction()
19
+ {
20
+ $response = $this->getResponse();
21
+ $request = $this->getRequest();
22
+ $authkey = $request->getParam('authentication_key');
23
+ $uuid = $request->getParam('uuid');
24
+ $scope = $request->getParam('scope', 'default');
25
+ $scopeId = $request->getParam('store_id', 1);
26
+
27
  if (!$this->valid($uuid, $authkey)) {
28
+ $resp = json_encode(array('status' => 'error: '.'Authentication failed'));
29
+ $response->setBody($resp);
30
+
31
  return;
32
  }
33
 
 
 
 
 
34
  try {
35
+ $this->_getConfig()->enableLayeredNavigation($scope, $scopeId);
36
  Mage::app()->getCacheInstance()->cleanType('config');
37
  } catch (Exception $e) {
38
+ $resp = json_encode(array('status' => 'error: '.print_r($e->getMessage(), true)));
39
+ $response->setBody($resp);
40
+
41
+ Mage::logException($e);
42
+
43
  return;
44
  }
45
+
46
+ $resp = array('new_state' => 1,
47
+ 'status' => 'ok',
48
  );
49
+
50
+ $response->setBody(json_encode($resp));
51
  }
52
 
53
+ public function setLayeredSearchOffAction()
54
+ {
55
+ $request = $this->getRequest();
56
+ $response = $this->getResponse();
57
+ $authkey = $request->getParam('authentication_key');
58
+ $uuid = $request->getParam('uuid');
59
+ $scope = $request->getParam('scope', 'default');
60
+ $scopeId = $request->getParam('store_id', 1);
61
+
62
  if (!$this->valid($uuid, $authkey)) {
63
+ $resp = json_encode(array('status' => 'error: '.'Authentication failed'));
64
+
65
+ $response->setBody($resp);
66
+
67
  return;
68
  }
69
 
 
 
 
 
70
  try {
71
+ $this->_getConfig()->disableLayeredNavigation($scope, $scopeId);
72
  Mage::app()->getCacheInstance()->cleanType('config');
73
  } catch (Exception $e) {
74
+ $resp = json_encode(array('status' => 'error: '.print_r($e->getMessage(), true)));
75
+ $response->setBody($resp);
76
+
77
+ Mage::logException($e);
78
+
79
  return;
80
  }
81
+
82
+ $resp = array('new_state' => 0,
83
+ 'status' => 'ok',
84
  );
85
+
86
+ $response->setBody(json_encode($resp));
87
  }
88
 
89
+ public function getLayeredSearchConfigAction()
90
+ {
91
+ $request = $this->getRequest();
92
+ $response = $this->getResponse();
93
+
94
+ $authkey = $request->getParam('authentication_key');
95
+ $uuid = $request->getParam('uuid');
96
+ $scopeId = $request->getParam('store_id', 1);
97
+
98
  if (!$this->valid($uuid, $authkey)) {
99
+ $resp = json_encode(array('status' => $this->__('error: Authentication failed')));
100
+ $response->setBody($resp);
101
+
102
  return;
103
  }
 
104
  try {
105
  Mage::app()->getCacheInstance()->cleanType('config');
106
+ $current_state = $this->_getConfig()->getLayeredNavigationStatus($scopeId);
107
  } catch (Exception $e) {
108
+ $resp = json_encode(array('status' => 'error: '.print_r($e->getMessage(), true)));
109
+ $response->setBody($resp);
110
+
111
+ Mage::logException($e);
112
+
113
  return;
114
  }
115
+
116
+ $resp = json_encode(array('current_state' => $current_state));
117
+ $response->setBody($resp);
118
  }
119
 
120
+ protected function valid($uuid, $authkey)
121
+ {
122
+ if ($this->_getConfig()->getAuthorizationKey() == $authkey
123
+ && $this->_getConfig()->getUUID() == $uuid) {
124
+ return true;
 
 
 
 
 
 
 
 
 
125
  }
126
+
127
+ return false;
128
  }
129
  }
app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsController.php CHANGED
@@ -1,713 +1,605 @@
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
+ * 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
+ *
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_ProductsController extends Autocompleteplus_Autosuggest_Controller_Abstract
17
+ {
18
+ protected $_storeId;
19
+ const MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION = 250;
20
+ const MISSING_PARAMETER = 'false';
21
+ const PUSH_IN_PROGRESS = 1;
22
+ const PUSH_COMPLETE = 2;
23
+ const POST_MESSAGE_OK = 'ok';
24
+ const URL_EMAIL_UPDATE = 'http://magento.autocompleteplus.com/ext_update_email';
25
+ const URL_UUID_UPDATE = 'http://magento.instantsearchplus.com/update_uuid';
26
+ const XML_CONFIG_STORE_EMAIL = 'autocompleteplus/config/store_email';
27
+
28
+ protected function _getConfig()
29
+ {
30
+ return Mage::getModel('autocompleteplus_autosuggest/config');
31
+ }
32
+
33
+ public function sendAction()
34
+ {
35
+ $response = $this->getResponse();
36
+ $request = $this->getRequest();
37
+ $startInd = $request->getParam('offset');
38
+ $count = $request->getParam('count');
39
+ $store = $request->getParam('store_id', '');
40
+ $storeId = $request->getParam('store', $store);
41
+ $orders = $request->getParam('orders', '');
42
+ $monthInterval = $request->getParam('month_interval', '');
43
+ $checksum = $request->getParam('checksum', '');
44
+ $catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
45
+
46
+ $xml = $catalogModel->renderCatalogXml($startInd, $count, $storeId, $orders, $monthInterval, $checksum);
47
+
48
+ $response->setHeader('Content-type', 'text/xml');
49
+ $response->setBody($xml);
50
+ }
51
+
52
+ public function sendupdatedAction()
53
+ {
54
+ date_default_timezone_set('Asia/Jerusalem');
55
+
56
+ $request = $this->getRequest();
57
+ $response = $this->getResponse();
58
+ $count = $request->getParam('count');
59
+ $from = $request->getParam('from');
60
+ $to = $request->getParam('to', strtotime('now'));
61
+ $storeId = $request->getParam('store_id', '');
62
+
63
+ if (!$storeId) {
64
+ $returnArr = array(
65
+ 'status' => self::STATUS_FAILURE,
66
+ 'error_code' => self::MISSING_PARAMETER,
67
+ 'error_details' => $this->__('The "store id" parameter is mandatory'),
68
+ );
69
+ $response->setHeader('Content-type', 'application/json');
70
+ $response->setHttpResponseCode(400);
71
+ $response->setBody(json_encode($returnArr));
72
+
73
+ return;
74
+ }
75
+
76
+ $catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
77
+
78
+ $xml = $catalogModel->renderUpdatesCatalogXml($count, $from, $to, $storeId);
79
+
80
+ $response->clearHeaders();
81
+ $response->setHeader('Content-type', 'text/xml');
82
+ $response->setBody($xml);
83
+ }
84
+
85
+ public function checkinstallAction()
86
+ {
87
+ $response = $this->getResponse();
88
+ $installStatus = $this->_getInstallStatus();
89
+
90
+ $response->setBody($installStatus);
91
+ }
92
+
93
+ protected function _getInstallStatus()
94
+ {
95
+ if (strlen($this->_getConfig()->getUUID()) > 0 && $this->_getConfig()->getUUID() != 'failed') {
96
+ return $this->__('the key exists');
97
+ }
98
+
99
+ return $this->__('no key inside');
100
+ }
101
+
102
+ public function versAction()
103
+ {
104
+ $response = $this->getResponse();
105
+ $get_modules = $this->getRequest()->getParam('modules', false);
106
+ $mage = Mage::getVersion();
107
+ $ext = Mage::helper('autocompleteplus_autosuggest')->getVersion();
108
+ $edition = method_exists('Mage', 'getEdition') ? Mage::getEdition() : 'Community';
109
+ $helper = Mage::helper('autocompleteplus_autosuggest');
110
+ $uuid = $this->_getConfig()->getUUID();
111
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
112
+ $store_id = Mage::app()->getStore()->getStoreId();
113
+ $modules = Mage::getConfig()->getNode('modules')->children();
114
+ $installedModules = array();
115
+
116
+ try {
117
+ $num_of_products = Mage::getModel('catalog/product')->getCollection()
118
+ ->addStoreFilter($store_id)
119
+ ->getSize();
120
+ } catch (Exception $e) {
121
+ $num_of_products = -1;
122
+ }
123
+
124
+ if ($get_modules) {
125
+ try {
126
+ foreach ($modules as $name => $module) {
127
+ if ($module->codePool != 'core' && $module->active == 'true') {
128
+ $installedModules[$name] = $module;
129
+ }
130
+ }
131
+ } catch (Exception $e) {
132
+ $installedModules = array();
133
+ }
134
+ }
135
+
136
+ $result = array(
137
+ 'mage' => $mage,
138
+ 'ext' => $ext,
139
+ 'num_of_products' => $num_of_products,
140
+ 'edition' => $edition,
141
+ 'uuid' => $uuid,
142
+ 'site_url' => $site_url,
143
+ 'store_id' => $store_id,
144
+ 'modules' => $installedModules,
145
+ );
146
+
147
+ $response->clearHeaders();
148
+ $response->setHeader('Content-type', 'application/json');
149
+ $response->setBody(json_encode($result));
150
+ }
151
+
152
+ public function getNumOfProductsAction()
153
+ {
154
+ $catalogReport = Mage::getModel('autocompleteplus_autosuggest/catalogreport');
155
+ $helper = Mage::helper('autocompleteplus_autosuggest');
156
+
157
+ $result = array('num_of_products' => $catalogReport->getEnabledProductsCount(),
158
+ 'num_of_disabled_products' => $catalogReport->getDisabledProductsCount(),
159
+ 'num_of_searchable_products' => $catalogReport->getSearchableProductsCount(),
160
+ 'num_of_searchable_products2' => $catalogReport->getSearchableProducts2Count(),
161
+ 'uuid' => $this->_getConfig()->getUUID(),
162
+ 'site_url' => $helper->getConfigDataByFullPath('web/unsecure/base_url'),
163
+ 'store_id' => $catalogReport->getCurrentStoreId(),
164
+ );
165
+
166
+ $this->getResponse()->setHeader('Content-type', 'application/json');
167
+ $this->getResponse()->setBody(json_encode($result));
168
+ }
169
+
170
+ public function getConflictAction()
171
+ {
172
+ $response = $this->getResponse();
173
+ $request = $this->getRequest();
174
+ $helper = Mage::helper('autocompleteplus_autosuggest');
175
+
176
+ //check for extension conflicts
177
+ $conflicts = (bool) $request->getParam('all');
178
+ $result = $helper->getExtensionConflict($conflicts);
179
+
180
+ $response->clearHeaders();
181
+ $response->setHeader('Content-type', 'application/json');
182
+ $response->setBody(json_encode($result));
183
+ }
184
+
185
+ public function getstoresAction()
186
+ {
187
+ $response = $this->getResponse();
188
+ $helper = Mage::helper('autocompleteplus_autosuggest');
189
+
190
+ $response->setBody($helper->getMultiStoreDataJson());
191
+ }
192
+
193
+ protected function _getRobotsPath()
194
+ {
195
+ if (!$this->_robotsPath) {
196
+ $this->_robotsPath = Mage::getBaseDir().DS.'robots.txt';
197
+ }
198
+
199
+ return $this->_robotsPath;
200
+ }
201
+
202
+ public function updatesitemapAction()
203
+ {
204
+ $helper = Mage::helper('autocompleteplus_autosuggest');
205
+ $key = $this->_getConfig()->getUUID();
206
+ $url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
207
+ $robotsPath = $this->_getRobotsPath();
208
+ $io = new Varien_Io_File();
209
+ $io->open(array('path' => $io->dirName($robotsPath)));
210
+
211
+ if ($this->validateUuid($key)) {
212
+ $sitemapUrl = 'Sitemap:http://magento.instantsearchplus.com/ext_sitemap?u='.$key;
213
+ $write = false;
214
+
215
+ if ($io->fileExists($robotsPath)) {
216
+ if (strpos($io->read($robotsPath), $sitemapUrl) == false) {
217
+ $write = true;
218
+ }
219
+ } else {
220
+ if ($io->isWritable(Mage::getBaseDir())) {
221
+
222
+ //create robots sitemap
223
+ $io->write($robotsPath, $sitemapUrl);
224
+ } else {
225
+
226
+ //write message that directory is not writteble
227
+ $command = 'http://magento.autocompleteplus.com/install_error';
228
+
229
+ $data = array();
230
+ $data['site'] = $url;
231
+ $data['msg'] = $this->__('Directory %s is not writable.', Mage::getBaseDir());
232
+ $res = $helper->sendPostCurl($command, $data);
233
+ }
234
+ }
235
+
236
+ if ($write) {
237
+ if ($io->isWritable($robotsPath)) {
238
+ //append sitemap
239
+ $io->write($robotsPath, $sitemapUrl, FILE_APPEND | LOCK_EX);
240
+ } else {
241
+ //write message that file is not writteble
242
+ $command = 'http://magento.autocompleteplus.com/install_error';
243
+
244
+ $data = array();
245
+ $data['site'] = $url;
246
+ $data['msg'] = 'File '.$robotsPath.' is not writable.';
247
+ $res = $helper->sendPostCurl($command, $data);
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ protected function _setUUID($uuid)
254
+ {
255
+ $this->_getConfig()->setUUID($uuid);
256
+ }
257
+
258
+ public function getIspUuidAction()
259
+ {
260
+ $response = $this->getResponse();
261
+ $response->setBody($this->_getConfig()->getUUID());
262
+ }
263
+
264
+ public function geterrormessageAction()
265
+ {
266
+ $response = $this->getResponse();
267
+ $helper = Mage::helper('autocompleteplus_autosuggest');
268
+
269
+ $response->setBody($helper->getErrormessage());
270
+ }
271
+
272
+ public function setIspUuidAction()
273
+ {
274
+ $helper = Mage::helper('autocompleteplus_autosuggest');
275
+ $url_domain = self::URL_UUID_UPDATE;
276
+ $storeId = Mage::app()->getStore()->getStoreId();
277
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
278
+
279
+ $url = $url_domain.http_build_query(array(
280
+ 'store_id' => $storeId,
281
+ 'site_url' => $site_url,
282
+ ));
283
+
284
+ $helper = Mage::helper('autocompleteplus_autosuggest');
285
+ $resp = $helper->sendCurl($url);
286
+ $response_json = json_decode($resp);
287
+
288
+ if ($helper->validateUuid($response_json->uuid)) {
289
+ $this->_setUUID($response_json->uuid);
290
+ }
291
+ }
292
+
293
+ public function checkDeletedAction()
294
+ {
295
+ $response = $this->getResponse();
296
+ $helper = Mage::helper('autocompleteplus_autosuggest');
297
+ if (!$helper->isChecksumTableExists()) {
298
+ return;
299
+ }
300
+ $time_stamp = time();
301
+
302
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
303
+ $table_prefix = (string) Mage::getConfig()->getTablePrefix();
304
+
305
+ $post = $this->getRequest()->getParams();
306
+ if (array_key_exists('store_id', $post)) {
307
+ $store_id = $post['store_id'];
308
+ } else {
309
+ $store_id = Mage::app()->getStore()->getStoreId(); // default
310
+ }
311
+
312
+ $sql_fetch = 'SELECT identifier FROM '.$table_prefix.'autocompleteplus_checksum WHERE store_id=?';
313
+ $updates = $read->fetchPairs($sql_fetch, array($store_id)); // empty array if fails
314
+ if (empty($updates)) {
315
+ return;
316
+ }
317
+
318
+ $checksum_ids = array_keys($updates); // array of all checksum table identifiers
319
+ $collection = Mage::getResourceModel('catalog/product_collection');
320
+ $collection->addFieldToFilter('entity_id', array('in' => $checksum_ids));
321
+ $found_ids = $collection->getAllIds();
322
+
323
+ $removed_products_list = array_diff($checksum_ids, $found_ids); // list of identifiers that are not present in the store (removed at some point)
324
+ $removed_ids = array();
325
+
326
+ // removing non-existing identifiers from checksum table
327
+ if (!empty($removed_products_list)) {
328
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
329
+ $sql_delete = 'DELETE FROM '.$table_prefix.'autocompleteplus_checksum WHERE identifier IN ('.implode(',', $removed_products_list).')';
330
+ $write->query($sql_delete);
331
+
332
+ foreach ($removed_products_list as $product_id) {
333
+ $helper->deleteProductFromTables($read, $write, $table_prefix, $product_id, $store_id);
334
+ $removed_ids[] = $product_id;
335
+ }
336
+ }
337
+
338
+ $args = array('removed_ids' => $removed_ids,
339
+ 'uuid' => $this->_getConfig()->getUUID(),
340
+ 'store_id' => $store_id,
341
+ 'latency' => time() - $time_stamp, // seconds
342
+ );
343
+
344
+ $response->clearHeaders();
345
+ $response->setHeader('Content-type', 'application/json');
346
+ $response->setBody(json_encode($args)); // returning the summary
347
+ }
348
+
349
+ public function checksumAction()
350
+ {
351
+ $request = $this->getRequest();
352
+ $response = $this->getResponse();
353
+ $helper = Mage::helper('autocompleteplus_autosuggest');
354
+ $store_id = $request->getParam('store_id', Mage::app()->getStore()->getStoreId());
355
+ $count = $request->getParam('count', self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION);
356
+ $start_index = $request->getParam('offset', 0);
357
+ $php_timeout = $request->getParam('timeout', -1);
358
+ $is_single = $request->getParam('is_single', 0);
359
+ $uuid = $this->_getConfig()->getUUID();
360
+ $checksum_server = $helper->getServerUrl();
361
+ $collection = Mage::getModel('catalog/product')->getCollection();
362
+
363
+ if (!$helper->isChecksumTableExists()) {
364
+ $helper->ispErrorLog('checksum table not exist');
365
+ $response->setBody(json_encode(array('status' => 'checksum table not exist')));
366
+
367
+ return;
368
+ }
369
+
370
+ $max_exe_time = -1;
371
+
372
+ if ($count > self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION && $php_timeout != -1) {
373
+ $max_exe_time = ini_get('max_execution_time');
374
+ ini_set('max_execution_time', $php_timeout);
375
+ }
376
+
377
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
378
+
379
+ if ($store_id) {
380
+ $collection->addStoreFilter($store_id);
381
+ }
382
+
383
+ $num_of_products = $collection->getSize();
384
+
385
+ if ($count + $start_index > $num_of_products) {
386
+ $count = $num_of_products - $start_index;
387
+ }
388
+
389
+ // sending log to the server
390
+ $log_msg = 'Update checksum is starting...';
391
+ $log_msg .= (' number of products in this store: '.$num_of_products.' | from: '.$start_index.', to: '.($start_index + $count));
392
+ $server_url = $checksum_server.'/magento_logging_record';
393
+ $request = $server_url.'?uuid='.$uuid.'&site_url='.$site_url.'&msg='.urlencode($log_msg);
394
+ if ($store_id) {
395
+ $request .= '&store_id='.$store_id;
396
+ }
397
+ $resp = $helper->sendCurl($request);
398
+
399
+ $start_time = time();
400
+ $num_of_updated_checksum = 0;
401
+ if ($count > self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION) {
402
+ $iter = $start_index;
403
+ while ($iter < $count) {
404
+ // start updating the checksum table if needed
405
+ $num_of_updated_checksum += $helper->compareProductsChecksum($iter, self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION, $store_id);
406
+ $iter += self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION;
407
+ }
408
+ } else {
409
+ // start updating the checksum table if needed
410
+ $num_of_updated_checksum = $helper->compareProductsChecksum($start_index, $count, $store_id);
411
+ }
412
+
413
+ $process_time = time() - $start_time;
414
+ // sending confirmation/summary to the server
415
+ $args = array(
416
+ 'uuid' => $uuid,
417
+ 'site_url' => $site_url,
418
+ 'store_id' => $store_id,
419
+ 'updated_checksum' => $num_of_updated_checksum,
420
+ 'total_checksum' => $count,
421
+ 'num_of_products' => $num_of_products,
422
+ 'start_index' => $start_index,
423
+ 'end_index' => $start_index + $count,
424
+ 'count' => $count,
425
+ 'ext_version' => (string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version,
426
+ 'mage_version' => Mage::getVersion(),
427
+ 'latency' => $process_time,
428
+ );
429
+ if ($is_single) {
430
+ $args['is_single'] = 1;
431
+ }
432
+
433
+ $response->setBody(json_encode($args));
434
+
435
+ $resp = $helper->sendCurl($checksum_server.'/magento_checksum_iterator?'.http_build_query($args));
436
+
437
+ if ($max_exe_time != -1) { // restore php max execution time
438
+ ini_set('max_execution_time', $max_exe_time);
439
+ }
440
+ }
441
+
442
+ public function connectionAction()
443
+ {
444
+ $this->getResponse()->setBody(1);
445
+ }
446
+
447
+ public function changeSerpAction()
448
+ {
449
+ $scope_name = 'stores';
450
+ $request = $this->getRequest();
451
+ $response = $this->getResponse();
452
+
453
+ $helper = Mage::helper('autocompleteplus_autosuggest');
454
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
455
+ $is_new_serp = $request->getParam('new_serp', 0);
456
+
457
+ $store_id = $request->getParam('store_id', 0);
458
+ if (!$store_id) {
459
+ $scope_name = 'default';
460
+ }
461
+
462
+ define('SOAP_WSDL', $site_url.'/api/?wsdl');
463
+ define('SOAP_USER', 'instant_search');
464
+ define('SOAP_PASS', 'Rilb@kped3');
465
+
466
+ try {
467
+ $client = new SoapClient(SOAP_WSDL, array('trace' => 1, 'cache_wsdl' => 0));
468
+ $session = $client->login(SOAP_USER, SOAP_PASS);
469
+
470
+ switch ($is_new_serp) {
471
+
472
+ case 'status':
473
+ $current_state = $client->call($session, 'autocompleteplus_autosuggest.getLayeredSearchConfig', array($store_id));
474
+ $resp = array('current_status' => $current_state);
475
+ $response->setBody(json_encode($resp));
476
+
477
+ return;
478
+
479
+ case '1':
480
+ $status = $client->call($session, 'autocompleteplus_autosuggest.setLayeredSearchOn', array($scope_name, $store_id));
481
+ break;
482
+ default:
483
+ $status = $client->call($session, 'autocompleteplus_autosuggest.setLayeredSearchOff', array($scope_name, $store_id));
484
+ break;
485
+ }
486
+
487
+ $new_state = $client->call($session, 'autocompleteplus_autosuggest.getLayeredSearchConfig', array($store_id));
488
+
489
+ $resp = array(
490
+ 'request_state' => $is_new_serp,
491
+ 'new_state' => $new_state,
492
+ 'site_url' => $site_url,
493
+ 'status' => $status,
494
+ );
495
+
496
+ $response->setBody(json_encode($resp));
497
+ } catch (Exception $e) {
498
+ $resp = array('status' => 'exception: '.print_r($e, true));
499
+ $response->setBody(json_encode($resp));
500
+ Mage::logException($e);
501
+ throw $e;
502
+ }
503
+ }
504
+
505
+ public function pushbulkAction()
506
+ {
507
+ $request = $this->getRequest();
508
+ $response = $this->getResponse();
509
+ $helper = Mage::helper('autocompleteplus_autosuggest');
510
+
511
+ $pushId = $request->getParam('pushid', null);
512
+ $response->clearHeaders();
513
+ $response->setHeader('Content-type', 'application/json');
514
+ $catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
515
+ $count = 100;
516
+ $server_url = $helper->getServerUrl();
517
+ $cmd_url = $server_url.'/magento_fetch_products';
518
+
519
+ if (!$pushId) {
520
+ $returnArr = array(
521
+ 'success' => self::MISSING_PARAMETER,
522
+ 'message' => $this->__('Missing push id!'),
523
+ );
524
+
525
+ $response->setHttpResponseCode(400);
526
+ $response->setBody(json_encode($returnArr));
527
+
528
+ return;
529
+ }
530
+
531
+ $pusher = Mage::getModel('autocompleteplus_autosuggest/pusher')->load($pushid);
532
+ $sent = $pusher->getSent();
533
+
534
+ switch ($sent) {
535
+ case self::PUSH_IN_PROGRESS:
536
+ $responseArr = array('success' => false, 'message' => $this->__('push is in process'));
537
+ $response->setBody(json_encode($responseArr));
538
+
539
+ return;
540
+ case self::PUSH_COMPLETE:
541
+ $responseArr = array('success' => false, 'message' => $this->__('push was already sent'));
542
+ $response->setBody(json_encode($responseArr));
543
+
544
+ return;
545
+ default:
546
+ $pusher->setSent(1)->save();
547
+ break;
548
+ }
549
+
550
+ $offset = $pusher->getoffset();
551
+ $storeId = $pusher->getstore_id();
552
+ $to_send = $pusher->getto_send();
553
+ $total_batches = $pusher->gettotal_batches();
554
+
555
+ $xml = $catalogModel->renderCatalogXml($offset, $count, $storeId, '', '', '');
556
+
557
+ $url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
558
+
559
+ // setting post data and command url
560
+ $data = array(
561
+ 'uuid' => $this->_getConfig()->getUUID(),
562
+ 'site_url' => $url,
563
+ 'store_id' => $storeId,
564
+ 'authentication_key' => $this->_getConfig()->getAuthenticationKey(),
565
+ 'total_batches' => $total_batches,
566
+ 'batch_number' => $pusher->getbatch_number(),
567
+ 'products' => $xml,
568
+ );
569
+
570
+ if ($offset + $count > $to_send) {
571
+ $data['is_last'] = 1;
572
+ $count = $to_send - $offset;
573
+ }
574
+
575
+ // sending products
576
+ $postResponseMessage = $helper->sendPostCurl($cmd_url, $data);
577
+
578
+ if ($postResponseMessage != self::POST_MESSAGE_OK) {
579
+ $responseArr = array(
580
+ 'success' => false,
581
+ 'message' => $postResponseMessage,
582
+ );
583
+
584
+ $response->setBody(json_encode($responseArr));
585
+
586
+ return;
587
+ }
588
+
589
+ $pusher->setSent(2)->save();
590
+ $nextPushId = $helper->getPushId();
591
+
592
+ $totalPushes = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->getSize();
593
+
594
+ $responseArr = array(
595
+ 'success' => true,
596
+ 'updatedStatus' => $this->__('Syncing: push %s/%s', $nextPushId, $totalPushes),
597
+ 'updatedSuccessStatus' => $this->__('Successfully synced %s products', $count),
598
+ 'message' => '',
599
+ 'nextPushUrl' => $nextPushId ? $helper->getPushUrl($nextPushId) : '',
600
+ 'count' => $count,
601
+ );
602
+
603
+ $response->setBody(json_encode($responseArr));
604
+ }
605
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsbyidController.php CHANGED
@@ -1,71 +1,62 @@
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
+ *
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 Autocompleteplus_Autosuggest_Controller_Abstract
17
+ {
18
+ public function getbyidAction()
19
+ {
20
+ $request = $this->getRequest();
21
+ $response = $this->getResponse();
22
+ $storeId = $request->getParam('store', 1);
23
+ $id = $request->getParam('id');
24
+
25
+ if (!$id) {
26
+ $returnArr = array(
27
+ 'status' => self::STATUS_FAILURE,
28
+ 'error_code' => self::MISSING_PARAMETER,
29
+ 'error_details' => $this->__('The "id" parameter is mandatory'),
30
+ );
31
+ $response->setHeader('Content-type', 'application/json');
32
+ $response->setHttpResponseCode(400);
33
+ $response->setBody(json_encode($returnArr));
34
+
35
+ return;
36
+ }
37
+
38
+ $ids = explode(',', $id);
39
+ $catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
40
+ $xml = $catalogModel->renderCatalogByIds($ids, $storeId);
41
+
42
+ $response->clearHeaders();
43
+ $response->setHeader('Content-type', 'text/xml');
44
+ $response->setBody($xml);
45
+ }
46
+
47
+ public function getfromidAction()
48
+ {
49
+ $request = $this->getRequest();
50
+ $response = $this->getResponse();
51
+ $fromId = $request->getParam('id', 0);
52
+ $storeId = $request->getParam('store', 1);
53
+ $count = $request->getParam('count', 100);
54
+
55
+ $catalogModel = Mage::getModel('autocompleteplus_autosuggest/catalog');
56
+ $xml = $catalogModel->renderCatalogFromIds($count, $fromId, $storeId);
57
+
58
+ $response->clearHeaders();
59
+ $response->setHeader('Content-type', 'text/xml');
60
+ $response->setBody($xml);
61
+ }
62
+ }
 
 
 
 
 
 
 
 
 
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/controllers/SearchesController.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,15 +9,15 @@
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_SearchesController extends Mage_Core_Controller_Front_Action
18
  {
19
- public function sendAction(){
20
-
21
- set_time_limit (1800);
22
 
23
  $post = $this->getRequest()->getParams();
24
 
@@ -27,90 +26,84 @@ class Autocompleteplus_Autosuggest_SearchesController extends Mage_Core_Controll
27
  // die('The user has disabled autocompleteplus.');
28
  // }
29
 
30
-
31
- $startInd = $post['offset'];
32
- if(!$startInd){
33
- $startInd=0;
34
  }
35
 
36
- $count = $post['count'];
37
 
38
  //maxim products on one page is 10000
39
- if(!$count||$count>10000){
40
- $count=10000;
41
  }
42
  //retrieving page number
43
 
44
  //retrieving products collection to check if the offset is not bigger that the product count
45
- $collection=Mage::getModel('catalogsearch/query')->getCollection();
46
 
47
- $searchesCount=$collection->count();
48
 
49
  /* since the retreiving of product count will load the entire collection of products,
50
  * we need to annul it in order to get the specified page only
51
  */
52
  unset($collection);
53
 
54
- $xml='<?xml version="1.0"?>';
55
- $xml.='<searches>';
56
 
57
- if($searchesCount<$startInd){
58
  //if the products count is smaller then specified offset then we return empty xml node
59
- $xml.='</searches>';
60
  echo $xml;
61
  die;
62
-
63
  }
64
 
65
- $connection = $this->_getConnection('core_write');
66
- $sql ="SELECT * FROM " . $this->_getTableName('catalogsearch_query'). " ORDER BY `popularity` DESC LIMIT ".$startInd.", ".$count;
67
- $searches=$connection->fetchAll($sql);
68
 
69
  //setting page+products on the page
70
 
71
-
72
  foreach ($searches as $search) {
 
 
 
73
 
74
- $search_term=htmlspecialchars($search['query_text']);
75
- $search_term=$this->_xmlEscape($search_term);
76
- $popularity=$search['popularity'];
77
-
78
- $row='<search term="'.$search_term.'" count="'.$popularity.'" ></search>';
79
- $xml.=$row;
80
  }
81
 
82
- $xml.='</searches>';
83
-
84
  header('Content-type: text/xml');
85
  echo $xml;
86
  die;
87
-
88
  }
89
 
90
- private function _xmlEscape($term){
91
-
92
- $arr=array(
93
- '&'=>'&amp;',
94
- '"'=>'&quot;',
95
- '<'=>'&lt;',
96
- '>'=>'&gt;'
97
  );
98
 
99
- foreach($arr as $key=>$val){
100
- $term=str_replace($key,$val,$term);
101
  }
102
 
103
  return $term;
104
-
105
  }
106
 
107
- protected function _getConnection($type = 'core_read'){
 
108
  return Mage::getSingleton('core/resource')->getConnection($type);
109
  }
110
 
111
- protected function _getTableName($tableName){
 
112
  return Mage::getSingleton('core/resource')->getTableName($tableName);
113
  }
114
  }
115
-
116
-
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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_SearchesController extends Mage_Core_Controller_Front_Action
17
  {
18
+ public function sendAction()
19
+ {
20
+ set_time_limit(1800);
21
 
22
  $post = $this->getRequest()->getParams();
23
 
26
  // die('The user has disabled autocompleteplus.');
27
  // }
28
 
29
+ $startInd = $post['offset'];
30
+ if (!$startInd) {
31
+ $startInd = 0;
 
32
  }
33
 
34
+ $count = $post['count'];
35
 
36
  //maxim products on one page is 10000
37
+ if (!$count || $count > 10000) {
38
+ $count = 10000;
39
  }
40
  //retrieving page number
41
 
42
  //retrieving products collection to check if the offset is not bigger that the product count
43
+ $collection = Mage::getModel('catalogsearch/query')->getCollection();
44
 
45
+ $searchesCount = $collection->count();
46
 
47
  /* since the retreiving of product count will load the entire collection of products,
48
  * we need to annul it in order to get the specified page only
49
  */
50
  unset($collection);
51
 
52
+ $xml = '<?xml version="1.0"?>';
53
+ $xml .= '<searches>';
54
 
55
+ if ($searchesCount < $startInd) {
56
  //if the products count is smaller then specified offset then we return empty xml node
57
+ $xml .= '</searches>';
58
  echo $xml;
59
  die;
 
60
  }
61
 
62
+ $connection = $this->_getConnection('core_write');
63
+ $sql = 'SELECT * FROM '.$this->_getTableName('catalogsearch_query').' ORDER BY `popularity` DESC LIMIT '.$startInd.', '.$count;
64
+ $searches = $connection->fetchAll($sql);
65
 
66
  //setting page+products on the page
67
 
 
68
  foreach ($searches as $search) {
69
+ $search_term = htmlspecialchars($search['query_text']);
70
+ $search_term = $this->_xmlEscape($search_term);
71
+ $popularity = $search['popularity'];
72
 
73
+ $row = '<search term="'.$search_term.'" count="'.$popularity.'" ></search>';
74
+ $xml .= $row;
 
 
 
 
75
  }
76
 
77
+ $xml .= '</searches>';
78
+
79
  header('Content-type: text/xml');
80
  echo $xml;
81
  die;
 
82
  }
83
 
84
+ private function _xmlEscape($term)
85
+ {
86
+ $arr = array(
87
+ '&' => '&amp;',
88
+ '"' => '&quot;',
89
+ '<' => '&lt;',
90
+ '>' => '&gt;',
91
  );
92
 
93
+ foreach ($arr as $key => $val) {
94
+ $term = str_replace($key, $val, $term);
95
  }
96
 
97
  return $term;
 
98
  }
99
 
100
+ protected function _getConnection($type = 'core_read')
101
+ {
102
  return Mage::getSingleton('core/resource')->getConnection($type);
103
  }
104
 
105
+ protected function _getTableName($tableName)
106
+ {
107
  return Mage::getSingleton('core/resource')->getTableName($tableName);
108
  }
109
  }
 
 
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.8</version>
6
  <url>http://autocompleteplus.com/</url>
7
  <modulename>Autocompleteplus_Autosuggest</modulename>
8
  </Autocompleteplus_Autosuggest>
@@ -11,10 +11,10 @@
11
  <models>
12
  <autocompleteplus_autosuggest>
13
  <class>Autocompleteplus_Autosuggest_Model</class>
14
- <resourceModel>autocompleteplus_autosuggest_mysql4</resourceModel>
15
  </autocompleteplus_autosuggest>
16
- <autocompleteplus_autosuggest_mysql4>
17
- <class>Autocompleteplus_Autosuggest_Model_Mysql4</class>
18
  <entities>
19
  <notifications>
20
  <table>autocompleteplus_notifications</table>
@@ -25,8 +25,11 @@
25
  <config>
26
  <table>autocompleteplus_config</table>
27
  </config>
 
 
 
28
  </entities>
29
- </autocompleteplus_autosuggest_mysql4>
30
  <catalogsearch_mysql4>
31
  </catalogsearch_mysql4>
32
  <catalogsearch_resource>
@@ -60,14 +63,6 @@
60
  </autocompleteplus_autosuggest>
61
  </observers>
62
  </controller_action_postdispatch_checkout_onepage_success>
63
- <catalog_controller_product_init>
64
- <observers>
65
- <autocompleteplus_autosuggest>
66
- <class>autocompleteplus_autosuggest/observer</class>
67
- <method>catalog_controller_product_init</method>
68
- </autocompleteplus_autosuggest>
69
- </observers>
70
- </catalog_controller_product_init>
71
  <catalog_product_save_before>
72
  <observers>
73
  <autocompleteplus_autosuggest>
@@ -95,15 +90,6 @@
95
  </autocompleteplus_autosuggest>
96
  </observers>
97
  </adminhtml_controller_catalogrule_prepare_save>
98
- <catalogrule_after_apply>
99
- <observers>
100
- <autocompleteplus_autosuggest>
101
- <type>singleton</type>
102
- <class>autocompleteplus_autosuggest/observer</class>
103
- <method>catalogrule_after_apply</method>
104
- </autocompleteplus_autosuggest>
105
- </observers>
106
- </catalogrule_after_apply>
107
  </events>
108
  <resources>
109
  <autosuggest_setup>
@@ -212,6 +198,7 @@
212
  <imagefield>thumbnail</imagefield>
213
  <attributes>1</attributes>
214
  <layered>0</layered>
 
215
  </config>
216
  </autocompleteplus>
217
  </default>
2
  <config>
3
  <modules>
4
  <Autocompleteplus_Autosuggest>
5
+ <version>3.0.0.0</version>
6
  <url>http://autocompleteplus.com/</url>
7
  <modulename>Autocompleteplus_Autosuggest</modulename>
8
  </Autocompleteplus_Autosuggest>
11
  <models>
12
  <autocompleteplus_autosuggest>
13
  <class>Autocompleteplus_Autosuggest_Model</class>
14
+ <resourceModel>autocompleteplus_autosuggest_resource</resourceModel>
15
  </autocompleteplus_autosuggest>
16
+ <autocompleteplus_autosuggest_resource>
17
+ <class>Autocompleteplus_Autosuggest_Model_Resource</class>
18
  <entities>
19
  <notifications>
20
  <table>autocompleteplus_notifications</table>
25
  <config>
26
  <table>autocompleteplus_config</table>
27
  </config>
28
+ <batches>
29
+ <table>autocompleteplus_batches</table>
30
+ </batches>
31
  </entities>
32
+ </autocompleteplus_autosuggest_resource>
33
  <catalogsearch_mysql4>
34
  </catalogsearch_mysql4>
35
  <catalogsearch_resource>
63
  </autocompleteplus_autosuggest>
64
  </observers>
65
  </controller_action_postdispatch_checkout_onepage_success>
 
 
 
 
 
 
 
 
66
  <catalog_product_save_before>
67
  <observers>
68
  <autocompleteplus_autosuggest>
90
  </autocompleteplus_autosuggest>
91
  </observers>
92
  </adminhtml_controller_catalogrule_prepare_save>
 
 
 
 
 
 
 
 
 
93
  </events>
94
  <resources>
95
  <autosuggest_setup>
198
  <imagefield>thumbnail</imagefield>
199
  <attributes>1</attributes>
200
  <layered>0</layered>
201
+ <api_endpoint><![CDATA[http://magento.instantsearchplus.com]]></api_endpoint>
202
  </config>
203
  </autocompleteplus>
204
  </default>
app/code/local/Autocompleteplus/Autosuggest/etc/config_no_fulltext.xml DELETED
@@ -1,214 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Autocompleteplus_Autosuggest>
5
- <version>2.0.7.8</version>
6
- <url>http://autocompleteplus.com/</url>
7
- <modulename>Autocompleteplus_Autosuggest</modulename>
8
- </Autocompleteplus_Autosuggest>
9
- </modules>
10
- <global>
11
- <models>
12
- <autocompleteplus_autosuggest>
13
- <class>Autocompleteplus_Autosuggest_Model</class>
14
- <resourceModel>autocompleteplus_autosuggest_mysql4</resourceModel>
15
- </autocompleteplus_autosuggest>
16
- <autocompleteplus_autosuggest_mysql4>
17
- <class>Autocompleteplus_Autosuggest_Model_Mysql4</class>
18
- <entities>
19
- <notifications>
20
- <table>autocompleteplus_notifications</table>
21
- </notifications>
22
- </entities>
23
- </autocompleteplus_autosuggest_mysql4>
24
- <!-- <catalogsearch_mysql4>
25
- <rewrite>
26
- <fulltext_collection>Autocompleteplus_Autosuggest_Model_Mysql4_Fulltext_Collection</fulltext_collection>
27
- </rewrite>
28
- </catalogsearch_mysql4>
29
- <catalogsearch_resource>
30
- <rewrite>
31
- <fulltext_collection>Autocompleteplus_Autosuggest_Model_Resource_Fulltext_Collection</fulltext_collection>
32
- </rewrite>
33
- </catalogsearch_resource> -->
34
- <!--<catalogsearch>
35
- <rewrite>
36
- <layer>Autocompleteplus_Autosuggest_Model_Layer</layer>
37
- </rewrite>
38
- </catalogsearch>-->
39
- </models>
40
- <events>
41
- <catalog_controller_product_init>
42
- <observers>
43
- <autocompleteplus_autosuggest>
44
- <class>autocompleteplus_autosuggest/observer</class>
45
- <method>catalog_controller_product_init</method>
46
- </autocompleteplus_autosuggest>
47
- </observers>
48
- </catalog_controller_product_init>
49
- <catalog_product_save_before>
50
- <observers>
51
- <autocompleteplus_autosuggest>
52
- <type>singleton</type>
53
- <class>autocompleteplus_autosuggest/observer</class>
54
- <method>catalog_product_save_after</method>
55
- </autocompleteplus_autosuggest>
56
- </observers>
57
- </catalog_product_save_before>
58
- <catalog_product_delete_before>
59
- <observers>
60
- <autocompleteplus_autosuggest>
61
- <type>singleton</type>
62
- <class>autocompleteplus_autosuggest/observer</class>
63
- <method>catalog_product_delete_before</method>
64
- </autocompleteplus_autosuggest>
65
- </observers>
66
- </catalog_product_delete_before>
67
- <adminhtml_controller_catalogrule_prepare_save>
68
- <observers>
69
- <autocompleteplus_autosuggest>
70
- <type>singleton</type>
71
- <class>autocompleteplus_autosuggest/observer</class>
72
- <method>adminhtml_controller_catalogrule_prepare_save</method>
73
- </autocompleteplus_autosuggest>
74
- </observers>
75
- </adminhtml_controller_catalogrule_prepare_save>
76
- <catalogrule_after_apply>
77
- <observers>
78
- <autocompleteplus_autosuggest>
79
- <type>singleton</type>
80
- <class>autocompleteplus_autosuggest/observer</class>
81
- <method>catalogrule_after_apply</method>
82
- </autocompleteplus_autosuggest>
83
- </observers>
84
- </catalogrule_after_apply>
85
- <admin_session_user_login_success>
86
- <observers>
87
- <autocompleteplus_autosuggest>
88
- <class>Autocompleteplus_Autosuggest_Model_Observer</class>
89
- <method>adminSessionUserLoginSuccess</method>
90
- </autocompleteplus_autosuggest>
91
- </observers>
92
- </admin_session_user_login_success>
93
- </events>
94
- <resources>
95
- <autosuggest_setup>
96
- <setup>
97
- <module>Autocompleteplus_Autosuggest</module>
98
- </setup>
99
- <connection>
100
- <use>core_setup</use>
101
- </connection>
102
- </autosuggest_setup>
103
- <autosuggest_write>
104
- <connection>
105
- <use>core_write</use>
106
- </connection>
107
- </autosuggest_write>
108
- <autosuggest_read>
109
- <connection>
110
- <use>core_read</use>
111
- </connection>
112
- </autosuggest_read>
113
- </resources>
114
- <blocks>
115
- <autocompleteplus_autosuggest>
116
- <class>Autocompleteplus_Autosuggest_Block</class>
117
- </autocompleteplus_autosuggest>
118
- </blocks>
119
- <template>
120
- <email>
121
- <autosuggest_status_notification module="autocompleteplus_autosuggest">
122
- <label>Autocompleteplus status notification</label>
123
- <file>autocompleteplus/status_notification.html</file>
124
- <type>html</type>
125
- </autosuggest_status_notification>
126
- </email>
127
- </template>
128
- <helpers>
129
- <autocompleteplus_autosuggest>
130
- <class>Autocompleteplus_Autosuggest_Helper</class>
131
- </autocompleteplus_autosuggest>
132
- </helpers>
133
- </global>
134
- <frontend>
135
- <layout>
136
- <updates>
137
- <autosuggest>
138
- <file>autocompleteplus.xml</file>
139
- </autosuggest>
140
- </updates>
141
- </layout>
142
- <routers>
143
- <autocompleteplus>
144
- <use>standard</use>
145
- <args>
146
- <module>Autocompleteplus_Autosuggest</module>
147
- <frontName>autocompleteplus</frontName>
148
- </args>
149
- </autocompleteplus>
150
- <catalogsearch>
151
- <args>
152
- <modules>
153
- <Autocompleteplus_Autosuggest before="Mage_CatalogSearch">Autocompleteplus_Autosuggest_CatalogSearch</Autocompleteplus_Autosuggest>
154
- </modules>
155
- </args>
156
- </catalogsearch>
157
- </routers>
158
- </frontend>
159
- <admin>
160
- <routers>
161
- <autocompleteplus>
162
- <use>admin</use>
163
- <args>
164
- <module>Autocompleteplus_Autosuggest</module>
165
- <frontName>autocompleteplus</frontName>
166
- </args>
167
- </autocompleteplus>
168
- </routers>
169
- </admin>
170
- <adminhtml>
171
- <acl>
172
- <resources>
173
- <admin>
174
- <children>
175
- <system>
176
- <children>
177
- <config>
178
- <children>
179
- <autocompleteplus translate="label" module="autocompleteplus_autosuggest">
180
- <title>AutocompletePlus</title>
181
- </autocompleteplus>
182
- </children>
183
- </config>
184
- </children>
185
- </system>
186
- </children>
187
- </admin>
188
- </resources>
189
- </acl>
190
- <menu>
191
- <autocompleteplus>
192
- <title>InstantSearch+</title>
193
- <sort_order>999</sort_order>
194
- <action>adminhtml/autocompleteplus_redirect/goto</action>
195
- </autocompleteplus>
196
- </menu>
197
- <layout>
198
- <updates>
199
- <autosuggest>
200
- <file>autocompleteplus.xml</file>
201
- </autosuggest>
202
- </updates>
203
- </layout>
204
- </adminhtml>
205
- <default>
206
- <autocompleteplus>
207
- <config>
208
- <imagefield>thumbnail</imagefield>
209
- <attributes>1</attributes>
210
- <layered>0</layered>
211
- </config>
212
- </autocompleteplus>
213
- </default>
214
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/etc/config_with_crontab.xml DELETED
@@ -1,205 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Autocompleteplus_Autosuggest>
5
- <version>2.0.6.6</version>
6
- <url>http://autocompleteplus.com/</url>
7
- <modulename>Autocompleteplus_Autosuggest</modulename>
8
- </Autocompleteplus_Autosuggest>
9
- </modules>
10
- <global>
11
- <rewrite>
12
- <!--<autocompleteplus_autosuggest_catalogsearch>
13
- <from><![CDATA[#^/catalogsearch/result/#]]></from>
14
- <to>/autocompleteplus/catalogsearch/</to>
15
- </autocompleteplus_autosuggest_catalogsearch>-->
16
- </rewrite>
17
- <models>
18
- <autocompleteplus_autosuggest>
19
- <class>Autocompleteplus_Autosuggest_Model</class>
20
- <resourceModel>autocompleteplus_autosuggest_mysql4</resourceModel>
21
- </autocompleteplus_autosuggest>
22
- <autocompleteplus_autosuggest_mysql4>
23
- <class>Autocompleteplus_Autosuggest_Model_Mysql4</class>
24
- <entities>
25
- <notifications>
26
- <table>autocompleteplus_notifications</table>
27
- </notifications>
28
- <pusher>
29
- <table>autocompleteplus_pusher</table>
30
- </pusher>
31
- <config>
32
- <table>autocompleteplus_config</table>
33
- </config>
34
- </entities>
35
- </autocompleteplus_autosuggest_mysql4>
36
- <catalogsearch_mysql4>
37
- <rewrite>
38
- <!--<fulltext_collection>Autocompleteplus_Autosuggest_Model_Mysql4_Fulltext_Collection</fulltext_collection>-->
39
- </rewrite>
40
- </catalogsearch_mysql4>
41
- <catalogsearch_resource>
42
- <rewrite>
43
- <fulltext_collection>Autocompleteplus_Autosuggest_Model_Resource_Fulltext_Collection</fulltext_collection>
44
- </rewrite>
45
- </catalogsearch_resource>
46
- <!--<catalogsearch>
47
- <rewrite>
48
- <layer>Autocompleteplus_Autosuggest_Model_Layer</layer>
49
- </rewrite>
50
- </catalogsearch>-->
51
- </models>
52
- <events>
53
- <catalog_controller_product_init>
54
- <observers>
55
- <autocompleteplus_autosuggest>
56
- <class>autocompleteplus_autosuggest/observer</class>
57
- <method>catalog_controller_product_init</method>
58
- </autocompleteplus_autosuggest>
59
- </observers>
60
- </catalog_controller_product_init>
61
- <catalog_product_save_before>
62
- <observers>
63
- <autocompleteplus_autosuggest>
64
- <type>singleton</type>
65
- <class>autocompleteplus_autosuggest/observer</class>
66
- <method>catalog_product_save_after</method>
67
- </autocompleteplus_autosuggest>
68
- </observers>
69
- </catalog_product_save_before>
70
- <catalog_product_delete_before>
71
- <observers>
72
- <autocompleteplus_autosuggest>
73
- <type>singleton</type>
74
- <class>autocompleteplus_autosuggest/observer</class>
75
- <method>catalog_product_delete_before</method>
76
- </autocompleteplus_autosuggest>
77
- </observers>
78
- </catalog_product_delete_before>
79
- <adminhtml_controller_catalogrule_prepare_save>
80
- <observers>
81
- <autocompleteplus_autosuggest>
82
- <type>singleton</type>
83
- <class>autocompleteplus_autosuggest/observer</class>
84
- <method>adminhtml_controller_catalogrule_prepare_save</method>
85
- </autocompleteplus_autosuggest>
86
- </observers>
87
- </adminhtml_controller_catalogrule_prepare_save>
88
- <catalogrule_after_apply>
89
- <observers>
90
- <autocompleteplus_autosuggest>
91
- <type>singleton</type>
92
- <class>autocompleteplus_autosuggest/observer</class>
93
- <method>catalogrule_after_apply</method>
94
- </autocompleteplus_autosuggest>
95
- </observers>
96
- </catalogrule_after_apply>
97
- <admin_session_user_login_success>
98
- <observers>
99
- <autocompleteplus_autosuggest>
100
- <class>Autocompleteplus_Autosuggest_Model_Observer</class>
101
- <method>adminSessionUserLoginSuccess</method>
102
- </autocompleteplus_autosuggest>
103
- </observers>
104
- </admin_session_user_login_success>
105
- </events>
106
- <resources>
107
- <autosuggest_setup>
108
- <setup>
109
- <module>Autocompleteplus_Autosuggest</module>
110
- </setup>
111
- <connection>
112
- <use>core_setup</use>
113
- </connection>
114
- </autosuggest_setup>
115
- <autosuggest_write>
116
- <connection>
117
- <use>core_write</use>
118
- </connection>
119
- </autosuggest_write>
120
- <autosuggest_read>
121
- <connection>
122
- <use>core_read</use>
123
- </connection>
124
- </autosuggest_read>
125
- </resources>
126
- <blocks>
127
- <autocompleteplus_autosuggest>
128
- <class>Autocompleteplus_Autosuggest_Block</class>
129
- </autocompleteplus_autosuggest>
130
- </blocks>
131
- <template>
132
- <email>
133
- <autosuggest_status_notification module="autocompleteplus_autosuggest">
134
- <label>Autocompleteplus status notification</label>
135
- <file>autocompleteplus/status_notification.html</file>
136
- <type>html</type>
137
- </autosuggest_status_notification>
138
- </email>
139
- </template>
140
- <helpers>
141
- <autocompleteplus_autosuggest>
142
- <class>Autocompleteplus_Autosuggest_Helper</class>
143
- </autocompleteplus_autosuggest>
144
- </helpers>
145
- </global>
146
- <frontend>
147
- <layout>
148
- <updates>
149
- <autosuggest>
150
- <file>autocompleteplus.xml</file>
151
- </autosuggest>
152
- </updates>
153
- </layout>
154
- <routers>
155
- <autocompleteplus>
156
- <use>standard</use>
157
- <args>
158
- <module>Autocompleteplus_Autosuggest</module>
159
- <frontName>autocompleteplus</frontName>
160
- </args>
161
- </autocompleteplus>
162
- </routers>
163
- </frontend>
164
- <adminhtml>
165
- <acl>
166
- <resources>
167
- <admin>
168
- <children>
169
- <system>
170
- <children>
171
- <config>
172
- <children>
173
- <autocompleteplus translate="label" module="autocompleteplus_autosuggest">
174
- <title>AutocompletePlus</title>
175
- </autocompleteplus>
176
- </children>
177
- </config>
178
- </children>
179
- </system>
180
- </children>
181
- </admin>
182
- </resources>
183
- </acl>
184
- </adminhtml>
185
- <default>
186
- <autocompleteplus>
187
- <config>
188
- <imagefield>thumbnail</imagefield>
189
- <attributes>1</attributes>
190
- </config>
191
- </autocompleteplus>
192
- </default>
193
- <crontab>
194
- <jobs>
195
- <autocompleteplus_autosuggest_toSend>
196
- <schedule>
197
- <cron_expr>*/2 * * * *</cron_expr>
198
- </schedule>
199
- <run>
200
- <model>autocompleteplus_autosuggest/service::toSend</model>
201
- </run>
202
- </autocompleteplus_autosuggest_toSend>
203
- </jobs>
204
- </crontab>
205
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-install-2.0.1.1.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,21 +9,17 @@
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
 
18
- $helper=Mage::helper('autocompleteplus_autosuggest');
19
-
20
- Mage::log('mysql4-install-2.0.1.1.php triggered',null,'autocomplete.log',true);
21
 
22
  //getting site owner email
23
- $storeMail=$helper->getConfigDataByFullPath('trans_email/ident_general/email');
24
- Mage::log($storeMail,null,'autocomplete.log');
25
- Mage::getModel('core/config')->saveConfig('autocompleteplus/config/store_email', $storeMail );
26
-
27
- Mage::getModel('core/config')->saveConfig('autocompleteplus/config/enabled', 1 );
28
-
29
 
30
- ?>
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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
+ $helper = Mage::helper('autocompleteplus_autosuggest');
17
 
18
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
 
 
19
 
20
  //getting site owner email
21
+ $storeMail = $helper->getConfigDataByFullPath('trans_email/ident_general/email');
22
+ Mage::log($storeMail, null, 'autocomplete.log');
23
+ Mage::getModel('core/config')->saveConfig('autocompleteplus/config/store_email', $storeMail);
 
 
 
24
 
25
+ Mage::getModel('core/config')->saveConfig('autocompleteplus/config/enabled', 1);
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.1.3-2.0.2.2.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,40 +9,24 @@
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
-
18
  $installer = $this;
19
-
20
  $installer->startSetup();
21
 
22
- $res=$installer->run("
23
-
24
  DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_batches')};
25
-
26
  CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_batches')} (
27
-
28
  `id` int(11) NOT NULL auto_increment,
29
-
30
  `product_id` INT NULL,
31
-
32
  `store_id` INT NOT NULL,
33
-
34
  `update_date` INT DEFAULT NULL,
35
-
36
  `action` VARCHAR( 255 ) NOT NULL,
37
-
38
  `sku` VARCHAR( 255 ) NOT NULL,
39
-
40
  PRIMARY KEY (`id`)
 
41
 
42
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
43
-
44
- ");
45
-
46
- Mage::log('mysql4-upgrade-2.0.1.3-2.0.2.2.php triggered',null,'autocomplete.log',true);
47
  $installer->endSetup();
48
-
49
- ?>
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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
  $installer = $this;
 
17
  $installer->startSetup();
18
 
19
+ $res = $installer->run("
 
20
  DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_batches')};
 
21
  CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_batches')} (
 
22
  `id` int(11) NOT NULL auto_increment,
 
23
  `product_id` INT NULL,
 
24
  `store_id` INT NOT NULL,
 
25
  `update_date` INT DEFAULT NULL,
 
26
  `action` VARCHAR( 255 ) NOT NULL,
 
27
  `sku` VARCHAR( 255 ) NOT NULL,
 
28
  PRIMARY KEY (`id`)
29
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
30
 
31
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
 
 
 
 
32
  $installer->endSetup();
 
 
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.2.5-2.0.2.6.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,7 +9,7 @@
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
  */
@@ -34,5 +33,5 @@ CREATE TABLE IF NOT EXISTS `{$installer->getTable('autocompleteplus_autosuggest/
34
  KEY `IDX_IS_ACTIVE` (`is_active`)
35
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
36
  ");
37
- Mage::log('mysql4-upgrade-2.0.2.5-2.0.2.6.php',null,'autocomplete.log',true);
38
- $installer->endSetup();
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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
  */
33
  KEY `IDX_IS_ACTIVE` (`is_active`)
34
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
35
  ");
36
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
37
+ $installer->endSetup();
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.4.6-2.0.4.7.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /**
3
- * InstantSearchPlus (Autosuggest)
4
-
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -10,7 +9,7 @@
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
  */
@@ -18,7 +17,7 @@ $installer = $this;
18
 
19
  $installer->startSetup();
20
 
21
- $res=$installer->run("
22
 
23
  DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_checksum')};
24
 
@@ -38,5 +37,5 @@ CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_checksum')} (
38
 
39
  ");
40
 
41
- Mage::log('mysql4-upgrade-2.0.4.6-2.0.4.7.php triggered',null,'autocomplete.log',true);
42
  $installer->endSetup();
1
  <?php
2
  /**
3
+ * InstantSearchPlus (Autosuggest).
 
4
  *
5
  * NOTICE OF LICENSE
6
  *
9
  * http://opensource.org/licenses/osl-3.0.php
10
  *
11
  * @category Mage
12
+ *
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
  */
17
 
18
  $installer->startSetup();
19
 
20
+ $res = $installer->run("
21
 
22
  DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_checksum')};
23
 
37
 
38
  ");
39
 
40
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
41
  $installer->endSetup();
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.4-2.0.5.5.php CHANGED
@@ -1,11 +1,16 @@
1
  <?php
 
2
  $installer = $this;
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
 
@@ -32,87 +37,65 @@ if (!method_exists('Mage' , 'getEdition') && file_exists('LICENSE_EE.txt') && me
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
-
1
  <?php
2
+
3
  $installer = $this;
4
 
5
  $installer->startSetup();
6
+ $fileIo = new Varien_Io_File();
7
+ $fileIo->open(array('path' => Mage::getBaseDir()));
8
 
9
  // 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
10
+ if (!method_exists('Mage', 'getEdition') && $fileIo->isValid('LICENSE_EE.txt') && method_exists('Mage',
11
+ 'getVersion') && version_compare(Mage::getVersion(), '1.10.0.0.', '<') === true
12
+ ) {
13
+ $res = $installer->run("
14
 
15
  DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_pusher')};
16
 
37
  ");
38
  } else {
39
  $table = $installer->getConnection()->newTable($installer->getTable('autocompleteplus_autosuggest/pusher'))
 
40
  ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
41
+
42
  'identity' => true,
43
+
44
  'unsigned' => true,
45
+
46
  'nullable' => false,
47
+
48
+ 'primary' => true,
49
+
50
  ), 'Id')
 
51
  ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
52
+
53
  'nullable' => false,
54
+
55
+ 'unsigned' => true,
56
+
57
  ))
 
58
  ->addColumn('to_send', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
59
+
60
  'nullable' => false,
61
+
62
+ 'unsigned' => true,
63
+
64
  ), 'Amount left to send')
 
65
  ->addColumn('offset', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
66
+
67
  'nullable' => false,
68
+
69
+ 'unsigned' => true,
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
  ->addColumn('batch_number', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
80
+
81
  'nullable' => false,
82
+
83
+ 'unsigned' => true,
84
+
85
  ))
 
86
  ->addColumn('sent', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
87
+
88
  'nullable' => false,
89
+
90
+ 'unsigned' => true,
91
+
92
  ));
93
+
 
 
 
 
 
 
 
 
 
 
94
  if ($installer->getConnection()->isTableExists($table->getName())) {
 
95
  $installer->getConnection()->dropTable($table->getName());
 
96
  }
97
+
 
 
98
  $installer->getConnection()->createTable($table);
99
  }
100
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
101
  $installer->endSetup();
 
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.6-2.0.5.7.php CHANGED
@@ -1,55 +1,48 @@
1
  <?php
2
- // Creating API user and role
3
- $role_model = Mage::getModel('api/roles');
4
- $roles = $role_model->getCollection()->getData();
5
- $user_model = Mage::getModel('api/user');
6
- $users = $user_model->getCollection()->getData();
7
-
8
- $role_name = 'InstantS';
9
- if (isset($roles)) {
10
- foreach ($roles as $role) {
11
- if ($role['role_name'] == $role_name) {
12
- try {
13
- $role_model->setId($role['role_id'])->delete();
14
- } catch (Exception $e) {
15
- Mage::log($e->getMessage());
16
- }
17
- }
18
- }
19
- }
20
 
21
- $user_name = 'instant_search';
22
- foreach ($users as $user) {
23
- if ($user['username'] == $user_name) {
24
- try {
25
- $user_model->setId($user['user_id'])->delete();
26
- } catch (Exception $e) {
27
- Mage::log($e->getMessage());
28
- }
29
- }
 
 
 
 
 
 
 
30
  }
31
 
32
- $role_model = Mage::getModel('api/roles');
33
- $user_model = Mage::getModel('api/user');
 
 
34
 
35
- $role_model->setName($role_name)->setPid(false)->setRoleType('G')->save();
36
 
37
- $role_id = $role_model->getId();
38
 
39
- Mage::getModel("api/rules")->setRoleId($role_id)->setResources(array('all'))->saveRel();
40
 
41
- $user_model->setData(array(
42
- 'username' => $user_name,
43
- 'firstname' => 'instant',
44
- 'lastname' => 'search',
45
- 'email' => 'owner@example.com',
46
- 'api_key' => 'Rilb@kped3',
47
  'api_key_confirmation' => 'Rilb@kped3',
48
- 'is_active' => 1,
49
- 'user_roles' => '',
50
- 'assigned_user_role' => '',
51
- 'role_name' => '',
52
- 'roles' => array($role_id)
53
  ))->save();
54
 
55
- $user_model->setRoleIds(array($role_id))->setRoleUserId($user_model->getUserId())->saveRelations();
 
 
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ $rolesModel = Mage::getModel('api/roles');
4
+ $userModel = Mage::getModel('api/user');
5
+ $apiRoles = $rolesModel->getCollection();
6
+ $apiUsers = $userModel->getCollection();
7
+ $roleName = 'InstantS';
8
+ $userName = 'instant_search';
9
+
10
+ $apiRoles->addFieldToFilter('role_name', $roleName);
11
+ $apiUsers->addFieldToFilter('username', $userName);
12
+
13
+ $apiRoles->getSelect()->limit(1);
14
+ $apiUsers->getSelect()->limit(1);
15
+
16
+ if ($apiRoles->getSize() > 0) {
17
+ // @codingStandardsIgnoreLine
18
+ $apiRoles->getFirstItem()->delete();
19
  }
20
 
21
+ if ($apiUsers->getSize() > 0) {
22
+ // @codingStandardsIgnoreLine
23
+ $apiUsers->getFirstItem()->delete();
24
+ }
25
 
26
+ $rolesModel->setName($roleName)->setPid(false)->setRoleType('G')->save();
27
 
28
+ $roleId = $rolesModel->getId();
29
 
30
+ Mage::getModel('api/rules')->setRoleId($roleId)->setResources(array('all'))->saveRel();
31
 
32
+ $userModel->setData(array(
33
+ 'username' => $userName,
34
+ 'firstname' => 'instant',
35
+ 'lastname' => 'search',
36
+ 'email' => 'owner@example.com',
37
+ 'api_key' => 'Rilb@kped3',
38
  'api_key_confirmation' => 'Rilb@kped3',
39
+ 'is_active' => 1,
40
+ 'user_roles' => '',
41
+ 'assigned_user_role' => '',
42
+ 'role_name' => '',
43
+ 'roles' => array($roleId),
44
  ))->save();
45
 
46
+ $userModel->setRoleIds(array($roleId))->setRoleUserId($userModel->getUserId())->saveRelations();
47
+
48
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.6.1-2.0.6.4.php DELETED
@@ -1,169 +0,0 @@
1
- <?php
2
- $installer = $this;
3
-
4
- $helper = Mage::helper('autocompleteplus_autosuggest');
5
-
6
- //getting site url
7
- $url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
8
-
9
- //getting site owner email
10
- $storeMail = $helper->getConfigDataByFullPath('autocompleteplus/config/store_email');
11
-
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'];
36
- }
37
-
38
- $key='';
39
- $auth_key='';
40
- $is_reachable=0;
41
- $errMsg = '';
42
-
43
- try {
44
- $commandOrig = "http://magento.instantsearchplus.com/install";
45
- $data['multistore'] = $multistoreJson;
46
- if (method_exists('Mage' , 'getEdition')){
47
- $data['edition'] = Mage::getEdition();
48
- } else {
49
- $data['edition'] = 'Unknown';
50
- }
51
- $data['site'] = $url;
52
- $data['email'] = $storeMail;
53
- $data['f'] = '2.0.6.2';
54
-
55
- $auto_arr = json_decode($helper->sendPostCurl($commandOrig, $data), true);
56
-
57
- $key = $auto_arr['uuid'];
58
- $auth_key = $auto_arr['authentication_key'];
59
- if (strlen($key) > 50) {
60
- $key = 'InstallFailedUUID';
61
- }
62
- if(isset($auto_arr['is_reachable'])){
63
- $is_reachable=$auto_arr['is_reachable'];
64
- }
65
-
66
- Mage::log(print_r($auto_arr, true), null, 'autocomplete.log',true);
67
-
68
- if ($key == 'InstallFailedUUID') {
69
- $errMsg .= 'Could not get license string.';
70
- }
71
-
72
- //sending error info
73
- if ($errMsg != '') {
74
-
75
- $command = "http://magento.instantsearchplus.com/install_error";
76
- $data = array();
77
- $data['site'] = $url;
78
- $data['msg'] = $errMsg;
79
- $data['email'] = $storeMail;
80
- //$data['product_count']=$productCount;
81
- $data['multistore'] = $multistoreJson;
82
- $data['f'] = '2.0.6.2';
83
- $res = $helper->sendPostCurl($command, $data);
84
- }
85
-
86
- //getting sitemap.xml
87
- if ($key != '' && $key != 'InstallFailedUUID'){
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);
95
- }else{
96
- //write message that file is not writteble
97
- $command="http://magento.instantsearchplus.com/install_error";
98
- $data=array();
99
- $data['site']=$url;
100
- $data['msg']='File '.$robotsPath.' is not writable.';
101
- $data['f'] = '2.0.6.2';
102
- $res=$helper->sendPostCurl($command,$data);
103
- }
104
- }
105
- }else{
106
- //create file
107
- if(is_writable(Mage::getBaseDir())){
108
- //create robots sitemap
109
- file_put_contents($robotsPath,$stemapUrl);
110
- }else{
111
- //write message that directory is not writteble
112
- $command="http://magento.instantsearchplus.com/install_error";
113
- $data=array();
114
- $data['site']=$url;
115
- $data['msg']='Directory '.Mage::getBaseDir().' is not writable.';
116
- $data['f'] = '2.0.6.2';
117
- $res=$helper->sendPostCurl($command,$data);
118
- }
119
- }
120
- }
121
-
122
- } catch (Exception $e) {
123
- $key = 'failed';
124
- $errMsg = $e->getMessage();
125
- Mage::log('Install failed with a message: ' . $errMsg, null, 'autocomplete.log',true);
126
- $command = "http://magento.instantsearchplus.com/install_error";
127
-
128
- $data = array();
129
- $data['site'] = $url;
130
- $data['msg'] = $errMsg;
131
- $data['original_install_URL'] = $commandOrig;
132
- $data['f'] = '2.0.6.2';
133
- $res = $helper->sendPostCurl($command, $data);
134
- }
135
-
136
-
137
- $installer->startSetup();
138
-
139
- $res=$installer->run("
140
- DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_config')};
141
-
142
- CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_config')} (
143
-
144
- `id` int(11) NOT NULL auto_increment,
145
-
146
- `licensekey` varchar(255) character set utf8 NOT NULL,
147
-
148
- `authkey` varchar(255) character set utf8 NOT NULL,
149
-
150
- `site_url` varchar(255) character set utf8 NOT NULL,
151
-
152
- `is_reachable` TINYINT NOT NULL,
153
-
154
- `errormessage` TEXT character set utf8 NOT NULL,
155
-
156
- `server_type` varchar(255) character set utf8,
157
-
158
- `cdn_cache_key` varchar(255) character set utf8,
159
-
160
- PRIMARY KEY (`id`)
161
-
162
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
163
- ");
164
-
165
- $res = $installer->run("INSERT INTO {$this->getTable('autocompleteplus_config')}
166
- (licensekey,authkey,site_url,is_reachable,errormessage)
167
- VALUES('" . $key . "','" . $auth_key . "','" . $url . "',".$is_reachable.",'".$errMsg."');");
168
-
169
- $installer->endSetup();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.0-2.0.7.1.php CHANGED
@@ -1,7 +1,8 @@
1
  <?php
 
2
  $installer = $this;
3
  $installer->startSetup();
4
 
5
  // $installer->run("ALTER TABLE {$this->getTable('sales/quote_item')} ADD `added_from_search` TINYINT(1) NULL DEFAULT NULL COMMENT 'AutocompletePlus Add Flag';");
6
-
7
  $installer->endSetup();
1
  <?php
2
+
3
  $installer = $this;
4
  $installer->startSetup();
5
 
6
  // $installer->run("ALTER TABLE {$this->getTable('sales/quote_item')} ADD `added_from_search` TINYINT(1) NULL DEFAULT NULL COMMENT 'AutocompletePlus Add Flag';");
7
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
8
  $installer->endSetup();
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.2-2.0.7.3.php CHANGED
@@ -1,58 +1,93 @@
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
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $tableName = $this->getTable('autocompleteplus_batches');
5
+ $columnName = 'update_date';
6
+ $checkColumnType = false;
7
+ $fileIo = new Varien_Io_File();
8
+ $fileIo->open(array('path' => Mage::getBaseDir()));
9
+
10
+ /*
11
+ * Check if getEdition method does not exist in Mage
12
+ * Check if Enterprise Edition license exists in Magento root
13
+ * Check if getVersion method exists in Mage
14
+ * Compare versions to check if less than 1.10.0.0
15
+ */
16
+ if (!method_exists('Mage', 'getEdition') && $fileIo->isValid('LICENSE_EE.txt') && method_exists('Mage', 'getVersion') && version_compare(Mage::getVersion(), '1.10.0.0.', '<') === true) {
17
+ $tableExists = $installer->getConnection()->showTableStatus($tableName);
18
+ } else {
19
+ $tableExists = $installer->getConnection()->isTableExists($tableName);
20
+ }
21
+
22
+ if ($tableExists) {
23
+ try {
24
+ $checkIfExists = $installer->getConnection()->tableColumnExists($tableName, 'update_date');
25
+
26
+ /*
27
+ * Check if table already exists
28
+ */
29
+ if (!$checkIfExists) {
30
+
31
+ /*
32
+ * Check if column 'update_date' is type INT
33
+ */
34
+ $describe = $this->getConnection()->describeTable($tableName);
35
+ foreach ($describe as $column) {
36
+ if ($column['COLUMN_NAME'] == $columnName && $column['DATA_TYPE'] == Varien_Db_Ddl_Table::TYPE_INTEGER) {
37
+ $checkColumnType = true;
38
+ }
39
+ }
40
+
41
+ if (!$checkColumnType) {
42
+ $installer->startSetup();
43
+
44
+ $installer->getConnection()->dropTable($tableName);
45
+ $installer->getConnection()->newTable($tableName)
46
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
47
+ 'identity' => true,
48
+ 'unsigned' => true,
49
+ 'nullable' => false,
50
+ 'primary' => true,
51
+ 'comment' => 'Batch ID',
52
+ ))
53
+ ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
54
+ 'nullable' => false,
55
+ 'comment' => 'Product ID',
56
+ ))
57
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
58
+ 'nullable' => false,
59
+ 'comment' => 'Store ID',
60
+ ))
61
+ ->addColumn('update_date', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
62
+ 'nullable' => true,
63
+ 'comment' => 'Update Time Integer',
64
+ ))
65
+ ->addColumn('action', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
66
+ 'nullable' => false,
67
+ 'comment' => 'Batch Action',
68
+ ))
69
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
70
+ 'nullable' => false,
71
+ 'comment' => 'Product SKU',
72
+ ));
73
+ $installer->endSetup();
74
+ }
75
+ }
76
+ } catch (Exception $e) {
77
+ $errMsg = $e->getMessage();
78
+ Mage::log('Install failed with a message: '.$errMsg, null, 'autocomplete.log', true);
79
+
80
+ $command = 'http://magento.instantsearchplus.com/install_error';
81
+ $helper = Mage::helper('autocompleteplus_autosuggest');
82
+ //getting site url
83
+ $url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
84
+
85
+ $data = array();
86
+ $data['site'] = $url;
87
+ $data['msg'] = $errMsg;
88
+ $data['f'] = '2.0.7.3';
89
+ $res = $helper->sendPostCurl($command, $data);
90
+ }
91
+
92
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
93
+ }
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.8.8-3.0.0.0.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $config = Mage::getModel('autocompleteplus_autosuggest/config');
5
+ $row = false;
6
+ $installer->startSetup();
7
+
8
+ if ($installer->getConnection()->isTableExists($installer->getTable('autocompleteplus_autosuggest/config'))) {
9
+ $select = $installer->getConnection()->select()
10
+ ->from(array('config' => $installer->getTable('autocompleteplus_autosuggest/config')));
11
+ $row = $installer->getConnection()->fetchOne($select);
12
+ $installer->getConnection()->dropTable($installer->getTable('autocompleteplus_autosuggest/config'));
13
+ }
14
+
15
+ if ($row) {
16
+ $config->generateConfig($row['licensekey']);
17
+ } else {
18
+ $config->generateConfig();
19
+ }
20
+
21
+ Mage::app()->getCacheInstance()->cleanType('config');
22
+
23
+ Mage::log(__FILE__ . ' triggered', null, 'autocomplete.log', true);
24
+ $installer->endSetup();
app/design/adminhtml/default/default/template/autocompleteplus/notifications_old.php DELETED
@@ -1,28 +0,0 @@
1
- <?php
2
- /** @var Autocompleteplus_Autosuggest_Block_Notifications $this */
3
- ?>
4
- <?php $notifications = $this->getNotifications(); ?>
5
- <?php if ($notifications->count()): ?>
6
- <?php foreach ($notifications as $notification): ?>
7
- <div id="autosuggest-notification<?php echo $notification->getId() ?>" class="notification-global">
8
- <?php echo $notification->getMessage() ?>.
9
- <a href="#" onclick="autosuggestRemove('<?php echo $notification->getId() ?>'); return false;">
10
- <?php echo $this->__('Remove this notification'); ?>
11
- </a>
12
- </div>
13
- <?php endforeach; ?>
14
- <script type="text/javascript">
15
- function autosuggestRemove(notification_id) {
16
- var url = '<?php echo $this->getUrl('*/autocompleteplus/notification', array('_current' => true)); ?>';
17
- new Ajax.Request(url, {
18
- method: 'post',
19
- parameters: {notification_id: notification_id},
20
- onComplete: function(transport) {
21
- if (200 == transport.status) {
22
- $('autosuggest-notification'+ notification_id).remove();
23
- }
24
- }
25
- });
26
- }
27
- </script>
28
- <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/adminhtml/default/default/template/autocompleteplus/system/config/button.phtml CHANGED
@@ -1,26 +1,20 @@
1
  <script type="text/javascript">
2
  //<![CDATA[
3
  function updateautocomplete() {
 
4
 
5
- var email=$('autocompleteplus_config_store_email').value;
6
-
7
- if(email==undefined || email==''){
8
-
9
- email='no@email.com';
10
- }
11
  new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
12
  method: 'post',
13
- parameters: {email: email},
14
- onSuccess: function(transport){
15
-
16
  if (transport.responseText){
17
  alert(transport.responseText);
18
  configForm.submit();
19
  }
20
- }
21
- });
22
  }
23
  //]]>
24
  </script>
25
-
26
  <?php echo $this->getButtonHtml() ?>
1
  <script type="text/javascript">
2
  //<![CDATA[
3
  function updateautocomplete() {
4
+ var email = $('autocompleteplus_config_store_email').value || ='no@email.com';
5
 
 
 
 
 
 
 
6
  new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
7
  method: 'post',
8
+ parameters: { email: email },
9
+ onSuccess: function( transport ) {
 
10
  if (transport.responseText){
11
  alert(transport.responseText);
12
  configForm.submit();
13
  }
14
+ }
15
+ });
16
  }
17
  //]]>
18
  </script>
19
+
20
  <?php echo $this->getButtonHtml() ?>
app/design/frontend/base/default/layout/autocompleteplus.xml CHANGED
@@ -2,7 +2,7 @@
2
  <layout version="0.1.0">
3
  <default>
4
  <reference name="head">
5
- <block name="inject_new" template="autocompleteplus/inject_new.phtml" type="autocompleteplus_autosuggest/inject"/>
6
  <block type="autocompleteplus_autosuggest/autocomplete" />
7
  </reference>
8
  </default>
@@ -26,7 +26,6 @@
26
  <remove name="search.result"/>
27
  <remove name="left"/>
28
  <reference name="content">
29
- <!-- <block type="catalog/product_list" name="search_result_list" template="autocompleteplus/catalog/product/list.phtml"/> -->
30
  <block type="core/template" name="search_result_list" template="autocompleteplus/catalog/product/list.phtml"/>
31
  </reference>
32
  </autocompleteplus_result_index>
@@ -35,8 +34,7 @@
35
  <remove name="search.result"/>
36
  <remove name="left"/>
37
  <reference name="content">
38
- <!-- <block type="catalog/product_list" name="search_result_list" template="autocompleteplus/catalog/product/list.phtml"/> -->
39
  <block type="core/template" name="search_result_list" template="autocompleteplus/catalog/product/list.phtml"/>
40
  </reference>
41
  </instantsearchplus_result_index>
42
- </layout>
2
  <layout version="0.1.0">
3
  <default>
4
  <reference name="head">
5
+ <block name="inject" template="autocompleteplus/inject.phtml" type="autocompleteplus_autosuggest/inject"/>
6
  <block type="autocompleteplus_autosuggest/autocomplete" />
7
  </reference>
8
  </default>
26
  <remove name="search.result"/>
27
  <remove name="left"/>
28
  <reference name="content">
 
29
  <block type="core/template" name="search_result_list" template="autocompleteplus/catalog/product/list.phtml"/>
30
  </reference>
31
  </autocompleteplus_result_index>
34
  <remove name="search.result"/>
35
  <remove name="left"/>
36
  <reference name="content">
 
37
  <block type="core/template" name="search_result_list" template="autocompleteplus/catalog/product/list.phtml"/>
38
  </reference>
39
  </instantsearchplus_result_index>
40
+ </layout>
app/design/frontend/base/default/template/autocompleteplus/catalog/product/list.phtml CHANGED
@@ -1,21 +1,11 @@
1
  <?php
2
  $store_id = Mage::app()->getStore()->getStoreId();
3
- $auto_config = Mage::getModel('autocompleteplus_autosuggest/config')->getCollection()->getData();
4
- $uuid = $auto_config[0]['licensekey'];
5
  $query = htmlentities(Mage::app()->getRequest()->getParam('q'), ENT_QUOTES);
 
6
 
7
  try{
8
- // prevent js injection - Remove query with <script>
9
- $pattern = '/<\s*script[^>]*>/i';
10
- $pattern1 = '/%3C\s*script/i';
11
- $pattern2 = '/&lt;\s*script/i';
12
- if (preg_match($pattern, $query) || preg_match($pattern1, $query) || preg_match($pattern2, $query)){
13
- $query = '';
14
- }
15
- } catch (Exception $e){}
16
-
17
- try{
18
- $match_value = '';
19
  $formkey_html = $this->getBlockHtml('formkey'); // '<input name="form_key" type="hidden" value="E3rpphc1BL6zyTB3" />'
20
  $pattern = '/.*form_key.*value=\"([^\"]+)\"/s';
21
  if (preg_match($pattern, $formkey_html, $match)){
@@ -23,21 +13,23 @@ try{
23
  $match_value = $match[1];
24
  }
25
  }
26
- } catch (Exception $e){}
 
 
27
 
28
  ?>
29
  <!-- <div id="isp_search_result_page"></div> -->
30
 
31
  <script>
32
  var __isp_fulltext_search_obj = {
33
- uuid: <?php echo '"' . $uuid . '"'; ?>,
34
- store_id: <?php echo $store_id; ?>,
35
- query: <?php echo '"' . $query . '"'; ?>,
36
- formkey: <?php echo "'" . $match_value . "'"; ?>,
37
  };
38
  </script>
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);
1
  <?php
2
  $store_id = Mage::app()->getStore()->getStoreId();
3
+ $config = Mage::getModel('autocompleteplus_autosuggest/config');
4
+ $uuid = $config->getUUID();
5
  $query = htmlentities(Mage::app()->getRequest()->getParam('q'), ENT_QUOTES);
6
+ $match_value = '';
7
 
8
  try{
 
 
 
 
 
 
 
 
 
 
 
9
  $formkey_html = $this->getBlockHtml('formkey'); // '<input name="form_key" type="hidden" value="E3rpphc1BL6zyTB3" />'
10
  $pattern = '/.*form_key.*value=\"([^\"]+)\"/s';
11
  if (preg_match($pattern, $formkey_html, $match)){
13
  $match_value = $match[1];
14
  }
15
  }
16
+ } catch (Exception $e){
17
+ Mage::logException($e);
18
+ }
19
 
20
  ?>
21
  <!-- <div id="isp_search_result_page"></div> -->
22
 
23
  <script>
24
  var __isp_fulltext_search_obj = {
25
+ uuid: "<?php echo $this->escapeHtml($config->getUUID()); ?>",
26
+ store_id: <?php echo $this->escapeHtml($store_id); ?>,
27
+ query: "<?php echo $this->escapeHtml($query); ?>",
28
+ formkey: "<?php echo $this->escapeHtml($match_value); ?>"
29
  };
30
  </script>
31
  <?php
32
+ $helper = Mage::helper('autocompleteplus_autosuggest');
33
  $server_url = $helper->getServerUrl();
34
  $url = $server_url . '/ma_load_search_page?isp_platform=magento&r=002';
35
  $resp = $helper->sendCurl($url);
app/design/frontend/base/default/template/autocompleteplus/inject.phtml CHANGED
@@ -1,58 +1,3 @@
1
- <?php
2
-
3
- $enabled= Mage::getStoreConfig('autocompleteplus/config/enabled');
4
-
5
- if($enabled!='0'){
6
- $adminLoggedIn = 0;
7
- try{
8
- //check if adminhtml cookie is set
9
- if(array_key_exists('adminhtml', $_COOKIE)){
10
- //get session path and add dir seperator and content field of cookie as data name with magento "sess_" prefix
11
- $sessionFilePath = Mage::getBaseDir('session').DS.'sess_'.$_COOKIE['adminhtml'];
12
- //write content of file in var
13
- $sessionFile = file_get_contents($sessionFilePath);
14
-
15
- //save old session
16
- $oldSession = $_SESSION;
17
- //decode adminhtml session
18
- session_decode($sessionFile);
19
- //save session data from $_SESSION
20
- $adminSessionData = $_SESSION;
21
- //set old session back to current session
22
- $_SESSION = $oldSession;
23
-
24
- if(array_key_exists('user', $adminSessionData['admin'])){
25
- //save Mage_Admin_Model_User object in var
26
- $adminLoggedIn = 1;
27
- }
28
- }
29
- } catch (Exception $e){}
30
-
31
- $storeId=Mage::app()->getStore()->getStoreId();
32
-
33
- $helper=Mage::helper('autocompleteplus_autosuggest');
34
-
35
- $uuid=$helper->getUUID();
36
-
37
- $onCatalog = false;
38
-
39
- $product=Mage::registry('current_product');
40
-
41
- $sku='';
42
- $productUrl='';
43
- $identifier='';
44
-
45
- if($product) {
46
- $sku = $product->getSku();
47
- $productUrl = $product->getProductUrl();
48
- $identifier = $product->getId();
49
- }
50
-
51
- $magento_version = Mage::getVersion();
52
- $extension_version = (string)Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
53
- ?>
54
-
55
- <script data-cfasync="false" async type="text/javascript" src="https://acp-magento.appspot.com/js/acp-magento.js?mage_v=<?php echo $magento_version ?>&ext_v=<?php echo $extension_version ?>&store=<?php echo $storeId?>&UUID=<?php echo $uuid?>&product_url=<?php echo urlencode($productUrl)?>&product_sku=<?php echo $sku?>&product_id=<?php echo $identifier?>&is_admin_user=<?php echo $adminLoggedIn?>"></script>
56
- <?php
57
- }
58
- ?>
1
+ <?php if(Mage::getStoreConfigFlag('autocompleteplus/config/enabled')): ?>
2
+ <script data-cfasync="false" async type="text/javascript" src="<?php echo $this->getSrc()?>"></script>
3
+ <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/frontend/base/default/template/autocompleteplus/inject_new.phtml DELETED
@@ -1,3 +0,0 @@
1
- <?php if(Mage::getStoreConfigFlag('autocompleteplus/config/enabled')): ?>
2
- <script data-cfasync="false" async type="text/javascript" src="<?php echo $this->getSrc()?>"></script>
3
- <?php endif; ?>
 
 
 
app/design/frontend/base/default/template/autocompleteplus/process.phtml ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $helper = Mage::helper('autocompleteplus_autosuggest');
3
+ $pushId = $helper->getPushId();
4
+ $totalPushes = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->getSize();
5
+ $pushUrl = '';
6
+
7
+ if ($pushId != '') {
8
+ $pushUrl = $helper->getPushUrl($pushId);
9
+ }
10
+ ?>
11
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
13
+ <head>
14
+ <style type="text/css">
15
+ ul { list-style-type:none; padding:0; margin:0; }
16
+ li { margin-left:0; border:1px solid #ccc; margin:2px; padding:2px 2px 2px 2px; font:normal 12px sans-serif; }
17
+ img { margin-right:5px; }
18
+ </style>
19
+ <title><?php echo $this->__('Syncing data...') ?></title>
20
+ </head>
21
+ <body>
22
+
23
+ <ul>
24
+ <li>
25
+ <img src="<?php echo $this->getSkinUrl('images/note_msg_icon.gif');?>" class="v-middle" style="margin-right:5px"/>
26
+ <?php echo $this->__('Starting initial store product sync with InstantSearch+'); ?>
27
+ </li>
28
+
29
+ <li style="background-color:#FFD;">
30
+ <img src="<?php echo $this->getSkinUrl('images/fam_bullet_error.gif'); ?>" class="v-middle" style="margin-right:5px"/>
31
+ <?php echo $this->__('Warning: Please do not close this tab until sync is complete'); ?>
32
+ </li>
33
+
34
+ <li id="liFinished" style="display:none;">
35
+ <img src="<?php echo $this->getSkinUrl('images/note_msg_icon.gif'); ?>" class="v-middle" style="margin-right:5px"/>
36
+ <?php echo $this->__(' Initial Product Sync is finished. '); ?>
37
+ <span id="liFinished_count">0</span>&nbsp;<?php echo $this->__('products were synced'); ?>
38
+ </li>
39
+ </ul>
40
+
41
+ <script type="text/javascript">
42
+ var config = <?php echo Mage::helper('core')->jsonEncode($this->_pushConfig); ?>;
43
+ config.tpl = new Template(config.template);
44
+ config.tplTxt = new Template(config.text);
45
+ config.tplSccTxt = new Template(config.successText);
46
+
47
+ var url= <?php echo $pushUrl; ?>;
48
+
49
+ var count=0;
50
+
51
+ if(url!=""){
52
+ sendImportData(url);
53
+ }else{
54
+ $("liFinished").show();
55
+ $("liFinished_count").update(count);
56
+ $("synced-rows").hide()
57
+ }
58
+
59
+ function sendImportData(url) {
60
+
61
+ if (!$("updatedRows")) {
62
+ Element.insert($("liFinished"), {before: config.tpl.evaluate({
63
+ style: "background-color: #FFD;",
64
+ image: config.styles.loader,
65
+ text: <?php echo $this->__('Syncing: push %s/%s', $pushId, $totalPushes); ?>,
66
+ id: "updatedRows"
67
+ })});
68
+ }
69
+
70
+ new Ajax.Request(url, {
71
+ method: "get",
72
+ onSuccess: function(transport) {
73
+
74
+ if (transport.responseText.isJSON()) {
75
+ var res=transport.responseText.evalJSON();
76
+
77
+ if(!res){
78
+ Element.insert($("updatedRows"), {before: config.tpl.evaluate({
79
+ style: "background-color:"+config.styles.error.bg,
80
+ image: config.styles.error.icon,
81
+ text: res.message,
82
+ id: "error-"+makeid()
83
+ })});
84
+ }else{
85
+
86
+ if (!$("synced-rows")){
87
+ Element.insert($("updatedRows"), {before: config.tpl.evaluate({
88
+ style: "background-color:"+config.styles.message.bg,
89
+ image: config.styles.message.icon,
90
+ text: res.updatedSuccessStatus,
91
+ id: "synced-rows"
92
+ })});
93
+ }else{
94
+ $("synced-rows_status").update(res.updatedSuccessStatus);
95
+ }
96
+
97
+ url=res.nextPushUrl;
98
+
99
+ count+=res.count;
100
+
101
+ if(url!=""){
102
+ $("updatedRows_status").update(res.updatedStatus);
103
+ sendImportData(url);
104
+ }else{
105
+ $("liFinished").show();
106
+ $("liFinished_count").update(count);
107
+ $("updatedRows").hide()
108
+ $("synced-rows").hide()
109
+ }
110
+
111
+ }
112
+ } else {
113
+ Element.insert($("updatedRows"), {before: config.tpl.evaluate({
114
+ style: "background-color:"+config.styles.error.bg,
115
+ image: config.styles.error.icon,
116
+ text: transport.responseText.escapeHTML(),
117
+ id: "error-"+makeid()
118
+ })});
119
+ }
120
+ }
121
+ });
122
+ }
123
+
124
+ function makeid()
125
+ {
126
+ var text = "";
127
+ var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
128
+
129
+ for( var i=0; i < 5; i++ )
130
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
131
+
132
+ return text;
133
+ }
134
+ </script>
135
+ </body>
136
+ </html>
app/etc/modules/Autocompleteplus_Autosuggest.xml CHANGED
@@ -1,23 +1,9 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <config>
3
-
4
-
5
- <modules>
6
-
7
-
8
- <Autocompleteplus_Autosuggest>
9
-
10
-
11
- <active>true</active>
12
-
13
-
14
- <codePool>local</codePool>
15
-
16
-
17
- </Autocompleteplus_Autosuggest>
18
-
19
-
20
- </modules>
21
-
22
-
23
  </config>
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <config>
3
+ <modules>
4
+ <Autocompleteplus_Autosuggest>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Autocompleteplus_Autosuggest>
8
+ </modules>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  </config>
package.xml CHANGED
@@ -1,20 +1,22 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>autocompleteplus_autosuggest</name>
4
- <version>2.0.8.8</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>* Bug fix - stock management for grouped products&#xD;
12
- * Product's attribute 'select' bug fix&#xD;
13
- </notes>
14
- <authors><author><name>Adar</name><user>Adar</user><email>magento@autocompleteplus.com</email></author></authors>
15
- <date>2016-01-17</date>
16
- <time>14:02:36</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="1337ac8525ddac67fd1c560485c16dc8"/><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="80d5c93d9ebfcacfe1fd5baccbbc9891"/><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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>autocompleteplus_autosuggest</name>
4
+ <version>3.0.0.0</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>* Newly refactored module in preparation for Magento 2&#xD;
12
+ * Add support for PSR-2&#xD;
13
+ * Fix security issue with API connection&#xD;
14
+ * Fix issue with admin session loading&#xD;
15
+ * Fix issue with application config table migration</notes>
16
+ <authors><author><name>Adar Greenshpon</name><user>Adar</user><email>magento@autocompleteplus.com</email></author><author><name>Phillip Jackson</name><user>philwinkle</user><email>philwinkle@gmail.com</email></author><author><name>Daniel Kenney</name><user>DKenney</user><email>j.kenney.daniel@gmail.com</email></author></authors>
17
+ <date>2016-02-09</date>
18
+ <time>08:18:11</time>
19
+ <contents><target name="magelocal"><dir name="Autocompleteplus"><dir name="Autosuggest"><dir name="Adminhtml"><dir name="Model"><file name="Attributes.php" hash="5e480167310365ad57785ef2a2da39be"/><file name="Button.php" hash="ad2429ce8a2c172237e41faef5fce322"/></dir></dir><dir name="Block"><dir name="Adminhtml"><file name="Button.php" hash="262987c852813741a2562fe927054469"/><file name="Process.php" hash="30f02cc873ac8d6eaeaaeca5c3d328e5"/><file name="Sync.php" hash="3c668febd558dd7c2db75c314378e0d5"/></dir><file name="Autocomplete.php" hash="cc694575438fe43fc086b89f2d4826c9"/><file name="Autocorrection.php" hash="6676f140f9da260f52e59478e1af2b47"/><file name="Inject.php" hash="bc001de5e9d27bc1e41b8df80d482117"/><file name="Notifications.php" hash="3ab60946b756f093585a708185d98909"/></dir><dir name="Controller"><file name="Abstract.php" hash="84b311dbc24ca94ee7f1af655430f8ea"/></dir><dir name="Helper"><file name="Data.php" hash="882586ede4d095d2e7e2a221610855cc"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Attributes.php" hash="8f8581590b3b2eee69704aa1715dfdd4"/></dir><dir name="Api"><file name="V2.php" hash="f764e775bf087dad35a0351ff2c04539"/></dir><file name="Api.php" hash="298fcc3db05af5fad34375457b5001d4"/><file name="Batches.php" hash="bfa0c53ff502dbb99f120a8ac7626819"/><file name="Catalog.php" hash="bad373d41075e12b37dcf63e10b93f30"/><file name="Catalogreport.php" hash="110c05b050cffb2fec71973e36440702"/><file name="Checksum.php" hash="37550b6bd6d934f1ad2ef581dfa10eea"/><file name="Config.php" hash="e6d1fdbcfcc79e527add17776a913dca"/><file name="Layer.php" hash="82538541fb58038dd308fc584454d0bd"/><file name="Notifications.php" hash="7f4037e171c63de662370aeceaeed1d6"/><file name="Observer.php" hash="216a02f7cc87e5f84d0806e48897a03d"/><file name="Pusher.php" hash="518825e11c9d8fd0b91ac78f6916c40b"/><dir name="Resource"><dir name="Batches"><file name="Collection.php" hash="5d3f333f7383f040654cfb402a089823"/></dir><file name="Batches.php" hash="c5c012179db3636e503f48d0a6de59d5"/><dir name="Checksum"><file name="Collection.php" hash="4c2c32f787763cef11ae9bf175c8813f"/></dir><file name="Checksum.php" hash="5e2d0ece6ea043e517a0c777fc165de4"/><dir name="Fulltext"><file name="Collection.php" hash="5096155efa1f4973f702778673c62507"/></dir><dir name="Notifications"><file name="Collection.php" hash="d7ef7e0ee228b48238b727de349a61b0"/></dir><file name="Notifications.php" hash="f4f1111bd0144c7bcc62ae456d7b36be"/><dir name="Pusher"><file name="Collection.php" hash="8f15379bc010d2a25bf01a8ed3f10fbb"/></dir><file name="Pusher.php" hash="e25a14c317dfe3ae1134f3afc654e8d3"/></dir><file name="Service.php" hash="1bfa0efd3d0652562fd7e9f90130558f"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Autocompleteplus"><file name="PushController.php" hash="c708e07e9b5ae23b4d27c5df0c04cc7f"/><file name="RedirectController.php" hash="8361d1e5922d75763eb82cd916480fb1"/></dir></dir><dir name="CatalogSearch"><file name="ResultController.php" hash="8d2c03b7849b7dbeeb9a08cfa37e63ea"/></dir><file name="CatalogsearchController.php" hash="e534d0933da8a0a1deb4b0618cea5665"/><file name="CategoriesController.php" hash="2222f02aa99ac14c465143462e581270"/><file name="LayeredController.php" hash="dad342dfc566c45bdf77554fa4268882"/><file name="ProductsController.php" hash="4fc00fe17c3455e7d4bb84fa4d3bc949"/><file name="ProductsbyidController.php" hash="4829c9ddf535c1a4abf2302e37beeabc"/><file name="ResultController.php" hash="182f65ce4ccdf154aa0326512ec37140"/><file name="SearchesController.php" hash="7a4e94bb9456b4ac6b48c30b0cd389db"/></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="40168668df5c944aee06a50990446f1e"/><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="c891e1836f3df18eba24821371c85bfa"/><file name="mysql4-upgrade-2.0.1.3-2.0.2.2.php" hash="ddc7001e761dce3b4970f3d4adac2aa3"/><file name="mysql4-upgrade-2.0.2.5-2.0.2.6.php" hash="ea94264608685c51f008382d42d499fd"/><file name="mysql4-upgrade-2.0.4.6-2.0.4.7.php" hash="8166f765780956ea87bbe62b9f709f46"/><file name="mysql4-upgrade-2.0.5.4-2.0.5.5.php" hash="00b8f4401d59f42359baec70ef2de8bb"/><file name="mysql4-upgrade-2.0.5.6-2.0.5.7.php" hash="b40aa51ca00369caa28a0030dc2490e7"/><file name="mysql4-upgrade-2.0.7.0-2.0.7.1.php" hash="3837250beee18106d0f043493dde3382"/><file name="mysql4-upgrade-2.0.7.2-2.0.7.3.php" hash="f858517837a97200e3b5c36339a0b200"/><file name="mysql4-upgrade-2.0.8.8-3.0.0.0.php" hash="6dc213bc5cfb643cbd5b0a2c2c017fdc"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Autocompleteplus_Autosuggest.xml" hash="530931765807be8a21baa5e070bc4bc2"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="autocompleteplus.xml" hash="3998429f613fcc7842b7ea31cb423ec8"/></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="c269d5b27302efb51cefb86a71027a0d"/></dir></dir><file name="inject.phtml" hash="e1e8e050631fe65417edb7a8f25155c8"/><file name="process.phtml" hash="2bb8f334e6d1d64c9042c10d55ac5155"/></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"/><dir name="system"><dir name="config"><file name="button.phtml" hash="3adf3f3f4ab989cf643f2fc49719b59d"/><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>
20
  <compatible/>
21
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
22
  </package>