stockinthechannel2012 - Version 1.0.0.0

Version Notes

This has been out to the market for 6 months and is only now being released via Magento Connect. As such it is stable

Installation guides will help you get it working quickly

Download this release

Release Info

Developer stockinchannel
Extension stockinthechannel2012
Version 1.0.0.0
Comparing to
See all releases


Version 1.0.0.0

Files changed (50) hide show
  1. app/code/local/Bintime/Sinchimport/Block/Importhistory.php +386 -0
  2. app/code/local/Bintime/Sinchimport/Block/Layer/Filter/Feature.php +17 -0
  3. app/code/local/Bintime/Sinchimport/Block/Layer/View.php +49 -0
  4. app/code/local/Bintime/Sinchimport/Block/List.php +130 -0
  5. app/code/local/Bintime/Sinchimport/Block/Product/View/Media.php +19 -0
  6. app/code/local/Bintime/Sinchimport/Block/Startimportbutton.php +344 -0
  7. app/code/local/Bintime/Sinchimport/Block/Startstockpriceimportbutton.php +138 -0
  8. app/code/local/Bintime/Sinchimport/Helper/Data.php +6 -0
  9. app/code/local/Bintime/Sinchimport/Helper/Getdata.php +186 -0
  10. app/code/local/Bintime/Sinchimport/Helper/Image.php +73 -0
  11. app/code/local/Bintime/Sinchimport/Model/Api.php +86 -0
  12. app/code/local/Bintime/Sinchimport/Model/Category.php +20 -0
  13. app/code/local/Bintime/Sinchimport/Model/Image.php +118 -0
  14. app/code/local/Bintime/Sinchimport/Model/Layer.php +214 -0
  15. app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Feature.php +255 -0
  16. app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Price.php +194 -0
  17. app/code/local/Bintime/Sinchimport/Model/Product.php +74 -0
  18. app/code/local/Bintime/Sinchimport/Model/Resource/Layer/Filter/Price.php +64 -0
  19. app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php +383 -0
  20. app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Setup.php +4 -0
  21. app/code/local/Bintime/Sinchimport/Model/Sinch.php +3584 -0
  22. app/code/local/Bintime/Sinchimport/Model/System/Config/CatRewrite.php +18 -0
  23. app/code/local/Bintime/Sinchimport/Model/System/Config/Subscription.php +40 -0
  24. app/code/local/Bintime/Sinchimport/Model/config.php +56 -0
  25. app/code/local/Bintime/Sinchimport/controllers/AjaxController.php +62 -0
  26. app/code/local/Bintime/Sinchimport/controllers/IndexController.php +46 -0
  27. app/code/local/Bintime/Sinchimport/controllers/ProductController.php +44 -0
  28. app/code/local/Bintime/Sinchimport/controllers/SplitfeaturesController.php +16 -0
  29. app/code/local/Bintime/Sinchimport/etc/api.xml +34 -0
  30. app/code/local/Bintime/Sinchimport/etc/config.xml +244 -0
  31. app/code/local/Bintime/Sinchimport/etc/system.xml +155 -0
  32. app/code/local/Bintime/Sinchimport/sinch_import_start_ajax.php +14 -0
  33. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/filter_sinch_products_s.sql +110 -0
  34. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-install-0.1.0.php +142 -0
  35. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.0-0.1.1.php +67 -0
  36. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.1-0.1.2.php +30 -0
  37. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.2-0.1.3.php +133 -0
  38. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.3-0.1.4.php +53 -0
  39. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.4-0.1.5.php +33 -0
  40. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.5-0.1.6.php +13 -0
  41. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.6-0.1.7.php +155 -0
  42. app/code/local/Bintime/Sinchimport/stock_price_sinch_import_start_ajax.php +14 -0
  43. app/design/frontend/default/default/layout/sinchimport.xml +110 -0
  44. app/design/frontend/default/default/template/sinchimport/list.phtml +153 -0
  45. app/design/frontend/default/default/template/sinchimport/media.phtml +89 -0
  46. app/design/frontend/default/default/template/sinchimport/view.phtml +363 -0
  47. app/etc/modules/Bintime_Sinchimport.xml +10 -0
  48. package.xml +25 -0
  49. skin/adminhtml/default/default/images/sinchimport_run.gif +0 -0
  50. skin/adminhtml/default/default/images/sinchimport_yes.gif +0 -0
