stockinthechannel2012 - Version 2.0.6

Version Notes

Version 2.0.6:
* Update available servers to reflect new regions

Download this release

Release Info

Developer stockinchannel
Extension stockinthechannel2012
Version 2.0.6
Comparing to
See all releases


Code changes from version 2.0.5 to 2.0.6

Files changed (23) 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/Importhistory.php +386 -386
  4. app/code/local/Bintime/Sinchimport/Block/Layer/Filter/Feature.php +17 -17
  5. app/code/local/Bintime/Sinchimport/Block/Layer/View.php +48 -48
  6. app/code/local/Bintime/Sinchimport/Block/List.php +159 -159
  7. app/code/local/Bintime/Sinchimport/Block/Product/View/Media.php +19 -19
  8. app/code/local/Bintime/Sinchimport/Block/Startimportbutton.php +344 -344
  9. app/code/local/Bintime/Sinchimport/Block/Startstockpriceimportbutton.php +138 -138
  10. app/code/local/Bintime/Sinchimport/Helper/Data.php +6 -6
  11. app/code/local/Bintime/Sinchimport/Helper/Getdata.php +186 -186
  12. app/code/local/Bintime/Sinchimport/Helper/Image.php +73 -73
  13. app/code/local/Bintime/Sinchimport/Model/Api.php +86 -86
  14. app/code/local/Bintime/Sinchimport/Model/Category.php +20 -20
  15. app/code/local/Bintime/Sinchimport/Model/Image.php +118 -118
  16. app/code/local/Bintime/Sinchimport/Model/Layer.php +49 -49
  17. app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Feature.php +260 -260
  18. app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Price.php +194 -194
  19. app/code/local/Bintime/Sinchimport/Model/Product.php +74 -74
  20. app/code/local/Bintime/Sinchimport/Model/Resource/Layer/Filter/Price.php +80 -80
  21. app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php +384 -384
  22. app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Setup.php +4 -4
  23. app/code/local/Bintime/Sinchimport/Model/Sinch.php +9292 -9939
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/Importhistory.php CHANGED
@@ -1,386 +1,386 @@
1
- <?php
2
- class Bintime_Sinchimport_Block_Importhistory extends Mage_Adminhtml_Block_System_Config_Form_Field
3
- {
4
-
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $this->setElement($element);
8
- $url = $this->getUrl('sinchimport/index'); //
9
- $this->setElement($element);
10
-
11
- $html = $this->_appendJs();
12
-
13
- $html .= '<div id="sinchimport_status_template" name="sinchimport_status_template" style="display:none">';//none
14
- $html .= $this->_getStatusTemplateHtml();
15
- $html .= '</div>';
16
-
17
- $start_import_button = $this->getLayout()->createBlock('adminhtml/widget_button')
18
- ->setType('button')
19
- ->setClass('scalable')
20
- ->setLabel('Force Import now')
21
- ->setOnClick("start_sinch_import()") //setLocation('$url')
22
- ->toHtml();
23
-
24
- $html .= $start_import_button;
25
- // $html .= $url;
26
- $dataConf = Mage::getConfig();//('sinchimport_root');//getConfig()->getNode()->asXML();
27
- // $html .= "<pre>".var_export($dataConf, true)."</pre>";
28
-
29
-
30
-
31
- $import=Mage::getModel('sinchimport/sinch');
32
- if($import->is_imort_not_run()){
33
- $import->set_imports_failed();
34
- }
35
- $last_success_import=$import->getDateOfLatestSuccessImport();
36
- $import_history=$import->getImportStatusHistory();
37
-
38
- $css_arr=array(
39
- 'Failed' => 'sinch-error',
40
- 'Run' => 'sinch-run',
41
- 'Successful' => 'sinch-success'
42
- );
43
-
44
- $html=
45
- '
46
- <style type="text/css">
47
- .sinch-error {
48
- font-weight: bold;
49
- color: #D40707 ;
50
- text-align: center;
51
- margin: 5px 0;
52
- }
53
-
54
- .sinch-success {
55
- color: green;
56
- font-weight: bold;
57
- text-align: center;
58
- margin: 5px 0;
59
- }
60
-
61
- .sinch-run {
62
- color: blue;
63
- font-weight: bold;
64
- text-align: center;
65
- margin: 5px 0;
66
- }
67
-
68
-
69
- table.history {
70
- border-collapse: collapse;
71
- width: 100%;
72
- }
73
-
74
- table.history th {
75
- border: solid 1px #6F8992;
76
- background-color: #6F8992;
77
- color: #fff;
78
- font-weight: bold;
79
- padding: 2px 3px;
80
- }
81
-
82
- table.history td {
83
- border: 1px solid #333;
84
- padding: 2px 3px;
85
- }
86
- </style>
87
-
88
- <!--Table for import history-->
89
- <div class="comment">'.($last_success_import? "Your last successful feed import was at ".$last_success_import: "Your import never finished with success" ).'</div>
90
- <table class="history">
91
- <thead>
92
- <tr>
93
- <th>Import Start</th>
94
- <th>Import Finish</th>
95
- <th nowrap>Import Type</th>
96
- <th>Status</th>
97
-
98
- <th nowrap>Number of products</th>
99
- </tr>
100
- </thead>
101
- <tbody>';
102
- foreach($import_history as $item){
103
- $html.='
104
- <tr>
105
- <td nowrap>'.$item['start_import'].'</td>
106
- <td nowrap>'.$item['finish_import'].'</td>
107
- <td nowrap>'.$item['import_type'].'</td>
108
- <td class="'.$css_arr[$item['global_status_import']].'">'.$item['global_status_import'].'</td>
109
-
110
- <td>'.$item['number_of_products'].'</td>
111
- </tr>
112
- ';
113
- }
114
- $html.='
115
- </tbody>
116
- </table>
117
- ';
118
-
119
-
120
- return $html;
121
- }
122
-
123
- protected function _getStatusTemplateHtml()
124
- {
125
- $run_pic=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif";
126
- $html="
127
- <ul>
128
- <li>
129
- Start Import
130
- &nbsp
131
- <span id='sinchimport_start_import'>
132
- <img src='".$run_pic."'
133
- alt='Sinch Import run' />
134
- </span>
135
- </li>
136
- <li>
137
- Upload Files
138
- &nbsp
139
- <span id='sinchimport_upload_files'>
140
- <img src='".$run_pic."'
141
- alt='Upload Files' />
142
- </span>
143
- </li>
144
- <li>
145
- Parse Categories
146
- &nbsp
147
- <span id='sinchimport_parse_categories'>
148
- <img src='".$run_pic."'
149
- alt='Parse Categories' />
150
- </span>
151
- </li>
152
- <li>
153
- Parse Category Features
154
- &nbsp
155
- <span id='sinchimport_parse_category_features'>
156
- <img src='".$run_pic."'
157
- alt='Parse Category Features' />
158
- </span>
159
- </li>
160
- <li>
161
- Parse Distributors
162
- &nbsp
163
- <span id='sinchimport_parse_distributors'>
164
- <img src='".$run_pic."'
165
- alt='Parse Distributors' />
166
- </span>
167
- </li>
168
- <li>
169
- Parse EAN Codes
170
- &nbsp
171
- <span id='sinchimport_parse_ean_codes'>
172
- <img src='".$run_pic."'
173
- alt='Parse EAN Codes' />
174
- </span>
175
- </li>
176
- <li>
177
- Parse Manufacturers
178
- &nbsp
179
- <span id='sinchimport_parse_manufacturers'>
180
- <img src='".$run_pic."'
181
- alt='Parse Manufacturers'' />
182
- </span>
183
- </li>
184
- <li>
185
- Parse Related Products
186
- &nbsp
187
- <span id='sinchimport_parse_related_products'>
188
- <img src='".$run_pic."'
189
- alt='Parse Related Products' />
190
- </span>
191
- </li>
192
- <li>
193
- Parse Product Features
194
- &nbsp
195
- <span id='sinchimport_parse_product_features'>
196
- <img src='".$run_pic."'
197
- alt='Parse Product Features' />
198
- </span>
199
- </li>
200
- <li>
201
- Parse Products
202
- &nbsp
203
- <span id='sinchimport_parse_products'>
204
- <img src='".$run_pic."'
205
- alt='Parse Products' />
206
- </span>
207
- </li>
208
- <li>
209
- Parse Pictures Gallery
210
- &nbsp
211
- <span id='sinchimport_parse_pictures_gallery'>
212
- <img src='".$run_pic."'
213
- alt='Parse Pictures Gallery' />
214
- </span>
215
- </li>
216
- <li>
217
- Parse Restricted Values
218
- &nbsp
219
- <span id='sinchimport_parse_restricted_values'>
220
- <img src='".$run_pic."'
221
- alt='Parse Restricted Values' />
222
- </span>
223
- </li>
224
- <li>
225
- Parse Stock And Prices
226
- &nbsp
227
- <span id='sinchimport_parse_stock_and_prices'>
228
- <img src='".$run_pic."'
229
- alt='Parse Stock And Prices' />
230
- </span>
231
- </li>
232
- <li>
233
- Generate category filters
234
- &nbsp
235
- <span id='sinchimport_generate_category_filters'>
236
- <img src='".$run_pic."'
237
- alt='Generate category filters' />
238
- </span>
239
- </li>
240
- <li>
241
- Import finished
242
- &nbsp
243
- <span id='sinchimport_import_finished'>
244
- <img src='".$run_pic."'
245
- alt='Import finished' />
246
- </span>
247
- </li>
248
-
249
- </ul>
250
- ";
251
- return $html;
252
- }
253
-
254
- protected function _appendJs()
255
- {
256
- $post_url=$this->getUrl('sinchimport/ajax');
257
- $post_url_upd=$this->getUrl('sinchimport/ajax/UpdateStatus');
258
- $html = "
259
- <script>
260
- function start_sinch_import(){
261
- status_div=document.getElementById('sinchimport_status_template');
262
- status_div.style.display='';
263
- // status_div.innerHTML='';
264
- sinch = new Sinch('$post_url','$post_url_upd');
265
- sinch.startSinchImport();
266
-
267
- //
268
- }
269
- var Sinch = Class.create();
270
- Sinch.prototype = {
271
-
272
- initialize: function(postUrl, postUrlUpd) {
273
- this.postUrl = postUrl; //'https://techatcost.com/purchases/ajax/';
274
- this.postUrlUpd = postUrlUpd;
275
- this.failureUrl = document.URL;
276
- // unique user session ID
277
- this.SID = null;
278
- // object with event message data
279
- this.objectMsg = null;
280
- this.prevMsg = '';
281
- // interval object
282
- this.updateTimer = null;
283
- // default shipping code. Display on errors
284
-
285
- elem = 'checkoutSteps';
286
- clickableEntity = '.head';
287
-
288
- // overwrite Accordion class method
289
- var headers = $$('#' + elem + ' .section ' + clickableEntity);
290
- headers.each(function(header) {
291
- Event.observe(header,'click',this.sectionClicked.bindAsEventListener(this));
292
- }.bind(this));
293
- },
294
- startSinchImport: function () {
295
- _this = this;
296
- new Ajax.Request(this.postUrl,
297
- {
298
- method:'post',
299
- parameters: '',
300
- requestTimeout: 10,
301
- /*
302
- onLoading:function(){
303
- alert('onLoading');
304
- },
305
- onLoaded:function(){
306
- alert('onLoaded');
307
- },
308
- */
309
- onSuccess: function(transport) {
310
- var response = transport.responseText || null;
311
- _this.SID = response;
312
- if (_this.SID) {
313
- _this.updateTimer = setInterval(function(){_this.updateEvent();},20000);
314
- $('session_id').value = _this.SID;
315
- } else {
316
- alert('Can not get your session ID. Please reload the page!');
317
- }
318
- },
319
- onTimeout: function() { alert('Can not get your session ID. Timeout!'); },
320
- onFailure: function() { alert('Something went wrong...') }
321
- });
322
-
323
- },
324
-
325
- updateEvent: function () {
326
- _this = this;
327
- new Ajax.Request(this.postUrlUpd,
328
- {
329
- method: 'post',
330
- parameters: {session_id: this.SID},
331
- onSuccess: function(transport) {
332
- _this.objectMsg = transport.responseText.evalJSON();
333
- _this.prevMsg = _this.objectMsg.message;
334
- if(_this.prevMsg!=''){
335
- _this.updateStatusHtml();
336
- }
337
-
338
- if (_this.objectMsg.error == 1) {
339
- // Do something on error
340
- _this.clearUpdateInterval();
341
- }
342
-
343
- if (_this.objectMsg.finished == 1) {
344
- _this.objectMsg.message='Import finished';
345
- _this.updateStatusHtml();
346
- _this.clearUpdateInterval();
347
-
348
- }
349
-
350
- },
351
- onFailure: this.ajaxFailure.bind(),
352
- });
353
- },
354
-
355
- updateStatusHtml: function(){
356
- message=this.objectMsg.message.toLowerCase();
357
- mess_id='sinchimport_'+message.replace(/\s+/g, '_');
358
- if(!document.getElementById(mess_id)){
359
- alert(mess_id+' - not exist');
360
- }
361
- else{
362
- // alert (mess_id+' - exist');
363
- $(mess_id).innerHTML='<img src=\"".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_yes.gif"."\"/>'
364
- }
365
- htm=$('sinchimport_status_template').innerHTML;
366
- // $('sinchimport_status_template').innerHTML=htm+'<br>'+this.objectMsg.message;
367
- },
368
-
369
- ajaxFailure: function(){
370
- this.clearUpdateInterval();
371
- location.href = this.failureUrl;
372
- },
373
-
374
- clearUpdateInterval: function () {
375
- clearInterval(this.updateTimer);
376
- },
377
-
378
-
379
- }
380
- </script>
381
- ";
382
- return $html;
383
- }
384
-
385
- }
386
- ?>
1
+ <?php
2
+ class Bintime_Sinchimport_Block_Importhistory extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $this->setElement($element);
8
+ $url = $this->getUrl('sinchimport/index'); //
9
+ $this->setElement($element);
10
+
11
+ $html = $this->_appendJs();
12
+
13
+ $html .= '<div id="sinchimport_status_template" name="sinchimport_status_template" style="display:none">';//none
14
+ $html .= $this->_getStatusTemplateHtml();
15
+ $html .= '</div>';
16
+
17
+ $start_import_button = $this->getLayout()->createBlock('adminhtml/widget_button')
18
+ ->setType('button')
19
+ ->setClass('scalable')
20
+ ->setLabel('Force Import now')
21
+ ->setOnClick("start_sinch_import()") //setLocation('$url')
22
+ ->toHtml();
23
+
24
+ $html .= $start_import_button;
25
+ // $html .= $url;
26
+ $dataConf = Mage::getConfig();//('sinchimport_root');//getConfig()->getNode()->asXML();
27
+ // $html .= "<pre>".var_export($dataConf, true)."</pre>";
28
+
29
+
30
+
31
+ $import=Mage::getModel('sinchimport/sinch');
32
+ if($import->is_imort_not_run()){
33
+ $import->set_imports_failed();
34
+ }
35
+ $last_success_import=$import->getDateOfLatestSuccessImport();
36
+ $import_history=$import->getImportStatusHistory();
37
+
38
+ $css_arr=array(
39
+ 'Failed' => 'sinch-error',
40
+ 'Run' => 'sinch-run',
41
+ 'Successful' => 'sinch-success'
42
+ );
43
+
44
+ $html=
45
+ '
46
+ <style type="text/css">
47
+ .sinch-error {
48
+ font-weight: bold;
49
+ color: #D40707 ;
50
+ text-align: center;
51
+ margin: 5px 0;
52
+ }
53
+
54
+ .sinch-success {
55
+ color: green;
56
+ font-weight: bold;
57
+ text-align: center;
58
+ margin: 5px 0;
59
+ }
60
+
61
+ .sinch-run {
62
+ color: blue;
63
+ font-weight: bold;
64
+ text-align: center;
65
+ margin: 5px 0;
66
+ }
67
+
68
+
69
+ table.history {
70
+ border-collapse: collapse;
71
+ width: 100%;
72
+ }
73
+
74
+ table.history th {
75
+ border: solid 1px #6F8992;
76
+ background-color: #6F8992;
77
+ color: #fff;
78
+ font-weight: bold;
79
+ padding: 2px 3px;
80
+ }
81
+
82
+ table.history td {
83
+ border: 1px solid #333;
84
+ padding: 2px 3px;
85
+ }
86
+ </style>
87
+
88
+ <!--Table for import history-->
89
+ <div class="comment">'.($last_success_import? "Your last successful feed import was at ".$last_success_import: "Your import never finished with success" ).'</div>
90
+ <table class="history">
91
+ <thead>
92
+ <tr>
93
+ <th>Import Start</th>
94
+ <th>Import Finish</th>
95
+ <th nowrap>Import Type</th>
96
+ <th>Status</th>
97
+
98
+ <th nowrap>Number of products</th>
99
+ </tr>
100
+ </thead>
101
+ <tbody>';
102
+ foreach($import_history as $item){
103
+ $html.='
104
+ <tr>
105
+ <td nowrap>'.$item['start_import'].'</td>
106
+ <td nowrap>'.$item['finish_import'].'</td>
107
+ <td nowrap>'.$item['import_type'].'</td>
108
+ <td class="'.$css_arr[$item['global_status_import']].'">'.$item['global_status_import'].'</td>
109
+
110
+ <td>'.$item['number_of_products'].'</td>
111
+ </tr>
112
+ ';
113
+ }
114
+ $html.='
115
+ </tbody>
116
+ </table>
117
+ ';
118
+
119
+
120
+ return $html;
121
+ }
122
+
123
+ protected function _getStatusTemplateHtml()
124
+ {
125
+ $run_pic=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif";
126
+ $html="
127
+ <ul>
128
+ <li>
129
+ Start Import
130
+ &nbsp
131
+ <span id='sinchimport_start_import'>
132
+ <img src='".$run_pic."'
133
+ alt='Sinch Import run' />
134
+ </span>
135
+ </li>
136
+ <li>
137
+ Upload Files
138
+ &nbsp
139
+ <span id='sinchimport_upload_files'>
140
+ <img src='".$run_pic."'
141
+ alt='Upload Files' />
142
+ </span>
143
+ </li>
144
+ <li>
145
+ Parse Categories
146
+ &nbsp
147
+ <span id='sinchimport_parse_categories'>
148
+ <img src='".$run_pic."'
149
+ alt='Parse Categories' />
150
+ </span>
151
+ </li>
152
+ <li>
153
+ Parse Category Features
154
+ &nbsp
155
+ <span id='sinchimport_parse_category_features'>
156
+ <img src='".$run_pic."'
157
+ alt='Parse Category Features' />
158
+ </span>
159
+ </li>
160
+ <li>
161
+ Parse Distributors
162
+ &nbsp
163
+ <span id='sinchimport_parse_distributors'>
164
+ <img src='".$run_pic."'
165
+ alt='Parse Distributors' />
166
+ </span>
167
+ </li>
168
+ <li>
169
+ Parse EAN Codes
170
+ &nbsp
171
+ <span id='sinchimport_parse_ean_codes'>
172
+ <img src='".$run_pic."'
173
+ alt='Parse EAN Codes' />
174
+ </span>
175
+ </li>
176
+ <li>
177
+ Parse Manufacturers
178
+ &nbsp
179
+ <span id='sinchimport_parse_manufacturers'>
180
+ <img src='".$run_pic."'
181
+ alt='Parse Manufacturers'' />
182
+ </span>
183
+ </li>
184
+ <li>
185
+ Parse Related Products
186
+ &nbsp
187
+ <span id='sinchimport_parse_related_products'>
188
+ <img src='".$run_pic."'
189
+ alt='Parse Related Products' />
190
+ </span>
191
+ </li>
192
+ <li>
193
+ Parse Product Features
194
+ &nbsp
195
+ <span id='sinchimport_parse_product_features'>
196
+ <img src='".$run_pic."'
197
+ alt='Parse Product Features' />
198
+ </span>
199
+ </li>
200
+ <li>
201
+ Parse Products
202
+ &nbsp
203
+ <span id='sinchimport_parse_products'>
204
+ <img src='".$run_pic."'
205
+ alt='Parse Products' />
206
+ </span>
207
+ </li>
208
+ <li>
209
+ Parse Pictures Gallery
210
+ &nbsp
211
+ <span id='sinchimport_parse_pictures_gallery'>
212
+ <img src='".$run_pic."'
213
+ alt='Parse Pictures Gallery' />
214
+ </span>
215
+ </li>
216
+ <li>
217
+ Parse Restricted Values
218
+ &nbsp
219
+ <span id='sinchimport_parse_restricted_values'>
220
+ <img src='".$run_pic."'
221
+ alt='Parse Restricted Values' />
222
+ </span>
223
+ </li>
224
+ <li>
225
+ Parse Stock And Prices
226
+ &nbsp
227
+ <span id='sinchimport_parse_stock_and_prices'>
228
+ <img src='".$run_pic."'
229
+ alt='Parse Stock And Prices' />
230
+ </span>
231
+ </li>
232
+ <li>
233
+ Generate category filters
234
+ &nbsp
235
+ <span id='sinchimport_generate_category_filters'>
236
+ <img src='".$run_pic."'
237
+ alt='Generate category filters' />
238
+ </span>
239
+ </li>
240
+ <li>
241
+ Import finished
242
+ &nbsp
243
+ <span id='sinchimport_import_finished'>
244
+ <img src='".$run_pic."'
245
+ alt='Import finished' />
246
+ </span>
247
+ </li>
248
+
249
+ </ul>
250
+ ";
251
+ return $html;
252
+ }
253
+
254
+ protected function _appendJs()
255
+ {
256
+ $post_url=$this->getUrl('sinchimport/ajax');
257
+ $post_url_upd=$this->getUrl('sinchimport/ajax/UpdateStatus');
258
+ $html = "
259
+ <script>
260
+ function start_sinch_import(){
261
+ status_div=document.getElementById('sinchimport_status_template');
262
+ status_div.style.display='';
263
+ // status_div.innerHTML='';
264
+ sinch = new Sinch('$post_url','$post_url_upd');
265
+ sinch.startSinchImport();
266
+
267
+ //
268
+ }
269
+ var Sinch = Class.create();
270
+ Sinch.prototype = {
271
+
272
+ initialize: function(postUrl, postUrlUpd) {
273
+ this.postUrl = postUrl; //'https://techatcost.com/purchases/ajax/';
274
+ this.postUrlUpd = postUrlUpd;
275
+ this.failureUrl = document.URL;
276
+ // unique user session ID
277
+ this.SID = null;
278
+ // object with event message data
279
+ this.objectMsg = null;
280
+ this.prevMsg = '';
281
+ // interval object
282
+ this.updateTimer = null;
283
+ // default shipping code. Display on errors
284
+
285
+ elem = 'checkoutSteps';
286
+ clickableEntity = '.head';
287
+
288
+ // overwrite Accordion class method
289
+ var headers = $$('#' + elem + ' .section ' + clickableEntity);
290
+ headers.each(function(header) {
291
+ Event.observe(header,'click',this.sectionClicked.bindAsEventListener(this));
292
+ }.bind(this));
293
+ },
294
+ startSinchImport: function () {
295
+ _this = this;
296
+ new Ajax.Request(this.postUrl,
297
+ {
298
+ method:'post',
299
+ parameters: '',
300
+ requestTimeout: 10,
301
+ /*
302
+ onLoading:function(){
303
+ alert('onLoading');
304
+ },
305
+ onLoaded:function(){
306
+ alert('onLoaded');
307
+ },
308
+ */
309
+ onSuccess: function(transport) {
310
+ var response = transport.responseText || null;
311
+ _this.SID = response;
312
+ if (_this.SID) {
313
+ _this.updateTimer = setInterval(function(){_this.updateEvent();},20000);
314
+ $('session_id').value = _this.SID;
315
+ } else {
316
+ alert('Can not get your session ID. Please reload the page!');
317
+ }
318
+ },
319
+ onTimeout: function() { alert('Can not get your session ID. Timeout!'); },
320
+ onFailure: function() { alert('Something went wrong...') }
321
+ });
322
+
323
+ },
324
+
325
+ updateEvent: function () {
326
+ _this = this;
327
+ new Ajax.Request(this.postUrlUpd,
328
+ {
329
+ method: 'post',
330
+ parameters: {session_id: this.SID},
331
+ onSuccess: function(transport) {
332
+ _this.objectMsg = transport.responseText.evalJSON();
333
+ _this.prevMsg = _this.objectMsg.message;
334
+ if(_this.prevMsg!=''){
335
+ _this.updateStatusHtml();
336
+ }
337
+
338
+ if (_this.objectMsg.error == 1) {
339
+ // Do something on error
340
+ _this.clearUpdateInterval();
341
+ }
342
+
343
+ if (_this.objectMsg.finished == 1) {
344
+ _this.objectMsg.message='Import finished';
345
+ _this.updateStatusHtml();
346
+ _this.clearUpdateInterval();
347
+
348
+ }
349
+
350
+ },
351
+ onFailure: this.ajaxFailure.bind(),
352
+ });
353
+ },
354
+
355
+ updateStatusHtml: function(){
356
+ message=this.objectMsg.message.toLowerCase();
357
+ mess_id='sinchimport_'+message.replace(/\s+/g, '_');
358
+ if(!document.getElementById(mess_id)){
359
+ alert(mess_id+' - not exist');
360
+ }
361
+ else{
362
+ // alert (mess_id+' - exist');
363
+ $(mess_id).innerHTML='<img src=\"".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_yes.gif"."\"/>'
364
+ }
365
+ htm=$('sinchimport_status_template').innerHTML;
366
+ // $('sinchimport_status_template').innerHTML=htm+'<br>'+this.objectMsg.message;
367
+ },
368
+
369
+ ajaxFailure: function(){
370
+ this.clearUpdateInterval();
371
+ location.href = this.failureUrl;
372
+ },
373
+
374
+ clearUpdateInterval: function () {
375
+ clearInterval(this.updateTimer);
376
+ },
377
+
378
+
379
+ }
380
+ </script>
381
+ ";
382
+ return $html;
383
+ }
384
+
385
+ }
386
+ ?>
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/Block/Product/View/Media.php CHANGED
@@ -1,19 +1,19 @@
1
- <?php
2
- class Bintime_Sinchimport_Block_Product_View_Media extends Mage_Catalog_Block_Product_View_Media
3
- {
4
- public function getGalleryUrl($image=null)
5
- {
6
- if (substr($image['url'],0,4) != 'http') {
7
- $params = array('id'=>$this->getProduct()->getId());
8
- if ($image) {
9
- $params['image'] = $image->getValueId();
10
- return $this->getUrl('*/*/gallery', $params);
11
- }
12
- return $this->getUrl('*/*/gallery', $params);
13
- }else{
14
- return $image['url'];
15
- }
16
- }
17
-
18
- }
19
- ?>
1
+ <?php
2
+ class Bintime_Sinchimport_Block_Product_View_Media extends Mage_Catalog_Block_Product_View_Media
3
+ {
4
+ public function getGalleryUrl($image=null)
5
+ {
6
+ if (substr($image['url'],0,4) != 'http') {
7
+ $params = array('id'=>$this->getProduct()->getId());
8
+ if ($image) {
9
+ $params['image'] = $image->getValueId();
10
+ return $this->getUrl('*/*/gallery', $params);
11
+ }
12
+ return $this->getUrl('*/*/gallery', $params);
13
+ }else{
14
+ return $image['url'];
15
+ }
16
+ }
17
+
18
+ }
19
+ ?>
app/code/local/Bintime/Sinchimport/Block/Startimportbutton.php CHANGED
@@ -1,344 +1,344 @@
1
- <?php
2
- class Bintime_Sinchimport_Block_Startimportbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
3
- {
4
-
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $this->setElement($element);
8
- $url = $this->getUrl('sinchimport/index'); //
9
- $this->setElement($element);
10
-
11
- $html = $this->_appendJs();
12
-
13
- $html .= '<div id="sinchimport_status_template" name="sinchimport_status_template" style="display:none">';//none
14
- $html .= $this->_getStatusTemplateHtml();
15
- $html .= '</div>';
16
-
17
- $start_import_button = $this->getLayout()->createBlock('adminhtml/widget_button')
18
- ->setType('button')
19
- ->setClass('scalable')
20
- ->setLabel('Force Import now')
21
- ->setOnClick("start_sinch_import()") //setLocation('$url')
22
- ->toHtml();
23
- $safe_mode_set = ini_get('safe_mode');
24
- if($safe_mode_set){
25
- $html .="<p class='sinch-error'><b>You can't start import (safe_mode is 'On'. set safe_mode = Off in php.ini )<b></p>";
26
- }else{
27
- $html .= $start_import_button;
28
- }
29
- // $html .= $url;
30
- $dataConf = Mage::getConfig();//('sinchimport_root');//getConfig()->getNode()->asXML();
31
- // $html .= "<pre>".var_export($dataConf, true)."</pre>";
32
- $import=Mage::getModel('sinchimport/sinch');
33
- $last_import=$import->getDataOfLatestImport();
34
- $last_imp_status=$last_import['global_status_import'];
35
- if($last_imp_status=='Failed'){
36
- $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p class="sinch-error">The import has failed. Please ensure that you are using the correct settings. Last step was "'.$last_import['detail_status_import'].'"<br> Error reporting : "'.$last_import['error_report_message'].'"</p></div>';
37
- }elseif($last_imp_status=='Successful'){
38
- $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p class="sinch-success">'.$last_import['number_of_products'].' products imported succesfully!</p></div>';
39
- }elseif($last_imp_status=='Run'){
40
- $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p>Import is running now</p></div>';
41
- }else{
42
- $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"></div>';
43
- }
44
-
45
- return $html;
46
- }
47
-
48
- protected function _getStatusTemplateHtml()
49
- {
50
- $run_pic=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif";
51
- $html="
52
- <ul>
53
- <li>
54
- Start Import
55
- &nbsp
56
- <span id='sinchimport_start_import'>
57
- <img src='".$run_pic."'
58
- alt='Sinch Import run' />
59
- </span>
60
- </li>
61
- <li>
62
- Download files
63
- &nbsp
64
- <span id='sinchimport_upload_files'>
65
- <img src='".$run_pic."'
66
- alt='Download files' />
67
- </span>
68
- </li>
69
- <li>
70
- Parse Categories
71
- &nbsp
72
- <span id='sinchimport_parse_categories'>
73
- <img src='".$run_pic."'
74
- alt='Parse Categories' />
75
- </span>
76
- </li>
77
- <li>
78
- Parse Category Features
79
- &nbsp
80
- <span id='sinchimport_parse_category_features'>
81
- <img src='".$run_pic."'
82
- alt='Parse Category Features' />
83
- </span>
84
- </li>
85
- <li>
86
- Parse Distributors
87
- &nbsp
88
- <span id='sinchimport_parse_distributors'>
89
- <img src='".$run_pic."'
90
- alt='Parse Distributors' />
91
- </span>
92
- </li>
93
- <li>
94
- Parse EAN Codes
95
- &nbsp
96
- <span id='sinchimport_parse_ean_codes'>
97
- <img src='".$run_pic."'
98
- alt='Parse EAN Codes' />
99
- </span>
100
- </li>
101
- <li>
102
- Parse Manufacturers
103
- &nbsp
104
- <span id='sinchimport_parse_manufacturers'>
105
- <img src='".$run_pic."'
106
- alt='Parse Manufacturers'' />
107
- </span>
108
- </li>
109
- <li>
110
- Parse Related Products
111
- &nbsp
112
- <span id='sinchimport_parse_related_products'>
113
- <img src='".$run_pic."'
114
- alt='Parse Related Products' />
115
- </span>
116
- </li>
117
- <li>
118
- Parse Product Features
119
- &nbsp
120
- <span id='sinchimport_parse_product_features'>
121
- <img src='".$run_pic."'
122
- alt='Parse Product Features' />
123
- </span>
124
- </li>
125
- <li>
126
- Parse Products
127
- &nbsp
128
- <span id='sinchimport_parse_products'>
129
- <img src='".$run_pic."'
130
- alt='Parse Products' />
131
- </span>
132
- </li>
133
- <li>
134
- Parse Pictures Gallery
135
- &nbsp
136
- <span id='sinchimport_parse_pictures_gallery'>
137
- <img src='".$run_pic."'
138
- alt='Parse Pictures Gallery' />
139
- </span>
140
- </li>
141
- <li>
142
- Parse Restricted Values
143
- &nbsp
144
- <span id='sinchimport_parse_restricted_values'>
145
- <img src='".$run_pic."'
146
- alt='Parse Restricted Values' />
147
- </span>
148
- </li>
149
- <li>
150
- Parse Stock And Prices
151
- &nbsp
152
- <span id='sinchimport_parse_stock_and_prices'>
153
- <img src='".$run_pic."'
154
- alt='Parse Stock And Prices' />
155
- </span>
156
- </li>
157
- <li>
158
- Generate category filters
159
- &nbsp
160
- <span id='sinchimport_generate_category_filters'>
161
- <img src='".$run_pic."'
162
- alt='Generate category filters' />
163
- </span>
164
- </li>
165
- <li>
166
- Indexing data
167
- &nbsp
168
- <span id='sinchimport_indexing_data'>
169
- <img src='".$run_pic."'
170
- alt='Indexing data' />
171
- </span>
172
- </li>
173
- <li>
174
- Import finished
175
- &nbsp
176
- <span id='sinchimport_import_finished'>
177
- <img src='".$run_pic."'
178
- alt='Import finished' />
179
- </span>
180
- </li>
181
-
182
- </ul>
183
- ";
184
- return $html;
185
- }
186
-
187
- protected function _appendJs()
188
- {
189
- $post_url=$this->getUrl('sinchimport/ajax');
190
- $post_url_upd=$this->getUrl('sinchimport/ajax/UpdateStatus');
191
- $html = "
192
- <script>
193
- function start_sinch_import(){
194
- set_run_icon();
195
- status_div=document.getElementById('sinchimport_status_template');
196
- curr_status_div=document.getElementById('sinchimport_current_status_message');
197
- curr_status_div.style.display='none';
198
- status_div.style.display='';
199
- // status_div.innerHTML='';
200
- sinch = new Sinch('$post_url','$post_url_upd');
201
- sinch.startSinchImport();
202
-
203
- //
204
- }
205
- function set_run_icon(){
206
- run_pic='<img src=\"".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif\""."/>';
207
- document.getElementById('sinchimport_start_import').innerHTML=run_pic;
208
- document.getElementById('sinchimport_upload_files').innerHTML=run_pic;
209
- document.getElementById('sinchimport_parse_categories').innerHTML=run_pic;
210
- document.getElementById('sinchimport_parse_category_features').innerHTML=run_pic;
211
- document.getElementById('sinchimport_parse_distributors').innerHTML=run_pic;
212
- document.getElementById('sinchimport_parse_ean_codes').innerHTML=run_pic;
213
- document.getElementById('sinchimport_parse_manufacturers').innerHTML=run_pic;
214
- document.getElementById('sinchimport_parse_related_products').innerHTML=run_pic;
215
- document.getElementById('sinchimport_parse_product_features').innerHTML=run_pic;
216
- document.getElementById('sinchimport_parse_products').innerHTML=run_pic;
217
- document.getElementById('sinchimport_parse_pictures_gallery').innerHTML=run_pic;
218
- document.getElementById('sinchimport_parse_restricted_values').innerHTML=run_pic;
219
- document.getElementById('sinchimport_parse_stock_and_prices').innerHTML=run_pic;
220
- document.getElementById('sinchimport_generate_category_filters').innerHTML=run_pic;
221
- document.getElementById('sinchimport_indexing_data').innerHTML=run_pic;
222
- document.getElementById('sinchimport_import_finished').innerHTML=run_pic;
223
-
224
-
225
-
226
- }
227
- var Sinch = Class.create();
228
- Sinch.prototype = {
229
-
230
- initialize: function(postUrl, postUrlUpd) {
231
- this.postUrl = postUrl; //'https://techatcost.com/purchases/ajax/';
232
- this.postUrlUpd = postUrlUpd;
233
- this.failureUrl = document.URL;
234
- // unique user session ID
235
- this.SID = null;
236
- // object with event message data
237
- this.objectMsg = null;
238
- this.prevMsg = '';
239
- // interval object
240
- this.updateTimer = null;
241
- // default shipping code. Display on errors
242
-
243
- elem = 'checkoutSteps';
244
- clickableEntity = '.head';
245
-
246
- // overwrite Accordion class method
247
- var headers = $$('#' + elem + ' .section ' + clickableEntity);
248
- headers.each(function(header) {
249
- Event.observe(header,'click',this.sectionClicked.bindAsEventListener(this));
250
- }.bind(this));
251
- },
252
- startSinchImport: function () {
253
- _this = this;
254
- new Ajax.Request(this.postUrl,
255
- {
256
- method:'post',
257
- parameters: '',
258
- requestTimeout: 10,
259
- /*
260
- onLoading:function(){
261
- alert('onLoading');
262
- },
263
- onLoaded:function(){
264
- alert('onLoaded');
265
- },
266
- */
267
- onSuccess: function(transport) {
268
- var response = transport.responseText || null;
269
- _this.SID = response;
270
- if (_this.SID) {
271
- _this.updateTimer = setInterval(function(){_this.updateEvent();},20000);
272
- $('session_id').value = _this.SID;
273
- } else {
274
- alert('Can not get your session ID. Please reload the page!');
275
- }
276
- },
277
- onTimeout: function() { alert('Can not get your session ID. Timeout!'); },
278
- onFailure: function() { alert('Something went wrong...') }
279
- });
280
-
281
- },
282
-
283
- updateEvent: function () {
284
- _this = this;
285
- new Ajax.Request(this.postUrlUpd,
286
- {
287
- method: 'post',
288
- parameters: {session_id: this.SID},
289
- onSuccess: function(transport) {
290
- _this.objectMsg = transport.responseText.evalJSON();
291
- _this.prevMsg = _this.objectMsg.message;
292
- if(_this.prevMsg!=''){
293
- _this.updateStatusHtml();
294
- }
295
-
296
- if (_this.objectMsg.error == 1) {
297
- // Do something on error
298
- _this.clearUpdateInterval();
299
- }
300
-
301
- if (_this.objectMsg.finished == 1) {
302
- _this.objectMsg.message='Import finished';
303
- _this.updateStatusHtml();
304
- _this.clearUpdateInterval();
305
-
306
- }
307
-
308
- },
309
- onFailure: this.ajaxFailure.bind(),
310
- });
311
- },
312
-
313
- updateStatusHtml: function(){
314
- message=this.objectMsg.message.toLowerCase();
315
- mess_id='sinchimport_'+message.replace(/\s+/g, '_');
316
- if(!document.getElementById(mess_id)){
317
- // alert(mess_id+' - not exist');
318
- }
319
- else{
320
- // alert (mess_id+' - exist');
321
- $(mess_id).innerHTML='<img src=\"".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_yes.gif"."\"/>'
322
- }
323
- htm=$('sinchimport_status_template').innerHTML;
324
- // $('sinchimport_status_template').innerHTML=htm+'<br>'+this.objectMsg.message;
325
- },
326
-
327
- ajaxFailure: function(){
328
- this.clearUpdateInterval();
329
- location.href = this.failureUrl;
330
- },
331
-
332
- clearUpdateInterval: function () {
333
- clearInterval(this.updateTimer);
334
- },
335
-
336
-
337
- }
338
- </script>
339
- ";
340
- return $html;
341
- }
342
-
343
- }
344
- ?>
1
+ <?php
2
+ class Bintime_Sinchimport_Block_Startimportbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $this->setElement($element);
8
+ $url = $this->getUrl('sinchimport/index'); //
9
+ $this->setElement($element);
10
+
11
+ $html = $this->_appendJs();
12
+
13
+ $html .= '<div id="sinchimport_status_template" name="sinchimport_status_template" style="display:none">';//none
14
+ $html .= $this->_getStatusTemplateHtml();
15
+ $html .= '</div>';
16
+
17
+ $start_import_button = $this->getLayout()->createBlock('adminhtml/widget_button')
18
+ ->setType('button')
19
+ ->setClass('scalable')
20
+ ->setLabel('Force Import now')
21
+ ->setOnClick("start_sinch_import()") //setLocation('$url')
22
+ ->toHtml();
23
+ $safe_mode_set = ini_get('safe_mode');
24
+ if($safe_mode_set){
25
+ $html .="<p class='sinch-error'><b>You can't start import (safe_mode is 'On'. set safe_mode = Off in php.ini )<b></p>";
26
+ }else{
27
+ $html .= $start_import_button;
28
+ }
29
+ // $html .= $url;
30
+ $dataConf = Mage::getConfig();//('sinchimport_root');//getConfig()->getNode()->asXML();
31
+ // $html .= "<pre>".var_export($dataConf, true)."</pre>";
32
+ $import=Mage::getModel('sinchimport/sinch');
33
+ $last_import=$import->getDataOfLatestImport();
34
+ $last_imp_status=$last_import['global_status_import'];
35
+ if($last_imp_status=='Failed'){
36
+ $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p class="sinch-error">The import has failed. Please ensure that you are using the correct settings. Last step was "'.$last_import['detail_status_import'].'"<br> Error reporting : "'.$last_import['error_report_message'].'"</p></div>';
37
+ }elseif($last_imp_status=='Successful'){
38
+ $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p class="sinch-success">'.$last_import['number_of_products'].' products imported succesfully!</p></div>';
39
+ }elseif($last_imp_status=='Run'){
40
+ $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p>Import is running now</p></div>';
41
+ }else{
42
+ $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"></div>';
43
+ }
44
+
45
+ return $html;
46
+ }
47
+
48
+ protected function _getStatusTemplateHtml()
49
+ {
50
+ $run_pic=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif";
51
+ $html="
52
+ <ul>
53
+ <li>
54
+ Start Import
55
+ &nbsp
56
+ <span id='sinchimport_start_import'>
57
+ <img src='".$run_pic."'
58
+ alt='Sinch Import run' />
59
+ </span>
60
+ </li>
61
+ <li>
62
+ Download files
63
+ &nbsp
64
+ <span id='sinchimport_upload_files'>
65
+ <img src='".$run_pic."'
66
+ alt='Download files' />
67
+ </span>
68
+ </li>
69
+ <li>
70
+ Parse Categories
71
+ &nbsp
72
+ <span id='sinchimport_parse_categories'>
73
+ <img src='".$run_pic."'
74
+ alt='Parse Categories' />
75
+ </span>
76
+ </li>
77
+ <li>
78
+ Parse Category Features
79
+ &nbsp
80
+ <span id='sinchimport_parse_category_features'>
81
+ <img src='".$run_pic."'
82
+ alt='Parse Category Features' />
83
+ </span>
84
+ </li>
85
+ <li>
86
+ Parse Distributors
87
+ &nbsp
88
+ <span id='sinchimport_parse_distributors'>
89
+ <img src='".$run_pic."'
90
+ alt='Parse Distributors' />
91
+ </span>
92
+ </li>
93
+ <li>
94
+ Parse EAN Codes
95
+ &nbsp
96
+ <span id='sinchimport_parse_ean_codes'>
97
+ <img src='".$run_pic."'
98
+ alt='Parse EAN Codes' />
99
+ </span>
100
+ </li>
101
+ <li>
102
+ Parse Manufacturers
103
+ &nbsp
104
+ <span id='sinchimport_parse_manufacturers'>
105
+ <img src='".$run_pic."'
106
+ alt='Parse Manufacturers'' />
107
+ </span>
108
+ </li>
109
+ <li>
110
+ Parse Related Products
111
+ &nbsp
112
+ <span id='sinchimport_parse_related_products'>
113
+ <img src='".$run_pic."'
114
+ alt='Parse Related Products' />
115
+ </span>
116
+ </li>
117
+ <li>
118
+ Parse Product Features
119
+ &nbsp
120
+ <span id='sinchimport_parse_product_features'>
121
+ <img src='".$run_pic."'
122
+ alt='Parse Product Features' />
123
+ </span>
124
+ </li>
125
+ <li>
126
+ Parse Products
127
+ &nbsp
128
+ <span id='sinchimport_parse_products'>
129
+ <img src='".$run_pic."'
130
+ alt='Parse Products' />
131
+ </span>
132
+ </li>
133
+ <li>
134
+ Parse Pictures Gallery
135
+ &nbsp
136
+ <span id='sinchimport_parse_pictures_gallery'>
137
+ <img src='".$run_pic."'
138
+ alt='Parse Pictures Gallery' />
139
+ </span>
140
+ </li>
141
+ <li>
142
+ Parse Restricted Values
143
+ &nbsp
144
+ <span id='sinchimport_parse_restricted_values'>
145
+ <img src='".$run_pic."'
146
+ alt='Parse Restricted Values' />
147
+ </span>
148
+ </li>
149
+ <li>
150
+ Parse Stock And Prices
151
+ &nbsp
152
+ <span id='sinchimport_parse_stock_and_prices'>
153
+ <img src='".$run_pic."'
154
+ alt='Parse Stock And Prices' />
155
+ </span>
156
+ </li>
157
+ <li>
158
+ Generate category filters
159
+ &nbsp
160
+ <span id='sinchimport_generate_category_filters'>
161
+ <img src='".$run_pic."'
162
+ alt='Generate category filters' />
163
+ </span>
164
+ </li>
165
+ <li>
166
+ Indexing data
167
+ &nbsp
168
+ <span id='sinchimport_indexing_data'>
169
+ <img src='".$run_pic."'
170
+ alt='Indexing data' />
171
+ </span>
172
+ </li>
173
+ <li>
174
+ Import finished
175
+ &nbsp
176
+ <span id='sinchimport_import_finished'>
177
+ <img src='".$run_pic."'
178
+ alt='Import finished' />
179
+ </span>
180
+ </li>
181
+
182
+ </ul>
183
+ ";
184
+ return $html;
185
+ }
186
+
187
+ protected function _appendJs()
188
+ {
189
+ $post_url=$this->getUrl('sinchimport/ajax');
190
+ $post_url_upd=$this->getUrl('sinchimport/ajax/UpdateStatus');
191
+ $html = "
192
+ <script>
193
+ function start_sinch_import(){
194
+ set_run_icon();
195
+ status_div=document.getElementById('sinchimport_status_template');
196
+ curr_status_div=document.getElementById('sinchimport_current_status_message');
197
+ curr_status_div.style.display='none';
198
+ status_div.style.display='';
199
+ // status_div.innerHTML='';
200
+ sinch = new Sinch('$post_url','$post_url_upd');
201
+ sinch.startSinchImport();
202
+
203
+ //
204
+ }
205
+ function set_run_icon(){
206
+ run_pic='<img src=\"".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif\""."/>';
207
+ document.getElementById('sinchimport_start_import').innerHTML=run_pic;
208
+ document.getElementById('sinchimport_upload_files').innerHTML=run_pic;
209
+ document.getElementById('sinchimport_parse_categories').innerHTML=run_pic;
210
+ document.getElementById('sinchimport_parse_category_features').innerHTML=run_pic;
211
+ document.getElementById('sinchimport_parse_distributors').innerHTML=run_pic;
212
+ document.getElementById('sinchimport_parse_ean_codes').innerHTML=run_pic;
213
+ document.getElementById('sinchimport_parse_manufacturers').innerHTML=run_pic;
214
+ document.getElementById('sinchimport_parse_related_products').innerHTML=run_pic;
215
+ document.getElementById('sinchimport_parse_product_features').innerHTML=run_pic;
216
+ document.getElementById('sinchimport_parse_products').innerHTML=run_pic;
217
+ document.getElementById('sinchimport_parse_pictures_gallery').innerHTML=run_pic;
218
+ document.getElementById('sinchimport_parse_restricted_values').innerHTML=run_pic;
219
+ document.getElementById('sinchimport_parse_stock_and_prices').innerHTML=run_pic;
220
+ document.getElementById('sinchimport_generate_category_filters').innerHTML=run_pic;
221
+ document.getElementById('sinchimport_indexing_data').innerHTML=run_pic;
222
+ document.getElementById('sinchimport_import_finished').innerHTML=run_pic;
223
+
224
+
225
+
226
+ }
227
+ var Sinch = Class.create();
228
+ Sinch.prototype = {
229
+
230
+ initialize: function(postUrl, postUrlUpd) {
231
+ this.postUrl = postUrl; //'https://techatcost.com/purchases/ajax/';
232
+ this.postUrlUpd = postUrlUpd;
233
+ this.failureUrl = document.URL;
234
+ // unique user session ID
235
+ this.SID = null;
236
+ // object with event message data
237
+ this.objectMsg = null;
238
+ this.prevMsg = '';
239
+ // interval object
240
+ this.updateTimer = null;
241
+ // default shipping code. Display on errors
242
+
243
+ elem = 'checkoutSteps';
244
+ clickableEntity = '.head';
245
+
246
+ // overwrite Accordion class method
247
+ var headers = $$('#' + elem + ' .section ' + clickableEntity);
248
+ headers.each(function(header) {
249
+ Event.observe(header,'click',this.sectionClicked.bindAsEventListener(this));
250
+ }.bind(this));
251
+ },
252
+ startSinchImport: function () {
253
+ _this = this;
254
+ new Ajax.Request(this.postUrl,
255
+ {
256
+ method:'post',
257
+ parameters: '',
258
+ requestTimeout: 10,
259
+ /*
260
+ onLoading:function(){
261
+ alert('onLoading');
262
+ },
263
+ onLoaded:function(){
264
+ alert('onLoaded');
265
+ },
266
+ */
267
+ onSuccess: function(transport) {
268
+ var response = transport.responseText || null;
269
+ _this.SID = response;
270
+ if (_this.SID) {
271
+ _this.updateTimer = setInterval(function(){_this.updateEvent();},20000);
272
+ $('session_id').value = _this.SID;
273
+ } else {
274
+ alert('Can not get your session ID. Please reload the page!');
275
+ }
276
+ },
277
+ onTimeout: function() { alert('Can not get your session ID. Timeout!'); },
278
+ onFailure: function() { alert('Something went wrong...') }
279
+ });
280
+
281
+ },
282
+
283
+ updateEvent: function () {
284
+ _this = this;
285
+ new Ajax.Request(this.postUrlUpd,
286
+ {
287
+ method: 'post',
288
+ parameters: {session_id: this.SID},
289
+ onSuccess: function(transport) {
290
+ _this.objectMsg = transport.responseText.evalJSON();
291
+ _this.prevMsg = _this.objectMsg.message;
292
+ if(_this.prevMsg!=''){
293
+ _this.updateStatusHtml();
294
+ }
295
+
296
+ if (_this.objectMsg.error == 1) {
297
+ // Do something on error
298
+ _this.clearUpdateInterval();
299
+ }
300
+
301
+ if (_this.objectMsg.finished == 1) {
302
+ _this.objectMsg.message='Import finished';
303
+ _this.updateStatusHtml();
304
+ _this.clearUpdateInterval();
305
+
306
+ }
307
+
308
+ },
309
+ onFailure: this.ajaxFailure.bind(),
310
+ });
311
+ },
312
+
313
+ updateStatusHtml: function(){
314
+ message=this.objectMsg.message.toLowerCase();
315
+ mess_id='sinchimport_'+message.replace(/\s+/g, '_');
316
+ if(!document.getElementById(mess_id)){
317
+ // alert(mess_id+' - not exist');
318
+ }
319
+ else{
320
+ // alert (mess_id+' - exist');
321
+ $(mess_id).innerHTML='<img src=\"".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_yes.gif"."\"/>'
322
+ }
323
+ htm=$('sinchimport_status_template').innerHTML;
324
+ // $('sinchimport_status_template').innerHTML=htm+'<br>'+this.objectMsg.message;
325
+ },
326
+
327
+ ajaxFailure: function(){
328
+ this.clearUpdateInterval();
329
+ location.href = this.failureUrl;
330
+ },
331
+
332
+ clearUpdateInterval: function () {
333
+ clearInterval(this.updateTimer);
334
+ },
335
+
336
+
337
+ }
338
+ </script>
339
+ ";
340
+ return $html;
341
+ }
342
+
343
+ }
344
+ ?>
app/code/local/Bintime/Sinchimport/Block/Startstockpriceimportbutton.php CHANGED
@@ -1,138 +1,138 @@
1
- <?php
2
- class Bintime_Sinchimport_Block_Startstockpriceimportbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
3
- {
4
-
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $this->setElement($element);
8
- $url = $this->getUrl('sinchimport/index'); //
9
- $this->setElement($element);
10
-
11
- $html = $this->_appendJs();
12
-
13
- $html .= '<div id="sinchimport_stock_price_status_template" name="sinchimport_stock_price_status_template" style="display:none">';//none
14
- $html .= $this->_getStatusTemplateHtml();
15
- $html .= '</div>';
16
-
17
- $start_import_button = $this->getLayout()->createBlock('adminhtml/widget_button')
18
- ->setType('button')
19
- ->setClass('scalable')
20
- ->setLabel('Force Stock & Prices Import now')
21
- ->setOnClick("start_stock_price_sinch_import()") //setLocation('$url')
22
- ->toHtml();
23
- // $html .= $url;
24
- $dataConf = Mage::getConfig();//('sinchimport_root');//getConfig()->getNode()->asXML();
25
- // $html .= "<pre>".var_export($dataConf, true)."</pre>";
26
- $import=Mage::getModel('sinchimport/sinch');
27
-
28
- $safe_mode_set = ini_get('safe_mode');
29
- if($safe_mode_set){
30
- $html .="<p class='sinch-error'><b>You can't start import (safe_mode is 'On'. set safe_mode = Off in php.ini )<b></p>";
31
- }elseif(!$import->is_full_import_have_been_run()){
32
- $html .="Full import have never finished with success";
33
- }else{
34
- $html .= $start_import_button;
35
- }
36
-
37
- $last_import=$import->getDataOfLatestImport();
38
- $last_imp_status=$last_import['global_status_import'];
39
- if($last_imp_status=='Failed'){
40
- $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p class="sinch-error">The import has failed. Please ensure that you are using the correct settings. Last step was "'.$last_import['detail_status_import'].'"<br> Error reporting : "'.$last_import['error_report_message'].'"</p></div>';
41
- }elseif($last_imp_status=='Successful'){
42
- $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p class="sinch-success">'.$last_import['number_of_products'].' products imported succesfully!</p></div>';
43
- }elseif($last_imp_status=='Run'){
44
- $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p>Import is running now</p></div>';
45
- }else{
46
- $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"></div>';
47
- }
48
-
49
- return $html;
50
- }
51
-
52
- protected function _getStatusTemplateHtml()
53
- {
54
- $run_pic=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif";
55
- $html="
56
- <ul>
57
- <li>
58
- Start Import
59
- &nbsp
60
- <span id='sinchimport_stock_price_start_import'>
61
- <img src='".$run_pic."'
62
- alt='Sinch Import run' />
63
- </span>
64
- </li>
65
- <li>
66
- Download files
67
- &nbsp
68
- <span id='sinchimport_stock_price_upload_files'>
69
- <img src='".$run_pic."'
70
- alt='Download files' />
71
- </span>
72
- </li>
73
- <li>
74
- Parse Stock And Prices
75
- &nbsp
76
- <span id='sinchimport_stock_price_parse_products'>
77
- <img src='".$run_pic."'
78
- alt='Parse Stock And Prices' />
79
- </span>
80
- </li>
81
- <li>
82
- Indexing data
83
- &nbsp
84
- <span id='sinchimport_stock_price_indexing_data'>
85
- <img src='".$run_pic."'
86
- alt='Indexing data' />
87
- </span>
88
- </li>
89
- <li>
90
- Import finished
91
- &nbsp
92
- <span id='sinchimport_stock_price_finish_import'>
93
- <img src='".$run_pic."'
94
- alt='Import finished' />
95
- </span>
96
- </li>
97
-
98
- </ul>
99
- ";
100
- return $html;
101
- }
102
-
103
- protected function _appendJs()
104
- {
105
- $post_url=$this->getUrl('sinchimport/ajax/stockPrice');
106
- $post_url_upd=$this->getUrl('sinchimport/ajax/UpdateStatus');
107
- $html = "
108
- <script>
109
- function start_stock_price_sinch_import(){
110
- set_stock_price_run_icon();
111
- st_pr_status_div=document.getElementById('sinchimport_stock_price_status_template');
112
- curr_status_div=document.getElementById('sinchimport_current_status_message');
113
- curr_status_div.style.display='none';
114
- st_pr_status_div.style.display='';
115
- // status_div.innerHTML='';
116
- sinch = new Sinch('$post_url','$post_url_upd');
117
- sinch.startSinchImport();
118
-
119
- //
120
- }
121
-
122
- function set_stock_price_run_icon(){
123
- run_pic='<img src=\"".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif\""."/>';
124
- document.getElementById('sinchimport_stock_price_start_import').innerHTML=run_pic;
125
- document.getElementById('sinchimport_stock_price_upload_files').innerHTML=run_pic;
126
- document.getElementById('sinchimport_stock_price_parse_products').innerHTML=run_pic;
127
- document.getElementById('sinchimport_stock_price_indexing_data').innerHTML=run_pic;
128
- document.getElementById('sinchimport_stock_price_finish_import').innerHTML=run_pic;
129
-
130
- }
131
-
132
- </script>
133
- ";
134
- return $html;
135
- }
136
-
137
- }
138
- ?>
1
+ <?php
2
+ class Bintime_Sinchimport_Block_Startstockpriceimportbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $this->setElement($element);
8
+ $url = $this->getUrl('sinchimport/index'); //
9
+ $this->setElement($element);
10
+
11
+ $html = $this->_appendJs();
12
+
13
+ $html .= '<div id="sinchimport_stock_price_status_template" name="sinchimport_stock_price_status_template" style="display:none">';//none
14
+ $html .= $this->_getStatusTemplateHtml();
15
+ $html .= '</div>';
16
+
17
+ $start_import_button = $this->getLayout()->createBlock('adminhtml/widget_button')
18
+ ->setType('button')
19
+ ->setClass('scalable')
20
+ ->setLabel('Force Stock & Prices Import now')
21
+ ->setOnClick("start_stock_price_sinch_import()") //setLocation('$url')
22
+ ->toHtml();
23
+ // $html .= $url;
24
+ $dataConf = Mage::getConfig();//('sinchimport_root');//getConfig()->getNode()->asXML();
25
+ // $html .= "<pre>".var_export($dataConf, true)."</pre>";
26
+ $import=Mage::getModel('sinchimport/sinch');
27
+
28
+ $safe_mode_set = ini_get('safe_mode');
29
+ if($safe_mode_set){
30
+ $html .="<p class='sinch-error'><b>You can't start import (safe_mode is 'On'. set safe_mode = Off in php.ini )<b></p>";
31
+ }elseif(!$import->is_full_import_have_been_run()){
32
+ $html .="Full import have never finished with success";
33
+ }else{
34
+ $html .= $start_import_button;
35
+ }
36
+
37
+ $last_import=$import->getDataOfLatestImport();
38
+ $last_imp_status=$last_import['global_status_import'];
39
+ if($last_imp_status=='Failed'){
40
+ $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p class="sinch-error">The import has failed. Please ensure that you are using the correct settings. Last step was "'.$last_import['detail_status_import'].'"<br> Error reporting : "'.$last_import['error_report_message'].'"</p></div>';
41
+ }elseif($last_imp_status=='Successful'){
42
+ $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p class="sinch-success">'.$last_import['number_of_products'].' products imported succesfully!</p></div>';
43
+ }elseif($last_imp_status=='Run'){
44
+ $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"><br><br><hr/><p>Import is running now</p></div>';
45
+ }else{
46
+ $html.='<div id="sinchimport_current_status_message" name="sinchimport_current_status_message" style="display:true"></div>';
47
+ }
48
+
49
+ return $html;
50
+ }
51
+
52
+ protected function _getStatusTemplateHtml()
53
+ {
54
+ $run_pic=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif";
55
+ $html="
56
+ <ul>
57
+ <li>
58
+ Start Import
59
+ &nbsp
60
+ <span id='sinchimport_stock_price_start_import'>
61
+ <img src='".$run_pic."'
62
+ alt='Sinch Import run' />
63
+ </span>
64
+ </li>
65
+ <li>
66
+ Download files
67
+ &nbsp
68
+ <span id='sinchimport_stock_price_upload_files'>
69
+ <img src='".$run_pic."'
70
+ alt='Download files' />
71
+ </span>
72
+ </li>
73
+ <li>
74
+ Parse Stock And Prices
75
+ &nbsp
76
+ <span id='sinchimport_stock_price_parse_products'>
77
+ <img src='".$run_pic."'
78
+ alt='Parse Stock And Prices' />
79
+ </span>
80
+ </li>
81
+ <li>
82
+ Indexing data
83
+ &nbsp
84
+ <span id='sinchimport_stock_price_indexing_data'>
85
+ <img src='".$run_pic."'
86
+ alt='Indexing data' />
87
+ </span>
88
+ </li>
89
+ <li>
90
+ Import finished
91
+ &nbsp
92
+ <span id='sinchimport_stock_price_finish_import'>
93
+ <img src='".$run_pic."'
94
+ alt='Import finished' />
95
+ </span>
96
+ </li>
97
+
98
+ </ul>
99
+ ";
100
+ return $html;
101
+ }
102
+
103
+ protected function _appendJs()
104
+ {
105
+ $post_url=$this->getUrl('sinchimport/ajax/stockPrice');
106
+ $post_url_upd=$this->getUrl('sinchimport/ajax/UpdateStatus');
107
+ $html = "
108
+ <script>
109
+ function start_stock_price_sinch_import(){
110
+ set_stock_price_run_icon();
111
+ st_pr_status_div=document.getElementById('sinchimport_stock_price_status_template');
112
+ curr_status_div=document.getElementById('sinchimport_current_status_message');
113
+ curr_status_div.style.display='none';
114
+ st_pr_status_div.style.display='';
115
+ // status_div.innerHTML='';
116
+ sinch = new Sinch('$post_url','$post_url_upd');
117
+ sinch.startSinchImport();
118
+
119
+ //
120
+ }
121
+
122
+ function set_stock_price_run_icon(){
123
+ run_pic='<img src=\"".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."adminhtml/default/default/images/sinchimport_run.gif\""."/>';
124
+ document.getElementById('sinchimport_stock_price_start_import').innerHTML=run_pic;
125
+ document.getElementById('sinchimport_stock_price_upload_files').innerHTML=run_pic;
126
+ document.getElementById('sinchimport_stock_price_parse_products').innerHTML=run_pic;
127
+ document.getElementById('sinchimport_stock_price_indexing_data').innerHTML=run_pic;
128
+ document.getElementById('sinchimport_stock_price_finish_import').innerHTML=run_pic;
129
+
130
+ }
131
+
132
+ </script>
133
+ ";
134
+ return $html;
135
+ }
136
+
137
+ }
138
+ ?>
app/code/local/Bintime/Sinchimport/Helper/Data.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
- class Bintime_Sinchimport_Helper_Data extends Mage_Core_Helper_Abstract
3
- {
4
-
5
- }
6
- ?>
1
+ <?php
2
+ class Bintime_Sinchimport_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
6
+ ?>
app/code/local/Bintime/Sinchimport/Helper/Getdata.php CHANGED
@@ -1,186 +1,186 @@
1
- <?php
2
- /**
3
- *
4
- * Class achieves icecat description from Model by recieved SKU and manufacturer
5
- * @author Sergey Gozhedrianov <info@bintime.com>
6
- *
7
- */
8
- class Bintime_Sinchimport_Helper_Getdata extends Mage_Core_Helper_Abstract
9
- {
10
- private $iceCatModel;
11
- private $sinchModel;
12
- private $error;
13
- private $systemError;
14
-
15
- /**
16
- * Gets product Data and delegates it to Model
17
- * @param Mage_Catalog_Model_Product $_product
18
- * @return Bintime_Icecatimport_Helper_Getdata
19
- */
20
- public function getProductDescription($_product){
21
- $entityId = $_product->getEntityId();
22
- /* $sku = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
23
- $manufacturerId = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/manufacturer'));
24
- if (Mage::getStoreConfig('icecat_root/icecat/manufacturer') == 'manufacturer'){
25
- $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
26
- ->setEntityTypeFilter($_product->getResource()->getTypeId())
27
- ->addFieldToFilter('attribute_code', 'manufacturer');
28
- $attribute = $attributes->getFirstItem()->setEntity($_product->getResource());
29
- $manufacturer = $attribute->getSource()->getOptionText($manufacturerId);
30
- }
31
- else {
32
- $manufacturer = $manufacturerId;
33
- }
34
- $locale = Mage::getStoreConfig('icecat_root/icecat/language');
35
-
36
- if ($locale == '0'){
37
- $systemLocale = explode("_", Mage::app()->getLocale()->getLocaleCode());
38
- $locale = $systemLocale[0];
39
- }
40
- $userLogin = Mage::getStoreConfig('icecat_root/icecat/login');
41
- $userPass = Mage::getStoreConfig('icecat_root/icecat/password');
42
-
43
- $this->iceCatModel = Mage::getSingleton('icecatimport/import');
44
-
45
- if (!$this->iceCatModel->getProductDescription($sku, $manufacturer, $locale, $userLogin, $userPass, $entityId)){
46
- $this->error = $this->iceCatModel->getErrorMessage();
47
- $this->systemError = $this->iceCatModel->getSystemError();
48
- return $this;
49
- }
50
- */
51
- $this->sinchModel = Mage::getSingleton('sinchimport/sinch');
52
- if(!$this->sinchModel->getProductDescription($entityId)){
53
- $this->error = $this->sinchModel->getErrorMessage();
54
- $this->systemError = $this->sinchModel->getSystemError();
55
- }
56
- return $this;
57
- }
58
- /**
59
- * returns true if error during data fetch occured else false
60
- */
61
- public function hasError(){
62
- if ($this->error || $this->systemError){
63
- return true;
64
- }
65
- return false;
66
- }
67
-
68
- /**
69
- * return error message
70
- */
71
- public function getError(){
72
- //show icecat error on product page return $this->error;
73
- }
74
-
75
- /**
76
- * return system error
77
- */
78
- public function hasSystemError(){
79
- if ($this->systemError){
80
- return $this->systemError;
81
- }
82
- return false;
83
- }
84
-
85
- public function getProductDescriptionList(){
86
- return $this->sinchModel->getProductDescriptionList();
87
- }
88
- public function getProductSpecifications(){
89
- return $this->sinchModel->getProductSpecifications();
90
- }
91
-
92
- public function getShortProductDescription(){
93
- return $this->sinchModel->getShortProductDescription();
94
- }
95
-
96
- public function getLowPicUrl(){
97
- return $this->sinchModel->getLowPicUrl();
98
- }
99
-
100
- public function getGalleryPhotos(){
101
- return $this->sinchModel->getGalleryPhotos();
102
- }
103
-
104
- public function getProductName(){
105
- return $this->sinchModel->getProductName();
106
- }
107
- public function getVendor(){
108
- return $this->sinchModel->getVendor();
109
- }
110
-
111
- public function getFullProductDescription(){
112
- return $this->sinchModel->getFullProductDescription();
113
- }
114
-
115
- public function getMPN(){
116
- return $this->sinchModel->getMPN();
117
- }
118
- public function getEAN(){
119
- return $this->sinchModel->getEAN();
120
- }
121
-
122
- /**
123
- * Form related products list according to store products
124
- */
125
- public function getRelatedProducts(){
126
- $relatedProducts =$this->sinchModel->getRelatedProducts();
127
- if (empty($relatedProducts)){
128
- return array();
129
- }
130
- $sku = 'sku';
131
- $collection = Mage::getModel('catalog/product')->getCollection();
132
-
133
- $filterArray = array();
134
- foreach($relatedProducts as $mpn => $valueArray){
135
- array_push($filterArray, array('attribute'=>$sku,'eq'=>$mpn));
136
- }
137
- $collection->addFieldToFilter($filterArray);
138
-
139
- $collection->addAttributeToSelect($sku);
140
- $collection->addAttributeToSelect('category_ids');
141
-
142
- $relatedProductsList = array();
143
- foreach ($collection as $product) {
144
- $categoryIds = $product->getCategoryIds();
145
- if(!empty($categoryIds)){
146
- if (is_array($categoryIds)){
147
- $catogoriesArray = $categoryIds;
148
- }
149
- if (is_string($categoryIds)){
150
- $catogoriesArray = explode(",",$product->getCategoryIds());
151
- }
152
- foreach($catogoriesArray as $categoryId){
153
- if (!array_key_exists($product->getData($sku), $relatedProducts)){
154
- continue;
155
- }
156
- $relatedProductInfo = $relatedProducts[$product->getData($sku)];
157
- $relatedProductInfo['mpn'] = $product->getData($sku);
158
- $relatedProductInfo['url'] = $product->getProductUrl();//preg_replace( '/\/\d+\/$/',"/".$categoryId."/",$product->getProductUrl());;
159
- if (!array_key_exists($categoryId, $relatedProductsList)){
160
- $relatedProductsList[$categoryId]= array();
161
- }
162
-
163
- array_push($relatedProductsList[$categoryId], $relatedProductInfo);
164
- }
165
- }
166
- else {
167
- if (!array_key_exists($product->getData($sku), $relatedProducts)){
168
- continue;
169
- }
170
- $relatedProductInfo = $relatedProducts[$product->getData($sku)];
171
- $relatedProductInfo['mpn'] = $product->getData($sku);
172
- $relatedProductInfo['url'] = $product->getProductUrl();//preg_replace( '/category\/\d+\/$/','',$product->getProductUrl());;
173
- if (!array_key_exists('a', $relatedProductsList)){
174
- $relatedProductsList['a']= array();
175
- }
176
-
177
- array_push($relatedProductsList['a'], $relatedProductInfo);
178
- }
179
- }
180
-
181
- return $relatedProductsList;
182
-
183
- }
184
-
185
- }
186
- ?>
1
+ <?php
2
+ /**
3
+ *
4
+ * Class achieves icecat description from Model by recieved SKU and manufacturer
5
+ * @author Sergey Gozhedrianov <info@bintime.com>
6
+ *
7
+ */
8
+ class Bintime_Sinchimport_Helper_Getdata extends Mage_Core_Helper_Abstract
9
+ {
10
+ private $iceCatModel;
11
+ private $sinchModel;
12
+ private $error;
13
+ private $systemError;
14
+
15
+ /**
16
+ * Gets product Data and delegates it to Model
17
+ * @param Mage_Catalog_Model_Product $_product
18
+ * @return Bintime_Icecatimport_Helper_Getdata
19
+ */
20
+ public function getProductDescription($_product){
21
+ $entityId = $_product->getEntityId();
22
+ /* $sku = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
23
+ $manufacturerId = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/manufacturer'));
24
+ if (Mage::getStoreConfig('icecat_root/icecat/manufacturer') == 'manufacturer'){
25
+ $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
26
+ ->setEntityTypeFilter($_product->getResource()->getTypeId())
27
+ ->addFieldToFilter('attribute_code', 'manufacturer');
28
+ $attribute = $attributes->getFirstItem()->setEntity($_product->getResource());
29
+ $manufacturer = $attribute->getSource()->getOptionText($manufacturerId);
30
+ }
31
+ else {
32
+ $manufacturer = $manufacturerId;
33
+ }
34
+ $locale = Mage::getStoreConfig('icecat_root/icecat/language');
35
+
36
+ if ($locale == '0'){
37
+ $systemLocale = explode("_", Mage::app()->getLocale()->getLocaleCode());
38
+ $locale = $systemLocale[0];
39
+ }
40
+ $userLogin = Mage::getStoreConfig('icecat_root/icecat/login');
41
+ $userPass = Mage::getStoreConfig('icecat_root/icecat/password');
42
+
43
+ $this->iceCatModel = Mage::getSingleton('icecatimport/import');
44
+
45
+ if (!$this->iceCatModel->getProductDescription($sku, $manufacturer, $locale, $userLogin, $userPass, $entityId)){
46
+ $this->error = $this->iceCatModel->getErrorMessage();
47
+ $this->systemError = $this->iceCatModel->getSystemError();
48
+ return $this;
49
+ }
50
+ */
51
+ $this->sinchModel = Mage::getSingleton('sinchimport/sinch');
52
+ if(!$this->sinchModel->getProductDescription($entityId)){
53
+ $this->error = $this->sinchModel->getErrorMessage();
54
+ $this->systemError = $this->sinchModel->getSystemError();
55
+ }
56
+ return $this;
57
+ }
58
+ /**
59
+ * returns true if error during data fetch occured else false
60
+ */
61
+ public function hasError(){
62
+ if ($this->error || $this->systemError){
63
+ return true;
64
+ }
65
+ return false;
66
+ }
67
+
68
+ /**
69
+ * return error message
70
+ */
71
+ public function getError(){
72
+ //show icecat error on product page return $this->error;
73
+ }
74
+
75
+ /**
76
+ * return system error
77
+ */
78
+ public function hasSystemError(){
79
+ if ($this->systemError){
80
+ return $this->systemError;
81
+ }
82
+ return false;
83
+ }
84
+
85
+ public function getProductDescriptionList(){
86
+ return $this->sinchModel->getProductDescriptionList();
87
+ }
88
+ public function getProductSpecifications(){
89
+ return $this->sinchModel->getProductSpecifications();
90
+ }
91
+
92
+ public function getShortProductDescription(){
93
+ return $this->sinchModel->getShortProductDescription();
94
+ }
95
+
96
+ public function getLowPicUrl(){
97
+ return $this->sinchModel->getLowPicUrl();
98
+ }
99
+
100
+ public function getGalleryPhotos(){
101
+ return $this->sinchModel->getGalleryPhotos();
102
+ }
103
+
104
+ public function getProductName(){
105
+ return $this->sinchModel->getProductName();
106
+ }
107
+ public function getVendor(){
108
+ return $this->sinchModel->getVendor();
109
+ }
110
+
111
+ public function getFullProductDescription(){
112
+ return $this->sinchModel->getFullProductDescription();
113
+ }
114
+
115
+ public function getMPN(){
116
+ return $this->sinchModel->getMPN();
117
+ }
118
+ public function getEAN(){
119
+ return $this->sinchModel->getEAN();
120
+ }
121
+
122
+ /**
123
+ * Form related products list according to store products
124
+ */
125
+ public function getRelatedProducts(){
126
+ $relatedProducts =$this->sinchModel->getRelatedProducts();
127
+ if (empty($relatedProducts)){
128
+ return array();
129
+ }
130
+ $sku = 'sku';
131
+ $collection = Mage::getModel('catalog/product')->getCollection();
132
+
133
+ $filterArray = array();
134
+ foreach($relatedProducts as $mpn => $valueArray){
135
+ array_push($filterArray, array('attribute'=>$sku,'eq'=>$mpn));
136
+ }
137
+ $collection->addFieldToFilter($filterArray);
138
+
139
+ $collection->addAttributeToSelect($sku);
140
+ $collection->addAttributeToSelect('category_ids');
141
+
142
+ $relatedProductsList = array();
143
+ foreach ($collection as $product) {
144
+ $categoryIds = $product->getCategoryIds();
145
+ if(!empty($categoryIds)){
146
+ if (is_array($categoryIds)){
147
+ $catogoriesArray = $categoryIds;
148
+ }
149
+ if (is_string($categoryIds)){
150
+ $catogoriesArray = explode(",",$product->getCategoryIds());
151
+ }
152
+ foreach($catogoriesArray as $categoryId){
153
+ if (!array_key_exists($product->getData($sku), $relatedProducts)){
154
+ continue;
155
+ }
156
+ $relatedProductInfo = $relatedProducts[$product->getData($sku)];
157
+ $relatedProductInfo['mpn'] = $product->getData($sku);
158
+ $relatedProductInfo['url'] = $product->getProductUrl();//preg_replace( '/\/\d+\/$/',"/".$categoryId."/",$product->getProductUrl());;
159
+ if (!array_key_exists($categoryId, $relatedProductsList)){
160
+ $relatedProductsList[$categoryId]= array();
161
+ }
162
+
163
+ array_push($relatedProductsList[$categoryId], $relatedProductInfo);
164
+ }
165
+ }
166
+ else {
167
+ if (!array_key_exists($product->getData($sku), $relatedProducts)){
168
+ continue;
169
+ }
170
+ $relatedProductInfo = $relatedProducts[$product->getData($sku)];
171
+ $relatedProductInfo['mpn'] = $product->getData($sku);
172
+ $relatedProductInfo['url'] = $product->getProductUrl();//preg_replace( '/category\/\d+\/$/','',$product->getProductUrl());;
173
+ if (!array_key_exists('a', $relatedProductsList)){
174
+ $relatedProductsList['a']= array();
175
+ }
176
+
177
+ array_push($relatedProductsList['a'], $relatedProductInfo);
178
+ }
179
+ }
180
+
181
+ return $relatedProductsList;
182
+
183
+ }
184
+
185
+ }
186
+ ?>
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/Api.php CHANGED
@@ -1,86 +1,86 @@
1
- <?php
2
- class Bintime_Sinchimport_Model_Api extends Mage_Api_Model_Resource_Abstract
3
- {
4
- public function test($arg)
5
- {
6
- return "!!!!!!!!!!Hello World! My argument is : ".$arg;
7
- }
8
-
9
- public function run_full_import($arg)
10
- {
11
- $import=Mage::getModel('sinchimport/sinch');
12
-
13
- if($import->is_imort_not_run()){
14
- $dir = dirname(__FILE__);
15
- exec("nohup ".$import->php_run_string.$dir."/../sinch_import_start_ajax.php > /dev/null & echo $!");
16
- sleep(5);
17
- if($import->is_imort_not_run()){
18
- $message_arr = $import->getDataOfLatestImport();
19
- $satus_arr=array('NOT OK', "Last Import finish with ".$message_arr['global_status_import']." at ".$message_arr['finish_import']."; Last status - ".$message_arr['detail_status_import']." ".$message_arr['error_report_message']);
20
- }else{
21
- $satus_arr=array('OK', "Import started");
22
- }
23
-
24
- }else{
25
- $message_arr = $import->getDataOfLatestImport();
26
- $satus_arr=array('NOT OK', "Import already started at ".$message_arr['start_import']." current_status - ".$message_arr['detail_status_import']);
27
- }
28
-
29
- return $satus_arr;
30
- }
31
- public function run_ps_import($arg)
32
- {
33
- $import=Mage::getModel('sinchimport/sinch');
34
-
35
- if($import->is_imort_not_run()){
36
- $dir = dirname(__FILE__);
37
- exec("nohup ".$import->php_run_string.$dir."/../stock_price_sinch_import_start_ajax.php > /dev/null & echo $!");
38
- sleep(5);
39
- if($import->is_imort_not_run()){
40
- $message_arr = $import->getDataOfLatestImport();
41
- $satus_arr=array('NOT OK', "Last ".$message_arr['import_type']." import finish with ".$message_arr['global_status_import']."; Last status '".$message_arr['detail_status_import']."' ".$message_arr['error_report_message']);
42
- }else{
43
- $satus_arr=array('OK', "Price Stock Import started");
44
- }
45
-
46
- }else{
47
- $message_arr = $import->getDataOfLatestImport();
48
- $satus_arr=array('NOT OK', $message_arr['import_type']." import already started at ".$message_arr['start_import']." current_status - '".$message_arr['detail_status_import']."'");
49
- }
50
-
51
- return $satus_arr;
52
- }
53
-
54
- public function get_import_status()
55
- {
56
- $import=Mage::getModel('sinchimport/sinch');
57
- $message_arr = $import->getDataOfLatestImport();
58
- if($import->is_imort_not_run()){
59
- if($message_arr['global_status_import']=='Successful'){
60
- $status=$message_arr['detail_status_import'];
61
- }elseif($message_arr['global_status_import']=='Failed'){
62
- $status=$message_arr['error_report_message'];
63
- }
64
- $satus_arr=array(
65
- 'is_import_running' => 'Not Running',
66
- 'status' => $status,
67
- 'last_finish_date' => $message_arr['finish_import'],
68
- 'count_of_products' => $message_arr['number_of_products'],
69
- 'import_type' => $message_arr['import_type'],
70
- 'message' => "Last ".$message_arr['import_type'].' import finished at '.$message_arr['finish_import'].' with '.$message_arr['global_status_import']."; Last status '".$message_arr['detail_status_import']."' ".$message_arr['error_report_message']
71
-
72
- );
73
- }else{
74
- $satus_arr=array( 'is_import_running' =>'Running',
75
- 'status' => '',
76
- 'last_finish_date' => $message_arr['finish_import'],
77
- 'count_of_products' => $message_arr['number_of_products'],
78
- 'import_type' => $message_arr['import_type'],
79
- 'message' =>$message_arr['import_type']." import already started at ".$message_arr['start_import']." current_status - '".$message_arr['detail_status_import']."'");
80
- }
81
-
82
- return $satus_arr;
83
- }
84
-
85
- }
86
- ?>
1
+ <?php
2
+ class Bintime_Sinchimport_Model_Api extends Mage_Api_Model_Resource_Abstract
3
+ {
4
+ public function test($arg)
5
+ {
6
+ return "!!!!!!!!!!Hello World! My argument is : ".$arg;
7
+ }
8
+
9
+ public function run_full_import($arg)
10
+ {
11
+ $import=Mage::getModel('sinchimport/sinch');
12
+
13
+ if($import->is_imort_not_run()){
14
+ $dir = dirname(__FILE__);
15
+ exec("nohup ".$import->php_run_string.$dir."/../sinch_import_start_ajax.php > /dev/null & echo $!");
16
+ sleep(5);
17
+ if($import->is_imort_not_run()){
18
+ $message_arr = $import->getDataOfLatestImport();
19
+ $satus_arr=array('NOT OK', "Last Import finish with ".$message_arr['global_status_import']." at ".$message_arr['finish_import']."; Last status - ".$message_arr['detail_status_import']." ".$message_arr['error_report_message']);
20
+ }else{
21
+ $satus_arr=array('OK', "Import started");
22
+ }
23
+
24
+ }else{
25
+ $message_arr = $import->getDataOfLatestImport();
26
+ $satus_arr=array('NOT OK', "Import already started at ".$message_arr['start_import']." current_status - ".$message_arr['detail_status_import']);
27
+ }
28
+
29
+ return $satus_arr;
30
+ }
31
+ public function run_ps_import($arg)
32
+ {
33
+ $import=Mage::getModel('sinchimport/sinch');
34
+
35
+ if($import->is_imort_not_run()){
36
+ $dir = dirname(__FILE__);
37
+ exec("nohup ".$import->php_run_string.$dir."/../stock_price_sinch_import_start_ajax.php > /dev/null & echo $!");
38
+ sleep(5);
39
+ if($import->is_imort_not_run()){
40
+ $message_arr = $import->getDataOfLatestImport();
41
+ $satus_arr=array('NOT OK', "Last ".$message_arr['import_type']." import finish with ".$message_arr['global_status_import']."; Last status '".$message_arr['detail_status_import']."' ".$message_arr['error_report_message']);
42
+ }else{
43
+ $satus_arr=array('OK', "Price Stock Import started");
44
+ }
45
+
46
+ }else{
47
+ $message_arr = $import->getDataOfLatestImport();
48
+ $satus_arr=array('NOT OK', $message_arr['import_type']." import already started at ".$message_arr['start_import']." current_status - '".$message_arr['detail_status_import']."'");
49
+ }
50
+
51
+ return $satus_arr;
52
+ }
53
+
54
+ public function get_import_status()
55
+ {
56
+ $import=Mage::getModel('sinchimport/sinch');
57
+ $message_arr = $import->getDataOfLatestImport();
58
+ if($import->is_imort_not_run()){
59
+ if($message_arr['global_status_import']=='Successful'){
60
+ $status=$message_arr['detail_status_import'];
61
+ }elseif($message_arr['global_status_import']=='Failed'){
62
+ $status=$message_arr['error_report_message'];
63
+ }
64
+ $satus_arr=array(
65
+ 'is_import_running' => 'Not Running',
66
+ 'status' => $status,
67
+ 'last_finish_date' => $message_arr['finish_import'],
68
+ 'count_of_products' => $message_arr['number_of_products'],
69
+ 'import_type' => $message_arr['import_type'],
70
+ 'message' => "Last ".$message_arr['import_type'].' import finished at '.$message_arr['finish_import'].' with '.$message_arr['global_status_import']."; Last status '".$message_arr['detail_status_import']."' ".$message_arr['error_report_message']
71
+
72
+ );
73
+ }else{
74
+ $satus_arr=array( 'is_import_running' =>'Running',
75
+ 'status' => '',
76
+ 'last_finish_date' => $message_arr['finish_import'],
77
+ 'count_of_products' => $message_arr['number_of_products'],
78
+ 'import_type' => $message_arr['import_type'],
79
+ 'message' =>$message_arr['import_type']." import already started at ".$message_arr['start_import']." current_status - '".$message_arr['detail_status_import']."'");
80
+ }
81
+
82
+ return $satus_arr;
83
+ }
84
+
85
+ }
86
+ ?>
app/code/local/Bintime/Sinchimport/Model/Category.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
-
3
- class Bintime_Sinchimport_Model_Category extends Mage_Catalog_Model_Category {
4
-
5
- public function getImageUrl()
6
- {
7
- $url = false;
8
- if ($image = $this->getImage()) {
9
- if (substr($image,0,4) != 'http'){
10
- $url = Mage::getBaseUrl('media').'catalog/category/'.$image;
11
- }else{
12
- $url = $image;
13
- }
14
- }
15
- return $url;
16
- }
17
-
18
-
19
- }
20
- ?>
1
+ <?php
2
+
3
+ class Bintime_Sinchimport_Model_Category extends Mage_Catalog_Model_Category {
4
+
5
+ public function getImageUrl()
6
+ {
7
+ $url = false;
8
+ if ($image = $this->getImage()) {
9
+ if (substr($image,0,4) != 'http'){
10
+ $url = Mage::getBaseUrl('media').'catalog/category/'.$image;
11
+ }else{
12
+ $url = $image;
13
+ }
14
+ }
15
+ return $url;
16
+ }
17
+
18
+
19
+ }
20
+ ?>
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,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 = $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 = $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
+ }
app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Price.php CHANGED
@@ -1,194 +1,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
- // $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
+ // $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
+ }
app/code/local/Bintime/Sinchimport/Model/Product.php CHANGED
@@ -1,74 +1,74 @@
1
- <?php
2
-
3
- class Bintime_Sinchimport_Model_Product extends Mage_Catalog_Model_Product
4
- {
5
- public function getIcecatId()
6
- {
7
-
8
- $resource = $this->getResource();
9
- $connection = $resource->getReadConnection();
10
- $result = $connection->query("
11
- SELECT product_id FROM icecat_products WHERE mpn = '" . $this->getVendorProductId() . "' ");
12
- $id = 0;
13
- if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
14
- $id = $row['product_id'];
15
- }
16
- // echo 'rewrite!';
17
- return $id;
18
- }
19
- public function getMediaGalleryImages()
20
- {
21
- $entity_id=$this->getEntityId();
22
- $sinch=Mage::getModel('sinchimport/sinch');
23
- $sinch->loadGalleryPhotos($this->getEntityId());
24
- $gallery_photos=$sinch->getGalleryPhotos();
25
- if(is_array($gallery_photos)){
26
- $images = new Varien_Data_Collection();
27
- foreach($gallery_photos as $photo){
28
- $image['file']=$photo['thumb'];
29
- $image['url']=$photo['pic'];
30
- $images->addItem(new Varien_Object($image));
31
- }
32
- $this->setData('media_gallery_images', $images);
33
- }else{
34
- if(!$this->hasData('media_gallery_images') && is_array($this->getMediaGallery('images'))) {
35
- $images = new Varien_Data_Collection();
36
- foreach ($this->getMediaGallery('images') as $image) {
37
- if ($image['disabled']) {
38
- continue;
39
- }
40
- $image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
41
- $image['id'] = isset($image['value_id']) ? $image['value_id'] : null;
42
- $image['path'] = $this->getMediaConfig()->getMediaPath($image['file']);
43
- $images->addItem(new Varien_Object($image));
44
- }
45
- $this->setData('media_gallery_images', $images);
46
- }
47
-
48
- }
49
-
50
- return $this->getData('media_gallery_images');
51
- }
52
-
53
- function afterCommitCallback(){
54
- parent::afterCommitCallback();
55
- Mage::getSingleton('index/indexer')->processEntityAction(
56
- $this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
57
- );
58
- $entity_id=$this->getEntityId();
59
- $sinch=Mage::getModel('sinchimport/sinch');
60
- $sinch->reloadProductImage($entity_id);
61
- return $this;
62
-
63
- }
64
- }
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
1
+ <?php
2
+
3
+ class Bintime_Sinchimport_Model_Product extends Mage_Catalog_Model_Product
4
+ {
5
+ public function getIcecatId()
6
+ {
7
+
8
+ $resource = $this->getResource();
9
+ $connection = $resource->getReadConnection();
10
+ $result = $connection->query("
11
+ SELECT product_id FROM icecat_products WHERE mpn = '" . $this->getVendorProductId() . "' ");
12
+ $id = 0;
13
+ if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
14
+ $id = $row['product_id'];
15
+ }
16
+ // echo 'rewrite!';
17
+ return $id;
18
+ }
19
+ public function getMediaGalleryImages()
20
+ {
21
+ $entity_id=$this->getEntityId();
22
+ $sinch=Mage::getModel('sinchimport/sinch');
23
+ $sinch->loadGalleryPhotos($this->getEntityId());
24
+ $gallery_photos=$sinch->getGalleryPhotos();
25
+ if(is_array($gallery_photos)){
26
+ $images = new Varien_Data_Collection();
27
+ foreach($gallery_photos as $photo){
28
+ $image['file']=$photo['thumb'];
29
+ $image['url']=$photo['pic'];
30
+ $images->addItem(new Varien_Object($image));
31
+ }
32
+ $this->setData('media_gallery_images', $images);
33
+ }else{
34
+ if(!$this->hasData('media_gallery_images') && is_array($this->getMediaGallery('images'))) {
35
+ $images = new Varien_Data_Collection();
36
+ foreach ($this->getMediaGallery('images') as $image) {
37
+ if ($image['disabled']) {
38
+ continue;
39
+ }
40
+ $image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
41
+ $image['id'] = isset($image['value_id']) ? $image['value_id'] : null;
42
+ $image['path'] = $this->getMediaConfig()->getMediaPath($image['file']);
43
+ $images->addItem(new Varien_Object($image));
44
+ }
45
+ $this->setData('media_gallery_images', $images);
46
+ }
47
+
48
+ }
49
+
50
+ return $this->getData('media_gallery_images');
51
+ }
52
+
53
+ function afterCommitCallback(){
54
+ parent::afterCommitCallback();
55
+ Mage::getSingleton('index/indexer')->processEntityAction(
56
+ $this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
57
+ );
58
+ $entity_id=$this->getEntityId();
59
+ $sinch=Mage::getModel('sinchimport/sinch');
60
+ $sinch->reloadProductImage($entity_id);
61
+ return $this;
62
+
63
+ }
64
+ }
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
app/code/local/Bintime/Sinchimport/Model/Resource/Layer/Filter/Price.php CHANGED
@@ -1,80 +1,80 @@
1
- <?php
2
- /**
3
- * Catalog Layer Price Filter resource model
4
- *
5
- * @category Mage
6
- * @package Mage_Catalog
7
- * @author Sergey Stepanchuk
8
- */
9
- class Bintime_Sinchimport_Model_Resource_Layer_Filter_Price extends Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Price
10
- {
11
- public function applyFilterToCollectionMinMaxPrice($filter, $minPrice, $maxPrice)
12
- {
13
- $collection = $filter->getLayer()->getProductCollection();
14
- $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId());
15
-
16
- $select = $collection->getSelect();
17
- $response = $this->_dispatchPreparePriceEvent($filter, $select);
18
-
19
- $table = $this->_getIndexTableAlias();
20
- $additional = join('', $response->getAdditionalCalculations());
21
- $rate = $filter->getCurrencyRate();
22
- $priceExpr = new Zend_Db_Expr("(({$table}.min_price {$additional}) * {$rate})");
23
-
24
- $select->where($priceExpr . ' >= ?', $minPrice);
25
- if($maxPrice!='*'){
26
- $select ->where($priceExpr . ' < ?', $maxPrice);
27
- }
28
- return $this;
29
- }
30
-
31
- public function getCountMinMaxPrice($filter, $minPrice, $maxPrice)
32
- {
33
- $select = $this->_getSelect($filter);
34
- $connection = $this->_getReadAdapter();
35
- $response = $this->_dispatchPreparePriceEvent($filter, $select);
36
- $table = $this->_getIndexTableAlias();
37
-
38
- $additional = join('', $response->getAdditionalCalculations());
39
- $rate = $filter->getCurrencyRate();
40
-
41
- /**
42
- * Check and set correct variable values to prevent SQL-injections
43
- */
44
- $rate = floatval($rate);
45
-
46
-
47
-
48
-
49
- $countExpr = new Zend_Db_Expr('COUNT(*)');
50
- $rangeExpr = new Zend_Db_Expr("FLOOR(({$table}.min_price {$additional}) * {$rate}) ");
51
- $select->where($rangeExpr . ' >= ?', $minPrice);
52
- if($maxPrice!='*'){
53
- $select->where($rangeExpr . ' < ?', $maxPrice);
54
- }
55
- $select->columns(array(
56
- 'count' => $countExpr
57
- ));
58
-
59
- $count=$connection->fetchPairs($select);
60
- return key($count);
61
- }
62
-
63
- protected function _getSelect($filter)
64
- {
65
- $collection = $filter->getLayer()->getProductCollection();
66
- $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId());
67
-
68
- // clone select from collection with filters
69
- $select = clone $collection->getSelect();
70
- // reset columns, order and limitation conditions
71
- $select->reset(Zend_Db_Select::COLUMNS);
72
- $select->reset(Zend_Db_Select::ORDER);
73
- $select->reset(Zend_Db_Select::LIMIT_COUNT);
74
- $select->reset(Zend_Db_Select::LIMIT_OFFSET);
75
-
76
- return $select;
77
- }
78
-
79
- }
80
- ?>
1
+ <?php
2
+ /**
3
+ * Catalog Layer Price Filter resource model
4
+ *
5
+ * @category Mage
6
+ * @package Mage_Catalog
7
+ * @author Sergey Stepanchuk
8
+ */
9
+ class Bintime_Sinchimport_Model_Resource_Layer_Filter_Price extends Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Price
10
+ {
11
+ public function applyFilterToCollectionMinMaxPrice($filter, $minPrice, $maxPrice)
12
+ {
13
+ $collection = $filter->getLayer()->getProductCollection();
14
+ $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId());
15
+
16
+ $select = $collection->getSelect();
17
+ $response = $this->_dispatchPreparePriceEvent($filter, $select);
18
+
19
+ $table = $this->_getIndexTableAlias();
20
+ $additional = join('', $response->getAdditionalCalculations());
21
+ $rate = $filter->getCurrencyRate();
22
+ $priceExpr = new Zend_Db_Expr("(({$table}.min_price {$additional}) * {$rate})");
23
+
24
+ $select->where($priceExpr . ' >= ?', $minPrice);
25
+ if($maxPrice!='*'){
26
+ $select ->where($priceExpr . ' < ?', $maxPrice);
27
+ }
28
+ return $this;
29
+ }
30
+
31
+ public function getCountMinMaxPrice($filter, $minPrice, $maxPrice)
32
+ {
33
+ $select = $this->_getSelect($filter);
34
+ $connection = $this->_getReadAdapter();
35
+ $response = $this->_dispatchPreparePriceEvent($filter, $select);
36
+ $table = $this->_getIndexTableAlias();
37
+
38
+ $additional = join('', $response->getAdditionalCalculations());
39
+ $rate = $filter->getCurrencyRate();
40
+
41
+ /**
42
+ * Check and set correct variable values to prevent SQL-injections
43
+ */
44
+ $rate = floatval($rate);
45
+
46
+
47
+
48
+
49
+ $countExpr = new Zend_Db_Expr('COUNT(*)');
50
+ $rangeExpr = new Zend_Db_Expr("FLOOR(({$table}.min_price {$additional}) * {$rate}) ");
51
+ $select->where($rangeExpr . ' >= ?', $minPrice);
52
+ if($maxPrice!='*'){
53
+ $select->where($rangeExpr . ' < ?', $maxPrice);
54
+ }
55
+ $select->columns(array(
56
+ 'count' => $countExpr
57
+ ));
58
+
59
+ $count=$connection->fetchPairs($select);
60
+ return key($count);
61
+ }
62
+
63
+ protected function _getSelect($filter)
64
+ {
65
+ $collection = $filter->getLayer()->getProductCollection();
66
+ $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId());
67
+
68
+ // clone select from collection with filters
69
+ $select = clone $collection->getSelect();
70
+ // reset columns, order and limitation conditions
71
+ $select->reset(Zend_Db_Select::COLUMNS);
72
+ $select->reset(Zend_Db_Select::ORDER);
73
+ $select->reset(Zend_Db_Select::LIMIT_COUNT);
74
+ $select->reset(Zend_Db_Select::LIMIT_OFFSET);
75
+
76
+ return $select;
77
+ }
78
+
79
+ }
80
+ ?>
app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php CHANGED
@@ -1,384 +1,384 @@
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
-
29
- case 'search':
30
- return $tablePrefix . $this->searchTable;
31
- break;
32
- default:
33
- $resource = Mage::getSingleton('core/resource');
34
- return $resource->getTableName($type);
35
- }
36
-
37
- }
38
-
39
- /**
40
- * Подготавливает фильтр к поиску
41
- *
42
- * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
43
- * @param string $value Значение, которму должен соответствовать атрибут
44
- * @return string
45
- */
46
- protected function _prepareSearch($filter, $value = null)
47
- {
48
- Varien_Profiler::start(__METHOD__);
49
- $catId = $filter->getLayer()->getCurrentCategory()->getId();
50
- $connection = $this->_getReadAdapter();
51
-
52
- $cfid = 0;
53
- if (!is_null($value)) {
54
- $feature = $filter->getAttributeModel();
55
- $cfid = $feature['category_feature_id'];
56
- }
57
- $resultTable = $this->_getTableName('result', $cfid);
58
- //TODO: this table must be temporary
59
- $sql = "
60
- CREATE TABLE IF NOT EXISTS `{$resultTable}`(
61
- `entity_id` int(10) unsigned,
62
- `category_id` int(10) unsigned,
63
- `product_id` int,
64
- `sinch_category_id` int,
65
- `name` varchar(255),
66
- `image` varchar(255),
67
- `supplier_id` int,
68
- `category_feature_id` int,
69
- `feature_id` int,
70
- `feature_name` varchar(255),
71
- `feature_value` text
72
- );
73
- ";
74
- $connection->exec($sql);
75
-
76
- $sql = "TRUNCATE TABLE {$resultTable}";
77
- $connection->exec($sql);
78
-
79
- $featuresTable = $this->_getTableName('FilterListOfFeatures');
80
- $sql = "TRUNCATE TABLE `$featuresTable`";
81
- $connection->exec($sql);
82
-
83
- $feature = $filter->getAttributeModel();
84
- if ($feature['limit_direction'] != 1 && $feature['limit_direction'] != 2) {
85
- if (!is_null($value)) {
86
- $sql = "INSERT INTO `$featuresTable` (category_feature_id, feature_value) VALUES (?)";
87
- $sql = $connection->quoteInto($sql, array($cfid, $value));
88
- $connection->exec($sql);
89
- }
90
- $params = 'null, null';
91
- }
92
- else {
93
- $bounds = explode(',', $value);
94
-
95
- $params = $bounds[0] != '-' ? (int)$bounds[0] : 'null';
96
- $params .= ', ';
97
- $params .= $bounds[1] != '-' ? (int)$bounds[1] : 'null';
98
- }
99
- //$connection->query("CALL `filter_icecat_products_s`($cfid, $catId,0,$cfid, $params)"));
100
- $tablePrefix = (string)Mage::app()->getConfig()->getTablePrefix();
101
- $result = $connection->raw_query("CALL ".$this->_getTableName('filter_sinch_products_s')."($cfid, $catId,0, $cfid, $params, '$tablePrefix')");
102
- Varien_Profiler::stop(__METHOD__);
103
- return $resultTable;
104
- }
105
-
106
-
107
- /**
108
- * Apply attribute filter to product collection
109
- *
110
- * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
111
- * @param string $value
112
- * @return Bintime_Icelayered_Model_Resource_Mysql4_Layer_Filter_Feature
113
- */
114
- public function applyFilterToCollection($filter, $value)
115
- {
116
- Varien_Profiler::start(__METHOD__);
117
- $searchTable = $this->_prepareSearch($filter, $value);
118
- self::$lastResultTable = $searchTable;
119
-
120
- $collection = $filter->getLayer()->getProductCollection();
121
- $feature = $filter->getAttributeModel();
122
- $connection = $this->_getReadAdapter();
123
-
124
- $collection->getSelect()->join(
125
- $searchTable,
126
- "{$searchTable}.entity_id = e.entity_id",
127
- array()
128
- );
129
-
130
- Varien_Profiler::stop(__METHOD__);
131
- return $this;
132
- }
133
-
134
- /**
135
- * Retrieve array with products counts per attribute option
136
- *
137
- * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
138
- * @return array
139
- */
140
- public function getCount($filter)
141
- {
142
- Varien_Profiler::start(__METHOD__);
143
-
144
- // clone select from collection with filters
145
- $select = clone $filter->getLayer()->getProductCollection()->getSelect();
146
-
147
- // reset columns, order and limitation conditions
148
- $select->reset(Zend_Db_Select::COLUMNS);
149
- $select->reset(Zend_Db_Select::ORDER);
150
- $select->reset(Zend_Db_Select::LIMIT_COUNT);
151
- $select->reset(Zend_Db_Select::LIMIT_OFFSET);
152
- $connection = $this->_getReadAdapter();
153
- $feature = $filter->getAttributeModel();
154
- $tableAlias = 'idx_' . $feature['category_feature_id'];
155
-
156
- $conditions = array(
157
- "{$tableAlias}.entity_id = e.entity_id",
158
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
159
- );
160
-
161
- $select->joinInner(
162
- array($tableAlias => $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id'])),
163
- join(' AND ', $conditions),
164
- array('value', 'count' => "COUNT(e.entity_id)")
165
- )
166
- ->group("{$tableAlias}.value");
167
-
168
- $tablePattern = $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id']);
169
- $query = "SHOW TABLES LIKE '$tablePattern'";
170
- $featureTables = $connection->fetchCol($query);
171
- $presentFeatures = array();
172
- foreach($featureTables as $t) {
173
- if (preg_match("#$tablePattern#", $t, $matches)) {
174
- $table_feat_exist=true;
175
- }
176
- }
177
-
178
- Varien_Profiler::stop(__METHOD__);
179
- if($table_feat_exist){
180
- return $connection->fetchPairs($select);
181
- }else{
182
- return null;
183
- }
184
-
185
- }
186
-
187
- public function getIntervalsCount($filter, $interval)
188
- {
189
- Varien_Profiler::start(__METHOD__);
190
-
191
- // clone select from collection with filters
192
- $select = clone $filter->getLayer()->getProductCollection()->getSelect();
193
-
194
- // reset columns, order and limitation conditions
195
- $select->reset(Zend_Db_Select::COLUMNS);
196
- $select->reset(Zend_Db_Select::ORDER);
197
- $select->reset(Zend_Db_Select::LIMIT_COUNT);
198
- $select->reset(Zend_Db_Select::LIMIT_OFFSET);
199
-
200
- $connection = $this->_getReadAdapter();
201
- $feature = $filter->getAttributeModel();
202
- $tableAlias = 'idx_' . $feature['category_feature_id'];
203
-
204
- $conditions = array(
205
- "{$tableAlias}.entity_id = e.entity_id",
206
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
207
- );
208
-
209
- $select->joinInner(
210
- array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
211
- join(' AND ', $conditions),
212
- array('count' => "COUNT(e.entity_id)")
213
- );
214
- if (isset($interval['low'], $interval['high'])) {
215
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
216
- }
217
- else if (isset($interval['low'])) {
218
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
219
- }
220
- else if (isset($interval['high'])) {
221
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
222
- }
223
- $count = $connection->fetchOne($select);
224
- Varien_Profiler::stop(__METHOD__);
225
- return $count;
226
- }
227
-
228
- function getIntervalsCountDescending($filter, $interval)
229
- {
230
- Varien_Profiler::start(__METHOD__);
231
-
232
- // clone select from collection with filters
233
- $select = clone $filter->getLayer()->getProductCollection()->getSelect();
234
-
235
- // reset columns, order and limitation conditions
236
- $select->reset(Zend_Db_Select::COLUMNS);
237
- $select->reset(Zend_Db_Select::ORDER);
238
- $select->reset(Zend_Db_Select::LIMIT_COUNT);
239
- $select->reset(Zend_Db_Select::LIMIT_OFFSET);
240
-
241
- $connection = $this->_getReadAdapter();
242
- $feature = $filter->getAttributeModel();
243
- $tableAlias = 'idx_' . $feature['category_feature_id'];
244
-
245
- $conditions = array(
246
- "{$tableAlias}.entity_id = e.entity_id",
247
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
248
- );
249
-
250
- $select->joinInner(
251
- array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
252
- join(' AND ', $conditions),
253
- array('count' => "COUNT(e.entity_id)")
254
- );
255
- if (isset($interval['low'], $interval['high'])) {
256
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
257
- }
258
- else if (isset($interval['low'])) {
259
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
260
- }
261
- else if (isset($interval['high'])) {
262
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
263
- }
264
- $count = $connection->fetchOne($select);
265
-
266
- Varien_Profiler::stop(__METHOD__);
267
- return $count;
268
- }
269
-
270
-
271
-
272
- /*
273
- * INDEXES FOLLOW.
274
- */
275
-
276
- /**
277
- * Запускает процедуры индексации.
278
- * Слушает событие Mage::dispatchEvent('iceimport_model_import_after',..)
279
- * @param <type> $observer
280
- */
281
- public function reindex($observer)
282
- {
283
- $this->splitProductsFeature();
284
- }
285
-
286
-
287
- /**
288
- * Разбивает таблицу icecat_product_feature на таблицы вида icecat_product_feature_%category_feature_id% для каждой фичи.
289
- *
290
- */
291
- public function splitProductsFeature()
292
- {
293
- Mage::log(__METHOD__ . " start at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
294
- $featureIds = $this->getProductFeatures4indexig();
295
-
296
- $resource = Mage::getSingleton('core/resource');
297
- // $tProudctsFeature = $resource->getTableName("icecat_products_feature");
298
- $connection = $this->_getWriteAdapter();
299
-
300
- //удаление таблиц с фичами не используемыми больше для навигации.
301
- $tablePattern = $resource->getTableName('stINch_products_feature_');
302
- $query = "SHOW TABLES LIKE '%$tablePattern%'";
303
- $featureTables = $connection->fetchCol($query);
304
- $presentFeatures = array();
305
- foreach($featureTables as $t) {
306
- if (preg_match("#$tablePattern(\d+)#", $t, $matches)) {
307
- $presentFeatures[] = $matches[1];
308
- }
309
- }
310
-
311
- $features2delete = array_diff($presentFeatures, $featureIds);
312
- if (count($features2delete)) {
313
- foreach ($features2delete as & $drop) {
314
- $drop = $tablePattern . $drop;
315
- }
316
- $dropSql = "DROP TABLE " . implode(',', $features2delete);
317
- $connection->exec($dropSql);
318
- }
319
- //
320
-
321
- //Создание таблиц с фичами используемыми в навигации.
322
- $i = 0; $storeId = Mage::app()->getStore()->getId(); $websiteId = Mage::app()->getWebsite()->getId();
323
- foreach ($featureIds as $featureId) {
324
- $tFeature = $resource->getTableName("stINch_products_feature_$featureId");
325
- $query = "DROP TABLE IF EXISTS $tFeature";
326
- $connection->exec($query);
327
-
328
- $query = "CREATE TABLE IF NOT EXISTS $tFeature (
329
- `entity_id` int(11) default NULL,
330
- `feature_id` int(11) NOT NULL,
331
- `product_id` int(11) default NULL,
332
- `category_feature_id` int(11) default NULL,
333
- `value` text,
334
- `presentation_value` text,
335
- INDEX (`feature_id`),
336
- KEY `category_feature_id` (`category_feature_id`)
337
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8
338
- ";
339
- $connection->exec($query);
340
-
341
- $query = "TRUNCATE TABLE $tFeature";
342
- $connection->exec($query);
343
-
344
- /*$query = "
345
- INSERT INTO $tFeature (feature_id, product_id, category_feature_id, value, presentation_value)
346
- SELECT feature_id, product_id, category_feature_id, value, presentation_value FROM $tProudctsFeature
347
- WHERE category_feature_id = $featureId
348
- ";*/
349
- $query = "
350
- REPLACE INTO $tFeature (entity_id,feature_id, product_id, category_feature_id, value, presentation_value)
351
- SELECT E.entity_id, RV.category_feature_id,E.entity_id, RV.category_feature_id, RV.text , RV.text
352
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." E
353
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." PCind
354
- ON (E.entity_id = PCind.product_id AND PCind.store_id='{$storeId}' AND PCind.visibility IN(2,4))
355
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
356
- ON price_index.entity_id = E.entity_id AND price_index.website_id = '{$websiteId}' AND price_index.customer_group_id = 0
357
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." PR
358
- ON (PR.store_product_id = E.store_product_id)
359
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." PF
360
- ON (PR.sinch_product_id = PF.sinch_product_id )
361
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." RV
362
- ON (PF.restricted_value_id=RV.restricted_value_id AND RV.category_feature_id= $featureId)
363
- GROUP BY E.entity_id;
364
- ";
365
- $connection->exec($query);
366
- }
367
- Mage::log(__METHOD__ . " end at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
368
- }
369
-
370
- /**
371
- * Список фич подлежащих индексации.
372
- *
373
- * @return array
374
- */
375
- private function getProductFeatures4indexig()
376
- {
377
- $connection = $this->_getReadAdapter();
378
-
379
- $tCatFeature = Mage::getSingleton('core/resource')->getTableName('stINch_categories_features');
380
- $query = "SELECT category_feature_id FROM $tCatFeature ";
381
-
382
- return $connection->fetchCol($query);
383
- }
384
- }
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
+
29
+ case 'search':
30
+ return $tablePrefix . $this->searchTable;
31
+ break;
32
+ default:
33
+ $resource = Mage::getSingleton('core/resource');
34
+ return $resource->getTableName($type);
35
+ }
36
+
37
+ }
38
+
39
+ /**
40
+ * Подготавливает фильтр к поиску
41
+ *
42
+ * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
43
+ * @param string $value Значение, которму должен соответствовать атрибут
44
+ * @return string
45
+ */
46
+ protected function _prepareSearch($filter, $value = null)
47
+ {
48
+ Varien_Profiler::start(__METHOD__);
49
+ $catId = $filter->getLayer()->getCurrentCategory()->getId();
50
+ $connection = $this->_getReadAdapter();
51
+
52
+ $cfid = 0;
53
+ if (!is_null($value)) {
54
+ $feature = $filter->getAttributeModel();
55
+ $cfid = $feature['category_feature_id'];
56
+ }
57
+ $resultTable = $this->_getTableName('result', $cfid);
58
+ //TODO: this table must be temporary
59
+ $sql = "
60
+ CREATE TABLE IF NOT EXISTS `{$resultTable}`(
61
+ `entity_id` int(10) unsigned,
62
+ `category_id` int(10) unsigned,
63
+ `product_id` int,
64
+ `sinch_category_id` int,
65
+ `name` varchar(255),
66
+ `image` varchar(255),
67
+ `supplier_id` int,
68
+ `category_feature_id` int,
69
+ `feature_id` int,
70
+ `feature_name` varchar(255),
71
+ `feature_value` text
72
+ );
73
+ ";
74
+ $connection->exec($sql);
75
+
76
+ $sql = "TRUNCATE TABLE {$resultTable}";
77
+ $connection->exec($sql);
78
+
79
+ $featuresTable = $this->_getTableName('FilterListOfFeatures');
80
+ $sql = "TRUNCATE TABLE `$featuresTable`";
81
+ $connection->exec($sql);
82
+
83
+ $feature = $filter->getAttributeModel();
84
+ if ($feature['limit_direction'] != 1 && $feature['limit_direction'] != 2) {
85
+ if (!is_null($value)) {
86
+ $sql = "INSERT INTO `$featuresTable` (category_feature_id, feature_value) VALUES (?)";
87
+ $sql = $connection->quoteInto($sql, array($cfid, $value));
88
+ $connection->exec($sql);
89
+ }
90
+ $params = 'null, null';
91
+ }
92
+ else {
93
+ $bounds = explode(',', $value);
94
+
95
+ $params = $bounds[0] != '-' ? (int)$bounds[0] : 'null';
96
+ $params .= ', ';
97
+ $params .= $bounds[1] != '-' ? (int)$bounds[1] : 'null';
98
+ }
99
+ //$connection->query("CALL `filter_icecat_products_s`($cfid, $catId,0,$cfid, $params)"));
100
+ $tablePrefix = (string)Mage::app()->getConfig()->getTablePrefix();
101
+ $result = $connection->raw_query("CALL ".$this->_getTableName('filter_sinch_products_s')."($cfid, $catId,0, $cfid, $params, '$tablePrefix')");
102
+ Varien_Profiler::stop(__METHOD__);
103
+ return $resultTable;
104
+ }
105
+
106
+
107
+ /**
108
+ * Apply attribute filter to product collection
109
+ *
110
+ * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
111
+ * @param string $value
112
+ * @return Bintime_Icelayered_Model_Resource_Mysql4_Layer_Filter_Feature
113
+ */
114
+ public function applyFilterToCollection($filter, $value)
115
+ {
116
+ Varien_Profiler::start(__METHOD__);
117
+ $searchTable = $this->_prepareSearch($filter, $value);
118
+ self::$lastResultTable = $searchTable;
119
+
120
+ $collection = $filter->getLayer()->getProductCollection();
121
+ $feature = $filter->getAttributeModel();
122
+ $connection = $this->_getReadAdapter();
123
+
124
+ $collection->getSelect()->join(
125
+ $searchTable,
126
+ "{$searchTable}.entity_id = e.entity_id",
127
+ array()
128
+ );
129
+
130
+ Varien_Profiler::stop(__METHOD__);
131
+ return $this;
132
+ }
133
+
134
+ /**
135
+ * Retrieve array with products counts per attribute option
136
+ *
137
+ * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
138
+ * @return array
139
+ */
140
+ public function getCount($filter)
141
+ {
142
+ Varien_Profiler::start(__METHOD__);
143
+
144
+ // clone select from collection with filters
145
+ $select = clone $filter->getLayer()->getProductCollection()->getSelect();
146
+
147
+ // reset columns, order and limitation conditions
148
+ $select->reset(Zend_Db_Select::COLUMNS);
149
+ $select->reset(Zend_Db_Select::ORDER);
150
+ $select->reset(Zend_Db_Select::LIMIT_COUNT);
151
+ $select->reset(Zend_Db_Select::LIMIT_OFFSET);
152
+ $connection = $this->_getReadAdapter();
153
+ $feature = $filter->getAttributeModel();
154
+ $tableAlias = 'idx_' . $feature['category_feature_id'];
155
+
156
+ $conditions = array(
157
+ "{$tableAlias}.entity_id = e.entity_id",
158
+ //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
159
+ );
160
+
161
+ $select->joinInner(
162
+ array($tableAlias => $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id'])),
163
+ join(' AND ', $conditions),
164
+ array('value', 'count' => "COUNT(e.entity_id)")
165
+ )
166
+ ->group("{$tableAlias}.value");
167
+
168
+ $tablePattern = $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id']);
169
+ $query = "SHOW TABLES LIKE '$tablePattern'";
170
+ $featureTables = $connection->fetchCol($query);
171
+ $presentFeatures = array();
172
+ foreach($featureTables as $t) {
173
+ if (preg_match("#$tablePattern#", $t, $matches)) {
174
+ $table_feat_exist=true;
175
+ }
176
+ }
177
+
178
+ Varien_Profiler::stop(__METHOD__);
179
+ if($table_feat_exist){
180
+ return $connection->fetchPairs($select);
181
+ }else{
182
+ return null;
183
+ }
184
+
185
+ }
186
+
187
+ public function getIntervalsCount($filter, $interval)
188
+ {
189
+ Varien_Profiler::start(__METHOD__);
190
+
191
+ // clone select from collection with filters
192
+ $select = clone $filter->getLayer()->getProductCollection()->getSelect();
193
+
194
+ // reset columns, order and limitation conditions
195
+ $select->reset(Zend_Db_Select::COLUMNS);
196
+ $select->reset(Zend_Db_Select::ORDER);
197
+ $select->reset(Zend_Db_Select::LIMIT_COUNT);
198
+ $select->reset(Zend_Db_Select::LIMIT_OFFSET);
199
+
200
+ $connection = $this->_getReadAdapter();
201
+ $feature = $filter->getAttributeModel();
202
+ $tableAlias = 'idx_' . $feature['category_feature_id'];
203
+
204
+ $conditions = array(
205
+ "{$tableAlias}.entity_id = e.entity_id",
206
+ //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
207
+ );
208
+
209
+ $select->joinInner(
210
+ array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
211
+ join(' AND ', $conditions),
212
+ array('count' => "COUNT(e.entity_id)")
213
+ );
214
+ if (isset($interval['low'], $interval['high'])) {
215
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
216
+ }
217
+ else if (isset($interval['low'])) {
218
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
219
+ }
220
+ else if (isset($interval['high'])) {
221
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
222
+ }
223
+ $count = $connection->fetchOne($select);
224
+ Varien_Profiler::stop(__METHOD__);
225
+ return $count;
226
+ }
227
+
228
+ function getIntervalsCountDescending($filter, $interval)
229
+ {
230
+ Varien_Profiler::start(__METHOD__);
231
+
232
+ // clone select from collection with filters
233
+ $select = clone $filter->getLayer()->getProductCollection()->getSelect();
234
+
235
+ // reset columns, order and limitation conditions
236
+ $select->reset(Zend_Db_Select::COLUMNS);
237
+ $select->reset(Zend_Db_Select::ORDER);
238
+ $select->reset(Zend_Db_Select::LIMIT_COUNT);
239
+ $select->reset(Zend_Db_Select::LIMIT_OFFSET);
240
+
241
+ $connection = $this->_getReadAdapter();
242
+ $feature = $filter->getAttributeModel();
243
+ $tableAlias = 'idx_' . $feature['category_feature_id'];
244
+
245
+ $conditions = array(
246
+ "{$tableAlias}.entity_id = e.entity_id",
247
+ //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
248
+ );
249
+
250
+ $select->joinInner(
251
+ array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
252
+ join(' AND ', $conditions),
253
+ array('count' => "COUNT(e.entity_id)")
254
+ );
255
+ if (isset($interval['low'], $interval['high'])) {
256
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
257
+ }
258
+ else if (isset($interval['low'])) {
259
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
260
+ }
261
+ else if (isset($interval['high'])) {
262
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
263
+ }
264
+ $count = $connection->fetchOne($select);
265
+
266
+ Varien_Profiler::stop(__METHOD__);
267
+ return $count;
268
+ }
269
+
270
+
271
+
272
+ /*
273
+ * INDEXES FOLLOW.
274
+ */
275
+
276
+ /**
277
+ * Запускает процедуры индексации.
278
+ * Слушает событие Mage::dispatchEvent('iceimport_model_import_after',..)
279
+ * @param <type> $observer
280
+ */
281
+ public function reindex($observer)
282
+ {
283
+ $this->splitProductsFeature();
284
+ }
285
+
286
+
287
+ /**
288
+ * Разбивает таблицу icecat_product_feature на таблицы вида icecat_product_feature_%category_feature_id% для каждой фичи.
289
+ *
290
+ */
291
+ public function splitProductsFeature()
292
+ {
293
+ Mage::log(__METHOD__ . " start at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
294
+ $featureIds = $this->getProductFeatures4indexig();
295
+
296
+ $resource = Mage::getSingleton('core/resource');
297
+ // $tProudctsFeature = $resource->getTableName("icecat_products_feature");
298
+ $connection = $this->_getWriteAdapter();
299
+
300
+ //удаление таблиц с фичами не используемыми больше для навигации.
301
+ $tablePattern = $resource->getTableName('stINch_products_feature_');
302
+ $query = "SHOW TABLES LIKE '%$tablePattern%'";
303
+ $featureTables = $connection->fetchCol($query);
304
+ $presentFeatures = array();
305
+ foreach($featureTables as $t) {
306
+ if (preg_match("#$tablePattern(\d+)#", $t, $matches)) {
307
+ $presentFeatures[] = $matches[1];
308
+ }
309
+ }
310
+
311
+ $features2delete = array_diff($presentFeatures, $featureIds);
312
+ if (count($features2delete)) {
313
+ foreach ($features2delete as & $drop) {
314
+ $drop = $tablePattern . $drop;
315
+ }
316
+ $dropSql = "DROP TABLE " . implode(',', $features2delete);
317
+ $connection->exec($dropSql);
318
+ }
319
+ //
320
+
321
+ //Создание таблиц с фичами используемыми в навигации.
322
+ $i = 0; $storeId = Mage::app()->getStore()->getId(); $websiteId = Mage::app()->getWebsite()->getId();
323
+ foreach ($featureIds as $featureId) {
324
+ $tFeature = $resource->getTableName("stINch_products_feature_$featureId");
325
+ $query = "DROP TABLE IF EXISTS $tFeature";
326
+ $connection->exec($query);
327
+
328
+ $query = "CREATE TABLE IF NOT EXISTS $tFeature (
329
+ `entity_id` int(11) default NULL,
330
+ `feature_id` int(11) NOT NULL,
331
+ `product_id` int(11) default NULL,
332
+ `category_feature_id` int(11) default NULL,
333
+ `value` text,
334
+ `presentation_value` text,
335
+ INDEX (`feature_id`),
336
+ KEY `category_feature_id` (`category_feature_id`)
337
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8
338
+ ";
339
+ $connection->exec($query);
340
+
341
+ $query = "TRUNCATE TABLE $tFeature";
342
+ $connection->exec($query);
343
+
344
+ /*$query = "
345
+ INSERT INTO $tFeature (feature_id, product_id, category_feature_id, value, presentation_value)
346
+ SELECT feature_id, product_id, category_feature_id, value, presentation_value FROM $tProudctsFeature
347
+ WHERE category_feature_id = $featureId
348
+ ";*/
349
+ $query = "
350
+ REPLACE INTO $tFeature (entity_id,feature_id, product_id, category_feature_id, value, presentation_value)
351
+ SELECT E.entity_id, RV.category_feature_id,E.entity_id, RV.category_feature_id, RV.text , RV.text
352
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." E
353
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." PCind
354
+ ON (E.entity_id = PCind.product_id AND PCind.store_id='{$storeId}' AND PCind.visibility IN(2,4))
355
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
356
+ ON price_index.entity_id = E.entity_id AND price_index.website_id = '{$websiteId}' AND price_index.customer_group_id = 0
357
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." PR
358
+ ON (PR.store_product_id = E.store_product_id)
359
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." PF
360
+ ON (PR.sinch_product_id = PF.sinch_product_id )
361
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." RV
362
+ ON (PF.restricted_value_id=RV.restricted_value_id AND RV.category_feature_id= $featureId)
363
+ GROUP BY E.entity_id;
364
+ ";
365
+ $connection->exec($query);
366
+ }
367
+ Mage::log(__METHOD__ . " end at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
368
+ }
369
+
370
+ /**
371
+ * Список фич подлежащих индексации.
372
+ *
373
+ * @return array
374
+ */
375
+ private function getProductFeatures4indexig()
376
+ {
377
+ $connection = $this->_getReadAdapter();
378
+
379
+ $tCatFeature = Mage::getSingleton('core/resource')->getTableName('stINch_categories_features');
380
+ $query = "SELECT category_feature_id FROM $tCatFeature ";
381
+
382
+ return $connection->fetchCol($query);
383
+ }
384
+ }
app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Setup.php CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
- class Bintime_Sinchimport_Model_Resource_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup{
3
- }
4
- ?>
1
+ <?php
2
+ class Bintime_Sinchimport_Model_Resource_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup{
3
+ }
4
+ ?>
app/code/local/Bintime/Sinchimport/Model/Sinch.php CHANGED
@@ -1,9939 +1,9939 @@
1
- <?php
2
-
3
- ini_set('memory_limit','256M');
4
- $dir = Mage::getBaseDir('code')."/local/Bintime/Sinchimport/Model";//dirname(__FILE__);
5
- require_once ($dir.'/config.php');
6
-
7
- class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
8
- var
9
- $connection,
10
- $varDir,
11
- $shellDir,
12
- $files,
13
- $attributes,
14
- $db,
15
- $lang_id,
16
- $debug_mode=1;
17
- private $productDescriptionList = array();
18
- private $specifications;
19
- private $productDescription;
20
- private $fullProductDescription;
21
- private $lowPicUrl;
22
- private $highPicUrl;
23
- private $errorMessage;
24
- private $galleryPhotos = array();
25
- private $productName;
26
- private $relatedProducts = array();
27
- private $errorSystemMessage; //depricated
28
- private $sinchProductId;
29
- private $_productEntityTypeId = 0;
30
- private $defaultAttributeSetId = 0;
31
- private $field_terminated_char;
32
- private $import_status_table;
33
- private $import_status_statistic_table;
34
- private $current_import_status_statistic_id;
35
- private $import_log_table;
36
- private $_attributeId;
37
- private $_categoryEntityTypeId;
38
- private $_categoryDefault_attribute_set_id;
39
- private $_root_cat;
40
- private $import_run_type = 'MANUAL';
41
- private $_ignore_category_features = false;
42
- private $_ignore_product_features = false;
43
- private $_ignore_product_related = false;
44
- private $_ignore_product_categories = false;
45
- private $_ignore_price_rules = false;
46
- private $product_file_format = "NEW";
47
- private $_ignore_restricted_values = false;
48
- private $_categoryMetaTitleAttrId;
49
- private $_categoryMetadescriptionAttrId;
50
- private $_categoryDescriptionAttrId;
51
-
52
-
53
- public $php_run_string;
54
- public $php_run_strings;
55
-
56
- public $price_breaks_filter;
57
-
58
- private $im_type;
59
-
60
- #################################################################################################
61
-
62
- function __construct(){
63
-
64
- $this->import_status_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status');
65
- $this->import_status_statistic_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic');
66
- $this->import_log_table="stINch_import_log";
67
-
68
- $this->php_run_string=PHP_RUN_STRING;
69
- $this->php_run_strings=PHP_RUN_STRINGS;
70
-
71
- $this->price_breaks_filter=PRICE_BREAKS;
72
- /*$this->db_connect();
73
- $res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
74
- $row = mysqli_fetch_assoc($res);
75
- $this->lang_id = $row['languages_id'];
76
- */
77
- $this->varDir = TEMPORARY_DIRECTORY_FOR_STORING_FILES;
78
- $this->shellDir = SHELL_DIRECTORY_FOR_INDEXER;
79
- $this->connection=$this->db_connect();
80
- $this->createTemporaryImportDerictory();
81
- $this->_logFile="Sinch.log";
82
- $this->_LOG("constructor");
83
- $this->files=array(
84
- FILE_CATEGORIES,
85
- FILE_CATEGORY_TYPES,
86
- FILE_CATEGORIES_FEATURES,
87
- FILE_DISTRIBUTORS,
88
- FILE_DISTRIBUTORS_STOCK_AND_PRICES,
89
- FILE_EANCODES,
90
- FILE_MANUFACTURERS,
91
- FILE_PRODUCT_FEATURES,
92
- FILE_PRODUCT_CATEGORIES,
93
- FILE_PRODUCTS,
94
- FILE_RELATED_PRODUCTS,
95
- FILE_RESTRICTED_VALUES,
96
- FILE_STOCK_AND_PRICES,
97
- FILE_PRODUCTS_PICTURES_GALLERY,
98
- FILE_PRICE_RULES
99
- );
100
- $this->attributes['manufacturer']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
101
- $this->attributes['name']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
102
- $this->attributes['is_active']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('is_active')->getFirstItem()->getId();
103
- $this->attributes['include_in_menu']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('include_in_menu')->getFirstItem()->getId();
104
- $this->attributes['url_key']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('url_key')->getFirstItem()->getId();
105
- $this->attributes['display_mode']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('display_mode')->getFirstItem()->getId();
106
- $this->attributes['status']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('status')->getFirstItem()->getId();
107
- $this->attributes['visibility']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('visibility')->getFirstItem()->getId();
108
- $this->attributes['price']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('price')->getFirstItem()->getId();
109
- $this->attributes['cost']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('cost')->getFirstItem()->getId();
110
- $this->attributes['weight']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('weight')->getFirstItem()->getId();
111
- $this->attributes['tax_class_id']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('tax_class_id')->getFirstItem()->getId();
112
-
113
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
114
- // if($dataConf['field_terminated_char']){
115
- // $this->field_terminated_char=$dataConf['field_terminated_char'];
116
- // }else{
117
- $this->field_terminated_char=DEFAULT_FILE_TERMINATED_CHAR;
118
- // }
119
- // $attributeOptions = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getSource()->getAllOptions(false);
120
- // echo "<pre>"; print_r($attributeOptions); echo "</pre>";
121
- }
122
-
123
- #################################################################################################
124
- function cron_start_import(){
125
- $this->_LOG("Start import from cron");
126
- $start_hr=Mage::getStoreConfig('sinchimport_root/sinch_cron/sinch_cron_time');
127
- $now_hr=date('H');
128
- $this->_LOG("Now $now_hr hr, scheduler time is $start_hr hr");
129
-
130
- if($start_hr==$now_hr){
131
- $this->run_sinch_import();
132
- }else{
133
- $this->_LOG(" it's NOT time for SINCH ");
134
- }
135
-
136
- $this->_LOG("Finish import from cron");
137
-
138
- }
139
- ################################################################################################
140
- function cron_start_full_import(){
141
- $this->import_run_type='CRON';
142
- $this->run_sinch_import();
143
- }
144
- ################################################################################################
145
- function cron_start_stock_price_import(){
146
- $this->import_run_type='CRON';
147
- $this->run_stock_price_sinch_import();
148
- }
149
- #################################################################################################
150
- function is_imort_not_run(){
151
- $q="SELECT IS_FREE_LOCK('sinchimport') as getlock";
152
- $quer=$this->db_do($q);
153
- $row=mysqli_fetch_array($quer);
154
- return $row['getlock'];
155
- }
156
- #################################################################################################
157
- function check_store_procedure_exist(){
158
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
159
- $q='SHOW PROCEDURE STATUS LIKE "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'"';
160
- $quer=$this->db_do($q);
161
- $result=false;
162
- While($row=mysqli_fetch_array($quer)){
163
- if(($row['Name']==Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s')) && ($row['Db']==$dbConf->dbname)){
164
- $result = true;
165
- }
166
- }
167
- return $result;
168
- }
169
- #################################################################################################
170
- function check_db_privileges(){
171
- $q='SHOW PRIVILEGES';
172
- $quer=$this->db_do($q);
173
- while($row=mysqli_fetch_array($quer)){
174
- if($row['Privilege']=='File' && $row['Context']=='File access on server'){
175
- return true;
176
- }
177
- }
178
- return false;
179
- }
180
- #################################################################################################
181
- function check_local_infile(){
182
- $q='SHOW VARIABLES LIKE "local_infile"';
183
- $quer=$this->db_do($q);
184
- $row=mysqli_fetch_array($quer);
185
- if($row['Variable_name']=='local_infile' && $row['Value']=="ON"){
186
- return true;
187
- }else{
188
- return false;
189
- }
190
- }
191
- #################################################################################################
192
- function is_full_import_have_been_run(){
193
- $q="SELECT COUNT(*) AS cnt
194
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic')."
195
- WHERE import_type='FULL' AND global_status_import='Successful'";
196
- $quer=$this->db_do($q);
197
- $row=mysqli_fetch_array($quer);
198
- if($row['cnt']>0){
199
- return true;
200
- }else{
201
- return false;
202
- }
203
- }
204
- #################################################################################################
205
- function run_sinch_import(){
206
-
207
- $this->_categoryMetaTitleAttrId = $this->_getCategoryAttributeId('meta_title');
208
- $this->_categoryMetadescriptionAttrId = $this->_getCategoryAttributeId('meta_description');
209
- $this->_categoryDescriptionAttrId = $this->_getCategoryAttributeId('description');
210
-
211
- $safe_mode_set = ini_get('safe_mode');
212
-
213
- $this->InitImportStatuses('FULL');
214
- if($safe_mode_set ){
215
- $this->_LOG('safe_mode is enable. import stoped.');
216
- $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
217
- exit;
218
- }
219
- $store_proc=$this->check_store_procedure_exist();
220
-
221
- if(!$store_proc){
222
- $this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
223
- $this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
224
- exit;
225
- }
226
-
227
- $file_privileg=$this->check_db_privileges();
228
-
229
- if(!$file_privileg){
230
- $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
231
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
232
- exit;
233
- }
234
- $local_infile=$this->check_local_infile();
235
- if(!$local_infile){
236
- $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. Add this string to 'set-variable=local-infile=0' in '/etc/my.cnf'");
237
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
238
- exit;
239
- }
240
- //STP TEST
241
- //$this->ApplyCustomerGroupPrice();
242
- //echo $children_cat=$this->get_all_children_cat(6);
243
-
244
-
245
-
246
- if($this->is_imort_not_run()){
247
- try{
248
- //$this->InitImportStatuses();
249
- $q="SELECT GET_LOCK('sinchimport', 30)";
250
- $quer=$this->db_do($q);
251
- $import=$this;
252
- $import->addImportStatus('Start Import');
253
- echo "Upload Files <br>";
254
- $import->UploadFiles();
255
- $import->addImportStatus('Upload Files');
256
-
257
- echo "Parse Category Types <br>";
258
- $import->ParseCategoryTypes();
259
-
260
- echo "Parse Categories <br>";
261
- $coincidence = $import->ParseCategories();
262
- $import->addImportStatus('Parse Categories');
263
-
264
-
265
- //$import->_cleanCateoryProductFlatTable();
266
- //$import->runIndexer();
267
- //echo("\n\n\n==================RETURN=================\n\n\n");
268
-
269
-
270
- echo "Parse Category Features <br>";
271
- $import->ParseCategoryFeatures();
272
- $import->addImportStatus('Parse Category Features');
273
-
274
-
275
- echo "Parse Distributors <br>";
276
- $import->ParseDistributors();
277
- if($this->product_file_format == "NEW"){
278
- $this->ParseDistributorsStockAndPrice();
279
- }
280
- $import->addImportStatus('Parse Distributors');
281
-
282
- echo "Parse EAN Codes <br>";
283
- $import->ParseEANCodes();
284
- $import->addImportStatus('Parse EAN Codes');
285
-
286
-
287
- echo "Parse Manufacturers <br>";
288
- $import->ParseManufacturers();
289
- $import->addImportStatus('Parse Manufacturers');
290
-
291
- echo "Parse Related Products <br>";
292
- $import->ParseRelatedProducts();
293
- $import->addImportStatus('Parse Related Products');
294
-
295
-
296
-
297
- echo "Parse Product Features <br>";
298
- $import->ParseProductFeatures();
299
- $import->addImportStatus('Parse Product Features');
300
-
301
- echo "Parse Product Categories <br>";
302
- $import->ParseProductCategories();
303
-
304
- echo "Parse Products <br>";
305
- $import->ParseProducts($coincidence);
306
- $import->addImportStatus('Parse Products');
307
-
308
- //echo("\n\n\n\n ##################################### \n\n\n\n"); return;
309
- //
310
-
311
- echo "Parse Pictures Gallery";
312
- $import->ParseProductsPicturesGallery();
313
- $import->addImportStatus('Parse Pictures Gallery');
314
-
315
-
316
- echo "Parse Restricted Values <br>";
317
- $import->ParseRestrictedValues();
318
- $import->addImportStatus('Parse Restricted Values');
319
-
320
- echo "Parse Stock And Prices <br>";
321
- $import->ParseStockAndPrices();
322
- $import->addImportStatus('Parse Stock And Prices');
323
-
324
- echo "Apply Customer Group Price <br>";
325
- //$import->ParsePriceRules();
326
- //$import->AddPriceRules();
327
- //$import->ApplyCustomerGroupPrice();
328
-
329
- if(file_exists($this->varDir.FILE_PRICE_RULES)){
330
- $ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
331
- Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
332
- 'ftp_host' => $ftpCred["ftp_server"],
333
- 'ftp_username' => $ftpCred["login"],
334
- 'ftp_password' => $ftpCred["password"]
335
- ));
336
- }
337
-
338
-
339
- Mage::log("Finish Sinch import", null, $this->_logFile);
340
- echo "Finish Sinch import<br>";
341
-
342
- Mage::log("Start cleanin Sinch cache<br>", null, $this->_logFile);
343
- echo "Start cleanin Sinch cache<br>";
344
- Mage::app()->getCacheInstance()->cleanType('block_html');
345
- /*
346
- $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
347
- if ($indexProcess) {
348
- $indexProcess->reindexAll();
349
- }
350
- */
351
-
352
- Mage::log("Start indexing Sinch features for filters", null, $this->_logFile);
353
- echo "Start indexing Sinch features for filters<br>";
354
-
355
-
356
- $resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
357
- $resource->splitProductsFeature(null);
358
-
359
- Mage::log("Finish indexing Sinch features for filters", null, $this->_logFile);
360
- $import->addImportStatus('Generate category filters');
361
- echo "Finish indexing Sinch features for filters<br>";
362
-
363
-
364
- Mage::log("Start indexing data", null, $this->_logFile);
365
- echo "Start indexing data";
366
- $import->_cleanCateoryProductFlatTable();
367
- $import->runIndexer();
368
- Mage::log("Finish indexing data", null, $this->_logFile);
369
- $import->addImportStatus('Indexing data', 1);
370
- echo "Finish indexing data";
371
-
372
- $q="SELECT RELEASE_LOCK('sinchimport')";
373
- $quer=$this->db_do($q);
374
- }catch (Exception $e) {
375
- $this->set_import_error_reporting_message($e);
376
- }
377
- }
378
- else{
379
- Mage::log("Sinchimport already run", null, $this->_logFile);
380
- echo "Sinchimport already run<br>";
381
-
382
- }
383
-
384
- }
385
- #################################################################################################
386
- function run_stock_price_sinch_import(){
387
- $safe_mode_set = ini_get('safe_mode');
388
-
389
- $this->InitImportStatuses('PRICE STOCK');
390
- if($safe_mode_set ){
391
- $this->_LOG('safe_mode is enable. import stoped.');
392
- $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
393
- exit;
394
- }
395
- $store_proc=$this->check_store_procedure_exist();
396
-
397
- if(!$store_proc){
398
- $this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
399
- $this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
400
- exit;
401
- }
402
-
403
- $file_privileg=$this->check_db_privileges();
404
-
405
- if(!$file_privileg){
406
- $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
407
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
408
- exit;
409
- }
410
- $local_infile=$this->check_local_infile();
411
- if(!$local_infile){
412
- $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. Add this string to 'set-variable=local-infile=0' in '/etc/my.cnf'");
413
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
414
- exit;
415
- }
416
-
417
- if($this->is_imort_not_run() && $this->is_full_import_have_been_run()){
418
- try{
419
- //$this->InitImportStatuses();
420
- $q="SELECT GET_LOCK('sinchimport', 30)";
421
- $quer=$this->db_do($q);
422
- $import=$this;
423
- $import->addImportStatus('Stock Price Start Import');
424
- echo "Upload Files <br>";
425
- $this->files=array(
426
- FILE_STOCK_AND_PRICES,
427
- FILE_PRICE_RULES
428
- );
429
-
430
- $import->UploadFiles();
431
- $import->addImportStatus('Stock Price Upload Files');
432
-
433
- echo "Parse Stock And Prices <br>";
434
- //exit;
435
- $import->ParseStockAndPrices();
436
- $import->addImportStatus('Stock Price Parse Products');
437
-
438
- echo "Apply Customer Group Price <br>";
439
- //$import->ParsePriceRules();
440
- //$import->AddPriceRules();
441
- //$import->ApplyCustomerGroupPrice();
442
-
443
- $ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
444
- Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
445
- 'ftp_host' => $ftpCred["ftp_server"],
446
- 'ftp_username' => $ftpCred["login"],
447
- 'ftp_password' => $ftpCred["password"]
448
- ));
449
-
450
-
451
- Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
452
- echo "Finish Stock & Price Sinch import<br>";
453
-
454
- Mage::log("Start indexing Stock & Price", null, $this->_logFile);
455
- echo "Start indexing Stock & Price<br>";
456
- $import->_cleanCateoryProductFlatTable();
457
- $import->runStockPriceIndexer();
458
- Mage::log("Finish indexing Stock & Price", null, $this->_logFile);
459
- $import->addImportStatus('Stock Price Indexing data');
460
- $import->addImportStatus('Stock Price Finish import', 1);
461
- echo "Finish indexing Stock & Price<br>";
462
-
463
- $q="SELECT RELEASE_LOCK('sinchimport')";
464
- $quer=$this->db_do($q);
465
- }catch (Exception $e) {
466
- $this->set_import_error_reporting_message($e);
467
- }
468
- }
469
- else{
470
- if(!$this->is_imort_not_run()){
471
- Mage::log("Sinchimport already run", null, $this->_logFile);
472
- echo "Sinchimport already run<br>";
473
- }else{
474
- Mage::log("Full import have never finished with success", null, $this->_logFile);
475
- echo "Full import have never finished with success<br>";
476
- }
477
- }
478
-
479
- }
480
- #################################################################################################
481
-
482
-
483
- function UploadFiles(){
484
-
485
- $this->_LOG("Start upload files");
486
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
487
- $login=$dataConf['login'];
488
- $passw=$dataConf['password'];
489
- $server=$dataConf['ftp_server'];
490
-
491
- //return;//stepan tes//stepan tes//stepan testtt
492
- if(!$login || !$passw){
493
- $this->_LOG('ftp login or password dosent defined');
494
- $this->set_import_error_reporting_message('FTP login or password has not been defined. Import stopped.');
495
- exit;
496
-
497
- }
498
- $file_url_and_dir=$this->repl_ph(FILE_URL_AND_DIR, array(
499
- 'server' => $server,
500
- 'login' => $login,
501
- 'password'=> $passw
502
- )
503
- );
504
- foreach ($this->files as $file) {
505
- $this->_LOG("Copy ".$file_url_and_dir.$file." to ".$this->varDir.$file);
506
- if(strstr($file_url_and_dir, 'ftp://')){
507
- preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
508
- //var_dump($match);
509
- if($conn = ftp_connect($match[3])){
510
- if(!ftp_login($conn, $login, $passw))
511
- {
512
- $this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
513
- exit;
514
- }
515
- }
516
- else{
517
- $this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
518
- exit;
519
- }
520
- if (!$this->wget ($file_url_and_dir.$file, $this->varDir.$file, 'system')){
521
- $this->_LOG("wget Can't copy ".$file.", will use old one");
522
- echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file.", will use old one<br>";
523
- }
524
- }
525
- else{
526
- if(!copy($file_url_and_dir.$file, $this->varDir.$file)){
527
- $this->_LOG("copy Can't copy ".$file.", will use old one");
528
- echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file." will use old one<br>";
529
- }
530
- }
531
- exec("chmod a+rw ".$this->varDir.$file);
532
- if(!filesize($this->varDir.$file)){
533
- if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES && $file!=FILE_PRODUCT_CATEGORIES && $file !=FILE_CATEGORY_TYPES && $file != FILE_DISTRIBUTORS_STOCK_AND_PRICES && $file != FILE_PRICE_RULES){
534
- $this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
535
- $this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
536
- $this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
537
-
538
- exit;
539
- }else{
540
- if($file==FILE_CATEGORIES_FEATURES){
541
- $this->_LOG("Can't copy ".FILE_CATEGORIES_FEATURES." file ignored" );
542
- $this->_ignore_category_features=true;
543
- }elseif($file==FILE_PRODUCT_FEATURES){
544
- $this->_LOG("Can't copy ".FILE_PRODUCT_FEATURES." file ignored" );
545
- $this->_ignore_product_features=true;
546
- }elseif($file==FILE_RELATED_PRODUCTS){
547
- $this->_LOG("Can't copy ".FILE_RELATED_PRODUCTS." file ignored" );
548
- $this->_ignore_product_related=true;
549
- }elseif($file==FILE_RESTRICTED_VALUES){
550
- $this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
551
- $this->_ignore_restricted_values=true;
552
- }elseif($file==FILE_PRODUCT_CATEGORIES){
553
- $this->_LOG("Can't copy ".FILE_PRODUCT_CATEGORIES." file ignored" );
554
- $this->_ignore_product_categories=true;
555
- $this->product_file_format = "OLD";
556
- }elseif($file==FILE_CATEGORY_TYPES){
557
- $this->_LOG("Can't copy ".FILE_CATEGORY_TYPES." file ignored" );
558
- $this->_ignore_category_types=true;
559
- }elseif($file==FILE_DISTRIBUTORS_STOCK_AND_PRICES){
560
- $this->_LOG("Can't copy ".FILE_DISTRIBUTORS_STOCK_AND_PRICES." file ignored" );
561
- $this->_ignore_category_types=true;
562
- }elseif($file==FILE_PRICE_RULES){
563
- $this->_LOG("Can't copy ".FILE_PRICE_RULES." file ignored" );
564
- $this->_ignore_price_rules=true;
565
- }
566
-
567
- }
568
- }
569
- }
570
- if (file_exists($file_url_and_dir.FILE_PRODUCT_CATEGORIES)){
571
- $this->product_file_format = "NEW";
572
- $this->_LOG("File ".$file_url_and_dir.FILE_PRODUCT_CATEGORIES." exist. Will used parser for NEW format product.csv" );
573
- }else{
574
- $this->product_file_format = "OLD";
575
- $this->_LOG("File ".$file_url_and_dir.FILE_PRODUCT_CATEGORIES." dosen't exist. Will used parser for OLD format product.csv" );
576
- }
577
- $this->_LOG("Finish upload files");
578
- }
579
- #################################################################################################
580
-
581
-
582
-
583
- ################################################################################################################################################################
584
- function ParseCategories()
585
- {
586
-
587
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
588
- $im_type = $dataConf['replace_category'];
589
- $parse_file = $this->varDir.FILE_CATEGORIES;
590
- $field_terminated_char = $this->field_terminated_char;
591
-
592
- $this->im_type = $im_type;
593
-
594
- if(filesize($parse_file))
595
- {
596
- $this->_LOG("Start parse ".FILE_CATEGORIES);
597
-
598
- $this->_getCategoryEntityTypeIdAndDefault_attribute_set_id();
599
-
600
- $categories_temp = Mage::getSingleton('core/resource')->getTableName('categories_temp');
601
- $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
602
- $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
603
- $catalog_category_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int');
604
- $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
605
- $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
606
- $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
607
- $category_types = Mage::getSingleton('core/resource')->getTableName('stINch_category_types');
608
-
609
- $_categoryEntityTypeId = $this->_categoryEntityTypeId;
610
- $_categoryDefault_attribute_set_id = $this->_categoryDefault_attribute_set_id;
611
-
612
- $name_attrid = $this->_getCategoryAttributeId('name');
613
- $is_anchor_attrid = $this->_getCategoryAttributeId('is_anchor');
614
- $image_attrid = $this->_getCategoryAttributeId('image');
615
-
616
-
617
-
618
-
619
- $attr_url_key = $this->attributes['url_key'];
620
- $attr_display_mode = $this->attributes['display_mode'];
621
- $attr_is_active = $this->attributes['is_active'];
622
- $attr_include_in_menu = $this->attributes['include_in_menu'];
623
-
624
-
625
- $this->loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char);
626
- $coincidence = $this->calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type, $category_types);
627
-
628
- /**/
629
- if (!$this->check_loaded_data($parse_file, $categories_temp))
630
- {
631
- $inf = mysqli_info();
632
- $this->set_import_error_reporting_message('The Stock In The Channel data files do not appear to be in the correct format. Check file'.$parse_file. "(LOAD DATA ... ".$inf.")");
633
- exit;
634
- }/**/
635
-
636
-
637
- echo("\n\ncoincidence = [".count($coincidence)."]\n\n");
638
-
639
- if (count($coincidence) == 1) // one store logic
640
- {
641
- echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
642
- if ($im_type == "REWRITE")
643
- {
644
- $root_cat = 2;
645
-
646
- $root_cat = $this->truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
647
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
648
- $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu); // return $root_cat
649
- }
650
- else // if ($im_type == "MERGE")
651
- {
652
- $root_cat = $this->_getShopRootCategoryId();
653
- }
654
-
655
- $this->_root_cat = $root_cat;
656
-
657
- $this->setCategorySettings($categories_temp, $root_cat);
658
- $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
659
- $this->addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
660
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat);
661
- }
662
- else if (count($coincidence) > 1) // multistore logic
663
- {
664
- echo("\n\n\n====================================\nmultistore logic\n====================================\n\n\n");
665
- switch ($im_type)
666
- {
667
- case "REWRITE": $this->rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
668
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
669
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
670
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
671
- break;
672
- case "MERGE" : $this->mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
673
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
674
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
675
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
676
- break;
677
- default : $retcode = "error";
678
- };
679
- }
680
- else
681
- {
682
- echo("error");
683
- }
684
-
685
- $this->_LOG("Finish parse ".FILE_CATEGORIES);
686
- }
687
- else
688
- {
689
- $this->_LOG("Wrong file ".$parse_file);
690
- }
691
- $this->_LOG(' ');
692
- $this->_set_default_root_category();
693
- return $coincidence;
694
- } // function ParseCategories()
695
- ################################################################################################################################################################
696
-
697
-
698
-
699
-
700
-
701
-
702
- ################################################################################################################################################################
703
- private function loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char)
704
- {
705
- $this->db_do("DROP TABLE IF EXISTS $categories_temp");
706
-
707
-
708
- /** OLD !!!*
709
- $this->db_do("CREATE TABLE $categories_temp (
710
- store_category_id int(11),
711
- parent_store_category_id int(11),
712
- category_name varchar(50),
713
- order_number int(11),
714
- is_hidden boolean,
715
- products_within_this_category int(11),
716
- products_within_sub_categories int(11),
717
- categories_image varchar(255),
718
- level int(10) NOT NULL default 0,
719
- children_count int(11) NOT NULL default 0,
720
- KEY(store_category_id),
721
- KEY(parent_store_category_id)
722
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
723
- ");
724
- /**/
725
-
726
- /** NEW !!! */
727
- $this->db_do("
728
- CREATE TABLE $categories_temp
729
- (
730
- store_category_id INT(11),
731
- parent_store_category_id INT(11),
732
- category_name VARCHAR(50),
733
- order_number INT(11),
734
- is_hidden VARCHAR(10),
735
- products_within_sub_categories INT(11),
736
- products_within_this_category INT(11),
737
- categories_image VARCHAR(255),
738
- level INT(10) NOT NULL DEFAULT 0,
739
- children_count INT(11) NOT NULL DEFAULT 0,
740
- UNSPSC INT(10) DEFAULT NULL,
741
- RootName INT(10) DEFAULT NULL,
742
- MainImageURL VARCHAR(255),
743
- MetaTitle TEXT,
744
- MetaDescription TEXT,
745
- Description TEXT,
746
- KEY(store_category_id),
747
- KEY(parent_store_category_id)
748
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
749
- /**/
750
-
751
- $this->db_do("
752
- LOAD DATA LOCAL INFILE '$parse_file' INTO TABLE $categories_temp
753
- FIELDS TERMINATED BY '$field_terminated_char' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES");
754
-
755
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN include_in_menu TINYINT(1) NOT NULL DEFAULT 1");
756
- $this->db_do("UPDATE $categories_temp SET include_in_menu = 0 WHERE UCASE(is_hidden)='TRUE'");
757
-
758
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN is_anchor TINYINT(1) NOT NULL DEFAULT 1");
759
- $this->db_do("UPDATE $categories_temp SET level = (level+2) WHERE level >= 0");
760
- # $this->db_do("UPDATE $categories_temp SET is_anchor = 0 WHERE level > 0");
761
-
762
-
763
-
764
- /** FOR TEST !!! *
765
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN UNSPSC INT(10) NOT NULL DEFAULT 0");
766
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN RootName VARCHAR(50) NOT NULL DEFAULT 0");
767
-
768
- //$this->db_do("UPDATE $categories_temp SET RootName = '3'"); // one store logic test
769
-
770
- $this->db_do("UPDATE $categories_temp SET RootName = 'KAMERY' WHERE store_category_id IN (93530, 93531, 93230, 93231, 175559, 175687)");
771
- $this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
772
- $this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553, 93530, 93531, 93230, 93231, 175559, 175687)");
773
-
774
-
775
- //$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
776
- //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553)");
777
-
778
-
779
- //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id IN (175687, 175553)"); // OLD CATS...//
780
-
781
- /**/
782
- } // private function loadCategoriesTemp()
783
- ################################################################################################################################################################
784
-
785
-
786
-
787
- ################################################################################################################################################################
788
- private function mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
789
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
790
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
791
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
792
- {
793
- echo("mergeMultistoreCategories RUN\n");
794
-
795
-
796
-
797
- $this->createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
798
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
799
-
800
-
801
-
802
- $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
803
-
804
-
805
- $this->addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
806
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
807
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
808
-
809
-
810
-
811
- echo("\n\n\nmergeMultistoreCategories DONE\n");
812
- }
813
- ################################################################################################################################################################
814
-
815
-
816
-
817
-
818
-
819
-
820
- ################################################################################################################################################################
821
- private function addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
822
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
823
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
824
- {
825
- echo("\n\n\n\n *************************************************************\n addCategoryDataMultistoreMerge start... \n");
826
-
827
-
828
- if (UPDATE_CATEGORY_DATA)
829
- {
830
- $ignore = '';
831
- $on_diplicate_key_update = "
832
- ON DUPLICATE KEY UPDATE
833
- updated_at = now(),
834
- store_category_id = c.store_category_id,
835
- level = c.level,
836
- children_count = c.children_count,
837
- position = c.order_number,
838
- parent_store_category_id = c.parent_store_category_id";
839
- //level=c.level,
840
- //children_count=c.children_count
841
- //position=c.order_number,
842
- }
843
- else
844
- {
845
- $ignore = 'IGNORE';
846
- $on_diplicate_key_update = '';
847
- }
848
-
849
- $query = "
850
- INSERT $ignore INTO $catalog_category_entity
851
- (
852
- entity_type_id,
853
- attribute_set_id,
854
- created_at,
855
- updated_at,
856
- level,
857
- children_count,
858
- entity_id,
859
- position,
860
- parent_id,
861
- store_category_id,
862
- parent_store_category_id
863
- )
864
- (SELECT
865
- $_categoryEntityTypeId,
866
- $_categoryDefault_attribute_set_id,
867
- NOW(),
868
- NOW(),
869
- c.level,
870
- c.children_count,
871
- scm.shop_entity_id,
872
- c.order_number,
873
- scm.shop_parent_id,
874
- c.store_category_id,
875
- c.parent_store_category_id
876
- FROM $categories_temp c
877
- LEFT JOIN $stINch_categories_mapping scm
878
- ON c.store_category_id = scm.store_category_id
879
- ) $on_diplicate_key_update";
880
- echo("\n\n $query\n\n");
881
- $this->db_do($query);
882
-
883
-
884
-
885
-
886
-
887
-
888
-
889
- $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
890
-
891
-
892
-
893
-
894
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
895
- while ($row = mysqli_fetch_array($categories))
896
- {
897
- $parent_id = $row['parent_id'];
898
- $entity_id = $row['entity_id'];
899
-
900
- $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
901
-
902
- $this->db_do("
903
- UPDATE $catalog_category_entity
904
- SET path = '$path'
905
- WHERE entity_id = $entity_id");
906
- } // while ($row = mysqli_fetch_array($categories))
907
-
908
-
909
-
910
- ///////////////////////////////////////////////////////
911
-
912
-
913
- if(UPDATE_CATEGORY_DATA)
914
- {
915
- echo "Update category_data \n";
916
-
917
- $q = "
918
- INSERT INTO $catalog_category_entity_varchar
919
- (
920
- entity_type_id,
921
- attribute_id,
922
- store_id,
923
- entity_id,
924
- value
925
- )
926
- (SELECT
927
- $_categoryEntityTypeId,
928
- $name_attrid,
929
- 0,
930
- scm.shop_entity_id,
931
- c.category_name
932
- FROM $categories_temp c
933
- JOIN $stINch_categories_mapping scm
934
- ON c.store_category_id = scm.store_category_id
935
- )
936
- ON DUPLICATE KEY UPDATE
937
- value = c.category_name";
938
- $this->db_do($q);
939
-
940
-
941
- $q = "
942
- INSERT INTO $catalog_category_entity_varchar
943
- (
944
- entity_type_id,
945
- attribute_id,
946
- store_id,
947
- entity_id,
948
- value
949
- )
950
- (SELECT
951
- $_categoryEntityTypeId,
952
- $name_attrid,
953
- 1,
954
- scm.shop_entity_id,
955
- c.category_name
956
- FROM $categories_temp c
957
- JOIN $stINch_categories_mapping scm
958
- ON c.store_category_id = scm.store_category_id
959
- )
960
- ON DUPLICATE KEY UPDATE
961
- value = c.category_name";
962
- $this->db_do($q);
963
-
964
-
965
- $q = "
966
- INSERT INTO $catalog_category_entity
967
- (
968
- entity_type_id,
969
- attribute_id,
970
- store_id,
971
- entity_id,
972
- value
973
- )
974
- (SELECT
975
- $_categoryEntityTypeId,
976
- $attr_is_active,
977
- 0,
978
- scm.shop_entity_id,
979
- 1
980
- FROM $categories_temp c
981
- JOIN $stINch_categories_mapping scm
982
- ON c.store_category_id = scm.store_category_id
983
- )
984
- ON DUPLICATE KEY UPDATE
985
- value = 1";
986
- $this->db_do($q);
987
-
988
-
989
- $q = "
990
- INSERT INTO $catalog_category_entity_int
991
- (
992
- entity_type_id,
993
- attribute_id,
994
- store_id,
995
- entity_id,
996
- value
997
- )
998
- (SELECT
999
- $_categoryEntityTypeId,
1000
- $attr_is_active,
1001
- 1,
1002
- scm.shop_entity_id,
1003
- 1
1004
- FROM $categories_temp c
1005
- JOIN $stINch_categories_mapping scm
1006
- ON c.store_category_id = scm.store_category_id
1007
- )
1008
- ON DUPLICATE KEY UPDATE
1009
- value = 1";
1010
- $this->db_do($q);
1011
-
1012
-
1013
- $q = "
1014
- INSERT INTO $catalog_category_entity_int
1015
- (
1016
- entity_type_id,
1017
- attribute_id,
1018
- store_id,
1019
- entity_id,
1020
- value
1021
- )
1022
- (SELECT
1023
- $_categoryEntityTypeId,
1024
- $attr_include_in_menu,
1025
- 0,
1026
- scm.shop_entity_id,
1027
- c.include_in_menu
1028
- FROM $categories_temp c
1029
- JOIN $stINch_categories_mapping scm
1030
- ON c.store_category_id = scm.store_category_id
1031
- )
1032
- ON DUPLICATE KEY UPDATE
1033
- value = c.include_in_menu";
1034
- $this->db_do($q);
1035
-
1036
-
1037
- $q = "
1038
- INSERT INTO $catalog_category_entity_int
1039
- (
1040
- entity_type_id,
1041
- attribute_id,
1042
- store_id,
1043
- entity_id,
1044
- value
1045
- )
1046
- (SELECT
1047
- $_categoryEntityTypeId,
1048
- $is_anchor_attrid,
1049
- 1,
1050
- scm.shop_entity_id,
1051
- c.is_anchor
1052
- FROM $categories_temp c
1053
- JOIN $stINch_categories_mapping scm
1054
- ON c.store_category_id = scm.store_category_id
1055
- )
1056
- ON DUPLICATE KEY UPDATE
1057
- value = c.is_anchor";
1058
- $this->db_do($q);
1059
-
1060
-
1061
- $q = "
1062
- INSERT INTO $catalog_category_entity_int
1063
- (
1064
- entity_type_id,
1065
- attribute_id,
1066
- store_id,
1067
- entity_id,
1068
- value
1069
- )
1070
- (SELECT
1071
- $_categoryEntityTypeId,
1072
- $is_anchor_attrid,
1073
- 0,
1074
- scm.shop_entity_id,
1075
- c.is_anchor
1076
- FROM $categories_temp c
1077
- JOIN $stINch_categories_mapping scm
1078
- ON c.store_category_id = scm.store_category_id
1079
- )
1080
- ON DUPLICATE KEY UPDATE
1081
- value = c.is_anchor";
1082
- $this->db_do($q);
1083
-
1084
- $q = "
1085
- INSERT INTO $catalog_category_entity_varchar
1086
- (
1087
- entity_type_id,
1088
- attribute_id,
1089
- store_id,
1090
- entity_id,
1091
- value
1092
- )
1093
- (SELECT
1094
- $_categoryEntityTypeId,
1095
- $image_attrid,
1096
- 0,
1097
- scm.shop_entity_id,
1098
- c.categories_image
1099
- FROM $categories_temp c
1100
- JOIN $stINch_categories_mapping scm
1101
- ON c.store_category_id = scm.store_category_id
1102
- )
1103
- ON DUPLICATE KEY UPDATE
1104
- value = c.categories_image";
1105
- $this->db_do($q);
1106
- //STP
1107
- $q = "
1108
- INSERT INTO $catalog_category_entity_varchar
1109
- (
1110
- entity_type_id,
1111
- attribute_id,
1112
- store_id,
1113
- entity_id,
1114
- value
1115
- )
1116
- (SELECT
1117
- $this->_categoryEntityTypeId,
1118
- $this->_categoryMetaTitleAttrId,
1119
- 0,
1120
- scm.shop_entity_id,
1121
- c.MetaTitle
1122
- FROM $categories_temp c
1123
- JOIN $stINch_categories_mapping scm
1124
- ON c.store_category_id = scm.store_category_id
1125
- )
1126
- ON DUPLICATE KEY UPDATE
1127
- value = c.MetaTitle";
1128
- $this->db_do($q);
1129
-
1130
- $q = "
1131
- INSERT INTO $catalog_category_entity_varchar
1132
- (
1133
- entity_type_id,
1134
- attribute_id,
1135
- store_id,
1136
- entity_id,
1137
- value
1138
- )
1139
- (SELECT
1140
- $this->_categoryEntityTypeId,
1141
- $this->_categoryMetadescriptionAttrId,
1142
- 0,
1143
- scm.shop_entity_id,
1144
- c.MetaDescription
1145
- FROM $categories_temp c
1146
- JOIN $stINch_categories_mapping scm
1147
- ON c.store_category_id = scm.store_category_id
1148
- )
1149
- ON DUPLICATE KEY UPDATE
1150
- value = c.MetaDescription";
1151
- $this->db_do($q);
1152
-
1153
- $q = "
1154
- INSERT INTO $catalog_category_entity_varchar
1155
- (
1156
- entity_type_id,
1157
- attribute_id,
1158
- store_id,
1159
- entity_id,
1160
- value
1161
- )
1162
- (SELECT
1163
- $this->_categoryEntityTypeId,
1164
- $this->_categoryDescriptionAttrId,
1165
- 0,
1166
- scm.shop_entity_id,
1167
- c.Description
1168
- FROM $categories_temp c
1169
- JOIN $stINch_categories_mapping scm
1170
- ON c.store_category_id = scm.store_category_id
1171
- )
1172
- ON DUPLICATE KEY UPDATE
1173
- value = c.Description";
1174
- $this->db_do($q);
1175
-
1176
-
1177
- //stp
1178
- }
1179
- else
1180
- {
1181
- echo "Insert ignore category_data \n";
1182
-
1183
-
1184
- $q = "
1185
- INSERT IGNORE INTO $catalog_category_entity_varchar
1186
- (
1187
- entity_type_id,
1188
- attribute_id,
1189
- store_id,
1190
- entity_id,
1191
- value
1192
- )
1193
- (SELECT
1194
- $_categoryEntityTypeId,
1195
- $name_attrid,
1196
- 0,
1197
- scm.shop_entity_id,
1198
- c.category_name
1199
- FROM $categories_temp c
1200
- JOIN $stINch_categories_mapping scm
1201
- ON c.store_category_id = scm.store_category_id
1202
- )";
1203
- $this->db_do($q);
1204
-
1205
-
1206
- $q = "
1207
- INSERT IGNORE INTO $catalog_category_entity_int
1208
- (
1209
- entity_type_id,
1210
- attribute_id,
1211
- store_id,
1212
- entity_id,
1213
- value
1214
- )
1215
- (SELECT
1216
- $_categoryEntityTypeId,
1217
- $attr_is_active,
1218
- 0,
1219
- scm.shop_entity_id,
1220
- 1
1221
- FROM $categories_temp c
1222
- JOIN $stINch_categories_mapping scm
1223
- ON c.store_category_id = scm.store_category_id
1224
- )";
1225
- $this->db_do($q);
1226
-
1227
-
1228
- $q = "
1229
- INSERT IGNORE INTO $catalog_category_entity_int
1230
- (
1231
- entity_type_id,
1232
- attribute_id,
1233
- store_id,
1234
- entity_id,
1235
- value
1236
- )
1237
- (SELECT
1238
- $_categoryEntityTypeId,
1239
- $attr_include_in_menu,
1240
- 0,
1241
- scm.shop_entity_id,
1242
- c.include_in_menu
1243
- FROM $categories_temp c
1244
- JOIN $stINch_categories_mapping scm
1245
- ON c.store_category_id = scm.store_category_id
1246
- )";
1247
- $this->db_do($q);
1248
-
1249
-
1250
- $q = "
1251
- INSERT IGNORE INTO $catalog_category_entity_int
1252
- (
1253
- entity_type_id,
1254
- attribute_id,
1255
- store_id,
1256
- entity_id,
1257
- value
1258
- )
1259
- (SELECT
1260
- $_categoryEntityTypeId,
1261
- $is_anchor_attrid,
1262
- 0,
1263
- scm.shop_entity_id,
1264
- c.is_anchor
1265
- FROM $categories_temp c
1266
- JOIN $stINch_categories_mapping scm
1267
- ON c.store_category_id = scm.store_category_id
1268
- )";
1269
- $this->db_do($q);
1270
-
1271
-
1272
- $q = "
1273
- INSERT IGNORE INTO $catalog_category_entity_varchar
1274
- (
1275
- entity_type_id,
1276
- attribute_id,
1277
- store_id,
1278
- entity_id,
1279
- value
1280
- )
1281
- (SELECT
1282
- $_categoryEntityTypeId,
1283
- $image_attrid,
1284
- 0,
1285
- scm.shop_entity_id,
1286
- c.categories_image
1287
- FROM $categories_temp c
1288
- JOIN $stINch_categories_mapping scm
1289
- ON c.store_category_id = scm.store_category_id
1290
- )";
1291
- $this->db_do($q);
1292
- //STP
1293
- $q = "
1294
- INSERT IGNORE INTO $catalog_category_entity_varchar
1295
- (
1296
- entity_type_id,
1297
- attribute_id,
1298
- store_id,
1299
- entity_id,
1300
- value
1301
- )
1302
- (SELECT
1303
- $this->_categoryEntityTypeId,
1304
- $this->_categoryMetaTitleAttrId,
1305
- 0,
1306
- scm.shop_entity_id,
1307
- c.MetaTitle
1308
- FROM $categories_temp c
1309
- JOIN $stINch_categories_mapping scm
1310
- ON c.store_category_id = scm.store_category_id
1311
- )
1312
- ";
1313
- $this->db_do($q);
1314
-
1315
- $q = "
1316
- INSERT IGNORE INTO $catalog_category_entity_varchar
1317
- (
1318
- entity_type_id,
1319
- attribute_id,
1320
- store_id,
1321
- entity_id,
1322
- value
1323
- )
1324
- (SELECT
1325
- $this->_categoryEntityTypeId,
1326
- $this->_categoryMetadescriptionAttrId,
1327
- 0,
1328
- scm.shop_entity_id,
1329
- c.MetaDescription
1330
- FROM $categories_temp c
1331
- JOIN $stINch_categories_mapping scm
1332
- ON c.store_category_id = scm.store_category_id
1333
- )
1334
- ";
1335
- $this->db_do($q);
1336
-
1337
- $q = "
1338
- INSERT IGNORE INTO $catalog_category_entity_varchar
1339
- (
1340
- entity_type_id,
1341
- attribute_id,
1342
- store_id,
1343
- entity_id,
1344
- value
1345
- )
1346
- (SELECT
1347
- $this->_categoryEntityTypeId,
1348
- $this->_categoryDescriptionAttrId,
1349
- 0,
1350
- scm.shop_entity_id,
1351
- c.Description
1352
- FROM $categories_temp c
1353
- JOIN $stINch_categories_mapping scm
1354
- ON c.store_category_id = scm.store_category_id
1355
- )
1356
- ";
1357
- $this->db_do($q);
1358
-
1359
-
1360
- //stp
1361
-
1362
- }
1363
-
1364
-
1365
-
1366
-
1367
-
1368
- //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
1369
-
1370
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
1371
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
1372
-
1373
- $this->deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int);
1374
- /**/
1375
-
1376
- echo("\n addCategoryDataMultistoreMerge done... \n *************************************************************\n");
1377
-
1378
- } // private function addCategoryDataMultistoreMerge(...)
1379
- ################################################################################################################################################################
1380
-
1381
-
1382
-
1383
-
1384
-
1385
- ################################################################################################################################################################
1386
- private function deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int)
1387
- {
1388
-
1389
- echo("\n\n\n\n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n deleteOldSinchCategoriesFromShopMerge start... \n");
1390
-
1391
-
1392
- $query = "DROP TABLE IF EXISTS delete_cats";
1393
- echo("\n $query\n");
1394
- $this->db_do($query );
1395
-
1396
-
1397
-
1398
- $delete_cats = Mage::getSingleton('core/resource')->getTableName('delete_cats');
1399
- $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
1400
-
1401
- $query = "
1402
- CREATE TABLE $delete_cats
1403
-
1404
- SELECT entity_id
1405
- FROM $catalog_category_entity cce
1406
- WHERE cce.entity_id NOT IN
1407
- (
1408
- SELECT cce2.entity_id
1409
- FROM $catalog_category_entity cce2
1410
- JOIN $stINch_categories sc
1411
- ON cce2.store_category_id = sc.store_category_id
1412
- )
1413
- AND cce.store_category_id IS NOT NULL
1414
- ;";
1415
-
1416
- echo("\n $query\n");
1417
- $this->db_do($query);
1418
-
1419
-
1420
-
1421
- $query = "DELETE cce FROM $catalog_category_entity cce JOIN $delete_cats dc USING(entity_id)";
1422
- echo("\n $query\n");
1423
- $this->db_do($query);
1424
-
1425
-
1426
-
1427
- $query = "DROP TABLE IF EXISTS $delete_cats";
1428
- echo("\n $query\n");
1429
- //$this->db_do($query );
1430
-
1431
-
1432
- /**
1433
- $query = "
1434
- DELETE cat FROM $catalog_category_entity_varchar cat
1435
- JOIN $stINch_categories_mapping scm
1436
- ON cat.entity_id = scm.shop_entity_id
1437
- WHERE
1438
- (scm.shop_store_category_id IS NOT NULL) AND
1439
- (scm.store_category_id IS NULL)";
1440
- echo("\n $query\n");
1441
- // $this->db_do($query);
1442
-
1443
- $query = "
1444
- DELETE cat FROM $catalog_category_entity_int cat
1445
- JOIN $stINch_categories_mapping scm
1446
- ON cat.entity_id = scm.shop_entity_id
1447
- WHERE
1448
- (scm.shop_store_category_id IS NOT NULL) AND
1449
- (scm.store_category_id IS NULL)";
1450
- echo("\n $query\n");
1451
- // $this->db_do($query);
1452
-
1453
- $query = "
1454
- DELETE cat FROM $catalog_category_entity cat
1455
- JOIN $stINch_categories_mapping scm
1456
- ON cat.entity_id=scm.shop_entity_id
1457
- WHERE
1458
- (scm.shop_store_category_id IS NOT NULL) AND
1459
- (scm.store_category_id IS NULL)";
1460
- echo("\n $query\n");
1461
- // $this->db_do($query);
1462
- /**/
1463
-
1464
- echo("\n deleteOldSinchCategoriesFromShopMerge done... \n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n\n");
1465
-
1466
- } // private function deleteOldSinchCategoriesFromShopMerge()
1467
- ################################################################################################################################################################
1468
-
1469
-
1470
-
1471
-
1472
-
1473
- ################################################################################################################################################################
1474
- private function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
1475
- {
1476
- echo("\n\n\ ==========================================================================\n mapSinchCategoriesMultistore start... \n");
1477
-
1478
- $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
1479
-
1480
- $query = "
1481
- INSERT IGNORE INTO $stINch_categories_mapping_temp
1482
- (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
1483
- (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
1484
- FROM $catalog_category_entity)";
1485
- echo("\n $query\n");
1486
- $this->db_do($query);
1487
-
1488
-
1489
- $query = "
1490
- UPDATE $stINch_categories_mapping_temp cmt
1491
- JOIN $categories_temp c
1492
- ON cmt.shop_store_category_id = c.store_category_id
1493
- SET
1494
- cmt.store_category_id = c.store_category_id,
1495
- cmt.parent_store_category_id = c.parent_store_category_id,
1496
- cmt.category_name = c.category_name,
1497
- cmt.order_number = c.order_number,
1498
- cmt.products_within_this_category = c.products_within_this_category";
1499
- echo("\n $query\n");
1500
- $this->db_do($query);
1501
-
1502
-
1503
- $query = "
1504
- UPDATE $stINch_categories_mapping_temp cmt
1505
- JOIN $catalog_category_entity cce
1506
- ON cmt.parent_store_category_id = cce.store_category_id
1507
- SET cmt.shop_parent_id = cce.entity_id";
1508
- echo("\n $query\n");
1509
- $this->db_do($query);
1510
-
1511
-
1512
- $query = "
1513
- SELECT DISTINCT
1514
- c.RootName, cce.entity_id
1515
- FROM $categories_temp c
1516
- JOIN $catalog_category_entity_varchar ccev
1517
- ON c.RootName = ccev.value
1518
- AND ccev.entity_type_id = $_categoryEntityTypeId
1519
- AND ccev.attribute_id = $name_attrid
1520
- AND ccev.store_id = 0
1521
- JOIN $catalog_category_entity cce
1522
- ON ccev.entity_id = cce.entity_id";
1523
- echo("\n $query\n");
1524
- $root_categories = $this->db_do($query);
1525
-
1526
- while($root_cat = mysqli_fetch_array($root_categories))
1527
- {
1528
- $root_id = $root_cat['entity_id'];
1529
- $root_name = $root_cat['RootName'];
1530
-
1531
- $query = "
1532
- UPDATE $stINch_categories_mapping_temp cmt
1533
- JOIN $categories_temp c
1534
- ON cmt.shop_store_category_id = c.store_category_id
1535
- SET
1536
- cmt.shop_parent_id = $root_id,
1537
- cmt.shop_parent_store_category_id = $root_id,
1538
- cmt.parent_store_category_id = $root_id,
1539
- c.parent_store_category_id = $root_id
1540
- WHERE RootName = '$root_name'
1541
- AND cmt.shop_parent_id = 0";
1542
- echo("\n $query\n");
1543
- $this->db_do($query);
1544
- }
1545
-
1546
-
1547
-
1548
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1549
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
1550
- else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
1551
-
1552
- $query = "
1553
- UPDATE $stINch_categories_mapping_temp cmt
1554
- JOIN $catalog_category_entity cce
1555
- ON cmt.shop_entity_id = cce.entity_id
1556
- SET cce.parent_id = cmt.shop_parent_id
1557
- $where";
1558
- echo("\n $query\n");
1559
- $this->db_do($query);
1560
-
1561
- $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
1562
- echo("\n $query\n");
1563
- $this->db_do($query);
1564
-
1565
- $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
1566
- echo("\n $query\n");
1567
- $this->db_do($query);
1568
-
1569
- echo("\n mapSinchCategoriesMultistore done... \n ==========================================================================\n\n\n\n");
1570
- } // public function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
1571
- ################################################################################################################################################################
1572
-
1573
-
1574
-
1575
-
1576
-
1577
-
1578
-
1579
- ################################################################################################################################################################
1580
- private function createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1581
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1582
- {
1583
- echo("\n\n ==========================================================================\n createNewDefaultCategories start... \n");
1584
-
1585
- $old_cats = array();
1586
- $query = $this->db_do("
1587
- SELECT
1588
- cce.entity_id,
1589
- ccev.value AS category_name
1590
- FROM $catalog_category_entity cce
1591
- JOIN $catalog_category_entity_varchar ccev
1592
- ON cce.entity_id = ccev.entity_id
1593
- AND ccev.store_id = 0
1594
- AND cce.entity_type_id = ccev.entity_type_id
1595
- AND ccev.attribute_id = 41
1596
- WHERE parent_id = 1"); // 41 - category name
1597
- while ($row = mysqli_fetch_array($query)) $old_cats[] = $row['category_name'];
1598
-
1599
- //var_dump($old_cats);
1600
-
1601
-
1602
- $query = $this->db_do("SELECT MAX(entity_id) AS max_entity_id FROM $catalog_category_entity");
1603
- $max_entity_id = mysqli_fetch_array($query);
1604
-
1605
- //var_dump($max_entity_id);
1606
-
1607
- $i = $max_entity_id[max_entity_id] + 1;
1608
-
1609
- foreach($coincidence as $key => $item)
1610
- {
1611
- echo("\n coincidence: key = [$key]\n");
1612
-
1613
-
1614
- /**if ($item)
1615
- {
1616
- echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> CONTINUE: key = [$key] item = [$item]\n");
1617
- //continue;
1618
- }
1619
- else
1620
- {
1621
- echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> NOT CONTINUE: key = [$key] item = [$item]\n");
1622
- }/**/
1623
-
1624
-
1625
- if (in_array($key, $old_cats))
1626
- {
1627
- echo(" CONTINUE: key = [$key] item = [$item]\n");
1628
- continue;
1629
- }
1630
- else
1631
- {
1632
- echo(" CREATE NEW CATEGORY: key = [$key] item = [$item]\n");
1633
- }
1634
-
1635
-
1636
- $this->db_do("INSERT $catalog_category_entity
1637
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1638
- path, position, level, children_count, store_category_id, parent_store_category_id)
1639
- VALUES
1640
- ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 1, NULL, NULL)");
1641
-
1642
-
1643
- $this->db_do("INSERT $catalog_category_entity_varchar
1644
- (entity_type_id, attribute_id, store_id, entity_id, value)
1645
- VALUES
1646
- ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
1647
- ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
1648
- ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
1649
- ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
1650
-
1651
-
1652
- $this->db_do("INSERT $catalog_category_entity_int
1653
- (entity_type_id, attribute_id, store_id, entity_id, value)
1654
- VALUES
1655
- ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
1656
- ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
1657
- ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
1658
- ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
1659
- $i++;
1660
- } // foreach($coincidence as $key => $item)
1661
-
1662
- echo("\n createNewDefaultCategories done... \n ==========================================================================\n");
1663
-
1664
- } // private function createNewDefaultCategories()
1665
- ################################################################################################################################################################
1666
-
1667
-
1668
-
1669
-
1670
-
1671
-
1672
-
1673
- ################################################################################################################################################################
1674
- private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type, $category_types)
1675
- {
1676
- $root_categories = $this->db_do("
1677
- SELECT
1678
- cce.entity_id,
1679
- ccev.value AS category_name
1680
- FROM $catalog_category_entity cce
1681
- JOIN $catalog_category_entity_varchar ccev
1682
- ON cce.entity_id = ccev.entity_id
1683
- AND ccev.store_id = 0
1684
- AND cce.entity_type_id = ccev.entity_type_id
1685
- AND ccev.attribute_id = 41
1686
- WHERE parent_id = 1"); // 41 - category name
1687
- $OLD = array();
1688
- while($root_cat = mysqli_fetch_array($root_categories)) $OLD[] = $root_cat['category_name'];
1689
-
1690
- $new_categories = $this->db_do("SELECT DISTINCT RootName FROM $categories_temp");
1691
-
1692
- //STP $new_categories = $this->db_do("SELECT DISTINCT ctemp.RootName, ctype.name FROM $categories_temp ctemp LEFT JOIN $category_types ctypes on ctemp.RootName = ctype.name");
1693
-
1694
- $NEW = array();
1695
- while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['RootName']] = TRUE;
1696
- /////STP while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['name']] = TRUE;
1697
- /**
1698
- $exists_coincidence = array();
1699
-
1700
- switch ($im_type)
1701
- {
1702
- case "REWRITE":
1703
- foreach($NEW as $item)
1704
- {
1705
- $exists_coincidence[$item] = TRUE;
1706
- }
1707
- break;
1708
- case "MERGE" :
1709
- foreach($OLD as $item)
1710
- {
1711
- $exists_coincidence[$item] = FALSE;
1712
- }
1713
- foreach($NEW as $item)
1714
- {
1715
- $exists_coincidence[$item] = TRUE;
1716
- }
1717
- break;
1718
- default : $retcode = "error";
1719
- };
1720
- /**/
1721
-
1722
-
1723
-
1724
- echo("\ncalculateCategoryCoincidence ...im_type = [$im_type]\n\n");
1725
- var_dump($exists_coincidence);
1726
-
1727
- return $exists_coincidence;
1728
- } // private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity)
1729
- ################################################################################################################################################################
1730
-
1731
-
1732
-
1733
- ################################################################################################################################################################
1734
- private function rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1735
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1736
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
1737
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
1738
- {
1739
- echo("rewriteMultistoreCategories RUN\n");
1740
-
1741
-
1742
- echo(" truncateAllCateriesAndCreateRoot start...");
1743
- $this->truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1744
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active);
1745
- echo(" done.\n");
1746
-
1747
-
1748
- echo(" createDefaultCategories start...");
1749
- $this->createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1750
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
1751
- echo(" done.\n");
1752
-
1753
-
1754
- echo(" mapSinchCategoriesMultistore start...");
1755
- $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
1756
- echo(" done.\n");
1757
-
1758
-
1759
- echo(" addCategoryDataMultistore start...");
1760
- $this->addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1761
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1762
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
1763
- echo(" done.\n");
1764
-
1765
-
1766
- echo("rewriteMultistoreCategories DONE\n");
1767
- } // private function rewriteMultistoreCategories()
1768
- ################################################################################################################################################################
1769
-
1770
-
1771
-
1772
-
1773
-
1774
-
1775
-
1776
- ################################################################################################################################################################
1777
- private function truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1778
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active)
1779
- {
1780
- $this->db_do('SET foreign_key_checks=0');
1781
-
1782
-
1783
- $this->db_do("TRUNCATE $catalog_category_entity");
1784
- $this->db_do("TRUNCATE $catalog_category_entity_varchar");
1785
- $this->db_do("TRUNCATE $catalog_category_entity_int");
1786
-
1787
-
1788
- $this->db_do("INSERT $catalog_category_entity
1789
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1790
- path, position, level, children_count, store_category_id, parent_store_category_id)
1791
- VALUES
1792
- (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', NOW(), '1', 0, 0, 1, NULL, NULL)");
1793
-
1794
-
1795
- $this->db_do("INSERT $catalog_category_entity_varchar
1796
- (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1797
- VALUES
1798
- (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
1799
- (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
1800
- (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog')");
1801
-
1802
-
1803
- $this->db_do("INSERT $catalog_category_entity_int
1804
- (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1805
- VALUES
1806
- (1, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1)");
1807
- } // private function truncateAllCateriesAndCreateRoot(...)
1808
- ################################################################################################################################################################
1809
-
1810
-
1811
-
1812
-
1813
- ################################################################################################################################################################
1814
- private function createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1815
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1816
- {
1817
- $i = 3; // 2 - is Default Category... not use.
1818
-
1819
- foreach($coincidence as $key => $item)
1820
- {
1821
- $this->db_do("INSERT $catalog_category_entity
1822
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1823
- path, position, level, children_count, store_category_id, parent_store_category_id)
1824
- VALUES
1825
- ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 1, NULL, NULL)");
1826
-
1827
-
1828
- $this->db_do("INSERT $catalog_category_entity_varchar
1829
- (entity_type_id, attribute_id, store_id, entity_id, value)
1830
- VALUES
1831
- ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
1832
- ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
1833
- ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
1834
- ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
1835
-
1836
-
1837
- $this->db_do("INSERT $catalog_category_entity_int
1838
- (entity_type_id, attribute_id, store_id, entity_id, value)
1839
- VALUES
1840
- ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
1841
- ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
1842
- ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
1843
- ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
1844
- $i++;
1845
- } // foreach($coincidence as $key => $item)
1846
- } // private function truncateAllCateries()
1847
- ################################################################################################################################################################
1848
-
1849
-
1850
-
1851
-
1852
- ################################################################################################################################################################
1853
- private function mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
1854
- {
1855
- echo("\n\n\n\n==========================================================================\nmapSinchCategoriesMultistore start... \n");
1856
-
1857
- $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
1858
-
1859
- $query = "
1860
- INSERT IGNORE INTO $stINch_categories_mapping_temp
1861
- (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
1862
- (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
1863
- FROM $catalog_category_entity)";
1864
- echo("\n\n$query\n\n");
1865
- $this->db_do($query);
1866
-
1867
-
1868
- $query = "
1869
- UPDATE $stINch_categories_mapping_temp cmt
1870
- JOIN $categories_temp c
1871
- ON cmt.shop_store_category_id = c.store_category_id
1872
- SET
1873
- cmt.store_category_id = c.store_category_id,
1874
- cmt.parent_store_category_id = c.parent_store_category_id,
1875
- cmt.category_name = c.category_name,
1876
- cmt.order_number = c.order_number,
1877
- cmt.products_within_this_category = c.products_within_this_category";
1878
- echo("\n\n$query\n\n");
1879
- $this->db_do($query);
1880
-
1881
-
1882
- $query = "
1883
- UPDATE $stINch_categories_mapping_temp cmt
1884
- JOIN $catalog_category_entity cce
1885
- ON cmt.parent_store_category_id = cce.store_category_id
1886
- SET cmt.shop_parent_id = cce.entity_id";
1887
- echo("\n\n$query\n\n");
1888
- $this->db_do($query);
1889
-
1890
-
1891
- $query = "
1892
- SELECT DISTINCT
1893
- c.RootName, cce.entity_id
1894
- FROM $categories_temp c
1895
- JOIN $catalog_category_entity_varchar ccev
1896
- ON c.RootName = ccev.value
1897
- AND ccev.entity_type_id = $_categoryEntityTypeId
1898
- AND ccev.attribute_id = $name_attrid
1899
- AND ccev.store_id = 0
1900
- JOIN $catalog_category_entity cce
1901
- ON ccev.entity_id = cce.entity_id";
1902
- echo("\n\n$query\n\n");
1903
- $root_categories = $this->db_do($query);
1904
-
1905
- while($root_cat = mysqli_fetch_array($root_categories))
1906
- {
1907
- $root_id = $root_cat['entity_id'];
1908
- $root_name = $root_cat['RootName'];
1909
-
1910
- $query = "
1911
- UPDATE $stINch_categories_mapping_temp cmt
1912
- JOIN $categories_temp c
1913
- ON cmt.shop_store_category_id = c.store_category_id
1914
- SET
1915
- cmt.shop_parent_id = $root_id,
1916
- cmt.shop_parent_store_category_id = $root_id,
1917
- cmt.parent_store_category_id = $root_id,
1918
- c.parent_store_category_id = $root_id
1919
- WHERE RootName = '$root_name'
1920
- AND cmt.shop_parent_id = 0";
1921
- echo("\n\n$query\n\n");
1922
- $this->db_do($query);
1923
- }
1924
-
1925
-
1926
-
1927
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1928
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
1929
- else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
1930
-
1931
- $query = "
1932
- UPDATE $stINch_categories_mapping_temp cmt
1933
- JOIN $catalog_category_entity cce
1934
- ON cmt.shop_entity_id = cce.entity_id
1935
- SET cce.parent_id = cmt.shop_parent_id
1936
- $where";
1937
- echo("\n\n$query\n\n");
1938
- $this->db_do($query);
1939
-
1940
- $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
1941
- echo("\n\n$query\n\n");
1942
- $this->db_do($query);
1943
-
1944
- $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
1945
- echo("\n\n$query\n\n");
1946
- $this->db_do($query);
1947
-
1948
- echo("\nmapSinchCategoriesMultistore done... \n==========================================================================\n\n\n\n");
1949
- } // public function mapSinchCategoriesMultistore($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
1950
- ################################################################################################################################################################
1951
-
1952
-
1953
-
1954
- ################################################################################################################################################################
1955
- private function createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping)
1956
- {
1957
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
1958
- $this->db_do("
1959
- CREATE TABLE $stINch_categories_mapping_temp
1960
- (
1961
- shop_entity_id INT(11) UNSIGNED NOT NULL,
1962
- shop_entity_type_id INT(11),
1963
- shop_attribute_set_id INT(11),
1964
- shop_parent_id INT(11),
1965
- shop_store_category_id INT(11),
1966
- shop_parent_store_category_id INT(11),
1967
- store_category_id INT(11),
1968
- parent_store_category_id INT(11),
1969
- category_name VARCHAR(255),
1970
- order_number INT(11),
1971
- products_within_this_category INT(11),
1972
-
1973
- KEY shop_entity_id (shop_entity_id),
1974
- KEY shop_parent_id (shop_parent_id),
1975
- KEY store_category_id (store_category_id),
1976
- KEY parent_store_category_id (parent_store_category_id),
1977
- UNIQUE KEY(shop_entity_id)
1978
- )");
1979
-
1980
-
1981
- $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
1982
- }
1983
- ################################################################################################################################################################
1984
-
1985
-
1986
-
1987
- ################################################################################################################################################################
1988
- private function addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1989
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1990
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
1991
- {
1992
- echo("\n\n\n\n*************************************************************\nmapSinchCategoriesMultistore start... \n");
1993
- if (UPDATE_CATEGORY_DATA)
1994
- {
1995
- $ignore = '';
1996
- $on_diplicate_key_update = "
1997
- ON DUPLICATE KEY UPDATE
1998
- updated_at = now(),
1999
- store_category_id = c.store_category_id,
2000
- level = c.level,
2001
- children_count = c.children_count,
2002
- position = c.order_number,
2003
- parent_store_category_id = c.parent_store_category_id";
2004
- //level=c.level,
2005
- //children_count=c.children_count
2006
- //position=c.order_number,
2007
- }
2008
- else
2009
- {
2010
- $ignore = 'IGNORE';
2011
- $on_diplicate_key_update = '';
2012
- }
2013
-
2014
- $query = "
2015
- INSERT $ignore INTO $catalog_category_entity
2016
- (
2017
- entity_type_id,
2018
- attribute_set_id,
2019
- created_at,
2020
- updated_at,
2021
- level,
2022
- children_count,
2023
- entity_id,
2024
- position,
2025
- parent_id,
2026
- store_category_id,
2027
- parent_store_category_id
2028
- )
2029
- (SELECT
2030
- $_categoryEntityTypeId,
2031
- $_categoryDefault_attribute_set_id,
2032
- NOW(),
2033
- NOW(),
2034
- c.level,
2035
- c.children_count,
2036
- scm.shop_entity_id,
2037
- c.order_number,
2038
- scm.shop_parent_id,
2039
- c.store_category_id,
2040
- c.parent_store_category_id
2041
- FROM $categories_temp c
2042
- LEFT JOIN $stINch_categories_mapping scm
2043
- ON c.store_category_id = scm.store_category_id
2044
- ) $on_diplicate_key_update";
2045
- echo("\n\n$query\n\n");
2046
- $this->db_do($query);
2047
-
2048
- //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
2049
-
2050
-
2051
- $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
2052
-
2053
-
2054
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
2055
- while ($row = mysqli_fetch_array($categories))
2056
- {
2057
- $parent_id = $row['parent_id'];
2058
- $entity_id = $row['entity_id'];
2059
-
2060
- $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
2061
-
2062
- $this->db_do("
2063
- UPDATE $catalog_category_entity
2064
- SET path = '$path'
2065
- WHERE entity_id = $entity_id");
2066
- } // while ($row = mysqli_fetch_array($categories))
2067
-
2068
-
2069
- ///////////////////////////////////////////////////////
2070
-
2071
-
2072
- if(UPDATE_CATEGORY_DATA)
2073
- {
2074
- echo "Update category_data \n";
2075
-
2076
- $q = "
2077
- INSERT INTO $catalog_category_entity_varchar
2078
- (
2079
- entity_type_id,
2080
- attribute_id,
2081
- store_id,
2082
- entity_id,
2083
- value
2084
- )
2085
- (SELECT
2086
- $_categoryEntityTypeId,
2087
- $name_attrid,
2088
- 0,
2089
- scm.shop_entity_id,
2090
- c.category_name
2091
- FROM $categories_temp c
2092
- JOIN $stINch_categories_mapping scm
2093
- ON c.store_category_id = scm.store_category_id
2094
- )
2095
- ON DUPLICATE KEY UPDATE
2096
- value = c.category_name";
2097
- $this->db_do($q);
2098
-
2099
-
2100
- $q = "
2101
- INSERT INTO $catalog_category_entity_varchar
2102
- (
2103
- entity_type_id,
2104
- attribute_id,
2105
- store_id,
2106
- entity_id,
2107
- value
2108
- )
2109
- (SELECT
2110
- $_categoryEntityTypeId,
2111
- $name_attrid,
2112
- 1,
2113
- scm.shop_entity_id,
2114
- c.category_name
2115
- FROM $categories_temp c
2116
- JOIN $stINch_categories_mapping scm
2117
- ON c.store_category_id = scm.store_category_id
2118
- )
2119
- ON DUPLICATE KEY UPDATE
2120
- value = c.category_name";
2121
- $this->db_do($q);
2122
-
2123
-
2124
- $q = "
2125
- INSERT INTO $catalog_category_entity
2126
- (
2127
- entity_type_id,
2128
- attribute_id,
2129
- store_id,
2130
- entity_id,
2131
- value
2132
- )
2133
- (SELECT
2134
- $_categoryEntityTypeId,
2135
- $attr_is_active,
2136
- 0,
2137
- scm.shop_entity_id,
2138
- 1
2139
- FROM $categories_temp c
2140
- JOIN $stINch_categories_mapping scm
2141
- ON c.store_category_id = scm.store_category_id
2142
- )
2143
- ON DUPLICATE KEY UPDATE
2144
- value = 1";
2145
- $this->db_do($q);
2146
-
2147
-
2148
- $q = "
2149
- INSERT INTO $catalog_category_entity_int
2150
- (
2151
- entity_type_id,
2152
- attribute_id,
2153
- store_id,
2154
- entity_id,
2155
- value
2156
- )
2157
- (SELECT
2158
- $_categoryEntityTypeId,
2159
- $attr_is_active,
2160
- 1,
2161
- scm.shop_entity_id,
2162
- 1
2163
- FROM $categories_temp c
2164
- JOIN $stINch_categories_mapping scm
2165
- ON c.store_category_id = scm.store_category_id
2166
- )
2167
- ON DUPLICATE KEY UPDATE
2168
- value = 1";
2169
- $this->db_do($q);
2170
-
2171
-
2172
- $q = "
2173
- INSERT INTO $catalog_category_entity_int
2174
- (
2175
- entity_type_id,
2176
- attribute_id,
2177
- store_id,
2178
- entity_id,
2179
- value
2180
- )
2181
- (SELECT
2182
- $_categoryEntityTypeId,
2183
- $attr_include_in_menu,
2184
- 0,
2185
- scm.shop_entity_id,
2186
- c.include_in_menu
2187
- FROM $categories_temp c
2188
- JOIN $stINch_categories_mapping scm
2189
- ON c.store_category_id = scm.store_category_id
2190
- )
2191
- ON DUPLICATE KEY UPDATE
2192
- value = c.include_in_menu";
2193
- $this->db_do($q);
2194
-
2195
-
2196
- $q = "
2197
- INSERT INTO $catalog_category_entity_int
2198
- (
2199
- entity_type_id,
2200
- attribute_id,
2201
- store_id,
2202
- entity_id,
2203
- value
2204
- )
2205
- (SELECT
2206
- $_categoryEntityTypeId,
2207
- $is_anchor_attrid,
2208
- 1,
2209
- scm.shop_entity_id,
2210
- c.is_anchor
2211
- FROM $categories_temp c
2212
- JOIN $stINch_categories_mapping scm
2213
- ON c.store_category_id = scm.store_category_id
2214
- )
2215
- ON DUPLICATE KEY UPDATE
2216
- value = c.is_anchor";
2217
- $this->db_do($q);
2218
-
2219
-
2220
- $q = "
2221
- INSERT INTO $catalog_category_entity_int
2222
- (
2223
- entity_type_id,
2224
- attribute_id,
2225
- store_id,
2226
- entity_id,
2227
- value
2228
- )
2229
- (SELECT
2230
- $_categoryEntityTypeId,
2231
- $is_anchor_attrid,
2232
- 0,
2233
- scm.shop_entity_id,
2234
- c.is_anchor
2235
- FROM $categories_temp c
2236
- JOIN $stINch_categories_mapping scm
2237
- ON c.store_category_id = scm.store_category_id
2238
- )
2239
- ON DUPLICATE KEY UPDATE
2240
- value = c.is_anchor";
2241
- $this->db_do($q);
2242
-
2243
- $q = "
2244
- INSERT INTO $catalog_category_entity_varchar
2245
- (
2246
- entity_type_id,
2247
- attribute_id,
2248
- store_id,
2249
- entity_id,
2250
- value
2251
- )
2252
- (SELECT
2253
- $_categoryEntityTypeId,
2254
- $image_attrid,
2255
- 0,
2256
- scm.shop_entity_id,
2257
- c.categories_image
2258
- FROM $categories_temp c
2259
- JOIN $stINch_categories_mapping scm
2260
- ON c.store_category_id = scm.store_category_id
2261
- )
2262
- ON DUPLICATE KEY UPDATE
2263
- value = c.categories_image";
2264
- $this->db_do($q);
2265
- //STP
2266
- $q = "
2267
- INSERT INTO $catalog_category_entity_varchar
2268
- (
2269
- entity_type_id,
2270
- attribute_id,
2271
- store_id,
2272
- entity_id,
2273
- value
2274
- )
2275
- (SELECT
2276
- $this->_categoryEntityTypeId,
2277
- $this->_categoryMetaTitleAttrId,
2278
- 0,
2279
- scm.shop_entity_id,
2280
- c.MetaTitle
2281
- FROM $categories_temp c
2282
- JOIN $stINch_categories_mapping scm
2283
- ON c.store_category_id = scm.store_category_id
2284
- )
2285
- ON DUPLICATE KEY UPDATE
2286
- value = c.MetaTitle";
2287
- $this->db_do($q);
2288
-
2289
- $q = "
2290
- INSERT INTO $catalog_category_entity_varchar
2291
- (
2292
- entity_type_id,
2293
- attribute_id,
2294
- store_id,
2295
- entity_id,
2296
- value
2297
- )
2298
- (SELECT
2299
- $this->_categoryEntityTypeId,
2300
- $this->_categoryMetadescriptionAttrId,
2301
- 0,
2302
- scm.shop_entity_id,
2303
- c.MetaDescription
2304
- FROM $categories_temp c
2305
- JOIN $stINch_categories_mapping scm
2306
- ON c.store_category_id = scm.store_category_id
2307
- )
2308
- ON DUPLICATE KEY UPDATE
2309
- value = c.MetaDescription";
2310
- $this->db_do($q);
2311
-
2312
- $q = "
2313
- INSERT INTO $catalog_category_entity_varchar
2314
- (
2315
- entity_type_id,
2316
- attribute_id,
2317
- store_id,
2318
- entity_id,
2319
- value
2320
- )
2321
- (SELECT
2322
- $this->_categoryEntityTypeId,
2323
- $this->_categoryDescriptionAttrId,
2324
- 0,
2325
- scm.shop_entity_id,
2326
- c.Description
2327
- FROM $categories_temp c
2328
- JOIN $stINch_categories_mapping scm
2329
- ON c.store_category_id = scm.store_category_id
2330
- )
2331
- ON DUPLICATE KEY UPDATE
2332
- value = c.Description";
2333
- $this->db_do($q);
2334
-
2335
-
2336
- //stp
2337
- }
2338
- else
2339
- {
2340
- echo "Insert ignore category_data \n";
2341
-
2342
- $q = "
2343
- INSERT IGNORE INTO $catalog_category_entity_varchar
2344
- (
2345
- entity_type_id,
2346
- attribute_id,
2347
- store_id,
2348
- entity_id,
2349
- value
2350
- )
2351
- (SELECT
2352
- $_categoryEntityTypeId,
2353
- $name_attrid,
2354
- 0,
2355
- scm.shop_entity_id,
2356
- c.category_name
2357
- FROM $categories_temp c
2358
- JOIN $stINch_categories_mapping scm
2359
- ON c.store_category_id = scm.store_category_id
2360
- )";
2361
- $this->db_do($q);
2362
-
2363
-
2364
- $q = "
2365
- INSERT IGNORE INTO $catalog_category_entity_int
2366
- (
2367
- entity_type_id,
2368
- attribute_id,
2369
- store_id,
2370
- entity_id,
2371
- value
2372
- )
2373
- (SELECT
2374
- $_categoryEntityTypeId,
2375
- $attr_is_active,
2376
- 0,
2377
- scm.shop_entity_id,
2378
- 1
2379
- FROM $categories_temp c
2380
- JOIN $stINch_categories_mapping scm
2381
- ON c.store_category_id = scm.store_category_id
2382
- )";
2383
- $this->db_do($q);
2384
-
2385
-
2386
- $q = "
2387
- INSERT IGNORE INTO $catalog_category_entity_int
2388
- (
2389
- entity_type_id,
2390
- attribute_id,
2391
- store_id,
2392
- entity_id,
2393
- value
2394
- )
2395
- (SELECT
2396
- $_categoryEntityTypeId,
2397
- $attr_include_in_menu,
2398
- 0,
2399
- scm.shop_entity_id,
2400
- c.include_in_menu
2401
- FROM $categories_temp c
2402
- JOIN $stINch_categories_mapping scm
2403
- ON c.store_category_id = scm.store_category_id
2404
- )";
2405
- $this->db_do($q);
2406
-
2407
-
2408
- $q = "
2409
- INSERT IGNORE INTO $catalog_category_entity_int
2410
- (
2411
- entity_type_id,
2412
- attribute_id,
2413
- store_id,
2414
- entity_id,
2415
- value
2416
- )
2417
- (SELECT
2418
- $_categoryEntityTypeId,
2419
- $is_anchor_attrid,
2420
- 0,
2421
- scm.shop_entity_id,
2422
- c.is_anchor
2423
- FROM $categories_temp c
2424
- JOIN $stINch_categories_mapping scm
2425
- ON c.store_category_id = scm.store_category_id
2426
- )";
2427
- $this->db_do($q);
2428
-
2429
-
2430
- $q = "
2431
- INSERT IGNORE INTO $catalog_category_entity_varchar
2432
- (
2433
- entity_type_id,
2434
- attribute_id,
2435
- store_id,
2436
- entity_id,
2437
- value
2438
- )
2439
- (SELECT
2440
- $_categoryEntityTypeId,
2441
- $image_attrid,
2442
- 0,
2443
- scm.shop_entity_id,
2444
- c.categories_image
2445
- FROM $categories_temp c
2446
- JOIN $stINch_categories_mapping scm
2447
- ON c.store_category_id = scm.store_category_id
2448
- )";
2449
- $this->db_do($q);
2450
- //STP
2451
- $q = "
2452
- INSERT IGNORE INTO $catalog_category_entity_varchar
2453
- (
2454
- entity_type_id,
2455
- attribute_id,
2456
- store_id,
2457
- entity_id,
2458
- value
2459
- )
2460
- (SELECT
2461
- $this->_categoryEntityTypeId,
2462
- $this->_categoryMetaTitleAttrId,
2463
- 0,
2464
- scm.shop_entity_id,
2465
- c.MetaTitle
2466
- FROM $categories_temp c
2467
- JOIN $stINch_categories_mapping scm
2468
- ON c.store_category_id = scm.store_category_id
2469
- )
2470
- ";
2471
- $this->db_do($q);
2472
-
2473
- $q = "
2474
- INSERT IGNORE INTO $catalog_category_entity_varchar
2475
- (
2476
- entity_type_id,
2477
- attribute_id,
2478
- store_id,
2479
- entity_id,
2480
- value
2481
- )
2482
- (SELECT
2483
- $this->_categoryEntityTypeId,
2484
- $this->_categoryMetadescriptionAttrId,
2485
- 0,
2486
- scm.shop_entity_id,
2487
- c.MetaDescription
2488
- FROM $categories_temp c
2489
- JOIN $stINch_categories_mapping scm
2490
- ON c.store_category_id = scm.store_category_id
2491
- )
2492
- ";
2493
- $this->db_do($q);
2494
-
2495
- $q = "
2496
- INSERT IGNORE INTO $catalog_category_entity_varchar
2497
- (
2498
- entity_type_id,
2499
- attribute_id,
2500
- store_id,
2501
- entity_id,
2502
- value
2503
- )
2504
- (SELECT
2505
- $this->_categoryEntityTypeId,
2506
- $this->_categoryDescriptionAttrId,
2507
- 0,
2508
- scm.shop_entity_id,
2509
- c.Description
2510
- FROM $categories_temp c
2511
- JOIN $stINch_categories_mapping scm
2512
- ON c.store_category_id = scm.store_category_id
2513
- )
2514
- ";
2515
- $this->db_do($q);
2516
-
2517
-
2518
- //stp
2519
-
2520
- }
2521
-
2522
- $this->delete_old_sinch_categories_from_shop();
2523
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
2524
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
2525
- } // private function addCategoryDataMultistore(...)
2526
- ################################################################################################################################################################
2527
-
2528
-
2529
-
2530
- ################################################################################################################################################################
2531
- function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
2532
- {
2533
-
2534
- //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]");
2535
-
2536
- $path = '';
2537
-
2538
- $cat_id = $parent_id;
2539
-
2540
- $q = "
2541
- SELECT
2542
- parent_id
2543
- FROM $catalog_category_entity
2544
- WHERE entity_id = $cat_id";
2545
- $quer = $this->db_do($q);
2546
- $row = mysqli_fetch_array($quer);
2547
- while ($row['parent_id'])
2548
- {
2549
- $path = $row['parent_id'].'/'.$path;
2550
- $parent_id = $row['parent_id'];
2551
-
2552
- $q = "
2553
- SELECT
2554
- parent_id
2555
- FROM $catalog_category_entity
2556
- WHERE entity_id = $parent_id";
2557
- $quer = $this->db_do($q);
2558
- $row = mysqli_fetch_array($quer);
2559
- }
2560
-
2561
- if ($cat_id) $path.=$cat_id."/";
2562
-
2563
- if ($path) $path .= $ent_id;
2564
- else $path = $ent_id;
2565
-
2566
- //echo(" path = [$path]\n");
2567
-
2568
- return $path;
2569
- } // function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
2570
- ################################################################################################################################################################
2571
-
2572
-
2573
-
2574
-
2575
-
2576
-
2577
-
2578
-
2579
- ################################################################################################################################################################
2580
- public function replaceMagentoProductsMultistoreMERGE($coincidence)
2581
- {
2582
-
2583
- echo("\n replaceMagentoProductsMultistoreMERGE 1\n");
2584
-
2585
-
2586
-
2587
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
2588
-
2589
-
2590
- $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
2591
- $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
2592
- $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
2593
- $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
2594
- $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
2595
- $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
2596
- $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
2597
- $stINch_products = Mage::getSingleton('core/resource')->getTableName('stINch_products');
2598
- $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
2599
- $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
2600
- $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
2601
- $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
2602
- $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
2603
- $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
2604
- //STP DELETE $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
2605
- // $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
2606
- $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
2607
-
2608
- $_getProductEntityTypeId = $this->_getProductEntityTypeId();
2609
- $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
2610
-
2611
- $attr_atatus = $this->_getProductAttributeId('status');
2612
- $attr_name = $this->_getProductAttributeId('name');
2613
- $attr_visibility = $this->_getProductAttributeId('visibility');
2614
- $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
2615
- $attr_image = $this->_getProductAttributeId('image');
2616
- $attr_small_image = $this->_getProductAttributeId('small_image');
2617
- $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
2618
-
2619
- $cat_attr_name = $this->_getCategoryAttributeId('name');
2620
- echo("\n replaceMagentoProductsMultistoreMERGE 2\n");
2621
-
2622
-
2623
-
2624
-
2625
-
2626
- //clear products, inserting new products and updating old others.
2627
- $query = "
2628
- DELETE cpe
2629
- FROM $catalog_product_entity cpe
2630
- JOIN $stINch_products_mapping pm
2631
- ON cpe.entity_id = pm.entity_id
2632
- WHERE pm.shop_store_product_id IS NOT NULL
2633
- AND pm.store_product_id IS NULL";
2634
- $result = $this->db_do($query);
2635
-
2636
-
2637
-
2638
-
2639
-
2640
- echo("\n replaceMagentoProductsMultistoreMERGE 3\n");
2641
-
2642
- $result = $this->db_do("
2643
- INSERT INTO $catalog_product_entity
2644
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
2645
- (SELECT
2646
- pm.entity_id,
2647
- $_getProductEntityTypeId,
2648
- $_defaultAttributeSetId,
2649
- 'simple',
2650
- a.product_sku,
2651
- NOW(),
2652
- 0,
2653
- a.store_product_id,
2654
- a.sinch_product_id
2655
- FROM $products_temp a
2656
- LEFT JOIN $stINch_products_mapping pm
2657
- ON a.store_product_id = pm.store_product_id
2658
- AND a.sinch_product_id = pm.sinch_product_id
2659
- WHERE pm.entity_id IS NOT NULL
2660
- )
2661
- ON DUPLICATE KEY UPDATE
2662
- sku = a.product_sku,
2663
- store_product_id = a.store_product_id,
2664
- sinch_product_id = a.sinch_product_id");
2665
- // store_product_id = a.store_product_id,
2666
- // sinch_product_id = a.sinch_product_id
2667
-
2668
- $result = $this->db_do("
2669
- INSERT INTO $catalog_product_entity
2670
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
2671
- (SELECT
2672
- pm.entity_id,
2673
- $_getProductEntityTypeId,
2674
- $_defaultAttributeSetId,
2675
- 'simple',
2676
- a.product_sku,
2677
- NOW(),
2678
- 0,
2679
- a.store_product_id,
2680
- a.sinch_product_id
2681
- FROM $products_temp a
2682
- LEFT JOIN $stINch_products_mapping pm
2683
- ON a.store_product_id = pm.store_product_id
2684
- AND a.sinch_product_id = pm.sinch_product_id
2685
- WHERE pm.entity_id IS NULL
2686
- )
2687
- ON DUPLICATE KEY UPDATE
2688
- sku = a.product_sku,
2689
- store_product_id = a.store_product_id,
2690
- sinch_product_id = a.sinch_product_id");
2691
- // store_product_id = a.store_product_id,
2692
- // sinch_product_id = a.sinch_product_id
2693
-
2694
-
2695
- echo("\n replaceMagentoProductsMultistoreMERGE 4\n");
2696
-
2697
-
2698
-
2699
-
2700
-
2701
- //Set enabled
2702
- $result = $this->db_do("
2703
- DELETE cpei
2704
- FROM $catalog_product_entity_int cpei
2705
- LEFT JOIN $catalog_product_entity cpe
2706
- ON cpei.entity_id = cpe.entity_id
2707
- WHERE cpe.entity_id IS NULL");
2708
-
2709
- $result = $this->db_do("
2710
- INSERT INTO $catalog_product_entity_int
2711
- (entity_type_id, attribute_id, store_id, entity_id, value)
2712
- (SELECT
2713
- $_getProductEntityTypeId,
2714
- $attr_atatus,
2715
- w.website,
2716
- a.entity_id,
2717
- 1
2718
- FROM $catalog_product_entity a
2719
- JOIN $products_website_temp w
2720
- ON a.store_product_id = w.store_product_id
2721
- )
2722
- ON DUPLICATE KEY UPDATE
2723
- value = 1");
2724
-
2725
-
2726
-
2727
-
2728
-
2729
- echo("\n replaceMagentoProductsMultistoreMERGE 5\n");
2730
-
2731
-
2732
- // set status = 1 for all stores
2733
- $result = $this->db_do("
2734
- INSERT INTO $catalog_product_entity_int
2735
- (entity_type_id, attribute_id, store_id, entity_id, value)
2736
- (SELECT
2737
- $_getProductEntityTypeId,
2738
- $attr_atatus,
2739
- 0,
2740
- a.entity_id,
2741
- 1
2742
- FROM $catalog_product_entity a
2743
- )
2744
- ON DUPLICATE KEY UPDATE
2745
- value = 1");
2746
-
2747
-
2748
-
2749
-
2750
-
2751
- echo("\n replaceMagentoProductsMultistoreMERGE 6\n");
2752
-
2753
-
2754
- //Unifying products with categories.
2755
- $result = $this->db_do("
2756
- DELETE ccp
2757
- FROM $catalog_category_product ccp
2758
- LEFT JOIN $catalog_product_entity cpe
2759
- ON ccp.product_id = cpe.entity_id
2760
- WHERE cpe.entity_id IS NULL");
2761
-
2762
-
2763
-
2764
-
2765
-
2766
-
2767
-
2768
- echo("\n replaceMagentoProductsMultistoreMERGE 7\n");
2769
-
2770
-
2771
- $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
2772
-
2773
- $result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
2774
- $result = $this->db_do("
2775
- CREATE TABLE $root_cats
2776
- SELECT
2777
- entity_id,
2778
- path,
2779
- SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
2780
- LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
2781
- SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
2782
- FROM $catalog_category_entity
2783
- ");
2784
- $result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
2785
-
2786
-
2787
- echo("\n replaceMagentoProductsMultistoreMERGE 8\n");
2788
-
2789
-
2790
- // !!! $this->_root_cat
2791
- $result = $this->db_do("
2792
- UPDATE IGNORE $catalog_category_product ccp
2793
- LEFT JOIN $catalog_category_entity cce
2794
- ON ccp.category_id = cce.entity_id
2795
- JOIN $root_cats rc
2796
- ON cce.entity_id = rc.entity_id
2797
- SET ccp.category_id = rc.root_cat
2798
- WHERE cce.entity_id IS NULL");
2799
-
2800
-
2801
-
2802
- echo("\n replaceMagentoProductsMultistoreMERGE 9\n");
2803
-
2804
-
2805
-
2806
-
2807
-
2808
- $result = $this->db_do("
2809
- DELETE ccp
2810
- FROM $catalog_category_product ccp
2811
- LEFT JOIN $catalog_category_entity cce
2812
- ON ccp.category_id = cce.entity_id
2813
- WHERE cce.entity_id IS NULL");
2814
-
2815
-
2816
-
2817
-
2818
- $stinch_products_delete = Mage::getSingleton('core/resource')->getTableName('stinch_products_delete');
2819
-
2820
- $result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
2821
- $result = $this->db_do("
2822
- CREATE TABLE $stinch_products_delete
2823
- SELECT cpe.entity_id
2824
- FROM $catalog_product_entity cpe
2825
- WHERE cpe.entity_id NOT IN
2826
- (
2827
- SELECT cpe2.entity_id
2828
- FROM $catalog_product_entity cpe2
2829
- JOIN $stINch_products sp
2830
- ON cpe2.sinch_product_id = sp.sinch_product_id
2831
- )");
2832
-
2833
-
2834
- $result = $this->db_do("DELETE cpe FROM $catalog_product_entity cpe JOIN $stinch_products_delete spd USING(entity_id)");
2835
-
2836
- $result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
2837
-
2838
-
2839
-
2840
-
2841
-
2842
-
2843
- //echo("\n\nget out...\n\n");
2844
- //return;
2845
-
2846
- /**
2847
-
2848
- echo("\n replaceMagentoProductsMultistoreMERGE 10\n");
2849
-
2850
-
2851
- // TEMPORARY
2852
- $this->db_do(" DROP TABLE IF EXISTS {$catalog_category_product}_for_delete_temp");
2853
- $this->db_do("
2854
- CREATE TABLE `{$catalog_category_product}_for_delete_temp`
2855
- (
2856
- `category_id` int(10) unsigned NOT NULL default '0',
2857
- `product_id` int(10) unsigned NOT NULL default '0',
2858
- `store_product_id` int(10) NOT NULL default '0',
2859
- `store_category_id` int(10) NOT NULL default '0',
2860
- `new_category_id` int(10) NOT NULL default '0',
2861
-
2862
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
2863
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
2864
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
2865
- KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
2866
- )");
2867
-
2868
- echo("\n replaceMagentoProductsMultistoreMERGE 11\n");
2869
-
2870
- $result = $this->db_do("
2871
- INSERT INTO {$catalog_category_product}_for_delete_temp
2872
- (category_id, product_id, store_product_id)
2873
- (SELECT
2874
- ccp.category_id,
2875
- ccp.product_id,
2876
- cpe.store_product_id
2877
- FROM $catalog_category_product ccp
2878
- JOIN $catalog_product_entity cpe
2879
- ON ccp.product_id = cpe.entity_id
2880
- WHERE store_product_id IS NOT NULL)");
2881
-
2882
- echo("\n replaceMagentoProductsMultistoreMERGE 12\n");
2883
-
2884
- $result = $this->db_do("
2885
- UPDATE {$catalog_category_product}_for_delete_temp ccpfd
2886
- JOIN $products_temp p
2887
- ON ccpfd.store_product_id = p.store_product_id
2888
- SET ccpfd.store_category_id = p.store_category_id
2889
- WHERE ccpfd.store_product_id != 0");
2890
-
2891
- echo("\n replaceMagentoProductsMultistoreMERGE 13\n");
2892
-
2893
- $result = $this->db_do("
2894
- UPDATE {$catalog_category_product}_for_delete_temp ccpfd
2895
- JOIN $stINch_categories_mapping scm
2896
- ON ccpfd.store_category_id = scm.store_category_id
2897
- SET ccpfd.new_category_id = scm.shop_entity_id
2898
- WHERE ccpfd.store_category_id != 0");
2899
-
2900
- echo("\n replaceMagentoProductsMultistoreMERGE 14\n");
2901
-
2902
- $result = $this->db_do("DELETE FROM {$catalog_category_product}_for_delete_temp WHERE category_id = new_category_id");
2903
-
2904
-
2905
-
2906
- $result = $this->db_do("
2907
- DELETE ccp
2908
- FROM $catalog_category_product ccp
2909
- JOIN {$catalog_category_product}_for_delete_temp ccpfd
2910
- ON ccp.product_id = ccpfd.product_id
2911
- AND ccp.category_id = ccpfd.category_id");
2912
-
2913
- /**/
2914
-
2915
-
2916
-
2917
- echo("\n replaceMagentoProductsMultistoreMERGE 15\n");
2918
-
2919
-
2920
-
2921
-
2922
- $result = $this->db_do("
2923
- INSERT INTO $catalog_category_product
2924
- (category_id, product_id)
2925
- (SELECT
2926
- scm.shop_entity_id,
2927
- cpe.entity_id
2928
- FROM $catalog_product_entity cpe
2929
- JOIN $products_temp p
2930
- ON cpe.store_product_id = p.store_product_id
2931
- JOIN $stINch_categories_mapping scm
2932
- ON p.store_category_id = scm.store_category_id
2933
- )
2934
- ON DUPLICATE KEY UPDATE
2935
- product_id = cpe.entity_id");
2936
-
2937
-
2938
-
2939
- echo("\n replaceMagentoProductsMultistoreMERGE 15.1 (add multi categories)\n");
2940
-
2941
-
2942
-
2943
-
2944
- $result = $this->db_do("
2945
- INSERT INTO $catalog_category_product
2946
- (category_id, product_id)
2947
- (SELECT
2948
- scm.shop_entity_id,
2949
- cpe.entity_id
2950
- FROM $catalog_product_entity cpe
2951
- JOIN $products_temp p
2952
- ON cpe.store_product_id = p.store_product_id
2953
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
2954
- ON p.store_product_id=spc.store_product_id
2955
- JOIN $stINch_categories_mapping scm
2956
- ON spc.store_category_id = scm.store_category_id
2957
- )
2958
- ON DUPLICATE KEY UPDATE
2959
- product_id = cpe.entity_id
2960
- ");
2961
-
2962
-
2963
-
2964
- echo("\n replaceMagentoProductsMultistoreMERGE 16\n");
2965
-
2966
- //Indexing products and categories in the shop
2967
- $result = $this->db_do("
2968
- DELETE ccpi
2969
- FROM $catalog_category_product_index ccpi
2970
- LEFT JOIN $catalog_product_entity cpe
2971
- ON ccpi.product_id = cpe.entity_id
2972
- WHERE cpe.entity_id IS NULL");
2973
-
2974
-
2975
-
2976
-
2977
-
2978
- echo("\n replaceMagentoProductsMultistoreMERGE 16.2\n");
2979
-
2980
-
2981
- $result = $this->db_do("
2982
- INSERT INTO $catalog_category_product_index
2983
- (category_id, product_id, position, is_parent, store_id, visibility)
2984
- (SELECT
2985
- a.category_id,
2986
- a.product_id,
2987
- a.position,
2988
- 1,
2989
- b.store_id,
2990
- 4
2991
- FROM $catalog_category_product a
2992
- JOIN $core_store b
2993
- )
2994
- ON DUPLICATE KEY UPDATE
2995
- visibility = 4");
2996
-
2997
-
2998
-
2999
- echo("\n replaceMagentoProductsMultistoreMERGE 17\n");
3000
- $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
3001
- // !!! $this->_root_cat
3002
- $result = $this->db_do("
3003
- INSERT ignore INTO $catalog_category_product_index
3004
- (category_id, product_id, position, is_parent, store_id, visibility)
3005
- (SELECT
3006
- rc.root_cat,
3007
- a.product_id,
3008
- a.position,
3009
- 1,
3010
- b.store_id,
3011
- 4
3012
- FROM $catalog_category_product a
3013
- JOIN $root_cats rc
3014
- ON a.category_id = rc.entity_id
3015
- JOIN $core_store b
3016
- )
3017
- ON DUPLICATE KEY UPDATE
3018
- visibility = 4");
3019
-
3020
- echo("\n replaceMagentoProductsMultistoreMERGE 18\n");
3021
-
3022
-
3023
- //Set product name for specific web sites
3024
- $result = $this->db_do("
3025
- DELETE cpev
3026
- FROM $catalog_product_entity_varchar cpev
3027
- LEFT JOIN $catalog_product_entity cpe
3028
- ON cpev.entity_id = cpe.entity_id
3029
- WHERE cpe.entity_id IS NULL");
3030
-
3031
- $result = $this->db_do("
3032
- INSERT INTO $catalog_product_entity_varchar
3033
- (entity_type_id, attribute_id, store_id, entity_id, value)
3034
- (SELECT
3035
- $_getProductEntityTypeId,
3036
- $attr_name,
3037
- w.website,
3038
- a.entity_id,
3039
- b.product_name
3040
- FROM $catalog_product_entity a
3041
- JOIN $products_temp b
3042
- ON a.store_product_id = b.store_product_id
3043
- JOIN $products_website_temp w
3044
- ON a.store_product_id = w.store_product_id
3045
- )
3046
- ON DUPLICATE KEY UPDATE
3047
- value = b.product_name");
3048
-
3049
- echo("\n replaceMagentoProductsMultistoreMERGE 19\n");
3050
-
3051
-
3052
-
3053
-
3054
-
3055
- // product name for all web sites
3056
- $result = $this->db_do("
3057
- INSERT INTO $catalog_product_entity_varchar
3058
- (entity_type_id, attribute_id, store_id, entity_id, value)
3059
- (SELECT
3060
- $_getProductEntityTypeId,
3061
- $attr_name,
3062
- 0,
3063
- a.entity_id,
3064
- b.product_name
3065
- FROM $catalog_product_entity a
3066
- JOIN $products_temp b
3067
- ON a.store_product_id = b.store_product_id
3068
- )
3069
- ON DUPLICATE KEY UPDATE
3070
- value = b.product_name");
3071
-
3072
- echo("\n replaceMagentoProductsMultistoreMERGE 20\n");
3073
-
3074
-
3075
-
3076
- $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
3077
- $this->addDescriptions();
3078
- $this->cleanProductDistributors();
3079
- if($this->product_file_format == "NEW"){
3080
- $this->addReviews();
3081
- $this->addWeight();
3082
- $this->addSearchCache();
3083
- $this->addPdfUrl();
3084
- $this->addShortDescriptions();
3085
- $this->addProductDistributors();
3086
- }
3087
- $this->addEAN();
3088
- $this->addSpecification();
3089
- $this->addManufacturers();
3090
-
3091
-
3092
-
3093
-
3094
-
3095
-
3096
-
3097
- echo("\n replaceMagentoProductsMultistoreMERGE 21\n");
3098
-
3099
- //Enabling product index.
3100
- $result = $this->db_do("
3101
- DELETE cpei
3102
- FROM $catalog_product_enabled_index cpei
3103
- LEFT JOIN $catalog_product_entity cpe
3104
- ON cpei.product_id = cpe.entity_id
3105
- WHERE cpe.entity_id IS NULL");
3106
-
3107
-
3108
-
3109
-
3110
-
3111
-
3112
- echo("\n replaceMagentoProductsMultistoreMERGE 22\n");
3113
-
3114
- $result = $this->db_do("
3115
- INSERT INTO $catalog_product_enabled_index
3116
- (product_id, store_id, visibility)
3117
- (SELECT
3118
- a.entity_id,
3119
- w.website,
3120
- 4
3121
- FROM $catalog_product_entity a
3122
- JOIN $products_website_temp w
3123
- ON a.store_product_id = w.store_product_id
3124
- )
3125
- ON DUPLICATE KEY UPDATE
3126
- visibility = 4");
3127
-
3128
- echo("\n replaceMagentoProductsMultistoreMERGE 23\n");
3129
-
3130
- $result = $this->db_do("
3131
- INSERT INTO $catalog_product_enabled_index
3132
- (product_id, store_id, visibility)
3133
- (SELECT
3134
- a.entity_id,
3135
- 0,
3136
- 4
3137
- FROM $catalog_product_entity a
3138
- JOIN $products_website_temp w
3139
- ON a.store_product_id = w.store_product_id
3140
- )
3141
- ON DUPLICATE KEY UPDATE
3142
- visibility = 4");
3143
-
3144
-
3145
- /////////////////////////////////////echo(" .... DONE\n");return;
3146
-
3147
-
3148
- echo("\n replaceMagentoProductsMultistoreMERGE 24\n");
3149
-
3150
- $result = $this->db_do("
3151
- INSERT INTO $catalog_product_entity_int
3152
- (entity_type_id, attribute_id, store_id, entity_id, value)
3153
- (SELECT
3154
- $_getProductEntityTypeId,
3155
- $attr_visibility,
3156
- w.website,
3157
- a.entity_id,
3158
- 4
3159
- FROM $catalog_product_entity a
3160
- JOIN $products_website_temp w
3161
- ON a.store_product_id = w.store_product_id
3162
- )
3163
- ON DUPLICATE KEY UPDATE
3164
- value = 4");
3165
-
3166
- echo("\n replaceMagentoProductsMultistoreMERGE 25\n");
3167
-
3168
- $result = $this->db_do("
3169
- INSERT INTO $catalog_product_entity_int
3170
- (entity_type_id, attribute_id, store_id, entity_id, value)
3171
- (SELECT
3172
- $_getProductEntityTypeId,
3173
- $attr_visibility,
3174
- 0,
3175
- a.entity_id,
3176
- 4
3177
- FROM $catalog_product_entity a
3178
- )
3179
- ON DUPLICATE KEY UPDATE
3180
- value = 4");
3181
-
3182
- echo("\n replaceMagentoProductsMultistoreMERGE 26\n");
3183
-
3184
-
3185
-
3186
- $result = $this->db_do("
3187
- DELETE cpw
3188
- FROM $catalog_product_website cpw
3189
- LEFT JOIN $catalog_product_entity cpe
3190
- ON cpw.product_id = cpe.entity_id
3191
- WHERE cpe.entity_id IS NULL");
3192
-
3193
- echo("\n replaceMagentoProductsMultistoreMERGE 27\n");
3194
-
3195
-
3196
-
3197
-
3198
-
3199
-
3200
-
3201
-
3202
-
3203
-
3204
-
3205
- $result = $this->db_do("
3206
- INSERT INTO $catalog_product_website
3207
- (product_id, website_id)
3208
- (SELECT
3209
- a.entity_id,
3210
- w.website_id
3211
- FROM $catalog_product_entity a
3212
- JOIN $products_website_temp w
3213
- ON a.store_product_id = w.store_product_id
3214
- )
3215
- ON DUPLICATE KEY UPDATE
3216
- product_id = a.entity_id,
3217
- website_id = w.website_id");
3218
-
3219
-
3220
- //echo(" .... DONE\n");return;
3221
-
3222
-
3223
- echo("\n replaceMagentoProductsMultistoreMERGE 28\n");
3224
-
3225
- // temporary disabled mart@bintime.com
3226
- //$result = $this->db_do("
3227
- // UPDATE catalog_category_entity_int a
3228
- // SET a.value = 0
3229
- // WHERE a.attribute_id = 32
3230
- //");
3231
-
3232
-
3233
- //Adding tax class "Taxable Goods"
3234
- $result = $this->db_do("
3235
- INSERT INTO $catalog_product_entity_int
3236
- (entity_type_id, attribute_id, store_id, entity_id, value)
3237
- (SELECT
3238
- $_getProductEntityTypeId,
3239
- $attr_tax_class_id,
3240
- w.website,
3241
- a.entity_id,
3242
- 2
3243
- FROM $catalog_product_entity a
3244
- JOIN $products_website_temp w
3245
- ON a.store_product_id = w.store_product_id
3246
- )
3247
- ON DUPLICATE KEY UPDATE
3248
- value = 2");
3249
-
3250
- echo("\n replaceMagentoProductsMultistoreMERGE 29\n");
3251
-
3252
- $result = $this->db_do("
3253
- INSERT INTO $catalog_product_entity_int
3254
- (entity_type_id, attribute_id, store_id, entity_id, value)
3255
- (SELECT
3256
- $_getProductEntityTypeId,
3257
- $attr_tax_class_id,
3258
- 0,
3259
- a.entity_id,
3260
- 2
3261
- FROM $catalog_product_entity a
3262
- )
3263
- ON DUPLICATE KEY UPDATE
3264
- value = 2");
3265
-
3266
- echo("\n replaceMagentoProductsMultistoreMERGE 30\n");
3267
-
3268
- // Load url Image
3269
- $result = $this->db_do("
3270
- INSERT INTO $catalog_product_entity_varchar
3271
- (entity_type_id, attribute_id, store_id, entity_id, value)
3272
- (SELECT
3273
- $_getProductEntityTypeId,
3274
- $attr_image,
3275
- w.store_id,
3276
- a.entity_id,
3277
- b.main_image_url
3278
- FROM $catalog_product_entity a
3279
- JOIN $core_store w
3280
- JOIN $products_temp b
3281
- ON a.store_product_id = b.store_product_id
3282
- )
3283
- ON DUPLICATE KEY UPDATE
3284
- value = b.main_image_url");
3285
-
3286
- echo("\n replaceMagentoProductsMultistoreMERGE 31\n");
3287
-
3288
- // image for specific web sites
3289
- $result = $this->db_do("
3290
- INSERT INTO $catalog_product_entity_varchar
3291
- (entity_type_id, attribute_id, store_id, entity_id, value)
3292
- (SELECT
3293
- $_getProductEntityTypeId,
3294
- $attr_image,
3295
- 0,
3296
- a.entity_id,
3297
- b.main_image_url
3298
- FROM $catalog_product_entity a
3299
- JOIN $products_temp b
3300
- ON a.store_product_id = b.store_product_id
3301
- )
3302
- ON DUPLICATE KEY UPDATE
3303
- value = b.main_image_url");
3304
-
3305
- echo("\n replaceMagentoProductsMultistoreMERGE 32\n");
3306
-
3307
- // small_image for specific web sites
3308
- $result = $this->db_do("
3309
- INSERT INTO $catalog_product_entity_varchar
3310
- (entity_type_id, attribute_id, store_id, entity_id, value)
3311
- (SELECT
3312
- $_getProductEntityTypeId,
3313
- $attr_small_image,
3314
- w.store_id,
3315
- a.entity_id,
3316
- b.medium_image_url
3317
- FROM $catalog_product_entity a
3318
- JOIN $core_store w
3319
- JOIN $products_temp b
3320
- ON a.store_product_id = b.store_product_id
3321
- )
3322
- ON DUPLICATE KEY UPDATE
3323
- value = b.medium_image_url");
3324
-
3325
- echo("\n replaceMagentoProductsMultistoreMERGE 33\n");
3326
-
3327
- // small_image for all web sites
3328
- $result = $this->db_do("
3329
- INSERT INTO $catalog_product_entity_varchar
3330
- (entity_type_id, attribute_id, store_id, entity_id, value)
3331
- (SELECT
3332
- $_getProductEntityTypeId,
3333
- $attr_small_image,
3334
- 0,
3335
- a.entity_id,
3336
- b.medium_image_url
3337
- FROM $catalog_product_entity a
3338
- JOIN $core_store w
3339
- JOIN $products_temp b
3340
- ON a.store_product_id = b.store_product_id
3341
- )
3342
- ON DUPLICATE KEY UPDATE
3343
- value = b.medium_image_url");
3344
-
3345
- echo("\n replaceMagentoProductsMultistoreMERGE 34\n");
3346
-
3347
- // thumbnail for specific web site
3348
- $result = $this->db_do("
3349
- INSERT INTO $catalog_product_entity_varchar
3350
- (entity_type_id, attribute_id, store_id, entity_id, value)
3351
- (SELECT
3352
- $_getProductEntityTypeId,
3353
- $attr_thumbnail,
3354
- w.store_id,
3355
- a.entity_id,
3356
- b.thumb_image_url
3357
- FROM $catalog_product_entity a
3358
- JOIN $core_store w
3359
- JOIN $products_temp b
3360
- ON a.store_product_id = b.store_product_id
3361
- )
3362
- ON DUPLICATE KEY UPDATE
3363
- value = b.thumb_image_url");
3364
-
3365
- echo("\n replaceMagentoProductsMultistoreMERGE 35\n");
3366
-
3367
- // thumbnail for all web sites
3368
- $result = $this->db_do("
3369
- INSERT INTO $catalog_product_entity_varchar
3370
- (entity_type_id, attribute_id, store_id, entity_id, value)
3371
- (SELECT
3372
- $_getProductEntityTypeId,
3373
- $attr_thumbnail,
3374
- 0,
3375
- a.entity_id,
3376
- b.thumb_image_url
3377
- FROM $catalog_product_entity a
3378
- JOIN $core_store w
3379
- JOIN $products_temp b
3380
- ON a.store_product_id = b.store_product_id
3381
- )
3382
- ON DUPLICATE KEY UPDATE
3383
- value = b.thumb_image_url");
3384
-
3385
- echo("\n replaceMagentoProductsMultistoreMERGE 36\n");
3386
-
3387
-
3388
-
3389
-
3390
-
3391
- /* STP DELETE
3392
- //Refresh fulltext search
3393
- $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
3394
- $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
3395
-
3396
-
3397
- echo("\n replaceMagentoProductsMultistoreMERGE 36.2\n");
3398
- $q = "
3399
- INSERT INTO {$catalogsearch_fulltext}_tmp
3400
- (product_id, store_id, data_index)
3401
- (SELECT
3402
- a.entity_id,
3403
- w.website,
3404
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3405
- FROM $catalog_product_entity a
3406
- JOIN $products_website_temp w
3407
- ON a.store_product_id = w.store_product_id
3408
- LEFT JOIN $catalog_category_product b
3409
- ON a.entity_id = b.product_id
3410
- LEFT JOIN $catalog_category_entity_varchar c
3411
- ON b.category_id = c.entity_id
3412
- AND c.attribute_id = $cat_attr_name
3413
- LEFT JOIN $catalog_product_entity_varchar e
3414
- ON a.entity_id = e.entity_id
3415
- AND e.attribute_id = $attr_name
3416
- LEFT JOIN $catalog_product_website j
3417
- ON a.entity_id = j.product_id
3418
- LEFT JOIN $products_temp f
3419
- ON a.store_product_id = f.store_product_id
3420
- )
3421
- ON DUPLICATE KEY UPDATE
3422
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
3423
- echo("\n\n============================\n$q\n============================\n\n");
3424
-
3425
-
3426
- $result = $this->db_do("
3427
- INSERT INTO {$catalogsearch_fulltext}_tmp
3428
- (product_id, store_id, data_index)
3429
- (SELECT
3430
- a.entity_id,
3431
- w.website,
3432
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3433
- FROM $catalog_product_entity a
3434
- JOIN $products_website_temp w
3435
- ON a.store_product_id = w.store_product_id
3436
- LEFT JOIN $catalog_category_product b
3437
- ON a.entity_id = b.product_id
3438
- LEFT JOIN $catalog_category_entity_varchar c
3439
- ON b.category_id = c.entity_id
3440
- AND c.attribute_id = $cat_attr_name
3441
- LEFT JOIN $catalog_product_entity_varchar e
3442
- ON a.entity_id = e.entity_id
3443
- AND e.attribute_id = $attr_name
3444
- LEFT JOIN $catalog_product_website j
3445
- ON a.entity_id = j.product_id
3446
- LEFT JOIN $products_temp f
3447
- ON a.store_product_id = f.store_product_id
3448
- )
3449
- ON DUPLICATE KEY UPDATE
3450
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
3451
-
3452
- echo("\n replaceMagentoProductsMultistoreMERGE 37\n");
3453
-
3454
-
3455
- $result = $this->db_do("
3456
- INSERT INTO {$catalogsearch_fulltext}_tmp
3457
- (product_id, store_id, data_index)
3458
- (SELECT
3459
- a.entity_id,
3460
- w.website,
3461
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3462
- FROM $catalog_product_entity a
3463
- JOIN $products_website_temp w
3464
- ON a.store_product_id = w.store_product_id
3465
- LEFT JOIN $catalog_category_product b
3466
- ON a.entity_id = b.product_id
3467
- LEFT JOIN $catalog_category_entity_varchar c
3468
- ON b.category_id = c.entity_id
3469
- AND c.attribute_id = $cat_attr_name
3470
- LEFT JOIN $catalog_product_entity_varchar e
3471
- ON a.entity_id = e.entity_id
3472
- AND e.attribute_id = $attr_name
3473
- LEFT JOIN $products_temp f
3474
- ON a.store_product_id = f.store_product_id
3475
- )
3476
- ON DUPLICATE KEY UPDATE
3477
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
3478
-
3479
- echo("\n replaceMagentoProductsMultistoreMERGE 38\n");
3480
-
3481
- $result = $this->db_do("
3482
- DELETE cf
3483
- FROM $catalogsearch_fulltext cf
3484
- LEFT JOIN $catalog_product_entity cpe
3485
- ON cf.product_id = cpe.entity_id
3486
- WHERE cpe.entity_id IS NULL");
3487
-
3488
- echo("\n replaceMagentoProductsMultistoreMERGE 39\n");
3489
-
3490
- $result = $this->db_do("
3491
- INSERT INTO $catalogsearch_fulltext
3492
- (product_id, store_id, data_index)
3493
- (SELECT
3494
- a.product_id,
3495
- a.store_id,
3496
- a.data_index
3497
- FROM {$catalogsearch_fulltext}_tmp a
3498
- )
3499
- ON DUPLICATE KEY UPDATE
3500
- data_index = a.data_index");
3501
-
3502
- echo("\n replaceMagentoProductsMultistoreMERGE 40\n");
3503
-
3504
- $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
3505
- //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
3506
- //TODO add something else
3507
- STP DELETE*/
3508
-
3509
- $this->addRelatedProducts();
3510
- echo("\n replaceMagentoProductsMultistoreMERGE 41\n");
3511
- } //
3512
- ################################################################################################################################################################
3513
-
3514
-
3515
-
3516
-
3517
-
3518
-
3519
-
3520
-
3521
-
3522
-
3523
-
3524
-
3525
-
3526
-
3527
-
3528
-
3529
-
3530
-
3531
-
3532
-
3533
-
3534
-
3535
-
3536
-
3537
-
3538
-
3539
-
3540
-
3541
- ################################################################################################################################################################
3542
- public function replaceMagentoProductsMultistore($coincidence)
3543
- {
3544
-
3545
- echo("\n replaceMagentoProductsMultistore 1\n");
3546
-
3547
-
3548
-
3549
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
3550
-
3551
-
3552
- $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
3553
- $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
3554
- $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
3555
- $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
3556
- $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
3557
- $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
3558
- $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
3559
- $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
3560
- $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
3561
- $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
3562
- $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
3563
- $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
3564
- $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
3565
- //STP DELETE $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
3566
- // $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
3567
- $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
3568
-
3569
- $_getProductEntityTypeId = $this->_getProductEntityTypeId();
3570
- $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
3571
-
3572
- $attr_atatus = $this->_getProductAttributeId('status');
3573
- $attr_name = $this->_getProductAttributeId('name');
3574
- $attr_visibility = $this->_getProductAttributeId('visibility');
3575
- $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
3576
- $attr_image = $this->_getProductAttributeId('image');
3577
- $attr_small_image = $this->_getProductAttributeId('small_image');
3578
- $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
3579
-
3580
- $cat_attr_name = $this->_getCategoryAttributeId('name');
3581
- echo("\n replaceMagentoProductsMultistore 2\n");
3582
-
3583
-
3584
-
3585
-
3586
-
3587
- //clear products, inserting new products and updating old others.
3588
- $query = "
3589
- DELETE cpe
3590
- FROM $catalog_product_entity cpe
3591
- JOIN $stINch_products_mapping pm
3592
- ON cpe.entity_id = pm.entity_id
3593
- WHERE pm.shop_store_product_id IS NOT NULL
3594
- AND pm.store_product_id IS NULL";
3595
- $result = $this->db_do($query);
3596
-
3597
-
3598
-
3599
-
3600
-
3601
- echo("\n replaceMagentoProductsMultistore 3\n");
3602
-
3603
- $result = $this->db_do("
3604
- INSERT INTO $catalog_product_entity
3605
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
3606
- (SELECT
3607
- pm.entity_id,
3608
- $_getProductEntityTypeId,
3609
- $_defaultAttributeSetId,
3610
- 'simple',
3611
- a.product_sku,
3612
- NOW(),
3613
- 0,
3614
- a.store_product_id,
3615
- a.sinch_product_id
3616
- FROM $products_temp a
3617
- LEFT JOIN $stINch_products_mapping pm
3618
- ON a.store_product_id = pm.store_product_id
3619
- AND a.sinch_product_id = pm.sinch_product_id
3620
- WHERE pm.entity_id IS NULL
3621
- )
3622
- ON DUPLICATE KEY UPDATE
3623
- sku = a.product_sku,
3624
- store_product_id = a.store_product_id,
3625
- sinch_product_id = a.sinch_product_id");
3626
- // store_product_id = a.store_product_id,
3627
- // sinch_product_id = a.sinch_product_id
3628
-
3629
- $result = $this->db_do("
3630
- INSERT INTO $catalog_product_entity
3631
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
3632
- (SELECT
3633
- pm.entity_id,
3634
- $_getProductEntityTypeId,
3635
- $_defaultAttributeSetId,
3636
- 'simple',
3637
- a.product_sku,
3638
- NOW(),
3639
- 0,
3640
- a.store_product_id,
3641
- a.sinch_product_id
3642
- FROM $products_temp a
3643
- LEFT JOIN $stINch_products_mapping pm
3644
- ON a.store_product_id = pm.store_product_id
3645
- AND a.sinch_product_id = pm.sinch_product_id
3646
- WHERE pm.entity_id IS NOT NULL
3647
- )
3648
- ON DUPLICATE KEY UPDATE
3649
- sku = a.product_sku,
3650
- store_product_id = a.store_product_id,
3651
- sinch_product_id = a.sinch_product_id");
3652
- // store_product_id = a.store_product_id,
3653
- // sinch_product_id = a.sinch_product_id
3654
-
3655
- echo("\n replaceMagentoProductsMultistore 4\n");
3656
-
3657
-
3658
-
3659
-
3660
-
3661
- //Set enabled
3662
- $result = $this->db_do("
3663
- DELETE cpei
3664
- FROM $catalog_product_entity_int cpei
3665
- LEFT JOIN $catalog_product_entity cpe
3666
- ON cpei.entity_id = cpe.entity_id
3667
- WHERE cpe.entity_id IS NULL");
3668
-
3669
- $result = $this->db_do("
3670
- INSERT INTO $catalog_product_entity_int
3671
- (entity_type_id, attribute_id, store_id, entity_id, value)
3672
- (SELECT
3673
- $_getProductEntityTypeId,
3674
- $attr_atatus,
3675
- w.website,
3676
- a.entity_id,
3677
- 1
3678
- FROM $catalog_product_entity a
3679
- JOIN $products_website_temp w
3680
- ON a.store_product_id = w.store_product_id
3681
- )
3682
- ON DUPLICATE KEY UPDATE
3683
- value = 1");
3684
-
3685
-
3686
-
3687
-
3688
-
3689
- echo("\n replaceMagentoProductsMultistore 5\n");
3690
-
3691
-
3692
- // set status = 1 for all stores
3693
- $result = $this->db_do("
3694
- INSERT INTO $catalog_product_entity_int
3695
- (entity_type_id, attribute_id, store_id, entity_id, value)
3696
- (SELECT
3697
- $_getProductEntityTypeId,
3698
- $attr_atatus,
3699
- 0,
3700
- a.entity_id,
3701
- 1
3702
- FROM $catalog_product_entity a
3703
- )
3704
- ON DUPLICATE KEY UPDATE
3705
- value = 1");
3706
-
3707
-
3708
-
3709
-
3710
-
3711
- echo("\n replaceMagentoProductsMultistore 6\n");
3712
-
3713
-
3714
- //Unifying products with categories.
3715
- $result = $this->db_do("
3716
- DELETE ccp
3717
- FROM $catalog_category_product ccp
3718
- LEFT JOIN $catalog_product_entity cpe
3719
- ON ccp.product_id = cpe.entity_id
3720
- WHERE cpe.entity_id IS NULL");
3721
-
3722
-
3723
-
3724
-
3725
-
3726
-
3727
-
3728
- echo("\n replaceMagentoProductsMultistore 7\n");
3729
-
3730
-
3731
-
3732
- $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
3733
-
3734
-
3735
- $result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
3736
- $result = $this->db_do("
3737
- CREATE TABLE $root_cats
3738
- SELECT
3739
- entity_id,
3740
- path,
3741
- SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
3742
- LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
3743
- SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
3744
- FROM $catalog_category_entity
3745
- ");
3746
- $result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
3747
-
3748
-
3749
- echo("\n replaceMagentoProductsMultistore 8\n");
3750
-
3751
-
3752
- // !!! $this->_root_cat
3753
- $result = $this->db_do("
3754
- UPDATE IGNORE $catalog_category_product ccp
3755
- LEFT JOIN $catalog_category_entity cce
3756
- ON ccp.category_id = cce.entity_id
3757
- JOIN $root_cats rc
3758
- ON cce.entity_id = rc.entity_id
3759
- SET ccp.category_id = rc.root_cat
3760
- WHERE cce.entity_id IS NULL");
3761
-
3762
-
3763
-
3764
- echo("\n replaceMagentoProductsMultistore 9\n");
3765
-
3766
-
3767
-
3768
-
3769
-
3770
- $result = $this->db_do("
3771
- DELETE ccp
3772
- FROM $catalog_category_product ccp
3773
- LEFT JOIN $catalog_category_entity cce
3774
- ON ccp.category_id = cce.entity_id
3775
- WHERE cce.entity_id IS NULL");
3776
-
3777
-
3778
- //echo("\n\nget out...\n\n");
3779
- //return;
3780
-
3781
-
3782
-
3783
-
3784
-
3785
- echo("\n replaceMagentoProductsMultistore 10\n");
3786
-
3787
-
3788
- $catalog_category_product_for_delete_temp = $catalog_category_product."_for_delete_temp";
3789
-
3790
- // TEMPORARY
3791
- $this->db_do(" DROP TABLE IF EXISTS $catalog_category_product_for_delete_temp");
3792
- $this->db_do("
3793
- CREATE TABLE $catalog_category_product_for_delete_temp
3794
- (
3795
- `category_id` int(10) unsigned NOT NULL default '0',
3796
- `product_id` int(10) unsigned NOT NULL default '0',
3797
- `store_product_id` int(10) NOT NULL default '0',
3798
- `store_category_id` int(10) NOT NULL default '0',
3799
- `new_category_id` int(10) NOT NULL default '0',
3800
-
3801
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
3802
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
3803
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
3804
- KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
3805
- )");
3806
-
3807
- echo("\n replaceMagentoProductsMultistore 11\n");
3808
-
3809
- $result = $this->db_do("
3810
- INSERT INTO $catalog_category_product_for_delete_temp
3811
- (category_id, product_id, store_product_id)
3812
- (SELECT
3813
- ccp.category_id,
3814
- ccp.product_id,
3815
- cpe.store_product_id
3816
- FROM $catalog_category_product ccp
3817
- JOIN $catalog_product_entity cpe
3818
- ON ccp.product_id = cpe.entity_id
3819
- WHERE store_product_id IS NOT NULL)");
3820
-
3821
- echo("\n replaceMagentoProductsMultistore 12\n");
3822
-
3823
- $result = $this->db_do("
3824
- UPDATE $catalog_category_product_for_delete_temp ccpfd
3825
- JOIN $products_temp p
3826
- ON ccpfd.store_product_id = p.store_product_id
3827
- SET ccpfd.store_category_id = p.store_category_id
3828
- WHERE ccpfd.store_product_id != 0");
3829
-
3830
- echo("\n replaceMagentoProductsMultistore 13\n");
3831
-
3832
- $result = $this->db_do("
3833
- UPDATE $catalog_category_product_for_delete_temp ccpfd
3834
- JOIN $stINch_categories_mapping scm
3835
- ON ccpfd.store_category_id = scm.store_category_id
3836
- SET ccpfd.new_category_id = scm.shop_entity_id
3837
- WHERE ccpfd.store_category_id != 0");
3838
-
3839
- echo("\n replaceMagentoProductsMultistore 14\n");
3840
-
3841
- $result = $this->db_do("DELETE FROM $catalog_category_product_for_delete_temp WHERE category_id = new_category_id");
3842
-
3843
-
3844
-
3845
- $result = $this->db_do("
3846
- DELETE ccp
3847
- FROM $catalog_category_product ccp
3848
- JOIN $catalog_category_product_for_delete_temp ccpfd
3849
- ON ccp.product_id = ccpfd.product_id
3850
- AND ccp.category_id = ccpfd.category_id");
3851
-
3852
-
3853
- //echo("\n\nget out...\n\n");
3854
- //return;
3855
-
3856
-
3857
- echo("\n replaceMagentoProductsMultistore 15\n");
3858
-
3859
- $result = $this->db_do("
3860
- INSERT INTO $catalog_category_product
3861
- (category_id, product_id)
3862
- (SELECT
3863
- scm.shop_entity_id,
3864
- cpe.entity_id
3865
- FROM $catalog_product_entity cpe
3866
- JOIN $products_temp p
3867
- ON cpe.store_product_id = p.store_product_id
3868
- JOIN $stINch_categories_mapping scm
3869
- ON p.store_category_id = scm.store_category_id
3870
- )
3871
- ON DUPLICATE KEY UPDATE
3872
- product_id = cpe.entity_id");
3873
-
3874
-
3875
- echo("\n replaceMagentoProductsMultistore 15.1 (add multi categories)\n");
3876
-
3877
- $result = $this->db_do("
3878
- INSERT INTO $catalog_category_product
3879
- (category_id, product_id)
3880
- (SELECT
3881
- scm.shop_entity_id,
3882
- cpe.entity_id
3883
- FROM $catalog_product_entity cpe
3884
- JOIN $products_temp p
3885
- ON cpe.store_product_id = p.store_product_id
3886
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
3887
- ON p.store_product_id=spc.store_product_id
3888
- JOIN $stINch_categories_mapping scm
3889
- ON spc.store_category_id = scm.store_category_id
3890
- )
3891
- ON DUPLICATE KEY UPDATE
3892
- product_id = cpe.entity_id
3893
- ");
3894
-
3895
-
3896
-
3897
-
3898
- echo("\n replaceMagentoProductsMultistore 16\n");
3899
-
3900
- //Indexing products and categories in the shop
3901
- $result = $this->db_do("
3902
- DELETE ccpi
3903
- FROM $catalog_category_product_index ccpi
3904
- LEFT JOIN $catalog_product_entity cpe
3905
- ON ccpi.product_id = cpe.entity_id
3906
- WHERE cpe.entity_id IS NULL");
3907
-
3908
-
3909
-
3910
- echo("\n replaceMagentoProductsMultistore 16.2\n");
3911
-
3912
-
3913
- $result = $this->db_do("
3914
- INSERT INTO $catalog_category_product_index
3915
- (category_id, product_id, position, is_parent, store_id, visibility)
3916
- (SELECT
3917
- a.category_id,
3918
- a.product_id,
3919
- a.position,
3920
- 1,
3921
- b.store_id,
3922
- 4
3923
- FROM $catalog_category_product a
3924
- JOIN $core_store b
3925
- )
3926
- ON DUPLICATE KEY UPDATE
3927
- visibility = 4");
3928
-
3929
-
3930
-
3931
- echo("\n replaceMagentoProductsMultistore 17\n");
3932
-
3933
- // !!! $this->_root_cat
3934
- $result = $this->db_do("
3935
- INSERT ignore INTO $catalog_category_product_index
3936
- (category_id, product_id, position, is_parent, store_id, visibility)
3937
- (SELECT
3938
- rc.root_cat,
3939
- a.product_id,
3940
- a.position,
3941
- 1,
3942
- b.store_id,
3943
- 4
3944
- FROM $catalog_category_product a
3945
- JOIN $root_cats rc
3946
- ON a.category_id = rc.entity_id
3947
- JOIN $core_store b
3948
- )
3949
- ON DUPLICATE KEY UPDATE
3950
- visibility = 4");
3951
-
3952
- echo("\n replaceMagentoProductsMultistore 18\n");
3953
-
3954
-
3955
- //Set product name for specific web sites
3956
- $result = $this->db_do("
3957
- DELETE cpev
3958
- FROM $catalog_product_entity_varchar cpev
3959
- LEFT JOIN $catalog_product_entity cpe
3960
- ON cpev.entity_id = cpe.entity_id
3961
- WHERE cpe.entity_id IS NULL");
3962
-
3963
- $result = $this->db_do("
3964
- INSERT INTO $catalog_product_entity_varchar
3965
- (entity_type_id, attribute_id, store_id, entity_id, value)
3966
- (SELECT
3967
- $_getProductEntityTypeId,
3968
- $attr_name,
3969
- w.website,
3970
- a.entity_id,
3971
- b.product_name
3972
- FROM $catalog_product_entity a
3973
- JOIN $products_temp b
3974
- ON a.store_product_id = b.store_product_id
3975
- JOIN $products_website_temp w
3976
- ON a.store_product_id = w.store_product_id
3977
- )
3978
- ON DUPLICATE KEY UPDATE
3979
- value = b.product_name");
3980
-
3981
- echo("\n replaceMagentoProductsMultistore 19\n");
3982
-
3983
-
3984
- // product name for all web sites
3985
- $result = $this->db_do("
3986
- INSERT INTO $catalog_product_entity_varchar
3987
- (entity_type_id, attribute_id, store_id, entity_id, value)
3988
- (SELECT
3989
- $_getProductEntityTypeId,
3990
- $attr_name,
3991
- 0,
3992
- a.entity_id,
3993
- b.product_name
3994
- FROM $catalog_product_entity a
3995
- JOIN $products_temp b
3996
- ON a.store_product_id = b.store_product_id
3997
- )
3998
- ON DUPLICATE KEY UPDATE
3999
- value = b.product_name");
4000
-
4001
- echo("\n replaceMagentoProductsMultistore 20\n");
4002
-
4003
-
4004
-
4005
- $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
4006
- $this->addDescriptions();
4007
- $this->cleanProductDistributors();
4008
- if($this->product_file_format == "NEW"){
4009
- $this->addReviews();
4010
- $this->addWeight();
4011
- $this->addSearchCache();
4012
- $this->addPdfUrl();
4013
- $this->addShortDescriptions();
4014
- $this->addProductDistributors();
4015
- }
4016
- $this->addEAN();
4017
- $this->addSpecification();
4018
- $this->addManufacturers();
4019
-
4020
- //echo(" .... DONE\n");return;
4021
-
4022
- echo("\n replaceMagentoProductsMultistore 21\n");
4023
-
4024
- //Enabling product index.
4025
- $result = $this->db_do("
4026
- DELETE cpei
4027
- FROM $catalog_product_enabled_index cpei
4028
- LEFT JOIN $catalog_product_entity cpe
4029
- ON cpei.product_id = cpe.entity_id
4030
- WHERE cpe.entity_id IS NULL");
4031
-
4032
- echo("\n replaceMagentoProductsMultistore 22\n");
4033
-
4034
- $result = $this->db_do("
4035
- INSERT INTO $catalog_product_enabled_index
4036
- (product_id, store_id, visibility)
4037
- (SELECT
4038
- a.entity_id,
4039
- w.website,
4040
- 4
4041
- FROM $catalog_product_entity a
4042
- JOIN $products_website_temp w
4043
- ON a.store_product_id = w.store_product_id
4044
- )
4045
- ON DUPLICATE KEY UPDATE
4046
- visibility = 4");
4047
-
4048
- echo("\n replaceMagentoProductsMultistore 23\n");
4049
-
4050
- $result = $this->db_do("
4051
- INSERT INTO $catalog_product_enabled_index
4052
- (product_id, store_id, visibility)
4053
- (SELECT
4054
- a.entity_id,
4055
- 0,
4056
- 4
4057
- FROM $catalog_product_entity a
4058
- JOIN $products_website_temp w
4059
- ON a.store_product_id = w.store_product_id
4060
- )
4061
- ON DUPLICATE KEY UPDATE
4062
- visibility = 4");
4063
-
4064
-
4065
- /////////////////////////////////////echo(" .... DONE\n");return;
4066
-
4067
-
4068
- echo("\n replaceMagentoProductsMultistore 24\n");
4069
-
4070
- $result = $this->db_do("
4071
- INSERT INTO $catalog_product_entity_int
4072
- (entity_type_id, attribute_id, store_id, entity_id, value)
4073
- (SELECT
4074
- $_getProductEntityTypeId,
4075
- $attr_visibility,
4076
- w.website,
4077
- a.entity_id,
4078
- 4
4079
- FROM $catalog_product_entity a
4080
- JOIN $products_website_temp w
4081
- ON a.store_product_id = w.store_product_id
4082
- )
4083
- ON DUPLICATE KEY UPDATE
4084
- value = 4");
4085
-
4086
- echo("\n replaceMagentoProductsMultistore 25\n");
4087
-
4088
- $result = $this->db_do("
4089
- INSERT INTO $catalog_product_entity_int
4090
- (entity_type_id, attribute_id, store_id, entity_id, value)
4091
- (SELECT
4092
- $_getProductEntityTypeId,
4093
- $attr_visibility,
4094
- 0,
4095
- a.entity_id,
4096
- 4
4097
- FROM $catalog_product_entity a
4098
- )
4099
- ON DUPLICATE KEY UPDATE
4100
- value = 4");
4101
-
4102
- echo("\n replaceMagentoProductsMultistore 26\n");
4103
-
4104
- $result = $this->db_do("
4105
- DELETE cpw
4106
- FROM $catalog_product_website cpw
4107
- LEFT JOIN $catalog_product_entity cpe
4108
- ON cpw.product_id = cpe.entity_id
4109
- WHERE cpe.entity_id IS NULL");
4110
-
4111
- echo("\n replaceMagentoProductsMultistore 27\n");
4112
-
4113
- $result = $this->db_do("
4114
- INSERT INTO $catalog_product_website
4115
- (product_id, website_id)
4116
- (SELECT
4117
- a.entity_id,
4118
- w.website_id
4119
- FROM $catalog_product_entity a
4120
- JOIN $products_website_temp w
4121
- ON a.store_product_id = w.store_product_id
4122
- )
4123
- ON DUPLICATE KEY UPDATE
4124
- product_id = a.entity_id,
4125
- website_id = w.website_id");
4126
-
4127
-
4128
- //echo(" .... DONE\n");return;
4129
-
4130
-
4131
- echo("\n replaceMagentoProductsMultistore 28\n");
4132
-
4133
- // temporary disabled mart@bintime.com
4134
- //$result = $this->db_do("
4135
- // UPDATE catalog_category_entity_int a
4136
- // SET a.value = 0
4137
- // WHERE a.attribute_id = 32
4138
- //");
4139
-
4140
-
4141
- //Adding tax class "Taxable Goods"
4142
- $result = $this->db_do("
4143
- INSERT INTO $catalog_product_entity_int
4144
- (entity_type_id, attribute_id, store_id, entity_id, value)
4145
- (SELECT
4146
- $_getProductEntityTypeId,
4147
- $attr_tax_class_id,
4148
- w.website,
4149
- a.entity_id,
4150
- 2
4151
- FROM $catalog_product_entity a
4152
- JOIN $products_website_temp w
4153
- ON a.store_product_id = w.store_product_id
4154
- )
4155
- ON DUPLICATE KEY UPDATE
4156
- value = 2");
4157
-
4158
- echo("\n replaceMagentoProductsMultistore 29\n");
4159
-
4160
- $result = $this->db_do("
4161
- INSERT INTO $catalog_product_entity_int
4162
- (entity_type_id, attribute_id, store_id, entity_id, value)
4163
- (SELECT
4164
- $_getProductEntityTypeId,
4165
- $attr_tax_class_id,
4166
- 0,
4167
- a.entity_id,
4168
- 2
4169
- FROM $catalog_product_entity a
4170
- )
4171
- ON DUPLICATE KEY UPDATE
4172
- value = 2");
4173
-
4174
- echo("\n replaceMagentoProductsMultistore 30\n");
4175
-
4176
- // Load url Image
4177
- $result = $this->db_do("
4178
- INSERT INTO $catalog_product_entity_varchar
4179
- (entity_type_id, attribute_id, store_id, entity_id, value)
4180
- (SELECT
4181
- $_getProductEntityTypeId,
4182
- $attr_image,
4183
- w.store_id,
4184
- a.entity_id,
4185
- b.main_image_url
4186
- FROM $catalog_product_entity a
4187
- JOIN $core_store w
4188
- JOIN $products_temp b
4189
- ON a.store_product_id = b.store_product_id
4190
- )
4191
- ON DUPLICATE KEY UPDATE
4192
- value = b.main_image_url");
4193
-
4194
- echo("\n replaceMagentoProductsMultistore 31\n");
4195
-
4196
- // image for specific web sites
4197
- $result = $this->db_do("
4198
- INSERT INTO $catalog_product_entity_varchar
4199
- (entity_type_id, attribute_id, store_id, entity_id, value)
4200
- (SELECT
4201
- $_getProductEntityTypeId,
4202
- $attr_image,
4203
- 0,
4204
- a.entity_id,
4205
- b.main_image_url
4206
- FROM $catalog_product_entity a
4207
- JOIN $products_temp b
4208
- ON a.store_product_id = b.store_product_id
4209
- )
4210
- ON DUPLICATE KEY UPDATE
4211
- value = b.main_image_url");
4212
-
4213
- echo("\n replaceMagentoProductsMultistore 32\n");
4214
-
4215
- // small_image for specific web sites
4216
- $result = $this->db_do("
4217
- INSERT INTO $catalog_product_entity_varchar
4218
- (entity_type_id, attribute_id, store_id, entity_id, value)
4219
- (SELECT
4220
- $_getProductEntityTypeId,
4221
- $attr_small_image,
4222
- w.store_id,
4223
- a.entity_id,
4224
- b.medium_image_url
4225
- FROM $catalog_product_entity a
4226
- JOIN $core_store w
4227
- JOIN $products_temp b
4228
- ON a.store_product_id = b.store_product_id
4229
- )
4230
- ON DUPLICATE KEY UPDATE
4231
- value = b.medium_image_url");
4232
-
4233
- echo("\n replaceMagentoProductsMultistore 33\n");
4234
-
4235
- // small_image for all web sites
4236
- $result = $this->db_do("
4237
- INSERT INTO $catalog_product_entity_varchar
4238
- (entity_type_id, attribute_id, store_id, entity_id, value)
4239
- (SELECT
4240
- $_getProductEntityTypeId,
4241
- $attr_small_image,
4242
- 0,
4243
- a.entity_id,
4244
- b.medium_image_url
4245
- FROM $catalog_product_entity a
4246
- JOIN $core_store w
4247
- JOIN $products_temp b
4248
- ON a.store_product_id = b.store_product_id
4249
- )
4250
- ON DUPLICATE KEY UPDATE
4251
- value = b.medium_image_url");
4252
-
4253
- echo("\n replaceMagentoProductsMultistore 34\n");
4254
-
4255
- // thumbnail for specific web site
4256
- $result = $this->db_do("
4257
- INSERT INTO $catalog_product_entity_varchar
4258
- (entity_type_id, attribute_id, store_id, entity_id, value)
4259
- (SELECT
4260
- $_getProductEntityTypeId,
4261
- $attr_thumbnail,
4262
- w.store_id,
4263
- a.entity_id,
4264
- b.thumb_image_url
4265
- FROM $catalog_product_entity a
4266
- JOIN $core_store w
4267
- JOIN $products_temp b
4268
- ON a.store_product_id = b.store_product_id
4269
- )
4270
- ON DUPLICATE KEY UPDATE
4271
- value = b.thumb_image_url");
4272
-
4273
- echo("\n replaceMagentoProductsMultistore 35\n");
4274
-
4275
- // thumbnail for all web sites
4276
- $result = $this->db_do("
4277
- INSERT INTO $catalog_product_entity_varchar
4278
- (entity_type_id, attribute_id, store_id, entity_id, value)
4279
- (SELECT
4280
- $_getProductEntityTypeId,
4281
- $attr_thumbnail,
4282
- 0,
4283
- a.entity_id,
4284
- b.thumb_image_url
4285
- FROM $catalog_product_entity a
4286
- JOIN $core_store w
4287
- JOIN $products_temp b
4288
- ON a.store_product_id = b.store_product_id
4289
- )
4290
- ON DUPLICATE KEY UPDATE
4291
- value = b.thumb_image_url");
4292
-
4293
- echo("\n replaceMagentoProductsMultistore 36\n");
4294
-
4295
-
4296
-
4297
-
4298
-
4299
- /*STP DELETE
4300
- //Refresh fulltext search
4301
- $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
4302
- $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
4303
-
4304
-
4305
- echo("\n replaceMagentoProductsMultistore 36.2\n");
4306
- $q = "
4307
- INSERT INTO {$catalogsearch_fulltext}_tmp
4308
- (product_id, store_id, data_index)
4309
- (SELECT
4310
- a.entity_id,
4311
- w.website,
4312
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4313
- FROM $catalog_product_entity a
4314
- JOIN $products_website_temp w
4315
- ON a.store_product_id = w.store_product_id
4316
- LEFT JOIN $catalog_category_product b
4317
- ON a.entity_id = b.product_id
4318
- LEFT JOIN $catalog_category_entity_varchar c
4319
- ON b.category_id = c.entity_id
4320
- AND c.attribute_id = $cat_attr_name
4321
- LEFT JOIN $catalog_product_entity_varchar e
4322
- ON a.entity_id = e.entity_id
4323
- AND e.attribute_id = $attr_name
4324
- LEFT JOIN $catalog_product_website j
4325
- ON a.entity_id = j.product_id
4326
- LEFT JOIN $products_temp f
4327
- ON a.store_product_id = f.store_product_id
4328
- )
4329
- ON DUPLICATE KEY UPDATE
4330
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
4331
- echo("\n\n============================\n$q\n============================\n\n");
4332
-
4333
-
4334
- $result = $this->db_do("
4335
- INSERT INTO {$catalogsearch_fulltext}_tmp
4336
- (product_id, store_id, data_index)
4337
- (SELECT
4338
- a.entity_id,
4339
- w.website,
4340
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4341
- FROM $catalog_product_entity a
4342
- JOIN $products_website_temp w
4343
- ON a.store_product_id = w.store_product_id
4344
- LEFT JOIN $catalog_category_product b
4345
- ON a.entity_id = b.product_id
4346
- LEFT JOIN $catalog_category_entity_varchar c
4347
- ON b.category_id = c.entity_id
4348
- AND c.attribute_id = $cat_attr_name
4349
- LEFT JOIN $catalog_product_entity_varchar e
4350
- ON a.entity_id = e.entity_id
4351
- AND e.attribute_id = $attr_name
4352
- LEFT JOIN $catalog_product_website j
4353
- ON a.entity_id = j.product_id
4354
- LEFT JOIN $products_temp f
4355
- ON a.store_product_id = f.store_product_id
4356
- )
4357
- ON DUPLICATE KEY UPDATE
4358
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
4359
-
4360
- echo("\n replaceMagentoProductsMultistore 37\n");
4361
-
4362
-
4363
- $result = $this->db_do("
4364
- INSERT INTO {$catalogsearch_fulltext}_tmp
4365
- (product_id, store_id, data_index)
4366
- (SELECT
4367
- a.entity_id,
4368
- w.website,
4369
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4370
- FROM $catalog_product_entity a
4371
- JOIN $products_website_temp w
4372
- ON a.store_product_id = w.store_product_id
4373
- LEFT JOIN $catalog_category_product b
4374
- ON a.entity_id = b.product_id
4375
- LEFT JOIN $catalog_category_entity_varchar c
4376
- ON b.category_id = c.entity_id
4377
- AND c.attribute_id = $cat_attr_name
4378
- LEFT JOIN $catalog_product_entity_varchar e
4379
- ON a.entity_id = e.entity_id
4380
- AND e.attribute_id = $attr_name
4381
- LEFT JOIN $products_temp f
4382
- ON a.store_product_id = f.store_product_id
4383
- )
4384
- ON DUPLICATE KEY UPDATE
4385
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
4386
-
4387
- echo("\n replaceMagentoProductsMultistore 38\n");
4388
-
4389
- $result = $this->db_do("
4390
- DELETE cf
4391
- FROM $catalogsearch_fulltext cf
4392
- LEFT JOIN $catalog_product_entity cpe
4393
- ON cf.product_id = cpe.entity_id
4394
- WHERE cpe.entity_id IS NULL");
4395
-
4396
- echo("\n replaceMagentoProductsMultistore 39\n");
4397
-
4398
- $result = $this->db_do("
4399
- INSERT INTO $catalogsearch_fulltext
4400
- (product_id, store_id, data_index)
4401
- (SELECT
4402
- a.product_id,
4403
- a.store_id,
4404
- a.data_index
4405
- FROM {$catalogsearch_fulltext}_tmp a
4406
- )
4407
- ON DUPLICATE KEY UPDATE
4408
- data_index = a.data_index");
4409
-
4410
- echo("\n replaceMagentoProductsMultistore 40\n");
4411
-
4412
- $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
4413
- //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
4414
- //TODO add something else
4415
- STP DELETE*/
4416
-
4417
- $this->addRelatedProducts();
4418
- echo("\n replaceMagentoProductsMultistore 41\n");
4419
- } //
4420
- ################################################################################################################################################################
4421
-
4422
-
4423
-
4424
-
4425
-
4426
-
4427
-
4428
-
4429
-
4430
-
4431
-
4432
-
4433
-
4434
-
4435
-
4436
-
4437
-
4438
-
4439
-
4440
-
4441
-
4442
-
4443
-
4444
-
4445
-
4446
-
4447
-
4448
-
4449
-
4450
-
4451
-
4452
-
4453
-
4454
-
4455
-
4456
-
4457
-
4458
-
4459
-
4460
-
4461
-
4462
-
4463
-
4464
-
4465
-
4466
-
4467
-
4468
-
4469
-
4470
-
4471
-
4472
-
4473
-
4474
-
4475
-
4476
-
4477
-
4478
-
4479
-
4480
-
4481
-
4482
-
4483
-
4484
-
4485
-
4486
-
4487
-
4488
-
4489
-
4490
-
4491
-
4492
-
4493
-
4494
-
4495
-
4496
-
4497
-
4498
-
4499
-
4500
-
4501
-
4502
-
4503
-
4504
-
4505
-
4506
-
4507
-
4508
-
4509
-
4510
- ################################################################################################################################################################
4511
- private function truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
4512
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
4513
- $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
4514
- {
4515
- $this->db_do('SET foreign_key_checks=0');
4516
-
4517
- $this->db_do("TRUNCATE $catalog_category_entity");
4518
- $this->db_do("
4519
- INSERT $catalog_category_entity
4520
- (
4521
- entity_id,
4522
- entity_type_id,
4523
- attribute_set_id,
4524
- parent_id,
4525
- created_at,
4526
- updated_at,
4527
- path,
4528
- position,
4529
- level,
4530
- children_count,
4531
- store_category_id,
4532
- parent_store_category_id
4533
- )
4534
- VALUES
4535
- (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
4536
- (2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 1, null, null)");
4537
-
4538
- $this->db_do("TRUNCATE $catalog_category_entity_varchar");
4539
- $this->db_do("
4540
- INSERT $catalog_category_entity_varchar
4541
- (
4542
- value_id,
4543
- entity_type_id,
4544
- attribute_id,
4545
- store_id,
4546
- entity_id,
4547
- value
4548
- )
4549
- VALUES
4550
- (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
4551
- (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
4552
- (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog'),
4553
- (4, $_categoryEntityTypeId, $name_attrid, 0, 2, 'Default Category'),
4554
- (5, $_categoryEntityTypeId, $name_attrid, 1, 2, 'Default Category'),
4555
- (6, $_categoryEntityTypeId, $attr_display_mode, 1, 2, 'PRODUCTS'),
4556
- (7, $_categoryEntityTypeId, $attr_url_key, 0, 2, 'default-category')");
4557
-
4558
- $this->db_do("TRUNCATE $catalog_category_entity_int");
4559
- $this->db_do("
4560
- INSERT $catalog_category_entity_int
4561
- (
4562
- value_id,
4563
- entity_type_id,
4564
- attribute_id,
4565
- store_id,
4566
- entity_id,
4567
- value
4568
- )
4569
- VALUES
4570
- (1, $_categoryEntityTypeId, $attr_is_active, 0, 2, 1),
4571
- (2, $_categoryEntityTypeId, $attr_is_active, 1, 2, 1),
4572
- (3, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1),
4573
- (4, $_categoryEntityTypeId, $attr_include_in_menu, 0, 2, 1)");
4574
-
4575
- return $root_cat;
4576
- } // private function truncateAllCateriesAndRecreateDefaults(...)
4577
- ################################################################################################################################################################
4578
-
4579
-
4580
-
4581
- ################################################################################################################################################################
4582
- private function setCategorySettings($categories_temp, $root_cat)
4583
- {
4584
- $this->db_do("
4585
- UPDATE $categories_temp
4586
- SET parent_store_category_id = $root_cat
4587
- WHERE parent_store_category_id = 0");
4588
-
4589
- $store_cat_ids = $this->db_do("SELECT store_category_id FROM $categories_temp");
4590
- while ($row = mysqli_fetch_array($store_cat_ids))
4591
- {
4592
- $store_category_id = $row['store_category_id'];
4593
-
4594
- $children_count = $this->count_children($store_category_id);
4595
- $level = $this->get_category_level($store_category_id);
4596
-
4597
- $this->db_do("
4598
- UPDATE $categories_temp
4599
- SET children_count = $children_count,
4600
- level = $level
4601
- WHERE store_category_id = $store_category_id");
4602
- }
4603
- } // private function setCategorySettings($categories_temp, $root_cat)
4604
- ################################################################################################################################################################
4605
-
4606
-
4607
-
4608
-
4609
-
4610
-
4611
-
4612
- ################################################################################################################################################################
4613
- public function mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat)
4614
- {
4615
- $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
4616
-
4617
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
4618
-
4619
- $this->db_do("
4620
- CREATE TABLE $stINch_categories_mapping_temp
4621
- (
4622
- shop_entity_id INT(11) UNSIGNED NOT NULL,
4623
- shop_entity_type_id INT(11),
4624
- shop_attribute_set_id INT(11),
4625
- shop_parent_id INT(11),
4626
- shop_store_category_id INT(11),
4627
- shop_parent_store_category_id INT(11),
4628
- store_category_id INT(11),
4629
- parent_store_category_id INT(11),
4630
- category_name VARCHAR(255),
4631
- order_number INT(11),
4632
- products_within_this_category INT(11),
4633
-
4634
- KEY shop_entity_id (shop_entity_id),
4635
- KEY shop_parent_id (shop_parent_id),
4636
- KEY store_category_id (store_category_id),
4637
- KEY parent_store_category_id (parent_store_category_id),
4638
- UNIQUE KEY(shop_entity_id)
4639
- )");
4640
-
4641
- $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
4642
-
4643
- $this->db_do("
4644
- INSERT IGNORE INTO $stINch_categories_mapping_temp
4645
- (
4646
- shop_entity_id,
4647
- shop_entity_type_id,
4648
- shop_attribute_set_id,
4649
- shop_parent_id,
4650
- shop_store_category_id,
4651
- shop_parent_store_category_id
4652
- )
4653
- (SELECT
4654
- entity_id,
4655
- entity_type_id,
4656
- attribute_set_id,
4657
- parent_id,
4658
- store_category_id,
4659
- parent_store_category_id
4660
- FROM $catalog_category_entity)");
4661
-
4662
- $this->db_do("
4663
- UPDATE $stINch_categories_mapping_temp cmt
4664
- JOIN $categories_temp c
4665
- ON cmt.shop_store_category_id = c.store_category_id
4666
- SET
4667
- cmt.store_category_id = c.store_category_id,
4668
- cmt.parent_store_category_id = c.parent_store_category_id,
4669
- cmt.category_name = c.category_name,
4670
- cmt.order_number = c.order_number,
4671
- cmt.products_within_this_category = c.products_within_this_category");
4672
-
4673
- $this->db_do("
4674
- UPDATE $stINch_categories_mapping_temp cmt
4675
- JOIN $catalog_category_entity cce
4676
- ON cmt.parent_store_category_id = cce.store_category_id
4677
- SET cmt.shop_parent_id = cce.entity_id");
4678
-
4679
- $this->db_do("
4680
- UPDATE $stINch_categories_mapping_temp cmt
4681
- JOIN $categories_temp c
4682
- ON cmt.shop_store_category_id = c.store_category_id
4683
- SET shop_parent_id = ".$this->_root_cat."
4684
- WHERE shop_parent_id = 0");
4685
- // !!!!!!!!!!!!!!!!!!!!!!!!!!! one shop ($this->_root_cat) => milti shop ($root_cat)
4686
-
4687
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
4688
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE"))
4689
- {
4690
- $this->db_do("
4691
- UPDATE $stINch_categories_mapping_temp cmt
4692
- JOIN $catalog_category_entity cce
4693
- ON cmt.shop_entity_id = cce.entity_id
4694
- SET cce.parent_id = cmt.shop_parent_id");
4695
- }
4696
- else
4697
- {
4698
- $this->db_do("
4699
- UPDATE $stINch_categories_mapping_temp cmt
4700
- JOIN $catalog_category_entity cce
4701
- ON cmt.shop_entity_id = cce.entity_id
4702
- SET cce.parent_id = cmt.shop_parent_id
4703
- WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL");
4704
- }
4705
-
4706
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping");
4707
- $this->db_do("RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping");
4708
- } //
4709
- ################################################################################################################################################################
4710
-
4711
-
4712
-
4713
- ################################################################################################################################################################
4714
- private function addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
4715
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat)
4716
- {
4717
- if (UPDATE_CATEGORY_DATA)
4718
- {
4719
- echo "Update category_entity \n";
4720
-
4721
- $q = "
4722
- INSERT INTO $catalog_category_entity
4723
- (
4724
- entity_type_id,
4725
- attribute_set_id,
4726
- created_at,
4727
- updated_at,
4728
- level,
4729
- children_count,
4730
- entity_id,
4731
- position,
4732
- parent_id,
4733
- store_category_id,
4734
- parent_store_category_id
4735
- )
4736
- (SELECT
4737
- $_categoryEntityTypeId,
4738
- $_categoryDefault_attribute_set_id,
4739
- now(),
4740
- now(),
4741
- c.level,
4742
- c.children_count,
4743
- scm.shop_entity_id,
4744
- c.order_number,
4745
- scm.shop_parent_id,
4746
- c.store_category_id,
4747
- c.parent_store_category_id
4748
- FROM $categories_temp c
4749
- LEFT JOIN $stINch_categories_mapping scm
4750
- ON c.store_category_id = scm.store_category_id
4751
- )
4752
- ON DUPLICATE KEY UPDATE
4753
- updated_at = now(),
4754
- store_category_id = c.store_category_id,
4755
- level = c.level,
4756
- children_count = c.children_count,
4757
- position = c.order_number,
4758
- parent_store_category_id = c.parent_store_category_id";
4759
- //level=c.level,
4760
- //children_count=c.children_count
4761
- //position=c.order_number,
4762
- }
4763
- else
4764
- {
4765
- echo "Insert ignore category_entity \n";
4766
-
4767
- $q = "
4768
- INSERT IGNORE INTO $catalog_category_entity
4769
- (
4770
- entity_type_id,
4771
- attribute_set_id,
4772
- created_at,
4773
- updated_at,
4774
- level,
4775
- children_count,
4776
- entity_id,
4777
- position,
4778
- parent_id,
4779
- store_category_id,
4780
- parent_store_category_id
4781
- )
4782
- (SELECT
4783
- $_categoryEntityTypeId,
4784
- $_categoryDefault_attribute_set_id,
4785
- now(),
4786
- now(),
4787
- c.level,
4788
- c.children_count,
4789
- scm.shop_entity_id,
4790
- c.order_number,
4791
- scm.shop_parent_id,
4792
- c.store_category_id,
4793
- c.parent_store_category_id
4794
- FROM $categories_temp c
4795
- LEFT JOIN $stINch_categories_mapping scm
4796
- ON c.store_category_id = scm.store_category_id
4797
- )";
4798
- }
4799
- $this->db_do($q);
4800
-
4801
- $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
4802
-
4803
-
4804
-
4805
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
4806
- while ($row = mysqli_fetch_array($categories))
4807
- {
4808
- $parent_id = $row['parent_id'];
4809
- $entity_id = $row['entity_id'];
4810
-
4811
- $path = $this->culc_path($parent_id, $entity_id);
4812
-
4813
- //echo("\n$path\n");
4814
-
4815
- $this->db_do("
4816
- UPDATE $catalog_category_entity
4817
- SET path = '$path'
4818
- WHERE entity_id = $entity_id");
4819
- }
4820
-
4821
- if(UPDATE_CATEGORY_DATA)
4822
- {
4823
- echo "Update category_data \n";
4824
-
4825
- $q = "
4826
- INSERT INTO $catalog_category_entity_varchar
4827
- (
4828
- entity_type_id,
4829
- attribute_id,
4830
- store_id,
4831
- entity_id,
4832
- value
4833
- )
4834
- (SELECT
4835
- $_categoryEntityTypeId,
4836
- $name_attrid,
4837
- 0,
4838
- scm.shop_entity_id,
4839
- c.category_name
4840
- FROM $categories_temp c
4841
- JOIN $stINch_categories_mapping scm
4842
- ON c.store_category_id = scm.store_category_id
4843
- )
4844
- ON DUPLICATE KEY UPDATE
4845
- value = c.category_name";
4846
- $this->db_do($q);
4847
-
4848
- $q = "
4849
- INSERT INTO $catalog_category_entity_varchar
4850
- (
4851
- entity_type_id,
4852
- attribute_id,
4853
- store_id,
4854
- entity_id,
4855
- value
4856
- )
4857
- (SELECT
4858
- $_categoryEntityTypeId,
4859
- $name_attrid,
4860
- 1,
4861
- scm.shop_entity_id,
4862
- c.category_name
4863
- FROM $categories_temp c
4864
- JOIN $stINch_categories_mapping scm
4865
- ON c.store_category_id = scm.store_category_id
4866
- )
4867
- ON DUPLICATE KEY UPDATE
4868
- value = c.category_name";
4869
- $this->db_do($q);
4870
-
4871
- $q = "
4872
- INSERT INTO $catalog_category_entity
4873
- (
4874
- entity_type_id,
4875
- attribute_id,
4876
- store_id,
4877
- entity_id,
4878
- value
4879
- )
4880
- (SELECT
4881
- $_categoryEntityTypeId,
4882
- $attr_is_active,
4883
- 0,
4884
- scm.shop_entity_id,
4885
- 1
4886
- FROM $categories_temp c
4887
- JOIN $stINch_categories_mapping scm
4888
- ON c.store_category_id = scm.store_category_id
4889
- )
4890
- ON DUPLICATE KEY UPDATE
4891
- value = 1";
4892
- $this->db_do($q);
4893
-
4894
- $q = "
4895
- INSERT INTO $catalog_category_entity_int
4896
- (
4897
- entity_type_id,
4898
- attribute_id,
4899
- store_id,
4900
- entity_id,
4901
- value
4902
- )
4903
- (SELECT
4904
- $_categoryEntityTypeId,
4905
- $attr_is_active,
4906
- 1,
4907
- scm.shop_entity_id,
4908
- 1
4909
- FROM $categories_temp c
4910
- JOIN $stINch_categories_mapping scm
4911
- ON c.store_category_id = scm.store_category_id
4912
- )
4913
- ON DUPLICATE KEY UPDATE
4914
- value = 1";
4915
- $this->db_do($q);
4916
-
4917
- $q = "
4918
- INSERT INTO $catalog_category_entity_int
4919
- (
4920
- entity_type_id,
4921
- attribute_id,
4922
- store_id,
4923
- entity_id,
4924
- value
4925
- )
4926
- (SELECT
4927
- $_categoryEntityTypeId,
4928
- $attr_include_in_menu,
4929
- 0,
4930
- scm.shop_entity_id,
4931
- c.include_in_menu
4932
- FROM $categories_temp c
4933
- JOIN $stINch_categories_mapping scm
4934
- ON c.store_category_id = scm.store_category_id
4935
- )
4936
- ON DUPLICATE KEY UPDATE
4937
- value = c.include_in_menu";
4938
- $this->db_do($q);
4939
-
4940
- $q = "
4941
- INSERT INTO $catalog_category_entity_int
4942
- (
4943
- entity_type_id,
4944
- attribute_id,
4945
- store_id,
4946
- entity_id,
4947
- value
4948
- )
4949
- (SELECT
4950
- $_categoryEntityTypeId,
4951
- $is_anchor_attrid,
4952
- 1,
4953
- scm.shop_entity_id,
4954
- c.is_anchor
4955
- FROM $categories_temp c
4956
- JOIN $stINch_categories_mapping scm
4957
- ON c.store_category_id = scm.store_category_id
4958
- )
4959
- ON DUPLICATE KEY UPDATE
4960
- value = c.is_anchor";
4961
- $this->db_do($q);
4962
-
4963
- $q = "
4964
- INSERT INTO $catalog_category_entity_int
4965
- (
4966
- entity_type_id,
4967
- attribute_id,
4968
- store_id,
4969
- entity_id,
4970
- value
4971
- )
4972
- (SELECT
4973
- $_categoryEntityTypeId,
4974
- $is_anchor_attrid,
4975
- 0,
4976
- scm.shop_entity_id,
4977
- c.is_anchor
4978
- FROM $categories_temp c
4979
- JOIN $stINch_categories_mapping scm
4980
- ON c.store_category_id = scm.store_category_id
4981
- )
4982
- ON DUPLICATE KEY UPDATE
4983
- value = c.is_anchor";
4984
- $this->db_do($q);
4985
-
4986
- $q = "
4987
- INSERT INTO $catalog_category_entity_varchar
4988
- (
4989
- entity_type_id,
4990
- attribute_id,
4991
- store_id,
4992
- entity_id,
4993
- value
4994
- )
4995
- (SELECT
4996
- $_categoryEntityTypeId,
4997
- $image_attrid,
4998
- 0,
4999
- scm.shop_entity_id,
5000
- c.categories_image
5001
- FROM $categories_temp c
5002
- JOIN $stINch_categories_mapping scm
5003
- ON c.store_category_id = scm.store_category_id
5004
- )
5005
- ON DUPLICATE KEY UPDATE
5006
- value = c.categories_image";
5007
- $this->db_do($q);
5008
- //STP
5009
- $q = "
5010
- INSERT INTO $catalog_category_entity_varchar
5011
- (
5012
- entity_type_id,
5013
- attribute_id,
5014
- store_id,
5015
- entity_id,
5016
- value
5017
- )
5018
- (SELECT
5019
- $this->_categoryEntityTypeId,
5020
- $this->_categoryMetaTitleAttrId,
5021
- 0,
5022
- scm.shop_entity_id,
5023
- c.MetaTitle
5024
- FROM $categories_temp c
5025
- JOIN $stINch_categories_mapping scm
5026
- ON c.store_category_id = scm.store_category_id
5027
- )
5028
- ON DUPLICATE KEY UPDATE
5029
- value = c.MetaTitle";
5030
- $this->db_do($q);
5031
-
5032
- $q = "
5033
- INSERT INTO $catalog_category_entity_varchar
5034
- (
5035
- entity_type_id,
5036
- attribute_id,
5037
- store_id,
5038
- entity_id,
5039
- value
5040
- )
5041
- (SELECT
5042
- $this->_categoryEntityTypeId,
5043
- $this->_categoryMetadescriptionAttrId,
5044
- 0,
5045
- scm.shop_entity_id,
5046
- c.MetaDescription
5047
- FROM $categories_temp c
5048
- JOIN $stINch_categories_mapping scm
5049
- ON c.store_category_id = scm.store_category_id
5050
- )
5051
- ON DUPLICATE KEY UPDATE
5052
- value = c.MetaDescription";
5053
- $this->db_do($q);
5054
-
5055
- $q = "
5056
- INSERT INTO $catalog_category_entity_varchar
5057
- (
5058
- entity_type_id,
5059
- attribute_id,
5060
- store_id,
5061
- entity_id,
5062
- value
5063
- )
5064
- (SELECT
5065
- $this->_categoryEntityTypeId,
5066
- $this->_categoryDescriptionAttrId,
5067
- 0,
5068
- scm.shop_entity_id,
5069
- c.Description
5070
- FROM $categories_temp c
5071
- JOIN $stINch_categories_mapping scm
5072
- ON c.store_category_id = scm.store_category_id
5073
- )
5074
- ON DUPLICATE KEY UPDATE
5075
- value = c.Description";
5076
- $this->db_do($q);
5077
-
5078
-
5079
- //stp
5080
- }
5081
- else
5082
- {
5083
- echo "Insert ignore category_data \n";
5084
-
5085
- $q = "
5086
- INSERT IGNORE INTO $catalog_category_entity_varchar
5087
- (
5088
- entity_type_id,
5089
- attribute_id,
5090
- store_id,
5091
- entity_id,
5092
- value
5093
- )
5094
- (SELECT
5095
- $_categoryEntityTypeId,
5096
- $name_attrid,
5097
- 0,
5098
- scm.shop_entity_id,
5099
- c.category_name
5100
- FROM $categories_temp c
5101
- JOIN $stINch_categories_mapping scm
5102
- ON c.store_category_id = scm.store_category_id
5103
- )";
5104
- $this->db_do($q);
5105
-
5106
- $q = "
5107
- INSERT IGNORE INTO $catalog_category_entity_int
5108
- (
5109
- entity_type_id,
5110
- attribute_id,
5111
- store_id,
5112
- entity_id,
5113
- value
5114
- )
5115
- (SELECT
5116
- $_categoryEntityTypeId,
5117
- $attr_is_active,
5118
- 0,
5119
- scm.shop_entity_id,
5120
- 1
5121
- FROM $categories_temp c
5122
- JOIN $stINch_categories_mapping scm
5123
- ON c.store_category_id = scm.store_category_id
5124
- )";
5125
- $this->db_do($q);
5126
-
5127
- $q = "
5128
- INSERT IGNORE INTO $catalog_category_entity_int
5129
- (
5130
- entity_type_id,
5131
- attribute_id,
5132
- store_id,
5133
- entity_id,
5134
- value
5135
- )
5136
- (SELECT
5137
- $_categoryEntityTypeId,
5138
- $attr_include_in_menu,
5139
- 0,
5140
- scm.shop_entity_id,
5141
- c.include_in_menu
5142
- FROM $categories_temp c
5143
- JOIN $stINch_categories_mapping scm
5144
- ON c.store_category_id = scm.store_category_id
5145
- )";
5146
- $this->db_do($q);
5147
-
5148
- $q = "
5149
- INSERT IGNORE INTO $catalog_category_entity_int
5150
- (
5151
- entity_type_id,
5152
- attribute_id,
5153
- store_id,
5154
- entity_id,
5155
- value
5156
- )
5157
- (SELECT
5158
- $_categoryEntityTypeId,
5159
- $is_anchor_attrid,
5160
- 0,
5161
- scm.shop_entity_id,
5162
- c.is_anchor
5163
- FROM $categories_temp c
5164
- JOIN $stINch_categories_mapping scm
5165
- ON c.store_category_id = scm.store_category_id
5166
- )";
5167
- $this->db_do($q);
5168
-
5169
- $q = "
5170
- INSERT IGNORE INTO $catalog_category_entity_varchar
5171
- (
5172
- entity_type_id,
5173
- attribute_id,
5174
- store_id,
5175
- entity_id,
5176
- value
5177
- )
5178
- (SELECT
5179
- $_categoryEntityTypeId,
5180
- $image_attrid,
5181
- 0,
5182
- scm.shop_entity_id,
5183
- c.categories_image
5184
- FROM $categories_temp c
5185
- JOIN $stINch_categories_mapping scm
5186
- ON c.store_category_id = scm.store_category_id
5187
- )";
5188
- $this->db_do($q);
5189
- //STP
5190
- $q = "
5191
- INSERT IGNORE INTO $catalog_category_entity_varchar
5192
- (
5193
- entity_type_id,
5194
- attribute_id,
5195
- store_id,
5196
- entity_id,
5197
- value
5198
- )
5199
- (SELECT
5200
- $this->_categoryEntityTypeId,
5201
- $this->_categoryMetaTitleAttrId,
5202
- 0,
5203
- scm.shop_entity_id,
5204
- c.MetaTitle
5205
- FROM $categories_temp c
5206
- JOIN $stINch_categories_mapping scm
5207
- ON c.store_category_id = scm.store_category_id
5208
- )
5209
- ";
5210
- $this->db_do($q);
5211
-
5212
- $q = "
5213
- INSERT IGNORE INTO $catalog_category_entity_varchar
5214
- (
5215
- entity_type_id,
5216
- attribute_id,
5217
- store_id,
5218
- entity_id,
5219
- value
5220
- )
5221
- (SELECT
5222
- $this->_categoryEntityTypeId,
5223
- $this->_categoryMetadescriptionAttrId,
5224
- 0,
5225
- scm.shop_entity_id,
5226
- c.MetaDescription
5227
- FROM $categories_temp c
5228
- JOIN $stINch_categories_mapping scm
5229
- ON c.store_category_id = scm.store_category_id
5230
- )
5231
- ";
5232
- $this->db_do($q);
5233
-
5234
- $q = "
5235
- INSERT IGNORE INTO $catalog_category_entity_varchar
5236
- (
5237
- entity_type_id,
5238
- attribute_id,
5239
- store_id,
5240
- entity_id,
5241
- value
5242
- )
5243
- (SELECT
5244
- $this->_categoryEntityTypeId,
5245
- $this->_categoryDescriptionAttrId,
5246
- 0,
5247
- scm.shop_entity_id,
5248
- c.Description
5249
- FROM $categories_temp c
5250
- JOIN $stINch_categories_mapping scm
5251
- ON c.store_category_id = scm.store_category_id
5252
- )
5253
- ";
5254
- $this->db_do($q);
5255
-
5256
-
5257
- //stp
5258
-
5259
- }
5260
-
5261
- $this->delete_old_sinch_categories_from_shop();
5262
-
5263
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories");
5264
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
5265
- } // private function addCategoryData(...)
5266
- ################################################################################################################################################################
5267
-
5268
-
5269
-
5270
-
5271
-
5272
-
5273
-
5274
-
5275
-
5276
-
5277
-
5278
-
5279
-
5280
-
5281
-
5282
-
5283
-
5284
- function ParseCategoryFeatures(){
5285
-
5286
- $parse_file=$this->varDir.FILE_CATEGORIES_FEATURES;
5287
- if(filesize($parse_file) || $this->_ignore_category_features){
5288
- $this->_LOG("Start parse ".FILE_CATEGORIES_FEATURES);
5289
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp'));
5290
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')." (
5291
- category_feature_id int(11),
5292
- store_category_id int(11),
5293
- feature_name varchar(50),
5294
- display_order_number int(11),
5295
- KEY(store_category_id),
5296
- KEY(category_feature_id)
5297
- )
5298
- ");
5299
-
5300
- if(!$this->_ignore_category_features){
5301
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5302
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
5303
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5304
- OPTIONALLY ENCLOSED BY '\"'
5305
- LINES TERMINATED BY \"\r\n\"
5306
- IGNORE 1 LINES ");
5307
- }
5308
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
5309
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
5310
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
5311
-
5312
- $this->_LOG("Finish parse ".FILE_CATEGORIES_FEATURES);
5313
- }else{
5314
- $this->_LOG("Wrong file ".$parse_file);
5315
- }
5316
- $this->_LOG(' ');
5317
- }
5318
-
5319
- #################################################################################################
5320
-
5321
- function ParseDistributors(){
5322
-
5323
- $parse_file=$this->varDir.FILE_DISTRIBUTORS;
5324
- if(filesize($parse_file)){
5325
- $this->_LOG("Start parse ".FILE_DISTRIBUTORS);
5326
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('distributors_temp'));
5327
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."(
5328
- distributor_id int(11),
5329
- distributor_name varchar(255),
5330
- website varchar(255),
5331
- KEY(distributor_id)
5332
- )
5333
- ");
5334
-
5335
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5336
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
5337
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5338
- OPTIONALLY ENCLOSED BY '\"'
5339
- LINES TERMINATED BY \"\r\n\"
5340
- IGNORE 1 LINES ");
5341
-
5342
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
5343
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
5344
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
5345
-
5346
- $this->_LOG("Finish parse ".FILE_DISTRIBUTORS);
5347
- }else{
5348
- $this->_LOG("Wrong file ".$parse_file);
5349
- }
5350
- $this->_LOG(' ');
5351
- }
5352
-
5353
- #################################################################################################
5354
-
5355
- function ParseDistributorsStockAndPrice(){
5356
- $parse_file=$this->varDir.FILE_DISTRIBUTORS_STOCK_AND_PRICES;
5357
- if(filesize($parse_file)){
5358
- $this->_LOG("Start parse ".FILE_DISTRIBUTORS_STOCK_AND_PRICES);
5359
-
5360
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp'));
5361
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."(
5362
- `store_product_id` int(11) DEFAULT NULL,
5363
- `distributor_id` int(11) DEFAULT NULL,
5364
- `stock` int(11) DEFAULT NULL,
5365
- `cost` decimal(15,4) DEFAULT NULL,
5366
- `distributor_sku` varchar(255) DEFAULT NULL,
5367
- `distributor_category` varchar(50) DEFAULT NULL,
5368
- `eta` varchar(50) DEFAULT NULL,
5369
- UNIQUE KEY `product_distri` (store_product_id, distributor_id)
5370
- )");
5371
-
5372
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5373
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."
5374
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5375
- OPTIONALLY ENCLOSED BY '\"'
5376
- LINES TERMINATED BY \"\r\n\"
5377
- IGNORE 1 LINES ");
5378
-
5379
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
5380
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."
5381
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
5382
-
5383
- $this->_LOG("Finish parse ".FILE_DISTRIBUTORS_STOCK_AND_PRICES);
5384
- }else{
5385
- $this->_LOG("Wrong file ".$parse_file);
5386
- }
5387
- $this->_LOG(' ');
5388
-
5389
- }
5390
-
5391
-
5392
- #################################################################################################
5393
-
5394
- function ParseEANCodes(){
5395
-
5396
- $parse_file=$this->varDir.FILE_EANCODES;
5397
- if(filesize($parse_file)){
5398
- $this->_LOG("Start parse ".FILE_EANCODES);
5399
-
5400
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp'));
5401
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."(
5402
- product_id int(11),
5403
- ean_code varchar(255),
5404
- KEY(product_id)
5405
- )");
5406
-
5407
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5408
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
5409
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5410
- OPTIONALLY ENCLOSED BY '\"'
5411
- LINES TERMINATED BY \"\r\n\"
5412
- IGNORE 1 LINES ");
5413
-
5414
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
5415
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
5416
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
5417
-
5418
- $this->_LOG("Finish parse ".FILE_EANCODES);
5419
- }else{
5420
- $this->_LOG("Wrong file ".$parse_file);
5421
- }
5422
- $this->_LOG(' ');
5423
- }
5424
-
5425
- #################################################################################################
5426
-
5427
- function ParseManufacturers(){
5428
-
5429
- $parse_file=$this->varDir.FILE_MANUFACTURERS;
5430
- if(filesize($parse_file)){
5431
- $this->_LOG("Start parse ".FILE_MANUFACTURERS);
5432
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp'));
5433
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."(
5434
- sinch_manufacturer_id int(11),
5435
- manufacturer_name varchar(255),
5436
- manufacturers_image varchar(255),
5437
- shop_option_id int(11),
5438
- KEY(sinch_manufacturer_id),
5439
- KEY(shop_option_id),
5440
- KEY(manufacturer_name)
5441
- )");
5442
-
5443
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5444
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
5445
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5446
- OPTIONALLY ENCLOSED BY '\"'
5447
- LINES TERMINATED BY \"\r\n\"
5448
- IGNORE 1 LINES ");
5449
-
5450
- $q="DELETE aov
5451
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5452
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5453
- ON ao.option_id=aov.option_id left
5454
- JOIN ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
5455
- ON aov.value=mt.manufacturer_name
5456
- WHERE
5457
- ao.attribute_id=".$this->attributes['manufacturer']." AND
5458
- mt.manufacturer_name is null";
5459
- $this->db_do($q);
5460
-
5461
- $q="DELETE ao
5462
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5463
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5464
- ON ao.option_id=aov.option_id
5465
- WHERE
5466
- attribute_id=".$this->attributes['manufacturer']." AND
5467
- aov.option_id is null";
5468
- $this->db_do($q);
5469
-
5470
- $q="SELECT
5471
- m.sinch_manufacturer_id,
5472
- m.manufacturer_name,
5473
- m.manufacturers_image
5474
- FROM ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." m
5475
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5476
- ON m.manufacturer_name=aov.value
5477
- WHERE aov.value IS NULL";
5478
- $quer=$this->db_do($q);
5479
-
5480
- while($row=mysqli_fetch_array($quer)){
5481
- $q0="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
5482
- (attribute_id)
5483
- VALUES(".$this->attributes['manufacturer'].")";
5484
- $quer0=$this->db_do($q0);
5485
-
5486
- $q2="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')."(
5487
- option_id,
5488
- value
5489
- )(
5490
- SELECT
5491
- max(option_id) as option_id,
5492
- "."'".mysqli_real_escape_string($this->db, $row['manufacturer_name'])."'
5493
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
5494
- WHERE attribute_id=".$this->attributes['manufacturer']."
5495
- )
5496
- ";
5497
- $quer2=$this->db_do($q2);
5498
- // $option['attribute_id'] = $this->attributes['manufacturer'];
5499
- // $option['value'][$row['sinch_manufacturer_id']][0] = $row['manufacturer_name'];
5500
-
5501
- }
5502
-
5503
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
5504
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5505
- ON mt.manufacturer_name=aov.value
5506
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5507
- ON ao.option_id=aov.option_id
5508
- SET mt.shop_option_id=aov.option_id
5509
- WHERE ao.attribute_id=".$this->attributes['manufacturer'];
5510
- $this->db_do($q);
5511
-
5512
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
5513
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
5514
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
5515
- $this->_LOG("Finish parse ".FILE_MANUFACTURERS);
5516
- }else{
5517
- $this->_LOG("Wrong file ".$parse_file);
5518
- }
5519
- $this->_LOG(' ');
5520
- }
5521
-
5522
- #################################################################################################
5523
-
5524
- function ParseProductFeatures(){
5525
-
5526
- $parse_file=$this->varDir.FILE_PRODUCT_FEATURES;
5527
- if(filesize($parse_file) || $this->_ignore_product_features){
5528
- $this->_LOG("Start parse ".FILE_PRODUCT_FEATURES);
5529
-
5530
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('product_features_temp'));
5531
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."(
5532
- product_feature_id int(11),
5533
- sinch_product_id int(11),
5534
- restricted_value_id int(11),
5535
- KEY(sinch_product_id),
5536
- KEY(restricted_value_id)
5537
- )
5538
- ");
5539
- if(!$this->_ignore_product_features){
5540
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5541
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
5542
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5543
- OPTIONALLY ENCLOSED BY '\"'
5544
- LINES TERMINATED BY \"\r\n\"
5545
- IGNORE 1 LINES ");
5546
- }
5547
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
5548
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
5549
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
5550
-
5551
- $this->_LOG("Finish parse ".FILE_PRODUCT_FEATURES);
5552
- }else{
5553
- $this->_LOG("Wrong file ".$parse_file);
5554
- }
5555
- $this->_LOG(" ");
5556
- }
5557
- #################################################################################################
5558
-
5559
- function ParseCategoryTypes(){
5560
- $parse_file=$this->varDir.FILE_CATEGORY_TYPES;
5561
- if(filesize($parse_file)){
5562
- $this->_LOG("Start parse ".FILE_CATEGORY_TYPES);
5563
-
5564
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('category_types_temp'));
5565
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."(
5566
- id int(11),
5567
- name varchar(255),
5568
- key(id)
5569
- )");
5570
-
5571
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5572
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."
5573
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5574
- OPTIONALLY ENCLOSED BY '\"'
5575
- LINES TERMINATED BY \"\r\n\"
5576
- IGNORE 1 LINES ");
5577
-
5578
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_category_types'));
5579
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."
5580
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_category_types'));
5581
-
5582
- $this->_LOG("Finish parse ".FILE_CATEGORY_TYPES);
5583
- }else{
5584
- $this->_LOG("Wrong file ".$parse_file);
5585
- }
5586
- $this->_LOG(' ');
5587
-
5588
- }
5589
-
5590
- #################################################################################################
5591
-
5592
- function ParseProductCategories(){
5593
- $parse_file=$this->varDir.FILE_PRODUCT_CATEGORIES;
5594
- if(filesize($parse_file)){
5595
- $this->_LOG("Start parse ".FILE_PRODUCT_CATEGORIES);
5596
-
5597
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp'));
5598
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."(
5599
- store_product_id int(11),
5600
- store_category_id int(11),
5601
- key(store_product_id),
5602
- key(store_category_id)
5603
- )");
5604
-
5605
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5606
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."
5607
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5608
- OPTIONALLY ENCLOSED BY '\"'
5609
- LINES TERMINATED BY \"\r\n\"
5610
- IGNORE 1 LINES ");
5611
-
5612
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories'));
5613
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."
5614
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories'));
5615
-
5616
- $this->_LOG("Finish parse ".FILE_PRODUCT_CATEGORIES);
5617
- }else{
5618
- $this->_LOG("Wrong file ".$parse_file);
5619
- }
5620
- $this->_LOG(' ');
5621
-
5622
- }
5623
- #################################################################################################
5624
-
5625
- function ParseProducts($coincidence){
5626
- echo("\nParseProducts 2\n");
5627
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
5628
- $replace_merge_product = $dataConf['replace_products'];
5629
-
5630
- $parse_file=$this->varDir.FILE_PRODUCTS;
5631
- if(filesize($parse_file)){
5632
- $this->_LOG("Start parse ".FILE_PRODUCTS);
5633
- echo("\nParseProducts 2\n");
5634
-
5635
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
5636
- if($this->product_file_format == "NEW"){
5637
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
5638
- store_product_id int(11),
5639
- product_sku varchar(255),
5640
- product_name varchar(255),
5641
- sinch_manufacturer_id int(11),
5642
- main_image_url varchar(255),
5643
- thumb_image_url varchar(255),
5644
- specifications text,
5645
- description text,
5646
- search_cache text,
5647
- description_type varchar(50),
5648
- medium_image_url varchar(255),
5649
- Title varchar(255),
5650
- Weight decimal(15,4),
5651
- Family varchar(255),
5652
- Reviews varchar(255),
5653
- pdf_url varchar(255),
5654
- product_short_description varchar(255),
5655
- products_date_added datetime default NULL,
5656
- products_last_modified datetime default NULL,
5657
- availability_id_in_stock int(11) default '1',
5658
- availability_id_out_of_stock int(11) default '2',
5659
- products_locate varchar(30) default NULL,
5660
- products_ordered int(11) NOT NULL default '0',
5661
- products_url varchar(255) default NULL,
5662
- products_viewed int(5) default '0',
5663
- products_seo_url varchar(100) NOT NULL,
5664
- manufacturer_name varchar(255) default NULL,
5665
- KEY(store_product_id),
5666
- KEY(sinch_manufacturer_id)
5667
- )DEFAULT CHARSET=utf8
5668
- ");
5669
- }elseif($this->product_file_format == "OLD"){
5670
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
5671
- store_category_product_id int(11),
5672
- store_product_id int(11),
5673
- sinch_product_id int(11),
5674
- product_sku varchar(255),
5675
- product_name varchar(255),
5676
- sinch_manufacturer_id int(11),
5677
- store_category_id int(11),
5678
- main_image_url varchar(255),
5679
- thumb_image_url varchar(255),
5680
- specifications text,
5681
- description text,
5682
- search_cache text,
5683
- spec_characte_u_count int(11),
5684
- description_type varchar(50),
5685
- medium_image_url varchar(255),
5686
- products_date_added datetime default NULL,
5687
- products_last_modified datetime default NULL,
5688
- availability_id_in_stock int(11) default '1',
5689
- availability_id_out_of_stock int(11) default '2',
5690
- products_locate varchar(30) default NULL,
5691
- products_ordered int(11) NOT NULL default '0',
5692
- products_url varchar(255) default NULL,
5693
- products_viewed int(5) default '0',
5694
- products_seo_url varchar(100) NOT NULL,
5695
- manufacturer_name varchar(255) default NULL,
5696
- KEY(store_category_product_id),
5697
- KEY(store_product_id),
5698
- KEY(sinch_manufacturer_id),
5699
- KEY(store_category_id)
5700
- )DEFAULT CHARSET=utf8
5701
- ");
5702
-
5703
- }
5704
- echo("\nParseProducts 3\n");
5705
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5706
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5707
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5708
- OPTIONALLY ENCLOSED BY '\"'
5709
- LINES TERMINATED BY \"\r\n\"
5710
- IGNORE 1 LINES ");
5711
-
5712
- if($this->product_file_format == "NEW"){
5713
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5714
- ADD COLUMN sinch_product_id int(11) AFTER store_product_id
5715
- ");
5716
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5717
- SET sinch_product_id=store_product_id
5718
- ");
5719
-
5720
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5721
- ADD COLUMN store_category_id int(11) AFTER sinch_manufacturer_id
5722
- ");
5723
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5724
- ADD KEY(store_category_id)
5725
- ");
5726
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5727
- SET product_name = Title WHERE Title != ''
5728
- ");
5729
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." pt
5730
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
5731
- SET pt.store_category_id=spc.store_category_id
5732
- WHERE pt.store_product_id=spc.store_product_id
5733
- ");
5734
- //http://redmine.bintime.com/issues/4127
5735
- //3.
5736
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5737
- SET main_image_url = medium_image_url WHERE main_image_url = ''
5738
- ");
5739
- //end
5740
-
5741
- }
5742
-
5743
- echo("\nParseProducts 4\n");
5744
-
5745
- echo("\nParseProducts 5\n");
5746
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5747
- SET products_date_added=now(), products_last_modified=now()");
5748
- echo("\nParseProducts 6\n");
5749
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
5750
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." m
5751
- ON p.sinch_manufacturer_id=m.sinch_manufacturer_id
5752
- SET p.manufacturer_name=m.manufacturer_name");
5753
- echo("\nParseProducts 7\n");
5754
- if($this->current_import_status_statistic_id){
5755
- $res = $this->db_do("SELECT COUNT(*) AS cnt
5756
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
5757
- $row = mysqli_fetch_assoc($res);
5758
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
5759
- SET number_of_products=".$row['cnt']."
5760
- WHERE id=".$this->current_import_status_statistic_id);
5761
- }
5762
-
5763
- if ($replace_merge_product == "REWRITE"){
5764
- $this->db_do ("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'));
5765
- $this->db_do ("SET FOREIGN_KEY_CHECKS=0");
5766
- $this->db_do ("TRUNCATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'));
5767
- $this->db_do ("SET FOREIGN_KEY_CHECKS=1");
5768
- }
5769
-
5770
- echo("\nParseProducts 8\n");
5771
- $this->addProductsWebsite();
5772
- $this->mapSinchProducts();
5773
- echo("\nParseProducts 9\n");
5774
-
5775
- if (count($coincidence) == 1)
5776
- {
5777
- $this->replaceMagentoProducts();
5778
- }
5779
- else
5780
- {
5781
- echo("\n\n\n\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ [".$this->im_type."] $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n\n\n"); //exit;
5782
-
5783
-
5784
- switch ($this->im_type)
5785
- {
5786
- case "REWRITE": $this->replaceMagentoProductsMultistore($coincidence); break;
5787
- case "MERGE": $this->replaceMagentoProductsMultistoreMERGE($coincidence); break;
5788
- }
5789
- }
5790
- echo("\nParseProducts 10\n");
5791
-
5792
-
5793
- $this->mapSinchProducts();
5794
- $this->addManufacturer_attribute();
5795
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
5796
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5797
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
5798
- $this->_LOG("Finish parse ".FILE_PRODUCTS);
5799
- }else{
5800
- $this->_LOG("Wrong file ".$parse_file);
5801
- }
5802
- $this->_LOG(" ");
5803
- echo("\nParseProducts 11\n");
5804
- }
5805
-
5806
- #################################################################################################
5807
-
5808
- function ParseRelatedProducts(){
5809
-
5810
- $parse_file=$this->varDir.FILE_RELATED_PRODUCTS;
5811
- if(filesize($parse_file) || $this->_ignore_product_related){
5812
- $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
5813
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('related_products_temp'));
5814
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."(
5815
- sinch_product_id int(11),
5816
- related_sinch_product_id int(11),
5817
- store_product_id int(11) default null,
5818
- store_related_product_id int(11) default null,
5819
- entity_id int(11),
5820
- related_entity_id int(11),
5821
- KEY(sinch_product_id),
5822
- KEY(related_sinch_product_id),
5823
- KEY(store_product_id)
5824
- )DEFAULT CHARSET=utf8");
5825
- if(!$this->_ignore_product_related){
5826
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5827
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
5828
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5829
- OPTIONALLY ENCLOSED BY '\"'
5830
- LINES TERMINATED BY \"\r\n\"
5831
- IGNORE 1 LINES ");
5832
- }
5833
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
5834
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
5835
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
5836
-
5837
- $this->_LOG("Finish parse ".FILE_RELATED_PRODUCTS);
5838
- }else{
5839
- $this->_LOG("Wrong file ".$parse_file);
5840
- }
5841
- $this->_LOG(" ");
5842
- }
5843
-
5844
- #################################################################################################
5845
-
5846
- function ParseRestrictedValues(){
5847
-
5848
- $parse_file=$this->varDir.FILE_RESTRICTED_VALUES;
5849
- if(filesize($parse_file) || $this->_ignore_restricted_values){
5850
- $this->_LOG("Start parse ".FILE_RESTRICTED_VALUES);
5851
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp'));
5852
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')." (
5853
- restricted_value_id int(11),
5854
- category_feature_id int(11),
5855
- text text,
5856
- display_order_number int(11),
5857
- KEY(restricted_value_id),
5858
- KEY(category_feature_id)
5859
- )");
5860
- if(!$this->_ignore_restricted_values){
5861
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5862
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
5863
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5864
- OPTIONALLY ENCLOSED BY '\"'
5865
- LINES TERMINATED BY \"\r\n\"
5866
- IGNORE 1 LINES ");
5867
- }
5868
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
5869
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
5870
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
5871
-
5872
- $this->_LOG("Finish parse ".FILE_RESTRICTED_VALUES);
5873
- }else{
5874
- $this->_LOG("Wrong file ".$parse_file);
5875
- }
5876
- $this->_LOG(" ");
5877
- }
5878
-
5879
- #################################################################################################
5880
-
5881
- function ParseStockAndPrices(){
5882
-
5883
- $parse_file=$this->varDir.FILE_STOCK_AND_PRICES;
5884
- if(filesize($parse_file)){
5885
- $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
5886
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp'));
5887
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." (
5888
- store_product_id int(11),
5889
- stock int(11),
5890
- price decimal(15,4),
5891
- cost decimal(15,4),
5892
- distributor_id int(11),
5893
- KEY(store_product_id),
5894
- KEY(distributor_id)
5895
- )");
5896
-
5897
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5898
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
5899
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5900
- OPTIONALLY ENCLOSED BY '\"'
5901
- LINES TERMINATED BY \"\r\n\"
5902
- IGNORE 1 LINES ");
5903
-
5904
- $this->replaceMagentoProductsStockPrice();
5905
-
5906
- $res = $this->db_do("SELECT count(*) as cnt
5907
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5908
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5909
- ON a.store_product_id=b.store_product_id");
5910
- $row = mysqli_fetch_assoc($res);
5911
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
5912
- SET number_of_products=".$row['cnt']."
5913
- WHERE id=".$this->current_import_status_statistic_id);
5914
-
5915
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
5916
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
5917
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
5918
-
5919
- $this->_LOG("Finish parse".FILE_RELATED_PRODUCTS);
5920
- }else{
5921
- $this->_LOG("Wrong file".$parse_file);
5922
- }
5923
- $this->_LOG(" ");
5924
- }
5925
-
5926
- #################################################################################################
5927
-
5928
- function ParseProductsPicturesGallery(){
5929
-
5930
- $parse_file=$this->varDir.FILE_PRODUCTS_PICTURES_GALLERY;
5931
- if(filesize($parse_file)){
5932
- $this->_LOG("Start parse ".FILE_PRODUCTS_PICTURES_GALLERY);
5933
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp'));
5934
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." (
5935
- sinch_product_id int(11),
5936
- image_url varchar(255),
5937
- thumb_image_url varchar(255),
5938
- store_product_id int(11),
5939
- key(sinch_product_id),
5940
- key(store_product_id)
5941
- )");
5942
-
5943
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5944
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
5945
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5946
- OPTIONALLY ENCLOSED BY '\"'
5947
- LINES TERMINATED BY \"\r\n\"
5948
- IGNORE 1 LINES ");
5949
-
5950
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." ppgt
5951
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
5952
- ON ppgt.sinch_product_id=sp.sinch_product_id
5953
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5954
- ON sp.store_product_id=cpe.store_product_id
5955
- SET ppgt.store_product_id=sp.store_product_id");
5956
-
5957
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
5958
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
5959
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
5960
-
5961
- $this->_LOG("Finish parse".FILE_PRODUCTS_PICTURES_GALLERY);
5962
- }else{
5963
- $this->_LOG("Wrong file".$parse_file);
5964
- }
5965
- $this->_LOG(" ");
5966
-
5967
- }
5968
-
5969
- #################################################################################################
5970
-
5971
- function ParsePriceRules(){
5972
- $parse_file=$this->varDir.FILE_PRICE_RULES;
5973
- if(filesize($parse_file) || $this->_ignore_price_rules){
5974
- $this->_LOG("Start parse ".FILE_PRICE_RULES);
5975
-
5976
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp'));
5977
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."(
5978
- `id` int(11) NOT NULL,
5979
- `price_from` decimal(10,2) DEFAULT NULL,
5980
- `price_to` decimal(10,2) DEFAULT NULL,
5981
- `category_id` int(10) unsigned DEFAULT NULL,
5982
- `vendor_id` int(11) DEFAULT NULL,
5983
- `vendor_product_id` varchar(255) DEFAULT NULL,
5984
- `customergroup_id` varchar(32) DEFAULT NULL,
5985
- `marge` decimal(10,2) DEFAULT NULL,
5986
- `fixed` decimal(10,2) DEFAULT NULL,
5987
- `final_price` decimal(10,2) DEFAULT NULL,
5988
- PRIMARY KEY (`id`),
5989
- UNIQUE KEY `price_from` (`price_from`,`price_to`,`vendor_id`,`category_id`,`vendor_product_id`,`customergroup_id`),
5990
- KEY `vendor_product_id` (`vendor_product_id`),
5991
- KEY `category_id` (`category_id`)
5992
- )
5993
- ");
5994
- if(!$this->_ignore_price_rules){
5995
-
5996
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5997
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
5998
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5999
- OPTIONALLY ENCLOSED BY '\"'
6000
- LINES TERMINATED BY \"\r\n\"
6001
- IGNORE 1 LINES
6002
- (id, @vprice_from, @vprice_to, @vcategory_id, @vvendor_id, @vvendor_product_id, @vcustomergroup_id, @vmarge, @vfixed, @vfinal_price)
6003
- SET price_from = nullif(@vprice_from,''),
6004
- price_to = nullif(@vprice_to,''),
6005
- category_id = nullif(@vcategory_id,''),
6006
- vendor_id = nullif(@vvendor_id,''),
6007
- vendor_product_id = nullif(@vvendor_product_id,''),
6008
- customergroup_id = nullif(@vcustomergroup_id,''),
6009
- marge = nullif(@vmarge,''),
6010
- fixed = nullif(@vfixed,''),
6011
- final_price = nullif(@vfinal_price,'')
6012
- ");
6013
- }
6014
-
6015
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6016
- ADD COLUMN `shop_category_id` int(10) unsigned DEFAULT NULL,
6017
- ADD COLUMN `shop_vendor_id` int(11) DEFAULT NULL,
6018
- ADD COLUMN `shop_vendor_product_id` varchar(255) DEFAULT NULL,
6019
- ADD COLUMN `shop_customergroup_id` varchar(32) DEFAULT NULL
6020
- ");
6021
-
6022
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6023
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6024
- ON prt.category_id = cce.store_category_id
6025
- SET prt.shop_category_id = cce.entity_id");
6026
-
6027
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6028
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." sicm
6029
- ON prt.vendor_id = sicm.sinch_manufacturer_id
6030
- SET prt.shop_vendor_id = sicm.shop_option_id");
6031
-
6032
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6033
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." sicpm
6034
- ON prt.vendor_product_id = sicpm.product_sku
6035
- SET prt.shop_vendor_product_id = sicpm.sku");
6036
-
6037
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6038
- JOIN ".Mage::getSingleton('core/resource')->getTableName('customer_group')." cg
6039
- ON prt.customergroup_id = cg.customer_group_id
6040
- SET prt.shop_customergroup_id = cg.customer_group_id");
6041
-
6042
- $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6043
- WHERE
6044
- (category_id IS NOT NULL AND shop_category_id IS NULL) OR
6045
- (vendor_id IS NOT NULL AND shop_vendor_id IS NULL) OR
6046
- (vendor_product_id IS NOT NULL AND shop_vendor_product_id IS NULL) OR
6047
- (customergroup_id IS NOT NULL AND shop_customergroup_id IS NULL)
6048
- ");
6049
-
6050
-
6051
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules'));
6052
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6053
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules'));
6054
-
6055
- $this->_LOG("Finish parse ".FILE_PRICE_RULES);
6056
- }else{
6057
- $this->_LOG("Wrong file ".$parse_file);
6058
- }
6059
- $this->_LOG(" ");
6060
- }
6061
-
6062
- #################################################################################################
6063
-
6064
- function AddPriceRules(){
6065
- if (!$this->check_table_exist('import_pricerules_standards')){
6066
- return;
6067
- }
6068
-
6069
- $result = $this->db_do("
6070
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('import_pricerules')." (
6071
- id,
6072
- price_from,
6073
- price_to,
6074
- vendor_id,
6075
- category_id,
6076
- vendor_product_id,
6077
- customergroup_id,
6078
- marge,
6079
- fixed,
6080
- final_price
6081
- )(SELECT
6082
- id,
6083
- price_from,
6084
- price_to,
6085
- shop_vendor_id,
6086
- shop_category_id,
6087
- shop_vendor_product_id,
6088
- shop_customergroup_id,
6089
- marge,
6090
- fixed,
6091
- final_price
6092
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules')." a
6093
- )
6094
- ON DUPLICATE KEY UPDATE
6095
- id = a.id,
6096
- price_from = a.price_from,
6097
- price_to = a.price_to,
6098
- vendor_id = a.shop_vendor_id,
6099
- category_id = a.shop_category_id,
6100
- vendor_product_id = a.shop_vendor_product_id,
6101
- customergroup_id = a.shop_customergroup_id,
6102
- marge = a.marge,
6103
- fixed = a.fixed,
6104
- final_price = a.final_price
6105
- ");
6106
-
6107
- }
6108
-
6109
- #################################################################################################
6110
-
6111
- public function mapSinchProducts(){
6112
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
6113
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
6114
- entity_id int(11) unsigned NOT NULL,
6115
- manufacturer_option_id int(11),
6116
- manufacturer_name varchar(255),
6117
- shop_store_product_id int(11),
6118
- shop_sinch_product_id int(11),
6119
- sku varchar(64) default NULL,
6120
- store_product_id int(11),
6121
- sinch_product_id int(11),
6122
- product_sku varchar(255),
6123
- sinch_manufacturer_id int(11),
6124
- sinch_manufacturer_name varchar(255),
6125
- KEY entity_id (entity_id),
6126
- KEY manufacturer_option_id (manufacturer_option_id),
6127
- KEY manufacturer_name (manufacturer_name),
6128
- KEY store_product_id (store_product_id),
6129
- KEY sinch_product_id (sinch_product_id),
6130
- KEY sku (sku),
6131
- UNIQUE KEY(entity_id)
6132
- )
6133
- ");
6134
- $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
6135
- LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
6136
- $result = $this->db_do("
6137
- INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
6138
- entity_id,
6139
- sku,
6140
- shop_store_product_id,
6141
- shop_sinch_product_id
6142
- )(SELECT
6143
- entity_id,
6144
- sku,
6145
- store_product_id,
6146
- sinch_product_id
6147
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')."
6148
- )
6149
- ");
6150
-
6151
- $this->addManufacturers(1);
6152
-
6153
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6154
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." cpie
6155
- ON pmt.entity_id=cpie.entity_id
6156
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
6157
- ON cpie.value=aov.option_id
6158
- SET
6159
- manufacturer_option_id=cpie.value,
6160
- manufacturer_name=aov.value
6161
- WHERE cpie.attribute_id=".$this->attributes['manufacturer'];
6162
- $this->db_do($q);
6163
-
6164
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6165
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6166
- ON pmt.sku=p.product_sku
6167
- SET
6168
- pmt.store_product_id=p.store_product_id,
6169
- pmt.sinch_product_id=p.sinch_product_id,
6170
- pmt.product_sku=p.product_sku,
6171
- pmt.sinch_manufacturer_id=p.sinch_manufacturer_id,
6172
- pmt.sinch_manufacturer_name=p.manufacturer_name";
6173
-
6174
- $this->db_do($q);
6175
-
6176
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6177
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6178
- ON cpe.entity_id=pmt.entity_id
6179
- SET cpe.store_product_id=pmt.store_product_id,
6180
- cpe.sinch_product_id=pmt.sinch_product_id
6181
- WHERE
6182
- cpe.sinch_product_id IS NULL
6183
- AND pmt.sinch_product_id IS NOT NULL
6184
- AND cpe.store_product_id IS NULL
6185
- AND pmt.store_product_id IS NOT NULL";
6186
- $this->db_do($q);
6187
-
6188
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
6189
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')."
6190
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
6191
- }
6192
- #################################################################################################
6193
- public function addProductsWebsite (){
6194
- $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_website_temp'));
6195
- // TEMPORARY
6196
- $this->db_do("
6197
- CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('products_website_temp')."` (
6198
- `id` int(10) unsigned NOT NULL auto_increment,
6199
- store_product_id int(11),
6200
- sinch_product_id int(11),
6201
- `website` int(11) default NULL,
6202
- `website_id` int(11) default NULL,
6203
- PRIMARY KEY (`id`),
6204
- KEY store_product_id (`store_product_id`)
6205
- )
6206
- ");
6207
- $result = $this->db_do("SELECT
6208
- website_id,
6209
- store_id as website
6210
- FROM ".Mage::getSingleton('core/resource')->getTableName('core_store')."
6211
- WHERE code!='admin'
6212
- "); // where code!='admin' was adder for editing Featured products;
6213
- while ($row = mysqli_fetch_assoc($result)) {
6214
- $sql = "INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." (
6215
- store_product_id,
6216
- sinch_product_id,
6217
- website,
6218
- website_id
6219
- )(
6220
- SELECT
6221
- distinct
6222
- store_product_id,
6223
- sinch_product_id,
6224
- {$row['website']},
6225
- {$row['website_id']}
6226
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
6227
- )";
6228
- $result2 = $this->db_do($sql);
6229
- }
6230
-
6231
-
6232
- }
6233
-
6234
- #################################################################################################
6235
- public function replaceMagentoProducts() {
6236
-
6237
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
6238
-
6239
- $result = $this->db_do("DELETE cpe
6240
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6241
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6242
- ON cpe.entity_id=pm.entity_id
6243
- WHERE pm.shop_store_product_id IS NOT NULL
6244
- AND pm.store_product_id IS NULL
6245
- ");
6246
-
6247
- //Inserting new products and updating old others.
6248
- $this->_getProductDefaulAttributeSetId();
6249
- $result = $this->db_do("
6250
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." (
6251
- entity_id,
6252
- entity_type_id,
6253
- attribute_set_id,
6254
- type_id,
6255
- sku,
6256
- updated_at,
6257
- has_options,
6258
- store_product_id,
6259
- sinch_product_id
6260
- )(SELECT
6261
- pm.entity_id,
6262
- " . $this->_getProductEntityTypeId(). ",
6263
- $this->defaultAttributeSetId,
6264
- 'simple',
6265
- a.product_sku,
6266
- NOW(),
6267
- 0,
6268
- a.store_product_id,
6269
- a.sinch_product_id
6270
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')." a
6271
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6272
- ON a.store_product_id=pm.store_product_id
6273
- AND a.sinch_product_id=pm.sinch_product_id
6274
- WHERE pm.entity_id IS NOT NULL
6275
- )
6276
- ON DUPLICATE KEY UPDATE
6277
- sku= a.product_sku,
6278
- store_product_id=a.store_product_id,
6279
- sinch_product_id=a.sinch_product_id
6280
- ");
6281
- // store_product_id=a.store_product_id,
6282
- // sinch_product_id=a.sinch_product_id
6283
-
6284
- $result = $this->db_do("
6285
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." (
6286
- entity_id,
6287
- entity_type_id,
6288
- attribute_set_id,
6289
- type_id,
6290
- sku,
6291
- updated_at,
6292
- has_options,
6293
- store_product_id,
6294
- sinch_product_id
6295
- )(SELECT
6296
- pm.entity_id,
6297
- " . $this->_getProductEntityTypeId(). ",
6298
- $this->defaultAttributeSetId,
6299
- 'simple',
6300
- a.product_sku,
6301
- NOW(),
6302
- 0,
6303
- a.store_product_id,
6304
- a.sinch_product_id
6305
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')." a
6306
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6307
- ON a.store_product_id=pm.store_product_id
6308
- AND a.sinch_product_id=pm.sinch_product_id
6309
- WHERE pm.entity_id IS NULL
6310
- )
6311
- ON DUPLICATE KEY UPDATE
6312
- sku= a.product_sku,
6313
- store_product_id=a.store_product_id,
6314
- sinch_product_id=a.sinch_product_id
6315
- ");
6316
- // store_product_id=a.store_product_id,
6317
- // sinch_product_id=a.sinch_product_id
6318
-
6319
- //Set enabled
6320
- $result = $this->db_do("DELETE cpei
6321
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." cpei
6322
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6323
- ON cpei.entity_id=cpe.entity_id
6324
- WHERE cpe.entity_id IS NULL");
6325
-
6326
- $result = $this->db_do("
6327
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6328
- entity_type_id,
6329
- attribute_id,
6330
- store_id,
6331
- entity_id,
6332
- value
6333
- )(
6334
- SELECT
6335
- " . $this->_getProductEntityTypeId(). ",
6336
- ". $this->_getProductAttributeId('status').",
6337
- w.website,
6338
- a.entity_id,
6339
- 1
6340
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6341
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6342
- ON a.store_product_id=w.store_product_id
6343
- )
6344
- ON DUPLICATE KEY UPDATE
6345
- value=1
6346
- ");
6347
- // set status = 1 for all stores
6348
- $result = $this->db_do("
6349
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6350
- entity_type_id,
6351
- attribute_id,
6352
- store_id,
6353
- entity_id,
6354
- value
6355
- )(SELECT
6356
- " . $this->_getProductEntityTypeId(). ",
6357
- ".$this->_getProductAttributeId('status').",
6358
- 0,
6359
- a.entity_id,
6360
- 1
6361
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6362
- )
6363
- ON DUPLICATE KEY UPDATE
6364
- value=1
6365
- ");
6366
-
6367
- //Unifying products with categories.
6368
- $result = $this->db_do("DELETE ccp
6369
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6370
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6371
- ON ccp.product_id=cpe.entity_id
6372
- WHERE cpe.entity_id IS NULL");
6373
-
6374
- echo("\n\n\nUPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6375
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6376
- ON ccp.category_id=cce.entity_id
6377
- SET ccp.category_id=".$this->_root_cat."
6378
- WHERE cce.entity_id IS NULL");
6379
- $result = $this->db_do("UPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6380
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6381
- ON ccp.category_id=cce.entity_id
6382
- SET ccp.category_id=".$this->_root_cat."
6383
- WHERE cce.entity_id IS NULL");
6384
- echo("\ndone\n");
6385
-
6386
-
6387
- echo("\n\n\nDELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6388
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6389
- ON ccp.category_id=cce.entity_id
6390
- WHERE cce.entity_id IS NULL");
6391
- $result = $this->db_do("DELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6392
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6393
- ON ccp.category_id=cce.entity_id
6394
- WHERE cce.entity_id IS NULL");
6395
- echo("\ndone\n");
6396
-
6397
-
6398
- $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp");
6399
- // TEMPORARY
6400
- $this->db_do("
6401
- CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp` (
6402
- `category_id` int(10) unsigned NOT NULL default '0',
6403
- `product_id` int(10) unsigned NOT NULL default '0',
6404
- `store_product_id` int(10) NOT NULL default '0',
6405
- `store_category_id` int(10) NOT NULL default '0',
6406
- `new_category_id` int(10) NOT NULL default '0',
6407
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
6408
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
6409
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
6410
- KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
6411
- )
6412
-
6413
- ");
6414
-
6415
- $result = $this->db_do("
6416
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp (
6417
- category_id,
6418
- product_id,
6419
- store_product_id
6420
- )(SELECT
6421
- ccp.category_id,
6422
- ccp.product_id,
6423
- cpe.store_product_id
6424
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6425
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6426
- ON ccp.product_id=cpe.entity_id
6427
- WHERE store_product_id is not null
6428
- )
6429
- ");
6430
-
6431
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6432
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6433
- ON ccpfd.store_product_id=p.store_product_id
6434
- SET ccpfd.store_category_id=p.store_category_id
6435
- WHERE ccpfd.store_product_id!=0
6436
- ");
6437
-
6438
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6439
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6440
- ON ccpfd.store_category_id=scm.store_category_id
6441
- SET ccpfd.new_category_id=scm.shop_entity_id
6442
- WHERE ccpfd.store_category_id!=0
6443
- ");
6444
-
6445
- $result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp
6446
- WHERE category_id=new_category_id");
6447
-
6448
- $result = $this->db_do("
6449
- DELETE ccp
6450
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6451
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6452
- ON ccp.product_id=ccpfd.product_id
6453
- AND ccp.category_id=ccpfd.category_id
6454
- ");
6455
-
6456
- $result = $this->db_do("
6457
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." (
6458
- category_id,
6459
- product_id
6460
- )(SELECT
6461
- scm.shop_entity_id,
6462
- cpe.entity_id
6463
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6464
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6465
- ON cpe.store_product_id=p.store_product_id
6466
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6467
- ON p.store_category_id=scm.store_category_id
6468
- )
6469
- ON DUPLICATE KEY UPDATE
6470
- product_id = cpe.entity_id
6471
- ");
6472
-
6473
-
6474
- //add multi categories;
6475
-
6476
-
6477
-
6478
-
6479
- $result = $this->db_do("
6480
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."
6481
- (category_id, product_id)
6482
- (SELECT
6483
- scm.shop_entity_id,
6484
- cpe.entity_id
6485
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6486
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6487
- ON cpe.store_product_id = p.store_product_id
6488
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
6489
- ON p.store_product_id=spc.store_product_id
6490
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6491
- ON spc.store_category_id = scm.store_category_id
6492
- )
6493
- ON DUPLICATE KEY UPDATE
6494
- product_id = cpe.entity_id
6495
- ");
6496
-
6497
-
6498
-
6499
-
6500
- //Indexing products and categories in the shop
6501
- $result = $this->db_do("DELETE ccpi
6502
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." ccpi
6503
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6504
- ON ccpi.product_id=cpe.entity_id
6505
- WHERE cpe.entity_id IS NULL");
6506
-
6507
- $result = $this->db_do("
6508
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
6509
- category_id,
6510
- product_id,
6511
- position,
6512
- is_parent,
6513
- store_id,
6514
- visibility
6515
- )(
6516
- SELECT
6517
- a.category_id,
6518
- a.product_id,
6519
- a.position,
6520
- 1,
6521
- b.store_id,
6522
- 4
6523
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
6524
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
6525
- )
6526
- ON DUPLICATE KEY UPDATE
6527
- visibility = 4
6528
- ");
6529
-
6530
- $result = $this->db_do("
6531
- INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
6532
- category_id,
6533
- product_id,
6534
- position,
6535
- is_parent,
6536
- store_id,
6537
- visibility
6538
- )(
6539
- SELECT
6540
- ".$this->_root_cat.",
6541
- a.product_id,
6542
- a.position,
6543
- 1,
6544
- b.store_id,
6545
- 4
6546
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
6547
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
6548
- )
6549
- ON DUPLICATE KEY UPDATE
6550
- visibility = 4
6551
- ");
6552
-
6553
- //Set product name for specific web sites
6554
- $result = $this->db_do("DELETE cpev
6555
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." cpev
6556
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6557
- ON cpev.entity_id=cpe.entity_id
6558
- WHERE cpe.entity_id IS NULL");
6559
- $result = $this->db_do("
6560
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6561
- entity_type_id,
6562
- attribute_id,
6563
- store_id,
6564
- entity_id,
6565
- value
6566
- )(SELECT
6567
- " . $this->_getProductEntityTypeId(). ",
6568
- " . $this->_getProductAttributeId('name'). ",
6569
- w.website,
6570
- a.entity_id,
6571
- b.product_name
6572
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6573
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6574
- ON a.store_product_id= b.store_product_id
6575
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6576
- ON a.store_product_id=w.store_product_id
6577
- )
6578
- ON DUPLICATE KEY UPDATE
6579
- value = b.product_name
6580
- ");
6581
-
6582
- // product name for all web sites
6583
- $result = $this->db_do("
6584
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6585
- entity_type_id,
6586
- attribute_id,
6587
- store_id,
6588
- entity_id,
6589
- value
6590
- )(
6591
- SELECT
6592
- " . $this->_getProductEntityTypeId(). ",
6593
- " . $this->_getProductAttributeId('name'). ",
6594
- 0,
6595
- a.entity_id,
6596
- b.product_name
6597
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6598
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6599
- ON a.store_product_id = b.store_product_id
6600
- )
6601
- ON DUPLICATE KEY UPDATE
6602
- value = b.product_name
6603
- ");
6604
-
6605
- $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
6606
- $this->addDescriptions();
6607
- $this->cleanProductDistributors();
6608
- if($this->product_file_format == "NEW"){
6609
- $this->addReviews();
6610
- $this->addWeight();
6611
- $this->addSearchCache();
6612
- $this->addPdfUrl();
6613
- $this->addShortDescriptions();
6614
- $this->addProductDistributors();
6615
- }
6616
- $this->addEAN();
6617
- $this->addSpecification();
6618
- $this->addManufacturers();
6619
-
6620
- //Enabling product index.
6621
- $result = $this->db_do("DELETE cpei
6622
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." cpei
6623
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6624
- ON cpei.product_id=cpe.entity_id
6625
- WHERE cpe.entity_id IS NULL");
6626
-
6627
- $result = $this->db_do("
6628
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
6629
- product_id,
6630
- store_id,
6631
- visibility
6632
- )(
6633
- SELECT
6634
- a.entity_id,
6635
- w.website,
6636
- 4
6637
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6638
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6639
- ON a.store_product_id=w.store_product_id
6640
- )
6641
- ON DUPLICATE KEY UPDATE
6642
- visibility = 4
6643
- ");
6644
- $result = $this->db_do("
6645
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
6646
- product_id,
6647
- store_id,
6648
- visibility
6649
- )(
6650
- SELECT
6651
- a.entity_id,
6652
- 0,
6653
- 4
6654
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6655
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6656
- ON a.store_product_id=w.store_product_id
6657
- )
6658
- ON DUPLICATE KEY UPDATE
6659
- visibility = 4
6660
- ");
6661
-
6662
-
6663
- $result = $this->db_do("
6664
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6665
- entity_type_id,
6666
- attribute_id,
6667
- store_id,
6668
- entity_id,
6669
- value
6670
- )(
6671
- SELECT
6672
- " . $this->_getProductEntityTypeId(). ",
6673
- " . $this->_getProductAttributeId('visibility'). ",
6674
- w.website,
6675
- a.entity_id,
6676
- 4
6677
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6678
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6679
- ON a.store_product_id=w.store_product_id
6680
- )
6681
- ON DUPLICATE KEY UPDATE
6682
- value = 4
6683
- ");
6684
-
6685
- $result = $this->db_do("
6686
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6687
- entity_type_id,
6688
- attribute_id,
6689
- store_id,
6690
- entity_id,
6691
- value
6692
- )(
6693
- SELECT
6694
- " . $this->_getProductEntityTypeId(). ",
6695
- " . $this->_getProductAttributeId('visibility'). ",
6696
- 0,
6697
- a.entity_id,
6698
- 4
6699
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6700
- )
6701
- ON DUPLICATE KEY UPDATE
6702
- value = 4
6703
- ");
6704
-
6705
- $result = $this->db_do("DELETE cpw
6706
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." cpw
6707
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6708
- ON cpw.product_id=cpe.entity_id
6709
- WHERE cpe.entity_id IS NULL");
6710
-
6711
- $result = $this->db_do("
6712
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." (
6713
- product_id,
6714
- website_id
6715
- )(
6716
- SELECT a.entity_id, w.website_id
6717
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6718
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6719
- ON a.store_product_id=w.store_product_id
6720
- )
6721
- ON DUPLICATE KEY UPDATE
6722
- product_id=a.entity_id,
6723
- website_id=w.website_id
6724
- ");
6725
-
6726
- // temporary disabled mart@bintime.com
6727
- //$result = $this->db_do("
6728
- // UPDATE catalog_category_entity_int a
6729
- // SET a.value = 0
6730
- // WHERE a.attribute_id = 32
6731
- //");
6732
-
6733
-
6734
- //Adding tax class "Taxable Goods"
6735
- $result = $this->db_do("
6736
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6737
- entity_type_id,
6738
- attribute_id,
6739
- store_id,
6740
- entity_id,
6741
- value
6742
- )(
6743
- SELECT
6744
- " . $this->_getProductEntityTypeId(). ",
6745
- " . $this->_getProductAttributeId('tax_class_id'). ",
6746
- w.website,
6747
- a.entity_id,
6748
- 2
6749
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6750
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6751
- ON a.store_product_id=w.store_product_id
6752
- )
6753
- ON DUPLICATE KEY UPDATE
6754
- value = 2
6755
- ");
6756
- $result = $this->db_do("
6757
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6758
- entity_type_id,
6759
- attribute_id,
6760
- store_id,
6761
- entity_id,
6762
- value
6763
- )(
6764
- SELECT
6765
- " . $this->_getProductEntityTypeId(). ",
6766
- " . $this->_getProductAttributeId('tax_class_id'). ",
6767
- 0,
6768
- a.entity_id,
6769
- 2
6770
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6771
- )
6772
- ON DUPLICATE KEY UPDATE
6773
- value = 2
6774
- ");
6775
-
6776
- // Load url Image
6777
- $result = $this->db_do("
6778
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6779
- entity_type_id,
6780
- attribute_id,
6781
- store_id,
6782
- entity_id,
6783
- value
6784
- )(
6785
- SELECT
6786
- " . $this->_getProductEntityTypeId(). ",
6787
- " . $this->_getProductAttributeId('image'). ",
6788
- w.store_id,
6789
- a.entity_id,
6790
- b.main_image_url
6791
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6792
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6793
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6794
- ON a.store_product_id = b.store_product_id
6795
- )
6796
- ON DUPLICATE KEY UPDATE
6797
- value = b.main_image_url
6798
- ");
6799
-
6800
-
6801
- // image for specific web sites
6802
- $result = $this->db_do("
6803
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6804
- entity_type_id,
6805
- attribute_id,
6806
- store_id,
6807
- entity_id,
6808
- value
6809
- )(
6810
- SELECT
6811
- " . $this->_getProductEntityTypeId(). ",
6812
- " . $this->_getProductAttributeId('image'). ",
6813
- 0,
6814
- a.entity_id,
6815
- b.main_image_url
6816
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6817
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6818
- ON a.store_product_id = b.store_product_id
6819
- )
6820
- ON DUPLICATE KEY UPDATE
6821
- value = b.main_image_url
6822
- ");
6823
-
6824
-
6825
- // small_image for specific web sites
6826
- $result = $this->db_do("
6827
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6828
- entity_type_id,
6829
- attribute_id,
6830
- store_id,
6831
- entity_id,
6832
- value
6833
- )(
6834
- SELECT
6835
- " . $this->_getProductEntityTypeId(). ",
6836
- " . $this->_getProductAttributeId('small_image'). ",
6837
- w.store_id,
6838
- a.entity_id,
6839
- b.medium_image_url
6840
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6841
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6842
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6843
- ON a.store_product_id = b.store_product_id
6844
- )
6845
- ON DUPLICATE KEY UPDATE
6846
- value = b.medium_image_url
6847
- ");
6848
-
6849
-
6850
- // small_image for all web sites
6851
- $result = $this->db_do("
6852
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6853
- entity_type_id,
6854
- attribute_id,
6855
- store_id,
6856
- entity_id,
6857
- value
6858
- )(
6859
- SELECT
6860
- " . $this->_getProductEntityTypeId(). ",
6861
- " . $this->_getProductAttributeId('small_image'). ",
6862
- 0,
6863
- a.entity_id,
6864
- b.medium_image_url
6865
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6866
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6867
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6868
- ON a.store_product_id = b.store_product_id
6869
- )
6870
- ON DUPLICATE KEY UPDATE
6871
- value = b.medium_image_url
6872
- ");
6873
-
6874
-
6875
- // thumbnail for specific web site
6876
- $result = $this->db_do("
6877
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6878
- entity_type_id,
6879
- attribute_id,
6880
- store_id,
6881
- entity_id,
6882
- value
6883
- )(
6884
- SELECT
6885
- " . $this->_getProductEntityTypeId(). ",
6886
- " . $this->_getProductAttributeId('thumbnail'). ",
6887
- w.store_id,
6888
- a.entity_id,
6889
- b.thumb_image_url
6890
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6891
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6892
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6893
- ON a.store_product_id = b.store_product_id
6894
- )
6895
- ON DUPLICATE KEY UPDATE
6896
- value = b.thumb_image_url
6897
- ");
6898
-
6899
-
6900
- // thumbnail for all web sites
6901
- $result = $this->db_do("
6902
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6903
- entity_type_id,
6904
- attribute_id,
6905
- store_id,
6906
- entity_id,
6907
- value
6908
- )(
6909
- SELECT
6910
- " . $this->_getProductEntityTypeId(). ",
6911
- " . $this->_getProductAttributeId('thumbnail'). ",
6912
- 0,
6913
- a.entity_id,
6914
- b.thumb_image_url
6915
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6916
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6917
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6918
- ON a.store_product_id = b.store_product_id
6919
- )
6920
- ON DUPLICATE KEY UPDATE
6921
- value = b.thumb_image_url
6922
-
6923
- ");
6924
-
6925
- /*STP DELETE
6926
- //Refresh fulltext search
6927
- $result = $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp");
6928
- $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS
6929
- ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp
6930
- LIKE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext'));
6931
-
6932
- $result = $this->db_do("
6933
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
6934
- product_id,
6935
- store_id,
6936
- data_index
6937
- )(
6938
- SELECT
6939
- a.entity_id,
6940
- w.website,
6941
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6942
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6943
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6944
- ON a.store_product_id=w.store_product_id
6945
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
6946
- ON a.entity_id = b.product_id
6947
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
6948
- ON b.category_id = c.entity_id
6949
- AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
6950
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
6951
- ON a.entity_id = e.entity_id
6952
- AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
6953
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." j
6954
- ON a.entity_id = j.product_id
6955
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
6956
- ON a.store_product_id = f.store_product_id
6957
- )
6958
- ON DUPLICATE KEY UPDATE
6959
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6960
- ");
6961
-
6962
- $result = $this->db_do("
6963
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
6964
- product_id,
6965
- store_id,
6966
- data_index
6967
- )(
6968
- SELECT
6969
- a.entity_id,
6970
- w.website,
6971
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6972
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6973
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6974
- ON a.store_product_id=w.store_product_id
6975
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
6976
- ON a.entity_id = b.product_id
6977
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
6978
- ON b.category_id = c.entity_id
6979
- AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
6980
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
6981
- ON a.entity_id = e.entity_id
6982
- AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
6983
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
6984
- ON a.store_product_id = f.store_product_id
6985
- )
6986
- ON DUPLICATE KEY UPDATE
6987
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6988
- ");
6989
-
6990
- $result = $this->db_do("DELETE cf
6991
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." cf
6992
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6993
- ON cf.product_id=cpe.entity_id
6994
- WHERE cpe.entity_id is null");
6995
-
6996
- $result = $this->db_do("
6997
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." (
6998
- product_id,
6999
- store_id,
7000
- data_index
7001
- )(
7002
- SELECT
7003
- a.product_id,
7004
- a.store_id,
7005
- a.data_index
7006
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp a
7007
- WHERE product_id = a.product_id
7008
- )
7009
- ON DUPLICATE KEY UPDATE
7010
- data_index = a.data_index
7011
- ");
7012
-
7013
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_query')." SET is_processed = 0");
7014
- //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
7015
- //TODO add something else
7016
- STP DELETE*/
7017
- $this->addRelatedProducts();
7018
- }
7019
-
7020
- #################################################################################################
7021
- function addReviews(){
7022
- // product reviews for all web sites
7023
- $result = $this->db_do("
7024
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7025
- entity_type_id,
7026
- attribute_id,
7027
- store_id,
7028
- entity_id,
7029
- value
7030
- )(
7031
- SELECT
7032
- " . $this->_getProductEntityTypeId(). ",
7033
- " . $this->_getProductAttributeId('reviews'). ",
7034
- w.website,
7035
- a.entity_id,
7036
- b.Reviews
7037
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7038
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7039
- ON a.store_product_id = b.store_product_id
7040
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7041
- ON a.store_product_id=w.store_product_id
7042
- )
7043
- ON DUPLICATE KEY UPDATE
7044
- value = b.Reviews
7045
- ");
7046
-
7047
- // product Reviews for all web sites
7048
- $result = $this->db_do("
7049
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7050
- entity_type_id,
7051
- attribute_id,
7052
- store_id,
7053
- entity_id,
7054
- value
7055
- )(
7056
- SELECT
7057
- " . $this->_getProductEntityTypeId(). ",
7058
- " . $this->_getProductAttributeId('reviews'). ",
7059
- 0,
7060
- a.entity_id,
7061
- b.Reviews
7062
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7063
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7064
- ON a.store_product_id = b.store_product_id
7065
- )
7066
- ON DUPLICATE KEY UPDATE
7067
- value = b.Reviews
7068
- ");
7069
-
7070
-
7071
- }
7072
-
7073
-
7074
- #################################################################################################
7075
- function addDescriptions(){
7076
- // product description for all web sites
7077
- $result = $this->db_do("
7078
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7079
- entity_type_id,
7080
- attribute_id,
7081
- store_id,
7082
- entity_id,
7083
- value
7084
- )(
7085
- SELECT
7086
- " . $this->_getProductEntityTypeId(). ",
7087
- " . $this->_getProductAttributeId('description'). ",
7088
- w.website,
7089
- a.entity_id,
7090
- b.description
7091
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7092
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7093
- ON a.store_product_id = b.store_product_id
7094
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7095
- ON a.store_product_id=w.store_product_id
7096
- )
7097
- ON DUPLICATE KEY UPDATE
7098
- value = b.description
7099
- ");
7100
-
7101
- // product description for all web sites
7102
- $result = $this->db_do("
7103
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7104
- entity_type_id,
7105
- attribute_id,
7106
- store_id,
7107
- entity_id,
7108
- value
7109
- )(
7110
- SELECT
7111
- " . $this->_getProductEntityTypeId(). ",
7112
- " . $this->_getProductAttributeId('description'). ",
7113
- 0,
7114
- a.entity_id,
7115
- b.description
7116
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7117
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7118
- ON a.store_product_id = b.store_product_id
7119
- )
7120
- ON DUPLICATE KEY UPDATE
7121
- value = b.description
7122
- ");
7123
-
7124
-
7125
- }
7126
- ############################### ##################################################################
7127
- function addSearchCache(){
7128
- // product search_cache for all web sites
7129
- $result = $this->db_do("
7130
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7131
- entity_type_id,
7132
- attribute_id,
7133
- store_id,
7134
- entity_id,
7135
- value
7136
- )(
7137
- SELECT
7138
- " . $this->_getProductEntityTypeId(). ",
7139
- " . $this->_getProductAttributeId('sinch_search_cache'). ",
7140
- w.website,
7141
- a.entity_id,
7142
- b.search_cache
7143
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7144
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7145
- ON a.store_product_id = b.store_product_id
7146
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7147
- ON a.store_product_id=w.store_product_id
7148
- )
7149
- ON DUPLICATE KEY UPDATE
7150
- value = b.search_cache
7151
- ");
7152
-
7153
- // product search_cache for all web sites
7154
- $result = $this->db_do("
7155
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7156
- entity_type_id,
7157
- attribute_id,
7158
- store_id,
7159
- entity_id,
7160
- value
7161
- )(
7162
- SELECT
7163
- " . $this->_getProductEntityTypeId(). ",
7164
- " . $this->_getProductAttributeId('sinch_search_cache'). ",
7165
- 0,
7166
- a.entity_id,
7167
- b.search_cache
7168
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7169
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7170
- ON a.store_product_id = b.store_product_id
7171
- )
7172
- ON DUPLICATE KEY UPDATE
7173
- value = b.search_cache
7174
- ");
7175
-
7176
-
7177
- }
7178
-
7179
- #################################################################################################
7180
- function addPdfUrl(){
7181
- // product PDF Url for all web sites
7182
- $result = $this->db_do("
7183
- UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
7184
- SET pdf_url = CONCAT(
7185
- '<a href=\"#\" onclick=\"popWin(',
7186
- \"'\",
7187
- pdf_url,
7188
- \"'\",
7189
- \", 'pdf', 'width=500,height=800,left=50,top=50, location=no,status=yes,scrollbars=yes,resizable=yes'); return false;\",
7190
- '\"',
7191
- '>',
7192
- pdf_url,
7193
- '</a>')
7194
- WHERE pdf_url != ''
7195
- ");
7196
- //<a title="" onclick="popWin('http://images.icecat.biz/img/gallery/14532248_4539.jpg', 'gallery', 'width=500,height=500,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" href="#">
7197
- $result = $this->db_do("
7198
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7199
- entity_type_id,
7200
- attribute_id,
7201
- store_id,
7202
- entity_id,
7203
- value
7204
- )(
7205
- SELECT
7206
- " . $this->_getProductEntityTypeId(). ",
7207
- " . $this->_getProductAttributeId('pdf_url'). ",
7208
- w.website,
7209
- a.entity_id,
7210
- b.pdf_url
7211
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7212
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7213
- ON a.store_product_id = b.store_product_id
7214
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7215
- ON a.store_product_id=w.store_product_id
7216
- )
7217
- ON DUPLICATE KEY UPDATE
7218
- value = b.pdf_url
7219
- ");
7220
- // product PDF url for all web sites
7221
- $result = $this->db_do("
7222
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7223
- entity_type_id,
7224
- attribute_id,
7225
- store_id,
7226
- entity_id,
7227
- value
7228
- )(
7229
- SELECT
7230
- " . $this->_getProductEntityTypeId(). ",
7231
- " . $this->_getProductAttributeId('pdf_url'). ",
7232
- 0,
7233
- a.entity_id,
7234
- b.pdf_url
7235
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7236
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7237
- ON a.store_product_id = b.store_product_id
7238
- )
7239
- ON DUPLICATE KEY UPDATE
7240
- value = b.pdf_url
7241
- ");
7242
-
7243
- }
7244
-
7245
- #################################################################################################
7246
- function cleanProductDistributors(){
7247
- for($i=1; $i<=5; $i++){
7248
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
7249
- SET value = ''
7250
- WHERE entity_type_id=".$this->_getProductEntityTypeId()." AND attribute_id=".$this->_getProductAttributeId('supplier_'.$i));
7251
- }
7252
- }
7253
- #################################################################################################
7254
- function addProductDistributors(){
7255
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary'));
7256
- $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')."
7257
- LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7258
- $this->db_do("INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." SELECT * FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7259
- for($i=1; $i<=5; $i++){
7260
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier'));
7261
- $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')."
7262
- LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7263
- $this->db_do("INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." SELECT * FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." GROUP BY store_product_id");
7264
-
7265
- // product Distributors for all web sites
7266
- $result = $this->db_do("
7267
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7268
- entity_type_id,
7269
- attribute_id,
7270
- store_id,
7271
- entity_id,
7272
- value
7273
- )(
7274
- SELECT
7275
- " . $this->_getProductEntityTypeId(). ",
7276
- " . $this->_getProductAttributeId('supplier_'.$i). ",
7277
- w.website,
7278
- a.entity_id,
7279
- d.distributor_name
7280
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7281
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." b
7282
- ON a.store_product_id = b.store_product_id
7283
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors')." d
7284
- ON b.distributor_id = d.distributor_id
7285
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7286
- ON a.store_product_id=w.store_product_id
7287
- )
7288
- ON DUPLICATE KEY UPDATE
7289
- value = d.distributor_name
7290
- ");
7291
- // product Distributors for all web sites
7292
- $result = $this->db_do("
7293
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7294
- entity_type_id,
7295
- attribute_id,
7296
- store_id,
7297
- entity_id,
7298
- value
7299
- )(
7300
- SELECT
7301
- " . $this->_getProductEntityTypeId(). ",
7302
- " . $this->_getProductAttributeId('supplier_'.$i). ",
7303
- 0,
7304
- a.entity_id,
7305
- d.distributor_name
7306
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7307
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." b
7308
- ON a.store_product_id = b.store_product_id
7309
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors')." d
7310
- ON b.distributor_id = d.distributor_id
7311
- )
7312
- ON DUPLICATE KEY UPDATE
7313
- value = d.distributor_name
7314
- ");
7315
-
7316
- $this->db_do("DELETE sdsapt FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." sdsapt JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." sdsapts ON sdsapt.store_product_id = sdsapts.store_product_id AND sdsapt.distributor_id = sdsapts.distributor_id");
7317
-
7318
-
7319
- }
7320
-
7321
- }
7322
-
7323
-
7324
-
7325
- #################################################################################################
7326
- function addShortDescriptions(){
7327
- // product short description for all web sites
7328
- $result = $this->db_do("
7329
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7330
- entity_type_id,
7331
- attribute_id,
7332
- store_id,
7333
- entity_id,
7334
- value
7335
- )(
7336
- SELECT
7337
- " . $this->_getProductEntityTypeId(). ",
7338
- " . $this->_getProductAttributeId('short_description'). ",
7339
- w.website,
7340
- a.entity_id,
7341
- b.product_short_description
7342
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7343
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7344
- ON a.store_product_id = b.store_product_id
7345
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7346
- ON a.store_product_id=w.store_product_id
7347
- )
7348
- ON DUPLICATE KEY UPDATE
7349
- value = b.product_short_description
7350
- ");
7351
- // product short description for all web sites
7352
- $result = $this->db_do("
7353
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7354
- entity_type_id,
7355
- attribute_id,
7356
- store_id,
7357
- entity_id,
7358
- value
7359
- )(
7360
- SELECT
7361
- " . $this->_getProductEntityTypeId(). ",
7362
- " . $this->_getProductAttributeId('short_description'). ",
7363
- 0,
7364
- a.entity_id,
7365
- b.product_short_description
7366
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7367
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7368
- ON a.store_product_id = b.store_product_id
7369
- )
7370
- ON DUPLICATE KEY UPDATE
7371
- value = b.product_short_description
7372
- ");
7373
-
7374
- }
7375
-
7376
- #################################################################################################
7377
- function addEAN(){
7378
- //gather EAN codes for each product
7379
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('EANs_temp'));
7380
- $this->db_do("
7381
- CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
7382
- sinch_product_id int(11),
7383
- store_product_id int(11),
7384
- EANs text,
7385
- KEY `sinch_product_id` (`sinch_product_id`),
7386
- KEY `store_product_id` (`store_product_id`)
7387
- )
7388
- ");
7389
- $this->db_do("
7390
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
7391
- sinch_product_id,
7392
- EANs
7393
- )(SELECT
7394
- sec.product_id,
7395
- GROUP_CONCAT(DISTINCT ean_code ORDER BY ean_code DESC SEPARATOR ', ') AS eans
7396
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
7397
- GROUP BY sec.product_id
7398
- )
7399
- ");
7400
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7401
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7402
- ON e.sinch_product_id=p.sinch_product_id
7403
- SET e.store_product_id=p.store_product_id");
7404
- // product EANs for all web sites
7405
- $result = $this->db_do("
7406
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7407
- entity_type_id,
7408
- attribute_id,
7409
- store_id,
7410
- entity_id,
7411
- value
7412
- )(
7413
- SELECT
7414
- " . $this->_getProductEntityTypeId(). ",
7415
- " . $this->_getProductAttributeId('ean'). ",
7416
- w.website,
7417
- a.entity_id,
7418
- e.EANs
7419
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7420
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7421
- ON a.store_product_id = e.store_product_id
7422
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7423
- ON a.store_product_id=w.store_product_id
7424
- )
7425
- ON DUPLICATE KEY UPDATE
7426
- value = e.EANs
7427
- ");
7428
-
7429
- // product EANs for all web sites
7430
- $result = $this->db_do("
7431
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7432
- entity_type_id,
7433
- attribute_id,
7434
- store_id,
7435
- entity_id,
7436
- value
7437
- )(
7438
- SELECT
7439
- " . $this->_getProductEntityTypeId(). ",
7440
- " . $this->_getProductAttributeId('ean'). ",
7441
- 0,
7442
- a.entity_id,
7443
- e.EANs
7444
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7445
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7446
- ON a.store_product_id = e.store_product_id
7447
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7448
- ON a.store_product_id=w.store_product_id
7449
- )
7450
- ON DUPLICATE KEY UPDATE
7451
- value = e.EANs
7452
- ");
7453
-
7454
- }
7455
-
7456
- ################################################################################################
7457
- function addSpecification(){
7458
- // product specification for all web sites
7459
- $result = $this->db_do("
7460
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7461
- entity_type_id,
7462
- attribute_id,
7463
- store_id,
7464
- entity_id,
7465
- value
7466
- )(
7467
- SELECT
7468
- " . $this->_getProductEntityTypeId(). ",
7469
- " . $this->_getProductAttributeId('specification'). ",
7470
- w.website,
7471
- a.entity_id,
7472
- b.specifications
7473
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7474
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7475
- ON a.store_product_id = b.store_product_id
7476
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7477
- ON a.store_product_id=w.store_product_id
7478
- )
7479
- ON DUPLICATE KEY UPDATE
7480
- value = b.specifications
7481
- ");
7482
- // product specification for all web sites
7483
- $result = $this->db_do("
7484
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7485
- entity_type_id,
7486
- attribute_id,
7487
- store_id,
7488
- entity_id,
7489
- value
7490
- )(
7491
- SELECT
7492
- " . $this->_getProductEntityTypeId(). ",
7493
- " . $this->_getProductAttributeId('specification'). ",
7494
- 0,
7495
- a.entity_id,
7496
- b.specifications
7497
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7498
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7499
- ON a.store_product_id = b.store_product_id
7500
- )
7501
- ON DUPLICATE KEY UPDATE
7502
- value = b.specifications
7503
- ");
7504
-
7505
-
7506
- }
7507
-
7508
- private function addManufacturer_attribute(){
7509
- $result = $this->db_do("
7510
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
7511
- entity_type_id,
7512
- attribute_id,
7513
- store_id,
7514
- entity_id,
7515
- value
7516
- )(
7517
- SELECT
7518
- " . $this->_getProductEntityTypeId(). ",
7519
- " . $this->_getProductAttributeId('manufacturer'). ",
7520
- 0,
7521
- a.entity_id,
7522
- pm.manufacturer_option_id
7523
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7524
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
7525
- ON a.entity_id = pm.entity_id
7526
- )
7527
- ON DUPLICATE KEY UPDATE
7528
- value = pm.manufacturer_option_id
7529
- ");
7530
-
7531
-
7532
- }
7533
-
7534
- #################################################################################################
7535
- function addManufacturers($delete_eav=null){
7536
- // this cleanup is not needed due to foreign keys
7537
- if(!$delete_eav){
7538
- $result = $this->db_do("
7539
- DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')."
7540
- WHERE attribute_id = ".$this->_getProductAttributeId('manufacturer')//." AND store_id = ".$websiteId
7541
- );
7542
- }
7543
- $this->addManufacturer_attribute();
7544
- // todo: doesn't seems to work properly, should be inserted per visibility
7545
- // done, test now
7546
-
7547
- $result = $this->db_do("
7548
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
7549
- entity_id,
7550
- attribute_id,
7551
- store_id,
7552
- value
7553
- )(
7554
- SELECT
7555
- a.entity_id,
7556
- " . $this->_getProductAttributeId('manufacturer'). ",
7557
- w.website,
7558
- mn.shop_option_id
7559
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7560
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7561
- ON a.store_product_id = b.store_product_id
7562
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7563
- ON a.store_product_id=w.store_product_id
7564
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
7565
- ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
7566
- WHERE mn.shop_option_id IS NOT NULL
7567
- )
7568
- ON DUPLICATE KEY UPDATE
7569
- value = mn.shop_option_id
7570
- ");
7571
-
7572
- $result = $this->db_do("
7573
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
7574
- entity_id,
7575
- attribute_id,
7576
- store_id,
7577
- value
7578
- )(
7579
- SELECT
7580
- a.entity_id,
7581
- " . $this->_getProductAttributeId('manufacturer'). ",
7582
- 0,
7583
- mn.shop_option_id
7584
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7585
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7586
- ON a.store_product_id = b.store_product_id
7587
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7588
- ON a.store_product_id=w.store_product_id
7589
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
7590
- ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
7591
- WHERE mn.shop_option_id IS NOT NULL
7592
- )
7593
- ON DUPLICATE KEY UPDATE
7594
- value = mn.shop_option_id
7595
- ");
7596
-
7597
-
7598
- }
7599
-
7600
- #################################################################################################
7601
- function addRelatedProducts(){
7602
-
7603
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
7604
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7605
- ON rpt.sinch_product_id=p.sinch_product_id
7606
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7607
- ON p.store_product_id=cpe.store_product_id
7608
- SET rpt.store_product_id=p.store_product_id, rpt.entity_id=cpe.entity_id");
7609
-
7610
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
7611
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7612
- ON rpt.related_sinch_product_id=p.sinch_product_id
7613
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7614
- ON p.store_product_id=cpe.store_product_id
7615
- SET rpt.store_related_product_id=p.store_product_id, rpt.related_entity_id=cpe.entity_id");
7616
-
7617
- $result = $this->db_do("SELECT
7618
- link_type_id,
7619
- code
7620
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_type')
7621
- );
7622
- $link_type=array();
7623
- while ($row = mysqli_fetch_array($result)) {
7624
- $link_type[$row['code']]=$row['link_type_id'];
7625
- }
7626
-
7627
- $result = $this->db_do("
7628
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." (
7629
- product_id,
7630
- linked_product_id,
7631
- link_type_id
7632
- )(
7633
- SELECT
7634
- entity_id,
7635
- related_entity_id,
7636
- ".$link_type['relation']."
7637
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')."
7638
- WHERE store_product_id IS NOT NULL
7639
- AND store_related_product_id IS NOT NULL
7640
- )
7641
- ON DUPLICATE KEY UPDATE
7642
- product_id = entity_id,
7643
- linked_product_id = related_entity_id
7644
- ");
7645
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp");
7646
-
7647
- $this->db_do("CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp (
7648
- `value_id` int(11) default NULL,
7649
- `product_link_attribute_id` smallint(6) unsigned default NULL,
7650
- `link_id` int(11) unsigned default NULL,
7651
- `value` int(11) NOT NULL default '0',
7652
- KEY `FK_INT_PRODUCT_LINK_ATTRIBUTE` (`product_link_attribute_id`),
7653
- KEY `FK_INT_PRODUCT_LINK` (`link_id`)
7654
- )
7655
- ");
7656
-
7657
- $result = $this->db_do("
7658
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp(
7659
- product_link_attribute_id,
7660
- link_id,
7661
- value
7662
- )(
7663
- SELECT
7664
- 2,
7665
- cpl.link_id,
7666
- 0
7667
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." cpl
7668
- )
7669
- ");
7670
-
7671
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
7672
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." c
7673
- ON ct.link_id=c.link_id
7674
- SET ct.value_id=c.value_id
7675
- WHERE c.product_link_attribute_id=2
7676
- ");
7677
-
7678
- $result = $this->db_do("
7679
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." (
7680
- value_id,
7681
- product_link_attribute_id,
7682
- link_id,
7683
- value
7684
- )(
7685
- SELECT
7686
- value_id,
7687
- product_link_attribute_id,
7688
- link_id,
7689
- value
7690
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
7691
- )
7692
- ON DUPLICATE KEY UPDATE
7693
- link_id=ct.link_id
7694
-
7695
- ");
7696
-
7697
- /* $q="select distinct store_product_id from stINch_related_products";
7698
- $quer=$this->db_do($q);
7699
- $prod = Mage::getModel('catalog/product');
7700
- while ($row = mysqli_fetch_assoc($quer)) {
7701
- $q1="select distinct store_related_product_id store_product_id from stINch_related_products where store_product_id=".$row['store_product_id'].;
7702
- $quer1=$this->db_do($q1);
7703
- $prod->load($row['store_product_id']);
7704
-
7705
- ###//get related product data (product id's and positions)
7706
- ###$relatedData = array();
7707
- ###foreach ($product->getRelatedLinkCollection() as $link) {
7708
- ### $relatedData[$link->getLinkedProductId()]['position'] = $link->getPosition();
7709
- ###}
7710
- ###//manipulate $relatedData array
7711
- ###// ...
7712
- ###//set and save related product data
7713
- ###$product->setRelatedLinkData($relatedData);
7714
- ###$product->save();
7715
- ###
7716
- $i=1;
7717
- while ($row1 = mysqli_fetch_assoc($quer1)) {
7718
- $param[$row1['store_related_product_id']]['position']=$i++;
7719
-
7720
- }
7721
- $prod->setRelatedLinkData($param);
7722
- //here ... some other product operations and in the end
7723
- $prod->save();
7724
-
7725
- }
7726
- */
7727
- }
7728
- #################################################################################################
7729
- function addWeight(){
7730
- // product weight for specific web site
7731
- $result = $this->db_do("
7732
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
7733
- entity_type_id,
7734
- attribute_id,
7735
- store_id,
7736
- entity_id,
7737
- value
7738
- )(
7739
- SELECT
7740
- " . $this->_getProductEntityTypeId(). ",
7741
- " . $this->_getProductAttributeId('weight'). ",
7742
- w.website,
7743
- a.entity_id,
7744
- b.Weight
7745
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7746
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7747
- ON a.store_product_id = b.store_product_id
7748
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7749
- ON a.store_product_id=w.store_product_id
7750
- )
7751
- ON DUPLICATE KEY UPDATE
7752
- value = b.Weight
7753
- ");
7754
- // product weight for all web sites
7755
- $result = $this->db_do("
7756
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
7757
- entity_type_id,
7758
- attribute_id,
7759
- store_id,
7760
- entity_id,
7761
- value
7762
- )(
7763
- SELECT
7764
- " . $this->_getProductEntityTypeId(). ",
7765
- " . $this->_getProductAttributeId('weight'). ",
7766
- 0,
7767
- a.entity_id,
7768
- b.Weight
7769
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7770
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7771
- ON a.store_product_id = b.store_product_id
7772
- )
7773
- ON DUPLICATE KEY UPDATE
7774
- value = b.Weight
7775
-
7776
-
7777
- ");
7778
-
7779
-
7780
- }
7781
-
7782
- #################################################################################################
7783
- function _getProductsForCustomerGroupPrice(){
7784
- // TEMPORARY
7785
- $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp'));
7786
- $this->db_do("
7787
- CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')."
7788
- (
7789
- `category_id` int(10) unsigned NOT NULL default '0',
7790
- `product_id` int(10) unsigned NOT NULL default '0',
7791
- `store_product_id` int(10) NOT NULL default '0',
7792
- `sku` varchar(64) DEFAULT NULL COMMENT 'SKU',
7793
- `manufacturer_id` int(10) NOT NULL default '0',
7794
- `price` decimal(15,4) DEFAULT NULL,
7795
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`product_id`,`category_id`),
7796
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
7797
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`)
7798
- )");
7799
-
7800
- $result = $this->db_do("
7801
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')."
7802
- (category_id, product_id, store_product_id, sku)
7803
- (SELECT
7804
- ccp.category_id,
7805
- ccp.product_id,
7806
- cpe.store_product_id,
7807
- cpe.sku
7808
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
7809
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7810
- ON ccp.product_id = cpe.entity_id
7811
- WHERE cpe.store_product_id IS NOT NULL)");
7812
-
7813
- $result = $this->db_do("
7814
- UPDATE ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." pfcgpt
7815
- JOIN ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." cpei
7816
- ON pfcgpt.product_id = cpei.entity_id
7817
- AND cpei.entity_type_id = " . $this->_getProductEntityTypeId(). "
7818
- AND cpei.attribute_id = " . $this->_getProductAttributeId('manufacturer'). "
7819
- SET pfcgpt.manufacturer_id = cpei.value
7820
- ");
7821
-
7822
- $result = $this->db_do("
7823
- UPDATE ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." pfcgpt
7824
- JOIN ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." cped
7825
- ON pfcgpt.product_id = cped.entity_id
7826
- AND cped.entity_type_id = " . $this->_getProductEntityTypeId(). "
7827
- AND cped.attribute_id = " . $this->_getProductAttributeId('price'). "
7828
- SET pfcgpt.price = cped.value
7829
- ");
7830
-
7831
-
7832
-
7833
- }
7834
-
7835
- #################################################################################################
7836
- function ApplyCustomerGroupPrice(){
7837
- if (!$this->check_table_exist('import_pricerules_standards')){
7838
- return;
7839
- }
7840
- $this->_getProductsForCustomerGroupPrice();
7841
- $pricerulesArray = $this->_getPricerulesList();
7842
- if(is_array($pricerulesArray)){
7843
- $this->db_do("TRUNCATE TABLE ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_group_price'));
7844
- $this->db_do("TRUNCATE TABLE ". Mage::getSingleton('core/resource')->getTableName('catalog_product_index_group_price'));
7845
-
7846
- }
7847
- // $i=1;
7848
- foreach($pricerulesArray as $pricerule) {
7849
- $this->_LOG("Calculation group price for rule ".$pricerule['id']."
7850
- (\nname = ".$pricerule['name']."
7851
- \nfinal_price = ".$pricerule['final_price']."
7852
- \nprice_from = ".$pricerule['price_from']."
7853
- \nprice_to = ".$pricerule['price_to']."
7854
- \nvendor_id = ".$pricerule['vendor_id']."
7855
- \ncategory_id = ".$pricerule['category_id']."
7856
- \nproduct_entity_id = ".$pricerule['product_entity_id']."
7857
- \nvendor_product_id = ".$pricerule['vendor_product_id']."
7858
- \ncustomergroup_id = ".$pricerule['customergroup_id']."
7859
- \ndistributor_id = ".$pricerule['distributor_id']."
7860
- \nrating = ".$pricerule['rating']."
7861
- \nmarge = ".$pricerule['marge']."
7862
- \nfixed = ".$pricerule['fixed']."
7863
- \nallow_subcat = ".$pricerule['allow_subcat']."
7864
- \nstore_id = ".$pricerule['store_id']."
7865
- )");
7866
-
7867
- $vendor_product_id_str = "'".str_replace(';', "','", $pricerule['vendor_product_id'])."'";
7868
- $where = "";
7869
- if (empty($pricerule['marge'])) $marge = "NULL";
7870
- else $marge = $pricerule['marge'];
7871
-
7872
- if (empty($pricerule['fixed'])) $fixed = "NULL";
7873
- else $fixed = $pricerule['fixed'];
7874
-
7875
- if (empty($pricerule['final_price'])) $final_price = "NULL";
7876
- else $final_price = $pricerule['final_price'];
7877
-
7878
- if (!empty($pricerule['price_from'])) $where.= " AND a.price > ".$pricerule['price_from'];
7879
-
7880
- if (!empty($pricerule['price_to'])) $where.= " AND a.price < ".$pricerule['price_to'];
7881
-
7882
- if (!empty($pricerule['vendor_id'])) $where.= " AND a.manufacturer_id = ".$pricerule['vendor_id'];
7883
-
7884
- //if(!empty($pricerule['vendor_product_id']))
7885
- // $where.= " AND vendor_product_id = ".$pricerule['vendor_product_id'];
7886
- if (!empty($pricerule['product_entity_id'])) $where.= " AND a.product_id = '".$pricerule['product_entity_id']."'";
7887
-
7888
- // if (!empty($pricerule['vendor_product_id'])) $where.= " AND a.sku = '".$pricerule['vendor_product_id']."'";
7889
- if (!empty($pricerule['vendor_product_id'])) $where.= " AND a.sku IN (". $vendor_product_id_str.")";
7890
-
7891
- if(!empty($pricerule['allow_subcat'])){
7892
- if (!empty($pricerule['category_id'])){
7893
- $children_cat=$this->get_all_children_cat($pricerule['category_id']);
7894
- $where.= " AND a.category_id IN (".$children_cat.")";
7895
- }
7896
- }else{
7897
- if (!empty($pricerule['category_id'])) $where.= " AND a.category_id = ".$pricerule['category_id'];
7898
- }
7899
-
7900
-
7901
- // if (!empty($pricerule['store_id'])) $where.= " AND store_id = ".$pricerule['store_id'];
7902
-
7903
- // if (!empty($pricerule['distributor_id'])) $where.= " AND distributor_id = ".$pricerule['distributor_id'];
7904
-
7905
- // $this->createCalcPriceFunc();
7906
- //echo "\n\nAAAAAAAAAAAAAAAAAAAAa".$pricerule['customergroup_id']."----------";
7907
- $customer_group_id_array = array();
7908
- if(strstr($pricerule['customergroup_id'], ",")){
7909
- //echo "55555555555555555";
7910
- $customer_group_id_array = explode(",", $pricerule['customergroup_id']);
7911
- }else{
7912
- $customer_group_id_array[0] = $pricerule['customergroup_id'];
7913
- }
7914
- // var_dump($pricerule);
7915
- // echo "CCCCCCC\n";
7916
- // var_dump($customer_group_id_array);
7917
- foreach($customer_group_id_array as $customer_group_id){
7918
- if(isset($customer_group_id) && $customer_group_id>=0){
7919
- $query="
7920
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_group_price')." (entity_id,
7921
- all_groups,
7922
- customer_group_id,
7923
- value,
7924
- website_id
7925
- )
7926
- (SELECT
7927
- a.product_id,
7928
- 0,
7929
- ".$customer_group_id.",
7930
- ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7931
- a.price,
7932
- ".$marge." ,
7933
- ".$fixed.",
7934
- ".$final_price."),
7935
- 0
7936
- FROM ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." a
7937
- WHERE true ".$where."
7938
- )
7939
- ON DUPLICATE KEY UPDATE
7940
- value =
7941
- ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7942
- a.price,
7943
- ".$marge." ,
7944
- ".$fixed.",
7945
- ".$final_price.")
7946
- ";
7947
- // echo "\n\n".$query;
7948
- $this->db_do($query);
7949
- if (!empty($pricerule['store_id']) && $pricerule['store_id']>0){
7950
- $query="
7951
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_group_price')." (entity_id,
7952
- customer_group_id,
7953
- price,
7954
- website_id
7955
- )
7956
- (SELECT
7957
- a.product_id,
7958
- ".$customer_group_id.",
7959
- ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7960
- a.price,
7961
- ".$marge." ,
7962
- ".$fixed.",
7963
- ".$final_price."),
7964
- ".$pricerule['store_id']."
7965
- FROM ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." a
7966
- WHERE true ".$where."
7967
- )
7968
- ON DUPLICATE KEY UPDATE
7969
- price =
7970
- ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7971
- a.price,
7972
- ".$marge." ,
7973
- ".$fixed.",
7974
- ".$final_price.")
7975
- ";
7976
- // echo "\n\n".$query;
7977
- $this->db_do($query);
7978
-
7979
- }
7980
- }
7981
- }
7982
- }
7983
-
7984
- }
7985
- #################################################################################################
7986
-
7987
- protected function _getPricerulesList() {
7988
- $rulesArray = array();
7989
- $result = $this->db_do("
7990
- SELECT *
7991
- FROM ".Mage::getSingleton('core/resource')->getTableName('import_pricerules')."
7992
- ORDER BY rating DESC
7993
- ");
7994
- while($row = mysqli_fetch_assoc($result)) {
7995
- $rulesArray[$row['id']] = $row;
7996
- }
7997
- return $rulesArray;
7998
- }
7999
-
8000
-
8001
- #################################################################################################
8002
- function replaceMagentoProductsStockPrice(){
8003
- //Add stock
8004
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
8005
- $result = $this->db_do("DELETE csi
8006
- FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
8007
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8008
- ON csi.product_id=cpe.entity_id
8009
- WHERE cpe.entity_id is null");
8010
- //set all sinch products stock=0 before upgrade (nedds for dayly stock&price import)
8011
-
8012
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8013
- JOIN ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
8014
- ON cpe.entity_id=csi.product_id
8015
- SET
8016
- csi.qty=0,
8017
- csi.is_in_stock=0
8018
- WHERE cpe.store_product_id IS NOT NULL");
8019
-
8020
- $result = $this->db_do("
8021
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." (
8022
- product_id,
8023
- stock_id,
8024
- qty,
8025
- is_in_stock,
8026
- manage_stock
8027
- )(
8028
- SELECT
8029
- a.entity_id,
8030
- 1,
8031
- b.stock,
8032
- IF(b.stock > 0, 1, 0),
8033
- 1
8034
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8035
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8036
- ON a.store_product_id=b.store_product_id
8037
- )
8038
- ON DUPLICATE KEY UPDATE
8039
- qty=b.stock,
8040
- is_in_stock = IF(b.stock > 0, 1, 0),
8041
- manage_stock = 1
8042
- ");
8043
-
8044
-
8045
- $result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status'));
8046
-
8047
- $result = $this->db_do("
8048
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status')." (
8049
- product_id,
8050
- website_id,
8051
- stock_id,
8052
- qty,
8053
- stock_status
8054
- )(
8055
- SELECT
8056
- a.product_id,
8057
- w.website_id,
8058
- 1,
8059
- a.qty,
8060
- IF(qty > 0, 1, 0)
8061
- FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." a
8062
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." b
8063
- ON a.product_id=b.entity_id
8064
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8065
- ON b.store_product_id=w.store_product_id
8066
- )
8067
- ON DUPLICATE KEY UPDATE
8068
- qty=a.qty,
8069
- stock_status = IF(a.qty > 0, 1, 0)
8070
- ");
8071
-
8072
- //Add prices
8073
- //$result = $this->db_do("truncate catalog_product_entity_decimal");
8074
- $result = $this->db_do("DELETE cped
8075
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." cped
8076
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8077
- ON cped.entity_id=cpe.entity_id
8078
- WHERE cpe.entity_id IS NULL");
8079
-
8080
- $result = $this->db_do("
8081
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8082
- entity_type_id,
8083
- attribute_id,
8084
- store_id,
8085
- entity_id,
8086
- value
8087
- )(
8088
- SELECT
8089
- " . $this->_getProductEntityTypeId(). ",
8090
- " . $this->_getProductAttributeId('price'). ",
8091
- w.website,
8092
- a.entity_id,
8093
- b.price
8094
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8095
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8096
- ON a.store_product_id=b.store_product_id
8097
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8098
- ON a.store_product_id=w.store_product_id
8099
- )
8100
- ON DUPLICATE KEY UPDATE
8101
- value = b.price
8102
- ");
8103
-
8104
- $result = $this->db_do("
8105
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8106
- entity_type_id,
8107
- attribute_id,
8108
- store_id,
8109
- entity_id,
8110
- value
8111
- )(
8112
- SELECT
8113
- " . $this->_getProductEntityTypeId(). ",
8114
- " . $this->_getProductAttributeId('price'). ",
8115
- 0,
8116
- a.entity_id,
8117
- b.price
8118
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8119
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8120
- ON a.store_product_id=b.store_product_id
8121
- )
8122
- ON DUPLICATE KEY UPDATE
8123
- value = b.price
8124
- ");
8125
- //Add cost
8126
- // $result = $this->db_do("truncate catalog_product_entity_decimal");
8127
- $result = $this->db_do("
8128
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8129
- entity_type_id,
8130
- attribute_id,
8131
- store_id,
8132
- entity_id,
8133
- value
8134
- )(
8135
- SELECT
8136
- " . $this->_getProductEntityTypeId(). ",
8137
- " . $this->_getProductAttributeId('cost'). ",
8138
- w.website,
8139
- a.entity_id,
8140
- b.cost
8141
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8142
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8143
- ON a.store_product_id=b.store_product_id
8144
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8145
- ON a.store_product_id=w.store_product_id
8146
- )
8147
- ON DUPLICATE KEY UPDATE
8148
- value = b.cost
8149
- ");
8150
-
8151
- $result = $this->db_do("
8152
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8153
- entity_type_id,
8154
- attribute_id,
8155
- store_id,
8156
- entity_id,
8157
- value
8158
- )(
8159
- SELECT
8160
- " . $this->_getProductEntityTypeId(). ",
8161
- " . $this->_getProductAttributeId('cost'). ",
8162
- 0,
8163
- a.entity_id,
8164
- b.cost
8165
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8166
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8167
- ON a.store_product_id=b.store_product_id
8168
- )
8169
- ON DUPLICATE KEY UPDATE
8170
- value = b.cost
8171
- ");
8172
-
8173
- //make products enable in FO
8174
- // $result = $this->db_do(" truncate catalog_product_index_price");
8175
- $result = $this->db_do("DELETE cpip
8176
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." cpip
8177
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8178
- ON cpip.entity_id=cpe.entity_id
8179
- WHERE cpe.entity_id IS NULL");
8180
-
8181
- $q="SELECT customer_group_id FROM ".Mage::getSingleton('core/resource')->getTableName('customer_group');
8182
- $quer=$this->db_do($q);
8183
-
8184
- while ($row = mysqli_fetch_assoc($quer)) {
8185
- $result = $this->db_do("
8186
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." (
8187
- entity_id,
8188
- customer_group_id,
8189
- website_id,
8190
- tax_class_id,
8191
- price,
8192
- final_price,
8193
- min_price,
8194
- max_price
8195
- )(SELECT
8196
- a.entity_id,
8197
- ".$row['customer_group_id'].",
8198
- w.website_id,
8199
- 2,
8200
- b.price ,
8201
- b.price ,
8202
- b.price ,
8203
- b.price
8204
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8205
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8206
- ON a.store_product_id=b.store_product_id
8207
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8208
- ON a.store_product_id=w.store_product_id
8209
- )
8210
- ON DUPLICATE KEY UPDATE
8211
- tax_class_id = 2,
8212
- price = b.price,
8213
- final_price = b.price,
8214
- min_price = b.price,
8215
- max_price = b.price
8216
- ");
8217
- }
8218
- }
8219
-
8220
-
8221
-
8222
- #################################################################################################
8223
-
8224
- function getProductDescription($entity_id){
8225
-
8226
- $this->loadProductParams($entity_id);
8227
- $this->loadProductStarfeatures($entity_id);
8228
- $this->loadGalleryPhotos($entity_id);
8229
- Varien_Profiler::start('Bintime FILE RELATED');
8230
- $this->loadRelatedProducts($entity_id);
8231
- Varien_Profiler::stop('Bintime FILE RELATED');
8232
-
8233
- return true;
8234
- }
8235
- #################################################################################################
8236
-
8237
- public function getProductName(){
8238
- return $this->productName;
8239
- }
8240
- #################################################################################################
8241
-
8242
- public function getProductDescriptionList(){
8243
- return $this->productDescriptionList;
8244
- }
8245
- #################################################################################################
8246
-
8247
- public function getProductSpecifications(){
8248
- return $this->specifications;
8249
- }
8250
- #################################################################################################
8251
-
8252
- public function getShortProductDescription(){
8253
- return $this->productDescription;
8254
- }
8255
- #################################################################################################
8256
-
8257
- public function getFullProductDescription(){
8258
- return $this->fullProductDescription;
8259
- }
8260
- #################################################################################################
8261
-
8262
- public function getLowPicUrl(){
8263
- return $this->highPicUrl;
8264
- }
8265
- #################################################################################################
8266
-
8267
- public function getRelatedProducts(){
8268
- return $this->relatedProducts;
8269
- }
8270
- #################################################################################################
8271
-
8272
- public function getVendor(){
8273
- return $this->vendor;
8274
- }
8275
- #################################################################################################
8276
-
8277
- public function getMPN(){
8278
- return $this->productId;
8279
- }
8280
- #################################################################################################
8281
-
8282
- public function getEAN(){
8283
- return $this->EAN;
8284
- }
8285
- ################################################################################################
8286
-
8287
- public function getGalleryPhotos(){
8288
- return $this->galleryPhotos;
8289
- }
8290
-
8291
- #################################################################################################
8292
-
8293
- private function loadProductParams($entity_id){
8294
- $store_product_id=$this->getStoreProductIdByEntity($entity_id);
8295
- if(!$store_product_id){
8296
- // echo "AAAAAAA"; exit;
8297
- return;
8298
- }
8299
- $q="SELECT
8300
- sinch_product_id,
8301
- product_sku,
8302
- product_name,
8303
- sinch_manufacturer_id,
8304
- store_category_id,
8305
- main_image_url,
8306
- thumb_image_url,
8307
- medium_image_url,
8308
- specifications,
8309
- description,
8310
- specifications
8311
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products')."
8312
- WHERE store_product_id =".$store_product_id;
8313
- $quer=$this->db_do($q);
8314
- $product=mysqli_fetch_array($quer);
8315
-
8316
- $this->productDescription = (string) substr($product['description'],50,0);
8317
- $this->fullProductDescription = (string)$product['description'];
8318
- $this->lowPicUrl = (string)$product["medium_image_url"];//thumb_image_url"];
8319
- $this->highPicUrl = (string)$product["main_image_url"];
8320
- $this->productName = (string)$product["product_name"];
8321
- $this->productId = (string)$product['product_sku'];
8322
- $this->specifications = (string)$product['specifications'];
8323
- $this->sinchProductId = (string)$product['sinch_product_id'];
8324
- if($product['sinch_manufacturer_id']){
8325
- $q="SELECT manufacturer_name
8326
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')."
8327
- WHERE sinch_manufacturer_id=".$product['sinch_manufacturer_id'];
8328
- $quer=$this->db_do($q);
8329
- $manufacturer=mysqli_fetch_array($quer);
8330
- $this->vendor = (string)$manufacturer['manufacturer_name'];
8331
- }
8332
- $q="SELECT DISTINCT ean_code
8333
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
8334
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
8335
- ON sec.product_id=sp.sinch_product_id
8336
- WHERE sp.store_product_id=".$store_product_id;
8337
- $quer=$this->db_do($q);
8338
- while ($row=mysqli_fetch_array($quer)){
8339
- $EANarr[]=$row['ean_code'];
8340
- }
8341
- // $prodEAN = $productTag->EANCode;
8342
- $EANstr='';
8343
- /* $EANarr=null;
8344
- foreach($prodEAN as $ellEAN){
8345
- $EANarr[]=$ellEAN['EAN'];
8346
- }
8347
- */
8348
- $EANstr=implode(", ",$EANarr);
8349
- $this->EAN = (string)$EANstr;//$productTag->EANCode['EAN'];
8350
- }
8351
- #################################################################################################
8352
-
8353
- private function loadProductStarfeatures($entity_id){
8354
- $descriptionArray=array();
8355
- $product_info_features = $this->db_do("
8356
- SELECT c.feature_name AS name, b.text AS value
8357
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." a
8358
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." b
8359
- ON a.restricted_value_id = b.restricted_value_id
8360
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features')." c
8361
- ON b.category_feature_id = c.category_feature_id
8362
- WHERE a.sinch_product_id = '" .$this->sinchProductId . "'" );
8363
- while ($features = mysqli_fetch_array($product_info_features)) {
8364
- $descriptionArray[$features['name']] = $features['value'];
8365
- }
8366
-
8367
-
8368
- $this->productDescriptionList = $descriptionArray;
8369
- }
8370
- #################################################################################################
8371
-
8372
- private function loadRelatedProducts($entity_id){
8373
- $this->sinchProductId;
8374
- if(!$this->sinchProductId){
8375
- return;
8376
- }
8377
- $q="SELECT
8378
- st_prod.sinch_product_id,
8379
- st_prod.product_sku,
8380
- st_prod.product_name,
8381
- st_prod.sinch_manufacturer_id,
8382
- st_prod.store_category_id,
8383
- st_prod.main_image_url,
8384
- st_prod.thumb_image_url,
8385
- st_prod.medium_image_url,
8386
- st_prod.specifications,
8387
- st_prod.description,
8388
- st_prod.specifications,
8389
- st_manuf.manufacturer_name,
8390
- st_manuf.manufacturers_image
8391
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." st_rel_prod
8392
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." st_prod
8393
- ON st_rel_prod.related_sinch_product_id=st_prod.sinch_product_id
8394
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." st_manuf
8395
- ON st_prod.sinch_manufacturer_id=st_manuf.sinch_manufacturer_id
8396
- WHERE st_rel_prod.sinch_product_id=".$this->sinchProductId;
8397
-
8398
- // echo $q;
8399
- $quer=$this->db_do($q);
8400
- while($row=mysqli_fetch_array($quer)){
8401
-
8402
- $productArray = array();
8403
- $productArray['name'] = (string)$row['product_name'];
8404
- $productArray['thumb'] = (string)$row['thumb_image_url'];
8405
- $mpn = (string)$row['product_sku'];
8406
- $productSupplierId = (int)$row['sinch_manufacturer_id'];
8407
- $productArray['supplier_thumb'] = (string)($row['manufacturers_image']);
8408
- $productArray['supplier_name'] = (string)$row['manufacturer_name'];
8409
-
8410
- $this->relatedProducts[$mpn] = $productArray;
8411
- }
8412
- }
8413
- #################################################################################################
8414
- /**
8415
- * load Gallery array from XML
8416
- */
8417
- public function loadGalleryPhotos($entity_id){
8418
- /*$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
8419
- if (!count($galleryPhotos)){
8420
- return false;
8421
- }
8422
- */
8423
- $store_product_id=$this->getStoreProductIdByEntity($entity_id);
8424
- if(!$store_product_id){
8425
- return;
8426
- }
8427
- $q=$this->db_do("SELECT COUNT(*) AS cnt
8428
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
8429
- WHERE store_product_id=".$store_product_id);
8430
-
8431
- $res=mysqli_fetch_array($q);
8432
- if(!$res || !$res['cnt']){
8433
- return false;
8434
- }
8435
- $q="SELECT
8436
- image_url as Pic,
8437
- thumb_image_url as ThumbPic
8438
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
8439
- WHERE store_product_id=".$store_product_id;
8440
-
8441
- $res=$this->db_do($q);
8442
-
8443
- while($photo=mysqli_fetch_array($res)){
8444
- $picHeight = (int)500;//$photo["PicHeight"];
8445
- $picWidth = (int)500;//$photo["PicWidth"];
8446
- $thumbUrl = (string)$photo["ThumbPic"];
8447
- $picUrl = (string)$photo["Pic"];
8448
-
8449
- array_push($this->galleryPhotos, array(
8450
- 'height' => $picHeight,
8451
- 'width' => $picWidth,
8452
- 'thumb' => $thumbUrl,
8453
- 'pic' => $picUrl
8454
- ));
8455
- }
8456
- }
8457
- #################################################################################################
8458
- public function reloadProductImage($entity_id){
8459
- $result = $this->db_do("
8460
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8461
- entity_type_id,
8462
- attribute_id,
8463
- store_id,
8464
- entity_id,
8465
- value
8466
- )(
8467
- SELECT
8468
- " . $this->_getProductEntityTypeId(). ",
8469
- " . $this->_getProductAttributeId('image'). ",
8470
- w.store_id,
8471
- a.entity_id,
8472
- b.main_image_url
8473
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8474
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8475
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8476
- ON a.store_product_id = b.store_product_id
8477
- WHERE a.entity_id=$entity_id
8478
- )
8479
- ON DUPLICATE KEY UPDATE
8480
- value = b.main_image_url
8481
- ");
8482
-
8483
-
8484
- // image for specific web sites
8485
- $result = $this->db_do("
8486
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8487
- entity_type_id,
8488
- attribute_id,
8489
- store_id,
8490
- entity_id,
8491
- value
8492
- )(
8493
- SELECT
8494
- " . $this->_getProductEntityTypeId(). ",
8495
- " . $this->_getProductAttributeId('image'). ",
8496
- 0,
8497
- a.entity_id,
8498
- b.main_image_url
8499
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8500
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8501
- ON a.store_product_id = b.store_product_id
8502
- WHERE a.entity_id=$entity_id
8503
- )
8504
- ON DUPLICATE KEY UPDATE
8505
- value = b.main_image_url
8506
- ");
8507
-
8508
-
8509
- // small_image for specific web sites
8510
- $result = $this->db_do("
8511
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8512
- entity_type_id,
8513
- attribute_id,
8514
- store_id,
8515
- entity_id,
8516
- value
8517
- )(
8518
- SELECT
8519
- " . $this->_getProductEntityTypeId(). ",
8520
- " . $this->_getProductAttributeId('small_image'). ",
8521
- w.store_id,
8522
- a.entity_id,
8523
- b.main_image_url
8524
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8525
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8526
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8527
- ON a.store_product_id = b.store_product_id
8528
- WHERE a.entity_id=$entity_id
8529
- )
8530
- ON DUPLICATE KEY UPDATE
8531
- value = b.main_image_url
8532
- ");
8533
-
8534
-
8535
- // small_image for all web sites
8536
- $result = $this->db_do("
8537
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8538
- entity_type_id,
8539
- attribute_id,
8540
- store_id,
8541
- entity_id,
8542
- value
8543
- )(
8544
- SELECT
8545
- " . $this->_getProductEntityTypeId(). ",
8546
- " . $this->_getProductAttributeId('small_image'). ",
8547
- 0,
8548
- a.entity_id,
8549
- b.main_image_url
8550
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8551
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8552
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8553
- ON a.store_product_id = b.store_product_id
8554
- WHERE a.entity_id=$entity_id
8555
- )
8556
- ON DUPLICATE KEY UPDATE
8557
- value = b.main_image_url
8558
- ");
8559
- }
8560
- #################################################################################################
8561
- public function runIndexer(){
8562
- $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'));
8563
- $this->db_do ("SET FOREIGN_KEY_CHECKS=0");
8564
- $this->db_do("TRUNCATE TABLE ".Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'));
8565
- $this->db_do ("SET FOREIGN_KEY_CHECKS=1");
8566
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8567
- SET value = ''
8568
- WHERE entity_type_id=".$this->_getProductEntityTypeId()." AND attribute_id=".$this->_getProductAttributeId('url_key'));
8569
- exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php reindexall');
8570
- }
8571
- #################################################################################################
8572
- public function runStockPriceIndexer(){
8573
- exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php --reindex catalog_product_price,cataloginventory_stock');
8574
- }
8575
- #################################################################################################
8576
- private function getStoreProductIdByEntity($entity_id){
8577
- $q=$this->db_do("SELECT store_product_id
8578
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
8579
- WHERE entity_id=".$entity_id);
8580
- $res=mysqli_fetch_array($q);
8581
- // echo $entity_id."AAAA".$res['store_product_id']; exit;
8582
- return ($res['store_product_id']);
8583
- }
8584
- #################################################################################################
8585
-
8586
- private function db_connect() {
8587
- // $connection = Mage::getModel('core/resource')->getConnection('core_write');
8588
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
8589
- $dbConn = mysqli_init();
8590
- mysqli_options($dbConn, MYSQLI_OPT_LOCAL_INFILE, true);
8591
- if (mysqli_real_connect($dbConn, $dbConf->host, $dbConf->username, $dbConf->password)) {
8592
- $this->db = $dbConn;
8593
- if(!mysqli_select_db($this->db, $dbConf->dbname)){
8594
- die("Can't select the database: " . mysqli_error($this->db));
8595
- }
8596
- }else{
8597
- die("Could not connect: " . mysqli_error($this->db));
8598
- }
8599
-
8600
- }
8601
- #################################################################################################
8602
-
8603
- private function db_do($query) {
8604
- if($this->debug_mode){
8605
- Mage::log("Query: " . $query, null, $this->_logFile);
8606
- }
8607
- $result = mysqli_query($this->db, $query) or die("Query failed: " . mysqli_error($this->db));
8608
- if (!$result) {
8609
- throw new Exception("Invalid query: $sql\n" . mysqli_error($this->db));
8610
- } else {
8611
- return $result;
8612
- }
8613
- return $result;
8614
- }
8615
- ##################################################################################################
8616
- function table_rows_count($table){
8617
- $rows_count_res=$this->db_do("select count(*) as cnt from ".$table);
8618
- $rows_count=mysqli_fetch_array($rows_count_res);
8619
- return ($rows_count['cnt']);
8620
- }
8621
- ##################################################################################################
8622
- function file_strings_count($parse_file){
8623
- $files_str=count(file($parse_file));
8624
- return $files_str;
8625
- }
8626
- ##################################################################################################
8627
- function check_loaded_data($file, $table){
8628
- $cnt_strings_in_file=$this->file_strings_count($file);
8629
- $cnt_rows_int_table=$this->table_rows_count($table);
8630
- $persent_cnt_strings_in_file=$cnt_strings_in_file / 10;
8631
- if($cnt_rows_int_table > $persent_cnt_strings_in_file){
8632
- return true;
8633
- }else{
8634
- return false;
8635
- }
8636
- }
8637
- ##################################################################################################
8638
-
8639
-
8640
- function valid_utf($string,$new_line = true){
8641
- /* if($new_line == true){
8642
- $string = preg_replace('/\\\n/',"\n",$string);
8643
- }
8644
- */
8645
- $string = preg_replace('/™/','&#8482;',$string);
8646
- $string = preg_replace("/®/",'&reg;',$string);
8647
- $string = preg_replace("/≈/",'&asymp;',$string);
8648
- $string = preg_replace("/".chr(226).chr(128).chr(157)."/",'&quot;',$string);
8649
- $string = preg_replace("/".chr(226).chr(128).chr(153)."/",'&prime;',$string);
8650
- $string = preg_replace("/°/",'&deg;',$string);
8651
- $string = preg_replace("/±/",'&plusmn;',$string);
8652
- $string = preg_replace("/µ/",'&micro;',$string);
8653
- $string = preg_replace("/²/",'&sup2;',$string);
8654
- $string = preg_replace("/³/",'&sup3;',$string);
8655
- $string = preg_replace('/\xe2\x80\x93/','-',$string);
8656
- $string = preg_replace('/\xe2\x80\x99/','\'',$string);
8657
- $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
8658
- $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
8659
-
8660
- return utf8_decode($string);
8661
-
8662
- // return $string;
8663
- }
8664
-
8665
- #################################################################################################
8666
- function dropHTMLentities($entity_type_id, $attribute_id){
8667
- // product name for all web sites
8668
- $result = $this->db_do("
8669
- SELECT value, entity_id
8670
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8671
- WHERE entity_type_id=".$entity_type_id."
8672
- AND attribute_id=".$attribute_id
8673
- );
8674
- while($row=mysqli_fetch_array($result)){
8675
- $value=$this->valid_char($row['value']);
8676
- if($value!='' and $value!=$row['value']){
8677
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8678
- SET value='".mysqli_real_escape_string($this->db, $value)."'
8679
- WHERE entity_id=".$row['entity_id']."
8680
- AND entity_type_id=".$entity_type_id."
8681
- AND attribute_id=".$attribute_id);
8682
- }
8683
-
8684
- }
8685
- }
8686
-
8687
- #################################################################################################
8688
-
8689
- function valid_char($string){
8690
- $string = preg_replace('/&#8482;/', ' ',$string);
8691
- $string = preg_replace('/&reg;/', ' ',$string);
8692
- $string = preg_replace('/&asymp;/', ' ',$string);
8693
- $string = preg_replace('/&quot;/', ' ',$string);
8694
- $string = preg_replace('/&prime;/', ' ',$string);
8695
- $string = preg_replace('/&deg;/', ' ',$string);
8696
- $string = preg_replace('/&plusmn;/', ' ',$string);
8697
- $string = preg_replace('/&micro;/', ' ',$string);
8698
- $string = preg_replace('/&sup2;/', ' ',$string);
8699
- $string = preg_replace('/&sup3;/', ' ',$string);
8700
- // $string = preg_replace('/\xe2\x80\x93/','-',$string);
8701
- // $string = preg_replace('/\xe2\x80\x99/','\'',$string);
8702
- // $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
8703
- // $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
8704
-
8705
- // return utf8_decode($string);
8706
-
8707
- return $string;
8708
- }
8709
-
8710
- #################################################################################################
8711
-
8712
- function _LOG($log){
8713
-
8714
- if($log){
8715
- // $q="insert into ".$this->import_log_table." (message_date, message) values(now(), '".$log."')";
8716
- // $this->db_do($q);
8717
- Mage::log($log, null, $this->_logFile);
8718
- // list($usec, $sec) = explode(" ", microtime());
8719
- // $time = ((float)$usec + (float)$sec);
8720
- /* $time = date("D M j G:i:s T Y");
8721
-
8722
- if($_SERVER['REMOTE_ADDR']){
8723
- $log = "[".getmypid()."] "."[".$_SERVER['REMOTE_ADDR']."] "."[".$time."] ".$log."\n";
8724
- error_log($log,3,LOG_FILE);
8725
- }else{
8726
- $log = "[".getmypid()."] "."[".$time."] ".$log."\n";
8727
- error_log($log,3,LOG_FILE . ".cli");
8728
- */
8729
- }
8730
- }
8731
-
8732
- #################################################################################################
8733
-
8734
- function wget(){
8735
-
8736
- $got = func_num_args();
8737
- $url = $file = $flag = false;
8738
-
8739
- if($got<1){
8740
- return false;
8741
- }elseif($got == 1){
8742
- $url = func_get_arg(0);
8743
- }elseif($got == 2){
8744
- $url = func_get_arg(0);
8745
- $file= func_get_arg(1);
8746
- }elseif($got == 3){
8747
- $url = func_get_arg(0);
8748
- $file= func_get_arg(1);
8749
- $flag= func_get_arg(2);
8750
- }
8751
-
8752
- if($flag == 'copy'){
8753
- if(copy($url,$file)){
8754
- return true;
8755
- }else{
8756
- return false;
8757
- }
8758
- }elseif($flag == 'system'){
8759
- exec("wget -O$file $url");
8760
- return true;
8761
- }else{
8762
- $c=curl_init($url);
8763
- curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
8764
- curl_setopt($c,CURLOPT_FOLLOWLOCATION,1);
8765
- curl_setopt($c,CURLOPT_HEADER,array("Accept-Encoding: gzip"));
8766
- if(!$file){
8767
- $page = curl_exec($c);
8768
- curl_close($c);
8769
- return $page;
8770
- }else{
8771
- $FH = fopen($file,"wb");// or echo"Can't open for writing ".$file;
8772
- fwrite($FH,curl_exec($c));
8773
- fclose($FH);
8774
- curl_close($c);
8775
- return true;
8776
- }
8777
- }
8778
- }
8779
- #################################################################################################
8780
- /**
8781
- * Create the import directory Hierarchy
8782
- * @return false if directory already exists
8783
- */
8784
- public function createTemporaryImportDerictory(){
8785
- $dirArray = explode('/', $this->varDir);
8786
- end($dirArray);
8787
- // $this->_LOG('before :'.$this->varDir);
8788
- if (prev($dirArray)=='bintime'){
8789
- return false;
8790
- }
8791
-
8792
-
8793
- $this->varDir = $this->varDir . 'bintime/sinchimport/';
8794
- if (!is_dir($this->varDir)) {
8795
- mkdir($this->varDir,0777,true);
8796
- }
8797
- // $this->_LOG('after :'.$this->varDir);
8798
- }
8799
- #################################################################################################
8800
-
8801
- function count_children($id){
8802
-
8803
- $q="SELECT store_category_id
8804
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8805
- WHERE parent_store_category_id=".$id;
8806
- $quer=$this->db_do($q);
8807
- $count=0;
8808
- while ($row=mysqli_fetch_array($quer)){
8809
- $count+=$this->count_children($row['store_category_id']);
8810
- $count++;
8811
- }
8812
- return ($count);
8813
- }
8814
- #################################################################################################
8815
- private function delete_old_sinch_categories_from_shop(){
8816
-
8817
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." cat
8818
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8819
- ON cat.entity_id=scm.shop_entity_id
8820
- WHERE
8821
- (scm.shop_store_category_id is not null) AND
8822
- (scm.store_category_id is null)";
8823
- $this->db_do($q);
8824
-
8825
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." cat
8826
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8827
- ON cat.entity_id=scm.shop_entity_id
8828
- WHERE
8829
- (scm.shop_store_category_id is not null) AND
8830
- (scm.store_category_id is null)";
8831
- $this->db_do($q);
8832
-
8833
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cat
8834
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8835
- ON cat.entity_id=scm.shop_entity_id
8836
- WHERE
8837
- (scm.shop_store_category_id is not null) AND
8838
- (scm.store_category_id is null)";
8839
- $this->db_do($q);
8840
-
8841
- }
8842
- #################################################################################################
8843
-
8844
- function culc_path($parent_id, $ent_id){
8845
-
8846
- //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]\n");
8847
-
8848
- $path='';
8849
- $cat_id=$parent_id;
8850
- $q="SELECT
8851
- parent_id
8852
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
8853
- WHERE entity_id=".$cat_id;
8854
- $quer=$this->db_do($q);
8855
- $row=mysqli_fetch_array($quer);
8856
- while($row['parent_id']){
8857
- $path=$row['parent_id'].'/'.$path;
8858
- $q="SELECT
8859
- parent_id
8860
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
8861
- WHERE entity_id=".$row['parent_id'];
8862
- $quer=$this->db_do($q);
8863
- $row=mysqli_fetch_array($quer);
8864
-
8865
- }
8866
- if($cat_id){
8867
- $path.=$cat_id."/";
8868
- }
8869
-
8870
- if($path){
8871
- return($path.$ent_id);
8872
- }else{
8873
- return($ent_id);
8874
- }
8875
-
8876
- }
8877
- #################################################################################################
8878
-
8879
- function get_category_level($id){
8880
- $q="SELECT parent_store_category_id
8881
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8882
- WHERE store_category_id=".$id;
8883
- $quer=$this->db_do($q);
8884
- $level=1;
8885
- $row=mysqli_fetch_array($quer);
8886
- while ($row['parent_store_category_id']!=0){
8887
- $q="SELECT parent_store_category_id
8888
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8889
- WHERE store_category_id=".$row['parent_store_category_id'];
8890
- $quer=$this->db_do($q);
8891
- $row=mysqli_fetch_array($quer);
8892
- $level++;
8893
- if($level>20){
8894
- break;
8895
- }
8896
- }
8897
-
8898
- return($level);
8899
- }
8900
- #################################################################################################
8901
-
8902
- function InitImportStatuses($type){
8903
- $this->db_do("DROP TABLE IF EXISTS ".$this->import_status_table);
8904
- $this->db_do("CREATE TABLE ".$this->import_status_table."(
8905
- id int(11) NOT NULL auto_increment PRIMARY KEY,
8906
- message varchar(50),
8907
- finished int(1) default 0
8908
- )"
8909
- );
8910
- $this->db_do("INSERT INTO ".$this->import_status_statistic_table." (
8911
- start_import,
8912
- finish_import,
8913
- import_type,
8914
- global_status_import,
8915
- import_run_type,
8916
- error_report_message)
8917
- VALUES(
8918
- now(),
8919
- NULL,
8920
- '$type',
8921
- 'Run',
8922
- '".$this->import_run_type."',
8923
- ''
8924
- )
8925
- ");
8926
- $q="SELECT MAX(id) AS id FROM ".$this->import_status_statistic_table;
8927
-
8928
- $quer=$this->db_do($q);
8929
- $row=mysqli_fetch_array($quer);
8930
- $this->current_import_status_statistic_id=$row['id'];
8931
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
8932
- SET global_status_import='Failed'
8933
- WHERE global_status_import='Run' AND id!=".$this->current_import_status_statistic_id);
8934
-
8935
- }
8936
- #################################################################################################
8937
- function set_imports_failed(){
8938
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
8939
- SET global_status_import='Failed'
8940
- WHERE global_status_import='Run'");
8941
- }
8942
- #################################################################################################
8943
- function set_import_error_reporting_message($message){
8944
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
8945
- SET error_report_message='".mysqli_real_escape_string($this->db, $message)."'
8946
- WHERE id=".$this->current_import_status_statistic_id);
8947
- }
8948
- #################################################################################################
8949
- function getImportStatusHistory(){
8950
- $res="SELECT COUNT(*) FROM ".$this->import_status_statistic_table;
8951
- $cnt_arr=mysqli_fetch_array($this->db_do($res));
8952
- $cnt=$cnt_arr[0];
8953
- $StatusHistory_arr = array();
8954
- if($cnt>0){
8955
- $a=(($cnt>7)? ($cnt-7): 0);
8956
- $b=$cnt;
8957
- $q="SELECT
8958
- id,
8959
- start_import,
8960
- finish_import,
8961
- import_type,
8962
- number_of_products,
8963
- global_status_import,
8964
- detail_status_import
8965
- FROM ".$this->import_status_statistic_table."
8966
- ORDER BY start_import limit ".$a.", ".$b;
8967
- $result=$this->db_do($q);
8968
- while($row=mysqli_fetch_array($result)){
8969
- $StatusHistory_arr[]=$row;
8970
- }
8971
- }
8972
- return $StatusHistory_arr;
8973
- }
8974
- #################################################################################################
8975
- function getDateOfLatestSuccessImport(){
8976
- $q="SELECT start_import, finish_import
8977
- FROM ".$this->import_status_statistic_table."
8978
- WHERE global_status_import='Successful'
8979
- ORDER BY id DESC LIMIT 1";
8980
- $imp_date=mysqli_fetch_array($this->db_do($q));
8981
- return $imp_date['start_import'];
8982
- }
8983
- #################################################################################################
8984
- function getDataOfLatestImport(){
8985
- $q="SELECT
8986
- start_import,
8987
- finish_import,
8988
- import_type,
8989
- number_of_products,
8990
- global_status_import,
8991
- detail_status_import,
8992
- number_of_products,
8993
- error_report_message
8994
- FROM ".$this->import_status_statistic_table."
8995
- ORDER BY id DESC LIMIT 1";
8996
- $imp_status=mysqli_fetch_array($this->db_do($q));
8997
- return $imp_status;
8998
- }
8999
-
9000
- #################################################################################################
9001
- function addImportStatus($message, $finished=0){
9002
- $q="INSERT INTO ".$this->import_status_table."
9003
- (message, finished)
9004
- VALUES('".$message."', $finished)";
9005
- $this->db_do($q);
9006
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
9007
- SET detail_status_import='".$message."'
9008
- WHERE id=".$this->current_import_status_statistic_id);
9009
- if($finished==1){
9010
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
9011
- SET
9012
- global_status_import='Successful',
9013
- finish_import=now()
9014
- WHERE
9015
- error_report_message='' and
9016
- id=".$this->current_import_status_statistic_id);
9017
- }
9018
- }
9019
- #################################################################################################
9020
-
9021
- function getImportStatuses(){
9022
- $q="SELECT id, message, finished
9023
- FROM ".$this->import_status_table."
9024
- ORDER BY id LIMIT 1";
9025
- $quer=$this->db_do($q);
9026
- if($row=mysqli_fetch_array($quer)){
9027
- $messages=array('message'=>$row['message'], 'id'=>$row['id'], 'finished'=>$row['finished']);
9028
- $id=$row['id'];
9029
- }
9030
- if($id){
9031
- $q="DELETE FROM ".$this->import_status_table." WHERE id=".$id;
9032
- $this->db_do($q);
9033
- }
9034
- return $messages;
9035
- }
9036
- #################################################################################################
9037
-
9038
- private function _getEntityTypeId($code) {
9039
- $sql = "
9040
- SELECT entity_type_id
9041
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9042
- WHERE entity_type_code = '".$code."'
9043
- LIMIT 1
9044
- ";
9045
- $result = $this->db_do($sql);
9046
- if ($row = mysqli_fetch_assoc($result)) {
9047
- return $row['entity_type_id'];
9048
- }
9049
- return false;
9050
- }
9051
- #################################################################################################
9052
-
9053
- private function _getProductEntityTypeId(){
9054
- if (!$this->_productEntityTypeId) {
9055
- $this->_productEntityTypeId = $this->_getEntityTypeId('catalog_product');
9056
- }
9057
- return $this->_productEntityTypeId;
9058
- }
9059
- #################################################################################
9060
-
9061
- private function _getProductDefaulAttributeSetId(){
9062
- if (!$this->defaultAttributeSetId) {
9063
- $sql = "
9064
- SELECT entity_type_id, default_attribute_set_id
9065
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9066
- WHERE entity_type_code = 'catalog_product'
9067
- LIMIT 1
9068
- ";
9069
- $result = $this->db_do($sql);
9070
- if ($row = mysqli_fetch_assoc($result)) {
9071
-
9072
- $this->defaultAttributeSetId = $row['default_attribute_set_id'];
9073
- }
9074
- }
9075
- return $this->defaultAttributeSetId;
9076
- }
9077
- #################################################################################################
9078
-
9079
- private function _getCategoryEntityTypeIdAndDefault_attribute_set_id(){
9080
- if (!$this->_categoryEntityTypeId || !$this->_categoryDefault_attribute_set_id) {
9081
- $sql = "
9082
- SELECT entity_type_id, default_attribute_set_id
9083
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9084
- WHERE entity_type_code = 'catalog_category'
9085
- LIMIT 1
9086
- ";
9087
- $result = $this->db_do($sql);
9088
- if ($row = mysqli_fetch_assoc($result)) {
9089
- $this->_categoryEntityTypeId = $row['entity_type_id'];
9090
- $this->_categoryDefault_attribute_set_id = $row['default_attribute_set_id'];
9091
- }
9092
-
9093
- }
9094
- }
9095
- ##################################################################################################
9096
-
9097
- private function _getAttributeId($attributeCode,$typeCode)
9098
- {
9099
- if ($typeCode=='catalog_product') {
9100
- $typeId = $this->_getProductEntityTypeId();
9101
- }
9102
- else {
9103
- $typeId = $this->_getEntityTypeId($typeCode);
9104
- }
9105
- if (!isset($this->_attributeId[$typeCode]) OR !is_array($this->_attributeId[$typeCode])) {
9106
- $sql = "
9107
- SELECT attribute_id, attribute_code
9108
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute')."
9109
- WHERE entity_type_id = '" . $typeId . "'
9110
- ";
9111
- $result = $this->db_do($sql);
9112
- while ($row = mysqli_fetch_assoc($result)) {
9113
- $this->_attributeId[$typeCode][$row['attribute_code']] = $row['attribute_id'];
9114
- }
9115
- }
9116
- // echo 'attribute code: '.$attributeCode.','.$typeCode.' => '.$this->_attributeId[$typeCode][$attributeCode].PHP_EOL;
9117
- return $this->_attributeId[$typeCode][$attributeCode];
9118
- }
9119
- ##################################################################################################
9120
-
9121
- private function repl_ph($content,$hash){
9122
- if($hash){
9123
- foreach($hash as $key => $val){
9124
- if ($key=="category_name") {
9125
- if (strlen($val)>25) { $val = substr($val,0,24)."..."; }
9126
- }
9127
- $content = preg_replace("/%%%$key%%%/",$val,$content);
9128
- }
9129
- }
9130
- return $content;
9131
- }
9132
- ##################################################################################################
9133
-
9134
- private function _getProductAttributeId($attributeCode) {
9135
- return $this->_getAttributeId($attributeCode,'catalog_product');
9136
- }
9137
- ##################################################################################################
9138
-
9139
- private function _getCategoryAttributeId($attributeCode) {
9140
- return $this->_getAttributeId($attributeCode,'catalog_category');
9141
- }
9142
- ##################################################################################################
9143
- private function _getShopRootCategoryId($cat_id=0){
9144
- if($root_cat = Mage::app()->getStore()->getRootCategoryId()){
9145
- return $root_cat;
9146
- }else{
9147
- $q="SELECT
9148
- entity_id
9149
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')."
9150
- WHERE
9151
- value='default-category'";
9152
- $res=$this->db_do($q);
9153
- $row=mysqli_fetch_array($res);
9154
- if($row['entity_id']>0){
9155
- return $row['entity_id'];
9156
- }else{
9157
- $q="SELECT entity_id
9158
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
9159
- WHERE parent_id=".$cat_id;
9160
- $quer=$this->db_do($q);
9161
- $count=0;
9162
- while ($row=mysqli_fetch_array($quer)){
9163
- $count++;
9164
- $entity_id=$row['entity_id'];
9165
- }
9166
- if($count>1 || $count==0){
9167
- return ($cat_id);
9168
- }else{
9169
- return $this->_getShopRootCategoryId($entity_id);
9170
- }
9171
- }
9172
- }
9173
- }
9174
- ##################################################################################################
9175
- private function _cleanCateoryProductFlatTable(){
9176
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
9177
- $q='SHOW TABLES LIKE "'.Mage::getSingleton('core/resource')->getTableName('catalog_product_flat_').'%"';
9178
- $quer=$this->db_do($q);
9179
- $result=false;
9180
- While($row=mysqli_fetch_array($quer)){
9181
- if(is_array($row)){
9182
- $catalog_product_flat=array_pop($row);
9183
- $q='DELETE pf1 FROM '.$catalog_product_flat.' pf1
9184
- LEFT JOIN '.Mage::getSingleton('core/resource')->getTableName('catalog_product_entity').' p
9185
- ON pf1.entity_id = p.entity_id
9186
- WHERE p.entity_id IS NULL;';
9187
- $this->db_do($q);
9188
- $this->_LOG('cleaned wrong rows from '.$catalog_product_flat);
9189
- }
9190
- }
9191
- return $result;
9192
-
9193
- }
9194
- ##################################################################################################
9195
-
9196
-
9197
-
9198
-
9199
-
9200
- ##################################################################################################
9201
- public function checkMemory() {
9202
- $check_code = 'memory';
9203
-
9204
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9205
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9206
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9207
- $row = $result->fetch(PDO::FETCH_ASSOC);
9208
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9209
-
9210
-
9211
- $Caption = $row['caption'];
9212
- $CheckValue = $row['check_value'];
9213
- $CheckMeasure = $row['check_measure'];
9214
- $ErrorMessage = $row['error_msg'];
9215
- $FixMessage = $row['fix_msg'];
9216
-
9217
- $retvalue = array();
9218
- $retvalue["'$check_code'"] = array();
9219
-
9220
- $data = explode("\n", file_get_contents("/proc/meminfo"));
9221
-
9222
- $meminfo = array();
9223
- foreach ($data as $line) {
9224
- list($key, $val) = explode(":", $line);
9225
- $meminfo[$key] = trim($val);
9226
-
9227
- if ($key == 'MemTotal') {
9228
- $val = trim($val);
9229
- $value = (int)substr($val, 0, strpos($val, ' kB'));
9230
- $measure = substr($val, strpos($val, ' kB'));
9231
-
9232
- $retvalue['memory']['value'] = (integer)(((float)$value)/1024); // (float)$value
9233
- $retvalue['memory']['measure'] = 'MB'; // $measure;
9234
- }
9235
- }
9236
-
9237
- $errmsg = '';
9238
- $fixmsg = '';
9239
- if ($retvalue['memory']['value'] <= $CheckValue) {
9240
- $errmsg .= sprintf($ErrorMessage, $retvalue['memory']['value']); //." ".$retvalue['memory']['value']." ".$retvalue['memory']['measure'];
9241
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
9242
- $retvalue['memory']['status'] = 'error';
9243
- } else {
9244
- $errmsg .= 'none';
9245
- $fixmsg .= 'none';
9246
- $retvalue['memory']['status'] = 'OK';
9247
- }
9248
-
9249
- $ret = array();
9250
- array_push($ret, $retvalue['memory']['status'], $Caption, $CheckValue, $retvalue['memory']['value'], $CheckMeasure, $errmsg, $fixmsg);
9251
-
9252
- return $ret;
9253
- } // public function getImportEnvironment()
9254
- ##################################################################################################
9255
-
9256
-
9257
-
9258
-
9259
- ##################################################################################################
9260
- public function checkLoaddata() {
9261
- $check_code = 'loaddata';
9262
-
9263
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9264
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9265
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9266
- $row = $result->fetch(PDO::FETCH_ASSOC);
9267
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9268
-
9269
- $Caption = $row['caption'];
9270
- $CheckValue = $row['check_value'];
9271
- $CheckMeasure = $row['check_measure'];
9272
- $ErrorMessage = $row['error_msg'];
9273
- $FixMessage = $row['fix_msg'];
9274
-
9275
- $retvalue = array();
9276
- $retvalue["'$check_code'"] = array();
9277
-
9278
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9279
- $result = $conn->query("SHOW VARIABLES LIKE 'local_infile'");
9280
- $row = $result->fetch(PDO::FETCH_ASSOC);
9281
- $value = $row['Value'];
9282
-
9283
-
9284
- $errmsg = '';
9285
- $fixmsg = '';
9286
- if ($value != $CheckValue) {
9287
- $errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
9288
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9289
- $status = 'error';
9290
- } else {
9291
- $errmsg .= 'none';
9292
- $fixmsg .= 'none';
9293
- $status = 'OK';
9294
- }
9295
-
9296
- $ret = array();
9297
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9298
-
9299
- return $ret;
9300
- } // public function getImportEnvironment()
9301
- ##################################################################################################
9302
-
9303
-
9304
-
9305
-
9306
- ##################################################################################################
9307
- public function checkPhpsafemode() {
9308
- $check_code = 'phpsafemode';
9309
-
9310
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9311
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9312
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9313
- $row = $result->fetch(PDO::FETCH_ASSOC);
9314
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9315
-
9316
- $Caption = $row['caption'];
9317
- $CheckValue = $row['check_value'];
9318
- $CheckMeasure = $row['check_measure'];
9319
- $ErrorMessage = $row['error_msg'];
9320
- $FixMessage = $row['fix_msg'];
9321
-
9322
- $retvalue = array();
9323
- $retvalue["'$check_code'"] = array();
9324
-
9325
- $a = ini_get('safe_mode');
9326
- if ($a) {
9327
- $value = 'ON';
9328
- } else {
9329
- $value = 'OFF';
9330
- }
9331
-
9332
- $errmsg = '';
9333
- $fixmsg = '';
9334
- if ($value != $CheckValue) {
9335
- $errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
9336
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
9337
- $status = 'error';
9338
- } else {
9339
- $errmsg .= 'none';
9340
- $fixmsg .= 'none';
9341
- $status = 'OK';
9342
- }
9343
-
9344
- $ret = array();
9345
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9346
-
9347
- return $ret;
9348
- } // public function getImportEnvironment()
9349
- ##################################################################################################
9350
-
9351
-
9352
-
9353
-
9354
- ##################################################################################################
9355
- public function checkWaittimeout() {
9356
- $check_code = 'waittimeout';
9357
-
9358
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9359
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9360
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9361
- $row = $result->fetch(PDO::FETCH_ASSOC);
9362
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9363
-
9364
- $Caption = $row['caption'];
9365
- $CheckValue = $row['check_value'];
9366
- $CheckMeasure = $row['check_measure'];
9367
- $ErrorMessage = $row['error_msg'];
9368
- $FixMessage = $row['fix_msg'];
9369
-
9370
- $retvalue = array();
9371
- $retvalue["'$check_code'"] = array();
9372
-
9373
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9374
- $result = $conn->query("SHOW VARIABLES LIKE 'wait_timeout'");
9375
- $row = $result->fetch(PDO::FETCH_ASSOC);
9376
- $value = $row['Value'];
9377
-
9378
- $errmsg = '';
9379
- $fixmsg = '';
9380
- if ($value <= $CheckValue) {
9381
- $errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
9382
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue);
9383
- $status = 'error';
9384
- } else {
9385
- $errmsg .= 'none';
9386
- $fixmsg .= 'none';
9387
- $status = 'OK';
9388
- }
9389
-
9390
- $ret = array();
9391
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9392
-
9393
- return $ret;
9394
- } // public function getImportEnvironment()
9395
- ##################################################################################################
9396
-
9397
-
9398
-
9399
-
9400
- ##################################################################################################
9401
- public function checkInnodbbufferpoolsize() {
9402
- $check_code = 'innodbbufpool';
9403
-
9404
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9405
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9406
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9407
- $row = $result->fetch(PDO::FETCH_ASSOC);
9408
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9409
-
9410
- $Caption = $row['caption'];
9411
- $CheckValue = $row['check_value'];
9412
- $CheckMeasure = $row['check_measure'];
9413
- $ErrorMessage = $row['error_msg'];
9414
- $FixMessage = $row['fix_msg'];
9415
-
9416
- $retvalue = array();
9417
- $retvalue["'$check_code'"] = array();
9418
-
9419
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9420
- $result = $conn->query("SHOW VARIABLES LIKE 'innodb_buffer_pool_size'");
9421
- $row = $result->fetch(PDO::FETCH_ASSOC);
9422
- $value = (int)($row['Value']/(1024*1024));
9423
-
9424
- $errmsg = '';
9425
- $fixmsg = '';
9426
- if ($value < $CheckValue) {
9427
- $errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
9428
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
9429
- $status = 'error';
9430
- } else {
9431
- $errmsg .= 'none';
9432
- $fixmsg .= 'none';
9433
- $status = 'OK';
9434
- }
9435
-
9436
- $ret = array();
9437
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9438
-
9439
- return $ret;
9440
- } // public function getImportEnvironment()
9441
- ##################################################################################################
9442
-
9443
-
9444
-
9445
-
9446
- ##################################################################################################
9447
- public function checkPhprunstring() {
9448
- $check_code = 'php5run';
9449
-
9450
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9451
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9452
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9453
- $row = $result->fetch(PDO::FETCH_ASSOC);
9454
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9455
-
9456
- $Caption = $row['caption'];
9457
- $CheckValue = $row['check_value'];
9458
- $CheckMeasure = $row['check_measure'];
9459
- $ErrorMessage = $row['error_msg'];
9460
- $FixMessage = $row['fix_msg'];
9461
-
9462
- $retvalue = array();
9463
- $retvalue["'$check_code'"] = array();
9464
-
9465
- $value = trim(PHP_RUN_STRING);
9466
- $errmsg = '';
9467
- $fixmsg = '';
9468
- if( !defined('PHP_RUN_STRING')){
9469
- $errmsg .= "You haven't installed PHP CLI";
9470
- $fixmsg .= "Install PHP CLI."; // ." ".$CheckValue." ".$CheckMeasure
9471
- $status = 'error';
9472
- }
9473
-
9474
- $ret = array();
9475
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9476
-
9477
- return $ret;
9478
- } // public function getImportEnvironment()
9479
- ##################################################################################################
9480
-
9481
-
9482
-
9483
-
9484
- ##################################################################################################
9485
- public function checkChmodwgetdatafile() {
9486
- $check_code = 'chmodwget';
9487
-
9488
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9489
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9490
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9491
- $row = $result->fetch(PDO::FETCH_ASSOC);
9492
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9493
-
9494
- $Caption = $row['caption'];
9495
- $CheckValue = $row['check_value'];
9496
- $CheckMeasure = $row['check_measure'];
9497
- $ErrorMessage = $row['error_msg'];
9498
- $FixMessage = $row['fix_msg'];
9499
-
9500
- $retvalue = array();
9501
- $retvalue["'$check_code'"] = array();
9502
-
9503
- $datafile_csv = '/usr/bin/wget';
9504
-
9505
- $value = substr(sprintf('%o', fileperms($datafile_csv)), -4);
9506
-
9507
- $CheckValue_own = $CheckValue{1};
9508
- $CheckValue_group = $CheckValue{2};
9509
- $CheckValue_other = $CheckValue{3};
9510
-
9511
- $value_own = $value{1};
9512
- $value_group = $value{2};
9513
- $value_other = $value{3};
9514
-
9515
- $errmsg = '';
9516
- $fixmsg = '';
9517
- //if ($value <= $CheckValue) {
9518
- if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9519
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9520
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9521
- $status = 'error';
9522
- } else {
9523
- $errmsg .= 'none';
9524
- $fixmsg .= 'none';
9525
- $status = 'OK';
9526
- }
9527
-
9528
- $ret = array();
9529
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9530
-
9531
- return $ret;
9532
- } // public function getImportEnvironment()
9533
- ##################################################################################################
9534
-
9535
-
9536
-
9537
-
9538
- ##################################################################################################
9539
- public function checkChmodwgetcronphpfile() {
9540
- $check_code = 'chmodcronphp';
9541
-
9542
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9543
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9544
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9545
- $row = $result->fetch(PDO::FETCH_ASSOC);
9546
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9547
-
9548
- $Caption = $row['caption'];
9549
- $CheckValue = $row['check_value'];
9550
- $CheckMeasure = $row['check_measure'];
9551
- $ErrorMessage = $row['error_msg'];
9552
- $FixMessage = $row['fix_msg'];
9553
-
9554
- $retvalue = array();
9555
- $retvalue["'$check_code'"] = array();
9556
-
9557
- $cronfile_php = Mage::getBaseDir().'/cron.php';
9558
-
9559
- $value = substr(sprintf('%o', fileperms($cronfile_php)), -4);
9560
-
9561
- $CheckValue_own = $CheckValue{1};
9562
- $CheckValue_group = $CheckValue{2};
9563
- $CheckValue_other = $CheckValue{3};
9564
-
9565
- $value_own = $value{1};
9566
- $value_group = $value{2};
9567
- $value_other = $value{3};
9568
-
9569
- $errmsg = '';
9570
- $fixmsg = '';
9571
- //if ($value <= $CheckValue) {
9572
- if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9573
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9574
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9575
- $status = 'error';
9576
- } else {
9577
- $errmsg .= 'none';
9578
- $fixmsg .= 'none';
9579
- $status = 'OK';
9580
- }
9581
-
9582
- $ret = array();
9583
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9584
-
9585
- return $ret;
9586
- } // public function checkChmodwgetcronphpfile()
9587
- ##################################################################################################
9588
-
9589
-
9590
-
9591
-
9592
- ##################################################################################################
9593
- public function checkChmodwgetcronshfile() {
9594
- $check_code = 'chmodcronsh';
9595
-
9596
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9597
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9598
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9599
- $row = $result->fetch(PDO::FETCH_ASSOC);
9600
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9601
-
9602
- $Caption = $row['caption'];
9603
- $CheckValue = $row['check_value'];
9604
- $CheckMeasure = $row['check_measure'];
9605
- $ErrorMessage = $row['error_msg'];
9606
- $FixMessage = $row['fix_msg'];
9607
-
9608
- $retvalue = array();
9609
- $retvalue["'$check_code'"] = array();
9610
-
9611
- $cronfile_sh = Mage::getBaseDir().'/cron.sh';
9612
-
9613
- $value = substr(sprintf('%o', fileperms($cronfile_sh)), -4);
9614
-
9615
- $CheckValue_own = $CheckValue{1};
9616
- $CheckValue_group = $CheckValue{2};
9617
- $CheckValue_other = $CheckValue{3};
9618
-
9619
- $value_own = $value{1};
9620
- $value_group = $value{2};
9621
- $value_other = $value{3};
9622
-
9623
- $errmsg = '';
9624
- $fixmsg = '';
9625
- //if ($value <= $CheckValue) {
9626
- if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9627
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9628
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9629
- $status = 'error';
9630
- } else {
9631
- $errmsg .= 'none';
9632
- $fixmsg .= 'none';
9633
- $status = 'OK';
9634
- }
9635
-
9636
- $ret = array();
9637
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9638
-
9639
- return $ret;
9640
- } // public function checkChmodwgetcronphpfile()
9641
- ##################################################################################################
9642
-
9643
-
9644
-
9645
-
9646
- ##################################################################################################
9647
- public function checkProcedure() {
9648
- $check_code = 'routine';
9649
-
9650
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9651
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9652
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9653
- $row = $result->fetch(PDO::FETCH_ASSOC);
9654
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9655
-
9656
- $Caption = $row['caption'];
9657
- $CheckValue = $row['check_value'];
9658
- $CheckMeasure = $row['check_measure'];
9659
- $ErrorMessage = $row['error_msg'];
9660
- $FixMessage = $row['fix_msg'];
9661
-
9662
- $retvalue = array();
9663
- $retvalue["'$check_code'"] = array();
9664
-
9665
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9666
- $storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
9667
- $result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
9668
- $row = $result->fetch(PDO::FETCH_ASSOC);
9669
- $value = $row['Name'];
9670
-
9671
- $errmsg = '';
9672
- $fixmsg = '';
9673
- if ($value != $CheckValue) {
9674
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9675
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9676
- $status = 'error';
9677
- } else {
9678
- $errmsg .= 'none';
9679
- $fixmsg .= 'none';
9680
- $status = 'OK';
9681
- }
9682
-
9683
- $ret = array();
9684
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9685
-
9686
- return $ret;
9687
- } // public function getImportEnvironment()
9688
- ##################################################################################################
9689
-
9690
-
9691
-
9692
-
9693
- ##################################################################################################
9694
- public function checkConflictsWithInstalledModules() {
9695
- $check_code = 'conflictwithinstalledmodules';
9696
-
9697
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9698
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9699
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9700
- $row = $result->fetch(PDO::FETCH_ASSOC);
9701
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9702
-
9703
- $Caption = $row['caption'];
9704
- $CheckValue = $row['check_value'];
9705
- $CheckMeasure = $row['check_measure'];
9706
- $ErrorMessage = $row['error_msg'];
9707
- $FixMessage = $row['fix_msg'];
9708
-
9709
- $retvalue = array();
9710
- $retvalue["'$check_code'"] = array();
9711
-
9712
- /* $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9713
- $storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
9714
- $result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
9715
- $row = $result->fetch(PDO::FETCH_ASSOC);
9716
- $value = $row['Name'];
9717
- */
9718
- $config_file = (Mage::app()->getConfig()->getNode()->asXML());
9719
-
9720
- $errmsg = $ErrorMessage;
9721
- $fixmsg = $FixMessage;
9722
- /*
9723
- if ($value != $CheckValue) {
9724
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9725
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9726
- $status = 'error';
9727
- */
9728
- $status = 'OK';
9729
-
9730
- if (!strstr($config_file, '<image>Bintime_Sinchimport_Helper_Image</image>')) {
9731
- $errmsg .= " Can't find <image>Bintime_Sinchimport_Helper_Image</image> in <helpers><catalog></catalog></helpers>"; // ." ".$value." ".$CheckMeasure
9732
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9733
- $status = 'error';
9734
- }
9735
-
9736
- if (!strstr($config_file, '<product_image>Bintime_Sinchimport_Model_Image</product_image>')) {
9737
- $errmsg .= " Can't find <product_image>Bintime_Sinchimport_Model_Image</product_image> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
9738
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9739
- $status = 'error';
9740
- }
9741
-
9742
- if (!strstr($config_file, '<category>Bintime_Sinchimport_Model_Category</category>')) {
9743
- $errmsg .= " Can't find <category>Bintime_Sinchimport_Model_Category</category> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
9744
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9745
- $status = 'error';
9746
- }
9747
-
9748
- if (!strstr($config_file, '<product_compare_list>Bintime_Sinchimport_Block_List</product_compare_list>')) {
9749
- $errmsg .= " Can't find <product_compare_list>Bintime_Sinchimport_Block_List</product_compare_list> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
9750
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9751
- $status = 'error';
9752
- }
9753
-
9754
- if (!strstr($config_file, '<product_view_media>Bintime_Sinchimport_Block_Product_View_Media</product_view_media>')) {
9755
- $errmsg .= " Can't find <product_view_media>Bintime_Sinchimport_Block_Product_View_Media</product_view_media> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
9756
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9757
- $status = 'error';
9758
- }
9759
-
9760
- if (!strstr($config_file, '<product>Bintime_Sinchimport_Model_Product</product>')) {
9761
- $errmsg .= " Can't find <product>Bintime_Sinchimport_Model_Product</product> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
9762
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9763
- $status = 'error';
9764
- }
9765
-
9766
- if (!strstr($config_file, '<layer_filter_price>Bintime_Sinchimport_Model_Layer_Filter_Price</layer_filter_price>')) {
9767
- $errmsg .= " Can't find <layer_filter_price>Bintime_Sinchimport_Model_Layer_Filter_Price</layer_filter_price> in <models><catalog></catalog><models>"; // ." ".$value." ".$CheckMeasure
9768
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9769
- $status = 'error';
9770
- }
9771
-
9772
- if (!strstr($config_file, '<layer_view>Bintime_Sinchimport_Block_Layer_View</layer_view>')) {
9773
- $errmsg .= " Can't find <layer_view>Bintime_Sinchimport_Block_Layer_View</layer_view> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
9774
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9775
- $status = 'error';
9776
- }
9777
-
9778
- if (!strstr($config_file, '<layer>Bintime_Sinchimport_Model_Layer</layer>')) {
9779
- $errmsg .= " Can't find <layer>Bintime_Sinchimport_Model_Layer</layer> in <models><catalog></catalog><models>"; // ." ".$value." ".$CheckMeasure
9780
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9781
- $status = 'error';
9782
- }
9783
-
9784
- if (!strstr($config_file, '<layer_filter_price>Bintime_Sinchimport_Model_Resource_Layer_Filter_Price</layer_filter_price>')) {
9785
- $errmsg .= " Can't find <layer_filter_price>Bintime_Sinchimport_Model_Resource_Layer_Filter_Price</layer_filter_price> in <models><catalog_resource_eav_mysql4></catalog_resource_eav_mysql4></models>"; // ." ".$value." ".$CheckMeasure
9786
- $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9787
- $status = 'error';
9788
- }
9789
-
9790
-
9791
- if ($status == 'OK'){
9792
- $errmsg = 'none';
9793
- $fixmsg = 'none';
9794
- }
9795
- $ret = array();
9796
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9797
-
9798
- return $ret;
9799
- } // public function getImportEnvironment()
9800
- ##################################################################################################
9801
-
9802
-
9803
-
9804
- ##################################################################################################
9805
- public function getSinchDistribotorsTableHtml($entity_id=null) {
9806
- /*/ Load the collection
9807
- $collection = getResourceModel('sales/order_grid_collection');
9808
-
9809
- // Add custom data
9810
- $collection->addToAll('example', 'This is a test');
9811
-
9812
- // Set the collection
9813
- $this->setCollection($collection);
9814
- // return parent::_prepareCollection();
9815
- */
9816
- if(!$entity_id){
9817
- $entity_id = Mage::registry('current_product')->getId();
9818
- }
9819
- if (!$entity_id){
9820
- return '';
9821
- }
9822
-
9823
- $distributors_stock_price = $this->getDistributorStockPriceByProductid($entity_id);
9824
- $distributors_table = '
9825
- <table>
9826
- <thead>
9827
- <tr class="headings">
9828
- <th>Supplier</th>
9829
- <th>Stock</th>
9830
- <th>Price</th>
9831
- </tr>
9832
- </thead>
9833
- <tbody>';
9834
- $i = 1;
9835
- foreach($distributors_stock_price as $offer){
9836
- if ($i > 0){
9837
- $class = "even pointer";
9838
- $i = 0;
9839
- }else{
9840
- $class = "pointer";
9841
- $i = 1;
9842
- }
9843
- $distributors_table .= '
9844
- <tr class="'.$class.'">
9845
- <td nowrap style="font-weight: normal">'.$offer['distributor_name'].'</td>
9846
- <td style="font-weight: normal">'.$offer['stock'].'</td>
9847
- <td style="font-weight: normal">'.Mage::helper('core')->currency($offer['cost']).'</td>
9848
- </tr>';
9849
- }
9850
- $distributors_table .= '
9851
- </tbody>
9852
- </table>
9853
- ';
9854
- return $distributors_table;
9855
- }
9856
- ##################################################################################################
9857
-
9858
-
9859
-
9860
-
9861
- ##################################################################################################
9862
- private function getDistributorStockPriceByProductid($entity_id) {
9863
- $store_product_id=$this->getStoreProductIdByEntity($entity_id);
9864
- if(!$store_product_id){
9865
- // echo "AAAAAAA"; exit;
9866
- return;
9867
- }
9868
- $q="SELECT
9869
- d.distributor_name,
9870
- d.website,
9871
- dsp.stock,
9872
- dsp.cost,
9873
- dsp.distributor_sku,
9874
- dsp.distributor_category,
9875
- dsp.eta
9876
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price')." dsp
9877
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors')." d
9878
- ON dsp.distributor_id = d.distributor_id
9879
- WHERE store_product_id =".$store_product_id;
9880
- $quer=$this->db_do($q);
9881
- $offers = null;
9882
- while($row = mysqli_fetch_array($quer)){
9883
- $offers[]=$row;
9884
- }
9885
- return $offers;
9886
-
9887
- }
9888
- #################################################################################################
9889
-
9890
- private function get_all_children_cat($entity_id){
9891
- $children_cat = "'" . $entity_id . "'" . $this->get_all_children_cat_recursive($entity_id);
9892
- return ($children_cat);
9893
- }
9894
- #################################################################################################
9895
-
9896
- private function get_all_children_cat_recursive($entity_id) {
9897
- $q="SELECT entity_id
9898
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
9899
- WHERE parent_id=".$entity_id;
9900
- $quer=$this->db_do($q);
9901
- $children_cat='';
9902
- while ($row=mysqli_fetch_array($quer)){
9903
- $children_cat .= ", '".$row['entity_id']."'";
9904
- $children_cat .= $this->get_all_children_cat_recursive($row['entity_id']);
9905
- }
9906
- return ($children_cat);
9907
- }
9908
- #################################################################################################
9909
-
9910
- private function check_table_exist($table){
9911
-
9912
- $q="SHOW TABLES LIKE \"%".Mage::getSingleton('core/resource')->getTableName($table)."%\"";
9913
- // echo $q;
9914
- $quer=$this->db_do($q);
9915
- $i=0;
9916
- while ($row=mysqli_fetch_array($quer)){
9917
- $i++;
9918
- }
9919
- return ($i);
9920
- }
9921
- #################################################################################################
9922
-
9923
- private function _set_default_root_category(){
9924
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('core_store_group')." csg
9925
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
9926
- ON csg.root_category_id = cce.entity_id
9927
- SET csg.root_category_id=(SELECT entity_id FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." WHERE parent_id = 1 LIMIT 1)
9928
- WHERE csg.root_category_id > 0 AND cce.entity_id IS NULL";
9929
- $this->db_do($q);
9930
- }
9931
-
9932
- } // class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract
9933
-
9934
- ?>
9935
-
9936
-
9937
-
9938
-
9939
-
1
+ <?php
2
+
3
+ ini_set('memory_limit','256M');
4
+ $dir = Mage::getBaseDir('code')."/local/Bintime/Sinchimport/Model";//dirname(__FILE__);
5
+ require_once ($dir.'/config.php');
6
+
7
+ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
8
+ var
9
+ $connection,
10
+ $varDir,
11
+ $shellDir,
12
+ $files,
13
+ $attributes,
14
+ $db,
15
+ $lang_id,
16
+ $debug_mode=1;
17
+ private $productDescriptionList = array();
18
+ private $specifications;
19
+ private $productDescription;
20
+ private $fullProductDescription;
21
+ private $lowPicUrl;
22
+ private $highPicUrl;
23
+ private $errorMessage;
24
+ private $galleryPhotos = array();
25
+ private $productName;
26
+ private $relatedProducts = array();
27
+ private $errorSystemMessage; //depricated
28
+ private $sinchProductId;
29
+ private $_productEntityTypeId = 0;
30
+ private $defaultAttributeSetId = 0;
31
+ private $field_terminated_char;
32
+ private $import_status_table;
33
+ private $import_status_statistic_table;
34
+ private $current_import_status_statistic_id;
35
+ private $import_log_table;
36
+ private $_attributeId;
37
+ private $_categoryEntityTypeId;
38
+ private $_categoryDefault_attribute_set_id;
39
+ private $_root_cat;
40
+ private $import_run_type = 'MANUAL';
41
+ private $_ignore_category_features = false;
42
+ private $_ignore_product_features = false;
43
+ private $_ignore_product_related = false;
44
+ private $_ignore_product_categories = false;
45
+ private $_ignore_price_rules = false;
46
+ private $product_file_format = "NEW";
47
+ private $_ignore_restricted_values = false;
48
+ private $_categoryMetaTitleAttrId;
49
+ private $_categoryMetadescriptionAttrId;
50
+ private $_categoryDescriptionAttrId;
51
+
52
+
53
+ public $php_run_string;
54
+ public $php_run_strings;
55
+
56
+ public $price_breaks_filter;
57
+
58
+ private $im_type;
59
+
60
+ #################################################################################################
61
+
62
+ function __construct(){
63
+
64
+ $this->import_status_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status');
65
+ $this->import_status_statistic_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic');
66
+ $this->import_log_table="stINch_import_log";
67
+
68
+ $this->php_run_string=PHP_RUN_STRING;
69
+ $this->php_run_strings=PHP_RUN_STRINGS;
70
+
71
+ $this->price_breaks_filter=PRICE_BREAKS;
72
+ /*$this->db_connect();
73
+ $res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
74
+ $row = mysqli_fetch_assoc($res);
75
+ $this->lang_id = $row['languages_id'];
76
+ */
77
+ $this->varDir = TEMPORARY_DIRECTORY_FOR_STORING_FILES;
78
+ $this->shellDir = SHELL_DIRECTORY_FOR_INDEXER;
79
+ $this->connection=$this->db_connect();
80
+ $this->createTemporaryImportDerictory();
81
+ $this->_logFile="Sinch.log";
82
+ $this->_LOG("constructor");
83
+ $this->files=array(
84
+ FILE_CATEGORIES,
85
+ FILE_CATEGORY_TYPES,
86
+ FILE_CATEGORIES_FEATURES,
87
+ FILE_DISTRIBUTORS,
88
+ FILE_DISTRIBUTORS_STOCK_AND_PRICES,
89
+ FILE_EANCODES,
90
+ FILE_MANUFACTURERS,
91
+ FILE_PRODUCT_FEATURES,
92
+ FILE_PRODUCT_CATEGORIES,
93
+ FILE_PRODUCTS,
94
+ FILE_RELATED_PRODUCTS,
95
+ FILE_RESTRICTED_VALUES,
96
+ FILE_STOCK_AND_PRICES,
97
+ FILE_PRODUCTS_PICTURES_GALLERY,
98
+ FILE_PRICE_RULES
99
+ );
100
+ $this->attributes['manufacturer']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
101
+ $this->attributes['name']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
102
+ $this->attributes['is_active']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('is_active')->getFirstItem()->getId();
103
+ $this->attributes['include_in_menu']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('include_in_menu')->getFirstItem()->getId();
104
+ $this->attributes['url_key']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('url_key')->getFirstItem()->getId();
105
+ $this->attributes['display_mode']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('display_mode')->getFirstItem()->getId();
106
+ $this->attributes['status']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('status')->getFirstItem()->getId();
107
+ $this->attributes['visibility']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('visibility')->getFirstItem()->getId();
108
+ $this->attributes['price']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('price')->getFirstItem()->getId();
109
+ $this->attributes['cost']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('cost')->getFirstItem()->getId();
110
+ $this->attributes['weight']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('weight')->getFirstItem()->getId();
111
+ $this->attributes['tax_class_id']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('tax_class_id')->getFirstItem()->getId();
112
+
113
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
114
+ // if($dataConf['field_terminated_char']){
115
+ // $this->field_terminated_char=$dataConf['field_terminated_char'];
116
+ // }else{
117
+ $this->field_terminated_char=DEFAULT_FILE_TERMINATED_CHAR;
118
+ // }
119
+ // $attributeOptions = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getSource()->getAllOptions(false);
120
+ // echo "<pre>"; print_r($attributeOptions); echo "</pre>";
121
+ }
122
+
123
+ #################################################################################################
124
+ function cron_start_import(){
125
+ $this->_LOG("Start import from cron");
126
+ $start_hr=Mage::getStoreConfig('sinchimport_root/sinch_cron/sinch_cron_time');
127
+ $now_hr=date('H');
128
+ $this->_LOG("Now $now_hr hr, scheduler time is $start_hr hr");
129
+
130
+ if($start_hr==$now_hr){
131
+ $this->run_sinch_import();
132
+ }else{
133
+ $this->_LOG(" it's NOT time for SINCH ");
134
+ }
135
+
136
+ $this->_LOG("Finish import from cron");
137
+
138
+ }
139
+ ################################################################################################
140
+ function cron_start_full_import(){
141
+ $this->import_run_type='CRON';
142
+ $this->run_sinch_import();
143
+ }
144
+ ################################################################################################
145
+ function cron_start_stock_price_import(){
146
+ $this->import_run_type='CRON';
147
+ $this->run_stock_price_sinch_import();
148
+ }
149
+ #################################################################################################
150
+ function is_imort_not_run(){
151
+ $q="SELECT IS_FREE_LOCK('sinchimport') as getlock";
152
+ $quer=$this->db_do($q);
153
+ $row=mysqli_fetch_array($quer);
154
+ return $row['getlock'];
155
+ }
156
+ #################################################################################################
157
+ function check_store_procedure_exist(){
158
+ $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
159
+ $q='SHOW PROCEDURE STATUS LIKE "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'"';
160
+ $quer=$this->db_do($q);
161
+ $result=false;
162
+ While($row=mysqli_fetch_array($quer)){
163
+ if(($row['Name']==Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s')) && ($row['Db']==$dbConf->dbname)){
164
+ $result = true;
165
+ }
166
+ }
167
+ return $result;
168
+ }
169
+ #################################################################################################
170
+ function check_db_privileges(){
171
+ $q='SHOW PRIVILEGES';
172
+ $quer=$this->db_do($q);
173
+ while($row=mysqli_fetch_array($quer)){
174
+ if($row['Privilege']=='File' && $row['Context']=='File access on server'){
175
+ return true;
176
+ }
177
+ }
178
+ return false;
179
+ }
180
+ #################################################################################################
181
+ function check_local_infile(){
182
+ $q='SHOW VARIABLES LIKE "local_infile"';
183
+ $quer=$this->db_do($q);
184
+ $row=mysqli_fetch_array($quer);
185
+ if($row['Variable_name']=='local_infile' && $row['Value']=="ON"){
186
+ return true;
187
+ }else{
188
+ return false;
189
+ }
190
+ }
191
+ #################################################################################################
192
+ function is_full_import_have_been_run(){
193
+ $q="SELECT COUNT(*) AS cnt
194
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic')."
195
+ WHERE import_type='FULL' AND global_status_import='Successful'";
196
+ $quer=$this->db_do($q);
197
+ $row=mysqli_fetch_array($quer);
198
+ if($row['cnt']>0){
199
+ return true;
200
+ }else{
201
+ return false;
202
+ }
203
+ }
204
+ #################################################################################################
205
+ function run_sinch_import(){
206
+
207
+ $this->_categoryMetaTitleAttrId = $this->_getCategoryAttributeId('meta_title');
208
+ $this->_categoryMetadescriptionAttrId = $this->_getCategoryAttributeId('meta_description');
209
+ $this->_categoryDescriptionAttrId = $this->_getCategoryAttributeId('description');
210
+
211
+ $safe_mode_set = ini_get('safe_mode');
212
+
213
+ $this->InitImportStatuses('FULL');
214
+ if($safe_mode_set ){
215
+ $this->_LOG('safe_mode is enable. import stoped.');
216
+ $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
217
+ exit;
218
+ }
219
+ $store_proc=$this->check_store_procedure_exist();
220
+
221
+ if(!$store_proc){
222
+ $this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
223
+ $this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
224
+ exit;
225
+ }
226
+
227
+ $file_privileg=$this->check_db_privileges();
228
+
229
+ if(!$file_privileg){
230
+ $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
231
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
232
+ exit;
233
+ }
234
+ $local_infile=$this->check_local_infile();
235
+ if(!$local_infile){
236
+ $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. Add this string to 'set-variable=local-infile=0' in '/etc/my.cnf'");
237
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
238
+ exit;
239
+ }
240
+ //STP TEST
241
+ //$this->ApplyCustomerGroupPrice();
242
+ //echo $children_cat=$this->get_all_children_cat(6);
243
+
244
+
245
+
246
+ if($this->is_imort_not_run()){
247
+ try{
248
+ //$this->InitImportStatuses();
249
+ $q="SELECT GET_LOCK('sinchimport', 30)";
250
+ $quer=$this->db_do($q);
251
+ $import=$this;
252
+ $import->addImportStatus('Start Import');
253
+ echo "Upload Files <br>";
254
+ $import->UploadFiles();
255
+ $import->addImportStatus('Upload Files');
256
+
257
+ echo "Parse Category Types <br>";
258
+ $import->ParseCategoryTypes();
259
+
260
+ echo "Parse Categories <br>";
261
+ $coincidence = $import->ParseCategories();
262
+ $import->addImportStatus('Parse Categories');
263
+
264
+
265
+ //$import->_cleanCateoryProductFlatTable();
266
+ //$import->runIndexer();
267
+ //echo("\n\n\n==================RETURN=================\n\n\n");
268
+
269
+
270
+ echo "Parse Category Features <br>";
271
+ $import->ParseCategoryFeatures();
272
+ $import->addImportStatus('Parse Category Features');
273
+
274
+
275
+ echo "Parse Distributors <br>";
276
+ $import->ParseDistributors();
277
+ if($this->product_file_format == "NEW"){
278
+ $this->ParseDistributorsStockAndPrice();
279
+ }
280
+ $import->addImportStatus('Parse Distributors');
281
+
282
+ echo "Parse EAN Codes <br>";
283
+ $import->ParseEANCodes();
284
+ $import->addImportStatus('Parse EAN Codes');
285
+
286
+
287
+ echo "Parse Manufacturers <br>";
288
+ $import->ParseManufacturers();
289
+ $import->addImportStatus('Parse Manufacturers');
290
+
291
+ echo "Parse Related Products <br>";
292
+ $import->ParseRelatedProducts();
293
+ $import->addImportStatus('Parse Related Products');
294
+
295
+
296
+
297
+ echo "Parse Product Features <br>";
298
+ $import->ParseProductFeatures();
299
+ $import->addImportStatus('Parse Product Features');
300
+
301
+ echo "Parse Product Categories <br>";
302
+ $import->ParseProductCategories();
303
+
304
+ echo "Parse Products <br>";
305
+ $import->ParseProducts($coincidence);
306
+ $import->addImportStatus('Parse Products');
307
+
308
+ //echo("\n\n\n\n ##################################### \n\n\n\n"); return;
309
+ //
310
+
311
+ echo "Parse Pictures Gallery";
312
+ $import->ParseProductsPicturesGallery();
313
+ $import->addImportStatus('Parse Pictures Gallery');
314
+
315
+
316
+ echo "Parse Restricted Values <br>";
317
+ $import->ParseRestrictedValues();
318
+ $import->addImportStatus('Parse Restricted Values');
319
+
320
+ echo "Parse Stock And Prices <br>";
321
+ $import->ParseStockAndPrices();
322
+ $import->addImportStatus('Parse Stock And Prices');
323
+
324
+ echo "Apply Customer Group Price <br>";
325
+ //$import->ParsePriceRules();
326
+ //$import->AddPriceRules();
327
+ //$import->ApplyCustomerGroupPrice();
328
+
329
+ if(file_exists($this->varDir.FILE_PRICE_RULES)){
330
+ $ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
331
+ Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
332
+ 'ftp_host' => $ftpCred["ftp_server"],
333
+ 'ftp_username' => $ftpCred["login"],
334
+ 'ftp_password' => $ftpCred["password"]
335
+ ));
336
+ }
337
+
338
+
339
+ Mage::log("Finish Sinch import", null, $this->_logFile);
340
+ echo "Finish Sinch import<br>";
341
+
342
+ Mage::log("Start cleanin Sinch cache<br>", null, $this->_logFile);
343
+ echo "Start cleanin Sinch cache<br>";
344
+ Mage::app()->getCacheInstance()->cleanType('block_html');
345
+ /*
346
+ $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
347
+ if ($indexProcess) {
348
+ $indexProcess->reindexAll();
349
+ }
350
+ */
351
+
352
+ Mage::log("Start indexing Sinch features for filters", null, $this->_logFile);
353
+ echo "Start indexing Sinch features for filters<br>";
354
+
355
+
356
+ $resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
357
+ $resource->splitProductsFeature(null);
358
+
359
+ Mage::log("Finish indexing Sinch features for filters", null, $this->_logFile);
360
+ $import->addImportStatus('Generate category filters');
361
+ echo "Finish indexing Sinch features for filters<br>";
362
+
363
+
364
+ Mage::log("Start indexing data", null, $this->_logFile);
365
+ echo "Start indexing data";
366
+ $import->_cleanCateoryProductFlatTable();
367
+ $import->runIndexer();
368
+ Mage::log("Finish indexing data", null, $this->_logFile);
369
+ $import->addImportStatus('Indexing data', 1);
370
+ echo "Finish indexing data";
371
+
372
+ $q="SELECT RELEASE_LOCK('sinchimport')";
373
+ $quer=$this->db_do($q);
374
+ }catch (Exception $e) {
375
+ $this->set_import_error_reporting_message($e);
376
+ }
377
+ }
378
+ else{
379
+ Mage::log("Sinchimport already run", null, $this->_logFile);
380
+ echo "Sinchimport already run<br>";
381
+
382
+ }
383
+
384
+ }
385
+ #################################################################################################
386
+ function run_stock_price_sinch_import(){
387
+ $safe_mode_set = ini_get('safe_mode');
388
+
389
+ $this->InitImportStatuses('PRICE STOCK');
390
+ if($safe_mode_set ){
391
+ $this->_LOG('safe_mode is enable. import stoped.');
392
+ $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
393
+ exit;
394
+ }
395
+ $store_proc=$this->check_store_procedure_exist();
396
+
397
+ if(!$store_proc){
398
+ $this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
399
+ $this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
400
+ exit;
401
+ }
402
+
403
+ $file_privileg=$this->check_db_privileges();
404
+
405
+ if(!$file_privileg){
406
+ $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
407
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
408
+ exit;
409
+ }
410
+ $local_infile=$this->check_local_infile();
411
+ if(!$local_infile){
412
+ $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. Add this string to 'set-variable=local-infile=0' in '/etc/my.cnf'");
413
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
414
+ exit;
415
+ }
416
+
417
+ if($this->is_imort_not_run() && $this->is_full_import_have_been_run()){
418
+ try{
419
+ //$this->InitImportStatuses();
420
+ $q="SELECT GET_LOCK('sinchimport', 30)";
421
+ $quer=$this->db_do($q);
422
+ $import=$this;
423
+ $import->addImportStatus('Stock Price Start Import');
424
+ echo "Upload Files <br>";
425
+ $this->files=array(
426
+ FILE_STOCK_AND_PRICES,
427
+ FILE_PRICE_RULES
428
+ );
429
+
430
+ $import->UploadFiles();
431
+ $import->addImportStatus('Stock Price Upload Files');
432
+
433
+ echo "Parse Stock And Prices <br>";
434
+ //exit;
435
+ $import->ParseStockAndPrices();
436
+ $import->addImportStatus('Stock Price Parse Products');
437
+
438
+ echo "Apply Customer Group Price <br>";
439
+ //$import->ParsePriceRules();
440
+ //$import->AddPriceRules();
441
+ //$import->ApplyCustomerGroupPrice();
442
+
443
+ $ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
444
+ Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
445
+ 'ftp_host' => $ftpCred["ftp_server"],
446
+ 'ftp_username' => $ftpCred["login"],
447
+ 'ftp_password' => $ftpCred["password"]
448
+ ));
449
+
450
+
451
+ Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
452
+ echo "Finish Stock & Price Sinch import<br>";
453
+
454
+ Mage::log("Start indexing Stock & Price", null, $this->_logFile);
455
+ echo "Start indexing Stock & Price<br>";
456
+ $import->_cleanCateoryProductFlatTable();
457
+ $import->runStockPriceIndexer();
458
+ Mage::log("Finish indexing Stock & Price", null, $this->_logFile);
459
+ $import->addImportStatus('Stock Price Indexing data');
460
+ $import->addImportStatus('Stock Price Finish import', 1);
461
+ echo "Finish indexing Stock & Price<br>";
462
+
463
+ $q="SELECT RELEASE_LOCK('sinchimport')";
464
+ $quer=$this->db_do($q);
465
+ }catch (Exception $e) {
466
+ $this->set_import_error_reporting_message($e);
467
+ }
468
+ }
469
+ else{
470
+ if(!$this->is_imort_not_run()){
471
+ Mage::log("Sinchimport already run", null, $this->_logFile);
472
+ echo "Sinchimport already run<br>";
473
+ }else{
474
+ Mage::log("Full import have never finished with success", null, $this->_logFile);
475
+ echo "Full import have never finished with success<br>";
476
+ }
477
+ }
478
+
479
+ }
480
+ #################################################################################################
481
+
482
+
483
+ function UploadFiles(){
484
+
485
+ $this->_LOG("Start upload files");
486
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
487
+ $login=$dataConf['login'];
488
+ $passw=$dataConf['password'];
489
+ $server=$dataConf['ftp_server'];
490
+
491
+ //return;//stepan tes//stepan tes//stepan testtt
492
+ if(!$login || !$passw){
493
+ $this->_LOG('ftp login or password dosent defined');
494
+ $this->set_import_error_reporting_message('FTP login or password has not been defined. Import stopped.');
495
+ exit;
496
+
497
+ }
498
+ $file_url_and_dir=$this->repl_ph(FILE_URL_AND_DIR, array(
499
+ 'server' => $server,
500
+ 'login' => $login,
501
+ 'password'=> $passw
502
+ )
503
+ );
504
+ foreach ($this->files as $file) {
505
+ $this->_LOG("Copy ".$file_url_and_dir.$file." to ".$this->varDir.$file);
506
+ if(strstr($file_url_and_dir, 'ftp://')){
507
+ preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
508
+ //var_dump($match);
509
+ if($conn = ftp_connect($match[3])){
510
+ if(!ftp_login($conn, $login, $passw))
511
+ {
512
+ $this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
513
+ exit;
514
+ }
515
+ }
516
+ else{
517
+ $this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
518
+ exit;
519
+ }
520
+ if (!$this->wget ($file_url_and_dir.$file, $this->varDir.$file, 'system')){
521
+ $this->_LOG("wget Can't copy ".$file.", will use old one");
522
+ echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file.", will use old one<br>";
523
+ }
524
+ }
525
+ else{
526
+ if(!copy($file_url_and_dir.$file, $this->varDir.$file)){
527
+ $this->_LOG("copy Can't copy ".$file.", will use old one");
528
+ echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file." will use old one<br>";
529
+ }
530
+ }
531
+ exec("chmod a+rw ".$this->varDir.$file);
532
+ if(!filesize($this->varDir.$file)){
533
+ if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES && $file!=FILE_PRODUCT_CATEGORIES && $file !=FILE_CATEGORY_TYPES && $file != FILE_DISTRIBUTORS_STOCK_AND_PRICES && $file != FILE_PRICE_RULES){
534
+ $this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
535
+ $this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
536
+ $this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
537
+
538
+ exit;
539
+ }else{
540
+ if($file==FILE_CATEGORIES_FEATURES){
541
+ $this->_LOG("Can't copy ".FILE_CATEGORIES_FEATURES." file ignored" );
542
+ $this->_ignore_category_features=true;
543
+ }elseif($file==FILE_PRODUCT_FEATURES){
544
+ $this->_LOG("Can't copy ".FILE_PRODUCT_FEATURES." file ignored" );
545
+ $this->_ignore_product_features=true;
546
+ }elseif($file==FILE_RELATED_PRODUCTS){
547
+ $this->_LOG("Can't copy ".FILE_RELATED_PRODUCTS." file ignored" );
548
+ $this->_ignore_product_related=true;
549
+ }elseif($file==FILE_RESTRICTED_VALUES){
550
+ $this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
551
+ $this->_ignore_restricted_values=true;
552
+ }elseif($file==FILE_PRODUCT_CATEGORIES){
553
+ $this->_LOG("Can't copy ".FILE_PRODUCT_CATEGORIES." file ignored" );
554
+ $this->_ignore_product_categories=true;
555
+ $this->product_file_format = "OLD";
556
+ }elseif($file==FILE_CATEGORY_TYPES){
557
+ $this->_LOG("Can't copy ".FILE_CATEGORY_TYPES." file ignored" );
558
+ $this->_ignore_category_types=true;
559
+ }elseif($file==FILE_DISTRIBUTORS_STOCK_AND_PRICES){
560
+ $this->_LOG("Can't copy ".FILE_DISTRIBUTORS_STOCK_AND_PRICES." file ignored" );
561
+ $this->_ignore_category_types=true;
562
+ }elseif($file==FILE_PRICE_RULES){
563
+ $this->_LOG("Can't copy ".FILE_PRICE_RULES." file ignored" );
564
+ $this->_ignore_price_rules=true;
565
+ }
566
+
567
+ }
568
+ }
569
+ }
570
+ if (file_exists($file_url_and_dir.FILE_PRODUCT_CATEGORIES)){
571
+ $this->product_file_format = "NEW";
572
+ $this->_LOG("File ".$file_url_and_dir.FILE_PRODUCT_CATEGORIES." exist. Will used parser for NEW format product.csv" );
573
+ }else{
574
+ $this->product_file_format = "OLD";
575
+ $this->_LOG("File ".$file_url_and_dir.FILE_PRODUCT_CATEGORIES." dosen't exist. Will used parser for OLD format product.csv" );
576
+ }
577
+ $this->_LOG("Finish upload files");
578
+ }
579
+ #################################################################################################
580
+
581
+
582
+
583
+ ################################################################################################################################################################
584
+ function ParseCategories()
585
+ {
586
+
587
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
588
+ $im_type = $dataConf['replace_category'];
589
+ $parse_file = $this->varDir.FILE_CATEGORIES;
590
+ $field_terminated_char = $this->field_terminated_char;
591
+
592
+ $this->im_type = $im_type;
593
+
594
+ if(filesize($parse_file))
595
+ {
596
+ $this->_LOG("Start parse ".FILE_CATEGORIES);
597
+
598
+ $this->_getCategoryEntityTypeIdAndDefault_attribute_set_id();
599
+
600
+ $categories_temp = Mage::getSingleton('core/resource')->getTableName('categories_temp');
601
+ $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
602
+ $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
603
+ $catalog_category_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int');
604
+ $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
605
+ $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
606
+ $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
607
+ $category_types = Mage::getSingleton('core/resource')->getTableName('stINch_category_types');
608
+
609
+ $_categoryEntityTypeId = $this->_categoryEntityTypeId;
610
+ $_categoryDefault_attribute_set_id = $this->_categoryDefault_attribute_set_id;
611
+
612
+ $name_attrid = $this->_getCategoryAttributeId('name');
613
+ $is_anchor_attrid = $this->_getCategoryAttributeId('is_anchor');
614
+ $image_attrid = $this->_getCategoryAttributeId('image');
615
+
616
+
617
+
618
+
619
+ $attr_url_key = $this->attributes['url_key'];
620
+ $attr_display_mode = $this->attributes['display_mode'];
621
+ $attr_is_active = $this->attributes['is_active'];
622
+ $attr_include_in_menu = $this->attributes['include_in_menu'];
623
+
624
+
625
+ $this->loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char);
626
+ $coincidence = $this->calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type, $category_types);
627
+
628
+ /**/
629
+ if (!$this->check_loaded_data($parse_file, $categories_temp))
630
+ {
631
+ $inf = mysqli_info();
632
+ $this->set_import_error_reporting_message('The Stock In The Channel data files do not appear to be in the correct format. Check file'.$parse_file. "(LOAD DATA ... ".$inf.")");
633
+ exit;
634
+ }/**/
635
+
636
+
637
+ echo("\n\ncoincidence = [".count($coincidence)."]\n\n");
638
+
639
+ if (count($coincidence) == 1) // one store logic
640
+ {
641
+ echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
642
+ if ($im_type == "REWRITE")
643
+ {
644
+ $root_cat = 2;
645
+
646
+ $root_cat = $this->truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
647
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
648
+ $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu); // return $root_cat
649
+ }
650
+ else // if ($im_type == "MERGE")
651
+ {
652
+ $root_cat = $this->_getShopRootCategoryId();
653
+ }
654
+
655
+ $this->_root_cat = $root_cat;
656
+
657
+ $this->setCategorySettings($categories_temp, $root_cat);
658
+ $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
659
+ $this->addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
660
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat);
661
+ }
662
+ else if (count($coincidence) > 1) // multistore logic
663
+ {
664
+ echo("\n\n\n====================================\nmultistore logic\n====================================\n\n\n");
665
+ switch ($im_type)
666
+ {
667
+ case "REWRITE": $this->rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
668
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
669
+ $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
670
+ $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
671
+ break;
672
+ case "MERGE" : $this->mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
673
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
674
+ $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
675
+ $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
676
+ break;
677
+ default : $retcode = "error";
678
+ };
679
+ }
680
+ else
681
+ {
682
+ echo("error");
683
+ }
684
+
685
+ $this->_LOG("Finish parse ".FILE_CATEGORIES);
686
+ }
687
+ else
688
+ {
689
+ $this->_LOG("Wrong file ".$parse_file);
690
+ }
691
+ $this->_LOG(' ');
692
+ $this->_set_default_root_category();
693
+ return $coincidence;
694
+ } // function ParseCategories()
695
+ ################################################################################################################################################################
696
+
697
+
698
+
699
+
700
+
701
+
702
+ ################################################################################################################################################################
703
+ private function loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char)
704
+ {
705
+ $this->db_do("DROP TABLE IF EXISTS $categories_temp");
706
+
707
+
708
+ /** OLD !!!*
709
+ $this->db_do("CREATE TABLE $categories_temp (
710
+ store_category_id int(11),
711
+ parent_store_category_id int(11),
712
+ category_name varchar(50),
713
+ order_number int(11),
714
+ is_hidden boolean,
715
+ products_within_this_category int(11),
716
+ products_within_sub_categories int(11),
717
+ categories_image varchar(255),
718
+ level int(10) NOT NULL default 0,
719
+ children_count int(11) NOT NULL default 0,
720
+ KEY(store_category_id),
721
+ KEY(parent_store_category_id)
722
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
723
+ ");
724
+ /**/
725
+
726
+ /** NEW !!! */
727
+ $this->db_do("
728
+ CREATE TABLE $categories_temp
729
+ (
730
+ store_category_id INT(11),
731
+ parent_store_category_id INT(11),
732
+ category_name VARCHAR(50),
733
+ order_number INT(11),
734
+ is_hidden VARCHAR(10),
735
+ products_within_sub_categories INT(11),
736
+ products_within_this_category INT(11),
737
+ categories_image VARCHAR(255),
738
+ level INT(10) NOT NULL DEFAULT 0,
739
+ children_count INT(11) NOT NULL DEFAULT 0,
740
+ UNSPSC INT(10) DEFAULT NULL,
741
+ RootName INT(10) DEFAULT NULL,
742
+ MainImageURL VARCHAR(255),
743
+ MetaTitle TEXT,
744
+ MetaDescription TEXT,
745
+ Description TEXT,
746
+ KEY(store_category_id),
747
+ KEY(parent_store_category_id)
748
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
749
+ /**/
750
+
751
+ $this->db_do("
752
+ LOAD DATA LOCAL INFILE '$parse_file' INTO TABLE $categories_temp
753
+ FIELDS TERMINATED BY '$field_terminated_char' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES");
754
+
755
+ $this->db_do("ALTER TABLE $categories_temp ADD COLUMN include_in_menu TINYINT(1) NOT NULL DEFAULT 1");
756
+ $this->db_do("UPDATE $categories_temp SET include_in_menu = 0 WHERE UCASE(is_hidden)='TRUE'");
757
+
758
+ $this->db_do("ALTER TABLE $categories_temp ADD COLUMN is_anchor TINYINT(1) NOT NULL DEFAULT 1");
759
+ $this->db_do("UPDATE $categories_temp SET level = (level+2) WHERE level >= 0");
760
+ # $this->db_do("UPDATE $categories_temp SET is_anchor = 0 WHERE level > 0");
761
+
762
+
763
+
764
+ /** FOR TEST !!! *
765
+ $this->db_do("ALTER TABLE $categories_temp ADD COLUMN UNSPSC INT(10) NOT NULL DEFAULT 0");
766
+ $this->db_do("ALTER TABLE $categories_temp ADD COLUMN RootName VARCHAR(50) NOT NULL DEFAULT 0");
767
+
768
+ //$this->db_do("UPDATE $categories_temp SET RootName = '3'"); // one store logic test
769
+
770
+ $this->db_do("UPDATE $categories_temp SET RootName = 'KAMERY' WHERE store_category_id IN (93530, 93531, 93230, 93231, 175559, 175687)");
771
+ $this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
772
+ $this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553, 93530, 93531, 93230, 93231, 175559, 175687)");
773
+
774
+
775
+ //$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
776
+ //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553)");
777
+
778
+
779
+ //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id IN (175687, 175553)"); // OLD CATS...//
780
+
781
+ /**/
782
+ } // private function loadCategoriesTemp()
783
+ ################################################################################################################################################################
784
+
785
+
786
+
787
+ ################################################################################################################################################################
788
+ private function mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
789
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
790
+ $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
791
+ $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
792
+ {
793
+ echo("mergeMultistoreCategories RUN\n");
794
+
795
+
796
+
797
+ $this->createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
798
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
799
+
800
+
801
+
802
+ $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
803
+
804
+
805
+ $this->addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
806
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
807
+ $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
808
+
809
+
810
+
811
+ echo("\n\n\nmergeMultistoreCategories DONE\n");
812
+ }
813
+ ################################################################################################################################################################
814
+
815
+
816
+
817
+
818
+
819
+
820
+ ################################################################################################################################################################
821
+ private function addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
822
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
823
+ $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
824
+ {
825
+ echo("\n\n\n\n *************************************************************\n addCategoryDataMultistoreMerge start... \n");
826
+
827
+
828
+ if (UPDATE_CATEGORY_DATA)
829
+ {
830
+ $ignore = '';
831
+ $on_diplicate_key_update = "
832
+ ON DUPLICATE KEY UPDATE
833
+ updated_at = now(),
834
+ store_category_id = c.store_category_id,
835
+ level = c.level,
836
+ children_count = c.children_count,
837
+ position = c.order_number,
838
+ parent_store_category_id = c.parent_store_category_id";
839
+ //level=c.level,
840
+ //children_count=c.children_count
841
+ //position=c.order_number,
842
+ }
843
+ else
844
+ {
845
+ $ignore = 'IGNORE';
846
+ $on_diplicate_key_update = '';
847
+ }
848
+
849
+ $query = "
850
+ INSERT $ignore INTO $catalog_category_entity
851
+ (
852
+ entity_type_id,
853
+ attribute_set_id,
854
+ created_at,
855
+ updated_at,
856
+ level,
857
+ children_count,
858
+ entity_id,
859
+ position,
860
+ parent_id,
861
+ store_category_id,
862
+ parent_store_category_id
863
+ )
864
+ (SELECT
865
+ $_categoryEntityTypeId,
866
+ $_categoryDefault_attribute_set_id,
867
+ NOW(),
868
+ NOW(),
869
+ c.level,
870
+ c.children_count,
871
+ scm.shop_entity_id,
872
+ c.order_number,
873
+ scm.shop_parent_id,
874
+ c.store_category_id,
875
+ c.parent_store_category_id
876
+ FROM $categories_temp c
877
+ LEFT JOIN $stINch_categories_mapping scm
878
+ ON c.store_category_id = scm.store_category_id
879
+ ) $on_diplicate_key_update";
880
+ echo("\n\n $query\n\n");
881
+ $this->db_do($query);
882
+
883
+
884
+
885
+
886
+
887
+
888
+
889
+ $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
890
+
891
+
892
+
893
+
894
+ $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
895
+ while ($row = mysqli_fetch_array($categories))
896
+ {
897
+ $parent_id = $row['parent_id'];
898
+ $entity_id = $row['entity_id'];
899
+
900
+ $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
901
+
902
+ $this->db_do("
903
+ UPDATE $catalog_category_entity
904
+ SET path = '$path'
905
+ WHERE entity_id = $entity_id");
906
+ } // while ($row = mysqli_fetch_array($categories))
907
+
908
+
909
+
910
+ ///////////////////////////////////////////////////////
911
+
912
+
913
+ if(UPDATE_CATEGORY_DATA)
914
+ {
915
+ echo "Update category_data \n";
916
+
917
+ $q = "
918
+ INSERT INTO $catalog_category_entity_varchar
919
+ (
920
+ entity_type_id,
921
+ attribute_id,
922
+ store_id,
923
+ entity_id,
924
+ value
925
+ )
926
+ (SELECT
927
+ $_categoryEntityTypeId,
928
+ $name_attrid,
929
+ 0,
930
+ scm.shop_entity_id,
931
+ c.category_name
932
+ FROM $categories_temp c
933
+ JOIN $stINch_categories_mapping scm
934
+ ON c.store_category_id = scm.store_category_id
935
+ )
936
+ ON DUPLICATE KEY UPDATE
937
+ value = c.category_name";
938
+ $this->db_do($q);
939
+
940
+
941
+ $q = "
942
+ INSERT INTO $catalog_category_entity_varchar
943
+ (
944
+ entity_type_id,
945
+ attribute_id,
946
+ store_id,
947
+ entity_id,
948
+ value
949
+ )
950
+ (SELECT
951
+ $_categoryEntityTypeId,
952
+ $name_attrid,
953
+ 1,
954
+ scm.shop_entity_id,
955
+ c.category_name
956
+ FROM $categories_temp c
957
+ JOIN $stINch_categories_mapping scm
958
+ ON c.store_category_id = scm.store_category_id
959
+ )
960
+ ON DUPLICATE KEY UPDATE
961
+ value = c.category_name";
962
+ $this->db_do($q);
963
+
964
+
965
+ $q = "
966
+ INSERT INTO $catalog_category_entity
967
+ (
968
+ entity_type_id,
969
+ attribute_id,
970
+ store_id,
971
+ entity_id,
972
+ value
973
+ )
974
+ (SELECT
975
+ $_categoryEntityTypeId,
976
+ $attr_is_active,
977
+ 0,
978
+ scm.shop_entity_id,
979
+ 1
980
+ FROM $categories_temp c
981
+ JOIN $stINch_categories_mapping scm
982
+ ON c.store_category_id = scm.store_category_id
983
+ )
984
+ ON DUPLICATE KEY UPDATE
985
+ value = 1";
986
+ $this->db_do($q);
987
+
988
+
989
+ $q = "
990
+ INSERT INTO $catalog_category_entity_int
991
+ (
992
+ entity_type_id,
993
+ attribute_id,
994
+ store_id,
995
+ entity_id,
996
+ value
997
+ )
998
+ (SELECT
999
+ $_categoryEntityTypeId,
1000
+ $attr_is_active,
1001
+ 1,
1002
+ scm.shop_entity_id,
1003
+ 1
1004
+ FROM $categories_temp c
1005
+ JOIN $stINch_categories_mapping scm
1006
+ ON c.store_category_id = scm.store_category_id
1007
+ )
1008
+ ON DUPLICATE KEY UPDATE
1009
+ value = 1";
1010
+ $this->db_do($q);
1011
+
1012
+
1013
+ $q = "
1014
+ INSERT INTO $catalog_category_entity_int
1015
+ (
1016
+ entity_type_id,
1017
+ attribute_id,
1018
+ store_id,
1019
+ entity_id,
1020
+ value
1021
+ )
1022
+ (SELECT
1023
+ $_categoryEntityTypeId,
1024
+ $attr_include_in_menu,
1025
+ 0,
1026
+ scm.shop_entity_id,
1027
+ c.include_in_menu
1028
+ FROM $categories_temp c
1029
+ JOIN $stINch_categories_mapping scm
1030
+ ON c.store_category_id = scm.store_category_id
1031
+ )
1032
+ ON DUPLICATE KEY UPDATE
1033
+ value = c.include_in_menu";
1034
+ $this->db_do($q);
1035
+
1036
+
1037
+ $q = "
1038
+ INSERT INTO $catalog_category_entity_int
1039
+ (
1040
+ entity_type_id,
1041
+ attribute_id,
1042
+ store_id,
1043
+ entity_id,
1044
+ value
1045
+ )
1046
+ (SELECT
1047
+ $_categoryEntityTypeId,
1048
+ $is_anchor_attrid,
1049
+ 1,
1050
+ scm.shop_entity_id,
1051
+ c.is_anchor
1052
+ FROM $categories_temp c
1053
+ JOIN $stINch_categories_mapping scm
1054
+ ON c.store_category_id = scm.store_category_id
1055
+ )
1056
+ ON DUPLICATE KEY UPDATE
1057
+ value = c.is_anchor";
1058
+ $this->db_do($q);
1059
+
1060
+
1061
+ $q = "
1062
+ INSERT INTO $catalog_category_entity_int
1063
+ (
1064
+ entity_type_id,
1065
+ attribute_id,
1066
+ store_id,
1067
+ entity_id,
1068
+ value
1069
+ )
1070
+ (SELECT
1071
+ $_categoryEntityTypeId,
1072
+ $is_anchor_attrid,
1073
+ 0,
1074
+ scm.shop_entity_id,
1075
+ c.is_anchor
1076
+ FROM $categories_temp c
1077
+ JOIN $stINch_categories_mapping scm
1078
+ ON c.store_category_id = scm.store_category_id
1079
+ )
1080
+ ON DUPLICATE KEY UPDATE
1081
+ value = c.is_anchor";
1082
+ $this->db_do($q);
1083
+
1084
+ $q = "
1085
+ INSERT INTO $catalog_category_entity_varchar
1086
+ (
1087
+ entity_type_id,
1088
+ attribute_id,
1089
+ store_id,
1090
+ entity_id,
1091
+ value
1092
+ )
1093
+ (SELECT
1094
+ $_categoryEntityTypeId,
1095
+ $image_attrid,
1096
+ 0,
1097
+ scm.shop_entity_id,
1098
+ c.categories_image
1099
+ FROM $categories_temp c
1100
+ JOIN $stINch_categories_mapping scm
1101
+ ON c.store_category_id = scm.store_category_id
1102
+ )
1103
+ ON DUPLICATE KEY UPDATE
1104
+ value = c.categories_image";
1105
+ $this->db_do($q);
1106
+ //STP
1107
+ $q = "
1108
+ INSERT INTO $catalog_category_entity_varchar
1109
+ (
1110
+ entity_type_id,
1111
+ attribute_id,
1112
+ store_id,
1113
+ entity_id,
1114
+ value
1115
+ )
1116
+ (SELECT
1117
+ $this->_categoryEntityTypeId,
1118
+ $this->_categoryMetaTitleAttrId,
1119
+ 0,
1120
+ scm.shop_entity_id,
1121
+ c.MetaTitle
1122
+ FROM $categories_temp c
1123
+ JOIN $stINch_categories_mapping scm
1124
+ ON c.store_category_id = scm.store_category_id
1125
+ )
1126
+ ON DUPLICATE KEY UPDATE
1127
+ value = c.MetaTitle";
1128
+ $this->db_do($q);
1129
+
1130
+ $q = "
1131
+ INSERT INTO $catalog_category_entity_varchar
1132
+ (
1133
+ entity_type_id,
1134
+ attribute_id,
1135
+ store_id,
1136
+ entity_id,
1137
+ value
1138
+ )
1139
+ (SELECT
1140
+ $this->_categoryEntityTypeId,
1141
+ $this->_categoryMetadescriptionAttrId,
1142
+ 0,
1143
+ scm.shop_entity_id,
1144
+ c.MetaDescription
1145
+ FROM $categories_temp c
1146
+ JOIN $stINch_categories_mapping scm
1147
+ ON c.store_category_id = scm.store_category_id
1148
+ )
1149
+ ON DUPLICATE KEY UPDATE
1150
+ value = c.MetaDescription";
1151
+ $this->db_do($q);
1152
+
1153
+ $q = "
1154
+ INSERT INTO $catalog_category_entity_varchar
1155
+ (
1156
+ entity_type_id,
1157
+ attribute_id,
1158
+ store_id,
1159
+ entity_id,
1160
+ value
1161
+ )
1162
+ (SELECT
1163
+ $this->_categoryEntityTypeId,
1164
+ $this->_categoryDescriptionAttrId,
1165
+ 0,
1166
+ scm.shop_entity_id,
1167
+ c.Description
1168
+ FROM $categories_temp c
1169
+ JOIN $stINch_categories_mapping scm
1170
+ ON c.store_category_id = scm.store_category_id
1171
+ )
1172
+ ON DUPLICATE KEY UPDATE
1173
+ value = c.Description";
1174
+ $this->db_do($q);
1175
+
1176
+
1177
+ //stp
1178
+ }
1179
+ else
1180
+ {
1181
+ echo "Insert ignore category_data \n";
1182
+
1183
+
1184
+ $q = "
1185
+ INSERT IGNORE INTO $catalog_category_entity_varchar
1186
+ (
1187
+ entity_type_id,
1188
+ attribute_id,
1189
+ store_id,
1190
+ entity_id,
1191
+ value
1192
+ )
1193
+ (SELECT
1194
+ $_categoryEntityTypeId,
1195
+ $name_attrid,
1196
+ 0,
1197
+ scm.shop_entity_id,
1198
+ c.category_name
1199
+ FROM $categories_temp c
1200
+ JOIN $stINch_categories_mapping scm
1201
+ ON c.store_category_id = scm.store_category_id
1202
+ )";
1203
+ $this->db_do($q);
1204
+
1205
+
1206
+ $q = "
1207
+ INSERT IGNORE INTO $catalog_category_entity_int
1208
+ (
1209
+ entity_type_id,
1210
+ attribute_id,
1211
+ store_id,
1212
+ entity_id,
1213
+ value
1214
+ )
1215
+ (SELECT
1216
+ $_categoryEntityTypeId,
1217
+ $attr_is_active,
1218
+ 0,
1219
+ scm.shop_entity_id,
1220
+ 1
1221
+ FROM $categories_temp c
1222
+ JOIN $stINch_categories_mapping scm
1223
+ ON c.store_category_id = scm.store_category_id
1224
+ )";
1225
+ $this->db_do($q);
1226
+
1227
+
1228
+ $q = "
1229
+ INSERT IGNORE INTO $catalog_category_entity_int
1230
+ (
1231
+ entity_type_id,
1232
+ attribute_id,
1233
+ store_id,
1234
+ entity_id,
1235
+ value
1236
+ )
1237
+ (SELECT
1238
+ $_categoryEntityTypeId,
1239
+ $attr_include_in_menu,
1240
+ 0,
1241
+ scm.shop_entity_id,
1242
+ c.include_in_menu
1243
+ FROM $categories_temp c
1244
+ JOIN $stINch_categories_mapping scm
1245
+ ON c.store_category_id = scm.store_category_id
1246
+ )";
1247
+ $this->db_do($q);
1248
+
1249
+
1250
+ $q = "
1251
+ INSERT IGNORE INTO $catalog_category_entity_int
1252
+ (
1253
+ entity_type_id,
1254
+ attribute_id,
1255
+ store_id,
1256
+ entity_id,
1257
+ value
1258
+ )
1259
+ (SELECT
1260
+ $_categoryEntityTypeId,
1261
+ $is_anchor_attrid,
1262
+ 0,
1263
+ scm.shop_entity_id,
1264
+ c.is_anchor
1265
+ FROM $categories_temp c
1266
+ JOIN $stINch_categories_mapping scm
1267
+ ON c.store_category_id = scm.store_category_id
1268
+ )";
1269
+ $this->db_do($q);
1270
+
1271
+
1272
+ $q = "
1273
+ INSERT IGNORE INTO $catalog_category_entity_varchar
1274
+ (
1275
+ entity_type_id,
1276
+ attribute_id,
1277
+ store_id,
1278
+ entity_id,
1279
+ value
1280
+ )
1281
+ (SELECT
1282
+ $_categoryEntityTypeId,
1283
+ $image_attrid,
1284
+ 0,
1285
+ scm.shop_entity_id,
1286
+ c.categories_image
1287
+ FROM $categories_temp c
1288
+ JOIN $stINch_categories_mapping scm
1289
+ ON c.store_category_id = scm.store_category_id
1290
+ )";
1291
+ $this->db_do($q);
1292
+ //STP
1293
+ $q = "
1294
+ INSERT IGNORE INTO $catalog_category_entity_varchar
1295
+ (
1296
+ entity_type_id,
1297
+ attribute_id,
1298
+ store_id,
1299
+ entity_id,
1300
+ value
1301
+ )
1302
+ (SELECT
1303
+ $this->_categoryEntityTypeId,
1304
+ $this->_categoryMetaTitleAttrId,
1305
+ 0,
1306
+ scm.shop_entity_id,
1307
+ c.MetaTitle
1308
+ FROM $categories_temp c
1309
+ JOIN $stINch_categories_mapping scm
1310
+ ON c.store_category_id = scm.store_category_id
1311
+ )
1312
+ ";
1313
+ $this->db_do($q);
1314
+
1315
+ $q = "
1316
+ INSERT IGNORE INTO $catalog_category_entity_varchar
1317
+ (
1318
+ entity_type_id,
1319
+ attribute_id,
1320
+ store_id,
1321
+ entity_id,
1322
+ value
1323
+ )
1324
+ (SELECT
1325
+ $this->_categoryEntityTypeId,
1326
+ $this->_categoryMetadescriptionAttrId,
1327
+ 0,
1328
+ scm.shop_entity_id,
1329
+ c.MetaDescription
1330
+ FROM $categories_temp c
1331
+ JOIN $stINch_categories_mapping scm
1332
+ ON c.store_category_id = scm.store_category_id
1333
+ )
1334
+ ";
1335
+ $this->db_do($q);
1336
+
1337
+ $q = "
1338
+ INSERT IGNORE INTO $catalog_category_entity_varchar
1339
+ (
1340
+ entity_type_id,
1341
+ attribute_id,
1342
+ store_id,
1343
+ entity_id,
1344
+ value
1345
+ )
1346
+ (SELECT
1347
+ $this->_categoryEntityTypeId,
1348
+ $this->_categoryDescriptionAttrId,
1349
+ 0,
1350
+ scm.shop_entity_id,
1351
+ c.Description
1352
+ FROM $categories_temp c
1353
+ JOIN $stINch_categories_mapping scm
1354
+ ON c.store_category_id = scm.store_category_id
1355
+ )
1356
+ ";
1357
+ $this->db_do($q);
1358
+
1359
+
1360
+ //stp
1361
+
1362
+ }
1363
+
1364
+
1365
+
1366
+
1367
+
1368
+ //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
1369
+
1370
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
1371
+ $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
1372
+
1373
+ $this->deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int);
1374
+ /**/
1375
+
1376
+ echo("\n addCategoryDataMultistoreMerge done... \n *************************************************************\n");
1377
+
1378
+ } // private function addCategoryDataMultistoreMerge(...)
1379
+ ################################################################################################################################################################
1380
+
1381
+
1382
+
1383
+
1384
+
1385
+ ################################################################################################################################################################
1386
+ private function deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int)
1387
+ {
1388
+
1389
+ echo("\n\n\n\n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n deleteOldSinchCategoriesFromShopMerge start... \n");
1390
+
1391
+
1392
+ $query = "DROP TABLE IF EXISTS delete_cats";
1393
+ echo("\n $query\n");
1394
+ $this->db_do($query );
1395
+
1396
+
1397
+
1398
+ $delete_cats = Mage::getSingleton('core/resource')->getTableName('delete_cats');
1399
+ $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
1400
+
1401
+ $query = "
1402
+ CREATE TABLE $delete_cats
1403
+
1404
+ SELECT entity_id
1405
+ FROM $catalog_category_entity cce
1406
+ WHERE cce.entity_id NOT IN
1407
+ (
1408
+ SELECT cce2.entity_id
1409
+ FROM $catalog_category_entity cce2
1410
+ JOIN $stINch_categories sc
1411
+ ON cce2.store_category_id = sc.store_category_id
1412
+ )
1413
+ AND cce.store_category_id IS NOT NULL
1414
+ ;";
1415
+
1416
+ echo("\n $query\n");
1417
+ $this->db_do($query);
1418
+
1419
+
1420
+
1421
+ $query = "DELETE cce FROM $catalog_category_entity cce JOIN $delete_cats dc USING(entity_id)";
1422
+ echo("\n $query\n");
1423
+ $this->db_do($query);
1424
+
1425
+
1426
+
1427
+ $query = "DROP TABLE IF EXISTS $delete_cats";
1428
+ echo("\n $query\n");
1429
+ //$this->db_do($query );
1430
+
1431
+
1432
+ /**
1433
+ $query = "
1434
+ DELETE cat FROM $catalog_category_entity_varchar cat
1435
+ JOIN $stINch_categories_mapping scm
1436
+ ON cat.entity_id = scm.shop_entity_id
1437
+ WHERE
1438
+ (scm.shop_store_category_id IS NOT NULL) AND
1439
+ (scm.store_category_id IS NULL)";
1440
+ echo("\n $query\n");
1441
+ // $this->db_do($query);
1442
+
1443
+ $query = "
1444
+ DELETE cat FROM $catalog_category_entity_int cat
1445
+ JOIN $stINch_categories_mapping scm
1446
+ ON cat.entity_id = scm.shop_entity_id
1447
+ WHERE
1448
+ (scm.shop_store_category_id IS NOT NULL) AND
1449
+ (scm.store_category_id IS NULL)";
1450
+ echo("\n $query\n");
1451
+ // $this->db_do($query);
1452
+
1453
+ $query = "
1454
+ DELETE cat FROM $catalog_category_entity cat
1455
+ JOIN $stINch_categories_mapping scm
1456
+ ON cat.entity_id=scm.shop_entity_id
1457
+ WHERE
1458
+ (scm.shop_store_category_id IS NOT NULL) AND
1459
+ (scm.store_category_id IS NULL)";
1460
+ echo("\n $query\n");
1461
+ // $this->db_do($query);
1462
+ /**/
1463
+
1464
+ echo("\n deleteOldSinchCategoriesFromShopMerge done... \n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n\n");
1465
+
1466
+ } // private function deleteOldSinchCategoriesFromShopMerge()
1467
+ ################################################################################################################################################################
1468
+
1469
+
1470
+
1471
+
1472
+
1473
+ ################################################################################################################################################################
1474
+ private function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
1475
+ {
1476
+ echo("\n\n\ ==========================================================================\n mapSinchCategoriesMultistore start... \n");
1477
+
1478
+ $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
1479
+
1480
+ $query = "
1481
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
1482
+ (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
1483
+ (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
1484
+ FROM $catalog_category_entity)";
1485
+ echo("\n $query\n");
1486
+ $this->db_do($query);
1487
+
1488
+
1489
+ $query = "
1490
+ UPDATE $stINch_categories_mapping_temp cmt
1491
+ JOIN $categories_temp c
1492
+ ON cmt.shop_store_category_id = c.store_category_id
1493
+ SET
1494
+ cmt.store_category_id = c.store_category_id,
1495
+ cmt.parent_store_category_id = c.parent_store_category_id,
1496
+ cmt.category_name = c.category_name,
1497
+ cmt.order_number = c.order_number,
1498
+ cmt.products_within_this_category = c.products_within_this_category";
1499
+ echo("\n $query\n");
1500
+ $this->db_do($query);
1501
+
1502
+
1503
+ $query = "
1504
+ UPDATE $stINch_categories_mapping_temp cmt
1505
+ JOIN $catalog_category_entity cce
1506
+ ON cmt.parent_store_category_id = cce.store_category_id
1507
+ SET cmt.shop_parent_id = cce.entity_id";
1508
+ echo("\n $query\n");
1509
+ $this->db_do($query);
1510
+
1511
+
1512
+ $query = "
1513
+ SELECT DISTINCT
1514
+ c.RootName, cce.entity_id
1515
+ FROM $categories_temp c
1516
+ JOIN $catalog_category_entity_varchar ccev
1517
+ ON c.RootName = ccev.value
1518
+ AND ccev.entity_type_id = $_categoryEntityTypeId
1519
+ AND ccev.attribute_id = $name_attrid
1520
+ AND ccev.store_id = 0
1521
+ JOIN $catalog_category_entity cce
1522
+ ON ccev.entity_id = cce.entity_id";
1523
+ echo("\n $query\n");
1524
+ $root_categories = $this->db_do($query);
1525
+
1526
+ while($root_cat = mysqli_fetch_array($root_categories))
1527
+ {
1528
+ $root_id = $root_cat['entity_id'];
1529
+ $root_name = $root_cat['RootName'];
1530
+
1531
+ $query = "
1532
+ UPDATE $stINch_categories_mapping_temp cmt
1533
+ JOIN $categories_temp c
1534
+ ON cmt.shop_store_category_id = c.store_category_id
1535
+ SET
1536
+ cmt.shop_parent_id = $root_id,
1537
+ cmt.shop_parent_store_category_id = $root_id,
1538
+ cmt.parent_store_category_id = $root_id,
1539
+ c.parent_store_category_id = $root_id
1540
+ WHERE RootName = '$root_name'
1541
+ AND cmt.shop_parent_id = 0";
1542
+ echo("\n $query\n");
1543
+ $this->db_do($query);
1544
+ }
1545
+
1546
+
1547
+
1548
+ // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1549
+ if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
1550
+ else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
1551
+
1552
+ $query = "
1553
+ UPDATE $stINch_categories_mapping_temp cmt
1554
+ JOIN $catalog_category_entity cce
1555
+ ON cmt.shop_entity_id = cce.entity_id
1556
+ SET cce.parent_id = cmt.shop_parent_id
1557
+ $where";
1558
+ echo("\n $query\n");
1559
+ $this->db_do($query);
1560
+
1561
+ $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
1562
+ echo("\n $query\n");
1563
+ $this->db_do($query);
1564
+
1565
+ $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
1566
+ echo("\n $query\n");
1567
+ $this->db_do($query);
1568
+
1569
+ echo("\n mapSinchCategoriesMultistore done... \n ==========================================================================\n\n\n\n");
1570
+ } // public function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
1571
+ ################################################################################################################################################################
1572
+
1573
+
1574
+
1575
+
1576
+
1577
+
1578
+
1579
+ ################################################################################################################################################################
1580
+ private function createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1581
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1582
+ {
1583
+ echo("\n\n ==========================================================================\n createNewDefaultCategories start... \n");
1584
+
1585
+ $old_cats = array();
1586
+ $query = $this->db_do("
1587
+ SELECT
1588
+ cce.entity_id,
1589
+ ccev.value AS category_name
1590
+ FROM $catalog_category_entity cce
1591
+ JOIN $catalog_category_entity_varchar ccev
1592
+ ON cce.entity_id = ccev.entity_id
1593
+ AND ccev.store_id = 0
1594
+ AND cce.entity_type_id = ccev.entity_type_id
1595
+ AND ccev.attribute_id = 41
1596
+ WHERE parent_id = 1"); // 41 - category name
1597
+ while ($row = mysqli_fetch_array($query)) $old_cats[] = $row['category_name'];
1598
+
1599
+ //var_dump($old_cats);
1600
+
1601
+
1602
+ $query = $this->db_do("SELECT MAX(entity_id) AS max_entity_id FROM $catalog_category_entity");
1603
+ $max_entity_id = mysqli_fetch_array($query);
1604
+
1605
+ //var_dump($max_entity_id);
1606
+
1607
+ $i = $max_entity_id[max_entity_id] + 1;
1608
+
1609
+ foreach($coincidence as $key => $item)
1610
+ {
1611
+ echo("\n coincidence: key = [$key]\n");
1612
+
1613
+
1614
+ /**if ($item)
1615
+ {
1616
+ echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> CONTINUE: key = [$key] item = [$item]\n");
1617
+ //continue;
1618
+ }
1619
+ else
1620
+ {
1621
+ echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> NOT CONTINUE: key = [$key] item = [$item]\n");
1622
+ }/**/
1623
+
1624
+
1625
+ if (in_array($key, $old_cats))
1626
+ {
1627
+ echo(" CONTINUE: key = [$key] item = [$item]\n");
1628
+ continue;
1629
+ }
1630
+ else
1631
+ {
1632
+ echo(" CREATE NEW CATEGORY: key = [$key] item = [$item]\n");
1633
+ }
1634
+
1635
+
1636
+ $this->db_do("INSERT $catalog_category_entity
1637
+ (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1638
+ path, position, level, children_count, store_category_id, parent_store_category_id)
1639
+ VALUES
1640
+ ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 1, NULL, NULL)");
1641
+
1642
+
1643
+ $this->db_do("INSERT $catalog_category_entity_varchar
1644
+ (entity_type_id, attribute_id, store_id, entity_id, value)
1645
+ VALUES
1646
+ ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
1647
+ ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
1648
+ ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
1649
+ ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
1650
+
1651
+
1652
+ $this->db_do("INSERT $catalog_category_entity_int
1653
+ (entity_type_id, attribute_id, store_id, entity_id, value)
1654
+ VALUES
1655
+ ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
1656
+ ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
1657
+ ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
1658
+ ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
1659
+ $i++;
1660
+ } // foreach($coincidence as $key => $item)
1661
+
1662
+ echo("\n createNewDefaultCategories done... \n ==========================================================================\n");
1663
+
1664
+ } // private function createNewDefaultCategories()
1665
+ ################################################################################################################################################################
1666
+
1667
+
1668
+
1669
+
1670
+
1671
+
1672
+
1673
+ ################################################################################################################################################################
1674
+ private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type, $category_types)
1675
+ {
1676
+ $root_categories = $this->db_do("
1677
+ SELECT
1678
+ cce.entity_id,
1679
+ ccev.value AS category_name
1680
+ FROM $catalog_category_entity cce
1681
+ JOIN $catalog_category_entity_varchar ccev
1682
+ ON cce.entity_id = ccev.entity_id
1683
+ AND ccev.store_id = 0
1684
+ AND cce.entity_type_id = ccev.entity_type_id
1685
+ AND ccev.attribute_id = 41
1686
+ WHERE parent_id = 1"); // 41 - category name
1687
+ $OLD = array();
1688
+ while($root_cat = mysqli_fetch_array($root_categories)) $OLD[] = $root_cat['category_name'];
1689
+
1690
+ $new_categories = $this->db_do("SELECT DISTINCT RootName FROM $categories_temp");
1691
+
1692
+ //STP $new_categories = $this->db_do("SELECT DISTINCT ctemp.RootName, ctype.name FROM $categories_temp ctemp LEFT JOIN $category_types ctypes on ctemp.RootName = ctype.name");
1693
+
1694
+ $NEW = array();
1695
+ while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['RootName']] = TRUE;
1696
+ /////STP while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['name']] = TRUE;
1697
+ /**
1698
+ $exists_coincidence = array();
1699
+
1700
+ switch ($im_type)
1701
+ {
1702
+ case "REWRITE":
1703
+ foreach($NEW as $item)
1704
+ {
1705
+ $exists_coincidence[$item] = TRUE;
1706
+ }
1707
+ break;
1708
+ case "MERGE" :
1709
+ foreach($OLD as $item)
1710
+ {
1711
+ $exists_coincidence[$item] = FALSE;
1712
+ }
1713
+ foreach($NEW as $item)
1714
+ {
1715
+ $exists_coincidence[$item] = TRUE;
1716
+ }
1717
+ break;
1718
+ default : $retcode = "error";
1719
+ };
1720
+ /**/
1721
+
1722
+
1723
+
1724
+ echo("\ncalculateCategoryCoincidence ...im_type = [$im_type]\n\n");
1725
+ var_dump($exists_coincidence);
1726
+
1727
+ return $exists_coincidence;
1728
+ } // private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity)
1729
+ ################################################################################################################################################################
1730
+
1731
+
1732
+
1733
+ ################################################################################################################################################################
1734
+ private function rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1735
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1736
+ $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
1737
+ $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
1738
+ {
1739
+ echo("rewriteMultistoreCategories RUN\n");
1740
+
1741
+
1742
+ echo(" truncateAllCateriesAndCreateRoot start...");
1743
+ $this->truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1744
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active);
1745
+ echo(" done.\n");
1746
+
1747
+
1748
+ echo(" createDefaultCategories start...");
1749
+ $this->createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1750
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
1751
+ echo(" done.\n");
1752
+
1753
+
1754
+ echo(" mapSinchCategoriesMultistore start...");
1755
+ $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
1756
+ echo(" done.\n");
1757
+
1758
+
1759
+ echo(" addCategoryDataMultistore start...");
1760
+ $this->addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1761
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1762
+ $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
1763
+ echo(" done.\n");
1764
+
1765
+
1766
+ echo("rewriteMultistoreCategories DONE\n");
1767
+ } // private function rewriteMultistoreCategories()
1768
+ ################################################################################################################################################################
1769
+
1770
+
1771
+
1772
+
1773
+
1774
+
1775
+
1776
+ ################################################################################################################################################################
1777
+ private function truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1778
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active)
1779
+ {
1780
+ $this->db_do('SET foreign_key_checks=0');
1781
+
1782
+
1783
+ $this->db_do("TRUNCATE $catalog_category_entity");
1784
+ $this->db_do("TRUNCATE $catalog_category_entity_varchar");
1785
+ $this->db_do("TRUNCATE $catalog_category_entity_int");
1786
+
1787
+
1788
+ $this->db_do("INSERT $catalog_category_entity
1789
+ (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1790
+ path, position, level, children_count, store_category_id, parent_store_category_id)
1791
+ VALUES
1792
+ (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', NOW(), '1', 0, 0, 1, NULL, NULL)");
1793
+
1794
+
1795
+ $this->db_do("INSERT $catalog_category_entity_varchar
1796
+ (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1797
+ VALUES
1798
+ (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
1799
+ (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
1800
+ (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog')");
1801
+
1802
+
1803
+ $this->db_do("INSERT $catalog_category_entity_int
1804
+ (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1805
+ VALUES
1806
+ (1, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1)");
1807
+ } // private function truncateAllCateriesAndCreateRoot(...)
1808
+ ################################################################################################################################################################
1809
+
1810
+
1811
+
1812
+
1813
+ ################################################################################################################################################################
1814
+ private function createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1815
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1816
+ {
1817
+ $i = 3; // 2 - is Default Category... not use.
1818
+
1819
+ foreach($coincidence as $key => $item)
1820
+ {
1821
+ $this->db_do("INSERT $catalog_category_entity
1822
+ (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1823
+ path, position, level, children_count, store_category_id, parent_store_category_id)
1824
+ VALUES
1825
+ ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 1, NULL, NULL)");
1826
+
1827
+
1828
+ $this->db_do("INSERT $catalog_category_entity_varchar
1829
+ (entity_type_id, attribute_id, store_id, entity_id, value)
1830
+ VALUES
1831
+ ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
1832
+ ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
1833
+ ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
1834
+ ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
1835
+
1836
+
1837
+ $this->db_do("INSERT $catalog_category_entity_int
1838
+ (entity_type_id, attribute_id, store_id, entity_id, value)
1839
+ VALUES
1840
+ ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
1841
+ ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
1842
+ ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
1843
+ ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
1844
+ $i++;
1845
+ } // foreach($coincidence as $key => $item)
1846
+ } // private function truncateAllCateries()
1847
+ ################################################################################################################################################################
1848
+
1849
+
1850
+
1851
+
1852
+ ################################################################################################################################################################
1853
+ private function mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
1854
+ {
1855
+ echo("\n\n\n\n==========================================================================\nmapSinchCategoriesMultistore start... \n");
1856
+
1857
+ $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
1858
+
1859
+ $query = "
1860
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
1861
+ (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
1862
+ (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
1863
+ FROM $catalog_category_entity)";
1864
+ echo("\n\n$query\n\n");
1865
+ $this->db_do($query);
1866
+
1867
+
1868
+ $query = "
1869
+ UPDATE $stINch_categories_mapping_temp cmt
1870
+ JOIN $categories_temp c
1871
+ ON cmt.shop_store_category_id = c.store_category_id
1872
+ SET
1873
+ cmt.store_category_id = c.store_category_id,
1874
+ cmt.parent_store_category_id = c.parent_store_category_id,
1875
+ cmt.category_name = c.category_name,
1876
+ cmt.order_number = c.order_number,
1877
+ cmt.products_within_this_category = c.products_within_this_category";
1878
+ echo("\n\n$query\n\n");
1879
+ $this->db_do($query);
1880
+
1881
+
1882
+ $query = "
1883
+ UPDATE $stINch_categories_mapping_temp cmt
1884
+ JOIN $catalog_category_entity cce
1885
+ ON cmt.parent_store_category_id = cce.store_category_id
1886
+ SET cmt.shop_parent_id = cce.entity_id";
1887
+ echo("\n\n$query\n\n");
1888
+ $this->db_do($query);
1889
+
1890
+
1891
+ $query = "
1892
+ SELECT DISTINCT
1893
+ c.RootName, cce.entity_id
1894
+ FROM $categories_temp c
1895
+ JOIN $catalog_category_entity_varchar ccev
1896
+ ON c.RootName = ccev.value
1897
+ AND ccev.entity_type_id = $_categoryEntityTypeId
1898
+ AND ccev.attribute_id = $name_attrid
1899
+ AND ccev.store_id = 0
1900
+ JOIN $catalog_category_entity cce
1901
+ ON ccev.entity_id = cce.entity_id";
1902
+ echo("\n\n$query\n\n");
1903
+ $root_categories = $this->db_do($query);
1904
+
1905
+ while($root_cat = mysqli_fetch_array($root_categories))
1906
+ {
1907
+ $root_id = $root_cat['entity_id'];
1908
+ $root_name = $root_cat['RootName'];
1909
+
1910
+ $query = "
1911
+ UPDATE $stINch_categories_mapping_temp cmt
1912
+ JOIN $categories_temp c
1913
+ ON cmt.shop_store_category_id = c.store_category_id
1914
+ SET
1915
+ cmt.shop_parent_id = $root_id,
1916
+ cmt.shop_parent_store_category_id = $root_id,
1917
+ cmt.parent_store_category_id = $root_id,
1918
+ c.parent_store_category_id = $root_id
1919
+ WHERE RootName = '$root_name'
1920
+ AND cmt.shop_parent_id = 0";
1921
+ echo("\n\n$query\n\n");
1922
+ $this->db_do($query);
1923
+ }
1924
+
1925
+
1926
+
1927
+ // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1928
+ if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
1929
+ else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
1930
+
1931
+ $query = "
1932
+ UPDATE $stINch_categories_mapping_temp cmt
1933
+ JOIN $catalog_category_entity cce
1934
+ ON cmt.shop_entity_id = cce.entity_id
1935
+ SET cce.parent_id = cmt.shop_parent_id
1936
+ $where";
1937
+ echo("\n\n$query\n\n");
1938
+ $this->db_do($query);
1939
+
1940
+ $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
1941
+ echo("\n\n$query\n\n");
1942
+ $this->db_do($query);
1943
+
1944
+ $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
1945
+ echo("\n\n$query\n\n");
1946
+ $this->db_do($query);
1947
+
1948
+ echo("\nmapSinchCategoriesMultistore done... \n==========================================================================\n\n\n\n");
1949
+ } // public function mapSinchCategoriesMultistore($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
1950
+ ################################################################################################################################################################
1951
+
1952
+
1953
+
1954
+ ################################################################################################################################################################
1955
+ private function createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping)
1956
+ {
1957
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
1958
+ $this->db_do("
1959
+ CREATE TABLE $stINch_categories_mapping_temp
1960
+ (
1961
+ shop_entity_id INT(11) UNSIGNED NOT NULL,
1962
+ shop_entity_type_id INT(11),
1963
+ shop_attribute_set_id INT(11),
1964
+ shop_parent_id INT(11),
1965
+ shop_store_category_id INT(11),
1966
+ shop_parent_store_category_id INT(11),
1967
+ store_category_id INT(11),
1968
+ parent_store_category_id INT(11),
1969
+ category_name VARCHAR(255),
1970
+ order_number INT(11),
1971
+ products_within_this_category INT(11),
1972
+
1973
+ KEY shop_entity_id (shop_entity_id),
1974
+ KEY shop_parent_id (shop_parent_id),
1975
+ KEY store_category_id (store_category_id),
1976
+ KEY parent_store_category_id (parent_store_category_id),
1977
+ UNIQUE KEY(shop_entity_id)
1978
+ )");
1979
+
1980
+
1981
+ $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
1982
+ }
1983
+ ################################################################################################################################################################
1984
+
1985
+
1986
+
1987
+ ################################################################################################################################################################
1988
+ private function addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1989
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1990
+ $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
1991
+ {
1992
+ echo("\n\n\n\n*************************************************************\nmapSinchCategoriesMultistore start... \n");
1993
+ if (UPDATE_CATEGORY_DATA)
1994
+ {
1995
+ $ignore = '';
1996
+ $on_diplicate_key_update = "
1997
+ ON DUPLICATE KEY UPDATE
1998
+ updated_at = now(),
1999
+ store_category_id = c.store_category_id,
2000
+ level = c.level,
2001
+ children_count = c.children_count,
2002
+ position = c.order_number,
2003
+ parent_store_category_id = c.parent_store_category_id";
2004
+ //level=c.level,
2005
+ //children_count=c.children_count
2006
+ //position=c.order_number,
2007
+ }
2008
+ else
2009
+ {
2010
+ $ignore = 'IGNORE';
2011
+ $on_diplicate_key_update = '';
2012
+ }
2013
+
2014
+ $query = "
2015
+ INSERT $ignore INTO $catalog_category_entity
2016
+ (
2017
+ entity_type_id,
2018
+ attribute_set_id,
2019
+ created_at,
2020
+ updated_at,
2021
+ level,
2022
+ children_count,
2023
+ entity_id,
2024
+ position,
2025
+ parent_id,
2026
+ store_category_id,
2027
+ parent_store_category_id
2028
+ )
2029
+ (SELECT
2030
+ $_categoryEntityTypeId,
2031
+ $_categoryDefault_attribute_set_id,
2032
+ NOW(),
2033
+ NOW(),
2034
+ c.level,
2035
+ c.children_count,
2036
+ scm.shop_entity_id,
2037
+ c.order_number,
2038
+ scm.shop_parent_id,
2039
+ c.store_category_id,
2040
+ c.parent_store_category_id
2041
+ FROM $categories_temp c
2042
+ LEFT JOIN $stINch_categories_mapping scm
2043
+ ON c.store_category_id = scm.store_category_id
2044
+ ) $on_diplicate_key_update";
2045
+ echo("\n\n$query\n\n");
2046
+ $this->db_do($query);
2047
+
2048
+ //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
2049
+
2050
+
2051
+ $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
2052
+
2053
+
2054
+ $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
2055
+ while ($row = mysqli_fetch_array($categories))
2056
+ {
2057
+ $parent_id = $row['parent_id'];
2058
+ $entity_id = $row['entity_id'];
2059
+
2060
+ $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
2061
+
2062
+ $this->db_do("
2063
+ UPDATE $catalog_category_entity
2064
+ SET path = '$path'
2065
+ WHERE entity_id = $entity_id");
2066
+ } // while ($row = mysqli_fetch_array($categories))
2067
+
2068
+
2069
+ ///////////////////////////////////////////////////////
2070
+
2071
+
2072
+ if(UPDATE_CATEGORY_DATA)
2073
+ {
2074
+ echo "Update category_data \n";
2075
+
2076
+ $q = "
2077
+ INSERT INTO $catalog_category_entity_varchar
2078
+ (
2079
+ entity_type_id,
2080
+ attribute_id,
2081
+ store_id,
2082
+ entity_id,
2083
+ value
2084
+ )
2085
+ (SELECT
2086
+ $_categoryEntityTypeId,
2087
+ $name_attrid,
2088
+ 0,
2089
+ scm.shop_entity_id,
2090
+ c.category_name
2091
+ FROM $categories_temp c
2092
+ JOIN $stINch_categories_mapping scm
2093
+ ON c.store_category_id = scm.store_category_id
2094
+ )
2095
+ ON DUPLICATE KEY UPDATE
2096
+ value = c.category_name";
2097
+ $this->db_do($q);
2098
+
2099
+
2100
+ $q = "
2101
+ INSERT INTO $catalog_category_entity_varchar
2102
+ (
2103
+ entity_type_id,
2104
+ attribute_id,
2105
+ store_id,
2106
+ entity_id,
2107
+ value
2108
+ )
2109
+ (SELECT
2110
+ $_categoryEntityTypeId,
2111
+ $name_attrid,
2112
+ 1,
2113
+ scm.shop_entity_id,
2114
+ c.category_name
2115
+ FROM $categories_temp c
2116
+ JOIN $stINch_categories_mapping scm
2117
+ ON c.store_category_id = scm.store_category_id
2118
+ )
2119
+ ON DUPLICATE KEY UPDATE
2120
+ value = c.category_name";
2121
+ $this->db_do($q);
2122
+
2123
+
2124
+ $q = "
2125
+ INSERT INTO $catalog_category_entity
2126
+ (
2127
+ entity_type_id,
2128
+ attribute_id,
2129
+ store_id,
2130
+ entity_id,
2131
+ value
2132
+ )
2133
+ (SELECT
2134
+ $_categoryEntityTypeId,
2135
+ $attr_is_active,
2136
+ 0,
2137
+ scm.shop_entity_id,
2138
+ 1
2139
+ FROM $categories_temp c
2140
+ JOIN $stINch_categories_mapping scm
2141
+ ON c.store_category_id = scm.store_category_id
2142
+ )
2143
+ ON DUPLICATE KEY UPDATE
2144
+ value = 1";
2145
+ $this->db_do($q);
2146
+
2147
+
2148
+ $q = "
2149
+ INSERT INTO $catalog_category_entity_int
2150
+ (
2151
+ entity_type_id,
2152
+ attribute_id,
2153
+ store_id,
2154
+ entity_id,
2155
+ value
2156
+ )
2157
+ (SELECT
2158
+ $_categoryEntityTypeId,
2159
+ $attr_is_active,
2160
+ 1,
2161
+ scm.shop_entity_id,
2162
+ 1
2163
+ FROM $categories_temp c
2164
+ JOIN $stINch_categories_mapping scm
2165
+ ON c.store_category_id = scm.store_category_id
2166
+ )
2167
+ ON DUPLICATE KEY UPDATE
2168
+ value = 1";
2169
+ $this->db_do($q);
2170
+
2171
+
2172
+ $q = "
2173
+ INSERT INTO $catalog_category_entity_int
2174
+ (
2175
+ entity_type_id,
2176
+ attribute_id,
2177
+ store_id,
2178
+ entity_id,
2179
+ value
2180
+ )
2181
+ (SELECT
2182
+ $_categoryEntityTypeId,
2183
+ $attr_include_in_menu,
2184
+ 0,
2185
+ scm.shop_entity_id,
2186
+ c.include_in_menu
2187
+ FROM $categories_temp c
2188
+ JOIN $stINch_categories_mapping scm
2189
+ ON c.store_category_id = scm.store_category_id
2190
+ )
2191
+ ON DUPLICATE KEY UPDATE
2192
+ value = c.include_in_menu";
2193
+ $this->db_do($q);
2194
+
2195
+
2196
+ $q = "
2197
+ INSERT INTO $catalog_category_entity_int
2198
+ (
2199
+ entity_type_id,
2200
+ attribute_id,
2201
+ store_id,
2202
+ entity_id,
2203
+ value
2204
+ )
2205
+ (SELECT
2206
+ $_categoryEntityTypeId,
2207
+ $is_anchor_attrid,
2208
+ 1,
2209
+ scm.shop_entity_id,
2210
+ c.is_anchor
2211
+ FROM $categories_temp c
2212
+ JOIN $stINch_categories_mapping scm
2213
+ ON c.store_category_id = scm.store_category_id
2214
+ )
2215
+ ON DUPLICATE KEY UPDATE
2216
+ value = c.is_anchor";
2217
+ $this->db_do($q);
2218
+
2219
+
2220
+ $q = "
2221
+ INSERT INTO $catalog_category_entity_int
2222
+ (
2223
+ entity_type_id,
2224
+ attribute_id,
2225
+ store_id,
2226
+ entity_id,
2227
+ value
2228
+ )
2229
+ (SELECT
2230
+ $_categoryEntityTypeId,
2231
+ $is_anchor_attrid,
2232
+ 0,
2233
+ scm.shop_entity_id,
2234
+ c.is_anchor
2235
+ FROM $categories_temp c
2236
+ JOIN $stINch_categories_mapping scm
2237
+ ON c.store_category_id = scm.store_category_id
2238
+ )
2239
+ ON DUPLICATE KEY UPDATE
2240
+ value = c.is_anchor";
2241
+ $this->db_do($q);
2242
+
2243
+ $q = "
2244
+ INSERT INTO $catalog_category_entity_varchar
2245
+ (
2246
+ entity_type_id,
2247
+ attribute_id,
2248
+ store_id,
2249
+ entity_id,
2250
+ value
2251
+ )
2252
+ (SELECT
2253
+ $_categoryEntityTypeId,
2254
+ $image_attrid,
2255
+ 0,
2256
+ scm.shop_entity_id,
2257
+ c.categories_image
2258
+ FROM $categories_temp c
2259
+ JOIN $stINch_categories_mapping scm
2260
+ ON c.store_category_id = scm.store_category_id
2261
+ )
2262
+ ON DUPLICATE KEY UPDATE
2263
+ value = c.categories_image";
2264
+ $this->db_do($q);
2265
+ //STP
2266
+ $q = "
2267
+ INSERT INTO $catalog_category_entity_varchar
2268
+ (
2269
+ entity_type_id,
2270
+ attribute_id,
2271
+ store_id,
2272
+ entity_id,
2273
+ value
2274
+ )
2275
+ (SELECT
2276
+ $this->_categoryEntityTypeId,
2277
+ $this->_categoryMetaTitleAttrId,
2278
+ 0,
2279
+ scm.shop_entity_id,
2280
+ c.MetaTitle
2281
+ FROM $categories_temp c
2282
+ JOIN $stINch_categories_mapping scm
2283
+ ON c.store_category_id = scm.store_category_id
2284
+ )
2285
+ ON DUPLICATE KEY UPDATE
2286
+ value = c.MetaTitle";
2287
+ $this->db_do($q);
2288
+
2289
+ $q = "
2290
+ INSERT INTO $catalog_category_entity_varchar
2291
+ (
2292
+ entity_type_id,
2293
+ attribute_id,
2294
+ store_id,
2295
+ entity_id,
2296
+ value
2297
+ )
2298
+ (SELECT
2299
+ $this->_categoryEntityTypeId,
2300
+ $this->_categoryMetadescriptionAttrId,
2301
+ 0,
2302
+ scm.shop_entity_id,
2303
+ c.MetaDescription
2304
+ FROM $categories_temp c
2305
+ JOIN $stINch_categories_mapping scm
2306
+ ON c.store_category_id = scm.store_category_id
2307
+ )
2308
+ ON DUPLICATE KEY UPDATE
2309
+ value = c.MetaDescription";
2310
+ $this->db_do($q);
2311
+
2312
+ $q = "
2313
+ INSERT INTO $catalog_category_entity_varchar
2314
+ (
2315
+ entity_type_id,
2316
+ attribute_id,
2317
+ store_id,
2318
+ entity_id,
2319
+ value
2320
+ )
2321
+ (SELECT
2322
+ $this->_categoryEntityTypeId,
2323
+ $this->_categoryDescriptionAttrId,
2324
+ 0,
2325
+ scm.shop_entity_id,
2326
+ c.Description
2327
+ FROM $categories_temp c
2328
+ JOIN $stINch_categories_mapping scm
2329
+ ON c.store_category_id = scm.store_category_id
2330
+ )
2331
+ ON DUPLICATE KEY UPDATE
2332
+ value = c.Description";
2333
+ $this->db_do($q);
2334
+
2335
+
2336
+ //stp
2337
+ }
2338
+ else
2339
+ {
2340
+ echo "Insert ignore category_data \n";
2341
+
2342
+ $q = "
2343
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2344
+ (
2345
+ entity_type_id,
2346
+ attribute_id,
2347
+ store_id,
2348
+ entity_id,
2349
+ value
2350
+ )
2351
+ (SELECT
2352
+ $_categoryEntityTypeId,
2353
+ $name_attrid,
2354
+ 0,
2355
+ scm.shop_entity_id,
2356
+ c.category_name
2357
+ FROM $categories_temp c
2358
+ JOIN $stINch_categories_mapping scm
2359
+ ON c.store_category_id = scm.store_category_id
2360
+ )";
2361
+ $this->db_do($q);
2362
+
2363
+
2364
+ $q = "
2365
+ INSERT IGNORE INTO $catalog_category_entity_int
2366
+ (
2367
+ entity_type_id,
2368
+ attribute_id,
2369
+ store_id,
2370
+ entity_id,
2371
+ value
2372
+ )
2373
+ (SELECT
2374
+ $_categoryEntityTypeId,
2375
+ $attr_is_active,
2376
+ 0,
2377
+ scm.shop_entity_id,
2378
+ 1
2379
+ FROM $categories_temp c
2380
+ JOIN $stINch_categories_mapping scm
2381
+ ON c.store_category_id = scm.store_category_id
2382
+ )";
2383
+ $this->db_do($q);
2384
+
2385
+
2386
+ $q = "
2387
+ INSERT IGNORE INTO $catalog_category_entity_int
2388
+ (
2389
+ entity_type_id,
2390
+ attribute_id,
2391
+ store_id,
2392
+ entity_id,
2393
+ value
2394
+ )
2395
+ (SELECT
2396
+ $_categoryEntityTypeId,
2397
+ $attr_include_in_menu,
2398
+ 0,
2399
+ scm.shop_entity_id,
2400
+ c.include_in_menu
2401
+ FROM $categories_temp c
2402
+ JOIN $stINch_categories_mapping scm
2403
+ ON c.store_category_id = scm.store_category_id
2404
+ )";
2405
+ $this->db_do($q);
2406
+
2407
+
2408
+ $q = "
2409
+ INSERT IGNORE INTO $catalog_category_entity_int
2410
+ (
2411
+ entity_type_id,
2412
+ attribute_id,
2413
+ store_id,
2414
+ entity_id,
2415
+ value
2416
+ )
2417
+ (SELECT
2418
+ $_categoryEntityTypeId,
2419
+ $is_anchor_attrid,
2420
+ 0,
2421
+ scm.shop_entity_id,
2422
+ c.is_anchor
2423
+ FROM $categories_temp c
2424
+ JOIN $stINch_categories_mapping scm
2425
+ ON c.store_category_id = scm.store_category_id
2426
+ )";
2427
+ $this->db_do($q);
2428
+
2429
+
2430
+ $q = "
2431
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2432
+ (
2433
+ entity_type_id,
2434
+ attribute_id,
2435
+ store_id,
2436
+ entity_id,
2437
+ value
2438
+ )
2439
+ (SELECT
2440
+ $_categoryEntityTypeId,
2441
+ $image_attrid,
2442
+ 0,
2443
+ scm.shop_entity_id,
2444
+ c.categories_image
2445
+ FROM $categories_temp c
2446
+ JOIN $stINch_categories_mapping scm
2447
+ ON c.store_category_id = scm.store_category_id
2448
+ )";
2449
+ $this->db_do($q);
2450
+ //STP
2451
+ $q = "
2452
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2453
+ (
2454
+ entity_type_id,
2455
+ attribute_id,
2456
+ store_id,
2457
+ entity_id,
2458
+ value
2459
+ )
2460
+ (SELECT
2461
+ $this->_categoryEntityTypeId,
2462
+ $this->_categoryMetaTitleAttrId,
2463
+ 0,
2464
+ scm.shop_entity_id,
2465
+ c.MetaTitle
2466
+ FROM $categories_temp c
2467
+ JOIN $stINch_categories_mapping scm
2468
+ ON c.store_category_id = scm.store_category_id
2469
+ )
2470
+ ";
2471
+ $this->db_do($q);
2472
+
2473
+ $q = "
2474
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2475
+ (
2476
+ entity_type_id,
2477
+ attribute_id,
2478
+ store_id,
2479
+ entity_id,
2480
+ value
2481
+ )
2482
+ (SELECT
2483
+ $this->_categoryEntityTypeId,
2484
+ $this->_categoryMetadescriptionAttrId,
2485
+ 0,
2486
+ scm.shop_entity_id,
2487
+ c.MetaDescription
2488
+ FROM $categories_temp c
2489
+ JOIN $stINch_categories_mapping scm
2490
+ ON c.store_category_id = scm.store_category_id
2491
+ )
2492
+ ";
2493
+ $this->db_do($q);
2494
+
2495
+ $q = "
2496
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2497
+ (
2498
+ entity_type_id,
2499
+ attribute_id,
2500
+ store_id,
2501
+ entity_id,
2502
+ value
2503
+ )
2504
+ (SELECT
2505
+ $this->_categoryEntityTypeId,
2506
+ $this->_categoryDescriptionAttrId,
2507
+ 0,
2508
+ scm.shop_entity_id,
2509
+ c.Description
2510
+ FROM $categories_temp c
2511
+ JOIN $stINch_categories_mapping scm
2512
+ ON c.store_category_id = scm.store_category_id
2513
+ )
2514
+ ";
2515
+ $this->db_do($q);
2516
+
2517
+
2518
+ //stp
2519
+
2520
+ }
2521
+
2522
+ $this->delete_old_sinch_categories_from_shop();
2523
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
2524
+ $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
2525
+ } // private function addCategoryDataMultistore(...)
2526
+ ################################################################################################################################################################
2527
+
2528
+
2529
+
2530
+ ################################################################################################################################################################
2531
+ function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
2532
+ {
2533
+
2534
+ //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]");
2535
+
2536
+ $path = '';
2537
+
2538
+ $cat_id = $parent_id;
2539
+
2540
+ $q = "
2541
+ SELECT
2542
+ parent_id
2543
+ FROM $catalog_category_entity
2544
+ WHERE entity_id = $cat_id";
2545
+ $quer = $this->db_do($q);
2546
+ $row = mysqli_fetch_array($quer);
2547
+ while ($row['parent_id'])
2548
+ {
2549
+ $path = $row['parent_id'].'/'.$path;
2550
+ $parent_id = $row['parent_id'];
2551
+
2552
+ $q = "
2553
+ SELECT
2554
+ parent_id
2555
+ FROM $catalog_category_entity
2556
+ WHERE entity_id = $parent_id";
2557
+ $quer = $this->db_do($q);
2558
+ $row = mysqli_fetch_array($quer);
2559
+ }
2560
+
2561
+ if ($cat_id) $path.=$cat_id."/";
2562
+
2563
+ if ($path) $path .= $ent_id;
2564
+ else $path = $ent_id;
2565
+
2566
+ //echo(" path = [$path]\n");
2567
+
2568
+ return $path;
2569
+ } // function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
2570
+ ################################################################################################################################################################
2571
+
2572
+
2573
+
2574
+
2575
+
2576
+
2577
+
2578
+
2579
+ ################################################################################################################################################################
2580
+ public function replaceMagentoProductsMultistoreMERGE($coincidence)
2581
+ {
2582
+
2583
+ echo("\n replaceMagentoProductsMultistoreMERGE 1\n");
2584
+
2585
+
2586
+
2587
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
2588
+
2589
+
2590
+ $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
2591
+ $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
2592
+ $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
2593
+ $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
2594
+ $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
2595
+ $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
2596
+ $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
2597
+ $stINch_products = Mage::getSingleton('core/resource')->getTableName('stINch_products');
2598
+ $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
2599
+ $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
2600
+ $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
2601
+ $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
2602
+ $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
2603
+ $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
2604
+ //STP DELETE $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
2605
+ // $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
2606
+ $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
2607
+
2608
+ $_getProductEntityTypeId = $this->_getProductEntityTypeId();
2609
+ $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
2610
+
2611
+ $attr_atatus = $this->_getProductAttributeId('status');
2612
+ $attr_name = $this->_getProductAttributeId('name');
2613
+ $attr_visibility = $this->_getProductAttributeId('visibility');
2614
+ $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
2615
+ $attr_image = $this->_getProductAttributeId('image');
2616
+ $attr_small_image = $this->_getProductAttributeId('small_image');
2617
+ $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
2618
+
2619
+ $cat_attr_name = $this->_getCategoryAttributeId('name');
2620
+ echo("\n replaceMagentoProductsMultistoreMERGE 2\n");
2621
+
2622
+
2623
+
2624
+
2625
+
2626
+ //clear products, inserting new products and updating old others.
2627
+ $query = "
2628
+ DELETE cpe
2629
+ FROM $catalog_product_entity cpe
2630
+ JOIN $stINch_products_mapping pm
2631
+ ON cpe.entity_id = pm.entity_id
2632
+ WHERE pm.shop_store_product_id IS NOT NULL
2633
+ AND pm.store_product_id IS NULL";
2634
+ $result = $this->db_do($query);
2635
+
2636
+
2637
+
2638
+
2639
+
2640
+ echo("\n replaceMagentoProductsMultistoreMERGE 3\n");
2641
+
2642
+ $result = $this->db_do("
2643
+ INSERT INTO $catalog_product_entity
2644
+ (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
2645
+ (SELECT
2646
+ pm.entity_id,
2647
+ $_getProductEntityTypeId,
2648
+ $_defaultAttributeSetId,
2649
+ 'simple',
2650
+ a.product_sku,
2651
+ NOW(),
2652
+ 0,
2653
+ a.store_product_id,
2654
+ a.sinch_product_id
2655
+ FROM $products_temp a
2656
+ LEFT JOIN $stINch_products_mapping pm
2657
+ ON a.store_product_id = pm.store_product_id
2658
+ AND a.sinch_product_id = pm.sinch_product_id
2659
+ WHERE pm.entity_id IS NOT NULL
2660
+ )
2661
+ ON DUPLICATE KEY UPDATE
2662
+ sku = a.product_sku,
2663
+ store_product_id = a.store_product_id,
2664
+ sinch_product_id = a.sinch_product_id");
2665
+ // store_product_id = a.store_product_id,
2666
+ // sinch_product_id = a.sinch_product_id
2667
+
2668
+ $result = $this->db_do("
2669
+ INSERT INTO $catalog_product_entity
2670
+ (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
2671
+ (SELECT
2672
+ pm.entity_id,
2673
+ $_getProductEntityTypeId,
2674
+ $_defaultAttributeSetId,
2675
+ 'simple',
2676
+ a.product_sku,
2677
+ NOW(),
2678
+ 0,
2679
+ a.store_product_id,
2680
+ a.sinch_product_id
2681
+ FROM $products_temp a
2682
+ LEFT JOIN $stINch_products_mapping pm
2683
+ ON a.store_product_id = pm.store_product_id
2684
+ AND a.sinch_product_id = pm.sinch_product_id
2685
+ WHERE pm.entity_id IS NULL
2686
+ )
2687
+ ON DUPLICATE KEY UPDATE
2688
+ sku = a.product_sku,
2689
+ store_product_id = a.store_product_id,
2690
+ sinch_product_id = a.sinch_product_id");
2691
+ // store_product_id = a.store_product_id,
2692
+ // sinch_product_id = a.sinch_product_id
2693
+
2694
+
2695
+ echo("\n replaceMagentoProductsMultistoreMERGE 4\n");
2696
+
2697
+
2698
+
2699
+
2700
+
2701
+ //Set enabled
2702
+ $result = $this->db_do("
2703
+ DELETE cpei
2704
+ FROM $catalog_product_entity_int cpei
2705
+ LEFT JOIN $catalog_product_entity cpe
2706
+ ON cpei.entity_id = cpe.entity_id
2707
+ WHERE cpe.entity_id IS NULL");
2708
+
2709
+ $result = $this->db_do("
2710
+ INSERT INTO $catalog_product_entity_int
2711
+ (entity_type_id, attribute_id, store_id, entity_id, value)
2712
+ (SELECT
2713
+ $_getProductEntityTypeId,
2714
+ $attr_atatus,
2715
+ w.website,
2716
+ a.entity_id,
2717
+ 1
2718
+ FROM $catalog_product_entity a
2719
+ JOIN $products_website_temp w
2720
+ ON a.store_product_id = w.store_product_id
2721
+ )
2722
+ ON DUPLICATE KEY UPDATE
2723
+ value = 1");
2724
+
2725
+
2726
+
2727
+
2728
+
2729
+ echo("\n replaceMagentoProductsMultistoreMERGE 5\n");
2730
+
2731
+
2732
+ // set status = 1 for all stores
2733
+ $result = $this->db_do("
2734
+ INSERT INTO $catalog_product_entity_int
2735
+ (entity_type_id, attribute_id, store_id, entity_id, value)
2736
+ (SELECT
2737
+ $_getProductEntityTypeId,
2738
+ $attr_atatus,
2739
+ 0,
2740
+ a.entity_id,
2741
+ 1
2742
+ FROM $catalog_product_entity a
2743
+ )
2744
+ ON DUPLICATE KEY UPDATE
2745
+ value = 1");
2746
+
2747
+
2748
+
2749
+
2750
+
2751
+ echo("\n replaceMagentoProductsMultistoreMERGE 6\n");
2752
+
2753
+
2754
+ //Unifying products with categories.
2755
+ $result = $this->db_do("
2756
+ DELETE ccp
2757
+ FROM $catalog_category_product ccp
2758
+ LEFT JOIN $catalog_product_entity cpe
2759
+ ON ccp.product_id = cpe.entity_id
2760
+ WHERE cpe.entity_id IS NULL");
2761
+
2762
+
2763
+
2764
+
2765
+
2766
+
2767
+
2768
+ echo("\n replaceMagentoProductsMultistoreMERGE 7\n");
2769
+
2770
+
2771
+ $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
2772
+
2773
+ $result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
2774
+ $result = $this->db_do("
2775
+ CREATE TABLE $root_cats
2776
+ SELECT
2777
+ entity_id,
2778
+ path,
2779
+ SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
2780
+ LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
2781
+ SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
2782
+ FROM $catalog_category_entity
2783
+ ");
2784
+ $result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
2785
+
2786
+
2787
+ echo("\n replaceMagentoProductsMultistoreMERGE 8\n");
2788
+
2789
+
2790
+ // !!! $this->_root_cat
2791
+ $result = $this->db_do("
2792
+ UPDATE IGNORE $catalog_category_product ccp
2793
+ LEFT JOIN $catalog_category_entity cce
2794
+ ON ccp.category_id = cce.entity_id
2795
+ JOIN $root_cats rc
2796
+ ON cce.entity_id = rc.entity_id
2797
+ SET ccp.category_id = rc.root_cat
2798
+ WHERE cce.entity_id IS NULL");
2799
+
2800
+
2801
+
2802
+ echo("\n replaceMagentoProductsMultistoreMERGE 9\n");
2803
+
2804
+
2805
+
2806
+
2807
+
2808
+ $result = $this->db_do("
2809
+ DELETE ccp
2810
+ FROM $catalog_category_product ccp
2811
+ LEFT JOIN $catalog_category_entity cce
2812
+ ON ccp.category_id = cce.entity_id
2813
+ WHERE cce.entity_id IS NULL");
2814
+
2815
+
2816
+
2817
+
2818
+ $stinch_products_delete = Mage::getSingleton('core/resource')->getTableName('stinch_products_delete');
2819
+
2820
+ $result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
2821
+ $result = $this->db_do("
2822
+ CREATE TABLE $stinch_products_delete
2823
+ SELECT cpe.entity_id
2824
+ FROM $catalog_product_entity cpe
2825
+ WHERE cpe.entity_id NOT IN
2826
+ (
2827
+ SELECT cpe2.entity_id
2828
+ FROM $catalog_product_entity cpe2
2829
+ JOIN $stINch_products sp
2830
+ ON cpe2.sinch_product_id = sp.sinch_product_id
2831
+ )");
2832
+
2833
+
2834
+ $result = $this->db_do("DELETE cpe FROM $catalog_product_entity cpe JOIN $stinch_products_delete spd USING(entity_id)");
2835
+
2836
+ $result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
2837
+
2838
+
2839
+
2840
+
2841
+
2842
+
2843
+ //echo("\n\nget out...\n\n");
2844
+ //return;
2845
+
2846
+ /**
2847
+
2848
+ echo("\n replaceMagentoProductsMultistoreMERGE 10\n");
2849
+
2850
+
2851
+ // TEMPORARY
2852
+ $this->db_do(" DROP TABLE IF EXISTS {$catalog_category_product}_for_delete_temp");
2853
+ $this->db_do("
2854
+ CREATE TABLE `{$catalog_category_product}_for_delete_temp`
2855
+ (
2856
+ `category_id` int(10) unsigned NOT NULL default '0',
2857
+ `product_id` int(10) unsigned NOT NULL default '0',
2858
+ `store_product_id` int(10) NOT NULL default '0',
2859
+ `store_category_id` int(10) NOT NULL default '0',
2860
+ `new_category_id` int(10) NOT NULL default '0',
2861
+
2862
+ UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
2863
+ KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
2864
+ KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
2865
+ KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
2866
+ )");
2867
+
2868
+ echo("\n replaceMagentoProductsMultistoreMERGE 11\n");
2869
+
2870
+ $result = $this->db_do("
2871
+ INSERT INTO {$catalog_category_product}_for_delete_temp
2872
+ (category_id, product_id, store_product_id)
2873
+ (SELECT
2874
+ ccp.category_id,
2875
+ ccp.product_id,
2876
+ cpe.store_product_id
2877
+ FROM $catalog_category_product ccp
2878
+ JOIN $catalog_product_entity cpe
2879
+ ON ccp.product_id = cpe.entity_id
2880
+ WHERE store_product_id IS NOT NULL)");
2881
+
2882
+ echo("\n replaceMagentoProductsMultistoreMERGE 12\n");
2883
+
2884
+ $result = $this->db_do("
2885
+ UPDATE {$catalog_category_product}_for_delete_temp ccpfd
2886
+ JOIN $products_temp p
2887
+ ON ccpfd.store_product_id = p.store_product_id
2888
+ SET ccpfd.store_category_id = p.store_category_id
2889
+ WHERE ccpfd.store_product_id != 0");
2890
+
2891
+ echo("\n replaceMagentoProductsMultistoreMERGE 13\n");
2892
+
2893
+ $result = $this->db_do("
2894
+ UPDATE {$catalog_category_product}_for_delete_temp ccpfd
2895
+ JOIN $stINch_categories_mapping scm
2896
+ ON ccpfd.store_category_id = scm.store_category_id
2897
+ SET ccpfd.new_category_id = scm.shop_entity_id
2898
+ WHERE ccpfd.store_category_id != 0");
2899
+
2900
+ echo("\n replaceMagentoProductsMultistoreMERGE 14\n");
2901
+
2902
+ $result = $this->db_do("DELETE FROM {$catalog_category_product}_for_delete_temp WHERE category_id = new_category_id");
2903
+
2904
+
2905
+
2906
+ $result = $this->db_do("
2907
+ DELETE ccp
2908
+ FROM $catalog_category_product ccp
2909
+ JOIN {$catalog_category_product}_for_delete_temp ccpfd
2910
+ ON ccp.product_id = ccpfd.product_id
2911
+ AND ccp.category_id = ccpfd.category_id");
2912
+
2913
+ /**/
2914
+
2915
+
2916
+
2917
+ echo("\n replaceMagentoProductsMultistoreMERGE 15\n");
2918
+
2919
+
2920
+
2921
+
2922
+ $result = $this->db_do("
2923
+ INSERT INTO $catalog_category_product
2924
+ (category_id, product_id)
2925
+ (SELECT
2926
+ scm.shop_entity_id,
2927
+ cpe.entity_id
2928
+ FROM $catalog_product_entity cpe
2929
+ JOIN $products_temp p
2930
+ ON cpe.store_product_id = p.store_product_id
2931
+ JOIN $stINch_categories_mapping scm
2932
+ ON p.store_category_id = scm.store_category_id
2933
+ )
2934
+ ON DUPLICATE KEY UPDATE
2935
+ product_id = cpe.entity_id");
2936
+
2937
+
2938
+
2939
+ echo("\n replaceMagentoProductsMultistoreMERGE 15.1 (add multi categories)\n");
2940
+
2941
+
2942
+
2943
+
2944
+ $result = $this->db_do("
2945
+ INSERT INTO $catalog_category_product
2946
+ (category_id, product_id)
2947
+ (SELECT
2948
+ scm.shop_entity_id,
2949
+ cpe.entity_id
2950
+ FROM $catalog_product_entity cpe
2951
+ JOIN $products_temp p
2952
+ ON cpe.store_product_id = p.store_product_id
2953
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
2954
+ ON p.store_product_id=spc.store_product_id
2955
+ JOIN $stINch_categories_mapping scm
2956
+ ON spc.store_category_id = scm.store_category_id
2957
+ )
2958
+ ON DUPLICATE KEY UPDATE
2959
+ product_id = cpe.entity_id
2960
+ ");
2961
+
2962
+
2963
+
2964
+ echo("\n replaceMagentoProductsMultistoreMERGE 16\n");
2965
+
2966
+ //Indexing products and categories in the shop
2967
+ $result = $this->db_do("
2968
+ DELETE ccpi
2969
+ FROM $catalog_category_product_index ccpi
2970
+ LEFT JOIN $catalog_product_entity cpe
2971
+ ON ccpi.product_id = cpe.entity_id
2972
+ WHERE cpe.entity_id IS NULL");
2973
+
2974
+
2975
+
2976
+
2977
+
2978
+ echo("\n replaceMagentoProductsMultistoreMERGE 16.2\n");
2979
+
2980
+
2981
+ $result = $this->db_do("
2982
+ INSERT INTO $catalog_category_product_index
2983
+ (category_id, product_id, position, is_parent, store_id, visibility)
2984
+ (SELECT
2985
+ a.category_id,
2986
+ a.product_id,
2987
+ a.position,
2988
+ 1,
2989
+ b.store_id,
2990
+ 4
2991
+ FROM $catalog_category_product a
2992
+ JOIN $core_store b
2993
+ )
2994
+ ON DUPLICATE KEY UPDATE
2995
+ visibility = 4");
2996
+
2997
+
2998
+
2999
+ echo("\n replaceMagentoProductsMultistoreMERGE 17\n");
3000
+ $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
3001
+ // !!! $this->_root_cat
3002
+ $result = $this->db_do("
3003
+ INSERT ignore INTO $catalog_category_product_index
3004
+ (category_id, product_id, position, is_parent, store_id, visibility)
3005
+ (SELECT
3006
+ rc.root_cat,
3007
+ a.product_id,
3008
+ a.position,
3009
+ 1,
3010
+ b.store_id,
3011
+ 4
3012
+ FROM $catalog_category_product a
3013
+ JOIN $root_cats rc
3014
+ ON a.category_id = rc.entity_id
3015
+ JOIN $core_store b
3016
+ )
3017
+ ON DUPLICATE KEY UPDATE
3018
+ visibility = 4");
3019
+
3020
+ echo("\n replaceMagentoProductsMultistoreMERGE 18\n");
3021
+
3022
+
3023
+ //Set product name for specific web sites
3024
+ $result = $this->db_do("
3025
+ DELETE cpev
3026
+ FROM $catalog_product_entity_varchar cpev
3027
+ LEFT JOIN $catalog_product_entity cpe
3028
+ ON cpev.entity_id = cpe.entity_id
3029
+ WHERE cpe.entity_id IS NULL");
3030
+
3031
+ $result = $this->db_do("
3032
+ INSERT INTO $catalog_product_entity_varchar
3033
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3034
+ (SELECT
3035
+ $_getProductEntityTypeId,
3036
+ $attr_name,
3037
+ w.website,
3038
+ a.entity_id,
3039
+ b.product_name
3040
+ FROM $catalog_product_entity a
3041
+ JOIN $products_temp b
3042
+ ON a.store_product_id = b.store_product_id
3043
+ JOIN $products_website_temp w
3044
+ ON a.store_product_id = w.store_product_id
3045
+ )
3046
+ ON DUPLICATE KEY UPDATE
3047
+ value = b.product_name");
3048
+
3049
+ echo("\n replaceMagentoProductsMultistoreMERGE 19\n");
3050
+
3051
+
3052
+
3053
+
3054
+
3055
+ // product name for all web sites
3056
+ $result = $this->db_do("
3057
+ INSERT INTO $catalog_product_entity_varchar
3058
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3059
+ (SELECT
3060
+ $_getProductEntityTypeId,
3061
+ $attr_name,
3062
+ 0,
3063
+ a.entity_id,
3064
+ b.product_name
3065
+ FROM $catalog_product_entity a
3066
+ JOIN $products_temp b
3067
+ ON a.store_product_id = b.store_product_id
3068
+ )
3069
+ ON DUPLICATE KEY UPDATE
3070
+ value = b.product_name");
3071
+
3072
+ echo("\n replaceMagentoProductsMultistoreMERGE 20\n");
3073
+
3074
+
3075
+
3076
+ $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
3077
+ $this->addDescriptions();
3078
+ $this->cleanProductDistributors();
3079
+ if($this->product_file_format == "NEW"){
3080
+ $this->addReviews();
3081
+ $this->addWeight();
3082
+ $this->addSearchCache();
3083
+ $this->addPdfUrl();
3084
+ $this->addShortDescriptions();
3085
+ $this->addProductDistributors();
3086
+ }
3087
+ $this->addEAN();
3088
+ $this->addSpecification();
3089
+ $this->addManufacturers();
3090
+
3091
+
3092
+
3093
+
3094
+
3095
+
3096
+
3097
+ echo("\n replaceMagentoProductsMultistoreMERGE 21\n");
3098
+
3099
+ //Enabling product index.
3100
+ $result = $this->db_do("
3101
+ DELETE cpei
3102
+ FROM $catalog_product_enabled_index cpei
3103
+ LEFT JOIN $catalog_product_entity cpe
3104
+ ON cpei.product_id = cpe.entity_id
3105
+ WHERE cpe.entity_id IS NULL");
3106
+
3107
+
3108
+
3109
+
3110
+
3111
+
3112
+ echo("\n replaceMagentoProductsMultistoreMERGE 22\n");
3113
+
3114
+ $result = $this->db_do("
3115
+ INSERT INTO $catalog_product_enabled_index
3116
+ (product_id, store_id, visibility)
3117
+ (SELECT
3118
+ a.entity_id,
3119
+ w.website,
3120
+ 4
3121
+ FROM $catalog_product_entity a
3122
+ JOIN $products_website_temp w
3123
+ ON a.store_product_id = w.store_product_id
3124
+ )
3125
+ ON DUPLICATE KEY UPDATE
3126
+ visibility = 4");
3127
+
3128
+ echo("\n replaceMagentoProductsMultistoreMERGE 23\n");
3129
+
3130
+ $result = $this->db_do("
3131
+ INSERT INTO $catalog_product_enabled_index
3132
+ (product_id, store_id, visibility)
3133
+ (SELECT
3134
+ a.entity_id,
3135
+ 0,
3136
+ 4
3137
+ FROM $catalog_product_entity a
3138
+ JOIN $products_website_temp w
3139
+ ON a.store_product_id = w.store_product_id
3140
+ )
3141
+ ON DUPLICATE KEY UPDATE
3142
+ visibility = 4");
3143
+
3144
+
3145
+ /////////////////////////////////////echo(" .... DONE\n");return;
3146
+
3147
+
3148
+ echo("\n replaceMagentoProductsMultistoreMERGE 24\n");
3149
+
3150
+ $result = $this->db_do("
3151
+ INSERT INTO $catalog_product_entity_int
3152
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3153
+ (SELECT
3154
+ $_getProductEntityTypeId,
3155
+ $attr_visibility,
3156
+ w.website,
3157
+ a.entity_id,
3158
+ 4
3159
+ FROM $catalog_product_entity a
3160
+ JOIN $products_website_temp w
3161
+ ON a.store_product_id = w.store_product_id
3162
+ )
3163
+ ON DUPLICATE KEY UPDATE
3164
+ value = 4");
3165
+
3166
+ echo("\n replaceMagentoProductsMultistoreMERGE 25\n");
3167
+
3168
+ $result = $this->db_do("
3169
+ INSERT INTO $catalog_product_entity_int
3170
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3171
+ (SELECT
3172
+ $_getProductEntityTypeId,
3173
+ $attr_visibility,
3174
+ 0,
3175
+ a.entity_id,
3176
+ 4
3177
+ FROM $catalog_product_entity a
3178
+ )
3179
+ ON DUPLICATE KEY UPDATE
3180
+ value = 4");
3181
+
3182
+ echo("\n replaceMagentoProductsMultistoreMERGE 26\n");
3183
+
3184
+
3185
+
3186
+ $result = $this->db_do("
3187
+ DELETE cpw
3188
+ FROM $catalog_product_website cpw
3189
+ LEFT JOIN $catalog_product_entity cpe
3190
+ ON cpw.product_id = cpe.entity_id
3191
+ WHERE cpe.entity_id IS NULL");
3192
+
3193
+ echo("\n replaceMagentoProductsMultistoreMERGE 27\n");
3194
+
3195
+
3196
+
3197
+
3198
+
3199
+
3200
+
3201
+
3202
+
3203
+
3204
+
3205
+ $result = $this->db_do("
3206
+ INSERT INTO $catalog_product_website
3207
+ (product_id, website_id)
3208
+ (SELECT
3209
+ a.entity_id,
3210
+ w.website_id
3211
+ FROM $catalog_product_entity a
3212
+ JOIN $products_website_temp w
3213
+ ON a.store_product_id = w.store_product_id
3214
+ )
3215
+ ON DUPLICATE KEY UPDATE
3216
+ product_id = a.entity_id,
3217
+ website_id = w.website_id");
3218
+
3219
+
3220
+ //echo(" .... DONE\n");return;
3221
+
3222
+
3223
+ echo("\n replaceMagentoProductsMultistoreMERGE 28\n");
3224
+
3225
+ // temporary disabled mart@bintime.com
3226
+ //$result = $this->db_do("
3227
+ // UPDATE catalog_category_entity_int a
3228
+ // SET a.value = 0
3229
+ // WHERE a.attribute_id = 32
3230
+ //");
3231
+
3232
+
3233
+ //Adding tax class "Taxable Goods"
3234
+ $result = $this->db_do("
3235
+ INSERT INTO $catalog_product_entity_int
3236
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3237
+ (SELECT
3238
+ $_getProductEntityTypeId,
3239
+ $attr_tax_class_id,
3240
+ w.website,
3241
+ a.entity_id,
3242
+ 2
3243
+ FROM $catalog_product_entity a
3244
+ JOIN $products_website_temp w
3245
+ ON a.store_product_id = w.store_product_id
3246
+ )
3247
+ ON DUPLICATE KEY UPDATE
3248
+ value = 2");
3249
+
3250
+ echo("\n replaceMagentoProductsMultistoreMERGE 29\n");
3251
+
3252
+ $result = $this->db_do("
3253
+ INSERT INTO $catalog_product_entity_int
3254
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3255
+ (SELECT
3256
+ $_getProductEntityTypeId,
3257
+ $attr_tax_class_id,
3258
+ 0,
3259
+ a.entity_id,
3260
+ 2
3261
+ FROM $catalog_product_entity a
3262
+ )
3263
+ ON DUPLICATE KEY UPDATE
3264
+ value = 2");
3265
+
3266
+ echo("\n replaceMagentoProductsMultistoreMERGE 30\n");
3267
+
3268
+ // Load url Image
3269
+ $result = $this->db_do("
3270
+ INSERT INTO $catalog_product_entity_varchar
3271
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3272
+ (SELECT
3273
+ $_getProductEntityTypeId,
3274
+ $attr_image,
3275
+ w.store_id,
3276
+ a.entity_id,
3277
+ b.main_image_url
3278
+ FROM $catalog_product_entity a
3279
+ JOIN $core_store w
3280
+ JOIN $products_temp b
3281
+ ON a.store_product_id = b.store_product_id
3282
+ )
3283
+ ON DUPLICATE KEY UPDATE
3284
+ value = b.main_image_url");
3285
+
3286
+ echo("\n replaceMagentoProductsMultistoreMERGE 31\n");
3287
+
3288
+ // image for specific web sites
3289
+ $result = $this->db_do("
3290
+ INSERT INTO $catalog_product_entity_varchar
3291
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3292
+ (SELECT
3293
+ $_getProductEntityTypeId,
3294
+ $attr_image,
3295
+ 0,
3296
+ a.entity_id,
3297
+ b.main_image_url
3298
+ FROM $catalog_product_entity a
3299
+ JOIN $products_temp b
3300
+ ON a.store_product_id = b.store_product_id
3301
+ )
3302
+ ON DUPLICATE KEY UPDATE
3303
+ value = b.main_image_url");
3304
+
3305
+ echo("\n replaceMagentoProductsMultistoreMERGE 32\n");
3306
+
3307
+ // small_image for specific web sites
3308
+ $result = $this->db_do("
3309
+ INSERT INTO $catalog_product_entity_varchar
3310
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3311
+ (SELECT
3312
+ $_getProductEntityTypeId,
3313
+ $attr_small_image,
3314
+ w.store_id,
3315
+ a.entity_id,
3316
+ b.medium_image_url
3317
+ FROM $catalog_product_entity a
3318
+ JOIN $core_store w
3319
+ JOIN $products_temp b
3320
+ ON a.store_product_id = b.store_product_id
3321
+ )
3322
+ ON DUPLICATE KEY UPDATE
3323
+ value = b.medium_image_url");
3324
+
3325
+ echo("\n replaceMagentoProductsMultistoreMERGE 33\n");
3326
+
3327
+ // small_image for all web sites
3328
+ $result = $this->db_do("
3329
+ INSERT INTO $catalog_product_entity_varchar
3330
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3331
+ (SELECT
3332
+ $_getProductEntityTypeId,
3333
+ $attr_small_image,
3334
+ 0,
3335
+ a.entity_id,
3336
+ b.medium_image_url
3337
+ FROM $catalog_product_entity a
3338
+ JOIN $core_store w
3339
+ JOIN $products_temp b
3340
+ ON a.store_product_id = b.store_product_id
3341
+ )
3342
+ ON DUPLICATE KEY UPDATE
3343
+ value = b.medium_image_url");
3344
+
3345
+ echo("\n replaceMagentoProductsMultistoreMERGE 34\n");
3346
+
3347
+ // thumbnail for specific web site
3348
+ $result = $this->db_do("
3349
+ INSERT INTO $catalog_product_entity_varchar
3350
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3351
+ (SELECT
3352
+ $_getProductEntityTypeId,
3353
+ $attr_thumbnail,
3354
+ w.store_id,
3355
+ a.entity_id,
3356
+ b.thumb_image_url
3357
+ FROM $catalog_product_entity a
3358
+ JOIN $core_store w
3359
+ JOIN $products_temp b
3360
+ ON a.store_product_id = b.store_product_id
3361
+ )
3362
+ ON DUPLICATE KEY UPDATE
3363
+ value = b.thumb_image_url");
3364
+
3365
+ echo("\n replaceMagentoProductsMultistoreMERGE 35\n");
3366
+
3367
+ // thumbnail for all web sites
3368
+ $result = $this->db_do("
3369
+ INSERT INTO $catalog_product_entity_varchar
3370
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3371
+ (SELECT
3372
+ $_getProductEntityTypeId,
3373
+ $attr_thumbnail,
3374
+ 0,
3375
+ a.entity_id,
3376
+ b.thumb_image_url
3377
+ FROM $catalog_product_entity a
3378
+ JOIN $core_store w
3379
+ JOIN $products_temp b
3380
+ ON a.store_product_id = b.store_product_id
3381
+ )
3382
+ ON DUPLICATE KEY UPDATE
3383
+ value = b.thumb_image_url");
3384
+
3385
+ echo("\n replaceMagentoProductsMultistoreMERGE 36\n");
3386
+
3387
+
3388
+
3389
+
3390
+
3391
+ /* STP DELETE
3392
+ //Refresh fulltext search
3393
+ $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
3394
+ $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
3395
+
3396
+
3397
+ echo("\n replaceMagentoProductsMultistoreMERGE 36.2\n");
3398
+ $q = "
3399
+ INSERT INTO {$catalogsearch_fulltext}_tmp
3400
+ (product_id, store_id, data_index)
3401
+ (SELECT
3402
+ a.entity_id,
3403
+ w.website,
3404
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3405
+ FROM $catalog_product_entity a
3406
+ JOIN $products_website_temp w
3407
+ ON a.store_product_id = w.store_product_id
3408
+ LEFT JOIN $catalog_category_product b
3409
+ ON a.entity_id = b.product_id
3410
+ LEFT JOIN $catalog_category_entity_varchar c
3411
+ ON b.category_id = c.entity_id
3412
+ AND c.attribute_id = $cat_attr_name
3413
+ LEFT JOIN $catalog_product_entity_varchar e
3414
+ ON a.entity_id = e.entity_id
3415
+ AND e.attribute_id = $attr_name
3416
+ LEFT JOIN $catalog_product_website j
3417
+ ON a.entity_id = j.product_id
3418
+ LEFT JOIN $products_temp f
3419
+ ON a.store_product_id = f.store_product_id
3420
+ )
3421
+ ON DUPLICATE KEY UPDATE
3422
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
3423
+ echo("\n\n============================\n$q\n============================\n\n");
3424
+
3425
+
3426
+ $result = $this->db_do("
3427
+ INSERT INTO {$catalogsearch_fulltext}_tmp
3428
+ (product_id, store_id, data_index)
3429
+ (SELECT
3430
+ a.entity_id,
3431
+ w.website,
3432
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3433
+ FROM $catalog_product_entity a
3434
+ JOIN $products_website_temp w
3435
+ ON a.store_product_id = w.store_product_id
3436
+ LEFT JOIN $catalog_category_product b
3437
+ ON a.entity_id = b.product_id
3438
+ LEFT JOIN $catalog_category_entity_varchar c
3439
+ ON b.category_id = c.entity_id
3440
+ AND c.attribute_id = $cat_attr_name
3441
+ LEFT JOIN $catalog_product_entity_varchar e
3442
+ ON a.entity_id = e.entity_id
3443
+ AND e.attribute_id = $attr_name
3444
+ LEFT JOIN $catalog_product_website j
3445
+ ON a.entity_id = j.product_id
3446
+ LEFT JOIN $products_temp f
3447
+ ON a.store_product_id = f.store_product_id
3448
+ )
3449
+ ON DUPLICATE KEY UPDATE
3450
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
3451
+
3452
+ echo("\n replaceMagentoProductsMultistoreMERGE 37\n");
3453
+
3454
+
3455
+ $result = $this->db_do("
3456
+ INSERT INTO {$catalogsearch_fulltext}_tmp
3457
+ (product_id, store_id, data_index)
3458
+ (SELECT
3459
+ a.entity_id,
3460
+ w.website,
3461
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3462
+ FROM $catalog_product_entity a
3463
+ JOIN $products_website_temp w
3464
+ ON a.store_product_id = w.store_product_id
3465
+ LEFT JOIN $catalog_category_product b
3466
+ ON a.entity_id = b.product_id
3467
+ LEFT JOIN $catalog_category_entity_varchar c
3468
+ ON b.category_id = c.entity_id
3469
+ AND c.attribute_id = $cat_attr_name
3470
+ LEFT JOIN $catalog_product_entity_varchar e
3471
+ ON a.entity_id = e.entity_id
3472
+ AND e.attribute_id = $attr_name
3473
+ LEFT JOIN $products_temp f
3474
+ ON a.store_product_id = f.store_product_id
3475
+ )
3476
+ ON DUPLICATE KEY UPDATE
3477
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
3478
+
3479
+ echo("\n replaceMagentoProductsMultistoreMERGE 38\n");
3480
+
3481
+ $result = $this->db_do("
3482
+ DELETE cf
3483
+ FROM $catalogsearch_fulltext cf
3484
+ LEFT JOIN $catalog_product_entity cpe
3485
+ ON cf.product_id = cpe.entity_id
3486
+ WHERE cpe.entity_id IS NULL");
3487
+
3488
+ echo("\n replaceMagentoProductsMultistoreMERGE 39\n");
3489
+
3490
+ $result = $this->db_do("
3491
+ INSERT INTO $catalogsearch_fulltext
3492
+ (product_id, store_id, data_index)
3493
+ (SELECT
3494
+ a.product_id,
3495
+ a.store_id,
3496
+ a.data_index
3497
+ FROM {$catalogsearch_fulltext}_tmp a
3498
+ )
3499
+ ON DUPLICATE KEY UPDATE
3500
+ data_index = a.data_index");
3501
+
3502
+ echo("\n replaceMagentoProductsMultistoreMERGE 40\n");
3503
+
3504
+ $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
3505
+ //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
3506
+ //TODO add something else
3507
+ STP DELETE*/
3508
+
3509
+ $this->addRelatedProducts();
3510
+ echo("\n replaceMagentoProductsMultistoreMERGE 41\n");
3511
+ } //
3512
+ ################################################################################################################################################################
3513
+
3514
+
3515
+
3516
+
3517
+
3518
+
3519
+
3520
+
3521
+
3522
+
3523
+
3524
+
3525
+
3526
+
3527
+
3528
+
3529
+
3530
+
3531
+
3532
+
3533
+
3534
+
3535
+
3536
+
3537
+
3538
+
3539
+
3540
+
3541
+ ################################################################################################################################################################
3542
+ public function replaceMagentoProductsMultistore($coincidence)
3543
+ {
3544
+
3545
+ echo("\n replaceMagentoProductsMultistore 1\n");
3546
+
3547
+
3548
+
3549
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
3550
+
3551
+
3552
+ $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
3553
+ $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
3554
+ $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
3555
+ $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
3556
+ $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
3557
+ $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
3558
+ $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
3559
+ $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
3560
+ $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
3561
+ $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
3562
+ $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
3563
+ $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
3564
+ $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
3565
+ //STP DELETE $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
3566
+ // $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
3567
+ $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
3568
+
3569
+ $_getProductEntityTypeId = $this->_getProductEntityTypeId();
3570
+ $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
3571
+
3572
+ $attr_atatus = $this->_getProductAttributeId('status');
3573
+ $attr_name = $this->_getProductAttributeId('name');
3574
+ $attr_visibility = $this->_getProductAttributeId('visibility');
3575
+ $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
3576
+ $attr_image = $this->_getProductAttributeId('image');
3577
+ $attr_small_image = $this->_getProductAttributeId('small_image');
3578
+ $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
3579
+
3580
+ $cat_attr_name = $this->_getCategoryAttributeId('name');
3581
+ echo("\n replaceMagentoProductsMultistore 2\n");
3582
+
3583
+
3584
+
3585
+
3586
+
3587
+ //clear products, inserting new products and updating old others.
3588
+ $query = "
3589
+ DELETE cpe
3590
+ FROM $catalog_product_entity cpe
3591
+ JOIN $stINch_products_mapping pm
3592
+ ON cpe.entity_id = pm.entity_id
3593
+ WHERE pm.shop_store_product_id IS NOT NULL
3594
+ AND pm.store_product_id IS NULL";
3595
+ $result = $this->db_do($query);
3596
+
3597
+
3598
+
3599
+
3600
+
3601
+ echo("\n replaceMagentoProductsMultistore 3\n");
3602
+
3603
+ $result = $this->db_do("
3604
+ INSERT INTO $catalog_product_entity
3605
+ (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
3606
+ (SELECT
3607
+ pm.entity_id,
3608
+ $_getProductEntityTypeId,
3609
+ $_defaultAttributeSetId,
3610
+ 'simple',
3611
+ a.product_sku,
3612
+ NOW(),
3613
+ 0,
3614
+ a.store_product_id,
3615
+ a.sinch_product_id
3616
+ FROM $products_temp a
3617
+ LEFT JOIN $stINch_products_mapping pm
3618
+ ON a.store_product_id = pm.store_product_id
3619
+ AND a.sinch_product_id = pm.sinch_product_id
3620
+ WHERE pm.entity_id IS NULL
3621
+ )
3622
+ ON DUPLICATE KEY UPDATE
3623
+ sku = a.product_sku,
3624
+ store_product_id = a.store_product_id,
3625
+ sinch_product_id = a.sinch_product_id");
3626
+ // store_product_id = a.store_product_id,
3627
+ // sinch_product_id = a.sinch_product_id
3628
+
3629
+ $result = $this->db_do("
3630
+ INSERT INTO $catalog_product_entity
3631
+ (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
3632
+ (SELECT
3633
+ pm.entity_id,
3634
+ $_getProductEntityTypeId,
3635
+ $_defaultAttributeSetId,
3636
+ 'simple',
3637
+ a.product_sku,
3638
+ NOW(),
3639
+ 0,
3640
+ a.store_product_id,
3641
+ a.sinch_product_id
3642
+ FROM $products_temp a
3643
+ LEFT JOIN $stINch_products_mapping pm
3644
+ ON a.store_product_id = pm.store_product_id
3645
+ AND a.sinch_product_id = pm.sinch_product_id
3646
+ WHERE pm.entity_id IS NOT NULL
3647
+ )
3648
+ ON DUPLICATE KEY UPDATE
3649
+ sku = a.product_sku,
3650
+ store_product_id = a.store_product_id,
3651
+ sinch_product_id = a.sinch_product_id");
3652
+ // store_product_id = a.store_product_id,
3653
+ // sinch_product_id = a.sinch_product_id
3654
+
3655
+ echo("\n replaceMagentoProductsMultistore 4\n");
3656
+
3657
+
3658
+
3659
+
3660
+
3661
+ //Set enabled
3662
+ $result = $this->db_do("
3663
+ DELETE cpei
3664
+ FROM $catalog_product_entity_int cpei
3665
+ LEFT JOIN $catalog_product_entity cpe
3666
+ ON cpei.entity_id = cpe.entity_id
3667
+ WHERE cpe.entity_id IS NULL");
3668
+
3669
+ $result = $this->db_do("
3670
+ INSERT INTO $catalog_product_entity_int
3671
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3672
+ (SELECT
3673
+ $_getProductEntityTypeId,
3674
+ $attr_atatus,
3675
+ w.website,
3676
+ a.entity_id,
3677
+ 1
3678
+ FROM $catalog_product_entity a
3679
+ JOIN $products_website_temp w
3680
+ ON a.store_product_id = w.store_product_id
3681
+ )
3682
+ ON DUPLICATE KEY UPDATE
3683
+ value = 1");
3684
+
3685
+
3686
+
3687
+
3688
+
3689
+ echo("\n replaceMagentoProductsMultistore 5\n");
3690
+
3691
+
3692
+ // set status = 1 for all stores
3693
+ $result = $this->db_do("
3694
+ INSERT INTO $catalog_product_entity_int
3695
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3696
+ (SELECT
3697
+ $_getProductEntityTypeId,
3698
+ $attr_atatus,
3699
+ 0,
3700
+ a.entity_id,
3701
+ 1
3702
+ FROM $catalog_product_entity a
3703
+ )
3704
+ ON DUPLICATE KEY UPDATE
3705
+ value = 1");
3706
+
3707
+
3708
+
3709
+
3710
+
3711
+ echo("\n replaceMagentoProductsMultistore 6\n");
3712
+
3713
+
3714
+ //Unifying products with categories.
3715
+ $result = $this->db_do("
3716
+ DELETE ccp
3717
+ FROM $catalog_category_product ccp
3718
+ LEFT JOIN $catalog_product_entity cpe
3719
+ ON ccp.product_id = cpe.entity_id
3720
+ WHERE cpe.entity_id IS NULL");
3721
+
3722
+
3723
+
3724
+
3725
+
3726
+
3727
+
3728
+ echo("\n replaceMagentoProductsMultistore 7\n");
3729
+
3730
+
3731
+
3732
+ $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
3733
+
3734
+
3735
+ $result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
3736
+ $result = $this->db_do("
3737
+ CREATE TABLE $root_cats
3738
+ SELECT
3739
+ entity_id,
3740
+ path,
3741
+ SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
3742
+ LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
3743
+ SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
3744
+ FROM $catalog_category_entity
3745
+ ");
3746
+ $result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
3747
+
3748
+
3749
+ echo("\n replaceMagentoProductsMultistore 8\n");
3750
+
3751
+
3752
+ // !!! $this->_root_cat
3753
+ $result = $this->db_do("
3754
+ UPDATE IGNORE $catalog_category_product ccp
3755
+ LEFT JOIN $catalog_category_entity cce
3756
+ ON ccp.category_id = cce.entity_id
3757
+ JOIN $root_cats rc
3758
+ ON cce.entity_id = rc.entity_id
3759
+ SET ccp.category_id = rc.root_cat
3760
+ WHERE cce.entity_id IS NULL");
3761
+
3762
+
3763
+
3764
+ echo("\n replaceMagentoProductsMultistore 9\n");
3765
+
3766
+
3767
+
3768
+
3769
+
3770
+ $result = $this->db_do("
3771
+ DELETE ccp
3772
+ FROM $catalog_category_product ccp
3773
+ LEFT JOIN $catalog_category_entity cce
3774
+ ON ccp.category_id = cce.entity_id
3775
+ WHERE cce.entity_id IS NULL");
3776
+
3777
+
3778
+ //echo("\n\nget out...\n\n");
3779
+ //return;
3780
+
3781
+
3782
+
3783
+
3784
+
3785
+ echo("\n replaceMagentoProductsMultistore 10\n");
3786
+
3787
+
3788
+ $catalog_category_product_for_delete_temp = $catalog_category_product."_for_delete_temp";
3789
+
3790
+ // TEMPORARY
3791
+ $this->db_do(" DROP TABLE IF EXISTS $catalog_category_product_for_delete_temp");
3792
+ $this->db_do("
3793
+ CREATE TABLE $catalog_category_product_for_delete_temp
3794
+ (
3795
+ `category_id` int(10) unsigned NOT NULL default '0',
3796
+ `product_id` int(10) unsigned NOT NULL default '0',
3797
+ `store_product_id` int(10) NOT NULL default '0',
3798
+ `store_category_id` int(10) NOT NULL default '0',
3799
+ `new_category_id` int(10) NOT NULL default '0',
3800
+
3801
+ UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
3802
+ KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
3803
+ KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
3804
+ KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
3805
+ )");
3806
+
3807
+ echo("\n replaceMagentoProductsMultistore 11\n");
3808
+
3809
+ $result = $this->db_do("
3810
+ INSERT INTO $catalog_category_product_for_delete_temp
3811
+ (category_id, product_id, store_product_id)
3812
+ (SELECT
3813
+ ccp.category_id,
3814
+ ccp.product_id,
3815
+ cpe.store_product_id
3816
+ FROM $catalog_category_product ccp
3817
+ JOIN $catalog_product_entity cpe
3818
+ ON ccp.product_id = cpe.entity_id
3819
+ WHERE store_product_id IS NOT NULL)");
3820
+
3821
+ echo("\n replaceMagentoProductsMultistore 12\n");
3822
+
3823
+ $result = $this->db_do("
3824
+ UPDATE $catalog_category_product_for_delete_temp ccpfd
3825
+ JOIN $products_temp p
3826
+ ON ccpfd.store_product_id = p.store_product_id
3827
+ SET ccpfd.store_category_id = p.store_category_id
3828
+ WHERE ccpfd.store_product_id != 0");
3829
+
3830
+ echo("\n replaceMagentoProductsMultistore 13\n");
3831
+
3832
+ $result = $this->db_do("
3833
+ UPDATE $catalog_category_product_for_delete_temp ccpfd
3834
+ JOIN $stINch_categories_mapping scm
3835
+ ON ccpfd.store_category_id = scm.store_category_id
3836
+ SET ccpfd.new_category_id = scm.shop_entity_id
3837
+ WHERE ccpfd.store_category_id != 0");
3838
+
3839
+ echo("\n replaceMagentoProductsMultistore 14\n");
3840
+
3841
+ $result = $this->db_do("DELETE FROM $catalog_category_product_for_delete_temp WHERE category_id = new_category_id");
3842
+
3843
+
3844
+
3845
+ $result = $this->db_do("
3846
+ DELETE ccp
3847
+ FROM $catalog_category_product ccp
3848
+ JOIN $catalog_category_product_for_delete_temp ccpfd
3849
+ ON ccp.product_id = ccpfd.product_id
3850
+ AND ccp.category_id = ccpfd.category_id");
3851
+
3852
+
3853
+ //echo("\n\nget out...\n\n");
3854
+ //return;
3855
+
3856
+
3857
+ echo("\n replaceMagentoProductsMultistore 15\n");
3858
+
3859
+ $result = $this->db_do("
3860
+ INSERT INTO $catalog_category_product
3861
+ (category_id, product_id)
3862
+ (SELECT
3863
+ scm.shop_entity_id,
3864
+ cpe.entity_id
3865
+ FROM $catalog_product_entity cpe
3866
+ JOIN $products_temp p
3867
+ ON cpe.store_product_id = p.store_product_id
3868
+ JOIN $stINch_categories_mapping scm
3869
+ ON p.store_category_id = scm.store_category_id
3870
+ )
3871
+ ON DUPLICATE KEY UPDATE
3872
+ product_id = cpe.entity_id");
3873
+
3874
+
3875
+ echo("\n replaceMagentoProductsMultistore 15.1 (add multi categories)\n");
3876
+
3877
+ $result = $this->db_do("
3878
+ INSERT INTO $catalog_category_product
3879
+ (category_id, product_id)
3880
+ (SELECT
3881
+ scm.shop_entity_id,
3882
+ cpe.entity_id
3883
+ FROM $catalog_product_entity cpe
3884
+ JOIN $products_temp p
3885
+ ON cpe.store_product_id = p.store_product_id
3886
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
3887
+ ON p.store_product_id=spc.store_product_id
3888
+ JOIN $stINch_categories_mapping scm
3889
+ ON spc.store_category_id = scm.store_category_id
3890
+ )
3891
+ ON DUPLICATE KEY UPDATE
3892
+ product_id = cpe.entity_id
3893
+ ");
3894
+
3895
+
3896
+
3897
+
3898
+ echo("\n replaceMagentoProductsMultistore 16\n");
3899
+
3900
+ //Indexing products and categories in the shop
3901
+ $result = $this->db_do("
3902
+ DELETE ccpi
3903
+ FROM $catalog_category_product_index ccpi
3904
+ LEFT JOIN $catalog_product_entity cpe
3905
+ ON ccpi.product_id = cpe.entity_id
3906
+ WHERE cpe.entity_id IS NULL");
3907
+
3908
+
3909
+
3910
+ echo("\n replaceMagentoProductsMultistore 16.2\n");
3911
+
3912
+
3913
+ $result = $this->db_do("
3914
+ INSERT INTO $catalog_category_product_index
3915
+ (category_id, product_id, position, is_parent, store_id, visibility)
3916
+ (SELECT
3917
+ a.category_id,
3918
+ a.product_id,
3919
+ a.position,
3920
+ 1,
3921
+ b.store_id,
3922
+ 4
3923
+ FROM $catalog_category_product a
3924
+ JOIN $core_store b
3925
+ )
3926
+ ON DUPLICATE KEY UPDATE
3927
+ visibility = 4");
3928
+
3929
+
3930
+
3931
+ echo("\n replaceMagentoProductsMultistore 17\n");
3932
+
3933
+ // !!! $this->_root_cat
3934
+ $result = $this->db_do("
3935
+ INSERT ignore INTO $catalog_category_product_index
3936
+ (category_id, product_id, position, is_parent, store_id, visibility)
3937
+ (SELECT
3938
+ rc.root_cat,
3939
+ a.product_id,
3940
+ a.position,
3941
+ 1,
3942
+ b.store_id,
3943
+ 4
3944
+ FROM $catalog_category_product a
3945
+ JOIN $root_cats rc
3946
+ ON a.category_id = rc.entity_id
3947
+ JOIN $core_store b
3948
+ )
3949
+ ON DUPLICATE KEY UPDATE
3950
+ visibility = 4");
3951
+
3952
+ echo("\n replaceMagentoProductsMultistore 18\n");
3953
+
3954
+
3955
+ //Set product name for specific web sites
3956
+ $result = $this->db_do("
3957
+ DELETE cpev
3958
+ FROM $catalog_product_entity_varchar cpev
3959
+ LEFT JOIN $catalog_product_entity cpe
3960
+ ON cpev.entity_id = cpe.entity_id
3961
+ WHERE cpe.entity_id IS NULL");
3962
+
3963
+ $result = $this->db_do("
3964
+ INSERT INTO $catalog_product_entity_varchar
3965
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3966
+ (SELECT
3967
+ $_getProductEntityTypeId,
3968
+ $attr_name,
3969
+ w.website,
3970
+ a.entity_id,
3971
+ b.product_name
3972
+ FROM $catalog_product_entity a
3973
+ JOIN $products_temp b
3974
+ ON a.store_product_id = b.store_product_id
3975
+ JOIN $products_website_temp w
3976
+ ON a.store_product_id = w.store_product_id
3977
+ )
3978
+ ON DUPLICATE KEY UPDATE
3979
+ value = b.product_name");
3980
+
3981
+ echo("\n replaceMagentoProductsMultistore 19\n");
3982
+
3983
+
3984
+ // product name for all web sites
3985
+ $result = $this->db_do("
3986
+ INSERT INTO $catalog_product_entity_varchar
3987
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3988
+ (SELECT
3989
+ $_getProductEntityTypeId,
3990
+ $attr_name,
3991
+ 0,
3992
+ a.entity_id,
3993
+ b.product_name
3994
+ FROM $catalog_product_entity a
3995
+ JOIN $products_temp b
3996
+ ON a.store_product_id = b.store_product_id
3997
+ )
3998
+ ON DUPLICATE KEY UPDATE
3999
+ value = b.product_name");
4000
+
4001
+ echo("\n replaceMagentoProductsMultistore 20\n");
4002
+
4003
+
4004
+
4005
+ $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
4006
+ $this->addDescriptions();
4007
+ $this->cleanProductDistributors();
4008
+ if($this->product_file_format == "NEW"){
4009
+ $this->addReviews();
4010
+ $this->addWeight();
4011
+ $this->addSearchCache();
4012
+ $this->addPdfUrl();
4013
+ $this->addShortDescriptions();
4014
+ $this->addProductDistributors();
4015
+ }
4016
+ $this->addEAN();
4017
+ $this->addSpecification();
4018
+ $this->addManufacturers();
4019
+
4020
+ //echo(" .... DONE\n");return;
4021
+
4022
+ echo("\n replaceMagentoProductsMultistore 21\n");
4023
+
4024
+ //Enabling product index.
4025
+ $result = $this->db_do("
4026
+ DELETE cpei
4027
+ FROM $catalog_product_enabled_index cpei
4028
+ LEFT JOIN $catalog_product_entity cpe
4029
+ ON cpei.product_id = cpe.entity_id
4030
+ WHERE cpe.entity_id IS NULL");
4031
+
4032
+ echo("\n replaceMagentoProductsMultistore 22\n");
4033
+
4034
+ $result = $this->db_do("
4035
+ INSERT INTO $catalog_product_enabled_index
4036
+ (product_id, store_id, visibility)
4037
+ (SELECT
4038
+ a.entity_id,
4039
+ w.website,
4040
+ 4
4041
+ FROM $catalog_product_entity a
4042
+ JOIN $products_website_temp w
4043
+ ON a.store_product_id = w.store_product_id
4044
+ )
4045
+ ON DUPLICATE KEY UPDATE
4046
+ visibility = 4");
4047
+
4048
+ echo("\n replaceMagentoProductsMultistore 23\n");
4049
+
4050
+ $result = $this->db_do("
4051
+ INSERT INTO $catalog_product_enabled_index
4052
+ (product_id, store_id, visibility)
4053
+ (SELECT
4054
+ a.entity_id,
4055
+ 0,
4056
+ 4
4057
+ FROM $catalog_product_entity a
4058
+ JOIN $products_website_temp w
4059
+ ON a.store_product_id = w.store_product_id
4060
+ )
4061
+ ON DUPLICATE KEY UPDATE
4062
+ visibility = 4");
4063
+
4064
+
4065
+ /////////////////////////////////////echo(" .... DONE\n");return;
4066
+
4067
+
4068
+ echo("\n replaceMagentoProductsMultistore 24\n");
4069
+
4070
+ $result = $this->db_do("
4071
+ INSERT INTO $catalog_product_entity_int
4072
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4073
+ (SELECT
4074
+ $_getProductEntityTypeId,
4075
+ $attr_visibility,
4076
+ w.website,
4077
+ a.entity_id,
4078
+ 4
4079
+ FROM $catalog_product_entity a
4080
+ JOIN $products_website_temp w
4081
+ ON a.store_product_id = w.store_product_id
4082
+ )
4083
+ ON DUPLICATE KEY UPDATE
4084
+ value = 4");
4085
+
4086
+ echo("\n replaceMagentoProductsMultistore 25\n");
4087
+
4088
+ $result = $this->db_do("
4089
+ INSERT INTO $catalog_product_entity_int
4090
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4091
+ (SELECT
4092
+ $_getProductEntityTypeId,
4093
+ $attr_visibility,
4094
+ 0,
4095
+ a.entity_id,
4096
+ 4
4097
+ FROM $catalog_product_entity a
4098
+ )
4099
+ ON DUPLICATE KEY UPDATE
4100
+ value = 4");
4101
+
4102
+ echo("\n replaceMagentoProductsMultistore 26\n");
4103
+
4104
+ $result = $this->db_do("
4105
+ DELETE cpw
4106
+ FROM $catalog_product_website cpw
4107
+ LEFT JOIN $catalog_product_entity cpe
4108
+ ON cpw.product_id = cpe.entity_id
4109
+ WHERE cpe.entity_id IS NULL");
4110
+
4111
+ echo("\n replaceMagentoProductsMultistore 27\n");
4112
+
4113
+ $result = $this->db_do("
4114
+ INSERT INTO $catalog_product_website
4115
+ (product_id, website_id)
4116
+ (SELECT
4117
+ a.entity_id,
4118
+ w.website_id
4119
+ FROM $catalog_product_entity a
4120
+ JOIN $products_website_temp w
4121
+ ON a.store_product_id = w.store_product_id
4122
+ )
4123
+ ON DUPLICATE KEY UPDATE
4124
+ product_id = a.entity_id,
4125
+ website_id = w.website_id");
4126
+
4127
+
4128
+ //echo(" .... DONE\n");return;
4129
+
4130
+
4131
+ echo("\n replaceMagentoProductsMultistore 28\n");
4132
+
4133
+ // temporary disabled mart@bintime.com
4134
+ //$result = $this->db_do("
4135
+ // UPDATE catalog_category_entity_int a
4136
+ // SET a.value = 0
4137
+ // WHERE a.attribute_id = 32
4138
+ //");
4139
+
4140
+
4141
+ //Adding tax class "Taxable Goods"
4142
+ $result = $this->db_do("
4143
+ INSERT INTO $catalog_product_entity_int
4144
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4145
+ (SELECT
4146
+ $_getProductEntityTypeId,
4147
+ $attr_tax_class_id,
4148
+ w.website,
4149
+ a.entity_id,
4150
+ 2
4151
+ FROM $catalog_product_entity a
4152
+ JOIN $products_website_temp w
4153
+ ON a.store_product_id = w.store_product_id
4154
+ )
4155
+ ON DUPLICATE KEY UPDATE
4156
+ value = 2");
4157
+
4158
+ echo("\n replaceMagentoProductsMultistore 29\n");
4159
+
4160
+ $result = $this->db_do("
4161
+ INSERT INTO $catalog_product_entity_int
4162
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4163
+ (SELECT
4164
+ $_getProductEntityTypeId,
4165
+ $attr_tax_class_id,
4166
+ 0,
4167
+ a.entity_id,
4168
+ 2
4169
+ FROM $catalog_product_entity a
4170
+ )
4171
+ ON DUPLICATE KEY UPDATE
4172
+ value = 2");
4173
+
4174
+ echo("\n replaceMagentoProductsMultistore 30\n");
4175
+
4176
+ // Load url Image
4177
+ $result = $this->db_do("
4178
+ INSERT INTO $catalog_product_entity_varchar
4179
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4180
+ (SELECT
4181
+ $_getProductEntityTypeId,
4182
+ $attr_image,
4183
+ w.store_id,
4184
+ a.entity_id,
4185
+ b.main_image_url
4186
+ FROM $catalog_product_entity a
4187
+ JOIN $core_store w
4188
+ JOIN $products_temp b
4189
+ ON a.store_product_id = b.store_product_id
4190
+ )
4191
+ ON DUPLICATE KEY UPDATE
4192
+ value = b.main_image_url");
4193
+
4194
+ echo("\n replaceMagentoProductsMultistore 31\n");
4195
+
4196
+ // image for specific web sites
4197
+ $result = $this->db_do("
4198
+ INSERT INTO $catalog_product_entity_varchar
4199
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4200
+ (SELECT
4201
+ $_getProductEntityTypeId,
4202
+ $attr_image,
4203
+ 0,
4204
+ a.entity_id,
4205
+ b.main_image_url
4206
+ FROM $catalog_product_entity a
4207
+ JOIN $products_temp b
4208
+ ON a.store_product_id = b.store_product_id
4209
+ )
4210
+ ON DUPLICATE KEY UPDATE
4211
+ value = b.main_image_url");
4212
+
4213
+ echo("\n replaceMagentoProductsMultistore 32\n");
4214
+
4215
+ // small_image for specific web sites
4216
+ $result = $this->db_do("
4217
+ INSERT INTO $catalog_product_entity_varchar
4218
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4219
+ (SELECT
4220
+ $_getProductEntityTypeId,
4221
+ $attr_small_image,
4222
+ w.store_id,
4223
+ a.entity_id,
4224
+ b.medium_image_url
4225
+ FROM $catalog_product_entity a
4226
+ JOIN $core_store w
4227
+ JOIN $products_temp b
4228
+ ON a.store_product_id = b.store_product_id
4229
+ )
4230
+ ON DUPLICATE KEY UPDATE
4231
+ value = b.medium_image_url");
4232
+
4233
+ echo("\n replaceMagentoProductsMultistore 33\n");
4234
+
4235
+ // small_image for all web sites
4236
+ $result = $this->db_do("
4237
+ INSERT INTO $catalog_product_entity_varchar
4238
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4239
+ (SELECT
4240
+ $_getProductEntityTypeId,
4241
+ $attr_small_image,
4242
+ 0,
4243
+ a.entity_id,
4244
+ b.medium_image_url
4245
+ FROM $catalog_product_entity a
4246
+ JOIN $core_store w
4247
+ JOIN $products_temp b
4248
+ ON a.store_product_id = b.store_product_id
4249
+ )
4250
+ ON DUPLICATE KEY UPDATE
4251
+ value = b.medium_image_url");
4252
+
4253
+ echo("\n replaceMagentoProductsMultistore 34\n");
4254
+
4255
+ // thumbnail for specific web site
4256
+ $result = $this->db_do("
4257
+ INSERT INTO $catalog_product_entity_varchar
4258
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4259
+ (SELECT
4260
+ $_getProductEntityTypeId,
4261
+ $attr_thumbnail,
4262
+ w.store_id,
4263
+ a.entity_id,
4264
+ b.thumb_image_url
4265
+ FROM $catalog_product_entity a
4266
+ JOIN $core_store w
4267
+ JOIN $products_temp b
4268
+ ON a.store_product_id = b.store_product_id
4269
+ )
4270
+ ON DUPLICATE KEY UPDATE
4271
+ value = b.thumb_image_url");
4272
+
4273
+ echo("\n replaceMagentoProductsMultistore 35\n");
4274
+
4275
+ // thumbnail for all web sites
4276
+ $result = $this->db_do("
4277
+ INSERT INTO $catalog_product_entity_varchar
4278
+ (entity_type_id, attribute_id, store_id, entity_id, value)
4279
+ (SELECT
4280
+ $_getProductEntityTypeId,
4281
+ $attr_thumbnail,
4282
+ 0,
4283
+ a.entity_id,
4284
+ b.thumb_image_url
4285
+ FROM $catalog_product_entity a
4286
+ JOIN $core_store w
4287
+ JOIN $products_temp b
4288
+ ON a.store_product_id = b.store_product_id
4289
+ )
4290
+ ON DUPLICATE KEY UPDATE
4291
+ value = b.thumb_image_url");
4292
+
4293
+ echo("\n replaceMagentoProductsMultistore 36\n");
4294
+
4295
+
4296
+
4297
+
4298
+
4299
+ /*STP DELETE
4300
+ //Refresh fulltext search
4301
+ $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
4302
+ $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
4303
+
4304
+
4305
+ echo("\n replaceMagentoProductsMultistore 36.2\n");
4306
+ $q = "
4307
+ INSERT INTO {$catalogsearch_fulltext}_tmp
4308
+ (product_id, store_id, data_index)
4309
+ (SELECT
4310
+ a.entity_id,
4311
+ w.website,
4312
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4313
+ FROM $catalog_product_entity a
4314
+ JOIN $products_website_temp w
4315
+ ON a.store_product_id = w.store_product_id
4316
+ LEFT JOIN $catalog_category_product b
4317
+ ON a.entity_id = b.product_id
4318
+ LEFT JOIN $catalog_category_entity_varchar c
4319
+ ON b.category_id = c.entity_id
4320
+ AND c.attribute_id = $cat_attr_name
4321
+ LEFT JOIN $catalog_product_entity_varchar e
4322
+ ON a.entity_id = e.entity_id
4323
+ AND e.attribute_id = $attr_name
4324
+ LEFT JOIN $catalog_product_website j
4325
+ ON a.entity_id = j.product_id
4326
+ LEFT JOIN $products_temp f
4327
+ ON a.store_product_id = f.store_product_id
4328
+ )
4329
+ ON DUPLICATE KEY UPDATE
4330
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
4331
+ echo("\n\n============================\n$q\n============================\n\n");
4332
+
4333
+
4334
+ $result = $this->db_do("
4335
+ INSERT INTO {$catalogsearch_fulltext}_tmp
4336
+ (product_id, store_id, data_index)
4337
+ (SELECT
4338
+ a.entity_id,
4339
+ w.website,
4340
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4341
+ FROM $catalog_product_entity a
4342
+ JOIN $products_website_temp w
4343
+ ON a.store_product_id = w.store_product_id
4344
+ LEFT JOIN $catalog_category_product b
4345
+ ON a.entity_id = b.product_id
4346
+ LEFT JOIN $catalog_category_entity_varchar c
4347
+ ON b.category_id = c.entity_id
4348
+ AND c.attribute_id = $cat_attr_name
4349
+ LEFT JOIN $catalog_product_entity_varchar e
4350
+ ON a.entity_id = e.entity_id
4351
+ AND e.attribute_id = $attr_name
4352
+ LEFT JOIN $catalog_product_website j
4353
+ ON a.entity_id = j.product_id
4354
+ LEFT JOIN $products_temp f
4355
+ ON a.store_product_id = f.store_product_id
4356
+ )
4357
+ ON DUPLICATE KEY UPDATE
4358
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
4359
+
4360
+ echo("\n replaceMagentoProductsMultistore 37\n");
4361
+
4362
+
4363
+ $result = $this->db_do("
4364
+ INSERT INTO {$catalogsearch_fulltext}_tmp
4365
+ (product_id, store_id, data_index)
4366
+ (SELECT
4367
+ a.entity_id,
4368
+ w.website,
4369
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4370
+ FROM $catalog_product_entity a
4371
+ JOIN $products_website_temp w
4372
+ ON a.store_product_id = w.store_product_id
4373
+ LEFT JOIN $catalog_category_product b
4374
+ ON a.entity_id = b.product_id
4375
+ LEFT JOIN $catalog_category_entity_varchar c
4376
+ ON b.category_id = c.entity_id
4377
+ AND c.attribute_id = $cat_attr_name
4378
+ LEFT JOIN $catalog_product_entity_varchar e
4379
+ ON a.entity_id = e.entity_id
4380
+ AND e.attribute_id = $attr_name
4381
+ LEFT JOIN $products_temp f
4382
+ ON a.store_product_id = f.store_product_id
4383
+ )
4384
+ ON DUPLICATE KEY UPDATE
4385
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
4386
+
4387
+ echo("\n replaceMagentoProductsMultistore 38\n");
4388
+
4389
+ $result = $this->db_do("
4390
+ DELETE cf
4391
+ FROM $catalogsearch_fulltext cf
4392
+ LEFT JOIN $catalog_product_entity cpe
4393
+ ON cf.product_id = cpe.entity_id
4394
+ WHERE cpe.entity_id IS NULL");
4395
+
4396
+ echo("\n replaceMagentoProductsMultistore 39\n");
4397
+
4398
+ $result = $this->db_do("
4399
+ INSERT INTO $catalogsearch_fulltext
4400
+ (product_id, store_id, data_index)
4401
+ (SELECT
4402
+ a.product_id,
4403
+ a.store_id,
4404
+ a.data_index
4405
+ FROM {$catalogsearch_fulltext}_tmp a
4406
+ )
4407
+ ON DUPLICATE KEY UPDATE
4408
+ data_index = a.data_index");
4409
+
4410
+ echo("\n replaceMagentoProductsMultistore 40\n");
4411
+
4412
+ $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
4413
+ //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
4414
+ //TODO add something else
4415
+ STP DELETE*/
4416
+
4417
+ $this->addRelatedProducts();
4418
+ echo("\n replaceMagentoProductsMultistore 41\n");
4419
+ } //
4420
+ ################################################################################################################################################################
4421
+
4422
+
4423
+
4424
+
4425
+
4426
+
4427
+
4428
+
4429
+
4430
+
4431
+
4432
+
4433
+
4434
+
4435
+
4436
+
4437
+
4438
+
4439
+
4440
+
4441
+
4442
+
4443
+
4444
+
4445
+
4446
+
4447
+
4448
+
4449
+
4450
+
4451
+
4452
+
4453
+
4454
+
4455
+
4456
+
4457
+
4458
+
4459
+
4460
+
4461
+
4462
+
4463
+
4464
+
4465
+
4466
+
4467
+
4468
+
4469
+
4470
+
4471
+
4472
+
4473
+
4474
+
4475
+
4476
+
4477
+
4478
+
4479
+
4480
+
4481
+
4482
+
4483
+
4484
+
4485
+
4486
+
4487
+
4488
+
4489
+
4490
+
4491
+
4492
+
4493
+
4494
+
4495
+
4496
+
4497
+
4498
+
4499
+
4500
+
4501
+
4502
+
4503
+
4504
+
4505
+
4506
+
4507
+
4508
+
4509
+
4510
+ ################################################################################################################################################################
4511
+ private function truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
4512
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
4513
+ $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
4514
+ {
4515
+ $this->db_do('SET foreign_key_checks=0');
4516
+
4517
+ $this->db_do("TRUNCATE $catalog_category_entity");
4518
+ $this->db_do("
4519
+ INSERT $catalog_category_entity
4520
+ (
4521
+ entity_id,
4522
+ entity_type_id,
4523
+ attribute_set_id,
4524
+ parent_id,
4525
+ created_at,
4526
+ updated_at,
4527
+ path,
4528
+ position,
4529
+ level,
4530
+ children_count,
4531
+ store_category_id,
4532
+ parent_store_category_id
4533
+ )
4534
+ VALUES
4535
+ (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
4536
+ (2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 1, null, null)");
4537
+
4538
+ $this->db_do("TRUNCATE $catalog_category_entity_varchar");
4539
+ $this->db_do("
4540
+ INSERT $catalog_category_entity_varchar
4541
+ (
4542
+ value_id,
4543
+ entity_type_id,
4544
+ attribute_id,
4545
+ store_id,
4546
+ entity_id,
4547
+ value
4548
+ )
4549
+ VALUES
4550
+ (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
4551
+ (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
4552
+ (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog'),
4553
+ (4, $_categoryEntityTypeId, $name_attrid, 0, 2, 'Default Category'),
4554
+ (5, $_categoryEntityTypeId, $name_attrid, 1, 2, 'Default Category'),
4555
+ (6, $_categoryEntityTypeId, $attr_display_mode, 1, 2, 'PRODUCTS'),
4556
+ (7, $_categoryEntityTypeId, $attr_url_key, 0, 2, 'default-category')");
4557
+
4558
+ $this->db_do("TRUNCATE $catalog_category_entity_int");
4559
+ $this->db_do("
4560
+ INSERT $catalog_category_entity_int
4561
+ (
4562
+ value_id,
4563
+ entity_type_id,
4564
+ attribute_id,
4565
+ store_id,
4566
+ entity_id,
4567
+ value
4568
+ )
4569
+ VALUES
4570
+ (1, $_categoryEntityTypeId, $attr_is_active, 0, 2, 1),
4571
+ (2, $_categoryEntityTypeId, $attr_is_active, 1, 2, 1),
4572
+ (3, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1),
4573
+ (4, $_categoryEntityTypeId, $attr_include_in_menu, 0, 2, 1)");
4574
+
4575
+ return $root_cat;
4576
+ } // private function truncateAllCateriesAndRecreateDefaults(...)
4577
+ ################################################################################################################################################################
4578
+
4579
+
4580
+
4581
+ ################################################################################################################################################################
4582
+ private function setCategorySettings($categories_temp, $root_cat)
4583
+ {
4584
+ $this->db_do("
4585
+ UPDATE $categories_temp
4586
+ SET parent_store_category_id = $root_cat
4587
+ WHERE parent_store_category_id = 0");
4588
+
4589
+ $store_cat_ids = $this->db_do("SELECT store_category_id FROM $categories_temp");
4590
+ while ($row = mysqli_fetch_array($store_cat_ids))
4591
+ {
4592
+ $store_category_id = $row['store_category_id'];
4593
+
4594
+ $children_count = $this->count_children($store_category_id);
4595
+ $level = $this->get_category_level($store_category_id);
4596
+
4597
+ $this->db_do("
4598
+ UPDATE $categories_temp
4599
+ SET children_count = $children_count,
4600
+ level = $level
4601
+ WHERE store_category_id = $store_category_id");
4602
+ }
4603
+ } // private function setCategorySettings($categories_temp, $root_cat)
4604
+ ################################################################################################################################################################
4605
+
4606
+
4607
+
4608
+
4609
+
4610
+
4611
+
4612
+ ################################################################################################################################################################
4613
+ public function mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat)
4614
+ {
4615
+ $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
4616
+
4617
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
4618
+
4619
+ $this->db_do("
4620
+ CREATE TABLE $stINch_categories_mapping_temp
4621
+ (
4622
+ shop_entity_id INT(11) UNSIGNED NOT NULL,
4623
+ shop_entity_type_id INT(11),
4624
+ shop_attribute_set_id INT(11),
4625
+ shop_parent_id INT(11),
4626
+ shop_store_category_id INT(11),
4627
+ shop_parent_store_category_id INT(11),
4628
+ store_category_id INT(11),
4629
+ parent_store_category_id INT(11),
4630
+ category_name VARCHAR(255),
4631
+ order_number INT(11),
4632
+ products_within_this_category INT(11),
4633
+
4634
+ KEY shop_entity_id (shop_entity_id),
4635
+ KEY shop_parent_id (shop_parent_id),
4636
+ KEY store_category_id (store_category_id),
4637
+ KEY parent_store_category_id (parent_store_category_id),
4638
+ UNIQUE KEY(shop_entity_id)
4639
+ )");
4640
+
4641
+ $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
4642
+
4643
+ $this->db_do("
4644
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
4645
+ (
4646
+ shop_entity_id,
4647
+ shop_entity_type_id,
4648
+ shop_attribute_set_id,
4649
+ shop_parent_id,
4650
+ shop_store_category_id,
4651
+ shop_parent_store_category_id
4652
+ )
4653
+ (SELECT
4654
+ entity_id,
4655
+ entity_type_id,
4656
+ attribute_set_id,
4657
+ parent_id,
4658
+ store_category_id,
4659
+ parent_store_category_id
4660
+ FROM $catalog_category_entity)");
4661
+
4662
+ $this->db_do("
4663
+ UPDATE $stINch_categories_mapping_temp cmt
4664
+ JOIN $categories_temp c
4665
+ ON cmt.shop_store_category_id = c.store_category_id
4666
+ SET
4667
+ cmt.store_category_id = c.store_category_id,
4668
+ cmt.parent_store_category_id = c.parent_store_category_id,
4669
+ cmt.category_name = c.category_name,
4670
+ cmt.order_number = c.order_number,
4671
+ cmt.products_within_this_category = c.products_within_this_category");
4672
+
4673
+ $this->db_do("
4674
+ UPDATE $stINch_categories_mapping_temp cmt
4675
+ JOIN $catalog_category_entity cce
4676
+ ON cmt.parent_store_category_id = cce.store_category_id
4677
+ SET cmt.shop_parent_id = cce.entity_id");
4678
+
4679
+ $this->db_do("
4680
+ UPDATE $stINch_categories_mapping_temp cmt
4681
+ JOIN $categories_temp c
4682
+ ON cmt.shop_store_category_id = c.store_category_id
4683
+ SET shop_parent_id = ".$this->_root_cat."
4684
+ WHERE shop_parent_id = 0");
4685
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!! one shop ($this->_root_cat) => milti shop ($root_cat)
4686
+
4687
+ // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
4688
+ if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE"))
4689
+ {
4690
+ $this->db_do("
4691
+ UPDATE $stINch_categories_mapping_temp cmt
4692
+ JOIN $catalog_category_entity cce
4693
+ ON cmt.shop_entity_id = cce.entity_id
4694
+ SET cce.parent_id = cmt.shop_parent_id");
4695
+ }
4696
+ else
4697
+ {
4698
+ $this->db_do("
4699
+ UPDATE $stINch_categories_mapping_temp cmt
4700
+ JOIN $catalog_category_entity cce
4701
+ ON cmt.shop_entity_id = cce.entity_id
4702
+ SET cce.parent_id = cmt.shop_parent_id
4703
+ WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL");
4704
+ }
4705
+
4706
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping");
4707
+ $this->db_do("RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping");
4708
+ } //
4709
+ ################################################################################################################################################################
4710
+
4711
+
4712
+
4713
+ ################################################################################################################################################################
4714
+ private function addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
4715
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat)
4716
+ {
4717
+ if (UPDATE_CATEGORY_DATA)
4718
+ {
4719
+ echo "Update category_entity \n";
4720
+
4721
+ $q = "
4722
+ INSERT INTO $catalog_category_entity
4723
+ (
4724
+ entity_type_id,
4725
+ attribute_set_id,
4726
+ created_at,
4727
+ updated_at,
4728
+ level,
4729
+ children_count,
4730
+ entity_id,
4731
+ position,
4732
+ parent_id,
4733
+ store_category_id,
4734
+ parent_store_category_id
4735
+ )
4736
+ (SELECT
4737
+ $_categoryEntityTypeId,
4738
+ $_categoryDefault_attribute_set_id,
4739
+ now(),
4740
+ now(),
4741
+ c.level,
4742
+ c.children_count,
4743
+ scm.shop_entity_id,
4744
+ c.order_number,
4745
+ scm.shop_parent_id,
4746
+ c.store_category_id,
4747
+ c.parent_store_category_id
4748
+ FROM $categories_temp c
4749
+ LEFT JOIN $stINch_categories_mapping scm
4750
+ ON c.store_category_id = scm.store_category_id
4751
+ )
4752
+ ON DUPLICATE KEY UPDATE
4753
+ updated_at = now(),
4754
+ store_category_id = c.store_category_id,
4755
+ level = c.level,
4756
+ children_count = c.children_count,
4757
+ position = c.order_number,
4758
+ parent_store_category_id = c.parent_store_category_id";
4759
+ //level=c.level,
4760
+ //children_count=c.children_count
4761
+ //position=c.order_number,
4762
+ }
4763
+ else
4764
+ {
4765
+ echo "Insert ignore category_entity \n";
4766
+
4767
+ $q = "
4768
+ INSERT IGNORE INTO $catalog_category_entity
4769
+ (
4770
+ entity_type_id,
4771
+ attribute_set_id,
4772
+ created_at,
4773
+ updated_at,
4774
+ level,
4775
+ children_count,
4776
+ entity_id,
4777
+ position,
4778
+ parent_id,
4779
+ store_category_id,
4780
+ parent_store_category_id
4781
+ )
4782
+ (SELECT
4783
+ $_categoryEntityTypeId,
4784
+ $_categoryDefault_attribute_set_id,
4785
+ now(),
4786
+ now(),
4787
+ c.level,
4788
+ c.children_count,
4789
+ scm.shop_entity_id,
4790
+ c.order_number,
4791
+ scm.shop_parent_id,
4792
+ c.store_category_id,
4793
+ c.parent_store_category_id
4794
+ FROM $categories_temp c
4795
+ LEFT JOIN $stINch_categories_mapping scm
4796
+ ON c.store_category_id = scm.store_category_id
4797
+ )";
4798
+ }
4799
+ $this->db_do($q);
4800
+
4801
+ $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
4802
+
4803
+
4804
+
4805
+ $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
4806
+ while ($row = mysqli_fetch_array($categories))
4807
+ {
4808
+ $parent_id = $row['parent_id'];
4809
+ $entity_id = $row['entity_id'];
4810
+
4811
+ $path = $this->culc_path($parent_id, $entity_id);
4812
+
4813
+ //echo("\n$path\n");
4814
+
4815
+ $this->db_do("
4816
+ UPDATE $catalog_category_entity
4817
+ SET path = '$path'
4818
+ WHERE entity_id = $entity_id");
4819
+ }
4820
+
4821
+ if(UPDATE_CATEGORY_DATA)
4822
+ {
4823
+ echo "Update category_data \n";
4824
+
4825
+ $q = "
4826
+ INSERT INTO $catalog_category_entity_varchar
4827
+ (
4828
+ entity_type_id,
4829
+ attribute_id,
4830
+ store_id,
4831
+ entity_id,
4832
+ value
4833
+ )
4834
+ (SELECT
4835
+ $_categoryEntityTypeId,
4836
+ $name_attrid,
4837
+ 0,
4838
+ scm.shop_entity_id,
4839
+ c.category_name
4840
+ FROM $categories_temp c
4841
+ JOIN $stINch_categories_mapping scm
4842
+ ON c.store_category_id = scm.store_category_id
4843
+ )
4844
+ ON DUPLICATE KEY UPDATE
4845
+ value = c.category_name";
4846
+ $this->db_do($q);
4847
+
4848
+ $q = "
4849
+ INSERT INTO $catalog_category_entity_varchar
4850
+ (
4851
+ entity_type_id,
4852
+ attribute_id,
4853
+ store_id,
4854
+ entity_id,
4855
+ value
4856
+ )
4857
+ (SELECT
4858
+ $_categoryEntityTypeId,
4859
+ $name_attrid,
4860
+ 1,
4861
+ scm.shop_entity_id,
4862
+ c.category_name
4863
+ FROM $categories_temp c
4864
+ JOIN $stINch_categories_mapping scm
4865
+ ON c.store_category_id = scm.store_category_id
4866
+ )
4867
+ ON DUPLICATE KEY UPDATE
4868
+ value = c.category_name";
4869
+ $this->db_do($q);
4870
+
4871
+ $q = "
4872
+ INSERT INTO $catalog_category_entity
4873
+ (
4874
+ entity_type_id,
4875
+ attribute_id,
4876
+ store_id,
4877
+ entity_id,
4878
+ value
4879
+ )
4880
+ (SELECT
4881
+ $_categoryEntityTypeId,
4882
+ $attr_is_active,
4883
+ 0,
4884
+ scm.shop_entity_id,
4885
+ 1
4886
+ FROM $categories_temp c
4887
+ JOIN $stINch_categories_mapping scm
4888
+ ON c.store_category_id = scm.store_category_id
4889
+ )
4890
+ ON DUPLICATE KEY UPDATE
4891
+ value = 1";
4892
+ $this->db_do($q);
4893
+
4894
+ $q = "
4895
+ INSERT INTO $catalog_category_entity_int
4896
+ (
4897
+ entity_type_id,
4898
+ attribute_id,
4899
+ store_id,
4900
+ entity_id,
4901
+ value
4902
+ )
4903
+ (SELECT
4904
+ $_categoryEntityTypeId,
4905
+ $attr_is_active,
4906
+ 1,
4907
+ scm.shop_entity_id,
4908
+ 1
4909
+ FROM $categories_temp c
4910
+ JOIN $stINch_categories_mapping scm
4911
+ ON c.store_category_id = scm.store_category_id
4912
+ )
4913
+ ON DUPLICATE KEY UPDATE
4914
+ value = 1";
4915
+ $this->db_do($q);
4916
+
4917
+ $q = "
4918
+ INSERT INTO $catalog_category_entity_int
4919
+ (
4920
+ entity_type_id,
4921
+ attribute_id,
4922
+ store_id,
4923
+ entity_id,
4924
+ value
4925
+ )
4926
+ (SELECT
4927
+ $_categoryEntityTypeId,
4928
+ $attr_include_in_menu,
4929
+ 0,
4930
+ scm.shop_entity_id,
4931
+ c.include_in_menu
4932
+ FROM $categories_temp c
4933
+ JOIN $stINch_categories_mapping scm
4934
+ ON c.store_category_id = scm.store_category_id
4935
+ )
4936
+ ON DUPLICATE KEY UPDATE
4937
+ value = c.include_in_menu";
4938
+ $this->db_do($q);
4939
+
4940
+ $q = "
4941
+ INSERT INTO $catalog_category_entity_int
4942
+ (
4943
+ entity_type_id,
4944
+ attribute_id,
4945
+ store_id,
4946
+ entity_id,
4947
+ value
4948
+ )
4949
+ (SELECT
4950
+ $_categoryEntityTypeId,
4951
+ $is_anchor_attrid,
4952
+ 1,
4953
+ scm.shop_entity_id,
4954
+ c.is_anchor
4955
+ FROM $categories_temp c
4956
+ JOIN $stINch_categories_mapping scm
4957
+ ON c.store_category_id = scm.store_category_id
4958
+ )
4959
+ ON DUPLICATE KEY UPDATE
4960
+ value = c.is_anchor";
4961
+ $this->db_do($q);
4962
+
4963
+ $q = "
4964
+ INSERT INTO $catalog_category_entity_int
4965
+ (
4966
+ entity_type_id,
4967
+ attribute_id,
4968
+ store_id,
4969
+ entity_id,
4970
+ value
4971
+ )
4972
+ (SELECT
4973
+ $_categoryEntityTypeId,
4974
+ $is_anchor_attrid,
4975
+ 0,
4976
+ scm.shop_entity_id,
4977
+ c.is_anchor
4978
+ FROM $categories_temp c
4979
+ JOIN $stINch_categories_mapping scm
4980
+ ON c.store_category_id = scm.store_category_id
4981
+ )
4982
+ ON DUPLICATE KEY UPDATE
4983
+ value = c.is_anchor";
4984
+ $this->db_do($q);
4985
+
4986
+ $q = "
4987
+ INSERT INTO $catalog_category_entity_varchar
4988
+ (
4989
+ entity_type_id,
4990
+ attribute_id,
4991
+ store_id,
4992
+ entity_id,
4993
+ value
4994
+ )
4995
+ (SELECT
4996
+ $_categoryEntityTypeId,
4997
+ $image_attrid,
4998
+ 0,
4999
+ scm.shop_entity_id,
5000
+ c.categories_image
5001
+ FROM $categories_temp c
5002
+ JOIN $stINch_categories_mapping scm
5003
+ ON c.store_category_id = scm.store_category_id
5004
+ )
5005
+ ON DUPLICATE KEY UPDATE
5006
+ value = c.categories_image";
5007
+ $this->db_do($q);
5008
+ //STP
5009
+ $q = "
5010
+ INSERT INTO $catalog_category_entity_varchar
5011
+ (
5012
+ entity_type_id,
5013
+ attribute_id,
5014
+ store_id,
5015
+ entity_id,
5016
+ value
5017
+ )
5018
+ (SELECT
5019
+ $this->_categoryEntityTypeId,
5020
+ $this->_categoryMetaTitleAttrId,
5021
+ 0,
5022
+ scm.shop_entity_id,
5023
+ c.MetaTitle
5024
+ FROM $categories_temp c
5025
+ JOIN $stINch_categories_mapping scm
5026
+ ON c.store_category_id = scm.store_category_id
5027
+ )
5028
+ ON DUPLICATE KEY UPDATE
5029
+ value = c.MetaTitle";
5030
+ $this->db_do($q);
5031
+
5032
+ $q = "
5033
+ INSERT INTO $catalog_category_entity_varchar
5034
+ (
5035
+ entity_type_id,
5036
+ attribute_id,
5037
+ store_id,
5038
+ entity_id,
5039
+ value
5040
+ )
5041
+ (SELECT
5042
+ $this->_categoryEntityTypeId,
5043
+ $this->_categoryMetadescriptionAttrId,
5044
+ 0,
5045
+ scm.shop_entity_id,
5046
+ c.MetaDescription
5047
+ FROM $categories_temp c
5048
+ JOIN $stINch_categories_mapping scm
5049
+ ON c.store_category_id = scm.store_category_id
5050
+ )
5051
+ ON DUPLICATE KEY UPDATE
5052
+ value = c.MetaDescription";
5053
+ $this->db_do($q);
5054
+
5055
+ $q = "
5056
+ INSERT INTO $catalog_category_entity_varchar
5057
+ (
5058
+ entity_type_id,
5059
+ attribute_id,
5060
+ store_id,
5061
+ entity_id,
5062
+ value
5063
+ )
5064
+ (SELECT
5065
+ $this->_categoryEntityTypeId,
5066
+ $this->_categoryDescriptionAttrId,
5067
+ 0,
5068
+ scm.shop_entity_id,
5069
+ c.Description
5070
+ FROM $categories_temp c
5071
+ JOIN $stINch_categories_mapping scm
5072
+ ON c.store_category_id = scm.store_category_id
5073
+ )
5074
+ ON DUPLICATE KEY UPDATE
5075
+ value = c.Description";
5076
+ $this->db_do($q);
5077
+
5078
+
5079
+ //stp
5080
+ }
5081
+ else
5082
+ {
5083
+ echo "Insert ignore category_data \n";
5084
+
5085
+ $q = "
5086
+ INSERT IGNORE INTO $catalog_category_entity_varchar
5087
+ (
5088
+ entity_type_id,
5089
+ attribute_id,
5090
+ store_id,
5091
+ entity_id,
5092
+ value
5093
+ )
5094
+ (SELECT
5095
+ $_categoryEntityTypeId,
5096
+ $name_attrid,
5097
+ 0,
5098
+ scm.shop_entity_id,
5099
+ c.category_name
5100
+ FROM $categories_temp c
5101
+ JOIN $stINch_categories_mapping scm
5102
+ ON c.store_category_id = scm.store_category_id
5103
+ )";
5104
+ $this->db_do($q);
5105
+
5106
+ $q = "
5107
+ INSERT IGNORE INTO $catalog_category_entity_int
5108
+ (
5109
+ entity_type_id,
5110
+ attribute_id,
5111
+ store_id,
5112
+ entity_id,
5113
+ value
5114
+ )
5115
+ (SELECT
5116
+ $_categoryEntityTypeId,
5117
+ $attr_is_active,
5118
+ 0,
5119
+ scm.shop_entity_id,
5120
+ 1
5121
+ FROM $categories_temp c
5122
+ JOIN $stINch_categories_mapping scm
5123
+ ON c.store_category_id = scm.store_category_id
5124
+ )";
5125
+ $this->db_do($q);
5126
+
5127
+ $q = "
5128
+ INSERT IGNORE INTO $catalog_category_entity_int
5129
+ (
5130
+ entity_type_id,
5131
+ attribute_id,
5132
+ store_id,
5133
+ entity_id,
5134
+ value
5135
+ )
5136
+ (SELECT
5137
+ $_categoryEntityTypeId,
5138
+ $attr_include_in_menu,
5139
+ 0,
5140
+ scm.shop_entity_id,
5141
+ c.include_in_menu
5142
+ FROM $categories_temp c
5143
+ JOIN $stINch_categories_mapping scm
5144
+ ON c.store_category_id = scm.store_category_id
5145
+ )";
5146
+ $this->db_do($q);
5147
+
5148
+ $q = "
5149
+ INSERT IGNORE INTO $catalog_category_entity_int
5150
+ (
5151
+ entity_type_id,
5152
+ attribute_id,
5153
+ store_id,
5154
+ entity_id,
5155
+ value
5156
+ )
5157
+ (SELECT
5158
+ $_categoryEntityTypeId,
5159
+ $is_anchor_attrid,
5160
+ 0,
5161
+ scm.shop_entity_id,
5162
+ c.is_anchor
5163
+ FROM $categories_temp c
5164
+ JOIN $stINch_categories_mapping scm
5165
+ ON c.store_category_id = scm.store_category_id
5166
+ )";
5167
+ $this->db_do($q);
5168
+
5169
+ $q = "
5170
+ INSERT IGNORE INTO $catalog_category_entity_varchar
5171
+ (
5172
+ entity_type_id,
5173
+ attribute_id,
5174
+ store_id,
5175
+ entity_id,
5176
+ value
5177
+ )
5178
+ (SELECT
5179
+ $_categoryEntityTypeId,
5180
+ $image_attrid,
5181
+ 0,
5182
+ scm.shop_entity_id,
5183
+ c.categories_image
5184
+ FROM $categories_temp c
5185
+ JOIN $stINch_categories_mapping scm
5186
+ ON c.store_category_id = scm.store_category_id
5187
+ )";
5188
+ $this->db_do($q);
5189
+ //STP
5190
+ $q = "
5191
+ INSERT IGNORE INTO $catalog_category_entity_varchar
5192
+ (
5193
+ entity_type_id,
5194
+ attribute_id,
5195
+ store_id,
5196
+ entity_id,
5197
+ value
5198
+ )
5199
+ (SELECT
5200
+ $this->_categoryEntityTypeId,
5201
+ $this->_categoryMetaTitleAttrId,
5202
+ 0,
5203
+ scm.shop_entity_id,
5204
+ c.MetaTitle
5205
+ FROM $categories_temp c
5206
+ JOIN $stINch_categories_mapping scm
5207
+ ON c.store_category_id = scm.store_category_id
5208
+ )
5209
+ ";
5210
+ $this->db_do($q);
5211
+
5212
+ $q = "
5213
+ INSERT IGNORE INTO $catalog_category_entity_varchar
5214
+ (
5215
+ entity_type_id,
5216
+ attribute_id,
5217
+ store_id,
5218
+ entity_id,
5219
+ value
5220
+ )
5221
+ (SELECT
5222
+ $this->_categoryEntityTypeId,
5223
+ $this->_categoryMetadescriptionAttrId,
5224
+ 0,
5225
+ scm.shop_entity_id,
5226
+ c.MetaDescription
5227
+ FROM $categories_temp c
5228
+ JOIN $stINch_categories_mapping scm
5229
+ ON c.store_category_id = scm.store_category_id
5230
+ )
5231
+ ";
5232
+ $this->db_do($q);
5233
+
5234
+ $q = "
5235
+ INSERT IGNORE INTO $catalog_category_entity_varchar
5236
+ (
5237
+ entity_type_id,
5238
+ attribute_id,
5239
+ store_id,
5240
+ entity_id,
5241
+ value
5242
+ )
5243
+ (SELECT
5244
+ $this->_categoryEntityTypeId,
5245
+ $this->_categoryDescriptionAttrId,
5246
+ 0,
5247
+ scm.shop_entity_id,
5248
+ c.Description
5249
+ FROM $categories_temp c
5250
+ JOIN $stINch_categories_mapping scm
5251
+ ON c.store_category_id = scm.store_category_id
5252
+ )
5253
+ ";
5254
+ $this->db_do($q);
5255
+
5256
+
5257
+ //stp
5258
+
5259
+ }
5260
+
5261
+ $this->delete_old_sinch_categories_from_shop();
5262
+
5263
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories");
5264
+ $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
5265
+ } // private function addCategoryData(...)
5266
+ ################################################################################################################################################################
5267
+
5268
+
5269
+
5270
+
5271
+
5272
+
5273
+
5274
+
5275
+
5276
+
5277
+
5278
+
5279
+
5280
+
5281
+
5282
+
5283
+
5284
+ function ParseCategoryFeatures(){
5285
+
5286
+ $parse_file=$this->varDir.FILE_CATEGORIES_FEATURES;
5287
+ if(filesize($parse_file) || $this->_ignore_category_features){
5288
+ $this->_LOG("Start parse ".FILE_CATEGORIES_FEATURES);
5289
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp'));
5290
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')." (
5291
+ category_feature_id int(11),
5292
+ store_category_id int(11),
5293
+ feature_name varchar(50),
5294
+ display_order_number int(11),
5295
+ KEY(store_category_id),
5296
+ KEY(category_feature_id)
5297
+ )
5298
+ ");
5299
+
5300
+ if(!$this->_ignore_category_features){
5301
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5302
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
5303
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5304
+ OPTIONALLY ENCLOSED BY '\"'
5305
+ LINES TERMINATED BY \"\r\n\"
5306
+ IGNORE 1 LINES ");
5307
+ }
5308
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
5309
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
5310
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
5311
+
5312
+ $this->_LOG("Finish parse ".FILE_CATEGORIES_FEATURES);
5313
+ }else{
5314
+ $this->_LOG("Wrong file ".$parse_file);
5315
+ }
5316
+ $this->_LOG(' ');
5317
+ }
5318
+
5319
+ #################################################################################################
5320
+
5321
+ function ParseDistributors(){
5322
+
5323
+ $parse_file=$this->varDir.FILE_DISTRIBUTORS;
5324
+ if(filesize($parse_file)){
5325
+ $this->_LOG("Start parse ".FILE_DISTRIBUTORS);
5326
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('distributors_temp'));
5327
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."(
5328
+ distributor_id int(11),
5329
+ distributor_name varchar(255),
5330
+ website varchar(255),
5331
+ KEY(distributor_id)
5332
+ )
5333
+ ");
5334
+
5335
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5336
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
5337
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5338
+ OPTIONALLY ENCLOSED BY '\"'
5339
+ LINES TERMINATED BY \"\r\n\"
5340
+ IGNORE 1 LINES ");
5341
+
5342
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
5343
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
5344
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
5345
+
5346
+ $this->_LOG("Finish parse ".FILE_DISTRIBUTORS);
5347
+ }else{
5348
+ $this->_LOG("Wrong file ".$parse_file);
5349
+ }
5350
+ $this->_LOG(' ');
5351
+ }
5352
+
5353
+ #################################################################################################
5354
+
5355
+ function ParseDistributorsStockAndPrice(){
5356
+ $parse_file=$this->varDir.FILE_DISTRIBUTORS_STOCK_AND_PRICES;
5357
+ if(filesize($parse_file)){
5358
+ $this->_LOG("Start parse ".FILE_DISTRIBUTORS_STOCK_AND_PRICES);
5359
+
5360
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp'));
5361
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."(
5362
+ `store_product_id` int(11) DEFAULT NULL,
5363
+ `distributor_id` int(11) DEFAULT NULL,
5364
+ `stock` int(11) DEFAULT NULL,
5365
+ `cost` decimal(15,4) DEFAULT NULL,
5366
+ `distributor_sku` varchar(255) DEFAULT NULL,
5367
+ `distributor_category` varchar(50) DEFAULT NULL,
5368
+ `eta` varchar(50) DEFAULT NULL,
5369
+ UNIQUE KEY `product_distri` (store_product_id, distributor_id)
5370
+ )");
5371
+
5372
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5373
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."
5374
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5375
+ OPTIONALLY ENCLOSED BY '\"'
5376
+ LINES TERMINATED BY \"\r\n\"
5377
+ IGNORE 1 LINES ");
5378
+
5379
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
5380
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."
5381
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
5382
+
5383
+ $this->_LOG("Finish parse ".FILE_DISTRIBUTORS_STOCK_AND_PRICES);
5384
+ }else{
5385
+ $this->_LOG("Wrong file ".$parse_file);
5386
+ }
5387
+ $this->_LOG(' ');
5388
+
5389
+ }
5390
+
5391
+
5392
+ #################################################################################################
5393
+
5394
+ function ParseEANCodes(){
5395
+
5396
+ $parse_file=$this->varDir.FILE_EANCODES;
5397
+ if(filesize($parse_file)){
5398
+ $this->_LOG("Start parse ".FILE_EANCODES);
5399
+
5400
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp'));
5401
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."(
5402
+ product_id int(11),
5403
+ ean_code varchar(255),
5404
+ KEY(product_id)
5405
+ )");
5406
+
5407
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5408
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
5409
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5410
+ OPTIONALLY ENCLOSED BY '\"'
5411
+ LINES TERMINATED BY \"\r\n\"
5412
+ IGNORE 1 LINES ");
5413
+
5414
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
5415
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
5416
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
5417
+
5418
+ $this->_LOG("Finish parse ".FILE_EANCODES);
5419
+ }else{
5420
+ $this->_LOG("Wrong file ".$parse_file);
5421
+ }
5422
+ $this->_LOG(' ');
5423
+ }
5424
+
5425
+ #################################################################################################
5426
+
5427
+ function ParseManufacturers(){
5428
+
5429
+ $parse_file=$this->varDir.FILE_MANUFACTURERS;
5430
+ if(filesize($parse_file)){
5431
+ $this->_LOG("Start parse ".FILE_MANUFACTURERS);
5432
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp'));
5433
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."(
5434
+ sinch_manufacturer_id int(11),
5435
+ manufacturer_name varchar(255),
5436
+ manufacturers_image varchar(255),
5437
+ shop_option_id int(11),
5438
+ KEY(sinch_manufacturer_id),
5439
+ KEY(shop_option_id),
5440
+ KEY(manufacturer_name)
5441
+ )");
5442
+
5443
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5444
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
5445
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5446
+ OPTIONALLY ENCLOSED BY '\"'
5447
+ LINES TERMINATED BY \"\r\n\"
5448
+ IGNORE 1 LINES ");
5449
+
5450
+ $q="DELETE aov
5451
+ FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5452
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5453
+ ON ao.option_id=aov.option_id left
5454
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
5455
+ ON aov.value=mt.manufacturer_name
5456
+ WHERE
5457
+ ao.attribute_id=".$this->attributes['manufacturer']." AND
5458
+ mt.manufacturer_name is null";
5459
+ $this->db_do($q);
5460
+
5461
+ $q="DELETE ao
5462
+ FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5463
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5464
+ ON ao.option_id=aov.option_id
5465
+ WHERE
5466
+ attribute_id=".$this->attributes['manufacturer']." AND
5467
+ aov.option_id is null";
5468
+ $this->db_do($q);
5469
+
5470
+ $q="SELECT
5471
+ m.sinch_manufacturer_id,
5472
+ m.manufacturer_name,
5473
+ m.manufacturers_image
5474
+ FROM ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." m
5475
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5476
+ ON m.manufacturer_name=aov.value
5477
+ WHERE aov.value IS NULL";
5478
+ $quer=$this->db_do($q);
5479
+
5480
+ while($row=mysqli_fetch_array($quer)){
5481
+ $q0="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
5482
+ (attribute_id)
5483
+ VALUES(".$this->attributes['manufacturer'].")";
5484
+ $quer0=$this->db_do($q0);
5485
+
5486
+ $q2="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')."(
5487
+ option_id,
5488
+ value
5489
+ )(
5490
+ SELECT
5491
+ max(option_id) as option_id,
5492
+ "."'".mysqli_real_escape_string($this->db, $row['manufacturer_name'])."'
5493
+ FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
5494
+ WHERE attribute_id=".$this->attributes['manufacturer']."
5495
+ )
5496
+ ";
5497
+ $quer2=$this->db_do($q2);
5498
+ // $option['attribute_id'] = $this->attributes['manufacturer'];
5499
+ // $option['value'][$row['sinch_manufacturer_id']][0] = $row['manufacturer_name'];
5500
+
5501
+ }
5502
+
5503
+ $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
5504
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5505
+ ON mt.manufacturer_name=aov.value
5506
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5507
+ ON ao.option_id=aov.option_id
5508
+ SET mt.shop_option_id=aov.option_id
5509
+ WHERE ao.attribute_id=".$this->attributes['manufacturer'];
5510
+ $this->db_do($q);
5511
+
5512
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
5513
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
5514
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
5515
+ $this->_LOG("Finish parse ".FILE_MANUFACTURERS);
5516
+ }else{
5517
+ $this->_LOG("Wrong file ".$parse_file);
5518
+ }
5519
+ $this->_LOG(' ');
5520
+ }
5521
+
5522
+ #################################################################################################
5523
+
5524
+ function ParseProductFeatures(){
5525
+
5526
+ $parse_file=$this->varDir.FILE_PRODUCT_FEATURES;
5527
+ if(filesize($parse_file) || $this->_ignore_product_features){
5528
+ $this->_LOG("Start parse ".FILE_PRODUCT_FEATURES);
5529
+
5530
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('product_features_temp'));
5531
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."(
5532
+ product_feature_id int(11),
5533
+ sinch_product_id int(11),
5534
+ restricted_value_id int(11),
5535
+ KEY(sinch_product_id),
5536
+ KEY(restricted_value_id)
5537
+ )
5538
+ ");
5539
+ if(!$this->_ignore_product_features){
5540
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5541
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
5542
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5543
+ OPTIONALLY ENCLOSED BY '\"'
5544
+ LINES TERMINATED BY \"\r\n\"
5545
+ IGNORE 1 LINES ");
5546
+ }
5547
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
5548
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
5549
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
5550
+
5551
+ $this->_LOG("Finish parse ".FILE_PRODUCT_FEATURES);
5552
+ }else{
5553
+ $this->_LOG("Wrong file ".$parse_file);
5554
+ }
5555
+ $this->_LOG(" ");
5556
+ }
5557
+ #################################################################################################
5558
+
5559
+ function ParseCategoryTypes(){
5560
+ $parse_file=$this->varDir.FILE_CATEGORY_TYPES;
5561
+ if(filesize($parse_file)){
5562
+ $this->_LOG("Start parse ".FILE_CATEGORY_TYPES);
5563
+
5564
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('category_types_temp'));
5565
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."(
5566
+ id int(11),
5567
+ name varchar(255),
5568
+ key(id)
5569
+ )");
5570
+
5571
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5572
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."
5573
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5574
+ OPTIONALLY ENCLOSED BY '\"'
5575
+ LINES TERMINATED BY \"\r\n\"
5576
+ IGNORE 1 LINES ");
5577
+
5578
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_category_types'));
5579
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."
5580
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_category_types'));
5581
+
5582
+ $this->_LOG("Finish parse ".FILE_CATEGORY_TYPES);
5583
+ }else{
5584
+ $this->_LOG("Wrong file ".$parse_file);
5585
+ }
5586
+ $this->_LOG(' ');
5587
+
5588
+ }
5589
+
5590
+ #################################################################################################
5591
+
5592
+ function ParseProductCategories(){
5593
+ $parse_file=$this->varDir.FILE_PRODUCT_CATEGORIES;
5594
+ if(filesize($parse_file)){
5595
+ $this->_LOG("Start parse ".FILE_PRODUCT_CATEGORIES);
5596
+
5597
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp'));
5598
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."(
5599
+ store_product_id int(11),
5600
+ store_category_id int(11),
5601
+ key(store_product_id),
5602
+ key(store_category_id)
5603
+ )");
5604
+
5605
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5606
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."
5607
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5608
+ OPTIONALLY ENCLOSED BY '\"'
5609
+ LINES TERMINATED BY \"\r\n\"
5610
+ IGNORE 1 LINES ");
5611
+
5612
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories'));
5613
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."
5614
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories'));
5615
+
5616
+ $this->_LOG("Finish parse ".FILE_PRODUCT_CATEGORIES);
5617
+ }else{
5618
+ $this->_LOG("Wrong file ".$parse_file);
5619
+ }
5620
+ $this->_LOG(' ');
5621
+
5622
+ }
5623
+ #################################################################################################
5624
+
5625
+ function ParseProducts($coincidence){
5626
+ echo("\nParseProducts 2\n");
5627
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
5628
+ $replace_merge_product = $dataConf['replace_products'];
5629
+
5630
+ $parse_file=$this->varDir.FILE_PRODUCTS;
5631
+ if(filesize($parse_file)){
5632
+ $this->_LOG("Start parse ".FILE_PRODUCTS);
5633
+ echo("\nParseProducts 2\n");
5634
+
5635
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
5636
+ if($this->product_file_format == "NEW"){
5637
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
5638
+ store_product_id int(11),
5639
+ product_sku varchar(255),
5640
+ product_name varchar(255),
5641
+ sinch_manufacturer_id int(11),
5642
+ main_image_url varchar(255),
5643
+ thumb_image_url varchar(255),
5644
+ specifications text,
5645
+ description text,
5646
+ search_cache text,
5647
+ description_type varchar(50),
5648
+ medium_image_url varchar(255),
5649
+ Title varchar(255),
5650
+ Weight decimal(15,4),
5651
+ Family varchar(255),
5652
+ Reviews varchar(255),
5653
+ pdf_url varchar(255),
5654
+ product_short_description varchar(255),
5655
+ products_date_added datetime default NULL,
5656
+ products_last_modified datetime default NULL,
5657
+ availability_id_in_stock int(11) default '1',
5658
+ availability_id_out_of_stock int(11) default '2',
5659
+ products_locate varchar(30) default NULL,
5660
+ products_ordered int(11) NOT NULL default '0',
5661
+ products_url varchar(255) default NULL,
5662
+ products_viewed int(5) default '0',
5663
+ products_seo_url varchar(100) NOT NULL,
5664
+ manufacturer_name varchar(255) default NULL,
5665
+ KEY(store_product_id),
5666
+ KEY(sinch_manufacturer_id)
5667
+ )DEFAULT CHARSET=utf8
5668
+ ");
5669
+ }elseif($this->product_file_format == "OLD"){
5670
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
5671
+ store_category_product_id int(11),
5672
+ store_product_id int(11),
5673
+ sinch_product_id int(11),
5674
+ product_sku varchar(255),
5675
+ product_name varchar(255),
5676
+ sinch_manufacturer_id int(11),
5677
+ store_category_id int(11),
5678
+ main_image_url varchar(255),
5679
+ thumb_image_url varchar(255),
5680
+ specifications text,
5681
+ description text,
5682
+ search_cache text,
5683
+ spec_characte_u_count int(11),
5684
+ description_type varchar(50),
5685
+ medium_image_url varchar(255),
5686
+ products_date_added datetime default NULL,
5687
+ products_last_modified datetime default NULL,
5688
+ availability_id_in_stock int(11) default '1',
5689
+ availability_id_out_of_stock int(11) default '2',
5690
+ products_locate varchar(30) default NULL,
5691
+ products_ordered int(11) NOT NULL default '0',
5692
+ products_url varchar(255) default NULL,
5693
+ products_viewed int(5) default '0',
5694
+ products_seo_url varchar(100) NOT NULL,
5695
+ manufacturer_name varchar(255) default NULL,
5696
+ KEY(store_category_product_id),
5697
+ KEY(store_product_id),
5698
+ KEY(sinch_manufacturer_id),
5699
+ KEY(store_category_id)
5700
+ )DEFAULT CHARSET=utf8
5701
+ ");
5702
+
5703
+ }
5704
+ echo("\nParseProducts 3\n");
5705
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5706
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5707
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5708
+ OPTIONALLY ENCLOSED BY '\"'
5709
+ LINES TERMINATED BY \"\r\n\"
5710
+ IGNORE 1 LINES ");
5711
+
5712
+ if($this->product_file_format == "NEW"){
5713
+ $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5714
+ ADD COLUMN sinch_product_id int(11) AFTER store_product_id
5715
+ ");
5716
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5717
+ SET sinch_product_id=store_product_id
5718
+ ");
5719
+
5720
+ $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5721
+ ADD COLUMN store_category_id int(11) AFTER sinch_manufacturer_id
5722
+ ");
5723
+ $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5724
+ ADD KEY(store_category_id)
5725
+ ");
5726
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5727
+ SET product_name = Title WHERE Title != ''
5728
+ ");
5729
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." pt
5730
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
5731
+ SET pt.store_category_id=spc.store_category_id
5732
+ WHERE pt.store_product_id=spc.store_product_id
5733
+ ");
5734
+ //http://redmine.bintime.com/issues/4127
5735
+ //3.
5736
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5737
+ SET main_image_url = medium_image_url WHERE main_image_url = ''
5738
+ ");
5739
+ //end
5740
+
5741
+ }
5742
+
5743
+ echo("\nParseProducts 4\n");
5744
+
5745
+ echo("\nParseProducts 5\n");
5746
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5747
+ SET products_date_added=now(), products_last_modified=now()");
5748
+ echo("\nParseProducts 6\n");
5749
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
5750
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." m
5751
+ ON p.sinch_manufacturer_id=m.sinch_manufacturer_id
5752
+ SET p.manufacturer_name=m.manufacturer_name");
5753
+ echo("\nParseProducts 7\n");
5754
+ if($this->current_import_status_statistic_id){
5755
+ $res = $this->db_do("SELECT COUNT(*) AS cnt
5756
+ FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
5757
+ $row = mysqli_fetch_assoc($res);
5758
+ $this->db_do("UPDATE ".$this->import_status_statistic_table."
5759
+ SET number_of_products=".$row['cnt']."
5760
+ WHERE id=".$this->current_import_status_statistic_id);
5761
+ }
5762
+
5763
+ if ($replace_merge_product == "REWRITE"){
5764
+ $this->db_do ("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'));
5765
+ $this->db_do ("SET FOREIGN_KEY_CHECKS=0");
5766
+ $this->db_do ("TRUNCATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'));
5767
+ $this->db_do ("SET FOREIGN_KEY_CHECKS=1");
5768
+ }
5769
+
5770
+ echo("\nParseProducts 8\n");
5771
+ $this->addProductsWebsite();
5772
+ $this->mapSinchProducts();
5773
+ echo("\nParseProducts 9\n");
5774
+
5775
+ if (count($coincidence) == 1)
5776
+ {
5777
+ $this->replaceMagentoProducts();
5778
+ }
5779
+ else
5780
+ {
5781
+ echo("\n\n\n\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ [".$this->im_type."] $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n\n\n"); //exit;
5782
+
5783
+
5784
+ switch ($this->im_type)
5785
+ {
5786
+ case "REWRITE": $this->replaceMagentoProductsMultistore($coincidence); break;
5787
+ case "MERGE": $this->replaceMagentoProductsMultistoreMERGE($coincidence); break;
5788
+ }
5789
+ }
5790
+ echo("\nParseProducts 10\n");
5791
+
5792
+
5793
+ $this->mapSinchProducts();
5794
+ $this->addManufacturer_attribute();
5795
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
5796
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5797
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
5798
+ $this->_LOG("Finish parse ".FILE_PRODUCTS);
5799
+ }else{
5800
+ $this->_LOG("Wrong file ".$parse_file);
5801
+ }
5802
+ $this->_LOG(" ");
5803
+ echo("\nParseProducts 11\n");
5804
+ }
5805
+
5806
+ #################################################################################################
5807
+
5808
+ function ParseRelatedProducts(){
5809
+
5810
+ $parse_file=$this->varDir.FILE_RELATED_PRODUCTS;
5811
+ if(filesize($parse_file) || $this->_ignore_product_related){
5812
+ $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
5813
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('related_products_temp'));
5814
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."(
5815
+ sinch_product_id int(11),
5816
+ related_sinch_product_id int(11),
5817
+ store_product_id int(11) default null,
5818
+ store_related_product_id int(11) default null,
5819
+ entity_id int(11),
5820
+ related_entity_id int(11),
5821
+ KEY(sinch_product_id),
5822
+ KEY(related_sinch_product_id),
5823
+ KEY(store_product_id)
5824
+ )DEFAULT CHARSET=utf8");
5825
+ if(!$this->_ignore_product_related){
5826
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5827
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
5828
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5829
+ OPTIONALLY ENCLOSED BY '\"'
5830
+ LINES TERMINATED BY \"\r\n\"
5831
+ IGNORE 1 LINES ");
5832
+ }
5833
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
5834
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
5835
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
5836
+
5837
+ $this->_LOG("Finish parse ".FILE_RELATED_PRODUCTS);
5838
+ }else{
5839
+ $this->_LOG("Wrong file ".$parse_file);
5840
+ }
5841
+ $this->_LOG(" ");
5842
+ }
5843
+
5844
+ #################################################################################################
5845
+
5846
+ function ParseRestrictedValues(){
5847
+
5848
+ $parse_file=$this->varDir.FILE_RESTRICTED_VALUES;
5849
+ if(filesize($parse_file) || $this->_ignore_restricted_values){
5850
+ $this->_LOG("Start parse ".FILE_RESTRICTED_VALUES);
5851
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp'));
5852
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')." (
5853
+ restricted_value_id int(11),
5854
+ category_feature_id int(11),
5855
+ text text,
5856
+ display_order_number int(11),
5857
+ KEY(restricted_value_id),
5858
+ KEY(category_feature_id)
5859
+ )");
5860
+ if(!$this->_ignore_restricted_values){
5861
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5862
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
5863
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5864
+ OPTIONALLY ENCLOSED BY '\"'
5865
+ LINES TERMINATED BY \"\r\n\"
5866
+ IGNORE 1 LINES ");
5867
+ }
5868
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
5869
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
5870
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
5871
+
5872
+ $this->_LOG("Finish parse ".FILE_RESTRICTED_VALUES);
5873
+ }else{
5874
+ $this->_LOG("Wrong file ".$parse_file);
5875
+ }
5876
+ $this->_LOG(" ");
5877
+ }
5878
+
5879
+ #################################################################################################
5880
+
5881
+ function ParseStockAndPrices(){
5882
+
5883
+ $parse_file=$this->varDir.FILE_STOCK_AND_PRICES;
5884
+ if(filesize($parse_file)){
5885
+ $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
5886
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp'));
5887
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." (
5888
+ store_product_id int(11),
5889
+ stock int(11),
5890
+ price decimal(15,4),
5891
+ cost decimal(15,4),
5892
+ distributor_id int(11),
5893
+ KEY(store_product_id),
5894
+ KEY(distributor_id)
5895
+ )");
5896
+
5897
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5898
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
5899
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5900
+ OPTIONALLY ENCLOSED BY '\"'
5901
+ LINES TERMINATED BY \"\r\n\"
5902
+ IGNORE 1 LINES ");
5903
+
5904
+ $this->replaceMagentoProductsStockPrice();
5905
+
5906
+ $res = $this->db_do("SELECT count(*) as cnt
5907
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5908
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5909
+ ON a.store_product_id=b.store_product_id");
5910
+ $row = mysqli_fetch_assoc($res);
5911
+ $this->db_do("UPDATE ".$this->import_status_statistic_table."
5912
+ SET number_of_products=".$row['cnt']."
5913
+ WHERE id=".$this->current_import_status_statistic_id);
5914
+
5915
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
5916
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
5917
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
5918
+
5919
+ $this->_LOG("Finish parse".FILE_RELATED_PRODUCTS);
5920
+ }else{
5921
+ $this->_LOG("Wrong file".$parse_file);
5922
+ }
5923
+ $this->_LOG(" ");
5924
+ }
5925
+
5926
+ #################################################################################################
5927
+
5928
+ function ParseProductsPicturesGallery(){
5929
+
5930
+ $parse_file=$this->varDir.FILE_PRODUCTS_PICTURES_GALLERY;
5931
+ if(filesize($parse_file)){
5932
+ $this->_LOG("Start parse ".FILE_PRODUCTS_PICTURES_GALLERY);
5933
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp'));
5934
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." (
5935
+ sinch_product_id int(11),
5936
+ image_url varchar(255),
5937
+ thumb_image_url varchar(255),
5938
+ store_product_id int(11),
5939
+ key(sinch_product_id),
5940
+ key(store_product_id)
5941
+ )");
5942
+
5943
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5944
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
5945
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5946
+ OPTIONALLY ENCLOSED BY '\"'
5947
+ LINES TERMINATED BY \"\r\n\"
5948
+ IGNORE 1 LINES ");
5949
+
5950
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." ppgt
5951
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
5952
+ ON ppgt.sinch_product_id=sp.sinch_product_id
5953
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5954
+ ON sp.store_product_id=cpe.store_product_id
5955
+ SET ppgt.store_product_id=sp.store_product_id");
5956
+
5957
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
5958
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
5959
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
5960
+
5961
+ $this->_LOG("Finish parse".FILE_PRODUCTS_PICTURES_GALLERY);
5962
+ }else{
5963
+ $this->_LOG("Wrong file".$parse_file);
5964
+ }
5965
+ $this->_LOG(" ");
5966
+
5967
+ }
5968
+
5969
+ #################################################################################################
5970
+
5971
+ function ParsePriceRules(){
5972
+ $parse_file=$this->varDir.FILE_PRICE_RULES;
5973
+ if(filesize($parse_file) || $this->_ignore_price_rules){
5974
+ $this->_LOG("Start parse ".FILE_PRICE_RULES);
5975
+
5976
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp'));
5977
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."(
5978
+ `id` int(11) NOT NULL,
5979
+ `price_from` decimal(10,2) DEFAULT NULL,
5980
+ `price_to` decimal(10,2) DEFAULT NULL,
5981
+ `category_id` int(10) unsigned DEFAULT NULL,
5982
+ `vendor_id` int(11) DEFAULT NULL,
5983
+ `vendor_product_id` varchar(255) DEFAULT NULL,
5984
+ `customergroup_id` varchar(32) DEFAULT NULL,
5985
+ `marge` decimal(10,2) DEFAULT NULL,
5986
+ `fixed` decimal(10,2) DEFAULT NULL,
5987
+ `final_price` decimal(10,2) DEFAULT NULL,
5988
+ PRIMARY KEY (`id`),
5989
+ UNIQUE KEY `price_from` (`price_from`,`price_to`,`vendor_id`,`category_id`,`vendor_product_id`,`customergroup_id`),
5990
+ KEY `vendor_product_id` (`vendor_product_id`),
5991
+ KEY `category_id` (`category_id`)
5992
+ )
5993
+ ");
5994
+ if(!$this->_ignore_price_rules){
5995
+
5996
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5997
+ INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
5998
+ FIELDS TERMINATED BY '".$this->field_terminated_char."'
5999
+ OPTIONALLY ENCLOSED BY '\"'
6000
+ LINES TERMINATED BY \"\r\n\"
6001
+ IGNORE 1 LINES
6002
+ (id, @vprice_from, @vprice_to, @vcategory_id, @vvendor_id, @vvendor_product_id, @vcustomergroup_id, @vmarge, @vfixed, @vfinal_price)
6003
+ SET price_from = nullif(@vprice_from,''),
6004
+ price_to = nullif(@vprice_to,''),
6005
+ category_id = nullif(@vcategory_id,''),
6006
+ vendor_id = nullif(@vvendor_id,''),
6007
+ vendor_product_id = nullif(@vvendor_product_id,''),
6008
+ customergroup_id = nullif(@vcustomergroup_id,''),
6009
+ marge = nullif(@vmarge,''),
6010
+ fixed = nullif(@vfixed,''),
6011
+ final_price = nullif(@vfinal_price,'')
6012
+ ");
6013
+ }
6014
+
6015
+ $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6016
+ ADD COLUMN `shop_category_id` int(10) unsigned DEFAULT NULL,
6017
+ ADD COLUMN `shop_vendor_id` int(11) DEFAULT NULL,
6018
+ ADD COLUMN `shop_vendor_product_id` varchar(255) DEFAULT NULL,
6019
+ ADD COLUMN `shop_customergroup_id` varchar(32) DEFAULT NULL
6020
+ ");
6021
+
6022
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6023
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6024
+ ON prt.category_id = cce.store_category_id
6025
+ SET prt.shop_category_id = cce.entity_id");
6026
+
6027
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6028
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." sicm
6029
+ ON prt.vendor_id = sicm.sinch_manufacturer_id
6030
+ SET prt.shop_vendor_id = sicm.shop_option_id");
6031
+
6032
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6033
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." sicpm
6034
+ ON prt.vendor_product_id = sicpm.product_sku
6035
+ SET prt.shop_vendor_product_id = sicpm.sku");
6036
+
6037
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6038
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('customer_group')." cg
6039
+ ON prt.customergroup_id = cg.customer_group_id
6040
+ SET prt.shop_customergroup_id = cg.customer_group_id");
6041
+
6042
+ $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6043
+ WHERE
6044
+ (category_id IS NOT NULL AND shop_category_id IS NULL) OR
6045
+ (vendor_id IS NOT NULL AND shop_vendor_id IS NULL) OR
6046
+ (vendor_product_id IS NOT NULL AND shop_vendor_product_id IS NULL) OR
6047
+ (customergroup_id IS NOT NULL AND shop_customergroup_id IS NULL)
6048
+ ");
6049
+
6050
+
6051
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules'));
6052
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6053
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules'));
6054
+
6055
+ $this->_LOG("Finish parse ".FILE_PRICE_RULES);
6056
+ }else{
6057
+ $this->_LOG("Wrong file ".$parse_file);
6058
+ }
6059
+ $this->_LOG(" ");
6060
+ }
6061
+
6062
+ #################################################################################################
6063
+
6064
+ function AddPriceRules(){
6065
+ if (!$this->check_table_exist('import_pricerules_standards')){
6066
+ return;
6067
+ }
6068
+
6069
+ $result = $this->db_do("
6070
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('import_pricerules')." (
6071
+ id,
6072
+ price_from,
6073
+ price_to,
6074
+ vendor_id,
6075
+ category_id,
6076
+ vendor_product_id,
6077
+ customergroup_id,
6078
+ marge,
6079
+ fixed,
6080
+ final_price
6081
+ )(SELECT
6082
+ id,
6083
+ price_from,
6084
+ price_to,
6085
+ shop_vendor_id,
6086
+ shop_category_id,
6087
+ shop_vendor_product_id,
6088
+ shop_customergroup_id,
6089
+ marge,
6090
+ fixed,
6091
+ final_price
6092
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules')." a
6093
+ )
6094
+ ON DUPLICATE KEY UPDATE
6095
+ id = a.id,
6096
+ price_from = a.price_from,
6097
+ price_to = a.price_to,
6098
+ vendor_id = a.shop_vendor_id,
6099
+ category_id = a.shop_category_id,
6100
+ vendor_product_id = a.shop_vendor_product_id,
6101
+ customergroup_id = a.shop_customergroup_id,
6102
+ marge = a.marge,
6103
+ fixed = a.fixed,
6104
+ final_price = a.final_price
6105
+ ");
6106
+
6107
+ }
6108
+
6109
+ #################################################################################################
6110
+
6111
+ public function mapSinchProducts(){
6112
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
6113
+ $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
6114
+ entity_id int(11) unsigned NOT NULL,
6115
+ manufacturer_option_id int(11),
6116
+ manufacturer_name varchar(255),
6117
+ shop_store_product_id int(11),
6118
+ shop_sinch_product_id int(11),
6119
+ sku varchar(64) default NULL,
6120
+ store_product_id int(11),
6121
+ sinch_product_id int(11),
6122
+ product_sku varchar(255),
6123
+ sinch_manufacturer_id int(11),
6124
+ sinch_manufacturer_name varchar(255),
6125
+ KEY entity_id (entity_id),
6126
+ KEY manufacturer_option_id (manufacturer_option_id),
6127
+ KEY manufacturer_name (manufacturer_name),
6128
+ KEY store_product_id (store_product_id),
6129
+ KEY sinch_product_id (sinch_product_id),
6130
+ KEY sku (sku),
6131
+ UNIQUE KEY(entity_id)
6132
+ )
6133
+ ");
6134
+ $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
6135
+ LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
6136
+ $result = $this->db_do("
6137
+ INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
6138
+ entity_id,
6139
+ sku,
6140
+ shop_store_product_id,
6141
+ shop_sinch_product_id
6142
+ )(SELECT
6143
+ entity_id,
6144
+ sku,
6145
+ store_product_id,
6146
+ sinch_product_id
6147
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')."
6148
+ )
6149
+ ");
6150
+
6151
+ $this->addManufacturers(1);
6152
+
6153
+ $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6154
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." cpie
6155
+ ON pmt.entity_id=cpie.entity_id
6156
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
6157
+ ON cpie.value=aov.option_id
6158
+ SET
6159
+ manufacturer_option_id=cpie.value,
6160
+ manufacturer_name=aov.value
6161
+ WHERE cpie.attribute_id=".$this->attributes['manufacturer'];
6162
+ $this->db_do($q);
6163
+
6164
+ $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6165
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6166
+ ON pmt.sku=p.product_sku
6167
+ SET
6168
+ pmt.store_product_id=p.store_product_id,
6169
+ pmt.sinch_product_id=p.sinch_product_id,
6170
+ pmt.product_sku=p.product_sku,
6171
+ pmt.sinch_manufacturer_id=p.sinch_manufacturer_id,
6172
+ pmt.sinch_manufacturer_name=p.manufacturer_name";
6173
+
6174
+ $this->db_do($q);
6175
+
6176
+ $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6177
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6178
+ ON cpe.entity_id=pmt.entity_id
6179
+ SET cpe.store_product_id=pmt.store_product_id,
6180
+ cpe.sinch_product_id=pmt.sinch_product_id
6181
+ WHERE
6182
+ cpe.sinch_product_id IS NULL
6183
+ AND pmt.sinch_product_id IS NOT NULL
6184
+ AND cpe.store_product_id IS NULL
6185
+ AND pmt.store_product_id IS NOT NULL";
6186
+ $this->db_do($q);
6187
+
6188
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
6189
+ $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')."
6190
+ TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
6191
+ }
6192
+ #################################################################################################
6193
+ public function addProductsWebsite (){
6194
+ $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_website_temp'));
6195
+ // TEMPORARY
6196
+ $this->db_do("
6197
+ CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('products_website_temp')."` (
6198
+ `id` int(10) unsigned NOT NULL auto_increment,
6199
+ store_product_id int(11),
6200
+ sinch_product_id int(11),
6201
+ `website` int(11) default NULL,
6202
+ `website_id` int(11) default NULL,
6203
+ PRIMARY KEY (`id`),
6204
+ KEY store_product_id (`store_product_id`)
6205
+ )
6206
+ ");
6207
+ $result = $this->db_do("SELECT
6208
+ website_id,
6209
+ store_id as website
6210
+ FROM ".Mage::getSingleton('core/resource')->getTableName('core_store')."
6211
+ WHERE code!='admin'
6212
+ "); // where code!='admin' was adder for editing Featured products;
6213
+ while ($row = mysqli_fetch_assoc($result)) {
6214
+ $sql = "INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." (
6215
+ store_product_id,
6216
+ sinch_product_id,
6217
+ website,
6218
+ website_id
6219
+ )(
6220
+ SELECT
6221
+ distinct
6222
+ store_product_id,
6223
+ sinch_product_id,
6224
+ {$row['website']},
6225
+ {$row['website_id']}
6226
+ FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
6227
+ )";
6228
+ $result2 = $this->db_do($sql);
6229
+ }
6230
+
6231
+
6232
+ }
6233
+
6234
+ #################################################################################################
6235
+ public function replaceMagentoProducts() {
6236
+
6237
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
6238
+
6239
+ $result = $this->db_do("DELETE cpe
6240
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6241
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6242
+ ON cpe.entity_id=pm.entity_id
6243
+ WHERE pm.shop_store_product_id IS NOT NULL
6244
+ AND pm.store_product_id IS NULL
6245
+ ");
6246
+
6247
+ //Inserting new products and updating old others.
6248
+ $this->_getProductDefaulAttributeSetId();
6249
+ $result = $this->db_do("
6250
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." (
6251
+ entity_id,
6252
+ entity_type_id,
6253
+ attribute_set_id,
6254
+ type_id,
6255
+ sku,
6256
+ updated_at,
6257
+ has_options,
6258
+ store_product_id,
6259
+ sinch_product_id
6260
+ )(SELECT
6261
+ pm.entity_id,
6262
+ " . $this->_getProductEntityTypeId(). ",
6263
+ $this->defaultAttributeSetId,
6264
+ 'simple',
6265
+ a.product_sku,
6266
+ NOW(),
6267
+ 0,
6268
+ a.store_product_id,
6269
+ a.sinch_product_id
6270
+ FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')." a
6271
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6272
+ ON a.store_product_id=pm.store_product_id
6273
+ AND a.sinch_product_id=pm.sinch_product_id
6274
+ WHERE pm.entity_id IS NOT NULL
6275
+ )
6276
+ ON DUPLICATE KEY UPDATE
6277
+ sku= a.product_sku,
6278
+ store_product_id=a.store_product_id,
6279
+ sinch_product_id=a.sinch_product_id
6280
+ ");
6281
+ // store_product_id=a.store_product_id,
6282
+ // sinch_product_id=a.sinch_product_id
6283
+
6284
+ $result = $this->db_do("
6285
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." (
6286
+ entity_id,
6287
+ entity_type_id,
6288
+ attribute_set_id,
6289
+ type_id,
6290
+ sku,
6291
+ updated_at,
6292
+ has_options,
6293
+ store_product_id,
6294
+ sinch_product_id
6295
+ )(SELECT
6296
+ pm.entity_id,
6297
+ " . $this->_getProductEntityTypeId(). ",
6298
+ $this->defaultAttributeSetId,
6299
+ 'simple',
6300
+ a.product_sku,
6301
+ NOW(),
6302
+ 0,
6303
+ a.store_product_id,
6304
+ a.sinch_product_id
6305
+ FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')." a
6306
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6307
+ ON a.store_product_id=pm.store_product_id
6308
+ AND a.sinch_product_id=pm.sinch_product_id
6309
+ WHERE pm.entity_id IS NULL
6310
+ )
6311
+ ON DUPLICATE KEY UPDATE
6312
+ sku= a.product_sku,
6313
+ store_product_id=a.store_product_id,
6314
+ sinch_product_id=a.sinch_product_id
6315
+ ");
6316
+ // store_product_id=a.store_product_id,
6317
+ // sinch_product_id=a.sinch_product_id
6318
+
6319
+ //Set enabled
6320
+ $result = $this->db_do("DELETE cpei
6321
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." cpei
6322
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6323
+ ON cpei.entity_id=cpe.entity_id
6324
+ WHERE cpe.entity_id IS NULL");
6325
+
6326
+ $result = $this->db_do("
6327
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6328
+ entity_type_id,
6329
+ attribute_id,
6330
+ store_id,
6331
+ entity_id,
6332
+ value
6333
+ )(
6334
+ SELECT
6335
+ " . $this->_getProductEntityTypeId(). ",
6336
+ ". $this->_getProductAttributeId('status').",
6337
+ w.website,
6338
+ a.entity_id,
6339
+ 1
6340
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6341
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6342
+ ON a.store_product_id=w.store_product_id
6343
+ )
6344
+ ON DUPLICATE KEY UPDATE
6345
+ value=1
6346
+ ");
6347
+ // set status = 1 for all stores
6348
+ $result = $this->db_do("
6349
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6350
+ entity_type_id,
6351
+ attribute_id,
6352
+ store_id,
6353
+ entity_id,
6354
+ value
6355
+ )(SELECT
6356
+ " . $this->_getProductEntityTypeId(). ",
6357
+ ".$this->_getProductAttributeId('status').",
6358
+ 0,
6359
+ a.entity_id,
6360
+ 1
6361
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6362
+ )
6363
+ ON DUPLICATE KEY UPDATE
6364
+ value=1
6365
+ ");
6366
+
6367
+ //Unifying products with categories.
6368
+ $result = $this->db_do("DELETE ccp
6369
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6370
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6371
+ ON ccp.product_id=cpe.entity_id
6372
+ WHERE cpe.entity_id IS NULL");
6373
+
6374
+ echo("\n\n\nUPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6375
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6376
+ ON ccp.category_id=cce.entity_id
6377
+ SET ccp.category_id=".$this->_root_cat."
6378
+ WHERE cce.entity_id IS NULL");
6379
+ $result = $this->db_do("UPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6380
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6381
+ ON ccp.category_id=cce.entity_id
6382
+ SET ccp.category_id=".$this->_root_cat."
6383
+ WHERE cce.entity_id IS NULL");
6384
+ echo("\ndone\n");
6385
+
6386
+
6387
+ echo("\n\n\nDELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6388
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6389
+ ON ccp.category_id=cce.entity_id
6390
+ WHERE cce.entity_id IS NULL");
6391
+ $result = $this->db_do("DELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6392
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6393
+ ON ccp.category_id=cce.entity_id
6394
+ WHERE cce.entity_id IS NULL");
6395
+ echo("\ndone\n");
6396
+
6397
+
6398
+ $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp");
6399
+ // TEMPORARY
6400
+ $this->db_do("
6401
+ CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp` (
6402
+ `category_id` int(10) unsigned NOT NULL default '0',
6403
+ `product_id` int(10) unsigned NOT NULL default '0',
6404
+ `store_product_id` int(10) NOT NULL default '0',
6405
+ `store_category_id` int(10) NOT NULL default '0',
6406
+ `new_category_id` int(10) NOT NULL default '0',
6407
+ UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
6408
+ KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
6409
+ KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
6410
+ KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
6411
+ )
6412
+
6413
+ ");
6414
+
6415
+ $result = $this->db_do("
6416
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp (
6417
+ category_id,
6418
+ product_id,
6419
+ store_product_id
6420
+ )(SELECT
6421
+ ccp.category_id,
6422
+ ccp.product_id,
6423
+ cpe.store_product_id
6424
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6425
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6426
+ ON ccp.product_id=cpe.entity_id
6427
+ WHERE store_product_id is not null
6428
+ )
6429
+ ");
6430
+
6431
+ $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6432
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6433
+ ON ccpfd.store_product_id=p.store_product_id
6434
+ SET ccpfd.store_category_id=p.store_category_id
6435
+ WHERE ccpfd.store_product_id!=0
6436
+ ");
6437
+
6438
+ $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6439
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6440
+ ON ccpfd.store_category_id=scm.store_category_id
6441
+ SET ccpfd.new_category_id=scm.shop_entity_id
6442
+ WHERE ccpfd.store_category_id!=0
6443
+ ");
6444
+
6445
+ $result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp
6446
+ WHERE category_id=new_category_id");
6447
+
6448
+ $result = $this->db_do("
6449
+ DELETE ccp
6450
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6451
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6452
+ ON ccp.product_id=ccpfd.product_id
6453
+ AND ccp.category_id=ccpfd.category_id
6454
+ ");
6455
+
6456
+ $result = $this->db_do("
6457
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." (
6458
+ category_id,
6459
+ product_id
6460
+ )(SELECT
6461
+ scm.shop_entity_id,
6462
+ cpe.entity_id
6463
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6464
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6465
+ ON cpe.store_product_id=p.store_product_id
6466
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6467
+ ON p.store_category_id=scm.store_category_id
6468
+ )
6469
+ ON DUPLICATE KEY UPDATE
6470
+ product_id = cpe.entity_id
6471
+ ");
6472
+
6473
+
6474
+ //add multi categories;
6475
+
6476
+
6477
+
6478
+
6479
+ $result = $this->db_do("
6480
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."
6481
+ (category_id, product_id)
6482
+ (SELECT
6483
+ scm.shop_entity_id,
6484
+ cpe.entity_id
6485
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6486
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6487
+ ON cpe.store_product_id = p.store_product_id
6488
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
6489
+ ON p.store_product_id=spc.store_product_id
6490
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6491
+ ON spc.store_category_id = scm.store_category_id
6492
+ )
6493
+ ON DUPLICATE KEY UPDATE
6494
+ product_id = cpe.entity_id
6495
+ ");
6496
+
6497
+
6498
+
6499
+
6500
+ //Indexing products and categories in the shop
6501
+ $result = $this->db_do("DELETE ccpi
6502
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." ccpi
6503
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6504
+ ON ccpi.product_id=cpe.entity_id
6505
+ WHERE cpe.entity_id IS NULL");
6506
+
6507
+ $result = $this->db_do("
6508
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
6509
+ category_id,
6510
+ product_id,
6511
+ position,
6512
+ is_parent,
6513
+ store_id,
6514
+ visibility
6515
+ )(
6516
+ SELECT
6517
+ a.category_id,
6518
+ a.product_id,
6519
+ a.position,
6520
+ 1,
6521
+ b.store_id,
6522
+ 4
6523
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
6524
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
6525
+ )
6526
+ ON DUPLICATE KEY UPDATE
6527
+ visibility = 4
6528
+ ");
6529
+
6530
+ $result = $this->db_do("
6531
+ INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
6532
+ category_id,
6533
+ product_id,
6534
+ position,
6535
+ is_parent,
6536
+ store_id,
6537
+ visibility
6538
+ )(
6539
+ SELECT
6540
+ ".$this->_root_cat.",
6541
+ a.product_id,
6542
+ a.position,
6543
+ 1,
6544
+ b.store_id,
6545
+ 4
6546
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
6547
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
6548
+ )
6549
+ ON DUPLICATE KEY UPDATE
6550
+ visibility = 4
6551
+ ");
6552
+
6553
+ //Set product name for specific web sites
6554
+ $result = $this->db_do("DELETE cpev
6555
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." cpev
6556
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6557
+ ON cpev.entity_id=cpe.entity_id
6558
+ WHERE cpe.entity_id IS NULL");
6559
+ $result = $this->db_do("
6560
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6561
+ entity_type_id,
6562
+ attribute_id,
6563
+ store_id,
6564
+ entity_id,
6565
+ value
6566
+ )(SELECT
6567
+ " . $this->_getProductEntityTypeId(). ",
6568
+ " . $this->_getProductAttributeId('name'). ",
6569
+ w.website,
6570
+ a.entity_id,
6571
+ b.product_name
6572
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6573
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6574
+ ON a.store_product_id= b.store_product_id
6575
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6576
+ ON a.store_product_id=w.store_product_id
6577
+ )
6578
+ ON DUPLICATE KEY UPDATE
6579
+ value = b.product_name
6580
+ ");
6581
+
6582
+ // product name for all web sites
6583
+ $result = $this->db_do("
6584
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6585
+ entity_type_id,
6586
+ attribute_id,
6587
+ store_id,
6588
+ entity_id,
6589
+ value
6590
+ )(
6591
+ SELECT
6592
+ " . $this->_getProductEntityTypeId(). ",
6593
+ " . $this->_getProductAttributeId('name'). ",
6594
+ 0,
6595
+ a.entity_id,
6596
+ b.product_name
6597
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6598
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6599
+ ON a.store_product_id = b.store_product_id
6600
+ )
6601
+ ON DUPLICATE KEY UPDATE
6602
+ value = b.product_name
6603
+ ");
6604
+
6605
+ $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
6606
+ $this->addDescriptions();
6607
+ $this->cleanProductDistributors();
6608
+ if($this->product_file_format == "NEW"){
6609
+ $this->addReviews();
6610
+ $this->addWeight();
6611
+ $this->addSearchCache();
6612
+ $this->addPdfUrl();
6613
+ $this->addShortDescriptions();
6614
+ $this->addProductDistributors();
6615
+ }
6616
+ $this->addEAN();
6617
+ $this->addSpecification();
6618
+ $this->addManufacturers();
6619
+
6620
+ //Enabling product index.
6621
+ $result = $this->db_do("DELETE cpei
6622
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." cpei
6623
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6624
+ ON cpei.product_id=cpe.entity_id
6625
+ WHERE cpe.entity_id IS NULL");
6626
+
6627
+ $result = $this->db_do("
6628
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
6629
+ product_id,
6630
+ store_id,
6631
+ visibility
6632
+ )(
6633
+ SELECT
6634
+ a.entity_id,
6635
+ w.website,
6636
+ 4
6637
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6638
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6639
+ ON a.store_product_id=w.store_product_id
6640
+ )
6641
+ ON DUPLICATE KEY UPDATE
6642
+ visibility = 4
6643
+ ");
6644
+ $result = $this->db_do("
6645
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
6646
+ product_id,
6647
+ store_id,
6648
+ visibility
6649
+ )(
6650
+ SELECT
6651
+ a.entity_id,
6652
+ 0,
6653
+ 4
6654
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6655
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6656
+ ON a.store_product_id=w.store_product_id
6657
+ )
6658
+ ON DUPLICATE KEY UPDATE
6659
+ visibility = 4
6660
+ ");
6661
+
6662
+
6663
+ $result = $this->db_do("
6664
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6665
+ entity_type_id,
6666
+ attribute_id,
6667
+ store_id,
6668
+ entity_id,
6669
+ value
6670
+ )(
6671
+ SELECT
6672
+ " . $this->_getProductEntityTypeId(). ",
6673
+ " . $this->_getProductAttributeId('visibility'). ",
6674
+ w.website,
6675
+ a.entity_id,
6676
+ 4
6677
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6678
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6679
+ ON a.store_product_id=w.store_product_id
6680
+ )
6681
+ ON DUPLICATE KEY UPDATE
6682
+ value = 4
6683
+ ");
6684
+
6685
+ $result = $this->db_do("
6686
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6687
+ entity_type_id,
6688
+ attribute_id,
6689
+ store_id,
6690
+ entity_id,
6691
+ value
6692
+ )(
6693
+ SELECT
6694
+ " . $this->_getProductEntityTypeId(). ",
6695
+ " . $this->_getProductAttributeId('visibility'). ",
6696
+ 0,
6697
+ a.entity_id,
6698
+ 4
6699
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6700
+ )
6701
+ ON DUPLICATE KEY UPDATE
6702
+ value = 4
6703
+ ");
6704
+
6705
+ $result = $this->db_do("DELETE cpw
6706
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." cpw
6707
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6708
+ ON cpw.product_id=cpe.entity_id
6709
+ WHERE cpe.entity_id IS NULL");
6710
+
6711
+ $result = $this->db_do("
6712
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." (
6713
+ product_id,
6714
+ website_id
6715
+ )(
6716
+ SELECT a.entity_id, w.website_id
6717
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6718
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6719
+ ON a.store_product_id=w.store_product_id
6720
+ )
6721
+ ON DUPLICATE KEY UPDATE
6722
+ product_id=a.entity_id,
6723
+ website_id=w.website_id
6724
+ ");
6725
+
6726
+ // temporary disabled mart@bintime.com
6727
+ //$result = $this->db_do("
6728
+ // UPDATE catalog_category_entity_int a
6729
+ // SET a.value = 0
6730
+ // WHERE a.attribute_id = 32
6731
+ //");
6732
+
6733
+
6734
+ //Adding tax class "Taxable Goods"
6735
+ $result = $this->db_do("
6736
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6737
+ entity_type_id,
6738
+ attribute_id,
6739
+ store_id,
6740
+ entity_id,
6741
+ value
6742
+ )(
6743
+ SELECT
6744
+ " . $this->_getProductEntityTypeId(). ",
6745
+ " . $this->_getProductAttributeId('tax_class_id'). ",
6746
+ w.website,
6747
+ a.entity_id,
6748
+ 2
6749
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6750
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6751
+ ON a.store_product_id=w.store_product_id
6752
+ )
6753
+ ON DUPLICATE KEY UPDATE
6754
+ value = 2
6755
+ ");
6756
+ $result = $this->db_do("
6757
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6758
+ entity_type_id,
6759
+ attribute_id,
6760
+ store_id,
6761
+ entity_id,
6762
+ value
6763
+ )(
6764
+ SELECT
6765
+ " . $this->_getProductEntityTypeId(). ",
6766
+ " . $this->_getProductAttributeId('tax_class_id'). ",
6767
+ 0,
6768
+ a.entity_id,
6769
+ 2
6770
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6771
+ )
6772
+ ON DUPLICATE KEY UPDATE
6773
+ value = 2
6774
+ ");
6775
+
6776
+ // Load url Image
6777
+ $result = $this->db_do("
6778
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6779
+ entity_type_id,
6780
+ attribute_id,
6781
+ store_id,
6782
+ entity_id,
6783
+ value
6784
+ )(
6785
+ SELECT
6786
+ " . $this->_getProductEntityTypeId(). ",
6787
+ " . $this->_getProductAttributeId('image'). ",
6788
+ w.store_id,
6789
+ a.entity_id,
6790
+ b.main_image_url
6791
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6792
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6793
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6794
+ ON a.store_product_id = b.store_product_id
6795
+ )
6796
+ ON DUPLICATE KEY UPDATE
6797
+ value = b.main_image_url
6798
+ ");
6799
+
6800
+
6801
+ // image for specific web sites
6802
+ $result = $this->db_do("
6803
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6804
+ entity_type_id,
6805
+ attribute_id,
6806
+ store_id,
6807
+ entity_id,
6808
+ value
6809
+ )(
6810
+ SELECT
6811
+ " . $this->_getProductEntityTypeId(). ",
6812
+ " . $this->_getProductAttributeId('image'). ",
6813
+ 0,
6814
+ a.entity_id,
6815
+ b.main_image_url
6816
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6817
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6818
+ ON a.store_product_id = b.store_product_id
6819
+ )
6820
+ ON DUPLICATE KEY UPDATE
6821
+ value = b.main_image_url
6822
+ ");
6823
+
6824
+
6825
+ // small_image for specific web sites
6826
+ $result = $this->db_do("
6827
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6828
+ entity_type_id,
6829
+ attribute_id,
6830
+ store_id,
6831
+ entity_id,
6832
+ value
6833
+ )(
6834
+ SELECT
6835
+ " . $this->_getProductEntityTypeId(). ",
6836
+ " . $this->_getProductAttributeId('small_image'). ",
6837
+ w.store_id,
6838
+ a.entity_id,
6839
+ b.medium_image_url
6840
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6841
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6842
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6843
+ ON a.store_product_id = b.store_product_id
6844
+ )
6845
+ ON DUPLICATE KEY UPDATE
6846
+ value = b.medium_image_url
6847
+ ");
6848
+
6849
+
6850
+ // small_image for all web sites
6851
+ $result = $this->db_do("
6852
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6853
+ entity_type_id,
6854
+ attribute_id,
6855
+ store_id,
6856
+ entity_id,
6857
+ value
6858
+ )(
6859
+ SELECT
6860
+ " . $this->_getProductEntityTypeId(). ",
6861
+ " . $this->_getProductAttributeId('small_image'). ",
6862
+ 0,
6863
+ a.entity_id,
6864
+ b.medium_image_url
6865
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6866
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6867
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6868
+ ON a.store_product_id = b.store_product_id
6869
+ )
6870
+ ON DUPLICATE KEY UPDATE
6871
+ value = b.medium_image_url
6872
+ ");
6873
+
6874
+
6875
+ // thumbnail for specific web site
6876
+ $result = $this->db_do("
6877
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6878
+ entity_type_id,
6879
+ attribute_id,
6880
+ store_id,
6881
+ entity_id,
6882
+ value
6883
+ )(
6884
+ SELECT
6885
+ " . $this->_getProductEntityTypeId(). ",
6886
+ " . $this->_getProductAttributeId('thumbnail'). ",
6887
+ w.store_id,
6888
+ a.entity_id,
6889
+ b.thumb_image_url
6890
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6891
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6892
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6893
+ ON a.store_product_id = b.store_product_id
6894
+ )
6895
+ ON DUPLICATE KEY UPDATE
6896
+ value = b.thumb_image_url
6897
+ ");
6898
+
6899
+
6900
+ // thumbnail for all web sites
6901
+ $result = $this->db_do("
6902
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6903
+ entity_type_id,
6904
+ attribute_id,
6905
+ store_id,
6906
+ entity_id,
6907
+ value
6908
+ )(
6909
+ SELECT
6910
+ " . $this->_getProductEntityTypeId(). ",
6911
+ " . $this->_getProductAttributeId('thumbnail'). ",
6912
+ 0,
6913
+ a.entity_id,
6914
+ b.thumb_image_url
6915
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6916
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6917
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6918
+ ON a.store_product_id = b.store_product_id
6919
+ )
6920
+ ON DUPLICATE KEY UPDATE
6921
+ value = b.thumb_image_url
6922
+
6923
+ ");
6924
+
6925
+ /*STP DELETE
6926
+ //Refresh fulltext search
6927
+ $result = $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp");
6928
+ $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS
6929
+ ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp
6930
+ LIKE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext'));
6931
+
6932
+ $result = $this->db_do("
6933
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
6934
+ product_id,
6935
+ store_id,
6936
+ data_index
6937
+ )(
6938
+ SELECT
6939
+ a.entity_id,
6940
+ w.website,
6941
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6942
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6943
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6944
+ ON a.store_product_id=w.store_product_id
6945
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
6946
+ ON a.entity_id = b.product_id
6947
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
6948
+ ON b.category_id = c.entity_id
6949
+ AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
6950
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
6951
+ ON a.entity_id = e.entity_id
6952
+ AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
6953
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." j
6954
+ ON a.entity_id = j.product_id
6955
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
6956
+ ON a.store_product_id = f.store_product_id
6957
+ )
6958
+ ON DUPLICATE KEY UPDATE
6959
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6960
+ ");
6961
+
6962
+ $result = $this->db_do("
6963
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
6964
+ product_id,
6965
+ store_id,
6966
+ data_index
6967
+ )(
6968
+ SELECT
6969
+ a.entity_id,
6970
+ w.website,
6971
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6972
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6973
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6974
+ ON a.store_product_id=w.store_product_id
6975
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
6976
+ ON a.entity_id = b.product_id
6977
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
6978
+ ON b.category_id = c.entity_id
6979
+ AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
6980
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
6981
+ ON a.entity_id = e.entity_id
6982
+ AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
6983
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
6984
+ ON a.store_product_id = f.store_product_id
6985
+ )
6986
+ ON DUPLICATE KEY UPDATE
6987
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6988
+ ");
6989
+
6990
+ $result = $this->db_do("DELETE cf
6991
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." cf
6992
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6993
+ ON cf.product_id=cpe.entity_id
6994
+ WHERE cpe.entity_id is null");
6995
+
6996
+ $result = $this->db_do("
6997
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." (
6998
+ product_id,
6999
+ store_id,
7000
+ data_index
7001
+ )(
7002
+ SELECT
7003
+ a.product_id,
7004
+ a.store_id,
7005
+ a.data_index
7006
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp a
7007
+ WHERE product_id = a.product_id
7008
+ )
7009
+ ON DUPLICATE KEY UPDATE
7010
+ data_index = a.data_index
7011
+ ");
7012
+
7013
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_query')." SET is_processed = 0");
7014
+ //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
7015
+ //TODO add something else
7016
+ STP DELETE*/
7017
+ $this->addRelatedProducts();
7018
+ }
7019
+
7020
+ #################################################################################################
7021
+ function addReviews(){
7022
+ // product reviews for all web sites
7023
+ $result = $this->db_do("
7024
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7025
+ entity_type_id,
7026
+ attribute_id,
7027
+ store_id,
7028
+ entity_id,
7029
+ value
7030
+ )(
7031
+ SELECT
7032
+ " . $this->_getProductEntityTypeId(). ",
7033
+ " . $this->_getProductAttributeId('reviews'). ",
7034
+ w.website,
7035
+ a.entity_id,
7036
+ b.Reviews
7037
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7038
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7039
+ ON a.store_product_id = b.store_product_id
7040
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7041
+ ON a.store_product_id=w.store_product_id
7042
+ )
7043
+ ON DUPLICATE KEY UPDATE
7044
+ value = b.Reviews
7045
+ ");
7046
+
7047
+ // product Reviews for all web sites
7048
+ $result = $this->db_do("
7049
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7050
+ entity_type_id,
7051
+ attribute_id,
7052
+ store_id,
7053
+ entity_id,
7054
+ value
7055
+ )(
7056
+ SELECT
7057
+ " . $this->_getProductEntityTypeId(). ",
7058
+ " . $this->_getProductAttributeId('reviews'). ",
7059
+ 0,
7060
+ a.entity_id,
7061
+ b.Reviews
7062
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7063
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7064
+ ON a.store_product_id = b.store_product_id
7065
+ )
7066
+ ON DUPLICATE KEY UPDATE
7067
+ value = b.Reviews
7068
+ ");
7069
+
7070
+
7071
+ }
7072
+
7073
+
7074
+ #################################################################################################
7075
+ function addDescriptions(){
7076
+ // product description for all web sites
7077
+ $result = $this->db_do("
7078
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7079
+ entity_type_id,
7080
+ attribute_id,
7081
+ store_id,
7082
+ entity_id,
7083
+ value
7084
+ )(
7085
+ SELECT
7086
+ " . $this->_getProductEntityTypeId(). ",
7087
+ " . $this->_getProductAttributeId('description'). ",
7088
+ w.website,
7089
+ a.entity_id,
7090
+ b.description
7091
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7092
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7093
+ ON a.store_product_id = b.store_product_id
7094
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7095
+ ON a.store_product_id=w.store_product_id
7096
+ )
7097
+ ON DUPLICATE KEY UPDATE
7098
+ value = b.description
7099
+ ");
7100
+
7101
+ // product description for all web sites
7102
+ $result = $this->db_do("
7103
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7104
+ entity_type_id,
7105
+ attribute_id,
7106
+ store_id,
7107
+ entity_id,
7108
+ value
7109
+ )(
7110
+ SELECT
7111
+ " . $this->_getProductEntityTypeId(). ",
7112
+ " . $this->_getProductAttributeId('description'). ",
7113
+ 0,
7114
+ a.entity_id,
7115
+ b.description
7116
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7117
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7118
+ ON a.store_product_id = b.store_product_id
7119
+ )
7120
+ ON DUPLICATE KEY UPDATE
7121
+ value = b.description
7122
+ ");
7123
+
7124
+
7125
+ }
7126
+ ############################### ##################################################################
7127
+ function addSearchCache(){
7128
+ // product search_cache for all web sites
7129
+ $result = $this->db_do("
7130
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7131
+ entity_type_id,
7132
+ attribute_id,
7133
+ store_id,
7134
+ entity_id,
7135
+ value
7136
+ )(
7137
+ SELECT
7138
+ " . $this->_getProductEntityTypeId(). ",
7139
+ " . $this->_getProductAttributeId('sinch_search_cache'). ",
7140
+ w.website,
7141
+ a.entity_id,
7142
+ b.search_cache
7143
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7144
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7145
+ ON a.store_product_id = b.store_product_id
7146
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7147
+ ON a.store_product_id=w.store_product_id
7148
+ )
7149
+ ON DUPLICATE KEY UPDATE
7150
+ value = b.search_cache
7151
+ ");
7152
+
7153
+ // product search_cache for all web sites
7154
+ $result = $this->db_do("
7155
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7156
+ entity_type_id,
7157
+ attribute_id,
7158
+ store_id,
7159
+ entity_id,
7160
+ value
7161
+ )(
7162
+ SELECT
7163
+ " . $this->_getProductEntityTypeId(). ",
7164
+ " . $this->_getProductAttributeId('sinch_search_cache'). ",
7165
+ 0,
7166
+ a.entity_id,
7167
+ b.search_cache
7168
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7169
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7170
+ ON a.store_product_id = b.store_product_id
7171
+ )
7172
+ ON DUPLICATE KEY UPDATE
7173
+ value = b.search_cache
7174
+ ");
7175
+
7176
+
7177
+ }
7178
+
7179
+ #################################################################################################
7180
+ function addPdfUrl(){
7181
+ // product PDF Url for all web sites
7182
+ $result = $this->db_do("
7183
+ UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
7184
+ SET pdf_url = CONCAT(
7185
+ '<a href=\"#\" onclick=\"popWin(',
7186
+ \"'\",
7187
+ pdf_url,
7188
+ \"'\",
7189
+ \", 'pdf', 'width=500,height=800,left=50,top=50, location=no,status=yes,scrollbars=yes,resizable=yes'); return false;\",
7190
+ '\"',
7191
+ '>',
7192
+ pdf_url,
7193
+ '</a>')
7194
+ WHERE pdf_url != ''
7195
+ ");
7196
+ //<a title="" onclick="popWin('http://images.icecat.biz/img/gallery/14532248_4539.jpg', 'gallery', 'width=500,height=500,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" href="#">
7197
+ $result = $this->db_do("
7198
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7199
+ entity_type_id,
7200
+ attribute_id,
7201
+ store_id,
7202
+ entity_id,
7203
+ value
7204
+ )(
7205
+ SELECT
7206
+ " . $this->_getProductEntityTypeId(). ",
7207
+ " . $this->_getProductAttributeId('pdf_url'). ",
7208
+ w.website,
7209
+ a.entity_id,
7210
+ b.pdf_url
7211
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7212
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7213
+ ON a.store_product_id = b.store_product_id
7214
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7215
+ ON a.store_product_id=w.store_product_id
7216
+ )
7217
+ ON DUPLICATE KEY UPDATE
7218
+ value = b.pdf_url
7219
+ ");
7220
+ // product PDF url for all web sites
7221
+ $result = $this->db_do("
7222
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7223
+ entity_type_id,
7224
+ attribute_id,
7225
+ store_id,
7226
+ entity_id,
7227
+ value
7228
+ )(
7229
+ SELECT
7230
+ " . $this->_getProductEntityTypeId(). ",
7231
+ " . $this->_getProductAttributeId('pdf_url'). ",
7232
+ 0,
7233
+ a.entity_id,
7234
+ b.pdf_url
7235
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7236
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7237
+ ON a.store_product_id = b.store_product_id
7238
+ )
7239
+ ON DUPLICATE KEY UPDATE
7240
+ value = b.pdf_url
7241
+ ");
7242
+
7243
+ }
7244
+
7245
+ #################################################################################################
7246
+ function cleanProductDistributors(){
7247
+ for($i=1; $i<=5; $i++){
7248
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
7249
+ SET value = ''
7250
+ WHERE entity_type_id=".$this->_getProductEntityTypeId()." AND attribute_id=".$this->_getProductAttributeId('supplier_'.$i));
7251
+ }
7252
+ }
7253
+ #################################################################################################
7254
+ function addProductDistributors(){
7255
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary'));
7256
+ $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')."
7257
+ LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7258
+ $this->db_do("INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." SELECT * FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7259
+ for($i=1; $i<=5; $i++){
7260
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier'));
7261
+ $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')."
7262
+ LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7263
+ $this->db_do("INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." SELECT * FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." GROUP BY store_product_id");
7264
+
7265
+ // product Distributors for all web sites
7266
+ $result = $this->db_do("
7267
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7268
+ entity_type_id,
7269
+ attribute_id,
7270
+ store_id,
7271
+ entity_id,
7272
+ value
7273
+ )(
7274
+ SELECT
7275
+ " . $this->_getProductEntityTypeId(). ",
7276
+ " . $this->_getProductAttributeId('supplier_'.$i). ",
7277
+ w.website,
7278
+ a.entity_id,
7279
+ d.distributor_name
7280
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7281
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." b
7282
+ ON a.store_product_id = b.store_product_id
7283
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors')." d
7284
+ ON b.distributor_id = d.distributor_id
7285
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7286
+ ON a.store_product_id=w.store_product_id
7287
+ )
7288
+ ON DUPLICATE KEY UPDATE
7289
+ value = d.distributor_name
7290
+ ");
7291
+ // product Distributors for all web sites
7292
+ $result = $this->db_do("
7293
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7294
+ entity_type_id,
7295
+ attribute_id,
7296
+ store_id,
7297
+ entity_id,
7298
+ value
7299
+ )(
7300
+ SELECT
7301
+ " . $this->_getProductEntityTypeId(). ",
7302
+ " . $this->_getProductAttributeId('supplier_'.$i). ",
7303
+ 0,
7304
+ a.entity_id,
7305
+ d.distributor_name
7306
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7307
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." b
7308
+ ON a.store_product_id = b.store_product_id
7309
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors')." d
7310
+ ON b.distributor_id = d.distributor_id
7311
+ )
7312
+ ON DUPLICATE KEY UPDATE
7313
+ value = d.distributor_name
7314
+ ");
7315
+
7316
+ $this->db_do("DELETE sdsapt FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." sdsapt JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." sdsapts ON sdsapt.store_product_id = sdsapts.store_product_id AND sdsapt.distributor_id = sdsapts.distributor_id");
7317
+
7318
+
7319
+ }
7320
+
7321
+ }
7322
+
7323
+
7324
+
7325
+ #################################################################################################
7326
+ function addShortDescriptions(){
7327
+ // product short description for all web sites
7328
+ $result = $this->db_do("
7329
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7330
+ entity_type_id,
7331
+ attribute_id,
7332
+ store_id,
7333
+ entity_id,
7334
+ value
7335
+ )(
7336
+ SELECT
7337
+ " . $this->_getProductEntityTypeId(). ",
7338
+ " . $this->_getProductAttributeId('short_description'). ",
7339
+ w.website,
7340
+ a.entity_id,
7341
+ b.product_short_description
7342
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7343
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7344
+ ON a.store_product_id = b.store_product_id
7345
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7346
+ ON a.store_product_id=w.store_product_id
7347
+ )
7348
+ ON DUPLICATE KEY UPDATE
7349
+ value = b.product_short_description
7350
+ ");
7351
+ // product short description for all web sites
7352
+ $result = $this->db_do("
7353
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7354
+ entity_type_id,
7355
+ attribute_id,
7356
+ store_id,
7357
+ entity_id,
7358
+ value
7359
+ )(
7360
+ SELECT
7361
+ " . $this->_getProductEntityTypeId(). ",
7362
+ " . $this->_getProductAttributeId('short_description'). ",
7363
+ 0,
7364
+ a.entity_id,
7365
+ b.product_short_description
7366
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7367
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7368
+ ON a.store_product_id = b.store_product_id
7369
+ )
7370
+ ON DUPLICATE KEY UPDATE
7371
+ value = b.product_short_description
7372
+ ");
7373
+
7374
+ }
7375
+
7376
+ #################################################################################################
7377
+ function addEAN(){
7378
+ //gather EAN codes for each product
7379
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('EANs_temp'));
7380
+ $this->db_do("
7381
+ CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
7382
+ sinch_product_id int(11),
7383
+ store_product_id int(11),
7384
+ EANs text,
7385
+ KEY `sinch_product_id` (`sinch_product_id`),
7386
+ KEY `store_product_id` (`store_product_id`)
7387
+ )
7388
+ ");
7389
+ $this->db_do("
7390
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
7391
+ sinch_product_id,
7392
+ EANs
7393
+ )(SELECT
7394
+ sec.product_id,
7395
+ GROUP_CONCAT(DISTINCT ean_code ORDER BY ean_code DESC SEPARATOR ', ') AS eans
7396
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
7397
+ GROUP BY sec.product_id
7398
+ )
7399
+ ");
7400
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7401
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7402
+ ON e.sinch_product_id=p.sinch_product_id
7403
+ SET e.store_product_id=p.store_product_id");
7404
+ // product EANs for all web sites
7405
+ $result = $this->db_do("
7406
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7407
+ entity_type_id,
7408
+ attribute_id,
7409
+ store_id,
7410
+ entity_id,
7411
+ value
7412
+ )(
7413
+ SELECT
7414
+ " . $this->_getProductEntityTypeId(). ",
7415
+ " . $this->_getProductAttributeId('ean'). ",
7416
+ w.website,
7417
+ a.entity_id,
7418
+ e.EANs
7419
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7420
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7421
+ ON a.store_product_id = e.store_product_id
7422
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7423
+ ON a.store_product_id=w.store_product_id
7424
+ )
7425
+ ON DUPLICATE KEY UPDATE
7426
+ value = e.EANs
7427
+ ");
7428
+
7429
+ // product EANs for all web sites
7430
+ $result = $this->db_do("
7431
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7432
+ entity_type_id,
7433
+ attribute_id,
7434
+ store_id,
7435
+ entity_id,
7436
+ value
7437
+ )(
7438
+ SELECT
7439
+ " . $this->_getProductEntityTypeId(). ",
7440
+ " . $this->_getProductAttributeId('ean'). ",
7441
+ 0,
7442
+ a.entity_id,
7443
+ e.EANs
7444
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7445
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7446
+ ON a.store_product_id = e.store_product_id
7447
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7448
+ ON a.store_product_id=w.store_product_id
7449
+ )
7450
+ ON DUPLICATE KEY UPDATE
7451
+ value = e.EANs
7452
+ ");
7453
+
7454
+ }
7455
+
7456
+ ################################################################################################
7457
+ function addSpecification(){
7458
+ // product specification for all web sites
7459
+ $result = $this->db_do("
7460
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7461
+ entity_type_id,
7462
+ attribute_id,
7463
+ store_id,
7464
+ entity_id,
7465
+ value
7466
+ )(
7467
+ SELECT
7468
+ " . $this->_getProductEntityTypeId(). ",
7469
+ " . $this->_getProductAttributeId('specification'). ",
7470
+ w.website,
7471
+ a.entity_id,
7472
+ b.specifications
7473
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7474
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7475
+ ON a.store_product_id = b.store_product_id
7476
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7477
+ ON a.store_product_id=w.store_product_id
7478
+ )
7479
+ ON DUPLICATE KEY UPDATE
7480
+ value = b.specifications
7481
+ ");
7482
+ // product specification for all web sites
7483
+ $result = $this->db_do("
7484
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7485
+ entity_type_id,
7486
+ attribute_id,
7487
+ store_id,
7488
+ entity_id,
7489
+ value
7490
+ )(
7491
+ SELECT
7492
+ " . $this->_getProductEntityTypeId(). ",
7493
+ " . $this->_getProductAttributeId('specification'). ",
7494
+ 0,
7495
+ a.entity_id,
7496
+ b.specifications
7497
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7498
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7499
+ ON a.store_product_id = b.store_product_id
7500
+ )
7501
+ ON DUPLICATE KEY UPDATE
7502
+ value = b.specifications
7503
+ ");
7504
+
7505
+
7506
+ }
7507
+
7508
+ private function addManufacturer_attribute(){
7509
+ $result = $this->db_do("
7510
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
7511
+ entity_type_id,
7512
+ attribute_id,
7513
+ store_id,
7514
+ entity_id,
7515
+ value
7516
+ )(
7517
+ SELECT
7518
+ " . $this->_getProductEntityTypeId(). ",
7519
+ " . $this->_getProductAttributeId('manufacturer'). ",
7520
+ 0,
7521
+ a.entity_id,
7522
+ pm.manufacturer_option_id
7523
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7524
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
7525
+ ON a.entity_id = pm.entity_id
7526
+ )
7527
+ ON DUPLICATE KEY UPDATE
7528
+ value = pm.manufacturer_option_id
7529
+ ");
7530
+
7531
+
7532
+ }
7533
+
7534
+ #################################################################################################
7535
+ function addManufacturers($delete_eav=null){
7536
+ // this cleanup is not needed due to foreign keys
7537
+ if(!$delete_eav){
7538
+ $result = $this->db_do("
7539
+ DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')."
7540
+ WHERE attribute_id = ".$this->_getProductAttributeId('manufacturer')//." AND store_id = ".$websiteId
7541
+ );
7542
+ }
7543
+ $this->addManufacturer_attribute();
7544
+ // todo: doesn't seems to work properly, should be inserted per visibility
7545
+ // done, test now
7546
+
7547
+ $result = $this->db_do("
7548
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
7549
+ entity_id,
7550
+ attribute_id,
7551
+ store_id,
7552
+ value
7553
+ )(
7554
+ SELECT
7555
+ a.entity_id,
7556
+ " . $this->_getProductAttributeId('manufacturer'). ",
7557
+ w.website,
7558
+ mn.shop_option_id
7559
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7560
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7561
+ ON a.store_product_id = b.store_product_id
7562
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7563
+ ON a.store_product_id=w.store_product_id
7564
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
7565
+ ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
7566
+ WHERE mn.shop_option_id IS NOT NULL
7567
+ )
7568
+ ON DUPLICATE KEY UPDATE
7569
+ value = mn.shop_option_id
7570
+ ");
7571
+
7572
+ $result = $this->db_do("
7573
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
7574
+ entity_id,
7575
+ attribute_id,
7576
+ store_id,
7577
+ value
7578
+ )(
7579
+ SELECT
7580
+ a.entity_id,
7581
+ " . $this->_getProductAttributeId('manufacturer'). ",
7582
+ 0,
7583
+ mn.shop_option_id
7584
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7585
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7586
+ ON a.store_product_id = b.store_product_id
7587
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7588
+ ON a.store_product_id=w.store_product_id
7589
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
7590
+ ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
7591
+ WHERE mn.shop_option_id IS NOT NULL
7592
+ )
7593
+ ON DUPLICATE KEY UPDATE
7594
+ value = mn.shop_option_id
7595
+ ");
7596
+
7597
+
7598
+ }
7599
+
7600
+ #################################################################################################
7601
+ function addRelatedProducts(){
7602
+
7603
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
7604
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7605
+ ON rpt.sinch_product_id=p.sinch_product_id
7606
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7607
+ ON p.store_product_id=cpe.store_product_id
7608
+ SET rpt.store_product_id=p.store_product_id, rpt.entity_id=cpe.entity_id");
7609
+
7610
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
7611
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7612
+ ON rpt.related_sinch_product_id=p.sinch_product_id
7613
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7614
+ ON p.store_product_id=cpe.store_product_id
7615
+ SET rpt.store_related_product_id=p.store_product_id, rpt.related_entity_id=cpe.entity_id");
7616
+
7617
+ $result = $this->db_do("SELECT
7618
+ link_type_id,
7619
+ code
7620
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_type')
7621
+ );
7622
+ $link_type=array();
7623
+ while ($row = mysqli_fetch_array($result)) {
7624
+ $link_type[$row['code']]=$row['link_type_id'];
7625
+ }
7626
+
7627
+ $result = $this->db_do("
7628
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." (
7629
+ product_id,
7630
+ linked_product_id,
7631
+ link_type_id
7632
+ )(
7633
+ SELECT
7634
+ entity_id,
7635
+ related_entity_id,
7636
+ ".$link_type['relation']."
7637
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')."
7638
+ WHERE store_product_id IS NOT NULL
7639
+ AND store_related_product_id IS NOT NULL
7640
+ )
7641
+ ON DUPLICATE KEY UPDATE
7642
+ product_id = entity_id,
7643
+ linked_product_id = related_entity_id
7644
+ ");
7645
+ $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp");
7646
+
7647
+ $this->db_do("CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp (
7648
+ `value_id` int(11) default NULL,
7649
+ `product_link_attribute_id` smallint(6) unsigned default NULL,
7650
+ `link_id` int(11) unsigned default NULL,
7651
+ `value` int(11) NOT NULL default '0',
7652
+ KEY `FK_INT_PRODUCT_LINK_ATTRIBUTE` (`product_link_attribute_id`),
7653
+ KEY `FK_INT_PRODUCT_LINK` (`link_id`)
7654
+ )
7655
+ ");
7656
+
7657
+ $result = $this->db_do("
7658
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp(
7659
+ product_link_attribute_id,
7660
+ link_id,
7661
+ value
7662
+ )(
7663
+ SELECT
7664
+ 2,
7665
+ cpl.link_id,
7666
+ 0
7667
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." cpl
7668
+ )
7669
+ ");
7670
+
7671
+ $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
7672
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." c
7673
+ ON ct.link_id=c.link_id
7674
+ SET ct.value_id=c.value_id
7675
+ WHERE c.product_link_attribute_id=2
7676
+ ");
7677
+
7678
+ $result = $this->db_do("
7679
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." (
7680
+ value_id,
7681
+ product_link_attribute_id,
7682
+ link_id,
7683
+ value
7684
+ )(
7685
+ SELECT
7686
+ value_id,
7687
+ product_link_attribute_id,
7688
+ link_id,
7689
+ value
7690
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
7691
+ )
7692
+ ON DUPLICATE KEY UPDATE
7693
+ link_id=ct.link_id
7694
+
7695
+ ");
7696
+
7697
+ /* $q="select distinct store_product_id from stINch_related_products";
7698
+ $quer=$this->db_do($q);
7699
+ $prod = Mage::getModel('catalog/product');
7700
+ while ($row = mysqli_fetch_assoc($quer)) {
7701
+ $q1="select distinct store_related_product_id store_product_id from stINch_related_products where store_product_id=".$row['store_product_id'].;
7702
+ $quer1=$this->db_do($q1);
7703
+ $prod->load($row['store_product_id']);
7704
+
7705
+ ###//get related product data (product id's and positions)
7706
+ ###$relatedData = array();
7707
+ ###foreach ($product->getRelatedLinkCollection() as $link) {
7708
+ ### $relatedData[$link->getLinkedProductId()]['position'] = $link->getPosition();
7709
+ ###}
7710
+ ###//manipulate $relatedData array
7711
+ ###// ...
7712
+ ###//set and save related product data
7713
+ ###$product->setRelatedLinkData($relatedData);
7714
+ ###$product->save();
7715
+ ###
7716
+ $i=1;
7717
+ while ($row1 = mysqli_fetch_assoc($quer1)) {
7718
+ $param[$row1['store_related_product_id']]['position']=$i++;
7719
+
7720
+ }
7721
+ $prod->setRelatedLinkData($param);
7722
+ //here ... some other product operations and in the end
7723
+ $prod->save();
7724
+
7725
+ }
7726
+ */
7727
+ }
7728
+ #################################################################################################
7729
+ function addWeight(){
7730
+ // product weight for specific web site
7731
+ $result = $this->db_do("
7732
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
7733
+ entity_type_id,
7734
+ attribute_id,
7735
+ store_id,
7736
+ entity_id,
7737
+ value
7738
+ )(
7739
+ SELECT
7740
+ " . $this->_getProductEntityTypeId(). ",
7741
+ " . $this->_getProductAttributeId('weight'). ",
7742
+ w.website,
7743
+ a.entity_id,
7744
+ b.Weight
7745
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7746
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7747
+ ON a.store_product_id = b.store_product_id
7748
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7749
+ ON a.store_product_id=w.store_product_id
7750
+ )
7751
+ ON DUPLICATE KEY UPDATE
7752
+ value = b.Weight
7753
+ ");
7754
+ // product weight for all web sites
7755
+ $result = $this->db_do("
7756
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
7757
+ entity_type_id,
7758
+ attribute_id,
7759
+ store_id,
7760
+ entity_id,
7761
+ value
7762
+ )(
7763
+ SELECT
7764
+ " . $this->_getProductEntityTypeId(). ",
7765
+ " . $this->_getProductAttributeId('weight'). ",
7766
+ 0,
7767
+ a.entity_id,
7768
+ b.Weight
7769
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7770
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7771
+ ON a.store_product_id = b.store_product_id
7772
+ )
7773
+ ON DUPLICATE KEY UPDATE
7774
+ value = b.Weight
7775
+
7776
+
7777
+ ");
7778
+
7779
+
7780
+ }
7781
+
7782
+ #################################################################################################
7783
+ function _getProductsForCustomerGroupPrice(){
7784
+ // TEMPORARY
7785
+ $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp'));
7786
+ $this->db_do("
7787
+ CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')."
7788
+ (
7789
+ `category_id` int(10) unsigned NOT NULL default '0',
7790
+ `product_id` int(10) unsigned NOT NULL default '0',
7791
+ `store_product_id` int(10) NOT NULL default '0',
7792
+ `sku` varchar(64) DEFAULT NULL COMMENT 'SKU',
7793
+ `manufacturer_id` int(10) NOT NULL default '0',
7794
+ `price` decimal(15,4) DEFAULT NULL,
7795
+ UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`product_id`,`category_id`),
7796
+ KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
7797
+ KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`)
7798
+ )");
7799
+
7800
+ $result = $this->db_do("
7801
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')."
7802
+ (category_id, product_id, store_product_id, sku)
7803
+ (SELECT
7804
+ ccp.category_id,
7805
+ ccp.product_id,
7806
+ cpe.store_product_id,
7807
+ cpe.sku
7808
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
7809
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7810
+ ON ccp.product_id = cpe.entity_id
7811
+ WHERE cpe.store_product_id IS NOT NULL)");
7812
+
7813
+ $result = $this->db_do("
7814
+ UPDATE ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." pfcgpt
7815
+ JOIN ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." cpei
7816
+ ON pfcgpt.product_id = cpei.entity_id
7817
+ AND cpei.entity_type_id = " . $this->_getProductEntityTypeId(). "
7818
+ AND cpei.attribute_id = " . $this->_getProductAttributeId('manufacturer'). "
7819
+ SET pfcgpt.manufacturer_id = cpei.value
7820
+ ");
7821
+
7822
+ $result = $this->db_do("
7823
+ UPDATE ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." pfcgpt
7824
+ JOIN ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." cped
7825
+ ON pfcgpt.product_id = cped.entity_id
7826
+ AND cped.entity_type_id = " . $this->_getProductEntityTypeId(). "
7827
+ AND cped.attribute_id = " . $this->_getProductAttributeId('price'). "
7828
+ SET pfcgpt.price = cped.value
7829
+ ");
7830
+
7831
+
7832
+
7833
+ }
7834
+
7835
+ #################################################################################################
7836
+ function ApplyCustomerGroupPrice(){
7837
+ if (!$this->check_table_exist('import_pricerules_standards')){
7838
+ return;
7839
+ }
7840
+ $this->_getProductsForCustomerGroupPrice();
7841
+ $pricerulesArray = $this->_getPricerulesList();
7842
+ if(is_array($pricerulesArray)){
7843
+ $this->db_do("TRUNCATE TABLE ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_group_price'));
7844
+ $this->db_do("TRUNCATE TABLE ". Mage::getSingleton('core/resource')->getTableName('catalog_product_index_group_price'));
7845
+
7846
+ }
7847
+ // $i=1;
7848
+ foreach($pricerulesArray as $pricerule) {
7849
+ $this->_LOG("Calculation group price for rule ".$pricerule['id']."
7850
+ (\nname = ".$pricerule['name']."
7851
+ \nfinal_price = ".$pricerule['final_price']."
7852
+ \nprice_from = ".$pricerule['price_from']."
7853
+ \nprice_to = ".$pricerule['price_to']."
7854
+ \nvendor_id = ".$pricerule['vendor_id']."
7855
+ \ncategory_id = ".$pricerule['category_id']."
7856
+ \nproduct_entity_id = ".$pricerule['product_entity_id']."
7857
+ \nvendor_product_id = ".$pricerule['vendor_product_id']."
7858
+ \ncustomergroup_id = ".$pricerule['customergroup_id']."
7859
+ \ndistributor_id = ".$pricerule['distributor_id']."
7860
+ \nrating = ".$pricerule['rating']."
7861
+ \nmarge = ".$pricerule['marge']."
7862
+ \nfixed = ".$pricerule['fixed']."
7863
+ \nallow_subcat = ".$pricerule['allow_subcat']."
7864
+ \nstore_id = ".$pricerule['store_id']."
7865
+ )");
7866
+
7867
+ $vendor_product_id_str = "'".str_replace(';', "','", $pricerule['vendor_product_id'])."'";
7868
+ $where = "";
7869
+ if (empty($pricerule['marge'])) $marge = "NULL";
7870
+ else $marge = $pricerule['marge'];
7871
+
7872
+ if (empty($pricerule['fixed'])) $fixed = "NULL";
7873
+ else $fixed = $pricerule['fixed'];
7874
+
7875
+ if (empty($pricerule['final_price'])) $final_price = "NULL";
7876
+ else $final_price = $pricerule['final_price'];
7877
+
7878
+ if (!empty($pricerule['price_from'])) $where.= " AND a.price > ".$pricerule['price_from'];
7879
+
7880
+ if (!empty($pricerule['price_to'])) $where.= " AND a.price < ".$pricerule['price_to'];
7881
+
7882
+ if (!empty($pricerule['vendor_id'])) $where.= " AND a.manufacturer_id = ".$pricerule['vendor_id'];
7883
+
7884
+ //if(!empty($pricerule['vendor_product_id']))
7885
+ // $where.= " AND vendor_product_id = ".$pricerule['vendor_product_id'];
7886
+ if (!empty($pricerule['product_entity_id'])) $where.= " AND a.product_id = '".$pricerule['product_entity_id']."'";
7887
+
7888
+ // if (!empty($pricerule['vendor_product_id'])) $where.= " AND a.sku = '".$pricerule['vendor_product_id']."'";
7889
+ if (!empty($pricerule['vendor_product_id'])) $where.= " AND a.sku IN (". $vendor_product_id_str.")";
7890
+
7891
+ if(!empty($pricerule['allow_subcat'])){
7892
+ if (!empty($pricerule['category_id'])){
7893
+ $children_cat=$this->get_all_children_cat($pricerule['category_id']);
7894
+ $where.= " AND a.category_id IN (".$children_cat.")";
7895
+ }
7896
+ }else{
7897
+ if (!empty($pricerule['category_id'])) $where.= " AND a.category_id = ".$pricerule['category_id'];
7898
+ }
7899
+
7900
+
7901
+ // if (!empty($pricerule['store_id'])) $where.= " AND store_id = ".$pricerule['store_id'];
7902
+
7903
+ // if (!empty($pricerule['distributor_id'])) $where.= " AND distributor_id = ".$pricerule['distributor_id'];
7904
+
7905
+ // $this->createCalcPriceFunc();
7906
+ //echo "\n\nAAAAAAAAAAAAAAAAAAAAa".$pricerule['customergroup_id']."----------";
7907
+ $customer_group_id_array = array();
7908
+ if(strstr($pricerule['customergroup_id'], ",")){
7909
+ //echo "55555555555555555";
7910
+ $customer_group_id_array = explode(",", $pricerule['customergroup_id']);
7911
+ }else{
7912
+ $customer_group_id_array[0] = $pricerule['customergroup_id'];
7913
+ }
7914
+ // var_dump($pricerule);
7915
+ // echo "CCCCCCC\n";
7916
+ // var_dump($customer_group_id_array);
7917
+ foreach($customer_group_id_array as $customer_group_id){
7918
+ if(isset($customer_group_id) && $customer_group_id>=0){
7919
+ $query="
7920
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_group_price')." (entity_id,
7921
+ all_groups,
7922
+ customer_group_id,
7923
+ value,
7924
+ website_id
7925
+ )
7926
+ (SELECT
7927
+ a.product_id,
7928
+ 0,
7929
+ ".$customer_group_id.",
7930
+ ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7931
+ a.price,
7932
+ ".$marge." ,
7933
+ ".$fixed.",
7934
+ ".$final_price."),
7935
+ 0
7936
+ FROM ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." a
7937
+ WHERE true ".$where."
7938
+ )
7939
+ ON DUPLICATE KEY UPDATE
7940
+ value =
7941
+ ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7942
+ a.price,
7943
+ ".$marge." ,
7944
+ ".$fixed.",
7945
+ ".$final_price.")
7946
+ ";
7947
+ // echo "\n\n".$query;
7948
+ $this->db_do($query);
7949
+ if (!empty($pricerule['store_id']) && $pricerule['store_id']>0){
7950
+ $query="
7951
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_group_price')." (entity_id,
7952
+ customer_group_id,
7953
+ price,
7954
+ website_id
7955
+ )
7956
+ (SELECT
7957
+ a.product_id,
7958
+ ".$customer_group_id.",
7959
+ ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7960
+ a.price,
7961
+ ".$marge." ,
7962
+ ".$fixed.",
7963
+ ".$final_price."),
7964
+ ".$pricerule['store_id']."
7965
+ FROM ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." a
7966
+ WHERE true ".$where."
7967
+ )
7968
+ ON DUPLICATE KEY UPDATE
7969
+ price =
7970
+ ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7971
+ a.price,
7972
+ ".$marge." ,
7973
+ ".$fixed.",
7974
+ ".$final_price.")
7975
+ ";
7976
+ // echo "\n\n".$query;
7977
+ $this->db_do($query);
7978
+
7979
+ }
7980
+ }
7981
+ }
7982
+ }
7983
+
7984
+ }
7985
+ #################################################################################################
7986
+
7987
+ protected function _getPricerulesList() {
7988
+ $rulesArray = array();
7989
+ $result = $this->db_do("
7990
+ SELECT *
7991
+ FROM ".Mage::getSingleton('core/resource')->getTableName('import_pricerules')."
7992
+ ORDER BY rating DESC
7993
+ ");
7994
+ while($row = mysqli_fetch_assoc($result)) {
7995
+ $rulesArray[$row['id']] = $row;
7996
+ }
7997
+ return $rulesArray;
7998
+ }
7999
+
8000
+
8001
+ #################################################################################################
8002
+ function replaceMagentoProductsStockPrice(){
8003
+ //Add stock
8004
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
8005
+ $result = $this->db_do("DELETE csi
8006
+ FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
8007
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8008
+ ON csi.product_id=cpe.entity_id
8009
+ WHERE cpe.entity_id is null");
8010
+ //set all sinch products stock=0 before upgrade (nedds for dayly stock&price import)
8011
+
8012
+ $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8013
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
8014
+ ON cpe.entity_id=csi.product_id
8015
+ SET
8016
+ csi.qty=0,
8017
+ csi.is_in_stock=0
8018
+ WHERE cpe.store_product_id IS NOT NULL");
8019
+
8020
+ $result = $this->db_do("
8021
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." (
8022
+ product_id,
8023
+ stock_id,
8024
+ qty,
8025
+ is_in_stock,
8026
+ manage_stock
8027
+ )(
8028
+ SELECT
8029
+ a.entity_id,
8030
+ 1,
8031
+ b.stock,
8032
+ IF(b.stock > 0, 1, 0),
8033
+ 1
8034
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8035
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8036
+ ON a.store_product_id=b.store_product_id
8037
+ )
8038
+ ON DUPLICATE KEY UPDATE
8039
+ qty=b.stock,
8040
+ is_in_stock = IF(b.stock > 0, 1, 0),
8041
+ manage_stock = 1
8042
+ ");
8043
+
8044
+
8045
+ $result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status'));
8046
+
8047
+ $result = $this->db_do("
8048
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status')." (
8049
+ product_id,
8050
+ website_id,
8051
+ stock_id,
8052
+ qty,
8053
+ stock_status
8054
+ )(
8055
+ SELECT
8056
+ a.product_id,
8057
+ w.website_id,
8058
+ 1,
8059
+ a.qty,
8060
+ IF(qty > 0, 1, 0)
8061
+ FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." a
8062
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." b
8063
+ ON a.product_id=b.entity_id
8064
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8065
+ ON b.store_product_id=w.store_product_id
8066
+ )
8067
+ ON DUPLICATE KEY UPDATE
8068
+ qty=a.qty,
8069
+ stock_status = IF(a.qty > 0, 1, 0)
8070
+ ");
8071
+
8072
+ //Add prices
8073
+ //$result = $this->db_do("truncate catalog_product_entity_decimal");
8074
+ $result = $this->db_do("DELETE cped
8075
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." cped
8076
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8077
+ ON cped.entity_id=cpe.entity_id
8078
+ WHERE cpe.entity_id IS NULL");
8079
+
8080
+ $result = $this->db_do("
8081
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8082
+ entity_type_id,
8083
+ attribute_id,
8084
+ store_id,
8085
+ entity_id,
8086
+ value
8087
+ )(
8088
+ SELECT
8089
+ " . $this->_getProductEntityTypeId(). ",
8090
+ " . $this->_getProductAttributeId('price'). ",
8091
+ w.website,
8092
+ a.entity_id,
8093
+ b.price
8094
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8095
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8096
+ ON a.store_product_id=b.store_product_id
8097
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8098
+ ON a.store_product_id=w.store_product_id
8099
+ )
8100
+ ON DUPLICATE KEY UPDATE
8101
+ value = b.price
8102
+ ");
8103
+
8104
+ $result = $this->db_do("
8105
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8106
+ entity_type_id,
8107
+ attribute_id,
8108
+ store_id,
8109
+ entity_id,
8110
+ value
8111
+ )(
8112
+ SELECT
8113
+ " . $this->_getProductEntityTypeId(). ",
8114
+ " . $this->_getProductAttributeId('price'). ",
8115
+ 0,
8116
+ a.entity_id,
8117
+ b.price
8118
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8119
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8120
+ ON a.store_product_id=b.store_product_id
8121
+ )
8122
+ ON DUPLICATE KEY UPDATE
8123
+ value = b.price
8124
+ ");
8125
+ //Add cost
8126
+ // $result = $this->db_do("truncate catalog_product_entity_decimal");
8127
+ $result = $this->db_do("
8128
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8129
+ entity_type_id,
8130
+ attribute_id,
8131
+ store_id,
8132
+ entity_id,
8133
+ value
8134
+ )(
8135
+ SELECT
8136
+ " . $this->_getProductEntityTypeId(). ",
8137
+ " . $this->_getProductAttributeId('cost'). ",
8138
+ w.website,
8139
+ a.entity_id,
8140
+ b.cost
8141
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8142
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8143
+ ON a.store_product_id=b.store_product_id
8144
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8145
+ ON a.store_product_id=w.store_product_id
8146
+ )
8147
+ ON DUPLICATE KEY UPDATE
8148
+ value = b.cost
8149
+ ");
8150
+
8151
+ $result = $this->db_do("
8152
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8153
+ entity_type_id,
8154
+ attribute_id,
8155
+ store_id,
8156
+ entity_id,
8157
+ value
8158
+ )(
8159
+ SELECT
8160
+ " . $this->_getProductEntityTypeId(). ",
8161
+ " . $this->_getProductAttributeId('cost'). ",
8162
+ 0,
8163
+ a.entity_id,
8164
+ b.cost
8165
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8166
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8167
+ ON a.store_product_id=b.store_product_id
8168
+ )
8169
+ ON DUPLICATE KEY UPDATE
8170
+ value = b.cost
8171
+ ");
8172
+
8173
+ //make products enable in FO
8174
+ // $result = $this->db_do(" truncate catalog_product_index_price");
8175
+ $result = $this->db_do("DELETE cpip
8176
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." cpip
8177
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8178
+ ON cpip.entity_id=cpe.entity_id
8179
+ WHERE cpe.entity_id IS NULL");
8180
+
8181
+ $q="SELECT customer_group_id FROM ".Mage::getSingleton('core/resource')->getTableName('customer_group');
8182
+ $quer=$this->db_do($q);
8183
+
8184
+ while ($row = mysqli_fetch_assoc($quer)) {
8185
+ $result = $this->db_do("
8186
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." (
8187
+ entity_id,
8188
+ customer_group_id,
8189
+ website_id,
8190
+ tax_class_id,
8191
+ price,
8192
+ final_price,
8193
+ min_price,
8194
+ max_price
8195
+ )(SELECT
8196
+ a.entity_id,
8197
+ ".$row['customer_group_id'].",
8198
+ w.website_id,
8199
+ 2,
8200
+ b.price ,
8201
+ b.price ,
8202
+ b.price ,
8203
+ b.price
8204
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8205
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8206
+ ON a.store_product_id=b.store_product_id
8207
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8208
+ ON a.store_product_id=w.store_product_id
8209
+ )
8210
+ ON DUPLICATE KEY UPDATE
8211
+ tax_class_id = 2,
8212
+ price = b.price,
8213
+ final_price = b.price,
8214
+ min_price = b.price,
8215
+ max_price = b.price
8216
+ ");
8217
+ }
8218
+ }
8219
+
8220
+
8221
+
8222
+ #################################################################################################
8223
+
8224
+ function getProductDescription($entity_id){
8225
+
8226
+ $this->loadProductParams($entity_id);
8227
+ $this->loadProductStarfeatures($entity_id);
8228
+ $this->loadGalleryPhotos($entity_id);
8229
+ Varien_Profiler::start('Bintime FILE RELATED');
8230
+ $this->loadRelatedProducts($entity_id);
8231
+ Varien_Profiler::stop('Bintime FILE RELATED');
8232
+
8233
+ return true;
8234
+ }
8235
+ #################################################################################################
8236
+
8237
+ public function getProductName(){
8238
+ return $this->productName;
8239
+ }
8240
+ #################################################################################################
8241
+
8242
+ public function getProductDescriptionList(){
8243
+ return $this->productDescriptionList;
8244
+ }
8245
+ #################################################################################################
8246
+
8247
+ public function getProductSpecifications(){
8248
+ return $this->specifications;
8249
+ }
8250
+ #################################################################################################
8251
+
8252
+ public function getShortProductDescription(){
8253
+ return $this->productDescription;
8254
+ }
8255
+ #################################################################################################
8256
+
8257
+ public function getFullProductDescription(){
8258
+ return $this->fullProductDescription;
8259
+ }
8260
+ #################################################################################################
8261
+
8262
+ public function getLowPicUrl(){
8263
+ return $this->highPicUrl;
8264
+ }
8265
+ #################################################################################################
8266
+
8267
+ public function getRelatedProducts(){
8268
+ return $this->relatedProducts;
8269
+ }
8270
+ #################################################################################################
8271
+
8272
+ public function getVendor(){
8273
+ return $this->vendor;
8274
+ }
8275
+ #################################################################################################
8276
+
8277
+ public function getMPN(){
8278
+ return $this->productId;
8279
+ }
8280
+ #################################################################################################
8281
+
8282
+ public function getEAN(){
8283
+ return $this->EAN;
8284
+ }
8285
+ ################################################################################################
8286
+
8287
+ public function getGalleryPhotos(){
8288
+ return $this->galleryPhotos;
8289
+ }
8290
+
8291
+ #################################################################################################
8292
+
8293
+ private function loadProductParams($entity_id){
8294
+ $store_product_id=$this->getStoreProductIdByEntity($entity_id);
8295
+ if(!$store_product_id){
8296
+ // echo "AAAAAAA"; exit;
8297
+ return;
8298
+ }
8299
+ $q="SELECT
8300
+ sinch_product_id,
8301
+ product_sku,
8302
+ product_name,
8303
+ sinch_manufacturer_id,
8304
+ store_category_id,
8305
+ main_image_url,
8306
+ thumb_image_url,
8307
+ medium_image_url,
8308
+ specifications,
8309
+ description,
8310
+ specifications
8311
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products')."
8312
+ WHERE store_product_id =".$store_product_id;
8313
+ $quer=$this->db_do($q);
8314
+ $product=mysqli_fetch_array($quer);
8315
+
8316
+ $this->productDescription = (string) substr($product['description'],50,0);
8317
+ $this->fullProductDescription = (string)$product['description'];
8318
+ $this->lowPicUrl = (string)$product["medium_image_url"];//thumb_image_url"];
8319
+ $this->highPicUrl = (string)$product["main_image_url"];
8320
+ $this->productName = (string)$product["product_name"];
8321
+ $this->productId = (string)$product['product_sku'];
8322
+ $this->specifications = (string)$product['specifications'];
8323
+ $this->sinchProductId = (string)$product['sinch_product_id'];
8324
+ if($product['sinch_manufacturer_id']){
8325
+ $q="SELECT manufacturer_name
8326
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')."
8327
+ WHERE sinch_manufacturer_id=".$product['sinch_manufacturer_id'];
8328
+ $quer=$this->db_do($q);
8329
+ $manufacturer=mysqli_fetch_array($quer);
8330
+ $this->vendor = (string)$manufacturer['manufacturer_name'];
8331
+ }
8332
+ $q="SELECT DISTINCT ean_code
8333
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
8334
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
8335
+ ON sec.product_id=sp.sinch_product_id
8336
+ WHERE sp.store_product_id=".$store_product_id;
8337
+ $quer=$this->db_do($q);
8338
+ while ($row=mysqli_fetch_array($quer)){
8339
+ $EANarr[]=$row['ean_code'];
8340
+ }
8341
+ // $prodEAN = $productTag->EANCode;
8342
+ $EANstr='';
8343
+ /* $EANarr=null;
8344
+ foreach($prodEAN as $ellEAN){
8345
+ $EANarr[]=$ellEAN['EAN'];
8346
+ }
8347
+ */
8348
+ $EANstr=implode(", ",$EANarr);
8349
+ $this->EAN = (string)$EANstr;//$productTag->EANCode['EAN'];
8350
+ }
8351
+ #################################################################################################
8352
+
8353
+ private function loadProductStarfeatures($entity_id){
8354
+ $descriptionArray=array();
8355
+ $product_info_features = $this->db_do("
8356
+ SELECT c.feature_name AS name, b.text AS value
8357
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." a
8358
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." b
8359
+ ON a.restricted_value_id = b.restricted_value_id
8360
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features')." c
8361
+ ON b.category_feature_id = c.category_feature_id
8362
+ WHERE a.sinch_product_id = '" .$this->sinchProductId . "'" );
8363
+ while ($features = mysqli_fetch_array($product_info_features)) {
8364
+ $descriptionArray[$features['name']] = $features['value'];
8365
+ }
8366
+
8367
+
8368
+ $this->productDescriptionList = $descriptionArray;
8369
+ }
8370
+ #################################################################################################
8371
+
8372
+ private function loadRelatedProducts($entity_id){
8373
+ $this->sinchProductId;
8374
+ if(!$this->sinchProductId){
8375
+ return;
8376
+ }
8377
+ $q="SELECT
8378
+ st_prod.sinch_product_id,
8379
+ st_prod.product_sku,
8380
+ st_prod.product_name,
8381
+ st_prod.sinch_manufacturer_id,
8382
+ st_prod.store_category_id,
8383
+ st_prod.main_image_url,
8384
+ st_prod.thumb_image_url,
8385
+ st_prod.medium_image_url,
8386
+ st_prod.specifications,
8387
+ st_prod.description,
8388
+ st_prod.specifications,
8389
+ st_manuf.manufacturer_name,
8390
+ st_manuf.manufacturers_image
8391
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." st_rel_prod
8392
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." st_prod
8393
+ ON st_rel_prod.related_sinch_product_id=st_prod.sinch_product_id
8394
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." st_manuf
8395
+ ON st_prod.sinch_manufacturer_id=st_manuf.sinch_manufacturer_id
8396
+ WHERE st_rel_prod.sinch_product_id=".$this->sinchProductId;
8397
+
8398
+ // echo $q;
8399
+ $quer=$this->db_do($q);
8400
+ while($row=mysqli_fetch_array($quer)){
8401
+
8402
+ $productArray = array();
8403
+ $productArray['name'] = (string)$row['product_name'];
8404
+ $productArray['thumb'] = (string)$row['thumb_image_url'];
8405
+ $mpn = (string)$row['product_sku'];
8406
+ $productSupplierId = (int)$row['sinch_manufacturer_id'];
8407
+ $productArray['supplier_thumb'] = (string)($row['manufacturers_image']);
8408
+ $productArray['supplier_name'] = (string)$row['manufacturer_name'];
8409
+
8410
+ $this->relatedProducts[$mpn] = $productArray;
8411
+ }
8412
+ }
8413
+ #################################################################################################
8414
+ /**
8415
+ * load Gallery array from XML
8416
+ */
8417
+ public function loadGalleryPhotos($entity_id){
8418
+ /*$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
8419
+ if (!count($galleryPhotos)){
8420
+ return false;
8421
+ }
8422
+ */
8423
+ $store_product_id=$this->getStoreProductIdByEntity($entity_id);
8424
+ if(!$store_product_id){
8425
+ return;
8426
+ }
8427
+ $q=$this->db_do("SELECT COUNT(*) AS cnt
8428
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
8429
+ WHERE store_product_id=".$store_product_id);
8430
+
8431
+ $res=mysqli_fetch_array($q);
8432
+ if(!$res || !$res['cnt']){
8433
+ return false;
8434
+ }
8435
+ $q="SELECT
8436
+ image_url as Pic,
8437
+ thumb_image_url as ThumbPic
8438
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
8439
+ WHERE store_product_id=".$store_product_id;
8440
+
8441
+ $res=$this->db_do($q);
8442
+
8443
+ while($photo=mysqli_fetch_array($res)){
8444
+ $picHeight = (int)500;//$photo["PicHeight"];
8445
+ $picWidth = (int)500;//$photo["PicWidth"];
8446
+ $thumbUrl = (string)$photo["ThumbPic"];
8447
+ $picUrl = (string)$photo["Pic"];
8448
+
8449
+ array_push($this->galleryPhotos, array(
8450
+ 'height' => $picHeight,
8451
+ 'width' => $picWidth,
8452
+ 'thumb' => $thumbUrl,
8453
+ 'pic' => $picUrl
8454
+ ));
8455
+ }
8456
+ }
8457
+ #################################################################################################
8458
+ public function reloadProductImage($entity_id){
8459
+ $result = $this->db_do("
8460
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8461
+ entity_type_id,
8462
+ attribute_id,
8463
+ store_id,
8464
+ entity_id,
8465
+ value
8466
+ )(
8467
+ SELECT
8468
+ " . $this->_getProductEntityTypeId(). ",
8469
+ " . $this->_getProductAttributeId('image'). ",
8470
+ w.store_id,
8471
+ a.entity_id,
8472
+ b.main_image_url
8473
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8474
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8475
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8476
+ ON a.store_product_id = b.store_product_id
8477
+ WHERE a.entity_id=$entity_id
8478
+ )
8479
+ ON DUPLICATE KEY UPDATE
8480
+ value = b.main_image_url
8481
+ ");
8482
+
8483
+
8484
+ // image for specific web sites
8485
+ $result = $this->db_do("
8486
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8487
+ entity_type_id,
8488
+ attribute_id,
8489
+ store_id,
8490
+ entity_id,
8491
+ value
8492
+ )(
8493
+ SELECT
8494
+ " . $this->_getProductEntityTypeId(). ",
8495
+ " . $this->_getProductAttributeId('image'). ",
8496
+ 0,
8497
+ a.entity_id,
8498
+ b.main_image_url
8499
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8500
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8501
+ ON a.store_product_id = b.store_product_id
8502
+ WHERE a.entity_id=$entity_id
8503
+ )
8504
+ ON DUPLICATE KEY UPDATE
8505
+ value = b.main_image_url
8506
+ ");
8507
+
8508
+
8509
+ // small_image for specific web sites
8510
+ $result = $this->db_do("
8511
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8512
+ entity_type_id,
8513
+ attribute_id,
8514
+ store_id,
8515
+ entity_id,
8516
+ value
8517
+ )(
8518
+ SELECT
8519
+ " . $this->_getProductEntityTypeId(). ",
8520
+ " . $this->_getProductAttributeId('small_image'). ",
8521
+ w.store_id,
8522
+ a.entity_id,
8523
+ b.main_image_url
8524
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8525
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8526
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8527
+ ON a.store_product_id = b.store_product_id
8528
+ WHERE a.entity_id=$entity_id
8529
+ )
8530
+ ON DUPLICATE KEY UPDATE
8531
+ value = b.main_image_url
8532
+ ");
8533
+
8534
+
8535
+ // small_image for all web sites
8536
+ $result = $this->db_do("
8537
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8538
+ entity_type_id,
8539
+ attribute_id,
8540
+ store_id,
8541
+ entity_id,
8542
+ value
8543
+ )(
8544
+ SELECT
8545
+ " . $this->_getProductEntityTypeId(). ",
8546
+ " . $this->_getProductAttributeId('small_image'). ",
8547
+ 0,
8548
+ a.entity_id,
8549
+ b.main_image_url
8550
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8551
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8552
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8553
+ ON a.store_product_id = b.store_product_id
8554
+ WHERE a.entity_id=$entity_id
8555
+ )
8556
+ ON DUPLICATE KEY UPDATE
8557
+ value = b.main_image_url
8558
+ ");
8559
+ }
8560
+ #################################################################################################
8561
+ public function runIndexer(){
8562
+ $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'));
8563
+ $this->db_do ("SET FOREIGN_KEY_CHECKS=0");
8564
+ $this->db_do("TRUNCATE TABLE ".Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'));
8565
+ $this->db_do ("SET FOREIGN_KEY_CHECKS=1");
8566
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8567
+ SET value = ''
8568
+ WHERE entity_type_id=".$this->_getProductEntityTypeId()." AND attribute_id=".$this->_getProductAttributeId('url_key'));
8569
+ exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php reindexall');
8570
+ }
8571
+ #################################################################################################
8572
+ public function runStockPriceIndexer(){
8573
+ exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php --reindex catalog_product_price,cataloginventory_stock');
8574
+ }
8575
+ #################################################################################################
8576
+ private function getStoreProductIdByEntity($entity_id){
8577
+ $q=$this->db_do("SELECT store_product_id
8578
+ FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
8579
+ WHERE entity_id=".$entity_id);
8580
+ $res=mysqli_fetch_array($q);
8581
+ // echo $entity_id."AAAA".$res['store_product_id']; exit;
8582
+ return ($res['store_product_id']);
8583
+ }
8584
+ #################################################################################################
8585
+
8586
+ private function db_connect() {
8587
+ // $connection = Mage::getModel('core/resource')->getConnection('core_write');
8588
+ $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
8589
+ $dbConn = mysqli_init();
8590
+ mysqli_options($dbConn, MYSQLI_OPT_LOCAL_INFILE, true);
8591
+ if (mysqli_real_connect($dbConn, $dbConf->host, $dbConf->username, $dbConf->password)) {
8592
+ $this->db = $dbConn;
8593
+ if(!mysqli_select_db($this->db, $dbConf->dbname)){
8594
+ die("Can't select the database: " . mysqli_error($this->db));
8595
+ }
8596
+ }else{
8597
+ die("Could not connect: " . mysqli_error($this->db));
8598
+ }
8599
+
8600
+ }
8601
+ #################################################################################################
8602
+
8603
+ private function db_do($query) {
8604
+ if($this->debug_mode){
8605
+ Mage::log("Query: " . $query, null, $this->_logFile);
8606
+ }
8607
+ $result = mysqli_query($this->db, $query) or die("Query failed: " . mysqli_error($this->db));
8608
+ if (!$result) {
8609
+ throw new Exception("Invalid query: $sql\n" . mysqli_error($this->db));
8610
+ } else {
8611
+ return $result;
8612
+ }
8613
+ return $result;
8614
+ }
8615
+ ##################################################################################################
8616
+ function table_rows_count($table){
8617
+ $rows_count_res=$this->db_do("select count(*) as cnt from ".$table);
8618
+ $rows_count=mysqli_fetch_array($rows_count_res);
8619
+ return ($rows_count['cnt']);
8620
+ }
8621
+ ##################################################################################################
8622
+ function file_strings_count($parse_file){
8623
+ $files_str=count(file($parse_file));
8624
+ return $files_str;
8625
+ }
8626
+ ##################################################################################################
8627
+ function check_loaded_data($file, $table){
8628
+ $cnt_strings_in_file=$this->file_strings_count($file);
8629
+ $cnt_rows_int_table=$this->table_rows_count($table);
8630
+ $persent_cnt_strings_in_file=$cnt_strings_in_file / 10;
8631
+ if($cnt_rows_int_table > $persent_cnt_strings_in_file){
8632
+ return true;
8633
+ }else{
8634
+ return false;
8635
+ }
8636
+ }
8637
+ ##################################################################################################
8638
+
8639
+
8640
+ function valid_utf($string,$new_line = true){
8641
+ /* if($new_line == true){
8642
+ $string = preg_replace('/\\\n/',"\n",$string);
8643
+ }
8644
+ */
8645
+ $string = preg_replace('/™/','&#8482;',$string);
8646
+ $string = preg_replace("/®/",'&reg;',$string);
8647
+ $string = preg_replace("/≈/",'&asymp;',$string);
8648
+ $string = preg_replace("/".chr(226).chr(128).chr(157)."/",'&quot;',$string);
8649
+ $string = preg_replace("/".chr(226).chr(128).chr(153)."/",'&prime;',$string);
8650
+ $string = preg_replace("/°/",'&deg;',$string);
8651
+ $string = preg_replace("/±/",'&plusmn;',$string);
8652
+ $string = preg_replace("/µ/",'&micro;',$string);
8653
+ $string = preg_replace("/²/",'&sup2;',$string);
8654
+ $string = preg_replace("/³/",'&sup3;',$string);
8655
+ $string = preg_replace('/\xe2\x80\x93/','-',$string);
8656
+ $string = preg_replace('/\xe2\x80\x99/','\'',$string);
8657
+ $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
8658
+ $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
8659
+
8660
+ return utf8_decode($string);
8661
+
8662
+ // return $string;
8663
+ }
8664
+
8665
+ #################################################################################################
8666
+ function dropHTMLentities($entity_type_id, $attribute_id){
8667
+ // product name for all web sites
8668
+ $result = $this->db_do("
8669
+ SELECT value, entity_id
8670
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8671
+ WHERE entity_type_id=".$entity_type_id."
8672
+ AND attribute_id=".$attribute_id
8673
+ );
8674
+ while($row=mysqli_fetch_array($result)){
8675
+ $value=$this->valid_char($row['value']);
8676
+ if($value!='' and $value!=$row['value']){
8677
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8678
+ SET value='".mysqli_real_escape_string($this->db, $value)."'
8679
+ WHERE entity_id=".$row['entity_id']."
8680
+ AND entity_type_id=".$entity_type_id."
8681
+ AND attribute_id=".$attribute_id);
8682
+ }
8683
+
8684
+ }
8685
+ }
8686
+
8687
+ #################################################################################################
8688
+
8689
+ function valid_char($string){
8690
+ $string = preg_replace('/&#8482;/', ' ',$string);
8691
+ $string = preg_replace('/&reg;/', ' ',$string);
8692
+ $string = preg_replace('/&asymp;/', ' ',$string);
8693
+ $string = preg_replace('/&quot;/', ' ',$string);
8694
+ $string = preg_replace('/&prime;/', ' ',$string);
8695
+ $string = preg_replace('/&deg;/', ' ',$string);
8696
+ $string = preg_replace('/&plusmn;/', ' ',$string);
8697
+ $string = preg_replace('/&micro;/', ' ',$string);
8698
+ $string = preg_replace('/&sup2;/', ' ',$string);
8699
+ $string = preg_replace('/&sup3;/', ' ',$string);
8700
+ // $string = preg_replace('/\xe2\x80\x93/','-',$string);
8701
+ // $string = preg_replace('/\xe2\x80\x99/','\'',$string);
8702
+ // $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
8703
+ // $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
8704
+
8705
+ // return utf8_decode($string);
8706
+
8707
+ return $string;
8708
+ }
8709
+
8710
+ #################################################################################################
8711
+
8712
+ function _LOG($log){
8713
+
8714
+ if($log){
8715
+ // $q="insert into ".$this->import_log_table." (message_date, message) values(now(), '".$log."')";
8716
+ // $this->db_do($q);
8717
+ Mage::log($log, null, $this->_logFile);
8718
+ // list($usec, $sec) = explode(" ", microtime());
8719
+ // $time = ((float)$usec + (float)$sec);
8720
+ /* $time = date("D M j G:i:s T Y");
8721
+
8722
+ if($_SERVER['REMOTE_ADDR']){
8723
+ $log = "[".getmypid()."] "."[".$_SERVER['REMOTE_ADDR']."] "."[".$time."] ".$log."\n";
8724
+ error_log($log,3,LOG_FILE);
8725
+ }else{
8726
+ $log = "[".getmypid()."] "."[".$time."] ".$log."\n";
8727
+ error_log($log,3,LOG_FILE . ".cli");
8728
+ */
8729
+ }
8730
+ }
8731
+
8732
+ #################################################################################################
8733
+
8734
+ function wget(){
8735
+
8736
+ $got = func_num_args();
8737
+ $url = $file = $flag = false;
8738
+
8739
+ if($got<1){
8740
+ return false;
8741
+ }elseif($got == 1){
8742
+ $url = func_get_arg(0);
8743
+ }elseif($got == 2){
8744
+ $url = func_get_arg(0);
8745
+ $file= func_get_arg(1);
8746
+ }elseif($got == 3){
8747
+ $url = func_get_arg(0);
8748
+ $file= func_get_arg(1);
8749
+ $flag= func_get_arg(2);
8750
+ }
8751
+
8752
+ if($flag == 'copy'){
8753
+ if(copy($url,$file)){
8754
+ return true;
8755
+ }else{
8756
+ return false;
8757
+ }
8758
+ }elseif($flag == 'system'){
8759
+ exec("wget -O$file $url");
8760
+ return true;
8761
+ }else{
8762
+ $c=curl_init($url);
8763
+ curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
8764
+ curl_setopt($c,CURLOPT_FOLLOWLOCATION,1);
8765
+ curl_setopt($c,CURLOPT_HEADER,array("Accept-Encoding: gzip"));
8766
+ if(!$file){
8767
+ $page = curl_exec($c);
8768
+ curl_close($c);
8769
+ return $page;
8770
+ }else{
8771
+ $FH = fopen($file,"wb");// or echo"Can't open for writing ".$file;
8772
+ fwrite($FH,curl_exec($c));
8773
+ fclose($FH);
8774
+ curl_close($c);
8775
+ return true;
8776
+ }
8777
+ }
8778
+ }
8779
+ #################################################################################################
8780
+ /**
8781
+ * Create the import directory Hierarchy
8782
+ * @return false if directory already exists
8783
+ */
8784
+ public function createTemporaryImportDerictory(){
8785
+ $dirArray = explode('/', $this->varDir);
8786
+ end($dirArray);
8787
+ // $this->_LOG('before :'.$this->varDir);
8788
+ if (prev($dirArray)=='bintime'){
8789
+ return false;
8790
+ }
8791
+
8792
+
8793
+ $this->varDir = $this->varDir . 'bintime/sinchimport/';
8794
+ if (!is_dir($this->varDir)) {
8795
+ mkdir($this->varDir,0777,true);
8796
+ }
8797
+ // $this->_LOG('after :'.$this->varDir);
8798
+ }
8799
+ #################################################################################################
8800
+
8801
+ function count_children($id){
8802
+
8803
+ $q="SELECT store_category_id
8804
+ FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8805
+ WHERE parent_store_category_id=".$id;
8806
+ $quer=$this->db_do($q);
8807
+ $count=0;
8808
+ while ($row=mysqli_fetch_array($quer)){
8809
+ $count+=$this->count_children($row['store_category_id']);
8810
+ $count++;
8811
+ }
8812
+ return ($count);
8813
+ }
8814
+ #################################################################################################
8815
+ private function delete_old_sinch_categories_from_shop(){
8816
+
8817
+ $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." cat
8818
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8819
+ ON cat.entity_id=scm.shop_entity_id
8820
+ WHERE
8821
+ (scm.shop_store_category_id is not null) AND
8822
+ (scm.store_category_id is null)";
8823
+ $this->db_do($q);
8824
+
8825
+ $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." cat
8826
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8827
+ ON cat.entity_id=scm.shop_entity_id
8828
+ WHERE
8829
+ (scm.shop_store_category_id is not null) AND
8830
+ (scm.store_category_id is null)";
8831
+ $this->db_do($q);
8832
+
8833
+ $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cat
8834
+ JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8835
+ ON cat.entity_id=scm.shop_entity_id
8836
+ WHERE
8837
+ (scm.shop_store_category_id is not null) AND
8838
+ (scm.store_category_id is null)";
8839
+ $this->db_do($q);
8840
+
8841
+ }
8842
+ #################################################################################################
8843
+
8844
+ function culc_path($parent_id, $ent_id){
8845
+
8846
+ //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]\n");
8847
+
8848
+ $path='';
8849
+ $cat_id=$parent_id;
8850
+ $q="SELECT
8851
+ parent_id
8852
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
8853
+ WHERE entity_id=".$cat_id;
8854
+ $quer=$this->db_do($q);
8855
+ $row=mysqli_fetch_array($quer);
8856
+ while($row['parent_id']){
8857
+ $path=$row['parent_id'].'/'.$path;
8858
+ $q="SELECT
8859
+ parent_id
8860
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
8861
+ WHERE entity_id=".$row['parent_id'];
8862
+ $quer=$this->db_do($q);
8863
+ $row=mysqli_fetch_array($quer);
8864
+
8865
+ }
8866
+ if($cat_id){
8867
+ $path.=$cat_id."/";
8868
+ }
8869
+
8870
+ if($path){
8871
+ return($path.$ent_id);
8872
+ }else{
8873
+ return($ent_id);
8874
+ }
8875
+
8876
+ }
8877
+ #################################################################################################
8878
+
8879
+ function get_category_level($id){
8880
+ $q="SELECT parent_store_category_id
8881
+ FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8882
+ WHERE store_category_id=".$id;
8883
+ $quer=$this->db_do($q);
8884
+ $level=1;
8885
+ $row=mysqli_fetch_array($quer);
8886
+ while ($row['parent_store_category_id']!=0){
8887
+ $q="SELECT parent_store_category_id
8888
+ FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8889
+ WHERE store_category_id=".$row['parent_store_category_id'];
8890
+ $quer=$this->db_do($q);
8891
+ $row=mysqli_fetch_array($quer);
8892
+ $level++;
8893
+ if($level>20){
8894
+ break;
8895
+ }
8896
+ }
8897
+
8898
+ return($level);
8899
+ }
8900
+ #################################################################################################
8901
+
8902
+ function InitImportStatuses($type){
8903
+ $this->db_do("DROP TABLE IF EXISTS ".$this->import_status_table);
8904
+ $this->db_do("CREATE TABLE ".$this->import_status_table."(
8905
+ id int(11) NOT NULL auto_increment PRIMARY KEY,
8906
+ message varchar(50),
8907
+ finished int(1) default 0
8908
+ )"
8909
+ );
8910
+ $this->db_do("INSERT INTO ".$this->import_status_statistic_table." (
8911
+ start_import,
8912
+ finish_import,
8913
+ import_type,
8914
+ global_status_import,
8915
+ import_run_type,
8916
+ error_report_message)
8917
+ VALUES(
8918
+ now(),
8919
+ NULL,
8920
+ '$type',
8921
+ 'Run',
8922
+ '".$this->import_run_type."',
8923
+ ''
8924
+ )
8925
+ ");
8926
+ $q="SELECT MAX(id) AS id FROM ".$this->import_status_statistic_table;
8927
+
8928
+ $quer=$this->db_do($q);
8929
+ $row=mysqli_fetch_array($quer);
8930
+ $this->current_import_status_statistic_id=$row['id'];
8931
+ $this->db_do("UPDATE ".$this->import_status_statistic_table."
8932
+ SET global_status_import='Failed'
8933
+ WHERE global_status_import='Run' AND id!=".$this->current_import_status_statistic_id);
8934
+
8935
+ }
8936
+ #################################################################################################
8937
+ function set_imports_failed(){
8938
+ $this->db_do("UPDATE ".$this->import_status_statistic_table."
8939
+ SET global_status_import='Failed'
8940
+ WHERE global_status_import='Run'");
8941
+ }
8942
+ #################################################################################################
8943
+ function set_import_error_reporting_message($message){
8944
+ $this->db_do("UPDATE ".$this->import_status_statistic_table."
8945
+ SET error_report_message='".mysqli_real_escape_string($this->db, $message)."'
8946
+ WHERE id=".$this->current_import_status_statistic_id);
8947
+ }
8948
+ #################################################################################################
8949
+ function getImportStatusHistory(){
8950
+ $res="SELECT COUNT(*) FROM ".$this->import_status_statistic_table;
8951
+ $cnt_arr=mysqli_fetch_array($this->db_do($res));
8952
+ $cnt=$cnt_arr[0];
8953
+ $StatusHistory_arr = array();
8954
+ if($cnt>0){
8955
+ $a=(($cnt>7)? ($cnt-7): 0);
8956
+ $b=$cnt;
8957
+ $q="SELECT
8958
+ id,
8959
+ start_import,
8960
+ finish_import,
8961
+ import_type,
8962
+ number_of_products,
8963
+ global_status_import,
8964
+ detail_status_import
8965
+ FROM ".$this->import_status_statistic_table."
8966
+ ORDER BY start_import limit ".$a.", ".$b;
8967
+ $result=$this->db_do($q);
8968
+ while($row=mysqli_fetch_array($result)){
8969
+ $StatusHistory_arr[]=$row;
8970
+ }
8971
+ }
8972
+ return $StatusHistory_arr;
8973
+ }
8974
+ #################################################################################################
8975
+ function getDateOfLatestSuccessImport(){
8976
+ $q="SELECT start_import, finish_import
8977
+ FROM ".$this->import_status_statistic_table."
8978
+ WHERE global_status_import='Successful'
8979
+ ORDER BY id DESC LIMIT 1";
8980
+ $imp_date=mysqli_fetch_array($this->db_do($q));
8981
+ return $imp_date['start_import'];
8982
+ }
8983
+ #################################################################################################
8984
+ function getDataOfLatestImport(){
8985
+ $q="SELECT
8986
+ start_import,
8987
+ finish_import,
8988
+ import_type,
8989
+ number_of_products,
8990
+ global_status_import,
8991
+ detail_status_import,
8992
+ number_of_products,
8993
+ error_report_message
8994
+ FROM ".$this->import_status_statistic_table."
8995
+ ORDER BY id DESC LIMIT 1";
8996
+ $imp_status=mysqli_fetch_array($this->db_do($q));
8997
+ return $imp_status;
8998
+ }
8999
+
9000
+ #################################################################################################
9001
+ function addImportStatus($message, $finished=0){
9002
+ $q="INSERT INTO ".$this->import_status_table."
9003
+ (message, finished)
9004
+ VALUES('".$message."', $finished)";
9005
+ $this->db_do($q);
9006
+ $this->db_do("UPDATE ".$this->import_status_statistic_table."
9007
+ SET detail_status_import='".$message."'
9008
+ WHERE id=".$this->current_import_status_statistic_id);
9009
+ if($finished==1){
9010
+ $this->db_do("UPDATE ".$this->import_status_statistic_table."
9011
+ SET
9012
+ global_status_import='Successful',
9013
+ finish_import=now()
9014
+ WHERE
9015
+ error_report_message='' and
9016
+ id=".$this->current_import_status_statistic_id);
9017
+ }
9018
+ }
9019
+ #################################################################################################
9020
+
9021
+ function getImportStatuses(){
9022
+ $q="SELECT id, message, finished
9023
+ FROM ".$this->import_status_table."
9024
+ ORDER BY id LIMIT 1";
9025
+ $quer=$this->db_do($q);
9026
+ if($row=mysqli_fetch_array($quer)){
9027
+ $messages=array('message'=>$row['message'], 'id'=>$row['id'], 'finished'=>$row['finished']);
9028
+ $id=$row['id'];
9029
+ }
9030
+ if($id){
9031
+ $q="DELETE FROM ".$this->import_status_table." WHERE id=".$id;
9032
+ $this->db_do($q);
9033
+ }
9034
+ return $messages;
9035
+ }
9036
+ #################################################################################################
9037
+
9038
+ private function _getEntityTypeId($code) {
9039
+ $sql = "
9040
+ SELECT entity_type_id
9041
+ FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9042
+ WHERE entity_type_code = '".$code."'
9043
+ LIMIT 1
9044
+ ";
9045
+ $result = $this->db_do($sql);
9046
+ if ($row = mysqli_fetch_assoc($result)) {
9047
+ return $row['entity_type_id'];
9048
+ }
9049
+ return false;
9050
+ }
9051
+ #################################################################################################
9052
+
9053
+ private function _getProductEntityTypeId(){
9054
+ if (!$this->_productEntityTypeId) {
9055
+ $this->_productEntityTypeId = $this->_getEntityTypeId('catalog_product');
9056
+ }
9057
+ return $this->_productEntityTypeId;
9058
+ }
9059
+ #################################################################################
9060
+
9061
+ private function _getProductDefaulAttributeSetId(){
9062
+ if (!$this->defaultAttributeSetId) {
9063
+ $sql = "
9064
+ SELECT entity_type_id, default_attribute_set_id
9065
+ FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9066
+ WHERE entity_type_code = 'catalog_product'
9067
+ LIMIT 1
9068
+ ";
9069
+ $result = $this->db_do($sql);
9070
+ if ($row = mysqli_fetch_assoc($result)) {
9071
+
9072
+ $this->defaultAttributeSetId = $row['default_attribute_set_id'];
9073
+ }
9074
+ }
9075
+ return $this->defaultAttributeSetId;
9076
+ }
9077
+ #################################################################################################
9078
+
9079
+ private function _getCategoryEntityTypeIdAndDefault_attribute_set_id(){
9080
+ if (!$this->_categoryEntityTypeId || !$this->_categoryDefault_attribute_set_id) {
9081
+ $sql = "
9082
+ SELECT entity_type_id, default_attribute_set_id
9083
+ FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9084
+ WHERE entity_type_code = 'catalog_category'
9085
+ LIMIT 1
9086
+ ";
9087
+ $result = $this->db_do($sql);
9088
+ if ($row = mysqli_fetch_assoc($result)) {
9089
+ $this->_categoryEntityTypeId = $row['entity_type_id'];
9090
+ $this->_categoryDefault_attribute_set_id = $row['default_attribute_set_id'];
9091
+ }
9092
+
9093
+ }
9094
+ }
9095
+ ##################################################################################################
9096
+
9097
+ private function _getAttributeId($attributeCode,$typeCode)
9098
+ {
9099
+ if ($typeCode=='catalog_product') {
9100
+ $typeId = $this->_getProductEntityTypeId();
9101
+ }
9102
+ else {
9103
+ $typeId = $this->_getEntityTypeId($typeCode);
9104
+ }
9105
+ if (!isset($this->_attributeId[$typeCode]) OR !is_array($this->_attributeId[$typeCode])) {
9106
+ $sql = "
9107
+ SELECT attribute_id, attribute_code
9108
+ FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute')."
9109
+ WHERE entity_type_id = '" . $typeId . "'
9110
+ ";
9111
+ $result = $this->db_do($sql);
9112
+ while ($row = mysqli_fetch_assoc($result)) {
9113
+ $this->_attributeId[$typeCode][$row['attribute_code']] = $row['attribute_id'];
9114
+ }
9115
+ }
9116
+ // echo 'attribute code: '.$attributeCode.','.$typeCode.' => '.$this->_attributeId[$typeCode][$attributeCode].PHP_EOL;
9117
+ return $this->_attributeId[$typeCode][$attributeCode];
9118
+ }
9119
+ ##################################################################################################
9120
+
9121
+ private function repl_ph($content,$hash){
9122
+ if($hash){
9123
+ foreach($hash as $key => $val){
9124
+ if ($key=="category_name") {
9125
+ if (strlen($val)>25) { $val = substr($val,0,24)."..."; }
9126
+ }
9127
+ $content = preg_replace("/%%%$key%%%/",$val,$content);
9128
+ }
9129
+ }
9130
+ return $content;
9131
+ }
9132
+ ##################################################################################################
9133
+
9134
+ private function _getProductAttributeId($attributeCode) {
9135
+ return $this->_getAttributeId($attributeCode,'catalog_product');
9136
+ }
9137
+ ##################################################################################################
9138
+
9139
+ private function _getCategoryAttributeId($attributeCode) {
9140
+ return $this->_getAttributeId($attributeCode,'catalog_category');
9141
+ }
9142
+ ##################################################################################################
9143
+ private function _getShopRootCategoryId($cat_id=0){
9144
+ if($root_cat = Mage::app()->getStore()->getRootCategoryId()){
9145
+ return $root_cat;
9146
+ }else{
9147
+ $q="SELECT
9148
+ entity_id
9149
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')."
9150
+ WHERE
9151
+ value='default-category'";
9152
+ $res=$this->db_do($q);
9153
+ $row=mysqli_fetch_array($res);
9154
+ if($row['entity_id']>0){
9155
+ return $row['entity_id'];
9156
+ }else{
9157
+ $q="SELECT entity_id
9158
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
9159
+ WHERE parent_id=".$cat_id;
9160
+ $quer=$this->db_do($q);
9161
+ $count=0;
9162
+ while ($row=mysqli_fetch_array($quer)){
9163
+ $count++;
9164
+ $entity_id=$row['entity_id'];
9165
+ }
9166
+ if($count>1 || $count==0){
9167
+ return ($cat_id);
9168
+ }else{
9169
+ return $this->_getShopRootCategoryId($entity_id);
9170
+ }
9171
+ }
9172
+ }
9173
+ }
9174
+ ##################################################################################################
9175
+ private function _cleanCateoryProductFlatTable(){
9176
+ $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
9177
+ $q='SHOW TABLES LIKE "'.Mage::getSingleton('core/resource')->getTableName('catalog_product_flat_').'%"';
9178
+ $quer=$this->db_do($q);
9179
+ $result=false;
9180
+ While($row=mysqli_fetch_array($quer)){
9181
+ if(is_array($row)){
9182
+ $catalog_product_flat=array_pop($row);
9183
+ $q='DELETE pf1 FROM '.$catalog_product_flat.' pf1
9184
+ LEFT JOIN '.Mage::getSingleton('core/resource')->getTableName('catalog_product_entity').' p
9185
+ ON pf1.entity_id = p.entity_id
9186
+ WHERE p.entity_id IS NULL;';
9187
+ $this->db_do($q);
9188
+ $this->_LOG('cleaned wrong rows from '.$catalog_product_flat);
9189
+ }
9190
+ }
9191
+ return $result;
9192
+
9193
+ }
9194
+ ##################################################################################################
9195
+
9196
+
9197
+
9198
+
9199
+
9200
+ ##################################################################################################
9201
+ public function checkMemory() {
9202
+ $check_code = 'memory';
9203
+
9204
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9205
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9206
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9207
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9208
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9209
+
9210
+
9211
+ $Caption = $row['caption'];
9212
+ $CheckValue = $row['check_value'];
9213
+ $CheckMeasure = $row['check_measure'];
9214
+ $ErrorMessage = $row['error_msg'];
9215
+ $FixMessage = $row['fix_msg'];
9216
+
9217
+ $retvalue = array();
9218
+ $retvalue["'$check_code'"] = array();
9219
+
9220
+ $data = explode("\n", file_get_contents("/proc/meminfo"));
9221
+
9222
+ $meminfo = array();
9223
+ foreach ($data as $line) {
9224
+ list($key, $val) = explode(":", $line);
9225
+ $meminfo[$key] = trim($val);
9226
+
9227
+ if ($key == 'MemTotal') {
9228
+ $val = trim($val);
9229
+ $value = (int)substr($val, 0, strpos($val, ' kB'));
9230
+ $measure = substr($val, strpos($val, ' kB'));
9231
+
9232
+ $retvalue['memory']['value'] = (integer)(((float)$value)/1024); // (float)$value
9233
+ $retvalue['memory']['measure'] = 'MB'; // $measure;
9234
+ }
9235
+ }
9236
+
9237
+ $errmsg = '';
9238
+ $fixmsg = '';
9239
+ if ($retvalue['memory']['value'] <= $CheckValue) {
9240
+ $errmsg .= sprintf($ErrorMessage, $retvalue['memory']['value']); //." ".$retvalue['memory']['value']." ".$retvalue['memory']['measure'];
9241
+ $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
9242
+ $retvalue['memory']['status'] = 'error';
9243
+ } else {
9244
+ $errmsg .= 'none';
9245
+ $fixmsg .= 'none';
9246
+ $retvalue['memory']['status'] = 'OK';
9247
+ }
9248
+
9249
+ $ret = array();
9250
+ array_push($ret, $retvalue['memory']['status'], $Caption, $CheckValue, $retvalue['memory']['value'], $CheckMeasure, $errmsg, $fixmsg);
9251
+
9252
+ return $ret;
9253
+ } // public function getImportEnvironment()
9254
+ ##################################################################################################
9255
+
9256
+
9257
+
9258
+
9259
+ ##################################################################################################
9260
+ public function checkLoaddata() {
9261
+ $check_code = 'loaddata';
9262
+
9263
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9264
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9265
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9266
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9267
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9268
+
9269
+ $Caption = $row['caption'];
9270
+ $CheckValue = $row['check_value'];
9271
+ $CheckMeasure = $row['check_measure'];
9272
+ $ErrorMessage = $row['error_msg'];
9273
+ $FixMessage = $row['fix_msg'];
9274
+
9275
+ $retvalue = array();
9276
+ $retvalue["'$check_code'"] = array();
9277
+
9278
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9279
+ $result = $conn->query("SHOW VARIABLES LIKE 'local_infile'");
9280
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9281
+ $value = $row['Value'];
9282
+
9283
+
9284
+ $errmsg = '';
9285
+ $fixmsg = '';
9286
+ if ($value != $CheckValue) {
9287
+ $errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
9288
+ $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9289
+ $status = 'error';
9290
+ } else {
9291
+ $errmsg .= 'none';
9292
+ $f