stockinthechannel2012 - Version 2.0.0

Version Notes

Version 2.0.0
* NEW - Now supports new Magento feed format
* NEW - Allow for Toner Feed imports
* NEW - Allow Mapping of products to Multiple Categories
* Fixed Occasional Price Breaks Error

Download this release

Release Info

Developer stockinchannel
Extension stockinthechannel2012
Version 2.0.0
Comparing to
See all releases


Code changes from version 1.2.0 to 2.0.0

Files changed (20) hide show
  1. app/code/local/Bintime/Sinchimport/Block/Adminhtml/Catalog/Product/Sinchdistributors.php +25 -0
  2. app/code/local/Bintime/Sinchimport/Block/Importenvironment.php +14 -0
  3. app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php +2 -1
  4. app/code/local/Bintime/Sinchimport/Model/Sinch.php +1660 -127
  5. app/code/local/Bintime/Sinchimport/Model/System/Config/ProdRewrite.php +18 -0
  6. app/code/local/Bintime/Sinchimport/Model/config.php +7 -1
  7. app/code/local/Bintime/Sinchimport/controllers/AjaxController.php +16 -2
  8. app/code/local/Bintime/Sinchimport/etc/config.xml +24 -1
  9. app/code/local/Bintime/Sinchimport/etc/system.xml +10 -1
  10. app/code/local/Bintime/Sinchimport/sinch_import_start_ajax.php +0 -1
  11. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/filter_sinch_products_s.sql +181 -84
  12. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.9-0.2.0.php +0 -3
  13. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.2.1-0.2.2.php +230 -0
  14. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.0-3.0.1.php +307 -0
  15. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.1-3.0.2.php +108 -0
  16. app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.2-3.0.3.php +42 -0
  17. app/design/adminhtml/default/default/layout/sinchimport.xml +57 -0
  18. app/design/adminhtml/default/default/template/sinchimport/sales/items/column/name.phtml +70 -0
  19. app/design/adminhtml/default/default/template/sinchimport/sinchdistributors.phtml +13 -0
  20. package.xml +14 -13
app/code/local/Bintime/Sinchimport/Block/Adminhtml/Catalog/Product/Sinchdistributors.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Sinchimport_Block_Adminhtml_Catalog_Product_Sinchdistributors extends Mage_Core_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface
3
+ {
4
+ public function __construct(){
5
+ $this->setTemplate('sinchimport/sinchdistributors.phtml');
6
+ parent::__construct();
7
+ }
8
+
9
+ //Label to be shown in the tab
10
+ public function getTabLabel(){
11
+ return Mage::helper('core')->__('Suppliers');
12
+ }
13
+
14
+ public function getTabTitle(){
15
+ return Mage::helper('core')->__('Suppliers');
16
+ }
17
+
18
+ public function canShowTab(){
19
+ return true;
20
+ }
21
+
22
+ public function isHidden(){
23
+ return false;
24
+ }
25
+ }
app/code/local/Bintime/Sinchimport/Block/Importenvironment.php CHANGED
@@ -104,6 +104,20 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
104
  ";
105
  };
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
  // PHP run string
109
  list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkPhprunstring();
104
  ";
105
  };
106
 
107
+
108
+ // Conflict with installed module
109
+ list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkConflictsWithInstalledModules();
110
+ if ($status == 'error') $errors_count++;
111
+ if ($status == 'error') {
112
+ $html .= // $caption: $value $measure
113
+ "
114
+ <tr> <td nowrap rowspan=4> $caption </td> </tr>
115
+ <tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
116
+ <tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
117
+ <tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
118
+ ";
119
+ };
120
+
121
 
122
  // PHP run string
123
  list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkPhprunstring();
app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php CHANGED
@@ -97,7 +97,8 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
97
  $params .= $bounds[1] != '-' ? (int)$bounds[1] : 'null';
98
  }
99
  //$connection->query("CALL `filter_icecat_products_s`($cfid, $catId,0,$cfid, $params)"));
100
- $result = $connection->raw_query("CALL ".$this->_getTableName('filter_sinch_products_s')."($cfid, $catId,0, $cfid, $params)");
 
101
  Varien_Profiler::stop(__METHOD__);
102
  return $resultTable;
103
  }
97
  $params .= $bounds[1] != '-' ? (int)$bounds[1] : 'null';
98
  }
99
  //$connection->query("CALL `filter_icecat_products_s`($cfid, $catId,0,$cfid, $params)"));
100
+ $tablePrefix = (string)Mage::app()->getConfig()->getTablePrefix();
101
+ $result = $connection->raw_query("CALL ".$this->_getTableName('filter_sinch_products_s')."($cfid, $catId,0, $cfid, $params, '$tablePrefix')");
102
  Varien_Profiler::stop(__METHOD__);
103
  return $resultTable;
104
  }
app/code/local/Bintime/Sinchimport/Model/Sinch.php CHANGED
@@ -40,9 +40,19 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
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
  private $im_type;
@@ -56,6 +66,8 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
56
  $this->import_log_table="stINch_import_log";
57
 
58
  $this->php_run_string=PHP_RUN_STRING;
 
 
59
  $this->price_breaks_filter=PRICE_BREAKS;
