stockinthechannel2012 - Version 2.2.0

Version Notes

Version 2.2.0:
* Major update, fixes and improvements, courtesy of Neo

Download this release

Release Info

Developer stockinchannel
Extension stockinthechannel2012
Version 2.2.0
Comparing to
See all releases


Code changes from version 2.1.2 to 2.2.0

app/code/local/Bintime/Sinchimport/Block/Backupbutton.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Sinchimport_Block_Backupbutton extends Mage_Adminhtml_Block_System_Config_Form_Field {
3
+
4
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
5
+ $this->setElement($element);
6
+ $url = $this->getUrl('sinchimport/backup'); //
7
+ $this->setElement($element);
8
+
9
+ $start_import_button = $this->getLayout()->createBlock('adminhtml/widget_button')
10
+ ->setType('button')
11
+ ->setClass('scalable')
12
+ ->setLabel('Backup Now')
13
+ ->setOnClick("setLocation('$url')")
14
+ ->toHtml();
15
+
16
+ $html .= $start_import_button;
17
+
18
+ return $html;
19
+ }
20
+
21
+
22
+ }
app/code/local/Bintime/Sinchimport/Block/Layer/View.php CHANGED
@@ -40,7 +40,7 @@ class Bintime_Sinchimport_Block_Layer_View extends Mage_Catalog_Block_Layer_View
40
  /* ------------ */
41
  foreach ($this->filterableFeatures as $feature) {
42
  $filters[] = $this->getChild('feature_' . $feature['feature_id'] . '_filter');
43
- }
44
  /* ------------ */
45
 
46
  return $filters;
40
  /* ------------ */
41
  foreach ($this->filterableFeatures as $feature) {
42
  $filters[] = $this->getChild('feature_' . $feature['feature_id'] . '_filter');
43
+ }
44
  /* ------------ */
45
 
46
  return $filters;
app/code/local/Bintime/Sinchimport/Model/Backup.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ ini_set('memory_limit','256M');
3
+ $dir = Mage::getBaseDir('code')."/local/Bintime/Sinchimport/Model";//dirname(__FILE__);
4
+ require_once ($dir.'/config.php');
5
+
6
+ class Bintime_Sinchimport_Model_Backup extends Mage_Core_Model_Abstract {
7
+ var $connection, $db;
8
+
9
+ function __construct() {
10
+ $this->connection=$this->db_connect();
11
+ $this->backupProductIds();
12
+ $this->backupCategoryIds();
13
+ }
14
+
15
+ private function backupProductIds() {
16
+ $this->db_do("TRUNCATE ".Mage::getSingleton('core/resource')->getTableName('sinch_product_backup'));
17
+ $result = $this->db_do("
18
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('sinch_product_backup')." (
19
+ entity_id,
20
+ sku,
21
+ store_product_id,
22
+ sinch_product_id
23
+ )(SELECT
24
+ entity_id,
25
+ sku,
26
+ store_product_id,
27
+ sinch_product_id
28
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')."
29
+ )
30
+ ");
31
+ }
32
+
33
+ private function backupCategoryIds() {
34
+ $this->db_do("TRUNCATE ".Mage::getSingleton('core/resource')->getTableName('sinch_category_backup'));
35
+ $result = $this->db_do("
36
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('sinch_category_backup')." (
37
+ entity_id,
38
+ entity_type_id,
39
+ attribute_set_id,
40
+ parent_id,
41
+ store_category_id,
42
+ parent_store_category_id
43
+ )(SELECT
44
+ entity_id,
45
+ entity_type_id,
46
+ attribute_set_id,
47
+ parent_id,
48
+ store_category_id,
49
+ parent_store_category_id
50
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
51
+ )
52
+ ");
53
+ }
54
+
55
+ ////// Utility functions
56
+ private function db_connect() {
57
+ $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
58
+ $dbConn = mysqli_init();
59
+ mysqli_options($dbConn, MYSQLI_OPT_LOCAL_INFILE, true);
60
+ if (mysqli_real_connect($dbConn, $dbConf->host, $dbConf->username, $dbConf->password)) {
61
+ $this->db = $dbConn;
62
+ if(!mysqli_select_db($this->db, $dbConf->dbname)) {
63
+ die("Can't select the database: " . mysqli_error($this->db));
64
+ }
65
+ } else {
66
+ die("Could not connect: " . mysqli_error($this->db));
67
+ }
68
+
69
+ }
70
+
71
+ private function db_do($query) {
72
+ $result = mysqli_query($this->db, $query) or die("Query failed: " . mysqli_error($this->db));
73
+ if (!$result) {
74
+ throw new Exception("Invalid query: $sql\n" . mysqli_error($this->db));
75
+ } else {
76
+ return $result;
77
+ }
78
+ return $result;
79
+ }
80
+ }
app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Feature.php CHANGED
@@ -35,7 +35,7 @@ class Bintime_Sinchimport_Model_Layer_Filter_Feature extends Mage_Catalog_Model_
35
  $attribute = $this->getAttributeModel();
36
  return $attribute['name'];
37
  }
38
-
39
  /**
40
  * Retrieve resource instance
41
  *
@@ -75,14 +75,14 @@ class Bintime_Sinchimport_Model_Layer_Filter_Feature extends Mage_Catalog_Model_
75
  if (is_array($filter)) {
76
  return $this;
77
  }
78
-
79
  $text = $this->_getOptionText($filter);
80
  if ($filter && $text) {
81
  $this->_getResource()->applyFilterToCollection($this, $filter);
82
  $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
83
  $this->_items = array();
84
  }
85
-
86
  return $this;
87
  }
88
 
@@ -110,7 +110,7 @@ class Bintime_Sinchimport_Model_Layer_Filter_Feature extends Mage_Catalog_Model_
110
  $feature = $this->getAttributeModel();
111
  $this->_requestVar = 'feature_' . $feature['category_feature_id'];
112
  $limitDirection = isset($feature['limit_direction']) ? $feature['limit_direction'] : 0;
113
-
114
  $data = array();
115
  $options = explode("\n", $feature['restricted_values']);
116
  if (count($options) == 0) {
@@ -118,7 +118,7 @@ class Bintime_Sinchimport_Model_Layer_Filter_Feature extends Mage_Catalog_Model_
118
  return $data;
119
  }
120
  if (isset($feature['order_val']) && $feature['order_val'] == '2') {
121
- $options = array_reverse($options);
122
  }
123
  if ($limitDirection != self::LESS && $limitDirection != self::GREATER) {
124
 
@@ -151,7 +151,7 @@ class Bintime_Sinchimport_Model_Layer_Filter_Feature extends Mage_Catalog_Model_
151
  for ($i = 0; $i < $oCount -1; $i++) {
152
  $intervals[$i]['low'] = $options[$i];
153
  $intervals[$i]['high'] = $options[$i +1];
154
- }
155
  }
156
  //FIXME: this is ugly
157
  if ($feature['order_val'] == '2') {
@@ -224,25 +224,25 @@ class Bintime_Sinchimport_Model_Layer_Filter_Feature extends Mage_Catalog_Model_
224
  return $data;
225
  }
226
 
227
- public function getOrderValues($category_feature_id,$categoryId)
228
  {
229
- $select = "
230
- SELECT COUNT(e.entity_id) AS count
231
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." AS e
232
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." AS cat_index
233
- ON cat_index.product_id=e.entity_id
234
- AND cat_index.store_id='1'
235
- AND cat_index.visibility IN(2, 4)
236
- AND cat_index.category_id='".$categoryId."'
237
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
238
- ON price_index.entity_id = e.entity_id
239
- AND price_index.website_id = '1'
240
- AND price_index.customer_group_id = 0
241
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_feature_'.$feature['category_feature_id'])." AS idx_".$category_feature_id."
242
- ON idx_".$category_feature_id.".entity_id = e.icecat_product_id;
243
- ";
244
-
245
- return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select);
246
- }
247
-
248
  }
35
  $attribute = $this->getAttributeModel();
36
  return $attribute['name'];
37
  }
38
+
39
  /**
40
  * Retrieve resource instance
41
  *
75
  if (is_array($filter)) {
76
  return $this;
77
  }
78
+
79
  $text = $this->_getOptionText($filter);
80
  if ($filter && $text) {
81
  $this->_getResource()->applyFilterToCollection($this, $filter);
82
  $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
83
  $this->_items = array();
84
  }
85
+
86
  return $this;
87
  }
88
 
110
  $feature = $this->getAttributeModel();
111
  $this->_requestVar = 'feature_' . $feature['category_feature_id'];
112
  $limitDirection = isset($feature['limit_direction']) ? $feature['limit_direction'] : 0;
113
+
114
  $data = array();
115
  $options = explode("\n", $feature['restricted_values']);
116
  if (count($options) == 0) {
118
  return $data;
119
  }
120
  if (isset($feature['order_val']) && $feature['order_val'] == '2') {
121
+ $options = array_reverse($options);
122
  }
123
  if ($limitDirection != self::LESS && $limitDirection != self::GREATER) {
124
 
151
  for ($i = 0; $i < $oCount -1; $i++) {
152
  $intervals[$i]['low'] = $options[$i];
153
  $intervals[$i]['high'] = $options[$i +1];
154
+ }
155
  }
156
  //FIXME: this is ugly
157
  if ($feature['order_val'] == '2') {
224
  return $data;
225
  }
226
 
227
+ /*public function getOrderValues($category_feature_id,$categoryId)
228
  {
229
+ $select = "
230
+ SELECT COUNT(e.entity_id) AS count
231
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." AS e
232
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." AS cat_index
233
+ ON cat_index.product_id=e.entity_id
234
+ AND cat_index.store_id='1'
235
+ AND cat_index.visibility IN(2, 4)
236
+ AND cat_index.category_id='".$categoryId."'
237
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
238
+ ON price_index.entity_id = e.entity_id
239
+ AND price_index.website_id = '1'
240
+ AND price_index.customer_group_id = 0
241
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_feature_'.$feature['category_feature_id'])." AS idx_".$category_feature_id."
242
+ ON idx_".$category_feature_id.".entity_id = e.icecat_product_id;
243
+ ";
244
+
245
+ return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchCol($select);
246
+ }*/
247
+
248
  }
app/code/local/Bintime/Sinchimport/Model/Layer/Filter/Price.php CHANGED
@@ -142,10 +142,13 @@ class Bintime_Sinchimport_Model_Layer_Filter_Price extends Mage_Catalog_Model_La
142
  list($minPrice, $maxPrice) = $price_range_value;
143
  if(is_numeric($minPrice) && (is_numeric($maxPrice) || $maxPrice=='*')){
144
  $count=$this->_getResource()->getCountMinMaxPrice($this, $minPrice, $maxPrice);
 
 
145
  if($count){
146
  $data[] = array(
147
  'label' => $this->_renderItemLabelMinMaxPrice($minPrice, $maxPrice),
148
  'value' =>$price_range_value,
 
149
  'count' => $count,
150
  );
151
  }
142
  list($minPrice, $maxPrice) = $price_range_value;
143
  if(is_numeric($minPrice) && (is_numeric($maxPrice) || $maxPrice=='*')){
144
  $count=$this->_getResource()->getCountMinMaxPrice($this, $minPrice, $maxPrice);
145
+ $fromPrice = $minPrice;
146
+ $toPrice = ($maxPrice == '*') ? '' : ($maxPrice);
147
  if($count){
148
  $data[] = array(
149
  'label' => $this->_renderItemLabelMinMaxPrice($minPrice, $maxPrice),
150
  'value' =>$price_range_value,
151
+ 'value' =>$minPrice . '-' . $maxPrice,
152
  'count' => $count,
153
  );
154
  }
app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php CHANGED
@@ -3,11 +3,11 @@
3
  class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mage_Core_Model_Mysql4_Abstract
4
  {
5
  protected $resultTable = 'SinchFilterResult';
6
-
7
  protected static $lastResultTable = false;
8
 
9
  protected $filterAplied = false;
10
-
11
  /**
12
  * Initialize connection and define main table name
13
  *
@@ -25,7 +25,7 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
25
  $id = (int)$id;
26
  return $tablePrefix . $this->resultTable . "_$id";
27
  break;
28
-
29
  case 'search':
30
  return $tablePrefix . $this->searchTable;
31
  break;
@@ -55,6 +55,12 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
55
  $cfid = $feature['category_feature_id'];
56
  }
57
  $resultTable = $this->_getTableName('result', $cfid);
 
 
 
 
 
 
58
  //TODO: this table must be temporary
59
  $sql = "
60
  CREATE TABLE IF NOT EXISTS `{$resultTable}`(
@@ -100,7 +106,7 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
100
  return $resultTable;
101
  }
102
 
103
-
104
  /**
105
  * Apply attribute filter to product collection
106
  *
@@ -113,7 +119,7 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
113
  Varien_Profiler::start(__METHOD__);
114
  $searchTable = $this->_prepareSearch($filter, $value);
115
  self::$lastResultTable = $searchTable;
116
-
117
  $collection = $filter->getLayer()->getProductCollection();
118
  $feature = $filter->getAttributeModel();
119
  $connection = $this->_getReadAdapter();
@@ -140,45 +146,34 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
140
 
141
  // clone select from collection with filters
142
  $select = clone $filter->getLayer()->getProductCollection()->getSelect();
143
-
144
  // reset columns, order and limitation conditions
145
  $select->reset(Zend_Db_Select::COLUMNS);
146
  $select->reset(Zend_Db_Select::ORDER);
147
  $select->reset(Zend_Db_Select::LIMIT_COUNT);
148
  $select->reset(Zend_Db_Select::LIMIT_OFFSET);
 
149
  $connection = $this->_getReadAdapter();
150
  $feature = $filter->getAttributeModel();
151
- $tableAlias = 'idx_' . $feature['category_feature_id'];
152
 
153
- $conditions = array(
154
- "{$tableAlias}.entity_id = e.entity_id",
155
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
156
- );
157
-
158
  $select->joinInner(
159
- array($tableAlias => $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id'])),
160
- join(' AND ', $conditions),
161
- array('value', 'count' => "COUNT(e.entity_id)")
162
- )
163
- ->group("{$tableAlias}.value");
164
-
165
- $tablePattern = $this->_getTableName('stINch_products_feature_'.$feature['category_feature_id']);
166
- $query = "SHOW TABLES LIKE '$tablePattern'";
167
- $featureTables = $connection->fetchCol($query);
168
- $presentFeatures = array();
169
- foreach($featureTables as $t) {
170
- if (preg_match("#$tablePattern#", $t, $matches)) {
171
- $table_feat_exist=true;
172
- }
173
- }
174
 
175
  Varien_Profiler::stop(__METHOD__);
176
- if($table_feat_exist){
177
- return $connection->fetchPairs($select);
178
- }else{
179
- return null;
180
- }
181
-
182
  }
183
 
184
  public function getIntervalsCount($filter, $interval)
@@ -196,26 +191,33 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
196
 
197
  $connection = $this->_getReadAdapter();
198
  $feature = $filter->getAttributeModel();
199
- $tableAlias = 'idx_' . $feature['category_feature_id'];
200
-
201
- $conditions = array(
202
- "{$tableAlias}.entity_id = e.entity_id",
203
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
204
- );
205
-
206
  $select->joinInner(
207
- array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
208
- join(' AND ', $conditions),
209
- array('count' => "COUNT(e.entity_id)")
210
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  if (isset($interval['low'], $interval['high'])) {
212
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
213
  }
214
  else if (isset($interval['low'])) {
215
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
216
  }
217
  else if (isset($interval['high'])) {
218
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
219
  }
220
  $count = $connection->fetchOne($select);
221
  Varien_Profiler::stop(__METHOD__);
@@ -237,26 +239,34 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
237
 
238
  $connection = $this->_getReadAdapter();
239
  $feature = $filter->getAttributeModel();
240
- $tableAlias = 'idx_' . $feature['category_feature_id'];
241
-
242
- $conditions = array(
243
- "{$tableAlias}.entity_id = e.entity_id",
244
- //"{$tableAlias}.category_feature_id = {$feature['category_feature_id']}",
245
- );
246
 
247
  $select->joinInner(
248
- array($tableAlias => $this->_getTableName('icecat_products_feature_'.$feature['category_feature_id'])),
249
- join(' AND ', $conditions),
250
- array('count' => "COUNT(e.entity_id)")
251
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  if (isset($interval['low'], $interval['high'])) {
253
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low'])->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
254
  }
255
  else if (isset($interval['low'])) {
256
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) >= ?', $interval['low']);
257
  }
258
  else if (isset($interval['high'])) {
259
- $select->where('CAST('.$tableAlias.'.value AS SIGNED) < ?', $interval['high']);
260
  }
261
  $count = $connection->fetchOne($select);
262
 
@@ -264,8 +274,6 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
264
  return $count;
265
  }
266
 
267
-
268
-
269
  /*
270
  * INDEXES FOLLOW.
271
  */
@@ -277,21 +285,36 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
277
  */
278
  public function reindex($observer)
279
  {
280
- $this->splitProductsFeature();
281
  }
282
-
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  /**
285
- * Разбивает таблицу icecat_product_feature на таблицы вида icecat_product_feature_%category_feature_id% для каждой фичи.
286
- *
287
- */
288
  public function splitProductsFeature()
289
  {
290
  Mage::log(__METHOD__ . " start at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
291
  $featureIds = $this->getProductFeatures4indexig();
292
 
293
  $resource = Mage::getSingleton('core/resource');
294
- // $tProudctsFeature = $resource->getTableName("icecat_products_feature");
295
  $connection = $this->_getWriteAdapter();
296
 
297
  //удаление таблиц с фичами не используемыми больше для навигации.
@@ -313,49 +336,48 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
313
  $dropSql = "DROP TABLE " . implode(',', $features2delete);
314
  $connection->exec($dropSql);
315
  }
316
- //
317
-
318
  //Создание таблиц с фичами используемыми в навигации.
319
  $i = 0; $storeId = Mage::app()->getStore()->getId(); $websiteId = Mage::app()->getStore(true)->getWebsite()->getId();
320
  foreach ($featureIds as $featureId) {
321
  $tFeature = $resource->getTableName("stINch_products_feature_$featureId");
322
- $query = "DROP TABLE IF EXISTS $tFeature";
323
- $connection->exec($query);
324
 
325
  $query = "CREATE TABLE IF NOT EXISTS $tFeature (
326
- `entity_id` int(11) default NULL,
327
- `feature_id` int(11) NOT NULL,
328
- `product_id` int(11) default NULL,
329
- `category_feature_id` int(11) default NULL,
330
- `value` text,
331
- `presentation_value` text,
332
- INDEX (`feature_id`),
333
- KEY `category_feature_id` (`category_feature_id`)
334
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8
335
  ";
336
  $connection->exec($query);
337
 
338
  $query = "TRUNCATE TABLE $tFeature";
339
  $connection->exec($query);
340
 
341
- /*$query = "
342
  INSERT INTO $tFeature (feature_id, product_id, category_feature_id, value, presentation_value)
343
  SELECT feature_id, product_id, category_feature_id, value, presentation_value FROM $tProudctsFeature
344
  WHERE category_feature_id = $featureId
345
- ";*/
346
  $query = "
347
  REPLACE INTO $tFeature (entity_id,feature_id, product_id, category_feature_id, value, presentation_value)
348
  SELECT E.entity_id, RV.category_feature_id,E.entity_id, RV.category_feature_id, RV.text , RV.text
349
  FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." E
350
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." PCind
351
  ON (E.entity_id = PCind.product_id AND PCind.store_id='{$storeId}' AND PCind.visibility IN(2,4))
352
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
353
  ON price_index.entity_id = E.entity_id AND price_index.website_id = '{$websiteId}' AND price_index.customer_group_id = 0
354
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." PR
355
  ON (PR.store_product_id = E.store_product_id)
356
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." PF
357
  ON (PR.sinch_product_id = PF.sinch_product_id )
358
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." RV
359
  ON (PF.restricted_value_id=RV.restricted_value_id AND RV.category_feature_id= $featureId)
360
  GROUP BY E.entity_id;
361
  ";
@@ -364,11 +386,6 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
364
  Mage::log(__METHOD__ . " end at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
365
  }
366
 
367
- /**
368
- * Список фич подлежащих индексации.
369
- *
370
- * @return array
371
- */
372
  private function getProductFeatures4indexig()
373
  {
374
  $connection = $this->_getReadAdapter();
@@ -378,4 +395,5 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
378
 
379
  return $connection->fetchCol($query);
380
  }
 
381
  }
3
  class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mage_Core_Model_Mysql4_Abstract
4
  {
5
  protected $resultTable = 'SinchFilterResult';
6
+
7
  protected static $lastResultTable = false;
8
 
9
  protected $filterAplied = false;
10
+
11
  /**
12
  * Initialize connection and define main table name
13
  *
25
  $id = (int)$id;
26
  return $tablePrefix . $this->resultTable . "_$id";
27
  break;
28
+
29
  case 'search':
30
  return $tablePrefix . $this->searchTable;
31
  break;
55
  $cfid = $feature['category_feature_id'];
56
  }
57
  $resultTable = $this->_getTableName('result', $cfid);
58
+ // Toàn Handsome đã thêm đoạn code này để kiểm tra bảng dữ liệu đã tồn tại hay chưa
59
+ $result = $connection->fetchPairs("SHOW TABLES LIKE '$resultTable'");
60
+ if ($result) {
61
+ return $resultTable;
62
+ }
63
+
64
  //TODO: this table must be temporary
65
  $sql = "
66
  CREATE TABLE IF NOT EXISTS `{$resultTable}`(
106
  return $resultTable;
107
  }
108
 
109
+
110
  /**
111
  * Apply attribute filter to product collection
112
  *
119
  Varien_Profiler::start(__METHOD__);
120
  $searchTable = $this->_prepareSearch($filter, $value);
121
  self::$lastResultTable = $searchTable;
122
+
123
  $collection = $filter->getLayer()->getProductCollection();
124
  $feature = $filter->getAttributeModel();
125
  $connection = $this->_getReadAdapter();
146
 
147
  // clone select from collection with filters
148
  $select = clone $filter->getLayer()->getProductCollection()->getSelect();
149
+
150
  // reset columns, order and limitation conditions
151
  $select->reset(Zend_Db_Select::COLUMNS);
152
  $select->reset(Zend_Db_Select::ORDER);
153
  $select->reset(Zend_Db_Select::LIMIT_COUNT);
154
  $select->reset(Zend_Db_Select::LIMIT_OFFSET);
155
+
156
  $connection = $this->_getReadAdapter();
157
  $feature = $filter->getAttributeModel();
158
+ $featureId = $feature['category_feature_id'];
159
 
 
 
 
 
 
160
  $select->joinInner(
161
+ array('sp' => $this->_getTableName('stINch_products')),
162
+ "sp.store_product_id = e.store_product_id",
163
+ array()
164
+ )->joinInner(
165
+ array('spf' => $this->_getTableName('stINch_product_features')),
166
+ "spf.sinch_product_id = e.sinch_product_id",
167
+ array()
168
+ )->joinInner(
169
+ array('srv' => $this->_getTableName('stINch_restricted_values')),
170
+ "spf.restricted_value_id = srv.restricted_value_id AND srv.category_feature_id = $featureId",
171
+ array('value' => 'srv.text', 'count' => 'COUNT(e.entity_id)')
172
+ )
173
+ ->group("srv.text");
 
 
174
 
175
  Varien_Profiler::stop(__METHOD__);
176
+ return $connection->fetchPairs($select);
 
 
 
 
 
177
  }
178
 
179
  public function getIntervalsCount($filter, $interval)
191
 
192
  $connection = $this->_getReadAdapter();
193
  $feature = $filter->getAttributeModel();
 
 
 
 
 
 
 
194
  $select->joinInner(
195
+ array('spf' => $this->_getTableName('stINch_product_features')),
196
+ "spf.sinch_product_id = e.sinch_product_id",
197
+ array()
198
+ )->joinLeft(
199
+ array('srv' => $this->_getTableName('stINch_restricted_values')),
200
+ "srv.restricted_value_id = spf.restricted_value_id",
201
+ array('value' => 'srv.text')
202
+ )->joinLeft(
203
+ array('scf' => $this->_getTableName('stINch_categories_features')),
204
+ "scf.category_feature_id = srv.category_feature_id",
205
+ array()
206
+ )->joinLeft(
207
+ array('scm' => $this->_getTableName('stINch_categories_mapping')),
208
+ "scm.shop_store_category_id = scf.store_category_id",
209
+ array('count' => "COUNT(e.entity_id)")
210
+ )
211
+ ->where('srv.category_feature_id = ?', $feature['category_feature_id']);
212
+
213
  if (isset($interval['low'], $interval['high'])) {
214
+ $select->where('CAST(srv.text AS SIGNED) >= ?', $interval['low'])->where('CAST(srv.text AS SIGNED) < ?', $interval['high']);
215
  }
216
  else if (isset($interval['low'])) {
217
+ $select->where('CAST(srv.text AS SIGNED) >= ?', $interval['low']);
218
  }
219
  else if (isset($interval['high'])) {
220
+ $select->where('CAST(srv.text AS SIGNED) < ?', $interval['high']);
221
  }
222
  $count = $connection->fetchOne($select);
223
  Varien_Profiler::stop(__METHOD__);
239
 
240
  $connection = $this->_getReadAdapter();
241
  $feature = $filter->getAttributeModel();
 
 
 
 
 
 
242
 
243
  $select->joinInner(
244
+ array('spf' => $this->_getTableName('stINch_product_features')),
245
+ "spf.sinch_product_id = e.sinch_product_id",
246
+ array()
247
+ )->joinLeft(
248
+ array('srv' => $this->_getTableName('stINch_restricted_values')),
249
+ "srv.restricted_value_id = spf.restricted_value_id",
250
+ array('value' => 'srv.text')
251
+ )->joinLeft(
252
+ array('scf' => $this->_getTableName('stINch_categories_features')),
253
+ "scf.category_feature_id = srv.category_feature_id",
254
+ array()
255
+ )->joinLeft(
256
+ array('scm' => $this->_getTableName('stINch_categories_mapping')),
257
+ "scm.shop_store_category_id = scf.store_category_id",
258
+ array('count' => "COUNT(e.entity_id)")
259
+ )
260
+ ->where('srv.category_feature_id = ?', $feature['category_feature_id']);
261
+
262
  if (isset($interval['low'], $interval['high'])) {
263
+ $select->where('CAST(srv.text AS SIGNED) >= ?', $interval['low'])->where('CAST(srv.text AS SIGNED) < ?', $interval['high']);
264
  }
265
  else if (isset($interval['low'])) {
266
+ $select->where('CAST(srv.text AS SIGNED) >= ?', $interval['low']);
267
  }
268
  else if (isset($interval['high'])) {
269
+ $select->where('CAST(srv.text AS SIGNED) < ?', $interval['high']);
270
  }
271
  $count = $connection->fetchOne($select);
272
 
274
  return $count;
275
  }
276
 
 
 
277
  /*
278
  * INDEXES FOLLOW.
279
  */
285
  */
286
  public function reindex($observer)
287
  {
288
+ $this->dropFeatureResultTables();
289
  }
 
290
 
291
+ public function dropFeatureResultTables()
292
+ {
293
+ $connection = $this->_getWriteAdapter();
294
+ $dbName = Mage::getConfig()->getResourceConnectionConfig('core_setup')->dbname;
295
+ $filterResultTablePrefix = $this->_getTableName('SinchFilterResult_');
296
+ $dropSql = "
297
+ SET GROUP_CONCAT_MAX_LEN=10000;
298
+ SET @tbls = (SELECT GROUP_CONCAT(TABLE_NAME)
299
+ FROM information_schema.TABLES
300
+ WHERE TABLE_SCHEMA = '$dbName' AND TABLE_NAME LIKE '$filterResultTablePrefix%');
301
+ SET @delStmt = CONCAT('DROP TABLE ', @tbls);
302
+ PREPARE stmt FROM @delStmt;
303
+ EXECUTE stmt;
304
+ DEALLOCATE PREPARE stmt;
305
+ ";
306
+ $connection->exec($dropSql);
307
+ }
308
+
309
+ // Toàn Handsome đã rào đoạn mã này
310
  /**
 
 
 
311
  public function splitProductsFeature()
312
  {
313
  Mage::log(__METHOD__ . " start at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
314
  $featureIds = $this->getProductFeatures4indexig();
315
 
316
  $resource = Mage::getSingleton('core/resource');
317
+ //$tProudctsFeature = $resource->getTableName("icecat_products_feature");
318
  $connection = $this->_getWriteAdapter();
319
 
320
  //удаление таблиц с фичами не используемыми больше для навигации.
336
  $dropSql = "DROP TABLE " . implode(',', $features2delete);
337
  $connection->exec($dropSql);
338
  }
339
+
 
340
  //Создание таблиц с фичами используемыми в навигации.
341
  $i = 0; $storeId = Mage::app()->getStore()->getId(); $websiteId = Mage::app()->getStore(true)->getWebsite()->getId();
342
  foreach ($featureIds as $featureId) {
343
  $tFeature = $resource->getTableName("stINch_products_feature_$featureId");
344
+ $query = "DROP TABLE IF EXISTS $tFeature";
345
+ $connection->exec($query);
346
 
347
  $query = "CREATE TABLE IF NOT EXISTS $tFeature (
348
+ `entity_id` int(11) default NULL,
349
+ `feature_id` int(11) NOT NULL,
350
+ `product_id` int(11) default NULL,
351
+ `category_feature_id` int(11) default NULL,
352
+ `value` text,
353
+ `presentation_value` text,
354
+ INDEX (`feature_id`),
355
+ KEY `category_feature_id` (`category_feature_id`)
356
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8
357
  ";
358
  $connection->exec($query);
359
 
360
  $query = "TRUNCATE TABLE $tFeature";
361
  $connection->exec($query);
362
 
363
+ $query = "
364
  INSERT INTO $tFeature (feature_id, product_id, category_feature_id, value, presentation_value)
365
  SELECT feature_id, product_id, category_feature_id, value, presentation_value FROM $tProudctsFeature
366
  WHERE category_feature_id = $featureId
367
+ ";
368
  $query = "
369
  REPLACE INTO $tFeature (entity_id,feature_id, product_id, category_feature_id, value, presentation_value)
370
  SELECT E.entity_id, RV.category_feature_id,E.entity_id, RV.category_feature_id, RV.text , RV.text
371
  FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." E
372
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." PCind
373
  ON (E.entity_id = PCind.product_id AND PCind.store_id='{$storeId}' AND PCind.visibility IN(2,4))
374
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
375
  ON price_index.entity_id = E.entity_id AND price_index.website_id = '{$websiteId}' AND price_index.customer_group_id = 0
376
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." PR
377
  ON (PR.store_product_id = E.store_product_id)
378
  INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." PF
379
  ON (PR.sinch_product_id = PF.sinch_product_id )
380
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." RV
381
  ON (PF.restricted_value_id=RV.restricted_value_id AND RV.category_feature_id= $featureId)
382
  GROUP BY E.entity_id;
383
  ";
386
  Mage::log(__METHOD__ . " end at ". date('d-m-Y H:i:s'), null, 'sinchlayered.log');
387
  }
388
 
 
 
 
 
 
389
  private function getProductFeatures4indexig()
390
  {
391
  $connection = $this->_getReadAdapter();
395
 
396
  return $connection->fetchCol($query);
397
  }
398
+ */
399
  }
app/code/local/Bintime/Sinchimport/Model/Sinch.php CHANGED
@@ -1,19 +1,23 @@
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;
@@ -21,10 +25,10 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
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;
@@ -38,37 +42,32 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
38
  private $_categoryDefault_attribute_set_id;
39
  private $_root_cat;
40
  private $import_run_type = 'MANUAL';
41
- private $_ignore_category_features = false;
42
- private $_ignore_product_features = false;
43
- private $_ignore_product_related = false;
44
  private $_ignore_product_categories = false;
45
- private $_ignore_price_rules = false;
 
46
  private $product_file_format = "NEW";
47
- private $_ignore_restricted_values = false;
48
  private $_categoryMetaTitleAttrId;
49
  private $_categoryMetadescriptionAttrId;
50
  private $_categoryDescriptionAttrId;
51
-
52
-
53
- public $php_run_string;
54
- public $php_run_strings;
55
-
56
- public $price_breaks_filter;
57
-
58
- private $im_type;
59
 
60
  #################################################################################################
61
 
62
- function __construct(){
 
63
 
64
- $this->import_status_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status');
65
- $this->import_status_statistic_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic');
66
- $this->import_log_table="stINch_import_log";
67
 
68
- $this->php_run_string=PHP_RUN_STRING;
69
- $this->php_run_strings=PHP_RUN_STRINGS;
70
 
71
- $this->price_breaks_filter=PRICE_BREAKS;
72
  /*$this->db_connect();
73
  $res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
74
  $row = mysqli_fetch_assoc($res);
@@ -76,179 +75,184 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
76
  */
77
  $this->varDir = TEMPORARY_DIRECTORY_FOR_STORING_FILES;
78
  $this->shellDir = SHELL_DIRECTORY_FOR_INDEXER;
79
- $this->connection=$this->db_connect();
80
  $this->createTemporaryImportDerictory();
81
- $this->_logFile="Sinch.log";
82
- $this->_LOG("constructor");
83
- $this->files=array(
84
- FILE_CATEGORIES,
85
- FILE_CATEGORY_TYPES,
86
- FILE_CATEGORIES_FEATURES,
87
- FILE_DISTRIBUTORS,
88
- FILE_DISTRIBUTORS_STOCK_AND_PRICES,
89
- FILE_EANCODES,
90
- FILE_MANUFACTURERS,
91
- FILE_PRODUCT_FEATURES,
92
- FILE_PRODUCT_CATEGORIES,
93
- FILE_PRODUCTS,
94
- FILE_RELATED_PRODUCTS,
95
- FILE_RESTRICTED_VALUES,
96
- FILE_STOCK_AND_PRICES,
97
- FILE_PRODUCTS_PICTURES_GALLERY,
98
- FILE_PRICE_RULES
99
- );
100
- $this->attributes['manufacturer']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
101
- $this->attributes['name']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
102
- $this->attributes['is_active']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('is_active')->getFirstItem()->getId();
103
- $this->attributes['include_in_menu']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('include_in_menu')->getFirstItem()->getId();
104
- $this->attributes['url_key']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('url_key')->getFirstItem()->getId();
105
- $this->attributes['display_mode']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('display_mode')->getFirstItem()->getId();
106
- $this->attributes['status']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('status')->getFirstItem()->getId();
107
- $this->attributes['visibility']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('visibility')->getFirstItem()->getId();
108
- $this->attributes['price']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('price')->getFirstItem()->getId();
109
- $this->attributes['cost']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('cost')->getFirstItem()->getId();
110
- $this->attributes['weight']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('weight')->getFirstItem()->getId();
111
- $this->attributes['tax_class_id']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('tax_class_id')->getFirstItem()->getId();
 
112
 
113
  $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
114
  // if($dataConf['field_terminated_char']){
115
- // $this->field_terminated_char=$dataConf['field_terminated_char'];
116
- // }else{
117
- $this->field_terminated_char=DEFAULT_FILE_TERMINATED_CHAR;
118
  // }
119
- // $attributeOptions = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getSource()->getAllOptions(false);
120
  // echo "<pre>"; print_r($attributeOptions); echo "</pre>";
121
  }
122
 
123
  #################################################################################################
124
- function cron_start_import(){
125
- $this->_LOG("Start import from cron");
126
- $start_hr=Mage::getStoreConfig('sinchimport_root/sinch_cron/sinch_cron_time');
127
- $now_hr=date('H');
128
- $this->_LOG("Now $now_hr hr, scheduler time is $start_hr hr");
129
 
130
- if($start_hr==$now_hr){
131
- $this->run_sinch_import();
132
- }else{
133
- $this->_LOG(" it's NOT time for SINCH ");
 
 
 
 
 
 
 
 
 
134
  }
135
 
136
- $this->_LOG("Finish import from cron");
137
-
138
  }
 
139
  ################################################################################################
140
- function cron_start_full_import(){
141
- $this->import_run_type='CRON';
142
- $this->run_sinch_import();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  }
 
144
  ################################################################################################
145
- function cron_start_stock_price_import(){
146
- $this->import_run_type='CRON';
147
- $this->run_stock_price_sinch_import();
148
- }
149
- #################################################################################################
150
- function is_imort_not_run(){
151
- $q="SELECT IS_FREE_LOCK('sinchimport') as getlock";
152
- $quer=$this->db_do($q);
153
- $row=mysqli_fetch_array($quer);
154
- return $row['getlock'];
155
- }
156
- #################################################################################################
157
- function check_store_procedure_exist(){
158
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
159
- $q='SHOW PROCEDURE STATUS LIKE "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'"';
160
- $quer=$this->db_do($q);
161
- $result=false;
162
- While($row=mysqli_fetch_array($quer)){
163
- if(($row['Name']==Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s')) && ($row['Db']==$dbConf->dbname)){
164
- $result = true;
165
- }
166
  }
167
- return $result;
168
  }
 
169
  #################################################################################################
170
- function check_db_privileges(){
171
- $q='SHOW PRIVILEGES';
172
- $quer=$this->db_do($q);
173
- while($row=mysqli_fetch_array($quer)){
174
- if($row['Privilege']=='File' && $row['Context']=='File access on server'){
175
- return true;
176
- }
177
- }
178
- return false;
179
- }
180
- #################################################################################################
181
- function check_local_infile(){
182
- $q='SHOW VARIABLES LIKE "local_infile"';
183
- $quer=$this->db_do($q);
184
- $row=mysqli_fetch_array($quer);
185
- if($row['Variable_name']=='local_infile' && $row['Value']=="ON"){
186
- return true;
187
- }else{
188
- return false;
189
- }
190
- }
191
- #################################################################################################
192
- function is_full_import_have_been_run(){
193
- $q="SELECT COUNT(*) AS cnt
194
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic')."
195
- WHERE import_type='FULL' AND global_status_import='Successful'";
196
- $quer=$this->db_do($q);
197
- $row=mysqli_fetch_array($quer);
198
- if($row['cnt']>0){
199
- return true;
200
- }else{
201
- return false;
202
  }
 
 
 
203
  }
204
- #################################################################################################
205
- function run_sinch_import(){
206
-
207
- $this->_categoryMetaTitleAttrId = $this->_getCategoryAttributeId('meta_title');
 
 
 
208
  $this->_categoryMetadescriptionAttrId = $this->_getCategoryAttributeId('meta_description');
209
- $this->_categoryDescriptionAttrId = $this->_getCategoryAttributeId('description');
210
 
211
  $safe_mode_set = ini_get('safe_mode');
212
 
213
  $this->InitImportStatuses('FULL');
214
- if($safe_mode_set ){
215
- $this->_LOG('safe_mode is enable. import stoped.');
216
- $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
217
  exit;
218
- }
219
- $store_proc=$this->check_store_procedure_exist();
220
 
221
- if(!$store_proc){
222
- $this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
223
- $this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
224
- exit;
225
  }
226
 
227
- $file_privileg=$this->check_db_privileges();
228
 
229
- if(!$file_privileg){
230
  $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
231
  $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
232
- exit;
233
  }
234
- $local_infile=$this->check_local_infile();
235
- if(!$local_infile){
236
  $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. Add this string to 'set-variable=local-infile=0' in '/etc/my.cnf'");
237
  $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
238
  exit;
239
  }
240
- //STP TEST
241
  //$this->ApplyCustomerGroupPrice();
242
  //echo $children_cat=$this->get_all_children_cat(6);
243
-
244
 
245
 
246
- if($this->is_imort_not_run()){
247
- try{
248
  //$this->InitImportStatuses();
249
- $q="SELECT GET_LOCK('sinchimport', 30)";
250
- $quer=$this->db_do($q);
251
- $import=$this;
252
  $import->addImportStatus('Start Import');
253
  echo "Upload Files <br>";
254
  $import->UploadFiles();
@@ -264,7 +268,7 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
264
 
265
  //$import->_cleanCateoryProductFlatTable();
266
  //$import->runIndexer();
267
- //echo("\n\n\n==================RETURN=================\n\n\n");
268
 
269
 
270
  echo "Parse Category Features <br>";
@@ -274,8 +278,9 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
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
 
@@ -293,7 +298,6 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
293
  $import->addImportStatus('Parse Related Products');
294
 
295
 
296
-
297
  echo "Parse Product Features <br>";
298
  $import->ParseProductFeatures();
299
  $import->addImportStatus('Parse Product Features');
@@ -320,19 +324,19 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
320
  echo "Parse Stock And Prices <br>";
321
  $import->ParseStockAndPrices();
322
  $import->addImportStatus('Parse Stock And Prices');
323
-
324
  echo "Apply Customer Group Price <br>";
325
  //$import->ParsePriceRules();
326
  //$import->AddPriceRules();
327
  //$import->ApplyCustomerGroupPrice();
328
 
329
- if(file_exists($this->varDir.FILE_PRICE_RULES)){
330
- $ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
331
- Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
332
- 'ftp_host' => $ftpCred["ftp_server"],
333
- 'ftp_username' => $ftpCred["login"],
334
- 'ftp_password' => $ftpCred["password"]
335
- ));
336
  }
337
 
338
 
@@ -347,14 +351,14 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
347
  if ($indexProcess) {
348
  $indexProcess->reindexAll();
349
  }
350
- */
351
 
352
  Mage::log("Start indexing Sinch features for filters", null, $this->_logFile);
353
  echo "Start indexing Sinch features for filters<br>";
354
 
355
-
356
  $resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
357
- $resource->splitProductsFeature(null);
 
358
 
359
  Mage::log("Finish indexing Sinch features for filters", null, $this->_logFile);
360
  $import->addImportStatus('Generate category filters');
@@ -369,1917 +373,1429 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
369
  $import->addImportStatus('Indexing data', 1);
370
  echo "Finish indexing data";
371
 
372
- $q="SELECT RELEASE_LOCK('sinchimport')";
373
- $quer=$this->db_do($q);
374
- }catch (Exception $e) {
375
  $this->set_import_error_reporting_message($e);
376
  }
377
- }
378
- else{
379
  Mage::log("Sinchimport already run", null, $this->_logFile);
380
  echo "Sinchimport already run<br>";
381
 
382
  }
383
 
384
- }
 
385
  #################################################################################################
386
- function run_stock_price_sinch_import(){
387
- $safe_mode_set = ini_get('safe_mode');
388
 
389
- $this->InitImportStatuses('PRICE STOCK');
390
- if($safe_mode_set ){
391
- $this->_LOG('safe_mode is enable. import stoped.');
392
- $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
393
- exit;
394
- }
395
- $store_proc=$this->check_store_procedure_exist();
396
 
397
- if(!$store_proc){
398
- $this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
399
- $this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
400
- exit;
 
 
 
 
401
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
 
403
- $file_privileg=$this->check_db_privileges();
404
 
405
- if(!$file_privileg){
406
- $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
407
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
408
- exit;
409
  }
410
- $local_infile=$this->check_local_infile();
411
- if(!$local_infile){
412
- $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. Add this string to 'set-variable=local-infile=0' in '/etc/my.cnf'");
413
- $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
414
- exit;
 
 
 
 
 
 
 
 
 
 
 
415
  }
 
 
416
 
417
- if($this->is_imort_not_run() && $this->is_full_import_have_been_run()){
418
- try{
419
- //$this->InitImportStatuses();
420
- $q="SELECT GET_LOCK('sinchimport', 30)";
421
- $quer=$this->db_do($q);
422
- $import=$this;
423
- $import->addImportStatus('Stock Price Start Import');
424
- echo "Upload Files <br>";
425
- $this->files=array(
426
- FILE_STOCK_AND_PRICES,
427
- FILE_PRICE_RULES
428
- );
429
 
430
- $import->UploadFiles();
431
- $import->addImportStatus('Stock Price Upload Files');
 
 
 
 
 
 
 
 
 
 
 
432
 
433
- echo "Parse Stock And Prices <br>";
434
- //exit;
435
- $import->ParseStockAndPrices();
436
- $import->addImportStatus('Stock Price Parse Products');
437
 
438
- echo "Apply Customer Group Price <br>";
439
- //$import->ParsePriceRules();
440
- //$import->AddPriceRules();
441
- //$import->ApplyCustomerGroupPrice();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
 
443
- $ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
444
- Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
445
- 'ftp_host' => $ftpCred["ftp_server"],
446
- 'ftp_username' => $ftpCred["login"],
447
- 'ftp_password' => $ftpCred["password"]
448
- ));
449
 
 
 
450
 
451
- Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
452
- echo "Finish Stock & Price Sinch import<br>";
453
 
454
- Mage::log("Start indexing Stock & Price", null, $this->_logFile);
455
- echo "Start indexing Stock & Price<br>";
456
- $import->_cleanCateoryProductFlatTable();
457
- $import->runStockPriceIndexer();
458
- Mage::log("Finish indexing Stock & Price", null, $this->_logFile);
459
- $import->addImportStatus('Stock Price Indexing data');
460
- $import->addImportStatus('Stock Price Finish import', 1);
461
- echo "Finish indexing Stock & Price<br>";
462
 
463
- $q="SELECT RELEASE_LOCK('sinchimport')";
464
- $quer=$this->db_do($q);
465
- }catch (Exception $e) {
466
- $this->set_import_error_reporting_message($e);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
  }
468
  }
469
- else{
470
- if(!$this->is_imort_not_run()){
471
- Mage::log("Sinchimport already run", null, $this->_logFile);
472
- echo "Sinchimport already run<br>";
473
- }else{
474
- Mage::log("Full import have never finished with success", null, $this->_logFile);
475
- echo "Full import have never finished with success<br>";
 
 
 
 
 
 
 
476
  }
477
  }
478
-
479
  }
480
- #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
 
482
 
483
- function UploadFiles(){
484
 
 
 
485
  $this->_LOG("Start upload files");
486
  $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
487
- $login=$dataConf['login'];
488
- $passw=$dataConf['password'];
489
- $server=$dataConf['ftp_server'];
490
 
491
  //return;//stepan tes//stepan tes//stepan testtt
492
- if(!$login || !$passw){
493
  $this->_LOG('ftp login or password dosent defined');
494
  $this->set_import_error_reporting_message('FTP login or password has not been defined. Import stopped.');
495
  exit;
496
 
497
  }
498
- $file_url_and_dir=$this->repl_ph(FILE_URL_AND_DIR, array(
499
- 'server' => $server,
500
- 'login' => $login,
501
- 'password'=> $passw
502
- )
503
- );
504
  foreach ($this->files as $file) {
505
- $this->_LOG("Copy ".$file_url_and_dir.$file." to ".$this->varDir.$file);
506
- if(strstr($file_url_and_dir, 'ftp://')){
507
  preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
508
- //var_dump($match);
509
- if($conn = ftp_connect($match[3])){
510
- if(!ftp_login($conn, $login, $passw))
511
- {
512
- $this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
 
 
 
513
  exit;
514
  }
515
- }
516
- else{
517
- $this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
518
- exit;
519
- }
520
- if (!$this->wget ($file_url_and_dir.$file, $this->varDir.$file, 'system')){
521
- $this->_LOG("wget Can't copy ".$file.", will use old one");
522
- echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file.", will use old one<br>";
523
- }
524
- }
525
- else{
526
- if(!copy($file_url_and_dir.$file, $this->varDir.$file)){
527
- $this->_LOG("copy Can't copy ".$file.", will use old one");
528
- echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file." will use old one<br>";
529
  }
530
  }
531
- exec("chmod a+rw ".$this->varDir.$file);
532
- if(!filesize($this->varDir.$file)){
533
- if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES && $file!=FILE_PRODUCT_CATEGORIES && $file !=FILE_CATEGORY_TYPES && $file != FILE_DISTRIBUTORS_STOCK_AND_PRICES && $file != FILE_PRICE_RULES){
534
- $this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
535
- $this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
536
  $this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
537
 
538
  exit;
539
- }else{
540
- if($file==FILE_CATEGORIES_FEATURES){
541
- $this->_LOG("Can't copy ".FILE_CATEGORIES_FEATURES." file ignored" );
542
- $this->_ignore_category_features=true;
543
- }elseif($file==FILE_PRODUCT_FEATURES){
544
- $this->_LOG("Can't copy ".FILE_PRODUCT_FEATURES." file ignored" );
545
- $this->_ignore_product_features=true;
546
- }elseif($file==FILE_RELATED_PRODUCTS){
547
- $this->_LOG("Can't copy ".FILE_RELATED_PRODUCTS." file ignored" );
548
- $this->_ignore_product_related=true;
549
- }elseif($file==FILE_RESTRICTED_VALUES){
550
- $this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
551
- $this->_ignore_restricted_values=true;
552
- }elseif($file==FILE_PRODUCT_CATEGORIES){
553
- $this->_LOG("Can't copy ".FILE_PRODUCT_CATEGORIES." file ignored" );
554
- $this->_ignore_product_categories=true;
555
  $this->product_file_format = "OLD";
556
- }elseif($file==FILE_CATEGORY_TYPES){
557
- $this->_LOG("Can't copy ".FILE_CATEGORY_TYPES." file ignored" );
558
- $this->_ignore_category_types=true;
559
- }elseif($file==FILE_DISTRIBUTORS_STOCK_AND_PRICES){
560
- $this->_LOG("Can't copy ".FILE_DISTRIBUTORS_STOCK_AND_PRICES." file ignored" );
561
- $this->_ignore_category_types=true;
562
- }elseif($file==FILE_PRICE_RULES){
563
- $this->_LOG("Can't copy ".FILE_PRICE_RULES." file ignored" );
564
- $this->_ignore_price_rules=true;
 
 
 
565
  }
566
 
567
  }
568
  }
569
  }
570
- if (file_exists($file_url_and_dir.FILE_PRODUCT_CATEGORIES)){
571
  $this->product_file_format = "NEW";
572
- $this->_LOG("File ".$file_url_and_dir.FILE_PRODUCT_CATEGORIES." exist. Will used parser for NEW format product.csv" );
573
- }else{
574
  $this->product_file_format = "OLD";
575
- $this->_LOG("File ".$file_url_and_dir.FILE_PRODUCT_CATEGORIES." dosen't exist. Will used parser for OLD format product.csv" );
576
  }
577
  $this->_LOG("Finish upload files");
578
- }
579
- #################################################################################################
580
-
581
-
582
-
583
- ################################################################################################################################################################
584
- function ParseCategories()
585
- {
586
-
587
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
588
- $im_type = $dataConf['replace_category'];
589
- $parse_file = $this->varDir.FILE_CATEGORIES;
590
- $field_terminated_char = $this->field_terminated_char;
591
-
592
- $this->im_type = $im_type;
593
-
594
- if(filesize($parse_file))
595
- {
596
- $this->_LOG("Start parse ".FILE_CATEGORIES);
597
-
598
- $this->_getCategoryEntityTypeIdAndDefault_attribute_set_id();
599
-
600
- $categories_temp = Mage::getSingleton('core/resource')->getTableName('categories_temp');
601
- $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
602
- $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
603
- $catalog_category_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int');
604
- $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
605
- $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
606
- $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
607
- $category_types = Mage::getSingleton('core/resource')->getTableName('stINch_category_types');
608
-
609
- $_categoryEntityTypeId = $this->_categoryEntityTypeId;
610
- $_categoryDefault_attribute_set_id = $this->_categoryDefault_attribute_set_id;
611
-
612
- $name_attrid = $this->_getCategoryAttributeId('name');
613
- $is_anchor_attrid = $this->_getCategoryAttributeId('is_anchor');
614
- $image_attrid = $this->_getCategoryAttributeId('image');
615
-
616
-
617
-
618
-
619
- $attr_url_key = $this->attributes['url_key'];
620
- $attr_display_mode = $this->attributes['display_mode'];
621
- $attr_is_active = $this->attributes['is_active'];
622
- $attr_include_in_menu = $this->attributes['include_in_menu'];
623
-
624
-
625
- $this->loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char);
626
- $coincidence = $this->calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type, $category_types);
627
-
628
- /**/
629
- if (!$this->check_loaded_data($parse_file, $categories_temp))
630
- {
631
- $inf = mysqli_info();
632
- $this->set_import_error_reporting_message('The Stock In The Channel data files do not appear to be in the correct format. Check file'.$parse_file. "(LOAD DATA ... ".$inf.")");
633
- exit;
634
- }/**/
635
-
636
-
637
- echo("\n\ncoincidence = [".count($coincidence)."]\n\n");
638
-
639
- if (count($coincidence) == 1) // one store logic
640
- {
641
- echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
642
- if ($im_type == "REWRITE")
643
- {
644
- $root_cat = 2;
645
-
646
- $root_cat = $this->truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
647
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
648
- $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu); // return $root_cat
649
- }
650
- else // if ($im_type == "MERGE")
651
- {
652
- $root_cat = $this->_getShopRootCategoryId();
653
- }
654
-
655
- $this->_root_cat = $root_cat;
656
-
657
- $this->setCategorySettings($categories_temp, $root_cat);
658
- $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
659
- $this->addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
660
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat);
661
- }
662
- else if (count($coincidence) > 1) // multistore logic
663
- {
664
- echo("\n\n\n====================================\nmultistore logic\n====================================\n\n\n");
665
- switch ($im_type)
666
- {
667
- case "REWRITE": $this->rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
668
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
669
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
670
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
671
- break;
672
- case "MERGE" : $this->mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
673
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
674
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
675
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
676
- break;
677
- default : $retcode = "error";
678
- };
679
- }
680
- else
681
- {
682
- echo("error");
683
- }
684
-
685
- $this->_LOG("Finish parse ".FILE_CATEGORIES);
686
- }
687
- else
688
- {
689
- $this->_LOG("Wrong file ".$parse_file);
690
- }
691
- $this->_LOG(' ');
692
- $this->_set_default_root_category();
693
- return $coincidence;
694
- } // function ParseCategories()
695
  ################################################################################################################################################################
696
 
697
 
 
698
 
699
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
700
 
701
 
702
  ################################################################################################################################################################
703
- private function loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char)
704
- {
705
- $this->db_do("DROP TABLE IF EXISTS $categories_temp");
706
-
707
-
708
- /** OLD !!!*
709
- $this->db_do("CREATE TABLE $categories_temp (
710
- store_category_id int(11),
711
- parent_store_category_id int(11),
712
- category_name varchar(50),
713
- order_number int(11),
714
- is_hidden boolean,
715
- products_within_this_category int(11),
716
- products_within_sub_categories int(11),
717
- categories_image varchar(255),
718
- level int(10) NOT NULL default 0,
719
- children_count int(11) NOT NULL default 0,
720
- KEY(store_category_id),
721
- KEY(parent_store_category_id)
722
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
723
- ");
724
- /**/
725
-
726
- /** NEW !!! */
727
- $this->db_do("
728
- CREATE TABLE $categories_temp
729
- (
730
- store_category_id INT(11),
731
- parent_store_category_id INT(11),
732
- category_name VARCHAR(50),
733
- order_number INT(11),
734
- is_hidden VARCHAR(10),
735
- products_within_sub_categories INT(11),
736
- products_within_this_category INT(11),
737
- categories_image VARCHAR(255),
738
- level INT(10) NOT NULL DEFAULT 0,
739
- children_count INT(11) NOT NULL DEFAULT 0,
740
- UNSPSC INT(10) DEFAULT NULL,
741
- RootName INT(10) DEFAULT NULL,
742
- MainImageURL VARCHAR(255),
743
- MetaTitle TEXT,
744
- MetaDescription TEXT,
745
- Description TEXT,
746
- KEY(store_category_id),
747
- KEY(parent_store_category_id)
748
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
749
- /**/
750
 
751
- $this->db_do("
752
- LOAD DATA LOCAL INFILE '$parse_file' INTO TABLE $categories_temp
753
- FIELDS TERMINATED BY '$field_terminated_char' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES");
754
-
755
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN include_in_menu TINYINT(1) NOT NULL DEFAULT 1");
756
- $this->db_do("UPDATE $categories_temp SET include_in_menu = 0 WHERE UCASE(is_hidden)='TRUE'");
757
 
758
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN is_anchor TINYINT(1) NOT NULL DEFAULT 1");
759
- $this->db_do("UPDATE $categories_temp SET level = (level+2) WHERE level >= 0");
760
- # $this->db_do("UPDATE $categories_temp SET is_anchor = 0 WHERE level > 0");
761
 
 
 
 
 
 
 
 
 
 
 
 
 
762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763
 
764
- /** FOR TEST !!! *
765
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN UNSPSC INT(10) NOT NULL DEFAULT 0");
766
- $this->db_do("ALTER TABLE $categories_temp ADD COLUMN RootName VARCHAR(50) NOT NULL DEFAULT 0");
767
 
768
- //$this->db_do("UPDATE $categories_temp SET RootName = '3'"); // one store logic test
769
 
770
- $this->db_do("UPDATE $categories_temp SET RootName = 'KAMERY' WHERE store_category_id IN (93530, 93531, 93230, 93231, 175559, 175687)");
771
- $this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
772
- $this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553, 93530, 93531, 93230, 93231, 175559, 175687)");
 
 
773
 
 
 
 
 
 
 
774
 
775
- //$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
776
- //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553)");
 
 
 
 
777
 
 
 
 
778
 
779
- //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id IN (175687, 175553)"); // OLD CATS...//
 
 
 
 
780
 
781
- /**/
782
- } // private function loadCategoriesTemp()
783
  ################################################################################################################################################################
784
 
785
 
786
-
787
  ################################################################################################################################################################
788
- private function mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
789
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
790
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
791
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
792
- {
793
- echo("mergeMultistoreCategories RUN\n");
794
 
 
 
795
 
 
 
 
 
 
796
 
797
- $this->createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
798
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
799
 
 
 
800
 
 
801
 
802
- $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
 
 
 
 
 
 
 
803
 
 
 
804
 
805
- $this->addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
806
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
807
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
808
 
809
 
 
 
 
 
810
 
811
- echo("\n\n\nmergeMultistoreCategories DONE\n");
812
- }
813
- ################################################################################################################################################################
814
 
 
 
815
 
 
 
 
 
 
 
816
 
817
 
 
818
 
 
 
 
 
 
819
 
820
- ################################################################################################################################################################
821
- private function addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
822
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
823
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
824
- {
825
- echo("\n\n\n\n *************************************************************\n addCategoryDataMultistoreMerge start... \n");
826
-
827
-
828
- if (UPDATE_CATEGORY_DATA)
829
- {
830
- $ignore = '';
831
- $on_diplicate_key_update = "
832
- ON DUPLICATE KEY UPDATE
833
- updated_at = now(),
834
- store_category_id = c.store_category_id,
835
- level = c.level,
836
- children_count = c.children_count,
837
- position = c.order_number,
838
- parent_store_category_id = c.parent_store_category_id";
839
- //level=c.level,
840
- //children_count=c.children_count
841
- //position=c.order_number,
842
- }
843
- else
844
- {
845
- $ignore = 'IGNORE';
846
- $on_diplicate_key_update = '';
847
- }
848
-
849
- $query = "
850
- INSERT $ignore INTO $catalog_category_entity
851
- (
852
- entity_type_id,
853
- attribute_set_id,
854
- created_at,
855
- updated_at,
856
- level,
857
- children_count,
858
- entity_id,
859
- position,
860
- parent_id,
861
- store_category_id,
862
- parent_store_category_id
863
- )
864
- (SELECT
865
- $_categoryEntityTypeId,
866
- $_categoryDefault_attribute_set_id,
867
- NOW(),
868
- NOW(),
869
- c.level,
870
- c.children_count,
871
- scm.shop_entity_id,
872
- c.order_number,
873
- scm.shop_parent_id,
874
- c.store_category_id,
875
- c.parent_store_category_id
876
- FROM $categories_temp c
877
- LEFT JOIN $stINch_categories_mapping scm
878
- ON c.store_category_id = scm.store_category_id
879
- ) $on_diplicate_key_update";
880
- echo("\n\n $query\n\n");
881
- $this->db_do($query);
882
-
883
-
884
-
885
-
886
-
887
-
888
-
889
- $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
890
-
891
-
892
-
893
-
894
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
895
- while ($row = mysqli_fetch_array($categories))
896
- {
897
- $parent_id = $row['parent_id'];
898
- $entity_id = $row['entity_id'];
899
-
900
- $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
901
-
902
- $this->db_do("
903
- UPDATE $catalog_category_entity
904
- SET path = '$path'
905
- WHERE entity_id = $entity_id");
906
- } // while ($row = mysqli_fetch_array($categories))
907
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
908
 
 
 
 
 
 
 
 
 
 
909
 
910
- ///////////////////////////////////////////////////////
911
 
 
912
 
913
- if(UPDATE_CATEGORY_DATA)
914
- {
915
- echo "Update category_data \n";
916
-
917
- $q = "
918
- INSERT INTO $catalog_category_entity_varchar
919
- (
920
- entity_type_id,
921
- attribute_id,
922
- store_id,
923
- entity_id,
924
- value
925
- )
926
- (SELECT
927
- $_categoryEntityTypeId,
928
- $name_attrid,
929
- 0,
930
- scm.shop_entity_id,
931
- c.category_name
932
- FROM $categories_temp c
933
- JOIN $stINch_categories_mapping scm
934
- ON c.store_category_id = scm.store_category_id
935
- )
936
- ON DUPLICATE KEY UPDATE
937
- value = c.category_name";
938
- $this->db_do($q);
939
-
940
-
941
- $q = "
942
- INSERT INTO $catalog_category_entity_varchar
943
- (
944
- entity_type_id,
945
- attribute_id,
946
- store_id,
947
- entity_id,
948
- value
949
- )
950
- (SELECT
951
- $_categoryEntityTypeId,
952
- $name_attrid,
953
- 1,
954
- scm.shop_entity_id,
955
- c.category_name
956
- FROM $categories_temp c
957
- JOIN $stINch_categories_mapping scm
958
- ON c.store_category_id = scm.store_category_id
959
- )
960
- ON DUPLICATE KEY UPDATE
961
- value = c.category_name";
962
- $this->db_do($q);
963
-
964
-
965
- $q = "
966
- INSERT INTO $catalog_category_entity
967
- (
968
- entity_type_id,
969
- attribute_id,
970
- store_id,
971
- entity_id,
972
- value
973
- )
974
- (SELECT
975
- $_categoryEntityTypeId,
976
- $attr_is_active,
977
- 0,
978
- scm.shop_entity_id,
979
- 1
980
- FROM $categories_temp c
981
- JOIN $stINch_categories_mapping scm
982
- ON c.store_category_id = scm.store_category_id
983
- )
984
- ON DUPLICATE KEY UPDATE
985
- value = 1";
986
- $this->db_do($q);
987
-
988
-
989
- $q = "
990
- INSERT INTO $catalog_category_entity_int
991
- (
992
- entity_type_id,
993
- attribute_id,
994
- store_id,
995
- entity_id,
996
- value
997
- )
998
- (SELECT
999
- $_categoryEntityTypeId,
1000
- $attr_is_active,
1001
- 1,
1002
- scm.shop_entity_id,
1003
- 1
1004
- FROM $categories_temp c
1005
- JOIN $stINch_categories_mapping scm
1006
- ON c.store_category_id = scm.store_category_id
1007
- )
1008
- ON DUPLICATE KEY UPDATE
1009
- value = 1";
1010
- $this->db_do($q);
1011
-
1012
-
1013
- $q = "
1014
- INSERT INTO $catalog_category_entity_int
1015
- (
1016
- entity_type_id,
1017
- attribute_id,
1018
- store_id,
1019
- entity_id,
1020
- value
1021
- )
1022
- (SELECT
1023
- $_categoryEntityTypeId,
1024
- $attr_include_in_menu,
1025
- 0,
1026
- scm.shop_entity_id,
1027
- c.include_in_menu
1028
- FROM $categories_temp c
1029
- JOIN $stINch_categories_mapping scm
1030
- ON c.store_category_id = scm.store_category_id
1031
- )
1032
- ON DUPLICATE KEY UPDATE
1033
- value = c.include_in_menu";
1034
- $this->db_do($q);
1035
-
1036
-
1037
- $q = "
1038
- INSERT INTO $catalog_category_entity_int
1039
- (
1040
- entity_type_id,
1041
- attribute_id,
1042
- store_id,
1043
- entity_id,
1044
- value
1045
- )
1046
- (SELECT
1047
- $_categoryEntityTypeId,
1048
- $is_anchor_attrid,
1049
- 1,
1050
- scm.shop_entity_id,
1051
- c.is_anchor
1052
- FROM $categories_temp c
1053
- JOIN $stINch_categories_mapping scm
1054
- ON c.store_category_id = scm.store_category_id
1055
- )
1056
- ON DUPLICATE KEY UPDATE
1057
- value = c.is_anchor";
1058
- $this->db_do($q);
1059
-
1060
-
1061
- $q = "
1062
- INSERT INTO $catalog_category_entity_int
1063
- (
1064
- entity_type_id,
1065
- attribute_id,
1066
- store_id,
1067
- entity_id,
1068
- value
1069
- )
1070
- (SELECT
1071
- $_categoryEntityTypeId,
1072
- $is_anchor_attrid,
1073
- 0,
1074
- scm.shop_entity_id,
1075
- c.is_anchor
1076
- FROM $categories_temp c
1077
- JOIN $stINch_categories_mapping scm
1078
- ON c.store_category_id = scm.store_category_id
1079
- )
1080
- ON DUPLICATE KEY UPDATE
1081
- value = c.is_anchor";
1082
- $this->db_do($q);
1083
-
1084
- $q = "
1085
- INSERT INTO $catalog_category_entity_varchar
1086
- (
1087
- entity_type_id,
1088
- attribute_id,
1089
- store_id,
1090
- entity_id,
1091
- value
1092
- )
1093
- (SELECT
1094
- $_categoryEntityTypeId,
1095
- $image_attrid,
1096
- 0,
1097
- scm.shop_entity_id,
1098
- c.categories_image
1099
- FROM $categories_temp c
1100
- JOIN $stINch_categories_mapping scm
1101
- ON c.store_category_id = scm.store_category_id
1102
- )
1103
- ON DUPLICATE KEY UPDATE
1104
- value = c.categories_image";
1105
- $this->db_do($q);
1106
- //STP
1107
- $q = "
1108
- INSERT INTO $catalog_category_entity_varchar
1109
- (
1110
- entity_type_id,
1111
- attribute_id,
1112
- store_id,
1113
- entity_id,
1114
- value
1115
- )
1116
- (SELECT
1117
- $this->_categoryEntityTypeId,
1118
- $this->_categoryMetaTitleAttrId,
1119
- 0,
1120
- scm.shop_entity_id,
1121
- c.MetaTitle
1122
- FROM $categories_temp c
1123
- JOIN $stINch_categories_mapping scm
1124
- ON c.store_category_id = scm.store_category_id
1125
- )
1126
- ON DUPLICATE KEY UPDATE
1127
- value = c.MetaTitle";
1128
- $this->db_do($q);
1129
 
1130
- $q = "
1131
- INSERT INTO $catalog_category_entity_varchar
1132
- (
1133
- entity_type_id,
1134
- attribute_id,
1135
- store_id,
1136
- entity_id,
1137
- value
1138
- )
1139
- (SELECT
1140
- $this->_categoryEntityTypeId,
1141
- $this->_categoryMetadescriptionAttrId,
1142
- 0,
1143
- scm.shop_entity_id,
1144
- c.MetaDescription
1145
- FROM $categories_temp c
1146
- JOIN $stINch_categories_mapping scm
1147
- ON c.store_category_id = scm.store_category_id
1148
- )
1149
- ON DUPLICATE KEY UPDATE
1150
- value = c.MetaDescription";
1151
- $this->db_do($q);
1152
 
1153
- $q = "
1154
- INSERT INTO $catalog_category_entity_varchar
1155
- (
1156
- entity_type_id,
1157
- attribute_id,
1158
- store_id,
1159
- entity_id,
1160
- value
1161
- )
1162
- (SELECT
1163
- $this->_categoryEntityTypeId,
1164
- $this->_categoryDescriptionAttrId,
1165
- 0,
1166
- scm.shop_entity_id,
1167
- c.Description
1168
- FROM $categories_temp c
1169
- JOIN $stINch_categories_mapping scm
1170
- ON c.store_category_id = scm.store_category_id
1171
- )
1172
- ON DUPLICATE KEY UPDATE
1173
- value = c.Description";
1174
- $this->db_do($q);
1175
 
 
1176
 
1177
- //stp
1178
- }
1179
- else
1180
- {
1181
- echo "Insert ignore category_data \n";
1182
-
1183
-
1184
- $q = "
1185
- INSERT IGNORE INTO $catalog_category_entity_varchar
1186
- (
1187
- entity_type_id,
1188
- attribute_id,
1189
- store_id,
1190
- entity_id,
1191
- value
1192
- )
1193
- (SELECT
1194
- $_categoryEntityTypeId,
1195
- $name_attrid,
1196
- 0,
1197
- scm.shop_entity_id,
1198
- c.category_name
1199
- FROM $categories_temp c
1200
- JOIN $stINch_categories_mapping scm
1201
- ON c.store_category_id = scm.store_category_id
1202
- )";
1203
- $this->db_do($q);
1204
-
1205
-
1206
- $q = "
1207
- INSERT IGNORE INTO $catalog_category_entity_int
1208
- (
1209
- entity_type_id,
1210
- attribute_id,
1211
- store_id,
1212
- entity_id,
1213
- value
1214
- )
1215
- (SELECT
1216
- $_categoryEntityTypeId,
1217
- $attr_is_active,
1218
- 0,
1219
- scm.shop_entity_id,
1220
- 1
1221
- FROM $categories_temp c
1222
- JOIN $stINch_categories_mapping scm
1223
- ON c.store_category_id = scm.store_category_id
1224
- )";
1225
- $this->db_do($q);
1226
-
1227
-
1228
- $q = "
1229
- INSERT IGNORE INTO $catalog_category_entity_int
1230
- (
1231
- entity_type_id,
1232
- attribute_id,
1233
- store_id,
1234
- entity_id,
1235
- value
1236
- )
1237
- (SELECT
1238
- $_categoryEntityTypeId,
1239
- $attr_include_in_menu,
1240
- 0,
1241
- scm.shop_entity_id,
1242
- c.include_in_menu
1243
- FROM $categories_temp c
1244
- JOIN $stINch_categories_mapping scm
1245
- ON c.store_category_id = scm.store_category_id
1246
- )";
1247
- $this->db_do($q);
1248
-
1249
-
1250
- $q = "
1251
- INSERT IGNORE INTO $catalog_category_entity_int
1252
- (
1253
- entity_type_id,
1254
- attribute_id,
1255
- store_id,
1256
- entity_id,
1257
- value
1258
- )
1259
- (SELECT
1260
- $_categoryEntityTypeId,
1261
- $is_anchor_attrid,
1262
- 0,
1263
- scm.shop_entity_id,
1264
- c.is_anchor
1265
- FROM $categories_temp c
1266
- JOIN $stINch_categories_mapping scm
1267
- ON c.store_category_id = scm.store_category_id
1268
- )";
1269
- $this->db_do($q);
1270
-
1271
-
1272
- $q = "
1273
- INSERT IGNORE INTO $catalog_category_entity_varchar
1274
- (
1275
- entity_type_id,
1276
- attribute_id,
1277
- store_id,
1278
- entity_id,
1279
- value
1280
- )
1281
- (SELECT
1282
- $_categoryEntityTypeId,
1283
- $image_attrid,
1284
- 0,
1285
- scm.shop_entity_id,
1286
- c.categories_image
1287
- FROM $categories_temp c
1288
- JOIN $stINch_categories_mapping scm
1289
- ON c.store_category_id = scm.store_category_id
1290
- )";
1291
- $this->db_do($q);
1292
- //STP
1293
- $q = "
1294
- INSERT IGNORE INTO $catalog_category_entity_varchar
1295
- (
1296
- entity_type_id,
1297
- attribute_id,
1298
- store_id,
1299
- entity_id,
1300
- value
1301
- )
1302
- (SELECT
1303
- $this->_categoryEntityTypeId,
1304
- $this->_categoryMetaTitleAttrId,
1305
- 0,
1306
- scm.shop_entity_id,
1307
- c.MetaTitle
1308
- FROM $categories_temp c
1309
- JOIN $stINch_categories_mapping scm
1310
- ON c.store_category_id = scm.store_category_id
1311
- )
1312
- ";
1313
- $this->db_do($q);
1314
 
1315
- $q = "
1316
- INSERT IGNORE INTO $catalog_category_entity_varchar
1317
- (
1318
- entity_type_id,
1319
- attribute_id,
1320
- store_id,
1321
- entity_id,
1322
- value
1323
- )
1324
- (SELECT
1325
- $this->_categoryEntityTypeId,
1326
- $this->_categoryMetadescriptionAttrId,
1327
- 0,
1328
- scm.shop_entity_id,
1329
- c.MetaDescription
1330
- FROM $categories_temp c
1331
- JOIN $stINch_categories_mapping scm
1332
- ON c.store_category_id = scm.store_category_id
1333
- )
1334
- ";
1335
- $this->db_do($q);
1336
 
1337
- $q = "
1338
- INSERT IGNORE INTO $catalog_category_entity_varchar
1339
- (
1340
- entity_type_id,
1341
- attribute_id,
1342
- store_id,
1343
- entity_id,
1344
- value
1345
- )
1346
- (SELECT
1347
- $this->_categoryEntityTypeId,
1348
- $this->_categoryDescriptionAttrId,
1349
- 0,
1350
- scm.shop_entity_id,
1351
- c.Description
1352
- FROM $categories_temp c
1353
- JOIN $stINch_categories_mapping scm
1354
- ON c.store_category_id = scm.store_category_id
1355
- )
1356
- ";
1357
- $this->db_do($q);
1358
 
 
 
 
1359
 
1360
- //stp
1361
 
1362
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1363
 
1364
 
 
1365
 
1366
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1367
 
1368
- //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
1369
 
1370
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
1371
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1372
 
1373
- $this->deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int);
1374
- /**/
1375
 
1376
- echo("\n addCategoryDataMultistoreMerge done... \n *************************************************************\n");
1377
 
1378
- } // private function addCategoryDataMultistoreMerge(...)
 
 
 
 
 
 
 
 
 
 
1379
  ################################################################################################################################################################
1380
 
1381
 
 
1382
 
 
 
 
 
 
 
1383
 
1384
 
1385
  ################################################################################################################################################################
1386
- private function deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int)
1387
- {
1388
 
1389
- echo("\n\n\n\n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n deleteOldSinchCategoriesFromShopMerge start... \n");
 
 
 
 
 
 
1390
 
1391
 
1392
- $query = "DROP TABLE IF EXISTS delete_cats";
1393
- echo("\n $query\n");
1394
- $this->db_do($query );
1395
 
 
 
 
 
 
1396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1397
 
1398
- $delete_cats = Mage::getSingleton('core/resource')->getTableName('delete_cats');
1399
- $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1400
 
1401
- $query = "
1402
- CREATE TABLE $delete_cats
1403
 
1404
- SELECT entity_id
1405
- FROM $catalog_category_entity cce
1406
- WHERE cce.entity_id NOT IN
1407
- (
1408
- SELECT cce2.entity_id
1409
- FROM $catalog_category_entity cce2
1410
- JOIN $stINch_categories sc
1411
- ON cce2.store_category_id = sc.store_category_id
1412
- )
1413
- AND cce.store_category_id IS NOT NULL
1414
- ;";
1415
 
1416
- echo("\n $query\n");
1417
- $this->db_do($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1418
 
1419
 
 
1420
 
1421
- $query = "DELETE cce FROM $catalog_category_entity cce JOIN $delete_cats dc USING(entity_id)";
1422
- echo("\n $query\n");
1423
- $this->db_do($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1424
 
1425
 
 
1426
 
1427
- $query = "DROP TABLE IF EXISTS $delete_cats";
1428
- echo("\n $query\n");
1429
- //$this->db_do($query );
1430
 
 
 
 
 
 
 
 
 
 
 
 
1431
 
1432
- /**
1433
- $query = "
1434
- DELETE cat FROM $catalog_category_entity_varchar cat
1435
- JOIN $stINch_categories_mapping scm
1436
- ON cat.entity_id = scm.shop_entity_id
1437
- WHERE
1438
- (scm.shop_store_category_id IS NOT NULL) AND
1439
- (scm.store_category_id IS NULL)";
1440
- echo("\n $query\n");
1441
- // $this->db_do($query);
1442
-
1443
- $query = "
1444
- DELETE cat FROM $catalog_category_entity_int cat
1445
- JOIN $stINch_categories_mapping scm
1446
- ON cat.entity_id = scm.shop_entity_id
1447
- WHERE
1448
- (scm.shop_store_category_id IS NOT NULL) AND
1449
- (scm.store_category_id IS NULL)";
1450
- echo("\n $query\n");
1451
- // $this->db_do($query);
1452
-
1453
- $query = "
1454
- DELETE cat FROM $catalog_category_entity cat
1455
- JOIN $stINch_categories_mapping scm
1456
- ON cat.entity_id=scm.shop_entity_id
1457
- WHERE
1458
- (scm.shop_store_category_id IS NOT NULL) AND
1459
- (scm.store_category_id IS NULL)";
1460
- echo("\n $query\n");
1461
- // $this->db_do($query);
1462
- /**/
1463
-
1464
- echo("\n deleteOldSinchCategoriesFromShopMerge done... \n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n\n");
1465
-
1466
- } // private function deleteOldSinchCategoriesFromShopMerge()
1467
  ################################################################################################################################################################
1468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1469
 
 
 
1470
 
 
1471
 
 
 
 
1472
 
1473
- ################################################################################################################################################################
1474
- private function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
1475
- {
1476
- echo("\n\n\ ==========================================================================\n mapSinchCategoriesMultistore start... \n");
1477
-
1478
- $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
1479
-
1480
- $query = "
1481
- INSERT IGNORE INTO $stINch_categories_mapping_temp
1482
- (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
1483
- (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
1484
- FROM $catalog_category_entity)";
1485
- echo("\n $query\n");
1486
- $this->db_do($query);
1487
-
1488
-
1489
- $query = "
1490
- UPDATE $stINch_categories_mapping_temp cmt
1491
- JOIN $categories_temp c
1492
- ON cmt.shop_store_category_id = c.store_category_id
1493
- SET
1494
- cmt.store_category_id = c.store_category_id,
1495
- cmt.parent_store_category_id = c.parent_store_category_id,
1496
- cmt.category_name = c.category_name,
1497
- cmt.order_number = c.order_number,
1498
- cmt.products_within_this_category = c.products_within_this_category";
1499
- echo("\n $query\n");
1500
- $this->db_do($query);
1501
-
1502
-
1503
- $query = "
1504
- UPDATE $stINch_categories_mapping_temp cmt
1505
- JOIN $catalog_category_entity cce
1506
- ON cmt.parent_store_category_id = cce.store_category_id
1507
- SET cmt.shop_parent_id = cce.entity_id";
1508
- echo("\n $query\n");
1509
- $this->db_do($query);
1510
-
1511
-
1512
- $query = "
1513
- SELECT DISTINCT
1514
- c.RootName, cce.entity_id
1515
- FROM $categories_temp c
1516
- JOIN $catalog_category_entity_varchar ccev
1517
- ON c.RootName = ccev.value
1518
- AND ccev.entity_type_id = $_categoryEntityTypeId
1519
- AND ccev.attribute_id = $name_attrid
1520
- AND ccev.store_id = 0
1521
- JOIN $catalog_category_entity cce
1522
- ON ccev.entity_id = cce.entity_id";
1523
- echo("\n $query\n");
1524
- $root_categories = $this->db_do($query);
1525
-
1526
- while($root_cat = mysqli_fetch_array($root_categories))
1527
- {
1528
- $root_id = $root_cat['entity_id'];
1529
- $root_name = $root_cat['RootName'];
1530
-
1531
- $query = "
1532
- UPDATE $stINch_categories_mapping_temp cmt
1533
- JOIN $categories_temp c
1534
- ON cmt.shop_store_category_id = c.store_category_id
1535
- SET
1536
- cmt.shop_parent_id = $root_id,
1537
- cmt.shop_parent_store_category_id = $root_id,
1538
- cmt.parent_store_category_id = $root_id,
1539
- c.parent_store_category_id = $root_id
1540
- WHERE RootName = '$root_name'
1541
- AND cmt.shop_parent_id = 0";
1542
- echo("\n $query\n");
1543
- $this->db_do($query);
1544
- }
1545
-
1546
-
1547
-
1548
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1549
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
1550
- else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
1551
-
1552
- $query = "
1553
- UPDATE $stINch_categories_mapping_temp cmt
1554
- JOIN $catalog_category_entity cce
1555
- ON cmt.shop_entity_id = cce.entity_id
1556
- SET cce.parent_id = cmt.shop_parent_id
1557
- $where";
1558
- echo("\n $query\n");
1559
- $this->db_do($query);
1560
-
1561
- $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
1562
- echo("\n $query\n");
1563
- $this->db_do($query);
1564
-
1565
- $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
1566
- echo("\n $query\n");
1567
- $this->db_do($query);
1568
-
1569
- echo("\n mapSinchCategoriesMultistore done... \n ==========================================================================\n\n\n\n");
1570
- } // public function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
1571
- ################################################################################################################################################################
1572
-
1573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1574
 
 
1575
 
 
1576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1578
 
1579
- ################################################################################################################################################################
1580
- private function createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1581
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1582
- {
1583
- echo("\n\n ==========================================================================\n createNewDefaultCategories start... \n");
1584
-
1585
- $old_cats = array();
1586
- $query = $this->db_do("
1587
- SELECT
1588
- cce.entity_id,
1589
- ccev.value AS category_name
1590
- FROM $catalog_category_entity cce
1591
- JOIN $catalog_category_entity_varchar ccev
1592
- ON cce.entity_id = ccev.entity_id
1593
- AND ccev.store_id = 0
1594
- AND cce.entity_type_id = ccev.entity_type_id
1595
- AND ccev.attribute_id = 41
1596
- WHERE parent_id = 1"); // 41 - category name
1597
- while ($row = mysqli_fetch_array($query)) $old_cats[] = $row['category_name'];
1598
-
1599
- //var_dump($old_cats);
1600
-
1601
-
1602
- $query = $this->db_do("SELECT MAX(entity_id) AS max_entity_id FROM $catalog_category_entity");
1603
- $max_entity_id = mysqli_fetch_array($query);
1604
-
1605
- //var_dump($max_entity_id);
1606
-
1607
- $i = $max_entity_id[max_entity_id] + 1;
1608
-
1609
- foreach($coincidence as $key => $item)
1610
- {
1611
- echo("\n coincidence: key = [$key]\n");
1612
-
1613
-
1614
- /**if ($item)
1615
- {
1616
- echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> CONTINUE: key = [$key] item = [$item]\n");
1617
- //continue;
1618
- }
1619
- else
1620
- {
1621
- echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> NOT CONTINUE: key = [$key] item = [$item]\n");
1622
- }/**/
1623
-
1624
-
1625
- if (in_array($key, $old_cats))
1626
- {
1627
- echo(" CONTINUE: key = [$key] item = [$item]\n");
1628
- continue;
1629
- }
1630
- else
1631
- {
1632
- echo(" CREATE NEW CATEGORY: key = [$key] item = [$item]\n");
1633
- }
1634
-
1635
-
1636
- $this->db_do("INSERT $catalog_category_entity
1637
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1638
- path, position, level, children_count, store_category_id, parent_store_category_id)
1639
- VALUES
1640
- ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 1, NULL, NULL)");
1641
-
1642
-
1643
- $this->db_do("INSERT $catalog_category_entity_varchar
1644
- (entity_type_id, attribute_id, store_id, entity_id, value)
1645
- VALUES
1646
- ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
1647
- ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
1648
- ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
1649
- ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
1650
-
1651
-
1652
- $this->db_do("INSERT $catalog_category_entity_int
1653
- (entity_type_id, attribute_id, store_id, entity_id, value)
1654
- VALUES
1655
- ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
1656
- ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
1657
- ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
1658
- ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
1659
- $i++;
1660
- } // foreach($coincidence as $key => $item)
1661
-
1662
- echo("\n createNewDefaultCategories done... \n ==========================================================================\n");
1663
-
1664
- } // private function createNewDefaultCategories()
1665
- ################################################################################################################################################################
1666
-
1667
-
1668
-
1669
-
1670
-
1671
-
1672
-
1673
- ################################################################################################################################################################
1674
- private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type, $category_types)
1675
- {
1676
- $root_categories = $this->db_do("
1677
- SELECT
1678
- cce.entity_id,
1679
- ccev.value AS category_name
1680
- FROM $catalog_category_entity cce
1681
- JOIN $catalog_category_entity_varchar ccev
1682
- ON cce.entity_id = ccev.entity_id
1683
- AND ccev.store_id = 0
1684
- AND cce.entity_type_id = ccev.entity_type_id
1685
- AND ccev.attribute_id = 41
1686
- WHERE parent_id = 1"); // 41 - category name
1687
- $OLD = array();
1688
- while($root_cat = mysqli_fetch_array($root_categories)) $OLD[] = $root_cat['category_name'];
1689
-
1690
- $new_categories = $this->db_do("SELECT DISTINCT RootName FROM $categories_temp");
1691
-
1692
- //STP $new_categories = $this->db_do("SELECT DISTINCT ctemp.RootName, ctype.name FROM $categories_temp ctemp LEFT JOIN $category_types ctypes on ctemp.RootName = ctype.name");
1693
-
1694
- $NEW = array();
1695
- while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['RootName']] = TRUE;
1696
- /////STP while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['name']] = TRUE;
1697
- /**
1698
- $exists_coincidence = array();
1699
-
1700
- switch ($im_type)
1701
- {
1702
- case "REWRITE":
1703
- foreach($NEW as $item)
1704
- {
1705
- $exists_coincidence[$item] = TRUE;
1706
- }
1707
- break;
1708
- case "MERGE" :
1709
- foreach($OLD as $item)
1710
- {
1711
- $exists_coincidence[$item] = FALSE;
1712
- }
1713
- foreach($NEW as $item)
1714
- {
1715
- $exists_coincidence[$item] = TRUE;
1716
- }
1717
- break;
1718
- default : $retcode = "error";
1719
- };
1720
- /**/
1721
-
1722
-
1723
-
1724
- echo("\ncalculateCategoryCoincidence ...im_type = [$im_type]\n\n");
1725
- var_dump($exists_coincidence);
1726
-
1727
- return $exists_coincidence;
1728
- } // private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity)
1729
- ################################################################################################################################################################
1730
-
1731
-
1732
-
1733
- ################################################################################################################################################################
1734
- private function rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1735
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1736
- $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
1737
- $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
1738
- {
1739
- echo("rewriteMultistoreCategories RUN\n");
1740
-
1741
-
1742
- echo(" truncateAllCateriesAndCreateRoot start...");
1743
- $this->truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1744
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active);
1745
- echo(" done.\n");
1746
-
1747
-
1748
- echo(" createDefaultCategories start...");
1749
- $this->createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1750
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
1751
- echo(" done.\n");
1752
-
1753
-
1754
- echo(" mapSinchCategoriesMultistore start...");
1755
- $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
1756
- echo(" done.\n");
1757
-
1758
-
1759
- echo(" addCategoryDataMultistore start...");
1760
- $this->addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1761
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1762
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
1763
- echo(" done.\n");
1764
-
1765
-
1766
- echo("rewriteMultistoreCategories DONE\n");
1767
- } // private function rewriteMultistoreCategories()
1768
- ################################################################################################################################################################
1769
-
1770
-
1771
-
1772
-
1773
-
1774
-
1775
-
1776
- ################################################################################################################################################################
1777
- private function truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1778
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active)
1779
- {
1780
- $this->db_do('SET foreign_key_checks=0');
1781
-
1782
-
1783
- $this->db_do("TRUNCATE $catalog_category_entity");
1784
- $this->db_do("TRUNCATE $catalog_category_entity_varchar");
1785
- $this->db_do("TRUNCATE $catalog_category_entity_int");
1786
-
1787
-
1788
- $this->db_do("INSERT $catalog_category_entity
1789
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1790
- path, position, level, children_count, store_category_id, parent_store_category_id)
1791
- VALUES
1792
- (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', NOW(), '1', 0, 0, 1, NULL, NULL)");
1793
-
1794
-
1795
- $this->db_do("INSERT $catalog_category_entity_varchar
1796
- (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1797
- VALUES
1798
- (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
1799
- (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
1800
- (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog')");
1801
-
1802
-
1803
- $this->db_do("INSERT $catalog_category_entity_int
1804
- (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
1805
- VALUES
1806
- (1, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1)");
1807
- } // private function truncateAllCateriesAndCreateRoot(...)
1808
- ################################################################################################################################################################
1809
-
1810
-
1811
-
1812
-
1813
- ################################################################################################################################################################
1814
- private function createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1815
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1816
- {
1817
- $i = 3; // 2 - is Default Category... not use.
1818
-
1819
- foreach($coincidence as $key => $item)
1820
- {
1821
- $this->db_do("INSERT $catalog_category_entity
1822
- (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
1823
- path, position, level, children_count, store_category_id, parent_store_category_id)
1824
- VALUES
1825
- ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 1, NULL, NULL)");
1826
-
1827
-
1828
- $this->db_do("INSERT $catalog_category_entity_varchar
1829
- (entity_type_id, attribute_id, store_id, entity_id, value)
1830
- VALUES
1831
- ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
1832
- ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
1833
- ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
1834
- ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
1835
-
1836
-
1837
- $this->db_do("INSERT $catalog_category_entity_int
1838
- (entity_type_id, attribute_id, store_id, entity_id, value)
1839
- VALUES
1840
- ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
1841
- ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
1842
- ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
1843
- ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
1844
- $i++;
1845
- } // foreach($coincidence as $key => $item)
1846
- } // private function truncateAllCateries()
1847
- ################################################################################################################################################################
1848
-
1849
-
1850
-
1851
-
1852
- ################################################################################################################################################################
1853
- private function mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
1854
- {
1855
- echo("\n\n\n\n==========================================================================\nmapSinchCategoriesMultistore start... \n");
1856
-
1857
- $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
1858
-
1859
- $query = "
1860
- INSERT IGNORE INTO $stINch_categories_mapping_temp
1861
- (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
1862
- (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
1863
- FROM $catalog_category_entity)";
1864
- echo("\n\n$query\n\n");
1865
- $this->db_do($query);
1866
-
1867
-
1868
- $query = "
1869
- UPDATE $stINch_categories_mapping_temp cmt
1870
- JOIN $categories_temp c
1871
- ON cmt.shop_store_category_id = c.store_category_id
1872
- SET
1873
- cmt.store_category_id = c.store_category_id,
1874
- cmt.parent_store_category_id = c.parent_store_category_id,
1875
- cmt.category_name = c.category_name,
1876
- cmt.order_number = c.order_number,
1877
- cmt.products_within_this_category = c.products_within_this_category";
1878
- echo("\n\n$query\n\n");
1879
- $this->db_do($query);
1880
-
1881
-
1882
- $query = "
1883
- UPDATE $stINch_categories_mapping_temp cmt
1884
- JOIN $catalog_category_entity cce
1885
- ON cmt.parent_store_category_id = cce.store_category_id
1886
- SET cmt.shop_parent_id = cce.entity_id";
1887
- echo("\n\n$query\n\n");
1888
- $this->db_do($query);
1889
-
1890
-
1891
- $query = "
1892
- SELECT DISTINCT
1893
- c.RootName, cce.entity_id
1894
- FROM $categories_temp c
1895
- JOIN $catalog_category_entity_varchar ccev
1896
- ON c.RootName = ccev.value
1897
- AND ccev.entity_type_id = $_categoryEntityTypeId
1898
- AND ccev.attribute_id = $name_attrid
1899
- AND ccev.store_id = 0
1900
- JOIN $catalog_category_entity cce
1901
- ON ccev.entity_id = cce.entity_id";
1902
- echo("\n\n$query\n\n");
1903
- $root_categories = $this->db_do($query);
1904
-
1905
- while($root_cat = mysqli_fetch_array($root_categories))
1906
- {
1907
- $root_id = $root_cat['entity_id'];
1908
- $root_name = $root_cat['RootName'];
1909
-
1910
- $query = "
1911
- UPDATE $stINch_categories_mapping_temp cmt
1912
- JOIN $categories_temp c
1913
- ON cmt.shop_store_category_id = c.store_category_id
1914
- SET
1915
- cmt.shop_parent_id = $root_id,
1916
- cmt.shop_parent_store_category_id = $root_id,
1917
- cmt.parent_store_category_id = $root_id,
1918
- c.parent_store_category_id = $root_id
1919
- WHERE RootName = '$root_name'
1920
- AND cmt.shop_parent_id = 0";
1921
- echo("\n\n$query\n\n");
1922
- $this->db_do($query);
1923
- }
1924
-
1925
-
1926
-
1927
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1928
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
1929
- else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
1930
-
1931
- $query = "
1932
- UPDATE $stINch_categories_mapping_temp cmt
1933
- JOIN $catalog_category_entity cce
1934
- ON cmt.shop_entity_id = cce.entity_id
1935
- SET cce.parent_id = cmt.shop_parent_id
1936
- $where";
1937
- echo("\n\n$query\n\n");
1938
- $this->db_do($query);
1939
-
1940
- $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
1941
- echo("\n\n$query\n\n");
1942
- $this->db_do($query);
1943
-
1944
- $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
1945
- echo("\n\n$query\n\n");
1946
- $this->db_do($query);
1947
-
1948
- echo("\nmapSinchCategoriesMultistore done... \n==========================================================================\n\n\n\n");
1949
- } // public function mapSinchCategoriesMultistore($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
1950
- ################################################################################################################################################################
1951
-
1952
-
1953
 
1954
- ################################################################################################################################################################
1955
- private function createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping)
1956
- {
1957
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
1958
- $this->db_do("
1959
- CREATE TABLE $stINch_categories_mapping_temp
1960
- (
1961
- shop_entity_id INT(11) UNSIGNED NOT NULL,
1962
- shop_entity_type_id INT(11),
1963
- shop_attribute_set_id INT(11),
1964
- shop_parent_id INT(11),
1965
- shop_store_category_id INT(11),
1966
- shop_parent_store_category_id INT(11),
1967
- store_category_id INT(11),
1968
- parent_store_category_id INT(11),
1969
- category_name VARCHAR(255),
1970
- order_number INT(11),
1971
- products_within_this_category INT(11),
1972
 
1973
- KEY shop_entity_id (shop_entity_id),
1974
- KEY shop_parent_id (shop_parent_id),
1975
- KEY store_category_id (store_category_id),
1976
- KEY parent_store_category_id (parent_store_category_id),
1977
- UNIQUE KEY(shop_entity_id)
1978
- )");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1979
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1980
 
1981
- $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
1982
- }
1983
- ################################################################################################################################################################
1984
 
1985
 
 
 
 
 
1986
 
1987
- ################################################################################################################################################################
1988
- private function addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1989
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
1990
- $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
1991
- {
1992
- echo("\n\n\n\n*************************************************************\nmapSinchCategoriesMultistore start... \n");
1993
- if (UPDATE_CATEGORY_DATA)
1994
- {
1995
- $ignore = '';
1996
- $on_diplicate_key_update = "
1997
- ON DUPLICATE KEY UPDATE
1998
- updated_at = now(),
1999
- store_category_id = c.store_category_id,
2000
- level = c.level,
2001
- children_count = c.children_count,
2002
- position = c.order_number,
2003
- parent_store_category_id = c.parent_store_category_id";
2004
- //level=c.level,
2005
- //children_count=c.children_count
2006
- //position=c.order_number,
2007
- }
2008
- else
2009
- {
2010
- $ignore = 'IGNORE';
2011
- $on_diplicate_key_update = '';
2012
- }
2013
-
2014
- $query = "
2015
- INSERT $ignore INTO $catalog_category_entity
2016
- (
2017
- entity_type_id,
2018
- attribute_set_id,
2019
- created_at,
2020
- updated_at,
2021
- level,
2022
- children_count,
2023
- entity_id,
2024
- position,
2025
- parent_id,
2026
- store_category_id,
2027
- parent_store_category_id
2028
- )
2029
- (SELECT
2030
- $_categoryEntityTypeId,
2031
- $_categoryDefault_attribute_set_id,
2032
- NOW(),
2033
- NOW(),
2034
- c.level,
2035
- c.children_count,
2036
- scm.shop_entity_id,
2037
- c.order_number,
2038
- scm.shop_parent_id,
2039
- c.store_category_id,
2040
- c.parent_store_category_id
2041
- FROM $categories_temp c
2042
- LEFT JOIN $stINch_categories_mapping scm
2043
- ON c.store_category_id = scm.store_category_id
2044
- ) $on_diplicate_key_update";
2045
- echo("\n\n$query\n\n");
2046
- $this->db_do($query);
2047
 
2048
- //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
2049
 
 
 
 
 
 
2050
 
2051
- $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
 
2052
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2053
 
2054
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
2055
- while ($row = mysqli_fetch_array($categories))
2056
- {
2057
- $parent_id = $row['parent_id'];
2058
- $entity_id = $row['entity_id'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2059
 
2060
- $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2061
 
2062
- $this->db_do("
2063
- UPDATE $catalog_category_entity
2064
- SET path = '$path'
2065
- WHERE entity_id = $entity_id");
2066
- } // while ($row = mysqli_fetch_array($categories))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2068
 
2069
- ///////////////////////////////////////////////////////
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2070
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2071
 
2072
- if(UPDATE_CATEGORY_DATA)
2073
- {
2074
- echo "Update category_data \n";
2075
-
2076
- $q = "
2077
- INSERT INTO $catalog_category_entity_varchar
2078
- (
2079
- entity_type_id,
2080
- attribute_id,
2081
- store_id,
2082
- entity_id,
2083
- value
2084
- )
2085
- (SELECT
2086
- $_categoryEntityTypeId,
2087
- $name_attrid,
2088
- 0,
2089
- scm.shop_entity_id,
2090
- c.category_name
2091
- FROM $categories_temp c
2092
- JOIN $stINch_categories_mapping scm
2093
- ON c.store_category_id = scm.store_category_id
2094
- )
2095
- ON DUPLICATE KEY UPDATE
2096
- value = c.category_name";
2097
- $this->db_do($q);
2098
-
2099
-
2100
- $q = "
2101
- INSERT INTO $catalog_category_entity_varchar
2102
- (
2103
- entity_type_id,
2104
- attribute_id,
2105
- store_id,
2106
- entity_id,
2107
- value
2108
- )
2109
- (SELECT
2110
- $_categoryEntityTypeId,
2111
- $name_attrid,
2112
- 1,
2113
- scm.shop_entity_id,
2114
- c.category_name
2115
- FROM $categories_temp c
2116
- JOIN $stINch_categories_mapping scm
2117
- ON c.store_category_id = scm.store_category_id
2118
- )
2119
- ON DUPLICATE KEY UPDATE
2120
- value = c.category_name";
2121
- $this->db_do($q);
2122
-
2123
-
2124
- $q = "
2125
- INSERT INTO $catalog_category_entity
2126
- (
2127
- entity_type_id,
2128
- attribute_id,
2129
- store_id,
2130
- entity_id,
2131
- value
2132
- )
2133
- (SELECT
2134
- $_categoryEntityTypeId,
2135
- $attr_is_active,
2136
- 0,
2137
- scm.shop_entity_id,
2138
- 1
2139
- FROM $categories_temp c
2140
- JOIN $stINch_categories_mapping scm
2141
- ON c.store_category_id = scm.store_category_id
2142
- )
2143
- ON DUPLICATE KEY UPDATE
2144
- value = 1";
2145
- $this->db_do($q);
2146
-
2147
-
2148
- $q = "
2149
- INSERT INTO $catalog_category_entity_int
2150
- (
2151
- entity_type_id,
2152
- attribute_id,
2153
- store_id,
2154
- entity_id,
2155
- value
2156
- )
2157
- (SELECT
2158
- $_categoryEntityTypeId,
2159
- $attr_is_active,
2160
- 1,
2161
- scm.shop_entity_id,
2162
- 1
2163
- FROM $categories_temp c
2164
- JOIN $stINch_categories_mapping scm
2165
- ON c.store_category_id = scm.store_category_id
2166
- )
2167
- ON DUPLICATE KEY UPDATE
2168
- value = 1";
2169
- $this->db_do($q);
2170
-
2171
-
2172
- $q = "
2173
- INSERT INTO $catalog_category_entity_int
2174
- (
2175
- entity_type_id,
2176
- attribute_id,
2177
- store_id,
2178
- entity_id,
2179
- value
2180
- )
2181
- (SELECT
2182
- $_categoryEntityTypeId,
2183
- $attr_include_in_menu,
2184
- 0,
2185
- scm.shop_entity_id,
2186
- c.include_in_menu
2187
- FROM $categories_temp c
2188
- JOIN $stINch_categories_mapping scm
2189
- ON c.store_category_id = scm.store_category_id
2190
- )
2191
- ON DUPLICATE KEY UPDATE
2192
- value = c.include_in_menu";
2193
- $this->db_do($q);
2194
-
2195
-
2196
- $q = "
2197
- INSERT INTO $catalog_category_entity_int
2198
- (
2199
- entity_type_id,
2200
- attribute_id,
2201
- store_id,
2202
- entity_id,
2203
- value
2204
- )
2205
- (SELECT
2206
- $_categoryEntityTypeId,
2207
- $is_anchor_attrid,
2208
- 1,
2209
- scm.shop_entity_id,
2210
- c.is_anchor
2211
- FROM $categories_temp c
2212
- JOIN $stINch_categories_mapping scm
2213
- ON c.store_category_id = scm.store_category_id
2214
- )
2215
- ON DUPLICATE KEY UPDATE
2216
- value = c.is_anchor";
2217
- $this->db_do($q);
2218
-
2219
-
2220
- $q = "
2221
- INSERT INTO $catalog_category_entity_int
2222
- (
2223
- entity_type_id,
2224
- attribute_id,
2225
- store_id,
2226
- entity_id,
2227
- value
2228
- )
2229
- (SELECT
2230
- $_categoryEntityTypeId,
2231
- $is_anchor_attrid,
2232
- 0,
2233
- scm.shop_entity_id,
2234
- c.is_anchor
2235
- FROM $categories_temp c
2236
- JOIN $stINch_categories_mapping scm
2237
- ON c.store_category_id = scm.store_category_id
2238
- )
2239
- ON DUPLICATE KEY UPDATE
2240
- value = c.is_anchor";
2241
- $this->db_do($q);
2242
-
2243
- $q = "
2244
- INSERT INTO $catalog_category_entity_varchar
2245
- (
2246
- entity_type_id,
2247
- attribute_id,
2248
- store_id,
2249
- entity_id,
2250
- value
2251
- )
2252
- (SELECT
2253
- $_categoryEntityTypeId,
2254
- $image_attrid,
2255
- 0,
2256
- scm.shop_entity_id,
2257
- c.categories_image
2258
- FROM $categories_temp c
2259
- JOIN $stINch_categories_mapping scm
2260
- ON c.store_category_id = scm.store_category_id
2261
- )
2262
- ON DUPLICATE KEY UPDATE
2263
- value = c.categories_image";
2264
- $this->db_do($q);
2265
- //STP
2266
  $q = "
2267
  INSERT INTO $catalog_category_entity_varchar
2268
  (
2269
- entity_type_id,
2270
- attribute_id,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2271
  store_id,
2272
- entity_id,
2273
  value
2274
  )
2275
- (SELECT
2276
  $this->_categoryEntityTypeId,
2277
  $this->_categoryMetaTitleAttrId,
2278
- 0,
2279
- scm.shop_entity_id,
2280
- c.MetaTitle
2281
- FROM $categories_temp c
2282
- JOIN $stINch_categories_mapping scm
2283
  ON c.store_category_id = scm.store_category_id
2284
  )
2285
  ON DUPLICATE KEY UPDATE
@@ -2289,20 +1805,20 @@ echo("\n\n$query\n\n");
2289
  $q = "
2290
  INSERT INTO $catalog_category_entity_varchar
2291
  (
2292
- entity_type_id,
2293
- attribute_id,
2294
  store_id,
2295
- entity_id,
2296
  value
2297
  )
2298
- (SELECT
2299
  $this->_categoryEntityTypeId,
2300
  $this->_categoryMetadescriptionAttrId,
2301
- 0,
2302
- scm.shop_entity_id,
2303
- c.MetaDescription
2304
- FROM $categories_temp c
2305
- JOIN $stINch_categories_mapping scm
2306
  ON c.store_category_id = scm.store_category_id
2307
  )
2308
  ON DUPLICATE KEY UPDATE
@@ -2312,20 +1828,20 @@ echo("\n\n$query\n\n");
2312
  $q = "
2313
  INSERT INTO $catalog_category_entity_varchar
2314
  (
2315
- entity_type_id,
2316
- attribute_id,
2317
  store_id,
2318
- entity_id,
2319
  value
2320
  )
2321
- (SELECT
2322
  $this->_categoryEntityTypeId,
2323
  $this->_categoryDescriptionAttrId,
2324
- 0,
2325
- scm.shop_entity_id,
2326
- c.Description
2327
- FROM $categories_temp c
2328
- JOIN $stINch_categories_mapping scm
2329
  ON c.store_category_id = scm.store_category_id
2330
  )
2331
  ON DUPLICATE KEY UPDATE
@@ -2333,138 +1849,132 @@ echo("\n\n$query\n\n");
2333
  $this->db_do($q);
2334
 
2335
 
2336
- //stp
2337
- }
2338
- else
2339
- {
2340
- echo "Insert ignore category_data \n";
2341
-
2342
- $q = "
2343
- INSERT IGNORE INTO $catalog_category_entity_varchar
2344
- (
2345
- entity_type_id,
2346
- attribute_id,
2347
- store_id,
2348
- entity_id,
2349
- value
2350
- )
2351
- (SELECT
2352
- $_categoryEntityTypeId,
2353
- $name_attrid,
2354
- 0,
2355
- scm.shop_entity_id,
2356
- c.category_name
2357
- FROM $categories_temp c
2358
- JOIN $stINch_categories_mapping scm
2359
- ON c.store_category_id = scm.store_category_id
2360
- )";
2361
- $this->db_do($q);
2362
-
2363
-
2364
- $q = "
2365
- INSERT IGNORE INTO $catalog_category_entity_int
2366
- (
2367
- entity_type_id,
2368
- attribute_id,
2369
- store_id,
2370
- entity_id,
2371
- value
2372
- )
2373
- (SELECT
2374
- $_categoryEntityTypeId,
2375
- $attr_is_active,
2376
- 0,
2377
- scm.shop_entity_id,
2378
- 1
2379
- FROM $categories_temp c
2380
- JOIN $stINch_categories_mapping scm
2381
- ON c.store_category_id = scm.store_category_id
2382
- )";
2383
- $this->db_do($q);
2384
-
2385
-
2386
- $q = "
2387
- INSERT IGNORE INTO $catalog_category_entity_int
2388
- (
2389
- entity_type_id,
2390
- attribute_id,
2391
- store_id,
2392
- entity_id,
2393
- value
2394
- )
2395
- (SELECT
2396
- $_categoryEntityTypeId,
2397
- $attr_include_in_menu,
2398
- 0,
2399
- scm.shop_entity_id,
2400
- c.include_in_menu
2401
- FROM $categories_temp c
2402
- JOIN $stINch_categories_mapping scm
2403
- ON c.store_category_id = scm.store_category_id
2404
- )";
2405
- $this->db_do($q);
2406
-
2407
-
2408
- $q = "
2409
- INSERT IGNORE INTO $catalog_category_entity_int
2410
- (
2411
- entity_type_id,
2412
- attribute_id,
2413
- store_id,
2414
- entity_id,
2415
- value
2416
- )
2417
- (SELECT
2418
- $_categoryEntityTypeId,
2419
- $is_anchor_attrid,
2420
- 0,
2421
- scm.shop_entity_id,
2422
- c.is_anchor
2423
- FROM $categories_temp c
2424
- JOIN $stINch_categories_mapping scm
2425
- ON c.store_category_id = scm.store_category_id
2426
- )";
2427
- $this->db_do($q);
2428
-
2429
-
2430
- $q = "
2431
- INSERT IGNORE INTO $catalog_category_entity_varchar
2432
- (
2433
- entity_type_id,
2434
- attribute_id,
2435
- store_id,
2436
- entity_id,
2437
- value
2438
- )
2439
- (SELECT
2440
- $_categoryEntityTypeId,
2441
- $image_attrid,
2442
- 0,
2443
- scm.shop_entity_id,
2444
- c.categories_image
2445
- FROM $categories_temp c
2446
- JOIN $stINch_categories_mapping scm
2447
- ON c.store_category_id = scm.store_category_id
2448
- )";
2449
- $this->db_do($q);
2450
- //STP
2451
  $q = "
2452
  INSERT IGNORE INTO $catalog_category_entity_varchar
2453
  (
2454
- entity_type_id,
2455
- attribute_id,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2456
  store_id,
2457
- entity_id,
2458
  value
2459
  )
2460
- (SELECT
2461
  $this->_categoryEntityTypeId,
2462
  $this->_categoryMetaTitleAttrId,
2463
- 0,
2464
- scm.shop_entity_id,
2465
- c.MetaTitle
2466
- FROM $categories_temp c
2467
- JOIN $stINch_categories_mapping scm
2468
  ON c.store_category_id = scm.store_category_id
2469
  )
2470
  ";
@@ -2473,20 +1983,20 @@ echo("\n\n$query\n\n");
2473
  $q = "
2474
  INSERT IGNORE INTO $catalog_category_entity_varchar
2475
  (
2476
- entity_type_id,
2477
- attribute_id,
2478
  store_id,
2479
- entity_id,
2480
  value
2481
  )
2482
- (SELECT
2483
  $this->_categoryEntityTypeId,
2484
  $this->_categoryMetadescriptionAttrId,
2485
- 0,
2486
- scm.shop_entity_id,
2487
- c.MetaDescription
2488
- FROM $categories_temp c
2489
- JOIN $stINch_categories_mapping scm
2490
  ON c.store_category_id = scm.store_category_id
2491
  )
2492
  ";
@@ -2495,20 +2005,20 @@ echo("\n\n$query\n\n");
2495
  $q = "
2496
  INSERT IGNORE INTO $catalog_category_entity_varchar
2497
  (
2498
- entity_type_id,
2499
- attribute_id,
2500
  store_id,
2501
- entity_id,
2502
  value
2503
  )
2504
- (SELECT
2505
  $this->_categoryEntityTypeId,
2506
  $this->_categoryDescriptionAttrId,
2507
- 0,
2508
- scm.shop_entity_id,
2509
- c.Description
2510
- FROM $categories_temp c
2511
- JOIN $stINch_categories_mapping scm
2512
  ON c.store_category_id = scm.store_category_id
2513
  )
2514
  ";
@@ -2516,4919 +2026,6294 @@ echo("\n\n$query\n\n");
2516
 
2517
 
2518
  //stp
2519
-
2520
- }
2521
 
2522
- $this->delete_old_sinch_categories_from_shop();
2523
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
2524
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
2525
- } // private function addCategoryDataMultistore(...)
2526
- ################################################################################################################################################################
2527
 
 
2528
 
 
 
 
2529
 
2530
- ################################################################################################################################################################
2531
- function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
2532
- {
2533
 
2534
- //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]");
2535
 
2536
- $path = '';
 
2537
 
2538
- $cat_id = $parent_id;
2539
 
2540
- $q = "
2541
- SELECT
2542
- parent_id
2543
- FROM $catalog_category_entity
2544
- WHERE entity_id = $cat_id";
2545
- $quer = $this->db_do($q);
2546
- $row = mysqli_fetch_array($quer);
2547
- while ($row['parent_id'])
2548
- {
2549
- $path = $row['parent_id'].'/'.$path;
2550
- $parent_id = $row['parent_id'];
 
 
 
 
 
2551
 
2552
- $q = "
2553
- SELECT
2554
- parent_id
2555
- FROM $catalog_category_entity
2556
- WHERE entity_id = $parent_id";
2557
- $quer = $this->db_do($q);
2558
- $row = mysqli_fetch_array($quer);
2559
- }
2560
 
2561
- if ($cat_id) $path.=$cat_id."/";
 
 
 
 
2562
 
2563
- if ($path) $path .= $ent_id;
2564
- else $path = $ent_id;
2565
 
2566
- //echo(" path = [$path]\n");
2567
 
2568
- return $path;
2569
- } // function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
2570
- ################################################################################################################################################################
2571
 
 
 
2572
 
 
 
 
 
 
 
 
2573
 
 
 
 
 
 
 
 
2574
 
 
 
 
 
 
 
 
2575
 
 
2576
 
 
2577
 
 
 
 
 
 
 
2578
 
2579
- ################################################################################################################################################################
2580
- public function replaceMagentoProductsMultistoreMERGE($coincidence)
2581
- {
2582
 
2583
- echo("\n replaceMagentoProductsMultistoreMERGE 1\n");
 
 
 
2584
 
2585
 
 
 
 
 
2586
 
2587
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
2588
 
 
 
 
2589
 
2590
- $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
2591
- $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
2592
- $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
2593
- $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
2594
- $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
2595
- $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
2596
- $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
2597
- $stINch_products = Mage::getSingleton('core/resource')->getTableName('stINch_products');
2598
- $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
2599
- $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
2600
- $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
2601
- $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
2602
- $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
2603
- $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
2604
- //STP DELETE $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
2605
- // $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
2606
- $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
2607
 
2608
- $_getProductEntityTypeId = $this->_getProductEntityTypeId();
2609
- $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
 
 
 
2610
 
2611
- $attr_atatus = $this->_getProductAttributeId('status');
2612
- $attr_name = $this->_getProductAttributeId('name');
2613
- $attr_visibility = $this->_getProductAttributeId('visibility');
2614
- $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
2615
- $attr_image = $this->_getProductAttributeId('image');
2616
- $attr_small_image = $this->_getProductAttributeId('small_image');
2617
- $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
2618
 
2619
- $cat_attr_name = $this->_getCategoryAttributeId('name');
2620
- echo("\n replaceMagentoProductsMultistoreMERGE 2\n");
2621
 
 
2622
 
 
 
 
 
2623
 
2624
 
 
 
 
2625
 
2626
- //clear products, inserting new products and updating old others.
2627
- $query = "
2628
- DELETE cpe
2629
- FROM $catalog_product_entity cpe
2630
- JOIN $stINch_products_mapping pm
2631
- ON cpe.entity_id = pm.entity_id
2632
- WHERE pm.shop_store_product_id IS NOT NULL
2633
- AND pm.store_product_id IS NULL";
2634
- $result = $this->db_do($query);
2635
 
 
 
 
 
 
2636
 
2637
 
 
 
 
 
 
 
2638
 
2639
 
2640
- echo("\n replaceMagentoProductsMultistoreMERGE 3\n");
 
 
 
 
2641
 
2642
- $result = $this->db_do("
2643
- INSERT INTO $catalog_product_entity
2644
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
2645
- (SELECT
2646
- pm.entity_id,
2647
- $_getProductEntityTypeId,
2648
- $_defaultAttributeSetId,
2649
- 'simple',
2650
- a.product_sku,
2651
- NOW(),
2652
- 0,
2653
- a.store_product_id,
2654
- a.sinch_product_id
2655
- FROM $products_temp a
2656
- LEFT JOIN $stINch_products_mapping pm
2657
- ON a.store_product_id = pm.store_product_id
2658
- AND a.sinch_product_id = pm.sinch_product_id
2659
- WHERE pm.entity_id IS NOT NULL
2660
- )
2661
- ON DUPLICATE KEY UPDATE
2662
- sku = a.product_sku,
2663
- store_product_id = a.store_product_id,
2664
- sinch_product_id = a.sinch_product_id");
2665
- // store_product_id = a.store_product_id,
2666
- // sinch_product_id = a.sinch_product_id
2667
-
2668
- $result = $this->db_do("
2669
- INSERT INTO $catalog_product_entity
2670
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
2671
- (SELECT
2672
- pm.entity_id,
2673
- $_getProductEntityTypeId,
2674
- $_defaultAttributeSetId,
2675
- 'simple',
2676
- a.product_sku,
2677
- NOW(),
2678
- 0,
2679
- a.store_product_id,
2680
- a.sinch_product_id
2681
- FROM $products_temp a
2682
- LEFT JOIN $stINch_products_mapping pm
2683
- ON a.store_product_id = pm.store_product_id
2684
- AND a.sinch_product_id = pm.sinch_product_id
2685
- WHERE pm.entity_id IS NULL
2686
- )
2687
- ON DUPLICATE KEY UPDATE
2688
- sku = a.product_sku,
2689
- store_product_id = a.store_product_id,
2690
- sinch_product_id = a.sinch_product_id");
2691
- // store_product_id = a.store_product_id,
2692
- // sinch_product_id = a.sinch_product_id
2693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2694
 
2695
- echo("\n replaceMagentoProductsMultistoreMERGE 4\n");
2696
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2698
 
 
2699
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2700
 
2701
- //Set enabled
2702
- $result = $this->db_do("
2703
- DELETE cpei
2704
- FROM $catalog_product_entity_int cpei
2705
- LEFT JOIN $catalog_product_entity cpe
2706
- ON cpei.entity_id = cpe.entity_id
2707
- WHERE cpe.entity_id IS NULL");
2708
 
2709
- $result = $this->db_do("
2710
- INSERT INTO $catalog_product_entity_int
2711
- (entity_type_id, attribute_id, store_id, entity_id, value)
2712
- (SELECT
2713
- $_getProductEntityTypeId,
2714
- $attr_atatus,
2715
- w.website,
2716
- a.entity_id,
2717
- 1
2718
- FROM $catalog_product_entity a
2719
- JOIN $products_website_temp w
2720
- ON a.store_product_id = w.store_product_id
2721
- )
2722
- ON DUPLICATE KEY UPDATE
2723
- value = 1");
2724
 
 
2725
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2726
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2727
 
 
2728
 
2729
- echo("\n replaceMagentoProductsMultistoreMERGE 5\n");
2730
 
 
2731
 
2732
- // set status = 1 for all stores
2733
- $result = $this->db_do("
2734
- INSERT INTO $catalog_product_entity_int
2735
- (entity_type_id, attribute_id, store_id, entity_id, value)
2736
- (SELECT
2737
- $_getProductEntityTypeId,
2738
- $attr_atatus,
2739
- 0,
2740
- a.entity_id,
2741
- 1
2742
- FROM $catalog_product_entity a
2743
- )
2744
- ON DUPLICATE KEY UPDATE
2745
- value = 1");
2746
 
 
 
 
 
2747
 
 
2748
 
 
 
 
 
 
2749
 
2750
 
2751
- echo("\n replaceMagentoProductsMultistoreMERGE 6\n");
2752
 
2753
 
2754
- //Unifying products with categories.
2755
- $result = $this->db_do("
2756
- DELETE ccp
2757
- FROM $catalog_category_product ccp
2758
- LEFT JOIN $catalog_product_entity cpe
2759
- ON ccp.product_id = cpe.entity_id
2760
- WHERE cpe.entity_id IS NULL");
2761
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2762
 
2763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2764
 
2765
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2766
 
2767
 
2768
- echo("\n replaceMagentoProductsMultistoreMERGE 7\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2769
 
2770
 
2771
- $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2772
 
2773
- $result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
2774
- $result = $this->db_do("
2775
- CREATE TABLE $root_cats
2776
- SELECT
2777
- entity_id,
2778
- path,
2779
- SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
2780
- LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
2781
- SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
2782
- FROM $catalog_category_entity
2783
- ");
2784
- $result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
2785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2786
 
2787
- echo("\n replaceMagentoProductsMultistoreMERGE 8\n");
2788
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2789
 
2790
- // !!! $this->_root_cat
2791
- $result = $this->db_do("
2792
- UPDATE IGNORE $catalog_category_product ccp
2793
- LEFT JOIN $catalog_category_entity cce
2794
- ON ccp.category_id = cce.entity_id
2795
- JOIN $root_cats rc
2796
- ON cce.entity_id = rc.entity_id
2797
- SET ccp.category_id = rc.root_cat
2798
- WHERE cce.entity_id IS NULL");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2799
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2800
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2801
 
2802
- echo("\n replaceMagentoProductsMultistoreMERGE 9\n");
2803
 
 
 
 
2804
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2805
 
2806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2807
 
2808
- $result = $this->db_do("
2809
- DELETE ccp
2810
- FROM $catalog_category_product ccp
2811
- LEFT JOIN $catalog_category_entity cce
2812
- ON ccp.category_id = cce.entity_id
2813
- WHERE cce.entity_id IS NULL");
2814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2815
 
2816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2817
 
2818
- $stinch_products_delete = Mage::getSingleton('core/resource')->getTableName('stinch_products_delete');
2819
 
2820
- $result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
2821
- $result = $this->db_do("
2822
- CREATE TABLE $stinch_products_delete
2823
- SELECT cpe.entity_id
2824
- FROM $catalog_product_entity cpe
2825
- WHERE cpe.entity_id NOT IN
2826
- (
2827
- SELECT cpe2.entity_id
2828
- FROM $catalog_product_entity cpe2
2829
- JOIN $stINch_products sp
2830
- ON cpe2.sinch_product_id = sp.sinch_product_id
2831
- )");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2832
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2833
 
2834
- $result = $this->db_do("DELETE cpe FROM $catalog_product_entity cpe JOIN $stinch_products_delete spd USING(entity_id)");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2835
 
2836
- $result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
2837
 
 
2838
 
 
2839
 
 
 
 
 
2840
 
 
2841
 
 
 
2842
 
2843
- //echo("\n\nget out...\n\n");
2844
- //return;
2845
 
2846
- /**
2847
 
2848
- echo("\n replaceMagentoProductsMultistoreMERGE 10\n");
2849
 
 
 
 
 
 
 
 
 
 
 
2850
 
2851
- // TEMPORARY
2852
- $this->db_do(" DROP TABLE IF EXISTS {$catalog_category_product}_for_delete_temp");
2853
- $this->db_do("
2854
- CREATE TABLE `{$catalog_category_product}_for_delete_temp`
2855
- (
2856
- `category_id` int(10) unsigned NOT NULL default '0',
2857
- `product_id` int(10) unsigned NOT NULL default '0',
2858
- `store_product_id` int(10) NOT NULL default '0',
2859
- `store_category_id` int(10) NOT NULL default '0',
2860
- `new_category_id` int(10) NOT NULL default '0',
2861
 
2862
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
2863
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
2864
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
2865
- KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
2866
- )");
2867
 
2868
- echo("\n replaceMagentoProductsMultistoreMERGE 11\n");
 
2869
 
2870
- $result = $this->db_do("
2871
- INSERT INTO {$catalog_category_product}_for_delete_temp
2872
- (category_id, product_id, store_product_id)
2873
- (SELECT
2874
- ccp.category_id,
2875
- ccp.product_id,
2876
- cpe.store_product_id
2877
- FROM $catalog_category_product ccp
2878
- JOIN $catalog_product_entity cpe
2879
- ON ccp.product_id = cpe.entity_id
2880
- WHERE store_product_id IS NOT NULL)");
2881
 
2882
- echo("\n replaceMagentoProductsMultistoreMERGE 12\n");
 
2883
 
2884
- $result = $this->db_do("
2885
- UPDATE {$catalog_category_product}_for_delete_temp ccpfd
2886
- JOIN $products_temp p
2887
- ON ccpfd.store_product_id = p.store_product_id
2888
- SET ccpfd.store_category_id = p.store_category_id
2889
- WHERE ccpfd.store_product_id != 0");
2890
 
2891
- echo("\n replaceMagentoProductsMultistoreMERGE 13\n");
 
 
 
 
 
2892
 
2893
- $result = $this->db_do("
2894
- UPDATE {$catalog_category_product}_for_delete_temp ccpfd
2895
- JOIN $stINch_categories_mapping scm
2896
- ON ccpfd.store_category_id = scm.store_category_id
2897
- SET ccpfd.new_category_id = scm.shop_entity_id
2898
- WHERE ccpfd.store_category_id != 0");
2899
 
2900
- echo("\n replaceMagentoProductsMultistoreMERGE 14\n");
 
2901
 
2902
- $result = $this->db_do("DELETE FROM {$catalog_category_product}_for_delete_temp WHERE category_id = new_category_id");
2903
 
 
2904
 
2905
 
2906
- $result = $this->db_do("
2907
- DELETE ccp
2908
- FROM $catalog_category_product ccp
2909
- JOIN {$catalog_category_product}_for_delete_temp ccpfd
2910
- ON ccp.product_id = ccpfd.product_id
2911
- AND ccp.category_id = ccpfd.category_id");
2912
 
2913
- /**/
2914
 
 
 
2915
 
 
2916
 
2917
- echo("\n replaceMagentoProductsMultistoreMERGE 15\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2918
 
 
2919
 
2920
 
 
 
2921
 
2922
- $result = $this->db_do("
2923
- INSERT INTO $catalog_category_product
2924
- (category_id, product_id)
2925
- (SELECT
2926
- scm.shop_entity_id,
2927
- cpe.entity_id
2928
- FROM $catalog_product_entity cpe
2929
- JOIN $products_temp p
2930
- ON cpe.store_product_id = p.store_product_id
2931
- JOIN $stINch_categories_mapping scm
2932
- ON p.store_category_id = scm.store_category_id
2933
- )
2934
- ON DUPLICATE KEY UPDATE
2935
- product_id = cpe.entity_id");
2936
 
 
2937
 
 
 
2938
 
2939
- echo("\n replaceMagentoProductsMultistoreMERGE 15.1 (add multi categories)\n");
2940
 
 
 
 
 
 
 
 
 
 
2941
 
2942
 
 
 
 
 
 
 
2943
 
2944
- $result = $this->db_do("
2945
- INSERT INTO $catalog_category_product
2946
- (category_id, product_id)
2947
- (SELECT
2948
- scm.shop_entity_id,
2949
- cpe.entity_id
2950
- FROM $catalog_product_entity cpe
2951
- JOIN $products_temp p
2952
- ON cpe.store_product_id = p.store_product_id
2953
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
2954
- ON p.store_product_id=spc.store_product_id
2955
- JOIN $stINch_categories_mapping scm
2956
- ON spc.store_category_id = scm.store_category_id
2957
- )
2958
- ON DUPLICATE KEY UPDATE
2959
- product_id = cpe.entity_id
2960
- ");
2961
 
 
 
 
 
 
2962
 
2963
 
2964
- echo("\n replaceMagentoProductsMultistoreMERGE 16\n");
 
 
 
 
 
 
2965
 
2966
- //Indexing products and categories in the shop
2967
- $result = $this->db_do("
2968
- DELETE ccpi
2969
- FROM $catalog_category_product_index ccpi
2970
- LEFT JOIN $catalog_product_entity cpe
2971
- ON ccpi.product_id = cpe.entity_id
2972
- WHERE cpe.entity_id IS NULL");
2973
 
 
 
 
 
 
 
 
 
 
2974
 
 
2975
 
 
2976
 
 
2977
 
2978
- echo("\n replaceMagentoProductsMultistoreMERGE 16.2\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2979
 
2980
 
2981
- $result = $this->db_do("
2982
- INSERT INTO $catalog_category_product_index
2983
- (category_id, product_id, position, is_parent, store_id, visibility)
2984
- (SELECT
2985
- a.category_id,
2986
- a.product_id,
2987
- a.position,
2988
- 1,
2989
- b.store_id,
2990
- 4
2991
- FROM $catalog_category_product a
2992
- JOIN $core_store b
2993
- )
2994
- ON DUPLICATE KEY UPDATE
2995
- visibility = 4");
2996
 
 
 
 
 
 
 
 
 
2997
 
 
 
 
2998
 
2999
- echo("\n replaceMagentoProductsMultistoreMERGE 17\n");
3000
- $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
3001
- // !!! $this->_root_cat
3002
- $result = $this->db_do("
3003
- INSERT ignore INTO $catalog_category_product_index
3004
- (category_id, product_id, position, is_parent, store_id, visibility)
3005
- (SELECT
3006
- rc.root_cat,
3007
- a.product_id,
3008
- a.position,
3009
- 1,
3010
- b.store_id,
3011
- 4
3012
- FROM $catalog_category_product a
3013
- JOIN $root_cats rc
3014
- ON a.category_id = rc.entity_id
3015
- JOIN $core_store b
3016
- )
3017
- ON DUPLICATE KEY UPDATE
3018
- visibility = 4");
3019
-
3020
- echo("\n replaceMagentoProductsMultistoreMERGE 18\n");
3021
-
3022
-
3023
- //Set product name for specific web sites
3024
- $result = $this->db_do("
3025
- DELETE cpev
3026
- FROM $catalog_product_entity_varchar cpev
3027
- LEFT JOIN $catalog_product_entity cpe
3028
- ON cpev.entity_id = cpe.entity_id
3029
- WHERE cpe.entity_id IS NULL");
3030
-
3031
- $result = $this->db_do("
3032
- INSERT INTO $catalog_product_entity_varchar
3033
- (entity_type_id, attribute_id, store_id, entity_id, value)
3034
- (SELECT
3035
- $_getProductEntityTypeId,
3036
- $attr_name,
3037
- w.website,
3038
- a.entity_id,
3039
- b.product_name
3040
- FROM $catalog_product_entity a
3041
- JOIN $products_temp b
3042
- ON a.store_product_id = b.store_product_id
3043
- JOIN $products_website_temp w
3044
- ON a.store_product_id = w.store_product_id
3045
- )
3046
- ON DUPLICATE KEY UPDATE
3047
- value = b.product_name");
3048
-
3049
- echo("\n replaceMagentoProductsMultistoreMERGE 19\n");
3050
-
3051
-
3052
-
3053
-
3054
-
3055
- // product name for all web sites
3056
- $result = $this->db_do("
3057
- INSERT INTO $catalog_product_entity_varchar
3058
- (entity_type_id, attribute_id, store_id, entity_id, value)
3059
- (SELECT
3060
- $_getProductEntityTypeId,
3061
- $attr_name,
3062
- 0,
3063
- a.entity_id,
3064
- b.product_name
3065
- FROM $catalog_product_entity a
3066
- JOIN $products_temp b
3067
- ON a.store_product_id = b.store_product_id
3068
- )
3069
- ON DUPLICATE KEY UPDATE
3070
- value = b.product_name");
3071
-
3072
- echo("\n replaceMagentoProductsMultistoreMERGE 20\n");
3073
-
3074
-
3075
-
3076
- $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
3077
- $this->addDescriptions();
3078
- $this->cleanProductDistributors();
3079
- if($this->product_file_format == "NEW"){
3080
- $this->addReviews();
3081
- $this->addWeight();
3082
- $this->addSearchCache();
3083
- $this->addPdfUrl();
3084
- $this->addShortDescriptions();
3085
- $this->addProductDistributors();
3086
- }
3087
- $this->addEAN();
3088
- $this->addSpecification();
3089
- $this->addManufacturers();
3090
-
3091
 
 
 
3092
 
 
3093
 
 
 
 
 
 
3094
 
3095
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3096
 
3097
- echo("\n replaceMagentoProductsMultistoreMERGE 21\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3098
 
3099
- //Enabling product index.
3100
- $result = $this->db_do("
3101
- DELETE cpei
3102
- FROM $catalog_product_enabled_index cpei
3103
- LEFT JOIN $catalog_product_entity cpe
3104
- ON cpei.product_id = cpe.entity_id
3105
- WHERE cpe.entity_id IS NULL");
3106
 
 
3107
 
3108
 
 
 
3109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3110
 
3111
 
3112
- echo("\n replaceMagentoProductsMultistoreMERGE 22\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3113
 
3114
- $result = $this->db_do("
3115
- INSERT INTO $catalog_product_enabled_index
3116
- (product_id, store_id, visibility)
3117
- (SELECT
3118
- a.entity_id,
3119
- w.website,
3120
- 4
3121
- FROM $catalog_product_entity a
3122
- JOIN $products_website_temp w
3123
- ON a.store_product_id = w.store_product_id
3124
- )
3125
- ON DUPLICATE KEY UPDATE
3126
- visibility = 4");
3127
 
3128
- echo("\n replaceMagentoProductsMultistoreMERGE 23\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3129
 
3130
- $result = $this->db_do("
3131
- INSERT INTO $catalog_product_enabled_index
3132
- (product_id, store_id, visibility)
3133
- (SELECT
3134
- a.entity_id,
3135
- 0,
3136
- 4
3137
- FROM $catalog_product_entity a
3138
- JOIN $products_website_temp w
3139
- ON a.store_product_id = w.store_product_id
3140
- )
3141
- ON DUPLICATE KEY UPDATE
3142
- visibility = 4");
3143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3144
 
3145
- /////////////////////////////////////echo(" .... DONE\n");return;
3146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3147
 
3148
- echo("\n replaceMagentoProductsMultistoreMERGE 24\n");
3149
 
3150
- $result = $this->db_do("
3151
- INSERT INTO $catalog_product_entity_int
3152
- (entity_type_id, attribute_id, store_id, entity_id, value)
3153
- (SELECT
3154
- $_getProductEntityTypeId,
3155
- $attr_visibility,
3156
- w.website,
3157
- a.entity_id,
3158
- 4
3159
- FROM $catalog_product_entity a
3160
- JOIN $products_website_temp w
3161
- ON a.store_product_id = w.store_product_id
3162
- )
3163
- ON DUPLICATE KEY UPDATE
3164
- value = 4");
 
 
 
 
 
 
 
3165
 
3166
- echo("\n replaceMagentoProductsMultistoreMERGE 25\n");
3167
 
3168
- $result = $this->db_do("
3169
- INSERT INTO $catalog_product_entity_int
3170
- (entity_type_id, attribute_id, store_id, entity_id, value)
3171
- (SELECT
3172
- $_getProductEntityTypeId,
3173
- $attr_visibility,
3174
- 0,
3175
- a.entity_id,
3176
- 4
3177
- FROM $catalog_product_entity a
3178
- )
3179
- ON DUPLICATE KEY UPDATE
3180
- value = 4");
 
 
 
 
 
 
 
 
 
3181
 
3182
- echo("\n replaceMagentoProductsMultistoreMERGE 26\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3185
 
3186
- $result = $this->db_do("
3187
- DELETE cpw
3188
- FROM $catalog_product_website cpw
3189
- LEFT JOIN $catalog_product_entity cpe
3190
- ON cpw.product_id = cpe.entity_id
3191
- WHERE cpe.entity_id IS NULL");
3192
 
3193
- echo("\n replaceMagentoProductsMultistoreMERGE 27\n");
 
 
3194
 
3195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3196
 
3197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3198
 
3199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3200
 
3201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3202
 
3203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3204
 
3205
- $result = $this->db_do("
3206
- INSERT INTO $catalog_product_website
3207
- (product_id, website_id)
3208
- (SELECT
3209
- a.entity_id,
3210
- w.website_id
3211
- FROM $catalog_product_entity a
3212
- JOIN $products_website_temp w
3213
- ON a.store_product_id = w.store_product_id
3214
- )
3215
- ON DUPLICATE KEY UPDATE
3216
- product_id = a.entity_id,
3217
- website_id = w.website_id");
 
 
 
 
 
 
 
 
3218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3219
 
3220
- //echo(" .... DONE\n");return;
3221
 
 
3222
 
3223
- echo("\n replaceMagentoProductsMultistoreMERGE 28\n");
3224
-
3225
- // temporary disabled mart@bintime.com
3226
- //$result = $this->db_do("
3227
- // UPDATE catalog_category_entity_int a
3228
- // SET a.value = 0
3229
- // WHERE a.attribute_id = 32
3230
- //");
3231
-
3232
-
3233
- //Adding tax class "Taxable Goods"
3234
- $result = $this->db_do("
3235
- INSERT INTO $catalog_product_entity_int
3236
- (entity_type_id, attribute_id, store_id, entity_id, value)
3237
- (SELECT
3238
- $_getProductEntityTypeId,
3239
- $attr_tax_class_id,
3240
- w.website,
3241
- a.entity_id,
3242
- 2
3243
- FROM $catalog_product_entity a
3244
- JOIN $products_website_temp w
3245
- ON a.store_product_id = w.store_product_id
3246
- )
3247
- ON DUPLICATE KEY UPDATE
3248
- value = 2");
3249
-
3250
- echo("\n replaceMagentoProductsMultistoreMERGE 29\n");
3251
-
3252
- $result = $this->db_do("
3253
- INSERT INTO $catalog_product_entity_int
3254
- (entity_type_id, attribute_id, store_id, entity_id, value)
3255
- (SELECT
3256
- $_getProductEntityTypeId,
3257
- $attr_tax_class_id,
3258
- 0,
3259
- a.entity_id,
3260
- 2
3261
- FROM $catalog_product_entity a
3262
- )
3263
- ON DUPLICATE KEY UPDATE
3264
- value = 2");
3265
-
3266
- echo("\n replaceMagentoProductsMultistoreMERGE 30\n");
3267
-
3268
- // Load url Image
3269
- $result = $this->db_do("
3270
- INSERT INTO $catalog_product_entity_varchar
3271
- (entity_type_id, attribute_id, store_id, entity_id, value)
3272
- (SELECT
3273
- $_getProductEntityTypeId,
3274
- $attr_image,
3275
- w.store_id,
3276
- a.entity_id,
3277
- b.main_image_url
3278
- FROM $catalog_product_entity a
3279
- JOIN $core_store w
3280
- JOIN $products_temp b
3281
- ON a.store_product_id = b.store_product_id
3282
- )
3283
- ON DUPLICATE KEY UPDATE
3284
- value = b.main_image_url");
3285
-
3286
- echo("\n replaceMagentoProductsMultistoreMERGE 31\n");
3287
-
3288
- // image for specific web sites
3289
- $result = $this->db_do("
3290
- INSERT INTO $catalog_product_entity_varchar
3291
- (entity_type_id, attribute_id, store_id, entity_id, value)
3292
- (SELECT
3293
- $_getProductEntityTypeId,
3294
- $attr_image,
3295
- 0,
3296
- a.entity_id,
3297
- b.main_image_url
3298
- FROM $catalog_product_entity a
3299
- JOIN $products_temp b
3300
- ON a.store_product_id = b.store_product_id
3301
- )
3302
- ON DUPLICATE KEY UPDATE
3303
- value = b.main_image_url");
3304
-
3305
- echo("\n replaceMagentoProductsMultistoreMERGE 32\n");
3306
-
3307
- // small_image for specific web sites
3308
- $result = $this->db_do("
3309
- INSERT INTO $catalog_product_entity_varchar
3310
- (entity_type_id, attribute_id, store_id, entity_id, value)
3311
- (SELECT
3312
- $_getProductEntityTypeId,
3313
- $attr_small_image,
3314
- w.store_id,
3315
- a.entity_id,
3316
- b.medium_image_url
3317
- FROM $catalog_product_entity a
3318
- JOIN $core_store w
3319
- JOIN $products_temp b
3320
- ON a.store_product_id = b.store_product_id
3321
- )
3322
- ON DUPLICATE KEY UPDATE
3323
- value = b.medium_image_url");
3324
-
3325
- echo("\n replaceMagentoProductsMultistoreMERGE 33\n");
3326
-
3327
- // small_image for all web sites
3328
- $result = $this->db_do("
3329
- INSERT INTO $catalog_product_entity_varchar
3330
- (entity_type_id, attribute_id, store_id, entity_id, value)
3331
- (SELECT
3332
- $_getProductEntityTypeId,
3333
- $attr_small_image,
3334
- 0,
3335
- a.entity_id,
3336
- b.medium_image_url
3337
- FROM $catalog_product_entity a
3338
- JOIN $core_store w
3339
- JOIN $products_temp b
3340
- ON a.store_product_id = b.store_product_id
3341
- )
3342
- ON DUPLICATE KEY UPDATE
3343
- value = b.medium_image_url");
3344
-
3345
- echo("\n replaceMagentoProductsMultistoreMERGE 34\n");
3346
-
3347
- // thumbnail for specific web site
3348
- $result = $this->db_do("
3349
- INSERT INTO $catalog_product_entity_varchar
3350
- (entity_type_id, attribute_id, store_id, entity_id, value)
3351
- (SELECT
3352
- $_getProductEntityTypeId,
3353
- $attr_thumbnail,
3354
- w.store_id,
3355
- a.entity_id,
3356
- b.thumb_image_url
3357
- FROM $catalog_product_entity a
3358
- JOIN $core_store w
3359
- JOIN $products_temp b
3360
- ON a.store_product_id = b.store_product_id
3361
- )
3362
- ON DUPLICATE KEY UPDATE
3363
- value = b.thumb_image_url");
3364
-
3365
- echo("\n replaceMagentoProductsMultistoreMERGE 35\n");
3366
-
3367
- // thumbnail for all web sites
3368
- $result = $this->db_do("
3369
- INSERT INTO $catalog_product_entity_varchar
3370
- (entity_type_id, attribute_id, store_id, entity_id, value)
3371
- (SELECT
3372
- $_getProductEntityTypeId,
3373
- $attr_thumbnail,
3374
- 0,
3375
- a.entity_id,
3376
- b.thumb_image_url
3377
- FROM $catalog_product_entity a
3378
- JOIN $core_store w
3379
- JOIN $products_temp b
3380
- ON a.store_product_id = b.store_product_id
3381
- )
3382
- ON DUPLICATE KEY UPDATE
3383
- value = b.thumb_image_url");
3384
-
3385
- echo("\n replaceMagentoProductsMultistoreMERGE 36\n");
3386
-
3387
-
3388
-
3389
-
3390
-
3391
- /* STP DELETE
3392
- //Refresh fulltext search
3393
- $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
3394
- $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
3395
 
3396
 
3397
- echo("\n replaceMagentoProductsMultistoreMERGE 36.2\n");
3398
- $q = "
3399
- INSERT INTO {$catalogsearch_fulltext}_tmp
3400
- (product_id, store_id, data_index)
3401
- (SELECT
3402
- a.entity_id,
3403
- w.website,
3404
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3405
- FROM $catalog_product_entity a
3406
- JOIN $products_website_temp w
3407
- ON a.store_product_id = w.store_product_id
3408
- LEFT JOIN $catalog_category_product b
3409
- ON a.entity_id = b.product_id
3410
- LEFT JOIN $catalog_category_entity_varchar c
3411
- ON b.category_id = c.entity_id
3412
- AND c.attribute_id = $cat_attr_name
3413
- LEFT JOIN $catalog_product_entity_varchar e
3414
- ON a.entity_id = e.entity_id
3415
- AND e.attribute_id = $attr_name
3416
- LEFT JOIN $catalog_product_website j
3417
- ON a.entity_id = j.product_id
3418
- LEFT JOIN $products_temp f
3419
- ON a.store_product_id = f.store_product_id
3420
- )
3421
- ON DUPLICATE KEY UPDATE
3422
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
3423
- echo("\n\n============================\n$q\n============================\n\n");
3424
 
 
 
3425
 
3426
- $result = $this->db_do("
3427
- INSERT INTO {$catalogsearch_fulltext}_tmp
3428
- (product_id, store_id, data_index)
3429
- (SELECT
3430
- a.entity_id,
3431
- w.website,
3432
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3433
- FROM $catalog_product_entity a
3434
- JOIN $products_website_temp w
3435
- ON a.store_product_id = w.store_product_id
3436
- LEFT JOIN $catalog_category_product b
3437
- ON a.entity_id = b.product_id
3438
- LEFT JOIN $catalog_category_entity_varchar c
3439
- ON b.category_id = c.entity_id
3440
- AND c.attribute_id = $cat_attr_name
3441
- LEFT JOIN $catalog_product_entity_varchar e
3442
- ON a.entity_id = e.entity_id
3443
- AND e.attribute_id = $attr_name
3444
- LEFT JOIN $catalog_product_website j
3445
- ON a.entity_id = j.product_id
3446
- LEFT JOIN $products_temp f
3447
- ON a.store_product_id = f.store_product_id
3448
- )
3449
- ON DUPLICATE KEY UPDATE
3450
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
3451
 
3452
- echo("\n replaceMagentoProductsMultistoreMERGE 37\n");
3453
 
 
3454
 
3455
- $result = $this->db_do("
3456
- INSERT INTO {$catalogsearch_fulltext}_tmp
3457
- (product_id, store_id, data_index)
3458
- (SELECT
3459
- a.entity_id,
3460
- w.website,
3461
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
3462
- FROM $catalog_product_entity a
3463
- JOIN $products_website_temp w
3464
- ON a.store_product_id = w.store_product_id
3465
- LEFT JOIN $catalog_category_product b
3466
- ON a.entity_id = b.product_id
3467
- LEFT JOIN $catalog_category_entity_varchar c
3468
- ON b.category_id = c.entity_id
3469
- AND c.attribute_id = $cat_attr_name
3470
- LEFT JOIN $catalog_product_entity_varchar e
3471
- ON a.entity_id = e.entity_id
3472
- AND e.attribute_id = $attr_name
3473
- LEFT JOIN $products_temp f
3474
- ON a.store_product_id = f.store_product_id
3475
- )
3476
- ON DUPLICATE KEY UPDATE
3477
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
3478
 
3479
- echo("\n replaceMagentoProductsMultistoreMERGE 38\n");
 
3480
 
3481
- $result = $this->db_do("
3482
- DELETE cf
3483
- FROM $catalogsearch_fulltext cf
3484
- LEFT JOIN $catalog_product_entity cpe
3485
- ON cf.product_id = cpe.entity_id
3486
- WHERE cpe.entity_id IS NULL");
3487
 
3488
- echo("\n replaceMagentoProductsMultistoreMERGE 39\n");
3489
 
3490
- $result = $this->db_do("
3491
- INSERT INTO $catalogsearch_fulltext
3492
- (product_id, store_id, data_index)
3493
- (SELECT
3494
- a.product_id,
3495
- a.store_id,
3496
- a.data_index
3497
- FROM {$catalogsearch_fulltext}_tmp a
3498
- )
3499
- ON DUPLICATE KEY UPDATE
3500
- data_index = a.data_index");
3501
 
3502
- echo("\n replaceMagentoProductsMultistoreMERGE 40\n");
3503
 
3504
- $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
3505
- //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
3506
- //TODO add something else
3507
- STP DELETE*/
3508
 
3509
- $this->addRelatedProducts();
3510
- echo("\n replaceMagentoProductsMultistoreMERGE 41\n");
3511
- } //
3512
- ################################################################################################################################################################
3513
 
 
 
 
 
 
 
 
 
 
 
 
3514
 
 
 
3515
 
3516
 
 
 
 
3517
 
3518
 
 
 
 
3519
 
3520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3521
 
 
3522
 
 
3523
 
 
 
 
 
 
 
 
 
 
3524
 
 
3525
 
 
 
3526
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3527
 
 
 
 
 
 
 
 
 
 
 
 
3528
 
 
 
 
 
 
 
3529
 
 
3530
 
 
 
3531
 
 
 
 
 
 
 
 
 
 
 
 
3532
 
 
 
 
 
 
 
3533
 
 
 
 
3534
 
 
 
 
 
 
 
3535
 
3536
 
 
3537
 
 
 
 
 
 
3538
 
 
 
 
 
 
 
 
 
 
 
 
3539
 
 
 
 
 
 
 
3540
 
3541
- ################################################################################################################################################################
3542
- public function replaceMagentoProductsMultistore($coincidence)
3543
- {
3544
-
3545
- echo("\n replaceMagentoProductsMultistore 1\n");
3546
-
3547
-
3548
-
3549
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
3550
-
3551
-
3552
- $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
3553
- $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
3554
- $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
3555
- $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
3556
- $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
3557
- $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
3558
- $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
3559
- $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
3560
- $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
3561
- $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
3562
- $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
3563
- $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
3564
- $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
3565
- //STP DELETE $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
3566
- // $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
3567
- $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
3568
-
3569
- $_getProductEntityTypeId = $this->_getProductEntityTypeId();
3570
- $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
3571
-
3572
- $attr_atatus = $this->_getProductAttributeId('status');
3573
- $attr_name = $this->_getProductAttributeId('name');
3574
- $attr_visibility = $this->_getProductAttributeId('visibility');
3575
- $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
3576
- $attr_image = $this->_getProductAttributeId('image');
3577
- $attr_small_image = $this->_getProductAttributeId('small_image');
3578
- $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
3579
-
3580
- $cat_attr_name = $this->_getCategoryAttributeId('name');
3581
- echo("\n replaceMagentoProductsMultistore 2\n");
3582
-
3583
-
3584
-
3585
-
3586
-
3587
- //clear products, inserting new products and updating old others.
3588
- $query = "
3589
- DELETE cpe
3590
- FROM $catalog_product_entity cpe
3591
- JOIN $stINch_products_mapping pm
3592
- ON cpe.entity_id = pm.entity_id
3593
- WHERE pm.shop_store_product_id IS NOT NULL
3594
- AND pm.store_product_id IS NULL";
3595
- $result = $this->db_do($query);
3596
 
 
 
 
 
 
3597
 
 
3598
 
 
3599
 
 
 
 
 
 
3600
 
3601
- echo("\n replaceMagentoProductsMultistore 3\n");
 
 
 
 
 
3602
 
3603
- $result = $this->db_do("
3604
- INSERT INTO $catalog_product_entity
3605
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
3606
- (SELECT
3607
- pm.entity_id,
3608
- $_getProductEntityTypeId,
3609
- $_defaultAttributeSetId,
3610
- 'simple',
3611
- a.product_sku,
3612
- NOW(),
3613
- 0,
3614
- a.store_product_id,
3615
- a.sinch_product_id
3616
- FROM $products_temp a
3617
- LEFT JOIN $stINch_products_mapping pm
3618
- ON a.store_product_id = pm.store_product_id
3619
- AND a.sinch_product_id = pm.sinch_product_id
3620
- WHERE pm.entity_id IS NULL
3621
- )
3622
- ON DUPLICATE KEY UPDATE
3623
- sku = a.product_sku,
3624
- store_product_id = a.store_product_id,
3625
- sinch_product_id = a.sinch_product_id");
3626
- // store_product_id = a.store_product_id,
3627
- // sinch_product_id = a.sinch_product_id
3628
-
3629
- $result = $this->db_do("
3630
- INSERT INTO $catalog_product_entity
3631
- (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
3632
- (SELECT
3633
- pm.entity_id,
3634
- $_getProductEntityTypeId,
3635
- $_defaultAttributeSetId,
3636
- 'simple',
3637
- a.product_sku,
3638
- NOW(),
3639
- 0,
3640
- a.store_product_id,
3641
- a.sinch_product_id
3642
- FROM $products_temp a
3643
- LEFT JOIN $stINch_products_mapping pm
3644
- ON a.store_product_id = pm.store_product_id
3645
- AND a.sinch_product_id = pm.sinch_product_id
3646
- WHERE pm.entity_id IS NOT NULL
3647
- )
3648
- ON DUPLICATE KEY UPDATE
3649
- sku = a.product_sku,
3650
- store_product_id = a.store_product_id,
3651
- sinch_product_id = a.sinch_product_id");
3652
- // store_product_id = a.store_product_id,
3653
- // sinch_product_id = a.sinch_product_id
3654
 
3655
- echo("\n replaceMagentoProductsMultistore 4\n");
 
 
3656
 
 
 
 
 
 
3657
 
 
3658
 
 
3659
 
 
 
3660
 
3661
- //Set enabled
3662
- $result = $this->db_do("
3663
- DELETE cpei
3664
- FROM $catalog_product_entity_int cpei
3665
- LEFT JOIN $catalog_product_entity cpe
3666
- ON cpei.entity_id = cpe.entity_id
3667
- WHERE cpe.entity_id IS NULL");
3668
 
3669
- $result = $this->db_do("
3670
- INSERT INTO $catalog_product_entity_int
3671
- (entity_type_id, attribute_id, store_id, entity_id, value)
3672
- (SELECT
3673
- $_getProductEntityTypeId,
3674
- $attr_atatus,
3675
- w.website,
3676
- a.entity_id,
3677
- 1
3678
- FROM $catalog_product_entity a
3679
- JOIN $products_website_temp w
3680
- ON a.store_product_id = w.store_product_id
3681
- )
3682
- ON DUPLICATE KEY UPDATE
3683
- value = 1");
3684
 
 
 
 
 
 
 
3685
 
 
 
 
3686
 
 
 
 
 
 
 
3687
 
 
3688
 
3689
- echo("\n replaceMagentoProductsMultistore 5\n");
 
3690
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3691
 
3692
- // set status = 1 for all stores
3693
- $result = $this->db_do("
3694
- INSERT INTO $catalog_product_entity_int
3695
- (entity_type_id, attribute_id, store_id, entity_id, value)
3696
- (SELECT
3697
- $_getProductEntityTypeId,
3698
- $attr_atatus,
3699
- 0,
3700
- a.entity_id,
3701
- 1
3702
- FROM $catalog_product_entity a
3703
- )
3704
- ON DUPLICATE KEY UPDATE
3705
- value = 1");
3706
 
 
 
 
 
 
 
 
 
 
 
3707
 
 
 
 
 
 
 
 
 
3708
 
 
 
 
 
 
 
 
 
 
3709
 
 
 
 
 
 
3710
 
3711
- echo("\n replaceMagentoProductsMultistore 6\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
3712
 
 
3713
 
3714
- //Unifying products with categories.
3715
- $result = $this->db_do("
3716
- DELETE ccp
3717
- FROM $catalog_category_product ccp
3718
- LEFT JOIN $catalog_product_entity cpe
3719
- ON ccp.product_id = cpe.entity_id
3720
- WHERE cpe.entity_id IS NULL");
 
3721
 
 
 
 
 
 
 
 
 
 
3722
 
 
3723
 
 
 
3724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3725
 
 
 
 
 
 
 
3726
 
3727
 
3728
- echo("\n replaceMagentoProductsMultistore 7\n");
3729
 
 
 
3730
 
 
 
 
3731
 
3732
- $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3733
 
 
 
 
 
 
 
3734
 
3735
- $result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
3736
- $result = $this->db_do("
3737
- CREATE TABLE $root_cats
3738
- SELECT
3739
- entity_id,
3740
- path,
3741
- SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
3742
- LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
3743
- SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
3744
- FROM $catalog_category_entity
3745
- ");
3746
- $result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
3747
 
 
 
 
 
 
3748
 
3749
- echo("\n replaceMagentoProductsMultistore 8\n");
 
 
 
 
 
 
3750
 
 
 
 
 
 
 
3751
 
3752
- // !!! $this->_root_cat
3753
- $result = $this->db_do("
3754
- UPDATE IGNORE $catalog_category_product ccp
3755
- LEFT JOIN $catalog_category_entity cce
3756
- ON ccp.category_id = cce.entity_id
3757
- JOIN $root_cats rc
3758
- ON cce.entity_id = rc.entity_id
3759
- SET ccp.category_id = rc.root_cat
3760
- WHERE cce.entity_id IS NULL");
3761
 
 
 
 
 
 
3762
 
 
3763
 
3764
- echo("\n replaceMagentoProductsMultistore 9\n");
3765
 
 
3766
 
 
 
 
 
 
3767
 
 
 
 
 
 
3768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3769
 
3770
- $result = $this->db_do("
3771
- DELETE ccp
3772
- FROM $catalog_category_product ccp
3773
- LEFT JOIN $catalog_category_entity cce
3774
- ON ccp.category_id = cce.entity_id
3775
- WHERE cce.entity_id IS NULL");
 
 
3776
 
 
 
 
 
 
 
 
3777
 
3778
- //echo("\n\nget out...\n\n");
3779
- //return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3780
 
 
3781
 
 
3782
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3783
 
 
 
 
 
 
 
3784
 
3785
- echo("\n replaceMagentoProductsMultistore 10\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3786
 
 
3787
 
3788
- $catalog_category_product_for_delete_temp = $catalog_category_product."_for_delete_temp";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3789
 
3790
- // TEMPORARY
3791
- $this->db_do(" DROP TABLE IF EXISTS $catalog_category_product_for_delete_temp");
3792
- $this->db_do("
3793
- CREATE TABLE $catalog_category_product_for_delete_temp
3794
- (
3795
- `category_id` int(10) unsigned NOT NULL default '0',
3796
- `product_id` int(10) unsigned NOT NULL default '0',
3797
- `store_product_id` int(10) NOT NULL default '0',
3798
- `store_category_id` int(10) NOT NULL default '0',
3799
- `new_category_id` int(10) NOT NULL default '0',
3800
 
3801
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
3802
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
3803
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
3804
- KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
3805
- )");
3806
 
3807
- echo("\n replaceMagentoProductsMultistore 11\n");
3808
 
3809
- $result = $this->db_do("
3810
- INSERT INTO $catalog_category_product_for_delete_temp
3811
- (category_id, product_id, store_product_id)
3812
- (SELECT
3813
- ccp.category_id,
3814
- ccp.product_id,
3815
- cpe.store_product_id
3816
- FROM $catalog_category_product ccp
3817
- JOIN $catalog_product_entity cpe
3818
- ON ccp.product_id = cpe.entity_id
3819
- WHERE store_product_id IS NOT NULL)");
3820
-
3821
- echo("\n replaceMagentoProductsMultistore 12\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3822
 
3823
- $result = $this->db_do("
3824
- UPDATE $catalog_category_product_for_delete_temp ccpfd
3825
- JOIN $products_temp p
3826
- ON ccpfd.store_product_id = p.store_product_id
3827
- SET ccpfd.store_category_id = p.store_category_id
3828
- WHERE ccpfd.store_product_id != 0");
3829
 
3830
- echo("\n replaceMagentoProductsMultistore 13\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
3831
 
3832
- $result = $this->db_do("
3833
- UPDATE $catalog_category_product_for_delete_temp ccpfd
3834
- JOIN $stINch_categories_mapping scm
3835
- ON ccpfd.store_category_id = scm.store_category_id
3836
- SET ccpfd.new_category_id = scm.shop_entity_id
3837
- WHERE ccpfd.store_category_id != 0");
3838
-
3839
- echo("\n replaceMagentoProductsMultistore 14\n");
3840
-
3841
- $result = $this->db_do("DELETE FROM $catalog_category_product_for_delete_temp WHERE category_id = new_category_id");
3842
-
3843
-
3844
-
3845
- $result = $this->db_do("
3846
- DELETE ccp
3847
- FROM $catalog_category_product ccp
3848
- JOIN $catalog_category_product_for_delete_temp ccpfd
3849
- ON ccp.product_id = ccpfd.product_id
3850
- AND ccp.category_id = ccpfd.category_id");
3851
-
3852
-
3853
- //echo("\n\nget out...\n\n");
3854
- //return;
3855
-
3856
-
3857
- echo("\n replaceMagentoProductsMultistore 15\n");
3858
-
3859
- $result = $this->db_do("
3860
- INSERT INTO $catalog_category_product
3861
- (category_id, product_id)
3862
- (SELECT
3863
- scm.shop_entity_id,
3864
- cpe.entity_id
3865
- FROM $catalog_product_entity cpe
3866
- JOIN $products_temp p
3867
- ON cpe.store_product_id = p.store_product_id
3868
- JOIN $stINch_categories_mapping scm
3869
- ON p.store_category_id = scm.store_category_id
3870
- )
3871
- ON DUPLICATE KEY UPDATE
3872
- product_id = cpe.entity_id");
3873
-
3874
-
3875
- echo("\n replaceMagentoProductsMultistore 15.1 (add multi categories)\n");
3876
-
3877
- $result = $this->db_do("
3878
- INSERT INTO $catalog_category_product
3879
- (category_id, product_id)
3880
- (SELECT
3881
- scm.shop_entity_id,
3882
- cpe.entity_id
3883
- FROM $catalog_product_entity cpe
3884
- JOIN $products_temp p
3885
- ON cpe.store_product_id = p.store_product_id
3886
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
3887
- ON p.store_product_id=spc.store_product_id
3888
- JOIN $stINch_categories_mapping scm
3889
- ON spc.store_category_id = scm.store_category_id
3890
- )
3891
- ON DUPLICATE KEY UPDATE
3892
- product_id = cpe.entity_id
3893
- ");
3894
-
3895
-
3896
-
3897
-
3898
- echo("\n replaceMagentoProductsMultistore 16\n");
3899
-
3900
- //Indexing products and categories in the shop
3901
- $result = $this->db_do("
3902
- DELETE ccpi
3903
- FROM $catalog_category_product_index ccpi
3904
- LEFT JOIN $catalog_product_entity cpe
3905
- ON ccpi.product_id = cpe.entity_id
3906
- WHERE cpe.entity_id IS NULL");
3907
-
3908
-
3909
-
3910
- echo("\n replaceMagentoProductsMultistore 16.2\n");
3911
-
3912
-
3913
- $result = $this->db_do("
3914
- INSERT INTO $catalog_category_product_index
3915
- (category_id, product_id, position, is_parent, store_id, visibility)
3916
- (SELECT
3917
- a.category_id,
3918
- a.product_id,
3919
- a.position,
3920
- 1,
3921
- b.store_id,
3922
- 4
3923
- FROM $catalog_category_product a
3924
- JOIN $core_store b
3925
- )
3926
- ON DUPLICATE KEY UPDATE
3927
- visibility = 4");
3928
-
3929
-
3930
-
3931
- echo("\n replaceMagentoProductsMultistore 17\n");
3932
-
3933
- // !!! $this->_root_cat
3934
- $result = $this->db_do("
3935
- INSERT ignore INTO $catalog_category_product_index
3936
- (category_id, product_id, position, is_parent, store_id, visibility)
3937
- (SELECT
3938
- rc.root_cat,
3939
- a.product_id,
3940
- a.position,
3941
- 1,
3942
- b.store_id,
3943
- 4
3944
- FROM $catalog_category_product a
3945
- JOIN $root_cats rc
3946
- ON a.category_id = rc.entity_id
3947
- JOIN $core_store b
3948
- )
3949
- ON DUPLICATE KEY UPDATE
3950
- visibility = 4");
3951
-
3952
- echo("\n replaceMagentoProductsMultistore 18\n");
3953
-
3954
-
3955
- //Set product name for specific web sites
3956
- $result = $this->db_do("
3957
- DELETE cpev
3958
- FROM $catalog_product_entity_varchar cpev
3959
- LEFT JOIN $catalog_product_entity cpe
3960
- ON cpev.entity_id = cpe.entity_id
3961
- WHERE cpe.entity_id IS NULL");
3962
-
3963
- $result = $this->db_do("
3964
- INSERT INTO $catalog_product_entity_varchar
3965
- (entity_type_id, attribute_id, store_id, entity_id, value)
3966
- (SELECT
3967
- $_getProductEntityTypeId,
3968
- $attr_name,
3969
- w.website,
3970
- a.entity_id,
3971
- b.product_name
3972
- FROM $catalog_product_entity a
3973
- JOIN $products_temp b
3974
- ON a.store_product_id = b.store_product_id
3975
- JOIN $products_website_temp w
3976
- ON a.store_product_id = w.store_product_id
3977
- )
3978
- ON DUPLICATE KEY UPDATE
3979
- value = b.product_name");
3980
-
3981
- echo("\n replaceMagentoProductsMultistore 19\n");
3982
-
3983
-
3984
- // product name for all web sites
3985
- $result = $this->db_do("
3986
- INSERT INTO $catalog_product_entity_varchar
3987
- (entity_type_id, attribute_id, store_id, entity_id, value)
3988
- (SELECT
3989
- $_getProductEntityTypeId,
3990
- $attr_name,
3991
- 0,
3992
- a.entity_id,
3993
- b.product_name
3994
- FROM $catalog_product_entity a
3995
- JOIN $products_temp b
3996
- ON a.store_product_id = b.store_product_id
3997
- )
3998
- ON DUPLICATE KEY UPDATE
3999
- value = b.product_name");
4000
-
4001
- echo("\n replaceMagentoProductsMultistore 20\n");
4002
-
4003
-
4004
-
4005
- $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
4006
- $this->addDescriptions();
4007
- $this->cleanProductDistributors();
4008
- if($this->product_file_format == "NEW"){
4009
- $this->addReviews();
4010
- $this->addWeight();
4011
- $this->addSearchCache();
4012
- $this->addPdfUrl();
4013
- $this->addShortDescriptions();
4014
- $this->addProductDistributors();
4015
- }
4016
- $this->addEAN();
4017
- $this->addSpecification();
4018
- $this->addManufacturers();
4019
-
4020
- //echo(" .... DONE\n");return;
4021
-
4022
- echo("\n replaceMagentoProductsMultistore 21\n");
4023
-
4024
- //Enabling product index.
4025
- $result = $this->db_do("
4026
- DELETE cpei
4027
- FROM $catalog_product_enabled_index cpei
4028
- LEFT JOIN $catalog_product_entity cpe
4029
- ON cpei.product_id = cpe.entity_id
4030
- WHERE cpe.entity_id IS NULL");
4031
-
4032
- echo("\n replaceMagentoProductsMultistore 22\n");
4033
-
4034
- $result = $this->db_do("
4035
- INSERT INTO $catalog_product_enabled_index
4036
- (product_id, store_id, visibility)
4037
- (SELECT
4038
- a.entity_id,
4039
- w.website,
4040
- 4
4041
- FROM $catalog_product_entity a
4042
- JOIN $products_website_temp w
4043
- ON a.store_product_id = w.store_product_id
4044
- )
4045
- ON DUPLICATE KEY UPDATE
4046
- visibility = 4");
4047
-
4048
- echo("\n replaceMagentoProductsMultistore 23\n");
4049
-
4050
- $result = $this->db_do("
4051
- INSERT INTO $catalog_product_enabled_index
4052
- (product_id, store_id, visibility)
4053
- (SELECT
4054
- a.entity_id,
4055
- 0,
4056
- 4
4057
- FROM $catalog_product_entity a
4058
- JOIN $products_website_temp w
4059
- ON a.store_product_id = w.store_product_id
4060
- )
4061
- ON DUPLICATE KEY UPDATE
4062
- visibility = 4");
4063
-
4064
-
4065
- /////////////////////////////////////echo(" .... DONE\n");return;
4066
-
4067
-
4068
- echo("\n replaceMagentoProductsMultistore 24\n");
4069
-
4070
- $result = $this->db_do("
4071
- INSERT INTO $catalog_product_entity_int
4072
- (entity_type_id, attribute_id, store_id, entity_id, value)
4073
- (SELECT
4074
- $_getProductEntityTypeId,
4075
- $attr_visibility,
4076
- w.website,
4077
- a.entity_id,
4078
- 4
4079
- FROM $catalog_product_entity a
4080
- JOIN $products_website_temp w
4081
- ON a.store_product_id = w.store_product_id
4082
- )
4083
- ON DUPLICATE KEY UPDATE
4084
- value = 4");
4085
-
4086
- echo("\n replaceMagentoProductsMultistore 25\n");
4087
-
4088
- $result = $this->db_do("
4089
- INSERT INTO $catalog_product_entity_int
4090
- (entity_type_id, attribute_id, store_id, entity_id, value)
4091
- (SELECT
4092
- $_getProductEntityTypeId,
4093
- $attr_visibility,
4094
- 0,
4095
- a.entity_id,
4096
- 4
4097
- FROM $catalog_product_entity a
4098
- )
4099
- ON DUPLICATE KEY UPDATE
4100
- value = 4");
4101
-
4102
- echo("\n replaceMagentoProductsMultistore 26\n");
4103
-
4104
- $result = $this->db_do("
4105
- DELETE cpw
4106
- FROM $catalog_product_website cpw
4107
- LEFT JOIN $catalog_product_entity cpe
4108
- ON cpw.product_id = cpe.entity_id
4109
- WHERE cpe.entity_id IS NULL");
4110
-
4111
- echo("\n replaceMagentoProductsMultistore 27\n");
4112
-
4113
- $result = $this->db_do("
4114
- INSERT INTO $catalog_product_website
4115
- (product_id, website_id)
4116
- (SELECT
4117
- a.entity_id,
4118
- w.website_id
4119
- FROM $catalog_product_entity a
4120
- JOIN $products_website_temp w
4121
- ON a.store_product_id = w.store_product_id
4122
- )
4123
- ON DUPLICATE KEY UPDATE
4124
- product_id = a.entity_id,
4125
- website_id = w.website_id");
4126
-
4127
-
4128
- //echo(" .... DONE\n");return;
4129
-
4130
-
4131
- echo("\n replaceMagentoProductsMultistore 28\n");
4132
-
4133
- // temporary disabled mart@bintime.com
4134
- //$result = $this->db_do("
4135
- // UPDATE catalog_category_entity_int a
4136
- // SET a.value = 0
4137
- // WHERE a.attribute_id = 32
4138
- //");
4139
-
4140
-
4141
- //Adding tax class "Taxable Goods"
4142
- $result = $this->db_do("
4143
- INSERT INTO $catalog_product_entity_int
4144
- (entity_type_id, attribute_id, store_id, entity_id, value)
4145
- (SELECT
4146
- $_getProductEntityTypeId,
4147
- $attr_tax_class_id,
4148
- w.website,
4149
- a.entity_id,
4150
- 2
4151
- FROM $catalog_product_entity a
4152
- JOIN $products_website_temp w
4153
- ON a.store_product_id = w.store_product_id
4154
- )
4155
- ON DUPLICATE KEY UPDATE
4156
- value = 2");
4157
-
4158
- echo("\n replaceMagentoProductsMultistore 29\n");
4159
-
4160
- $result = $this->db_do("
4161
- INSERT INTO $catalog_product_entity_int
4162
- (entity_type_id, attribute_id, store_id, entity_id, value)
4163
- (SELECT
4164
- $_getProductEntityTypeId,
4165
- $attr_tax_class_id,
4166
- 0,
4167
- a.entity_id,
4168
- 2
4169
- FROM $catalog_product_entity a
4170
- )
4171
- ON DUPLICATE KEY UPDATE
4172
- value = 2");
4173
-
4174
- echo("\n replaceMagentoProductsMultistore 30\n");
4175
-
4176
- // Load url Image
4177
- $result = $this->db_do("
4178
- INSERT INTO $catalog_product_entity_varchar
4179
- (entity_type_id, attribute_id, store_id, entity_id, value)
4180
- (SELECT
4181
- $_getProductEntityTypeId,
4182
- $attr_image,
4183
- w.store_id,
4184
- a.entity_id,
4185
- b.main_image_url
4186
- FROM $catalog_product_entity a
4187
- JOIN $core_store w
4188
- JOIN $products_temp b
4189
- ON a.store_product_id = b.store_product_id
4190
- )
4191
- ON DUPLICATE KEY UPDATE
4192
- value = b.main_image_url");
4193
-
4194
- echo("\n replaceMagentoProductsMultistore 31\n");
4195
-
4196
- // image for specific web sites
4197
- $result = $this->db_do("
4198
- INSERT INTO $catalog_product_entity_varchar
4199
- (entity_type_id, attribute_id, store_id, entity_id, value)
4200
- (SELECT
4201
- $_getProductEntityTypeId,
4202
- $attr_image,
4203
- 0,
4204
- a.entity_id,
4205
- b.main_image_url
4206
- FROM $catalog_product_entity a
4207
- JOIN $products_temp b
4208
- ON a.store_product_id = b.store_product_id
4209
- )
4210
- ON DUPLICATE KEY UPDATE
4211
- value = b.main_image_url");
4212
-
4213
- echo("\n replaceMagentoProductsMultistore 32\n");
4214
-
4215
- // small_image for specific web sites
4216
- $result = $this->db_do("
4217
- INSERT INTO $catalog_product_entity_varchar
4218
- (entity_type_id, attribute_id, store_id, entity_id, value)
4219
- (SELECT
4220
- $_getProductEntityTypeId,
4221
- $attr_small_image,
4222
- w.store_id,
4223
- a.entity_id,
4224
- b.medium_image_url
4225
- FROM $catalog_product_entity a
4226
- JOIN $core_store w
4227
- JOIN $products_temp b
4228
- ON a.store_product_id = b.store_product_id
4229
- )
4230
- ON DUPLICATE KEY UPDATE
4231
- value = b.medium_image_url");
4232
-
4233
- echo("\n replaceMagentoProductsMultistore 33\n");
4234
-
4235
- // small_image for all web sites
4236
- $result = $this->db_do("
4237
- INSERT INTO $catalog_product_entity_varchar
4238
- (entity_type_id, attribute_id, store_id, entity_id, value)
4239
- (SELECT
4240
- $_getProductEntityTypeId,
4241
- $attr_small_image,
4242
- 0,
4243
- a.entity_id,
4244
- b.medium_image_url
4245
- FROM $catalog_product_entity a
4246
- JOIN $core_store w
4247
- JOIN $products_temp b
4248
- ON a.store_product_id = b.store_product_id
4249
- )
4250
- ON DUPLICATE KEY UPDATE
4251
- value = b.medium_image_url");
4252
-
4253
- echo("\n replaceMagentoProductsMultistore 34\n");
4254
-
4255
- // thumbnail for specific web site
4256
- $result = $this->db_do("
4257
- INSERT INTO $catalog_product_entity_varchar
4258
- (entity_type_id, attribute_id, store_id, entity_id, value)
4259
- (SELECT
4260
- $_getProductEntityTypeId,
4261
- $attr_thumbnail,
4262
- w.store_id,
4263
- a.entity_id,
4264
- b.thumb_image_url
4265
- FROM $catalog_product_entity a
4266
- JOIN $core_store w
4267
- JOIN $products_temp b
4268
- ON a.store_product_id = b.store_product_id
4269
- )
4270
- ON DUPLICATE KEY UPDATE
4271
- value = b.thumb_image_url");
4272
-
4273
- echo("\n replaceMagentoProductsMultistore 35\n");
4274
-
4275
- // thumbnail for all web sites
4276
- $result = $this->db_do("
4277
- INSERT INTO $catalog_product_entity_varchar
4278
- (entity_type_id, attribute_id, store_id, entity_id, value)
4279
- (SELECT
4280
- $_getProductEntityTypeId,
4281
- $attr_thumbnail,
4282
- 0,
4283
- a.entity_id,
4284
- b.thumb_image_url
4285
- FROM $catalog_product_entity a
4286
- JOIN $core_store w
4287
- JOIN $products_temp b
4288
- ON a.store_product_id = b.store_product_id
4289
- )
4290
- ON DUPLICATE KEY UPDATE
4291
- value = b.thumb_image_url");
4292
-
4293
- echo("\n replaceMagentoProductsMultistore 36\n");
4294
-
4295
-
4296
-
4297
-
4298
-
4299
- /*STP DELETE
4300
- //Refresh fulltext search
4301
- $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
4302
- $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
4303
-
4304
-
4305
- echo("\n replaceMagentoProductsMultistore 36.2\n");
4306
- $q = "
4307
- INSERT INTO {$catalogsearch_fulltext}_tmp
4308
- (product_id, store_id, data_index)
4309
- (SELECT
4310
- a.entity_id,
4311
- w.website,
4312
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4313
- FROM $catalog_product_entity a
4314
- JOIN $products_website_temp w
4315
- ON a.store_product_id = w.store_product_id
4316
- LEFT JOIN $catalog_category_product b
4317
- ON a.entity_id = b.product_id
4318
- LEFT JOIN $catalog_category_entity_varchar c
4319
- ON b.category_id = c.entity_id
4320
- AND c.attribute_id = $cat_attr_name
4321
- LEFT JOIN $catalog_product_entity_varchar e
4322
- ON a.entity_id = e.entity_id
4323
- AND e.attribute_id = $attr_name
4324
- LEFT JOIN $catalog_product_website j
4325
- ON a.entity_id = j.product_id
4326
- LEFT JOIN $products_temp f
4327
- ON a.store_product_id = f.store_product_id
4328
- )
4329
- ON DUPLICATE KEY UPDATE
4330
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
4331
- echo("\n\n============================\n$q\n============================\n\n");
4332
-
4333
-
4334
- $result = $this->db_do("
4335
- INSERT INTO {$catalogsearch_fulltext}_tmp
4336
- (product_id, store_id, data_index)
4337
- (SELECT
4338
- a.entity_id,
4339
- w.website,
4340
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4341
- FROM $catalog_product_entity a
4342
- JOIN $products_website_temp w
4343
- ON a.store_product_id = w.store_product_id
4344
- LEFT JOIN $catalog_category_product b
4345
- ON a.entity_id = b.product_id
4346
- LEFT JOIN $catalog_category_entity_varchar c
4347
- ON b.category_id = c.entity_id
4348
- AND c.attribute_id = $cat_attr_name
4349
- LEFT JOIN $catalog_product_entity_varchar e
4350
- ON a.entity_id = e.entity_id
4351
- AND e.attribute_id = $attr_name
4352
- LEFT JOIN $catalog_product_website j
4353
- ON a.entity_id = j.product_id
4354
- LEFT JOIN $products_temp f
4355
- ON a.store_product_id = f.store_product_id
4356
- )
4357
- ON DUPLICATE KEY UPDATE
4358
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
4359
-
4360
- echo("\n replaceMagentoProductsMultistore 37\n");
4361
-
4362
-
4363
- $result = $this->db_do("
4364
- INSERT INTO {$catalogsearch_fulltext}_tmp
4365
- (product_id, store_id, data_index)
4366
- (SELECT
4367
- a.entity_id,
4368
- w.website,
4369
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
4370
- FROM $catalog_product_entity a
4371
- JOIN $products_website_temp w
4372
- ON a.store_product_id = w.store_product_id
4373
- LEFT JOIN $catalog_category_product b
4374
- ON a.entity_id = b.product_id
4375
- LEFT JOIN $catalog_category_entity_varchar c
4376
- ON b.category_id = c.entity_id
4377
- AND c.attribute_id = $cat_attr_name
4378
- LEFT JOIN $catalog_product_entity_varchar e
4379
- ON a.entity_id = e.entity_id
4380
- AND e.attribute_id = $attr_name
4381
- LEFT JOIN $products_temp f
4382
- ON a.store_product_id = f.store_product_id
4383
- )
4384
- ON DUPLICATE KEY UPDATE
4385
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
4386
-
4387
- echo("\n replaceMagentoProductsMultistore 38\n");
4388
-
4389
- $result = $this->db_do("
4390
- DELETE cf
4391
- FROM $catalogsearch_fulltext cf
4392
- LEFT JOIN $catalog_product_entity cpe
4393
- ON cf.product_id = cpe.entity_id
4394
- WHERE cpe.entity_id IS NULL");
4395
-
4396
- echo("\n replaceMagentoProductsMultistore 39\n");
4397
-
4398
- $result = $this->db_do("
4399
- INSERT INTO $catalogsearch_fulltext
4400
- (product_id, store_id, data_index)
4401
- (SELECT
4402
- a.product_id,
4403
- a.store_id,
4404
- a.data_index
4405
- FROM {$catalogsearch_fulltext}_tmp a
4406
- )
4407
- ON DUPLICATE KEY UPDATE
4408
- data_index = a.data_index");
4409
-
4410
- echo("\n replaceMagentoProductsMultistore 40\n");
4411
-
4412
- $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
4413
- //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
4414
- //TODO add something else
4415
- STP DELETE*/
4416
-
4417
- $this->addRelatedProducts();
4418
- echo("\n replaceMagentoProductsMultistore 41\n");
4419
- } //
4420
- ################################################################################################################################################################
4421
 
 
 
 
 
 
 
 
 
 
 
4422
 
 
 
 
 
 
 
 
 
 
4423
 
 
4424
 
 
 
 
 
 
 
 
 
 
 
 
4425
 
 
 
 
 
4426
 
 
 
 
 
 
 
 
 
 
 
 
 
4427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4429
 
4430
 
 
4431
 
 
4432
 
 
 
 
 
4433
 
 
4434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4435
 
4436
 
 
4437
 
 
4438
 
 
 
4439
 
 
4440
 
 
 
 
 
 
 
 
4441
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4442
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4443
 
 
 
 
 
 
 
4444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4445
 
 
 
 
 
 
 
4446
 
 
 
 
 
 
 
 
 
 
 
 
4447
 
4448
 
 
 
 
 
 
 
 
 
 
4449
 
4450
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4451
 
 
4452
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4453
 
 
 
 
 
 
 
4454
 
 
 
 
 
 
 
4455
 
 
 
4456
 
 
 
 
 
 
 
 
4457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4458
 
4459
 
 
4460
 
4461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4462
 
4463
 
 
 
 
 
 
 
4464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4466
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4469
 
 
 
 
 
 
 
4470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4471
 
4472
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4474
 
 
 
 
 
 
4475
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4476
 
 
 
 
 
 
 
4477
 
4478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4480
 
4481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4482
 
4483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4484
 
4485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4486
 
4487
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4488
 
4489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4490
 
 
4491
 
 
 
 
 
 
 
4492
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4493
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4494
 
 
 
 
 
 
4495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4496
 
 
 
 
 
 
 
4497
 
 
4498
 
 
 
 
 
 
 
 
 
 
 
 
4499
 
 
 
 
 
 
4500
 
 
4501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4502
 
 
 
4503
 
 
4504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4505
 
 
4506
 
 
 
4507
 
4508
 
 
4509
 
4510
- ################################################################################################################################################################
4511
- private function truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
4512
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
4513
- $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
4514
- {
4515
- $this->db_do('SET foreign_key_checks=0');
4516
-
4517
- $this->db_do("TRUNCATE $catalog_category_entity");
4518
- $this->db_do("
4519
- INSERT $catalog_category_entity
4520
- (
4521
- entity_id,
4522
- entity_type_id,
4523
- attribute_set_id,
4524
- parent_id,
4525
- created_at,
4526
- updated_at,
4527
- path,
4528
- position,
4529
- level,
4530
- children_count,
4531
- store_category_id,
4532
- parent_store_category_id
4533
- )
4534
- VALUES
4535
- (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
4536
- (2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 1, null, null)");
4537
 
4538
- $this->db_do("TRUNCATE $catalog_category_entity_varchar");
4539
- $this->db_do("
4540
- INSERT $catalog_category_entity_varchar
4541
- (
4542
- value_id,
4543
- entity_type_id,
4544
- attribute_id,
4545
- store_id,
4546
- entity_id,
4547
- value
4548
- )
4549
- VALUES
4550
- (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
4551
- (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
4552
- (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog'),
4553
- (4, $_categoryEntityTypeId, $name_attrid, 0, 2, 'Default Category'),
4554
- (5, $_categoryEntityTypeId, $name_attrid, 1, 2, 'Default Category'),
4555
- (6, $_categoryEntityTypeId, $attr_display_mode, 1, 2, 'PRODUCTS'),
4556
- (7, $_categoryEntityTypeId, $attr_url_key, 0, 2, 'default-category')");
4557
-
4558
- $this->db_do("TRUNCATE $catalog_category_entity_int");
4559
- $this->db_do("
4560
- INSERT $catalog_category_entity_int
4561
- (
4562
- value_id,
4563
- entity_type_id,
4564
- attribute_id,
4565
- store_id,
4566
- entity_id,
4567
- value
4568
- )
4569
- VALUES
4570
- (1, $_categoryEntityTypeId, $attr_is_active, 0, 2, 1),
4571
- (2, $_categoryEntityTypeId, $attr_is_active, 1, 2, 1),
4572
- (3, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1),
4573
- (4, $_categoryEntityTypeId, $attr_include_in_menu, 0, 2, 1)");
4574
-
4575
- return $root_cat;
4576
- } // private function truncateAllCateriesAndRecreateDefaults(...)
4577
- ################################################################################################################################################################
4578
 
4579
 
 
4580
 
4581
- ################################################################################################################################################################
4582
- private function setCategorySettings($categories_temp, $root_cat)
4583
- {
4584
- $this->db_do("
4585
- UPDATE $categories_temp
4586
- SET parent_store_category_id = $root_cat
4587
- WHERE parent_store_category_id = 0");
4588
-
4589
- $store_cat_ids = $this->db_do("SELECT store_category_id FROM $categories_temp");
4590
- while ($row = mysqli_fetch_array($store_cat_ids))
4591
- {
4592
- $store_category_id = $row['store_category_id'];
4593
-
4594
- $children_count = $this->count_children($store_category_id);
4595
- $level = $this->get_category_level($store_category_id);
4596
-
4597
- $this->db_do("
4598
- UPDATE $categories_temp
4599
- SET children_count = $children_count,
4600
- level = $level
4601
- WHERE store_category_id = $store_category_id");
4602
- }
4603
- } // private function setCategorySettings($categories_temp, $root_cat)
4604
- ################################################################################################################################################################
4605
 
 
4606
 
 
 
 
 
 
 
 
 
4607
 
 
4608
 
 
 
 
 
 
 
4609
 
 
4610
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4611
 
4612
- ################################################################################################################################################################
4613
- public function mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat)
4614
- {
4615
- $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
4616
-
4617
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
4618
-
4619
- $this->db_do("
4620
- CREATE TABLE $stINch_categories_mapping_temp
4621
- (
4622
- shop_entity_id INT(11) UNSIGNED NOT NULL,
4623
- shop_entity_type_id INT(11),
4624
- shop_attribute_set_id INT(11),
4625
- shop_parent_id INT(11),
4626
- shop_store_category_id INT(11),
4627
- shop_parent_store_category_id INT(11),
4628
- store_category_id INT(11),
4629
- parent_store_category_id INT(11),
4630
- category_name VARCHAR(255),
4631
- order_number INT(11),
4632
- products_within_this_category INT(11),
4633
-
4634
- KEY shop_entity_id (shop_entity_id),
4635
- KEY shop_parent_id (shop_parent_id),
4636
- KEY store_category_id (store_category_id),
4637
- KEY parent_store_category_id (parent_store_category_id),
4638
- UNIQUE KEY(shop_entity_id)
4639
- )");
4640
-
4641
- $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
4642
-
4643
- $this->db_do("
4644
- INSERT IGNORE INTO $stINch_categories_mapping_temp
4645
- (
4646
- shop_entity_id,
4647
- shop_entity_type_id,
4648
- shop_attribute_set_id,
4649
- shop_parent_id,
4650
- shop_store_category_id,
4651
- shop_parent_store_category_id
4652
- )
4653
- (SELECT
4654
- entity_id,
4655
- entity_type_id,
4656
- attribute_set_id,
4657
- parent_id,
4658
- store_category_id,
4659
- parent_store_category_id
4660
- FROM $catalog_category_entity)");
4661
-
4662
- $this->db_do("
4663
- UPDATE $stINch_categories_mapping_temp cmt
4664
- JOIN $categories_temp c
4665
- ON cmt.shop_store_category_id = c.store_category_id
4666
- SET
4667
- cmt.store_category_id = c.store_category_id,
4668
- cmt.parent_store_category_id = c.parent_store_category_id,
4669
- cmt.category_name = c.category_name,
4670
- cmt.order_number = c.order_number,
4671
- cmt.products_within_this_category = c.products_within_this_category");
4672
-
4673
- $this->db_do("
4674
- UPDATE $stINch_categories_mapping_temp cmt
4675
- JOIN $catalog_category_entity cce
4676
- ON cmt.parent_store_category_id = cce.store_category_id
4677
- SET cmt.shop_parent_id = cce.entity_id");
4678
-
4679
- $this->db_do("
4680
- UPDATE $stINch_categories_mapping_temp cmt
4681
- JOIN $categories_temp c
4682
- ON cmt.shop_store_category_id = c.store_category_id
4683
- SET shop_parent_id = ".$this->_root_cat."
4684
- WHERE shop_parent_id = 0");
4685
- // !!!!!!!!!!!!!!!!!!!!!!!!!!! one shop ($this->_root_cat) => milti shop ($root_cat)
4686
 
4687
- // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
4688
- if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE"))
4689
- {
4690
- $this->db_do("
4691
- UPDATE $stINch_categories_mapping_temp cmt
4692
- JOIN $catalog_category_entity cce
4693
- ON cmt.shop_entity_id = cce.entity_id
4694
- SET cce.parent_id = cmt.shop_parent_id");
4695
- }
4696
- else
4697
- {
4698
- $this->db_do("
4699
- UPDATE $stINch_categories_mapping_temp cmt
4700
- JOIN $catalog_category_entity cce
4701
- ON cmt.shop_entity_id = cce.entity_id
4702
- SET cce.parent_id = cmt.shop_parent_id
4703
- WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL");
4704
- }
4705
-
4706
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping");
4707
- $this->db_do("RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping");
4708
- } //
4709
- ################################################################################################################################################################
4710
 
 
4711
 
 
4712
 
4713
- ################################################################################################################################################################
4714
- private function addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
4715
- $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat)
4716
- {
4717
- if (UPDATE_CATEGORY_DATA)
4718
- {
4719
- echo "Update category_entity \n";
4720
-
4721
- $q = "
4722
- INSERT INTO $catalog_category_entity
4723
- (
4724
- entity_type_id,
4725
- attribute_set_id,
4726
- created_at,
4727
- updated_at,
4728
- level,
4729
- children_count,
4730
- entity_id,
4731
- position,
4732
- parent_id,
4733
- store_category_id,
4734
- parent_store_category_id
4735
- )
4736
- (SELECT
4737
- $_categoryEntityTypeId,
4738
- $_categoryDefault_attribute_set_id,
4739
- now(),
4740
- now(),
4741
- c.level,
4742
- c.children_count,
4743
- scm.shop_entity_id,
4744
- c.order_number,
4745
- scm.shop_parent_id,
4746
- c.store_category_id,
4747
- c.parent_store_category_id
4748
- FROM $categories_temp c
4749
- LEFT JOIN $stINch_categories_mapping scm
4750
- ON c.store_category_id = scm.store_category_id
4751
- )
4752
- ON DUPLICATE KEY UPDATE
4753
- updated_at = now(),
4754
- store_category_id = c.store_category_id,
4755
- level = c.level,
4756
- children_count = c.children_count,
4757
- position = c.order_number,
4758
- parent_store_category_id = c.parent_store_category_id";
4759
- //level=c.level,
4760
- //children_count=c.children_count
4761
- //position=c.order_number,
4762
- }
4763
- else
4764
- {
4765
- echo "Insert ignore category_entity \n";
4766
-
4767
- $q = "
4768
- INSERT IGNORE INTO $catalog_category_entity
4769
- (
4770
- entity_type_id,
4771
- attribute_set_id,
4772
- created_at,
4773
- updated_at,
4774
- level,
4775
- children_count,
4776
- entity_id,
4777
- position,
4778
- parent_id,
4779
- store_category_id,
4780
- parent_store_category_id
4781
- )
4782
- (SELECT
4783
- $_categoryEntityTypeId,
4784
- $_categoryDefault_attribute_set_id,
4785
- now(),
4786
- now(),
4787
- c.level,
4788
- c.children_count,
4789
- scm.shop_entity_id,
4790
- c.order_number,
4791
- scm.shop_parent_id,
4792
- c.store_category_id,
4793
- c.parent_store_category_id
4794
- FROM $categories_temp c
4795
- LEFT JOIN $stINch_categories_mapping scm
4796
- ON c.store_category_id = scm.store_category_id
4797
- )";
4798
- }
4799
- $this->db_do($q);
4800
-
4801
- $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
4802
-
4803
-
4804
-
4805
- $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
4806
- while ($row = mysqli_fetch_array($categories))
4807
- {
4808
- $parent_id = $row['parent_id'];
4809
- $entity_id = $row['entity_id'];
4810
-
4811
- $path = $this->culc_path($parent_id, $entity_id);
4812
-
4813
- //echo("\n$path\n");
4814
-
4815
- $this->db_do("
4816
- UPDATE $catalog_category_entity
4817
- SET path = '$path'
4818
- WHERE entity_id = $entity_id");
4819
- }
4820
-
4821
- if(UPDATE_CATEGORY_DATA)
4822
- {
4823
- echo "Update category_data \n";
4824
-
4825
- $q = "
4826
- INSERT INTO $catalog_category_entity_varchar
4827
- (
4828
- entity_type_id,
4829
- attribute_id,
4830
- store_id,
4831
- entity_id,
4832
- value
4833
- )
4834
- (SELECT
4835
- $_categoryEntityTypeId,
4836
- $name_attrid,
4837
- 0,
4838
- scm.shop_entity_id,
4839
- c.category_name
4840
- FROM $categories_temp c
4841
- JOIN $stINch_categories_mapping scm
4842
- ON c.store_category_id = scm.store_category_id
4843
- )
4844
- ON DUPLICATE KEY UPDATE
4845
- value = c.category_name";
4846
- $this->db_do($q);
4847
-
4848
- $q = "
4849
- INSERT INTO $catalog_category_entity_varchar
4850
- (
4851
- entity_type_id,
4852
- attribute_id,
4853
- store_id,
4854
- entity_id,
4855
- value
4856
- )
4857
- (SELECT
4858
- $_categoryEntityTypeId,
4859
- $name_attrid,
4860
- 1,
4861
- scm.shop_entity_id,
4862
- c.category_name
4863
- FROM $categories_temp c
4864
- JOIN $stINch_categories_mapping scm
4865
- ON c.store_category_id = scm.store_category_id
4866
- )
4867
- ON DUPLICATE KEY UPDATE
4868
- value = c.category_name";
4869
- $this->db_do($q);
4870
-
4871
- $q = "
4872
- INSERT INTO $catalog_category_entity
4873
- (
4874
- entity_type_id,
4875
- attribute_id,
4876
- store_id,
4877
- entity_id,
4878
- value
4879
- )
4880
- (SELECT
4881
- $_categoryEntityTypeId,
4882
- $attr_is_active,
4883
- 0,
4884
- scm.shop_entity_id,
4885
- 1
4886
- FROM $categories_temp c
4887
- JOIN $stINch_categories_mapping scm
4888
- ON c.store_category_id = scm.store_category_id
4889
- )
4890
- ON DUPLICATE KEY UPDATE
4891
- value = 1";
4892
- $this->db_do($q);
4893
-
4894
- $q = "
4895
- INSERT INTO $catalog_category_entity_int
4896
- (
4897
- entity_type_id,
4898
- attribute_id,
4899
- store_id,
4900
- entity_id,
4901
- value
4902
- )
4903
- (SELECT
4904
- $_categoryEntityTypeId,
4905
- $attr_is_active,
4906
- 1,
4907
- scm.shop_entity_id,
4908
- 1
4909
- FROM $categories_temp c
4910
- JOIN $stINch_categories_mapping scm
4911
- ON c.store_category_id = scm.store_category_id
4912
- )
4913
- ON DUPLICATE KEY UPDATE
4914
- value = 1";
4915
- $this->db_do($q);
4916
-
4917
- $q = "
4918
- INSERT INTO $catalog_category_entity_int
4919
- (
4920
- entity_type_id,
4921
- attribute_id,
4922
- store_id,
4923
- entity_id,
4924
- value
4925
- )
4926
- (SELECT
4927
- $_categoryEntityTypeId,
4928
- $attr_include_in_menu,
4929
- 0,
4930
- scm.shop_entity_id,
4931
- c.include_in_menu
4932
- FROM $categories_temp c
4933
- JOIN $stINch_categories_mapping scm
4934
- ON c.store_category_id = scm.store_category_id
4935
- )
4936
- ON DUPLICATE KEY UPDATE
4937
- value = c.include_in_menu";
4938
- $this->db_do($q);
4939
-
4940
- $q = "
4941
- INSERT INTO $catalog_category_entity_int
4942
- (
4943
- entity_type_id,
4944
- attribute_id,
4945
- store_id,
4946
- entity_id,
4947
- value
4948
- )
4949
- (SELECT
4950
- $_categoryEntityTypeId,
4951
- $is_anchor_attrid,
4952
- 1,
4953
- scm.shop_entity_id,
4954
- c.is_anchor
4955
- FROM $categories_temp c
4956
- JOIN $stINch_categories_mapping scm
4957
- ON c.store_category_id = scm.store_category_id
4958
- )
4959
- ON DUPLICATE KEY UPDATE
4960
- value = c.is_anchor";
4961
- $this->db_do($q);
4962
-
4963
- $q = "
4964
- INSERT INTO $catalog_category_entity_int
4965
- (
4966
- entity_type_id,
4967
- attribute_id,
4968
- store_id,
4969
- entity_id,
4970
- value
4971
- )
4972
- (SELECT
4973
- $_categoryEntityTypeId,
4974
- $is_anchor_attrid,
4975
- 0,
4976
- scm.shop_entity_id,
4977
- c.is_anchor
4978
- FROM $categories_temp c
4979
- JOIN $stINch_categories_mapping scm
4980
- ON c.store_category_id = scm.store_category_id
4981
- )
4982
- ON DUPLICATE KEY UPDATE
4983
- value = c.is_anchor";
4984
- $this->db_do($q);
4985
-
4986
- $q = "
4987
- INSERT INTO $catalog_category_entity_varchar
4988
- (
4989
- entity_type_id,
4990
- attribute_id,
4991
- store_id,
4992
- entity_id,
4993
- value
4994
- )
4995
- (SELECT
4996
- $_categoryEntityTypeId,
4997
- $image_attrid,
4998
- 0,
4999
- scm.shop_entity_id,
5000
- c.categories_image
5001
- FROM $categories_temp c
5002
- JOIN $stINch_categories_mapping scm
5003
- ON c.store_category_id = scm.store_category_id
5004
- )
5005
- ON DUPLICATE KEY UPDATE
5006
- value = c.categories_image";
5007
- $this->db_do($q);
5008
- //STP
5009
- $q = "
5010
- INSERT INTO $catalog_category_entity_varchar
5011
- (
5012
- entity_type_id,
5013
- attribute_id,
5014
- store_id,
5015
- entity_id,
5016
- value
5017
- )
5018
- (SELECT
5019
- $this->_categoryEntityTypeId,
5020
- $this->_categoryMetaTitleAttrId,
5021
- 0,
5022
- scm.shop_entity_id,
5023
- c.MetaTitle
5024
- FROM $categories_temp c
5025
- JOIN $stINch_categories_mapping scm
5026
- ON c.store_category_id = scm.store_category_id
5027
- )
5028
- ON DUPLICATE KEY UPDATE
5029
- value = c.MetaTitle";
5030
- $this->db_do($q);
5031
 
5032
- $q = "
5033
- INSERT INTO $catalog_category_entity_varchar
5034
- (
5035
- entity_type_id,
5036
- attribute_id,
5037
- store_id,
5038
- entity_id,
5039
- value
5040
- )
5041
- (SELECT
5042
- $this->_categoryEntityTypeId,
5043
- $this->_categoryMetadescriptionAttrId,
5044
- 0,
5045
- scm.shop_entity_id,
5046
- c.MetaDescription
5047
- FROM $categories_temp c
5048
- JOIN $stINch_categories_mapping scm
5049
- ON c.store_category_id = scm.store_category_id
5050
- )
5051
- ON DUPLICATE KEY UPDATE
5052
- value = c.MetaDescription";
5053
- $this->db_do($q);
5054
 
5055
- $q = "
5056
- INSERT INTO $catalog_category_entity_varchar
5057
- (
5058
- entity_type_id,
5059
- attribute_id,
5060
- store_id,
5061
- entity_id,
5062
- value
5063
- )
5064
- (SELECT
5065
- $this->_categoryEntityTypeId,
5066
- $this->_categoryDescriptionAttrId,
5067
- 0,
5068
- scm.shop_entity_id,
5069
- c.Description
5070
- FROM $categories_temp c
5071
- JOIN $stINch_categories_mapping scm
5072
- ON c.store_category_id = scm.store_category_id
5073
- )
5074
- ON DUPLICATE KEY UPDATE
5075
- value = c.Description";
5076
- $this->db_do($q);
5077
 
5078
 
5079
- //stp
5080
- }
5081
- else
5082
- {
5083
- echo "Insert ignore category_data \n";
5084
-
5085
- $q = "
5086
- INSERT IGNORE INTO $catalog_category_entity_varchar
5087
- (
5088
- entity_type_id,
5089
- attribute_id,
5090
- store_id,
5091
- entity_id,
5092
- value
5093
- )
5094
- (SELECT
5095
- $_categoryEntityTypeId,
5096
- $name_attrid,
5097
- 0,
5098
- scm.shop_entity_id,
5099
- c.category_name
5100
- FROM $categories_temp c
5101
- JOIN $stINch_categories_mapping scm
5102
- ON c.store_category_id = scm.store_category_id
5103
- )";
5104
- $this->db_do($q);
5105
-
5106
- $q = "
5107
- INSERT IGNORE INTO $catalog_category_entity_int
5108
- (
5109
- entity_type_id,
5110
- attribute_id,
5111
- store_id,
5112
- entity_id,
5113
- value
5114
- )
5115
- (SELECT
5116
- $_categoryEntityTypeId,
5117
- $attr_is_active,
5118
- 0,
5119
- scm.shop_entity_id,
5120
- 1
5121
- FROM $categories_temp c
5122
- JOIN $stINch_categories_mapping scm
5123
- ON c.store_category_id = scm.store_category_id
5124
- )";
5125
- $this->db_do($q);
5126
-
5127
- $q = "
5128
- INSERT IGNORE INTO $catalog_category_entity_int
5129
- (
5130
- entity_type_id,
5131
- attribute_id,
5132
- store_id,
5133
- entity_id,
5134
- value
5135
- )
5136
- (SELECT
5137
- $_categoryEntityTypeId,
5138
- $attr_include_in_menu,
5139
- 0,
5140
- scm.shop_entity_id,
5141
- c.include_in_menu
5142
- FROM $categories_temp c
5143
- JOIN $stINch_categories_mapping scm
5144
- ON c.store_category_id = scm.store_category_id
5145
- )";
5146
- $this->db_do($q);
5147
-
5148
- $q = "
5149
- INSERT IGNORE INTO $catalog_category_entity_int
5150
- (
5151
- entity_type_id,
5152
- attribute_id,
5153
- store_id,
5154
- entity_id,
5155
- value
5156
- )
5157
- (SELECT
5158
- $_categoryEntityTypeId,
5159
- $is_anchor_attrid,
5160
- 0,
5161
- scm.shop_entity_id,
5162
- c.is_anchor
5163
- FROM $categories_temp c
5164
- JOIN $stINch_categories_mapping scm
5165
- ON c.store_category_id = scm.store_category_id
5166
- )";
5167
- $this->db_do($q);
5168
-
5169
- $q = "
5170
- INSERT IGNORE INTO $catalog_category_entity_varchar
5171
- (
5172
- entity_type_id,
5173
- attribute_id,
5174
- store_id,
5175
- entity_id,
5176
- value
5177
- )
5178
- (SELECT
5179
- $_categoryEntityTypeId,
5180
- $image_attrid,
5181
- 0,
5182
- scm.shop_entity_id,
5183
- c.categories_image
5184
- FROM $categories_temp c
5185
- JOIN $stINch_categories_mapping scm
5186
- ON c.store_category_id = scm.store_category_id
5187
- )";
5188
- $this->db_do($q);
5189
- //STP
5190
- $q = "
5191
- INSERT IGNORE INTO $catalog_category_entity_varchar
5192
- (
5193
- entity_type_id,
5194
- attribute_id,
5195
- store_id,
5196
- entity_id,
5197
- value
5198
- )
5199
- (SELECT
5200
- $this->_categoryEntityTypeId,
5201
- $this->_categoryMetaTitleAttrId,
5202
- 0,
5203
- scm.shop_entity_id,
5204
- c.MetaTitle
5205
- FROM $categories_temp c
5206
- JOIN $stINch_categories_mapping scm
5207
- ON c.store_category_id = scm.store_category_id
5208
- )
5209
- ";
5210
- $this->db_do($q);
5211
 
5212
- $q = "
5213
- INSERT IGNORE INTO $catalog_category_entity_varchar
5214
- (
5215
- entity_type_id,
5216
- attribute_id,
5217
- store_id,
5218
- entity_id,
5219
- value
5220
- )
5221
- (SELECT
5222
- $this->_categoryEntityTypeId,
5223
- $this->_categoryMetadescriptionAttrId,
5224
- 0,
5225
- scm.shop_entity_id,
5226
- c.MetaDescription
5227
- FROM $categories_temp c
5228
- JOIN $stINch_categories_mapping scm
5229
- ON c.store_category_id = scm.store_category_id
5230
- )
5231
- ";
5232
- $this->db_do($q);
5233
 
5234
- $q = "
5235
- INSERT IGNORE INTO $catalog_category_entity_varchar
5236
- (
5237
- entity_type_id,
5238
- attribute_id,
5239
- store_id,
5240
- entity_id,
5241
- value
5242
- )
5243
- (SELECT
5244
- $this->_categoryEntityTypeId,
5245
- $this->_categoryDescriptionAttrId,
5246
- 0,
5247
- scm.shop_entity_id,
5248
- c.Description
5249
- FROM $categories_temp c
5250
- JOIN $stINch_categories_mapping scm
5251
- ON c.store_category_id = scm.store_category_id
5252
- )
5253
- ";
5254
- $this->db_do($q);
 
 
 
 
 
5255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5256
 
5257
- //stp
5258
-
5259
- }
5260
 
5261
- $this->delete_old_sinch_categories_from_shop();
5262
 
5263
- $this->db_do("DROP TABLE IF EXISTS $stINch_categories");
5264
- $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
5265
- } // private function addCategoryData(...)
5266
- ################################################################################################################################################################
5267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5268
 
 
5269
 
 
5270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5271
 
 
5272
 
 
5273
 
 
 
 
 
 
 
 
 
 
 
 
5274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5275
 
 
5276
 
5277
 
 
5278
 
 
5279
 
 
5280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5281
 
5282
 
 
5283
 
5284
- function ParseCategoryFeatures(){
5285
 
5286
- $parse_file=$this->varDir.FILE_CATEGORIES_FEATURES;
5287
- if(filesize($parse_file) || $this->_ignore_category_features){
5288
- $this->_LOG("Start parse ".FILE_CATEGORIES_FEATURES);
5289
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp'));
5290
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')." (
5291
- category_feature_id int(11),
5292
- store_category_id int(11),
5293
- feature_name varchar(50),
5294
- display_order_number int(11),
5295
- KEY(store_category_id),
5296
- KEY(category_feature_id)
5297
- )
5298
- ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5299
 
5300
- if(!$this->_ignore_category_features){
5301
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5302
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
5303
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5304
- OPTIONALLY ENCLOSED BY '\"'
5305
- LINES TERMINATED BY \"\r\n\"
5306
- IGNORE 1 LINES ");
5307
- }
5308
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
5309
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
5310
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
 
 
 
 
 
 
 
 
 
 
 
 
 
5311
 
5312
- $this->_LOG("Finish parse ".FILE_CATEGORIES_FEATURES);
5313
- }else{
5314
- $this->_LOG("Wrong file ".$parse_file);
5315
- }
5316
- $this->_LOG(' ');
5317
  }
5318
 
5319
  #################################################################################################
5320
 
5321
- function ParseDistributors(){
5322
-
5323
- $parse_file=$this->varDir.FILE_DISTRIBUTORS;
5324
- if(filesize($parse_file)){
5325
- $this->_LOG("Start parse ".FILE_DISTRIBUTORS);
5326
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('distributors_temp'));
5327
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."(
5328
- distributor_id int(11),
5329
- distributor_name varchar(255),
5330
- website varchar(255),
5331
- KEY(distributor_id)
5332
- )
5333
- ");
5334
-
5335
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5336
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
5337
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5338
- OPTIONALLY ENCLOSED BY '\"'
5339
- LINES TERMINATED BY \"\r\n\"
5340
- IGNORE 1 LINES ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5341
 
5342
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
5343
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
5344
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
5345
 
5346
- $this->_LOG("Finish parse ".FILE_DISTRIBUTORS);
5347
- }else{
5348
- $this->_LOG("Wrong file ".$parse_file);
5349
- }
5350
- $this->_LOG(' ');
5351
  }
5352
 
5353
- #################################################################################################
5354
-
5355
- function ParseDistributorsStockAndPrice(){
5356
- $parse_file=$this->varDir.FILE_DISTRIBUTORS_STOCK_AND_PRICES;
5357
- if(filesize($parse_file)){
5358
- $this->_LOG("Start parse ".FILE_DISTRIBUTORS_STOCK_AND_PRICES);
5359
 
5360
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp'));
5361
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."(
5362
- `store_product_id` int(11) DEFAULT NULL,
5363
- `distributor_id` int(11) DEFAULT NULL,
5364
- `stock` int(11) DEFAULT NULL,
5365
- `cost` decimal(15,4) DEFAULT NULL,
5366
- `distributor_sku` varchar(255) DEFAULT NULL,
5367
- `distributor_category` varchar(50) DEFAULT NULL,
5368
- `eta` varchar(50) DEFAULT NULL,
5369
- UNIQUE KEY `product_distri` (store_product_id, distributor_id)
5370
- )");
5371
 
5372
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5373
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."
5374
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5375
- OPTIONALLY ENCLOSED BY '\"'
5376
- LINES TERMINATED BY \"\r\n\"
5377
- IGNORE 1 LINES ");
5378
 
5379
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
5380
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp')."
5381
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
 
 
 
5382
 
5383
- $this->_LOG("Finish parse ".FILE_DISTRIBUTORS_STOCK_AND_PRICES);
5384
- }else{
5385
- $this->_LOG("Wrong file ".$parse_file);
 
 
 
 
 
5386
  }
5387
- $this->_LOG(' ');
5388
 
5389
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5390
 
 
 
 
 
 
 
 
 
 
5391
 
5392
- #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
5393
 
5394
- function ParseEANCodes(){
 
 
 
 
 
5395
 
5396
- $parse_file=$this->varDir.FILE_EANCODES;
5397
- if(filesize($parse_file)){
5398
- $this->_LOG("Start parse ".FILE_EANCODES);
 
 
 
 
 
 
 
 
 
 
 
 
 
5399
 
5400
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp'));
5401
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."(
5402
- product_id int(11),
5403
- ean_code varchar(255),
5404
- KEY(product_id)
5405
- )");
5406
 
5407
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5408
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
5409
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5410
- OPTIONALLY ENCLOSED BY '\"'
5411
- LINES TERMINATED BY \"\r\n\"
5412
- IGNORE 1 LINES ");
 
5413
 
5414
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
5415
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
5416
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
 
 
 
 
 
 
 
 
 
 
 
5417
 
5418
- $this->_LOG("Finish parse ".FILE_EANCODES);
5419
- }else{
5420
- $this->_LOG("Wrong file ".$parse_file);
5421
- }
5422
- $this->_LOG(' ');
5423
  }
 
 
 
5424
 
5425
- #################################################################################################
5426
-
5427
- function ParseManufacturers(){
5428
-
5429
- $parse_file=$this->varDir.FILE_MANUFACTURERS;
5430
- if(filesize($parse_file)){
5431
- $this->_LOG("Start parse ".FILE_MANUFACTURERS);
5432
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp'));
5433
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."(
5434
- sinch_manufacturer_id int(11),
5435
- manufacturer_name varchar(255),
5436
- manufacturers_image varchar(255),
5437
- shop_option_id int(11),
5438
- KEY(sinch_manufacturer_id),
5439
- KEY(shop_option_id),
5440
- KEY(manufacturer_name)
5441
- )");
5442
-
5443
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5444
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
5445
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5446
- OPTIONALLY ENCLOSED BY '\"'
5447
- LINES TERMINATED BY \"\r\n\"
5448
- IGNORE 1 LINES ");
5449
-
5450
- $q="DELETE aov
5451
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5452
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5453
- ON ao.option_id=aov.option_id left
5454
- JOIN ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
5455
- ON aov.value=mt.manufacturer_name
5456
- WHERE
5457
- ao.attribute_id=".$this->attributes['manufacturer']." AND
5458
- mt.manufacturer_name is null";
5459
- $this->db_do($q);
5460
-
5461
- $q="DELETE ao
5462
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5463
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5464
- ON ao.option_id=aov.option_id
5465
- WHERE
5466
- attribute_id=".$this->attributes['manufacturer']." AND
5467
- aov.option_id is null";
5468
- $this->db_do($q);
5469
-
5470
- $q="SELECT
5471
- m.sinch_manufacturer_id,
5472
- m.manufacturer_name,
5473
- m.manufacturers_image
5474
- FROM ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." m
5475
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5476
- ON m.manufacturer_name=aov.value
5477
- WHERE aov.value IS NULL";
5478
- $quer=$this->db_do($q);
5479
-
5480
- while($row=mysqli_fetch_array($quer)){
5481
- $q0="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
5482
- (attribute_id)
5483
- VALUES(".$this->attributes['manufacturer'].")";
5484
- $quer0=$this->db_do($q0);
5485
 
5486
- $q2="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')."(
5487
- option_id,
5488
- value
5489
- )(
5490
- SELECT
5491
- max(option_id) as option_id,
5492
- "."'".mysqli_real_escape_string($this->db, $row['manufacturer_name'])."'
5493
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
5494
- WHERE attribute_id=".$this->attributes['manufacturer']."
5495
- )
5496
- ";
5497
- $quer2=$this->db_do($q2);
5498
- // $option['attribute_id'] = $this->attributes['manufacturer'];
5499
- // $option['value'][$row['sinch_manufacturer_id']][0] = $row['manufacturer_name'];
5500
 
5501
- }
 
5502
 
5503
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
5504
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
5505
- ON mt.manufacturer_name=aov.value
5506
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
5507
- ON ao.option_id=aov.option_id
5508
- SET mt.shop_option_id=aov.option_id
5509
- WHERE ao.attribute_id=".$this->attributes['manufacturer'];
5510
- $this->db_do($q);
5511
 
5512
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
5513
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
5514
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
5515
- $this->_LOG("Finish parse ".FILE_MANUFACTURERS);
5516
- }else{
5517
- $this->_LOG("Wrong file ".$parse_file);
5518
- }
5519
- $this->_LOG(' ');
5520
- }
5521
 
5522
- #################################################################################################
5523
 
5524
- function ParseProductFeatures(){
5525
 
5526
- $parse_file=$this->varDir.FILE_PRODUCT_FEATURES;
5527
- if(filesize($parse_file) || $this->_ignore_product_features){
5528
- $this->_LOG("Start parse ".FILE_PRODUCT_FEATURES);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5529
 
5530
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('product_features_temp'));
5531
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."(
5532
- product_feature_id int(11),
5533
- sinch_product_id int(11),
5534
- restricted_value_id int(11),
5535
- KEY(sinch_product_id),
5536
- KEY(restricted_value_id)
5537
- )
5538
- ");
5539
- if(!$this->_ignore_product_features){
5540
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5541
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
5542
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5543
- OPTIONALLY ENCLOSED BY '\"'
5544
- LINES TERMINATED BY \"\r\n\"
5545
- IGNORE 1 LINES ");
5546
- }
5547
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
5548
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
5549
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
 
 
 
 
 
5550
 
5551
- $this->_LOG("Finish parse ".FILE_PRODUCT_FEATURES);
5552
- }else{
5553
- $this->_LOG("Wrong file ".$parse_file);
5554
- }
5555
- $this->_LOG(" ");
5556
- }
5557
- #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5558
 
5559
- function ParseCategoryTypes(){
5560
- $parse_file=$this->varDir.FILE_CATEGORY_TYPES;
5561
- if(filesize($parse_file)){
5562
- $this->_LOG("Start parse ".FILE_CATEGORY_TYPES);
5563
 
5564
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('category_types_temp'));
5565
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."(
5566
- id int(11),
5567
- name varchar(255),
5568
- key(id)
5569
- )");
5570
 
5571
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5572
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."
5573
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5574
- OPTIONALLY ENCLOSED BY '\"'
5575
- LINES TERMINATED BY \"\r\n\"
5576
- IGNORE 1 LINES ");
 
5577
 
5578
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_category_types'));
5579
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('category_types_temp')."
5580
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_category_types'));
 
 
 
 
 
 
 
 
 
 
 
 
5581
 
5582
- $this->_LOG("Finish parse ".FILE_CATEGORY_TYPES);
5583
- }else{
5584
- $this->_LOG("Wrong file ".$parse_file);
5585
- }
5586
- $this->_LOG(' ');
5587
 
5588
- }
5589
 
5590
- #################################################################################################
5591
 
5592
- function ParseProductCategories(){
5593
- $parse_file=$this->varDir.FILE_PRODUCT_CATEGORIES;
5594
- if(filesize($parse_file)){
5595
- $this->_LOG("Start parse ".FILE_PRODUCT_CATEGORIES);
 
 
 
 
 
 
 
 
 
 
5596
 
5597
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp'));
5598
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."(
5599
- store_product_id int(11),
5600
- store_category_id int(11),
5601
- key(store_product_id),
5602
- key(store_category_id)
5603
- )");
5604
 
5605
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5606
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."
5607
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5608
- OPTIONALLY ENCLOSED BY '\"'
5609
- LINES TERMINATED BY \"\r\n\"
5610
- IGNORE 1 LINES ");
5611
 
5612
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories'));
5613
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('product_categories_temp')."
5614
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories'));
5615
 
5616
- $this->_LOG("Finish parse ".FILE_PRODUCT_CATEGORIES);
5617
- }else{
5618
- $this->_LOG("Wrong file ".$parse_file);
5619
- }
5620
- $this->_LOG(' ');
 
 
5621
 
5622
- }
5623
- #################################################################################################
5624
 
5625
- function ParseProducts($coincidence){
5626
- echo("\nParseProducts 2\n");
5627
- $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
5628
- $replace_merge_product = $dataConf['replace_products'];
5629
 
5630
- $parse_file=$this->varDir.FILE_PRODUCTS;
5631
- if(filesize($parse_file)){
5632
- $this->_LOG("Start parse ".FILE_PRODUCTS);
5633
- echo("\nParseProducts 2\n");
5634
 
5635
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
5636
- if($this->product_file_format == "NEW"){
5637
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
5638
- store_product_id int(11),
5639
- product_sku varchar(255),
5640
- product_name varchar(255),
5641
- sinch_manufacturer_id int(11),
5642
- main_image_url varchar(255),
5643
- thumb_image_url varchar(255),
5644
- specifications text,
5645
- description text,
5646
- search_cache text,
5647
- description_type varchar(50),
5648
- medium_image_url varchar(255),
5649
- Title varchar(255),
5650
- Weight decimal(15,4),
5651
- Family varchar(255),
5652
- Reviews varchar(255),
5653
- pdf_url varchar(255),
5654
- product_short_description varchar(255),
5655
- products_date_added datetime default NULL,
5656
- products_last_modified datetime default NULL,
5657
- availability_id_in_stock int(11) default '1',
5658
- availability_id_out_of_stock int(11) default '2',
5659
- products_locate varchar(30) default NULL,
5660
- products_ordered int(11) NOT NULL default '0',
5661
- products_url varchar(255) default NULL,
5662
- products_viewed int(5) default '0',
5663
- products_seo_url varchar(100) NOT NULL,
5664
- manufacturer_name varchar(255) default NULL,
5665
- KEY(store_product_id),
5666
- KEY(sinch_manufacturer_id)
5667
- )DEFAULT CHARSET=utf8
5668
- ");
5669
- }elseif($this->product_file_format == "OLD"){
5670
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
5671
- store_category_product_id int(11),
5672
- store_product_id int(11),
5673
- sinch_product_id int(11),
5674
- product_sku varchar(255),
5675
- product_name varchar(255),
5676
- sinch_manufacturer_id int(11),
5677
- store_category_id int(11),
5678
- main_image_url varchar(255),
5679
- thumb_image_url varchar(255),
5680
- specifications text,
5681
- description text,
5682
- search_cache text,
5683
- spec_characte_u_count int(11),
5684
- description_type varchar(50),
5685
- medium_image_url varchar(255),
5686
- products_date_added datetime default NULL,
5687
- products_last_modified datetime default NULL,
5688
- availability_id_in_stock int(11) default '1',
5689
- availability_id_out_of_stock int(11) default '2',
5690
- products_locate varchar(30) default NULL,
5691
- products_ordered int(11) NOT NULL default '0',
5692
- products_url varchar(255) default NULL,
5693
- products_viewed int(5) default '0',
5694
- products_seo_url varchar(100) NOT NULL,
5695
- manufacturer_name varchar(255) default NULL,
5696
- KEY(store_category_product_id),
5697
- KEY(store_product_id),
5698
- KEY(sinch_manufacturer_id),
5699
- KEY(store_category_id)
5700
- )DEFAULT CHARSET=utf8
5701
- ");
5702
 
5703
- }
5704
- echo("\nParseProducts 3\n");
5705
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5706
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5707
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5708
- OPTIONALLY ENCLOSED BY '\"'
5709
- LINES TERMINATED BY \"\r\n\"
5710
- IGNORE 1 LINES ");
5711
 
5712
- if($this->product_file_format == "NEW"){
5713
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5714
- ADD COLUMN sinch_product_id int(11) AFTER store_product_id
5715
- ");
5716
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5717
- SET sinch_product_id=store_product_id
5718
- ");
 
 
 
 
 
5719
 
5720
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5721
- ADD COLUMN store_category_id int(11) AFTER sinch_manufacturer_id
5722
- ");
5723
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5724
- ADD KEY(store_category_id)
5725
- ");
5726
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5727
- SET product_name = Title WHERE Title != ''
5728
- ");
5729
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." pt
5730
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
5731
- SET pt.store_category_id=spc.store_category_id
5732
- WHERE pt.store_product_id=spc.store_product_id
5733
- ");
5734
- //http://redmine.bintime.com/issues/4127
5735
- //3.
5736
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5737
- SET main_image_url = medium_image_url WHERE main_image_url = ''
5738
- ");
5739
- //end
5740
 
5741
- }
5742
 
5743
- echo("\nParseProducts 4\n");
5744
 
5745
- echo("\nParseProducts 5\n");
5746
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5747
- SET products_date_added=now(), products_last_modified=now()");
5748
- echo("\nParseProducts 6\n");
5749
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
5750
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." m
5751
- ON p.sinch_manufacturer_id=m.sinch_manufacturer_id
5752
- SET p.manufacturer_name=m.manufacturer_name");
5753
- echo("\nParseProducts 7\n");
5754
- if($this->current_import_status_statistic_id){
5755
- $res = $this->db_do("SELECT COUNT(*) AS cnt
5756
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
5757
- $row = mysqli_fetch_assoc($res);
5758
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
5759
- SET number_of_products=".$row['cnt']."
5760
- WHERE id=".$this->current_import_status_statistic_id);
5761
- }
5762
 
5763
- if ($replace_merge_product == "REWRITE"){
5764
- $this->db_do ("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'));
5765
- $this->db_do ("SET FOREIGN_KEY_CHECKS=0");
5766
- $this->db_do ("TRUNCATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'));
5767
- $this->db_do ("SET FOREIGN_KEY_CHECKS=1");
5768
- }
5769
 
5770
- echo("\nParseProducts 8\n");
5771
- $this->addProductsWebsite();
5772
- $this->mapSinchProducts();
5773
- echo("\nParseProducts 9\n");
5774
-
5775
- if (count($coincidence) == 1)
5776
- {
5777
- $this->replaceMagentoProducts();
5778
- }
5779
- else
5780
- {
5781
- echo("\n\n\n\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ [".$this->im_type."] $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n\n\n"); //exit;
5782
-
5783
-
5784
- switch ($this->im_type)
5785
- {
5786
- case "REWRITE": $this->replaceMagentoProductsMultistore($coincidence); break;
5787
- case "MERGE": $this->replaceMagentoProductsMultistoreMERGE($coincidence); break;
5788
- }
5789
- }
5790
- echo("\nParseProducts 10\n");
5791
-
5792
-
5793
- $this->mapSinchProducts();
5794
- $this->addManufacturer_attribute();
5795
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
5796
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
5797
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
5798
- $this->_LOG("Finish parse ".FILE_PRODUCTS);
5799
- }else{
5800
- $this->_LOG("Wrong file ".$parse_file);
5801
- }
5802
- $this->_LOG(" ");
5803
- echo("\nParseProducts 11\n");
5804
- }
5805
 
5806
- #################################################################################################
5807
 
5808
- function ParseRelatedProducts(){
 
 
 
 
 
5809
 
5810
- $parse_file=$this->varDir.FILE_RELATED_PRODUCTS;
5811
- if(filesize($parse_file) || $this->_ignore_product_related){
5812
- $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
5813
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('related_products_temp'));
5814
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."(
5815
- sinch_product_id int(11),
5816
- related_sinch_product_id int(11),
5817
- store_product_id int(11) default null,
5818
- store_related_product_id int(11) default null,
5819
- entity_id int(11),
5820
- related_entity_id int(11),
5821
- KEY(sinch_product_id),
5822
- KEY(related_sinch_product_id),
5823
- KEY(store_product_id)
5824
- )DEFAULT CHARSET=utf8");
5825
- if(!$this->_ignore_product_related){
5826
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5827
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
5828
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5829
- OPTIONALLY ENCLOSED BY '\"'
5830
- LINES TERMINATED BY \"\r\n\"
5831
- IGNORE 1 LINES ");
5832
- }
5833
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
5834
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
5835
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
5836
 
5837
- $this->_LOG("Finish parse ".FILE_RELATED_PRODUCTS);
5838
- }else{
5839
- $this->_LOG("Wrong file ".$parse_file);
5840
- }
5841
- $this->_LOG(" ");
5842
- }
5843
 
5844
- #################################################################################################
5845
 
5846
- function ParseRestrictedValues(){
5847
 
5848
- $parse_file=$this->varDir.FILE_RESTRICTED_VALUES;
5849
- if(filesize($parse_file) || $this->_ignore_restricted_values){
5850
- $this->_LOG("Start parse ".FILE_RESTRICTED_VALUES);
5851
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp'));
5852
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')." (
5853
- restricted_value_id int(11),
5854
- category_feature_id int(11),
5855
- text text,
5856
- display_order_number int(11),
5857
- KEY(restricted_value_id),
5858
- KEY(category_feature_id)
5859
- )");
5860
- if(!$this->_ignore_restricted_values){
5861
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5862
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
5863
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5864
- OPTIONALLY ENCLOSED BY '\"'
5865
- LINES TERMINATED BY \"\r\n\"
5866
- IGNORE 1 LINES ");
5867
- }
5868
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
5869
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
5870
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
5871
 
5872
- $this->_LOG("Finish parse ".FILE_RESTRICTED_VALUES);
5873
- }else{
5874
- $this->_LOG("Wrong file ".$parse_file);
5875
- }
5876
- $this->_LOG(" ");
5877
- }
5878
 
5879
- #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5880
 
5881
- function ParseStockAndPrices(){
 
 
 
 
 
 
 
 
 
 
 
 
5882
 
5883
- $parse_file=$this->varDir.FILE_STOCK_AND_PRICES;
5884
- if(filesize($parse_file)){
5885
- $this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
5886
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp'));
5887
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." (
5888
- store_product_id int(11),
5889
- stock int(11),
5890
- price decimal(15,4),
5891
- cost decimal(15,4),
5892
- distributor_id int(11),
5893
- KEY(store_product_id),
5894
- KEY(distributor_id)
5895
- )");
5896
 
5897
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5898
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
5899
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5900
- OPTIONALLY ENCLOSED BY '\"'
5901
- LINES TERMINATED BY \"\r\n\"
5902
- IGNORE 1 LINES ");
5903
 
5904
- $this->replaceMagentoProductsStockPrice();
 
 
 
 
 
5905
 
5906
- $res = $this->db_do("SELECT count(*) as cnt
5907
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5908
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
5909
- ON a.store_product_id=b.store_product_id");
5910
- $row = mysqli_fetch_assoc($res);
5911
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
5912
- SET number_of_products=".$row['cnt']."
5913
- WHERE id=".$this->current_import_status_statistic_id);
5914
 
5915
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
5916
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
5917
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
5918
 
5919
- $this->_LOG("Finish parse".FILE_RELATED_PRODUCTS);
5920
- }else{
5921
- $this->_LOG("Wrong file".$parse_file);
5922
- }
5923
- $this->_LOG(" ");
5924
- }
5925
 
5926
- #################################################################################################
 
 
 
 
 
5927
 
5928
- function ParseProductsPicturesGallery(){
5929
 
5930
- $parse_file=$this->varDir.FILE_PRODUCTS_PICTURES_GALLERY;
5931
- if(filesize($parse_file)){
5932
- $this->_LOG("Start parse ".FILE_PRODUCTS_PICTURES_GALLERY);
5933
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp'));
5934
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." (
5935
- sinch_product_id int(11),
5936
- image_url varchar(255),
5937
- thumb_image_url varchar(255),
5938
- store_product_id int(11),
5939
- key(sinch_product_id),
5940
- key(store_product_id)
5941
- )");
5942
 
5943
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5944
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
5945
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5946
- OPTIONALLY ENCLOSED BY '\"'
5947
- LINES TERMINATED BY \"\r\n\"
5948
- IGNORE 1 LINES ");
5949
 
5950
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." ppgt
5951
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
5952
- ON ppgt.sinch_product_id=sp.sinch_product_id
5953
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5954
- ON sp.store_product_id=cpe.store_product_id
5955
- SET ppgt.store_product_id=sp.store_product_id");
5956
 
5957
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
5958
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
5959
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5960
 
5961
- $this->_LOG("Finish parse".FILE_PRODUCTS_PICTURES_GALLERY);
5962
- }else{
5963
- $this->_LOG("Wrong file".$parse_file);
5964
- }
5965
- $this->_LOG(" ");
 
 
 
 
 
 
 
 
 
 
 
 
5966
 
5967
- }
5968
 
5969
- #################################################################################################
5970
 
5971
- function ParsePriceRules(){
5972
- $parse_file=$this->varDir.FILE_PRICE_RULES;
5973
- if(filesize($parse_file) || $this->_ignore_price_rules){
5974
- $this->_LOG("Start parse ".FILE_PRICE_RULES);
 
 
 
5975
 
5976
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp'));
5977
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."(
5978
- `id` int(11) NOT NULL,
5979
- `price_from` decimal(10,2) DEFAULT NULL,
5980
- `price_to` decimal(10,2) DEFAULT NULL,
5981
- `category_id` int(10) unsigned DEFAULT NULL,
5982
- `vendor_id` int(11) DEFAULT NULL,
5983
- `vendor_product_id` varchar(255) DEFAULT NULL,
5984
- `customergroup_id` varchar(32) DEFAULT NULL,
5985
- `marge` decimal(10,2) DEFAULT NULL,
5986
- `fixed` decimal(10,2) DEFAULT NULL,
5987
- `final_price` decimal(10,2) DEFAULT NULL,
5988
- PRIMARY KEY (`id`),
5989
- UNIQUE KEY `price_from` (`price_from`,`price_to`,`vendor_id`,`category_id`,`vendor_product_id`,`customergroup_id`),
5990
- KEY `vendor_product_id` (`vendor_product_id`),
5991
- KEY `category_id` (`category_id`)
5992
- )
5993
- ");
5994
- if(!$this->_ignore_price_rules){
5995
 
5996
- $this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
5997
- INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
5998
- FIELDS TERMINATED BY '".$this->field_terminated_char."'
5999
- OPTIONALLY ENCLOSED BY '\"'
6000
- LINES TERMINATED BY \"\r\n\"
6001
- IGNORE 1 LINES
6002
- (id, @vprice_from, @vprice_to, @vcategory_id, @vvendor_id, @vvendor_product_id, @vcustomergroup_id, @vmarge, @vfixed, @vfinal_price)
6003
- SET price_from = nullif(@vprice_from,''),
6004
- price_to = nullif(@vprice_to,''),
6005
- category_id = nullif(@vcategory_id,''),
6006
- vendor_id = nullif(@vvendor_id,''),
6007
- vendor_product_id = nullif(@vvendor_product_id,''),
6008
- customergroup_id = nullif(@vcustomergroup_id,''),
6009
- marge = nullif(@vmarge,''),
6010
- fixed = nullif(@vfixed,''),
6011
- final_price = nullif(@vfinal_price,'')
6012
- ");
6013
- }
6014
 
6015
- $this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6016
- ADD COLUMN `shop_category_id` int(10) unsigned DEFAULT NULL,
6017
- ADD COLUMN `shop_vendor_id` int(11) DEFAULT NULL,
6018
- ADD COLUMN `shop_vendor_product_id` varchar(255) DEFAULT NULL,
6019
- ADD COLUMN `shop_customergroup_id` varchar(32) DEFAULT NULL
6020
- ");
6021
 
6022
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6023
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6024
- ON prt.category_id = cce.store_category_id
6025
- SET prt.shop_category_id = cce.entity_id");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6026
 
6027
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6028
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." sicm
6029
- ON prt.vendor_id = sicm.sinch_manufacturer_id
6030
- SET prt.shop_vendor_id = sicm.shop_option_id");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6031
 
6032
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6033
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." sicpm
6034
- ON prt.vendor_product_id = sicpm.product_sku
6035
- SET prt.shop_vendor_product_id = sicpm.sku");
6036
 
6037
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')." prt
6038
- JOIN ".Mage::getSingleton('core/resource')->getTableName('customer_group')." cg
6039
- ON prt.customergroup_id = cg.customer_group_id
6040
- SET prt.shop_customergroup_id = cg.customer_group_id");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6041
 
6042
- $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6043
- WHERE
6044
- (category_id IS NOT NULL AND shop_category_id IS NULL) OR
6045
- (vendor_id IS NOT NULL AND shop_vendor_id IS NULL) OR
6046
- (vendor_product_id IS NOT NULL AND shop_vendor_product_id IS NULL) OR
6047
- (customergroup_id IS NOT NULL AND shop_customergroup_id IS NULL)
6048
- ");
6049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6050
 
6051
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules'));
6052
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('price_rules_temp')."
6053
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules'));
6054
 
6055
- $this->_LOG("Finish parse ".FILE_PRICE_RULES);
6056
- }else{
6057
- $this->_LOG("Wrong file ".$parse_file);
 
 
 
 
 
 
 
6058
  }
6059
- $this->_LOG(" ");
6060
- }
 
6061
 
6062
- #################################################################################################
6063
 
6064
- function AddPriceRules(){
6065
- if (!$this->check_table_exist('import_pricerules_standards')){
6066
- return;
6067
- }
6068
 
 
6069
  $result = $this->db_do("
6070
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('import_pricerules')." (
6071
- id,
6072
- price_from,
6073
- price_to,
6074
- vendor_id,
6075
- category_id,
6076
- vendor_product_id,
6077
- customergroup_id,
6078
- marge,
6079
- fixed,
6080
- final_price
6081
- )(SELECT
6082
- id,
6083
- price_from,
6084
- price_to,
6085
- shop_vendor_id,
6086
- shop_category_id,
6087
- shop_vendor_product_id,
6088
- shop_customergroup_id,
6089
- marge,
6090
- fixed,
6091
- final_price
6092
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_price_rules')." a
6093
- )
6094
- ON DUPLICATE KEY UPDATE
6095
- id = a.id,
6096
- price_from = a.price_from,
6097
- price_to = a.price_to,
6098
- vendor_id = a.shop_vendor_id,
6099
- category_id = a.shop_category_id,
6100
- vendor_product_id = a.shop_vendor_product_id,
6101
- customergroup_id = a.shop_customergroup_id,
6102
- marge = a.marge,
6103
- fixed = a.fixed,
6104
- final_price = a.final_price
6105
- ");
6106
-
6107
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6108
 
6109
- #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6110
 
6111
- public function mapSinchProducts(){
6112
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
6113
- $this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
6114
- entity_id int(11) unsigned NOT NULL,
6115
- manufacturer_option_id int(11),
6116
- manufacturer_name varchar(255),
6117
- shop_store_product_id int(11),
6118
- shop_sinch_product_id int(11),
6119
- sku varchar(64) default NULL,
6120
- store_product_id int(11),
6121
- sinch_product_id int(11),
6122
- product_sku varchar(255),
6123
- sinch_manufacturer_id int(11),
6124
- sinch_manufacturer_name varchar(255),
6125
- KEY entity_id (entity_id),
6126
- KEY manufacturer_option_id (manufacturer_option_id),
6127
- KEY manufacturer_name (manufacturer_name),
6128
- KEY store_product_id (store_product_id),
6129
- KEY sinch_product_id (sinch_product_id),
6130
- KEY sku (sku),
6131
- UNIQUE KEY(entity_id)
6132
- )
6133
- ");
6134
- $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
6135
- LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
6136
  $result = $this->db_do("
6137
- INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
6138
- entity_id,
6139
- sku,
6140
- shop_store_product_id,
6141
- shop_sinch_product_id
6142
- )(SELECT
6143
- entity_id,
6144
- sku,
6145
- store_product_id,
6146
- sinch_product_id
6147
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')."
6148
- )
6149
- ");
 
 
 
 
6150
 
6151
- $this->addManufacturers(1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6152
 
6153
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6154
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." cpie
6155
- ON pmt.entity_id=cpie.entity_id
6156
- JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
6157
- ON cpie.value=aov.option_id
6158
- SET
6159
- manufacturer_option_id=cpie.value,
6160
- manufacturer_name=aov.value
6161
- WHERE cpie.attribute_id=".$this->attributes['manufacturer'];
6162
- $this->db_do($q);
6163
 
6164
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6165
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6166
- ON pmt.sku=p.product_sku
6167
- SET
6168
- pmt.store_product_id=p.store_product_id,
6169
- pmt.sinch_product_id=p.sinch_product_id,
6170
- pmt.product_sku=p.product_sku,
6171
- pmt.sinch_manufacturer_id=p.sinch_manufacturer_id,
6172
- pmt.sinch_manufacturer_name=p.manufacturer_name";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6173
 
6174
- $this->db_do($q);
6175
 
6176
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6177
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
6178
- ON cpe.entity_id=pmt.entity_id
6179
- SET cpe.store_product_id=pmt.store_product_id,
6180
- cpe.sinch_product_id=pmt.sinch_product_id
6181
- WHERE
6182
- cpe.sinch_product_id IS NULL
6183
- AND pmt.sinch_product_id IS NOT NULL
6184
- AND cpe.store_product_id IS NULL
6185
- AND pmt.store_product_id IS NOT NULL";
6186
- $this->db_do($q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6187
 
6188
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
6189
- $this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')."
6190
- TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
6191
- }
6192
- #################################################################################################
6193
- public function addProductsWebsite (){
6194
- $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_website_temp'));
6195
- // TEMPORARY
6196
- $this->db_do("
6197
- CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('products_website_temp')."` (
6198
- `id` int(10) unsigned NOT NULL auto_increment,
6199
- store_product_id int(11),
6200
- sinch_product_id int(11),
6201
- `website` int(11) default NULL,
6202
- `website_id` int(11) default NULL,
6203
- PRIMARY KEY (`id`),
6204
- KEY store_product_id (`store_product_id`)
6205
- )
6206
- ");
6207
- $result = $this->db_do("SELECT
6208
- website_id,
6209
- store_id as website
6210
- FROM ".Mage::getSingleton('core/resource')->getTableName('core_store')."
6211
- WHERE code!='admin'
6212
- "); // where code!='admin' was adder for editing Featured products;
6213
- while ($row = mysqli_fetch_assoc($result)) {
6214
- $sql = "INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." (
6215
- store_product_id,
6216
- sinch_product_id,
6217
- website,
6218
- website_id
6219
- )(
6220
- SELECT
6221
- distinct
6222
- store_product_id,
6223
- sinch_product_id,
6224
- {$row['website']},
6225
- {$row['website_id']}
6226
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
6227
- )";
6228
- $result2 = $this->db_do($sql);
6229
- }
6230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6231
 
 
 
6232
  }
6233
 
6234
  #################################################################################################
6235
- public function replaceMagentoProducts() {
 
 
 
 
 
6236
 
6237
  $connection = Mage::getModel('core/resource')->getConnection('core_write');
6238
 
6239
- $result = $this->db_do("DELETE cpe
6240
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6241
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6242
- ON cpe.entity_id=pm.entity_id
6243
- WHERE pm.shop_store_product_id IS NOT NULL
6244
- AND pm.store_product_id IS NULL
6245
- ");
6246
 
6247
- //Inserting new products and updating old others.
6248
- $this->_getProductDefaulAttributeSetId();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6249
  $result = $this->db_do("
6250
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." (
6251
- entity_id,
6252
- entity_type_id,
6253
- attribute_set_id,
6254
- type_id,
6255
- sku,
6256
- updated_at,
6257
- has_options,
6258
- store_product_id,
6259
- sinch_product_id
6260
- )(SELECT
6261
- pm.entity_id,
6262
- " . $this->_getProductEntityTypeId(). ",
6263
- $this->defaultAttributeSetId,
6264
- 'simple',
6265
- a.product_sku,
6266
- NOW(),
6267
- 0,
6268
- a.store_product_id,
6269
- a.sinch_product_id
6270
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')." a
6271
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6272
- ON a.store_product_id=pm.store_product_id
6273
- AND a.sinch_product_id=pm.sinch_product_id
6274
- WHERE pm.entity_id IS NOT NULL
6275
- )
6276
- ON DUPLICATE KEY UPDATE
6277
- sku= a.product_sku,
6278
- store_product_id=a.store_product_id,
6279
- sinch_product_id=a.sinch_product_id
6280
- ");
6281
- // store_product_id=a.store_product_id,
6282
- // sinch_product_id=a.sinch_product_id
6283
 
6284
  $result = $this->db_do("
6285
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." (
6286
- entity_id,
6287
- entity_type_id,
6288
- attribute_set_id,
6289
- type_id,
6290
- sku,
6291
- updated_at,
6292
- has_options,
6293
- store_product_id,
6294
- sinch_product_id
6295
- )(SELECT
6296
- pm.entity_id,
6297
- " . $this->_getProductEntityTypeId(). ",
6298
- $this->defaultAttributeSetId,
6299
- 'simple',
6300
- a.product_sku,
6301
- NOW(),
6302
- 0,
6303
- a.store_product_id,
6304
- a.sinch_product_id
6305
- FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')." a
6306
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
6307
- ON a.store_product_id=pm.store_product_id
6308
- AND a.sinch_product_id=pm.sinch_product_id
6309
- WHERE pm.entity_id IS NULL
6310
- )
6311
- ON DUPLICATE KEY UPDATE
6312
- sku= a.product_sku,
6313
- store_product_id=a.store_product_id,
6314
- sinch_product_id=a.sinch_product_id
6315
- ");
6316
- // store_product_id=a.store_product_id,
6317
- // sinch_product_id=a.sinch_product_id
6318
 
6319
  //Set enabled
6320
- $result = $this->db_do("DELETE cpei
6321
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." cpei
6322
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6323
- ON cpei.entity_id=cpe.entity_id
6324
- WHERE cpe.entity_id IS NULL");
 
6325
 
6326
  $result = $this->db_do("
6327
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6328
- entity_type_id,
6329
- attribute_id,
6330
- store_id,
6331
- entity_id,
6332
- value
6333
- )(
6334
- SELECT
6335
- " . $this->_getProductEntityTypeId(). ",
6336
- ". $this->_getProductAttributeId('status').",
6337
- w.website,
6338
- a.entity_id,
6339
- 1
6340
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6341
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6342
- ON a.store_product_id=w.store_product_id
6343
- )
6344
- ON DUPLICATE KEY UPDATE
6345
- value=1
6346
- ");
6347
  // set status = 1 for all stores
6348
  $result = $this->db_do("
6349
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6350
- entity_type_id,
6351
- attribute_id,
6352
- store_id,
6353
- entity_id,
6354
- value
6355
- )(SELECT
6356
- " . $this->_getProductEntityTypeId(). ",
6357
- ".$this->_getProductAttributeId('status').",
6358
- 0,
6359
- a.entity_id,
6360
- 1
6361
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6362
- )
6363
- ON DUPLICATE KEY UPDATE
6364
- value=1
6365
- ");
6366
 
6367
  //Unifying products with categories.
6368
- $result = $this->db_do("DELETE ccp
6369
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6370
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6371
- ON ccp.product_id=cpe.entity_id
6372
- WHERE cpe.entity_id IS NULL");
 
6373
 
6374
- echo("\n\n\nUPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6375
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6376
- ON ccp.category_id=cce.entity_id
6377
- SET ccp.category_id=".$this->_root_cat."
6378
- WHERE cce.entity_id IS NULL");
6379
- $result = $this->db_do("UPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6380
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6381
- ON ccp.category_id=cce.entity_id
6382
- SET ccp.category_id=".$this->_root_cat."
6383
- WHERE cce.entity_id IS NULL");
6384
- echo("\ndone\n");
6385
 
 
6386
 
6387
- echo("\n\n\nDELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6388
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6389
- ON ccp.category_id=cce.entity_id
6390
- WHERE cce.entity_id IS NULL");
6391
- $result = $this->db_do("DELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6392
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
6393
- ON ccp.category_id=cce.entity_id
6394
- WHERE cce.entity_id IS NULL");
6395
- echo("\ndone\n");
6396
 
 
6397
 
6398
- $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp");
6399
- // TEMPORARY
6400
- $this->db_do("
6401
- CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp` (
6402
- `category_id` int(10) unsigned NOT NULL default '0',
6403
- `product_id` int(10) unsigned NOT NULL default '0',
6404
- `store_product_id` int(10) NOT NULL default '0',
6405
- `store_category_id` int(10) NOT NULL default '0',
6406
- `new_category_id` int(10) NOT NULL default '0',
6407
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
6408
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
6409
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
6410
- KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
6411
- )
6412
 
6413
- ");
6414
 
 
 
 
 
6415
  $result = $this->db_do("
6416
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp (
6417
- category_id,
6418
- product_id,
6419
- store_product_id
6420
- )(SELECT
6421
- ccp.category_id,
6422
- ccp.product_id,
6423
- cpe.store_product_id
6424
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6425
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6426
- ON ccp.product_id=cpe.entity_id
6427
- WHERE store_product_id is not null
6428
- )
6429
- ");
6430
 
6431
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6432
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6433
- ON ccpfd.store_product_id=p.store_product_id
6434
- SET ccpfd.store_category_id=p.store_category_id
6435
- WHERE ccpfd.store_product_id!=0
6436
- ");
6437
 
6438
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6439
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6440
- ON ccpfd.store_category_id=scm.store_category_id
6441
- SET ccpfd.new_category_id=scm.shop_entity_id
6442
- WHERE ccpfd.store_category_id!=0
6443
- ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6444
 
6445
- $result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp
6446
- WHERE category_id=new_category_id");
6447
 
6448
  $result = $this->db_do("
6449
- DELETE ccp
6450
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
6451
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
6452
- ON ccp.product_id=ccpfd.product_id
6453
- AND ccp.category_id=ccpfd.category_id
6454
- ");
 
 
 
 
 
 
 
6455
 
6456
- $result = $this->db_do("
6457
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." (
6458
- category_id,
6459
- product_id
6460
- )(SELECT
6461
- scm.shop_entity_id,
6462
- cpe.entity_id
6463
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6464
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6465
- ON cpe.store_product_id=p.store_product_id
6466
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6467
- ON p.store_category_id=scm.store_category_id
6468
- )
6469
- ON DUPLICATE KEY UPDATE
6470
- product_id = cpe.entity_id
6471
- ");
6472
 
 
6473
 
6474
- //add multi categories;
6475
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6476
 
6477
 
 
6478
 
 
6479
  $result = $this->db_do("
6480
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."
6481
- (category_id, product_id)
6482
- (SELECT
6483
- scm.shop_entity_id,
6484
- cpe.entity_id
6485
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6486
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
6487
- ON cpe.store_product_id = p.store_product_id
6488
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_categories')." spc
6489
- ON p.store_product_id=spc.store_product_id
6490
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
6491
- ON spc.store_category_id = scm.store_category_id
6492
- )
6493
- ON DUPLICATE KEY UPDATE
6494
- product_id = cpe.entity_id
6495
- ");
6496
-
6497
 
6498
 
 
6499
 
6500
- //Indexing products and categories in the shop
6501
- $result = $this->db_do("DELETE ccpi
6502
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." ccpi
6503
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6504
- ON ccpi.product_id=cpe.entity_id
6505
- WHERE cpe.entity_id IS NULL");
6506
 
6507
  $result = $this->db_do("
6508
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
6509
- category_id,
6510
- product_id,
6511
- position,
6512
- is_parent,
6513
- store_id,
6514
- visibility
6515
- )(
6516
- SELECT
6517
- a.category_id,
6518
- a.product_id,
6519
- a.position,
6520
- 1,
6521
- b.store_id,
6522
- 4
6523
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
6524
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
6525
- )
6526
- ON DUPLICATE KEY UPDATE
6527
- visibility = 4
6528
- ");
6529
-
6530
  $result = $this->db_do("
6531
- INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
6532
- category_id,
6533
- product_id,
6534
- position,
6535
- is_parent,
6536
- store_id,
6537
- visibility
6538
- )(
6539
- SELECT
6540
- ".$this->_root_cat.",
6541
- a.product_id,
6542
- a.position,
6543
- 1,
6544
- b.store_id,
6545
- 4
6546
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
6547
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
6548
- )
6549
- ON DUPLICATE KEY UPDATE
6550
- visibility = 4
6551
- ");
6552
 
6553
  //Set product name for specific web sites
6554
- $result = $this->db_do("DELETE cpev
6555
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." cpev
6556
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6557
- ON cpev.entity_id=cpe.entity_id
6558
- WHERE cpe.entity_id IS NULL");
6559
  $result = $this->db_do("
6560
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6561
- entity_type_id,
6562
- attribute_id,
6563
- store_id,
6564
- entity_id,
6565
- value
6566
- )(SELECT
6567
- " . $this->_getProductEntityTypeId(). ",
6568
- " . $this->_getProductAttributeId('name'). ",
6569
- w.website,
6570
- a.entity_id,
6571
- b.product_name
6572
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6573
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6574
- ON a.store_product_id= b.store_product_id
6575
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6576
- ON a.store_product_id=w.store_product_id
6577
- )
6578
- ON DUPLICATE KEY UPDATE
6579
- value = b.product_name
6580
- ");
 
 
 
 
 
6581
 
6582
  // product name for all web sites
6583
  $result = $this->db_do("
6584
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6585
- entity_type_id,
6586
- attribute_id,
6587
- store_id,
6588
- entity_id,
6589
- value
6590
- )(
6591
- SELECT
6592
- " . $this->_getProductEntityTypeId(). ",
6593
- " . $this->_getProductAttributeId('name'). ",
6594
- 0,
6595
- a.entity_id,
6596
- b.product_name
6597
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6598
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6599
- ON a.store_product_id = b.store_product_id
6600
- )
6601
- ON DUPLICATE KEY UPDATE
6602
- value = b.product_name
6603
- ");
6604
 
6605
  $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
6606
  $this->addDescriptions();
6607
  $this->cleanProductDistributors();
6608
- if($this->product_file_format == "NEW"){
 
 
 
6609
  $this->addReviews();
6610
  $this->addWeight();
6611
  $this->addSearchCache();
6612
  $this->addPdfUrl();
6613
  $this->addShortDescriptions();
6614
  $this->addProductDistributors();
 
 
 
6615
  }
6616
  $this->addEAN();
6617
  $this->addSpecification();
6618
- $this->addManufacturers();
6619
-
6620
- //Enabling product index.
6621
- $result = $this->db_do("DELETE cpei
6622
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." cpei
6623
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6624
- ON cpei.product_id=cpe.entity_id
6625
- WHERE cpe.entity_id IS NULL");
6626
-
6627
- $result = $this->db_do("
6628
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
6629
- product_id,
6630
- store_id,
6631
- visibility
6632
- )(
6633
- SELECT
6634
- a.entity_id,
6635
- w.website,
6636
- 4
6637
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6638
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6639
- ON a.store_product_id=w.store_product_id
6640
- )
6641
- ON DUPLICATE KEY UPDATE
6642
- visibility = 4
6643
- ");
6644
- $result = $this->db_do("
6645
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
6646
- product_id,
6647
- store_id,
6648
- visibility
6649
- )(
6650
- SELECT
6651
- a.entity_id,
6652
- 0,
6653
- 4
6654
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6655
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6656
- ON a.store_product_id=w.store_product_id
6657
- )
6658
- ON DUPLICATE KEY UPDATE
6659
- visibility = 4
6660
- ");
6661
-
6662
-
6663
- $result = $this->db_do("
6664
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6665
- entity_type_id,
6666
- attribute_id,
6667
- store_id,
6668
- entity_id,
6669
- value
6670
- )(
6671
- SELECT
6672
- " . $this->_getProductEntityTypeId(). ",
6673
- " . $this->_getProductAttributeId('visibility'). ",
6674
- w.website,
6675
- a.entity_id,
6676
- 4
6677
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6678
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6679
- ON a.store_product_id=w.store_product_id
6680
- )
6681
- ON DUPLICATE KEY UPDATE
6682
- value = 4
6683
- ");
6684
-
6685
- $result = $this->db_do("
6686
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6687
- entity_type_id,
6688
- attribute_id,
6689
- store_id,
6690
- entity_id,
6691
- value
6692
- )(
6693
- SELECT
6694
- " . $this->_getProductEntityTypeId(). ",
6695
- " . $this->_getProductAttributeId('visibility'). ",
6696
- 0,
6697
- a.entity_id,
6698
- 4
6699
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6700
- )
6701
- ON DUPLICATE KEY UPDATE
6702
- value = 4
6703
- ");
6704
-
6705
- $result = $this->db_do("DELETE cpw
6706
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." cpw
6707
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6708
- ON cpw.product_id=cpe.entity_id
6709
- WHERE cpe.entity_id IS NULL");
6710
-
6711
- $result = $this->db_do("
6712
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." (
6713
- product_id,
6714
- website_id
6715
- )(
6716
- SELECT a.entity_id, w.website_id
6717
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6718
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6719
- ON a.store_product_id=w.store_product_id
6720
- )
6721
- ON DUPLICATE KEY UPDATE
6722
- product_id=a.entity_id,
6723
- website_id=w.website_id
6724
- ");
6725
-
6726
- // temporary disabled mart@bintime.com
6727
- //$result = $this->db_do("
6728
- // UPDATE catalog_category_entity_int a
6729
- // SET a.value = 0
6730
- // WHERE a.attribute_id = 32
6731
- //");
6732
-
6733
-
6734
- //Adding tax class "Taxable Goods"
6735
- $result = $this->db_do("
6736
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6737
- entity_type_id,
6738
- attribute_id,
6739
- store_id,
6740
- entity_id,
6741
- value
6742
- )(
6743
- SELECT
6744
- " . $this->_getProductEntityTypeId(). ",
6745
- " . $this->_getProductAttributeId('tax_class_id'). ",
6746
- w.website,
6747
- a.entity_id,
6748
- 2
6749
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6750
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6751
- ON a.store_product_id=w.store_product_id
6752
- )
6753
- ON DUPLICATE KEY UPDATE
6754
- value = 2
6755
- ");
6756
- $result = $this->db_do("
6757
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
6758
- entity_type_id,
6759
- attribute_id,
6760
- store_id,
6761
- entity_id,
6762
- value
6763
- )(
6764
- SELECT
6765
- " . $this->_getProductEntityTypeId(). ",
6766
- " . $this->_getProductAttributeId('tax_class_id'). ",
6767
- 0,
6768
- a.entity_id,
6769
- 2
6770
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6771
- )
6772
- ON DUPLICATE KEY UPDATE
6773
- value = 2
6774
- ");
6775
-
6776
- // Load url Image
6777
- $result = $this->db_do("
6778
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6779
- entity_type_id,
6780
- attribute_id,
6781
- store_id,
6782
- entity_id,
6783
- value
6784
- )(
6785
- SELECT
6786
- " . $this->_getProductEntityTypeId(). ",
6787
- " . $this->_getProductAttributeId('image'). ",
6788
- w.store_id,
6789
- a.entity_id,
6790
- b.main_image_url
6791
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6792
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6793
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6794
- ON a.store_product_id = b.store_product_id
6795
- )
6796
- ON DUPLICATE KEY UPDATE
6797
- value = b.main_image_url
6798
- ");
6799
-
6800
 
6801
- // image for specific web sites
6802
- $result = $this->db_do("
6803
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6804
- entity_type_id,
6805
- attribute_id,
6806
- store_id,
6807
- entity_id,
6808
- value
6809
- )(
6810
- SELECT
6811
- " . $this->_getProductEntityTypeId(). ",
6812
- " . $this->_getProductAttributeId('image'). ",
6813
- 0,
6814
- a.entity_id,
6815
- b.main_image_url
6816
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6817
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6818
- ON a.store_product_id = b.store_product_id
6819
- )
6820
- ON DUPLICATE KEY UPDATE
6821
- value = b.main_image_url
6822
- ");
6823
 
 
6824
 
6825
- // small_image for specific web sites
6826
  $result = $this->db_do("
6827
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6828
- entity_type_id,
6829
- attribute_id,
6830
- store_id,
6831
- entity_id,
6832
- value
6833
- )(
6834
- SELECT
6835
- " . $this->_getProductEntityTypeId(). ",
6836
- " . $this->_getProductAttributeId('small_image'). ",
6837
- w.store_id,
6838
- a.entity_id,
6839
- b.medium_image_url
6840
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6841
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6842
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6843
- ON a.store_product_id = b.store_product_id
6844
- )
6845
- ON DUPLICATE KEY UPDATE
6846
- value = b.medium_image_url
6847
- ");
6848
 
6849
 
6850
- // small_image for all web sites
6851
- $result = $this->db_do("
6852
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6853
- entity_type_id,
6854
- attribute_id,
6855
- store_id,
6856
- entity_id,
6857
- value
6858
- )(
6859
- SELECT
6860
- " . $this->_getProductEntityTypeId(). ",
6861
- " . $this->_getProductAttributeId('small_image'). ",
6862
- 0,
6863
- a.entity_id,
6864
- b.medium_image_url
6865
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6866
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6867
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6868
- ON a.store_product_id = b.store_product_id
6869
- )
6870
- ON DUPLICATE KEY UPDATE
6871
- value = b.medium_image_url
6872
- ");
6873
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6874
 
6875
- // thumbnail for specific web site
6876
  $result = $this->db_do("
6877
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6878
- entity_type_id,
6879
- attribute_id,
6880
- store_id,
6881
- entity_id,
6882
- value
6883
- )(
6884
- SELECT
6885
- " . $this->_getProductEntityTypeId(). ",
6886
- " . $this->_getProductAttributeId('thumbnail'). ",
6887
- w.store_id,
6888
- a.entity_id,
6889
- b.thumb_image_url
6890
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6891
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6892
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6893
- ON a.store_product_id = b.store_product_id
6894
- )
6895
- ON DUPLICATE KEY UPDATE
6896
- value = b.thumb_image_url
6897
- ");
6898
 
6899
 
6900
- // thumbnail for all web sites
6901
- $result = $this->db_do("
6902
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
6903
- entity_type_id,
6904
- attribute_id,
6905
- store_id,
6906
- entity_id,
6907
- value
6908
- )(
6909
- SELECT
6910
- " . $this->_getProductEntityTypeId(). ",
6911
- " . $this->_getProductAttributeId('thumbnail'). ",
6912
- 0,
6913
- a.entity_id,
6914
- b.thumb_image_url
6915
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6916
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
6917
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
6918
- ON a.store_product_id = b.store_product_id
6919
- )
6920
- ON DUPLICATE KEY UPDATE
6921
- value = b.thumb_image_url
6922
 
6923
- ");
6924
 
6925
- /*STP DELETE
6926
- //Refresh fulltext search
6927
- $result = $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp");
6928
- $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS
6929
- ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp
6930
- LIKE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext'));
6931
 
6932
  $result = $this->db_do("
6933
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
6934
- product_id,
6935
- store_id,
6936
- data_index
6937
- )(
6938
- SELECT
6939
- a.entity_id,
6940
- w.website,
6941
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6942
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6943
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6944
- ON a.store_product_id=w.store_product_id
6945
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
6946
- ON a.entity_id = b.product_id
6947
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
6948
- ON b.category_id = c.entity_id
6949
- AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
6950
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
6951
- ON a.entity_id = e.entity_id
6952
- AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
6953
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." j
6954
- ON a.entity_id = j.product_id
6955
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
6956
- ON a.store_product_id = f.store_product_id
6957
- )
6958
- ON DUPLICATE KEY UPDATE
6959
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6960
- ");
6961
 
6962
  $result = $this->db_do("
6963
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
6964
- product_id,
6965
- store_id,
6966
- data_index
6967
- )(
6968
- SELECT
6969
- a.entity_id,
6970
- w.website,
6971
- CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6972
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
6973
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
6974
- ON a.store_product_id=w.store_product_id
6975
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
6976
- ON a.entity_id = b.product_id
6977
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
6978
- ON b.category_id = c.entity_id
6979
- AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
6980
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
6981
- ON a.entity_id = e.entity_id
6982
- AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
6983
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
6984
- ON a.store_product_id = f.store_product_id
6985
- )
6986
- ON DUPLICATE KEY UPDATE
6987
- data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
6988
- ");
6989
 
6990
- $result = $this->db_do("DELETE cf
6991
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." cf
6992
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
6993
- ON cf.product_id=cpe.entity_id
6994
- WHERE cpe.entity_id is null");
6995
 
6996
  $result = $this->db_do("
6997
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." (
6998
- product_id,
6999
- store_id,
7000
- data_index
7001
- )(
7002
- SELECT
7003
- a.product_id,
7004
- a.store_id,
7005
- a.data_index
7006
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp a
7007
- WHERE product_id = a.product_id
7008
- )
7009
- ON DUPLICATE KEY UPDATE
7010
- data_index = a.data_index
7011
- ");
7012
 
7013
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_query')." SET is_processed = 0");
7014
- //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
7015
- //TODO add something else
7016
- STP DELETE*/
7017
- $this->addRelatedProducts();
7018
- }
7019
 
7020
- #################################################################################################
7021
- function addReviews(){
7022
- // product reviews for all web sites
7023
- $result = $this->db_do("
7024
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7025
- entity_type_id,
7026
- attribute_id,
7027
- store_id,
7028
- entity_id,
7029
- value
7030
- )(
7031
- SELECT
7032
- " . $this->_getProductEntityTypeId(). ",
7033
- " . $this->_getProductAttributeId('reviews'). ",
7034
- w.website,
7035
- a.entity_id,
7036
- b.Reviews
7037
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7038
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7039
- ON a.store_product_id = b.store_product_id
7040
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7041
- ON a.store_product_id=w.store_product_id
7042
- )
7043
- ON DUPLICATE KEY UPDATE
7044
- value = b.Reviews
7045
- ");
7046
 
7047
- // product Reviews for all web sites
7048
  $result = $this->db_do("
7049
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7050
- entity_type_id,
7051
- attribute_id,
7052
- store_id,
7053
- entity_id,
7054
- value
7055
- )(
7056
- SELECT
7057
- " . $this->_getProductEntityTypeId(). ",
7058
- " . $this->_getProductAttributeId('reviews'). ",
7059
- 0,
7060
- a.entity_id,
7061
- b.Reviews
7062
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7063
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7064
- ON a.store_product_id = b.store_product_id
7065
- )
7066
- ON DUPLICATE KEY UPDATE
7067
- value = b.Reviews
7068
- ");
7069
 
7070
 
7071
- }
7072
 
7073
 
7074
- #################################################################################################
7075
- function addDescriptions(){
7076
- // product description for all web sites
 
 
 
 
 
 
 
 
7077
  $result = $this->db_do("
7078
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7079
- entity_type_id,
7080
- attribute_id,
7081
- store_id,
7082
- entity_id,
7083
- value
7084
- )(
7085
- SELECT
7086
- " . $this->_getProductEntityTypeId(). ",
7087
- " . $this->_getProductAttributeId('description'). ",
7088
- w.website,
7089
- a.entity_id,
7090
- b.description
7091
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7092
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7093
- ON a.store_product_id = b.store_product_id
7094
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7095
- ON a.store_product_id=w.store_product_id
7096
- )
7097
- ON DUPLICATE KEY UPDATE
7098
- value = b.description
7099
- ");
7100
 
7101
- // product description for all web sites
7102
  $result = $this->db_do("
7103
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7104
- entity_type_id,
7105
- attribute_id,
7106
- store_id,
7107
- entity_id,
7108
- value
7109
- )(
7110
- SELECT
7111
- " . $this->_getProductEntityTypeId(). ",
7112
- " . $this->_getProductAttributeId('description'). ",
7113
- 0,
7114
- a.entity_id,
7115
- b.description
7116
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7117
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7118
- ON a.store_product_id = b.store_product_id
7119
- )
7120
- ON DUPLICATE KEY UPDATE
7121
- value = b.description
7122
- ");
7123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7124
 
7125
- }
7126
- ############################### ##################################################################
7127
- function addSearchCache(){
7128
- // product search_cache for all web sites
7129
  $result = $this->db_do("
7130
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7131
- entity_type_id,
7132
- attribute_id,
7133
- store_id,
7134
- entity_id,
7135
- value
7136
- )(
7137
- SELECT
7138
- " . $this->_getProductEntityTypeId(). ",
7139
- " . $this->_getProductAttributeId('sinch_search_cache'). ",
7140
- w.website,
7141
- a.entity_id,
7142
- b.search_cache
7143
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7144
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7145
- ON a.store_product_id = b.store_product_id
7146
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7147
- ON a.store_product_id=w.store_product_id
7148
- )
7149
- ON DUPLICATE KEY UPDATE
7150
- value = b.search_cache
7151
- ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7152
 
7153
- // product search_cache for all web sites
7154
  $result = $this->db_do("
7155
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7156
- entity_type_id,
7157
- attribute_id,
7158
- store_id,
7159
- entity_id,
7160
- value
7161
- )(
7162
- SELECT
7163
- " . $this->_getProductEntityTypeId(). ",
7164
- " . $this->_getProductAttributeId('sinch_search_cache'). ",
7165
- 0,
7166
- a.entity_id,
7167
- b.search_cache
7168
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7169
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7170
- ON a.store_product_id = b.store_product_id
7171
- )
7172
- ON DUPLICATE KEY UPDATE
7173
- value = b.search_cache
7174
- ");
7175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7176
 
7177
- }
7178
 
7179
- #################################################################################################
7180
- function addPdfUrl(){
7181
- // product PDF Url for all web sites
7182
  $result = $this->db_do("
7183
- UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
7184
- SET pdf_url = CONCAT(
7185
- '<a href=\"#\" onclick=\"popWin(',
7186
- \"'\",
7187
- pdf_url,
7188
- \"'\",
7189
- \", 'pdf', 'width=500,height=800,left=50,top=50, location=no,status=yes,scrollbars=yes,resizable=yes'); return false;\",
7190
- '\"',
7191
- '>',
7192
- pdf_url,
7193
- '</a>')
7194
- WHERE pdf_url != ''
7195
- ");
7196
- //<a title="" onclick="popWin('http://images.icecat.biz/img/gallery/14532248_4539.jpg', 'gallery', 'width=500,height=500,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" href="#">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7197
  $result = $this->db_do("
7198
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7199
- entity_type_id,
7200
- attribute_id,
7201
- store_id,
7202
- entity_id,
7203
- value
7204
- )(
7205
- SELECT
7206
- " . $this->_getProductEntityTypeId(). ",
7207
- " . $this->_getProductAttributeId('pdf_url'). ",
7208
- w.website,
7209
- a.entity_id,
7210
- b.pdf_url
7211
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7212
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7213
- ON a.store_product_id = b.store_product_id
7214
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7215
- ON a.store_product_id=w.store_product_id
7216
- )
7217
- ON DUPLICATE KEY UPDATE
7218
- value = b.pdf_url
7219
- ");
7220
- // product PDF url for all web sites
 
 
7221
  $result = $this->db_do("
7222
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7223
- entity_type_id,
7224
- attribute_id,
7225
- store_id,
7226
- entity_id,
7227
- value
7228
- )(
7229
- SELECT
7230
- " . $this->_getProductEntityTypeId(). ",
7231
- " . $this->_getProductAttributeId('pdf_url'). ",
7232
- 0,
7233
- a.entity_id,
7234
- b.pdf_url
7235
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7236
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7237
- ON a.store_product_id = b.store_product_id
7238
- )
7239
- ON DUPLICATE KEY UPDATE
7240
- value = b.pdf_url
7241
- ");
 
 
 
 
 
 
7242
 
 
 
7243
  }
7244
 
7245
  #################################################################################################
7246
- function cleanProductDistributors(){
7247
- for($i=1; $i<=5; $i++){
7248
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
7249
- SET value = ''
7250
- WHERE entity_type_id=".$this->_getProductEntityTypeId()." AND attribute_id=".$this->_getProductAttributeId('supplier_'.$i));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7251
  }
 
 
7252
  }
7253
  #################################################################################################
7254
- function addProductDistributors(){
7255
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary'));
7256
- $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')."
7257
- LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7258
- $this->db_do("INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." SELECT * FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7259
- for($i=1; $i<=5; $i++){
7260
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier'));
7261
- $this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')."
7262
- LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
7263
- $this->db_do("INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." SELECT * FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." GROUP BY store_product_id");
7264
-
7265
- // product Distributors for all web sites
7266
- $result = $this->db_do("
7267
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7268
- entity_type_id,
7269
- attribute_id,
7270
- store_id,
7271
- entity_id,
7272
- value
7273
- )(
7274
- SELECT
7275
- " . $this->_getProductEntityTypeId(). ",
7276
- " . $this->_getProductAttributeId('supplier_'.$i). ",
7277
- w.website,
7278
- a.entity_id,
7279
- d.distributor_name
7280
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7281
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." b
7282
- ON a.store_product_id = b.store_product_id
7283
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors')." d
7284
- ON b.distributor_id = d.distributor_id
7285
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7286
- ON a.store_product_id=w.store_product_id
7287
- )
7288
- ON DUPLICATE KEY UPDATE
7289
- value = d.distributor_name
7290
- ");
7291
- // product Distributors for all web sites
7292
- $result = $this->db_do("
7293
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7294
- entity_type_id,
7295
- attribute_id,
7296
- store_id,
7297
- entity_id,
7298
- value
7299
- )(
7300
- SELECT
7301
- " . $this->_getProductEntityTypeId(). ",
7302
- " . $this->_getProductAttributeId('supplier_'.$i). ",
7303
- 0,
7304
- a.entity_id,
7305
- d.distributor_name
7306
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7307
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." b
7308
- ON a.store_product_id = b.store_product_id
7309
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors')." d
7310
- ON b.distributor_id = d.distributor_id
7311
- )
7312
- ON DUPLICATE KEY UPDATE
7313
- value = d.distributor_name
7314
- ");
7315
 
7316
- $this->db_do("DELETE sdsapt FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary')." sdsapt JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier')." sdsapts ON sdsapt.store_product_id = sdsapts.store_product_id AND sdsapt.distributor_id = sdsapts.distributor_id");
 
7317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7318
 
 
 
 
7319
  }
7320
-
7321
  }
7322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7323
 
 
 
 
 
 
 
7324
 
7325
  #################################################################################################
7326
- function addShortDescriptions(){
7327
- // product short description for all web sites
7328
- $result = $this->db_do("
7329
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7330
- entity_type_id,
7331
- attribute_id,
7332
- store_id,
7333
- entity_id,
7334
- value
7335
- )(
7336
- SELECT
7337
- " . $this->_getProductEntityTypeId(). ",
7338
- " . $this->_getProductAttributeId('short_description'). ",
7339
- w.website,
7340
- a.entity_id,
7341
- b.product_short_description
7342
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7343
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7344
- ON a.store_product_id = b.store_product_id
7345
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7346
- ON a.store_product_id=w.store_product_id
7347
- )
7348
- ON DUPLICATE KEY UPDATE
7349
- value = b.product_short_description
7350
- ");
7351
- // product short description for all web sites
7352
  $result = $this->db_do("
7353
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7354
- entity_type_id,
7355
- attribute_id,
7356
- store_id,
7357
- entity_id,
7358
- value
7359
  )(
7360
  SELECT
7361
- " . $this->_getProductEntityTypeId(). ",
7362
- " . $this->_getProductAttributeId('short_description'). ",
7363
- 0,
7364
  a.entity_id,
7365
- b.product_short_description
7366
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7367
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7368
- ON a.store_product_id = b.store_product_id
 
 
 
7369
  )
7370
  ON DUPLICATE KEY UPDATE
7371
- value = b.product_short_description
7372
- ");
7373
-
7374
- }
7375
-
7376
- #################################################################################################
7377
- function addEAN(){
7378
- //gather EAN codes for each product
7379
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('EANs_temp'));
7380
- $this->db_do("
7381
- CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
7382
- sinch_product_id int(11),
7383
- store_product_id int(11),
7384
- EANs text,
7385
- KEY `sinch_product_id` (`sinch_product_id`),
7386
- KEY `store_product_id` (`store_product_id`)
7387
- )
7388
- ");
7389
- $this->db_do("
7390
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
7391
- sinch_product_id,
7392
- EANs
7393
- )(SELECT
7394
- sec.product_id,
7395
- GROUP_CONCAT(DISTINCT ean_code ORDER BY ean_code DESC SEPARATOR ', ') AS eans
7396
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
7397
- GROUP BY sec.product_id
7398
- )
7399
- ");
7400
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7401
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7402
- ON e.sinch_product_id=p.sinch_product_id
7403
- SET e.store_product_id=p.store_product_id");
7404
- // product EANs for all web sites
7405
- $result = $this->db_do("
7406
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7407
- entity_type_id,
7408
- attribute_id,
7409
- store_id,
7410
- entity_id,
7411
- value
7412
  )(
7413
  SELECT
7414
- " . $this->_getProductEntityTypeId(). ",
7415
- " . $this->_getProductAttributeId('ean'). ",
7416
- w.website,
7417
- a.entity_id,
7418
- e.EANs
7419
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7420
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7421
- ON a.store_product_id = e.store_product_id
7422
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7423
- ON a.store_product_id=w.store_product_id
7424
  )
7425
  ON DUPLICATE KEY UPDATE
7426
- value = e.EANs
7427
- ");
 
 
 
 
 
 
 
 
 
7428
 
7429
- // product EANs for all web sites
7430
  $result = $this->db_do("
7431
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
7432
  entity_type_id,
7433
  attribute_id,
7434
  store_id,
@@ -7436,28 +8321,23 @@ STP DELETE*/
7436
  value
7437
  )(
7438
  SELECT
7439
- " . $this->_getProductEntityTypeId(). ",
7440
- " . $this->_getProductAttributeId('ean'). ",
7441
- 0,
7442
  a.entity_id,
7443
- e.EANs
7444
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7445
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
7446
- ON a.store_product_id = e.store_product_id
7447
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7448
  ON a.store_product_id=w.store_product_id
7449
  )
7450
  ON DUPLICATE KEY UPDATE
7451
- value = e.EANs
7452
  ");
7453
 
7454
- }
7455
-
7456
- ################################################################################################
7457
- function addSpecification(){
7458
- // product specification for all web sites
7459
  $result = $this->db_do("
7460
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7461
  entity_type_id,
7462
  attribute_id,
7463
  store_id,
@@ -7465,23 +8345,22 @@ STP DELETE*/
7465
  value
7466
  )(
7467
  SELECT
7468
- " . $this->_getProductEntityTypeId(). ",
7469
- " . $this->_getProductAttributeId('specification'). ",
7470
- w.website,
7471
  a.entity_id,
7472
- b.specifications
7473
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7474
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7475
- ON a.store_product_id = b.store_product_id
7476
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7477
- ON a.store_product_id=w.store_product_id
7478
  )
7479
  ON DUPLICATE KEY UPDATE
7480
- value = b.specifications
7481
  ");
7482
- // product specification for all web sites
 
7483
  $result = $this->db_do("
7484
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
7485
  entity_type_id,
7486
  attribute_id,
7487
  store_id,
@@ -7489,25 +8368,23 @@ STP DELETE*/
7489
  value
7490
  )(
7491
  SELECT
7492
- " . $this->_getProductEntityTypeId(). ",
7493
- " . $this->_getProductAttributeId('specification'). ",
7494
- 0,
7495
  a.entity_id,
7496
- b.specifications
7497
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7498
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7499
- ON a.store_product_id = b.store_product_id
 
 
7500
  )
7501
  ON DUPLICATE KEY UPDATE
7502
- value = b.specifications
7503
  ");
7504
 
7505
-
7506
- }
7507
-
7508
- private function addManufacturer_attribute(){
7509
  $result = $this->db_do("
7510
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
7511
  entity_type_id,
7512
  attribute_id,
7513
  store_id,
@@ -7515,356 +8392,431 @@ STP DELETE*/
7515
  value
7516
  )(
7517
  SELECT
7518
- " . $this->_getProductEntityTypeId(). ",
7519
- " . $this->_getProductAttributeId('manufacturer'). ",
7520
  0,
7521
  a.entity_id,
7522
- pm.manufacturer_option_id
7523
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7524
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
7525
- ON a.entity_id = pm.entity_id
7526
  )
7527
  ON DUPLICATE KEY UPDATE
7528
- value = pm.manufacturer_option_id
7529
  ");
7530
 
 
 
 
 
 
 
 
 
 
 
7531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7532
  }
7533
 
7534
  #################################################################################################
7535
- function addManufacturers($delete_eav=null){
7536
- // this cleanup is not needed due to foreign keys
7537
- if(!$delete_eav){
7538
- $result = $this->db_do("
7539
- DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')."
7540
- WHERE attribute_id = ".$this->_getProductAttributeId('manufacturer')//." AND store_id = ".$websiteId
7541
- );
 
 
 
 
 
 
 
 
 
 
7542
  }
7543
- $this->addManufacturer_attribute();
7544
- // todo: doesn't seems to work properly, should be inserted per visibility
7545
- // done, test now
7546
 
7547
- $result = $this->db_do("
7548
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
7549
- entity_id,
7550
- attribute_id,
7551
- store_id,
7552
- value
7553
- )(
7554
- SELECT
7555
- a.entity_id,
7556
- " . $this->_getProductAttributeId('manufacturer'). ",
7557
- w.website,
7558
- mn.shop_option_id
7559
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7560
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7561
- ON a.store_product_id = b.store_product_id
7562
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7563
- ON a.store_product_id=w.store_product_id
7564
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
7565
- ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
7566
- WHERE mn.shop_option_id IS NOT NULL
7567
- )
7568
- ON DUPLICATE KEY UPDATE
7569
- value = mn.shop_option_id
7570
- ");
7571
 
7572
- $result = $this->db_do("
7573
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
7574
- entity_id,
7575
- attribute_id,
7576
- store_id,
7577
- value
7578
- )(
7579
- SELECT
7580
- a.entity_id,
7581
- " . $this->_getProductAttributeId('manufacturer'). ",
7582
- 0,
7583
- mn.shop_option_id
7584
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7585
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7586
- ON a.store_product_id = b.store_product_id
7587
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7588
- ON a.store_product_id=w.store_product_id
7589
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
7590
- ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
7591
- WHERE mn.shop_option_id IS NOT NULL
7592
- )
7593
- ON DUPLICATE KEY UPDATE
7594
- value = mn.shop_option_id
7595
- ");
7596
 
 
7597
 
 
 
 
 
7598
  }
7599
 
7600
  #################################################################################################
7601
- function addRelatedProducts(){
7602
 
7603
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
7604
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7605
- ON rpt.sinch_product_id=p.sinch_product_id
7606
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7607
- ON p.store_product_id=cpe.store_product_id
7608
- SET rpt.store_product_id=p.store_product_id, rpt.entity_id=cpe.entity_id");
7609
 
7610
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
7611
- JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
7612
- ON rpt.related_sinch_product_id=p.sinch_product_id
7613
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7614
- ON p.store_product_id=cpe.store_product_id
7615
- SET rpt.store_related_product_id=p.store_product_id, rpt.related_entity_id=cpe.entity_id");
7616
 
7617
- $result = $this->db_do("SELECT
7618
- link_type_id,
7619
- code
7620
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_type')
7621
- );
7622
- $link_type=array();
7623
- while ($row = mysqli_fetch_array($result)) {
7624
- $link_type[$row['code']]=$row['link_type_id'];
 
7625
  }
 
7626
 
7627
- $result = $this->db_do("
7628
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." (
7629
- product_id,
7630
- linked_product_id,
7631
- link_type_id
7632
- )(
7633
- SELECT
7634
- entity_id,
7635
- related_entity_id,
7636
- ".$link_type['relation']."
7637
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')."
7638
- WHERE store_product_id IS NOT NULL
7639
- AND store_related_product_id IS NOT NULL
7640
- )
7641
- ON DUPLICATE KEY UPDATE
7642
- product_id = entity_id,
7643
- linked_product_id = related_entity_id
7644
- ");
7645
- $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7646
 
7647
- $this->db_do("CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp (
7648
- `value_id` int(11) default NULL,
7649
- `product_link_attribute_id` smallint(6) unsigned default NULL,
7650
- `link_id` int(11) unsigned default NULL,
7651
- `value` int(11) NOT NULL default '0',
7652
- KEY `FK_INT_PRODUCT_LINK_ATTRIBUTE` (`product_link_attribute_id`),
7653
- KEY `FK_INT_PRODUCT_LINK` (`link_id`)
7654
- )
7655
- ");
7656
 
7657
- $result = $this->db_do("
7658
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp(
7659
- product_link_attribute_id,
7660
- link_id,
7661
- value
7662
- )(
7663
- SELECT
7664
- 2,
7665
- cpl.link_id,
7666
- 0
7667
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." cpl
7668
- )
7669
- ");
7670
 
7671
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
7672
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." c
7673
- ON ct.link_id=c.link_id
7674
- SET ct.value_id=c.value_id
7675
- WHERE c.product_link_attribute_id=2
7676
- ");
7677
 
7678
- $result = $this->db_do("
7679
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." (
7680
- value_id,
7681
- product_link_attribute_id,
7682
- link_id,
7683
- value
7684
- )(
7685
- SELECT
7686
- value_id,
7687
- product_link_attribute_id,
7688
- link_id,
7689
- value
7690
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
7691
- )
7692
- ON DUPLICATE KEY UPDATE
7693
- link_id=ct.link_id
 
 
 
7694
 
7695
- ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7696
 
7697
- /* $q="select distinct store_product_id from stINch_related_products";
7698
- $quer=$this->db_do($q);
7699
- $prod = Mage::getModel('catalog/product');
7700
- while ($row = mysqli_fetch_assoc($quer)) {
7701
- $q1="select distinct store_related_product_id store_product_id from stINch_related_products where store_product_id=".$row['store_product_id'].;
7702
- $quer1=$this->db_do($q1);
7703
- $prod->load($row['store_product_id']);
7704
 
7705
- ###//get related product data (product id's and positions)
7706
- ###$relatedData = array();
7707
- ###foreach ($product->getRelatedLinkCollection() as $link) {
7708
- ### $relatedData[$link->getLinkedProductId()]['position'] = $link->getPosition();
7709
- ###}
7710
- ###//manipulate $relatedData array
7711
- ###// ...
7712
- ###//set and save related product data
7713
- ###$product->setRelatedLinkData($relatedData);
7714
- ###$product->save();
7715
- ###
7716
- $i=1;
7717
- while ($row1 = mysqli_fetch_assoc($quer1)) {
7718
- $param[$row1['store_related_product_id']]['position']=$i++;
7719
 
7720
- }
7721
- $prod->setRelatedLinkData($param);
7722
- //here ... some other product operations and in the end
7723
- $prod->save();
7724
 
7725
- }
7726
- */
7727
- }
7728
- #################################################################################################
7729
- function addWeight(){
7730
- // product weight for specific web site
7731
- $result = $this->db_do("
7732
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
7733
- entity_type_id,
7734
- attribute_id,
7735
- store_id,
7736
- entity_id,
7737
- value
7738
- )(
7739
- SELECT
7740
- " . $this->_getProductEntityTypeId(). ",
7741
- " . $this->_getProductAttributeId('weight'). ",
7742
- w.website,
7743
- a.entity_id,
7744
- b.Weight
7745
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7746
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7747
- ON a.store_product_id = b.store_product_id
7748
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
7749
- ON a.store_product_id=w.store_product_id
7750
- )
7751
- ON DUPLICATE KEY UPDATE
7752
- value = b.Weight
7753
- ");
7754
- // product weight for all web sites
7755
- $result = $this->db_do("
7756
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
7757
- entity_type_id,
7758
- attribute_id,
7759
- store_id,
7760
- entity_id,
7761
- value
7762
- )(
7763
- SELECT
7764
- " . $this->_getProductEntityTypeId(). ",
7765
- " . $this->_getProductAttributeId('weight'). ",
7766
- 0,
7767
- a.entity_id,
7768
- b.Weight
7769
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
7770
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
7771
- ON a.store_product_id = b.store_product_id
7772
- )
7773
- ON DUPLICATE KEY UPDATE
7774
- value = b.Weight
7775
 
 
 
 
 
 
 
 
7776
 
7777
- ");
7778
 
 
 
 
7779
 
 
 
 
 
 
7780
  }
7781
-
7782
  #################################################################################################
7783
- function _getProductsForCustomerGroupPrice(){
7784
- // TEMPORARY
7785
- $this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp'));
7786
- $this->db_do("
7787
- CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')."
7788
- (
7789
- `category_id` int(10) unsigned NOT NULL default '0',
7790
- `product_id` int(10) unsigned NOT NULL default '0',
7791
- `store_product_id` int(10) NOT NULL default '0',
7792
- `sku` varchar(64) DEFAULT NULL COMMENT 'SKU',
7793
- `manufacturer_id` int(10) NOT NULL default '0',
7794
- `price` decimal(15,4) DEFAULT NULL,
7795
- UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`product_id`,`category_id`),
7796
- KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
7797
- KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`)
7798
- )");
7799
 
7800
- $result = $this->db_do("
7801
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')."
7802
- (category_id, product_id, store_product_id, sku)
7803
- (SELECT
7804
- ccp.category_id,
7805
- ccp.product_id,
7806
- cpe.store_product_id,
7807
- cpe.sku
7808
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
7809
- JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
7810
- ON ccp.product_id = cpe.entity_id
7811
- WHERE cpe.store_product_id IS NOT NULL)");
7812
-
7813
- $result = $this->db_do("
7814
- UPDATE ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." pfcgpt
7815
- JOIN ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." cpei
7816
- ON pfcgpt.product_id = cpei.entity_id
7817
- AND cpei.entity_type_id = " . $this->_getProductEntityTypeId(). "
7818
- AND cpei.attribute_id = " . $this->_getProductAttributeId('manufacturer'). "
7819
- SET pfcgpt.manufacturer_id = cpei.value
7820
- ");
7821
 
7822
  $result = $this->db_do("
7823
- UPDATE ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." pfcgpt
7824
- JOIN ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." cped
7825
- ON pfcgpt.product_id = cped.entity_id
7826
- AND cped.entity_type_id = " . $this->_getProductEntityTypeId(). "
7827
- AND cped.attribute_id = " . $this->_getProductAttributeId('price'). "
7828
- SET pfcgpt.price = cped.value
7829
- ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7830
 
 
7831
 
 
 
7832
 
 
 
 
 
 
 
 
 
7833
  }
7834
-
7835
  #################################################################################################
7836
- function ApplyCustomerGroupPrice(){
7837
- if (!$this->check_table_exist('import_pricerules_standards')){
 
 
7838
  return;
7839
  }
7840
  $this->_getProductsForCustomerGroupPrice();
7841
  $pricerulesArray = $this->_getPricerulesList();
7842
- if(is_array($pricerulesArray)){
7843
- $this->db_do("TRUNCATE TABLE ". Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_group_price'));
7844
- $this->db_do("TRUNCATE TABLE ". Mage::getSingleton('core/resource')->getTableName('catalog_product_index_group_price'));
7845
 
7846
  }
7847
  // $i=1;
7848
- foreach($pricerulesArray as $pricerule) {
7849
- $this->_LOG("Calculation group price for rule ".$pricerule['id']."
7850
- (\nname = ".$pricerule['name']."
7851
- \nfinal_price = ".$pricerule['final_price']."
7852
- \nprice_from = ".$pricerule['price_from']."
7853
- \nprice_to = ".$pricerule['price_to']."
7854
- \nvendor_id = ".$pricerule['vendor_id']."
7855
- \ncategory_id = ".$pricerule['category_id']."
7856
- \nproduct_entity_id = ".$pricerule['product_entity_id']."
7857
- \nvendor_product_id = ".$pricerule['vendor_product_id']."
7858
- \ncustomergroup_id = ".$pricerule['customergroup_id']."
7859
- \ndistributor_id = ".$pricerule['distributor_id']."
7860
- \nrating = ".$pricerule['rating']."
7861
- \nmarge = ".$pricerule['marge']."
7862
- \nfixed = ".$pricerule['fixed']."
7863
- \nallow_subcat = ".$pricerule['allow_subcat']."
7864
- \nstore_id = ".$pricerule['store_id']."
7865
  )");
7866
 
7867
- $vendor_product_id_str = "'".str_replace(';', "','", $pricerule['vendor_product_id'])."'";
7868
  $where = "";
7869
  if (empty($pricerule['marge'])) $marge = "NULL";
7870
  else $marge = $pricerule['marge'];
@@ -7875,353 +8827,211 @@ STP DELETE*/
7875
  if (empty($pricerule['final_price'])) $final_price = "NULL";
7876
  else $final_price = $pricerule['final_price'];
7877
 
7878
- if (!empty($pricerule['price_from'])) $where.= " AND a.price > ".$pricerule['price_from'];
7879
 
7880
- if (!empty($pricerule['price_to'])) $where.= " AND a.price < ".$pricerule['price_to'];
7881
 
7882
- if (!empty($pricerule['vendor_id'])) $where.= " AND a.manufacturer_id = ".$pricerule['vendor_id'];
7883
 
7884
  //if(!empty($pricerule['vendor_product_id']))
7885
  // $where.= " AND vendor_product_id = ".$pricerule['vendor_product_id'];
7886
- if (!empty($pricerule['product_entity_id'])) $where.= " AND a.product_id = '".$pricerule['product_entity_id']."'";
7887
 
7888
  // if (!empty($pricerule['vendor_product_id'])) $where.= " AND a.sku = '".$pricerule['vendor_product_id']."'";
7889
- if (!empty($pricerule['vendor_product_id'])) $where.= " AND a.sku IN (". $vendor_product_id_str.")";
7890
 
7891
- if(!empty($pricerule['allow_subcat'])){
7892
- if (!empty($pricerule['category_id'])){
7893
- $children_cat=$this->get_all_children_cat($pricerule['category_id']);
7894
- $where.= " AND a.category_id IN (".$children_cat.")";
7895
  }
7896
- }else{
7897
- if (!empty($pricerule['category_id'])) $where.= " AND a.category_id = ".$pricerule['category_id'];
7898
  }
7899
 
7900
-
7901
  // if (!empty($pricerule['store_id'])) $where.= " AND store_id = ".$pricerule['store_id'];
7902
 
7903
  // if (!empty($pricerule['distributor_id'])) $where.= " AND distributor_id = ".$pricerule['distributor_id'];
7904
 
7905
- // $this->createCalcPriceFunc();
7906
- //echo "\n\nAAAAAAAAAAAAAAAAAAAAa".$pricerule['customergroup_id']."----------";
7907
  $customer_group_id_array = array();
7908
- if(strstr($pricerule['customergroup_id'], ",")){
7909
  //echo "55555555555555555";
7910
- $customer_group_id_array = explode(",", $pricerule['customergroup_id']);
7911
- }else{
7912
- $customer_group_id_array[0] = $pricerule['customergroup_id'];
7913
- }
7914
  // var_dump($pricerule);
7915
  // echo "CCCCCCC\n";
7916
  // var_dump($customer_group_id_array);
7917
- foreach($customer_group_id_array as $customer_group_id){
7918
- if(isset($customer_group_id) && $customer_group_id>=0){
7919
- $query="
7920
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_group_price')." (entity_id,
7921
  all_groups,
7922
  customer_group_id,
7923
  value,
7924
  website_id
7925
  )
7926
- (SELECT
7927
  a.product_id,
7928
  0,
7929
- ".$customer_group_id.",
7930
- ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7931
  a.price,
7932
- ".$marge." ,
7933
- ".$fixed.",
7934
- ".$final_price."),
7935
  0
7936
- FROM ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." a
7937
- WHERE true ".$where."
7938
  )
7939
  ON DUPLICATE KEY UPDATE
7940
- value =
7941
- ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7942
  a.price,
7943
- ".$marge." ,
7944
- ".$fixed.",
7945
- ".$final_price.")
7946
  ";
7947
  // echo "\n\n".$query;
7948
- $this->db_do($query);
7949
- if (!empty($pricerule['store_id']) && $pricerule['store_id']>0){
7950
- $query="
7951
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_group_price')." (entity_id,
7952
  customer_group_id,
7953
  price,
7954
  website_id
7955
  )
7956
- (SELECT
7957
  a.product_id,
7958
- ".$customer_group_id.",
7959
- ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7960
  a.price,
7961
- ".$marge." ,
7962
- ".$fixed.",
7963
- ".$final_price."),
7964
- ".$pricerule['store_id']."
7965
- FROM ". Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp')." a
7966
- WHERE true ".$where."
7967
  )
7968
- ON DUPLICATE KEY UPDATE
7969
- price =
7970
- ".Mage::getSingleton('core/resource')->getTableName('func_calc_price')."(
7971
- a.price,
7972
- ".$marge." ,
7973
- ".$fixed.",
7974
- ".$final_price.")
7975
- ";
7976
- // echo "\n\n".$query;
7977
- $this->db_do($query);
7978
-
7979
- }
7980
- }
7981
- }
7982
- }
7983
-
7984
- }
7985
- #################################################################################################
7986
-
7987
- protected function _getPricerulesList() {
7988
- $rulesArray = array();
7989
- $result = $this->db_do("
7990
- SELECT *
7991
- FROM ".Mage::getSingleton('core/resource')->getTableName('import_pricerules')."
7992
- ORDER BY rating DESC
7993
- ");
7994
- while($row = mysqli_fetch_assoc($result)) {
7995
- $rulesArray[$row['id']] = $row;
7996
- }
7997
- return $rulesArray;
7998
- }
7999
-
8000
-
8001
- #################################################################################################
8002
- function replaceMagentoProductsStockPrice(){
8003
- //Add stock
8004
- $connection = Mage::getModel('core/resource')->getConnection('core_write');
8005
- $result = $this->db_do("DELETE csi
8006
- FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
8007
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8008
- ON csi.product_id=cpe.entity_id
8009
- WHERE cpe.entity_id is null");
8010
- //set all sinch products stock=0 before upgrade (nedds for dayly stock&price import)
8011
-
8012
- $result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8013
- JOIN ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
8014
- ON cpe.entity_id=csi.product_id
8015
- SET
8016
- csi.qty=0,
8017
- csi.is_in_stock=0
8018
- WHERE cpe.store_product_id IS NOT NULL");
8019
-
8020
- $result = $this->db_do("
8021
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." (
8022
- product_id,
8023
- stock_id,
8024
- qty,
8025
- is_in_stock,
8026
- manage_stock
8027
- )(
8028
- SELECT
8029
- a.entity_id,
8030
- 1,
8031
- b.stock,
8032
- IF(b.stock > 0, 1, 0),
8033
- 1
8034
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8035
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8036
- ON a.store_product_id=b.store_product_id
8037
- )
8038
- ON DUPLICATE KEY UPDATE
8039
- qty=b.stock,
8040
- is_in_stock = IF(b.stock > 0, 1, 0),
8041
- manage_stock = 1
8042
- ");
8043
 
 
 
 
 
8044
 
8045
- $result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status'));
8046
 
8047
- $result = $this->db_do("
8048
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status')." (
8049
- product_id,
8050
- website_id,
8051
- stock_id,
8052
- qty,
8053
- stock_status
8054
- )(
8055
- SELECT
8056
- a.product_id,
8057
- w.website_id,
8058
- 1,
8059
- a.qty,
8060
- IF(qty > 0, 1, 0)
8061
- FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." a
8062
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." b
8063
- ON a.product_id=b.entity_id
8064
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8065
- ON b.store_product_id=w.store_product_id
8066
- )
8067
- ON DUPLICATE KEY UPDATE
8068
- qty=a.qty,
8069
- stock_status = IF(a.qty > 0, 1, 0)
8070
- ");
8071
 
8072
- //Add prices
8073
- //$result = $this->db_do("truncate catalog_product_entity_decimal");
8074
- $result = $this->db_do("DELETE cped
8075
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." cped
8076
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8077
- ON cped.entity_id=cpe.entity_id
8078
- WHERE cpe.entity_id IS NULL");
 
 
 
 
 
 
 
 
 
 
8079
 
8080
  $result = $this->db_do("
8081
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8082
- entity_type_id,
8083
- attribute_id,
8084
- store_id,
8085
- entity_id,
8086
- value
8087
- )(
8088
- SELECT
8089
- " . $this->_getProductEntityTypeId(). ",
8090
- " . $this->_getProductAttributeId('price'). ",
8091
- w.website,
8092
- a.entity_id,
8093
- b.price
8094
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8095
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8096
- ON a.store_product_id=b.store_product_id
8097
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8098
- ON a.store_product_id=w.store_product_id
8099
- )
8100
- ON DUPLICATE KEY UPDATE
8101
- value = b.price
8102
- ");
8103
 
8104
  $result = $this->db_do("
8105
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8106
- entity_type_id,
8107
- attribute_id,
8108
- store_id,
8109
- entity_id,
8110
- value
8111
- )(
8112
- SELECT
8113
- " . $this->_getProductEntityTypeId(). ",
8114
- " . $this->_getProductAttributeId('price'). ",
8115
- 0,
8116
- a.entity_id,
8117
- b.price
8118
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8119
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8120
- ON a.store_product_id=b.store_product_id
8121
- )
8122
- ON DUPLICATE KEY UPDATE
8123
- value = b.price
8124
- ");
8125
- //Add cost
8126
- // $result = $this->db_do("truncate catalog_product_entity_decimal");
8127
- $result = $this->db_do("
8128
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8129
- entity_type_id,
8130
- attribute_id,
8131
- store_id,
8132
- entity_id,
8133
- value
8134
- )(
8135
- SELECT
8136
- " . $this->_getProductEntityTypeId(). ",
8137
- " . $this->_getProductAttributeId('cost'). ",
8138
- w.website,
8139
- a.entity_id,
8140
- b.cost
8141
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8142
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8143
- ON a.store_product_id=b.store_product_id
8144
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8145
- ON a.store_product_id=w.store_product_id
8146
- )
8147
- ON DUPLICATE KEY UPDATE
8148
- value = b.cost
8149
- ");
8150
 
8151
  $result = $this->db_do("
8152
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
8153
- entity_type_id,
8154
- attribute_id,
8155
- store_id,
8156
- entity_id,
8157
- value
8158
- )(
8159
- SELECT
8160
- " . $this->_getProductEntityTypeId(). ",
8161
- " . $this->_getProductAttributeId('cost'). ",
8162
- 0,
8163
- a.entity_id,
8164
- b.cost
8165
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8166
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8167
- ON a.store_product_id=b.store_product_id
8168
- )
8169
- ON DUPLICATE KEY UPDATE
8170
- value = b.cost
8171
- ");
8172
 
8173
- //make products enable in FO
8174
- // $result = $this->db_do(" truncate catalog_product_index_price");
8175
- $result = $this->db_do("DELETE cpip
8176
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." cpip
8177
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
8178
- ON cpip.entity_id=cpe.entity_id
8179
- WHERE cpe.entity_id IS NULL");
8180
 
8181
- $q="SELECT customer_group_id FROM ".Mage::getSingleton('core/resource')->getTableName('customer_group');
8182
- $quer=$this->db_do($q);
8183
 
8184
- while ($row = mysqli_fetch_assoc($quer)) {
8185
- $result = $this->db_do("
8186
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." (
8187
- entity_id,
8188
- customer_group_id,
8189
- website_id,
8190
- tax_class_id,
8191
- price,
8192
- final_price,
8193
- min_price,
8194
- max_price
8195
- )(SELECT
8196
- a.entity_id,
8197
- ".$row['customer_group_id'].",
8198
- w.website_id,
8199
- 2,
8200
- b.price ,
8201
- b.price ,
8202
- b.price ,
8203
- b.price
8204
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8205
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
8206
- ON a.store_product_id=b.store_product_id
8207
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
8208
- ON a.store_product_id=w.store_product_id
8209
- )
8210
- ON DUPLICATE KEY UPDATE
8211
- tax_class_id = 2,
8212
- price = b.price,
8213
- final_price = b.price,
8214
- min_price = b.price,
8215
- max_price = b.price
8216
- ");
8217
  }
 
 
 
 
 
 
 
 
 
8218
  }
8219
 
 
8220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8221
 
8222
  #################################################################################################
8223
 
8224
- function getProductDescription($entity_id){
 
8225
 
8226
  $this->loadProductParams($entity_id);
8227
  $this->loadProductStarfeatures($entity_id);
@@ -8230,234 +9040,279 @@ STP DELETE*/
8230
  $this->loadRelatedProducts($entity_id);
8231
  Varien_Profiler::stop('Bintime FILE RELATED');
8232
 
8233
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8234
  }
 
8235
  #################################################################################################
8236
 
8237
- public function getProductName(){
 
8238
  return $this->productName;
8239
  }
 
8240
  #################################################################################################
8241
 
8242
- public function getProductDescriptionList(){
 
8243
  return $this->productDescriptionList;
8244
  }
 
8245
  #################################################################################################
8246
 
8247
- public function getProductSpecifications(){
 
8248
  return $this->specifications;
8249
  }
 
8250
  #################################################################################################
8251
 
8252
- public function getShortProductDescription(){
 
8253
  return $this->productDescription;
8254
  }
 
8255
  #################################################################################################
8256
 
8257
- public function getFullProductDescription(){
 
8258
  return $this->fullProductDescription;
8259
  }
 
8260
  #################################################################################################
8261
 
8262
- public function getLowPicUrl(){
 
8263
  return $this->highPicUrl;
8264
  }
8265
- #################################################################################################
8266
 
8267
- public function getRelatedProducts(){
8268
- return $this->relatedProducts;
8269
- }
8270
- #################################################################################################
8271
 
8272
- public function getVendor(){
8273
- return $this->vendor;
 
8274
  }
8275
- #################################################################################################
8276
 
8277
- public function getMPN(){
8278
- return $this->productId;
8279
- }
8280
  #################################################################################################
8281
 
8282
- public function getEAN(){
8283
- return $this->EAN;
8284
- }
8285
- ################################################################################################
8286
-
8287
- public function getGalleryPhotos(){
8288
- return $this->galleryPhotos;
8289
  }
8290
 
8291
- #################################################################################################
8292
 
8293
- private function loadProductParams($entity_id){
8294
- $store_product_id=$this->getStoreProductIdByEntity($entity_id);
8295
- if(!$store_product_id){
8296
- // echo "AAAAAAA"; exit;
8297
- return;
8298
- }
8299
- $q="SELECT
8300
- sinch_product_id,
8301
- product_sku,
8302
- product_name,
8303
- sinch_manufacturer_id,
8304
- store_category_id,
8305
- main_image_url,
8306
- thumb_image_url,
8307
- medium_image_url,
8308
- specifications,
8309
- description,
8310
- specifications
8311
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products')."
8312
- WHERE store_product_id =".$store_product_id;
8313
- $quer=$this->db_do($q);
8314
- $product=mysqli_fetch_array($quer);
8315
-
8316
- $this->productDescription = (string) substr($product['description'],50,0);
8317
- $this->fullProductDescription = (string)$product['description'];
8318
- $this->lowPicUrl = (string)$product["medium_image_url"];//thumb_image_url"];
8319
- $this->highPicUrl = (string)$product["main_image_url"];
8320
- $this->productName = (string)$product["product_name"];
8321
- $this->productId = (string)$product['product_sku'];
8322
- $this->specifications = (string)$product['specifications'];
8323
- $this->sinchProductId = (string)$product['sinch_product_id'];
8324
- if($product['sinch_manufacturer_id']){
8325
- $q="SELECT manufacturer_name
8326
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')."
8327
- WHERE sinch_manufacturer_id=".$product['sinch_manufacturer_id'];
8328
- $quer=$this->db_do($q);
8329
- $manufacturer=mysqli_fetch_array($quer);
8330
- $this->vendor = (string)$manufacturer['manufacturer_name'];
8331
- }
8332
- $q="SELECT DISTINCT ean_code
8333
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
8334
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
8335
- ON sec.product_id=sp.sinch_product_id
8336
- WHERE sp.store_product_id=".$store_product_id;
8337
- $quer=$this->db_do($q);
8338
- while ($row=mysqli_fetch_array($quer)){
8339
- $EANarr[]=$row['ean_code'];
8340
- }
8341
- // $prodEAN = $productTag->EANCode;
8342
- $EANstr='';
8343
- /* $EANarr=null;
8344
- foreach($prodEAN as $ellEAN){
8345
- $EANarr[]=$ellEAN['EAN'];
8346
- }
8347
- */
8348
- $EANstr=implode(", ",$EANarr);
8349
- $this->EAN = (string)$EANstr;//$productTag->EANCode['EAN'];
8350
  }
8351
- #################################################################################################
8352
-
8353
- private function loadProductStarfeatures($entity_id){
8354
- $descriptionArray=array();
8355
- $product_info_features = $this->db_do("
8356
- SELECT c.feature_name AS name, b.text AS value
8357
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." a
8358
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." b
8359
- ON a.restricted_value_id = b.restricted_value_id
8360
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features')." c
8361
- ON b.category_feature_id = c.category_feature_id
8362
- WHERE a.sinch_product_id = '" .$this->sinchProductId . "'" );
8363
- while ($features = mysqli_fetch_array($product_info_features)) {
8364
- $descriptionArray[$features['name']] = $features['value'];
8365
- }
8366
 
 
8367
 
8368
- $this->productDescriptionList = $descriptionArray;
 
 
8369
  }
8370
- #################################################################################################
8371
 
8372
- private function loadRelatedProducts($entity_id){
8373
- $this->sinchProductId;
8374
- if(!$this->sinchProductId){
8375
- return;
8376
- }
8377
- $q="SELECT
8378
- st_prod.sinch_product_id,
8379
- st_prod.product_sku,
8380
- st_prod.product_name,
8381
- st_prod.sinch_manufacturer_id,
8382
- st_prod.store_category_id,
8383
- st_prod.main_image_url,
8384
- st_prod.thumb_image_url,
8385
- st_prod.medium_image_url,
8386
- st_prod.specifications,
8387
- st_prod.description,
8388
- st_prod.specifications,
8389
- st_manuf.manufacturer_name,
8390
- st_manuf.manufacturers_image
8391
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." st_rel_prod
8392
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." st_prod
8393
- ON st_rel_prod.related_sinch_product_id=st_prod.sinch_product_id
8394
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." st_manuf
8395
- ON st_prod.sinch_manufacturer_id=st_manuf.sinch_manufacturer_id
8396
- WHERE st_rel_prod.sinch_product_id=".$this->sinchProductId;
8397
-
8398
- // echo $q;
8399
- $quer=$this->db_do($q);
8400
- while($row=mysqli_fetch_array($quer)){
8401
-
8402
- $productArray = array();
8403
- $productArray['name'] = (string)$row['product_name'];
8404
- $productArray['thumb'] = (string)$row['thumb_image_url'];
8405
- $mpn = (string)$row['product_sku'];
8406
- $productSupplierId = (int)$row['sinch_manufacturer_id'];
8407
- $productArray['supplier_thumb'] = (string)($row['manufacturers_image']);
8408
- $productArray['supplier_name'] = (string)$row['manufacturer_name'];
8409
 
8410
- $this->relatedProducts[$mpn] = $productArray;
8411
- }
 
8412
  }
8413
- #################################################################################################
8414
- /**
8415
- * load Gallery array from XML
8416
- */
8417
- public function loadGalleryPhotos($entity_id){
8418
- /*$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
8419
- if (!count($galleryPhotos)){
8420
- return false;
8421
- }
8422
- */
8423
- $store_product_id=$this->getStoreProductIdByEntity($entity_id);
8424
- if(!$store_product_id){
8425
- return;
8426
- }
8427
- $q=$this->db_do("SELECT COUNT(*) AS cnt
8428
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
8429
- WHERE store_product_id=".$store_product_id);
8430
-
8431
- $res=mysqli_fetch_array($q);
8432
- if(!$res || !$res['cnt']){
8433
- return false;
8434
- }
8435
- $q="SELECT
8436
- image_url as Pic,
8437
- thumb_image_url as ThumbPic
8438
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
8439
- WHERE store_product_id=".$store_product_id;
8440
 
8441
- $res=$this->db_do($q);
8442
-
8443
- while($photo=mysqli_fetch_array($res)){
8444
- $picHeight = (int)500;//$photo["PicHeight"];
8445
- $picWidth = (int)500;//$photo["PicWidth"];
8446
- $thumbUrl = (string)$photo["ThumbPic"];
8447
- $picUrl = (string)$photo["Pic"];
8448
 
8449
- array_push($this->galleryPhotos, array(
8450
- 'height' => $picHeight,
8451
- 'width' => $picWidth,
8452
- 'thumb' => $thumbUrl,
8453
- 'pic' => $picUrl
8454
- ));
8455
- }
8456
- }
8457
- #################################################################################################
8458
- public function reloadProductImage($entity_id){
8459
  $result = $this->db_do("
8460
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8461
  entity_type_id,
8462
  attribute_id,
8463
  store_id,
@@ -8465,14 +9320,14 @@ STP DELETE*/
8465
  value
8466
  )(
8467
  SELECT
8468
- " . $this->_getProductEntityTypeId(). ",
8469
- " . $this->_getProductAttributeId('image'). ",
8470
  w.store_id,
8471
  a.entity_id,
8472
  b.main_image_url
8473
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8474
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8475
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8476
  ON a.store_product_id = b.store_product_id
8477
  WHERE a.entity_id=$entity_id
8478
  )
@@ -8483,7 +9338,7 @@ STP DELETE*/
8483
 
8484
  // image for specific web sites
8485
  $result = $this->db_do("
8486
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8487
  entity_type_id,
8488
  attribute_id,
8489
  store_id,
@@ -8491,13 +9346,13 @@ STP DELETE*/
8491
  value
8492
  )(
8493
  SELECT
8494
- " . $this->_getProductEntityTypeId(). ",
8495
- " . $this->_getProductAttributeId('image'). ",
8496
  0,
8497
  a.entity_id,
8498
  b.main_image_url
8499
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8500
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8501
  ON a.store_product_id = b.store_product_id
8502
  WHERE a.entity_id=$entity_id
8503
  )
@@ -8508,7 +9363,7 @@ STP DELETE*/
8508
 
8509
  // small_image for specific web sites
8510
  $result = $this->db_do("
8511
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8512
  entity_type_id,
8513
  attribute_id,
8514
  store_id,
@@ -8516,14 +9371,14 @@ STP DELETE*/
8516
  value
8517
  )(
8518
  SELECT
8519
- " . $this->_getProductEntityTypeId(). ",
8520
- " . $this->_getProductAttributeId('small_image'). ",
8521
  w.store_id,
8522
  a.entity_id,
8523
  b.main_image_url
8524
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8525
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8526
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8527
  ON a.store_product_id = b.store_product_id
8528
  WHERE a.entity_id=$entity_id
8529
  )
@@ -8534,7 +9389,7 @@ STP DELETE*/
8534
 
8535
  // small_image for all web sites
8536
  $result = $this->db_do("
8537
- INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
8538
  entity_type_id,
8539
  attribute_id,
8540
  store_id,
@@ -8542,1295 +9397,779 @@ STP DELETE*/
8542
  value
8543
  )(
8544
  SELECT
8545
- " . $this->_getProductEntityTypeId(). ",
8546
- " . $this->_getProductAttributeId('small_image'). ",
8547
  0,
8548
  a.entity_id,
8549
  b.main_image_url
8550
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
8551
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
8552
- INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
8553
  ON a.store_product_id = b.store_product_id
8554
  WHERE a.entity_id=$entity_id
8555
  )
8556
  ON DUPLICATE KEY UPDATE
8557
- value = b.main_image_url
8558
- ");
8559
- }
8560
- #################################################################################################
8561
- public function runIndexer(){
8562
- $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'));
8563
- $this->db_do ("SET FOREIGN_KEY_CHECKS=0");
8564
- $this->db_do("TRUNCATE TABLE ".Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'));
8565
- $this->db_do ("SET FOREIGN_KEY_CHECKS=1");
8566
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8567
- SET value = ''
8568
- WHERE entity_type_id=".$this->_getProductEntityTypeId()." AND attribute_id=".$this->_getProductAttributeId('url_key'));
8569
- exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php reindexall');
8570
- }
8571
- #################################################################################################
8572
- public function runStockPriceIndexer(){
8573
- exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php --reindex catalog_product_price,cataloginventory_stock');
8574
- }
8575
- #################################################################################################
8576
- private function getStoreProductIdByEntity($entity_id){
8577
- $q=$this->db_do("SELECT store_product_id
8578
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
8579
- WHERE entity_id=".$entity_id);
8580
- $res=mysqli_fetch_array($q);
8581
- // echo $entity_id."AAAA".$res['store_product_id']; exit;
8582
- return ($res['store_product_id']);
8583
- }
8584
- #################################################################################################
8585
-
8586
- private function db_connect() {
8587
- // $connection = Mage::getModel('core/resource')->getConnection('core_write');
8588
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
8589
- $dbConn = mysqli_init();
8590
- mysqli_options($dbConn, MYSQLI_OPT_LOCAL_INFILE, true);
8591
- if (mysqli_real_connect($dbConn, $dbConf->host, $dbConf->username, $dbConf->password)) {
8592
- $this->db = $dbConn;
8593
- if(!mysqli_select_db($this->db, $dbConf->dbname)){
8594
- die("Can't select the database: " . mysqli_error($this->db));
8595
- }
8596
- }else{
8597
- die("Could not connect: " . mysqli_error($this->db));
8598
- }
8599
-
8600
- }
8601
- #################################################################################################
8602
-
8603
- private function db_do($query) {
8604
- if($this->debug_mode){
8605
- Mage::log("Query: " . $query, null, $this->_logFile);
8606
- }
8607
- $result = mysqli_query($this->db, $query) or die("Query failed: " . mysqli_error($this->db));
8608
- if (!$result) {
8609
- throw new Exception("Invalid query: $sql\n" . mysqli_error($this->db));
8610
- } else {
8611
- return $result;
8612
- }
8613
- return $result;
8614
- }
8615
- ##################################################################################################
8616
- function table_rows_count($table){
8617
- $rows_count_res=$this->db_do("select count(*) as cnt from ".$table);
8618
- $rows_count=mysqli_fetch_array($rows_count_res);
8619
- return ($rows_count['cnt']);
8620
- }
8621
- ##################################################################################################
8622
- function file_strings_count($parse_file){
8623
- $files_str=count(file($parse_file));
8624
- return $files_str;
8625
- }
8626
- ##################################################################################################
8627
- function check_loaded_data($file, $table){
8628
- $cnt_strings_in_file=$this->file_strings_count($file);
8629
- $cnt_rows_int_table=$this->table_rows_count($table);
8630
- $persent_cnt_strings_in_file=$cnt_strings_in_file / 10;
8631
- if($cnt_rows_int_table > $persent_cnt_strings_in_file){
8632
- return true;
8633
- }else{
8634
- return false;
8635
- }
8636
- }
8637
- ##################################################################################################
8638
-
8639
-
8640
- function valid_utf($string,$new_line = true){
8641
- /* if($new_line == true){
8642
- $string = preg_replace('/\\\n/',"\n",$string);
8643
- }
8644
- */
8645
- $string = preg_replace('/™/','&#8482;',$string);
8646
- $string = preg_replace("/®/",'&reg;',$string);
8647
- $string = preg_replace("/≈/",'&asymp;',$string);
8648
- $string = preg_replace("/".chr(226).chr(128).chr(157)."/",'&quot;',$string);
8649
- $string = preg_replace("/".chr(226).chr(128).chr(153)."/",'&prime;',$string);
8650
- $string = preg_replace("/°/",'&deg;',$string);
8651
- $string = preg_replace("/±/",'&plusmn;',$string);
8652
- $string = preg_replace("/µ/",'&micro;',$string);
8653
- $string = preg_replace("/²/",'&sup2;',$string);
8654
- $string = preg_replace("/³/",'&sup3;',$string);
8655
- $string = preg_replace('/\xe2\x80\x93/','-',$string);
8656
- $string = preg_replace('/\xe2\x80\x99/','\'',$string);
8657
- $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
8658
- $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
8659
-
8660
- return utf8_decode($string);
8661
-
8662
- // return $string;
8663
- }
8664
-
8665
- #################################################################################################
8666
- function dropHTMLentities($entity_type_id, $attribute_id){
8667
- // product name for all web sites
8668
- $result = $this->db_do("
8669
- SELECT value, entity_id
8670
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8671
- WHERE entity_type_id=".$entity_type_id."
8672
- AND attribute_id=".$attribute_id
8673
- );
8674
- while($row=mysqli_fetch_array($result)){
8675
- $value=$this->valid_char($row['value']);
8676
- if($value!='' and $value!=$row['value']){
8677
- $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
8678
- SET value='".mysqli_real_escape_string($this->db, $value)."'
8679
- WHERE entity_id=".$row['entity_id']."
8680
- AND entity_type_id=".$entity_type_id."
8681
- AND attribute_id=".$attribute_id);
8682
- }
8683
-
8684
- }
8685
- }
8686
-
8687
- #################################################################################################
8688
-
8689
- function valid_char($string){
8690
- $string = preg_replace('/&#8482;/', ' ',$string);
8691
- $string = preg_replace('/&reg;/', ' ',$string);
8692
- $string = preg_replace('/&asymp;/', ' ',$string);
8693
- $string = preg_replace('/&quot;/', ' ',$string);
8694
- $string = preg_replace('/&prime;/', ' ',$string);
8695
- $string = preg_replace('/&deg;/', ' ',$string);
8696
- $string = preg_replace('/&plusmn;/', ' ',$string);
8697
- $string = preg_replace('/&micro;/', ' ',$string);
8698
- $string = preg_replace('/&sup2;/', ' ',$string);
8699
- $string = preg_replace('/&sup3;/', ' ',$string);
8700
- // $string = preg_replace('/\xe2\x80\x93/','-',$string);
8701
- // $string = preg_replace('/\xe2\x80\x99/','\'',$string);
8702
- // $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
8703
- // $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
8704
-
8705
- // return utf8_decode($string);
8706
-
8707
- return $string;
8708
- }
8709
-
8710
- #################################################################################################
8711
-
8712
- function _LOG($log){
8713
-
8714
- if($log){
8715
- // $q="insert into ".$this->import_log_table." (message_date, message) values(now(), '".$log."')";
8716
- // $this->db_do($q);
8717
- Mage::log($log, null, $this->_logFile);
8718
- // list($usec, $sec) = explode(" ", microtime());
8719
- // $time = ((float)$usec + (float)$sec);
8720
- /* $time = date("D M j G:i:s T Y");
8721
-
8722
- if($_SERVER['REMOTE_ADDR']){
8723
- $log = "[".getmypid()."] "."[".$_SERVER['REMOTE_ADDR']."] "."[".$time."] ".$log."\n";
8724
- error_log($log,3,LOG_FILE);
8725
- }else{
8726
- $log = "[".getmypid()."] "."[".$time."] ".$log."\n";
8727
- error_log($log,3,LOG_FILE . ".cli");
8728
- */
8729
- }
8730
- }
8731
-
8732
- #################################################################################################
8733
-
8734
- function wget(){
8735
-
8736
- $got = func_num_args();
8737
- $url = $file = $flag = false;
8738
-
8739
- if($got<1){
8740
- return false;
8741
- }elseif($got == 1){
8742
- $url = func_get_arg(0);
8743
- }elseif($got == 2){
8744
- $url = func_get_arg(0);
8745
- $file= func_get_arg(1);
8746
- }elseif($got == 3){
8747
- $url = func_get_arg(0);
8748
- $file= func_get_arg(1);
8749
- $flag= func_get_arg(2);
8750
- }
8751
-
8752
- if($flag == 'copy'){
8753
- if(copy($url,$file)){
8754
- return true;
8755
- }else{
8756
- return false;
8757
- }
8758
- }elseif($flag == 'system'){
8759
- exec("wget -O$file $url");
8760
- return true;
8761
- }else{
8762
- $c=curl_init($url);
8763
- curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
8764
- curl_setopt($c,CURLOPT_FOLLOWLOCATION,1);
8765
- curl_setopt($c,CURLOPT_HEADER,array("Accept-Encoding: gzip"));
8766
- if(!$file){
8767
- $page = curl_exec($c);
8768
- curl_close($c);
8769
- return $page;
8770
- }else{
8771
- $FH = fopen($file,"wb");// or echo"Can't open for writing ".$file;
8772
- fwrite($FH,curl_exec($c));
8773
- fclose($FH);
8774
- curl_close($c);
8775
- return true;
8776
- }
8777
- }
8778
- }
8779
- #################################################################################################
8780
- /**
8781
- * Create the import directory Hierarchy
8782
- * @return false if directory already exists
8783
- */
8784
- public function createTemporaryImportDerictory(){
8785
- $dirArray = explode('/', $this->varDir);
8786
- end($dirArray);
8787
- // $this->_LOG('before :'.$this->varDir);
8788
- if (prev($dirArray)=='bintime'){
8789
- return false;
8790
- }
8791
-
8792
-
8793
- $this->varDir = $this->varDir . 'bintime/sinchimport/';
8794
- if (!is_dir($this->varDir)) {
8795
- mkdir($this->varDir,0777,true);
8796
- }
8797
- // $this->_LOG('after :'.$this->varDir);
8798
- }
8799
- #################################################################################################
8800
-
8801
- function count_children($id){
8802
-
8803
- $q="SELECT store_category_id
8804
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8805
- WHERE parent_store_category_id=".$id;
8806
- $quer=$this->db_do($q);
8807
- $count=0;
8808
- while ($row=mysqli_fetch_array($quer)){
8809
- $count+=$this->count_children($row['store_category_id']);
8810
- $count++;
8811
- }
8812
- return ($count);
8813
- }
8814
- #################################################################################################
8815
- private function delete_old_sinch_categories_from_shop(){
8816
-
8817
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." cat
8818
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8819
- ON cat.entity_id=scm.shop_entity_id
8820
- WHERE
8821
- (scm.shop_store_category_id is not null) AND
8822
- (scm.store_category_id is null)";
8823
- $this->db_do($q);
8824
-
8825
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." cat
8826
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8827
- ON cat.entity_id=scm.shop_entity_id
8828
- WHERE
8829
- (scm.shop_store_category_id is not null) AND
8830
- (scm.store_category_id is null)";
8831
- $this->db_do($q);
8832
-
8833
- $q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cat
8834
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
8835
- ON cat.entity_id=scm.shop_entity_id
8836
- WHERE
8837
- (scm.shop_store_category_id is not null) AND
8838
- (scm.store_category_id is null)";
8839
- $this->db_do($q);
8840
-
8841
  }
8842
- #################################################################################################
8843
-
8844
- function culc_path($parent_id, $ent_id){
8845
 
8846
- //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]\n");
8847
-
8848
- $path='';
8849
- $cat_id=$parent_id;
8850
- $q="SELECT
8851
- parent_id
8852
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
8853
- WHERE entity_id=".$cat_id;
8854
- $quer=$this->db_do($q);
8855
- $row=mysqli_fetch_array($quer);
8856
- while($row['parent_id']){
8857
- $path=$row['parent_id'].'/'.$path;
8858
- $q="SELECT
8859
- parent_id
8860
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
8861
- WHERE entity_id=".$row['parent_id'];
8862
- $quer=$this->db_do($q);
8863
- $row=mysqli_fetch_array($quer);
8864
 
8865
- }
8866
- if($cat_id){
8867
- $path.=$cat_id."/";
8868
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8869
 
8870
- if($path){
8871
- return($path.$ent_id);
8872
- }else{
8873
- return($ent_id);
8874
- }
8875
 
 
8876
  }
8877
- #################################################################################################
8878
 
8879
- function get_category_level($id){
8880
- $q="SELECT parent_store_category_id
8881
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8882
- WHERE store_category_id=".$id;
8883
- $quer=$this->db_do($q);
8884
- $level=1;
8885
- $row=mysqli_fetch_array($quer);
8886
- while ($row['parent_store_category_id']!=0){
8887
- $q="SELECT parent_store_category_id
8888
- FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
8889
- WHERE store_category_id=".$row['parent_store_category_id'];
8890
- $quer=$this->db_do($q);
8891
- $row=mysqli_fetch_array($quer);
8892
- $level++;
8893
- if($level>20){
8894
- break;
8895
- }
8896
- }
8897
 
8898
- return($level);
 
 
 
 
8899
  }
8900
- #################################################################################################
8901
 
8902
- function InitImportStatuses($type){
8903
- $this->db_do("DROP TABLE IF EXISTS ".$this->import_status_table);
8904
- $this->db_do("CREATE TABLE ".$this->import_status_table."(
8905
- id int(11) NOT NULL auto_increment PRIMARY KEY,
8906
- message varchar(50),
8907
- finished int(1) default 0
8908
- )"
8909
- );
8910
- $this->db_do("INSERT INTO ".$this->import_status_statistic_table." (
8911
- start_import,
8912
- finish_import,
8913
- import_type,
8914
- global_status_import,
8915
- import_run_type,
8916
- error_report_message)
8917
- VALUES(
8918
- now(),
8919
- NULL,
8920
- '$type',
8921
- 'Run',
8922
- '".$this->import_run_type."',
8923
- ''
8924
- )
8925
- ");
8926
- $q="SELECT MAX(id) AS id FROM ".$this->import_status_statistic_table;
8927
 
8928
- $quer=$this->db_do($q);
8929
- $row=mysqli_fetch_array($quer);
8930
- $this->current_import_status_statistic_id=$row['id'];
8931
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
8932
- SET global_status_import='Failed'
8933
- WHERE global_status_import='Run' AND id!=".$this->current_import_status_statistic_id);
8934
 
8935
- }
8936
- #################################################################################################
8937
- function set_imports_failed(){
8938
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
8939
- SET global_status_import='Failed'
8940
- WHERE global_status_import='Run'");
8941
- }
8942
- #################################################################################################
8943
- function set_import_error_reporting_message($message){
8944
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
8945
- SET error_report_message='".mysqli_real_escape_string($this->db, $message)."'
8946
- WHERE id=".$this->current_import_status_statistic_id);
8947
- }
8948
- #################################################################################################
8949
- function getImportStatusHistory(){
8950
- $res="SELECT COUNT(*) FROM ".$this->import_status_statistic_table;
8951
- $cnt_arr=mysqli_fetch_array($this->db_do($res));
8952
- $cnt=$cnt_arr[0];
8953
- $StatusHistory_arr = array();
8954
- if($cnt>0){
8955
- $a=(($cnt>7)? ($cnt-7): 0);
8956
- $b=$cnt;
8957
- $q="SELECT
8958
- id,
8959
- start_import,
8960
- finish_import,
8961
- import_type,
8962
- number_of_products,
8963
- global_status_import,
8964
- detail_status_import
8965
- FROM ".$this->import_status_statistic_table."
8966
- ORDER BY start_import limit ".$a.", ".$b;
8967
- $result=$this->db_do($q);
8968
- while($row=mysqli_fetch_array($result)){
8969
- $StatusHistory_arr[]=$row;
8970
  }
8971
  }
8972
  return $StatusHistory_arr;
8973
- }
8974
- #################################################################################################
8975
- function getDateOfLatestSuccessImport(){
8976
- $q="SELECT start_import, finish_import
8977
- FROM ".$this->import_status_statistic_table."
8978
- WHERE global_status_import='Successful'
 
 
 
 
 
8979
  ORDER BY id DESC LIMIT 1";
8980
- $imp_date=mysqli_fetch_array($this->db_do($q));
8981
  return $imp_date['start_import'];
8982
- }
8983
- #################################################################################################
8984
- function getDataOfLatestImport(){
8985
- $q="SELECT
8986
- start_import,
8987
- finish_import,
8988
- import_type,
8989
- number_of_products,
8990
- global_status_import,
8991
- detail_status_import,
8992
- number_of_products,
8993
- error_report_message
8994
- FROM ".$this->import_status_statistic_table."
 
 
 
 
 
8995
  ORDER BY id DESC LIMIT 1";
8996
- $imp_status=mysqli_fetch_array($this->db_do($q));
8997
  return $imp_status;
8998
- }
 
8999
 
9000
- #################################################################################################
9001
- function addImportStatus($message, $finished=0){
9002
- $q="INSERT INTO ".$this->import_status_table."
9003
- (message, finished)
9004
- VALUES('".$message."', $finished)";
9005
- $this->db_do($q);
9006
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
9007
- SET detail_status_import='".$message."'
9008
- WHERE id=".$this->current_import_status_statistic_id);
9009
- if($finished==1){
9010
- $this->db_do("UPDATE ".$this->import_status_statistic_table."
9011
- SET
9012
- global_status_import='Successful',
9013
- finish_import=now()
9014
- WHERE
9015
- error_report_message='' and
9016
- id=".$this->current_import_status_statistic_id);
9017
- }
9018
- }
9019
- #################################################################################################
9020
 
9021
- function getImportStatuses(){
9022
- $q="SELECT id, message, finished
9023
- FROM ".$this->import_status_table."
 
 
 
9024
  ORDER BY id LIMIT 1";
9025
- $quer=$this->db_do($q);
9026
- if($row=mysqli_fetch_array($quer)){
9027
- $messages=array('message'=>$row['message'], 'id'=>$row['id'], 'finished'=>$row['finished']);
9028
- $id=$row['id'];
9029
  }
9030
- if($id){
9031
- $q="DELETE FROM ".$this->import_status_table." WHERE id=".$id;
9032
  $this->db_do($q);
9033
  }
9034
  return $messages;
9035
- }
9036
- #################################################################################################
9037
 
9038
- private function _getEntityTypeId($code) {
9039
- $sql = "
9040
- SELECT entity_type_id
9041
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9042
- WHERE entity_type_code = '".$code."'
9043
- LIMIT 1
9044
- ";
9045
- $result = $this->db_do($sql);
9046
- if ($row = mysqli_fetch_assoc($result)) {
9047
- return $row['entity_type_id'];
9048
- }
9049
- return false;
9050
- }
9051
- #################################################################################################
9052
 
9053
- private function _getProductEntityTypeId(){
9054
- if (!$this->_productEntityTypeId) {
9055
- $this->_productEntityTypeId = $this->_getEntityTypeId('catalog_product');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9056
  }
9057
- return $this->_productEntityTypeId;
9058
- }
9059
- #################################################################################
9060
 
9061
- private function _getProductDefaulAttributeSetId(){
9062
- if (!$this->defaultAttributeSetId) {
9063
- $sql = "
9064
- SELECT entity_type_id, default_attribute_set_id
9065
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9066
- WHERE entity_type_code = 'catalog_product'
9067
- LIMIT 1
9068
- ";
9069
- $result = $this->db_do($sql);
9070
- if ($row = mysqli_fetch_assoc($result)) {
9071
 
9072
- $this->defaultAttributeSetId = $row['default_attribute_set_id'];
9073
- }
9074
- }
9075
- return $this->defaultAttributeSetId;
9076
- }
9077
- #################################################################################################
9078
 
9079
- private function _getCategoryEntityTypeIdAndDefault_attribute_set_id(){
9080
- if (!$this->_categoryEntityTypeId || !$this->_categoryDefault_attribute_set_id) {
9081
- $sql = "
9082
- SELECT entity_type_id, default_attribute_set_id
9083
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
9084
- WHERE entity_type_code = 'catalog_category'
9085
- LIMIT 1
9086
- ";
9087
- $result = $this->db_do($sql);
9088
- if ($row = mysqli_fetch_assoc($result)) {
9089
- $this->_categoryEntityTypeId = $row['entity_type_id'];
9090
- $this->_categoryDefault_attribute_set_id = $row['default_attribute_set_id'];
9091
  }
 
9092
 
 
 
 
 
 
 
 
 
9093
  }
9094
- }
 
 
 
 
 
 
 
 
 
 
9095
  ##################################################################################################
9096
 
9097
- private function _getAttributeId($attributeCode,$typeCode)
9098
- {
9099
- if ($typeCode=='catalog_product') {
9100
- $typeId = $this->_getProductEntityTypeId();
9101
- }
9102
- else {
9103
- $typeId = $this->_getEntityTypeId($typeCode);
9104
- }
9105
- if (!isset($this->_attributeId[$typeCode]) OR !is_array($this->_attributeId[$typeCode])) {
9106
- $sql = "
9107
- SELECT attribute_id, attribute_code
9108
- FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute')."
9109
- WHERE entity_type_id = '" . $typeId . "'
9110
- ";
9111
- $result = $this->db_do($sql);
9112
- while ($row = mysqli_fetch_assoc($result)) {
9113
- $this->_attributeId[$typeCode][$row['attribute_code']] = $row['attribute_id'];
9114
- }
9115
- }
9116
- // echo 'attribute code: '.$attributeCode.','.$typeCode.' => '.$this->_attributeId[$typeCode][$attributeCode].PHP_EOL;
9117
- return $this->_attributeId[$typeCode][$attributeCode];
9118
- }
9119
  ##################################################################################################
9120
 
9121
- private function repl_ph($content,$hash){
9122
- if($hash){
9123
- foreach($hash as $key => $val){
9124
- if ($key=="category_name") {
9125
- if (strlen($val)>25) { $val = substr($val,0,24)."..."; }
9126
- }
9127
- $content = preg_replace("/%%%$key%%%/",$val,$content);
9128
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9129
  }
9130
- return $content;
9131
- }
9132
- ##################################################################################################
9133
 
9134
- private function _getProductAttributeId($attributeCode) {
9135
- return $this->_getAttributeId($attributeCode,'catalog_product');
9136
- }
 
 
9137
  ##################################################################################################
9138
 
9139
- private function _getCategoryAttributeId($attributeCode) {
9140
- return $this->_getAttributeId($attributeCode,'catalog_category');
9141
- }
9142
  ##################################################################################################
9143
- private function _getShopRootCategoryId($cat_id=0){
9144
- if($root_cat = Mage::app()->getStore()->getRootCategoryId()){
9145
- return $root_cat;
9146
- }else{
9147
- $q="SELECT
9148
- entity_id
9149
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')."
9150
- WHERE
9151
- value='default-category'";
9152
- $res=$this->db_do($q);
9153
- $row=mysqli_fetch_array($res);
9154
- if($row['entity_id']>0){
9155
- return $row['entity_id'];
9156
- }else{
9157
- $q="SELECT entity_id
9158
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
9159
- WHERE parent_id=".$cat_id;
9160
- $quer=$this->db_do($q);
9161
- $count=0;
9162
- while ($row=mysqli_fetch_array($quer)){
9163
- $count++;
9164
- $entity_id=$row['entity_id'];
9165
- }
9166
- if($count>1 || $count==0){
9167
- return ($cat_id);
9168
- }else{
9169
- return $this->_getShopRootCategoryId($entity_id);
9170
- }
9171
- }
9172
  }
9173
- }
9174
- ##################################################################################################
9175
- private function _cleanCateoryProductFlatTable(){
9176
- $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
9177
- $q='SHOW TABLES LIKE "'.Mage::getSingleton('core/resource')->getTableName('catalog_product_flat_').'%"';
9178
- $quer=$this->db_do($q);
9179
- $result=false;
9180
- While($row=mysqli_fetch_array($quer)){
9181
- if(is_array($row)){
9182
- $catalog_product_flat=array_pop($row);
9183
- $q='DELETE pf1 FROM '.$catalog_product_flat.' pf1
9184
- LEFT JOIN '.Mage::getSingleton('core/resource')->getTableName('catalog_product_entity').' p
9185
- ON pf1.entity_id = p.entity_id
9186
- WHERE p.entity_id IS NULL;';
9187
- $this->db_do($q);
9188
- $this->_LOG('cleaned wrong rows from '.$catalog_product_flat);
9189
- }
9190
  }
9191
- return $result;
9192
-
9193
- }
 
 
 
9194
  ##################################################################################################
9195
 
9196
 
 
9197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9198
 
 
 
9199
 
 
 
9200
  ##################################################################################################
9201
- public function checkMemory() {
9202
- $check_code = 'memory';
9203
-
9204
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9205
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9206
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9207
- $row = $result->fetch(PDO::FETCH_ASSOC);
9208
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9209
-
9210
-
9211
- $Caption = $row['caption'];
9212
- $CheckValue = $row['check_value'];
9213
- $CheckMeasure = $row['check_measure'];
9214
- $ErrorMessage = $row['error_msg'];
9215
- $FixMessage = $row['fix_msg'];
9216
-
9217
- $retvalue = array();
9218
- $retvalue["'$check_code'"] = array();
9219
-
9220
- $memInfoContent = file_get_contents("/proc/meminfo");
9221
- if($memInfoContent === false){
9222
- return array(
9223
- 'error',
9224
- $Caption,
9225
- $CheckValue,
9226
- 0,
9227
- $CheckMeasure,
9228
- 'Cannot read /proc/meminfo for RAM information',
9229
- 'Make sure open_basedir permits access to /proc/meminfo (or is off) and that this is a *nix system'
9230
- );
9231
- }
9232
- $data = explode("\n", $memInfoContent);
9233
-
9234
- foreach ($data as $line) {
9235
- $lineParts = explode(":", $line);
9236
- if(count($lineParts) < 2) continue;
9237
- list($key, $val) = $lineParts;
9238
-
9239
- if ($key == 'MemTotal') {
9240
- $val = trim($val);
9241
- $value = (int)substr($val, 0, strpos($val, ' kB'));
9242
- $measure = substr($val, strpos($val, ' kB'));
9243
-
9244
- $retvalue['memory']['value'] = (integer)(((float)$value)/1024); // (float)$value
9245
- $retvalue['memory']['measure'] = 'MB'; // $measure;
9246
- }
9247
- }
9248
-
9249
- $errmsg = '';
9250
- $fixmsg = '';
9251
- if ($retvalue['memory']['value'] <= $CheckValue) {
9252
- $errmsg = sprintf($ErrorMessage, $retvalue['memory']['value']); //." ".$retvalue['memory']['value']." ".$retvalue['memory']['measure'];
9253
- $fixmsg = sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
9254
- $retvalue['memory']['status'] = 'error';
9255
- } else {
9256
- $retvalue['memory']['status'] = 'OK';
9257
- }
9258
-
9259
- return array(
9260
- $retvalue['memory']['status'],
9261
- $Caption,
9262
- $CheckValue,
9263
- $retvalue['memory']['value'],
9264
- $CheckMeasure,
9265
- $errmsg,
9266
- $fixmsg
9267
- );
9268
- } // public function getImportEnvironment()
9269
- ##################################################################################################
9270
 
9271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9272
 
 
 
9273
 
9274
- ##################################################################################################
9275
- public function checkLoaddata() {
9276
- $check_code = 'loaddata';
9277
-
9278
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9279
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9280
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9281
- $row = $result->fetch(PDO::FETCH_ASSOC);
9282
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9283
-
9284
- $Caption = $row['caption'];
9285
- $CheckValue = $row['check_value'];
9286
- $CheckMeasure = $row['check_measure'];
9287
- $ErrorMessage = $row['error_msg'];
9288
- $FixMessage = $row['fix_msg'];
9289
-
9290
- $retvalue = array();
9291
- $retvalue["'$check_code'"] = array();
9292
-
9293
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9294
- $result = $conn->query("SHOW VARIABLES LIKE 'local_infile'");
9295
- $row = $result->fetch(PDO::FETCH_ASSOC);
9296
- $value = $row['Value'];
9297
-
9298
-
9299
- $errmsg = '';
9300
- $fixmsg = '';
9301
- if ($value != $CheckValue) {
9302
- $errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
9303
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9304
- $status = 'error';
9305
- } else {
9306
- $errmsg .= 'none';
9307
- $fixmsg .= 'none';
9308
- $status = 'OK';
9309
- }
9310
-
9311
- $ret = array();
9312
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9313
-
9314
- return $ret;
9315
- } // public function getImportEnvironment()
9316
  ##################################################################################################
9317
 
9318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9319
 
 
 
 
 
 
9320
 
 
 
 
 
 
 
 
 
 
 
9321
  ##################################################################################################
9322
- public function checkPhpsafemode() {
9323
- $check_code = 'phpsafemode';
9324
-
9325
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9326
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9327
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9328
- $row = $result->fetch(PDO::FETCH_ASSOC);
9329
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9330
-
9331
- $Caption = $row['caption'];
9332
- $CheckValue = $row['check_value'];
9333
- $CheckMeasure = $row['check_measure'];
9334
- $ErrorMessage = $row['error_msg'];
9335
- $FixMessage = $row['fix_msg'];
9336
-
9337
- $retvalue = array();
9338
- $retvalue["'$check_code'"] = array();
9339
-
9340
- $a = ini_get('safe_mode');
9341
- if ($a) {
9342
- $value = 'ON';
9343
- } else {
9344
- $value = 'OFF';
9345
- }
9346
-
9347
- $errmsg = '';
9348
- $fixmsg = '';
9349
- if ($value != $CheckValue) {
9350
- $errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
9351
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
9352
- $status = 'error';
9353
- } else {
9354
- $errmsg .= 'none';
9355
- $fixmsg .= 'none';
9356
- $status = 'OK';
9357
- }
9358
-
9359
- $ret = array();
9360
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9361
-
9362
- return $ret;
9363
- } // public function getImportEnvironment()
9364
  ##################################################################################################
9365
 
 
 
 
9366
 
 
 
 
 
 
9367
 
 
 
 
 
 
9368
 
9369
- ##################################################################################################
9370
- public function checkWaittimeout() {
9371
- $check_code = 'waittimeout';
9372
-
9373
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9374
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9375
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9376
- $row = $result->fetch(PDO::FETCH_ASSOC);
9377
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9378
-
9379
- $Caption = $row['caption'];
9380
- $CheckValue = $row['check_value'];
9381
- $CheckMeasure = $row['check_measure'];
9382
- $ErrorMessage = $row['error_msg'];
9383
- $FixMessage = $row['fix_msg'];
9384
-
9385
- $retvalue = array();
9386
- $retvalue["'$check_code'"] = array();
9387
-
9388
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9389
- $result = $conn->query("SHOW VARIABLES LIKE 'wait_timeout'");
9390
- $row = $result->fetch(PDO::FETCH_ASSOC);
9391
- $value = $row['Value'];
9392
-
9393
- $errmsg = '';
9394
- $fixmsg = '';
9395
- if ($value <= $CheckValue) {
9396
- $errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
9397
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue);
9398
- $status = 'error';
9399
- } else {
9400
- $errmsg .= 'none';
9401
- $fixmsg .= 'none';
9402
- $status = 'OK';
9403
- }
9404
-
9405
- $ret = array();
9406
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9407
-
9408
- return $ret;
9409
- } // public function getImportEnvironment()
9410
- ##################################################################################################
9411
 
 
9412
 
 
9413
 
 
 
 
9414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9415
  ##################################################################################################
9416
- public function checkInnodbbufferpoolsize() {
9417
- $check_code = 'innodbbufpool';
9418
-
9419
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9420
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9421
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9422
- $row = $result->fetch(PDO::FETCH_ASSOC);
9423
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9424
-
9425
- $Caption = $row['caption'];
9426
- $CheckValue = $row['check_value'];
9427
- $CheckMeasure = $row['check_measure'];
9428
- $ErrorMessage = $row['error_msg'];
9429
- $FixMessage = $row['fix_msg'];
9430
-
9431
- $retvalue = array();
9432
- $retvalue["'$check_code'"] = array();
9433
-
9434
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9435
- $result = $conn->query("SHOW VARIABLES LIKE 'innodb_buffer_pool_size'");
9436
- $row = $result->fetch(PDO::FETCH_ASSOC);
9437
- $value = (int)($row['Value']/(1024*1024));
9438
-
9439
- $errmsg = '';
9440
- $fixmsg = '';
9441
- if ($value < $CheckValue) {
9442
- $errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
9443
- $fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
9444
- $status = 'error';
9445
- } else {
9446
- $errmsg .= 'none';
9447
- $fixmsg .= 'none';
9448
- $status = 'OK';
9449
- }
9450
-
9451
- $ret = array();
9452
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9453
-
9454
- return $ret;
9455
- } // public function getImportEnvironment()
9456
  ##################################################################################################
9457
 
 
 
 
9458
 
 
 
 
 
 
9459
 
 
 
 
 
 
9460
 
9461
- ##################################################################################################
9462
- public function checkPhprunstring() {
9463
- $check_code = 'php5run';
9464
-
9465
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9466
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9467
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9468
- $row = $result->fetch(PDO::FETCH_ASSOC);
9469
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9470
-
9471
- $Caption = $row['caption'];
9472
- $CheckValue = $row['check_value'];
9473
- $CheckMeasure = $row['check_measure'];
9474
- $ErrorMessage = $row['error_msg'];
9475
- $FixMessage = $row['fix_msg'];
9476
-
9477
- $retvalue = array();
9478
- $retvalue["'$check_code'"] = array();
9479
-
9480
- $value = trim(PHP_RUN_STRING);
9481
- $errmsg = '';
9482
- $fixmsg = '';
9483
- $status = 'OK';
9484
-
9485
- if( !defined('PHP_RUN_STRING')){
9486
- $errmsg .= "You haven't installed PHP CLI";
9487
- $fixmsg .= "Install PHP CLI."; // ." ".$CheckValue." ".$CheckMeasure
9488
- $status = 'error';
9489
- }
9490
 
9491
- return array(
9492
- $status,
9493
- $Caption,
9494
- $CheckValue,
9495
- $value,
9496
- $CheckMeasure,
9497
- $errmsg,
9498
- $fixmsg
9499
- );
9500
- } // public function getImportEnvironment()
9501
- ##################################################################################################
9502
 
 
 
 
9503
 
 
 
 
 
 
 
 
 
 
 
 
 
9504
 
 
 
9505
 
 
 
9506
  ##################################################################################################
9507
- public function checkChmodwgetdatafile() {
9508
- $check_code = 'chmodwget';
9509
-
9510
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9511
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9512
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9513
- $row = $result->fetch(PDO::FETCH_ASSOC);
9514
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9515
-
9516
- $Caption = $row['caption'];
9517
- $CheckValue = $row['check_value'];
9518
- $CheckMeasure = $row['check_measure'];
9519
- $ErrorMessage = $row['error_msg'];
9520
- $FixMessage = $row['fix_msg'];
9521
-
9522
- $retvalue = array();
9523
- $retvalue["'$check_code'"] = array();
9524
-
9525
- $datafile_csv = '/usr/bin/wget';
9526
-
9527
- $value = substr(sprintf('%o', fileperms($datafile_csv)), -4);
9528
-
9529
- $CheckValue_own = $CheckValue{1};
9530
- $CheckValue_group = $CheckValue{2};
9531
- $CheckValue_other = $CheckValue{3};
9532
-
9533
- $value_own = $value{1};
9534
- $value_group = $value{2};
9535
- $value_other = $value{3};
9536
-
9537
- $errmsg = '';
9538
- $fixmsg = '';
9539
- //if ($value <= $CheckValue) {
9540
- if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9541
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9542
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9543
- $status = 'error';
9544
- } else {
9545
- $errmsg .= 'none';
9546
- $fixmsg .= 'none';
9547
- $status = 'OK';
9548
- }
9549
-
9550
- $ret = array();
9551
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9552
-
9553
- return $ret;
9554
- } // public function getImportEnvironment()
9555
  ##################################################################################################
9556
 
 
 
 
9557
 
 
 
 
 
 
9558
 
 
 
 
 
 
9559
 
9560
- ##################################################################################################
9561
- public function checkChmodwgetcronphpfile() {
9562
- $check_code = 'chmodcronphp';
9563
-
9564
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9565
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9566
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9567
- $row = $result->fetch(PDO::FETCH_ASSOC);
9568
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9569
-
9570
- $Caption = $row['caption'];
9571
- $CheckValue = $row['check_value'];
9572
- $CheckMeasure = $row['check_measure'];
9573
- $ErrorMessage = $row['error_msg'];
9574
- $FixMessage = $row['fix_msg'];
9575
-
9576
- $retvalue = array();
9577
- $retvalue["'$check_code'"] = array();
9578
-
9579
- $cronfile_php = Mage::getBaseDir().'/cron.php';
9580
-
9581
- $value = substr(sprintf('%o', fileperms($cronfile_php)), -4);
9582
-
9583
- $CheckValue_own = $CheckValue{1};
9584
- $CheckValue_group = $CheckValue{2};
9585
- $CheckValue_other = $CheckValue{3};
9586
-
9587
- $value_own = $value{1};
9588
- $value_group = $value{2};
9589
- $value_other = $value{3};
9590
-
9591
- $errmsg = '';
9592
- $fixmsg = '';
9593
- //if ($value <= $CheckValue) {
9594
- if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9595
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9596
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9597
- $status = 'error';
9598
- } else {
9599
- $errmsg .= 'none';
9600
- $fixmsg .= 'none';
9601
- $status = 'OK';
9602
- }
9603
-
9604
- $ret = array();
9605
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9606
-
9607
- return $ret;
9608
- } // public function checkChmodwgetcronphpfile()
9609
- ##################################################################################################
9610
 
 
9611
 
 
9612
 
 
 
 
9613
 
9614
- ##################################################################################################
9615
- public function checkChmodwgetcronshfile() {
9616
- $check_code = 'chmodcronsh';
9617
-
9618
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9619
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9620
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9621
- $row = $result->fetch(PDO::FETCH_ASSOC);
9622
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9623
-
9624
- $Caption = $row['caption'];
9625
- $CheckValue = $row['check_value'];
9626
- $CheckMeasure = $row['check_measure'];
9627
- $ErrorMessage = $row['error_msg'];
9628
- $FixMessage = $row['fix_msg'];
9629
-
9630
- $retvalue = array();
9631
- $retvalue["'$check_code'"] = array();
9632
-
9633
- $cronfile_sh = Mage::getBaseDir().'/cron.sh';
9634
-
9635
- $value = substr(sprintf('%o', fileperms($cronfile_sh)), -4);
9636
-
9637
- $CheckValue_own = $CheckValue{1};
9638
- $CheckValue_group = $CheckValue{2};
9639
- $CheckValue_other = $CheckValue{3};
9640
-
9641
- $value_own = $value{1};
9642
- $value_group = $value{2};
9643
- $value_other = $value{3};
9644
-
9645
- $errmsg = '';
9646
- $fixmsg = '';
9647
- //if ($value <= $CheckValue) {
9648
- if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9649
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9650
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9651
- $status = 'error';
9652
- } else {
9653
- $errmsg .= 'none';
9654
- $fixmsg .= 'none';
9655
- $status = 'OK';
9656
- }
9657
-
9658
- $ret = array();
9659
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9660
-
9661
- return $ret;
9662
- } // public function checkChmodwgetcronphpfile()
9663
- ##################################################################################################
9664
 
 
 
 
 
 
 
 
 
 
 
 
 
9665
 
 
 
9666
 
 
 
9667
 
9668
- ##################################################################################################
9669
- public function checkProcedure() {
9670
- $check_code = 'routine';
9671
-
9672
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9673
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9674
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9675
- $row = $result->fetch(PDO::FETCH_ASSOC);
9676
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9677
-
9678
- $Caption = $row['caption'];
9679
- $CheckValue = $row['check_value'];
9680
- $CheckMeasure = $row['check_measure'];
9681
- $ErrorMessage = $row['error_msg'];
9682
- $FixMessage = $row['fix_msg'];
9683
-
9684
- $retvalue = array();
9685
- $retvalue["'$check_code'"] = array();
9686
-
9687
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9688
- $storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
9689
- $result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
9690
- $row = $result->fetch(PDO::FETCH_ASSOC);
9691
- $value = $row['Name'];
9692
-
9693
- $errmsg = '';
9694
- $fixmsg = '';
9695
- if ($value != $CheckValue) {
9696
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9697
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9698
- $status = 'error';
9699
- } else {
9700
- $errmsg .= 'none';
9701
- $fixmsg .= 'none';
9702
- $status = 'OK';
9703
- }
9704
-
9705
- $ret = array();
9706
- array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9707
-
9708
- return $ret;
9709
- } // public function getImportEnvironment()
9710
- ##################################################################################################
9711
 
 
 
9712
 
 
 
9713
 
 
9714
 
9715
- ##################################################################################################
9716
- public function checkConflictsWithInstalledModules() {
9717
- $check_code = 'conflictwithinstalledmodules';
9718
-
9719
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9720
- $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9721
- $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9722
- $row = $result->fetch(PDO::FETCH_ASSOC);
9723
- //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9724
-
9725
- $Caption = $row['caption'];
9726
- $CheckValue = $row['check_value'];
9727
- $CheckMeasure = $row['check_measure'];
9728
- $ErrorMessage = $row['error_msg'];
9729
- $FixMessage = $row['fix_msg'];
9730
-
9731
- $retvalue = array();
9732
- $retvalue["'$check_code'"] = array();
9733
-
9734
- /* $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9735
- $storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
9736
- $result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
9737
- $row = $result->fetch(PDO::FETCH_ASSOC);
9738
- $value = $row['Name'];
9739
  */
9740
  $config_file = (Mage::app()->getConfig()->getNode()->asXML());
9741
-
9742
- $errmsg = $ErrorMessage;
9743
- $fixmsg = $FixMessage;
9744
- /*
9745
- if ($value != $CheckValue) {
9746
- $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9747
- $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9748
- $status = 'error';
9749
- */
9750
  $status = 'OK';
9751
 
9752
  if (!strstr($config_file, '<image>Bintime_Sinchimport_Helper_Image</image>')) {
9753
- $errmsg .= " Can't find <image>Bintime_Sinchimport_Helper_Image</image> in <helpers><catalog></catalog></helpers>"; // ." ".$value." ".$CheckMeasure
9754
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9755
  $status = 'error';
9756
  }
9757
 
9758
  if (!strstr($config_file, '<product_image>Bintime_Sinchimport_Model_Image</product_image>')) {
9759
- $errmsg .= " Can't find <product_image>Bintime_Sinchimport_Model_Image</product_image> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
9760
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9761
  $status = 'error';
9762
  }
9763
 
9764
  if (!strstr($config_file, '<category>Bintime_Sinchimport_Model_Category</category>')) {
9765
- $errmsg .= " Can't find <category>Bintime_Sinchimport_Model_Category</category> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
9766
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9767
  $status = 'error';
9768
  }
9769
 
9770
  if (!strstr($config_file, '<product_compare_list>Bintime_Sinchimport_Block_List</product_compare_list>')) {
9771
- $errmsg .= " Can't find <product_compare_list>Bintime_Sinchimport_Block_List</product_compare_list> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
9772
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9773
  $status = 'error';
9774
  }
9775
 
9776
  if (!strstr($config_file, '<product_view_media>Bintime_Sinchimport_Block_Product_View_Media</product_view_media>')) {
9777
- $errmsg .= " Can't find <product_view_media>Bintime_Sinchimport_Block_Product_View_Media</product_view_media> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
9778
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9779
  $status = 'error';
9780
  }
9781
 
9782
  if (!strstr($config_file, '<product>Bintime_Sinchimport_Model_Product</product>')) {
9783
- $errmsg .= " Can't find <product>Bintime_Sinchimport_Model_Product</product> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
9784
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9785
  $status = 'error';
9786
  }
9787
 
9788
  if (!strstr($config_file, '<layer_filter_price>Bintime_Sinchimport_Model_Layer_Filter_Price</layer_filter_price>')) {
9789
- $errmsg .= " Can't find <layer_filter_price>Bintime_Sinchimport_Model_Layer_Filter_Price</layer_filter_price> in <models><catalog></catalog><models>"; // ." ".$value." ".$CheckMeasure
9790
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9791
  $status = 'error';
9792
  }
9793
 
9794
  if (!strstr($config_file, '<layer_view>Bintime_Sinchimport_Block_Layer_View</layer_view>')) {
9795
- $errmsg .= " Can't find <layer_view>Bintime_Sinchimport_Block_Layer_View</layer_view> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
9796
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9797
  $status = 'error';
9798
  }
9799
 
9800
  if (!strstr($config_file, '<layer>Bintime_Sinchimport_Model_Layer</layer>')) {
9801
- $errmsg .= " Can't find <layer>Bintime_Sinchimport_Model_Layer</layer> in <models><catalog></catalog><models>"; // ." ".$value." ".$CheckMeasure
9802
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9803
  $status = 'error';
9804
  }
9805
 
9806
  if (!strstr($config_file, '<layer_filter_price>Bintime_Sinchimport_Model_Resource_Layer_Filter_Price</layer_filter_price>')) {
9807
- $errmsg .= " Can't find <layer_filter_price>Bintime_Sinchimport_Model_Resource_Layer_Filter_Price</layer_filter_price> in <models><catalog_resource_eav_mysql4></catalog_resource_eav_mysql4></models>"; // ." ".$value." ".$CheckMeasure
9808
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
9809
  $status = 'error';
9810
  }
9811
 
9812
 
9813
- if ($status == 'OK'){
9814
  $errmsg = 'none';
9815
  $fixmsg = 'none';
9816
  }
9817
- return array(
9818
- $status,
9819
- $Caption,
9820
- $CheckValue,
9821
- '',
9822
- $CheckMeasure,
9823
- $errmsg,
9824
- $fixmsg
9825
- );
9826
- } // public function getImportEnvironment()
9827
- ##################################################################################################
9828
-
9829
 
 
9830
 
9831
- ##################################################################################################
9832
- public function getSinchDistribotorsTableHtml($entity_id=null) {
9833
- /*/ Load the collection
9834
  $collection = getResourceModel('sales/order_grid_collection');
9835
 
9836
  // Add custom data
@@ -9838,17 +10177,17 @@ STP DELETE*/
9838
 
9839
  // Set the collection
9840
  $this->setCollection($collection);
9841
- // return parent::_prepareCollection();
9842
  */
9843
- if(!$entity_id){
9844
- $entity_id = Mage::registry('current_product')->getId();
9845
- }
9846
- if (!$entity_id){
9847
  return '';
9848
- }
9849
-
9850
- $distributors_stock_price = $this->getDistributorStockPriceByProductid($entity_id);
9851
- $distributors_table = '
9852
  <table>
9853
  <thead>
9854
  <tr class="headings">
@@ -9859,19 +10198,19 @@ STP DELETE*/
9859
  </thead>
9860
  <tbody>';
9861
  $i = 1;
9862
- foreach($distributors_stock_price as $offer){
9863
- if ($i > 0){
9864
  $class = "even pointer";
9865
  $i = 0;
9866
- }else{
9867
  $class = "pointer";
9868
  $i = 1;
9869
  }
9870
  $distributors_table .= '
9871
- <tr class="'.$class.'">
9872
- <td nowrap style="font-weight: normal">'.$offer['distributor_name'].'</td>
9873
- <td style="font-weight: normal">'.$offer['stock'].'</td>
9874
- <td style="font-weight: normal">'.Mage::helper('core')->currency($offer['cost']).'</td>
9875
  </tr>';
9876
  }
9877
  $distributors_table .= '
@@ -9880,80 +10219,48 @@ STP DELETE*/
9880
  ';
9881
  return $distributors_table;
9882
  }
9883
- ##################################################################################################
9884
-
9885
 
 
9886
 
9887
-
9888
- ##################################################################################################
9889
- private function getDistributorStockPriceByProductid($entity_id) {
9890
- $store_product_id=$this->getStoreProductIdByEntity($entity_id);
9891
- if(!$store_product_id){
9892
- // echo "AAAAAAA"; exit;
9893
  return;
9894
- }
9895
- $q="SELECT
9896
  d.distributor_name,
9897
  d.website,
9898
- dsp.stock,
9899
  dsp.cost,
9900
  dsp.distributor_sku,
9901
  dsp.distributor_category,
9902
  dsp.eta
9903
- FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price')." dsp
9904
- JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors')." d
9905
  ON dsp.distributor_id = d.distributor_id
9906
- WHERE store_product_id =".$store_product_id;
9907
- $quer=$this->db_do($q);
9908
  $offers = null;
9909
- while($row = mysqli_fetch_array($quer)){
9910
- $offers[]=$row;
9911
  }
9912
  return $offers;
9913
-
9914
- }
9915
- #################################################################################################
9916
 
9917
- private function get_all_children_cat($entity_id){
9918
- $children_cat = "'" . $entity_id . "'" . $this->get_all_children_cat_recursive($entity_id);
9919
- return ($children_cat);
9920
  }
9921
- #################################################################################################
9922
-
9923
- private function get_all_children_cat_recursive($entity_id) {
9924
- $q="SELECT entity_id
9925
- FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
9926
- WHERE parent_id=".$entity_id;
9927
- $quer=$this->db_do($q);
9928
- $children_cat='';
9929
- while ($row=mysqli_fetch_array($quer)){
9930
- $children_cat .= ", '".$row['entity_id']."'";
9931
- $children_cat .= $this->get_all_children_cat_recursive($row['entity_id']);
9932
- }
9933
- return ($children_cat);
9934
- }
9935
- #################################################################################################
9936
-
9937
- private function check_table_exist($table){
9938
-
9939
- $q="SHOW TABLES LIKE \"%".Mage::getSingleton('core/resource')->getTableName($table)."%\"";
9940
- // echo $q;
9941
- $quer=$this->db_do($q);
9942
- $i=0;
9943
- while ($row=mysqli_fetch_array($quer)){
9944
- $i++;
9945
  }
9946
- return ($i);
9947
- }
9948
- #################################################################################################
9949
 
9950
- private function _set_default_root_category(){
9951
- $q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('core_store_group')." csg
9952
- LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
9953
- ON csg.root_category_id = cce.entity_id
9954
- SET csg.root_category_id=(SELECT entity_id FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." WHERE parent_id = 1 LIMIT 1)
9955
- WHERE csg.root_category_id > 0 AND cce.entity_id IS NULL";
9956
- $this->db_do($q);
9957
  }
9958
-
9959
  } // class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract
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
+ {
9
  var
10
+ $connection,
11
+ $varDir,
12
+ $shellDir,
13
+ $files,
14
+ $attributes,
15
+ $db,
16
+ $lang_id,
17
+ $debug_mode = 1;
18
+ public $php_run_string;
19
+ public $php_run_strings;
20
+ public $price_breaks_filter;
21
  private $productDescriptionList = array();
22
  private $specifications;
23
  private $productDescription;
25
  private $lowPicUrl;
26
  private $highPicUrl;
27
  private $errorMessage;
28
+ private $galleryPhotos = array(); //depricated
29
  private $productName;
30
  private $relatedProducts = array();
31
+ private $errorSystemMessage;
32
  private $sinchProductId;
33
  private $_productEntityTypeId = 0;
34
  private $defaultAttributeSetId = 0;
42
  private $_categoryDefault_attribute_set_id;
43
  private $_root_cat;
44
  private $import_run_type = 'MANUAL';
45
+ private $_ignore_category_features = false;
46
+ private $_ignore_product_features = false;
47
+ private $_ignore_product_related = false;
48
  private $_ignore_product_categories = false;
49
+ private $_ignore_product_contracts = false;
50
+ private $_ignore_price_rules = false;
51
  private $product_file_format = "NEW";
52
+ private $_ignore_restricted_values = false;
53
  private $_categoryMetaTitleAttrId;
54
  private $_categoryMetadescriptionAttrId;
55
  private $_categoryDescriptionAttrId;
56
+ private $im_type;
 
 
 
 
 
 
 
57
 
58
  #################################################################################################
59
 
60
+ function __construct()
61
+ {
62
 
63
+ $this->import_status_table = Mage::getSingleton('core/resource')->getTableName('stINch_import_status');
64
+ $this->import_status_statistic_table = Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic');
65
+ $this->import_log_table = "stINch_import_log";
66
 
67
+ $this->php_run_string = PHP_RUN_STRING;
68
+ $this->php_run_strings = PHP_RUN_STRINGS;
69
 
70
+ $this->price_breaks_filter = PRICE_BREAKS;
71
  /*$this->db_connect();
72
  $res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
73
  $row = mysqli_fetch_assoc($res);
75
  */
76
  $this->varDir = TEMPORARY_DIRECTORY_FOR_STORING_FILES;
77
  $this->shellDir = SHELL_DIRECTORY_FOR_INDEXER;
78
+ $this->connection = $this->db_connect();
79
  $this->createTemporaryImportDerictory();
80
+ $this->_logFile = "Sinch.log";
81
+ $this->_LOG("constructor");
82
+ $this->files = array(
83
+ FILE_CATEGORIES,
84
+ FILE_CATEGORY_TYPES,
85
+ FILE_CATEGORIES_FEATURES,
86
+ FILE_DISTRIBUTORS,
87
+ FILE_DISTRIBUTORS_STOCK_AND_PRICES,
88
+ FILE_EANCODES,
89
+ FILE_MANUFACTURERS,
90
+ FILE_PRODUCT_FEATURES,
91
+ FILE_PRODUCT_CATEGORIES,
92
+ FILE_PRODUCTS,
93
+ FILE_RELATED_PRODUCTS,
94
+ FILE_RESTRICTED_VALUES,
95
+ FILE_STOCK_AND_PRICES,
96
+ FILE_PRODUCTS_PICTURES_GALLERY,
97
+ FILE_PRICE_RULES,
98
+ FILE_PRODUCT_CONTRACTS
99
+ );
100
+ $this->attributes['manufacturer'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
101
+ $this->attributes['name'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
102
+ $this->attributes['is_active'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('is_active')->getFirstItem()->getId();
103
+ $this->attributes['include_in_menu'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('include_in_menu')->getFirstItem()->getId();
104
+ $this->attributes['url_key'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('url_key')->getFirstItem()->getId();
105
+ $this->attributes['display_mode'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('display_mode')->getFirstItem()->getId();
106
+ $this->attributes['status'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('status')->getFirstItem()->getId();
107
+ $this->attributes['visibility'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('visibility')->getFirstItem()->getId();
108
+ $this->attributes['price'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('price')->getFirstItem()->getId();
109
+ $this->attributes['cost'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('cost')->getFirstItem()->getId();
110
+ $this->attributes['weight'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('weight')->getFirstItem()->getId();
111
+ $this->attributes['tax_class_id'] = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('tax_class_id')->getFirstItem()->getId();
112
 
113
  $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
114
  // if($dataConf['field_terminated_char']){
115
+ // $this->field_terminated_char=$dataConf['field_terminated_char'];
116
+ // }else{
117
+ $this->field_terminated_char = DEFAULT_FILE_TERMINATED_CHAR;
118
  // }
119
+ // $attributeOptions = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getSource()->getAllOptions(false);
120
  // echo "<pre>"; print_r($attributeOptions); echo "</pre>";
121
  }
122
 
123
  #################################################################################################
 
 
 
 
 
124
 
125
+ private function db_connect()
126
+ {
127
+ // $connection = Mage::getModel('core/resource')->getConnection('core_write');
128
+ $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
129
+ $dbConn = mysqli_init();
130
+ mysqli_options($dbConn, MYSQLI_OPT_LOCAL_INFILE, true);
131
+ if (mysqli_real_connect($dbConn, $dbConf->host, $dbConf->username, $dbConf->password)) {
132
+ $this->db = $dbConn;
133
+ if (!mysqli_select_db($this->db, $dbConf->dbname)) {
134
+ die("Can't select the database: " . mysqli_error($this->db));
135
+ }
136
+ } else {
137
+ die("Could not connect: " . mysqli_error($this->db));
138
  }
139
 
 
 
140
  }
141
+
142
  ################################################################################################
143
+
144
+ /**
145
+ * Create the import directory Hierarchy
146
+ * @return false if directory already exists
147
+ */
148
+ public function createTemporaryImportDerictory()
149
+ {
150
+ $dirArray = explode('/', $this->varDir);
151
+ end($dirArray);
152
+ // $this->_LOG('before :'.$this->varDir);
153
+ if (prev($dirArray) == 'bintime') {
154
+ return false;
155
+ }
156
+
157
+
158
+ $this->varDir = $this->varDir . 'bintime/sinchimport/';
159
+ if (!is_dir($this->varDir)) {
160
+ mkdir($this->varDir, 0777, true);
161
+ }
162
+ // $this->_LOG('after :'.$this->varDir);
163
  }
164
+
165
  ################################################################################################
166
+
167
+ function _LOG($log)
168
+ {
169
+
170
+ if ($log) {
171
+ // $q="insert into ".$this->import_log_table." (message_date, message) values(now(), '".$log."')";
172
+ // $this->db_do($q);
173
+ Mage::log($log, null, $this->_logFile);
174
+ // list($usec, $sec) = explode(" ", microtime());
175
+ // $time = ((float)$usec + (float)$sec);
176
+ /* $time = date("D M j G:i:s T Y");
177
+
178
+ if($_SERVER['REMOTE_ADDR']){
179
+ $log = "[".getmypid()."] "."[".$_SERVER['REMOTE_ADDR']."] "."[".$time."] ".$log."\n";
180
+ error_log($log,3,LOG_FILE);
181
+ }else{
182
+ $log = "[".getmypid()."] "."[".$time."] ".$log."\n";
183
+ error_log($log,3,LOG_FILE . ".cli");
184
+ */
 
 
185
  }
 
186
  }
187
+
188
  #################################################################################################
189
+
190
+ function cron_start_import()
191
+ {
192
+ $this->_LOG("Start import from cron");
193
+ $start_hr = Mage::getStoreConfig('sinchimport_root/sinch_cron/sinch_cron_time');
194
+ $now_hr = date('H');
195
+ $this->_LOG("Now $now_hr hr, scheduler time is $start_hr hr");
196
+
197
+ if ($start_hr == $now_hr) {
198
+ $this->run_sinch_import();
199
+ } else {
200
+ $this->_LOG(" it's NOT time for SINCH ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  }
202
+
203
+ $this->_LOG("Finish import from cron");
204
+
205
  }
206
+
207
+ #################################################################################################
208
+
209
+ function run_sinch_import()
210
+ {
211
+
212
+ $this->_categoryMetaTitleAttrId = $this->_getCategoryAttributeId('meta_title');
213
  $this->_categoryMetadescriptionAttrId = $this->_getCategoryAttributeId('meta_description');
214
+ $this->_categoryDescriptionAttrId = $this->_getCategoryAttributeId('description');
215
 
216
  $safe_mode_set = ini_get('safe_mode');
217
 
218
  $this->InitImportStatuses('FULL');
219
+ if ($safe_mode_set) {
220
+ $this->_LOG('safe_mode is enable. import stoped.');
221
+ $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
222
  exit;
223
+ }
224
+ $store_proc = $this->check_store_procedure_exist();
225
 
226
+ if (!$store_proc) {
227
+ $this->_LOG('store prcedure "' . Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s') . '" is absent in this database. import stoped.');
228
+ $this->set_import_error_reporting_message('Stored procedure "' . Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s') . '" is absent in this database. Import stopped.');
229
+ exit;
230
  }
231
 
232
+ $file_privileg = $this->check_db_privileges();
233
 
234
+ if (!$file_privileg) {
235
  $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
236
  $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
237
+ exit;
238
  }
239
+ $local_infile = $this->check_local_infile();
240
+ if (!$local_infile) {
241
  $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'");
242
  $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
243
  exit;
244
  }
245
+ //STP TEST
246
  //$this->ApplyCustomerGroupPrice();
247
  //echo $children_cat=$this->get_all_children_cat(6);
 
248
 
249
 
250
+ if ($this->is_imort_not_run()) {
251
+ try {
252
  //$this->InitImportStatuses();
253
+ $q = "SELECT GET_LOCK('sinchimport', 30)";
254
+ $quer = $this->db_do($q);
255
+ $import = $this;
256
  $import->addImportStatus('Start Import');
257
  echo "Upload Files <br>";
258
  $import->UploadFiles();
268
 
269
  //$import->_cleanCateoryProductFlatTable();
270
  //$import->runIndexer();
271
+ //echo("\n\n\n==================RETURN=================\n\n\n");
272
 
273
 
274
  echo "Parse Category Features <br>";
278
 
279
  echo "Parse Distributors <br>";
280
  $import->ParseDistributors();
281
+ if ($this->product_file_format == "NEW") {
282
  $this->ParseDistributorsStockAndPrice();
283
+ $this->ParseProductContracts();
284
  }
285
  $import->addImportStatus('Parse Distributors');
286
 
298
  $import->addImportStatus('Parse Related Products');
299
 
300
 
 
301
  echo "Parse Product Features <br>";
302
  $import->ParseProductFeatures();
303
  $import->addImportStatus('Parse Product Features');
324
  echo "Parse Stock And Prices <br>";
325
  $import->ParseStockAndPrices();
326
  $import->addImportStatus('Parse Stock And Prices');
327
+
328
  echo "Apply Customer Group Price <br>";
329
  //$import->ParsePriceRules();
330
  //$import->AddPriceRules();
331
  //$import->ApplyCustomerGroupPrice();
332
 
333
+ if (file_exists($this->varDir . FILE_PRICE_RULES)) {
334
+ $ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
335
+ Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
336
+ 'ftp_host' => $ftpCred["ftp_server"],
337
+ 'ftp_username' => $ftpCred["login"],
338
+ 'ftp_password' => $ftpCred["password"]
339
+ ));
340
  }
341
 
342
 
351
  if ($indexProcess) {
352
  $indexProcess->reindexAll();
353
  }
354
+ */
355
 
356
  Mage::log("Start indexing Sinch features for filters", null, $this->_logFile);
357
  echo "Start indexing Sinch features for filters<br>";
358
 
 
359
  $resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
360
+ // Toàn Handsome thêm đoạn mã này
361
+ $resource->dropFeatureResultTables();
362
 
363
  Mage::log("Finish indexing Sinch features for filters", null, $this->_logFile);
364
  $import->addImportStatus('Generate category filters');
373
  $import->addImportStatus('Indexing data', 1);
374
  echo "Finish indexing data";
375
 
376
+ $q = "SELECT RELEASE_LOCK('sinchimport')";
377
+ $quer = $this->db_do($q);
378
+ } catch (Exception $e) {
379
  $this->set_import_error_reporting_message($e);
380
  }
381
+ } else {
 
382
  Mage::log("Sinchimport already run", null, $this->_logFile);
383
  echo "Sinchimport already run<br>";
384
 
385
  }
386
 
387
+ }
388
+
389
  #################################################################################################
 
 
390
 
391
+ private function _getCategoryAttributeId($attributeCode)
392
+ {
393
+ return $this->_getAttributeId($attributeCode, 'catalog_category');
394
+ }
 
 
 
395
 
396
+ #################################################################################################
397
+
398
+ private function _getAttributeId($attributeCode, $typeCode)
399
+ {
400
+ if ($typeCode == 'catalog_product') {
401
+ $typeId = $this->_getProductEntityTypeId();
402
+ } else {
403
+ $typeId = $this->_getEntityTypeId($typeCode);
404
  }
405
+ if (!isset($this->_attributeId[$typeCode]) OR !is_array($this->_attributeId[$typeCode])) {
406
+ $sql = "
407
+ SELECT attribute_id, attribute_code
408
+ FROM " . Mage::getSingleton('core/resource')->getTableName('eav_attribute') . "
409
+ WHERE entity_type_id = '" . $typeId . "'
410
+ ";
411
+ $result = $this->db_do($sql);
412
+ while ($row = mysqli_fetch_assoc($result)) {
413
+ $this->_attributeId[$typeCode][$row['attribute_code']] = $row['attribute_id'];
414
+ }
415
+ }
416
+ // echo 'attribute code: '.$attributeCode.','.$typeCode.' => '.$this->_attributeId[$typeCode][$attributeCode].PHP_EOL;
417
+ return $this->_attributeId[$typeCode][$attributeCode];
418
+ }
419
 
420
+ #################################################################################################
421
 
422
+ private function _getProductEntityTypeId()
423
+ {
424
+ if (!$this->_productEntityTypeId) {
425
+ $this->_productEntityTypeId = $this->_getEntityTypeId('catalog_product');
426
  }
427
+ return $this->_productEntityTypeId;
428
+ }
429
+
430
+ #################################################################################################
431
+
432
+ private function _getEntityTypeId($code)
433
+ {
434
+ $sql = "
435
+ SELECT entity_type_id
436
+ FROM " . Mage::getSingleton('core/resource')->getTableName('eav_entity_type') . "
437
+ WHERE entity_type_code = '" . $code . "'
438
+ LIMIT 1
439
+ ";
440
+ $result = $this->db_do($sql);
441
+ if ($row = mysqli_fetch_assoc($result)) {
442
+ return $row['entity_type_id'];
443
  }
444
+ return false;
445
+ }
446
 
447
+ #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
448
 
449
+ private function db_do($query)
450
+ {
451
+ if ($this->debug_mode) {
452
+ Mage::log("Query: " . $query, null, $this->_logFile);
453
+ }
454
+ $result = mysqli_query($this->db, $query) or die("Query failed: " . mysqli_error($this->db));
455
+ if (!$result) {
456
+ throw new Exception("Invalid query: $sql\n" . mysqli_error($this->db));
457
+ } else {
458
+ return $result;
459
+ }
460
+ return $result;
461
+ }
462
 
463
+ #################################################################################################
 
 
 
464
 
465
+ function InitImportStatuses($type)
466
+ {
467
+ $this->db_do("DROP TABLE IF EXISTS " . $this->import_status_table);
468
+ $this->db_do("CREATE TABLE " . $this->import_status_table . "(
469
+ id int(11) NOT NULL auto_increment PRIMARY KEY,
470
+ message varchar(50),
471
+ finished int(1) default 0
472
+ )"
473
+ );
474
+ $this->db_do("INSERT INTO " . $this->import_status_statistic_table . " (
475
+ start_import,
476
+ finish_import,
477
+ import_type,
478
+ global_status_import,
479
+ import_run_type,
480
+ error_report_message)
481
+ VALUES(
482
+ now(),
483
+ NULL,
484
+ '$type',
485
+ 'Run',
486
+ '" . $this->import_run_type . "',
487
+ ''
488
+ )
489
+ ");
490
+ $q = "SELECT MAX(id) AS id FROM " . $this->import_status_statistic_table;
491
 
492
+ $quer = $this->db_do($q);
493
+ $row = mysqli_fetch_array($quer);
494
+ $this->current_import_status_statistic_id = $row['id'];
495
+ $this->db_do("UPDATE " . $this->import_status_statistic_table . "
496
+ SET global_status_import='Failed'
497
+ WHERE global_status_import='Run' AND id!=" . $this->current_import_status_statistic_id);
498
 
499
+ }
500
+ #################################################################################################
501
 
 
 
502
 
503
+ ################################################################################################################################################################
 
 
 
 
 
 
 
504
 
505
+ function set_import_error_reporting_message($message)
506
+ {
507
+ $this->db_do("UPDATE " . $this->import_status_statistic_table . "
508
+ SET error_report_message='" . mysqli_real_escape_string($this->db, $message) . "'
509
+ WHERE id=" . $this->current_import_status_statistic_id);
510
+ } // function ParseCategories()
511
+ ################################################################################################################################################################
512
+
513
+
514
+ ################################################################################################################################################################
515
+
516
+ function check_store_procedure_exist()
517
+ {
518
+ $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
519
+ $q = 'SHOW PROCEDURE STATUS LIKE "' . Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s') . '"';
520
+ $quer = $this->db_do($q);
521
+ $result = false;
522
+ While ($row = mysqli_fetch_array($quer)) {
523
+ if (($row['Name'] == Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s')) && ($row['Db'] == $dbConf->dbname)) {
524
+ $result = true;
525
  }
526
  }
527
+ return $result;
528
+ } // private function loadCategoriesTemp()
529
+ ################################################################################################################################################################
530
+
531
+
532
+ ################################################################################################################################################################
533
+
534
+ function check_db_privileges()
535
+ {
536
+ $q = 'SHOW PRIVILEGES';
537
+ $quer = $this->db_do($q);
538
+ while ($row = mysqli_fetch_array($quer)) {
539
+ if ($row['Privilege'] == 'File' && $row['Context'] == 'File access on server') {
540
+ return true;
541
  }
542
  }
543
+ return false;
544
  }
545
+ ################################################################################################################################################################
546
+
547
+
548
+ ################################################################################################################################################################
549
+
550
+ function check_local_infile()
551
+ {
552
+ $q = 'SHOW VARIABLES LIKE "local_infile"';
553
+ $quer = $this->db_do($q);
554
+ $row = mysqli_fetch_array($quer);
555
+ if ($row['Variable_name'] == 'local_infile' && $row['Value'] == "ON") {
556
+ return true;
557
+ } else {
558
+ return false;
559
+ }
560
+ } // private function addCategoryDataMultistoreMerge(...)
561
+ ################################################################################################################################################################
562
+
563
+
564
+ ################################################################################################################################################################
565
+
566
+ function is_imort_not_run()
567
+ {
568
+ $q = "SELECT IS_FREE_LOCK('sinchimport') as getlock";
569
+ $quer = $this->db_do($q);
570
+ $row = mysqli_fetch_array($quer);
571
+ return $row['getlock'];
572
+ } // private function deleteOldSinchCategoriesFromShopMerge()
573
+ ################################################################################################################################################################
574
+
575
+
576
+ ################################################################################################################################################################
577
+
578
+ function addImportStatus($message, $finished = 0)
579
+ {
580
+ $q = "INSERT INTO " . $this->import_status_table . "
581
+ (message, finished)
582
+ VALUES('" . $message . "', $finished)";
583
+ $this->db_do($q);
584
+ $this->db_do("UPDATE " . $this->import_status_statistic_table . "
585
+ SET detail_status_import='" . $message . "'
586
+ WHERE id=" . $this->current_import_status_statistic_id);
587
+ if ($finished == 1) {
588
+ $this->db_do("UPDATE " . $this->import_status_statistic_table . "
589
+ SET
590
+ global_status_import='Successful',
591
+ finish_import=now()
592
+ WHERE
593
+ error_report_message='' and
594
+ id=" . $this->current_import_status_statistic_id);
595
+ }
596
+ } // public function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
597
+ ################################################################################################################################################################
598
 
599
 
600
+ ################################################################################################################################################################
601
 
602
+ function UploadFiles()
603
+ {
604
  $this->_LOG("Start upload files");
605
  $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
606
+ $login = $dataConf['login'];
607
+ $passw = $dataConf['password'];
608
+ $server = $dataConf['ftp_server'];
609
 
610
  //return;//stepan tes//stepan tes//stepan testtt
611
+ if (!$login || !$passw) {
612
  $this->_LOG('ftp login or password dosent defined');
613
  $this->set_import_error_reporting_message('FTP login or password has not been defined. Import stopped.');
614
  exit;
615
 
616
  }
617
+ $file_url_and_dir = $this->repl_ph(FILE_URL_AND_DIR, array(
618
+ 'server' => $server,
619
+ 'login' => $login,
620
+ 'password' => $passw
621
+ )
622
+ );
623
  foreach ($this->files as $file) {
624
+ $this->_LOG("Copy " . $file_url_and_dir . $file . " to " . $this->varDir . $file);
625
+ if (strstr($file_url_and_dir, 'ftp://')) {
626
  preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
627
+ //var_dump($match);
628
+ if ($conn = ftp_connect($match[3])) {
629
+ if (!ftp_login($conn, $login, $passw)) {
630
+ $this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
631
+ exit;
632
+ }
633
+ } else {
634
+ $this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
635
  exit;
636
  }
637
+ if (!$this->wget($file_url_and_dir . $file, $this->varDir . $file, 'system')) {
638
+ $this->_LOG("wget Can't copy " . $file . ", will use old one");
639
+ echo "copy Can't copy " . $file_url_and_dir . $file . " to " . $this->varDir . $file . ", will use old one<br>";
640
+ }
641
+ } else {
642
+ if (!copy($file_url_and_dir . $file, $this->varDir . $file)) {
643
+ $this->_LOG("copy Can't copy " . $file . ", will use old one");
644
+ echo "copy Can't copy " . $file_url_and_dir . $file . " to " . $this->varDir . $file . " will use old one<br>";
 
 
 
 
 
 
645
  }
646
  }
647
+ exec("chmod a+rw " . $this->varDir . $file);
648
+ if (!filesize($this->varDir . $file)) {
649
+ if ($file != FILE_CATEGORIES_FEATURES && $file != FILE_PRODUCT_FEATURES && $file != FILE_RELATED_PRODUCTS && $file != FILE_RESTRICTED_VALUES && $file != FILE_PRODUCT_CATEGORIES && $file != FILE_CATEGORY_TYPES && $file != FILE_DISTRIBUTORS_STOCK_AND_PRICES && $file != FILE_PRODUCT_CONTRACTS && $file != FILE_PRICE_RULES) {
650
+ $this->_LOG("Can't copy " . $file_url_and_dir . $file . ". file $this->varDir.$file is emty");
651
+ $this->set_import_error_reporting_message("Can't copy " . $file_url_and_dir . $file . ". file " . $this->varDir . $file . " is emty");
652
  $this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
653
 
654
  exit;
655
+ } else {
656
+ if ($file == FILE_CATEGORIES_FEATURES) {
657
+ $this->_LOG("Can't copy " . FILE_CATEGORIES_FEATURES . " file ignored");
658
+ $this->_ignore_category_features = true;
659
+ } elseif ($file == FILE_PRODUCT_FEATURES) {
660
+ $this->_LOG("Can't copy " . FILE_PRODUCT_FEATURES . " file ignored");
661
+ $this->_ignore_product_features = true;
662
+ } elseif ($file == FILE_RELATED_PRODUCTS) {
663
+ $this->_LOG("Can't copy " . FILE_RELATED_PRODUCTS . " file ignored");
664
+ $this->_ignore_product_related = true;
665
+ } elseif ($file == FILE_RESTRICTED_VALUES) {
666
+ $this->_LOG("Can't copy " . FILE_RESTRICTED_VALUES . " file ignored");
667
+ $this->_ignore_restricted_values = true;
668
+ } elseif ($file == FILE_PRODUCT_CATEGORIES) {
669
+ $this->_LOG("Can't copy " . FILE_PRODUCT_CATEGORIES . " file ignored");
670
+ $this->_ignore_product_categories = true;
671
  $this->product_file_format = "OLD";
672
+ } elseif ($file == FILE_CATEGORY_TYPES) {
673
+ $this->_LOG("Can't copy " . FILE_CATEGORY_TYPES . " file ignored");
674
+ $this->_ignore_category_types = true;
675
+ } elseif ($file == FILE_DISTRIBUTORS_STOCK_AND_PRICES) {
676
+ $this->_LOG("Can't copy " . FILE_DISTRIBUTORS_STOCK_AND_PRICES . " file ignored");
677
+ $this->_ignore_category_types = true;
678
+ } elseif ($file == FILE_PRODUCT_CONTRACTS) {
679
+ $this->_LOG("Can't copy " . FILE_PRODUCT_CONTRACTS . " file ignored");
680
+ $this->_ignore_product_contracts = true;
681
+ } elseif ($file == FILE_PRICE_RULES) {
682
+ $this->_LOG("Can't copy " . FILE_PRICE_RULES . " file ignored");
683
+ $this->_ignore_price_rules = true;
684
  }
685
 
686
  }
687
  }
688
  }
689
+ if (file_exists($file_url_and_dir . FILE_PRODUCT_CATEGORIES)) {
690
  $this->product_file_format = "NEW";
691
+ $this->_LOG("File " . $file_url_and_dir . FILE_PRODUCT_CATEGORIES . " exist. Will used parser for NEW format product.csv");
692
+ } else {
693
  $this->product_file_format = "OLD";
694
+ $this->_LOG("File " . $file_url_and_dir . FILE_PRODUCT_CATEGORIES . " dosen't exist. Will used parser for OLD format product.csv");
695
  }
696
  $this->_LOG("Finish upload files");
697
+ } // private function createNewDefaultCategories()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
698
  ################################################################################################################################################################
699
 
700
 
701
+ ################################################################################################################################################################
702
 
703
+ private function repl_ph($content, $hash)
704
+ {
705
+ if ($hash) {
706
+ foreach ($hash as $key => $val) {
707
+ if ($key == "category_name") {
708
+ if (strlen($val) > 25) {
709
+ $val = substr($val, 0, 24) . "...";
710
+ }
711
+ }
712
+ $content = preg_replace("/%%%$key%%%/", $val, $content);
713
+ }
714
+ }
715
+ return $content;
716
+ } // private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity)
717
+ ################################################################################################################################################################
718
 
719
 
720
  ################################################################################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
721
 
722
+ function wget()
723
+ {
 
 
 
 
724
 
725
+ $got = func_num_args();
726
+ $url = $file = $flag = false;
 
727
 
728
+ if ($got < 1) {
729
+ return false;
730
+ } elseif ($got == 1) {
731
+ $url = func_get_arg(0);
732
+ } elseif ($got == 2) {
733
+ $url = func_get_arg(0);
734
+ $file = func_get_arg(1);
735
+ } elseif ($got == 3) {
736
+ $url = func_get_arg(0);
737
+ $file = func_get_arg(1);
738
+ $flag = func_get_arg(2);
739
+ }
740
 
741
+ if ($flag == 'copy') {
742
+ if (copy($url, $file)) {
743
+ return true;
744
+ } else {
745
+ return false;
746
+ }
747
+ } elseif ($flag == 'system') {
748
+ exec("wget -O$file $url");
749
+ return true;
750
+ } else {
751
+ $c = curl_init($url);
752
+ curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
753
+ curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
754
+ curl_setopt($c, CURLOPT_HEADER, array("Accept-Encoding: gzip"));
755
+ if (!$file) {
756
+ $page = curl_exec($c);
757
+ curl_close($c);
758
+ return $page;
759
+ } else {
760
+ $FH = fopen($file, "wb");// or echo"Can't open for writing ".$file;
761
+ fwrite($FH, curl_exec($c));
762
+ fclose($FH);
763
+ curl_close($c);
764
+ return true;
765
+ }
766
+ }
767
+ } // private function rewriteMultistoreCategories()
768
+ ################################################################################################################################################################
769
 
 
 
 
770
 
771
+ ################################################################################################################################################################
772
 
773
+ function ParseCategoryTypes()
774
+ {
775
+ $parse_file = $this->varDir . FILE_CATEGORY_TYPES;
776
+ if (filesize($parse_file)) {
777
+ $this->_LOG("Start parse " . FILE_CATEGORY_TYPES);
778
 
779
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('category_types_temp'));
780
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('category_types_temp') . "(
781
+ id int(11),
782
+ name varchar(255),
783
+ key(id)
784
+ )");
785
 
786
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
787
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('category_types_temp') . "
788
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
789
+ OPTIONALLY ENCLOSED BY '\"'
790
+ LINES TERMINATED BY \"\r\n\"
791
+ IGNORE 1 LINES ");
792
 
793
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_category_types'));
794
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('category_types_temp') . "
795
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_category_types'));
796
 
797
+ $this->_LOG("Finish parse " . FILE_CATEGORY_TYPES);
798
+ } else {
799
+ $this->_LOG("Wrong file " . $parse_file);
800
+ }
801
+ $this->_LOG(' ');
802
 
803
+ } // private function truncateAllCateriesAndCreateRoot(...)
 
804
  ################################################################################################################################################################
805
 
806
 
 
807
  ################################################################################################################################################################
 
 
 
 
 
 
808
 
809
+ function ParseCategories()
810
+ {
811
 
812
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
813
+ $im_type = $dataConf['replace_category'];
814
+ $parse_file = $this->varDir . FILE_CATEGORIES;
815
+ //$parse_file = $this->varDir . FILE_CATEGORIES_TEST;
816
+ $field_terminated_char = $this->field_terminated_char;
817
 
818
+ $this->im_type = $im_type;
 
819
 
820
+ if (filesize($parse_file)) {
821
+ $this->_LOG("Start parse " . FILE_CATEGORIES);
822
 
823
+ $this->_getCategoryEntityTypeIdAndDefault_attribute_set_id();
824
 
825
+ $categories_temp = Mage::getSingleton('core/resource')->getTableName('categories_temp');
826
+ $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
827
+ $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
828
+ $catalog_category_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int');
829
+ $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
830
+ $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
831
+ $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
832
+ $category_types = Mage::getSingleton('core/resource')->getTableName('stINch_category_types');
833
 
834
+ $_categoryEntityTypeId = $this->_categoryEntityTypeId;
835
+ $_categoryDefault_attribute_set_id = $this->_categoryDefault_attribute_set_id;
836
 
837
+ $name_attrid = $this->_getCategoryAttributeId('name');
838
+ $is_anchor_attrid = $this->_getCategoryAttributeId('is_anchor');
839
+ $image_attrid = $this->_getCategoryAttributeId('image');
840
 
841
 
842
+ $attr_url_key = $this->attributes['url_key'];
843
+ $attr_display_mode = $this->attributes['display_mode'];
844
+ $attr_is_active = $this->attributes['is_active'];
845
+ $attr_include_in_menu = $this->attributes['include_in_menu'];
846
 
 
 
 
847
 
848
+ $this->loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char);
849
+ $coincidence = $this->calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type, $category_types);
850
 
851
+ /**/
852
+ if (!$this->check_loaded_data($parse_file, $categories_temp)) {
853
+ $inf = mysqli_info();
854
+ $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 . ")");
855
+ exit;
856
+ }/**/
857
 
858
 
859
+ echo("\n\ncoincidence = [" . count($coincidence) . "]\n\n");
860
 
861
+ if (count($coincidence) == 1) // one store logic
862
+ {
863
+ echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
864
+ if ($im_type == "REWRITE") {
865
+ $root_cat = 2;
866
 
867
+ $root_cat = $this->truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
868
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
869
+ $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu); // return $root_cat
870
+ } else // if ($im_type == "MERGE")
871
+ {
872
+ $root_cat = $this->_getShopRootCategoryId();
873
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
874
 
875
+ $this->_root_cat = $root_cat;
876
+
877
+ $this->setCategorySettings($categories_temp, $root_cat);
878
+ $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
879
+ $this->addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
880
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat);
881
+ } else if (count($coincidence) > 1) // multistore logic
882
+ {
883
+ echo("\n\n\n====================================\nmultistore logic\n====================================\n\n\n");
884
+ switch ($im_type) {
885
+ case "REWRITE":
886
+ $this->rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
887
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
888
+ $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
889
+ $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
890
+ break;
891
+ case "MERGE" :
892
+ $this->mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
893
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
894
+ $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
895
+ $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
896
+ break;
897
+ default :
898
+ $retcode = "error";
899
+ };
900
+ } else {
901
+ echo("error");
902
+ }
903
 
904
+ $this->_LOG("Finish parse " . FILE_CATEGORIES);
905
+ } else {
906
+ $this->_LOG("Wrong file " . $parse_file);
907
+ }
908
+ $this->_LOG(' ');
909
+ $this->_set_default_root_category();
910
+ return $coincidence;
911
+ } // private function truncateAllCateries()
912
+ ################################################################################################################################################################
913
 
 
914
 
915
+ ################################################################################################################################################################
916
 
917
+ private function _getCategoryEntityTypeIdAndDefault_attribute_set_id()
918
+ {
919
+ if (!$this->_categoryEntityTypeId || !$this->_categoryDefault_attribute_set_id) {
920
+ $sql = "
921
+ SELECT entity_type_id, default_attribute_set_id
922
+ FROM " . Mage::getSingleton('core/resource')->getTableName('eav_entity_type') . "
923
+ WHERE entity_type_code = 'catalog_category'
924
+ LIMIT 1
925
+ ";
926
+ $result = $this->db_do($sql);
927
+ if ($row = mysqli_fetch_assoc($result)) {
928
+ $this->_categoryEntityTypeId = $row['entity_type_id'];
929
+ $this->_categoryDefault_attribute_set_id = $row['default_attribute_set_id'];
930
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
931
 
932
+ }
933
+ } // public function mapSinchCategoriesMultistore($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
934
+ ################################################################################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
935
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
936
 
937
+ ################################################################################################################################################################
938
 
939
+ private function loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char)
940
+ {
941
+ $this->db_do("DROP TABLE IF EXISTS $categories_temp");
942
+
943
+
944
+ /** OLD !!!*
945
+ * $this->db_do("CREATE TABLE $categories_temp (
946
+ * store_category_id int(11),
947
+ * parent_store_category_id int(11),
948
+ * category_name varchar(50),
949
+ * order_number int(11),
950
+ * is_hidden boolean,
951
+ * products_within_this_category int(11),
952
+ * products_within_sub_categories int(11),
953
+ * categories_image varchar(255),
954
+ * level int(10) NOT NULL default 0,
955
+ * children_count int(11) NOT NULL default 0,
956
+ * KEY(store_category_id),
957
+ * KEY(parent_store_category_id)
958
+ * ) ENGINE=InnoDB DEFAULT CHARSET=utf8
959
+ * ");
960
+ * /**/
961
+
962
+ /** NEW !!! */
963
+ $this->db_do("
964
+ CREATE TABLE $categories_temp
965
+ (
966
+ store_category_id INT(11),
967
+ parent_store_category_id INT(11),
968
+ category_name VARCHAR(50),
969
+ order_number INT(11),
970
+ is_hidden VARCHAR(10),
971
+ products_within_sub_categories INT(11),
972
+ products_within_this_category INT(11),
973
+ categories_image VARCHAR(255),
974
+ level INT(10) NOT NULL DEFAULT 0,
975
+ children_count INT(11) NOT NULL DEFAULT 0,
976
+ UNSPSC INT(10) DEFAULT NULL,
977
+ RootName INT(10) DEFAULT NULL,
978
+ MainImageURL VARCHAR(255),
979
+ MetaTitle TEXT,
980
+ MetaDescription TEXT,
981
+ Description TEXT,
982
+ KEY(store_category_id),
983
+ KEY(parent_store_category_id)
984
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
985
+ /**/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
986
 
987
+ $this->db_do("
988
+ LOAD DATA LOCAL INFILE '$parse_file' INTO TABLE $categories_temp
989
+ FIELDS TERMINATED BY '$field_terminated_char' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
990
 
991
+ $this->db_do("ALTER TABLE $categories_temp ADD COLUMN include_in_menu TINYINT(1) NOT NULL DEFAULT 1");
992
+ $this->db_do("UPDATE $categories_temp SET include_in_menu = 0 WHERE UCASE(is_hidden)='TRUE'");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
993
 
994
+ $this->db_do("ALTER TABLE $categories_temp ADD COLUMN is_anchor TINYINT(1) NOT NULL DEFAULT 1");
995
+ $this->db_do("UPDATE $categories_temp SET level = (level+2) WHERE level >= 0");
996
+ # $this->db_do("UPDATE $categories_temp SET is_anchor = 0 WHERE level > 0");
997
 
 
998
 
999
+ /** FOR TEST !!! *
1000
+ * $this->db_do("ALTER TABLE $categories_temp ADD COLUMN UNSPSC INT(10) NOT NULL DEFAULT 0");
1001
+ * $this->db_do("ALTER TABLE $categories_temp ADD COLUMN RootName VARCHAR(50) NOT NULL DEFAULT 0");
1002
+ *
1003
+ * //$this->db_do("UPDATE $categories_temp SET RootName = '3'"); // one store logic test
1004
+ *
1005
+ * $this->db_do("UPDATE $categories_temp SET RootName = 'KAMERY' WHERE store_category_id IN (93530, 93531, 93230, 93231, 175559, 175687)");
1006
+ * $this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
1007
+ * $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)");
1008
+ *
1009
+ *
1010
+ * //$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
1011
+ * //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553)");
1012
+ *
1013
+ *
1014
+ * //$this->db_do("DELETE FROM $categories_temp WHERE store_category_id IN (175687, 175553)"); // OLD CATS...//
1015
+ *
1016
+ * /**/
1017
+ }
1018
+ ################################################################################################################################################################
1019
 
1020
 
1021
+ ################################################################################################################################################################
1022
 
1023
+ private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type, $category_types)
1024
+ {
1025
+ $root_categories = $this->db_do("
1026
+ SELECT
1027
+ cce.entity_id,
1028
+ ccev.value AS category_name
1029
+ FROM $catalog_category_entity cce
1030
+ JOIN $catalog_category_entity_varchar ccev
1031
+ ON cce.entity_id = ccev.entity_id
1032
+ AND ccev.store_id = 0
1033
+ AND cce.entity_type_id = ccev.entity_type_id
1034
+ AND ccev.attribute_id = 41
1035
+ WHERE parent_id = 1"); // 41 - category name
1036
+ $OLD = array();
1037
+ while ($root_cat = mysqli_fetch_array($root_categories)) $OLD[] = $root_cat['category_name'];
1038
+
1039
+ $new_categories = $this->db_do("SELECT DISTINCT RootName FROM $categories_temp");
1040
 
1041
+ //STP $new_categories = $this->db_do("SELECT DISTINCT ctemp.RootName, ctype.name FROM $categories_temp ctemp LEFT JOIN $category_types ctypes on ctemp.RootName = ctype.name");
1042
 
1043
+ $NEW = array();
1044
+ while ($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['RootName']] = TRUE;
1045
+ /////STP while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['name']] = TRUE;
1046
+ /**
1047
+ * $exists_coincidence = array();
1048
+ *
1049
+ * switch ($im_type)
1050
+ * {
1051
+ * case "REWRITE":
1052
+ * foreach($NEW as $item)
1053
+ * {
1054
+ * $exists_coincidence[$item] = TRUE;
1055
+ * }
1056
+ * break;
1057
+ * case "MERGE" :
1058
+ * foreach($OLD as $item)
1059
+ * {
1060
+ * $exists_coincidence[$item] = FALSE;
1061
+ * }
1062
+ * foreach($NEW as $item)
1063
+ * {
1064
+ * $exists_coincidence[$item] = TRUE;
1065
+ * }
1066
+ * break;
1067
+ * default : $retcode = "error";
1068
+ * };
1069
+ * /**/
1070
+
1071
+
1072
+ echo("\ncalculateCategoryCoincidence ...im_type = [$im_type]\n\n");
1073
+ var_dump($exists_coincidence);
1074
+
1075
+ return $exists_coincidence;
1076
+ } // private function addCategoryDataMultistore(...)
1077
+ ################################################################################################################################################################
1078
 
 
 
1079
 
1080
+ ################################################################################################################################################################
1081
 
1082
+ function check_loaded_data($file, $table)
1083
+ {
1084
+ $cnt_strings_in_file = $this->file_strings_count($file);
1085
+ $cnt_rows_int_table = $this->table_rows_count($table);
1086
+ $persent_cnt_strings_in_file = $cnt_strings_in_file / 10;
1087
+ if ($cnt_rows_int_table > $persent_cnt_strings_in_file) {
1088
+ return true;
1089
+ } else {
1090
+ return false;
1091
+ }
1092
+ } // function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
1093
  ################################################################################################################################################################
1094
 
1095
 
1096
+ ################################################################################################################################################################
1097
 
1098
+ function file_strings_count($parse_file)
1099
+ {
1100
+ $files_str = count(file($parse_file));
1101
+ return $files_str;
1102
+ } //
1103
+ ################################################################################################################################################################
1104
 
1105
 
1106
  ################################################################################################################################################################
 
 
1107
 
1108
+ function table_rows_count($table)
1109
+ {
1110
+ $rows_count_res = $this->db_do("select count(*) as cnt from " . $table);
1111
+ $rows_count = mysqli_fetch_array($rows_count_res);
1112
+ return ($rows_count['cnt']);
1113
+ } //
1114
+ ################################################################################################################################################################
1115
 
1116
 
1117
+ ################################################################################################################################################################
 
 
1118
 
1119
+ private function truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1120
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
1121
+ $name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
1122
+ {
1123
+ $this->db_do('SET foreign_key_checks=0');
1124
 
1125
+ $this->db_do("TRUNCATE $catalog_category_entity");
1126
+ $this->db_do("
1127
+ INSERT $catalog_category_entity
1128
+ (
1129
+ entity_id,
1130
+ entity_type_id,
1131
+ attribute_set_id,
1132
+ parent_id,
1133
+ created_at,
1134
+ updated_at,
1135
+ path,
1136
+ position,
1137
+ level,
1138
+ children_count,
1139
+ store_category_id,
1140
+ parent_store_category_id
1141
+ )
1142
+ VALUES
1143
+ (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
1144
+ (2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 1, null, null)");
1145
 
1146
+ $this->db_do("TRUNCATE $catalog_category_entity_varchar");
1147
+ $this->db_do("
1148
+ INSERT $catalog_category_entity_varchar
1149
+ (
1150
+ value_id,
1151
+ entity_type_id,
1152
+ attribute_id,
1153
+ store_id,
1154
+ entity_id,
1155
+ value
1156
+ )
1157
+ VALUES
1158
+ (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
1159
+ (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
1160
+ (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog'),
1161
+ (4, $_categoryEntityTypeId, $name_attrid, 0, 2, 'Default Category'),
1162
+ (5, $_categoryEntityTypeId, $name_attrid, 1, 2, 'Default Category'),
1163
+ (6, $_categoryEntityTypeId, $attr_display_mode, 1, 2, 'PRODUCTS'),
1164
+ (7, $_categoryEntityTypeId, $attr_url_key, 0, 2, 'default-category')");
1165
+
1166
+ $this->db_do("TRUNCATE $catalog_category_entity_int");
1167
+ $this->db_do("
1168
+ INSERT $catalog_category_entity_int
1169
+ (
1170
+ value_id,
1171
+ entity_type_id,
1172
+ attribute_id,
1173
+ store_id,
1174
+ entity_id,
1175
+ value
1176
+ )
1177
+ VALUES
1178
+ (1, $_categoryEntityTypeId, $attr_is_active, 0, 2, 1),
1179
+ (2, $_categoryEntityTypeId, $attr_is_active, 1, 2, 1),
1180
+ (3, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1),
1181
+ (4, $_categoryEntityTypeId, $attr_include_in_menu, 0, 2, 1)");
1182
+
1183
+ return $root_cat;
1184
+ } // private function truncateAllCateriesAndRecreateDefaults(...)
1185
+ ################################################################################################################################################################
1186
 
 
 
1187
 
1188
+ ################################################################################################################################################################
 
 
 
 
 
 
 
 
 
 
1189
 
1190
+ private function _getShopRootCategoryId($cat_id = 0)
1191
+ {
1192
+ if ($root_cat = Mage::app()->getStore()->getRootCategoryId()) {
1193
+ return $root_cat;
1194
+ } else {
1195
+ $q = "SELECT
1196
+ entity_id
1197
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar') . "
1198
+ WHERE
1199
+ value='default-category'";
1200
+ $res = $this->db_do($q);
1201
+ $row = mysqli_fetch_array($res);
1202
+ if ($row['entity_id'] > 0) {
1203
+ return $row['entity_id'];
1204
+ } else {
1205
+ $q = "SELECT entity_id
1206
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . "
1207
+ WHERE parent_id=" . $cat_id;
1208
+ $quer = $this->db_do($q);
1209
+ $count = 0;
1210
+ while ($row = mysqli_fetch_array($quer)) {
1211
+ $count++;
1212
+ $entity_id = $row['entity_id'];
1213
+ }
1214
+ if ($count > 1 || $count == 0) {
1215
+ return ($cat_id);
1216
+ } else {
1217
+ return $this->_getShopRootCategoryId($entity_id);
1218
+ }
1219
+ }
1220
+ }
1221
+ } // private function setCategorySettings($categories_temp, $root_cat)
1222
+ ################################################################################################################################################################
1223
 
1224
 
1225
+ ################################################################################################################################################################
1226
 
1227
+ private function setCategorySettings($categories_temp, $root_cat)
1228
+ {
1229
+ $this->db_do("
1230
+ UPDATE $categories_temp
1231
+ SET parent_store_category_id = $root_cat
1232
+ WHERE parent_store_category_id = 0");
1233
+
1234
+ $store_cat_ids = $this->db_do("SELECT store_category_id FROM $categories_temp");
1235
+ while ($row = mysqli_fetch_array($store_cat_ids)) {
1236
+ $store_category_id = $row['store_category_id'];
1237
+
1238
+ $children_count = $this->count_children($store_category_id);
1239
+ $level = $this->get_category_level($store_category_id);
1240
+
1241
+ $this->db_do("
1242
+ UPDATE $categories_temp
1243
+ SET children_count = $children_count,
1244
+ level = $level
1245
+ WHERE store_category_id = $store_category_id");
1246
+ }
1247
+ } //
1248
+ ################################################################################################################################################################
1249
 
1250
 
1251
+ ################################################################################################################################################################
1252
 
1253
+ function count_children($id)
1254
+ {
 
1255
 
1256
+ $q = "SELECT store_category_id
1257
+ FROM " . Mage::getSingleton('core/resource')->getTableName('categories_temp') . "
1258
+ WHERE parent_store_category_id=" . $id;
1259
+ $quer = $this->db_do($q);
1260
+ $count = 0;
1261
+ while ($row = mysqli_fetch_array($quer)) {
1262
+ $count += $this->count_children($row['store_category_id']);
1263
+ $count++;
1264
+ }
1265
+ return ($count);
1266
+ } // private function addCategoryData(...)
1267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1268
  ################################################################################################################################################################
1269
 
1270
+ function get_category_level($id)
1271
+ {
1272
+ $q = "SELECT parent_store_category_id
1273
+ FROM " . Mage::getSingleton('core/resource')->getTableName('categories_temp') . "
1274
+ WHERE store_category_id=" . $id;
1275
+ $quer = $this->db_do($q);
1276
+ $level = 1;
1277
+ $row = mysqli_fetch_array($quer);
1278
+ while ($row['parent_store_category_id'] != 0) {
1279
+ $q = "SELECT parent_store_category_id
1280
+ FROM " . Mage::getSingleton('core/resource')->getTableName('categories_temp') . "
1281
+ WHERE store_category_id=" . $row['parent_store_category_id'];
1282
+ $quer = $this->db_do($q);
1283
+ $row = mysqli_fetch_array($quer);
1284
+ $level++;
1285
+ if ($level > 20) {
1286
+ break;
1287
+ }
1288
+ }
1289
 
1290
+ return ($level);
1291
+ }
1292
 
1293
+ #################################################################################################
1294
 
1295
+ public function mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat, $mapping_again = false)
1296
+ {
1297
+ $stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
1298
 
1299
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1300
 
1301
+ $this->db_do("
1302
+ CREATE TABLE $stINch_categories_mapping_temp
1303
+ (
1304
+ shop_entity_id INT(11) UNSIGNED NOT NULL,
1305
+ shop_entity_type_id INT(11),
1306
+ shop_attribute_set_id INT(11),
1307
+ shop_parent_id INT(11),
1308
+ shop_store_category_id INT(11),
1309
+ shop_parent_store_category_id INT(11),
1310
+ store_category_id INT(11),
1311
+ parent_store_category_id INT(11),
1312
+ category_name VARCHAR(255),
1313
+ order_number INT(11),
1314
+ products_within_this_category INT(11),
1315
+
1316
+ KEY shop_entity_id (shop_entity_id),
1317
+ KEY shop_parent_id (shop_parent_id),
1318
+ KEY store_category_id (store_category_id),
1319
+ KEY parent_store_category_id (parent_store_category_id),
1320
+ UNIQUE KEY(shop_entity_id)
1321
+ )");
1322
 
1323
+ $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
1324
 
1325
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!! one shop ($this->_root_cat) => milti shop ($root_cat)
1326
 
1327
+ // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
1328
+ if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) {
1329
+ // backup Category ID in REWRITE mode
1330
+ if ($mapping_again) {
1331
+ $this->db_do("
1332
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
1333
+ (
1334
+ shop_entity_id,
1335
+ shop_entity_type_id,
1336
+ shop_attribute_set_id,
1337
+ shop_parent_id,
1338
+ shop_store_category_id,
1339
+ shop_parent_store_category_id
1340
+ )
1341
+ (SELECT
1342
+ entity_id,
1343
+ entity_type_id,
1344
+ attribute_set_id,
1345
+ parent_id,
1346
+ store_category_id,
1347
+ parent_store_category_id
1348
+ FROM $catalog_category_entity)");
1349
+
1350
+ $this->db_do("
1351
+ UPDATE $stINch_categories_mapping_temp cmt
1352
+ JOIN $categories_temp c
1353
+ ON cmt.shop_store_category_id = c.store_category_id
1354
+ SET
1355
+ cmt.store_category_id = c.store_category_id,
1356
+ cmt.parent_store_category_id = c.parent_store_category_id,
1357
+ cmt.category_name = c.category_name,
1358
+ cmt.order_number = c.order_number,
1359
+ cmt.products_within_this_category = c.products_within_this_category");
1360
+
1361
+ $this->db_do("
1362
+ UPDATE $stINch_categories_mapping_temp cmt
1363
+ JOIN $catalog_category_entity cce
1364
+ ON cmt.parent_store_category_id = cce.store_category_id
1365
+ SET cmt.shop_parent_id = cce.entity_id");
1366
+
1367
+ $this->db_do("
1368
+ UPDATE $stINch_categories_mapping_temp cmt
1369
+ JOIN $categories_temp c
1370
+ ON cmt.shop_store_category_id = c.store_category_id
1371
+ SET shop_parent_id = " . $this->_root_cat . "
1372
+ WHERE shop_parent_id = 0");
1373
+
1374
+ $this->db_do("
1375
+ UPDATE $stINch_categories_mapping_temp cmt
1376
+ JOIN $catalog_category_entity cce
1377
+ ON cmt.shop_entity_id = cce.entity_id
1378
+ SET cce.parent_id = cmt.shop_parent_id");
1379
+ } else {
1380
+ $catalog_category_entity_backup = Mage::getSingleton('core/resource')->getTableName('sinch_category_backup');
1381
+ if (!$this->_checkCategoryBackupExist($catalog_category_entity_backup)) {
1382
+ $catalog_category_entity_backup = $catalog_category_entity;
1383
+ }
1384
 
1385
+ $this->db_do("
1386
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
1387
+ (
1388
+ shop_entity_id,
1389
+ shop_entity_type_id,
1390
+ shop_attribute_set_id,
1391
+ shop_parent_id,
1392
+ shop_store_category_id,
1393
+ shop_parent_store_category_id
1394
+ )
1395
+ (SELECT
1396
+ entity_id,
1397
+ entity_type_id,
1398
+ attribute_set_id,
1399
+ parent_id,
1400
+ store_category_id,
1401
+ parent_store_category_id
1402
+ FROM $catalog_category_entity_backup)");
1403
+
1404
+ $this->db_do("
1405
+ UPDATE $stINch_categories_mapping_temp cmt
1406
+ JOIN $categories_temp c
1407
+ ON cmt.shop_store_category_id = c.store_category_id
1408
+ SET
1409
+ cmt.store_category_id = c.store_category_id,
1410
+ cmt.parent_store_category_id = c.parent_store_category_id,
1411
+ cmt.category_name = c.category_name,
1412
+ cmt.order_number = c.order_number,
1413
+ cmt.products_within_this_category = c.products_within_this_category");
1414
+
1415
+ $this->db_do("
1416
+ UPDATE $stINch_categories_mapping_temp cmt
1417
+ JOIN $catalog_category_entity_backup cce
1418
+ ON cmt.parent_store_category_id = cce.store_category_id
1419
+ SET cmt.shop_parent_id = cce.entity_id");
1420
+
1421
+ $this->db_do("
1422
+ UPDATE $stINch_categories_mapping_temp cmt
1423
+ JOIN $categories_temp c
1424
+ ON cmt.shop_store_category_id = c.store_category_id
1425
+ SET shop_parent_id = " . $this->_root_cat . "
1426
+ WHERE shop_parent_id = 0");
1427
+
1428
+ $this->db_do("
1429
+ UPDATE $stINch_categories_mapping_temp cmt
1430
+ JOIN $catalog_category_entity cce
1431
+ ON cmt.shop_entity_id = cce.entity_id
1432
+ SET cce.parent_id = cmt.shop_parent_id");
1433
+ }
1434
+ // (end) backup Category ID in REWRITE mode
1435
+ } else {
1436
+ $this->db_do("
1437
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
1438
+ (
1439
+ shop_entity_id,
1440
+ shop_entity_type_id,
1441
+ shop_attribute_set_id,
1442
+ shop_parent_id,
1443
+ shop_store_category_id,
1444
+ shop_parent_store_category_id
1445
+ )
1446
+ (SELECT
1447
+ entity_id,
1448
+ entity_type_id,
1449
+ attribute_set_id,
1450
+ parent_id,
1451
+ store_category_id,
1452
+ parent_store_category_id
1453
+ FROM $catalog_category_entity)");
1454
+
1455
+ $this->db_do("
1456
+ UPDATE $stINch_categories_mapping_temp cmt
1457
+ JOIN $categories_temp c
1458
+ ON cmt.shop_store_category_id = c.store_category_id
1459
+ SET
1460
+ cmt.store_category_id = c.store_category_id,
1461
+ cmt.parent_store_category_id = c.parent_store_category_id,
1462
+ cmt.category_name = c.category_name,
1463
+ cmt.order_number = c.order_number,
1464
+ cmt.products_within_this_category = c.products_within_this_category");
1465
+
1466
+ $this->db_do("
1467
+ UPDATE $stINch_categories_mapping_temp cmt
1468
+ JOIN $catalog_category_entity cce
1469
+ ON cmt.parent_store_category_id = cce.store_category_id
1470
+ SET cmt.shop_parent_id = cce.entity_id");
1471
+
1472
+ $this->db_do("
1473
+ UPDATE $stINch_categories_mapping_temp cmt
1474
+ JOIN $categories_temp c
1475
+ ON cmt.shop_store_category_id = c.store_category_id
1476
+ SET shop_parent_id = " . $this->_root_cat . "
1477
+ WHERE shop_parent_id = 0");
1478
+
1479
+ $this->db_do("
1480
+ UPDATE $stINch_categories_mapping_temp cmt
1481
+ JOIN $catalog_category_entity cce
1482
+ ON cmt.shop_entity_id = cce.entity_id
1483
+ SET cce.parent_id = cmt.shop_parent_id
1484
+ WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL");
1485
+ }
1486
+ $this->_LOG("Execute function mapSinchCategories");
1487
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping");
1488
+ $this->db_do("RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping");
1489
+ }
1490
 
1491
+ #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1492
 
1493
+ private function addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
1494
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat)
1495
+ {
1496
+ if (UPDATE_CATEGORY_DATA) {
1497
+ echo "Update category_entity \n";
 
 
 
 
 
 
 
 
 
 
 
 
 
1498
 
1499
+ $q = "
1500
+ INSERT INTO $catalog_category_entity
1501
+ (
1502
+ entity_type_id,
1503
+ attribute_set_id,
1504
+ created_at,
1505
+ updated_at,
1506
+ level,
1507
+ children_count,
1508
+ entity_id,
1509
+ position,
1510
+ parent_id,
1511
+ store_category_id,
1512
+ parent_store_category_id
1513
+ )
1514
+ (SELECT
1515
+ $_categoryEntityTypeId,
1516
+ $_categoryDefault_attribute_set_id,
1517
+ now(),
1518
+ now(),
1519
+ c.level,
1520
+ c.children_count,
1521
+ scm.shop_entity_id,
1522
+ c.order_number,
1523
+ scm.shop_parent_id,
1524
+ c.store_category_id,
1525
+ c.parent_store_category_id
1526
+ FROM $categories_temp c
1527
+ LEFT JOIN $stINch_categories_mapping scm
1528
+ ON c.store_category_id = scm.store_category_id
1529
+ )
1530
+ ON DUPLICATE KEY UPDATE
1531
+ updated_at = now(),
1532
+ store_category_id = c.store_category_id,
1533
+ level = c.level,
1534
+ children_count = c.children_count,
1535
+ position = c.order_number,
1536
+ parent_store_category_id = c.parent_store_category_id";
1537
+ //level=c.level,
1538
+ //children_count=c.children_count
1539
+ //position=c.order_number,
1540
+ } else {
1541
+ echo "Insert ignore category_entity \n";
1542
 
1543
+ $q = "
1544
+ INSERT IGNORE INTO $catalog_category_entity
1545
+ (
1546
+ entity_type_id,
1547
+ attribute_set_id,
1548
+ created_at,
1549
+ updated_at,
1550
+ level,
1551
+ children_count,
1552
+ entity_id,
1553
+ position,
1554
+ parent_id,
1555
+ store_category_id,
1556
+ parent_store_category_id
1557
+ )
1558
+ (SELECT
1559
+ $_categoryEntityTypeId,
1560
+ $_categoryDefault_attribute_set_id,
1561
+ now(),
1562
+ now(),
1563
+ c.level,
1564
+ c.children_count,
1565
+ scm.shop_entity_id,
1566
+ c.order_number,
1567
+ scm.shop_parent_id,
1568
+ c.store_category_id,
1569
+ c.parent_store_category_id
1570
+ FROM $categories_temp c
1571
+ LEFT JOIN $stINch_categories_mapping scm
1572
+ ON c.store_category_id = scm.store_category_id
1573
+ )";
1574
+ }
1575
+ $this->db_do($q);
1576
 
1577
+ $this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat, true);
 
 
1578
 
1579
 
1580
+ $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
1581
+ while ($row = mysqli_fetch_array($categories)) {
1582
+ $parent_id = $row['parent_id'];
1583
+ $entity_id = $row['entity_id'];
1584
 
1585
+ $path = $this->culc_path($parent_id, $entity_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1586
 
1587
+ //echo("\n$path\n");
1588
 
1589
+ $this->db_do("
1590
+ UPDATE $catalog_category_entity
1591
+ SET path = '$path'
1592
+ WHERE entity_id = $entity_id");
1593
+ }
1594
 
1595
+ if (UPDATE_CATEGORY_DATA) {
1596
+ echo "Update category_data \n";
1597
 
1598
+ $q = "
1599
+ INSERT INTO $catalog_category_entity_varchar
1600
+ (
1601
+ entity_type_id,
1602
+ attribute_id,
1603
+ store_id,
1604
+ entity_id,
1605
+ value
1606
+ )
1607
+ (SELECT
1608
+ $_categoryEntityTypeId,
1609
+ $name_attrid,
1610
+ 0,
1611
+ scm.shop_entity_id,
1612
+ c.category_name
1613
+ FROM $categories_temp c
1614
+ JOIN $stINch_categories_mapping scm
1615
+ ON c.store_category_id = scm.store_category_id
1616
+ )
1617
+ ON DUPLICATE KEY UPDATE
1618
+ value = c.category_name";
1619
+ $this->db_do($q);
1620
 
1621
+ $q = "
1622
+ INSERT INTO $catalog_category_entity_varchar
1623
+ (
1624
+ entity_type_id,
1625
+ attribute_id,
1626
+ store_id,
1627
+ entity_id,
1628
+ value
1629
+ )
1630
+ (SELECT
1631
+ $_categoryEntityTypeId,
1632
+ $name_attrid,
1633
+ 1,
1634
+ scm.shop_entity_id,
1635
+ c.category_name
1636
+ FROM $categories_temp c
1637
+ JOIN $stINch_categories_mapping scm
1638
+ ON c.store_category_id = scm.store_category_id
1639
+ )
1640
+ ON DUPLICATE KEY UPDATE
1641
+ value = c.category_name";
1642
+ $this->db_do($q);
1643
 
1644
+ $q = "
1645
+ INSERT INTO $catalog_category_entity
1646
+ (
1647
+ entity_type_id,
1648
+ attribute_id,
1649
+ store_id,
1650
+ entity_id,
1651
+ value
1652
+ )
1653
+ (SELECT
1654
+ $_categoryEntityTypeId,
1655
+ $attr_is_active,
1656
+ 0,
1657
+ scm.shop_entity_id,
1658
+ 1
1659
+ FROM $categories_temp c
1660
+ JOIN $stINch_categories_mapping scm
1661
+ ON c.store_category_id = scm.store_category_id
1662
+ )
1663
+ ON DUPLICATE KEY UPDATE
1664
+ value = 1";
1665
+ $this->db_do($q);
1666
 
1667
+ $q = "
1668
+ INSERT INTO $catalog_category_entity_int
1669
+ (
1670
+ entity_type_id,
1671
+ attribute_id,
1672
+ store_id,
1673
+ entity_id,
1674
+ value
1675
+ )
1676
+ (SELECT
1677
+ $_categoryEntityTypeId,
1678
+ $attr_is_active,
1679
+ 1,
1680
+ scm.shop_entity_id,
1681
+ 1
1682
+ FROM $categories_temp c
1683
+ JOIN $stINch_categories_mapping scm
1684
+ ON c.store_category_id = scm.store_category_id
1685
+ )
1686
+ ON DUPLICATE KEY UPDATE
1687
+ value = 1";
1688
+ $this->db_do($q);
1689
 
1690
+ $q = "
1691
+ INSERT INTO $catalog_category_entity_int
1692
+ (
1693
+ entity_type_id,
1694
+ attribute_id,
1695
+ store_id,
1696
+ entity_id,
1697
+ value
1698
+ )
1699
+ (SELECT
1700
+ $_categoryEntityTypeId,
1701
+ $attr_include_in_menu,
1702
+ 0,
1703
+ scm.shop_entity_id,
1704
+ c.include_in_menu
1705
+ FROM $categories_temp c
1706
+ JOIN $stINch_categories_mapping scm
1707
+ ON c.store_category_id = scm.store_category_id
1708
+ )
1709
+ ON DUPLICATE KEY UPDATE
1710
+ value = c.include_in_menu";
1711
+ $this->db_do($q);
1712
 
1713
+ $q = "
1714
+ INSERT INTO $catalog_category_entity_int
1715
+ (
1716
+ entity_type_id,
1717
+ attribute_id,
1718
+ store_id,
1719
+ entity_id,
1720
+ value
1721
+ )
1722
+ (SELECT
1723
+ $_categoryEntityTypeId,
1724
+ $is_anchor_attrid,
1725
+ 1,
1726
+ scm.shop_entity_id,
1727
+ c.is_anchor
1728
+ FROM $categories_temp c
1729
+ JOIN $stINch_categories_mapping scm
1730
+ ON c.store_category_id = scm.store_category_id
1731
+ )
1732
+ ON DUPLICATE KEY UPDATE
1733
+ value = c.is_anchor";
1734
+ $this->db_do($q);
1735
 
1736
+ $q = "
1737
+ INSERT INTO $catalog_category_entity_int
1738
+ (
1739
+ entity_type_id,
1740
+ attribute_id,
1741
+ store_id,
1742
+ entity_id,
1743
+ value
1744
+ )
1745
+ (SELECT
1746
+ $_categoryEntityTypeId,
1747
+ $is_anchor_attrid,
1748
+ 0,
1749
+ scm.shop_entity_id,
1750
+ c.is_anchor
1751
+ FROM $categories_temp c
1752
+ JOIN $stINch_categories_mapping scm
1753
+ ON c.store_category_id = scm.store_category_id
1754
+ )
1755
+ ON DUPLICATE KEY UPDATE
1756
+ value = c.is_anchor";
1757
+ $this->db_do($q);
1758
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1759
  $q = "
1760
  INSERT INTO $catalog_category_entity_varchar
1761
  (
1762
+ entity_type_id,
1763
+ attribute_id,
1764
+ store_id,
1765
+ entity_id,
1766
+ value
1767
+ )
1768
+ (SELECT
1769
+ $_categoryEntityTypeId,
1770
+ $image_attrid,
1771
+ 0,
1772
+ scm.shop_entity_id,
1773
+ c.categories_image
1774
+ FROM $categories_temp c
1775
+ JOIN $stINch_categories_mapping scm
1776
+ ON c.store_category_id = scm.store_category_id
1777
+ )
1778
+ ON DUPLICATE KEY UPDATE
1779
+ value = c.categories_image";
1780
+ $this->db_do($q);
1781
+ //STP
1782
+ $q = "
1783
+ INSERT INTO $catalog_category_entity_varchar
1784
+ (
1785
+ entity_type_id,
1786
+ attribute_id,
1787
  store_id,
1788
+ entity_id,
1789
  value
1790
  )
1791
+ (SELECT
1792
  $this->_categoryEntityTypeId,
1793
  $this->_categoryMetaTitleAttrId,
1794
+ 0,
1795
+ scm.shop_entity_id,
1796
+ c.MetaTitle
1797
+ FROM $categories_temp c
1798
+ JOIN $stINch_categories_mapping scm
1799
  ON c.store_category_id = scm.store_category_id
1800
  )
1801
  ON DUPLICATE KEY UPDATE
1805
  $q = "
1806
  INSERT INTO $catalog_category_entity_varchar
1807
  (
1808
+ entity_type_id,
1809
+ attribute_id,
1810
  store_id,
1811
+ entity_id,
1812
  value
1813
  )
1814
+ (SELECT
1815
  $this->_categoryEntityTypeId,
1816
  $this->_categoryMetadescriptionAttrId,
1817
+ 0,
1818
+ scm.shop_entity_id,
1819
+ c.MetaDescription
1820
+ FROM $categories_temp c
1821
+ JOIN $stINch_categories_mapping scm
1822
  ON c.store_category_id = scm.store_category_id
1823
  )
1824
  ON DUPLICATE KEY UPDATE
1828
  $q = "
1829
  INSERT INTO $catalog_category_entity_varchar
1830
  (
1831
+ entity_type_id,
1832
+ attribute_id,
1833
  store_id,
1834
+ entity_id,
1835
  value
1836
  )
1837
+ (SELECT
1838
  $this->_categoryEntityTypeId,
1839
  $this->_categoryDescriptionAttrId,
1840
+ 0,
1841
+ scm.shop_entity_id,
1842
+ c.Description
1843
+ FROM $categories_temp c
1844
+ JOIN $stINch_categories_mapping scm
1845
  ON c.store_category_id = scm.store_category_id
1846
  )
1847
  ON DUPLICATE KEY UPDATE
1849
  $this->db_do($q);
1850
 
1851
 
1852
+ //stp
1853
+ } else {
1854
+ echo "Insert ignore category_data \n";
1855
+
1856
+ $q = "
1857
+ INSERT IGNORE INTO $catalog_category_entity_varchar
1858
+ (
1859
+ entity_type_id,
1860
+ attribute_id,
1861
+ store_id,
1862
+ entity_id,
1863
+ value
1864
+ )
1865
+ (SELECT
1866
+ $_categoryEntityTypeId,
1867
+ $name_attrid,
1868
+ 0,
1869
+ scm.shop_entity_id,
1870
+ c.category_name
1871
+ FROM $categories_temp c
1872
+ JOIN $stINch_categories_mapping scm
1873
+ ON c.store_category_id = scm.store_category_id
1874
+ )";
1875
+ $this->db_do($q);
1876
+
1877
+ $q = "
1878
+ INSERT IGNORE INTO $catalog_category_entity_int
1879
+ (
1880
+ entity_type_id,
1881
+ attribute_id,
1882
+ store_id,
1883
+ entity_id,
1884
+ value
1885
+ )
1886
+ (SELECT
1887
+ $_categoryEntityTypeId,
1888
+ $attr_is_active,
1889
+ 0,
1890
+ scm.shop_entity_id,
1891
+ 1
1892
+ FROM $categories_temp c
1893
+ JOIN $stINch_categories_mapping scm
1894
+ ON c.store_category_id = scm.store_category_id
1895
+ )";
1896
+ $this->db_do($q);
1897
+
1898
+ $q = "
1899
+ INSERT IGNORE INTO $catalog_category_entity_int
1900
+ (
1901
+ entity_type_id,
1902
+ attribute_id,
1903
+ store_id,
1904
+ entity_id,
1905
+ value
1906
+ )
1907
+ (SELECT
1908
+ $_categoryEntityTypeId,
1909
+ $attr_include_in_menu,
1910
+ 0,
1911
+ scm.shop_entity_id,
1912
+ c.include_in_menu
1913
+ FROM $categories_temp c
1914
+ JOIN $stINch_categories_mapping scm
1915
+ ON c.store_category_id = scm.store_category_id
1916
+ )";
1917
+ $this->db_do($q);
1918
+
1919
+ $q = "
1920
+ INSERT IGNORE INTO $catalog_category_entity_int
1921
+ (
1922
+ entity_type_id,
1923
+ attribute_id,
1924
+ store_id,
1925
+ entity_id,
1926
+ value
1927
+ )
1928
+ (SELECT
1929
+ $_categoryEntityTypeId,
1930
+ $is_anchor_attrid,
1931
+ 0,
1932
+ scm.shop_entity_id,
1933
+ c.is_anchor
1934
+ FROM $categories_temp c
1935
+ JOIN $stINch_categories_mapping scm
1936
+ ON c.store_category_id = scm.store_category_id
1937
+ )";
1938
+ $this->db_do($q);
1939
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1940
  $q = "
1941
  INSERT IGNORE INTO $catalog_category_entity_varchar
1942
  (
1943
+ entity_type_id,
1944
+ attribute_id,
1945
+ store_id,
1946
+ entity_id,
1947
+ value
1948
+ )
1949
+ (SELECT
1950
+ $_categoryEntityTypeId,
1951
+ $image_attrid,
1952
+ 0,
1953
+ scm.shop_entity_id,
1954
+ c.categories_image
1955
+ FROM $categories_temp c
1956
+ JOIN $stINch_categories_mapping scm
1957
+ ON c.store_category_id = scm.store_category_id
1958
+ )";
1959
+ $this->db_do($q);
1960
+ //STP
1961
+ $q = "
1962
+ INSERT IGNORE INTO $catalog_category_entity_varchar
1963
+ (
1964
+ entity_type_id,
1965
+ attribute_id,
1966
  store_id,
1967
+ entity_id,
1968
  value
1969
  )
1970
+ (SELECT
1971
  $this->_categoryEntityTypeId,
1972
  $this->_categoryMetaTitleAttrId,
1973
+ 0,
1974
+ scm.shop_entity_id,
1975
+ c.MetaTitle
1976
+ FROM $categories_temp c
1977
+ JOIN $stINch_categories_mapping scm
1978
  ON c.store_category_id = scm.store_category_id
1979
  )
1980
  ";
1983
  $q = "
1984
  INSERT IGNORE INTO $catalog_category_entity_varchar
1985
  (
1986
+ entity_type_id,
1987
+ attribute_id,
1988
  store_id,
1989
+ entity_id,
1990
  value
1991
  )
1992
+ (SELECT
1993
  $this->_categoryEntityTypeId,
1994
  $this->_categoryMetadescriptionAttrId,
1995
+ 0,
1996
+ scm.shop_entity_id,
1997
+ c.MetaDescription
1998
+ FROM $categories_temp c
1999
+ JOIN $stINch_categories_mapping scm
2000
  ON c.store_category_id = scm.store_category_id
2001
  )
2002
  ";
2005
  $q = "
2006
  INSERT IGNORE INTO $catalog_category_entity_varchar
2007
  (
2008
+ entity_type_id,
2009
+ attribute_id,
2010
  store_id,
2011
+ entity_id,
2012
  value
2013
  )
2014
+ (SELECT
2015
  $this->_categoryEntityTypeId,
2016
  $this->_categoryDescriptionAttrId,
2017
+ 0,
2018
+ scm.shop_entity_id,
2019
+ c.Description
2020
+ FROM $categories_temp c
2021
+ JOIN $stINch_categories_mapping scm
2022
  ON c.store_category_id = scm.store_category_id
2023
  )
2024
  ";
2026
 
2027
 
2028
  //stp
 
 
2029
 
2030
+ }
 
 
 
 
2031
 
2032
+ $this->delete_old_sinch_categories_from_shop();
2033
 
2034
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories");
2035
+ $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
2036
+ }
2037
 
 
 
 
2038
 
2039
+ #################################################################################################
2040
 
2041
+ function culc_path($parent_id, $ent_id)
2042
+ {
2043
 
2044
+ //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]\n");
2045
 
2046
+ $path = '';
2047
+ $cat_id = $parent_id;
2048
+ $q = "SELECT
2049
+ parent_id
2050
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . "
2051
+ WHERE entity_id=" . $cat_id;
2052
+ $quer = $this->db_do($q);
2053
+ $row = mysqli_fetch_array($quer);
2054
+ while ($row['parent_id']) {
2055
+ $path = $row['parent_id'] . '/' . $path;
2056
+ $q = "SELECT
2057
+ parent_id
2058
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . "
2059
+ WHERE entity_id=" . $row['parent_id'];
2060
+ $quer = $this->db_do($q);
2061
+ $row = mysqli_fetch_array($quer);
2062
 
2063
+ }
2064
+ if ($cat_id) {
2065
+ $path .= $cat_id . "/";
2066
+ }
 
 
 
 
2067
 
2068
+ if ($path) {
2069
+ return ($path . $ent_id);
2070
+ } else {
2071
+ return ($ent_id);
2072
+ }
2073
 
2074
+ }
 
2075
 
 
2076
 
2077
+ #################################################################################################
 
 
2078
 
2079
+ private function delete_old_sinch_categories_from_shop()
2080
+ {
2081
 
2082
+ $q = "DELETE cat FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar') . " cat
2083
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping') . " scm
2084
+ ON cat.entity_id=scm.shop_entity_id
2085
+ WHERE
2086
+ (scm.shop_store_category_id is not null) AND
2087
+ (scm.store_category_id is null)";
2088
+ $this->db_do($q);
2089
 
2090
+ $q = "DELETE cat FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int') . " cat
2091
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping') . " scm
2092
+ ON cat.entity_id=scm.shop_entity_id
2093
+ WHERE
2094
+ (scm.shop_store_category_id is not null) AND
2095
+ (scm.store_category_id is null)";
2096
+ $this->db_do($q);
2097
 
2098
+ $q = "DELETE cat FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . " cat
2099
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping') . " scm
2100
+ ON cat.entity_id=scm.shop_entity_id
2101
+ WHERE
2102
+ (scm.shop_store_category_id is not null) AND
2103
+ (scm.store_category_id is null)";
2104
+ $this->db_do($q);
2105
 
2106
+ }
2107
 
2108
+ #################################################################################################
2109
 
2110
+ private function rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
2111
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
2112
+ $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
2113
+ $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
2114
+ {
2115
+ echo("rewriteMultistoreCategories RUN\n");
2116
 
 
 
 
2117
 
2118
+ echo(" truncateAllCateriesAndCreateRoot start...");
2119
+ $this->truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
2120
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active);
2121
+ echo(" done.\n");
2122
 
2123
 
2124
+ echo(" createDefaultCategories start...");
2125
+ $this->createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
2126
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
2127
+ echo(" done.\n");
2128
 
 
2129
 
2130
+ echo(" mapSinchCategoriesMultistore start...");
2131
+ $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
2132
+ echo(" done.\n");
2133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2134
 
2135
+ echo(" addCategoryDataMultistore start...");
2136
+ $this->addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
2137
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
2138
+ $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
2139
+ echo(" done.\n");
2140
 
 
 
 
 
 
 
 
2141
 
2142
+ echo("rewriteMultistoreCategories DONE\n");
2143
+ }
2144
 
2145
+ #################################################################################################
2146
 
2147
+ private function truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
2148
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active)
2149
+ {
2150
+ $this->db_do('SET foreign_key_checks=0');
2151
 
2152
 
2153
+ $this->db_do("TRUNCATE $catalog_category_entity");
2154
+ $this->db_do("TRUNCATE $catalog_category_entity_varchar");
2155
+ $this->db_do("TRUNCATE $catalog_category_entity_int");
2156
 
 
 
 
 
 
 
 
 
 
2157
 
2158
+ $this->db_do("INSERT $catalog_category_entity
2159
+ (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
2160
+ path, position, level, children_count, store_category_id, parent_store_category_id)
2161
+ VALUES
2162
+ (1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', NOW(), '1', 0, 0, 1, NULL, NULL)");
2163
 
2164
 
2165
+ $this->db_do("INSERT $catalog_category_entity_varchar
2166
+ (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
2167
+ VALUES
2168
+ (1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
2169
+ (2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
2170
+ (3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog')");
2171
 
2172
 
2173
+ $this->db_do("INSERT $catalog_category_entity_int
2174
+ (value_id, entity_type_id, attribute_id, store_id, entity_id, value)
2175
+ VALUES
2176
+ (1, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1)");
2177
+ }
2178
 
2179
+ #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2180
 
2181
+ private function createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
2182
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
2183
+ {
2184
+ $i = 3; // 2 - is Default Category... not use.
2185
+
2186
+ foreach ($coincidence as $key => $item) {
2187
+ $this->db_do("INSERT $catalog_category_entity
2188
+ (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
2189
+ path, position, level, children_count, store_category_id, parent_store_category_id)
2190
+ VALUES
2191
+ ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 1, NULL, NULL)");
2192
+
2193
+
2194
+ $this->db_do("INSERT $catalog_category_entity_varchar
2195
+ (entity_type_id, attribute_id, store_id, entity_id, value)
2196
+ VALUES
2197
+ ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
2198
+ ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
2199
+ ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
2200
+ ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
2201
+
2202
+
2203
+ $this->db_do("INSERT $catalog_category_entity_int
2204
+ (entity_type_id, attribute_id, store_id, entity_id, value)
2205
+ VALUES
2206
+ ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
2207
+ ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
2208
+ ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
2209
+ ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
2210
+ $i++;
2211
+ } // foreach($coincidence as $key => $item)
2212
+ }
2213
 
2214
+ #################################################################################################
2215
 
2216
+ private function mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid, $mapping_again = false)
2217
+ {
2218
+ echo("\n\n\n\n==========================================================================\nmapSinchCategoriesMultistore start... \n");
2219
+
2220
+ $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
2221
+
2222
+ // backup Category ID in REWRITE mode
2223
+ if ($im_type == "REWRITE" || (UPDATE_CATEGORY_DATA && $im_type == "MERGE")) {
2224
+ if ($mapping_again) {
2225
+ $query = "
2226
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
2227
+ (
2228
+ shop_entity_id,
2229
+ shop_entity_type_id,
2230
+ shop_attribute_set_id,
2231
+ shop_parent_id,
2232
+ shop_store_category_id,
2233
+ shop_parent_store_category_id
2234
+ )
2235
+ (SELECT
2236
+ entity_id,
2237
+ entity_type_id,
2238
+ attribute_set_id,
2239
+ parent_id,
2240
+ store_category_id,
2241
+ parent_store_category_id
2242
+ FROM $catalog_category_entity)";
2243
+ echo("\n\n$query\n\n");
2244
+ $this->db_do($query);
2245
+
2246
+
2247
+ $query = "
2248
+ UPDATE $stINch_categories_mapping_temp cmt
2249
+ JOIN $categories_temp c
2250
+ ON cmt.shop_store_category_id = c.store_category_id
2251
+ SET
2252
+ cmt.store_category_id = c.store_category_id,
2253
+ cmt.parent_store_category_id = c.parent_store_category_id,
2254
+ cmt.category_name = c.category_name,
2255
+ cmt.order_number = c.order_number,
2256
+ cmt.products_within_this_category = c.products_within_this_category";
2257
+ echo("\n\n$query\n\n");
2258
+ $this->db_do($query);
2259
+
2260
+
2261
+ $query = "
2262
+ UPDATE $stINch_categories_mapping_temp cmt
2263
+ JOIN $catalog_category_entity cce
2264
+ ON cmt.parent_store_category_id = cce.store_category_id
2265
+ SET cmt.shop_parent_id = cce.entity_id";
2266
+ echo("\n\n$query\n\n");
2267
+ $this->db_do($query);
2268
+
2269
+
2270
+ $query = "
2271
+ SELECT DISTINCT
2272
+ c.RootName, cce.entity_id
2273
+ FROM $categories_temp c
2274
+ JOIN $catalog_category_entity_varchar ccev
2275
+ ON c.RootName = ccev.value
2276
+ AND ccev.entity_type_id = $_categoryEntityTypeId
2277
+ AND ccev.attribute_id = $name_attrid
2278
+ AND ccev.store_id = 0
2279
+ JOIN $catalog_category_entity cce
2280
+ ON ccev.entity_id = cce.entity_id";
2281
+ echo("\n\n$query\n\n");
2282
+ $root_categories = $this->db_do($query);
2283
+
2284
+ while ($root_cat = mysqli_fetch_array($root_categories)) {
2285
+ $root_id = $root_cat['entity_id'];
2286
+ $root_name = $root_cat['RootName'];
2287
+
2288
+ $query = "
2289
+ UPDATE $stINch_categories_mapping_temp cmt
2290
+ JOIN $categories_temp c
2291
+ ON cmt.shop_store_category_id = c.store_category_id
2292
+ SET
2293
+ cmt.shop_parent_id = $root_id,
2294
+ cmt.shop_parent_store_category_id = $root_id,
2295
+ cmt.parent_store_category_id = $root_id,
2296
+ c.parent_store_category_id = $root_id
2297
+ WHERE RootName = '$root_name'
2298
+ AND cmt.shop_parent_id = 0";
2299
+ echo("\n\n$query\n\n");
2300
+ $this->db_do($query);
2301
+ }
2302
+ } else {
2303
+ $catalog_category_entity_backup = Mage::getSingleton('core/resource')->getTableName('sinch_category_backup');
2304
+ if (!$this->_checkCategoryBackupExist($catalog_category_entity_backup)) {
2305
+ $catalog_category_entity_backup = $catalog_category_entity;
2306
+ }
2307
+ $query = "
2308
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
2309
+ (
2310
+ shop_entity_id,
2311
+ shop_entity_type_id,
2312
+ shop_attribute_set_id,
2313
+ shop_parent_id,
2314
+ shop_store_category_id,
2315
+ shop_parent_store_category_id
2316
+ )
2317
+ (SELECT
2318
+ entity_id,
2319
+ entity_type_id,
2320
+ attribute_set_id,
2321
+ parent_id,
2322
+ store_category_id,
2323
+ parent_store_category_id
2324
+ FROM $catalog_category_entity_backup)";
2325
+ echo("\n\n$query\n\n");
2326
+ $this->db_do($query);
2327
+
2328
+
2329
+ $query = "
2330
+ UPDATE $stINch_categories_mapping_temp cmt
2331
+ JOIN $categories_temp c
2332
+ ON cmt.shop_store_category_id = c.store_category_id
2333
+ SET
2334
+ cmt.store_category_id = c.store_category_id,
2335
+ cmt.parent_store_category_id = c.parent_store_category_id,
2336
+ cmt.category_name = c.category_name,
2337
+ cmt.order_number = c.order_number,
2338
+ cmt.products_within_this_category = c.products_within_this_category";
2339
+ echo("\n\n$query\n\n");
2340
+ $this->db_do($query);
2341
+
2342
+
2343
+ $query = "
2344
+ UPDATE $stINch_categories_mapping_temp cmt
2345
+ JOIN $catalog_category_entity_backup cce
2346
+ ON cmt.parent_store_category_id = cce.store_category_id
2347
+ SET cmt.shop_parent_id = cce.entity_id";
2348
+ echo("\n\n$query\n\n");
2349
+ $this->db_do($query);
2350
+
2351
+
2352
+ $query = "
2353
+ SELECT DISTINCT
2354
+ c.RootName, cce.entity_id
2355
+ FROM $categories_temp c
2356
+ JOIN $catalog_category_entity_varchar ccev
2357
+ ON c.RootName = ccev.value
2358
+ AND ccev.entity_type_id = $_categoryEntityTypeId
2359
+ AND ccev.attribute_id = $name_attrid
2360
+ AND ccev.store_id = 0
2361
+ JOIN $catalog_category_entity_backup cce
2362
+ ON ccev.entity_id = cce.entity_id";
2363
+ echo("\n\n$query\n\n");
2364
+ $root_categories = $this->db_do($query);
2365
+
2366
+ while ($root_cat = mysqli_fetch_array($root_categories)) {
2367
+ $root_id = $root_cat['entity_id'];
2368
+ $root_name = $root_cat['RootName'];
2369
+
2370
+ $query = "
2371
+ UPDATE $stINch_categories_mapping_temp cmt
2372
+ JOIN $categories_temp c
2373
+ ON cmt.shop_store_category_id = c.store_category_id
2374
+ SET
2375
+ cmt.shop_parent_id = $root_id,
2376
+ cmt.shop_parent_store_category_id = $root_id,
2377
+ cmt.parent_store_category_id = $root_id,
2378
+ c.parent_store_category_id = $root_id
2379
+ WHERE RootName = '$root_name'
2380
+ AND cmt.shop_parent_id = 0";
2381
+ echo("\n\n$query\n\n");
2382
+ $this->db_do($query);
2383
+ }
2384
+ }
2385
+ // (end) backup Category ID in REWRITE mode
2386
+ } else {
2387
+ $query = "
2388
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
2389
+ (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
2390
+ (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
2391
+ FROM $catalog_category_entity)";
2392
+ $this->db_do($query);
2393
+
2394
+ $query = "
2395
+ UPDATE $stINch_categories_mapping_temp cmt
2396
+ JOIN $categories_temp c
2397
+ ON cmt.shop_store_category_id = c.store_category_id
2398
+ SET
2399
+ cmt.store_category_id = c.store_category_id,
2400
+ cmt.parent_store_category_id = c.parent_store_category_id,
2401
+ cmt.category_name = c.category_name,
2402
+ cmt.order_number = c.order_number,
2403
+ cmt.products_within_this_category = c.products_within_this_category";
2404
+ echo("\n\n$query\n\n");
2405
+ $this->db_do($query);
2406
+
2407
+
2408
+ $query = "
2409
+ UPDATE $stINch_categories_mapping_temp cmt
2410
+ JOIN $catalog_category_entity cce
2411
+ ON cmt.parent_store_category_id = cce.store_category_id
2412
+ SET cmt.shop_parent_id = cce.entity_id";
2413
+ echo("\n\n$query\n\n");
2414
+ $this->db_do($query);
2415
+
2416
+
2417
+ $query = "
2418
+ SELECT DISTINCT
2419
+ c.RootName, cce.entity_id
2420
+ FROM $categories_temp c
2421
+ JOIN $catalog_category_entity_varchar ccev
2422
+ ON c.RootName = ccev.value
2423
+ AND ccev.entity_type_id = $_categoryEntityTypeId
2424
+ AND ccev.attribute_id = $name_attrid
2425
+ AND ccev.store_id = 0
2426
+ JOIN $catalog_category_entity cce
2427
+ ON ccev.entity_id = cce.entity_id";
2428
+ echo("\n\n$query\n\n");
2429
+ $root_categories = $this->db_do($query);
2430
+
2431
+ while ($root_cat = mysqli_fetch_array($root_categories)) {
2432
+ $root_id = $root_cat['entity_id'];
2433
+ $root_name = $root_cat['RootName'];
2434
+
2435
+ $query = "
2436
+ UPDATE $stINch_categories_mapping_temp cmt
2437
+ JOIN $categories_temp c
2438
+ ON cmt.shop_store_category_id = c.store_category_id
2439
+ SET
2440
+ cmt.shop_parent_id = $root_id,
2441
+ cmt.shop_parent_store_category_id = $root_id,
2442
+ cmt.parent_store_category_id = $root_id,
2443
+ c.parent_store_category_id = $root_id
2444
+ WHERE RootName = '$root_name'
2445
+ AND cmt.shop_parent_id = 0";
2446
+ echo("\n\n$query\n\n");
2447
+ $this->db_do($query);
2448
+ }
2449
+ }
2450
 
2451
+ // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
2452
+ if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
2453
+ else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
2454
+
2455
+ $query = "
2456
+ UPDATE $stINch_categories_mapping_temp cmt
2457
+ JOIN $catalog_category_entity cce
2458
+ ON cmt.shop_entity_id = cce.entity_id
2459
+ SET cce.parent_id = cmt.shop_parent_id
2460
+ $where";
2461
+ echo("\n\n$query\n\n");
2462
+ $this->db_do($query);
2463
+ $this->_LOG("Execute function mapSinchCategoriesMultistore");
2464
+ $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
2465
+ echo("\n\n$query\n\n");
2466
+ $this->db_do($query);
2467
+
2468
+ $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
2469
+ echo("\n\n$query\n\n");
2470
+ $this->db_do($query);
2471
+
2472
+ echo("\nmapSinchCategoriesMultistore done... \n==========================================================================\n\n\n\n");
2473
+ }
2474
 
2475
+ #################################################################################################
2476
 
2477
+ private function createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping)
2478
+ {
2479
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
2480
+ $this->db_do("
2481
+ CREATE TABLE $stINch_categories_mapping_temp
2482
+ (
2483
+ shop_entity_id INT(11) UNSIGNED NOT NULL,
2484
+ shop_entity_type_id INT(11),
2485
+ shop_attribute_set_id INT(11),
2486
+ shop_parent_id INT(11),
2487
+ shop_store_category_id INT(11),
2488
+ shop_parent_store_category_id INT(11),
2489
+ store_category_id INT(11),
2490
+ parent_store_category_id INT(11),
2491
+ category_name VARCHAR(255),
2492
+ order_number INT(11),
2493
+ products_within_this_category INT(11),
2494
+
2495
+ KEY shop_entity_id (shop_entity_id),
2496
+ KEY shop_parent_id (shop_parent_id),
2497
+ KEY store_category_id (store_category_id),
2498
+ KEY parent_store_category_id (parent_store_category_id),
2499
+ UNIQUE KEY(shop_entity_id)
2500
+ )");
2501
 
 
 
 
 
 
 
 
2502
 
2503
+ $this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
2504
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
2505
 
2506
+ #################################################################################################
2507
 
2508
+ 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,
2509
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
2510
+ $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
2511
+ {
2512
+ echo("\n\n\n\n*************************************************************\nmapSinchCategoriesMultistore start... \n");
2513
+ if (UPDATE_CATEGORY_DATA) {
2514
+ $ignore = '';
2515
+ $on_diplicate_key_update = "
2516
+ ON DUPLICATE KEY UPDATE
2517
+ updated_at = now(),
2518
+ store_category_id = c.store_category_id,
2519
+ level = c.level,
2520
+ children_count = c.children_count,
2521
+ position = c.order_number,
2522
+ parent_store_category_id = c.parent_store_category_id";
2523
+ //level=c.level,
2524
+ //children_count=c.children_count
2525
+ //position=c.order_number,
2526
+ } else {
2527
+ $ignore = 'IGNORE';
2528
+ $on_diplicate_key_update = '';
2529
+ }
2530
 
2531
+ $query = "
2532
+ INSERT $ignore INTO $catalog_category_entity
2533
+ (
2534
+ entity_type_id,
2535
+ attribute_set_id,
2536
+ created_at,
2537
+ updated_at,
2538
+ level,
2539
+ children_count,
2540
+ entity_id,
2541
+ position,
2542
+ parent_id,
2543
+ store_category_id,
2544
+ parent_store_category_id
2545
+ )
2546
+ (SELECT
2547
+ $_categoryEntityTypeId,
2548
+ $_categoryDefault_attribute_set_id,
2549
+ NOW(),
2550
+ NOW(),
2551
+ c.level,
2552
+ c.children_count,
2553
+ scm.shop_entity_id,
2554
+ c.order_number,
2555
+ scm.shop_parent_id,
2556
+ c.store_category_id,
2557
+ c.parent_store_category_id
2558
+ FROM $categories_temp c
2559
+ LEFT JOIN $stINch_categories_mapping scm
2560
+ ON c.store_category_id = scm.store_category_id
2561
+ ) $on_diplicate_key_update";
2562
+ echo("\n\n$query\n\n");
2563
+ $this->db_do($query);
2564
 
2565
+ //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
2566
 
 
2567
 
2568
+ $this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid, true);
2569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2570
 
2571
+ $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
2572
+ while ($row = mysqli_fetch_array($categories)) {
2573
+ $parent_id = $row['parent_id'];
2574
+ $entity_id = $row['entity_id'];
2575
 
2576
+ $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
2577
 
2578
+ $this->db_do("
2579
+ UPDATE $catalog_category_entity
2580
+ SET path = '$path'
2581
+ WHERE entity_id = $entity_id");
2582
+ } // while ($row = mysqli_fetch_array($categories))
2583
 
2584
 
2585
+ ///////////////////////////////////////////////////////
2586
 
2587
 
2588
+ if (UPDATE_CATEGORY_DATA) {
2589
+ echo "Update category_data \n";
 
 
 
 
 
2590
 
2591
+ $q = "
2592
+ INSERT INTO $catalog_category_entity_varchar
2593
+ (
2594
+ entity_type_id,
2595
+ attribute_id,
2596
+ store_id,
2597
+ entity_id,
2598
+ value
2599
+ )
2600
+ (SELECT
2601
+ $_categoryEntityTypeId,
2602
+ $name_attrid,
2603
+ 0,
2604
+ scm.shop_entity_id,
2605
+ c.category_name
2606
+ FROM $categories_temp c
2607
+ JOIN $stINch_categories_mapping scm
2608
+ ON c.store_category_id = scm.store_category_id
2609
+ )
2610
+ ON DUPLICATE KEY UPDATE
2611
+ value = c.category_name";
2612
+ $this->db_do($q);
2613
 
2614
 
2615
+ $q = "
2616
+ INSERT INTO $catalog_category_entity_varchar
2617
+ (
2618
+ entity_type_id,
2619
+ attribute_id,
2620
+ store_id,
2621
+ entity_id,
2622
+ value
2623
+ )
2624
+ (SELECT
2625
+ $_categoryEntityTypeId,
2626
+ $name_attrid,
2627
+ 1,
2628
+ scm.shop_entity_id,
2629
+ c.category_name
2630
+ FROM $categories_temp c
2631
+ JOIN $stINch_categories_mapping scm
2632
+ ON c.store_category_id = scm.store_category_id
2633
+ )
2634
+ ON DUPLICATE KEY UPDATE
2635
+ value = c.category_name";
2636
+ $this->db_do($q);
2637
 
2638
 
2639
+ $q = "
2640
+ INSERT INTO $catalog_category_entity
2641
+ (
2642
+ entity_type_id,
2643
+ attribute_id,
2644
+ store_id,
2645
+ entity_id,
2646
+ value
2647
+ )
2648
+ (SELECT
2649
+ $_categoryEntityTypeId,
2650
+ $attr_is_active,
2651
+ 0,
2652
+ scm.shop_entity_id,
2653
+ 1
2654
+ FROM $categories_temp c
2655
+ JOIN $stINch_categories_mapping scm
2656
+ ON c.store_category_id = scm.store_category_id
2657
+ )
2658
+ ON DUPLICATE KEY UPDATE
2659
+ value = 1";
2660
+ $this->db_do($q);
2661
 
2662
 
2663
+ $q = "
2664
+ INSERT INTO $catalog_category_entity_int
2665
+ (
2666
+ entity_type_id,
2667
+ attribute_id,
2668
+ store_id,
2669
+ entity_id,
2670
+ value
2671
+ )
2672
+ (SELECT
2673
+ $_categoryEntityTypeId,
2674
+ $attr_is_active,
2675
+ 1,
2676
+ scm.shop_entity_id,
2677
+ 1
2678
+ FROM $categories_temp c
2679
+ JOIN $stINch_categories_mapping scm
2680
+ ON c.store_category_id = scm.store_category_id
2681
+ )
2682
+ ON DUPLICATE KEY UPDATE
2683
+ value = 1";
2684
+ $this->db_do($q);
2685
 
2686
 
2687
+ $q = "
2688
+ INSERT INTO $catalog_category_entity_int
2689
+ (
2690
+ entity_type_id,
2691
+ attribute_id,
2692
+ store_id,
2693
+ entity_id,
2694
+ value
2695
+ )
2696
+ (SELECT
2697
+ $_categoryEntityTypeId,
2698
+ $attr_include_in_menu,
2699
+ 0,
2700
+ scm.shop_entity_id,
2701
+ c.include_in_menu
2702
+ FROM $categories_temp c
2703
+ JOIN $stINch_categories_mapping scm
2704
+ ON c.store_category_id = scm.store_category_id
2705
+ )
2706
+ ON DUPLICATE KEY UPDATE
2707
+ value = c.include_in_menu";
2708
+ $this->db_do($q);
2709
 
 
 
 
 
 
 
 
 
 
 
 
 
2710
 
2711
+ $q = "
2712
+ INSERT INTO $catalog_category_entity_int
2713
+ (
2714
+ entity_type_id,
2715
+ attribute_id,
2716
+ store_id,
2717
+ entity_id,
2718
+ value
2719
+ )
2720
+ (SELECT
2721
+ $_categoryEntityTypeId,
2722
+ $is_anchor_attrid,
2723
+ 1,
2724
+ scm.shop_entity_id,
2725
+ c.is_anchor
2726
+ FROM $categories_temp c
2727
+ JOIN $stINch_categories_mapping scm
2728
+ ON c.store_category_id = scm.store_category_id
2729
+ )
2730
+ ON DUPLICATE KEY UPDATE
2731
+ value = c.is_anchor";
2732
+ $this->db_do($q);
2733
 
 
2734
 
2735
+ $q = "
2736
+ INSERT INTO $catalog_category_entity_int
2737
+ (
2738
+ entity_type_id,
2739
+ attribute_id,
2740
+ store_id,
2741
+ entity_id,
2742
+ value
2743
+ )
2744
+ (SELECT
2745
+ $_categoryEntityTypeId,
2746
+ $is_anchor_attrid,
2747
+ 0,
2748
+ scm.shop_entity_id,
2749
+ c.is_anchor
2750
+ FROM $categories_temp c
2751
+ JOIN $stINch_categories_mapping scm
2752
+ ON c.store_category_id = scm.store_category_id
2753
+ )
2754
+ ON DUPLICATE KEY UPDATE
2755
+ value = c.is_anchor";
2756
+ $this->db_do($q);
2757
 
2758
+ $q = "
2759
+ INSERT INTO $catalog_category_entity_varchar
2760
+ (
2761
+ entity_type_id,
2762
+ attribute_id,
2763
+ store_id,
2764
+ entity_id,
2765
+ value
2766
+ )
2767
+ (SELECT
2768
+ $_categoryEntityTypeId,
2769
+ $image_attrid,
2770
+ 0,
2771
+ scm.shop_entity_id,
2772
+ c.categories_image
2773
+ FROM $categories_temp c
2774
+ JOIN $stINch_categories_mapping scm
2775
+ ON c.store_category_id = scm.store_category_id
2776
+ )
2777
+ ON DUPLICATE KEY UPDATE
2778
+ value = c.categories_image";
2779
+ $this->db_do($q);
2780
+ //STP
2781
+ $q = "
2782
+ INSERT INTO $catalog_category_entity_varchar
2783
+ (
2784
+ entity_type_id,
2785
+ attribute_id,
2786
+ store_id,
2787
+ entity_id,
2788
+ value
2789
+ )
2790
+ (SELECT
2791
+ $this->_categoryEntityTypeId,
2792
+ $this->_categoryMetaTitleAttrId,
2793
+ 0,
2794
+ scm.shop_entity_id,
2795
+ c.MetaTitle
2796
+ FROM $categories_temp c
2797
+ JOIN $stINch_categories_mapping scm
2798
+ ON c.store_category_id = scm.store_category_id
2799
+ )
2800
+ ON DUPLICATE KEY UPDATE
2801
+ value = c.MetaTitle";
2802
+ $this->db_do($q);
2803
 
2804
+ $q = "
2805
+ INSERT INTO $catalog_category_entity_varchar
2806
+ (
2807
+ entity_type_id,
2808
+ attribute_id,
2809
+ store_id,
2810
+ entity_id,
2811
+ value
2812
+ )
2813
+ (SELECT
2814
+ $this->_categoryEntityTypeId,
2815
+ $this->_categoryMetadescriptionAttrId,
2816
+ 0,
2817
+ scm.shop_entity_id,
2818
+ c.MetaDescription
2819
+ FROM $categories_temp c
2820
+ JOIN $stINch_categories_mapping scm
2821
+ ON c.store_category_id = scm.store_category_id
2822
+ )
2823
+ ON DUPLICATE KEY UPDATE
2824
+ value = c.MetaDescription";
2825
+ $this->db_do($q);
2826
 
2827
+ $q = "
2828
+ INSERT INTO $catalog_category_entity_varchar
2829
+ (
2830
+ entity_type_id,
2831
+ attribute_id,
2832
+ store_id,
2833
+ entity_id,
2834
+ value
2835
+ )
2836
+ (SELECT
2837
+ $this->_categoryEntityTypeId,
2838
+ $this->_categoryDescriptionAttrId,
2839
+ 0,
2840
+ scm.shop_entity_id,
2841
+ c.Description
2842
+ FROM $categories_temp c
2843
+ JOIN $stINch_categories_mapping scm
2844
+ ON c.store_category_id = scm.store_category_id
2845
+ )
2846
+ ON DUPLICATE KEY UPDATE
2847
+ value = c.Description";
2848
+ $this->db_do($q);
2849
 
 
2850
 
2851
+ //stp
2852
+ } else {
2853
+ echo "Insert ignore category_data \n";
2854
 
2855
+ $q = "
2856
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2857
+ (
2858
+ entity_type_id,
2859
+ attribute_id,
2860
+ store_id,
2861
+ entity_id,
2862
+ value
2863
+ )
2864
+ (SELECT
2865
+ $_categoryEntityTypeId,
2866
+ $name_attrid,
2867
+ 0,
2868
+ scm.shop_entity_id,
2869
+ c.category_name
2870
+ FROM $categories_temp c
2871
+ JOIN $stINch_categories_mapping scm
2872
+ ON c.store_category_id = scm.store_category_id
2873
+ )";
2874
+ $this->db_do($q);
2875
 
2876
 
2877
+ $q = "
2878
+ INSERT IGNORE INTO $catalog_category_entity_int
2879
+ (
2880
+ entity_type_id,
2881
+ attribute_id,
2882
+ store_id,
2883
+ entity_id,
2884
+ value
2885
+ )
2886
+ (SELECT
2887
+ $_categoryEntityTypeId,
2888
+ $attr_is_active,
2889
+ 0,
2890
+ scm.shop_entity_id,
2891
+ 1
2892
+ FROM $categories_temp c
2893
+ JOIN $stINch_categories_mapping scm
2894
+ ON c.store_category_id = scm.store_category_id
2895
+ )";
2896
+ $this->db_do($q);
2897
 
 
 
 
 
 
 
2898
 
2899
+ $q = "
2900
+ INSERT IGNORE INTO $catalog_category_entity_int
2901
+ (
2902
+ entity_type_id,
2903
+ attribute_id,
2904
+ store_id,
2905
+ entity_id,
2906
+ value
2907
+ )
2908
+ (SELECT
2909
+ $_categoryEntityTypeId,
2910
+ $attr_include_in_menu,
2911
+ 0,
2912
+ scm.shop_entity_id,
2913
+ c.include_in_menu
2914
+ FROM $categories_temp c
2915
+ JOIN $stINch_categories_mapping scm
2916
+ ON c.store_category_id = scm.store_category_id
2917
+ )";
2918
+ $this->db_do($q);
2919
 
2920
 
2921
+ $q = "
2922
+ INSERT IGNORE INTO $catalog_category_entity_int
2923
+ (
2924
+ entity_type_id,
2925
+ attribute_id,
2926
+ store_id,
2927
+ entity_id,
2928
+ value
2929
+ )
2930
+ (SELECT
2931
+ $_categoryEntityTypeId,
2932
+ $is_anchor_attrid,
2933
+ 0,
2934
+ scm.shop_entity_id,
2935
+ c.is_anchor
2936
+ FROM $categories_temp c
2937
+ JOIN $stINch_categories_mapping scm
2938
+ ON c.store_category_id = scm.store_category_id
2939
+ )";
2940
+ $this->db_do($q);
2941
 
 
2942
 
2943
+ $q = "
2944
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2945
+ (
2946
+ entity_type_id,
2947
+ attribute_id,
2948
+ store_id,
2949
+ entity_id,
2950
+ value
2951
+ )
2952
+ (SELECT
2953
+ $_categoryEntityTypeId,
2954
+ $image_attrid,
2955
+ 0,
2956
+ scm.shop_entity_id,
2957
+ c.categories_image
2958
+ FROM $categories_temp c
2959
+ JOIN $stINch_categories_mapping scm
2960
+ ON c.store_category_id = scm.store_category_id
2961
+ )";
2962
+ $this->db_do($q);
2963
+ //STP
2964
+ $q = "
2965
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2966
+ (
2967
+ entity_type_id,
2968
+ attribute_id,
2969
+ store_id,
2970
+ entity_id,
2971
+ value
2972
+ )
2973
+ (SELECT
2974
+ $this->_categoryEntityTypeId,
2975
+ $this->_categoryMetaTitleAttrId,
2976
+ 0,
2977
+ scm.shop_entity_id,
2978
+ c.MetaTitle
2979
+ FROM $categories_temp c
2980
+ JOIN $stINch_categories_mapping scm
2981
+ ON c.store_category_id = scm.store_category_id
2982
+ )
2983
+ ";
2984
+ $this->db_do($q);
2985
 
2986
+ $q = "
2987
+ INSERT IGNORE INTO $catalog_category_entity_varchar
2988
+ (
2989
+ entity_type_id,
2990
+ attribute_id,
2991
+ store_id,
2992
+ entity_id,
2993
+ value
2994
+ )
2995
+ (SELECT
2996
+ $this->_categoryEntityTypeId,
2997
+ $this->_categoryMetadescriptionAttrId,
2998
+ 0,
2999
+ scm.shop_entity_id,
3000
+ c.MetaDescription
3001
+ FROM $categories_temp c
3002
+ JOIN $stINch_categories_mapping scm
3003
+ ON c.store_category_id = scm.store_category_id
3004
+ )
3005
+ ";
3006
+ $this->db_do($q);
3007
 
3008
+ $q = "
3009
+ INSERT IGNORE INTO $catalog_category_entity_varchar
3010
+ (
3011
+ entity_type_id,
3012
+ attribute_id,
3013
+ store_id,
3014
+ entity_id,
3015
+ value
3016
+ )
3017
+ (SELECT
3018
+ $this->_categoryEntityTypeId,
3019
+ $this->_categoryDescriptionAttrId,
3020
+ 0,
3021
+ scm.shop_entity_id,
3022
+ c.Description
3023
+ FROM $categories_temp c
3024
+ JOIN $stINch_categories_mapping scm
3025
+ ON c.store_category_id = scm.store_category_id
3026
+ )
3027
+ ";
3028
+ $this->db_do($q);
3029
 
 
3030
 
3031
+ //stp
3032
 
3033
+ }
3034
 
3035
+ $this->delete_old_sinch_categories_from_shop();
3036
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
3037
+ $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
3038
+ }
3039
 
3040
+ #################################################################################################
3041
 
3042
+ function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
3043
+ {
3044
 
3045
+ //echo("\nparent_id = [$parent_id] ent_id = [$ent_id]");
 
3046
 
3047
+ $path = '';
3048
 
3049
+ $cat_id = $parent_id;
3050
 
3051
+ $q = "
3052
+ SELECT
3053
+ parent_id
3054
+ FROM $catalog_category_entity
3055
+ WHERE entity_id = $cat_id";
3056
+ $quer = $this->db_do($q);
3057
+ $row = mysqli_fetch_array($quer);
3058
+ while ($row['parent_id']) {
3059
+ $path = $row['parent_id'] . '/' . $path;
3060
+ $parent_id = $row['parent_id'];
3061
 
3062
+ $q = "
3063
+ SELECT
3064
+ parent_id
3065
+ FROM $catalog_category_entity
3066
+ WHERE entity_id = $parent_id";
3067
+ $quer = $this->db_do($q);
3068
+ $row = mysqli_fetch_array($quer);
3069
+ }
 
 
3070
 
3071
+ if ($cat_id) $path .= $cat_id . "/";
 
 
 
 
3072
 
3073
+ if ($path) $path .= $ent_id;
3074
+ else $path = $ent_id;
3075
 
3076
+ //echo(" path = [$path]\n");
 
 
 
 
 
 
 
 
 
 
3077
 
3078
+ return $path;
3079
+ }
3080
 
3081
+ #################################################################################################
 
 
 
 
 
3082
 
3083
+ private function mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
3084
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
3085
+ $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
3086
+ $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
3087
+ {
3088
+ echo("mergeMultistoreCategories RUN\n");
3089
 
 
 
 
 
 
 
3090
 
3091
+ $this->createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
3092
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
3093
 
 
3094
 
3095
+ $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
3096
 
3097
 
3098
+ $this->addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
3099
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
3100
+ $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
 
 
 
3101
 
 
3102
 
3103
+ echo("\n\n\nmergeMultistoreCategories DONE\n");
3104
+ }
3105
 
3106
+ #################################################################################################
3107
 
3108
+ private function createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
3109
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
3110
+ {
3111
+ echo("\n\n ==========================================================================\n createNewDefaultCategories start... \n");
3112
+
3113
+ $old_cats = array();
3114
+ $query = $this->db_do("
3115
+ SELECT
3116
+ cce.entity_id,
3117
+ ccev.value AS category_name
3118
+ FROM $catalog_category_entity cce
3119
+ JOIN $catalog_category_entity_varchar ccev
3120
+ ON cce.entity_id = ccev.entity_id
3121
+ AND ccev.store_id = 0
3122
+ AND cce.entity_type_id = ccev.entity_type_id
3123
+ AND ccev.attribute_id = 41
3124
+ WHERE parent_id = 1"); // 41 - category name
3125
+ while ($row = mysqli_fetch_array($query)) $old_cats[] = $row['category_name'];
3126
 
3127
+ //var_dump($old_cats);
3128
 
3129
 
3130
+ $query = $this->db_do("SELECT MAX(entity_id) AS max_entity_id FROM $catalog_category_entity");
3131
+ $max_entity_id = mysqli_fetch_array($query);
3132
 
3133
+ //var_dump($max_entity_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
3134
 
3135
+ $i = $max_entity_id[max_entity_id] + 1;
3136
 
3137
+ foreach ($coincidence as $key => $item) {
3138
+ echo("\n coincidence: key = [$key]\n");
3139
 
 
3140
 
3141
+ /**if ($item)
3142
+ * {
3143
+ * echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> CONTINUE: key = [$key] item = [$item]\n");
3144
+ * //continue;
3145
+ * }
3146
+ * else
3147
+ * {
3148
+ * echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> NOT CONTINUE: key = [$key] item = [$item]\n");
3149
+ * }/**/
3150
 
3151
 
3152
+ if (in_array($key, $old_cats)) {
3153
+ echo(" CONTINUE: key = [$key] item = [$item]\n");
3154
+ continue;
3155
+ } else {
3156
+ echo(" CREATE NEW CATEGORY: key = [$key] item = [$item]\n");
3157
+ }
3158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3159
 
3160
+ $this->db_do("INSERT $catalog_category_entity
3161
+ (entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
3162
+ path, position, level, children_count, store_category_id, parent_store_category_id)
3163
+ VALUES
3164
+ ($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 1, NULL, NULL)");
3165
 
3166
 
3167
+ $this->db_do("INSERT $catalog_category_entity_varchar
3168
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3169
+ VALUES
3170
+ ($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
3171
+ ($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
3172
+ ($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
3173
+ ($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
3174
 
 
 
 
 
 
 
 
3175
 
3176
+ $this->db_do("INSERT $catalog_category_entity_int
3177
+ (entity_type_id, attribute_id, store_id, entity_id, value)
3178
+ VALUES
3179
+ ($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
3180
+ ($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
3181
+ ($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
3182
+ ($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
3183
+ $i++;
3184
+ } // foreach($coincidence as $key => $item)
3185
 
3186
+ echo("\n createNewDefaultCategories done... \n ==========================================================================\n");
3187
 
3188
+ }
3189
 
3190
+ #################################################################################################
3191
 
3192
+ private function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
3193
+ {
3194
+ echo("\n\n\ ==========================================================================\n mapSinchCategoriesMultistore start... \n");
3195
+
3196
+ $this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
3197
+
3198
+ $query = "
3199
+ INSERT IGNORE INTO $stINch_categories_mapping_temp
3200
+ (shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
3201
+ (SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
3202
+ FROM $catalog_category_entity)";
3203
+ echo("\n $query\n");
3204
+ $this->db_do($query);
3205
+
3206
+
3207
+ $query = "
3208
+ UPDATE $stINch_categories_mapping_temp cmt
3209
+ JOIN $categories_temp c
3210
+ ON cmt.shop_store_category_id = c.store_category_id
3211
+ SET
3212
+ cmt.store_category_id = c.store_category_id,
3213
+ cmt.parent_store_category_id = c.parent_store_category_id,
3214
+ cmt.category_name = c.category_name,
3215
+ cmt.order_number = c.order_number,
3216
+ cmt.products_within_this_category = c.products_within_this_category";
3217
+ echo("\n $query\n");
3218
+ $this->db_do($query);
3219
+
3220
+
3221
+ $query = "
3222
+ UPDATE $stINch_categories_mapping_temp cmt
3223
+ JOIN $catalog_category_entity cce
3224
+ ON cmt.parent_store_category_id = cce.store_category_id
3225
+ SET cmt.shop_parent_id = cce.entity_id";
3226
+ echo("\n $query\n");
3227
+ $this->db_do($query);
3228
+
3229
+
3230
+ $query = "
3231
+ SELECT DISTINCT
3232
+ c.RootName, cce.entity_id
3233
+ FROM $categories_temp c
3234
+ JOIN $catalog_category_entity_varchar ccev
3235
+ ON c.RootName = ccev.value
3236
+ AND ccev.entity_type_id = $_categoryEntityTypeId
3237
+ AND ccev.attribute_id = $name_attrid
3238
+ AND ccev.store_id = 0
3239
+ JOIN $catalog_category_entity cce
3240
+ ON ccev.entity_id = cce.entity_id";
3241
+ echo("\n $query\n");
3242
+ $root_categories = $this->db_do($query);
3243
+
3244
+ while ($root_cat = mysqli_fetch_array($root_categories)) {
3245
+ $root_id = $root_cat['entity_id'];
3246
+ $root_name = $root_cat['RootName'];
3247
+
3248
+ $query = "
3249
+ UPDATE $stINch_categories_mapping_temp cmt
3250
+ JOIN $categories_temp c
3251
+ ON cmt.shop_store_category_id = c.store_category_id
3252
+ SET
3253
+ cmt.shop_parent_id = $root_id,
3254
+ cmt.shop_parent_store_category_id = $root_id,
3255
+ cmt.parent_store_category_id = $root_id,
3256
+ c.parent_store_category_id = $root_id
3257
+ WHERE RootName = '$root_name'
3258
+ AND cmt.shop_parent_id = 0";
3259
+ echo("\n $query\n");
3260
+ $this->db_do($query);
3261
+ }
3262
 
3263
 
3264
+ // added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
3265
+ if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
3266
+ else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
 
 
 
 
 
 
 
 
 
 
 
 
3267
 
3268
+ $query = "
3269
+ UPDATE $stINch_categories_mapping_temp cmt
3270
+ JOIN $catalog_category_entity cce
3271
+ ON cmt.shop_entity_id = cce.entity_id
3272
+ SET cce.parent_id = cmt.shop_parent_id
3273
+ $where";
3274
+ echo("\n $query\n");
3275
+ $this->db_do($query);
3276
 
3277
+ $query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
3278
+ echo("\n $query\n");
3279
+ $this->db_do($query);
3280
 
3281
+ $query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
3282
+ echo("\n $query\n");
3283
+ $this->db_do($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3284
 
3285
+ echo("\n mapSinchCategoriesMultistore done... \n ==========================================================================\n\n\n\n");
3286
+ }
3287
 
3288
+ #################################################################################################
3289
 
3290
+ 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,
3291
+ $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
3292
+ $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
3293
+ {
3294
+ echo("\n\n\n\n *************************************************************\n addCategoryDataMultistoreMerge start... \n");
3295
 
3296
 
3297
+ if (UPDATE_CATEGORY_DATA) {
3298
+ $ignore = '';
3299
+ $on_diplicate_key_update = "
3300
+ ON DUPLICATE KEY UPDATE
3301
+ updated_at = now(),
3302
+ store_category_id = c.store_category_id,
3303
+ level = c.level,
3304
+ children_count = c.children_count,
3305
+ position = c.order_number,
3306
+ parent_store_category_id = c.parent_store_category_id";
3307
+ //level=c.level,
3308
+ //children_count=c.children_count
3309
+ //position=c.order_number,
3310
+ } else {
3311
+ $ignore = 'IGNORE';
3312
+ $on_diplicate_key_update = '';
3313
+ }
3314
 
3315
+ $query = "
3316
+ INSERT $ignore INTO $catalog_category_entity
3317
+ (
3318
+ entity_type_id,
3319
+ attribute_set_id,
3320
+ created_at,
3321
+ updated_at,
3322
+ level,
3323
+ children_count,
3324
+ entity_id,
3325
+ position,
3326
+ parent_id,
3327
+ store_category_id,
3328
+ parent_store_category_id
3329
+ )
3330
+ (SELECT
3331
+ $_categoryEntityTypeId,
3332
+ $_categoryDefault_attribute_set_id,
3333
+ NOW(),
3334
+ NOW(),
3335
+ c.level,
3336
+ c.children_count,
3337
+ scm.shop_entity_id,
3338
+ c.order_number,
3339
+ scm.shop_parent_id,
3340
+ c.store_category_id,
3341
+ c.parent_store_category_id
3342
+ FROM $categories_temp c
3343
+ LEFT JOIN $stINch_categories_mapping scm
3344
+ ON c.store_category_id = scm.store_category_id
3345
+ ) $on_diplicate_key_update";
3346
+ echo("\n\n $query\n\n");
3347
+ $this->db_do($query);
3348
+
3349
+
3350
+ $this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
3351
+
3352
+
3353
+ $categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
3354
+ while ($row = mysqli_fetch_array($categories)) {
3355
+ $parent_id = $row['parent_id'];
3356
+ $entity_id = $row['entity_id'];
3357
+
3358
+ $path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
3359
+
3360
+ $this->db_do("
3361
+ UPDATE $catalog_category_entity
3362
+ SET path = '$path'
3363
+ WHERE entity_id = $entity_id");
3364
+ } // while ($row = mysqli_fetch_array($categories))
3365
 
 
 
 
 
 
 
 
3366
 
3367
+ ///////////////////////////////////////////////////////
3368
 
3369
 
3370
+ if (UPDATE_CATEGORY_DATA) {
3371
+ echo "Update category_data \n";
3372
 
3373
+ $q = "
3374
+ INSERT INTO $catalog_category_entity_varchar
3375
+ (
3376
+ entity_type_id,
3377
+ attribute_id,
3378
+ store_id,
3379
+ entity_id,
3380
+ value
3381
+ )
3382
+ (SELECT
3383
+ $_categoryEntityTypeId,
3384
+ $name_attrid,
3385
+ 0,
3386
+ scm.shop_entity_id,
3387
+ c.category_name
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 = c.category_name";
3394
+ $this->db_do($q);
3395
 
3396
 
3397
+ $q = "
3398
+ INSERT INTO $catalog_category_entity_varchar
3399
+ (
3400
+ entity_type_id,
3401
+ attribute_id,
3402
+ store_id,
3403
+ entity_id,
3404
+ value
3405
+ )
3406
+ (SELECT
3407
+ $_categoryEntityTypeId,
3408
+ $name_attrid,
3409
+ 1,
3410
+ scm.shop_entity_id,
3411
+ c.category_name
3412
+ FROM $categories_temp c
3413
+ JOIN $stINch_categories_mapping scm
3414
+ ON c.store_category_id = scm.store_category_id
3415
+ )
3416
+ ON DUPLICATE KEY UPDATE
3417
+ value = c.category_name";
3418
+ $this->db_do($q);
3419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3420
 
3421
+ $q = "
3422
+ INSERT INTO $catalog_category_entity
3423
+ (
3424
+ entity_type_id,
3425
+ attribute_id,
3426
+ store_id,
3427
+ entity_id,
3428
+ value
3429
+ )
3430
+ (SELECT
3431
+ $_categoryEntityTypeId,
3432
+ $attr_is_active,
3433
+ 0,
3434
+ scm.shop_entity_id,
3435
+ 1
3436
+ FROM $categories_temp c
3437
+ JOIN $stINch_categories_mapping scm
3438
+ ON c.store_category_id = scm.store_category_id
3439
+ )
3440
+ ON DUPLICATE KEY UPDATE
3441
+ value = 1";
3442
+ $this->db_do($q);
3443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3444
 
3445
+ $q = "
3446
+ INSERT INTO $catalog_category_entity_int
3447
+ (
3448
+ entity_type_id,
3449
+ attribute_id,
3450
+ store_id,
3451
+ entity_id,
3452
+ value
3453
+ )
3454
+ (SELECT
3455
+ $_categoryEntityTypeId,
3456
+ $attr_is_active,
3457
+ 1,
3458
+ scm.shop_entity_id,
3459
+ 1
3460
+ FROM $categories_temp c
3461
+ JOIN $stINch_categories_mapping scm
3462
+ ON c.store_category_id = scm.store_category_id
3463
+ )
3464
+ ON DUPLICATE KEY UPDATE
3465
+ value = 1";
3466
+ $this->db_do($q);
3467
 
 
3468
 
3469
+ $q = "
3470
+ INSERT INTO $catalog_category_entity_int
3471
+ (
3472
+ entity_type_id,
3473
+ attribute_id,
3474
+ store_id,
3475
+ entity_id,
3476
+ value
3477
+ )
3478
+ (SELECT
3479
+ $_categoryEntityTypeId,
3480
+ $attr_include_in_menu,
3481
+ 0,
3482
+ scm.shop_entity_id,
3483
+ c.include_in_menu
3484
+ FROM $categories_temp c
3485
+ JOIN $stINch_categories_mapping scm
3486
+ ON c.store_category_id = scm.store_category_id
3487
+ )
3488
+ ON DUPLICATE KEY UPDATE
3489
+ value = c.include_in_menu";
3490
+ $this->db_do($q);
3491
 
 
3492
 
3493
+ $q = "
3494
+ INSERT INTO $catalog_category_entity_int
3495
+ (
3496
+ entity_type_id,
3497
+ attribute_id,
3498
+ store_id,
3499
+ entity_id,
3500
+ value
3501
+ )
3502
+ (SELECT
3503
+ $_categoryEntityTypeId,
3504
+ $is_anchor_attrid,
3505
+ 1,
3506
+ scm.shop_entity_id,
3507
+ c.is_anchor
3508
+ FROM $categories_temp c
3509
+ JOIN $stINch_categories_mapping scm
3510
+ ON c.store_category_id = scm.store_category_id
3511
+ )
3512
+ ON DUPLICATE KEY UPDATE
3513
+ value = c.is_anchor";
3514
+ $this->db_do($q);
3515
 
 
3516
 
3517
+ $q = "
3518
+ INSERT INTO $catalog_category_entity_int
3519
+ (
3520
+ entity_type_id,
3521
+ attribute_id,
3522
+ store_id,
3523
+ entity_id,
3524
+ value
3525
+ )
3526
+ (SELECT
3527
+ $_categoryEntityTypeId,
3528
+ $is_anchor_attrid,
3529
+ 0,
3530
+ scm.shop_entity_id,
3531
+ c.is_anchor
3532
+ FROM $categories_temp c
3533
+ JOIN $stINch_categories_mapping scm
3534
+ ON c.store_category_id = scm.store_category_id
3535
+ )
3536
+ ON DUPLICATE KEY UPDATE
3537
+ value = c.is_anchor";
3538
+ $this->db_do($q);
3539
 
3540
+ $q = "
3541
+ INSERT INTO $catalog_category_entity_varchar
3542
+ (
3543
+ entity_type_id,
3544
+ attribute_id,
3545
+ store_id,
3546
+ entity_id,
3547
+ value
3548
+ )
3549
+ (SELECT
3550
+ $_categoryEntityTypeId,
3551
+ $image_attrid,
3552
+ 0,
3553
+ scm.shop_entity_id,
3554
+ c.categories_image
3555
+ FROM $categories_temp c
3556
+ JOIN $stINch_categories_mapping scm
3557
+ ON c.store_category_id = scm.store_category_id
3558
+ )
3559
+ ON DUPLICATE KEY UPDATE
3560
+ value = c.categories_image";
3561
+ $this->db_do($q);
3562
+ //STP
3563
+ $q = "
3564
+ INSERT INTO $catalog_category_entity_varchar
3565
+ (
3566
+ entity_type_id,
3567
+ attribute_id,
3568
+ store_id,
3569
+ entity_id,
3570
+ value
3571
+ )
3572
+ (SELECT
3573
+ $this->_categoryEntityTypeId,
3574
+ $this->_categoryMetaTitleAttrId,
3575
+ 0,
3576
+ scm.shop_entity_id,
3577
+ c.MetaTitle
3578
+ FROM $categories_temp c
3579
+ JOIN $stINch_categories_mapping scm
3580
+ ON c.store_category_id = scm.store_category_id
3581
+ )
3582
+ ON DUPLICATE KEY UPDATE
3583
+ value = c.MetaTitle";
3584
+ $this->db_do($q);
3585
 
3586
+ $q = "
3587
+ INSERT INTO $catalog_category_entity_varchar
3588
+ (
3589
+ entity_type_id,
3590
+ attribute_id,
3591
+ store_id,
3592
+ entity_id,
3593
+ value
3594
+ )
3595
+ (SELECT
3596
+ $this->_categoryEntityTypeId,
3597
+ $this->_categoryMetadescriptionAttrId,
3598
+ 0,
3599
+ scm.shop_entity_id,
3600
+ c.MetaDescription
3601
+ FROM $categories_temp c
3602
+ JOIN $stINch_categories_mapping scm
3603
+ ON c.store_category_id = scm.store_category_id
3604
+ )
3605
+ ON DUPLICATE KEY UPDATE
3606
+ value = c.MetaDescription";
3607
+ $this->db_do($q);
3608
 
3609
+ $q = "
3610
+ INSERT INTO $catalog_category_entity_varchar
3611
+ (
3612
+ entity_type_id,
3613
+ attribute_id,
3614
+ store_id,
3615
+ entity_id,
3616
+ value
3617
+ )
3618
+ (SELECT
3619
+ $this->_categoryEntityTypeId,
3620
+ $this->_categoryDescriptionAttrId,
3621
+ 0,
3622
+ scm.shop_entity_id,
3623
+ c.Description
3624
+ FROM $categories_temp c
3625
+ JOIN $stINch_categories_mapping scm
3626
+ ON c.store_category_id = scm.store_category_id
3627
+ )
3628
+ ON DUPLICATE KEY UPDATE
3629
+ value = c.Description";
3630
+ $this->db_do($q);
3631
 
 
 
 
 
 
 
3632
 
3633
+ //stp
3634
+ } else {
3635
+ echo "Insert ignore category_data \n";
3636
 
3637
 
3638
+ $q = "
3639
+ INSERT IGNORE INTO $catalog_category_entity_varchar
3640
+ (
3641
+ entity_type_id,
3642
+ attribute_id,
3643
+ store_id,
3644
+ entity_id,
3645
+ value
3646
+ )
3647
+ (SELECT
3648
+ $_categoryEntityTypeId,
3649
+ $name_attrid,
3650
+ 0,
3651
+ scm.shop_entity_id,
3652
+ c.category_name
3653
+ FROM $categories_temp c
3654
+ JOIN $stINch_categories_mapping scm
3655
+ ON c.store_category_id = scm.store_category_id
3656
+ )";
3657
+ $this->db_do($q);
3658
 
3659
 
3660
+ $q = "
3661
+ INSERT IGNORE INTO $catalog_category_entity_int
3662
+ (
3663
+ entity_type_id,
3664
+ attribute_id,
3665
+ store_id,
3666
+ entity_id,
3667
+ value
3668
+ )
3669
+ (SELECT
3670
+ $_categoryEntityTypeId,
3671
+ $attr_is_active,
3672
+ 0,
3673
+ scm.shop_entity_id,
3674
+ 1
3675
+ FROM $categories_temp c
3676
+ JOIN $stINch_categories_mapping scm
3677
+ ON c.store_category_id = scm.store_category_id
3678
+ )";
3679
+ $this->db_do($q);
3680
 
3681
 
3682
+ $q = "
3683
+ INSERT IGNORE INTO $catalog_category_entity_int
3684
+ (
3685
+ entity_type_id,
3686
+ attribute_id,
3687
+ store_id,
3688
+ entity_id,
3689
+ value
3690
+ )
3691
+ (SELECT
3692
+ $_categoryEntityTypeId,
3693
+ $attr_include_in_menu,
3694
+ 0,
3695
+ scm.shop_entity_id,
3696
+ c.include_in_menu
3697
+ FROM $categories_temp c
3698
+ JOIN $stINch_categories_mapping scm
3699
+ ON c.store_category_id = scm.store_category_id
3700
+ )";
3701
+ $this->db_do($q);
3702
 
3703
 
3704
+ $q = "
3705
+ INSERT IGNORE INTO $catalog_category_entity_int
3706
+ (
3707
+ entity_type_id,
3708
+ attribute_id,
3709
+ store_id,
3710
+ entity_id,
3711
+ value
3712
+ )
3713
+ (SELECT
3714
+ $_categoryEntityTypeId,
3715
+ $is_anchor_attrid,
3716
+ 0,
3717
+ scm.shop_entity_id,
3718
+ c.is_anchor
3719
+ FROM $categories_temp c
3720
+ JOIN $stINch_categories_mapping scm
3721
+ ON c.store_category_id = scm.store_category_id
3722
+ )";
3723
+ $this->db_do($q);
3724
 
3725
 
3726
+ $q = "
3727
+ INSERT IGNORE INTO $catalog_category_entity_varchar
3728
+ (
3729
+ entity_type_id,
3730
+ attribute_id,
3731
+ store_id,
3732
+ entity_id,
3733
+ value
3734
+ )
3735
+ (SELECT
3736
+ $_categoryEntityTypeId,
3737
+ $image_attrid,
3738
+ 0,
3739
+ scm.shop_entity_id,
3740
+ c.categories_image
3741
+ FROM $categories_temp c
3742
+ JOIN $stINch_categories_mapping scm
3743
+ ON c.store_category_id = scm.store_category_id
3744
+ )";
3745
+ $this->db_do($q);
3746
+ //STP
3747
+ $q = "
3748
+ INSERT IGNORE INTO $catalog_category_entity_varchar
3749
+ (
3750
+ entity_type_id,
3751
+ attribute_id,
3752
+ store_id,
3753
+ entity_id,
3754
+ value
3755
+ )
3756
+ (SELECT
3757
+ $this->_categoryEntityTypeId,
3758
+ $this->_categoryMetaTitleAttrId,
3759
+ 0,
3760
+ scm.shop_entity_id,
3761
+ c.MetaTitle
3762
+ FROM $categories_temp c
3763
+ JOIN $stINch_categories_mapping scm
3764
+ ON c.store_category_id = scm.store_category_id
3765
+ )
3766
+ ";
3767
+ $this->db_do($q);
3768
 
3769
+ $q = "
3770
+ INSERT IGNORE INTO $catalog_category_entity_varchar
3771
+ (
3772
+ entity_type_id,
3773
+ attribute_id,
3774
+ store_id,
3775
+ entity_id,
3776
+ value
3777
+ )
3778
+ (SELECT
3779
+ $this->_categoryEntityTypeId,
3780
+ $this->_categoryMetadescriptionAttrId,
3781
+ 0,
3782
+ scm.shop_entity_id,
3783
+ c.MetaDescription
3784
+ FROM $categories_temp c
3785
+ JOIN $stINch_categories_mapping scm
3786
+ ON c.store_category_id = scm.store_category_id
3787
+ )
3788
+ ";
3789
+ $this->db_do($q);
3790
 
3791
+ $q = "
3792
+ INSERT IGNORE INTO $catalog_category_entity_varchar
3793
+ (
3794
+ entity_type_id,
3795
+ attribute_id,
3796
+ store_id,
3797
+ entity_id,
3798
+ value
3799
+ )
3800
+ (SELECT
3801
+ $this->_categoryEntityTypeId,
3802
+ $this->_categoryDescriptionAttrId,
3803
+ 0,
3804
+ scm.shop_entity_id,
3805
+ c.Description
3806
+ FROM $categories_temp c
3807
+ JOIN $stINch_categories_mapping scm
3808
+ ON c.store_category_id = scm.store_category_id
3809
+ )
3810
+ ";
3811
+ $this->db_do($q);
3812
 
 
3813
 
3814
+ //stp
3815
 
3816
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3817
 
3818
 
3819
+ //return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3820
 
3821
+ $this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
3822
+ $this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
3823
 
3824
+ $this->deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int);
3825
+ /**/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3826
 
3827
+ echo("\n addCategoryDataMultistoreMerge done... \n *************************************************************\n");
3828
 
3829
+ }
3830
 
3831
+ #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3832
 
3833
+ private function deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int)
3834
+ {
3835
 
3836
+ echo("\n\n\n\n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n deleteOldSinchCategoriesFromShopMerge start... \n");
 
 
 
 
 
3837
 
 
3838
 
3839
+ $query = "DROP TABLE IF EXISTS delete_cats";
3840
+ echo("\n $query\n");
3841
+ $this->db_do($query);
 
 
 
 
 
 
 
 
3842
 
 
3843
 
3844
+ $delete_cats = Mage::getSingleton('core/resource')->getTableName('delete_cats');
3845
+ $stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
 
 
3846
 
3847
+ $query = "
3848
+ CREATE TABLE $delete_cats
 
 
3849
 
3850
+ SELECT entity_id
3851
+ FROM $catalog_category_entity cce
3852
+ WHERE cce.entity_id NOT IN
3853
+ (
3854
+ SELECT cce2.entity_id
3855
+ FROM $catalog_category_entity cce2
3856
+ JOIN $stINch_categories sc
3857
+ ON cce2.store_category_id = sc.store_category_id
3858
+ )
3859
+ AND cce.store_category_id IS NOT NULL
3860
+ ;";
3861
 
3862
+ echo("\n $query\n");
3863
+ $this->db_do($query);
3864
 
3865
 
3866
+ $query = "DELETE cce FROM $catalog_category_entity cce JOIN $delete_cats dc USING(entity_id)";
3867
+ echo("\n $query\n");
3868
+ $this->db_do($query);
3869
 
3870
 
3871
+ $query = "DROP TABLE IF EXISTS $delete_cats";
3872
+ echo("\n $query\n");
3873
+ //$this->db_do($query );
3874
 
3875
 
3876
+ /**
3877
+ * $query = "
3878
+ * DELETE cat FROM $catalog_category_entity_varchar cat
3879
+ * JOIN $stINch_categories_mapping scm
3880
+ * ON cat.entity_id = scm.shop_entity_id
3881
+ * WHERE
3882
+ * (scm.shop_store_category_id IS NOT NULL) AND
3883
+ * (scm.store_category_id IS NULL)";
3884
+ * echo("\n $query\n");
3885
+ * // $this->db_do($query);
3886
+ *
3887
+ * $query = "
3888
+ * DELETE cat FROM $catalog_category_entity_int cat
3889
+ * JOIN $stINch_categories_mapping scm
3890
+ * ON cat.entity_id = scm.shop_entity_id
3891
+ * WHERE
3892
+ * (scm.shop_store_category_id IS NOT NULL) AND
3893
+ * (scm.store_category_id IS NULL)";
3894
+ * echo("\n $query\n");
3895
+ * // $this->db_do($query);
3896
+ *
3897
+ * $query = "
3898
+ * DELETE cat FROM $catalog_category_entity cat
3899
+ * JOIN $stINch_categories_mapping scm
3900
+ * ON cat.entity_id=scm.shop_entity_id
3901
+ * WHERE
3902
+ * (scm.shop_store_category_id IS NOT NULL) AND
3903
+ * (scm.store_category_id IS NULL)";
3904
+ * echo("\n $query\n");
3905
+ * // $this->db_do($query);
3906
+ * /**/
3907
+
3908
+ echo("\n deleteOldSinchCategoriesFromShopMerge done... \n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n\n");
3909
 
3910
+ }
3911
 
3912
+ #################################################################################################
3913
 
3914
+ private function _set_default_root_category()
3915
+ {
3916
+ $q = "UPDATE " . Mage::getSingleton('core/resource')->getTableName('core_store_group') . " csg
3917
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . " cce
3918
+ ON csg.root_category_id = cce.entity_id
3919
+ SET csg.root_category_id=(SELECT entity_id FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . " WHERE parent_id = 1 LIMIT 1)
3920
+ WHERE csg.root_category_id > 0 AND cce.entity_id IS NULL";
3921
+ $this->db_do($q);
3922
+ }
3923
 
3924
+ #################################################################################################
3925
 
3926
+ function ParseCategoryFeatures()
3927
+ {
3928
 
3929
+ $parse_file = $this->varDir . FILE_CATEGORIES_FEATURES;
3930
+ if (filesize($parse_file) || $this->_ignore_category_features) {
3931
+ $this->_LOG("Start parse " . FILE_CATEGORIES_FEATURES);
3932
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('categories_features_temp'));
3933
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('categories_features_temp') . " (
3934
+ category_feature_id int(11),
3935
+ store_category_id int(11),
3936
+ feature_name varchar(50),
3937
+ display_order_number int(11),
3938
+ KEY(store_category_id),
3939
+ KEY(category_feature_id)
3940
+ )
3941
+ ");
3942
 
3943
+ if (!$this->_ignore_category_features) {
3944
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
3945
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('categories_features_temp') . "
3946
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
3947
+ OPTIONALLY ENCLOSED BY '\"'
3948
+ LINES TERMINATED BY \"\r\n\"
3949
+ IGNORE 1 LINES ");
3950
+ }
3951
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
3952
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('categories_features_temp') . "
3953
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
3954
 
3955
+ $this->_LOG("Finish parse " . FILE_CATEGORIES_FEATURES);
3956
+ } else {
3957
+ $this->_LOG("Wrong file " . $parse_file);
3958
+ }
3959
+ $this->_LOG(' ');
3960
+ }
3961
 
3962
+ #################################################################################################
3963
 
3964
+ function ParseDistributors()
3965
+ {
3966
 
3967
+ $parse_file = $this->varDir . FILE_DISTRIBUTORS;
3968
+ if (filesize($parse_file)) {
3969
+ $this->_LOG("Start parse " . FILE_DISTRIBUTORS);
3970
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('distributors_temp'));
3971
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('distributors_temp') . "(
3972
+ distributor_id int(11),
3973
+ distributor_name varchar(255),
3974
+ website varchar(255),
3975
+ KEY(distributor_id)
3976
+ )
3977
+ ");
3978
 
3979
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
3980
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('distributors_temp') . "
3981
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
3982
+ OPTIONALLY ENCLOSED BY '\"'
3983
+ LINES TERMINATED BY \"\r\n\"
3984
+ IGNORE 1 LINES ");
3985
 
3986
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
3987
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('distributors_temp') . "
3988
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
3989
 
3990
+ $this->_LOG("Finish parse " . FILE_DISTRIBUTORS);
3991
+ } else {
3992
+ $this->_LOG("Wrong file " . $parse_file);
3993
+ }
3994
+ $this->_LOG(' ');
3995
+ }
3996
 
3997
 
3998
+ #################################################################################################
3999
 
4000
+ function ParseDistributorsStockAndPrice()
4001
+ {
4002
+ $parse_file = $this->varDir . FILE_DISTRIBUTORS_STOCK_AND_PRICES;
4003
+ if (filesize($parse_file)) {
4004
+ $this->_LOG("Start parse " . FILE_DISTRIBUTORS_STOCK_AND_PRICES);
4005
 
4006
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp'));
4007
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp') . "(
4008
+ `store_product_id` int(11) DEFAULT NULL,
4009
+ `distributor_id` int(11) DEFAULT NULL,
4010
+ `stock` int(11) DEFAULT NULL,
4011
+ `cost` decimal(15,4) DEFAULT NULL,
4012
+ `distributor_sku` varchar(255) DEFAULT NULL,
4013
+ `distributor_category` varchar(50) DEFAULT NULL,
4014
+ `eta` varchar(50) DEFAULT NULL,
4015
+ UNIQUE KEY `product_distri` (store_product_id, distributor_id)
4016
+ )");
4017
 
4018
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
4019
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp') . "
4020
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
4021
+ OPTIONALLY ENCLOSED BY '\"'
4022
+ LINES TERMINATED BY \"\r\n\"
4023
+ IGNORE 1 LINES ");
4024
 
4025
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
4026
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('distributors_stock_and_price_temp') . "
4027
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4028
 
4029
+ $this->_LOG("Finish parse " . FILE_DISTRIBUTORS_STOCK_AND_PRICES);
4030
+ } else {
4031
+ $this->_LOG("Wrong file " . $parse_file);
4032
+ }
4033
+ $this->_LOG(' ');
4034
 
4035
+ }
4036
 
4037
+ ############################### ##################################################################
4038
 
4039
+ function ParseProductContracts()
4040
+ {
4041
+ $parse_file = $this->varDir . FILE_PRODUCT_CONTRACTS;
4042
+ if (filesize($parse_file)) {
4043
+ $this->_LOG("Start parse " . FILE_PRODUCT_CONTRACTS);
4044
 
4045
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('product_contracts_temp'));
4046
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('product_contracts_temp') . "(
4047
+ `store_product_id` int(11) DEFAULT NULL,
4048
+ `contract_id` varchar(50) DEFAULT NULL,
4049
+ KEY `store_product_id` (store_product_id)
4050
+ )");
4051
 
4052
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
4053
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('product_contracts_temp') . "
4054
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
4055
+ OPTIONALLY ENCLOSED BY '\"'
4056
+ LINES TERMINATED BY \"\r\n\"
4057
+ IGNORE 1 LINES ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4058
 
4059
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_product_contracts'));
4060
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('product_contracts_temp') . "
4061
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_product_contracts'));
4062
 
4063
+ $this->_LOG("Finish parse " . FILE_PRODUCT_CONTRACTS);
4064
+ } else {
4065
+ $this->_LOG("Wrong file " . $parse_file);
4066
+ }
4067
+ $this->_LOG(' ');
4068
 
4069
+ }
4070
 
4071
+ #################################################################################################
4072
 
4073
+ function ParseEANCodes()
4074
+ {
4075
 
4076
+ $parse_file = $this->varDir . FILE_EANCODES;
4077
+ if (filesize($parse_file)) {
4078
+ $this->_LOG("Start parse " . FILE_EANCODES);
 
 
 
 
4079
 
4080
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('ean_codes_temp'));
4081
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('ean_codes_temp') . "(
4082
+ product_id int(11),
4083
+ ean_code varchar(255),
4084
+ KEY(product_id)
4085
+ )");
 
 
 
 
 
 
 
 
 
4086
 
4087
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
4088
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('ean_codes_temp') . "
4089
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
4090
+ OPTIONALLY ENCLOSED BY '\"'
4091
+ LINES TERMINATED BY \"\r\n\"
4092
+ IGNORE 1 LINES ");
4093
 
4094
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
4095
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('ean_codes_temp') . "
4096
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
4097
 
4098
+ $this->_LOG("Finish parse " . FILE_EANCODES);
4099
+ } else {
4100
+ $this->_LOG("Wrong file " . $parse_file);
4101
+ }
4102
+ $this->_LOG(' ');
4103
+ }
4104
 
4105
+ #################################################################################################
4106
 
4107
+ function ParseManufacturers()
4108
+ {
4109
 
4110
+ $parse_file = $this->varDir . FILE_MANUFACTURERS;
4111
+ if (filesize($parse_file)) {
4112
+ $this->_LOG("Start parse " . FILE_MANUFACTURERS);
4113
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('manufacturers_temp'));
4114
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('manufacturers_temp') . "(
4115
+ sinch_manufacturer_id int(11),
4116
+ manufacturer_name varchar(255),
4117
+ manufacturers_image varchar(255),
4118
+ shop_option_id int(11),
4119
+ KEY(sinch_manufacturer_id),
4120
+ KEY(shop_option_id),
4121
+ KEY(manufacturer_name)
4122
+ )");
4123
 
4124
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
4125
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('manufacturers_temp') . "
4126
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
4127
+ OPTIONALLY ENCLOSED BY '\"'
4128
+ LINES TERMINATED BY \"\r\n\"
4129
+ IGNORE 1 LINES ");
 
 
 
 
 
 
 
 
4130
 
4131
+ $q = "DELETE aov
4132
+ FROM " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option') . " ao
4133
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value') . " aov
4134
+ ON ao.option_id=aov.option_id left
4135
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('manufacturers_temp') . " mt
4136
+ ON aov.value=mt.manufacturer_name
4137
+ WHERE
4138
+ ao.attribute_id=" . $this->attributes['manufacturer'] . " AND
4139
+ mt.manufacturer_name is null";
4140
+ $this->db_do($q);
4141
 
4142
+ $q = "DELETE ao
4143
+ FROM " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option') . " ao
4144
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value') . " aov
4145
+ ON ao.option_id=aov.option_id
4146
+ WHERE
4147
+ attribute_id=" . $this->attributes['manufacturer'] . " AND
4148
+ aov.option_id is null";
4149
+ $this->db_do($q);
4150
 
4151
+ $q = "SELECT
4152
+ m.sinch_manufacturer_id,
4153
+ m.manufacturer_name,
4154
+ m.manufacturers_image
4155
+ FROM " . Mage::getSingleton('core/resource')->getTableName('manufacturers_temp') . " m
4156
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value') . " aov
4157
+ ON m.manufacturer_name=aov.value
4158
+ WHERE aov.value IS NULL";
4159
+ $quer = $this->db_do($q);
4160
 
4161
+ while ($row = mysqli_fetch_array($quer)) {
4162
+ $q0 = "INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option') . "
4163
+ (attribute_id)
4164
+ VALUES(" . $this->attributes['manufacturer'] . ")";
4165
+ $quer0 = $this->db_do($q0);
4166
 
4167
+ $q2 = "INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value') . "(
4168
+ option_id,
4169
+ value
4170
+ )(
4171
+ SELECT
4172
+ max(option_id) as option_id,
4173
+ " . "'" . mysqli_real_escape_string($this->db, $row['manufacturer_name']) . "'
4174
+ FROM " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option') . "
4175
+ WHERE attribute_id=" . $this->attributes['manufacturer'] . "
4176
+ )
4177
+ ";
4178
+ $quer2 = $this->db_do($q2);
4179
+ // $option['attribute_id'] = $this->attributes['manufacturer'];
4180
+ // $option['value'][$row['sinch_manufacturer_id']][0] = $row['manufacturer_name'];
4181
 
4182
+ }
4183
 
4184
+ $q = "UPDATE " . Mage::getSingleton('core/resource')->getTableName('manufacturers_temp') . " mt
4185
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value') . " aov
4186
+ ON mt.manufacturer_name=aov.value
4187
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option') . " ao
4188
+ ON ao.option_id=aov.option_id
4189
+ SET mt.shop_option_id=aov.option_id
4190
+ WHERE ao.attribute_id=" . $this->attributes['manufacturer'];
4191
+ $this->db_do($q);
4192
 
4193
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
4194
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('manufacturers_temp') . "
4195
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
4196
+ $this->_LOG("Finish parse " . FILE_MANUFACTURERS);
4197
+ } else {
4198
+ $this->_LOG("Wrong file " . $parse_file);
4199
+ }
4200
+ $this->_LOG(' ');
4201
+ }
4202
 
4203
+ #################################################################################################
4204
 
4205
+ function ParseRelatedProducts()
4206
+ {
4207
 
4208
+ $parse_file = $this->varDir . FILE_RELATED_PRODUCTS;
4209
+ if (filesize($parse_file) || $this->_ignore_product_related) {
4210
+ $this->_LOG("Start parse " . FILE_RELATED_PRODUCTS);
4211
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('related_products_temp'));
4212
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('related_products_temp') . "(
4213
+ sinch_product_id int(11),
4214
+ related_sinch_product_id int(11),
4215
+ store_product_id int(11) default null,
4216
+ store_related_product_id int(11) default null,
4217
+ entity_id int(11),
4218
+ related_entity_id int(11),
4219
+ KEY(sinch_product_id),
4220
+ KEY(related_sinch_product_id),
4221
+ KEY(store_product_id)
4222
+ )DEFAULT CHARSET=utf8");
4223
+ if (!$this->_ignore_product_related) {
4224
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
4225
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('related_products_temp') . "
4226
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
4227
+ OPTIONALLY ENCLOSED BY '\"'
4228
+ LINES TERMINATED BY \"\r\n\"
4229
+ IGNORE 1 LINES ");
4230
+ }
4231
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
4232
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('related_products_temp') . "
4233
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
4234
 
4235
+ $this->_LOG("Finish parse " . FILE_RELATED_PRODUCTS);
4236
+ } else {
4237
+ $this->_LOG("Wrong file " . $parse_file);
4238
+ }
4239
+ $this->_LOG(" ");
4240
+ }
4241
 
4242
 
4243
+ #################################################################################################
4244
 
4245
+ function ParseProductFeatures()
4246
+ {
4247
 
4248
+ $parse_file = $this->varDir . FILE_PRODUCT_FEATURES;
4249
+ if (filesize($parse_file) || $this->_ignore_product_features) {
4250
+ $this->_LOG("Start parse " . FILE_PRODUCT_FEATURES);
4251
 
4252
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('product_features_temp'));
4253
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('product_features_temp') . "(
4254
+ product_feature_id int(11),
4255
+ sinch_product_id int(11),
4256
+ restricted_value_id int(11),
4257
+ KEY(sinch_product_id),
4258
+ KEY(restricted_value_id)
4259
+ )
4260
+ ");
4261
+ if (!$this->_ignore_product_features) {
4262
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
4263
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('product_features_temp') . "
4264
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
4265
+ OPTIONALLY ENCLOSED BY '\"'
4266
+ LINES TERMINATED BY \"\r\n\"
4267
+ IGNORE 1 LINES ");
4268
+ }
4269
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
4270
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('product_features_temp') . "
4271
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
4272
 
4273
+ $this->_LOG("Finish parse " . FILE_PRODUCT_FEATURES);
4274
+ } else {
4275
+ $this->_LOG("Wrong file " . $parse_file);
4276
+ }
4277
+ $this->_LOG(" ");
4278
+ }
4279
 
4280
+ #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
4281
 
4282
+ function ParseProductCategories()
4283
+ {
4284
+ $parse_file = $this->varDir . FILE_PRODUCT_CATEGORIES;
4285
+ if (filesize($parse_file)) {
4286
+ $this->_LOG("Start parse " . FILE_PRODUCT_CATEGORIES);
4287
 
4288
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('product_categories_temp'));
4289
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('product_categories_temp') . "(
4290
+ store_product_id int(11),
4291
+ store_category_id int(11),
4292
+ key(store_product_id),
4293
+ key(store_category_id)
4294
+ )");
4295
 
4296
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
4297
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('product_categories_temp') . "
4298
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
4299
+ OPTIONALLY ENCLOSED BY '\"'
4300
+ LINES TERMINATED BY \"\r\n\"
4301
+ IGNORE 1 LINES ");
4302
 
4303
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_product_categories'));
4304
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('product_categories_temp') . "
4305
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_product_categories'));
 
 
 
 
 
 
4306
 
4307
+ $this->_LOG("Finish parse " . FILE_PRODUCT_CATEGORIES);
4308
+ } else {
4309
+ $this->_LOG("Wrong file " . $parse_file);
4310
+ }
4311
+ $this->_LOG(' ');
4312
 
4313
+ }
4314
 
 
4315
 
4316
+ #################################################################################################
4317
 
4318
+ function ParseProducts($coincidence)
4319
+ {
4320
+ echo("\nParseProducts 2\n");
4321
+ $dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
4322
+ $replace_merge_product = $dataConf['replace_products'];
4323
 
4324
+ $parse_file = $this->varDir . FILE_PRODUCTS;
4325
+ //$parse_file = $this->varDir . FILE_PRODUCTS_TEST;
4326
+ if (filesize($parse_file)) {
4327
+ $this->_LOG("Start parse " . FILE_PRODUCTS);
4328
+ echo("\nParseProducts 2\n");
4329
 
4330
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('products_temp'));
4331
+ if ($this->product_file_format == "NEW") {
4332
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "(
4333
+ store_product_id int(11),
4334
+ product_sku varchar(255),
4335
+ product_name varchar(255),
4336
+ sinch_manufacturer_id int(11),
4337
+ main_image_url varchar(255),
4338
+ thumb_image_url varchar(255),
4339
+ specifications text,
4340
+ description text,
4341
+ search_cache text,
4342
+ description_type varchar(50),
4343
+ medium_image_url varchar(255),
4344
+ Title varchar(255),
4345
+ Weight decimal(15,4),
4346
+ Family varchar(255),
4347
+ Reviews varchar(255),
4348
+ pdf_url varchar(255),
4349
+ product_short_description varchar(255),
4350
+ products_date_added datetime default NULL,
4351
+ products_last_modified datetime default NULL,
4352
+ availability_id_in_stock int(11) default '1',
4353
+ availability_id_out_of_stock int(11) default '2',
4354
+ products_locate varchar(30) default NULL,
4355
+ products_ordered int(11) NOT NULL default '0',
4356
+ products_url varchar(255) default NULL,
4357
+ products_viewed int(5) default '0',
4358
+ products_seo_url varchar(100) NOT NULL,
4359
+ manufacturer_name varchar(255) default NULL,
4360
+ KEY(store_product_id),
4361
+ KEY(sinch_manufacturer_id)
4362
+ )DEFAULT CHARSET=utf8
4363
+ ");
4364
+ } elseif ($this->product_file_format == "OLD") {
4365
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "(
4366
+ store_category_product_id int(11),
4367
+ store_product_id int(11),
4368
+ sinch_product_id int(11),
4369
+ product_sku varchar(255),
4370
+ product_name varchar(255),
4371
+ sinch_manufacturer_id int(11),
4372
+ store_category_id int(11),
4373
+ main_image_url varchar(255),
4374
+ thumb_image_url varchar(255),
4375
+ specifications text,
4376
+ description text,
4377
+ search_cache text,
4378
+ spec_characte_u_count int(11),
4379
+ description_type varchar(50),
4380
+ medium_image_url varchar(255),
4381
+ products_date_added datetime default NULL,
4382
+ products_last_modified datetime default NULL,
4383
+ availability_id_in_stock int(11) default '1',
4384
+ availability_id_out_of_stock int(11) default '2',
4385
+ products_locate varchar(30) default NULL,
4386
+ products_ordered int(11) NOT NULL default '0',
4387
+ products_url varchar(255) default NULL,
4388
+ products_viewed int(5) default '0',
4389
+ products_seo_url varchar(100) NOT NULL,
4390
+ manufacturer_name varchar(255) default NULL,
4391
+ KEY(store_category_product_id),
4392
+ KEY(store_product_id),
4393
+ KEY(sinch_manufacturer_id),
4394
+ KEY(store_category_id)
4395
+ )DEFAULT CHARSET=utf8
4396
+ ");
4397
 
4398
+ }
4399
+ echo("\nParseProducts 3\n");
4400
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
4401
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4402
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
4403
+ OPTIONALLY ENCLOSED BY '\"'
4404
+ LINES TERMINATED BY \"\r\n\"
4405
+ IGNORE 1 LINES ");
4406
 
4407
+ if ($this->product_file_format == "NEW") {
4408
+ $this->db_do("ALTER TABLE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4409
+ ADD COLUMN sinch_product_id int(11) AFTER store_product_id
4410
+ ");
4411
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4412
+ SET sinch_product_id=store_product_id
4413
+ ");
4414
 
4415
+ $this->db_do("ALTER TABLE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4416
+ ADD COLUMN store_category_id int(11) AFTER sinch_manufacturer_id
4417
+ ");
4418
+ $this->db_do("ALTER TABLE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4419
+ ADD KEY(store_category_id)
4420
+ ");
4421
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4422
+ SET product_name = Title WHERE Title != ''
4423
+ ");
4424
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " pt
4425
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_product_categories') . " spc
4426
+ SET pt.store_category_id=spc.store_category_id
4427
+ WHERE pt.store_product_id=spc.store_product_id
4428
+ ");
4429
+ //http://redmine.bintime.com/issues/4127
4430
+ //3.
4431
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4432
+ SET main_image_url = medium_image_url WHERE main_image_url = ''
4433
+ ");
4434
+ //end
4435
 
4436
+ }
4437
 
4438
+ echo("\nParseProducts 4\n");
4439
 
4440
+ echo("\nParseProducts 5\n");
4441
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4442
+ SET products_date_added=now(), products_last_modified=now()");
4443
+ echo("\nParseProducts 6\n");
4444
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " p
4445
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers') . " m
4446
+ ON p.sinch_manufacturer_id=m.sinch_manufacturer_id
4447
+ SET p.manufacturer_name=m.manufacturer_name");
4448
+ echo("\nParseProducts 7\n");
4449
+ if ($this->current_import_status_statistic_id) {
4450
+ $res = $this->db_do("SELECT COUNT(*) AS cnt
4451
+ FROM " . Mage::getSingleton('core/resource')->getTableName('products_temp'));
4452
+ $row = mysqli_fetch_assoc($res);
4453
+ $this->db_do("UPDATE " . $this->import_status_statistic_table . "
4454
+ SET number_of_products=" . $row['cnt'] . "
4455
+ WHERE id=" . $this->current_import_status_statistic_id);
4456
+ }
4457
 
4458
+ if ($replace_merge_product == "REWRITE") {
4459
+ $this->db_do("DELETE FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'));
4460
+ $this->db_do("SET FOREIGN_KEY_CHECKS=0");
4461
+ $this->db_do("TRUNCATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'));
4462
+ $this->db_do("SET FOREIGN_KEY_CHECKS=1");
4463
+ }
4464
 
4465
+ echo("\nParseProducts 8\n");
4466
+ $this->addProductsWebsite();
4467
+ $this->mapSinchProducts($replace_merge_product);
4468
+ echo("\nParseProducts 9\n");
4469
+
4470
+ if (count($coincidence) == 1) {
4471
+ $this->replaceMagentoProducts();
4472
+ } else {
4473
+ echo("\n\n\n\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ [" . $this->im_type . "] $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n\n\n"); //exit;
4474
+
4475
+
4476
+ switch ($this->im_type) {
4477
+ case "REWRITE":
4478
+ $this->replaceMagentoProductsMultistore($coincidence);
4479
+ break;
4480
+ case "MERGE":
4481
+ $this->replaceMagentoProductsMultistoreMERGE($coincidence);
4482
+ break;
4483
+ }
4484
+ }
4485
+ echo("\nParseProducts 10\n");
4486
+
4487
+ // Toàn đẹp trai đã rào đoạn mã này
4488
+ $this->mapSinchProducts($replace_merge_product, true);
4489
+ $this->addManufacturer_attribute();
4490
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_products'));
4491
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4492
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_products'));
4493
+ $this->_LOG("Finish parse " . FILE_PRODUCTS);
4494
+ } else {
4495
+ $this->_LOG("Wrong file " . $parse_file);
4496
+ }
4497
+ $this->_LOG(" ");
4498
+ echo("\nParseProducts 11\n");
4499
+ }
4500
 
4501
+ #################################################################################################
4502
 
4503
+ public function addProductsWebsite()
4504
+ {
4505
+ $this->db_do(" DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('products_website_temp'));
4506
+ // TEMPORARY
4507
+ $this->db_do("
4508
+ CREATE TABLE `" . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . "` (
4509
+ `id` int(10) unsigned NOT NULL auto_increment,
4510
+ store_product_id int(11),
4511
+ sinch_product_id int(11),
4512
+ `website` int(11) default NULL,
4513
+ `website_id` int(11) default NULL,
4514
+ PRIMARY KEY (`id`),
4515
+ KEY store_product_id (`store_product_id`)
4516
+ )
4517
+ ");
4518
+ $result = $this->db_do("SELECT
4519
+ website_id,
4520
+ store_id as website
4521
+ FROM " . Mage::getSingleton('core/resource')->getTableName('core_store') . "
4522
+ WHERE code!='admin'
4523
+ "); // where code!='admin' was adder for editing Featured products;
4524
+ while ($row = mysqli_fetch_assoc($result)) {
4525
+ $sql = "INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " (
4526
+ store_product_id,
4527
+ sinch_product_id,
4528
+ website,
4529
+ website_id
4530
+ )(
4531
+ SELECT
4532
+ distinct
4533
+ store_product_id,
4534
+ sinch_product_id,
4535
+ {$row['website']},
4536
+ {$row['website_id']}
4537
+ FROM " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
4538
+ )";
4539
+ $result2 = $this->db_do($sql);
4540
+ }
4541
 
 
 
 
 
 
 
 
 
 
 
4542
 
4543
+ }
 
 
 
 
4544
 
4545
+ ################################################################################################
4546
 
4547
+ public function mapSinchProducts($mode = 'MERGE', $mapping_again = false)
4548
+ {
4549
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
4550
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp') . " (
4551
+ entity_id int(11) unsigned NOT NULL,
4552
+ manufacturer_option_id int(11),
4553
+ manufacturer_name varchar(255),
4554
+ shop_store_product_id int(11),
4555
+ shop_sinch_product_id int(11),
4556
+ sku varchar(64) default NULL,
4557
+ store_product_id int(11),
4558
+ sinch_product_id int(11),
4559
+ product_sku varchar(255),
4560
+ sinch_manufacturer_id int(11),
4561
+ sinch_manufacturer_name varchar(255),
4562
+ KEY entity_id (entity_id),
4563
+ KEY manufacturer_option_id (manufacturer_option_id),
4564
+ KEY manufacturer_name (manufacturer_name),
4565
+ KEY store_product_id (store_product_id),
4566
+ KEY sinch_product_id (sinch_product_id),
4567
+ KEY sku (sku),
4568
+ UNIQUE KEY(entity_id)
4569
+ )
4570
+ ");
4571
+ $this->db_do("CREATE TABLE IF NOT EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping') . "
4572
+ LIKE " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
4573
+ $productEntityTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
4574
 
4575
+ // backup Product ID in REWRITE mode
4576
+ if ($mode == 'REWRITE' && !$mapping_again) {
4577
+ $productEntityTable = Mage::getSingleton('core/resource')->getTableName('sinch_product_backup');
4578
+ }
4579
+ // (end) backup Product ID in REWRITE mode
 
4580
 
4581
+ $result = $this->db_do("
4582
+ INSERT ignore INTO " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp') . " (
4583
+ entity_id,
4584
+ sku,
4585
+ shop_store_product_id,
4586
+ shop_sinch_product_id
4587
+ )(SELECT
4588
+ entity_id,
4589
+ sku,
4590
+ store_product_id,
4591
+ sinch_product_id
4592
+ FROM " . $productEntityTable . "
4593
+ )
4594
+ ");
4595
 
4596
+ $this->addManufacturers(1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4597
 
4598
+ $q = "UPDATE " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp') . " pmt
4599
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav') . " cpie
4600
+ ON pmt.entity_id=cpie.entity_id
4601
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value') . " aov
4602
+ ON cpie.value=aov.option_id
4603
+ SET
4604
+ manufacturer_option_id=cpie.value,
4605
+ manufacturer_name=aov.value
4606
+ WHERE cpie.attribute_id=" . $this->attributes['manufacturer'];
4607
+ $this->db_do($q);
4608
 
4609
+ $q = "UPDATE " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp') . " pmt
4610
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " p
4611
+ ON pmt.sku=p.product_sku
4612
+ SET
4613
+ pmt.store_product_id=p.store_product_id,
4614
+ pmt.sinch_product_id=p.sinch_product_id,
4615
+ pmt.product_sku=p.product_sku,
4616
+ pmt.sinch_manufacturer_id=p.sinch_manufacturer_id,
4617
+ pmt.sinch_manufacturer_name=p.manufacturer_name";
4618
 
4619
+ $this->db_do($q);
4620
 
4621
+ $q = "UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
4622
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp') . " pmt
4623
+ ON cpe.entity_id=pmt.entity_id
4624
+ SET cpe.store_product_id=pmt.store_product_id,
4625
+ cpe.sinch_product_id=pmt.sinch_product_id
4626
+ WHERE
4627
+ cpe.sinch_product_id IS NULL
4628
+ AND pmt.sinch_product_id IS NOT NULL
4629
+ AND cpe.store_product_id IS NULL
4630
+ AND pmt.store_product_id IS NOT NULL";
4631
+ $this->db_do($q);
4632
 
4633
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
4634
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp') . "
4635
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
4636
+ }
4637
 
4638
+ function addManufacturers($delete_eav = null)
4639
+ {
4640
+ // this cleanup is not needed due to foreign keys
4641
+ if (!$delete_eav) {
4642
+ $result = $this->db_do("
4643
+ DELETE FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav') . "
4644
+ WHERE attribute_id = " . $this->_getProductAttributeId('manufacturer')//." AND store_id = ".$websiteId
4645
+ );
4646
+ }
4647
+ $this->addManufacturer_attribute();
4648
+ // todo: doesn't seems to work properly, should be inserted per visibility
4649
+ // done, test now
4650
 
4651
+ $result = $this->db_do("
4652
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav') . " (
4653
+ entity_id,
4654
+ attribute_id,
4655
+ store_id,
4656
+ value
4657
+ )(
4658
+ SELECT
4659
+ a.entity_id,
4660
+ " . $this->_getProductAttributeId('manufacturer') . ",
4661
+ w.website,
4662
+ mn.shop_option_id
4663
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
4664
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
4665
+ ON a.store_product_id = b.store_product_id
4666
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
4667
+ ON a.store_product_id=w.store_product_id
4668
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers') . " mn
4669
+ ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
4670
+ WHERE mn.shop_option_id IS NOT NULL
4671
+ )
4672
+ ON DUPLICATE KEY UPDATE
4673
+ value = mn.shop_option_id
4674
+ ");
4675
 
4676
+ $result = $this->db_do("
4677
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav') . " (
4678
+ entity_id,
4679
+ attribute_id,
4680
+ store_id,
4681
+ value
4682
+ )(
4683
+ SELECT
4684
+ a.entity_id,
4685
+ " . $this->_getProductAttributeId('manufacturer') . ",
4686
+ 0,
4687
+ mn.shop_option_id
4688
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
4689
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
4690
+ ON a.store_product_id = b.store_product_id
4691
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
4692
+ ON a.store_product_id=w.store_product_id
4693
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers') . " mn
4694
+ ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
4695
+ WHERE mn.shop_option_id IS NOT NULL
4696
+ )
4697
+ ON DUPLICATE KEY UPDATE
4698
+ value = mn.shop_option_id
4699
+ ");
4700
 
4701
 
4702
+ }
4703
 
4704
+ #################################################################################################
4705
 
4706
+ private function _getProductAttributeId($attributeCode)
4707
+ {
4708
+ return $this->_getAttributeId($attributeCode, 'catalog_product');
4709
+ }
4710
 
4711
+ #################################################################################################
4712
 
4713
+ private function addManufacturer_attribute()
4714
+ {
4715
+ $result = $this->db_do("
4716
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " (
4717
+ entity_type_id,
4718
+ attribute_id,
4719
+ store_id,
4720
+ entity_id,
4721
+ value
4722
+ )(
4723
+ SELECT
4724
+ " . $this->_getProductEntityTypeId() . ",
4725
+ " . $this->_getProductAttributeId('manufacturer') . ",
4726
+ 0,
4727
+ a.entity_id,
4728
+ pm.manufacturer_option_id
4729
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
4730
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping') . " pm
4731
+ ON a.entity_id = pm.entity_id
4732
+ )
4733
+ ON DUPLICATE KEY UPDATE
4734
+ value = pm.manufacturer_option_id
4735
+ ");
4736
 
4737
 
4738
+ }
4739
 
4740
+ #################################################################################################
4741
 
4742
+ public function replaceMagentoProducts()
4743
+ {
4744
 
4745
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
4746
 
4747
+ $result = $this->db_do("DELETE cpe
4748
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
4749
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping') . " pm
4750
+ ON cpe.entity_id=pm.entity_id
4751
+ WHERE pm.shop_store_product_id IS NOT NULL
4752
+ AND pm.store_product_id IS NULL
4753
+ ");
4754
 
4755
+ //Inserting new products and updating old others.
4756
+ $this->_getProductDefaulAttributeSetId();
4757
+ $result = $this->db_do("
4758
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " (
4759
+ entity_id,
4760
+ entity_type_id,
4761
+ attribute_set_id,
4762
+ type_id,
4763
+ sku,
4764
+ updated_at,
4765
+ has_options,
4766
+ store_product_id,
4767
+ sinch_product_id
4768
+ )(SELECT
4769
+ pm.entity_id,
4770
+ " . $this->_getProductEntityTypeId() . ",
4771
+ $this->defaultAttributeSetId,
4772
+ 'simple',
4773
+ a.product_sku,
4774
+ NOW(),
4775
+ 0,
4776
+ a.store_product_id,
4777
+ a.sinch_product_id
4778
+ FROM " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " a
4779
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping') . " pm
4780
+ ON a.store_product_id=pm.store_product_id
4781
+ AND a.sinch_product_id=pm.sinch_product_id
4782
+ WHERE pm.entity_id IS NOT NULL
4783
+ )
4784
+ ON DUPLICATE KEY UPDATE
4785
+ sku= a.product_sku,
4786
+ store_product_id=a.store_product_id,
4787
+ sinch_product_id=a.sinch_product_id
4788
+ ");
4789
+ // store_product_id=a.store_product_id,
4790
+ // sinch_product_id=a.sinch_product_id
4791
 
4792
+ $result = $this->db_do("
4793
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " (
4794
+ entity_id,
4795
+ entity_type_id,
4796
+ attribute_set_id,
4797
+ type_id,
4798
+ sku,
4799
+ updated_at,
4800
+ has_options,
4801
+ store_product_id,
4802
+ sinch_product_id
4803
+ )(SELECT
4804
+ pm.entity_id,
4805
+ " . $this->_getProductEntityTypeId() . ",
4806
+ $this->defaultAttributeSetId,
4807
+ 'simple',
4808
+ a.product_sku,
4809
+ NOW(),
4810
+ 0,
4811
+ a.store_product_id,
4812
+ a.sinch_product_id
4813
+ FROM " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " a
4814
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping') . " pm
4815
+ ON a.store_product_id=pm.store_product_id
4816
+ AND a.sinch_product_id=pm.sinch_product_id
4817
+ WHERE pm.entity_id IS NULL
4818
+ )
4819
+ ON DUPLICATE KEY UPDATE
4820
+ sku= a.product_sku,
4821
+ store_product_id=a.store_product_id,
4822
+ sinch_product_id=a.sinch_product_id
4823
+ ");
4824
 
4825
+ //Set enabled
4826
+ $result = $this->db_do("DELETE cpei
4827
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " cpei
4828
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
4829
+ ON cpei.entity_id=cpe.entity_id
4830
+ WHERE cpe.entity_id IS NULL");
4831
 
4832
+ $result = $this->db_do("
4833
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " (
4834
+ entity_type_id,
4835
+ attribute_id,
4836
+ store_id,
4837
+ entity_id,
4838
+ value
4839
+ )(
4840
+ SELECT
4841
+ " . $this->_getProductEntityTypeId() . ",
4842
+ " . $this->_getProductAttributeId('status') . ",
4843
+ w.website,
4844
+ a.entity_id,
4845
+ 1
4846
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
4847
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
4848
+ ON a.store_product_id=w.store_product_id
4849
+ )
4850
+ ON DUPLICATE KEY UPDATE
4851
+ value=1
4852
+ ");
4853
+ // set status = 1 for all stores
4854
+ $result = $this->db_do("
4855
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " (
4856
+ entity_type_id,
4857
+ attribute_id,
4858
+ store_id,
4859
+ entity_id,
4860
+ value
4861
+ )(SELECT
4862
+ " . $this->_getProductEntityTypeId() . ",
4863
+ " . $this->_getProductAttributeId('status') . ",
4864
+ 0,
4865
+ a.entity_id,
4866
+ 1
4867
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
4868
+ )
4869
+ ON DUPLICATE KEY UPDATE
4870
+ value=1
4871
+ ");
4872
 
4873
+ //Unifying products with categories.
4874
+ $result = $this->db_do("DELETE ccp
4875
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " ccp
4876
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
4877
+ ON ccp.product_id=cpe.entity_id
4878
+ WHERE cpe.entity_id IS NULL");
4879
 
4880
+ echo("\n\n\nUPDATE IGNORE " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " ccp
4881
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . " cce
4882
+ ON ccp.category_id=cce.entity_id
4883
+ SET ccp.category_id=" . $this->_root_cat . "
4884
+ WHERE cce.entity_id IS NULL");
4885
+ $result = $this->db_do("UPDATE IGNORE " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " ccp
4886
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . " cce
4887
+ ON ccp.category_id=cce.entity_id
4888
+ SET ccp.category_id=" . $this->_root_cat . "
4889
+ WHERE cce.entity_id IS NULL");
4890
+ echo("\ndone\n");
4891
 
4892
 
4893
+ echo("\n\n\nDELETE ccp FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " ccp
4894
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . " cce
4895
+ ON ccp.category_id=cce.entity_id
4896
+ WHERE cce.entity_id IS NULL");
4897
+ $result = $this->db_do("DELETE ccp FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " ccp
4898
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . " cce
4899
+ ON ccp.category_id=cce.entity_id
4900
+ WHERE cce.entity_id IS NULL");
4901
+ echo("\ndone\n");
4902
 
4903
 
4904
+ $this->db_do(" DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . "_for_delete_temp");
4905
+ // TEMPORARY
4906
+ $this->db_do("
4907
+ CREATE TABLE `" . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . "_for_delete_temp` (
4908
+ `category_id` int(10) unsigned NOT NULL default '0',
4909
+ `product_id` int(10) unsigned NOT NULL default '0',
4910
+ `store_product_id` int(10) NOT NULL default '0',
4911
+ `store_category_id` int(10) NOT NULL default '0',
4912
+ `new_category_id` int(10) NOT NULL default '0',
4913
+ UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
4914
+ KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
4915
+ KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
4916
+ KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
4917
+ )
4918
 
4919
+ ");
4920
 
4921
+ $result = $this->db_do("
4922
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . "_for_delete_temp (
4923
+ category_id,
4924
+ product_id,
4925
+ store_product_id
4926
+ )(SELECT
4927
+ ccp.category_id,
4928
+ ccp.product_id,
4929
+ cpe.store_product_id
4930
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " ccp
4931
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
4932
+ ON ccp.product_id=cpe.entity_id
4933
+ WHERE store_product_id is not null
4934
+ )
4935
+ ");
4936
 
4937
+ $result = $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . "_for_delete_temp ccpfd
4938
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " p
4939
+ ON ccpfd.store_product_id=p.store_product_id
4940
+ SET ccpfd.store_category_id=p.store_category_id
4941
+ WHERE ccpfd.store_product_id!=0
4942
+ ");
4943
 
4944
+ $result = $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . "_for_delete_temp ccpfd
4945
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping') . " scm
4946
+ ON ccpfd.store_category_id=scm.store_category_id
4947
+ SET ccpfd.new_category_id=scm.shop_entity_id
4948
+ WHERE ccpfd.store_category_id!=0
4949
+ ");
4950
 
4951
+ $result = $this->db_do("DELETE FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . "_for_delete_temp
4952
+ WHERE category_id=new_category_id");
4953
 
4954
+ $result = $this->db_do("
4955
+ DELETE ccp
4956
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " ccp
4957
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . "_for_delete_temp ccpfd
4958
+ ON ccp.product_id=ccpfd.product_id
4959
+ AND ccp.category_id=ccpfd.category_id
4960
+ ");
4961
 
4962
+ $result = $this->db_do("
4963
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " (
4964
+ category_id,
4965
+ product_id
4966
+ )(SELECT
4967
+ scm.shop_entity_id,
4968
+ cpe.entity_id
4969
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
4970
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " p
4971
+ ON cpe.store_product_id=p.store_product_id
4972
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping') . " scm
4973
+ ON p.store_category_id=scm.store_category_id
4974
+ )
4975
+ ON DUPLICATE KEY UPDATE
4976
+ product_id = cpe.entity_id
4977
+ ");
4978
 
4979
 
4980
+ //add multi categories;
4981
 
4982
 
4983
+ $result = $this->db_do("
4984
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . "
4985
+ (category_id, product_id)
4986
+ (SELECT
4987
+ scm.shop_entity_id,
4988
+ cpe.entity_id
4989
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
4990
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " p
4991
+ ON cpe.store_product_id = p.store_product_id
4992
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_product_categories') . " spc
4993
+ ON p.store_product_id=spc.store_product_id
4994
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping') . " scm
4995
+ ON spc.store_category_id = scm.store_category_id
4996
+ )
4997
+ ON DUPLICATE KEY UPDATE
4998
+ product_id = cpe.entity_id
4999
+ ");
5000
 
5001
 
5002
+ //Indexing products and categories in the shop
5003
+ $result = $this->db_do("DELETE ccpi
5004
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index') . " ccpi
5005
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
5006
+ ON ccpi.product_id=cpe.entity_id
5007
+ WHERE cpe.entity_id IS NULL");
5008
 
5009
+ $result = $this->db_do("
5010
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index') . " (
5011
+ category_id,
5012
+ product_id,
5013
+ position,
5014
+ is_parent,
5015
+ store_id,
5016
+ visibility
5017
+ )(
5018
+ SELECT
5019
+ a.category_id,
5020
+ a.product_id,
5021
+ a.position,
5022
+ 1,
5023
+ b.store_id,
5024
+ 4
5025
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " a
5026
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " b
5027
+ )
5028
+ ON DUPLICATE KEY UPDATE
5029
+ visibility = 4
5030
+ ");
5031
 
5032
+ $result = $this->db_do("
5033
+ INSERT ignore INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index') . " (
5034
+ category_id,
5035
+ product_id,
5036
+ position,
5037
+ is_parent,
5038
+ store_id,
5039
+ visibility
5040
+ )(
5041
+ SELECT
5042
+ " . $this->_root_cat . ",
5043
+ a.product_id,
5044
+ a.position,
5045
+ 1,
5046
+ b.store_id,
5047
+ 4
5048
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " a
5049
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " b
5050
+ )
5051
+ ON DUPLICATE KEY UPDATE
5052
+ visibility = 4
5053
+ ");
5054
 
5055
+ //Set product name for specific web sites
5056
+ $result = $this->db_do("DELETE cpev
5057
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " cpev
5058
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
5059
+ ON cpev.entity_id=cpe.entity_id
5060
+ WHERE cpe.entity_id IS NULL");
5061
+ $result = $this->db_do("
5062
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5063
+ entity_type_id,
5064
+ attribute_id,
5065
+ store_id,
5066
+ entity_id,
5067
+ value
5068
+ )(SELECT
5069
+ " . $this->_getProductEntityTypeId() . ",
5070
+ " . $this->_getProductAttributeId('name') . ",
5071
+ w.website,
5072
+ a.entity_id,
5073
+ b.product_name
5074
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5075
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5076
+ ON a.store_product_id= b.store_product_id
5077
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5078
+ ON a.store_product_id=w.store_product_id
5079
+ )
5080
+ ON DUPLICATE KEY UPDATE
5081
+ value = b.product_name
5082
+ ");
5083
 
5084
+ // product name for all web sites
5085
+ $result = $this->db_do("
5086
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5087
+ entity_type_id,
5088
+ attribute_id,
5089
+ store_id,
5090
+ entity_id,
5091
+ value
5092
+ )(
5093
+ SELECT
5094
+ " . $this->_getProductEntityTypeId() . ",
5095
+ " . $this->_getProductAttributeId('name') . ",
5096
+ 0,
5097
+ a.entity_id,
5098
+ b.product_name
5099
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5100
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5101
+ ON a.store_product_id = b.store_product_id
5102
+ )
5103
+ ON DUPLICATE KEY UPDATE
5104
+ value = b.product_name
5105
+ ");
5106
 
5107
+ $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
5108
+ $this->addDescriptions();
5109
+ $this->cleanProductDistributors();
5110
+ if (!$this->_ignore_product_contracts) {
5111
+ $this->cleanProductContracts();
5112
+ }
5113
+ if ($this->product_file_format == "NEW") {
5114
+ $this->addReviews();
5115
+ $this->addWeight();
5116
+ $this->addSearchCache();
5117
+ $this->addPdfUrl();
5118
+ $this->addShortDescriptions();
5119
+ $this->addProductDistributors();
5120
+ if (!$this->_ignore_product_contracts) {
5121
+ $this->addProductContracts();
5122
+ }
5123
+ }
5124
+ $this->addEAN();
5125
+ $this->addSpecification();
5126
+ $this->addManufacturers();
5127
 
5128
+ //Enabling product index.
5129
+ $result = $this->db_do("DELETE cpei
5130
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index') . " cpei
5131
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
5132
+ ON cpei.product_id=cpe.entity_id
5133
+ WHERE cpe.entity_id IS NULL");
5134
 
5135
+ $result = $this->db_do("
5136
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index') . " (
5137
+ product_id,
5138
+ store_id,
5139
+ visibility
5140
+ )(
5141
+ SELECT
5142
+ a.entity_id,
5143
+ w.website,
5144
+ 4
5145
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5146
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5147
+ ON a.store_product_id=w.store_product_id
5148
+ )
5149
+ ON DUPLICATE KEY UPDATE
5150
+ visibility = 4
5151
+ ");
5152
+ $result = $this->db_do("
5153
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index') . " (
5154
+ product_id,
5155
+ store_id,
5156
+ visibility
5157
+ )(
5158
+ SELECT
5159
+ a.entity_id,
5160
+ 0,
5161
+ 4
5162
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5163
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5164
+ ON a.store_product_id=w.store_product_id
5165
+ )
5166
+ ON DUPLICATE KEY UPDATE
5167
+ visibility = 4
5168
+ ");
5169
 
5170
 
5171
+ $result = $this->db_do("
5172
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " (
5173
+ entity_type_id,
5174
+ attribute_id,
5175
+ store_id,
5176
+ entity_id,
5177
+ value
5178
+ )(
5179
+ SELECT
5180
+ " . $this->_getProductEntityTypeId() . ",
5181
+ " . $this->_getProductAttributeId('visibility') . ",
5182
+ w.website,
5183
+ a.entity_id,
5184
+ 4
5185
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5186
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5187
+ ON a.store_product_id=w.store_product_id
5188
+ )
5189
+ ON DUPLICATE KEY UPDATE
5190
+ value = 4
5191
+ ");
5192
 
5193
+ $result = $this->db_do("
5194
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " (
5195
+ entity_type_id,
5196
+ attribute_id,
5197
+ store_id,
5198
+ entity_id,
5199
+ value
5200
+ )(
5201
+ SELECT
5202
+ " . $this->_getProductEntityTypeId() . ",
5203
+ " . $this->_getProductAttributeId('visibility') . ",
5204
+ 0,
5205
+ a.entity_id,
5206
+ 4
5207
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5208
+ )
5209
+ ON DUPLICATE KEY UPDATE
5210
+ value = 4
5211
+ ");
5212
 
5213
+ $result = $this->db_do("DELETE cpw
5214
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_website') . " cpw
5215
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
5216
+ ON cpw.product_id=cpe.entity_id
5217
+ WHERE cpe.entity_id IS NULL");
5218
 
5219
+ $result = $this->db_do("
5220
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_website') . " (
5221
+ product_id,
5222
+ website_id
5223
+ )(
5224
+ SELECT a.entity_id, w.website_id
5225
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5226
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5227
+ ON a.store_product_id=w.store_product_id
5228
+ )
5229
+ ON DUPLICATE KEY UPDATE
5230
+ product_id=a.entity_id,
5231
+ website_id=w.website_id
5232
+ ");
5233
 
5234
+ // temporary disabled mart@bintime.com
5235
+ //$result = $this->db_do("
5236
+ // UPDATE catalog_category_entity_int a
5237
+ // SET a.value = 0
5238
+ // WHERE a.attribute_id = 32
5239
+ //");
5240
 
5241
 
5242
+ //Adding tax class "Taxable Goods"
5243
+ $result = $this->db_do("
5244
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " (
5245
+ entity_type_id,
5246
+ attribute_id,
5247
+ store_id,
5248
+ entity_id,
5249
+ value
5250
+ )(
5251
+ SELECT
5252
+ " . $this->_getProductEntityTypeId() . ",
5253
+ " . $this->_getProductAttributeId('tax_class_id') . ",
5254
+ w.website,
5255
+ a.entity_id,
5256
+ 2
5257
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5258
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5259
+ ON a.store_product_id=w.store_product_id
5260
+ )
5261
+ ON DUPLICATE KEY UPDATE
5262
+ value = 2
5263
+ ");
5264
+ $result = $this->db_do("
5265
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " (
5266
+ entity_type_id,
5267
+ attribute_id,
5268
+ store_id,
5269
+ entity_id,
5270
+ value
5271
+ )(
5272
+ SELECT
5273
+ " . $this->_getProductEntityTypeId() . ",
5274
+ " . $this->_getProductAttributeId('tax_class_id') . ",
5275
+ 0,
5276
+ a.entity_id,
5277
+ 2
5278
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5279
+ )
5280
+ ON DUPLICATE KEY UPDATE
5281
+ value = 2
5282
+ ");
5283
 
5284
+ // Load url Image
5285
+ $result = $this->db_do("
5286
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5287
+ entity_type_id,
5288
+ attribute_id,
5289
+ store_id,
5290
+ entity_id,
5291
+ value
5292
+ )(
5293
+ SELECT
5294
+ " . $this->_getProductEntityTypeId() . ",
5295
+ " . $this->_getProductAttributeId('image') . ",
5296
+ w.store_id,
5297
+ a.entity_id,
5298
+ b.main_image_url
5299
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5300
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " w
5301
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5302
+ ON a.store_product_id = b.store_product_id
5303
+ )
5304
+ ON DUPLICATE KEY UPDATE
5305
+ value = b.main_image_url
5306
+ ");
5307
 
5308
 
5309
+ // image for specific web sites
5310
+ $result = $this->db_do("
5311
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5312
+ entity_type_id,
5313
+ attribute_id,
5314
+ store_id,
5315
+ entity_id,
5316
+ value
5317
+ )(
5318
+ SELECT
5319
+ " . $this->_getProductEntityTypeId() . ",
5320
+ " . $this->_getProductAttributeId('image') . ",
5321
+ 0,
5322
+ a.entity_id,
5323
+ b.main_image_url
5324
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5325
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5326
+ ON a.store_product_id = b.store_product_id
5327
+ )
5328
+ ON DUPLICATE KEY UPDATE
5329
+ value = b.main_image_url
5330
+ ");
5331
 
5332
 
5333
+ // small_image for specific web sites
5334
+ $result = $this->db_do("
5335
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5336
+ entity_type_id,
5337
+ attribute_id,
5338
+ store_id,
5339
+ entity_id,
5340
+ value
5341
+ )(
5342
+ SELECT
5343
+ " . $this->_getProductEntityTypeId() . ",
5344
+ " . $this->_getProductAttributeId('small_image') . ",
5345
+ w.store_id,
5346
+ a.entity_id,
5347
+ b.medium_image_url
5348
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5349
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " w
5350
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5351
+ ON a.store_product_id = b.store_product_id
5352
+ )
5353
+ ON DUPLICATE KEY UPDATE
5354
+ value = b.medium_image_url
5355
+ ");
5356
 
5357
 
5358
+ // small_image for all web sites
5359
+ $result = $this->db_do("
5360
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5361
+ entity_type_id,
5362
+ attribute_id,
5363
+ store_id,
5364
+ entity_id,
5365
+ value
5366
+ )(
5367
+ SELECT
5368
+ " . $this->_getProductEntityTypeId() . ",
5369
+ " . $this->_getProductAttributeId('small_image') . ",
5370
+ 0,
5371
+ a.entity_id,
5372
+ b.medium_image_url
5373
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5374
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " w
5375
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5376
+ ON a.store_product_id = b.store_product_id
5377
+ )
5378
+ ON DUPLICATE KEY UPDATE
5379
+ value = b.medium_image_url
5380
+ ");
5381
 
5382
 
5383
+ // thumbnail for specific web site
5384
+ $result = $this->db_do("
5385
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5386
+ entity_type_id,
5387
+ attribute_id,
5388
+ store_id,
5389
+ entity_id,
5390
+ value
5391
+ )(
5392
+ SELECT
5393
+ " . $this->_getProductEntityTypeId() . ",
5394
+ " . $this->_getProductAttributeId('thumbnail') . ",
5395
+ w.store_id,
5396
+ a.entity_id,
5397
+ b.thumb_image_url
5398
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5399
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " w
5400
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5401
+ ON a.store_product_id = b.store_product_id
5402
+ )
5403
+ ON DUPLICATE KEY UPDATE
5404
+ value = b.thumb_image_url
5405
+ ");
5406
 
5407
 
5408
+ // thumbnail for all web sites
5409
+ $result = $this->db_do("
5410
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5411
+ entity_type_id,
5412
+ attribute_id,
5413
+ store_id,
5414
+ entity_id,
5415
+ value
5416
+ )(
5417
+ SELECT
5418
+ " . $this->_getProductEntityTypeId() . ",
5419
+ " . $this->_getProductAttributeId('thumbnail') . ",
5420
+ 0,
5421
+ a.entity_id,
5422
+ b.thumb_image_url
5423
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5424
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " w
5425
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5426
+ ON a.store_product_id = b.store_product_id
5427
+ )
5428
+ ON DUPLICATE KEY UPDATE
5429
+ value = b.thumb_image_url
5430
 
5431
+ ");
5432
 
5433
+ /*STP DELETE
5434
+ //Refresh fulltext search
5435
+ $result = $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp");
5436
+ $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS
5437
+ ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp
5438
+ LIKE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext'));
5439
 
5440
+ $result = $this->db_do("
5441
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
5442
+ product_id,
5443
+ store_id,
5444
+ data_index
5445
+ )(
5446
+ SELECT
5447
+ a.entity_id,
5448
+ w.website,
5449
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
5450
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5451
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5452
+ ON a.store_product_id=w.store_product_id
5453
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
5454
+ ON a.entity_id = b.product_id
5455
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
5456
+ ON b.category_id = c.entity_id
5457
+ AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
5458
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
5459
+ ON a.entity_id = e.entity_id
5460
+ AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
5461
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." j
5462
+ ON a.entity_id = j.product_id
5463
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
5464
+ ON a.store_product_id = f.store_product_id
5465
+ )
5466
+ ON DUPLICATE KEY UPDATE
5467
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
5468
+ ");
5469
 
5470
+ $result = $this->db_do("
5471
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
5472
+ product_id,
5473
+ store_id,
5474
+ data_index
5475
+ )(
5476
+ SELECT
5477
+ a.entity_id,
5478
+ w.website,
5479
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
5480
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
5481
+ INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
5482
+ ON a.store_product_id=w.store_product_id
5483
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
5484
+ ON a.entity_id = b.product_id
5485
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
5486
+ ON b.category_id = c.entity_id
5487
+ AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
5488
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
5489
+ ON a.entity_id = e.entity_id
5490
+ AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
5491
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
5492
+ ON a.store_product_id = f.store_product_id
5493
+ )
5494
+ ON DUPLICATE KEY UPDATE
5495
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
5496
+ ");
5497
 
5498
+ $result = $this->db_do("DELETE cf
5499
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." cf
5500
+ LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
5501
+ ON cf.product_id=cpe.entity_id
5502
+ WHERE cpe.entity_id is null");
5503
 
5504
+ $result = $this->db_do("
5505
+ INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." (
5506
+ product_id,
5507
+ store_id,
5508
+ data_index
5509
+ )(
5510
+ SELECT
5511
+ a.product_id,
5512
+ a.store_id,
5513
+ a.data_index
5514
+ FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp a
5515
+ WHERE product_id = a.product_id
5516
+ )
5517
+ ON DUPLICATE KEY UPDATE
5518
+ data_index = a.data_index
5519
+ ");
5520
 
5521
+ $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_query')." SET is_processed = 0");
5522
+ //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
5523
+ //TODO add something else
5524
+ STP DELETE*/
5525
+ $this->addRelatedProducts();
5526
+ }
5527
 
5528
+ #################################################################################################
5529
 
5530
+ private function _getProductDefaulAttributeSetId()
5531
+ {
5532
+ if (!$this->defaultAttributeSetId) {
5533
+ $sql = "
5534
+ SELECT entity_type_id, default_attribute_set_id
5535
+ FROM " . Mage::getSingleton('core/resource')->getTableName('eav_entity_type') . "
5536
+ WHERE entity_type_code = 'catalog_product'
5537
+ LIMIT 1
5538
+ ";
5539
+ $result = $this->db_do($sql);
5540
+ if ($row = mysqli_fetch_assoc($result)) {
5541
 
5542
+ $this->defaultAttributeSetId = $row['default_attribute_set_id'];
5543
+ }
5544
+ }
5545
+ return $this->defaultAttributeSetId;
5546
+ }
5547
 
5548
+ #################################################################################################
5549
 
5550
+ function dropHTMLentities($entity_type_id, $attribute_id)
5551
+ {
5552
+ // product name for all web sites
5553
+ $result = $this->db_do("
5554
+ SELECT value, entity_id
5555
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . "
5556
+ WHERE entity_type_id=" . $entity_type_id . "
5557
+ AND attribute_id=" . $attribute_id
5558
+ );
5559
+ while ($row = mysqli_fetch_array($result)) {
5560
+ $value = $this->valid_char($row['value']);
5561
+ if ($value != '' and $value != $row['value']) {
5562
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . "
5563
+ SET value='" . mysqli_real_escape_string($this->db, $value) . "'
5564
+ WHERE entity_id=" . $row['entity_id'] . "
5565
+ AND entity_type_id=" . $entity_type_id . "
5566
+ AND attribute_id=" . $attribute_id);
5567
+ }
5568
 
5569
+ }
5570
+ }
5571
 
5572
+ #################################################################################################
5573
 
5574
+ function valid_char($string)
5575
+ {
5576
+ $string = preg_replace('/&#8482;/', ' ', $string);
5577
+ $string = preg_replace('/&reg;/', ' ', $string);
5578
+ $string = preg_replace('/&asymp;/', ' ', $string);
5579
+ $string = preg_replace('/&quot;/', ' ', $string);
5580
+ $string = preg_replace('/&prime;/', ' ', $string);
5581
+ $string = preg_replace('/&deg;/', ' ', $string);
5582
+ $string = preg_replace('/&plusmn;/', ' ', $string);
5583
+ $string = preg_replace('/&micro;/', ' ', $string);
5584
+ $string = preg_replace('/&sup2;/', ' ', $string);
5585
+ $string = preg_replace('/&sup3;/', ' ', $string);
5586
+ // $string = preg_replace('/\xe2\x80\x93/','-',$string);
5587
+ // $string = preg_replace('/\xe2\x80\x99/','\'',$string);
5588
+ // $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
5589
+ // $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
5590
 
5591
+ // return utf8_decode($string);
5592
 
5593
+ return $string;
5594
+ }
5595
 
5596
 
5597
+ #################################################################################################
5598
 
5599
+ function addDescriptions()
5600
+ {
5601
+ // product description for all web sites
5602
+ $result = $this->db_do("
5603
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text') . " (
5604
+ entity_type_id,
5605
+ attribute_id,
5606
+ store_id,
5607
+ entity_id,
5608
+ value
5609
+ )(
5610
+ SELECT
5611
+ " . $this->_getProductEntityTypeId() . ",
5612
+ " . $this->_getProductAttributeId('description') . ",
5613
+ w.website,
5614
+ a.entity_id,
5615
+ b.description
5616
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5617
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5618
+ ON a.store_product_id = b.store_product_id
5619
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5620
+ ON a.store_product_id=w.store_product_id
5621
+ )
5622
+ ON DUPLICATE KEY UPDATE
5623
+ value = b.description
5624
+ ");
 
5625
 
5626
+ // product description for all web sites
5627
+ $result = $this->db_do("
5628
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text') . " (
5629
+ entity_type_id,
5630
+ attribute_id,
5631
+ store_id,
5632
+ entity_id,
5633
+ value
5634
+ )(
5635
+ SELECT
5636
+ " . $this->_getProductEntityTypeId() . ",
5637
+ " . $this->_getProductAttributeId('description') . ",
5638
+ 0,
5639
+ a.entity_id,
5640
+ b.description
5641
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5642
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5643
+ ON a.store_product_id = b.store_product_id
5644
+ )
5645
+ ON DUPLICATE KEY UPDATE
5646
+ value = b.description
5647
+ ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5648
 
5649
 
5650
+ }
5651
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5652
 
5653
+ #################################################################################################
5654
 
5655
+ function cleanProductDistributors()
5656
+ {
5657
+ for ($i = 1; $i <= 5; $i++) {
5658
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . "
5659
+ SET value = ''
5660
+ WHERE entity_type_id=" . $this->_getProductEntityTypeId() . " AND attribute_id=" . $this->_getProductAttributeId('supplier_' . $i));
5661
+ }
5662
+ }
5663
 
5664
+ #################################################################################################
5665
 
5666
+ function cleanProductContracts()
5667
+ {
5668
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . "
5669
+ SET value = ''
5670
+ WHERE entity_type_id=" . $this->_getProductEntityTypeId() . " AND attribute_id=" . $this->_getProductAttributeId('contract_id'));
5671
+ }
5672
 
5673
+ #################################################################################################
5674
 
5675
+ function addReviews()
5676
+ {
5677
+ // product reviews for all web sites
5678
+ $result = $this->db_do("
5679
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text') . " (
5680
+ entity_type_id,
5681
+ attribute_id,
5682
+ store_id,
5683
+ entity_id,
5684
+ value
5685
+ )(
5686
+ SELECT
5687
+ " . $this->_getProductEntityTypeId() . ",
5688
+ " . $this->_getProductAttributeId('reviews') . ",
5689
+ w.website,
5690
+ a.entity_id,
5691
+ b.Reviews
5692
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5693
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5694
+ ON a.store_product_id = b.store_product_id
5695
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5696
+ ON a.store_product_id=w.store_product_id
5697
+ )
5698
+ ON DUPLICATE KEY UPDATE
5699
+ value = b.Reviews
5700
+ ");
5701
 
5702
+ // product Reviews for all web sites
5703
+ $result = $this->db_do("
5704
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text') . " (
5705
+ entity_type_id,
5706
+ attribute_id,
5707
+ store_id,
5708
+ entity_id,
5709
+ value
5710
+ )(
5711
+ SELECT
5712
+ " . $this->_getProductEntityTypeId() . ",
5713
+ " . $this->_getProductAttributeId('reviews') . ",
5714
+ 0,
5715
+ a.entity_id,
5716
+ b.Reviews
5717
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5718
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5719
+ ON a.store_product_id = b.store_product_id
5720
+ )
5721
+ ON DUPLICATE KEY UPDATE
5722
+ value = b.Reviews
5723
+ ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5725
 
5726
+ }
5727
 
5728
+ #################################################################################################
5729
 
5730
+ function addWeight()
5731
+ {
5732
+ // product weight for specific web site
5733
+ $result = $this->db_do("
5734
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal') . " (
5735
+ entity_type_id,
5736
+ attribute_id,
5737
+ store_id,
5738
+ entity_id,
5739
+ value
5740
+ )(
5741
+ SELECT
5742
+ " . $this->_getProductEntityTypeId() . ",
5743
+ " . $this->_getProductAttributeId('weight') . ",
5744
+ w.website,
5745
+ a.entity_id,
5746
+ b.Weight
5747
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5748
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5749
+ ON a.store_product_id = b.store_product_id
5750
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5751
+ ON a.store_product_id=w.store_product_id
5752
+ )
5753
+ ON DUPLICATE KEY UPDATE
5754
+ value = b.Weight
5755
+ ");
5756
+ // product weight for all web sites
5757
+ $result = $this->db_do("
5758
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal') . " (
5759
+ entity_type_id,
5760
+ attribute_id,
5761
+ store_id,
5762
+ entity_id,
5763
+ value
5764
+ )(
5765
+ SELECT
5766
+ " . $this->_getProductEntityTypeId() . ",
5767
+ " . $this->_getProductAttributeId('weight') . ",
5768
+ 0,
5769
+ a.entity_id,
5770
+ b.Weight
5771
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5772
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5773
+ ON a.store_product_id = b.store_product_id
5774
+ )
5775
+ ON DUPLICATE KEY UPDATE
5776
+ value = b.Weight
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5777
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5778
 
5779
+ ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5780
 
5781
 
5782
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5783
 
5784
+ #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5785
 
5786
+ function addSearchCache()
5787
+ {
5788
+ // product search_cache for all web sites
5789
+ $result = $this->db_do("
5790
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text') . " (
5791
+ entity_type_id,
5792
+ attribute_id,
5793
+ store_id,
5794
+ entity_id,
5795
+ value
5796
+ )(
5797
+ SELECT
5798
+ " . $this->_getProductEntityTypeId() . ",
5799
+ " . $this->_getProductAttributeId('sinch_search_cache') . ",
5800
+ w.website,
5801
+ a.entity_id,
5802
+ b.search_cache
5803
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5804
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5805
+ ON a.store_product_id = b.store_product_id
5806
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5807
+ ON a.store_product_id=w.store_product_id
5808
+ )
5809
+ ON DUPLICATE KEY UPDATE
5810
+ value = b.search_cache
5811
+ ");
5812
 
5813
+ // product search_cache for all web sites
5814
+ $result = $this->db_do("
5815
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text') . " (
5816
+ entity_type_id,
5817
+ attribute_id,
5818
+ store_id,
5819
+ entity_id,
5820
+ value
5821
+ )(
5822
+ SELECT
5823
+ " . $this->_getProductEntityTypeId() . ",
5824
+ " . $this->_getProductAttributeId('sinch_search_cache') . ",
5825
+ 0,
5826
+ a.entity_id,
5827
+ b.search_cache
5828
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5829
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5830
+ ON a.store_product_id = b.store_product_id
5831
+ )
5832
+ ON DUPLICATE KEY UPDATE
5833
+ value = b.search_cache
5834
+ ");
5835
 
 
 
 
5836
 
5837
+ }
5838
 
5839
+ #################################################################################################
 
 
 
5840
 
5841
+ function addPdfUrl()
5842
+ {
5843
+ // product PDF Url for all web sites
5844
+ $result = $this->db_do("
5845
+ UPDATE " . Mage::getSingleton('core/resource')->getTableName('products_temp') . "
5846
+ SET pdf_url = CONCAT(
5847
+ '<a href=\"#\" onclick=\"popWin(',
5848
+ \"'\",
5849
+ pdf_url,
5850
+ \"'\",
5851
+ \", 'pdf', 'width=500,height=800,left=50,top=50, location=no,status=yes,scrollbars=yes,resizable=yes'); return false;\",
5852
+ '\"',
5853
+ '>',
5854
+ pdf_url,
5855
+ '</a>')
5856
+ WHERE pdf_url != ''
5857
+ ");
5858
+ //<a title="" onclick="popWin('http://images.icecat.biz/img/gallery/14532248_4539.jpg', 'gallery', 'width=500,height=500,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" href="#">
5859
+ $result = $this->db_do("
5860
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5861
+ entity_type_id,
5862
+ attribute_id,
5863
+ store_id,
5864
+ entity_id,
5865
+ value
5866
+ )(
5867
+ SELECT
5868
+ " . $this->_getProductEntityTypeId() . ",
5869
+ " . $this->_getProductAttributeId('pdf_url') . ",
5870
+ w.website,
5871
+ a.entity_id,
5872
+ b.pdf_url
5873
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5874
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5875
+ ON a.store_product_id = b.store_product_id
5876
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5877
+ ON a.store_product_id=w.store_product_id
5878
+ )
5879
+ ON DUPLICATE KEY UPDATE
5880
+ value = b.pdf_url
5881
+ ");
5882
+ // product PDF url for all web sites
5883
+ $result = $this->db_do("
5884
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5885
+ entity_type_id,
5886
+ attribute_id,
5887
+ store_id,
5888
+ entity_id,
5889
+ value
5890
+ )(
5891
+ SELECT
5892
+ " . $this->_getProductEntityTypeId() . ",
5893
+ " . $this->_getProductAttributeId('pdf_url') . ",
5894
+ 0,
5895
+ a.entity_id,
5896
+ b.pdf_url
5897
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5898
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5899
+ ON a.store_product_id = b.store_product_id
5900
+ )
5901
+ ON DUPLICATE KEY UPDATE
5902
+ value = b.pdf_url
5903
+ ");
5904
 
5905
+ }
5906
 
5907
+ #################################################################################################
5908
 
5909
+ function addShortDescriptions()
5910
+ {
5911
+ // product short description for all web sites
5912
+ $result = $this->db_do("
5913
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5914
+ entity_type_id,
5915
+ attribute_id,
5916
+ store_id,
5917
+ entity_id,
5918
+ value
5919
+ )(
5920
+ SELECT
5921
+ " . $this->_getProductEntityTypeId() . ",
5922
+ " . $this->_getProductAttributeId('short_description') . ",
5923
+ w.website,
5924
+ a.entity_id,
5925
+ b.product_short_description
5926
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5927
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5928
+ ON a.store_product_id = b.store_product_id
5929
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5930
+ ON a.store_product_id=w.store_product_id
5931
+ )
5932
+ ON DUPLICATE KEY UPDATE
5933
+ value = b.product_short_description
5934
+ ");
5935
+ // product short description for all web sites
5936
+ $result = $this->db_do("
5937
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5938
+ entity_type_id,
5939
+ attribute_id,
5940
+ store_id,
5941
+ entity_id,
5942
+ value
5943
+ )(
5944
+ SELECT
5945
+ " . $this->_getProductEntityTypeId() . ",
5946
+ " . $this->_getProductAttributeId('short_description') . ",
5947
+ 0,
5948
+ a.entity_id,
5949
+ b.product_short_description
5950
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5951
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
5952
+ ON a.store_product_id = b.store_product_id
5953
+ )
5954
+ ON DUPLICATE KEY UPDATE
5955
+ value = b.product_short_description
5956
+ ");
5957
 
5958
+ }
5959
 
5960
+ #################################################################################################
5961
 
5962
+ function addProductDistributors()
5963
+ {
5964
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary'));
5965
+ $this->db_do("CREATE TABLE IF NOT EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary') . "
5966
+ LIKE " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
5967
+ $this->db_do("INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary') . " SELECT * FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
5968
+ for ($i = 1; $i <= 5; $i++) {
5969
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier'));
5970
+ $this->db_do("CREATE TABLE IF NOT EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier') . "
5971
+ LIKE " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price'));
5972
+ $this->db_do("INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier') . " SELECT * FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary') . " GROUP BY store_product_id");
5973
 
5974
+ // product Distributors for all web sites
5975
+ $result = $this->db_do("
5976
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
5977
+ entity_type_id,
5978
+ attribute_id,
5979
+ store_id,
5980
+ entity_id,
5981
+ value
5982
+ )(
5983
+ SELECT
5984
+ " . $this->_getProductEntityTypeId() . ",
5985
+ " . $this->_getProductAttributeId('supplier_' . $i) . ",
5986
+ w.website,
5987
+ a.entity_id,
5988
+ d.distributor_name
5989
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
5990
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier') . " b
5991
+ ON a.store_product_id = b.store_product_id
5992
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors') . " d
5993
+ ON b.distributor_id = d.distributor_id
5994
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
5995
+ ON a.store_product_id=w.store_product_id
5996
+ )
5997
+ ON DUPLICATE KEY UPDATE
5998
+ value = d.distributor_name
5999
+ ");
6000
+ // product Distributors for all web sites
6001
+ $result = $this->db_do("
6002
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
6003
+ entity_type_id,
6004
+ attribute_id,
6005
+ store_id,
6006
+ entity_id,
6007
+ value
6008
+ )(
6009
+ SELECT
6010
+ " . $this->_getProductEntityTypeId() . ",
6011
+ " . $this->_getProductAttributeId('supplier_' . $i) . ",
6012
+ 0,
6013
+ a.entity_id,
6014
+ d.distributor_name
6015
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
6016
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier') . " b
6017
+ ON a.store_product_id = b.store_product_id
6018
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors') . " d
6019
+ ON b.distributor_id = d.distributor_id
6020
+ )
6021
+ ON DUPLICATE KEY UPDATE
6022
+ value = d.distributor_name
6023
+ ");
6024
 
6025
+ $this->db_do("DELETE sdsapt FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary') . " sdsapt JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price_temporary_supplier') . " sdsapts ON sdsapt.store_product_id = sdsapts.store_product_id AND sdsapt.distributor_id = sdsapts.distributor_id");
6026
 
6027
 
6028
+ }
6029
 
6030
+ }
6031
 
6032
+ #################################################################################################
6033
 
6034
+ function addProductContracts()
6035
+ {
6036
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_product_contracts_temporary'));
6037
+ $this->db_do("CREATE TABLE IF NOT EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_product_contracts_temporary') . "(
6038
+ `store_product_id` int(11) DEFAULT NULL,
6039
+ `contract_id_str` varchar(255) DEFAULT NULL,
6040
+ KEY `store_product_id` (store_product_id)
6041
+ )
6042
+ ");
6043
+ $this->db_do("INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('stINch_product_contracts_temporary') . " SELECT store_product_id, group_concat(contract_id) FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_product_contracts') . " GROUP BY store_product_id");
6044
+ // product Distributors for all web sites
6045
+ $result = $this->db_do("
6046
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
6047
+ entity_type_id,
6048
+ attribute_id,
6049
+ store_id,
6050
+ entity_id,
6051
+ value
6052
+ )(
6053
+ SELECT
6054
+ " . $this->_getProductEntityTypeId() . ",
6055
+ " . $this->_getProductAttributeId('contract_id') . ",
6056
+ w.website,
6057
+ a.entity_id,
6058
+ b.contract_id_str
6059
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
6060
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_product_contracts_temporary') . " b
6061
+ ON a.store_product_id = b.store_product_id
6062
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
6063
+ ON a.store_product_id=w.store_product_id
6064
+ )
6065
+ ON DUPLICATE KEY UPDATE
6066
+ value = b.contract_id_str
6067
+ ");
6068
+ // product Distributors for all web sites
6069
+ $result = $this->db_do("
6070
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
6071
+ entity_type_id,
6072
+ attribute_id,
6073
+ store_id,
6074
+ entity_id,
6075
+ value
6076
+ )(
6077
+ SELECT
6078
+ " . $this->_getProductEntityTypeId() . ",
6079
+ " . $this->_getProductAttributeId('contract_id') . ",
6080
+ 0,
6081
+ a.entity_id,
6082
+ b.contract_id_str
6083
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
6084
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_product_contracts_temporary') . " b
6085
+ ON a.store_product_id = b.store_product_id
6086
+ )
6087
+ ON DUPLICATE KEY UPDATE
6088
+ value = b.contract_id_str
6089
+ ");
6090
 
6091
 
6092
+ }
6093
 
6094
+ #################################################################################################
6095
 
6096
+ function addEAN()
6097
+ {
6098
+ //gather EAN codes for each product
6099
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('EANs_temp'));
6100
+ $this->db_do("
6101
+ CREATE TEMPORARY TABLE " . Mage::getSingleton('core/resource')->getTableName('EANs_temp') . " (
6102
+ sinch_product_id int(11),
6103
+ store_product_id int(11),
6104
+ EANs text,
6105
+ KEY `sinch_product_id` (`sinch_product_id`),
6106
+ KEY `store_product_id` (`store_product_id`)
6107
+ )
6108
+ ");
6109
+ $this->db_do("
6110
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('EANs_temp') . " (
6111
+ sinch_product_id,
6112
+ EANs
6113
+ )(SELECT
6114
+ sec.product_id,
6115
+ GROUP_CONCAT(DISTINCT ean_code ORDER BY ean_code DESC SEPARATOR ', ') AS eans
6116
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes') . " sec
6117
+ GROUP BY sec.product_id
6118
+ )
6119
+ ");
6120
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('EANs_temp') . " e
6121
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " p
6122
+ ON e.sinch_product_id=p.sinch_product_id
6123
+ SET e.store_product_id=p.store_product_id");
6124
+ // product EANs for all web sites
6125
+ $result = $this->db_do("
6126
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
6127
+ entity_type_id,
6128
+ attribute_id,
6129
+ store_id,
6130
+ entity_id,
6131
+ value
6132
+ )(
6133
+ SELECT
6134
+ " . $this->_getProductEntityTypeId() . ",
6135
+ " . $this->_getProductAttributeId('ean') . ",
6136
+ w.website,
6137
+ a.entity_id,
6138
+ e.EANs
6139
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
6140
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('EANs_temp') . " e
6141
+ ON a.store_product_id = e.store_product_id
6142
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
6143
+ ON a.store_product_id=w.store_product_id
6144
+ )
6145
+ ON DUPLICATE KEY UPDATE
6146
+ value = e.EANs
6147
+ ");
6148
 
6149
+ // product EANs for all web sites
6150
+ $result = $this->db_do("
6151
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
6152
+ entity_type_id,
6153
+ attribute_id,
6154
+ store_id,
6155
+ entity_id,
6156
+ value
6157
+ )(
6158
+ SELECT
6159
+ " . $this->_getProductEntityTypeId() . ",
6160
+ " . $this->_getProductAttributeId('ean') . ",
6161
+ 0,
6162
+ a.entity_id,
6163
+ e.EANs
6164
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
6165
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('EANs_temp') . " e
6166
+ ON a.store_product_id = e.store_product_id
6167
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
6168
+ ON a.store_product_id=w.store_product_id
6169
+ )
6170
+ ON DUPLICATE KEY UPDATE
6171
+ value = e.EANs
6172
+ ");
6173
 
 
 
 
 
 
6174
  }
6175
 
6176
  #################################################################################################
6177
 
6178
+ function addSpecification()
6179
+ {
6180
+ // product specification for all web sites
6181
+ $result = $this->db_do("
6182
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text') . " (
6183
+ entity_type_id,
6184
+ attribute_id,
6185
+ store_id,
6186
+ entity_id,
6187
+ value
6188
+ )(
6189
+ SELECT
6190
+ " . $this->_getProductEntityTypeId() . ",
6191
+ " . $this->_getProductAttributeId('specification') . ",
6192
+ w.website,
6193
+ a.entity_id,
6194
+ b.specifications
6195
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
6196
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
6197
+ ON a.store_product_id = b.store_product_id
6198
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
6199
+ ON a.store_product_id=w.store_product_id
6200
+ )
6201
+ ON DUPLICATE KEY UPDATE
6202
+ value = b.specifications
6203
+ ");
6204
+ // product specification for all web sites
6205
+ $result = $this->db_do("
6206
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text') . " (
6207
+ entity_type_id,
6208
+ attribute_id,
6209
+ store_id,
6210
+ entity_id,
6211
+ value
6212
+ )(
6213
+ SELECT
6214
+ " . $this->_getProductEntityTypeId() . ",
6215
+ " . $this->_getProductAttributeId('specification') . ",
6216
+ 0,
6217
+ a.entity_id,
6218
+ b.specifications
6219
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
6220
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " b
6221
+ ON a.store_product_id = b.store_product_id
6222
+ )
6223
+ ON DUPLICATE KEY UPDATE
6224
+ value = b.specifications
6225
+ ");
6226
 
 
 
 
6227
 
 
 
 
 
 
6228
  }
6229
 
6230
+ ################################################################################################
 
 
 
 
 
6231
 
6232
+ function addRelatedProducts()
6233
+ {
 
 
 
 
 
 
 
 
 
6234
 
6235
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('stINch_related_products') . " rpt
6236
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " p
6237
+ ON rpt.sinch_product_id=p.sinch_product_id
6238
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
6239
+ ON p.store_product_id=cpe.store_product_id
6240
+ SET rpt.store_product_id=p.store_product_id, rpt.entity_id=cpe.entity_id");
6241
 
6242
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('stINch_related_products') . " rpt
6243
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('products_temp') . " p
6244
+ ON rpt.related_sinch_product_id=p.sinch_product_id
6245
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
6246
+ ON p.store_product_id=cpe.store_product_id
6247
+ SET rpt.store_related_product_id=p.store_product_id, rpt.related_entity_id=cpe.entity_id");
6248
 
6249
+ $result = $this->db_do("SELECT
6250
+ link_type_id,
6251
+ code
6252
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link_type')
6253
+ );
6254
+ $link_type = array();
6255
+ while ($row = mysqli_fetch_array($result)) {
6256
+ $link_type[$row['code']] = $row['link_type_id'];
6257
  }
 
6258
 
6259
+ $result = $this->db_do("
6260
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link') . " (
6261
+ product_id,
6262
+ linked_product_id,
6263
+ link_type_id
6264
+ )(
6265
+ SELECT
6266
+ entity_id,
6267
+ related_entity_id,
6268
+ " . $link_type['relation'] . "
6269
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_related_products') . "
6270
+ WHERE store_product_id IS NOT NULL
6271
+ AND store_related_product_id IS NOT NULL
6272
+ )
6273
+ ON DUPLICATE KEY UPDATE
6274
+ product_id = entity_id,
6275
+ linked_product_id = related_entity_id
6276
+ ");
6277
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int') . "_tmp");
6278
 
6279
+ $this->db_do("CREATE TEMPORARY TABLE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int') . "_tmp (
6280
+ `value_id` int(11) default NULL,
6281
+ `product_link_attribute_id` smallint(6) unsigned default NULL,
6282
+ `link_id` int(11) unsigned default NULL,
6283
+ `value` int(11) NOT NULL default '0',
6284
+ KEY `FK_INT_PRODUCT_LINK_ATTRIBUTE` (`product_link_attribute_id`),
6285
+ KEY `FK_INT_PRODUCT_LINK` (`link_id`)
6286
+ )
6287
+ ");
6288
 
6289
+ $result = $this->db_do("
6290
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int') . "_tmp(
6291
+ product_link_attribute_id,
6292
+ link_id,
6293
+ value
6294
+ )(
6295
+ SELECT
6296
+ 2,
6297
+ cpl.link_id,
6298
+ 0
6299
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link') . " cpl
6300
+ )
6301
+ ");
6302
 
6303
+ $result = $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int') . "_tmp ct
6304
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int') . " c
6305
+ ON ct.link_id=c.link_id
6306
+ SET ct.value_id=c.value_id
6307
+ WHERE c.product_link_attribute_id=2
6308
+ ");
6309
 
6310
+ $result = $this->db_do("
6311
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int') . " (
6312
+ value_id,
6313
+ product_link_attribute_id,
6314
+ link_id,
6315
+ value
6316
+ )(
6317
+ SELECT
6318
+ value_id,
6319
+ product_link_attribute_id,
6320
+ link_id,
6321
+ value
6322
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int') . "_tmp ct
6323
+ )
6324
+ ON DUPLICATE KEY UPDATE
6325
+ link_id=ct.link_id
6326
 
6327
+ ");
 
 
 
 
 
6328
 
6329
+ /* $q="select distinct store_product_id from stINch_related_products";
6330
+ $quer=$this->db_do($q);
6331
+ $prod = Mage::getModel('catalog/product');
6332
+ while ($row = mysqli_fetch_assoc($quer)) {
6333
+ $q1="select distinct store_related_product_id store_product_id from stINch_related_products where store_product_id=".$row['store_product_id'].;
6334
+ $quer1=$this->db_do($q1);
6335
+ $prod->load($row['store_product_id']);
6336
 
6337
+ ###//get related product data (product id's and positions)
6338
+ ###$relatedData = array();
6339
+ ###foreach ($product->getRelatedLinkCollection() as $link) {
6340
+ ### $relatedData[$link->getLinkedProductId()]['position'] = $link->getPosition();
6341
+ ###}
6342
+ ###//manipulate $relatedData array
6343
+ ###// ...
6344
+ ###//set and save related product data
6345
+ ###$product->setRelatedLinkData($relatedData);
6346
+ ###$product->save();
6347
+ ###
6348
+ $i=1;
6349
+ while ($row1 = mysqli_fetch_assoc($quer1)) {
6350
+ $param[$row1['store_related_product_id']]['position']=$i++;
6351
 
 
 
 
 
 
6352
  }
6353
+ $prod->setRelatedLinkData($param);
6354
+ //here ... some other product operations and in the end
6355
+ $prod->save();
6356
 
6357
+ }
6358
+ */
6359
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6360
 
6361
+ #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
6362
 
6363
+ public function replaceMagentoProductsMultistore($coincidence)
6364
+ {
6365
 
6366
+ echo("\n replaceMagentoProductsMultistore 1\n");
 
 
 
 
 
 
 
6367
 
 
 
 
 
 
 
 
 
 
6368
 
6369
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
6370
 
 
6371
 
6372
+ $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
6373
+ $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
6374
+ $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
6375
+ $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
6376
+ $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
6377
+ $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
6378
+ $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
6379
+ $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
6380
+ $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
6381
+ $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
6382
+ $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
6383
+ $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
6384
+ $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
6385
+ //STP DELETE $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
6386
+ // $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
6387
+ $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
6388
+
6389
+ $_getProductEntityTypeId = $this->_getProductEntityTypeId();
6390
+ $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
6391
+
6392
+ $attr_atatus = $this->_getProductAttributeId('status');
6393
+ $attr_name = $this->_getProductAttributeId('name');
6394
+ $attr_visibility = $this->_getProductAttributeId('visibility');
6395
+ $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
6396
+ $attr_image = $this->_getProductAttributeId('image');
6397
+ $attr_small_image = $this->_getProductAttributeId('small_image');
6398
+ $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
6399
+
6400
+ $cat_attr_name = $this->_getCategoryAttributeId('name');
6401
+ echo("\n replaceMagentoProductsMultistore 2\n");
6402
+
6403
+
6404
+ //clear products, inserting new products and updating old others.
6405
+ $query = "
6406
+ DELETE cpe
6407
+ FROM $catalog_product_entity cpe
6408
+ JOIN $stINch_products_mapping pm
6409
+ ON cpe.entity_id = pm.entity_id
6410
+ WHERE pm.shop_store_product_id IS NOT NULL
6411
+ AND pm.store_product_id IS NULL";
6412
+ $result = $this->db_do($query);
6413
+
6414
+
6415
+ echo("\n replaceMagentoProductsMultistore 3\n");
6416
 
6417
+ $result = $this->db_do("
6418
+ INSERT INTO $catalog_product_entity
6419
+ (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
6420
+ (SELECT
6421
+ pm.entity_id,
6422
+ $_getProductEntityTypeId,
6423
+ $_defaultAttributeSetId,
6424
+ 'simple',
6425
+ a.product_sku,
6426
+ NOW(),
6427
+ 0,
6428
+ a.store_product_id,
6429
+ a.sinch_product_id
6430
+ FROM $products_temp a
6431
+ LEFT JOIN $stINch_products_mapping pm
6432
+ ON a.store_product_id = pm.store_product_id
6433
+ AND a.sinch_product_id = pm.sinch_product_id
6434
+ WHERE pm.entity_id IS NULL
6435
+ )
6436
+ ON DUPLICATE KEY UPDATE
6437
+ sku = a.product_sku,
6438
+ store_product_id = a.store_product_id,
6439
+ sinch_product_id = a.sinch_product_id");
6440
+ // store_product_id = a.store_product_id,
6441
+ // sinch_product_id = a.sinch_product_id
6442
 
6443
+ $result = $this->db_do("
6444
+ INSERT INTO $catalog_product_entity
6445
+ (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
6446
+ (SELECT
6447
+ pm.entity_id,
6448
+ $_getProductEntityTypeId,
6449
+ $_defaultAttributeSetId,
6450
+ 'simple',
6451
+ a.product_sku,
6452
+ NOW(),
6453
+ 0,
6454
+ a.store_product_id,
6455
+ a.sinch_product_id
6456
+ FROM $products_temp a
6457
+ LEFT JOIN $stINch_products_mapping pm
6458
+ ON a.store_product_id = pm.store_product_id
6459
+ AND a.sinch_product_id = pm.sinch_product_id
6460
+ WHERE pm.entity_id IS NOT NULL
6461
+ )
6462
+ ON DUPLICATE KEY UPDATE
6463
+ sku = a.product_sku,
6464
+ store_product_id = a.store_product_id,
6465
+ sinch_product_id = a.sinch_product_id");
6466
+ // store_product_id = a.store_product_id,
6467
+ // sinch_product_id = a.sinch_product_id
6468
 
6469
+ echo("\n replaceMagentoProductsMultistore 4\n");
 
 
 
6470
 
 
 
 
 
 
 
6471
 
6472
+ //Set enabled
6473
+ $result = $this->db_do("
6474
+ DELETE cpei
6475
+ FROM $catalog_product_entity_int cpei
6476
+ LEFT JOIN $catalog_product_entity cpe
6477
+ ON cpei.entity_id = cpe.entity_id
6478
+ WHERE cpe.entity_id IS NULL");
6479
 
6480
+ $result = $this->db_do("
6481
+ INSERT INTO $catalog_product_entity_int
6482
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6483
+ (SELECT
6484
+ $_getProductEntityTypeId,
6485
+ $attr_atatus,
6486
+ w.website,
6487
+ a.entity_id,
6488
+ 1
6489
+ FROM $catalog_product_entity a
6490
+ JOIN $products_website_temp w
6491
+ ON a.store_product_id = w.store_product_id
6492
+ )
6493
+ ON DUPLICATE KEY UPDATE
6494
+ value = 1");
6495
 
 
 
 
 
 
6496
 
6497
+ echo("\n replaceMagentoProductsMultistore 5\n");
6498
 
 
6499
 
6500
+ // set status = 1 for all stores
6501
+ $result = $this->db_do("
6502
+ INSERT INTO $catalog_product_entity_int
6503
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6504
+ (SELECT
6505
+ $_getProductEntityTypeId,
6506
+ $attr_atatus,
6507
+ 0,
6508
+ a.entity_id,
6509
+ 1
6510
+ FROM $catalog_product_entity a
6511
+ )
6512
+ ON DUPLICATE KEY UPDATE
6513
+ value = 1");
6514
 
 
 
 
 
 
 
 
6515
 
6516
+ echo("\n replaceMagentoProductsMultistore 6\n");
 
 
 
 
 
6517
 
 
 
 
6518
 
6519
+ //Unifying products with categories.
6520
+ $result = $this->db_do("
6521
+ DELETE ccp
6522
+ FROM $catalog_category_product ccp
6523
+ LEFT JOIN $catalog_product_entity cpe
6524
+ ON ccp.product_id = cpe.entity_id
6525
+ WHERE cpe.entity_id IS NULL");
6526
 
 
 
6527
 
6528
+ echo("\n replaceMagentoProductsMultistore 7\n");
 
 
 
6529
 
 
 
 
 
6530
 
6531
+ $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6532
 
 
 
 
 
 
 
 
 
6533
 
6534
+ $result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
6535
+ $result = $this->db_do("
6536
+ CREATE TABLE $root_cats
6537
+ SELECT
6538
+ entity_id,
6539
+ path,
6540
+ SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
6541
+ LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
6542
+ SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
6543
+ FROM $catalog_category_entity
6544
+ ");
6545
+ $result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
6546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6547
 
6548
+ echo("\n replaceMagentoProductsMultistore 8\n");
6549
 
 
6550
 
6551
+ // !!! $this->_root_cat
6552
+ $result = $this->db_do("
6553
+ UPDATE IGNORE $catalog_category_product ccp
6554
+ LEFT JOIN $catalog_category_entity cce
6555
+ ON ccp.category_id = cce.entity_id
6556
+ JOIN $root_cats rc
6557
+ ON cce.entity_id = rc.entity_id
6558
+ SET ccp.category_id = rc.root_cat
6559
+ WHERE cce.entity_id IS NULL");
 
 
 
 
 
 
 
 
6560
 
 
 
 
 
 
 
6561
 
6562
+ echo("\n replaceMagentoProductsMultistore 9\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6563
 
 
6564
 
6565
+ $result = $this->db_do("
6566
+ DELETE ccp
6567
+ FROM $catalog_category_product ccp
6568
+ LEFT JOIN $catalog_category_entity cce
6569
+ ON ccp.category_id = cce.entity_id
6570
+ WHERE cce.entity_id IS NULL");
6571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6572
 
6573
+ //echo("\n\nget out...\n\n");
6574
+ //return;
 
 
 
 
6575
 
 
6576
 
6577
+ echo("\n replaceMagentoProductsMultistore 10\n");
6578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6579
 
6580
+ $catalog_category_product_for_delete_temp = $catalog_category_product . "_for_delete_temp";
 
 
 
 
 
6581
 
6582
+ // TEMPORARY
6583
+ $this->db_do(" DROP TABLE IF EXISTS $catalog_category_product_for_delete_temp");
6584
+ $this->db_do("
6585
+ CREATE TABLE $catalog_category_product_for_delete_temp
6586
+ (
6587
+ `category_id` int(10) unsigned NOT NULL default '0',
6588
+ `product_id` int(10) unsigned NOT NULL default '0',
6589
+ `store_product_id` int(10) NOT NULL default '0',
6590
+ `store_category_id` int(10) NOT NULL default '0',
6591
+ `new_category_id` int(10) NOT NULL default '0',
6592
+
6593
+ UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
6594
+ KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
6595
+ KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
6596
+ KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
6597
+ )");
6598
+
6599
+ echo("\n replaceMagentoProductsMultistore 11\n");
6600
 
6601
+ $result = $this->db_do("
6602
+ INSERT INTO $catalog_category_product_for_delete_temp
6603
+ (category_id, product_id, store_product_id)
6604
+ (SELECT
6605
+ ccp.category_id,
6606
+ ccp.product_id,
6607
+ cpe.store_product_id
6608
+ FROM $catalog_category_product ccp
6609
+ JOIN $catalog_product_entity cpe
6610
+ ON ccp.product_id = cpe.entity_id
6611
+ WHERE store_product_id IS NOT NULL)");
6612
+
6613
+ echo("\n replaceMagentoProductsMultistore 12\n");
6614
 
6615
+ $result = $this->db_do("
6616
+ UPDATE $catalog_category_product_for_delete_temp ccpfd
6617
+ JOIN $products_temp p
6618
+ ON ccpfd.store_product_id = p.store_product_id
6619
+ SET ccpfd.store_category_id = p.store_category_id
6620
+ WHERE ccpfd.store_product_id != 0");
 
 
 
 
 
 
 
6621
 
6622
+ echo("\n replaceMagentoProductsMultistore 13\n");
 
 
 
 
 
6623
 
6624
+ $result = $this->db_do("
6625
+ UPDATE $catalog_category_product_for_delete_temp ccpfd
6626
+ JOIN $stINch_categories_mapping scm
6627
+ ON ccpfd.store_category_id = scm.store_category_id
6628
+ SET ccpfd.new_category_id = scm.shop_entity_id
6629
+ WHERE ccpfd.store_category_id != 0");
6630
 
6631
+ echo("\n replaceMagentoProductsMultistore 14\n");
 
 
 
 
 
 
 
6632
 
6633
+ $result = $this->db_do("DELETE FROM $catalog_category_product_for_delete_temp WHERE category_id = new_category_id");
 
 
6634
 
 
 
 
 
 
 
6635
 
6636
+ $result = $this->db_do("
6637
+ DELETE ccp
6638
+ FROM $catalog_category_product ccp
6639
+ JOIN $catalog_category_product_for_delete_temp ccpfd
6640
+ ON ccp.product_id = ccpfd.product_id
6641
+ AND ccp.category_id = ccpfd.category_id");
6642
 
 
6643
 
6644
+ //echo("\n\nget out...\n\n");
6645
+ //return;
 
 
 
 
 
 
 
 
 
 
6646
 
 
 
 
 
 
 
6647
 
6648
+ echo("\n replaceMagentoProductsMultistore 15\n");
 
 
 
 
 
6649
 
6650
+ $result = $this->db_do("
6651
+ INSERT INTO $catalog_category_product
6652
+ (category_id, product_id)
6653
+ (SELECT
6654
+ scm.shop_entity_id,
6655
+ cpe.entity_id
6656
+ FROM $catalog_product_entity cpe
6657
+ JOIN $products_temp p
6658
+ ON cpe.store_product_id = p.store_product_id
6659
+ JOIN $stINch_categories_mapping scm
6660
+ ON p.store_category_id = scm.store_category_id
6661
+ )
6662
+ ON DUPLICATE KEY UPDATE
6663
+ product_id = cpe.entity_id");
6664
+
6665
+
6666
+ echo("\n replaceMagentoProductsMultistore 15.1 (add multi categories)\n");
6667
 
6668
+ $result = $this->db_do("
6669
+ INSERT INTO $catalog_category_product
6670
+ (category_id, product_id)
6671
+ (SELECT
6672
+ scm.shop_entity_id,
6673
+ cpe.entity_id
6674
+ FROM $catalog_product_entity cpe
6675
+ JOIN $products_temp p
6676
+ ON cpe.store_product_id = p.store_product_id
6677
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_product_categories') . " spc
6678
+ ON p.store_product_id=spc.store_product_id
6679
+ JOIN $stINch_categories_mapping scm
6680
+ ON spc.store_category_id = scm.store_category_id
6681
+ )
6682
+ ON DUPLICATE KEY UPDATE
6683
+ product_id = cpe.entity_id
6684
+ ");
6685
 
 
6686
 
6687
+ echo("\n replaceMagentoProductsMultistore 16\n");
6688
 
6689
+ //Indexing products and categories in the shop
6690
+ $result = $this->db_do("
6691
+ DELETE ccpi
6692
+ FROM $catalog_category_product_index ccpi
6693
+ LEFT JOIN $catalog_product_entity cpe
6694
+ ON ccpi.product_id = cpe.entity_id
6695
+ WHERE cpe.entity_id IS NULL");
6696
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6697
 
6698
+ echo("\n replaceMagentoProductsMultistore 16.2\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6699
 
 
 
 
 
 
 
6700
 
6701
+ $result = $this->db_do("
6702
+ INSERT INTO $catalog_category_product_index
6703
+ (category_id, product_id, position, is_parent, store_id, visibility)
6704
+ (SELECT
6705
+ a.category_id,
6706
+ a.product_id,
6707
+ a.position,
6708
+ 1,
6709
+ b.store_id,
6710
+ 4
6711
+ FROM $catalog_category_product a
6712
+ JOIN $core_store b
6713
+ )
6714
+ ON DUPLICATE KEY UPDATE
6715
+ visibility = 4");
6716
+
6717
+
6718
+ echo("\n replaceMagentoProductsMultistore 17\n");
6719
 
6720
+ // !!! $this->_root_cat
6721
+ $result = $this->db_do("
6722
+ INSERT ignore INTO $catalog_category_product_index
6723
+ (category_id, product_id, position, is_parent, store_id, visibility)
6724
+ (SELECT
6725
+ rc.root_cat,
6726
+ a.product_id,
6727
+ a.position,
6728
+ 1,
6729
+ b.store_id,
6730
+ 4
6731
+ FROM $catalog_category_product a
6732
+ JOIN $root_cats rc
6733
+ ON a.category_id = rc.entity_id
6734
+ JOIN $core_store b
6735
+ )
6736
+ ON DUPLICATE KEY UPDATE
6737
+ visibility = 4");
6738
+
6739
+ echo("\n replaceMagentoProductsMultistore 18\n");
6740
 
 
 
 
 
6741
 
6742
+ //Set product name for specific web sites
6743
+ $result = $this->db_do("
6744
+ DELETE cpev
6745
+ FROM $catalog_product_entity_varchar cpev
6746
+ LEFT JOIN $catalog_product_entity cpe
6747
+ ON cpev.entity_id = cpe.entity_id
6748
+ WHERE cpe.entity_id IS NULL");
6749
+
6750
+ $result = $this->db_do("
6751
+ INSERT INTO $catalog_product_entity_varchar
6752
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6753
+ (SELECT
6754
+ $_getProductEntityTypeId,
6755
+ $attr_name,
6756
+ w.website,
6757
+ a.entity_id,
6758
+ b.product_name
6759
+ FROM $catalog_product_entity a
6760
+ JOIN $products_temp b
6761
+ ON a.store_product_id = b.store_product_id
6762
+ JOIN $products_website_temp w
6763
+ ON a.store_product_id = w.store_product_id
6764
+ )
6765
+ ON DUPLICATE KEY UPDATE
6766
+ value = b.product_name");
6767
+
6768
+ echo("\n replaceMagentoProductsMultistore 19\n");
6769
 
 
 
 
 
 
 
 
6770
 
6771
+ // product name for all web sites
6772
+ $result = $this->db_do("
6773
+ INSERT INTO $catalog_product_entity_varchar
6774
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6775
+ (SELECT
6776
+ $_getProductEntityTypeId,
6777
+ $attr_name,
6778
+ 0,
6779
+ a.entity_id,
6780
+ b.product_name
6781
+ FROM $catalog_product_entity a
6782
+ JOIN $products_temp b
6783
+ ON a.store_product_id = b.store_product_id
6784
+ )
6785
+ ON DUPLICATE KEY UPDATE
6786
+ value = b.product_name");
6787
+
6788
+ echo("\n replaceMagentoProductsMultistore 20\n");
6789
 
 
 
 
6790
 
6791
+ $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
6792
+ $this->addDescriptions();
6793
+ $this->cleanProductDistributors();
6794
+ if ($this->product_file_format == "NEW") {
6795
+ $this->addReviews();
6796
+ $this->addWeight();
6797
+ $this->addSearchCache();
6798
+ $this->addPdfUrl();
6799
+ $this->addShortDescriptions();
6800
+ $this->addProductDistributors();
6801
  }
6802
+ $this->addEAN();
6803
+ $this->addSpecification();
6804
+ $this->addManufacturers();
6805
 
6806
+ //echo(" .... DONE\n");return;
6807
 
6808
+ echo("\n replaceMagentoProductsMultistore 21\n");
 
 
 
6809
 
6810
+ //Enabling product index.
6811
  $result = $this->db_do("
6812
+ DELETE cpei
6813
+ FROM $catalog_product_enabled_index cpei
6814
+ LEFT JOIN $catalog_product_entity cpe
6815
+ ON cpei.product_id = cpe.entity_id
6816
+ WHERE cpe.entity_id IS NULL");
6817
+
6818
+ echo("\n replaceMagentoProductsMultistore 22\n");
6819
+
6820
+ $result = $this->db_do("
6821
+ INSERT INTO $catalog_product_enabled_index
6822
+ (product_id, store_id, visibility)
6823
+ (SELECT
6824
+ a.entity_id,
6825
+ w.website,
6826
+ 4
6827
+ FROM $catalog_product_entity a
6828
+ JOIN $products_website_temp w
6829
+ ON a.store_product_id = w.store_product_id
6830
+ )
6831
+ ON DUPLICATE KEY UPDATE
6832
+ visibility = 4");
6833
+
6834
+ echo("\n replaceMagentoProductsMultistore 23\n");
6835
+
6836
+ $result = $this->db_do("
6837
+ INSERT INTO $catalog_product_enabled_index
6838
+ (product_id, store_id, visibility)
6839
+ (SELECT
6840
+ a.entity_id,
6841
+ 0,
6842
+ 4
6843
+ FROM $catalog_product_entity a
6844
+ JOIN $products_website_temp w
6845
+ ON a.store_product_id = w.store_product_id
6846
+ )
6847
+ ON DUPLICATE KEY UPDATE
6848
+ visibility = 4");
6849
+
6850
+
6851
+ /////////////////////////////////////echo(" .... DONE\n");return;
6852
+
6853
+
6854
+ echo("\n replaceMagentoProductsMultistore 24\n");
6855
+
6856
+ $result = $this->db_do("
6857
+ INSERT INTO $catalog_product_entity_int
6858
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6859
+ (SELECT
6860
+ $_getProductEntityTypeId,
6861
+ $attr_visibility,
6862
+ w.website,
6863
+ a.entity_id,
6864
+ 4
6865
+ FROM $catalog_product_entity a
6866
+ JOIN $products_website_temp w
6867
+ ON a.store_product_id = w.store_product_id
6868
+ )
6869
+ ON DUPLICATE KEY UPDATE
6870
+ value = 4");
6871
+
6872
+ echo("\n replaceMagentoProductsMultistore 25\n");
6873
+
6874
+ $result = $this->db_do("
6875
+ INSERT INTO $catalog_product_entity_int
6876
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6877
+ (SELECT
6878
+ $_getProductEntityTypeId,
6879
+ $attr_visibility,
6880
+ 0,
6881
+ a.entity_id,
6882
+ 4
6883
+ FROM $catalog_product_entity a
6884
+ )
6885
+ ON DUPLICATE KEY UPDATE
6886
+ value = 4");
6887
+
6888
+ echo("\n replaceMagentoProductsMultistore 26\n");
6889
+
6890
+ $result = $this->db_do("
6891
+ DELETE cpw
6892
+ FROM $catalog_product_website cpw
6893
+ LEFT JOIN $catalog_product_entity cpe
6894
+ ON cpw.product_id = cpe.entity_id
6895
+ WHERE cpe.entity_id IS NULL");
6896
+
6897
+ echo("\n replaceMagentoProductsMultistore 27\n");
6898
+
6899
+ $result = $this->db_do("
6900
+ INSERT INTO $catalog_product_website
6901
+ (product_id, website_id)
6902
+ (SELECT
6903
+ a.entity_id,
6904
+ w.website_id
6905
+ FROM $catalog_product_entity a
6906
+ JOIN $products_website_temp w
6907
+ ON a.store_product_id = w.store_product_id
6908
+ )
6909
+ ON DUPLICATE KEY UPDATE
6910
+ product_id = a.entity_id,
6911
+ website_id = w.website_id");
6912
+
6913
+
6914
+ //echo(" .... DONE\n");return;
6915
+
6916
+
6917
+ echo("\n replaceMagentoProductsMultistore 28\n");
6918
+
6919
+ // temporary disabled mart@bintime.com
6920
+ //$result = $this->db_do("
6921
+ // UPDATE catalog_category_entity_int a
6922
+ // SET a.value = 0
6923
+ // WHERE a.attribute_id = 32
6924
+ //");
6925
+
6926
+
6927
+ //Adding tax class "Taxable Goods"
6928
+ $result = $this->db_do("
6929
+ INSERT INTO $catalog_product_entity_int
6930
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6931
+ (SELECT
6932
+ $_getProductEntityTypeId,
6933
+ $attr_tax_class_id,
6934
+ w.website,
6935
+ a.entity_id,
6936
+ 2
6937
+ FROM $catalog_product_entity a
6938
+ JOIN $products_website_temp w
6939
+ ON a.store_product_id = w.store_product_id
6940
+ )
6941
+ ON DUPLICATE KEY UPDATE
6942
+ value = 2");
6943
+
6944
+ echo("\n replaceMagentoProductsMultistore 29\n");
6945
+
6946
+ $result = $this->db_do("
6947
+ INSERT INTO $catalog_product_entity_int
6948
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6949
+ (SELECT
6950
+ $_getProductEntityTypeId,
6951
+ $attr_tax_class_id,
6952
+ 0,
6953
+ a.entity_id,
6954
+ 2
6955
+ FROM $catalog_product_entity a
6956
+ )
6957
+ ON DUPLICATE KEY UPDATE
6958
+ value = 2");
6959
+
6960
+ echo("\n replaceMagentoProductsMultistore 30\n");
6961
+
6962
+ // Load url Image
6963
+ $result = $this->db_do("
6964
+ INSERT INTO $catalog_product_entity_varchar
6965
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6966
+ (SELECT
6967
+ $_getProductEntityTypeId,
6968
+ $attr_image,
6969
+ w.store_id,
6970
+ a.entity_id,
6971
+ b.main_image_url
6972
+ FROM $catalog_product_entity a
6973
+ JOIN $core_store w
6974
+ JOIN $products_temp b
6975
+ ON a.store_product_id = b.store_product_id
6976
+ )
6977
+ ON DUPLICATE KEY UPDATE
6978
+ value = b.main_image_url");
6979
+
6980
+ echo("\n replaceMagentoProductsMultistore 31\n");
6981
+
6982
+ // image for specific web sites
6983
+ $result = $this->db_do("
6984
+ INSERT INTO $catalog_product_entity_varchar
6985
+ (entity_type_id, attribute_id, store_id, entity_id, value)
6986
+ (SELECT
6987
+ $_getProductEntityTypeId,
6988
+ $attr_image,
6989
+ 0,
6990
+ a.entity_id,
6991
+ b.main_image_url
6992
+ FROM $catalog_product_entity a
6993
+ JOIN $products_temp b
6994
+ ON a.store_product_id = b.store_product_id
6995
+ )
6996
+ ON DUPLICATE KEY UPDATE
6997
+ value = b.main_image_url");
6998
+
6999
+ echo("\n replaceMagentoProductsMultistore 32\n");
7000
+
7001
+ // small_image for specific web sites
7002
+ $result = $this->db_do("
7003
+ INSERT INTO $catalog_product_entity_varchar
7004
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7005
+ (SELECT
7006
+ $_getProductEntityTypeId,
7007
+ $attr_small_image,
7008
+ w.store_id,
7009
+ a.entity_id,
7010
+ b.medium_image_url
7011
+ FROM $catalog_product_entity a
7012
+ JOIN $core_store w
7013
+ JOIN $products_temp b
7014
+ ON a.store_product_id = b.store_product_id
7015
+ )
7016
+ ON DUPLICATE KEY UPDATE
7017
+ value = b.medium_image_url");
7018
+
7019
+ echo("\n replaceMagentoProductsMultistore 33\n");
7020
 
7021
+ // small_image for all web sites
7022
+ $result = $this->db_do("
7023
+ INSERT INTO $catalog_product_entity_varchar
7024
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7025
+ (SELECT
7026
+ $_getProductEntityTypeId,
7027
+ $attr_small_image,
7028
+ 0,
7029
+ a.entity_id,
7030
+ b.medium_image_url
7031
+ FROM $catalog_product_entity a
7032
+ JOIN $core_store w
7033
+ JOIN $products_temp b
7034
+ ON a.store_product_id = b.store_product_id
7035
+ )
7036
+ ON DUPLICATE KEY UPDATE
7037
+ value = b.medium_image_url");
7038
+
7039
+ echo("\n replaceMagentoProductsMultistore 34\n");
7040
 
7041
+ // thumbnail for specific web site
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7042
  $result = $this->db_do("
7043
+ INSERT INTO $catalog_product_entity_varchar
7044
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7045
+ (SELECT
7046
+ $_getProductEntityTypeId,
7047
+ $attr_thumbnail,
7048
+ w.store_id,
7049
+ a.entity_id,
7050
+ b.thumb_image_url
7051
+ FROM $catalog_product_entity a
7052
+ JOIN $core_store w
7053
+ JOIN $products_temp b
7054
+ ON a.store_product_id = b.store_product_id
7055
+ )
7056
+ ON DUPLICATE KEY UPDATE
7057
+ value = b.thumb_image_url");
7058
+
7059
+ echo("\n replaceMagentoProductsMultistore 35\n");
7060
 
7061
+ // thumbnail for all web sites
7062
+ $result = $this->db_do("
7063
+ INSERT INTO $catalog_product_entity_varchar
7064
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7065
+ (SELECT
7066
+ $_getProductEntityTypeId,
7067
+ $attr_thumbnail,
7068
+ 0,
7069
+ a.entity_id,
7070
+ b.thumb_image_url
7071
+ FROM $catalog_product_entity a
7072
+ JOIN $core_store w
7073
+ JOIN $products_temp b
7074
+ ON a.store_product_id = b.store_product_id
7075
+ )
7076
+ ON DUPLICATE KEY UPDATE
7077
+ value = b.thumb_image_url");
7078
+
7079
+ echo("\n replaceMagentoProductsMultistore 36\n");
7080
+
7081
+
7082
+ /*STP DELETE
7083
+ //Refresh fulltext search
7084
+ $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
7085
+ $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
7086
 
 
 
 
 
 
 
 
 
 
 
7087
 
7088
+ echo("\n replaceMagentoProductsMultistore 36.2\n");
7089
+ $q = "
7090
+ INSERT INTO {$catalogsearch_fulltext}_tmp
7091
+ (product_id, store_id, data_index)
7092
+ (SELECT
7093
+ a.entity_id,
7094
+ w.website,
7095
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
7096
+ FROM $catalog_product_entity a
7097
+ JOIN $products_website_temp w
7098
+ ON a.store_product_id = w.store_product_id
7099
+ LEFT JOIN $catalog_category_product b
7100
+ ON a.entity_id = b.product_id
7101
+ LEFT JOIN $catalog_category_entity_varchar c
7102
+ ON b.category_id = c.entity_id
7103
+ AND c.attribute_id = $cat_attr_name
7104
+ LEFT JOIN $catalog_product_entity_varchar e
7105
+ ON a.entity_id = e.entity_id
7106
+ AND e.attribute_id = $attr_name
7107
+ LEFT JOIN $catalog_product_website j
7108
+ ON a.entity_id = j.product_id
7109
+ LEFT JOIN $products_temp f
7110
+ ON a.store_product_id = f.store_product_id
7111
+ )
7112
+ ON DUPLICATE KEY UPDATE
7113
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
7114
+ echo("\n\n============================\n$q\n============================\n\n");
7115
 
 
7116
 
7117
+ $result = $this->db_do("
7118
+ INSERT INTO {$catalogsearch_fulltext}_tmp
7119
+ (product_id, store_id, data_index)
7120
+ (SELECT
7121
+ a.entity_id,
7122
+ w.website,
7123
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
7124
+ FROM $catalog_product_entity a
7125
+ JOIN $products_website_temp w
7126
+ ON a.store_product_id = w.store_product_id
7127
+ LEFT JOIN $catalog_category_product b
7128
+ ON a.entity_id = b.product_id
7129
+ LEFT JOIN $catalog_category_entity_varchar c
7130
+ ON b.category_id = c.entity_id
7131
+ AND c.attribute_id = $cat_attr_name
7132
+ LEFT JOIN $catalog_product_entity_varchar e
7133
+ ON a.entity_id = e.entity_id
7134
+ AND e.attribute_id = $attr_name
7135
+ LEFT JOIN $catalog_product_website j
7136
+ ON a.entity_id = j.product_id
7137
+ LEFT JOIN $products_temp f
7138
+ ON a.store_product_id = f.store_product_id
7139
+ )
7140
+ ON DUPLICATE KEY UPDATE
7141
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
7142
 
7143
+ echo("\n replaceMagentoProductsMultistore 37\n");
7144
+
7145
+
7146
+ $result = $this->db_do("
7147
+ INSERT INTO {$catalogsearch_fulltext}_tmp
7148
+ (product_id, store_id, data_index)
7149
+ (SELECT
7150
+ a.entity_id,
7151
+ w.website,
7152
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
7153
+ FROM $catalog_product_entity a
7154
+ JOIN $products_website_temp w
7155
+ ON a.store_product_id = w.store_product_id
7156
+ LEFT JOIN $catalog_category_product b
7157
+ ON a.entity_id = b.product_id
7158
+ LEFT JOIN $catalog_category_entity_varchar c
7159
+ ON b.category_id = c.entity_id
7160
+ AND c.attribute_id = $cat_attr_name
7161
+ LEFT JOIN $catalog_product_entity_varchar e
7162
+ ON a.entity_id = e.entity_id
7163
+ AND e.attribute_id = $attr_name
7164
+ LEFT JOIN $products_temp f
7165
+ ON a.store_product_id = f.store_product_id
7166
+ )
7167
+ ON DUPLICATE KEY UPDATE
7168
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
7169
+
7170
+ echo("\n replaceMagentoProductsMultistore 38\n");
7171
+
7172
+ $result = $this->db_do("
7173
+ DELETE cf
7174
+ FROM $catalogsearch_fulltext cf
7175
+ LEFT JOIN $catalog_product_entity cpe
7176
+ ON cf.product_id = cpe.entity_id
7177
+ WHERE cpe.entity_id IS NULL");
 
 
 
 
 
 
 
7178
 
7179
+ echo("\n replaceMagentoProductsMultistore 39\n");
7180
+
7181
+ $result = $this->db_do("
7182
+ INSERT INTO $catalogsearch_fulltext
7183
+ (product_id, store_id, data_index)
7184
+ (SELECT
7185
+ a.product_id,
7186
+ a.store_id,
7187
+ a.data_index
7188
+ FROM {$catalogsearch_fulltext}_tmp a
7189
+ )
7190
+ ON DUPLICATE KEY UPDATE
7191
+ data_index = a.data_index");
7192
+
7193
+ echo("\n replaceMagentoProductsMultistore 40\n");
7194
+
7195
+ $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
7196
+ //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
7197
+ //TODO add something else
7198
+ STP DELETE*/
7199
 
7200
+ $this->addRelatedProducts();
7201
+ echo("\n replaceMagentoProductsMultistore 41\n");
7202
  }
7203
 
7204
  #################################################################################################
7205
+
7206
+ public function replaceMagentoProductsMultistoreMERGE($coincidence)
7207
+ {
7208
+
7209
+ echo("\n replaceMagentoProductsMultistoreMERGE 1\n");
7210
+
7211
 
7212
  $connection = Mage::getModel('core/resource')->getConnection('core_write');
7213
 
 
 
 
 
 
 
 
7214
 
7215
+ $products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
7216
+ $products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
7217
+ $catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
7218
+ $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
7219
+ $catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
7220
+ $catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
7221
+ $stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
7222
+ $stINch_products = Mage::getSingleton('core/resource')->getTableName('stINch_products');
7223
+ $catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
7224
+ $stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
7225
+ $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
7226
+ $core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
7227
+ $catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
7228
+ $catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
7229
+ //STP DELETE $catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
7230
+ // $catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
7231
+ $catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
7232
+
7233
+ $_getProductEntityTypeId = $this->_getProductEntityTypeId();
7234
+ $_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
7235
+
7236
+ $attr_atatus = $this->_getProductAttributeId('status');
7237
+ $attr_name = $this->_getProductAttributeId('name');
7238
+ $attr_visibility = $this->_getProductAttributeId('visibility');
7239
+ $attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
7240
+ $attr_image = $this->_getProductAttributeId('image');
7241
+ $attr_small_image = $this->_getProductAttributeId('small_image');
7242
+ $attr_thumbnail = $this->_getProductAttributeId('thumbnail');
7243
+
7244
+ $cat_attr_name = $this->_getCategoryAttributeId('name');
7245
+ echo("\n replaceMagentoProductsMultistoreMERGE 2\n");
7246
+
7247
+
7248
+ //clear products, inserting new products and updating old others.
7249
+ $query = "
7250
+ DELETE cpe
7251
+ FROM $catalog_product_entity cpe
7252
+ JOIN $stINch_products_mapping pm
7253
+ ON cpe.entity_id = pm.entity_id
7254
+ WHERE pm.shop_store_product_id IS NOT NULL
7255
+ AND pm.store_product_id IS NULL";
7256
+ $result = $this->db_do($query);
7257
+
7258
+
7259
+ echo("\n replaceMagentoProductsMultistoreMERGE 3\n");
7260
+
7261
  $result = $this->db_do("
7262
+ INSERT INTO $catalog_product_entity
7263
+ (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
7264
+ (SELECT
7265
+ pm.entity_id,
7266
+ $_getProductEntityTypeId,
7267
+ $_defaultAttributeSetId,
7268
+ 'simple',
7269
+ a.product_sku,
7270
+ NOW(),
7271
+ 0,
7272
+ a.store_product_id,
7273
+ a.sinch_product_id
7274
+ FROM $products_temp a
7275
+ LEFT JOIN $stINch_products_mapping pm
7276
+ ON a.store_product_id = pm.store_product_id
7277
+ AND a.sinch_product_id = pm.sinch_product_id
7278
+ WHERE pm.entity_id IS NOT NULL
7279
+ )
7280
+ ON DUPLICATE KEY UPDATE
7281
+ sku = a.product_sku,
7282
+ store_product_id = a.store_product_id,
7283
+ sinch_product_id = a.sinch_product_id");
7284
+ // store_product_id = a.store_product_id,
7285
+ // sinch_product_id = a.sinch_product_id
 
 
 
 
 
 
 
 
 
7286
 
7287
  $result = $this->db_do("
7288
+ INSERT INTO $catalog_product_entity
7289
+ (entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
7290
+ (SELECT
7291
+ pm.entity_id,
7292
+ $_getProductEntityTypeId,
7293
+ $_defaultAttributeSetId,
7294
+ 'simple',
7295
+ a.product_sku,
7296
+ NOW(),
7297
+ 0,
7298
+ a.store_product_id,
7299
+ a.sinch_product_id
7300
+ FROM $products_temp a
7301
+ LEFT JOIN $stINch_products_mapping pm
7302
+ ON a.store_product_id = pm.store_product_id
7303
+ AND a.sinch_product_id = pm.sinch_product_id
7304
+ WHERE pm.entity_id IS NULL
7305
+ )
7306
+ ON DUPLICATE KEY UPDATE
7307
+ sku = a.product_sku,
7308
+ store_product_id = a.store_product_id,
7309
+ sinch_product_id = a.sinch_product_id");
7310
+ // store_product_id = a.store_product_id,
7311
+ // sinch_product_id = a.sinch_product_id
7312
+
7313
+
7314
+ echo("\n replaceMagentoProductsMultistoreMERGE 4\n");
7315
+
 
 
 
 
 
7316
 
7317
  //Set enabled
7318
+ $result = $this->db_do("
7319
+ DELETE cpei
7320
+ FROM $catalog_product_entity_int cpei
7321
+ LEFT JOIN $catalog_product_entity cpe
7322
+ ON cpei.entity_id = cpe.entity_id
7323
+ WHERE cpe.entity_id IS NULL");
7324
 
7325
  $result = $this->db_do("
7326
+ INSERT INTO $catalog_product_entity_int
7327
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7328
+ (SELECT
7329
+ $_getProductEntityTypeId,
7330
+ $attr_atatus,
7331
+ w.website,
7332
+ a.entity_id,
7333
+ 1
7334
+ FROM $catalog_product_entity a
7335
+ JOIN $products_website_temp w
7336
+ ON a.store_product_id = w.store_product_id
7337
+ )
7338
+ ON DUPLICATE KEY UPDATE
7339
+ value = 1");
7340
+
7341
+
7342
+ echo("\n replaceMagentoProductsMultistoreMERGE 5\n");
7343
+
7344
+
 
7345
  // set status = 1 for all stores
7346
  $result = $this->db_do("
7347
+ INSERT INTO $catalog_product_entity_int
7348
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7349
+ (SELECT
7350
+ $_getProductEntityTypeId,
7351
+ $attr_atatus,
7352
+ 0,
7353
+ a.entity_id,
7354
+ 1
7355
+ FROM $catalog_product_entity a
7356
+ )
7357
+ ON DUPLICATE KEY UPDATE
7358
+ value = 1");
7359
+
7360
+
7361
+ echo("\n replaceMagentoProductsMultistoreMERGE 6\n");
7362
+
 
7363
 
7364
  //Unifying products with categories.
7365
+ $result = $this->db_do("
7366
+ DELETE ccp
7367
+ FROM $catalog_category_product ccp
7368
+ LEFT JOIN $catalog_product_entity cpe
7369
+ ON ccp.product_id = cpe.entity_id
7370
+ WHERE cpe.entity_id IS NULL");
7371
 
 
 
 
 
 
 
 
 
 
 
 
7372
 
7373
+ echo("\n replaceMagentoProductsMultistoreMERGE 7\n");
7374
 
 
 
 
 
 
 
 
 
 
7375
 
7376
+ $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
7377
 
7378
+ $result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
7379
+ $result = $this->db_do("
7380
+ CREATE TABLE $root_cats
7381
+ SELECT
7382
+ entity_id,
7383
+ path,
7384
+ SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
7385
+ LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
7386
+ SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
7387
+ FROM $catalog_category_entity
7388
+ ");
7389
+ $result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
 
 
7390
 
 
7391
 
7392
+ echo("\n replaceMagentoProductsMultistoreMERGE 8\n");
7393
+
7394
+
7395
+ // !!! $this->_root_cat
7396
  $result = $this->db_do("
7397
+ UPDATE IGNORE $catalog_category_product ccp
7398
+ LEFT JOIN $catalog_category_entity cce
7399
+ ON ccp.category_id = cce.entity_id
7400
+ JOIN $root_cats rc
7401
+ ON cce.entity_id = rc.entity_id
7402
+ SET ccp.category_id = rc.root_cat
7403
+ WHERE cce.entity_id IS NULL");
 
 
 
 
 
 
 
7404
 
 
 
 
 
 
 
7405
 
7406
+ echo("\n replaceMagentoProductsMultistoreMERGE 9\n");
7407
+
7408
+
7409
+ $result = $this->db_do("
7410
+ DELETE ccp
7411
+ FROM $catalog_category_product ccp
7412
+ LEFT JOIN $catalog_category_entity cce
7413
+ ON ccp.category_id = cce.entity_id
7414
+ WHERE cce.entity_id IS NULL");
7415
+
7416
+
7417
+ $stinch_products_delete = Mage::getSingleton('core/resource')->getTableName('stinch_products_delete');
7418
+
7419
+ $result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
7420
+ $result = $this->db_do("
7421
+ CREATE TABLE $stinch_products_delete
7422
+ SELECT cpe.entity_id
7423
+ FROM $catalog_product_entity cpe
7424
+ WHERE cpe.entity_id NOT IN
7425
+ (
7426
+ SELECT cpe2.entity_id
7427
+ FROM $catalog_product_entity cpe2
7428
+ JOIN $stINch_products sp
7429
+ ON cpe2.sinch_product_id = sp.sinch_product_id
7430
+ )");
7431
+
7432
+
7433
+ $result = $this->db_do("DELETE cpe FROM $catalog_product_entity cpe JOIN $stinch_products_delete spd USING(entity_id)");
7434
+
7435
+ $result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
7436
+
7437
+
7438
+ //echo("\n\nget out...\n\n");
7439
+ //return;
7440
+
7441
+ /**
7442
+ *
7443
+ * echo("\n replaceMagentoProductsMultistoreMERGE 10\n");
7444
+ *
7445
+ *
7446
+ * // TEMPORARY
7447
+ * $this->db_do(" DROP TABLE IF EXISTS {$catalog_category_product}_for_delete_temp");
7448
+ * $this->db_do("
7449
+ * CREATE TABLE `{$catalog_category_product}_for_delete_temp`
7450
+ * (
7451
+ * `category_id` int(10) unsigned NOT NULL default '0',
7452
+ * `product_id` int(10) unsigned NOT NULL default '0',
7453
+ * `store_product_id` int(10) NOT NULL default '0',
7454
+ * `store_category_id` int(10) NOT NULL default '0',
7455
+ * `new_category_id` int(10) NOT NULL default '0',
7456
+ *
7457
+ * UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
7458
+ * KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
7459
+ * KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
7460
+ * KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
7461
+ * )");
7462
+ *
7463
+ * echo("\n replaceMagentoProductsMultistoreMERGE 11\n");
7464
+ *
7465
+ * $result = $this->db_do("
7466
+ * INSERT INTO {$catalog_category_product}_for_delete_temp
7467
+ * (category_id, product_id, store_product_id)
7468
+ * (SELECT
7469
+ * ccp.category_id,
7470
+ * ccp.product_id,
7471
+ * cpe.store_product_id
7472
+ * FROM $catalog_category_product ccp
7473
+ * JOIN $catalog_product_entity cpe
7474
+ * ON ccp.product_id = cpe.entity_id
7475
+ * WHERE store_product_id IS NOT NULL)");
7476
+ *
7477
+ * echo("\n replaceMagentoProductsMultistoreMERGE 12\n");
7478
+ *
7479
+ * $result = $this->db_do("
7480
+ * UPDATE {$catalog_category_product}_for_delete_temp ccpfd
7481
+ * JOIN $products_temp p
7482
+ * ON ccpfd.store_product_id = p.store_product_id
7483
+ * SET ccpfd.store_category_id = p.store_category_id
7484
+ * WHERE ccpfd.store_product_id != 0");
7485
+ *
7486
+ * echo("\n replaceMagentoProductsMultistoreMERGE 13\n");
7487
+ *
7488
+ * $result = $this->db_do("
7489
+ * UPDATE {$catalog_category_product}_for_delete_temp ccpfd
7490
+ * JOIN $stINch_categories_mapping scm
7491
+ * ON ccpfd.store_category_id = scm.store_category_id
7492
+ * SET ccpfd.new_category_id = scm.shop_entity_id
7493
+ * WHERE ccpfd.store_category_id != 0");
7494
+ *
7495
+ * echo("\n replaceMagentoProductsMultistoreMERGE 14\n");
7496
+ *
7497
+ * $result = $this->db_do("DELETE FROM {$catalog_category_product}_for_delete_temp WHERE category_id = new_category_id");
7498
+ *
7499
+ *
7500
+ *
7501
+ * $result = $this->db_do("
7502
+ * DELETE ccp
7503
+ * FROM $catalog_category_product ccp
7504
+ * JOIN {$catalog_category_product}_for_delete_temp ccpfd
7505
+ * ON ccp.product_id = ccpfd.product_id
7506
+ * AND ccp.category_id = ccpfd.category_id");
7507
+ *
7508
+ * /**/
7509
+
7510
+
7511
+ echo("\n replaceMagentoProductsMultistoreMERGE 15\n");
7512
 
 
 
7513
 
7514
  $result = $this->db_do("
7515
+ INSERT INTO $catalog_category_product
7516
+ (category_id, product_id)
7517
+ (SELECT
7518
+ scm.shop_entity_id,
7519
+ cpe.entity_id
7520
+ FROM $catalog_product_entity cpe
7521
+ JOIN $products_temp p
7522
+ ON cpe.store_product_id = p.store_product_id
7523
+ JOIN $stINch_categories_mapping scm
7524
+ ON p.store_category_id = scm.store_category_id
7525
+ )
7526
+ ON DUPLICATE KEY UPDATE
7527
+ product_id = cpe.entity_id");
7528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7529
 
7530
+ echo("\n replaceMagentoProductsMultistoreMERGE 15.1 (add multi categories)\n");
7531
 
 
7532
 
7533
+ $result = $this->db_do("
7534
+ INSERT INTO $catalog_category_product
7535
+ (category_id, product_id)
7536
+ (SELECT
7537
+ scm.shop_entity_id,
7538
+ cpe.entity_id
7539
+ FROM $catalog_product_entity cpe
7540
+ JOIN $products_temp p
7541
+ ON cpe.store_product_id = p.store_product_id
7542
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_product_categories') . " spc
7543
+ ON p.store_product_id=spc.store_product_id
7544
+ JOIN $stINch_categories_mapping scm
7545
+ ON spc.store_category_id = scm.store_category_id
7546
+ )
7547
+ ON DUPLICATE KEY UPDATE
7548
+ product_id = cpe.entity_id
7549
+ ");
7550
 
7551
 
7552
+ echo("\n replaceMagentoProductsMultistoreMERGE 16\n");
7553
 
7554
+ //Indexing products and categories in the shop
7555
  $result = $this->db_do("
7556
+ DELETE ccpi
7557
+ FROM $catalog_category_product_index ccpi
7558
+ LEFT JOIN $catalog_product_entity cpe
7559
+ ON ccpi.product_id = cpe.entity_id
7560
+ WHERE cpe.entity_id IS NULL");
 
 
 
 
 
 
 
 
 
 
 
 
7561
 
7562
 
7563
+ echo("\n replaceMagentoProductsMultistoreMERGE 16.2\n");
7564
 
 
 
 
 
 
 
7565
 
7566
  $result = $this->db_do("
7567
+ INSERT INTO $catalog_category_product_index
7568
+ (category_id, product_id, position, is_parent, store_id, visibility)
7569
+ (SELECT
7570
+ a.category_id,
7571
+ a.product_id,
7572
+ a.position,
7573
+ 1,
7574
+ b.store_id,
7575
+ 4
7576
+ FROM $catalog_category_product a
7577
+ JOIN $core_store b
7578
+ )
7579
+ ON DUPLICATE KEY UPDATE
7580
+ visibility = 4");
7581
+
7582
+
7583
+ echo("\n replaceMagentoProductsMultistoreMERGE 17\n");
7584
+ $root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
7585
+ // !!! $this->_root_cat
 
 
 
7586
  $result = $this->db_do("
7587
+ INSERT ignore INTO $catalog_category_product_index
7588
+ (category_id, product_id, position, is_parent, store_id, visibility)
7589
+ (SELECT
7590
+ rc.root_cat,
7591
+ a.product_id,
7592
+ a.position,
7593
+ 1,
7594
+ b.store_id,
7595
+ 4
7596
+ FROM $catalog_category_product a
7597
+ JOIN $root_cats rc
7598
+ ON a.category_id = rc.entity_id
7599
+ JOIN $core_store b
7600
+ )
7601
+ ON DUPLICATE KEY UPDATE
7602
+ visibility = 4");
7603
+
7604
+ echo("\n replaceMagentoProductsMultistoreMERGE 18\n");
7605
+
 
 
7606
 
7607
  //Set product name for specific web sites
 
 
 
 
 
7608
  $result = $this->db_do("
7609
+ DELETE cpev
7610
+ FROM $catalog_product_entity_varchar cpev
7611
+ LEFT JOIN $catalog_product_entity cpe
7612
+ ON cpev.entity_id = cpe.entity_id
7613
+ WHERE cpe.entity_id IS NULL");
7614
+
7615
+ $result = $this->db_do("
7616
+ INSERT INTO $catalog_product_entity_varchar
7617
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7618
+ (SELECT
7619
+ $_getProductEntityTypeId,
7620
+ $attr_name,
7621
+ w.website,
7622
+ a.entity_id,
7623
+ b.product_name
7624
+ FROM $catalog_product_entity a
7625
+ JOIN $products_temp b
7626
+ ON a.store_product_id = b.store_product_id
7627
+ JOIN $products_website_temp w
7628
+ ON a.store_product_id = w.store_product_id
7629
+ )
7630
+ ON DUPLICATE KEY UPDATE
7631
+ value = b.product_name");
7632
+
7633
+ echo("\n replaceMagentoProductsMultistoreMERGE 19\n");
7634
+
7635
 
7636
  // product name for all web sites
7637
  $result = $this->db_do("
7638
+ INSERT INTO $catalog_product_entity_varchar
7639
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7640
+ (SELECT
7641
+ $_getProductEntityTypeId,
7642
+ $attr_name,
7643
+ 0,
7644
+ a.entity_id,
7645
+ b.product_name
7646
+ FROM $catalog_product_entity a
7647
+ JOIN $products_temp b
7648
+ ON a.store_product_id = b.store_product_id
7649
+ )
7650
+ ON DUPLICATE KEY UPDATE
7651
+ value = b.product_name");
7652
+
7653
+ echo("\n replaceMagentoProductsMultistoreMERGE 20\n");
7654
+
 
 
 
7655
 
7656
  $this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
7657
  $this->addDescriptions();
7658
  $this->cleanProductDistributors();
7659
+ if (!$this->_ignore_product_contracts) {
7660
+ $this->cleanProductContracts();
7661
+ }
7662
+ if ($this->product_file_format == "NEW") {
7663
  $this->addReviews();
7664
  $this->addWeight();
7665
  $this->addSearchCache();
7666
  $this->addPdfUrl();
7667
  $this->addShortDescriptions();
7668
  $this->addProductDistributors();
7669
+ if (!$this->_ignore_product_contracts) {
7670
+ $this->addProductContracts();
7671
+ }
7672
  }
7673
  $this->addEAN();
7674
  $this->addSpecification();
7675
+ $this->addManufacturers();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7677
 
7678
+ echo("\n replaceMagentoProductsMultistoreMERGE 21\n");
7679
 
7680
+ //Enabling product index.
7681
  $result = $this->db_do("
7682
+ DELETE cpei
7683
+ FROM $catalog_product_enabled_index cpei
7684
+ LEFT JOIN $catalog_product_entity cpe
7685
+ ON cpei.product_id = cpe.entity_id
7686
+ WHERE cpe.entity_id IS NULL");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7687
 
7688
 
7689
+ echo("\n replaceMagentoProductsMultistoreMERGE 22\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7690
 
7691
+ $result = $this->db_do("
7692
+ INSERT INTO $catalog_product_enabled_index
7693
+ (product_id, store_id, visibility)
7694
+ (SELECT
7695
+ a.entity_id,
7696
+ w.website,
7697
+ 4
7698
+ FROM $catalog_product_entity a
7699
+ JOIN $products_website_temp w
7700
+ ON a.store_product_id = w.store_product_id
7701
+ )
7702
+ ON DUPLICATE KEY UPDATE
7703
+ visibility = 4");
7704
+
7705
+ echo("\n replaceMagentoProductsMultistoreMERGE 23\n");
7706
 
 
7707
  $result = $this->db_do("
7708
+ INSERT INTO $catalog_product_enabled_index
7709
+ (product_id, store_id, visibility)
7710
+ (SELECT
7711
+ a.entity_id,
7712
+ 0,
7713
+ 4
7714
+ FROM $catalog_product_entity a
7715
+ JOIN $products_website_temp w
7716
+ ON a.store_product_id = w.store_product_id
7717
+ )
7718
+ ON DUPLICATE KEY UPDATE
7719
+ visibility = 4");
 
 
 
 
 
 
 
 
 
7720
 
7721
 
7722
+ /////////////////////////////////////echo(" .... DONE\n");return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7723
 
 
7724
 
7725
+ echo("\n replaceMagentoProductsMultistoreMERGE 24\n");
 
 
 
 
 
7726
 
7727
  $result = $this->db_do("
7728
+ INSERT INTO $catalog_product_entity_int
7729
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7730
+ (SELECT
7731
+ $_getProductEntityTypeId,
7732
+ $attr_visibility,
7733
+ w.website,
7734
+ a.entity_id,
7735
+ 4
7736
+ FROM $catalog_product_entity a
7737
+ JOIN $products_website_temp w
7738
+ ON a.store_product_id = w.store_product_id
7739
+ )
7740
+ ON DUPLICATE KEY UPDATE
7741
+ value = 4");
7742
+
7743
+ echo("\n replaceMagentoProductsMultistoreMERGE 25\n");
 
 
 
 
 
 
 
 
 
 
 
 
7744
 
7745
  $result = $this->db_do("
7746
+ INSERT INTO $catalog_product_entity_int
7747
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7748
+ (SELECT
7749
+ $_getProductEntityTypeId,
7750
+ $attr_visibility,
7751
+ 0,
7752
+ a.entity_id,
7753
+ 4
7754
+ FROM $catalog_product_entity a
7755
+ )
7756
+ ON DUPLICATE KEY UPDATE
7757
+ value = 4");
7758
+
7759
+ echo("\n replaceMagentoProductsMultistoreMERGE 26\n");
 
 
 
 
 
 
 
 
 
 
 
 
7760
 
 
 
 
 
 
7761
 
7762
  $result = $this->db_do("
7763
+ DELETE cpw
7764
+ FROM $catalog_product_website cpw
7765
+ LEFT JOIN $catalog_product_entity cpe
7766
+ ON cpw.product_id = cpe.entity_id
7767
+ WHERE cpe.entity_id IS NULL");
 
 
 
 
 
 
 
 
 
 
7768
 
7769
+ echo("\n replaceMagentoProductsMultistoreMERGE 27\n");
 
 
 
 
 
7770
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7771
 
 
7772
  $result = $this->db_do("
7773
+ INSERT INTO $catalog_product_website
7774
+ (product_id, website_id)
7775
+ (SELECT
7776
+ a.entity_id,
7777
+ w.website_id
7778
+ FROM $catalog_product_entity a
7779
+ JOIN $products_website_temp w
7780
+ ON a.store_product_id = w.store_product_id
7781
+ )
7782
+ ON DUPLICATE KEY UPDATE
7783
+ product_id = a.entity_id,
7784
+ website_id = w.website_id");
 
 
 
 
 
 
 
 
7785
 
7786
 
7787
+ //echo(" .... DONE\n");return;
7788
 
7789
 
7790
+ echo("\n replaceMagentoProductsMultistoreMERGE 28\n");
7791
+
7792
+ // temporary disabled mart@bintime.com
7793
+ //$result = $this->db_do("
7794
+ // UPDATE catalog_category_entity_int a
7795
+ // SET a.value = 0
7796
+ // WHERE a.attribute_id = 32
7797
+ //");
7798
+
7799
+
7800
+ //Adding tax class "Taxable Goods"
7801
  $result = $this->db_do("
7802
+ INSERT INTO $catalog_product_entity_int
7803
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7804
+ (SELECT
7805
+ $_getProductEntityTypeId,
7806
+ $attr_tax_class_id,
7807
+ w.website,
7808
+ a.entity_id,
7809
+ 2
7810
+ FROM $catalog_product_entity a
7811
+ JOIN $products_website_temp w
7812
+ ON a.store_product_id = w.store_product_id
7813
+ )
7814
+ ON DUPLICATE KEY UPDATE
7815
+ value = 2");
7816
+
7817
+ echo("\n replaceMagentoProductsMultistoreMERGE 29\n");
 
 
 
 
 
 
7818
 
 
7819
  $result = $this->db_do("
7820
+ INSERT INTO $catalog_product_entity_int
7821
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7822
+ (SELECT
7823
+ $_getProductEntityTypeId,
7824
+ $attr_tax_class_id,
7825
+ 0,
7826
+ a.entity_id,
7827
+ 2
7828
+ FROM $catalog_product_entity a
7829
+ )
7830
+ ON DUPLICATE KEY UPDATE
7831
+ value = 2");
7832
+
7833
+ echo("\n replaceMagentoProductsMultistoreMERGE 30\n");
 
 
 
 
 
 
7834
 
7835
+ // Load url Image
7836
+ $result = $this->db_do("
7837
+ INSERT INTO $catalog_product_entity_varchar
7838
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7839
+ (SELECT
7840
+ $_getProductEntityTypeId,
7841
+ $attr_image,
7842
+ w.store_id,
7843
+ a.entity_id,
7844
+ b.main_image_url
7845
+ FROM $catalog_product_entity a
7846
+ JOIN $core_store w
7847
+ JOIN $products_temp b
7848
+ ON a.store_product_id = b.store_product_id
7849
+ )
7850
+ ON DUPLICATE KEY UPDATE
7851
+ value = b.main_image_url");
7852
+
7853
+ echo("\n replaceMagentoProductsMultistoreMERGE 31\n");
7854
 
7855
+ // image for specific web sites
 
 
 
7856
  $result = $this->db_do("
7857
+ INSERT INTO $catalog_product_entity_varchar
7858
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7859
+ (SELECT
7860
+ $_getProductEntityTypeId,
7861
+ $attr_image,
7862
+ 0,
7863
+ a.entity_id,
7864
+ b.main_image_url
7865
+ FROM $catalog_product_entity a
7866
+ JOIN $products_temp b
7867
+ ON a.store_product_id = b.store_product_id
7868
+ )
7869
+ ON DUPLICATE KEY UPDATE
7870
+ value = b.main_image_url");
7871
+
7872
+ echo("\n replaceMagentoProductsMultistoreMERGE 32\n");
7873
+
7874
+ // small_image for specific web sites
7875
+ $result = $this->db_do("
7876
+ INSERT INTO $catalog_product_entity_varchar
7877
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7878
+ (SELECT
7879
+ $_getProductEntityTypeId,
7880
+ $attr_small_image,
7881
+ w.store_id,
7882
+ a.entity_id,
7883
+ b.medium_image_url
7884
+ FROM $catalog_product_entity a
7885
+ JOIN $core_store w
7886
+ JOIN $products_temp b
7887
+ ON a.store_product_id = b.store_product_id
7888
+ )
7889
+ ON DUPLICATE KEY UPDATE
7890
+ value = b.medium_image_url");
7891
+
7892
+ echo("\n replaceMagentoProductsMultistoreMERGE 33\n");
7893
 
7894
+ // small_image for all web sites
7895
  $result = $this->db_do("
7896
+ INSERT INTO $catalog_product_entity_varchar
7897
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7898
+ (SELECT
7899
+ $_getProductEntityTypeId,
7900
+ $attr_small_image,
7901
+ 0,
7902
+ a.entity_id,
7903
+ b.medium_image_url
7904
+ FROM $catalog_product_entity a
7905
+ JOIN $core_store w
7906
+ JOIN $products_temp b
7907
+ ON a.store_product_id = b.store_product_id
7908
+ )
7909
+ ON DUPLICATE KEY UPDATE
7910
+ value = b.medium_image_url");
7911
+
7912
+ echo("\n replaceMagentoProductsMultistoreMERGE 34\n");
 
 
 
7913
 
7914
+ // thumbnail for specific web site
7915
+ $result = $this->db_do("
7916
+ INSERT INTO $catalog_product_entity_varchar
7917
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7918
+ (SELECT
7919
+ $_getProductEntityTypeId,
7920
+ $attr_thumbnail,
7921
+ w.store_id,
7922
+ a.entity_id,
7923
+ b.thumb_image_url
7924
+ FROM $catalog_product_entity a
7925
+ JOIN $core_store w
7926
+ JOIN $products_temp b
7927
+ ON a.store_product_id = b.store_product_id
7928
+ )
7929
+ ON DUPLICATE KEY UPDATE
7930
+ value = b.thumb_image_url");
7931
+
7932
+ echo("\n replaceMagentoProductsMultistoreMERGE 35\n");
7933
+
7934
+ // thumbnail for all web sites
7935
+ $result = $this->db_do("
7936
+ INSERT INTO $catalog_product_entity_varchar
7937
+ (entity_type_id, attribute_id, store_id, entity_id, value)
7938
+ (SELECT
7939
+ $_getProductEntityTypeId,
7940
+ $attr_thumbnail,
7941
+ 0,
7942
+ a.entity_id,
7943
+ b.thumb_image_url
7944
+ FROM $catalog_product_entity a
7945
+ JOIN $core_store w
7946
+ JOIN $products_temp b
7947
+ ON a.store_product_id = b.store_product_id
7948
+ )
7949
+ ON DUPLICATE KEY UPDATE
7950
+ value = b.thumb_image_url");
7951
+
7952
+ echo("\n replaceMagentoProductsMultistoreMERGE 36\n");
7953
+
7954
+
7955
+ /* STP DELETE
7956
+ //Refresh fulltext search
7957
+ $result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
7958
+ $result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
7959
+
7960
+
7961
+ echo("\n replaceMagentoProductsMultistoreMERGE 36.2\n");
7962
+ $q = "
7963
+ INSERT INTO {$catalogsearch_fulltext}_tmp
7964
+ (product_id, store_id, data_index)
7965
+ (SELECT
7966
+ a.entity_id,
7967
+ w.website,
7968
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
7969
+ FROM $catalog_product_entity a
7970
+ JOIN $products_website_temp w
7971
+ ON a.store_product_id = w.store_product_id
7972
+ LEFT JOIN $catalog_category_product b
7973
+ ON a.entity_id = b.product_id
7974
+ LEFT JOIN $catalog_category_entity_varchar c
7975
+ ON b.category_id = c.entity_id
7976
+ AND c.attribute_id = $cat_attr_name
7977
+ LEFT JOIN $catalog_product_entity_varchar e
7978
+ ON a.entity_id = e.entity_id
7979
+ AND e.attribute_id = $attr_name
7980
+ LEFT JOIN $catalog_product_website j
7981
+ ON a.entity_id = j.product_id
7982
+ LEFT JOIN $products_temp f
7983
+ ON a.store_product_id = f.store_product_id
7984
+ )
7985
+ ON DUPLICATE KEY UPDATE
7986
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
7987
+ echo("\n\n============================\n$q\n============================\n\n");
7988
 
 
7989
 
 
 
 
7990
  $result = $this->db_do("
7991
+ INSERT INTO {$catalogsearch_fulltext}_tmp
7992
+ (product_id, store_id, data_index)
7993
+ (SELECT
7994
+ a.entity_id,
7995
+ w.website,
7996
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
7997
+ FROM $catalog_product_entity a
7998
+ JOIN $products_website_temp w
7999
+ ON a.store_product_id = w.store_product_id
8000
+ LEFT JOIN $catalog_category_product b
8001
+ ON a.entity_id = b.product_id
8002
+ LEFT JOIN $catalog_category_entity_varchar c
8003
+ ON b.category_id = c.entity_id
8004
+ AND c.attribute_id = $cat_attr_name
8005
+ LEFT JOIN $catalog_product_entity_varchar e
8006
+ ON a.entity_id = e.entity_id
8007
+ AND e.attribute_id = $attr_name
8008
+ LEFT JOIN $catalog_product_website j
8009
+ ON a.entity_id = j.product_id
8010
+ LEFT JOIN $products_temp f
8011
+ ON a.store_product_id = f.store_product_id
8012
+ )
8013
+ ON DUPLICATE KEY UPDATE
8014
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
8015
+
8016
+ echo("\n replaceMagentoProductsMultistoreMERGE 37\n");
8017
+
8018
+
8019
  $result = $this->db_do("
8020
+ INSERT INTO {$catalogsearch_fulltext}_tmp
8021
+ (product_id, store_id, data_index)
8022
+ (SELECT
8023
+ a.entity_id,
8024
+ w.website,
8025
+ CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
8026
+ FROM $catalog_product_entity a
8027
+ JOIN $products_website_temp w
8028
+ ON a.store_product_id = w.store_product_id
8029
+ LEFT JOIN $catalog_category_product b
8030
+ ON a.entity_id = b.product_id
8031
+ LEFT JOIN $catalog_category_entity_varchar c
8032
+ ON b.category_id = c.entity_id
8033
+ AND c.attribute_id = $cat_attr_name
8034
+ LEFT JOIN $catalog_product_entity_varchar e
8035
+ ON a.entity_id = e.entity_id
8036
+ AND e.attribute_id = $attr_name
8037
+ LEFT JOIN $products_temp f
8038
+ ON a.store_product_id = f.store_product_id
8039
+ )
8040
+ ON DUPLICATE KEY UPDATE
8041
+ data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
8042
+
8043
+ echo("\n replaceMagentoProductsMultistoreMERGE 38\n");
8044
+
8045
  $result = $this->db_do("
8046
+ DELETE cf
8047
+ FROM $catalogsearch_fulltext cf
8048
+ LEFT JOIN $catalog_product_entity cpe
8049
+ ON cf.product_id = cpe.entity_id
8050
+ WHERE cpe.entity_id IS NULL");
8051
+
8052
+ echo("\n replaceMagentoProductsMultistoreMERGE 39\n");
8053
+
8054
+ $result = $this->db_do("
8055
+ INSERT INTO $catalogsearch_fulltext
8056
+ (product_id, store_id, data_index)
8057
+ (SELECT
8058
+ a.product_id,
8059
+ a.store_id,
8060
+ a.data_index
8061
+ FROM {$catalogsearch_fulltext}_tmp a
8062
+ )
8063
+ ON DUPLICATE KEY UPDATE
8064
+ data_index = a.data_index");
8065
+
8066
+ echo("\n replaceMagentoProductsMultistoreMERGE 40\n");
8067
+
8068
+ $this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
8069
+ //INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
8070
+ //TODO add something else
8071
+ STP DELETE*/
8072
 
8073
+ $this->addRelatedProducts();
8074
+ echo("\n replaceMagentoProductsMultistoreMERGE 41\n");
8075
  }
8076
 
8077
  #################################################################################################
8078
+
8079
+ function ParseProductsPicturesGallery()
8080
+ {
8081
+
8082
+ $parse_file = $this->varDir . FILE_PRODUCTS_PICTURES_GALLERY;
8083
+ if (filesize($parse_file)) {
8084
+ $this->_LOG("Start parse " . FILE_PRODUCTS_PICTURES_GALLERY);
8085
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp'));
8086
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp') . " (
8087
+ sinch_product_id int(11),
8088
+ image_url varchar(255),
8089
+ thumb_image_url varchar(255),
8090
+ store_product_id int(11),
8091
+ key(sinch_product_id),
8092
+ key(store_product_id)
8093
+ )");
8094
+
8095
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
8096
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp') . "
8097
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
8098
+ OPTIONALLY ENCLOSED BY '\"'
8099
+ LINES TERMINATED BY \"\r\n\"
8100
+ IGNORE 1 LINES ");
8101
+
8102
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp') . " ppgt
8103
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products') . " sp
8104
+ ON ppgt.sinch_product_id=sp.sinch_product_id
8105
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
8106
+ ON sp.store_product_id=cpe.store_product_id
8107
+ SET ppgt.store_product_id=sp.store_product_id");
8108
+
8109
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
8110
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp') . "
8111
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
8112
+
8113
+ $this->_LOG("Finish parse" . FILE_PRODUCTS_PICTURES_GALLERY);
8114
+ } else {
8115
+ $this->_LOG("Wrong file" . $parse_file);
8116
  }
8117
+ $this->_LOG(" ");
8118
+
8119
  }
8120
  #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8121
 
8122
+ function ParseRestrictedValues()
8123
+ {
8124
 
8125
+ $parse_file = $this->varDir . FILE_RESTRICTED_VALUES;
8126
+ if (filesize($parse_file) || $this->_ignore_restricted_values) {
8127
+ $this->_LOG("Start parse " . FILE_RESTRICTED_VALUES);
8128
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('restricted_values_temp'));
8129
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('restricted_values_temp') . " (
8130
+ restricted_value_id int(11),
8131
+ category_feature_id int(11),
8132
+ text text,
8133
+ display_order_number int(11),
8134
+ KEY(restricted_value_id),
8135
+ KEY(category_feature_id)
8136
+ )");
8137
+ if (!$this->_ignore_restricted_values) {
8138
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
8139
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('restricted_values_temp') . "
8140
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
8141
+ OPTIONALLY ENCLOSED BY '\"'
8142
+ LINES TERMINATED BY \"\r\n\"
8143
+ IGNORE 1 LINES ");
8144
+ }
8145
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
8146
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('restricted_values_temp') . "
8147
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
8148
 
8149
+ $this->_LOG("Finish parse " . FILE_RESTRICTED_VALUES);
8150
+ } else {
8151
+ $this->_LOG("Wrong file " . $parse_file);
8152
  }
8153
+ $this->_LOG(" ");
8154
  }
8155
 
8156
+ #################################################################################################
8157
+
8158
+ function ParseStockAndPrices()
8159
+ {
8160
+
8161
+ $parse_file = $this->varDir . FILE_STOCK_AND_PRICES;
8162
+
8163
+ if (filesize($parse_file)) {
8164
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp_before'));
8165
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp_before') . " (
8166
+ store_product_id int(11),
8167
+ stock int(11),
8168
+ price varchar(255),
8169
+ cost varchar(255),
8170
+ distributor_id int(11),
8171
+ KEY(store_product_id),
8172
+ KEY(distributor_id)
8173
+ )");
8174
+
8175
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
8176
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp_before') . "
8177
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
8178
+ OPTIONALLY ENCLOSED BY '\"'
8179
+ LINES TERMINATED BY \"\r\n\"
8180
+ IGNORE 1 LINES ");
8181
+
8182
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp'));
8183
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " (
8184
+ store_product_id int(11),
8185
+ stock int(11),
8186
+ price decimal(15,4),
8187
+ cost decimal(15,4),
8188
+ distributor_id int(11),
8189
+ KEY(store_product_id),
8190
+ KEY(distributor_id)
8191
+ )");
8192
+
8193
+ $this->db_do("
8194
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " (
8195
+ store_product_id,
8196
+ stock,
8197
+ price,
8198
+ cost,
8199
+ distributor_id
8200
+ )(
8201
+ SELECT
8202
+ store_product_id,
8203
+ stock,
8204
+ REPLACE(price, ',', '.'),
8205
+ REPLACE(cost, ',', '.' ),
8206
+ distributor_id
8207
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp_before') . "
8208
+ )
8209
+ ");
8210
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp_before'));
8211
+
8212
+ $this->replaceMagentoProductsStockPrice();
8213
+
8214
+ $res = $this->db_do("SELECT count(*) as cnt
8215
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
8216
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " b
8217
+ ON a.store_product_id=b.store_product_id");
8218
+ $row = mysqli_fetch_assoc($res);
8219
+ $this->db_do("UPDATE " . $this->import_status_statistic_table . "
8220
+ SET number_of_products=" . $row['cnt'] . "
8221
+ WHERE id=" . $this->current_import_status_statistic_id);
8222
+
8223
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
8224
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . "
8225
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
8226
 
8227
+ $this->_LOG("Finish parse" . FILE_RELATED_PRODUCTS);
8228
+ } else {
8229
+ $this->_LOG("Wrong file" . $parse_file);
8230
+ }
8231
+ $this->_LOG(" ");
8232
+ }
8233
 
8234
  #################################################################################################
8235
+
8236
+ function replaceMagentoProductsStockPrice()
8237
+ {
8238
+ //Add stock
8239
+ $connection = Mage::getModel('core/resource')->getConnection('core_write');
8240
+ $result = $this->db_do("DELETE csi
8241
+ FROM " . Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item') . " csi
8242
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
8243
+ ON csi.product_id=cpe.entity_id
8244
+ WHERE cpe.entity_id is null");
8245
+ //set all sinch products stock=0 before upgrade (nedds for dayly stock&price import)
8246
+
8247
+ $result = $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
8248
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item') . " csi
8249
+ ON cpe.entity_id=csi.product_id
8250
+ SET
8251
+ csi.qty=0,
8252
+ csi.is_in_stock=0
8253
+ WHERE cpe.store_product_id IS NOT NULL");
8254
+
 
 
 
 
 
 
8255
  $result = $this->db_do("
8256
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item') . " (
8257
+ product_id,
8258
+ stock_id,
8259
+ qty,
8260
+ is_in_stock,
8261
+ manage_stock
8262
  )(
8263
  SELECT
 
 
 
8264
  a.entity_id,
8265
+ 1,
8266
+ b.stock,
8267
+ IF(b.stock > 0, 1, 0),
8268
+ 1
8269
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
8270
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " b
8271
+ ON a.store_product_id=b.store_product_id
8272
  )
8273
  ON DUPLICATE KEY UPDATE
8274
+ qty=b.stock,
8275
+ is_in_stock = IF(b.stock > 0, 1, 0),
8276
+ manage_stock = 1
8277
+ ");
8278
+
8279
+
8280
+ $result = $this->db_do("DELETE FROM " . Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status'));
8281
+
8282
+ $result = $this->db_do("
8283
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status') . " (
8284
+ product_id,
8285
+ website_id,
8286
+ stock_id,
8287
+ qty,
8288
+ stock_status
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8289
  )(
8290
  SELECT
8291
+ a.product_id,
8292
+ w.website_id,
8293
+ 1,
8294
+ a.qty,
8295
+ IF(qty > 0, 1, 0)
8296
+ FROM " . Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item') . " a
8297
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " b
8298
+ ON a.product_id=b.entity_id
8299
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
8300
+ ON b.store_product_id=w.store_product_id
8301
  )
8302
  ON DUPLICATE KEY UPDATE
8303
+ qty=a.qty,
8304
+ stock_status = IF(a.qty > 0, 1, 0)
8305
+ ");
8306
+
8307
+ //Add prices
8308
+ //$result = $this->db_do("truncate catalog_product_entity_decimal");
8309
+ $result = $this->db_do("DELETE cped
8310
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal') . " cped
8311
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
8312
+ ON cped.entity_id=cpe.entity_id
8313
+ WHERE cpe.entity_id IS NULL");
8314
 
 
8315
  $result = $this->db_do("
8316
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal') . " (
8317
  entity_type_id,
8318
  attribute_id,
8319
  store_id,
8321
  value
8322
  )(
8323
  SELECT
8324
+ " . $this->_getProductEntityTypeId() . ",
8325
+ " . $this->_getProductAttributeId('price') . ",
8326
+ w.website,
8327
  a.entity_id,
8328
+ b.price
8329
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
8330
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " b
8331
+ ON a.store_product_id=b.store_product_id
8332
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
8333
  ON a.store_product_id=w.store_product_id
8334
  )
8335
  ON DUPLICATE KEY UPDATE
8336
+ value = b.price
8337
  ");
8338
 
 
 
 
 
 
8339
  $result = $this->db_do("
8340
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal') . " (
8341
  entity_type_id,
8342
  attribute_id,
8343
  store_id,
8345
  value
8346
  )(
8347
  SELECT
8348
+ " . $this->_getProductEntityTypeId() . ",
8349
+ " . $this->_getProductAttributeId('price') . ",
8350
+ 0,
8351
  a.entity_id,
8352
+ b.price
8353
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
8354
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " b
8355
+ ON a.store_product_id=b.store_product_id
 
 
8356
  )
8357
  ON DUPLICATE KEY UPDATE
8358
+ value = b.price
8359
  ");
8360
+ //Add cost
8361
+ // $result = $this->db_do("truncate catalog_product_entity_decimal");
8362
  $result = $this->db_do("
8363
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal') . " (
8364
  entity_type_id,
8365
  attribute_id,
8366
  store_id,
8368
  value
8369
  )(
8370
  SELECT
8371
+ " . $this->_getProductEntityTypeId() . ",
8372
+ " . $this->_getProductAttributeId('cost') . ",
8373
+ w.website,
8374
  a.entity_id,
8375
+ b.cost
8376
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
8377
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " b
8378
+ ON a.store_product_id=b.store_product_id
8379
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
8380
+ ON a.store_product_id=w.store_product_id
8381
  )
8382
  ON DUPLICATE KEY UPDATE
8383
+ value = b.cost
8384
  ");
8385
 
 
 
 
 
8386
  $result = $this->db_do("
8387
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal') . " (
8388
  entity_type_id,
8389
  attribute_id,
8390
  store_id,
8392
  value
8393
  )(
8394
  SELECT
8395
+ " . $this->_getProductEntityTypeId() . ",
8396
+ " . $this->_getProductAttributeId('cost') . ",
8397
  0,
8398
  a.entity_id,
8399
+ b.cost
8400
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
8401
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " b
8402
+ ON a.store_product_id=b.store_product_id
8403
  )
8404
  ON DUPLICATE KEY UPDATE
8405
+ value = b.cost
8406
  ");
8407
 
8408
+ //make products enable in FO
8409
+ // $result = $this->db_do(" truncate catalog_product_index_price");
8410
+ $result = $this->db_do("DELETE cpip
8411
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price') . " cpip
8412
+ LEFT JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
8413
+ ON cpip.entity_id=cpe.entity_id
8414
+ WHERE cpe.entity_id IS NULL");
8415
+
8416
+ $q = "SELECT customer_group_id FROM " . Mage::getSingleton('core/resource')->getTableName('customer_group');
8417
+ $quer = $this->db_do($q);
8418
 
8419
+ while ($row = mysqli_fetch_assoc($quer)) {
8420
+ $result = $this->db_do("
8421
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price') . " (
8422
+ entity_id,
8423
+ customer_group_id,
8424
+ website_id,
8425
+ tax_class_id,
8426
+ price,
8427
+ final_price,
8428
+ min_price,
8429
+ max_price
8430
+ )(SELECT
8431
+ a.entity_id,
8432
+ " . $row['customer_group_id'] . ",
8433
+ w.website_id,
8434
+ 2,
8435
+ b.price ,
8436
+ b.price ,
8437
+ b.price ,
8438
+ b.price
8439
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
8440
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp') . " b
8441
+ ON a.store_product_id=b.store_product_id
8442
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('products_website_temp') . " w
8443
+ ON a.store_product_id=w.store_product_id
8444
+ )
8445
+ ON DUPLICATE KEY UPDATE
8446
+ tax_class_id = 2,
8447
+ price = b.price,
8448
+ final_price = b.price,
8449
+ min_price = b.price,
8450
+ max_price = b.price
8451
+ ");
8452
+ }
8453
  }
8454
 
8455
  #################################################################################################
8456
+
8457
+ private function _cleanCateoryProductFlatTable()
8458
+ {
8459
+ $dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
8460
+ $q = 'SHOW TABLES LIKE "' . Mage::getSingleton('core/resource')->getTableName('catalog_product_flat_') . '%"';
8461
+ $quer = $this->db_do($q);
8462
+ $result = false;
8463
+ While ($row = mysqli_fetch_array($quer)) {
8464
+ if (is_array($row)) {
8465
+ $catalog_product_flat = array_pop($row);
8466
+ $q = 'DELETE pf1 FROM ' . $catalog_product_flat . ' pf1
8467
+ LEFT JOIN ' . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . ' p
8468
+ ON pf1.entity_id = p.entity_id
8469
+ WHERE p.entity_id IS NULL;';
8470
+ $this->db_do($q);
8471
+ $this->_LOG('cleaned wrong rows from ' . $catalog_product_flat);
8472
+ }
8473
  }
8474
+ return $result;
 
 
8475
 
8476
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8477
 
8478
+ #################################################################################################
8479
+
8480
+ public function runIndexer()
8481
+ {
8482
+ $this->db_do("DELETE FROM " . Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'));
8483
+ $this->db_do("SET FOREIGN_KEY_CHECKS=0");
8484
+ $this->db_do("TRUNCATE TABLE " . Mage::getSingleton('core/resource')->getTableName('core_url_rewrite'));
8485
+ $this->db_do("SET FOREIGN_KEY_CHECKS=1");
8486
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . "
8487
+ SET value = ''
8488
+ WHERE entity_type_id=" . $this->_getProductEntityTypeId() . " AND attribute_id=" . $this->_getProductAttributeId('url_key'));
8489
+ exec(PHP_RUN_STRING . ' ' . $this->shellDir . 'indexer.php reindexall');
8490
+ }
 
 
 
 
 
 
 
 
 
 
 
8491
 
8492
+ #################################################################################################
8493
 
8494
+ function cron_start_full_import()
8495
+ {
8496
+ $this->import_run_type = 'CRON';
8497
+ $this->run_sinch_import();
8498
  }
8499
 
8500
  #################################################################################################
 
8501
 
8502
+ function cron_start_stock_price_import()
8503
+ {
8504
+ $this->import_run_type = 'CRON';
8505
+ $this->run_stock_price_sinch_import();
8506
+ }
 
8507
 
8508
+ ##################################################################################################
 
 
 
 
 
8509
 
8510
+ function run_stock_price_sinch_import()
8511
+ {
8512
+ $safe_mode_set = ini_get('safe_mode');
8513
+
8514
+ $this->InitImportStatuses('PRICE STOCK');
8515
+ if ($safe_mode_set) {
8516
+ $this->_LOG('safe_mode is enable. import stoped.');
8517
+ $this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
8518
+ exit;
8519
  }
8520
+ $store_proc = $this->check_store_procedure_exist();
8521
 
8522
+ if (!$store_proc) {
8523
+ $this->_LOG('store prcedure "' . Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s') . '" is absent in this database. import stoped.');
8524
+ $this->set_import_error_reporting_message('Stored procedure "' . Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s') . '" is absent in this database. Import stopped.');
8525
+ exit;
8526
+ }
8527
+
8528
+ $file_privileg = $this->check_db_privileges();
8529
+
8530
+ if (!$file_privileg) {
8531
+ $this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
8532
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
8533
+ exit;
8534
+ }
8535
+ $local_infile = $this->check_local_infile();
8536
+ if (!$local_infile) {
8537
+ $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'");
8538
+ $this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
8539
+ exit;
8540
+ }
8541
+
8542
+ if ($this->is_imort_not_run() && $this->is_full_import_have_been_run()) {
8543
+ try {
8544
+ //$this->InitImportStatuses();
8545
+ $q = "SELECT GET_LOCK('sinchimport', 30)";
8546
+ $quer = $this->db_do($q);
8547
+ $import = $this;
8548
+ $import->addImportStatus('Stock Price Start Import');
8549
+ echo "Upload Files <br>";
8550
+ $this->files = array(
8551
+ FILE_STOCK_AND_PRICES,
8552
+ FILE_PRICE_RULES
8553
+ );
8554
+
8555
+ $import->UploadFiles();
8556
+ $import->addImportStatus('Stock Price Upload Files');
8557
+
8558
+ echo "Parse Stock And Prices <br>";
8559
+ //exit;
8560
+ $import->ParseStockAndPrices();
8561
+ $import->addImportStatus('Stock Price Parse Products');
8562
+
8563
+ echo "Apply Customer Group Price <br>";
8564
+ //$import->ParsePriceRules();
8565
+ //$import->AddPriceRules();
8566
+ //$import->ApplyCustomerGroupPrice();
8567
+
8568
+ $ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
8569
+ Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
8570
+ 'ftp_host' => $ftpCred["ftp_server"],
8571
+ 'ftp_username' => $ftpCred["login"],
8572
+ 'ftp_password' => $ftpCred["password"]
8573
+ ));
8574
+
8575
+
8576
+ Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
8577
+ echo "Finish Stock & Price Sinch import<br>";
8578
+
8579
+ Mage::log("Start indexing Stock & Price", null, $this->_logFile);
8580
+ echo "Start indexing Stock & Price<br>";
8581
+ $import->_cleanCateoryProductFlatTable();
8582
+ $import->runStockPriceIndexer();
8583
+ Mage::log("Finish indexing Stock & Price", null, $this->_logFile);
8584
+ $import->addImportStatus('Stock Price Indexing data');
8585
+ $import->addImportStatus('Stock Price Finish import', 1);
8586
+ echo "Finish indexing Stock & Price<br>";
8587
+
8588
+ $q = "SELECT RELEASE_LOCK('sinchimport')";
8589
+ $quer = $this->db_do($q);
8590
+ } catch (Exception $e) {
8591
+ $this->set_import_error_reporting_message($e);
8592
+ }
8593
+ } else {
8594
+ if (!$this->is_imort_not_run()) {
8595
+ Mage::log("Sinchimport already run", null, $this->_logFile);
8596
+ echo "Sinchimport already run<br>";
8597
+ } else {
8598
+ Mage::log("Full import have never finished with success", null, $this->_logFile);
8599
+ echo "Full import have never finished with success<br>";
8600
+ }
8601
+ }
8602
+
8603
+ }
8604
+
8605
+ ##################################################################################################
8606
+
8607
+ function is_full_import_have_been_run()
8608
+ {
8609
+ $q = "SELECT COUNT(*) AS cnt
8610
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic') . "
8611
+ WHERE import_type='FULL' AND global_status_import='Successful'";
8612
+ $quer = $this->db_do($q);
8613
+ $row = mysqli_fetch_array($quer);
8614
+ if ($row['cnt'] > 0) {
8615
+ return true;
8616
+ } else {
8617
+ return false;
8618
+ }
8619
+ }
8620
+
8621
+ ##################################################################################################
8622
 
8623
+ public function runStockPriceIndexer()
8624
+ {
8625
+ exec(PHP_RUN_STRING . ' ' . $this->shellDir . 'indexer.php --reindex catalog_product_price,cataloginventory_stock');
8626
+ }
 
 
 
 
 
8627
 
8628
+ ##################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
8629
 
8630
+ function ParsePriceRules()
8631
+ {
8632
+ $parse_file = $this->varDir . FILE_PRICE_RULES;
8633
+ if (filesize($parse_file) || $this->_ignore_price_rules) {
8634
+ $this->_LOG("Start parse " . FILE_PRICE_RULES);
 
8635
 
8636
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp'));
8637
+ $this->db_do("CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . "(
8638
+ `id` int(11) NOT NULL,
8639
+ `price_from` decimal(10,2) DEFAULT NULL,
8640
+ `price_to` decimal(10,2) DEFAULT NULL,
8641
+ `category_id` int(10) unsigned DEFAULT NULL,
8642
+ `vendor_id` int(11) DEFAULT NULL,
8643
+ `vendor_product_id` varchar(255) DEFAULT NULL,
8644
+ `customergroup_id` varchar(32) DEFAULT NULL,
8645
+ `marge` decimal(10,2) DEFAULT NULL,
8646
+ `fixed` decimal(10,2) DEFAULT NULL,
8647
+ `final_price` decimal(10,2) DEFAULT NULL,
8648
+ PRIMARY KEY (`id`),
8649
+ UNIQUE KEY `price_from` (`price_from`,`price_to`,`vendor_id`,`category_id`,`vendor_product_id`,`customergroup_id`),
8650
+ KEY `vendor_product_id` (`vendor_product_id`),
8651
+ KEY `category_id` (`category_id`)
8652
+ )
8653
+ ");
8654
+ if (!$this->_ignore_price_rules) {
8655
 
8656
+ $this->db_do("LOAD DATA LOCAL INFILE '" . $parse_file . "'
8657
+ INTO TABLE " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . "
8658
+ FIELDS TERMINATED BY '" . $this->field_terminated_char . "'
8659
+ OPTIONALLY ENCLOSED BY '\"'
8660
+ LINES TERMINATED BY \"\r\n\"
8661
+ IGNORE 1 LINES
8662
+ (id, @vprice_from, @vprice_to, @vcategory_id, @vvendor_id, @vvendor_product_id, @vcustomergroup_id, @vmarge, @vfixed, @vfinal_price)
8663
+ SET price_from = nullif(@vprice_from,''),
8664
+ price_to = nullif(@vprice_to,''),
8665
+ category_id = nullif(@vcategory_id,''),
8666
+ vendor_id = nullif(@vvendor_id,''),
8667
+ vendor_product_id = nullif(@vvendor_product_id,''),
8668
+ customergroup_id = nullif(@vcustomergroup_id,''),
8669
+ marge = nullif(@vmarge,''),
8670
+ fixed = nullif(@vfixed,''),
8671
+ final_price = nullif(@vfinal_price,'')
8672
+ ");
8673
+ }
8674
 
8675
+ $this->db_do("ALTER TABLE " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . "
8676
+ ADD COLUMN `shop_category_id` int(10) unsigned DEFAULT NULL,
8677
+ ADD COLUMN `shop_vendor_id` int(11) DEFAULT NULL,
8678
+ ADD COLUMN `shop_vendor_product_id` varchar(255) DEFAULT NULL,
8679
+ ADD COLUMN `shop_customergroup_id` varchar(32) DEFAULT NULL
8680
+ ");
 
8681
 
8682
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . " prt
8683
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . " cce
8684
+ ON prt.category_id = cce.store_category_id
8685
+ SET prt.shop_category_id = cce.entity_id");
 
 
 
 
 
 
 
 
 
 
8686
 
8687
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . " prt
8688
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers') . " sicm
8689
+ ON prt.vendor_id = sicm.sinch_manufacturer_id
8690
+ SET prt.shop_vendor_id = sicm.shop_option_id");
8691
 
8692
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . " prt
8693
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping') . " sicpm
8694
+ ON prt.vendor_product_id = sicpm.product_sku
8695
+ SET prt.shop_vendor_product_id = sicpm.sku");
8696
+
8697
+ $this->db_do("UPDATE " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . " prt
8698
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('customer_group') . " cg
8699
+ ON prt.customergroup_id = cg.customer_group_id
8700
+ SET prt.shop_customergroup_id = cg.customer_group_id");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8701
 
8702
+ $this->db_do("DELETE FROM " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . "
8703
+ WHERE
8704
+ (category_id IS NOT NULL AND shop_category_id IS NULL) OR
8705
+ (vendor_id IS NOT NULL AND shop_vendor_id IS NULL) OR
8706
+ (vendor_product_id IS NOT NULL AND shop_vendor_product_id IS NULL) OR
8707
+ (customergroup_id IS NOT NULL AND shop_customergroup_id IS NULL)
8708
+ ");
8709
 
 
8710
 
8711
+ $this->db_do("DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_price_rules'));
8712
+ $this->db_do("RENAME TABLE " . Mage::getSingleton('core/resource')->getTableName('price_rules_temp') . "
8713
+ TO " . Mage::getSingleton('core/resource')->getTableName('stINch_price_rules'));
8714
 
8715
+ $this->_LOG("Finish parse " . FILE_PRICE_RULES);
8716
+ } else {
8717
+ $this->_LOG("Wrong file " . $parse_file);
8718
+ }
8719
+ $this->_LOG(" ");
8720
  }
8721
+
8722
  #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8723
 
8724
+ function AddPriceRules()
8725
+ {
8726
+ if (!$this->check_table_exist('import_pricerules_standards')) {
8727
+ return;
8728
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8729
 
8730
  $result = $this->db_do("
8731
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('import_pricerules') . " (
8732
+ id,
8733
+ price_from,
8734
+ price_to,
8735
+ vendor_id,
8736
+ category_id,
8737
+ vendor_product_id,
8738
+ customergroup_id,
8739
+ marge,
8740
+ fixed,
8741
+ final_price
8742
+ )(SELECT
8743
+ id,
8744
+ price_from,
8745
+ price_to,
8746
+ shop_vendor_id,
8747
+ shop_category_id,
8748
+ shop_vendor_product_id,
8749
+ shop_customergroup_id,
8750
+ marge,
8751
+ fixed,
8752
+ final_price
8753
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_price_rules') . " a
8754
+ )
8755
+ ON DUPLICATE KEY UPDATE
8756
+ id = a.id,
8757
+ price_from = a.price_from,
8758
+ price_to = a.price_to,
8759
+ vendor_id = a.shop_vendor_id,
8760
+ category_id = a.shop_category_id,
8761
+ vendor_product_id = a.shop_vendor_product_id,
8762
+ customergroup_id = a.shop_customergroup_id,
8763
+ marge = a.marge,
8764
+ fixed = a.fixed,
8765
+ final_price = a.final_price
8766
+ ");
8767
+
8768
+ }
8769
 
8770
+ #################################################################################################
8771
 
8772
+ private function check_table_exist($table)
8773
+ {
8774
 
8775
+ $q = "SHOW TABLES LIKE \"%" . Mage::getSingleton('core/resource')->getTableName($table) . "%\"";
8776
+ // echo $q;
8777
+ $quer = $this->db_do($q);
8778
+ $i = 0;
8779
+ while ($row = mysqli_fetch_array($quer)) {
8780
+ $i++;
8781
+ }
8782
+ return ($i);
8783
  }
8784
+
8785
  #################################################################################################
8786
+
8787
+ function ApplyCustomerGroupPrice()
8788
+ {
8789
+ if (!$this->check_table_exist('import_pricerules_standards')) {
8790
  return;
8791
  }
8792
  $this->_getProductsForCustomerGroupPrice();
8793
  $pricerulesArray = $this->_getPricerulesList();
8794
+ if (is_array($pricerulesArray)) {
8795
+ $this->db_do("TRUNCATE TABLE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_group_price'));
8796
+ $this->db_do("TRUNCATE TABLE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_index_group_price'));
8797
 
8798
  }
8799
  // $i=1;
8800
+ foreach ($pricerulesArray as $pricerule) {
8801
+ $this->_LOG("Calculation group price for rule " . $pricerule['id'] . "
8802
+ (\nname = " . $pricerule['name'] . "
8803
+ \nfinal_price = " . $pricerule['final_price'] . "
8804
+ \nprice_from = " . $pricerule['price_from'] . "
8805
+ \nprice_to = " . $pricerule['price_to'] . "
8806
+ \nvendor_id = " . $pricerule['vendor_id'] . "
8807
+ \ncategory_id = " . $pricerule['category_id'] . "
8808
+ \nproduct_entity_id = " . $pricerule['product_entity_id'] . "
8809
+ \nvendor_product_id = " . $pricerule['vendor_product_id'] . "
8810
+ \ncustomergroup_id = " . $pricerule['customergroup_id'] . "
8811
+ \ndistributor_id = " . $pricerule['distributor_id'] . "
8812
+ \nrating = " . $pricerule['rating'] . "
8813
+ \nmarge = " . $pricerule['marge'] . "
8814
+ \nfixed = " . $pricerule['fixed'] . "
8815
+ \nallow_subcat = " . $pricerule['allow_subcat'] . "
8816
+ \nstore_id = " . $pricerule['store_id'] . "
8817
  )");
8818
 
8819
+ $vendor_product_id_str = "'" . str_replace(';', "','", $pricerule['vendor_product_id']) . "'";
8820
  $where = "";
8821
  if (empty($pricerule['marge'])) $marge = "NULL";
8822
  else $marge = $pricerule['marge'];
8827
  if (empty($pricerule['final_price'])) $final_price = "NULL";
8828
  else $final_price = $pricerule['final_price'];
8829
 
8830
+ if (!empty($pricerule['price_from'])) $where .= " AND a.price > " . $pricerule['price_from'];
8831
 
8832
+ if (!empty($pricerule['price_to'])) $where .= " AND a.price < " . $pricerule['price_to'];
8833
 
8834
+ if (!empty($pricerule['vendor_id'])) $where .= " AND a.manufacturer_id = " . $pricerule['vendor_id'];
8835
 
8836
  //if(!empty($pricerule['vendor_product_id']))
8837
  // $where.= " AND vendor_product_id = ".$pricerule['vendor_product_id'];
8838
+ if (!empty($pricerule['product_entity_id'])) $where .= " AND a.product_id = '" . $pricerule['product_entity_id'] . "'";
8839
 
8840
  // if (!empty($pricerule['vendor_product_id'])) $where.= " AND a.sku = '".$pricerule['vendor_product_id']."'";
8841
+ if (!empty($pricerule['vendor_product_id'])) $where .= " AND a.sku IN (" . $vendor_product_id_str . ")";
8842
 
8843
+ if (!empty($pricerule['allow_subcat'])) {
8844
+ if (!empty($pricerule['category_id'])) {
8845
+ $children_cat = $this->get_all_children_cat($pricerule['category_id']);
8846
+ $where .= " AND a.category_id IN (" . $children_cat . ")";
8847
  }
8848
+ } else {
8849
+ if (!empty($pricerule['category_id'])) $where .= " AND a.category_id = " . $pricerule['category_id'];
8850
  }
8851
 
8852
+
8853
  // if (!empty($pricerule['store_id'])) $where.= " AND store_id = ".$pricerule['store_id'];
8854
 
8855
  // if (!empty($pricerule['distributor_id'])) $where.= " AND distributor_id = ".$pricerule['distributor_id'];
8856
 
8857
+ // $this->createCalcPriceFunc();
8858
+ //echo "\n\nAAAAAAAAAAAAAAAAAAAAa".$pricerule['customergroup_id']."----------";
8859
  $customer_group_id_array = array();
8860
+ if (strstr($pricerule['customergroup_id'], ",")) {
8861
  //echo "55555555555555555";
8862
+ $customer_group_id_array = explode(",", $pricerule['customergroup_id']);
8863
+ } else {
8864
+ $customer_group_id_array[0] = $pricerule['customergroup_id'];
8865
+ }
8866
  // var_dump($pricerule);
8867
  // echo "CCCCCCC\n";
8868
  // var_dump($customer_group_id_array);
8869
+ foreach ($customer_group_id_array as $customer_group_id) {
8870
+ if (isset($customer_group_id) && $customer_group_id >= 0) {
8871
+ $query = "
8872
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_group_price') . " (entity_id,
8873
  all_groups,
8874
  customer_group_id,
8875
  value,
8876
  website_id
8877
  )
8878
+ (SELECT
8879
  a.product_id,
8880
  0,
8881
+ " . $customer_group_id . ",
8882
+ " . Mage::getSingleton('core/resource')->getTableName('func_calc_price') . "(
8883
  a.price,
8884
+ " . $marge . " ,
8885
+ " . $fixed . ",
8886
+ " . $final_price . "),
8887
  0
8888
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp') . " a
8889
+ WHERE true " . $where . "
8890
  )
8891
  ON DUPLICATE KEY UPDATE
8892
+ value =
8893
+ " . Mage::getSingleton('core/resource')->getTableName('func_calc_price') . "(
8894
  a.price,
8895
+ " . $marge . " ,
8896
+ " . $fixed . ",
8897
+ " . $final_price . ")
8898
  ";
8899
  // echo "\n\n".$query;
8900
+ $this->db_do($query);
8901
+ if (!empty($pricerule['store_id']) && $pricerule['store_id'] > 0) {
8902
+ $query = "
8903
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_index_group_price') . " (entity_id,
8904
  customer_group_id,
8905
  price,
8906
  website_id
8907
  )
8908
+ (SELECT
8909
  a.product_id,
8910
+ " . $customer_group_id . ",
8911
+ " . Mage::getSingleton('core/resource')->getTableName('func_calc_price') . "(
8912
  a.price,
8913
+ " . $marge . " ,
8914
+ " . $fixed . ",
8915
+ " . $final_price . "),
8916
+ " . $pricerule['store_id'] . "
8917
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp') . " a
8918
+ WHERE true " . $where . "
8919
  )
8920
+ ON DUPLICATE KEY UPDATE
8921
+ price =
8922
+ " . Mage::getSingleton('core/resource')->getTableName('func_calc_price') . "(
8923
+ a.price,
8924
+ " . $marge . " ,
8925
+ " . $fixed . ",
8926
+ " . $final_price . ")
8927
+ ";
8928
+ // echo "\n\n".$query;
8929
+ $this->db_do($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8930
 
8931
+ }
8932
+ }
8933
+ }
8934
+ }
8935
 
8936
+ }
8937
 
8938
+ #################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8939
 
8940
+ function _getProductsForCustomerGroupPrice()
8941
+ {
8942
+ // TEMPORARY
8943
+ $this->db_do(" DROP TABLE IF EXISTS " . Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp'));
8944
+ $this->db_do("
8945
+ CREATE TABLE " . Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp') . "
8946
+ (
8947
+ `category_id` int(10) unsigned NOT NULL default '0',
8948
+ `product_id` int(10) unsigned NOT NULL default '0',
8949
+ `store_product_id` int(10) NOT NULL default '0',
8950
+ `sku` varchar(64) DEFAULT NULL COMMENT 'SKU',
8951
+ `manufacturer_id` int(10) NOT NULL default '0',
8952
+ `price` decimal(15,4) DEFAULT NULL,
8953
+ UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`product_id`,`category_id`),
8954
+ KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
8955
+ KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`)
8956
+ )");
8957
 
8958
  $result = $this->db_do("
8959
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp') . "
8960
+ (category_id, product_id, store_product_id, sku)
8961
+ (SELECT
8962
+ ccp.category_id,
8963
+ ccp.product_id,
8964
+ cpe.store_product_id,
8965
+ cpe.sku
8966
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_product') . " ccp
8967
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " cpe
8968
+ ON ccp.product_id = cpe.entity_id
8969
+ WHERE cpe.store_product_id IS NOT NULL)");
 
 
 
 
 
 
 
 
 
 
 
8970
 
8971
  $result = $this->db_do("
8972
+ UPDATE " . Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp') . " pfcgpt
8973
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int') . " cpei
8974
+ ON pfcgpt.product_id = cpei.entity_id
8975
+ AND cpei.entity_type_id = " . $this->_getProductEntityTypeId() . "
8976
+ AND cpei.attribute_id = " . $this->_getProductAttributeId('manufacturer') . "
8977
+ SET pfcgpt.manufacturer_id = cpei.value
8978
+ ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8979
 
8980
  $result = $this->db_do("
8981
+ UPDATE " . Mage::getSingleton('core/resource')->getTableName('stINch_products_for_customer_group_price_temp') . " pfcgpt
8982
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal') . " cped
8983
+ ON pfcgpt.product_id = cped.entity_id
8984
+ AND cped.entity_type_id = " . $this->_getProductEntityTypeId() . "
8985
+ AND cped.attribute_id = " . $this->_getProductAttributeId('price') . "
8986
+ SET pfcgpt.price = cped.value
8987
+ ");
 
 
 
 
 
 
 
 
 
 
 
 
 
8988
 
 
 
 
 
 
 
 
8989
 
8990
+ }
8991
+ #################################################################################################
8992
 
8993
+ protected function _getPricerulesList()
8994
+ {
8995
+ $rulesArray = array();
8996
+ $result = $this->db_do("
8997
+ SELECT *
8998
+ FROM " . Mage::getSingleton('core/resource')->getTableName('import_pricerules') . "
8999
+ ORDER BY rating DESC
9000
+ ");
9001
+ while ($row = mysqli_fetch_assoc($result)) {
9002
+ $rulesArray[$row['id']] = $row;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9003
  }
9004
+ return $rulesArray;
9005
+ }
9006
+
9007
+ #################################################################################################
9008
+
9009
+ private function get_all_children_cat($entity_id)
9010
+ {
9011
+ $children_cat = "'" . $entity_id . "'" . $this->get_all_children_cat_recursive($entity_id);
9012
+ return ($children_cat);
9013
  }
9014
 
9015
+ #################################################################################################
9016
 
9017
+ private function get_all_children_cat_recursive($entity_id)
9018
+ {
9019
+ $q = "SELECT entity_id
9020
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_category_entity') . "
9021
+ WHERE parent_id=" . $entity_id;
9022
+ $quer = $this->db_do($q);
9023
+ $children_cat = '';
9024
+ while ($row = mysqli_fetch_array($quer)) {
9025
+ $children_cat .= ", '" . $row['entity_id'] . "'";
9026
+ $children_cat .= $this->get_all_children_cat_recursive($row['entity_id']);
9027
+ }
9028
+ return ($children_cat);
9029
+ }
9030
 
9031
  #################################################################################################
9032
 
9033
+ function getProductDescription($entity_id)
9034
+ {
9035
 
9036
  $this->loadProductParams($entity_id);
9037
  $this->loadProductStarfeatures($entity_id);
9040
  $this->loadRelatedProducts($entity_id);
9041
  Varien_Profiler::stop('Bintime FILE RELATED');
9042
 
9043
+ return true;
9044
+ }
9045
+
9046
+ #################################################################################################
9047
+
9048
+ private function loadProductParams($entity_id)
9049
+ {
9050
+ $store_product_id = $this->getStoreProductIdByEntity($entity_id);
9051
+ if (!$store_product_id) {
9052
+ // echo "AAAAAAA"; exit;
9053
+ return;
9054
+ }
9055
+ $q = "SELECT
9056
+ sinch_product_id,
9057
+ product_sku,
9058
+ product_name,
9059
+ sinch_manufacturer_id,
9060
+ store_category_id,
9061
+ main_image_url,
9062
+ thumb_image_url,
9063
+ medium_image_url,
9064
+ specifications,
9065
+ description,
9066
+ specifications
9067
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_products') . "
9068
+ WHERE store_product_id =" . $store_product_id;
9069
+ $quer = $this->db_do($q);
9070
+ $product = mysqli_fetch_array($quer);
9071
+
9072
+ $this->productDescription = (string)substr($product['description'], 50, 0);
9073
+ $this->fullProductDescription = (string)$product['description'];
9074
+ $this->lowPicUrl = (string)$product["medium_image_url"];//thumb_image_url"];
9075
+ $this->highPicUrl = (string)$product["main_image_url"];
9076
+ $this->productName = (string)$product["product_name"];
9077
+ $this->productId = (string)$product['product_sku'];
9078
+ $this->specifications = (string)$product['specifications'];
9079
+ $this->sinchProductId = (string)$product['sinch_product_id'];
9080
+ if ($product['sinch_manufacturer_id']) {
9081
+ $q = "SELECT manufacturer_name
9082
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers') . "
9083
+ WHERE sinch_manufacturer_id=" . $product['sinch_manufacturer_id'];
9084
+ $quer = $this->db_do($q);
9085
+ $manufacturer = mysqli_fetch_array($quer);
9086
+ $this->vendor = (string)$manufacturer['manufacturer_name'];
9087
+ }
9088
+ $q = "SELECT DISTINCT ean_code
9089
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes') . " sec
9090
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products') . " sp
9091
+ ON sec.product_id=sp.sinch_product_id
9092
+ WHERE sp.store_product_id=" . $store_product_id;
9093
+ $quer = $this->db_do($q);
9094
+ while ($row = mysqli_fetch_array($quer)) {
9095
+ $EANarr[] = $row['ean_code'];
9096
+ }
9097
+ // $prodEAN = $productTag->EANCode;
9098
+ $EANstr = '';
9099
+ /* $EANarr=null;
9100
+ foreach($prodEAN as $ellEAN){
9101
+ $EANarr[]=$ellEAN['EAN'];
9102
+ }
9103
+ */
9104
+ $EANstr = implode(", ", $EANarr);
9105
+ $this->EAN = (string)$EANstr;//$productTag->EANCode['EAN'];
9106
+ }
9107
+
9108
+ #################################################################################################
9109
+
9110
+ private function getStoreProductIdByEntity($entity_id)
9111
+ {
9112
+ $q = $this->db_do("SELECT store_product_id
9113
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping') . "
9114
+ WHERE entity_id=" . $entity_id);
9115
+ $res = mysqli_fetch_array($q);
9116
+ // echo $entity_id."AAAA".$res['store_product_id']; exit;
9117
+ return ($res['store_product_id']);
9118
+ }
9119
+
9120
+ #################################################################################################
9121
+
9122
+ private function loadProductStarfeatures($entity_id)
9123
+ {
9124
+ $descriptionArray = array();
9125
+ $product_info_features = $this->db_do("
9126
+ SELECT c.feature_name AS name, b.text AS value
9127
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_product_features') . " a
9128
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values') . " b
9129
+ ON a.restricted_value_id = b.restricted_value_id
9130
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_categories_features') . " c
9131
+ ON b.category_feature_id = c.category_feature_id
9132
+ WHERE a.sinch_product_id = '" . $this->sinchProductId . "'");
9133
+ while ($features = mysqli_fetch_array($product_info_features)) {
9134
+ $descriptionArray[$features['name']] = $features['value'];
9135
+ }
9136
+
9137
+
9138
+ $this->productDescriptionList = $descriptionArray;
9139
+ }
9140
+
9141
+ #################################################################################################
9142
+
9143
+ /**
9144
+ * load Gallery array from XML
9145
+ */
9146
+ public function loadGalleryPhotos($entity_id)
9147
+ {
9148
+ /*$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
9149
+ if (!count($galleryPhotos)){
9150
+ return false;
9151
+ }
9152
+ */
9153
+ $store_product_id = $this->getStoreProductIdByEntity($entity_id);
9154
+ if (!$store_product_id) {
9155
+ return;
9156
+ }
9157
+ $q = $this->db_do("SELECT COUNT(*) AS cnt
9158
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery') . "
9159
+ WHERE store_product_id=" . $store_product_id);
9160
+
9161
+ $res = mysqli_fetch_array($q);
9162
+ if (!$res || !$res['cnt']) {
9163
+ return false;
9164
+ }
9165
+ $q = "SELECT
9166
+ image_url as Pic,
9167
+ thumb_image_url as ThumbPic
9168
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery') . "
9169
+ WHERE store_product_id=" . $store_product_id;
9170
+
9171
+ $res = $this->db_do($q);
9172
+
9173
+ while ($photo = mysqli_fetch_array($res)) {
9174
+ $picHeight = (int)500;//$photo["PicHeight"];
9175
+ $picWidth = (int)500;//$photo["PicWidth"];
9176
+ $thumbUrl = (string)$photo["ThumbPic"];
9177
+ $picUrl = (string)$photo["Pic"];
9178
+
9179
+ array_push($this->galleryPhotos, array(
9180
+ 'height' => $picHeight,
9181
+ 'width' => $picWidth,
9182
+ 'thumb' => $thumbUrl,
9183
+ 'pic' => $picUrl
9184
+ ));
9185
+ }
9186
+ }
9187
+
9188
+ #################################################################################################
9189
+
9190
+ private function loadRelatedProducts($entity_id)
9191
+ {
9192
+ $this->sinchProductId;
9193
+ if (!$this->sinchProductId) {
9194
+ return;
9195
+ }
9196
+ $q = "SELECT
9197
+ st_prod.sinch_product_id,
9198
+ st_prod.product_sku,
9199
+ st_prod.product_name,
9200
+ st_prod.sinch_manufacturer_id,
9201
+ st_prod.store_category_id,
9202
+ st_prod.main_image_url,
9203
+ st_prod.thumb_image_url,
9204
+ st_prod.medium_image_url,
9205
+ st_prod.specifications,
9206
+ st_prod.description,
9207
+ st_prod.specifications,
9208
+ st_manuf.manufacturer_name,
9209
+ st_manuf.manufacturers_image
9210
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_related_products') . " st_rel_prod
9211
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products') . " st_prod
9212
+ ON st_rel_prod.related_sinch_product_id=st_prod.sinch_product_id
9213
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers') . " st_manuf
9214
+ ON st_prod.sinch_manufacturer_id=st_manuf.sinch_manufacturer_id
9215
+ WHERE st_rel_prod.sinch_product_id=" . $this->sinchProductId;
9216
+
9217
+ // echo $q;
9218
+ $quer = $this->db_do($q);
9219
+ while ($row = mysqli_fetch_array($quer)) {
9220
+
9221
+ $productArray = array();
9222
+ $productArray['name'] = (string)$row['product_name'];
9223
+ $productArray['thumb'] = (string)$row['thumb_image_url'];
9224
+ $mpn = (string)$row['product_sku'];
9225
+ $productSupplierId = (int)$row['sinch_manufacturer_id'];
9226
+ $productArray['supplier_thumb'] = (string)($row['manufacturers_image']);
9227
+ $productArray['supplier_name'] = (string)$row['manufacturer_name'];
9228
+
9229
+ $this->relatedProducts[$mpn] = $productArray;
9230
+ }
9231
  }
9232
+
9233
  #################################################################################################
9234
 
9235
+ public function getProductName()
9236
+ {
9237
  return $this->productName;
9238
  }
9239
+
9240
  #################################################################################################
9241
 
9242
+ public function getProductDescriptionList()
9243
+ {
9244
  return $this->productDescriptionList;
9245
  }
9246
+
9247
  #################################################################################################
9248
 
9249
+ public function getProductSpecifications()
9250
+ {
9251
  return $this->specifications;
9252
  }
9253
+
9254
  #################################################################################################
9255
 
9256
+ public function getShortProductDescription()
9257
+ {
9258
  return $this->productDescription;
9259
  }
9260
+
9261
  #################################################################################################
9262
 
9263
+ public function getFullProductDescription()
9264
+ {
9265
  return $this->fullProductDescription;
9266
  }
9267
+
9268
  #################################################################################################
9269
 
9270
+ public function getLowPicUrl()
9271
+ {
9272
  return $this->highPicUrl;
9273
  }
 
9274
 
9275
+ #################################################################################
 
 
 
9276
 
9277
+ public function getRelatedProducts()
9278
+ {
9279
+ return $this->relatedProducts;
9280
  }
 
9281
 
 
 
 
9282
  #################################################################################################
9283
 
9284
+ public function getVendor()
9285
+ {
9286
+ return $this->vendor;
 
 
 
 
9287
  }
9288
 
9289
+ ##################################################################################################
9290
 
9291
+ public function getMPN()
9292
+ {
9293
+ return $this->productId;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9294
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9295
 
9296
+ ##################################################################################################
9297
 
9298
+ public function getEAN()
9299
+ {
9300
+ return $this->EAN;
9301
  }
 
9302
 
9303
+ ##################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9304
 
9305
+ public function getGalleryPhotos()
9306
+ {
9307
+ return $this->galleryPhotos;
9308
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9309
 
9310
+ ##################################################################################################
 
 
 
 
 
 
9311
 
9312
+ public function reloadProductImage($entity_id)
9313
+ {
 
 
 
 
 
 
 
 
9314
  $result = $this->db_do("
9315
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
9316
  entity_type_id,
9317
  attribute_id,
9318
  store_id,
9320
  value
9321
  )(
9322
  SELECT
9323
+ " . $this->_getProductEntityTypeId() . ",
9324
+ " . $this->_getProductAttributeId('image') . ",
9325
  w.store_id,
9326
  a.entity_id,
9327
  b.main_image_url
9328
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
9329
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " w
9330
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products') . " b
9331
  ON a.store_product_id = b.store_product_id
9332
  WHERE a.entity_id=$entity_id
9333
  )
9338
 
9339
  // image for specific web sites
9340
  $result = $this->db_do("
9341
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
9342
  entity_type_id,
9343
  attribute_id,
9344
  store_id,
9346
  value
9347
  )(
9348
  SELECT
9349
+ " . $this->_getProductEntityTypeId() . ",
9350
+ " . $this->_getProductAttributeId('image') . ",
9351
  0,
9352
  a.entity_id,
9353
  b.main_image_url
9354
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
9355
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products') . " b
9356
  ON a.store_product_id = b.store_product_id
9357
  WHERE a.entity_id=$entity_id
9358
  )
9363
 
9364
  // small_image for specific web sites
9365
  $result = $this->db_do("
9366
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
9367
  entity_type_id,
9368
  attribute_id,
9369
  store_id,
9371
  value
9372
  )(
9373
  SELECT
9374
+ " . $this->_getProductEntityTypeId() . ",
9375
+ " . $this->_getProductAttributeId('small_image') . ",
9376
  w.store_id,
9377
  a.entity_id,
9378
  b.main_image_url
9379
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
9380
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " w
9381
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products') . " b
9382
  ON a.store_product_id = b.store_product_id
9383
  WHERE a.entity_id=$entity_id
9384
  )
9389
 
9390
  // small_image for all web sites
9391
  $result = $this->db_do("
9392
+ INSERT INTO " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar') . " (
9393
  entity_type_id,
9394
  attribute_id,
9395
  store_id,
9397
  value
9398
  )(
9399
  SELECT
9400
+ " . $this->_getProductEntityTypeId() . ",
9401
+ " . $this->_getProductAttributeId('small_image') . ",
9402
  0,
9403
  a.entity_id,
9404
  b.main_image_url
9405
+ FROM " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity') . " a
9406
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('core_store') . " w
9407
+ INNER JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_products') . " b
9408
  ON a.store_product_id = b.store_product_id
9409
  WHERE a.entity_id=$entity_id
9410
  )
9411
  ON DUPLICATE KEY UPDATE
9412
+ value = b.main_image_url
9413
+ ");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9414
  }
 
 
 
9415
 
9416
+ ##################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9417
 
9418
+ function valid_utf($string, $new_line = true)
9419
+ {
9420
+ /* if($new_line == true){
9421
+ $string = preg_replace('/\\\n/',"\n",$string);
9422
+ }
9423
+ */
9424
+ $string = preg_replace('/™/', '&#8482;', $string);
9425
+ $string = preg_replace("/®/", '&reg;', $string);
9426
+ $string = preg_replace("/≈/", '&asymp;', $string);
9427
+ $string = preg_replace("/" . chr(226) . chr(128) . chr(157) . "/", '&quot;', $string);
9428
+ $string = preg_replace("/" . chr(226) . chr(128) . chr(153) . "/", '&prime;', $string);
9429
+ $string = preg_replace("/°/", '&deg;', $string);
9430
+ $string = preg_replace("/±/", '&plusmn;', $string);
9431
+ $string = preg_replace("/µ/", '&micro;', $string);
9432
+ $string = preg_replace("/²/", '&sup2;', $string);
9433
+ $string = preg_replace("/³/", '&sup3;', $string);
9434
+ $string = preg_replace('/\xe2\x80\x93/', '-', $string);
9435
+ $string = preg_replace('/\xe2\x80\x99/', '\'', $string);
9436
+ $string = preg_replace('/\xe2\x80\x9c/', ' ', $string);
9437
+ $string = preg_replace('/\xe2\x80\x9d/', ' ', $string);
9438
 
9439
+ return utf8_decode($string);
 
 
 
 
9440
 
9441
+ // return $string;
9442
  }
 
9443
 
9444
+ ##################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9445
 
9446
+ function set_imports_failed()
9447
+ {
9448
+ $this->db_do("UPDATE " . $this->import_status_statistic_table . "
9449
+ SET global_status_import='Failed'
9450
+ WHERE global_status_import='Run'");
9451
  }
9452
+ ##################################################################################################
9453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9454
 
9455
+ ##################################################################################################
 
 
 
 
 
9456
 
9457
+ function getImportStatusHistory()
9458
+ {
9459
+ $res = "SELECT COUNT(*) FROM " . $this->import_status_statistic_table;
9460
+ $cnt_arr = mysqli_fetch_array($this->db_do($res));
9461
+ $cnt = $cnt_arr[0];
9462
+ $StatusHistory_arr = array();
9463
+ if ($cnt > 0) {
9464
+ $a = (($cnt > 7) ? ($cnt - 7) : 0);
9465
+ $b = $cnt;
9466
+ $q = "SELECT
9467
+ id,
9468
+ start_import,
9469
+ finish_import,
9470
+ import_type,
9471
+ number_of_products,
9472
+ global_status_import,
9473
+ detail_status_import
9474
+ FROM " . $this->import_status_statistic_table . "
9475
+ ORDER BY start_import limit " . $a . ", " . $b;
9476
+ $result = $this->db_do($q);
9477
+ while ($row = mysqli_fetch_array($result)) {
9478
+ $StatusHistory_arr[] = $row;
 
 
 
 
 
 
 
 
 
 
 
 
 
9479
  }
9480
  }
9481
  return $StatusHistory_arr;
9482
+ } // public function getImportEnvironment()
9483
+ ##################################################################################################
9484
+
9485
+
9486
+ ##################################################################################################
9487
+
9488
+ function getDateOfLatestSuccessImport()
9489
+ {
9490
+ $q = "SELECT start_import, finish_import
9491
+ FROM " . $this->import_status_statistic_table . "
9492
+ WHERE global_status_import='Successful'
9493
  ORDER BY id DESC LIMIT 1";
9494
+ $imp_date = mysqli_fetch_array($this->db_do($q));
9495
  return $imp_date['start_import'];
9496
+ } // public function getImportEnvironment()
9497
+ ##################################################################################################
9498
+
9499
+
9500
+ ##################################################################################################
9501
+
9502
+ function getDataOfLatestImport()
9503
+ {
9504
+ $q = "SELECT
9505
+ start_import,
9506
+ finish_import,
9507
+ import_type,
9508
+ number_of_products,
9509
+ global_status_import,
9510
+ detail_status_import,
9511
+ number_of_products,
9512
+ error_report_message
9513
+ FROM " . $this->import_status_statistic_table . "
9514
  ORDER BY id DESC LIMIT 1";
9515
+ $imp_status = mysqli_fetch_array($this->db_do($q));
9516
  return $imp_status;
9517
+ } // public function getImportEnvironment()
9518
+ ##################################################################################################
9519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9520
 
9521
+ ##################################################################################################
9522
+
9523
+ function getImportStatuses()
9524
+ {
9525
+ $q = "SELECT id, message, finished
9526
+ FROM " . $this->import_status_table . "
9527
  ORDER BY id LIMIT 1";
9528
+ $quer = $this->db_do($q);
9529
+ if ($row = mysqli_fetch_array($quer)) {
9530
+ $messages = array('message' => $row['message'], 'id' => $row['id'], 'finished' => $row['finished']);
9531
+ $id = $row['id'];
9532
  }
9533
+ if ($id) {
9534
+ $q = "DELETE FROM " . $this->import_status_table . " WHERE id=" . $id;
9535
  $this->db_do($q);
9536
  }
9537
  return $messages;
9538
+ } // public function getImportEnvironment()
9539
+ ##################################################################################################
9540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9541
 
9542
+ ##################################################################################################
9543
+
9544
+ public function checkMemory()
9545
+ {
9546
+ $check_code = 'memory';
9547
+
9548
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9549
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9550
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9551
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9552
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9553
+
9554
+
9555
+ $Caption = $row['caption'];
9556
+ $CheckValue = $row['check_value'];
9557
+ $CheckMeasure = $row['check_measure'];
9558
+ $ErrorMessage = $row['error_msg'];
9559
+ $FixMessage = $row['fix_msg'];
9560
+
9561
+ $retvalue = array();
9562
+ $retvalue["'$check_code'"] = array();
9563
+
9564
+ $memInfoContent = file_get_contents("/proc/meminfo");
9565
+ if ($memInfoContent === false) {
9566
+ return array(
9567
+ 'error',
9568
+ $Caption,
9569
+ $CheckValue,
9570
+ 0,
9571
+ $CheckMeasure,
9572
+ 'Cannot read /proc/meminfo for RAM information',
9573
+ 'Make sure open_basedir permits access to /proc/meminfo (or is off) and that this is a *nix system'
9574
+ );
9575
  }
9576
+ $data = explode("\n", $memInfoContent);
 
 
9577
 
9578
+ foreach ($data as $line) {
9579
+ $lineParts = explode(":", $line);
9580
+ if (count($lineParts) < 2) continue;
9581
+ list($key, $val) = $lineParts;
 
 
 
 
 
 
9582
 
9583
+ if ($key == 'MemTotal') {
9584
+ $val = trim($val);
9585
+ $value = (int)substr($val, 0, strpos($val, ' kB'));
9586
+ $measure = substr($val, strpos($val, ' kB'));
 
 
9587
 
9588
+ $retvalue['memory']['value'] = (integer)(((float)$value) / 1024); // (float)$value
9589
+ $retvalue['memory']['measure'] = 'MB'; // $measure;
 
 
 
 
 
 
 
 
 
 
9590
  }
9591
+ }
9592
 
9593
+ $errmsg = '';
9594
+ $fixmsg = '';
9595
+ if ($retvalue['memory']['value'] <= $CheckValue) {
9596
+ $errmsg = sprintf($ErrorMessage, $retvalue['memory']['value']); //." ".$retvalue['memory']['value']." ".$retvalue['memory']['measure'];
9597
+ $fixmsg = sprintf($FixMessage, " " . $CheckValue . " " . $CheckMeasure);
9598
+ $retvalue['memory']['status'] = 'error';
9599
+ } else {
9600
+ $retvalue['memory']['status'] = 'OK';
9601
  }
9602
+
9603
+ return array(
9604
+ $retvalue['memory']['status'],
9605
+ $Caption,
9606
+ $CheckValue,
9607
+ $retvalue['memory']['value'],
9608
+ $CheckMeasure,
9609
+ $errmsg,
9610
+ $fixmsg
9611
+ );
9612
+ } // public function getImportEnvironment()
9613
  ##################################################################################################
9614
 
9615
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9616
  ##################################################################################################
9617
 
9618
+ public function checkLoaddata()
9619
+ {
9620
+ $check_code = 'loaddata';
9621
+
9622
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9623
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9624
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9625
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9626
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9627
+
9628
+ $Caption = $row['caption'];
9629
+ $CheckValue = $row['check_value'];
9630
+ $CheckMeasure = $row['check_measure'];
9631
+ $ErrorMessage = $row['error_msg'];
9632
+ $FixMessage = $row['fix_msg'];
9633
+
9634
+ $retvalue = array();
9635
+ $retvalue["'$check_code'"] = array();
9636
+
9637
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9638
+ $result = $conn->query("SHOW VARIABLES LIKE 'local_infile'");
9639
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9640
+ $value = $row['Value'];
9641
+
9642
+
9643
+ $errmsg = '';
9644
+ $fixmsg = '';
9645
+ if ($value != $CheckValue) {
9646
+ $errmsg .= $ErrorMessage . " " . $value . " " . $CheckMeasure;
9647
+ $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9648
+ $status = 'error';
9649
+ } else {
9650
+ $errmsg .= 'none';
9651
+ $fixmsg .= 'none';
9652
+ $status = 'OK';
9653
  }
 
 
 
9654
 
9655
+ $ret = array();
9656
+ array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9657
+
9658
+ return $ret;
9659
+ } // public function getImportEnvironment()
9660
  ##################################################################################################
9661
 
9662
+
 
 
9663
  ##################################################################################################
9664
+
9665
+ public function checkPhpsafemode()
9666
+ {
9667
+ $check_code = 'phpsafemode';
9668
+
9669
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9670
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9671
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9672
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9673
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9674
+
9675
+ $Caption = $row['caption'];
9676
+ $CheckValue = $row['check_value'];
9677
+ $CheckMeasure = $row['check_measure'];
9678
+ $ErrorMessage = $row['error_msg'];
9679
+ $FixMessage = $row['fix_msg'];
9680
+
9681
+ $retvalue = array();
9682
+ $retvalue["'$check_code'"] = array();
9683
+
9684
+ $a = ini_get('safe_mode');
9685
+ if ($a) {
9686
+ $value = 'ON';
9687
+ } else {
9688
+ $value = 'OFF';
 
 
 
 
9689
  }
9690
+
9691
+ $errmsg = '';
9692
+ $fixmsg = '';
9693
+ if ($value != $CheckValue) {
9694
+ $errmsg .= sprintf($ErrorMessage, " " . $value . " " . $CheckMeasure);
9695
+ $fixmsg .= sprintf($FixMessage, " " . $CheckValue . " " . $CheckMeasure);
9696
+ $status = 'error';
9697
+ } else {
9698
+ $errmsg .= 'none';
9699
+ $fixmsg .= 'none';
9700
+ $status = 'OK';
 
 
 
 
 
 
9701
  }
9702
+
9703
+ $ret = array();
9704
+ array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9705
+
9706
+ return $ret;
9707
+ } // public function getImportEnvironment()
9708
  ##################################################################################################
9709
 
9710
 
9711
+ ##################################################################################################
9712
 
9713
+ public function checkWaittimeout()
9714
+ {
9715
+ $check_code = 'waittimeout';
9716
+
9717
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9718
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9719
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9720
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9721
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9722
+
9723
+ $Caption = $row['caption'];
9724
+ $CheckValue = $row['check_value'];
9725
+ $CheckMeasure = $row['check_measure'];
9726
+ $ErrorMessage = $row['error_msg'];
9727
+ $FixMessage = $row['fix_msg'];
9728
+
9729
+ $retvalue = array();
9730
+ $retvalue["'$check_code'"] = array();
9731
+
9732
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9733
+ $result = $conn->query("SHOW VARIABLES LIKE 'wait_timeout'");
9734
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9735
+ $value = $row['Value'];
9736
+
9737
+ $errmsg = '';
9738
+ $fixmsg = '';
9739
+ if ($value <= $CheckValue) {
9740
+ $errmsg .= $ErrorMessage . " " . $value . " " . $CheckMeasure;
9741
+ $fixmsg .= sprintf($FixMessage, " " . $CheckValue);
9742
+ $status = 'error';
9743
+ } else {
9744
+ $errmsg .= 'none';
9745
+ $fixmsg .= 'none';
9746
+ $status = 'OK';
9747
+ }
9748
 
9749
+ $ret = array();
9750
+ array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9751
 
9752
+ return $ret;
9753
+ } // public function checkChmodwgetcronphpfile()
9754
  ##################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9755
 
9756
 
9757
+ ##################################################################################################
9758
+
9759
+ public function checkInnodbbufferpoolsize()
9760
+ {
9761
+ $check_code = 'innodbbufpool';
9762
+
9763
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9764
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9765
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9766
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9767
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9768
+
9769
+ $Caption = $row['caption'];
9770
+ $CheckValue = $row['check_value'];
9771
+ $CheckMeasure = $row['check_measure'];
9772
+ $ErrorMessage = $row['error_msg'];
9773
+ $FixMessage = $row['fix_msg'];
9774
+
9775
+ $retvalue = array();
9776
+ $retvalue["'$check_code'"] = array();
9777
+
9778
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9779
+ $result = $conn->query("SHOW VARIABLES LIKE 'innodb_buffer_pool_size'");
9780
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9781
+ $value = (int)($row['Value'] / (1024 * 1024));
9782
+
9783
+ $errmsg = '';
9784
+ $fixmsg = '';
9785
+ if ($value < $CheckValue) {
9786
+ $errmsg .= sprintf($ErrorMessage, " " . $value . " " . $CheckMeasure);
9787
+ $fixmsg .= sprintf($FixMessage, " " . $CheckValue . " " . $CheckMeasure);
9788
+ $status = 'error';
9789
+ } else {
9790
+ $errmsg .= 'none';
9791
+ $fixmsg .= 'none';
9792
+ $status = 'OK';
9793
+ }
9794
 
9795
+ $ret = array();
9796
+ array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9797
 
9798
+ return $ret;
9799
+ } // public function checkChmodwgetcronphpfile()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9800
  ##################################################################################################
9801
 
9802
 
9803
+ ##################################################################################################
9804
+
9805
+ public function checkPhprunstring()
9806
+ {
9807
+ $check_code = 'php5run';
9808
+
9809
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9810
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9811
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9812
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9813
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9814
+
9815
+ $Caption = $row['caption'];
9816
+ $CheckValue = $row['check_value'];
9817
+ $CheckMeasure = $row['check_measure'];
9818
+ $ErrorMessage = $row['error_msg'];
9819
+ $FixMessage = $row['fix_msg'];
9820
+
9821
+ $retvalue = array();
9822
+ $retvalue["'$check_code'"] = array();
9823
+
9824
+ $value = trim(PHP_RUN_STRING);
9825
+ $errmsg = '';
9826
+ $fixmsg = '';
9827
+ $status = 'OK';
9828
 
9829
+ if (!defined('PHP_RUN_STRING')) {
9830
+ $errmsg .= "You haven't installed PHP CLI";
9831
+ $fixmsg .= "Install PHP CLI."; // ." ".$CheckValue." ".$CheckMeasure
9832
+ $status = 'error';
9833
+ }
9834
 
9835
+ return array(
9836
+ $status,
9837
+ $Caption,
9838
+ $CheckValue,
9839
+ $value,
9840
+ $CheckMeasure,
9841
+ $errmsg,
9842
+ $fixmsg
9843
+ );
9844
+ } // public function getImportEnvironment()
9845
  ##################################################################################################
9846
+
9847
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9848
  ##################################################################################################
9849
 
9850
+ public function checkChmodwgetdatafile()
9851
+ {
9852
+ $check_code = 'chmodwget';
9853
 
9854
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9855
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9856
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9857
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9858
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9859
 
9860
+ $Caption = $row['caption'];
9861
+ $CheckValue = $row['check_value'];
9862
+ $CheckMeasure = $row['check_measure'];
9863
+ $ErrorMessage = $row['error_msg'];
9864
+ $FixMessage = $row['fix_msg'];
9865
 
9866
+ $retvalue = array();
9867
+ $retvalue["'$check_code'"] = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9868
 
9869
+ $datafile_csv = '/usr/bin/wget';
9870
 
9871
+ $value = substr(sprintf('%o', fileperms($datafile_csv)), -4);
9872
 
9873
+ $CheckValue_own = $CheckValue{1};
9874
+ $CheckValue_group = $CheckValue{2};
9875
+ $CheckValue_other = $CheckValue{3};
9876
 
9877
+ $value_own = $value{1};
9878
+ $value_group = $value{2};
9879
+ $value_other = $value{3};
9880
+
9881
+ $errmsg = '';
9882
+ $fixmsg = '';
9883
+ //if ($value <= $CheckValue) {
9884
+ if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9885
+ $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9886
+ $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9887
+ $status = 'error';
9888
+ } else {
9889
+ $errmsg .= 'none';
9890
+ $fixmsg .= 'none';
9891
+ $status = 'OK';
9892
+ }
9893
+
9894
+ $ret = array();
9895
+ array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9896
+
9897
+ return $ret;
9898
+ } // public function getImportEnvironment()
9899
  ##################################################################################################
9900
+
9901
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9902
  ##################################################################################################
9903
 
9904
+ public function checkChmodwgetcronphpfile()
9905
+ {
9906
+ $check_code = 'chmodcronphp';
9907
 
9908
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9909
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9910
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9911
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9912
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9913
 
9914
+ $Caption = $row['caption'];
9915
+ $CheckValue = $row['check_value'];
9916
+ $CheckMeasure = $row['check_measure'];
9917
+ $ErrorMessage = $row['error_msg'];
9918
+ $FixMessage = $row['fix_msg'];
9919
 
9920
+ $retvalue = array();
9921
+ $retvalue["'$check_code'"] = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9922
 
9923
+ $cronfile_php = Mage::getBaseDir() . '/cron.php';
9924
+
9925
+ $value = substr(sprintf('%o', fileperms($cronfile_php)), -4);
9926
+
9927
+ $CheckValue_own = $CheckValue{1};
9928
+ $CheckValue_group = $CheckValue{2};
9929
+ $CheckValue_other = $CheckValue{3};
 
 
 
 
9930
 
9931
+ $value_own = $value{1};
9932
+ $value_group = $value{2};
9933
+ $value_other = $value{3};
9934
 
9935
+ $errmsg = '';
9936
+ $fixmsg = '';
9937
+ //if ($value <= $CheckValue) {
9938
+ if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9939
+ $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9940
+ $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9941
+ $status = 'error';
9942
+ } else {
9943
+ $errmsg .= 'none';
9944
+ $fixmsg .= 'none';
9945
+ $status = 'OK';
9946
+ }
9947
 
9948
+ $ret = array();
9949
+ array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
9950
 
9951
+ return $ret;
9952
+ }
9953
  ##################################################################################################
9954
+
9955
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9956
  ##################################################################################################
9957
 
9958
+ public function checkChmodwgetcronshfile()
9959
+ {
9960
+ $check_code = 'chmodcronsh';
9961
 
9962
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
9963
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
9964
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
9965
+ $row = $result->fetch(PDO::FETCH_ASSOC);
9966
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
9967
 
9968
+ $Caption = $row['caption'];
9969
+ $CheckValue = $row['check_value'];
9970
+ $CheckMeasure = $row['check_measure'];
9971
+ $ErrorMessage = $row['error_msg'];
9972
+ $FixMessage = $row['fix_msg'];
9973
 
9974
+ $retvalue = array();
9975
+ $retvalue["'$check_code'"] = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9976
 
9977
+ $cronfile_sh = Mage::getBaseDir() . '/cron.sh';
9978
 
9979
+ $value = substr(sprintf('%o', fileperms($cronfile_sh)), -4);
9980
 
9981
+ $CheckValue_own = $CheckValue{1};
9982
+ $CheckValue_group = $CheckValue{2};
9983
+ $CheckValue_other = $CheckValue{3};
9984
 
9985
+ $value_own = $value{1};
9986
+ $value_group = $value{2};
9987
+ $value_other = $value{3};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9988
 
9989
+ $errmsg = '';
9990
+ $fixmsg = '';
9991
+ //if ($value <= $CheckValue) {
9992
+ if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
9993
+ $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
9994
+ $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
9995
+ $status = 'error';
9996
+ } else {
9997
+ $errmsg .= 'none';
9998
+ $fixmsg .= 'none';
9999
+ $status = 'OK';
10000
+ }
10001
 
10002
+ $ret = array();
10003
+ array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
10004
 
10005
+ return $ret;
10006
+ }
10007
 
10008
+ #################################################################################################
10009
+
10010
+ public function checkProcedure()
10011
+ {
10012
+ $check_code = 'routine';
10013
+
10014
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
10015
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
10016
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
10017
+ $row = $result->fetch(PDO::FETCH_ASSOC);
10018
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
10019
+
10020
+ $Caption = $row['caption'];
10021
+ $CheckValue = $row['check_value'];
10022
+ $CheckMeasure = $row['check_measure'];
10023
+ $ErrorMessage = $row['error_msg'];
10024
+ $FixMessage = $row['fix_msg'];
10025
+
10026
+ $retvalue = array();
10027
+ $retvalue["'$check_code'"] = array();
10028
+
10029
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
10030
+ $storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
10031
+ $result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
10032
+ $row = $result->fetch(PDO::FETCH_ASSOC);
10033
+ $value = $row['Name'];
10034
+
10035
+ $errmsg = '';
10036
+ $fixmsg = '';
10037
+ if ($value != $CheckValue) {
10038
+ $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
10039
+ $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
10040
+ $status = 'error';
10041
+ } else {
10042
+ $errmsg .= 'none';
10043
+ $fixmsg .= 'none';
10044
+ $status = 'OK';
10045
+ }
 
 
 
 
 
10046
 
10047
+ $ret = array();
10048
+ array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
10049
 
10050
+ return $ret;
10051
+ }
10052
 
10053
+ #################################################################################################
10054
 
10055
+ public function checkConflictsWithInstalledModules()
10056
+ {
10057
+ $check_code = 'conflictwithinstalledmodules';
10058
+
10059
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
10060
+ $tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
10061
+ $result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
10062
+ $row = $result->fetch(PDO::FETCH_ASSOC);
10063
+ //echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
10064
+
10065
+ $Caption = $row['caption'];
10066
+ $CheckValue = $row['check_value'];
10067
+ $CheckMeasure = $row['check_measure'];
10068
+ $ErrorMessage = $row['error_msg'];
10069
+ $FixMessage = $row['fix_msg'];
10070
+
10071
+ $retvalue = array();
10072
+ $retvalue["'$check_code'"] = array();
10073
+
10074
+ /* $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
10075
+ $storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
10076
+ $result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
10077
+ $row = $result->fetch(PDO::FETCH_ASSOC);
10078
+ $value = $row['Name'];
10079
  */
10080
  $config_file = (Mage::app()->getConfig()->getNode()->asXML());
10081
+
10082
+ $errmsg = $ErrorMessage;
10083
+ $fixmsg = $FixMessage;
10084
+ /*
10085
+ if ($value != $CheckValue) {
10086
+ $errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
10087
+ $fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
10088
+ $status = 'error';
10089
+ */
10090
  $status = 'OK';
10091
 
10092
  if (!strstr($config_file, '<image>Bintime_Sinchimport_Helper_Image</image>')) {
10093
+ $errmsg .= " Can't find <image>Bintime_Sinchimport_Helper_Image</image> in <helpers><catalog></catalog></helpers>"; // ." ".$value." ".$CheckMeasure
10094
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10095
  $status = 'error';
10096
  }
10097
 
10098
  if (!strstr($config_file, '<product_image>Bintime_Sinchimport_Model_Image</product_image>')) {
10099
+ $errmsg .= " Can't find <product_image>Bintime_Sinchimport_Model_Image</product_image> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
10100
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10101
  $status = 'error';
10102
  }
10103
 
10104
  if (!strstr($config_file, '<category>Bintime_Sinchimport_Model_Category</category>')) {
10105
+ $errmsg .= " Can't find <category>Bintime_Sinchimport_Model_Category</category> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
10106
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10107
  $status = 'error';
10108
  }
10109
 
10110
  if (!strstr($config_file, '<product_compare_list>Bintime_Sinchimport_Block_List</product_compare_list>')) {
10111
+ $errmsg .= " Can't find <product_compare_list>Bintime_Sinchimport_Block_List</product_compare_list> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
10112
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10113
  $status = 'error';
10114
  }
10115
 
10116
  if (!strstr($config_file, '<product_view_media>Bintime_Sinchimport_Block_Product_View_Media</product_view_media>')) {
10117
+ $errmsg .= " Can't find <product_view_media>Bintime_Sinchimport_Block_Product_View_Media</product_view_media> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
10118
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10119
  $status = 'error';
10120
  }
10121
 
10122
  if (!strstr($config_file, '<product>Bintime_Sinchimport_Model_Product</product>')) {
10123
+ $errmsg .= " Can't find <product>Bintime_Sinchimport_Model_Product</product> in <models><catalog></catalog></models>"; // ." ".$value." ".$CheckMeasure
10124
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10125
  $status = 'error';
10126
  }
10127
 
10128
  if (!strstr($config_file, '<layer_filter_price>Bintime_Sinchimport_Model_Layer_Filter_Price</layer_filter_price>')) {
10129
+ $errmsg .= " Can't find <layer_filter_price>Bintime_Sinchimport_Model_Layer_Filter_Price</layer_filter_price> in <models><catalog></catalog><models>"; // ." ".$value." ".$CheckMeasure
10130
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10131
  $status = 'error';
10132
  }
10133
 
10134
  if (!strstr($config_file, '<layer_view>Bintime_Sinchimport_Block_Layer_View</layer_view>')) {
10135
+ $errmsg .= " Can't find <layer_view>Bintime_Sinchimport_Block_Layer_View</layer_view> in <blocks><catalog></catalog></blocks>"; // ." ".$value." ".$CheckMeasure
10136
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10137
  $status = 'error';
10138
  }
10139
 
10140
  if (!strstr($config_file, '<layer>Bintime_Sinchimport_Model_Layer</layer>')) {
10141
+ $errmsg .= " Can't find <layer>Bintime_Sinchimport_Model_Layer</layer> in <models><catalog></catalog><models>"; // ." ".$value." ".$CheckMeasure
10142
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10143
  $status = 'error';
10144
  }
10145
 
10146
  if (!strstr($config_file, '<layer_filter_price>Bintime_Sinchimport_Model_Resource_Layer_Filter_Price</layer_filter_price>')) {
10147
+ $errmsg .= " Can't find <layer_filter_price>Bintime_Sinchimport_Model_Resource_Layer_Filter_Price</layer_filter_price> in <models><catalog_resource_eav_mysql4></catalog_resource_eav_mysql4></models>"; // ." ".$value." ".$CheckMeasure
10148
  $fixmsg = $FixMessage;//.$CheckValue." ".$CheckMeasure
10149
  $status = 'error';
10150
  }
10151
 
10152
 
10153
+ if ($status == 'OK') {
10154
  $errmsg = 'none';
10155
  $fixmsg = 'none';
10156
  }
10157
+ return array(
10158
+ $status,
10159
+ $Caption,
10160
+ $CheckValue,
10161
+ '',
10162
+ $CheckMeasure,
10163
+ $errmsg,
10164
+ $fixmsg
10165
+ );
10166
+ }
 
 
10167
 
10168
+ #################################################################################################
10169
 
10170
+ public function getSinchDistribotorsTableHtml($entity_id = null)
10171
+ {
10172
+ /*/ Load the collection
10173
  $collection = getResourceModel('sales/order_grid_collection');
10174
 
10175
  // Add custom data
10177
 
10178
  // Set the collection
10179
  $this->setCollection($collection);
10180
+ // return parent::_prepareCollection();
10181
  */
10182
+ if (!$entity_id) {
10183
+ $entity_id = Mage::registry('current_product')->getId();
10184
+ }
10185
+ if (!$entity_id) {
10186
  return '';
10187
+ }
10188
+
10189
+ $distributors_stock_price = $this->getDistributorStockPriceByProductid($entity_id);
10190
+ $distributors_table = '
10191
  <table>
10192
  <thead>
10193
  <tr class="headings">
10198
  </thead>
10199
  <tbody>';
10200
  $i = 1;
10201
+ foreach ($distributors_stock_price as $offer) {
10202
+ if ($i > 0) {
10203
  $class = "even pointer";
10204
  $i = 0;
10205
+ } else {
10206
  $class = "pointer";
10207
  $i = 1;
10208
  }
10209
  $distributors_table .= '
10210
+ <tr class="' . $class . '">
10211
+ <td nowrap style="font-weight: normal">' . $offer['distributor_name'] . '</td>
10212
+ <td style="font-weight: normal">' . $offer['stock'] . '</td>
10213
+ <td style="font-weight: normal">' . Mage::helper('core')->currency($offer['cost']) . '</td>
10214
  </tr>';
10215
  }
10216
  $distributors_table .= '
10219
  ';
10220
  return $distributors_table;
10221
  }
 
 
10222
 
10223
+ #################################################################################################
10224
 
10225
+ private function getDistributorStockPriceByProductid($entity_id)
10226
+ {
10227
+ $store_product_id = $this->getStoreProductIdByEntity($entity_id);
10228
+ if (!$store_product_id) {
10229
+ // echo "AAAAAAA"; exit;
 
10230
  return;
10231
+ }
10232
+ $q = "SELECT
10233
  d.distributor_name,
10234
  d.website,
10235
+ dsp.stock,
10236
  dsp.cost,
10237
  dsp.distributor_sku,
10238
  dsp.distributor_category,
10239
  dsp.eta
10240
+ FROM " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors_stock_and_price') . " dsp
10241
+ JOIN " . Mage::getSingleton('core/resource')->getTableName('stINch_distributors') . " d
10242
  ON dsp.distributor_id = d.distributor_id
10243
+ WHERE store_product_id =" . $store_product_id;
10244
+ $quer = $this->db_do($q);
10245
  $offers = null;
10246
+ while ($row = mysqli_fetch_array($quer)) {
10247
+ $offers[] = $row;
10248
  }
10249
  return $offers;
 
 
 
10250
 
 
 
 
10251
  }
10252
+
10253
+ protected function _checkCategoryBackupExist($catalog_category_entity_backup) {
10254
+ $query = $this->db_do("
10255
+ SELECT *
10256
+ FROM $catalog_category_entity_backup
10257
+ ");
10258
+ while ($row = mysqli_fetch_array($query))
10259
+ {
10260
+ return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10261
  }
 
 
 
10262
 
10263
+ return false;
 
 
 
 
 
 
10264
  }
10265
+
10266
  } // class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract
app/code/local/Bintime/Sinchimport/Model/System/Config/ServerList.php CHANGED
@@ -29,7 +29,7 @@ class Bintime_Sinchimport_Model_System_Config_ServerList
29
  'ftpse.stockinthechannel.com' => 'Sweden - ftpse.stockinthechannel.com',
30
  'ftpch.stockinthechannel.com' => 'Switzerland - ftpch.stockinthechannel.com',
31
  'ftptr.stockinthechannel.com' => 'Turkey - ftptr.stockinthechannel.com',
32
- 'ftpdemo.stockinthechannel.com' => 'Demo - ftpdemo.stockinthechannel.com',
33
  );
34
  return $paramsArray;
35
  }
29
  'ftpse.stockinthechannel.com' => 'Sweden - ftpse.stockinthechannel.com',
30
  'ftpch.stockinthechannel.com' => 'Switzerland - ftpch.stockinthechannel.com',
31
  'ftptr.stockinthechannel.com' => 'Turkey - ftptr.stockinthechannel.com',
32
+ 'ftpdemo.stockinthechannel.com' => 'Demo - ftpdemo.stockinthechannel.com'
33
  );
34
  return $paramsArray;
35
  }
app/code/local/Bintime/Sinchimport/Model/config.php CHANGED
@@ -14,6 +14,7 @@
14
  define('LOG_FILE', 'LOG_PATH'.'import'.date("_Y_m").'.log');
15
 
16
  define('FILE_CATEGORIES', 'Categories.csv');
 
17
  define('FILE_CATEGORY_TYPES', 'CategoryTypes.csv');
18
  define('FILE_CATEGORIES_FEATURES', 'CategoryFeatures.csv');
19
  define('FILE_DISTRIBUTORS', 'Distributors.csv');
@@ -23,10 +24,12 @@
23
  define('FILE_PRODUCT_FEATURES', 'ProductFeatures.csv');
24
  define('FILE_PRODUCT_CATEGORIES', 'ProductCategories.csv');
25
  define('FILE_PRODUCTS', 'Products.csv');
 
26
  define('FILE_RELATED_PRODUCTS', 'RelatedProducts.csv');
27
  define('FILE_RESTRICTED_VALUES', 'RestrictedValues.csv');
28
  define('FILE_STOCK_AND_PRICES', 'StockAndPrices.csv');
29
  define('FILE_PRODUCTS_PICTURES_GALLERY', 'ProductPictures.csv');
 
30
  define('FILE_PRICE_RULES', 'contractprices.csv');
31
  define('FILE_URL_AND_DIR', "ftp://%%%login%%%:%%%password%%%@%%%server%%%/"); // insert StockInTheChannel url (default ftp://%%%login%%%:%%%password%%%@ftp.stockinthechannel.com/)
32
  define('DEFAULT_FILE_TERMINATED_CHAR', "|");
14
  define('LOG_FILE', 'LOG_PATH'.'import'.date("_Y_m").'.log');
15
 
16
  define('FILE_CATEGORIES', 'Categories.csv');
17
+ define('FILE_CATEGORIES_TEST', 'Categories_Test.csv');
18
  define('FILE_CATEGORY_TYPES', 'CategoryTypes.csv');
19
  define('FILE_CATEGORIES_FEATURES', 'CategoryFeatures.csv');
20
  define('FILE_DISTRIBUTORS', 'Distributors.csv');
24
  define('FILE_PRODUCT_FEATURES', 'ProductFeatures.csv');
25
  define('FILE_PRODUCT_CATEGORIES', 'ProductCategories.csv');
26
  define('FILE_PRODUCTS', 'Products.csv');
27
+ define('FILE_PRODUCTS_TEST', 'Products_Test.csv');
28
  define('FILE_RELATED_PRODUCTS', 'RelatedProducts.csv');
29
  define('FILE_RESTRICTED_VALUES', 'RestrictedValues.csv');
30
  define('FILE_STOCK_AND_PRICES', 'StockAndPrices.csv');
31
  define('FILE_PRODUCTS_PICTURES_GALLERY', 'ProductPictures.csv');
32
+ define('FILE_PRODUCT_CONTRACTS', 'ProductContracts.csv');
33
  define('FILE_PRICE_RULES', 'contractprices.csv');
34
  define('FILE_URL_AND_DIR', "ftp://%%%login%%%:%%%password%%%@%%%server%%%/"); // insert StockInTheChannel url (default ftp://%%%login%%%:%%%password%%%@ftp.stockinthechannel.com/)
35
  define('DEFAULT_FILE_TERMINATED_CHAR', "|");
app/code/local/Bintime/Sinchimport/controllers/BackupController.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Sinchimport_BackupController extends Mage_Adminhtml_Controller_Action {
3
+ public function indexAction(){
4
+ //process backup data here
5
+ $model = Mage::getModel('sinchimport/backup');
6
+ $this->_getSession()->addSuccess($this->__('Backup category and product ids successfully'));
7
+ $this->_redirect('adminhtml/system_config/edit', array('section' => 'sinchimport_root'));
8
+ return;
9
+ }
10
+ }
app/code/local/Bintime/Sinchimport/etc/config.xml CHANGED
@@ -4,7 +4,7 @@
4
 
5
  <modules>
6
  <Bintime_Sinchimport>
7
- <version>3.0.4</version>
8
  <depends>
9
  <!-- no dependencies -->
10
  </depends>
4
 
5
  <modules>
6
  <Bintime_Sinchimport>
7
+ <version>3.0.6</version>
8
  <depends>
9
  <!-- no dependencies -->
10
  </depends>
app/code/local/Bintime/Sinchimport/etc/system.xml CHANGED
@@ -126,6 +126,25 @@
126
  </start_sinch_import>
127
  </fields>
128
  </sinch_import_fullstatus>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  <sinch_import_stockpricestatus translate="label">
130
  <label>Import Stock &amp; Prices</label>
131
  <frontend_type>text</frontend_type>
126
  </start_sinch_import>
127
  </fields>
128
  </sinch_import_fullstatus>
129
+ <sinch_backup_catalog translate="label">
130
+ <label>Backup Categories and Products Ids</label>
131
+ <frontend_type>text</frontend_type>
132
+ <comment>Backup current Ids of products and categories to re-use when importing in overwrite mode.</comment>
133
+ <sort_order>160</sort_order>
134
+ <show_in_default>1</show_in_default>
135
+ <show_in_website>1</show_in_website>
136
+ <show_in_store>1</show_in_store>
137
+ <fields>
138
+ <start_sinch_import translate="label">
139
+ <frontend_type>button</frontend_type>
140
+ <frontend_model>sinchimport/backupbutton</frontend_model>
141
+ <sort_order>4</sort_order>
142
+ <show_in_default>1</show_in_default>
143
+ <show_in_website>0</show_in_website>
144
+ <show_in_store>0</show_in_store>
145
+ </start_sinch_import>
146
+ </fields>
147
+ </sinch_backup_catalog>
148
  <sinch_import_stockpricestatus translate="label">
149
  <label>Import Stock &amp; Prices</label>
150
  <frontend_type>text</frontend_type>
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.4-3.0.5.php ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+
4
+ //прямое подключение к базе необходимо для добавления хранимки
5
+ $config = $installer->getConnection()->getConfig();
6
+ $cnx = mysql_connect($config['host'], $config['username'], $config['password']);
7
+ if (!$cnx) {
8
+ throw new Exception('Failed to connect to database.');
9
+ }
10
+
11
+ if (!mysql_select_db($config['dbname'])) {
12
+ throw new Exception('Failed to select a database.');
13
+ }
14
+
15
+ $installer->startSetup();
16
+
17
+
18
+ $attr_varchar=array(
19
+ 'contract_id' => 'Contract ID',
20
+ );
21
+
22
+ foreach($attr_varchar as $key=>$value){
23
+
24
+ $installer->addAttribute('catalog_product', $key,array(
25
+ 'label' => $value,
26
+ 'type' => 'varchar',
27
+ 'input' => 'text',
28
+ 'backend' => 'eav/entity_attribute_backend_array',
29
+ 'frontend' => '',
30
+ 'source' => '',
31
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
32
+ 'visible' => true,
33
+ 'required' => false,
34
+ 'user_defined' => false,
35
+ 'searchable' => false,
36
+ 'filterable' => false,
37
+ 'comparable' => false,
38
+ 'visible_on_front' => true,
39
+ 'visible_in_advanced_search' => false,
40
+ 'unique' => false
41
+ ));
42
+
43
+
44
+ $data=array(
45
+ 'is_visible_on_front' => 0,
46
+ 'is_html_allowed_on_front' => 1
47
+ );
48
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
49
+ if ($id = $installer->getAttribute($entityTypeId, $key, 'attribute_id')) {
50
+ $installer->updateAttribute($entityTypeId, $id, $data);
51
+ }
52
+
53
+ }
54
+
55
+
56
+ $installer->run("DROP PROCEDURE IF EXISTS ".$installer->getTable('filter_sinch_products_s'));
57
+
58
+ $query = "
59
+ CREATE PROCEDURE ".$installer->getTable('filter_sinch_products_s')."(
60
+ IN arg_table INT,
61
+ IN arg_category_id INT,
62
+ IN arg_image INT,
63
+ IN arg_category_feature INT,
64
+ IN arg_least INT,
65
+ IN arg_greatest INT,
66
+ IN arg_table_prefix VARCHAR(255)
67
+ )
68
+ BEGIN
69
+ DROP TABLE IF EXISTS `tmp_result`;
70
+
71
+ CREATE TEMPORARY TABLE `tmp_result`(
72
+ `entity_id` int(10) unsigned,
73
+ `category_id` int(10) unsigned,
74
+ `product_id` int,
75
+ `sinch_category_id` int,
76
+ `name` varchar(255),
77
+ `image` varchar(255),
78
+ `supplier_id` int,
79
+ `category_feature_id` int,
80
+ `feature_id` int,
81
+ `feature_name` varchar(255),
82
+ `feature_value` text
83
+ );
84
+
85
+
86
+ IF arg_image = 1 THEN
87
+ SET @updquery = CONCAT('
88
+
89
+ INSERT INTO `tmp_result` (
90
+ entity_id,
91
+ category_id,
92
+ product_id,
93
+ sinch_category_id,
94
+ `name`,
95
+ `image`,
96
+ supplier_id,
97
+ category_feature_id,
98
+ feature_id,
99
+ feature_name,
100
+ feature_value
101
+ )(
102
+ SELECT
103
+ E.entity_id,
104
+ PCind.category_id,
105
+ E.entity_id,
106
+ PCind.category_id as `sinch_category`,
107
+ PR.`product_name`,
108
+ PR.main_image_url,
109
+ PR.sinch_manufacturer_id,
110
+ CF.category_feature_id,
111
+ CF.category_feature_id,
112
+ CF.`feature_name`,
113
+ RV.`text`
114
+ FROM ', arg_table_prefix, 'catalog_product_entity E
115
+ INNER JOIN ', arg_table_prefix, 'catalog_category_product_index PCind
116
+ ON (E.entity_id = PCind.product_id)
117
+ INNER JOIN ', arg_table_prefix, 'stINch_categories_mapping scm
118
+ ON PCind.category_id=scm.shop_entity_id
119
+ INNER JOIN ',arg_table_prefix, 'stINch_categories_features CF
120
+ ON (scm.store_category_id=CF.store_category_id)
121
+ INNER JOIN ',arg_table_prefix, 'stINch_products PR
122
+ ON (PR.store_product_id = E.store_product_id)
123
+ INNER JOIN ',arg_table_prefix, 'stINch_product_features PF
124
+ ON (PR.sinch_product_id = PF.sinch_product_id )
125
+ INNER JOIN ',arg_table_prefix, 'stINch_restricted_values RV
126
+ ON (PF.restricted_value_id=RV.restricted_value_id)
127
+ WHERE
128
+ scm.shop_entity_id = ', arg_category_id, '
129
+ AND PR.main_image_url <> \'\'
130
+ )
131
+ ');
132
+ ELSE
133
+ SET @updquery = CONCAT('
134
+
135
+ INSERT INTO `tmp_result` (
136
+ entity_id,
137
+ category_id,
138
+ product_id,
139
+ sinch_category_id,
140
+ `name`,
141
+ `image`,
142
+ supplier_id,
143
+ category_feature_id,
144
+ feature_id,
145
+ feature_name,
146
+ feature_value
147
+ )(
148
+ SELECT
149
+ E.entity_id,
150
+ PCind.category_id,
151
+ E.entity_id,
152
+ PCind.category_id as `sinch_category`,
153
+ PR.`product_name`,
154
+ PR.main_image_url,
155
+ PR.sinch_manufacturer_id,
156
+ CF.category_feature_id,
157
+ CF.category_feature_id,
158
+ CF.`feature_name`,
159
+ RV.`text`
160
+ FROM ', arg_table_prefix ,'catalog_product_entity E
161
+ INNER JOIN ', arg_table_prefix, 'catalog_category_product_index PCind
162
+ ON (E.entity_id = PCind.product_id)
163
+ INNER JOIN ', arg_table_prefix, 'stINch_categories_mapping scm
164
+ ON PCind.category_id=scm.shop_entity_id
165
+ INNER JOIN ', arg_table_prefix, 'stINch_categories_features CF
166
+ ON (scm.store_category_id=CF.store_category_id)
167
+ INNER JOIN ', arg_table_prefix, 'stINch_products PR
168
+ ON (PR.store_product_id = E.store_product_id)
169
+ INNER JOIN ', arg_table_prefix, 'stINch_product_features PF
170
+ ON (PR.sinch_product_id = PF.sinch_product_id )
171
+ INNER JOIN ', arg_table_prefix, 'stINch_restricted_values RV
172
+ ON (PF.restricted_value_id=RV.restricted_value_id)
173
+ WHERE
174
+ scm.shop_entity_id = ', arg_category_id, '
175
+
176
+ )
177
+ ');
178
+ END IF;
179
+
180
+ PREPARE myquery FROM @updquery;
181
+ EXECUTE myquery;
182
+ DROP PREPARE myquery;
183
+
184
+ SET @filter_features_count = 0;
185
+ SET @ifquery = CONCAT('SELECT COUNT(*) INTO @filter_features_count FROM `', arg_table_prefix, 'FilterListOfFeatures`');
186
+ PREPARE myquery FROM @ifquery;
187
+ EXECUTE myquery;
188
+ DROP PREPARE myquery;
189
+
190
+ IF (@filter_features_count) > 0 THEN
191
+ SET @query = CONCAT('
192
+ INSERT INTO `', arg_table_prefix, 'SinchFilterResult_', arg_table, '` (
193
+ entity_id,
194
+ category_id,
195
+ product_id,
196
+ sinch_category_id,
197
+ `name`,
198
+ `image`,
199
+ supplier_id,
200
+ category_feature_id,
201
+ feature_id,
202
+ feature_name,
203
+ feature_value
204
+ )(
205
+ SELECT
206
+ TR.entity_id,
207
+ TR.category_id,
208
+ TR.product_id,
209
+ TR.sinch_category_id,
210
+ TR.`name`,
211
+ TR.`image`,
212
+ TR.supplier_id,
213
+ TR.category_feature_id,
214
+ TR.feature_id,
215
+ TR.feature_name,
216
+ TR.feature_value
217
+ FROM `tmp_result` AS TR
218
+ INNER JOIN `', arg_table_prefix, 'FilterListOfFeatures` AS LF
219
+ ON (TR.category_feature_id = LF.category_feature_id)
220
+ WHERE TR.feature_value LIKE LF.feature_value GROUP BY entity_id
221
+ )
222
+ ');
223
+
224
+ ELSE
225
+ IF (arg_least IS NOT null AND arg_greatest IS NOT null) THEN
226
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' AND TR.feature_value <', arg_greatest, ' ');
227
+ ELSE
228
+ IF arg_least IS null THEN
229
+ SET @where = CONCAT(' AND TR.feature_value < ', arg_greatest, ' ');
230
+ ELSE
231
+ SET @where = CONCAT(' AND TR.feature_value >= ', arg_least, ' ');
232
+ END IF;
233
+ END IF;
234
+
235
+ SET @query = CONCAT('
236
+ INSERT INTO `', arg_table_prefix, 'SinchFilterResult_', arg_table, '` (
237
+ entity_id,
238
+ category_id,
239
+ product_id,
240
+ sinch_category_id,
241
+ `name`,
242
+ `image`,
243
+ supplier_id,
244
+ category_feature_id,
245
+ feature_id,
246
+ feature_name,
247
+ feature_value
248
+ )(
249
+ SELECT
250
+ TR.entity_id,
251
+ TR.category_id,
252
+ TR.product_id,
253
+ TR.sinch_category_id,
254
+ TR.`name`,
255
+ TR.`image`,
256
+ TR.supplier_id,
257
+ TR.category_feature_id,
258
+ TR.feature_id,
259
+ TR.feature_name,
260
+ TR.feature_value
261
+ FROM `tmp_result` AS TR
262
+ WHERE TR.category_feature_id = \'', arg_category_feature, '\'',
263
+ @where,
264
+ 'GROUP BY entity_id
265
+ )
266
+ ');
267
+
268
+ END IF;
269
+
270
+ PREPARE myquery FROM @query;
271
+ EXECUTE myquery;
272
+ DROP PREPARE myquery;
273
+
274
+ END
275
+ ";
276
+
277
+ if (!mysql_query($query, $cnx)) {
278
+ throw new Exception("Failed to create stored procedure".$query);
279
+ }
280
+
281
+
282
+ mysql_close($cnx);
283
+
284
+
285
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-3.0.5-3.0.6.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $installer->run("
6
+ -- DROP TABLE IF EXISTS {$this->getTable('sinch_product_backup')};
7
+ CREATE TABLE IF NOT EXISTS {$this->getTable('sinch_product_backup')} (
8
+ `entity_id` int(11) unsigned NOT NULL,
9
+ `sku` varchar(64) NULL,
10
+ `store_product_id` int(10) unsigned NOT NULL,
11
+ `sinch_product_id` int(11) unsigned NOT NULL,
12
+ UNIQUE KEY (entity_id),
13
+ KEY sku (sku),
14
+ KEY store_product_id (store_product_id),
15
+ KEY sinch_product_id (sinch_product_id)
16
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
17
+
18
+ -- DROP TABLE IF EXISTS {$this->getTable('sinch_category_backup')};
19
+ CREATE TABLE IF NOT EXISTS {$this->getTable('sinch_category_backup')} (
20
+ `entity_id` int(10) UNSIGNED NOT NULL,
21
+ `entity_type_id` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
22
+ `attribute_set_id` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
23
+ `parent_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
24
+ `store_category_id` int(11) UNSIGNED DEFAULT NULL,
25
+ `parent_store_category_id` int(11) UNSIGNED DEFAULT NULL,
26
+ UNIQUE KEY (entity_id),
27
+ KEY entity_type_id (entity_type_id),
28
+ KEY attribute_set_id (attribute_set_id),
29
+ KEY parent_id (parent_id),
30
+ KEY store_category_id (store_category_id),
31
+ KEY parent_store_category_id (parent_store_category_id)
32
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
33
+
34
+ ");
35
+
36
+ $installer->endSetup();
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/storeProcedureGenerator.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ($argc != 2) {
3
+ die(PHP_EOL . 'Use: php storeProcedureGenerator.php tablePrefix' . PHP_EOL);
4
+ }
5
+ $prefix = $argv[1];
6
+ $file_template = "filter_sinch_products_s.sql";
7
+ $new_store_file = $prefix.$file_template;
8
+ $table_array=array(
9
+ "filter_sinch_products_s",
10
+ "tmp_result",
11
+ "catalog_product_entity",
12
+ "catalog_category_product_index",
13
+ "stINch_categories_mapping",
14
+ "stINch_categories_features",
15
+ "stINch_products",
16
+ "stINch_product_features",
17
+ "stINch_restricted_values",
18
+ "FilterListOfFeatures",
19
+ "SinchFilterResult_"
20
+ );
21
+ $new_table_array = array();
22
+ foreach($table_array as $key => $table){
23
+ $new_table_array[] = $prefix.$table;
24
+ $table_array[$key] = "/".$table_array[$key]."/";
25
+ }
26
+ $file = file("$file_template");
27
+ $cahnged_file = fopen($new_store_file, "a+");
28
+ foreach($file as $str) {
29
+ $changed_string = preg_replace($table_array, $new_table_array, $str);
30
+ fwrite($cahnged_file, $changed_string);
31
+ }
32
+ fclose($cahnged_file);
33
+ echo "\nNew store file (".$new_store_file .") generated\n";
34
+ ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>stockinthechannel2012</name>
4
- <version>2.1.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3</license>
7
  <channel>community</channel>
@@ -9,12 +9,12 @@
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.1.2:&#xD;
13
- * Added more country options to the site to server list</notes>
14
- <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><author><name>Michael</name><user>michaelfigg</user><email>michael.figg@stockinthechannel.com</email></author></authors>
15
- <date>2016-03-08</date>
16
- <time>12:56:24</time>
17
- <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="4c211bb7854afd6f8830d8b9bdf22c2d"/></dir></dir></dir><file name="Importenvironment.php" hash="1c98dbc41e243bd2c899817ce91adfe7"/><file name="Importhistory.php" hash="9f1bda290333c3015b54ef3802857a3f"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="dd62c6b2546e387695b05307dbe7c07a"/></dir><file name="View.php" hash="9b64e2e1ab3b683db704878698a56dd9"/></dir><file name="List.php" hash="18b73e0f2d7959fa9af99f7fce8a60f4"/><dir name="Product"><dir name="View"><file name="Media.php" hash="f82030a12d1d41dfc75647a56b691dcb"/></dir></dir><file name="Startimportbutton.php" hash="b7564c48d52fc777abe1c5e87f63ad02"/><file name="Startstockpriceimportbutton.php" hash="f295d3d570114d0eb71238fb9c51dfa4"/></dir><dir name="Helper"><file name="Data.php" hash="6ba3ed5d098de4d1d90f5ce49bffbed2"/><file name="Getdata.php" hash="b966ec1c48a70956c980627af49d2078"/><file name="Image.php" hash="38dd206e1a90fac4b11ea340045a7b33"/></dir><dir name="Model"><file name="Api.php" hash="9c563069c93b6010597114a32304e44d"/><file name="Category.php" hash="24023d361652a68627a28a20b9229684"/><file name="Image.php" hash="7388b5396d4fd385e203e15e940c970d"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="6729da777e0fcc6ce24fa938a47a55f2"/><file name="Price.php" hash="d60d968b3b54842fbced634e3e89f428"/></dir></dir><file name="Layer.php" hash="a0b9a98e99e3da8b6d4b19093eb646a5"/><file name="Product.php" hash="de3db0ad9ab43ec060f906a66e7ac2ee"/><dir name="Resource"><dir name="Layer"><dir name="Filter"><file name="Price.php" hash="f7fcd3372e0c6ecc8ad8215e57679afa"/></dir></dir><dir name="Mysql4"><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="77e2f7fce4418f85f1dafba43a433ba7"/></dir></dir><file name="Setup.php" hash="a46e28853cc29d7ba38a168342f60b59"/></dir></dir><file name="Sinch.php" hash="7fec68dd6fc0e9eb2426f6a950289a2b"/><dir name="System"><dir name="Config"><file name="CatRewrite.php" hash="9e23b203bd4af59065776696794f105a"/><file name="ProdRewrite.php" hash="a93e7bfa552cb18886c06c7404d41e8a"/><file name="ServerList.php" hash="26be40d03d5ccfeda0745287b30a2d45"/><file name="Subscription.php" hash="2909e8dfe199e768fe763561cca68ac5"/></dir></dir><file name="config.php" hash="239f67e965eb9dbe0ada9af8f2112f13"/></dir><dir name="controllers"><file name="AjaxController.php" hash="388673c76cae1930317331ba66bf34b7"/><file name="IndexController.php" hash="54610343286f65e5ab6c640101194502"/><file name="ProductController.php" hash="f1a19d5b9516fe1896a74adafb005953"/><file name="SplitfeaturesController.php" hash="201702c1b94fdea2bb8f8f09ad96508e"/></dir><dir name="etc"><file name="api.xml" hash="1dc79cd5b99223d85af2844c6a5afa1f"/><file name="config.xml" hash="a2619363e13342556598f37482d6adec"/><file name="system.xml" hash="68a943e5220ad7feca8c4245a5103ae6"/></dir><file name="sinch_import_start_ajax.php" hash="63c0e899e6eca398b1ddc14a35c808ab"/><dir name="sql"><dir name="sinchimport_setup"><file name="filter_sinch_products_s.sql" hash="2045ee722c506ddff3f3eed6670ef0fd"/><file name="mysql4-install-0.1.0.php" hash="021075cbdb3eaeb7d9fd7ba180890ce6"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="692a09651695ccf64d3ed53b27ad717c"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="78594903bc046fbb614bfbd1114932d0"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="195cf0b895a81c56998edaf64d126772"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="8ad807df07fdbcc4b7a109657a1ca283"/><file name="mysql4-upgrade-0.1.4-0.1.5.php" hash="3c17013f1f3c5d4557dcc2237c1bbbba"/><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="26dc09878c99b74a40d6b9a9453b7179"/><file name="mysql4-upgrade-0.1.6-0.1.7.php" hash="8841960cdf8963835bd80d75c86629b5"/><file name="mysql4-upgrade-0.1.7-0.1.8.php" hash="2b3cb5b622e9ebd09ab7bf2ebaeba708"/><file name="mysql4-upgrade-0.1.8-0.1.9.php" hash="7658aa8e2537389bfcff4b5ef042c072"/><file name="mysql4-upgrade-0.1.9-0.2.0.php" hash="42df5d1209927b151a0ac6277f6f3d2a"/><file name="mysql4-upgrade-0.2.0-0.2.1.php" hash="4cd19f14fc16f2abe65afcd5abebd8c9"/><file name="mysql4-upgrade-0.2.1-0.2.2.php" hash="5570380209d8fd264e7eec8c96d58923"/><file name="mysql4-upgrade-3.0.0-3.0.1.php" hash="d1af2c55095f76852036782cc47fa0d0"/><file name="mysql4-upgrade-3.0.1-3.0.2.php" hash="286346407849a1953ce55c5ade1fb71a"/><file name="mysql4-upgrade-3.0.2-3.0.3.php" hash="a49d67bb4a32191ca1a5fa127062fc76"/><file name="mysql4-upgrade-3.0.3-3.0.4.php" hash="dc1707560d11c70d6981280f9e4d5d08"/></dir></dir><file name="stock_price_sinch_import_start_ajax.php" hash="f30d98651c6efac79ee76120fac4e49b"/></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="86d65ea9bea9c37cfb20f593095995db"/></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>
18
  <compatible/>
19
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>stockinthechannel2012</name>
4
+ <version>2.2.0</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.2.0:&#xD;
13
+ * Major update, fixes and improvements, courtesy of Neo</notes>
14
+ <authors><author><name>stockinchannel</name><user>stockinchannel</user><email>marketing@stockinthechannel.com</email></author></authors>
15
+ <date>2016-05-03</date>
16
+ <time>11:54:45</time>
17
+ <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="4c211bb7854afd6f8830d8b9bdf22c2d"/></dir></dir></dir><file name="Backupbutton.php" hash="8ee8b864e925f28fff7d818f5eddf6fa"/><file name="Importenvironment.php" hash="1c98dbc41e243bd2c899817ce91adfe7"/><file name="Importhistory.php" hash="9f1bda290333c3015b54ef3802857a3f"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="dd62c6b2546e387695b05307dbe7c07a"/></dir><file name="View.php" hash="3be74157878d08cf17598708b4d61dab"/></dir><file name="List.php" hash="18b73e0f2d7959fa9af99f7fce8a60f4"/><dir name="Product"><dir name="View"><file name="Media.php" hash="f82030a12d1d41dfc75647a56b691dcb"/></dir></dir><file name="Startimportbutton.php" hash="b7564c48d52fc777abe1c5e87f63ad02"/><file name="Startstockpriceimportbutton.php" hash="f295d3d570114d0eb71238fb9c51dfa4"/></dir><dir name="Helper"><file name="Data.php" hash="6ba3ed5d098de4d1d90f5ce49bffbed2"/><file name="Getdata.php" hash="b966ec1c48a70956c980627af49d2078"/><file name="Image.php" hash="38dd206e1a90fac4b11ea340045a7b33"/></dir><dir name="Model"><file name="Api.php" hash="9c563069c93b6010597114a32304e44d"/><file name="Backup.php" hash="f9547de1ad92cba2972c98624e38d02a"/><file name="Category.php" hash="24023d361652a68627a28a20b9229684"/><file name="Image.php" hash="7388b5396d4fd385e203e15e940c970d"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="71b361862365856da549b0fbd354b84f"/><file name="Price.php" hash="f99b582a270977389dc94c2460fe7b22"/></dir></dir><file name="Layer.php" hash="a0b9a98e99e3da8b6d4b19093eb646a5"/><file name="Product.php" hash="de3db0ad9ab43ec060f906a66e7ac2ee"/><dir name="Resource"><dir name="Layer"><dir name="Filter"><file name="Price.php" hash="f7fcd3372e0c6ecc8ad8215e57679afa"/></dir></dir><dir name="Mysql4"><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="cf01cdec127a1d4fae516c4bf6d107de"/></dir></dir><file name="Setup.php" hash="a46e28853cc29d7ba38a168342f60b59"/></dir></dir><file name="Sinch.php" hash="ab58a74c56f7acf00846b70984af3afd"/><dir name="System"><dir name="Config"><file name="CatRewrite.php" hash="9e23b203bd4af59065776696794f105a"/><file name="ProdRewrite.php" hash="a93e7bfa552cb18886c06c7404d41e8a"/><file name="ServerList.php" hash="8a12e5809a5947456254975a3e291db1"/><file name="Subscription.php" hash="2909e8dfe199e768fe763561cca68ac5"/></dir></dir><file name="config.php" hash="73aeed9c20ed55810b9cf4f64a6401bb"/></dir><dir name="controllers"><file name="AjaxController.php" hash="388673c76cae1930317331ba66bf34b7"/><file name="BackupController.php" hash="146a6acf52e63014c9c6f0a2018b8634"/><file name="IndexController.php" hash="54610343286f65e5ab6c640101194502"/><file name="ProductController.php" hash="f1a19d5b9516fe1896a74adafb005953"/><file name="SplitfeaturesController.php" hash="201702c1b94fdea2bb8f8f09ad96508e"/></dir><dir name="etc"><file name="api.xml" hash="1dc79cd5b99223d85af2844c6a5afa1f"/><file name="config.xml" hash="adf0e505aeb2b084a139619d057ead7d"/><file name="system.xml" hash="14c1445e542f4f538f120da0358379df"/></dir><file name="sinch_import_start_ajax.php" hash="63c0e899e6eca398b1ddc14a35c808ab"/><dir name="sql"><dir name="sinchimport_setup"><file name="filter_sinch_products_s.sql" hash="2045ee722c506ddff3f3eed6670ef0fd"/><file name="mysql4-install-0.1.0.php" hash="021075cbdb3eaeb7d9fd7ba180890ce6"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="692a09651695ccf64d3ed53b27ad717c"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="78594903bc046fbb614bfbd1114932d0"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="195cf0b895a81c56998edaf64d126772"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="8ad807df07fdbcc4b7a109657a1ca283"/><file name="mysql4-upgrade-0.1.4-0.1.5.php" hash="3c17013f1f3c5d4557dcc2237c1bbbba"/><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="26dc09878c99b74a40d6b9a9453b7179"/><file name="mysql4-upgrade-0.1.6-0.1.7.php" hash="8841960cdf8963835bd80d75c86629b5"/><file name="mysql4-upgrade-0.1.7-0.1.8.php" hash="2b3cb5b622e9ebd09ab7bf2ebaeba708"/><file name="mysql4-upgrade-0.1.8-0.1.9.php" hash="7658aa8e2537389bfcff4b5ef042c072"/><file name="mysql4-upgrade-0.1.9-0.2.0.php" hash="42df5d1209927b151a0ac6277f6f3d2a"/><file name="mysql4-upgrade-0.2.0-0.2.1.php" hash="4cd19f14fc16f2abe65afcd5abebd8c9"/><file name="mysql4-upgrade-0.2.1-0.2.2.php" hash="5570380209d8fd264e7eec8c96d58923"/><file name="mysql4-upgrade-3.0.0-3.0.1.php" hash="d1af2c55095f76852036782cc47fa0d0"/><file name="mysql4-upgrade-3.0.1-3.0.2.php" hash="286346407849a1953ce55c5ade1fb71a"/><file name="mysql4-upgrade-3.0.2-3.0.3.php" hash="a49d67bb4a32191ca1a5fa127062fc76"/><file name="mysql4-upgrade-3.0.3-3.0.4.php" hash="dc1707560d11c70d6981280f9e4d5d08"/><file name="mysql4-upgrade-3.0.4-3.0.5.php" hash="0ff614bb3c38e6bdde51f1188b7f88f0"/><file name="mysql4-upgrade-3.0.5-3.0.6.php" hash="4842abed88a40a879d2f728140e5e93a"/><file name="storeProcedureGenerator.php" hash="9a17a4ab896cd8e22c09b94cad43272f"/></dir></dir><file name="stock_price_sinch_import_start_ajax.php" hash="f30d98651c6efac79ee76120fac4e49b"/></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="86d65ea9bea9c37cfb20f593095995db"/></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>
18
  <compatible/>
19
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>