autocompleteplus_autosuggest - Version 2.0.7.5

Version Notes

* search result page product reviews

Download this release

Release Info

Developer Adar
Extension autocompleteplus_autosuggest
Version 2.0.7.5
Comparing to
See all releases


Version 2.0.7.5

Files changed (67) hide show
  1. app/code/local/Autocompleteplus/Autosuggest/Adminhtml/Model/Attributes.php +60 -0
  2. app/code/local/Autocompleteplus/Autosuggest/Adminhtml/Model/Button.php +78 -0
  3. app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Button.php +135 -0
  4. app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Process.php +339 -0
  5. app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Sync.php +54 -0
  6. app/code/local/Autocompleteplus/Autosuggest/Block/Autocomplete.php +55 -0
  7. app/code/local/Autocompleteplus/Autosuggest/Block/Autocorrection.php +28 -0
  8. app/code/local/Autocompleteplus/Autosuggest/Block/Inject.php +151 -0
  9. app/code/local/Autocompleteplus/Autosuggest/Block/Notifications.php +45 -0
  10. app/code/local/Autocompleteplus/Autosuggest/Helper/Data.php +783 -0
  11. app/code/local/Autocompleteplus/Autosuggest/Model/Adminhtml/Attributes.php +104 -0
  12. app/code/local/Autocompleteplus/Autosuggest/Model/Api.php +35 -0
  13. app/code/local/Autocompleteplus/Autosuggest/Model/Api/V2.php +2 -0
  14. app/code/local/Autocompleteplus/Autosuggest/Model/Catalog.php +952 -0
  15. app/code/local/Autocompleteplus/Autosuggest/Model/Config.php +8 -0
  16. app/code/local/Autocompleteplus/Autosuggest/Model/Layer.php +123 -0
  17. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Config.php +8 -0
  18. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Config/Collection.php +8 -0
  19. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Fulltext.php +101 -0
  20. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Fulltext/Collection.php +140 -0
  21. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Notifications.php +42 -0
  22. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Notifications/Collection.php +43 -0
  23. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Pusher.php +13 -0
  24. app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Pusher/Collection.php +10 -0
  25. app/code/local/Autocompleteplus/Autosuggest/Model/Notifications.php +24 -0
  26. app/code/local/Autocompleteplus/Autosuggest/Model/Observer.php +630 -0
  27. app/code/local/Autocompleteplus/Autosuggest/Model/Pusher.php +8 -0
  28. app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Fulltext/Collection.php +210 -0
  29. app/code/local/Autocompleteplus/Autosuggest/Model/Service.php +279 -0
  30. app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/PushController.php +20 -0
  31. app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/RedirectController.php +26 -0
  32. app/code/local/Autocompleteplus/Autosuggest/controllers/CatalogSearch/ResultController.php +19 -0
  33. app/code/local/Autocompleteplus/Autosuggest/controllers/CatalogsearchController.php +92 -0
  34. app/code/local/Autocompleteplus/Autosuggest/controllers/CategoriesController.php +109 -0
  35. app/code/local/Autocompleteplus/Autosuggest/controllers/LayeredController.php +97 -0
  36. app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsController.php +749 -0
  37. app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsbyidController.php +70 -0
  38. app/code/local/Autocompleteplus/Autosuggest/controllers/SearchesController.php +116 -0
  39. app/code/local/Autocompleteplus/Autosuggest/etc/adminhtml.xml +29 -0
  40. app/code/local/Autocompleteplus/Autosuggest/etc/api.xml +47 -0
  41. app/code/local/Autocompleteplus/Autosuggest/etc/cache.xml +11 -0
  42. app/code/local/Autocompleteplus/Autosuggest/etc/config.xml +233 -0
  43. app/code/local/Autocompleteplus/Autosuggest/etc/config_no_fulltext.xml +214 -0
  44. app/code/local/Autocompleteplus/Autosuggest/etc/config_with_crontab.xml +205 -0
  45. app/code/local/Autocompleteplus/Autosuggest/etc/system.xml +74 -0
  46. app/code/local/Autocompleteplus/Autosuggest/etc/wsdl.xml +95 -0
  47. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-install-2.0.1.1.php +30 -0
  48. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.1.3-2.0.2.2.php +49 -0
  49. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.2.5-2.0.2.6.php +38 -0
  50. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.4.6-2.0.4.7.php +42 -0
  51. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.4-2.0.5.5.php +81 -0
  52. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.6-2.0.5.7.php +55 -0
  53. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.6.1-2.0.6.4.php +158 -0
  54. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.0-2.0.7.1.php +7 -0
  55. app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.2-2.0.7.3.php +51 -0
  56. app/design/adminhtml/default/default/layout/autocompleteplus.xml +25 -0
  57. app/design/adminhtml/default/default/template/autocompleteplus/notifications.phtml +14 -0
  58. app/design/adminhtml/default/default/template/autocompleteplus/notifications_old.php +28 -0
  59. app/design/adminhtml/default/default/template/autocompleteplus/system/config/button.phtml +26 -0
  60. app/design/adminhtml/default/default/template/autocompleteplus/system/config/sync.phtml +21 -0
  61. app/design/frontend/base/default/layout/autocompleteplus.xml +21 -0
  62. app/design/frontend/base/default/template/autocompleteplus/catalog/layer/view.phtml +14 -0
  63. app/design/frontend/base/default/template/autocompleteplus/catalog/product/list.phtml +22 -0
  64. app/design/frontend/base/default/template/autocompleteplus/inject.phtml +58 -0
  65. app/design/frontend/base/default/template/autocompleteplus/inject_new.phtml +3 -0
  66. app/etc/modules/Autocompleteplus_Autosuggest.xml +23 -0
  67. package.xml +19 -0