60
  /*$this->db_connect();
61
  $res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
@@ -70,16 +82,20 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
70
  $this->_LOG("constructor");
71
  $this->files=array(
72
  FILE_CATEGORIES,
 
73
  FILE_CATEGORIES_FEATURES,
74
  FILE_DISTRIBUTORS,
 
75
  FILE_EANCODES,
76
  FILE_MANUFACTURERS,
77
  FILE_PRODUCT_FEATURES,
 
78
  FILE_PRODUCTS,
79
  FILE_RELATED_PRODUCTS,
80
  FILE_RESTRICTED_VALUES,
81
  FILE_STOCK_AND_PRICES,
82
- FILE_PRODUCTS_PICTURES_GALLERY
 
83
  );
84
  $this->attributes['manufacturer']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
85
  $this->attributes['name']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
@@ -187,6 +203,11 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
187
  }
188
  #################################################################################################
189
  function run_sinch_import(){
 
 
 
 
 
190
  $safe_mode_set = ini_get('safe_mode');
191
 
192
  $this->InitImportStatuses('FULL');
@@ -216,6 +237,11 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
216
  $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
217
  exit;
218
  }
 
 
 
 
 
219
 
220
  if($this->is_imort_not_run()){
221
  try{
@@ -228,6 +254,9 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
228
  $import->UploadFiles();
229
  $import->addImportStatus('Upload Files');
230
 
 
 
 
231
  echo "Parse Categories <br>";
232
  $coincidence = $import->ParseCategories();
233
  $import->addImportStatus('Parse Categories');
@@ -245,9 +274,11 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
245
 
246
  echo "Parse Distributors <br>";
247
  $import->ParseDistributors();
 
 
 
248
  $import->addImportStatus('Parse Distributors');
249
 
250
-
251
  echo "Parse EAN Codes <br>";
252
  $import->ParseEANCodes();
253
  $import->addImportStatus('Parse EAN Codes');
@@ -267,7 +298,8 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
267
  $import->ParseProductFeatures();
268
  $import->addImportStatus('Parse Product Features');
269
 
270
-
 
271
 
272
  echo "Parse Products <br>";
273
  $import->ParseProducts($coincidence);
@@ -285,11 +317,14 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
285
  $import->ParseRestrictedValues();
286
  $import->addImportStatus('Parse Restricted Values');
287
 
288
-
289
  echo "Parse Stock And Prices <br>";
290
  $import->ParseStockAndPrices();
291
  $import->addImportStatus('Parse Stock And Prices');
292
-
 
 
 
 
293
 
294
  Mage::log("Finish Sinch import", null, $this->_logFile);
295
  echo "Finish Sinch import<br>";
@@ -378,7 +413,8 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
378
  $import->addImportStatus('Stock Price Start Import');
379
  echo "Upload Files <br>";
380
  $this->files=array(
381
- FILE_STOCK_AND_PRICES
 
382
  );
383
 
384
  $import->UploadFiles();
@@ -389,6 +425,10 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
389
  $import->ParseStockAndPrices();
390
  $import->addImportStatus('Stock Price Parse Products');
391
 
 
 
 
 
392
 
393
  Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
394
  echo "Finish Stock & Price Sinch import<br>";
@@ -472,7 +512,7 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
472
  }
473
  exec("chmod a+rw ".$this->varDir.$file);
474
  if(!filesize($this->varDir.$file)){
475
- if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES){
476
  $this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
477
  $this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
478
  $this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
@@ -491,11 +531,31 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
491
  }elseif($file==FILE_RESTRICTED_VALUES){
492
  $this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
493
  $this->_ignore_restricted_values=true;
 
 
 
 
 
 
 
 
 
 
 
 
 
494
  }
 
495
  }
496
  }
497
  }
498
-
 
 
 
 
 
 
499
  $this->_LOG("Finish upload files");
500
  }
501
  #################################################################################################
@@ -526,6 +586,7 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
526
  $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
527
  $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
528
  $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
 
529
 
530
  $_categoryEntityTypeId = $this->_categoryEntityTypeId;
531
  $_categoryDefault_attribute_set_id = $this->_categoryDefault_attribute_set_id;
@@ -533,6 +594,10 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
533
  $name_attrid = $this->_getCategoryAttributeId('name');
534
  $is_anchor_attrid = $this->_getCategoryAttributeId('is_anchor');
535
  $image_attrid = $this->_getCategoryAttributeId('image');
 
 
 
 
536
  $attr_url_key = $this->attributes['url_key'];
537
  $attr_display_mode = $this->attributes['display_mode'];
538
  $attr_is_active = $this->attributes['is_active'];
@@ -540,7 +605,7 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
540
 
541
 
542
  $this->loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char);
543
- $coincidence = $this->calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type);
544
 
545
  /**/
546
  if (!$this->check_loaded_data($parse_file, $categories_temp))
@@ -606,7 +671,7 @@ echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
606
  $this->_LOG("Wrong file ".$parse_file);
607
  }
608
  $this->_LOG(' ');
609
-
610
  return $coincidence;
611
  } // function ParseCategories()
612
  ################################################################################################################################################################
@@ -648,7 +713,7 @@ echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
648
  parent_store_category_id INT(11),
649
  category_name VARCHAR(50),
650
  order_number INT(11),
651
- is_hidden BOOLEAN,
652
  products_within_sub_categories INT(11),
653
  products_within_this_category INT(11),
654
  categories_image VARCHAR(255),
@@ -656,7 +721,10 @@ echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
656
  children_count INT(11) NOT NULL DEFAULT 0,
657
  UNSPSC INT(10) DEFAULT NULL,
658
  RootName INT(10) DEFAULT NULL,
