stockinthechannel2012 - Version 2.0.4

Version Notes

Version 2.0.4:
* Change the way the MySQL connection is initialized to resolve an edge case where some systems wouldn't accept the LOCAL INFILE flag at that point
* Fix the calls to mysqli_real_escape_string to include the connection object as required
* Remove the currently unused Sinch_new_code.php from Model

Download this release

Release Info

Developer stockinchannel
Extension stockinthechannel2012
Version 2.0.4
Comparing to
See all releases


Code changes from version 2.0.3 to 2.0.4

app/code/local/Bintime/Sinchimport/Model/Sinch.php CHANGED
@@ -5489,7 +5489,7 @@ echo("\n replaceMagentoProductsMultistore 41\n");
5489
  )(
5490
  SELECT
5491
  max(option_id) as option_id,
5492
- "."'".mysqli_real_escape_string($row['manufacturer_name'])."'
5493
  FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
5494
  WHERE attribute_id=".$this->attributes['manufacturer']."
5495
  )
@@ -8584,20 +8584,17 @@ STP DELETE*/
8584
  #################################################################################################
8585
 
8586
  private function db_connect() {
8587
-
8588
  // $connection = Mage::getModel('core/resource')->getConnection('core_write');
8589
  $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
8590
-
8591
- if ($this->db = mysqli_connect($dbConf->host, $dbConf->username, $dbConf->password)) {
8592
- mysqli_options($this->db, MYSQLI_OPT_LOCAL_INFILE, true);
8593
- if(mysqli_select_db($this->db, $dbConf->dbname)){
8594
- $this->_LOG("Connected..");
8595
- }else{
8596
  die("Can't select the database: " . mysqli_error($this->db));
8597
  }
8598
  }else{
8599
  die("Could not connect: " . mysqli_error($this->db));
8600
-
8601
  }
8602
 
8603
  }
@@ -8613,7 +8610,6 @@ STP DELETE*/
8613
  } else {
8614
  return $result;
8615
  }
8616
-
8617
  return $result;
8618
  }
8619
  ##################################################################################################
@@ -8679,7 +8675,7 @@ STP DELETE*/
8679
  $value=$this->valid_char($row['value']);
8680
  if($value!='' and $value!=$row['value']){
8681
  $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8682
- SET value='".mysqli_real_escape_string($value)."'
8683
  WHERE entity_id=".$row['entity_id']."
8684
  AND entity_type_id=".$entity_type_id."
8685
  AND attribute_id=".$attribute_id);
@@ -8946,7 +8942,7 @@ STP DELETE*/
8946
  #################################################################################################
8947
  function set_import_error_reporting_message($message){
8948
  $this->db_do("UPDATE ".$this->import_status_statistic_table."
8949
- SET error_report_message='".mysqli_real_escape_string($message)."'
8950
  WHERE id=".$this->current_import_status_statistic_id);
8951
  }
8952
  #################################################################################################
5489
  )(
5490
  SELECT
5491
  max(option_id) as option_id,
5492
+ "."'".mysqli_real_escape_string($this->db, $row['manufacturer_name'])."'
5493
  FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
5494
  WHERE attribute_id=".$this->attributes['manufacturer']."
5495
  )
8584
  #################################################################################################
8585
 
8586
  private function db_connect() {
 
8587
  // $connection = Mage::getModel('core/resource')->getConnection('core_write');
8588
  $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
8589
+ $dbConn = mysqli_init();
8590
+ mysqli_options($dbConn, MYSQLI_OPT_LOCAL_INFILE, true);
8591
+ if (mysqli_real_connect($dbConn, $dbConf->host, $dbConf->username, $dbConf->password)) {
8592
+ $this->db = $dbConn;
8593
+ if(!mysqli_select_db($this->db, $dbConf->dbname)){
 
8594
  die("Can't select the database: " . mysqli_error($this->db));
8595
  }
8596
  }else{
8597
  die("Could not connect: " . mysqli_error($this->db));
 
8598
  }
8599
 
8600
  }
8610
  } else {
8611
  return $result;
8612
  }
 
8613
  return $result;
8614
  }
8615
  ##################################################################################################
8675
  $value=$this->valid_char($row['value']);
