stockinthechannel2012 - Version 2.1.1

Version Notes

Version 2.1.1:
* Improve stability on newer versions of PHP
* Cleanup some code
* Improve checks in admin panel

Download this release

Release Info

Developer stockinchannel
Extension stockinthechannel2012
Version 2.1.1
Comparing to
See all releases


Code changes from version 2.0.9 to 2.1.1

Files changed (38) hide show
  1. app/code/local/Bintime/Sinchimport/Block/Adminhtml/Catalog/Product/Sinchdistributors.php +25 -25
  2. app/code/local/Bintime/Sinchimport/Block/Importenvironment.php +210 -210
  3. app/code/local/Bintime/Sinchimport/Block/Layer/Filter/Feature.php +17 -17
  4. app/code/local/Bintime/Sinchimport/Block/Layer/View.php +48 -48
  5. app/code/local/Bintime/Sinchimport/Block/List.php +159 -159
  6. app/code/local/Bintime/Sinchimport/Helper/Image.php +73 -73
  7. app/code/local/Bintime/Sinchimport/Model/Image.php +118 -118
  8. app/code/local/Bintime/Sinchimport/Model/Layer.php +49 -49
  9. app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Feature.php +248 -260
  10. app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Price.php +189 -194
  11. app/code/local/Bintime/Sinchimport/Model/Resource/Layer/Filter/Price.php +1 -2
  12. app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php +381 -383
  13. app/code/local/Bintime/Sinchimport/Model/Sinch.php +48 -21
  14. app/code/local/Bintime/Sinchimport/Model/System/Config/ServerList.php +26 -26
  15. app/code/local/Bintime/Sinchimport/etc/api.xml +34 -34
  16. app/code/local/Bintime/Sinchimport/etc/config.xml +267 -267
  17. app/code/local/Bintime/Sinchimport/etc/system.xml +194 -194
  18. app/code/local/Bintime/Sinchimport/sinch_import_start_ajax.php +13 -13
  19. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/filter_sinch_products_s.sql +207 -207
  20. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-install-0.1.0.php +142 -142
  21. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.0-0.1.1.php +67 -67
  22. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.1-0.1.2.php +63 -63
  23. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.2-0.1.3.php +133 -133
  24. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.3-0.1.4.php +53 -53
  25. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.4-0.1.5.php +33 -33
  26. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.5-0.1.6.php +15 -15
  27. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.6-0.1.7.php +274 -274
  28. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.7-0.1.8.php +108 -108
  29. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.8-0.1.9.php +16 -16
  30. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.9-0.2.0.php +123 -123
  31. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.2.0-0.2.1.php +108 -108
  32. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.2.1-0.2.2.php +230 -230
  33. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.0-3.0.1.php +307 -307
  34. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.1-3.0.2.php +108 -108
  35. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.2-3.0.3.php +42 -42
  36. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.3-3.0.4.php +50 -50
  37. app/code/local/Bintime/Sinchimport/stock_price_sinch_import_start_ajax.php +14 -14
  38. package.xml +8 -6