659
-
 
 
 
660
  KEY(store_category_id),
661
  KEY(parent_store_category_id)
662
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
@@ -666,6 +734,12 @@ echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
666
  LOAD DATA LOCAL INFILE '$parse_file' INTO TABLE $categories_temp
667
  FIELDS TERMINATED BY '$field_terminated_char' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES");
668
 
 
 
 
 
 
 
669
 
670
 
671
 
@@ -687,7 +761,6 @@ echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
687
  //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id IN (175687, 175553)"); // OLD CATS...//
688
 
689
  /**/
690
-
691
  } // private function loadCategoriesTemp()
692
  ################################################################################################################################################################
693
 
@@ -933,13 +1006,13 @@ echo("\n\n $query\n\n");
933
  $attr_include_in_menu,
934
  0,
935
  scm.shop_entity_id,
936
- 1
937
  FROM $categories_temp c
938
  JOIN $stINch_categories_mapping scm
939
  ON c.store_category_id = scm.store_category_id
940
  )
941
  ON DUPLICATE KEY UPDATE
942
- value = 1";
943
  $this->db_do($q);
944
 
945
 
@@ -957,13 +1030,13 @@ echo("\n\n $query\n\n");
957
  $is_anchor_attrid,
958
  1,
959
  scm.shop_entity_id,
960
- 1
961
  FROM $categories_temp c
962
  JOIN $stINch_categories_mapping scm
963
  ON c.store_category_id = scm.store_category_id
964
  )
965
  ON DUPLICATE KEY UPDATE
966
- value = 1";
967
  $this->db_do($q);
968
 
969
 
@@ -981,13 +1054,13 @@ echo("\n\n $query\n\n");
981
  $is_anchor_attrid,
982
  0,
983
  scm.shop_entity_id,
984
- 1
985
  FROM $categories_temp c
986
  JOIN $stINch_categories_mapping scm
987
  ON c.store_category_id = scm.store_category_id
988
  )
989
  ON DUPLICATE KEY UPDATE
990
- value = 1";
991
  $this->db_do($q);
992
 
993
  $q = "
@@ -1012,6 +1085,78 @@ echo("\n\n $query\n\n");
1012
  ON DUPLICATE KEY UPDATE
1013
  value = c.categories_image";
1014
  $this->db_do($q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1015
  }
1016
  else
1017
  {
@@ -1076,7 +1221,7 @@ echo("\n\n $query\n\n");
1076
  $attr_include_in_menu,
1077
  0,
1078
  scm.shop_entity_id,
1079
- 1
1080
  FROM $categories_temp c
1081
  JOIN $stINch_categories_mapping scm
1082
  ON c.store_category_id = scm.store_category_id
@@ -1098,7 +1243,7 @@ echo("\n\n $query\n\n");
1098
  $is_anchor_attrid,
1099
  0,
1100
  scm.shop_entity_id,
1101
- 1
1102
  FROM $categories_temp c
1103
  JOIN $stINch_categories_mapping scm
1104
  ON c.store_category_id = scm.store_category_id
@@ -1126,6 +1271,76 @@ echo("\n\n $query\n\n");
1126
  ON c.store_category_id = scm.store_category_id
1127
  )";
1128
  $this->db_do($q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1129
  }
1130
 
1131
 
@@ -1404,7 +1619,7 @@ echo("\n\n ==================================================================
1404
  (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1405
  path, position, level, children_count, store_category_id, parent_store_category_id)
1406
  VALUES
1407
- ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 0, NULL, NULL)");
1408
 
1409
 