app/code/local/Bintime/Sinchimport/Block/Importhistory.php ADDED
@@ -0,0 +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
+ ?>
app/code/local/Bintime/Sinchimport/Block/Layer/Filter/Feature.php ADDED
@@ -0,0 +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
+ }
app/code/local/Bintime/Sinchimport/Block/Layer/View.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php
3
+
4
+ class Bintime_Sinchimport_Block_Layer_View extends Mage_Catalog_Block_Layer_View
5
+ {
6
+
7
+ protected $filterableFeatures = array();
8
+
9
+ /**
10
+ * Prepare child blocks
11
+ *
12
+ * @return Mage_Catalog_Block_Layer_View
13
+ */
14
+ protected function _prepareLayout()
15
+ {
16
+ //получение списка фич, по которым строися навигация
17
+ $filterableFeatures = $this->getLayer()->getFilterableFeatures();
18
+ $filterBlockName = 'sinchimport/layer_filter_feature'; //block
19
+ foreach ($filterableFeatures as $feature) {
20
+ $this->filterableFeatures[] = $feature;
21
+ $featureBlock = $this->getLayout()->createBlock($filterBlockName)
22
+ ->setLayer($this->getLayer())
23
+ ->setAttributeModel($feature)
24
+ ->init();
25
+ $this->setChild('feature_' . $feature['feature_id'] . '_filter',
26
+ $featureBlock
27
+ );
28
+ }
29
+ /* ------------ */
30
+ return parent::_prepareLayout();
31
+ }
32
+
33
+ /**
34
+ * Get all layer filters
35
+ *
36
+ * @return array
37
+ */
38
+ public function getFilters()
39
+ {
40
+ $filters = parent::getFilters();
41
+ /* ------------ */
42
+ foreach ($this->filterableFeatures as $feature) {
43
+ $filters[] = $this->getChild('feature_' . $feature['feature_id'] . '_filter');
44
+ }
45
+ /* ------------ */
46
+
47
+ return $filters;
48
+ }
49
+ }
app/code/local/Bintime/Sinchimport/Block/List.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = '$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 stINch_products p
32
+ JOIN stINch_products_mapping pm on
33
+ pm.shop_store_product_id = p.store_product_id and pm.shop_sinch_product_id=p.sinch_product_id
34
+ WHERE pm.entity_id IN ( $to_compare )";
35
+ $sinch = $this->tep_db_query($query);
36
+ while($data = $sinch->fetch(PDO::FETCH_ASSOC)){
37
+ $this->ins_from_htm($data['sinch_product_id'],$data['store_product_id'],$data['specifications'],$tmp_table_sorted);
38
+ $sinch_products_array[] = $data['sinch_product_id'];
39
+ $this->_compareSinchStoreProd[$data['entity_id']]=$data['sinch_product_id'];
40
+ }
41
+ $sinch_products = implode(',', $sinch_products_array);
42
+
43
+ $this->tep_db_query("insert ignore into $tmp_table_sorted (store_category_id, sinch_product_id, category_feature_id, feature_name, restricted_value_id, text)(select cf.store_category_id, pf.sinch_product_id, cf.category_feature_id, cf.feature_name, rv.restricted_value_id, rv.text from stINch_categories_features cf join stINch_restricted_values rv on cf.category_feature_id=rv.category_feature_id join stINch_product_features pf on rv.restricted_value_id=pf.restricted_value_id where sinch_product_id in (".$sinch_products.") order by cf.display_order_number, pf.sinch_product_id)");
44
+ $this->tep_db_query("update $tmp_table_sorted t join stINch_products p on t.sinch_product_id=p.sinch_product_id set t.store_product_id=p.store_product_id");
45
+
46
+ $this->goods = array();
47
+
48
+ $product_query = $this->tep_db_query("select store_product_id, sinch_product_id, category_feature_id, store_category_id, feature_name, text
49
+ FROM $tmp_table_sorted
50
+ ORDER BY id ASC");
51
+ while($data = $product_query->fetch(PDO::FETCH_ASSOC)){
52
+ $this->goods[$data['sinch_product_id']]['category_features'][$data['feature_name']] = array(
53
+
54
+
55
+ 'category_feature_id' => $data['category_feature_id'],
56
+ 'value' => $data['text'],
57
+
58
+
59
+ 'feature_name' => $data['feature_name'],
60
+ );
61
+ }
62
+ $catfeats = $this->tep_db_query("SELECT category_feature_id, feature_name FROM $tmp_table_sorted
63
+ GROUP BY feature_name
64
+ ORDER BY category_feature_id");
65
+ while($fdata = $catfeats->fetch(PDO::FETCH_ASSOC)){
66
+ $cf[] = $fdata;
67
+ }
68
+ return $cf;
69
+ }
70
+
71
+ public function GetSinchCompareProdAttributes(){
72
+ return $this->goods;
73
+ }
74
+
75
+ public function getSinchAttributeName($cf)
76
+ {
77
+ return $cf['feature_name'];
78
+ }
79
+
80
+ public function getSinchProductAttributeValue($product, $cf)
81
+ {
82
+
83
+ $prod = $this->_compareSinchStoreProd[$product->getID()];
84
+ $feature_name = $cf['feature_name'];
85
+ $data = $this->goods[$prod]['category_features'][$feature_name]['value'];
86
+ $data = Mage::getModel('sinchimport/sinch')->valid_utf($data);
87
+ return $data;
88
+ }
89
+
90
+ private function ins_from_htm($sinch_product_id, $store_product_id, $htm, $tmp_table_sorted){
91
+ if($htm){
92
+ /** создаем новый dom-объект **/
93
+ $dom = new domDocument;
94
+ /** загружаем html в объект **/
95
+ $dom->loadHTML($htm);
96
+ $dom->preserveWhiteSpace = false;
97
+
98
+ /** элемент по тэгу **/
99
+ $tables = $dom->getElementsByTagName('table');
100
+
101
+ /** получаем все строки таблицы **/
102
+ $rows = $tables->item(0)->getElementsByTagName('tr');
103
+
104
+ /** цикл по строкам **/
105
+ $i=0;
106
+ foreach ($rows as $row)
107
+ {
108
+ /** все ячейки по тэгу **/
109
+ $cols = $row->getElementsByTagName('td');
110
+ /** выводим значения **/
111
+ $name = $cols->item(0)->nodeValue;
112
+ $value = $cols->item(1)->nodeValue;
113
+
114
+ if($value && $i){
115
+ $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."')";
116
+ $this->tep_db_query($q);
117
+ }
118
+ //mysql_real_escape_string($name)
119
+ $i++;
120
+ }
121
+ }
122
+ }
123
+ private function tep_db_query($q){
124
+ $resource = Mage::getResourceSingleton('catalog/product');
125
+ $connection = $resource->getReadConnection();
126
+ $result = $connection->query($q);
127
+ return($result);
128
+ }
129
+
130
+ }
app/code/local/Bintime/Sinchimport/Block/Product/View/Media.php ADDED
@@ -0,0 +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
+ ?>
app/code/local/Bintime/Sinchimport/Block/Startimportbutton.php ADDED
@@ -0,0 +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
+ ?>
app/code/local/Bintime/Sinchimport/Block/Startstockpriceimportbutton.php ADDED
@@ -0,0 +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
+ ?>
app/code/local/Bintime/Sinchimport/Helper/Data.php ADDED
@@ -0,0 +1,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 ADDED
@@ -0,0 +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
+ ?>
app/code/local/Bintime/Sinchimport/Helper/Image.php ADDED
@@ -0,0 +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
+ }
app/code/local/Bintime/Sinchimport/Model/Api.php ADDED
@@ -0,0 +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
+ ?>
app/code/local/Bintime/Sinchimport/Model/Category.php ADDED
@@ -0,0 +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
+ ?>
app/code/local/Bintime/Sinchimport/Model/Image.php ADDED
@@ -0,0 +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
+ }
app/code/local/Bintime/Sinchimport/Model/Layer.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /* $iceCategories = $this->_getIceCategoryIds();
15
+ if (empty($iceCategories))
16
+ return array();
17
+ */
18
+ $category = Mage::registry('current_category');
19
+ $categoryId = $category->getEntityId();
20
+ $resource = Mage::getSingleton('core/resource');
21
+ $tCategor = $resource->getTableName('stINch_categories');
22
+ $tCatFeature = $resource->getTableName('stINch_categories_features');
23
+ $tRestrictedVal = $resource->getTableName('stINch_restricted_values');
24
+ $tCategMapp = $resource->getTableName('stINch_categories_mapping');
25
+
26
+ $select = new Varien_Db_Select(Mage::getSingleton('core/resource')->getConnection('core_read'));
27
+ $select->from(array('cf' => $tCatFeature))
28
+ ->joinInner(
29
+ array('rv' => $tRestrictedVal),
30
+ 'cf.category_feature_id = rv.category_feature_id'
31
+ )
32
+ ->joinInner(
33
+ array('cm' => $tCategMapp),
34
+ 'cf.store_category_id = cm.store_category_id'
35
+ )
36
+ ->where('cm.shop_entity_id = '.$categoryId)
37
+ ->group('cf.feature_name')
38
+ ->order('cf.display_order_number', 'asc')
39
+ ->order('cf.feature_name', 'asc')
40
+ ->order('rv.display_order_number', 'asc');
41
+ ;
42
+ $select->columns('cf.feature_name AS name');
43
+ $select->columns('cf.category_feature_id as feature_id');
44
+ $select->columns('GROUP_CONCAT(`rv`.`text` SEPARATOR "\n") as restricted_values');
45
+ $result = $select->query();
46
+ // echo $select->__toString();
47
+ //exit;
48
+ Varien_Profiler::stop(__METHOD__);
49
+ return $result;
50
+ }
51
+
52
+ /**
53
+ * Возвращает id icecat-категорий, к которым относятся продукты в текущей категории.
54
+ *
55
+ * @return array
56
+ */
57
+ protected function _getIceCategoryIds()
58
+ {
59
+ Varien_Profiler::start(__METHOD__);
60
+ $select = clone $this->getProductCollection()->getSelect();
61
+
62
+ $resource = Mage::getSingleton('core/resource');
63
+ $tProducts = $resource->getTableName('icecat_products');
64
+
65
+ $select->join(
66
+ array('_ip' => $tProducts),
67
+ '_ip.mpn = e.vendor_product_id'
68
+
69
+ );
70
+
71
+ $select->reset(Zend_Db_Select::COLUMNS);
72
+ $select->distinct(true);
73
+ $select->columns('_ip.category_id');
74
+
75
+ Varien_Profiler::stop(__METHOD__);
76
+
77
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select);
78
+ }
79
+
80
+ /**
81
+ * Возвращает фичи, по которым следует строить навигацию для данной категории.
82
+ *
83
+ * @return mixed
84
+ */
85
+ public function getFilterableFeaturesForEdit($categoryId)
86
+ {
87
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
88
+ $iceCategories = $this->_getIceCategoryIdsForEdit($categoryId);
89
+ $iceCategories = implode(',',$iceCategories);
90
+ if (empty($iceCategories))
91
+ return '';
92
+
93
+ $resource = Mage::getSingleton('core/resource');
94
+ $tFeature = $resource->getTableName('icecat_feature');
95
+ $tFeatureDesc = $resource->getTableName('icecat_feature_description');
96
+ $tFeatureEnab = $resource->getTableName('icecat_category_feature_enabled');
97
+ $tCatFeature = $resource->getTableName('icecat_category_feature');
98
+ $tMeasure = $resource->getTableName('icecat_measures_list');
99
+
100
+ $select = "SELECT `_if`.*, `ifd`.*, `icf`.*, `im`.*,IF(ife.name is NULL,ifd.name,ife.name) as name,IF(ife.enabled is NULL,icf.searchable,ife.enabled) as enabled,ife.position,IF(ife.restricted is NULL,icf.restricted_values,ife.restricted) as restricted_values,ife.order_val
101
+ FROM $tFeature AS _if
102
+ INNER JOIN $tFeatureDesc AS ifd
103
+ ON ifd.feature_id = _if.feature_id
104
+ LEFT JOIN $tCatFeature AS icf
105
+ ON icf.feature_id = _if.feature_id
106
+ LEFT JOIN $tFeatureEnab AS ife
107
+ ON ife.feature_id = ifd.feature_id AND ife.category_id = $categoryId
108
+ INNER JOIN $tMeasure AS im
109
+ ON im.measure_id = icf.measure_id
110
+ WHERE ifd.langid = 1
111
+ AND (icf.category_id IN ($iceCategories))
112
+ AND (icf.restricted_values <> '') GROUP BY _if.feature_id;
113
+ ";
114
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($select);
115
+ }
116
+
117
+ /**
118
+ * Возвращает id icecat-категорий, к которым относятся продукты в текущей категории.
119
+ *
120
+ * @return array
121
+ */
122
+ protected function _getIceCategoryIdsForEdit($categoryId)
123
+ {
124
+ $select = "
125
+ SELECT DISTINCT `_ip`.`category_id`
126
+ FROM `catalog_product_entity` AS `e`
127
+ INNER JOIN `catalog_category_product_index` AS `cat_index`
128
+ ON cat_index.product_id=e.entity_id
129
+ AND cat_index.store_id='1'
130
+ AND cat_index.visibility IN(2, 4)
131
+ AND cat_index.category_id='".$categoryId."'
132
+ INNER JOIN `catalog_product_index_price` AS `price_index`
133
+ ON price_index.entity_id = e.entity_id AND price_index.website_id = '1'
134
+ AND price_index.customer_group_id = 0
135
+ INNER JOIN `icecat_products` AS `_ip`
136
+ ON _ip.mpn = e.vendor_product_id
137
+ ;
138
+ ";
139
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select);
140
+
141
+ }
142
+
143
+ public function saveFeatures($categoryId,$features)
144
+ {
145
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
146
+ $features = explode(',',$features);
147
+ $featureId = $features[0];
148
+ $nameFeatures = $features[1];
149
+ $enabled = $features[2];
150
+ $position = $features[3];
151
+ $restricted = $features[4];
152
+ if (!isset($features[5])) {
153
+ $order_val = 1;
154
+ }
155
+ else {
156
+ $order_val = $features[5];
157
+ }
158
+ $connection->query("
159
+ REPLACE INTO icecat_category_feature_enabled (
160
+ feature_id,
161
+ position,
162
+ category_id,
163
+ name,
164
+ restricted,
165
+ order_val,
166
+ enabled
167
+ ) VALUE (
168
+ ".$featureId.",
169
+ ".$position.",
170
+ ".$categoryId.",
171
+ '".$nameFeatures."',
172
+ '".$restricted."',
173
+ ".$order_val.",
174
+ ".$enabled."
175
+ )
176
+ ");
177
+ }
178
+
179
+ public function getCount($category_feature_id,$categoryId)
180
+ {
181
+ $select = "
182
+ SELECT idx_".$category_feature_id.".value, COUNT(e.entity_id) AS count
183
+ FROM catalog_product_entity AS e
184
+ INNER JOIN catalog_category_product_index AS cat_index ON cat_index.product_id=e.entity_id AND cat_index.store_id='1'
185
+ AND cat_index.visibility IN(2, 4) AND cat_index.category_id='".$categoryId."'
186
+ INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1'
187
+ AND price_index.customer_group_id = 0
188
+ INNER JOIN icecat_products_feature_".$category_feature_id." AS idx_".$category_feature_id."
189
+ ON idx_".$category_feature_id.".entity_id = e.entity_id GROUP BY idx_".$category_feature_id.".value
190
+ ";
191
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($select);
192
+ }
193
+
194
+ public function getIntervalCount($category_feature_id,$categoryId)
195
+ {
196
+ $select = "
197
+ SELECT COUNT(e.entity_id) AS count
198
+ FROM catalog_product_entity AS e
199
+ INNER JOIN catalog_category_product_index AS cat_index
200
+ ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.visibility IN(2, 4) AND cat_index.category_id='".$categoryId."'
201
+ INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1'
202
+ AND price_index.customer_group_id = 0
203
+ INNER JOIN icecat_products_feature_".$category_feature_id." AS idx_".$category_feature_id."
204
+ ON idx_".$category_feature_id.".entity_id = e.entity_id;
205
+ ";
206
+
207
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select);
208
+ }
209
+
210
+
211
+
212
+
213
+
214
+ }
app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Feature.php ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 catalog_product_entity AS e
244
+ INNER JOIN catalog_category_product_index AS cat_index
245
+ ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.visibility IN(2, 4) AND cat_index.category_id='".$categoryId."'
246
+ INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1'
247
+ AND price_index.customer_group_id = 0
248
+ INNER JOIN stINch_products_feature_".$category_feature_id." AS idx_".$category_feature_id."
249
+ ON idx_".$category_feature_id.".entity_id = e.icecat_product_id;
250
+ ";
251
+
252
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select);
253
+ }
254
+
255
+ }
app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Price.php ADDED
@@ -0,0 +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
+ }
app/code/local/Bintime/Sinchimport/Model/Product.php ADDED
@@ -0,0 +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
+
app/code/local/Bintime/Sinchimport/Model/Resource/Layer/Filter/Price.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
64
+ ?>
app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php ADDED
@@ -0,0 +1,383 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $result = $connection->raw_query("CALL `filter_sinch_products_s`($cfid, $catId,0, $cfid, $params)");
101
+ Varien_Profiler::stop(__METHOD__);
102
+ return $resultTable;
103
+ }
104
+
105
+
106
+ /**
107
+ * Apply attribute filter to product collection
108
+ *
109
+ * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
110
+ * @param string $value
111
+ * @return Bintime_Icelayered_Model_Resource_Mysql4_Layer_Filter_Feature
112
+ */
113
+ public function applyFilterToCollection($filter, $value)
114
+ {
115
+ Varien_Profiler::start(__METHOD__);
116
+ $searchTable = $this->_prepareSearch($filter, $value);
117
+ self::$lastResultTable = $searchTable;
118
+
119
+ $collection = $filter->getLayer()->getProductCollection();
120
+ $feature = $filter->getAttributeModel();
121
+ $connection = $this->_getReadAdapter();
122
+
123
+ $collection->getSelect()->join(
124
+ $searchTable,
125
+ "{$searchTable}.entity_id = e.entity_id",
126
+ array()
127
+ );
128
+
129
+ Varien_Profiler::stop(__METHOD__);
130
+ return $this;
131
+ }
132
+
133
+ /**
134
+ * Retrieve array with products counts per attribute option
135
+ *
136
+ * @param Bintime_Icelayered_Model_Layer_Filter_Feature $filter
137
+ * @return array
138
+ */
139
+ public function getCount($filter)
140
+ {
141
+ Varien_Profiler::start(__METHOD__);
142
+
143
+ // clone select from collection with filters
144
+ $select = clone $filter->getLayer()->getProductCollection()->getSelect();
145
+
146
+ // reset columns, order and limitation conditions
147
+ $select->reset(Zend_Db_Select::COLUMNS);
148
+ $select->reset(Zend_Db_Select::ORDER);
149
+ $select->reset(Zend_Db_Select::LIMIT_COUNT);
150
+ $select->reset(Zend_Db_Select::LIMIT_OFFSET);
151
+ $connection = $this->_getReadAdapter();
152
+ $feature = $filter->getAttributeModel();
153
+ $tableAlias = 'idx_' . $feature['category_feature_id'];
154
+
155
+ $conditions = array(
156
+ "{$tableAlias}.entity_id = e.entity_id",
157
+ //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
158
+ );
159
+
160
+ $select->joinInner(
161
+ array($tableAlias => $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id'])),
162
+ join(' AND ', $conditions),
163
+ array('value', 'count' => "COUNT(e.entity_id)")
164
+ )
165
+ ->group("{$tableAlias}.value");
166
+
167
+ $tablePattern = 'stINch_products_feature_'.$feature['category_feature_id'];
168
+ $query = "SHOW TABLES LIKE '$tablePattern'";
169
+ $featureTables = $connection->fetchCol($query);
170
+ $presentFeatures = array();
171
+ foreach($featureTables as $t) {
172
+ if (preg_match("#$tablePattern#", $t, $matches)) {
173
+ $table_feat_exist=true;
174
+ }
175
+ }
176
+
177
+ Varien_Profiler::stop(__METHOD__);
178
+ if($table_feat_exist){
179
+ return $connection->fetchPairs($select);
180
+ }else{
181
+ return null;
182
+ }
183
+
184
+ }
185
+
186
+ public function getIntervalsCount($filter, $interval)
187
+ {
188
+ Varien_Profiler::start(__METHOD__);
189
+
190
+ // clone select from collection with filters
191
+ $select = clone $filter->getLayer()->getProductCollection()->getSelect();
192
+
193
+ // reset columns, order and limitation conditions
194
+ $select->reset(Zend_Db_Select::COLUMNS);
195
+ $select->reset(Zend_Db_Select::ORDER);
196
+ $select->reset(Zend_Db_Select::LIMIT_COUNT);
197
+ $select->reset(Zend_Db_Select::LIMIT_OFFSET);
198
+
199
+ $connection = $this->_getReadAdapter();
200
+ $feature = $filter->getAttributeModel();
201
+ $tableAlias = 'idx_' . $feature['category_feature_id'];
202
+
203
+ $conditions = array(
204
+ "{$tableAlias}.entity_id = e.entity_id",
205
+ //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
206
+ );
207
+
208
+ $select->joinInner(
209
+ array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
210
+ join(' AND ', $conditions),
211
+ array('count' => "COUNT(e.entity_id)")
212
+ );
213
+ if (isset($interval['low'], $interval['high'])) {
214
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
215
+ }
216
+ else if (isset($interval['low'])) {
217
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
218
+ }
219
+ else if (isset($interval['high'])) {
220
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
221
+ }
222
+ $count = $connection->fetchOne($select);
223
+ Varien_Profiler::stop(__METHOD__);
224
+ return $count;
225
+ }
226
+
227
+ function getIntervalsCountDescending($filter, $interval)
228
+ {
229
+ Varien_Profiler::start(__METHOD__);
230
+
231
+ // clone select from collection with filters
232
+ $select = clone $filter->getLayer()->getProductCollection()->getSelect();
233
+
234
+ // reset columns, order and limitation conditions
235
+ $select->reset(Zend_Db_Select::COLUMNS);
236
+ $select->reset(Zend_Db_Select::ORDER);
237
+ $select->reset(Zend_Db_Select::LIMIT_COUNT);
238
+ $select->reset(Zend_Db_Select::LIMIT_OFFSET);
239
+
240
+ $connection = $this->_getReadAdapter();
241
+ $feature = $filter->getAttributeModel();
242
+ $tableAlias = 'idx_' . $feature['category_feature_id'];
243
+
244
+ $conditions = array(
245
+ "{$tableAlias}.entity_id = e.entity_id",
246
+ //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
247
+ );
248
+
249
+ $select->joinInner(
250
+ array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
251
+ join(' AND ', $conditions),
252
+ array('count' => "COUNT(e.entity_id)")
253
+ );
254
+ if (isset($interval['low'], $interval['high'])) {
255
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
256
+ }
257
+ else if (isset($interval['low'])) {
258
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
259
+ }
260
+ else if (isset($interval['high'])) {
261
+ $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
262
+ }
263
+ $count = $connection->fetchOne($select);
264
+
265
+ Varien_Profiler::stop(__METHOD__);
266
+ return $count;
267
+ }
268
+
269
+
270
+
271
+ /*
272
+ * INDEXES FOLLOW.
273
+ */
274
+
275
+ /**
276
+ * Запускает процедуры индексации.
277
+ * Слушает событие Mage::dispatchEvent('iceimport_model_import_after',..)
278
+ * @param <type> $observer
279
+ */
280
+ public function reindex($observer)
281
+ {
282
+ $this->splitProductsFeature();
283
+ }
284
+
285
+
286
+ /**
287
+ * Разбивает таблицу icecat_product_feature на таблицы вида icecat_product_feature_%category_feature_id% для каждой фичи.
288
+ *
289
+ */
290
+ public function splitProductsFeature()
291
+ {
292
+ Mage::log(__METHOD__ . " start at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
293
+ $featureIds = $this->getProductFeatures4indexig();
294
+
295
+ $resource = Mage::getSingleton('core/resource');
296
+ // $tProudctsFeature = $resource->getTableName("icecat_products_feature");
297
+ $connection = $this->_getWriteAdapter();
298
+
299
+ //удаление таблиц с фичами не используемыми больше для навигации.
300
+ $tablePattern = $resource->getTableName('stINch_products_feature_');
301
+ $query = "SHOW TABLES LIKE '%$tablePattern%'";
302
+ $featureTables = $connection->fetchCol($query);
303
+ $presentFeatures = array();
304
+ foreach($featureTables as $t) {
305
+ if (preg_match("#$tablePattern(\d+)#", $t, $matches)) {
306
+ $presentFeatures[] = $matches[1];
307
+ }
308
+ }
309
+
310
+ $features2delete = array_diff($presentFeatures, $featureIds);
311
+ if (count($features2delete)) {
312
+ foreach ($features2delete as & $drop) {
313
+ $drop = $tablePattern . $drop;
314
+ }
315
+ $dropSql = "DROP TABLE " . implode(',', $features2delete);
316
+ $connection->exec($dropSql);
317
+ }
318
+ //
319
+
320
+ //Создание таблиц с фичами используемыми в навигации.
321
+ $i = 0;
322
+ foreach ($featureIds as $featureId) {
323
+ $tFeature = $resource->getTableName("stINch_products_feature_$featureId");
324
+ $query = "DROP TABLE IF EXISTS $tFeature";
325
+ $connection->exec($query);
326
+
327
+ $query = "CREATE TABLE IF NOT EXISTS $tFeature (
328
+ `entity_id` int(11) default NULL,
329
+ `feature_id` int(11) NOT NULL,
330
+ `product_id` int(11) default NULL,
331
+ `category_feature_id` int(11) default NULL,
332
+ `value` text,
333
+ `presentation_value` text,
334
+ INDEX (`feature_id`),
335
+ KEY `category_feature_id` (`category_feature_id`)
336
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8
337
+ ";
338
+ $connection->exec($query);
339
+
340
+ $query = "TRUNCATE TABLE $tFeature";
341
+ $connection->exec($query);
342
+
343
+ /*$query = "
344
+ INSERT INTO $tFeature (feature_id, product_id, category_feature_id, value, presentation_value)
345
+ SELECT feature_id, product_id, category_feature_id, value, presentation_value FROM $tProudctsFeature
346
+ WHERE category_feature_id = $featureId
347
+ ";*/
348
+ $query = "
349
+ REPLACE INTO $tFeature (entity_id,feature_id, product_id, category_feature_id, value, presentation_value)
350
+ SELECT E.entity_id, RV.category_feature_id,E.entity_id, RV.category_feature_id, RV.text , RV.text
351
+ FROM catalog_product_entity E
352
+ INNER JOIN catalog_category_product_index PCind
353
+ ON (E.entity_id = PCind.product_id AND PCind.store_id='1' AND PCind.visibility IN(2,4))
354
+ INNER JOIN catalog_product_index_price AS price_index
355
+ ON price_index.entity_id = E.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
356
+ INNER JOIN stINch_products PR
357
+ ON (PR.store_product_id = E.store_product_id)
358
+ INNER JOIN stINch_product_features PF
359
+ ON (PR.sinch_product_id = PF.sinch_product_id )
360
+ INNER JOIN stINch_restricted_values RV
361
+ ON (PF.restricted_value_id=RV.restricted_value_id AND RV.category_feature_id= $featureId)
362
+ GROUP BY E.entity_id;
363
+ ";
364
+ $connection->exec($query);
365
+ }
366
+ Mage::log(__METHOD__ . " end at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
367
+ }
368
+
369
+ /**
370
+ * Список фич подлежащих индексации.
371
+ *
372
+ * @return array
373
+ */
374
+ private function getProductFeatures4indexig()
375
+ {
376
+ $connection = $this->_getReadAdapter();
377
+
378
+ $tCatFeature = Mage::getSingleton('core/resource')->getTableName('stINch_categories_features');
379
+ $query = "SELECT category_feature_id FROM $tCatFeature ";
380
+
381
+ return $connection->fetchCol($query);
382
+ }
383
+ }
app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Setup.php ADDED
@@ -0,0 +1,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 ADDED
@@ -0,0 +1,3584 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ini_set('memory_limit','256M');
4
+ $dir = 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 $_ignore_category_features = false;
41
+ private $_ignore_product_features = false;
42
+ private $_ignore_product_related = false;
43
+ private $_ignore_restricted_values = false;
44
+ public $php_run_string;
45
+ public $price_breaks_filter;
46
+
47
+ #################################################################################################
48
+
49
+ function __construct(){
50
+
51
+ $this->import_status_table="stINch_import_status";
52
+ $this->import_status_statistic_table="stINch_import_status_statistic";
53
+ $this->import_log_table="stINch_import_log";
54
+
55
+ $this->php_run_string=PHP_RUN_STRING;
56
+ $this->price_breaks_filter=PRICE_BREAKS;
57
+ /* $this->db_connect();
58
+ $res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
59
+ $row = mysql_fetch_assoc($res);
60
+ $this->lang_id = $row['languages_id'];
61
+ */ $this->varDir = TEMPORARY_DIRECTORY_FOR_STORING_FILES;
62
+ $this->shellDir = SHELL_DIRECTORY_FOR_INDEXER;
63
+ $this->connection=$this->db_connect();
64
+ $this->createTemporaryImportDerictory();
65
+ $this->_logFile="Sinch.log";
66
+ $this->_LOG("constructor");
67
+ $this->files=array(
68
+ FILE_CATEGORIES,
69
+ FILE_CATEGORIES_FEATURES,
70
+ FILE_DISTRIBUTORS,
71
+ FILE_EANCODES,
72
+ FILE_MANUFACTURERS,
73
+ FILE_PRODUCT_FEATURES,
74
+ FILE_PRODUCTS,
75
+ FILE_RELATED_PRODUCTS,
76
+ FILE_RESTRICTED_VALUES,
77
+ FILE_STOCK_AND_PRICES,
78
+ FILE_PRODUCTS_PICTURES_GALLERY
79
+ );
80
+ $this->attributes['manufacturer']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
81
+ $this->attributes['name']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
82
+ $this->attributes['is_active']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('is_active')->getFirstItem()->getId();
83
+ $this->attributes['include_in_menu']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('include_in_menu')->getFirstItem()->getId();
84
+ $this->attributes['url_key']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('url_key')->getFirstItem()->getId();
85
+ $this->attributes['display_mode']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('display_mode')->getFirstItem()->getId();
86
+ $this->attributes['status']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('status')->getFirstItem()->getId();
87
+ $this->attributes['visibility']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('visibility')->getFirstItem()->getId();
88
+ $this->attributes['price']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('price')->getFirstItem()->getId();
89
+ $this->attributes['cost']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('cost')->getFirstItem()->getId();
90
+ $this->attributes['weight']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('weight')->getFirstItem()->getId();
91
+ $this->attributes['tax_class_id']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('tax_class_id')->getFirstItem()->getId();
92
+
93
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
94
+ // if($dataConf['field_terminated_char']){
95
+ // $this->field_terminated_char=$dataConf['field_terminated_char'];
96
+ // }else{
97
+ $this->field_terminated_char=DEFAULT_FILE_TERMINATED_CHAR;
98
+ // }
99
+ // $attributeOptions = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getSource()->getAllOptions(false);
100
+ // echo "<pre>"; print_r($attributeOptions); echo "</pre>";
101
+ }
102
+
103
+ #################################################################################################
104
+ function cron_start_import(){
105
+ $this->_LOG("Start import from cron");
106
+ $start_hr=Mage::getStoreConfig('sinchimport_root/sinch_cron/sinch_cron_time');
107
+ $now_hr=date('H');
108
+ $this->_LOG("Now $now_hr hr, scheduler time is $start_hr hr");
109
+
110
+ if($start_hr==$now_hr){
111
+ $this->run_sinch_import();
112
+ }else{
113
+ $this->_LOG(" it's NOT time for SINCH ");
114
+ }
115
+
116
+ $this->_LOG("Finish import from cron");
117
+
118
+ }
119
+ ################################################################################################
120
+ function cron_start_full_import(){
121
+ $this->run_sinch_import();
122
+ }
123
+ ################################################################################################
124
+ function cron_start_stock_price_import(){
125
+ $this->run_stock_price_sinch_import();
126
+ }
127
+ #################################################################################################
128
+ function is_imort_not_run(){
129
+ $q="SELECT IS_FREE_LOCK('sinchimport') as getlock";
130
+ $quer=$this->db_do($q);
131
+ $row=mysql_fetch_array($quer);
132
+ return $row['getlock'];
133
+ }
134
+ #################################################################################################
135
+ function check_store_procedure_exist(){
136
+ $q='show procedure status like "filter_sinch_products_s"';
137
+ $quer=$this->db_do($q);
138
+ $row=mysql_fetch_array($quer);
139
+ if($row['Name']=='filter_sinch_products_s'){
140
+ return true;
141
+ }else{
142
+ return false;
143
+ }
144
+ }
145
+ #################################################################################################
146
+ function check_db_privileges(){
147
+ $q='show privileges';
148
+ $quer=$this->db_do($q);
149
+ while($row=mysql_fetch_array($quer)){
150
+ if($row['Privilege']=='File' && $row['Context']=='File access on server'){
151
+ return true;
152
+ }
153
+ }
154
+ return false;
155
+ }
156
+ #################################################################################################
157
+ function check_local_infile(){
158
+ $q='show variables like "local_infile"';
159
+ $quer=$this->db_do($q);
160
+ $row=mysql_fetch_array($quer);
161
+ if($row['Variable_name']=='local_infile' && $row['Value']=="ON"){
162
+ return true;
163
+ }else{
164
+ return false;
165
+ }
166
+ }
167
+ #################################################################################################
168
+ function is_full_import_have_been_run(){
169
+ $q='select count(*) as cnt from stINch_import_status_statistic where import_type="FULL" and global_status_import="Successful"';
170
+ $quer=$this->db_do($q);
171
+ $row=mysql_fetch_array($quer);
172
+ if($row['cnt']>0){
173
+ return true;
174
+ }else{
175
+ return false;
176
+ }
177
+ }
178
+ #################################################################################################
179
+ function run_sinch_import(){
180
+ $safe_mode_set = ini_get('safe_mode');
181
+
182
+ $this->InitImportStatuses('FULL');
183
+ if($safe_mode_set ){
184
+ $this->_LOG('safe_mode is enable. import stoped.');
185
+ $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
186
+ exit;
187
+ }
188
+ $store_proc=$this->check_store_procedure_exist();
189
+
190
+ if(!$store_proc){
191
+ $this->_LOG('store prcedure "filter_sinch_products_s" is absent. import stoped.');
192
+ $this->set_import_error_reporting_message('Stored procedure "filter_sinch_products_s" is absent. Import stopped.');
193
+ exit;
194
+ }
195
+
196
+ $file_privileg=$this->check_db_privileges();
197
+
198
+ if(!$file_privileg){
199
+ $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
200
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
201
+ exit;
202
+ }
203
+ $local_infile=$this->check_local_infile();
204
+ if(!$local_infile){
205
+ $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'");
206
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
207
+ exit;
208
+ }
209
+
210
+ if($this->is_imort_not_run()){
211
+ try{
212
+ //$this->InitImportStatuses();
213
+ $q="SELECT GET_LOCK('sinchimport', 30)";
214
+ $quer=$this->db_do($q);
215
+ $import=$this;
216
+ $import->addImportStatus('Start Import');
217
+ echo "Upload Files <br>";
218
+ $import->UploadFiles();
219
+ $import->addImportStatus('Upload Files');
220
+
221
+ echo "Parse Categories <br>";
222
+ $import->ParseCategories();
223
+ $import->addImportStatus('Parse Categories');
224
+
225
+ echo "Parse Category Features <br>";
226
+ $import->ParseCategoryFeatures();
227
+ $import->addImportStatus('Parse Category Features');
228
+
229
+ //$import->ActivateCategories();
230
+ echo "Parse Distributors <br>";
231
+ $import->ParseDistributors();
232
+ $import->addImportStatus('Parse Distributors');
233
+
234
+ echo "Parse EAN Codes <br>";
235
+ $import->ParseEANCodes();
236
+ $import->addImportStatus('Parse EAN Codes');
237
+
238
+ echo "Parse Manufacturers <br>";
239
+ $import->ParseManufacturers();
240
+ $import->addImportStatus('Parse Manufacturers');
241
+
242
+ echo "Parse Related Products <br>";
243
+ $import->ParseRelatedProducts();
244
+ $import->addImportStatus('Parse Related Products');
245
+
246
+ echo "Parse Product Features <br>";
247
+ $import->ParseProductFeatures();
248
+ $import->addImportStatus('Parse Product Features');
249
+
250
+ echo "Parse Products <br>";
251
+ $import->ParseProducts();
252
+ $import->addImportStatus('Parse Products');
253
+
254
+ echo "Parse Pictures Gallery";
255
+ $import->ParseProductsPicturesGallery();
256
+ $import->addImportStatus('Parse Pictures Gallery');
257
+
258
+ echo "Parse Restricted Values <br>";
259
+ $import->ParseRestrictedValues();
260
+ $import->addImportStatus('Parse Restricted Values');
261
+
262
+ echo "Parse Stock And Prices <br>";
263
+ $import->ParseStockAndPrices();
264
+ $import->addImportStatus('Parse Stock And Prices');
265
+
266
+
267
+ Mage::log("Finish Sinch import", null, $this->_logFile);
268
+ echo "Finish Sinch import<br>";
269
+
270
+ Mage::log("Start cleanin Sinch cache<br>", null, $this->_logFile);
271
+ echo "Start cleanin Sinch cache<br>";
272
+ Mage::app()->getCacheInstance()->cleanType('block_html');
273
+ /*
274
+ $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
275
+ if ($indexProcess) {
276
+ $indexProcess->reindexAll();
277
+ }
278
+ }
279
+ */
280
+
281
+ Mage::log("Start indexing Sinch features for filters", null, $this->_logFile);
282
+ echo "Start indexing Sinch features for filters<br>";
283
+
284
+
285
+ $resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
286
+ $resource->splitProductsFeature(null);
287
+
288
+ Mage::log("Finish indexing Sinch features for filters", null, $this->_logFile);
289
+ $import->addImportStatus('Generate category filters');
290
+ echo "Finish indexing Sinch features for filters<br>";
291
+
292
+ Mage::log("Start indexing data", null, $this->_logFile);
293
+ echo "Start indexing data";
294
+ $import->runIndexer();
295
+ Mage::log("Finish indexing data", null, $this->_logFile);
296
+ $import->addImportStatus('Indexing data', 1);
297
+ echo "Finish indexing data";
298
+
299
+ $q="SELECT RELEASE_LOCK('sinchimport')";
300
+ $quer=$this->db_do($q);
301
+ }catch (Exception $e) {
302
+ $this->set_import_error_reporting_message($e);
303
+ }
304
+ }
305
+ else{
306
+ Mage::log("Sinchimport already run", null, $this->_logFile);
307
+ echo "Sinchimport already run<br>";
308
+
309
+ }
310
+
311
+ }
312
+ #################################################################################################
313
+ function run_stock_price_sinch_import(){
314
+ $safe_mode_set = ini_get('safe_mode');
315
+
316
+ $this->InitImportStatuses('PRICE STOCK');
317
+ if($safe_mode_set ){
318
+ $this->_LOG('safe_mode is enable. import stoped.');
319
+ $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
320
+ exit;
321
+ }
322
+ $store_proc=$this->check_store_procedure_exist();
323
+
324
+ if(!$store_proc){
325
+ $this->_LOG('store prcedure "filter_sinch_products_s" is absent. import stoped.');
326
+ $this->set_import_error_reporting_message('Stored procedure "filter_sinch_products_s" is absent. Import stopped.');
327
+ exit;
328
+ }
329
+
330
+ $file_privileg=$this->check_db_privileges();
331
+
332
+ if(!$file_privileg){
333
+ $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
334
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
335
+ exit;
336
+ }
337
+ $local_infile=$this->check_local_infile();
338
+ if(!$local_infile){
339
+ $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'");
340
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
341
+ exit;
342
+ }
343
+
344
+ if($this->is_imort_not_run() && $this->is_full_import_have_been_run()){
345
+ try{
346
+ //$this->InitImportStatuses();
347
+ $q="SELECT GET_LOCK('sinchimport', 30)";
348
+ $quer=$this->db_do($q);
349
+ $import=$this;
350
+ $import->addImportStatus('Stock Price Start Import');
351
+ echo "Upload Files <br>";
352
+ $this->files=array(
353
+ FILE_STOCK_AND_PRICES
354
+ );
355
+
356
+ $import->UploadFiles();
357
+ $import->addImportStatus('Stock Price Upload Files');
358
+
359
+ echo "Parse Stock And Prices <br>";
360
+ //exit;
361
+ $import->ParseStockAndPrices();
362
+ $import->addImportStatus('Stock Price Parse Products');
363
+
364
+
365
+ Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
366
+ echo "Finish Stock & Price Sinch import<br>";
367
+
368
+ Mage::log("Start indexing Stock & Price", null, $this->_logFile);
369
+ echo "Start indexing Stock & Price<br>";
370
+ $import->runStockPriceIndexer();
371
+ Mage::log("Finish indexing Stock & Price", null, $this->_logFile);
372
+ $import->addImportStatus('Stock Price Indexing data');
373
+ $import->addImportStatus('Stock Price Finish import', 1);
374
+ echo "Finish indexing Stock & Price<br>";
375
+
376
+ $q="SELECT RELEASE_LOCK('sinchimport')";
377
+ $quer=$this->db_do($q);
378
+ }catch (Exception $e) {
379
+ $this->set_import_error_reporting_message($e);
380
+ }
381
+ }
382
+ else{
383
+ if(!$this->is_imort_not_run()){
384
+ Mage::log("Sinchimport already run", null, $this->_logFile);
385
+ echo "Sinchimport already run<br>";
386
+ }else{
387
+ Mage::log("Full import have never finished with success", null, $this->_logFile);
388
+ echo "Full import have never finished with success<br>";
389
+ }
390
+ }
391
+
392
+ }
393
+ #################################################################################################
394
+
395
+
396
+ function UploadFiles(){
397
+
398
+ $this->_LOG("Start upload files");
399
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
400
+ $login=$dataConf['login'];
401
+ $passw=$dataConf['password'];
402
+ //return;//stepan tes//stepan tes//stepan testtt
403
+ if(!$login || !$passw){
404
+ $this->_LOG('ftp login or password dosent defined');
405
+ $this->set_import_error_reporting_message('FTP login or password has not been defined. Import stopped.');
406
+ exit;
407
+
408
+ }
409
+ $file_url_and_dir=$this->repl_ph(FILE_URL_AND_DIR, array('login' => $login,
410
+ 'password'=> $passw
411
+ )
412
+ );
413
+ foreach ($this->files as $file) {
414
+ $this->_LOG("Copy ".$file_url_and_dir.$file." to ".$this->varDir.$file);
415
+ if(strstr($file_url_and_dir, 'ftp://')){
416
+ preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
417
+ //var_dump($match);
418
+ if($conn = ftp_connect($match[3])){
419
+ if(!ftp_login($conn, $login, $passw))
420
+ {
421
+ $this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
422
+ exit;
423
+ }
424
+ }
425
+ else{
426
+ $this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
427
+ exit;
428
+ }
429
+ if (!$this->wget ($file_url_and_dir.$file, $this->varDir.$file, 'system')){
430
+ $this->_LOG("wget Can't copy ".$file.", will use old one");
431
+ echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file.", will use old one<br>";
432
+ }
433
+ }
434
+ else{
435
+ if(!copy($file_url_and_dir.$file, $this->varDir.$file)){
436
+ $this->_LOG("copy Can't copy ".$file.", will use old one");
437
+ echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file." will use old one<br>";
438
+ }
439
+ }
440
+ exec("chmod a+rw ".$this->varDir.$file);
441
+ if(!filesize($this->varDir.$file)){
442
+ if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES){
443
+ $this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
444
+ $this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
445
+ $this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
446
+
447
+ exit;
448
+ }else{
449
+ if($file==FILE_CATEGORIES_FEATURES){
450
+ $this->_LOG("Can't copy ".FILE_CATEGORIES_FEATURES." file ignored" );
451
+ $this->_ignore_category_features=true;
452
+ }elseif($file==FILE_PRODUCT_FEATURES){
453
+ $this->_LOG("Can't copy ".FILE_PRODUCT_FEATURES." file ignored" );
454
+ $this->_ignore_product_features=true;
455
+ }elseif($file==FILE_RELATED_PRODUCTS){
456
+ $this->_LOG("Can't copy ".FILE_RELATED_PRODUCTS." file ignored" );
457
+ $this->_ignore_product_related=true;
458
+ }elseif($file==FILE_RESTRICTED_VALUES){
459
+ $this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
460
+ $this->_ignore_restricted_values=true;
461
+ }
462
+ }
463
+ }
464
+ }
465
+
466
+ $this->_LOG("Finish upload files");
467
+ }
468
+
469
+ #################################################################################################
470
+
471
+ function ParseCategories(){
472
+
473
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
474
+ $im_type = $dataConf['replace_category'];
475
+ $parse_file=$this->varDir.FILE_CATEGORIES;
476
+ if(filesize($parse_file)){
477
+ $this->_LOG("Start parse ".FILE_CATEGORIES);
478
+ $this->_getCategoryEntityTypeIdAndDefault_attribute_set_id();
479
+ $this->db_do("DROP TABLE IF EXISTS categories_temp");
480
+ $this->db_do("CREATE TABLE categories_temp(
481
+ store_category_id int(11),
482
+ parent_store_category_id int(11),
483
+ category_name varchar(50),
484
+ order_number int(11),
485
+ is_hidden boolean,
486
+ products_within_this_category int(11),
487
+ products_within_sub_categories int(11),
488
+ categories_image varchar(255),
489
+ children_count int(11) NOT NULL default 0,
490
+ level int(10) NOT NULL default 0,
491
+ key(store_category_id),
492
+ key(parent_store_category_id)
493
+ )");
494
+
495
+ $res=$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE categories_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
496
+ $inf=mysql_info();
497
+ $table ="categories_temp";
498
+ if(!$this->check_loaded_data($parse_file, $table)){
499
+ $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.")");
500
+ exit;
501
+ }
502
+ if($im_type=="REWRITE"){
503
+ $root_cat=2;
504
+ $this->db_do('SET foreign_key_checks=0');
505
+ $this->db_do("TRUNCATE ".TABLE_CATEGORY_ENTITY);
506
+ $this->db_do("INSERT INTO `catalog_category_entity` VALUES (1,".$this->_categoryEntityTypeId.",".$this->_categoryDefault_attribute_set_id.",0,'0000-00-00 00:00:00',now(),'1',0,0,1,null,null),(2,".$this->_categoryEntityTypeId.",".$this->_categoryDefault_attribute_set_id.",1,now(),now(),'1/2',1,1,0,null,null)");
507
+ $this->db_do("TRUNCATE ".TABLE_CATEGORY_ENTITY_VARCHAR);
508
+ $this->db_do("INSERT INTO `catalog_category_entity_varchar` VALUES (1,".$this->_categoryEntityTypeId.",".$this->_getCategoryAttributeId('name').",0,1,'Root Catalog'),(2,".$this->_categoryEntityTypeId.",".$this->_getCategoryAttributeId('name').",1,1,'Root Catalog'),(3,".$this->_categoryEntityTypeId.",".$this->attributes['url_key'].",0,1,'root-catalog'),(4,".$this->_categoryEntityTypeId.",".$this->_getCategoryAttributeId('name').",0,2,'Default Category'),(5,".$this->_categoryEntityTypeId.",".$this->_getCategoryAttributeId('name').",1,2,'Default Category'),(6,".$this->_categoryEntityTypeId.",".$this->attributes['display_mode'].",1,2,'PRODUCTS'),(7,".$this->_categoryEntityTypeId.",".$this->attributes['url_key'].",0,2,'default-category')");
509
+ $this->db_do("TRUNCATE ".TABLE_CATEGORY_ENTITY_INT);
510
+ $this->db_do("INSERT INTO `catalog_category_entity_int` VALUES (1,".$this->_categoryEntityTypeId.",".$this->attributes['is_active'].",0,2,1),(2,".$this->_categoryEntityTypeId.",".$this->attributes['is_active'].",1,2,1),(3,".$this->_categoryEntityTypeId.",".$this->attributes['include_in_menu'].",0,1,1),(4,".$this->_categoryEntityTypeId.",".$this->attributes['include_in_menu'].",0,2,1)");
511
+
512
+ }else{
513
+ $root_cat=$this->_getShopRootCategoryId();
514
+ }
515
+ $this->_root_cat=$root_cat;
516
+ $q="update ".TABLE_SINCH_CAT." set parent_store_category_id='".$root_cat."' where parent_store_category_id=0";
517
+ $this->db_do($q);
518
+
519
+ $q="select store_category_id from ".TABLE_SINCH_CAT;
520
+ $quer=$this->db_do($q);
521
+ while($row=mysql_fetch_array($quer)){
522
+ $this->db_do("update ".TABLE_SINCH_CAT." set children_count=".$this->count_children($row['store_category_id']).", level=".$this->get_category_level($row['store_category_id'])." where store_category_id=".$row['store_category_id']);
523
+ }
524
+ $this->mapSinchCategories();
525
+ if(UPDATE_CATEGORY_DATA){
526
+ echo "Update category_entity \n";
527
+ $q="insert into ".TABLE_CATEGORY_ENTITY." (
528
+ entity_type_id,
529
+ attribute_set_id,
530
+ created_at,
531
+ updated_at,
532
+ level,
533
+ children_count,
534
+ entity_id,
535
+ position,
536
+ parent_id,
537
+ store_category_id,
538
+ parent_store_category_id
539
+ )(select
540
+ ".$this->_categoryEntityTypeId.",
541
+ ".$this->_categoryDefault_attribute_set_id.",
542
+ now(),
543
+ now(),
544
+ c.level,
545
+ c.children_count,
546
+ scm.shop_entity_id,
547
+ c.order_number,
548
+ scm.shop_parent_id,
549
+ c.store_category_id,
550
+ c.parent_store_category_id
551
+ from categories_temp c left join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id )
552
+ ON DUPLICATE KEY UPDATE
553
+ updated_at=now(),
554
+ store_category_id=c.store_category_id,
555
+ level=c.level,
556
+ children_count=c.children_count,
557
+ position=c.order_number,
558
+ parent_store_category_id=c.parent_store_category_id
559
+
560
+
561
+ ";
562
+ //level=c.level,
563
+ //children_count=c.children_count
564
+ //position=c.order_number,
565
+
566
+ }else{
567
+ echo "Insert ignore category_entity \n";
568
+ $q="insert ignore into ".TABLE_CATEGORY_ENTITY." (
569
+ entity_type_id,
570
+ attribute_set_id,
571
+ created_at,
572
+ updated_at,
573
+ level,
574
+ children_count,
575
+ entity_id,
576
+ position,
577
+ parent_id,
578
+ store_category_id,
579
+ parent_store_category_id
580
+ )(select
581
+ ".$this->_categoryEntityTypeId.",
582
+ ".$this->_categoryDefault_attribute_set_id.",
583
+ now(),
584
+ now(),
585
+ c.level,
586
+ c.children_count,
587
+ scm.shop_entity_id,
588
+ c.order_number,
589
+ scm.shop_parent_id,
590
+ c.store_category_id,
591
+ c.parent_store_category_id
592
+ from categories_temp c left join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id )
593
+ ";
594
+ }
595
+ $this->db_do($q);
596
+
597
+ $this->mapSinchCategories();
598
+
599
+
600
+
601
+ $q="select entity_id, parent_id from ".TABLE_CATEGORY_ENTITY." order by parent_id";
602
+ $quer=$this->db_do($q);
603
+ while($row=mysql_fetch_array($quer)){
604
+ $this->db_do("update ".TABLE_CATEGORY_ENTITY." set path='".$this->culc_path($row['parent_id'], $row['entity_id'])."' where entity_id=".$row['entity_id']);
605
+ }
606
+
607
+ if(UPDATE_CATEGORY_DATA){
608
+
609
+ echo "Update category_data \n";
610
+ $q="insert into ".TABLE_CATEGORY_ENTITY_VARCHAR." (
611
+ entity_type_id,
612
+ attribute_id,
613
+ store_id,
614
+ entity_id,
615
+ value
616
+ )(select
617
+ ".$this->_categoryEntityTypeId.",
618
+ ".$this->_getCategoryAttributeId('name').",
619
+ 0,
620
+ scm.shop_entity_id,
621
+ c.category_name
622
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
623
+ ON DUPLICATE KEY UPDATE
624
+ value=c.category_name
625
+
626
+ ";
627
+ $this->db_do($q);
628
+
629
+ $q="insert into ".TABLE_CATEGORY_ENTITY_VARCHAR." (
630
+ entity_type_id,
631
+ attribute_id,
632
+ store_id,
633
+ entity_id,
634
+ value
635
+ )(select
636
+ ".$this->_categoryEntityTypeId.",
637
+ ".$this->_getCategoryAttributeId('name').",
638
+ 1,
639
+ scm.shop_entity_id,
640
+ c.category_name
641
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
642
+ ON DUPLICATE KEY UPDATE
643
+ value=c.category_name
644
+ ";
645
+ $this->db_do($q);
646
+
647
+ $q="insert into ".TABLE_CATEGORY_ENTITY_INT." (
648
+ entity_type_id,
649
+ attribute_id,
650
+ store_id,
651
+ entity_id,
652
+ value
653
+ )(select
654
+ ".$this->_categoryEntityTypeId.",
655
+ ".$this->attributes['is_active'].",
656
+ 0,
657
+ scm.shop_entity_id,
658
+ 1
659
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
660
+ ON DUPLICATE KEY UPDATE
661
+ value=1
662
+ ";
663
+ $this->db_do($q);
664
+
665
+ $q="insert into ".TABLE_CATEGORY_ENTITY_INT." (
666
+ entity_type_id,
667
+ attribute_id,
668
+ store_id,
669
+ entity_id,
670
+ value
671
+ )(select
672
+ ".$this->_categoryEntityTypeId.",
673
+ ".$this->attributes['is_active'].",
674
+ 1,
675
+ scm.shop_entity_id,
676
+ 1
677
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
678
+ ON DUPLICATE KEY UPDATE
679
+ value=1
680
+ ";
681
+ $this->db_do($q);
682
+
683
+ $q="insert into ".TABLE_CATEGORY_ENTITY_INT." (
684
+ entity_type_id,
685
+ attribute_id,
686
+ store_id,
687
+ entity_id,
688
+ value
689
+ )(select
690
+ ".$this->_categoryEntityTypeId.",
691
+ ".$this->attributes['include_in_menu'].",
692
+ 0,
693
+ scm.shop_entity_id,
694
+ 1
695
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
696
+ ON DUPLICATE KEY UPDATE
697
+ value=1
698
+ ";
699
+ $this->db_do($q);
700
+
701
+ $q="insert into ".TABLE_CATEGORY_ENTITY_INT." (
702
+ entity_type_id,
703
+ attribute_id,
704
+ store_id,
705
+ entity_id,
706
+ value
707
+ )(select
708
+ ".$this->_categoryEntityTypeId.",
709
+ ".$this->_getCategoryAttributeId('is_anchor').",
710
+ 1,
711
+ scm.shop_entity_id,
712
+ 1
713
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
714
+ ON DUPLICATE KEY UPDATE
715
+ value=1
716
+ ";
717
+ $this->db_do($q);
718
+
719
+ $q="insert into ".TABLE_CATEGORY_ENTITY_INT." (
720
+ entity_type_id,
721
+ attribute_id,
722
+ store_id,
723
+ entity_id,
724
+ value
725
+ )(select
726
+ ".$this->_categoryEntityTypeId.",
727
+ ".$this->_getCategoryAttributeId('is_anchor').",
728
+ 0,
729
+ scm.shop_entity_id,
730
+ 1
731
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
732
+ ON DUPLICATE KEY UPDATE
733
+ value=1
734
+ ";
735
+ $this->db_do($q);
736
+
737
+ $q="insert into ".TABLE_CATEGORY_ENTITY_VARCHAR." (
738
+ entity_type_id,
739
+ attribute_id,
740
+ store_id,
741
+ entity_id,
742
+ value
743
+ )(select
744
+ ".$this->_categoryEntityTypeId.",
745
+ ".$this->_getCategoryAttributeId('image').",
746
+ 0,
747
+ scm.shop_entity_id,
748
+ c.categories_image
749
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
750
+ ON DUPLICATE KEY UPDATE
751
+ value=c.categories_image
752
+ ";
753
+ $this->db_do($q);
754
+ }else{
755
+ echo "Insert ignore category_data \n";
756
+ $q="insert IGNORE into ".TABLE_CATEGORY_ENTITY_VARCHAR." (
757
+ entity_type_id,
758
+ attribute_id,
759
+ store_id,
760
+ entity_id,
761
+ value
762
+ )(select
763
+ ".$this->_categoryEntityTypeId.",
764
+ ".$this->_getCategoryAttributeId('name').",
765
+ 0,
766
+ scm.shop_entity_id,
767
+ c.category_name
768
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
769
+
770
+ ";
771
+ $this->db_do($q);
772
+
773
+ /* $q="insert IGNORE into ".TABLE_CATEGORY_ENTITY_VARCHAR." (
774
+ entity_type_id,
775
+ attribute_id,
776
+ store_id,
777
+ entity_id,
778
+ value
779
+ )(select
780
+ ".$this->_categoryEntityTypeId.",
781
+ ".$this->_getCategoryAttributeId('name').",
782
+ 1,
783
+ scm.shop_entity_id,
784
+ c.category_name
785
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
786
+ ";
787
+ $this->db_do($q);
788
+ */
789
+ $q="insert IGNORE into ".TABLE_CATEGORY_ENTITY_INT." (
790
+ entity_type_id,
791
+ attribute_id,
792
+ store_id,
793
+ entity_id,
794
+ value
795
+ )(select
796
+ ".$this->_categoryEntityTypeId.",
797
+ ".$this->attributes['is_active'].",
798
+ 0,
799
+ scm.shop_entity_id,
800
+ 1
801
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
802
+ ";
803
+ $this->db_do($q);
804
+ /*
805
+ $q="insert IGNORE into ".TABLE_CATEGORY_ENTITY_INT." (
806
+ entity_type_id,
807
+ attribute_id,
808
+ store_id,
809
+ entity_id,
810
+ value
811
+ )(select
812
+ ".$this->_categoryEntityTypeId.",
813
+ ".$this->attributes['is_active'].",
814
+ 1,
815
+ scm.shop_entity_id,
816
+ 1
817
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
818
+ ";
819
+ $this->db_do($q);
820
+ */
821
+ $q="insert IGNORE into ".TABLE_CATEGORY_ENTITY_INT." (
822
+ entity_type_id,
823
+ attribute_id,
824
+ store_id,
825
+ entity_id,
826
+ value
827
+ )(select
828
+ ".$this->_categoryEntityTypeId.",
829
+ ".$this->attributes['include_in_menu'].",
830
+ 0,
831
+ scm.shop_entity_id,
832
+ 1
833
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
834
+ ";
835
+ $this->db_do($q);
836
+ /*
837
+ $q="insert IGNORE into ".TABLE_CATEGORY_ENTITY_INT." (
838
+ entity_type_id,
839
+ attribute_id,
840
+ store_id,
841
+ entity_id,
842
+ value
843
+ )(select
844
+ ".$this->_categoryEntityTypeId.",
845
+ ".$this->_getCategoryAttributeId('is_anchor').",
846
+ 1,
847
+ scm.shop_entity_id,
848
+ 1
849
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
850
+ ";
851
+ $this->db_do($q);
852
+ */
853
+ $q="insert IGNORE into ".TABLE_CATEGORY_ENTITY_INT." (
854
+ entity_type_id,
855
+ attribute_id,
856
+ store_id,
857
+ entity_id,
858
+ value
859
+ )(select
860
+ ".$this->_categoryEntityTypeId.",
861
+ ".$this->_getCategoryAttributeId('is_anchor').",
862
+ 0,
863
+ scm.shop_entity_id,
864
+ 1
865
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
866
+ ";
867
+ $this->db_do($q);
868
+
869
+ $q="insert IGNORE into ".TABLE_CATEGORY_ENTITY_VARCHAR." (
870
+ entity_type_id,
871
+ attribute_id,
872
+ store_id,
873
+ entity_id,
874
+ value
875
+ )(select
876
+ ".$this->_categoryEntityTypeId.",
877
+ ".$this->_getCategoryAttributeId('image').",
878
+ 0,
879
+ scm.shop_entity_id,
880
+ c.categories_image
881
+ from ".TABLE_SINCH_CAT." c join stINch_categories_mapping scm on c.store_category_id=scm.store_category_id)
882
+ ";
883
+ $this->db_do($q);
884
+
885
+ }
886
+ $this->delete_old_sinch_categories_from_shop();
887
+
888
+ $this->db_do("DROP TABLE IF EXISTS stINch_categories");
889
+ $this->db_do("RENAME TABLE categories_temp TO stINch_categories");
890
+ $this->_LOG("Finish parse ".FILE_CATEGORIES);
891
+ }else{
892
+ $this->_LOG("Wrong file ".$parse_file);
893
+ }
894
+ $this->_LOG(' ');
895
+ }
896
+
897
+ #################################################################################################
898
+
899
+ function ParseCategoryFeatures(){
900
+
901
+ $parse_file=$this->varDir.FILE_CATEGORIES_FEATURES;
902
+ if(filesize($parse_file) || $this->_ignore_category_features){
903
+ $this->_LOG("Start parse ".FILE_CATEGORIES_FEATURES);
904
+ $this->db_do("DROP TABLE IF EXISTS categories_features_temp");
905
+ $this->db_do("CREATE TABLE categories_features_temp(
906
+ category_feature_id int(11),
907
+ store_category_id int(11),
908
+ feature_name varchar(50),
909
+ display_order_number int(11),
910
+ key(store_category_id),
911
+ key(category_feature_id)
912
+ )");
913
+
914
+ if(!$this->_ignore_category_features){
915
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE categories_features_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
916
+ }
917
+ $this->db_do("DROP TABLE IF EXISTS stINch_categories_features");
918
+ $this->db_do("RENAME TABLE categories_features_temp TO stINch_categories_features");
919
+
920
+ $this->_LOG("Finish parse ".FILE_CATEGORIES_FEATURES);
921
+ }else{
922
+ $this->_LOG("Wrong file ".$parse_file);
923
+ }
924
+ $this->_LOG(' ');
925
+ }
926
+
927
+ ################################################################################################ 20.07.2010 Yan
928
+
929
+ function ActivateCategories() {
930
+ $this->db_do("UPDATE categories a LEFT JOIN products_to_categories b ON a.categories_id = b.categories_id SET categories_status = 1 WHERE b.products_id IS NOT NULL");
931
+ $result = $this->db_do("SELECT parent_id FROM categories WHERE categories_status = 1");
932
+ while ($row = mysql_fetch_assoc($result)) {
933
+ $this->db_do("UPDATE categories SET categories_status = 1 WHERE categories_id = ".$row['parent_id']);
934
+ }
935
+ }
936
+
937
+ #################################################################################################
938
+
939
+ function ParseDistributors(){
940
+
941
+ $parse_file=$this->varDir.FILE_DISTRIBUTORS;
942
+ if(filesize($parse_file)){
943
+ $this->_LOG("Start parse ".FILE_DISTRIBUTORS);
944
+ $this->db_do("DROP TABLE IF EXISTS distributors_temp");
945
+ $this->db_do("CREATE TABLE distributors_temp(
946
+ distributor_id int(11),
947
+ distributor_name varchar(255),
948
+ website varchar(255),
949
+ key(distributor_id)
950
+ )");
951
+
952
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE distributors_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
953
+
954
+ $this->db_do("DROP TABLE IF EXISTS stINch_distributors");
955
+ $this->db_do("RENAME TABLE distributors_temp TO stINch_distributors");
956
+
957
+ $this->_LOG("Finish parse ".FILE_DISTRIBUTORS);
958
+ }else{
959
+ $this->_LOG("Wrong file ".$parse_file);
960
+ }
961
+ $this->_LOG(' ');
962
+ }
963
+
964
+ #################################################################################################
965
+
966
+ function ParseEANCodes(){
967
+
968
+ $parse_file=$this->varDir.FILE_EANCODES;
969
+ if(filesize($parse_file)){
970
+ $this->_LOG("Start parse ".FILE_EANCODES);
971
+
972
+ $this->db_do("DROP TABLE IF EXISTS ean_codes_temp");
973
+ $this->db_do("CREATE TABLE ean_codes_temp(
974
+ product_id int(11),
975
+ ean_code varchar(255),
976
+ key(product_id)
977
+ )");
978
+
979
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE ean_codes_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
980
+
981
+ $this->db_do("DROP TABLE IF EXISTS stINch_ean_codes");
982
+ $this->db_do("RENAME TABLE ean_codes_temp TO stINch_ean_codes");
983
+
984
+ $this->_LOG("Finish parse ".FILE_EANCODES);
985
+ }else{
986
+ $this->_LOG("Wrong file ".$parse_file);
987
+ }
988
+ $this->_LOG(' ');
989
+ }
990
+
991
+ #################################################################################################
992
+
993
+ function ParseManufacturers(){
994
+
995
+ $parse_file=$this->varDir.FILE_MANUFACTURERS;
996
+ if(filesize($parse_file)){
997
+ $this->_LOG("Start parse ".FILE_MANUFACTURERS);
998
+ $this->db_do("DROP TABLE IF EXISTS ".TABLE_SINCH_MANUF);
999
+ $this->db_do("CREATE TABLE ".TABLE_SINCH_MANUF."(
1000
+ sinch_manufacturer_id int(11),
1001
+ manufacturer_name varchar(255),
1002
+ manufacturers_image varchar(255),
1003
+ shop_option_id int(11),
1004
+ key(sinch_manufacturer_id),
1005
+ key(shop_option_id),
1006
+ key(manufacturer_name)
1007
+ )");
1008
+
1009
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE ".TABLE_SINCH_MANUF." FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
1010
+
1011
+ /* $this->db_do("update manufacturers m join manufacturers_temp mt on m.manufacturers_id=mt.sinch_manufacturer_id set mt.manufacturers_image=m.manufacturers_image");
1012
+
1013
+ $this->db_do("TRUNCATE manufacturers");
1014
+ $this->db_do("insert ignore into manufacturers (manufacturers_id, manufacturers_name, manufacturers_image)(select sinch_manufacturer_id, manufacturer_name, manufacturers_image from manufacturers_temp)");
1015
+
1016
+ v*/
1017
+ $q="delete aov from ".TABLE_ATTRIBUTE_OPT." ao join ".TABLE_ATTRIBUTE_OPT_VALUE." aov on ao.option_id=aov.option_id left join ".TABLE_SINCH_MANUF." mt on aov.value=mt.manufacturer_name where ao.attribute_id=".$this->attributes['manufacturer']." and mt.manufacturer_name is null";
1018
+ $this->db_do($q);
1019
+
1020
+ $q="delete ao from ".TABLE_ATTRIBUTE_OPT." ao left join ".TABLE_ATTRIBUTE_OPT_VALUE." aov on ao.option_id=aov.option_id where attribute_id=".$this->attributes['manufacturer']." and aov.option_id is null";
1021
+ $this->db_do($q);
1022
+
1023
+ $q="select m.sinch_manufacturer_id, m.manufacturer_name, m.manufacturers_image from ".TABLE_SINCH_MANUF." m left join ".TABLE_ATTRIBUTE_OPT_VALUE." aov on m.manufacturer_name=aov.value where aov.value is null";
1024
+ $quer=$this->db_do($q);
1025
+
1026
+ while($row=mysql_fetch_array($quer)){
1027
+ $q0="insert into ".TABLE_ATTRIBUTE_OPT." (attribute_id) values(".$this->attributes['manufacturer'].")";
1028
+ $quer0=$this->db_do($q0);
1029
+
1030
+ $q2="insert into ".TABLE_ATTRIBUTE_OPT_VALUE." (option_id, value) (select max(option_id) as option_id, "."'".mysql_real_escape_string($row['manufacturer_name'])."' from ".TABLE_ATTRIBUTE_OPT." where attribute_id=".$this->attributes['manufacturer'].") ";
1031
+ $quer2=$this->db_do($q2);
1032
+ // $option['attribute_id'] = $this->attributes['manufacturer'];
1033
+ // $option['value'][$row['sinch_manufacturer_id']][0] = $row['manufacturer_name'];
1034
+
1035
+ }
1036
+
1037
+ $q="update manufacturers_temp mt join ".TABLE_ATTRIBUTE_OPT_VALUE." aov on mt.manufacturer_name=aov.value join ".TABLE_ATTRIBUTE_OPT." ao on ao.option_id=aov.option_id set mt.shop_option_id=aov.option_id where ao.attribute_id=".$this->attributes['manufacturer'];
1038
+ $this->db_do($q);
1039
+
1040
+ $this->db_do("DROP TABLE IF EXISTS stINch_manufacturers");
1041
+ $this->db_do("RENAME TABLE manufacturers_temp TO stINch_manufacturers");
1042
+ $this->_LOG("Finish parse ".FILE_MANUFACTURERS);
1043
+ }else{
1044
+ $this->_LOG("Wrong file ".$parse_file);
1045
+ }
1046
+ $this->_LOG(' ');
1047
+ }
1048
+
1049
+ #################################################################################################
1050
+
1051
+ function ParseProductFeatures(){
1052
+
1053
+ $parse_file=$this->varDir.FILE_PRODUCT_FEATURES;
1054
+ if(filesize($parse_file) || $this->_ignore_product_features){
1055
+ $this->_LOG("Start parse ".FILE_PRODUCT_FEATURES);
1056
+
1057
+ $this->db_do("DROP TABLE IF EXISTS product_features_temp");
1058
+ $this->db_do("CREATE TABLE product_features_temp(
1059
+ product_feature_id int(11),
1060
+ sinch_product_id int(11),
1061
+ restricted_value_id int(11),
1062
+ key(sinch_product_id),
1063
+ key(restricted_value_id)
1064
+ )");
1065
+ if(!$this->_ignore_product_features){
1066
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE product_features_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
1067
+ }
1068
+ $this->db_do("DROP TABLE IF EXISTS stINch_product_features");
1069
+ $this->db_do("RENAME TABLE product_features_temp TO stINch_product_features");
1070
+
1071
+ $this->_LOG("Finish parse ".FILE_PRODUCT_FEATURES);
1072
+ }else{
1073
+ $this->_LOG("Wrong file ".$parse_file);
1074
+ }
1075
+ $this->_LOG(" ");
1076
+ }
1077
+
1078
+ #################################################################################################
1079
+
1080
+ function ParseProducts(){
1081
+
1082
+ $parse_file=$this->varDir.FILE_PRODUCTS;
1083
+ if(filesize($parse_file)){
1084
+ $this->_LOG("Start parse ".FILE_PRODUCTS);
1085
+
1086
+ $file_handle_from = fopen($parse_file, "r");
1087
+ unlink($parse_file.".conv");
1088
+ $file_handle_to = fopen($parse_file.".conv", "w");
1089
+ while (!feof($file_handle_from)) {
1090
+ $line = fgets($file_handle_from);
1091
+ $line = $this->valid_utf($line);
1092
+ fwrite($file_handle_to, $line);
1093
+ }
1094
+ fclose($file_handle_from);
1095
+ fclose($file_handle_to);
1096
+
1097
+
1098
+ // $prod_file_str = file_get_contents($parse_file);
1099
+ $this->db_do("DROP TABLE IF EXISTS products_temp");
1100
+ $this->db_do("CREATE TABLE products_temp(
1101
+ store_category_product_id int(11),
1102
+ store_product_id int(11),
1103
+ sinch_product_id int(11),
1104
+ product_sku varchar(255),
1105
+ product_name varchar(255),
1106
+ sinch_manufacturer_id int(11),
1107
+ store_category_id int(11),
1108
+ main_image_url varchar(255),
1109
+ thumb_image_url varchar(255),
1110
+ specifications text,
1111
+ description text,
1112
+ search_cache text,
1113
+ spec_characte_u_count int(11),
1114
+ description_type varchar(50),
1115
+ medium_image_url varchar(255),
1116
+ products_date_added datetime default NULL,
1117
+ products_last_modified datetime default NULL,
1118
+ availability_id_in_stock int(11) default '1',
1119
+ availability_id_out_of_stock int(11) default '2',
1120
+ products_locate varchar(30) default NULL,
1121
+ products_ordered int(11) NOT NULL default '0',
1122
+ products_url varchar(255) default NULL,
1123
+ products_viewed int(5) default '0',
1124
+ products_seo_url varchar(100) NOT NULL,
1125
+ manufacturer_name varchar(255) default NULL,
1126
+ key(store_category_product_id),
1127
+ key(store_product_id),
1128
+ key(sinch_manufacturer_id),
1129
+ key(store_category_id)
1130
+ )DEFAULT CHARSET=utf8");
1131
+
1132
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv' INTO TABLE products_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
1133
+ $this->db_do("ALTER TABLE products_temp convert to CHARACTER SET \"latin1\"");
1134
+
1135
+ $this->db_do("update products_temp set products_date_added=now(), products_last_modified=now()");
1136
+
1137
+ $this->db_do("update products_temp p join stINch_manufacturers m on p.sinch_manufacturer_id=m.sinch_manufacturer_id set p.manufacturer_name=m.manufacturer_name");
1138
+
1139
+ if($this->current_import_status_statistic_id){
1140
+ $res = $this->db_do("select count(*) as cnt from products_temp");
1141
+ $row = mysql_fetch_assoc($res);
1142
+ $this->db_do("update ".$this->import_status_statistic_table." set number_of_products=".$row['cnt']." where id=".$this->current_import_status_statistic_id);
1143
+ }
1144
+ /* $this->db_do("update products p join products_temp pt on p.products_id=pt.store_product_id set pt.products_date_added=p.products_date_added where p.products_date_added > 0 and p.products_id is not null and p.products_date_added < pt.products_date_added");
1145
+ $this->db_do("update products p join products_temp pt on p.products_id=pt.store_product_id set pt.availability_id_in_stock=p.availability_id_in_stock, pt.availability_id_out_of_stock=p.availability_id_out_of_stock, pt.products_locate=p.products_locate, pt.products_ordered=p.products_ordered");
1146
+
1147
+ $this->db_do("update products_description pd join products_temp pt on pd.products_id=pt.store_product_id set pt.products_url=pd.products_url, pt.products_viewed=pd.products_viewed, pt.products_seo_url=pd.products_seo_url where pd.language_id=".$this->lang_id);
1148
+ // $this->db_do("update products_temp set products_date_added=now() limit 1000");
1149
+
1150
+
1151
+ $this->db_do("TRUNCATE products");
1152
+ $this->db_do("insert ignore into products (products_id, products_model, products_image, manufacturers_id, products_status, products_date_added, products_last_modified, availability_id_in_stock, availability_id_out_of_stock, products_locate, products_ordered) (select store_product_id, product_sku, main_image_url, sinch_manufacturer_id, 1, products_date_added, products_last_modified, availability_id_in_stock, availability_id_out_of_stock, products_locate, products_ordered from products_temp)");
1153
+
1154
+ $this->db_do("TRUNCATE products_description");
1155
+ $this->db_do("insert ignore into products_description (products_id, language_id, products_name, products_description, products_url, products_viewed, products_seo_url)(select store_product_id, ".$this->lang_id.", product_name, description, products_url, products_viewed, products_seo_url from products_temp)");
1156
+
1157
+ $this->db_do("TRUNCATE products_to_categories");
1158
+ $this->db_do("insert ignore into products_to_categories (select store_product_id, store_category_id from products_temp)");
1159
+ */ $this->addProductsWebsite();
1160
+ $this->mapSinchProducts();
1161
+ $this->replaceMagentoProducts();
1162
+ $this->mapSinchProducts();
1163
+ $this->addManufacturer_attribute();
1164
+ $this->db_do("DROP TABLE IF EXISTS stINch_products");
1165
+ $this->db_do("RENAME TABLE products_temp TO stINch_products");
1166
+ $this->_LOG("Finish parse ".FILE_PRODUCTS);
1167
+ }else{
1168
+ $this->_LOG("Wrong file ".$parse_file);
1169
+ }
1170
+ $this->_LOG(" ");
1171
+ }
1172
+
1173
+ #################################################################################################
1174
+
1175
+ function ParseRelatedProducts(){
1176
+
1177
+ $parse_file=$this->varDir.FILE_RELATED_PRODUCTS;
1178
+ if(filesize($parse_file) || $this->_ignore_product_related){
1179
+ $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
1180
+ $this->db_do("DROP TABLE IF EXISTS related_products_temp");
1181
+ $this->db_do("CREATE TABLE related_products_temp(
1182
+ sinch_product_id int(11),
1183
+ related_sinch_product_id int(11),
1184
+ store_product_id int(11) default null,
1185
+ store_related_product_id int(11) default null,
1186
+ entity_id int(11),
1187
+ related_entity_id int(11),
1188
+ key(sinch_product_id),
1189
+ key(related_sinch_product_id),
1190
+ key(store_product_id)
1191
+ )DEFAULT CHARSET=utf8");
1192
+ if(!$this->_ignore_product_related){
1193
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE related_products_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
1194
+ }
1195
+ $this->db_do("DROP TABLE IF EXISTS stINch_related_products");
1196
+ $this->db_do("RENAME TABLE related_products_temp TO stINch_related_products");
1197
+
1198
+ $this->_LOG("Finish parse ".FILE_RELATED_PRODUCTS);
1199
+ }else{
1200
+ $this->_LOG("Wrong file ".$parse_file);
1201
+ }
1202
+ $this->_LOG(" ");
1203
+ }
1204
+
1205
+ #################################################################################################
1206
+
1207
+ function ParseRestrictedValues(){
1208
+
1209
+ $parse_file=$this->varDir.FILE_RESTRICTED_VALUES;
1210
+ if(filesize($parse_file) || $this->_ignore_restricted_values){
1211
+ $this->_LOG("Start parse ".FILE_RESTRICTED_VALUES);
1212
+ $file_handle_from = fopen($parse_file, "r");
1213
+ unlink($parse_file.".conv");
1214
+ $file_handle_to = fopen($parse_file.".conv", "w");
1215
+ while (!feof($file_handle_from)) {
1216
+ $line = fgets($file_handle_from);
1217
+ $line = $this->valid_utf($line);
1218
+ fwrite($file_handle_to, $line);
1219
+ }
1220
+ fclose($file_handle_from);
1221
+ fclose($file_handle_to);
1222
+
1223
+
1224
+ $this->db_do("DROP TABLE IF EXISTS restricted_values_temp");
1225
+ $this->db_do("CREATE TABLE restricted_values_temp(
1226
+ restricted_value_id int(11),
1227
+ category_feature_id int(11),
1228
+ text text,
1229
+ display_order_number int(11),
1230
+ key(restricted_value_id),
1231
+ key(category_feature_id)
1232
+ )");
1233
+ if(!$this->_ignore_restricted_values){
1234
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv' INTO TABLE restricted_values_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
1235
+ }
1236
+ $this->db_do("ALTER TABLE restricted_values_temp convert to CHARACTER SET \"latin1\"");
1237
+ $this->db_do("DROP TABLE IF EXISTS stINch_restricted_values");
1238
+ $this->db_do("RENAME TABLE restricted_values_temp TO stINch_restricted_values");
1239
+
1240
+ $this->_LOG("Finish parse ".FILE_RESTRICTED_VALUES);
1241
+ }else{
1242
+ $this->_LOG("Wrong file ".$parse_file);
1243
+ }
1244
+ $this->_LOG(" ");
1245
+ }
1246
+
1247
+ #################################################################################################
1248
+
1249
+ function ParseStockAndPrices(){
1250
+
1251
+ $parse_file=$this->varDir.FILE_STOCK_AND_PRICES;
1252
+ if(filesize($parse_file)){
1253
+ $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
1254
+ $this->db_do("DROP TABLE IF EXISTS stock_and_prices_temp");
1255
+ $this->db_do("CREATE TABLE stock_and_prices_temp(
1256
+ store_product_id int(11),
1257
+ stock int(11),
1258
+ price decimal(15,4),
1259
+ cost decimal(15,4),
1260
+ distributor_id int(11),
1261
+ key(store_product_id),
1262
+ key(distributor_id)
1263
+ )");
1264
+
1265
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE stock_and_prices_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
1266
+
1267
+ // $this->db_do("update products p join stock_and_prices_temp s on p.products_id=s.store_product_id set p.products_price=s.price, p.products_quantity=s.stock");
1268
+ $this->replaceMagentoProductsStockPrice();
1269
+
1270
+ $res = $this->db_do("select count(*) as cnt FROM catalog_product_entity a
1271
+ INNER JOIN stock_and_prices_temp b on a.store_product_id=b.store_product_id");
1272
+ $row = mysql_fetch_assoc($res);
1273
+ $this->db_do("update ".$this->import_status_statistic_table." set number_of_products=".$row['cnt']." where id=".$this->current_import_status_statistic_id);
1274
+
1275
+ $this->addWeight();
1276
+
1277
+ $this->db_do("DROP TABLE IF EXISTS stINch_stock_and_prices");
1278
+ $this->db_do("RENAME TABLE stock_and_prices_temp TO stINch_stock_and_prices");
1279
+
1280
+ $this->_LOG("Finish parse".FILE_RELATED_PRODUCTS);
1281
+ }else{
1282
+ $this->_LOG("Wrong file".$parse_file);
1283
+ }
1284
+ $this->_LOG(" ");
1285
+ }
1286
+
1287
+ #################################################################################################
1288
+
1289
+ function ParseProductsPicturesGallery(){
1290
+
1291
+ $parse_file=$this->varDir.FILE_PRODUCTS_PICTURES_GALLERY;
1292
+ if(filesize($parse_file)){
1293
+ $this->_LOG("Start parse ".FILE_PRODUCTS_PICTURES_GALLERY);
1294
+ $this->db_do("DROP TABLE IF EXISTS products_pictures_gallery_temp");
1295
+ $this->db_do("CREATE TABLE products_pictures_gallery_temp(
1296
+ sinch_product_id int(11),
1297
+ image_url varchar(255),
1298
+ thumb_image_url varchar(255),
1299
+ store_product_id int(11),
1300
+ key(sinch_product_id),
1301
+ key(store_product_id)
1302
+ )");
1303
+
1304
+ $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."' INTO TABLE products_pictures_gallery_temp FIELDS TERMINATED BY '".$this->field_terminated_char."' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES ");
1305
+
1306
+ $this->db_do("UPDATE products_pictures_gallery_temp ppgt join stINch_products sp on ppgt.sinch_product_id=sp.sinch_product_id join catalog_product_entity cpe on sp.store_product_id=cpe.store_product_id set ppgt.store_product_id=sp.store_product_id");
1307
+
1308
+ $this->db_do("DROP TABLE IF EXISTS stINch_products_pictures_gallery");
1309
+ $this->db_do("RENAME TABLE products_pictures_gallery_temp TO stINch_products_pictures_gallery");
1310
+
1311
+ $this->_LOG("Finish parse".FILE_PRODUCTS_PICTURES_GALLERY);
1312
+ }else{
1313
+ $this->_LOG("Wrong file".$parse_file);
1314
+ }
1315
+ $this->_LOG(" ");
1316
+
1317
+ }
1318
+ #################################################################################################
1319
+ public function mapSinchCategories(){
1320
+ $this->db_do("DROP TABLE IF EXISTS stINch_categories_mapping_temp");
1321
+ $this->db_do("CREATE TABLE stINch_categories_mapping_temp(
1322
+ shop_entity_id int(11) unsigned NOT NULL,
1323
+ shop_entity_type_id int(11),
1324
+ shop_attribute_set_id int(11),
1325
+ shop_parent_id int(11),
1326
+ shop_store_category_id int(11),
1327
+ shop_parent_store_category_id int(11),
1328
+ store_category_id int(11),
1329
+ parent_store_category_id int(11),
1330
+ category_name varchar(255),
1331
+ order_number int(11),
1332
+ products_within_this_category int(11),
1333
+ key shop_entity_id (shop_entity_id),
1334
+ key shop_parent_id (shop_parent_id),
1335
+ key store_category_id (store_category_id),
1336
+ key parent_store_category_id (parent_store_category_id),
1337
+ unique key(shop_entity_id)
1338
+ )
1339
+ ");
1340
+ $this->db_do("CREATE TABLE IF NOT EXISTS stINch_categories_mapping like stINch_categories_mapping_temp");
1341
+ $result = $this->db_do("
1342
+ INSERT ignore INTO stINch_categories_mapping_temp (
1343
+ shop_entity_id,
1344
+ shop_entity_type_id,
1345
+ shop_attribute_set_id,
1346
+ shop_parent_id,
1347
+ shop_store_category_id,
1348
+ shop_parent_store_category_id
1349
+ )(select
1350
+ entity_id,
1351
+ entity_type_id,
1352
+ attribute_set_id,
1353
+ parent_id,
1354
+ store_category_id,
1355
+ parent_store_category_id
1356
+ from catalog_category_entity
1357
+ )
1358
+
1359
+ ");
1360
+
1361
+ $q="update stINch_categories_mapping_temp cmt join categories_temp c on cmt.shop_store_category_id=c.store_category_id set cmt.store_category_id=c.store_category_id, cmt.parent_store_category_id=c.parent_store_category_id, cmt.category_name=c.category_name, cmt.order_number=c.order_number, cmt.products_within_this_category=c.products_within_this_category";
1362
+ $this->db_do($q);
1363
+
1364
+ $q="update stINch_categories_mapping_temp cmt join catalog_category_entity cce on cmt.parent_store_category_id=cce.store_category_id set cmt.shop_parent_id=cce.entity_id";
1365
+ $this->db_do($q);
1366
+
1367
+ $q="update stINch_categories_mapping_temp cmt join categories_temp c on cmt.shop_store_category_id=c.store_category_id set shop_parent_id=".$this->_root_cat." where shop_parent_id=0";
1368
+ $this->db_do($q);
1369
+
1370
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
1371
+ $im_type = $dataConf['replace_category'];
1372
+ if((UPDATE_CATEGORY_DATA && $im_type=="MERGE") || ($im_type=="REWRITE")){
1373
+ $q="update stINch_categories_mapping_temp cmt join catalog_category_entity cce on cmt.shop_entity_id=cce.entity_id set cce.parent_id=cmt.shop_parent_id";
1374
+ $this->db_do($q);
1375
+ }
1376
+
1377
+
1378
+ $this->db_do("DROP TABLE IF EXISTS stINch_categories_mapping");
1379
+ $this->db_do("RENAME TABLE stINch_categories_mapping_temp TO stINch_categories_mapping");
1380
+ }
1381
+
1382
+ #################################################################################################
1383
+ public function mapSinchProducts(){
1384
+ $this->db_do("DROP TABLE IF EXISTS stINch_products_mapping_temp");
1385
+ $this->db_do("CREATE TABLE stINch_products_mapping_temp(
1386
+ entity_id int(11) unsigned NOT NULL,
1387
+ manufacturer_option_id int(11),
1388
+ manufacturer_name varchar(255),
1389
+ shop_store_product_id int(11),
1390
+ shop_sinch_product_id int(11),
1391
+ sku varchar(64) default NULL,
1392
+ store_category_product_id int(11),
1393
+ store_product_id int(11),
1394
+ sinch_product_id int(11),
1395
+ product_sku varchar(255),
1396
+ sinch_manufacturer_id int(11),
1397
+ sinch_manufacturer_name varchar(255),
1398
+ key entity_id (entity_id),
1399
+ key manufacturer_option_id (manufacturer_option_id),
1400
+ key manufacturer_name (manufacturer_name),
1401
+ key store_product_id (store_product_id),
1402
+ key sinch_product_id (sinch_product_id),
1403
+ key sku (sku),
1404
+ unique key(entity_id)
1405
+ )
1406
+ ");
1407
+ $this->db_do("CREATE TABLE IF NOT EXISTS stINch_products_mapping like stINch_products_mapping_temp");
1408
+ $result = $this->db_do("
1409
+ INSERT ignore INTO stINch_products_mapping_temp (
1410
+ entity_id,
1411
+ sku,
1412
+ shop_store_product_id,
1413
+ shop_sinch_product_id
1414
+ )(select
1415
+ entity_id,
1416
+ sku,
1417
+ store_product_id,
1418
+ sinch_product_id
1419
+ from catalog_product_entity
1420
+ )
1421
+
1422
+ ");
1423
+
1424
+ $this->addManufacturers(1);
1425
+
1426
+ $q="update stINch_products_mapping_temp pmt join catalog_product_index_eav cpie on pmt.entity_id=cpie.entity_id join eav_attribute_option_value aov on cpie.value=aov.option_id set manufacturer_option_id=cpie.value, manufacturer_name=aov.value where cpie.attribute_id=".$this->attributes['manufacturer'];
1427
+ $this->db_do($q);
1428
+
1429
+ $q="update stINch_products_mapping_temp pmt join products_temp p on pmt.sku=p.product_sku set pmt.store_category_product_id=p.store_category_product_id, pmt.store_product_id=p.store_product_id, pmt.sinch_product_id=p.sinch_product_id, pmt.product_sku=p.product_sku, pmt.sinch_manufacturer_id=p.sinch_manufacturer_id, pmt.sinch_manufacturer_name=p.manufacturer_name";
1430
+ $this->db_do($q);
1431
+
1432
+ $q="update catalog_product_entity cpe join stINch_products_mapping_temp pmt on cpe.entity_id=pmt.entity_id set cpe.store_product_id=pmt.store_product_id, cpe.sinch_product_id=pmt.sinch_product_id where cpe.sinch_product_id is null and pmt.sinch_product_id is not null and cpe.store_product_id is null and pmt.store_product_id is not null";
1433
+ $this->db_do($q);
1434
+
1435
+ $this->db_do("DROP TABLE IF EXISTS stINch_products_mapping");
1436
+ $this->db_do("RENAME TABLE stINch_products_mapping_temp TO stINch_products_mapping");
1437
+ }
1438
+ public function addProductsWebsite (){
1439
+ $this->db_do(" DROP TABLE IF EXISTS products_website_temp");
1440
+ // TEMPORARY
1441
+ $this->db_do("
1442
+ CREATE TABLE `products_website_temp` (
1443
+ `id` int(10) unsigned NOT NULL auto_increment,
1444
+ store_product_id int(11),
1445
+ sinch_product_id int(11),
1446
+ `website` int(11) default NULL,
1447
+ `website_id` int(11) default NULL,
1448
+ PRIMARY KEY (`id`),
1449
+ KEY store_product_id (`store_product_id`)
1450
+ )
1451
+ ");
1452
+ $result = $this->db_do("SELECT website_id, store_id as website FROM core_store where code!='admin'"); // where code!='admin' was adder for editing Featured products;
1453
+ while ($row = mysql_fetch_assoc($result)) {
1454
+ $sql = "INSERT INTO products_website_temp
1455
+ (store_product_id, sinch_product_id, website, website_id)
1456
+ (SELECT distinct
1457
+ store_product_id,
1458
+ sinch_product_id,
1459
+ {$row['website']},
1460
+ {$row['website_id']}
1461
+ FROM products_temp)";
1462
+ $result2 = $this->db_do($sql);
1463
+ }
1464
+
1465
+
1466
+ }
1467
+ #################################################################################################
1468
+ public function replaceMagentoProducts() {
1469
+
1470
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
1471
+
1472
+ // $this->db_do("DROP TABLE IF EXISTS stINch_backup_catalog_product_entity_datetime");
1473
+ // $this->db_do("DROP TABLE IF EXISTS stINch_backup_catalog_product_entity_int");
1474
+
1475
+ // $this->db_do("create table stINch_backup_catalog_product_entity_datetime like catalog_product_entity_datetime");
1476
+ // $this->db_do("create table stINch_backup_catalog_product_entity_int like catalog_product_entity_int");
1477
+
1478
+ // $this->db_do("INSERT INTO stINch_backup_catalog_product_entity_datetime (select * from catalog_product_entity_datetime where attribute_id=".$this->_getProductAttributeId('news_from_date').")");
1479
+ // $this->db_do("INSERT INTO stINch_backup_catalog_product_entity_datetime (select * from catalog_product_entity_datetime where attribute_id=".$this->_getProductAttributeId('news_to_date').")");
1480
+
1481
+ // if($this->_getProductAttributeId('inchoo_featured_product')){
1482
+ // $this->db_do("INSERT INTO stINch_backup_catalog_product_entity_int (select * from catalog_product_entity_int where attribute_id=".$this->_getProductAttributeId('inchoo_featured_product').")");
1483
+ // }
1484
+
1485
+ $result = $this->db_do("DELETE cpe from catalog_product_entity cpe join stINch_products_mapping pm on cpe.entity_id=pm.entity_id
1486
+ where pm.shop_store_product_id is not null and pm.store_product_id is null
1487
+ ");
1488
+
1489
+ // $this->db_do("INSERT INTO catalog_product_entity_datetime (select * from stINch_backup_catalog_product_entity_datetime backd) ON
1490
+ // DUPLICATE KEY UPDATE
1491
+ // value = backd.value");
1492
+
1493
+
1494
+ //Inserting new products and updating old others.
1495
+ $this->_getProductDefaulAttributeSetId();
1496
+ $result = $this->db_do("
1497
+ INSERT INTO catalog_product_entity (
1498
+ entity_id,
1499
+ entity_type_id,
1500
+ attribute_set_id,
1501
+ type_id,
1502
+ sku,
1503
+ updated_at,
1504
+ has_options,
1505
+ store_product_id,
1506
+ sinch_product_id
1507
+ )
1508
+ (SELECT
1509
+ pm.entity_id,
1510
+ " . $this->_getProductEntityTypeId(). ",
1511
+ $this->defaultAttributeSetId,
1512
+ 'simple',
1513
+
1514
+ a.product_sku,
1515
+ NOW(),
1516
+ 0,
1517
+ a.store_product_id,
1518
+ a.sinch_product_id
1519
+
1520
+ FROM products_temp a
1521
+ left join stINch_products_mapping pm on
1522
+ a.store_product_id=pm.store_product_id
1523
+ and
1524
+ a.sinch_product_id=pm.sinch_product_id
1525
+ )
1526
+ ON DUPLICATE KEY UPDATE
1527
+ sku= a.product_sku,
1528
+ store_product_id=a.store_product_id,
1529
+ sinch_product_id=a.sinch_product_id
1530
+ ");
1531
+ // store_product_id=a.store_product_id,
1532
+ // sinch_product_id=a.sinch_product_id
1533
+
1534
+ //Set enabled
1535
+ $result = $this->db_do(" DELETE cpei from catalog_product_entity_int cpei LEFT JOIN catalog_product_entity cpe on cpei.entity_id=cpe.entity_id where cpe.entity_id is null");
1536
+
1537
+ // $this->db_do("INSERT INTO catalog_product_entity_int (select bcpei.* from stINch_backup_catalog_product_entity_int bcpei join catalog_product_entity cpe on bcpei.entity_id=cpe.entity_id)");
1538
+ $result = $this->db_do("
1539
+ INSERT INTO catalog_product_entity_int (
1540
+ entity_type_id,
1541
+ attribute_id,
1542
+ store_id,
1543
+ entity_id,
1544
+ value
1545
+ )(
1546
+ SELECT
1547
+ " . $this->_getProductEntityTypeId(). ",
1548
+ ". $this->_getProductAttributeId('status').",
1549
+ w.website,
1550
+ a.entity_id,
1551
+ 1
1552
+ FROM catalog_product_entity a
1553
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
1554
+ ON DUPLICATE KEY UPDATE
1555
+ value=1
1556
+
1557
+ ");
1558
+ // set status = 1 for all stores
1559
+ $result = $this->db_do("
1560
+ INSERT INTO catalog_product_entity_int (
1561
+ entity_type_id,
1562
+ attribute_id,
1563
+ store_id,
1564
+ entity_id,
1565
+ value
1566
+ )(
1567
+ SELECT
1568
+ " . $this->_getProductEntityTypeId(). ",
1569
+ ".$this->_getProductAttributeId('status').",
1570
+ 0,
1571
+ a.entity_id,
1572
+ 1
1573
+ FROM catalog_product_entity a)
1574
+ ON DUPLICATE KEY UPDATE
1575
+ value=1
1576
+
1577
+ ");
1578
+
1579
+ //Unifying products with categories.
1580
+ $result = $this->db_do("DELETE ccp from catalog_category_product ccp LEFT JOIN catalog_product_entity cpe on ccp.product_id=cpe.entity_id where cpe.entity_id is null");
1581
+
1582
+ $result = $this->db_do("update ignore catalog_category_product ccp left join catalog_category_entity cce on ccp.category_id=cce.entity_id set ccp.category_id=2 where cce.entity_id is null");
1583
+ $result = $this->db_do("delete ccp from catalog_category_product ccp left join catalog_category_entity cce on ccp.category_id=cce.entity_id where cce.entity_id is null");
1584
+
1585
+
1586
+ $this->db_do(" DROP TABLE IF EXISTS catalog_category_product_for_delete_temp");
1587
+ // TEMPORARY
1588
+ $this->db_do("
1589
+ CREATE TABLE `catalog_category_product_for_delete_temp` (
1590
+ `category_id` int(10) unsigned NOT NULL default '0',
1591
+ `product_id` int(10) unsigned NOT NULL default '0',
1592
+ `store_product_id` int(10) NOT NULL default '0',
1593
+ `store_category_id` int(10) NOT NULL default '0',
1594
+ `new_category_id` int(10) NOT NULL default '0',
1595
+ UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
1596
+ KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
1597
+ KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
1598
+ KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
1599
+ )
1600
+
1601
+ ");
1602
+
1603
+ $result = $this->db_do("
1604
+ INSERT INTO catalog_category_product_for_delete_temp (
1605
+ category_id,
1606
+ product_id,
1607
+ store_product_id
1608
+ )(
1609
+ SELECT
1610
+ ccp.category_id,
1611
+ ccp.product_id,
1612
+ cpe.store_product_id
1613
+ FROM catalog_category_product ccp join catalog_product_entity cpe on ccp.product_id=cpe.entity_id)
1614
+ ");
1615
+
1616
+ $result = $this->db_do("
1617
+ update catalog_category_product_for_delete_temp ccpfd join products_temp p on ccpfd.store_product_id=p.store_product_id set ccpfd.store_category_id=p.store_category_id where ccpfd.store_product_id!=0
1618
+ ");
1619
+
1620
+ $result = $this->db_do("
1621
+ update catalog_category_product_for_delete_temp ccpfd join stINch_categories_mapping scm on ccpfd.store_category_id=scm.store_category_id set ccpfd.new_category_id=scm.shop_entity_id where ccpfd.store_category_id!=0
1622
+ ");
1623
+
1624
+ $result = $this->db_do("delete from catalog_category_product_for_delete_temp where category_id=new_category_id");
1625
+
1626
+ $result = $this->db_do("
1627
+ delete ccp from catalog_category_product ccp join catalog_category_product_for_delete_temp ccpfd on ccp.product_id=ccpfd.product_id and ccp.category_id=ccpfd.category_id
1628
+ ");
1629
+
1630
+ $result = $this->db_do("
1631
+ INSERT INTO catalog_category_product (
1632
+ category_id,
1633
+ product_id
1634
+ )(
1635
+ SELECT scm.shop_entity_id, cpe.entity_id from catalog_product_entity cpe join products_temp p on cpe.store_product_id=p.store_product_id join stINch_categories_mapping scm on p.store_category_id=scm.store_category_id)
1636
+ ON DUPLICATE KEY UPDATE
1637
+ product_id = cpe.entity_id
1638
+ ");
1639
+
1640
+ //Indexing products and categories in the shop
1641
+ $result = $this->db_do("DELETE ccpi from catalog_category_product_index ccpi LEFT JOIN catalog_product_entity cpe on ccpi.product_id=cpe.entity_id where cpe.entity_id is null");
1642
+
1643
+ $result = $this->db_do("
1644
+ INSERT INTO catalog_category_product_index (
1645
+ category_id,
1646
+ product_id,
1647
+ position,
1648
+ is_parent,
1649
+ store_id,
1650
+ visibility
1651
+ )(
1652
+ SELECT
1653
+ a.category_id,
1654
+ a.product_id,
1655
+ a.position,
1656
+ 1,
1657
+ b.store_id,
1658
+ 4
1659
+ FROM catalog_category_product a
1660
+ INNER JOIN core_store b)
1661
+ ON DUPLICATE KEY UPDATE
1662
+ visibility = 4
1663
+ ");
1664
+ $result = $this->db_do("
1665
+ INSERT ignore INTO catalog_category_product_index (
1666
+ category_id,
1667
+ product_id,
1668
+ position,
1669
+ is_parent,
1670
+ store_id,
1671
+ visibility
1672
+ )(
1673
+ SELECT
1674
+ 2,
1675
+ a.product_id,
1676
+ a.position,
1677
+ 1,
1678
+ b.store_id,
1679
+ 4
1680
+ FROM catalog_category_product a
1681
+ INNER JOIN core_store b)
1682
+ ON DUPLICATE KEY UPDATE
1683
+ visibility = 4
1684
+
1685
+ ");
1686
+
1687
+
1688
+
1689
+ //Set product name for specific web sites
1690
+ $result = $this->db_do("DELETE cpev from catalog_product_entity_varchar cpev LEFT JOIN catalog_product_entity cpe on cpev.entity_id=cpe.entity_id where cpe.entity_id is null");
1691
+ $result = $this->db_do("
1692
+ INSERT INTO catalog_product_entity_varchar (
1693
+ entity_type_id,
1694
+ attribute_id,
1695
+ store_id,
1696
+ entity_id,
1697
+ value
1698
+ )(
1699
+ SELECT
1700
+ " . $this->_getProductEntityTypeId(). ",
1701
+ " . $this->_getProductAttributeId('name'). ",
1702
+ w.website,
1703
+ a.entity_id,
1704
+ b.product_name
1705
+ FROM catalog_product_entity a
1706
+ INNER JOIN products_temp b
1707
+ ON a.store_product_id= b.store_product_id
1708
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
1709
+ ON DUPLICATE KEY UPDATE
1710
+ value = b.product_name
1711
+ ");
1712
+ // product name for all web sites
1713
+ $result = $this->db_do("
1714
+ INSERT INTO catalog_product_entity_varchar (
1715
+ entity_type_id,
1716
+ attribute_id,
1717
+ store_id,
1718
+ entity_id,
1719
+ value
1720
+ )(
1721
+ SELECT
1722
+ " . $this->_getProductEntityTypeId(). ",
1723
+ " . $this->_getProductAttributeId('name'). ",
1724
+ 0,
1725
+ a.entity_id,
1726
+ b.product_name
1727
+ FROM catalog_product_entity a
1728
+ INNER JOIN products_temp b
1729
+ ON a.store_product_id = b.store_product_id)
1730
+ ON DUPLICATE KEY UPDATE
1731
+ value = b.product_name
1732
+ ");
1733
+ $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
1734
+
1735
+ $this->addDescriptions();
1736
+ $this->addShortDescriptions();
1737
+ $this->addEAN();
1738
+ $this->addSpecification();
1739
+ $this->addManufacturers();
1740
+
1741
+ //Enabling product index.
1742
+ $result = $this->db_do("DELETE cpei from catalog_product_enabled_index cpei LEFT JOIN catalog_product_entity cpe on cpei.product_id=cpe.entity_id where cpe.entity_id is null");
1743
+ $result = $this->db_do("
1744
+ INSERT INTO catalog_product_enabled_index (
1745
+ product_id,
1746
+ store_id,
1747
+ visibility
1748
+ )(
1749
+ SELECT
1750
+ a.entity_id,
1751
+ w.website,
1752
+ 4
1753
+ FROM catalog_product_entity a
1754
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id
1755
+ )
1756
+ ON DUPLICATE KEY UPDATE
1757
+ visibility = 4
1758
+ ");
1759
+ $result = $this->db_do("
1760
+ INSERT INTO catalog_product_enabled_index (
1761
+ product_id,
1762
+ store_id,
1763
+ visibility
1764
+ )(
1765
+ SELECT
1766
+ a.entity_id,
1767
+ 0,
1768
+ 4
1769
+ FROM catalog_product_entity a
1770
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id
1771
+ )
1772
+ ON DUPLICATE KEY UPDATE
1773
+ visibility = 4
1774
+ ");
1775
+
1776
+
1777
+ $result = $this->db_do("
1778
+ INSERT INTO catalog_product_entity_int (
1779
+ entity_type_id,
1780
+ attribute_id,
1781
+ store_id,
1782
+ entity_id,
1783
+ value
1784
+ )(
1785
+ SELECT
1786
+ " . $this->_getProductEntityTypeId(). ",
1787
+ " . $this->_getProductAttributeId('visibility'). ",
1788
+ w.website,
1789
+ a.entity_id,
1790
+ 4
1791
+ FROM catalog_product_entity a
1792
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
1793
+ ON DUPLICATE KEY UPDATE
1794
+ value = 4
1795
+ ");
1796
+
1797
+ $result = $this->db_do("
1798
+ INSERT INTO catalog_product_entity_int (
1799
+ entity_type_id,
1800
+ attribute_id,
1801
+ store_id,
1802
+ entity_id,
1803
+ value
1804
+ )(
1805
+ SELECT
1806
+ " . $this->_getProductEntityTypeId(). ",
1807
+ " . $this->_getProductAttributeId('visibility'). ",
1808
+ 0,
1809
+ a.entity_id,
1810
+ 4
1811
+ FROM catalog_product_entity a
1812
+ )
1813
+ ON DUPLICATE KEY UPDATE
1814
+ value = 4
1815
+ ");
1816
+
1817
+ // $result = $this->db_do(" truncate catalog_product_website");
1818
+ $result = $this->db_do("DELETE cpw from catalog_product_website cpw LEFT JOIN catalog_product_entity cpe on cpw.product_id=cpe.entity_id where cpe.entity_id is null");
1819
+ $result = $this->db_do("
1820
+ INSERT INTO catalog_product_website (
1821
+ product_id,
1822
+ website_id
1823
+ )(
1824
+ SELECT a.entity_id, w.website_id
1825
+ FROM catalog_product_entity a
1826
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
1827
+ ON DUPLICATE KEY UPDATE
1828
+ product_id=a.entity_id,
1829
+ website_id=w.website_id
1830
+ ");
1831
+
1832
+ // temporary disabled mart@bintime.com
1833
+ //$result = $this->db_do("
1834
+ // UPDATE catalog_category_entity_int a
1835
+ // SET a.value = 0
1836
+ // WHERE a.attribute_id = 32
1837
+ //");
1838
+
1839
+
1840
+ //Adding tax class "Taxable Goods"
1841
+ $result = $this->db_do("
1842
+ INSERT INTO catalog_product_entity_int (
1843
+ entity_type_id,
1844
+ attribute_id,
1845
+ store_id,
1846
+ entity_id,
1847
+ value
1848
+ )(
1849
+ SELECT
1850
+ " . $this->_getProductEntityTypeId(). ",
1851
+ " . $this->_getProductAttributeId('tax_class_id'). ",
1852
+ w.website,
1853
+ a.entity_id,
1854
+ 2
1855
+ FROM catalog_product_entity a
1856
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
1857
+ ON DUPLICATE KEY UPDATE
1858
+ value = 2
1859
+ ");
1860
+ $result = $this->db_do("
1861
+ INSERT INTO catalog_product_entity_int (
1862
+ entity_type_id,
1863
+ attribute_id,
1864
+ store_id,
1865
+ entity_id,
1866
+ value
1867
+ )(
1868
+ SELECT
1869
+ " . $this->_getProductEntityTypeId(). ",
1870
+ " . $this->_getProductAttributeId('tax_class_id'). ",
1871
+ 0,
1872
+ a.entity_id,
1873
+ 2
1874
+ FROM catalog_product_entity a)
1875
+ ON DUPLICATE KEY UPDATE
1876
+ value = 2
1877
+ ");
1878
+
1879
+ //Add weight value
1880
+ /* $result = $this->db_do("
1881
+ INSERT INTO catalog_product_entity_decimal (
1882
+ entity_type_id,
1883
+ attribute_id,
1884
+ store_id,
1885
+ entity_id,
1886
+ value
1887
+ )
1888
+ SELECT 4, 65, 0, entity_id, b.weight
1889
+ FROM catalog_product_entity a
1890
+ INNER JOIN import_distributor_offer b
1891
+ ON a.distributor_product_id = b.distributor_product_code
1892
+ AND a.distributor_id = b.distributor_id
1893
+ ");
1894
+ */
1895
+ // Load url Image
1896
+ $result = $this->db_do("
1897
+ INSERT INTO catalog_product_entity_varchar (
1898
+ entity_type_id,
1899
+ attribute_id,
1900
+ store_id,
1901
+ entity_id,
1902
+ value
1903
+ )
1904
+ SELECT
1905
+ " . $this->_getProductEntityTypeId(). ",
1906
+ " . $this->_getProductAttributeId('image'). ",
1907
+ w.store_id,
1908
+ a.entity_id,
1909
+ b.main_image_url
1910
+ FROM catalog_product_entity a
1911
+ INNER JOIN core_store w
1912
+ INNER JOIN products_temp b
1913
+ ON a.store_product_id = b.store_product_id
1914
+ ON DUPLICATE KEY UPDATE
1915
+ value = b.main_image_url
1916
+ ");
1917
+
1918
+
1919
+ // image for specific web sites
1920
+ $result = $this->db_do("
1921
+ INSERT INTO catalog_product_entity_varchar (
1922
+ entity_type_id,
1923
+ attribute_id,
1924
+ store_id,
1925
+ entity_id,
1926
+ value
1927
+ )
1928
+ SELECT
1929
+ " . $this->_getProductEntityTypeId(). ",
1930
+ " . $this->_getProductAttributeId('image'). ",
1931
+ 0,
1932
+ a.entity_id,
1933
+ b.main_image_url
1934
+ FROM catalog_product_entity a
1935
+ INNER JOIN products_temp b
1936
+ ON a.store_product_id = b.store_product_id
1937
+ ON DUPLICATE KEY UPDATE
1938
+ value = b.main_image_url
1939
+
1940
+
1941
+ ");
1942
+
1943
+
1944
+ // small_image for specific web sites
1945
+ $result = $this->db_do("
1946
+ INSERT INTO catalog_product_entity_varchar (
1947
+ entity_type_id,
1948
+ attribute_id,
1949
+ store_id,
1950
+ entity_id,
1951
+ value
1952
+ )
1953
+ SELECT
1954
+ " . $this->_getProductEntityTypeId(). ",
1955
+ " . $this->_getProductAttributeId('small_image'). ",
1956
+ w.store_id,
1957
+ a.entity_id,
1958
+ b.medium_image_url
1959
+ FROM catalog_product_entity a
1960
+ INNER JOIN core_store w
1961
+ INNER JOIN products_temp b
1962
+ ON a.store_product_id = b.store_product_id
1963
+ ON DUPLICATE KEY UPDATE
1964
+ value = b.medium_image_url
1965
+ ");
1966
+
1967
+
1968
+ // small_image for all web sites
1969
+ $result = $this->db_do("
1970
+ INSERT INTO catalog_product_entity_varchar (
1971
+ entity_type_id,
1972
+ attribute_id,
1973
+ store_id,
1974
+ entity_id,
1975
+ value
1976
+ )
1977
+ SELECT
1978
+ " . $this->_getProductEntityTypeId(). ",
1979
+ " . $this->_getProductAttributeId('small_image'). ",
1980
+ 0,
1981
+ a.entity_id,
1982
+ b.medium_image_url
1983
+ FROM catalog_product_entity a
1984
+ INNER JOIN core_store w
1985
+ INNER JOIN products_temp b
1986
+ ON a.store_product_id = b.store_product_id
1987
+ ON DUPLICATE KEY UPDATE
1988
+ value = b.medium_image_url
1989
+ ");
1990
+
1991
+
1992
+ // thumbnail for specific web site
1993
+ $result = $this->db_do("
1994
+ INSERT INTO catalog_product_entity_varchar (
1995
+ entity_type_id,
1996
+ attribute_id,
1997
+ store_id,
1998
+ entity_id,
1999
+ value
2000
+ )
2001
+ SELECT
2002
+ " . $this->_getProductEntityTypeId(). ",
2003
+ " . $this->_getProductAttributeId('thumbnail'). ",
2004
+ w.store_id,
2005
+ a.entity_id,
2006
+ b.thumb_image_url
2007
+ FROM catalog_product_entity a
2008
+ INNER JOIN core_store w
2009
+ INNER JOIN products_temp b
2010
+ ON a.store_product_id = b.store_product_id
2011
+ ON DUPLICATE KEY UPDATE
2012
+ value = b.thumb_image_url
2013
+ ");
2014
+
2015
+
2016
+ // thumbnail for all web sites
2017
+ $result = $this->db_do("
2018
+ INSERT INTO catalog_product_entity_varchar (
2019
+ entity_type_id,
2020
+ attribute_id,
2021
+ store_id,
2022
+ entity_id,
2023
+ value
2024
+ )
2025
+ SELECT
2026
+ " . $this->_getProductEntityTypeId(). ",
2027
+ " . $this->_getProductAttributeId('thumbnail'). ",
2028
+ 0,
2029
+ a.entity_id,
2030
+ b.thumb_image_url
2031
+ FROM catalog_product_entity a
2032
+ INNER JOIN core_store w
2033
+ INNER JOIN products_temp b
2034
+ ON a.store_product_id = b.store_product_id
2035
+ ON DUPLICATE KEY UPDATE
2036
+ value = b.thumb_image_url
2037
+
2038
+ ");
2039
+
2040
+
2041
+ //Refresh fulltext search
2042
+ //d.value
2043
+ //$this->db_do('TRUNCATE catalogsearch_fulltext');
2044
+ $result = $this->db_do("DROP TABLE IF EXISTS catalogsearch_fulltext_tmp");
2045
+ $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS catalogsearch_fulltext_tmp LIKE catalogsearch_fulltext");
2046
+
2047
+ $result = $this->db_do("
2048
+ INSERT INTO catalogsearch_fulltext_tmp (product_id, store_id, data_index)
2049
+ SELECT
2050
+ a.entity_id,
2051
+ w.website_id,
2052
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
2053
+ FROM catalog_product_entity a
2054
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id
2055
+ LEFT JOIN catalog_category_product b ON a.entity_id = b.product_id
2056
+ LEFT JOIN catalog_category_entity_varchar c ON b.category_id = c.entity_id AND c.attribute_id =
2057
+ " . $this->_getCategoryAttributeId('name'). "
2058
+ LEFT JOIN catalog_product_entity_varchar e ON a.entity_id = e.entity_id AND e.attribute_id =
2059
+ " . $this->_getProductAttributeId('name'). "
2060
+ LEFT JOIN catalog_product_website j ON a.entity_id = j.product_id
2061
+ LEFT JOIN products_temp f ON a.entity_id = f.store_product_id
2062
+ ON DUPLICATE KEY UPDATE
2063
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
2064
+ ");
2065
+ $result = $this->db_do("
2066
+ INSERT INTO catalogsearch_fulltext_tmp (product_id, store_id, data_index)
2067
+ SELECT
2068
+ a.entity_id,
2069
+ w.website_id,
2070
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
2071
+ FROM catalog_product_entity a
2072
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id
2073
+ LEFT JOIN catalog_category_product b ON a.entity_id = b.product_id
2074
+ LEFT JOIN catalog_category_entity_varchar c ON b.category_id = c.entity_id AND c.attribute_id =
2075
+ " . $this->_getCategoryAttributeId('name'). "
2076
+ LEFT JOIN catalog_product_entity_varchar e ON a.entity_id = e.entity_id AND e.attribute_id =
2077
+ " . $this->_getProductAttributeId('name'). "
2078
+ LEFT JOIN products_temp f ON a.entity_id = f.store_product_id
2079
+ ON DUPLICATE KEY UPDATE
2080
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
2081
+ ");
2082
+
2083
+ $result = $this->db_do("DELETE cf from catalogsearch_fulltext cf LEFT JOIN catalog_product_entity cpe on cf.product_id=cpe.entity_id where cpe.entity_id is null");
2084
+
2085
+ $result = $this->db_do("
2086
+ INSERT INTO catalogsearch_fulltext (product_id, store_id, data_index)
2087
+ SELECT
2088
+ a.product_id,
2089
+ a.store_id,
2090
+ a.data_index
2091
+ FROM catalogsearch_fulltext_tmp a
2092
+ WHERE product_id = a.product_id
2093
+ ON DUPLICATE KEY UPDATE
2094
+ data_index = a.data_index
2095
+ ");
2096
+
2097
+ $this->db_do("UPDATE catalogsearch_query SET is_processed = 0");
2098
+ //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
2099
+ //TODO add something else
2100
+
2101
+ $this->addRelatedProducts();
2102
+ }
2103
+ #################################################################################################
2104
+ function addDescriptions(){
2105
+ // product description for all web sites
2106
+ $result = $this->db_do("
2107
+ INSERT INTO catalog_product_entity_text (
2108
+ entity_type_id,
2109
+ attribute_id,
2110
+ store_id,
2111
+ entity_id,
2112
+ value
2113
+ )(
2114
+ SELECT
2115
+ " . $this->_getProductEntityTypeId(). ",
2116
+ " . $this->_getProductAttributeId('description'). ",
2117
+ w.website,
2118
+ a.entity_id,
2119
+ b.description
2120
+ FROM catalog_product_entity a
2121
+ INNER JOIN products_temp b
2122
+ ON a.store_product_id = b.store_product_id
2123
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
2124
+ ON DUPLICATE KEY UPDATE
2125
+ value = b.description
2126
+ ");
2127
+ // product description for all web sites
2128
+ $result = $this->db_do("
2129
+ INSERT INTO catalog_product_entity_text (
2130
+ entity_type_id,
2131
+ attribute_id,
2132
+ store_id,
2133
+ entity_id,
2134
+ value
2135
+ )(
2136
+ SELECT
2137
+ " . $this->_getProductEntityTypeId(). ",
2138
+ " . $this->_getProductAttributeId('description'). ",
2139
+ 0,
2140
+ a.entity_id,
2141
+ b.description
2142
+ FROM catalog_product_entity a
2143
+ INNER JOIN products_temp b
2144
+ ON a.store_product_id = b.store_product_id)
2145
+ ON DUPLICATE KEY UPDATE
2146
+ value = b.description
2147
+
2148
+
2149
+ ");
2150
+
2151
+
2152
+ }
2153
+ #################################################################################################
2154
+ function addShortDescriptions(){
2155
+ // product short description for all web sites
2156
+ $result = $this->db_do("
2157
+ INSERT INTO catalog_product_entity_varchar (
2158
+ entity_type_id,
2159
+ attribute_id,
2160
+ store_id,
2161
+ entity_id,
2162
+ value
2163
+ )(
2164
+ SELECT
2165
+ " . $this->_getProductEntityTypeId(). ",
2166
+ " . $this->_getProductAttributeId('short_description'). ",
2167
+ w.website,
2168
+ a.entity_id,
2169
+ '&nbsp;'
2170
+ FROM catalog_product_entity a
2171
+ INNER JOIN products_temp b
2172
+ ON a.store_product_id = b.store_product_id
2173
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
2174
+ ON DUPLICATE KEY UPDATE
2175
+ value = '&nbsp;'
2176
+ ");
2177
+ // product short description for all web sites
2178
+ $result = $this->db_do("
2179
+ INSERT INTO catalog_product_entity_varchar (
2180
+ entity_type_id,
2181
+ attribute_id,
2182
+ store_id,
2183
+ entity_id,
2184
+ value
2185
+ )(
2186
+ SELECT
2187
+ " . $this->_getProductEntityTypeId(). ",
2188
+ " . $this->_getProductAttributeId('short_description'). ",
2189
+ 0,
2190
+ a.entity_id,
2191
+ '&nbsp;'
2192
+ FROM catalog_product_entity a
2193
+ INNER JOIN products_temp b
2194
+ ON a.store_product_id = b.store_product_id)
2195
+ ON DUPLICATE KEY UPDATE
2196
+ value = '&nbsp;'
2197
+
2198
+
2199
+ ");
2200
+
2201
+
2202
+ }
2203
+
2204
+ #################################################################################################
2205
+ function addEAN(){
2206
+ //gather EAN codes for each product
2207
+ $this->db_do("DROP TABLE IF EXISTS EANs_temp");
2208
+ $this->db_do("
2209
+ CREATE TEMPORARY TABLE EANs_temp(
2210
+ sinch_product_id int(11),
2211
+ store_product_id int(11),
2212
+ EANs text,
2213
+ KEY `sinch_product_id` (`sinch_product_id`),
2214
+ KEY `store_product_id` (`store_product_id`)
2215
+ )
2216
+ ");
2217
+ $this->db_do("
2218
+ INSERT INTO EANs_temp (sinch_product_id, EANs)(select sec.product_id, GROUP_CONCAT(DISTINCT ean_code ORDER BY ean_code DESC SEPARATOR ', ') as eans FROM stINch_ean_codes sec group by sec.product_id)
2219
+ ");
2220
+ $this->db_do("update EANs_temp e join products_temp p on e.sinch_product_id=p.sinch_product_id set e.store_product_id=p.store_product_id");
2221
+ // product EANs for all web sites
2222
+ $result = $this->db_do("
2223
+ INSERT INTO catalog_product_entity_varchar (
2224
+ entity_type_id,
2225
+ attribute_id,
2226
+ store_id,
2227
+ entity_id,
2228
+ value
2229
+ )(
2230
+ SELECT
2231
+ " . $this->_getProductEntityTypeId(). ",
2232
+ " . $this->_getProductAttributeId('ean'). ",
2233
+ w.website,
2234
+ a.entity_id,
2235
+ e.EANs
2236
+ FROM catalog_product_entity a
2237
+ INNER JOIN EANs_temp e
2238
+ ON a.store_product_id = e.store_product_id
2239
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
2240
+ ON DUPLICATE KEY UPDATE
2241
+ value = e.EANs
2242
+ ");
2243
+
2244
+ // product EANs for all web sites
2245
+ $result = $this->db_do("
2246
+ INSERT INTO catalog_product_entity_varchar (
2247
+ entity_type_id,
2248
+ attribute_id,
2249
+ store_id,
2250
+ entity_id,
2251
+ value
2252
+ )(
2253
+ SELECT
2254
+ " . $this->_getProductEntityTypeId(). ",
2255
+ " . $this->_getProductAttributeId('ean'). ",
2256
+ 0,
2257
+ a.entity_id,
2258
+ e.EANs
2259
+ FROM catalog_product_entity a
2260
+ INNER JOIN EANs_temp e
2261
+ ON a.store_product_id = e.store_product_id
2262
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
2263
+ ON DUPLICATE KEY UPDATE
2264
+ value = e.EANs
2265
+ ");
2266
+
2267
+
2268
+ }
2269
+ ################################################################################################
2270
+ function addSpecification(){
2271
+ // product specification for all web sites
2272
+ $result = $this->db_do("
2273
+ INSERT INTO catalog_product_entity_text (
2274
+ entity_type_id,
2275
+ attribute_id,
2276
+ store_id,
2277
+ entity_id,
2278
+ value
2279
+ )(
2280
+ SELECT
2281
+ " . $this->_getProductEntityTypeId(). ",
2282
+ " . $this->_getProductAttributeId('specification'). ",
2283
+ w.website,
2284
+ a.entity_id,
2285
+ b.specifications
2286
+ FROM catalog_product_entity a
2287
+ INNER JOIN products_temp b
2288
+ ON a.store_product_id = b.store_product_id
2289
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
2290
+ ON DUPLICATE KEY UPDATE
2291
+ value = b.specifications
2292
+ ");
2293
+ // product specification for all web sites
2294
+ $result = $this->db_do("
2295
+ INSERT INTO catalog_product_entity_text (
2296
+ entity_type_id,
2297
+ attribute_id,
2298
+ store_id,
2299
+ entity_id,
2300
+ value
2301
+ )(
2302
+ SELECT
2303
+ " . $this->_getProductEntityTypeId(). ",
2304
+ " . $this->_getProductAttributeId('specification'). ",
2305
+ 0,
2306
+ a.entity_id,
2307
+ b.specifications
2308
+ FROM catalog_product_entity a
2309
+ INNER JOIN products_temp b
2310
+ ON a.store_product_id = b.store_product_id)
2311
+ ON DUPLICATE KEY UPDATE
2312
+ value = b.specifications
2313
+
2314
+
2315
+ ");
2316
+
2317
+
2318
+ }
2319
+ private function addManufacturer_attribute(){
2320
+ $result = $this->db_do("
2321
+ INSERT INTO catalog_product_entity_int (
2322
+ entity_type_id,
2323
+ attribute_id,
2324
+ store_id,
2325
+ entity_id,
2326
+ value
2327
+ )(
2328
+ SELECT
2329
+ " . $this->_getProductEntityTypeId(). ",
2330
+ " . $this->_getProductAttributeId('manufacturer'). ",
2331
+ 0,
2332
+ a.entity_id,
2333
+ pm.manufacturer_option_id
2334
+ FROM catalog_product_entity a
2335
+ INNER JOIN stINch_products_mapping pm
2336
+ ON a.entity_id = pm.entity_id)
2337
+ ON DUPLICATE KEY UPDATE
2338
+ value = pm.manufacturer_option_id
2339
+ ");
2340
+
2341
+
2342
+ }
2343
+ #################################################################################################
2344
+ function addManufacturers($delete_eav=null){
2345
+ // this cleanup is not needed due to foreign keys
2346
+ if(!$delete_eav){
2347
+ $result = $this->db_do("
2348
+ DELETE FROM catalog_product_index_eav WHERE attribute_id = ".$this->_getProductAttributeId('manufacturer')//." AND store_id = ".$websiteId
2349
+ );
2350
+
2351
+ }
2352
+ $this->addManufacturer_attribute();
2353
+ // todo: doesn't seems to work properly, should be inserted per visibility
2354
+ // done, test now
2355
+
2356
+ $result = $this->db_do("
2357
+ INSERT INTO catalog_product_index_eav(
2358
+ entity_id,
2359
+ attribute_id,
2360
+ store_id,
2361
+ value
2362
+ )(
2363
+ SELECT
2364
+ a.entity_id,
2365
+ " . $this->_getProductAttributeId('manufacturer'). ",
2366
+ w.website,
2367
+ mn.shop_option_id
2368
+ FROM catalog_product_entity a
2369
+ INNER JOIN products_temp b
2370
+ ON a.store_product_id = b.store_product_id
2371
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id
2372
+ INNER JOIN stINch_manufacturers mn on b.sinch_manufacturer_id=mn.sinch_manufacturer_id
2373
+ where mn.shop_option_id is not null
2374
+ )
2375
+ ON DUPLICATE KEY UPDATE
2376
+ value = mn.shop_option_id
2377
+ ");
2378
+
2379
+ $result = $this->db_do("
2380
+ INSERT INTO catalog_product_index_eav(
2381
+ entity_id,
2382
+ attribute_id,
2383
+ store_id,
2384
+ value
2385
+ )(
2386
+ SELECT
2387
+ a.entity_id,
2388
+ " . $this->_getProductAttributeId('manufacturer'). ",
2389
+ 0,
2390
+ mn.shop_option_id
2391
+ FROM catalog_product_entity a
2392
+ INNER JOIN products_temp b
2393
+ ON a.store_product_id = b.store_product_id
2394
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id
2395
+ INNER JOIN stINch_manufacturers mn on b.sinch_manufacturer_id=mn.sinch_manufacturer_id
2396
+ where mn.shop_option_id is not null
2397
+ )
2398
+ ON DUPLICATE KEY UPDATE
2399
+ value = mn.shop_option_id
2400
+ ");
2401
+
2402
+
2403
+
2404
+ }
2405
+ #################################################################################################
2406
+ function addRelatedProducts(){
2407
+
2408
+ $this->db_do("update stINch_related_products rpt join products_temp p on rpt.sinch_product_id=p.sinch_product_id join catalog_product_entity cpe on p.store_product_id=cpe.store_product_id set rpt.store_product_id=p.store_product_id, rpt.entity_id=cpe.entity_id");
2409
+ $this->db_do("update stINch_related_products rpt join products_temp p on rpt.related_sinch_product_id=p.sinch_product_id join catalog_product_entity cpe on p.store_product_id=cpe.store_product_id set rpt.store_related_product_id=p.store_product_id, rpt.related_entity_id=cpe.entity_id");
2410
+
2411
+ $result = $this->db_do("SELECT link_type_id,code FROM catalog_product_link_type;");
2412
+ $link_type=array();
2413
+ while ($row = mysql_fetch_array($result)) {
2414
+ $link_type[$row['code']]=$row['link_type_id'];
2415
+ }
2416
+
2417
+ $result = $this->db_do("
2418
+ INSERT INTO catalog_product_link(
2419
+ product_id,
2420
+ linked_product_id,
2421
+ link_type_id
2422
+ )(
2423
+ SELECT
2424
+ entity_id,
2425
+ related_entity_id,
2426
+ ".$link_type['relation']."
2427
+ FROM stINch_related_products
2428
+ WHERE store_product_id is not null and store_related_product_id is not null
2429
+ )
2430
+ ON DUPLICATE KEY UPDATE
2431
+ product_id = entity_id,
2432
+ linked_product_id = related_entity_id
2433
+ ");
2434
+ $this->db_do("DROP TABLE IF EXISTS catalog_product_link_attribute_int_tmp");
2435
+
2436
+ $this->db_do("create temporary table catalog_product_link_attribute_int_tmp (
2437
+ `value_id` int(11) default NULL,
2438
+ `product_link_attribute_id` smallint(6) unsigned default NULL,
2439
+ `link_id` int(11) unsigned default NULL,
2440
+ `value` int(11) NOT NULL default '0',
2441
+ KEY `FK_INT_PRODUCT_LINK_ATTRIBUTE` (`product_link_attribute_id`),
2442
+ KEY `FK_INT_PRODUCT_LINK` (`link_id`)
2443
+ )
2444
+ ");
2445
+
2446
+ $result = $this->db_do("
2447
+ INSERT INTO catalog_product_link_attribute_int_tmp(
2448
+ product_link_attribute_id,
2449
+ link_id,
2450
+ value
2451
+ )(
2452
+ SELECT
2453
+ 2,
2454
+ cpl.link_id,
2455
+ 0
2456
+ FROM catalog_product_link cpl
2457
+ )
2458
+ ");
2459
+
2460
+ $result = $this->db_do(" UPDATE catalog_product_link_attribute_int_tmp ct join catalog_product_link_attribute_int c on ct.link_id=c.link_id set ct.value_id=c.value_id where c.product_link_attribute_id=2
2461
+ ");
2462
+ // $result = $this->db_do(" UPDATE catalog_product_link_attribute_int_tmp ct join catalog_product_link_attribute_int c on ct.link_id=c.link_id and ct.product_link_attribute_id=c.product_link_attribute_id set ct.value_id=c.value_id
2463
+ // ");
2464
+
2465
+
2466
+ $result = $this->db_do("
2467
+ INSERT INTO catalog_product_link_attribute_int(
2468
+ value_id,
2469
+ product_link_attribute_id,
2470
+ link_id,
2471
+ value
2472
+ )(
2473
+ SELECT
2474
+ value_id,
2475
+ product_link_attribute_id,
2476
+ link_id,
2477
+ value
2478
+ FROM catalog_product_link_attribute_int_tmp ct
2479
+ )
2480
+ ON DUPLICATE KEY UPDATE
2481
+ link_id=ct.link_id
2482
+
2483
+ ");
2484
+
2485
+ /* $q="select distinct store_product_id from stINch_related_products";
2486
+ $quer=$this->db_do($q);
2487
+ $prod = Mage::getModel('catalog/product');
2488
+ while ($row = mysql_fetch_assoc($quer)) {
2489
+ $q1="select distinct store_related_product_id store_product_id from stINch_related_products where store_product_id=".$row['store_product_id'].;
2490
+ $quer1=$this->db_do($q1);
2491
+ $prod->load($row['store_product_id']);
2492
+
2493
+ ###//get related product data (product id's and positions)
2494
+ ###$relatedData = array();
2495
+ ###foreach ($product->getRelatedLinkCollection() as $link) {
2496
+ ### $relatedData[$link->getLinkedProductId()]['position'] = $link->getPosition();
2497
+ ###}
2498
+ ###//manipulate $relatedData array
2499
+ ###// ...
2500
+ ###//set and save related product data
2501
+ ###$product->setRelatedLinkData($relatedData);
2502
+ ###$product->save();
2503
+ ###
2504
+ $i=1;
2505
+ while ($row1 = mysql_fetch_assoc($quer1)) {
2506
+ $param[$row1['store_related_product_id']]['position']=$i++;
2507
+
2508
+ }
2509
+ $prod->setRelatedLinkData($param);
2510
+ //here ... some other product operations and in the end
2511
+ $prod->save();
2512
+
2513
+ }
2514
+ */
2515
+ }
2516
+ #################################################################################################
2517
+ function addWeight(){
2518
+ // product short description for all web sites
2519
+ $result = $this->db_do("
2520
+ INSERT INTO catalog_product_entity_decimal (
2521
+ entity_type_id,
2522
+ attribute_id,
2523
+ store_id,
2524
+ entity_id,
2525
+ value
2526
+ )(
2527
+ SELECT
2528
+ " . $this->_getProductEntityTypeId(). ",
2529
+ " . $this->_getProductAttributeId('weight'). ",
2530
+ w.website,
2531
+ a.entity_id,
2532
+ 0
2533
+ FROM catalog_product_entity a
2534
+ INNER JOIN stINch_products b
2535
+ ON a.store_product_id = b.store_product_id
2536
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
2537
+ ON DUPLICATE KEY UPDATE
2538
+ value = 0
2539
+ ");
2540
+ // product short description for all web sites
2541
+ $result = $this->db_do("
2542
+ INSERT INTO catalog_product_entity_decimal (
2543
+ entity_type_id,
2544
+ attribute_id,
2545
+ store_id,
2546
+ entity_id,
2547
+ value
2548
+ )(
2549
+ SELECT
2550
+ " . $this->_getProductEntityTypeId(). ",
2551
+ " . $this->_getProductAttributeId('weight'). ",
2552
+ 0,
2553
+ a.entity_id,
2554
+ 0
2555
+ FROM catalog_product_entity a
2556
+ INNER JOIN stINch_products b
2557
+ ON a.store_product_id = b.store_product_id)
2558
+ ON DUPLICATE KEY UPDATE
2559
+ value = 0
2560
+
2561
+
2562
+ ");
2563
+
2564
+
2565
+ }
2566
+ #################################################################################################
2567
+ function replaceMagentoProductsStockPrice(){
2568
+ //Add stock
2569
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
2570
+ // $result = $this->db_do(" truncate cataloginventory_stock_item");
2571
+ $result = $this->db_do("DELETE csi from cataloginventory_stock_item csi LEFT JOIN catalog_product_entity cpe on csi.product_id=cpe.entity_id where cpe.entity_id is null");
2572
+ //set all sinch products stock=0 before upgrade (nedds for dayly stock&price import)
2573
+ $result = $this->db_do("UPDATE catalog_product_entity cpe join cataloginventory_stock_item csi on cpe.entity_id=csi.product_id set csi.qty=0, csi.is_in_stock=0 where cpe.store_product_id is not null");
2574
+ $result = $this->db_do("
2575
+ INSERT INTO cataloginventory_stock_item (
2576
+ product_id,
2577
+ stock_id,
2578
+ qty,
2579
+ is_in_stock,
2580
+ manage_stock
2581
+ )(
2582
+ SELECT
2583
+ a.entity_id,
2584
+ 1,
2585
+ b.stock,
2586
+ IF(b.stock > 0, 1, 0),
2587
+ 1
2588
+ FROM catalog_product_entity a
2589
+ INNER JOIN stock_and_prices_temp b on a.store_product_id=b.store_product_id )
2590
+ ON DUPLICATE KEY UPDATE
2591
+ qty=b.stock,
2592
+ is_in_stock = IF(b.stock > 0, 1, 0),
2593
+ manage_stock = 1
2594
+
2595
+
2596
+ ");
2597
+
2598
+
2599
+ $result = $this->db_do("
2600
+ DELETE FROM cataloginventory_stock_status
2601
+ ");
2602
+ $result = $this->db_do("
2603
+ INSERT INTO cataloginventory_stock_status (
2604
+ product_id,
2605
+ website_id,
2606
+ stock_id,
2607
+ qty,
2608
+ stock_status
2609
+ )(
2610
+ SELECT
2611
+ a.product_id,
2612
+ w.website_id,
2613
+ 1,
2614
+ a.qty,
2615
+ IF(qty > 0, 1, 0)
2616
+ FROM cataloginventory_stock_item a
2617
+ INNER JOIN catalog_product_entity b
2618
+ on a.product_id=b.entity_id
2619
+ INNER JOIN products_website_temp w
2620
+ on b.store_product_id=w.store_product_id
2621
+ )
2622
+ ON DUPLICATE KEY UPDATE
2623
+ qty=a.qty,
2624
+ stock_status = IF(a.qty > 0, 1, 0)
2625
+
2626
+ ");
2627
+
2628
+ //Add prices
2629
+ //$result = $this->db_do("truncate catalog_product_entity_decimal");
2630
+ $result = $this->db_do("DELETE cped from catalog_product_entity_decimal cped LEFT JOIN catalog_product_entity cpe on cped.entity_id=cpe.entity_id where cpe.entity_id is null");
2631
+ $result = $this->db_do("
2632
+ INSERT INTO catalog_product_entity_decimal (
2633
+ entity_type_id,
2634
+ attribute_id,
2635
+ store_id,
2636
+ entity_id,
2637
+ value
2638
+ )(
2639
+ SELECT
2640
+ " . $this->_getProductEntityTypeId(). ",
2641
+ " . $this->_getProductAttributeId('price'). ",
2642
+ w.website_id,
2643
+ a.entity_id,
2644
+ b.price
2645
+ FROM catalog_product_entity a
2646
+ INNER JOIN stock_and_prices_temp b on a.store_product_id=b.store_product_id
2647
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
2648
+ ON DUPLICATE KEY UPDATE
2649
+ value = b.price
2650
+
2651
+ ");
2652
+ $result = $this->db_do("
2653
+ INSERT INTO catalog_product_entity_decimal (
2654
+ entity_type_id,
2655
+ attribute_id,
2656
+ store_id,
2657
+ entity_id,
2658
+ value
2659
+ )(
2660
+ SELECT
2661
+ " . $this->_getProductEntityTypeId(). ",
2662
+ " . $this->_getProductAttributeId('price'). ",
2663
+ 0,
2664
+ a.entity_id,
2665
+ b.price
2666
+ FROM catalog_product_entity a
2667
+ INNER JOIN stock_and_prices_temp b on a.store_product_id=b.store_product_id)
2668
+ ON DUPLICATE KEY UPDATE
2669
+ value = b.price
2670
+ ");
2671
+ //Add cost
2672
+ // $result = $this->db_do("truncate catalog_product_entity_decimal");
2673
+ $result = $this->db_do("
2674
+ INSERT INTO catalog_product_entity_decimal (
2675
+ entity_type_id,
2676
+ attribute_id,
2677
+ store_id,
2678
+ entity_id,
2679
+ value
2680
+ )(
2681
+ SELECT
2682
+ " . $this->_getProductEntityTypeId(). ",
2683
+ " . $this->_getProductAttributeId('cost'). ",
2684
+ w.website_id,
2685
+ a.entity_id,
2686
+ b.cost
2687
+ FROM catalog_product_entity a
2688
+ INNER JOIN stock_and_prices_temp b on a.store_product_id=b.store_product_id
2689
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id)
2690
+ ON DUPLICATE KEY UPDATE
2691
+ value = b.cost
2692
+ ");
2693
+ $result = $this->db_do("
2694
+ INSERT INTO catalog_product_entity_decimal (
2695
+ entity_type_id,
2696
+ attribute_id,
2697
+ store_id,
2698
+ entity_id,
2699
+ value
2700
+ )(
2701
+ SELECT
2702
+ " . $this->_getProductEntityTypeId(). ",
2703
+ " . $this->_getProductAttributeId('cost'). ",
2704
+ 0,
2705
+ a.entity_id,
2706
+ b.cost
2707
+ FROM catalog_product_entity a
2708
+ INNER JOIN stock_and_prices_temp b on a.store_product_id=b.store_product_id)
2709
+ ON DUPLICATE KEY UPDATE
2710
+ value = b.cost
2711
+ ");
2712
+
2713
+
2714
+
2715
+ /* //Add stock attribute
2716
+ $result = $this->db_do("
2717
+ DELETE FROM catalog_product_entity_int
2718
+ WHERE attribute_id = ".$this->attributes['status']."
2719
+ ");
2720
+
2721
+ $result = $this->db_do("
2722
+ INSERT INTO catalog_product_entity_int (
2723
+ entity_type_id,
2724
+ attribute_id,
2725
+ store_id,
2726
+ entity_id,
2727
+ value
2728
+ )(
2729
+ SELECT 4, ".$this->attributes['status'].", 0, a.product_id, a.stock_status
2730
+ FROM cataloginventory_stock_status a)
2731
+ ");
2732
+ */
2733
+ //make products enable in FO
2734
+ // $result = $this->db_do(" truncate catalog_product_index_price");
2735
+ $result = $this->db_do("DELETE cpip from catalog_product_index_price cpip LEFT JOIN catalog_product_entity cpe on cpip.entity_id=cpe.entity_id where cpe.entity_id is null");
2736
+ $q="select customer_group_id from customer_group";
2737
+ $quer=$this->db_do($q);
2738
+ while ($row = mysql_fetch_assoc($quer)) {
2739
+ $result = $this->db_do("
2740
+ insert into catalog_product_index_price (
2741
+ entity_id,
2742
+ customer_group_id,
2743
+ website_id,
2744
+ tax_class_id,
2745
+ price,
2746
+ final_price,
2747
+ min_price,
2748
+ max_price
2749
+ )(select
2750
+ a.entity_id,
2751
+ ".$row['customer_group_id'].",
2752
+ w.website_id,
2753
+ 2,
2754
+ b.price ,
2755
+ b.price ,
2756
+ b.price ,
2757
+ b.price
2758
+ FROM catalog_product_entity a
2759
+ INNER JOIN stock_and_prices_temp b on a.store_product_id=b.store_product_id
2760
+ INNER JOIN products_website_temp w on a.store_product_id=w.store_product_id
2761
+ )
2762
+ ON DUPLICATE KEY UPDATE
2763
+ tax_class_id = 2,
2764
+ price = b.price,
2765
+ final_price = b.price,
2766
+ min_price = b.price,
2767
+ max_price = b.price
2768
+ ");
2769
+ }
2770
+ }
2771
+
2772
+
2773
+
2774
+ #################################################################################################
2775
+
2776
+ function getProductDescription($entity_id){
2777
+
2778
+ $this->loadProductParams($entity_id);
2779
+ $this->loadProductStarfeatures($entity_id);
2780
+ $this->loadGalleryPhotos($entity_id);
2781
+ Varien_Profiler::start('Bintime FILE RELATED');
2782
+ $this->loadRelatedProducts($entity_id);
2783
+ Varien_Profiler::stop('Bintime FILE RELATED');
2784
+
2785
+ return true;
2786
+ }
2787
+ #################################################################################################
2788
+
2789
+ public function getProductName(){
2790
+ return $this->productName;
2791
+ }
2792
+ #################################################################################################
2793
+
2794
+ public function getProductDescriptionList(){
2795
+ return $this->productDescriptionList;
2796
+ }
2797
+ #################################################################################################
2798
+
2799
+ public function getProductSpecifications(){
2800
+ return $this->specifications;
2801
+ }
2802
+ #################################################################################################
2803
+
2804
+ public function getShortProductDescription(){
2805
+ return $this->productDescription;
2806
+ }
2807
+ #################################################################################################
2808
+
2809
+ public function getFullProductDescription(){
2810
+ return $this->fullProductDescription;
2811
+ }
2812
+ #################################################################################################
2813
+
2814
+ public function getLowPicUrl(){
2815
+ return $this->highPicUrl;
2816
+ }
2817
+ #################################################################################################
2818
+
2819
+ public function getRelatedProducts(){
2820
+ return $this->relatedProducts;
2821
+ }
2822
+ #################################################################################################
2823
+
2824
+ public function getVendor(){
2825
+ return $this->vendor;
2826
+ }
2827
+ #################################################################################################
2828
+
2829
+ public function getMPN(){
2830
+ return $this->productId;
2831
+ }
2832
+ #################################################################################################
2833
+
2834
+ public function getEAN(){
2835
+ return $this->EAN;
2836
+ }
2837
+ ################################################################################################
2838
+
2839
+ public function getGalleryPhotos(){
2840
+ return $this->galleryPhotos;
2841
+ }
2842
+
2843
+ #################################################################################################
2844
+
2845
+ private function loadProductParams($entity_id){
2846
+ $store_product_id=$this->getStoreProductIdByEntity($entity_id);
2847
+ if(!$store_product_id){
2848
+ // echo "AAAAAAA"; exit;
2849
+ return;
2850
+ }
2851
+ $q="select sinch_product_id, product_sku, product_name, sinch_manufacturer_id, store_category_id, main_image_url, thumb_image_url, medium_image_url, specifications, description, specifications from stINch_products where store_product_id =".$store_product_id;
2852
+ $quer=$this->db_do($q);
2853
+ $product=mysql_fetch_array($quer);
2854
+
2855
+ $this->productDescription = (string) substr($product['description'],50,0);
2856
+ $this->fullProductDescription = (string)$product['description'];
2857
+ $this->lowPicUrl = (string)$product["medium_image_url"];//thumb_image_url"];
2858
+ $this->highPicUrl = (string)$product["main_image_url"];
2859
+ $this->productName = (string)$product["product_name"];
2860
+ $this->productId = (string)$product['product_sku'];
2861
+ $this->specifications = (string)$product['specifications'];
2862
+ $this->sinchProductId = (string)$product['sinch_product_id'];
2863
+ if($product['sinch_manufacturer_id']){
2864
+ $q="select manufacturer_name from stINch_manufacturers where sinch_manufacturer_id=".$product['sinch_manufacturer_id'];
2865
+ $quer=$this->db_do($q);
2866
+ $manufacturer=mysql_fetch_array($quer);
2867
+ $this->vendor = (string)$manufacturer['manufacturer_name'];
2868
+ }
2869
+ $q="select distinct ean_code FROM stINch_ean_codes sec join stINch_products sp on sec.product_id=sp.sinch_product_id where sp.store_product_id=".$store_product_id;
2870
+ $quer=$this->db_do($q);
2871
+ while ($row=mysql_fetch_array($quer)){
2872
+ $EANarr[]=$row['ean_code'];
2873
+ }
2874
+ // $prodEAN = $productTag->EANCode;
2875
+ $EANstr='';
2876
+ /* $EANarr=null;
2877
+ foreach($prodEAN as $ellEAN){
2878
+ $EANarr[]=$ellEAN['EAN'];
2879
+ }
2880
+ */
2881
+ $EANstr=implode(", ",$EANarr);
2882
+ $this->EAN = (string)$EANstr;//$productTag->EANCode['EAN'];
2883
+ }
2884
+ #################################################################################################
2885
+
2886
+ private function loadProductStarfeatures($entity_id){
2887
+ $descriptionArray=array();
2888
+ $product_info_features = $this->db_do("
2889
+ SELECT c.feature_name AS name, b.text AS value
2890
+ FROM stINch_product_features a
2891
+ INNER JOIN stINch_restricted_values b ON a.restricted_value_id = b.restricted_value_id
2892
+ INNER JOIN stINch_categories_features c ON b.category_feature_id = c.category_feature_id
2893
+ WHERE a.sinch_product_id = '" .$this->sinchProductId . "'" );
2894
+ while ($features = mysql_fetch_array($product_info_features)) {
2895
+ $descriptionArray[$features['name']] = $features['value'];
2896
+ }
2897
+
2898
+
2899
+ $this->productDescriptionList = $descriptionArray;
2900
+ }
2901
+ #################################################################################################
2902
+
2903
+ private function loadRelatedProducts($entity_id){
2904
+ $this->sinchProductId;
2905
+ if(!$this->sinchProductId){
2906
+ return;
2907
+ }
2908
+ $q="select st_prod.sinch_product_id, st_prod.product_sku, st_prod.product_name, st_prod.sinch_manufacturer_id, st_prod.store_category_id, st_prod.main_image_url, st_prod.thumb_image_url, st_prod.medium_image_url, st_prod.specifications, st_prod.description, st_prod.specifications, st_manuf.manufacturer_name, st_manuf.manufacturers_image from stINch_related_products st_rel_prod join stINch_products st_prod on st_rel_prod.related_sinch_product_id=st_prod.sinch_product_id join stINch_manufacturers st_manuf on st_prod.sinch_manufacturer_id=st_manuf.sinch_manufacturer_id where st_rel_prod.sinch_product_id=".$this->sinchProductId;
2909
+
2910
+ // echo $q;
2911
+ $quer=$this->db_do($q);
2912
+ while($row=mysql_fetch_array($quer)){
2913
+
2914
+ $productArray = array();
2915
+ $productArray['name'] = (string)$row['product_name'];
2916
+ $productArray['thumb'] = (string)$row['thumb_image_url'];
2917
+ $mpn = (string)$row['product_sku'];
2918
+ $productSupplierId = (int)$row['sinch_manufacturer_id'];
2919
+ $productArray['supplier_thumb'] = (string)($row['manufacturers_image']);
2920
+ $productArray['supplier_name'] = (string)$row['manufacturer_name'];
2921
+
2922
+ $this->relatedProducts[$mpn] = $productArray;
2923
+ }
2924
+ }
2925
+ #################################################################################################
2926
+ /**
2927
+ * load Gallery array from XML
2928
+ */
2929
+ public function loadGalleryPhotos($entity_id){
2930
+ /*$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
2931
+ if (!count($galleryPhotos)){
2932
+ return false;
2933
+ }
2934
+ */
2935
+ $store_product_id=$this->getStoreProductIdByEntity($entity_id);
2936
+ if(!$store_product_id){
2937
+ return;
2938
+ }
2939
+ $q=$this->db_do("select count(*) as cnt from stINch_products_pictures_gallery where store_product_id=".$store_product_id);
2940
+ $res=mysql_fetch_array($q);
2941
+ if(!$res || !$res['cnt']){
2942
+ return false;
2943
+ }
2944
+ $q="select image_url as Pic, thumb_image_url as ThumbPic from stINch_products_pictures_gallery where store_product_id=".$store_product_id;
2945
+ $res=$this->db_do($q);
2946
+
2947
+ while($photo=mysql_fetch_array($res)){
2948
+ $picHeight = (int)500;//$photo["PicHeight"];
2949
+ $picWidth = (int)500;//$photo["PicWidth"];
2950
+ $thumbUrl = (string)$photo["ThumbPic"];
2951
+ $picUrl = (string)$photo["Pic"];
2952
+
2953
+ array_push($this->galleryPhotos, array(
2954
+ 'height' => $picHeight,
2955
+ 'width' => $picWidth,
2956
+ 'thumb' => $thumbUrl,
2957
+ 'pic' => $picUrl
2958
+ ));
2959
+ }
2960
+ }
2961
+ #################################################################################################
2962
+ public function reloadProductImage($entity_id){
2963
+ $result = $this->db_do("
2964
+ INSERT INTO catalog_product_entity_varchar (
2965
+ entity_type_id,
2966
+ attribute_id,
2967
+ store_id,
2968
+ entity_id,
2969
+ value
2970
+ )
2971
+ SELECT
2972
+ " . $this->_getProductEntityTypeId(). ",
2973
+ " . $this->_getProductAttributeId('image'). ",
2974
+ w.store_id,
2975
+ a.entity_id,
2976
+ b.main_image_url
2977
+ FROM catalog_product_entity a
2978
+ INNER JOIN core_store w
2979
+ INNER JOIN stINch_products b
2980
+ ON a.store_product_id = b.store_product_id
2981
+ where a.entity_id=$entity_id
2982
+ ON DUPLICATE KEY UPDATE
2983
+ value = b.main_image_url
2984
+ ");
2985
+
2986
+
2987
+ // image for specific web sites
2988
+ $result = $this->db_do("
2989
+ INSERT INTO catalog_product_entity_varchar (
2990
+ entity_type_id,
2991
+ attribute_id,
2992
+ store_id,
2993
+ entity_id,
2994
+ value
2995
+ )
2996
+ SELECT
2997
+ " . $this->_getProductEntityTypeId(). ",
2998
+ " . $this->_getProductAttributeId('image'). ",
2999
+ 0,
3000
+ a.entity_id,
3001
+ b.main_image_url
3002
+ FROM catalog_product_entity a
3003
+ INNER JOIN stINch_products b
3004
+ ON a.store_product_id = b.store_product_id
3005
+ where a.entity_id=$entity_id
3006
+ ON DUPLICATE KEY UPDATE
3007
+ value = b.main_image_url
3008
+
3009
+
3010
+ ");
3011
+
3012
+
3013
+ // small_image for specific web sites
3014
+ $result = $this->db_do("
3015
+ INSERT INTO catalog_product_entity_varchar (
3016
+ entity_type_id,
3017
+ attribute_id,
3018
+ store_id,
3019
+ entity_id,
3020
+ value
3021
+ )
3022
+ SELECT
3023
+ " . $this->_getProductEntityTypeId(). ",
3024
+ " . $this->_getProductAttributeId('small_image'). ",
3025
+ w.store_id,
3026
+ a.entity_id,
3027
+ b.main_image_url
3028
+ FROM catalog_product_entity a
3029
+ INNER JOIN core_store w
3030
+ INNER JOIN stINch_products b
3031
+ ON a.store_product_id = b.store_product_id
3032
+ where a.entity_id=$entity_id
3033
+ ON DUPLICATE KEY UPDATE
3034
+ value = b.main_image_url
3035
+ ");
3036
+
3037
+
3038
+ // small_image for all web sites
3039
+ $result = $this->db_do("
3040
+ INSERT INTO catalog_product_entity_varchar (
3041
+ entity_type_id,
3042
+ attribute_id,
3043
+ store_id,
3044
+ entity_id,
3045
+ value
3046
+ )
3047
+ SELECT
3048
+ " . $this->_getProductEntityTypeId(). ",
3049
+ " . $this->_getProductAttributeId('small_image'). ",
3050
+ 0,
3051
+ a.entity_id,
3052
+ b.main_image_url
3053
+ FROM catalog_product_entity a
3054
+ INNER JOIN core_store w
3055
+ INNER JOIN stINch_products b
3056
+ ON a.store_product_id = b.store_product_id
3057
+ where a.entity_id=$entity_id
3058
+ ON DUPLICATE KEY UPDATE
3059
+ value = b.main_image_url
3060
+ ");
3061
+ }
3062
+ #################################################################################################
3063
+ public function runIndexer(){
3064
+ exec(PHP_RUN_STRING.$this->shellDir.'indexer.php reindexall');
3065
+ }
3066
+ #################################################################################################
3067
+ public function runStockPriceIndexer(){
3068
+ exec(PHP_RUN_STRING.$this->shellDir.'indexer.php --reindex catalog_product_price,cataloginventory_stock');
3069
+ }
3070
+ #################################################################################################
3071
+ private function getStoreProductIdByEntity($entity_id){
3072
+ $q=$this->db_do("select store_product_id from stINch_products_mapping where entity_id=".$entity_id);
3073
+ $res=mysql_fetch_array($q);
3074
+ // echo $entity_id."AAAA".$res['store_product_id']; exit;
3075
+ return ($res['store_product_id']);
3076
+ }
3077
+ #################################################################################################
3078
+
3079
+ private function db_connect() {
3080
+
3081
+ // $connection = Mage::getModel('core/resource')->getConnection('core_write');
3082
+ $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
3083
+
3084
+ if ($this->db = mysql_connect($dbConf->host, $dbConf->username, $dbConf->password, true, 128)) {
3085
+ if(mysql_select_db($dbConf->dbname)){
3086
+ $this->_LOG("Connected..");
3087
+ }else{
3088
+ die("Can't select the database: " . mysql_error());
3089
+ }
3090
+ }else{
3091
+ die("Could not connect: " . mysql_error());
3092
+
3093
+ }
3094
+
3095
+ }
3096
+ #################################################################################################
3097
+
3098
+ private function db_do($query) {
3099
+ if($this->debug_mode){
3100
+ // $this->_LOG("Query: " . $query);
3101
+ Mage::log("Query: " . $query, null, $this->_logFile);
3102
+ }
3103
+ // $result = $this->this->db_do($query);//
3104
+ // $query=mysql_real_escape_string($query);
3105
+ $result = mysql_query($query) or die("Query failed: " . mysql_error());
3106
+ if (!$result) {
3107
+ throw new Exception("Invalid query: $sql\n" . mysql_error());
3108
+ } else {
3109
+ return $result;
3110
+ }
3111
+
3112
+ return $result;
3113
+ }
3114
+ ##################################################################################################
3115
+ function table_rows_count($table){
3116
+ $rows_count_res=$this->db_do("select count(*) as cnt from ".$table);
3117
+ $rows_count=mysql_fetch_array($rows_count_res);
3118
+ return ($rows_count['cnt']);
3119
+ }
3120
+ ##################################################################################################
3121
+ function file_strings_count($parse_file){
3122
+ $files_str=count(file($parse_file));
3123
+ return $files_str;
3124
+ }
3125
+ ##################################################################################################
3126
+ function check_loaded_data($file, $table){
3127
+ $cnt_strings_in_file=$this->file_strings_count($file);
3128
+ $cnt_rows_int_table=$this->table_rows_count($table);
3129
+ $persent_cnt_strings_in_file=$cnt_strings_in_file / 10;
3130
+ if($cnt_rows_int_table > $persent_cnt_strings_in_file){
3131
+ return true;
3132
+ }else{
3133
+ return false;
3134
+ }
3135
+ }
3136
+ ##################################################################################################
3137
+
3138
+
3139
+ function valid_utf($string,$new_line = true){
3140
+ /* if($new_line == true){
3141
+ $string = preg_replace('/\\\n/',"\n",$string);
3142
+ }
3143
+ */
3144
+ $string = preg_replace('/™/','&#8482;',$string);
3145
+ $string = preg_replace("/®/",'&reg;',$string);
3146
+ $string = preg_replace("/≈/",'&asymp;',$string);
3147
+ $string = preg_replace("/".chr(226).chr(128).chr(157)."/",'&quot;',$string);
3148
+ $string = preg_replace("/".chr(226).chr(128).chr(153)."/",'&prime;',$string);
3149
+ $string = preg_replace("/°/",'&deg;',$string);
3150
+ $string = preg_replace("/±/",'&plusmn;',$string);
3151
+ $string = preg_replace("/µ/",'&micro;',$string);
3152
+ $string = preg_replace("/²/",'&sup2;',$string);
3153
+ $string = preg_replace("/³/",'&sup3;',$string);
3154
+ $string = preg_replace('/\xe2\x80\x93/','-',$string);
3155
+ $string = preg_replace('/\xe2\x80\x99/','\'',$string);
3156
+ $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
3157
+ $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
3158
+
3159
+ return utf8_decode($string);
3160
+
3161
+ // return $string;
3162
+ }
3163
+
3164
+ #################################################################################################
3165
+ function dropHTMLentities($entity_type_id, $attribute_id){
3166
+ // product name for all web sites
3167
+ $result = $this->db_do("
3168
+ SELECT value, entity_id from catalog_product_entity_varchar where entity_type_id=".$entity_type_id."
3169
+ and attribute_id=".$attribute_id
3170
+ );
3171
+ while($row=mysql_fetch_array($result)){
3172
+ $value=$this->valid_char($row['value']);
3173
+ if($value!='' and $value!=$row['value']){
3174
+ $this->db_do("UPDATE catalog_product_entity_varchar set value='".mysql_real_escape_string($value)."' where entity_id=".$row['entity_id']." and entity_type_id=".$entity_type_id." and attribute_id=".$attribute_id);
3175
+ }
3176
+
3177
+ }
3178
+ }
3179
+
3180
+ #################################################################################################
3181
+
3182
+ function valid_char($string){
3183
+ $string = preg_replace('/&#8482;/', ' ',$string);
3184
+ $string = preg_replace('/&reg;/', ' ',$string);
3185
+ $string = preg_replace('/&asymp;/', ' ',$string);
3186
+ $string = preg_replace('/&quot;/', ' ',$string);
3187
+ $string = preg_replace('/&prime;/', ' ',$string);
3188
+ $string = preg_replace('/&deg;/', ' ',$string);
3189
+ $string = preg_replace('/&plusmn;/', ' ',$string);
3190
+ $string = preg_replace('/&micro;/', ' ',$string);
3191
+ $string = preg_replace('/&sup2;/', ' ',$string);
3192
+ $string = preg_replace('/&sup3;/', ' ',$string);
3193
+ // $string = preg_replace('/\xe2\x80\x93/','-',$string);
3194
+ // $string = preg_replace('/\xe2\x80\x99/','\'',$string);
3195
+ // $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
3196
+ // $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
3197
+
3198
+ // return utf8_decode($string);
3199
+
3200
+ return $string;
3201
+ }
3202
+
3203
+ #################################################################################################
3204
+
3205
+ function _LOG($log){
3206
+
3207
+ if($log){
3208
+ // $q="insert into ".$this->import_log_table." (message_date, message) values(now(), '".$log."')";
3209
+ // $this->db_do($q);
3210
+ Mage::log($log, null, $this->_logFile);
3211
+ // list($usec, $sec) = explode(" ", microtime());
3212
+ // $time = ((float)$usec + (float)$sec);
3213
+ /* $time = date("D M j G:i:s T Y");
3214
+
3215
+ if($_SERVER['REMOTE_ADDR']){
3216
+ $log = "[".getmypid()."] "."[".$_SERVER['REMOTE_ADDR']."] "."[".$time."] ".$log."\n";
3217
+ error_log($log,3,LOG_FILE);
3218
+ }else{
3219
+ $log = "[".getmypid()."] "."[".$time."] ".$log."\n";
3220
+ error_log($log,3,LOG_FILE . ".cli");
3221
+ */
3222
+ }
3223
+ }
3224
+
3225
+ #################################################################################################
3226
+
3227
+ function wget(){
3228
+
3229
+ $got = func_num_args();
3230
+ $url = $file = $flag = false;
3231
+
3232
+ if($got<1){
3233
+ return false;
3234
+ }elseif($got == 1){
3235
+ $url = func_get_arg(0);
3236
+ }elseif($got == 2){
3237
+ $url = func_get_arg(0);
3238
+ $file= func_get_arg(1);
3239
+ }elseif($got == 3){
3240
+ $url = func_get_arg(0);
3241
+ $file= func_get_arg(1);
3242
+ $flag= func_get_arg(2);
3243
+ }
3244
+
3245
+ if($flag == 'copy'){
3246
+ if(copy($url,$file)){
3247
+ return true;
3248
+ }else{
3249
+ return false;
3250
+ }
3251
+ }elseif($flag == 'system'){
3252
+ exec("wget -O$file $url");
3253
+ return true;
3254
+ }else{
3255
+ $c=curl_init($url);
3256
+ curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
3257
+ curl_setopt($c,CURLOPT_FOLLOWLOCATION,1);
3258
+ curl_setopt($c,CURLOPT_HEADER,array("Accept-Encoding: gzip"));
3259
+ if(!$file){
3260
+ $page = curl_exec($c);
3261
+ curl_close($c);
3262
+ return $page;
3263
+ }else{
3264
+ $FH = fopen($file,"wb");// or echo"Can't open for writing ".$file;
3265
+ fwrite($FH,curl_exec($c));
3266
+ fclose($FH);
3267
+ curl_close($c);
3268
+ return true;
3269
+ }
3270
+ }
3271
+ }
3272
+ #################################################################################################
3273
+ /**
3274
+ * Create the import directory Hierarchy
3275
+ * @return false if directory already exists
3276
+ */
3277
+ public function createTemporaryImportDerictory(){
3278
+ $dirArray = explode('/', $this->varDir);
3279
+ end($dirArray);
3280
+ // $this->_LOG('before :'.$this->varDir);
3281
+ if (prev($dirArray)=='bintime'){
3282
+ return false;
3283
+ }
3284
+
3285
+
3286
+ $this->varDir = $this->varDir . 'bintime/sinchimport/';
3287
+ if (!is_dir($this->varDir)) {
3288
+ mkdir($this->varDir,0777,true);
3289
+ }
3290
+ // $this->_LOG('after :'.$this->varDir);
3291
+ }
3292
+ #################################################################################################
3293
+
3294
+ function count_children($id){
3295
+
3296
+ $q="select store_category_id from ".TABLE_SINCH_CAT." where parent_store_category_id=".$id;
3297
+ $quer=$this->db_do($q);
3298
+ $count=0;
3299
+ while ($row=mysql_fetch_array($quer)){
3300
+ $count+=$this->count_children($row['store_category_id']);
3301
+ $count++;
3302
+ }
3303
+ return ($count);
3304
+ }
3305
+ #################################################################################################
3306
+ private function delete_old_sinch_categories_from_shop(){
3307
+
3308
+ $q="Delete cat from ".TABLE_CATEGORY_ENTITY_VARCHAR." cat join stINch_categories_mapping scm on cat.entity_id=scm.shop_entity_id where (scm.shop_store_category_id is not null) and (scm.store_category_id is null)";
3309
+ $this->db_do($q);
3310
+
3311
+ $q="Delete cat from ".TABLE_CATEGORY_ENTITY_INT." cat join stINch_categories_mapping scm on cat.entity_id=scm.shop_entity_id where (scm.shop_store_category_id is not null) and (scm.store_category_id is null)";
3312
+ $this->db_do($q);
3313
+
3314
+ $q="Delete cat from ".TABLE_CATEGORY_ENTITY." cat join stINch_categories_mapping scm on cat.entity_id=scm.shop_entity_id where (scm.shop_store_category_id is not null) and (scm.store_category_id is null)";
3315
+ $this->db_do($q);
3316
+
3317
+ }
3318
+ #################################################################################################
3319
+
3320
+ function culc_path($parent_id, $ent_id){
3321
+ /* $q="select path from ".TABLE_CATEGORY_ENTITY." where entity_id=".$parent_id;
3322
+ $quer=$this->db_do($q);
3323
+ $row=mysql_fetch_array($quer);
3324
+ if($row['path']){
3325
+ return($row['path'].'/'.$ent_id);
3326
+ }else{
3327
+ return($ent_id);
3328
+ }
3329
+ */
3330
+ $path='';
3331
+ $cat_id=$parent_id;
3332
+ $q="select parent_id from ".TABLE_CATEGORY_ENTITY." where entity_id=".$cat_id;
3333
+ $quer=$this->db_do($q);
3334
+ $row=mysql_fetch_array($quer);
3335
+ while($row['parent_id']){
3336
+ $path=$row['parent_id'].'/'.$path;
3337
+ $q="select parent_id from ".TABLE_CATEGORY_ENTITY." where entity_id=".$row['parent_id'];
3338
+ $quer=$this->db_do($q);
3339
+ $row=mysql_fetch_array($quer);
3340
+
3341
+ }
3342
+ if($cat_id){
3343
+ $path.=$cat_id."/";
3344
+ }
3345
+
3346
+ if($path){
3347
+ return($path.$ent_id);
3348
+ }else{
3349
+ return($ent_id);
3350
+ }
3351
+
3352
+ }
3353
+ #################################################################################################
3354
+
3355
+ function get_category_level($id){
3356
+ $q="select parent_store_category_id from ".TABLE_SINCH_CAT." where store_category_id=".$id;
3357
+ $quer=$this->db_do($q);
3358
+ $level=1;
3359
+ $row=mysql_fetch_array($quer);
3360
+ while ($row['parent_store_category_id']!=0){
3361
+ $q="select parent_store_category_id from ".TABLE_SINCH_CAT." where store_category_id=".$row['parent_store_category_id'];
3362
+ $quer=$this->db_do($q);
3363
+ $row=mysql_fetch_array($quer);
3364
+ $level++;
3365
+ if($level>20){
3366
+ break;
3367
+ }
3368
+ }
3369
+
3370
+ return($level);
3371
+ }
3372
+ #################################################################################################
3373
+
3374
+ function InitImportStatuses($type){
3375
+ $this->db_do("DROP TABLE IF EXISTS ".$this->import_status_table);
3376
+ $this->db_do("CREATE TABLE ".$this->import_status_table."(
3377
+ id int(11) NOT NULL auto_increment PRIMARY KEY,
3378
+ message varchar(50),
3379
+ finished int(1) default 0
3380
+ )"
3381
+ );
3382
+ $this->db_do("INSERT INTO ".$this->import_status_statistic_table." (start_import, finish_import, import_type, global_status_import, error_report_message) values(now(), null, '$type', 'Run', '')");
3383
+ $q="select max(id) as id from ".$this->import_status_statistic_table;
3384
+
3385
+ $quer=$this->db_do($q);
3386
+ $row=mysql_fetch_array($quer);
3387
+ $this->current_import_status_statistic_id=$row['id'];
3388
+ $this->db_do("update ".$this->import_status_statistic_table." set global_status_import='Failed' where global_status_import='Run' and id!=".$this->current_import_status_statistic_id);
3389
+
3390
+ }
3391
+ #################################################################################################
3392
+ function set_imports_failed(){
3393
+ $this->db_do("update ".$this->import_status_statistic_table." set global_status_import='Failed' where global_status_import='Run'");
3394
+ }
3395
+ #################################################################################################
3396
+ function set_import_error_reporting_message($message){
3397
+ $this->db_do("update ".$this->import_status_statistic_table." set error_report_message='".mysql_real_escape_string($message)."' where id=".$this->current_import_status_statistic_id);
3398
+ }
3399
+ #################################################################################################
3400
+ function getImportStatusHistory(){
3401
+ $res="select count(*) from ".$this->import_status_statistic_table;
3402
+ $cnt_arr=mysql_fetch_array($this->db_do($res));
3403
+ $cnt=$cnt_arr[0];
3404
+ if($cnt>0){
3405
+ $a=(($cnt>7)? ($cnt-7): 0);
3406
+ $b=$cnt;
3407
+ $q="select id, start_import, finish_import, import_type, number_of_products, global_status_import, detail_status_import from ".$this->import_status_statistic_table." order by start_import limit ".$a.", ".$b;
3408
+ $result=$this->db_do($q);
3409
+ while($row=mysql_fetch_array($result)){
3410
+ $StatusHistory_arr[]=$row;
3411
+ }
3412
+ }
3413
+ return $StatusHistory_arr;
3414
+ }
3415
+ #################################################################################################
3416
+ function getDateOfLatestSuccessImport(){
3417
+ $q="select start_import, finish_import from ".$this->import_status_statistic_table." where global_status_import='Successful' order by id desc limit 1";
3418
+ $imp_date=mysql_fetch_array($this->db_do($q));
3419
+ return $imp_date['start_import'];
3420
+ }
3421
+ #################################################################################################
3422
+ function getDataOfLatestImport(){
3423
+ $q="select start_import, finish_import, import_type, number_of_products, global_status_import, detail_status_import, number_of_products, error_report_message from ".$this->import_status_statistic_table." order by id desc limit 1";
3424
+ $imp_status=mysql_fetch_array($this->db_do($q));
3425
+ return $imp_status;
3426
+ }
3427
+
3428
+ #################################################################################################
3429
+ function addImportStatus($message, $finished=0){
3430
+ $q="insert into ".$this->import_status_table." (message, finished) values('".$message."', $finished)";
3431
+ $this->db_do($q);
3432
+ $this->db_do("update ".$this->import_status_statistic_table." set detail_status_import='".$message."' where id=".$this->current_import_status_statistic_id);
3433
+ if($finished==1){
3434
+ $this->db_do("update ".$this->import_status_statistic_table." set global_status_import='Successful', finish_import=now() where error_report_message='' and id=".$this->current_import_status_statistic_id);
3435
+ }
3436
+ }
3437
+ #################################################################################################
3438
+
3439
+ function getImportStatuses(){
3440
+ $q="select id, message, finished from ".$this->import_status_table." order by id limit 1";
3441
+ $quer=$this->db_do($q);
3442
+ if($row=mysql_fetch_array($quer)){
3443
+ $messages=array('message'=>$row['message'], 'id'=>$row['id'], 'finished'=>$row['finished']);
3444
+ $id=$row['id'];
3445
+ }
3446
+ if($id){
3447
+ $q="delete from ".$this->import_status_table." where id=".$id;
3448
+ $this->db_do($q);
3449
+ }
3450
+ return $messages;
3451
+ }
3452
+ #################################################################################################
3453
+
3454
+ private function _getEntityTypeId($code) {
3455
+ $sql = "
3456
+ SELECT entity_type_id
3457
+ FROM eav_entity_type
3458
+ WHERE entity_type_code = '".$code."'
3459
+ LIMIT 1
3460
+ ";
3461
+ $result = $this->db_do($sql);
3462
+ if ($row = mysql_fetch_assoc($result)) {
3463
+ return $row['entity_type_id'];
3464
+ }
3465
+ return false;
3466
+ }
3467
+ #################################################################################################
3468
+
3469
+ private function _getProductEntityTypeId(){
3470
+ if (!$this->_productEntityTypeId) {
3471
+ $this->_productEntityTypeId = $this->_getEntityTypeId('catalog_product');
3472
+ }
3473
+ return $this->_productEntityTypeId;
3474
+ }
3475
+ #################################################################################
3476
+
3477
+ private function _getProductDefaulAttributeSetId(){
3478
+ if (!$this->defaultAttributeSetId) {
3479
+ $sql = "
3480
+ SELECT entity_type_id, default_attribute_set_id
3481
+ FROM eav_entity_type
3482
+ WHERE entity_type_code = 'catalog_product'
3483
+ LIMIT 1
3484
+ ";
3485
+ $result = $this->db_do($sql);
3486
+ if ($row = mysql_fetch_assoc($result)) {
3487
+
3488
+ $this->defaultAttributeSetId = $row['default_attribute_set_id'];
3489
+ }
3490
+ }
3491
+ return $this->defaultAttributeSetId;
3492
+ }
3493
+ #################################################################################################
3494
+
3495
+ private function _getCategoryEntityTypeIdAndDefault_attribute_set_id(){
3496
+ if (!$this->_categoryEntityTypeId || !$this->_categoryDefault_attribute_set_id) {
3497
+ $sql = "
3498
+ SELECT entity_type_id, default_attribute_set_id
3499
+ FROM eav_entity_type
3500
+ WHERE entity_type_code = 'catalog_category'
3501
+ LIMIT 1
3502
+ ";
3503
+ $result = $this->db_do($sql);
3504
+ if ($row = mysql_fetch_assoc($result)) {
3505
+ $this->_categoryEntityTypeId = $row['entity_type_id'];
3506
+ $this->_categoryDefault_attribute_set_id = $row['default_attribute_set_id'];
3507
+ }
3508
+
3509
+ }
3510
+ }
3511
+ ##################################################################################################
3512
+
3513
+ private function _getAttributeId($attributeCode,$typeCode)
3514
+ {
3515
+ if ($typeCode=='catalog_product') {
3516
+ $typeId = $this->_getProductEntityTypeId();
3517
+ }
3518
+ else {
3519
+ $typeId = $this->_getEntityTypeId($typeCode);
3520
+ }
3521
+ if (!isset($this->_attributeId[$typeCode]) OR !is_array($this->_attributeId[$typeCode])) {
3522
+ $sql = "
3523
+ SELECT attribute_id, attribute_code
3524
+ FROM eav_attribute
3525
+ WHERE entity_type_id = '" . $typeId . "'
3526
+ ";
3527
+ $result = $this->db_do($sql);
3528
+ while ($row = mysql_fetch_assoc($result)) {
3529
+ $this->_attributeId[$typeCode][$row['attribute_code']] = $row['attribute_id'];
3530
+ }
3531
+ }
3532
+ // echo 'attribute code: '.$attributeCode.','.$typeCode.' => '.$this->_attributeId[$typeCode][$attributeCode].PHP_EOL;
3533
+ return $this->_attributeId[$typeCode][$attributeCode];
3534
+ }
3535
+ ##################################################################################################
3536
+
3537
+ private function repl_ph($content,$hash){
3538
+ if($hash){
3539
+ foreach($hash as $key => $val){
3540
+ if ($key=="category_name") {
3541
+ if (strlen($val)>25) { $val = substr($val,0,24)."..."; }
3542
+ }
3543
+ $content = preg_replace("/%%%$key%%%/",$val,$content);
3544
+ }
3545
+ }
3546
+ return $content;
3547
+ }
3548
+ ##################################################################################################
3549
+
3550
+ private function _getProductAttributeId($attributeCode) {
3551
+ return $this->_getAttributeId($attributeCode,'catalog_product');
3552
+ }
3553
+ ##################################################################################################
3554
+
3555
+ private function _getCategoryAttributeId($attributeCode) {
3556
+ return $this->_getAttributeId($attributeCode,'catalog_category');
3557
+ }
3558
+ ##################################################################################################
3559
+ private function _getShopRootCategoryId($cat_id=0){
3560
+ $q="select entity_id from catalog_category_entity_varchar where value='default-category'";
3561
+ $res=$this->db_do($q);
3562
+ $row=mysql_fetch_array($quer);
3563
+ if($row['entity_id']>0){
3564
+ return $row['entity_id'];
3565
+ }else{
3566
+ $q="select entity_id from catalog_category_entity where parent_id=".$cat_id;
3567
+ $quer=$this->db_do($q);
3568
+ $count=0;
3569
+ while ($row=mysql_fetch_array($quer)){
3570
+ $count++;
3571
+ $entity_id=$row['entity_id'];
3572
+ }
3573
+ if($count>1 || $count==0){
3574
+ return ($cat_id);
3575
+ }else{
3576
+ return $this->_getShopRootCategoryId($entity_id);
3577
+ }
3578
+ }
3579
+ }
3580
+ ##################################################################################################
3581
+
3582
+ }
3583
+
3584
+ ?>
app/code/local/Bintime/Sinchimport/Model/System/Config/CatRewrite.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class provides data for Magento BO
4
+ * @author Sergey Stepanchuk <info@bintime.com>
5
+ *
6
+ */
7
+ class Bintime_Sinchimport_Model_System_Config_CatRewrite
8
+ {
9
+ public function toOptionArray()
10
+ {
11
+ $paramsArray = array(
12
+ 'MERGE' => 'Merge',
13
+ 'REWRITE' => 'Overwrite'
14
+ );
15
+ return $paramsArray;
16
+ }
17
+ }
18
+ ?>
app/code/local/Bintime/Sinchimport/Model/System/Config/Subscription.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class provides data for Magento BO
4
+ * @author Sergey Stepanchuk <info@bintime.com>
5
+ *
6
+ */
7
+ class Bintime_Sinchimport_Model_System_Config_Subscription
8
+ {
9
+ public function toOptionArray()
10
+ {
11
+ $paramsArray = array(
12
+ '1' => '1 am',
13
+ '2' => '2 am',
14
+ '3' => '3 am',
15
+ '4' => '4 am',
16
+ '5' => '5 am',
17
+ '6' => '6 am',
18
+ '7' => '7 am',
19
+ '8' => '8 am',
20
+ '9' => '9 am',
21
+ '10' => '10 am',
22
+ '11' => '11 am',
23
+ '12' => '12 am',
24
+ '13' => '1 pm',
25
+ '14' => '2 pm',
26
+ '15' => '3 pm',
27
+ '16' => '4 pm',
28
+ '17' => '5 pm',
29
+ '18' => '6 pm',
30
+ '19' => '7 pm',
31
+ '20' => '8 pm',
32
+ '21' => '9 pm',
33
+ '22' => '10 pm',
34
+ '23' => '11 pm',
35
+ '0' => '12 pm'
36
+ );
37
+ return $paramsArray;
38
+ }
39
+ }
40
+ ?>
app/code/local/Bintime/Sinchimport/Model/config.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ error_reporting(E_ALL);
3
+ ini_set('display_errors','On');
4
+ $baseDir = dirname(__FILE__);
5
+ $baseDir.=((substr($baseDir, -1)<>"/")? "/": "");
6
+ define(TEMPORARY_DIRECTORY_FOR_STORING_FILES, $baseDir.'../../../../../../var/');
7
+ define(SHELL_DIRECTORY_FOR_INDEXER, $baseDir.'../../../../../../shell/');
8
+ define(BASE_PATH, DIR_FS_ADMIN . 'StockInTheChannel_import');
9
+ define(LOG_PATH, BASE_PATH . '/logs/');
10
+ define(INCL_PATH, BASE_PATH . '/includes/');
11
+ define(CLASS_PATH, INCL_PATH . '/class/');
12
+
13
+ define(TMP_PATH, BASE_PATH . '/tmp/');
14
+ define(LOG_FILE, LOG_PATH.'import'.date("_Y_m").'.log');
15
+
16
+ define(FILE_CATEGORIES, 'Categories.csv');
17
+ define(FILE_CATEGORIES_FEATURES, 'CategoryFeatures.csv');
18
+ define(FILE_DISTRIBUTORS, 'Distributors.csv');
19
+ define(FILE_EANCODES, 'EANCodes.csv');
20
+ define(FILE_MANUFACTURERS, 'Manufacturers.csv');
21
+ define(FILE_PRODUCT_FEATURES, 'ProductFeatures.csv');
22
+ define(FILE_PRODUCTS, 'Products.csv');
23
+ define(FILE_RELATED_PRODUCTS, 'RelatedProducts.csv');
24
+ define(FILE_RESTRICTED_VALUES, 'RestrictedValues.csv');
25
+ define(FILE_STOCK_AND_PRICES, 'StockAndPrices.csv');
26
+ define(FILE_PRODUCTS_PICTURES_GALLERY, 'ProductPictures.csv');
27
+ define(FILE_URL_AND_DIR, "ftp://%%%login%%%:%%%password%%%@ftp.stockinthechannel.com/"); // insert StockInTheChannel url (default ftp://%%%login%%%:%%%password%%%@ftp.stockinthechannel.com/)
28
+ define(DEFAULT_FILE_TERMINATED_CHAR, "|");
29
+
30
+ define (TABLE_SINCH_CAT, "categories_temp");
31
+ define (TABLE_SINCH_MANUF, "manufacturers_temp");
32
+ define (TABLE_CATEGORY_ENTITY, "catalog_category_entity");
33
+ define (TABLE_CATEGORY_ENTITY_VARCHAR, "catalog_category_entity_varchar");
34
+ define (TABLE_CATEGORY_ENTITY_INT, "catalog_category_entity_int");
35
+ define (TABLE_ATTRIBUTE_OPT, "eav_attribute_option");
36
+ define (TABLE_ATTRIBUTE_OPT_VALUE,"eav_attribute_option_value");
37
+
38
+ define(LANG_CODE, 'en');
39
+ define(REWRITE_CATEGORIES_ORDER_ID, 'FALSE'); //TRUE FALSE
40
+ define(PHP_RUN_STRING, 'php ');
41
+ define(PRICE_BREAKS, "
42
+ 0-25;
43
+ 25-50;
44
+ 50-100;
45
+ 100-200;
46
+ 200-500;
47
+ 500-1000;
48
+ 2000-5000;
49
+ 5000-*;
50
+ ");
51
+ define("UPDATE_CATEGORY_DATA", false);
52
+
53
+ // require_once(INCL_PATH . 'utils/utils.php');
54
+ // require_once(CLASS_PATH . 'StockInTheChannel.php');
55
+
56
+ ?>
app/code/local/Bintime/Sinchimport/controllers/AjaxController.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Sinchimport_AjaxController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ var
5
+ $_logFile;
6
+
7
+ public function UpdateStatusAction() {
8
+
9
+ $import=Mage::getModel('sinchimport/sinch');
10
+ $message_arr = $import->getImportStatuses();
11
+ if ($message_arr['id']) {
12
+ // TODO use: $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result))
13
+ // JSON
14
+ print '{ "message": "'.$message_arr['message'].'", "finished": "'.$message_arr['finished'].'"}';
15
+ }
16
+ else{
17
+ print '{ "message": "", "finished": "0"}';
18
+ }
19
+
20
+ return;
21
+ }
22
+
23
+
24
+ public function indexAction(){
25
+ $sinch=Mage::getModel('sinchimport/sinch');
26
+ $this->_logFile="Sinch.log";
27
+ Mage::log("Start Sinch import", null, $this->_logFile);
28
+ // echo get_class(Mage::getModel('sinchimport/sinch'))."c".get_class(Mage::getModel('purchase/transporttask'));
29
+
30
+
31
+ echo "Start import <br>";
32
+ $dir = dirname(__FILE__);
33
+ exec("nohup ".$sinch->php_run_string.$dir."/../sinch_import_start_ajax.php > /dev/null & echo $!");
34
+
35
+ /*
36
+ $import=Mage::getModel('sinchimport/sinch');
37
+
38
+ $import->run_sinch_import();
39
+ */
40
+ echo "Finish import<br>";
41
+
42
+ }
43
+ public function stockPriceAction(){
44
+ $sinch=Mage::getModel('sinchimport/sinch');
45
+ $this->_logFile="Sinch.log";
46
+ Mage::log("Start Stock & Price Sinch import", null, $this->_logFile);
47
+ // echo get_class(Mage::getModel('sinchimport/sinch'))."c".get_class(Mage::getModel('purchase/transporttask'));
48
+
49
+
50
+ echo "Start Stock & Price import <br>";
51
+ $dir = dirname(__FILE__);
52
+ exec("nohup ".$sinch->php_run_string.$dir."/../stock_price_sinch_import_start_ajax.php > /dev/null & echo $!");
53
+
54
+ /*
55
+ $import=Mage::getModel('sinchimport/sinch');
56
+
57
+ $import->run_sinch_import();
58
+ */
59
+ echo "Finish Stock & Price import<br>";
60
+ }
61
+ }
62
+ ?>
app/code/local/Bintime/Sinchimport/controllers/IndexController.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Sinchimport_IndexController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ var
5
+ $_logFile;
6
+
7
+ public function indexAction(){
8
+ $this->_logFile="Sinch.log";
9
+ Mage::log("Start Sinch import", null, $this->_logFile);
10
+ // echo get_class(Mage::getModel('sinchimport/sinch'))."c".get_class(Mage::getModel('purchase/transporttask'));
11
+
12
+
13
+ echo "Start import <br>";
14
+
15
+ $import=Mage::getModel('sinchimport/sinch');
16
+
17
+ $import->run_sinch_import();
18
+
19
+ echo "Finish import<br>";
20
+
21
+ }
22
+
23
+ public function stockPriceImportAction(){
24
+ $this->_logFile="Sinch.log";
25
+ Mage::log("Start Stock & Price Sinch import", null, $this->_logFile);
26
+ // echo get_class(Mage::getModel('sinchimport/sinch'))."c".get_class(Mage::getModel('purchase/transporttask'));
27
+
28
+ echo "Start Stock & Price import <br>";
29
+
30
+ $import=Mage::getModel('sinchimport/sinch');
31
+
32
+ $import->run_stock_price_sinch_import();
33
+
34
+ echo "Finish Stock & Price import<br>";
35
+
36
+
37
+ }
38
+
39
+ public function splitFeaturesAction()
40
+ {
41
+ $resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
42
+ $resource->splitProductsFeature(null);
43
+ $this->getResponse()->setBody('<h2>done.</h2>');
44
+ }
45
+ }
46
+ ?>
app/code/local/Bintime/Sinchimport/controllers/ProductController.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Mage/Catalog/controllers/ProductController.php';
3
+ /**
4
+ * Class rewrites standard product view controller to provide icecat data on the page
5
+ * @author Sergey Gozhedrianov <info@bintime.com>
6
+ *
7
+ */
8
+ class Bintime_Sinchimport_ProductController extends Mage_Catalog_ProductController{
9
+ /**
10
+ * parent view Action
11
+ */
12
+ public function viewAction(){
13
+ parent::viewAction();
14
+ }
15
+
16
+ /**
17
+ * parent gallery Action
18
+ */
19
+ public function galleryAction(){
20
+ $this->getRequest()->setRouteName('catalog');
21
+ parent::galleryAction();
22
+ }
23
+
24
+ /**
25
+ * parent Image Action
26
+ */
27
+ public function imageAction()
28
+ {
29
+ $this->getRequest()->setRouteName('catalog');
30
+ parent::imageAction();
31
+ }
32
+
33
+ /**
34
+ * before resolving url make sure that route name is correct
35
+ */
36
+ public function preDispatch()
37
+ {
38
+ parent::preDispatch();
39
+ if ($this->getRequest()->getActionName() == 'view'){
40
+ $this->getRequest()->setRouteName('sinchimport');
41
+ }
42
+ }
43
+ }
44
+ ?>
app/code/local/Bintime/Sinchimport/controllers/SplitfeaturesController.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Sinchimport_SplitfeaturesController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ // indexAction
5
+ var
6
+ $_logFile;
7
+
8
+ public function indexAction(){
9
+
10
+ $resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
11
+ $resource->splitProductsFeature(null);
12
+ $this->getResponse()->setBody('<h2>done.</h2>');
13
+ }
14
+
15
+ }
16
+ ?>
app/code/local/Bintime/Sinchimport/etc/api.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <sinchimport_soap translate="title" module="sinchimport">
6
+ <title>Bintime Sinchimport Soap</title>
7
+ <model>sinchimport/api</model>
8
+ <methods>
9
+
10
+ <test translate="title" module="sinchimport">
11
+ <title>Bintime Sinchimport Soap method "test"</title>
12
+ <method>test</method>
13
+ </test>
14
+
15
+ <run_Full_Import>
16
+ <title>Bintime Sinchimport Soap method "run_Full_Import"</title>
17
+ <method>run_full_import</method>
18
+ </run_Full_Import>
19
+
20
+ <run_Price_Stock_Import>
21
+ <title>Bintime Sinchimport Soap method "run_Price_Stock_Import"</title>
22
+ <method>run_ps_import</method>
23
+ </run_Price_Stock_Import>
24
+
25
+ <get_Import_Status>
26
+ <title>Bintime Sinchimport Soap method "get_Import_Status"</title>
27
+ <method>get_import_status</method>
28
+ </get_Import_Status>
29
+
30
+ </methods>
31
+ </sinchimport_soap>
32
+ </resources>
33
+ </api>
34
+ </config>
app/code/local/Bintime/Sinchimport/etc/config.xml ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+
5
+ <modules>
6
+ <Bintime_Sinchimport>
7
+ <version>0.1.7</version>
8
+ <depends>
9
+ <!-- no dependencies -->
10
+ </depends>
11
+ </Bintime_Sinchimport>
12
+ </modules>
13
+
14
+ <global>
15
+ <helpers>
16
+ <sinchimport>
17
+ <class>Bintime_Sinchimport_Helper</class>
18
+ </sinchimport>
19
+ <catalog>
20
+ <rewrite>
21
+ <image>Bintime_Sinchimport_Helper_Image</image>
22
+ </rewrite>
23
+ </catalog>
24
+
25
+ </helpers>
26
+ <models>
27
+ <catalog>
28
+ <rewrite>
29
+ <product_image>Bintime_Sinchimport_Model_Image</product_image>
30
+ </rewrite>
31
+ </catalog>
32
+ <catalog>
33
+ <rewrite>
34
+ <category>Bintime_Sinchimport_Model_Category</category>
35
+ </rewrite>
36
+ </catalog>
37
+ </models>
38
+ <models>
39
+ <sinchimport>
40
+ <class>Bintime_Sinchimport_Model</class>
41
+ </sinchimport>
42
+ </models>
43
+ <blocks>
44
+ <catalog>
45
+ <rewrite>
46
+ <product_compare_list>Bintime_Sinchimport_Block_List</product_compare_list>
47
+ </rewrite>
48
+ </catalog>
49
+ <catalog>
50
+ <rewrite>
51
+ <product_view_media>Bintime_Sinchimport_Block_Product_View_Media</product_view_media>
52
+ </rewrite>
53
+ </catalog>
54
+ </blocks>
55
+ <models>
56
+ <catalog>
57
+ <rewrite>
58
+ <product>Bintime_Sinchimport_Model_Product</product>
59
+ </rewrite>
60
+ </catalog>
61
+ </models>
62
+ <models>
63
+ <catalog>
64
+ <rewrite>
65
+ <layer_filter_price>Bintime_Sinchimport_Model_Layer_Filter_Price</layer_filter_price>
66
+ </rewrite>
67
+ </catalog>
68
+ </models>
69
+
70
+ <resources>
71
+ <sinchimport_write>
72
+ <connection><use>core_write</use></connection>
73
+ </sinchimport_write>
74
+ <sinchimport_read>
75
+ <connection><use>core_read</use></connection>
76
+ </sinchimport_read>
77
+
78
+ <sinchimport_setup>
79
+ <setup>
80
+ <module>Bintime_Sinchimport</module>
81
+ <class>Bintime_Sinchimport_Model_Resource_Mysql4_Setup</class>
82
+ </setup>
83
+ <connection>
84
+ <use>core_setup</use>
85
+ </connection>
86
+ </sinchimport_setup>
87
+
88
+ </resources>
89
+ <!-- <routers>
90
+ <catalog>
91
+ <rewrite>
92
+ <product>
93
+ <to>Bintime_Sinchimport/product</to>
94
+ <override_actions>false</override_actions>
95
+ <actions>
96
+ <view><to>Bintime_Sinchimport/product/view</to></view>
97
+ </actions>
98
+ </product>
99
+ </rewrite>
100
+ </catalog>
101
+ </routers>
102
+ -->
103
+ <blocks>
104
+ <catalog>
105
+ <rewrite>
106
+ <layer_view>Bintime_Sinchimport_Block_Layer_View</layer_view>
107
+ </rewrite>
108
+ </catalog>
109
+ <sinchimport>
110
+ <class>Bintime_Sinchimport_Block</class>
111
+ </sinchimport>
112
+ </blocks>
113
+ <models>
114
+ <catalog>
115
+ <rewrite>
116
+ <layer>Bintime_Sinchimport_Model_Layer</layer>
117
+ </rewrite>
118
+ </catalog>
119
+ <sinchimport>
120
+ <class>Bintime_Sinchimport_Model</class>
121
+ <resourceModel>sinchimport_mysql4</resourceModel>
122
+ </sinchimport>
123
+
124
+ <catalog_resource_eav_mysql4>
125
+ <rewrite>
126
+ <layer_filter_price>Bintime_Sinchimport_Model_Resource_Layer_Filter_Price</layer_filter_price>
127
+ </rewrite>
128
+ </catalog_resource_eav_mysql4>
129
+
130
+ <sinchimport_mysql4>
131
+ <class>Bintime_Sinchimport_Model_Resource_Mysql4</class>
132
+ <!-- <entities>
133
+ <ice_feature><table>icecat_category_feature</table></ice_feature>
134
+ </entities>
135
+ -->
136
+ </sinchimport_mysql4>
137
+
138
+ <!-- <sinchimport>
139
+ <class>Bintime_Icelayered_Block</class>
140
+ </sinchimport>
141
+ -->
142
+
143
+ </models>
144
+ <events>
145
+ <sinchimport_model_import_after>
146
+ <observers>
147
+ <sinchimport_reindex>
148
+ <class>sinchimport/resource_mysql4_layer_filter_feature</class>
149
+ <method>reindex</method>
150
+ </sinchimport_reindex>
151
+ </observers>
152
+ </sinchimport_model_import_after>
153
+ </events>
154
+
155
+ </global>
156
+
157
+ <frontend>
158
+ <routers>
159
+ <sinchimport>
160
+ <use>standard</use>
161
+ <args>
162
+ <module>Bintime_Sinchimport</module>
163
+ <frontName>sinchimport</frontName>
164
+ </args>
165
+ </sinchimport>
166
+ </routers>
167
+ <layout>
168
+ <updates>
169
+ <sinchimport>
170
+ <file>sinchimport.xml</file>
171
+ </sinchimport>
172
+ </updates>
173
+ </layout>
174
+
175
+ </frontend>
176
+ <admin>
177
+ <routers>
178
+ <sinchimport>
179
+ <use>admin</use>
180
+ <args>
181
+ <module>Bintime_Sinchimport</module>
182
+ <frontName>sinchimport</frontName>
183
+ </args>
184
+ </sinchimport>
185
+ </routers>
186
+ </admin>
187
+
188
+ <adminhtml>
189
+ <acl>
190
+ <resources>
191
+ <admin>
192
+ <children>
193
+ <system>
194
+ <children>
195
+ <config>
196
+ <children>
197
+ <sinchimport_root translate="title" module="customer">
198
+ <title> Stock In The Channel model powered by Bintime company</title>
199
+ <sort_order>250</sort_order>
200
+ </sinchimport_root>
201
+ </children>
202
+ </config>
203
+ </children>
204
+ </system>
205
+ </children>
206
+ </admin>
207
+ </resources>
208
+ </acl>
209
+ <events></events>
210
+ <translate>
211
+ <modules>
212
+ <mage_adminhtml>
213
+ <files>
214
+ <sinchimport>Bintime_Sinchimport.csv</sinchimport>
215
+ </files>
216
+ </mage_adminhtml>
217
+ </modules>
218
+ </translate>
219
+ </adminhtml>
220
+
221
+ <default>
222
+ <sinchimport_root>
223
+ <sinch_cron>
224
+ <sinch_cron_time>8 am</sinch_cron_time>
225
+ </sinch_cron>
226
+ </sinchimport_root>
227
+ </default>
228
+ <crontab>
229
+ <jobs>
230
+ <fullsinchimport>
231
+ <schedule><cron_expr>0 2 * * *</cron_expr></schedule>
232
+ <run><model>sinchimport/sinch::cron_start_full_import</model></run>
233
+
234
+ </fullsinchimport>
235
+ <stockpricesinchimport>
236
+
237
+ <schedule><cron_expr>0 4 * * *</cron_expr></schedule>
238
+ <run><model>sinchimport/sinch::cron_start_stock_price_import</model></run>
239
+
240
+ </stockpricesinchimport>
241
+ </jobs>
242
+ </crontab>
243
+ </config>
244
+
app/code/local/Bintime/Sinchimport/etc/system.xml ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <sinchimport_root translate="label" module="catalog">
5
+ <class>separator-top</class>
6
+ <label>Stock in the Channel</label>
7
+ <tab>catalog</tab>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>200</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <groups>
14
+ <sinch_ftp translate="label">
15
+ <label>FTP Login Details</label>
16
+ <frontend_type>text</frontend_type>
17
+ <comment>Get these details from Stock in the Channel for the pricelist you want this store to use. This is not your Stock in the Channel username and password</comment>
18
+ <sort_order>50</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ <fields>
23
+ <login translate="label">
24
+ <label>FTP User Name</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>10</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </login>
31
+ <password translate="label">
32
+ <label>FTP Password</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>20</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </password>
39
+ <!--
40
+ <field_terminated_char>
41
+ <label>Field terminated char</label>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>30</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ </field_terminated_char>
48
+ -->
49
+ <replace_category>
50
+ <label>Merge or Overwrite Categories</label>
51
+ <frontend_type>select</frontend_type>
52
+ <source_model>sinchimport/system_config_CatRewrite</source_model>
53
+ <sort_order>30</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>1</show_in_store>
57
+ </replace_category>
58
+ <!--
59
+ <price_breaks translate="label">
60
+ <label>Inser price breaks (insert ranges like 0-10; 10-100; etc.)</label>
61
+ <frontend_type>textarea</frontend_type>
62
+ <sort_order>40</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ </price_breaks>
67
+ -->
68
+ </fields>
69
+ </sinch_ftp>
70
+ <!--
71
+ <sinch_cron translate="label">
72
+ <label>Schedule Import Time</label>
73
+ <frontend_type>text</frontend_type>
74
+ <comment>Choose the time you want the file to be imported to your Magento store, bear in mind some distributors do not publish their days prices until quite late, so set 8 AM as the earliest</comment>
75
+ <sort_order>100</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>1</show_in_store>
79
+ <fields>
80
+ <sinch_cron_time translate="label">
81
+ <label>Schedule Import Time</label>
82
+ <frontend_type>select</frontend_type>
83
+ <source_model>sinchimport/system_config_subscription</source_model>
84
+ <sort_order>10</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>1</show_in_store>
88
+ </sinch_cron_time>
89
+ </fields>
90
+ </sinch_cron>
91
+ -->
92
+ <sinch_import_fullstatus translate="label">
93
+ <label>Import Full Catalogue</label>
94
+ <frontend_type>text</frontend_type>
95
+ <comment>An import of 100000 products will take approximately 1 hour.Larger catalogues will take substantially longer.</comment>
96
+ <sort_order>150</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ <fields>
101
+ <start_sinch_import translate="label">
102
+ <frontend_type>button</frontend_type>
103
+ <frontend_model>sinchimport/startimportbutton</frontend_model>
104
+ <sort_order>4</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>0</show_in_website>
107
+ <show_in_store>0</show_in_store>
108
+ </start_sinch_import>
109
+ </fields>
110
+ </sinch_import_fullstatus>
111
+ <sinch_import_stockpricestatus translate="label">
112
+ <label>Import Stock &amp; Prices</label>
113
+ <frontend_type>text</frontend_type>
114
+ <comment>This will import stock and prices ONLY. This process should not take longer 5 minutes.</comment>
115
+ <sort_order>160</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>1</show_in_website>
118
+ <show_in_store>1</show_in_store>
119
+ <fields>
120
+ <start_sinch_import translate="label">
121
+ <frontend_type>button</frontend_type>
122
+ <frontend_model>sinchimport/startstockpriceimportbutton</frontend_model>
123
+ <sort_order>4</sort_order>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>0</show_in_website>
126
+ <show_in_store>0</show_in_store>
127
+ </start_sinch_import>
128
+ </fields>
129
+ </sinch_import_stockpricestatus>
130
+
131
+ <sinch_import_history>
132
+ <label>Import History</label>
133
+ <frontend_type>text</frontend_type>
134
+ <comment></comment>
135
+ <sort_order>170</sort_order>
136
+ <show_in_default>1</show_in_default>
137
+ <show_in_website>1</show_in_website>
138
+ <show_in_store>1</show_in_store>
139
+ <fields>
140
+ <sinch_import_hist translate="label">
141
+ <frontend_type>button</frontend_type>
142
+ <frontend_model>sinchimport/importhistory</frontend_model>
143
+ <sort_order>4</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>0</show_in_website>
146
+ <show_in_store>0</show_in_store>
147
+ </sinch_import_hist>
148
+ </fields>
149
+
150
+
151
+ </sinch_import_history>
152
+ </groups>
153
+ </sinchimport_root>
154
+ </sections>
155
+ </config>
app/code/local/Bintime/Sinchimport/sinch_import_start_ajax.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $baseDir = dirname(__FILE__);
3
+ require $baseDir . '/../../../../../app/Mage.php';
4
+
5
+ Mage::app();
6
+
7
+ $import=Mage::getModel('sinchimport/sinch');
8
+
9
+
10
+ $import->run_sinch_import();
11
+
12
+ $import->addImportStatus('Finish import', 1);
13
+
14
+ ?>
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/filter_sinch_products_s.sql ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ DROP PROCEDURE IF EXISTS `filter_sinch_products_s`;
2
+ delimiter =/=
3
+ CREATE PROCEDURE `filter_sinch_products_s`(
4
+ IN arg_table INT,
5
+ IN arg_category_id INT,
6
+ IN arg_image INT,
7
+ IN arg_category_feature INT,
8
+ IN arg_least INT,
9
+ IN arg_greatest INT
10
+ )
11
+ BEGIN
12
+ DROP TABLE IF EXISTS `tmp_result`;
13
+
14
+ CREATE TEMPORARY TABLE `tmp_result`(
15
+ `entity_id` int(10) unsigned,
16
+ `category_id` int(10) unsigned,
17
+ `product_id` int,
18
+ `sinch_category_id` int,
19
+ `name` varchar(255),
20
+ `image` varchar(255),
21
+ `supplier_id` int,
22
+ `category_feature_id` int,
23
+ `feature_id` int,
24
+ `feature_name` varchar(255),
25
+ `feature_value` text
26
+ );
27
+
28
+
29
+
30
+ IF arg_image = 1 THEN
31
+ INSERT INTO `tmp_result` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
32
+ (
33
+ SELECT E.entity_id, PCind.category_id, E.entity_id, PCind.category_id as `sinch_category`, PR.`product_name`, PR.main_image_url, PR.sinch_manufacturer_id, CF.category_feature_id, CF.category_feature_id, CF.`feature_name`, RV.`text`
34
+ FROM catalog_product_entity E
35
+ INNER JOIN catalog_category_product_index PCind
36
+ ON (E.entity_id = PCind.product_id)
37
+
38
+ inner join stINch_categories_mapping scm on PCind.category_id=scm.shop_entity_id
39
+ INNER JOIN stINch_categories_features CF
40
+ ON (scm.store_category_id=CF.store_category_id)
41
+ INNER JOIN stINch_products PR
42
+ ON (PR.store_product_id = E.store_product_id)
43
+ INNER JOIN stINch_product_features PF
44
+ ON (PR.sinch_product_id = PF.sinch_product_id )
45
+ INNER JOIN stINch_restricted_values RV
46
+ ON (PF.restricted_value_id=RV.restricted_value_id)
47
+ WHERE
48
+ scm.shop_entity_id = arg_category_id
49
+ AND PR.main_image_url <> ''
50
+ );
51
+ ELSE
52
+ INSERT INTO `tmp_result` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
53
+ (
54
+ SELECT E.entity_id, PCind.category_id, E.entity_id, PCind.category_id as `sinch_category`, PR.`product_name`, PR.main_image_url, PR.sinch_manufacturer_id, CF.category_feature_id, CF.category_feature_id, CF.`feature_name`, RV.`text`
55
+ FROM catalog_product_entity E
56
+ INNER JOIN catalog_category_product_index PCind
57
+ ON (E.entity_id = PCind.product_id)
58
+ inner join stINch_categories_mapping scm on PCind.category_id=scm.shop_entity_id
59
+ INNER JOIN stINch_categories_features CF
60
+ ON (scm.store_category_id=CF.store_category_id)
61
+ INNER JOIN stINch_products PR
62
+ ON (PR.store_product_id = E.store_product_id)
63
+ INNER JOIN stINch_product_features PF
64
+ ON (PR.sinch_product_id = PF.sinch_product_id )
65
+ INNER JOIN stINch_restricted_values RV
66
+ ON (PF.restricted_value_id=RV.restricted_value_id)
67
+ WHERE
68
+ scm.shop_entity_id = arg_category_id
69
+
70
+ );
71
+
72
+ END IF;
73
+
74
+ IF (SELECT COUNT(*) FROM `FilterListOfFeatures`) > 0 THEN
75
+ SET @query = CONCAT('INSERT INTO `SinchFilterResult_', arg_table, '` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
76
+ (
77
+ SELECT TR.entity_id, TR.category_id, TR.product_id, TR.sinch_category_id, TR.`name`, TR.`image`, TR.supplier_id, TR.category_feature_id, TR.feature_id, TR.feature_name, TR.feature_value
78
+ FROM `tmp_result` AS TR
79
+ INNER JOIN `FilterListOfFeatures` AS LF ON (TR.category_feature_id = LF.category_feature_id)
80
+ WHERE TR.feature_value LIKE LF.feature_value GROUP BY entity_id
81
+ )');
82
+
83
+ ELSE
84
+ IF (arg_least IS NOT null AND arg_greatest IS NOT null) THEN
85
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' AND TR.feature_value <', arg_greatest, ' ');
86
+ ELSE
87
+ IF arg_least IS null THEN
88
+ SET @where = CONCAT(' AND TR.feature_value < ', arg_greatest, ' ');
89
+ ELSE
90
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' ');
91
+ END IF;
92
+ END IF;
93
+
94
+ SET @query = CONCAT('INSERT INTO `SinchFilterResult_', arg_table, '` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
95
+ (
96
+ SELECT TR.entity_id, TR.category_id, TR.product_id, TR.sinch_category_id, TR.`name`, TR.`image`, TR.supplier_id, TR.category_feature_id, TR.feature_id, TR.feature_name, TR.feature_value
97
+ FROM `tmp_result` AS TR
98
+ WHERE TR.category_feature_id = \'', arg_category_feature, '\'',
99
+ @where,
100
+ 'GROUP BY entity_id
101
+ )');
102
+
103
+ END IF;
104
+
105
+ PREPARE myquery FROM @query;
106
+ EXECUTE myquery;
107
+ DROP PREPARE myquery;
108
+
109
+ END=/=
110
+ delimiter ;
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ //прямое подключение к базе необходимо для добавления хранимки
6
+ $config = $installer->getConnection()->getConfig();
7
+ $cnx = mysql_connect($config['host'], $config['username'], $config['password']);
8
+ if (!$cnx) {
9
+ throw new Exception('Failed to connect to database.');
10
+ }
11
+
12
+ if (!mysql_select_db($config['dbname'])) {
13
+ throw new Exception('Failed to select a database.');
14
+ }
15
+
16
+ $installer->startSetup();
17
+
18
+ $installer->run("DROP TABLE IF EXISTS {$installer->getTable('FilterListOfFeatures')}");
19
+
20
+ $installer->run("CREATE TABLE {$installer->getTable('FilterListOfFeatures')}(
21
+ `id` int PRIMARY KEY NOT NULL AUTO_INCREMENT,
22
+ `category_feature_id` int NOT NULL,
23
+ `feature_id` int NULL,
24
+ `feature_value` text
25
+ )");
26
+
27
+ $installer->run("DROP PROCEDURE IF EXISTS `filter_sinch_products_s`");
28
+
29
+ $query = "
30
+ CREATE PROCEDURE `filter_sinch_products_s`(
31
+ IN arg_table INT,
32
+ IN arg_category_id INT,
33
+ IN arg_image INT,
34
+ IN arg_category_feature INT,
35
+ IN arg_least INT,
36
+ IN arg_greatest INT
37
+ )
38
+ BEGIN
39
+ DROP TABLE IF EXISTS `tmp_result`;
40
+
41
+ CREATE TEMPORARY TABLE `tmp_result`(
42
+ `entity_id` int(10) unsigned,
43
+ `category_id` int(10) unsigned,
44
+ `product_id` int,
45
+ `sinch_category_id` int,
46
+ `name` varchar(255),
47
+ `image` varchar(255),
48
+ `supplier_id` int,
49
+ `category_feature_id` int,
50
+ `feature_id` int,
51
+ `feature_name` varchar(255),
52
+ `feature_value` text
53
+ );
54
+
55
+
56
+
57
+ IF arg_image = 1 THEN
58
+ INSERT INTO `tmp_result` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
59
+ (
60
+ SELECT E.entity_id, PCind.category_id, E.entity_id, PCind.category_id as `sinch_category`, PR.`product_name`, PR.main_image_url, PR.sinch_manufacturer_id, CF.category_feature_id, CF.category_feature_id, CF.`feature_name`, RV.`text`
61
+ FROM catalog_product_entity E
62
+ INNER JOIN catalog_category_product_index PCind
63
+ ON (E.entity_id = PCind.product_id)
64
+ INNER JOIN stINch_categories_features CF
65
+ ON (PCind.category_id=CF.store_category_id)
66
+ INNER JOIN stINch_products PR
67
+ ON (PR.store_product_id = E.entity_id)
68
+ INNER JOIN stINch_product_features PF
69
+ ON (PR.sinch_product_id = PF.sinch_product_id )
70
+ INNER JOIN stINch_restricted_values RV
71
+ ON (PF.restricted_value_id=RV.restricted_value_id)
72
+ WHERE
73
+ PCind.category_id = arg_category_id
74
+ AND PR.main_image_url <> ''
75
+ );
76
+ ELSE
77
+ INSERT INTO `tmp_result` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
78
+ (
79
+ SELECT E.entity_id, PCind.category_id, E.entity_id, PCind.category_id as `sinch_category`, PR.`product_name`, PR.main_image_url, PR.sinch_manufacturer_id, CF.category_feature_id, CF.category_feature_id, CF.`feature_name`, RV.`text`
80
+ FROM catalog_product_entity E
81
+ INNER JOIN catalog_category_product_index PCind
82
+ ON (E.entity_id = PCind.product_id)
83
+ INNER JOIN stINch_categories_features CF
84
+ ON (PCind.category_id=CF.store_category_id)
85
+ INNER JOIN stINch_products PR
86
+ ON (PR.store_product_id = E.entity_id)
87
+ INNER JOIN stINch_product_features PF
88
+ ON (PR.sinch_product_id = PF.sinch_product_id )
89
+ INNER JOIN stINch_restricted_values RV
90
+ ON (PF.restricted_value_id=RV.restricted_value_id)
91
+ WHERE
92
+ PCind.category_id = arg_category_id
93
+
94
+ );
95
+
96
+ END IF;
97
+
98
+ IF (SELECT COUNT(*) FROM `FilterListOfFeatures`) > 0 THEN
99
+ SET @query = CONCAT('INSERT INTO `SinchFilterResult_', arg_table, '` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
100
+ (
101
+ SELECT TR.entity_id, TR.category_id, TR.product_id, TR.sinch_category_id, TR.`name`, TR.`image`, TR.supplier_id, TR.category_feature_id, TR.feature_id, TR.feature_name, TR.feature_value
102
+ FROM `tmp_result` AS TR
103
+ INNER JOIN `FilterListOfFeatures` AS LF ON (TR.category_feature_id = LF.category_feature_id)
104
+ WHERE TR.feature_value LIKE LF.feature_value GROUP BY entity_id
105
+ )');
106
+
107
+ ELSE
108
+ IF (arg_least IS NOT null AND arg_greatest IS NOT null) THEN
109
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' AND TR.feature_value <', arg_greatest, ' ');
110
+ ELSE
111
+ IF arg_least IS null THEN
112
+ SET @where = CONCAT(' AND TR.feature_value < ', arg_greatest, ' ');
113
+ ELSE
114
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' ');
115
+ END IF;
116
+ END IF;
117
+
118
+ SET @query = CONCAT('INSERT INTO `SinchFilterResult_', arg_table, '` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
119
+ (
120
+ SELECT TR.entity_id, TR.category_id, TR.product_id, TR.sinch_category_id, TR.`name`, TR.`image`, TR.supplier_id, TR.category_feature_id, TR.feature_id, TR.feature_name, TR.feature_value
121
+ FROM `tmp_result` AS TR
122
+ WHERE TR.category_feature_id = \'', arg_category_feature, '\'',
123
+ @where,
124
+ 'GROUP BY entity_id
125
+ )');
126
+
127
+ END IF;
128
+
129
+ PREPARE myquery FROM @query;
130
+ EXECUTE myquery;
131
+ DROP PREPARE myquery;
132
+
133
+ END
134
+ ";
135
+
136
+ if (!mysql_query($query, $cnx)) {
137
+ throw new Exception("Failed to create stored procedure");
138
+ }
139
+
140
+ mysql_close($cnx);
141
+
142
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.0-0.1.1.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ stepan
4
+ */
5
+ $installer = $this;
6
+
7
+ $installer->startSetup();
8
+
9
+ $attr_varchar=array(
10
+ 'ean' => 'EAN'
11
+ );
12
+
13
+ foreach($attr_varchar as $key=>$value){
14
+
15
+ $installer->addAttribute('catalog_product', $key,array(
16
+ 'label' => $value,
17
+ 'type' => 'varchar',
18
+ 'input' => 'text',
19
+ 'backend' => 'eav/entity_attribute_backend_array',
20
+ 'frontend' => '',
21
+ 'source' => '',
22
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
23
+ 'visible' => true,
24
+ 'required' => false,
25
+ 'user_defined' => false,
26
+ 'searchable' => false,
27
+ 'filterable' => false,
28
+ 'comparable' => false,
29
+ 'visible_on_front' => true,
30
+ 'visible_in_advanced_search' => false,
31
+ 'unique' => false
32
+ ));
33
+ }
34
+
35
+
36
+ $attr_text=array(
37
+ 'specification' => 'Specification'
38
+ );
39
+
40
+ foreach($attr_text as $key=>$value){
41
+
42
+ $installer->addAttribute('catalog_product', $key,array(
43
+ 'label' => $value,
44
+ 'type' => 'text',
45
+ 'input' => 'textarea',
46
+ 'backend' => 'eav/entity_attribute_backend_array',
47
+ 'frontend' => '',
48
+ 'source' => '',
49
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
50
+ 'visible' => true,
51
+ 'required' => false,
52
+ 'user_defined' => false,
53
+ 'searchable' => false,
54
+ 'filterable' => false,
55
+ 'comparable' => false,
56
+ 'visible_on_front' => true,
57
+ 'is_visible_on_front' => true,
58
+ 'is_html_allowed_on_front' => true,
59
+ 'visible_in_advanced_search' => false,
60
+ 'unique' => false
61
+ ));
62
+ }
63
+
64
+
65
+ //$installer->installEntities();
66
+
67
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.1-0.1.2.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ stepan
4
+ */
5
+ $installer = $this;
6
+
7
+ $installer->startSetup();
8
+
9
+ $installer->run("
10
+ ALTER IGNORE TABLE {$this->getTable('catalog_product_entity')}
11
+ ADD COLUMN `store_product_id` INT(11) UNSIGNED NULL
12
+ ");
13
+ $installer->run("
14
+ ALTER IGNORE TABLE {$this->getTable('catalog_product_entity')}
15
+ ADD INDEX `store_product_id` (`store_product_id`);
16
+ ");
17
+
18
+ $installer->run("
19
+ ALTER IGNORE TABLE {$this->getTable('catalog_product_entity')}
20
+ ADD COLUMN `sinch_product_id` INT(11) UNSIGNED NULL
21
+ ");
22
+ $installer->run("
23
+ ALTER IGNORE TABLE {$this->getTable('catalog_product_entity')}
24
+ ADD INDEX `sinch_product_id` (`sinch_product_id`);
25
+ ");
26
+
27
+
28
+ //$installer->installEntities();
29
+
30
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.2-0.1.3.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ //прямое подключение к базе необходимо для добавления хранимки
6
+ $config = $installer->getConnection()->getConfig();
7
+ $cnx = mysql_connect($config['host'], $config['username'], $config['password']);
8
+ if (!$cnx) {
9
+ throw new Exception('Failed to connect to database.');
10
+ }
11
+
12
+ if (!mysql_select_db($config['dbname'])) {
13
+ throw new Exception('Failed to select a database.');
14
+ }
15
+
16
+ $installer->startSetup();
17
+
18
+ $installer->run("DROP PROCEDURE IF EXISTS `filter_sinch_products_s`");
19
+
20
+ $query = "
21
+ CREATE PROCEDURE `filter_sinch_products_s`(
22
+ IN arg_table INT,
23
+ IN arg_category_id INT,
24
+ IN arg_image INT,
25
+ IN arg_category_feature INT,
26
+ IN arg_least INT,
27
+ IN arg_greatest INT
28
+ )
29
+ BEGIN
30
+ DROP TABLE IF EXISTS `tmp_result`;
31
+
32
+ CREATE TEMPORARY TABLE `tmp_result`(
33
+ `entity_id` int(10) unsigned,
34
+ `category_id` int(10) unsigned,
35
+ `product_id` int,
36
+ `sinch_category_id` int,
37
+ `name` varchar(255),
38
+ `image` varchar(255),
39
+ `supplier_id` int,
40
+ `category_feature_id` int,
41
+ `feature_id` int,
42
+ `feature_name` varchar(255),
43
+ `feature_value` text
44
+ );
45
+
46
+
47
+
48
+ IF arg_image = 1 THEN
49
+ INSERT INTO `tmp_result` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
50
+ (
51
+ SELECT E.entity_id, PCind.category_id, E.entity_id, PCind.category_id as `sinch_category`, PR.`product_name`, PR.main_image_url, PR.sinch_manufacturer_id, CF.category_feature_id, CF.category_feature_id, CF.`feature_name`, RV.`text`
52
+ FROM catalog_product_entity E
53
+ INNER JOIN catalog_category_product_index PCind
54
+ ON (E.entity_id = PCind.product_id)
55
+ INNER JOIN stINch_categories_features CF
56
+ ON (PCind.category_id=CF.store_category_id)
57
+ INNER JOIN stINch_products PR
58
+ ON (PR.store_product_id = E.store_product_id)
59
+ INNER JOIN stINch_product_features PF
60
+ ON (PR.sinch_product_id = PF.sinch_product_id )
61
+ INNER JOIN stINch_restricted_values RV
62
+ ON (PF.restricted_value_id=RV.restricted_value_id)
63
+ WHERE
64
+ PCind.category_id = arg_category_id
65
+ AND PR.main_image_url <> ''
66
+ );
67
+ ELSE
68
+ INSERT INTO `tmp_result` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
69
+ (
70
+ SELECT E.entity_id, PCind.category_id, E.entity_id, PCind.category_id as `sinch_category`, PR.`product_name`, PR.main_image_url, PR.sinch_manufacturer_id, CF.category_feature_id, CF.category_feature_id, CF.`feature_name`, RV.`text`
71
+ FROM catalog_product_entity E
72
+ INNER JOIN catalog_category_product_index PCind
73
+ ON (E.entity_id = PCind.product_id)
74
+ INNER JOIN stINch_categories_features CF
75
+ ON (PCind.category_id=CF.store_category_id)
76
+ INNER JOIN stINch_products PR
77
+ ON (PR.store_product_id = E.store_product_id)
78
+ INNER JOIN stINch_product_features PF
79
+ ON (PR.sinch_product_id = PF.sinch_product_id )
80
+ INNER JOIN stINch_restricted_values RV
81
+ ON (PF.restricted_value_id=RV.restricted_value_id)
82
+ WHERE
83
+ PCind.category_id = arg_category_id
84
+
85
+ );
86
+
87
+ END IF;
88
+
89
+ IF (SELECT COUNT(*) FROM `FilterListOfFeatures`) > 0 THEN
90
+ SET @query = CONCAT('INSERT INTO `SinchFilterResult_', arg_table, '` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
91
+ (
92
+ SELECT TR.entity_id, TR.category_id, TR.product_id, TR.sinch_category_id, TR.`name`, TR.`image`, TR.supplier_id, TR.category_feature_id, TR.feature_id, TR.feature_name, TR.feature_value
93
+ FROM `tmp_result` AS TR
94
+ INNER JOIN `FilterListOfFeatures` AS LF ON (TR.category_feature_id = LF.category_feature_id)
95
+ WHERE TR.feature_value LIKE LF.feature_value GROUP BY entity_id
96
+ )');
97
+
98
+ ELSE
99
+ IF (arg_least IS NOT null AND arg_greatest IS NOT null) THEN
100
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' AND TR.feature_value <', arg_greatest, ' ');
101
+ ELSE
102
+ IF arg_least IS null THEN
103
+ SET @where = CONCAT(' AND TR.feature_value < ', arg_greatest, ' ');
104
+ ELSE
105
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' ');
106
+ END IF;
107
+ END IF;
108
+
109
+ SET @query = CONCAT('INSERT INTO `SinchFilterResult_', arg_table, '` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
110
+ (
111
+ SELECT TR.entity_id, TR.category_id, TR.product_id, TR.sinch_category_id, TR.`name`, TR.`image`, TR.supplier_id, TR.category_feature_id, TR.feature_id, TR.feature_name, TR.feature_value
112
+ FROM `tmp_result` AS TR
113
+ WHERE TR.category_feature_id = \'', arg_category_feature, '\'',
114
+ @where,
115
+ 'GROUP BY entity_id
116
+ )');
117
+
118
+ END IF;
119
+
120
+ PREPARE myquery FROM @query;
121
+ EXECUTE myquery;
122
+ DROP PREPARE myquery;
123
+
124
+ END
125
+ ";
126
+
127
+ if (!mysql_query($query, $cnx)) {
128
+ throw new Exception("Failed to create stored procedure");
129
+ }
130
+
131
+ mysql_close($cnx);
132
+
133
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.3-0.1.4.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ stepan
4
+ */
5
+ $installer = $this;
6
+
7
+ $installer->startSetup();
8
+
9
+
10
+ $attr_text=array(
11
+ 'specification' => 'Specification',
12
+ 'manufacturer' => 'Manufacturer',
13
+ 'ean' => 'EAN',
14
+ 'sku' => 'SKU'
15
+ );
16
+
17
+ foreach($attr_text as $key=>$value){
18
+ $data=array(
19
+ 'is_visible_on_front' => 1,
20
+ 'is_html_allowed_on_front' => 1
21
+ );
22
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
23
+ if ($id = $installer->getAttribute($entityTypeId, $key, 'attribute_id')) {
24
+ $installer->updateAttribute($entityTypeId, $id, $data);
25
+ }
26
+
27
+ }
28
+
29
+ $attr_filt=array(
30
+ 'manufacturer' => 'Manufacturer'
31
+ );
32
+
33
+ foreach($attr_filt as $key=>$value){
34
+ $data=array(
35
+ 'is_filterable' => 1,
36
+ 'is_global' => 1
37
+ );
38
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
39
+ if ($id = $installer->getAttribute($entityTypeId, $key, 'attribute_id')) {
40
+ $installer->updateAttribute($entityTypeId, $id, $data);
41
+ }
42
+
43
+ $sets = $installer->_conn->fetchAll('select * from '.$installer->getTable('eav/attribute_set').' where entity_type_id=?', $entityTypeId);
44
+ foreach ($sets as $set) {
45
+ $installer->addAttributeToSet($entityTypeId, $set['attribute_set_id'], 'Global', 'manufacturer');
46
+ }
47
+
48
+ }
49
+
50
+
51
+ //$installer->installEntities();
52
+
53
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.4-0.1.5.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+
6
+ $installer->startSetup();
7
+
8
+ $installer->run("
9
+ DROP TABLE IF EXISTS `stINch_import_status_statistic`;
10
+
11
+ CREATE TABLE stINch_import_status_statistic(
12
+ id int(11) NOT NULL auto_increment PRIMARY KEY,
13
+ start_import timestamp NOT NULL default '0000-00-00 00:00:00',
14
+ finish_import timestamp NOT NULL default '0000-00-00 00:00:00',
15
+ number_of_products int(11) default '0',
16
+ global_status_import varchar(255) default '',
17
+ detail_status_import varchar(255) default '',
18
+ error_report_message text not null default ''
19
+ );
20
+
21
+
22
+ ");
23
+ /*
24
+ DROP TABLE IF EXISTS `stINch_import_log;
25
+
26
+ CREATE TABLE `stINch_import_log`(
27
+ `entity_id` bigint NOT NULL auto_increment PRIMARY KEY,
28
+ `message_date` timestamp NOT NULL default '0000-00-00 00:00:00',
29
+ `message` text
30
+ );
31
+
32
+ */
33
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.5-0.1.6.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+
6
+ $installer->startSetup();
7
+
8
+ $installer->run("
9
+ ALTER IGNORE TABLE stINch_import_status_statistic
10
+ ADD COLUMN `import_type` ENUM('FULL', 'PRICE STOCK') default NULL after finish_import
11
+ ");
12
+
13
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.6-0.1.7.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ //прямое подключение к базе необходимо для добавления хранимки
6
+ $config = $installer->getConnection()->getConfig();
7
+ $cnx = mysql_connect($config['host'], $config['username'], $config['password']);
8
+ if (!$cnx) {
9
+ throw new Exception('Failed to connect to database.');
10
+ }
11
+
12
+ if (!mysql_select_db($config['dbname'])) {
13
+ throw new Exception('Failed to select a database.');
14
+ }
15
+
16
+ $installer->startSetup();
17
+
18
+ $installer->run("
19
+ ALTER IGNORE TABLE {$this->getTable('catalog_category_entity')}
20
+ ADD COLUMN `store_category_id` INT(11) UNSIGNED NULL
21
+ ");
22
+ $installer->run("
23
+ ALTER IGNORE TABLE {$this->getTable('catalog_category_entity')}
24
+ ADD INDEX `store_category_id` (`store_category_id`);
25
+ ");
26
+
27
+ $installer->run("
28
+ ALTER IGNORE TABLE {$this->getTable('catalog_category_entity')}
29
+ ADD COLUMN `parent_store_category_id` INT(11) UNSIGNED NULL
30
+ ");
31
+ $installer->run("
32
+ ALTER IGNORE TABLE {$this->getTable('catalog_category_entity')}
33
+ ADD INDEX `parent_store_category_id` (`parent_store_category_id`);
34
+ ");
35
+
36
+
37
+ $installer->run("DROP PROCEDURE IF EXISTS `filter_sinch_products_s`");
38
+
39
+ $query = "
40
+ CREATE PROCEDURE `filter_sinch_products_s`(
41
+ IN arg_table INT,
42
+ IN arg_category_id INT,
43
+ IN arg_image INT,
44
+ IN arg_category_feature INT,
45
+ IN arg_least INT,
46
+ IN arg_greatest INT
47
+ )
48
+ BEGIN
49
+ DROP TABLE IF EXISTS `tmp_result`;
50
+
51
+ CREATE TEMPORARY TABLE `tmp_result`(
52
+ `entity_id` int(10) unsigned,
53
+ `category_id` int(10) unsigned,
54
+ `product_id` int,
55
+ `sinch_category_id` int,
56
+ `name` varchar(255),
57
+ `image` varchar(255),
58
+ `supplier_id` int,
59
+ `category_feature_id` int,
60
+ `feature_id` int,
61
+ `feature_name` varchar(255),
62
+ `feature_value` text
63
+ );
64
+
65
+
66
+
67
+ IF arg_image = 1 THEN
68
+ INSERT INTO `tmp_result` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
69
+ (
70
+ SELECT E.entity_id, PCind.category_id, E.entity_id, PCind.category_id as `sinch_category`, PR.`product_name`, PR.main_image_url, PR.sinch_manufacturer_id, CF.category_feature_id, CF.category_feature_id, CF.`feature_name`, RV.`text`
71
+ FROM catalog_product_entity E
72
+ INNER JOIN catalog_category_product_index PCind
73
+ ON (E.entity_id = PCind.product_id)
74
+
75
+ inner join stINch_categories_mapping scm on PCind.category_id=scm.shop_entity_id
76
+ INNER JOIN stINch_categories_features CF
77
+ ON (scm.store_category_id=CF.store_category_id)
78
+ INNER JOIN stINch_products PR
79
+ ON (PR.store_product_id = E.store_product_id)
80
+ INNER JOIN stINch_product_features PF
81
+ ON (PR.sinch_product_id = PF.sinch_product_id )
82
+ INNER JOIN stINch_restricted_values RV
83
+ ON (PF.restricted_value_id=RV.restricted_value_id)
84
+ WHERE
85
+ scm.shop_entity_id = arg_category_id
86
+ AND PR.main_image_url <> ''
87
+ );
88
+ ELSE
89
+ INSERT INTO `tmp_result` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
90
+ (
91
+ SELECT E.entity_id, PCind.category_id, E.entity_id, PCind.category_id as `sinch_category`, PR.`product_name`, PR.main_image_url, PR.sinch_manufacturer_id, CF.category_feature_id, CF.category_feature_id, CF.`feature_name`, RV.`text`
92
+ FROM catalog_product_entity E
93
+ INNER JOIN catalog_category_product_index PCind
94
+ ON (E.entity_id = PCind.product_id)
95
+ inner join stINch_categories_mapping scm on PCind.category_id=scm.shop_entity_id
96
+ INNER JOIN stINch_categories_features CF
97
+ ON (scm.store_category_id=CF.store_category_id)
98
+ INNER JOIN stINch_products PR
99
+ ON (PR.store_product_id = E.store_product_id)
100
+ INNER JOIN stINch_product_features PF
101
+ ON (PR.sinch_product_id = PF.sinch_product_id )
102
+ INNER JOIN stINch_restricted_values RV
103
+ ON (PF.restricted_value_id=RV.restricted_value_id)
104
+ WHERE
105
+ scm.shop_entity_id = arg_category_id
106
+
107
+ );
108
+
109
+ END IF;
110
+
111
+ IF (SELECT COUNT(*) FROM `FilterListOfFeatures`) > 0 THEN
112
+ SET @query = CONCAT('INSERT INTO `SinchFilterResult_', arg_table, '` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
113
+ (
114
+ SELECT TR.entity_id, TR.category_id, TR.product_id, TR.sinch_category_id, TR.`name`, TR.`image`, TR.supplier_id, TR.category_feature_id, TR.feature_id, TR.feature_name, TR.feature_value
115
+ FROM `tmp_result` AS TR
116
+ INNER JOIN `FilterListOfFeatures` AS LF ON (TR.category_feature_id = LF.category_feature_id)
117
+ WHERE TR.feature_value LIKE LF.feature_value GROUP BY entity_id
118
+ )');
119
+
120
+ ELSE
121
+ IF (arg_least IS NOT null AND arg_greatest IS NOT null) THEN
122
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' AND TR.feature_value <', arg_greatest, ' ');
123
+ ELSE
124
+ IF arg_least IS null THEN
125
+ SET @where = CONCAT(' AND TR.feature_value < ', arg_greatest, ' ');
126
+ ELSE
127
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' ');
128
+ END IF;
129
+ END IF;
130
+
131
+ SET @query = CONCAT('INSERT INTO `SinchFilterResult_', arg_table, '` (entity_id, category_id, product_id, sinch_category_id, `name`, `image`, supplier_id, category_feature_id, feature_id, feature_name, feature_value)
132
+ (
133
+ SELECT TR.entity_id, TR.category_id, TR.product_id, TR.sinch_category_id, TR.`name`, TR.`image`, TR.supplier_id, TR.category_feature_id, TR.feature_id, TR.feature_name, TR.feature_value
134
+ FROM `tmp_result` AS TR
135
+ WHERE TR.category_feature_id = \'', arg_category_feature, '\'',
136
+ @where,
137
+ 'GROUP BY entity_id
138
+ )');
139
+
140
+ END IF;
141
+
142
+ PREPARE myquery FROM @query;
143
+ EXECUTE myquery;
144
+ DROP PREPARE myquery;
145
+
146
+ END
147
+ ";
148
+
149
+ if (!mysql_query($query, $cnx)) {
150
+ throw new Exception("Failed to create stored procedure");
151
+ }
152
+
153
+ mysql_close($cnx);
154
+
155
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/stock_price_sinch_import_start_ajax.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $baseDir = dirname(__FILE__);
3
+ require $baseDir . '/../../../../../app/Mage.php';
4
+
5
+ Mage::app();
6
+
7
+ $import=Mage::getModel('sinchimport/sinch');
8
+
9
+
10
+ $import->run_stock_price_sinch_import();
11
+
12
+ $import->addImportStatus('Stock Price Finish import', 1);
13
+
14
+ ?>
app/design/frontend/default/default/layout/sinchimport.xml ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+
4
+ <sinchimport_product_view>
5
+ <!-- <update handle="catalog_product_view" /> -->
6
+ <!-- Mage_Catalog -->
7
+ <reference name="root">
8
+ <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
9
+ </reference>
10
+ <reference name="head">
11
+ <action method="addJs"><script>varien/product.js</script></action>
12
+ <action method="addCss"><stylesheet>css/view_table.css</stylesheet></action>
13
+ <action method="addItem"><type>skin_js</type><name>js/product_view.js</name></action>
14
+ <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
15
+ <action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
16
+ <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
17
+ </reference>
18
+ <reference name="content">
19
+ <block type="catalog/product_view" name="product.info" template="/sinchimport/view.phtml">
20
+ <!--
21
+ <action method="addReviewSummaryTemplate"><type>default</type><template>review/helper/summary.phtml</template></action>
22
+ <action method="addReviewSummaryTemplate"><type>short</type><template>review/helper/summary_short.phtml</template></action>
23
+ <action method="addReviewSummaryTemplate"><type>...</type><template>...</template></action>
24
+ -->
25
+ <block type="catalog/product_view_media" name="product.info.media" as="media" template="/sinchimport/media.phtml"/>
26
+ <block type="core/text_list" name="alert.urls" as="alert_urls" />
27
+
28
+ <action method="setTierPriceTemplate"><template>catalog/product/view/tierprices.phtml</template></action>
29
+
30
+ <block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml">
31
+ <action method="setColumnCount"><columns>4</columns></action>
32
+ <action method="setItemLimit"><type>upsell</type><limit>4</limit></action>
33
+ </block>
34
+
35
+ <block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />
36
+ <block type="catalog/product_view_description" name="product.description" as="description" template="catalog/product/view/description.phtml"/>
37
+ <block type="catalog/product_view_attributes" name="product.attributes" as="additional" template="catalog/product/view/attributes.phtml"/>
38
+ <block type="catalog/product_view" name="product.info.addto" as="addto" template="catalog/product/view/addto.phtml"/>
39
+ <block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>
40
+
41
+ <block type="catalog/product_view" name="product.info.options.wrapper" as="product_options_wrapper" template="catalog/product/view/options/wrapper.phtml">
42
+ <block type="core/template" name="options_js" template="catalog/product/view/options/js.phtml"/>
43
+ <block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
44
+ <action method="addOptionRenderer"><type>text</type><block>catalog/product_view_options_type_text</block><template>catalog/product/view/options/type/text.phtml</template></action>
45
+ <action method="addOptionRenderer"><type>file</type><block>catalog/product_view_options_type_file</block><template>catalog/product/view/options/type/file.phtml</template></action>
46
+ <action method="addOptionRenderer"><type>select</type><block>catalog/product_view_options_type_select</block><template>catalog/product/view/options/type/select.phtml</template></action>
47
+ <action method="addOptionRenderer"><type>date</type><block>catalog/product_view_options_type_date</block><template>catalog/product/view/options/type/date.phtml</template></action>
48
+ </block>
49
+ <block type="core/html_calendar" name="html_calendar" as="html_calendar" template="page/js/calendar.phtml"/>
50
+ </block>
51
+ <block type="catalog/product_view" name="product.info.options.wrapper.bottom" as="product_options_wrapper_bottom" template="catalog/product/view/options/wrapper/bottom.phtml">
52
+ <action method="insert"><block>product.tierprices</block></action>
53
+ <block type="catalog/product_view" name="product.clone_prices" as="prices" template="catalog/product/view/price_clone.phtml"/>
54
+ <action method="append"><block>product.info.addtocart</block></action>
55
+ </block>
56
+
57
+ <block type="core/template_facade" name="product.info.container1" as="container1">
58
+ <action method="setDataByKey"><key>alias_in_layout</key><value>container1</value></action>
59
+ <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
60
+ <action method="append"><block>product.info.options.wrapper</block></action>
61
+ <action method="append"><block>product.info.options.wrapper.bottom</block></action>
62
+ </block>
63
+ <block type="core/template_facade" name="product.info.container2" as="container2">
64
+ <action method="setDataByKey"><key>alias_in_layout</key><value>container2</value></action>
65
+ <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
66
+ <action method="append"><block>product.info.options.wrapper</block></action>
67
+ <action method="append"><block>product.info.options.wrapper.bottom</block></action>
68
+ </block>
69
+ <action method="unsetCallChild"><child>container1</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
70
+ <action method="unsetCallChild"><child>container2</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
71
+ </block>
72
+ </reference>
73
+ <reference name="right">
74
+ <block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
75
+ </reference>
76
+ </sinchimport_product_view>
77
+ <!--
78
+ Compare products page
79
+ -->
80
+
81
+ <catalog_product_compare_index translate="label">
82
+ <label>Catalog Product Compare List</label>
83
+ <!-- Mage_Catalog -->
84
+ <reference name="root">
85
+ <action method="setTemplate"><template>page/popup.phtml</template></action>
86
+ </reference>
87
+ <reference name="head">
88
+ <action method="addJs"><script>scriptaculous/scriptaculous.js</script></action>
89
+ <action method="addJs"><script>varien/product.js</script></action>
90
+ </reference>
91
+ <reference name="content">
92
+ <block type="catalog/product_compare_list" name="sinch.catalog.compare.list" template="sinchimport/list.phtml"/>
93
+ </reference>
94
+ <reference name="content">
95
+ <remove name="catalog.compare.list"/>
96
+ </reference>
97
+
98
+ </catalog_product_compare_index>
99
+
100
+ <customer_account_index>
101
+ <reference name="right">
102
+ <action method="unsetChild"><name>catalog.compare.sidebar</name></action>
103
+ </reference>
104
+ </customer_account_index>
105
+
106
+ <!--
107
+ Product view
108
+ -->
109
+
110
+ </layout>
app/design/frontend/default/default/template/sinchimport/list.phtml ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-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 design_default
22
+ * @package Mage
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <div class="page-head button-level">
28
+ <h3><?php echo $this->__('Compare Products') ?></h3>
29
+ <a href="#" class="link-print right" onclick="print();"><?php echo $this->__('Print This Page') ?></a>
30
+ </div>
31
+ <?php $_total=$this->getItems()->getSize() ?>
32
+ <?php if($_total): ?>
33
+ <div class="compare-products">
34
+ <table cellspacing="0" class="data-table box-table catalog-listing" id="product_comparison">
35
+ <?php if ($_total>2): ?>
36
+ <tbody class="remove-buttons">
37
+ <tr>
38
+ <?php $_i=0 ?>
39
+ <?php foreach($this->getItems() as $_item): ?>
40
+ <?php if($_i++%10==0): ?>
41
+ <td>&nbsp;</td>
42
+ <?php endif; ?>
43
+ <td><a href="#" onclick="setLocation('<?php echo $this->helper('catalog/product_compare')->getRemoveUrl($_item) ?>');window.opener.location.reload();"><img src="<?php echo $this->getSkinUrl('images/chart_remove.gif') ?>" alt="<?php echo $this->__('Remove Product') ?>" /></a></td>
44
+ <?php endforeach; ?>
45
+ </tr>
46
+ </tbody>
47
+ <?php endif ?>
48
+ <tbody>
49
+ <tr class="first">
50
+ <?php $_i=0 ?>
51
+ <?php foreach($this->getItems() as $_item): ?>
52
+ <?php if($_i++%10==0): ?>
53
+ <td class="label">&nbsp;</td>
54
+ <?php endif; ?>
55
+ <td>
56
+ <a href="#" onclick="setPLocation('<?php echo $_item->getProductUrl() ?>', true)" title="<?php echo $this->htmlEscape($_item->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
57
+ <h5><a href="#" onclick="setPLocation('<?php echo $_item->getProductUrl() ?>', true)" title="<?php echo $this->htmlEscape($_item->getName()) ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a></h5>
58
+ <?php echo $this->getReviewsSummaryHtml($_item, 'short') ?>
59
+ <?php echo $this->getPriceHtml($_item, true) ?>
60
+ <?php if($_item->isSaleable()): ?>
61
+ <button class="form-button" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><?php echo $this->__('Add to Cart') ?></span></button><br/>
62
+ <?php else: ?>
63
+ <div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
64
+ <?php endif; ?>
65
+ <?php if ($this->helper('wishlist')->isAllow()) : ?>
66
+ <a href="#" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToWishlistUrl($_item) ?>', true)" class="link-cart"><small><?php echo $this->__('Add to Wishlist') ?></small></a>
67
+ <?php endif; ?>
68
+ </td>
69
+ <?php endforeach; ?>
70
+ </tr>
71
+ </tbody>
72
+ <tbody>
73
+ <?php /**************************************************** Sinch attributes ****************************************/ ?>
74
+ <?php $prod_attributes=$this->getSinchAttributes(); ?>
75
+ <?php foreach ($prod_attributes as $_attribute): ?>
76
+
77
+ <?php if($this->getSinchAttributeName($_attribute)) : ?>
78
+ <tr>
79
+ <?php $countItems = 0; ?>
80
+ <?php $_i=0; ?>
81
+
82
+ <?php foreach($this->getItems() as $_item) : ?>
83
+ <?php if ($this->getSinchProductAttributeValue($_item, $_attribute)) : $countItems++; endif; ?>
84
+ <?php endforeach; // Items (for count number) ?>
85
+ <?php foreach($this->getItems() as $_item) : ?>
86
+ <?php if ($countItems > 0 ) : ?>
87
+ <?php if($_i++%10==0): ?><td class="label"><?php echo $this->getSinchAttributeName($_attribute) ?></td><?php endif; ?>
88
+ <td>
89
+ <?php echo nl2br($this->getSinchProductAttributeValue($_item, $_attribute))."&nbsp;"; //.var_dump($this->getSinchProductAttributeValue($_item, $_attribute)); ?>
90
+ </td>
91
+ <?php endif; //AttributeValue ?>
92
+
93
+ <?php endforeach; // Items ?>
94
+ </tr>
95
+ <?php endif; //AttributeName ?>
96
+
97
+ <?php endforeach; ?>
98
+ <?php /**************************************************** End Sinch attributes ****************************************/ ?>
99
+
100
+ <?php /* foreach ($this->getAttributes() as $_attribute): ?>
101
+ <tr>
102
+ <?php $_i=0 ?>
103
+ <?php foreach($this->getItems() as $_item): ?>
104
+ <?php if($_i++%10==0): ?>
105
+ <td class="label"><?php echo $this->__($_attribute->getFrontendLabel()) ?><? //echo " "; print_r($_attribute->getFrontendLabel()); ?></td>
106
+ <?php endif; ?>
107
+ <td>
108
+ <?php switch ($_attribute->getAttributeCode()) {
109
+ case "price": ?>
110
+ <?php echo $this->getPriceHtml($_item, true) ?>
111
+ <?php break;
112
+ case "small_image": ?>
113
+ <img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" />
114
+ <?php break;
115
+ default: ?>
116
+ <?php echo nl2br($this->getProductAttributeValue($_item, $_attribute)) ?>
117
+ <?php break;
118
+ } ?>
119
+ </td>
120
+ <?php endforeach; ?>
121
+ </tr>
122
+ <?php endforeach; */ ?>
123
+ </tbody>
124
+ <tbody class="attribute-cart">
125
+ <tr>
126
+ <?php $_i=0 ?>
127
+ <?php foreach($this->getItems() as $_item): ?>
128
+ <?php if($_i++%10==0): ?>
129
+ <td class="label">&nbsp;</td>
130
+ <?php endif; ?>
131
+ <td>
132
+ <?php echo $this->getPriceHtml($_item, true) ?>
133
+ <?php if($_item->isSaleable()): ?>
134
+ <button class="form-button" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><?php echo $this->__('Add to Cart') ?></span></button><br/>
135
+ <?php else: ?>
136
+ <div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
137
+ <?php endif; ?>
138
+ <?php if ($this->helper('wishlist')->isAllow()) : ?>
139
+ <a href="#" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToWishlistUrl($_item) ?>', true)" class="link-cart"><small><?php echo $this->__('Add to Wishlist') ?></small></a>
140
+ <?php endif; ?>
141
+ </td>
142
+ <?php endforeach; ?>
143
+ </tr>
144
+ </tbody>
145
+ </table>
146
+ <div class="button-set">
147
+ <button class="form-button" onclick="window.close();"><span><?php echo $this->__('Close Window') ?></span></button>
148
+ </div>
149
+ </div>
150
+ <script type="text/javascript">decorateTable('product_comparison');</script>
151
+ <?php else: ?>
152
+ <script type="text/javascript">window.close();</script>
153
+ <?php endif; ?>
app/design/frontend/default/default/template/sinchimport/media.phtml ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-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 design_default
22
+ * @package Mage
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product media data template
29
+ *
30
+ * @see Mage_Catalog_Block_Product_View_Media
31
+ */
32
+ ?>
33
+
34
+ <?php
35
+ $_product = $this->getProduct();
36
+ $_helper = $this->helper('catalog/output');
37
+ $_productDescriptionHelper = $this->helper('sinchimport/getdata')->getProductDescription($_product);
38
+
39
+ ?>
40
+ <?php //if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
41
+ <p class="product-image-zoom">
42
+ <?php
43
+ $_img = '<img id="image" src="'. $this->helper('catalog/image')->init($_product, 'image') .'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
44
+ echo $_helper->productAttribute($_product, $_img, 'image');
45
+ ?>
46
+ </p>
47
+ <p class="a-center" id="track_hint"><?php echo $this->__('Double click on above image to view full picture') ?></p>
48
+
49
+ <div class="image-zoom zoom" id="track_outer">
50
+ <img id="zoom_out" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_out.gif') ?>" alt="<?php echo $this->__('Zoom Out') ?>" class="btn-zoom-out" />
51
+ <div id="track">
52
+ <div id="handle"></div>
53
+ </div>
54
+ <img id="zoom_in" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_in.gif') ?>" alt="<?php echo $this->__('Zoom In') ?>" class="btn-zoom-in" />
55
+ </div>
56
+ <script type="text/javascript">
57
+ Event.observe(window, 'load', function() {
58
+ product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
59
+ });
60
+ </script>
61
+ <?php /*else: ?>
62
+ <?php
63
+ $_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(265).'" alt="'.$this->htmlEscape($_product->getImageLabel()).'" />';
64
+ echo $_helper->productAttribute($_product, $_img, 'image')
65
+ ?>
66
+ <?php endif; */?>
67
+ <?php if (count($_productDescriptionHelper->getGalleryPhotos()) > 0): ?>
68
+ <div class="more-views">
69
+ <h4><?php echo $this->__('More Views') ?></h4>
70
+ <ul>
71
+ <?php foreach ($_productDescriptionHelper->getGalleryPhotos() as $_image): ?>
72
+ <li>
73
+ <a href="#" onclick="popWin('<?php echo $_image['pic'] ?>', 'gallery', 'width=<?php echo $_image['width']?>,height=<?php echo $_image['height']?>,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;"><img src="<?php echo $_image['thumb'] ?>" alt="<?php echo $_productDescriptionHelper->getProductName()?>" title="<?php echo $_productDescriptionHelper->getProductName()?>" /></a>
74
+ </li>
75
+ <?php endforeach; ?>
76
+ </ul>
77
+ </div>
78
+ <?php else :?>
79
+ <div class="more-views">
80
+ <h2><?php echo $this->__('More Views') ?></h2>
81
+ <ul>
82
+ <?php foreach ($this->getGalleryImages() as $_image): ?>
83
+ <li>
84
+ <a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
85
+ </li>
86
+ <?php endforeach; ?>
87
+ </ul>
88
+ </div>
89
+ <?php endif; ?>
app/design/frontend/default/default/template/sinchimport/view.phtml ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-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 design_default
22
+ * @package Mage
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product view template
29
+ *
30
+ * @see Mage_Catalog_Block_Product_View
31
+ * @see Mage_Review_Block_Product_View
32
+ */
33
+ ?>
34
+ <?php
35
+ $_helper = $this->helper('catalog/output');
36
+ $_product = $this->getProduct();
37
+ $_catIds = $_product->getCategoryIds();
38
+ $_catId = $_catIds[0];
39
+
40
+ $_productDescriptionHelper = $this->helper('sinchimport/getdata')->getProductDescription($_product);
41
+ $message = $_productDescriptionHelper->getError();
42
+ if ($message){
43
+ $this->getMessagesBlock()->addError($_productDescriptionHelper->getError());
44
+ }
45
+ $specificationArray = $_productDescriptionHelper->getProductDescriptionList();
46
+ $sinchSpecification=$_productDescriptionHelper->getProductSpecifications();
47
+ $relatedProductsList = $_productDescriptionHelper->getRelatedProducts();
48
+ // echo "related= ".$_productDescriptionHelper->getVendor();
49
+ ?>
50
+ <script type="text/javascript">
51
+ var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
52
+ </script>
53
+ <div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
54
+ <div style="display:none"><?php $message=$_productDescriptionHelper->hasSystemError(); if ($message){ echo $message; } ?></div>
55
+ <div class="product-info-box product-view">
56
+ <div class="product-essential">
57
+ <form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
58
+
59
+ <div class="product-img-box">
60
+ <?php echo $this->getChildHtml('media'); ?>
61
+ </div>
62
+
63
+ <div class="product-shop">
64
+ <?php if (!$_productDescriptionHelper->hasError()) : ?>
65
+ <h3 class="product-name"><?php echo $_productDescriptionHelper->getProductName()?></h3>
66
+ <?php else :?>
67
+ <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name')?></h1>
68
+ <?php endif;?>
69
+ <?php if ($this->canEmailToFriend()): ?>
70
+ <a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>"><?php echo $this->__('Email to a Friend') ?></a><br />
71
+ <?php endif; ?>
72
+
73
+ <?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
74
+
75
+ <fieldset class="no-display">
76
+ <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
77
+ <input type="hidden" name="related_product" id="related-products-field" value="" />
78
+ </fieldset>
79
+ <?php if (!$_productDescriptionHelper->hasError()):?>
80
+ <div><b><?php echo $this->helper('sinchimport/getdata')->__('Brand:')?></b><?php echo $_productDescriptionHelper->getVendor();?></div>
81
+ <div><b><?php echo $this->helper('sinchimport/getdata')->__('Product code:')?></b><?php echo $_productDescriptionHelper->getMPN();?></div>
82
+ <div><b><?php echo $this->helper('sinchimport/getdata')->__('EAN/UPC code:')?></b><?php echo $_productDescriptionHelper->getEAN();?></div>
83
+ <div><b><?php echo $this->helper('sinchimport/getdata')->__('Category:')?></b><?php echo Mage::getModel('catalog/category')->load($_catId)->getName()?></div>
84
+ <?php endif;?>
85
+ <?php echo $this->getChildHtml('alert_urls') ?>
86
+ <?php echo $this->getChildHtml('product_type_data') ?>
87
+ <?php echo $this->getTierPriceHtml() ?>
88
+
89
+ <?php if (!$this->hasOptions()):?>
90
+ <div class="add-to-holder">
91
+ <?php if($_product->isSaleable()): ?>
92
+ <?php echo $this->getChildHtml('addtocart') ?>
93
+ <?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
94
+ <span class="add-or"><?php echo $this->__('OR') ?></span>
95
+ <?php endif; ?>
96
+ <?php endif; ?>
97
+ <?php echo $this->getChildHtml('addto') ?>
98
+ </div>
99
+ <?php else:?>
100
+ <?php echo $this->getChildHtml('addto') ?>
101
+ <?php endif; ?>
102
+
103
+ <?php if ($_product->getShortDescription() && $_productDescriptionHelper->hasError()):?>
104
+ <div class="short-description">
105
+ <h2><?php echo $this->__('Quick Overview') ?></h2>
106
+ <div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
107
+ </div>
108
+ <?php else :?>
109
+ <div class="divider"></div>
110
+ <?php endif;?>
111
+
112
+
113
+ <?php echo $this->getChildHtml('other');?>
114
+ <?php if ($_product->isSaleable() && $this->hasOptions()):?>
115
+ <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
116
+ <?php endif;?>
117
+
118
+ </div>
119
+ <div class="clear"></div>
120
+ <?php if ($_product->isSaleable() && $this->hasOptions()):?>
121
+ <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
122
+ <?php endif;?>
123
+ </form>
124
+ <script type="text/javascript">
125
+ var productAddToCartForm = new VarienForm('product_addtocart_form');
126
+ productAddToCartForm.submit = function(){
127
+ if (this.validator.validate()) {
128
+ this.form.submit();
129
+ }
130
+ }.bind(productAddToCartForm);
131
+
132
+ function changeTab(id){
133
+ for(var i=0;i<4;i++){
134
+ var tab_cont = (document.getElementById) ? document.getElementById("tab_cont_"+i) : eval('document.all["tab_cont_'+i+'"]');
135
+ var tab = (document.getElementById) ? document.getElementById("tab_"+i) : eval('document.all["tab_'+i+'"]');
136
+
137
+ if (tab_cont!=null && tab!=null) {
138
+ if(i==id){
139
+ tab_cont.style.display="";
140
+ tab.className="prod_doc_tab_div_sel";
141
+ } else {
142
+ tab_cont.style.display="none";
143
+ tab.className="prod_doc_tab_div";
144
+ }
145
+ }
146
+ }
147
+ }
148
+ </script>
149
+ </div>
150
+ <?php if (!$_productDescriptionHelper->hasError()) : ?>
151
+ <div class="description_b">
152
+ <div class="short_product_description"><?php echo $_productDescriptionHelper->getShortProductDescription() ?></div>
153
+ <?php
154
+ if (strlen($_productDescriptionHelper->getFullProductDescription())>450){
155
+ $firstPart = str_replace("\\n", "<br>", substr($_productDescriptionHelper->getFullProductDescription(), 0, 400));
156
+ $space = strrpos($firstPart, " ");
157
+ $dot = strrpos($firstPart, ".");
158
+ $column = strrpos($firstPart, ",");
159
+ $spanTagStart = strrpos($firstPart, "<span");
160
+ $spanTagEND = strrpos($firstPart, "</span>");
161
+
162
+ if ($space-5>$dot && $space-5>$column){
163
+ $firstPart = substr($firstPart, 0, $space);
164
+ }
165
+ else{
166
+ $firstPart = $column > $dot ? substr($firstPart, 0, $column) : substr($firstPart, 0, $dot);
167
+ }
168
+ if ((int)$spanTagEND<$spanTagStart){
169
+ $firstPart = substr($firstPart, 0, $spanTagStart);
170
+ }
171
+
172
+ }
173
+
174
+ ?>
175
+ <div class="product_description">
176
+ <?php if (isset($firstPart)):?>
177
+ <span id="more_link"><?php echo $firstPart." "?>... <a class="more_link" href="javascript: showMore();"><?php echo htmlentities(' More>>>')?></a></span>
178
+ <span id="more_info" style="display: none;"><?php echo str_replace("\\n", "<br>", $_productDescriptionHelper->getFullProductDescription());?><a class="more_link" href="javascript: hideMore();"><?php echo htmlentities(' <<<Less')?></a></span>
179
+ <?php else: ?>
180
+ <span><?php echo str_replace("\\n", "<br>", $_productDescriptionHelper->getFullProductDescription());?></span>
181
+ <?php endif?>
182
+ </div >
183
+ </div>
184
+ <?php endif;?>
185
+ <div class="product-collateral">
186
+ <?php if ($_productDescriptionHelper->hasError()) :?>
187
+ <?php echo $this->getChildHtml('description') ?>
188
+ <?php else :
189
+ $tab_class0=$tab_class1=$tab_class2=$tab_class3='prod_doc_tab_div';
190
+ $data_tab_style0=$data_tab_style1=$data_tab_style2=$data_tab_style3="display:none";
191
+ if($sinchSpecification || $sinchSpecification!=''){
192
+ $tab_class0='prod_doc_tab_div_sel';
193
+ $data_tab_style0='';
194
+ }elseif(!empty($specificationArray)){
195
+ $tab_class1='prod_doc_tab_div_sel';
196
+ $data_tab_style1='';
197
+ }elseif($_catId && array_key_exists($_catId, $relatedProductsList)){
198
+ $tab_class2='prod_doc_tab_div_sel';
199
+ $data_tab_style2='';
200
+ }elseif(!empty($relatedProductsList)){
201
+ $tab_class3='prod_doc_tab_div_sel';
202
+ $data_tab_style3='';
203
+ }
204
+ ?>
205
+ <? if(false): ?>
206
+ <table cellspacing="0" cellpadding="0" width="100%">
207
+ <tr>
208
+ <td>
209
+ <table cellspacing="0" cellpadding="0" class="prod_doc_tabs_row">
210
+ <tr>
211
+ <td class="prod_doc_tabs_space">&nbsp;</td>
212
+ <?php if ($sinchSpecification || $sinchSpecification!=''):?>
213
+ <td class="prod_doc_tab"><div id="tab_0" class="<?php echo $tab_class0 ?>" onclick="changeTab(0)"><?php echo $this->helper('sinchimport/getdata')->__('Specification') ?></div></td>
214
+ <?php endif?>
215
+ <?php if (!empty($specificationArray)):?>
216
+ <td class="prod_doc_tab"><div id="tab_1" class="<?php echo $tab_class1 ?>" onclick="changeTab(1)"><?php echo $this->helper('sinchimport/getdata')->__('Star features') ?></div></td>
217
+ <?php endif?>
218
+ <?php if ($_catId && array_key_exists($_catId, $relatedProductsList)):?>
219
+ <td class="prod_doc_tab"><div id="tab_2" class="prod_doc_tab_div" onclick="changeTab(2)"><?php echo $this->helper('sinchimport/getdata')->__('Alternatives') ?></div></td>
220
+ <?php endif?>
221
+ <?php if (!empty($relatedProductsList)):?>
222
+ <td class="prod_doc_tab"><div id="tab_3" class="prod_doc_tab_div" onclick="changeTab(3)"><?php echo $this->helper('sinchimport/getdata')->__('Options') ?></div></td>
223
+ <?php endif?>
224
+ <td class="prod_doc_tabs_space" style="width:auto!important">&nbsp;</td>
225
+ </tr>
226
+ </table>
227
+ </td>
228
+ </tr>
229
+ <tr>
230
+ <td>
231
+ <table cellspacing="0" cellpadding="2" class="prod_doc_content">
232
+ <tr>
233
+ <td class="prod_doc_content_cell">
234
+ <!-- ZERO TAB's CONTENT (VISIBLE BY DEFAULT) -->
235
+ <table id="tab_cont_0" cellspacing="6" cellpadding="0" width="100%" style="<?php echo $data_tab_style0; ?>">
236
+ <tr>
237
+ <td width="50%" valign="top">
238
+ <table cellspacing="0" cellpadding="2" class="prod_doc_table">
239
+ <tr><td>
240
+ <?php echo $sinchSpecification; ?>
241
+ </td></tr>
242
+ </table>
243
+ </td>
244
+ </tr>
245
+ </table>
246
+
247
+ <!-- FIRST TAB's CONTENT (VISIBLE BY DEFAULT) -->
248
+ <table id="tab_cont_1" cellspacing="6" cellpadding="0" width="100%" style="<?php echo $data_tab_style1; ?>">
249
+ <tr>
250
+ <td width="50%" valign="top">
251
+ <table cellspacing="0" cellpadding="2" class="prod_doc_table">
252
+
253
+ <?php foreach($specificationArray as $key => $value):?>
254
+ <tr>
255
+ <td colspan="2" class="prod_doc_item_head"><?php echo $key?></td>
256
+ <td class="prod_doc_item_descr"><?php if($value == "Y"){
257
+ echo '<img border="0" alt="" src="http://prf.icecat.biz/imgs/yes.gif"/>';
258
+ }
259
+ else if ($value == "N"){
260
+ echo '<img border="0" alt="" src="http://prf.icecat.biz/imgs/no.gif"/>';
261
+ }
262
+ else{
263
+ echo str_replace("\\n", "<br>",$value);
264
+ }
265
+ ?></td>
266
+ </tr>
267
+ <?php endforeach;?>
268
+ </table>
269
+ </td>
270
+ </tr>
271
+ </table>
272
+ <!-- SECOND TAB's CONTENT (HIDDEN BY DEFAULT) -->
273
+ <table id="tab_cont_2" cellspacing="6" cellpadding="0" width="100%" style="<?php echo $data_tab_style2; ?>">
274
+ <tr>
275
+ <td>
276
+ <table cellspacing="1" cellpadding="5" class="prod_alt_table" width="100%" >
277
+ <tr>
278
+ <td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Brand') ?></td>
279
+ <td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Image') ?></td>
280
+ <td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Article code') ?></td>
281
+ <td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Product name') ?></td>
282
+ </tr>
283
+ <?php if ($_catId && array_key_exists($_catId, $relatedProductsList)):?>
284
+ <?php foreach($relatedProductsList[$_catId] as $product):?>
285
+ <tr>
286
+ <?php if($product['supplier_thumb']&&($product['supplier_thumb']!='')): ?>
287
+ <td><img src="<?php echo $product['supplier_thumb']?>" /></td>
288
+ <?php else :?>
289
+ <td><?php echo $product['supplier_name']?></td>
290
+ <?php endif ?>
291
+ <td><a href="<?php echo $product['url']?>"><img src="<?php echo $product['thumb']?>" /></a></td>
292
+ <td><?php echo $product['mpn']?></td>
293
+ <td><a href="<?php echo $product['url']?>" class="prod_link_small"><?php echo $product['name']?></a></td>
294
+ </tr>
295
+ <?php endforeach?>
296
+ <?php else: ?>
297
+ <tr><td></>No Alternative proposals for Current product avaible</td></tr>
298
+ <?php endif?>
299
+ </table>
300
+ </td>
301
+ </tr>
302
+ </table>
303
+ <!-- THIRD TAB's CONTENT (HIDDEN BY DEFAULT) -->
304
+ <table id="tab_cont_3" cellspacing="6" cellpadding="0" width="100%" style="<?php echo $data_tab_style3; ?>">
305
+ <tr>
306
+ <td>
307
+
308
+ <table cellspacing="1" cellpadding="5" width="100%" class="prod_alt_table">
309
+ <tr>
310
+ <td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Brand') ?></td>
311
+ <td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Image') ?></td>
312
+ <td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Article code') ?></td>
313
+ <td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Product name') ?></td>
314
+ </tr>
315
+ <?php if (!empty($relatedProductsList)):?>
316
+ <?php foreach($relatedProductsList as $categoryId => $productsArray):?>
317
+ <?php if ($categoryId == $_catId){
318
+ continue;
319
+ }?>
320
+ <?php if (!is_string($categoryId)):?>
321
+ <tr>
322
+ <td class="prod_doc_item_head2" colspan="4"><?php echo is_string($categoryId)? '' : Mage::getSingleton('catalog/category')->load($categoryId)->getName() ?></td>
323
+
324
+ </tr>
325
+ <?php endif?>
326
+ <?php foreach($productsArray as $product):?>
327
+ <tr>
328
+ <?php if($product['supplier_thumb']&&($product['supplier_thumb']!='')): ?>
329
+ <td><img src="<?php echo $product['supplier_thumb']?>" /></td>
330
+ <?php else :?>
331
+ <td><?php echo $product['supplier_name']?></td>
332
+ <?php endif ?>
333
+ <td><a href="<?php echo $product['url']?>"><img src="<?php echo $product['thumb']?>" /></a></td>
334
+ <td><?php echo $product['mpn']?></td>
335
+ <td><a href="<?php echo $product['url']?>" class="prod_link_small"><?php echo $product['name']?></a></td>
336
+ </tr>
337
+ <?php endforeach ?>
338
+ <?php endforeach ?>
339
+ <?php else: ?>
340
+ <tr><td></>No Related proposals for Current product avaible</td></tr>
341
+ <?php endif?>
342
+ </table>
343
+ </td>
344
+ </tr>
345
+ </table>
346
+ <!-- EOF -->
347
+ </td>
348
+ </tr>
349
+ </table>
350
+ <?php endif; ?>
351
+ </td>
352
+ </tr>
353
+ </table>
354
+ <?php endif;?>
355
+ <?php if ($_additional = $this->getChildHtml('additional')):?>
356
+ <div class="collateral-box">
357
+ <?php echo $_additional ?>
358
+ </div>
359
+ <?php endif;?>
360
+ <?php echo $this->getChildHtml('upsell_products') ?>
361
+ <?php echo $this->getChildHtml('product_additional_data') ?>
362
+ </div>
363
+ </div>
app/etc/modules/Bintime_Sinchimport.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <Bintime_Sinchimport>
6
+ <active>true</active>
7
+ <codePool>local</codePool>
8
+ </Bintime_Sinchimport>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>stockinthechannel2012</name>
4
+ <version>1.0.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Stock In The Channel to Magento Connector - Sell virtual stock - drop ship ecommerce</summary>
10
+ <description>StockInTheChannel has released a free connector to Magento&amp;#xD;&#xD;
11
+ What you get&amp;#xD;&#xD;
12
+ A site full of products with stock, prices, product descriptions, categories, attribute filters, images, product comparison, related products and more pumped in to Magento automatically.&amp;#xD;&#xD;
13
+ A tool to manage the feed &#x2013; see screenshot&amp;#xD;&#xD;
14
+ The ability to see your buy prices as you browse Sinch&amp;#xD;&#xD;
15
+ Free support and advice to help you get it working&amp;#xD;</description>
16
+ <notes>&lt;p&gt;This has been out to the market for 6 months and is only now being released via Magento Connect. As such it is stable&lt;/p&gt;&#xD;
17
+ &#xD;
18
+ &lt;p&gt;Installation guides will help you get it working quickly&lt;/p&gt;</notes>
19
+ <authors><author><name>stockinchannel</name><user>stockinchannel</user><email>marketing@stockinthechannel.com</email></author></authors>
20
+ <date>2012-04-02</date>
21
+ <time>13:54:55</time>
22
+ <contents><target name="magelocal"><dir name="Bintime"><dir name="Sinchimport"><dir name="Block"><file name="Importhistory.php" hash="b4208c2a73d0c067d1a66d75fc530bf4"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="239d86cde4cf08f5f50183df26e89eea"/></dir><file name="View.php" hash="97cf41b42afc26d46ee3d876721601c7"/></dir><file name="List.php" hash="64d25335628adb9ace3542204e0dc1e3"/><dir name="Product"><dir name="View"><file name="Media.php" hash="401c8afd5af4d0edda0929e8df4d6cd4"/></dir></dir><file name="Startimportbutton.php" hash="7dafc8567377960378db533fc690fc07"/><file name="Startstockpriceimportbutton.php" hash="14f033367ee4df620494f57be8f26719"/></dir><dir name="Helper"><file name="Data.php" hash="c9baa21be5ba345512e5c390b1954c72"/><file name="Getdata.php" hash="dcdf2bd47b01a26ed9400497774c86f8"/><file name="Image.php" hash="4507e0741e1bf094ce558ffb908dbae8"/></dir><dir name="Model"><file name="Api.php" hash="dbcb072fdf2a27766df6aae8213b3e5e"/><file name="Category.php" hash="c3e3410e01e33334b058dd9781f5d84a"/><file name="Image.php" hash="b87da6ed365c3265495afdc2f3b04eb2"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="89e8413eed23ab0df2e72daa996aeff0"/><file name="Price.php" hash="93a6b62fec1e11bf6af57dd0cb2f063a"/></dir></dir><file name="Layer.php" hash="0d15cc5a2d81496d1435c3635a4a95b7"/><file name="Product.php" hash="1e3be2c2c605b3eaf79aea1627ef4d49"/><dir name="Resource"><dir name="Layer"><dir name="Filter"><file name="Price.php" hash="e5011ebd212c5cc0f7004e1736a28a35"/></dir></dir><dir name="Mysql4"><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="4f60c0010241d1624974b726a103748d"/></dir></dir><file name="Setup.php" hash="280a1ece3e1bb1f035e2cf265da05b63"/></dir></dir><file name="Sinch.php" hash="69d4bdecbac7f0ba8d98b411c1b405a4"/><dir name="System"><dir name="Config"><file name="CatRewrite.php" hash="2b4282283e068888a4ac527edc7d30b3"/><file name="Subscription.php" hash="985102ab2005f33e017818ef9247b633"/></dir></dir><file name="config.php" hash="2f343c5a2b4e6a1a731731b9e7474da7"/></dir><dir name="controllers"><file name="AjaxController.php" hash="85d09a8a2fe9214dce3b6140f1b3983e"/><file name="IndexController.php" hash="910f7a5547e9bad529ea71f3e8cd37e6"/><file name="ProductController.php" hash="a7619ef76a1f48bd7f2c029b7c488385"/><file name="SplitfeaturesController.php" hash="a1c27276bced097e8b2a6667e4b6fdbd"/></dir><dir name="etc"><file name="api.xml" hash="4b9df3ba0ff94824f06a5c14497034cb"/><file name="config.xml" hash="86ebb5820211d7a5af07d30a62a6b363"/><file name="system.xml" hash="6c3a95784b4830a17add3227548f923b"/></dir><file name="sinch_import_start_ajax.php" hash="3c81464e43f630270bb0376e15fe21fa"/><dir name="sql"><dir name="sinchimport_setup"><file name="filter_sinch_products_s.sql" hash="40a09a0bb83bce3b14564909cfe3cfc5"/><file name="mysql4-install-0.1.0.php" hash="ea6c4aa6b36b0d580927378306908ed5"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="93a43b01c4ad6eb9c9638dc1d31ca777"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="55ec8d9b42c43dd3092b69928d080676"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="4bbcf03d3c0c5996c84fb87c6eb5f4cd"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="ab6aa72ff697db247423911437830795"/><file name="mysql4-upgrade-0.1.4-0.1.5.php" hash="0c34e3c4a057b4b83593f05a7cddae10"/><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="2a5bb8edd1a6e83eeb68290c3c256c7d"/><file name="mysql4-upgrade-0.1.6-0.1.7.php" hash="a50abb3122453b52b22f5ca9dd94ff1f"/></dir></dir><file name="stock_price_sinch_import_start_ajax.php" hash="960ba4cfdb5ea3548a17c2365c0fca80"/></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="js"><file name="product_view.js" hash=""/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="sinchimport.xml" hash="53dd99d9303049f92713aec45c21836f"/></dir><dir name="template"><dir name="sinchimport"><file name="list.phtml" hash="adc46e247797cdad4582792266d381e4"/><file name="media.phtml" hash="af44d0371493235e4d0a5d0e9223bd9e"/><file name="view.phtml" hash="f160f6226d774a82ab1b312ffb30eb3e"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bintime_Sinchimport.xml" hash="8d5661b858250eeb154af10ee19300c3"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><file name="sinchimport_yes.gif" hash="0afb20898a704a106cb4c598868abf32"/><file name="sinchimport_run.gif" hash="e805ea7eca1f34c75ba0f93780d32d38"/></dir></dir></dir></dir></target></contents>
23
+ <compatible/>
24
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
25
+ </package>
skin/adminhtml/default/default/images/sinchimport_run.gif ADDED
Binary file
skin/adminhtml/default/default/images/sinchimport_yes.gif ADDED
Binary file