app/code/local/Autocompleteplus/Autosuggest/Adminhtml/Model/Attributes.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Adminhtml/Model/Button.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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()
28
+ {
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
+ */
56
+ public function getAjaxCheckUrl()
57
+ {
58
+ return Mage::helper('adminhtml')->getUrl('autocompleteplus/products/updateemail');
59
+ }
60
+
61
+ /**
62
+ * Generate button html
63
+ *
64
+ * @return string
65
+ */
66
+ public function getButtonHtml()
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Button.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * InstantSearchPlus (Autosuggest)
5
+
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is available through the world-wide-web at this URL:
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
+
23
+ * Used in creating options for Yes|No config value selection
24
+
25
+ *
26
+
27
+ */
28
+
29
+ class Autocompleteplus_Autosuggest_Block_Adminhtml_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
30
+ {
31
+
32
+ /*
33
+
34
+ * Set template
35
+
36
+ */
37
+
38
+ protected function _construct()
39
+
40
+ {
41
+
42
+ parent::_construct();
43
+
44
+ $this->setTemplate('autocompleteplus/system/config/button.phtml');
45
+
46
+ }
47
+
48
+
49
+
50
+ /**
51
+
52
+ * Return element html
53
+
54
+ *
55
+
56
+ * @param Varien_Data_Form_Element_Abstract $element
57
+
58
+ * @return string
59
+
60
+ */
61
+
62
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
63
+
64
+ {
65
+
66
+ return $this->_toHtml();
67
+
68
+ }
69
+
70
+
71
+
72
+ public function getUUID(){
73
+
74
+ try{
75
+
76
+ $helper=Mage::helper('autocompleteplus_autosuggest');
77
+
78
+ return $helper->getUUID();
79
+
80
+
81
+
82
+ }catch(Exception $e){
83
+
84
+ Mage::log($e->getMessage(),null,'autocomplete.log');
85
+
86
+ }
87
+
88
+ }
89
+
90
+ /**
91
+
92
+ * Return ajax url for button
93
+
94
+ *
95
+
96
+ * @return string
97
+
98
+ */
99
+
100
+ public function getAjaxCheckUrl()
101
+ {
102
+
103
+ return Mage::helper('adminhtml')->getUrl('autocompleteplus/products/updateemail');
104
+ }
105
+
106
+ /**
107
+
108
+ * Generate button html
109
+
110
+ *
111
+
112
+ * @return string
113
+
114
+ */
115
+ public function getButtonHtml()
116
+ {
117
+
118
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
119
+
120
+ ->setData(array(
121
+
122
+ 'id' => 'autocompleteplus_button',
123
+
124
+ 'label' => $this->helper('adminhtml')->__('Update'),
125
+
126
+ 'onclick' => 'javascript:updateautocomplete(); return false;'
127
+
128
+ ));
129
+
130
+ return $button->toHtml();
131
+ }
132
+
133
+
134
+
135
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Process.php ADDED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Block_Adminhtml_Process extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ private $_pushConfig;
7
+
8
+ protected function _toHtml(){
9
+
10
+ $helper = Mage::helper('autocompleteplus_autosuggest');
11
+
12
+ $this->_pushConfig=array(
13
+
14
+ 'styles' => array(
15
+
16
+ 'error' => array(
17
+
18
+ 'icon' => Mage::getDesign()->getSkinUrl('images/error_msg_icon.gif'),
19
+
20
+ 'bg' => '#FDD'
21
+
22
+ ),
23
+
24
+ 'message' => array(
25
+
26
+ 'icon' => Mage::getDesign()->getSkinUrl('images/fam_bullet_success.gif'),
27
+
28
+ 'bg' => '#DDF'
29
+
30
+ ),
31
+
32
+ 'loader' => Mage::getDesign()->getSkinUrl('images/ajax-loader.gif')
33
+
34
+ ),
35
+
36
+ 'template' => '<li style="#{style}" id="#{id}">'
37
+
38
+ . '<img id="#{id}_img" src="#{image}" class="v-middle" style="margin-right:5px"/>'
39
+
40
+ . '<span id="#{id}_status" class="text">#{text}</span>'
41
+
42
+ . '</li>',
43
+
44
+ 'text' => $this->__('Processed <strong>%s%% %s/%d</strong> records', '#{percent}', '#{updated}', $this->getBatchItemsCount()),
45
+
46
+ 'successText' => $this->__('Imported <strong>%s</strong> records', '#{updated}')
47
+
48
+ );
49
+
50
+
51
+
52
+ echo '<html><head>';
53
+
54
+ echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
55
+
56
+ echo '<script type="text/javascript">var FORM_KEY = "'.Mage::getSingleton('core/session')->getFormKey().'";</script>';
57
+
58
+
59
+
60
+ $headBlock = $this->getLayout()->createBlock('page/html_head');
61
+
62
+ $headBlock->addJs('prototype/prototype.js');
63
+
64
+ $headBlock->addJs('mage/adminhtml/loader.js');
65
+
66
+ echo $headBlock->getCssJsHtml();
67
+
68
+
69
+
70
+ echo '<style type="text/css">
71
+
72
+ ul { list-style-type:none; padding:0; margin:0; }
73
+
74
+ li { margin-left:0; border:1px solid #ccc; margin:2px; padding:2px 2px 2px 2px; font:normal 12px sans-serif; }
75
+
76
+ img { margin-right:5px; }
77
+
78
+ </style>
79
+
80
+ <title>'.$this->__('Syncing data...').'</title>
81
+
82
+ </head><body>';
83
+
84
+ echo '<ul>';
85
+
86
+ echo '<li>';
87
+
88
+ echo '<img src="'.Mage::getDesign()->getSkinUrl('images/note_msg_icon.gif').'" class="v-middle" style="margin-right:5px"/>';
89
+
90
+ echo $this->__("Starting initial store product sync with InstantSearch+");
91
+
92
+ echo '</li>';
93
+
94
+ echo '<li style="background-color:#FFD;">';
95
+
96
+ echo '<img src="'.Mage::getDesign()->getSkinUrl('images/fam_bullet_error.gif').'" class="v-middle" style="margin-right:5px"/>';
97
+
98
+ echo $this->__("Warning: Please do not close this tab until sync is complete");
99
+
100
+
101
+
102
+ echo '</li>';
103
+
104
+
105
+
106
+ echo '<li id="liFinished" style="display:none;">
107
+
108
+ <img src="'.$this->getSkinUrl('images/note_msg_icon.gif').'" class="v-middle" style="margin-right:5px"/>
109
+
110
+ '.$this->__(" Initial Product Sync is finished. ").'
111
+
112
+ <span id="liFinished_count">0</span>&nbsp;'.$this->__("products were synced").'
113
+
114
+ </li>';
115
+
116
+ echo '</ul>';
117
+
118
+
119
+
120
+ $pushId=$helper->getPushId();
121
+
122
+
123
+
124
+ $totalPushes= Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->count();
125
+
126
+
127
+
128
+ $pushUrl='';
129
+
130
+
131
+
132
+ if($pushId!=''){
133
+
134
+ $pushUrl=$helper->getPushUrl($pushId);
135
+
136
+ }
137
+
138
+
139
+
140
+ echo '<script type="text/javascript">
141
+
142
+ var config= '.Mage::helper('core')->jsonEncode($this->_pushConfig).';
143
+
144
+ config.tpl = new Template(config.template);
145
+
146
+ config.tplTxt = new Template(config.text);
147
+
148
+ config.tplSccTxt = new Template(config.successText);
149
+
150
+
151
+
152
+ var url="'.$pushUrl.'";
153
+
154
+
155
+
156
+ var count=0;
157
+
158
+
159
+
160
+ if(url!=""){
161
+
162
+ sendImportData(url);
163
+
164
+ }else{
165
+
166
+ $("liFinished").show();
167
+
168
+ $("liFinished_count").update(count);
169
+
170
+ $("synced-rows").hide()
171
+ }
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ function sendImportData(url) {
180
+
181
+
182
+
183
+ if (!$("updatedRows")) {
184
+
185
+ Element.insert($("liFinished"), {before: config.tpl.evaluate({
186
+
187
+ style: "background-color: #FFD;",
188
+
189
+ image: config.styles.loader,
190
+
191
+ text: "Syncing: push '.$pushId.'/'.$totalPushes.'",
192
+
193
+ id: "updatedRows"
194
+
195
+ })});
196
+
197
+ }
198
+
199
+
200
+
201
+ new Ajax.Request(url, {
202
+
203
+ method: "get",
204
+
205
+ onSuccess: function(transport) {
206
+
207
+
208
+
209
+ if (transport.responseText.isJSON()) {
210
+
211
+ var res=transport.responseText.evalJSON();
212
+
213
+
214
+
215
+ if(!res){
216
+
217
+ Element.insert($("updatedRows"), {before: config.tpl.evaluate({
218
+
219
+ style: "background-color:"+config.styles.error.bg,
220
+
221
+ image: config.styles.error.icon,
222
+
223
+ text: res.message,
224
+
225
+ id: "error-"+makeid()
226
+
227
+ })});
228
+
229
+ }else{
230
+
231
+
232
+
233
+ if (!$("synced-rows")){
234
+
235
+ Element.insert($("updatedRows"), {before: config.tpl.evaluate({
236
+
237
+ style: "background-color:"+config.styles.message.bg,
238
+
239
+ image: config.styles.message.icon,
240
+
241
+ text: res.updatedSuccessStatus,
242
+
243
+ id: "synced-rows"
244
+
245
+ })});
246
+
247
+ }else{
248
+
249
+ $("synced-rows_status").update(res.updatedSuccessStatus);
250
+
251
+ }
252
+
253
+
254
+
255
+ url=res.nextPushUrl;
256
+
257
+
258
+
259
+ count+=res.count;
260
+
261
+
262
+
263
+ if(url!=""){
264
+
265
+ $("updatedRows_status").update(res.updatedStatus);
266
+
267
+ sendImportData(url);
268
+
269
+ }else{
270
+
271
+ $("liFinished").show();
272
+
273
+ $("liFinished_count").update(count);
274
+
275
+ $("updatedRows").hide()
276
+
277
+ $("synced-rows").hide()
278
+
279
+ }
280
+
281
+
282
+
283
+ }
284
+
285
+ } else {
286
+
287
+ Element.insert($("updatedRows"), {before: config.tpl.evaluate({
288
+
289
+ style: "background-color:"+config.styles.error.bg,
290
+
291
+ image: config.styles.error.icon,
292
+
293
+ text: transport.responseText.escapeHTML(),
294
+
295
+ id: "error-"+makeid()
296
+
297
+ })});
298
+
299
+ }
300
+
301
+ }
302
+
303
+ });
304
+
305
+ }
306
+
307
+
308
+
309
+ function makeid()
310
+
311
+ {
312
+
313
+ var text = "";
314
+
315
+ var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
316
+
317
+
318
+
319
+ for( var i=0; i < 5; i++ )
320
+
321
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
322
+
323
+
324
+
325
+ return text;
326
+
327
+ }
328
+
329
+ </script>';
330
+
331
+
332
+
333
+ echo '</body></html>';
334
+
335
+ }
336
+
337
+
338
+
339
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Adminhtml/Sync.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * InstantSearchPlus (Autosuggest) * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * * @category Mage * @package InstantSearchPlus * @copyright Copyright (c) 2014 Fast Simon (http://www.instantsearchplus.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */
5
+ /** * Used in creating options for Yes|No config value selection * */
6
+ class Autocompleteplus_Autosuggest_Block_Adminhtml_Sync extends Mage_Adminhtml_Block_System_Config_Form_Field{
7
+ /* * Set template */
8
+ protected function _construct(){
9
+ parent::_construct();
10
+ $this->setTemplate('autocompleteplus/system/config/sync.phtml');
11
+ }
12
+
13
+ /**
14
+ *
15
+ * Return element html
16
+ * * @param Varien_Data_Form_Element_Abstract $element
17
+ * @return string
18
+ */
19
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element){
20
+ return $this->_toHtml();
21
+ }
22
+
23
+ public function getUUID(){
24
+ $helper=Mage::helper('autocompleteplus_autosuggest');
25
+ return $helper->getUUID();
26
+ }
27
+
28
+ public function getIsReachable(){
29
+ $helper=Mage::helper('autocompleteplus_autosuggest');
30
+ return $helper->getIsReachable();
31
+ }
32
+
33
+ /**
34
+ * Return ajax url for button *
35
+ * @return string
36
+ */
37
+ public function getSyncUrl(){
38
+ return Mage::helper('adminhtml')->getUrl('autocompleteplus/adminhtml_push/startpush');
39
+ }
40
+
41
+ /**
42
+ * Generate button html *
43
+ * @return string
44
+ */
45
+ public function getButtonHtml(){
46
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
47
+ ->setData(array(
48
+ 'id' => 'autocompleteplus_sync',
49
+ 'label' => $this->helper('adminhtml')->__('Sync'),
50
+ 'onclick' => 'javascript:syncautocomplete(); return false;'
51
+ ));
52
+ return $button->toHtml();
53
+ }
54
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Autocomplete.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
app/code/local/Autocompleteplus/Autosuggest/Block/Autocorrection.php ADDED
@@ -0,0 +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
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Inject.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Block_Inject extends Mage_Checkout_Block_Cart_Sidebar
4
+ {
5
+ const AUTOCOMPLETE_JS_URL = 'https://acp-magento.appspot.com/js/acp-magento.js';
6
+
7
+ public $_onCatalog = false;
8
+ protected $_helper;
9
+
10
+ protected function _construct()
11
+ {
12
+ $this->_helper = Mage::helper('autocompleteplus_autosuggest');
13
+ $this->_uuid = $this->_helper->getUUID();
14
+ }
15
+
16
+ /**
17
+ * Test to see if admin is logged in
18
+ * by swapping session identifier
19
+ * @return boolean
20
+ * @todo rewrite this to be cleaner
21
+ */
22
+ protected function _isAdminLoggedIn()
23
+ {
24
+ try{
25
+ //check if adminhtml cookie is set
26
+ if(array_key_exists('adminhtml', $_COOKIE)){
27
+ //get session path and add dir seperator and content field of cookie as data name with magento "sess_" prefix
28
+ $sessionFilePath = Mage::getBaseDir('session').DS.'sess_'.$_COOKIE['adminhtml'];
29
+ //write content of file in var
30
+ $sessionFile = file_get_contents($sessionFilePath);
31
+
32
+ //save old session
33
+ $oldSession = $_SESSION;
34
+ //decode adminhtml session
35
+ session_decode($sessionFile);
36
+ //save session data from $_SESSION
37
+ $adminSessionData = $_SESSION;
38
+ //set old session back to current session
39
+ $_SESSION = $oldSession;
40
+
41
+ return array_key_exists('user', $adminSessionData['admin']);
42
+ }
43
+ } catch (Exception $e){}
44
+ }
45
+
46
+ /**
47
+ * Get the current store code
48
+ * @return string
49
+ */
50
+ public function getStoreId()
51
+ {
52
+ return Mage::app()->getStore()->getStoreId();
53
+ }
54
+
55
+ /**
56
+ * Get the Magento version
57
+ * @return string
58
+ */
59
+ public function getMagentoVersion()
60
+ {
61
+ return Mage::getVersion();
62
+ }
63
+
64
+ /**
65
+ * Get the AUTOCOMPLETEPLUS version
66
+ * @return string
67
+ * @todo move to a helper
68
+ */
69
+ public function getVersion()
70
+ {
71
+ return (string)Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
72
+ }
73
+
74
+ /**
75
+ * Get the current product
76
+ * @return Mage_Catalog_Model_Product
77
+ */
78
+ public function getProduct()
79
+ {
80
+ return Mage::registry('current_product');
81
+ }
82
+
83
+ /**
84
+ * UUID getter
85
+ * @return string
86
+ */
87
+ public function getUUID()
88
+ {
89
+ return $this->_uuid;
90
+ }
91
+
92
+ /**
93
+ * Get the URL of the current product if it exists
94
+ * @return string
95
+ */
96
+ public function getProductUrl()
97
+ {
98
+ if($product = $this->getProduct()){
99
+ return urlencode($product->getProductUrl());
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Get the current product's SKU if the product exists
105
+ * @return string
106
+ */
107
+ public function getProductSku()
108
+ {
109
+ if($product = $this->getProduct()){
110
+ return $product->getSku();
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Get the ID of the current product if it exists
116
+ * @return string
117
+ */
118
+ public function getProductIdentifier()
119
+ {
120
+ if($product = $this->getProduct()){
121
+ return $product->getId();
122
+ }
123
+ }
124
+
125
+ public function getQuoteId()
126
+ {
127
+ return Mage::getSingleton('checkout/session')->getQuoteId();
128
+ }
129
+
130
+ /**
131
+ * Return a formatted string for the <script src> attr
132
+ * @return string
133
+ */
134
+ public function getSrc()
135
+ {
136
+ $parameters = array(
137
+ 'mage_v' =>$this->getMagentoVersion(),
138
+ 'ext_v' =>$this->getVersion(),
139
+ 'store' =>$this->getStoreId(),
140
+ 'UUID' =>$this->getUUID(),
141
+ 'product_url' =>$this->getProductUrl(),
142
+ 'product_sku' =>$this->getProductSku(),
143
+ 'product_id' =>$this->getProductIdentifier(),
144
+ 'is_admin_user' =>$this->_isAdminLoggedIn(),
145
+ 'sessionID' =>$this->_helper->getSessionId(),
146
+ 'QuoteID' =>$this->getQuoteId()
147
+ );
148
+
149
+ return self::AUTOCOMPLETE_JS_URL . '?' . http_build_query($parameters,'','&');
150
+ }
151
+ }
app/code/local/Autocompleteplus/Autosuggest/Block/Notifications.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
18
+ class Autocompleteplus_Autosuggest_Block_Notifications extends Mage_Core_Block_Template
19
+ {
20
+ /**
21
+ * @return Autocompleteplus_Autosuggest_Model_Mysql4_Notifications_Collection
22
+ */
23
+ public function getNotifications()
24
+ {
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Helper/Data.php ADDED
@@ -0,0 +1,783 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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 getConfigDataByFullPath($path){
29
+
30
+ if (!$row = Mage::getSingleton('core/config_data')->getCollection()->getItemByColumnValue('path', $path)) {
31
+ $conf = Mage::getSingleton('core/config')->init()->getXpath('/config/default/'.$path);
32
+ if(is_array($conf)){
33
+ $value = array_shift($conf);
34
+ }else{
35
+ return '';
36
+ }
37
+
38
+ } else {
39
+ $value = $row->getValue();
40
+ }
41
+
42
+ return $value;
43
+
44
+ }
45
+
46
+ public function getConfigMultiDataByFullPath($path){
47
+
48
+ if (!$rows = Mage::getSingleton('core/config_data')->getCollection()->getItemsByColumnValue('path', $path)) {
49
+ $conf = Mage::getSingleton('core/config')->init()->getXpath('/config/default/'.$path);
50
+ $value = array_shift($conf);
51
+ } else {
52
+ $values=array();
53
+ foreach($rows as $row){
54
+ $values[$row->getScopeId()]=$row->getValue();
55
+ }
56
+ }
57
+
58
+ return $values;
59
+
60
+ }
61
+
62
+ public function sendCurl($command){
63
+
64
+ if(isset($ch)) unset($ch);
65
+
66
+ if(function_exists('curl_setopt')){
67
+ $ch = curl_init();
68
+ curl_setopt($ch, CURLOPT_URL, $command);
69
+ curl_setopt($ch, CURLOPT_HEADER, 0);
70
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
71
+ curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
72
+ $str=curl_exec($ch);
73
+ }else{
74
+ $str='failed';
75
+ }
76
+
77
+ return $str;
78
+
79
+
80
+ }
81
+
82
+ public function getKey(){
83
+
84
+ if(!$this->_authKey){
85
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
86
+ $sqlFetch = 'SELECT authkey FROM '. $_tableprefix.'autocompleteplus_config WHERE id = 1 LIMIT 1';
87
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
88
+ $this->_authKey = $read->fetchOne($sqlFetch);
89
+ }
90
+
91
+ return $this->_authKey;
92
+ }
93
+
94
+ public function getBothKeys(){
95
+
96
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
97
+
98
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
99
+
100
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
101
+
102
+ $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
103
+
104
+ if(!$tblExist){return;}
105
+
106
+ $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
107
+
108
+ $licenseData=$read->fetchAll($sql);
109
+
110
+ $key=$licenseData[0]['licensekey'];
111
+
112
+ $authKey= $licenseData[0]['authkey'];
113
+
114
+ $res=array('uuid'=>$key,'authkey'=>$authKey);
115
+
116
+ return $res;
117
+ }
118
+
119
+ public static function sendPostCurl($command, $data=array(),$cookie_file='genCookie.txt') {
120
+
121
+ if(isset($ch)) unset($ch);
122
+
123
+ if(function_exists('curl_setopt')){
124
+
125
+ $ch = curl_init();
126
+ curl_setopt($ch, CURLOPT_URL, $command);
127
+ curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
128
+ curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
129
+ curl_setopt($ch, CURLOPT_HEADER, 0);
130
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
131
+ curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
132
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0');
133
+ //curl_setopt($ch,CURLOPT_POST,0);
134
+ if(!empty($data)){
135
+ curl_setopt_array($ch, array(
136
+ CURLOPT_POSTFIELDS => $data,
137
+ ));
138
+ }
139
+
140
+
141
+ // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
142
+ // 'Connection: Keep-Alive',
143
+ // 'Keep-Alive: 800'
144
+ // ));
145
+
146
+ $str=curl_exec($ch);
147
+
148
+ }else{
149
+ $str='failed';
150
+ }
151
+
152
+ return $str;
153
+ }
154
+
155
+ public function prepareGroupedProductPrice($groupedProduct)
156
+ {
157
+ $aProductIds = $groupedProduct->getTypeInstance()->getChildrenIds($groupedProduct->getId());
158
+
159
+ $prices = array();
160
+ foreach ($aProductIds as $ids) {
161
+ foreach ($ids as $id) {
162
+ try{
163
+ $aProduct = Mage::getModel('catalog/product')->load($id);
164
+ $prices[] = $aProduct->getPriceModel()->getPrice($aProduct);
165
+ } catch (Exception $e){
166
+ continue;
167
+ }
168
+ }
169
+ }
170
+
171
+ krsort($prices);
172
+ try{
173
+ if (count($prices) > 0){
174
+ $groupedProduct->setPrice($prices[0]);
175
+ } else {
176
+ $groupedProduct->setPrice(0);
177
+ }
178
+ } catch (Exception $e){
179
+ $groupedProduct->setPrice(0);
180
+ }
181
+
182
+ // or you can return price
183
+ }
184
+
185
+ public function getBundlePrice($product) {
186
+
187
+ $optionCol= $product->getTypeInstance(true)
188
+ ->getOptionsCollection($product);
189
+ $selectionCol= $product->getTypeInstance(true)
190
+ ->getSelectionsCollection(
191
+ $product->getTypeInstance(true)->getOptionsIds($product),
192
+ $product
193
+ );
194
+ $optionCol->appendSelections($selectionCol);
195
+ $price = $product->getPrice();
196
+
197
+ foreach ($optionCol as $option) {
198
+ if($option->required) {
199
+ $selections = $option->getSelections();
200
+ $selPricesArr=array();
201
+
202
+ if(is_array($selections)){
203
+
204
+ foreach($selections as $s){
205
+ $selPricesArr[]=$s->price;
206
+ }
207
+
208
+
209
+
210
+ $minPrice = min($selPricesArr);
211
+
212
+ if($product->getSpecialPrice() > 0) {
213
+ $minPrice *= $product->getSpecialPrice()/100;
214
+ }
215
+
216
+ $price += round($minPrice,2);
217
+
218
+ }
219
+ }
220
+ }
221
+ return $price;
222
+
223
+ }
224
+
225
+ public function getMultiStoreDataJson(){
226
+
227
+ $websites=Mage::getModel('core/website')->getCollection();
228
+
229
+ $multistoreData=array();
230
+ $multistoreJson='';
231
+ $useStoreCode=$this->getConfigDataByFullPath('web/url/use_store');
232
+ $mage=Mage::getVersion();
233
+ $ext=(string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
234
+ $version=array('mage'=>$mage,'ext'=>$ext);
235
+
236
+ //getting site url
237
+ $url=$this->getConfigDataByFullPath('web/unsecure/base_url');
238
+
239
+ //getting site owner email
240
+ $storeMail=$this->getConfigDataByFullPath('autocompleteplus/config/store_email');
241
+
242
+ if(!$storeMail){
243
+
244
+ $storeMail=$this->getConfigDataByFullPath('trans_email/ident_general/email');
245
+ }
246
+
247
+ $collection=Mage::getModel('catalog/product')->getCollection();
248
+ //$productCount=$collection->count();
249
+
250
+
251
+ $storesArr=array();
252
+ foreach($websites as $website){
253
+ $code=$website->getCode();
254
+ $stores=$website->getStores();
255
+ foreach($stores as $store){
256
+ $storesArr[$store->getStoreId()]=$store->getData();
257
+ }
258
+ }
259
+
260
+ if(count($storesArr)==1){
261
+ try{
262
+ $dataArr = array(
263
+ // 'stores' => array(array_pop($storesArr)),
264
+ 'stores' => array_pop($storesArr),
265
+ 'version' => $version
266
+ );
267
+ } catch (Exception $e){
268
+ $dataArr = array(
269
+ 'stores' => $multistoreData,
270
+ 'version' => $version
271
+ );
272
+ }
273
+
274
+ $dataArr['site'] = $url;
275
+ $dataArr['email'] = $storeMail;
276
+
277
+ $multistoreJson = json_encode($dataArr);
278
+
279
+ }else{
280
+
281
+ $storeUrls=$this->getConfigMultiDataByFullPath('web/unsecure/base_url');
282
+ $locales=$this->getConfigMultiDataByFullPath('general/locale/code');
283
+ $storeComplete=array();
284
+
285
+ foreach($storesArr as $key=>$value){
286
+
287
+ if(!$value['is_active']){
288
+ continue;
289
+ }
290
+
291
+ $storeComplete=$value;
292
+ if(array_key_exists($key,$locales)){
293
+ $storeComplete['lang']=$locales[$key];
294
+ }else{
295
+ $storeComplete['lang']=$locales[0];
296
+ }
297
+
298
+ if(array_key_exists($key,$storeUrls)){
299
+ $storeComplete['url']=$storeUrls[$key];
300
+ }else{
301
+ $storeComplete['url']=$storeUrls[0];
302
+ }
303
+
304
+ if($useStoreCode){
305
+ $storeComplete['url']=$storeUrls[0].$value['code'];
306
+ }
307
+
308
+ $multistoreData[]=$storeComplete;
309
+ }
310
+
311
+ $dataArr=array(
312
+ 'stores'=>$multistoreData,
313
+ 'version'=>$version
314
+ );
315
+
316
+ $dataArr['site']=$url;
317
+ $dataArr['email']=$storeMail;
318
+ //$dataArr['product_count']=$productCount;
319
+
320
+ $multistoreJson=json_encode($dataArr);
321
+
322
+ }
323
+ Mage::log($multistoreJson,null,'autocomplete.log');
324
+
325
+ return $multistoreJson;
326
+ }
327
+
328
+ public function getExtensionConflict($all_conflicts = false){
329
+ $all_rewrite_classes = array();
330
+ $node_type_list = array('model', 'helper', 'block');
331
+
332
+ foreach ($node_type_list as $node_type){
333
+ foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module) {
334
+ if ($module->codePool == 'core' || $module->active != 'true'){
335
+ continue;
336
+ }
337
+ $config_file_path = Mage::getConfig()->getModuleDir('etc', $name) . DS . 'config.xml';
338
+ $config = new Varien_Simplexml_Config();
339
+ $config->loadString('<config/>');
340
+ $config->loadFile($config_file_path);
341
+ $config->extend($config, true);
342
+
343
+ $nodes = $config->getNode()->global->{$node_type . 's'};
344
+ if (!$nodes)
345
+ continue;
346
+ foreach($nodes->children() as $node_name => $config) {
347
+ if ($config->rewrite){ // there is rewrite for current config
348
+ foreach($config->rewrite->children() as $class_tag => $derived_class){
349
+ $base_class_name = $this->_getMageBaseClass($node_type, $node_name, $class_tag);
350
+
351
+ $lead_derived_class = '';
352
+ $conf = Mage::getConfig()->getNode()->global->{$node_type . 's'}->{$node_name};
353
+ if (isset($conf->rewrite->$class_tag)){
354
+ $lead_derived_class = (string)$conf->rewrite->$class_tag;
355
+ }
356
+ if ($derived_class == ''){
357
+ $derived_class = $lead_derived_class;
358
+ }
359
+
360
+ if (empty($all_rewrite_classes[$base_class_name])){
361
+ $all_rewrite_classes[$base_class_name] = array(
362
+ 'derived' => array((string)$derived_class),
363
+ 'lead' => (string)$lead_derived_class,
364
+ 'tag' => $class_tag,
365
+ 'name' => array((string)$name)
366
+ );
367
+ }else{
368
+ array_push($all_rewrite_classes[$base_class_name]['derived'], (string)$derived_class);
369
+ array_push($all_rewrite_classes[$base_class_name]['name'], (string)$name);
370
+ }
371
+ }
372
+ }
373
+ }
374
+ }
375
+ }
376
+ if ($all_conflicts){
377
+ return $all_rewrite_classes;
378
+ }
379
+
380
+ $isp_rewrite_classes = array();
381
+ $isp_module_name = 'Autocompleteplus_Autosuggest';
382
+ foreach ($all_rewrite_classes as $base => $conflict_info){
383
+ if (in_array($isp_module_name, $conflict_info['name'])){ // if isp extension rewrite this base class
384
+ if (count($conflict_info['derived']) > 1){ // more then 1 class rewrite this base class => there is a conflict
385
+ $isp_rewrite_classes[$base] = $conflict_info;
386
+ }
387
+ }
388
+ }
389
+ return $isp_rewrite_classes;
390
+ }
391
+
392
+ protected function _getMageBaseClass($node_type, $node_name, $class_tag){
393
+ $config = Mage::getConfig()->getNode()->global->{$node_type . 's'}->$node_name;
394
+
395
+ if (!empty($config)) {
396
+ $className = $config->getClassName();
397
+ }
398
+ if (empty($className)) {
399
+ $className = 'mage_'.$node_name.'_'.$node_type;
400
+ }
401
+ if (!empty($class_tag)) {
402
+ $className .= '_'.$class_tag;
403
+ }
404
+ return uc_words($className);
405
+ }
406
+
407
+ /**
408
+ * Checksum functionality
409
+ */
410
+ public function isChecksumTableExists(){
411
+ $table_prefix = (string)Mage::getConfig()->getTablePrefix();
412
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
413
+ if ($read->showTableStatus($table_prefix . 'autocompleteplus_checksum')){
414
+ return true;
415
+ } else {
416
+ return false;
417
+ }
418
+ }
419
+
420
+ public function calculateChecksum($product){
421
+ $product_id = $product->getId();
422
+ $product_title = $product->getName();
423
+ $product_description = $product->getDescription();
424
+ $product_short_desc = $product->getShortDescription();
425
+ $product_url = $product->getUrlPath(); //Mage::helper('catalog/product')->getProductUrl($product_id); | $product->getProductUrl()
426
+ $product_visibility = $product->getVisibility();
427
+ $product_in_stock = $product->isInStock();
428
+ $product_price = (float)$product->getPrice();
429
+ try{
430
+ $product_thumb_url = '/' . $product->getImage();
431
+
432
+ // $product_thumb_url = $product->getThumbnailUrl(); //Mage::helper('catalog/image')->init($product, 'thumbnail');
433
+ // $thumb_pattern = '/\/[^\/]+(?![^\/]*\/)/';
434
+ // if (preg_match($thumb_pattern, $product_thumb_url, $matches) && count($matches) > 0){
435
+ // $product_thumb_url = $matches[0];
436
+ // } else {
437
+ // $product_thumb_url = '';
438
+ // }
439
+ } catch (Exception $e){
440
+ $product_thumb_url = '';
441
+ }
442
+ $product_type = $product->getTypeID();
443
+
444
+ $checksum_string = $product_id . $product_title . $product_description . $product_short_desc . $product_url .
445
+ $product_visibility . $product_in_stock . $product_price . $product_thumb_url . $product_type;
446
+
447
+ $checksum_md5 = md5($checksum_string);
448
+ return $checksum_md5;
449
+ }
450
+
451
+ public function getSavedChecksum($table_prefix, $read, $product_id, $store_id){
452
+ $sql_fetch = 'SELECT checksum FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
453
+ $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
454
+ if($updates && (count($updates) != 0)){
455
+ return $updates[0]['checksum'];
456
+ } else {
457
+ return '';
458
+ }
459
+ }
460
+
461
+ public function updateSavedProductChecksum($table_prefix, $read, $write, $product_id, $sku, $store_id, $checksum){
462
+ if ($product_id == null || $sku == null){
463
+ return;
464
+ }
465
+ $sql_fetch = 'SELECT checksum FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
466
+ $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
467
+
468
+ if($updates && (count($updates) != 0)){
469
+ if ($updates[0]['checksum'] != $checksum){
470
+ $sql = 'UPDATE '. $table_prefix.'autocompleteplus_checksum SET checksum=? WHERE identifier=? AND store_id=?';
471
+ $write->query($sql, array($checksum, $product_id, $store_id));
472
+ }
473
+ }else{
474
+ $sql = 'INSERT INTO '. $table_prefix.'autocompleteplus_checksum (identifier, sku, store_id, checksum) VALUES (?,?,?,?)';
475
+ $write->query($sql, array($product_id, $sku, $store_id, $checksum));
476
+ }
477
+ }
478
+
479
+ public function updateDeletedProductChecksum($table_prefix, $read, $write, $product_id, $sku, $store_id){
480
+ if ($product_id == null){
481
+ return;
482
+ }
483
+ $sql_fetch = 'SELECT * FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
484
+ $updates = $read->fetchAll($sql_fetch, array($product_id, $store_id));
485
+
486
+ if($updates && (count($updates) != 0)){
487
+ $sql = 'DELETE FROM '. $table_prefix.'autocompleteplus_checksum WHERE identifier=? AND store_id=?';
488
+ $write->query($sql, array($product_id, $store_id));
489
+ }
490
+ }
491
+
492
+ private function setUpdateNeededForProduct($read, $write, $product_id, $product_sku, $store_id){
493
+ if ($product_id == null || $product_sku == null){
494
+ return;
495
+ }
496
+ try{
497
+ $table_prefix = (string)Mage::getConfig()->getTablePrefix();
498
+ $is_table_exist = $write->showTableStatus($table_prefix.'autocompleteplus_batches');
499
+ if (!$is_table_exist) // table not exists
500
+ return;
501
+
502
+ $sql_fetch = 'SELECT * FROM '. $table_prefix.'autocompleteplus_batches WHERE sku=? AND store_id=?';
503
+ $updates = $read->fetchAll($sql_fetch, array($product_sku, $store_id));
504
+
505
+ if ($updates && (count($updates) != 0)){
506
+ $sql = 'UPDATE '. $table_prefix.'autocompleteplus_batches SET update_date=?,action=? WHERE sku=? AND store_id=?';
507
+ $write->query($sql, array(strtotime('now'), "update", $product_sku, $store_id));
508
+ }else{
509
+ $sql='INSERT INTO '. $table_prefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
510
+ $write->query($sql, array($product_id, $store_id, strtotime('now'), "update", $product_sku));
511
+ }
512
+
513
+ }catch(Exception $e){
514
+ Mage::log('Exception raised in setUpdateNeededForProduct() - ' . $e->getMessage(), null, 'autocompleteplus.log');
515
+ $this->ispErrorLog('Exception raised in setUpdateNeededForProduct() - ' . $e->getMessage());
516
+ }
517
+ }
518
+
519
+ public function compareProductsChecksum($from, $count, $store_id = null){
520
+ $num_of_updates = 0;
521
+ if (!$this->isChecksumTableExists())
522
+ return;
523
+
524
+ $products = Mage::getModel('catalog/product')->getCollection();
525
+ if ($store_id){
526
+ $products->addStoreFilter($store_id);
527
+ }
528
+ $products->getSelect()->limit($count, $from);
529
+ $products->load();
530
+
531
+ $table_prefix = (string)Mage::getConfig()->getTablePrefix();
532
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
533
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
534
+
535
+ foreach ($products as $product) {
536
+ try{
537
+ $product_collection_data = $product->getData();
538
+ $product_model = Mage::getModel('catalog/product')->load($product_collection_data['entity_id']);
539
+ $current_checksum = $this->getSavedChecksum($table_prefix, $read, $product_model->getId(), $store_id );
540
+ $new_checksum = $this->calculateChecksum($product_model);
541
+ }catch(Exception $e){
542
+ Mage::log('Exception raised in compareProductsChecksum() on id: ' . $product->getId() . ' -> ' . $e->getMessage(), null, 'autocompleteplus.log');
543
+ $this->ispErrorLog('Exception raised in compareProductsChecksum() on id: ' . $product->getId() . ' -> ' . $e->getMessage());
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
+ return $num_of_updates;
554
+ }
555
+
556
+ public function deleteProductFromTables($read, $write, $table_prefix, $product_id, $store_id){
557
+ $dt = strtotime('now');
558
+ $sku = 'dummy_sku';
559
+ $sqlFetch = 'SELECT * FROM '. $table_prefix.'autocompleteplus_batches WHERE product_id = ? AND store_id=?';
560
+ $updates = $read->fetchAll($sqlFetch, array($product_id, $store_id));
561
+
562
+ if($updates && count($updates) != 0){
563
+ $sql = 'UPDATE '. $table_prefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id = ? AND store_id = ?';
564
+ $write->query($sql, array($dt, "remove", $product_id, $store_id));
565
+ } else {
566
+ $sql='INSERT INTO '. $table_prefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
567
+ $write->query($sql, array($product_id, $store_id, $dt, "remove", $sku));
568
+ }
569
+
570
+ $this->updateDeletedProductChecksum($table_prefix, $read, $write, $product_id, $sku, $store_id);
571
+ }
572
+
573
+ public function ispLog($log){
574
+ Mage::log($log, null, 'autocompleteplus.log');
575
+ }
576
+
577
+ public function ispErrorLog($log){
578
+ $uuid = $this->getUUID();
579
+ $site_url = $this->getConfigDataByFullPath('web/unsecure/base_url');
580
+ $store_id = Mage::app()->getStore()->getStoreId();
581
+
582
+ $server_url = $this->server_url . '/magento_logging_error';
583
+ $request = $server_url . '?uuid=' . $uuid . '&site_url=' . $site_url . '&store_id=' . $store_id . '&msg=' . urlencode($log);
584
+
585
+ $resp = $this->sendCurl($request);
586
+ }
587
+
588
+ public function getUUID(){
589
+
590
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
591
+
592
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
593
+
594
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
595
+
596
+ $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
597
+
598
+ if(!$tblExist){return '';}
599
+
600
+ $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
601
+
602
+ $licenseData=$read->fetchAll($sql);
603
+
604
+ $key=$licenseData[0]['licensekey'];
605
+
606
+ return $key;
607
+
608
+ }
609
+
610
+ public function getIsReachable(){
611
+
612
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
613
+
614
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
615
+
616
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
617
+
618
+ $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
619
+
620
+ if(!$tblExist){return '';}
621
+
622
+ $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
623
+
624
+ $licenseData=$read->fetchAll($sql);
625
+
626
+ $is_reachable=$licenseData[0]['is_reachable'];
627
+
628
+ return $is_reachable;
629
+
630
+ }
631
+
632
+ public function getServerEndPoint(){
633
+ try{
634
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
635
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
636
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
637
+ $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
638
+
639
+ if(!$tblExist){
640
+ return '';
641
+ }
642
+
643
+ $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
644
+ $licenseData=$read->fetchAll($sql);
645
+ if (array_key_exists('server_type', $licenseData[0])){
646
+ $key = $licenseData[0]['server_type'];
647
+ } else {
648
+ $key = '';
649
+ }
650
+ } catch(Exception $e){
651
+ $key = '';
652
+ }
653
+ return $key;
654
+ }
655
+
656
+ public function setServerEndPoint($end_point){
657
+ try{
658
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
659
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
660
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
661
+ $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
662
+
663
+ if(!$tblExist){
664
+ return;
665
+ }
666
+
667
+ $sqlFetch = 'SELECT * FROM '. $_tableprefix.'autocompleteplus_config WHERE id = 1';
668
+ $updates = $write->fetchAll($sqlFetch);
669
+
670
+ if($updates&&count($updates)!=0){
671
+ $sql='UPDATE '. $_tableprefix.'autocompleteplus_config SET server_type=? WHERE id = 1';
672
+ $write->query($sql, array($end_point));
673
+ }else{
674
+ Mage::log('cant update server_type',null,'autocompleteplus.log');
675
+ }
676
+ }catch(Exception $e){
677
+ Mage::log($e->getMessage(),null,'autocompleteplus.log');
678
+ }
679
+ }
680
+
681
+ public function getErrormessage(){
682
+
683
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
684
+
685
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
686
+
687
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
688
+
689
+ $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
690
+
691
+ if(!$tblExist){return '';}
692
+
693
+ $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
694
+
695
+ $licenseData=$read->fetchAll($sql);
696
+
697
+ $errormessage=$licenseData[0]['errormessage'];
698
+
699
+ return $errormessage;
700
+
701
+ }
702
+
703
+ public function getIfSyncWasInitiated(){
704
+ $collection = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection();
705
+
706
+ $count=$collection->count();
707
+
708
+ if($count==0){
709
+ return false;
710
+ }else{
711
+ return true;
712
+ }
713
+ }
714
+
715
+ public function getPushId(){
716
+
717
+ $collection = Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()
718
+ ->addFilter('sent',0);
719
+
720
+ $collection->getSelect()->limit(1);
721
+
722
+ $collection->load();
723
+
724
+ $id='';
725
+
726
+ foreach ($collection as $p) {
727
+ $id=$p->getId();
728
+ }
729
+
730
+ return $id;
731
+ }
732
+
733
+ public function getPushUrl($id=null){
734
+
735
+ if($id==null){
736
+ $id=$this->getPushId();
737
+ }
738
+
739
+ $url=Mage::getUrl();//'',array('pushid'=>$id));
740
+
741
+ if (strpos($url, 'index.php') !== FALSE){
742
+ $url=$url.'/autocompleteplus/products/pushbulk/pushid/'.$id;
743
+ }else{
744
+ $url=$url.'index.php/autocompleteplus/products/pushbulk/pushid/'.$id;
745
+ }
746
+ return $url;
747
+
748
+ }
749
+
750
+ public function escapeXml($xml){
751
+ // $pairs = array(
752
+ // "\x03" => "&#x03;",
753
+ // "\x05" => "&#x05;",
754
+ // "\x0E" => "&#x0E;",
755
+ // "\x16" => "&#x16;",
756
+ // );
757
+ // $xml = strtr($xml, $pairs);
758
+
759
+ $xml=preg_replace('/[\x00-\x1f]/', '', $xml);
760
+ return $xml;
761
+ }
762
+
763
+
764
+ /**
765
+ * Get the session cookie value
766
+ * protected with a salt (the store encryption key)
767
+ * @return string
768
+ */
769
+ public function getSessionId()
770
+ {
771
+ return md5(Mage::app()->getCookie()->get('frontend') . $this->_getEncryptionKey());
772
+ }
773
+
774
+ /**
775
+ * Return encryption key in Magento to use as salt
776
+ * @return string
777
+ */
778
+ protected function _getEncryptionKey()
779
+ {
780
+ return Mage::getModel('install/installer_data')->getEncryptionKey();
781
+ }
782
+
783
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Adminhtml/Attributes.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * InstantSearchPlus (Autosuggest)
5
+
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is available through the world-wide-web at this URL:
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Api.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Api/V2.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ class Autocompleteplus_Autosuggest_Model_Api_V2 extends Autocompleteplus_Autosuggest_Model_Api {}
app/code/local/Autocompleteplus/Autosuggest/Model/Catalog.php ADDED
@@ -0,0 +1,952 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=(string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
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
+ }
36
+
37
+ //setting page+products on the page
38
+ $collection->getSelect()->limit($count,$startInd);//->limitPage($pageNum, $count);//setPage($pageNum, $count)->load();
39
+ $collection->load();
40
+
41
+ // number of orderes per product section
42
+ if (isset($orders) && $orders == '1'){
43
+ $product_id_list = array();
44
+ foreach ($collection as $product){
45
+ $product_id_list[] = $product->getId();
46
+ }
47
+ if(isset($storeId)&& $storeId!=''){
48
+ $store_id = $storeId;
49
+ } else {
50
+ $store_id = 1;
51
+ }
52
+
53
+ if(isset($month_interval)&& $month_interval!=''){
54
+ $month_interval = $month_interval;
55
+ } else {
56
+ $month_interval = 12;
57
+ }
58
+ $orders_per_product = $this->_getOrdersPerProduct($store_id, $product_id_list, $month_interval);
59
+ } else {// end - number of orderes per product section
60
+ $orders_per_product = null;
61
+ }
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
+ $productModel=Mage::getModel('catalog/product')
80
+ ->setStore($storeId)->setStoreId($storeId)
81
+ ->load($productCollData['entity_id']);
82
+ $prodId =$productModel->getId();
83
+ $sku =$productModel->getSku();
84
+ $row=$this->renderProductXmlRow($productModel,$orders_per_product);
85
+ $xml.=$row;
86
+ if ($is_checksum && $helper){
87
+ if ($helper->isChecksumTableExists()){
88
+ $checksum = $helper->calculateChecksum($productModel);
89
+ $helper->updateSavedProductChecksum($_tableprefix, $read, $write, $prodId, $sku, $store_id, $checksum);
90
+ }
91
+ }
92
+ }
93
+ $xml.='</catalog>';
94
+ return $xml;
95
+ }
96
+
97
+ public function renderUpdatesCatalogXml($count,$from,$to,$storeId){
98
+ $storeQ='';
99
+
100
+ if($storeId!=''){
101
+ $storeQ = 'AND store_id='.$storeId;
102
+ }else{
103
+ $storeId = Mage::app()->getStore()->getStoreId();
104
+ }
105
+ $this->_initCatalogCommonFields($storeId);
106
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
107
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
108
+
109
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
110
+ $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_batches` WHERE update_date BETWEEN ? AND ? '.$storeQ. ' order by update_date' . ' LIMIT '.$count;
111
+ $updates=$read->fetchAll($sql,array($from,$to));
112
+
113
+ $mage=Mage::getVersion();
114
+ $ext=(string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
115
+
116
+ $xml='<?xml version="1.0"?>';
117
+ $xml.='<catalog fromdatetime="'.$from.'" version="'.$ext.'" magento="'.$mage.'">';
118
+ foreach ($updates as $batch) {
119
+ if($batch['action']=='update'){
120
+ $productId = $batch['product_id'];
121
+ $sku = $batch['sku'];
122
+ $batchStoreId = $batch['store_id'];
123
+
124
+ if($storeId!=$batchStoreId){
125
+ $this->currency = Mage::app()->getStore($batchStoreId)->getCurrentCurrencyCode();
126
+ }
127
+
128
+ $productModel = null;
129
+
130
+ if($productId!=null){
131
+ // load product by id
132
+ $productModel=Mage::getModel('catalog/product')
133
+ ->setStoreId($batchStoreId)
134
+ ->load($productId);
135
+ }else{
136
+ //load product by sku
137
+ continue;
138
+
139
+ /*
140
+ * FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
141
+ */
142
+ // $productModel=Mage::getModel('catalog/product')
143
+ // ->loadByAttribute('sku', $sku)
144
+ // ->setStoreId($batchStoreId);
145
+ }
146
+
147
+ if($productModel==null){
148
+ continue;
149
+ }
150
+
151
+ $updatedate = $batch['update_date'];
152
+ $action = $batch['action'];
153
+ $xmlAttrs='action="'.$action.'" updatedate="'.$updatedate.'" storeid="'.$storeId.'"' ;
154
+ // $xmlAttrs='action="'.$action.'" updatedate="'.$updatedate.'"';
155
+ $xml.=$this->renderProductXmlRow($productModel,null,$xmlAttrs);
156
+ }else{
157
+ $xml.=$this->_makeRemoveRow($batch);
158
+ }
159
+
160
+ }
161
+ $xml.='</catalog>';
162
+ return $xml;
163
+ }
164
+
165
+ public function renderCatalogFromIds($count,$ids,$storeId){
166
+
167
+ $this->_initCatalogCommonFields($storeId);
168
+
169
+ $mage=Mage::getVersion();
170
+
171
+ $ext=(string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
172
+
173
+ $xml='<catalog version="'.$ext.'" magento="'.$mage.'">';
174
+
175
+ $_productCollection = Mage::getModel('catalog/product')->getCollection()
176
+ //->addStoreFilter($storeId)
177
+ //->addAttributeToSelect('*')
178
+ ->addAttributeToFilter('entity_id', array(
179
+ 'from' => $ids
180
+ ));
181
+
182
+ $_productCollection->getSelect()->limit($count);
183
+ $_productCollection->load();
184
+
185
+ $action= 'getfromid';
186
+
187
+ foreach($_productCollection as $product){
188
+
189
+ if($product!=null){
190
+
191
+ $id=$product->getId();
192
+
193
+ $productModel=Mage::getModel('catalog/product')
194
+ ->setStoreId($storeId)
195
+ ->load($id);
196
+
197
+ $lastUpdateddt=$productModel->getUpdatedAt();
198
+
199
+ $xmlAttrs='last_updated="'.$lastUpdateddt.'" get_by_id_status="1" action="'.$action.'" storeid="'.$storeId.'"' ;
200
+
201
+ $xml.=$this->renderProductXmlRow($productModel,null,$xmlAttrs);
202
+
203
+ }else{
204
+ $xml.='<product action="'.$action.'" product="'.$id.'" get_by_id_status="0"></product>';
205
+ }
206
+
207
+ }
208
+
209
+ $xml.='</catalog>';
210
+
211
+ return $xml;
212
+ }
213
+
214
+ public function renderCatalogByIds($ids,$storeId){
215
+
216
+ $this->_initCatalogCommonFields($storeId);
217
+
218
+ $mage=Mage::getVersion();
219
+
220
+ $ext=(string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
221
+
222
+ $xml='<catalog version="'.$ext.'" magento="'.$mage.'">';
223
+
224
+ $_productCollection = Mage::getModel('catalog/product')->getCollection()
225
+ //->addStoreFilter($storeId)
226
+ //->addAttributeToSelect('*')
227
+ ->addAttributeToFilter('entity_id', array(
228
+ 'in' => $ids
229
+ ));
230
+
231
+ $action= 'getbyid';
232
+
233
+ foreach($ids as $id){
234
+
235
+ $productModel=Mage::getModel('catalog/product')
236
+ ->setStoreId($storeId)
237
+ ->load($id);
238
+
239
+ if($productModel->getId()){
240
+
241
+ $lastUpdateddt=$productModel->getUpdatedAt();
242
+
243
+ $xmlAttrs='last_updated="'.$lastUpdateddt.'" get_by_id_status="1" action="'.$action.'" storeid="'.$storeId.'"' ;
244
+
245
+ $xml.=$this->renderProductXmlRow($productModel,null,$xmlAttrs);
246
+
247
+ }else{
248
+ $xml.='<product action="'.$action.'" product="'.$id.'" get_by_id_status="0"></product>';
249
+ }
250
+
251
+ }
252
+
253
+ $xml.='</catalog>';
254
+
255
+ return $xml;
256
+ }
257
+
258
+
259
+ public function renderProductXmlRow($productModel,$orders_per_product,$xmlAttrs='action="insert"'){
260
+ $helper=Mage::helper('autocompleteplus_autosuggest');
261
+ $categoriesNames='';
262
+ $categories = $productModel->getCategoryCollection()
263
+ ->addAttributeToSelect('name');
264
+
265
+ foreach($categories as $category) {
266
+ $category_name = $category->getId();
267
+ $parent = $category->getParentCategory();
268
+ try{
269
+ $threshold = 100;
270
+ while ($parent){
271
+ $category_name .= ':'.$parent->getId();
272
+ if ($parent->getId() == Mage::app()->getStore(Mage::app()->getStore()->getStoreId())->getRootCategoryId()){
273
+ break;
274
+ }
275
+ if ($parent->getLevel() == 0){
276
+ $category_name = '';
277
+ break;
278
+ }
279
+ $parent = $parent->getParentCategory();
280
+
281
+ $threshold--;
282
+ if ($threshold == 0)
283
+ break;
284
+ }
285
+ }catch(Exception $e){
286
+ $category_name .= ':Exception - ' . $e->getMessage();
287
+ }
288
+ if ($category_name != ''){
289
+ $categoriesNames .= $category_name . ';';
290
+ }
291
+ }
292
+
293
+ $price =$this->_getPrice($productModel);
294
+ $sku =$productModel->getSku();
295
+ $stock_status =$productModel->isInStock();
296
+ $stockItem = $productModel->getStockItem();
297
+
298
+ if($stockItem){
299
+ if($stockItem->getIsInStock() && $stock_status){
300
+ $sell=1;
301
+ }else{
302
+ $sell=0;
303
+ }
304
+ }else{
305
+ if($stock_status){
306
+ $sell=1;
307
+ }else{
308
+ $sell=0;
309
+ }
310
+ }
311
+
312
+ $productUrl = ''; // getting the product's url according to the store_id
313
+
314
+ $is_getUrlPath_supported = true;
315
+ if (method_exists('Mage' , 'getVersionInfo')){ // getUrlPath is not supported on EE 1.13... & 1.14...
316
+ $edition_info = Mage::getVersionInfo();
317
+ if ($edition_info['major'] == 1 && $edition_info['minor'] >= 13){
318
+ $is_getUrlPath_supported = false;
319
+ }
320
+ }
321
+
322
+ if (method_exists($productModel, 'getUrlPath') && $is_getUrlPath_supported){
323
+ $productUrl = $productModel->getUrlPath();
324
+ if ($productUrl != ''){
325
+ $productUrl = Mage::getUrl($productUrl);
326
+ }
327
+ }
328
+ if ($productUrl == '' && method_exists($productModel, 'getProductUrl')){
329
+ $productUrl = $productModel->getProductUrl();
330
+ // $pattern = '/\?___.*/';
331
+ // $productUrl = preg_replace($pattern, '', $productUrl);
332
+ }
333
+ if ($productUrl == '') {
334
+ $productUrl = Mage::helper('catalog/product')->getProductUrl($productModel->getId());
335
+ }
336
+
337
+ $prodId =$productModel->getId();
338
+ $prodDesc =$productModel->getDescription();
339
+ $prodShortDesc =$productModel->getShortDescription();
340
+ $prodName =$productModel->getName();
341
+ $visibility =$productModel->getVisibility();
342
+
343
+ if(defined('Mage_Catalog_Model_Product_Status::STATUS_ENABLED')){
344
+ if ($productModel->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED){
345
+ $product_status = 1;
346
+ } else {
347
+ $product_status = 0;
348
+ }
349
+ } else {
350
+ if ($productModel->getStatus() == 1){
351
+ $product_status = 1;
352
+ } else {
353
+ $product_status = 0;
354
+ }
355
+ }
356
+
357
+ try{
358
+ if(in_array($this->imageField,$this->standardImageFields)){
359
+ $prodImage =Mage::helper('catalog/image')->init($productModel, $this->imageField);
360
+ }else{
361
+ $function='get'.$this->imageField;
362
+ $prodImage =$productModel->$function();
363
+ }
364
+
365
+ try{
366
+ $product_media_config = Mage::getModel('catalog/product_media_config');
367
+ $product_base_image = $product_media_config->getMediaUrl($productModel->getImage());
368
+ } catch (Exception $e){
369
+ $product_base_image = '';
370
+ }
371
+
372
+ }catch(Exception $e){
373
+ $prodImage='';
374
+ }
375
+
376
+ if($productModel->getTypeID()=='configurable'){
377
+ $configurableAttributes=$this->_getConfigurableAttributes($productModel);
378
+
379
+ $configurableChildren=$this->_getConfigurableChildren($productModel);
380
+ try{
381
+ $priceRange=$this->_getPriceRange($productModel);
382
+ }catch(Exception $e){
383
+ $priceRange='price_min="" price_max=""';
384
+ }
385
+ } else if ($productModel->getTypeID() == 'simple'){
386
+ $simple_product_parents = $this->_getSimpleProductParent($productModel);
387
+ $priceRange='price_min="" price_max=""';
388
+ }else{
389
+ $priceRange='price_min="" price_max=""';
390
+ }
391
+
392
+ $num_of_orders = ($orders_per_product != null && array_key_exists($prodId, $orders_per_product)) ? $orders_per_product[$prodId] : 0;
393
+ $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.' >';
394
+ $row.='<description><![CDATA['.$prodDesc.']]></description>';
395
+ $row.='<short><![CDATA['.$prodShortDesc.']]></short>';
396
+ $row.='<name><![CDATA['.$prodName.']]></name>';
397
+ $row.='<sku><![CDATA['.$sku.']]></sku>';
398
+
399
+ $summaryData = Mage::getModel('review/review_summary')
400
+ ->setStoreId($productModel->getStoreId())
401
+ ->load($prodId);
402
+ if (($summaryData['rating_summary'] || $summaryData['rating_summary'] == 0) && $summaryData['rating_summary'] != ''){
403
+ $row.='<review><![CDATA['.$summaryData['rating_summary'].']]></review>';
404
+ }
405
+
406
+ $new_from_date = $productModel->getNewsFromDate();
407
+ $new_to_date = $productModel->getNewsToDate();
408
+ if ($new_from_date){
409
+ $row.='<newfrom><![CDATA['.Mage::getModel('core/date')->timestamp($new_from_date).']]></newfrom>';
410
+ if ($new_to_date){
411
+ $row.='<newto><![CDATA['.Mage::getModel('core/date')->timestamp($new_to_date).']]></newto>';
412
+ }
413
+ }
414
+
415
+ $row.= '<purchase_popularity><![CDATA['.$num_of_orders.']]></purchase_popularity>';
416
+ $row.='<product_status><![CDATA['.$product_status.']]></product_status>';
417
+
418
+ try{
419
+ $row.='<creation_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getCreatedAt()).']]></creation_date>';
420
+ $row.='<updated_date><![CDATA['.Mage::getModel('core/date')->timestamp($productModel->getUpdatedAt()).']]></updated_date>';
421
+ } catch(Exception $e){
422
+ }
423
+
424
+ if($this->useAttributes!='0'){
425
+ foreach($this->attributes as $attr){
426
+ $action=$attr->getAttributeCode();
427
+ $is_filterable=$attr->getis_filterable();
428
+ $attribute_label = $attr->getStoreLabel($productModel->getStoreId());
429
+
430
+ if($attr->getfrontend_input()=='select'){
431
+ if($productModel->getData($action)){
432
+ if (method_exists($productModel, 'getAttributeText')){
433
+ $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
434
+ <attribute_values><![CDATA['.$productModel->getAttributeText($action).']]></attribute_values>
435
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
436
+ </attribute>';
437
+ } else {
438
+ $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
439
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
440
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
441
+ </attribute>';
442
+ }
443
+ }
444
+ }elseif($attr->getfrontend_input()=='textarea'){
445
+ if($productModel->getData($action)){
446
+ $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
447
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
448
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
449
+ </attribute>';
450
+ }
451
+ }elseif($attr->getfrontend_input()=='price'){
452
+ if($productModel->getData($action)){
453
+ $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
454
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
455
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
456
+ </attribute>';
457
+ }
458
+ }elseif($attr->getfrontend_input()=='text'){
459
+ if($productModel->getData($action)){
460
+ $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
461
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
462
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
463
+ </attribute>';
464
+ }
465
+ }elseif($attr->getfrontend_input()=='multiselect'){
466
+ if($productModel->getData($action)){
467
+ $values=$productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
468
+ $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'">
469
+ <attribute_values><![CDATA['.$productModel->getData($action).']]></attribute_values>
470
+ <attribute_label><![CDATA['.$attribute_label.']]></attribute_label>
471
+ </attribute>';
472
+ }
473
+ }
474
+ }
475
+
476
+ if($productModel->getTypeID()=='configurable' && count($configurableAttributes)>0){
477
+ foreach($configurableAttributes as $attrName=>$confAttrN){
478
+ if(is_array($confAttrN) && array_key_exists('values',$confAttrN)){
479
+ $values=implode(' , ',$confAttrN['values']);
480
+ $row.='<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
481
+ }
482
+ }
483
+
484
+ $row.='<simpleproducts><![CDATA['.implode(',',$configurableChildren).']]></simpleproducts>';
485
+ }
486
+
487
+ if($productModel->getTypeID() == 'simple'){
488
+ $row.='<product_parents><![CDATA['.implode(',',$simple_product_parents).']]></product_parents>';
489
+ }
490
+ }
491
+
492
+ $row.='<categories><![CDATA['.$categoriesNames.']]></categories>';
493
+ $row.='</product>';
494
+ return $helper->escapeXml($row);
495
+ }
496
+
497
+ private function _makeUpdateRow($batch,$attributes){
498
+
499
+ $productId = $batch['product_id'];
500
+
501
+ $sku = $batch['sku'];
502
+
503
+ $storeId = $batch['store_id'];
504
+
505
+ $updatedate = $batch['update_date'];
506
+
507
+ $action = $batch['action'];
508
+
509
+ $currency=Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
510
+
511
+ if($productId!=null){
512
+
513
+ $productModel=Mage::getModel('catalog/product')
514
+
515
+ ->setStoreId($storeId)
516
+
517
+ ->load($productId);
518
+
519
+ if($productModel==null){
520
+
521
+ return '';
522
+
523
+ }
524
+
525
+ }else{
526
+
527
+ /*
528
+
529
+ * FIX - Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::loadAllAttributes()
530
+
531
+ */
532
+
533
+ $productModel=Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
534
+
535
+ if($productModel==null){
536
+
537
+ return '';
538
+
539
+ }
540
+
541
+ $productModel = $productModel->setStoreId($storeId);
542
+
543
+ $productId=$productModel->getId();
544
+ }
545
+
546
+ if($productModel==null){
547
+
548
+ return '';
549
+
550
+ }
551
+
552
+ $price =$this->getPrice($productModel);
553
+
554
+ $sku =$productModel->getSku();
555
+
556
+ $status =$productModel->isInStock();
557
+
558
+ $stockItem = $productModel->getStockItem();
559
+
560
+ $categoriesNames='';
561
+
562
+ $categories = $productModel->getCategoryCollection()
563
+ ->addAttributeToSelect('name');
564
+
565
+ foreach($categories as $category) {
566
+ $categoriesNames.=$category->getName().':'.$category->getId().';';
567
+ }
568
+
569
+ if($stockItem->getIsInStock()&&$status)
570
+ {
571
+ $sell=1;
572
+ }else{
573
+ $sell=0;
574
+ }
575
+
576
+ $productUrl =Mage::helper('catalog/product')->getProductUrl($productId);
577
+
578
+ $prodId =$productModel->getId();
579
+
580
+ $prodDesc =$productModel->getDescription();
581
+
582
+ $prodShortDesc =$productModel->getShortDescription();
583
+
584
+ $prodName =$productModel->getName();
585
+
586
+ $visibility =$productModel->getVisibility();
587
+
588
+ try{
589
+
590
+ if(in_array($this->imageField,$this->standardImageFields)){
591
+
592
+ $prodImage =Mage::helper('catalog/image')->init($productModel, $this->imageField);
593
+
594
+ }else{
595
+
596
+ $function='get'.$this->imageField;
597
+
598
+ $prodImage =$productModel->$function();
599
+
600
+ }
601
+
602
+ }catch(Exception $e){
603
+
604
+ $prodImage='';
605
+
606
+ }
607
+
608
+ if($productModel->getTypeID()=='configurable'){
609
+
610
+ $configurableAttributes=$this->_getConfigurableAttributes($productModel);
611
+
612
+ try{
613
+
614
+ $priceRange=$this->_getPriceRange($productModel);
615
+
616
+ }catch(Exception $e){
617
+
618
+ $priceRange='price_min="" price_max=""';
619
+
620
+ }
621
+
622
+ }else{
623
+
624
+ $priceRange='price_min="" price_max=""';
625
+
626
+ }
627
+
628
+ $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.'" >';
629
+
630
+ $row.='<description><![CDATA['.$prodDesc.']]></description>';
631
+
632
+ $row.='<short><![CDATA['.$prodShortDesc.']]></short>';
633
+
634
+ $row.='<name><![CDATA['.$prodName.']]></name>';
635
+
636
+ $row.='<sku><![CDATA['.$sku.']]></sku>';
637
+
638
+ if($attributes!=null){
639
+
640
+ foreach($attributes as $attr){
641
+
642
+
643
+
644
+ $action=$attr->getAttributeCode();
645
+
646
+
647
+
648
+ $is_filterable=$attr->getis_filterable();
649
+
650
+
651
+
652
+ if($attr->getfrontend_input()=='select'){
653
+
654
+
655
+
656
+ if($productModel->getData($action)){
657
+
658
+ $row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getAttributeText($action).']]></attribute>';
659
+
660
+ }
661
+
662
+
663
+
664
+ }elseif($attr->getfrontend_input()=='textarea'){
665
+
666
+
667
+
668
+ if($productModel->getData($action)){
669
+
670
+ $row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
671
+
672
+ }
673
+
674
+ }elseif($attr->getfrontend_input()=='price'){
675
+
676
+
677
+
678
+ if($productModel->getData($action)){
679
+
680
+ $row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
681
+
682
+ }
683
+
684
+ }elseif($attr->getfrontend_input()=='text'){
685
+
686
+
687
+
688
+ if($productModel->getData($action)){
689
+
690
+ $row.='<attribute is_filterable="'.$is_filterable.'" attribute_type="'.$attr->getfrontend_input().'" name="'.$attr->getAttributeCode().'"><![CDATA['.$productModel->getData($action).']]></attribute>';
691
+
692
+ }
693
+
694
+ }elseif($attr->getfrontend_input()=='multiselect'){
695
+
696
+ if($productModel->getData($action)){
697
+
698
+ $values=$productModel->getResource()->getAttribute($action)->getFrontend()->getValue($productModel);
699
+
700
+
701
+
702
+ $row.='<attribute is_filterable="'.$is_filterable.'" name="'.$attr->getAttributeCode().'"><![CDATA['.$values.']]></attribute>';
703
+
704
+ }
705
+
706
+ }
707
+
708
+ }
709
+
710
+ if($productModel->getTypeID()=='configurable' && count($configurableAttributes)>0){
711
+
712
+ foreach($configurableAttributes as $attrName=>$confAttrN){
713
+
714
+ if(is_array($confAttrN) && array_key_exists('values',$confAttrN)){
715
+
716
+ $values=implode(' , ',$confAttrN['values']);
717
+
718
+ $row.='<attribute is_configurable="1" is_filterable="'.$confAttrN['is_filterable'].'" name="'.$attrName.'"><![CDATA['.$values.']]></attribute>';
719
+
720
+ }
721
+
722
+
723
+
724
+ }
725
+
726
+ }
727
+
728
+ }
729
+
730
+ $row.='<categories><![CDATA['.$categoriesNames.']]></categories>';
731
+
732
+ $row.='</product>';
733
+
734
+
735
+
736
+ return $row;
737
+
738
+ }
739
+
740
+ private function _makeRemoveRow($batch){
741
+ $updatedate = $batch['update_date'];
742
+ $action = $batch['action'];
743
+ $sku = $batch['sku'];
744
+ $productId = $batch['product_id'];
745
+ $storeId = $batch['store_id'];
746
+
747
+ $row='<product updatedate="'.$updatedate.'" action="'.$action.'" id="'.$productId.'" storeid="'.$storeId.'">';
748
+ $row.='<sku><![CDATA['.$sku.']]></sku>';
749
+ $row.='<id><![CDATA['.$productId.']]></id>';
750
+ $row.='</product>';
751
+ return $row;
752
+ }
753
+
754
+ private function _getConfigurableChildren($product){
755
+
756
+ $childProducts = Mage::getModel('catalog/product_type_configurable')
757
+ ->getUsedProducts(null,$product);
758
+ $ids=array();
759
+
760
+ foreach($childProducts as $cProd){
761
+ $ids[]=$cProd->getId();
762
+ }
763
+
764
+ //echo '<pre>';print_r($ids); die;
765
+
766
+ return $ids;
767
+ }
768
+
769
+ private function _getSimpleProductParent($product){
770
+ try{
771
+ $parent_products_ids_list = Mage::getModel('catalog/product_type_configurable')
772
+ ->getParentIdsByChild($product->getId());
773
+
774
+ return $parent_products_ids_list;
775
+ } catch(Exception $e){
776
+ return array();
777
+ }
778
+ }
779
+
780
+ private function _getConfigurableAttributes($product){
781
+
782
+ try{
783
+ // Collect options applicable to the configurable product
784
+ $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
785
+
786
+ $attributeOptions = array();
787
+
788
+ foreach ($productAttributeOptions as $productAttribute) {
789
+ $attributeFull = Mage::getModel('eav/config')->getAttribute('catalog_product', $productAttribute['attribute_code']);
790
+
791
+ foreach ($productAttribute['values'] as $attribute) {
792
+
793
+ $attributeOptions[$productAttribute['store_label']]['values'][] = $attribute['store_label'];
794
+
795
+ }
796
+
797
+ $attributeOptions[$productAttribute['store_label']]['is_filterable']=$attributeFull['is_filterable'];
798
+ $attributeOptions[$productAttribute['store_label']]['frontend_input']=$attributeFull['frontend_input'];
799
+ }
800
+ return $attributeOptions;
801
+
802
+ }catch(Exception $e){
803
+ return array();
804
+ }
805
+
806
+ }
807
+
808
+ private function _getPriceRange($product){
809
+ $max = '';
810
+ $min = '';
811
+
812
+ $pricesByAttributeValues = array();
813
+ $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
814
+ $basePrice = $product->getFinalPrice();
815
+ $items = $attributes->getItems();
816
+ if (is_array($items)){
817
+ foreach ($items as $attribute){
818
+ $prices = $attribute->getPrices();
819
+ if (is_array($prices)){
820
+ foreach ($prices as $price){
821
+ if ($price['is_percent']){ //if the price is specified in percents
822
+ $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
823
+ }
824
+ else { //if the price is absolute value
825
+ $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
826
+ }
827
+ }
828
+ }
829
+ }
830
+ }
831
+
832
+ $simple = $product->getTypeInstance()->getUsedProducts();
833
+ foreach ($simple as $sProduct){
834
+ $totalPrice = $basePrice;
835
+ foreach ($attributes as $attribute){
836
+ $value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode());
837
+ if (isset($pricesByAttributeValues[$value])){
838
+ $totalPrice += $pricesByAttributeValues[$value];
839
+ }
840
+ }
841
+ if(!$max || $totalPrice > $max)
842
+ $max = $totalPrice;
843
+ if(!$min || $totalPrice < $min)
844
+ $min = $totalPrice;
845
+ }
846
+ $priceRange='price_min="'.$min.'" price_max="'.$max.'"';
847
+ return $priceRange;
848
+ }
849
+
850
+ private function _getOrdersPerProduct($store_id, $product_id_list, $month_interval){
851
+
852
+ if (count($product_id_list) <= 0)
853
+
854
+ return null;
855
+
856
+ $id_str = implode(',', $product_id_list);
857
+
858
+ $query = Mage::getResourceModel('sales/order_item_collection');
859
+
860
+ $select = $query->getSelect()->reset(Zend_Db_Select::COLUMNS)
861
+
862
+ ->columns(array('product_id','SUM(qty_ordered)'))
863
+
864
+ ->where(new Zend_Db_Expr('store_id = ' . $store_id))
865
+
866
+ ->where(new Zend_Db_Expr('product_id IN ('.$id_str.')'))
867
+
868
+ ->where(new Zend_Db_Expr('created_at BETWEEN NOW() - INTERVAL '.$month_interval.' MONTH AND NOW()'))
869
+
870
+ ->group(array('product_id'));
871
+
872
+
873
+
874
+ $resource = Mage::getSingleton('core/resource');
875
+
876
+ $readConnection = $resource->getConnection('core_read');
877
+
878
+ $results = $readConnection->fetchAll($select);
879
+
880
+
881
+
882
+ $orders_per_product = array();
883
+
884
+ foreach ($results as $res){
885
+
886
+ $orders_per_product[$res['product_id']] = (int)$res['SUM(qty_ordered)'];
887
+
888
+ }
889
+
890
+ return $orders_per_product;
891
+
892
+ }
893
+
894
+ private function _getPrice($product){
895
+ $price = 0;
896
+ $helper=Mage::helper('autocompleteplus_autosuggest');
897
+ if ($product->getTypeId()=='grouped'){
898
+ $helper->prepareGroupedProductPrice($product);
899
+ $_minimalPriceValue = $product->getPrice();
900
+ if($_minimalPriceValue){
901
+ $price=$_minimalPriceValue;
902
+ }
903
+ }elseif($product->getTypeId()=='bundle'){
904
+ if(!$product->getFinalPrice()){
905
+ $price=$helper->getBundlePrice($product);
906
+ }else{
907
+ $price=$product->getFinalPrice();
908
+ }
909
+ }else{
910
+ $price =$product->getFinalPrice();
911
+ }
912
+ if(!$price){
913
+ $price=0;
914
+ }
915
+ return $price;
916
+ }
917
+
918
+ /**
919
+
920
+ * @param $storeId
921
+
922
+ */
923
+
924
+ private function _initCatalogCommonFields($storeId)
925
+ {
926
+ $this->imageField=Mage::getStoreConfig('autocompleteplus/config/imagefield');
927
+
928
+ if (!$this->imageField) {
929
+ $this->imageField = 'thumbnail';
930
+ }
931
+
932
+ $this->useAttributes = Mage::getStoreConfig('autocompleteplus/config/attributes');
933
+
934
+ $this->currency = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
935
+
936
+ $this->standardImageFields = array('image', 'small_image', 'thumbnail');
937
+
938
+ $productScheme = Mage::getModel('catalog/product');
939
+
940
+ if($this->useAttributes!='0'){
941
+ $this->attributes = Mage::getResourceModel('eav/entity_attribute_collection')
942
+
943
+ ->setEntityTypeFilter($productScheme->getResource()->getTypeId())
944
+
945
+ ->addFieldToFilter('is_user_defined', '1') // This can be changed to any attribute code
946
+
947
+ ->load(false);
948
+ }
949
+
950
+ }
951
+
952
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Config.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Layer.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 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
+ */
36
+ public function getProductCollection()
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;
45
+ }
46
+
47
+ return $collection;
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)
57
+ {
58
+ $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
59
+ ->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
60
+ ->setStore(Mage::app()->getStore())
61
+ ->addMinimalPrice()
62
+ ->addFinalPrice()
63
+ ->addTaxPercents()
64
+ ->addStoreFilter()
65
+ ->addUrlRewrite();
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
+ */
77
+ public function getStateKey()
78
+ {
79
+ if ($this->_stateKey === null) {
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Config.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/Notifications.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
18
+ class Autocompleteplus_Autosuggest_Model_Mysql4_Notifications extends Mage_Core_Model_Mysql4_Abstract
19
+ {
20
+ protected function _construct()
21
+ {
22
+ $this->_init('autocompleteplus_autosuggest/notifications', 'notification_id');
23
+ }
24
+
25
+ /**
26
+ * @param array $notifications
27
+ */
28
+ public function addNotifications($notifications)
29
+ {
30
+ $write = $this->_getWriteAdapter();
31
+ foreach ($notifications as $item) {
32
+ $select = $write->select()
33
+ ->from($this->getMainTable())
34
+ ->where('type=?', $item['type'])
35
+ ->where('timestamp=?', $item['timestamp']);
36
+ $row = $write->fetchRow($select);
37
+ if (!$row) {
38
+ $write->insert($this->getMainTable(), $item);
39
+ }
40
+ }
41
+ }
42
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Notifications/Collection.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
18
+ class Autocompleteplus_Autosuggest_Model_Mysql4_Notifications_Collection
19
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
20
+ {
21
+ protected function _construct()
22
+ {
23
+ $this->_init('autocompleteplus_autosuggest/notifications');
24
+ }
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
+
37
+ public function addActiveFilter()
38
+ {
39
+ $this->getSelect()
40
+ ->where('is_active=?', 1);
41
+ return $this;
42
+ }
43
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Pusher.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Mysql4/Pusher/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Observer.php ADDED
@@ -0,0 +1,630 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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=(string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
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
+ try{
182
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
183
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
184
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
185
+ $tblExist = $write->showTableStatus($_tableprefix.'autocompleteplus_batches');
186
+
187
+ if(!$tblExist){return;}
188
+ try{
189
+ if ($storeId == 0 && method_exists($product, 'getStoreIds')){
190
+ $product_stores = $product->getStoreIds();
191
+ } else {
192
+ $product_stores = array($storeId);
193
+ }
194
+ } catch (Exception $e){
195
+ $product_stores = array($storeId);
196
+ }
197
+
198
+ foreach ($product_stores as $product_store){
199
+ $sqlFetch = 'SELECT * FROM '. $_tableprefix.'autocompleteplus_batches WHERE product_id = ? AND store_id=?';
200
+ $updates = $write->fetchAll($sqlFetch, array($productId, $product_store));
201
+
202
+ if($updates&&count($updates) != 0){
203
+ $sql = 'UPDATE '. $_tableprefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id = ? AND store_id=?';
204
+ $write->query($sql, array($dt, "update", $productId, $product_store));
205
+ }else{
206
+ $sql='INSERT INTO '. $_tableprefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
207
+ $write->query($sql, array($productId, $product_store, $dt, "update", $sku));
208
+ }
209
+ try{
210
+ $helper = Mage::helper('autocompleteplus_autosuggest');
211
+ if ($helper->isChecksumTableExists()){
212
+ $checksum = $helper->calculateChecksum($product);
213
+ $helper->updateSavedProductChecksum($_tableprefix, $read, $write, $productId, $sku, $product_store, $checksum);
214
+ }
215
+ } catch (Exception $e){
216
+ Mage::log('checksum failed - ' . $e->getMessage(), null, 'autocompleteplus.log');
217
+ }
218
+ }
219
+
220
+ }catch(Exception $e){
221
+ Mage::log($e->getMessage(),null,'autocompleteplus.log');
222
+ }
223
+ }
224
+
225
+ private function __getProductData($product){
226
+
227
+ $sku =$product->getSku();
228
+
229
+ $status=$product->isInStock();
230
+ $stockItem = $product->getStockItem();
231
+ $storeId=$product->getStoreId();
232
+
233
+
234
+ if($stockItem&&$stockItem->getIsInStock()&&$status)
235
+ {
236
+ $sell=1;
237
+ }else{
238
+ $sell=0;
239
+ }
240
+
241
+ $price =$this->getPrice($product);
242
+
243
+ $productUrl =Mage::helper('catalog/product')->getProductUrl($product->getId());
244
+ $prodDesc =$product->getDescription();
245
+ $prodShortDesc =$product->getShortDescription();
246
+ $prodName =$product->getName();
247
+
248
+ try{
249
+
250
+ if(in_array($this->imageField,$this->standardImageFields)){
251
+ $prodImage =Mage::helper('catalog/image')->init($product, $this->imageField);
252
+ }else{
253
+ $function='get'.$this->imageField;
254
+ $prodImage =$product->$function();
255
+ }
256
+
257
+ }catch(Exception $e){
258
+ $prodImage='';
259
+ }
260
+
261
+
262
+ $visibility =$product->getVisibility();
263
+
264
+
265
+ $row='<product store="'.$storeId.'" currency="'.$this->currency.'" visibility="'.$visibility.'" price="'.$price.'" url="'.$productUrl.'" thumbs="'.$prodImage.'" selleable="'.$sell.'" action="update" >';
266
+ $row.='<description><![CDATA['.$prodDesc.']]></description>';
267
+ $row.='<short><![CDATA['.$prodShortDesc.']]></short>';
268
+ $row.='<name><![CDATA['.$prodName.']]></name>';
269
+ $row.='<sku><![CDATA['.$sku.']]></sku>';
270
+ $row.='</product>';
271
+
272
+ return $row;
273
+ }
274
+
275
+
276
+
277
+ private function __makeSafeString($str){
278
+ $str=strip_tags($str);
279
+ $str=str_replace('"','',$str);
280
+ $str=str_replace("'",'',$str);
281
+ $str=str_replace('/','',$str);
282
+ $str=str_replace('<','',$str);
283
+ $str=str_replace('>','',$str);
284
+ $str=str_replace('\\','',$str);
285
+ return $str;
286
+ }
287
+
288
+ private function __sendUpdate($data){
289
+
290
+ $ch=curl_init();
291
+ $command='http://magento.autocompleteplus.com/update';
292
+ curl_setopt($ch, CURLOPT_URL, $command);
293
+ curl_setopt($ch, CURLOPT_HEADER, 0);
294
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
295
+ curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
296
+ //curl_setopt($ch,CURLOPT_POST,0);
297
+ if(!empty($data)){
298
+ curl_setopt_array($ch, array(
299
+ CURLOPT_POSTFIELDS => $data,
300
+ ));
301
+ }
302
+
303
+ return curl_exec($ch);
304
+ }
305
+
306
+
307
+ private function getPrice($product){
308
+ $price = 0;
309
+ $helper=Mage::helper('autocompleteplus_autosuggest');
310
+ if ($product->getTypeId()=='grouped'){
311
+
312
+ $helper->prepareGroupedProductPrice($product);
313
+ $_minimalPriceValue = $product->getPrice();
314
+
315
+ if($_minimalPriceValue){
316
+ $price=$_minimalPriceValue;
317
+ }
318
+
319
+ }elseif($product->getTypeId()=='bundle'){
320
+
321
+ if(!$product->getFinalPrice()){
322
+ $price=$helper->getBundlePrice($product);
323
+ }else{
324
+ $price=$product->getFinalPrice();
325
+ }
326
+
327
+ }else{
328
+ $price =$product->getFinalPrice();
329
+ }
330
+
331
+ if(!$price){
332
+ $price=0;
333
+ }
334
+ return $price;
335
+ }
336
+
337
+ public function catalog_product_delete_before($observer){
338
+
339
+ $product=$observer->getProduct();
340
+
341
+ $storeId=$product->getStoreId();
342
+
343
+ $productId=$product->getId();
344
+
345
+ $sku=$product->getSku();
346
+
347
+ $this->__writeproductDeletion($sku,$productId,$storeId, $product);
348
+
349
+ }
350
+
351
+ private function __writeproductDeletion($sku, $productId, $storeId, $product = null){
352
+ $dt = strtotime('now');
353
+ //$mysqldate = date( 'Y-m-d h:m:s', $dt );
354
+
355
+ try{
356
+ // if ($productId == null){
357
+ // Mage::log('__writeproductDeletion - identifier is null', null, 'autocompleteplus.log');
358
+ // return;
359
+ // }
360
+
361
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
362
+
363
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
364
+
365
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
366
+
367
+ $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_batches');
368
+
369
+ if(!$tblExist){return;}
370
+
371
+ try{
372
+ $helper = Mage::helper('autocompleteplus_autosuggest');
373
+ if ($helper->isChecksumTableExists()){
374
+ try{
375
+ if (!$product){
376
+ $product = Mage::getModel('catalog/product')->load($productId);
377
+ }
378
+ if ($storeId == 0 && method_exists($product, 'getStoreIds')){
379
+ $product_stores = $product->getStoreIds();
380
+ } else {
381
+ $product_stores = array($storeId);
382
+ }
383
+ } catch (Exception $e){
384
+ Mage::log('exception raised: ' . $e->getMessage(),null,'autocompleteplus.log');
385
+ $product_stores = array($storeId);
386
+ }
387
+ if ($sku == null){
388
+ $sku = 'dummy_sku';
389
+ }
390
+
391
+ foreach ($product_stores as $product_store){
392
+ $sqlFetch = 'SELECT * FROM '. $_tableprefix.'autocompleteplus_batches WHERE product_id = ? AND store_id=?';
393
+ $updates = $read->fetchAll($sqlFetch, array($productId, $product_store));
394
+
395
+ if($updates && count($updates) != 0){
396
+ $sql = 'UPDATE '. $_tableprefix.'autocompleteplus_batches SET update_date=?,action=? WHERE product_id = ? AND store_id = ?';
397
+ $write->query($sql, array($dt, "remove", $productId, $product_store));
398
+ } else {
399
+ $sql='INSERT INTO '. $_tableprefix.'autocompleteplus_batches (product_id,store_id,update_date,action,sku) VALUES (?,?,?,?,?)';
400
+ $write->query($sql, array($productId, $product_store, $dt, "remove", $sku));
401
+ }
402
+
403
+ $helper->updateDeletedProductChecksum($_tableprefix, $read, $write, $productId, $sku, $product_store);
404
+ }
405
+ }
406
+ } catch (Exception $e){
407
+ Mage::log('__writeproductDeletion failed on remove - ' . $e->getMessage(), null, 'autocompleteplus.log');
408
+ }
409
+
410
+ }catch(Exception $e){
411
+ Mage::log('__writeproductDeletion: ' . $e->getMessage(),null,'autocompleteplus.log');
412
+ }
413
+ }
414
+
415
+ public function adminSessionUserLoginSuccess()
416
+ {
417
+ $notifications = array();
418
+ /** @var Autocompleteplus_Autosuggest_Helper_Data $helper */
419
+ $helper = Mage::helper('autocompleteplus_autosuggest');
420
+ $command = "http://magento.autocompleteplus.com/ext_info?u=". $helper->getUUID();
421
+ $res = $helper->sendCurl($command);
422
+ $result = json_decode($res);
423
+ if (isset($result->alerts)) {
424
+ foreach ($result->alerts as $alert) {
425
+ $notification = array(
426
+ 'type' => (string) $alert->type,
427
+ 'message' => (string) $alert->message,
428
+ 'timestamp' => (string) $alert->timestamp,
429
+ );
430
+ if (isset($alert->subject)) {
431
+ $notification['subject'] = (string) $alert->subject;
432
+ }
433
+ $notifications[] = $notification;
434
+ }
435
+ }
436
+ if (!empty($notifications)) {
437
+ Mage::getResourceModel('autocompleteplus_autosuggest/notifications')->addNotifications($notifications);
438
+ }
439
+ $this->sendNotificationMails();
440
+ }
441
+
442
+ public function sendNotificationMails()
443
+ {
444
+ /** @var Autocompleteplus_Autosuggest_Model_Mysql4_Notifications_Collection $notifications */
445
+ $notifications = Mage::getModel('autocompleteplus_autosuggest/notifications')->getCollection();
446
+ $notifications->addTypeFilter('email')->addActiveFilter();
447
+ foreach ($notifications as $notification) {
448
+ $this->_sendStatusMail($notification);
449
+ }
450
+ }
451
+
452
+ /**
453
+ * @param Autocompleteplus_Autosuggest_Model_Notifications $notification
454
+ */
455
+ protected function _sendStatusMail($notification)
456
+ {
457
+
458
+ /** @var Autocompleteplus_Autosuggest_Helper_Data $helper */
459
+ $helper = Mage::helper('autocompleteplus_autosuggest');
460
+ // Getting site owner email
461
+ $storeMail = $helper->getConfigDataByFullPath('autocompleteplus/config/store_email');
462
+ if ($storeMail) {
463
+ $emailTemplate = Mage::getModel('core/email_template');
464
+
465
+ $emailTemplate->loadDefault('autosuggest_status_notification');
466
+ $emailTemplate->setTemplateSubject($notification->getSubject());
467
+
468
+ // Get General email address (Admin->Configuration->General->Store Email Addresses)
469
+ $emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_general/email'));
470
+ $emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_general/name'));
471
+
472
+ $emailTemplateVariables['message'] = $notification->getMessage();
473
+ $emailTemplate->send($storeMail, null, $emailTemplateVariables);
474
+ $notification->setIsActive(0)
475
+ ->save();
476
+ }
477
+ }
478
+
479
+ /**
480
+ * The generic webhook service caller
481
+ * @param Varien_Event_Observer $observer
482
+ * @return void
483
+ */
484
+ public function webhook_service_call($observer)
485
+ {
486
+ $curl = new Varien_Http_Adapter_Curl();
487
+ $curl->setConfig(array(
488
+ 'timeout' => static::WEBHOOK_CURL_TIMEOUT_LENGTH
489
+ ));
490
+
491
+ $curl->write(Zend_Http_Client::GET, $this->_getWebhookObjectUri());
492
+ $curl->read();
493
+ $curl->close();
494
+ }
495
+
496
+ /**
497
+ * Returns the quote id if it exists, otherwise it will
498
+ * return the last order id. This only is set in the session
499
+ * when an order has been recently completed. Therefore
500
+ * this call may also return null.
501
+ * @return string|null
502
+ */
503
+ public function getQuoteId()
504
+ {
505
+ if($quoteId = Mage::getSingleton('checkout/session')->getQuoteId()){
506
+ return $quoteId;
507
+ }
508
+
509
+ return $this->getOrder()->getQuoteId();
510
+ }
511
+
512
+ /**
513
+ * Get the order associated with the previous quote id
514
+ * used as a fallback when the quote is no longer available
515
+ * @return Mage_Sales_Model_Order
516
+ */
517
+ public function getOrder()
518
+ {
519
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
520
+ return Mage::getModel('sales/order')->load($orderId);
521
+ }
522
+
523
+ /**
524
+ * Return a label for webhooks based on the current
525
+ * controller route. This cannot be handled by layout
526
+ * XML because the layout engine may not be init in all
527
+ * future uses of the webhook
528
+ * @return string|void
529
+ */
530
+ public function getWebhookEventLabel()
531
+ {
532
+ $request = Mage::app()->getRequest();
533
+ $route = $request->getRouteName();
534
+ $controller = $request->getControllerName();
535
+ $action = $request->getActionName();
536
+
537
+ if($route != 'checkout'){
538
+ return;
539
+ }
540
+
541
+ if($controller == 'cart' && $action == 'index'){
542
+ return 'cart';
543
+ }
544
+
545
+ if($controller == 'onepage' && $action == 'index'){
546
+ return 'checkout';
547
+ }
548
+
549
+ if($controller == 'onepage' && $action == 'success'){
550
+ return 'success';
551
+ }
552
+
553
+ }
554
+
555
+ /**
556
+ * Create the webhook URI
557
+ * @return string
558
+ */
559
+ protected function _getWebhookObjectUri()
560
+ {
561
+ $helper = Mage::helper('autocompleteplus_autosuggest');
562
+
563
+ $parameters = array(
564
+ 'event' =>$this->getWebhookEventLabel(),
565
+ 'UUID' =>$helper->getUUID(),
566
+ 'key' =>$helper->getKey(),
567
+ 'store_id' =>Mage::app()->getStore()->getStoreId(),
568
+ 'st' =>$helper->getSessionId(),
569
+ 'cart_token' =>$this->getQuoteId(),
570
+ 'serp' =>'',
571
+ 'cart_product' => $this->getCartContentsAsJson()
572
+ );
573
+
574
+ return static::AUTOCOMPLETEPLUS_WEBHOOK_URI . '?' . http_build_query($parameters,'','&');
575
+ }
576
+
577
+ /**
578
+ * JSON encode the cart contents
579
+ * @return string
580
+ */
581
+ public function getCartContentsAsJson()
582
+ {
583
+ return json_encode($this->_getVisibleItems());
584
+ }
585
+
586
+ /**
587
+ * Format visible cart contents into a multidimensional keyed array
588
+ * @return array
589
+ */
590
+ protected function _getVisibleItems()
591
+ {
592
+ if($cartItems = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems()){
593
+ return $this->_buildCartArray($cartItems);
594
+ }
595
+
596
+ return $this->_buildCartArray($this->getOrder()->getAllVisibleItems());
597
+ }
598
+
599
+ /**
600
+ * Return a formatted array of quote or order items
601
+ * @param array $cartItems
602
+ * @todo fork this for quote items vs sales order items
603
+ * @return array
604
+ */
605
+ protected function _buildCartArray($cartItems)
606
+ {
607
+ $items = array();
608
+
609
+ foreach($cartItems as $item){
610
+ /**
611
+ * @todo fix this check by providing separate models for MSMQI and MSMOI
612
+ */
613
+ if($item instanceof Mage_Sales_Model_Order_Item){
614
+ $quantity = (int)$item->getQtyOrdered();
615
+ } else {
616
+ $quantity = $item->getQty();
617
+ }
618
+ $items[] = array(
619
+ 'product_id' =>$item->getProduct()->getId(),
620
+ 'price' =>$item->getProduct()->getFinalPrice(),
621
+ 'quantity' =>$quantity,
622
+ 'currency' =>Mage::app()->getStore()->getCurrentCurrencyCode(),
623
+ 'attribution' =>$item->getAddedFromSearch()
624
+ );
625
+ }
626
+
627
+ return $items;
628
+ }
629
+
630
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Pusher.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
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
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Resource/Fulltext/Collection.php ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_CatalogSearch
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Fulltext Collection
30
+ *
31
+ * @category Mage
32
+ * @package Mage_CatalogSearch
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Autocompleteplus_Autosuggest_Model_Resource_Fulltext_Collection extends Mage_Catalog_Model_Resource_Product_Collection
36
+ {
37
+ private $list_ids = array();
38
+ private $is_fulltext_enabled = false;
39
+
40
+ private $is_layered_enabled = false;
41
+
42
+ public function __construct($resource = null, array $args = array()) {
43
+ $layered = Mage::getStoreConfig('autocompleteplus/config/layered');
44
+ if (isset($layered) && $layered == '1') {
45
+ $this->is_layered_enabled = true;
46
+ }
47
+ parent::__construct($resource, $args);
48
+ }
49
+
50
+ /**
51
+ * Retrieve query model object
52
+ *
53
+ * @return Mage_CatalogSearch_Model_Query
54
+ */
55
+ protected function _getQuery()
56
+ {
57
+ if ($this->is_layered_enabled) {
58
+ // do nothing
59
+ } else {
60
+ return Mage::helper('catalogsearch')->getQuery();
61
+ }
62
+ }
63
+
64
+ /* compatibility with GoMage extension */
65
+ public function getSearchedEntityIds(){
66
+ return $this->list_ids;
67
+ }
68
+
69
+ /**
70
+ * Add search query filter
71
+ *
72
+ * @param string $query
73
+ * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
74
+ */
75
+ public function addSearchFilter($query)
76
+ {
77
+ if ($this->is_layered_enabled) {
78
+ // do nothing
79
+ } else {
80
+ $helper=Mage::helper('autocompleteplus_autosuggest');
81
+ // $enabledFulltext=$helper->getConfigDataByFullPath('autocompleteplus/config/enabled_fulltext');
82
+
83
+ $key = $helper->getUUID();
84
+ $storeId = Mage::app()->getStore()->getStoreId();
85
+
86
+ $server_end_point = $helper->getServerEndPoint();
87
+ if ($server_end_point){
88
+ $url_domain = $server_end_point . '/ma_search';
89
+ } else {
90
+ $url_domain = 'http://magento.instantsearchplus.com/ma_search';
91
+ }
92
+
93
+ $extension_version = (string)Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
94
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
95
+ $url = $url_domain.'?q='.urlencode($query).'&p=1&products_per_page=1000&v='.$extension_version.'&store_id='.$storeId.'&UUID='.$key.'&h='.$site_url;
96
+
97
+ $resp = $helper->sendCurl($url);
98
+ $response_json = json_decode($resp);
99
+ if (array_key_exists('fulltext_disabled', $response_json)){
100
+ $enabledFulltext = !$response_json->fulltext_disabled;
101
+ } else {
102
+ $enabledFulltext = false;
103
+ }
104
+ if ($enabledFulltext){
105
+ $enabledFulltext = ((array_key_exists('id_list', $response_json)) &&
106
+ (array_key_exists('total_results', $response_json))) ? true : false;
107
+ }
108
+ Mage::getSingleton('core/session')->unsIsFullTextEnable();
109
+ Mage::getSingleton('core/session')->unsIspSearchAlternatives();
110
+ Mage::getSingleton('core/session')->unsIspSearchResultsFor();
111
+
112
+ if ($enabledFulltext){
113
+ $this->is_fulltext_enabled = true;
114
+ // InstantSearch+ js file will be injected to the search result page
115
+ Mage::getSingleton('core/session')->setIsFullTextEnable(true);
116
+ // recording the query for the current 'core/session' to check it when injecting the magento_full_text.js
117
+ Mage::getSingleton('core/session')->setIspUrlEncodeQuery(urlencode($query));
118
+
119
+ if (array_key_exists('alternatives', $response_json) && $response_json->alternatives){
120
+ Mage::getSingleton('core/session')->setIspSearchAlternatives($response_json->alternatives);
121
+ } else {
122
+ Mage::getSingleton('core/session')->setIspSearchAlternatives(false);
123
+ }
124
+ if (array_key_exists('results_for', $response_json) && $response_json->results_for){
125
+ Mage::getSingleton('core/session')->setIspSearchResultsFor($response_json->results_for);
126
+ } else {
127
+ Mage::getSingleton('core/session')->setIspSearchResultsFor(false);
128
+ }
129
+
130
+ if($response_json->total_results){
131
+ $id_list = $response_json->id_list;
132
+ $product_ids = array();
133
+ //validate received ids
134
+ foreach($id_list as $id){
135
+ if($id != null && is_numeric($id)){
136
+ $product_ids[] = $id;
137
+ }
138
+ }
139
+ $this->list_ids = $product_ids;
140
+ $idStr = (count($product_ids)>0) ? implode(',',$product_ids) : '0';
141
+ }else{
142
+ $idStr = '0';
143
+ }
144
+
145
+ if (array_key_exists('server_endpoint', $response_json)){
146
+ if ($server_end_point != $response_json->server_endpoint){
147
+ $helper->setServerEndPoint($response_json->server_endpoint);
148
+ }
149
+ }
150
+
151
+ $this->getSelect()->where('e.entity_id IN ('.$idStr.')');
152
+ }else{
153
+ Mage::getSingleton('core/session')->setIsFullTextEnable(false);
154
+ $this->is_fulltext_enabled = false;
155
+ }
156
+
157
+ if(!$enabledFulltext){
158
+ //adding if fulltext search disabled then write regular flow
159
+ Mage::getSingleton('catalogsearch/fulltext')->prepareResult();
160
+
161
+ $this->getSelect()->joinInner(
162
+ array('search_result' => $this->getTable('catalogsearch/result')),
163
+ $this->getConnection()->quoteInto(
164
+ 'search_result.product_id=e.entity_id AND search_result.query_id=?',
165
+ $this->_getQuery()->getId()
166
+ ),
167
+ array('relevance' => 'relevance')
168
+ );
169
+
170
+ }
171
+ }
172
+ return $this;
173
+ }
174
+
175
+ /**
176
+ * Set Order field
177
+ *
178
+ * @param string $attribute
179
+ * @param string $dir
180
+ * @return Mage_Catalog_Model_Resource_Product_Collection
181
+ */
182
+ public function setOrder($attribute, $dir = parent::SORT_ORDER_ASC){
183
+ if ($this->is_layered_enabled) {
184
+ // do nothing
185
+ } else {
186
+ if($this->is_fulltext_enabled && $attribute == 'relevance'){
187
+ $dir = parent::SORT_ORDER_ASC;
188
+ $id_str = (count($this->list_ids) > 0) ? implode(',', $this->list_ids) : '0';
189
+ if (!empty($id_str)) {
190
+ $sort = "FIELD(e.entity_id, {$id_str}) {$dir}";
191
+ $this->getSelect()->order(new Zend_Db_Expr($sort));
192
+ }
193
+ } else {
194
+ return parent::setOrder($attribute, $dir);
195
+ }
196
+ }
197
+
198
+ return $this;
199
+ }
200
+
201
+ /**
202
+ * Stub method for campatibility with other search engines
203
+ *
204
+ * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
205
+ */
206
+ public function setGeneralDefaultQuery()
207
+ {
208
+ return $this;
209
+ }
210
+ }
app/code/local/Autocompleteplus/Autosuggest/Model/Service.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
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
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/PushController.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Adminhtml_PushController extends Mage_Adminhtml_Controller_Action{
4
+
5
+ public function startpushAction(){
6
+
7
+ $service = Mage::getModel('autocompleteplus_autosuggest/service');
8
+
9
+ $service->populatePusher();
10
+
11
+ $this->getResponse()->setBody($this->getLayout()->createBlock('autocompleteplus_autosuggest/adminhtml_process')->toHtml());
12
+ $this->getResponse()->sendResponse();
13
+ }
14
+
15
+ protected function _isAllowed()
16
+ {
17
+ return Mage::getSingleton('admin/session')->isAllowed('system/config/autocompleteplus');
18
+ }
19
+
20
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/Adminhtml/RedirectController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Autocompleteplus_Autosuggest_Adminhtml_RedirectController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function gotoAction(){
6
+ //
7
+ $helper=Mage::helper('autocompleteplus_autosuggest');
8
+
9
+ $kwys=$helper->getBothKeys();
10
+
11
+ if(!isset($kwys['uuid']) || !isset($kwys['authkey'])){
12
+ $url='https://magento.instantsearchplus.com/login';
13
+ }else{
14
+ $url='http://magento.instantsearchplus.com/ma_dashboard?site_id='.$kwys['uuid'].'&authentication_key='.$kwys['authkey'];
15
+ }
16
+
17
+ header("Location: ".$url);
18
+
19
+ die;
20
+ }
21
+
22
+ protected function _isAllowed()
23
+ {
24
+ return Mage::getSingleton('admin/session')->isAllowed('system/config/autocompleteplus');
25
+ }
26
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/CatalogSearch/ResultController.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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();
14
+ $this->renderLayout();
15
+ } else {
16
+ parent::indexAction();
17
+ }
18
+ }
19
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/CatalogsearchController.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * 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
+ */
37
+ protected function _getSession()
38
+ {
39
+ return Mage::getSingleton('catalog/session');
40
+ }
41
+ /**
42
+ * Display search result
43
+ */
44
+ public function indexAction()
45
+ {
46
+ //die('moshe');
47
+
48
+ $query = Mage::helper('catalogsearch')->getQuery();
49
+ /* @var $query Mage_CatalogSearch_Model_Query */
50
+
51
+ $query->setStoreId(Mage::app()->getStore()->getId());
52
+
53
+ if ($query->getQueryText()) {
54
+ if (Mage::helper('catalogsearch')->isMinQueryLength()) {
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
+ }
76
+
77
+ Mage::helper('catalogsearch')->checkNotes();
78
+
79
+ $this->loadLayout();
80
+ $this->_initLayoutMessages('catalog/session');
81
+ $this->_initLayoutMessages('checkout/session');
82
+ $this->renderLayout();
83
+
84
+ if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
85
+ $query->save();
86
+ }
87
+ }
88
+ else {
89
+ $this->_redirectReferer();
90
+ }
91
+ }
92
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/CategoriesController.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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)
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
+ } else {
57
+ $category = Mage::getModel('catalog/category')->load($node->getId());
58
+ $result['url_path'] = $category->getUrl();
59
+ }
60
+
61
+ foreach ($node->getChildren() as $child) {
62
+ $result['children'][] = $this->nodeToArray($child,$mediaUrl,$baseUrl);
63
+ }
64
+
65
+ return $result;
66
+ }
67
+
68
+ private function load_tree(){
69
+
70
+ $tree = Mage::getResourceSingleton('catalog/category_tree')
71
+ ->load();
72
+
73
+ $post = $this->getRequest()->getParams();
74
+
75
+ if (array_key_exists('store', $post))
76
+ $store = $post['store'];
77
+ else
78
+ $store = Mage::app()->getStore()->getStoreId();
79
+
80
+ $parentId = Mage::app()->getStore($store)->getRootCategoryId();
81
+
82
+ $tree = Mage::getResourceSingleton('catalog/category_tree')
83
+ ->load();
84
+
85
+ $root = $tree->getNodeById($parentId);
86
+
87
+ if($root && $root->getId() == 1) {
88
+ $root->setName(Mage::helper('catalog')->__('Root'));
89
+ }
90
+
91
+ $collection = Mage::getModel('catalog/category')->getCollection()
92
+ ->setStoreId($store)
93
+ ->addAttributeToSelect('name')
94
+ ->addAttributeToSelect('url_path')
95
+ ->addAttributeToSelect('image')
96
+ ->addAttributeToSelect('thumbnail')
97
+ ->addAttributeToSelect('description')
98
+ ->addAttributeToFilter('is_active',array('eq'=>true));
99
+
100
+ $tree->addCollectionData($collection, true);
101
+
102
+ $mediaUrl= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
103
+ $baseUrl= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
104
+
105
+ return $this->nodeToArray($root,$mediaUrl,$baseUrl);
106
+
107
+ }
108
+
109
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/LayeredController.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsController.php ADDED
@@ -0,0 +1,749 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ const MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION = 250;
20
+
21
+ public function sendAction(){
22
+ set_time_limit (1800);
23
+
24
+ $post = $this->getRequest()->getParams();
25
+
26
+ $startInd = $post['offset'];
27
+
28
+ $count = $post['count'];
29
+
30
+ $storeId=isset($post['store']) ? $post['store'] : '';
31
+ if ($storeId == ''){
32
+ $storeId=isset($post['store_id']) ? $post['store_id'] : '';
33
+ }
34
+
35
+ $orders=isset($post['orders']) ? $post['orders'] : '';
36
+
37
+ $month_interval=isset($post['month_interval']) ? $post['month_interval'] : '';
38
+
39
+ $checksum=isset($post['checksum']) ? $post['checksum'] : '';
40
+
41
+ $catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
42
+
43
+ $xml=$catalogModel->renderCatalogXml($startInd,$count,$storeId,$orders,$month_interval,$checksum);
44
+
45
+ header('Content-type: text/xml');
46
+ echo $xml;
47
+ die;
48
+ }
49
+
50
+ public function sendupdatedAction(){
51
+
52
+ date_default_timezone_set('Asia/Jerusalem');
53
+
54
+ set_time_limit (1800);
55
+
56
+ $post = $this->getRequest()->getParams();
57
+
58
+ $count = $post['count'];
59
+
60
+ if(!isset($post['from'])){
61
+ $returnArr=array(
62
+ 'status'=>'failure',
63
+ 'error_code'=>'767',
64
+ 'error_details'=>'The "from" parameter is mandatory'
65
+ );
66
+ echo json_encode($returnArr);
67
+ die;
68
+ }
69
+ $from = $post['from'];
70
+
71
+ if(isset($post['to'])){
72
+ $to = $post['to'];
73
+ }else{
74
+ $to = strtotime('now');
75
+ }
76
+
77
+ $storeId='';
78
+
79
+ if(isset($post['store_id'])){
80
+ $storeId = $post['store_id'];
81
+ }
82
+
83
+ $catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
84
+
85
+ $xml=$catalogModel->renderUpdatesCatalogXml($count,$from,$to,$storeId);
86
+
87
+ header('Content-type: text/xml');
88
+ echo $xml;
89
+ die;
90
+
91
+ }
92
+
93
+ private function __checkAccess(){
94
+
95
+ $post = $this->getRequest()->getParams();
96
+
97
+ $key=Mage::getModel('autocompleteplus_autosuggest/observer')->getUUID();
98
+
99
+ if(isset($post['key'])&&$post['key']==$key){
100
+ return true;
101
+ }else{
102
+ return false;
103
+ }
104
+
105
+ }
106
+
107
+ public function checkinstallAction(){
108
+
109
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
110
+
111
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
112
+
113
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
114
+
115
+ $sql='SELECT * FROM `'.$_tableprefix.'autocompleteplus_config` WHERE `id` =1';
116
+
117
+ $licenseData=$read->fetchAll($sql);
118
+
119
+ $key=$licenseData[0]['licensekey'];
120
+
121
+ if(strlen($key)>0&&$key!='failed'){
122
+ echo 'the key exists';
123
+ }else{
124
+ echo 'no key inside';
125
+ }
126
+
127
+ }
128
+
129
+ public function versAction(){
130
+ $mage = Mage::getVersion();
131
+ $ext = (string) Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version;
132
+ try{
133
+ $num_of_products = Mage::getModel('catalog/product')->getCollection()
134
+ ->addStoreFilter(Mage::app()->getStore()->getStoreId())
135
+ ->getSize();
136
+ } catch (Exception $e){
137
+ $num_of_products = -1;
138
+ }
139
+
140
+ if (method_exists('Mage' , 'getEdition')){
141
+ $edition = Mage::getEdition();
142
+ } else {
143
+ $edition = 'Community';
144
+ }
145
+
146
+ $helper = Mage::helper('autocompleteplus_autosuggest');
147
+ $uuid = $helper->getUUID();
148
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
149
+ $store_id = Mage::app()->getStore()->getStoreId();
150
+
151
+ $result = array('mage' => $mage,
152
+ 'ext' => $ext,
153
+ 'num_of_products' => $num_of_products,
154
+ 'edition' => $edition,
155
+ 'uuid' => $uuid,
156
+ 'site_url' => $site_url,
157
+ 'store_id' => $store_id
158
+ );
159
+
160
+ $post = $this->getRequest()->getParams();
161
+
162
+ if (array_key_exists('modules', $post))
163
+ $get_modules = $post['modules'];
164
+ else
165
+ $get_modules = false;
166
+ if ($get_modules){
167
+ try{
168
+ $modules_array = array();
169
+ foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module) {
170
+ if ($module->codePool != 'core' && $module->active == 'true'){
171
+ $modules_array[$name] = $module;
172
+ }
173
+ }
174
+ } catch (Exception $e){
175
+ $modules_array = array();
176
+ }
177
+ $result['modules'] = $modules_array;
178
+ }
179
+ echo json_encode($result);die;
180
+ }
181
+
182
+ public function getNumOfProductsAction(){
183
+ $post = $this->getRequest()->getParams();
184
+ if (array_key_exists('store_id', $post))
185
+ $store_id = $post['store_id'];
186
+ else if (array_key_exists('store', $post))
187
+ $store_id = $post['store'];
188
+ else
189
+ $store_id = Mage::app()->getStore()->getStoreId();
190
+
191
+ $num_of_products = -1;
192
+ $num_of_disabled_products = -1;
193
+ $num_of_searchable_products = -1;
194
+ $num_of_searchable_products2 = -1;
195
+ try{
196
+ $num_of_products = Mage::getModel('catalog/product')->getCollection()
197
+ ->addStoreFilter($store_id)
198
+ ->addAttributeToFilter('status', array('eq' => 1)) // Mage_Catalog_Model_Product_Status::STATUS_ENABLED
199
+ ->getSize();
200
+ $num_of_disabled_products = Mage::getModel('catalog/product')->getCollection()
201
+ ->addStoreFilter($store_id)
202
+ ->addAttributeToFilter('status', array('eq' => 2)) // Mage_Catalog_Model_Product_Status::STATUS_DISABLE
203
+ ->getSize();
204
+ try{
205
+ $num_of_searchable_products = Mage::getModel('catalog/product')->getCollection()
206
+ ->addStoreFilter($store_id)
207
+ ->addAttributeToFilter('status', array('eq' => 1)) // Mage_Catalog_Model_Product_Status::STATUS_ENABLED
208
+ ->addAttributeToFilter(array(
209
+ array('attribute'=>'visibility', 'finset'=>3), // visibility Search
210
+ array('attribute'=>'visibility', 'finset'=>4), // visibility Catalog, Search
211
+ ))
212
+ ->getSize();
213
+ } catch (Exception $e){}
214
+ $num_of_searchable_products2 = Mage::getModel('catalog/product')->getCollection()
215
+ ->addStoreFilter($store_id)
216
+ ->addAttributeToFilter('status', array('eq' => 1)) // Mage_Catalog_Model_Product_Status::STATUS_ENABLED
217
+ ->addAttributeToFilter('visibility', array('in' => array(3,4))) // visibility Catalog, Catalog Search
218
+ ->getSize();
219
+ } catch (Exception $e){}
220
+
221
+ $helper = Mage::helper('autocompleteplus_autosuggest');
222
+ $uuid = $helper->getUUID();
223
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
224
+
225
+ $result = array('num_of_products' => $num_of_products,
226
+ 'num_of_disabled_products' => $num_of_disabled_products,
227
+ 'num_of_searchable_products' => $num_of_searchable_products,
228
+ 'num_of_searchable_products2' => $num_of_searchable_products2,
229
+ 'uuid' => $uuid,
230
+ 'site_url' => $site_url,
231
+ 'store_id' => $store_id
232
+ );
233
+ echo json_encode($result);
234
+ die;
235
+ }
236
+
237
+ public function getConflictAction(){
238
+ $post = $this->getRequest()->getParams();
239
+ if (array_key_exists('all', $post))
240
+ $get_all_conflicts = $post['all'];
241
+ else
242
+ $get_all_conflicts = false;
243
+
244
+ $helper = Mage::helper('autocompleteplus_autosuggest');
245
+ if ($get_all_conflicts){
246
+ $result = $helper->getExtensionConflict(true);
247
+ }else{
248
+ $result = $helper->getExtensionConflict();
249
+ }
250
+ echo json_encode($result);die;
251
+ }
252
+
253
+ public function getstoresAction(){
254
+
255
+ $helper=Mage::helper('autocompleteplus_autosuggest');
256
+
257
+ echo $helper->getMultiStoreDataJson();
258
+ die;
259
+ }
260
+
261
+ public function updateemailAction(){
262
+
263
+ $helper=Mage::helper('autocompleteplus_autosuggest');
264
+
265
+ $data = $this->getRequest()->getPost();
266
+
267
+ $email=$data['email'];
268
+ $uuid=$helper->getUUID();
269
+
270
+ Mage::getModel('core/config')->saveConfig('autocompleteplus/config/store_email',$email);
271
+
272
+ $params=array(
273
+ 'uuid'=>$uuid,
274
+ 'email'=>$email
275
+ );
276
+
277
+ $command="http://magento.autocompleteplus.com/ext_update_email";
278
+
279
+ $res=$helper->sendPostCurl($command,$params);
280
+
281
+ $result=json_decode($res);
282
+
283
+ if($result->status=='OK'){
284
+ echo 'Your email address was updated!';
285
+ }
286
+ }
287
+
288
+ public function updatesitemapAction(){
289
+
290
+ $helper=Mage::helper('autocompleteplus_autosuggest');
291
+
292
+ $key=$helper->getUUID();
293
+
294
+ $url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
295
+
296
+ if($key!='InstallFailedUUID' && $key!='failed'){
297
+
298
+ $stemapUrl='Sitemap:http://magento.instantsearchplus.com/ext_sitemap?u='.$key.PHP_EOL;
299
+
300
+ $robotsPath=Mage::getBaseDir().DS.'robots.txt';
301
+
302
+ $write=false;
303
+
304
+ if(file_exists($robotsPath)){
305
+ if( strpos(file_get_contents($robotsPath),$stemapUrl) == false) {
306
+ $write=true;
307
+ }
308
+ }else{
309
+
310
+ if(is_writable(Mage::getBaseDir())){
311
+
312
+ //create robots sitemap
313
+ file_put_contents($robotsPath,$stemapUrl);
314
+ }else{
315
+
316
+ //write message that directory is not writteble
317
+ $command="http://magento.autocompleteplus.com/install_error";
318
+
319
+ $data=array();
320
+ $data['site']=$url;
321
+ $data['msg']='Directory '.Mage::getBaseDir().' is not writable.';
322
+ $res=$helper->sendPostCurl($command,$data);
323
+ }
324
+ }
325
+
326
+ if($write){
327
+ if(is_writable($robotsPath)){
328
+
329
+ //append sitemap
330
+ file_put_contents($robotsPath, $stemapUrl, FILE_APPEND | LOCK_EX);
331
+ }else{
332
+ //write message that file is not writteble
333
+ $command="http://magento.autocompleteplus.com/install_error";
334
+
335
+ $data=array();
336
+ $data['site']=$url;
337
+ $data['msg']='File '.$robotsPath.' is not writable.';
338
+ $res=$helper->sendPostCurl($command,$data);
339
+ }
340
+ }
341
+
342
+ }
343
+ }
344
+
345
+ protected function _setUUID($key){
346
+
347
+ try{
348
+
349
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
350
+
351
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
352
+
353
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
354
+
355
+ $tblExist=$write->showTableStatus($_tableprefix.'autocompleteplus_config');
356
+
357
+ if(!$tblExist){return;}
358
+
359
+ $sqlFetch ='SELECT * FROM '. $_tableprefix.'autocompleteplus_config WHERE id = 1';
360
+
361
+ $updates=$write->fetchAll($sqlFetch);
362
+
363
+ if($updates&&count($updates)!=0){
364
+
365
+ $sql='UPDATE '. $_tableprefix.'autocompleteplus_config SET licensekey=? WHERE id = 1';
366
+
367
+ $write->query($sql, array($key));
368
+
369
+ }else{
370
+
371
+ $sql='INSERT INTO '. $_tableprefix.'autocompleteplus_config (licensekey) VALUES (?)';
372
+
373
+ $write->query($sql, array($key));
374
+
375
+ }
376
+
377
+
378
+ }catch(Exception $e){
379
+ Mage::log($e->getMessage(),null,'autocompleteplus.log');
380
+ }
381
+
382
+ }
383
+
384
+ public function getIspUuidAction(){
385
+
386
+ $helper = Mage::helper('autocompleteplus_autosuggest');
387
+
388
+ echo $helper->getUUID();
389
+ }
390
+
391
+ public function geterrormessageAction(){
392
+
393
+ $helper = Mage::helper('autocompleteplus_autosuggest');
394
+
395
+ echo $helper->getErrormessage();
396
+ }
397
+
398
+ public function setIspUuidAction(){
399
+ $helper = Mage::helper('autocompleteplus_autosuggest');
400
+ $url_domain = 'http://magento.instantsearchplus.com/update_uuid';
401
+ $storeId = Mage::app()->getStore()->getStoreId();
402
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
403
+ $url = $url_domain . '?store_id=' . $storeId . '&site_url=' . $site_url;
404
+
405
+ $helper = Mage::helper('autocompleteplus_autosuggest');
406
+ $resp = $helper->sendCurl($url);
407
+ $response_json = json_decode($resp);
408
+
409
+ if (array_key_exists('uuid', $response_json)){
410
+ if (strlen($response_json->uuid) == 36 && substr_count($response_json->uuid, '-') == 4){
411
+ $this->_setUUID($response_json->uuid);
412
+ }
413
+ }
414
+ }
415
+
416
+ public function checkDeletedAction(){
417
+ $helper = Mage::helper('autocompleteplus_autosuggest');
418
+ if (!$helper->isChecksumTableExists()){
419
+ return;
420
+ }
421
+ $time_stamp = time();
422
+
423
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
424
+ $table_prefix = (string)Mage::getConfig()->getTablePrefix();
425
+
426
+ $post = $this->getRequest()->getParams();
427
+ if (array_key_exists('store_id', $post)){
428
+ $store_id = $post['store_id'];
429
+ }else{
430
+ $store_id = Mage::app()->getStore()->getStoreId(); // default
431
+ }
432
+
433
+ $sql_fetch = 'SELECT identifier FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE store_id=?';
434
+ $updates = $read->fetchPairs($sql_fetch, array($store_id)); // empty array if fails
435
+ if (empty($updates)){
436
+ return;
437
+ }
438
+
439
+ $checksum_ids = array_keys($updates); // array of all checksum table identifiers
440
+ $collection = Mage::getResourceModel('catalog/product_collection');
441
+ $collection->addFieldToFilter('entity_id',array('in'=>$checksum_ids));
442
+ $found_ids = $collection->getAllIds();
443
+
444
+ $removed_products_list = array_diff($checksum_ids, $found_ids); // list of identifiers that are not present in the store (removed at some point)
445
+ $removed_ids = array();
446
+
447
+ // removing non-existing identifiers from checksum table
448
+ if (!empty($removed_products_list)){
449
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
450
+ $sql_delete = 'DELETE FROM ' . $table_prefix . 'autocompleteplus_checksum WHERE identifier IN (' . implode(',', $removed_products_list) . ')';
451
+ $write->query($sql_delete);
452
+
453
+ foreach ($removed_products_list as $product_id){
454
+ $helper->deleteProductFromTables($read, $write, $table_prefix, $product_id, $store_id);
455
+ $removed_ids[] = $product_id;
456
+ }
457
+ }
458
+
459
+ $args = array('removed_ids' => $removed_ids,
460
+ 'uuid' => $helper->getUUID(),
461
+ 'store_id' => $store_id,
462
+ 'latency' => time() - $time_stamp, // seconds
463
+ );
464
+ echo json_encode($args); // returning the summary
465
+ }
466
+
467
+ public function checksumAction(){
468
+ $helper = Mage::helper('autocompleteplus_autosuggest');
469
+
470
+ $checksum_server = $helper->getServerUrl();
471
+ if (!$helper->isChecksumTableExists()){
472
+ $helper->ispErrorLog('checksum table not exist');
473
+ exit(json_encode(array('status' => 'checksum table not exist')));
474
+ }
475
+ $max_exe_time = -1;
476
+
477
+ $post = $this->getRequest()->getParams();
478
+ if (array_key_exists('store_id', $post)){
479
+ $store_id = $post['store_id'];
480
+ }else{
481
+ $store_id = Mage::app()->getStore()->getStoreId(); // default
482
+ }
483
+ if (array_key_exists('count', $post)){
484
+ $count = $post['count'];
485
+ }else{
486
+ $count = self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION; // default
487
+ }
488
+ if (array_key_exists('offset', $post))
489
+ $start_index = $post['offset'];
490
+ else
491
+ $start_index = 0; // default
492
+ if (array_key_exists('timeout', $post))
493
+ $php_timeout = $post['timeout'];
494
+ else
495
+ $php_timeout = -1; // default
496
+ if (array_key_exists('is_single', $post))
497
+ $is_single = $post['is_single'];
498
+ else
499
+ $is_single = 0; // default
500
+
501
+ if ($count > self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION && $php_timeout != -1){
502
+ $max_exe_time = ini_get('max_execution_time');
503
+ ini_set('max_execution_time', $php_timeout); // 1 hour ~ 60*60
504
+ }
505
+
506
+ $uuid = $helper->getUUID();
507
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
508
+
509
+ $collection = Mage::getModel('catalog/product')->getCollection();
510
+ if ($store_id){
511
+ $collection->addStoreFilter($store_id);
512
+ }
513
+ $num_of_products = $collection->getSize();
514
+
515
+ if ($count + $start_index > $num_of_products){
516
+ $count = $num_of_products - $start_index;
517
+ }
518
+
519
+ // sending log to the server
520
+ $log_msg = 'Update checksum is starting...';
521
+ $log_msg .= (' number of products in this store: ' . $num_of_products . ' | from: ' . $start_index . ', to: ' . ($start_index + $count));
522
+ $server_url = $checksum_server . '/magento_logging_record';
523
+ $request = $server_url . '?uuid=' . $uuid . '&site_url=' . $site_url . '&msg=' . urlencode($log_msg);
524
+ if ($store_id)
525
+ $request .= '&store_id=' . $store_id;
526
+ $resp = $helper->sendCurl($request);
527
+
528
+ $start_time = time();
529
+ $num_of_updated_checksum = 0;
530
+ if($count > self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION){
531
+ $iter = $start_index;
532
+ while ($iter < $count){
533
+ // start updating the checksum table if needed
534
+ $num_of_updated_checksum += $helper->compareProductsChecksum($iter, self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION, $store_id);
535
+ $iter += self::MAX_NUM_OF_PRODUCTS_CHECKSUM_ITERATION;
536
+ }
537
+ } else {
538
+ // start updating the checksum table if needed
539
+ $num_of_updated_checksum = $helper->compareProductsChecksum($start_index, $count, $store_id);
540
+ }
541
+
542
+ $process_time = time() - $start_time;
543
+ // sending confirmation/summary to the server
544
+ $args = array( 'uuid' => $uuid,
545
+ 'site_url' => $site_url,
546
+ 'store_id' => $store_id,
547
+ 'updated_checksum' => $num_of_updated_checksum,
548
+ 'total_checksum' => $count,
549
+ 'num_of_products' => $num_of_products,
550
+ 'start_index' => $start_index,
551
+ 'end_index' => $start_index + $count,
552
+ 'count' => $count,
553
+ 'ext_version' => (string)Mage::getConfig()->getNode()->modules->Autocompleteplus_Autosuggest->version,
554
+ 'mage_version' => Mage::getVersion(),
555
+ 'latency' => $process_time, // seconds
556
+ );
557
+ if ($is_single)
558
+ $args['is_single'] = 1;
559
+ echo json_encode($args); // returning the summary
560
+
561
+ $resp = $helper->sendCurl($checksum_server . '/magento_checksum_iterator?' . http_build_query($args));
562
+
563
+ if ($max_exe_time != -1){ // restore php max execution time
564
+ ini_set('max_execution_time', $max_exe_time);
565
+ }
566
+ }
567
+
568
+ public function connectionAction(){
569
+ exit('1');
570
+ }
571
+
572
+ public function changeSerpAction(){
573
+ try {
574
+ $helper = Mage::helper('autocompleteplus_autosuggest');
575
+ $site_url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
576
+ define("SOAP_WSDL", $site_url . '/api/?wsdl');
577
+ define("SOAP_USER", "instant_search");
578
+ define("SOAP_PASS", "Rilb@kped3");
579
+
580
+ $client = new SoapClient(SOAP_WSDL, array('trace' => 1, 'cache_wsdl' => 0));
581
+ $session = $client->login(SOAP_USER, SOAP_PASS);
582
+
583
+ $post = $this->getRequest()->getParams();
584
+ if (array_key_exists('new_serp', $post)){
585
+ $is_new_serp = $post['new_serp'];
586
+ }else{
587
+ $is_new_serp = '0'; // default
588
+ }
589
+
590
+ if (array_key_exists('store_id', $post)){
591
+ $store_id = $post['store_id'];
592
+ $scope_name = 'stores';
593
+ }else{ // default
594
+ $store_id = '0';
595
+ $scope_name = 'default';
596
+ }
597
+
598
+ try {
599
+
600
+ if ($is_new_serp == 'status'){
601
+ $current_state = $client->call($session, 'autocompleteplus_autosuggest.getLayeredSearchConfig', array($store_id));
602
+ echo json_encode(array('current_status' => $current_state));
603
+ return;
604
+ }
605
+
606
+ if ($is_new_serp == '1'){
607
+ $status = $client->call($session, 'autocompleteplus_autosuggest.setLayeredSearchOn', array($scope_name, $store_id));
608
+ } else {
609
+ $status = $client->call($session, 'autocompleteplus_autosuggest.setLayeredSearchOff', array($scope_name, $store_id));
610
+ }
611
+ $new_state= $client->call($session, 'autocompleteplus_autosuggest.getLayeredSearchConfig', array($store_id));
612
+
613
+ $resp = array('request_state' => $is_new_serp,
614
+ 'new_state' => $new_state,
615
+ 'site_url' => $site_url,
616
+ 'status' => $status
617
+ );
618
+ echo json_encode($resp);
619
+
620
+ } catch (SoapFault $exception) {
621
+ echo json_encode(array('status' => 'exception: ' . print_r($exception, true)));
622
+ return;
623
+ }
624
+
625
+ } catch (Exception $e){
626
+ echo json_encode(array('status' => 'exception: ' . print_r($e, true)));
627
+ throw $e;
628
+ }
629
+ }
630
+
631
+ public function pushbulkAction(){
632
+
633
+ set_time_limit (1800);
634
+
635
+ $post = $this->getRequest()->getParams();
636
+
637
+ // $enabled= Mage::getStoreConfig('autocompleteplus/config/enabled');
638
+ // if($enabled=='0'){
639
+ // die('The user has disabled autocompleteplus.');
640
+ // }
641
+
642
+ $helper = Mage::helper('autocompleteplus_autosuggest');
643
+
644
+ if(!isset($post['pushid'])){
645
+
646
+ echo json_encode(array('success'=>false,'message'=>'Missing pushid!'));
647
+ die;
648
+ }
649
+
650
+ $pushid = $post['pushid'];
651
+
652
+ $pusher = Mage::getModel('autocompleteplus_autosuggest/pusher')->load($pushid);
653
+
654
+ $sent=$pusher->getSent();
655
+
656
+ if($sent==1){
657
+ echo json_encode(array('success'=>false,'message'=>'push is in process'));
658
+ die;
659
+ }elseif($sent==2){
660
+ echo json_encode(array('success'=>false,'message'=>'push was already sent'));
661
+ die;
662
+ }else{
663
+ $pusher->setSent(1);
664
+
665
+ $pusher->save();
666
+ }
667
+
668
+ $offset = $pusher->getoffset();
669
+
670
+ $count = 100;
671
+
672
+ $storeId=$pusher->getstore_id();
673
+
674
+ $to_send = $pusher->getto_send();
675
+
676
+ $total_batches = $pusher->gettotal_batches();
677
+
678
+ $catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
679
+
680
+ $xml=$catalogModel->renderCatalogXml($offset,$count,$storeId,'','','');
681
+
682
+ $url=$helper->getConfigDataByFullPath('web/unsecure/base_url');
683
+
684
+ // setting post data and command url
685
+ $data['uuid'] = $helper->getUUID();
686
+ $data['site_url'] = $url;
687
+ $data['store_id'] = $storeId;
688
+ $data['authentication_key'] = $helper->getKey();
689
+ $data['total_batches'] = $total_batches;
690
+ $data['batch_number'] = $pusher->getbatch_number();
691
+
692
+ if ($offset+$count > $to_send) {
693
+ $data['is_last'] = 1;
694
+
695
+ $count=$to_send-$offset;
696
+ // error_log('IS LAST ' . $data['is_last']);
697
+ }
698
+
699
+ $data['products'] = $xml;
700
+
701
+ $server_url = $helper->getServerUrl();
702
+ $cmd_url = $server_url . '/magento_fetch_products';
703
+
704
+ // sending products
705
+ $res2 = $helper->sendPostCurl($cmd_url, $data);
706
+
707
+ unset($data['products']);
708
+
709
+ Mage::log(print_r($data,true), null, 'autocomplete.log',true);
710
+ Mage::log(print_r($res2,true), null, 'autocomplete.log',true);
711
+
712
+ if($res2=='ok'){
713
+ $pusher->setSent(2);
714
+
715
+ $pusher->save();
716
+
717
+ $nextPushId=$helper->getPushId();
718
+
719
+ $nextPushUrl='';
720
+
721
+ if($nextPushId!=''){
722
+ $nextPushUrl=$helper->getPushUrl($nextPushId);
723
+ }
724
+
725
+ $totalPushes= Mage::getModel('autocompleteplus_autosuggest/pusher')->getCollection()->count();
726
+
727
+ $updatedStatus='Syncing: push '.$nextPushId.'/'.$totalPushes;
728
+
729
+ $updatedSuccessStatus='Successfully synced '.$count.' products';
730
+
731
+ echo json_encode(
732
+ array(
733
+ 'success'=>true,
734
+ 'updatedStatus'=>$updatedStatus,
735
+ 'updatedSuccessStatus'=>$updatedSuccessStatus,
736
+ 'message'=>'',
737
+ 'nextPushUrl'=>$nextPushUrl,
738
+ 'count'=>$count
739
+ )
740
+ );
741
+
742
+ die;
743
+ }else{
744
+ echo json_encode(array('success'=>false,'message'=>$res2));
745
+ die;
746
+ }
747
+ }
748
+
749
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/ProductsbyidController.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_ProductsbyidController extends Mage_Core_Controller_Front_Action
18
+ {
19
+ public function getbyidAction(){
20
+
21
+ set_time_limit (1800);
22
+
23
+ $post = $this->getRequest()->getParams();
24
+
25
+ if(!isset($post['id'])){
26
+ $returnArr=array(
27
+ 'status'=>'failure',
28
+ 'error_code'=>'767',
29
+ 'error_details'=>'The "id" parameter is mandatory'
30
+ );
31
+ echo json_encode($returnArr);
32
+ die;
33
+ }
34
+
35
+ $ids = $post['id'];
36
+
37
+ $storeId = isset($post['store']) ? $post['store'] : 1;
38
+
39
+ $catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
40
+
41
+ $idsArr=explode(',',$ids);
42
+
43
+ $xml=$catalogModel->renderCatalogByIds($idsArr,$storeId);
44
+
45
+ header('Content-type: text/xml');
46
+ echo $xml;
47
+ die;
48
+ }
49
+
50
+ public function getfromidAction(){
51
+
52
+ set_time_limit (1800);
53
+
54
+ $post = $this->getRequest()->getParams();
55
+
56
+ $from_id = isset($post['id']) ? $post['id'] : 0;
57
+
58
+ $storeId = isset($post['store']) ? $post['store'] : 1;
59
+
60
+ $count = isset($post['count']) ? $post['count'] : 100;
61
+
62
+ $catalogModel=Mage::getModel('autocompleteplus_autosuggest/catalog');
63
+
64
+ $xml=$catalogModel->renderCatalogFromIds($count,$from_id,$storeId);
65
+
66
+ header('Content-type: text/xml');
67
+ echo $xml;
68
+ die;
69
+ }
70
+ }
app/code/local/Autocompleteplus/Autosuggest/controllers/SearchesController.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_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
+
25
+ // $enabled= Mage::getStoreConfig('autocompleteplus/config/enabled');
26
+ // if($enabled=='0'){
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
+
app/code/local/Autocompleteplus/Autosuggest/etc/adminhtml.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <autocompleteplus translate="label" module="autocompleteplus_autosuggest">
12
+ <title>AutocompletePlus</title>
13
+ </autocompleteplus>
14
+ </children>
15
+ </config>
16
+ </children>
17
+ </system>
18
+ </children>
19
+ </admin>
20
+ </resources>
21
+ </acl>
22
+ <menu>
23
+ <autocompleteplus>
24
+ <title>InstantSearch+</title>
25
+ <sort_order>999</sort_order>
26
+ <action>autocompleteplus/adminhtml_redirect/goto</action>
27
+ </autocompleteplus>
28
+ </menu>
29
+ </config>
app/code/local/Autocompleteplus/Autosuggest/etc/api.xml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <autocompleteplus_autosuggest translate="title" module="autocompleteplus_autosuggest">
6
+ <title>autocompleteplus_autosuggest</title>
7
+ <model>autocompleteplus_autosuggest/api</model>
8
+ <methods>
9
+ <setLayeredSearchOn translate="title" module="autocompleteplus_autosuggest">
10
+ <title>setLayeredSearchOn</title>
11
+ <acl>autocompleteplus_autosuggest/setLayeredSearchOn</acl>
12
+ </setLayeredSearchOn>
13
+ <setLayeredSearchOff translate="title" module="autocompleteplus_autosuggest">
14
+ <title>setLayeredSearchOff</title>
15
+ <acl>autocompleteplus_autosuggest/setLayeredSearchOff</acl>
16
+ </setLayeredSearchOff>
17
+ <getLayeredSearchConfig translate="title" module="autocompleteplus_autosuggest">
18
+ <title>getLayeredSearchConfig</title>
19
+ <acl>autocompleteplus_autosuggest/getLayeredSearchConfig</acl>
20
+ </getLayeredSearchConfig>
21
+ </methods>
22
+ </autocompleteplus_autosuggest>
23
+ </resources>
24
+ <v2>
25
+ <resources_function_prefix>
26
+ <autocompleteplus_autosuggest>autocompleteplus_autosuggest</autocompleteplus_autosuggest>
27
+ </resources_function_prefix>
28
+ </v2>
29
+ <acl>
30
+ <resources>
31
+ <autocompleteplus_autosuggest translate="title" module="autocompleteplus_autosuggest">
32
+ <title>Autosuggest</title>
33
+ <sort_order>2000</sort_order>
34
+ <myapimethod translate="title" module="autocompleteplus_autosuggest">
35
+ <title>setLayeredSearchOn</title>
36
+ </myapimethod>
37
+ <myapimethod translate="title" module="autocompleteplus_autosuggest">
38
+ <title>setLayeredSearchOff</title>
39
+ </myapimethod>
40
+ <myapimethod translate="title" module="autocompleteplus_autosuggest">
41
+ <title>getLayeredSearchConfig</title>
42
+ </myapimethod>
43
+ </autocompleteplus_autosuggest>
44
+ </resources>
45
+ </acl>
46
+ </api>
47
+ </config>
app/code/local/Autocompleteplus/Autosuggest/etc/cache.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <placeholders>
4
+ <autocompleteplus_autosuggest>
5
+ <block>autocompleteplus_autosuggest/inject</block>
6
+ <placeholder>AUTOCOMPLETEPLUS_INJECTION</placeholder>
7
+ <container>Enterprise_PageCache_Model_Container_Sidebar_Cart</container>
8
+ <cache_lifetime>86400</cache_lifetime>
9
+ </autocompleteplus_autosuggest>
10
+ </placeholders>
11
+ </config>
app/code/local/Autocompleteplus/Autosuggest/etc/config.xml ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Autocompleteplus_Autosuggest>
5
+ <version>2.0.7.5</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
+ <controller_action_postdispatch_checkout_cart_index>
54
+ <observers>
55
+ <autocompleteplus_autosuggest>
56
+ <class>autocompleteplus_autosuggest/observer</class>
57
+ <method>webhook_service_call</method>
58
+ </autocompleteplus_autosuggest>
59
+ </observers>
60
+ </controller_action_postdispatch_checkout_cart_index>
61
+ <controller_action_postdispatch_checkout_onepage_index>
62
+ <observers>
63
+ <autocompleteplus_autosuggest>
64
+ <class>autocompleteplus_autosuggest/observer</class>
65
+ <method>webhook_service_call</method>
66
+ </autocompleteplus_autosuggest>
67
+ </observers>
68
+ </controller_action_postdispatch_checkout_onepage_index>
69
+ <controller_action_postdispatch_checkout_onepage_success>
70
+ <observers>
71
+ <autocompleteplus_autosuggest>
72
+ <class>autocompleteplus_autosuggest/observer</class>
73
+ <method>webhook_service_call</method>
74
+ </autocompleteplus_autosuggest>
75
+ </observers>
76
+ </controller_action_postdispatch_checkout_onepage_success>
77
+ <catalog_controller_product_init>
78
+ <observers>
79
+ <autocompleteplus_autosuggest>
80
+ <class>autocompleteplus_autosuggest/observer</class>
81
+ <method>catalog_controller_product_init</method>
82
+ </autocompleteplus_autosuggest>
83
+ </observers>
84
+ </catalog_controller_product_init>
85
+ <catalog_product_save_before>
86
+ <observers>
87
+ <autocompleteplus_autosuggest>
88
+ <type>singleton</type>
89
+ <class>autocompleteplus_autosuggest/observer</class>
90
+ <method>catalog_product_save_after</method>
91
+ </autocompleteplus_autosuggest>
92
+ </observers>
93
+ </catalog_product_save_before>
94
+ <catalog_product_delete_before>
95
+ <observers>
96
+ <autocompleteplus_autosuggest>
97
+ <type>singleton</type>
98
+ <class>autocompleteplus_autosuggest/observer</class>
99
+ <method>catalog_product_delete_before</method>
100
+ </autocompleteplus_autosuggest>
101
+ </observers>
102
+ </catalog_product_delete_before>
103
+ <adminhtml_controller_catalogrule_prepare_save>
104
+ <observers>
105
+ <autocompleteplus_autosuggest>
106
+ <type>singleton</type>
107
+ <class>autocompleteplus_autosuggest/observer</class>
108
+ <method>adminhtml_controller_catalogrule_prepare_save</method>
109
+ </autocompleteplus_autosuggest>
110
+ </observers>
111
+ </adminhtml_controller_catalogrule_prepare_save>
112
+ <catalogrule_after_apply>
113
+ <observers>
114
+ <autocompleteplus_autosuggest>
115
+ <type>singleton</type>
116
+ <class>autocompleteplus_autosuggest/observer</class>
117
+ <method>catalogrule_after_apply</method>
118
+ </autocompleteplus_autosuggest>
119
+ </observers>
120
+ </catalogrule_after_apply>
121
+ <!--<admin_session_user_login_success>
122
+ <observers>
123
+ <autocompleteplus_autosuggest>
124
+ <class>Autocompleteplus_Autosuggest_Model_Observer</class>
125
+ <method>adminSessionUserLoginSuccess</method>
126
+ </autocompleteplus_autosuggest>
127
+ </observers>
128
+ </admin_session_user_login_success>-->
129
+ </events>
130
+ <resources>
131
+ <autosuggest_setup>
132
+ <setup>
133
+ <module>Autocompleteplus_Autosuggest</module>
134
+ </setup>
135
+ <connection>
136
+ <use>core_setup</use>
137
+ </connection>
138
+ </autosuggest_setup>
139
+ <autosuggest_write>
140
+ <connection>
141
+ <use>core_write</use>
142
+ </connection>
143
+ </autosuggest_write>
144
+ <autosuggest_read>
145
+ <connection>
146
+ <use>core_read</use>
147
+ </connection>
148
+ </autosuggest_read>
149
+ </resources>
150
+ <blocks>
151
+ <autocompleteplus_autosuggest>
152
+ <class>Autocompleteplus_Autosuggest_Block</class>
153
+ </autocompleteplus_autosuggest>
154
+ </blocks>
155
+ <template>
156
+ <email>
157
+ <autosuggest_status_notification module="autocompleteplus_autosuggest">
158
+ <label>Autocompleteplus status notification</label>
159
+ <file>autocompleteplus/status_notification.html</file>
160
+ <type>html</type>
161
+ </autosuggest_status_notification>
162
+ </email>
163
+ </template>
164
+ <helpers>
165
+ <autocompleteplus_autosuggest>
166
+ <class>Autocompleteplus_Autosuggest_Helper</class>
167
+ </autocompleteplus_autosuggest>
168
+ </helpers>
169
+ <sales>
170
+ <quote>
171
+ <item>
172
+ <product_attributes>
173
+ <added_from_search />
174
+ </product_attributes>
175
+ </item>
176
+ </quote>
177
+ </sales>
178
+ </global>
179
+ <frontend>
180
+ <layout>
181
+ <updates>
182
+ <autosuggest>
183
+ <file>autocompleteplus.xml</file>
184
+ </autosuggest>
185
+ </updates>
186
+ </layout>
187
+ <routers>
188
+ <autocompleteplus>
189
+ <use>standard</use>
190
+ <args>
191
+ <module>Autocompleteplus_Autosuggest</module>
192
+ <frontName>autocompleteplus</frontName>
193
+ </args>
194
+ </autocompleteplus>
195
+ <catalogsearch>
196
+ <args>
197
+ <modules>
198
+ <Autocompleteplus_Autosuggest before="Mage_CatalogSearch">Autocompleteplus_Autosuggest_CatalogSearch</Autocompleteplus_Autosuggest>
199
+ </modules>
200
+ </args>
201
+ </catalogsearch>
202
+ </routers>
203
+ </frontend>
204
+ <admin>
205
+ <routers>
206
+ <autocompleteplus>
207
+ <use>admin</use>
208
+ <args>
209
+ <module>Autocompleteplus_Autosuggest</module>
210
+ <frontName>autocompleteplus</frontName>
211
+ </args>
212
+ </autocompleteplus>
213
+ </routers>
214
+ </admin>
215
+ <adminhtml>
216
+ <layout>
217
+ <updates>
218
+ <autosuggest>
219
+ <file>autocompleteplus.xml</file>
220
+ </autosuggest>
221
+ </updates>
222
+ </layout>
223
+ </adminhtml>
224
+ <default>
225
+ <autocompleteplus>
226
+ <config>
227
+ <imagefield>thumbnail</imagefield>
228
+ <attributes>1</attributes>
229
+ <layered>0</layered>
230
+ </config>
231
+ </autocompleteplus>
232
+ </default>
233
+ </config>
app/code/local/Autocompleteplus/Autosuggest/etc/config_no_fulltext.xml ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Autocompleteplus_Autosuggest>
5
+ <version>2.0.7.5</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>autocompleteplus/adminhtml_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 ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/etc/system.xml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <autocompleteplus_autosuggest translate="label" module="autocompleteplus_autosuggest">
5
+ <label>InstantSearch+</label>
6
+ <sort_order>195</sort_order>
7
+ </autocompleteplus_autosuggest>
8
+ </tabs>
9
+ <sections>
10
+ <autocompleteplus translate="label" module="autocompleteplus_autosuggest">
11
+ <label>InstantSearch+</label>
12
+ <tab>autocompleteplus_autosuggest</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>100</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <config translate="label">
20
+ <label>General Settings</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <enabled translate="label">
28
+ <label>Enable InstantSearch+</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </enabled>
36
+ <imagefield translate="label">
37
+ <label>Magento field for product thumbnail image</label>
38
+ <frontend_type>select</frontend_type>
39
+ <source_model>autocompleteplus_autosuggest/adminhtml_attributes</source_model>
40
+ <sort_order>3</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </imagefield>
45
+ <attributes translate="label">
46
+ <label>Sync custom attributes</label>
47
+ <comment>Allow users to search by your shop custom attributes</comment>
48
+ <frontend_type>select</frontend_type>
49
+ <source_model>adminhtml/system_config_source_yesno</source_model>
50
+ <sort_order>4</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>1</show_in_store>
54
+ </attributes>
55
+ <sync translate="label">
56
+ <label>Sync products with InstantSearch+</label>
57
+ <comment>Sync store products with InstantSearch+ initially, as well as subsequent product updates</comment>
58
+ <frontend_type>button</frontend_type>
59
+ <frontend_model>autocompleteplus_autosuggest/adminhtml_sync</frontend_model>
60
+ <sort_order>21</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>1</show_in_store>
64
+ </sync>
65
+ </fields>
66
+ <comment>
67
+ &lt;b style="font-size:1.2em;" &gt;Visit InstantSearch+ Dashboard to customize additional settings.&lt;/b&gt;&lt;br&gt;
68
+ InstantSearch+ brings your users relevant personal product and searches suggestions using a dedicated world-class cloud service.
69
+ </comment>
70
+ </config>
71
+ </groups>
72
+ </autocompleteplus>
73
+ </sections>
74
+ </config>
app/code/local/Autocompleteplus/Autosuggest/etc/wsdl.xml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
3
+ xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
4
+ name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
5
+ <types>
6
+ <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
7
+ <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
8
+ </schema>
9
+ </types>
10
+ <message name="setLayeredSearchOnRequest">
11
+ <part name="sessionId" type="xsd:string" />
12
+ <part name="scope" type="xsd:string" />
13
+ <part name="scope_id" type="xsd:string" />
14
+ </message>
15
+ <message name="setLayeredSearchOnResponse">
16
+ <part name="result" type="xsd:string" />
17
+ </message>
18
+
19
+ <message name="setLayeredSearchOffRequest">
20
+ <part name="sessionId" type="xsd:string" />
21
+ <part name="scope" type="xsd:string" />
22
+ <part name="scope_id" type="xsd:string" />
23
+ </message>
24
+ <message name="setLayeredSearchOffResponse">
25
+ <part name="result" type="xsd:string" />
26
+ </message>
27
+
28
+ <message name="getLayeredSearchConfigRequest">
29
+ <part name="sessionId" type="xsd:string" />
30
+ <part name="scope_id" type="xsd:string" />
31
+ </message>
32
+ <message name="getLayeredSearchConfigResponse">
33
+ <part name="result" type="xsd:string" />
34
+ </message>
35
+
36
+ <portType name="{{var wsdl.handler}}PortType">
37
+ <operation name="setLayeredSearchOn">
38
+ <documentation>Set Layered Search on</documentation>
39
+ <input message="typens:setLayeredSearchOnRequest" />
40
+ <output message="typens:setLayeredSearchOnResponse" />
41
+ </operation>
42
+ </portType>
43
+
44
+ <portType name="{{var wsdl.handler}}PortType">
45
+ <operation name="setLayeredSearchOff">
46
+ <documentation>Set Layered Search off</documentation>
47
+ <input message="typens:setLayeredSearchOffRequest" />
48
+ <output message="typens:setLayeredSearchOffResponse" />
49
+ </operation>
50
+ </portType>
51
+
52
+ <portType name="{{var wsdl.handler}}PortType">
53
+ <operation name="getLayeredSearchConfig">
54
+ <documentation>Get Layered Search config</documentation>
55
+ <input message="typens:getLayeredSearchConfigRequest" />
56
+ <output message="typens:getLayeredSearchConfigResponse" />
57
+ </operation>
58
+ </portType>
59
+
60
+ <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
61
+ <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
62
+ <operation name="setLayeredSearchOn">
63
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
64
+ <input>
65
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
66
+ </input>
67
+ <output>
68
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
69
+ </output>
70
+ </operation>
71
+ <operation name="setLayeredSearchOff">
72
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
73
+ <input>
74
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
75
+ </input>
76
+ <output>
77
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
78
+ </output>
79
+ </operation>
80
+ <operation name="getLayeredSearchConfig">
81
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
82
+ <input>
83
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
84
+ </input>
85
+ <output>
86
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
87
+ </output>
88
+ </operation>
89
+ </binding>
90
+ <service name="{{var wsdl.name}}Service">
91
+ <port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
92
+ <soap:address location="{{var wsdl.url}}" />
93
+ </port>
94
+ </service>
95
+ </definitions>
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-install-2.0.1.1.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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
+ ?>
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.1.3-2.0.2.2.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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
+ ?>
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.2.5-2.0.2.6.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
18
+ /* @var $installer Mage_Core_Model_Resource_Setup */
19
+ $installer = $this;
20
+
21
+ $installer->startSetup();
22
+
23
+ $installer->run("
24
+ -- DROP TABLE IF EXISTS `{$this->getTable('autocompleteplus_autosuggest/notifications')}`;
25
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('autocompleteplus_autosuggest/notifications')}` (
26
+ `notification_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
27
+ `type` varchar(32) default NULL,
28
+ `subject` varchar(255) default NULL,
29
+ `message` text,
30
+ `timestamp` varchar(32) default NULL,
31
+ `is_active` tinyint(1) NOT NULL default '1',
32
+ PRIMARY KEY (`notification_id`),
33
+ KEY `IDX_TYPE` (`type`),
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();
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.4.6-2.0.4.7.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $installer = $this;
18
+
19
+ $installer->startSetup();
20
+
21
+ $res=$installer->run("
22
+
23
+ DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_checksum')};
24
+
25
+ CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_checksum')} (
26
+
27
+ `identifier` VARCHAR( 255 ) NOT NULL,
28
+
29
+ `sku` VARCHAR( 255 ) NOT NULL,
30
+
31
+ `store_id` INT NOT NULL,
32
+
33
+ `checksum` VARCHAR( 255 ) NOT NULL,
34
+
35
+ PRIMARY KEY (`identifier`, `store_id`)
36
+
37
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
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();
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.4-2.0.5.5.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+
4
+ $installer->startSetup();
5
+
6
+ $table = $installer->getConnection()->newTable($installer->getTable('autocompleteplus_autosuggest/pusher'))
7
+
8
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
9
+
10
+ 'identity' => true,
11
+
12
+ 'unsigned' => true,
13
+
14
+ 'nullable' => false,
15
+
16
+ 'primary' => true
17
+
18
+ ), 'Id')
19
+
20
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
21
+
22
+ 'nullable' => false,
23
+
24
+ 'unsigned' => true
25
+
26
+ ))
27
+
28
+ ->addColumn('to_send', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
29
+
30
+ 'nullable' => false,
31
+
32
+ 'unsigned' => true
33
+
34
+ ), 'Amount left to send')
35
+
36
+ ->addColumn('offset', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
37
+
38
+ 'nullable' => false,
39
+
40
+ 'unsigned' => true
41
+
42
+ ))
43
+
44
+ ->addColumn('total_batches', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
45
+
46
+ 'nullable' => false,
47
+
48
+ 'unsigned' => true
49
+
50
+ ))
51
+
52
+ ->addColumn('batch_number', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
53
+
54
+ 'nullable' => false,
55
+
56
+ 'unsigned' => true
57
+
58
+ ))
59
+
60
+ ->addColumn('sent', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
61
+
62
+ 'nullable' => false,
63
+
64
+ 'unsigned' => true
65
+
66
+ ));
67
+
68
+
69
+
70
+ if ($installer->getConnection()->isTableExists($table->getName())) {
71
+
72
+ $installer->getConnection()->dropTable($table->getName());
73
+
74
+ }
75
+
76
+
77
+
78
+ $installer->getConnection()->createTable($table);
79
+
80
+ $installer->endSetup();
81
+
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.5.6-2.0.5.7.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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();
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.6.1-2.0.6.4.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ($installer->getConnection()->isTableExists($this->getTable('autocompleteplus_config'))) {
16
+ $config_arr = Mage::getModel('autocompleteplus_autosuggest/config')->getCollection()->getData();
17
+ $config = $config_arr[0];
18
+ } else {
19
+ $config = false;
20
+ }
21
+
22
+ $data = array();
23
+ if ($config && isset($config['licensekey'])) {
24
+ $data['uuid'] = $config['licensekey'];
25
+ }
26
+
27
+ $key='';
28
+ $auth_key='';
29
+ $is_reachable=0;
30
+ $errMsg = '';
31
+
32
+ try {
33
+ $commandOrig = "http://magento.instantsearchplus.com/install";
34
+ $data['multistore'] = $multistoreJson;
35
+ if (method_exists('Mage' , 'getEdition')){
36
+ $data['edition'] = Mage::getEdition();
37
+ } else {
38
+ $data['edition'] = 'Unknown';
39
+ }
40
+ $data['site'] = $url;
41
+ $data['email'] = $storeMail;
42
+ $data['f'] = '2.0.6.2';
43
+
44
+ $auto_arr = json_decode($helper->sendPostCurl($commandOrig, $data), true);
45
+
46
+ $key = $auto_arr['uuid'];
47
+ $auth_key = $auto_arr['authentication_key'];
48
+ if (strlen($key) > 50) {
49
+ $key = 'InstallFailedUUID';
50
+ }
51
+ if(isset($auto_arr['is_reachable'])){
52
+ $is_reachable=$auto_arr['is_reachable'];
53
+ }
54
+
55
+ Mage::log(print_r($auto_arr, true), null, 'autocomplete.log',true);
56
+
57
+ if ($key == 'InstallFailedUUID') {
58
+ $errMsg .= 'Could not get license string.';
59
+ }
60
+
61
+ //sending error info
62
+ if ($errMsg != '') {
63
+
64
+ $command = "http://magento.instantsearchplus.com/install_error";
65
+ $data = array();
66
+ $data['site'] = $url;
67
+ $data['msg'] = $errMsg;
68
+ $data['email'] = $storeMail;
69
+ //$data['product_count']=$productCount;
70
+ $data['multistore'] = $multistoreJson;
71
+ $data['f'] = '2.0.6.2';
72
+ $res = $helper->sendPostCurl($command, $data);
73
+ }
74
+
75
+ //getting sitemap.xml
76
+ if ($key != '' && $key != 'InstallFailedUUID'){
77
+ $stemapUrl='Sitemap:http://magento.instantsearchplus.com/ext_sitemap?u='.$key.PHP_EOL;
78
+ $robotsPath=Mage::getBaseDir().DS.'robots.txt';
79
+ if (file_exists($robotsPath)) {
80
+ if (strpos($robots_content,$stemapUrl) == false){
81
+ if(is_writable($robotsPath)){
82
+ //append sitemap
83
+ file_put_contents($robotsPath, $stemapUrl, FILE_APPEND | LOCK_EX);
84
+ }else{
85
+ //write message that file is not writteble
86
+ $command="http://magento.instantsearchplus.com/install_error";
87
+ $data=array();
88
+ $data['site']=$url;
89
+ $data['msg']='File '.$robotsPath.' is not writable.';
90
+ $data['f'] = '2.0.6.2';
91
+ $res=$helper->sendPostCurl($command,$data);
92
+ }
93
+ }
94
+ }else{
95
+ //create file
96
+ if(is_writable(Mage::getBaseDir())){
97
+ //create robots sitemap
98
+ file_put_contents($robotsPath,$stemapUrl);
99
+ }else{
100
+ //write message that directory is not writteble
101
+ $command="http://magento.instantsearchplus.com/install_error";
102
+ $data=array();
103
+ $data['site']=$url;
104
+ $data['msg']='Directory '.Mage::getBaseDir().' is not writable.';
105
+ $data['f'] = '2.0.6.2';
106
+ $res=$helper->sendPostCurl($command,$data);
107
+ }
108
+ }
109
+ }
110
+
111
+ } catch (Exception $e) {
112
+ $key = 'failed';
113
+ $errMsg = $e->getMessage();
114
+ Mage::log('Install failed with a message: ' . $errMsg, null, 'autocomplete.log',true);
115
+ $command = "http://magento.instantsearchplus.com/install_error";
116
+
117
+ $data = array();
118
+ $data['site'] = $url;
119
+ $data['msg'] = $errMsg;
120
+ $data['original_install_URL'] = $commandOrig;
121
+ $data['f'] = '2.0.6.2';
122
+ $res = $helper->sendPostCurl($command, $data);
123
+ }
124
+
125
+
126
+ $installer->startSetup();
127
+
128
+ $res=$installer->run("
129
+ DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_config')};
130
+
131
+ CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_config')} (
132
+
133
+ `id` int(11) NOT NULL auto_increment,
134
+
135
+ `licensekey` varchar(255) character set utf8 NOT NULL,
136
+
137
+ `authkey` varchar(255) character set utf8 NOT NULL,
138
+
139
+ `site_url` varchar(255) character set utf8 NOT NULL,
140
+
141
+ `is_reachable` TINYINT NOT NULL,
142
+
143
+ `errormessage` TEXT character set utf8 NOT NULL,
144
+
145
+ `server_type` varchar(255) character set utf8,
146
+
147
+ `cdn_cache_key` varchar(255) character set utf8,
148
+
149
+ PRIMARY KEY (`id`)
150
+
151
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
152
+ ");
153
+
154
+ $res = $installer->run("INSERT INTO {$this->getTable('autocompleteplus_config')}
155
+ (licensekey,authkey,site_url,is_reachable,errormessage)
156
+ VALUES('" . $key . "','" . $auth_key . "','" . $url . "',".$is_reachable.",'".$errMsg."');");
157
+
158
+ $installer->endSetup();
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.0-2.0.7.1.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
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();
app/code/local/Autocompleteplus/Autosuggest/sql/autosuggest_setup/mysql4-upgrade-2.0.7.2-2.0.7.3.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ if ($installer->getConnection()->isTableExists($this->getTable('autocompleteplus_batches'))) {
5
+ try{
6
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
7
+ $_tableprefix = (string)Mage::getConfig()->getTablePrefix();
8
+ $query = 'SHOW FIELDS FROM `'.$_tableprefix.'autocompleteplus_batches` WHERE Field = \'update_date\'';
9
+ // $query = 'DESCRIBE `'.$_tableprefix.'autocompleteplus_batches`'.' \'update_date\'';
10
+
11
+ $result = $read->fetchAll($query);
12
+ if (!empty($result) && array_key_exists('Type', $result[0])){
13
+ if (!(substr($result[0]['Type'], 0, 3) == 'int')){ // check if variable 'update_date' type is not Integer
14
+
15
+ $installer->startSetup();
16
+ // rebuild the autocompleteplus_batches table
17
+ $res=$installer->run("
18
+ DROP TABLE IF EXISTS {$this->getTable('autocompleteplus_batches')};
19
+
20
+ CREATE TABLE IF NOT EXISTS {$this->getTable('autocompleteplus_batches')} (
21
+ `id` int(11) NOT NULL auto_increment,
22
+ `product_id` INT NULL,
23
+ `store_id` INT NOT NULL,
24
+ `update_date` INT DEFAULT NULL,
25
+ `action` VARCHAR( 255 ) NOT NULL,
26
+ `sku` VARCHAR( 255 ) NOT NULL,
27
+ PRIMARY KEY (`id`)
28
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
29
+
30
+ ");
31
+ $installer->endSetup();
32
+ }
33
+ }
34
+ } catch (Exception $e) {
35
+ $errMsg = $e->getMessage();
36
+ Mage::log('Install failed with a message: ' . $errMsg, null, 'autocomplete.log',true);
37
+
38
+ $command = "http://magento.instantsearchplus.com/install_error";
39
+ $helper = Mage::helper('autocompleteplus_autosuggest');
40
+ //getting site url
41
+ $url = $helper->getConfigDataByFullPath('web/unsecure/base_url');
42
+
43
+ $data = array();
44
+ $data['site'] = $url;
45
+ $data['msg'] = $errMsg;
46
+ $data['f'] = '2.0.7.3';
47
+ $res = $helper->sendPostCurl($command, $data);
48
+ }
49
+ }
50
+
51
+ ?>
app/design/adminhtml/default/default/layout/autocompleteplus.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <default>
4
+ <reference name="notifications">
5
+ <block type="autocompleteplus_autosuggest/notifications" name="autocompleteplus_notifications" template="autocompleteplus/notifications.phtml"></block>
6
+ </reference>
7
+ <reference name="before_body_end">
8
+ <block type="core/text" name="instantsearch.adminLinks">
9
+ <action method="setText">
10
+ <text>
11
+ <![CDATA[
12
+ <script type="text/javascript">
13
+ document.observe('dom:loaded', function() {$('nav').select('li.level0').each(function(l, ind) {
14
+ if (l.innerHTML.indexOf('InstantSearch+') >= 0) {
15
+ l.select('a').first().writeAttribute('target', '_blank');
16
+ }});
17
+ });
18
+ </script>
19
+ ]]>
20
+ </text>
21
+ </action>
22
+ </block>
23
+ </reference>
24
+ </default>
25
+ </layout>
app/design/adminhtml/default/default/template/autocompleteplus/notifications.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $shouldSync=$this->localhostSynced();
3
+
4
+ if($shouldSync){
5
+ ?>
6
+ <div id="autosuggest-notification" class="notification-global">
7
+ <a target="_blank" href="<?php echo Mage::helper('adminhtml')->getUrl('autocompleteplus/adminhtml_push/startpush');?>">
8
+ <b><?php echo $this->__('Sync now'); ?></b>
9
+ </a>
10
+ <?php echo $this->__(' to complete the initial <strong>InstantSearch+</strong> product synchronization with our cloud service') ?>.
11
+ </div>
12
+ <?php
13
+ }
14
+ ?>
app/design/adminhtml/default/default/template/autocompleteplus/notifications_old.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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() ?>
app/design/adminhtml/default/default/template/autocompleteplus/system/config/sync.phtml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ //<![CDATA[
3
+ function syncautocomplete() {
4
+
5
+ var url='<?php echo $this->getSyncUrl(); ?>';
6
+
7
+ window.open(url);
8
+ }
9
+ //]]>
10
+ </script>
11
+ <?php
12
+
13
+ if($this->getIsReachable()==0){
14
+ echo $this->getButtonHtml();
15
+ }else{
16
+ echo
17
+ '<style>
18
+ #row_autocompleteplus_config_sync{display: none}
19
+ </style>';
20
+ }
21
+ ?>
app/design/frontend/base/default/layout/autocompleteplus.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
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>
9
+ <catalogsearch_result_index>
10
+ <reference name="catalogsearch.leftnav">
11
+ <action method="setTemplate" ifconfig="autocompleteplus/config/layered">
12
+ <value>autocompleteplus/catalog/layer/view.phtml</value>
13
+ </action>
14
+ </reference>
15
+ <reference name="search_result_list">
16
+ <action method="setTemplate" ifconfig="autocompleteplus/config/layered">
17
+ <value>autocompleteplus/catalog/product/list.phtml</value>
18
+ </action>
19
+ </reference>
20
+ </catalogsearch_result_index>
21
+ </layout>
app/design/frontend/base/default/template/autocompleteplus/catalog/layer/view.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = Mage::app()->getRequest()->getParam('q');
6
+ ?>
7
+ <div id="isp_search_result_layered_navigation"></div>
8
+ <script>
9
+ var __isp_fulltext_search_obj = {
10
+ uuid: <?php echo '"' . $uuid . '"'; ?>,
11
+ store_id: <?php echo $store_id; ?>,
12
+ query: <?php echo '"' . $query . '"'; ?>
13
+ };
14
+ </script>
app/design/frontend/base/default/template/autocompleteplus/catalog/product/list.phtml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = Mage::app()->getRequest()->getParam('q');
6
+ ?>
7
+ <!-- <div id="isp_search_result_page"></div> -->
8
+ <script>
9
+ var __isp_fulltext_search_obj = {
10
+ uuid: <?php echo '"' . $uuid . '"'; ?>,
11
+ store_id: <?php echo $store_id; ?>,
12
+ query: <?php echo '"' . $query . '"'; ?>
13
+ };
14
+ </script>
15
+ <?php
16
+ $helper=Mage::helper('autocompleteplus_autosuggest');
17
+ $server_url = $helper->getServerUrl();
18
+ $url = $server_url . '/ma_load_search_page?isp_platform=magento';
19
+ $resp = $helper->sendCurl($url);
20
+ $response_json = json_decode($resp);
21
+ echo $response_json->html;
22
+ ?>
app/design/frontend/base/default/template/autocompleteplus/inject.phtml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ?>
app/design/frontend/base/default/template/autocompleteplus/inject_new.phtml ADDED
@@ -0,0 +1,3 @@
 
 
 
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/etc/modules/Autocompleteplus_Autosuggest.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>autocompleteplus_autosuggest</name>
4
+ <version>2.0.7.5</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>* search result page product reviews&#xD;
12
+ </notes>
13
+ <authors><author><name>Adar</name><user>Adar</user><email>magento@autocompleteplus.com</email></author></authors>
14
+ <date>2015-08-03</date>
15
+ <time>12:46:01</time>
16
+ <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="e0a2fe4d412ebdf8cabc01fa4c224e6e"/><file name="Process.php" hash="aa23776a49fb4fae3f7a9891155608c2"/><file name="Sync.php" hash="033d8bbf1f2aa68582ff56d87ee7f4c7"/></dir><file name="Autocomplete.php" hash="3a63d5c743d8dda3552f8c0b717c8d2e"/><file name="Autocorrection.php" hash="08da843c04cf9176cefb8588a0da3e77"/><file name="Inject.php" hash="d66c539aa8e8ba203c81060920474545"/><file name="Notifications.php" hash="825fcc830917a22aff36e859fd63b16f"/></dir><dir name="Helper"><file name="Data.php" hash="5896b513a31e34f0dbd9943133e16c33"/></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="8036ec20017065d11903bb1a477e9a13"/><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="5b454a3dc3bb7a1a72d5aa125c684bbb"/><file name="Pusher.php" hash="cb55bd677f131dc4370429c2cb485be9"/><dir name="Resource"><dir name="Fulltext"><file name="Collection.php" hash="2492156a0fffde6aa7a62f596d8b30ca"/></dir></dir><file name="Service.php" hash="2c1e4d7764f7d99d2f54e442f3652918"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="PushController.php" hash="f92822911e861c39e2bb50eb1ccc1d14"/><file name="RedirectController.php" hash="2bdc7574edfc293bde1e89c87a9b6ce1"/></dir><dir name="CatalogSearch"><file name="ResultController.php" hash="67333080dc7d7cf748667b53616f1457"/></dir><file name="CatalogsearchController.php" hash="0327c979fc357504147d7caff7079d69"/><file name="CategoriesController.php" hash="38e9551dd84f4f9fad2ccebde1f8bf77"/><file name="LayeredController.php" hash="f43274329a4e8cfbae6c994beea25653"/><file name="ProductsController.php" hash="ceffa6d0309f8949c505c296f2e0feb1"/><file name="ProductsbyidController.php" hash="5705ccffaba0d594d6e64bdb0fa95715"/><file name="SearchesController.php" hash="344ab1717d1b25d746d033074ae22ade"/></dir><dir name="etc"><file name="adminhtml.xml" hash="aceab8126257d9afbb4a2bc9be994ac5"/><file name="api.xml" hash="25ab859fc8312c4aa308f2e3306c6b66"/><file name="cache.xml" hash="b57472bc9410d67af3843825fba5b420"/><file name="config.xml" hash="7d29c67552a7e225c9973210de2e5148"/><file name="config_no_fulltext.xml" hash="2c54a24e594ffdf91e01038dec4bf029"/><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="241322290fd27a9d69cfe5523c089434"/><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="fa5411870fa2eef5ed21a6db1373b651"/><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="9ea280adb0ba238fcb6b92b0fe86219b"/></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="fde78c32c4eba6de8d324c4fd6a8863c"/></dir><dir name="template"><dir name="autocompleteplus"><dir name="catalog"><dir name="layer"><file name="view.phtml" hash="aa1bb4fac059c860cd306dc9181bac06"/></dir><dir name="product"><file name="list.phtml" hash="c56f2667ac792b3a4d561c486beca23d"/></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="88db09b9c262104a73886aa7e7efef1e"/><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>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>