Version Notes
Version 2.0.4:
* Change the way the MySQL connection is initialized to resolve an edge case where some systems wouldn't accept the LOCAL INFILE flag at that point
* Fix the calls to mysqli_real_escape_string to include the connection object as required
* Remove the currently unused Sinch_new_code.php from Model
Download this release
Release Info
Developer | stockinchannel |
Extension | stockinthechannel2012 |
Version | 2.0.4 |
Comparing to | |
See all releases |
Code changes from version 2.0.3 to 2.0.4
app/code/local/Bintime/Sinchimport/Model/Sinch.php
CHANGED
@@ -5489,7 +5489,7 @@ echo("\n replaceMagentoProductsMultistore 41\n");
|
|
5489 |
)(
|
5490 |
SELECT
|
5491 |
max(option_id) as option_id,
|
5492 |
-
"."'".mysqli_real_escape_string($row['manufacturer_name'])."'
|
5493 |
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
|
5494 |
WHERE attribute_id=".$this->attributes['manufacturer']."
|
5495 |
)
|
@@ -8584,20 +8584,17 @@ STP DELETE*/
|
|
8584 |
#################################################################################################
|
8585 |
|
8586 |
private function db_connect() {
|
8587 |
-
|
8588 |
// $connection = Mage::getModel('core/resource')->getConnection('core_write');
|
8589 |
$dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
|
8590 |
-
|
8591 |
-
|
8592 |
-
|
8593 |
-
|
8594 |
-
|
8595 |
-
}else{
|
8596 |
die("Can't select the database: " . mysqli_error($this->db));
|
8597 |
}
|
8598 |
}else{
|
8599 |
die("Could not connect: " . mysqli_error($this->db));
|
8600 |
-
|
8601 |
}
|
8602 |
|
8603 |
}
|
@@ -8613,7 +8610,6 @@ STP DELETE*/
|
|
8613 |
} else {
|
8614 |
return $result;
|
8615 |
}
|
8616 |
-
|
8617 |
return $result;
|
8618 |
}
|
8619 |
##################################################################################################
|
@@ -8679,7 +8675,7 @@ STP DELETE*/
|
|
8679 |
$value=$this->valid_char($row['value']);
|
8680 |
if($value!='' and $value!=$row['value']){
|
8681 |
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
|
8682 |
-
SET value='".mysqli_real_escape_string($value)."'
|
8683 |
WHERE entity_id=".$row['entity_id']."
|
8684 |
AND entity_type_id=".$entity_type_id."
|
8685 |
AND attribute_id=".$attribute_id);
|
@@ -8946,7 +8942,7 @@ STP DELETE*/
|
|
8946 |
#################################################################################################
|
8947 |
function set_import_error_reporting_message($message){
|
8948 |
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
8949 |
-
SET error_report_message='".mysqli_real_escape_string($message)."'
|
8950 |
WHERE id=".$this->current_import_status_statistic_id);
|
8951 |
}
|
8952 |
#################################################################################################
|
5489 |
)(
|
5490 |
SELECT
|
5491 |
max(option_id) as option_id,
|
5492 |
+
"."'".mysqli_real_escape_string($this->db, $row['manufacturer_name'])."'
|
5493 |
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
|
5494 |
WHERE attribute_id=".$this->attributes['manufacturer']."
|
5495 |
)
|
8584 |
#################################################################################################
|
8585 |
|
8586 |
private function db_connect() {
|
|
|
8587 |
// $connection = Mage::getModel('core/resource')->getConnection('core_write');
|
8588 |
$dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
|
8589 |
+
$dbConn = mysqli_init();
|
8590 |
+
mysqli_options($dbConn, MYSQLI_OPT_LOCAL_INFILE, true);
|
8591 |
+
if (mysqli_real_connect($dbConn, $dbConf->host, $dbConf->username, $dbConf->password)) {
|
8592 |
+
$this->db = $dbConn;
|
8593 |
+
if(!mysqli_select_db($this->db, $dbConf->dbname)){
|
|
|
8594 |
die("Can't select the database: " . mysqli_error($this->db));
|
8595 |
}
|
8596 |
}else{
|
8597 |
die("Could not connect: " . mysqli_error($this->db));
|
|
|
8598 |
}
|
8599 |
|
8600 |
}
|
8610 |
} else {
|
8611 |
return $result;
|
8612 |
}
|
|
|
8613 |
return $result;
|
8614 |
}
|
8615 |
##################################################################################################
|
8675 |
$value=$this->valid_char($row['value']);
|
8676 |
if($value!='' and $value!=$row['value']){
|
8677 |
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
|
8678 |
+
SET value='".mysqli_real_escape_string($this->db, $value)."'
|
8679 |
WHERE entity_id=".$row['entity_id']."
|
8680 |
AND entity_type_id=".$entity_type_id."
|
8681 |
AND attribute_id=".$attribute_id);
|
8942 |
#################################################################################################
|
8943 |
function set_import_error_reporting_message($message){
|
8944 |
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
8945 |
+
SET error_report_message='".mysqli_real_escape_string($this->db, $message)."'
|
8946 |
WHERE id=".$this->current_import_status_statistic_id);
|
8947 |
}
|
8948 |
#################################################################################################
|
app/code/local/Bintime/Sinchimport/Model/Sinch_new_code.php
DELETED
@@ -1,7177 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
ini_set('memory_limit','256M');
|
4 |
-
$dir = Mage::getBaseDir('code')."/local/Bintime/Sinchimport/Model";//dirname(__FILE__);
|
5 |
-
require_once ($dir.'/config.php');
|
6 |
-
|
7 |
-
class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
|
8 |
-
var
|
9 |
-
$connection,
|
10 |
-
$varDir,
|
11 |
-
$shellDir,
|
12 |
-
$files,
|
13 |
-
$attributes,
|
14 |
-
$db,
|
15 |
-
$lang_id,
|
16 |
-
$debug_mode=1;
|
17 |
-
private $productDescriptionList = array();
|
18 |
-
private $specifications;
|
19 |
-
private $productDescription;
|
20 |
-
private $fullProductDescription;
|
21 |
-
private $lowPicUrl;
|
22 |
-
private $highPicUrl;
|
23 |
-
private $errorMessage;
|
24 |
-
private $galleryPhotos = array();
|
25 |
-
private $productName;
|
26 |
-
private $relatedProducts = array();
|
27 |
-
private $errorSystemMessage; //depricated
|
28 |
-
private $sinchProductId;
|
29 |
-
private $_productEntityTypeId = 0;
|
30 |
-
private $defaultAttributeSetId = 0;
|
31 |
-
private $field_terminated_char;
|
32 |
-
private $import_status_table;
|
33 |
-
private $import_status_statistic_table;
|
34 |
-
private $current_import_status_statistic_id;
|
35 |
-
private $import_log_table;
|
36 |
-
private $_attributeId;
|
37 |
-
private $_categoryEntityTypeId;
|
38 |
-
private $_categoryDefault_attribute_set_id;
|
39 |
-
private $_root_cat;
|
40 |
-
private $import_run_type = 'MANUAL';
|
41 |
-
private $_ignore_category_features = false;
|
42 |
-
private $_ignore_product_features = false;
|
43 |
-
private $_ignore_product_related = false;
|
44 |
-
private $_ignore_restricted_values = false;
|
45 |
-
public $php_run_string;
|
46 |
-
public $price_breaks_filter;
|
47 |
-
|
48 |
-
#################################################################################################
|
49 |
-
|
50 |
-
function __construct(){
|
51 |
-
|
52 |
-
$this->import_status_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status');
|
53 |
-
$this->import_status_statistic_table=Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic');
|
54 |
-
$this->import_log_table="stINch_import_log";
|
55 |
-
|
56 |
-
$this->php_run_string=PHP_RUN_STRING;
|
57 |
-
$this->price_breaks_filter=PRICE_BREAKS;
|
58 |
-
/*$this->db_connect();
|
59 |
-
$res = $this->db_do("select languages_id from languages where code='".LANG_CODE."'");
|
60 |
-
$row = mysqli_fetch_assoc($res);
|
61 |
-
$this->lang_id = $row['languages_id'];
|
62 |
-
*/
|
63 |
-
$this->varDir = TEMPORARY_DIRECTORY_FOR_STORING_FILES;
|
64 |
-
$this->shellDir = SHELL_DIRECTORY_FOR_INDEXER;
|
65 |
-
$this->connection=$this->db_connect();
|
66 |
-
$this->createTemporaryImportDerictory();
|
67 |
-
$this->_logFile="Sinch.log";
|
68 |
-
$this->_LOG("constructor");
|
69 |
-
$this->files=array(
|
70 |
-
FILE_CATEGORIES,
|
71 |
-
FILE_CATEGORIES_FEATURES,
|
72 |
-
FILE_DISTRIBUTORS,
|
73 |
-
FILE_EANCODES,
|
74 |
-
FILE_MANUFACTURERS,
|
75 |
-
FILE_PRODUCT_FEATURES,
|
76 |
-
FILE_PRODUCTS,
|
77 |
-
FILE_RELATED_PRODUCTS,
|
78 |
-
FILE_RESTRICTED_VALUES,
|
79 |
-
FILE_STOCK_AND_PRICES,
|
80 |
-
FILE_PRODUCTS_PICTURES_GALLERY
|
81 |
-
);
|
82 |
-
$this->attributes['manufacturer']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getId();
|
83 |
-
$this->attributes['name']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('name')->getFirstItem()->getId();
|
84 |
-
$this->attributes['is_active']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('is_active')->getFirstItem()->getId();
|
85 |
-
$this->attributes['include_in_menu']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('include_in_menu')->getFirstItem()->getId();
|
86 |
-
$this->attributes['url_key']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('url_key')->getFirstItem()->getId();
|
87 |
-
$this->attributes['display_mode']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('display_mode')->getFirstItem()->getId();
|
88 |
-
$this->attributes['status']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('status')->getFirstItem()->getId();
|
89 |
-
$this->attributes['visibility']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('visibility')->getFirstItem()->getId();
|
90 |
-
$this->attributes['price']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('price')->getFirstItem()->getId();
|
91 |
-
$this->attributes['cost']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('cost')->getFirstItem()->getId();
|
92 |
-
$this->attributes['weight']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('weight')->getFirstItem()->getId();
|
93 |
-
$this->attributes['tax_class_id']=Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('tax_class_id')->getFirstItem()->getId();
|
94 |
-
|
95 |
-
$dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
|
96 |
-
// if($dataConf['field_terminated_char']){
|
97 |
-
// $this->field_terminated_char=$dataConf['field_terminated_char'];
|
98 |
-
// }else{
|
99 |
-
$this->field_terminated_char=DEFAULT_FILE_TERMINATED_CHAR;
|
100 |
-
// }
|
101 |
-
// $attributeOptions = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('manufacturer')->getFirstItem()->getSource()->getAllOptions(false);
|
102 |
-
// echo "<pre>"; print_r($attributeOptions); echo "</pre>";
|
103 |
-
}
|
104 |
-
|
105 |
-
#################################################################################################
|
106 |
-
function cron_start_import(){
|
107 |
-
$this->_LOG("Start import from cron");
|
108 |
-
$start_hr=Mage::getStoreConfig('sinchimport_root/sinch_cron/sinch_cron_time');
|
109 |
-
$now_hr=date('H');
|
110 |
-
$this->_LOG("Now $now_hr hr, scheduler time is $start_hr hr");
|
111 |
-
|
112 |
-
if($start_hr==$now_hr){
|
113 |
-
$this->run_sinch_import();
|
114 |
-
}else{
|
115 |
-
$this->_LOG(" it's NOT time for SINCH ");
|
116 |
-
}
|
117 |
-
|
118 |
-
$this->_LOG("Finish import from cron");
|
119 |
-
|
120 |
-
}
|
121 |
-
################################################################################################
|
122 |
-
function cron_start_full_import(){
|
123 |
-
$this->import_run_type='CRON';
|
124 |
-
$this->run_sinch_import();
|
125 |
-
}
|
126 |
-
################################################################################################
|
127 |
-
function cron_start_stock_price_import(){
|
128 |
-
$this->import_run_type='CRON';
|
129 |
-
$this->run_stock_price_sinch_import();
|
130 |
-
}
|
131 |
-
#################################################################################################
|
132 |
-
function is_imort_not_run(){
|
133 |
-
$q="SELECT IS_FREE_LOCK('sinchimport') as getlock";
|
134 |
-
$quer=$this->db_do($q);
|
135 |
-
$row=mysqli_fetch_array($quer);
|
136 |
-
return $row['getlock'];
|
137 |
-
}
|
138 |
-
#################################################################################################
|
139 |
-
function check_store_procedure_exist(){
|
140 |
-
$dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
|
141 |
-
$q='SHOW PROCEDURE STATUS LIKE "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'"';
|
142 |
-
$quer=$this->db_do($q);
|
143 |
-
$result=false;
|
144 |
-
While($row=mysqli_fetch_array($quer)){
|
145 |
-
if(($row['Name']==Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s')) && ($row['Db']==$dbConf->dbname)){
|
146 |
-
$result = true;
|
147 |
-
}
|
148 |
-
}
|
149 |
-
return $result;
|
150 |
-
}
|
151 |
-
#################################################################################################
|
152 |
-
function check_db_privileges(){
|
153 |
-
$q='SHOW PRIVILEGES';
|
154 |
-
$quer=$this->db_do($q);
|
155 |
-
while($row=mysqli_fetch_array($quer)){
|
156 |
-
if($row['Privilege']=='File' && $row['Context']=='File access on server'){
|
157 |
-
return true;
|
158 |
-
}
|
159 |
-
}
|
160 |
-
return false;
|
161 |
-
}
|
162 |
-
#################################################################################################
|
163 |
-
function check_local_infile(){
|
164 |
-
$q='SHOW VARIABLES LIKE "local_infile"';
|
165 |
-
$quer=$this->db_do($q);
|
166 |
-
$row=mysqli_fetch_array($quer);
|
167 |
-
if($row['Variable_name']=='local_infile' && $row['Value']=="ON"){
|
168 |
-
return true;
|
169 |
-
}else{
|
170 |
-
return false;
|
171 |
-
}
|
172 |
-
}
|
173 |
-
#################################################################################################
|
174 |
-
function is_full_import_have_been_run(){
|
175 |
-
$q="SELECT COUNT(*) AS cnt
|
176 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_import_status_statistic')."
|
177 |
-
WHERE import_type='FULL' AND global_status_import='Successful'";
|
178 |
-
$quer=$this->db_do($q);
|
179 |
-
$row=mysqli_fetch_array($quer);
|
180 |
-
if($row['cnt']>0){
|
181 |
-
return true;
|
182 |
-
}else{
|
183 |
-
return false;
|
184 |
-
}
|
185 |
-
}
|
186 |
-
#################################################################################################
|
187 |
-
function run_sinch_import(){
|
188 |
-
$safe_mode_set = ini_get('safe_mode');
|
189 |
-
|
190 |
-
$this->InitImportStatuses('FULL');
|
191 |
-
if($safe_mode_set ){
|
192 |
-
$this->_LOG('safe_mode is enable. import stoped.');
|
193 |
-
$this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
|
194 |
-
exit;
|
195 |
-
}
|
196 |
-
$store_proc=$this->check_store_procedure_exist();
|
197 |
-
|
198 |
-
if(!$store_proc){
|
199 |
-
$this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
|
200 |
-
$this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
|
201 |
-
exit;
|
202 |
-
}
|
203 |
-
|
204 |
-
$file_privileg=$this->check_db_privileges();
|
205 |
-
|
206 |
-
if(!$file_privileg){
|
207 |
-
$this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
|
208 |
-
$this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
|
209 |
-
exit;
|
210 |
-
}
|
211 |
-
$local_infile=$this->check_local_infile();
|
212 |
-
if(!$local_infile){
|
213 |
-
$this->_LOG("Loaddata option not set - please check the documentation on how to fix this. Add this string to 'set-variable=local-infile=0' in '/etc/my.cnf'");
|
214 |
-
$this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
|
215 |
-
exit;
|
216 |
-
}
|
217 |
-
|
218 |
-
if($this->is_imort_not_run()){
|
219 |
-
try{
|
220 |
-
//$this->InitImportStatuses();
|
221 |
-
$q="SELECT GET_LOCK('sinchimport', 30)";
|
222 |
-
$quer=$this->db_do($q);
|
223 |
-
$import=$this;
|
224 |
-
$import->addImportStatus('Start Import');
|
225 |
-
echo "Upload Files <br>";
|
226 |
-
$import->UploadFiles();
|
227 |
-
$import->addImportStatus('Upload Files');
|
228 |
-
|
229 |
-
echo "Parse Categories <br>";
|
230 |
-
$coincidence = $import->ParseCategories();
|
231 |
-
$import->addImportStatus('Parse Categories');
|
232 |
-
|
233 |
-
|
234 |
-
//$import->_cleanCateoryProductFlatTable();
|
235 |
-
//$import->runIndexer();
|
236 |
-
echo("\n\n\n==================RETURN=================\n\n\n");
|
237 |
-
|
238 |
-
|
239 |
-
echo "Parse Category Features <br>";
|
240 |
-
$import->ParseCategoryFeatures();
|
241 |
-
$import->addImportStatus('Parse Category Features');
|
242 |
-
|
243 |
-
|
244 |
-
echo "Parse Distributors <br>";
|
245 |
-
$import->ParseDistributors();
|
246 |
-
$import->addImportStatus('Parse Distributors');
|
247 |
-
|
248 |
-
|
249 |
-
echo "Parse EAN Codes <br>";
|
250 |
-
$import->ParseEANCodes();
|
251 |
-
$import->addImportStatus('Parse EAN Codes');
|
252 |
-
|
253 |
-
|
254 |
-
echo "Parse Manufacturers <br>";
|
255 |
-
$import->ParseManufacturers();
|
256 |
-
$import->addImportStatus('Parse Manufacturers');
|
257 |
-
|
258 |
-
echo "Parse Related Products <br>";
|
259 |
-
$import->ParseRelatedProducts();
|
260 |
-
$import->addImportStatus('Parse Related Products');
|
261 |
-
|
262 |
-
echo "Parse Product Features <br>";
|
263 |
-
$import->ParseProductFeatures();
|
264 |
-
$import->addImportStatus('Parse Product Features');
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
echo "Parse Products <br>";
|
269 |
-
$import->ParseProducts($coincidence);
|
270 |
-
$import->addImportStatus('Parse Products');
|
271 |
-
//return;
|
272 |
-
echo "Parse Pictures Gallery";
|
273 |
-
$import->ParseProductsPicturesGallery();
|
274 |
-
$import->addImportStatus('Parse Pictures Gallery');
|
275 |
-
|
276 |
-
echo "Parse Restricted Values <br>";
|
277 |
-
$import->ParseRestrictedValues();
|
278 |
-
$import->addImportStatus('Parse Restricted Values');
|
279 |
-
|
280 |
-
echo "Parse Stock And Prices <br>";
|
281 |
-
$import->ParseStockAndPrices();
|
282 |
-
$import->addImportStatus('Parse Stock And Prices');
|
283 |
-
|
284 |
-
|
285 |
-
Mage::log("Finish Sinch import", null, $this->_logFile);
|
286 |
-
echo "Finish Sinch import<br>";
|
287 |
-
|
288 |
-
Mage::log("Start cleanin Sinch cache<br>", null, $this->_logFile);
|
289 |
-
echo "Start cleanin Sinch cache<br>";
|
290 |
-
Mage::app()->getCacheInstance()->cleanType('block_html');
|
291 |
-
/*
|
292 |
-
$indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
|
293 |
-
if ($indexProcess) {
|
294 |
-
$indexProcess->reindexAll();
|
295 |
-
}
|
296 |
-
*/
|
297 |
-
|
298 |
-
Mage::log("Start indexing Sinch features for filters", null, $this->_logFile);
|
299 |
-
echo "Start indexing Sinch features for filters<br>";
|
300 |
-
|
301 |
-
|
302 |
-
$resource = Mage::getResourceModel('sinchimport/layer_filter_feature');
|
303 |
-
$resource->splitProductsFeature(null);
|
304 |
-
|
305 |
-
Mage::log("Finish indexing Sinch features for filters", null, $this->_logFile);
|
306 |
-
$import->addImportStatus('Generate category filters');
|
307 |
-
echo "Finish indexing Sinch features for filters<br>";
|
308 |
-
|
309 |
-
Mage::log("Start indexing data", null, $this->_logFile);
|
310 |
-
echo "Start indexing data";
|
311 |
-
$import->_cleanCateoryProductFlatTable();
|
312 |
-
$import->runIndexer();
|
313 |
-
Mage::log("Finish indexing data", null, $this->_logFile);
|
314 |
-
$import->addImportStatus('Indexing data', 1);
|
315 |
-
echo "Finish indexing data";
|
316 |
-
|
317 |
-
$q="SELECT RELEASE_LOCK('sinchimport')";
|
318 |
-
$quer=$this->db_do($q);
|
319 |
-
}catch (Exception $e) {
|
320 |
-
$this->set_import_error_reporting_message($e);
|
321 |
-
}
|
322 |
-
}
|
323 |
-
else{
|
324 |
-
Mage::log("Sinchimport already run", null, $this->_logFile);
|
325 |
-
echo "Sinchimport already run<br>";
|
326 |
-
|
327 |
-
}
|
328 |
-
|
329 |
-
}
|
330 |
-
#################################################################################################
|
331 |
-
function run_stock_price_sinch_import(){
|
332 |
-
$safe_mode_set = ini_get('safe_mode');
|
333 |
-
|
334 |
-
$this->InitImportStatuses('PRICE STOCK');
|
335 |
-
if($safe_mode_set ){
|
336 |
-
$this->_LOG('safe_mode is enable. import stoped.');
|
337 |
-
$this->set_import_error_reporting_message('Safe_mode is enabled. Please check the documentation on how to fix this. Import stopped.');
|
338 |
-
exit;
|
339 |
-
}
|
340 |
-
$store_proc=$this->check_store_procedure_exist();
|
341 |
-
|
342 |
-
if(!$store_proc){
|
343 |
-
$this->_LOG('store prcedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. import stoped.');
|
344 |
-
$this->set_import_error_reporting_message('Stored procedure "'.Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s').'" is absent in this database. Import stopped.');
|
345 |
-
exit;
|
346 |
-
}
|
347 |
-
|
348 |
-
$file_privileg=$this->check_db_privileges();
|
349 |
-
|
350 |
-
if(!$file_privileg){
|
351 |
-
$this->_LOG("Loaddata option not set - please check the documentation on how to fix this. You dan't have privileges for LOAD DATA.");
|
352 |
-
$this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
|
353 |
-
exit;
|
354 |
-
}
|
355 |
-
$local_infile=$this->check_local_infile();
|
356 |
-
if(!$local_infile){
|
357 |
-
$this->_LOG("Loaddata option not set - please check the documentation on how to fix this. Add this string to 'set-variable=local-infile=0' in '/etc/my.cnf'");
|
358 |
-
$this->set_import_error_reporting_message("Loaddata option not set - please check the documentation on how to fix this. Import stopped.");
|
359 |
-
exit;
|
360 |
-
}
|
361 |
-
|
362 |
-
if($this->is_imort_not_run() && $this->is_full_import_have_been_run()){
|
363 |
-
try{
|
364 |
-
//$this->InitImportStatuses();
|
365 |
-
$q="SELECT GET_LOCK('sinchimport', 30)";
|
366 |
-
$quer=$this->db_do($q);
|
367 |
-
$import=$this;
|
368 |
-
$import->addImportStatus('Stock Price Start Import');
|
369 |
-
echo "Upload Files <br>";
|
370 |
-
$this->files=array(
|
371 |
-
FILE_STOCK_AND_PRICES
|
372 |
-
);
|
373 |
-
|
374 |
-
$import->UploadFiles();
|
375 |
-
$import->addImportStatus('Stock Price Upload Files');
|
376 |
-
|
377 |
-
echo "Parse Stock And Prices <br>";
|
378 |
-
//exit;
|
379 |
-
$import->ParseStockAndPrices();
|
380 |
-
$import->addImportStatus('Stock Price Parse Products');
|
381 |
-
|
382 |
-
|
383 |
-
Mage::log("Finish Stock & Price Sinch import", null, $this->_logFile);
|
384 |
-
echo "Finish Stock & Price Sinch import<br>";
|
385 |
-
|
386 |
-
Mage::log("Start indexing Stock & Price", null, $this->_logFile);
|
387 |
-
echo "Start indexing Stock & Price<br>";
|
388 |
-
$import->_cleanCateoryProductFlatTable();
|
389 |
-
$import->runStockPriceIndexer();
|
390 |
-
Mage::log("Finish indexing Stock & Price", null, $this->_logFile);
|
391 |
-
$import->addImportStatus('Stock Price Indexing data');
|
392 |
-
$import->addImportStatus('Stock Price Finish import', 1);
|
393 |
-
echo "Finish indexing Stock & Price<br>";
|
394 |
-
|
395 |
-
$q="SELECT RELEASE_LOCK('sinchimport')";
|
396 |
-
$quer=$this->db_do($q);
|
397 |
-
}catch (Exception $e) {
|
398 |
-
$this->set_import_error_reporting_message($e);
|
399 |
-
}
|
400 |
-
}
|
401 |
-
else{
|
402 |
-
if(!$this->is_imort_not_run()){
|
403 |
-
Mage::log("Sinchimport already run", null, $this->_logFile);
|
404 |
-
echo "Sinchimport already run<br>";
|
405 |
-
}else{
|
406 |
-
Mage::log("Full import have never finished with success", null, $this->_logFile);
|
407 |
-
echo "Full import have never finished with success<br>";
|
408 |
-
}
|
409 |
-
}
|
410 |
-
|
411 |
-
}
|
412 |
-
#################################################################################################
|
413 |
-
|
414 |
-
|
415 |
-
function UploadFiles(){
|
416 |
-
|
417 |
-
$this->_LOG("Start upload files");
|
418 |
-
$dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
|
419 |
-
$login=$dataConf['login'];
|
420 |
-
$passw=$dataConf['password'];
|
421 |
-
//return;//stepan tes//stepan tes//stepan testtt
|
422 |
-
if(!$login || !$passw){
|
423 |
-
$this->_LOG('ftp login or password dosent defined');
|
424 |
-
$this->set_import_error_reporting_message('FTP login or password has not been defined. Import stopped.');
|
425 |
-
exit;
|
426 |
-
|
427 |
-
}
|
428 |
-
$file_url_and_dir=$this->repl_ph(FILE_URL_AND_DIR, array('login' => $login,
|
429 |
-
'password'=> $passw
|
430 |
-
)
|
431 |
-
);
|
432 |
-
foreach ($this->files as $file) {
|
433 |
-
$this->_LOG("Copy ".$file_url_and_dir.$file." to ".$this->varDir.$file);
|
434 |
-
if(strstr($file_url_and_dir, 'ftp://')){
|
435 |
-
preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
|
436 |
-
//var_dump($match);
|
437 |
-
if($conn = ftp_connect($match[3])){
|
438 |
-
if(!ftp_login($conn, $login, $passw))
|
439 |
-
{
|
440 |
-
$this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
|
441 |
-
exit;
|
442 |
-
}
|
443 |
-
}
|
444 |
-
else{
|
445 |
-
$this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
|
446 |
-
exit;
|
447 |
-
}
|
448 |
-
if (!$this->wget ($file_url_and_dir.$file, $this->varDir.$file, 'system')){
|
449 |
-
$this->_LOG("wget Can't copy ".$file.", will use old one");
|
450 |
-
echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file.", will use old one<br>";
|
451 |
-
}
|
452 |
-
}
|
453 |
-
else{
|
454 |
-
if(!copy($file_url_and_dir.$file, $this->varDir.$file)){
|
455 |
-
$this->_LOG("copy Can't copy ".$file.", will use old one");
|
456 |
-
echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file." will use old one<br>";
|
457 |
-
}
|
458 |
-
}
|
459 |
-
exec("chmod a+rw ".$this->varDir.$file);
|
460 |
-
if(!filesize($this->varDir.$file)){
|
461 |
-
if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES){
|
462 |
-
$this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
|
463 |
-
$this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
|
464 |
-
$this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
|
465 |
-
|
466 |
-
exit;
|
467 |
-
}else{
|
468 |
-
if($file==FILE_CATEGORIES_FEATURES){
|
469 |
-
$this->_LOG("Can't copy ".FILE_CATEGORIES_FEATURES." file ignored" );
|
470 |
-
$this->_ignore_category_features=true;
|
471 |
-
}elseif($file==FILE_PRODUCT_FEATURES){
|
472 |
-
$this->_LOG("Can't copy ".FILE_PRODUCT_FEATURES." file ignored" );
|
473 |
-
$this->_ignore_product_features=true;
|
474 |
-
}elseif($file==FILE_RELATED_PRODUCTS){
|
475 |
-
$this->_LOG("Can't copy ".FILE_RELATED_PRODUCTS." file ignored" );
|
476 |
-
$this->_ignore_product_related=true;
|
477 |
-
}elseif($file==FILE_RESTRICTED_VALUES){
|
478 |
-
$this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
|
479 |
-
$this->_ignore_restricted_values=true;
|
480 |
-
}
|
481 |
-
}
|
482 |
-
}
|
483 |
-
}
|
484 |
-
|
485 |
-
$this->_LOG("Finish upload files");
|
486 |
-
}
|
487 |
-
#################################################################################################
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
################################################################################################################################################################
|
492 |
-
function ParseCategories()
|
493 |
-
{
|
494 |
-
|
495 |
-
$dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
|
496 |
-
$im_type = $dataConf['replace_category'];
|
497 |
-
$parse_file = $this->varDir.FILE_CATEGORIES;
|
498 |
-
$field_terminated_char = $this->field_terminated_char;
|
499 |
-
|
500 |
-
if(filesize($parse_file))
|
501 |
-
{
|
502 |
-
$this->_LOG("Start parse ".FILE_CATEGORIES);
|
503 |
-
|
504 |
-
$this->_getCategoryEntityTypeIdAndDefault_attribute_set_id();
|
505 |
-
|
506 |
-
$categories_temp = Mage::getSingleton('core/resource')->getTableName('categories_temp');
|
507 |
-
$catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
|
508 |
-
$catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
|
509 |
-
$catalog_category_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int');
|
510 |
-
$stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
|
511 |
-
$stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
|
512 |
-
$stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
|
513 |
-
|
514 |
-
$_categoryEntityTypeId = $this->_categoryEntityTypeId;
|
515 |
-
$_categoryDefault_attribute_set_id = $this->_categoryDefault_attribute_set_id;
|
516 |
-
|
517 |
-
$name_attrid = $this->_getCategoryAttributeId('name');
|
518 |
-
$is_anchor_attrid = $this->_getCategoryAttributeId('is_anchor');
|
519 |
-
$image_attrid = $this->_getCategoryAttributeId('image');
|
520 |
-
$attr_url_key = $this->attributes['url_key'];
|
521 |
-
$attr_display_mode = $this->attributes['display_mode'];
|
522 |
-
$attr_is_active = $this->attributes['is_active'];
|
523 |
-
$attr_include_in_menu = $this->attributes['include_in_menu'];
|
524 |
-
|
525 |
-
|
526 |
-
$this->loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char);
|
527 |
-
$coincidence = $this->calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type);
|
528 |
-
|
529 |
-
/**if (!$this->check_loaded_data($parse_file, $categories_temp))
|
530 |
-
{
|
531 |
-
$inf = mysqli_info();
|
532 |
-
$this->set_import_error_reporting_message('The Stock In The Channel data files do not appear to be in the correct format. Check file'.$parse_file. "(LOAD DATA ... ".$inf.")");
|
533 |
-
exit;
|
534 |
-
}/**/
|
535 |
-
|
536 |
-
|
537 |
-
if (count($coincidence) == -1) // one store logic
|
538 |
-
{
|
539 |
-
|
540 |
-
if ($im_type == "REWRITE")
|
541 |
-
{
|
542 |
-
$root_cat = 2;
|
543 |
-
|
544 |
-
$root_cat = $this->truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
545 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
|
546 |
-
$name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu); // return $root_cat
|
547 |
-
}
|
548 |
-
else // if ($im_type == "MERGE")
|
549 |
-
{
|
550 |
-
$root_cat = $this->_getShopRootCategoryId();
|
551 |
-
}
|
552 |
-
|
553 |
-
$this->_root_cat = $root_cat;
|
554 |
-
|
555 |
-
$this->setCategorySettings($categories_temp, $root_cat);
|
556 |
-
$this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
|
557 |
-
$this->addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
558 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat);
|
559 |
-
}
|
560 |
-
else if (count($coincidence) >= 1) // multistore logic
|
561 |
-
{
|
562 |
-
echo("\n\n\n====================================\nmultistore logic\n====================================\n\n\n");
|
563 |
-
switch ($im_type)
|
564 |
-
{
|
565 |
-
case "REWRITE": $this->rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
566 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
567 |
-
$name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
|
568 |
-
$stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
|
569 |
-
break;
|
570 |
-
case "MERGE" : $this->mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
571 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
572 |
-
$name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
|
573 |
-
$stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
|
574 |
-
break;
|
575 |
-
default : $retcode = "error";
|
576 |
-
};
|
577 |
-
}
|
578 |
-
else
|
579 |
-
{
|
580 |
-
echo("error");
|
581 |
-
}
|
582 |
-
|
583 |
-
$this->_LOG("Finish parse ".FILE_CATEGORIES);
|
584 |
-
}
|
585 |
-
else
|
586 |
-
{
|
587 |
-
$this->_LOG("Wrong file ".$parse_file);
|
588 |
-
}
|
589 |
-
$this->_LOG(' ');
|
590 |
-
|
591 |
-
return $coincidence;
|
592 |
-
} // function ParseCategories()
|
593 |
-
################################################################################################################################################################
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
################################################################################################################################################################
|
601 |
-
private function loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char)
|
602 |
-
{
|
603 |
-
$this->db_do("DROP TABLE IF EXISTS $categories_temp");
|
604 |
-
|
605 |
-
$this->db_do("CREATE TABLE $categories_temp (
|
606 |
-
store_category_id int(11),
|
607 |
-
parent_store_category_id int(11),
|
608 |
-
category_name varchar(50),
|
609 |
-
order_number int(11),
|
610 |
-
is_hidden boolean,
|
611 |
-
products_within_this_category int(11),
|
612 |
-
products_within_sub_categories int(11),
|
613 |
-
categories_image varchar(255),
|
614 |
-
level int(10) NOT NULL default 0,
|
615 |
-
children_count int(11) NOT NULL default 0,
|
616 |
-
KEY(store_category_id),
|
617 |
-
KEY(parent_store_category_id)
|
618 |
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
619 |
-
");
|
620 |
-
|
621 |
-
/** NEW !!!
|
622 |
-
$this->db_do("
|
623 |
-
CREATE TABLE $categories_temp
|
624 |
-
(
|
625 |
-
store_category_id INT(11),
|
626 |
-
parent_store_category_id INT(11),
|
627 |
-
category_name VARCHAR(50),
|
628 |
-
order_number INT(11),
|
629 |
-
is_hidden BOOLEAN,
|
630 |
-
products_within_sub_categories INT(11),
|
631 |
-
products_within_this_category INT(11),
|
632 |
-
categories_image VARCHAR(255),
|
633 |
-
level INT(10) NOT NULL DEFAULT 0,
|
634 |
-
children_count INT(11) NOT NULL DEFAULT 0,
|
635 |
-
UNSPSC INT(10) NOT NULL DEFAULT 0,
|
636 |
-
TypeID INT(10) NOT NULL DEFAULT 0,
|
637 |
-
|
638 |
-
KEY(store_category_id),
|
639 |
-
KEY(parent_store_category_id)
|
640 |
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
641 |
-
/**/
|
642 |
-
|
643 |
-
$this->db_do("
|
644 |
-
LOAD DATA LOCAL INFILE '$parse_file' INTO TABLE $categories_temp
|
645 |
-
FIELDS TERMINATED BY '$field_terminated_char' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES");
|
646 |
-
|
647 |
-
$this->db_do("ALTER TABLE $categories_temp ADD COLUMN UNSPSC INT(10) NOT NULL DEFAULT 0");
|
648 |
-
$this->db_do("ALTER TABLE $categories_temp ADD COLUMN RootName VARCHAR(50) NOT NULL DEFAULT 0");
|
649 |
-
|
650 |
-
//$this->db_do("UPDATE $categories_temp SET RootName = '3'"); // one store logic test
|
651 |
-
|
652 |
-
//$this->db_do("UPDATE $categories_temp SET RootName = 'KAMERY' WHERE store_category_id IN (93530, 93531, 93230, 93231, 175559, 175687)");
|
653 |
-
//$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
|
654 |
-
//$this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553, 93530, 93531, 93230, 93231, 175559, 175687)");
|
655 |
-
|
656 |
-
|
657 |
-
$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
|
658 |
-
$this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553)");
|
659 |
-
} // private function loadCategoriesTemp()
|
660 |
-
################################################################################################################################################################
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
################################################################################################################################################################
|
665 |
-
private function mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
666 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
667 |
-
$name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
|
668 |
-
$stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
|
669 |
-
{
|
670 |
-
echo("mergeMultistoreCategories RUN\n");
|
671 |
-
|
672 |
-
|
673 |
-
$this->createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
674 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
$this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
|
679 |
-
|
680 |
-
|
681 |
-
$this->addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
682 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
683 |
-
$name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
|
684 |
-
|
685 |
-
|
686 |
-
echo("\n\n\nmergeMultistoreCategories DONE\n");
|
687 |
-
}
|
688 |
-
################################################################################################################################################################
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
################################################################################################################################################################
|
696 |
-
private function addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
697 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
698 |
-
$name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
|
699 |
-
{
|
700 |
-
echo("\n\n\n\n *************************************************************\n mapSinchCategoriesMultistore start... \n");
|
701 |
-
|
702 |
-
|
703 |
-
if (UPDATE_CATEGORY_DATA)
|
704 |
-
{
|
705 |
-
$ignore = '';
|
706 |
-
$on_diplicate_key_update = "
|
707 |
-
ON DUPLICATE KEY UPDATE
|
708 |
-
updated_at = now(),
|
709 |
-
store_category_id = c.store_category_id,
|
710 |
-
level = c.level,
|
711 |
-
children_count = c.children_count,
|
712 |
-
position = c.order_number,
|
713 |
-
parent_store_category_id = c.parent_store_category_id";
|
714 |
-
//level=c.level,
|
715 |
-
//children_count=c.children_count
|
716 |
-
//position=c.order_number,
|
717 |
-
}
|
718 |
-
else
|
719 |
-
{
|
720 |
-
$ignore = 'IGNORE';
|
721 |
-
$on_diplicate_key_update = '';
|
722 |
-
}
|
723 |
-
|
724 |
-
$query = "
|
725 |
-
INSERT $ignore INTO $catalog_category_entity
|
726 |
-
(
|
727 |
-
entity_type_id,
|
728 |
-
attribute_set_id,
|
729 |
-
created_at,
|
730 |
-
updated_at,
|
731 |
-
level,
|
732 |
-
children_count,
|
733 |
-
entity_id,
|
734 |
-
position,
|
735 |
-
parent_id,
|
736 |
-
store_category_id,
|
737 |
-
parent_store_category_id
|
738 |
-
)
|
739 |
-
(SELECT
|
740 |
-
$_categoryEntityTypeId,
|
741 |
-
$_categoryDefault_attribute_set_id,
|
742 |
-
NOW(),
|
743 |
-
NOW(),
|
744 |
-
c.level,
|
745 |
-
c.children_count,
|
746 |
-
scm.shop_entity_id,
|
747 |
-
c.order_number,
|
748 |
-
scm.shop_parent_id,
|
749 |
-
c.store_category_id,
|
750 |
-
c.parent_store_category_id
|
751 |
-
FROM $categories_temp c
|
752 |
-
LEFT JOIN $stINch_categories_mapping scm
|
753 |
-
ON c.store_category_id = scm.store_category_id
|
754 |
-
) $on_diplicate_key_update";
|
755 |
-
echo("\n\n $query\n\n");
|
756 |
-
$this->db_do($query);
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
$this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
$categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
|
767 |
-
while ($row = mysqli_fetch_array($categories))
|
768 |
-
{
|
769 |
-
$parent_id = $row['parent_id'];
|
770 |
-
$entity_id = $row['entity_id'];
|
771 |
-
|
772 |
-
$path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
|
773 |
-
|
774 |
-
$this->db_do("
|
775 |
-
UPDATE $catalog_category_entity
|
776 |
-
SET path = '$path'
|
777 |
-
WHERE entity_id = $entity_id");
|
778 |
-
} // while ($row = mysqli_fetch_array($categories))
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
///////////////////////////////////////////////////////
|
784 |
-
|
785 |
-
|
786 |
-
if(UPDATE_CATEGORY_DATA)
|
787 |
-
{
|
788 |
-
echo "Update category_data \n";
|
789 |
-
|
790 |
-
$q = "
|
791 |
-
INSERT INTO $catalog_category_entity_varchar
|
792 |
-
(
|
793 |
-
entity_type_id,
|
794 |
-
attribute_id,
|
795 |
-
store_id,
|
796 |
-
entity_id,
|
797 |
-
value
|
798 |
-
)
|
799 |
-
(SELECT
|
800 |
-
$_categoryEntityTypeId,
|
801 |
-
$name_attrid,
|
802 |
-
0,
|
803 |
-
scm.shop_entity_id,
|
804 |
-
c.category_name
|
805 |
-
FROM $categories_temp c
|
806 |
-
JOIN $stINch_categories_mapping scm
|
807 |
-
ON c.store_category_id = scm.store_category_id
|
808 |
-
)
|
809 |
-
ON DUPLICATE KEY UPDATE
|
810 |
-
value = c.category_name";
|
811 |
-
$this->db_do($q);
|
812 |
-
|
813 |
-
|
814 |
-
$q = "
|
815 |
-
INSERT INTO $catalog_category_entity_varchar
|
816 |
-
(
|
817 |
-
entity_type_id,
|
818 |
-
attribute_id,
|
819 |
-
store_id,
|
820 |
-
entity_id,
|
821 |
-
value
|
822 |
-
)
|
823 |
-
(SELECT
|
824 |
-
$_categoryEntityTypeId,
|
825 |
-
$name_attrid,
|
826 |
-
1,
|
827 |
-
scm.shop_entity_id,
|
828 |
-
c.category_name
|
829 |
-
FROM $categories_temp c
|
830 |
-
JOIN $stINch_categories_mapping scm
|
831 |
-
ON c.store_category_id = scm.store_category_id
|
832 |
-
)
|
833 |
-
ON DUPLICATE KEY UPDATE
|
834 |
-
value = c.category_name";
|
835 |
-
$this->db_do($q);
|
836 |
-
|
837 |
-
|
838 |
-
$q = "
|
839 |
-
INSERT INTO $catalog_category_entity
|
840 |
-
(
|
841 |
-
entity_type_id,
|
842 |
-
attribute_id,
|
843 |
-
store_id,
|
844 |
-
entity_id,
|
845 |
-
value
|
846 |
-
)
|
847 |
-
(SELECT
|
848 |
-
$_categoryEntityTypeId,
|
849 |
-
$attr_is_active,
|
850 |
-
0,
|
851 |
-
scm.shop_entity_id,
|
852 |
-
1
|
853 |
-
FROM $categories_temp c
|
854 |
-
JOIN $stINch_categories_mapping scm
|
855 |
-
ON c.store_category_id = scm.store_category_id
|
856 |
-
)
|
857 |
-
ON DUPLICATE KEY UPDATE
|
858 |
-
value = 1";
|
859 |
-
$this->db_do($q);
|
860 |
-
|
861 |
-
|
862 |
-
$q = "
|
863 |
-
INSERT INTO $catalog_category_entity_int
|
864 |
-
(
|
865 |
-
entity_type_id,
|
866 |
-
attribute_id,
|
867 |
-
store_id,
|
868 |
-
entity_id,
|
869 |
-
value
|
870 |
-
)
|
871 |
-
(SELECT
|
872 |
-
$_categoryEntityTypeId,
|
873 |
-
$attr_is_active,
|
874 |
-
1,
|
875 |
-
scm.shop_entity_id,
|
876 |
-
1
|
877 |
-
FROM $categories_temp c
|
878 |
-
JOIN $stINch_categories_mapping scm
|
879 |
-
ON c.store_category_id = scm.store_category_id
|
880 |
-
)
|
881 |
-
ON DUPLICATE KEY UPDATE
|
882 |
-
value = 1";
|
883 |
-
$this->db_do($q);
|
884 |
-
|
885 |
-
|
886 |
-
$q = "
|
887 |
-
INSERT INTO $catalog_category_entity_int
|
888 |
-
(
|
889 |
-
entity_type_id,
|
890 |
-
attribute_id,
|
891 |
-
store_id,
|
892 |
-
entity_id,
|
893 |
-
value
|
894 |
-
)
|
895 |
-
(SELECT
|
896 |
-
$_categoryEntityTypeId,
|
897 |
-
$attr_include_in_menu,
|
898 |
-
0,
|
899 |
-
scm.shop_entity_id,
|
900 |
-
1
|
901 |
-
FROM $categories_temp c
|
902 |
-
JOIN $stINch_categories_mapping scm
|
903 |
-
ON c.store_category_id = scm.store_category_id
|
904 |
-
)
|
905 |
-
ON DUPLICATE KEY UPDATE
|
906 |
-
value = 1";
|
907 |
-
$this->db_do($q);
|
908 |
-
|
909 |
-
|
910 |
-
$q = "
|
911 |
-
INSERT INTO $catalog_category_entity_int
|
912 |
-
(
|
913 |
-
entity_type_id,
|
914 |
-
attribute_id,
|
915 |
-
store_id,
|
916 |
-
entity_id,
|
917 |
-
value
|
918 |
-
)
|
919 |
-
(SELECT
|
920 |
-
$_categoryEntityTypeId,
|
921 |
-
$is_anchor_attrid,
|
922 |
-
1,
|
923 |
-
scm.shop_entity_id,
|
924 |
-
1
|
925 |
-
FROM $categories_temp c
|
926 |
-
JOIN $stINch_categories_mapping scm
|
927 |
-
ON c.store_category_id = scm.store_category_id
|
928 |
-
)
|
929 |
-
ON DUPLICATE KEY UPDATE
|
930 |
-
value = 1";
|
931 |
-
$this->db_do($q);
|
932 |
-
|
933 |
-
|
934 |
-
$q = "
|
935 |
-
INSERT INTO $catalog_category_entity_int
|
936 |
-
(
|
937 |
-
entity_type_id,
|
938 |
-
attribute_id,
|
939 |
-
store_id,
|
940 |
-
entity_id,
|
941 |
-
value
|
942 |
-
)
|
943 |
-
(SELECT
|
944 |
-
$_categoryEntityTypeId,
|
945 |
-
$is_anchor_attrid,
|
946 |
-
0,
|
947 |
-
scm.shop_entity_id,
|
948 |
-
1
|
949 |
-
FROM $categories_temp c
|
950 |
-
JOIN $stINch_categories_mapping scm
|
951 |
-
ON c.store_category_id = scm.store_category_id
|
952 |
-
)
|
953 |
-
ON DUPLICATE KEY UPDATE
|
954 |
-
value = 1";
|
955 |
-
$this->db_do($q);
|
956 |
-
|
957 |
-
$q = "
|
958 |
-
INSERT INTO $catalog_category_entity_varchar
|
959 |
-
(
|
960 |
-
entity_type_id,
|
961 |
-
attribute_id,
|
962 |
-
store_id,
|
963 |
-
entity_id,
|
964 |
-
value
|
965 |
-
)
|
966 |
-
(SELECT
|
967 |
-
$_categoryEntityTypeId,
|
968 |
-
$image_attrid,
|
969 |
-
0,
|
970 |
-
scm.shop_entity_id,
|
971 |
-
c.categories_image
|
972 |
-
FROM $categories_temp c
|
973 |
-
JOIN $stINch_categories_mapping scm
|
974 |
-
ON c.store_category_id = scm.store_category_id
|
975 |
-
)
|
976 |
-
ON DUPLICATE KEY UPDATE
|
977 |
-
value = c.categories_image";
|
978 |
-
$this->db_do($q);
|
979 |
-
}
|
980 |
-
else
|
981 |
-
{
|
982 |
-
echo "Insert ignore category_data \n";
|
983 |
-
|
984 |
-
|
985 |
-
$q = "
|
986 |
-
INSERT IGNORE INTO $catalog_category_entity_varchar
|
987 |
-
(
|
988 |
-
entity_type_id,
|
989 |
-
attribute_id,
|
990 |
-
store_id,
|
991 |
-
entity_id,
|
992 |
-
value
|
993 |
-
)
|
994 |
-
(SELECT
|
995 |
-
$_categoryEntityTypeId,
|
996 |
-
$name_attrid,
|
997 |
-
0,
|
998 |
-
scm.shop_entity_id,
|
999 |
-
c.category_name
|
1000 |
-
FROM $categories_temp c
|
1001 |
-
JOIN $stINch_categories_mapping scm
|
1002 |
-
ON c.store_category_id = scm.store_category_id
|
1003 |
-
)";
|
1004 |
-
$this->db_do($q);
|
1005 |
-
|
1006 |
-
|
1007 |
-
$q = "
|
1008 |
-
INSERT IGNORE INTO $catalog_category_entity_int
|
1009 |
-
(
|
1010 |
-
entity_type_id,
|
1011 |
-
attribute_id,
|
1012 |
-
store_id,
|
1013 |
-
entity_id,
|
1014 |
-
value
|
1015 |
-
)
|
1016 |
-
(SELECT
|
1017 |
-
$_categoryEntityTypeId,
|
1018 |
-
$attr_is_active,
|
1019 |
-
0,
|
1020 |
-
scm.shop_entity_id,
|
1021 |
-
1
|
1022 |
-
FROM $categories_temp c
|
1023 |
-
JOIN $stINch_categories_mapping scm
|
1024 |
-
ON c.store_category_id = scm.store_category_id
|
1025 |
-
)";
|
1026 |
-
$this->db_do($q);
|
1027 |
-
|
1028 |
-
|
1029 |
-
$q = "
|
1030 |
-
INSERT IGNORE INTO $catalog_category_entity_int
|
1031 |
-
(
|
1032 |
-
entity_type_id,
|
1033 |
-
attribute_id,
|
1034 |
-
store_id,
|
1035 |
-
entity_id,
|
1036 |
-
value
|
1037 |
-
)
|
1038 |
-
(SELECT
|
1039 |
-
$_categoryEntityTypeId,
|
1040 |
-
$attr_include_in_menu,
|
1041 |
-
0,
|
1042 |
-
scm.shop_entity_id,
|
1043 |
-
1
|
1044 |
-
FROM $categories_temp c
|
1045 |
-
JOIN $stINch_categories_mapping scm
|
1046 |
-
ON c.store_category_id = scm.store_category_id
|
1047 |
-
)";
|
1048 |
-
$this->db_do($q);
|
1049 |
-
|
1050 |
-
|
1051 |
-
$q = "
|
1052 |
-
INSERT IGNORE INTO $catalog_category_entity_int
|
1053 |
-
(
|
1054 |
-
entity_type_id,
|
1055 |
-
attribute_id,
|
1056 |
-
store_id,
|
1057 |
-
entity_id,
|
1058 |
-
value
|
1059 |
-
)
|
1060 |
-
(SELECT
|
1061 |
-
$_categoryEntityTypeId,
|
1062 |
-
$is_anchor_attrid,
|
1063 |
-
0,
|
1064 |
-
scm.shop_entity_id,
|
1065 |
-
1
|
1066 |
-
FROM $categories_temp c
|
1067 |
-
JOIN $stINch_categories_mapping scm
|
1068 |
-
ON c.store_category_id = scm.store_category_id
|
1069 |
-
)";
|
1070 |
-
$this->db_do($q);
|
1071 |
-
|
1072 |
-
|
1073 |
-
$q = "
|
1074 |
-
INSERT IGNORE INTO $catalog_category_entity_varchar
|
1075 |
-
(
|
1076 |
-
entity_type_id,
|
1077 |
-
attribute_id,
|
1078 |
-
store_id,
|
1079 |
-
entity_id,
|
1080 |
-
value
|
1081 |
-
)
|
1082 |
-
(SELECT
|
1083 |
-
$_categoryEntityTypeId,
|
1084 |
-
$image_attrid,
|
1085 |
-
0,
|
1086 |
-
scm.shop_entity_id,
|
1087 |
-
c.categories_image
|
1088 |
-
FROM $categories_temp c
|
1089 |
-
JOIN $stINch_categories_mapping scm
|
1090 |
-
ON c.store_category_id = scm.store_category_id
|
1091 |
-
)";
|
1092 |
-
$this->db_do($q);
|
1093 |
-
}
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
//$this->deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int);
|
1098 |
-
|
1099 |
-
//return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
|
1100 |
-
|
1101 |
-
$this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
|
1102 |
-
$this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
|
1103 |
-
/**/
|
1104 |
-
|
1105 |
-
echo("\n mapSinchCategoriesMultistore done... \n *************************************************************\n");
|
1106 |
-
|
1107 |
-
} // private function addCategoryDataMultistoreMerge(...)
|
1108 |
-
################################################################################################################################################################
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
################################################################################################################################################################
|
1115 |
-
private function deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int)
|
1116 |
-
{
|
1117 |
-
|
1118 |
-
echo("\n\n\n\n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n deleteOldSinchCategoriesFromShopMerge start... \n");
|
1119 |
-
|
1120 |
-
/**
|
1121 |
-
$query = "
|
1122 |
-
DELETE cat FROM $catalog_category_entity_varchar cat
|
1123 |
-
JOIN $stINch_categories_mapping scm
|
1124 |
-
ON cat.entity_id = scm.shop_entity_id
|
1125 |
-
WHERE
|
1126 |
-
(scm.shop_store_category_id IS NOT NULL) AND
|
1127 |
-
(scm.store_category_id IS NULL)";
|
1128 |
-
echo("\n $query\n");
|
1129 |
-
// $this->db_do($query);
|
1130 |
-
|
1131 |
-
$query = "
|
1132 |
-
DELETE cat FROM $catalog_category_entity_int cat
|
1133 |
-
JOIN $stINch_categories_mapping scm
|
1134 |
-
ON cat.entity_id = scm.shop_entity_id
|
1135 |
-
WHERE
|
1136 |
-
(scm.shop_store_category_id IS NOT NULL) AND
|
1137 |
-
(scm.store_category_id IS NULL)";
|
1138 |
-
echo("\n $query\n");
|
1139 |
-
// $this->db_do($query);
|
1140 |
-
|
1141 |
-
$query = "
|
1142 |
-
DELETE cat FROM $catalog_category_entity cat
|
1143 |
-
JOIN $stINch_categories_mapping scm
|
1144 |
-
ON cat.entity_id=scm.shop_entity_id
|
1145 |
-
WHERE
|
1146 |
-
(scm.shop_store_category_id IS NOT NULL) AND
|
1147 |
-
(scm.store_category_id IS NULL)";
|
1148 |
-
echo("\n $query\n");
|
1149 |
-
// $this->db_do($query);
|
1150 |
-
/**/
|
1151 |
-
|
1152 |
-
echo("\n deleteOldSinchCategoriesFromShopMerge done... \n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
|
1153 |
-
|
1154 |
-
} // private function deleteOldSinchCategoriesFromShopMerge()
|
1155 |
-
################################################################################################################################################################
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
################################################################################################################################################################
|
1162 |
-
private function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
|
1163 |
-
{
|
1164 |
-
echo("\n\n\ ==========================================================================\n mapSinchCategoriesMultistore start... \n");
|
1165 |
-
|
1166 |
-
$this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
|
1167 |
-
|
1168 |
-
$query = "
|
1169 |
-
INSERT IGNORE INTO $stINch_categories_mapping_temp
|
1170 |
-
(shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
|
1171 |
-
(SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
|
1172 |
-
FROM $catalog_category_entity)";
|
1173 |
-
echo("\n $query\n");
|
1174 |
-
$this->db_do($query);
|
1175 |
-
|
1176 |
-
|
1177 |
-
$query = "
|
1178 |
-
UPDATE $stINch_categories_mapping_temp cmt
|
1179 |
-
JOIN $categories_temp c
|
1180 |
-
ON cmt.shop_store_category_id = c.store_category_id
|
1181 |
-
SET
|
1182 |
-
cmt.store_category_id = c.store_category_id,
|
1183 |
-
cmt.parent_store_category_id = c.parent_store_category_id,
|
1184 |
-
cmt.category_name = c.category_name,
|
1185 |
-
cmt.order_number = c.order_number,
|
1186 |
-
cmt.products_within_this_category = c.products_within_this_category";
|
1187 |
-
echo("\n $query\n");
|
1188 |
-
$this->db_do($query);
|
1189 |
-
|
1190 |
-
|
1191 |
-
$query = "
|
1192 |
-
UPDATE $stINch_categories_mapping_temp cmt
|
1193 |
-
JOIN $catalog_category_entity cce
|
1194 |
-
ON cmt.parent_store_category_id = cce.store_category_id
|
1195 |
-
SET cmt.shop_parent_id = cce.entity_id";
|
1196 |
-
echo("\n $query\n");
|
1197 |
-
$this->db_do($query);
|
1198 |
-
|
1199 |
-
|
1200 |
-
$query = "
|
1201 |
-
SELECT DISTINCT
|
1202 |
-
c.RootName, cce.entity_id
|
1203 |
-
FROM $categories_temp c
|
1204 |
-
JOIN $catalog_category_entity_varchar ccev
|
1205 |
-
ON c.RootName = ccev.value
|
1206 |
-
AND ccev.entity_type_id = $_categoryEntityTypeId
|
1207 |
-
AND ccev.attribute_id = $name_attrid
|
1208 |
-
AND ccev.store_id = 0
|
1209 |
-
JOIN $catalog_category_entity cce
|
1210 |
-
ON ccev.entity_id = cce.entity_id";
|
1211 |
-
echo("\n $query\n");
|
1212 |
-
$root_categories = $this->db_do($query);
|
1213 |
-
|
1214 |
-
while($root_cat = mysqli_fetch_array($root_categories))
|
1215 |
-
{
|
1216 |
-
$root_id = $root_cat['entity_id'];
|
1217 |
-
$root_name = $root_cat['RootName'];
|
1218 |
-
|
1219 |
-
$query = "
|
1220 |
-
UPDATE $stINch_categories_mapping_temp cmt
|
1221 |
-
JOIN $categories_temp c
|
1222 |
-
ON cmt.shop_store_category_id = c.store_category_id
|
1223 |
-
SET
|
1224 |
-
cmt.shop_parent_id = $root_id,
|
1225 |
-
cmt.shop_parent_store_category_id = $root_id,
|
1226 |
-
cmt.parent_store_category_id = $root_id,
|
1227 |
-
c.parent_store_category_id = $root_id
|
1228 |
-
WHERE RootName = '$root_name'
|
1229 |
-
AND cmt.shop_parent_id = 0";
|
1230 |
-
echo("\n $query\n");
|
1231 |
-
$this->db_do($query);
|
1232 |
-
}
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
// added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
|
1237 |
-
if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
|
1238 |
-
else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
|
1239 |
-
|
1240 |
-
$query = "
|
1241 |
-
UPDATE $stINch_categories_mapping_temp cmt
|
1242 |
-
JOIN $catalog_category_entity cce
|
1243 |
-
ON cmt.shop_entity_id = cce.entity_id
|
1244 |
-
SET cce.parent_id = cmt.shop_parent_id
|
1245 |
-
$where";
|
1246 |
-
echo("\n $query\n");
|
1247 |
-
$this->db_do($query);
|
1248 |
-
|
1249 |
-
$query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
|
1250 |
-
echo("\n $query\n");
|
1251 |
-
$this->db_do($query);
|
1252 |
-
|
1253 |
-
$query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
|
1254 |
-
echo("\n $query\n");
|
1255 |
-
$this->db_do($query);
|
1256 |
-
|
1257 |
-
echo("\n mapSinchCategoriesMultistore done... \n ==========================================================================\n\n\n\n");
|
1258 |
-
} // public function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
|
1259 |
-
################################################################################################################################################################
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
################################################################################################################################################################
|
1268 |
-
private function createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
1269 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
|
1270 |
-
{
|
1271 |
-
echo("\n\n ==========================================================================\n createNewDefaultCategories start... \n");
|
1272 |
-
|
1273 |
-
$old_cats = array();
|
1274 |
-
$query = $this->db_do("
|
1275 |
-
SELECT
|
1276 |
-
cce.entity_id,
|
1277 |
-
ccev.value AS category_name
|
1278 |
-
FROM $catalog_category_entity cce
|
1279 |
-
JOIN $catalog_category_entity_varchar ccev
|
1280 |
-
ON cce.entity_id = ccev.entity_id
|
1281 |
-
AND ccev.store_id = 0
|
1282 |
-
AND cce.entity_type_id = ccev.entity_type_id
|
1283 |
-
AND ccev.attribute_id = 41
|
1284 |
-
WHERE parent_id = 1"); // 41 - category name
|
1285 |
-
while ($row = mysqli_fetch_array($query)) $old_cats[] = $row['category_name'];
|
1286 |
-
|
1287 |
-
//var_dump($old_cats);
|
1288 |
-
|
1289 |
-
|
1290 |
-
$query = $this->db_do("SELECT MAX(entity_id) AS max_entity_id FROM $catalog_category_entity");
|
1291 |
-
$max_entity_id = mysqli_fetch_array($query);
|
1292 |
-
|
1293 |
-
//var_dump($max_entity_id);
|
1294 |
-
|
1295 |
-
$i = $max_entity_id[max_entity_id] + 1;
|
1296 |
-
|
1297 |
-
foreach($coincidence as $key => $item)
|
1298 |
-
{
|
1299 |
-
echo("\n coincidence: key = [$key]\n");
|
1300 |
-
|
1301 |
-
|
1302 |
-
/**if ($item)
|
1303 |
-
{
|
1304 |
-
echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> CONTINUE: key = [$key] item = [$item]\n");
|
1305 |
-
//continue;
|
1306 |
-
}
|
1307 |
-
else
|
1308 |
-
{
|
1309 |
-
echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> NOT CONTINUE: key = [$key] item = [$item]\n");
|
1310 |
-
}/**/
|
1311 |
-
|
1312 |
-
|
1313 |
-
if (in_array($key, $old_cats))
|
1314 |
-
{
|
1315 |
-
echo(" CONTINUE: key = [$key] item = [$item]\n");
|
1316 |
-
continue;
|
1317 |
-
}
|
1318 |
-
else
|
1319 |
-
{
|
1320 |
-
echo(" CREATE NEW CATEGORY: key = [$key] item = [$item]\n");
|
1321 |
-
}
|
1322 |
-
|
1323 |
-
|
1324 |
-
$this->db_do("INSERT $catalog_category_entity
|
1325 |
-
(entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
|
1326 |
-
path, position, level, children_count, store_category_id, parent_store_category_id)
|
1327 |
-
VALUES
|
1328 |
-
($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 0, NULL, NULL)");
|
1329 |
-
|
1330 |
-
|
1331 |
-
$this->db_do("INSERT $catalog_category_entity_varchar
|
1332 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
1333 |
-
VALUES
|
1334 |
-
($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
|
1335 |
-
($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
|
1336 |
-
($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
|
1337 |
-
($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
|
1338 |
-
|
1339 |
-
|
1340 |
-
$this->db_do("INSERT $catalog_category_entity_int
|
1341 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
1342 |
-
VALUES
|
1343 |
-
($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
|
1344 |
-
($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
|
1345 |
-
($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
|
1346 |
-
($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
|
1347 |
-
$i++;
|
1348 |
-
} // foreach($coincidence as $key => $item)
|
1349 |
-
|
1350 |
-
echo("\n createNewDefaultCategories done... \n ==========================================================================\n");
|
1351 |
-
|
1352 |
-
} // private function createNewDefaultCategories()
|
1353 |
-
################################################################################################################################################################
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
################################################################################################################################################################
|
1362 |
-
private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type)
|
1363 |
-
{
|
1364 |
-
$root_categories = $this->db_do("
|
1365 |
-
SELECT
|
1366 |
-
cce.entity_id,
|
1367 |
-
ccev.value AS category_name
|
1368 |
-
FROM $catalog_category_entity cce
|
1369 |
-
JOIN $catalog_category_entity_varchar ccev
|
1370 |
-
ON cce.entity_id = ccev.entity_id
|
1371 |
-
AND ccev.store_id = 0
|
1372 |
-
AND cce.entity_type_id = ccev.entity_type_id
|
1373 |
-
AND ccev.attribute_id = 41
|
1374 |
-
WHERE parent_id = 1"); // 41 - category name
|
1375 |
-
$OLD = array();
|
1376 |
-
while($root_cat = mysqli_fetch_array($root_categories)) $OLD[] = $root_cat['category_name'];
|
1377 |
-
|
1378 |
-
$new_categories = $this->db_do("SELECT DISTINCT RootName FROM $categories_temp");
|
1379 |
-
$NEW = array();
|
1380 |
-
while($new_root_cat = mysqli_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['RootName']] = TRUE;
|
1381 |
-
|
1382 |
-
/**
|
1383 |
-
$exists_coincidence = array();
|
1384 |
-
|
1385 |
-
switch ($im_type)
|
1386 |
-
{
|
1387 |
-
case "REWRITE":
|
1388 |
-
foreach($NEW as $item)
|
1389 |
-
{
|
1390 |
-
$exists_coincidence[$item] = TRUE;
|
1391 |
-
}
|
1392 |
-
break;
|
1393 |
-
case "MERGE" :
|
1394 |
-
foreach($OLD as $item)
|
1395 |
-
{
|
1396 |
-
$exists_coincidence[$item] = FALSE;
|
1397 |
-
}
|
1398 |
-
foreach($NEW as $item)
|
1399 |
-
{
|
1400 |
-
$exists_coincidence[$item] = TRUE;
|
1401 |
-
}
|
1402 |
-
break;
|
1403 |
-
default : $retcode = "error";
|
1404 |
-
};
|
1405 |
-
/**/
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
echo("\ncalculateCategoryCoincidence ...im_type = [$im_type]\n");
|
1410 |
-
var_dump($exists_coincidence);
|
1411 |
-
|
1412 |
-
return $exists_coincidence;
|
1413 |
-
} // private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity)
|
1414 |
-
################################################################################################################################################################
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
################################################################################################################################################################
|
1419 |
-
private function rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
1420 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
1421 |
-
$name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
|
1422 |
-
$stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
|
1423 |
-
{
|
1424 |
-
echo("rewriteMultistoreCategories RUN\n");
|
1425 |
-
|
1426 |
-
|
1427 |
-
echo(" truncateAllCateriesAndCreateRoot start...");
|
1428 |
-
$this->truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
1429 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active);
|
1430 |
-
echo(" done.\n");
|
1431 |
-
|
1432 |
-
|
1433 |
-
echo(" createDefaultCategories start...");
|
1434 |
-
$this->createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
1435 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
|
1436 |
-
echo(" done.\n");
|
1437 |
-
|
1438 |
-
|
1439 |
-
echo(" mapSinchCategoriesMultistore start...");
|
1440 |
-
$this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
|
1441 |
-
echo(" done.\n");
|
1442 |
-
|
1443 |
-
|
1444 |
-
echo(" addCategoryDataMultistore start...");
|
1445 |
-
$this->addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
1446 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
1447 |
-
$name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
|
1448 |
-
echo(" done.\n");
|
1449 |
-
|
1450 |
-
|
1451 |
-
echo("rewriteMultistoreCategories DONE\n");
|
1452 |
-
} // private function rewriteMultistoreCategories()
|
1453 |
-
################################################################################################################################################################
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
################################################################################################################################################################
|
1462 |
-
private function truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
1463 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active)
|
1464 |
-
{
|
1465 |
-
$this->db_do('SET foreign_key_checks=0');
|
1466 |
-
|
1467 |
-
|
1468 |
-
$this->db_do("TRUNCATE $catalog_category_entity");
|
1469 |
-
$this->db_do("TRUNCATE $catalog_category_entity_varchar");
|
1470 |
-
$this->db_do("TRUNCATE $catalog_category_entity_int");
|
1471 |
-
|
1472 |
-
|
1473 |
-
$this->db_do("INSERT $catalog_category_entity
|
1474 |
-
(entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
|
1475 |
-
path, position, level, children_count, store_category_id, parent_store_category_id)
|
1476 |
-
VALUES
|
1477 |
-
(1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', NOW(), '1', 0, 0, 1, NULL, NULL)");
|
1478 |
-
|
1479 |
-
|
1480 |
-
$this->db_do("INSERT $catalog_category_entity_varchar
|
1481 |
-
(value_id, entity_type_id, attribute_id, store_id, entity_id, value)
|
1482 |
-
VALUES
|
1483 |
-
(1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
|
1484 |
-
(2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
|
1485 |
-
(3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog')");
|
1486 |
-
|
1487 |
-
|
1488 |
-
$this->db_do("INSERT $catalog_category_entity_int
|
1489 |
-
(value_id, entity_type_id, attribute_id, store_id, entity_id, value)
|
1490 |
-
VALUES
|
1491 |
-
(1, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1)");
|
1492 |
-
} // private function truncateAllCateriesAndCreateRoot(...)
|
1493 |
-
################################################################################################################################################################
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
################################################################################################################################################################
|
1499 |
-
private function createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
1500 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
|
1501 |
-
{
|
1502 |
-
$i = 3; // 2 - is Default Category... not use.
|
1503 |
-
|
1504 |
-
foreach($coincidence as $key => $item)
|
1505 |
-
{
|
1506 |
-
$this->db_do("INSERT $catalog_category_entity
|
1507 |
-
(entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
|
1508 |
-
path, position, level, children_count, store_category_id, parent_store_category_id)
|
1509 |
-
VALUES
|
1510 |
-
($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 0, NULL, NULL)");
|
1511 |
-
|
1512 |
-
|
1513 |
-
$this->db_do("INSERT $catalog_category_entity_varchar
|
1514 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
1515 |
-
VALUES
|
1516 |
-
($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
|
1517 |
-
($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
|
1518 |
-
($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
|
1519 |
-
($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
|
1520 |
-
|
1521 |
-
|
1522 |
-
$this->db_do("INSERT $catalog_category_entity_int
|
1523 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
1524 |
-
VALUES
|
1525 |
-
($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
|
1526 |
-
($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
|
1527 |
-
($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
|
1528 |
-
($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
|
1529 |
-
$i++;
|
1530 |
-
} // foreach($coincidence as $key => $item)
|
1531 |
-
} // private function truncateAllCateries()
|
1532 |
-
################################################################################################################################################################
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
################################################################################################################################################################
|
1538 |
-
private function mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
|
1539 |
-
{
|
1540 |
-
echo("\n\n\n\n==========================================================================\nmapSinchCategoriesMultistore start... \n");
|
1541 |
-
|
1542 |
-
$this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
|
1543 |
-
|
1544 |
-
$query = "
|
1545 |
-
INSERT IGNORE INTO $stINch_categories_mapping_temp
|
1546 |
-
(shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
|
1547 |
-
(SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
|
1548 |
-
FROM $catalog_category_entity)";
|
1549 |
-
echo("\n\n$query\n\n");
|
1550 |
-
$this->db_do($query);
|
1551 |
-
|
1552 |
-
|
1553 |
-
$query = "
|
1554 |
-
UPDATE $stINch_categories_mapping_temp cmt
|
1555 |
-
JOIN $categories_temp c
|
1556 |
-
ON cmt.shop_store_category_id = c.store_category_id
|
1557 |
-
SET
|
1558 |
-
cmt.store_category_id = c.store_category_id,
|
1559 |
-
cmt.parent_store_category_id = c.parent_store_category_id,
|
1560 |
-
cmt.category_name = c.category_name,
|
1561 |
-
cmt.order_number = c.order_number,
|
1562 |
-
cmt.products_within_this_category = c.products_within_this_category";
|
1563 |
-
echo("\n\n$query\n\n");
|
1564 |
-
$this->db_do($query);
|
1565 |
-
|
1566 |
-
|
1567 |
-
$query = "
|
1568 |
-
UPDATE $stINch_categories_mapping_temp cmt
|
1569 |
-
JOIN $catalog_category_entity cce
|
1570 |
-
ON cmt.parent_store_category_id = cce.store_category_id
|
1571 |
-
SET cmt.shop_parent_id = cce.entity_id";
|
1572 |
-
echo("\n\n$query\n\n");
|
1573 |
-
$this->db_do($query);
|
1574 |
-
|
1575 |
-
|
1576 |
-
$query = "
|
1577 |
-
SELECT DISTINCT
|
1578 |
-
c.RootName, cce.entity_id
|
1579 |
-
FROM $categories_temp c
|
1580 |
-
JOIN $catalog_category_entity_varchar ccev
|
1581 |
-
ON c.RootName = ccev.value
|
1582 |
-
AND ccev.entity_type_id = $_categoryEntityTypeId
|
1583 |
-
AND ccev.attribute_id = $name_attrid
|
1584 |
-
AND ccev.store_id = 0
|
1585 |
-
JOIN $catalog_category_entity cce
|
1586 |
-
ON ccev.entity_id = cce.entity_id";
|
1587 |
-
echo("\n\n$query\n\n");
|
1588 |
-
$root_categories = $this->db_do($query);
|
1589 |
-
|
1590 |
-
while($root_cat = mysqli_fetch_array($root_categories))
|
1591 |
-
{
|
1592 |
-
$root_id = $root_cat['entity_id'];
|
1593 |
-
$root_name = $root_cat['RootName'];
|
1594 |
-
|
1595 |
-
$query = "
|
1596 |
-
UPDATE $stINch_categories_mapping_temp cmt
|
1597 |
-
JOIN $categories_temp c
|
1598 |
-
ON cmt.shop_store_category_id = c.store_category_id
|
1599 |
-
SET
|
1600 |
-
cmt.shop_parent_id = $root_id,
|
1601 |
-
cmt.shop_parent_store_category_id = $root_id,
|
1602 |
-
cmt.parent_store_category_id = $root_id,
|
1603 |
-
c.parent_store_category_id = $root_id
|
1604 |
-
WHERE RootName = '$root_name'
|
1605 |
-
AND cmt.shop_parent_id = 0";
|
1606 |
-
echo("\n\n$query\n\n");
|
1607 |
-
$this->db_do($query);
|
1608 |
-
}
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
// added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
|
1613 |
-
if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
|
1614 |
-
else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
|
1615 |
-
|
1616 |
-
$query = "
|
1617 |
-
UPDATE $stINch_categories_mapping_temp cmt
|
1618 |
-
JOIN $catalog_category_entity cce
|
1619 |
-
ON cmt.shop_entity_id = cce.entity_id
|
1620 |
-
SET cce.parent_id = cmt.shop_parent_id
|
1621 |
-
$where";
|
1622 |
-
echo("\n\n$query\n\n");
|
1623 |
-
$this->db_do($query);
|
1624 |
-
|
1625 |
-
$query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
|
1626 |
-
echo("\n\n$query\n\n");
|
1627 |
-
$this->db_do($query);
|
1628 |
-
|
1629 |
-
$query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
|
1630 |
-
echo("\n\n$query\n\n");
|
1631 |
-
$this->db_do($query);
|
1632 |
-
|
1633 |
-
echo("\nmapSinchCategoriesMultistore done... \n==========================================================================\n\n\n\n");
|
1634 |
-
} // public function mapSinchCategoriesMultistore($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
|
1635 |
-
################################################################################################################################################################
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
################################################################################################################################################################
|
1640 |
-
private function createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping)
|
1641 |
-
{
|
1642 |
-
$this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
|
1643 |
-
$this->db_do("
|
1644 |
-
CREATE TABLE $stINch_categories_mapping_temp
|
1645 |
-
(
|
1646 |
-
shop_entity_id INT(11) UNSIGNED NOT NULL,
|
1647 |
-
shop_entity_type_id INT(11),
|
1648 |
-
shop_attribute_set_id INT(11),
|
1649 |
-
shop_parent_id INT(11),
|
1650 |
-
shop_store_category_id INT(11),
|
1651 |
-
shop_parent_store_category_id INT(11),
|
1652 |
-
store_category_id INT(11),
|
1653 |
-
parent_store_category_id INT(11),
|
1654 |
-
category_name VARCHAR(255),
|
1655 |
-
order_number INT(11),
|
1656 |
-
products_within_this_category INT(11),
|
1657 |
-
|
1658 |
-
KEY shop_entity_id (shop_entity_id),
|
1659 |
-
KEY shop_parent_id (shop_parent_id),
|
1660 |
-
KEY store_category_id (store_category_id),
|
1661 |
-
KEY parent_store_category_id (parent_store_category_id),
|
1662 |
-
UNIQUE KEY(shop_entity_id)
|
1663 |
-
)");
|
1664 |
-
|
1665 |
-
|
1666 |
-
$this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
|
1667 |
-
}
|
1668 |
-
################################################################################################################################################################
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
################################################################################################################################################################
|
1673 |
-
private function addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
1674 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
1675 |
-
$name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
|
1676 |
-
{
|
1677 |
-
echo("\n\n\n\n*************************************************************\nmapSinchCategoriesMultistore start... \n");
|
1678 |
-
if (UPDATE_CATEGORY_DATA)
|
1679 |
-
{
|
1680 |
-
$ignore = '';
|
1681 |
-
$on_diplicate_key_update = "
|
1682 |
-
ON DUPLICATE KEY UPDATE
|
1683 |
-
updated_at = now(),
|
1684 |
-
store_category_id = c.store_category_id,
|
1685 |
-
level = c.level,
|
1686 |
-
children_count = c.children_count,
|
1687 |
-
position = c.order_number,
|
1688 |
-
parent_store_category_id = c.parent_store_category_id";
|
1689 |
-
//level=c.level,
|
1690 |
-
//children_count=c.children_count
|
1691 |
-
//position=c.order_number,
|
1692 |
-
}
|
1693 |
-
else
|
1694 |
-
{
|
1695 |
-
$ignore = 'IGNORE';
|
1696 |
-
$on_diplicate_key_update = '';
|
1697 |
-
}
|
1698 |
-
|
1699 |
-
$query = "
|
1700 |
-
INSERT $ignore INTO $catalog_category_entity
|
1701 |
-
(
|
1702 |
-
entity_type_id,
|
1703 |
-
attribute_set_id,
|
1704 |
-
created_at,
|
1705 |
-
updated_at,
|
1706 |
-
level,
|
1707 |
-
children_count,
|
1708 |
-
entity_id,
|
1709 |
-
position,
|
1710 |
-
parent_id,
|
1711 |
-
store_category_id,
|
1712 |
-
parent_store_category_id
|
1713 |
-
)
|
1714 |
-
(SELECT
|
1715 |
-
$_categoryEntityTypeId,
|
1716 |
-
$_categoryDefault_attribute_set_id,
|
1717 |
-
NOW(),
|
1718 |
-
NOW(),
|
1719 |
-
c.level,
|
1720 |
-
c.children_count,
|
1721 |
-
scm.shop_entity_id,
|
1722 |
-
c.order_number,
|
1723 |
-
scm.shop_parent_id,
|
1724 |
-
c.store_category_id,
|
1725 |
-
c.parent_store_category_id
|
1726 |
-
FROM $categories_temp c
|
1727 |
-
LEFT JOIN $stINch_categories_mapping scm
|
1728 |
-
ON c.store_category_id = scm.store_category_id
|
1729 |
-
) $on_diplicate_key_update";
|
1730 |
-
echo("\n\n$query\n\n");
|
1731 |
-
$this->db_do($query);
|
1732 |
-
|
1733 |
-
//return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
|
1734 |
-
|
1735 |
-
|
1736 |
-
$this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
|
1737 |
-
|
1738 |
-
|
1739 |
-
$categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
|
1740 |
-
while ($row = mysqli_fetch_array($categories))
|
1741 |
-
{
|
1742 |
-
$parent_id = $row['parent_id'];
|
1743 |
-
$entity_id = $row['entity_id'];
|
1744 |
-
|
1745 |
-
$path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
|
1746 |
-
|
1747 |
-
$this->db_do("
|
1748 |
-
UPDATE $catalog_category_entity
|
1749 |
-
SET path = '$path'
|
1750 |
-
WHERE entity_id = $entity_id");
|
1751 |
-
} // while ($row = mysqli_fetch_array($categories))
|
1752 |
-
|
1753 |
-
|
1754 |
-
///////////////////////////////////////////////////////
|
1755 |
-
|
1756 |
-
|
1757 |
-
if(UPDATE_CATEGORY_DATA)
|
1758 |
-
{
|
1759 |
-
echo "Update category_data \n";
|
1760 |
-
|
1761 |
-
$q = "
|
1762 |
-
INSERT INTO $catalog_category_entity_varchar
|
1763 |
-
(
|
1764 |
-
entity_type_id,
|
1765 |
-
attribute_id,
|
1766 |
-
store_id,
|
1767 |
-
entity_id,
|
1768 |
-
value
|
1769 |
-
)
|
1770 |
-
(SELECT
|
1771 |
-
$_categoryEntityTypeId,
|
1772 |
-
$name_attrid,
|
1773 |
-
0,
|
1774 |
-
scm.shop_entity_id,
|
1775 |
-
c.category_name
|
1776 |
-
FROM $categories_temp c
|
1777 |
-
JOIN $stINch_categories_mapping scm
|
1778 |
-
ON c.store_category_id = scm.store_category_id
|
1779 |
-
)
|
1780 |
-
ON DUPLICATE KEY UPDATE
|
1781 |
-
value = c.category_name";
|
1782 |
-
$this->db_do($q);
|
1783 |
-
|
1784 |
-
|
1785 |
-
$q = "
|
1786 |
-
INSERT INTO $catalog_category_entity_varchar
|
1787 |
-
(
|
1788 |
-
entity_type_id,
|
1789 |
-
attribute_id,
|
1790 |
-
store_id,
|
1791 |
-
entity_id,
|
1792 |
-
value
|
1793 |
-
)
|
1794 |
-
(SELECT
|
1795 |
-
$_categoryEntityTypeId,
|
1796 |
-
$name_attrid,
|
1797 |
-
1,
|
1798 |
-
scm.shop_entity_id,
|
1799 |
-
c.category_name
|
1800 |
-
FROM $categories_temp c
|
1801 |
-
JOIN $stINch_categories_mapping scm
|
1802 |
-
ON c.store_category_id = scm.store_category_id
|
1803 |
-
)
|
1804 |
-
ON DUPLICATE KEY UPDATE
|
1805 |
-
value = c.category_name";
|
1806 |
-
$this->db_do($q);
|
1807 |
-
|
1808 |
-
|
1809 |
-
$q = "
|
1810 |
-
INSERT INTO $catalog_category_entity
|
1811 |
-
(
|
1812 |
-
entity_type_id,
|
1813 |
-
attribute_id,
|
1814 |
-
store_id,
|
1815 |
-
entity_id,
|
1816 |
-
value
|
1817 |
-
)
|
1818 |
-
(SELECT
|
1819 |
-
$_categoryEntityTypeId,
|
1820 |
-
$attr_is_active,
|
1821 |
-
0,
|
1822 |
-
scm.shop_entity_id,
|
1823 |
-
1
|
1824 |
-
FROM $categories_temp c
|
1825 |
-
JOIN $stINch_categories_mapping scm
|
1826 |
-
ON c.store_category_id = scm.store_category_id
|
1827 |
-
)
|
1828 |
-
ON DUPLICATE KEY UPDATE
|
1829 |
-
value = 1";
|
1830 |
-
$this->db_do($q);
|
1831 |
-
|
1832 |
-
|
1833 |
-
$q = "
|
1834 |
-
INSERT INTO $catalog_category_entity_int
|
1835 |
-
(
|
1836 |
-
entity_type_id,
|
1837 |
-
attribute_id,
|
1838 |
-
store_id,
|
1839 |
-
entity_id,
|
1840 |
-
value
|
1841 |
-
)
|
1842 |
-
(SELECT
|
1843 |
-
$_categoryEntityTypeId,
|
1844 |
-
$attr_is_active,
|
1845 |
-
1,
|
1846 |
-
scm.shop_entity_id,
|
1847 |
-
1
|
1848 |
-
FROM $categories_temp c
|
1849 |
-
JOIN $stINch_categories_mapping scm
|
1850 |
-
ON c.store_category_id = scm.store_category_id
|
1851 |
-
)
|
1852 |
-
ON DUPLICATE KEY UPDATE
|
1853 |
-
value = 1";
|
1854 |
-
$this->db_do($q);
|
1855 |
-
|
1856 |
-
|
1857 |
-
$q = "
|
1858 |
-
INSERT INTO $catalog_category_entity_int
|
1859 |
-
(
|
1860 |
-
entity_type_id,
|
1861 |
-
attribute_id,
|
1862 |
-
store_id,
|
1863 |
-
entity_id,
|
1864 |
-
value
|
1865 |
-
)
|
1866 |
-
(SELECT
|
1867 |
-
$_categoryEntityTypeId,
|
1868 |
-
$attr_include_in_menu,
|
1869 |
-
0,
|
1870 |
-
scm.shop_entity_id,
|
1871 |
-
1
|
1872 |
-
FROM $categories_temp c
|
1873 |
-
JOIN $stINch_categories_mapping scm
|
1874 |
-
ON c.store_category_id = scm.store_category_id
|
1875 |
-
)
|
1876 |
-
ON DUPLICATE KEY UPDATE
|
1877 |
-
value = 1";
|
1878 |
-
$this->db_do($q);
|
1879 |
-
|
1880 |
-
|
1881 |
-
$q = "
|
1882 |
-
INSERT INTO $catalog_category_entity_int
|
1883 |
-
(
|
1884 |
-
entity_type_id,
|
1885 |
-
attribute_id,
|
1886 |
-
store_id,
|
1887 |
-
entity_id,
|
1888 |
-
value
|
1889 |
-
)
|
1890 |
-
(SELECT
|
1891 |
-
$_categoryEntityTypeId,
|
1892 |
-
$is_anchor_attrid,
|
1893 |
-
1,
|
1894 |
-
scm.shop_entity_id,
|
1895 |
-
1
|
1896 |
-
FROM $categories_temp c
|
1897 |
-
JOIN $stINch_categories_mapping scm
|
1898 |
-
ON c.store_category_id = scm.store_category_id
|
1899 |
-
)
|
1900 |
-
ON DUPLICATE KEY UPDATE
|
1901 |
-
value = 1";
|
1902 |
-
$this->db_do($q);
|
1903 |
-
|
1904 |
-
|
1905 |
-
$q = "
|
1906 |
-
INSERT INTO $catalog_category_entity_int
|
1907 |
-
(
|
1908 |
-
entity_type_id,
|
1909 |
-
attribute_id,
|
1910 |
-
store_id,
|
1911 |
-
entity_id,
|
1912 |
-
value
|
1913 |
-
)
|
1914 |
-
(SELECT
|
1915 |
-
$_categoryEntityTypeId,
|
1916 |
-
$is_anchor_attrid,
|
1917 |
-
0,
|
1918 |
-
scm.shop_entity_id,
|
1919 |
-
1
|
1920 |
-
FROM $categories_temp c
|
1921 |
-
JOIN $stINch_categories_mapping scm
|
1922 |
-
ON c.store_category_id = scm.store_category_id
|
1923 |
-
)
|
1924 |
-
ON DUPLICATE KEY UPDATE
|
1925 |
-
value = 1";
|
1926 |
-
$this->db_do($q);
|
1927 |
-
|
1928 |
-
$q = "
|
1929 |
-
INSERT INTO $catalog_category_entity_varchar
|
1930 |
-
(
|
1931 |
-
entity_type_id,
|
1932 |
-
attribute_id,
|
1933 |
-
store_id,
|
1934 |
-
entity_id,
|
1935 |
-
value
|
1936 |
-
)
|
1937 |
-
(SELECT
|
1938 |
-
$_categoryEntityTypeId,
|
1939 |
-
$image_attrid,
|
1940 |
-
0,
|
1941 |
-
scm.shop_entity_id,
|
1942 |
-
c.categories_image
|
1943 |
-
FROM $categories_temp c
|
1944 |
-
JOIN $stINch_categories_mapping scm
|
1945 |
-
ON c.store_category_id = scm.store_category_id
|
1946 |
-
)
|
1947 |
-
ON DUPLICATE KEY UPDATE
|
1948 |
-
value = c.categories_image";
|
1949 |
-
$this->db_do($q);
|
1950 |
-
}
|
1951 |
-
else
|
1952 |
-
{
|
1953 |
-
echo "Insert ignore category_data \n";
|
1954 |
-
|
1955 |
-
$q = "
|
1956 |
-
INSERT IGNORE INTO $catalog_category_entity_varchar
|
1957 |
-
(
|
1958 |
-
entity_type_id,
|
1959 |
-
attribute_id,
|
1960 |
-
store_id,
|
1961 |
-
entity_id,
|
1962 |
-
value
|
1963 |
-
)
|
1964 |
-
(SELECT
|
1965 |
-
$_categoryEntityTypeId,
|
1966 |
-
$name_attrid,
|
1967 |
-
0,
|
1968 |
-
scm.shop_entity_id,
|
1969 |
-
c.category_name
|
1970 |
-
FROM $categories_temp c
|
1971 |
-
JOIN $stINch_categories_mapping scm
|
1972 |
-
ON c.store_category_id = scm.store_category_id
|
1973 |
-
)";
|
1974 |
-
$this->db_do($q);
|
1975 |
-
|
1976 |
-
|
1977 |
-
$q = "
|
1978 |
-
INSERT IGNORE INTO $catalog_category_entity_int
|
1979 |
-
(
|
1980 |
-
entity_type_id,
|
1981 |
-
attribute_id,
|
1982 |
-
store_id,
|
1983 |
-
entity_id,
|
1984 |
-
value
|
1985 |
-
)
|
1986 |
-
(SELECT
|
1987 |
-
$_categoryEntityTypeId,
|
1988 |
-
$attr_is_active,
|
1989 |
-
0,
|
1990 |
-
scm.shop_entity_id,
|
1991 |
-
1
|
1992 |
-
FROM $categories_temp c
|
1993 |
-
JOIN $stINch_categories_mapping scm
|
1994 |
-
ON c.store_category_id = scm.store_category_id
|
1995 |
-
)";
|
1996 |
-
$this->db_do($q);
|
1997 |
-
|
1998 |
-
|
1999 |
-
$q = "
|
2000 |
-
INSERT IGNORE INTO $catalog_category_entity_int
|
2001 |
-
(
|
2002 |
-
entity_type_id,
|
2003 |
-
attribute_id,
|
2004 |
-
store_id,
|
2005 |
-
entity_id,
|
2006 |
-
value
|
2007 |
-
)
|
2008 |
-
(SELECT
|
2009 |
-
$_categoryEntityTypeId,
|
2010 |
-
$attr_include_in_menu,
|
2011 |
-
0,
|
2012 |
-
scm.shop_entity_id,
|
2013 |
-
1
|
2014 |
-
FROM $categories_temp c
|
2015 |
-
JOIN $stINch_categories_mapping scm
|
2016 |
-
ON c.store_category_id = scm.store_category_id
|
2017 |
-
)";
|
2018 |
-
$this->db_do($q);
|
2019 |
-
|
2020 |
-
|
2021 |
-
$q = "
|
2022 |
-
INSERT IGNORE INTO $catalog_category_entity_int
|
2023 |
-
(
|
2024 |
-
entity_type_id,
|
2025 |
-
attribute_id,
|
2026 |
-
store_id,
|
2027 |
-
entity_id,
|
2028 |
-
value
|
2029 |
-
)
|
2030 |
-
(SELECT
|
2031 |
-
$_categoryEntityTypeId,
|
2032 |
-
$is_anchor_attrid,
|
2033 |
-
0,
|
2034 |
-
scm.shop_entity_id,
|
2035 |
-
1
|
2036 |
-
FROM $categories_temp c
|
2037 |
-
JOIN $stINch_categories_mapping scm
|
2038 |
-
ON c.store_category_id = scm.store_category_id
|
2039 |
-
)";
|
2040 |
-
$this->db_do($q);
|
2041 |
-
|
2042 |
-
|
2043 |
-
$q = "
|
2044 |
-
INSERT IGNORE INTO $catalog_category_entity_varchar
|
2045 |
-
(
|
2046 |
-
entity_type_id,
|
2047 |
-
attribute_id,
|
2048 |
-
store_id,
|
2049 |
-
entity_id,
|
2050 |
-
value
|
2051 |
-
)
|
2052 |
-
(SELECT
|
2053 |
-
$_categoryEntityTypeId,
|
2054 |
-
$image_attrid,
|
2055 |
-
0,
|
2056 |
-
scm.shop_entity_id,
|
2057 |
-
c.categories_image
|
2058 |
-
FROM $categories_temp c
|
2059 |
-
JOIN $stINch_categories_mapping scm
|
2060 |
-
ON c.store_category_id = scm.store_category_id
|
2061 |
-
)";
|
2062 |
-
$this->db_do($q);
|
2063 |
-
}
|
2064 |
-
|
2065 |
-
$this->delete_old_sinch_categories_from_shop();
|
2066 |
-
$this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
|
2067 |
-
$this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
|
2068 |
-
} // private function addCategoryDataMultistore(...)
|
2069 |
-
################################################################################################################################################################
|
2070 |
-
|
2071 |
-
|
2072 |
-
|
2073 |
-
################################################################################################################################################################
|
2074 |
-
function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
|
2075 |
-
{
|
2076 |
-
|
2077 |
-
//echo("\nparent_id = [$parent_id] ent_id = [$ent_id]");
|
2078 |
-
|
2079 |
-
$path = '';
|
2080 |
-
|
2081 |
-
$cat_id = $parent_id;
|
2082 |
-
|
2083 |
-
$q = "
|
2084 |
-
SELECT
|
2085 |
-
parent_id
|
2086 |
-
FROM $catalog_category_entity
|
2087 |
-
WHERE entity_id = $cat_id";
|
2088 |
-
$quer = $this->db_do($q);
|
2089 |
-
$row = mysqli_fetch_array($quer);
|
2090 |
-
while ($row['parent_id'])
|
2091 |
-
{
|
2092 |
-
$path = $row['parent_id'].'/'.$path;
|
2093 |
-
$parent_id = $row['parent_id'];
|
2094 |
-
|
2095 |
-
$q = "
|
2096 |
-
SELECT
|
2097 |
-
parent_id
|
2098 |
-
FROM $catalog_category_entity
|
2099 |
-
WHERE entity_id = $parent_id";
|
2100 |
-
$quer = $this->db_do($q);
|
2101 |
-
$row = mysqli_fetch_array($quer);
|
2102 |
-
}
|
2103 |
-
|
2104 |
-
if ($cat_id) $path.=$cat_id."/";
|
2105 |
-
|
2106 |
-
if ($path) $path .= $ent_id;
|
2107 |
-
else $path = $ent_id;
|
2108 |
-
|
2109 |
-
//echo(" path = [$path]\n");
|
2110 |
-
|
2111 |
-
return $path;
|
2112 |
-
} // function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
|
2113 |
-
################################################################################################################################################################
|
2114 |
-
|
2115 |
-
|
2116 |
-
|
2117 |
-
################################################################################################################################################################
|
2118 |
-
public function replaceMagentoProductsMultistore($coincidence)
|
2119 |
-
{
|
2120 |
-
|
2121 |
-
echo("\n replaceMagentoProductsMultistore 1\n");
|
2122 |
-
|
2123 |
-
$connection = Mage::getModel('core/resource')->getConnection('core_write');
|
2124 |
-
|
2125 |
-
|
2126 |
-
$products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
|
2127 |
-
$products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
|
2128 |
-
$catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
|
2129 |
-
$catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
|
2130 |
-
$catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
|
2131 |
-
$catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
|
2132 |
-
$stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
|
2133 |
-
$catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
|
2134 |
-
$stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
|
2135 |
-
$catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
|
2136 |
-
$core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
|
2137 |
-
$catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
|
2138 |
-
$catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
|
2139 |
-
$catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
|
2140 |
-
$catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
|
2141 |
-
$catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
|
2142 |
-
|
2143 |
-
$_getProductEntityTypeId = $this->_getProductEntityTypeId();
|
2144 |
-
$_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
|
2145 |
-
|
2146 |
-
$attr_atatus = $this->_getProductAttributeId('status');
|
2147 |
-
$attr_name = $this->_getProductAttributeId('name');
|
2148 |
-
$attr_visibility = $this->_getProductAttributeId('visibility');
|
2149 |
-
$attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
|
2150 |
-
$attr_image = $this->_getProductAttributeId('image');
|
2151 |
-
$attr_small_image = $this->_getProductAttributeId('small_image');
|
2152 |
-
$attr_thumbnail = $this->_getProductAttributeId('thumbnail');
|
2153 |
-
|
2154 |
-
$cat_attr_name = $this->_getCategoryAttributeId('name');
|
2155 |
-
echo("\n replaceMagentoProductsMultistore 2\n");
|
2156 |
-
|
2157 |
-
//clear products, inserting new products and updating old others.
|
2158 |
-
$result = $this->db_do("
|
2159 |
-
DELETE cpe
|
2160 |
-
FROM $catalog_product_entity cpe
|
2161 |
-
JOIN $stINch_products_mapping pm
|
2162 |
-
ON cpe.entity_id = pm.entity_id
|
2163 |
-
WHERE pm.shop_store_product_id IS NOT NULL
|
2164 |
-
AND pm.store_product_id IS NULL");
|
2165 |
-
|
2166 |
-
|
2167 |
-
|
2168 |
-
echo("\n replaceMagentoProductsMultistore 3\n");
|
2169 |
-
|
2170 |
-
$result = $this->db_do("
|
2171 |
-
INSERT INTO $catalog_product_entity
|
2172 |
-
(entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
|
2173 |
-
(SELECT
|
2174 |
-
pm.entity_id,
|
2175 |
-
$_getProductEntityTypeId,
|
2176 |
-
$_defaultAttributeSetId,
|
2177 |
-
'simple',
|
2178 |
-
a.product_sku,
|
2179 |
-
NOW(),
|
2180 |
-
0,
|
2181 |
-
a.store_product_id,
|
2182 |
-
a.sinch_product_id
|
2183 |
-
FROM $products_temp a
|
2184 |
-
LEFT JOIN $stINch_products_mapping pm
|
2185 |
-
ON a.store_product_id = pm.store_product_id
|
2186 |
-
AND a.sinch_product_id = pm.sinch_product_id
|
2187 |
-
)
|
2188 |
-
ON DUPLICATE KEY UPDATE
|
2189 |
-
sku = a.product_sku,
|
2190 |
-
store_product_id = a.store_product_id,
|
2191 |
-
sinch_product_id = a.sinch_product_id");
|
2192 |
-
// store_product_id = a.store_product_id,
|
2193 |
-
// sinch_product_id = a.sinch_product_id
|
2194 |
-
|
2195 |
-
echo("\n replaceMagentoProductsMultistore 4\n");
|
2196 |
-
|
2197 |
-
|
2198 |
-
//Set enabled
|
2199 |
-
$result = $this->db_do("
|
2200 |
-
DELETE cpei
|
2201 |
-
FROM $catalog_product_entity_int cpei
|
2202 |
-
LEFT JOIN $catalog_product_entity cpe
|
2203 |
-
ON cpei.entity_id = cpe.entity_id
|
2204 |
-
WHERE cpe.entity_id IS NULL");
|
2205 |
-
|
2206 |
-
$result = $this->db_do("
|
2207 |
-
INSERT INTO $catalog_product_entity_int
|
2208 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2209 |
-
(SELECT
|
2210 |
-
$_getProductEntityTypeId,
|
2211 |
-
$attr_atatus,
|
2212 |
-
w.website,
|
2213 |
-
a.entity_id,
|
2214 |
-
1
|
2215 |
-
FROM $catalog_product_entity a
|
2216 |
-
JOIN $products_website_temp w
|
2217 |
-
ON a.store_product_id = w.store_product_id
|
2218 |
-
)
|
2219 |
-
ON DUPLICATE KEY UPDATE
|
2220 |
-
value = 1");
|
2221 |
-
|
2222 |
-
//___ return.
|
2223 |
-
|
2224 |
-
echo("\n replaceMagentoProductsMultistore 5\n");
|
2225 |
-
|
2226 |
-
|
2227 |
-
// set status = 1 for all stores
|
2228 |
-
$result = $this->db_do("
|
2229 |
-
INSERT INTO $catalog_product_entity_int
|
2230 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2231 |
-
(SELECT
|
2232 |
-
$_getProductEntityTypeId,
|
2233 |
-
$attr_atatus,
|
2234 |
-
0,
|
2235 |
-
a.entity_id,
|
2236 |
-
1
|
2237 |
-
FROM $catalog_product_entity a
|
2238 |
-
)
|
2239 |
-
ON DUPLICATE KEY UPDATE
|
2240 |
-
value = 1");
|
2241 |
-
|
2242 |
-
echo("\n replaceMagentoProductsMultistore 6\n");
|
2243 |
-
|
2244 |
-
|
2245 |
-
//Unifying products with categories.
|
2246 |
-
$result = $this->db_do("
|
2247 |
-
DELETE ccp
|
2248 |
-
FROM $catalog_category_product ccp
|
2249 |
-
LEFT JOIN $catalog_product_entity cpe
|
2250 |
-
ON ccp.product_id = cpe.entity_id
|
2251 |
-
WHERE cpe.entity_id IS NULL");
|
2252 |
-
|
2253 |
-
|
2254 |
-
echo("\n replaceMagentoProductsMultistore 7\n");
|
2255 |
-
|
2256 |
-
|
2257 |
-
$result = $this->db_do("DROP TABLE IF EXISTS root_cats");
|
2258 |
-
$result = $this->db_do("
|
2259 |
-
CREATE TABLE root_cats
|
2260 |
-
SELECT
|
2261 |
-
entity_id,
|
2262 |
-
path,
|
2263 |
-
SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
|
2264 |
-
LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
|
2265 |
-
SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
|
2266 |
-
FROM catalog_category_entity
|
2267 |
-
");
|
2268 |
-
$result = $this->db_do("UPDATE root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
|
2269 |
-
|
2270 |
-
|
2271 |
-
echo("\n replaceMagentoProductsMultistore 8\n");
|
2272 |
-
|
2273 |
-
|
2274 |
-
// !!! $this->_root_cat
|
2275 |
-
$result = $this->db_do("
|
2276 |
-
UPDATE IGNORE $catalog_category_product ccp
|
2277 |
-
LEFT JOIN $catalog_category_entity cce
|
2278 |
-
ON ccp.category_id = cce.entity_id
|
2279 |
-
JOIN root_cats rc
|
2280 |
-
ON cce.entity_id = rc.entity_id
|
2281 |
-
SET ccp.category_id = rc.root_cat
|
2282 |
-
WHERE cce.entity_id IS NULL");
|
2283 |
-
|
2284 |
-
|
2285 |
-
|
2286 |
-
echo("\n replaceMagentoProductsMultistore 9\n");
|
2287 |
-
|
2288 |
-
|
2289 |
-
|
2290 |
-
|
2291 |
-
$result = $this->db_do("
|
2292 |
-
DELETE ccp
|
2293 |
-
FROM $catalog_category_product ccp
|
2294 |
-
LEFT JOIN $catalog_category_entity cce
|
2295 |
-
ON ccp.category_id = cce.entity_id
|
2296 |
-
WHERE cce.entity_id IS NULL");
|
2297 |
-
|
2298 |
-
|
2299 |
-
echo("\n replaceMagentoProductsMultistore 10\n");
|
2300 |
-
|
2301 |
-
|
2302 |
-
|
2303 |
-
// TEMPORARY
|
2304 |
-
$this->db_do(" DROP TABLE IF EXISTS {$catalog_category_product}_for_delete_temp");
|
2305 |
-
$this->db_do("
|
2306 |
-
CREATE TABLE `{$catalog_category_product}_for_delete_temp`
|
2307 |
-
(
|
2308 |
-
`category_id` int(10) unsigned NOT NULL default '0',
|
2309 |
-
`product_id` int(10) unsigned NOT NULL default '0',
|
2310 |
-
`store_product_id` int(10) NOT NULL default '0',
|
2311 |
-
`store_category_id` int(10) NOT NULL default '0',
|
2312 |
-
`new_category_id` int(10) NOT NULL default '0',
|
2313 |
-
|
2314 |
-
UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
|
2315 |
-
KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
|
2316 |
-
KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
|
2317 |
-
KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
|
2318 |
-
)");
|
2319 |
-
|
2320 |
-
echo("\n replaceMagentoProductsMultistore 11\n");
|
2321 |
-
|
2322 |
-
$result = $this->db_do("
|
2323 |
-
INSERT INTO {$catalog_category_product}_for_delete_temp
|
2324 |
-
(category_id, product_id, store_product_id)
|
2325 |
-
(SELECT
|
2326 |
-
ccp.category_id,
|
2327 |
-
ccp.product_id,
|
2328 |
-
cpe.store_product_id
|
2329 |
-
FROM $catalog_category_product ccp
|
2330 |
-
JOIN $catalog_product_entity cpe
|
2331 |
-
ON ccp.product_id = cpe.entity_id
|
2332 |
-
WHERE store_product_id IS NOT NULL)");
|
2333 |
-
|
2334 |
-
echo("\n replaceMagentoProductsMultistore 12\n");
|
2335 |
-
|
2336 |
-
$result = $this->db_do("
|
2337 |
-
UPDATE {$catalog_category_product}_for_delete_temp ccpfd
|
2338 |
-
JOIN $products_temp p
|
2339 |
-
ON ccpfd.store_product_id = p.store_product_id
|
2340 |
-
SET ccpfd.store_category_id = p.store_category_id
|
2341 |
-
WHERE ccpfd.store_product_id != 0");
|
2342 |
-
|
2343 |
-
echo("\n replaceMagentoProductsMultistore 13\n");
|
2344 |
-
|
2345 |
-
$result = $this->db_do("
|
2346 |
-
UPDATE {$catalog_category_product}_for_delete_temp ccpfd
|
2347 |
-
JOIN $stINch_categories_mapping scm
|
2348 |
-
ON ccpfd.store_category_id = scm.store_category_id
|
2349 |
-
SET ccpfd.new_category_id = scm.shop_entity_id
|
2350 |
-
WHERE ccpfd.store_category_id != 0");
|
2351 |
-
|
2352 |
-
echo("\n replaceMagentoProductsMultistore 14\n");
|
2353 |
-
|
2354 |
-
$result = $this->db_do("DELETE FROM {$catalog_category_product}_for_delete_temp WHERE category_id = new_category_id");
|
2355 |
-
|
2356 |
-
$result = $this->db_do("
|
2357 |
-
DELETE ccp
|
2358 |
-
FROM $catalog_category_product ccp
|
2359 |
-
JOIN {$catalog_category_product}_for_delete_temp ccpfd
|
2360 |
-
ON ccp.product_id = ccpfd.product_id
|
2361 |
-
AND ccp.category_id = ccpfd.category_id");
|
2362 |
-
|
2363 |
-
echo("\n replaceMagentoProductsMultistore 15\n");
|
2364 |
-
|
2365 |
-
$result = $this->db_do("
|
2366 |
-
INSERT INTO $catalog_category_product
|
2367 |
-
(category_id, product_id)
|
2368 |
-
(SELECT
|
2369 |
-
scm.shop_entity_id,
|
2370 |
-
cpe.entity_id
|
2371 |
-
FROM $catalog_product_entity cpe
|
2372 |
-
JOIN $products_temp p
|
2373 |
-
ON cpe.store_product_id = p.store_product_id
|
2374 |
-
JOIN $stINch_categories_mapping scm
|
2375 |
-
ON p.store_category_id = scm.store_category_id
|
2376 |
-
)
|
2377 |
-
ON DUPLICATE KEY UPDATE
|
2378 |
-
product_id = cpe.entity_id");
|
2379 |
-
|
2380 |
-
echo("\n replaceMagentoProductsMultistore 16\n");
|
2381 |
-
|
2382 |
-
//Indexing products and categories in the shop
|
2383 |
-
$result = $this->db_do("
|
2384 |
-
DELETE ccpi
|
2385 |
-
FROM $catalog_category_product_index ccpi
|
2386 |
-
LEFT JOIN $catalog_product_entity cpe
|
2387 |
-
ON ccpi.product_id = cpe.entity_id
|
2388 |
-
WHERE cpe.entity_id IS NULL");
|
2389 |
-
|
2390 |
-
|
2391 |
-
|
2392 |
-
echo("\n replaceMagentoProductsMultistore 16.2\n");
|
2393 |
-
|
2394 |
-
|
2395 |
-
$result = $this->db_do("
|
2396 |
-
INSERT INTO $catalog_category_product_index
|
2397 |
-
(category_id, product_id, position, is_parent, store_id, visibility)
|
2398 |
-
(SELECT
|
2399 |
-
a.category_id,
|
2400 |
-
a.product_id,
|
2401 |
-
a.position,
|
2402 |
-
1,
|
2403 |
-
b.store_id,
|
2404 |
-
4
|
2405 |
-
FROM $catalog_category_product a
|
2406 |
-
JOIN $core_store b
|
2407 |
-
)
|
2408 |
-
ON DUPLICATE KEY UPDATE
|
2409 |
-
visibility = 4");
|
2410 |
-
|
2411 |
-
echo("\n replaceMagentoProductsMultistore 17\n");
|
2412 |
-
|
2413 |
-
// !!! $this->_root_cat
|
2414 |
-
$result = $this->db_do("
|
2415 |
-
INSERT ignore INTO $catalog_category_product_index
|
2416 |
-
(category_id, product_id, position, is_parent, store_id, visibility)
|
2417 |
-
(SELECT
|
2418 |
-
rc.root_cat,
|
2419 |
-
a.product_id,
|
2420 |
-
a.position,
|
2421 |
-
1,
|
2422 |
-
b.store_id,
|
2423 |
-
4
|
2424 |
-
FROM $catalog_category_product a
|
2425 |
-
JOIN root_cats rc
|
2426 |
-
ON a.category_id = rc.entity_id
|
2427 |
-
JOIN $core_store b
|
2428 |
-
)
|
2429 |
-
ON DUPLICATE KEY UPDATE
|
2430 |
-
visibility = 4");
|
2431 |
-
|
2432 |
-
echo("\n replaceMagentoProductsMultistore 18\n");
|
2433 |
-
|
2434 |
-
|
2435 |
-
//Set product name for specific web sites
|
2436 |
-
$result = $this->db_do("
|
2437 |
-
DELETE cpev
|
2438 |
-
FROM $catalog_product_entity_varchar cpev
|
2439 |
-
LEFT JOIN $catalog_product_entity cpe
|
2440 |
-
ON cpev.entity_id = cpe.entity_id
|
2441 |
-
WHERE cpe.entity_id IS NULL");
|
2442 |
-
|
2443 |
-
$result = $this->db_do("
|
2444 |
-
INSERT INTO $catalog_product_entity_varchar
|
2445 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2446 |
-
(SELECT
|
2447 |
-
$_getProductEntityTypeId,
|
2448 |
-
$attr_name,
|
2449 |
-
w.website,
|
2450 |
-
a.entity_id,
|
2451 |
-
b.product_name
|
2452 |
-
FROM $catalog_product_entity a
|
2453 |
-
JOIN $products_temp b
|
2454 |
-
ON a.store_product_id = b.store_product_id
|
2455 |
-
JOIN $products_website_temp w
|
2456 |
-
ON a.store_product_id = w.store_product_id
|
2457 |
-
)
|
2458 |
-
ON DUPLICATE KEY UPDATE
|
2459 |
-
value = b.product_name");
|
2460 |
-
|
2461 |
-
echo("\n replaceMagentoProductsMultistore 19\n");
|
2462 |
-
|
2463 |
-
|
2464 |
-
// product name for all web sites
|
2465 |
-
$result = $this->db_do("
|
2466 |
-
INSERT INTO $catalog_product_entity_varchar
|
2467 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2468 |
-
(SELECT
|
2469 |
-
$_getProductEntityTypeId,
|
2470 |
-
$attr_name,
|
2471 |
-
0,
|
2472 |
-
a.entity_id,
|
2473 |
-
b.product_name
|
2474 |
-
FROM $catalog_product_entity a
|
2475 |
-
JOIN $products_temp b
|
2476 |
-
ON a.store_product_id = b.store_product_id
|
2477 |
-
)
|
2478 |
-
ON DUPLICATE KEY UPDATE
|
2479 |
-
value = b.product_name");
|
2480 |
-
|
2481 |
-
echo("\n replaceMagentoProductsMultistore 20\n");
|
2482 |
-
|
2483 |
-
$this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
|
2484 |
-
$this->addDescriptions();
|
2485 |
-
$this->addShortDescriptions();
|
2486 |
-
$this->addEAN();
|
2487 |
-
$this->addSpecification();
|
2488 |
-
$this->addManufacturers();
|
2489 |
-
|
2490 |
-
echo("\n replaceMagentoProductsMultistore 21\n");
|
2491 |
-
|
2492 |
-
//Enabling product index.
|
2493 |
-
$result = $this->db_do("
|
2494 |
-
DELETE cpei
|
2495 |
-
FROM $catalog_product_enabled_index cpei
|
2496 |
-
LEFT JOIN $catalog_product_entity cpe
|
2497 |
-
ON cpei.product_id = cpe.entity_id
|
2498 |
-
WHERE cpe.entity_id IS NULL");
|
2499 |
-
|
2500 |
-
echo("\n replaceMagentoProductsMultistore 22\n");
|
2501 |
-
|
2502 |
-
$result = $this->db_do("
|
2503 |
-
INSERT INTO $catalog_product_enabled_index
|
2504 |
-
(product_id, store_id, visibility)
|
2505 |
-
(SELECT
|
2506 |
-
a.entity_id,
|
2507 |
-
w.website,
|
2508 |
-
4
|
2509 |
-
FROM $catalog_product_entity a
|
2510 |
-
JOIN $products_website_temp w
|
2511 |
-
ON a.store_product_id = w.store_product_id
|
2512 |
-
)
|
2513 |
-
ON DUPLICATE KEY UPDATE
|
2514 |
-
visibility = 4");
|
2515 |
-
|
2516 |
-
echo("\n replaceMagentoProductsMultistore 23\n");
|
2517 |
-
|
2518 |
-
$result = $this->db_do("
|
2519 |
-
INSERT INTO $catalog_product_enabled_index
|
2520 |
-
(product_id, store_id, visibility)
|
2521 |
-
(SELECT
|
2522 |
-
a.entity_id,
|
2523 |
-
0,
|
2524 |
-
4
|
2525 |
-
FROM $catalog_product_entity a
|
2526 |
-
JOIN $products_website_temp w
|
2527 |
-
ON a.store_product_id = w.store_product_id
|
2528 |
-
)
|
2529 |
-
ON DUPLICATE KEY UPDATE
|
2530 |
-
visibility = 4");
|
2531 |
-
|
2532 |
-
echo("\n replaceMagentoProductsMultistore 24\n");
|
2533 |
-
|
2534 |
-
$result = $this->db_do("
|
2535 |
-
INSERT INTO $catalog_product_entity_int
|
2536 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2537 |
-
(SELECT
|
2538 |
-
$_getProductEntityTypeId,
|
2539 |
-
$attr_visibility,
|
2540 |
-
w.website,
|
2541 |
-
a.entity_id,
|
2542 |
-
4
|
2543 |
-
FROM $catalog_product_entity a
|
2544 |
-
JOIN $products_website_temp w
|
2545 |
-
ON a.store_product_id = w.store_product_id
|
2546 |
-
)
|
2547 |
-
ON DUPLICATE KEY UPDATE
|
2548 |
-
value = 4");
|
2549 |
-
|
2550 |
-
echo("\n replaceMagentoProductsMultistore 25\n");
|
2551 |
-
|
2552 |
-
$result = $this->db_do("
|
2553 |
-
INSERT INTO $catalog_product_entity_int
|
2554 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2555 |
-
(SELECT
|
2556 |
-
$_getProductEntityTypeId,
|
2557 |
-
$attr_visibility,
|
2558 |
-
0,
|
2559 |
-
a.entity_id,
|
2560 |
-
4
|
2561 |
-
FROM $catalog_product_entity a
|
2562 |
-
)
|
2563 |
-
ON DUPLICATE KEY UPDATE
|
2564 |
-
value = 4");
|
2565 |
-
|
2566 |
-
echo("\n replaceMagentoProductsMultistore 26\n");
|
2567 |
-
|
2568 |
-
$result = $this->db_do("
|
2569 |
-
DELETE cpw
|
2570 |
-
FROM $catalog_product_website cpw
|
2571 |
-
LEFT JOIN $catalog_product_entity cpe
|
2572 |
-
ON cpw.product_id = cpe.entity_id
|
2573 |
-
WHERE cpe.entity_id IS NULL");
|
2574 |
-
|
2575 |
-
echo("\n replaceMagentoProductsMultistore 27\n");
|
2576 |
-
|
2577 |
-
$result = $this->db_do("
|
2578 |
-
INSERT INTO $catalog_product_website
|
2579 |
-
(product_id, website_id)
|
2580 |
-
(SELECT
|
2581 |
-
a.entity_id,
|
2582 |
-
w.website_id
|
2583 |
-
FROM $catalog_product_entity a
|
2584 |
-
JOIN $products_website_temp w
|
2585 |
-
ON a.store_product_id = w.store_product_id
|
2586 |
-
)
|
2587 |
-
ON DUPLICATE KEY UPDATE
|
2588 |
-
product_id = a.entity_id,
|
2589 |
-
website_id = w.website_id");
|
2590 |
-
|
2591 |
-
echo("\n replaceMagentoProductsMultistore 28\n");
|
2592 |
-
|
2593 |
-
// temporary disabled mart@bintime.com
|
2594 |
-
//$result = $this->db_do("
|
2595 |
-
// UPDATE catalog_category_entity_int a
|
2596 |
-
// SET a.value = 0
|
2597 |
-
// WHERE a.attribute_id = 32
|
2598 |
-
//");
|
2599 |
-
|
2600 |
-
|
2601 |
-
//Adding tax class "Taxable Goods"
|
2602 |
-
$result = $this->db_do("
|
2603 |
-
INSERT INTO $catalog_product_entity_int
|
2604 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2605 |
-
(SELECT
|
2606 |
-
$_getProductEntityTypeId,
|
2607 |
-
$attr_tax_class_id,
|
2608 |
-
w.website,
|
2609 |
-
a.entity_id,
|
2610 |
-
2
|
2611 |
-
FROM $catalog_product_entity a
|
2612 |
-
JOIN $products_website_temp w
|
2613 |
-
ON a.store_product_id = w.store_product_id
|
2614 |
-
)
|
2615 |
-
ON DUPLICATE KEY UPDATE
|
2616 |
-
value = 2");
|
2617 |
-
|
2618 |
-
echo("\n replaceMagentoProductsMultistore 29\n");
|
2619 |
-
|
2620 |
-
$result = $this->db_do("
|
2621 |
-
INSERT INTO $catalog_product_entity_int
|
2622 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2623 |
-
(SELECT
|
2624 |
-
$_getProductEntityTypeId,
|
2625 |
-
$attr_tax_class_id,
|
2626 |
-
0,
|
2627 |
-
a.entity_id,
|
2628 |
-
2
|
2629 |
-
FROM $catalog_product_entity a
|
2630 |
-
)
|
2631 |
-
ON DUPLICATE KEY UPDATE
|
2632 |
-
value = 2");
|
2633 |
-
|
2634 |
-
echo("\n replaceMagentoProductsMultistore 30\n");
|
2635 |
-
|
2636 |
-
// Load url Image
|
2637 |
-
$result = $this->db_do("
|
2638 |
-
INSERT INTO $catalog_product_entity_varchar
|
2639 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2640 |
-
(SELECT
|
2641 |
-
$_getProductEntityTypeId,
|
2642 |
-
$attr_image,
|
2643 |
-
w.store_id,
|
2644 |
-
a.entity_id,
|
2645 |
-
b.main_image_url
|
2646 |
-
FROM $catalog_product_entity a
|
2647 |
-
JOIN $core_store w
|
2648 |
-
JOIN $products_temp b
|
2649 |
-
ON a.store_product_id = b.store_product_id
|
2650 |
-
)
|
2651 |
-
ON DUPLICATE KEY UPDATE
|
2652 |
-
value = b.main_image_url");
|
2653 |
-
|
2654 |
-
echo("\n replaceMagentoProductsMultistore 31\n");
|
2655 |
-
|
2656 |
-
// image for specific web sites
|
2657 |
-
$result = $this->db_do("
|
2658 |
-
INSERT INTO $catalog_product_entity_varchar
|
2659 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2660 |
-
(SELECT
|
2661 |
-
$_getProductEntityTypeId,
|
2662 |
-
$attr_image,
|
2663 |
-
0,
|
2664 |
-
a.entity_id,
|
2665 |
-
b.main_image_url
|
2666 |
-
FROM $catalog_product_entity a
|
2667 |
-
JOIN $products_temp b
|
2668 |
-
ON a.store_product_id = b.store_product_id
|
2669 |
-
)
|
2670 |
-
ON DUPLICATE KEY UPDATE
|
2671 |
-
value = b.main_image_url");
|
2672 |
-
|
2673 |
-
echo("\n replaceMagentoProductsMultistore 32\n");
|
2674 |
-
|
2675 |
-
// small_image for specific web sites
|
2676 |
-
$result = $this->db_do("
|
2677 |
-
INSERT INTO $catalog_product_entity_varchar
|
2678 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2679 |
-
(SELECT
|
2680 |
-
$_getProductEntityTypeId,
|
2681 |
-
$attr_small_image,
|
2682 |
-
w.store_id,
|
2683 |
-
a.entity_id,
|
2684 |
-
b.medium_image_url
|
2685 |
-
FROM $catalog_product_entity a
|
2686 |
-
JOIN $core_store w
|
2687 |
-
JOIN $products_temp b
|
2688 |
-
ON a.store_product_id = b.store_product_id
|
2689 |
-
)
|
2690 |
-
ON DUPLICATE KEY UPDATE
|
2691 |
-
value = b.medium_image_url");
|
2692 |
-
|
2693 |
-
echo("\n replaceMagentoProductsMultistore 33\n");
|
2694 |
-
|
2695 |
-
// small_image for all web sites
|
2696 |
-
$result = $this->db_do("
|
2697 |
-
INSERT INTO $catalog_product_entity_varchar
|
2698 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2699 |
-
(SELECT
|
2700 |
-
$_getProductEntityTypeId,
|
2701 |
-
$attr_small_image,
|
2702 |
-
0,
|
2703 |
-
a.entity_id,
|
2704 |
-
b.medium_image_url
|
2705 |
-
FROM $catalog_product_entity a
|
2706 |
-
JOIN $core_store w
|
2707 |
-
JOIN $products_temp b
|
2708 |
-
ON a.store_product_id = b.store_product_id
|
2709 |
-
)
|
2710 |
-
ON DUPLICATE KEY UPDATE
|
2711 |
-
value = b.medium_image_url");
|
2712 |
-
|
2713 |
-
echo("\n replaceMagentoProductsMultistore 34\n");
|
2714 |
-
|
2715 |
-
// thumbnail for specific web site
|
2716 |
-
$result = $this->db_do("
|
2717 |
-
INSERT INTO $catalog_product_entity_varchar
|
2718 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2719 |
-
(SELECT
|
2720 |
-
$_getProductEntityTypeId,
|
2721 |
-
$attr_thumbnail,
|
2722 |
-
w.store_id,
|
2723 |
-
a.entity_id,
|
2724 |
-
b.thumb_image_url
|
2725 |
-
FROM $catalog_product_entity a
|
2726 |
-
JOIN $core_store w
|
2727 |
-
JOIN $products_temp b
|
2728 |
-
ON a.store_product_id = b.store_product_id
|
2729 |
-
)
|
2730 |
-
ON DUPLICATE KEY UPDATE
|
2731 |
-
value = b.thumb_image_url");
|
2732 |
-
|
2733 |
-
echo("\n replaceMagentoProductsMultistore 35\n");
|
2734 |
-
|
2735 |
-
// thumbnail for all web sites
|
2736 |
-
$result = $this->db_do("
|
2737 |
-
INSERT INTO $catalog_product_entity_varchar
|
2738 |
-
(entity_type_id, attribute_id, store_id, entity_id, value)
|
2739 |
-
(SELECT
|
2740 |
-
$_getProductEntityTypeId,
|
2741 |
-
$attr_thumbnail,
|
2742 |
-
0,
|
2743 |
-
a.entity_id,
|
2744 |
-
b.thumb_image_url
|
2745 |
-
FROM $catalog_product_entity a
|
2746 |
-
JOIN $core_store w
|
2747 |
-
JOIN $products_temp b
|
2748 |
-
ON a.store_product_id = b.store_product_id
|
2749 |
-
)
|
2750 |
-
ON DUPLICATE KEY UPDATE
|
2751 |
-
value = b.thumb_image_url");
|
2752 |
-
|
2753 |
-
echo("\n replaceMagentoProductsMultistore 36\n");
|
2754 |
-
|
2755 |
-
|
2756 |
-
//Refresh fulltext search
|
2757 |
-
$result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
|
2758 |
-
$result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
|
2759 |
-
|
2760 |
-
|
2761 |
-
echo("\n replaceMagentoProductsMultistore 36.2\n");
|
2762 |
-
$q = "
|
2763 |
-
INSERT INTO {$catalogsearch_fulltext}_tmp
|
2764 |
-
(product_id, store_id, data_index)
|
2765 |
-
(SELECT
|
2766 |
-
a.entity_id,
|
2767 |
-
w.website,
|
2768 |
-
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
2769 |
-
FROM $catalog_product_entity a
|
2770 |
-
JOIN $products_website_temp w
|
2771 |
-
ON a.store_product_id = w.store_product_id
|
2772 |
-
LEFT JOIN $catalog_category_product b
|
2773 |
-
ON a.entity_id = b.product_id
|
2774 |
-
LEFT JOIN $catalog_category_entity_varchar c
|
2775 |
-
ON b.category_id = c.entity_id
|
2776 |
-
AND c.attribute_id = $cat_attr_name
|
2777 |
-
LEFT JOIN $catalog_product_entity_varchar e
|
2778 |
-
ON a.entity_id = e.entity_id
|
2779 |
-
AND e.attribute_id = $attr_name
|
2780 |
-
LEFT JOIN $catalog_product_website j
|
2781 |
-
ON a.entity_id = j.product_id
|
2782 |
-
LEFT JOIN $products_temp f
|
2783 |
-
ON a.entity_id = f.store_product_id
|
2784 |
-
)
|
2785 |
-
ON DUPLICATE KEY UPDATE
|
2786 |
-
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
|
2787 |
-
echo("\n\n============================\n$q\n============================\n\n");
|
2788 |
-
|
2789 |
-
|
2790 |
-
$result = $this->db_do("
|
2791 |
-
INSERT INTO {$catalogsearch_fulltext}_tmp
|
2792 |
-
(product_id, store_id, data_index)
|
2793 |
-
(SELECT
|
2794 |
-
a.entity_id,
|
2795 |
-
w.website,
|
2796 |
-
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
2797 |
-
FROM $catalog_product_entity a
|
2798 |
-
JOIN $products_website_temp w
|
2799 |
-
ON a.store_product_id = w.store_product_id
|
2800 |
-
LEFT JOIN $catalog_category_product b
|
2801 |
-
ON a.entity_id = b.product_id
|
2802 |
-
LEFT JOIN $catalog_category_entity_varchar c
|
2803 |
-
ON b.category_id = c.entity_id
|
2804 |
-
AND c.attribute_id = $cat_attr_name
|
2805 |
-
LEFT JOIN $catalog_product_entity_varchar e
|
2806 |
-
ON a.entity_id = e.entity_id
|
2807 |
-
AND e.attribute_id = $attr_name
|
2808 |
-
LEFT JOIN $catalog_product_website j
|
2809 |
-
ON a.entity_id = j.product_id
|
2810 |
-
LEFT JOIN $products_temp f
|
2811 |
-
ON a.entity_id = f.store_product_id
|
2812 |
-
)
|
2813 |
-
ON DUPLICATE KEY UPDATE
|
2814 |
-
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
|
2815 |
-
|
2816 |
-
echo("\n replaceMagentoProductsMultistore 37\n");
|
2817 |
-
|
2818 |
-
|
2819 |
-
$result = $this->db_do("
|
2820 |
-
INSERT INTO {$catalogsearch_fulltext}_tmp
|
2821 |
-
(product_id, store_id, data_index)
|
2822 |
-
(SELECT
|
2823 |
-
a.entity_id,
|
2824 |
-
w.website,
|
2825 |
-
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
2826 |
-
FROM $catalog_product_entity a
|
2827 |
-
JOIN $products_website_temp w
|
2828 |
-
ON a.store_product_id = w.store_product_id
|
2829 |
-
LEFT JOIN $catalog_category_product b
|
2830 |
-
ON a.entity_id = b.product_id
|
2831 |
-
LEFT JOIN $catalog_category_entity_varchar c
|
2832 |
-
ON b.category_id = c.entity_id
|
2833 |
-
AND c.attribute_id = $cat_attr_name
|
2834 |
-
LEFT JOIN $catalog_product_entity_varchar e
|
2835 |
-
ON a.entity_id = e.entity_id
|
2836 |
-
AND e.attribute_id = $attr_name
|
2837 |
-
LEFT JOIN $products_temp f
|
2838 |
-
ON a.entity_id = f.store_product_id
|
2839 |
-
)
|
2840 |
-
ON DUPLICATE KEY UPDATE
|
2841 |
-
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
|
2842 |
-
|
2843 |
-
echo("\n replaceMagentoProductsMultistore 38\n");
|
2844 |
-
|
2845 |
-
$result = $this->db_do("
|
2846 |
-
DELETE cf
|
2847 |
-
FROM $catalogsearch_fulltext cf
|
2848 |
-
LEFT JOIN $catalog_product_entity cpe
|
2849 |
-
ON cf.product_id = cpe.entity_id
|
2850 |
-
WHERE cpe.entity_id IS NULL");
|
2851 |
-
|
2852 |
-
echo("\n replaceMagentoProductsMultistore 39\n");
|
2853 |
-
|
2854 |
-
$result = $this->db_do("
|
2855 |
-
INSERT INTO $catalogsearch_fulltext
|
2856 |
-
(product_id, store_id, data_index)
|
2857 |
-
(SELECT
|
2858 |
-
a.product_id,
|
2859 |
-
a.store_id,
|
2860 |
-
a.data_index
|
2861 |
-
FROM {$catalogsearch_fulltext}_tmp a
|
2862 |
-
WHERE product_id = a.product_id
|
2863 |
-
)
|
2864 |
-
ON DUPLICATE KEY UPDATE
|
2865 |
-
data_index = a.data_index");
|
2866 |
-
|
2867 |
-
echo("\n replaceMagentoProductsMultistore 40\n");
|
2868 |
-
|
2869 |
-
$this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
|
2870 |
-
//INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
|
2871 |
-
//TODO add something else
|
2872 |
-
|
2873 |
-
$this->addRelatedProducts();
|
2874 |
-
echo("\n replaceMagentoProductsMultistore 41\n");
|
2875 |
-
} //
|
2876 |
-
################################################################################################################################################################
|
2877 |
-
|
2878 |
-
|
2879 |
-
|
2880 |
-
|
2881 |
-
|
2882 |
-
|
2883 |
-
|
2884 |
-
|
2885 |
-
|
2886 |
-
|
2887 |
-
|
2888 |
-
|
2889 |
-
|
2890 |
-
|
2891 |
-
|
2892 |
-
|
2893 |
-
|
2894 |
-
|
2895 |
-
|
2896 |
-
|
2897 |
-
|
2898 |
-
|
2899 |
-
|
2900 |
-
|
2901 |
-
|
2902 |
-
|
2903 |
-
|
2904 |
-
|
2905 |
-
|
2906 |
-
|
2907 |
-
|
2908 |
-
|
2909 |
-
|
2910 |
-
|
2911 |
-
|
2912 |
-
|
2913 |
-
|
2914 |
-
|
2915 |
-
|
2916 |
-
|
2917 |
-
|
2918 |
-
|
2919 |
-
|
2920 |
-
|
2921 |
-
|
2922 |
-
|
2923 |
-
|
2924 |
-
|
2925 |
-
|
2926 |
-
|
2927 |
-
|
2928 |
-
|
2929 |
-
|
2930 |
-
|
2931 |
-
|
2932 |
-
|
2933 |
-
|
2934 |
-
|
2935 |
-
|
2936 |
-
|
2937 |
-
|
2938 |
-
|
2939 |
-
|
2940 |
-
|
2941 |
-
|
2942 |
-
|
2943 |
-
|
2944 |
-
|
2945 |
-
|
2946 |
-
|
2947 |
-
|
2948 |
-
|
2949 |
-
|
2950 |
-
|
2951 |
-
|
2952 |
-
|
2953 |
-
|
2954 |
-
|
2955 |
-
|
2956 |
-
|
2957 |
-
|
2958 |
-
|
2959 |
-
|
2960 |
-
|
2961 |
-
|
2962 |
-
|
2963 |
-
|
2964 |
-
|
2965 |
-
|
2966 |
-
################################################################################################################################################################
|
2967 |
-
private function truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
2968 |
-
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
|
2969 |
-
$name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
|
2970 |
-
{
|
2971 |
-
$this->db_do('SET foreign_key_checks=0');
|
2972 |
-
|
2973 |
-
$this->db_do("TRUNCATE $catalog_category_entity");
|
2974 |
-
$this->db_do("
|
2975 |
-
INSERT $catalog_category_entity
|
2976 |
-
(
|
2977 |
-
entity_id,
|
2978 |
-
entity_type_id,
|
2979 |
-
attribute_set_id,
|
2980 |
-
parent_id,
|
2981 |
-
created_at,
|
2982 |
-
updated_at,
|
2983 |
-
path,
|
2984 |
-
position,
|
2985 |
-
level,
|
2986 |
-
children_count,
|
2987 |
-
store_category_id,
|
2988 |
-
parent_store_category_id
|
2989 |
-
)
|
2990 |
-
VALUES
|
2991 |
-
(1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
|
2992 |
-
(2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 0, null, null)");
|
2993 |
-
|
2994 |
-
$this->db_do("TRUNCATE $catalog_category_entity_varchar");
|
2995 |
-
$this->db_do("
|
2996 |
-
INSERT $catalog_category_entity_varchar
|
2997 |
-
(
|
2998 |
-
value_id,
|
2999 |
-
entity_type_id,
|
3000 |
-
attribute_id,
|
3001 |
-
store_id,
|
3002 |
-
entity_id,
|
3003 |
-
value
|
3004 |
-
)
|
3005 |
-
VALUES
|
3006 |
-
(1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
|
3007 |
-
(2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
|
3008 |
-
(3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog'),
|
3009 |
-
(4, $_categoryEntityTypeId, $name_attrid, 0, 2, 'Default Category'),
|
3010 |
-
(5, $_categoryEntityTypeId, $name_attrid, 1, 2, 'Default Category'),
|
3011 |
-
(6, $_categoryEntityTypeId, $attr_display_mode, 1, 2, 'PRODUCTS'),
|
3012 |
-
(7, $_categoryEntityTypeId, $attr_url_key, 0, 2, 'default-category')");
|
3013 |
-
|
3014 |
-
$this->db_do("TRUNCATE $catalog_category_entity_int");
|
3015 |
-
$this->db_do("
|
3016 |
-
|