app/code/local/Bintime/Sinchimport/Block/Adminhtml/Catalog/Product/Sinchdistributors.php CHANGED
@@ -1,25 +1,25 @@
1
- <?php
2
- class Bintime_Sinchimport_Block_Adminhtml_Catalog_Product_Sinchdistributors extends Mage_Core_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface
3
- {
4
- public function __construct(){
5
- $this->setTemplate('sinchimport/sinchdistributors.phtml');
6
- parent::__construct();
7
- }
8
-
9
- //Label to be shown in the tab
10
- public function getTabLabel(){
11
- return Mage::helper('core')->__('Suppliers');
12
- }
13
-
14
- public function getTabTitle(){
15
- return Mage::helper('core')->__('Suppliers');
16
- }
17
-
18
- public function canShowTab(){
19
- return true;
20
- }
21
-
22
- public function isHidden(){
23
- return false;
24
- }
25
- }
1
+ <?php
2
+ class Bintime_Sinchimport_Block_Adminhtml_Catalog_Product_Sinchdistributors extends Mage_Core_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface
3
+ {
4
+ public function __construct(){
5
+ $this->setTemplate('sinchimport/sinchdistributors.phtml');
6
+ parent::__construct();
7
+ }
8
+
9
+ //Label to be shown in the tab
10
+ public function getTabLabel(){
11
+ return Mage::helper('core')->__('Suppliers');
12
+ }
13
+
14
+ public function getTabTitle(){
15
+ return Mage::helper('core')->__('Suppliers');
16
+ }
17
+
18
+ public function canShowTab(){
19
+ return true;
20
+ }
21
+
22
+ public function isHidden(){
23
+ return false;
24
+ }
25
+ }
app/code/local/Bintime/Sinchimport/Block/Importenvironment.php CHANGED
@@ -1,210 +1,210 @@
1
- <?php
2
-
3
-
4
-
5
-
6
- class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_System_Config_Form_Field {
7
-
8
-
9
-
10
-
11
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
12
- $this->setElement($element);
13
- $url = $this->getUrl('sinchimport/index');
14
- $this->setElement($element);
15
-
16
- $html = '';
17
-
18
- //$html .= '<div class="comment"><H3>'.("Your Stock In The Channel Environment Check Summary" ).'</H3></div>';
19
-
20
- //$html .= '<div class="comment"><H3>'.("In order for this extension to work, your server needs to be configured in a particular way and have sufficient memory." ).'</H3></div>';
21
-
22
-
23
- $html .= '
24
- <table class="history">
25
- <thead>
26
- <tr>
27
- <th>Checked</th>
28
- <th>Necessary, Error And Fix</th>
29
-
30
- </tr>
31
- </thead><tbody>';
32
- // <th>Necessary</th>
33
- // <th>Fix</th>
34
-
35
- $errors_count = 0;
36
-
37
- // Memory total
38
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkMemory();
39
- if ($status == 'error') $errors_count++;
40
- if ($status == 'error') {
41
- $html .= // $caption: $value $measure
42
- "
43
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
44
- <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
45
- <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
46
- <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
47
- ";
48
- };
49
-
50
-
51
-
52
- // Mysql parameter LOCAL DATA LOCAL
53
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkLoaddata();
54
- if ($status == 'error') $errors_count++;
55
- if ($status == 'error') {
56
- $html .= // $caption: $value $measure
57
- "
58
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
59
- <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
60
- <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
61
- <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
62
- ";
63
- };
64
-
65
-
66
- // PHP safe mode
67
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkPhpsafemode();
68
- if ($status == 'error') $errors_count++;
69
- if ($status == 'error') {
70
- $html .= // $caption: $value $measure
71
- "
72
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
73
- <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
74
- <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
75
- <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
76
- ";
77
- };
78
-
79
-
80
- // Mysql parameter wait_timeout
81
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkWaittimeout();
82
- if ($status == 'error') $errors_count++;
83
- if ($status == 'error') {
84
- $html .= // $caption: $value $measure
85
- "
86
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
87
- <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
88
- <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
89
- <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
90
- ";
91
- };
92
-
93
-
94
- // Mysql parameter innodb_buffer_pool_size
95
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkInnodbbufferpoolsize();
96
- if ($status == 'error') $errors_count++;
97
- if ($status == 'error') {
98
- $html .= // $caption: $value $measure
99
- "
100
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
101
- <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
102
- <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
103
- <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
104
- ";
105
- };
106
-
107
-
108
- // Conflict with installed module
109
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkConflictsWithInstalledModules();
110
- if ($status == 'error') $errors_count++;
111
- if ($status == 'error') {
112
- $html .= // $caption: $value $measure
113
- "
114
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
115
- <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
116
- <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
117
- <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
118
- ";
119
- };
120
-
121
-
122
- // PHP run string
123
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkPhprunstring();
124
- if ($status == 'error') $errors_count++;
125
- if ($status == 'error') {
126
- $html .= // $caption: $value $measure
127
- "
128
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
129
- <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
130
- <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
131
- <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
132
- ";
133
- };
134
-
135
-
136
- // Chmod wget file
137
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkChmodwgetdatafile();
138
- if ($status == 'error') $errors_count++;
139
- if ($status == 'error') {
140
- $html .= // $caption: $value $measure
141
- "
142
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
143
- <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
144
- <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
145
- <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
146
- ";
147
- };
148
-
149
-
150
- // Chmod wget cron.php file
151
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkChmodwgetcronphpfile();
152
- if ($status == 'error') $errors_count++;
153
- if ($status == 'error') {
154
- $html .= // $caption: $value $measure
155
- "
156
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
157
- <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
158
- <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
159
- <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
160
- ";
161
- };
162
-
163
- // Chmod wget cron.sh file
164
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkChmodwgetcronshfile();
165
- if ($status == 'error') $errors_count++;
166
- if ($status == 'error') {
167
- $html .= // $caption: $value $measure
168
- "
169
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
170
- <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
171
- <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
172
- <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
173
- ";
174
- };
175
-
176
- // Mysql stored procedure filter_sinch_products_s
177
- list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkProcedure();
178
- if ($status == 'error') $errors_count++;
179
- if ($status == 'error') {
180
- $html .= // $caption: $value $measure
181
- "
182
- <tr> <td nowrap rowspan=4> $caption </td> </tr>
183
- <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
184
- <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
185
- <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
186
- ";
187
- };
188
-
189
-
190
- $html .= '
191
- </tbody>
192
- </table>';
193
-
194
- $html .= '<div class="comment"><H3>'.("There are $errors_count notices." ).'</H3></div>';
195
-
196
- // all checks
197
- return $html;
198
-
199
- } // protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
200
-
201
- protected function _colored($str, $color){
202
- return "<b><span style='color:{$color}'>{$str}</span></b>";
203
- }
204
-
205
-
206
- } // class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_System_Config_Form_Field
207
-
208
-
209
-
210
-
1
+ <?php
2
+
3
+
4
+
5
+
6
+ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_System_Config_Form_Field {
7
+
8
+
9
+
10
+
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
12
+ $this->setElement($element);
13
+ $url = $this->getUrl('sinchimport/index');
14
+ $this->setElement($element);
15
+
16
+ $html = '';
17
+
18
+ //$html .= '<div class="comment"><H3>'.("Your Stock In The Channel Environment Check Summary" ).'</H3></div>';
19
+
20
+ //$html .= '<div class="comment"><H3>'.("In order for this extension to work, your server needs to be configured in a particular way and have sufficient memory." ).'</H3></div>';
21
+
22
+
23
+ $html .= '
24
+ <table class="history">
25
+ <thead>
26
+ <tr>
27
+ <th>Checked</th>
28
+ <th>Necessary, Error And Fix</th>
29
+
30
+ </tr>
31
+ </thead><tbody>';
32
+ // <th>Necessary</th>
33
+ // <th>Fix</th>
34
+
35
+ $errors_count = 0;
36
+
37
+ // Memory total
38
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkMemory();
39
+ if ($status == 'error') $errors_count++;
40
+ if ($status == 'error') {
41
+ $html .= // $caption: $value $measure
42
+ "
43
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
44
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
45
+ <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
46
+ <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
47
+ ";
48
+ };
49
+
50
+
51
+
52
+ // Mysql parameter LOCAL DATA LOCAL
53
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkLoaddata();
54
+ if ($status == 'error') $errors_count++;
55
+ if ($status == 'error') {
56
+ $html .= // $caption: $value $measure
57
+ "
58
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
59
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
60
+ <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
61
+ <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
62
+ ";
63
+ };
64
+
65
+
66
+ // PHP safe mode
67
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkPhpsafemode();
68
+ if ($status == 'error') $errors_count++;
69
+ if ($status == 'error') {
70
+ $html .= // $caption: $value $measure
71
+ "
72
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
73
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
74
+ <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
75
+ <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
76
+ ";
77
+ };
78
+
79
+
80
+ // Mysql parameter wait_timeout
81
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkWaittimeout();
82
+ if ($status == 'error') $errors_count++;
83
+ if ($status == 'error') {
84
+ $html .= // $caption: $value $measure
85
+ "
86
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
87
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
88
+ <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
89
+ <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
90
+ ";
91
+ };
92
+
93
+
94
+ // Mysql parameter innodb_buffer_pool_size
95
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkInnodbbufferpoolsize();
96
+ if ($status == 'error') $errors_count++;
97
+ if ($status == 'error') {
98
+ $html .= // $caption: $value $measure
99
+ "
100
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
101
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
102
+ <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
103
+ <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
104
+ ";
105
+ };
106
+
107
+
108
+ // Conflict with installed module
109
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkConflictsWithInstalledModules();
110
+ if ($status == 'error') $errors_count++;
111
+ if ($status == 'error') {
112
+ $html .= // $caption: $value $measure
113
+ "
114
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
115
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
116
+ <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
117
+ <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
118
+ ";
119
+ };
120
+
121
+
122
+ // PHP run string
123
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkPhprunstring();
124
+ if ($status == 'error') $errors_count++;
125
+ if ($status == 'error') {
126
+ $html .= // $caption: $value $measure
127
+ "
128
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
129
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
130
+ <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
131
+ <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
132
+ ";
133
+ };
134
+
135
+
136
+ // Chmod wget file
137
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkChmodwgetdatafile();
138
+ if ($status == 'error') $errors_count++;
139
+ if ($status == 'error') {
140
+ $html .= // $caption: $value $measure
141
+ "
142
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
143
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
144
+ <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
145
+ <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
146
+ ";
147
+ };
148
+
149
+
150
+ // Chmod wget cron.php file
151
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkChmodwgetcronphpfile();
152
+ if ($status == 'error') $errors_count++;
153
+ if ($status == 'error') {
154
+ $html .= // $caption: $value $measure
155
+ "
156
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
157
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
158
+ <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
159
+ <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
160
+ ";
161
+ };
162
+
163
+ // Chmod wget cron.sh file
164
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkChmodwgetcronshfile();
165
+ if ($status == 'error') $errors_count++;
166
+ if ($status == 'error') {
167
+ $html .= // $caption: $value $measure
168
+ "
169
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
170
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
171
+ <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
172
+ <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
173
+ ";
174
+ };
175
+
176
+ // Mysql stored procedure filter_sinch_products_s
177
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkProcedure();
178
+ if ($status == 'error') $errors_count++;
179
+ if ($status == 'error') {
180
+ $html .= // $caption: $value $measure
181
+ "
182
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
183
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
184
+ <tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
185
+ <tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
186
+ ";
187
+ };
188
+
189
+
190
+ $html .= '
191
+ </tbody>
192
+ </table>';
193
+
194
+ $html .= '<div class="comment"><H3>'.("There are $errors_count notices." ).'</H3></div>';
195
+
196
+ // all checks
197
+ return $html;
198
+
199
+ } // protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
200
+
201
+ protected function _colored($str, $color){
202
+ return "<b><span style='color:{$color}'>{$str}</span></b>";
203
+ }
204
+
205
+
206
+ } // class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_System_Config_Form_Field
207
+
208
+
209
+
210
+
app/code/local/Bintime/Sinchimport/Block/Layer/Filter/Feature.php CHANGED
@@ -1,17 +1,17 @@
1
- <?php
2
-
3
- class Bintime_Sinchimport_Block_Layer_Filter_Feature extends Mage_Catalog_Block_Layer_Filter_Abstract
4
- {
5
-
6
- public function __construct()
7
- {
8
- parent::__construct();
9
- $this->_filterModelName = 'sinchimport/layer_filter_feature';
10
- }
11
-
12
- protected function _prepareFilter()
13
- {
14
- $this->_filter->setAttributeModel($this->getAttributeModel());
15
- return $this;
16
- }
17
- }
1
+ <?php
2
+
3
+ class Bintime_Sinchimport_Block_Layer_Filter_Feature extends Mage_Catalog_Block_Layer_Filter_Abstract
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->_filterModelName = 'sinchimport/layer_filter_feature';
10
+ }
11
+
12
+ protected function _prepareFilter()
13
+ {
14
+ $this->_filter->setAttributeModel($this->getAttributeModel());
15
+ return $this;
16
+ }
17
+ }
app/code/local/Bintime/Sinchimport/Block/Layer/View.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
-
3
- class Bintime_Sinchimport_Block_Layer_View extends Mage_Catalog_Block_Layer_View
4
- {
5
-
6
- protected $filterableFeatures = array();
7
-
8
- /**
9
- * Prepare child blocks
10
- *
11
- * @return Mage_Catalog_Block_Layer_View
12
- */
13
- protected function _prepareLayout()
14
- {
15
- //получение списка фич, по которым строися навигация
16
- $filterableFeatures = $this->getLayer()->getFilterableFeatures();
17
- $filterBlockName = 'sinchimport/layer_filter_feature'; //block
18
- foreach ($filterableFeatures as $feature) {
19
- $this->filterableFeatures[] = $feature;
20
- $featureBlock = $this->getLayout()->createBlock($filterBlockName)
21
- ->setLayer($this->getLayer())
22
- ->setAttributeModel($feature)
23
- ->init();
24
- $this->setChild('feature_' . $feature['feature_id'] . '_filter',
25
- $featureBlock
26
- );
27
- }
28
- /* ------------ */
29
- return parent::_prepareLayout();
30
- }
31
-
32
- /**
33
- * Get all layer filters
34
- *
35
- * @return array
36
- */
37
- public function getFilters()
38
- {
39
- $filters = parent::getFilters();
40
- /* ------------ */
41
- foreach ($this->filterableFeatures as $feature) {
42
- $filters[] = $this->getChild('feature_' . $feature['feature_id'] . '_filter');
43
- }
44
- /* ------------ */
45
-
46
- return $filters;
47
- }
48
- }
1
+ <?php
2
+
3
+ class Bintime_Sinchimport_Block_Layer_View extends Mage_Catalog_Block_Layer_View
4
+ {
5
+
6
+ protected $filterableFeatures = array();
7
+
8
+ /**
9
+ * Prepare child blocks
10
+ *
11
+ * @return Mage_Catalog_Block_Layer_View
12
+ */
13
+ protected function _prepareLayout()
14
+ {
15
+ //получение списка фич, по которым строися навигация
16
+ $filterableFeatures = $this->getLayer()->getFilterableFeatures();
17
+ $filterBlockName = 'sinchimport/layer_filter_feature'; //block
18
+ foreach ($filterableFeatures as $feature) {
19
+ $this->filterableFeatures[] = $feature;
20
+ $featureBlock = $this->getLayout()->createBlock($filterBlockName)
21
+ ->setLayer($this->getLayer())
22
+ ->setAttributeModel($feature)
23
+ ->init();
24
+ $this->setChild('feature_' . $feature['feature_id'] . '_filter',
25
+ $featureBlock
26
+ );
27
+ }
28
+ /* ------------ */
29
+ return parent::_prepareLayout();
30
+ }
31
+
32
+ /**
33
+ * Get all layer filters
34
+ *
35
+ * @return array
36
+ */
37
+ public function getFilters()
38
+ {
39
+ $filters = parent::getFilters();
40
+ /* ------------ */
41
+ foreach ($this->filterableFeatures as $feature) {
42
+ $filters[] = $this->getChild('feature_' . $feature['feature_id'] . '_filter');
43
+ }
44
+ /* ------------ */
45
+
46
+ return $filters;
47
+ }
48
+ }
app/code/local/Bintime/Sinchimport/Block/List.php CHANGED
@@ -1,159 +1,159 @@
1
- <?php
2
- class Bintime_Sinchimport_Block_List extends Mage_Catalog_Block_Product_Compare_List
3
- {
4
- var $goods;
5
- var $_compareSinchStoreProd;
6
- public function getSinchAttributes()
7
- {
8
- $items = array();
9
- foreach ($this->getItems() as $_item) {
10
- $items[] = $_item->getId();
11
- }
12
- $to_compare=implode(',', $items);
13
- $tmp_table_sorted = Mage::getSingleton('core/resource')->getTableName('$tmp_table_sorted_').time();
14
- $this->tep_db_query("DROP TABLE IF EXISTS $tmp_table_sorted");
15
- $this->tep_db_query("CREATE TABLE $tmp_table_sorted (
16
- id int(11) not null PRIMARY KEY AUTO_INCREMENT,
17
- store_category_id int(11) not null default 0,
18
- store_product_id int(11) not null default 0,
19
- sinch_product_id int(11) not null default 0,
20
- category_feature_id int(11) not null default 0,
21
- feature_name varchar(255) not null default '',
22
- restricted_value_id int(11) not null default 0,
23
- text varchar(255) not null default '',
24
- KEY(category_feature_id),
25
- KEY(store_product_id),
26
- unique key(sinch_product_id, feature_name)
27
- )");
28
-
29
-
30
- $query = "SELECT p.sinch_product_id, p.store_product_id, p.specifications, pm.entity_id
31
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." p
32
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
33
- ON pm.shop_store_product_id = p.store_product_id AND
34
- pm.shop_sinch_product_id=p.sinch_product_id
35
- WHERE pm.entity_id IN ( $to_compare )";
36
- $sinch = $this->tep_db_query($query);
37
- while($data = $sinch->fetch(PDO::FETCH_ASSOC)){
38
- $this->ins_from_htm($data['sinch_product_id'],$data['store_product_id'],$data['specifications'],$tmp_table_sorted);
39
- $sinch_products_array[] = $data['sinch_product_id'];
40
- $this->_compareSinchStoreProd[$data['entity_id']]=$data['sinch_product_id'];
41
- }
42
- $sinch_products = implode(',', $sinch_products_array);
43
- if(!$sinch_products){
44
- $sinch_products = "''";
45
- }
46
- $this->tep_db_query("INSERT IGNORE INTO $tmp_table_sorted (
47
- store_category_id,
48
- sinch_product_id,
49
- category_feature_id,
50
- feature_name,
51
- restricted_value_id,
52
- text
53
- )(SELECT
54
- cf.store_category_id,
55
- pf.sinch_product_id,
56
- cf.category_feature_id,
57
- cf.feature_name,
58
- rv.restricted_value_id,
59
- rv.text
60
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features')." cf
61
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." rv
62
- ON cf.category_feature_id=rv.category_feature_id
63
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." pf
64
- ON rv.restricted_value_id=pf.restricted_value_id
65
- WHERE sinch_product_id in (".$sinch_products.")
66
- ORDER BY
67
- cf.display_order_number,
68
- pf.sinch_product_id)
69
- ");
70
- $this->tep_db_query("UPDATE $tmp_table_sorted t
71
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." p
72
- ON t.sinch_product_id=p.sinch_product_id
73
- SET t.store_product_id=p.store_product_id");
74
-
75
- $this->goods = array();
76
-
77
- $product_query = $this->tep_db_query("select store_product_id, sinch_product_id, category_feature_id, store_category_id, feature_name, text
78
- FROM $tmp_table_sorted
79
- ORDER BY id ASC");
80
- while($data = $product_query->fetch(PDO::FETCH_ASSOC)){
81
- $this->goods[$data['sinch_product_id']]['category_features'][$data['feature_name']] = array(
82
-
83
-
84
- 'category_feature_id' => $data['category_feature_id'],
85
- 'value' => $data['text'],
86
-
87
-
88
- 'feature_name' => $data['feature_name'],
89
- );
90
- }
91
- $catfeats = $this->tep_db_query("SELECT category_feature_id, feature_name FROM $tmp_table_sorted
92
- GROUP BY feature_name
93
- ORDER BY category_feature_id");
94
- while($fdata = $catfeats->fetch(PDO::FETCH_ASSOC)){
95
- $cf[] = $fdata;
96
- }
97
- return $cf;
98
- }
99
-
100
- public function GetSinchCompareProdAttributes(){
101
- return $this->goods;
102
- }
103
-
104
- public function getSinchAttributeName($cf)
105
- {
106
- return $cf['feature_name'];
107
- }
108
-
109
- public function getSinchProductAttributeValue($product, $cf)
110
- {
111
-
112
- $prod = $this->_compareSinchStoreProd[$product->getID()];
113
- $feature_name = $cf['feature_name'];
114
- $data = $this->goods[$prod]['category_features'][$feature_name]['value'];
115
- $data = Mage::getModel('sinchimport/sinch')->valid_utf($data);
116
- return $data;
117
- }
118
-
119
- private function ins_from_htm($sinch_product_id, $store_product_id, $htm, $tmp_table_sorted){
120
- if($htm){
121
- /** создаем новый dom-объект **/
122
- $dom = new domDocument;
123
- /** загружаем html в объект **/
124
- $dom->loadHTML($htm);
125
- $dom->preserveWhiteSpace = false;
126
-
127
- /** элемент по тэгу **/
128
- $tables = $dom->getElementsByTagName('table');
129
-
130
- /** получаем все строки таблицы **/
131
- $rows = $tables->item(0)->getElementsByTagName('tr');
132
-
133
- /** цикл по строкам **/
134
- $i=0;
135
- foreach ($rows as $row)
136
- {
137
- /** все ячейки по тэгу **/
138
- $cols = $row->getElementsByTagName('td');
139
- /** выводим значения **/
140
- $name = $cols->item(0)->nodeValue;
141
- $value = $cols->item(1)->nodeValue;
142
-
143
- if($value && $i){
144
- $q=" insert ignore into ".$tmp_table_sorted." (store_product_id, sinch_product_id, feature_name, text) values(".$store_product_id.",".$sinch_product_id.",'".$name."','".$value."')";
145
- $this->tep_db_query($q);
146
- }
147
- //mysqli_real_escape_string($name)
148
- $i++;
149
- }
150
- }
151
- }
152
- private function tep_db_query($q){
153
- $resource = Mage::getResourceSingleton('catalog/product');
154
- $connection = $resource->getReadConnection();
155
- $result = $connection->query($q);
156
- return($result);
157
- }
158
-
159
- }
1
+ <?php
2
+ class Bintime_Sinchimport_Block_List extends Mage_Catalog_Block_Product_Compare_List
3
+ {
4
+ var $goods;
5
+ var $_compareSinchStoreProd;
6
+ public function getSinchAttributes()
7
+ {
8
+ $items = array();
9
+ foreach ($this->getItems() as $_item) {
10
+ $items[] = $_item->getId();
11
+ }
12
+ $to_compare=implode(',', $items);
13
+ $tmp_table_sorted = Mage::getSingleton('core/resource')->getTableName('$tmp_table_sorted_').time();
14
+ $this->tep_db_query("DROP TABLE IF EXISTS $tmp_table_sorted");
15
+ $this->tep_db_query("CREATE TABLE $tmp_table_sorted (
16
+ id int(11) not null PRIMARY KEY AUTO_INCREMENT,
17
+ store_category_id int(11) not null default 0,
18
+ store_product_id int(11) not null default 0,
19
+ sinch_product_id int(11) not null default 0,
20
+ category_feature_id int(11) not null default 0,
21
+ feature_name varchar(255) not null default '',
22
+ restricted_value_id int(11) not null default 0,
23
+ text varchar(255) not null default '',
24
+ KEY(category_feature_id),
25
+ KEY(store_product_id),
26
+ unique key(sinch_product_id, feature_name)
27
+ )");
28
+
29
+
30
+ $query = "SELECT p.sinch_product_id, p.store_product_id, p.specifications, pm.entity_id
31
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." p
32
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
33
+ ON pm.shop_store_product_id = p.store_product_id AND
34
+ pm.shop_sinch_product_id=p.sinch_product_id
35
+ WHERE pm.entity_id IN ( $to_compare )";
36
+ $sinch = $this->tep_db_query($query);
37
+ while($data = $sinch->fetch(PDO::FETCH_ASSOC)){
38
+ $this->ins_from_htm($data['sinch_product_id'],$data['store_product_id'],$data['specifications'],$tmp_table_sorted);
39
+ $sinch_products_array[] = $data['sinch_product_id'];
40
+ $this->_compareSinchStoreProd[$data['entity_id']]=$data['sinch_product_id'];
41
+ }
42
+ $sinch_products = implode(',', $sinch_products_array);
43
+ if(!$sinch_products){
44
+ $sinch_products = "''";
45
+ }
46
+ $this->tep_db_query("INSERT IGNORE INTO $tmp_table_sorted (
47
+ store_category_id,
48
+ sinch_product_id,
49
+ category_feature_id,
50
+ feature_name,
51
+ restricted_value_id,
52
+ text
53
+ )(SELECT
54
+ cf.store_category_id,
55
+ pf.sinch_product_id,
56
+ cf.category_feature_id,
57
+ cf.feature_name,
58
+ rv.restricted_value_id,
59
+ rv.text
60
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features')." cf
61
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." rv
62
+ ON cf.category_feature_id=rv.category_feature_id
63
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." pf
64
+ ON rv.restricted_value_id=pf.restricted_value_id
65
+ WHERE sinch_product_id in (".$sinch_products.")
66
+ ORDER BY
67
+ cf.display_order_number,
68
+ pf.sinch_product_id)
69
+ ");
70
+ $this->tep_db_query("UPDATE $tmp_table_sorted t
71
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." p
72
+ ON t.sinch_product_id=p.sinch_product_id
73
+ SET t.store_product_id=p.store_product_id");
74
+
75
+ $this->goods = array();
76
+
77
+ $product_query = $this->tep_db_query("select store_product_id, sinch_product_id, category_feature_id, store_category_id, feature_name, text
78
+ FROM $tmp_table_sorted
79
+ ORDER BY id ASC");
80
+ while($data = $product_query->fetch(PDO::FETCH_ASSOC)){
81
+ $this->goods[$data['sinch_product_id']]['category_features'][$data['feature_name']] = array(
82
+
83
+
84
+ 'category_feature_id' => $data['category_feature_id'],
85
+ 'value' => $data['text'],
86
+
87
+
88
+ 'feature_name' => $data['feature_name'],
89
+ );
90
+ }
91
+ $catfeats = $this->tep_db_query("SELECT category_feature_id, feature_name FROM $tmp_table_sorted
92
+ GROUP BY feature_name
93
+ ORDER BY category_feature_id");
94
+ while($fdata = $catfeats->fetch(PDO::FETCH_ASSOC)){
95
+ $cf[] = $fdata;
96
+ }
97
+ return $cf;
98
+ }
99
+
100
+ public function GetSinchCompareProdAttributes(){
101
+ return $this->goods;
102
+ }
103
+
104
+ public function getSinchAttributeName($cf)
105
+ {
106
+ return $cf['feature_name'];
107
+ }
108
+
109
+ public function getSinchProductAttributeValue($product, $cf)
110
+ {
111
+
112
+ $prod = $this->_compareSinchStoreProd[$product->getID()];
113
+ $feature_name = $cf['feature_name'];
114
+ $data = $this->goods[$prod]['category_features'][$feature_name]['value'];
115
+ $data = Mage::getModel('sinchimport/sinch')->valid_utf($data);
116
+ return $data;
117
+ }
118
+
119
+ private function ins_from_htm($sinch_product_id, $store_product_id, $htm, $tmp_table_sorted){
120
+ if($htm){
121
+ /** создаем новый dom-объект **/
122
+ $dom = new domDocument;
123
+ /** загружаем html в объект **/
124
+ $dom->loadHTML($htm);
125
+ $dom->preserveWhiteSpace = false;
126
+
127
+ /** элемент по тэгу **/
128
+ $tables = $dom->getElementsByTagName('table');
129
+
130
+ /** получаем все строки таблицы **/
131
+ $rows = $tables->item(0)->getElementsByTagName('tr');
132
+
133
+ /** цикл по строкам **/
134
+ $i=0;
135
+ foreach ($rows as $row)
136
+ {
137
+ /** все ячейки по тэгу **/
138
+ $cols = $row->getElementsByTagName('td');
139
+ /** выводим значения **/
140
+ $name = $cols->item(0)->nodeValue;
141
+ $value = $cols->item(1)->nodeValue;
142
+
143
+ if($value && $i){
144
+ $q=" insert ignore into ".$tmp_table_sorted." (store_product_id, sinch_product_id, feature_name, text) values(".$store_product_id.",".$sinch_product_id.",'".$name."','".$value."')";
145
+ $this->tep_db_query($q);
146
+ }
147
+ //mysqli_real_escape_string($name)
148
+ $i++;
149
+ }
150
+ }
151
+ }
152
+ private function tep_db_query($q){
153
+ $resource = Mage::getResourceSingleton('catalog/product');
154
+ $connection = $resource->getReadConnection();
155
+ $result = $connection->query($q);
156
+ return($result);
157
+ }
158
+
159
+ }
app/code/local/Bintime/Sinchimport/Helper/Image.php CHANGED
@@ -1,73 +1,73 @@
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_Catalog
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 image helper
29
- *
30
- * @author Magento Core Team <core@magentocommerce.com>
31
- */
32
- class Bintime_Sinchimport_Helper_Image extends Mage_Catalog_Helper_Image
33
- {
34
-
35
- public function __toString()
36
- {
37
- try {
38
- if( $this->getImageFile() ) {
39
- $this->_getModel()->setBaseFile( $this->getImageFile() );
40
- } else {
41
- $this->_getModel()->setBaseFile( $this->getProduct()->getData($this->_getModel()->getDestinationSubdir()) );
42
- }
43
- if (substr($this->_getModel()->getNewFile(),0,4) != 'http') {
44
- if( $this->_getModel()->isCached() ) {
45
- return $this->_getModel()->getUrl();
46
- } else {
47
- if( $this->_scheduleRotate ) {
48
- $this->_getModel()->rotate( $this->getAngle() );
49
- }
50
-
51
- if ($this->_scheduleResize) {
52
- $this->_getModel()->resize();
53
- }
54
-
55
- if( $this->getWatermark() ) {
56
- $this->_getModel()->setWatermark($this->getWatermark());
57
- }
58
-
59
- $url = $this->_getModel()->saveFile()->getUrl();
60
- }
61
- }
62
- else {
63
- return $this->_getModel()->getNewFile();
64
- }
65
- } catch( Exception $e ) {
66
- $url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
67
- }
68
- return $url;
69
- }
70
-
71
-
72
-
73
- }
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_Catalog
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 image helper
29
+ *
30
+ * @author Magento Core Team <core@magentocommerce.com>
31
+ */
32
+ class Bintime_Sinchimport_Helper_Image extends Mage_Catalog_Helper_Image
33
+ {
34
+
35
+ public function __toString()
36
+ {
37
+ try {
38
+ if( $this->getImageFile() ) {
39
+ $this->_getModel()->setBaseFile( $this->getImageFile() );
40
+ } else {
41
+ $this->_getModel()->setBaseFile( $this->getProduct()->getData($this->_getModel()->getDestinationSubdir()) );
42
+ }
43
+ if (substr($this->_getModel()->getNewFile(),0,4) != 'http') {
44
+ if( $this->_getModel()->isCached() ) {
45
+ return $this->_getModel()->getUrl();
46
+ } else {
47
+ if( $this->_scheduleRotate ) {
48
+ $this->_getModel()->rotate( $this->getAngle() );
49
+ }
50
+
51
+ if ($this->_scheduleResize) {
52
+ $this->_getModel()->resize();
53
+ }
54
+
55
+ if( $this->getWatermark() ) {
56
+ $this->_getModel()->setWatermark($this->getWatermark());
57
+ }
58
+
59
+ $url = $this->_getModel()->saveFile()->getUrl();
60
+ }
61
+ }
62
+ else {
63
+ return $this->_getModel()->getNewFile();
64
+ }
65
+ } catch( Exception $e ) {
66
+ $url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
67
+ }
68
+ return $url;
69
+ }
70
+
71
+
72
+
73
+ }
app/code/local/Bintime/Sinchimport/Model/Image.php CHANGED
@@ -1,118 +1,118 @@
1
- <?php
2
-
3
- class Bintime_Sinchimport_Model_Image extends Mage_Catalog_Model_Product_Image {
4
-
5
- public function setBaseFile($file)
6
- {
7
- $this->_isBaseFilePlaceholder = false;
8
- if (substr($file,0,4) != 'http') {
9
- if (($file) && (0 !== strpos($file, '/', 0))) {
10
- $file = '/' . $file;
11
- }
12
- $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath();
13
- if ('/no_selection' == $file) {
14
- $file = null;
15
- }
16
- if ($file) {
17
- if ((!file_exists($baseDir . $file)) || !$this->_checkMemory($baseDir . $file)) {
18
- $file = null;
19
- }
20
- }
21
- if (!$file) {
22
- // check if placeholder defined in config
23
- $isConfigPlaceholder = Mage::getStoreConfig("catalog/placeholder/{$this->getDestinationSubdir()}_placeholder");
24
- $configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
25
- if ($isConfigPlaceholder && file_exists($baseDir . $configPlaceholder)) {
26
- $file = $configPlaceholder;
27
- }
28
- else {
29
- // replace file with skin or default skin placeholder
30
- $skinBaseDir = Mage::getDesign()->getSkinBaseDir();
31
- $skinPlaceholder = "/images/catalog/product/placeholder/{$this->getDestinationSubdir()}.jpg";
32
- $file = $skinPlaceholder;
33
- if (file_exists($skinBaseDir . $file)) {
34
- $baseDir = $skinBaseDir;
35
- }
36
- else {
37
- $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default'));
38
- if (!file_exists($baseDir . $file)) {
39
- $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default', '_package' => 'base'));
40
- }
41
- }
42
- }
43
- $this->_isBaseFilePlaceholder = true;
44
- }
45
-
46
- $baseFile = $baseDir . $file;
47
- }
48
- else {
49
- $baseFile =$file;
50
- }
51
- if ((!$file) AND (!file_exists($baseFile)) AND substr($baseFile,0,4) != 'http') {
52
- throw new Exception(Mage::helper('catalog')->__('Image file not found'));
53
- }
54
-
55
- $this->_baseFile = $baseFile;
56
- if (substr($baseFile,0,4) != 'http') {
57
- // build new filename (most important params)
58
- $path = array(
59
- Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
60
- 'cache',
61
- Mage::app()->getStore()->getId(),
62
- $path[] = $this->getDestinationSubdir()
63
- );
64
- if((!empty($this->_width)) || (!empty($this->_height)))
65
- $path[] = "{$this->_width}x{$this->_height}";
66
-
67
- // add misk params as a hash
68
- $miscParams = array(
69
- ($this->_keepAspectRatio ? '' : 'non') . 'proportional',
70
- ($this->_keepFrame ? '' : 'no') . 'frame',
71
- ($this->_keepTransparency ? '' : 'no') . 'transparency',
72
- ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
73
- $this->_rgbToString($this->_backgroundColor),
74
- 'angle' . $this->_angle,
75
- 'quality' . $this->_quality
76
- );
77
-
78
- // if has watermark add watermark params to hash
79
- if ($this->getWatermarkFile()) {
80
- $miscParams[] = $this->getWatermarkFile();
81
- $miscParams[] = $this->getWatermarkImageOpacity();
82
- $miscParams[] = $this->getWatermarkPosition();
83
- $miscParams[] = $this->getWatermarkWidth();
84
- $miscParams[] = $this->getWatermarkHeigth();
85
- }
86
-
87
- $path[] = md5(implode('_', $miscParams));
88
- }
89
- else {
90
- $path[] = $file;
91
- }
92
-
93
-
94
- // append prepared filename
95
- if (substr($file,0,4) != 'http') {
96
- $this->_newFile = implode('/', $path) . $file; // the $file contains heading slash
97
- }
98
- else {
99
- $this->_newFile = $file;
100
- }
101
- return $this;
102
- }
103
-
104
- protected function _rgbToString($rgbArray)
105
- {
106
- $result = array();
107
- foreach ($rgbArray as $value) {
108
- if (null === $value) {
109
- $result[] = 'null';
110
- }
111
- else {
112
- $result[] = sprintf('%02s', dechex($value));
113
- }
114
- }
115
- return implode($result);
116
- }
117
-
118
- }
1
+ <?php
2
+
3
+ class Bintime_Sinchimport_Model_Image extends Mage_Catalog_Model_Product_Image {
4
+
5
+ public function setBaseFile($file)
6
+ {
7
+ $this->_isBaseFilePlaceholder = false;
8
+ if (substr($file,0,4) != 'http') {
9
+ if (($file) && (0 !== strpos($file, '/', 0))) {
10
+ $file = '/' . $file;
11
+ }
12
+ $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath();
13
+ if ('/no_selection' == $file) {
14
+ $file = null;
15
+ }
16
+ if ($file) {
17
+ if ((!file_exists($baseDir . $file)) || !$this->_checkMemory($baseDir . $file)) {
18
+ $file = null;
19
+ }
20
+ }
21
+ if (!$file) {
22
+ // check if placeholder defined in config
23
+ $isConfigPlaceholder = Mage::getStoreConfig("catalog/placeholder/{$this->getDestinationSubdir()}_placeholder");
24
+ $configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
25
+ if ($isConfigPlaceholder && file_exists($baseDir . $configPlaceholder)) {
26
+ $file = $configPlaceholder;
27
+ }
28
+ else {
29
+ // replace file with skin or default skin placeholder
30
+ $skinBaseDir = Mage::getDesign()->getSkinBaseDir();
31
+ $skinPlaceholder = "/images/catalog/product/placeholder/{$this->getDestinationSubdir()}.jpg";
32
+ $file = $skinPlaceholder;
33
+ if (file_exists($skinBaseDir . $file)) {
34
+ $baseDir = $skinBaseDir;
35
+ }
36
+ else {
37
+ $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default'));
38
+ if (!file_exists($baseDir . $file)) {
39
+ $baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default', '_package' => 'base'));
40
+ }
41
+ }
42
+ }
43
+ $this->_isBaseFilePlaceholder = true;
44
+ }
45
+
46
+ $baseFile = $baseDir . $file;
47
+ }
48
+ else {
49
+ $baseFile =$file;
50
+ }
51
+ if ((!$file) AND (!file_exists($baseFile)) AND substr($baseFile,0,4) != 'http') {
52
+ throw new Exception(Mage::helper('catalog')->__('Image file not found'));
53
+ }
54
+
55
+ $this->_baseFile = $baseFile;
56
+ if (substr($baseFile,0,4) != 'http') {
57
+ // build new filename (most important params)
58
+ $path = array(
59
+ Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
60
+ 'cache',
61
+ Mage::app()->getStore()->getId(),
62
+ $path[] = $this->getDestinationSubdir()
63
+ );
64
+ if((!empty($this->_width)) || (!empty($this->_height)))
65
+ $path[] = "{$this->_width}x{$this->_height}";
66
+
67
+ // add misk params as a hash
68
+ $miscParams = array(
69
+ ($this->_keepAspectRatio ? '' : 'non') . 'proportional',
70
+ ($this->_keepFrame ? '' : 'no') . 'frame',
71
+ ($this->_keepTransparency ? '' : 'no') . 'transparency',
72
+ ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
73
+ $this->_rgbToString($this->_backgroundColor),
74
+ 'angle' . $this->_angle,
75
+ 'quality' . $this->_quality
76
+ );
77
+
78
+ // if has watermark add watermark params to hash
79
+ if ($this->getWatermarkFile()) {
80
+ $miscParams[] = $this->getWatermarkFile();
81
+ $miscParams[] = $this->getWatermarkImageOpacity();
82
+ $miscParams[] = $this->getWatermarkPosition();
83
+ $miscParams[] = $this->getWatermarkWidth();
84
+ $miscParams[] = $this->getWatermarkHeigth();
85
+ }
86
+
87
+ $path[] = md5(implode('_', $miscParams));
88
+ }
89
+ else {
90
+ $path[] = $file;
91
+ }
92
+
93
+
94
+ // append prepared filename
95
+ if (substr($file,0,4) != 'http') {
96
+ $this->_newFile = implode('/', $path) . $file; // the $file contains heading slash
97
+ }
98
+ else {
99
+ $this->_newFile = $file;
100
+ }
101
+ return $this;
102
+ }
103
+
104
+ protected function _rgbToString($rgbArray)
105
+ {
106
+ $result = array();
107
+ foreach ($rgbArray as $value) {
108
+ if (null === $value) {
109
+ $result[] = 'null';
110
+ }
111
+ else {
112
+ $result[] = sprintf('%02s', dechex($value));
113
+ }
114
+ }
115
+ return implode($result);
116
+ }
117
+
118
+ }
app/code/local/Bintime/Sinchimport/Model/Layer.php CHANGED
@@ -1,49 +1,49 @@
1
- <?php
2
-
3
- class Bintime_Sinchimport_Model_Layer extends Mage_Catalog_Model_Layer
4
- {
5
- /**
6
- * Возвращает фичи, по которым следует строить навигацию для данной категории.
7
- *
8
- * @return mixed
9
- */
10
- public function getFilterableFeatures()
11
- {
12
- Varien_Profiler::start(__METHOD__);
13
-
14
- $category = Mage::registry('current_category');
15
- if( empty($category) ) { $category = Mage::getModel('catalog/category')->load( Mage::app()->getStore()->getRootCategoryId() ); }
16
- $categoryId = $category->getEntityId();
17
- $resource = Mage::getSingleton('core/resource');
18
- $tCategor = $resource->getTableName('stINch_categories');
19
- $tCatFeature = $resource->getTableName('stINch_categories_features');
20
- $tRestrictedVal = $resource->getTableName('stINch_restricted_values');
21
- $tCategMapp = $resource->getTableName('stINch_categories_mapping');
22
-
23
- $select = new Varien_Db_Select(Mage::getSingleton('core/resource')->getConnection('core_read'));
24
- $select->from(array('cf' => $tCatFeature))
25
- ->joinInner(
26
- array('rv' => $tRestrictedVal),
27
- 'cf.category_feature_id = rv.category_feature_id'
28
- )
29
- ->joinInner(
30
- array('cm' => $tCategMapp),
31
- 'cf.store_category_id = cm.store_category_id'
32
- )
33
- ->where('cm.shop_entity_id = '.$categoryId)
34
- ->group('cf.feature_name')
35
- ->order('cf.display_order_number', 'asc')
36
- ->order('cf.feature_name', 'asc')
37
- ->order('rv.display_order_number', 'asc');
38
- ;
39
- $select->columns('cf.feature_name AS name');
40
- $select->columns('cf.category_feature_id as feature_id');
41
- $select->columns('GROUP_CONCAT(`rv`.`text` SEPARATOR "\n") as restricted_values');
42
- $result = $select->query();
43
- // echo $select->__toString();
44
- //exit;
45
- Varien_Profiler::stop(__METHOD__);
46
- return $result;
47
- }
48
-
49
- }
1
+ <?php
2
+
3
+ class Bintime_Sinchimport_Model_Layer extends Mage_Catalog_Model_Layer
4
+ {
5
+ /**
6
+ * Возвращает фичи, по которым следует строить навигацию для данной категории.
7
+ *
8
+ * @return mixed
9
+ */
10
+ public function getFilterableFeatures()
11
+ {
12
+ Varien_Profiler::start(__METHOD__);
13
+
14
+ $category = Mage::registry('current_category');
15
+ if( empty($category) ) { $category = Mage::getModel('catalog/category')->load( Mage::app()->getStore()->getRootCategoryId() ); }
16
+ $categoryId = $category->getEntityId();
17
+ $resource = Mage::getSingleton('core/resource');
18
+ $tCategor = $resource->getTableName('stINch_categories');
19
+ $tCatFeature = $resource->getTableName('stINch_categories_features');
20
+ $tRestrictedVal = $resource->getTableName('stINch_restricted_values');
21
+ $tCategMapp = $resource->getTableName('stINch_categories_mapping');
22
+
23
+ $select = new Varien_Db_Select(Mage::getSingleton('core/resource')->getConnection('core_read'));
24
+ $select->from(array('cf' => $tCatFeature))
25
+ ->joinInner(
26
+ array('rv' => $tRestrictedVal),
27
+ 'cf.category_feature_id = rv.category_feature_id'
28
+ )
29
+ ->joinInner(
30
+ array('cm' => $tCategMapp),
31
+ 'cf.store_category_id = cm.store_category_id'
32
+ )
33
+ ->where('cm.shop_entity_id = '.$categoryId)
34
+ ->group('cf.feature_name')
35
+ ->order('cf.display_order_number', 'asc')
36
+ ->order('cf.feature_name', 'asc')
37
+ ->order('rv.display_order_number', 'asc');
38
+ ;
39
+ $select->columns('cf.feature_name AS name');
40
+ $select->columns('cf.category_feature_id as feature_id');
41
+ $select->columns('GROUP_CONCAT(`rv`.`text` SEPARATOR "\n") as restricted_values');
42
+ $result = $select->query();
43
+ // echo $select->__toString();
44
+ //exit;
45
+ Varien_Profiler::stop(__METHOD__);
46
+ return $result;
47
+ }
48
+
49
+ }
app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Feature.php CHANGED
@@ -1,260 +1,248 @@
1
- <?php
2
-
3
- class Bintime_Sinchimport_Model_Layer_Filter_Feature extends Mage_Catalog_Model_Layer_Filter_Abstract
4
- {
5
- protected $_resource;
6
-
7
- protected $dont_panic = true;
8
-
9
- const LESS = 1;
10
- const GREATER = 2;
11
- /**
12
- * Construct attribute filter
13
- *
14
- */
15
- public function __construct()
16
- {
17
- parent::__construct();
18
- $this->_requestVar = 'ice_feature';
19
- }
20
-
21
- /**
22
- * Задаёт атрибут и строку запроса для текущего фильтра
23
- * @param Фича из Icecat'a
24
- * @return Bintime_Icelayered_Model_Layer_Filter_Feature
25
- */
26
- public function setAttributeModel($attribute)
27
- {
28
- $this->setRequestVar('feature_' . $attribute['category_feature_id']);
29
- $this->setData('attribute_model', $attribute);
30
- return $this;
31
- }
32
-
33
- public function getName()
34
- {
35
- $attribute = $this->getAttributeModel();
36
- return $attribute['name'];
37
- }
38
-
39
- /**
40
- * Retrieve resource instance
41
- *
42
- * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Attribute
43
- */
44
- protected function _getResource()
45
- {
46
-
47
- if (is_null($this->_resource)) {
48
- $this->_resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
49
- }
50
- return $this->_resource;
51
- }
52
-
53
- /**
54
- * Get option text from frontend model by option id
55
- *
56
- * @param int $optionId
57
- * @return unknown
58
- */
59
- protected function _getOptionText($optionId)
60
- {
61
- $feature = $this->getAttributeModel();
62
- return $optionId;
63
- }
64
-
65
- /**
66
- * Apply attribute option filter to product collection
67
- *
68
- * @param Zend_Controller_Request_Abstract $request
69
- * @param Varien_Object $filterBlock
70
- * @return Mage_Catalog_Model_Layer_Filter_Attribute
71
- */
72
- public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
73
- {
74
- $filter = $request->getParam($this->_requestVar);
75
- if (is_array($filter)) {
76
- return $this;
77
- }
78
-
79
- $text = $this->_getOptionText($filter);
80
- if ($filter && $text) {
81
- $this->_getResource()->applyFilterToCollection($this, $filter);
82
- $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
83
- $this->_items = array();
84
- }
85
-
86
- return $this;
87
- }
88
-
89
- /**
90
- * Check whether specified attribute can be used in LN
91
- *
92
- * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
93
- * @return bool
94
- */
95
- protected function _getIsFilterableAttribute($attribute)
96
- {
97
- if ($this->dont_panic) return null;
98
- die(__METHOD__);
99
- return $attribute->getIsFilterable();
100
- }
101
-
102
- /**
103
- * Возвращает массив с информацией по опциям фильтра.
104
- * @return array
105
- */
106
- protected function _getItemsData()
107
- {
108
- Varien_Profiler::start(__METHOD__);
109
-
110
- $feature = $this->getAttributeModel();
111
- $this->_requestVar = 'feature_' . $feature['category_feature_id'];
112
- $limitDirection = $feature['limit_direction'];
113
-
114
- $data = array();
115
- $options = explode("\n", $feature['restricted_values']);
116
- if ($feature['order_val'] == '2') {
117
- $options = array_reverse($options);
118
- }
119
-
120
- if (count($options)) {
121
- if ($limitDirection != self::LESS && $limitDirection != self::GREATER) {
122
-
123
- $optionsCount = $this->_getResource()->getCount($this);
124
- foreach ($options as $option) {
125
- if ($pos = strpos($option, '::')) {
126
- $value = substr($option, 0, $pos);
127
- $presentation_value = substr($option, $pos + 2);
128
- //var_dump($option, $value, $presentation_value); die('sadf');
129
- }
130
- else {
131
- $value = $presentation_value = $option;
132
- }
133
- if (isset($optionsCount[$value]) && $optionsCount[$value] > 0) {
134
- $data[] = array(
135
- 'label' => $presentation_value,
136
- 'value' => $value,
137
- 'count' => $optionsCount[$value],
138
- );
139
- }
140
- }
141
- }
142
- else {
143
- $oCount = count($options);
144
-
145
- $intervals = array();
146
- if ($feature['order_val'] == '2') {
147
- for ($i = 0; $i < $oCount -1; $i++) {
148
- $intervals[$i]['high'] = $options[$i];
149
- $intervals[$i]['low'] = $options[$i +1];
150
- }
151
- }
152
- else {
153
- for ($i = 0; $i < $oCount -1; $i++) {
154
- $intervals[$i]['low'] = $options[$i];
155
- $intervals[$i]['high'] = $options[$i +1];
156
- }
157
- }
158
- //FIXME: this is ugly
159
- if ($feature['order_val'] == '2') {
160
- array_push ($intervals, array(
161
- 'high' => $options[$oCount -1],
162
- ));
163
-
164
- array_unshift($intervals, array(
165
- 'low' => $options[0],
166
- ));
167
- }
168
- else {
169
- array_push ($intervals, array(
170
- 'low' => $options[$oCount -1],
171
- ));
172
-
173
- array_unshift($intervals, array(
174
- 'high' => $options[0],
175
- ));
176
-
177
- }
178
-
179
- $this->setData('intervals', $intervals);
180
-
181
- $defaultSign = $feature['default_sign'];
182
- for($i = 0; $i < count($intervals); $i++) {
183
- if ($feature['order_val'] == '2') {
184
- $interval = $intervals[$i];
185
- $label = isset($interval['high']) ? $interval['high'] . " $defaultSign" : '>';
186
- if ($label == '>' && isset($intervals[$i + 1])) {
187
- $pad = strlen($intervals[$i + 1]['high'] . $defaultSign) + 2;
188
- $label = str_pad($label, $pad*2, ' ', STR_PAD_LEFT);
189
- $label = str_replace(' ', '&nbsp', $label);
190
- }
191
- $label .= isset($interval['high'], $interval['high']) ? ' - ' : ' ';
192
- $label .= isset($interval['low']) ? $interval['low'] . " $defaultSign" : '>';
193
- $value = isset($interval['low']) ? $interval['low'] : '-';
194
- $value .= ',';
195
- $value .= isset($interval['high']) ? $interval['high'] : '-';
196
- if (isset($interval['high']) AND !isset($interval['low'])) { $value = '-,'.$interval['high'];}
197
- if ($this->_getResource()->getIntervalsCountDescending($this, $interval) > 0){
198
- $data[] = array(
199
- 'label' => $label,
200
- 'value' => $value,
201
- 'count' => $this->_getResource()->getIntervalsCountDescending($this, $interval),
202
- );
203
-
204
- }
205
- }
206
- else {
207
- $interval = $intervals[$i];
208
- $label = isset($interval['low']) ? $interval['low'] . " $defaultSign" : '<';
209
- if ($label == '<' && isset($intervals[$i + 1])) {
210
- $pad = strlen($intervals[$i + 1]['low'] . $defaultSign) + 2;
211
- $label = str_pad($label, $pad*2, ' ', STR_PAD_LEFT);
212
- $label = str_replace(' ', '&nbsp', $label);
213
- }
214
- $label .= isset($interval['low'], $interval['high']) ? ' - ' : ' ';
215
- $label .= isset($interval['high']) ? $interval['high'] . " $defaultSign" : '<';
216
-
217
- $value = isset($interval['low']) ? $interval['low'] : '-';
218
- $value .= ',';
219
- $value .= isset($interval['high']) ? $interval['high'] : '-';
220
- if ($this->_getResource()->getIntervalsCount($this, $interval) > 0){
221
- $data[] = array(
222
- 'label' => $label,
223
- 'value' => $value,
224
- 'count' => $this->_getResource()->getIntervalsCount($this, $interval),
225
- );
226
-
227
- }
228
-
229
- }
230
- }
231
-
232
- }
233
- }
234
-
235
- Varien_Profiler::stop(__METHOD__);
236
- return $data;
237
- }
238
-
239
- public function getOrderValues($category_feature_id,$categoryId)
240
- {
241
- $select = "
242
- SELECT COUNT(e.entity_id) AS count
243
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." AS e
244
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." AS cat_index
245
- ON cat_index.product_id=e.entity_id
246
- AND cat_index.store_id='1'
247
- AND cat_index.visibility IN(2, 4)
248
- AND cat_index.category_id='".$categoryId."'
249
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
250
- ON price_index.entity_id = e.entity_id
251
- AND price_index.website_id = '1'
252
- AND price_index.customer_group_id = 0
253
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_feature_'.$feature['category_feature_id'])." AS idx_".$category_feature_id."
254
- ON idx_".$category_feature_id.".entity_id = e.icecat_product_id;
255
- ";
256
-
257
- return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select);
258
- }
259
-
260
- }
1
+ <?php
2
+
3
+ class Bintime_Sinchimport_Model_Layer_Filter_Feature extends Mage_Catalog_Model_Layer_Filter_Abstract
4
+ {
5
+ protected $_resource;
6
+
7
+ protected $dont_panic = true;
8
+
9
+ const LESS = 1;
10
+ const GREATER = 2;
11
+ /**
12
+ * Construct attribute filter
13
+ *
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+ $this->_requestVar = 'ice_feature';
19
+ }
20
+
21
+ /**
22
+ * Задаёт атрибут и строку запроса для текущего фильтра
23
+ * @param Фича из Icecat'a
24
+ * @return Bintime_Icelayered_Model_Layer_Filter_Feature
25
+ */
26
+ public function setAttributeModel($attribute)
27
+ {
28
+ $this->setRequestVar('feature_' . $attribute['category_feature_id']);
29
+ $this->setData('attribute_model', $attribute);
30
+ return $this;
31
+ }
32
+
33
+ public function getName()
34
+ {
35
+ $attribute = $this->getAttributeModel();
36
+ return $attribute['name'];
37
+ }
38
+
39
+ /**
40
+ * Retrieve resource instance
41
+ *
42
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Attribute
43
+ */
44
+ protected function _getResource()
45
+ {
46
+
47
+ if (is_null($this->_resource)) {
48
+ $this->_resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
49
+ }
50
+ return $this->_resource;
51
+ }
52
+
53
+ /**
54
+ * Get option text from frontend model by option id
55
+ *
56
+ * @param int $optionId
57
+ * @return unknown
58
+ */
59
+ protected function _getOptionText($optionId)
60
+ {
61
+ $feature = $this->getAttributeModel();
62
+ return $optionId;
63
+ }
64
+
65
+ /**
66
+ * Apply attribute option filter to product collection
67
+ *
68
+ * @param Zend_Controller_Request_Abstract $request
69
+ * @param Varien_Object $filterBlock
70
+ * @return Mage_Catalog_Model_Layer_Filter_Attribute
71
+ */
72
+ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
73
+ {
74
+ $filter = $request->getParam($this->_requestVar);
75
+ if (is_array($filter)) {
76
+ return $this;
77
+ }
78
+
79
+ $text = $this->_getOptionText($filter);
80
+ if ($filter && $text) {
81
+ $this->_getResource()->applyFilterToCollection($this, $filter);
82
+ $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
83
+ $this->_items = array();
84
+ }
85
+
86
+ return $this;
87
+ }
88
+
89
+ /**
90
+ * Check whether specified attribute can be used in LN
91
+ *
92
+ * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
93
+ * @return bool
94
+ */
95
+ protected function _getIsFilterableAttribute($attribute)
96
+ {
97
+ if ($this->dont_panic) return null;
98
+ die(__METHOD__);
99
+ return $attribute->getIsFilterable();
100
+ }
101
+
102
+ /**
103
+ * Возвращает массив с информацией по опциям фильтра.
104
+ * @return array
105
+ */
106
+ protected function _getItemsData()
107
+ {
108
+ Varien_Profiler::start(__METHOD__);
109
+
110
+ $feature = $this->getAttributeModel();
111
+ $this->_requestVar = 'feature_' . $feature['category_feature_id'];
112
+ $limitDirection = isset($feature['limit_direction']) ? $feature['limit_direction'] : 0;
113
+
114
+ $data = array();
115
+ $options = explode("\n", $feature['restricted_values']);
116
+ if (count($options) == 0) {
117
+ Varien_Profiler::stop(__METHOD__);
118
+ return $data;
119
+ }
120
+ if (isset($feature['order_val']) && $feature['order_val'] == '2') {
121
+ $options = array_reverse($options);
122
+ }
123
+ if ($limitDirection != self::LESS && $limitDirection != self::GREATER) {
124
+
125
+ $optionsCount = $this->_getResource()->getCount($this);
126
+ foreach ($options as $option) {
127
+ if ($pos = strpos($option, '::')) {
128
+ $value = substr($option, 0, $pos);
129
+ $presentation_value = substr($option, $pos + 2);
130
+ }
131
+ else {
132
+ $value = $presentation_value = $option;
133
+ }
134
+ if (isset($optionsCount[$value]) && $optionsCount[$value] > 0) {
135
+ $data[] = array(
136
+ 'label' => $presentation_value,
137
+ 'value' => $value,
138
+ 'count' => $optionsCount[$value],
139
+ );
140
+ }
141
+ }
142
+ } else {
143
+ $oCount = count($options);
144
+ $intervals = array();
145
+ if ($feature['order_val'] == '2') {
146
+ for ($i = 0; $i < $oCount -1; $i++) {
147
+ $intervals[$i]['high'] = $options[$i];
148
+ $intervals[$i]['low'] = $options[$i +1];
149
+ }
150
+ } else {
151
+ for ($i = 0; $i < $oCount -1; $i++) {
152
+ $intervals[$i]['low'] = $options[$i];
153
+ $intervals[$i]['high'] = $options[$i +1];
154
+ }
155
+ }
156
+ //FIXME: this is ugly
157
+ if ($feature['order_val'] == '2') {
158
+ array_push ($intervals, array(
159
+ 'high' => $options[$oCount -1],
160
+ ));
161
+ array_unshift($intervals, array(
162
+ 'low' => $options[0],
163
+ ));
164
+ } else {
165
+ array_push ($intervals, array(
166
+ 'low' => $options[$oCount -1],
167
+ ));
168
+ array_unshift($intervals, array(
169
+ 'high' => $options[0],
170
+ ));
171
+ }
172
+
173
+ $this->setData('intervals', $intervals);
174
+
175
+ $defaultSign = $feature['default_sign'];
176
+ for($i = 0; $i < count($intervals); $i++) {
177
+ if ($feature['order_val'] == '2') {
178
+ $interval = $intervals[$i];
179
+ $label = isset($interval['high']) ? $interval['high'] . " $defaultSign" : '>';
180
+ if ($label == '>' && isset($intervals[$i + 1])) {
181
+ $pad = strlen($intervals[$i + 1]['high'] . $defaultSign) + 2;
182
+ $label = str_pad($label, $pad*2, ' ', STR_PAD_LEFT);
183
+ $label = str_replace(' ', '&nbsp', $label);
184
+ }
185
+ $label .= isset($interval['high'], $interval['high']) ? ' - ' : ' ';
186
+ $label .= isset($interval['low']) ? $interval['low'] . " $defaultSign" : '>';
187
+ $value = isset($interval['low']) ? $interval['low'] : '-';
188
+ $value .= ',';
189
+ $value .= isset($interval['high']) ? $interval['high'] : '-';
190
+ if (isset($interval['high']) AND !isset($interval['low'])) { $value = '-,'.$interval['high'];}
191
+ if ($this->_getResource()->getIntervalsCountDescending($this, $interval) > 0){
192
+ $data[] = array(
193
+ 'label' => $label,
194
+ 'value' => $value,
195
+ 'count' => $this->_getResource()->getIntervalsCountDescending($this, $interval),
196
+ );
197
+ }
198
+ } else {
199
+ $interval = $intervals[$i];
200
+ $label = isset($interval['low']) ? $interval['low'] . " $defaultSign" : '<';
201
+ if ($label == '<' && isset($intervals[$i + 1])) {
202
+ $pad = strlen($intervals[$i + 1]['low'] . $defaultSign) + 2;
203
+ $label = str_pad($label, $pad*2, ' ', STR_PAD_LEFT);
204
+ $label = str_replace(' ', '&nbsp', $label);
205
+ }
206
+ $label .= isset($interval['low'], $interval['high']) ? ' - ' : ' ';
207
+ $label .= isset($interval['high']) ? $interval['high'] . " $defaultSign" : '<';
208
+
209
+ $value = isset($interval['low']) ? $interval['low'] : '-';
210
+ $value .= ',';
211
+ $value .= isset($interval['high']) ? $interval['high'] : '-';
212
+ if ($this->_getResource()->getIntervalsCount($this, $interval) > 0){
213
+ $data[] = array(
214
+ 'label' => $label,
215
+ 'value' => $value,
216
+ 'count' => $this->_getResource()->getIntervalsCount($this, $interval),
217
+ );
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ Varien_Profiler::stop(__METHOD__);
224
+ return $data;
225
+ }
226
+
227
+ public function getOrderValues($category_feature_id,$categoryId)
228
+ {
229
+ $select = "
230
+ SELECT COUNT(e.entity_id) AS count
231
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." AS e
232
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." AS cat_index
233
+ ON cat_index.product_id=e.entity_id
234
+ AND cat_index.store_id='1'
235
+ AND cat_index.visibility IN(2, 4)
236
+ AND cat_index.category_id='".$categoryId."'
237
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
238
+ ON price_index.entity_id = e.entity_id
239
+ AND price_index.website_id = '1'
240
+ AND price_index.customer_group_id = 0
241
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_feature_'.$feature['category_feature_id'])." AS idx_".$category_feature_id."
242
+ ON idx_".$category_feature_id.".entity_id = e.icecat_product_id;
243
+ ";
244
+
245
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select);
246
+ }
247
+
248
+ }
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Price.php CHANGED
@@ -1,194 +1,189 @@
1
- <?php
2
-
3
- /**
4
- * price filter - override price breaks for customer price grouping
5
- *
6
- * @category Mage
7
- * @package Mage_Catalog
8
- * @author Sergey Stepanchuk
9
- */
10
- class Bintime_Sinchimport_Model_Layer_Filter_Price extends Mage_Catalog_Model_Layer_Filter_Price
11
- {
12
- /**
13
- * Get price range for building filter steps
14
- *
15
- * @return int
16
- *//*
17
- public function getPriceRange()
18
- {
19
-
20
- $range = $this->getData('price_range');
21
- if (is_null($range)) {
22
- $maxPrice = $this->getMaxPriceInt();
23
- $index = 2;
24
- if ($maxPrice<1000) {
25
- $index = 1;
26
- }
27
- do {
28
- $range = pow(10, (strlen(floor($maxPrice))-$index));
29
- $items = $this->getRangeItemCounts($range);
30
- $index++;
31
- }
32
- while($range>self::MIN_RANGE_POWER && count($items)<2);
33
-
34
- $this->setData('price_range', $range);
35
- }
36
- return $range;
37
- }
38
-
39
- */
40
- /**
41
- * Apply price range filter to collection
42
- *
43
- * @param Zend_Controller_Request_Abstract $request
44
- * @param $filterBlock
45
- *
46
- * @return Mage_Catalog_Model_Layer_Filter_Price
47
- */
48
- public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
49
- {
50
- /**
51
- * Filter must be string: $index,$range
52
- */
53
- $filter = $request->getParam($this->getRequestVar());
54
- if (!$filter) {
55
- return $this;
56
- }
57
- /* echo "<pre>";
58
- var_dump($filter);
59
- echo "</pre>";
60
- */
61
- if(strstr($filter, ',')){
62
- $filter = explode(',', $filter);
63
- if (count($filter) != 2) {
64
- return $this;
65
- }
66
- list($index, $range) = $filter;
67
- // echo $index.$range."AAAAAAAa";
68
- if ((int)$index && (int)$range) {
69
- $this->setPriceRange((int)$range);
70
-
71
- $this->_applyToCollection($range, $index);
72
- $this->getLayer()->getState()->addFilter(
73
- $this->_createItem($this->_renderItemLabel($range, $index), $filter)
74
- );
75
-
76
- $this->_items = array();
77
- }
78
-
79
- }elseif(strstr($filter, '-')){
80
- $filter = explode('-', $filter);
81
- if (count($filter) != 2) {
82
- return $this;
83
- }
84
-
85
- list($minPrice, $maxPrice) = $filter;
86
- // echo $minPrice."BBBBBB".$maxPrice;
87
-
88
- // if ((int)$minPrice && (int)$maxPrice) {
89
- if(((int)$minPrice || $minPrice==0) && ((int)$maxPrice || $maxPrice=='*')){
90
- // $this->setPriceRange((int)$range);
91
-
92
- $this->_applyToCollectionMinMaxPrice($minPrice, $maxPrice);
93
- $this->getLayer()->getState()->addFilter(
94
- $this->_createItem($this->_renderItemLabelMinMaxPrice($minPrice, $maxPrice), $filter)
95
- );
96
-
97
- $this->_items = array();
98
- }
99
-
100
- }
101
-
102
- return $this;
103
- }
104
- /**
105
- * Prepare text of item label
106
- *
107
- * @param int $fromPrice
108
- * @param int
109
- * @return string
110
- */
111
-
112
- protected function _renderItemLabelMinMaxPrice($fromPrice, $toPrice)
113
- {
114
- $store = Mage::app()->getStore();
115
- $toPriceLabel=$toPrice;
116
- $fromPrice = $store->formatPrice($fromPrice);
117
- $toPrice = $store->formatPrice($toPrice);
118
- $label= Mage::helper('catalog')->__('%s - %s', $fromPrice, $toPrice);
119
- if( $toPriceLabel=='' || $toPriceLabel=='*'){
120
- $label=$fromPrice." + ";
121
- }
122
-
123
- return $label;
124
- }
125
-
126
- /**
127
- * Get data for build price filter items
128
- *
129
- * @return array
130
- */
131
- protected function _getItemsData()
132
- {
133
- // $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
134
- // $price_breaks=$dataConf['price_breaks'];
135
- $import=Mage::getModel('sinchimport/sinch');
136
- $price_breaks=$import->price_breaks_filter;
137
-
138
- if(strstr($price_breaks, ';')){
139
- $price_ranges = explode(';', $price_breaks);
140
-
141
- foreach ($price_ranges as $price_range) {
142
- $price_range_value=trim($price_range);
143
- if($price_range && $price_range!=''){
144
-
145
- $price_range = explode('-', $price_range);
146
- list($minPrice, $maxPrice) = $price_range;
147
- if(((int)$minPrice || $minPrice==0) && ((int)$maxPrice || $maxPrice=='*')){
148
- $count=$this->_getResource()->getCountMinMaxPrice($this, $minPrice, $maxPrice);
149
- if($count){
150
- $data[] = array(
151
- 'label' => $this->_renderItemLabelMinMaxPrice($minPrice, $maxPrice),
152
- 'value' =>$price_range_value,
153
- 'count' => $count,
154
- );
155
- }
156
- }
157
- }
158
- }
159
- if($data){
160
- return $data;
161
- }
162
-
163
- }
164
-
165
- $range = $this->getPriceRange();
166
- $dbRanges = $this->getRangeItemCounts($range);
167
- $data = array();
168
-
169
- foreach ($dbRanges as $index=>$count) {
170
- $data[] = array(
171
- 'label' => $this->_renderItemLabel($range, $index),
172
- 'value' => $index . ',' . $range,
173
- 'count' => $count,
174
- );
175
- }
176
-
177
- return $data;
178
- }
179
-
180
- /**
181
- * Apply filter value to product collection based on customer price breaks and selected value
182
- *
183
- * @param int $minPrice
184
- * @param int $maxPrice
185
- * @return Mage_Catalog_Model_Layer_Filter_Price
186
- */
187
-
188
- protected function _applyToCollectionMinMaxPrice($minPrice, $maxPrice)
189
- {
190
- $this->_getResource()->applyFilterToCollectionMinMaxPrice($this, $minPrice, $maxPrice);
191
- return $this;
192
- }
193
-
194
- }
1
+ <?php
2
+
3
+ /**
4
+ * price filter - override price breaks for customer price grouping
5
+ *
6
+ * @category Mage
7
+ * @package Mage_Catalog
8
+ * @author Sergey Stepanchuk
9
+ */
10
+ class Bintime_Sinchimport_Model_Layer_Filter_Price extends Mage_Catalog_Model_Layer_Filter_Price
11
+ {
12
+ /**
13
+ * Get price range for building filter steps
14
+ *
15
+ * @return int
16
+ *//*
17
+ public function getPriceRange()
18
+ {
19
+
20
+ $range = $this->getData('price_range');
21
+ if (is_null($range)) {
22
+ $maxPrice = $this->getMaxPriceInt();
23
+ $index = 2;
24
+ if ($maxPrice<1000) {
25
+ $index = 1;
26
+ }
27
+ do {
28
+ $range = pow(10, (strlen(floor($maxPrice))-$index));
29
+ $items = $this->getRangeItemCounts($range);
30
+ $index++;
31
+ }
32
+ while($range>self::MIN_RANGE_POWER && count($items)<2);
33
+
34
+ $this->setData('price_range', $range);
35
+ }
36
+ return $range;
37
+ }
38
+
39
+ */
40
+ /**
41
+ * Apply price range filter to collection
42
+ *
43
+ * @param Zend_Controller_Request_Abstract $request
44
+ * @param $filterBlock
45
+ *
46
+ * @return Mage_Catalog_Model_Layer_Filter_Price
47
+ */
48
+ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
49
+ {
50
+ /**
51
+ * Filter must be string: $index,$range
52
+ */
53
+ $filter = $request->getParam($this->getRequestVar());
54
+ if (!$filter) {
55
+ return $this;
56
+ }
57
+ /* echo "<pre>";
58
+ var_dump($filter);
59
+ echo "</pre>";
60
+ */
61
+ if(strstr($filter, ',')){
62
+ $filter = explode(',', $filter);
63
+ if (count($filter) != 2) {
64
+ return $this;
65
+ }
66
+ list($index, $range) = $filter;
67
+ // echo $index.$range."AAAAAAAa";
68
+ if ((int)$index && (int)$range) {
69
+ $this->setPriceRange((int)$range);
70
+
71
+ $this->_applyToCollection($range, $index);
72
+ $this->getLayer()->getState()->addFilter(
73
+ $this->_createItem($this->_renderItemLabel($range, $index), $filter)
74
+ );
75
+
76
+ $this->_items = array();
77
+ }
78
+
79
+ }elseif(strstr($filter, '-')){
80
+ $filter = explode('-', $filter);
81
+ if (count($filter) != 2) {
82
+ return $this;
83
+ }
84
+
85
+ list($minPrice, $maxPrice) = $filter;
86
+ // echo $minPrice."BBBBBB".$maxPrice;
87
+
88
+ // if ((int)$minPrice && (int)$maxPrice) {
89
+ if(((int)$minPrice || $minPrice==0) && ((int)$maxPrice || $maxPrice=='*')){
90
+ // $this->setPriceRange((int)$range);
91
+
92
+ $this->_applyToCollectionMinMaxPrice($minPrice, $maxPrice);
93
+ $this->getLayer()->getState()->addFilter(
94
+ $this->_createItem($this->_renderItemLabelMinMaxPrice($minPrice, $maxPrice), $filter)
95
+ );
96
+
97
+ $this->_items = array();
98
+ }
99
+
100
+ }
101
+
102
+ return $this;
103
+ }
104
+ /**
105
+ * Prepare text of item label
106
+ *
107
+ * @param int $fromPrice
108
+ * @param int
109
+ * @return string
110
+ */
111
+
112
+ protected function _renderItemLabelMinMaxPrice($fromPrice, $toPrice)
113
+ {
114
+ $store = Mage::app()->getStore();
115
+ $toPriceLabel=$toPrice;
116
+ $fromPrice = $store->formatPrice($fromPrice);
117
+ $toPrice = $store->formatPrice($toPrice);
118
+ $label= Mage::helper('catalog')->__('%s - %s', $fromPrice, $toPrice);
119
+ if( $toPriceLabel=='' || $toPriceLabel=='*'){
120
+ $label=$fromPrice." + ";
121
+ }
122
+
123
+ return $label;
124
+ }
125
+
126
+ /**
127
+ * Get data for build price filter items
128
+ *
129
+ * @return array
130
+ */
131
+ protected function _getItemsData()
132
+ {
133
+ $import=Mage::getModel('sinchimport/sinch');
134
+ $price_breaks=$import->price_breaks_filter;
135
+
136
+ if(strpos($price_breaks, ';') !== false){
137
+ $price_ranges = explode(';', $price_breaks);
138
+ foreach ($price_ranges as $price_range) {
139
+ $price_range_value=trim($price_range);
140
+ if($price_range_value == '' || strpos($price_range_value, "-") === false) continue;
141
+ $price_range_value = explode('-', $price_range_value);
142
+ list($minPrice, $maxPrice) = $price_range_value;
143
+ if(is_numeric($minPrice) && (is_numeric($maxPrice) || $maxPrice=='*')){
144
+ $count=$this->_getResource()->getCountMinMaxPrice($this, $minPrice, $maxPrice);
145
+ if($count){
146
+ $data[] = array(
147
+ 'label' => $this->_renderItemLabelMinMaxPrice($minPrice, $maxPrice),
148
+ 'value' =>$price_range_value,
149
+ 'count' => $count,
150
+ );
151
+ }
152
+ }
153
+ }
154
+ if($data){
155
+ return $data;
156
+ }
157
+
158
+ }
159
+
160
+ $range = $this->getPriceRange();
161
+ $dbRanges = $this->getRangeItemCounts($range);
162
+ $data = array();
163
+
164
+ foreach ($dbRanges as $index=>$count) {
165
+ $data[] = array(
166
+ 'label' => $this->_renderItemLabel($range, $index),
167
+ 'value' => $index . ',' . $range,
168
+ 'count' => $count,
169
+ );
170
+ }
171
+
172
+ return $data;
173
+ }
174
+
175
+ /**
176
+ * Apply filter value to product collection based on customer price breaks and selected value
177
+ *
178
+ * @param int $minPrice
179
+ * @param int $maxPrice
180
+ * @return Mage_Catalog_Model_Layer_Filter_Price
181
+ */
182
+
183
+ protected function _applyToCollectionMinMaxPrice($minPrice, $maxPrice)
184
+ {
185
+ $this->_getResource()->applyFilterToCollectionMinMaxPrice($this, $minPrice, $maxPrice);
186
+ return $this;
187
+ }
188
+
189
+ }
 
 
 
 
 
app/code/local/Bintime/Sinchimport/Model/Resource/Layer/Filter/Price.php CHANGED
@@ -56,8 +56,7 @@ class Bintime_Sinchimport_Model_Resource_Layer_Filter_Price extends Mage_Catalo
56
  'count' => $countExpr
57
  ));
58
 
59
- $count=$connection->fetchPairs($select);
60
- return key($count);
61
  }
62
 
63
  protected function _getSelect($filter)
56
  'count' => $countExpr
57
  ));
58
 
59
+ return $connection->fetchOne($select);
 
60
  }
61
 
62
  protected function _getSelect($filter)
app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php CHANGED
@@ -1,383 +1,381 @@
1
- <?php
2
-
3
- class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mage_Core_Model_Mysql4_Abstract
4
- {
5
- protected $resultTable = 'SinchFilterResult';
6
-
7
- protected static $lastResultTable = false;
8
-
9
- protected $filterAplied = false;
10
-
11
- /**
12
- * Initialize connection and define main table name
13
- *
14
- */
15
- protected function _construct()
16
- {
17
- $this->_init('catalog/ice_feature', 'category_feature_id');
18
- }
19
-
20
- protected function _getTableName($type, $id = 0)
21
- {
22
- $tablePrefix = (string)Mage::getConfig()->getTablePrefix();
23
- switch ($type) {
24
- case 'result':
25
- $id = (int)$id;
26
- return $tablePrefix . $this->resultTable . "_$id";
27
- break;
28
- case 'search':
29
- return $tablePrefix . $this->searchTable;
30
- break;
31
- default:
32
- $resource = Mage::getSingleton('core/resource');
33
- return $resource->getTableName($type);
34
- }
35
-
36
- }
37
-
38
- /**
39
- * Подготавливает фильтр к поиску
40
- *
41
- * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
42
- * @param string $value Значение, которму должен соответствовать атрибут
43
- * @return string
44
- */
45
- protected function _prepareSearch($filter, $value = null)
46
- {
47
- Varien_Profiler::start(__METHOD__);
48
- $catId = $filter->getLayer()->getCurrentCategory()->getId();
49
- $connection = $this->_getReadAdapter();
50
-
51
- $cfid = 0;
52
- if (!is_null($value)) {
53
- $feature = $filter->getAttributeModel();
54
- $cfid = $feature['category_feature_id'];
55
- }
56
- $resultTable = $this->_getTableName('result', $cfid);
57
- //TODO: this table must be temporary
58
- $sql = "
59
- CREATE TABLE IF NOT EXISTS `{$resultTable}`(
60
- `entity_id` int(10) unsigned,
61
- `category_id` int(10) unsigned,
62
- `product_id` int,
63
- `sinch_category_id` int,
64
- `name` varchar(255),
65
- `image` varchar(255),
66
- `supplier_id` int,
67
- `category_feature_id` int,
68
- `feature_id` int,
69
- `feature_name` varchar(255),
70
- `feature_value` text
71
- );
72
- ";
73
- $connection->exec($sql);
74
-
75
- $sql = "TRUNCATE TABLE {$resultTable}";
76
- $connection->exec($sql);
77
-
78
- $featuresTable = $this->_getTableName('FilterListOfFeatures');
79
- $sql = "TRUNCATE TABLE `$featuresTable`";
80
- $connection->exec($sql);
81
-
82
- $feature = $filter->getAttributeModel();
83
- if ($feature['limit_direction'] != 1 && $feature['limit_direction'] != 2) {
84
- if (!is_null($value)) {
85
- $sql = "INSERT INTO `$featuresTable` (category_feature_id, feature_value) VALUES (?)";
86
- $sql = $connection->quoteInto($sql, array($cfid, $value));
87
- $connection->exec($sql);
88
- }
89
- $params = 'null, null';
90
- }
91
- else {
92
- $bounds = explode(',', $value);
93
-
94
- $params = $bounds[0] != '-' ? (int)$bounds[0] : 'null';
95
- $params .= ', ';
96
- $params .= $bounds[1] != '-' ? (int)$bounds[1] : 'null';
97
- }
98
- //$connection->query("CALL `filter_icecat_products_s`($cfid, $catId,0,$cfid, $params)"));
99
- $tablePrefix = (string)Mage::app()->getConfig()->getTablePrefix();
100
- $result = $connection->raw_query("CALL ".$this->_getTableName('filter_sinch_products_s')."($cfid, $catId,0, $cfid, $params, '$tablePrefix')");
101
- Varien_Profiler::stop(__METHOD__);
102
- return $resultTable;
103
- }
104
-
105
-
106
- /**
107
- * Apply attribute filter to product collection
108
- *
109
- * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
110
- * @param string $value
111
- * @return Bintime_Icelayered_Model_Resource_Mysql4_Layer_Filter_Feature
112
- */
113
- public function applyFilterToCollection($filter, $value)
114
- {
115
- Varien_Profiler::start(__METHOD__);
116
- $searchTable = $this->_prepareSearch($filter, $value);
117
- self::$lastResultTable = $searchTable;
118
-
119
- $collection = $filter->getLayer()->getProductCollection();
120
- $feature = $filter->getAttributeModel();
121
- $connection = $this->_getReadAdapter();
122
-
123
- $collection->getSelect()->join(
124
- $searchTable,
125
- "{$searchTable}.entity_id = e.entity_id",
126
- array()
127
- );
128
-
129
- Varien_Profiler::stop(__METHOD__);
130
- return $this;
131
- }
132
-
133
- /**
134
- * Retrieve array with products counts per attribute option
135
- *
136
- * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
137
- * @return array
138
- */
139
- public function getCount($filter)
140
- {
141
- Varien_Profiler::start(__METHOD__);
142
-
143
- // clone select from collection with filters
144
- $select = clone $filter->getLayer()->getProductCollection()->getSelect();
145
-
146
- // reset columns, order and limitation conditions
147
- $select->reset(Zend_Db_Select::COLUMNS);
148
- $select->reset(Zend_Db_Select::ORDER);
149
- $select->reset(Zend_Db_Select::LIMIT_COUNT);
150
- $select->reset(Zend_Db_Select::LIMIT_OFFSET);
151
- $connection = $this->_getReadAdapter();
152
- $feature = $filter->getAttributeModel();
153
- $tableAlias = 'idx_' . $feature['category_feature_id'];
154
-
155
- $conditions = array(
156
- "{$tableAlias}.entity_id = e.entity_id",
157
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
158
- );
159
-
160
- $select->joinInner(
161
- array($tableAlias => $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id'])),
162
- join(' AND ', $conditions),
163
- array('value', 'count' => "COUNT(e.entity_id)")
164
- )
165
- ->group("{$tableAlias}.value");
166
-
167
- $tablePattern = $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id']);
168
- $query = "SHOW TABLES LIKE '$tablePattern'";
169
- $featureTables = $connection->fetchCol($query);
170
- $presentFeatures = array();
171
- foreach($featureTables as $t) {
172
- if (preg_match("#$tablePattern#", $t, $matches)) {
173
- $table_feat_exist=true;
174
- }
175
- }
176
-
177
- Varien_Profiler::stop(__METHOD__);
178
- if($table_feat_exist){
179
- return $connection->fetchPairs($select);
180
- }else{
181
- return null;
182
- }
183
-
184
- }
185
-
186
- public function getIntervalsCount($filter, $interval)
187
- {
188
- Varien_Profiler::start(__METHOD__);
189
-
190
- // clone select from collection with filters
191
- $select = clone $filter->getLayer()->getProductCollection()->getSelect();
192
-
193
- // reset columns, order and limitation conditions
194
- $select->reset(Zend_Db_Select::COLUMNS);
195
- $select->reset(Zend_Db_Select::ORDER);
196
- $select->reset(Zend_Db_Select::LIMIT_COUNT);
197
- $select->reset(Zend_Db_Select::LIMIT_OFFSET);
198
-
199
- $connection = $this->_getReadAdapter();
200
- $feature = $filter->getAttributeModel();
201
- $tableAlias = 'idx_' . $feature['category_feature_id'];
202
-
203
- $conditions = array(
204
- "{$tableAlias}.entity_id = e.entity_id",
205
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
206
- );
207
-
208
- $select->joinInner(
209
- array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
210
- join(' AND ', $conditions),
211
- array('count' => "COUNT(e.entity_id)")
212
- );
213
- if (isset($interval['low'], $interval['high'])) {
214
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
215
- }
216
- else if (isset($interval['low'])) {
217
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
218
- }
219
- else if (isset($interval['high'])) {
220
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
221
- }
222
- $count = $connection->fetchOne($select);
223
- Varien_Profiler::stop(__METHOD__);
224
- return $count;
225
- }
226
-
227
- function getIntervalsCountDescending($filter, $interval)
228
- {
229
- Varien_Profiler::start(__METHOD__);
230
-
231
- // clone select from collection with filters
232
- $select = clone $filter->getLayer()->getProductCollection()->getSelect();
233
-
234
- // reset columns, order and limitation conditions
235
- $select->reset(Zend_Db_Select::COLUMNS);
236
- $select->reset(Zend_Db_Select::ORDER);
237
- $select->reset(Zend_Db_Select::LIMIT_COUNT);
238
- $select->reset(Zend_Db_Select::LIMIT_OFFSET);
239
-
240
- $connection = $this->_getReadAdapter();
241
- $feature = $filter->getAttributeModel();
242
- $tableAlias = 'idx_' . $feature['category_feature_id'];
243
-
244
- $conditions = array(
245
- "{$tableAlias}.entity_id = e.entity_id",
246
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
247
- );
248
-
249
- $select->joinInner(
250
- array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
251
- join(' AND ', $conditions),
252
- array('count' => "COUNT(e.entity_id)")
253
- );
254
- if (isset($interval['low'], $interval['high'])) {
255
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
256
- }
257
- else if (isset($interval['low'])) {
258
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
259
- }
260
- else if (isset($interval['high'])) {
261
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
262
- }
263
- $count = $connection->fetchOne($select);
264
-
265
- Varien_Profiler::stop(__METHOD__);
266
- return $count;
267
- }
268
-
269
-
270
-
271
- /*
272
- * INDEXES FOLLOW.
273
- */
274
-
275
- /**
276
- * Запускает процедуры индексации.
277
- * Слушает событие Mage::dispatchEvent('iceimport_model_import_after',..)
278
- * @param <type> $observer
279
- */
280
- public function reindex($observer)
281
- {
282
- $this->splitProductsFeature();
283
- }
284
-
285
-
286
- /**
287
- * Разбивает таблицу icecat_product_feature на таблицы вида icecat_product_feature_%category_feature_id% для каждой фичи.
288
- *
289
- */
290
- public function splitProductsFeature()
291
- {
292
- Mage::log(__METHOD__ . " start at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
293
- $featureIds = $this->getProductFeatures4indexig();
294
-
295
- $resource = Mage::getSingleton('core/resource');
296
- // $tProudctsFeature = $resource->getTableName("icecat_products_feature");
297
- $connection = $this->_getWriteAdapter();
298
-
299
- //удаление таблиц с фичами не используемыми больше для навигации.
300
- $tablePattern = $resource->getTableName('stINch_products_feature_');
301
- $query = "SHOW TABLES LIKE '%$tablePattern%'";
302
- $featureTables = $connection->fetchCol($query);
303
- $presentFeatures = array();
304
- foreach($featureTables as $t) {
305
- if (preg_match("#$tablePattern(\d+)#", $t, $matches)) {
306
- $presentFeatures[] = $matches[1];
307
- }
308
- }
309
-
310
- $features2delete = array_diff($presentFeatures, $featureIds);
311
- if (count($features2delete)) {
312
- foreach ($features2delete as & $drop) {
313
- $drop = $tablePattern . $drop;
314
- }
315
- $dropSql = "DROP TABLE " . implode(',', $features2delete);
316
- $connection->exec($dropSql);
317
- }
318
- //
319
-
320
- //Создание таблиц с фичами используемыми в навигации.
321
- $i = 0; $storeId = Mage::app()->getStore()->getId(); $websiteId = Mage::app()->getStore(true)->getWebsite()->getId();
322
- foreach ($featureIds as $featureId) {
323
- $tFeature = $resource->getTableName("stINch_products_feature_$featureId");
324
- $query = "DROP TABLE IF EXISTS $tFeature";
325
- $connection->exec($query);
326
-
327
- $query = "CREATE TABLE IF NOT EXISTS $tFeature (
328
- `entity_id` int(11) default NULL,
329
- `feature_id` int(11) NOT NULL,
330
- `product_id` int(11) default NULL,
331
- `category_feature_id` int(11) default NULL,
332
- `value` text,
333
- `presentation_value` text,
334
- INDEX (`feature_id`),
335
- KEY `category_feature_id` (`category_feature_id`)
336
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8
337
- ";
338
- $connection->exec($query);
339
-
340
- $query = "TRUNCATE TABLE $tFeature";
341
- $connection->exec($query);
342
-
343
- /*$query = "
344
- INSERT INTO $tFeature (feature_id, product_id, category_feature_id, value, presentation_value)
345
- SELECT feature_id, product_id, category_feature_id, value, presentation_value FROM $tProudctsFeature
346
- WHERE category_feature_id = $featureId
347
- ";*/
348
- $query = "
349
- REPLACE INTO $tFeature (entity_id,feature_id, product_id, category_feature_id, value, presentation_value)
350
- SELECT E.entity_id, RV.category_feature_id,E.entity_id, RV.category_feature_id, RV.text , RV.text
351
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." E
352
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." PCind
353
- ON (E.entity_id = PCind.product_id AND PCind.store_id='{$storeId}' AND PCind.visibility IN(2,4))
354
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
355
- ON price_index.entity_id = E.entity_id AND price_index.website_id = '{$websiteId}' AND price_index.customer_group_id = 0
356
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." PR
357
- ON (PR.store_product_id = E.store_product_id)
358
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." PF
359
- ON (PR.sinch_product_id = PF.sinch_product_id )
360
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." RV
361
- ON (PF.restricted_value_id=RV.restricted_value_id AND RV.category_feature_id= $featureId)
362
- GROUP BY E.entity_id;
363
- ";
364
- $connection->exec($query);
365
- }
366
- Mage::log(__METHOD__ . " end at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
367
- }
368
-
369
- /**
370
- * Список фич подлежащих индексации.
371
- *
372
- * @return array
373
- */
374
- private function getProductFeatures4indexig()
375
- {
376
- $connection = $this->_getReadAdapter();
377
-
378
- $tCatFeature = Mage::getSingleton('core/resource')->getTableName('stINch_categories_features');
379
- $query = "SELECT category_feature_id FROM $tCatFeature ";
380
-
381
- return $connection->fetchCol($query);
382
- }
383
- }
1
+ <?php
2