8676
  if($value!='' and $value!=$row['value']){
8677
  $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8678
+ SET value='".mysqli_real_escape_string($this->db, $value)."'
8679
  WHERE entity_id=".$row['entity_id']."
8680
  AND entity_type_id=".$entity_type_id."
8681
  AND attribute_id=".$attribute_id);
8942
  #################################################################################################
8943
  function set_import_error_reporting_message($message){
8944
  $this->db_do("UPDATE ".$this->import_status_statistic_table."
8945
+ SET error_report_message='".mysqli_real_escape_string($this->db, $message)."'
8946
  WHERE id=".$this->current_import_status_statistic_id);
8947
  }
8948
  #################################################################################################
app/code/local/Bintime/Sinchimport/Model/Sinch_new_code.php DELETED
@@ -1,7177 +0,0 @@
1
- <?php
2
-
3
- ini_set('memory_limit','256M');
4
- $dir = Mage::getBaseDir('code')."/local/Bintime/Sinchimport/Model";//dirname(__FILE__);
5
- require_once ($dir.'/config.php');
6
-
7
- class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
8
- var
9
- $connection,
10
- $varDir,
11
- $shellDir,
12
- $files,
13
- $attributes,
14
- $db,
15
- $lang_id,
16
- $debug_mode=1;
17
- private $productDescriptionList = array();
18
- private $specifications;
19
- private $productDescription;
20
- private $fullProductDescription;
21
- private $lowPicUrl;
22
- private $highPicUrl;
23
- private $errorMessage;
24
- private $galleryPhotos = array();
25
- private $productName;
26
- private $relatedProducts = array();
27
- private $errorSystemMessage; //depricated
28
- private $sinchProductId;
29
- private $_productEntityTypeId = 0;
30
- private $defaultAttributeSetId = 0;
31
- private $field_terminated_char;
32
- private $import_status_table;
33
- private $import_status_statistic_table;
34
- private $current_import_status_statistic_id;
35
- private $import_log_table;
36
- private $_attributeId;
37
- private $_categoryEntityTypeId;
38
- private $_categoryDefault_attribute_set_id;
39
- private $_root_cat;
40
- private $import_run_type = 'MANUAL';
41
- private $_ignore_category_features = false;
42
- private $_ignore_product_features = false;
43
- private $_ignore_product_related = false;
44
- private $_ignore_restricted_values = false;
45
- public $php_run_string;
46
- public $price_breaks_filter;
47
-
48
- #################################################################################################
49
-
50
- function __construct(){
51
-
52
- $this->import_status_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status');
53
- $this->import_status_statistic_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic');
54
- $this->import_log_table="stINch_import_log";
55
-
56
- $this->php_run_string=PHP_RUN_STRING;
57
- $this->price_breaks_filter=PRICE_BREAKS;
58
- /*$this->db_connect();
59
- $res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
60
- $row = mysqli_fetch_assoc($res);
61
- $this->lang_id = $row['languages_id'];
62
- */
63
- $this->varDir = TEMPORARY_DIRECTORY_FOR_STORING_FILES;
64
- $this->shellDir = SHELL_DIRECTORY_FOR_INDEXER;
65
- $this->connection=$this->db_connect();
66
- $this->createTemporaryImportDerictory();
67
- $this->_logFile="Sinch.log";
68
- $this->_LOG("constructor");
69
- $this->files=array(
70
- FILE_CATEGORIES,
71
- FILE_CATEGORIES_FEATURES,
72
- FILE_DISTRIBUTORS,
73
- FILE_EANCODES,
74
- FILE_MANUFACTURERS,
75
- FILE_PRODUCT_FEATURES,
76
- FILE_PRODUCTS,
77
- FILE_RELATED_PRODUCTS,
78
- FILE_RESTRICTED_VALUES,
79
- FILE_STOCK_AND_PRICES,
80
- FILE_PRODUCTS_PICTURES_GALLERY
81
- );
82
- $this->attributes['manufacturer']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
83
- $this->attributes['name']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
84
- $this->attributes['is_active']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('is_active')->getFirstItem()->getId();
85
- $this->attributes['include_in_menu']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('include_in_menu')->getFirstItem()->getId();
86
- $this->attributes['url_key']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('url_key')->getFirstItem()->getId();
87
- $this->attributes['display_mode']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('display_mode')->getFirstItem()->getId();
88
- $this->attributes['status']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('status')->getFirstItem()->getId();
89
- $this->attributes['visibility']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('visibility')->getFirstItem()->getId();
90
- $this->attributes['price']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('price')->getFirstItem()->getId();
91
- $this->attributes['cost']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('cost')->getFirstItem()->getId();
92
- $this->attributes['weight']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('weight')->getFirstItem()->getId();
93
- $this->attributes['tax_class_id']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('tax_class_id')->getFirstItem()->getId();
94
-
95
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
96
- // if($dataConf['field_terminated_char']){
97
- // $this->field_terminated_char=$dataConf['field_terminated_char'];
98
- // }else{
99
- $this->field_terminated_char=DEFAULT_FILE_TERMINATED_CHAR;
100
- // }
101
- // $attributeOptions = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getSource()->getAllOptions(false);
102
- // echo "<pre>"; print_r($attributeOptions); echo "</pre>";
103
- }
104
-
105
- #################################################################################################
106
- function cron_start_import(){
107
- $this->_LOG("Start import from cron");
108
- $start_hr=Mage::getStoreConfig('sinchimport_root/sinch_cron/sinch_cron_time');
109
- $now_hr=date('H');
110
- $this->_LOG("Now $now_hr hr, scheduler time is $start_hr hr");
111
-
112
- if($start_hr==$now_hr){
113
- $this->run_sinch_import();
114
- }else{
115
- $this->_LOG(" it's NOT time for SINCH ");
116
- }
117
-
118
- $this->_LOG("Finish import from cron");
119
-
120
- }
121
- ################################################################################################
122
- function cron_start_full_import(){
123
- $this->import_run_type='CRON';
124
- $this->run_sinch_import();
125
- }
126
- ################################################################################################
127
- function cron_start_stock_price_import(){
128
- $this->import_run_type='CRON';
129
- $this->run_stock_price_sinch_import();
130
- }
131
- #################################################################################################
132
- function is_imort_not_run(){
133
- $q="SELECT IS_FREE_LOCK('sinchimport') as getlock";
134
- $quer=$this->db_do($q);
135
- $row=mysqli_fetch_array($quer);
136
- return $row['getlock'];
137
- }
138
- #################################################################################################
139
- function check_store_procedure_exist(){
140
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
141
- $q='SHOW PROCEDURE STATUS LIKE "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'"';
142
- $quer=$this->db_do($q);
143
- $result=false;
144
- While($row=mysqli_fetch_array($quer)){
145
- if(($row['Name']==Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s')) && ($row['Db']==$dbConf->dbname)){
146
- $result = true;
147
- }
148
- }
149
- return $result;
150
- }
151
- #################################################################################################
152
- function check_db_privileges(){
153
- $q='SHOW PRIVILEGES';
154
- $quer=$this->db_do($q);
155
- while($row=mysqli_fetch_array($quer)){
156
- if($row['Privilege']=='File' && $row['Context']=='File access on server'){
157
- return true;
158
- }
159
- }
160
- return false;
161
- }
162
- #################################################################################################
163
- function check_local_infile(){
164
- $q='SHOW VARIABLES LIKE "local_infile"';
165
- $quer=$this->db_do($q);
166
- $row=mysqli_fetch_array($quer);
167
- if($row['Variable_name']=='local_infile' && $row['Value']=="ON"){
168
- return true;
169
- }else{
170
- return false;
171
- }
172
- }
173
- #################################################################################################
174
- function is_full_import_have_been_run(){
175
- $q="SELECT COUNT(*) AS cnt
176
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic')."
177
- WHERE import_type='FULL' AND global_status_import='Successful'";
178
- $quer=$this->db_do($q);
179
- $row=mysqli_fetch_array($quer);
180
- if($row['cnt']>0){
181
- return true;
182
- }else{
183
- return false;
184
- }
185
- }
186
- #################################################################################################
187
- function run_sinch_import(){
188
- $safe_mode_set = ini_get('safe_mode');
189
-
190
- $this->InitImportStatuses('FULL');
191
- if($safe_mode_set ){
192
- $this->_LOG('safe_mode is enable. import stoped.');
193
- $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
194
- exit;
195
- }
196
- $store_proc=$this->check_store_procedure_exist();
197
-
198
- if(!$store_proc){
199
- $this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
200
- $this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
201
- exit;
202
- }
203
-
204
- $file_privileg=$this->check_db_privileges();
205
-
206
- if(!$file_privileg){
207
- $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
208
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
209
- exit;
210
- }
211
- $local_infile=$this->check_local_infile();
212
- if(!$local_infile){
213
- $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'");
214
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
215
- exit;
216
- }
217
-
218
- if($this->is_imort_not_run()){
219
- try{
220
- //$this->InitImportStatuses();
221
- $q="SELECT GET_LOCK('sinchimport', 30)";
222
- $quer=$this->db_do($q);
223
- $import=$this;
224
- $import->addImportStatus('Start Import');
225
- echo "Upload Files <br>";
226
- $import->UploadFiles();
227
- $import->addImportStatus('Upload Files');
228
-
229
- echo "Parse Categories <br>";
230
- $coincidence = $import->ParseCategories();
231
- $import->addImportStatus('Parse Categories');
232
-
233
-
234
- //$import->_cleanCateoryProductFlatTable();
235
- //$import->runIndexer();
236
- echo("\n\n\n==================RETURN=================\n\n\n");
237
-
238
-
239
- echo "Parse Category Features <br>";
240
- $import->ParseCategoryFeatures();
241
- $import->addImportStatus('Parse Category Features');
242
-
243
-
244
- echo "Parse Distributors <br>";
245
- $import->ParseDistributors();
246
- $import->addImportStatus('Parse Distributors');
247
-
248
-
249
- echo "Parse EAN Codes <br>";
250
- $import->ParseEANCodes();
251
- $import->addImportStatus('Parse EAN Codes');
252
-
253
-
254
- echo "Parse Manufacturers <br>";
255
- $import->ParseManufacturers();
256
- $import->addImportStatus('Parse Manufacturers');
257
-
258
- echo "Parse Related Products <br>";
259
- $import->ParseRelatedProducts();
260
- $import->addImportStatus('Parse Related Products');
261
-
262
- echo "Parse Product Features <br>";
263
- $import->ParseProductFeatures();
264
- $import->addImportStatus('Parse Product Features');
265
-
266
-
267
-
268
- echo "Parse Products <br>";
269
- $import->ParseProducts($coincidence);
270
- $import->addImportStatus('Parse Products');
271
- //return;
272
- echo "Parse Pictures Gallery";
273
- $import->ParseProductsPicturesGallery();
274
- $import->addImportStatus('Parse Pictures Gallery');
275
-
276
- echo "Parse Restricted Values <br>";
277
- $import->ParseRestrictedValues();
278
- $import->addImportStatus('Parse Restricted Values');
279
-
280
- echo "Parse Stock And Prices <br>";
281
- $import->ParseStockAndPrices();
282
- $import->addImportStatus('Parse Stock And Prices');
283
-
284
-
285
- Mage::log("Finish Sinch import", null, $this->_logFile);
286
- echo "Finish Sinch import<br>";
287
-
288
- Mage::log("Start cleanin Sinch cache<br>", null, $this->_logFile);
289
- echo "Start cleanin Sinch cache<br>";
290
- Mage::app()->getCacheInstance()->cleanType('block_html');
291
- /*
292
- $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
293
- if ($indexProcess) {
294
- $indexProcess->reindexAll();
295
- }
296
- */
297
-
298
- Mage::log("Start indexing Sinch features for filters", null, $this->_logFile);
299
- echo "Start indexing Sinch features for filters<br>";
300
-
301
-
302
- $resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
303
- $resource->splitProductsFeature(null);
304
-
305
- Mage::log("Finish indexing Sinch features for filters", null, $this->_logFile);
306
- $import->addImportStatus('Generate category filters');
307
- echo "Finish indexing Sinch features for filters<br>";
308
-
309
- Mage::log("Start indexing data", null, $this->_logFile);
310
- echo "Start indexing data";
311
- $import->_cleanCateoryProductFlatTable();
312
- $import->runIndexer();
313
- Mage::log("Finish indexing data", null, $this->_logFile);
314
- $import->addImportStatus('Indexing data', 1);
315
- echo "Finish indexing data";
316
-
317
- $q="SELECT RELEASE_LOCK('sinchimport')";
318
- $quer=$this->db_do($q);
319
- }catch (Exception $e) {
320
- $this->set_import_error_reporting_message($e);
321
- }
322
- }
323
- else{
324
- Mage::log("Sinchimport already run", null, $this->_logFile);
325
- echo "Sinchimport already run<br>";
326
-
327
- }
328
-
329
- }
330
- #################################################################################################
331
- function run_stock_price_sinch_import(){
332
- $safe_mode_set = ini_get('safe_mode');
333
-
334
- $this->InitImportStatuses('PRICE STOCK');
335
- if($safe_mode_set ){
336
- $this->_LOG('safe_mode is enable. import stoped.');
337
- $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
338
- exit;
339
- }
340
- $store_proc=$this->check_store_procedure_exist();
341
-
342
- if(!$store_proc){
343
- $this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
344
- $this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
345
- exit;
346
- }
347
-
348
- $file_privileg=$this->check_db_privileges();
349
-
350
- if(!$file_privileg){
351
- $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
352
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
353
- exit;
354
- }
355
- $local_infile=$this->check_local_infile();
356
- if(!$local_infile){
357
- $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'");
358
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
359
- exit;
360
- }
361
-
362
- if($this->is_imort_not_run() && $this->is_full_import_have_been_run()){
363
- try{
364
- //$this->InitImportStatuses();
365
- $q="SELECT GET_LOCK('sinchimport', 30)";
366
- $quer=$this->db_do($q);
367
- $import=$this;
368
- $import->addImportStatus('Stock Price Start Import');
369
- echo "Upload Files <br>";
370
- $this->files=array(
371
- FILE_STOCK_AND_PRICES
372
- );
373
-
374
- $import->UploadFiles();
375
- $import->addImportStatus('Stock Price Upload Files');
376
-
377
- echo "Parse Stock And Prices <br>";
378
- //exit;
379
- $import->ParseStockAndPrices();
380
- $import->addImportStatus('Stock Price Parse Products');
381
-
382
-
383
- Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
384
- echo "Finish Stock & Price Sinch import<br>";
385
-
386
- Mage::log("Start indexing Stock & Price", null, $this->_logFile);
387
- echo "Start indexing Stock & Price<br>";
388
- $import->_cleanCateoryProductFlatTable();
389
- $import->runStockPriceIndexer();
390
- Mage::log("Finish indexing Stock & Price", null, $this->_logFile);
391
- $import->addImportStatus('Stock Price Indexing data');
392
- $import->addImportStatus('Stock Price Finish import', 1);
393
- echo "Finish indexing Stock & Price<br>";
394
-
395
- $q="SELECT RELEASE_LOCK('sinchimport')";
396
- $quer=$this->db_do($q);
397
- }catch (Exception $e) {
398
- $this->set_import_error_reporting_message($e);
399
- }
400
- }
401
- else{
402
- if(!$this->is_imort_not_run()){
403
- Mage::log("Sinchimport already run", null, $this->_logFile);
404
- echo "Sinchimport already run<br>";
405
- }else{
406
- Mage::log("Full import have never finished with success", null, $this->_logFile);
407
- echo "Full import have never finished with success<br>";
408
- }
409
- }
410
-
411
- }
412
- #################################################################################################
413
-
414
-
415
- function UploadFiles(){
416
-
417
- $this->_LOG("Start upload files");
418
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
419
- $login=$dataConf['login'];
420
- $passw=$dataConf['password'];
421
- //return;//stepan tes//stepan tes//stepan testtt
422
- if(!$login || !$passw){
423
- $this->_LOG('ftp login or password dosent defined');
424
- $this->set_import_error_reporting_message('FTP login or password has not been defined. Import stopped.');
425
- exit;
426
-
427
- }
428
- $file_url_and_dir=$this->repl_ph(FILE_URL_AND_DIR, array('login' => $login,
429
- 'password'=> $passw
430
- )
431
- );
432
- foreach ($this->files as $file) {
433
- $this->_LOG("Copy ".$file_url_and_dir.$file." to ".$this->varDir.$file);
434
- if(strstr($file_url_and_dir, 'ftp://')){
435
- preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
436
- //var_dump($match);
437
- if($conn = ftp_connect($match[3])){
438
- if(!ftp_login($conn, $login, $passw))
439
- {
440
- $this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
441
- exit;
442
- }
443
- }
444
- else{
445
- $this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
446
- exit;
447
- }
448
- if (!$this->wget ($file_url_and_dir.$file, $this->varDir.$file, 'system')){
449
- $this->_LOG("wget Can't copy ".$file.", will use old one");
450
- echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file.", will use old one<br>";
451
- }
452
- }
453
- else{
454
- if(!copy($file_url_and_dir.$file, $this->varDir.$file)){
455
- $this->_LOG("copy Can't copy ".$file.", will use old one");
456
- echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file." will use old one<br>";
457
- }
458
- }
459
- exec("chmod a+rw ".$this->varDir.$file);
460
- if(!filesize($this->varDir.$file)){
461
- if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES){
462
- $this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
463
- $this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
464
- $this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
465
-
466
- exit;
467
- }else{
468
- if($file==FILE_CATEGORIES_FEATURES){
469
- $this->_LOG("Can't copy ".FILE_CATEGORIES_FEATURES." file ignored" );
470
- $this->_ignore_category_features=true;
471
- }elseif($file==FILE_PRODUCT_FEATURES){
472
- $this->_LOG("Can't copy ".FILE_PRODUCT_FEATURES." file ignored" );
473
- $this->_ignore_product_features=true;
474
- }elseif($file==FILE_RELATED_PRODUCTS){
475
- $this->_LOG("Can't copy ".FILE_RELATED_PRODUCTS." file ignored" );
476
- $this->_ignore_product_related=true;
477
- }elseif($file==FILE_RESTRICTED_VALUES){
478
- $this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
479
- $this->_ignore_restricted_values=true;
480
- }
481
- }
482
- }
483
- }
484
-
485
- $this->_LOG("Finish upload files");
486
- }
487
- #################################################################################################
488
-
489
-
490
-
491
- ################################################################################################################################################################
492
- function ParseCategories()
493
- {
494
-
495
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
496
- $im_type = $dataConf['replace_category'];
497
- $parse_file = $this->varDir.FILE_CATEGORIES;
498
- $field_terminated_char = $this->field_terminated_char;
499
-
500
- if(filesize($parse_file))
501
- {
502
- $this->_LOG("Start parse ".FILE_CATEGORIES);
503
-
504
- $this->_getCategoryEntityTypeIdAndDefault_attribute_set_id();
505
-
506
- $categories_temp = Mage::getSingleton('core/resource')->getTableName('categories_temp');
507
- $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
508
- $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
509
- $catalog_category_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int');
510
- $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
511
- $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
512
- $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
513
-
514
- $_categoryEntityTypeId = $this->_categoryEntityTypeId;
515
- $_categoryDefault_attribute_set_id = $this->_categoryDefault_attribute_set_id;
516
-
517
- $name_attrid = $this->_getCategoryAttributeId('name');
518
- $is_anchor_attrid = $this->_getCategoryAttributeId('is_anchor');
519
- $image_attrid = $this->_getCategoryAttributeId('image');
520
- $attr_url_key = $this->attributes['url_key'];
521
- $attr_display_mode = $this->attributes['display_mode'];
522
- $attr_is_active = $this->attributes['is_active'];
523
- $attr_include_in_menu = $this->attributes['include_in_menu'];
524
-
525
-
526
- $this->loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char);
527
- $coincidence = $this->calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type);
528
-
529
- /**if (!$this->check_loaded_data($parse_file, $categories_temp))
530
- {
531
- $inf = mysqli_info();
532
- $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.")");
533
- exit;
534
- }/**/
535
-
536
-
537
- if (count($coincidence) == -1) // one store logic
538
- {
539
-
540
- if ($im_type == "REWRITE")
541
- {
542
- $root_cat = 2;
543
-
544
- $root_cat = $this->truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
545
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
546
- $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu); // return $root_cat
547
- }
548
- else // if ($im_type == "MERGE")
549
- {
550
- $root_cat = $this->_getShopRootCategoryId();
551
- }
552
-
553
- $this->_root_cat = $root_cat;
554
-
555
- $this->setCategorySettings($categories_temp, $root_cat);
556
- $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
557
- $this->addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
558
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat);
559
- }
560
- else if (count($coincidence) >= 1) // multistore logic
561
- {
562
- echo("\n\n\n====================================\nmultistore logic\n====================================\n\n\n");
563
- switch ($im_type)
564
- {
565
- case "REWRITE": $this->rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
566
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
567
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
568
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
569
- break;
570
- case "MERGE" : $this->mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
571
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
572
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
573
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
574
- break;
575
- default : $retcode = "error";
576
- };
577
- }
578
- else
579
- {
580
- echo("error");
581
- }
582
-
583
- $this->_LOG("Finish parse ".FILE_CATEGORIES);
584
- }
585
- else
586
- {
587
- $this->_LOG("Wrong file ".$parse_file);
588
- }
589
- $this->_LOG(' ');
590
-
591
- return $coincidence;
592
- } // function ParseCategories()
593
- ################################################################################################################################################################
594
-
595
-
596
-
597
-
598
-
599
-
600
- ################################################################################################################################################################
601
- private function loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char)
602
- {
603
- $this->db_do("DROP TABLE IF EXISTS $categories_temp");
604
-
605
- $this->db_do("CREATE TABLE $categories_temp (
606
- store_category_id int(11),
607
- parent_store_category_id int(11),
608
- category_name varchar(50),
609
- order_number int(11),
610
- is_hidden boolean,
611
- products_within_this_category int(11),
612
- products_within_sub_categories int(11),
613
- categories_image varchar(255),
614
- level int(10) NOT NULL default 0,
615
- children_count int(11) NOT NULL default 0,
616
- KEY(store_category_id),
617
- KEY(parent_store_category_id)
618
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
619
- ");
620
-
621
- /** NEW !!!
622
- $this->db_do("
623
- CREATE TABLE $categories_temp
624
- (
625
- store_category_id INT(11),
626
- parent_store_category_id INT(11),
627
- category_name VARCHAR(50),
628
- order_number INT(11),
629
- is_hidden BOOLEAN,
630
- products_within_sub_categories INT(11),
631
- products_within_this_category INT(11),
632
- categories_image VARCHAR(255),
633
- level INT(10) NOT NULL DEFAULT 0,
634
- children_count INT(11) NOT NULL DEFAULT 0,
635
- UNSPSC INT(10) NOT NULL DEFAULT 0,
636
- TypeID INT(10) NOT NULL DEFAULT 0,
637
-
638
- KEY(store_category_id),
639
- KEY(parent_store_category_id)
640
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
641
- /**/
642
-
643
- $this->db_do("
644
- LOAD DATA LOCAL INFILE '$parse_file' INTO TABLE $categories_temp
645
- FIELDS TERMINATED BY '$field_terminated_char' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES");
646
-
647
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN UNSPSC INT(10) NOT NULL DEFAULT 0");
648
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN RootName VARCHAR(50) NOT NULL DEFAULT 0");
649
-
650
- //$this->db_do("UPDATE $categories_temp SET RootName = '3'"); // one store logic test
651
-
652
- //$this->db_do("UPDATE $categories_temp SET RootName = 'KAMERY' WHERE store_category_id IN (93530, 93531, 93230, 93231, 175559, 175687)");
653
- //$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
654
- //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553, 93530, 93531, 93230, 93231, 175559, 175687)");
655
-
656
-
657
- $this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
658
- $this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553)");
659
- } // private function loadCategoriesTemp()
660
- ################################################################################################################################################################
661
-
662
-
663
-
664
- ################################################################################################################################################################
665
- private function mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
666
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
667
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
668
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
669
- {
670
- echo("mergeMultistoreCategories RUN\n");
671
-
672
-
673
- $this->createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
674
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
675
-
676
-
677
-
678
- $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
679
-
680
-
681
- $this->addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
682
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
683
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
684
-
685
-
686
- echo("\n\n\nmergeMultistoreCategories DONE\n");
687
- }
688
- ################################################################################################################################################################
689
-
690
-
691
-
692
-
693
-
694
-
695
- ################################################################################################################################################################
696
- private function addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
697
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
698
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
699
- {
700
- echo("\n\n\n\n *************************************************************\n mapSinchCategoriesMultistore start... \n");
701
-
702
-
703
- if (UPDATE_CATEGORY_DATA)
704
- {
705
- $ignore = '';
706
- $on_diplicate_key_update = "
707
- ON DUPLICATE KEY UPDATE
708
- updated_at = now(),
709
- store_category_id = c.store_category_id,
710
- level = c.level,
711
- children_count = c.children_count,
712
- position = c.order_number,
713
- parent_store_category_id = c.parent_store_category_id";
714
- //level=c.level,
715
- //children_count=c.children_count
716
- //position=c.order_number,
717
- }
718
- else
719
- {
720
- $ignore = 'IGNORE';
721
- $on_diplicate_key_update = '';
722
- }
723
-
724
- $query = "
725
- INSERT $ignore INTO $catalog_category_entity
726
- (
727
- entity_type_id,
728
- attribute_set_id,
729
- created_at,
730
- updated_at,
731
- level,
732
- children_count,
733
- entity_id,
734
- position,
735
- parent_id,
736
- store_category_id,
737
- parent_store_category_id
738
- )
739
- (SELECT
740
- $_categoryEntityTypeId,
741
- $_categoryDefault_attribute_set_id,
742
- NOW(),
743
- NOW(),
744
- c.level,
745
- c.children_count,
746
- scm.shop_entity_id,
747
- c.order_number,
748
- scm.shop_parent_id,
749
- c.store_category_id,
750
- c.parent_store_category_id
751
- FROM $categories_temp c
752
- LEFT JOIN $stINch_categories_mapping scm
753
- ON c.store_category_id = scm.store_category_id
754
- ) $on_diplicate_key_update";
755
- echo("\n\n $query\n\n");
756
- $this->db_do($query);
757
-
758
-
759
-
760
-
761
- $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
762
-
763
-
764
-
765
-
766
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
767
- while ($row = mysqli_fetch_array($categories))
768
- {
769
- $parent_id = $row['parent_id'];
770
- $entity_id = $row['entity_id'];
771
-
772
- $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
773
-
774
- $this->db_do("
775
- UPDATE $catalog_category_entity
776
- SET path = '$path'
777
- WHERE entity_id = $entity_id");
778
- } // while ($row = mysqli_fetch_array($categories))
779
-
780
-
781
-
782
-
783
- ///////////////////////////////////////////////////////
784
-
785
-
786
- if(UPDATE_CATEGORY_DATA)
787
- {
788
- echo "Update category_data \n";
789
-
790
- $q = "
791
- INSERT INTO $catalog_category_entity_varchar
792
- (
793
- entity_type_id,
794
- attribute_id,
795
- store_id,
796
- entity_id,
797
- value
798
- )
799
- (SELECT
800
- $_categoryEntityTypeId,
801
- $name_attrid,
802
- 0,
803
- scm.shop_entity_id,
804
- c.category_name
805
- FROM $categories_temp c
806
- JOIN $stINch_categories_mapping scm
807
- ON c.store_category_id = scm.store_category_id
808
- )
809
- ON DUPLICATE KEY UPDATE
810
- value = c.category_name";
811
- $this->db_do($q);
812
-
813
-
814
- $q = "
815
- INSERT INTO $catalog_category_entity_varchar
816
- (
817
- entity_type_id,
818
- attribute_id,
819
- store_id,
820
- entity_id,
821
- value
822
- )
823
- (SELECT
824
- $_categoryEntityTypeId,
825
- $name_attrid,
826
- 1,
827
- scm.shop_entity_id,
828
- c.category_name
829
- FROM $categories_temp c
830
- JOIN $stINch_categories_mapping scm
831
- ON c.store_category_id = scm.store_category_id
832
- )
833
- ON DUPLICATE KEY UPDATE
834
- value = c.category_name";
835
- $this->db_do($q);
836
-
837
-
838
- $q = "
839
- INSERT INTO $catalog_category_entity
840
- (
841
- entity_type_id,
842
- attribute_id,
843
- store_id,
844
- entity_id,
845
- value
846
- )
847
- (SELECT
848
- $_categoryEntityTypeId,
849
- $attr_is_active,
850
- 0,
851
- scm.shop_entity_id,
852
- 1
853
- FROM $categories_temp c
854
- JOIN $stINch_categories_mapping scm
855
- ON c.store_category_id = scm.store_category_id
856
- )
857
- ON DUPLICATE KEY UPDATE
858
- value = 1";
859
- $this->db_do($q);
860
-
861
-
862
- $q = "
863
- INSERT INTO $catalog_category_entity_int
864
- (
865
- entity_type_id,
866
- attribute_id,
867
- store_id,
868
- entity_id,
869
- value
870
- )
871
- (SELECT
872
- $_categoryEntityTypeId,
873
- $attr_is_active,
874
- 1,
875
- scm.shop_entity_id,
876
- 1
877
- FROM $categories_temp c
878
- JOIN $stINch_categories_mapping scm
879
- ON c.store_category_id = scm.store_category_id
880
- )
881
- ON DUPLICATE KEY UPDATE
882
- value = 1";
883
- $this->db_do($q);
884
-
885
-
886
- $q = "
887
- INSERT INTO $catalog_category_entity_int
888
- (
889
- entity_type_id,
890
- attribute_id,
891
- store_id,
892
- entity_id,
893
- value
894
- )
895
- (SELECT
896
- $_categoryEntityTypeId,
897
- $attr_include_in_menu,
898
- 0,
899
- scm.shop_entity_id,
900
- 1
901
- FROM $categories_temp c
902
- JOIN $stINch_categories_mapping scm
903
- ON c.store_category_id = scm.store_category_id
904
- )
905
- ON DUPLICATE KEY UPDATE
906
- value = 1";
907
- $this->db_do($q);
908
-
909
-
910
- $q = "
911
- INSERT INTO $catalog_category_entity_int
912
- (
913
- entity_type_id,
914
- attribute_id,
915
- store_id,
916
- entity_id,
917
- value
918
- )
919
- (SELECT
920
- $_categoryEntityTypeId,
921
- $is_anchor_attrid,
922
- 1,
923
- scm.shop_entity_id,
924
- 1
925
- FROM $categories_temp c
926
- JOIN $stINch_categories_mapping scm
927
- ON c.store_category_id = scm.store_category_id
928
- )
929
- ON DUPLICATE KEY UPDATE
930
- value = 1";
931
- $this->db_do($q);
932
-
933
-
934
- $q = "
935
- INSERT INTO $catalog_category_entity_int
936
- (
937
- entity_type_id,
938
- attribute_id,
939
- store_id,
940
- entity_id,
941
- value
942
- )
943
- (SELECT
944
- $_categoryEntityTypeId,
945
- $is_anchor_attrid,
946
- 0,
947
- scm.shop_entity_id,
948
- 1
949
- FROM $categories_temp c
950
- JOIN $stINch_categories_mapping scm
951
- ON c.store_category_id = scm.store_category_id
952
- )
953
- ON DUPLICATE KEY UPDATE
954
- value = 1";
955
- $this->db_do($q);
956
-
957
- $q = "
958
- INSERT INTO $catalog_category_entity_varchar
959
- (
960
- entity_type_id,
961
- attribute_id,
962
- store_id,
963
- entity_id,
964
- value
965
- )
966
- (SELECT
967
- $_categoryEntityTypeId,
968
- $image_attrid,
969
- 0,
970
- scm.shop_entity_id,
971
- c.categories_image
972
- FROM $categories_temp c
973
- JOIN $stINch_categories_mapping scm
974
- ON c.store_category_id = scm.store_category_id
975
- )
976
- ON DUPLICATE KEY UPDATE
977
- value = c.categories_image";
978
- $this->db_do($q);
979
- }
980
- else
981
- {
982
- echo "Insert ignore category_data \n";
983
-
984
-
985
- $q = "
986
- INSERT IGNORE INTO $catalog_category_entity_varchar
987
- (
988
- entity_type_id,
989
- attribute_id,
990
- store_id,
991
- entity_id,
992
- value
993
- )
994
- (SELECT
995
- $_categoryEntityTypeId,
996
- $name_attrid,
997
- 0,
998
- scm.shop_entity_id,
999
- c.category_name
1000
- FROM $categories_temp c
1001
- JOIN $stINch_categories_mapping scm
1002
- ON c.store_category_id = scm.store_category_id
1003
- )";
1004
- $this->db_do($q);
1005
-
1006
-
1007
- $q = "
1008
- INSERT IGNORE INTO $catalog_category_entity_int
1009
- (
1010
- entity_type_id,
1011
- attribute_id,
1012
- store_id,
1013
- entity_id,
1014
- value
1015
- )
1016
- (SELECT
1017
- $_categoryEntityTypeId,
1018
- $attr_is_active,
1019
- 0,
1020
- scm.shop_entity_id,
1021
- 1
1022
- FROM $categories_temp c
1023
- JOIN $stINch_categories_mapping scm
1024
- ON c.store_category_id = scm.store_category_id
1025
- )";
1026
- $this->db_do($q);
1027
-
1028
-
1029
- $q = "
1030
- INSERT IGNORE INTO $catalog_category_entity_int
1031
- (
1032
- entity_type_id,
1033
- attribute_id,
1034
- store_id,
1035
- entity_id,
1036
- value
1037
- )
1038
- (SELECT
1039
- $_categoryEntityTypeId,
1040
- $attr_include_in_menu,
1041
- 0,
1042
- scm.shop_entity_id,
1043
- 1
1044
- FROM $categories_temp c
1045
- JOIN $stINch_categories_mapping scm
1046
- ON c.store_category_id = scm.store_category_id
1047
- )";
1048
- $this->db_do($q);
1049
-
1050
-
1051
- $q = "
1052
- INSERT IGNORE INTO $catalog_category_entity_int
1053
- (
1054
- entity_type_id,
1055
- attribute_id,
1056
- store_id,
1057
- entity_id,
1058
- value
1059
- )
1060
- (SELECT
1061
- $_categoryEntityTypeId,
1062
- $is_anchor_attrid,
1063
- 0,
1064
- scm.shop_entity_id,
1065
- 1
1066
- FROM $categories_temp c
1067
- JOIN $stINch_categories_mapping scm
1068
- ON c.store_category_id = scm.store_category_id
1069
- )";
1070
- $this->db_do($q);
1071
-
1072
-
1073
- $q = "
1074
- INSERT IGNORE INTO $catalog_category_entity_varchar
1075
- (
1076
- entity_type_id,
1077
- attribute_id,
1078
- store_id,
1079
- entity_id,
1080
- value
1081
- )
1082
- (SELECT
1083
- $_categoryEntityTypeId,
1084
- $image_attrid,
1085
- 0,
1086
- scm.shop_entity_id,
1087
- c.categories_image
1088
- FROM $categories_temp c
1089
- JOIN $stINch_categories_mapping scm
1090
- ON c.store_category_id = scm.store_category_id
1091
- )";
1092
- $this->db_do($q);
1093
- }
1094
-
1095
-
1096
-
1097
- //$this->deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int);
1098
-
1099
- //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
1100
-
1101
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
1102
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
1103
- /**/
1104
-
1105
- echo("\n mapSinchCategoriesMultistore done... \n *************************************************************\n");
1106
-
1107
- } // private function addCategoryDataMultistoreMerge(...)
1108
- ################################################################################################################################################################
1109
-
1110
-
1111
-
1112
-
1113
-
1114
- ################################################################################################################################################################
1115
- private function deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int)
1116
- {
1117
-
1118
- echo("\n\n\n\n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n deleteOldSinchCategoriesFromShopMerge start... \n");
1119
-
1120
- /**
1121
- $query = "
1122
- DELETE cat FROM $catalog_category_entity_varchar cat
1123
- JOIN $stINch_categories_mapping scm
1124
- ON cat.entity_id = scm.shop_entity_id
1125
- WHERE
1126
- (scm.shop_store_category_id IS NOT NULL) AND
1127
- (scm.store_category_id IS NULL)";
1128
- echo("\n $query\n");
1129
- // $this->db_do($query);
1130
-
1131
- $query = "
1132
- DELETE cat FROM $catalog_category_entity_int cat
1133
- JOIN $stINch_categories_mapping scm
1134
- ON cat.entity_id = scm.shop_entity_id
1135
- WHERE
1136
- (scm.shop_store_category_id IS NOT NULL) AND
1137
- (scm.store_category_id IS NULL)";
1138
- echo("\n $query\n");
1139
- // $this->db_do($query);
1140
-
1141
- $query = "
1142
- DELETE cat FROM $catalog_category_entity cat
1143
- JOIN $stINch_categories_mapping scm
1144
- ON cat.entity_id=scm.shop_entity_id
1145
- WHERE
1146
- (scm.shop_store_category_id IS NOT NULL) AND
1147
- (scm.store_category_id IS NULL)";
1148
- echo("\n $query\n");
1149
- // $this->db_do($query);
1150
- /**/
1151
-
1152
- echo("\n deleteOldSinchCategoriesFromShopMerge done... \n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
1153
-
1154
- } // private function deleteOldSinchCategoriesFromShopMerge()
1155
- ################################################################################################################################################################
1156
-
1157
-
1158
-
1159
-
1160
-
1161
- ################################################################################################################################################################
1162
- private function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
1163
- {
1164
- echo("\n\n\ ==========================================================================\n mapSinchCategoriesMultistore start... \n");
1165
-
1166
- $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
1167
-
1168
- $query = "
1169
- INSERT IGNORE INTO $stINch_categories_mapping_temp
1170
- (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
1171
- (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
1172
- FROM $catalog_category_entity)";
1173
- echo("\n $query\n");
1174
- $this->db_do($query);
1175
-
1176
-
1177
- $query = "
1178
- UPDATE $stINch_categories_mapping_temp cmt
1179
- JOIN $categories_temp c
1180
- ON cmt.shop_store_category_id = c.store_category_id
1181
- SET
1182
- cmt.store_category_id = c.store_category_id,
1183
- cmt.parent_store_category_id = c.parent_store_category_id,
1184
- cmt.category_name = c.category_name,
1185
- cmt.order_number = c.order_number,
1186
- cmt.products_within_this_category = c.products_within_this_category";
1187
- echo("\n $query\n");
1188
- $this->db_do($query);
1189
-
1190
-
1191
- $query = "
1192
- UPDATE $stINch_categories_mapping_temp cmt
1193
- JOIN $catalog_category_entity cce
1194
- ON cmt.parent_store_category_id = cce.store_category_id
1195
- SET cmt.shop_parent_id = cce.entity_id";
1196
- echo("\n $query\n");
1197
- $this->db_do($query);
1198
-
1199
-
1200
- $query = "
1201
- SELECT DISTINCT
1202
- c.RootName, cce.entity_id
1203
- FROM $categories_temp c
1204
- JOIN $catalog_category_entity_varchar ccev
1205
- ON c.RootName = ccev.value
1206
- AND ccev.entity_type_id = $_categoryEntityTypeId
1207
- AND ccev.attribute_id = $name_attrid
1208
- AND ccev.store_id = 0
1209
- JOIN $catalog_category_entity cce
1210
- ON ccev.entity_id = cce.entity_id";
1211
- echo("\n $query\n");
1212
- $root_categories = $this->db_do($query);
1213
-
1214
- while($root_cat = mysqli_fetch_array($root_categories))
1215
- {
1216
- $root_id = $root_cat['entity_id'];
1217
- $root_name = $root_cat['RootName'];
1218
-
1219
- $query = "
1220
- UPDATE $stINch_categories_mapping_temp cmt
1221
- JOIN $categories_temp c
1222
- ON cmt.shop_store_category_id = c.store_category_id
1223
- SET
1224
- cmt.shop_parent_id = $root_id,
1225
- cmt.shop_parent_store_category_id = $root_id,
1226
- cmt.parent_store_category_id = $root_id,
1227
- c.parent_store_category_id = $root_id
1228
- WHERE RootName = '$root_name'
1229
- AND cmt.shop_parent_id = 0";
1230
- echo("\n $query\n");
1231
- $this->db_do($query);
1232
- }
1233
-
1234
-
1235
-
1236
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1237
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
1238
- else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
1239
-
1240
- $query = "
1241
- UPDATE $stINch_categories_mapping_temp cmt
1242
- JOIN $catalog_category_entity cce
1243
- ON cmt.shop_entity_id = cce.entity_id
1244
- SET cce.parent_id = cmt.shop_parent_id
1245
- $where";
1246
- echo("\n $query\n");
1247
- $this->db_do($query);
1248
-
1249
- $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
1250
- echo("\n $query\n");
1251
- $this->db_do($query);
1252
-
1253
- $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
1254
- echo("\n $query\n");
1255
- $this->db_do($query);
1256
-
1257
- echo("\n mapSinchCategoriesMultistore done... \n ==========================================================================\n\n\n\n");
1258
- } // public function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
1259
- ################################################################################################################################################################
1260
-
1261
-
1262
-
1263
-
1264
-
1265
-
1266
-
1267
- ################################################################################################################################################################
1268
- private function createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1269
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1270
- {
1271
- echo("\n\n ==========================================================================\n createNewDefaultCategories start... \n");
1272
-
1273
- $old_cats = array();
1274
- $query = $this->db_do("
1275
- SELECT
1276
- cce.entity_id,
1277
- ccev.value AS category_name
1278
- FROM $catalog_category_entity cce
1279
- JOIN $catalog_category_entity_varchar ccev
1280
- ON cce.entity_id = ccev.entity_id
1281
- AND ccev.store_id = 0
1282
- AND cce.entity_type_id = ccev.entity_type_id
1283
- AND ccev.attribute_id = 41
1284
- WHERE parent_id = 1"); // 41 - category name
1285
- while ($row = mysqli_fetch_array($query)) $old_cats[] = $row['category_name'];
1286
-
1287
- //var_dump($old_cats);
1288
-
1289
-
1290
- $query = $this->db_do("SELECT MAX(entity_id) AS max_entity_id FROM $catalog_category_entity");
1291
- $max_entity_id = mysqli_fetch_array($query);
1292
-
1293
- //var_dump($max_entity_id);
1294
-
1295
- $i = $max_entity_id[max_entity_id] + 1;
1296
-
1297
- foreach($coincidence as $key => $item)
1298
- {
1299
- echo("\n coincidence: key = [$key]\n");
1300
-
1301
-
1302
- /**if ($item)
1303
- {
1304
- echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> CONTINUE: key = [$key] item = [$item]\n");
1305
- //continue;
1306
- }
1307
- else
1308
- {
1309
- echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> NOT CONTINUE: key = [$key] item = [$item]\n");
1310
- }/**/
1311
-
1312
-
1313
- if (in_array($key, $old_cats))
1314
- {
1315
- echo(" CONTINUE: key = [$key] item = [$item]\n");
1316
- continue;
1317
- }
1318
- else
1319
- {
1320
- echo(" CREATE NEW CATEGORY: key = [$key] item = [$item]\n");
1321
- }
1322
-
1323
-
1324
- $this->db_do("INSERT $catalog_category_entity
1325
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1326
- path, position, level, children_count, store_category_id, parent_store_category_id)
1327
- VALUES
1328
- ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 0, NULL, NULL)");
1329
-
1330
-
1331
- $this->db_do("INSERT $catalog_category_entity_varchar
1332
- (entity_type_id, attribute_id, store_id, entity_id, value)
1333
- VALUES
1334
- ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
1335
- ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
1336
- ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
1337
- ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
1338
-
1339
-
1340
- $this->db_do("INSERT $catalog_category_entity_int
1341
- (entity_type_id, attribute_id, store_id, entity_id, value)
1342
- VALUES
1343
- ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
1344
- ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
1345
- ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
1346
- ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
1347
- $i++;
1348
- } // foreach($coincidence as $key => $item)
1349
-
1350
- echo("\n createNewDefaultCategories done... \n ==========================================================================\n");
1351
-
1352
- } // private function createNewDefaultCategories()
1353
- ################################################################################################################################################################
1354
-
1355
-
1356
-
1357
-
1358
-
1359
-
1360
-
1361
- ################################################################################################################################################################
1362
- private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type)
1363
- {
1364
- $root_categories = $this->db_do("
1365
- SELECT
1366
- cce.entity_id,
1367
- ccev.value AS category_name
1368
- FROM $catalog_category_entity cce
1369
- JOIN $catalog_category_entity_varchar ccev
1370
- ON cce.entity_id = ccev.entity_id
1371
- AND ccev.store_id = 0
1372
- AND cce.entity_type_id = ccev.entity_type_id
1373
- AND ccev.attribute_id = 41
1374
- WHERE parent_id = 1"); // 41 - category name
1375
- $OLD = array();
1376
- while($root_cat = mysqli_fetch_array($root_categories)) $OLD[] = $root_cat['category_name'];
1377
-
1378
- $new_categories = $this->db_do("SELECT DISTINCT RootName FROM $categories_temp");
1379
- $NEW = array();
1380
- while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['RootName']] = TRUE;
1381
-
1382
- /**
1383
- $exists_coincidence = array();
1384
-
1385
- switch ($im_type)
1386
- {
1387
- case "REWRITE":
1388
- foreach($NEW as $item)
1389
- {
1390
- $exists_coincidence[$item] = TRUE;
1391
- }
1392
- break;
1393
- case "MERGE" :
1394
- foreach($OLD as $item)
1395
- {
1396
- $exists_coincidence[$item] = FALSE;
1397
- }
1398
- foreach($NEW as $item)
1399
- {
1400
- $exists_coincidence[$item] = TRUE;
1401
- }
1402
- break;
1403
- default : $retcode = "error";
1404
- };
1405
- /**/
1406
-
1407
-
1408
-
1409
- echo("\ncalculateCategoryCoincidence ...im_type = [$im_type]\n");
1410
- var_dump($exists_coincidence);
1411
-
1412
- return $exists_coincidence;
1413
- } // private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity)
1414
- ################################################################################################################################################################
1415
-
1416
-
1417
-
1418
- ################################################################################################################################################################
1419
- private function rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1420
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1421
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
1422
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
1423
- {
1424
- echo("rewriteMultistoreCategories RUN\n");
1425
-
1426
-
1427
- echo(" truncateAllCateriesAndCreateRoot start...");
1428
- $this->truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1429
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active);
1430
- echo(" done.\n");
1431
-
1432
-
1433
- echo(" createDefaultCategories start...");
1434
- $this->createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1435
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
1436
- echo(" done.\n");
1437
-
1438
-
1439
- echo(" mapSinchCategoriesMultistore start...");
1440
- $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
1441
- echo(" done.\n");
1442
-
1443
-
1444
- echo(" addCategoryDataMultistore start...");
1445
- $this->addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1446
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1447
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
1448
- echo(" done.\n");
1449
-
1450
-
1451
- echo("rewriteMultistoreCategories DONE\n");
1452
- } // private function rewriteMultistoreCategories()
1453
- ################################################################################################################################################################
1454
-
1455
-
1456
-
1457
-
1458
-
1459
-
1460
-
1461
- ################################################################################################################################################################
1462
- private function truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1463
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active)
1464
- {
1465
- $this->db_do('SET foreign_key_checks=0');
1466
-
1467
-
1468
- $this->db_do("TRUNCATE $catalog_category_entity");
1469
- $this->db_do("TRUNCATE $catalog_category_entity_varchar");
1470
- $this->db_do("TRUNCATE $catalog_category_entity_int");
1471
-
1472
-
1473
- $this->db_do("INSERT $catalog_category_entity
1474
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1475
- path, position, level, children_count, store_category_id, parent_store_category_id)
1476
- VALUES
1477
- (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', NOW(), '1', 0, 0, 1, NULL, NULL)");
1478
-
1479
-
1480
- $this->db_do("INSERT $catalog_category_entity_varchar
1481
- (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1482
- VALUES
1483
- (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
1484
- (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
1485
- (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog')");
1486
-
1487
-
1488
- $this->db_do("INSERT $catalog_category_entity_int
1489
- (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1490
- VALUES
1491
- (1, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1)");
1492
- } // private function truncateAllCateriesAndCreateRoot(...)
1493
- ################################################################################################################################################################
1494
-
1495
-
1496
-
1497
-
1498
- ################################################################################################################################################################
1499
- private function createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1500
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1501
- {
1502
- $i = 3; // 2 - is Default Category... not use.
1503
-
1504
- foreach($coincidence as $key => $item)
1505
- {
1506
- $this->db_do("INSERT $catalog_category_entity
1507
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1508
- path, position, level, children_count, store_category_id, parent_store_category_id)
1509
- VALUES
1510
- ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 0, NULL, NULL)");
1511
-
1512
-
1513
- $this->db_do("INSERT $catalog_category_entity_varchar
1514
- (entity_type_id, attribute_id, store_id, entity_id, value)
1515
- VALUES
1516
- ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
1517
- ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
1518
- ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
1519
- ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
1520
-
1521
-
1522
- $this->db_do("INSERT $catalog_category_entity_int
1523
- (entity_type_id, attribute_id, store_id, entity_id, value)
1524
- VALUES
1525
- ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
1526
- ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
1527
- ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
1528
- ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
1529
- $i++;
1530
- } // foreach($coincidence as $key => $item)
1531
- } // private function truncateAllCateries()
1532
- ################################################################################################################################################################
1533
-
1534
-
1535
-
1536
-
1537
- ################################################################################################################################################################
1538
- private function mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
1539
- {
1540
- echo("\n\n\n\n==========================================================================\nmapSinchCategoriesMultistore start... \n");
1541
-
1542
- $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
1543
-
1544
- $query = "
1545
- INSERT IGNORE INTO $stINch_categories_mapping_temp
1546
- (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
1547
- (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
1548
- FROM $catalog_category_entity)";
1549
- echo("\n\n$query\n\n");
1550
- $this->db_do($query);
1551
-
1552
-
1553
- $query = "
1554
- UPDATE $stINch_categories_mapping_temp cmt
1555
- JOIN $categories_temp c
1556
- ON cmt.shop_store_category_id = c.store_category_id
1557
- SET
1558
- cmt.store_category_id = c.store_category_id,
1559
- cmt.parent_store_category_id = c.parent_store_category_id,
1560
- cmt.category_name = c.category_name,
1561
- cmt.order_number = c.order_number,
1562
- cmt.products_within_this_category = c.products_within_this_category";
1563
- echo("\n\n$query\n\n");
1564
- $this->db_do($query);
1565
-
1566
-
1567
- $query = "
1568
- UPDATE $stINch_categories_mapping_temp cmt
1569
- JOIN $catalog_category_entity cce
1570
- ON cmt.parent_store_category_id = cce.store_category_id
1571
- SET cmt.shop_parent_id = cce.entity_id";
1572
- echo("\n\n$query\n\n");
1573
- $this->db_do($query);
1574
-
1575
-
1576
- $query = "
1577
- SELECT DISTINCT
1578
- c.RootName, cce.entity_id
1579
- FROM $categories_temp c
1580
- JOIN $catalog_category_entity_varchar ccev
1581
- ON c.RootName = ccev.value
1582
- AND ccev.entity_type_id = $_categoryEntityTypeId
1583
- AND ccev.attribute_id = $name_attrid
1584
- AND ccev.store_id = 0
1585
- JOIN $catalog_category_entity cce
1586
- ON ccev.entity_id = cce.entity_id";
1587
- echo("\n\n$query\n\n");
1588
- $root_categories = $this->db_do($query);
1589
-
1590
- while($root_cat = mysqli_fetch_array($root_categories))
1591
- {
1592
- $root_id = $root_cat['entity_id'];
1593
- $root_name = $root_cat['RootName'];
1594
-
1595
- $query = "
1596
- UPDATE $stINch_categories_mapping_temp cmt
1597
- JOIN $categories_temp c
1598
- ON cmt.shop_store_category_id = c.store_category_id
1599
- SET
1600
- cmt.shop_parent_id = $root_id,
1601
- cmt.shop_parent_store_category_id = $root_id,
1602
- cmt.parent_store_category_id = $root_id,
1603
- c.parent_store_category_id = $root_id
1604
- WHERE RootName = '$root_name'
1605
- AND cmt.shop_parent_id = 0";
1606
- echo("\n\n$query\n\n");
1607
- $this->db_do($query);
1608
- }
1609
-
1610
-
1611
-
1612
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1613
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
1614
- else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
1615
-
1616
- $query = "
1617
- UPDATE $stINch_categories_mapping_temp cmt
1618
- JOIN $catalog_category_entity cce
1619
- ON cmt.shop_entity_id = cce.entity_id
1620
- SET cce.parent_id = cmt.shop_parent_id
1621
- $where";
1622
- echo("\n\n$query\n\n");
1623
- $this->db_do($query);
1624
-
1625
- $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
1626
- echo("\n\n$query\n\n");
1627
- $this->db_do($query);
1628
-
1629
- $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
1630
- echo("\n\n$query\n\n");
1631
- $this->db_do($query);
1632
-
1633
- echo("\nmapSinchCategoriesMultistore done... \n==========================================================================\n\n\n\n");
1634
- } // public function mapSinchCategoriesMultistore($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
1635
- ################################################################################################################################################################
1636
-
1637
-
1638
-
1639
- ################################################################################################################################################################
1640
- private function createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping)
1641
- {
1642
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
1643
- $this->db_do("
1644
- CREATE TABLE $stINch_categories_mapping_temp
1645
- (
1646
- shop_entity_id INT(11) UNSIGNED NOT NULL,
1647
- shop_entity_type_id INT(11),
1648
- shop_attribute_set_id INT(11),
1649
- shop_parent_id INT(11),
1650
- shop_store_category_id INT(11),
1651
- shop_parent_store_category_id INT(11),
1652
- store_category_id INT(11),
1653
- parent_store_category_id INT(11),
1654
- category_name VARCHAR(255),
1655
- order_number INT(11),
1656
- products_within_this_category INT(11),
1657
-
1658
- KEY shop_entity_id (shop_entity_id),
1659
- KEY shop_parent_id (shop_parent_id),
1660
- KEY store_category_id (store_category_id),
1661
- KEY parent_store_category_id (parent_store_category_id),
1662
- UNIQUE KEY(shop_entity_id)
1663
- )");
1664
-
1665
-
1666
- $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
1667
- }
1668
- ################################################################################################################################################################
1669
-
1670
-
1671
-
1672
- ################################################################################################################################################################
1673
- private function addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1674
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1675
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
1676
- {
1677
- echo("\n\n\n\n*************************************************************\nmapSinchCategoriesMultistore start... \n");
1678
- if (UPDATE_CATEGORY_DATA)
1679
- {
1680
- $ignore = '';
1681
- $on_diplicate_key_update = "
1682
- ON DUPLICATE KEY UPDATE
1683
- updated_at = now(),
1684
- store_category_id = c.store_category_id,
1685
- level = c.level,
1686
- children_count = c.children_count,
1687
- position = c.order_number,
1688
- parent_store_category_id = c.parent_store_category_id";
1689
- //level=c.level,
1690
- //children_count=c.children_count
1691
- //position=c.order_number,
1692
- }
1693
- else
1694
- {
1695
- $ignore = 'IGNORE';
1696
- $on_diplicate_key_update = '';
1697
- }
1698
-
1699
- $query = "
1700
- INSERT $ignore INTO $catalog_category_entity
1701
- (
1702
- entity_type_id,
1703
- attribute_set_id,
1704
- created_at,
1705
- updated_at,
1706
- level,
1707
- children_count,
1708
- entity_id,
1709
- position,
1710
- parent_id,
1711
- store_category_id,
1712
- parent_store_category_id
1713
- )
1714
- (SELECT
1715
- $_categoryEntityTypeId,
1716
- $_categoryDefault_attribute_set_id,
1717
- NOW(),
1718
- NOW(),
1719
- c.level,
1720
- c.children_count,
1721
- scm.shop_entity_id,
1722
- c.order_number,
1723
- scm.shop_parent_id,
1724
- c.store_category_id,
1725
- c.parent_store_category_id
1726
- FROM $categories_temp c
1727
- LEFT JOIN $stINch_categories_mapping scm
1728
- ON c.store_category_id = scm.store_category_id
1729
- ) $on_diplicate_key_update";
1730
- echo("\n\n$query\n\n");
1731
- $this->db_do($query);
1732
-
1733
- //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
1734
-
1735
-
1736
- $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
1737
-
1738
-
1739
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
1740
- while ($row = mysqli_fetch_array($categories))
1741
- {
1742
- $parent_id = $row['parent_id'];
1743
- $entity_id = $row['entity_id'];
1744
-
1745
- $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
1746
-
1747
- $this->db_do("
1748
- UPDATE $catalog_category_entity
1749
- SET path = '$path'
1750
- WHERE entity_id = $entity_id");
1751
- } // while ($row = mysqli_fetch_array($categories))
1752
-
1753
-
1754
- ///////////////////////////////////////////////////////
1755
-
1756
-
1757
- if(UPDATE_CATEGORY_DATA)
1758
- {
1759
- echo "Update category_data \n";
1760
-
1761
- $q = "
1762
- INSERT INTO $catalog_category_entity_varchar
1763
- (
1764
- entity_type_id,
1765
- attribute_id,
1766
- store_id,
1767
- entity_id,
1768
- value
1769
- )
1770
- (SELECT
1771
- $_categoryEntityTypeId,
1772
- $name_attrid,
1773
- 0,
1774
- scm.shop_entity_id,
1775
- c.category_name
1776
- FROM $categories_temp c
1777
- JOIN $stINch_categories_mapping scm
1778
- ON c.store_category_id = scm.store_category_id
1779
- )
1780
- ON DUPLICATE KEY UPDATE
1781
- value = c.category_name";
1782
- $this->db_do($q);
1783
-
1784
-
1785
- $q = "
1786
- INSERT INTO $catalog_category_entity_varchar
1787
- (
1788
- entity_type_id,
1789
- attribute_id,
1790
- store_id,
1791
- entity_id,
1792
- value
1793
- )
1794
- (SELECT
1795
- $_categoryEntityTypeId,
1796
- $name_attrid,
1797
- 1,
1798
- scm.shop_entity_id,
1799
- c.category_name
1800
- FROM $categories_temp c
1801
- JOIN $stINch_categories_mapping scm
1802
- ON c.store_category_id = scm.store_category_id
1803
- )
1804
- ON DUPLICATE KEY UPDATE
1805
- value = c.category_name";
1806
- $this->db_do($q);
1807
-
1808
-
1809
- $q = "
1810
- INSERT INTO $catalog_category_entity
1811
- (
1812
- entity_type_id,
1813
- attribute_id,
1814
- store_id,
1815
- entity_id,
1816
- value
1817
- )
1818
- (SELECT
1819
- $_categoryEntityTypeId,
1820
- $attr_is_active,
1821
- 0,
1822
- scm.shop_entity_id,
1823
- 1
1824
- FROM $categories_temp c
1825
- JOIN $stINch_categories_mapping scm
1826
- ON c.store_category_id = scm.store_category_id
1827
- )
1828
- ON DUPLICATE KEY UPDATE
1829
- value = 1";
1830
- $this->db_do($q);
1831
-
1832
-
1833
- $q = "
1834
- INSERT INTO $catalog_category_entity_int
1835
- (
1836
- entity_type_id,
1837
- attribute_id,
1838
- store_id,
1839
- entity_id,
1840
- value
1841
- )
1842
- (SELECT
1843
- $_categoryEntityTypeId,
1844
- $attr_is_active,
1845
- 1,
1846
- scm.shop_entity_id,
1847
- 1
1848
- FROM $categories_temp c
1849
- JOIN $stINch_categories_mapping scm
1850
- ON c.store_category_id = scm.store_category_id
1851
- )
1852
- ON DUPLICATE KEY UPDATE
1853
- value = 1";
1854
- $this->db_do($q);
1855
-
1856
-
1857
- $q = "
1858
- INSERT INTO $catalog_category_entity_int
1859
- (
1860
- entity_type_id,
1861
- attribute_id,
1862
- store_id,
1863
- entity_id,
1864
- value
1865
- )
1866
- (SELECT
1867
- $_categoryEntityTypeId,
1868
- $attr_include_in_menu,
1869
- 0,
1870
- scm.shop_entity_id,
1871
- 1
1872
- FROM $categories_temp c
1873
- JOIN $stINch_categories_mapping scm
1874
- ON c.store_category_id = scm.store_category_id
1875
- )
1876
- ON DUPLICATE KEY UPDATE
1877
- value = 1";
1878
- $this->db_do($q);
1879
-
1880
-
1881
- $q = "
1882
- INSERT INTO $catalog_category_entity_int
1883
- (
1884
- entity_type_id,
1885
- attribute_id,
1886
- store_id,
1887
- entity_id,
1888
- value
1889
- )
1890
- (SELECT
1891
- $_categoryEntityTypeId,
1892
- $is_anchor_attrid,
1893
- 1,
1894
- scm.shop_entity_id,
1895
- 1
1896
- FROM $categories_temp c
1897
- JOIN $stINch_categories_mapping scm
1898
- ON c.store_category_id = scm.store_category_id
1899
- )
1900
- ON DUPLICATE KEY UPDATE
1901
- value = 1";
1902
- $this->db_do($q);
1903
-
1904
-
1905
- $q = "
1906
- INSERT INTO $catalog_category_entity_int
1907
- (
1908
- entity_type_id,
1909
- attribute_id,
1910
- store_id,
1911
- entity_id,
1912
- value
1913
- )
1914
- (SELECT
1915
- $_categoryEntityTypeId,
1916
- $is_anchor_attrid,
1917
- 0,
1918
- scm.shop_entity_id,
1919
- 1
1920
- FROM $categories_temp c
1921
- JOIN $stINch_categories_mapping scm
1922
- ON c.store_category_id = scm.store_category_id
1923
- )
1924
- ON DUPLICATE KEY UPDATE
1925
- value = 1";
1926
- $this->db_do($q);
1927
-
1928
- $q = "
1929
- INSERT INTO $catalog_category_entity_varchar
1930
- (
1931
- entity_type_id,
1932
- attribute_id,
1933
- store_id,
1934
- entity_id,
1935
- value
1936
- )
1937
- (SELECT
1938
- $_categoryEntityTypeId,
1939
- $image_attrid,
1940
- 0,
1941
- scm.shop_entity_id,
1942
- c.categories_image
1943
- FROM $categories_temp c
1944
- JOIN $stINch_categories_mapping scm
1945
- ON c.store_category_id = scm.store_category_id
1946
- )
1947
- ON DUPLICATE KEY UPDATE
1948
- value = c.categories_image";
1949
- $this->db_do($q);
1950
- }
1951
- else
1952
- {
1953
- echo "Insert ignore category_data \n";
1954
-
1955
- $q = "
1956
- INSERT IGNORE INTO $catalog_category_entity_varchar
1957
- (
1958
- entity_type_id,
1959
- attribute_id,
1960
- store_id,
1961
- entity_id,
1962
- value
1963
- )
1964
- (SELECT
1965
- $_categoryEntityTypeId,
1966
- $name_attrid,
1967
- 0,
1968
- scm.shop_entity_id,
1969
- c.category_name
1970
- FROM $categories_temp c
1971
- JOIN $stINch_categories_mapping scm
1972
- ON c.store_category_id = scm.store_category_id
1973
- )";
1974
- $this->db_do($q);
1975
-
1976
-
1977
- $q = "
1978
- INSERT IGNORE INTO $catalog_category_entity_int
1979
- (
1980
- entity_type_id,
1981
- attribute_id,
1982
- store_id,
1983
- entity_id,
1984
- value
1985
- )
1986
- (SELECT
1987
- $_categoryEntityTypeId,
1988
- $attr_is_active,
1989
- 0,
1990
- scm.shop_entity_id,
1991
- 1
1992
- FROM $categories_temp c
1993
- JOIN $stINch_categories_mapping scm
1994
- ON c.store_category_id = scm.store_category_id
1995
- )";
1996
- $this->db_do($q);
1997
-
1998
-
1999
- $q = "
2000
- INSERT IGNORE INTO $catalog_category_entity_int
2001
- (
2002
- entity_type_id,
2003
- attribute_id,
2004
- store_id,
2005
- entity_id,
2006
- value
2007
- )
2008
- (SELECT
2009
- $_categoryEntityTypeId,
2010
- $attr_include_in_menu,
2011
- 0,
2012
- scm.shop_entity_id,
2013
- 1
2014
- FROM $categories_temp c
2015
- JOIN $stINch_categories_mapping scm
2016
- ON c.store_category_id = scm.store_category_id
2017
- )";
2018
- $this->db_do($q);
2019
-
2020
-
2021
- $q = "
2022
- INSERT IGNORE INTO $catalog_category_entity_int
2023
- (
2024
- entity_type_id,
2025
- attribute_id,
2026
- store_id,
2027
- entity_id,
2028
- value
2029
- )
2030
- (SELECT
2031
- $_categoryEntityTypeId,
2032
- $is_anchor_attrid,
2033
- 0,
2034
- scm.shop_entity_id,
2035
- 1
2036
- FROM $categories_temp c
2037
- JOIN $stINch_categories_mapping scm
2038
- ON c.store_category_id = scm.store_category_id
2039
- )";
2040
- $this->db_do($q);
2041
-
2042
-
2043
- $q = "
2044
- INSERT IGNORE INTO $catalog_category_entity_varchar
2045
- (
2046
- entity_type_id,
2047
- attribute_id,
2048
- store_id,
2049
- entity_id,
2050
- value
2051
- )
2052
- (SELECT
2053
- $_categoryEntityTypeId,
2054
- $image_attrid,
2055
- 0,
2056
- scm.shop_entity_id,
2057
- c.categories_image
2058
- FROM $categories_temp c
2059
- JOIN $stINch_categories_mapping scm
2060
- ON c.store_category_id = scm.store_category_id
2061
- )";
2062
- $this->db_do($q);
2063
- }
2064
-
2065
- $this->delete_old_sinch_categories_from_shop();
2066
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
2067
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
2068
- } // private function addCategoryDataMultistore(...)
2069
- ################################################################################################################################################################
2070
-
2071
-
2072
-
2073
- ################################################################################################################################################################
2074
- function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
2075
- {
2076
-
2077
- //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]");
2078
-
2079
- $path = '';
2080
-
2081
- $cat_id = $parent_id;
2082
-
2083
- $q = "
2084
- SELECT
2085
- parent_id
2086
- FROM $catalog_category_entity
2087
- WHERE entity_id = $cat_id";
2088
- $quer = $this->db_do($q);
2089
- $row = mysqli_fetch_array($quer);
2090
- while ($row['parent_id'])
2091
- {
2092
- $path = $row['parent_id'].'/'.$path;
2093
- $parent_id = $row['parent_id'];
2094
-
2095
- $q = "
2096
- SELECT
2097
- parent_id
2098
- FROM $catalog_category_entity
2099
- WHERE entity_id = $parent_id";
2100
- $quer = $this->db_do($q);
2101
- $row = mysqli_fetch_array($quer);
2102
- }
2103
-
2104
- if ($cat_id) $path.=$cat_id."/";
2105
-
2106
- if ($path) $path .= $ent_id;
2107
- else $path = $ent_id;
2108
-
2109
- //echo(" path = [$path]\n");
2110
-
2111
- return $path;
2112
- } // function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
2113
- ################################################################################################################################################################
2114
-
2115
-
2116
-
2117
- ################################################################################################################################################################
2118
- public function replaceMagentoProductsMultistore($coincidence)
2119
- {
2120
-
2121
- echo("\n replaceMagentoProductsMultistore 1\n");
2122
-
2123
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
2124
-
2125
-
2126
- $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
2127
- $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
2128
- $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
2129
- $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
2130
- $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
2131
- $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
2132
- $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
2133
- $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
2134
- $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
2135
- $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
2136
- $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
2137
- $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
2138
- $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
2139
- $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
2140
- $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
2141
- $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
2142
-
2143
- $_getProductEntityTypeId = $this->_getProductEntityTypeId();
2144
- $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
2145
-
2146
- $attr_atatus = $this->_getProductAttributeId('status');
2147
- $attr_name = $this->_getProductAttributeId('name');
2148
- $attr_visibility = $this->_getProductAttributeId('visibility');
2149
- $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
2150
- $attr_image = $this->_getProductAttributeId('image');
2151
- $attr_small_image = $this->_getProductAttributeId('small_image');
2152
- $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
2153
-
2154
- $cat_attr_name = $this->_getCategoryAttributeId('name');
2155
- echo("\n replaceMagentoProductsMultistore 2\n");
2156
-
2157
- //clear products, inserting new products and updating old others.
2158
- $result = $this->db_do("
2159
- DELETE cpe
2160
- FROM $catalog_product_entity cpe
2161
- JOIN $stINch_products_mapping pm
2162
- ON cpe.entity_id = pm.entity_id
2163
- WHERE pm.shop_store_product_id IS NOT NULL
2164
- AND pm.store_product_id IS NULL");
2165
-
2166
-
2167
-
2168
- echo("\n replaceMagentoProductsMultistore 3\n");
2169
-
2170
- $result = $this->db_do("
2171
- INSERT INTO $catalog_product_entity
2172
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
2173
- (SELECT
2174
- pm.entity_id,
2175
- $_getProductEntityTypeId,
2176
- $_defaultAttributeSetId,
2177
- 'simple',
2178
- a.product_sku,
2179
- NOW(),
2180
- 0,
2181
- a.store_product_id,
2182
- a.sinch_product_id
2183
- FROM $products_temp a
2184
- LEFT JOIN $stINch_products_mapping pm
2185
- ON a.store_product_id = pm.store_product_id
2186
- AND a.sinch_product_id = pm.sinch_product_id
2187
- )
2188
- ON DUPLICATE KEY UPDATE
2189
- sku = a.product_sku,
2190
- store_product_id = a.store_product_id,
2191
- sinch_product_id = a.sinch_product_id");
2192
- // store_product_id = a.store_product_id,
2193
- // sinch_product_id = a.sinch_product_id
2194
-
2195
- echo("\n replaceMagentoProductsMultistore 4\n");
2196
-
2197
-
2198
- //Set enabled
2199
- $result = $this->db_do("
2200
- DELETE cpei
2201
- FROM $catalog_product_entity_int cpei
2202
- LEFT JOIN $catalog_product_entity cpe
2203
- ON cpei.entity_id = cpe.entity_id
2204
- WHERE cpe.entity_id IS NULL");
2205
-
2206
- $result = $this->db_do("
2207
- INSERT INTO $catalog_product_entity_int
2208
- (entity_type_id, attribute_id, store_id, entity_id, value)
2209
- (SELECT
2210
- $_getProductEntityTypeId,
2211
- $attr_atatus,
2212
- w.website,
2213
- a.entity_id,
2214
- 1
2215
- FROM $catalog_product_entity a
2216
- JOIN $products_website_temp w
2217
- ON a.store_product_id = w.store_product_id
2218
- )
2219
- ON DUPLICATE KEY UPDATE
2220
- value = 1");
2221
-
2222
- //___ return.
2223
-
2224
- echo("\n replaceMagentoProductsMultistore 5\n");
2225
-
2226
-
2227
- // set status = 1 for all stores
2228
- $result = $this->db_do("
2229
- INSERT INTO $catalog_product_entity_int
2230
- (entity_type_id, attribute_id, store_id, entity_id, value)
2231
- (SELECT
2232
- $_getProductEntityTypeId,
2233
- $attr_atatus,
2234
- 0,
2235
- a.entity_id,
2236
- 1
2237
- FROM $catalog_product_entity a
2238
- )
2239
- ON DUPLICATE KEY UPDATE
2240
- value = 1");
2241
-
2242
- echo("\n replaceMagentoProductsMultistore 6\n");
2243
-
2244
-
2245
- //Unifying products with categories.
2246
- $result = $this->db_do("
2247
- DELETE ccp
2248
- FROM $catalog_category_product ccp
2249
- LEFT JOIN $catalog_product_entity cpe
2250
- ON ccp.product_id = cpe.entity_id
2251
- WHERE cpe.entity_id IS NULL");
2252
-
2253
-
2254
- echo("\n replaceMagentoProductsMultistore 7\n");
2255
-
2256
-
2257
- $result = $this->db_do("DROP TABLE IF EXISTS root_cats");
2258
- $result = $this->db_do("
2259
- CREATE TABLE root_cats
2260
- SELECT
2261
- entity_id,
2262
- path,
2263
- SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
2264
- LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
2265
- SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
2266
- FROM catalog_category_entity
2267
- ");
2268
- $result = $this->db_do("UPDATE root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
2269
-
2270
-
2271
- echo("\n replaceMagentoProductsMultistore 8\n");
2272
-
2273
-
2274
- // !!! $this->_root_cat
2275
- $result = $this->db_do("
2276
- UPDATE IGNORE $catalog_category_product ccp
2277
- LEFT JOIN $catalog_category_entity cce
2278
- ON ccp.category_id = cce.entity_id
2279
- JOIN root_cats rc
2280
- ON cce.entity_id = rc.entity_id
2281
- SET ccp.category_id = rc.root_cat
2282
- WHERE cce.entity_id IS NULL");
2283
-
2284
-
2285
-
2286
- echo("\n replaceMagentoProductsMultistore 9\n");
2287
-
2288
-
2289
-
2290
-
2291
- $result = $this->db_do("
2292
- DELETE ccp
2293
- FROM $catalog_category_product ccp
2294
- LEFT JOIN $catalog_category_entity cce
2295
- ON ccp.category_id = cce.entity_id
2296
- WHERE cce.entity_id IS NULL");
2297
-
2298
-
2299
- echo("\n replaceMagentoProductsMultistore 10\n");
2300
-
2301
-
2302
-
2303
- // TEMPORARY
2304
- $this->db_do(" DROP TABLE IF EXISTS {$catalog_category_product}_for_delete_temp");
2305
- $this->db_do("
2306
- CREATE TABLE `{$catalog_category_product}_for_delete_temp`
2307
- (
2308
- `category_id` int(10) unsigned NOT NULL default '0',
2309
- `product_id` int(10) unsigned NOT NULL default '0',
2310
- `store_product_id` int(10) NOT NULL default '0',
2311
- `store_category_id` int(10) NOT NULL default '0',
2312
- `new_category_id` int(10) NOT NULL default '0',
2313
-
2314
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
2315
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
2316
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
2317
- KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
2318
- )");
2319
-
2320
- echo("\n replaceMagentoProductsMultistore 11\n");
2321
-
2322
- $result = $this->db_do("
2323
- INSERT INTO {$catalog_category_product}_for_delete_temp
2324
- (category_id, product_id, store_product_id)
2325
- (SELECT
2326
- ccp.category_id,
2327
- ccp.product_id,
2328
- cpe.store_product_id
2329
- FROM $catalog_category_product ccp
2330
- JOIN $catalog_product_entity cpe
2331
- ON ccp.product_id = cpe.entity_id
2332
- WHERE store_product_id IS NOT NULL)");
2333
-
2334
- echo("\n replaceMagentoProductsMultistore 12\n");
2335
-
2336
- $result = $this->db_do("
2337
- UPDATE {$catalog_category_product}_for_delete_temp ccpfd
2338
- JOIN $products_temp p
2339
- ON ccpfd.store_product_id = p.store_product_id
2340
- SET ccpfd.store_category_id = p.store_category_id
2341
- WHERE ccpfd.store_product_id != 0");
2342
-
2343
- echo("\n replaceMagentoProductsMultistore 13\n");
2344
-
2345
- $result = $this->db_do("
2346
- UPDATE {$catalog_category_product}_for_delete_temp ccpfd
2347
- JOIN $stINch_categories_mapping scm
2348
- ON ccpfd.store_category_id = scm.store_category_id
2349
- SET ccpfd.new_category_id = scm.shop_entity_id
2350
- WHERE ccpfd.store_category_id != 0");
2351
-
2352
- echo("\n replaceMagentoProductsMultistore 14\n");
2353
-
2354
- $result = $this->db_do("DELETE FROM {$catalog_category_product}_for_delete_temp WHERE category_id = new_category_id");
2355
-
2356
- $result = $this->db_do("
2357
- DELETE ccp
2358
- FROM $catalog_category_product ccp
2359
- JOIN {$catalog_category_product}_for_delete_temp ccpfd
2360
- ON ccp.product_id = ccpfd.product_id
2361
- AND ccp.category_id = ccpfd.category_id");
2362
-
2363
- echo("\n replaceMagentoProductsMultistore 15\n");
2364
-
2365
- $result = $this->db_do("
2366
- INSERT INTO $catalog_category_product
2367
- (category_id, product_id)
2368
- (SELECT
2369
- scm.shop_entity_id,
2370
- cpe.entity_id
2371
- FROM $catalog_product_entity cpe
2372
- JOIN $products_temp p
2373
- ON cpe.store_product_id = p.store_product_id
2374
- JOIN $stINch_categories_mapping scm
2375
- ON p.store_category_id = scm.store_category_id
2376
- )
2377
- ON DUPLICATE KEY UPDATE
2378
- product_id = cpe.entity_id");
2379
-
2380
- echo("\n replaceMagentoProductsMultistore 16\n");
2381
-
2382
- //Indexing products and categories in the shop
2383
- $result = $this->db_do("
2384
- DELETE ccpi
2385
- FROM $catalog_category_product_index ccpi
2386
- LEFT JOIN $catalog_product_entity cpe
2387
- ON ccpi.product_id = cpe.entity_id
2388
- WHERE cpe.entity_id IS NULL");
2389
-
2390
-
2391
-
2392
- echo("\n replaceMagentoProductsMultistore 16.2\n");
2393
-
2394
-
2395
- $result = $this->db_do("
2396
- INSERT INTO $catalog_category_product_index
2397
- (category_id, product_id, position, is_parent, store_id, visibility)
2398
- (SELECT
2399
- a.category_id,
2400
- a.product_id,
2401
- a.position,
2402
- 1,
2403
- b.store_id,
2404
- 4
2405
- FROM $catalog_category_product a
2406
- JOIN $core_store b
2407
- )
2408
- ON DUPLICATE KEY UPDATE
2409
- visibility = 4");
2410
-
2411
- echo("\n replaceMagentoProductsMultistore 17\n");
2412
-
2413
- // !!! $this->_root_cat
2414
- $result = $this->db_do("
2415
- INSERT ignore INTO $catalog_category_product_index
2416
- (category_id, product_id, position, is_parent, store_id, visibility)
2417
- (SELECT
2418
- rc.root_cat,
2419
- a.product_id,
2420
- a.position,
2421
- 1,
2422
- b.store_id,
2423
- 4
2424
- FROM $catalog_category_product a
2425
- JOIN root_cats rc
2426
- ON a.category_id = rc.entity_id
2427
- JOIN $core_store b
2428
- )
2429
- ON DUPLICATE KEY UPDATE
2430
- visibility = 4");
2431
-
2432
- echo("\n replaceMagentoProductsMultistore 18\n");
2433
-
2434
-
2435
- //Set product name for specific web sites
2436
- $result = $this->db_do("
2437
- DELETE cpev
2438
- FROM $catalog_product_entity_varchar cpev
2439
- LEFT JOIN $catalog_product_entity cpe
2440
- ON cpev.entity_id = cpe.entity_id
2441
- WHERE cpe.entity_id IS NULL");
2442
-
2443
- $result = $this->db_do("
2444
- INSERT INTO $catalog_product_entity_varchar
2445
- (entity_type_id, attribute_id, store_id, entity_id, value)
2446
- (SELECT
2447
- $_getProductEntityTypeId,
2448
- $attr_name,
2449
- w.website,
2450
- a.entity_id,
2451
- b.product_name
2452
- FROM $catalog_product_entity a
2453
- JOIN $products_temp b
2454
- ON a.store_product_id = b.store_product_id
2455
- JOIN $products_website_temp w
2456
- ON a.store_product_id = w.store_product_id
2457
- )
2458
- ON DUPLICATE KEY UPDATE
2459
- value = b.product_name");
2460
-
2461
- echo("\n replaceMagentoProductsMultistore 19\n");
2462
-
2463
-
2464
- // product name for all web sites
2465
- $result = $this->db_do("
2466
- INSERT INTO $catalog_product_entity_varchar
2467
- (entity_type_id, attribute_id, store_id, entity_id, value)
2468
- (SELECT
2469
- $_getProductEntityTypeId,
2470
- $attr_name,
2471
- 0,
2472
- a.entity_id,
2473
- b.product_name
2474
- FROM $catalog_product_entity a
2475
- JOIN $products_temp b
2476
- ON a.store_product_id = b.store_product_id
2477
- )
2478
- ON DUPLICATE KEY UPDATE
2479
- value = b.product_name");
2480
-
2481
- echo("\n replaceMagentoProductsMultistore 20\n");
2482
-
2483
- $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
2484
- $this->addDescriptions();
2485
- $this->addShortDescriptions();
2486
- $this->addEAN();
2487
- $this->addSpecification();
2488
- $this->addManufacturers();
2489
-
2490
- echo("\n replaceMagentoProductsMultistore 21\n");
2491
-
2492
- //Enabling product index.
2493
- $result = $this->db_do("
2494
- DELETE cpei
2495
- FROM $catalog_product_enabled_index cpei
2496
- LEFT JOIN $catalog_product_entity cpe
2497
- ON cpei.product_id = cpe.entity_id
2498
- WHERE cpe.entity_id IS NULL");
2499
-
2500
- echo("\n replaceMagentoProductsMultistore 22\n");
2501
-
2502
- $result = $this->db_do("
2503
- INSERT INTO $catalog_product_enabled_index
2504
- (product_id, store_id, visibility)
2505
- (SELECT
2506
- a.entity_id,
2507
- w.website,
2508
- 4
2509
- FROM $catalog_product_entity a
2510
- JOIN $products_website_temp w
2511
- ON a.store_product_id = w.store_product_id
2512
- )
2513
- ON DUPLICATE KEY UPDATE
2514
- visibility = 4");
2515
-
2516
- echo("\n replaceMagentoProductsMultistore 23\n");
2517
-
2518
- $result = $this->db_do("
2519
- INSERT INTO $catalog_product_enabled_index
2520
- (product_id, store_id, visibility)
2521
- (SELECT
2522
- a.entity_id,
2523
- 0,
2524
- 4
2525
- FROM $catalog_product_entity a
2526
- JOIN $products_website_temp w
2527
- ON a.store_product_id = w.store_product_id
2528
- )
2529
- ON DUPLICATE KEY UPDATE
2530
- visibility = 4");
2531
-
2532
- echo("\n replaceMagentoProductsMultistore 24\n");
2533
-
2534
- $result = $this->db_do("
2535
- INSERT INTO $catalog_product_entity_int
2536
- (entity_type_id, attribute_id, store_id, entity_id, value)
2537
- (SELECT
2538
- $_getProductEntityTypeId,
2539
- $attr_visibility,
2540
- w.website,
2541
- a.entity_id,
2542
- 4
2543
- FROM $catalog_product_entity a
2544
- JOIN $products_website_temp w
2545
- ON a.store_product_id = w.store_product_id
2546
- )
2547
- ON DUPLICATE KEY UPDATE
2548
- value = 4");
2549
-
2550
- echo("\n replaceMagentoProductsMultistore 25\n");
2551
-
2552
- $result = $this->db_do("
2553
- INSERT INTO $catalog_product_entity_int
2554
- (entity_type_id, attribute_id, store_id, entity_id, value)
2555
- (SELECT
2556
- $_getProductEntityTypeId,
2557
- $attr_visibility,
2558
- 0,
2559
- a.entity_id,
2560
- 4
2561
- FROM $catalog_product_entity a
2562
- )
2563
- ON DUPLICATE KEY UPDATE
2564
- value = 4");
2565
-
2566
- echo("\n replaceMagentoProductsMultistore 26\n");
2567
-
2568
- $result = $this->db_do("
2569
- DELETE cpw
2570
- FROM $catalog_product_website cpw
2571
- LEFT JOIN $catalog_product_entity cpe
2572
- ON cpw.product_id = cpe.entity_id
2573
- WHERE cpe.entity_id IS NULL");
2574
-
2575
- echo("\n replaceMagentoProductsMultistore 27\n");
2576
-
2577
- $result = $this->db_do("
2578
- INSERT INTO $catalog_product_website
2579
- (product_id, website_id)
2580
- (SELECT
2581
- a.entity_id,
2582
- w.website_id
2583
- FROM $catalog_product_entity a
2584
- JOIN $products_website_temp w
2585
- ON a.store_product_id = w.store_product_id
2586
- )
2587
- ON DUPLICATE KEY UPDATE
2588
- product_id = a.entity_id,
2589
- website_id = w.website_id");
2590
-
2591
- echo("\n replaceMagentoProductsMultistore 28\n");
2592
-
2593
- // temporary disabled mart@bintime.com
2594
- //$result = $this->db_do("
2595
- // UPDATE catalog_category_entity_int a
2596
- // SET a.value = 0
2597
- // WHERE a.attribute_id = 32
2598
- //");
2599
-
2600
-
2601
- //Adding tax class "Taxable Goods"
2602
- $result = $this->db_do("
2603
- INSERT INTO $catalog_product_entity_int
2604
- (entity_type_id, attribute_id, store_id, entity_id, value)
2605
- (SELECT
2606
- $_getProductEntityTypeId,
2607
- $attr_tax_class_id,
2608
- w.website,
2609
- a.entity_id,
2610
- 2
2611
- FROM $catalog_product_entity a
2612
- JOIN $products_website_temp w
2613
- ON a.store_product_id = w.store_product_id
2614
- )
2615
- ON DUPLICATE KEY UPDATE
2616
- value = 2");
2617
-
2618
- echo("\n replaceMagentoProductsMultistore 29\n");
2619
-
2620
- $result = $this->db_do("
2621
- INSERT INTO $catalog_product_entity_int
2622
- (entity_type_id, attribute_id, store_id, entity_id, value)
2623
- (SELECT
2624
- $_getProductEntityTypeId,
2625
- $attr_tax_class_id,
2626
- 0,
2627
- a.entity_id,
2628
- 2
2629
- FROM $catalog_product_entity a
2630
- )
2631
- ON DUPLICATE KEY UPDATE
2632
- value = 2");
2633
-
2634
- echo("\n replaceMagentoProductsMultistore 30\n");
2635
-
2636
- // Load url Image
2637
- $result = $this->db_do("
2638
- INSERT INTO $catalog_product_entity_varchar
2639
- (entity_type_id, attribute_id, store_id, entity_id, value)
2640
- (SELECT
2641
- $_getProductEntityTypeId,
2642
- $attr_image,
2643
- w.store_id,
2644
- a.entity_id,
2645
- b.main_image_url
2646
- FROM $catalog_product_entity a
2647
- JOIN $core_store w
2648
- JOIN $products_temp b
2649
- ON a.store_product_id = b.store_product_id
2650
- )
2651
- ON DUPLICATE KEY UPDATE
2652
- value = b.main_image_url");
2653
-
2654
- echo("\n replaceMagentoProductsMultistore 31\n");
2655
-
2656
- // image for specific web sites
2657
- $result = $this->db_do("
2658
- INSERT INTO $catalog_product_entity_varchar
2659
- (entity_type_id, attribute_id, store_id, entity_id, value)
2660
- (SELECT
2661
- $_getProductEntityTypeId,
2662
- $attr_image,
2663
- 0,
2664
- a.entity_id,
2665
- b.main_image_url
2666
- FROM $catalog_product_entity a
2667
- JOIN $products_temp b
2668
- ON a.store_product_id = b.store_product_id
2669
- )
2670
- ON DUPLICATE KEY UPDATE
2671
- value = b.main_image_url");
2672
-
2673
- echo("\n replaceMagentoProductsMultistore 32\n");
2674
-
2675
- // small_image for specific web sites
2676
- $result = $this->db_do("
2677
- INSERT INTO $catalog_product_entity_varchar
2678
- (entity_type_id, attribute_id, store_id, entity_id, value)
2679
- (SELECT
2680
- $_getProductEntityTypeId,
2681
- $attr_small_image,
2682
- w.store_id,
2683
- a.entity_id,
2684
- b.medium_image_url
2685
- FROM $catalog_product_entity a
2686
- JOIN $core_store w
2687
- JOIN $products_temp b
2688
- ON a.store_product_id = b.store_product_id
2689
- )
2690
- ON DUPLICATE KEY UPDATE
2691
- value = b.medium_image_url");
2692
-
2693
- echo("\n replaceMagentoProductsMultistore 33\n");
2694
-
2695
- // small_image for all web sites
2696
- $result = $this->db_do("
2697
- INSERT INTO $catalog_product_entity_varchar
2698
- (entity_type_id, attribute_id, store_id, entity_id, value)
2699
- (SELECT
2700
- $_getProductEntityTypeId,
2701
- $attr_small_image,
2702
- 0,
2703
- a.entity_id,
2704
- b.medium_image_url
2705
- FROM $catalog_product_entity a
2706
- JOIN $core_store w
2707
- JOIN $products_temp b
2708
- ON a.store_product_id = b.store_product_id
2709
- )
2710
- ON DUPLICATE KEY UPDATE
2711
- value = b.medium_image_url");
2712
-
2713
- echo("\n replaceMagentoProductsMultistore 34\n");
2714
-
2715
- // thumbnail for specific web site
2716
- $result = $this->db_do("
2717
- INSERT INTO $catalog_product_entity_varchar
2718
- (entity_type_id, attribute_id, store_id, entity_id, value)
2719
- (SELECT
2720
- $_getProductEntityTypeId,
2721
- $attr_thumbnail,
2722
- w.store_id,
2723
- a.entity_id,
2724
- b.thumb_image_url
2725
- FROM $catalog_product_entity a
2726
- JOIN $core_store w
2727
- JOIN $products_temp b
2728
- ON a.store_product_id = b.store_product_id
2729
- )
2730
- ON DUPLICATE KEY UPDATE
2731
- value = b.thumb_image_url");
2732
-
2733
- echo("\n replaceMagentoProductsMultistore 35\n");
2734
-
2735
- // thumbnail for all web sites
2736
- $result = $this->db_do("
2737
- INSERT INTO $catalog_product_entity_varchar
2738
- (entity_type_id, attribute_id, store_id, entity_id, value)
2739
- (SELECT
2740
- $_getProductEntityTypeId,
2741
- $attr_thumbnail,
2742
- 0,
2743
- a.entity_id,
2744
- b.thumb_image_url
2745
- FROM $catalog_product_entity a
2746
- JOIN $core_store w
2747
- JOIN $products_temp b
2748
- ON a.store_product_id = b.store_product_id
2749
- )
2750
- ON DUPLICATE KEY UPDATE
2751
- value = b.thumb_image_url");
2752
-
2753
- echo("\n replaceMagentoProductsMultistore 36\n");
2754
-
2755
-
2756
- //Refresh fulltext search
2757
- $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
2758
- $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
2759
-
2760
-
2761
- echo("\n replaceMagentoProductsMultistore 36.2\n");
2762
- $q = "
2763
- INSERT INTO {$catalogsearch_fulltext}_tmp
2764
- (product_id, store_id, data_index)
2765
- (SELECT
2766
- a.entity_id,
2767
- w.website,
2768
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
2769
- FROM $catalog_product_entity a
2770
- JOIN $products_website_temp w
2771
- ON a.store_product_id = w.store_product_id
2772
- LEFT JOIN $catalog_category_product b
2773
- ON a.entity_id = b.product_id
2774
- LEFT JOIN $catalog_category_entity_varchar c
2775
- ON b.category_id = c.entity_id
2776
- AND c.attribute_id = $cat_attr_name
2777
- LEFT JOIN $catalog_product_entity_varchar e
2778
- ON a.entity_id = e.entity_id
2779
- AND e.attribute_id = $attr_name
2780
- LEFT JOIN $catalog_product_website j
2781
- ON a.entity_id = j.product_id
2782
- LEFT JOIN $products_temp f
2783
- ON a.entity_id = f.store_product_id
2784
- )
2785
- ON DUPLICATE KEY UPDATE
2786
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
2787
- echo("\n\n============================\n$q\n============================\n\n");
2788
-
2789
-
2790
- $result = $this->db_do("
2791
- INSERT INTO {$catalogsearch_fulltext}_tmp
2792
- (product_id, store_id, data_index)
2793
- (SELECT
2794
- a.entity_id,
2795
- w.website,
2796
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
2797
- FROM $catalog_product_entity a
2798
- JOIN $products_website_temp w
2799
- ON a.store_product_id = w.store_product_id
2800
- LEFT JOIN $catalog_category_product b
2801
- ON a.entity_id = b.product_id
2802
- LEFT JOIN $catalog_category_entity_varchar c
2803
- ON b.category_id = c.entity_id
2804
- AND c.attribute_id = $cat_attr_name
2805
- LEFT JOIN $catalog_product_entity_varchar e
2806
- ON a.entity_id = e.entity_id
2807
- AND e.attribute_id = $attr_name
2808
- LEFT JOIN $catalog_product_website j
2809
- ON a.entity_id = j.product_id
2810
- LEFT JOIN $products_temp f
2811
- ON a.entity_id = f.store_product_id
2812
- )
2813
- ON DUPLICATE KEY UPDATE
2814
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
2815
-
2816
- echo("\n replaceMagentoProductsMultistore 37\n");
2817
-
2818
-
2819
- $result = $this->db_do("
2820
- INSERT INTO {$catalogsearch_fulltext}_tmp
2821
- (product_id, store_id, data_index)
2822
- (SELECT
2823
- a.entity_id,
2824
- w.website,
2825
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
2826
- FROM $catalog_product_entity a
2827
- JOIN $products_website_temp w
2828
- ON a.store_product_id = w.store_product_id
2829
- LEFT JOIN $catalog_category_product b
2830
- ON a.entity_id = b.product_id
2831
- LEFT JOIN $catalog_category_entity_varchar c
2832
- ON b.category_id = c.entity_id
2833
- AND c.attribute_id = $cat_attr_name
2834
- LEFT JOIN $catalog_product_entity_varchar e
2835
- ON a.entity_id = e.entity_id
2836
- AND e.attribute_id = $attr_name
2837
- LEFT JOIN $products_temp f
2838
- ON a.entity_id = f.store_product_id
2839
- )
2840
- ON DUPLICATE KEY UPDATE
2841
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
2842
-
2843
- echo("\n replaceMagentoProductsMultistore 38\n");
2844
-
2845
- $result = $this->db_do("
2846
- DELETE cf
2847
- FROM $catalogsearch_fulltext cf
2848
- LEFT JOIN $catalog_product_entity cpe
2849
- ON cf.product_id = cpe.entity_id
2850
- WHERE cpe.entity_id IS NULL");
2851
-
2852
- echo("\n replaceMagentoProductsMultistore 39\n");
2853
-
2854
- $result = $this->db_do("
2855
- INSERT INTO $catalogsearch_fulltext
2856
- (product_id, store_id, data_index)
2857
- (SELECT
2858
- a.product_id,
2859
- a.store_id,
2860
- a.data_index
2861
- FROM {$catalogsearch_fulltext}_tmp a
2862
- WHERE product_id = a.product_id
2863
- )
2864
- ON DUPLICATE KEY UPDATE
2865
- data_index = a.data_index");
2866
-
2867
- echo("\n replaceMagentoProductsMultistore 40\n");
2868
-
2869
- $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
2870
- //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
2871
- //TODO add something else
2872
-
2873
- $this->addRelatedProducts();
2874
- echo("\n replaceMagentoProductsMultistore 41\n");
2875
- } //
2876
- ################################################################################################################################################################
2877
-
2878
-
2879
-
2880
-
2881
-
2882
-
2883
-
2884
-
2885
-
2886
-
2887
-
2888
-
2889
-
2890
-
2891
-
2892
-
2893
-
2894
-
2895
-
2896
-
2897
-
2898
-
2899
-
2900
-
2901
-
2902
-
2903
-
2904
-
2905
-
2906
-
2907
-
2908
-
2909
-
2910
-
2911
-
2912
-
2913
-
2914
-
2915
-
2916
-
2917
-
2918
-
2919
-
2920
-
2921
-
2922
-
2923
-
2924
-
2925
-
2926
-
2927
-
2928
-
2929
-
2930
-
2931
-
2932
-
2933
-
2934
-
2935
-
2936
-
2937
-
2938
-
2939
-
2940
-
2941
-
2942
-
2943
-
2944
-
2945
-
2946
-
2947
-
2948
-
2949
-
2950
-
2951
-
2952
-
2953
-
2954
-
2955
-
2956
-
2957
-
2958
-
2959
-
2960
-
2961
-
2962
-
2963
-
2964
-
2965
-
2966
- ################################################################################################################################################################
2967
- private function truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
2968
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
2969
- $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
2970
- {
2971
- $this->db_do('SET foreign_key_checks=0');
2972
-
2973
- $this->db_do("TRUNCATE $catalog_category_entity");
2974
- $this->db_do("
2975
- INSERT $catalog_category_entity
2976
- (
2977
- entity_id,
2978
- entity_type_id,
2979
- attribute_set_id,
2980
- parent_id,
2981
- created_at,
2982
- updated_at,
2983
- path,
2984
- position,
2985
- level,
2986
- children_count,
2987
- store_category_id,
2988
- parent_store_category_id
2989
- )
2990
- VALUES
2991
- (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
2992
- (2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 0, null, null)");
2993
-
2994
- $this->db_do("TRUNCATE $catalog_category_entity_varchar");
2995
- $this->db_do("
2996
- INSERT $catalog_category_entity_varchar
2997
- (
2998
- value_id,
2999
- entity_type_id,
3000
- attribute_id,
3001
- store_id,
3002
- entity_id,
3003
- value
3004
- )
3005
- VALUES
3006
- (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
3007
- (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
3008
- (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog'),
3009
- (4, $_categoryEntityTypeId, $name_attrid, 0, 2, 'Default Category'),
3010
- (5, $_categoryEntityTypeId, $name_attrid, 1, 2, 'Default Category'),
3011
- (6, $_categoryEntityTypeId, $attr_display_mode, 1, 2, 'PRODUCTS'),
3012
- (7, $_categoryEntityTypeId, $attr_url_key, 0, 2, 'default-category')");
3013
-
3014
- $this->db_do("TRUNCATE $catalog_category_entity_int");
3015
- $this->db_do("
3016
- INSERT $catalog_category_entity_int
3017
- (
3018
- value_id,
3019
- entity_type_id,
3020
- attribute_id,
3021
- store_id,
3022
- entity_id,
3023
- value
3024
- )
3025
- VALUES
3026
- (1, $_categoryEntityTypeId, $attr_is_active, 0, 2, 1),
3027
- (2, $_categoryEntityTypeId, $attr_is_active, 1, 2, 1),
3028
- (3, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1),
3029
- (4, $_categoryEntityTypeId, $attr_include_in_menu, 0, 2, 1)");
3030
-
3031
- return $root_cat;
3032
- } // private function truncateAllCateriesAndRecreateDefaults(...)
3033
- ################################################################################################################################################################
3034
-
3035
-
3036
-
3037
- ################################################################################################################################################################
3038
- private function setCategorySettings($categories_temp, $root_cat)
3039
- {
3040
- $this->db_do("
3041
- UPDATE $categories_temp
3042
- SET parent_store_category_id = $root_cat
3043
- WHERE parent_store_category_id = 0");
3044
-
3045
- $store_cat_ids = $this->db_do("SELECT store_category_id FROM $categories_temp");
3046
- while ($row = mysqli_fetch_array($store_cat_ids))
3047
- {
3048
- $store_category_id = $row['store_category_id'];
3049
-
3050
- $children_count = $this->count_children($store_category_id);
3051
- $level = $this->get_category_level($store_category_id);
3052
-
3053
- $this->db_do("
3054
- UPDATE $categories_temp
3055
- SET children_count = $children_count,
3056
- level = $level
3057
- WHERE store_category_id = $store_category_id");
3058
- }
3059
- } // private function setCategorySettings($categories_temp, $root_cat)
3060
- ################################################################################################################################################################
3061
-
3062
-
3063
-
3064
-
3065
-
3066
-
3067
-
3068
- ################################################################################################################################################################
3069
- public function mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat)
3070
- {
3071
- $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
3072
-
3073
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
3074
-
3075
- $this->db_do("
3076
- CREATE TABLE $stINch_categories_mapping_temp
3077
- (
3078
- shop_entity_id INT(11) UNSIGNED NOT NULL,
3079
- shop_entity_type_id INT(11),
3080
- shop_attribute_set_id INT(11),
3081
- shop_parent_id INT(11),
3082
- shop_store_category_id INT(11),
3083
- shop_parent_store_category_id INT(11),
3084
- store_category_id INT(11),
3085
- parent_store_category_id INT(11),
3086
- category_name VARCHAR(255),
3087
- order_number INT(11),
3088
- products_within_this_category INT(11),
3089
-
3090
- KEY shop_entity_id (shop_entity_id),
3091
- KEY shop_parent_id (shop_parent_id),
3092
- KEY store_category_id (store_category_id),
3093
- KEY parent_store_category_id (parent_store_category_id),
3094
- UNIQUE KEY(shop_entity_id)
3095
- )");
3096
-
3097
- $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
3098
-
3099
- $this->db_do("
3100
- INSERT IGNORE INTO $stINch_categories_mapping_temp
3101
- (
3102
- shop_entity_id,
3103
- shop_entity_type_id,
3104
- shop_attribute_set_id,
3105
- shop_parent_id,
3106
- shop_store_category_id,
3107
- shop_parent_store_category_id
3108
- )
3109
- (SELECT
3110
- entity_id,
3111
- entity_type_id,
3112
- attribute_set_id,
3113
- parent_id,
3114
- store_category_id,
3115
- parent_store_category_id
3116
- FROM $catalog_category_entity)");
3117
-
3118
- $this->db_do("
3119
- UPDATE $stINch_categories_mapping_temp cmt
3120
- JOIN $categories_temp c
3121
- ON cmt.shop_store_category_id = c.store_category_id
3122
- SET
3123
- cmt.store_category_id = c.store_category_id,
3124
- cmt.parent_store_category_id = c.parent_store_category_id,
3125
- cmt.category_name = c.category_name,
3126
- cmt.order_number = c.order_number,
3127
- cmt.products_within_this_category = c.products_within_this_category");
3128
-
3129
- $this->db_do("
3130
- UPDATE $stINch_categories_mapping_temp cmt
3131
- JOIN $catalog_category_entity cce
3132
- ON cmt.parent_store_category_id = cce.store_category_id
3133
- SET cmt.shop_parent_id = cce.entity_id");
3134
-
3135
- $this->db_do("
3136
- UPDATE $stINch_categories_mapping_temp cmt
3137
- JOIN $categories_temp c
3138
- ON cmt.shop_store_category_id = c.store_category_id
3139
- SET shop_parent_id = ".$this->_root_cat."
3140
- WHERE shop_parent_id = 0");
3141
- // !!!!!!!!!!!!!!!!!!!!!!!!!!! one shop ($this->_root_cat) => milti shop ($root_cat)
3142
-
3143
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
3144
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE"))
3145
- {
3146
- $this->db_do("
3147
- UPDATE $stINch_categories_mapping_temp cmt
3148
- JOIN $catalog_category_entity cce
3149
- ON cmt.shop_entity_id = cce.entity_id
3150
- SET cce.parent_id = cmt.shop_parent_id");
3151
- }
3152
- else
3153
- {
3154
- $this->db_do("
3155
- UPDATE $stINch_categories_mapping_temp cmt
3156
- JOIN $catalog_category_entity cce
3157
- ON cmt.shop_entity_id = cce.entity_id
3158
- SET cce.parent_id = cmt.shop_parent_id
3159
- WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL");
3160
- }
3161
-
3162
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping");
3163
- $this->db_do("RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping");
3164
- } //
3165
- ################################################################################################################################################################
3166
-
3167
-
3168
-
3169
- ################################################################################################################################################################
3170
- private function addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
3171
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat)
3172
- {
3173
- if (UPDATE_CATEGORY_DATA)
3174
- {
3175
- echo "Update category_entity \n";
3176
-
3177
- $q = "
3178
- INSERT INTO $catalog_category_entity
3179
- (
3180
- entity_type_id,
3181
- attribute_set_id,
3182
- created_at,
3183
- updated_at,
3184
- level,
3185
- children_count,
3186
- entity_id,
3187
- position,
3188
- parent_id,
3189
- store_category_id,
3190
- parent_store_category_id
3191
- )
3192
- (SELECT
3193
- $_categoryEntityTypeId,
3194
- $_categoryDefault_attribute_set_id,
3195
- now(),
3196
- now(),
3197
- c.level,
3198
- c.children_count,
3199
- scm.shop_entity_id,
3200
- c.order_number,
3201
- scm.shop_parent_id,
3202
- c.store_category_id,
3203
- c.parent_store_category_id
3204
- FROM $categories_temp c
3205
- LEFT JOIN $stINch_categories_mapping scm
3206
- ON c.store_category_id = scm.store_category_id
3207
- )
3208
- ON DUPLICATE KEY UPDATE
3209
- updated_at = now(),
3210
- store_category_id = c.store_category_id,
3211
- level = c.level,
3212
- children_count = c.children_count,
3213
- position = c.order_number,
3214
- parent_store_category_id = c.parent_store_category_id";
3215
- //level=c.level,
3216
- //children_count=c.children_count
3217
- //position=c.order_number,
3218
- }
3219
- else
3220
- {
3221
- echo "Insert ignore category_entity \n";
3222
-
3223
- $q = "
3224
- INSERT IGNORE INTO $catalog_category_entity
3225
- (
3226
- entity_type_id,
3227
- attribute_set_id,
3228
- created_at,
3229
- updated_at,
3230
- level,
3231
- children_count,
3232
- entity_id,
3233
- position,
3234
- parent_id,
3235
- store_category_id,
3236
- parent_store_category_id
3237
- )
3238
- (SELECT
3239
- $_categoryEntityTypeId,
3240
- $_categoryDefault_attribute_set_id,
3241
- now(),
3242
- now(),
3243
- c.level,
3244
- c.children_count,
3245
- scm.shop_entity_id,
3246
- c.order_number,
3247
- scm.shop_parent_id,
3248
- c.store_category_id,
3249
- c.parent_store_category_id
3250
- FROM $categories_temp c
3251
- LEFT JOIN $stINch_categories_mapping scm
3252
- ON c.store_category_id = scm.store_category_id
3253
- )";
3254
- }
3255
- $this->db_do($q);
3256
-
3257
- $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
3258
-
3259
-
3260
-
3261
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
3262
- while ($row = mysqli_fetch_array($categories))
3263
- {
3264
- $parent_id = $row['parent_id'];
3265
- $entity_id = $row['entity_id'];
3266
-
3267
- $path = $this->culc_path($parent_id, $entity_id);
3268
-
3269
- echo("\n$path\n");
3270
-
3271
- $this->db_do("
3272
- UPDATE $catalog_category_entity
3273
- SET path = '$path'
3274
- WHERE entity_id = $entity_id");
3275
- }
3276
-
3277
- if(UPDATE_CATEGORY_DATA)
3278
- {
3279
- echo "Update category_data \n";
3280
-
3281
- $q = "
3282
- INSERT INTO $catalog_category_entity_varchar
3283
- (
3284
- entity_type_id,
3285
- attribute_id,
3286
- store_id,
3287
- entity_id,
3288
- value
3289
- )
3290
- (SELECT
3291
- $_categoryEntityTypeId,
3292
- $name_attrid,
3293
- 0,
3294
- scm.shop_entity_id,
3295
- c.category_name
3296
- FROM $categories_temp c
3297
- JOIN $stINch_categories_mapping scm
3298
- ON c.store_category_id = scm.store_category_id
3299
- )
3300
- ON DUPLICATE KEY UPDATE
3301
- value = c.category_name";
3302
- $this->db_do($q);
3303
-
3304
- $q = "
3305
- INSERT INTO $catalog_category_entity_varchar
3306
- (
3307
- entity_type_id,
3308
- attribute_id,
3309
- store_id,
3310
- entity_id,
3311
- value
3312
- )
3313
- (SELECT
3314
- $_categoryEntityTypeId,
3315
- $name_attrid,
3316
- 1,
3317
- scm.shop_entity_id,
3318
- c.category_name
3319
- FROM $categories_temp c
3320
- JOIN $stINch_categories_mapping scm
3321
- ON c.store_category_id = scm.store_category_id
3322
- )
3323
- ON DUPLICATE KEY UPDATE
3324
- value = c.category_name";
3325
- $this->db_do($q);
3326
-
3327
- $q = "
3328
- INSERT INTO $catalog_category_entity
3329
- (
3330
- entity_type_id,
3331
- attribute_id,
3332
- store_id,
3333
- entity_id,
3334
- value
3335
- )
3336
- (SELECT
3337
- $_categoryEntityTypeId,
3338
- $attr_is_active,
3339
- 0,
3340
- scm.shop_entity_id,
3341
- 1
3342
- FROM $categories_temp c
3343
- JOIN $stINch_categories_mapping scm
3344
- ON c.store_category_id = scm.store_category_id
3345
- )
3346
- ON DUPLICATE KEY UPDATE
3347
- value = 1";
3348
- $this->db_do($q);
3349
-
3350
- $q = "
3351
- INSERT INTO $catalog_category_entity_int
3352
- (
3353
- entity_type_id,
3354
- attribute_id,
3355
- store_id,
3356
- entity_id,
3357
- value
3358
- )
3359
- (SELECT
3360
- $_categoryEntityTypeId,
3361
- $attr_is_active,
3362
- 1,
3363
- scm.shop_entity_id,
3364
- 1
3365
- FROM $categories_temp c
3366
- JOIN $stINch_categories_mapping scm
3367
- ON c.store_category_id = scm.store_category_id
3368
- )
3369
- ON DUPLICATE KEY UPDATE
3370
- value = 1";
3371
- $this->db_do($q);
3372
-
3373
- $q = "
3374
- INSERT INTO $catalog_category_entity_int
3375
- (
3376
- entity_type_id,
3377
- attribute_id,
3378
- store_id,
3379
- entity_id,
3380
- value
3381
- )
3382
- (SELECT
3383
- $_categoryEntityTypeId,
3384
- $attr_include_in_menu,
3385
- 0,
3386
- scm.shop_entity_id,
3387
- 1
3388
- FROM $categories_temp c
3389
- JOIN $stINch_categories_mapping scm
3390
- ON c.store_category_id = scm.store_category_id
3391
- )
3392
- ON DUPLICATE KEY UPDATE
3393
- value = 1";
3394
- $this->db_do($q);
3395
-
3396
- $q = "
3397
- INSERT INTO $catalog_category_entity_int
3398
- (
3399
- entity_type_id,
3400
- attribute_id,
3401
- store_id,
3402
- entity_id,
3403
- value
3404
- )
3405
- (SELECT
3406
- $_categoryEntityTypeId,
3407
- $is_anchor_attrid,
3408
- 1,
3409
- scm.shop_entity_id,
3410
- 1
3411
- FROM $categories_temp c
3412
- JOIN $stINch_categories_mapping scm
3413
- ON c.store_category_id = scm.store_category_id
3414
- )
3415
- ON DUPLICATE KEY UPDATE
3416
- value = 1";
3417
- $this->db_do($q);
3418
-
3419
- $q = "
3420
- INSERT INTO $catalog_category_entity_int
3421
- (
3422
- entity_type_id,
3423
- attribute_id,
3424
- store_id,
3425
- entity_id,
3426
- value
3427
- )
3428
- (SELECT
3429
- $_categoryEntityTypeId,
3430
- $is_anchor_attrid,
3431
- 0,
3432
- scm.shop_entity_id,
3433
- 1
3434
- FROM $categories_temp c
3435
- JOIN $stINch_categories_mapping scm
3436
- ON c.store_category_id = scm.store_category_id
3437
- )
3438
- ON DUPLICATE KEY UPDATE
3439
- value = 1";
3440
- $this->db_do($q);
3441
-
3442
- $q = "
3443
- INSERT INTO $catalog_category_entity_varchar
3444
- (
3445
- entity_type_id,
3446
- attribute_id,
3447
- store_id,
3448
- entity_id,
3449
- value
3450
- )
3451
- (SELECT
3452
- $_categoryEntityTypeId,
3453
- $image_attrid,
3454
- 0,
3455
- scm.shop_entity_id,
3456
- c.categories_image
3457
- FROM $categories_temp c
3458
- JOIN $stINch_categories_mapping scm
3459
- ON c.store_category_id = scm.store_category_id
3460
- )
3461
- ON DUPLICATE KEY UPDATE
3462
- value = c.categories_image";
3463
- $this->db_do($q);
3464
- }
3465
- else
3466
- {
3467
- echo "Insert ignore category_data \n";
3468
-
3469
- $q = "
3470
- INSERT IGNORE INTO $catalog_category_entity_varchar
3471
- (
3472
- entity_type_id,
3473
- attribute_id,
3474
- store_id,
3475
- entity_id,
3476
- value
3477
- )
3478
- (SELECT
3479
- $_categoryEntityTypeId,
3480
- $name_attrid,
3481
- 0,
3482
- scm.shop_entity_id,
3483
- c.category_name
3484
- FROM $categories_temp c
3485
- JOIN $stINch_categories_mapping scm
3486
- ON c.store_category_id = scm.store_category_id
3487
- )";
3488
- $this->db_do($q);
3489
-
3490
- $q = "
3491
- INSERT IGNORE INTO $catalog_category_entity_int
3492
- (
3493
- entity_type_id,
3494
- attribute_id,
3495
- store_id,
3496
- entity_id,
3497
- value
3498
- )
3499
- (SELECT
3500
- $_categoryEntityTypeId,
3501
- $attr_is_active,
3502
- 0,
3503
- scm.shop_entity_id,
3504
- 1
3505
- FROM $categories_temp c
3506
- JOIN $stINch_categories_mapping scm
3507
- ON c.store_category_id = scm.store_category_id
3508
- )";
3509
- $this->db_do($q);
3510
-
3511
- $q = "
3512
- INSERT IGNORE INTO $catalog_category_entity_int
3513
- (
3514
- entity_type_id,
3515
- attribute_id,
3516
- store_id,
3517
- entity_id,
3518
- value
3519
- )
3520
- (SELECT
3521
- $_categoryEntityTypeId,
3522
- $attr_include_in_menu,
3523
- 0,
3524
- scm.shop_entity_id,
3525
- 1
3526
- FROM $categories_temp c
3527
- JOIN $stINch_categories_mapping scm
3528
- ON c.store_category_id = scm.store_category_id
3529
- )";
3530
- $this->db_do($q);
3531
-
3532
- $q = "
3533
- INSERT IGNORE INTO $catalog_category_entity_int
3534
- (
3535
- entity_type_id,
3536
- attribute_id,
3537
- store_id,
3538
- entity_id,
3539
- value
3540
- )
3541
- (SELECT
3542
- $_categoryEntityTypeId,
3543
- $is_anchor_attrid,
3544
- 0,
3545
- scm.shop_entity_id,
3546
- 1
3547
- FROM $categories_temp c
3548
- JOIN $stINch_categories_mapping scm
3549
- ON c.store_category_id = scm.store_category_id
3550
- )";
3551
- $this->db_do($q);
3552
-
3553
- $q = "
3554
- INSERT IGNORE INTO $catalog_category_entity_varchar
3555
- (
3556
- entity_type_id,
3557
- attribute_id,
3558
- store_id,
3559
- entity_id,
3560
- value
3561
- )
3562
- (SELECT
3563
- $_categoryEntityTypeId,
3564
- $image_attrid,
3565
- 0,
3566
- scm.shop_entity_id,
3567
- c.categories_image
3568
- FROM $categories_temp c
3569
- JOIN $stINch_categories_mapping scm
3570
- ON c.store_category_id = scm.store_category_id
3571
- )";
3572
- $this->db_do($q);
3573
- }
3574
-
3575
- $this->delete_old_sinch_categories_from_shop();
3576
-
3577
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories");
3578
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
3579
- } // private function addCategoryData(...)
3580
- ################################################################################################################################################################
3581
-
3582
-
3583
-
3584
-
3585
-
3586
-
3587
-
3588
-
3589
-
3590
-
3591
-
3592
-
3593
-
3594
-
3595
-
3596
-
3597
-
3598
- function ParseCategoryFeatures(){
3599
-
3600
- $parse_file=$this->varDir.FILE_CATEGORIES_FEATURES;
3601
- if(filesize($parse_file) || $this->_ignore_category_features){
3602
- $this->_LOG("Start parse ".FILE_CATEGORIES_FEATURES);
3603
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp'));
3604
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')." (
3605
- category_feature_id int(11),
3606
- store_category_id int(11),
3607
- feature_name varchar(50),
3608
- display_order_number int(11),
3609
- KEY(store_category_id),
3610
- KEY(category_feature_id)
3611
- )
3612
- ");
3613
-
3614
- if(!$this->_ignore_category_features){
3615
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
3616
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
3617
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
3618
- OPTIONALLY ENCLOSED BY '\"'
3619
- LINES TERMINATED BY \"\r\n\"
3620
- IGNORE 1 LINES ");
3621
- }
3622
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
3623
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
3624
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
3625
-
3626
- $this->_LOG("Finish parse ".FILE_CATEGORIES_FEATURES);
3627
- }else{
3628
- $this->_LOG("Wrong file ".$parse_file);
3629
- }
3630
- $this->_LOG(' ');
3631
- }
3632
-
3633
- #################################################################################################
3634
-
3635
- function ParseDistributors(){
3636
-
3637
- $parse_file=$this->varDir.FILE_DISTRIBUTORS;
3638
- if(filesize($parse_file)){
3639
- $this->_LOG("Start parse ".FILE_DISTRIBUTORS);
3640
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('distributors_temp'));
3641
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."(
3642
- distributor_id int(11),
3643
- distributor_name varchar(255),
3644
- website varchar(255),
3645
- KEY(distributor_id)
3646
- )
3647
- ");
3648
-
3649
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
3650
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
3651
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
3652
- OPTIONALLY ENCLOSED BY '\"'
3653
- LINES TERMINATED BY \"\r\n\"
3654
- IGNORE 1 LINES ");
3655
-
3656
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
3657
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
3658
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
3659
-
3660
- $this->_LOG("Finish parse ".FILE_DISTRIBUTORS);
3661
- }else{
3662
- $this->_LOG("Wrong file ".$parse_file);
3663
- }
3664
- $this->_LOG(' ');
3665
- }
3666
-
3667
- #################################################################################################
3668
-
3669
- function ParseEANCodes(){
3670
-
3671
- $parse_file=$this->varDir.FILE_EANCODES;
3672
- if(filesize($parse_file)){
3673
- $this->_LOG("Start parse ".FILE_EANCODES);
3674
-
3675
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp'));
3676
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."(
3677
- product_id int(11),
3678
- ean_code varchar(255),
3679
- KEY(product_id)
3680
- )");
3681
-
3682
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
3683
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
3684
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
3685
- OPTIONALLY ENCLOSED BY '\"'
3686
- LINES TERMINATED BY \"\r\n\"
3687
- IGNORE 1 LINES ");
3688
-
3689
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
3690
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
3691
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
3692
-
3693
- $this->_LOG("Finish parse ".FILE_EANCODES);
3694
- }else{
3695
- $this->_LOG("Wrong file ".$parse_file);
3696
- }
3697
- $this->_LOG(' ');
3698
- }
3699
-
3700
- #################################################################################################
3701
-
3702
- function ParseManufacturers(){
3703
-
3704
- $parse_file=$this->varDir.FILE_MANUFACTURERS;
3705
- if(filesize($parse_file)){
3706
- $this->_LOG("Start parse ".FILE_MANUFACTURERS);
3707
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp'));
3708
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."(
3709
- sinch_manufacturer_id int(11),
3710
- manufacturer_name varchar(255),
3711
- manufacturers_image varchar(255),
3712
- shop_option_id int(11),
3713
- KEY(sinch_manufacturer_id),
3714
- KEY(shop_option_id),
3715
- KEY(manufacturer_name)
3716
- )");
3717
-
3718
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
3719
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
3720
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
3721
- OPTIONALLY ENCLOSED BY '\"'
3722
- LINES TERMINATED BY \"\r\n\"
3723
- IGNORE 1 LINES ");
3724
-
3725
- $q="DELETE aov
3726
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
3727
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
3728
- ON ao.option_id=aov.option_id left
3729
- JOIN ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
3730
- ON aov.value=mt.manufacturer_name
3731
- WHERE
3732
- ao.attribute_id=".$this->attributes['manufacturer']." AND
3733
- mt.manufacturer_name is null";
3734
- $this->db_do($q);
3735
-
3736
- $q="DELETE ao
3737
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
3738
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
3739
- ON ao.option_id=aov.option_id
3740
- WHERE
3741
- attribute_id=".$this->attributes['manufacturer']." AND
3742
- aov.option_id is null";
3743
- $this->db_do($q);
3744
-
3745
- $q="SELECT
3746
- m.sinch_manufacturer_id,
3747
- m.manufacturer_name,
3748
- m.manufacturers_image
3749
- FROM ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." m
3750
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
3751
- ON m.manufacturer_name=aov.value
3752
- WHERE aov.value IS NULL";
3753
- $quer=$this->db_do($q);
3754
-
3755
- while($row=mysqli_fetch_array($quer)){
3756
- $q0="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
3757
- (attribute_id)
3758
- VALUES(".$this->attributes['manufacturer'].")";
3759
- $quer0=$this->db_do($q0);
3760
-
3761
- $q2="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')."(
3762
- option_id,
3763
- value
3764
- )(
3765
- SELECT
3766
- max(option_id) as option_id,
3767
- "."'".mysqli_real_escape_string($row['manufacturer_name'])."'
3768
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
3769
- WHERE attribute_id=".$this->attributes['manufacturer']."
3770
- )
3771
- ";
3772
- $quer2=$this->db_do($q2);
3773
- // $option['attribute_id'] = $this->attributes['manufacturer'];
3774
- // $option['value'][$row['sinch_manufacturer_id']][0] = $row['manufacturer_name'];
3775
-
3776
- }
3777
-
3778
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
3779
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
3780
- ON mt.manufacturer_name=aov.value
3781
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
3782
- ON ao.option_id=aov.option_id
3783
- SET mt.shop_option_id=aov.option_id
3784
- WHERE ao.attribute_id=".$this->attributes['manufacturer'];
3785
- $this->db_do($q);
3786
-
3787
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
3788
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
3789
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
3790
- $this->_LOG("Finish parse ".FILE_MANUFACTURERS);
3791
- }else{
3792
- $this->_LOG("Wrong file ".$parse_file);
3793
- }
3794
- $this->_LOG(' ');
3795
- }
3796
-
3797
- #################################################################################################
3798
-
3799
- function ParseProductFeatures(){
3800
-
3801
- $parse_file=$this->varDir.FILE_PRODUCT_FEATURES;
3802
- if(filesize($parse_file) || $this->_ignore_product_features){
3803
- $this->_LOG("Start parse ".FILE_PRODUCT_FEATURES);
3804
-
3805
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('product_features_temp'));
3806
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."(
3807
- product_feature_id int(11),
3808
- sinch_product_id int(11),
3809
- restricted_value_id int(11),
3810
- KEY(sinch_product_id),
3811
- KEY(restricted_value_id)
3812
- )
3813
- ");
3814
- if(!$this->_ignore_product_features){
3815
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
3816
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
3817
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
3818
- OPTIONALLY ENCLOSED BY '\"'
3819
- LINES TERMINATED BY \"\r\n\"
3820
- IGNORE 1 LINES ");
3821
- }
3822
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
3823
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
3824
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
3825
-
3826
- $this->_LOG("Finish parse ".FILE_PRODUCT_FEATURES);
3827
- }else{
3828
- $this->_LOG("Wrong file ".$parse_file);
3829
- }
3830
- $this->_LOG(" ");
3831
- }
3832
-
3833
- #################################################################################################
3834
-
3835
- function ParseProducts($coincidence){
3836
- echo("\nParseProducts 2\n");
3837
- $parse_file=$this->varDir.FILE_PRODUCTS;
3838
- if(filesize($parse_file)){
3839
- $this->_LOG("Start parse ".FILE_PRODUCTS);
3840
-
3841
- $file_handle_from = fopen($parse_file, "r");
3842
- unlink($parse_file.".conv");
3843
- $file_handle_to = fopen($parse_file.".conv", "w");
3844
- while (!feof($file_handle_from)) {
3845
- $line = fgets($file_handle_from);
3846
- $line = $this->valid_utf($line);
3847
- fwrite($file_handle_to, $line);
3848
- }
3849
- fclose($file_handle_from);
3850
- fclose($file_handle_to);
3851
- echo("\nParseProducts 2\n");
3852
-
3853
- // $prod_file_str = file_get_contents($parse_file);
3854
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
3855
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
3856
- store_category_product_id int(11),
3857
- store_product_id int(11),
3858
- sinch_product_id int(11),
3859
- product_sku varchar(255),
3860
- product_name varchar(255),
3861
- sinch_manufacturer_id int(11),
3862
- store_category_id int(11),
3863
- main_image_url varchar(255),
3864
- thumb_image_url varchar(255),
3865
- specifications text,
3866
- description text,
3867
- search_cache text,
3868
- spec_characte_u_count int(11),
3869
- description_type varchar(50),
3870
- medium_image_url varchar(255),
3871
- products_date_added datetime default NULL,
3872
- products_last_modified datetime default NULL,
3873
- availability_id_in_stock int(11) default '1',
3874
- availability_id_out_of_stock int(11) default '2',
3875
- products_locate varchar(30) default NULL,
3876
- products_ordered int(11) NOT NULL default '0',
3877
- products_url varchar(255) default NULL,
3878
- products_viewed int(5) default '0',
3879
- products_seo_url varchar(100) NOT NULL,
3880
- manufacturer_name varchar(255) default NULL,
3881
- KEY(store_category_product_id),
3882
- KEY(store_product_id),
3883
- KEY(sinch_manufacturer_id),
3884
- KEY(store_category_id)
3885
- )DEFAULT CHARSET=utf8
3886
- ");
3887
- echo("\nParseProducts 3\n");
3888
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv'
3889
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
3890
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
3891
- OPTIONALLY ENCLOSED BY '\"'
3892
- LINES TERMINATED BY \"\r\n\"
3893
- IGNORE 1 LINES ");
3894
- echo("\nParseProducts 4\n");
3895
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
3896
- CONVERT TO CHARACTER SET \"latin1\"");
3897
- echo("\nParseProducts 5\n");
3898
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
3899
- SET products_date_added=now(), products_last_modified=now()");
3900
- echo("\nParseProducts 6\n");
3901
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
3902
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." m
3903
- ON p.sinch_manufacturer_id=m.sinch_manufacturer_id
3904
- SET p.manufacturer_name=m.manufacturer_name");
3905
- echo("\nParseProducts 7\n");
3906
- if($this->current_import_status_statistic_id){
3907
- $res = $this->db_do("SELECT COUNT(*) AS cnt
3908
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
3909
- $row = mysqli_fetch_assoc($res);
3910
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
3911
- SET number_of_products=".$row['cnt']."
3912
- WHERE id=".$this->current_import_status_statistic_id);
3913
- }
3914
- echo("\nParseProducts 8\n");
3915
- $this->addProductsWebsite();
3916
- $this->mapSinchProducts();
3917
- echo("\nParseProducts 9\n");
3918
-
3919
-
3920
- if (count($coincidence) == -1)
3921
- {
3922
- $this->replaceMagentoProducts();
3923
- }
3924
- else
3925
- {
3926
- $this->replaceMagentoProductsMultistore($coincidence);
3927
- }
3928
- echo("\nParseProducts 10\n");
3929
-
3930
-
3931
- $this->mapSinchProducts();
3932
- $this->addManufacturer_attribute();
3933
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
3934
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
3935
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
3936
- $this->_LOG("Finish parse ".FILE_PRODUCTS);
3937
- }else{
3938
- $this->_LOG("Wrong file ".$parse_file);
3939
- }
3940
- $this->_LOG(" ");
3941
- echo("\nParseProducts 11\n");
3942
- }
3943
-
3944
- #################################################################################################
3945
-
3946
- function ParseRelatedProducts(){
3947
-
3948
- $parse_file=$this->varDir.FILE_RELATED_PRODUCTS;
3949
- if(filesize($parse_file) || $this->_ignore_product_related){
3950
- $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
3951
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('related_products_temp'));
3952
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."(
3953
- sinch_product_id int(11),
3954
- related_sinch_product_id int(11),
3955
- store_product_id int(11) default null,
3956
- store_related_product_id int(11) default null,
3957
- entity_id int(11),
3958
- related_entity_id int(11),
3959
- KEY(sinch_product_id),
3960
- KEY(related_sinch_product_id),
3961
- KEY(store_product_id)
3962
- )DEFAULT CHARSET=utf8");
3963
- if(!$this->_ignore_product_related){
3964
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
3965
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
3966
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
3967
- OPTIONALLY ENCLOSED BY '\"'
3968
- LINES TERMINATED BY \"\r\n\"
3969
- IGNORE 1 LINES ");
3970
- }
3971
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
3972
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
3973
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
3974
-
3975
- $this->_LOG("Finish parse ".FILE_RELATED_PRODUCTS);
3976
- }else{
3977
- $this->_LOG("Wrong file ".$parse_file);
3978
- }
3979
- $this->_LOG(" ");
3980
- }
3981
-
3982
- #################################################################################################
3983
-
3984
- function ParseRestrictedValues(){
3985
-
3986
- $parse_file=$this->varDir.FILE_RESTRICTED_VALUES;
3987
- if(filesize($parse_file) || $this->_ignore_restricted_values){
3988
- $this->_LOG("Start parse ".FILE_RESTRICTED_VALUES);
3989
- $file_handle_from = fopen($parse_file, "r");
3990
- unlink($parse_file.".conv");
3991
- $file_handle_to = fopen($parse_file.".conv", "w");
3992
- while (!feof($file_handle_from)) {
3993
- $line = fgets($file_handle_from);
3994
- $line = $this->valid_utf($line);
3995
- fwrite($file_handle_to, $line);
3996
- }
3997
- fclose($file_handle_from);
3998
- fclose($file_handle_to);
3999
-
4000
-
4001
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp'));
4002
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')." (
4003
- restricted_value_id int(11),
4004
- category_feature_id int(11),
4005
- text text,
4006
- display_order_number int(11),
4007
- KEY(restricted_value_id),
4008
- KEY(category_feature_id)
4009
- )");
4010
- if(!$this->_ignore_restricted_values){
4011
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv'
4012
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
4013
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
4014
- OPTIONALLY ENCLOSED BY '\"'
4015
- LINES TERMINATED BY \"\r\n\"
4016
- IGNORE 1 LINES ");
4017
- }
4018
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
4019
- CONVERT TO CHARACTER SET \"latin1\"");
4020
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
4021
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
4022
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
4023
-
4024
- $this->_LOG("Finish parse ".FILE_RESTRICTED_VALUES);
4025
- }else{
4026
- $this->_LOG("Wrong file ".$parse_file);
4027
- }
4028
- $this->_LOG(" ");
4029
- }
4030
-
4031
- #################################################################################################
4032
-
4033
- function ParseStockAndPrices(){
4034
-
4035
- $parse_file=$this->varDir.FILE_STOCK_AND_PRICES;
4036
- if(filesize($parse_file)){
4037
- $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
4038
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp'));
4039
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." (
4040
- store_product_id int(11),
4041
- stock int(11),
4042
- price decimal(15,4),
4043
- cost decimal(15,4),
4044
- distributor_id int(11),
4045
- KEY(store_product_id),
4046
- KEY(distributor_id)
4047
- )");
4048
-
4049
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
4050
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
4051
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
4052
- OPTIONALLY ENCLOSED BY '\"'
4053
- LINES TERMINATED BY \"\r\n\"
4054
- IGNORE 1 LINES ");
4055
-
4056
- $this->replaceMagentoProductsStockPrice();
4057
-
4058
- $res = $this->db_do("SELECT count(*) as cnt
4059
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4060
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
4061
- ON a.store_product_id=b.store_product_id");
4062
- $row = mysqli_fetch_assoc($res);
4063
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
4064
- SET number_of_products=".$row['cnt']."
4065
- WHERE id=".$this->current_import_status_statistic_id);
4066
-
4067
- $this->addWeight();
4068
-
4069
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
4070
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
4071
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
4072
-
4073
- $this->_LOG("Finish parse".FILE_RELATED_PRODUCTS);
4074
- }else{
4075
- $this->_LOG("Wrong file".$parse_file);
4076
- }
4077
- $this->_LOG(" ");
4078
- }
4079
-
4080
- #################################################################################################
4081
-
4082
- function ParseProductsPicturesGallery(){
4083
-
4084
- $parse_file=$this->varDir.FILE_PRODUCTS_PICTURES_GALLERY;
4085
- if(filesize($parse_file)){
4086
- $this->_LOG("Start parse ".FILE_PRODUCTS_PICTURES_GALLERY);
4087
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp'));
4088
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." (
4089
- sinch_product_id int(11),
4090
- image_url varchar(255),
4091
- thumb_image_url varchar(255),
4092
- store_product_id int(11),
4093
- key(sinch_product_id),
4094
- key(store_product_id)
4095
- )");
4096
-
4097
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
4098
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
4099
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
4100
- OPTIONALLY ENCLOSED BY '\"'
4101
- LINES TERMINATED BY \"\r\n\"
4102
- IGNORE 1 LINES ");
4103
-
4104
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." ppgt
4105
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
4106
- ON ppgt.sinch_product_id=sp.sinch_product_id
4107
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4108
- ON sp.store_product_id=cpe.store_product_id
4109
- SET ppgt.store_product_id=sp.store_product_id");
4110
-
4111
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
4112
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
4113
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
4114
-
4115
- $this->_LOG("Finish parse".FILE_PRODUCTS_PICTURES_GALLERY);
4116
- }else{
4117
- $this->_LOG("Wrong file".$parse_file);
4118
- }
4119
- $this->_LOG(" ");
4120
-
4121
- }
4122
-
4123
-
4124
-
4125
- #################################################################################################
4126
- public function mapSinchProducts(){
4127
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
4128
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
4129
- entity_id int(11) unsigned NOT NULL,
4130
- manufacturer_option_id int(11),
4131
- manufacturer_name varchar(255),
4132
- shop_store_product_id int(11),
4133
- shop_sinch_product_id int(11),
4134
- sku varchar(64) default NULL,
4135
- store_category_product_id int(11),
4136
- store_product_id int(11),
4137
- sinch_product_id int(11),
4138
- product_sku varchar(255),
4139
- sinch_manufacturer_id int(11),
4140
- sinch_manufacturer_name varchar(255),
4141
- KEY entity_id (entity_id),
4142
- KEY manufacturer_option_id (manufacturer_option_id),
4143
- KEY manufacturer_name (manufacturer_name),
4144
- KEY store_product_id (store_product_id),
4145
- KEY sinch_product_id (sinch_product_id),
4146
- KEY sku (sku),
4147
- UNIQUE KEY(entity_id)
4148
- )
4149
- ");
4150
- $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
4151
- LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
4152
- $result = $this->db_do("
4153
- INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
4154
- entity_id,
4155
- sku,
4156
- shop_store_product_id,
4157
- shop_sinch_product_id
4158
- )(SELECT
4159
- entity_id,
4160
- sku,
4161
- store_product_id,
4162
- sinch_product_id
4163
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')."
4164
- )
4165
- ");
4166
-
4167
- $this->addManufacturers(1);
4168
-
4169
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
4170
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." cpie
4171
- ON pmt.entity_id=cpie.entity_id
4172
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
4173
- ON cpie.value=aov.option_id
4174
- SET
4175
- manufacturer_option_id=cpie.value,
4176
- manufacturer_name=aov.value
4177
- WHERE cpie.attribute_id=".$this->attributes['manufacturer'];
4178
- $this->db_do($q);
4179
-
4180
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
4181
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
4182
- ON pmt.sku=p.product_sku
4183
- SET
4184
- pmt.store_category_product_id=p.store_category_product_id,
4185
- pmt.store_product_id=p.store_product_id,
4186
- pmt.sinch_product_id=p.sinch_product_id,
4187
- pmt.product_sku=p.product_sku,
4188
- pmt.sinch_manufacturer_id=p.sinch_manufacturer_id,
4189
- pmt.sinch_manufacturer_name=p.manufacturer_name";
4190
-
4191
- $this->db_do($q);
4192
-
4193
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4194
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
4195
- ON cpe.entity_id=pmt.entity_id
4196
- SET cpe.store_product_id=pmt.store_product_id,
4197
- cpe.sinch_product_id=pmt.sinch_product_id
4198
- WHERE
4199
- cpe.sinch_product_id IS NULL
4200
- AND pmt.sinch_product_id IS NOT NULL
4201
- AND cpe.store_product_id IS NULL
4202
- AND pmt.store_product_id IS NOT NULL";
4203
- $this->db_do($q);
4204
-
4205
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
4206
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')."
4207
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
4208
- }
4209
- #################################################################################################
4210
- public function addProductsWebsite (){
4211
- $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_website_temp'));
4212
- // TEMPORARY
4213
- $this->db_do("
4214
- CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('products_website_temp')."` (
4215
- `id` int(10) unsigned NOT NULL auto_increment,
4216
- store_product_id int(11),
4217
- sinch_product_id int(11),
4218
- `website` int(11) default NULL,
4219
- `website_id` int(11) default NULL,
4220
- PRIMARY KEY (`id`),
4221
- KEY store_product_id (`store_product_id`)
4222
- )
4223
- ");
4224
- $result = $this->db_do("SELECT
4225
- website_id,
4226
- store_id as website
4227
- FROM ".Mage::getSingleton('core/resource')->getTableName('core_store')."
4228
- WHERE code!='admin'
4229
- "); // where code!='admin' was adder for editing Featured products;
4230
- while ($row = mysqli_fetch_assoc($result)) {
4231
- $sql = "INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." (
4232
- store_product_id,
4233
- sinch_product_id,
4234
- website,
4235
- website_id
4236
- )(
4237
- SELECT
4238
- distinct
4239
- store_product_id,
4240
- sinch_product_id,
4241
- {$row['website']},
4242
- {$row['website_id']}
4243
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
4244
- )";
4245
- $result2 = $this->db_do($sql);
4246
- }
4247
-
4248
-
4249
- }
4250
-
4251
- #################################################################################################
4252
- public function replaceMagentoProducts() {
4253
-
4254
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
4255
-
4256
- $result = $this->db_do("DELETE cpe
4257
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4258
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
4259
- ON cpe.entity_id=pm.entity_id
4260
- WHERE pm.shop_store_product_id IS NOT NULL
4261
- AND pm.store_product_id IS NULL
4262
- ");
4263
-
4264
- //Inserting new products and updating old others.
4265
- $this->_getProductDefaulAttributeSetId();
4266
- $result = $this->db_do("
4267
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." (
4268
- entity_id,
4269
- entity_type_id,
4270
- attribute_set_id,
4271
- type_id,
4272
- sku,
4273
- updated_at,
4274
- has_options,
4275
- store_product_id,
4276
- sinch_product_id
4277
- )(SELECT
4278
- pm.entity_id,
4279
- " . $this->_getProductEntityTypeId(). ",
4280
- $this->defaultAttributeSetId,
4281
- 'simple',
4282
- a.product_sku,
4283
- NOW(),
4284
- 0,
4285
- a.store_product_id,
4286
- a.sinch_product_id
4287
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')." a
4288
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
4289
- ON a.store_product_id=pm.store_product_id
4290
- AND a.sinch_product_id=pm.sinch_product_id
4291
- )
4292
- ON DUPLICATE KEY UPDATE
4293
- sku= a.product_sku,
4294
- store_product_id=a.store_product_id,
4295
- sinch_product_id=a.sinch_product_id
4296
- ");
4297
- // store_product_id=a.store_product_id,
4298
- // sinch_product_id=a.sinch_product_id
4299
-
4300
- //Set enabled
4301
- $result = $this->db_do("DELETE cpei
4302
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." cpei
4303
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4304
- ON cpei.entity_id=cpe.entity_id
4305
- WHERE cpe.entity_id IS NULL");
4306
-
4307
- $result = $this->db_do("
4308
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
4309
- entity_type_id,
4310
- attribute_id,
4311
- store_id,
4312
- entity_id,
4313
- value
4314
- )(
4315
- SELECT
4316
- " . $this->_getProductEntityTypeId(). ",
4317
- ". $this->_getProductAttributeId('status').",
4318
- w.website,
4319
- a.entity_id,
4320
- 1
4321
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4322
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4323
- ON a.store_product_id=w.store_product_id
4324
- )
4325
- ON DUPLICATE KEY UPDATE
4326
- value=1
4327
- ");
4328
- // set status = 1 for all stores
4329
- $result = $this->db_do("
4330
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
4331
- entity_type_id,
4332
- attribute_id,
4333
- store_id,
4334
- entity_id,
4335
- value
4336
- )(SELECT
4337
- " . $this->_getProductEntityTypeId(). ",
4338
- ".$this->_getProductAttributeId('status').",
4339
- 0,
4340
- a.entity_id,
4341
- 1
4342
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4343
- )
4344
- ON DUPLICATE KEY UPDATE
4345
- value=1
4346
- ");
4347
-
4348
- //Unifying products with categories.
4349
- $result = $this->db_do("DELETE ccp
4350
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
4351
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4352
- ON ccp.product_id=cpe.entity_id
4353
- WHERE cpe.entity_id IS NULL");
4354
-
4355
- echo("\n\n\nUPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
4356
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
4357
- ON ccp.category_id=cce.entity_id
4358
- SET ccp.category_id=".$this->_root_cat."
4359
- WHERE cce.entity_id IS NULL");
4360
- $result = $this->db_do("UPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
4361
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
4362
- ON ccp.category_id=cce.entity_id
4363
- SET ccp.category_id=".$this->_root_cat."
4364
- WHERE cce.entity_id IS NULL");
4365
- echo("\ndone\n");
4366
-
4367
-
4368
- echo("\n\n\nDELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
4369
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
4370
- ON ccp.category_id=cce.entity_id
4371
- WHERE cce.entity_id IS NULL");
4372
- $result = $this->db_do("DELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
4373
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
4374
- ON ccp.category_id=cce.entity_id
4375
- WHERE cce.entity_id IS NULL");
4376
- echo("\ndone\n");
4377
-
4378
-
4379
- $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp");
4380
- // TEMPORARY
4381
- $this->db_do("
4382
- CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp` (
4383
- `category_id` int(10) unsigned NOT NULL default '0',
4384
- `product_id` int(10) unsigned NOT NULL default '0',
4385
- `store_product_id` int(10) NOT NULL default '0',
4386
- `store_category_id` int(10) NOT NULL default '0',
4387
- `new_category_id` int(10) NOT NULL default '0',
4388
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
4389
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
4390
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
4391
- KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
4392
- )
4393
-
4394
- ");
4395
-
4396
- $result = $this->db_do("
4397
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp (
4398
- category_id,
4399
- product_id,
4400
- store_product_id
4401
- )(SELECT
4402
- ccp.category_id,
4403
- ccp.product_id,
4404
- cpe.store_product_id
4405
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
4406
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4407
- ON ccp.product_id=cpe.entity_id
4408
- WHERE store_product_id is not null
4409
- )
4410
- ");
4411
-
4412
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
4413
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
4414
- ON ccpfd.store_product_id=p.store_product_id
4415
- SET ccpfd.store_category_id=p.store_category_id
4416
- WHERE ccpfd.store_product_id!=0
4417
- ");
4418
-
4419
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
4420
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
4421
- ON ccpfd.store_category_id=scm.store_category_id
4422
- SET ccpfd.new_category_id=scm.shop_entity_id
4423
- WHERE ccpfd.store_category_id!=0
4424
- ");
4425
-
4426
- $result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp
4427
- WHERE category_id=new_category_id");
4428
-
4429
- $result = $this->db_do("
4430
- DELETE ccp
4431
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
4432
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
4433
- ON ccp.product_id=ccpfd.product_id
4434
- AND ccp.category_id=ccpfd.category_id
4435
- ");
4436
-
4437
- $result = $this->db_do("
4438
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." (
4439
- category_id,
4440
- product_id
4441
- )(SELECT
4442
- scm.shop_entity_id,
4443
- cpe.entity_id
4444
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4445
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
4446
- ON cpe.store_product_id=p.store_product_id
4447
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
4448
- ON p.store_category_id=scm.store_category_id
4449
- )
4450
- ON DUPLICATE KEY UPDATE
4451
- product_id = cpe.entity_id
4452
- ");
4453
-
4454
- //Indexing products and categories in the shop
4455
- $result = $this->db_do("DELETE ccpi
4456
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." ccpi
4457
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4458
- ON ccpi.product_id=cpe.entity_id
4459
- WHERE cpe.entity_id IS NULL");
4460
-
4461
- $result = $this->db_do("
4462
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
4463
- category_id,
4464
- product_id,
4465
- position,
4466
- is_parent,
4467
- store_id,
4468
- visibility
4469
- )(
4470
- SELECT
4471
- a.category_id,
4472
- a.product_id,
4473
- a.position,
4474
- 1,
4475
- b.store_id,
4476
- 4
4477
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
4478
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
4479
- )
4480
- ON DUPLICATE KEY UPDATE
4481
- visibility = 4
4482
- ");
4483
-
4484
- $result = $this->db_do("
4485
- INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
4486
- category_id,
4487
- product_id,
4488
- position,
4489
- is_parent,
4490
- store_id,
4491
- visibility
4492
- )(
4493
- SELECT
4494
- ".$this->_root_cat.",
4495
- a.product_id,
4496
- a.position,
4497
- 1,
4498
- b.store_id,
4499
- 4
4500
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
4501
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
4502
- )
4503
- ON DUPLICATE KEY UPDATE
4504
- visibility = 4
4505
- ");
4506
-
4507
- //Set product name for specific web sites
4508
- $result = $this->db_do("DELETE cpev
4509
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." cpev
4510
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4511
- ON cpev.entity_id=cpe.entity_id
4512
- WHERE cpe.entity_id IS NULL");
4513
- $result = $this->db_do("
4514
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
4515
- entity_type_id,
4516
- attribute_id,
4517
- store_id,
4518
- entity_id,
4519
- value
4520
- )(SELECT
4521
- " . $this->_getProductEntityTypeId(). ",
4522
- " . $this->_getProductAttributeId('name'). ",
4523
- w.website,
4524
- a.entity_id,
4525
- b.product_name
4526
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4527
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4528
- ON a.store_product_id= b.store_product_id
4529
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4530
- ON a.store_product_id=w.store_product_id
4531
- )
4532
- ON DUPLICATE KEY UPDATE
4533
- value = b.product_name
4534
- ");
4535
-
4536
- // product name for all web sites
4537
- $result = $this->db_do("
4538
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
4539
- entity_type_id,
4540
- attribute_id,
4541
- store_id,
4542
- entity_id,
4543
- value
4544
- )(
4545
- SELECT
4546
- " . $this->_getProductEntityTypeId(). ",
4547
- " . $this->_getProductAttributeId('name'). ",
4548
- 0,
4549
- a.entity_id,
4550
- b.product_name
4551
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4552
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4553
- ON a.store_product_id = b.store_product_id
4554
- )
4555
- ON DUPLICATE KEY UPDATE
4556
- value = b.product_name
4557
- ");
4558
-
4559
- $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
4560
- $this->addDescriptions();
4561
- $this->addShortDescriptions();
4562
- $this->addEAN();
4563
- $this->addSpecification();
4564
- $this->addManufacturers();
4565
-
4566
- //Enabling product index.
4567
- $result = $this->db_do("DELETE cpei
4568
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." cpei
4569
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4570
- ON cpei.product_id=cpe.entity_id
4571
- WHERE cpe.entity_id IS NULL");
4572
-
4573
- $result = $this->db_do("
4574
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
4575
- product_id,
4576
- store_id,
4577
- visibility
4578
- )(
4579
- SELECT
4580
- a.entity_id,
4581
- w.website,
4582
- 4
4583
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4584
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4585
- ON a.store_product_id=w.store_product_id
4586
- )
4587
- ON DUPLICATE KEY UPDATE
4588
- visibility = 4
4589
- ");
4590
- $result = $this->db_do("
4591
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
4592
- product_id,
4593
- store_id,
4594
- visibility
4595
- )(
4596
- SELECT
4597
- a.entity_id,
4598
- 0,
4599
- 4
4600
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4601
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4602
- ON a.store_product_id=w.store_product_id
4603
- )
4604
- ON DUPLICATE KEY UPDATE
4605
- visibility = 4
4606
- ");
4607
-
4608
-
4609
- $result = $this->db_do("
4610
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
4611
- entity_type_id,
4612
- attribute_id,
4613
- store_id,
4614
- entity_id,
4615
- value
4616
- )(
4617
- SELECT
4618
- " . $this->_getProductEntityTypeId(). ",
4619
- " . $this->_getProductAttributeId('visibility'). ",
4620
- w.website,
4621
- a.entity_id,
4622
- 4
4623
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4624
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4625
- ON a.store_product_id=w.store_product_id
4626
- )
4627
- ON DUPLICATE KEY UPDATE
4628
- value = 4
4629
- ");
4630
-
4631
- $result = $this->db_do("
4632
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
4633
- entity_type_id,
4634
- attribute_id,
4635
- store_id,
4636
- entity_id,
4637
- value
4638
- )(
4639
- SELECT
4640
- " . $this->_getProductEntityTypeId(). ",
4641
- " . $this->_getProductAttributeId('visibility'). ",
4642
- 0,
4643
- a.entity_id,
4644
- 4
4645
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4646
- )
4647
- ON DUPLICATE KEY UPDATE
4648
- value = 4
4649
- ");
4650
-
4651
- $result = $this->db_do("DELETE cpw
4652
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." cpw
4653
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4654
- ON cpw.product_id=cpe.entity_id
4655
- WHERE cpe.entity_id IS NULL");
4656
-
4657
- $result = $this->db_do("
4658
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." (
4659
- product_id,
4660
- website_id
4661
- )(
4662
- SELECT a.entity_id, w.website_id
4663
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4664
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4665
- ON a.store_product_id=w.store_product_id
4666
- )
4667
- ON DUPLICATE KEY UPDATE
4668
- product_id=a.entity_id,
4669
- website_id=w.website_id
4670
- ");
4671
-
4672
- // temporary disabled mart@bintime.com
4673
- //$result = $this->db_do("
4674
- // UPDATE catalog_category_entity_int a
4675
- // SET a.value = 0
4676
- // WHERE a.attribute_id = 32
4677
- //");
4678
-
4679
-
4680
- //Adding tax class "Taxable Goods"
4681
- $result = $this->db_do("
4682
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
4683
- entity_type_id,
4684
- attribute_id,
4685
- store_id,
4686
- entity_id,
4687
- value
4688
- )(
4689
- SELECT
4690
- " . $this->_getProductEntityTypeId(). ",
4691
- " . $this->_getProductAttributeId('tax_class_id'). ",
4692
- w.website,
4693
- a.entity_id,
4694
- 2
4695
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4696
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4697
- ON a.store_product_id=w.store_product_id
4698
- )
4699
- ON DUPLICATE KEY UPDATE
4700
- value = 2
4701
- ");
4702
- $result = $this->db_do("
4703
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
4704
- entity_type_id,
4705
- attribute_id,
4706
- store_id,
4707
- entity_id,
4708
- value
4709
- )(
4710
- SELECT
4711
- " . $this->_getProductEntityTypeId(). ",
4712
- " . $this->_getProductAttributeId('tax_class_id'). ",
4713
- 0,
4714
- a.entity_id,
4715
- 2
4716
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4717
- )
4718
- ON DUPLICATE KEY UPDATE
4719
- value = 2
4720
- ");
4721
-
4722
- // Load url Image
4723
- $result = $this->db_do("
4724
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
4725
- entity_type_id,
4726
- attribute_id,
4727
- store_id,
4728
- entity_id,
4729
- value
4730
- )(
4731
- SELECT
4732
- " . $this->_getProductEntityTypeId(). ",
4733
- " . $this->_getProductAttributeId('image'). ",
4734
- w.store_id,
4735
- a.entity_id,
4736
- b.main_image_url
4737
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4738
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
4739
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4740
- ON a.store_product_id = b.store_product_id
4741
- )
4742
- ON DUPLICATE KEY UPDATE
4743
- value = b.main_image_url
4744
- ");
4745
-
4746
-
4747
- // image for specific web sites
4748
- $result = $this->db_do("
4749
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
4750
- entity_type_id,
4751
- attribute_id,
4752
- store_id,
4753
- entity_id,
4754
- value
4755
- )(
4756
- SELECT
4757
- " . $this->_getProductEntityTypeId(). ",
4758
- " . $this->_getProductAttributeId('image'). ",
4759
- 0,
4760
- a.entity_id,
4761
- b.main_image_url
4762
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4763
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4764
- ON a.store_product_id = b.store_product_id
4765
- )
4766
- ON DUPLICATE KEY UPDATE
4767
- value = b.main_image_url
4768
- ");
4769
-
4770
-
4771
- // small_image for specific web sites
4772
- $result = $this->db_do("
4773
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
4774
- entity_type_id,
4775
- attribute_id,
4776
- store_id,
4777
- entity_id,
4778
- value
4779
- )(
4780
- SELECT
4781
- " . $this->_getProductEntityTypeId(). ",
4782
- " . $this->_getProductAttributeId('small_image'). ",
4783
- w.store_id,
4784
- a.entity_id,
4785
- b.medium_image_url
4786
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4787
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
4788
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4789
- ON a.store_product_id = b.store_product_id
4790
- )
4791
- ON DUPLICATE KEY UPDATE
4792
- value = b.medium_image_url
4793
- ");
4794
-
4795
-
4796
- // small_image for all web sites
4797
- $result = $this->db_do("
4798
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
4799
- entity_type_id,
4800
- attribute_id,
4801
- store_id,
4802
- entity_id,
4803
- value
4804
- )(
4805
- SELECT
4806
- " . $this->_getProductEntityTypeId(). ",
4807
- " . $this->_getProductAttributeId('small_image'). ",
4808
- 0,
4809
- a.entity_id,
4810
- b.medium_image_url
4811
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4812
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
4813
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4814
- ON a.store_product_id = b.store_product_id
4815
- )
4816
- ON DUPLICATE KEY UPDATE
4817
- value = b.medium_image_url
4818
- ");
4819
-
4820
-
4821
- // thumbnail for specific web site
4822
- $result = $this->db_do("
4823
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
4824
- entity_type_id,
4825
- attribute_id,
4826
- store_id,
4827
- entity_id,
4828
- value
4829
- )(
4830
- SELECT
4831
- " . $this->_getProductEntityTypeId(). ",
4832
- " . $this->_getProductAttributeId('thumbnail'). ",
4833
- w.store_id,
4834
- a.entity_id,
4835
- b.thumb_image_url
4836
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4837
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
4838
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4839
- ON a.store_product_id = b.store_product_id
4840
- )
4841
- ON DUPLICATE KEY UPDATE
4842
- value = b.thumb_image_url
4843
- ");
4844
-
4845
-
4846
- // thumbnail for all web sites
4847
- $result = $this->db_do("
4848
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
4849
- entity_type_id,
4850
- attribute_id,
4851
- store_id,
4852
- entity_id,
4853
- value
4854
- )(
4855
- SELECT
4856
- " . $this->_getProductEntityTypeId(). ",
4857
- " . $this->_getProductAttributeId('thumbnail'). ",
4858
- 0,
4859
- a.entity_id,
4860
- b.thumb_image_url
4861
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4862
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
4863
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4864
- ON a.store_product_id = b.store_product_id
4865
- )
4866
- ON DUPLICATE KEY UPDATE
4867
- value = b.thumb_image_url
4868
-
4869
- ");
4870
-
4871
-
4872
- //Refresh fulltext search
4873
- $result = $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp");
4874
- $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS
4875
- ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp
4876
- LIKE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext'));
4877
-
4878
- $result = $this->db_do("
4879
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
4880
- product_id,
4881
- store_id,
4882
- data_index
4883
- )(
4884
- SELECT
4885
- a.entity_id,
4886
- w.website,
4887
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4888
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4889
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4890
- ON a.store_product_id=w.store_product_id
4891
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
4892
- ON a.entity_id = b.product_id
4893
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
4894
- ON b.category_id = c.entity_id
4895
- AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
4896
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
4897
- ON a.entity_id = e.entity_id
4898
- AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
4899
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." j
4900
- ON a.entity_id = j.product_id
4901
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
4902
- ON a.entity_id = f.store_product_id
4903
- )
4904
- ON DUPLICATE KEY UPDATE
4905
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4906
- ");
4907
-
4908
- $result = $this->db_do("
4909
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
4910
- product_id,
4911
- store_id,
4912
- data_index
4913
- )(
4914
- SELECT
4915
- a.entity_id,
4916
- w.website,
4917
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4918
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4919
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4920
- ON a.store_product_id=w.store_product_id
4921
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
4922
- ON a.entity_id = b.product_id
4923
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
4924
- ON b.category_id = c.entity_id
4925
- AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
4926
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
4927
- ON a.entity_id = e.entity_id
4928
- AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
4929
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
4930
- ON a.entity_id = f.store_product_id
4931
- )
4932
- ON DUPLICATE KEY UPDATE
4933
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4934
- ");
4935
-
4936
- $result = $this->db_do("DELETE cf
4937
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." cf
4938
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
4939
- ON cf.product_id=cpe.entity_id
4940
- WHERE cpe.entity_id is null");
4941
-
4942
- $result = $this->db_do("
4943
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." (
4944
- product_id,
4945
- store_id,
4946
- data_index
4947
- )(
4948
- SELECT
4949
- a.product_id,
4950
- a.store_id,
4951
- a.data_index
4952
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp a
4953
- WHERE product_id = a.product_id
4954
- )
4955
- ON DUPLICATE KEY UPDATE
4956
- data_index = a.data_index
4957
- ");
4958
-
4959
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_query')." SET is_processed = 0");
4960
- //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
4961
- //TODO add something else
4962
-
4963
- $this->addRelatedProducts();
4964
- }
4965
-
4966
- #################################################################################################
4967
- function addDescriptions(){
4968
- // product description for all web sites
4969
- $result = $this->db_do("
4970
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
4971
- entity_type_id,
4972
- attribute_id,
4973
- store_id,
4974
- entity_id,
4975
- value
4976
- )(
4977
- SELECT
4978
- " . $this->_getProductEntityTypeId(). ",
4979
- " . $this->_getProductAttributeId('description'). ",
4980
- w.website,
4981
- a.entity_id,
4982
- b.description
4983
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
4984
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
4985
- ON a.store_product_id = b.store_product_id
4986
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
4987
- ON a.store_product_id=w.store_product_id
4988
- )
4989
- ON DUPLICATE KEY UPDATE
4990
- value = b.description
4991
- ");
4992
-
4993
- // product description for all web sites
4994
- $result = $this->db_do("
4995
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
4996
- entity_type_id,
4997
- attribute_id,
4998
- store_id,
4999
- entity_id,
5000
- value
5001
- )(
5002
- SELECT
5003
- " . $this->_getProductEntityTypeId(). ",
5004
- " . $this->_getProductAttributeId('description'). ",
5005
- 0,
5006
- a.entity_id,
5007
- b.description
5008
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5009
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
5010
- ON a.store_product_id = b.store_product_id
5011
- )
5012
- ON DUPLICATE KEY UPDATE
5013
- value = b.description
5014
- ");
5015
-
5016
-
5017
- }
5018
-
5019
- #################################################################################################
5020
- function addShortDescriptions(){
5021
- // product short description for all web sites
5022
- $result = $this->db_do("
5023
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
5024
- entity_type_id,
5025
- attribute_id,
5026
- store_id,
5027
- entity_id,
5028
- value
5029
- )(
5030
- SELECT
5031
- " . $this->_getProductEntityTypeId(). ",
5032
- " . $this->_getProductAttributeId('short_description'). ",
5033
- w.website,
5034
- a.entity_id,
5035
- '&nbsp;'
5036
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5037
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
5038
- ON a.store_product_id = b.store_product_id
5039
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5040
- ON a.store_product_id=w.store_product_id
5041
- )
5042
- ON DUPLICATE KEY UPDATE
5043
- value = '&nbsp;'
5044
- ");
5045
- // product short description for all web sites
5046
- $result = $this->db_do("
5047
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
5048
- entity_type_id,
5049
- attribute_id,
5050
- store_id,
5051
- entity_id,
5052
- value
5053
- )(
5054
- SELECT
5055
- " . $this->_getProductEntityTypeId(). ",
5056
- " . $this->_getProductAttributeId('short_description'). ",
5057
- 0,
5058
- a.entity_id,
5059
- '&nbsp;'
5060
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5061
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
5062
- ON a.store_product_id = b.store_product_id
5063
- )
5064
- ON DUPLICATE KEY UPDATE
5065
- value = '&nbsp;'
5066
- ");
5067
-
5068
- }
5069
-
5070
- #################################################################################################
5071
- function addEAN(){
5072
- //gather EAN codes for each product
5073
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('EANs_temp'));
5074
- $this->db_do("
5075
- CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
5076
- sinch_product_id int(11),
5077
- store_product_id int(11),
5078
- EANs text,
5079
- KEY `sinch_product_id` (`sinch_product_id`),
5080
- KEY `store_product_id` (`store_product_id`)
5081
- )
5082
- ");
5083
- $this->db_do("
5084
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
5085
- sinch_product_id,
5086
- EANs
5087
- )(SELECT
5088
- sec.product_id,
5089
- GROUP_CONCAT(DISTINCT ean_code ORDER BY ean_code DESC SEPARATOR ', ') AS eans
5090
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
5091
- GROUP BY sec.product_id
5092
- )
5093
- ");
5094
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
5095
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
5096
- ON e.sinch_product_id=p.sinch_product_id
5097
- SET e.store_product_id=p.store_product_id");
5098
- // product EANs for all web sites
5099
- $result = $this->db_do("
5100
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
5101
- entity_type_id,
5102
- attribute_id,
5103
- store_id,
5104
- entity_id,
5105
- value
5106
- )(
5107
- SELECT
5108
- " . $this->_getProductEntityTypeId(). ",
5109
- " . $this->_getProductAttributeId('ean'). ",
5110
- w.website,
5111
- a.entity_id,
5112
- e.EANs
5113
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5114
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
5115
- ON a.store_product_id = e.store_product_id
5116
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5117
- ON a.store_product_id=w.store_product_id
5118
- )
5119
- ON DUPLICATE KEY UPDATE
5120
- value = e.EANs
5121
- ");
5122
-
5123
- // product EANs for all web sites
5124
- $result = $this->db_do("
5125
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
5126
- entity_type_id,
5127
- attribute_id,
5128
- store_id,
5129
- entity_id,
5130
- value
5131
- )(
5132
- SELECT
5133
- " . $this->_getProductEntityTypeId(). ",
5134
- " . $this->_getProductAttributeId('ean'). ",
5135
- 0,
5136
- a.entity_id,
5137
- e.EANs
5138
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5139
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
5140
- ON a.store_product_id = e.store_product_id
5141
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5142
- ON a.store_product_id=w.store_product_id
5143
- )
5144
- ON DUPLICATE KEY UPDATE
5145
- value = e.EANs
5146
- ");
5147
-
5148
- }
5149
-
5150
- ################################################################################################
5151
- function addSpecification(){
5152
- // product specification for all web sites
5153
- $result = $this->db_do("
5154
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
5155
- entity_type_id,
5156
- attribute_id,
5157
- store_id,
5158
- entity_id,
5159
- value
5160
- )(
5161
- SELECT
5162
- " . $this->_getProductEntityTypeId(). ",
5163
- " . $this->_getProductAttributeId('specification'). ",
5164
- w.website,
5165
- a.entity_id,
5166
- b.specifications
5167
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5168
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
5169
- ON a.store_product_id = b.store_product_id
5170
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5171
- ON a.store_product_id=w.store_product_id
5172
- )
5173
- ON DUPLICATE KEY UPDATE
5174
- value = b.specifications
5175
- ");
5176
- // product specification for all web sites
5177
- $result = $this->db_do("
5178
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
5179
- entity_type_id,
5180
- attribute_id,
5181
- store_id,
5182
- entity_id,
5183
- value
5184
- )(
5185
- SELECT
5186
- " . $this->_getProductEntityTypeId(). ",
5187
- " . $this->_getProductAttributeId('specification'). ",
5188
- 0,
5189
- a.entity_id,
5190
- b.specifications
5191
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5192
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
5193
- ON a.store_product_id = b.store_product_id
5194
- )
5195
- ON DUPLICATE KEY UPDATE
5196
- value = b.specifications
5197
- ");
5198
-
5199
-
5200
- }
5201
-
5202
- private function addManufacturer_attribute(){
5203
- $result = $this->db_do("
5204
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
5205
- entity_type_id,
5206
- attribute_id,
5207
- store_id,
5208
- entity_id,
5209
- value
5210
- )(
5211
- SELECT
5212
- " . $this->_getProductEntityTypeId(). ",
5213
- " . $this->_getProductAttributeId('manufacturer'). ",
5214
- 0,
5215
- a.entity_id,
5216
- pm.manufacturer_option_id
5217
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5218
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
5219
- ON a.entity_id = pm.entity_id
5220
- )
5221
- ON DUPLICATE KEY UPDATE
5222
- value = pm.manufacturer_option_id
5223
- ");
5224
-
5225
-
5226
- }
5227
-
5228
- #################################################################################################
5229
- function addManufacturers($delete_eav=null){
5230
- // this cleanup is not needed due to foreign keys
5231
- if(!$delete_eav){
5232
- $result = $this->db_do("
5233
- DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')."
5234
- WHERE attribute_id = ".$this->_getProductAttributeId('manufacturer')//." AND store_id = ".$websiteId
5235
- );
5236
- }
5237
- $this->addManufacturer_attribute();
5238
- // todo: doesn't seems to work properly, should be inserted per visibility
5239
- // done, test now
5240
-
5241
- $result = $this->db_do("
5242
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
5243
- entity_id,
5244
- attribute_id,
5245
- store_id,
5246
- value
5247
- )(
5248
- SELECT
5249
- a.entity_id,
5250
- " . $this->_getProductAttributeId('manufacturer'). ",
5251
- w.website,
5252
- mn.shop_option_id
5253
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5254
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
5255
- ON a.store_product_id = b.store_product_id
5256
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5257
- ON a.store_product_id=w.store_product_id
5258
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
5259
- ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
5260
- WHERE mn.shop_option_id IS NOT NULL
5261
- )
5262
- ON DUPLICATE KEY UPDATE
5263
- value = mn.shop_option_id
5264
- ");
5265
-
5266
- $result = $this->db_do("
5267
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
5268
- entity_id,
5269
- attribute_id,
5270
- store_id,
5271
- value
5272
- )(
5273
- SELECT
5274
- a.entity_id,
5275
- " . $this->_getProductAttributeId('manufacturer'). ",
5276
- 0,
5277
- mn.shop_option_id
5278
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5279
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
5280
- ON a.store_product_id = b.store_product_id
5281
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5282
- ON a.store_product_id=w.store_product_id
5283
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
5284
- ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
5285
- WHERE mn.shop_option_id IS NOT NULL
5286
- )
5287
- ON DUPLICATE KEY UPDATE
5288
- value = mn.shop_option_id
5289
- ");
5290
-
5291
-
5292
- }
5293
-
5294
- #################################################################################################
5295
- function addRelatedProducts(){
5296
-
5297
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
5298
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
5299
- ON rpt.sinch_product_id=p.sinch_product_id
5300
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5301
- ON p.store_product_id=cpe.store_product_id
5302
- SET rpt.store_product_id=p.store_product_id, rpt.entity_id=cpe.entity_id");
5303
-
5304
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
5305
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
5306
- ON rpt.related_sinch_product_id=p.sinch_product_id
5307
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5308
- ON p.store_product_id=cpe.store_product_id
5309
- SET rpt.store_related_product_id=p.store_product_id, rpt.related_entity_id=cpe.entity_id");
5310
-
5311
- $result = $this->db_do("SELECT
5312
- link_type_id,
5313
- code
5314
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_type')
5315
- );
5316
- $link_type=array();
5317
- while ($row = mysqli_fetch_array($result)) {
5318
- $link_type[$row['code']]=$row['link_type_id'];
5319
- }
5320
-
5321
- $result = $this->db_do("
5322
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." (
5323
- product_id,
5324
- linked_product_id,
5325
- link_type_id
5326
- )(
5327
- SELECT
5328
- entity_id,
5329
- related_entity_id,
5330
- ".$link_type['relation']."
5331
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')."
5332
- WHERE store_product_id IS NOT NULL
5333
- AND store_related_product_id IS NOT NULL
5334
- )
5335
- ON DUPLICATE KEY UPDATE
5336
- product_id = entity_id,
5337
- linked_product_id = related_entity_id
5338
- ");
5339
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp");
5340
-
5341
- $this->db_do("CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp (
5342
- `value_id` int(11) default NULL,
5343
- `product_link_attribute_id` smallint(6) unsigned default NULL,
5344
- `link_id` int(11) unsigned default NULL,
5345
- `value` int(11) NOT NULL default '0',
5346
- KEY `FK_INT_PRODUCT_LINK_ATTRIBUTE` (`product_link_attribute_id`),
5347
- KEY `FK_INT_PRODUCT_LINK` (`link_id`)
5348
- )
5349
- ");
5350
-
5351
- $result = $this->db_do("
5352
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp(
5353
- product_link_attribute_id,
5354
- link_id,
5355
- value
5356
- )(
5357
- SELECT
5358
- 2,
5359
- cpl.link_id,
5360
- 0
5361
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." cpl
5362
- )
5363
- ");
5364
-
5365
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
5366
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." c
5367
- ON ct.link_id=c.link_id
5368
- SET ct.value_id=c.value_id
5369
- WHERE c.product_link_attribute_id=2
5370
- ");
5371
-
5372
- $result = $this->db_do("
5373
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." (
5374
- value_id,
5375
- product_link_attribute_id,
5376
- link_id,
5377
- value
5378
- )(
5379
- SELECT
5380
- value_id,
5381
- product_link_attribute_id,
5382
- link_id,
5383
- value
5384
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
5385
- )
5386
- ON DUPLICATE KEY UPDATE
5387
- link_id=ct.link_id
5388
-
5389
- ");
5390
-
5391
- /* $q="select distinct store_product_id from stINch_related_products";
5392
- $quer=$this->db_do($q);
5393
- $prod = Mage::getModel('catalog/product');
5394
- while ($row = mysqli_fetch_assoc($quer)) {
5395
- $q1="select distinct store_related_product_id store_product_id from stINch_related_products where store_product_id=".$row['store_product_id'].;
5396
- $quer1=$this->db_do($q1);
5397
- $prod->load($row['store_product_id']);
5398
-
5399
- ###//get related product data (product id's and positions)
5400
- ###$relatedData = array();
5401
- ###foreach ($product->getRelatedLinkCollection() as $link) {
5402
- ### $relatedData[$link->getLinkedProductId()]['position'] = $link->getPosition();
5403
- ###}
5404
- ###//manipulate $relatedData array
5405
- ###// ...
5406
- ###//set and save related product data
5407
- ###$product->setRelatedLinkData($relatedData);
5408
- ###$product->save();
5409
- ###
5410
- $i=1;
5411
- while ($row1 = mysqli_fetch_assoc($quer1)) {
5412
- $param[$row1['store_related_product_id']]['position']=$i++;
5413
-
5414
- }
5415
- $prod->setRelatedLinkData($param);
5416
- //here ... some other product operations and in the end
5417
- $prod->save();
5418
-
5419
- }
5420
- */
5421
- }
5422
- #################################################################################################
5423
- function addWeight(){
5424
- // product short description for all web sites
5425
- $result = $this->db_do("
5426
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
5427
- entity_type_id,
5428
- attribute_id,
5429
- store_id,
5430
- entity_id,
5431
- value
5432
- )(
5433
- SELECT
5434
- " . $this->_getProductEntityTypeId(). ",
5435
- " . $this->_getProductAttributeId('weight'). ",
5436
- w.website,
5437
- a.entity_id,
5438
- 0
5439
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5440
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
5441
- ON a.store_product_id = b.store_product_id
5442
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5443
- ON a.store_product_id=w.store_product_id
5444
- )
5445
- ON DUPLICATE KEY UPDATE
5446
- value = 0
5447
- ");
5448
- // product short description for all web sites
5449
- $result = $this->db_do("
5450
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
5451
- entity_type_id,
5452
- attribute_id,
5453
- store_id,
5454
- entity_id,
5455
- value
5456
- )(
5457
- SELECT
5458
- " . $this->_getProductEntityTypeId(). ",
5459
- " . $this->_getProductAttributeId('weight'). ",
5460
- 0,
5461
- a.entity_id,
5462
- 0
5463
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5464
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
5465
- ON a.store_product_id = b.store_product_id
5466
- )
5467
- ON DUPLICATE KEY UPDATE
5468
- value = 0
5469
-
5470
-
5471
- ");
5472
-
5473
-
5474
- }
5475
- #################################################################################################
5476
- function replaceMagentoProductsStockPrice(){
5477
- //Add stock
5478
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
5479
- $result = $this->db_do("DELETE csi
5480
- FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
5481
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5482
- ON csi.product_id=cpe.entity_id
5483
- WHERE cpe.entity_id is null");
5484
- //set all sinch products stock=0 before upgrade (nedds for dayly stock&price import)
5485
-
5486
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5487
- JOIN ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
5488
- ON cpe.entity_id=csi.product_id
5489
- SET
5490
- csi.qty=0,
5491
- csi.is_in_stock=0
5492
- WHERE cpe.store_product_id IS NOT NULL");
5493
-
5494
- $result = $this->db_do("
5495
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." (
5496
- product_id,
5497
- stock_id,
5498
- qty,
5499
- is_in_stock,
5500
- manage_stock
5501
- )(
5502
- SELECT
5503
- a.entity_id,
5504
- 1,
5505
- b.stock,
5506
- IF(b.stock > 0, 1, 0),
5507
- 1
5508
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5509
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5510
- ON a.store_product_id=b.store_product_id
5511
- )
5512
- ON DUPLICATE KEY UPDATE
5513
- qty=b.stock,
5514
- is_in_stock = IF(b.stock > 0, 1, 0),
5515
- manage_stock = 1
5516
- ");
5517
-
5518
-
5519
- $result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status'));
5520
-
5521
- $result = $this->db_do("
5522
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status')." (
5523
- product_id,
5524
- website_id,
5525
- stock_id,
5526
- qty,
5527
- stock_status
5528
- )(
5529
- SELECT
5530
- a.product_id,
5531
- w.website_id,
5532
- 1,
5533
- a.qty,
5534
- IF(qty > 0, 1, 0)
5535
- FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." a
5536
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." b
5537
- ON a.product_id=b.entity_id
5538
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5539
- ON b.store_product_id=w.store_product_id
5540
- )
5541
- ON DUPLICATE KEY UPDATE
5542
- qty=a.qty,
5543
- stock_status = IF(a.qty > 0, 1, 0)
5544
- ");
5545
-
5546
- //Add prices
5547
- //$result = $this->db_do("truncate catalog_product_entity_decimal");
5548
- $result = $this->db_do("DELETE cped
5549
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." cped
5550
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5551
- ON cped.entity_id=cpe.entity_id
5552
- WHERE cpe.entity_id IS NULL");
5553
-
5554
- $result = $this->db_do("
5555
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
5556
- entity_type_id,
5557
- attribute_id,
5558
- store_id,
5559
- entity_id,
5560
- value
5561
- )(
5562
- SELECT
5563
- " . $this->_getProductEntityTypeId(). ",
5564
- " . $this->_getProductAttributeId('price'). ",
5565
- w.website,
5566
- a.entity_id,
5567
- b.price
5568
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5569
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5570
- ON a.store_product_id=b.store_product_id
5571
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5572
- ON a.store_product_id=w.store_product_id
5573
- )
5574
- ON DUPLICATE KEY UPDATE
5575
- value = b.price
5576
- ");
5577
-
5578
- $result = $this->db_do("
5579
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
5580
- entity_type_id,
5581
- attribute_id,
5582
- store_id,
5583
- entity_id,
5584
- value
5585
- )(
5586
- SELECT
5587
- " . $this->_getProductEntityTypeId(). ",
5588
- " . $this->_getProductAttributeId('price'). ",
5589
- 0,
5590
- a.entity_id,
5591
- b.price
5592
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5593
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5594
- ON a.store_product_id=b.store_product_id
5595
- )
5596
- ON DUPLICATE KEY UPDATE
5597
- value = b.price
5598
- ");
5599
- //Add cost
5600
- // $result = $this->db_do("truncate catalog_product_entity_decimal");
5601
- $result = $this->db_do("
5602
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
5603
- entity_type_id,
5604
- attribute_id,
5605
- store_id,
5606
- entity_id,
5607
- value
5608
- )(
5609
- SELECT
5610
- " . $this->_getProductEntityTypeId(). ",
5611
- " . $this->_getProductAttributeId('cost'). ",
5612
- w.website,
5613
- a.entity_id,
5614
- b.cost
5615
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5616
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5617
- ON a.store_product_id=b.store_product_id
5618
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5619
- ON a.store_product_id=w.store_product_id
5620
- )
5621
- ON DUPLICATE KEY UPDATE
5622
- value = b.cost
5623
- ");
5624
-
5625
- $result = $this->db_do("
5626
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
5627
- entity_type_id,
5628
- attribute_id,
5629
- store_id,
5630
- entity_id,
5631
- value
5632
- )(
5633
- SELECT
5634
- " . $this->_getProductEntityTypeId(). ",
5635
- " . $this->_getProductAttributeId('cost'). ",
5636
- 0,
5637
- a.entity_id,
5638
- b.cost
5639
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5640
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5641
- ON a.store_product_id=b.store_product_id
5642
- )
5643
- ON DUPLICATE KEY UPDATE
5644
- value = b.cost
5645
- ");
5646
-
5647
- //make products enable in FO
5648
- // $result = $this->db_do(" truncate catalog_product_index_price");
5649
- $result = $this->db_do("DELETE cpip
5650
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." cpip
5651
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5652
- ON cpip.entity_id=cpe.entity_id
5653
- WHERE cpe.entity_id IS NULL");
5654
-
5655
- $q="SELECT customer_group_id FROM ".Mage::getSingleton('core/resource')->getTableName('customer_group');
5656
- $quer=$this->db_do($q);
5657
-
5658
- while ($row = mysqli_fetch_assoc($quer)) {
5659
- $result = $this->db_do("
5660
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." (
5661
- entity_id,
5662
- customer_group_id,
5663
- website_id,
5664
- tax_class_id,
5665
- price,
5666
- final_price,
5667
- min_price,
5668
- max_price
5669
- )(SELECT
5670
- a.entity_id,
5671
- ".$row['customer_group_id'].",
5672
- w.website_id,
5673
- 2,
5674
- b.price ,
5675
- b.price ,
5676
- b.price ,
5677
- b.price
5678
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5679
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5680
- ON a.store_product_id=b.store_product_id
5681
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5682
- ON a.store_product_id=w.store_product_id
5683
- )
5684
- ON DUPLICATE KEY UPDATE
5685
- tax_class_id = 2,
5686
- price = b.price,
5687
- final_price = b.price,
5688
- min_price = b.price,
5689
- max_price = b.price
5690
- ");
5691
- }
5692
- }
5693
-
5694
-
5695
-
5696
- #################################################################################################
5697
-
5698
- function getProductDescription($entity_id){
5699
-
5700
- $this->loadProductParams($entity_id);
5701
- $this->loadProductStarfeatures($entity_id);
5702
- $this->loadGalleryPhotos($entity_id);
5703
- Varien_Profiler::start('Bintime FILE RELATED');
5704
- $this->loadRelatedProducts($entity_id);
5705
- Varien_Profiler::stop('Bintime FILE RELATED');
5706
-
5707
- return true;
5708
- }
5709
- #################################################################################################
5710
-
5711
- public function getProductName(){
5712
- return $this->productName;
5713
- }
5714
- #################################################################################################
5715
-
5716
- public function getProductDescriptionList(){
5717
- return $this->productDescriptionList;
5718
- }
5719
- #################################################################################################
5720
-
5721
- public function getProductSpecifications(){
5722
- return $this->specifications;
5723
- }
5724
- #################################################################################################
5725
-
5726
- public function getShortProductDescription(){
5727
- return $this->productDescription;
5728
- }
5729
- #################################################################################################
5730
-
5731
- public function getFullProductDescription(){
5732
- return $this->fullProductDescription;
5733
- }
5734
- #################################################################################################
5735
-
5736
- public function getLowPicUrl(){
5737
- return $this->highPicUrl;
5738
- }
5739
- #################################################################################################
5740
-
5741
- public function getRelatedProducts(){
5742
- return $this->relatedProducts;
5743
- }
5744
- #################################################################################################
5745
-
5746
- public function getVendor(){
5747
- return $this->vendor;
5748
- }
5749
- #################################################################################################
5750
-
5751
- public function getMPN(){
5752
- return $this->productId;
5753
- }
5754
- #################################################################################################
5755
-
5756
- public function getEAN(){
5757
- return $this->EAN;
5758
- }
5759
- ################################################################################################
5760
-
5761
- public function getGalleryPhotos(){
5762
- return $this->galleryPhotos;
5763
- }
5764
-
5765
- #################################################################################################
5766
-
5767
- private function loadProductParams($entity_id){
5768
- $store_product_id=$this->getStoreProductIdByEntity($entity_id);
5769
- if(!$store_product_id){
5770
- // echo "AAAAAAA"; exit;
5771
- return;
5772
- }
5773
- $q="SELECT
5774
- sinch_product_id,
5775
- product_sku,
5776
- product_name,
5777
- sinch_manufacturer_id,
5778
- store_category_id,
5779
- main_image_url,
5780
- thumb_image_url,
5781
- medium_image_url,
5782
- specifications,
5783
- description,
5784
- specifications
5785
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products')."
5786
- WHERE store_product_id =".$store_product_id;
5787
- $quer=$this->db_do($q);
5788
- $product=mysqli_fetch_array($quer);
5789
-
5790
- $this->productDescription = (string) substr($product['description'],50,0);
5791
- $this->fullProductDescription = (string)$product['description'];
5792
- $this->lowPicUrl = (string)$product["medium_image_url"];//thumb_image_url"];
5793
- $this->highPicUrl = (string)$product["main_image_url"];
5794
- $this->productName = (string)$product["product_name"];
5795
- $this->productId = (string)$product['product_sku'];
5796
- $this->specifications = (string)$product['specifications'];
5797
- $this->sinchProductId = (string)$product['sinch_product_id'];
5798
- if($product['sinch_manufacturer_id']){
5799
- $q="SELECT manufacturer_name
5800
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')."
5801
- WHERE sinch_manufacturer_id=".$product['sinch_manufacturer_id'];
5802
- $quer=$this->db_do($q);
5803
- $manufacturer=mysqli_fetch_array($quer);
5804
- $this->vendor = (string)$manufacturer['manufacturer_name'];
5805
- }
5806
- $q="SELECT DISTINCT ean_code
5807
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
5808
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
5809
- ON sec.product_id=sp.sinch_product_id
5810
- WHERE sp.store_product_id=".$store_product_id;
5811
- $quer=$this->db_do($q);
5812
- while ($row=mysqli_fetch_array($quer)){
5813
- $EANarr[]=$row['ean_code'];
5814
- }
5815
- // $prodEAN = $productTag->EANCode;
5816
- $EANstr='';
5817
- /* $EANarr=null;
5818
- foreach($prodEAN as $ellEAN){
5819
- $EANarr[]=$ellEAN['EAN'];
5820
- }
5821
- */
5822
- $EANstr=implode(", ",$EANarr);
5823
- $this->EAN = (string)$EANstr;//$productTag->EANCode['EAN'];
5824
- }
5825
- #################################################################################################
5826
-
5827
- private function loadProductStarfeatures($entity_id){
5828
- $descriptionArray=array();
5829
- $product_info_features = $this->db_do("
5830
- SELECT c.feature_name AS name, b.text AS value
5831
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." a
5832
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." b
5833
- ON a.restricted_value_id = b.restricted_value_id
5834
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features')." c
5835
- ON b.category_feature_id = c.category_feature_id
5836
- WHERE a.sinch_product_id = '" .$this->sinchProductId . "'" );
5837
- while ($features = mysqli_fetch_array($product_info_features)) {
5838
- $descriptionArray[$features['name']] = $features['value'];
5839
- }
5840
-
5841
-
5842
- $this->productDescriptionList = $descriptionArray;
5843
- }
5844
- #################################################################################################
5845
-
5846
- private function loadRelatedProducts($entity_id){
5847
- $this->sinchProductId;
5848
- if(!$this->sinchProductId){
5849
- return;
5850
- }
5851
- $q="SELECT
5852
- st_prod.sinch_product_id,
5853
- st_prod.product_sku,
5854
- st_prod.product_name,
5855
- st_prod.sinch_manufacturer_id,
5856
- st_prod.store_category_id,
5857
- st_prod.main_image_url,
5858
- st_prod.thumb_image_url,
5859
- st_prod.medium_image_url,
5860
- st_prod.specifications,
5861
- st_prod.description,
5862
- st_prod.specifications,
5863
- st_manuf.manufacturer_name,
5864
- st_manuf.manufacturers_image
5865
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." st_rel_prod
5866
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." st_prod
5867
- ON st_rel_prod.related_sinch_product_id=st_prod.sinch_product_id
5868
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." st_manuf
5869
- ON st_prod.sinch_manufacturer_id=st_manuf.sinch_manufacturer_id
5870
- WHERE st_rel_prod.sinch_product_id=".$this->sinchProductId;
5871
-
5872
- // echo $q;
5873
- $quer=$this->db_do($q);
5874
- while($row=mysqli_fetch_array($quer)){
5875
-
5876
- $productArray = array();
5877
- $productArray['name'] = (string)$row['product_name'];
5878
- $productArray['thumb'] = (string)$row['thumb_image_url'];
5879
- $mpn = (string)$row['product_sku'];
5880
- $productSupplierId = (int)$row['sinch_manufacturer_id'];
5881
- $productArray['supplier_thumb'] = (string)($row['manufacturers_image']);
5882
- $productArray['supplier_name'] = (string)$row['manufacturer_name'];
5883
-
5884
- $this->relatedProducts[$mpn] = $productArray;
5885
- }
5886
- }
5887
- #################################################################################################
5888
- /**
5889
- * load Gallery array from XML
5890
- */
5891
- public function loadGalleryPhotos($entity_id){
5892
- /*$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
5893
- if (!count($galleryPhotos)){
5894
- return false;
5895
- }
5896
- */
5897
- $store_product_id=$this->getStoreProductIdByEntity($entity_id);
5898
- if(!$store_product_id){
5899
- return;
5900
- }
5901
- $q=$this->db_do("SELECT COUNT(*) AS cnt
5902
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
5903
- WHERE store_product_id=".$store_product_id);
5904
-
5905
- $res=mysqli_fetch_array($q);
5906
- if(!$res || !$res['cnt']){
5907
- return false;
5908
- }
5909
- $q="SELECT
5910
- image_url as Pic,
5911
- thumb_image_url as ThumbPic
5912
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
5913
- WHERE store_product_id=".$store_product_id;
5914
-
5915
- $res=$this->db_do($q);
5916
-
5917
- while($photo=mysqli_fetch_array($res)){
5918
- $picHeight = (int)500;//$photo["PicHeight"];
5919
- $picWidth = (int)500;//$photo["PicWidth"];
5920
- $thumbUrl = (string)$photo["ThumbPic"];
5921
- $picUrl = (string)$photo["Pic"];
5922
-
5923
- array_push($this->galleryPhotos, array(
5924
- 'height' => $picHeight,
5925
- 'width' => $picWidth,
5926
- 'thumb' => $thumbUrl,
5927
- 'pic' => $picUrl
5928
- ));
5929
- }
5930
- }
5931
- #################################################################################################
5932
- public function reloadProductImage($entity_id){
5933
- $result = $this->db_do("
5934
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
5935
- entity_type_id,
5936
- attribute_id,
5937
- store_id,
5938
- entity_id,
5939
- value
5940
- )(
5941
- SELECT
5942
- " . $this->_getProductEntityTypeId(). ",
5943
- " . $this->_getProductAttributeId('image'). ",
5944
- w.store_id,
5945
- a.entity_id,
5946
- b.main_image_url
5947
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5948
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
5949
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
5950
- ON a.store_product_id = b.store_product_id
5951
- WHERE a.entity_id=$entity_id
5952
- )
5953
- ON DUPLICATE KEY UPDATE
5954
- value = b.main_image_url
5955
- ");
5956
-
5957
-
5958
- // image for specific web sites
5959
- $result = $this->db_do("
5960
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
5961
- entity_type_id,
5962
- attribute_id,
5963
- store_id,
5964
- entity_id,
5965
- value
5966
- )(
5967
- SELECT
5968
- " . $this->_getProductEntityTypeId(). ",
5969
- " . $this->_getProductAttributeId('image'). ",
5970
- 0,
5971
- a.entity_id,
5972
- b.main_image_url
5973
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5974
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
5975
- ON a.store_product_id = b.store_product_id
5976
- WHERE a.entity_id=$entity_id
5977
- )
5978
- ON DUPLICATE KEY UPDATE
5979
- value = b.main_image_url
5980
- ");
5981
-
5982
-
5983
- // small_image for specific web sites
5984
- $result = $this->db_do("
5985
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
5986
- entity_type_id,
5987
- attribute_id,
5988
- store_id,
5989
- entity_id,
5990
- value
5991
- )(
5992
- SELECT
5993
- " . $this->_getProductEntityTypeId(). ",
5994
- " . $this->_getProductAttributeId('small_image'). ",
5995
- w.store_id,
5996
- a.entity_id,
5997
- b.main_image_url
5998
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5999
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6000
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
6001
- ON a.store_product_id = b.store_product_id
6002
- WHERE a.entity_id=$entity_id
6003
- )
6004
- ON DUPLICATE KEY UPDATE
6005
- value = b.main_image_url
6006
- ");
6007
-
6008
-
6009
- // small_image for all web sites
6010
- $result = $this->db_do("
6011
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6012
- entity_type_id,
6013
- attribute_id,
6014
- store_id,
6015
- entity_id,
6016
- value
6017
- )(
6018
- SELECT
6019
- " . $this->_getProductEntityTypeId(). ",
6020
- " . $this->_getProductAttributeId('small_image'). ",
6021
- 0,
6022
- a.entity_id,
6023
- b.main_image_url
6024
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6025
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6026
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
6027
- ON a.store_product_id = b.store_product_id
6028
- WHERE a.entity_id=$entity_id
6029
- )
6030
- ON DUPLICATE KEY UPDATE
6031
- value = b.main_image_url
6032
- ");
6033
- }
6034
- #################################################################################################
6035
- public function runIndexer(){
6036
- exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php reindexall');
6037
- }
6038
- #################################################################################################
6039
- public function runStockPriceIndexer(){
6040
- exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php --reindex catalog_product_price,cataloginventory_stock');
6041
- }
6042
- #################################################################################################
6043
- private function getStoreProductIdByEntity($entity_id){
6044
- $q=$this->db_do("SELECT store_product_id
6045
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
6046
- WHERE entity_id=".$entity_id);
6047
- $res=mysqli_fetch_array($q);
6048
- // echo $entity_id."AAAA".$res['store_product_id']; exit;
6049
- return ($res['store_product_id']);
6050
- }
6051
- #################################################################################################
6052
-
6053
- private function db_connect() {
6054
-
6055
- // $connection = Mage::getModel('core/resource')->getConnection('core_write');
6056
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
6057
-
6058
- if ($this->db = mysqli_connect($dbConf->host, $dbConf->username, $dbConf->password)) {
6059
- mysqli_options($this->db, MYSQLI_OPT_LOCAL_INFILE, true);
6060
- if(mysqli_select_db($this->db, $dbConf->dbname)){
6061
- $this->_LOG("Connected..");
6062
- }else{
6063
- die("Can't select the database: " . mysqli_error($this->db));
6064
- }
6065
- }else{
6066
- die("Could not connect: " . mysqli_error($this->db));
6067
-
6068
- }
6069
-
6070
- }
6071
- #################################################################################################
6072
-
6073
- private function db_do($query) {
6074
- if($this->debug_mode){
6075
- // $this->_LOG("Query: " . $query);
6076
- Mage::log("Query: " . $query, null, $this->_logFile);
6077
- }
6078
- // $result = $this->this->db_do($query);//
6079
- // $query=mysqli_real_escape_string($query);
6080
- //mysqli_query('set names utf8');
6081
- $result = mysqli_query($this->db, $query) or die("Query failed: " . mysqli_error($this->db));
6082
- if (!$result) {
6083
- throw new Exception("Invalid query: $sql\n" . mysqli_error($this->db));
6084
- } else {
6085
- return $result;
6086
- }
6087
-
6088
- return $result;
6089
- }
6090
- ##################################################################################################
6091
- function table_rows_count($table){
6092
- $rows_count_res=$this->db_do("select count(*) as cnt from ".$table);
6093
- $rows_count=mysqli_fetch_array($rows_count_res);
6094
- return ($rows_count['cnt']);
6095
- }
6096
- ##################################################################################################
6097
- function file_strings_count($parse_file){
6098
- $files_str=count(file($parse_file));
6099
- return $files_str;
6100
- }
6101
- ##################################################################################################
6102
- function check_loaded_data($file, $table){
6103
- $cnt_strings_in_file=$this->file_strings_count($file);
6104
- $cnt_rows_int_table=$this->table_rows_count($table);
6105
- $persent_cnt_strings_in_file=$cnt_strings_in_file / 10;
6106
- if($cnt_rows_int_table > $persent_cnt_strings_in_file){
6107
- return true;
6108
- }else{
6109
- return false;
6110
- }
6111
- }
6112
- ##################################################################################################
6113
-
6114
-
6115
- function valid_utf($string,$new_line = true){
6116
- /* if($new_line == true){
6117
- $string = preg_replace('/\\\n/',"\n",$string);
6118
- }
6119
- */
6120
- $string = preg_replace('/™/','&#8482;',$string);
6121
- $string = preg_replace("/®/",'&reg;',$string);
6122
- $string = preg_replace("/≈/",'&asymp;',$string);
6123
- $string = preg_replace("/".chr(226).chr(128).chr(157)."/",'&quot;',$string);
6124
- $string = preg_replace("/".chr(226).chr(128).chr(153)."/",'&prime;',$string);
6125
- $string = preg_replace("/°/",'&deg;',$string);
6126
- $string = preg_replace("/±/",'&plusmn;',$string);
6127
- $string = preg_replace("/µ/",'&micro;',$string);
6128
- $string = preg_replace("/²/",'&sup2;',$string);
6129
- $string = preg_replace("/³/",'&sup3;',$string);
6130
- $string = preg_replace('/\xe2\x80\x93/','-',$string);
6131
- $string = preg_replace('/\xe2\x80\x99/','\'',$string);
6132
- $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
6133
- $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
6134
-
6135
- return utf8_decode($string);
6136
-
6137
- // return $string;
6138
- }
6139
-
6140
- #################################################################################################
6141
- function dropHTMLentities($entity_type_id, $attribute_id){
6142
- // product name for all web sites
6143
- $result = $this->db_do("
6144
- SELECT value, entity_id
6145
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
6146
- WHERE entity_type_id=".$entity_type_id."
6147
- AND attribute_id=".$attribute_id
6148
- );
6149
- while($row=mysqli_fetch_array($result)){
6150
- $value=$this->valid_char($row['value']);
6151
- if($value!='' and $value!=$row['value']){
6152
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
6153
- SET value='".mysqli_real_escape_string($value)."'
6154
- WHERE entity_id=".$row['entity_id']."
6155
- AND entity_type_id=".$entity_type_id."
6156
- AND attribute_id=".$attribute_id);
6157
- }
6158
-
6159
- }
6160
- }
6161
-
6162
- #################################################################################################
6163
-
6164
- function valid_char($string){
6165
- $string = preg_replace('/&#8482;/', ' ',$string);
6166
- $string = preg_replace('/&reg;/', ' ',$string);
6167
- $string = preg_replace('/&asymp;/', ' ',$string);
6168
- $string = preg_replace('/&quot;/', ' ',$string);
6169
- $string = preg_replace('/&prime;/', ' ',$string);
6170
- $string = preg_replace('/&deg;/', ' ',$string);
6171
- $string = preg_replace('/&plusmn;/', ' ',$string);
6172
- $string = preg_replace('/&micro;/', ' ',$string);
6173
- $string = preg_replace('/&sup2;/', ' ',$string);
6174
- $string = preg_replace('/&sup3;/', ' ',$string);
6175
- // $string = preg_replace('/\xe2\x80\x93/','-',$string);
6176
- // $string = preg_replace('/\xe2\x80\x99/','\'',$string);
6177
- // $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
6178
- // $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
6179
-
6180
- // return utf8_decode($string);
6181
-
6182
- return $string;
6183
- }
6184
-
6185
- #################################################################################################
6186
-
6187
- function _LOG($log){
6188
-
6189
- if($log){
6190
- // $q="insert into ".$this->import_log_table." (message_date, message) values(now(), '".$log."')";
6191
- // $this->db_do($q);
6192
- Mage::log($log, null, $this->_logFile);
6193
- // list($usec, $sec) = explode(" ", microtime());
6194
- // $time = ((float)$usec + (float)$sec);
6195
- /* $time = date("D M j G:i:s T Y");
6196
-
6197
- if($_SERVER['REMOTE_ADDR']){
6198
- $log = "[".getmypid()."] "."[".$_SERVER['REMOTE_ADDR']."] "."[".$time."] ".$log."\n";
6199
- error_log($log,3,LOG_FILE);
6200
- }else{
6201
- $log = "[".getmypid()."] "."[".$time."] ".$log."\n";
6202
- error_log($log,3,LOG_FILE . ".cli");
6203
- */
6204
- }
6205
- }
6206
-
6207
- #################################################################################################
6208
-
6209
- function wget(){
6210
-
6211
- $got = func_num_args();
6212
- $url = $file = $flag = false;
6213
-
6214
- if($got<1){
6215
- return false;
6216
- }elseif($got == 1){
6217
- $url = func_get_arg(0);
6218
- }elseif($got == 2){
6219
- $url = func_get_arg(0);
6220
- $file= func_get_arg(1);
6221
- }elseif($got == 3){
6222
- $url = func_get_arg(0);
6223
- $file= func_get_arg(1);
6224
- $flag= func_get_arg(2);
6225
- }
6226
-
6227
- if($flag == 'copy'){
6228
- if(copy($url,$file)){
6229
- return true;
6230
- }else{
6231
- return false;
6232
- }
6233
- }elseif($flag == 'system'){
6234
- exec("wget -O$file $url");
6235
- return true;
6236
- }else{
6237
- $c=curl_init($url);
6238
- curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
6239
- curl_setopt($c,CURLOPT_FOLLOWLOCATION,1);
6240
- curl_setopt($c,CURLOPT_HEADER,array("Accept-Encoding: gzip"));
6241
- if(!$file){
6242
- $page = curl_exec($c);
6243
- curl_close($c);
6244
- return $page;
6245
- }else{
6246
- $FH = fopen($file,"wb");// or echo"Can't open for writing ".$file;
6247
- fwrite($FH,curl_exec($c));
6248
- fclose($FH);
6249
- curl_close($c);
6250
- return true;
6251
- }
6252
- }
6253
- }
6254
- #################################################################################################
6255
- /**
6256
- * Create the import directory Hierarchy
6257
- * @return false if directory already exists
6258
- */
6259
- public function createTemporaryImportDerictory(){
6260
- $dirArray = explode('/', $this->varDir);
6261
- end($dirArray);
6262
- // $this->_LOG('before :'.$this->varDir);
6263
- if (prev($dirArray)=='bintime'){
6264
- return false;
6265
- }
6266
-
6267
-
6268
- $this->varDir = $this->varDir . 'bintime/sinchimport/';
6269
- if (!is_dir($this->varDir)) {
6270
- mkdir($this->varDir,0777,true);
6271
- }
6272
- // $this->_LOG('after :'.$this->varDir);
6273
- }
6274
- #################################################################################################
6275
-
6276
- function count_children($id){
6277
-
6278
- $q="SELECT store_category_id
6279
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
6280
- WHERE parent_store_category_id=".$id;
6281
- $quer=$this->db_do($q);
6282
- $count=0;
6283
- while ($row=mysqli_fetch_array($quer)){
6284
- $count+=$this->count_children($row['store_category_id']);
6285
- $count++;
6286
- }
6287
- return ($count);
6288
- }
6289
- #################################################################################################
6290
- private function delete_old_sinch_categories_from_shop(){
6291
-
6292
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." cat
6293
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6294
- ON cat.entity_id=scm.shop_entity_id
6295
- WHERE
6296
- (scm.shop_store_category_id is not null) AND
6297
- (scm.store_category_id is null)";
6298
- $this->db_do($q);
6299
-
6300
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." cat
6301
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6302
- ON cat.entity_id=scm.shop_entity_id
6303
- WHERE
6304
- (scm.shop_store_category_id is not null) AND
6305
- (scm.store_category_id is null)";
6306
- $this->db_do($q);
6307
-
6308
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cat
6309
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6310
- ON cat.entity_id=scm.shop_entity_id
6311
- WHERE
6312
- (scm.shop_store_category_id is not null) AND
6313
- (scm.store_category_id is null)";
6314
- $this->db_do($q);
6315
-
6316
- }
6317
- #################################################################################################
6318
-
6319
- function culc_path($parent_id, $ent_id){
6320
-
6321
- echo("\nparent_id = [$parent_id] ent_id = [$ent_id]\n");
6322
-
6323
- $path='';
6324
- $cat_id=$parent_id;
6325
- $q="SELECT
6326
- parent_id
6327
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
6328
- WHERE entity_id=".$cat_id;
6329
- $quer=$this->db_do($q);
6330
- $row=mysqli_fetch_array($quer);
6331
- while($row['parent_id']){
6332
- $path=$row['parent_id'].'/'.$path;
6333
- $q="SELECT
6334
- parent_id
6335
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
6336
- WHERE entity_id=".$row['parent_id'];
6337
- $quer=$this->db_do($q);
6338
- $row=mysqli_fetch_array($quer);
6339
-
6340
- }
6341
- if($cat_id){
6342
- $path.=$cat_id."/";
6343
- }
6344
-
6345
- if($path){
6346
- return($path.$ent_id);
6347
- }else{
6348
- return($ent_id);
6349
- }
6350
-
6351
- }
6352
- #################################################################################################
6353
-
6354
- function get_category_level($id){
6355
- $q="SELECT parent_store_category_id
6356
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
6357
- WHERE store_category_id=".$id;
6358
- $quer=$this->db_do($q);
6359
- $level=1;
6360
- $row=mysqli_fetch_array($quer);
6361
- while ($row['parent_store_category_id']!=0){
6362
- $q="SELECT parent_store_category_id
6363
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
6364
- WHERE store_category_id=".$row['parent_store_category_id'];
6365
- $quer=$this->db_do($q);
6366
- $row=mysqli_fetch_array($quer);
6367
- $level++;
6368
- if($level>20){
6369
- break;
6370
- }
6371
- }
6372
-
6373
- return($level);
6374
- }
6375
- #################################################################################################
6376
-
6377
- function InitImportStatuses($type){
6378
- $this->db_do("DROP TABLE IF EXISTS ".$this->import_status_table);
6379
- $this->db_do("CREATE TABLE ".$this->import_status_table."(
6380
- id int(11) NOT NULL auto_increment PRIMARY KEY,
6381
- message varchar(50),
6382
- finished int(1) default 0
6383
- )"
6384
- );
6385
- $this->db_do("INSERT INTO ".$this->import_status_statistic_table." (
6386
- start_import,
6387
- finish_import,
6388
- import_type,
6389
- global_status_import,
6390
- import_run_type,
6391
- error_report_message)
6392
- VALUES(
6393
- now(),
6394
- NULL,
6395
- '$type',
6396
- 'Run',
6397
- '".$this->import_run_type."',
6398
- ''
6399
- )
6400
- ");
6401
- $q="SELECT MAX(id) AS id FROM ".$this->import_status_statistic_table;
6402
-
6403
- $quer=$this->db_do($q);
6404
- $row=mysqli_fetch_array($quer);
6405
- $this->current_import_status_statistic_id=$row['id'];
6406
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
6407
- SET global_status_import='Failed'
6408
- WHERE global_status_import='Run' AND id!=".$this->current_import_status_statistic_id);
6409
-
6410
- }
6411
- #################################################################################################
6412
- function set_imports_failed(){
6413
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
6414
- SET global_status_import='Failed'
6415
- WHERE global_status_import='Run'");
6416
- }
6417
- #################################################################################################
6418
- function set_import_error_reporting_message($message){
6419
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
6420
- SET error_report_message='".mysqli_real_escape_string($message)."'
6421
- WHERE id=".$this->current_import_status_statistic_id);
6422
- }
6423
- #################################################################################################
6424
- function getImportStatusHistory(){
6425
- $res="SELECT COUNT(*) FROM ".$this->import_status_statistic_table;
6426
- $cnt_arr=mysqli_fetch_array($this->db_do($res));
6427
- $cnt=$cnt_arr[0];
6428
- $StatusHistory_arr = array();
6429
- if($cnt>0){
6430
- $a=(($cnt>7)? ($cnt-7): 0);
6431
- $b=$cnt;
6432
- $q="SELECT
6433
- id,
6434
- start_import,
6435
- finish_import,
6436
- import_type,
6437
- number_of_products,
6438
- global_status_import,
6439
- detail_status_import
6440
- FROM ".$this->import_status_statistic_table."
6441
- ORDER BY start_import limit ".$a.", ".$b;
6442
- $result=$this->db_do($q);
6443
- while($row=mysqli_fetch_array($result)){
6444
- $StatusHistory_arr[]=$row;
6445
- }
6446
- }
6447
- return $StatusHistory_arr;
6448
- }
6449
- #################################################################################################
6450
- function getDateOfLatestSuccessImport(){
6451
- $q="SELECT start_import, finish_import
6452
- FROM ".$this->import_status_statistic_table."
6453
- WHERE global_status_import='Successful'
6454
- ORDER BY id DESC LIMIT 1";
6455
- $imp_date=mysqli_fetch_array($this->db_do($q));
6456
- return $imp_date['start_import'];
6457
- }
6458
- #################################################################################################
6459
- function getDataOfLatestImport(){
6460
- $q="SELECT
6461
- start_import,
6462
- finish_import,
6463
- import_type,
6464
- number_of_products,
6465
- global_status_import,
6466
- detail_status_import,
6467
- number_of_products,
6468
- error_report_message
6469
- FROM ".$this->import_status_statistic_table."
6470
- ORDER BY id DESC LIMIT 1";
6471
- $imp_status=mysqli_fetch_array($this->db_do($q));
6472
- return $imp_status;
6473
- }
6474
-
6475
- #################################################################################################
6476
- function addImportStatus($message, $finished=0){
6477
- $q="INSERT INTO ".$this->import_status_table."
6478
- (message, finished)
6479
- VALUES('".$message."', $finished)";
6480
- $this->db_do($q);
6481
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
6482
- SET detail_status_import='".$message."'
6483
- WHERE id=".$this->current_import_status_statistic_id);
6484
- if($finished==1){
6485
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
6486
- SET
6487
- global_status_import='Successful',
6488
- finish_import=now()
6489
- WHERE
6490
- error_report_message='' and
6491
- id=".$this->current_import_status_statistic_id);
6492
- }
6493
- }
6494
- #################################################################################################
6495
-
6496
- function getImportStatuses(){
6497
- $q="SELECT id, message, finished
6498
- FROM ".$this->import_status_table."
6499
- ORDER BY id LIMIT 1";
6500
- $quer=$this->db_do($q);
6501
- if($row=mysqli_fetch_array($quer)){
6502
- $messages=array('message'=>$row['message'], 'id'=>$row['id'], 'finished'=>$row['finished']);
6503
- $id=$row['id'];
6504
- }
6505
- if($id){
6506
- $q="DELETE FROM ".$this->import_status_table." WHERE id=".$id;
6507
- $this->db_do($q);
6508
- }
6509
- return $messages;
6510
- }
6511
- #################################################################################################
6512
-
6513
- private function _getEntityTypeId($code) {
6514
- $sql = "
6515
- SELECT entity_type_id
6516
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
6517
- WHERE entity_type_code = '".$code."'
6518
- LIMIT 1
6519
- ";
6520
- $result = $this->db_do($sql);
6521
- if ($row = mysqli_fetch_assoc($result)) {
6522
- return $row['entity_type_id'];
6523
- }
6524
- return false;
6525
- }
6526
- #################################################################################################
6527
-
6528
- private function _getProductEntityTypeId(){
6529
- if (!$this->_productEntityTypeId) {
6530
- $this->_productEntityTypeId = $this->_getEntityTypeId('catalog_product');
6531
- }
6532
- return $this->_productEntityTypeId;
6533
- }
6534
- #################################################################################
6535
-
6536
- private function _getProductDefaulAttributeSetId(){
6537
- if (!$this->defaultAttributeSetId) {
6538
- $sql = "
6539
- SELECT entity_type_id, default_attribute_set_id
6540
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
6541
- WHERE entity_type_code = 'catalog_product'
6542
- LIMIT 1
6543
- ";
6544
- $result = $this->db_do($sql);
6545
- if ($row = mysqli_fetch_assoc($result)) {
6546
-
6547
- $this->defaultAttributeSetId = $row['default_attribute_set_id'];
6548
- }
6549
- }
6550
- return $this->defaultAttributeSetId;
6551
- }
6552
- #################################################################################################
6553
-
6554
- private function _getCategoryEntityTypeIdAndDefault_attribute_set_id(){
6555
- if (!$this->_categoryEntityTypeId || !$this->_categoryDefault_attribute_set_id) {
6556
- $sql = "
6557
- SELECT entity_type_id, default_attribute_set_id
6558
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
6559
- WHERE entity_type_code = 'catalog_category'
6560
- LIMIT 1
6561
- ";
6562
- $result = $this->db_do($sql);
6563
- if ($row = mysqli_fetch_assoc($result)) {
6564
- $this->_categoryEntityTypeId = $row['entity_type_id'];
6565
- $this->_categoryDefault_attribute_set_id = $row['default_attribute_set_id'];
6566
- }
6567
-
6568
- }
6569
- }
6570
- ##################################################################################################
6571
-
6572
- private function _getAttributeId($attributeCode,$typeCode)
6573
- {
6574
- if ($typeCode=='catalog_product') {
6575
- $typeId = $this->_getProductEntityTypeId();
6576
- }
6577
- else {
6578
- $typeId = $this->_getEntityTypeId($typeCode);
6579
- }
6580
- if (!isset($this->_attributeId[$typeCode]) OR !is_array($this->_attributeId[$typeCode])) {
6581
- $sql = "
6582
- SELECT attribute_id, attribute_code
6583
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute')."
6584
- WHERE entity_type_id = '" . $typeId . "'
6585
- ";
6586
- $result = $this->db_do($sql);
6587
- while ($row = mysqli_fetch_assoc($result)) {
6588
- $this->_attributeId[$typeCode][$row['attribute_code']] = $row['attribute_id'];
6589
- }
6590
- }
6591
- // echo 'attribute code: '.$attributeCode.','.$typeCode.' => '.$this->_attributeId[$typeCode][$attributeCode].PHP_EOL;
6592
- return $this->_attributeId[$typeCode][$attributeCode];
6593
- }
6594
- ##################################################################################################
6595
-
6596
- private function repl_ph($content,$hash){
6597
- if($hash){
6598
- foreach($hash as $key => $val){
6599
- if ($key=="category_name") {
6600
- if (strlen($val)>25) { $val = substr($val,0,24)."..."; }
6601
- }
6602
- $content = preg_replace("/%%%$key%%%/",$val,$content);
6603
- }
6604
- }
6605
- return $content;
6606
- }
6607
- ##################################################################################################
6608
-
6609
- private function _getProductAttributeId($attributeCode) {
6610
- return $this->_getAttributeId($attributeCode,'catalog_product');
6611
- }
6612
- ##################################################################################################
6613
-
6614
- private function _getCategoryAttributeId($attributeCode) {
6615
- return $this->_getAttributeId($attributeCode,'catalog_category');
6616
- }
6617
- ##################################################################################################
6618
- private function _getShopRootCategoryId($cat_id=0){
6619
- if($root_cat = Mage::app()->getStore()->getRootCategoryId()){
6620
- return $root_cat;
6621
- }else{
6622
- $q="SELECT
6623
- entity_id
6624
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')."
6625
- WHERE
6626
- value='default-category'";
6627
- $res=$this->db_do($q);
6628
- $row=mysqli_fetch_array($res);
6629
- if($row['entity_id']>0){
6630
- return $row['entity_id'];
6631
- }else{
6632
- $q="SELECT entity_id
6633
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
6634
- WHERE parent_id=".$cat_id;
6635
- $quer=$this->db_do($q);
6636
- $count=0;
6637
- while ($row=mysqli_fetch_array($quer)){
6638
- $count++;
6639
- $entity_id=$row['entity_id'];
6640
- }
6641
- if($count>1 || $count==0){
6642
- return ($cat_id);
6643
- }else{
6644
- return $this->_getShopRootCategoryId($entity_id);
6645
- }
6646
- }
6647
- }
6648
- }
6649
- ##################################################################################################
6650
- private function _cleanCateoryProductFlatTable(){
6651
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
6652
- $q='SHOW TABLES LIKE "'.Mage::getSingleton('core/resource')->getTableName('catalog_product_flat_').'%"';
6653
- $quer=$this->db_do($q);
6654
- $result=false;
6655
- While($row=mysqli_fetch_array($quer)){
6656
- if(is_array($row)){
6657
- $catalog_product_flat=array_pop($row);
6658
- $q='DELETE pf1 FROM '.$catalog_product_flat.' pf1
6659
- LEFT JOIN '.Mage::getSingleton('core/resource')->getTableName('catalog_product_entity').' p
6660
- ON pf1.entity_id = p.entity_id
6661
- WHERE p.entity_id IS NULL;';
6662
- $this->db_do($q);
6663
- $this->_LOG('cleaned wrong rows from '.$catalog_product_flat);
6664
- }
6665
- }
6666
- return $result;
6667
-
6668
- }
6669
- ##################################################################################################
6670
-
6671
-
6672
-
6673
-
6674
-
6675
- ##################################################################################################
6676
- public function checkMemory() {
6677
- $check_code = 'memory';
6678
-
6679
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6680
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
6681
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
6682
- $row = $result->fetch(PDO::FETCH_ASSOC);
6683
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
6684
-
6685
-
6686
- $Caption = $row['caption'];
6687
- $CheckValue = $row['check_value'];
6688
- $CheckMeasure = $row['check_measure'];
6689
- $ErrorMessage = $row['error_msg'];
6690
- $FixMessage = $row['fix_msg'];
6691
-
6692
- $retvalue = array();
6693
- $retvalue["'$check_code'"] = array();
6694
-
6695
- $data = explode("\n", file_get_contents("/proc/meminfo"));
6696
-
6697
- $meminfo = array();
6698
- foreach ($data as $line) {
6699
- list($key, $val) = explode(":", $line);
6700
- $meminfo[$key] = trim($val);
6701
-
6702
- if ($key == 'MemTotal') {
6703
- $val = trim($val);
6704
- $value = (int)substr($val, 0, strpos($val, ' kB'));
6705
- $measure = substr($val, strpos($val, ' kB'));
6706
-
6707
- $retvalue['memory']['value'] = (integer)(((float)$value)/1024); // (float)$value
6708
- $retvalue['memory']['measure'] = 'MB'; // $measure;
6709
- }
6710
- }
6711
-
6712
- $errmsg = '';
6713
- $fixmsg = '';
6714
- if ($retvalue['memory']['value'] <= $CheckValue || TRUE) {
6715
- $errmsg .= sprintf($ErrorMessage, $retvalue['memory']['value']); //." ".$retvalue['memory']['value']." ".$retvalue['memory']['measure'];
6716
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
6717
- $retvalue['memory']['status'] = 'error';
6718
- } else {
6719
- $errmsg .= 'none';
6720
- $fixmsg .= 'none';
6721
- $retvalue['memory']['status'] = 'OK';
6722
- }
6723
-
6724
- $ret = array();
6725
- array_push($ret, $retvalue['memory']['status'], $Caption, $CheckValue, $retvalue['memory']['value'], $CheckMeasure, $errmsg, $fixmsg);
6726
-
6727
- return $ret;
6728
- } // public function getImportEnvironment()
6729
- ##################################################################################################
6730
-
6731
-
6732
-
6733
-
6734
- ##################################################################################################
6735
- public function checkLoaddata() {
6736
- $check_code = 'loaddata';
6737
-
6738
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6739
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
6740
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
6741
- $row = $result->fetch(PDO::FETCH_ASSOC);
6742
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
6743
-
6744
- $Caption = $row['caption'];
6745
- $CheckValue = $row['check_value'];
6746
- $CheckMeasure = $row['check_measure'];
6747
- $ErrorMessage = $row['error_msg'];
6748
- $FixMessage = $row['fix_msg'];
6749
-
6750
- $retvalue = array();
6751
- $retvalue["'$check_code'"] = array();
6752
-
6753
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6754
- $result = $conn->query("SHOW VARIABLES LIKE 'local_infile'");
6755
- $row = $result->fetch(PDO::FETCH_ASSOC);
6756
- $value = $row['Value'];
6757
-
6758
-
6759
- $errmsg = '';
6760
- $fixmsg = '';
6761
- if ($value != $CheckValue || TRUE) {
6762
- $errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
6763
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
6764
- $status = 'error';
6765
- } else {
6766
- $errmsg .= 'none';
6767
- $fixmsg .= 'none';
6768
- $status = 'OK';
6769
- }
6770
-
6771
- $ret = array();
6772
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
6773
-
6774
- return $ret;
6775
- } // public function getImportEnvironment()
6776
- ##################################################################################################
6777
-
6778
-
6779
-
6780
-
6781
- ##################################################################################################
6782
- public function checkPhpsafemode() {
6783
- $check_code = 'phpsafemode';
6784
-
6785
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6786
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
6787
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
6788
- $row = $result->fetch(PDO::FETCH_ASSOC);
6789
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
6790
-
6791
- $Caption = $row['caption'];
6792
- $CheckValue = $row['check_value'];
6793
- $CheckMeasure = $row['check_measure'];
6794
- $ErrorMessage = $row['error_msg'];
6795
- $FixMessage = $row['fix_msg'];
6796
-
6797
- $retvalue = array();
6798
- $retvalue["'$check_code'"] = array();
6799
-
6800
- $a = ini_get('safe_mode');
6801
- if ($a) {
6802
- $value = 'ON';
6803
- } else {
6804
- $value = 'OFF';
6805
- }
6806
-
6807
- $errmsg = '';
6808
- $fixmsg = '';
6809
- if ($value != $CheckValue || TRUE) {
6810
- $errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
6811
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
6812
- $status = 'error';
6813
- } else {
6814
- $errmsg .= 'none';
6815
- $fixmsg .= 'none';
6816
- $status = 'OK';
6817
- }
6818
-
6819
- $ret = array();
6820
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
6821
-
6822
- return $ret;
6823
- } // public function getImportEnvironment()
6824
- ##################################################################################################
6825
-
6826
-
6827
-
6828
-
6829
- ##################################################################################################
6830
- public function checkWaittimeout() {
6831
- $check_code = 'waittimeout';
6832
-
6833
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6834
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
6835
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
6836
- $row = $result->fetch(PDO::FETCH_ASSOC);
6837
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
6838
-
6839
- $Caption = $row['caption'];
6840
- $CheckValue = $row['check_value'];
6841
- $CheckMeasure = $row['check_measure'];
6842
- $ErrorMessage = $row['error_msg'];
6843
- $FixMessage = $row['fix_msg'];
6844
-
6845
- $retvalue = array();
6846
- $retvalue["'$check_code'"] = array();
6847
-
6848
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6849
- $result = $conn->query("SHOW VARIABLES LIKE 'wait_timeout'");
6850
- $row = $result->fetch(PDO::FETCH_ASSOC);
6851
- $value = $row['Value'];
6852
-
6853
- $errmsg = '';
6854
- $fixmsg = '';
6855
- if ($value <= $CheckValue || TRUE) {
6856
- $errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
6857
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue);
6858
- $status = 'error';
6859
- } else {
6860
- $errmsg .= 'none';
6861
- $fixmsg .= 'none';
6862
- $status = 'OK';
6863
- }
6864
-
6865
- $ret = array();
6866
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
6867
-
6868
- return $ret;
6869
- } // public function getImportEnvironment()
6870
- ##################################################################################################
6871
-
6872
-
6873
-
6874
-
6875
- ##################################################################################################
6876
- public function checkInnodbbufferpoolsize() {
6877
- $check_code = 'innodbbufpool';
6878
-
6879
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6880
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
6881
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
6882
- $row = $result->fetch(PDO::FETCH_ASSOC);
6883
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
6884
-
6885
- $Caption = $row['caption'];
6886
- $CheckValue = $row['check_value'];
6887
- $CheckMeasure = $row['check_measure'];
6888
- $ErrorMessage = $row['error_msg'];
6889
- $FixMessage = $row['fix_msg'];
6890
-
6891
- $retvalue = array();
6892
- $retvalue["'$check_code'"] = array();
6893
-
6894
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6895
- $result = $conn->query("SHOW VARIABLES LIKE 'innodb_buffer_pool_size'");
6896
- $row = $result->fetch(PDO::FETCH_ASSOC);
6897
- $value = (int)($row['Value']/(1024*1024));
6898
-
6899
- $errmsg = '';
6900
- $fixmsg = '';
6901
- if ($value < $CheckValue || TRUE) {
6902
- $errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
6903
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
6904
- $status = 'error';
6905
- } else {
6906
- $errmsg .= 'none';
6907
- $fixmsg .= 'none';
6908
- $status = 'OK';
6909
- }
6910
-
6911
- $ret = array();
6912
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
6913
-
6914
- return $ret;
6915
- } // public function getImportEnvironment()
6916
- ##################################################################################################
6917
-
6918
-
6919
-
6920
-
6921
- ##################################################################################################
6922
- public function checkPhprunstring() {
6923
- $check_code = 'php5run';
6924
-
6925
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6926
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
6927
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
6928
- $row = $result->fetch(PDO::FETCH_ASSOC);
6929
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
6930
-
6931
- $Caption = $row['caption'];
6932
- $CheckValue = $row['check_value'];
6933
- $CheckMeasure = $row['check_measure'];
6934
- $ErrorMessage = $row['error_msg'];
6935
- $FixMessage = $row['fix_msg'];
6936
-
6937
- $retvalue = array();
6938
- $retvalue["'$check_code'"] = array();
6939
-
6940
- $value = trim(PHP_RUN_STRING);
6941
- $errmsg = '';
6942
- $fixmsg = '';
6943
- if( !defined('PHP_RUN_STRING') || TRUE){
6944
- $errmsg .= "You haven't installed PHP CLI";
6945
- $fixmsg .= "Install PHP CLI."; // ." ".$CheckValue." ".$CheckMeasure
6946
- $status = 'error';
6947
- }
6948
-
6949
- $ret = array();
6950
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
6951
-
6952
- return $ret;
6953
- } // public function getImportEnvironment()
6954
- ##################################################################################################
6955
-
6956
-
6957
-
6958
-
6959
- ##################################################################################################
6960
- public function checkChmodwgetdatafile() {
6961
- $check_code = 'chmodwget';
6962
-
6963
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
6964
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
6965
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
6966
- $row = $result->fetch(PDO::FETCH_ASSOC);
6967
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
6968
-
6969
- $Caption = $row['caption'];
6970
- $CheckValue = $row['check_value'];
6971
- $CheckMeasure = $row['check_measure'];
6972
- $ErrorMessage = $row['error_msg'];
6973
- $FixMessage = $row['fix_msg'];
6974
-
6975
- $retvalue = array();
6976
- $retvalue["'$check_code'"] = array();
6977
-
6978
- $datafile_csv = '/usr/bin/wget';
6979
-
6980
- $value = substr(sprintf('%o', fileperms($datafile_csv)), -4);
6981
-
6982
- $CheckValue_own = $CheckValue{1};
6983
- $CheckValue_group = $CheckValue{2};
6984
- $CheckValue_other = $CheckValue{3};
6985
-
6986
- $value_own = $value{1};
6987
- $value_group = $value{2};
6988
- $value_other = $value{3};
6989
-
6990
- $errmsg = '';
6991
- $fixmsg = '';
6992
- //if ($value <= $CheckValue) {
6993
- if (($value_own < $CheckValue_own || TRUE) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
6994
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
6995
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
6996
- $status = 'error';
6997
- } else {
6998
- $errmsg .= 'none';
6999
- $fixmsg .= 'none';
7000
- $status = 'OK';
7001
- }
7002
-
7003
- $ret = array();
7004
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
7005
-
7006
- return $ret;
7007
- } // public function getImportEnvironment()
7008
- ##################################################################################################
7009
-
7010
-
7011
-
7012
-
7013
- ##################################################################################################
7014
- public function checkChmodwgetcronphpfile() {
7015
- $check_code = 'chmodcronphp';
7016
-
7017
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
7018
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
7019
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
7020
- $row = $result->fetch(PDO::FETCH_ASSOC);
7021
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
7022
-
7023
- $Caption = $row['caption'];
7024
- $CheckValue = $row['check_value'];
7025
- $CheckMeasure = $row['check_measure'];
7026
- $ErrorMessage = $row['error_msg'];
7027
- $FixMessage = $row['fix_msg'];
7028
-
7029
- $retvalue = array();
7030
- $retvalue["'$check_code'"] = array();
7031
-
7032
- $cronfile_php = Mage::getBaseDir().'/cron.php';
7033
-
7034
- $value = substr(sprintf('%o', fileperms($cronfile_php)), -4);
7035
-
7036
- $CheckValue_own = $CheckValue{1};
7037
- $CheckValue_group = $CheckValue{2};
7038
- $CheckValue_other = $CheckValue{3};
7039
-
7040
- $value_own = $value{1};
7041
- $value_group = $value{2};
7042
- $value_other = $value{3};
7043
-
7044
- $errmsg = '';
7045
- $fixmsg = '';
7046
- //if ($value <= $CheckValue) {
7047
- if (($value_own < $CheckValue_own || TRUE) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
7048
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
7049
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
7050
- $status = 'error';
7051
- } else {
7052
- $errmsg .= 'none';
7053
- $fixmsg .= 'none';
7054
- $status = 'OK';
7055
- }
7056
-
7057
- $ret = array();
7058
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
7059
-
7060
- return $ret;
7061
- } // public function checkChmodwgetcronphpfile()
7062
- ##################################################################################################
7063
-
7064
-
7065
-
7066
-
7067
- ##################################################################################################
7068
- public function checkChmodwgetcronshfile() {
7069
- $check_code = 'chmodcronsh';
7070
-
7071
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
7072
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
7073
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
7074
- $row = $result->fetch(PDO::FETCH_ASSOC);
7075
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
7076
-
7077
- $Caption = $row['caption'];
7078
- $CheckValue = $row['check_value'];
7079
- $CheckMeasure = $row['check_measure'];
7080
- $ErrorMessage = $row['error_msg'];
7081
- $FixMessage = $row['fix_msg'];
7082
-
7083
- $retvalue = array();
7084
- $retvalue["'$check_code'"] = array();
7085
-
7086
- $cronfile_sh = Mage::getBaseDir().'/cron.sh';
7087
-
7088
- $value = substr(sprintf('%o', fileperms($cronfile_sh)), -4);
7089
-
7090
- $CheckValue_own = $CheckValue{1};
7091
- $CheckValue_group = $CheckValue{2};
7092
- $CheckValue_other = $CheckValue{3};
7093
-
7094
- $value_own = $value{1};
7095
- $value_group = $value{2};
7096
- $value_other = $value{3};
7097
-
7098
- $errmsg = '';
7099
- $fixmsg = '';
7100
- //if ($value <= $CheckValue) {
7101
- if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other) || TRUE) {
7102
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
7103
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
7104
- $status = 'error';
7105
- } else {
7106
- $errmsg .= 'none';
7107
- $fixmsg .= 'none';
7108
- $status = 'OK';
7109
- }
7110
-
7111
- $ret = array();
7112
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
7113
-
7114
- return $ret;
7115
- } // public function checkChmodwgetcronphpfile()
7116
- ##################################################################################################
7117
-
7118
-
7119
-
7120
-
7121
- ##################################################################################################
7122
- public function checkProcedure() {
7123
- $check_code = 'routine';
7124
-
7125
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
7126
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
7127
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
7128
- $row = $result->fetch(PDO::FETCH_ASSOC);
7129
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
7130
-
7131
- $Caption = $row['caption'];
7132
- $CheckValue = $row['check_value'];
7133
- $CheckMeasure = $row['check_measure'];
7134
- $ErrorMessage = $row['error_msg'];
7135
- $FixMessage = $row['fix_msg'];
7136
-
7137
- $retvalue = array();
7138
- $retvalue["'$check_code'"] = array();
7139
-
7140
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
7141
- $storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
7142
- $result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
7143
- $row = $result->fetch(PDO::FETCH_ASSOC);
7144
- $value = $row['Name'];
7145
-
7146
- $errmsg = '';
7147
- $fixmsg = '';
7148
- if ($value != $CheckValue || TRUE) {
7149
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
7150
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
7151
- $status = 'error';
7152
- } else {
7153
- $errmsg .= 'none';
7154
- $fixmsg .= 'none';
7155
- $status = 'OK';
7156
- }
7157
-
7158
- $ret = array();
7159
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
7160
-
7161
- return $ret;
7162
- } // public function getImportEnvironment()
7163
- ##################################################################################################
7164
-
7165
-
7166
-
7167
- } // class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract
7168
-
7169
-
7170
-
7171
-
7172
- ?>
7173
-
7174
-
7175
-
7176
-
7177
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>stockinthechannel2012</name>
4
- <version>2.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3</license>
7
  <channel>community</channel>
@@ -9,14 +9,14 @@
9
  <summary>Import Plugin for the Stock in the Channel Magento Data Feed</summary>
10
  <description>Import Plugin for the Stock in the Channel Magento Data Feed.&#xD;
11
  Requires a Magento Formatted Data feed from http://stockinthechannel.com</description>
12
- <notes>Version 2.0.3:&#xD;
13
- * Now uses MySQLi instead of the MySQL plugin&#xD;
14
- * Updated Server's list to contain every region we support&#xD;
15
- * International fix is now part of the plugin by default</notes>
16
  <authors><author><name>stockinchannel</name><user>stockinchannel</user><email>marketing@stockinthechannel.com</email></author><author><name>Nick Anstee</name><user>nicka101</user><email>nick@stockinthechannel.com</email></author></authors>
17
- <date>2014-11-20</date>
18
- <time>13:21:30</time>
19
- <contents><target name="magelocal"><dir name="Bintime"><dir name="Sinchimport"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><file name="Sinchdistributors.php" hash="20c2452bfbf7206c72b2402e4eaa1541"/></dir></dir></dir><file name="Importenvironment.php" hash="85ac7cf582ad798fc31d85855319d6e1"/><file name="Importhistory.php" hash="3748b6e5ccdd242fa8a8cdb96a53241e"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="239d86cde4cf08f5f50183df26e89eea"/></dir><file name="View.php" hash="60e6aeb7f07e6be9e6202395bf76dfad"/></dir><file name="List.php" hash="db883cb9fb90fc16e4e9cb5db2050937"/><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="4ab6866b88f6aa5e59a99808b38dc85b"/><file name="Price.php" hash="93a6b62fec1e11bf6af57dd0cb2f063a"/></dir></dir><file name="Layer.php" hash="2c0131265f18450126d7a0988d6ed284"/><file name="Product.php" hash="1e3be2c2c605b3eaf79aea1627ef4d49"/><dir name="Resource"><dir name="Layer"><dir name="Filter"><file name="Price.php" hash="0d1fd59eb80f281ebad11bf15d3007da"/></dir></dir><dir name="Mysql4"><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="ea9c35e365239bdcc362ff98369cbd87"/></dir></dir><file name="Setup.php" hash="280a1ece3e1bb1f035e2cf265da05b63"/></dir></dir><file name="Sinch.php" hash="ce012e1b5231cc97d368389e1d38c25e"/><file name="Sinch_new_code.php" hash="98a2c5197038404a4de141c647b32b88"/><dir name="System"><dir name="Config"><file name="CatRewrite.php" hash="f54ba849b2342dfb177f4cd4736eaa48"/><file name="ProdRewrite.php" hash="95c993c6ef3258fd0c2745f39f3fcec7"/><file name="ServerList.php" hash="0ce62323bf583551c3c812ba4c656189"/><file name="Subscription.php" hash="985102ab2005f33e017818ef9247b633"/></dir></dir><file name="config.php" hash="89690f17588698f736ff9070d6f947a2"/></dir><dir name="controllers"><file name="AjaxController.php" hash="997ca1a6c79ad85b7eff86e2b3125bf1"/><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="d1aef99f24977f702b6f3f5aaaf1f373"/><file name="system.xml" hash="b725941c89c9695ac9ff6e15e30ffb8e"/></dir><file name="sinch_import_start_ajax.php" hash="3f34acad1b0618d5350d28fd1acf506d"/><dir name="sql"><dir name="sinchimport_setup"><file name="filter_sinch_products_s.sql" hash="a66330a1c2717091c1752ddd89f63960"/><file name="mysql4-install-0.1.0.php" hash="5925ffb8574cb35032b9d2866f4da7be"/><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="710c4d2873fcbe3061b925072d995d73"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="d2892bb825c7baf2139c136fd96f2f66"/><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="f195a8bf9fbcc31eca6d066ff1bb98f5"/><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="f4ee53d9644c16c80327b40fec432d1d"/><file name="mysql4-upgrade-0.1.6-0.1.7.php" hash="987ed4ca76a263580705ec93e0277120"/><file name="mysql4-upgrade-0.1.7-0.1.8.php" hash="e52bb4ef6f982992fcbfcce710698525"/><file name="mysql4-upgrade-0.1.8-0.1.9.php" hash="de6b560cef7edf7914cc4f135b0678b9"/><file name="mysql4-upgrade-0.1.9-0.2.0.php" hash="33618a810c8b88d28fc1b504eb65c657"/><file name="mysql4-upgrade-0.2.0-0.2.1.php" hash="507b285ba1f3eb98d9fb54a3ae29257c"/><file name="mysql4-upgrade-0.2.1-0.2.2.php" hash="55732b89b294191eaecbe3a5e1c7691e"/><file name="mysql4-upgrade-3.0.0-3.0.1.php" hash="3a7b53cbc0585e04afed64b321771a8a"/><file name="mysql4-upgrade-3.0.1-3.0.2.php" hash="12853ce85af460e0d462fbf3297715c0"/><file name="mysql4-upgrade-3.0.2-3.0.3.php" hash="2c0c1a12c567ecacad6647eeffa4f198"/><file name="mysql4-upgrade-3.0.3-3.0.4.php" hash="9c3612df0a873fa6e59ae9f98c5de2b0"/></dir></dir><file name="stock_price_sinch_import_start_ajax.php" hash="960ba4cfdb5ea3548a17c2365c0fca80"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bintime_Sinchimport.xml" hash="14afd0361958cc31fc57431c4e4c3ba1"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="sinchimport.xml" hash="e60b86828e8d9666724311907451d1ba"/></dir><dir name="template"><dir name="sinchimport"><file name="list.phtml" hash="1312f3b0ded996cb820e9c17a434e716"/><file name="media.phtml" hash="a448fd63753f44c86cc091e4da8b9e99"/><file name="view.phtml" hash="7c21e0b3f31cf3eb7d0e2a6e619f58ef"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="sinchimport.xml" hash="3ed2e666e7bf9838a63aa31c0c829e9c"/></dir><dir name="template"><dir name="sinchimport"><dir name="sales"><dir name="items"><dir name="column"><file name="name.phtml" hash="7997765254d19e09b30cf1d0090bd4e6"/></dir></dir></dir><file name="sinchdistributors.phtml" hash="d74f3d401b83319c1b42b878afc5ccff"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><file name="sinchimport_run.gif" hash="e805ea7eca1f34c75ba0f93780d32d38"/><file name="sinchimport_yes.gif" hash="0afb20898a704a106cb4c598868abf32"/></dir></dir></dir></dir></target></contents>
20
  <compatible/>
21
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
22
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>stockinthechannel2012</name>
4
+ <version>2.0.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3</license>
7
  <channel>community</channel>
9
  <summary>Import Plugin for the Stock in the Channel Magento Data Feed</summary>
10
  <description>Import Plugin for the Stock in the Channel Magento Data Feed.&#xD;
11
  Requires a Magento Formatted Data feed from http://stockinthechannel.com</description>
12
+ <notes>Version 2.0.4:&#xD;
13
+ * Change the way the MySQL connection is initialized to resolve an edge case where some systems wouldn't accept the LOCAL INFILE flag at that point&#xD;
14
+ * Fix the calls to mysqli_real_escape_string to include the connection object as required&#xD;
15
+ * Remove the currently unused Sinch_new_code.php from Model</notes>
16
  <authors><author><name>stockinchannel</name><user>stockinchannel</user><email>marketing@stockinthechannel.com</email></author><author><name>Nick Anstee</name><user>nicka101</user><email>nick@stockinthechannel.com</email></author></authors>
17
+ <date>2014-12-04</date>
18
+ <time>15:15:19</time>
19
+ <contents><target name="magelocal"><dir name="Bintime"><dir name="Sinchimport"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><file name="Sinchdistributors.php" hash="20c2452bfbf7206c72b2402e4eaa1541"/></dir></dir></dir><file name="Importenvironment.php" hash="85ac7cf582ad798fc31d85855319d6e1"/><file name="Importhistory.php" hash="3748b6e5ccdd242fa8a8cdb96a53241e"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="239d86cde4cf08f5f50183df26e89eea"/></dir><file name="View.php" hash="60e6aeb7f07e6be9e6202395bf76dfad"/></dir><file name="List.php" hash="db883cb9fb90fc16e4e9cb5db2050937"/><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="4ab6866b88f6aa5e59a99808b38dc85b"/><file name="Price.php" hash="93a6b62fec1e11bf6af57dd0cb2f063a"/></dir></dir><file name="Layer.php" hash="2c0131265f18450126d7a0988d6ed284"/><file name="Product.php" hash="1e3be2c2c605b3eaf79aea1627ef4d49"/><dir name="Resource"><dir name="Layer"><dir name="Filter"><file name="Price.php" hash="0d1fd59eb80f281ebad11bf15d3007da"/></dir></dir><dir name="Mysql4"><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="ea9c35e365239bdcc362ff98369cbd87"/></dir></dir><file name="Setup.php" hash="280a1ece3e1bb1f035e2cf265da05b63"/></dir></dir><file name="Sinch.php" hash="9c6b71e7c1f4e7f6e83a0e1597b4120b"/><dir name="System"><dir name="Config"><file name="CatRewrite.php" hash="f54ba849b2342dfb177f4cd4736eaa48"/><file name="ProdRewrite.php" hash="95c993c6ef3258fd0c2745f39f3fcec7"/><file name="ServerList.php" hash="0ce62323bf583551c3c812ba4c656189"/><file name="Subscription.php" hash="985102ab2005f33e017818ef9247b633"/></dir></dir><file name="config.php" hash="89690f17588698f736ff9070d6f947a2"/></dir><dir name="controllers"><file name="AjaxController.php" hash="997ca1a6c79ad85b7eff86e2b3125bf1"/><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="d1aef99f24977f702b6f3f5aaaf1f373"/><file name="system.xml" hash="b725941c89c9695ac9ff6e15e30ffb8e"/></dir><file name="sinch_import_start_ajax.php" hash="3f34acad1b0618d5350d28fd1acf506d"/><dir name="sql"><dir name="sinchimport_setup"><file name="filter_sinch_products_s.sql" hash="a66330a1c2717091c1752ddd89f63960"/><file name="mysql4-install-0.1.0.php" hash="5925ffb8574cb35032b9d2866f4da7be"/><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="710c4d2873fcbe3061b925072d995d73"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="d2892bb825c7baf2139c136fd96f2f66"/><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="f195a8bf9fbcc31eca6d066ff1bb98f5"/><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="f4ee53d9644c16c80327b40fec432d1d"/><file name="mysql4-upgrade-0.1.6-0.1.7.php" hash="987ed4ca76a263580705ec93e0277120"/><file name="mysql4-upgrade-0.1.7-0.1.8.php" hash="e52bb4ef6f982992fcbfcce710698525"/><file name="mysql4-upgrade-0.1.8-0.1.9.php" hash="de6b560cef7edf7914cc4f135b0678b9"/><file name="mysql4-upgrade-0.1.9-0.2.0.php" hash="33618a810c8b88d28fc1b504eb65c657"/><file name="mysql4-upgrade-0.2.0-0.2.1.php" hash="507b285ba1f3eb98d9fb54a3ae29257c"/><file name="mysql4-upgrade-0.2.1-0.2.2.php" hash="55732b89b294191eaecbe3a5e1c7691e"/><file name="mysql4-upgrade-3.0.0-3.0.1.php" hash="3a7b53cbc0585e04afed64b321771a8a"/><file name="mysql4-upgrade-3.0.1-3.0.2.php" hash="12853ce85af460e0d462fbf3297715c0"/><file name="mysql4-upgrade-3.0.2-3.0.3.php" hash="2c0c1a12c567ecacad6647eeffa4f198"/><file name="mysql4-upgrade-3.0.3-3.0.4.php" hash="9c3612df0a873fa6e59ae9f98c5de2b0"/></dir></dir><file name="stock_price_sinch_import_start_ajax.php" hash="960ba4cfdb5ea3548a17c2365c0fca80"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bintime_Sinchimport.xml" hash="14afd0361958cc31fc57431c4e4c3ba1"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="sinchimport.xml" hash="e60b86828e8d9666724311907451d1ba"/></dir><dir name="template"><dir name="sinchimport"><file name="list.phtml" hash="1312f3b0ded996cb820e9c17a434e716"/><file name="media.phtml" hash="a448fd63753f44c86cc091e4da8b9e99"/><file name="view.phtml" hash="7c21e0b3f31cf3eb7d0e2a6e619f58ef"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="sinchimport.xml" hash="3ed2e666e7bf9838a63aa31c0c829e9c"/></dir><dir name="template"><dir name="sinchimport"><dir name="sales"><dir name="items"><dir name="column"><file name="name.phtml" hash="7997765254d19e09b30cf1d0090bd4e6"/></dir></dir></dir><file name="sinchdistributors.phtml" hash="d74f3d401b83319c1b42b878afc5ccff"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><file name="sinchimport_run.gif" hash="e805ea7eca1f34c75ba0f93780d32d38"/><file name="sinchimport_yes.gif" hash="0afb20898a704a106cb4c598868abf32"/></dir></dir></dir></dir></target></contents>
20
  <compatible/>
21
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
22
  </package>