1410
  $this->db_do("INSERT $catalog_category_entity_varchar
@@ -1438,7 +1653,7 @@ echo("\n createNewDefaultCategories done... \n ===========================
1438
 
1439
 
1440
  ################################################################################################################################################################
1441
- private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type)
1442
  {
1443
  $root_categories = $this->db_do("
1444
  SELECT
@@ -1455,9 +1670,12 @@ echo("\n createNewDefaultCategories done... \n ===========================
1455
  while($root_cat = mysql_fetch_array($root_categories)) $OLD[] = $root_cat['category_name'];
1456
 
1457
  $new_categories = $this->db_do("SELECT DISTINCT RootName FROM $categories_temp");
 
 
 
1458
  $NEW = array();
1459
  while($new_root_cat = mysql_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['RootName']] = TRUE;
1460
-
1461
  /**
1462
  $exists_coincidence = array();
1463
 
@@ -1586,7 +1804,7 @@ echo("rewriteMultistoreCategories DONE\n");
1586
  (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1587
  path, position, level, children_count, store_category_id, parent_store_category_id)
1588
  VALUES
1589
- ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 0, NULL, NULL)");
1590
 
1591
 
1592
  $this->db_do("INSERT $catalog_category_entity_varchar
@@ -1947,13 +2165,13 @@ echo("\n\n$query\n\n");
1947
  $attr_include_in_menu,
1948
  0,
1949
  scm.shop_entity_id,
1950
- 1
1951
  FROM $categories_temp c
1952
  JOIN $stINch_categories_mapping scm
1953
  ON c.store_category_id = scm.store_category_id
1954
  )
1955
  ON DUPLICATE KEY UPDATE
1956
- value = 1";
1957
  $this->db_do($q);
1958
 
1959
 
@@ -1971,13 +2189,13 @@ echo("\n\n$query\n\n");
1971
  $is_anchor_attrid,
1972
  1,
1973
  scm.shop_entity_id,
1974
- 1
1975
  FROM $categories_temp c
1976
  JOIN $stINch_categories_mapping scm
1977
  ON c.store_category_id = scm.store_category_id
1978
  )
1979
  ON DUPLICATE KEY UPDATE
1980
- value = 1";
1981
  $this->db_do($q);
1982
 
1983
 
@@ -1995,13 +2213,13 @@ echo("\n\n$query\n\n");
1995
  $is_anchor_attrid,
1996
  0,
1997
  scm.shop_entity_id,
1998
- 1
1999
  FROM $categories_temp c
2000
  JOIN $stINch_categories_mapping scm
2001
  ON c.store_category_id = scm.store_category_id
2002
  )
2003
  ON DUPLICATE KEY UPDATE
2004
- value = 1";
2005
  $this->db_do($q);
2006
 
2007
  $q = "
@@ -2026,6 +2244,78 @@ echo("\n\n$query\n\n");
2026
  ON DUPLICATE KEY UPDATE
2027
  value = c.categories_image";
2028
  $this->db_do($q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2029
  }
2030
  else
2031
  {
@@ -2089,7 +2379,7 @@ echo("\n\n$query\n\n");
2089
  $attr_include_in_menu,
2090
  0,
2091
  scm.shop_entity_id,
2092
- 1
2093
  FROM $categories_temp c
2094
  JOIN $stINch_categories_mapping scm
2095
  ON c.store_category_id = scm.store_category_id
@@ -2111,7 +2401,7 @@ echo("\n\n$query\n\n");
2111
  $is_anchor_attrid,
2112
  0,
2113
  scm.shop_entity_id,
2114
- 1
2115
  FROM $categories_temp c
2116
  JOIN $stINch_categories_mapping scm
2117
  ON c.store_category_id = scm.store_category_id
@@ -2139,6 +2429,76 @@ echo("\n\n$query\n\n");
2139
  ON c.store_category_id = scm.store_category_id
2140
  )";
2141
  $this->db_do($q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2142
  }
2143
 
2144
  $this->delete_old_sinch_categories_from_shop();
@@ -2223,8 +2583,8 @@ echo("\n replaceMagentoProductsMultistoreMERGE 1\n");
2223
  $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
2224
  $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
2225
  $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
2226
- $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
2227
- $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
2228
  $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
2229
 
2230
  $_getProductEntityTypeId = $this->_getProductEntityTypeId();
@@ -2530,6 +2890,31 @@ echo("\n replaceMagentoProductsMultistoreMERGE 15\n");
2530
 
2531
 
2532
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2533
  echo("\n replaceMagentoProductsMultistoreMERGE 16\n");
2534
 
2535
  //Indexing products and categories in the shop
@@ -2644,7 +3029,13 @@ echo("\n replaceMagentoProductsMultistoreMERGE 20\n");
2644
 
2645
  $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
2646
  $this->addDescriptions();
2647
- $this->addShortDescriptions();
 
 
 
 
 
 
2648
  $this->addEAN();
2649
  $this->addSpecification();
2650
  $this->addManufacturers();
@@ -2949,7 +3340,7 @@ echo("\n replaceMagentoProductsMultistoreMERGE 36\n");
2949
 
2950
 
2951
 
2952
-
2953
  //Refresh fulltext search
2954
  $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
2955
  $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
@@ -2977,7 +3368,7 @@ $q = "
2977
  LEFT JOIN $catalog_product_website j
2978
  ON a.entity_id = j.product_id
2979
  LEFT JOIN $products_temp f
2980
- ON a.entity_id = f.store_product_id
2981
  )
2982
  ON DUPLICATE KEY UPDATE
2983
  data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
@@ -3005,7 +3396,7 @@ echo("\n\n============================\n$q\n============================\n\n");
3005
  LEFT JOIN $catalog_product_website j
3006
  ON a.entity_id = j.product_id
3007
  LEFT JOIN $products_temp f
3008
- ON a.entity_id = f.store_product_id
3009
  )
3010
  ON DUPLICATE KEY UPDATE
3011
  data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
@@ -3032,7 +3423,7 @@ echo("\n replaceMagentoProductsMultistoreMERGE 37\n");
3032
  ON a.entity_id = e.entity_id
3033
  AND e.attribute_id = $attr_name
3034
  LEFT JOIN $products_temp f
3035
- ON a.entity_id = f.store_product_id
3036
  )
3037
  ON DUPLICATE KEY UPDATE
3038
  data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
@@ -3056,7 +3447,6 @@ echo("\n replaceMagentoProductsMultistoreMERGE 39\n");
3056
  a.store_id,
3057
  a.data_index
3058
  FROM {$catalogsearch_fulltext}_tmp a
3059
- WHERE product_id = a.product_id
3060
  )
3061
  ON DUPLICATE KEY UPDATE
3062
  data_index = a.data_index");
@@ -3066,7 +3456,7 @@ echo("\n replaceMagentoProductsMultistoreMERGE 40\n");
3066
  $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
3067
  //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
3068
  //TODO add something else
3069
-
3070
 
3071
  $this->addRelatedProducts();
3072
  echo("\n replaceMagentoProductsMultistoreMERGE 41\n");
@@ -3124,8 +3514,8 @@ echo("\n replaceMagentoProductsMultistore 1\n");
3124
  $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
3125
  $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
3126
  $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
3127
- $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
3128
- $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
3129
  $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
3130
 
3131
  $_getProductEntityTypeId = $this->_getProductEntityTypeId();
@@ -3320,7 +3710,7 @@ echo("\n replaceMagentoProductsMultistore 9\n");
3320
  echo("\n replaceMagentoProductsMultistore 10\n");
3321
 
3322
 
3323
- $catalog_category_product_for_delete_temp = Mage::getSingleton('core/resource')->getTableName("{$catalog_category_product}_for_delete_temp");
3324
 
3325
  // TEMPORARY
3326
  $this->db_do(" DROP TABLE IF EXISTS $catalog_category_product_for_delete_temp");
@@ -3407,6 +3797,28 @@ echo("\n replaceMagentoProductsMultistore 15\n");
3407
  product_id = cpe.entity_id");
3408
 
3409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3410
 
3411
  echo("\n replaceMagentoProductsMultistore 16\n");
3412
 
@@ -3455,7 +3867,7 @@ echo("\n replaceMagentoProductsMultistore 17\n");
3455
  b.store_id,
3456
  4
3457
  FROM $catalog_category_product a
3458
- JOIN root_cats rc
3459
  ON a.category_id = rc.entity_id
3460
  JOIN $core_store b
3461
  )
@@ -3517,7 +3929,13 @@ echo("\n replaceMagentoProductsMultistore 20\n");
3517
 
3518
  $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
3519
  $this->addDescriptions();
3520
- $this->addShortDescriptions();
 
 
 
 
 
 
3521
  $this->addEAN();
3522
  $this->addSpecification();
3523
  $this->addManufacturers();
@@ -3801,7 +4219,7 @@ echo("\n replaceMagentoProductsMultistore 36\n");
3801
 
3802
 
3803
 
3804
-
3805
  //Refresh fulltext search
3806
  $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
3807
  $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
@@ -3829,7 +4247,7 @@ $q = "
3829
  LEFT JOIN $catalog_product_website j
3830
  ON a.entity_id = j.product_id
3831
  LEFT JOIN $products_temp f
3832
- ON a.entity_id = f.store_product_id
3833
  )
3834
  ON DUPLICATE KEY UPDATE
3835
  data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
@@ -3857,7 +4275,7 @@ echo("\n\n============================\n$q\n============================\n\n");
3857
  LEFT JOIN $catalog_product_website j
3858
  ON a.entity_id = j.product_id
3859
  LEFT JOIN $products_temp f
3860
- ON a.entity_id = f.store_product_id
3861
  )
3862
  ON DUPLICATE KEY UPDATE
3863
  data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
@@ -3884,7 +4302,7 @@ echo("\n replaceMagentoProductsMultistore 37\n");
3884
  ON a.entity_id = e.entity_id
3885
  AND e.attribute_id = $attr_name
3886
  LEFT JOIN $products_temp f
3887
- ON a.entity_id = f.store_product_id
3888
  )
3889
  ON DUPLICATE KEY UPDATE
3890
  data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
@@ -3908,7 +4326,6 @@ echo("\n replaceMagentoProductsMultistore 39\n");
3908
  a.store_id,
3909
  a.data_index
3910
  FROM {$catalogsearch_fulltext}_tmp a
3911
- WHERE product_id = a.product_id
3912
  )
3913
  ON DUPLICATE KEY UPDATE
3914
  data_index = a.data_index");
@@ -3918,7 +4335,7 @@ echo("\n replaceMagentoProductsMultistore 40\n");
3918
  $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
3919
  //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
3920
  //TODO add something else
3921
-
3922
 
3923
  $this->addRelatedProducts();
3924
  echo("\n replaceMagentoProductsMultistore 41\n");
@@ -4039,7 +4456,7 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4039
  )
4040
  VALUES
4041
  (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
4042
- (2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 0, null, null)");
4043
 
4044
  $this->db_do("TRUNCATE $catalog_category_entity_varchar");
4045
  $this->db_do("
@@ -4434,13 +4851,13 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4434
  $attr_include_in_menu,
4435
  0,
4436
  scm.shop_entity_id,
4437
- 1
4438
  FROM $categories_temp c
4439
  JOIN $stINch_categories_mapping scm
4440
  ON c.store_category_id = scm.store_category_id
4441
  )
4442
  ON DUPLICATE KEY UPDATE
4443
- value = 1";
4444
  $this->db_do($q);
4445
 
4446
  $q = "
@@ -4457,13 +4874,13 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4457
  $is_anchor_attrid,
4458
  1,
4459
  scm.shop_entity_id,
4460
- 1
4461
  FROM $categories_temp c
4462
  JOIN $stINch_categories_mapping scm
4463
  ON c.store_category_id = scm.store_category_id
4464
  )
4465
  ON DUPLICATE KEY UPDATE
4466
- value = 1";
4467
  $this->db_do($q);
4468
 
4469
  $q = "
@@ -4480,13 +4897,13 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4480
  $is_anchor_attrid,
4481
  0,
4482
  scm.shop_entity_id,
4483
- 1
4484
  FROM $categories_temp c
4485
  JOIN $stINch_categories_mapping scm
4486
  ON c.store_category_id = scm.store_category_id
4487
  )
4488
  ON DUPLICATE KEY UPDATE
4489
- value = 1";
4490
  $this->db_do($q);
4491
 
4492
  $q = "
@@ -4511,6 +4928,78 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4511
  ON DUPLICATE KEY UPDATE
4512
  value = c.categories_image";
4513
  $this->db_do($q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4514
  }
4515
  else
4516
  {
@@ -4572,7 +5061,7 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4572
  $attr_include_in_menu,
4573
  0,
4574
  scm.shop_entity_id,
4575
- 1
4576
  FROM $categories_temp c
4577
  JOIN $stINch_categories_mapping scm
4578
  ON c.store_category_id = scm.store_category_id
@@ -4593,7 +5082,7 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4593
  $is_anchor_attrid,
4594
  0,
4595
  scm.shop_entity_id,
4596
- 1
4597
  FROM $categories_temp c
4598
  JOIN $stINch_categories_mapping scm
4599
  ON c.store_category_id = scm.store_category_id
@@ -4620,6 +5109,76 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4620
  ON c.store_category_id = scm.store_category_id
4621
  )";
4622
  $this->db_do($q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4623
  }
4624
 
4625
  $this->delete_old_sinch_categories_from_shop();
@@ -4714,6 +5273,45 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4714
  $this->_LOG(' ');
4715
  }
4716
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4717
  #################################################################################################
4718
 
4719
  function ParseEANCodes(){
@@ -4879,11 +5477,79 @@ echo("\n replaceMagentoProductsMultistore 41\n");
4879
  }
4880
  $this->_LOG(" ");
4881
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4882
 
 
 
 
 
 
 
 
4883
  #################################################################################################
4884
 
4885
  function ParseProducts($coincidence){
4886
  echo("\nParseProducts 2\n");
 
 
 
4887
  $parse_file=$this->varDir.FILE_PRODUCTS;
4888
  if(filesize($parse_file)){
4889
  $this->_LOG("Start parse ".FILE_PRODUCTS);
@@ -4902,22 +5568,25 @@ echo("\nParseProducts 2\n");
4902
 
4903
  // $prod_file_str = file_get_contents($parse_file);
4904
  $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
 
4905
  $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
4906
- store_category_product_id int(11),
4907
  store_product_id int(11),
4908
- sinch_product_id int(11),
4909
  product_sku varchar(255),
4910
  product_name varchar(255),
4911
  sinch_manufacturer_id int(11),
4912
- store_category_id int(11),
4913
  main_image_url varchar(255),
4914
  thumb_image_url varchar(255),
4915
  specifications text,
4916
  description text,
4917
  search_cache text,
4918
- spec_characte_u_count int(11),
4919
  description_type varchar(50),
4920
  medium_image_url varchar(255),
 
 
 
 
 
 
4921
  products_date_added datetime default NULL,
4922
  products_last_modified datetime default NULL,
4923
  availability_id_in_stock int(11) default '1',
@@ -4928,12 +5597,45 @@ echo("\nParseProducts 2\n");
4928
  products_viewed int(5) default '0',
4929
  products_seo_url varchar(100) NOT NULL,
4930
  manufacturer_name varchar(255) default NULL,
4931
- KEY(store_category_product_id),
4932
  KEY(store_product_id),
4933
- KEY(sinch_manufacturer_id),
4934
- KEY(store_category_id)
4935
  )DEFAULT CHARSET=utf8
4936
  ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4937
  echo("\nParseProducts 3\n");
4938
  $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv'
4939
  INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
@@ -4941,6 +5643,38 @@ echo("\nParseProducts 3\n");
4941
  OPTIONALLY ENCLOSED BY '\"'
4942
  LINES TERMINATED BY \"\r\n\"
4943
  IGNORE 1 LINES ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4944
  echo("\nParseProducts 4\n");
4945
 
4946
 
@@ -4974,8 +5708,9 @@ echo("\nParseProducts 8\n");
4974
  $this->mapSinchProducts();
4975
  echo("\nParseProducts 9\n");
4976
 
4977
-
4978
-
 
4979
  if (count($coincidence) == 1)
4980
  {
4981
  $this->replaceMagentoProducts();
@@ -5130,8 +5865,6 @@ echo("\nParseProducts 11\n");
5130
  SET number_of_products=".$row['cnt']."
5131
  WHERE id=".$this->current_import_status_statistic_id);
5132
 
5133
- $this->addWeight();
5134
-
5135
  $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
5136
  $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
5137
  TO ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
@@ -5186,41 +5919,179 @@ echo("\nParseProducts 11\n");
5186
 
5187
  }
5188
 
 
5189
 
5190
-
5191
- #################################################################################################
5192
- public function mapSinchProducts(){
5193
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
5194
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
5195
- entity_id int(11) unsigned NOT NULL,
5196
- manufacturer_option_id int(11),
5197
- manufacturer_name varchar(255),
5198
- shop_store_product_id int(11),
5199
- shop_sinch_product_id int(11),
5200
- sku varchar(64) default NULL,
5201
- store_category_product_id int(11),
5202
- store_product_id int(11),
5203
- sinch_product_id int(11),
5204
- product_sku varchar(255),
5205
- sinch_manufacturer_id int(11),
5206
- sinch_manufacturer_name varchar(255),
5207
- KEY entity_id (entity_id),
5208
- KEY manufacturer_option_id (manufacturer_option_id),
5209
- KEY manufacturer_name (manufacturer_name),
5210
- KEY store_product_id (store_product_id),
5211
- KEY sinch_product_id (sinch_product_id),
5212
- KEY sku (sku),
5213
- UNIQUE KEY(entity_id)
5214
  )
5215
- ");
5216
- $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
5217
- LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
5218
- $result = $this->db_do("
5219
- INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
5220
- entity_id,
5221
- sku,
5222
- shop_store_product_id,
5223
- shop_sinch_product_id
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5224
  )(SELECT
5225
  entity_id,
5226
  sku,
@@ -5247,7 +6118,6 @@ echo("\nParseProducts 11\n");
5247
  JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
5248
  ON pmt.sku=p.product_sku
5249
  SET
5250
- pmt.store_category_product_id=p.store_category_product_id,
5251
  pmt.store_product_id=p.store_product_id,
5252
  pmt.sinch_product_id=p.sinch_product_id,
5253
  pmt.product_sku=p.product_sku,
@@ -5517,6 +6387,33 @@ echo("\ndone\n");
5517
  product_id = cpe.entity_id
5518
  ");
5519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5520
  //Indexing products and categories in the shop
5521
  $result = $this->db_do("DELETE ccpi
5522
  FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." ccpi
@@ -5624,7 +6521,13 @@ echo("\ndone\n");
5624
 
5625
  $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
5626
  $this->addDescriptions();
5627
- $this->addShortDescriptions();
 
 
 
 
 
 
5628
  $this->addEAN();
5629
  $this->addSpecification();
5630
  $this->addManufacturers();
@@ -5934,7 +6837,7 @@ echo("\ndone\n");
5934
 
5935
  ");
5936
 
5937
-
5938
  //Refresh fulltext search
5939
  $result = $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp");
5940
  $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS
@@ -5965,7 +6868,7 @@ echo("\ndone\n");
5965
  LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." j
5966
  ON a.entity_id = j.product_id
5967
  LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
5968
- ON a.entity_id = f.store_product_id
5969
  )
5970
  ON DUPLICATE KEY UPDATE
5971
  data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
@@ -5993,7 +6896,7 @@ echo("\ndone\n");
5993
  ON a.entity_id = e.entity_id
5994
  AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
5995
  LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
5996
- ON a.entity_id = f.store_product_id
5997
  )
5998
  ON DUPLICATE KEY UPDATE
5999
  data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
@@ -6025,10 +6928,64 @@ echo("\ndone\n");
6025
  $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_query')." SET is_processed = 0");
6026
  //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
6027
  //TODO add something else
6028
-
6029
  $this->addRelatedProducts();
6030
  }
6031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6032
  #################################################################################################
6033
  function addDescriptions(){
6034
  // product description for all web sites
@@ -6080,8 +7037,127 @@ echo("\ndone\n");
6080
  ");
6081
 
6082
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6083
  }
6084
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6085
  #################################################################################################
6086
  function addShortDescriptions(){
6087
  // product short description for all web sites
@@ -6098,7 +7174,7 @@ echo("\ndone\n");
6098
  " . $this->_getProductAttributeId('short_description'). ",
6099
  w.website,
6100
  a.entity_id,
6101
- '&nbsp;'
6102
  FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6103
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6104
  ON a.store_product_id = b.store_product_id
@@ -6106,7 +7182,7 @@ echo("\ndone\n");
6106
  ON a.store_product_id=w.store_product_id
6107
  )
6108
  ON DUPLICATE KEY UPDATE
6109
- value = '&nbsp;'
6110
  ");
6111
  // product short description for all web sites
6112
  $result = $this->db_do("
@@ -6122,13 +7198,13 @@ echo("\ndone\n");
6122
  " . $this->_getProductAttributeId('short_description'). ",
6123
  0,
6124
  a.entity_id,
6125
- '&nbsp;'
6126
  FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6127
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6128
  ON a.store_product_id = b.store_product_id
6129
  )
6130
  ON DUPLICATE KEY UPDATE
6131
- value = '&nbsp;'
6132
  ");
6133
 
6134
  }
@@ -6162,7 +7238,7 @@ echo("\ndone\n");
6162
  ON e.sinch_product_id=p.sinch_product_id
6163
  SET e.store_product_id=p.store_product_id");
6164
  // product EANs for all web sites
6165
- $result = $this->db_do("
6166
  INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6167
  entity_type_id,
6168
  attribute_id,
@@ -6487,7 +7563,7 @@ echo("\ndone\n");
6487
  }
6488
  #################################################################################################
6489
  function addWeight(){
6490
- // product short description for all web sites
6491
  $result = $this->db_do("
6492
  INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
6493
  entity_type_id,
@@ -6501,17 +7577,17 @@ echo("\ndone\n");
6501
  " . $this->_getProductAttributeId('weight'). ",
6502
  w.website,
6503
  a.entity_id,
6504
- 0
6505
  FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6506
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
6507
  ON a.store_product_id = b.store_product_id
6508
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6509
  ON a.store_product_id=w.store_product_id
6510
  )
6511
  ON DUPLICATE KEY UPDATE
6512
- value = 0
6513
  ");
6514
- // product short description for all web sites
6515
  $result = $this->db_do("
6516
  INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
6517
  entity_type_id,
@@ -6525,19 +7601,239 @@ echo("\ndone\n");
6525
  " . $this->_getProductAttributeId('weight'). ",
6526
  0,
6527
  a.entity_id,
6528
- 0
6529
  FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6530
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
6531
  ON a.store_product_id = b.store_product_id
6532
  )
6533
  ON DUPLICATE KEY UPDATE
6534
- value = 0
6535
 
6536
 
6537
  ");
6538
 
6539
 
6540
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6541
  #################################################################################################
6542
  function replaceMagentoProductsStockPrice(){
6543
  //Add stock
@@ -8229,11 +9525,248 @@ echo("\ndone\n");
8229
 
8230
 
8231
 
8232
- } // class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract
8233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8234
 
8235
 
8236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8237
  ?>
8238
 
8239
 
40
  private $import_run_type = 'MANUAL';
41
  private $_ignore_category_features = false;
42
  private $_ignore_product_features = false;
43
+ private $_ignore_product_related = false;
44
+ private $_ignore_product_categories = false;
45
+ private $_ignore_price_rules = false;
46
+ private $product_file_format = "NEW";
47
  private $_ignore_restricted_values = false;
48
+ private $_categoryMetaTitleAttrId;
49
+ private $_categoryMetadescriptionAttrId;
50
+ private $_categoryDescriptionAttrId;
51
+
52
+
53
  public $php_run_string;
54
+ public $php_run_strings;
55
+
56
  public $price_breaks_filter;
57
 
58
  private $im_type;
66
  $this->import_log_table="stINch_import_log";
67
 
68
  $this->php_run_string=PHP_RUN_STRING;
69
+ $this->php_run_strings=PHP_RUN_STRINGS;
70
+
71
  $this->price_breaks_filter=PRICE_BREAKS;
72
  /*$this->db_connect();
73
  $res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
82
  $this->_LOG("constructor");
83
  $this->files=array(
84
  FILE_CATEGORIES,
85
+ FILE_CATEGORY_TYPES,
86
  FILE_CATEGORIES_FEATURES,
87
  FILE_DISTRIBUTORS,
88
+ FILE_DISTRIBUTORS_STOCK_AND_PRICES,
89
  FILE_EANCODES,
90
  FILE_MANUFACTURERS,
91
  FILE_PRODUCT_FEATURES,
92
+ FILE_PRODUCT_CATEGORIES,
93
  FILE_PRODUCTS,
94
  FILE_RELATED_PRODUCTS,
95
  FILE_RESTRICTED_VALUES,
96
  FILE_STOCK_AND_PRICES,
97
+ FILE_PRODUCTS_PICTURES_GALLERY,
98
+ FILE_PRICE_RULES
99
  );
100
  $this->attributes['manufacturer']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
101
  $this->attributes['name']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
203
  }
204
  #################################################################################################
205
  function run_sinch_import(){
206
+
207
+ $this->_categoryMetaTitleAttrId = $this->_getCategoryAttributeId('meta_title');
208
+ $this->_categoryMetadescriptionAttrId = $this->_getCategoryAttributeId('meta_description');
209
+ $this->_categoryDescriptionAttrId = $this->_getCategoryAttributeId('description');
210
+
211
  $safe_mode_set = ini_get('safe_mode');
212
 
213
  $this->InitImportStatuses('FULL');
237
  $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
238
  exit;
239
  }
240
+ //STP TEST
241
+ //$this->ApplyCustomerGroupPrice();
242
+ //echo $children_cat=$this->get_all_children_cat(6);
243
+
244
+
245
 
246
  if($this->is_imort_not_run()){
247
  try{
254
  $import->UploadFiles();
255
  $import->addImportStatus('Upload Files');
256
 
257
+ echo "Parse Category Types <br>";
258
+ $import->ParseCategoryTypes();
259
+
260
  echo "Parse Categories <br>";
261
  $coincidence = $import->ParseCategories();
262
  $import->addImportStatus('Parse Categories');
274
 
275
  echo "Parse Distributors <br>";
276
  $import->ParseDistributors();
277
+ if($this->product_file_format == "NEW"){
278
+ $this->ParseDistributorsStockAndPrice();
279
+ }
280
  $import->addImportStatus('Parse Distributors');
281
 
 
282
  echo "Parse EAN Codes <br>";
283
  $import->ParseEANCodes();
284
  $import->addImportStatus('Parse EAN Codes');
298
  $import->ParseProductFeatures();
299
  $import->addImportStatus('Parse Product Features');
300
 
301
+ echo "Parse Product Categories <br>";
302
+ $import->ParseProductCategories();
303
 
304
  echo "Parse Products <br>";
305
  $import->ParseProducts($coincidence);
317
  $import->ParseRestrictedValues();
318
  $import->addImportStatus('Parse Restricted Values');
319
 
 
320
  echo "Parse Stock And Prices <br>";
321
  $import->ParseStockAndPrices();
322
  $import->addImportStatus('Parse Stock And Prices');
323
+
324
+ echo "Apply Customer Group Price <br>";
325
+ $import->ParsePriceRules();
326
+ $import->AddPriceRules();
327
+ $import->ApplyCustomerGroupPrice();
328
 
329
  Mage::log("Finish Sinch import", null, $this->_logFile);
330
  echo "Finish Sinch import<br>";
413
  $import->addImportStatus('Stock Price Start Import');
414
  echo "Upload Files <br>";
415
  $this->files=array(
416
+ FILE_STOCK_AND_PRICES,
417
+ FILE_PRICE_RULES
418
  );
419
 
420
  $import->UploadFiles();
425
  $import->ParseStockAndPrices();
426
  $import->addImportStatus('Stock Price Parse Products');
427
 
428
+ echo "Apply Customer Group Price <br>";
429
+ $import->ParsePriceRules();
430
+ $import->AddPriceRules();
431
+ $import->ApplyCustomerGroupPrice();
432
 
433
  Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
434
  echo "Finish Stock & Price Sinch import<br>";
512
  }