Version Notes
Added Compatibility for US Stock in the channel
Bug Fixes
Download this release
Release Info
| Developer | stockinchannel |
| Extension | stockinthechannel2012 |
| Version | 1.2.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.0.1 to 1.2.0
- app/code/local/Bintime/Sinchimport/Block/Importenvironment.php +46 -44
- app/code/local/Bintime/Sinchimport/Model/Layer.php +1 -0
- app/code/local/Bintime/Sinchimport/Model/Resource/Layer/Filter/Price.php +16 -0
- app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php +3 -3
- app/code/local/Bintime/Sinchimport/Model/Sinch.php +4297 -664
- app/code/local/Bintime/Sinchimport/Model/Sinch_new_code.php +7176 -0
- app/code/local/Bintime/Sinchimport/Model/System/Config/CatRewrite.php +1 -1
- app/code/local/Bintime/Sinchimport/Model/System/Config/ServerList.php +19 -0
- app/code/local/Bintime/Sinchimport/Model/config.php +30 -26
- app/code/local/Bintime/Sinchimport/etc/config.xml +1 -1
- app/code/local/Bintime/Sinchimport/etc/system.xml +10 -1
- app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.1-0.1.2.php +8 -0
- app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.5-0.1.6.php +6 -4
- app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.6-0.1.7.php +10 -2
- app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.8-0.1.9.php +8 -5
- app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.2.0-0.2.1.php +4 -4
- app/design/frontend/default/default/template/sinchimport/list.phtml +153 -0
- app/design/frontend/default/default/template/sinchimport/media.phtml +89 -0
- app/design/frontend/default/default/template/sinchimport/view.phtml +363 -0
- package.xml +10 -12
app/code/local/Bintime/Sinchimport/Block/Importenvironment.php
CHANGED
|
@@ -17,7 +17,7 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 17 |
|
| 18 |
//$html .= '<div class="comment"><H3>'.("Your Stock In The Channel Environment Check Summary" ).'</H3></div>';
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
|
| 23 |
$html .= '
|
|
@@ -40,10 +40,10 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 40 |
if ($status == 'error') {
|
| 41 |
$html .= // $caption: $value $measure
|
| 42 |
"
|
| 43 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 44 |
-
<tr> <td nowrap>
|
| 45 |
-
<tr> <td nowrap>
|
| 46 |
-
<tr> <td nowrap>
|
| 47 |
";
|
| 48 |
};
|
| 49 |
|
|
@@ -55,10 +55,10 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 55 |
if ($status == 'error') {
|
| 56 |
$html .= // $caption: $value $measure
|
| 57 |
"
|
| 58 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 59 |
-
<tr> <td nowrap>
|
| 60 |
-
<tr> <td nowrap>
|
| 61 |
-
<tr> <td nowrap>
|
| 62 |
";
|
| 63 |
};
|
| 64 |
|
|
@@ -69,10 +69,10 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 69 |
if ($status == 'error') {
|
| 70 |
$html .= // $caption: $value $measure
|
| 71 |
"
|
| 72 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 73 |
-
<tr> <td nowrap>
|
| 74 |
-
<tr> <td nowrap>
|
| 75 |
-
<tr> <td nowrap>
|
| 76 |
";
|
| 77 |
};
|
| 78 |
|
|
@@ -83,10 +83,10 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 83 |
if ($status == 'error') {
|
| 84 |
$html .= // $caption: $value $measure
|
| 85 |
"
|
| 86 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 87 |
-
<tr> <td nowrap>
|
| 88 |
-
<tr> <td nowrap>
|
| 89 |
-
<tr> <td nowrap>
|
| 90 |
";
|
| 91 |
};
|
| 92 |
|
|
@@ -97,10 +97,10 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 97 |
if ($status == 'error') {
|
| 98 |
$html .= // $caption: $value $measure
|
| 99 |
"
|
| 100 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 101 |
-
<tr> <td nowrap>
|
| 102 |
-
<tr> <td nowrap>
|
| 103 |
-
<tr> <td nowrap>
|
| 104 |
";
|
| 105 |
};
|
| 106 |
|
|
@@ -111,10 +111,10 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 111 |
if ($status == 'error') {
|
| 112 |
$html .= // $caption: $value $measure
|
| 113 |
"
|
| 114 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 115 |
-
<tr> <td nowrap>
|
| 116 |
-
<tr> <td nowrap>
|
| 117 |
-
<tr> <td nowrap>
|
| 118 |
";
|
| 119 |
};
|
| 120 |
|
|
@@ -125,10 +125,10 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 125 |
if ($status == 'error') {
|
| 126 |
$html .= // $caption: $value $measure
|
| 127 |
"
|
| 128 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 129 |
-
<tr> <td nowrap>
|
| 130 |
-
<tr> <td nowrap>
|
| 131 |
-
<tr> <td nowrap>
|
| 132 |
";
|
| 133 |
};
|
| 134 |
|
|
@@ -139,10 +139,10 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 139 |
if ($status == 'error') {
|
| 140 |
$html .= // $caption: $value $measure
|
| 141 |
"
|
| 142 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 143 |
-
<tr> <td nowrap>
|
| 144 |
-
<tr> <td nowrap>
|
| 145 |
-
<tr> <td nowrap>
|
| 146 |
";
|
| 147 |
};
|
| 148 |
|
|
@@ -152,23 +152,23 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 152 |
if ($status == 'error') {
|
| 153 |
$html .= // $caption: $value $measure
|
| 154 |
"
|
| 155 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 156 |
-
<tr> <td nowrap>
|
| 157 |
-
<tr> <td nowrap>
|
| 158 |
-
<tr> <td nowrap>
|
| 159 |
";
|
| 160 |
};
|
| 161 |
|
| 162 |
-
// Mysql stored procedure
|
| 163 |
list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkProcedure();
|
| 164 |
if ($status == 'error') $errors_count++;
|
| 165 |
if ($status == 'error') {
|
| 166 |
$html .= // $caption: $value $measure
|
| 167 |
"
|
| 168 |
-
<tr> <td rowspan=4> $caption </td> </tr>
|
| 169 |
-
<tr> <td nowrap>
|
| 170 |
-
<tr> <td nowrap>
|
| 171 |
-
<tr> <td nowrap>
|
| 172 |
";
|
| 173 |
};
|
| 174 |
|
|
@@ -177,14 +177,16 @@ class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_S
|
|
| 177 |
</tbody>
|
| 178 |
</table>';
|
| 179 |
|
| 180 |
-
$html .= '<div class="comment"><H3>'.("There are $errors_count
|
| 181 |
|
| 182 |
// all checks
|
| 183 |
return $html;
|
| 184 |
|
| 185 |
} // protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
| 188 |
|
| 189 |
|
| 190 |
} // class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_System_Config_Form_Field
|
| 17 |
|
| 18 |
//$html .= '<div class="comment"><H3>'.("Your Stock In The Channel Environment Check Summary" ).'</H3></div>';
|
| 19 |
|
| 20 |
+
//$html .= '<div class="comment"><H3>'.("In order for this extension to work, your server needs to be configured in a particular way and have sufficient memory." ).'</H3></div>';
|
| 21 |
|
| 22 |
|
| 23 |
$html .= '
|
| 40 |
if ($status == 'error') {
|
| 41 |
$html .= // $caption: $value $measure
|
| 42 |
"
|
| 43 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 44 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
|
| 45 |
+
<tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
|
| 46 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
|
| 47 |
";
|
| 48 |
};
|
| 49 |
|
| 55 |
if ($status == 'error') {
|
| 56 |
$html .= // $caption: $value $measure
|
| 57 |
"
|
| 58 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 59 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
|
| 60 |
+
<tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
|
| 61 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
|
| 62 |
";
|
| 63 |
};
|
| 64 |
|
| 69 |
if ($status == 'error') {
|
| 70 |
$html .= // $caption: $value $measure
|
| 71 |
"
|
| 72 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 73 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
|
| 74 |
+
<tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
|
| 75 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
|
| 76 |
";
|
| 77 |
};
|
| 78 |
|
| 83 |
if ($status == 'error') {
|
| 84 |
$html .= // $caption: $value $measure
|
| 85 |
"
|
| 86 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 87 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
|
| 88 |
+
<tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
|
| 89 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
|
| 90 |
";
|
| 91 |
};
|
| 92 |
|
| 97 |
if ($status == 'error') {
|
| 98 |
$html .= // $caption: $value $measure
|
| 99 |
"
|
| 100 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 101 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'blue')} $critical $measure </td> </tr>
|
| 102 |
+
<tr> <td nowrap> {$this->_colored('Notice:', 'blue')} $errmsg </td> </tr>
|
| 103 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'blue')} $fixmsg </td> </tr>
|
| 104 |
";
|
| 105 |
};
|
| 106 |
|
| 111 |
if ($status == 'error') {
|
| 112 |
$html .= // $caption: $value $measure
|
| 113 |
"
|
| 114 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 115 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
|
| 116 |
+
<tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
|
| 117 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
|
| 118 |
";
|
| 119 |
};
|
| 120 |
|
| 125 |
if ($status == 'error') {
|
| 126 |
$html .= // $caption: $value $measure
|
| 127 |
"
|
| 128 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 129 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
|
| 130 |
+
<tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
|
| 131 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
|
| 132 |
";
|
| 133 |
};
|
| 134 |
|
| 139 |
if ($status == 'error') {
|
| 140 |
$html .= // $caption: $value $measure
|
| 141 |
"
|
| 142 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 143 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
|
| 144 |
+
<tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
|
| 145 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
|
| 146 |
";
|
| 147 |
};
|
| 148 |
|
| 152 |
if ($status == 'error') {
|
| 153 |
$html .= // $caption: $value $measure
|
| 154 |
"
|
| 155 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 156 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
|
| 157 |
+
<tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
|
| 158 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
|
| 159 |
";
|
| 160 |
};
|
| 161 |
|
| 162 |
+
// Mysql stored procedure filter_sinch_products_s
|
| 163 |
list($status, $caption, $critical, $value, $measure, $errmsg, $fixmsg) = Mage::getModel('sinchimport/sinch')->checkProcedure();
|
| 164 |
if ($status == 'error') $errors_count++;
|
| 165 |
if ($status == 'error') {
|
| 166 |
$html .= // $caption: $value $measure
|
| 167 |
"
|
| 168 |
+
<tr> <td nowrap rowspan=4> $caption </td> </tr>
|
| 169 |
+
<tr> <td nowrap> {$this->_colored('Necessary:', 'red')} $critical $measure </td> </tr>
|
| 170 |
+
<tr> <td nowrap> {$this->_colored('Error:', 'red')} $errmsg </td> </tr>
|
| 171 |
+
<tr> <td nowrap> {$this->_colored('Fix:', 'red')} $fixmsg </td> </tr>
|
| 172 |
";
|
| 173 |
};
|
| 174 |
|
| 177 |
</tbody>
|
| 178 |
</table>';
|
| 179 |
|
| 180 |
+
$html .= '<div class="comment"><H3>'.("There are $errors_count notices." ).'</H3></div>';
|
| 181 |
|
| 182 |
// all checks
|
| 183 |
return $html;
|
| 184 |
|
| 185 |
} // protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
| 186 |
|
| 187 |
+
protected function _colored($str, $color){
|
| 188 |
+
return "<b><span style='color:{$color}'>{$str}</span></b>";
|
| 189 |
+
}
|
| 190 |
|
| 191 |
|
| 192 |
} // class Bintime_Sinchimport_Block_Importenvironment extends Mage_Adminhtml_Block_System_Config_Form_Field
|
app/code/local/Bintime/Sinchimport/Model/Layer.php
CHANGED
|
@@ -12,6 +12,7 @@ class Bintime_Sinchimport_Model_Layer extends Mage_Catalog_Model_Layer
|
|
| 12 |
Varien_Profiler::start(__METHOD__);
|
| 13 |
|
| 14 |
$category = Mage::registry('current_category');
|
|
|
|
| 15 |
$categoryId = $category->getEntityId();
|
| 16 |
$resource = Mage::getSingleton('core/resource');
|
| 17 |
$tCategor = $resource->getTableName('stINch_categories');
|
| 12 |
Varien_Profiler::start(__METHOD__);
|
| 13 |
|
| 14 |
$category = Mage::registry('current_category');
|
| 15 |
+
if( empty($category) ) { $category = Mage::getModel('catalog/category')->load( Mage::app()->getStore()->getRootCategoryId() ); }
|
| 16 |
$categoryId = $category->getEntityId();
|
| 17 |
$resource = Mage::getSingleton('core/resource');
|
| 18 |
$tCategor = $resource->getTableName('stINch_categories');
|
app/code/local/Bintime/Sinchimport/Model/Resource/Layer/Filter/Price.php
CHANGED
|
@@ -59,6 +59,22 @@ class Bintime_Sinchimport_Model_Resource_Layer_Filter_Price extends Mage_Catalo
|
|
| 59 |
$count=$connection->fetchPairs($select);
|
| 60 |
return key($count);
|
| 61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
}
|
| 64 |
?>
|
| 59 |
$count=$connection->fetchPairs($select);
|
| 60 |
return key($count);
|
| 61 |
}
|
| 62 |
+
|
| 63 |
+
protected function _getSelect($filter)
|
| 64 |
+
{
|
| 65 |
+
$collection = $filter->getLayer()->getProductCollection();
|
| 66 |
+
$collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId());
|
| 67 |
+
|
| 68 |
+
// clone select from collection with filters
|
| 69 |
+
$select = clone $collection->getSelect();
|
| 70 |
+
// reset columns, order and limitation conditions
|
| 71 |
+
$select->reset(Zend_Db_Select::COLUMNS);
|
| 72 |
+
$select->reset(Zend_Db_Select::ORDER);
|
| 73 |
+
$select->reset(Zend_Db_Select::LIMIT_COUNT);
|
| 74 |
+
$select->reset(Zend_Db_Select::LIMIT_OFFSET);
|
| 75 |
+
|
| 76 |
+
return $select;
|
| 77 |
+
}
|
| 78 |
|
| 79 |
}
|
| 80 |
?>
|
app/code/local/Bintime/Sinchimport/Model/Resource/Mysql4/Layer/Filter/Feature.php
CHANGED
|
@@ -318,7 +318,7 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
|
|
| 318 |
//
|
| 319 |
|
| 320 |
//Создание таблиц с фичами используемыми в навигации.
|
| 321 |
-
$i = 0;
|
| 322 |
foreach ($featureIds as $featureId) {
|
| 323 |
$tFeature = $resource->getTableName("stINch_products_feature_$featureId");
|
| 324 |
$query = "DROP TABLE IF EXISTS $tFeature";
|
|
@@ -350,9 +350,9 @@ class Bintime_Sinchimport_Model_Resource_Mysql4_Layer_Filter_Feature extends Mag
|
|
| 350 |
SELECT E.entity_id, RV.category_feature_id,E.entity_id, RV.category_feature_id, RV.text , RV.text
|
| 351 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." E
|
| 352 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." PCind
|
| 353 |
-
ON (E.entity_id = PCind.product_id AND PCind.store_id='
|
| 354 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
|
| 355 |
-
ON price_index.entity_id = E.entity_id AND price_index.website_id = '
|
| 356 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." PR
|
| 357 |
ON (PR.store_product_id = E.store_product_id)
|
| 358 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." PF
|
| 318 |
//
|
| 319 |
|
| 320 |
//Создание таблиц с фичами используемыми в навигации.
|
| 321 |
+
$i = 0; $storeId = Mage::app()->getStore()->getId(); $websiteId = Mage::app()->getWebsite()->getId();
|
| 322 |
foreach ($featureIds as $featureId) {
|
| 323 |
$tFeature = $resource->getTableName("stINch_products_feature_$featureId");
|
| 324 |
$query = "DROP TABLE IF EXISTS $tFeature";
|
| 350 |
SELECT E.entity_id, RV.category_feature_id,E.entity_id, RV.category_feature_id, RV.text , RV.text
|
| 351 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." E
|
| 352 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." PCind
|
| 353 |
+
ON (E.entity_id = PCind.product_id AND PCind.store_id='{$storeId}' AND PCind.visibility IN(2,4))
|
| 354 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." AS price_index
|
| 355 |
+
ON price_index.entity_id = E.entity_id AND price_index.website_id = '{$websiteId}' AND price_index.customer_group_id = 0
|
| 356 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." PR
|
| 357 |
ON (PR.store_product_id = E.store_product_id)
|
| 358 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." PF
|
app/code/local/Bintime/Sinchimport/Model/Sinch.php
CHANGED
|
@@ -45,6 +45,8 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
|
|
| 45 |
public $php_run_string;
|
| 46 |
public $price_breaks_filter;
|
| 47 |
|
|
|
|
|
|
|
| 48 |
#################################################################################################
|
| 49 |
|
| 50 |
function __construct(){
|
|
@@ -227,21 +229,30 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
|
|
| 227 |
$import->addImportStatus('Upload Files');
|
| 228 |
|
| 229 |
echo "Parse Categories <br>";
|
| 230 |
-
$import->ParseCategories();
|
| 231 |
$import->addImportStatus('Parse Categories');
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
echo "Parse Category Features <br>";
|
| 234 |
$import->ParseCategoryFeatures();
|
| 235 |
$import->addImportStatus('Parse Category Features');
|
| 236 |
|
|
|
|
| 237 |
echo "Parse Distributors <br>";
|
| 238 |
$import->ParseDistributors();
|
| 239 |
$import->addImportStatus('Parse Distributors');
|
| 240 |
|
|
|
|
| 241 |
echo "Parse EAN Codes <br>";
|
| 242 |
$import->ParseEANCodes();
|
| 243 |
$import->addImportStatus('Parse EAN Codes');
|
| 244 |
|
|
|
|
| 245 |
echo "Parse Manufacturers <br>";
|
| 246 |
$import->ParseManufacturers();
|
| 247 |
$import->addImportStatus('Parse Manufacturers');
|
|
@@ -250,22 +261,31 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
|
|
| 250 |
$import->ParseRelatedProducts();
|
| 251 |
$import->addImportStatus('Parse Related Products');
|
| 252 |
|
|
|
|
|
|
|
| 253 |
echo "Parse Product Features <br>";
|
| 254 |
$import->ParseProductFeatures();
|
| 255 |
$import->addImportStatus('Parse Product Features');
|
| 256 |
|
|
|
|
|
|
|
| 257 |
echo "Parse Products <br>";
|
| 258 |
-
$import->ParseProducts();
|
| 259 |
$import->addImportStatus('Parse Products');
|
| 260 |
|
|
|
|
|
|
|
|
|
|
| 261 |
echo "Parse Pictures Gallery";
|
| 262 |
$import->ParseProductsPicturesGallery();
|
| 263 |
$import->addImportStatus('Parse Pictures Gallery');
|
| 264 |
|
|
|
|
| 265 |
echo "Parse Restricted Values <br>";
|
| 266 |
$import->ParseRestrictedValues();
|
| 267 |
$import->addImportStatus('Parse Restricted Values');
|
| 268 |
|
|
|
|
| 269 |
echo "Parse Stock And Prices <br>";
|
| 270 |
$import->ParseStockAndPrices();
|
| 271 |
$import->addImportStatus('Parse Stock And Prices');
|
|
@@ -295,6 +315,7 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
|
|
| 295 |
$import->addImportStatus('Generate category filters');
|
| 296 |
echo "Finish indexing Sinch features for filters<br>";
|
| 297 |
|
|
|
|
| 298 |
Mage::log("Start indexing data", null, $this->_logFile);
|
| 299 |
echo "Start indexing data";
|
| 300 |
$import->_cleanCateoryProductFlatTable();
|
|
@@ -381,587 +402,4248 @@ class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract {
|
|
| 381 |
$import->addImportStatus('Stock Price Finish import', 1);
|
| 382 |
echo "Finish indexing Stock & Price<br>";
|
| 383 |
|
| 384 |
-
$q="SELECT RELEASE_LOCK('sinchimport')";
|
| 385 |
-
$quer=$this->db_do($q);
|
| 386 |
-
}catch (Exception $e) {
|
| 387 |
-
$this->set_import_error_reporting_message($e);
|
| 388 |
-
}
|
| 389 |
-
}
|
| 390 |
-
else{
|
| 391 |
-
if(!$this->is_imort_not_run()){
|
| 392 |
-
Mage::log("Sinchimport already run", null, $this->_logFile);
|
| 393 |
-
echo "Sinchimport already run<br>";
|
| 394 |
-
}else{
|
| 395 |
-
Mage::log("Full import have never finished with success", null, $this->_logFile);
|
| 396 |
-
echo "Full import have never finished with success<br>";
|
| 397 |
-
}
|
| 398 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
)
|
| 420 |
-
);
|
| 421 |
-
foreach ($this->files as $file) {
|
| 422 |
-
$this->_LOG("Copy ".$file_url_and_dir.$file." to ".$this->varDir.$file);
|
| 423 |
-
if(strstr($file_url_and_dir, 'ftp://')){
|
| 424 |
-
preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
|
| 425 |
-
//var_dump($match);
|
| 426 |
-
if($conn = ftp_connect($match[3])){
|
| 427 |
-
if(!ftp_login($conn, $login, $passw))
|
| 428 |
-
{
|
| 429 |
-
$this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
|
| 430 |
-
exit;
|
| 431 |
-
}
|
| 432 |
-
}
|
| 433 |
-
else{
|
| 434 |
-
$this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
|
| 435 |
-
exit;
|
| 436 |
-
}
|
| 437 |
-
if (!$this->wget ($file_url_and_dir.$file, $this->varDir.$file, 'system')){
|
| 438 |
-
$this->_LOG("wget Can't copy ".$file.", will use old one");
|
| 439 |
-
echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file.", will use old one<br>";
|
| 440 |
-
}
|
| 441 |
-
}
|
| 442 |
-
else{
|
| 443 |
-
if(!copy($file_url_and_dir.$file, $this->varDir.$file)){
|
| 444 |
-
$this->_LOG("copy Can't copy ".$file.", will use old one");
|
| 445 |
-
echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file." will use old one<br>";
|
| 446 |
-
}
|
| 447 |
-
}
|
| 448 |
-
exec("chmod a+rw ".$this->varDir.$file);
|
| 449 |
-
if(!filesize($this->varDir.$file)){
|
| 450 |
-
if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES){
|
| 451 |
-
$this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
|
| 452 |
-
$this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
|
| 453 |
-
$this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
|
| 454 |
|
| 455 |
-
exit;
|
| 456 |
-
}else{
|
| 457 |
-
if($file==FILE_CATEGORIES_FEATURES){
|
| 458 |
-
$this->_LOG("Can't copy ".FILE_CATEGORIES_FEATURES." file ignored" );
|
| 459 |
-
$this->_ignore_category_features=true;
|
| 460 |
-
}elseif($file==FILE_PRODUCT_FEATURES){
|
| 461 |
-
$this->_LOG("Can't copy ".FILE_PRODUCT_FEATURES." file ignored" );
|
| 462 |
-
$this->_ignore_product_features=true;
|
| 463 |
-
}elseif($file==FILE_RELATED_PRODUCTS){
|
| 464 |
-
$this->_LOG("Can't copy ".FILE_RELATED_PRODUCTS." file ignored" );
|
| 465 |
-
$this->_ignore_product_related=true;
|
| 466 |
-
}elseif($file==FILE_RESTRICTED_VALUES){
|
| 467 |
-
$this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
|
| 468 |
-
$this->_ignore_restricted_values=true;
|
| 469 |
-
}
|
| 470 |
-
}
|
| 471 |
-
}
|
| 472 |
-
}
|
| 473 |
|
| 474 |
-
$this->_LOG("Finish upload files");
|
| 475 |
-
}
|
| 476 |
|
| 477 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
|
| 479 |
-
|
|
|
|
|
|
|
|
|
|
| 480 |
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486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
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
|
| 571 |
-
|
| 572 |
-
$root_cat=$this->_getShopRootCategoryId();
|
| 573 |
-
}
|
| 574 |
-
$this->_root_cat=$root_cat;
|
| 575 |
-
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
|
| 576 |
-
SET parent_store_category_id='".$root_cat."'
|
| 577 |
-
WHERE parent_store_category_id=0";
|
| 578 |
-
$this->db_do($q);
|
| 579 |
-
$this->_LOG("root cat : ".$this->_root_cat);
|
| 580 |
|
| 581 |
-
$q="SELECT store_category_id
|
| 582 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp');
|
| 583 |
-
$quer=$this->db_do($q);
|
| 584 |
-
while($row=mysql_fetch_array($quer)){
|
| 585 |
-
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
|
| 586 |
-
SET children_count=".$this->count_children($row['store_category_id']).",
|
| 587 |
-
level=".$this->get_category_level($row['store_category_id'])."
|
| 588 |
-
WHERE store_category_id=".$row['store_category_id']);
|
| 589 |
-
}
|
| 590 |
-
$this->mapSinchCategories();
|
| 591 |
-
if(UPDATE_CATEGORY_DATA){
|
| 592 |
-
echo "Update category_entity \n";
|
| 593 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." (
|
| 594 |
-
entity_type_id,
|
| 595 |
-
attribute_set_id,
|
| 596 |
-
created_at,
|
| 597 |
-
updated_at,
|
| 598 |
-
level,
|
| 599 |
-
children_count,
|
| 600 |
-
entity_id,
|
| 601 |
-
position,
|
| 602 |
-
parent_id,
|
| 603 |
-
store_category_id,
|
| 604 |
-
parent_store_category_id
|
| 605 |
-
)(SELECT
|
| 606 |
-
".$this->_categoryEntityTypeId.",
|
| 607 |
-
".$this->_categoryDefault_attribute_set_id.",
|
| 608 |
-
now(),
|
| 609 |
-
now(),
|
| 610 |
-
c.level,
|
| 611 |
-
c.children_count,
|
| 612 |
-
scm.shop_entity_id,
|
| 613 |
-
c.order_number,
|
| 614 |
-
scm.shop_parent_id,
|
| 615 |
-
c.store_category_id,
|
| 616 |
-
c.parent_store_category_id
|
| 617 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 618 |
-
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 619 |
-
ON c.store_category_id=scm.store_category_id
|
| 620 |
-
)
|
| 621 |
-
ON DUPLICATE KEY UPDATE
|
| 622 |
-
updated_at=now(),
|
| 623 |
-
store_category_id=c.store_category_id,
|
| 624 |
-
level=c.level,
|
| 625 |
-
children_count=c.children_count,
|
| 626 |
-
position=c.order_number,
|
| 627 |
-
parent_store_category_id=c.parent_store_category_id";
|
| 628 |
-
//level=c.level,
|
| 629 |
-
//children_count=c.children_count
|
| 630 |
-
//position=c.order_number,
|
| 631 |
|
| 632 |
-
}else{
|
| 633 |
-
echo "Insert ignore category_entity \n";
|
| 634 |
-
$q="INSERT IGNORE INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." (
|
| 635 |
-
entity_type_id,
|
| 636 |
-
attribute_set_id,
|
| 637 |
-
created_at,
|
| 638 |
-
updated_at,
|
| 639 |
-
level,
|
| 640 |
-
children_count,
|
| 641 |
-
entity_id,
|
| 642 |
-
position,
|
| 643 |
-
parent_id,
|
| 644 |
-
store_category_id,
|
| 645 |
-
parent_store_category_id
|
| 646 |
-
)(SELECT
|
| 647 |
-
".$this->_categoryEntityTypeId.",
|
| 648 |
-
".$this->_categoryDefault_attribute_set_id.",
|
| 649 |
-
now(),
|
| 650 |
-
now(),
|
| 651 |
-
c.level,
|
| 652 |
-
c.children_count,
|
| 653 |
-
scm.shop_entity_id,
|
| 654 |
-
c.order_number,
|
| 655 |
-
scm.shop_parent_id,
|
| 656 |
-
c.store_category_id,
|
| 657 |
-
c.parent_store_category_id
|
| 658 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 659 |
-
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 660 |
-
ON c.store_category_id=scm.store_category_id
|
| 661 |
-
)";
|
| 662 |
-
}
|
| 663 |
-
$this->db_do($q);
|
| 664 |
|
| 665 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 666 |
|
|
|
|
| 667 |
|
|
|
|
| 668 |
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
;
|
| 675 |
-
$quer=$this->db_do($q);
|
| 676 |
-
while($row=mysql_fetch_array($quer)){
|
| 677 |
-
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
|
| 678 |
-
SET path='".$this->culc_path($row['parent_id'], $row['entity_id'])."'
|
| 679 |
-
WHERE entity_id=".$row['entity_id']);
|
| 680 |
-
}
|
| 681 |
|
| 682 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 683 |
|
| 684 |
-
echo "Update category_data \n";
|
| 685 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." (
|
| 686 |
-
entity_type_id,
|
| 687 |
-
attribute_id,
|
| 688 |
-
store_id,
|
| 689 |
-
entity_id,
|
| 690 |
-
value
|
| 691 |
-
)(SELECT
|
| 692 |
-
".$this->_categoryEntityTypeId.",
|
| 693 |
-
".$this->_getCategoryAttributeId('name').",
|
| 694 |
-
0,
|
| 695 |
-
scm.shop_entity_id,
|
| 696 |
-
c.category_name
|
| 697 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 698 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 699 |
-
ON c.store_category_id=scm.store_category_id
|
| 700 |
-
)
|
| 701 |
-
ON DUPLICATE KEY UPDATE
|
| 702 |
-
value=c.category_name
|
| 703 |
|
| 704 |
-
";
|
| 705 |
-
$this->db_do($q);
|
| 706 |
|
| 707 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." (
|
| 708 |
-
entity_type_id,
|
| 709 |
-
attribute_id,
|
| 710 |
-
store_id,
|
| 711 |
-
entity_id,
|
| 712 |
-
value
|
| 713 |
-
)(SELECT
|
| 714 |
-
".$this->_categoryEntityTypeId.",
|
| 715 |
-
".$this->_getCategoryAttributeId('name').",
|
| 716 |
-
1,
|
| 717 |
-
scm.shop_entity_id,
|
| 718 |
-
c.category_name
|
| 719 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 720 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 721 |
-
ON c.store_category_id=scm.store_category_id
|
| 722 |
-
)
|
| 723 |
-
ON DUPLICATE KEY UPDATE
|
| 724 |
-
value=c.category_name
|
| 725 |
-
";
|
| 726 |
-
$this->db_do($q);
|
| 727 |
|
| 728 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." (
|
| 729 |
-
entity_type_id,
|
| 730 |
-
attribute_id,
|
| 731 |
-
store_id,
|
| 732 |
-
entity_id,
|
| 733 |
-
value
|
| 734 |
-
)(SELECT
|
| 735 |
-
".$this->_categoryEntityTypeId.",
|
| 736 |
-
".$this->attributes['is_active'].",
|
| 737 |
-
0,
|
| 738 |
-
scm.shop_entity_id,
|
| 739 |
-
1
|
| 740 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 741 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 742 |
-
ON c.store_category_id=scm.store_category_id
|
| 743 |
-
)
|
| 744 |
-
ON DUPLICATE KEY UPDATE
|
| 745 |
-
value=1
|
| 746 |
-
";
|
| 747 |
-
$this->db_do($q);
|
| 748 |
|
| 749 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." (
|
| 750 |
-
entity_type_id,
|
| 751 |
-
attribute_id,
|
| 752 |
-
store_id,
|
| 753 |
-
entity_id,
|
| 754 |
-
value
|
| 755 |
-
)(SELECT
|
| 756 |
-
".$this->_categoryEntityTypeId.",
|
| 757 |
-
".$this->attributes['is_active'].",
|
| 758 |
-
1,
|
| 759 |
-
scm.shop_entity_id,
|
| 760 |
-
1
|
| 761 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 762 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 763 |
-
ON c.store_category_id=scm.store_category_id
|
| 764 |
-
)
|
| 765 |
-
ON DUPLICATE KEY UPDATE
|
| 766 |
-
value=1
|
| 767 |
-
";
|
| 768 |
-
$this->db_do($q);
|
| 769 |
|
| 770 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." (
|
| 771 |
-
entity_type_id,
|
| 772 |
-
attribute_id,
|
| 773 |
-
store_id,
|
| 774 |
-
entity_id,
|
| 775 |
-
value
|
| 776 |
-
)(SELECT
|
| 777 |
-
".$this->_categoryEntityTypeId.",
|
| 778 |
-
".$this->attributes['include_in_menu'].",
|
| 779 |
-
0,
|
| 780 |
-
scm.shop_entity_id,
|
| 781 |
-
1
|
| 782 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 783 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 784 |
-
ON c.store_category_id=scm.store_category_id
|
| 785 |
-
)
|
| 786 |
-
ON DUPLICATE KEY UPDATE
|
| 787 |
-
value=1
|
| 788 |
-
";
|
| 789 |
-
$this->db_do($q);
|
| 790 |
|
| 791 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." (
|
| 792 |
-
entity_type_id,
|
| 793 |
-
attribute_id,
|
| 794 |
-
store_id,
|
| 795 |
-
entity_id,
|
| 796 |
-
value
|
| 797 |
-
)(SELECT
|
| 798 |
-
".$this->_categoryEntityTypeId.",
|
| 799 |
-
".$this->_getCategoryAttributeId('is_anchor').",
|
| 800 |
-
1,
|
| 801 |
-
scm.shop_entity_id,
|
| 802 |
-
1
|
| 803 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 804 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 805 |
-
ON c.store_category_id=scm.store_category_id
|
| 806 |
-
)
|
| 807 |
-
ON DUPLICATE KEY UPDATE
|
| 808 |
-
value=1
|
| 809 |
-
";
|
| 810 |
-
$this->db_do($q);
|
| 811 |
|
| 812 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." (
|
| 813 |
-
entity_type_id,
|
| 814 |
-
attribute_id,
|
| 815 |
-
store_id,
|
| 816 |
-
entity_id,
|
| 817 |
-
value
|
| 818 |
-
)(SELECT
|
| 819 |
-
".$this->_categoryEntityTypeId.",
|
| 820 |
-
".$this->_getCategoryAttributeId('is_anchor').",
|
| 821 |
-
0,
|
| 822 |
-
scm.shop_entity_id,
|
| 823 |
-
1
|
| 824 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 825 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 826 |
-
ON c.store_category_id=scm.store_category_id
|
| 827 |
-
)
|
| 828 |
-
ON DUPLICATE KEY UPDATE
|
| 829 |
-
value=1
|
| 830 |
-
";
|
| 831 |
-
$this->db_do($q);
|
| 832 |
|
| 833 |
-
$q="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." (
|
| 834 |
-
entity_type_id,
|
| 835 |
-
attribute_id,
|
| 836 |
-
store_id,
|
| 837 |
-
entity_id,
|
| 838 |
-
value
|
| 839 |
-
)(SELECT
|
| 840 |
-
".$this->_categoryEntityTypeId.",
|
| 841 |
-
".$this->_getCategoryAttributeId('image').",
|
| 842 |
-
0,
|
| 843 |
-
scm.shop_entity_id,
|
| 844 |
-
c.categories_image
|
| 845 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 846 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 847 |
-
ON c.store_category_id=scm.store_category_id
|
| 848 |
-
)
|
| 849 |
-
ON DUPLICATE KEY UPDATE
|
| 850 |
-
value=c.categories_image
|
| 851 |
-
";
|
| 852 |
-
$this->db_do($q);
|
| 853 |
-
}else{
|
| 854 |
-
echo "Insert ignore category_data \n";
|
| 855 |
-
$q="INSERT IGNORE INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." (
|
| 856 |
-
entity_type_id,
|
| 857 |
-
attribute_id,
|
| 858 |
-
store_id,
|
| 859 |
-
entity_id,
|
| 860 |
-
value
|
| 861 |
-
)(SELECT
|
| 862 |
-
".$this->_categoryEntityTypeId.",
|
| 863 |
-
".$this->_getCategoryAttributeId('name').",
|
| 864 |
-
0,
|
| 865 |
-
scm.shop_entity_id,
|
| 866 |
-
c.category_name
|
| 867 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 868 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 869 |
-
ON c.store_category_id=scm.store_category_id
|
| 870 |
-
)
|
| 871 |
-
";
|
| 872 |
-
$this->db_do($q);
|
| 873 |
|
| 874 |
-
$q="INSERT IGNORE INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." (
|
| 875 |
-
entity_type_id,
|
| 876 |
-
attribute_id,
|
| 877 |
-
store_id,
|
| 878 |
-
entity_id,
|
| 879 |
-
value
|
| 880 |
-
)(SELECT
|
| 881 |
-
".$this->_categoryEntityTypeId.",
|
| 882 |
-
".$this->attributes['is_active'].",
|
| 883 |
-
0,
|
| 884 |
-
scm.shop_entity_id,
|
| 885 |
-
1
|
| 886 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 887 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 888 |
-
ON c.store_category_id=scm.store_category_id
|
| 889 |
-
)
|
| 890 |
-
";
|
| 891 |
-
$this->db_do($q);
|
| 892 |
|
| 893 |
-
$q="INSERT IGNORE INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." (
|
| 894 |
-
entity_type_id,
|
| 895 |
-
attribute_id,
|
| 896 |
-
store_id,
|
| 897 |
-
entity_id,
|
| 898 |
-
value
|
| 899 |
-
)(SELECT
|
| 900 |
-
".$this->_categoryEntityTypeId.",
|
| 901 |
-
".$this->attributes['include_in_menu'].",
|
| 902 |
-
0,
|
| 903 |
-
scm.shop_entity_id,
|
| 904 |
-
1
|
| 905 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 906 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 907 |
-
ON c.store_category_id=scm.store_category_id
|
| 908 |
-
)
|
| 909 |
-
";
|
| 910 |
-
$this->db_do($q);
|
| 911 |
|
| 912 |
-
$q="INSERT IGNORE INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." (
|
| 913 |
-
entity_type_id,
|
| 914 |
-
attribute_id,
|
| 915 |
-
store_id,
|
| 916 |
-
entity_id,
|
| 917 |
-
value
|
| 918 |
-
)(SELECT
|
| 919 |
-
".$this->_categoryEntityTypeId.",
|
| 920 |
-
".$this->_getCategoryAttributeId('is_anchor').",
|
| 921 |
-
0,
|
| 922 |
-
scm.shop_entity_id,
|
| 923 |
-
1
|
| 924 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 925 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 926 |
-
ON c.store_category_id=scm.store_category_id
|
| 927 |
-
)
|
| 928 |
-
";
|
| 929 |
-
$this->db_do($q);
|
| 930 |
|
| 931 |
-
$q="INSERT IGNORE INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." (
|
| 932 |
-
entity_type_id,
|
| 933 |
-
attribute_id,
|
| 934 |
-
store_id,
|
| 935 |
-
entity_id,
|
| 936 |
-
value
|
| 937 |
-
)(SELECT
|
| 938 |
-
".$this->_categoryEntityTypeId.",
|
| 939 |
-
".$this->_getCategoryAttributeId('image').",
|
| 940 |
-
0,
|
| 941 |
-
scm.shop_entity_id,
|
| 942 |
-
c.categories_image
|
| 943 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 944 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 945 |
-
ON c.store_category_id=scm.store_category_id
|
| 946 |
-
)
|
| 947 |
-
";
|
| 948 |
-
$this->db_do($q);
|
| 949 |
|
| 950 |
-
}
|
| 951 |
-
$this->delete_old_sinch_categories_from_shop();
|
| 952 |
|
| 953 |
-
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories'));
|
| 954 |
-
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
|
| 955 |
-
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_categories')
|
| 956 |
-
);
|
| 957 |
-
$this->_LOG("Finish parse ".FILE_CATEGORIES);
|
| 958 |
-
}else{
|
| 959 |
-
$this->_LOG("Wrong file ".$parse_file);
|
| 960 |
-
}
|
| 961 |
-
$this->_LOG(' ');
|
| 962 |
-
}
|
| 963 |
|
| 964 |
-
#################################################################################################
|
| 965 |
|
| 966 |
function ParseCategoryFeatures(){
|
| 967 |
|
|
@@ -1200,8 +4882,8 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 1200 |
|
| 1201 |
#################################################################################################
|
| 1202 |
|
| 1203 |
-
function ParseProducts(){
|
| 1204 |
-
|
| 1205 |
$parse_file=$this->varDir.FILE_PRODUCTS;
|
| 1206 |
if(filesize($parse_file)){
|
| 1207 |
$this->_LOG("Start parse ".FILE_PRODUCTS);
|
|
@@ -1216,7 +4898,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 1216 |
}
|
| 1217 |
fclose($file_handle_from);
|
| 1218 |
fclose($file_handle_to);
|
| 1219 |
-
|
| 1220 |
|
| 1221 |
// $prod_file_str = file_get_contents($parse_file);
|
| 1222 |
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
|
|
@@ -1252,25 +4934,33 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 1252 |
KEY(store_category_id)
|
| 1253 |
)DEFAULT CHARSET=utf8
|
| 1254 |
");
|
| 1255 |
-
|
| 1256 |
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv'
|
| 1257 |
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 1258 |
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 1259 |
OPTIONALLY ENCLOSED BY '\"'
|
| 1260 |
LINES TERMINATED BY \"\r\n\"
|
| 1261 |
IGNORE 1 LINES ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1262 |
|
| 1263 |
$this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 1264 |
CONVERT TO CHARACTER SET \"latin1\"");
|
| 1265 |
-
|
| 1266 |
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 1267 |
SET products_date_added=now(), products_last_modified=now()");
|
| 1268 |
-
|
| 1269 |
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 1270 |
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." m
|
| 1271 |
ON p.sinch_manufacturer_id=m.sinch_manufacturer_id
|
| 1272 |
SET p.manufacturer_name=m.manufacturer_name");
|
| 1273 |
-
|
| 1274 |
if($this->current_import_status_statistic_id){
|
| 1275 |
$res = $this->db_do("SELECT COUNT(*) AS cnt
|
| 1276 |
FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
|
|
@@ -1279,10 +4969,31 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 1279 |
SET number_of_products=".$row['cnt']."
|
| 1280 |
WHERE id=".$this->current_import_status_statistic_id);
|
| 1281 |
}
|
| 1282 |
-
|
| 1283 |
$this->addProductsWebsite();
|
| 1284 |
$this->mapSinchProducts();
|
| 1285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1286 |
$this->mapSinchProducts();
|
| 1287 |
$this->addManufacturer_attribute();
|
| 1288 |
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
|
|
@@ -1293,6 +5004,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 1293 |
$this->_LOG("Wrong file ".$parse_file);
|
| 1294 |
}
|
| 1295 |
$this->_LOG(" ");
|
|
|
|
| 1296 |
}
|
| 1297 |
|
| 1298 |
#################################################################################################
|
|
@@ -1474,98 +5186,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 1474 |
|
| 1475 |
}
|
| 1476 |
|
| 1477 |
-
#################################################################################################
|
| 1478 |
-
public function mapSinchCategories(){
|
| 1479 |
-
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp'));
|
| 1480 |
-
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')." (
|
| 1481 |
-
shop_entity_id int(11) unsigned NOT NULL,
|
| 1482 |
-
shop_entity_type_id int(11),
|
| 1483 |
-
shop_attribute_set_id int(11),
|
| 1484 |
-
shop_parent_id int(11),
|
| 1485 |
-
shop_store_category_id int(11),
|
| 1486 |
-
shop_parent_store_category_id int(11),
|
| 1487 |
-
store_category_id int(11),
|
| 1488 |
-
parent_store_category_id int(11),
|
| 1489 |
-
category_name varchar(255),
|
| 1490 |
-
order_number int(11),
|
| 1491 |
-
products_within_this_category int(11),
|
| 1492 |
-
KEY shop_entity_id (shop_entity_id),
|
| 1493 |
-
KEY shop_parent_id (shop_parent_id),
|
| 1494 |
-
KEY store_category_id (store_category_id),
|
| 1495 |
-
KEY parent_store_category_id (parent_store_category_id),
|
| 1496 |
-
UNIQUE KEY(shop_entity_id)
|
| 1497 |
-
)
|
| 1498 |
-
");
|
| 1499 |
-
$this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')."
|
| 1500 |
-
LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')
|
| 1501 |
-
);
|
| 1502 |
-
$result = $this->db_do("INSERT IGNORE INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')." (
|
| 1503 |
-
shop_entity_id,
|
| 1504 |
-
shop_entity_type_id,
|
| 1505 |
-
shop_attribute_set_id,
|
| 1506 |
-
shop_parent_id,
|
| 1507 |
-
shop_store_category_id,
|
| 1508 |
-
shop_parent_store_category_id
|
| 1509 |
-
)(SELECT
|
| 1510 |
-
entity_id,
|
| 1511 |
-
entity_type_id,
|
| 1512 |
-
attribute_set_id,
|
| 1513 |
-
parent_id,
|
| 1514 |
-
store_category_id,
|
| 1515 |
-
parent_store_category_id
|
| 1516 |
-
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
|
| 1517 |
-
)
|
| 1518 |
-
");
|
| 1519 |
-
|
| 1520 |
-
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')." cmt
|
| 1521 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 1522 |
-
ON cmt.shop_store_category_id=c.store_category_id
|
| 1523 |
-
SET
|
| 1524 |
-
cmt.store_category_id=c.store_category_id,
|
| 1525 |
-
cmt.parent_store_category_id=c.parent_store_category_id,
|
| 1526 |
-
cmt.category_name=c.category_name,
|
| 1527 |
-
cmt.order_number=c.order_number,
|
| 1528 |
-
cmt.products_within_this_category=c.products_within_this_category";
|
| 1529 |
-
$this->db_do($q);
|
| 1530 |
-
|
| 1531 |
-
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')." cmt
|
| 1532 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 1533 |
-
ON cmt.parent_store_category_id=cce.store_category_id
|
| 1534 |
-
SET cmt.shop_parent_id=cce.entity_id";
|
| 1535 |
-
$this->db_do($q);
|
| 1536 |
-
|
| 1537 |
-
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')." cmt
|
| 1538 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('categories_temp')." c
|
| 1539 |
-
ON cmt.shop_store_category_id=c.store_category_id
|
| 1540 |
-
SET shop_parent_id=".$this->_root_cat."
|
| 1541 |
-
WHERE shop_parent_id=0";
|
| 1542 |
-
$this->db_do($q);
|
| 1543 |
-
|
| 1544 |
-
$dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
|
| 1545 |
-
$im_type = $dataConf['replace_category'];
|
| 1546 |
-
// added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
|
| 1547 |
-
if((UPDATE_CATEGORY_DATA && $im_type=="MERGE") || ($im_type=="REWRITE")){
|
| 1548 |
-
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')." cmt
|
| 1549 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 1550 |
-
ON cmt.shop_entity_id=cce.entity_id
|
| 1551 |
-
SET cce.parent_id=cmt.shop_parent_id";
|
| 1552 |
-
$this->db_do($q);
|
| 1553 |
-
}else{
|
| 1554 |
-
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')." cmt
|
| 1555 |
-
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 1556 |
-
ON cmt.shop_entity_id=cce.entity_id
|
| 1557 |
-
SET cce.parent_id=cmt.shop_parent_id
|
| 1558 |
-
WHERE cce.parent_id=0 AND cce.store_category_id is not null
|
| 1559 |
-
";
|
| 1560 |
-
$this->db_do($q);
|
| 1561 |
-
|
| 1562 |
-
}
|
| 1563 |
-
|
| 1564 |
|
| 1565 |
-
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping'));
|
| 1566 |
-
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp')."
|
| 1567 |
-
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping'));
|
| 1568 |
-
}
|
| 1569 |
|
| 1570 |
#################################################################################################
|
| 1571 |
public function mapSinchProducts(){
|
|
@@ -1797,16 +5418,28 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 1797 |
ON ccp.product_id=cpe.entity_id
|
| 1798 |
WHERE cpe.entity_id IS NULL");
|
| 1799 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1800 |
$result = $this->db_do("UPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 1801 |
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 1802 |
ON ccp.category_id=cce.entity_id
|
| 1803 |
SET ccp.category_id=".$this->_root_cat."
|
| 1804 |
WHERE cce.entity_id IS NULL");
|
|
|
|
| 1805 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1806 |
$result = $this->db_do("DELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 1807 |
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 1808 |
ON ccp.category_id=cce.entity_id
|
| 1809 |
WHERE cce.entity_id IS NULL");
|
|
|
|
| 1810 |
|
| 1811 |
|
| 1812 |
$this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp");
|
|
@@ -2316,7 +5949,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 2316 |
)(
|
| 2317 |
SELECT
|
| 2318 |
a.entity_id,
|
| 2319 |
-
w.
|
| 2320 |
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 2321 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 2322 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
|
@@ -2346,7 +5979,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 2346 |
)(
|
| 2347 |
SELECT
|
| 2348 |
a.entity_id,
|
| 2349 |
-
w.
|
| 2350 |
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 2351 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 2352 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
|
@@ -2995,7 +6628,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 2995 |
SELECT
|
| 2996 |
" . $this->_getProductEntityTypeId(). ",
|
| 2997 |
" . $this->_getProductAttributeId('price'). ",
|
| 2998 |
-
w.
|
| 2999 |
a.entity_id,
|
| 3000 |
b.price
|
| 3001 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
|
@@ -3042,7 +6675,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 3042 |
SELECT
|
| 3043 |
" . $this->_getProductEntityTypeId(). ",
|
| 3044 |
" . $this->_getProductAttributeId('cost'). ",
|
| 3045 |
-
w.
|
| 3046 |
a.entity_id,
|
| 3047 |
b.cost
|
| 3048 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
|
@@ -3509,6 +7142,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 3509 |
}
|
| 3510 |
// $result = $this->this->db_do($query);//
|
| 3511 |
// $query=mysql_real_escape_string($query);
|
|
|
|
| 3512 |
$result = mysql_query($query) or die("Query failed: " . mysql_error());
|
| 3513 |
if (!$result) {
|
| 3514 |
throw new Exception("Invalid query: $sql\n" . mysql_error());
|
|
@@ -3748,6 +7382,9 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 3748 |
#################################################################################################
|
| 3749 |
|
| 3750 |
function culc_path($parent_id, $ent_id){
|
|
|
|
|
|
|
|
|
|
| 3751 |
$path='';
|
| 3752 |
$cat_id=$parent_id;
|
| 3753 |
$q="SELECT
|
|
@@ -3853,6 +7490,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 3853 |
$res="SELECT COUNT(*) FROM ".$this->import_status_statistic_table;
|
| 3854 |
$cnt_arr=mysql_fetch_array($this->db_do($res));
|
| 3855 |
$cnt=$cnt_arr[0];
|
|
|
|
| 3856 |
if($cnt>0){
|
| 3857 |
$a=(($cnt>7)? ($cnt-7): 0);
|
| 3858 |
$b=$cnt;
|
|
@@ -4325,7 +7963,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 4325 |
|
| 4326 |
$errmsg = '';
|
| 4327 |
$fixmsg = '';
|
| 4328 |
-
if ($value
|
| 4329 |
$errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
|
| 4330 |
$fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
|
| 4331 |
$status = 'error';
|
|
@@ -4365,18 +8003,13 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 4365 |
$retvalue["'$check_code'"] = array();
|
| 4366 |
|
| 4367 |
$value = trim(PHP_RUN_STRING);
|
| 4368 |
-
|
| 4369 |
$errmsg = '';
|
| 4370 |
$fixmsg = '';
|
| 4371 |
-
|
| 4372 |
-
|
| 4373 |
-
|
| 4374 |
-
|
| 4375 |
-
|
| 4376 |
-
$errmsg .= 'none';
|
| 4377 |
-
$fixmsg .= 'none';
|
| 4378 |
-
$status = 'OK';
|
| 4379 |
-
}
|
| 4380 |
|
| 4381 |
$ret = array();
|
| 4382 |
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
|
@@ -4570,7 +8203,7 @@ $this->_LOG("root cat : ".$this->_root_cat);
|
|
| 4570 |
$retvalue["'$check_code'"] = array();
|
| 4571 |
|
| 4572 |
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 4573 |
-
$storedFunctionName = Mage::getSingleton('core/resource')->getTableName('
|
| 4574 |
$result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
|
| 4575 |
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 4576 |
$value = $row['Name'];
|
| 45 |
public $php_run_string;
|
| 46 |
public $price_breaks_filter;
|
| 47 |
|
| 48 |
+
private $im_type;
|
| 49 |
+
|
| 50 |
#################################################################################################
|
| 51 |
|
| 52 |
function __construct(){
|
| 229 |
$import->addImportStatus('Upload Files');
|
| 230 |
|
| 231 |
echo "Parse Categories <br>";
|
| 232 |
+
$coincidence = $import->ParseCategories();
|
| 233 |
$import->addImportStatus('Parse Categories');
|
| 234 |
|
| 235 |
+
|
| 236 |
+
//$import->_cleanCateoryProductFlatTable();
|
| 237 |
+
//$import->runIndexer();
|
| 238 |
+
//echo("\n\n\n==================RETURN=================\n\n\n");
|
| 239 |
+
|
| 240 |
+
|
| 241 |
echo "Parse Category Features <br>";
|
| 242 |
$import->ParseCategoryFeatures();
|
| 243 |
$import->addImportStatus('Parse Category Features');
|
| 244 |
|
| 245 |
+
|
| 246 |
echo "Parse Distributors <br>";
|
| 247 |
$import->ParseDistributors();
|
| 248 |
$import->addImportStatus('Parse Distributors');
|
| 249 |
|
| 250 |
+
|
| 251 |
echo "Parse EAN Codes <br>";
|
| 252 |
$import->ParseEANCodes();
|
| 253 |
$import->addImportStatus('Parse EAN Codes');
|
| 254 |
|
| 255 |
+
|
| 256 |
echo "Parse Manufacturers <br>";
|
| 257 |
$import->ParseManufacturers();
|
| 258 |
$import->addImportStatus('Parse Manufacturers');
|
| 261 |
$import->ParseRelatedProducts();
|
| 262 |
$import->addImportStatus('Parse Related Products');
|
| 263 |
|
| 264 |
+
|
| 265 |
+
|
| 266 |
echo "Parse Product Features <br>";
|
| 267 |
$import->ParseProductFeatures();
|
| 268 |
$import->addImportStatus('Parse Product Features');
|
| 269 |
|
| 270 |
+
|
| 271 |
+
|
| 272 |
echo "Parse Products <br>";
|
| 273 |
+
$import->ParseProducts($coincidence);
|
| 274 |
$import->addImportStatus('Parse Products');
|
| 275 |
|
| 276 |
+
//echo("\n\n\n\n ##################################### \n\n\n\n"); return;
|
| 277 |
+
//
|
| 278 |
+
|
| 279 |
echo "Parse Pictures Gallery";
|
| 280 |
$import->ParseProductsPicturesGallery();
|
| 281 |
$import->addImportStatus('Parse Pictures Gallery');
|
| 282 |
|
| 283 |
+
|
| 284 |
echo "Parse Restricted Values <br>";
|
| 285 |
$import->ParseRestrictedValues();
|
| 286 |
$import->addImportStatus('Parse Restricted Values');
|
| 287 |
|
| 288 |
+
|
| 289 |
echo "Parse Stock And Prices <br>";
|
| 290 |
$import->ParseStockAndPrices();
|
| 291 |
$import->addImportStatus('Parse Stock And Prices');
|
| 315 |
$import->addImportStatus('Generate category filters');
|
| 316 |
echo "Finish indexing Sinch features for filters<br>";
|
| 317 |
|
| 318 |
+
|
| 319 |
Mage::log("Start indexing data", null, $this->_logFile);
|
| 320 |
echo "Start indexing data";
|
| 321 |
$import->_cleanCateoryProductFlatTable();
|
| 402 |
$import->addImportStatus('Stock Price Finish import', 1);
|
| 403 |
echo "Finish indexing Stock & Price<br>";
|
| 404 |
|
| 405 |
+
$q="SELECT RELEASE_LOCK('sinchimport')";
|
| 406 |
+
$quer=$this->db_do($q);
|
| 407 |
+
}catch (Exception $e) {
|
| 408 |
+
$this->set_import_error_reporting_message($e);
|
| 409 |
+
}
|
| 410 |
+
}
|
| 411 |
+
else{
|
| 412 |
+
if(!$this->is_imort_not_run()){
|
| 413 |
+
Mage::log("Sinchimport already run", null, $this->_logFile);
|
| 414 |
+
echo "Sinchimport already run<br>";
|
| 415 |
+
}else{
|
| 416 |
+
Mage::log("Full import have never finished with success", null, $this->_logFile);
|
| 417 |
+
echo "Full import have never finished with success<br>";
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
}
|
| 422 |
+
#################################################################################################
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
function UploadFiles(){
|
| 426 |
+
|
| 427 |
+
$this->_LOG("Start upload files");
|
| 428 |
+
$dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
|
| 429 |
+
$login=$dataConf['login'];
|
| 430 |
+
$passw=$dataConf['password'];
|
| 431 |
+
$server=$dataConf['ftp_server'];
|
| 432 |
+
|
| 433 |
+
//return;//stepan tes//stepan tes//stepan testtt
|
| 434 |
+
if(!$login || !$passw){
|
| 435 |
+
$this->_LOG('ftp login or password dosent defined');
|
| 436 |
+
$this->set_import_error_reporting_message('FTP login or password has not been defined. Import stopped.');
|
| 437 |
+
exit;
|
| 438 |
+
|
| 439 |
+
}
|
| 440 |
+
$file_url_and_dir=$this->repl_ph(FILE_URL_AND_DIR, array(
|
| 441 |
+
'server' => $server,
|
| 442 |
+
'login' => $login,
|
| 443 |
+
'password'=> $passw
|
| 444 |
+
)
|
| 445 |
+
);
|
| 446 |
+
foreach ($this->files as $file) {
|
| 447 |
+
$this->_LOG("Copy ".$file_url_and_dir.$file." to ".$this->varDir.$file);
|
| 448 |
+
if(strstr($file_url_and_dir, 'ftp://')){
|
| 449 |
+
preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $file_url_and_dir, $match);
|
| 450 |
+
//var_dump($match);
|
| 451 |
+
if($conn = ftp_connect($match[3])){
|
| 452 |
+
if(!ftp_login($conn, $login, $passw))
|
| 453 |
+
{
|
| 454 |
+
$this->set_import_error_reporting_message('Incorrect username or password for the Stock In The Channel server. Import stopped.');
|
| 455 |
+
exit;
|
| 456 |
+
}
|
| 457 |
+
}
|
| 458 |
+
else{
|
| 459 |
+
$this->set_import_error_reporting_message('FTP connection failed. Unable to connect to the Stock In The Channel server');
|
| 460 |
+
exit;
|
| 461 |
+
}
|
| 462 |
+
if (!$this->wget ($file_url_and_dir.$file, $this->varDir.$file, 'system')){
|
| 463 |
+
$this->_LOG("wget Can't copy ".$file.", will use old one");
|
| 464 |
+
echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file.", will use old one<br>";
|
| 465 |
+
}
|
| 466 |
+
}
|
| 467 |
+
else{
|
| 468 |
+
if(!copy($file_url_and_dir.$file, $this->varDir.$file)){
|
| 469 |
+
$this->_LOG("copy Can't copy ".$file.", will use old one");
|
| 470 |
+
echo "copy Can't copy ".$file_url_and_dir.$file." to ".$this->varDir.$file." will use old one<br>";
|
| 471 |
+
}
|
| 472 |
+
}
|
| 473 |
+
exec("chmod a+rw ".$this->varDir.$file);
|
| 474 |
+
if(!filesize($this->varDir.$file)){
|
| 475 |
+
if($file!=FILE_CATEGORIES_FEATURES && $file!=FILE_PRODUCT_FEATURES && $file!=FILE_RELATED_PRODUCTS && $file!=FILE_RESTRICTED_VALUES){
|
| 476 |
+
$this->_LOG("Can't copy ".$file_url_and_dir.$file.". file $this->varDir.$file is emty");
|
| 477 |
+
$this->set_import_error_reporting_message("Can't copy ".$file_url_and_dir.$file.". file ".$this->varDir.$file." is emty");
|
| 478 |
+
$this->addImportStatus('Sinch import stoped. Impot file(s) empty', 1);
|
| 479 |
+
|
| 480 |
+
exit;
|
| 481 |
+
}else{
|
| 482 |
+
if($file==FILE_CATEGORIES_FEATURES){
|
| 483 |
+
$this->_LOG("Can't copy ".FILE_CATEGORIES_FEATURES." file ignored" );
|
| 484 |
+
$this->_ignore_category_features=true;
|
| 485 |
+
}elseif($file==FILE_PRODUCT_FEATURES){
|
| 486 |
+
$this->_LOG("Can't copy ".FILE_PRODUCT_FEATURES." file ignored" );
|
| 487 |
+
$this->_ignore_product_features=true;
|
| 488 |
+
}elseif($file==FILE_RELATED_PRODUCTS){
|
| 489 |
+
$this->_LOG("Can't copy ".FILE_RELATED_PRODUCTS." file ignored" );
|
| 490 |
+
$this->_ignore_product_related=true;
|
| 491 |
+
}elseif($file==FILE_RESTRICTED_VALUES){
|
| 492 |
+
$this->_LOG("Can't copy ".FILE_RESTRICTED_VALUES." file ignored" );
|
| 493 |
+
$this->_ignore_restricted_values=true;
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
$this->_LOG("Finish upload files");
|
| 500 |
+
}
|
| 501 |
+
#################################################################################################
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
################################################################################################################################################################
|
| 506 |
+
function ParseCategories()
|
| 507 |
+
{
|
| 508 |
+
|
| 509 |
+
$dataConf = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
|
| 510 |
+
$im_type = $dataConf['replace_category'];
|
| 511 |
+
$parse_file = $this->varDir.FILE_CATEGORIES;
|
| 512 |
+
$field_terminated_char = $this->field_terminated_char;
|
| 513 |
+
|
| 514 |
+
$this->im_type = $im_type;
|
| 515 |
+
|
| 516 |
+
if(filesize($parse_file))
|
| 517 |
+
{
|
| 518 |
+
$this->_LOG("Start parse ".FILE_CATEGORIES);
|
| 519 |
+
|
| 520 |
+
$this->_getCategoryEntityTypeIdAndDefault_attribute_set_id();
|
| 521 |
+
|
| 522 |
+
$categories_temp = Mage::getSingleton('core/resource')->getTableName('categories_temp');
|
| 523 |
+
$catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
|
| 524 |
+
$catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
|
| 525 |
+
$catalog_category_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int');
|
| 526 |
+
$stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
|
| 527 |
+
$stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
|
| 528 |
+
$stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
|
| 529 |
+
|
| 530 |
+
$_categoryEntityTypeId = $this->_categoryEntityTypeId;
|
| 531 |
+
$_categoryDefault_attribute_set_id = $this->_categoryDefault_attribute_set_id;
|
| 532 |
+
|
| 533 |
+
$name_attrid = $this->_getCategoryAttributeId('name');
|
| 534 |
+
$is_anchor_attrid = $this->_getCategoryAttributeId('is_anchor');
|
| 535 |
+
$image_attrid = $this->_getCategoryAttributeId('image');
|
| 536 |
+
$attr_url_key = $this->attributes['url_key'];
|
| 537 |
+
$attr_display_mode = $this->attributes['display_mode'];
|
| 538 |
+
$attr_is_active = $this->attributes['is_active'];
|
| 539 |
+
$attr_include_in_menu = $this->attributes['include_in_menu'];
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
$this->loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char);
|
| 543 |
+
$coincidence = $this->calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type);
|
| 544 |
+
|
| 545 |
+
/**/
|
| 546 |
+
if (!$this->check_loaded_data($parse_file, $categories_temp))
|
| 547 |
+
{
|
| 548 |
+
$inf = mysql_info();
|
| 549 |
+
$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.")");
|
| 550 |
+
exit;
|
| 551 |
+
}/**/
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
echo("\n\ncoincidence = [".count($coincidence)."]\n\n");
|
| 555 |
+
|
| 556 |
+
if (count($coincidence) == 1) // one store logic
|
| 557 |
+
{
|
| 558 |
+
echo("\n\n\n\n\n\nOLD LOGIC\n\n\n\n\n\n\n\n\n");
|
| 559 |
+
if ($im_type == "REWRITE")
|
| 560 |
+
{
|
| 561 |
+
$root_cat = 2;
|
| 562 |
+
|
| 563 |
+
$root_cat = $this->truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 564 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
|
| 565 |
+
$name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu); // return $root_cat
|
| 566 |
+
}
|
| 567 |
+
else // if ($im_type == "MERGE")
|
| 568 |
+
{
|
| 569 |
+
$root_cat = $this->_getShopRootCategoryId();
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
$this->_root_cat = $root_cat;
|
| 573 |
+
|
| 574 |
+
$this->setCategorySettings($categories_temp, $root_cat);
|
| 575 |
+
$this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
|
| 576 |
+
$this->addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 577 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat);
|
| 578 |
+
}
|
| 579 |
+
else if (count($coincidence) > 1) // multistore logic
|
| 580 |
+
{
|
| 581 |
+
echo("\n\n\n====================================\nmultistore logic\n====================================\n\n\n");
|
| 582 |
+
switch ($im_type)
|
| 583 |
+
{
|
| 584 |
+
case "REWRITE": $this->rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 585 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
| 586 |
+
$name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
|
| 587 |
+
$stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
|
| 588 |
+
break;
|
| 589 |
+
case "MERGE" : $this->mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 590 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
| 591 |
+
$name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
|
| 592 |
+
$stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp);
|
| 593 |
+
break;
|
| 594 |
+
default : $retcode = "error";
|
| 595 |
+
};
|
| 596 |
+
}
|
| 597 |
+
else
|
| 598 |
+
{
|
| 599 |
+
echo("error");
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
$this->_LOG("Finish parse ".FILE_CATEGORIES);
|
| 603 |
+
}
|
| 604 |
+
else
|
| 605 |
+
{
|
| 606 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 607 |
+
}
|
| 608 |
+
$this->_LOG(' ');
|
| 609 |
+
|
| 610 |
+
return $coincidence;
|
| 611 |
+
} // function ParseCategories()
|
| 612 |
+
################################################################################################################################################################
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
|
| 617 |
+
|
| 618 |
+
|
| 619 |
+
################################################################################################################################################################
|
| 620 |
+
private function loadCategoriesTemp($categories_temp, $parse_file, $field_terminated_char)
|
| 621 |
+
{
|
| 622 |
+
$this->db_do("DROP TABLE IF EXISTS $categories_temp");
|
| 623 |
+
|
| 624 |
+
|
| 625 |
+
/** OLD !!!*
|
| 626 |
+
$this->db_do("CREATE TABLE $categories_temp (
|
| 627 |
+
store_category_id int(11),
|
| 628 |
+
parent_store_category_id int(11),
|
| 629 |
+
category_name varchar(50),
|
| 630 |
+
order_number int(11),
|
| 631 |
+
is_hidden boolean,
|
| 632 |
+
products_within_this_category int(11),
|
| 633 |
+
products_within_sub_categories int(11),
|
| 634 |
+
categories_image varchar(255),
|
| 635 |
+
level int(10) NOT NULL default 0,
|
| 636 |
+
children_count int(11) NOT NULL default 0,
|
| 637 |
+
KEY(store_category_id),
|
| 638 |
+
KEY(parent_store_category_id)
|
| 639 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
| 640 |
+
");
|
| 641 |
+
/**/
|
| 642 |
+
|
| 643 |
+
/** NEW !!! */
|
| 644 |
+
$this->db_do("
|
| 645 |
+
CREATE TABLE $categories_temp
|
| 646 |
+
(
|
| 647 |
+
store_category_id INT(11),
|
| 648 |
+
parent_store_category_id INT(11),
|
| 649 |
+
category_name VARCHAR(50),
|
| 650 |
+
order_number INT(11),
|
| 651 |
+
is_hidden BOOLEAN,
|
| 652 |
+
products_within_sub_categories INT(11),
|
| 653 |
+
products_within_this_category INT(11),
|
| 654 |
+
categories_image VARCHAR(255),
|
| 655 |
+
level INT(10) NOT NULL DEFAULT 0,
|
| 656 |
+
children_count INT(11) NOT NULL DEFAULT 0,
|
| 657 |
+
UNSPSC INT(10) DEFAULT NULL,
|
| 658 |
+
RootName INT(10) DEFAULT NULL,
|
| 659 |
+
|
| 660 |
+
KEY(store_category_id),
|
| 661 |
+
KEY(parent_store_category_id)
|
| 662 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
| 663 |
+
/**/
|
| 664 |
+
|
| 665 |
+
$this->db_do("
|
| 666 |
+
LOAD DATA LOCAL INFILE '$parse_file' INTO TABLE $categories_temp
|
| 667 |
+
FIELDS TERMINATED BY '$field_terminated_char' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\r\n\" IGNORE 1 LINES");
|
| 668 |
+
|
| 669 |
+
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
/** FOR TEST !!! *
|
| 673 |
+
$this->db_do("ALTER TABLE $categories_temp ADD COLUMN UNSPSC INT(10) NOT NULL DEFAULT 0");
|
| 674 |
+
$this->db_do("ALTER TABLE $categories_temp ADD COLUMN RootName VARCHAR(50) NOT NULL DEFAULT 0");
|
| 675 |
+
|
| 676 |
+
//$this->db_do("UPDATE $categories_temp SET RootName = '3'"); // one store logic test
|
| 677 |
+
|
| 678 |
+
$this->db_do("UPDATE $categories_temp SET RootName = 'KAMERY' WHERE store_category_id IN (93530, 93531, 93230, 93231, 175559, 175687)");
|
| 679 |
+
$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
|
| 680 |
+
$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)");
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
//$this->db_do("UPDATE $categories_temp SET RootName = 'PROJECTORS' WHERE store_category_id IN (151019, 151066, 175554, 175555, 175579, 175553)");
|
| 684 |
+
//$this->db_do("DELETE FROM $categories_temp WHERE store_category_id NOT IN (151019, 151066, 175554, 175555, 175579, 175553)");
|
| 685 |
+
|
| 686 |
+
|
| 687 |
+
//$this->db_do("DELETE FROM $categories_temp WHERE store_category_id IN (175687, 175553)"); // OLD CATS...//
|
| 688 |
+
|
| 689 |
+
/**/
|
| 690 |
+
|
| 691 |
+
} // private function loadCategoriesTemp()
|
| 692 |
+
################################################################################################################################################################
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
|
| 696 |
+
################################################################################################################################################################
|
| 697 |
+
private function mergeMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 698 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
| 699 |
+
$name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
|
| 700 |
+
$stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
|
| 701 |
+
{
|
| 702 |
+
echo("mergeMultistoreCategories RUN\n");
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
|
| 706 |
+
$this->createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 707 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
|
| 708 |
+
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
$this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
|
| 712 |
+
|
| 713 |
+
|
| 714 |
+
$this->addCategoryDataMultistoreMerge($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 715 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
| 716 |
+
$name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
|
| 717 |
+
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
echo("\n\n\nmergeMultistoreCategories DONE\n");
|
| 721 |
+
}
|
| 722 |
+
################################################################################################################################################################
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
|
| 726 |
+
|
| 727 |
+
|
| 728 |
+
|
| 729 |
+
################################################################################################################################################################
|
| 730 |
+
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,
|
| 731 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
| 732 |
+
$name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
|
| 733 |
+
{
|
| 734 |
+
echo("\n\n\n\n *************************************************************\n addCategoryDataMultistoreMerge start... \n");
|
| 735 |
+
|
| 736 |
+
|
| 737 |
+
if (UPDATE_CATEGORY_DATA)
|
| 738 |
+
{
|
| 739 |
+
$ignore = '';
|
| 740 |
+
$on_diplicate_key_update = "
|
| 741 |
+
ON DUPLICATE KEY UPDATE
|
| 742 |
+
updated_at = now(),
|
| 743 |
+
store_category_id = c.store_category_id,
|
| 744 |
+
level = c.level,
|
| 745 |
+
children_count = c.children_count,
|
| 746 |
+
position = c.order_number,
|
| 747 |
+
parent_store_category_id = c.parent_store_category_id";
|
| 748 |
+
//level=c.level,
|
| 749 |
+
//children_count=c.children_count
|
| 750 |
+
//position=c.order_number,
|
| 751 |
+
}
|
| 752 |
+
else
|
| 753 |
+
{
|
| 754 |
+
$ignore = 'IGNORE';
|
| 755 |
+
$on_diplicate_key_update = '';
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
$query = "
|
| 759 |
+
INSERT $ignore INTO $catalog_category_entity
|
| 760 |
+
(
|
| 761 |
+
entity_type_id,
|
| 762 |
+
attribute_set_id,
|
| 763 |
+
created_at,
|
| 764 |
+
updated_at,
|
| 765 |
+
level,
|
| 766 |
+
children_count,
|
| 767 |
+
entity_id,
|
| 768 |
+
position,
|
| 769 |
+
parent_id,
|
| 770 |
+
store_category_id,
|
| 771 |
+
parent_store_category_id
|
| 772 |
+
)
|
| 773 |
+
(SELECT
|
| 774 |
+
$_categoryEntityTypeId,
|
| 775 |
+
$_categoryDefault_attribute_set_id,
|
| 776 |
+
NOW(),
|
| 777 |
+
NOW(),
|
| 778 |
+
c.level,
|
| 779 |
+
c.children_count,
|
| 780 |
+
scm.shop_entity_id,
|
| 781 |
+
c.order_number,
|
| 782 |
+
scm.shop_parent_id,
|
| 783 |
+
c.store_category_id,
|
| 784 |
+
c.parent_store_category_id
|
| 785 |
+
FROM $categories_temp c
|
| 786 |
+
LEFT JOIN $stINch_categories_mapping scm
|
| 787 |
+
ON c.store_category_id = scm.store_category_id
|
| 788 |
+
) $on_diplicate_key_update";
|
| 789 |
+
echo("\n\n $query\n\n");
|
| 790 |
+
$this->db_do($query);
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
|
| 798 |
+
$this->mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
|
| 799 |
+
|
| 800 |
+
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
$categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
|
| 804 |
+
while ($row = mysql_fetch_array($categories))
|
| 805 |
+
{
|
| 806 |
+
$parent_id = $row['parent_id'];
|
| 807 |
+
$entity_id = $row['entity_id'];
|
| 808 |
+
|
| 809 |
+
$path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
|
| 810 |
+
|
| 811 |
+
$this->db_do("
|
| 812 |
+
UPDATE $catalog_category_entity
|
| 813 |
+
SET path = '$path'
|
| 814 |
+
WHERE entity_id = $entity_id");
|
| 815 |
+
} // while ($row = mysql_fetch_array($categories))
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
|
| 819 |
+
///////////////////////////////////////////////////////
|
| 820 |
+
|
| 821 |
+
|
| 822 |
+
if(UPDATE_CATEGORY_DATA)
|
| 823 |
+
{
|
| 824 |
+
echo "Update category_data \n";
|
| 825 |
+
|
| 826 |
+
$q = "
|
| 827 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 828 |
+
(
|
| 829 |
+
entity_type_id,
|
| 830 |
+
attribute_id,
|
| 831 |
+
store_id,
|
| 832 |
+
entity_id,
|
| 833 |
+
value
|
| 834 |
+
)
|
| 835 |
+
(SELECT
|
| 836 |
+
$_categoryEntityTypeId,
|
| 837 |
+
$name_attrid,
|
| 838 |
+
0,
|
| 839 |
+
scm.shop_entity_id,
|
| 840 |
+
c.category_name
|
| 841 |
+
FROM $categories_temp c
|
| 842 |
+
JOIN $stINch_categories_mapping scm
|
| 843 |
+
ON c.store_category_id = scm.store_category_id
|
| 844 |
+
)
|
| 845 |
+
ON DUPLICATE KEY UPDATE
|
| 846 |
+
value = c.category_name";
|
| 847 |
+
$this->db_do($q);
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
$q = "
|
| 851 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 852 |
+
(
|
| 853 |
+
entity_type_id,
|
| 854 |
+
attribute_id,
|
| 855 |
+
store_id,
|
| 856 |
+
entity_id,
|
| 857 |
+
value
|
| 858 |
+
)
|
| 859 |
+
(SELECT
|
| 860 |
+
$_categoryEntityTypeId,
|
| 861 |
+
$name_attrid,
|
| 862 |
+
1,
|
| 863 |
+
scm.shop_entity_id,
|
| 864 |
+
c.category_name
|
| 865 |
+
FROM $categories_temp c
|
| 866 |
+
JOIN $stINch_categories_mapping scm
|
| 867 |
+
ON c.store_category_id = scm.store_category_id
|
| 868 |
+
)
|
| 869 |
+
ON DUPLICATE KEY UPDATE
|
| 870 |
+
value = c.category_name";
|
| 871 |
+
$this->db_do($q);
|
| 872 |
+
|
| 873 |
+
|
| 874 |
+
$q = "
|
| 875 |
+
INSERT INTO $catalog_category_entity
|
| 876 |
+
(
|
| 877 |
+
entity_type_id,
|
| 878 |
+
attribute_id,
|
| 879 |
+
store_id,
|
| 880 |
+
entity_id,
|
| 881 |
+
value
|
| 882 |
+
)
|
| 883 |
+
(SELECT
|
| 884 |
+
$_categoryEntityTypeId,
|
| 885 |
+
$attr_is_active,
|
| 886 |
+
0,
|
| 887 |
+
scm.shop_entity_id,
|
| 888 |
+
1
|
| 889 |
+
FROM $categories_temp c
|
| 890 |
+
JOIN $stINch_categories_mapping scm
|
| 891 |
+
ON c.store_category_id = scm.store_category_id
|
| 892 |
+
)
|
| 893 |
+
ON DUPLICATE KEY UPDATE
|
| 894 |
+
value = 1";
|
| 895 |
+
$this->db_do($q);
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
$q = "
|
| 899 |
+
INSERT INTO $catalog_category_entity_int
|
| 900 |
+
(
|
| 901 |
+
entity_type_id,
|
| 902 |
+
attribute_id,
|
| 903 |
+
store_id,
|
| 904 |
+
entity_id,
|
| 905 |
+
value
|
| 906 |
+
)
|
| 907 |
+
(SELECT
|
| 908 |
+
$_categoryEntityTypeId,
|
| 909 |
+
$attr_is_active,
|
| 910 |
+
1,
|
| 911 |
+
scm.shop_entity_id,
|
| 912 |
+
1
|
| 913 |
+
FROM $categories_temp c
|
| 914 |
+
JOIN $stINch_categories_mapping scm
|
| 915 |
+
ON c.store_category_id = scm.store_category_id
|
| 916 |
+
)
|
| 917 |
+
ON DUPLICATE KEY UPDATE
|
| 918 |
+
value = 1";
|
| 919 |
+
$this->db_do($q);
|
| 920 |
+
|
| 921 |
+
|
| 922 |
+
$q = "
|
| 923 |
+
INSERT INTO $catalog_category_entity_int
|
| 924 |
+
(
|
| 925 |
+
entity_type_id,
|
| 926 |
+
attribute_id,
|
| 927 |
+
store_id,
|
| 928 |
+
entity_id,
|
| 929 |
+
value
|
| 930 |
+
)
|
| 931 |
+
(SELECT
|
| 932 |
+
$_categoryEntityTypeId,
|
| 933 |
+
$attr_include_in_menu,
|
| 934 |
+
0,
|
| 935 |
+
scm.shop_entity_id,
|
| 936 |
+
1
|
| 937 |
+
FROM $categories_temp c
|
| 938 |
+
JOIN $stINch_categories_mapping scm
|
| 939 |
+
ON c.store_category_id = scm.store_category_id
|
| 940 |
+
)
|
| 941 |
+
ON DUPLICATE KEY UPDATE
|
| 942 |
+
value = 1";
|
| 943 |
+
$this->db_do($q);
|
| 944 |
+
|
| 945 |
+
|
| 946 |
+
$q = "
|
| 947 |
+
INSERT INTO $catalog_category_entity_int
|
| 948 |
+
(
|
| 949 |
+
entity_type_id,
|
| 950 |
+
attribute_id,
|
| 951 |
+
store_id,
|
| 952 |
+
entity_id,
|
| 953 |
+
value
|
| 954 |
+
)
|
| 955 |
+
(SELECT
|
| 956 |
+
$_categoryEntityTypeId,
|
| 957 |
+
$is_anchor_attrid,
|
| 958 |
+
1,
|
| 959 |
+
scm.shop_entity_id,
|
| 960 |
+
1
|
| 961 |
+
FROM $categories_temp c
|
| 962 |
+
JOIN $stINch_categories_mapping scm
|
| 963 |
+
ON c.store_category_id = scm.store_category_id
|
| 964 |
+
)
|
| 965 |
+
ON DUPLICATE KEY UPDATE
|
| 966 |
+
value = 1";
|
| 967 |
+
$this->db_do($q);
|
| 968 |
+
|
| 969 |
+
|
| 970 |
+
$q = "
|
| 971 |
+
INSERT INTO $catalog_category_entity_int
|
| 972 |
+
(
|
| 973 |
+
entity_type_id,
|
| 974 |
+
attribute_id,
|
| 975 |
+
store_id,
|
| 976 |
+
entity_id,
|
| 977 |
+
value
|
| 978 |
+
)
|
| 979 |
+
(SELECT
|
| 980 |
+
$_categoryEntityTypeId,
|
| 981 |
+
$is_anchor_attrid,
|
| 982 |
+
0,
|
| 983 |
+
scm.shop_entity_id,
|
| 984 |
+
1
|
| 985 |
+
FROM $categories_temp c
|
| 986 |
+
JOIN $stINch_categories_mapping scm
|
| 987 |
+
ON c.store_category_id = scm.store_category_id
|
| 988 |
+
)
|
| 989 |
+
ON DUPLICATE KEY UPDATE
|
| 990 |
+
value = 1";
|
| 991 |
+
$this->db_do($q);
|
| 992 |
+
|
| 993 |
+
$q = "
|
| 994 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 995 |
+
(
|
| 996 |
+
entity_type_id,
|
| 997 |
+
attribute_id,
|
| 998 |
+
store_id,
|
| 999 |
+
entity_id,
|
| 1000 |
+
value
|
| 1001 |
+
)
|
| 1002 |
+
(SELECT
|
| 1003 |
+
$_categoryEntityTypeId,
|
| 1004 |
+
$image_attrid,
|
| 1005 |
+
0,
|
| 1006 |
+
scm.shop_entity_id,
|
| 1007 |
+
c.categories_image
|
| 1008 |
+
FROM $categories_temp c
|
| 1009 |
+
JOIN $stINch_categories_mapping scm
|
| 1010 |
+
ON c.store_category_id = scm.store_category_id
|
| 1011 |
+
)
|
| 1012 |
+
ON DUPLICATE KEY UPDATE
|
| 1013 |
+
value = c.categories_image";
|
| 1014 |
+
$this->db_do($q);
|
| 1015 |
+
}
|
| 1016 |
+
else
|
| 1017 |
+
{
|
| 1018 |
+
echo "Insert ignore category_data \n";
|
| 1019 |
+
|
| 1020 |
+
|
| 1021 |
+
$q = "
|
| 1022 |
+
INSERT IGNORE INTO $catalog_category_entity_varchar
|
| 1023 |
+
(
|
| 1024 |
+
entity_type_id,
|
| 1025 |
+
attribute_id,
|
| 1026 |
+
store_id,
|
| 1027 |
+
entity_id,
|
| 1028 |
+
value
|
| 1029 |
+
)
|
| 1030 |
+
(SELECT
|
| 1031 |
+
$_categoryEntityTypeId,
|
| 1032 |
+
$name_attrid,
|
| 1033 |
+
0,
|
| 1034 |
+
scm.shop_entity_id,
|
| 1035 |
+
c.category_name
|
| 1036 |
+
FROM $categories_temp c
|
| 1037 |
+
JOIN $stINch_categories_mapping scm
|
| 1038 |
+
ON c.store_category_id = scm.store_category_id
|
| 1039 |
+
)";
|
| 1040 |
+
$this->db_do($q);
|
| 1041 |
+
|
| 1042 |
+
|
| 1043 |
+
$q = "
|
| 1044 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 1045 |
+
(
|
| 1046 |
+
entity_type_id,
|
| 1047 |
+
attribute_id,
|
| 1048 |
+
store_id,
|
| 1049 |
+
entity_id,
|
| 1050 |
+
value
|
| 1051 |
+
)
|
| 1052 |
+
(SELECT
|
| 1053 |
+
$_categoryEntityTypeId,
|
| 1054 |
+
$attr_is_active,
|
| 1055 |
+
0,
|
| 1056 |
+
scm.shop_entity_id,
|
| 1057 |
+
1
|
| 1058 |
+
FROM $categories_temp c
|
| 1059 |
+
JOIN $stINch_categories_mapping scm
|
| 1060 |
+
ON c.store_category_id = scm.store_category_id
|
| 1061 |
+
)";
|
| 1062 |
+
$this->db_do($q);
|
| 1063 |
+
|
| 1064 |
+
|
| 1065 |
+
$q = "
|
| 1066 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 1067 |
+
(
|
| 1068 |
+
entity_type_id,
|
| 1069 |
+
attribute_id,
|
| 1070 |
+
store_id,
|
| 1071 |
+
entity_id,
|
| 1072 |
+
value
|
| 1073 |
+
)
|
| 1074 |
+
(SELECT
|
| 1075 |
+
$_categoryEntityTypeId,
|
| 1076 |
+
$attr_include_in_menu,
|
| 1077 |
+
0,
|
| 1078 |
+
scm.shop_entity_id,
|
| 1079 |
+
1
|
| 1080 |
+
FROM $categories_temp c
|
| 1081 |
+
JOIN $stINch_categories_mapping scm
|
| 1082 |
+
ON c.store_category_id = scm.store_category_id
|
| 1083 |
+
)";
|
| 1084 |
+
$this->db_do($q);
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
$q = "
|
| 1088 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 1089 |
+
(
|
| 1090 |
+
entity_type_id,
|
| 1091 |
+
attribute_id,
|
| 1092 |
+
store_id,
|
| 1093 |
+
entity_id,
|
| 1094 |
+
value
|
| 1095 |
+
)
|
| 1096 |
+
(SELECT
|
| 1097 |
+
$_categoryEntityTypeId,
|
| 1098 |
+
$is_anchor_attrid,
|
| 1099 |
+
0,
|
| 1100 |
+
scm.shop_entity_id,
|
| 1101 |
+
1
|
| 1102 |
+
FROM $categories_temp c
|
| 1103 |
+
JOIN $stINch_categories_mapping scm
|
| 1104 |
+
ON c.store_category_id = scm.store_category_id
|
| 1105 |
+
)";
|
| 1106 |
+
$this->db_do($q);
|
| 1107 |
+
|
| 1108 |
+
|
| 1109 |
+
$q = "
|
| 1110 |
+
INSERT IGNORE INTO $catalog_category_entity_varchar
|
| 1111 |
+
(
|
| 1112 |
+
entity_type_id,
|
| 1113 |
+
attribute_id,
|
| 1114 |
+
store_id,
|
| 1115 |
+
entity_id,
|
| 1116 |
+
value
|
| 1117 |
+
)
|
| 1118 |
+
(SELECT
|
| 1119 |
+
$_categoryEntityTypeId,
|
| 1120 |
+
$image_attrid,
|
| 1121 |
+
0,
|
| 1122 |
+
scm.shop_entity_id,
|
| 1123 |
+
c.categories_image
|
| 1124 |
+
FROM $categories_temp c
|
| 1125 |
+
JOIN $stINch_categories_mapping scm
|
| 1126 |
+
ON c.store_category_id = scm.store_category_id
|
| 1127 |
+
)";
|
| 1128 |
+
$this->db_do($q);
|
| 1129 |
+
}
|
| 1130 |
+
|
| 1131 |
+
|
| 1132 |
+
|
| 1133 |
+
|
| 1134 |
+
|
| 1135 |
+
//return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
|
| 1136 |
+
|
| 1137 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
|
| 1138 |
+
$this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
|
| 1139 |
+
|
| 1140 |
+
$this->deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int);
|
| 1141 |
+
/**/
|
| 1142 |
+
|
| 1143 |
+
echo("\n addCategoryDataMultistoreMerge done... \n *************************************************************\n");
|
| 1144 |
+
|
| 1145 |
+
} // private function addCategoryDataMultistoreMerge(...)
|
| 1146 |
+
################################################################################################################################################################
|
| 1147 |
+
|
| 1148 |
+
|
| 1149 |
+
|
| 1150 |
+
|
| 1151 |
+
|
| 1152 |
+
################################################################################################################################################################
|
| 1153 |
+
private function deleteOldSinchCategoriesFromShopMerge($stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int)
|
| 1154 |
+
{
|
| 1155 |
+
|
| 1156 |
+
echo("\n\n\n\n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n deleteOldSinchCategoriesFromShopMerge start... \n");
|
| 1157 |
+
|
| 1158 |
+
|
| 1159 |
+
$query = "DROP TABLE IF EXISTS delete_cats";
|
| 1160 |
+
echo("\n $query\n");
|
| 1161 |
+
$this->db_do($query );
|
| 1162 |
+
|
| 1163 |
+
|
| 1164 |
+
|
| 1165 |
+
$delete_cats = Mage::getSingleton('core/resource')->getTableName('delete_cats');
|
| 1166 |
+
$stINch_categories = Mage::getSingleton('core/resource')->getTableName('stINch_categories');
|
| 1167 |
+
|
| 1168 |
+
$query = "
|
| 1169 |
+
CREATE TABLE $delete_cats
|
| 1170 |
+
|
| 1171 |
+
SELECT entity_id
|
| 1172 |
+
FROM $catalog_category_entity cce
|
| 1173 |
+
WHERE cce.entity_id NOT IN
|
| 1174 |
+
(
|
| 1175 |
+
SELECT cce2.entity_id
|
| 1176 |
+
FROM $catalog_category_entity cce2
|
| 1177 |
+
JOIN $stINch_categories sc
|
| 1178 |
+
ON cce2.store_category_id = sc.store_category_id
|
| 1179 |
+
)
|
| 1180 |
+
AND cce.store_category_id IS NOT NULL
|
| 1181 |
+
;";
|
| 1182 |
+
|
| 1183 |
+
echo("\n $query\n");
|
| 1184 |
+
$this->db_do($query);
|
| 1185 |
+
|
| 1186 |
+
|
| 1187 |
+
|
| 1188 |
+
$query = "DELETE cce FROM $catalog_category_entity cce JOIN $delete_cats dc USING(entity_id)";
|
| 1189 |
+
echo("\n $query\n");
|
| 1190 |
+
$this->db_do($query);
|
| 1191 |
+
|
| 1192 |
+
|
| 1193 |
+
|
| 1194 |
+
$query = "DROP TABLE IF EXISTS $delete_cats";
|
| 1195 |
+
echo("\n $query\n");
|
| 1196 |
+
//$this->db_do($query );
|
| 1197 |
+
|
| 1198 |
+
|
| 1199 |
+
/**
|
| 1200 |
+
$query = "
|
| 1201 |
+
DELETE cat FROM $catalog_category_entity_varchar cat
|
| 1202 |
+
JOIN $stINch_categories_mapping scm
|
| 1203 |
+
ON cat.entity_id = scm.shop_entity_id
|
| 1204 |
+
WHERE
|
| 1205 |
+
(scm.shop_store_category_id IS NOT NULL) AND
|
| 1206 |
+
(scm.store_category_id IS NULL)";
|
| 1207 |
+
echo("\n $query\n");
|
| 1208 |
+
// $this->db_do($query);
|
| 1209 |
+
|
| 1210 |
+
$query = "
|
| 1211 |
+
DELETE cat FROM $catalog_category_entity_int cat
|
| 1212 |
+
JOIN $stINch_categories_mapping scm
|
| 1213 |
+
ON cat.entity_id = scm.shop_entity_id
|
| 1214 |
+
WHERE
|
| 1215 |
+
(scm.shop_store_category_id IS NOT NULL) AND
|
| 1216 |
+
(scm.store_category_id IS NULL)";
|
| 1217 |
+
echo("\n $query\n");
|
| 1218 |
+
// $this->db_do($query);
|
| 1219 |
+
|
| 1220 |
+
$query = "
|
| 1221 |
+
DELETE cat FROM $catalog_category_entity cat
|
| 1222 |
+
JOIN $stINch_categories_mapping scm
|
| 1223 |
+
ON cat.entity_id=scm.shop_entity_id
|
| 1224 |
+
WHERE
|
| 1225 |
+
(scm.shop_store_category_id IS NOT NULL) AND
|
| 1226 |
+
(scm.store_category_id IS NULL)";
|
| 1227 |
+
echo("\n $query\n");
|
| 1228 |
+
// $this->db_do($query);
|
| 1229 |
+
/**/
|
| 1230 |
+
|
| 1231 |
+
echo("\n deleteOldSinchCategoriesFromShopMerge done... \n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n\n");
|
| 1232 |
+
|
| 1233 |
+
} // private function deleteOldSinchCategoriesFromShopMerge()
|
| 1234 |
+
################################################################################################################################################################
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
|
| 1238 |
+
|
| 1239 |
+
|
| 1240 |
+
################################################################################################################################################################
|
| 1241 |
+
private function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
|
| 1242 |
+
{
|
| 1243 |
+
echo("\n\n\ ==========================================================================\n mapSinchCategoriesMultistore start... \n");
|
| 1244 |
+
|
| 1245 |
+
$this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
|
| 1246 |
+
|
| 1247 |
+
$query = "
|
| 1248 |
+
INSERT IGNORE INTO $stINch_categories_mapping_temp
|
| 1249 |
+
(shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
|
| 1250 |
+
(SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
|
| 1251 |
+
FROM $catalog_category_entity)";
|
| 1252 |
+
echo("\n $query\n");
|
| 1253 |
+
$this->db_do($query);
|
| 1254 |
+
|
| 1255 |
+
|
| 1256 |
+
$query = "
|
| 1257 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 1258 |
+
JOIN $categories_temp c
|
| 1259 |
+
ON cmt.shop_store_category_id = c.store_category_id
|
| 1260 |
+
SET
|
| 1261 |
+
cmt.store_category_id = c.store_category_id,
|
| 1262 |
+
cmt.parent_store_category_id = c.parent_store_category_id,
|
| 1263 |
+
cmt.category_name = c.category_name,
|
| 1264 |
+
cmt.order_number = c.order_number,
|
| 1265 |
+
cmt.products_within_this_category = c.products_within_this_category";
|
| 1266 |
+
echo("\n $query\n");
|
| 1267 |
+
$this->db_do($query);
|
| 1268 |
+
|
| 1269 |
+
|
| 1270 |
+
$query = "
|
| 1271 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 1272 |
+
JOIN $catalog_category_entity cce
|
| 1273 |
+
ON cmt.parent_store_category_id = cce.store_category_id
|
| 1274 |
+
SET cmt.shop_parent_id = cce.entity_id";
|
| 1275 |
+
echo("\n $query\n");
|
| 1276 |
+
$this->db_do($query);
|
| 1277 |
+
|
| 1278 |
+
|
| 1279 |
+
$query = "
|
| 1280 |
+
SELECT DISTINCT
|
| 1281 |
+
c.RootName, cce.entity_id
|
| 1282 |
+
FROM $categories_temp c
|
| 1283 |
+
JOIN $catalog_category_entity_varchar ccev
|
| 1284 |
+
ON c.RootName = ccev.value
|
| 1285 |
+
AND ccev.entity_type_id = $_categoryEntityTypeId
|
| 1286 |
+
AND ccev.attribute_id = $name_attrid
|
| 1287 |
+
AND ccev.store_id = 0
|
| 1288 |
+
JOIN $catalog_category_entity cce
|
| 1289 |
+
ON ccev.entity_id = cce.entity_id";
|
| 1290 |
+
echo("\n $query\n");
|
| 1291 |
+
$root_categories = $this->db_do($query);
|
| 1292 |
+
|
| 1293 |
+
while($root_cat = mysql_fetch_array($root_categories))
|
| 1294 |
+
{
|
| 1295 |
+
$root_id = $root_cat['entity_id'];
|
| 1296 |
+
$root_name = $root_cat['RootName'];
|
| 1297 |
+
|
| 1298 |
+
$query = "
|
| 1299 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 1300 |
+
JOIN $categories_temp c
|
| 1301 |
+
ON cmt.shop_store_category_id = c.store_category_id
|
| 1302 |
+
SET
|
| 1303 |
+
cmt.shop_parent_id = $root_id,
|
| 1304 |
+
cmt.shop_parent_store_category_id = $root_id,
|
| 1305 |
+
cmt.parent_store_category_id = $root_id,
|
| 1306 |
+
c.parent_store_category_id = $root_id
|
| 1307 |
+
WHERE RootName = '$root_name'
|
| 1308 |
+
AND cmt.shop_parent_id = 0";
|
| 1309 |
+
echo("\n $query\n");
|
| 1310 |
+
$this->db_do($query);
|
| 1311 |
+
}
|
| 1312 |
+
|
| 1313 |
+
|
| 1314 |
+
|
| 1315 |
+
// added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
|
| 1316 |
+
if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
|
| 1317 |
+
else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
|
| 1318 |
+
|
| 1319 |
+
$query = "
|
| 1320 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 1321 |
+
JOIN $catalog_category_entity cce
|
| 1322 |
+
ON cmt.shop_entity_id = cce.entity_id
|
| 1323 |
+
SET cce.parent_id = cmt.shop_parent_id
|
| 1324 |
+
$where";
|
| 1325 |
+
echo("\n $query\n");
|
| 1326 |
+
$this->db_do($query);
|
| 1327 |
+
|
| 1328 |
+
$query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
|
| 1329 |
+
echo("\n $query\n");
|
| 1330 |
+
$this->db_do($query);
|
| 1331 |
+
|
| 1332 |
+
$query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
|
| 1333 |
+
echo("\n $query\n");
|
| 1334 |
+
$this->db_do($query);
|
| 1335 |
+
|
| 1336 |
+
echo("\n mapSinchCategoriesMultistore done... \n ==========================================================================\n\n\n\n");
|
| 1337 |
+
} // public function mapSinchCategoriesMultistoreMerge($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
|
| 1338 |
+
################################################################################################################################################################
|
| 1339 |
+
|
| 1340 |
+
|
| 1341 |
+
|
| 1342 |
+
|
| 1343 |
+
|
| 1344 |
+
|
| 1345 |
+
|
| 1346 |
+
################################################################################################################################################################
|
| 1347 |
+
private function createNewDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 1348 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
|
| 1349 |
+
{
|
| 1350 |
+
echo("\n\n ==========================================================================\n createNewDefaultCategories start... \n");
|
| 1351 |
+
|
| 1352 |
+
$old_cats = array();
|
| 1353 |
+
$query = $this->db_do("
|
| 1354 |
+
SELECT
|
| 1355 |
+
cce.entity_id,
|
| 1356 |
+
ccev.value AS category_name
|
| 1357 |
+
FROM $catalog_category_entity cce
|
| 1358 |
+
JOIN $catalog_category_entity_varchar ccev
|
| 1359 |
+
ON cce.entity_id = ccev.entity_id
|
| 1360 |
+
AND ccev.store_id = 0
|
| 1361 |
+
AND cce.entity_type_id = ccev.entity_type_id
|
| 1362 |
+
AND ccev.attribute_id = 41
|
| 1363 |
+
WHERE parent_id = 1"); // 41 - category name
|
| 1364 |
+
while ($row = mysql_fetch_array($query)) $old_cats[] = $row['category_name'];
|
| 1365 |
+
|
| 1366 |
+
//var_dump($old_cats);
|
| 1367 |
+
|
| 1368 |
+
|
| 1369 |
+
$query = $this->db_do("SELECT MAX(entity_id) AS max_entity_id FROM $catalog_category_entity");
|
| 1370 |
+
$max_entity_id = mysql_fetch_array($query);
|
| 1371 |
+
|
| 1372 |
+
//var_dump($max_entity_id);
|
| 1373 |
+
|
| 1374 |
+
$i = $max_entity_id[max_entity_id] + 1;
|
| 1375 |
+
|
| 1376 |
+
foreach($coincidence as $key => $item)
|
| 1377 |
+
{
|
| 1378 |
+
echo("\n coincidence: key = [$key]\n");
|
| 1379 |
+
|
| 1380 |
+
|
| 1381 |
+
/**if ($item)
|
| 1382 |
+
{
|
| 1383 |
+
echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> CONTINUE: key = [$key] item = [$item]\n");
|
| 1384 |
+
//continue;
|
| 1385 |
+
}
|
| 1386 |
+
else
|
| 1387 |
+
{
|
| 1388 |
+
echo(">>>>>>>>>>>>>>>>>>>>>>>>>>>> NOT CONTINUE: key = [$key] item = [$item]\n");
|
| 1389 |
+
}/**/
|
| 1390 |
+
|
| 1391 |
+
|
| 1392 |
+
if (in_array($key, $old_cats))
|
| 1393 |
+
{
|
| 1394 |
+
echo(" CONTINUE: key = [$key] item = [$item]\n");
|
| 1395 |
+
continue;
|
| 1396 |
+
}
|
| 1397 |
+
else
|
| 1398 |
+
{
|
| 1399 |
+
echo(" CREATE NEW CATEGORY: key = [$key] item = [$item]\n");
|
| 1400 |
+
}
|
| 1401 |
+
|
| 1402 |
+
|
| 1403 |
+
$this->db_do("INSERT $catalog_category_entity
|
| 1404 |
+
(entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
|
| 1405 |
+
path, position, level, children_count, store_category_id, parent_store_category_id)
|
| 1406 |
+
VALUES
|
| 1407 |
+
($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 0, NULL, NULL)");
|
| 1408 |
+
|
| 1409 |
+
|
| 1410 |
+
$this->db_do("INSERT $catalog_category_entity_varchar
|
| 1411 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 1412 |
+
VALUES
|
| 1413 |
+
($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
|
| 1414 |
+
($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
|
| 1415 |
+
($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
|
| 1416 |
+
($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
|
| 1417 |
+
|
| 1418 |
+
|
| 1419 |
+
$this->db_do("INSERT $catalog_category_entity_int
|
| 1420 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 1421 |
+
VALUES
|
| 1422 |
+
($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
|
| 1423 |
+
($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
|
| 1424 |
+
($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
|
| 1425 |
+
($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
|
| 1426 |
+
$i++;
|
| 1427 |
+
} // foreach($coincidence as $key => $item)
|
| 1428 |
+
|
| 1429 |
+
echo("\n createNewDefaultCategories done... \n ==========================================================================\n");
|
| 1430 |
+
|
| 1431 |
+
} // private function createNewDefaultCategories()
|
| 1432 |
+
################################################################################################################################################################
|
| 1433 |
+
|
| 1434 |
+
|
| 1435 |
+
|
| 1436 |
+
|
| 1437 |
+
|
| 1438 |
+
|
| 1439 |
+
|
| 1440 |
+
################################################################################################################################################################
|
| 1441 |
+
private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity, $catalog_category_entity_varchar, $im_type)
|
| 1442 |
+
{
|
| 1443 |
+
$root_categories = $this->db_do("
|
| 1444 |
+
SELECT
|
| 1445 |
+
cce.entity_id,
|
| 1446 |
+
ccev.value AS category_name
|
| 1447 |
+
FROM $catalog_category_entity cce
|
| 1448 |
+
JOIN $catalog_category_entity_varchar ccev
|
| 1449 |
+
ON cce.entity_id = ccev.entity_id
|
| 1450 |
+
AND ccev.store_id = 0
|
| 1451 |
+
AND cce.entity_type_id = ccev.entity_type_id
|
| 1452 |
+
AND ccev.attribute_id = 41
|
| 1453 |
+
WHERE parent_id = 1"); // 41 - category name
|
| 1454 |
+
$OLD = array();
|
| 1455 |
+
while($root_cat = mysql_fetch_array($root_categories)) $OLD[] = $root_cat['category_name'];
|
| 1456 |
+
|
| 1457 |
+
$new_categories = $this->db_do("SELECT DISTINCT RootName FROM $categories_temp");
|
| 1458 |
+
$NEW = array();
|
| 1459 |
+
while($new_root_cat = mysql_fetch_array($new_categories)) $exists_coincidence[$new_root_cat['RootName']] = TRUE;
|
| 1460 |
+
|
| 1461 |
+
/**
|
| 1462 |
+
$exists_coincidence = array();
|
| 1463 |
+
|
| 1464 |
+
switch ($im_type)
|
| 1465 |
+
{
|
| 1466 |
+
case "REWRITE":
|
| 1467 |
+
foreach($NEW as $item)
|
| 1468 |
+
{
|
| 1469 |
+
$exists_coincidence[$item] = TRUE;
|
| 1470 |
+
}
|
| 1471 |
+
break;
|
| 1472 |
+
case "MERGE" :
|
| 1473 |
+
foreach($OLD as $item)
|
| 1474 |
+
{
|
| 1475 |
+
$exists_coincidence[$item] = FALSE;
|
| 1476 |
+
}
|
| 1477 |
+
foreach($NEW as $item)
|
| 1478 |
+
{
|
| 1479 |
+
$exists_coincidence[$item] = TRUE;
|
| 1480 |
+
}
|
| 1481 |
+
break;
|
| 1482 |
+
default : $retcode = "error";
|
| 1483 |
+
};
|
| 1484 |
+
/**/
|
| 1485 |
+
|
| 1486 |
+
|
| 1487 |
+
|
| 1488 |
+
echo("\ncalculateCategoryCoincidence ...im_type = [$im_type]\n\n");
|
| 1489 |
+
var_dump($exists_coincidence);
|
| 1490 |
+
|
| 1491 |
+
return $exists_coincidence;
|
| 1492 |
+
} // private function calculateCategoryCoincidence($categories_temp, $catalog_category_entity)
|
| 1493 |
+
################################################################################################################################################################
|
| 1494 |
+
|
| 1495 |
+
|
| 1496 |
+
|
| 1497 |
+
################################################################################################################################################################
|
| 1498 |
+
private function rewriteMultistoreCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 1499 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
| 1500 |
+
$name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active, $image_attrid, $is_anchor_attrid,
|
| 1501 |
+
$stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $categories_temp)
|
| 1502 |
+
{
|
| 1503 |
+
echo("rewriteMultistoreCategories RUN\n");
|
| 1504 |
+
|
| 1505 |
+
|
| 1506 |
+
echo(" truncateAllCateriesAndCreateRoot start...");
|
| 1507 |
+
$this->truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 1508 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active);
|
| 1509 |
+
echo(" done.\n");
|
| 1510 |
+
|
| 1511 |
+
|
| 1512 |
+
echo(" createDefaultCategories start...");
|
| 1513 |
+
$this->createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 1514 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu);
|
| 1515 |
+
echo(" done.\n");
|
| 1516 |
+
|
| 1517 |
+
|
| 1518 |
+
echo(" mapSinchCategoriesMultistore start...");
|
| 1519 |
+
$this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
|
| 1520 |
+
echo(" done.\n");
|
| 1521 |
+
|
| 1522 |
+
|
| 1523 |
+
echo(" addCategoryDataMultistore start...");
|
| 1524 |
+
$this->addCategoryDataMultistore($categories_temp, $stINch_categories_mapping_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 1525 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
| 1526 |
+
$name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid);
|
| 1527 |
+
echo(" done.\n");
|
| 1528 |
+
|
| 1529 |
+
|
| 1530 |
+
echo("rewriteMultistoreCategories DONE\n");
|
| 1531 |
+
} // private function rewriteMultistoreCategories()
|
| 1532 |
+
################################################################################################################################################################
|
| 1533 |
+
|
| 1534 |
+
|
| 1535 |
+
|
| 1536 |
+
|
| 1537 |
+
|
| 1538 |
+
|
| 1539 |
+
|
| 1540 |
+
################################################################################################################################################################
|
| 1541 |
+
private function truncateAllCateriesAndCreateRoot($catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 1542 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_include_in_menu, $attr_is_active)
|
| 1543 |
+
{
|
| 1544 |
+
$this->db_do('SET foreign_key_checks=0');
|
| 1545 |
+
|
| 1546 |
+
|
| 1547 |
+
$this->db_do("TRUNCATE $catalog_category_entity");
|
| 1548 |
+
$this->db_do("TRUNCATE $catalog_category_entity_varchar");
|
| 1549 |
+
$this->db_do("TRUNCATE $catalog_category_entity_int");
|
| 1550 |
+
|
| 1551 |
+
|
| 1552 |
+
$this->db_do("INSERT $catalog_category_entity
|
| 1553 |
+
(entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
|
| 1554 |
+
path, position, level, children_count, store_category_id, parent_store_category_id)
|
| 1555 |
+
VALUES
|
| 1556 |
+
(1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', NOW(), '1', 0, 0, 1, NULL, NULL)");
|
| 1557 |
+
|
| 1558 |
+
|
| 1559 |
+
$this->db_do("INSERT $catalog_category_entity_varchar
|
| 1560 |
+
(value_id, entity_type_id, attribute_id, store_id, entity_id, value)
|
| 1561 |
+
VALUES
|
| 1562 |
+
(1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
|
| 1563 |
+
(2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
|
| 1564 |
+
(3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog')");
|
| 1565 |
+
|
| 1566 |
+
|
| 1567 |
+
$this->db_do("INSERT $catalog_category_entity_int
|
| 1568 |
+
(value_id, entity_type_id, attribute_id, store_id, entity_id, value)
|
| 1569 |
+
VALUES
|
| 1570 |
+
(1, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1)");
|
| 1571 |
+
} // private function truncateAllCateriesAndCreateRoot(...)
|
| 1572 |
+
################################################################################################################################################################
|
| 1573 |
+
|
| 1574 |
+
|
| 1575 |
+
|
| 1576 |
+
|
| 1577 |
+
################################################################################################################################################################
|
| 1578 |
+
private function createDefaultCategories($coincidence, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 1579 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
|
| 1580 |
+
{
|
| 1581 |
+
$i = 3; // 2 - is Default Category... not use.
|
| 1582 |
+
|
| 1583 |
+
foreach($coincidence as $key => $item)
|
| 1584 |
+
{
|
| 1585 |
+
$this->db_do("INSERT $catalog_category_entity
|
| 1586 |
+
(entity_id, entity_type_id, attribute_set_id, parent_id, created_at, updated_at,
|
| 1587 |
+
path, position, level, children_count, store_category_id, parent_store_category_id)
|
| 1588 |
+
VALUES
|
| 1589 |
+
($i, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/$i', 1, 1, 0, NULL, NULL)");
|
| 1590 |
+
|
| 1591 |
+
|
| 1592 |
+
$this->db_do("INSERT $catalog_category_entity_varchar
|
| 1593 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 1594 |
+
VALUES
|
| 1595 |
+
($_categoryEntityTypeId, $name_attrid, 0, $i, '$key'),
|
| 1596 |
+
($_categoryEntityTypeId, $name_attrid, 1, $i, '$key'),
|
| 1597 |
+
($_categoryEntityTypeId, $attr_display_mode, 1, $i, '$key'),
|
| 1598 |
+
($_categoryEntityTypeId, $attr_url_key, 0, $i, '$key')");
|
| 1599 |
+
|
| 1600 |
+
|
| 1601 |
+
$this->db_do("INSERT $catalog_category_entity_int
|
| 1602 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 1603 |
+
VALUES
|
| 1604 |
+
($_categoryEntityTypeId, $attr_is_active, 0, $i, 1),
|
| 1605 |
+
($_categoryEntityTypeId, $attr_is_active, 1, $i, 1),
|
| 1606 |
+
($_categoryEntityTypeId, $attr_include_in_menu, 0, $i, 1),
|
| 1607 |
+
($_categoryEntityTypeId, $attr_include_in_menu, 1, $i, 1)");
|
| 1608 |
+
$i++;
|
| 1609 |
+
} // foreach($coincidence as $key => $item)
|
| 1610 |
+
} // private function truncateAllCateries()
|
| 1611 |
+
################################################################################################################################################################
|
| 1612 |
+
|
| 1613 |
+
|
| 1614 |
+
|
| 1615 |
+
|
| 1616 |
+
################################################################################################################################################################
|
| 1617 |
+
private function mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid)
|
| 1618 |
+
{
|
| 1619 |
+
echo("\n\n\n\n==========================================================================\nmapSinchCategoriesMultistore start... \n");
|
| 1620 |
+
|
| 1621 |
+
$this->createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping);
|
| 1622 |
+
|
| 1623 |
+
$query = "
|
| 1624 |
+
INSERT IGNORE INTO $stINch_categories_mapping_temp
|
| 1625 |
+
(shop_entity_id, shop_entity_type_id, shop_attribute_set_id, shop_parent_id, shop_store_category_id, shop_parent_store_category_id)
|
| 1626 |
+
(SELECT entity_id, entity_type_id, attribute_set_id, parent_id, store_category_id, parent_store_category_id
|
| 1627 |
+
FROM $catalog_category_entity)";
|
| 1628 |
+
echo("\n\n$query\n\n");
|
| 1629 |
+
$this->db_do($query);
|
| 1630 |
+
|
| 1631 |
+
|
| 1632 |
+
$query = "
|
| 1633 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 1634 |
+
JOIN $categories_temp c
|
| 1635 |
+
ON cmt.shop_store_category_id = c.store_category_id
|
| 1636 |
+
SET
|
| 1637 |
+
cmt.store_category_id = c.store_category_id,
|
| 1638 |
+
cmt.parent_store_category_id = c.parent_store_category_id,
|
| 1639 |
+
cmt.category_name = c.category_name,
|
| 1640 |
+
cmt.order_number = c.order_number,
|
| 1641 |
+
cmt.products_within_this_category = c.products_within_this_category";
|
| 1642 |
+
echo("\n\n$query\n\n");
|
| 1643 |
+
$this->db_do($query);
|
| 1644 |
+
|
| 1645 |
+
|
| 1646 |
+
$query = "
|
| 1647 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 1648 |
+
JOIN $catalog_category_entity cce
|
| 1649 |
+
ON cmt.parent_store_category_id = cce.store_category_id
|
| 1650 |
+
SET cmt.shop_parent_id = cce.entity_id";
|
| 1651 |
+
echo("\n\n$query\n\n");
|
| 1652 |
+
$this->db_do($query);
|
| 1653 |
+
|
| 1654 |
+
|
| 1655 |
+
$query = "
|
| 1656 |
+
SELECT DISTINCT
|
| 1657 |
+
c.RootName, cce.entity_id
|
| 1658 |
+
FROM $categories_temp c
|
| 1659 |
+
JOIN $catalog_category_entity_varchar ccev
|
| 1660 |
+
ON c.RootName = ccev.value
|
| 1661 |
+
AND ccev.entity_type_id = $_categoryEntityTypeId
|
| 1662 |
+
AND ccev.attribute_id = $name_attrid
|
| 1663 |
+
AND ccev.store_id = 0
|
| 1664 |
+
JOIN $catalog_category_entity cce
|
| 1665 |
+
ON ccev.entity_id = cce.entity_id";
|
| 1666 |
+
echo("\n\n$query\n\n");
|
| 1667 |
+
$root_categories = $this->db_do($query);
|
| 1668 |
+
|
| 1669 |
+
while($root_cat = mysql_fetch_array($root_categories))
|
| 1670 |
+
{
|
| 1671 |
+
$root_id = $root_cat['entity_id'];
|
| 1672 |
+
$root_name = $root_cat['RootName'];
|
| 1673 |
+
|
| 1674 |
+
$query = "
|
| 1675 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 1676 |
+
JOIN $categories_temp c
|
| 1677 |
+
ON cmt.shop_store_category_id = c.store_category_id
|
| 1678 |
+
SET
|
| 1679 |
+
cmt.shop_parent_id = $root_id,
|
| 1680 |
+
cmt.shop_parent_store_category_id = $root_id,
|
| 1681 |
+
cmt.parent_store_category_id = $root_id,
|
| 1682 |
+
c.parent_store_category_id = $root_id
|
| 1683 |
+
WHERE RootName = '$root_name'
|
| 1684 |
+
AND cmt.shop_parent_id = 0";
|
| 1685 |
+
echo("\n\n$query\n\n");
|
| 1686 |
+
$this->db_do($query);
|
| 1687 |
+
}
|
| 1688 |
+
|
| 1689 |
+
|
| 1690 |
+
|
| 1691 |
+
// added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
|
| 1692 |
+
if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE")) $where = '';
|
| 1693 |
+
else $where = 'WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL';
|
| 1694 |
+
|
| 1695 |
+
$query = "
|
| 1696 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 1697 |
+
JOIN $catalog_category_entity cce
|
| 1698 |
+
ON cmt.shop_entity_id = cce.entity_id
|
| 1699 |
+
SET cce.parent_id = cmt.shop_parent_id
|
| 1700 |
+
$where";
|
| 1701 |
+
echo("\n\n$query\n\n");
|
| 1702 |
+
$this->db_do($query);
|
| 1703 |
+
|
| 1704 |
+
$query = "DROP TABLE IF EXISTS $stINch_categories_mapping";
|
| 1705 |
+
echo("\n\n$query\n\n");
|
| 1706 |
+
$this->db_do($query);
|
| 1707 |
+
|
| 1708 |
+
$query = "RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping";
|
| 1709 |
+
echo("\n\n$query\n\n");
|
| 1710 |
+
$this->db_do($query);
|
| 1711 |
+
|
| 1712 |
+
echo("\nmapSinchCategoriesMultistore done... \n==========================================================================\n\n\n\n");
|
| 1713 |
+
} // public function mapSinchCategoriesMultistore($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type)
|
| 1714 |
+
################################################################################################################################################################
|
| 1715 |
+
|
| 1716 |
+
|
| 1717 |
+
|
| 1718 |
+
################################################################################################################################################################
|
| 1719 |
+
private function createMappingSinchTables($stINch_categories_mapping_temp, $stINch_categories_mapping)
|
| 1720 |
+
{
|
| 1721 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
|
| 1722 |
+
$this->db_do("
|
| 1723 |
+
CREATE TABLE $stINch_categories_mapping_temp
|
| 1724 |
+
(
|
| 1725 |
+
shop_entity_id INT(11) UNSIGNED NOT NULL,
|
| 1726 |
+
shop_entity_type_id INT(11),
|
| 1727 |
+
shop_attribute_set_id INT(11),
|
| 1728 |
+
shop_parent_id INT(11),
|
| 1729 |
+
shop_store_category_id INT(11),
|
| 1730 |
+
shop_parent_store_category_id INT(11),
|
| 1731 |
+
store_category_id INT(11),
|
| 1732 |
+
parent_store_category_id INT(11),
|
| 1733 |
+
category_name VARCHAR(255),
|
| 1734 |
+
order_number INT(11),
|
| 1735 |
+
products_within_this_category INT(11),
|
| 1736 |
+
|
| 1737 |
+
KEY shop_entity_id (shop_entity_id),
|
| 1738 |
+
KEY shop_parent_id (shop_parent_id),
|
| 1739 |
+
KEY store_category_id (store_category_id),
|
| 1740 |
+
KEY parent_store_category_id (parent_store_category_id),
|
| 1741 |
+
UNIQUE KEY(shop_entity_id)
|
| 1742 |
+
)");
|
| 1743 |
+
|
| 1744 |
+
|
| 1745 |
+
$this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
|
| 1746 |
+
}
|
| 1747 |
+
################################################################################################################################################################
|
| 1748 |
+
|
| 1749 |
+
|
| 1750 |
+
|
| 1751 |
+
################################################################################################################################################################
|
| 1752 |
+
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,
|
| 1753 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $im_type,
|
| 1754 |
+
$name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid)
|
| 1755 |
+
{
|
| 1756 |
+
echo("\n\n\n\n*************************************************************\nmapSinchCategoriesMultistore start... \n");
|
| 1757 |
+
if (UPDATE_CATEGORY_DATA)
|
| 1758 |
+
{
|
| 1759 |
+
$ignore = '';
|
| 1760 |
+
$on_diplicate_key_update = "
|
| 1761 |
+
ON DUPLICATE KEY UPDATE
|
| 1762 |
+
updated_at = now(),
|
| 1763 |
+
store_category_id = c.store_category_id,
|
| 1764 |
+
level = c.level,
|
| 1765 |
+
children_count = c.children_count,
|
| 1766 |
+
position = c.order_number,
|
| 1767 |
+
parent_store_category_id = c.parent_store_category_id";
|
| 1768 |
+
//level=c.level,
|
| 1769 |
+
//children_count=c.children_count
|
| 1770 |
+
//position=c.order_number,
|
| 1771 |
+
}
|
| 1772 |
+
else
|
| 1773 |
+
{
|
| 1774 |
+
$ignore = 'IGNORE';
|
| 1775 |
+
$on_diplicate_key_update = '';
|
| 1776 |
+
}
|
| 1777 |
+
|
| 1778 |
+
$query = "
|
| 1779 |
+
INSERT $ignore INTO $catalog_category_entity
|
| 1780 |
+
(
|
| 1781 |
+
entity_type_id,
|
| 1782 |
+
attribute_set_id,
|
| 1783 |
+
created_at,
|
| 1784 |
+
updated_at,
|
| 1785 |
+
level,
|
| 1786 |
+
children_count,
|
| 1787 |
+
entity_id,
|
| 1788 |
+
position,
|
| 1789 |
+
parent_id,
|
| 1790 |
+
store_category_id,
|
| 1791 |
+
parent_store_category_id
|
| 1792 |
+
)
|
| 1793 |
+
(SELECT
|
| 1794 |
+
$_categoryEntityTypeId,
|
| 1795 |
+
$_categoryDefault_attribute_set_id,
|
| 1796 |
+
NOW(),
|
| 1797 |
+
NOW(),
|
| 1798 |
+
c.level,
|
| 1799 |
+
c.children_count,
|
| 1800 |
+
scm.shop_entity_id,
|
| 1801 |
+
c.order_number,
|
| 1802 |
+
scm.shop_parent_id,
|
| 1803 |
+
c.store_category_id,
|
| 1804 |
+
c.parent_store_category_id
|
| 1805 |
+
FROM $categories_temp c
|
| 1806 |
+
LEFT JOIN $stINch_categories_mapping scm
|
| 1807 |
+
ON c.store_category_id = scm.store_category_id
|
| 1808 |
+
) $on_diplicate_key_update";
|
| 1809 |
+
echo("\n\n$query\n\n");
|
| 1810 |
+
$this->db_do($query);
|
| 1811 |
+
|
| 1812 |
+
//return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!
|
| 1813 |
+
|
| 1814 |
+
|
| 1815 |
+
$this->mapSinchCategoriesMultistore($stINch_categories_mapping_temp, $stINch_categories_mapping, $catalog_category_entity, $catalog_category_entity_varchar, $categories_temp, $im_type, $_categoryEntityTypeId, $name_attrid);
|
| 1816 |
+
|
| 1817 |
+
|
| 1818 |
+
$categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
|
| 1819 |
+
while ($row = mysql_fetch_array($categories))
|
| 1820 |
+
{
|
| 1821 |
+
$parent_id = $row['parent_id'];
|
| 1822 |
+
$entity_id = $row['entity_id'];
|
| 1823 |
+
|
| 1824 |
+
$path = $this->culcPathMultistore($parent_id, $entity_id, $catalog_category_entity);
|
| 1825 |
+
|
| 1826 |
+
$this->db_do("
|
| 1827 |
+
UPDATE $catalog_category_entity
|
| 1828 |
+
SET path = '$path'
|
| 1829 |
+
WHERE entity_id = $entity_id");
|
| 1830 |
+
} // while ($row = mysql_fetch_array($categories))
|
| 1831 |
+
|
| 1832 |
+
|
| 1833 |
+
///////////////////////////////////////////////////////
|
| 1834 |
+
|
| 1835 |
+
|
| 1836 |
+
if(UPDATE_CATEGORY_DATA)
|
| 1837 |
+
{
|
| 1838 |
+
echo "Update category_data \n";
|
| 1839 |
+
|
| 1840 |
+
$q = "
|
| 1841 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 1842 |
+
(
|
| 1843 |
+
entity_type_id,
|
| 1844 |
+
attribute_id,
|
| 1845 |
+
store_id,
|
| 1846 |
+
entity_id,
|
| 1847 |
+
value
|
| 1848 |
+
)
|
| 1849 |
+
(SELECT
|
| 1850 |
+
$_categoryEntityTypeId,
|
| 1851 |
+
$name_attrid,
|
| 1852 |
+
0,
|
| 1853 |
+
scm.shop_entity_id,
|
| 1854 |
+
c.category_name
|
| 1855 |
+
FROM $categories_temp c
|
| 1856 |
+
JOIN $stINch_categories_mapping scm
|
| 1857 |
+
ON c.store_category_id = scm.store_category_id
|
| 1858 |
+
)
|
| 1859 |
+
ON DUPLICATE KEY UPDATE
|
| 1860 |
+
value = c.category_name";
|
| 1861 |
+
$this->db_do($q);
|
| 1862 |
+
|
| 1863 |
+
|
| 1864 |
+
$q = "
|
| 1865 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 1866 |
+
(
|
| 1867 |
+
entity_type_id,
|
| 1868 |
+
attribute_id,
|
| 1869 |
+
store_id,
|
| 1870 |
+
entity_id,
|
| 1871 |
+
value
|
| 1872 |
+
)
|
| 1873 |
+
(SELECT
|
| 1874 |
+
$_categoryEntityTypeId,
|
| 1875 |
+
$name_attrid,
|
| 1876 |
+
1,
|
| 1877 |
+
scm.shop_entity_id,
|
| 1878 |
+
c.category_name
|
| 1879 |
+
FROM $categories_temp c
|
| 1880 |
+
JOIN $stINch_categories_mapping scm
|
| 1881 |
+
ON c.store_category_id = scm.store_category_id
|
| 1882 |
+
)
|
| 1883 |
+
ON DUPLICATE KEY UPDATE
|
| 1884 |
+
value = c.category_name";
|
| 1885 |
+
$this->db_do($q);
|
| 1886 |
+
|
| 1887 |
+
|
| 1888 |
+
$q = "
|
| 1889 |
+
INSERT INTO $catalog_category_entity
|
| 1890 |
+
(
|
| 1891 |
+
entity_type_id,
|
| 1892 |
+
attribute_id,
|
| 1893 |
+
store_id,
|
| 1894 |
+
entity_id,
|
| 1895 |
+
value
|
| 1896 |
+
)
|
| 1897 |
+
(SELECT
|
| 1898 |
+
$_categoryEntityTypeId,
|
| 1899 |
+
$attr_is_active,
|
| 1900 |
+
0,
|
| 1901 |
+
scm.shop_entity_id,
|
| 1902 |
+
1
|
| 1903 |
+
FROM $categories_temp c
|
| 1904 |
+
JOIN $stINch_categories_mapping scm
|
| 1905 |
+
ON c.store_category_id = scm.store_category_id
|
| 1906 |
+
)
|
| 1907 |
+
ON DUPLICATE KEY UPDATE
|
| 1908 |
+
value = 1";
|
| 1909 |
+
$this->db_do($q);
|
| 1910 |
+
|
| 1911 |
+
|
| 1912 |
+
$q = "
|
| 1913 |
+
INSERT INTO $catalog_category_entity_int
|
| 1914 |
+
(
|
| 1915 |
+
entity_type_id,
|
| 1916 |
+
attribute_id,
|
| 1917 |
+
store_id,
|
| 1918 |
+
entity_id,
|
| 1919 |
+
value
|
| 1920 |
+
)
|
| 1921 |
+
(SELECT
|
| 1922 |
+
$_categoryEntityTypeId,
|
| 1923 |
+
$attr_is_active,
|
| 1924 |
+
1,
|
| 1925 |
+
scm.shop_entity_id,
|
| 1926 |
+
1
|
| 1927 |
+
FROM $categories_temp c
|
| 1928 |
+
JOIN $stINch_categories_mapping scm
|
| 1929 |
+
ON c.store_category_id = scm.store_category_id
|
| 1930 |
+
)
|
| 1931 |
+
ON DUPLICATE KEY UPDATE
|
| 1932 |
+
value = 1";
|
| 1933 |
+
$this->db_do($q);
|
| 1934 |
+
|
| 1935 |
+
|
| 1936 |
+
$q = "
|
| 1937 |
+
INSERT INTO $catalog_category_entity_int
|
| 1938 |
+
(
|
| 1939 |
+
entity_type_id,
|
| 1940 |
+
attribute_id,
|
| 1941 |
+
store_id,
|
| 1942 |
+
entity_id,
|
| 1943 |
+
value
|
| 1944 |
+
)
|
| 1945 |
+
(SELECT
|
| 1946 |
+
$_categoryEntityTypeId,
|
| 1947 |
+
$attr_include_in_menu,
|
| 1948 |
+
0,
|
| 1949 |
+
scm.shop_entity_id,
|
| 1950 |
+
1
|
| 1951 |
+
FROM $categories_temp c
|
| 1952 |
+
JOIN $stINch_categories_mapping scm
|
| 1953 |
+
ON c.store_category_id = scm.store_category_id
|
| 1954 |
+
)
|
| 1955 |
+
ON DUPLICATE KEY UPDATE
|
| 1956 |
+
value = 1";
|
| 1957 |
+
$this->db_do($q);
|
| 1958 |
+
|
| 1959 |
+
|
| 1960 |
+
$q = "
|
| 1961 |
+
INSERT INTO $catalog_category_entity_int
|
| 1962 |
+
(
|
| 1963 |
+
entity_type_id,
|
| 1964 |
+
attribute_id,
|
| 1965 |
+
store_id,
|
| 1966 |
+
entity_id,
|
| 1967 |
+
value
|
| 1968 |
+
)
|
| 1969 |
+
(SELECT
|
| 1970 |
+
$_categoryEntityTypeId,
|
| 1971 |
+
$is_anchor_attrid,
|
| 1972 |
+
1,
|
| 1973 |
+
scm.shop_entity_id,
|
| 1974 |
+
1
|
| 1975 |
+
FROM $categories_temp c
|
| 1976 |
+
JOIN $stINch_categories_mapping scm
|
| 1977 |
+
ON c.store_category_id = scm.store_category_id
|
| 1978 |
+
)
|
| 1979 |
+
ON DUPLICATE KEY UPDATE
|
| 1980 |
+
value = 1";
|
| 1981 |
+
$this->db_do($q);
|
| 1982 |
+
|
| 1983 |
+
|
| 1984 |
+
$q = "
|
| 1985 |
+
INSERT INTO $catalog_category_entity_int
|
| 1986 |
+
(
|
| 1987 |
+
entity_type_id,
|
| 1988 |
+
attribute_id,
|
| 1989 |
+
store_id,
|
| 1990 |
+
entity_id,
|
| 1991 |
+
value
|
| 1992 |
+
)
|
| 1993 |
+
(SELECT
|
| 1994 |
+
$_categoryEntityTypeId,
|
| 1995 |
+
$is_anchor_attrid,
|
| 1996 |
+
0,
|
| 1997 |
+
scm.shop_entity_id,
|
| 1998 |
+
1
|
| 1999 |
+
FROM $categories_temp c
|
| 2000 |
+
JOIN $stINch_categories_mapping scm
|
| 2001 |
+
ON c.store_category_id = scm.store_category_id
|
| 2002 |
+
)
|
| 2003 |
+
ON DUPLICATE KEY UPDATE
|
| 2004 |
+
value = 1";
|
| 2005 |
+
$this->db_do($q);
|
| 2006 |
+
|
| 2007 |
+
$q = "
|
| 2008 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 2009 |
+
(
|
| 2010 |
+
entity_type_id,
|
| 2011 |
+
attribute_id,
|
| 2012 |
+
store_id,
|
| 2013 |
+
entity_id,
|
| 2014 |
+
value
|
| 2015 |
+
)
|
| 2016 |
+
(SELECT
|
| 2017 |
+
$_categoryEntityTypeId,
|
| 2018 |
+
$image_attrid,
|
| 2019 |
+
0,
|
| 2020 |
+
scm.shop_entity_id,
|
| 2021 |
+
c.categories_image
|
| 2022 |
+
FROM $categories_temp c
|
| 2023 |
+
JOIN $stINch_categories_mapping scm
|
| 2024 |
+
ON c.store_category_id = scm.store_category_id
|
| 2025 |
+
)
|
| 2026 |
+
ON DUPLICATE KEY UPDATE
|
| 2027 |
+
value = c.categories_image";
|
| 2028 |
+
$this->db_do($q);
|
| 2029 |
+
}
|
| 2030 |
+
else
|
| 2031 |
+
{
|
| 2032 |
+
echo "Insert ignore category_data \n";
|
| 2033 |
+
|
| 2034 |
+
$q = "
|
| 2035 |
+
INSERT IGNORE INTO $catalog_category_entity_varchar
|
| 2036 |
+
(
|
| 2037 |
+
entity_type_id,
|
| 2038 |
+
attribute_id,
|
| 2039 |
+
store_id,
|
| 2040 |
+
entity_id,
|
| 2041 |
+
value
|
| 2042 |
+
)
|
| 2043 |
+
(SELECT
|
| 2044 |
+
$_categoryEntityTypeId,
|
| 2045 |
+
$name_attrid,
|
| 2046 |
+
0,
|
| 2047 |
+
scm.shop_entity_id,
|
| 2048 |
+
c.category_name
|
| 2049 |
+
FROM $categories_temp c
|
| 2050 |
+
JOIN $stINch_categories_mapping scm
|
| 2051 |
+
ON c.store_category_id = scm.store_category_id
|
| 2052 |
+
)";
|
| 2053 |
+
$this->db_do($q);
|
| 2054 |
+
|
| 2055 |
+
|
| 2056 |
+
$q = "
|
| 2057 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 2058 |
+
(
|
| 2059 |
+
entity_type_id,
|
| 2060 |
+
attribute_id,
|
| 2061 |
+
store_id,
|
| 2062 |
+
entity_id,
|
| 2063 |
+
value
|
| 2064 |
+
)
|
| 2065 |
+
(SELECT
|
| 2066 |
+
$_categoryEntityTypeId,
|
| 2067 |
+
$attr_is_active,
|
| 2068 |
+
0,
|
| 2069 |
+
scm.shop_entity_id,
|
| 2070 |
+
1
|
| 2071 |
+
FROM $categories_temp c
|
| 2072 |
+
JOIN $stINch_categories_mapping scm
|
| 2073 |
+
ON c.store_category_id = scm.store_category_id
|
| 2074 |
+
)";
|
| 2075 |
+
$this->db_do($q);
|
| 2076 |
+
|
| 2077 |
+
|
| 2078 |
+
$q = "
|
| 2079 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 2080 |
+
(
|
| 2081 |
+
entity_type_id,
|
| 2082 |
+
attribute_id,
|
| 2083 |
+
store_id,
|
| 2084 |
+
entity_id,
|
| 2085 |
+
value
|
| 2086 |
+
)
|
| 2087 |
+
(SELECT
|
| 2088 |
+
$_categoryEntityTypeId,
|
| 2089 |
+
$attr_include_in_menu,
|
| 2090 |
+
0,
|
| 2091 |
+
scm.shop_entity_id,
|
| 2092 |
+
1
|
| 2093 |
+
FROM $categories_temp c
|
| 2094 |
+
JOIN $stINch_categories_mapping scm
|
| 2095 |
+
ON c.store_category_id = scm.store_category_id
|
| 2096 |
+
)";
|
| 2097 |
+
$this->db_do($q);
|
| 2098 |
+
|
| 2099 |
+
|
| 2100 |
+
$q = "
|
| 2101 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 2102 |
+
(
|
| 2103 |
+
entity_type_id,
|
| 2104 |
+
attribute_id,
|
| 2105 |
+
store_id,
|
| 2106 |
+
entity_id,
|
| 2107 |
+
value
|
| 2108 |
+
)
|
| 2109 |
+
(SELECT
|
| 2110 |
+
$_categoryEntityTypeId,
|
| 2111 |
+
$is_anchor_attrid,
|
| 2112 |
+
0,
|
| 2113 |
+
scm.shop_entity_id,
|
| 2114 |
+
1
|
| 2115 |
+
FROM $categories_temp c
|
| 2116 |
+
JOIN $stINch_categories_mapping scm
|
| 2117 |
+
ON c.store_category_id = scm.store_category_id
|
| 2118 |
+
)";
|
| 2119 |
+
$this->db_do($q);
|
| 2120 |
+
|
| 2121 |
+
|
| 2122 |
+
$q = "
|
| 2123 |
+
INSERT IGNORE INTO $catalog_category_entity_varchar
|
| 2124 |
+
(
|
| 2125 |
+
entity_type_id,
|
| 2126 |
+
attribute_id,
|
| 2127 |
+
store_id,
|
| 2128 |
+
entity_id,
|
| 2129 |
+
value
|
| 2130 |
+
)
|
| 2131 |
+
(SELECT
|
| 2132 |
+
$_categoryEntityTypeId,
|
| 2133 |
+
$image_attrid,
|
| 2134 |
+
0,
|
| 2135 |
+
scm.shop_entity_id,
|
| 2136 |
+
c.categories_image
|
| 2137 |
+
FROM $categories_temp c
|
| 2138 |
+
JOIN $stINch_categories_mapping scm
|
| 2139 |
+
ON c.store_category_id = scm.store_category_id
|
| 2140 |
+
)";
|
| 2141 |
+
$this->db_do($q);
|
| 2142 |
+
}
|
| 2143 |
+
|
| 2144 |
+
$this->delete_old_sinch_categories_from_shop();
|
| 2145 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories\n\n");
|
| 2146 |
+
$this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
|
| 2147 |
+
} // private function addCategoryDataMultistore(...)
|
| 2148 |
+
################################################################################################################################################################
|
| 2149 |
+
|
| 2150 |
+
|
| 2151 |
+
|
| 2152 |
+
################################################################################################################################################################
|
| 2153 |
+
function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
|
| 2154 |
+
{
|
| 2155 |
+
|
| 2156 |
+
//echo("\nparent_id = [$parent_id] ent_id = [$ent_id]");
|
| 2157 |
+
|
| 2158 |
+
$path = '';
|
| 2159 |
+
|
| 2160 |
+
$cat_id = $parent_id;
|
| 2161 |
+
|
| 2162 |
+
$q = "
|
| 2163 |
+
SELECT
|
| 2164 |
+
parent_id
|
| 2165 |
+
FROM $catalog_category_entity
|
| 2166 |
+
WHERE entity_id = $cat_id";
|
| 2167 |
+
$quer = $this->db_do($q);
|
| 2168 |
+
$row = mysql_fetch_array($quer);
|
| 2169 |
+
while ($row['parent_id'])
|
| 2170 |
+
{
|
| 2171 |
+
$path = $row['parent_id'].'/'.$path;
|
| 2172 |
+
$parent_id = $row['parent_id'];
|
| 2173 |
+
|
| 2174 |
+
$q = "
|
| 2175 |
+
SELECT
|
| 2176 |
+
parent_id
|
| 2177 |
+
FROM $catalog_category_entity
|
| 2178 |
+
WHERE entity_id = $parent_id";
|
| 2179 |
+
$quer = $this->db_do($q);
|
| 2180 |
+
$row = mysql_fetch_array($quer);
|
| 2181 |
+
}
|
| 2182 |
+
|
| 2183 |
+
if ($cat_id) $path.=$cat_id."/";
|
| 2184 |
+
|
| 2185 |
+
if ($path) $path .= $ent_id;
|
| 2186 |
+
else $path = $ent_id;
|
| 2187 |
+
|
| 2188 |
+
//echo(" path = [$path]\n");
|
| 2189 |
+
|
| 2190 |
+
return $path;
|
| 2191 |
+
} // function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
|
| 2192 |
+
################################################################################################################################################################
|
| 2193 |
+
|
| 2194 |
+
|
| 2195 |
+
|
| 2196 |
+
|
| 2197 |
+
|
| 2198 |
+
|
| 2199 |
+
|
| 2200 |
+
|
| 2201 |
+
################################################################################################################################################################
|
| 2202 |
+
public function replaceMagentoProductsMultistoreMERGE($coincidence)
|
| 2203 |
+
{
|
| 2204 |
+
|
| 2205 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 1\n");
|
| 2206 |
+
|
| 2207 |
+
|
| 2208 |
+
|
| 2209 |
+
$connection = Mage::getModel('core/resource')->getConnection('core_write');
|
| 2210 |
+
|
| 2211 |
+
|
| 2212 |
+
$products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
|
| 2213 |
+
$products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
|
| 2214 |
+
$catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
|
| 2215 |
+
$catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
|
| 2216 |
+
$catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
|
| 2217 |
+
$catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
|
| 2218 |
+
$stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
|
| 2219 |
+
$stINch_products = Mage::getSingleton('core/resource')->getTableName('stINch_products');
|
| 2220 |
+
$catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
|
| 2221 |
+
$stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
|
| 2222 |
+
$catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
|
| 2223 |
+
$core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
|
| 2224 |
+
$catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
|
| 2225 |
+
$catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
|
| 2226 |
+
$catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
|
| 2227 |
+
$catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
|
| 2228 |
+
$catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
|
| 2229 |
+
|
| 2230 |
+
$_getProductEntityTypeId = $this->_getProductEntityTypeId();
|
| 2231 |
+
$_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
|
| 2232 |
+
|
| 2233 |
+
$attr_atatus = $this->_getProductAttributeId('status');
|
| 2234 |
+
$attr_name = $this->_getProductAttributeId('name');
|
| 2235 |
+
$attr_visibility = $this->_getProductAttributeId('visibility');
|
| 2236 |
+
$attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
|
| 2237 |
+
$attr_image = $this->_getProductAttributeId('image');
|
| 2238 |
+
$attr_small_image = $this->_getProductAttributeId('small_image');
|
| 2239 |
+
$attr_thumbnail = $this->_getProductAttributeId('thumbnail');
|
| 2240 |
+
|
| 2241 |
+
$cat_attr_name = $this->_getCategoryAttributeId('name');
|
| 2242 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 2\n");
|
| 2243 |
+
|
| 2244 |
+
|
| 2245 |
+
|
| 2246 |
+
|
| 2247 |
+
|
| 2248 |
+
//clear products, inserting new products and updating old others.
|
| 2249 |
+
$query = "
|
| 2250 |
+
DELETE cpe
|
| 2251 |
+
FROM $catalog_product_entity cpe
|
| 2252 |
+
JOIN $stINch_products_mapping pm
|
| 2253 |
+
ON cpe.entity_id = pm.entity_id
|
| 2254 |
+
WHERE pm.shop_store_product_id IS NOT NULL
|
| 2255 |
+
AND pm.store_product_id IS NULL";
|
| 2256 |
+
$result = $this->db_do($query);
|
| 2257 |
+
|
| 2258 |
+
|
| 2259 |
+
|
| 2260 |
+
|
| 2261 |
+
|
| 2262 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 3\n");
|
| 2263 |
+
|
| 2264 |
+
$result = $this->db_do("
|
| 2265 |
+
INSERT INTO $catalog_product_entity
|
| 2266 |
+
(entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
|
| 2267 |
+
(SELECT
|
| 2268 |
+
pm.entity_id,
|
| 2269 |
+
$_getProductEntityTypeId,
|
| 2270 |
+
$_defaultAttributeSetId,
|
| 2271 |
+
'simple',
|
| 2272 |
+
a.product_sku,
|
| 2273 |
+
NOW(),
|
| 2274 |
+
0,
|
| 2275 |
+
a.store_product_id,
|
| 2276 |
+
a.sinch_product_id
|
| 2277 |
+
FROM $products_temp a
|
| 2278 |
+
LEFT JOIN $stINch_products_mapping pm
|
| 2279 |
+
ON a.store_product_id = pm.store_product_id
|
| 2280 |
+
AND a.sinch_product_id = pm.sinch_product_id
|
| 2281 |
+
)
|
| 2282 |
+
ON DUPLICATE KEY UPDATE
|
| 2283 |
+
sku = a.product_sku,
|
| 2284 |
+
store_product_id = a.store_product_id,
|
| 2285 |
+
sinch_product_id = a.sinch_product_id");
|
| 2286 |
+
// store_product_id = a.store_product_id,
|
| 2287 |
+
// sinch_product_id = a.sinch_product_id
|
| 2288 |
+
|
| 2289 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 4\n");
|
| 2290 |
+
|
| 2291 |
+
|
| 2292 |
+
|
| 2293 |
+
|
| 2294 |
+
|
| 2295 |
+
//Set enabled
|
| 2296 |
+
$result = $this->db_do("
|
| 2297 |
+
DELETE cpei
|
| 2298 |
+
FROM $catalog_product_entity_int cpei
|
| 2299 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2300 |
+
ON cpei.entity_id = cpe.entity_id
|
| 2301 |
+
WHERE cpe.entity_id IS NULL");
|
| 2302 |
+
|
| 2303 |
+
$result = $this->db_do("
|
| 2304 |
+
INSERT INTO $catalog_product_entity_int
|
| 2305 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2306 |
+
(SELECT
|
| 2307 |
+
$_getProductEntityTypeId,
|
| 2308 |
+
$attr_atatus,
|
| 2309 |
+
w.website,
|
| 2310 |
+
a.entity_id,
|
| 2311 |
+
1
|
| 2312 |
+
FROM $catalog_product_entity a
|
| 2313 |
+
JOIN $products_website_temp w
|
| 2314 |
+
ON a.store_product_id = w.store_product_id
|
| 2315 |
+
)
|
| 2316 |
+
ON DUPLICATE KEY UPDATE
|
| 2317 |
+
value = 1");
|
| 2318 |
+
|
| 2319 |
+
|
| 2320 |
+
|
| 2321 |
+
|
| 2322 |
+
|
| 2323 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 5\n");
|
| 2324 |
+
|
| 2325 |
+
|
| 2326 |
+
// set status = 1 for all stores
|
| 2327 |
+
$result = $this->db_do("
|
| 2328 |
+
INSERT INTO $catalog_product_entity_int
|
| 2329 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2330 |
+
(SELECT
|
| 2331 |
+
$_getProductEntityTypeId,
|
| 2332 |
+
$attr_atatus,
|
| 2333 |
+
0,
|
| 2334 |
+
a.entity_id,
|
| 2335 |
+
1
|
| 2336 |
+
FROM $catalog_product_entity a
|
| 2337 |
+
)
|
| 2338 |
+
ON DUPLICATE KEY UPDATE
|
| 2339 |
+
value = 1");
|
| 2340 |
+
|
| 2341 |
+
|
| 2342 |
+
|
| 2343 |
+
|
| 2344 |
+
|
| 2345 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 6\n");
|
| 2346 |
+
|
| 2347 |
+
|
| 2348 |
+
//Unifying products with categories.
|
| 2349 |
+
$result = $this->db_do("
|
| 2350 |
+
DELETE ccp
|
| 2351 |
+
FROM $catalog_category_product ccp
|
| 2352 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2353 |
+
ON ccp.product_id = cpe.entity_id
|
| 2354 |
+
WHERE cpe.entity_id IS NULL");
|
| 2355 |
+
|
| 2356 |
+
|
| 2357 |
+
|
| 2358 |
+
|
| 2359 |
+
|
| 2360 |
+
|
| 2361 |
+
|
| 2362 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 7\n");
|
| 2363 |
+
|
| 2364 |
+
|
| 2365 |
+
$root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
|
| 2366 |
+
|
| 2367 |
+
$result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
|
| 2368 |
+
$result = $this->db_do("
|
| 2369 |
+
CREATE TABLE $root_cats
|
| 2370 |
+
SELECT
|
| 2371 |
+
entity_id,
|
| 2372 |
+
path,
|
| 2373 |
+
SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
|
| 2374 |
+
LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
|
| 2375 |
+
SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
|
| 2376 |
+
FROM $catalog_category_entity
|
| 2377 |
+
");
|
| 2378 |
+
$result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
|
| 2379 |
+
|
| 2380 |
+
|
| 2381 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 8\n");
|
| 2382 |
+
|
| 2383 |
+
|
| 2384 |
+
// !!! $this->_root_cat
|
| 2385 |
+
$result = $this->db_do("
|
| 2386 |
+
UPDATE IGNORE $catalog_category_product ccp
|
| 2387 |
+
LEFT JOIN $catalog_category_entity cce
|
| 2388 |
+
ON ccp.category_id = cce.entity_id
|
| 2389 |
+
JOIN $root_cats rc
|
| 2390 |
+
ON cce.entity_id = rc.entity_id
|
| 2391 |
+
SET ccp.category_id = rc.root_cat
|
| 2392 |
+
WHERE cce.entity_id IS NULL");
|
| 2393 |
+
|
| 2394 |
+
|
| 2395 |
+
|
| 2396 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 9\n");
|
| 2397 |
+
|
| 2398 |
+
|
| 2399 |
+
|
| 2400 |
+
|
| 2401 |
+
|
| 2402 |
+
$result = $this->db_do("
|
| 2403 |
+
DELETE ccp
|
| 2404 |
+
FROM $catalog_category_product ccp
|
| 2405 |
+
LEFT JOIN $catalog_category_entity cce
|
| 2406 |
+
ON ccp.category_id = cce.entity_id
|
| 2407 |
+
WHERE cce.entity_id IS NULL");
|
| 2408 |
+
|
| 2409 |
+
|
| 2410 |
+
|
| 2411 |
+
|
| 2412 |
+
$stinch_products_delete = Mage::getSingleton('core/resource')->getTableName('stinch_products_delete');
|
| 2413 |
+
|
| 2414 |
+
$result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
|
| 2415 |
+
$result = $this->db_do("
|
| 2416 |
+
CREATE TABLE $stinch_products_delete
|
| 2417 |
+
SELECT cpe.entity_id
|
| 2418 |
+
FROM $catalog_product_entity cpe
|
| 2419 |
+
WHERE cpe.entity_id NOT IN
|
| 2420 |
+
(
|
| 2421 |
+
SELECT cpe2.entity_id
|
| 2422 |
+
FROM $catalog_product_entity cpe2
|
| 2423 |
+
JOIN $stINch_products sp
|
| 2424 |
+
ON cpe2.sinch_product_id = sp.sinch_product_id
|
| 2425 |
+
)");
|
| 2426 |
+
|
| 2427 |
+
|
| 2428 |
+
$result = $this->db_do("DELETE cpe FROM $catalog_product_entity cpe JOIN $stinch_products_delete spd USING(entity_id)");
|
| 2429 |
+
|
| 2430 |
+
$result = $this->db_do("DROP TABLE IF EXISTS $stinch_products_delete");
|
| 2431 |
+
|
| 2432 |
+
|
| 2433 |
+
|
| 2434 |
+
|
| 2435 |
+
|
| 2436 |
+
|
| 2437 |
+
//echo("\n\nget out...\n\n");
|
| 2438 |
+
//return;
|
| 2439 |
+
|
| 2440 |
+
/**
|
| 2441 |
+
|
| 2442 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 10\n");
|
| 2443 |
+
|
| 2444 |
+
|
| 2445 |
+
// TEMPORARY
|
| 2446 |
+
$this->db_do(" DROP TABLE IF EXISTS {$catalog_category_product}_for_delete_temp");
|
| 2447 |
+
$this->db_do("
|
| 2448 |
+
CREATE TABLE `{$catalog_category_product}_for_delete_temp`
|
| 2449 |
+
(
|
| 2450 |
+
`category_id` int(10) unsigned NOT NULL default '0',
|
| 2451 |
+
`product_id` int(10) unsigned NOT NULL default '0',
|
| 2452 |
+
`store_product_id` int(10) NOT NULL default '0',
|
| 2453 |
+
`store_category_id` int(10) NOT NULL default '0',
|
| 2454 |
+
`new_category_id` int(10) NOT NULL default '0',
|
| 2455 |
+
|
| 2456 |
+
UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
|
| 2457 |
+
KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
|
| 2458 |
+
KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
|
| 2459 |
+
KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
|
| 2460 |
+
)");
|
| 2461 |
+
|
| 2462 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 11\n");
|
| 2463 |
+
|
| 2464 |
+
$result = $this->db_do("
|
| 2465 |
+
INSERT INTO {$catalog_category_product}_for_delete_temp
|
| 2466 |
+
(category_id, product_id, store_product_id)
|
| 2467 |
+
(SELECT
|
| 2468 |
+
ccp.category_id,
|
| 2469 |
+
ccp.product_id,
|
| 2470 |
+
cpe.store_product_id
|
| 2471 |
+
FROM $catalog_category_product ccp
|
| 2472 |
+
JOIN $catalog_product_entity cpe
|
| 2473 |
+
ON ccp.product_id = cpe.entity_id
|
| 2474 |
+
WHERE store_product_id IS NOT NULL)");
|
| 2475 |
+
|
| 2476 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 12\n");
|
| 2477 |
+
|
| 2478 |
+
$result = $this->db_do("
|
| 2479 |
+
UPDATE {$catalog_category_product}_for_delete_temp ccpfd
|
| 2480 |
+
JOIN $products_temp p
|
| 2481 |
+
ON ccpfd.store_product_id = p.store_product_id
|
| 2482 |
+
SET ccpfd.store_category_id = p.store_category_id
|
| 2483 |
+
WHERE ccpfd.store_product_id != 0");
|
| 2484 |
+
|
| 2485 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 13\n");
|
| 2486 |
+
|
| 2487 |
+
$result = $this->db_do("
|
| 2488 |
+
UPDATE {$catalog_category_product}_for_delete_temp ccpfd
|
| 2489 |
+
JOIN $stINch_categories_mapping scm
|
| 2490 |
+
ON ccpfd.store_category_id = scm.store_category_id
|
| 2491 |
+
SET ccpfd.new_category_id = scm.shop_entity_id
|
| 2492 |
+
WHERE ccpfd.store_category_id != 0");
|
| 2493 |
+
|
| 2494 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 14\n");
|
| 2495 |
+
|
| 2496 |
+
$result = $this->db_do("DELETE FROM {$catalog_category_product}_for_delete_temp WHERE category_id = new_category_id");
|
| 2497 |
+
|
| 2498 |
+
|
| 2499 |
+
|
| 2500 |
+
$result = $this->db_do("
|
| 2501 |
+
DELETE ccp
|
| 2502 |
+
FROM $catalog_category_product ccp
|
| 2503 |
+
JOIN {$catalog_category_product}_for_delete_temp ccpfd
|
| 2504 |
+
ON ccp.product_id = ccpfd.product_id
|
| 2505 |
+
AND ccp.category_id = ccpfd.category_id");
|
| 2506 |
+
|
| 2507 |
+
/**/
|
| 2508 |
+
|
| 2509 |
+
|
| 2510 |
+
|
| 2511 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 15\n");
|
| 2512 |
+
|
| 2513 |
+
|
| 2514 |
+
|
| 2515 |
+
|
| 2516 |
+
$result = $this->db_do("
|
| 2517 |
+
INSERT INTO $catalog_category_product
|
| 2518 |
+
(category_id, product_id)
|
| 2519 |
+
(SELECT
|
| 2520 |
+
scm.shop_entity_id,
|
| 2521 |
+
cpe.entity_id
|
| 2522 |
+
FROM $catalog_product_entity cpe
|
| 2523 |
+
JOIN $products_temp p
|
| 2524 |
+
ON cpe.store_product_id = p.store_product_id
|
| 2525 |
+
JOIN $stINch_categories_mapping scm
|
| 2526 |
+
ON p.store_category_id = scm.store_category_id
|
| 2527 |
+
)
|
| 2528 |
+
ON DUPLICATE KEY UPDATE
|
| 2529 |
+
product_id = cpe.entity_id");
|
| 2530 |
+
|
| 2531 |
+
|
| 2532 |
+
|
| 2533 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 16\n");
|
| 2534 |
+
|
| 2535 |
+
//Indexing products and categories in the shop
|
| 2536 |
+
$result = $this->db_do("
|
| 2537 |
+
DELETE ccpi
|
| 2538 |
+
FROM $catalog_category_product_index ccpi
|
| 2539 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2540 |
+
ON ccpi.product_id = cpe.entity_id
|
| 2541 |
+
WHERE cpe.entity_id IS NULL");
|
| 2542 |
+
|
| 2543 |
+
|
| 2544 |
+
|
| 2545 |
+
|
| 2546 |
+
|
| 2547 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 16.2\n");
|
| 2548 |
+
|
| 2549 |
+
|
| 2550 |
+
$result = $this->db_do("
|
| 2551 |
+
INSERT INTO $catalog_category_product_index
|
| 2552 |
+
(category_id, product_id, position, is_parent, store_id, visibility)
|
| 2553 |
+
(SELECT
|
| 2554 |
+
a.category_id,
|
| 2555 |
+
a.product_id,
|
| 2556 |
+
a.position,
|
| 2557 |
+
1,
|
| 2558 |
+
b.store_id,
|
| 2559 |
+
4
|
| 2560 |
+
FROM $catalog_category_product a
|
| 2561 |
+
JOIN $core_store b
|
| 2562 |
+
)
|
| 2563 |
+
ON DUPLICATE KEY UPDATE
|
| 2564 |
+
visibility = 4");
|
| 2565 |
+
|
| 2566 |
+
|
| 2567 |
+
|
| 2568 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 17\n");
|
| 2569 |
+
$root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
|
| 2570 |
+
// !!! $this->_root_cat
|
| 2571 |
+
$result = $this->db_do("
|
| 2572 |
+
INSERT ignore INTO $catalog_category_product_index
|
| 2573 |
+
(category_id, product_id, position, is_parent, store_id, visibility)
|
| 2574 |
+
(SELECT
|
| 2575 |
+
rc.root_cat,
|
| 2576 |
+
a.product_id,
|
| 2577 |
+
a.position,
|
| 2578 |
+
1,
|
| 2579 |
+
b.store_id,
|
| 2580 |
+
4
|
| 2581 |
+
FROM $catalog_category_product a
|
| 2582 |
+
JOIN $root_cats rc
|
| 2583 |
+
ON a.category_id = rc.entity_id
|
| 2584 |
+
JOIN $core_store b
|
| 2585 |
+
)
|
| 2586 |
+
ON DUPLICATE KEY UPDATE
|
| 2587 |
+
visibility = 4");
|
| 2588 |
+
|
| 2589 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 18\n");
|
| 2590 |
+
|
| 2591 |
+
|
| 2592 |
+
//Set product name for specific web sites
|
| 2593 |
+
$result = $this->db_do("
|
| 2594 |
+
DELETE cpev
|
| 2595 |
+
FROM $catalog_product_entity_varchar cpev
|
| 2596 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2597 |
+
ON cpev.entity_id = cpe.entity_id
|
| 2598 |
+
WHERE cpe.entity_id IS NULL");
|
| 2599 |
+
|
| 2600 |
+
$result = $this->db_do("
|
| 2601 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2602 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2603 |
+
(SELECT
|
| 2604 |
+
$_getProductEntityTypeId,
|
| 2605 |
+
$attr_name,
|
| 2606 |
+
w.website,
|
| 2607 |
+
a.entity_id,
|
| 2608 |
+
b.product_name
|
| 2609 |
+
FROM $catalog_product_entity a
|
| 2610 |
+
JOIN $products_temp b
|
| 2611 |
+
ON a.store_product_id = b.store_product_id
|
| 2612 |
+
JOIN $products_website_temp w
|
| 2613 |
+
ON a.store_product_id = w.store_product_id
|
| 2614 |
+
)
|
| 2615 |
+
ON DUPLICATE KEY UPDATE
|
| 2616 |
+
value = b.product_name");
|
| 2617 |
+
|
| 2618 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 19\n");
|
| 2619 |
+
|
| 2620 |
+
|
| 2621 |
+
|
| 2622 |
+
|
| 2623 |
+
|
| 2624 |
+
// product name for all web sites
|
| 2625 |
+
$result = $this->db_do("
|
| 2626 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2627 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2628 |
+
(SELECT
|
| 2629 |
+
$_getProductEntityTypeId,
|
| 2630 |
+
$attr_name,
|
| 2631 |
+
0,
|
| 2632 |
+
a.entity_id,
|
| 2633 |
+
b.product_name
|
| 2634 |
+
FROM $catalog_product_entity a
|
| 2635 |
+
JOIN $products_temp b
|
| 2636 |
+
ON a.store_product_id = b.store_product_id
|
| 2637 |
+
)
|
| 2638 |
+
ON DUPLICATE KEY UPDATE
|
| 2639 |
+
value = b.product_name");
|
| 2640 |
+
|
| 2641 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 20\n");
|
| 2642 |
+
|
| 2643 |
+
|
| 2644 |
+
|
| 2645 |
+
$this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
|
| 2646 |
+
$this->addDescriptions();
|
| 2647 |
+
$this->addShortDescriptions();
|
| 2648 |
+
$this->addEAN();
|
| 2649 |
+
$this->addSpecification();
|
| 2650 |
+
$this->addManufacturers();
|
| 2651 |
+
|
| 2652 |
+
|
| 2653 |
+
|
| 2654 |
+
|
| 2655 |
+
|
| 2656 |
+
|
| 2657 |
+
|
| 2658 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 21\n");
|
| 2659 |
+
|
| 2660 |
+
//Enabling product index.
|
| 2661 |
+
$result = $this->db_do("
|
| 2662 |
+
DELETE cpei
|
| 2663 |
+
FROM $catalog_product_enabled_index cpei
|
| 2664 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2665 |
+
ON cpei.product_id = cpe.entity_id
|
| 2666 |
+
WHERE cpe.entity_id IS NULL");
|
| 2667 |
+
|
| 2668 |
+
|
| 2669 |
+
|
| 2670 |
+
|
| 2671 |
+
|
| 2672 |
+
|
| 2673 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 22\n");
|
| 2674 |
+
|
| 2675 |
+
$result = $this->db_do("
|
| 2676 |
+
INSERT INTO $catalog_product_enabled_index
|
| 2677 |
+
(product_id, store_id, visibility)
|
| 2678 |
+
(SELECT
|
| 2679 |
+
a.entity_id,
|
| 2680 |
+
w.website,
|
| 2681 |
+
4
|
| 2682 |
+
FROM $catalog_product_entity a
|
| 2683 |
+
JOIN $products_website_temp w
|
| 2684 |
+
ON a.store_product_id = w.store_product_id
|
| 2685 |
+
)
|
| 2686 |
+
ON DUPLICATE KEY UPDATE
|
| 2687 |
+
visibility = 4");
|
| 2688 |
+
|
| 2689 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 23\n");
|
| 2690 |
+
|
| 2691 |
+
$result = $this->db_do("
|
| 2692 |
+
INSERT INTO $catalog_product_enabled_index
|
| 2693 |
+
(product_id, store_id, visibility)
|
| 2694 |
+
(SELECT
|
| 2695 |
+
a.entity_id,
|
| 2696 |
+
0,
|
| 2697 |
+
4
|
| 2698 |
+
FROM $catalog_product_entity a
|
| 2699 |
+
JOIN $products_website_temp w
|
| 2700 |
+
ON a.store_product_id = w.store_product_id
|
| 2701 |
+
)
|
| 2702 |
+
ON DUPLICATE KEY UPDATE
|
| 2703 |
+
visibility = 4");
|
| 2704 |
+
|
| 2705 |
+
|
| 2706 |
+
/////////////////////////////////////echo(" .... DONE\n");return;
|
| 2707 |
+
|
| 2708 |
+
|
| 2709 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 24\n");
|
| 2710 |
+
|
| 2711 |
+
$result = $this->db_do("
|
| 2712 |
+
INSERT INTO $catalog_product_entity_int
|
| 2713 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2714 |
+
(SELECT
|
| 2715 |
+
$_getProductEntityTypeId,
|
| 2716 |
+
$attr_visibility,
|
| 2717 |
+
w.website,
|
| 2718 |
+
a.entity_id,
|
| 2719 |
+
4
|
| 2720 |
+
FROM $catalog_product_entity a
|
| 2721 |
+
JOIN $products_website_temp w
|
| 2722 |
+
ON a.store_product_id = w.store_product_id
|
| 2723 |
+
)
|
| 2724 |
+
ON DUPLICATE KEY UPDATE
|
| 2725 |
+
value = 4");
|
| 2726 |
+
|
| 2727 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 25\n");
|
| 2728 |
+
|
| 2729 |
+
$result = $this->db_do("
|
| 2730 |
+
INSERT INTO $catalog_product_entity_int
|
| 2731 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2732 |
+
(SELECT
|
| 2733 |
+
$_getProductEntityTypeId,
|
| 2734 |
+
$attr_visibility,
|
| 2735 |
+
0,
|
| 2736 |
+
a.entity_id,
|
| 2737 |
+
4
|
| 2738 |
+
FROM $catalog_product_entity a
|
| 2739 |
+
)
|
| 2740 |
+
ON DUPLICATE KEY UPDATE
|
| 2741 |
+
value = 4");
|
| 2742 |
+
|
| 2743 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 26\n");
|
| 2744 |
+
|
| 2745 |
+
|
| 2746 |
+
|
| 2747 |
+
$result = $this->db_do("
|
| 2748 |
+
DELETE cpw
|
| 2749 |
+
FROM $catalog_product_website cpw
|
| 2750 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2751 |
+
ON cpw.product_id = cpe.entity_id
|
| 2752 |
+
WHERE cpe.entity_id IS NULL");
|
| 2753 |
+
|
| 2754 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 27\n");
|
| 2755 |
+
|
| 2756 |
+
|
| 2757 |
+
|
| 2758 |
+
|
| 2759 |
+
|
| 2760 |
+
|
| 2761 |
+
|
| 2762 |
+
|
| 2763 |
+
|
| 2764 |
+
|
| 2765 |
+
|
| 2766 |
+
$result = $this->db_do("
|
| 2767 |
+
INSERT INTO $catalog_product_website
|
| 2768 |
+
(product_id, website_id)
|
| 2769 |
+
(SELECT
|
| 2770 |
+
a.entity_id,
|
| 2771 |
+
w.website_id
|
| 2772 |
+
FROM $catalog_product_entity a
|
| 2773 |
+
JOIN $products_website_temp w
|
| 2774 |
+
ON a.store_product_id = w.store_product_id
|
| 2775 |
+
)
|
| 2776 |
+
ON DUPLICATE KEY UPDATE
|
| 2777 |
+
product_id = a.entity_id,
|
| 2778 |
+
website_id = w.website_id");
|
| 2779 |
+
|
| 2780 |
+
|
| 2781 |
+
//echo(" .... DONE\n");return;
|
| 2782 |
+
|
| 2783 |
+
|
| 2784 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 28\n");
|
| 2785 |
+
|
| 2786 |
+
// temporary disabled mart@bintime.com
|
| 2787 |
+
//$result = $this->db_do("
|
| 2788 |
+
// UPDATE catalog_category_entity_int a
|
| 2789 |
+
// SET a.value = 0
|
| 2790 |
+
// WHERE a.attribute_id = 32
|
| 2791 |
+
//");
|
| 2792 |
+
|
| 2793 |
+
|
| 2794 |
+
//Adding tax class "Taxable Goods"
|
| 2795 |
+
$result = $this->db_do("
|
| 2796 |
+
INSERT INTO $catalog_product_entity_int
|
| 2797 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2798 |
+
(SELECT
|
| 2799 |
+
$_getProductEntityTypeId,
|
| 2800 |
+
$attr_tax_class_id,
|
| 2801 |
+
w.website,
|
| 2802 |
+
a.entity_id,
|
| 2803 |
+
2
|
| 2804 |
+
FROM $catalog_product_entity a
|
| 2805 |
+
JOIN $products_website_temp w
|
| 2806 |
+
ON a.store_product_id = w.store_product_id
|
| 2807 |
+
)
|
| 2808 |
+
ON DUPLICATE KEY UPDATE
|
| 2809 |
+
value = 2");
|
| 2810 |
+
|
| 2811 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 29\n");
|
| 2812 |
+
|
| 2813 |
+
$result = $this->db_do("
|
| 2814 |
+
INSERT INTO $catalog_product_entity_int
|
| 2815 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2816 |
+
(SELECT
|
| 2817 |
+
$_getProductEntityTypeId,
|
| 2818 |
+
$attr_tax_class_id,
|
| 2819 |
+
0,
|
| 2820 |
+
a.entity_id,
|
| 2821 |
+
2
|
| 2822 |
+
FROM $catalog_product_entity a
|
| 2823 |
+
)
|
| 2824 |
+
ON DUPLICATE KEY UPDATE
|
| 2825 |
+
value = 2");
|
| 2826 |
+
|
| 2827 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 30\n");
|
| 2828 |
+
|
| 2829 |
+
// Load url Image
|
| 2830 |
+
$result = $this->db_do("
|
| 2831 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2832 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2833 |
+
(SELECT
|
| 2834 |
+
$_getProductEntityTypeId,
|
| 2835 |
+
$attr_image,
|
| 2836 |
+
w.store_id,
|
| 2837 |
+
a.entity_id,
|
| 2838 |
+
b.main_image_url
|
| 2839 |
+
FROM $catalog_product_entity a
|
| 2840 |
+
JOIN $core_store w
|
| 2841 |
+
JOIN $products_temp b
|
| 2842 |
+
ON a.store_product_id = b.store_product_id
|
| 2843 |
+
)
|
| 2844 |
+
ON DUPLICATE KEY UPDATE
|
| 2845 |
+
value = b.main_image_url");
|
| 2846 |
+
|
| 2847 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 31\n");
|
| 2848 |
+
|
| 2849 |
+
// image for specific web sites
|
| 2850 |
+
$result = $this->db_do("
|
| 2851 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2852 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2853 |
+
(SELECT
|
| 2854 |
+
$_getProductEntityTypeId,
|
| 2855 |
+
$attr_image,
|
| 2856 |
+
0,
|
| 2857 |
+
a.entity_id,
|
| 2858 |
+
b.main_image_url
|
| 2859 |
+
FROM $catalog_product_entity a
|
| 2860 |
+
JOIN $products_temp b
|
| 2861 |
+
ON a.store_product_id = b.store_product_id
|
| 2862 |
+
)
|
| 2863 |
+
ON DUPLICATE KEY UPDATE
|
| 2864 |
+
value = b.main_image_url");
|
| 2865 |
+
|
| 2866 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 32\n");
|
| 2867 |
+
|
| 2868 |
+
// small_image for specific web sites
|
| 2869 |
+
$result = $this->db_do("
|
| 2870 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2871 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2872 |
+
(SELECT
|
| 2873 |
+
$_getProductEntityTypeId,
|
| 2874 |
+
$attr_small_image,
|
| 2875 |
+
w.store_id,
|
| 2876 |
+
a.entity_id,
|
| 2877 |
+
b.medium_image_url
|
| 2878 |
+
FROM $catalog_product_entity a
|
| 2879 |
+
JOIN $core_store w
|
| 2880 |
+
JOIN $products_temp b
|
| 2881 |
+
ON a.store_product_id = b.store_product_id
|
| 2882 |
+
)
|
| 2883 |
+
ON DUPLICATE KEY UPDATE
|
| 2884 |
+
value = b.medium_image_url");
|
| 2885 |
+
|
| 2886 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 33\n");
|
| 2887 |
+
|
| 2888 |
+
// small_image for all web sites
|
| 2889 |
+
$result = $this->db_do("
|
| 2890 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2891 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2892 |
+
(SELECT
|
| 2893 |
+
$_getProductEntityTypeId,
|
| 2894 |
+
$attr_small_image,
|
| 2895 |
+
0,
|
| 2896 |
+
a.entity_id,
|
| 2897 |
+
b.medium_image_url
|
| 2898 |
+
FROM $catalog_product_entity a
|
| 2899 |
+
JOIN $core_store w
|
| 2900 |
+
JOIN $products_temp b
|
| 2901 |
+
ON a.store_product_id = b.store_product_id
|
| 2902 |
+
)
|
| 2903 |
+
ON DUPLICATE KEY UPDATE
|
| 2904 |
+
value = b.medium_image_url");
|
| 2905 |
+
|
| 2906 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 34\n");
|
| 2907 |
+
|
| 2908 |
+
// thumbnail for specific web site
|
| 2909 |
+
$result = $this->db_do("
|
| 2910 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2911 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2912 |
+
(SELECT
|
| 2913 |
+
$_getProductEntityTypeId,
|
| 2914 |
+
$attr_thumbnail,
|
| 2915 |
+
w.store_id,
|
| 2916 |
+
a.entity_id,
|
| 2917 |
+
b.thumb_image_url
|
| 2918 |
+
FROM $catalog_product_entity a
|
| 2919 |
+
JOIN $core_store w
|
| 2920 |
+
JOIN $products_temp b
|
| 2921 |
+
ON a.store_product_id = b.store_product_id
|
| 2922 |
+
)
|
| 2923 |
+
ON DUPLICATE KEY UPDATE
|
| 2924 |
+
value = b.thumb_image_url");
|
| 2925 |
+
|
| 2926 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 35\n");
|
| 2927 |
+
|
| 2928 |
+
// thumbnail for all web sites
|
| 2929 |
+
$result = $this->db_do("
|
| 2930 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2931 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2932 |
+
(SELECT
|
| 2933 |
+
$_getProductEntityTypeId,
|
| 2934 |
+
$attr_thumbnail,
|
| 2935 |
+
0,
|
| 2936 |
+
a.entity_id,
|
| 2937 |
+
b.thumb_image_url
|
| 2938 |
+
FROM $catalog_product_entity a
|
| 2939 |
+
JOIN $core_store w
|
| 2940 |
+
JOIN $products_temp b
|
| 2941 |
+
ON a.store_product_id = b.store_product_id
|
| 2942 |
+
)
|
| 2943 |
+
ON DUPLICATE KEY UPDATE
|
| 2944 |
+
value = b.thumb_image_url");
|
| 2945 |
+
|
| 2946 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 36\n");
|
| 2947 |
+
|
| 2948 |
+
|
| 2949 |
+
|
| 2950 |
+
|
| 2951 |
+
|
| 2952 |
+
|
| 2953 |
+
//Refresh fulltext search
|
| 2954 |
+
$result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
|
| 2955 |
+
$result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
|
| 2956 |
+
|
| 2957 |
+
|
| 2958 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 36.2\n");
|
| 2959 |
+
$q = "
|
| 2960 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 2961 |
+
(product_id, store_id, data_index)
|
| 2962 |
+
(SELECT
|
| 2963 |
+
a.entity_id,
|
| 2964 |
+
w.website,
|
| 2965 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 2966 |
+
FROM $catalog_product_entity a
|
| 2967 |
+
JOIN $products_website_temp w
|
| 2968 |
+
ON a.store_product_id = w.store_product_id
|
| 2969 |
+
LEFT JOIN $catalog_category_product b
|
| 2970 |
+
ON a.entity_id = b.product_id
|
| 2971 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 2972 |
+
ON b.category_id = c.entity_id
|
| 2973 |
+
AND c.attribute_id = $cat_attr_name
|
| 2974 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 2975 |
+
ON a.entity_id = e.entity_id
|
| 2976 |
+
AND e.attribute_id = $attr_name
|
| 2977 |
+
LEFT JOIN $catalog_product_website j
|
| 2978 |
+
ON a.entity_id = j.product_id
|
| 2979 |
+
LEFT JOIN $products_temp f
|
| 2980 |
+
ON a.entity_id = f.store_product_id
|
| 2981 |
+
)
|
| 2982 |
+
ON DUPLICATE KEY UPDATE
|
| 2983 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
|
| 2984 |
+
echo("\n\n============================\n$q\n============================\n\n");
|
| 2985 |
+
|
| 2986 |
+
|
| 2987 |
+
$result = $this->db_do("
|
| 2988 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 2989 |
+
(product_id, store_id, data_index)
|
| 2990 |
+
(SELECT
|
| 2991 |
+
a.entity_id,
|
| 2992 |
+
w.website,
|
| 2993 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 2994 |
+
FROM $catalog_product_entity a
|
| 2995 |
+
JOIN $products_website_temp w
|
| 2996 |
+
ON a.store_product_id = w.store_product_id
|
| 2997 |
+
LEFT JOIN $catalog_category_product b
|
| 2998 |
+
ON a.entity_id = b.product_id
|
| 2999 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 3000 |
+
ON b.category_id = c.entity_id
|
| 3001 |
+
AND c.attribute_id = $cat_attr_name
|
| 3002 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 3003 |
+
ON a.entity_id = e.entity_id
|
| 3004 |
+
AND e.attribute_id = $attr_name
|
| 3005 |
+
LEFT JOIN $catalog_product_website j
|
| 3006 |
+
ON a.entity_id = j.product_id
|
| 3007 |
+
LEFT JOIN $products_temp f
|
| 3008 |
+
ON a.entity_id = f.store_product_id
|
| 3009 |
+
)
|
| 3010 |
+
ON DUPLICATE KEY UPDATE
|
| 3011 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
|
| 3012 |
+
|
| 3013 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 37\n");
|
| 3014 |
+
|
| 3015 |
+
|
| 3016 |
+
$result = $this->db_do("
|
| 3017 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 3018 |
+
(product_id, store_id, data_index)
|
| 3019 |
+
(SELECT
|
| 3020 |
+
a.entity_id,
|
| 3021 |
+
w.website,
|
| 3022 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 3023 |
+
FROM $catalog_product_entity a
|
| 3024 |
+
JOIN $products_website_temp w
|
| 3025 |
+
ON a.store_product_id = w.store_product_id
|
| 3026 |
+
LEFT JOIN $catalog_category_product b
|
| 3027 |
+
ON a.entity_id = b.product_id
|
| 3028 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 3029 |
+
ON b.category_id = c.entity_id
|
| 3030 |
+
AND c.attribute_id = $cat_attr_name
|
| 3031 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 3032 |
+
ON a.entity_id = e.entity_id
|
| 3033 |
+
AND e.attribute_id = $attr_name
|
| 3034 |
+
LEFT JOIN $products_temp f
|
| 3035 |
+
ON a.entity_id = f.store_product_id
|
| 3036 |
+
)
|
| 3037 |
+
ON DUPLICATE KEY UPDATE
|
| 3038 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
|
| 3039 |
+
|
| 3040 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 38\n");
|
| 3041 |
+
|
| 3042 |
+
$result = $this->db_do("
|
| 3043 |
+
DELETE cf
|
| 3044 |
+
FROM $catalogsearch_fulltext cf
|
| 3045 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 3046 |
+
ON cf.product_id = cpe.entity_id
|
| 3047 |
+
WHERE cpe.entity_id IS NULL");
|
| 3048 |
+
|
| 3049 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 39\n");
|
| 3050 |
+
|
| 3051 |
+
$result = $this->db_do("
|
| 3052 |
+
INSERT INTO $catalogsearch_fulltext
|
| 3053 |
+
(product_id, store_id, data_index)
|
| 3054 |
+
(SELECT
|
| 3055 |
+
a.product_id,
|
| 3056 |
+
a.store_id,
|
| 3057 |
+
a.data_index
|
| 3058 |
+
FROM {$catalogsearch_fulltext}_tmp a
|
| 3059 |
+
WHERE product_id = a.product_id
|
| 3060 |
+
)
|
| 3061 |
+
ON DUPLICATE KEY UPDATE
|
| 3062 |
+
data_index = a.data_index");
|
| 3063 |
+
|
| 3064 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 40\n");
|
| 3065 |
+
|
| 3066 |
+
$this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
|
| 3067 |
+
//INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
|
| 3068 |
+
//TODO add something else
|
| 3069 |
+
|
| 3070 |
+
|
| 3071 |
+
$this->addRelatedProducts();
|
| 3072 |
+
echo("\n replaceMagentoProductsMultistoreMERGE 41\n");
|
| 3073 |
+
} //
|
| 3074 |
+
################################################################################################################################################################
|
| 3075 |
+
|
| 3076 |
+
|
| 3077 |
+
|
| 3078 |
+
|
| 3079 |
+
|
| 3080 |
+
|
| 3081 |
+
|
| 3082 |
+
|
| 3083 |
+
|
| 3084 |
+
|
| 3085 |
+
|
| 3086 |
+
|
| 3087 |
+
|
| 3088 |
+
|
| 3089 |
+
|
| 3090 |
+
|
| 3091 |
+
|
| 3092 |
+
|
| 3093 |
+
|
| 3094 |
+
|
| 3095 |
+
|
| 3096 |
+
|
| 3097 |
+
|
| 3098 |
+
|
| 3099 |
+
|
| 3100 |
+
|
| 3101 |
+
|
| 3102 |
+
|
| 3103 |
+
################################################################################################################################################################
|
| 3104 |
+
public function replaceMagentoProductsMultistore($coincidence)
|
| 3105 |
+
{
|
| 3106 |
+
|
| 3107 |
+
echo("\n replaceMagentoProductsMultistore 1\n");
|
| 3108 |
+
|
| 3109 |
+
|
| 3110 |
+
|
| 3111 |
+
$connection = Mage::getModel('core/resource')->getConnection('core_write');
|
| 3112 |
+
|
| 3113 |
+
|
| 3114 |
+
$products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
|
| 3115 |
+
$products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
|
| 3116 |
+
$catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
|
| 3117 |
+
$catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
|
| 3118 |
+
$catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
|
| 3119 |
+
$catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
|
| 3120 |
+
$stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
|
| 3121 |
+
$catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
|
| 3122 |
+
$stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
|
| 3123 |
+
$catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
|
| 3124 |
+
$core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
|
| 3125 |
+
$catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
|
| 3126 |
+
$catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
|
| 3127 |
+
$catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
|
| 3128 |
+
$catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
|
| 3129 |
+
$catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
|
| 3130 |
+
|
| 3131 |
+
$_getProductEntityTypeId = $this->_getProductEntityTypeId();
|
| 3132 |
+
$_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
|
| 3133 |
+
|
| 3134 |
+
$attr_atatus = $this->_getProductAttributeId('status');
|
| 3135 |
+
$attr_name = $this->_getProductAttributeId('name');
|
| 3136 |
+
$attr_visibility = $this->_getProductAttributeId('visibility');
|
| 3137 |
+
$attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
|
| 3138 |
+
$attr_image = $this->_getProductAttributeId('image');
|
| 3139 |
+
$attr_small_image = $this->_getProductAttributeId('small_image');
|
| 3140 |
+
$attr_thumbnail = $this->_getProductAttributeId('thumbnail');
|
| 3141 |
+
|
| 3142 |
+
$cat_attr_name = $this->_getCategoryAttributeId('name');
|
| 3143 |
+
echo("\n replaceMagentoProductsMultistore 2\n");
|
| 3144 |
+
|
| 3145 |
+
|
| 3146 |
+
|
| 3147 |
+
|
| 3148 |
+
|
| 3149 |
+
//clear products, inserting new products and updating old others.
|
| 3150 |
+
$query = "
|
| 3151 |
+
DELETE cpe
|
| 3152 |
+
FROM $catalog_product_entity cpe
|
| 3153 |
+
JOIN $stINch_products_mapping pm
|
| 3154 |
+
ON cpe.entity_id = pm.entity_id
|
| 3155 |
+
WHERE pm.shop_store_product_id IS NOT NULL
|
| 3156 |
+
AND pm.store_product_id IS NULL";
|
| 3157 |
+
$result = $this->db_do($query);
|
| 3158 |
+
|
| 3159 |
+
|
| 3160 |
+
|
| 3161 |
+
|
| 3162 |
+
|
| 3163 |
+
echo("\n replaceMagentoProductsMultistore 3\n");
|
| 3164 |
+
|
| 3165 |
+
$result = $this->db_do("
|
| 3166 |
+
INSERT INTO $catalog_product_entity
|
| 3167 |
+
(entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
|
| 3168 |
+
(SELECT
|
| 3169 |
+
pm.entity_id,
|
| 3170 |
+
$_getProductEntityTypeId,
|
| 3171 |
+
$_defaultAttributeSetId,
|
| 3172 |
+
'simple',
|
| 3173 |
+
a.product_sku,
|
| 3174 |
+
NOW(),
|
| 3175 |
+
0,
|
| 3176 |
+
a.store_product_id,
|
| 3177 |
+
a.sinch_product_id
|
| 3178 |
+
FROM $products_temp a
|
| 3179 |
+
LEFT JOIN $stINch_products_mapping pm
|
| 3180 |
+
ON a.store_product_id = pm.store_product_id
|
| 3181 |
+
AND a.sinch_product_id = pm.sinch_product_id
|
| 3182 |
+
)
|
| 3183 |
+
ON DUPLICATE KEY UPDATE
|
| 3184 |
+
sku = a.product_sku,
|
| 3185 |
+
store_product_id = a.store_product_id,
|
| 3186 |
+
sinch_product_id = a.sinch_product_id");
|
| 3187 |
+
// store_product_id = a.store_product_id,
|
| 3188 |
+
// sinch_product_id = a.sinch_product_id
|
| 3189 |
+
|
| 3190 |
+
echo("\n replaceMagentoProductsMultistore 4\n");
|
| 3191 |
+
|
| 3192 |
+
|
| 3193 |
+
|
| 3194 |
+
|
| 3195 |
+
|
| 3196 |
+
//Set enabled
|
| 3197 |
+
$result = $this->db_do("
|
| 3198 |
+
DELETE cpei
|
| 3199 |
+
FROM $catalog_product_entity_int cpei
|
| 3200 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 3201 |
+
ON cpei.entity_id = cpe.entity_id
|
| 3202 |
+
WHERE cpe.entity_id IS NULL");
|
| 3203 |
+
|
| 3204 |
+
$result = $this->db_do("
|
| 3205 |
+
INSERT INTO $catalog_product_entity_int
|
| 3206 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3207 |
+
(SELECT
|
| 3208 |
+
$_getProductEntityTypeId,
|
| 3209 |
+
$attr_atatus,
|
| 3210 |
+
w.website,
|
| 3211 |
+
a.entity_id,
|
| 3212 |
+
1
|
| 3213 |
+
FROM $catalog_product_entity a
|
| 3214 |
+
JOIN $products_website_temp w
|
| 3215 |
+
ON a.store_product_id = w.store_product_id
|
| 3216 |
+
)
|
| 3217 |
+
ON DUPLICATE KEY UPDATE
|
| 3218 |
+
value = 1");
|
| 3219 |
+
|
| 3220 |
+
|
| 3221 |
+
|
| 3222 |
+
|
| 3223 |
+
|
| 3224 |
+
echo("\n replaceMagentoProductsMultistore 5\n");
|
| 3225 |
+
|
| 3226 |
+
|
| 3227 |
+
// set status = 1 for all stores
|
| 3228 |
+
$result = $this->db_do("
|
| 3229 |
+
INSERT INTO $catalog_product_entity_int
|
| 3230 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3231 |
+
(SELECT
|
| 3232 |
+
$_getProductEntityTypeId,
|
| 3233 |
+
$attr_atatus,
|
| 3234 |
+
0,
|
| 3235 |
+
a.entity_id,
|
| 3236 |
+
1
|
| 3237 |
+
FROM $catalog_product_entity a
|
| 3238 |
+
)
|
| 3239 |
+
ON DUPLICATE KEY UPDATE
|
| 3240 |
+
value = 1");
|
| 3241 |
+
|
| 3242 |
+
|
| 3243 |
+
|
| 3244 |
+
|
| 3245 |
+
|
| 3246 |
+
echo("\n replaceMagentoProductsMultistore 6\n");
|
| 3247 |
+
|
| 3248 |
+
|
| 3249 |
+
//Unifying products with categories.
|
| 3250 |
+
$result = $this->db_do("
|
| 3251 |
+
DELETE ccp
|
| 3252 |
+
FROM $catalog_category_product ccp
|
| 3253 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 3254 |
+
ON ccp.product_id = cpe.entity_id
|
| 3255 |
+
WHERE cpe.entity_id IS NULL");
|
| 3256 |
+
|
| 3257 |
+
|
| 3258 |
+
|
| 3259 |
+
|
| 3260 |
+
|
| 3261 |
+
|
| 3262 |
+
|
| 3263 |
+
echo("\n replaceMagentoProductsMultistore 7\n");
|
| 3264 |
+
|
| 3265 |
+
|
| 3266 |
+
|
| 3267 |
+
$root_cats = Mage::getSingleton('core/resource')->getTableName('root_cats');
|
| 3268 |
+
|
| 3269 |
+
|
| 3270 |
+
$result = $this->db_do("DROP TABLE IF EXISTS $root_cats");
|
| 3271 |
+
$result = $this->db_do("
|
| 3272 |
+
CREATE TABLE $root_cats
|
| 3273 |
+
SELECT
|
| 3274 |
+
entity_id,
|
| 3275 |
+
path,
|
| 3276 |
+
SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
|
| 3277 |
+
LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
|
| 3278 |
+
SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
|
| 3279 |
+
FROM $catalog_category_entity
|
| 3280 |
+
");
|
| 3281 |
+
$result = $this->db_do("UPDATE $root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
|
| 3282 |
+
|
| 3283 |
+
|
| 3284 |
+
echo("\n replaceMagentoProductsMultistore 8\n");
|
| 3285 |
+
|
| 3286 |
+
|
| 3287 |
+
// !!! $this->_root_cat
|
| 3288 |
+
$result = $this->db_do("
|
| 3289 |
+
UPDATE IGNORE $catalog_category_product ccp
|
| 3290 |
+
LEFT JOIN $catalog_category_entity cce
|
| 3291 |
+
ON ccp.category_id = cce.entity_id
|
| 3292 |
+
JOIN $root_cats rc
|
| 3293 |
+
ON cce.entity_id = rc.entity_id
|
| 3294 |
+
SET ccp.category_id = rc.root_cat
|
| 3295 |
+
WHERE cce.entity_id IS NULL");
|
| 3296 |
+
|
| 3297 |
+
|
| 3298 |
+
|
| 3299 |
+
echo("\n replaceMagentoProductsMultistore 9\n");
|
| 3300 |
+
|
| 3301 |
+
|
| 3302 |
+
|
| 3303 |
+
|
| 3304 |
+
|
| 3305 |
+
$result = $this->db_do("
|
| 3306 |
+
DELETE ccp
|
| 3307 |
+
FROM $catalog_category_product ccp
|
| 3308 |
+
LEFT JOIN $catalog_category_entity cce
|
| 3309 |
+
ON ccp.category_id = cce.entity_id
|
| 3310 |
+
WHERE cce.entity_id IS NULL");
|
| 3311 |
+
|
| 3312 |
+
|
| 3313 |
+
//echo("\n\nget out...\n\n");
|
| 3314 |
+
//return;
|
| 3315 |
+
|
| 3316 |
+
|
| 3317 |
+
|
| 3318 |
+
|
| 3319 |
+
|
| 3320 |
+
echo("\n replaceMagentoProductsMultistore 10\n");
|
| 3321 |
+
|
| 3322 |
+
|
| 3323 |
+
$catalog_category_product_for_delete_temp = Mage::getSingleton('core/resource')->getTableName("{$catalog_category_product}_for_delete_temp");
|
| 3324 |
+
|
| 3325 |
+
// TEMPORARY
|
| 3326 |
+
$this->db_do(" DROP TABLE IF EXISTS $catalog_category_product_for_delete_temp");
|
| 3327 |
+
$this->db_do("
|
| 3328 |
+
CREATE TABLE $catalog_category_product_for_delete_temp
|
| 3329 |
+
(
|
| 3330 |
+
`category_id` int(10) unsigned NOT NULL default '0',
|
| 3331 |
+
`product_id` int(10) unsigned NOT NULL default '0',
|
| 3332 |
+
`store_product_id` int(10) NOT NULL default '0',
|
| 3333 |
+
`store_category_id` int(10) NOT NULL default '0',
|
| 3334 |
+
`new_category_id` int(10) NOT NULL default '0',
|
| 3335 |
+
|
| 3336 |
+
UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
|
| 3337 |
+
KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
|
| 3338 |
+
KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
|
| 3339 |
+
KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
|
| 3340 |
+
)");
|
| 3341 |
+
|
| 3342 |
+
echo("\n replaceMagentoProductsMultistore 11\n");
|
| 3343 |
+
|
| 3344 |
+
$result = $this->db_do("
|
| 3345 |
+
INSERT INTO $catalog_category_product_for_delete_temp
|
| 3346 |
+
(category_id, product_id, store_product_id)
|
| 3347 |
+
(SELECT
|
| 3348 |
+
ccp.category_id,
|
| 3349 |
+
ccp.product_id,
|
| 3350 |
+
cpe.store_product_id
|
| 3351 |
+
FROM $catalog_category_product ccp
|
| 3352 |
+
JOIN $catalog_product_entity cpe
|
| 3353 |
+
ON ccp.product_id = cpe.entity_id
|
| 3354 |
+
WHERE store_product_id IS NOT NULL)");
|
| 3355 |
+
|
| 3356 |
+
echo("\n replaceMagentoProductsMultistore 12\n");
|
| 3357 |
+
|
| 3358 |
+
$result = $this->db_do("
|
| 3359 |
+
UPDATE $catalog_category_product_for_delete_temp ccpfd
|
| 3360 |
+
JOIN $products_temp p
|
| 3361 |
+
ON ccpfd.store_product_id = p.store_product_id
|
| 3362 |
+
SET ccpfd.store_category_id = p.store_category_id
|
| 3363 |
+
WHERE ccpfd.store_product_id != 0");
|
| 3364 |
+
|
| 3365 |
+
echo("\n replaceMagentoProductsMultistore 13\n");
|
| 3366 |
+
|
| 3367 |
+
$result = $this->db_do("
|
| 3368 |
+
UPDATE $catalog_category_product_for_delete_temp ccpfd
|
| 3369 |
+
JOIN $stINch_categories_mapping scm
|
| 3370 |
+
ON ccpfd.store_category_id = scm.store_category_id
|
| 3371 |
+
SET ccpfd.new_category_id = scm.shop_entity_id
|
| 3372 |
+
WHERE ccpfd.store_category_id != 0");
|
| 3373 |
+
|
| 3374 |
+
echo("\n replaceMagentoProductsMultistore 14\n");
|
| 3375 |
+
|
| 3376 |
+
$result = $this->db_do("DELETE FROM $catalog_category_product_for_delete_temp WHERE category_id = new_category_id");
|
| 3377 |
+
|
| 3378 |
+
|
| 3379 |
+
|
| 3380 |
+
$result = $this->db_do("
|
| 3381 |
+
DELETE ccp
|
| 3382 |
+
FROM $catalog_category_product ccp
|
| 3383 |
+
JOIN $catalog_category_product_for_delete_temp ccpfd
|
| 3384 |
+
ON ccp.product_id = ccpfd.product_id
|
| 3385 |
+
AND ccp.category_id = ccpfd.category_id");
|
| 3386 |
+
|
| 3387 |
+
|
| 3388 |
+
//echo("\n\nget out...\n\n");
|
| 3389 |
+
//return;
|
| 3390 |
+
|
| 3391 |
+
|
| 3392 |
+
echo("\n replaceMagentoProductsMultistore 15\n");
|
| 3393 |
+
|
| 3394 |
+
$result = $this->db_do("
|
| 3395 |
+
INSERT INTO $catalog_category_product
|
| 3396 |
+
(category_id, product_id)
|
| 3397 |
+
(SELECT
|
| 3398 |
+
scm.shop_entity_id,
|
| 3399 |
+
cpe.entity_id
|
| 3400 |
+
FROM $catalog_product_entity cpe
|
| 3401 |
+
JOIN $products_temp p
|
| 3402 |
+
ON cpe.store_product_id = p.store_product_id
|
| 3403 |
+
JOIN $stINch_categories_mapping scm
|
| 3404 |
+
ON p.store_category_id = scm.store_category_id
|
| 3405 |
+
)
|
| 3406 |
+
ON DUPLICATE KEY UPDATE
|
| 3407 |
+
product_id = cpe.entity_id");
|
| 3408 |
+
|
| 3409 |
+
|
| 3410 |
+
|
| 3411 |
+
echo("\n replaceMagentoProductsMultistore 16\n");
|
| 3412 |
+
|
| 3413 |
+
//Indexing products and categories in the shop
|
| 3414 |
+
$result = $this->db_do("
|
| 3415 |
+
DELETE ccpi
|
| 3416 |
+
FROM $catalog_category_product_index ccpi
|
| 3417 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 3418 |
+
ON ccpi.product_id = cpe.entity_id
|
| 3419 |
+
WHERE cpe.entity_id IS NULL");
|
| 3420 |
+
|
| 3421 |
+
|
| 3422 |
+
|
| 3423 |
+
echo("\n replaceMagentoProductsMultistore 16.2\n");
|
| 3424 |
+
|
| 3425 |
+
|
| 3426 |
+
$result = $this->db_do("
|
| 3427 |
+
INSERT INTO $catalog_category_product_index
|
| 3428 |
+
(category_id, product_id, position, is_parent, store_id, visibility)
|
| 3429 |
+
(SELECT
|
| 3430 |
+
a.category_id,
|
| 3431 |
+
a.product_id,
|
| 3432 |
+
a.position,
|
| 3433 |
+
1,
|
| 3434 |
+
b.store_id,
|
| 3435 |
+
4
|
| 3436 |
+
FROM $catalog_category_product a
|
| 3437 |
+
JOIN $core_store b
|
| 3438 |
+
)
|
| 3439 |
+
ON DUPLICATE KEY UPDATE
|
| 3440 |
+
visibility = 4");
|
| 3441 |
+
|
| 3442 |
+
|
| 3443 |
+
|
| 3444 |
+
echo("\n replaceMagentoProductsMultistore 17\n");
|
| 3445 |
+
|
| 3446 |
+
// !!! $this->_root_cat
|
| 3447 |
+
$result = $this->db_do("
|
| 3448 |
+
INSERT ignore INTO $catalog_category_product_index
|
| 3449 |
+
(category_id, product_id, position, is_parent, store_id, visibility)
|
| 3450 |
+
(SELECT
|
| 3451 |
+
rc.root_cat,
|
| 3452 |
+
a.product_id,
|
| 3453 |
+
a.position,
|
| 3454 |
+
1,
|
| 3455 |
+
b.store_id,
|
| 3456 |
+
4
|
| 3457 |
+
FROM $catalog_category_product a
|
| 3458 |
+
JOIN root_cats rc
|
| 3459 |
+
ON a.category_id = rc.entity_id
|
| 3460 |
+
JOIN $core_store b
|
| 3461 |
+
)
|
| 3462 |
+
ON DUPLICATE KEY UPDATE
|
| 3463 |
+
visibility = 4");
|
| 3464 |
+
|
| 3465 |
+
echo("\n replaceMagentoProductsMultistore 18\n");
|
| 3466 |
+
|
| 3467 |
+
|
| 3468 |
+
//Set product name for specific web sites
|
| 3469 |
+
$result = $this->db_do("
|
| 3470 |
+
DELETE cpev
|
| 3471 |
+
FROM $catalog_product_entity_varchar cpev
|
| 3472 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 3473 |
+
ON cpev.entity_id = cpe.entity_id
|
| 3474 |
+
WHERE cpe.entity_id IS NULL");
|
| 3475 |
+
|
| 3476 |
+
$result = $this->db_do("
|
| 3477 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 3478 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3479 |
+
(SELECT
|
| 3480 |
+
$_getProductEntityTypeId,
|
| 3481 |
+
$attr_name,
|
| 3482 |
+
w.website,
|
| 3483 |
+
a.entity_id,
|
| 3484 |
+
b.product_name
|
| 3485 |
+
FROM $catalog_product_entity a
|
| 3486 |
+
JOIN $products_temp b
|
| 3487 |
+
ON a.store_product_id = b.store_product_id
|
| 3488 |
+
JOIN $products_website_temp w
|
| 3489 |
+
ON a.store_product_id = w.store_product_id
|
| 3490 |
+
)
|
| 3491 |
+
ON DUPLICATE KEY UPDATE
|
| 3492 |
+
value = b.product_name");
|
| 3493 |
+
|
| 3494 |
+
echo("\n replaceMagentoProductsMultistore 19\n");
|
| 3495 |
+
|
| 3496 |
+
|
| 3497 |
+
// product name for all web sites
|
| 3498 |
+
$result = $this->db_do("
|
| 3499 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 3500 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3501 |
+
(SELECT
|
| 3502 |
+
$_getProductEntityTypeId,
|
| 3503 |
+
$attr_name,
|
| 3504 |
+
0,
|
| 3505 |
+
a.entity_id,
|
| 3506 |
+
b.product_name
|
| 3507 |
+
FROM $catalog_product_entity a
|
| 3508 |
+
JOIN $products_temp b
|
| 3509 |
+
ON a.store_product_id = b.store_product_id
|
| 3510 |
+
)
|
| 3511 |
+
ON DUPLICATE KEY UPDATE
|
| 3512 |
+
value = b.product_name");
|
| 3513 |
+
|
| 3514 |
+
echo("\n replaceMagentoProductsMultistore 20\n");
|
| 3515 |
+
|
| 3516 |
+
|
| 3517 |
+
|
| 3518 |
+
$this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
|
| 3519 |
+
$this->addDescriptions();
|
| 3520 |
+
$this->addShortDescriptions();
|
| 3521 |
+
$this->addEAN();
|
| 3522 |
+
$this->addSpecification();
|
| 3523 |
+
$this->addManufacturers();
|
| 3524 |
+
|
| 3525 |
+
//echo(" .... DONE\n");return;
|
| 3526 |
+
|
| 3527 |
+
echo("\n replaceMagentoProductsMultistore 21\n");
|
| 3528 |
+
|
| 3529 |
+
//Enabling product index.
|
| 3530 |
+
$result = $this->db_do("
|
| 3531 |
+
DELETE cpei
|
| 3532 |
+
FROM $catalog_product_enabled_index cpei
|
| 3533 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 3534 |
+
ON cpei.product_id = cpe.entity_id
|
| 3535 |
+
WHERE cpe.entity_id IS NULL");
|
| 3536 |
+
|
| 3537 |
+
echo("\n replaceMagentoProductsMultistore 22\n");
|
| 3538 |
+
|
| 3539 |
+
$result = $this->db_do("
|
| 3540 |
+
INSERT INTO $catalog_product_enabled_index
|
| 3541 |
+
(product_id, store_id, visibility)
|
| 3542 |
+
(SELECT
|
| 3543 |
+
a.entity_id,
|
| 3544 |
+
w.website,
|
| 3545 |
+
4
|
| 3546 |
+
FROM $catalog_product_entity a
|
| 3547 |
+
JOIN $products_website_temp w
|
| 3548 |
+
ON a.store_product_id = w.store_product_id
|
| 3549 |
+
)
|
| 3550 |
+
ON DUPLICATE KEY UPDATE
|
| 3551 |
+
visibility = 4");
|
| 3552 |
+
|
| 3553 |
+
echo("\n replaceMagentoProductsMultistore 23\n");
|
| 3554 |
+
|
| 3555 |
+
$result = $this->db_do("
|
| 3556 |
+
INSERT INTO $catalog_product_enabled_index
|
| 3557 |
+
(product_id, store_id, visibility)
|
| 3558 |
+
(SELECT
|
| 3559 |
+
a.entity_id,
|
| 3560 |
+
0,
|
| 3561 |
+
4
|
| 3562 |
+
FROM $catalog_product_entity a
|
| 3563 |
+
JOIN $products_website_temp w
|
| 3564 |
+
ON a.store_product_id = w.store_product_id
|
| 3565 |
+
)
|
| 3566 |
+
ON DUPLICATE KEY UPDATE
|
| 3567 |
+
visibility = 4");
|
| 3568 |
+
|
| 3569 |
+
|
| 3570 |
+
/////////////////////////////////////echo(" .... DONE\n");return;
|
| 3571 |
+
|
| 3572 |
+
|
| 3573 |
+
echo("\n replaceMagentoProductsMultistore 24\n");
|
| 3574 |
+
|
| 3575 |
+
$result = $this->db_do("
|
| 3576 |
+
INSERT INTO $catalog_product_entity_int
|
| 3577 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3578 |
+
(SELECT
|
| 3579 |
+
$_getProductEntityTypeId,
|
| 3580 |
+
$attr_visibility,
|
| 3581 |
+
w.website,
|
| 3582 |
+
a.entity_id,
|
| 3583 |
+
4
|
| 3584 |
+
FROM $catalog_product_entity a
|
| 3585 |
+
JOIN $products_website_temp w
|
| 3586 |
+
ON a.store_product_id = w.store_product_id
|
| 3587 |
+
)
|
| 3588 |
+
ON DUPLICATE KEY UPDATE
|
| 3589 |
+
value = 4");
|
| 3590 |
+
|
| 3591 |
+
echo("\n replaceMagentoProductsMultistore 25\n");
|
| 3592 |
+
|
| 3593 |
+
$result = $this->db_do("
|
| 3594 |
+
INSERT INTO $catalog_product_entity_int
|
| 3595 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3596 |
+
(SELECT
|
| 3597 |
+
$_getProductEntityTypeId,
|
| 3598 |
+
$attr_visibility,
|
| 3599 |
+
0,
|
| 3600 |
+
a.entity_id,
|
| 3601 |
+
4
|
| 3602 |
+
FROM $catalog_product_entity a
|
| 3603 |
+
)
|
| 3604 |
+
ON DUPLICATE KEY UPDATE
|
| 3605 |
+
value = 4");
|
| 3606 |
+
|
| 3607 |
+
echo("\n replaceMagentoProductsMultistore 26\n");
|
| 3608 |
+
|
| 3609 |
+
$result = $this->db_do("
|
| 3610 |
+
DELETE cpw
|
| 3611 |
+
FROM $catalog_product_website cpw
|
| 3612 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 3613 |
+
ON cpw.product_id = cpe.entity_id
|
| 3614 |
+
WHERE cpe.entity_id IS NULL");
|
| 3615 |
+
|
| 3616 |
+
echo("\n replaceMagentoProductsMultistore 27\n");
|
| 3617 |
+
|
| 3618 |
+
$result = $this->db_do("
|
| 3619 |
+
INSERT INTO $catalog_product_website
|
| 3620 |
+
(product_id, website_id)
|
| 3621 |
+
(SELECT
|
| 3622 |
+
a.entity_id,
|
| 3623 |
+
w.website_id
|
| 3624 |
+
FROM $catalog_product_entity a
|
| 3625 |
+
JOIN $products_website_temp w
|
| 3626 |
+
ON a.store_product_id = w.store_product_id
|
| 3627 |
+
)
|
| 3628 |
+
ON DUPLICATE KEY UPDATE
|
| 3629 |
+
product_id = a.entity_id,
|
| 3630 |
+
website_id = w.website_id");
|
| 3631 |
+
|
| 3632 |
+
|
| 3633 |
+
//echo(" .... DONE\n");return;
|
| 3634 |
+
|
| 3635 |
+
|
| 3636 |
+
echo("\n replaceMagentoProductsMultistore 28\n");
|
| 3637 |
+
|
| 3638 |
+
// temporary disabled mart@bintime.com
|
| 3639 |
+
//$result = $this->db_do("
|
| 3640 |
+
// UPDATE catalog_category_entity_int a
|
| 3641 |
+
// SET a.value = 0
|
| 3642 |
+
// WHERE a.attribute_id = 32
|
| 3643 |
+
//");
|
| 3644 |
+
|
| 3645 |
+
|
| 3646 |
+
//Adding tax class "Taxable Goods"
|
| 3647 |
+
$result = $this->db_do("
|
| 3648 |
+
INSERT INTO $catalog_product_entity_int
|
| 3649 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3650 |
+
(SELECT
|
| 3651 |
+
$_getProductEntityTypeId,
|
| 3652 |
+
$attr_tax_class_id,
|
| 3653 |
+
w.website,
|
| 3654 |
+
a.entity_id,
|
| 3655 |
+
2
|
| 3656 |
+
FROM $catalog_product_entity a
|
| 3657 |
+
JOIN $products_website_temp w
|
| 3658 |
+
ON a.store_product_id = w.store_product_id
|
| 3659 |
+
)
|
| 3660 |
+
ON DUPLICATE KEY UPDATE
|
| 3661 |
+
value = 2");
|
| 3662 |
+
|
| 3663 |
+
echo("\n replaceMagentoProductsMultistore 29\n");
|
| 3664 |
+
|
| 3665 |
+
$result = $this->db_do("
|
| 3666 |
+
INSERT INTO $catalog_product_entity_int
|
| 3667 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3668 |
+
(SELECT
|
| 3669 |
+
$_getProductEntityTypeId,
|
| 3670 |
+
$attr_tax_class_id,
|
| 3671 |
+
0,
|
| 3672 |
+
a.entity_id,
|
| 3673 |
+
2
|
| 3674 |
+
FROM $catalog_product_entity a
|
| 3675 |
+
)
|
| 3676 |
+
ON DUPLICATE KEY UPDATE
|
| 3677 |
+
value = 2");
|
| 3678 |
+
|
| 3679 |
+
echo("\n replaceMagentoProductsMultistore 30\n");
|
| 3680 |
+
|
| 3681 |
+
// Load url Image
|
| 3682 |
+
$result = $this->db_do("
|
| 3683 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 3684 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3685 |
+
(SELECT
|
| 3686 |
+
$_getProductEntityTypeId,
|
| 3687 |
+
$attr_image,
|
| 3688 |
+
w.store_id,
|
| 3689 |
+
a.entity_id,
|
| 3690 |
+
b.main_image_url
|
| 3691 |
+
FROM $catalog_product_entity a
|
| 3692 |
+
JOIN $core_store w
|
| 3693 |
+
JOIN $products_temp b
|
| 3694 |
+
ON a.store_product_id = b.store_product_id
|
| 3695 |
+
)
|
| 3696 |
+
ON DUPLICATE KEY UPDATE
|
| 3697 |
+
value = b.main_image_url");
|
| 3698 |
+
|
| 3699 |
+
echo("\n replaceMagentoProductsMultistore 31\n");
|
| 3700 |
+
|
| 3701 |
+
// image for specific web sites
|
| 3702 |
+
$result = $this->db_do("
|
| 3703 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 3704 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3705 |
+
(SELECT
|
| 3706 |
+
$_getProductEntityTypeId,
|
| 3707 |
+
$attr_image,
|
| 3708 |
+
0,
|
| 3709 |
+
a.entity_id,
|
| 3710 |
+
b.main_image_url
|
| 3711 |
+
FROM $catalog_product_entity a
|
| 3712 |
+
JOIN $products_temp b
|
| 3713 |
+
ON a.store_product_id = b.store_product_id
|
| 3714 |
+
)
|
| 3715 |
+
ON DUPLICATE KEY UPDATE
|
| 3716 |
+
value = b.main_image_url");
|
| 3717 |
+
|
| 3718 |
+
echo("\n replaceMagentoProductsMultistore 32\n");
|
| 3719 |
+
|
| 3720 |
+
// small_image for specific web sites
|
| 3721 |
+
$result = $this->db_do("
|
| 3722 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 3723 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3724 |
+
(SELECT
|
| 3725 |
+
$_getProductEntityTypeId,
|
| 3726 |
+
$attr_small_image,
|
| 3727 |
+
w.store_id,
|
| 3728 |
+
a.entity_id,
|
| 3729 |
+
b.medium_image_url
|
| 3730 |
+
FROM $catalog_product_entity a
|
| 3731 |
+
JOIN $core_store w
|
| 3732 |
+
JOIN $products_temp b
|
| 3733 |
+
ON a.store_product_id = b.store_product_id
|
| 3734 |
+
)
|
| 3735 |
+
ON DUPLICATE KEY UPDATE
|
| 3736 |
+
value = b.medium_image_url");
|
| 3737 |
+
|
| 3738 |
+
echo("\n replaceMagentoProductsMultistore 33\n");
|
| 3739 |
+
|
| 3740 |
+
// small_image for all web sites
|
| 3741 |
+
$result = $this->db_do("
|
| 3742 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 3743 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3744 |
+
(SELECT
|
| 3745 |
+
$_getProductEntityTypeId,
|
| 3746 |
+
$attr_small_image,
|
| 3747 |
+
0,
|
| 3748 |
+
a.entity_id,
|
| 3749 |
+
b.medium_image_url
|
| 3750 |
+
FROM $catalog_product_entity a
|
| 3751 |
+
JOIN $core_store w
|
| 3752 |
+
JOIN $products_temp b
|
| 3753 |
+
ON a.store_product_id = b.store_product_id
|
| 3754 |
+
)
|
| 3755 |
+
ON DUPLICATE KEY UPDATE
|
| 3756 |
+
value = b.medium_image_url");
|
| 3757 |
+
|
| 3758 |
+
echo("\n replaceMagentoProductsMultistore 34\n");
|
| 3759 |
+
|
| 3760 |
+
// thumbnail for specific web site
|
| 3761 |
+
$result = $this->db_do("
|
| 3762 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 3763 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3764 |
+
(SELECT
|
| 3765 |
+
$_getProductEntityTypeId,
|
| 3766 |
+
$attr_thumbnail,
|
| 3767 |
+
w.store_id,
|
| 3768 |
+
a.entity_id,
|
| 3769 |
+
b.thumb_image_url
|
| 3770 |
+
FROM $catalog_product_entity a
|
| 3771 |
+
JOIN $core_store w
|
| 3772 |
+
JOIN $products_temp b
|
| 3773 |
+
ON a.store_product_id = b.store_product_id
|
| 3774 |
+
)
|
| 3775 |
+
ON DUPLICATE KEY UPDATE
|
| 3776 |
+
value = b.thumb_image_url");
|
| 3777 |
+
|
| 3778 |
+
echo("\n replaceMagentoProductsMultistore 35\n");
|
| 3779 |
+
|
| 3780 |
+
// thumbnail for all web sites
|
| 3781 |
+
$result = $this->db_do("
|
| 3782 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 3783 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 3784 |
+
(SELECT
|
| 3785 |
+
$_getProductEntityTypeId,
|
| 3786 |
+
$attr_thumbnail,
|
| 3787 |
+
0,
|
| 3788 |
+
a.entity_id,
|
| 3789 |
+
b.thumb_image_url
|
| 3790 |
+
FROM $catalog_product_entity a
|
| 3791 |
+
JOIN $core_store w
|
| 3792 |
+
JOIN $products_temp b
|
| 3793 |
+
ON a.store_product_id = b.store_product_id
|
| 3794 |
+
)
|
| 3795 |
+
ON DUPLICATE KEY UPDATE
|
| 3796 |
+
value = b.thumb_image_url");
|
| 3797 |
+
|
| 3798 |
+
echo("\n replaceMagentoProductsMultistore 36\n");
|
| 3799 |
+
|
| 3800 |
+
|
| 3801 |
+
|
| 3802 |
+
|
| 3803 |
+
|
| 3804 |
+
|
| 3805 |
+
//Refresh fulltext search
|
| 3806 |
+
$result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
|
| 3807 |
+
$result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
|
| 3808 |
+
|
| 3809 |
+
|
| 3810 |
+
echo("\n replaceMagentoProductsMultistore 36.2\n");
|
| 3811 |
+
$q = "
|
| 3812 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 3813 |
+
(product_id, store_id, data_index)
|
| 3814 |
+
(SELECT
|
| 3815 |
+
a.entity_id,
|
| 3816 |
+
w.website,
|
| 3817 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 3818 |
+
FROM $catalog_product_entity a
|
| 3819 |
+
JOIN $products_website_temp w
|
| 3820 |
+
ON a.store_product_id = w.store_product_id
|
| 3821 |
+
LEFT JOIN $catalog_category_product b
|
| 3822 |
+
ON a.entity_id = b.product_id
|
| 3823 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 3824 |
+
ON b.category_id = c.entity_id
|
| 3825 |
+
AND c.attribute_id = $cat_attr_name
|
| 3826 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 3827 |
+
ON a.entity_id = e.entity_id
|
| 3828 |
+
AND e.attribute_id = $attr_name
|
| 3829 |
+
LEFT JOIN $catalog_product_website j
|
| 3830 |
+
ON a.entity_id = j.product_id
|
| 3831 |
+
LEFT JOIN $products_temp f
|
| 3832 |
+
ON a.entity_id = f.store_product_id
|
| 3833 |
+
)
|
| 3834 |
+
ON DUPLICATE KEY UPDATE
|
| 3835 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
|
| 3836 |
+
echo("\n\n============================\n$q\n============================\n\n");
|
| 3837 |
+
|
| 3838 |
+
|
| 3839 |
+
$result = $this->db_do("
|
| 3840 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 3841 |
+
(product_id, store_id, data_index)
|
| 3842 |
+
(SELECT
|
| 3843 |
+
a.entity_id,
|
| 3844 |
+
w.website,
|
| 3845 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 3846 |
+
FROM $catalog_product_entity a
|
| 3847 |
+
JOIN $products_website_temp w
|
| 3848 |
+
ON a.store_product_id = w.store_product_id
|
| 3849 |
+
LEFT JOIN $catalog_category_product b
|
| 3850 |
+
ON a.entity_id = b.product_id
|
| 3851 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 3852 |
+
ON b.category_id = c.entity_id
|
| 3853 |
+
AND c.attribute_id = $cat_attr_name
|
| 3854 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 3855 |
+
ON a.entity_id = e.entity_id
|
| 3856 |
+
AND e.attribute_id = $attr_name
|
| 3857 |
+
LEFT JOIN $catalog_product_website j
|
| 3858 |
+
ON a.entity_id = j.product_id
|
| 3859 |
+
LEFT JOIN $products_temp f
|
| 3860 |
+
ON a.entity_id = f.store_product_id
|
| 3861 |
+
)
|
| 3862 |
+
ON DUPLICATE KEY UPDATE
|
| 3863 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
|
| 3864 |
+
|
| 3865 |
+
echo("\n replaceMagentoProductsMultistore 37\n");
|
| 3866 |
+
|
| 3867 |
+
|
| 3868 |
+
$result = $this->db_do("
|
| 3869 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 3870 |
+
(product_id, store_id, data_index)
|
| 3871 |
+
(SELECT
|
| 3872 |
+
a.entity_id,
|
| 3873 |
+
w.website,
|
| 3874 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 3875 |
+
FROM $catalog_product_entity a
|
| 3876 |
+
JOIN $products_website_temp w
|
| 3877 |
+
ON a.store_product_id = w.store_product_id
|
| 3878 |
+
LEFT JOIN $catalog_category_product b
|
| 3879 |
+
ON a.entity_id = b.product_id
|
| 3880 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 3881 |
+
ON b.category_id = c.entity_id
|
| 3882 |
+
AND c.attribute_id = $cat_attr_name
|
| 3883 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 3884 |
+
ON a.entity_id = e.entity_id
|
| 3885 |
+
AND e.attribute_id = $attr_name
|
| 3886 |
+
LEFT JOIN $products_temp f
|
| 3887 |
+
ON a.entity_id = f.store_product_id
|
| 3888 |
+
)
|
| 3889 |
+
ON DUPLICATE KEY UPDATE
|
| 3890 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
|
| 3891 |
+
|
| 3892 |
+
echo("\n replaceMagentoProductsMultistore 38\n");
|
| 3893 |
+
|
| 3894 |
+
$result = $this->db_do("
|
| 3895 |
+
DELETE cf
|
| 3896 |
+
FROM $catalogsearch_fulltext cf
|
| 3897 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 3898 |
+
ON cf.product_id = cpe.entity_id
|
| 3899 |
+
WHERE cpe.entity_id IS NULL");
|
| 3900 |
+
|
| 3901 |
+
echo("\n replaceMagentoProductsMultistore 39\n");
|
| 3902 |
+
|
| 3903 |
+
$result = $this->db_do("
|
| 3904 |
+
INSERT INTO $catalogsearch_fulltext
|
| 3905 |
+
(product_id, store_id, data_index)
|
| 3906 |
+
(SELECT
|
| 3907 |
+
a.product_id,
|
| 3908 |
+
a.store_id,
|
| 3909 |
+
a.data_index
|
| 3910 |
+
FROM {$catalogsearch_fulltext}_tmp a
|
| 3911 |
+
WHERE product_id = a.product_id
|
| 3912 |
+
)
|
| 3913 |
+
ON DUPLICATE KEY UPDATE
|
| 3914 |
+
data_index = a.data_index");
|
| 3915 |
+
|
| 3916 |
+
echo("\n replaceMagentoProductsMultistore 40\n");
|
| 3917 |
+
|
| 3918 |
+
$this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
|
| 3919 |
+
//INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
|
| 3920 |
+
//TODO add something else
|
| 3921 |
+
|
| 3922 |
+
|
| 3923 |
+
$this->addRelatedProducts();
|
| 3924 |
+
echo("\n replaceMagentoProductsMultistore 41\n");
|
| 3925 |
+
} //
|
| 3926 |
+
################################################################################################################################################################
|
| 3927 |
+
|
| 3928 |
+
|
| 3929 |
+
|
| 3930 |
+
|
| 3931 |
+
|
| 3932 |
+
|
| 3933 |
+
|
| 3934 |
+
|
| 3935 |
+
|
| 3936 |
+
|
| 3937 |
+
|
| 3938 |
+
|
| 3939 |
+
|
| 3940 |
+
|
| 3941 |
+
|
| 3942 |
+
|
| 3943 |
+
|
| 3944 |
+
|
| 3945 |
+
|
| 3946 |
+
|
| 3947 |
+
|
| 3948 |
+
|
| 3949 |
+
|
| 3950 |
+
|
| 3951 |
+
|
| 3952 |
+
|
| 3953 |
+
|
| 3954 |
+
|
| 3955 |
+
|
| 3956 |
+
|
| 3957 |
+
|
| 3958 |
+
|
| 3959 |
+
|
| 3960 |
+
|
| 3961 |
+
|
| 3962 |
+
|
| 3963 |
+
|
| 3964 |
+
|
| 3965 |
+
|
| 3966 |
+
|
| 3967 |
+
|
| 3968 |
+
|
| 3969 |
+
|
| 3970 |
+
|
| 3971 |
+
|
| 3972 |
+
|
| 3973 |
+
|
| 3974 |
+
|
| 3975 |
+
|
| 3976 |
+
|
| 3977 |
+
|
| 3978 |
+
|
| 3979 |
+
|
| 3980 |
+
|
| 3981 |
+
|
| 3982 |
+
|
| 3983 |
+
|
| 3984 |
+
|
| 3985 |
+
|
| 3986 |
+
|
| 3987 |
+
|
| 3988 |
+
|
| 3989 |
+
|
| 3990 |
+
|
| 3991 |
+
|
| 3992 |
+
|
| 3993 |
+
|
| 3994 |
+
|
| 3995 |
+
|
| 3996 |
+
|
| 3997 |
+
|
| 3998 |
+
|
| 3999 |
+
|
| 4000 |
+
|
| 4001 |
+
|
| 4002 |
+
|
| 4003 |
+
|
| 4004 |
+
|
| 4005 |
+
|
| 4006 |
+
|
| 4007 |
+
|
| 4008 |
+
|
| 4009 |
+
|
| 4010 |
+
|
| 4011 |
+
|
| 4012 |
+
|
| 4013 |
+
|
| 4014 |
+
|
| 4015 |
|
| 4016 |
+
################################################################################################################################################################
|
| 4017 |
+
private function truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 4018 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
|
| 4019 |
+
$name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
|
| 4020 |
+
{
|
| 4021 |
+
$this->db_do('SET foreign_key_checks=0');
|
| 4022 |
|
| 4023 |
+
$this->db_do("TRUNCATE $catalog_category_entity");
|
| 4024 |
+
$this->db_do("
|
| 4025 |
+
INSERT $catalog_category_entity
|
| 4026 |
+
(
|
| 4027 |
+
entity_id,
|
| 4028 |
+
entity_type_id,
|
| 4029 |
+
attribute_set_id,
|
| 4030 |
+
parent_id,
|
| 4031 |
+
created_at,
|
| 4032 |
+
updated_at,
|
| 4033 |
+
path,
|
| 4034 |
+
position,
|
| 4035 |
+
level,
|
| 4036 |
+
children_count,
|
| 4037 |
+
store_category_id,
|
| 4038 |
+
parent_store_category_id
|
| 4039 |
+
)
|
| 4040 |
+
VALUES
|
| 4041 |
+
(1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
|
| 4042 |
+
(2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 0, null, null)");
|
| 4043 |
|
| 4044 |
+
$this->db_do("TRUNCATE $catalog_category_entity_varchar");
|
| 4045 |
+
$this->db_do("
|
| 4046 |
+
INSERT $catalog_category_entity_varchar
|
| 4047 |
+
(
|
| 4048 |
+
value_id,
|
| 4049 |
+
entity_type_id,
|
| 4050 |
+
attribute_id,
|
| 4051 |
+
store_id,
|
| 4052 |
+
entity_id,
|
| 4053 |
+
value
|
| 4054 |
+
)
|
| 4055 |
+
VALUES
|
| 4056 |
+
(1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
|
| 4057 |
+
(2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
|
| 4058 |
+
(3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog'),
|
| 4059 |
+
(4, $_categoryEntityTypeId, $name_attrid, 0, 2, 'Default Category'),
|
| 4060 |
+
(5, $_categoryEntityTypeId, $name_attrid, 1, 2, 'Default Category'),
|
| 4061 |
+
(6, $_categoryEntityTypeId, $attr_display_mode, 1, 2, 'PRODUCTS'),
|
| 4062 |
+
(7, $_categoryEntityTypeId, $attr_url_key, 0, 2, 'default-category')");
|
| 4063 |
|
| 4064 |
+
$this->db_do("TRUNCATE $catalog_category_entity_int");
|
| 4065 |
+
$this->db_do("
|
| 4066 |
+
INSERT $catalog_category_entity_int
|
| 4067 |
+
(
|
| 4068 |
+
value_id,
|
| 4069 |
+
entity_type_id,
|
| 4070 |
+
attribute_id,
|
| 4071 |
+
store_id,
|
| 4072 |
+
entity_id,
|
| 4073 |
+
value
|
| 4074 |
+
)
|
| 4075 |
+
VALUES
|
| 4076 |
+
(1, $_categoryEntityTypeId, $attr_is_active, 0, 2, 1),
|
| 4077 |
+
(2, $_categoryEntityTypeId, $attr_is_active, 1, 2, 1),
|
| 4078 |
+
(3, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1),
|
| 4079 |
+
(4, $_categoryEntityTypeId, $attr_include_in_menu, 0, 2, 1)");
|
| 4080 |
|
| 4081 |
+
return $root_cat;
|
| 4082 |
+
} // private function truncateAllCateriesAndRecreateDefaults(...)
|
| 4083 |
+
################################################################################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4084 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4085 |
|
|
|
|
|
|
|
| 4086 |
|
| 4087 |
+
################################################################################################################################################################
|
| 4088 |
+
private function setCategorySettings($categories_temp, $root_cat)
|
| 4089 |
+
{
|
| 4090 |
+
$this->db_do("
|
| 4091 |
+
UPDATE $categories_temp
|
| 4092 |
+
SET parent_store_category_id = $root_cat
|
| 4093 |
+
WHERE parent_store_category_id = 0");
|
| 4094 |
|
| 4095 |
+
$store_cat_ids = $this->db_do("SELECT store_category_id FROM $categories_temp");
|
| 4096 |
+
while ($row = mysql_fetch_array($store_cat_ids))
|
| 4097 |
+
{
|
| 4098 |
+
$store_category_id = $row['store_category_id'];
|
| 4099 |
|
| 4100 |
+
$children_count = $this->count_children($store_category_id);
|
| 4101 |
+
$level = $this->get_category_level($store_category_id);
|
| 4102 |
+
|
| 4103 |
+
$this->db_do("
|
| 4104 |
+
UPDATE $categories_temp
|
| 4105 |
+
SET children_count = $children_count,
|
| 4106 |
+
level = $level
|
| 4107 |
+
WHERE store_category_id = $store_category_id");
|
| 4108 |
+
}
|
| 4109 |
+
} // private function setCategorySettings($categories_temp, $root_cat)
|
| 4110 |
+
################################################################################################################################################################
|
| 4111 |
+
|
| 4112 |
+
|
| 4113 |
+
|
| 4114 |
+
|
| 4115 |
+
|
| 4116 |
+
|
| 4117 |
+
|
| 4118 |
+
################################################################################################################################################################
|
| 4119 |
+
public function mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat)
|
| 4120 |
+
{
|
| 4121 |
+
$stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
|
| 4122 |
+
|
| 4123 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
|
| 4124 |
+
|
| 4125 |
+
$this->db_do("
|
| 4126 |
+
CREATE TABLE $stINch_categories_mapping_temp
|
| 4127 |
+
(
|
| 4128 |
+
shop_entity_id INT(11) UNSIGNED NOT NULL,
|
| 4129 |
+
shop_entity_type_id INT(11),
|
| 4130 |
+
shop_attribute_set_id INT(11),
|
| 4131 |
+
shop_parent_id INT(11),
|
| 4132 |
+
shop_store_category_id INT(11),
|
| 4133 |
+
shop_parent_store_category_id INT(11),
|
| 4134 |
+
store_category_id INT(11),
|
| 4135 |
+
parent_store_category_id INT(11),
|
| 4136 |
+
category_name VARCHAR(255),
|
| 4137 |
+
order_number INT(11),
|
| 4138 |
+
products_within_this_category INT(11),
|
| 4139 |
+
|
| 4140 |
+
KEY shop_entity_id (shop_entity_id),
|
| 4141 |
+
KEY shop_parent_id (shop_parent_id),
|
| 4142 |
+
KEY store_category_id (store_category_id),
|
| 4143 |
+
KEY parent_store_category_id (parent_store_category_id),
|
| 4144 |
+
UNIQUE KEY(shop_entity_id)
|
| 4145 |
+
)");
|
| 4146 |
+
|
| 4147 |
+
$this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
|
| 4148 |
+
|
| 4149 |
+
$this->db_do("
|
| 4150 |
+
INSERT IGNORE INTO $stINch_categories_mapping_temp
|
| 4151 |
+
(
|
| 4152 |
+
shop_entity_id,
|
| 4153 |
+
shop_entity_type_id,
|
| 4154 |
+
shop_attribute_set_id,
|
| 4155 |
+
shop_parent_id,
|
| 4156 |
+
shop_store_category_id,
|
| 4157 |
+
shop_parent_store_category_id
|
| 4158 |
+
)
|
| 4159 |
+
(SELECT
|
| 4160 |
+
entity_id,
|
| 4161 |
+
entity_type_id,
|
| 4162 |
+
attribute_set_id,
|
| 4163 |
+
parent_id,
|
| 4164 |
+
store_category_id,
|
| 4165 |
+
parent_store_category_id
|
| 4166 |
+
FROM $catalog_category_entity)");
|
| 4167 |
+
|
| 4168 |
+
$this->db_do("
|
| 4169 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 4170 |
+
JOIN $categories_temp c
|
| 4171 |
+
ON cmt.shop_store_category_id = c.store_category_id
|
| 4172 |
+
SET
|
| 4173 |
+
cmt.store_category_id = c.store_category_id,
|
| 4174 |
+
cmt.parent_store_category_id = c.parent_store_category_id,
|
| 4175 |
+
cmt.category_name = c.category_name,
|
| 4176 |
+
cmt.order_number = c.order_number,
|
| 4177 |
+
cmt.products_within_this_category = c.products_within_this_category");
|
| 4178 |
+
|
| 4179 |
+
$this->db_do("
|
| 4180 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 4181 |
+
JOIN $catalog_category_entity cce
|
| 4182 |
+
ON cmt.parent_store_category_id = cce.store_category_id
|
| 4183 |
+
SET cmt.shop_parent_id = cce.entity_id");
|
| 4184 |
+
|
| 4185 |
+
$this->db_do("
|
| 4186 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 4187 |
+
JOIN $categories_temp c
|
| 4188 |
+
ON cmt.shop_store_category_id = c.store_category_id
|
| 4189 |
+
SET shop_parent_id = ".$this->_root_cat."
|
| 4190 |
+
WHERE shop_parent_id = 0");
|
| 4191 |
+
// !!!!!!!!!!!!!!!!!!!!!!!!!!! one shop ($this->_root_cat) => milti shop ($root_cat)
|
| 4192 |
+
|
| 4193 |
+
// added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
|
| 4194 |
+
if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE"))
|
| 4195 |
+
{
|
| 4196 |
+
$this->db_do("
|
| 4197 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 4198 |
+
JOIN $catalog_category_entity cce
|
| 4199 |
+
ON cmt.shop_entity_id = cce.entity_id
|
| 4200 |
+
SET cce.parent_id = cmt.shop_parent_id");
|
| 4201 |
+
}
|
| 4202 |
+
else
|
| 4203 |
+
{
|
| 4204 |
+
$this->db_do("
|
| 4205 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 4206 |
+
JOIN $catalog_category_entity cce
|
| 4207 |
+
ON cmt.shop_entity_id = cce.entity_id
|
| 4208 |
+
SET cce.parent_id = cmt.shop_parent_id
|
| 4209 |
+
WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL");
|
| 4210 |
+
}
|
| 4211 |
|
| 4212 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping");
|
| 4213 |
+
$this->db_do("RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping");
|
| 4214 |
+
} //
|
| 4215 |
+
################################################################################################################################################################
|
| 4216 |
+
|
| 4217 |
+
|
| 4218 |
+
|
| 4219 |
+
################################################################################################################################################################
|
| 4220 |
+
private function addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 4221 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat)
|
| 4222 |
+
{
|
| 4223 |
+
if (UPDATE_CATEGORY_DATA)
|
| 4224 |
+
{
|
| 4225 |
+
echo "Update category_entity \n";
|
| 4226 |
+
|
| 4227 |
+
$q = "
|
| 4228 |
+
INSERT INTO $catalog_category_entity
|
| 4229 |
+
(
|
| 4230 |
+
entity_type_id,
|
| 4231 |
+
attribute_set_id,
|
| 4232 |
+
created_at,
|
| 4233 |
+
updated_at,
|
| 4234 |
+
level,
|
| 4235 |
+
children_count,
|
| 4236 |
+
entity_id,
|
| 4237 |
+
position,
|
| 4238 |
+
parent_id,
|
| 4239 |
+
store_category_id,
|
| 4240 |
+
parent_store_category_id
|
| 4241 |
+
)
|
| 4242 |
+
(SELECT
|
| 4243 |
+
$_categoryEntityTypeId,
|
| 4244 |
+
$_categoryDefault_attribute_set_id,
|
| 4245 |
+
now(),
|
| 4246 |
+
now(),
|
| 4247 |
+
c.level,
|
| 4248 |
+
c.children_count,
|
| 4249 |
+
scm.shop_entity_id,
|
| 4250 |
+
c.order_number,
|
| 4251 |
+
scm.shop_parent_id,
|
| 4252 |
+
c.store_category_id,
|
| 4253 |
+
c.parent_store_category_id
|
| 4254 |
+
FROM $categories_temp c
|
| 4255 |
+
LEFT JOIN $stINch_categories_mapping scm
|
| 4256 |
+
ON c.store_category_id = scm.store_category_id
|
| 4257 |
+
)
|
| 4258 |
+
ON DUPLICATE KEY UPDATE
|
| 4259 |
+
updated_at = now(),
|
| 4260 |
+
store_category_id = c.store_category_id,
|
| 4261 |
+
level = c.level,
|
| 4262 |
+
children_count = c.children_count,
|
| 4263 |
+
position = c.order_number,
|
| 4264 |
+
parent_store_category_id = c.parent_store_category_id";
|
| 4265 |
+
//level=c.level,
|
| 4266 |
+
//children_count=c.children_count
|
| 4267 |
+
//position=c.order_number,
|
| 4268 |
+
}
|
| 4269 |
+
else
|
| 4270 |
+
{
|
| 4271 |
+
echo "Insert ignore category_entity \n";
|
| 4272 |
+
|
| 4273 |
+
$q = "
|
| 4274 |
+
INSERT IGNORE INTO $catalog_category_entity
|
| 4275 |
+
(
|
| 4276 |
+
entity_type_id,
|
| 4277 |
+
attribute_set_id,
|
| 4278 |
+
created_at,
|
| 4279 |
+
updated_at,
|
| 4280 |
+
level,
|
| 4281 |
+
children_count,
|
| 4282 |
+
entity_id,
|
| 4283 |
+
position,
|
| 4284 |
+
parent_id,
|
| 4285 |
+
store_category_id,
|
| 4286 |
+
parent_store_category_id
|
| 4287 |
+
)
|
| 4288 |
+
(SELECT
|
| 4289 |
+
$_categoryEntityTypeId,
|
| 4290 |
+
$_categoryDefault_attribute_set_id,
|
| 4291 |
+
now(),
|
| 4292 |
+
now(),
|
| 4293 |
+
c.level,
|
| 4294 |
+
c.children_count,
|
| 4295 |
+
scm.shop_entity_id,
|
| 4296 |
+
c.order_number,
|
| 4297 |
+
scm.shop_parent_id,
|
| 4298 |
+
c.store_category_id,
|
| 4299 |
+
c.parent_store_category_id
|
| 4300 |
+
FROM $categories_temp c
|
| 4301 |
+
LEFT JOIN $stINch_categories_mapping scm
|
| 4302 |
+
ON c.store_category_id = scm.store_category_id
|
| 4303 |
+
)";
|
| 4304 |
+
}
|
| 4305 |
+
$this->db_do($q);
|
| 4306 |
|
| 4307 |
+
$this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4310 |
|
| 4311 |
+
$categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
|
| 4312 |
+
while ($row = mysql_fetch_array($categories))
|
| 4313 |
+
{
|
| 4314 |
+
$parent_id = $row['parent_id'];
|
| 4315 |
+
$entity_id = $row['entity_id'];
|
| 4316 |
|
| 4317 |
+
$path = $this->culc_path($parent_id, $entity_id);
|
| 4318 |
|
| 4319 |
+
//echo("\n$path\n");
|
| 4320 |
|
| 4321 |
+
$this->db_do("
|
| 4322 |
+
UPDATE $catalog_category_entity
|
| 4323 |
+
SET path = '$path'
|
| 4324 |
+
WHERE entity_id = $entity_id");
|
| 4325 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4326 |
|
| 4327 |
+
if(UPDATE_CATEGORY_DATA)
|
| 4328 |
+
{
|
| 4329 |
+
echo "Update category_data \n";
|
| 4330 |
+
|
| 4331 |
+
$q = "
|
| 4332 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 4333 |
+
(
|
| 4334 |
+
entity_type_id,
|
| 4335 |
+
attribute_id,
|
| 4336 |
+
store_id,
|
| 4337 |
+
entity_id,
|
| 4338 |
+
value
|
| 4339 |
+
)
|
| 4340 |
+
(SELECT
|
| 4341 |
+
$_categoryEntityTypeId,
|
| 4342 |
+
$name_attrid,
|
| 4343 |
+
0,
|
| 4344 |
+
scm.shop_entity_id,
|
| 4345 |
+
c.category_name
|
| 4346 |
+
FROM $categories_temp c
|
| 4347 |
+
JOIN $stINch_categories_mapping scm
|
| 4348 |
+
ON c.store_category_id = scm.store_category_id
|
| 4349 |
+
)
|
| 4350 |
+
ON DUPLICATE KEY UPDATE
|
| 4351 |
+
value = c.category_name";
|
| 4352 |
+
$this->db_do($q);
|
| 4353 |
+
|
| 4354 |
+
$q = "
|
| 4355 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 4356 |
+
(
|
| 4357 |
+
entity_type_id,
|
| 4358 |
+
attribute_id,
|
| 4359 |
+
store_id,
|
| 4360 |
+
entity_id,
|
| 4361 |
+
value
|
| 4362 |
+
)
|
| 4363 |
+
(SELECT
|
| 4364 |
+
$_categoryEntityTypeId,
|
| 4365 |
+
$name_attrid,
|
| 4366 |
+
1,
|
| 4367 |
+
scm.shop_entity_id,
|
| 4368 |
+
c.category_name
|
| 4369 |
+
FROM $categories_temp c
|
| 4370 |
+
JOIN $stINch_categories_mapping scm
|
| 4371 |
+
ON c.store_category_id = scm.store_category_id
|
| 4372 |
+
)
|
| 4373 |
+
ON DUPLICATE KEY UPDATE
|
| 4374 |
+
value = c.category_name";
|
| 4375 |
+
$this->db_do($q);
|
| 4376 |
+
|
| 4377 |
+
$q = "
|
| 4378 |
+
INSERT INTO $catalog_category_entity
|
| 4379 |
+
(
|
| 4380 |
+
entity_type_id,
|
| 4381 |
+
attribute_id,
|
| 4382 |
+
store_id,
|
| 4383 |
+
entity_id,
|
| 4384 |
+
value
|
| 4385 |
+
)
|
| 4386 |
+
(SELECT
|
| 4387 |
+
$_categoryEntityTypeId,
|
| 4388 |
+
$attr_is_active,
|
| 4389 |
+
0,
|
| 4390 |
+
scm.shop_entity_id,
|
| 4391 |
+
1
|
| 4392 |
+
FROM $categories_temp c
|
| 4393 |
+
JOIN $stINch_categories_mapping scm
|
| 4394 |
+
ON c.store_category_id = scm.store_category_id
|
| 4395 |
+
)
|
| 4396 |
+
ON DUPLICATE KEY UPDATE
|
| 4397 |
+
value = 1";
|
| 4398 |
+
$this->db_do($q);
|
| 4399 |
+
|
| 4400 |
+
$q = "
|
| 4401 |
+
INSERT INTO $catalog_category_entity_int
|
| 4402 |
+
(
|
| 4403 |
+
entity_type_id,
|
| 4404 |
+
attribute_id,
|
| 4405 |
+
store_id,
|
| 4406 |
+
entity_id,
|
| 4407 |
+
value
|
| 4408 |
+
)
|
| 4409 |
+
(SELECT
|
| 4410 |
+
$_categoryEntityTypeId,
|
| 4411 |
+
$attr_is_active,
|
| 4412 |
+
1,
|
| 4413 |
+
scm.shop_entity_id,
|
| 4414 |
+
1
|
| 4415 |
+
FROM $categories_temp c
|
| 4416 |
+
JOIN $stINch_categories_mapping scm
|
| 4417 |
+
ON c.store_category_id = scm.store_category_id
|
| 4418 |
+
)
|
| 4419 |
+
ON DUPLICATE KEY UPDATE
|
| 4420 |
+
value = 1";
|
| 4421 |
+
$this->db_do($q);
|
| 4422 |
+
|
| 4423 |
+
$q = "
|
| 4424 |
+
INSERT INTO $catalog_category_entity_int
|
| 4425 |
+
(
|
| 4426 |
+
entity_type_id,
|
| 4427 |
+
attribute_id,
|
| 4428 |
+
store_id,
|
| 4429 |
+
entity_id,
|
| 4430 |
+
value
|
| 4431 |
+
)
|
| 4432 |
+
(SELECT
|
| 4433 |
+
$_categoryEntityTypeId,
|
| 4434 |
+
$attr_include_in_menu,
|
| 4435 |
+
0,
|
| 4436 |
+
scm.shop_entity_id,
|
| 4437 |
+
1
|
| 4438 |
+
FROM $categories_temp c
|
| 4439 |
+
JOIN $stINch_categories_mapping scm
|
| 4440 |
+
ON c.store_category_id = scm.store_category_id
|
| 4441 |
+
)
|
| 4442 |
+
ON DUPLICATE KEY UPDATE
|
| 4443 |
+
value = 1";
|
| 4444 |
+
$this->db_do($q);
|
| 4445 |
+
|
| 4446 |
+
$q = "
|
| 4447 |
+
INSERT INTO $catalog_category_entity_int
|
| 4448 |
+
(
|
| 4449 |
+
entity_type_id,
|
| 4450 |
+
attribute_id,
|
| 4451 |
+
store_id,
|
| 4452 |
+
entity_id,
|
| 4453 |
+
value
|
| 4454 |
+
)
|
| 4455 |
+
(SELECT
|
| 4456 |
+
$_categoryEntityTypeId,
|
| 4457 |
+
$is_anchor_attrid,
|
| 4458 |
+
1,
|
| 4459 |
+
scm.shop_entity_id,
|
| 4460 |
+
1
|
| 4461 |
+
FROM $categories_temp c
|
| 4462 |
+
JOIN $stINch_categories_mapping scm
|
| 4463 |
+
ON c.store_category_id = scm.store_category_id
|
| 4464 |
+
)
|
| 4465 |
+
ON DUPLICATE KEY UPDATE
|
| 4466 |
+
value = 1";
|
| 4467 |
+
$this->db_do($q);
|
| 4468 |
+
|
| 4469 |
+
$q = "
|
| 4470 |
+
INSERT INTO $catalog_category_entity_int
|
| 4471 |
+
(
|
| 4472 |
+
entity_type_id,
|
| 4473 |
+
attribute_id,
|
| 4474 |
+
store_id,
|
| 4475 |
+
entity_id,
|
| 4476 |
+
value
|
| 4477 |
+
)
|
| 4478 |
+
(SELECT
|
| 4479 |
+
$_categoryEntityTypeId,
|
| 4480 |
+
$is_anchor_attrid,
|
| 4481 |
+
0,
|
| 4482 |
+
scm.shop_entity_id,
|
| 4483 |
+
1
|
| 4484 |
+
FROM $categories_temp c
|
| 4485 |
+
JOIN $stINch_categories_mapping scm
|
| 4486 |
+
ON c.store_category_id = scm.store_category_id
|
| 4487 |
+
)
|
| 4488 |
+
ON DUPLICATE KEY UPDATE
|
| 4489 |
+
value = 1";
|
| 4490 |
+
$this->db_do($q);
|
| 4491 |
+
|
| 4492 |
+
$q = "
|
| 4493 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 4494 |
+
(
|
| 4495 |
+
entity_type_id,
|
| 4496 |
+
attribute_id,
|
| 4497 |
+
store_id,
|
| 4498 |
+
entity_id,
|
| 4499 |
+
value
|
| 4500 |
+
)
|
| 4501 |
+
(SELECT
|
| 4502 |
+
$_categoryEntityTypeId,
|
| 4503 |
+
$image_attrid,
|
| 4504 |
+
0,
|
| 4505 |
+
scm.shop_entity_id,
|
| 4506 |
+
c.categories_image
|
| 4507 |
+
FROM $categories_temp c
|
| 4508 |
+
JOIN $stINch_categories_mapping scm
|
| 4509 |
+
ON c.store_category_id = scm.store_category_id
|
| 4510 |
+
)
|
| 4511 |
+
ON DUPLICATE KEY UPDATE
|
| 4512 |
+
value = c.categories_image";
|
| 4513 |
+
$this->db_do($q);
|
| 4514 |
+
}
|
| 4515 |
+
else
|
| 4516 |
+
{
|
| 4517 |
+
echo "Insert ignore category_data \n";
|
| 4518 |
+
|
| 4519 |
+
$q = "
|
| 4520 |
+
INSERT IGNORE INTO $catalog_category_entity_varchar
|
| 4521 |
+
(
|
| 4522 |
+
entity_type_id,
|
| 4523 |
+
attribute_id,
|
| 4524 |
+
store_id,
|
| 4525 |
+
entity_id,
|
| 4526 |
+
value
|
| 4527 |
+
)
|
| 4528 |
+
(SELECT
|
| 4529 |
+
$_categoryEntityTypeId,
|
| 4530 |
+
$name_attrid,
|
| 4531 |
+
0,
|
| 4532 |
+
scm.shop_entity_id,
|
| 4533 |
+
c.category_name
|
| 4534 |
+
FROM $categories_temp c
|
| 4535 |
+
JOIN $stINch_categories_mapping scm
|
| 4536 |
+
ON c.store_category_id = scm.store_category_id
|
| 4537 |
+
)";
|
| 4538 |
+
$this->db_do($q);
|
| 4539 |
+
|
| 4540 |
+
$q = "
|
| 4541 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 4542 |
+
(
|
| 4543 |
+
entity_type_id,
|
| 4544 |
+
attribute_id,
|
| 4545 |
+
store_id,
|
| 4546 |
+
entity_id,
|
| 4547 |
+
value
|
| 4548 |
+
)
|
| 4549 |
+
(SELECT
|
| 4550 |
+
$_categoryEntityTypeId,
|
| 4551 |
+
$attr_is_active,
|
| 4552 |
+
0,
|
| 4553 |
+
scm.shop_entity_id,
|
| 4554 |
+
1
|
| 4555 |
+
FROM $categories_temp c
|
| 4556 |
+
JOIN $stINch_categories_mapping scm
|
| 4557 |
+
ON c.store_category_id = scm.store_category_id
|
| 4558 |
+
)";
|
| 4559 |
+
$this->db_do($q);
|
| 4560 |
+
|
| 4561 |
+
$q = "
|
| 4562 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 4563 |
+
(
|
| 4564 |
+
entity_type_id,
|
| 4565 |
+
attribute_id,
|
| 4566 |
+
store_id,
|
| 4567 |
+
entity_id,
|
| 4568 |
+
value
|
| 4569 |
+
)
|
| 4570 |
+
(SELECT
|
| 4571 |
+
$_categoryEntityTypeId,
|
| 4572 |
+
$attr_include_in_menu,
|
| 4573 |
+
0,
|
| 4574 |
+
scm.shop_entity_id,
|
| 4575 |
+
1
|
| 4576 |
+
FROM $categories_temp c
|
| 4577 |
+
JOIN $stINch_categories_mapping scm
|
| 4578 |
+
ON c.store_category_id = scm.store_category_id
|
| 4579 |
+
)";
|
| 4580 |
+
$this->db_do($q);
|
| 4581 |
+
|
| 4582 |
+
$q = "
|
| 4583 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 4584 |
+
(
|
| 4585 |
+
entity_type_id,
|
| 4586 |
+
attribute_id,
|
| 4587 |
+
store_id,
|
| 4588 |
+
entity_id,
|
| 4589 |
+
value
|
| 4590 |
+
)
|
| 4591 |
+
(SELECT
|
| 4592 |
+
$_categoryEntityTypeId,
|
| 4593 |
+
$is_anchor_attrid,
|
| 4594 |
+
0,
|
| 4595 |
+
scm.shop_entity_id,
|
| 4596 |
+
1
|
| 4597 |
+
FROM $categories_temp c
|
| 4598 |
+
JOIN $stINch_categories_mapping scm
|
| 4599 |
+
ON c.store_category_id = scm.store_category_id
|
| 4600 |
+
)";
|
| 4601 |
+
$this->db_do($q);
|
| 4602 |
+
|
| 4603 |
+
$q = "
|
| 4604 |
+
INSERT IGNORE INTO $catalog_category_entity_varchar
|
| 4605 |
+
(
|
| 4606 |
+
entity_type_id,
|
| 4607 |
+
attribute_id,
|
| 4608 |
+
store_id,
|
| 4609 |
+
entity_id,
|
| 4610 |
+
value
|
| 4611 |
+
)
|
| 4612 |
+
(SELECT
|
| 4613 |
+
$_categoryEntityTypeId,
|
| 4614 |
+
$image_attrid,
|
| 4615 |
+
0,
|
| 4616 |
+
scm.shop_entity_id,
|
| 4617 |
+
c.categories_image
|
| 4618 |
+
FROM $categories_temp c
|
| 4619 |
+
JOIN $stINch_categories_mapping scm
|
| 4620 |
+
ON c.store_category_id = scm.store_category_id
|
| 4621 |
+
)";
|
| 4622 |
+
$this->db_do($q);
|
| 4623 |
+
}
|
| 4624 |
+
|
| 4625 |
+
$this->delete_old_sinch_categories_from_shop();
|
| 4626 |
+
|
| 4627 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories");
|
| 4628 |
+
$this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
|
| 4629 |
+
} // private function addCategoryData(...)
|
| 4630 |
+
################################################################################################################################################################
|
| 4631 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4632 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
|
|
|
|
|
|
|
| 4640 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4641 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4642 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4643 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4644 |
|
|
|
|
|
|
|
| 4645 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4646 |
|
|
|
|
| 4647 |
|
| 4648 |
function ParseCategoryFeatures(){
|
| 4649 |
|
| 4882 |
|
| 4883 |
#################################################################################################
|
| 4884 |
|
| 4885 |
+
function ParseProducts($coincidence){
|
| 4886 |
+
echo("\nParseProducts 2\n");
|
| 4887 |
$parse_file=$this->varDir.FILE_PRODUCTS;
|
| 4888 |
if(filesize($parse_file)){
|
| 4889 |
$this->_LOG("Start parse ".FILE_PRODUCTS);
|
| 4898 |
}
|
| 4899 |
fclose($file_handle_from);
|
| 4900 |
fclose($file_handle_to);
|
| 4901 |
+
echo("\nParseProducts 2\n");
|
| 4902 |
|
| 4903 |
// $prod_file_str = file_get_contents($parse_file);
|
| 4904 |
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
|
| 4934 |
KEY(store_category_id)
|
| 4935 |
)DEFAULT CHARSET=utf8
|
| 4936 |
");
|
| 4937 |
+
echo("\nParseProducts 3\n");
|
| 4938 |
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv'
|
| 4939 |
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 4940 |
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 4941 |
OPTIONALLY ENCLOSED BY '\"'
|
| 4942 |
LINES TERMINATED BY \"\r\n\"
|
| 4943 |
IGNORE 1 LINES ");
|
| 4944 |
+
echo("\nParseProducts 4\n");
|
| 4945 |
+
|
| 4946 |
+
|
| 4947 |
+
//$this->db_do("DELETE FROM stINch_products WHERE sinch_product_id IN (4936140, 4326529)");
|
| 4948 |
+
|
| 4949 |
+
//echo("\n\n clear parse products....\n\n"); //exit;
|
| 4950 |
+
|
| 4951 |
+
|
| 4952 |
|
| 4953 |
$this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 4954 |
CONVERT TO CHARACTER SET \"latin1\"");
|
| 4955 |
+
echo("\nParseProducts 5\n");
|
| 4956 |
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 4957 |
SET products_date_added=now(), products_last_modified=now()");
|
| 4958 |
+
echo("\nParseProducts 6\n");
|
| 4959 |
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 4960 |
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." m
|
| 4961 |
ON p.sinch_manufacturer_id=m.sinch_manufacturer_id
|
| 4962 |
SET p.manufacturer_name=m.manufacturer_name");
|
| 4963 |
+
echo("\nParseProducts 7\n");
|
| 4964 |
if($this->current_import_status_statistic_id){
|
| 4965 |
$res = $this->db_do("SELECT COUNT(*) AS cnt
|
| 4966 |
FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
|
| 4969 |
SET number_of_products=".$row['cnt']."
|
| 4970 |
WHERE id=".$this->current_import_status_statistic_id);
|
| 4971 |
}
|
| 4972 |
+
echo("\nParseProducts 8\n");
|
| 4973 |
$this->addProductsWebsite();
|
| 4974 |
$this->mapSinchProducts();
|
| 4975 |
+
echo("\nParseProducts 9\n");
|
| 4976 |
+
|
| 4977 |
+
|
| 4978 |
+
|
| 4979 |
+
if (count($coincidence) == 1)
|
| 4980 |
+
{
|
| 4981 |
+
$this->replaceMagentoProducts();
|
| 4982 |
+
}
|
| 4983 |
+
else
|
| 4984 |
+
{
|
| 4985 |
+
echo("\n\n\n\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ [".$this->im_type."] $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n\n\n"); //exit;
|
| 4986 |
+
|
| 4987 |
+
|
| 4988 |
+
switch ($this->im_type)
|
| 4989 |
+
{
|
| 4990 |
+
case "REWRITE": $this->replaceMagentoProductsMultistore($coincidence); break;
|
| 4991 |
+
case "MERGE": $this->replaceMagentoProductsMultistoreMERGE($coincidence); break;
|
| 4992 |
+
}
|
| 4993 |
+
}
|
| 4994 |
+
echo("\nParseProducts 10\n");
|
| 4995 |
+
|
| 4996 |
+
|
| 4997 |
$this->mapSinchProducts();
|
| 4998 |
$this->addManufacturer_attribute();
|
| 4999 |
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
|
| 5004 |
$this->_LOG("Wrong file ".$parse_file);
|
| 5005 |
}
|
| 5006 |
$this->_LOG(" ");
|
| 5007 |
+
echo("\nParseProducts 11\n");
|
| 5008 |
}
|
| 5009 |
|
| 5010 |
#################################################################################################
|
| 5186 |
|
| 5187 |
}
|
| 5188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5190 |
|
| 5191 |
#################################################################################################
|
| 5192 |
public function mapSinchProducts(){
|
| 5418 |
ON ccp.product_id=cpe.entity_id
|
| 5419 |
WHERE cpe.entity_id IS NULL");
|
| 5420 |
|
| 5421 |
+
echo("\n\n\nUPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 5422 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 5423 |
+
ON ccp.category_id=cce.entity_id
|
| 5424 |
+
SET ccp.category_id=".$this->_root_cat."
|
| 5425 |
+
WHERE cce.entity_id IS NULL");
|
| 5426 |
$result = $this->db_do("UPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 5427 |
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 5428 |
ON ccp.category_id=cce.entity_id
|
| 5429 |
SET ccp.category_id=".$this->_root_cat."
|
| 5430 |
WHERE cce.entity_id IS NULL");
|
| 5431 |
+
echo("\ndone\n");
|
| 5432 |
|
| 5433 |
+
|
| 5434 |
+
echo("\n\n\nDELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 5435 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 5436 |
+
ON ccp.category_id=cce.entity_id
|
| 5437 |
+
WHERE cce.entity_id IS NULL");
|
| 5438 |
$result = $this->db_do("DELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 5439 |
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 5440 |
ON ccp.category_id=cce.entity_id
|
| 5441 |
WHERE cce.entity_id IS NULL");
|
| 5442 |
+
echo("\ndone\n");
|
| 5443 |
|
| 5444 |
|
| 5445 |
$this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp");
|
| 5949 |
)(
|
| 5950 |
SELECT
|
| 5951 |
a.entity_id,
|
| 5952 |
+
w.website,
|
| 5953 |
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 5954 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5955 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5979 |
)(
|
| 5980 |
SELECT
|
| 5981 |
a.entity_id,
|
| 5982 |
+
w.website,
|
| 5983 |
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 5984 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5985 |
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 6628 |
SELECT
|
| 6629 |
" . $this->_getProductEntityTypeId(). ",
|
| 6630 |
" . $this->_getProductAttributeId('price'). ",
|
| 6631 |
+
w.website,
|
| 6632 |
a.entity_id,
|
| 6633 |
b.price
|
| 6634 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 6675 |
SELECT
|
| 6676 |
" . $this->_getProductEntityTypeId(). ",
|
| 6677 |
" . $this->_getProductAttributeId('cost'). ",
|
| 6678 |
+
w.website,
|
| 6679 |
a.entity_id,
|
| 6680 |
b.cost
|
| 6681 |
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 7142 |
}
|
| 7143 |
// $result = $this->this->db_do($query);//
|
| 7144 |
// $query=mysql_real_escape_string($query);
|
| 7145 |
+
//mysql_query('set names utf8');
|
| 7146 |
$result = mysql_query($query) or die("Query failed: " . mysql_error());
|
| 7147 |
if (!$result) {
|
| 7148 |
throw new Exception("Invalid query: $sql\n" . mysql_error());
|
| 7382 |
#################################################################################################
|
| 7383 |
|
| 7384 |
function culc_path($parent_id, $ent_id){
|
| 7385 |
+
|
| 7386 |
+
//echo("\nparent_id = [$parent_id] ent_id = [$ent_id]\n");
|
| 7387 |
+
|
| 7388 |
$path='';
|
| 7389 |
$cat_id=$parent_id;
|
| 7390 |
$q="SELECT
|
| 7490 |
$res="SELECT COUNT(*) FROM ".$this->import_status_statistic_table;
|
| 7491 |
$cnt_arr=mysql_fetch_array($this->db_do($res));
|
| 7492 |
$cnt=$cnt_arr[0];
|
| 7493 |
+
$StatusHistory_arr = array();
|
| 7494 |
if($cnt>0){
|
| 7495 |
$a=(($cnt>7)? ($cnt-7): 0);
|
| 7496 |
$b=$cnt;
|
| 7963 |
|
| 7964 |
$errmsg = '';
|
| 7965 |
$fixmsg = '';
|
| 7966 |
+
if ($value < $CheckValue) {
|
| 7967 |
$errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
|
| 7968 |
$fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
|
| 7969 |
$status = 'error';
|
| 8003 |
$retvalue["'$check_code'"] = array();
|
| 8004 |
|
| 8005 |
$value = trim(PHP_RUN_STRING);
|
|
|
|
| 8006 |
$errmsg = '';
|
| 8007 |
$fixmsg = '';
|
| 8008 |
+
if( !defined('PHP_RUN_STRING')){
|
| 8009 |
+
$errmsg .= "You haven't installed PHP CLI";
|
| 8010 |
+
$fixmsg .= "Install PHP CLI."; // ." ".$CheckValue." ".$CheckMeasure
|
| 8011 |
+
$status = 'error';
|
| 8012 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8013 |
|
| 8014 |
$ret = array();
|
| 8015 |
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 8203 |
$retvalue["'$check_code'"] = array();
|
| 8204 |
|
| 8205 |
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 8206 |
+
$storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
|
| 8207 |
$result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
|
| 8208 |
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 8209 |
$value = $row['Name'];
|
app/code/local/Bintime/Sinchimport/Model/Sinch_new_code.php
ADDED
|
@@ -0,0 +1,7176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = mysql_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=mysql_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=mysql_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=mysql_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=mysql_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=mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_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 = mysql_fetch_array($quer);
|
| 2102 |
+
}
|
| 2103 |
+
|
| 2104 |
+
if ($cat_id) $path.=$cat_id."/";
|
| 2105 |
+
|
| 2106 |
+
if ($path) $path .= $ent_id;
|
| 2107 |
+
else $path = $ent_id;
|
| 2108 |
+
|
| 2109 |
+
//echo(" path = [$path]\n");
|
| 2110 |
+
|
| 2111 |
+
return $path;
|
| 2112 |
+
} // function culcPathMultistore($parent_id, $ent_id, $catalog_category_entity)
|
| 2113 |
+
################################################################################################################################################################
|
| 2114 |
+
|
| 2115 |
+
|
| 2116 |
+
|
| 2117 |
+
################################################################################################################################################################
|
| 2118 |
+
public function replaceMagentoProductsMultistore($coincidence)
|
| 2119 |
+
{
|
| 2120 |
+
|
| 2121 |
+
echo("\n replaceMagentoProductsMultistore 1\n");
|
| 2122 |
+
|
| 2123 |
+
$connection = Mage::getModel('core/resource')->getConnection('core_write');
|
| 2124 |
+
|
| 2125 |
+
|
| 2126 |
+
$products_temp = Mage::getSingleton('core/resource')->getTableName('products_temp');
|
| 2127 |
+
$products_website_temp = Mage::getSingleton('core/resource')->getTableName('products_website_temp');
|
| 2128 |
+
$catalog_product_entity = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
|
| 2129 |
+
$catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
|
| 2130 |
+
$catalog_product_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
|
| 2131 |
+
$catalog_category_product = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
|
| 2132 |
+
$stINch_products_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping');
|
| 2133 |
+
$catalog_category_entity = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity');
|
| 2134 |
+
$stINch_categories_mapping = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping');
|
| 2135 |
+
$catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index');
|
| 2136 |
+
$core_store = Mage::getSingleton('core/resource')->getTableName('core_store');
|
| 2137 |
+
$catalog_product_enabled_index = Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index');
|
| 2138 |
+
$catalog_product_website = Mage::getSingleton('core/resource')->getTableName('catalog_product_website');
|
| 2139 |
+
$catalogsearch_fulltext = Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext');
|
| 2140 |
+
$catalogsearch_query = Mage::getSingleton('core/resource')->getTableName('catalogsearch_query');
|
| 2141 |
+
$catalog_category_entity_varchar = Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar');
|
| 2142 |
+
|
| 2143 |
+
$_getProductEntityTypeId = $this->_getProductEntityTypeId();
|
| 2144 |
+
$_defaultAttributeSetId = $this->_getProductDefaulAttributeSetId();
|
| 2145 |
+
|
| 2146 |
+
$attr_atatus = $this->_getProductAttributeId('status');
|
| 2147 |
+
$attr_name = $this->_getProductAttributeId('name');
|
| 2148 |
+
$attr_visibility = $this->_getProductAttributeId('visibility');
|
| 2149 |
+
$attr_tax_class_id = $this->_getProductAttributeId('tax_class_id');
|
| 2150 |
+
$attr_image = $this->_getProductAttributeId('image');
|
| 2151 |
+
$attr_small_image = $this->_getProductAttributeId('small_image');
|
| 2152 |
+
$attr_thumbnail = $this->_getProductAttributeId('thumbnail');
|
| 2153 |
+
|
| 2154 |
+
$cat_attr_name = $this->_getCategoryAttributeId('name');
|
| 2155 |
+
echo("\n replaceMagentoProductsMultistore 2\n");
|
| 2156 |
+
|
| 2157 |
+
//clear products, inserting new products and updating old others.
|
| 2158 |
+
$result = $this->db_do("
|
| 2159 |
+
DELETE cpe
|
| 2160 |
+
FROM $catalog_product_entity cpe
|
| 2161 |
+
JOIN $stINch_products_mapping pm
|
| 2162 |
+
ON cpe.entity_id = pm.entity_id
|
| 2163 |
+
WHERE pm.shop_store_product_id IS NOT NULL
|
| 2164 |
+
AND pm.store_product_id IS NULL");
|
| 2165 |
+
|
| 2166 |
+
|
| 2167 |
+
|
| 2168 |
+
echo("\n replaceMagentoProductsMultistore 3\n");
|
| 2169 |
+
|
| 2170 |
+
$result = $this->db_do("
|
| 2171 |
+
INSERT INTO $catalog_product_entity
|
| 2172 |
+
(entity_id, entity_type_id, attribute_set_id, type_id, sku, updated_at, has_options, store_product_id, sinch_product_id)
|
| 2173 |
+
(SELECT
|
| 2174 |
+
pm.entity_id,
|
| 2175 |
+
$_getProductEntityTypeId,
|
| 2176 |
+
$_defaultAttributeSetId,
|
| 2177 |
+
'simple',
|
| 2178 |
+
a.product_sku,
|
| 2179 |
+
NOW(),
|
| 2180 |
+
0,
|
| 2181 |
+
a.store_product_id,
|
| 2182 |
+
a.sinch_product_id
|
| 2183 |
+
FROM $products_temp a
|
| 2184 |
+
LEFT JOIN $stINch_products_mapping pm
|
| 2185 |
+
ON a.store_product_id = pm.store_product_id
|
| 2186 |
+
AND a.sinch_product_id = pm.sinch_product_id
|
| 2187 |
+
)
|
| 2188 |
+
ON DUPLICATE KEY UPDATE
|
| 2189 |
+
sku = a.product_sku,
|
| 2190 |
+
store_product_id = a.store_product_id,
|
| 2191 |
+
sinch_product_id = a.sinch_product_id");
|
| 2192 |
+
// store_product_id = a.store_product_id,
|
| 2193 |
+
// sinch_product_id = a.sinch_product_id
|
| 2194 |
+
|
| 2195 |
+
echo("\n replaceMagentoProductsMultistore 4\n");
|
| 2196 |
+
|
| 2197 |
+
|
| 2198 |
+
//Set enabled
|
| 2199 |
+
$result = $this->db_do("
|
| 2200 |
+
DELETE cpei
|
| 2201 |
+
FROM $catalog_product_entity_int cpei
|
| 2202 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2203 |
+
ON cpei.entity_id = cpe.entity_id
|
| 2204 |
+
WHERE cpe.entity_id IS NULL");
|
| 2205 |
+
|
| 2206 |
+
$result = $this->db_do("
|
| 2207 |
+
INSERT INTO $catalog_product_entity_int
|
| 2208 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2209 |
+
(SELECT
|
| 2210 |
+
$_getProductEntityTypeId,
|
| 2211 |
+
$attr_atatus,
|
| 2212 |
+
w.website,
|
| 2213 |
+
a.entity_id,
|
| 2214 |
+
1
|
| 2215 |
+
FROM $catalog_product_entity a
|
| 2216 |
+
JOIN $products_website_temp w
|
| 2217 |
+
ON a.store_product_id = w.store_product_id
|
| 2218 |
+
)
|
| 2219 |
+
ON DUPLICATE KEY UPDATE
|
| 2220 |
+
value = 1");
|
| 2221 |
+
|
| 2222 |
+
//___ return.
|
| 2223 |
+
|
| 2224 |
+
echo("\n replaceMagentoProductsMultistore 5\n");
|
| 2225 |
+
|
| 2226 |
+
|
| 2227 |
+
// set status = 1 for all stores
|
| 2228 |
+
$result = $this->db_do("
|
| 2229 |
+
INSERT INTO $catalog_product_entity_int
|
| 2230 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2231 |
+
(SELECT
|
| 2232 |
+
$_getProductEntityTypeId,
|
| 2233 |
+
$attr_atatus,
|
| 2234 |
+
0,
|
| 2235 |
+
a.entity_id,
|
| 2236 |
+
1
|
| 2237 |
+
FROM $catalog_product_entity a
|
| 2238 |
+
)
|
| 2239 |
+
ON DUPLICATE KEY UPDATE
|
| 2240 |
+
value = 1");
|
| 2241 |
+
|
| 2242 |
+
echo("\n replaceMagentoProductsMultistore 6\n");
|
| 2243 |
+
|
| 2244 |
+
|
| 2245 |
+
//Unifying products with categories.
|
| 2246 |
+
$result = $this->db_do("
|
| 2247 |
+
DELETE ccp
|
| 2248 |
+
FROM $catalog_category_product ccp
|
| 2249 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2250 |
+
ON ccp.product_id = cpe.entity_id
|
| 2251 |
+
WHERE cpe.entity_id IS NULL");
|
| 2252 |
+
|
| 2253 |
+
|
| 2254 |
+
echo("\n replaceMagentoProductsMultistore 7\n");
|
| 2255 |
+
|
| 2256 |
+
|
| 2257 |
+
$result = $this->db_do("DROP TABLE IF EXISTS root_cats");
|
| 2258 |
+
$result = $this->db_do("
|
| 2259 |
+
CREATE TABLE root_cats
|
| 2260 |
+
SELECT
|
| 2261 |
+
entity_id,
|
| 2262 |
+
path,
|
| 2263 |
+
SUBSTRING(path, LOCATE('/', path)+1) AS short_path,
|
| 2264 |
+
LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1)) AS end_pos,
|
| 2265 |
+
SUBSTRING(SUBSTRING(path, LOCATE('/', path)+1), 1, LOCATE('/', SUBSTRING(path, LOCATE('/', path)+1))-1) as root_cat
|
| 2266 |
+
FROM catalog_category_entity
|
| 2267 |
+
");
|
| 2268 |
+
$result = $this->db_do("UPDATE root_cats SET root_cat = entity_id WHERE CHAR_LENGTH(root_cat) = 0");
|
| 2269 |
+
|
| 2270 |
+
|
| 2271 |
+
echo("\n replaceMagentoProductsMultistore 8\n");
|
| 2272 |
+
|
| 2273 |
+
|
| 2274 |
+
// !!! $this->_root_cat
|
| 2275 |
+
$result = $this->db_do("
|
| 2276 |
+
UPDATE IGNORE $catalog_category_product ccp
|
| 2277 |
+
LEFT JOIN $catalog_category_entity cce
|
| 2278 |
+
ON ccp.category_id = cce.entity_id
|
| 2279 |
+
JOIN root_cats rc
|
| 2280 |
+
ON cce.entity_id = rc.entity_id
|
| 2281 |
+
SET ccp.category_id = rc.root_cat
|
| 2282 |
+
WHERE cce.entity_id IS NULL");
|
| 2283 |
+
|
| 2284 |
+
|
| 2285 |
+
|
| 2286 |
+
echo("\n replaceMagentoProductsMultistore 9\n");
|
| 2287 |
+
|
| 2288 |
+
|
| 2289 |
+
|
| 2290 |
+
|
| 2291 |
+
$result = $this->db_do("
|
| 2292 |
+
DELETE ccp
|
| 2293 |
+
FROM $catalog_category_product ccp
|
| 2294 |
+
LEFT JOIN $catalog_category_entity cce
|
| 2295 |
+
ON ccp.category_id = cce.entity_id
|
| 2296 |
+
WHERE cce.entity_id IS NULL");
|
| 2297 |
+
|
| 2298 |
+
|
| 2299 |
+
echo("\n replaceMagentoProductsMultistore 10\n");
|
| 2300 |
+
|
| 2301 |
+
|
| 2302 |
+
|
| 2303 |
+
// TEMPORARY
|
| 2304 |
+
$this->db_do(" DROP TABLE IF EXISTS {$catalog_category_product}_for_delete_temp");
|
| 2305 |
+
$this->db_do("
|
| 2306 |
+
CREATE TABLE `{$catalog_category_product}_for_delete_temp`
|
| 2307 |
+
(
|
| 2308 |
+
`category_id` int(10) unsigned NOT NULL default '0',
|
| 2309 |
+
`product_id` int(10) unsigned NOT NULL default '0',
|
| 2310 |
+
`store_product_id` int(10) NOT NULL default '0',
|
| 2311 |
+
`store_category_id` int(10) NOT NULL default '0',
|
| 2312 |
+
`new_category_id` int(10) NOT NULL default '0',
|
| 2313 |
+
|
| 2314 |
+
UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
|
| 2315 |
+
KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
|
| 2316 |
+
KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
|
| 2317 |
+
KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
|
| 2318 |
+
)");
|
| 2319 |
+
|
| 2320 |
+
echo("\n replaceMagentoProductsMultistore 11\n");
|
| 2321 |
+
|
| 2322 |
+
$result = $this->db_do("
|
| 2323 |
+
INSERT INTO {$catalog_category_product}_for_delete_temp
|
| 2324 |
+
(category_id, product_id, store_product_id)
|
| 2325 |
+
(SELECT
|
| 2326 |
+
ccp.category_id,
|
| 2327 |
+
ccp.product_id,
|
| 2328 |
+
cpe.store_product_id
|
| 2329 |
+
FROM $catalog_category_product ccp
|
| 2330 |
+
JOIN $catalog_product_entity cpe
|
| 2331 |
+
ON ccp.product_id = cpe.entity_id
|
| 2332 |
+
WHERE store_product_id IS NOT NULL)");
|
| 2333 |
+
|
| 2334 |
+
echo("\n replaceMagentoProductsMultistore 12\n");
|
| 2335 |
+
|
| 2336 |
+
$result = $this->db_do("
|
| 2337 |
+
UPDATE {$catalog_category_product}_for_delete_temp ccpfd
|
| 2338 |
+
JOIN $products_temp p
|
| 2339 |
+
ON ccpfd.store_product_id = p.store_product_id
|
| 2340 |
+
SET ccpfd.store_category_id = p.store_category_id
|
| 2341 |
+
WHERE ccpfd.store_product_id != 0");
|
| 2342 |
+
|
| 2343 |
+
echo("\n replaceMagentoProductsMultistore 13\n");
|
| 2344 |
+
|
| 2345 |
+
$result = $this->db_do("
|
| 2346 |
+
UPDATE {$catalog_category_product}_for_delete_temp ccpfd
|
| 2347 |
+
JOIN $stINch_categories_mapping scm
|
| 2348 |
+
ON ccpfd.store_category_id = scm.store_category_id
|
| 2349 |
+
SET ccpfd.new_category_id = scm.shop_entity_id
|
| 2350 |
+
WHERE ccpfd.store_category_id != 0");
|
| 2351 |
+
|
| 2352 |
+
echo("\n replaceMagentoProductsMultistore 14\n");
|
| 2353 |
+
|
| 2354 |
+
$result = $this->db_do("DELETE FROM {$catalog_category_product}_for_delete_temp WHERE category_id = new_category_id");
|
| 2355 |
+
|
| 2356 |
+
$result = $this->db_do("
|
| 2357 |
+
DELETE ccp
|
| 2358 |
+
FROM $catalog_category_product ccp
|
| 2359 |
+
JOIN {$catalog_category_product}_for_delete_temp ccpfd
|
| 2360 |
+
ON ccp.product_id = ccpfd.product_id
|
| 2361 |
+
AND ccp.category_id = ccpfd.category_id");
|
| 2362 |
+
|
| 2363 |
+
echo("\n replaceMagentoProductsMultistore 15\n");
|
| 2364 |
+
|
| 2365 |
+
$result = $this->db_do("
|
| 2366 |
+
INSERT INTO $catalog_category_product
|
| 2367 |
+
(category_id, product_id)
|
| 2368 |
+
(SELECT
|
| 2369 |
+
scm.shop_entity_id,
|
| 2370 |
+
cpe.entity_id
|
| 2371 |
+
FROM $catalog_product_entity cpe
|
| 2372 |
+
JOIN $products_temp p
|
| 2373 |
+
ON cpe.store_product_id = p.store_product_id
|
| 2374 |
+
JOIN $stINch_categories_mapping scm
|
| 2375 |
+
ON p.store_category_id = scm.store_category_id
|
| 2376 |
+
)
|
| 2377 |
+
ON DUPLICATE KEY UPDATE
|
| 2378 |
+
product_id = cpe.entity_id");
|
| 2379 |
+
|
| 2380 |
+
echo("\n replaceMagentoProductsMultistore 16\n");
|
| 2381 |
+
|
| 2382 |
+
//Indexing products and categories in the shop
|
| 2383 |
+
$result = $this->db_do("
|
| 2384 |
+
DELETE ccpi
|
| 2385 |
+
FROM $catalog_category_product_index ccpi
|
| 2386 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2387 |
+
ON ccpi.product_id = cpe.entity_id
|
| 2388 |
+
WHERE cpe.entity_id IS NULL");
|
| 2389 |
+
|
| 2390 |
+
|
| 2391 |
+
|
| 2392 |
+
echo("\n replaceMagentoProductsMultistore 16.2\n");
|
| 2393 |
+
|
| 2394 |
+
|
| 2395 |
+
$result = $this->db_do("
|
| 2396 |
+
INSERT INTO $catalog_category_product_index
|
| 2397 |
+
(category_id, product_id, position, is_parent, store_id, visibility)
|
| 2398 |
+
(SELECT
|
| 2399 |
+
a.category_id,
|
| 2400 |
+
a.product_id,
|
| 2401 |
+
a.position,
|
| 2402 |
+
1,
|
| 2403 |
+
b.store_id,
|
| 2404 |
+
4
|
| 2405 |
+
FROM $catalog_category_product a
|
| 2406 |
+
JOIN $core_store b
|
| 2407 |
+
)
|
| 2408 |
+
ON DUPLICATE KEY UPDATE
|
| 2409 |
+
visibility = 4");
|
| 2410 |
+
|
| 2411 |
+
echo("\n replaceMagentoProductsMultistore 17\n");
|
| 2412 |
+
|
| 2413 |
+
// !!! $this->_root_cat
|
| 2414 |
+
$result = $this->db_do("
|
| 2415 |
+
INSERT ignore INTO $catalog_category_product_index
|
| 2416 |
+
(category_id, product_id, position, is_parent, store_id, visibility)
|
| 2417 |
+
(SELECT
|
| 2418 |
+
rc.root_cat,
|
| 2419 |
+
a.product_id,
|
| 2420 |
+
a.position,
|
| 2421 |
+
1,
|
| 2422 |
+
b.store_id,
|
| 2423 |
+
4
|
| 2424 |
+
FROM $catalog_category_product a
|
| 2425 |
+
JOIN root_cats rc
|
| 2426 |
+
ON a.category_id = rc.entity_id
|
| 2427 |
+
JOIN $core_store b
|
| 2428 |
+
)
|
| 2429 |
+
ON DUPLICATE KEY UPDATE
|
| 2430 |
+
visibility = 4");
|
| 2431 |
+
|
| 2432 |
+
echo("\n replaceMagentoProductsMultistore 18\n");
|
| 2433 |
+
|
| 2434 |
+
|
| 2435 |
+
//Set product name for specific web sites
|
| 2436 |
+
$result = $this->db_do("
|
| 2437 |
+
DELETE cpev
|
| 2438 |
+
FROM $catalog_product_entity_varchar cpev
|
| 2439 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2440 |
+
ON cpev.entity_id = cpe.entity_id
|
| 2441 |
+
WHERE cpe.entity_id IS NULL");
|
| 2442 |
+
|
| 2443 |
+
$result = $this->db_do("
|
| 2444 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2445 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2446 |
+
(SELECT
|
| 2447 |
+
$_getProductEntityTypeId,
|
| 2448 |
+
$attr_name,
|
| 2449 |
+
w.website,
|
| 2450 |
+
a.entity_id,
|
| 2451 |
+
b.product_name
|
| 2452 |
+
FROM $catalog_product_entity a
|
| 2453 |
+
JOIN $products_temp b
|
| 2454 |
+
ON a.store_product_id = b.store_product_id
|
| 2455 |
+
JOIN $products_website_temp w
|
| 2456 |
+
ON a.store_product_id = w.store_product_id
|
| 2457 |
+
)
|
| 2458 |
+
ON DUPLICATE KEY UPDATE
|
| 2459 |
+
value = b.product_name");
|
| 2460 |
+
|
| 2461 |
+
echo("\n replaceMagentoProductsMultistore 19\n");
|
| 2462 |
+
|
| 2463 |
+
|
| 2464 |
+
// product name for all web sites
|
| 2465 |
+
$result = $this->db_do("
|
| 2466 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2467 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2468 |
+
(SELECT
|
| 2469 |
+
$_getProductEntityTypeId,
|
| 2470 |
+
$attr_name,
|
| 2471 |
+
0,
|
| 2472 |
+
a.entity_id,
|
| 2473 |
+
b.product_name
|
| 2474 |
+
FROM $catalog_product_entity a
|
| 2475 |
+
JOIN $products_temp b
|
| 2476 |
+
ON a.store_product_id = b.store_product_id
|
| 2477 |
+
)
|
| 2478 |
+
ON DUPLICATE KEY UPDATE
|
| 2479 |
+
value = b.product_name");
|
| 2480 |
+
|
| 2481 |
+
echo("\n replaceMagentoProductsMultistore 20\n");
|
| 2482 |
+
|
| 2483 |
+
$this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
|
| 2484 |
+
$this->addDescriptions();
|
| 2485 |
+
$this->addShortDescriptions();
|
| 2486 |
+
$this->addEAN();
|
| 2487 |
+
$this->addSpecification();
|
| 2488 |
+
$this->addManufacturers();
|
| 2489 |
+
|
| 2490 |
+
echo("\n replaceMagentoProductsMultistore 21\n");
|
| 2491 |
+
|
| 2492 |
+
//Enabling product index.
|
| 2493 |
+
$result = $this->db_do("
|
| 2494 |
+
DELETE cpei
|
| 2495 |
+
FROM $catalog_product_enabled_index cpei
|
| 2496 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2497 |
+
ON cpei.product_id = cpe.entity_id
|
| 2498 |
+
WHERE cpe.entity_id IS NULL");
|
| 2499 |
+
|
| 2500 |
+
echo("\n replaceMagentoProductsMultistore 22\n");
|
| 2501 |
+
|
| 2502 |
+
$result = $this->db_do("
|
| 2503 |
+
INSERT INTO $catalog_product_enabled_index
|
| 2504 |
+
(product_id, store_id, visibility)
|
| 2505 |
+
(SELECT
|
| 2506 |
+
a.entity_id,
|
| 2507 |
+
w.website,
|
| 2508 |
+
4
|
| 2509 |
+
FROM $catalog_product_entity a
|
| 2510 |
+
JOIN $products_website_temp w
|
| 2511 |
+
ON a.store_product_id = w.store_product_id
|
| 2512 |
+
)
|
| 2513 |
+
ON DUPLICATE KEY UPDATE
|
| 2514 |
+
visibility = 4");
|
| 2515 |
+
|
| 2516 |
+
echo("\n replaceMagentoProductsMultistore 23\n");
|
| 2517 |
+
|
| 2518 |
+
$result = $this->db_do("
|
| 2519 |
+
INSERT INTO $catalog_product_enabled_index
|
| 2520 |
+
(product_id, store_id, visibility)
|
| 2521 |
+
(SELECT
|
| 2522 |
+
a.entity_id,
|
| 2523 |
+
0,
|
| 2524 |
+
4
|
| 2525 |
+
FROM $catalog_product_entity a
|
| 2526 |
+
JOIN $products_website_temp w
|
| 2527 |
+
ON a.store_product_id = w.store_product_id
|
| 2528 |
+
)
|
| 2529 |
+
ON DUPLICATE KEY UPDATE
|
| 2530 |
+
visibility = 4");
|
| 2531 |
+
|
| 2532 |
+
echo("\n replaceMagentoProductsMultistore 24\n");
|
| 2533 |
+
|
| 2534 |
+
$result = $this->db_do("
|
| 2535 |
+
INSERT INTO $catalog_product_entity_int
|
| 2536 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2537 |
+
(SELECT
|
| 2538 |
+
$_getProductEntityTypeId,
|
| 2539 |
+
$attr_visibility,
|
| 2540 |
+
w.website,
|
| 2541 |
+
a.entity_id,
|
| 2542 |
+
4
|
| 2543 |
+
FROM $catalog_product_entity a
|
| 2544 |
+
JOIN $products_website_temp w
|
| 2545 |
+
ON a.store_product_id = w.store_product_id
|
| 2546 |
+
)
|
| 2547 |
+
ON DUPLICATE KEY UPDATE
|
| 2548 |
+
value = 4");
|
| 2549 |
+
|
| 2550 |
+
echo("\n replaceMagentoProductsMultistore 25\n");
|
| 2551 |
+
|
| 2552 |
+
$result = $this->db_do("
|
| 2553 |
+
INSERT INTO $catalog_product_entity_int
|
| 2554 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2555 |
+
(SELECT
|
| 2556 |
+
$_getProductEntityTypeId,
|
| 2557 |
+
$attr_visibility,
|
| 2558 |
+
0,
|
| 2559 |
+
a.entity_id,
|
| 2560 |
+
4
|
| 2561 |
+
FROM $catalog_product_entity a
|
| 2562 |
+
)
|
| 2563 |
+
ON DUPLICATE KEY UPDATE
|
| 2564 |
+
value = 4");
|
| 2565 |
+
|
| 2566 |
+
echo("\n replaceMagentoProductsMultistore 26\n");
|
| 2567 |
+
|
| 2568 |
+
$result = $this->db_do("
|
| 2569 |
+
DELETE cpw
|
| 2570 |
+
FROM $catalog_product_website cpw
|
| 2571 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2572 |
+
ON cpw.product_id = cpe.entity_id
|
| 2573 |
+
WHERE cpe.entity_id IS NULL");
|
| 2574 |
+
|
| 2575 |
+
echo("\n replaceMagentoProductsMultistore 27\n");
|
| 2576 |
+
|
| 2577 |
+
$result = $this->db_do("
|
| 2578 |
+
INSERT INTO $catalog_product_website
|
| 2579 |
+
(product_id, website_id)
|
| 2580 |
+
(SELECT
|
| 2581 |
+
a.entity_id,
|
| 2582 |
+
w.website_id
|
| 2583 |
+
FROM $catalog_product_entity a
|
| 2584 |
+
JOIN $products_website_temp w
|
| 2585 |
+
ON a.store_product_id = w.store_product_id
|
| 2586 |
+
)
|
| 2587 |
+
ON DUPLICATE KEY UPDATE
|
| 2588 |
+
product_id = a.entity_id,
|
| 2589 |
+
website_id = w.website_id");
|
| 2590 |
+
|
| 2591 |
+
echo("\n replaceMagentoProductsMultistore 28\n");
|
| 2592 |
+
|
| 2593 |
+
// temporary disabled mart@bintime.com
|
| 2594 |
+
//$result = $this->db_do("
|
| 2595 |
+
// UPDATE catalog_category_entity_int a
|
| 2596 |
+
// SET a.value = 0
|
| 2597 |
+
// WHERE a.attribute_id = 32
|
| 2598 |
+
//");
|
| 2599 |
+
|
| 2600 |
+
|
| 2601 |
+
//Adding tax class "Taxable Goods"
|
| 2602 |
+
$result = $this->db_do("
|
| 2603 |
+
INSERT INTO $catalog_product_entity_int
|
| 2604 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2605 |
+
(SELECT
|
| 2606 |
+
$_getProductEntityTypeId,
|
| 2607 |
+
$attr_tax_class_id,
|
| 2608 |
+
w.website,
|
| 2609 |
+
a.entity_id,
|
| 2610 |
+
2
|
| 2611 |
+
FROM $catalog_product_entity a
|
| 2612 |
+
JOIN $products_website_temp w
|
| 2613 |
+
ON a.store_product_id = w.store_product_id
|
| 2614 |
+
)
|
| 2615 |
+
ON DUPLICATE KEY UPDATE
|
| 2616 |
+
value = 2");
|
| 2617 |
+
|
| 2618 |
+
echo("\n replaceMagentoProductsMultistore 29\n");
|
| 2619 |
+
|
| 2620 |
+
$result = $this->db_do("
|
| 2621 |
+
INSERT INTO $catalog_product_entity_int
|
| 2622 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2623 |
+
(SELECT
|
| 2624 |
+
$_getProductEntityTypeId,
|
| 2625 |
+
$attr_tax_class_id,
|
| 2626 |
+
0,
|
| 2627 |
+
a.entity_id,
|
| 2628 |
+
2
|
| 2629 |
+
FROM $catalog_product_entity a
|
| 2630 |
+
)
|
| 2631 |
+
ON DUPLICATE KEY UPDATE
|
| 2632 |
+
value = 2");
|
| 2633 |
+
|
| 2634 |
+
echo("\n replaceMagentoProductsMultistore 30\n");
|
| 2635 |
+
|
| 2636 |
+
// Load url Image
|
| 2637 |
+
$result = $this->db_do("
|
| 2638 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2639 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2640 |
+
(SELECT
|
| 2641 |
+
$_getProductEntityTypeId,
|
| 2642 |
+
$attr_image,
|
| 2643 |
+
w.store_id,
|
| 2644 |
+
a.entity_id,
|
| 2645 |
+
b.main_image_url
|
| 2646 |
+
FROM $catalog_product_entity a
|
| 2647 |
+
JOIN $core_store w
|
| 2648 |
+
JOIN $products_temp b
|
| 2649 |
+
ON a.store_product_id = b.store_product_id
|
| 2650 |
+
)
|
| 2651 |
+
ON DUPLICATE KEY UPDATE
|
| 2652 |
+
value = b.main_image_url");
|
| 2653 |
+
|
| 2654 |
+
echo("\n replaceMagentoProductsMultistore 31\n");
|
| 2655 |
+
|
| 2656 |
+
// image for specific web sites
|
| 2657 |
+
$result = $this->db_do("
|
| 2658 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2659 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2660 |
+
(SELECT
|
| 2661 |
+
$_getProductEntityTypeId,
|
| 2662 |
+
$attr_image,
|
| 2663 |
+
0,
|
| 2664 |
+
a.entity_id,
|
| 2665 |
+
b.main_image_url
|
| 2666 |
+
FROM $catalog_product_entity a
|
| 2667 |
+
JOIN $products_temp b
|
| 2668 |
+
ON a.store_product_id = b.store_product_id
|
| 2669 |
+
)
|
| 2670 |
+
ON DUPLICATE KEY UPDATE
|
| 2671 |
+
value = b.main_image_url");
|
| 2672 |
+
|
| 2673 |
+
echo("\n replaceMagentoProductsMultistore 32\n");
|
| 2674 |
+
|
| 2675 |
+
// small_image for specific web sites
|
| 2676 |
+
$result = $this->db_do("
|
| 2677 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2678 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2679 |
+
(SELECT
|
| 2680 |
+
$_getProductEntityTypeId,
|
| 2681 |
+
$attr_small_image,
|
| 2682 |
+
w.store_id,
|
| 2683 |
+
a.entity_id,
|
| 2684 |
+
b.medium_image_url
|
| 2685 |
+
FROM $catalog_product_entity a
|
| 2686 |
+
JOIN $core_store w
|
| 2687 |
+
JOIN $products_temp b
|
| 2688 |
+
ON a.store_product_id = b.store_product_id
|
| 2689 |
+
)
|
| 2690 |
+
ON DUPLICATE KEY UPDATE
|
| 2691 |
+
value = b.medium_image_url");
|
| 2692 |
+
|
| 2693 |
+
echo("\n replaceMagentoProductsMultistore 33\n");
|
| 2694 |
+
|
| 2695 |
+
// small_image for all web sites
|
| 2696 |
+
$result = $this->db_do("
|
| 2697 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2698 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2699 |
+
(SELECT
|
| 2700 |
+
$_getProductEntityTypeId,
|
| 2701 |
+
$attr_small_image,
|
| 2702 |
+
0,
|
| 2703 |
+
a.entity_id,
|
| 2704 |
+
b.medium_image_url
|
| 2705 |
+
FROM $catalog_product_entity a
|
| 2706 |
+
JOIN $core_store w
|
| 2707 |
+
JOIN $products_temp b
|
| 2708 |
+
ON a.store_product_id = b.store_product_id
|
| 2709 |
+
)
|
| 2710 |
+
ON DUPLICATE KEY UPDATE
|
| 2711 |
+
value = b.medium_image_url");
|
| 2712 |
+
|
| 2713 |
+
echo("\n replaceMagentoProductsMultistore 34\n");
|
| 2714 |
+
|
| 2715 |
+
// thumbnail for specific web site
|
| 2716 |
+
$result = $this->db_do("
|
| 2717 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2718 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2719 |
+
(SELECT
|
| 2720 |
+
$_getProductEntityTypeId,
|
| 2721 |
+
$attr_thumbnail,
|
| 2722 |
+
w.store_id,
|
| 2723 |
+
a.entity_id,
|
| 2724 |
+
b.thumb_image_url
|
| 2725 |
+
FROM $catalog_product_entity a
|
| 2726 |
+
JOIN $core_store w
|
| 2727 |
+
JOIN $products_temp b
|
| 2728 |
+
ON a.store_product_id = b.store_product_id
|
| 2729 |
+
)
|
| 2730 |
+
ON DUPLICATE KEY UPDATE
|
| 2731 |
+
value = b.thumb_image_url");
|
| 2732 |
+
|
| 2733 |
+
echo("\n replaceMagentoProductsMultistore 35\n");
|
| 2734 |
+
|
| 2735 |
+
// thumbnail for all web sites
|
| 2736 |
+
$result = $this->db_do("
|
| 2737 |
+
INSERT INTO $catalog_product_entity_varchar
|
| 2738 |
+
(entity_type_id, attribute_id, store_id, entity_id, value)
|
| 2739 |
+
(SELECT
|
| 2740 |
+
$_getProductEntityTypeId,
|
| 2741 |
+
$attr_thumbnail,
|
| 2742 |
+
0,
|
| 2743 |
+
a.entity_id,
|
| 2744 |
+
b.thumb_image_url
|
| 2745 |
+
FROM $catalog_product_entity a
|
| 2746 |
+
JOIN $core_store w
|
| 2747 |
+
JOIN $products_temp b
|
| 2748 |
+
ON a.store_product_id = b.store_product_id
|
| 2749 |
+
)
|
| 2750 |
+
ON DUPLICATE KEY UPDATE
|
| 2751 |
+
value = b.thumb_image_url");
|
| 2752 |
+
|
| 2753 |
+
echo("\n replaceMagentoProductsMultistore 36\n");
|
| 2754 |
+
|
| 2755 |
+
|
| 2756 |
+
//Refresh fulltext search
|
| 2757 |
+
$result = $this->db_do("DROP TABLE IF EXISTS {$catalogsearch_fulltext}_tmp");
|
| 2758 |
+
$result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS {$catalogsearch_fulltext}_tmp LIKE $catalogsearch_fulltext");
|
| 2759 |
+
|
| 2760 |
+
|
| 2761 |
+
echo("\n replaceMagentoProductsMultistore 36.2\n");
|
| 2762 |
+
$q = "
|
| 2763 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 2764 |
+
(product_id, store_id, data_index)
|
| 2765 |
+
(SELECT
|
| 2766 |
+
a.entity_id,
|
| 2767 |
+
w.website,
|
| 2768 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 2769 |
+
FROM $catalog_product_entity a
|
| 2770 |
+
JOIN $products_website_temp w
|
| 2771 |
+
ON a.store_product_id = w.store_product_id
|
| 2772 |
+
LEFT JOIN $catalog_category_product b
|
| 2773 |
+
ON a.entity_id = b.product_id
|
| 2774 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 2775 |
+
ON b.category_id = c.entity_id
|
| 2776 |
+
AND c.attribute_id = $cat_attr_name
|
| 2777 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 2778 |
+
ON a.entity_id = e.entity_id
|
| 2779 |
+
AND e.attribute_id = $attr_name
|
| 2780 |
+
LEFT JOIN $catalog_product_website j
|
| 2781 |
+
ON a.entity_id = j.product_id
|
| 2782 |
+
LEFT JOIN $products_temp f
|
| 2783 |
+
ON a.entity_id = f.store_product_id
|
| 2784 |
+
)
|
| 2785 |
+
ON DUPLICATE KEY UPDATE
|
| 2786 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)";
|
| 2787 |
+
echo("\n\n============================\n$q\n============================\n\n");
|
| 2788 |
+
|
| 2789 |
+
|
| 2790 |
+
$result = $this->db_do("
|
| 2791 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 2792 |
+
(product_id, store_id, data_index)
|
| 2793 |
+
(SELECT
|
| 2794 |
+
a.entity_id,
|
| 2795 |
+
w.website,
|
| 2796 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 2797 |
+
FROM $catalog_product_entity a
|
| 2798 |
+
JOIN $products_website_temp w
|
| 2799 |
+
ON a.store_product_id = w.store_product_id
|
| 2800 |
+
LEFT JOIN $catalog_category_product b
|
| 2801 |
+
ON a.entity_id = b.product_id
|
| 2802 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 2803 |
+
ON b.category_id = c.entity_id
|
| 2804 |
+
AND c.attribute_id = $cat_attr_name
|
| 2805 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 2806 |
+
ON a.entity_id = e.entity_id
|
| 2807 |
+
AND e.attribute_id = $attr_name
|
| 2808 |
+
LEFT JOIN $catalog_product_website j
|
| 2809 |
+
ON a.entity_id = j.product_id
|
| 2810 |
+
LEFT JOIN $products_temp f
|
| 2811 |
+
ON a.entity_id = f.store_product_id
|
| 2812 |
+
)
|
| 2813 |
+
ON DUPLICATE KEY UPDATE
|
| 2814 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
|
| 2815 |
+
|
| 2816 |
+
echo("\n replaceMagentoProductsMultistore 37\n");
|
| 2817 |
+
|
| 2818 |
+
|
| 2819 |
+
$result = $this->db_do("
|
| 2820 |
+
INSERT INTO {$catalogsearch_fulltext}_tmp
|
| 2821 |
+
(product_id, store_id, data_index)
|
| 2822 |
+
(SELECT
|
| 2823 |
+
a.entity_id,
|
| 2824 |
+
w.website,
|
| 2825 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 2826 |
+
FROM $catalog_product_entity a
|
| 2827 |
+
JOIN $products_website_temp w
|
| 2828 |
+
ON a.store_product_id = w.store_product_id
|
| 2829 |
+
LEFT JOIN $catalog_category_product b
|
| 2830 |
+
ON a.entity_id = b.product_id
|
| 2831 |
+
LEFT JOIN $catalog_category_entity_varchar c
|
| 2832 |
+
ON b.category_id = c.entity_id
|
| 2833 |
+
AND c.attribute_id = $cat_attr_name
|
| 2834 |
+
LEFT JOIN $catalog_product_entity_varchar e
|
| 2835 |
+
ON a.entity_id = e.entity_id
|
| 2836 |
+
AND e.attribute_id = $attr_name
|
| 2837 |
+
LEFT JOIN $products_temp f
|
| 2838 |
+
ON a.entity_id = f.store_product_id
|
| 2839 |
+
)
|
| 2840 |
+
ON DUPLICATE KEY UPDATE
|
| 2841 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)");
|
| 2842 |
+
|
| 2843 |
+
echo("\n replaceMagentoProductsMultistore 38\n");
|
| 2844 |
+
|
| 2845 |
+
$result = $this->db_do("
|
| 2846 |
+
DELETE cf
|
| 2847 |
+
FROM $catalogsearch_fulltext cf
|
| 2848 |
+
LEFT JOIN $catalog_product_entity cpe
|
| 2849 |
+
ON cf.product_id = cpe.entity_id
|
| 2850 |
+
WHERE cpe.entity_id IS NULL");
|
| 2851 |
+
|
| 2852 |
+
echo("\n replaceMagentoProductsMultistore 39\n");
|
| 2853 |
+
|
| 2854 |
+
$result = $this->db_do("
|
| 2855 |
+
INSERT INTO $catalogsearch_fulltext
|
| 2856 |
+
(product_id, store_id, data_index)
|
| 2857 |
+
(SELECT
|
| 2858 |
+
a.product_id,
|
| 2859 |
+
a.store_id,
|
| 2860 |
+
a.data_index
|
| 2861 |
+
FROM {$catalogsearch_fulltext}_tmp a
|
| 2862 |
+
WHERE product_id = a.product_id
|
| 2863 |
+
)
|
| 2864 |
+
ON DUPLICATE KEY UPDATE
|
| 2865 |
+
data_index = a.data_index");
|
| 2866 |
+
|
| 2867 |
+
echo("\n replaceMagentoProductsMultistore 40\n");
|
| 2868 |
+
|
| 2869 |
+
$this->db_do("UPDATE $catalogsearch_query SET is_processed = 0");
|
| 2870 |
+
//INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
|
| 2871 |
+
//TODO add something else
|
| 2872 |
+
|
| 2873 |
+
$this->addRelatedProducts();
|
| 2874 |
+
echo("\n replaceMagentoProductsMultistore 41\n");
|
| 2875 |
+
} //
|
| 2876 |
+
################################################################################################################################################################
|
| 2877 |
+
|
| 2878 |
+
|
| 2879 |
+
|
| 2880 |
+
|
| 2881 |
+
|
| 2882 |
+
|
| 2883 |
+
|
| 2884 |
+
|
| 2885 |
+
|
| 2886 |
+
|
| 2887 |
+
|
| 2888 |
+
|
| 2889 |
+
|
| 2890 |
+
|
| 2891 |
+
|
| 2892 |
+
|
| 2893 |
+
|
| 2894 |
+
|
| 2895 |
+
|
| 2896 |
+
|
| 2897 |
+
|
| 2898 |
+
|
| 2899 |
+
|
| 2900 |
+
|
| 2901 |
+
|
| 2902 |
+
|
| 2903 |
+
|
| 2904 |
+
|
| 2905 |
+
|
| 2906 |
+
|
| 2907 |
+
|
| 2908 |
+
|
| 2909 |
+
|
| 2910 |
+
|
| 2911 |
+
|
| 2912 |
+
|
| 2913 |
+
|
| 2914 |
+
|
| 2915 |
+
|
| 2916 |
+
|
| 2917 |
+
|
| 2918 |
+
|
| 2919 |
+
|
| 2920 |
+
|
| 2921 |
+
|
| 2922 |
+
|
| 2923 |
+
|
| 2924 |
+
|
| 2925 |
+
|
| 2926 |
+
|
| 2927 |
+
|
| 2928 |
+
|
| 2929 |
+
|
| 2930 |
+
|
| 2931 |
+
|
| 2932 |
+
|
| 2933 |
+
|
| 2934 |
+
|
| 2935 |
+
|
| 2936 |
+
|
| 2937 |
+
|
| 2938 |
+
|
| 2939 |
+
|
| 2940 |
+
|
| 2941 |
+
|
| 2942 |
+
|
| 2943 |
+
|
| 2944 |
+
|
| 2945 |
+
|
| 2946 |
+
|
| 2947 |
+
|
| 2948 |
+
|
| 2949 |
+
|
| 2950 |
+
|
| 2951 |
+
|
| 2952 |
+
|
| 2953 |
+
|
| 2954 |
+
|
| 2955 |
+
|
| 2956 |
+
|
| 2957 |
+
|
| 2958 |
+
|
| 2959 |
+
|
| 2960 |
+
|
| 2961 |
+
|
| 2962 |
+
|
| 2963 |
+
|
| 2964 |
+
|
| 2965 |
+
|
| 2966 |
+
################################################################################################################################################################
|
| 2967 |
+
private function truncateAllCateriesAndRecreateDefaults($root_cat, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 2968 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id,
|
| 2969 |
+
$name_attrid, $attr_url_key, $attr_display_mode, $attr_url_key, $attr_is_active, $attr_include_in_menu)
|
| 2970 |
+
{
|
| 2971 |
+
$this->db_do('SET foreign_key_checks=0');
|
| 2972 |
+
|
| 2973 |
+
$this->db_do("TRUNCATE $catalog_category_entity");
|
| 2974 |
+
$this->db_do("
|
| 2975 |
+
INSERT $catalog_category_entity
|
| 2976 |
+
(
|
| 2977 |
+
entity_id,
|
| 2978 |
+
entity_type_id,
|
| 2979 |
+
attribute_set_id,
|
| 2980 |
+
parent_id,
|
| 2981 |
+
created_at,
|
| 2982 |
+
updated_at,
|
| 2983 |
+
path,
|
| 2984 |
+
position,
|
| 2985 |
+
level,
|
| 2986 |
+
children_count,
|
| 2987 |
+
store_category_id,
|
| 2988 |
+
parent_store_category_id
|
| 2989 |
+
)
|
| 2990 |
+
VALUES
|
| 2991 |
+
(1, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 0, '0000-00-00 00:00:00', now(), '1', 0, 0, 1, null, null),
|
| 2992 |
+
(2, $_categoryEntityTypeId, $_categoryDefault_attribute_set_id, 1, now(), now(), '1/2', 1, 1, 0, null, null)");
|
| 2993 |
+
|
| 2994 |
+
$this->db_do("TRUNCATE $catalog_category_entity_varchar");
|
| 2995 |
+
$this->db_do("
|
| 2996 |
+
INSERT $catalog_category_entity_varchar
|
| 2997 |
+
(
|
| 2998 |
+
value_id,
|
| 2999 |
+
entity_type_id,
|
| 3000 |
+
attribute_id,
|
| 3001 |
+
store_id,
|
| 3002 |
+
entity_id,
|
| 3003 |
+
value
|
| 3004 |
+
)
|
| 3005 |
+
VALUES
|
| 3006 |
+
(1, $_categoryEntityTypeId, $name_attrid, 0, 1, 'Root Catalog'),
|
| 3007 |
+
(2, $_categoryEntityTypeId, $name_attrid, 1, 1, 'Root Catalog'),
|
| 3008 |
+
(3, $_categoryEntityTypeId, $attr_url_key, 0, 1, 'root-catalog'),
|
| 3009 |
+
(4, $_categoryEntityTypeId, $name_attrid, 0, 2, 'Default Category'),
|
| 3010 |
+
(5, $_categoryEntityTypeId, $name_attrid, 1, 2, 'Default Category'),
|
| 3011 |
+
(6, $_categoryEntityTypeId, $attr_display_mode, 1, 2, 'PRODUCTS'),
|
| 3012 |
+
(7, $_categoryEntityTypeId, $attr_url_key, 0, 2, 'default-category')");
|
| 3013 |
+
|
| 3014 |
+
$this->db_do("TRUNCATE $catalog_category_entity_int");
|
| 3015 |
+
$this->db_do("
|
| 3016 |
+
INSERT $catalog_category_entity_int
|
| 3017 |
+
(
|
| 3018 |
+
value_id,
|
| 3019 |
+
entity_type_id,
|
| 3020 |
+
attribute_id,
|
| 3021 |
+
store_id,
|
| 3022 |
+
entity_id,
|
| 3023 |
+
value
|
| 3024 |
+
)
|
| 3025 |
+
VALUES
|
| 3026 |
+
(1, $_categoryEntityTypeId, $attr_is_active, 0, 2, 1),
|
| 3027 |
+
(2, $_categoryEntityTypeId, $attr_is_active, 1, 2, 1),
|
| 3028 |
+
(3, $_categoryEntityTypeId, $attr_include_in_menu, 0, 1, 1),
|
| 3029 |
+
(4, $_categoryEntityTypeId, $attr_include_in_menu, 0, 2, 1)");
|
| 3030 |
+
|
| 3031 |
+
return $root_cat;
|
| 3032 |
+
} // private function truncateAllCateriesAndRecreateDefaults(...)
|
| 3033 |
+
################################################################################################################################################################
|
| 3034 |
+
|
| 3035 |
+
|
| 3036 |
+
|
| 3037 |
+
################################################################################################################################################################
|
| 3038 |
+
private function setCategorySettings($categories_temp, $root_cat)
|
| 3039 |
+
{
|
| 3040 |
+
$this->db_do("
|
| 3041 |
+
UPDATE $categories_temp
|
| 3042 |
+
SET parent_store_category_id = $root_cat
|
| 3043 |
+
WHERE parent_store_category_id = 0");
|
| 3044 |
+
|
| 3045 |
+
$store_cat_ids = $this->db_do("SELECT store_category_id FROM $categories_temp");
|
| 3046 |
+
while ($row = mysql_fetch_array($store_cat_ids))
|
| 3047 |
+
{
|
| 3048 |
+
$store_category_id = $row['store_category_id'];
|
| 3049 |
+
|
| 3050 |
+
$children_count = $this->count_children($store_category_id);
|
| 3051 |
+
$level = $this->get_category_level($store_category_id);
|
| 3052 |
+
|
| 3053 |
+
$this->db_do("
|
| 3054 |
+
UPDATE $categories_temp
|
| 3055 |
+
SET children_count = $children_count,
|
| 3056 |
+
level = $level
|
| 3057 |
+
WHERE store_category_id = $store_category_id");
|
| 3058 |
+
}
|
| 3059 |
+
} // private function setCategorySettings($categories_temp, $root_cat)
|
| 3060 |
+
################################################################################################################################################################
|
| 3061 |
+
|
| 3062 |
+
|
| 3063 |
+
|
| 3064 |
+
|
| 3065 |
+
|
| 3066 |
+
|
| 3067 |
+
|
| 3068 |
+
################################################################################################################################################################
|
| 3069 |
+
public function mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat)
|
| 3070 |
+
{
|
| 3071 |
+
$stINch_categories_mapping_temp = Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping_temp');
|
| 3072 |
+
|
| 3073 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping_temp");
|
| 3074 |
+
|
| 3075 |
+
$this->db_do("
|
| 3076 |
+
CREATE TABLE $stINch_categories_mapping_temp
|
| 3077 |
+
(
|
| 3078 |
+
shop_entity_id INT(11) UNSIGNED NOT NULL,
|
| 3079 |
+
shop_entity_type_id INT(11),
|
| 3080 |
+
shop_attribute_set_id INT(11),
|
| 3081 |
+
shop_parent_id INT(11),
|
| 3082 |
+
shop_store_category_id INT(11),
|
| 3083 |
+
shop_parent_store_category_id INT(11),
|
| 3084 |
+
store_category_id INT(11),
|
| 3085 |
+
parent_store_category_id INT(11),
|
| 3086 |
+
category_name VARCHAR(255),
|
| 3087 |
+
order_number INT(11),
|
| 3088 |
+
products_within_this_category INT(11),
|
| 3089 |
+
|
| 3090 |
+
KEY shop_entity_id (shop_entity_id),
|
| 3091 |
+
KEY shop_parent_id (shop_parent_id),
|
| 3092 |
+
KEY store_category_id (store_category_id),
|
| 3093 |
+
KEY parent_store_category_id (parent_store_category_id),
|
| 3094 |
+
UNIQUE KEY(shop_entity_id)
|
| 3095 |
+
)");
|
| 3096 |
+
|
| 3097 |
+
$this->db_do("CREATE TABLE IF NOT EXISTS $stINch_categories_mapping LIKE $stINch_categories_mapping_temp");
|
| 3098 |
+
|
| 3099 |
+
$this->db_do("
|
| 3100 |
+
INSERT IGNORE INTO $stINch_categories_mapping_temp
|
| 3101 |
+
(
|
| 3102 |
+
shop_entity_id,
|
| 3103 |
+
shop_entity_type_id,
|
| 3104 |
+
shop_attribute_set_id,
|
| 3105 |
+
shop_parent_id,
|
| 3106 |
+
shop_store_category_id,
|
| 3107 |
+
shop_parent_store_category_id
|
| 3108 |
+
)
|
| 3109 |
+
(SELECT
|
| 3110 |
+
entity_id,
|
| 3111 |
+
entity_type_id,
|
| 3112 |
+
attribute_set_id,
|
| 3113 |
+
parent_id,
|
| 3114 |
+
store_category_id,
|
| 3115 |
+
parent_store_category_id
|
| 3116 |
+
FROM $catalog_category_entity)");
|
| 3117 |
+
|
| 3118 |
+
$this->db_do("
|
| 3119 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 3120 |
+
JOIN $categories_temp c
|
| 3121 |
+
ON cmt.shop_store_category_id = c.store_category_id
|
| 3122 |
+
SET
|
| 3123 |
+
cmt.store_category_id = c.store_category_id,
|
| 3124 |
+
cmt.parent_store_category_id = c.parent_store_category_id,
|
| 3125 |
+
cmt.category_name = c.category_name,
|
| 3126 |
+
cmt.order_number = c.order_number,
|
| 3127 |
+
cmt.products_within_this_category = c.products_within_this_category");
|
| 3128 |
+
|
| 3129 |
+
$this->db_do("
|
| 3130 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 3131 |
+
JOIN $catalog_category_entity cce
|
| 3132 |
+
ON cmt.parent_store_category_id = cce.store_category_id
|
| 3133 |
+
SET cmt.shop_parent_id = cce.entity_id");
|
| 3134 |
+
|
| 3135 |
+
$this->db_do("
|
| 3136 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 3137 |
+
JOIN $categories_temp c
|
| 3138 |
+
ON cmt.shop_store_category_id = c.store_category_id
|
| 3139 |
+
SET shop_parent_id = ".$this->_root_cat."
|
| 3140 |
+
WHERE shop_parent_id = 0");
|
| 3141 |
+
// !!!!!!!!!!!!!!!!!!!!!!!!!!! one shop ($this->_root_cat) => milti shop ($root_cat)
|
| 3142 |
+
|
| 3143 |
+
// added for mapping new sinch categories in merge && !UPDATE_CATEGORY_DATA mode
|
| 3144 |
+
if ((UPDATE_CATEGORY_DATA && $im_type == "MERGE") || ($im_type == "REWRITE"))
|
| 3145 |
+
{
|
| 3146 |
+
$this->db_do("
|
| 3147 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 3148 |
+
JOIN $catalog_category_entity cce
|
| 3149 |
+
ON cmt.shop_entity_id = cce.entity_id
|
| 3150 |
+
SET cce.parent_id = cmt.shop_parent_id");
|
| 3151 |
+
}
|
| 3152 |
+
else
|
| 3153 |
+
{
|
| 3154 |
+
$this->db_do("
|
| 3155 |
+
UPDATE $stINch_categories_mapping_temp cmt
|
| 3156 |
+
JOIN $catalog_category_entity cce
|
| 3157 |
+
ON cmt.shop_entity_id = cce.entity_id
|
| 3158 |
+
SET cce.parent_id = cmt.shop_parent_id
|
| 3159 |
+
WHERE cce.parent_id = 0 AND cce.store_category_id IS NOT NULL");
|
| 3160 |
+
}
|
| 3161 |
+
|
| 3162 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories_mapping");
|
| 3163 |
+
$this->db_do("RENAME TABLE $stINch_categories_mapping_temp TO $stINch_categories_mapping");
|
| 3164 |
+
} //
|
| 3165 |
+
################################################################################################################################################################
|
| 3166 |
+
|
| 3167 |
+
|
| 3168 |
+
|
| 3169 |
+
################################################################################################################################################################
|
| 3170 |
+
private function addCategoryData($categories_temp, $stINch_categories_mapping, $stINch_categories, $catalog_category_entity, $catalog_category_entity_varchar, $catalog_category_entity_int,
|
| 3171 |
+
$_categoryEntityTypeId, $_categoryDefault_attribute_set_id, $name_attrid, $attr_is_active, $attr_include_in_menu, $is_anchor_attrid, $image_attrid, $im_type, $root_cat)
|
| 3172 |
+
{
|
| 3173 |
+
if (UPDATE_CATEGORY_DATA)
|
| 3174 |
+
{
|
| 3175 |
+
echo "Update category_entity \n";
|
| 3176 |
+
|
| 3177 |
+
$q = "
|
| 3178 |
+
INSERT INTO $catalog_category_entity
|
| 3179 |
+
(
|
| 3180 |
+
entity_type_id,
|
| 3181 |
+
attribute_set_id,
|
| 3182 |
+
created_at,
|
| 3183 |
+
updated_at,
|
| 3184 |
+
level,
|
| 3185 |
+
children_count,
|
| 3186 |
+
entity_id,
|
| 3187 |
+
position,
|
| 3188 |
+
parent_id,
|
| 3189 |
+
store_category_id,
|
| 3190 |
+
parent_store_category_id
|
| 3191 |
+
)
|
| 3192 |
+
(SELECT
|
| 3193 |
+
$_categoryEntityTypeId,
|
| 3194 |
+
$_categoryDefault_attribute_set_id,
|
| 3195 |
+
now(),
|
| 3196 |
+
now(),
|
| 3197 |
+
c.level,
|
| 3198 |
+
c.children_count,
|
| 3199 |
+
scm.shop_entity_id,
|
| 3200 |
+
c.order_number,
|
| 3201 |
+
scm.shop_parent_id,
|
| 3202 |
+
c.store_category_id,
|
| 3203 |
+
c.parent_store_category_id
|
| 3204 |
+
FROM $categories_temp c
|
| 3205 |
+
LEFT JOIN $stINch_categories_mapping scm
|
| 3206 |
+
ON c.store_category_id = scm.store_category_id
|
| 3207 |
+
)
|
| 3208 |
+
ON DUPLICATE KEY UPDATE
|
| 3209 |
+
updated_at = now(),
|
| 3210 |
+
store_category_id = c.store_category_id,
|
| 3211 |
+
level = c.level,
|
| 3212 |
+
children_count = c.children_count,
|
| 3213 |
+
position = c.order_number,
|
| 3214 |
+
parent_store_category_id = c.parent_store_category_id";
|
| 3215 |
+
//level=c.level,
|
| 3216 |
+
//children_count=c.children_count
|
| 3217 |
+
//position=c.order_number,
|
| 3218 |
+
}
|
| 3219 |
+
else
|
| 3220 |
+
{
|
| 3221 |
+
echo "Insert ignore category_entity \n";
|
| 3222 |
+
|
| 3223 |
+
$q = "
|
| 3224 |
+
INSERT IGNORE INTO $catalog_category_entity
|
| 3225 |
+
(
|
| 3226 |
+
entity_type_id,
|
| 3227 |
+
attribute_set_id,
|
| 3228 |
+
created_at,
|
| 3229 |
+
updated_at,
|
| 3230 |
+
level,
|
| 3231 |
+
children_count,
|
| 3232 |
+
entity_id,
|
| 3233 |
+
position,
|
| 3234 |
+
parent_id,
|
| 3235 |
+
store_category_id,
|
| 3236 |
+
parent_store_category_id
|
| 3237 |
+
)
|
| 3238 |
+
(SELECT
|
| 3239 |
+
$_categoryEntityTypeId,
|
| 3240 |
+
$_categoryDefault_attribute_set_id,
|
| 3241 |
+
now(),
|
| 3242 |
+
now(),
|
| 3243 |
+
c.level,
|
| 3244 |
+
c.children_count,
|
| 3245 |
+
scm.shop_entity_id,
|
| 3246 |
+
c.order_number,
|
| 3247 |
+
scm.shop_parent_id,
|
| 3248 |
+
c.store_category_id,
|
| 3249 |
+
c.parent_store_category_id
|
| 3250 |
+
FROM $categories_temp c
|
| 3251 |
+
LEFT JOIN $stINch_categories_mapping scm
|
| 3252 |
+
ON c.store_category_id = scm.store_category_id
|
| 3253 |
+
)";
|
| 3254 |
+
}
|
| 3255 |
+
$this->db_do($q);
|
| 3256 |
+
|
| 3257 |
+
$this->mapSinchCategories($stINch_categories_mapping, $catalog_category_entity, $categories_temp, $im_type, $root_cat);
|
| 3258 |
+
|
| 3259 |
+
|
| 3260 |
+
|
| 3261 |
+
$categories = $this->db_do("SELECT entity_id, parent_id FROM $catalog_category_entity ORDER BY parent_id");
|
| 3262 |
+
while ($row = mysql_fetch_array($categories))
|
| 3263 |
+
{
|
| 3264 |
+
$parent_id = $row['parent_id'];
|
| 3265 |
+
$entity_id = $row['entity_id'];
|
| 3266 |
+
|
| 3267 |
+
$path = $this->culc_path($parent_id, $entity_id);
|
| 3268 |
+
|
| 3269 |
+
echo("\n$path\n");
|
| 3270 |
+
|
| 3271 |
+
$this->db_do("
|
| 3272 |
+
UPDATE $catalog_category_entity
|
| 3273 |
+
SET path = '$path'
|
| 3274 |
+
WHERE entity_id = $entity_id");
|
| 3275 |
+
}
|
| 3276 |
+
|
| 3277 |
+
if(UPDATE_CATEGORY_DATA)
|
| 3278 |
+
{
|
| 3279 |
+
echo "Update category_data \n";
|
| 3280 |
+
|
| 3281 |
+
$q = "
|
| 3282 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 3283 |
+
(
|
| 3284 |
+
entity_type_id,
|
| 3285 |
+
attribute_id,
|
| 3286 |
+
store_id,
|
| 3287 |
+
entity_id,
|
| 3288 |
+
value
|
| 3289 |
+
)
|
| 3290 |
+
(SELECT
|
| 3291 |
+
$_categoryEntityTypeId,
|
| 3292 |
+
$name_attrid,
|
| 3293 |
+
0,
|
| 3294 |
+
scm.shop_entity_id,
|
| 3295 |
+
c.category_name
|
| 3296 |
+
FROM $categories_temp c
|
| 3297 |
+
JOIN $stINch_categories_mapping scm
|
| 3298 |
+
ON c.store_category_id = scm.store_category_id
|
| 3299 |
+
)
|
| 3300 |
+
ON DUPLICATE KEY UPDATE
|
| 3301 |
+
value = c.category_name";
|
| 3302 |
+
$this->db_do($q);
|
| 3303 |
+
|
| 3304 |
+
$q = "
|
| 3305 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 3306 |
+
(
|
| 3307 |
+
entity_type_id,
|
| 3308 |
+
attribute_id,
|
| 3309 |
+
store_id,
|
| 3310 |
+
entity_id,
|
| 3311 |
+
value
|
| 3312 |
+
)
|
| 3313 |
+
(SELECT
|
| 3314 |
+
$_categoryEntityTypeId,
|
| 3315 |
+
$name_attrid,
|
| 3316 |
+
1,
|
| 3317 |
+
scm.shop_entity_id,
|
| 3318 |
+
c.category_name
|
| 3319 |
+
FROM $categories_temp c
|
| 3320 |
+
JOIN $stINch_categories_mapping scm
|
| 3321 |
+
ON c.store_category_id = scm.store_category_id
|
| 3322 |
+
)
|
| 3323 |
+
ON DUPLICATE KEY UPDATE
|
| 3324 |
+
value = c.category_name";
|
| 3325 |
+
$this->db_do($q);
|
| 3326 |
+
|
| 3327 |
+
$q = "
|
| 3328 |
+
INSERT INTO $catalog_category_entity
|
| 3329 |
+
(
|
| 3330 |
+
entity_type_id,
|
| 3331 |
+
attribute_id,
|
| 3332 |
+
store_id,
|
| 3333 |
+
entity_id,
|
| 3334 |
+
value
|
| 3335 |
+
)
|
| 3336 |
+
(SELECT
|
| 3337 |
+
$_categoryEntityTypeId,
|
| 3338 |
+
$attr_is_active,
|
| 3339 |
+
0,
|
| 3340 |
+
scm.shop_entity_id,
|
| 3341 |
+
1
|
| 3342 |
+
FROM $categories_temp c
|
| 3343 |
+
JOIN $stINch_categories_mapping scm
|
| 3344 |
+
ON c.store_category_id = scm.store_category_id
|
| 3345 |
+
)
|
| 3346 |
+
ON DUPLICATE KEY UPDATE
|
| 3347 |
+
value = 1";
|
| 3348 |
+
$this->db_do($q);
|
| 3349 |
+
|
| 3350 |
+
$q = "
|
| 3351 |
+
INSERT INTO $catalog_category_entity_int
|
| 3352 |
+
(
|
| 3353 |
+
entity_type_id,
|
| 3354 |
+
attribute_id,
|
| 3355 |
+
store_id,
|
| 3356 |
+
entity_id,
|
| 3357 |
+
value
|
| 3358 |
+
)
|
| 3359 |
+
(SELECT
|
| 3360 |
+
$_categoryEntityTypeId,
|
| 3361 |
+
$attr_is_active,
|
| 3362 |
+
1,
|
| 3363 |
+
scm.shop_entity_id,
|
| 3364 |
+
1
|
| 3365 |
+
FROM $categories_temp c
|
| 3366 |
+
JOIN $stINch_categories_mapping scm
|
| 3367 |
+
ON c.store_category_id = scm.store_category_id
|
| 3368 |
+
)
|
| 3369 |
+
ON DUPLICATE KEY UPDATE
|
| 3370 |
+
value = 1";
|
| 3371 |
+
$this->db_do($q);
|
| 3372 |
+
|
| 3373 |
+
$q = "
|
| 3374 |
+
INSERT INTO $catalog_category_entity_int
|
| 3375 |
+
(
|
| 3376 |
+
entity_type_id,
|
| 3377 |
+
attribute_id,
|
| 3378 |
+
store_id,
|
| 3379 |
+
entity_id,
|
| 3380 |
+
value
|
| 3381 |
+
)
|
| 3382 |
+
(SELECT
|
| 3383 |
+
$_categoryEntityTypeId,
|
| 3384 |
+
$attr_include_in_menu,
|
| 3385 |
+
0,
|
| 3386 |
+
scm.shop_entity_id,
|
| 3387 |
+
1
|
| 3388 |
+
FROM $categories_temp c
|
| 3389 |
+
JOIN $stINch_categories_mapping scm
|
| 3390 |
+
ON c.store_category_id = scm.store_category_id
|
| 3391 |
+
)
|
| 3392 |
+
ON DUPLICATE KEY UPDATE
|
| 3393 |
+
value = 1";
|
| 3394 |
+
$this->db_do($q);
|
| 3395 |
+
|
| 3396 |
+
$q = "
|
| 3397 |
+
INSERT INTO $catalog_category_entity_int
|
| 3398 |
+
(
|
| 3399 |
+
entity_type_id,
|
| 3400 |
+
attribute_id,
|
| 3401 |
+
store_id,
|
| 3402 |
+
entity_id,
|
| 3403 |
+
value
|
| 3404 |
+
)
|
| 3405 |
+
(SELECT
|
| 3406 |
+
$_categoryEntityTypeId,
|
| 3407 |
+
$is_anchor_attrid,
|
| 3408 |
+
1,
|
| 3409 |
+
scm.shop_entity_id,
|
| 3410 |
+
1
|
| 3411 |
+
FROM $categories_temp c
|
| 3412 |
+
JOIN $stINch_categories_mapping scm
|
| 3413 |
+
ON c.store_category_id = scm.store_category_id
|
| 3414 |
+
)
|
| 3415 |
+
ON DUPLICATE KEY UPDATE
|
| 3416 |
+
value = 1";
|
| 3417 |
+
$this->db_do($q);
|
| 3418 |
+
|
| 3419 |
+
$q = "
|
| 3420 |
+
INSERT INTO $catalog_category_entity_int
|
| 3421 |
+
(
|
| 3422 |
+
entity_type_id,
|
| 3423 |
+
attribute_id,
|
| 3424 |
+
store_id,
|
| 3425 |
+
entity_id,
|
| 3426 |
+
value
|
| 3427 |
+
)
|
| 3428 |
+
(SELECT
|
| 3429 |
+
$_categoryEntityTypeId,
|
| 3430 |
+
$is_anchor_attrid,
|
| 3431 |
+
0,
|
| 3432 |
+
scm.shop_entity_id,
|
| 3433 |
+
1
|
| 3434 |
+
FROM $categories_temp c
|
| 3435 |
+
JOIN $stINch_categories_mapping scm
|
| 3436 |
+
ON c.store_category_id = scm.store_category_id
|
| 3437 |
+
)
|
| 3438 |
+
ON DUPLICATE KEY UPDATE
|
| 3439 |
+
value = 1";
|
| 3440 |
+
$this->db_do($q);
|
| 3441 |
+
|
| 3442 |
+
$q = "
|
| 3443 |
+
INSERT INTO $catalog_category_entity_varchar
|
| 3444 |
+
(
|
| 3445 |
+
entity_type_id,
|
| 3446 |
+
attribute_id,
|
| 3447 |
+
store_id,
|
| 3448 |
+
entity_id,
|
| 3449 |
+
value
|
| 3450 |
+
)
|
| 3451 |
+
(SELECT
|
| 3452 |
+
$_categoryEntityTypeId,
|
| 3453 |
+
$image_attrid,
|
| 3454 |
+
0,
|
| 3455 |
+
scm.shop_entity_id,
|
| 3456 |
+
c.categories_image
|
| 3457 |
+
FROM $categories_temp c
|
| 3458 |
+
JOIN $stINch_categories_mapping scm
|
| 3459 |
+
ON c.store_category_id = scm.store_category_id
|
| 3460 |
+
)
|
| 3461 |
+
ON DUPLICATE KEY UPDATE
|
| 3462 |
+
value = c.categories_image";
|
| 3463 |
+
$this->db_do($q);
|
| 3464 |
+
}
|
| 3465 |
+
else
|
| 3466 |
+
{
|
| 3467 |
+
echo "Insert ignore category_data \n";
|
| 3468 |
+
|
| 3469 |
+
$q = "
|
| 3470 |
+
INSERT IGNORE INTO $catalog_category_entity_varchar
|
| 3471 |
+
(
|
| 3472 |
+
entity_type_id,
|
| 3473 |
+
attribute_id,
|
| 3474 |
+
store_id,
|
| 3475 |
+
entity_id,
|
| 3476 |
+
value
|
| 3477 |
+
)
|
| 3478 |
+
(SELECT
|
| 3479 |
+
$_categoryEntityTypeId,
|
| 3480 |
+
$name_attrid,
|
| 3481 |
+
0,
|
| 3482 |
+
scm.shop_entity_id,
|
| 3483 |
+
c.category_name
|
| 3484 |
+
FROM $categories_temp c
|
| 3485 |
+
JOIN $stINch_categories_mapping scm
|
| 3486 |
+
ON c.store_category_id = scm.store_category_id
|
| 3487 |
+
)";
|
| 3488 |
+
$this->db_do($q);
|
| 3489 |
+
|
| 3490 |
+
$q = "
|
| 3491 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 3492 |
+
(
|
| 3493 |
+
entity_type_id,
|
| 3494 |
+
attribute_id,
|
| 3495 |
+
store_id,
|
| 3496 |
+
entity_id,
|
| 3497 |
+
value
|
| 3498 |
+
)
|
| 3499 |
+
(SELECT
|
| 3500 |
+
$_categoryEntityTypeId,
|
| 3501 |
+
$attr_is_active,
|
| 3502 |
+
0,
|
| 3503 |
+
scm.shop_entity_id,
|
| 3504 |
+
1
|
| 3505 |
+
FROM $categories_temp c
|
| 3506 |
+
JOIN $stINch_categories_mapping scm
|
| 3507 |
+
ON c.store_category_id = scm.store_category_id
|
| 3508 |
+
)";
|
| 3509 |
+
$this->db_do($q);
|
| 3510 |
+
|
| 3511 |
+
$q = "
|
| 3512 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 3513 |
+
(
|
| 3514 |
+
entity_type_id,
|
| 3515 |
+
attribute_id,
|
| 3516 |
+
store_id,
|
| 3517 |
+
entity_id,
|
| 3518 |
+
value
|
| 3519 |
+
)
|
| 3520 |
+
(SELECT
|
| 3521 |
+
$_categoryEntityTypeId,
|
| 3522 |
+
$attr_include_in_menu,
|
| 3523 |
+
0,
|
| 3524 |
+
scm.shop_entity_id,
|
| 3525 |
+
1
|
| 3526 |
+
FROM $categories_temp c
|
| 3527 |
+
JOIN $stINch_categories_mapping scm
|
| 3528 |
+
ON c.store_category_id = scm.store_category_id
|
| 3529 |
+
)";
|
| 3530 |
+
$this->db_do($q);
|
| 3531 |
+
|
| 3532 |
+
$q = "
|
| 3533 |
+
INSERT IGNORE INTO $catalog_category_entity_int
|
| 3534 |
+
(
|
| 3535 |
+
entity_type_id,
|
| 3536 |
+
attribute_id,
|
| 3537 |
+
store_id,
|
| 3538 |
+
entity_id,
|
| 3539 |
+
value
|
| 3540 |
+
)
|
| 3541 |
+
(SELECT
|
| 3542 |
+
$_categoryEntityTypeId,
|
| 3543 |
+
$is_anchor_attrid,
|
| 3544 |
+
0,
|
| 3545 |
+
scm.shop_entity_id,
|
| 3546 |
+
1
|
| 3547 |
+
FROM $categories_temp c
|
| 3548 |
+
JOIN $stINch_categories_mapping scm
|
| 3549 |
+
ON c.store_category_id = scm.store_category_id
|
| 3550 |
+
)";
|
| 3551 |
+
$this->db_do($q);
|
| 3552 |
+
|
| 3553 |
+
$q = "
|
| 3554 |
+
INSERT IGNORE INTO $catalog_category_entity_varchar
|
| 3555 |
+
(
|
| 3556 |
+
entity_type_id,
|
| 3557 |
+
attribute_id,
|
| 3558 |
+
store_id,
|
| 3559 |
+
entity_id,
|
| 3560 |
+
value
|
| 3561 |
+
)
|
| 3562 |
+
(SELECT
|
| 3563 |
+
$_categoryEntityTypeId,
|
| 3564 |
+
$image_attrid,
|
| 3565 |
+
0,
|
| 3566 |
+
scm.shop_entity_id,
|
| 3567 |
+
c.categories_image
|
| 3568 |
+
FROM $categories_temp c
|
| 3569 |
+
JOIN $stINch_categories_mapping scm
|
| 3570 |
+
ON c.store_category_id = scm.store_category_id
|
| 3571 |
+
)";
|
| 3572 |
+
$this->db_do($q);
|
| 3573 |
+
}
|
| 3574 |
+
|
| 3575 |
+
$this->delete_old_sinch_categories_from_shop();
|
| 3576 |
+
|
| 3577 |
+
$this->db_do("DROP TABLE IF EXISTS $stINch_categories");
|
| 3578 |
+
$this->db_do("RENAME TABLE $categories_temp TO $stINch_categories");
|
| 3579 |
+
} // private function addCategoryData(...)
|
| 3580 |
+
################################################################################################################################################################
|
| 3581 |
+
|
| 3582 |
+
|
| 3583 |
+
|
| 3584 |
+
|
| 3585 |
+
|
| 3586 |
+
|
| 3587 |
+
|
| 3588 |
+
|
| 3589 |
+
|
| 3590 |
+
|
| 3591 |
+
|
| 3592 |
+
|
| 3593 |
+
|
| 3594 |
+
|
| 3595 |
+
|
| 3596 |
+
|
| 3597 |
+
|
| 3598 |
+
function ParseCategoryFeatures(){
|
| 3599 |
+
|
| 3600 |
+
$parse_file=$this->varDir.FILE_CATEGORIES_FEATURES;
|
| 3601 |
+
if(filesize($parse_file) || $this->_ignore_category_features){
|
| 3602 |
+
$this->_LOG("Start parse ".FILE_CATEGORIES_FEATURES);
|
| 3603 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp'));
|
| 3604 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')." (
|
| 3605 |
+
category_feature_id int(11),
|
| 3606 |
+
store_category_id int(11),
|
| 3607 |
+
feature_name varchar(50),
|
| 3608 |
+
display_order_number int(11),
|
| 3609 |
+
KEY(store_category_id),
|
| 3610 |
+
KEY(category_feature_id)
|
| 3611 |
+
)
|
| 3612 |
+
");
|
| 3613 |
+
|
| 3614 |
+
if(!$this->_ignore_category_features){
|
| 3615 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
|
| 3616 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
|
| 3617 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 3618 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 3619 |
+
LINES TERMINATED BY \"\r\n\"
|
| 3620 |
+
IGNORE 1 LINES ");
|
| 3621 |
+
}
|
| 3622 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
|
| 3623 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('categories_features_temp')."
|
| 3624 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features'));
|
| 3625 |
+
|
| 3626 |
+
$this->_LOG("Finish parse ".FILE_CATEGORIES_FEATURES);
|
| 3627 |
+
}else{
|
| 3628 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 3629 |
+
}
|
| 3630 |
+
$this->_LOG(' ');
|
| 3631 |
+
}
|
| 3632 |
+
|
| 3633 |
+
#################################################################################################
|
| 3634 |
+
|
| 3635 |
+
function ParseDistributors(){
|
| 3636 |
+
|
| 3637 |
+
$parse_file=$this->varDir.FILE_DISTRIBUTORS;
|
| 3638 |
+
if(filesize($parse_file)){
|
| 3639 |
+
$this->_LOG("Start parse ".FILE_DISTRIBUTORS);
|
| 3640 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('distributors_temp'));
|
| 3641 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."(
|
| 3642 |
+
distributor_id int(11),
|
| 3643 |
+
distributor_name varchar(255),
|
| 3644 |
+
website varchar(255),
|
| 3645 |
+
KEY(distributor_id)
|
| 3646 |
+
)
|
| 3647 |
+
");
|
| 3648 |
+
|
| 3649 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
|
| 3650 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
|
| 3651 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 3652 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 3653 |
+
LINES TERMINATED BY \"\r\n\"
|
| 3654 |
+
IGNORE 1 LINES ");
|
| 3655 |
+
|
| 3656 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
|
| 3657 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('distributors_temp')."
|
| 3658 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_distributors'));
|
| 3659 |
+
|
| 3660 |
+
$this->_LOG("Finish parse ".FILE_DISTRIBUTORS);
|
| 3661 |
+
}else{
|
| 3662 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 3663 |
+
}
|
| 3664 |
+
$this->_LOG(' ');
|
| 3665 |
+
}
|
| 3666 |
+
|
| 3667 |
+
#################################################################################################
|
| 3668 |
+
|
| 3669 |
+
function ParseEANCodes(){
|
| 3670 |
+
|
| 3671 |
+
$parse_file=$this->varDir.FILE_EANCODES;
|
| 3672 |
+
if(filesize($parse_file)){
|
| 3673 |
+
$this->_LOG("Start parse ".FILE_EANCODES);
|
| 3674 |
+
|
| 3675 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp'));
|
| 3676 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."(
|
| 3677 |
+
product_id int(11),
|
| 3678 |
+
ean_code varchar(255),
|
| 3679 |
+
KEY(product_id)
|
| 3680 |
+
)");
|
| 3681 |
+
|
| 3682 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
|
| 3683 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
|
| 3684 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 3685 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 3686 |
+
LINES TERMINATED BY \"\r\n\"
|
| 3687 |
+
IGNORE 1 LINES ");
|
| 3688 |
+
|
| 3689 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
|
| 3690 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('ean_codes_temp')."
|
| 3691 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes'));
|
| 3692 |
+
|
| 3693 |
+
$this->_LOG("Finish parse ".FILE_EANCODES);
|
| 3694 |
+
}else{
|
| 3695 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 3696 |
+
}
|
| 3697 |
+
$this->_LOG(' ');
|
| 3698 |
+
}
|
| 3699 |
+
|
| 3700 |
+
#################################################################################################
|
| 3701 |
+
|
| 3702 |
+
function ParseManufacturers(){
|
| 3703 |
+
|
| 3704 |
+
$parse_file=$this->varDir.FILE_MANUFACTURERS;
|
| 3705 |
+
if(filesize($parse_file)){
|
| 3706 |
+
$this->_LOG("Start parse ".FILE_MANUFACTURERS);
|
| 3707 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp'));
|
| 3708 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."(
|
| 3709 |
+
sinch_manufacturer_id int(11),
|
| 3710 |
+
manufacturer_name varchar(255),
|
| 3711 |
+
manufacturers_image varchar(255),
|
| 3712 |
+
shop_option_id int(11),
|
| 3713 |
+
KEY(sinch_manufacturer_id),
|
| 3714 |
+
KEY(shop_option_id),
|
| 3715 |
+
KEY(manufacturer_name)
|
| 3716 |
+
)");
|
| 3717 |
+
|
| 3718 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
|
| 3719 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
|
| 3720 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 3721 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 3722 |
+
LINES TERMINATED BY \"\r\n\"
|
| 3723 |
+
IGNORE 1 LINES ");
|
| 3724 |
+
|
| 3725 |
+
$q="DELETE aov
|
| 3726 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
|
| 3727 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
|
| 3728 |
+
ON ao.option_id=aov.option_id left
|
| 3729 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
|
| 3730 |
+
ON aov.value=mt.manufacturer_name
|
| 3731 |
+
WHERE
|
| 3732 |
+
ao.attribute_id=".$this->attributes['manufacturer']." AND
|
| 3733 |
+
mt.manufacturer_name is null";
|
| 3734 |
+
$this->db_do($q);
|
| 3735 |
+
|
| 3736 |
+
$q="DELETE ao
|
| 3737 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
|
| 3738 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
|
| 3739 |
+
ON ao.option_id=aov.option_id
|
| 3740 |
+
WHERE
|
| 3741 |
+
attribute_id=".$this->attributes['manufacturer']." AND
|
| 3742 |
+
aov.option_id is null";
|
| 3743 |
+
$this->db_do($q);
|
| 3744 |
+
|
| 3745 |
+
$q="SELECT
|
| 3746 |
+
m.sinch_manufacturer_id,
|
| 3747 |
+
m.manufacturer_name,
|
| 3748 |
+
m.manufacturers_image
|
| 3749 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." m
|
| 3750 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
|
| 3751 |
+
ON m.manufacturer_name=aov.value
|
| 3752 |
+
WHERE aov.value IS NULL";
|
| 3753 |
+
$quer=$this->db_do($q);
|
| 3754 |
+
|
| 3755 |
+
while($row=mysql_fetch_array($quer)){
|
| 3756 |
+
$q0="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
|
| 3757 |
+
(attribute_id)
|
| 3758 |
+
VALUES(".$this->attributes['manufacturer'].")";
|
| 3759 |
+
$quer0=$this->db_do($q0);
|
| 3760 |
+
|
| 3761 |
+
$q2="INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')."(
|
| 3762 |
+
option_id,
|
| 3763 |
+
value
|
| 3764 |
+
)(
|
| 3765 |
+
SELECT
|
| 3766 |
+
max(option_id) as option_id,
|
| 3767 |
+
"."'".mysql_real_escape_string($row['manufacturer_name'])."'
|
| 3768 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')."
|
| 3769 |
+
WHERE attribute_id=".$this->attributes['manufacturer']."
|
| 3770 |
+
)
|
| 3771 |
+
";
|
| 3772 |
+
$quer2=$this->db_do($q2);
|
| 3773 |
+
// $option['attribute_id'] = $this->attributes['manufacturer'];
|
| 3774 |
+
// $option['value'][$row['sinch_manufacturer_id']][0] = $row['manufacturer_name'];
|
| 3775 |
+
|
| 3776 |
+
}
|
| 3777 |
+
|
| 3778 |
+
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')." mt
|
| 3779 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
|
| 3780 |
+
ON mt.manufacturer_name=aov.value
|
| 3781 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')." ao
|
| 3782 |
+
ON ao.option_id=aov.option_id
|
| 3783 |
+
SET mt.shop_option_id=aov.option_id
|
| 3784 |
+
WHERE ao.attribute_id=".$this->attributes['manufacturer'];
|
| 3785 |
+
$this->db_do($q);
|
| 3786 |
+
|
| 3787 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
|
| 3788 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('manufacturers_temp')."
|
| 3789 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers'));
|
| 3790 |
+
$this->_LOG("Finish parse ".FILE_MANUFACTURERS);
|
| 3791 |
+
}else{
|
| 3792 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 3793 |
+
}
|
| 3794 |
+
$this->_LOG(' ');
|
| 3795 |
+
}
|
| 3796 |
+
|
| 3797 |
+
#################################################################################################
|
| 3798 |
+
|
| 3799 |
+
function ParseProductFeatures(){
|
| 3800 |
+
|
| 3801 |
+
$parse_file=$this->varDir.FILE_PRODUCT_FEATURES;
|
| 3802 |
+
if(filesize($parse_file) || $this->_ignore_product_features){
|
| 3803 |
+
$this->_LOG("Start parse ".FILE_PRODUCT_FEATURES);
|
| 3804 |
+
|
| 3805 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('product_features_temp'));
|
| 3806 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."(
|
| 3807 |
+
product_feature_id int(11),
|
| 3808 |
+
sinch_product_id int(11),
|
| 3809 |
+
restricted_value_id int(11),
|
| 3810 |
+
KEY(sinch_product_id),
|
| 3811 |
+
KEY(restricted_value_id)
|
| 3812 |
+
)
|
| 3813 |
+
");
|
| 3814 |
+
if(!$this->_ignore_product_features){
|
| 3815 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
|
| 3816 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
|
| 3817 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 3818 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 3819 |
+
LINES TERMINATED BY \"\r\n\"
|
| 3820 |
+
IGNORE 1 LINES ");
|
| 3821 |
+
}
|
| 3822 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
|
| 3823 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('product_features_temp')."
|
| 3824 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features'));
|
| 3825 |
+
|
| 3826 |
+
$this->_LOG("Finish parse ".FILE_PRODUCT_FEATURES);
|
| 3827 |
+
}else{
|
| 3828 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 3829 |
+
}
|
| 3830 |
+
$this->_LOG(" ");
|
| 3831 |
+
}
|
| 3832 |
+
|
| 3833 |
+
#################################################################################################
|
| 3834 |
+
|
| 3835 |
+
function ParseProducts($coincidence){
|
| 3836 |
+
echo("\nParseProducts 2\n");
|
| 3837 |
+
$parse_file=$this->varDir.FILE_PRODUCTS;
|
| 3838 |
+
if(filesize($parse_file)){
|
| 3839 |
+
$this->_LOG("Start parse ".FILE_PRODUCTS);
|
| 3840 |
+
|
| 3841 |
+
$file_handle_from = fopen($parse_file, "r");
|
| 3842 |
+
unlink($parse_file.".conv");
|
| 3843 |
+
$file_handle_to = fopen($parse_file.".conv", "w");
|
| 3844 |
+
while (!feof($file_handle_from)) {
|
| 3845 |
+
$line = fgets($file_handle_from);
|
| 3846 |
+
$line = $this->valid_utf($line);
|
| 3847 |
+
fwrite($file_handle_to, $line);
|
| 3848 |
+
}
|
| 3849 |
+
fclose($file_handle_from);
|
| 3850 |
+
fclose($file_handle_to);
|
| 3851 |
+
echo("\nParseProducts 2\n");
|
| 3852 |
+
|
| 3853 |
+
// $prod_file_str = file_get_contents($parse_file);
|
| 3854 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
|
| 3855 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."(
|
| 3856 |
+
store_category_product_id int(11),
|
| 3857 |
+
store_product_id int(11),
|
| 3858 |
+
sinch_product_id int(11),
|
| 3859 |
+
product_sku varchar(255),
|
| 3860 |
+
product_name varchar(255),
|
| 3861 |
+
sinch_manufacturer_id int(11),
|
| 3862 |
+
store_category_id int(11),
|
| 3863 |
+
main_image_url varchar(255),
|
| 3864 |
+
thumb_image_url varchar(255),
|
| 3865 |
+
specifications text,
|
| 3866 |
+
description text,
|
| 3867 |
+
search_cache text,
|
| 3868 |
+
spec_characte_u_count int(11),
|
| 3869 |
+
description_type varchar(50),
|
| 3870 |
+
medium_image_url varchar(255),
|
| 3871 |
+
products_date_added datetime default NULL,
|
| 3872 |
+
products_last_modified datetime default NULL,
|
| 3873 |
+
availability_id_in_stock int(11) default '1',
|
| 3874 |
+
availability_id_out_of_stock int(11) default '2',
|
| 3875 |
+
products_locate varchar(30) default NULL,
|
| 3876 |
+
products_ordered int(11) NOT NULL default '0',
|
| 3877 |
+
products_url varchar(255) default NULL,
|
| 3878 |
+
products_viewed int(5) default '0',
|
| 3879 |
+
products_seo_url varchar(100) NOT NULL,
|
| 3880 |
+
manufacturer_name varchar(255) default NULL,
|
| 3881 |
+
KEY(store_category_product_id),
|
| 3882 |
+
KEY(store_product_id),
|
| 3883 |
+
KEY(sinch_manufacturer_id),
|
| 3884 |
+
KEY(store_category_id)
|
| 3885 |
+
)DEFAULT CHARSET=utf8
|
| 3886 |
+
");
|
| 3887 |
+
echo("\nParseProducts 3\n");
|
| 3888 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv'
|
| 3889 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 3890 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 3891 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 3892 |
+
LINES TERMINATED BY \"\r\n\"
|
| 3893 |
+
IGNORE 1 LINES ");
|
| 3894 |
+
echo("\nParseProducts 4\n");
|
| 3895 |
+
$this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 3896 |
+
CONVERT TO CHARACTER SET \"latin1\"");
|
| 3897 |
+
echo("\nParseProducts 5\n");
|
| 3898 |
+
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 3899 |
+
SET products_date_added=now(), products_last_modified=now()");
|
| 3900 |
+
echo("\nParseProducts 6\n");
|
| 3901 |
+
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 3902 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." m
|
| 3903 |
+
ON p.sinch_manufacturer_id=m.sinch_manufacturer_id
|
| 3904 |
+
SET p.manufacturer_name=m.manufacturer_name");
|
| 3905 |
+
echo("\nParseProducts 7\n");
|
| 3906 |
+
if($this->current_import_status_statistic_id){
|
| 3907 |
+
$res = $this->db_do("SELECT COUNT(*) AS cnt
|
| 3908 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp'));
|
| 3909 |
+
$row = mysql_fetch_assoc($res);
|
| 3910 |
+
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
| 3911 |
+
SET number_of_products=".$row['cnt']."
|
| 3912 |
+
WHERE id=".$this->current_import_status_statistic_id);
|
| 3913 |
+
}
|
| 3914 |
+
echo("\nParseProducts 8\n");
|
| 3915 |
+
$this->addProductsWebsite();
|
| 3916 |
+
$this->mapSinchProducts();
|
| 3917 |
+
echo("\nParseProducts 9\n");
|
| 3918 |
+
|
| 3919 |
+
|
| 3920 |
+
if (count($coincidence) == -1)
|
| 3921 |
+
{
|
| 3922 |
+
$this->replaceMagentoProducts();
|
| 3923 |
+
}
|
| 3924 |
+
else
|
| 3925 |
+
{
|
| 3926 |
+
$this->replaceMagentoProductsMultistore($coincidence);
|
| 3927 |
+
}
|
| 3928 |
+
echo("\nParseProducts 10\n");
|
| 3929 |
+
|
| 3930 |
+
|
| 3931 |
+
$this->mapSinchProducts();
|
| 3932 |
+
$this->addManufacturer_attribute();
|
| 3933 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
|
| 3934 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 3935 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products'));
|
| 3936 |
+
$this->_LOG("Finish parse ".FILE_PRODUCTS);
|
| 3937 |
+
}else{
|
| 3938 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 3939 |
+
}
|
| 3940 |
+
$this->_LOG(" ");
|
| 3941 |
+
echo("\nParseProducts 11\n");
|
| 3942 |
+
}
|
| 3943 |
+
|
| 3944 |
+
#################################################################################################
|
| 3945 |
+
|
| 3946 |
+
function ParseRelatedProducts(){
|
| 3947 |
+
|
| 3948 |
+
$parse_file=$this->varDir.FILE_RELATED_PRODUCTS;
|
| 3949 |
+
if(filesize($parse_file) || $this->_ignore_product_related){
|
| 3950 |
+
$this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
|
| 3951 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('related_products_temp'));
|
| 3952 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."(
|
| 3953 |
+
sinch_product_id int(11),
|
| 3954 |
+
related_sinch_product_id int(11),
|
| 3955 |
+
store_product_id int(11) default null,
|
| 3956 |
+
store_related_product_id int(11) default null,
|
| 3957 |
+
entity_id int(11),
|
| 3958 |
+
related_entity_id int(11),
|
| 3959 |
+
KEY(sinch_product_id),
|
| 3960 |
+
KEY(related_sinch_product_id),
|
| 3961 |
+
KEY(store_product_id)
|
| 3962 |
+
)DEFAULT CHARSET=utf8");
|
| 3963 |
+
if(!$this->_ignore_product_related){
|
| 3964 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
|
| 3965 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
|
| 3966 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 3967 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 3968 |
+
LINES TERMINATED BY \"\r\n\"
|
| 3969 |
+
IGNORE 1 LINES ");
|
| 3970 |
+
}
|
| 3971 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
|
| 3972 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('related_products_temp')."
|
| 3973 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products'));
|
| 3974 |
+
|
| 3975 |
+
$this->_LOG("Finish parse ".FILE_RELATED_PRODUCTS);
|
| 3976 |
+
}else{
|
| 3977 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 3978 |
+
}
|
| 3979 |
+
$this->_LOG(" ");
|
| 3980 |
+
}
|
| 3981 |
+
|
| 3982 |
+
#################################################################################################
|
| 3983 |
+
|
| 3984 |
+
function ParseRestrictedValues(){
|
| 3985 |
+
|
| 3986 |
+
$parse_file=$this->varDir.FILE_RESTRICTED_VALUES;
|
| 3987 |
+
if(filesize($parse_file) || $this->_ignore_restricted_values){
|
| 3988 |
+
$this->_LOG("Start parse ".FILE_RESTRICTED_VALUES);
|
| 3989 |
+
$file_handle_from = fopen($parse_file, "r");
|
| 3990 |
+
unlink($parse_file.".conv");
|
| 3991 |
+
$file_handle_to = fopen($parse_file.".conv", "w");
|
| 3992 |
+
while (!feof($file_handle_from)) {
|
| 3993 |
+
$line = fgets($file_handle_from);
|
| 3994 |
+
$line = $this->valid_utf($line);
|
| 3995 |
+
fwrite($file_handle_to, $line);
|
| 3996 |
+
}
|
| 3997 |
+
fclose($file_handle_from);
|
| 3998 |
+
fclose($file_handle_to);
|
| 3999 |
+
|
| 4000 |
+
|
| 4001 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp'));
|
| 4002 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')." (
|
| 4003 |
+
restricted_value_id int(11),
|
| 4004 |
+
category_feature_id int(11),
|
| 4005 |
+
text text,
|
| 4006 |
+
display_order_number int(11),
|
| 4007 |
+
KEY(restricted_value_id),
|
| 4008 |
+
KEY(category_feature_id)
|
| 4009 |
+
)");
|
| 4010 |
+
if(!$this->_ignore_restricted_values){
|
| 4011 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file.".conv'
|
| 4012 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
|
| 4013 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 4014 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 4015 |
+
LINES TERMINATED BY \"\r\n\"
|
| 4016 |
+
IGNORE 1 LINES ");
|
| 4017 |
+
}
|
| 4018 |
+
$this->db_do("ALTER TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
|
| 4019 |
+
CONVERT TO CHARACTER SET \"latin1\"");
|
| 4020 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
|
| 4021 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('restricted_values_temp')."
|
| 4022 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values'));
|
| 4023 |
+
|
| 4024 |
+
$this->_LOG("Finish parse ".FILE_RESTRICTED_VALUES);
|
| 4025 |
+
}else{
|
| 4026 |
+
$this->_LOG("Wrong file ".$parse_file);
|
| 4027 |
+
}
|
| 4028 |
+
$this->_LOG(" ");
|
| 4029 |
+
}
|
| 4030 |
+
|
| 4031 |
+
#################################################################################################
|
| 4032 |
+
|
| 4033 |
+
function ParseStockAndPrices(){
|
| 4034 |
+
|
| 4035 |
+
$parse_file=$this->varDir.FILE_STOCK_AND_PRICES;
|
| 4036 |
+
if(filesize($parse_file)){
|
| 4037 |
+
$this->_LOG("Start parse ".FILE_RELATED_PRODUCTS);
|
| 4038 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp'));
|
| 4039 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." (
|
| 4040 |
+
store_product_id int(11),
|
| 4041 |
+
stock int(11),
|
| 4042 |
+
price decimal(15,4),
|
| 4043 |
+
cost decimal(15,4),
|
| 4044 |
+
distributor_id int(11),
|
| 4045 |
+
KEY(store_product_id),
|
| 4046 |
+
KEY(distributor_id)
|
| 4047 |
+
)");
|
| 4048 |
+
|
| 4049 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
|
| 4050 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
|
| 4051 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 4052 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 4053 |
+
LINES TERMINATED BY \"\r\n\"
|
| 4054 |
+
IGNORE 1 LINES ");
|
| 4055 |
+
|
| 4056 |
+
$this->replaceMagentoProductsStockPrice();
|
| 4057 |
+
|
| 4058 |
+
$res = $this->db_do("SELECT count(*) as cnt
|
| 4059 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4060 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
|
| 4061 |
+
ON a.store_product_id=b.store_product_id");
|
| 4062 |
+
$row = mysql_fetch_assoc($res);
|
| 4063 |
+
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
| 4064 |
+
SET number_of_products=".$row['cnt']."
|
| 4065 |
+
WHERE id=".$this->current_import_status_statistic_id);
|
| 4066 |
+
|
| 4067 |
+
$this->addWeight();
|
| 4068 |
+
|
| 4069 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
|
| 4070 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')."
|
| 4071 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_stock_and_prices'));
|
| 4072 |
+
|
| 4073 |
+
$this->_LOG("Finish parse".FILE_RELATED_PRODUCTS);
|
| 4074 |
+
}else{
|
| 4075 |
+
$this->_LOG("Wrong file".$parse_file);
|
| 4076 |
+
}
|
| 4077 |
+
$this->_LOG(" ");
|
| 4078 |
+
}
|
| 4079 |
+
|
| 4080 |
+
#################################################################################################
|
| 4081 |
+
|
| 4082 |
+
function ParseProductsPicturesGallery(){
|
| 4083 |
+
|
| 4084 |
+
$parse_file=$this->varDir.FILE_PRODUCTS_PICTURES_GALLERY;
|
| 4085 |
+
if(filesize($parse_file)){
|
| 4086 |
+
$this->_LOG("Start parse ".FILE_PRODUCTS_PICTURES_GALLERY);
|
| 4087 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp'));
|
| 4088 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." (
|
| 4089 |
+
sinch_product_id int(11),
|
| 4090 |
+
image_url varchar(255),
|
| 4091 |
+
thumb_image_url varchar(255),
|
| 4092 |
+
store_product_id int(11),
|
| 4093 |
+
key(sinch_product_id),
|
| 4094 |
+
key(store_product_id)
|
| 4095 |
+
)");
|
| 4096 |
+
|
| 4097 |
+
$this->db_do("LOAD DATA LOCAL INFILE '".$parse_file."'
|
| 4098 |
+
INTO TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
|
| 4099 |
+
FIELDS TERMINATED BY '".$this->field_terminated_char."'
|
| 4100 |
+
OPTIONALLY ENCLOSED BY '\"'
|
| 4101 |
+
LINES TERMINATED BY \"\r\n\"
|
| 4102 |
+
IGNORE 1 LINES ");
|
| 4103 |
+
|
| 4104 |
+
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')." ppgt
|
| 4105 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
|
| 4106 |
+
ON ppgt.sinch_product_id=sp.sinch_product_id
|
| 4107 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4108 |
+
ON sp.store_product_id=cpe.store_product_id
|
| 4109 |
+
SET ppgt.store_product_id=sp.store_product_id");
|
| 4110 |
+
|
| 4111 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
|
| 4112 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('products_pictures_gallery_temp')."
|
| 4113 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery'));
|
| 4114 |
+
|
| 4115 |
+
$this->_LOG("Finish parse".FILE_PRODUCTS_PICTURES_GALLERY);
|
| 4116 |
+
}else{
|
| 4117 |
+
$this->_LOG("Wrong file".$parse_file);
|
| 4118 |
+
}
|
| 4119 |
+
$this->_LOG(" ");
|
| 4120 |
+
|
| 4121 |
+
}
|
| 4122 |
+
|
| 4123 |
+
|
| 4124 |
+
|
| 4125 |
+
#################################################################################################
|
| 4126 |
+
public function mapSinchProducts(){
|
| 4127 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
|
| 4128 |
+
$this->db_do("CREATE TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
|
| 4129 |
+
entity_id int(11) unsigned NOT NULL,
|
| 4130 |
+
manufacturer_option_id int(11),
|
| 4131 |
+
manufacturer_name varchar(255),
|
| 4132 |
+
shop_store_product_id int(11),
|
| 4133 |
+
shop_sinch_product_id int(11),
|
| 4134 |
+
sku varchar(64) default NULL,
|
| 4135 |
+
store_category_product_id int(11),
|
| 4136 |
+
store_product_id int(11),
|
| 4137 |
+
sinch_product_id int(11),
|
| 4138 |
+
product_sku varchar(255),
|
| 4139 |
+
sinch_manufacturer_id int(11),
|
| 4140 |
+
sinch_manufacturer_name varchar(255),
|
| 4141 |
+
KEY entity_id (entity_id),
|
| 4142 |
+
KEY manufacturer_option_id (manufacturer_option_id),
|
| 4143 |
+
KEY manufacturer_name (manufacturer_name),
|
| 4144 |
+
KEY store_product_id (store_product_id),
|
| 4145 |
+
KEY sinch_product_id (sinch_product_id),
|
| 4146 |
+
KEY sku (sku),
|
| 4147 |
+
UNIQUE KEY(entity_id)
|
| 4148 |
+
)
|
| 4149 |
+
");
|
| 4150 |
+
$this->db_do("CREATE TABLE IF NOT EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
|
| 4151 |
+
LIKE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp'));
|
| 4152 |
+
$result = $this->db_do("
|
| 4153 |
+
INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." (
|
| 4154 |
+
entity_id,
|
| 4155 |
+
sku,
|
| 4156 |
+
shop_store_product_id,
|
| 4157 |
+
shop_sinch_product_id
|
| 4158 |
+
)(SELECT
|
| 4159 |
+
entity_id,
|
| 4160 |
+
sku,
|
| 4161 |
+
store_product_id,
|
| 4162 |
+
sinch_product_id
|
| 4163 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')."
|
| 4164 |
+
)
|
| 4165 |
+
");
|
| 4166 |
+
|
| 4167 |
+
$this->addManufacturers(1);
|
| 4168 |
+
|
| 4169 |
+
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
|
| 4170 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." cpie
|
| 4171 |
+
ON pmt.entity_id=cpie.entity_id
|
| 4172 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')." aov
|
| 4173 |
+
ON cpie.value=aov.option_id
|
| 4174 |
+
SET
|
| 4175 |
+
manufacturer_option_id=cpie.value,
|
| 4176 |
+
manufacturer_name=aov.value
|
| 4177 |
+
WHERE cpie.attribute_id=".$this->attributes['manufacturer'];
|
| 4178 |
+
$this->db_do($q);
|
| 4179 |
+
|
| 4180 |
+
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
|
| 4181 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 4182 |
+
ON pmt.sku=p.product_sku
|
| 4183 |
+
SET
|
| 4184 |
+
pmt.store_category_product_id=p.store_category_product_id,
|
| 4185 |
+
pmt.store_product_id=p.store_product_id,
|
| 4186 |
+
pmt.sinch_product_id=p.sinch_product_id,
|
| 4187 |
+
pmt.product_sku=p.product_sku,
|
| 4188 |
+
pmt.sinch_manufacturer_id=p.sinch_manufacturer_id,
|
| 4189 |
+
pmt.sinch_manufacturer_name=p.manufacturer_name";
|
| 4190 |
+
|
| 4191 |
+
$this->db_do($q);
|
| 4192 |
+
|
| 4193 |
+
$q="UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4194 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')." pmt
|
| 4195 |
+
ON cpe.entity_id=pmt.entity_id
|
| 4196 |
+
SET cpe.store_product_id=pmt.store_product_id,
|
| 4197 |
+
cpe.sinch_product_id=pmt.sinch_product_id
|
| 4198 |
+
WHERE
|
| 4199 |
+
cpe.sinch_product_id IS NULL
|
| 4200 |
+
AND pmt.sinch_product_id IS NOT NULL
|
| 4201 |
+
AND cpe.store_product_id IS NULL
|
| 4202 |
+
AND pmt.store_product_id IS NOT NULL";
|
| 4203 |
+
$this->db_do($q);
|
| 4204 |
+
|
| 4205 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
|
| 4206 |
+
$this->db_do("RENAME TABLE ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping_temp')."
|
| 4207 |
+
TO ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping'));
|
| 4208 |
+
}
|
| 4209 |
+
#################################################################################################
|
| 4210 |
+
public function addProductsWebsite (){
|
| 4211 |
+
$this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('products_website_temp'));
|
| 4212 |
+
// TEMPORARY
|
| 4213 |
+
$this->db_do("
|
| 4214 |
+
CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('products_website_temp')."` (
|
| 4215 |
+
`id` int(10) unsigned NOT NULL auto_increment,
|
| 4216 |
+
store_product_id int(11),
|
| 4217 |
+
sinch_product_id int(11),
|
| 4218 |
+
`website` int(11) default NULL,
|
| 4219 |
+
`website_id` int(11) default NULL,
|
| 4220 |
+
PRIMARY KEY (`id`),
|
| 4221 |
+
KEY store_product_id (`store_product_id`)
|
| 4222 |
+
)
|
| 4223 |
+
");
|
| 4224 |
+
$result = $this->db_do("SELECT
|
| 4225 |
+
website_id,
|
| 4226 |
+
store_id as website
|
| 4227 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('core_store')."
|
| 4228 |
+
WHERE code!='admin'
|
| 4229 |
+
"); // where code!='admin' was adder for editing Featured products;
|
| 4230 |
+
while ($row = mysql_fetch_assoc($result)) {
|
| 4231 |
+
$sql = "INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." (
|
| 4232 |
+
store_product_id,
|
| 4233 |
+
sinch_product_id,
|
| 4234 |
+
website,
|
| 4235 |
+
website_id
|
| 4236 |
+
)(
|
| 4237 |
+
SELECT
|
| 4238 |
+
distinct
|
| 4239 |
+
store_product_id,
|
| 4240 |
+
sinch_product_id,
|
| 4241 |
+
{$row['website']},
|
| 4242 |
+
{$row['website_id']}
|
| 4243 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')."
|
| 4244 |
+
)";
|
| 4245 |
+
$result2 = $this->db_do($sql);
|
| 4246 |
+
}
|
| 4247 |
+
|
| 4248 |
+
|
| 4249 |
+
}
|
| 4250 |
+
|
| 4251 |
+
#################################################################################################
|
| 4252 |
+
public function replaceMagentoProducts() {
|
| 4253 |
+
|
| 4254 |
+
$connection = Mage::getModel('core/resource')->getConnection('core_write');
|
| 4255 |
+
|
| 4256 |
+
$result = $this->db_do("DELETE cpe
|
| 4257 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4258 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
|
| 4259 |
+
ON cpe.entity_id=pm.entity_id
|
| 4260 |
+
WHERE pm.shop_store_product_id IS NOT NULL
|
| 4261 |
+
AND pm.store_product_id IS NULL
|
| 4262 |
+
");
|
| 4263 |
+
|
| 4264 |
+
//Inserting new products and updating old others.
|
| 4265 |
+
$this->_getProductDefaulAttributeSetId();
|
| 4266 |
+
$result = $this->db_do("
|
| 4267 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." (
|
| 4268 |
+
entity_id,
|
| 4269 |
+
entity_type_id,
|
| 4270 |
+
attribute_set_id,
|
| 4271 |
+
type_id,
|
| 4272 |
+
sku,
|
| 4273 |
+
updated_at,
|
| 4274 |
+
has_options,
|
| 4275 |
+
store_product_id,
|
| 4276 |
+
sinch_product_id
|
| 4277 |
+
)(SELECT
|
| 4278 |
+
pm.entity_id,
|
| 4279 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4280 |
+
$this->defaultAttributeSetId,
|
| 4281 |
+
'simple',
|
| 4282 |
+
a.product_sku,
|
| 4283 |
+
NOW(),
|
| 4284 |
+
0,
|
| 4285 |
+
a.store_product_id,
|
| 4286 |
+
a.sinch_product_id
|
| 4287 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('products_temp')." a
|
| 4288 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
|
| 4289 |
+
ON a.store_product_id=pm.store_product_id
|
| 4290 |
+
AND a.sinch_product_id=pm.sinch_product_id
|
| 4291 |
+
)
|
| 4292 |
+
ON DUPLICATE KEY UPDATE
|
| 4293 |
+
sku= a.product_sku,
|
| 4294 |
+
store_product_id=a.store_product_id,
|
| 4295 |
+
sinch_product_id=a.sinch_product_id
|
| 4296 |
+
");
|
| 4297 |
+
// store_product_id=a.store_product_id,
|
| 4298 |
+
// sinch_product_id=a.sinch_product_id
|
| 4299 |
+
|
| 4300 |
+
//Set enabled
|
| 4301 |
+
$result = $this->db_do("DELETE cpei
|
| 4302 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." cpei
|
| 4303 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4304 |
+
ON cpei.entity_id=cpe.entity_id
|
| 4305 |
+
WHERE cpe.entity_id IS NULL");
|
| 4306 |
+
|
| 4307 |
+
$result = $this->db_do("
|
| 4308 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
|
| 4309 |
+
entity_type_id,
|
| 4310 |
+
attribute_id,
|
| 4311 |
+
store_id,
|
| 4312 |
+
entity_id,
|
| 4313 |
+
value
|
| 4314 |
+
)(
|
| 4315 |
+
SELECT
|
| 4316 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4317 |
+
". $this->_getProductAttributeId('status').",
|
| 4318 |
+
w.website,
|
| 4319 |
+
a.entity_id,
|
| 4320 |
+
1
|
| 4321 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4322 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4323 |
+
ON a.store_product_id=w.store_product_id
|
| 4324 |
+
)
|
| 4325 |
+
ON DUPLICATE KEY UPDATE
|
| 4326 |
+
value=1
|
| 4327 |
+
");
|
| 4328 |
+
// set status = 1 for all stores
|
| 4329 |
+
$result = $this->db_do("
|
| 4330 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
|
| 4331 |
+
entity_type_id,
|
| 4332 |
+
attribute_id,
|
| 4333 |
+
store_id,
|
| 4334 |
+
entity_id,
|
| 4335 |
+
value
|
| 4336 |
+
)(SELECT
|
| 4337 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4338 |
+
".$this->_getProductAttributeId('status').",
|
| 4339 |
+
0,
|
| 4340 |
+
a.entity_id,
|
| 4341 |
+
1
|
| 4342 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4343 |
+
)
|
| 4344 |
+
ON DUPLICATE KEY UPDATE
|
| 4345 |
+
value=1
|
| 4346 |
+
");
|
| 4347 |
+
|
| 4348 |
+
//Unifying products with categories.
|
| 4349 |
+
$result = $this->db_do("DELETE ccp
|
| 4350 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 4351 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4352 |
+
ON ccp.product_id=cpe.entity_id
|
| 4353 |
+
WHERE cpe.entity_id IS NULL");
|
| 4354 |
+
|
| 4355 |
+
echo("\n\n\nUPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 4356 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 4357 |
+
ON ccp.category_id=cce.entity_id
|
| 4358 |
+
SET ccp.category_id=".$this->_root_cat."
|
| 4359 |
+
WHERE cce.entity_id IS NULL");
|
| 4360 |
+
$result = $this->db_do("UPDATE IGNORE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 4361 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 4362 |
+
ON ccp.category_id=cce.entity_id
|
| 4363 |
+
SET ccp.category_id=".$this->_root_cat."
|
| 4364 |
+
WHERE cce.entity_id IS NULL");
|
| 4365 |
+
echo("\ndone\n");
|
| 4366 |
+
|
| 4367 |
+
|
| 4368 |
+
echo("\n\n\nDELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 4369 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 4370 |
+
ON ccp.category_id=cce.entity_id
|
| 4371 |
+
WHERE cce.entity_id IS NULL");
|
| 4372 |
+
$result = $this->db_do("DELETE ccp FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 4373 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cce
|
| 4374 |
+
ON ccp.category_id=cce.entity_id
|
| 4375 |
+
WHERE cce.entity_id IS NULL");
|
| 4376 |
+
echo("\ndone\n");
|
| 4377 |
+
|
| 4378 |
+
|
| 4379 |
+
$this->db_do(" DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp");
|
| 4380 |
+
// TEMPORARY
|
| 4381 |
+
$this->db_do("
|
| 4382 |
+
CREATE TABLE `".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp` (
|
| 4383 |
+
`category_id` int(10) unsigned NOT NULL default '0',
|
| 4384 |
+
`product_id` int(10) unsigned NOT NULL default '0',
|
| 4385 |
+
`store_product_id` int(10) NOT NULL default '0',
|
| 4386 |
+
`store_category_id` int(10) NOT NULL default '0',
|
| 4387 |
+
`new_category_id` int(10) NOT NULL default '0',
|
| 4388 |
+
UNIQUE KEY `UNQ_CATEGORY_PRODUCT` (`category_id`,`product_id`),
|
| 4389 |
+
KEY `CATALOG_CATEGORY_PRODUCT_CATEGORY` (`category_id`),
|
| 4390 |
+
KEY `CATALOG_CATEGORY_PRODUCT_PRODUCT` (`product_id`),
|
| 4391 |
+
KEY `CATALOG_NEW_CATEGORY_PRODUCT_CATEGORY` (`new_category_id`)
|
| 4392 |
+
)
|
| 4393 |
+
|
| 4394 |
+
");
|
| 4395 |
+
|
| 4396 |
+
$result = $this->db_do("
|
| 4397 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp (
|
| 4398 |
+
category_id,
|
| 4399 |
+
product_id,
|
| 4400 |
+
store_product_id
|
| 4401 |
+
)(SELECT
|
| 4402 |
+
ccp.category_id,
|
| 4403 |
+
ccp.product_id,
|
| 4404 |
+
cpe.store_product_id
|
| 4405 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 4406 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4407 |
+
ON ccp.product_id=cpe.entity_id
|
| 4408 |
+
WHERE store_product_id is not null
|
| 4409 |
+
)
|
| 4410 |
+
");
|
| 4411 |
+
|
| 4412 |
+
$result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
|
| 4413 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 4414 |
+
ON ccpfd.store_product_id=p.store_product_id
|
| 4415 |
+
SET ccpfd.store_category_id=p.store_category_id
|
| 4416 |
+
WHERE ccpfd.store_product_id!=0
|
| 4417 |
+
");
|
| 4418 |
+
|
| 4419 |
+
$result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
|
| 4420 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 4421 |
+
ON ccpfd.store_category_id=scm.store_category_id
|
| 4422 |
+
SET ccpfd.new_category_id=scm.shop_entity_id
|
| 4423 |
+
WHERE ccpfd.store_category_id!=0
|
| 4424 |
+
");
|
| 4425 |
+
|
| 4426 |
+
$result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp
|
| 4427 |
+
WHERE category_id=new_category_id");
|
| 4428 |
+
|
| 4429 |
+
$result = $this->db_do("
|
| 4430 |
+
DELETE ccp
|
| 4431 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." ccp
|
| 4432 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')."_for_delete_temp ccpfd
|
| 4433 |
+
ON ccp.product_id=ccpfd.product_id
|
| 4434 |
+
AND ccp.category_id=ccpfd.category_id
|
| 4435 |
+
");
|
| 4436 |
+
|
| 4437 |
+
$result = $this->db_do("
|
| 4438 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." (
|
| 4439 |
+
category_id,
|
| 4440 |
+
product_id
|
| 4441 |
+
)(SELECT
|
| 4442 |
+
scm.shop_entity_id,
|
| 4443 |
+
cpe.entity_id
|
| 4444 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4445 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 4446 |
+
ON cpe.store_product_id=p.store_product_id
|
| 4447 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 4448 |
+
ON p.store_category_id=scm.store_category_id
|
| 4449 |
+
)
|
| 4450 |
+
ON DUPLICATE KEY UPDATE
|
| 4451 |
+
product_id = cpe.entity_id
|
| 4452 |
+
");
|
| 4453 |
+
|
| 4454 |
+
//Indexing products and categories in the shop
|
| 4455 |
+
$result = $this->db_do("DELETE ccpi
|
| 4456 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." ccpi
|
| 4457 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4458 |
+
ON ccpi.product_id=cpe.entity_id
|
| 4459 |
+
WHERE cpe.entity_id IS NULL");
|
| 4460 |
+
|
| 4461 |
+
$result = $this->db_do("
|
| 4462 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
|
| 4463 |
+
category_id,
|
| 4464 |
+
product_id,
|
| 4465 |
+
position,
|
| 4466 |
+
is_parent,
|
| 4467 |
+
store_id,
|
| 4468 |
+
visibility
|
| 4469 |
+
)(
|
| 4470 |
+
SELECT
|
| 4471 |
+
a.category_id,
|
| 4472 |
+
a.product_id,
|
| 4473 |
+
a.position,
|
| 4474 |
+
1,
|
| 4475 |
+
b.store_id,
|
| 4476 |
+
4
|
| 4477 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
|
| 4478 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
|
| 4479 |
+
)
|
| 4480 |
+
ON DUPLICATE KEY UPDATE
|
| 4481 |
+
visibility = 4
|
| 4482 |
+
");
|
| 4483 |
+
|
| 4484 |
+
$result = $this->db_do("
|
| 4485 |
+
INSERT ignore INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')." (
|
| 4486 |
+
category_id,
|
| 4487 |
+
product_id,
|
| 4488 |
+
position,
|
| 4489 |
+
is_parent,
|
| 4490 |
+
store_id,
|
| 4491 |
+
visibility
|
| 4492 |
+
)(
|
| 4493 |
+
SELECT
|
| 4494 |
+
".$this->_root_cat.",
|
| 4495 |
+
a.product_id,
|
| 4496 |
+
a.position,
|
| 4497 |
+
1,
|
| 4498 |
+
b.store_id,
|
| 4499 |
+
4
|
| 4500 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." a
|
| 4501 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." b
|
| 4502 |
+
)
|
| 4503 |
+
ON DUPLICATE KEY UPDATE
|
| 4504 |
+
visibility = 4
|
| 4505 |
+
");
|
| 4506 |
+
|
| 4507 |
+
//Set product name for specific web sites
|
| 4508 |
+
$result = $this->db_do("DELETE cpev
|
| 4509 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." cpev
|
| 4510 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4511 |
+
ON cpev.entity_id=cpe.entity_id
|
| 4512 |
+
WHERE cpe.entity_id IS NULL");
|
| 4513 |
+
$result = $this->db_do("
|
| 4514 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 4515 |
+
entity_type_id,
|
| 4516 |
+
attribute_id,
|
| 4517 |
+
store_id,
|
| 4518 |
+
entity_id,
|
| 4519 |
+
value
|
| 4520 |
+
)(SELECT
|
| 4521 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4522 |
+
" . $this->_getProductAttributeId('name'). ",
|
| 4523 |
+
w.website,
|
| 4524 |
+
a.entity_id,
|
| 4525 |
+
b.product_name
|
| 4526 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4527 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4528 |
+
ON a.store_product_id= b.store_product_id
|
| 4529 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4530 |
+
ON a.store_product_id=w.store_product_id
|
| 4531 |
+
)
|
| 4532 |
+
ON DUPLICATE KEY UPDATE
|
| 4533 |
+
value = b.product_name
|
| 4534 |
+
");
|
| 4535 |
+
|
| 4536 |
+
// product name for all web sites
|
| 4537 |
+
$result = $this->db_do("
|
| 4538 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 4539 |
+
entity_type_id,
|
| 4540 |
+
attribute_id,
|
| 4541 |
+
store_id,
|
| 4542 |
+
entity_id,
|
| 4543 |
+
value
|
| 4544 |
+
)(
|
| 4545 |
+
SELECT
|
| 4546 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4547 |
+
" . $this->_getProductAttributeId('name'). ",
|
| 4548 |
+
0,
|
| 4549 |
+
a.entity_id,
|
| 4550 |
+
b.product_name
|
| 4551 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4552 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4553 |
+
ON a.store_product_id = b.store_product_id
|
| 4554 |
+
)
|
| 4555 |
+
ON DUPLICATE KEY UPDATE
|
| 4556 |
+
value = b.product_name
|
| 4557 |
+
");
|
| 4558 |
+
|
| 4559 |
+
$this->dropHTMLentities($this->_getProductEntityTypeId(), $this->_getProductAttributeId('name'));
|
| 4560 |
+
$this->addDescriptions();
|
| 4561 |
+
$this->addShortDescriptions();
|
| 4562 |
+
$this->addEAN();
|
| 4563 |
+
$this->addSpecification();
|
| 4564 |
+
$this->addManufacturers();
|
| 4565 |
+
|
| 4566 |
+
//Enabling product index.
|
| 4567 |
+
$result = $this->db_do("DELETE cpei
|
| 4568 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." cpei
|
| 4569 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4570 |
+
ON cpei.product_id=cpe.entity_id
|
| 4571 |
+
WHERE cpe.entity_id IS NULL");
|
| 4572 |
+
|
| 4573 |
+
$result = $this->db_do("
|
| 4574 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
|
| 4575 |
+
product_id,
|
| 4576 |
+
store_id,
|
| 4577 |
+
visibility
|
| 4578 |
+
)(
|
| 4579 |
+
SELECT
|
| 4580 |
+
a.entity_id,
|
| 4581 |
+
w.website,
|
| 4582 |
+
4
|
| 4583 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4584 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4585 |
+
ON a.store_product_id=w.store_product_id
|
| 4586 |
+
)
|
| 4587 |
+
ON DUPLICATE KEY UPDATE
|
| 4588 |
+
visibility = 4
|
| 4589 |
+
");
|
| 4590 |
+
$result = $this->db_do("
|
| 4591 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_enabled_index')." (
|
| 4592 |
+
product_id,
|
| 4593 |
+
store_id,
|
| 4594 |
+
visibility
|
| 4595 |
+
)(
|
| 4596 |
+
SELECT
|
| 4597 |
+
a.entity_id,
|
| 4598 |
+
0,
|
| 4599 |
+
4
|
| 4600 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4601 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4602 |
+
ON a.store_product_id=w.store_product_id
|
| 4603 |
+
)
|
| 4604 |
+
ON DUPLICATE KEY UPDATE
|
| 4605 |
+
visibility = 4
|
| 4606 |
+
");
|
| 4607 |
+
|
| 4608 |
+
|
| 4609 |
+
$result = $this->db_do("
|
| 4610 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
|
| 4611 |
+
entity_type_id,
|
| 4612 |
+
attribute_id,
|
| 4613 |
+
store_id,
|
| 4614 |
+
entity_id,
|
| 4615 |
+
value
|
| 4616 |
+
)(
|
| 4617 |
+
SELECT
|
| 4618 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4619 |
+
" . $this->_getProductAttributeId('visibility'). ",
|
| 4620 |
+
w.website,
|
| 4621 |
+
a.entity_id,
|
| 4622 |
+
4
|
| 4623 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4624 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4625 |
+
ON a.store_product_id=w.store_product_id
|
| 4626 |
+
)
|
| 4627 |
+
ON DUPLICATE KEY UPDATE
|
| 4628 |
+
value = 4
|
| 4629 |
+
");
|
| 4630 |
+
|
| 4631 |
+
$result = $this->db_do("
|
| 4632 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
|
| 4633 |
+
entity_type_id,
|
| 4634 |
+
attribute_id,
|
| 4635 |
+
store_id,
|
| 4636 |
+
entity_id,
|
| 4637 |
+
value
|
| 4638 |
+
)(
|
| 4639 |
+
SELECT
|
| 4640 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4641 |
+
" . $this->_getProductAttributeId('visibility'). ",
|
| 4642 |
+
0,
|
| 4643 |
+
a.entity_id,
|
| 4644 |
+
4
|
| 4645 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4646 |
+
)
|
| 4647 |
+
ON DUPLICATE KEY UPDATE
|
| 4648 |
+
value = 4
|
| 4649 |
+
");
|
| 4650 |
+
|
| 4651 |
+
$result = $this->db_do("DELETE cpw
|
| 4652 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." cpw
|
| 4653 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4654 |
+
ON cpw.product_id=cpe.entity_id
|
| 4655 |
+
WHERE cpe.entity_id IS NULL");
|
| 4656 |
+
|
| 4657 |
+
$result = $this->db_do("
|
| 4658 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." (
|
| 4659 |
+
product_id,
|
| 4660 |
+
website_id
|
| 4661 |
+
)(
|
| 4662 |
+
SELECT a.entity_id, w.website_id
|
| 4663 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4664 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4665 |
+
ON a.store_product_id=w.store_product_id
|
| 4666 |
+
)
|
| 4667 |
+
ON DUPLICATE KEY UPDATE
|
| 4668 |
+
product_id=a.entity_id,
|
| 4669 |
+
website_id=w.website_id
|
| 4670 |
+
");
|
| 4671 |
+
|
| 4672 |
+
// temporary disabled mart@bintime.com
|
| 4673 |
+
//$result = $this->db_do("
|
| 4674 |
+
// UPDATE catalog_category_entity_int a
|
| 4675 |
+
// SET a.value = 0
|
| 4676 |
+
// WHERE a.attribute_id = 32
|
| 4677 |
+
//");
|
| 4678 |
+
|
| 4679 |
+
|
| 4680 |
+
//Adding tax class "Taxable Goods"
|
| 4681 |
+
$result = $this->db_do("
|
| 4682 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
|
| 4683 |
+
entity_type_id,
|
| 4684 |
+
attribute_id,
|
| 4685 |
+
store_id,
|
| 4686 |
+
entity_id,
|
| 4687 |
+
value
|
| 4688 |
+
)(
|
| 4689 |
+
SELECT
|
| 4690 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4691 |
+
" . $this->_getProductAttributeId('tax_class_id'). ",
|
| 4692 |
+
w.website,
|
| 4693 |
+
a.entity_id,
|
| 4694 |
+
2
|
| 4695 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4696 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4697 |
+
ON a.store_product_id=w.store_product_id
|
| 4698 |
+
)
|
| 4699 |
+
ON DUPLICATE KEY UPDATE
|
| 4700 |
+
value = 2
|
| 4701 |
+
");
|
| 4702 |
+
$result = $this->db_do("
|
| 4703 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
|
| 4704 |
+
entity_type_id,
|
| 4705 |
+
attribute_id,
|
| 4706 |
+
store_id,
|
| 4707 |
+
entity_id,
|
| 4708 |
+
value
|
| 4709 |
+
)(
|
| 4710 |
+
SELECT
|
| 4711 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4712 |
+
" . $this->_getProductAttributeId('tax_class_id'). ",
|
| 4713 |
+
0,
|
| 4714 |
+
a.entity_id,
|
| 4715 |
+
2
|
| 4716 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4717 |
+
)
|
| 4718 |
+
ON DUPLICATE KEY UPDATE
|
| 4719 |
+
value = 2
|
| 4720 |
+
");
|
| 4721 |
+
|
| 4722 |
+
// Load url Image
|
| 4723 |
+
$result = $this->db_do("
|
| 4724 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 4725 |
+
entity_type_id,
|
| 4726 |
+
attribute_id,
|
| 4727 |
+
store_id,
|
| 4728 |
+
entity_id,
|
| 4729 |
+
value
|
| 4730 |
+
)(
|
| 4731 |
+
SELECT
|
| 4732 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4733 |
+
" . $this->_getProductAttributeId('image'). ",
|
| 4734 |
+
w.store_id,
|
| 4735 |
+
a.entity_id,
|
| 4736 |
+
b.main_image_url
|
| 4737 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4738 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
|
| 4739 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4740 |
+
ON a.store_product_id = b.store_product_id
|
| 4741 |
+
)
|
| 4742 |
+
ON DUPLICATE KEY UPDATE
|
| 4743 |
+
value = b.main_image_url
|
| 4744 |
+
");
|
| 4745 |
+
|
| 4746 |
+
|
| 4747 |
+
// image for specific web sites
|
| 4748 |
+
$result = $this->db_do("
|
| 4749 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 4750 |
+
entity_type_id,
|
| 4751 |
+
attribute_id,
|
| 4752 |
+
store_id,
|
| 4753 |
+
entity_id,
|
| 4754 |
+
value
|
| 4755 |
+
)(
|
| 4756 |
+
SELECT
|
| 4757 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4758 |
+
" . $this->_getProductAttributeId('image'). ",
|
| 4759 |
+
0,
|
| 4760 |
+
a.entity_id,
|
| 4761 |
+
b.main_image_url
|
| 4762 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4763 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4764 |
+
ON a.store_product_id = b.store_product_id
|
| 4765 |
+
)
|
| 4766 |
+
ON DUPLICATE KEY UPDATE
|
| 4767 |
+
value = b.main_image_url
|
| 4768 |
+
");
|
| 4769 |
+
|
| 4770 |
+
|
| 4771 |
+
// small_image for specific web sites
|
| 4772 |
+
$result = $this->db_do("
|
| 4773 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 4774 |
+
entity_type_id,
|
| 4775 |
+
attribute_id,
|
| 4776 |
+
store_id,
|
| 4777 |
+
entity_id,
|
| 4778 |
+
value
|
| 4779 |
+
)(
|
| 4780 |
+
SELECT
|
| 4781 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4782 |
+
" . $this->_getProductAttributeId('small_image'). ",
|
| 4783 |
+
w.store_id,
|
| 4784 |
+
a.entity_id,
|
| 4785 |
+
b.medium_image_url
|
| 4786 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4787 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
|
| 4788 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4789 |
+
ON a.store_product_id = b.store_product_id
|
| 4790 |
+
)
|
| 4791 |
+
ON DUPLICATE KEY UPDATE
|
| 4792 |
+
value = b.medium_image_url
|
| 4793 |
+
");
|
| 4794 |
+
|
| 4795 |
+
|
| 4796 |
+
// small_image for all web sites
|
| 4797 |
+
$result = $this->db_do("
|
| 4798 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 4799 |
+
entity_type_id,
|
| 4800 |
+
attribute_id,
|
| 4801 |
+
store_id,
|
| 4802 |
+
entity_id,
|
| 4803 |
+
value
|
| 4804 |
+
)(
|
| 4805 |
+
SELECT
|
| 4806 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4807 |
+
" . $this->_getProductAttributeId('small_image'). ",
|
| 4808 |
+
0,
|
| 4809 |
+
a.entity_id,
|
| 4810 |
+
b.medium_image_url
|
| 4811 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4812 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
|
| 4813 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4814 |
+
ON a.store_product_id = b.store_product_id
|
| 4815 |
+
)
|
| 4816 |
+
ON DUPLICATE KEY UPDATE
|
| 4817 |
+
value = b.medium_image_url
|
| 4818 |
+
");
|
| 4819 |
+
|
| 4820 |
+
|
| 4821 |
+
// thumbnail for specific web site
|
| 4822 |
+
$result = $this->db_do("
|
| 4823 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 4824 |
+
entity_type_id,
|
| 4825 |
+
attribute_id,
|
| 4826 |
+
store_id,
|
| 4827 |
+
entity_id,
|
| 4828 |
+
value
|
| 4829 |
+
)(
|
| 4830 |
+
SELECT
|
| 4831 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4832 |
+
" . $this->_getProductAttributeId('thumbnail'). ",
|
| 4833 |
+
w.store_id,
|
| 4834 |
+
a.entity_id,
|
| 4835 |
+
b.thumb_image_url
|
| 4836 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4837 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
|
| 4838 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4839 |
+
ON a.store_product_id = b.store_product_id
|
| 4840 |
+
)
|
| 4841 |
+
ON DUPLICATE KEY UPDATE
|
| 4842 |
+
value = b.thumb_image_url
|
| 4843 |
+
");
|
| 4844 |
+
|
| 4845 |
+
|
| 4846 |
+
// thumbnail for all web sites
|
| 4847 |
+
$result = $this->db_do("
|
| 4848 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 4849 |
+
entity_type_id,
|
| 4850 |
+
attribute_id,
|
| 4851 |
+
store_id,
|
| 4852 |
+
entity_id,
|
| 4853 |
+
value
|
| 4854 |
+
)(
|
| 4855 |
+
SELECT
|
| 4856 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4857 |
+
" . $this->_getProductAttributeId('thumbnail'). ",
|
| 4858 |
+
0,
|
| 4859 |
+
a.entity_id,
|
| 4860 |
+
b.thumb_image_url
|
| 4861 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4862 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
|
| 4863 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4864 |
+
ON a.store_product_id = b.store_product_id
|
| 4865 |
+
)
|
| 4866 |
+
ON DUPLICATE KEY UPDATE
|
| 4867 |
+
value = b.thumb_image_url
|
| 4868 |
+
|
| 4869 |
+
");
|
| 4870 |
+
|
| 4871 |
+
|
| 4872 |
+
//Refresh fulltext search
|
| 4873 |
+
$result = $this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp");
|
| 4874 |
+
$result = $this->db_do("CREATE TEMPORARY TABLE IF NOT EXISTS
|
| 4875 |
+
".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp
|
| 4876 |
+
LIKE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext'));
|
| 4877 |
+
|
| 4878 |
+
$result = $this->db_do("
|
| 4879 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
|
| 4880 |
+
product_id,
|
| 4881 |
+
store_id,
|
| 4882 |
+
data_index
|
| 4883 |
+
)(
|
| 4884 |
+
SELECT
|
| 4885 |
+
a.entity_id,
|
| 4886 |
+
w.website,
|
| 4887 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 4888 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4889 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4890 |
+
ON a.store_product_id=w.store_product_id
|
| 4891 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
|
| 4892 |
+
ON a.entity_id = b.product_id
|
| 4893 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
|
| 4894 |
+
ON b.category_id = c.entity_id
|
| 4895 |
+
AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
|
| 4896 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
|
| 4897 |
+
ON a.entity_id = e.entity_id
|
| 4898 |
+
AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
|
| 4899 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_website')." j
|
| 4900 |
+
ON a.entity_id = j.product_id
|
| 4901 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
|
| 4902 |
+
ON a.entity_id = f.store_product_id
|
| 4903 |
+
)
|
| 4904 |
+
ON DUPLICATE KEY UPDATE
|
| 4905 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 4906 |
+
");
|
| 4907 |
+
|
| 4908 |
+
$result = $this->db_do("
|
| 4909 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp (
|
| 4910 |
+
product_id,
|
| 4911 |
+
store_id,
|
| 4912 |
+
data_index
|
| 4913 |
+
)(
|
| 4914 |
+
SELECT
|
| 4915 |
+
a.entity_id,
|
| 4916 |
+
w.website,
|
| 4917 |
+
CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 4918 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4919 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4920 |
+
ON a.store_product_id=w.store_product_id
|
| 4921 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_product')." b
|
| 4922 |
+
ON a.entity_id = b.product_id
|
| 4923 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." c
|
| 4924 |
+
ON b.category_id = c.entity_id
|
| 4925 |
+
AND c.attribute_id = " . $this->_getCategoryAttributeId('name'). "
|
| 4926 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." e
|
| 4927 |
+
ON a.entity_id = e.entity_id
|
| 4928 |
+
AND e.attribute_id = " . $this->_getProductAttributeId('name'). "
|
| 4929 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." f
|
| 4930 |
+
ON a.entity_id = f.store_product_id
|
| 4931 |
+
)
|
| 4932 |
+
ON DUPLICATE KEY UPDATE
|
| 4933 |
+
data_index = CONCAT_WS(' ', a.sku, f.search_cache, c.value, e.value)
|
| 4934 |
+
");
|
| 4935 |
+
|
| 4936 |
+
$result = $this->db_do("DELETE cf
|
| 4937 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." cf
|
| 4938 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 4939 |
+
ON cf.product_id=cpe.entity_id
|
| 4940 |
+
WHERE cpe.entity_id is null");
|
| 4941 |
+
|
| 4942 |
+
$result = $this->db_do("
|
| 4943 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')." (
|
| 4944 |
+
product_id,
|
| 4945 |
+
store_id,
|
| 4946 |
+
data_index
|
| 4947 |
+
)(
|
| 4948 |
+
SELECT
|
| 4949 |
+
a.product_id,
|
| 4950 |
+
a.store_id,
|
| 4951 |
+
a.data_index
|
| 4952 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_fulltext')."_tmp a
|
| 4953 |
+
WHERE product_id = a.product_id
|
| 4954 |
+
)
|
| 4955 |
+
ON DUPLICATE KEY UPDATE
|
| 4956 |
+
data_index = a.data_index
|
| 4957 |
+
");
|
| 4958 |
+
|
| 4959 |
+
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalogsearch_query')." SET is_processed = 0");
|
| 4960 |
+
//INNER JOIN eav_attribute_option_value d ON a.vendor_id = d.option_id
|
| 4961 |
+
//TODO add something else
|
| 4962 |
+
|
| 4963 |
+
$this->addRelatedProducts();
|
| 4964 |
+
}
|
| 4965 |
+
|
| 4966 |
+
#################################################################################################
|
| 4967 |
+
function addDescriptions(){
|
| 4968 |
+
// product description for all web sites
|
| 4969 |
+
$result = $this->db_do("
|
| 4970 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
|
| 4971 |
+
entity_type_id,
|
| 4972 |
+
attribute_id,
|
| 4973 |
+
store_id,
|
| 4974 |
+
entity_id,
|
| 4975 |
+
value
|
| 4976 |
+
)(
|
| 4977 |
+
SELECT
|
| 4978 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 4979 |
+
" . $this->_getProductAttributeId('description'). ",
|
| 4980 |
+
w.website,
|
| 4981 |
+
a.entity_id,
|
| 4982 |
+
b.description
|
| 4983 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 4984 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 4985 |
+
ON a.store_product_id = b.store_product_id
|
| 4986 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 4987 |
+
ON a.store_product_id=w.store_product_id
|
| 4988 |
+
)
|
| 4989 |
+
ON DUPLICATE KEY UPDATE
|
| 4990 |
+
value = b.description
|
| 4991 |
+
");
|
| 4992 |
+
|
| 4993 |
+
// product description for all web sites
|
| 4994 |
+
$result = $this->db_do("
|
| 4995 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
|
| 4996 |
+
entity_type_id,
|
| 4997 |
+
attribute_id,
|
| 4998 |
+
store_id,
|
| 4999 |
+
entity_id,
|
| 5000 |
+
value
|
| 5001 |
+
)(
|
| 5002 |
+
SELECT
|
| 5003 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5004 |
+
" . $this->_getProductAttributeId('description'). ",
|
| 5005 |
+
0,
|
| 5006 |
+
a.entity_id,
|
| 5007 |
+
b.description
|
| 5008 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5009 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 5010 |
+
ON a.store_product_id = b.store_product_id
|
| 5011 |
+
)
|
| 5012 |
+
ON DUPLICATE KEY UPDATE
|
| 5013 |
+
value = b.description
|
| 5014 |
+
");
|
| 5015 |
+
|
| 5016 |
+
|
| 5017 |
+
}
|
| 5018 |
+
|
| 5019 |
+
#################################################################################################
|
| 5020 |
+
function addShortDescriptions(){
|
| 5021 |
+
// product short description for all web sites
|
| 5022 |
+
$result = $this->db_do("
|
| 5023 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 5024 |
+
entity_type_id,
|
| 5025 |
+
attribute_id,
|
| 5026 |
+
store_id,
|
| 5027 |
+
entity_id,
|
| 5028 |
+
value
|
| 5029 |
+
)(
|
| 5030 |
+
SELECT
|
| 5031 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5032 |
+
" . $this->_getProductAttributeId('short_description'). ",
|
| 5033 |
+
w.website,
|
| 5034 |
+
a.entity_id,
|
| 5035 |
+
' '
|
| 5036 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5037 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 5038 |
+
ON a.store_product_id = b.store_product_id
|
| 5039 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5040 |
+
ON a.store_product_id=w.store_product_id
|
| 5041 |
+
)
|
| 5042 |
+
ON DUPLICATE KEY UPDATE
|
| 5043 |
+
value = ' '
|
| 5044 |
+
");
|
| 5045 |
+
// product short description for all web sites
|
| 5046 |
+
$result = $this->db_do("
|
| 5047 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 5048 |
+
entity_type_id,
|
| 5049 |
+
attribute_id,
|
| 5050 |
+
store_id,
|
| 5051 |
+
entity_id,
|
| 5052 |
+
value
|
| 5053 |
+
)(
|
| 5054 |
+
SELECT
|
| 5055 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5056 |
+
" . $this->_getProductAttributeId('short_description'). ",
|
| 5057 |
+
0,
|
| 5058 |
+
a.entity_id,
|
| 5059 |
+
' '
|
| 5060 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5061 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 5062 |
+
ON a.store_product_id = b.store_product_id
|
| 5063 |
+
)
|
| 5064 |
+
ON DUPLICATE KEY UPDATE
|
| 5065 |
+
value = ' '
|
| 5066 |
+
");
|
| 5067 |
+
|
| 5068 |
+
}
|
| 5069 |
+
|
| 5070 |
+
#################################################################################################
|
| 5071 |
+
function addEAN(){
|
| 5072 |
+
//gather EAN codes for each product
|
| 5073 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('EANs_temp'));
|
| 5074 |
+
$this->db_do("
|
| 5075 |
+
CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
|
| 5076 |
+
sinch_product_id int(11),
|
| 5077 |
+
store_product_id int(11),
|
| 5078 |
+
EANs text,
|
| 5079 |
+
KEY `sinch_product_id` (`sinch_product_id`),
|
| 5080 |
+
KEY `store_product_id` (`store_product_id`)
|
| 5081 |
+
)
|
| 5082 |
+
");
|
| 5083 |
+
$this->db_do("
|
| 5084 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." (
|
| 5085 |
+
sinch_product_id,
|
| 5086 |
+
EANs
|
| 5087 |
+
)(SELECT
|
| 5088 |
+
sec.product_id,
|
| 5089 |
+
GROUP_CONCAT(DISTINCT ean_code ORDER BY ean_code DESC SEPARATOR ', ') AS eans
|
| 5090 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
|
| 5091 |
+
GROUP BY sec.product_id
|
| 5092 |
+
)
|
| 5093 |
+
");
|
| 5094 |
+
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
|
| 5095 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 5096 |
+
ON e.sinch_product_id=p.sinch_product_id
|
| 5097 |
+
SET e.store_product_id=p.store_product_id");
|
| 5098 |
+
// product EANs for all web sites
|
| 5099 |
+
$result = $this->db_do("
|
| 5100 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 5101 |
+
entity_type_id,
|
| 5102 |
+
attribute_id,
|
| 5103 |
+
store_id,
|
| 5104 |
+
entity_id,
|
| 5105 |
+
value
|
| 5106 |
+
)(
|
| 5107 |
+
SELECT
|
| 5108 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5109 |
+
" . $this->_getProductAttributeId('ean'). ",
|
| 5110 |
+
w.website,
|
| 5111 |
+
a.entity_id,
|
| 5112 |
+
e.EANs
|
| 5113 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5114 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
|
| 5115 |
+
ON a.store_product_id = e.store_product_id
|
| 5116 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5117 |
+
ON a.store_product_id=w.store_product_id
|
| 5118 |
+
)
|
| 5119 |
+
ON DUPLICATE KEY UPDATE
|
| 5120 |
+
value = e.EANs
|
| 5121 |
+
");
|
| 5122 |
+
|
| 5123 |
+
// product EANs for all web sites
|
| 5124 |
+
$result = $this->db_do("
|
| 5125 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 5126 |
+
entity_type_id,
|
| 5127 |
+
attribute_id,
|
| 5128 |
+
store_id,
|
| 5129 |
+
entity_id,
|
| 5130 |
+
value
|
| 5131 |
+
)(
|
| 5132 |
+
SELECT
|
| 5133 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5134 |
+
" . $this->_getProductAttributeId('ean'). ",
|
| 5135 |
+
0,
|
| 5136 |
+
a.entity_id,
|
| 5137 |
+
e.EANs
|
| 5138 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5139 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('EANs_temp')." e
|
| 5140 |
+
ON a.store_product_id = e.store_product_id
|
| 5141 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5142 |
+
ON a.store_product_id=w.store_product_id
|
| 5143 |
+
)
|
| 5144 |
+
ON DUPLICATE KEY UPDATE
|
| 5145 |
+
value = e.EANs
|
| 5146 |
+
");
|
| 5147 |
+
|
| 5148 |
+
}
|
| 5149 |
+
|
| 5150 |
+
################################################################################################
|
| 5151 |
+
function addSpecification(){
|
| 5152 |
+
// product specification for all web sites
|
| 5153 |
+
$result = $this->db_do("
|
| 5154 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
|
| 5155 |
+
entity_type_id,
|
| 5156 |
+
attribute_id,
|
| 5157 |
+
store_id,
|
| 5158 |
+
entity_id,
|
| 5159 |
+
value
|
| 5160 |
+
)(
|
| 5161 |
+
SELECT
|
| 5162 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5163 |
+
" . $this->_getProductAttributeId('specification'). ",
|
| 5164 |
+
w.website,
|
| 5165 |
+
a.entity_id,
|
| 5166 |
+
b.specifications
|
| 5167 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5168 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 5169 |
+
ON a.store_product_id = b.store_product_id
|
| 5170 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5171 |
+
ON a.store_product_id=w.store_product_id
|
| 5172 |
+
)
|
| 5173 |
+
ON DUPLICATE KEY UPDATE
|
| 5174 |
+
value = b.specifications
|
| 5175 |
+
");
|
| 5176 |
+
// product specification for all web sites
|
| 5177 |
+
$result = $this->db_do("
|
| 5178 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_text')." (
|
| 5179 |
+
entity_type_id,
|
| 5180 |
+
attribute_id,
|
| 5181 |
+
store_id,
|
| 5182 |
+
entity_id,
|
| 5183 |
+
value
|
| 5184 |
+
)(
|
| 5185 |
+
SELECT
|
| 5186 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5187 |
+
" . $this->_getProductAttributeId('specification'). ",
|
| 5188 |
+
0,
|
| 5189 |
+
a.entity_id,
|
| 5190 |
+
b.specifications
|
| 5191 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5192 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 5193 |
+
ON a.store_product_id = b.store_product_id
|
| 5194 |
+
)
|
| 5195 |
+
ON DUPLICATE KEY UPDATE
|
| 5196 |
+
value = b.specifications
|
| 5197 |
+
");
|
| 5198 |
+
|
| 5199 |
+
|
| 5200 |
+
}
|
| 5201 |
+
|
| 5202 |
+
private function addManufacturer_attribute(){
|
| 5203 |
+
$result = $this->db_do("
|
| 5204 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int')." (
|
| 5205 |
+
entity_type_id,
|
| 5206 |
+
attribute_id,
|
| 5207 |
+
store_id,
|
| 5208 |
+
entity_id,
|
| 5209 |
+
value
|
| 5210 |
+
)(
|
| 5211 |
+
SELECT
|
| 5212 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5213 |
+
" . $this->_getProductAttributeId('manufacturer'). ",
|
| 5214 |
+
0,
|
| 5215 |
+
a.entity_id,
|
| 5216 |
+
pm.manufacturer_option_id
|
| 5217 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5218 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')." pm
|
| 5219 |
+
ON a.entity_id = pm.entity_id
|
| 5220 |
+
)
|
| 5221 |
+
ON DUPLICATE KEY UPDATE
|
| 5222 |
+
value = pm.manufacturer_option_id
|
| 5223 |
+
");
|
| 5224 |
+
|
| 5225 |
+
|
| 5226 |
+
}
|
| 5227 |
+
|
| 5228 |
+
#################################################################################################
|
| 5229 |
+
function addManufacturers($delete_eav=null){
|
| 5230 |
+
// this cleanup is not needed due to foreign keys
|
| 5231 |
+
if(!$delete_eav){
|
| 5232 |
+
$result = $this->db_do("
|
| 5233 |
+
DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')."
|
| 5234 |
+
WHERE attribute_id = ".$this->_getProductAttributeId('manufacturer')//." AND store_id = ".$websiteId
|
| 5235 |
+
);
|
| 5236 |
+
}
|
| 5237 |
+
$this->addManufacturer_attribute();
|
| 5238 |
+
// todo: doesn't seems to work properly, should be inserted per visibility
|
| 5239 |
+
// done, test now
|
| 5240 |
+
|
| 5241 |
+
$result = $this->db_do("
|
| 5242 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
|
| 5243 |
+
entity_id,
|
| 5244 |
+
attribute_id,
|
| 5245 |
+
store_id,
|
| 5246 |
+
value
|
| 5247 |
+
)(
|
| 5248 |
+
SELECT
|
| 5249 |
+
a.entity_id,
|
| 5250 |
+
" . $this->_getProductAttributeId('manufacturer'). ",
|
| 5251 |
+
w.website,
|
| 5252 |
+
mn.shop_option_id
|
| 5253 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5254 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 5255 |
+
ON a.store_product_id = b.store_product_id
|
| 5256 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5257 |
+
ON a.store_product_id=w.store_product_id
|
| 5258 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
|
| 5259 |
+
ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
|
| 5260 |
+
WHERE mn.shop_option_id IS NOT NULL
|
| 5261 |
+
)
|
| 5262 |
+
ON DUPLICATE KEY UPDATE
|
| 5263 |
+
value = mn.shop_option_id
|
| 5264 |
+
");
|
| 5265 |
+
|
| 5266 |
+
$result = $this->db_do("
|
| 5267 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_eav')." (
|
| 5268 |
+
entity_id,
|
| 5269 |
+
attribute_id,
|
| 5270 |
+
store_id,
|
| 5271 |
+
value
|
| 5272 |
+
)(
|
| 5273 |
+
SELECT
|
| 5274 |
+
a.entity_id,
|
| 5275 |
+
" . $this->_getProductAttributeId('manufacturer'). ",
|
| 5276 |
+
0,
|
| 5277 |
+
mn.shop_option_id
|
| 5278 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5279 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." b
|
| 5280 |
+
ON a.store_product_id = b.store_product_id
|
| 5281 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5282 |
+
ON a.store_product_id=w.store_product_id
|
| 5283 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." mn
|
| 5284 |
+
ON b.sinch_manufacturer_id=mn.sinch_manufacturer_id
|
| 5285 |
+
WHERE mn.shop_option_id IS NOT NULL
|
| 5286 |
+
)
|
| 5287 |
+
ON DUPLICATE KEY UPDATE
|
| 5288 |
+
value = mn.shop_option_id
|
| 5289 |
+
");
|
| 5290 |
+
|
| 5291 |
+
|
| 5292 |
+
}
|
| 5293 |
+
|
| 5294 |
+
#################################################################################################
|
| 5295 |
+
function addRelatedProducts(){
|
| 5296 |
+
|
| 5297 |
+
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
|
| 5298 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 5299 |
+
ON rpt.sinch_product_id=p.sinch_product_id
|
| 5300 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 5301 |
+
ON p.store_product_id=cpe.store_product_id
|
| 5302 |
+
SET rpt.store_product_id=p.store_product_id, rpt.entity_id=cpe.entity_id");
|
| 5303 |
+
|
| 5304 |
+
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." rpt
|
| 5305 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('products_temp')." p
|
| 5306 |
+
ON rpt.related_sinch_product_id=p.sinch_product_id
|
| 5307 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 5308 |
+
ON p.store_product_id=cpe.store_product_id
|
| 5309 |
+
SET rpt.store_related_product_id=p.store_product_id, rpt.related_entity_id=cpe.entity_id");
|
| 5310 |
+
|
| 5311 |
+
$result = $this->db_do("SELECT
|
| 5312 |
+
link_type_id,
|
| 5313 |
+
code
|
| 5314 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_type')
|
| 5315 |
+
);
|
| 5316 |
+
$link_type=array();
|
| 5317 |
+
while ($row = mysql_fetch_array($result)) {
|
| 5318 |
+
$link_type[$row['code']]=$row['link_type_id'];
|
| 5319 |
+
}
|
| 5320 |
+
|
| 5321 |
+
$result = $this->db_do("
|
| 5322 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." (
|
| 5323 |
+
product_id,
|
| 5324 |
+
linked_product_id,
|
| 5325 |
+
link_type_id
|
| 5326 |
+
)(
|
| 5327 |
+
SELECT
|
| 5328 |
+
entity_id,
|
| 5329 |
+
related_entity_id,
|
| 5330 |
+
".$link_type['relation']."
|
| 5331 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')."
|
| 5332 |
+
WHERE store_product_id IS NOT NULL
|
| 5333 |
+
AND store_related_product_id IS NOT NULL
|
| 5334 |
+
)
|
| 5335 |
+
ON DUPLICATE KEY UPDATE
|
| 5336 |
+
product_id = entity_id,
|
| 5337 |
+
linked_product_id = related_entity_id
|
| 5338 |
+
");
|
| 5339 |
+
$this->db_do("DROP TABLE IF EXISTS ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp");
|
| 5340 |
+
|
| 5341 |
+
$this->db_do("CREATE TEMPORARY TABLE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp (
|
| 5342 |
+
`value_id` int(11) default NULL,
|
| 5343 |
+
`product_link_attribute_id` smallint(6) unsigned default NULL,
|
| 5344 |
+
`link_id` int(11) unsigned default NULL,
|
| 5345 |
+
`value` int(11) NOT NULL default '0',
|
| 5346 |
+
KEY `FK_INT_PRODUCT_LINK_ATTRIBUTE` (`product_link_attribute_id`),
|
| 5347 |
+
KEY `FK_INT_PRODUCT_LINK` (`link_id`)
|
| 5348 |
+
)
|
| 5349 |
+
");
|
| 5350 |
+
|
| 5351 |
+
$result = $this->db_do("
|
| 5352 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp(
|
| 5353 |
+
product_link_attribute_id,
|
| 5354 |
+
link_id,
|
| 5355 |
+
value
|
| 5356 |
+
)(
|
| 5357 |
+
SELECT
|
| 5358 |
+
2,
|
| 5359 |
+
cpl.link_id,
|
| 5360 |
+
0
|
| 5361 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link')." cpl
|
| 5362 |
+
)
|
| 5363 |
+
");
|
| 5364 |
+
|
| 5365 |
+
$result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
|
| 5366 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." c
|
| 5367 |
+
ON ct.link_id=c.link_id
|
| 5368 |
+
SET ct.value_id=c.value_id
|
| 5369 |
+
WHERE c.product_link_attribute_id=2
|
| 5370 |
+
");
|
| 5371 |
+
|
| 5372 |
+
$result = $this->db_do("
|
| 5373 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')." (
|
| 5374 |
+
value_id,
|
| 5375 |
+
product_link_attribute_id,
|
| 5376 |
+
link_id,
|
| 5377 |
+
value
|
| 5378 |
+
)(
|
| 5379 |
+
SELECT
|
| 5380 |
+
value_id,
|
| 5381 |
+
product_link_attribute_id,
|
| 5382 |
+
link_id,
|
| 5383 |
+
value
|
| 5384 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_link_attribute_int')."_tmp ct
|
| 5385 |
+
)
|
| 5386 |
+
ON DUPLICATE KEY UPDATE
|
| 5387 |
+
link_id=ct.link_id
|
| 5388 |
+
|
| 5389 |
+
");
|
| 5390 |
+
|
| 5391 |
+
/* $q="select distinct store_product_id from stINch_related_products";
|
| 5392 |
+
$quer=$this->db_do($q);
|
| 5393 |
+
$prod = Mage::getModel('catalog/product');
|
| 5394 |
+
while ($row = mysql_fetch_assoc($quer)) {
|
| 5395 |
+
$q1="select distinct store_related_product_id store_product_id from stINch_related_products where store_product_id=".$row['store_product_id'].;
|
| 5396 |
+
$quer1=$this->db_do($q1);
|
| 5397 |
+
$prod->load($row['store_product_id']);
|
| 5398 |
+
|
| 5399 |
+
###//get related product data (product id's and positions)
|
| 5400 |
+
###$relatedData = array();
|
| 5401 |
+
###foreach ($product->getRelatedLinkCollection() as $link) {
|
| 5402 |
+
### $relatedData[$link->getLinkedProductId()]['position'] = $link->getPosition();
|
| 5403 |
+
###}
|
| 5404 |
+
###//manipulate $relatedData array
|
| 5405 |
+
###// ...
|
| 5406 |
+
###//set and save related product data
|
| 5407 |
+
###$product->setRelatedLinkData($relatedData);
|
| 5408 |
+
###$product->save();
|
| 5409 |
+
###
|
| 5410 |
+
$i=1;
|
| 5411 |
+
while ($row1 = mysql_fetch_assoc($quer1)) {
|
| 5412 |
+
$param[$row1['store_related_product_id']]['position']=$i++;
|
| 5413 |
+
|
| 5414 |
+
}
|
| 5415 |
+
$prod->setRelatedLinkData($param);
|
| 5416 |
+
//here ... some other product operations and in the end
|
| 5417 |
+
$prod->save();
|
| 5418 |
+
|
| 5419 |
+
}
|
| 5420 |
+
*/
|
| 5421 |
+
}
|
| 5422 |
+
#################################################################################################
|
| 5423 |
+
function addWeight(){
|
| 5424 |
+
// product short description for all web sites
|
| 5425 |
+
$result = $this->db_do("
|
| 5426 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
|
| 5427 |
+
entity_type_id,
|
| 5428 |
+
attribute_id,
|
| 5429 |
+
store_id,
|
| 5430 |
+
entity_id,
|
| 5431 |
+
value
|
| 5432 |
+
)(
|
| 5433 |
+
SELECT
|
| 5434 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5435 |
+
" . $this->_getProductAttributeId('weight'). ",
|
| 5436 |
+
w.website,
|
| 5437 |
+
a.entity_id,
|
| 5438 |
+
0
|
| 5439 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5440 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
|
| 5441 |
+
ON a.store_product_id = b.store_product_id
|
| 5442 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5443 |
+
ON a.store_product_id=w.store_product_id
|
| 5444 |
+
)
|
| 5445 |
+
ON DUPLICATE KEY UPDATE
|
| 5446 |
+
value = 0
|
| 5447 |
+
");
|
| 5448 |
+
// product short description for all web sites
|
| 5449 |
+
$result = $this->db_do("
|
| 5450 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
|
| 5451 |
+
entity_type_id,
|
| 5452 |
+
attribute_id,
|
| 5453 |
+
store_id,
|
| 5454 |
+
entity_id,
|
| 5455 |
+
value
|
| 5456 |
+
)(
|
| 5457 |
+
SELECT
|
| 5458 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5459 |
+
" . $this->_getProductAttributeId('weight'). ",
|
| 5460 |
+
0,
|
| 5461 |
+
a.entity_id,
|
| 5462 |
+
0
|
| 5463 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5464 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
|
| 5465 |
+
ON a.store_product_id = b.store_product_id
|
| 5466 |
+
)
|
| 5467 |
+
ON DUPLICATE KEY UPDATE
|
| 5468 |
+
value = 0
|
| 5469 |
+
|
| 5470 |
+
|
| 5471 |
+
");
|
| 5472 |
+
|
| 5473 |
+
|
| 5474 |
+
}
|
| 5475 |
+
#################################################################################################
|
| 5476 |
+
function replaceMagentoProductsStockPrice(){
|
| 5477 |
+
//Add stock
|
| 5478 |
+
$connection = Mage::getModel('core/resource')->getConnection('core_write');
|
| 5479 |
+
$result = $this->db_do("DELETE csi
|
| 5480 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
|
| 5481 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 5482 |
+
ON csi.product_id=cpe.entity_id
|
| 5483 |
+
WHERE cpe.entity_id is null");
|
| 5484 |
+
//set all sinch products stock=0 before upgrade (nedds for dayly stock&price import)
|
| 5485 |
+
|
| 5486 |
+
$result = $this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 5487 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." csi
|
| 5488 |
+
ON cpe.entity_id=csi.product_id
|
| 5489 |
+
SET
|
| 5490 |
+
csi.qty=0,
|
| 5491 |
+
csi.is_in_stock=0
|
| 5492 |
+
WHERE cpe.store_product_id IS NOT NULL");
|
| 5493 |
+
|
| 5494 |
+
$result = $this->db_do("
|
| 5495 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." (
|
| 5496 |
+
product_id,
|
| 5497 |
+
stock_id,
|
| 5498 |
+
qty,
|
| 5499 |
+
is_in_stock,
|
| 5500 |
+
manage_stock
|
| 5501 |
+
)(
|
| 5502 |
+
SELECT
|
| 5503 |
+
a.entity_id,
|
| 5504 |
+
1,
|
| 5505 |
+
b.stock,
|
| 5506 |
+
IF(b.stock > 0, 1, 0),
|
| 5507 |
+
1
|
| 5508 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5509 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
|
| 5510 |
+
ON a.store_product_id=b.store_product_id
|
| 5511 |
+
)
|
| 5512 |
+
ON DUPLICATE KEY UPDATE
|
| 5513 |
+
qty=b.stock,
|
| 5514 |
+
is_in_stock = IF(b.stock > 0, 1, 0),
|
| 5515 |
+
manage_stock = 1
|
| 5516 |
+
");
|
| 5517 |
+
|
| 5518 |
+
|
| 5519 |
+
$result = $this->db_do("DELETE FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status'));
|
| 5520 |
+
|
| 5521 |
+
$result = $this->db_do("
|
| 5522 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_status')." (
|
| 5523 |
+
product_id,
|
| 5524 |
+
website_id,
|
| 5525 |
+
stock_id,
|
| 5526 |
+
qty,
|
| 5527 |
+
stock_status
|
| 5528 |
+
)(
|
| 5529 |
+
SELECT
|
| 5530 |
+
a.product_id,
|
| 5531 |
+
w.website_id,
|
| 5532 |
+
1,
|
| 5533 |
+
a.qty,
|
| 5534 |
+
IF(qty > 0, 1, 0)
|
| 5535 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')." a
|
| 5536 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." b
|
| 5537 |
+
ON a.product_id=b.entity_id
|
| 5538 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5539 |
+
ON b.store_product_id=w.store_product_id
|
| 5540 |
+
)
|
| 5541 |
+
ON DUPLICATE KEY UPDATE
|
| 5542 |
+
qty=a.qty,
|
| 5543 |
+
stock_status = IF(a.qty > 0, 1, 0)
|
| 5544 |
+
");
|
| 5545 |
+
|
| 5546 |
+
//Add prices
|
| 5547 |
+
//$result = $this->db_do("truncate catalog_product_entity_decimal");
|
| 5548 |
+
$result = $this->db_do("DELETE cped
|
| 5549 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." cped
|
| 5550 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 5551 |
+
ON cped.entity_id=cpe.entity_id
|
| 5552 |
+
WHERE cpe.entity_id IS NULL");
|
| 5553 |
+
|
| 5554 |
+
$result = $this->db_do("
|
| 5555 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
|
| 5556 |
+
entity_type_id,
|
| 5557 |
+
attribute_id,
|
| 5558 |
+
store_id,
|
| 5559 |
+
entity_id,
|
| 5560 |
+
value
|
| 5561 |
+
)(
|
| 5562 |
+
SELECT
|
| 5563 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5564 |
+
" . $this->_getProductAttributeId('price'). ",
|
| 5565 |
+
w.website,
|
| 5566 |
+
a.entity_id,
|
| 5567 |
+
b.price
|
| 5568 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5569 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
|
| 5570 |
+
ON a.store_product_id=b.store_product_id
|
| 5571 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5572 |
+
ON a.store_product_id=w.store_product_id
|
| 5573 |
+
)
|
| 5574 |
+
ON DUPLICATE KEY UPDATE
|
| 5575 |
+
value = b.price
|
| 5576 |
+
");
|
| 5577 |
+
|
| 5578 |
+
$result = $this->db_do("
|
| 5579 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
|
| 5580 |
+
entity_type_id,
|
| 5581 |
+
attribute_id,
|
| 5582 |
+
store_id,
|
| 5583 |
+
entity_id,
|
| 5584 |
+
value
|
| 5585 |
+
)(
|
| 5586 |
+
SELECT
|
| 5587 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5588 |
+
" . $this->_getProductAttributeId('price'). ",
|
| 5589 |
+
0,
|
| 5590 |
+
a.entity_id,
|
| 5591 |
+
b.price
|
| 5592 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5593 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
|
| 5594 |
+
ON a.store_product_id=b.store_product_id
|
| 5595 |
+
)
|
| 5596 |
+
ON DUPLICATE KEY UPDATE
|
| 5597 |
+
value = b.price
|
| 5598 |
+
");
|
| 5599 |
+
//Add cost
|
| 5600 |
+
// $result = $this->db_do("truncate catalog_product_entity_decimal");
|
| 5601 |
+
$result = $this->db_do("
|
| 5602 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
|
| 5603 |
+
entity_type_id,
|
| 5604 |
+
attribute_id,
|
| 5605 |
+
store_id,
|
| 5606 |
+
entity_id,
|
| 5607 |
+
value
|
| 5608 |
+
)(
|
| 5609 |
+
SELECT
|
| 5610 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5611 |
+
" . $this->_getProductAttributeId('cost'). ",
|
| 5612 |
+
w.website,
|
| 5613 |
+
a.entity_id,
|
| 5614 |
+
b.cost
|
| 5615 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5616 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
|
| 5617 |
+
ON a.store_product_id=b.store_product_id
|
| 5618 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5619 |
+
ON a.store_product_id=w.store_product_id
|
| 5620 |
+
)
|
| 5621 |
+
ON DUPLICATE KEY UPDATE
|
| 5622 |
+
value = b.cost
|
| 5623 |
+
");
|
| 5624 |
+
|
| 5625 |
+
$result = $this->db_do("
|
| 5626 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_decimal')." (
|
| 5627 |
+
entity_type_id,
|
| 5628 |
+
attribute_id,
|
| 5629 |
+
store_id,
|
| 5630 |
+
entity_id,
|
| 5631 |
+
value
|
| 5632 |
+
)(
|
| 5633 |
+
SELECT
|
| 5634 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5635 |
+
" . $this->_getProductAttributeId('cost'). ",
|
| 5636 |
+
0,
|
| 5637 |
+
a.entity_id,
|
| 5638 |
+
b.cost
|
| 5639 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5640 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
|
| 5641 |
+
ON a.store_product_id=b.store_product_id
|
| 5642 |
+
)
|
| 5643 |
+
ON DUPLICATE KEY UPDATE
|
| 5644 |
+
value = b.cost
|
| 5645 |
+
");
|
| 5646 |
+
|
| 5647 |
+
//make products enable in FO
|
| 5648 |
+
// $result = $this->db_do(" truncate catalog_product_index_price");
|
| 5649 |
+
$result = $this->db_do("DELETE cpip
|
| 5650 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." cpip
|
| 5651 |
+
LEFT JOIN ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." cpe
|
| 5652 |
+
ON cpip.entity_id=cpe.entity_id
|
| 5653 |
+
WHERE cpe.entity_id IS NULL");
|
| 5654 |
+
|
| 5655 |
+
$q="SELECT customer_group_id FROM ".Mage::getSingleton('core/resource')->getTableName('customer_group');
|
| 5656 |
+
$quer=$this->db_do($q);
|
| 5657 |
+
|
| 5658 |
+
while ($row = mysql_fetch_assoc($quer)) {
|
| 5659 |
+
$result = $this->db_do("
|
| 5660 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_index_price')." (
|
| 5661 |
+
entity_id,
|
| 5662 |
+
customer_group_id,
|
| 5663 |
+
website_id,
|
| 5664 |
+
tax_class_id,
|
| 5665 |
+
price,
|
| 5666 |
+
final_price,
|
| 5667 |
+
min_price,
|
| 5668 |
+
max_price
|
| 5669 |
+
)(SELECT
|
| 5670 |
+
a.entity_id,
|
| 5671 |
+
".$row['customer_group_id'].",
|
| 5672 |
+
w.website_id,
|
| 5673 |
+
2,
|
| 5674 |
+
b.price ,
|
| 5675 |
+
b.price ,
|
| 5676 |
+
b.price ,
|
| 5677 |
+
b.price
|
| 5678 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5679 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stock_and_prices_temp')." b
|
| 5680 |
+
ON a.store_product_id=b.store_product_id
|
| 5681 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('products_website_temp')." w
|
| 5682 |
+
ON a.store_product_id=w.store_product_id
|
| 5683 |
+
)
|
| 5684 |
+
ON DUPLICATE KEY UPDATE
|
| 5685 |
+
tax_class_id = 2,
|
| 5686 |
+
price = b.price,
|
| 5687 |
+
final_price = b.price,
|
| 5688 |
+
min_price = b.price,
|
| 5689 |
+
max_price = b.price
|
| 5690 |
+
");
|
| 5691 |
+
}
|
| 5692 |
+
}
|
| 5693 |
+
|
| 5694 |
+
|
| 5695 |
+
|
| 5696 |
+
#################################################################################################
|
| 5697 |
+
|
| 5698 |
+
function getProductDescription($entity_id){
|
| 5699 |
+
|
| 5700 |
+
$this->loadProductParams($entity_id);
|
| 5701 |
+
$this->loadProductStarfeatures($entity_id);
|
| 5702 |
+
$this->loadGalleryPhotos($entity_id);
|
| 5703 |
+
Varien_Profiler::start('Bintime FILE RELATED');
|
| 5704 |
+
$this->loadRelatedProducts($entity_id);
|
| 5705 |
+
Varien_Profiler::stop('Bintime FILE RELATED');
|
| 5706 |
+
|
| 5707 |
+
return true;
|
| 5708 |
+
}
|
| 5709 |
+
#################################################################################################
|
| 5710 |
+
|
| 5711 |
+
public function getProductName(){
|
| 5712 |
+
return $this->productName;
|
| 5713 |
+
}
|
| 5714 |
+
#################################################################################################
|
| 5715 |
+
|
| 5716 |
+
public function getProductDescriptionList(){
|
| 5717 |
+
return $this->productDescriptionList;
|
| 5718 |
+
}
|
| 5719 |
+
#################################################################################################
|
| 5720 |
+
|
| 5721 |
+
public function getProductSpecifications(){
|
| 5722 |
+
return $this->specifications;
|
| 5723 |
+
}
|
| 5724 |
+
#################################################################################################
|
| 5725 |
+
|
| 5726 |
+
public function getShortProductDescription(){
|
| 5727 |
+
return $this->productDescription;
|
| 5728 |
+
}
|
| 5729 |
+
#################################################################################################
|
| 5730 |
+
|
| 5731 |
+
public function getFullProductDescription(){
|
| 5732 |
+
return $this->fullProductDescription;
|
| 5733 |
+
}
|
| 5734 |
+
#################################################################################################
|
| 5735 |
+
|
| 5736 |
+
public function getLowPicUrl(){
|
| 5737 |
+
return $this->highPicUrl;
|
| 5738 |
+
}
|
| 5739 |
+
#################################################################################################
|
| 5740 |
+
|
| 5741 |
+
public function getRelatedProducts(){
|
| 5742 |
+
return $this->relatedProducts;
|
| 5743 |
+
}
|
| 5744 |
+
#################################################################################################
|
| 5745 |
+
|
| 5746 |
+
public function getVendor(){
|
| 5747 |
+
return $this->vendor;
|
| 5748 |
+
}
|
| 5749 |
+
#################################################################################################
|
| 5750 |
+
|
| 5751 |
+
public function getMPN(){
|
| 5752 |
+
return $this->productId;
|
| 5753 |
+
}
|
| 5754 |
+
#################################################################################################
|
| 5755 |
+
|
| 5756 |
+
public function getEAN(){
|
| 5757 |
+
return $this->EAN;
|
| 5758 |
+
}
|
| 5759 |
+
################################################################################################
|
| 5760 |
+
|
| 5761 |
+
public function getGalleryPhotos(){
|
| 5762 |
+
return $this->galleryPhotos;
|
| 5763 |
+
}
|
| 5764 |
+
|
| 5765 |
+
#################################################################################################
|
| 5766 |
+
|
| 5767 |
+
private function loadProductParams($entity_id){
|
| 5768 |
+
$store_product_id=$this->getStoreProductIdByEntity($entity_id);
|
| 5769 |
+
if(!$store_product_id){
|
| 5770 |
+
// echo "AAAAAAA"; exit;
|
| 5771 |
+
return;
|
| 5772 |
+
}
|
| 5773 |
+
$q="SELECT
|
| 5774 |
+
sinch_product_id,
|
| 5775 |
+
product_sku,
|
| 5776 |
+
product_name,
|
| 5777 |
+
sinch_manufacturer_id,
|
| 5778 |
+
store_category_id,
|
| 5779 |
+
main_image_url,
|
| 5780 |
+
thumb_image_url,
|
| 5781 |
+
medium_image_url,
|
| 5782 |
+
specifications,
|
| 5783 |
+
description,
|
| 5784 |
+
specifications
|
| 5785 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products')."
|
| 5786 |
+
WHERE store_product_id =".$store_product_id;
|
| 5787 |
+
$quer=$this->db_do($q);
|
| 5788 |
+
$product=mysql_fetch_array($quer);
|
| 5789 |
+
|
| 5790 |
+
$this->productDescription = (string) substr($product['description'],50,0);
|
| 5791 |
+
$this->fullProductDescription = (string)$product['description'];
|
| 5792 |
+
$this->lowPicUrl = (string)$product["medium_image_url"];//thumb_image_url"];
|
| 5793 |
+
$this->highPicUrl = (string)$product["main_image_url"];
|
| 5794 |
+
$this->productName = (string)$product["product_name"];
|
| 5795 |
+
$this->productId = (string)$product['product_sku'];
|
| 5796 |
+
$this->specifications = (string)$product['specifications'];
|
| 5797 |
+
$this->sinchProductId = (string)$product['sinch_product_id'];
|
| 5798 |
+
if($product['sinch_manufacturer_id']){
|
| 5799 |
+
$q="SELECT manufacturer_name
|
| 5800 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')."
|
| 5801 |
+
WHERE sinch_manufacturer_id=".$product['sinch_manufacturer_id'];
|
| 5802 |
+
$quer=$this->db_do($q);
|
| 5803 |
+
$manufacturer=mysql_fetch_array($quer);
|
| 5804 |
+
$this->vendor = (string)$manufacturer['manufacturer_name'];
|
| 5805 |
+
}
|
| 5806 |
+
$q="SELECT DISTINCT ean_code
|
| 5807 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_ean_codes')." sec
|
| 5808 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." sp
|
| 5809 |
+
ON sec.product_id=sp.sinch_product_id
|
| 5810 |
+
WHERE sp.store_product_id=".$store_product_id;
|
| 5811 |
+
$quer=$this->db_do($q);
|
| 5812 |
+
while ($row=mysql_fetch_array($quer)){
|
| 5813 |
+
$EANarr[]=$row['ean_code'];
|
| 5814 |
+
}
|
| 5815 |
+
// $prodEAN = $productTag->EANCode;
|
| 5816 |
+
$EANstr='';
|
| 5817 |
+
/* $EANarr=null;
|
| 5818 |
+
foreach($prodEAN as $ellEAN){
|
| 5819 |
+
$EANarr[]=$ellEAN['EAN'];
|
| 5820 |
+
}
|
| 5821 |
+
*/
|
| 5822 |
+
$EANstr=implode(", ",$EANarr);
|
| 5823 |
+
$this->EAN = (string)$EANstr;//$productTag->EANCode['EAN'];
|
| 5824 |
+
}
|
| 5825 |
+
#################################################################################################
|
| 5826 |
+
|
| 5827 |
+
private function loadProductStarfeatures($entity_id){
|
| 5828 |
+
$descriptionArray=array();
|
| 5829 |
+
$product_info_features = $this->db_do("
|
| 5830 |
+
SELECT c.feature_name AS name, b.text AS value
|
| 5831 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_product_features')." a
|
| 5832 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_restricted_values')." b
|
| 5833 |
+
ON a.restricted_value_id = b.restricted_value_id
|
| 5834 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_features')." c
|
| 5835 |
+
ON b.category_feature_id = c.category_feature_id
|
| 5836 |
+
WHERE a.sinch_product_id = '" .$this->sinchProductId . "'" );
|
| 5837 |
+
while ($features = mysql_fetch_array($product_info_features)) {
|
| 5838 |
+
$descriptionArray[$features['name']] = $features['value'];
|
| 5839 |
+
}
|
| 5840 |
+
|
| 5841 |
+
|
| 5842 |
+
$this->productDescriptionList = $descriptionArray;
|
| 5843 |
+
}
|
| 5844 |
+
#################################################################################################
|
| 5845 |
+
|
| 5846 |
+
private function loadRelatedProducts($entity_id){
|
| 5847 |
+
$this->sinchProductId;
|
| 5848 |
+
if(!$this->sinchProductId){
|
| 5849 |
+
return;
|
| 5850 |
+
}
|
| 5851 |
+
$q="SELECT
|
| 5852 |
+
st_prod.sinch_product_id,
|
| 5853 |
+
st_prod.product_sku,
|
| 5854 |
+
st_prod.product_name,
|
| 5855 |
+
st_prod.sinch_manufacturer_id,
|
| 5856 |
+
st_prod.store_category_id,
|
| 5857 |
+
st_prod.main_image_url,
|
| 5858 |
+
st_prod.thumb_image_url,
|
| 5859 |
+
st_prod.medium_image_url,
|
| 5860 |
+
st_prod.specifications,
|
| 5861 |
+
st_prod.description,
|
| 5862 |
+
st_prod.specifications,
|
| 5863 |
+
st_manuf.manufacturer_name,
|
| 5864 |
+
st_manuf.manufacturers_image
|
| 5865 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_related_products')." st_rel_prod
|
| 5866 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." st_prod
|
| 5867 |
+
ON st_rel_prod.related_sinch_product_id=st_prod.sinch_product_id
|
| 5868 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_manufacturers')." st_manuf
|
| 5869 |
+
ON st_prod.sinch_manufacturer_id=st_manuf.sinch_manufacturer_id
|
| 5870 |
+
WHERE st_rel_prod.sinch_product_id=".$this->sinchProductId;
|
| 5871 |
+
|
| 5872 |
+
// echo $q;
|
| 5873 |
+
$quer=$this->db_do($q);
|
| 5874 |
+
while($row=mysql_fetch_array($quer)){
|
| 5875 |
+
|
| 5876 |
+
$productArray = array();
|
| 5877 |
+
$productArray['name'] = (string)$row['product_name'];
|
| 5878 |
+
$productArray['thumb'] = (string)$row['thumb_image_url'];
|
| 5879 |
+
$mpn = (string)$row['product_sku'];
|
| 5880 |
+
$productSupplierId = (int)$row['sinch_manufacturer_id'];
|
| 5881 |
+
$productArray['supplier_thumb'] = (string)($row['manufacturers_image']);
|
| 5882 |
+
$productArray['supplier_name'] = (string)$row['manufacturer_name'];
|
| 5883 |
+
|
| 5884 |
+
$this->relatedProducts[$mpn] = $productArray;
|
| 5885 |
+
}
|
| 5886 |
+
}
|
| 5887 |
+
#################################################################################################
|
| 5888 |
+
/**
|
| 5889 |
+
* load Gallery array from XML
|
| 5890 |
+
*/
|
| 5891 |
+
public function loadGalleryPhotos($entity_id){
|
| 5892 |
+
/*$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
|
| 5893 |
+
if (!count($galleryPhotos)){
|
| 5894 |
+
return false;
|
| 5895 |
+
}
|
| 5896 |
+
*/
|
| 5897 |
+
$store_product_id=$this->getStoreProductIdByEntity($entity_id);
|
| 5898 |
+
if(!$store_product_id){
|
| 5899 |
+
return;
|
| 5900 |
+
}
|
| 5901 |
+
$q=$this->db_do("SELECT COUNT(*) AS cnt
|
| 5902 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
|
| 5903 |
+
WHERE store_product_id=".$store_product_id);
|
| 5904 |
+
|
| 5905 |
+
$res=mysql_fetch_array($q);
|
| 5906 |
+
if(!$res || !$res['cnt']){
|
| 5907 |
+
return false;
|
| 5908 |
+
}
|
| 5909 |
+
$q="SELECT
|
| 5910 |
+
image_url as Pic,
|
| 5911 |
+
thumb_image_url as ThumbPic
|
| 5912 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_pictures_gallery')."
|
| 5913 |
+
WHERE store_product_id=".$store_product_id;
|
| 5914 |
+
|
| 5915 |
+
$res=$this->db_do($q);
|
| 5916 |
+
|
| 5917 |
+
while($photo=mysql_fetch_array($res)){
|
| 5918 |
+
$picHeight = (int)500;//$photo["PicHeight"];
|
| 5919 |
+
$picWidth = (int)500;//$photo["PicWidth"];
|
| 5920 |
+
$thumbUrl = (string)$photo["ThumbPic"];
|
| 5921 |
+
$picUrl = (string)$photo["Pic"];
|
| 5922 |
+
|
| 5923 |
+
array_push($this->galleryPhotos, array(
|
| 5924 |
+
'height' => $picHeight,
|
| 5925 |
+
'width' => $picWidth,
|
| 5926 |
+
'thumb' => $thumbUrl,
|
| 5927 |
+
'pic' => $picUrl
|
| 5928 |
+
));
|
| 5929 |
+
}
|
| 5930 |
+
}
|
| 5931 |
+
#################################################################################################
|
| 5932 |
+
public function reloadProductImage($entity_id){
|
| 5933 |
+
$result = $this->db_do("
|
| 5934 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 5935 |
+
entity_type_id,
|
| 5936 |
+
attribute_id,
|
| 5937 |
+
store_id,
|
| 5938 |
+
entity_id,
|
| 5939 |
+
value
|
| 5940 |
+
)(
|
| 5941 |
+
SELECT
|
| 5942 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5943 |
+
" . $this->_getProductAttributeId('image'). ",
|
| 5944 |
+
w.store_id,
|
| 5945 |
+
a.entity_id,
|
| 5946 |
+
b.main_image_url
|
| 5947 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5948 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
|
| 5949 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
|
| 5950 |
+
ON a.store_product_id = b.store_product_id
|
| 5951 |
+
WHERE a.entity_id=$entity_id
|
| 5952 |
+
)
|
| 5953 |
+
ON DUPLICATE KEY UPDATE
|
| 5954 |
+
value = b.main_image_url
|
| 5955 |
+
");
|
| 5956 |
+
|
| 5957 |
+
|
| 5958 |
+
// image for specific web sites
|
| 5959 |
+
$result = $this->db_do("
|
| 5960 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 5961 |
+
entity_type_id,
|
| 5962 |
+
attribute_id,
|
| 5963 |
+
store_id,
|
| 5964 |
+
entity_id,
|
| 5965 |
+
value
|
| 5966 |
+
)(
|
| 5967 |
+
SELECT
|
| 5968 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5969 |
+
" . $this->_getProductAttributeId('image'). ",
|
| 5970 |
+
0,
|
| 5971 |
+
a.entity_id,
|
| 5972 |
+
b.main_image_url
|
| 5973 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5974 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
|
| 5975 |
+
ON a.store_product_id = b.store_product_id
|
| 5976 |
+
WHERE a.entity_id=$entity_id
|
| 5977 |
+
)
|
| 5978 |
+
ON DUPLICATE KEY UPDATE
|
| 5979 |
+
value = b.main_image_url
|
| 5980 |
+
");
|
| 5981 |
+
|
| 5982 |
+
|
| 5983 |
+
// small_image for specific web sites
|
| 5984 |
+
$result = $this->db_do("
|
| 5985 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 5986 |
+
entity_type_id,
|
| 5987 |
+
attribute_id,
|
| 5988 |
+
store_id,
|
| 5989 |
+
entity_id,
|
| 5990 |
+
value
|
| 5991 |
+
)(
|
| 5992 |
+
SELECT
|
| 5993 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 5994 |
+
" . $this->_getProductAttributeId('small_image'). ",
|
| 5995 |
+
w.store_id,
|
| 5996 |
+
a.entity_id,
|
| 5997 |
+
b.main_image_url
|
| 5998 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 5999 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
|
| 6000 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
|
| 6001 |
+
ON a.store_product_id = b.store_product_id
|
| 6002 |
+
WHERE a.entity_id=$entity_id
|
| 6003 |
+
)
|
| 6004 |
+
ON DUPLICATE KEY UPDATE
|
| 6005 |
+
value = b.main_image_url
|
| 6006 |
+
");
|
| 6007 |
+
|
| 6008 |
+
|
| 6009 |
+
// small_image for all web sites
|
| 6010 |
+
$result = $this->db_do("
|
| 6011 |
+
INSERT INTO ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')." (
|
| 6012 |
+
entity_type_id,
|
| 6013 |
+
attribute_id,
|
| 6014 |
+
store_id,
|
| 6015 |
+
entity_id,
|
| 6016 |
+
value
|
| 6017 |
+
)(
|
| 6018 |
+
SELECT
|
| 6019 |
+
" . $this->_getProductEntityTypeId(). ",
|
| 6020 |
+
" . $this->_getProductAttributeId('small_image'). ",
|
| 6021 |
+
0,
|
| 6022 |
+
a.entity_id,
|
| 6023 |
+
b.main_image_url
|
| 6024 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')." a
|
| 6025 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('core_store')." w
|
| 6026 |
+
INNER JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_products')." b
|
| 6027 |
+
ON a.store_product_id = b.store_product_id
|
| 6028 |
+
WHERE a.entity_id=$entity_id
|
| 6029 |
+
)
|
| 6030 |
+
ON DUPLICATE KEY UPDATE
|
| 6031 |
+
value = b.main_image_url
|
| 6032 |
+
");
|
| 6033 |
+
}
|
| 6034 |
+
#################################################################################################
|
| 6035 |
+
public function runIndexer(){
|
| 6036 |
+
exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php reindexall');
|
| 6037 |
+
}
|
| 6038 |
+
#################################################################################################
|
| 6039 |
+
public function runStockPriceIndexer(){
|
| 6040 |
+
exec(PHP_RUN_STRING.' '.$this->shellDir.'indexer.php --reindex catalog_product_price,cataloginventory_stock');
|
| 6041 |
+
}
|
| 6042 |
+
#################################################################################################
|
| 6043 |
+
private function getStoreProductIdByEntity($entity_id){
|
| 6044 |
+
$q=$this->db_do("SELECT store_product_id
|
| 6045 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('stINch_products_mapping')."
|
| 6046 |
+
WHERE entity_id=".$entity_id);
|
| 6047 |
+
$res=mysql_fetch_array($q);
|
| 6048 |
+
// echo $entity_id."AAAA".$res['store_product_id']; exit;
|
| 6049 |
+
return ($res['store_product_id']);
|
| 6050 |
+
}
|
| 6051 |
+
#################################################################################################
|
| 6052 |
+
|
| 6053 |
+
private function db_connect() {
|
| 6054 |
+
|
| 6055 |
+
// $connection = Mage::getModel('core/resource')->getConnection('core_write');
|
| 6056 |
+
$dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
|
| 6057 |
+
|
| 6058 |
+
if ($this->db = mysql_connect($dbConf->host, $dbConf->username, $dbConf->password, true, 128)) {
|
| 6059 |
+
if(mysql_select_db($dbConf->dbname)){
|
| 6060 |
+
$this->_LOG("Connected..");
|
| 6061 |
+
}else{
|
| 6062 |
+
die("Can't select the database: " . mysql_error());
|
| 6063 |
+
}
|
| 6064 |
+
}else{
|
| 6065 |
+
die("Could not connect: " . mysql_error());
|
| 6066 |
+
|
| 6067 |
+
}
|
| 6068 |
+
|
| 6069 |
+
}
|
| 6070 |
+
#################################################################################################
|
| 6071 |
+
|
| 6072 |
+
private function db_do($query) {
|
| 6073 |
+
if($this->debug_mode){
|
| 6074 |
+
// $this->_LOG("Query: " . $query);
|
| 6075 |
+
Mage::log("Query: " . $query, null, $this->_logFile);
|
| 6076 |
+
}
|
| 6077 |
+
// $result = $this->this->db_do($query);//
|
| 6078 |
+
// $query=mysql_real_escape_string($query);
|
| 6079 |
+
//mysql_query('set names utf8');
|
| 6080 |
+
$result = mysql_query($query) or die("Query failed: " . mysql_error());
|
| 6081 |
+
if (!$result) {
|
| 6082 |
+
throw new Exception("Invalid query: $sql\n" . mysql_error());
|
| 6083 |
+
} else {
|
| 6084 |
+
return $result;
|
| 6085 |
+
}
|
| 6086 |
+
|
| 6087 |
+
return $result;
|
| 6088 |
+
}
|
| 6089 |
+
##################################################################################################
|
| 6090 |
+
function table_rows_count($table){
|
| 6091 |
+
$rows_count_res=$this->db_do("select count(*) as cnt from ".$table);
|
| 6092 |
+
$rows_count=mysql_fetch_array($rows_count_res);
|
| 6093 |
+
return ($rows_count['cnt']);
|
| 6094 |
+
}
|
| 6095 |
+
##################################################################################################
|
| 6096 |
+
function file_strings_count($parse_file){
|
| 6097 |
+
$files_str=count(file($parse_file));
|
| 6098 |
+
return $files_str;
|
| 6099 |
+
}
|
| 6100 |
+
##################################################################################################
|
| 6101 |
+
function check_loaded_data($file, $table){
|
| 6102 |
+
$cnt_strings_in_file=$this->file_strings_count($file);
|
| 6103 |
+
$cnt_rows_int_table=$this->table_rows_count($table);
|
| 6104 |
+
$persent_cnt_strings_in_file=$cnt_strings_in_file / 10;
|
| 6105 |
+
if($cnt_rows_int_table > $persent_cnt_strings_in_file){
|
| 6106 |
+
return true;
|
| 6107 |
+
}else{
|
| 6108 |
+
return false;
|
| 6109 |
+
}
|
| 6110 |
+
}
|
| 6111 |
+
##################################################################################################
|
| 6112 |
+
|
| 6113 |
+
|
| 6114 |
+
function valid_utf($string,$new_line = true){
|
| 6115 |
+
/* if($new_line == true){
|
| 6116 |
+
$string = preg_replace('/\\\n/',"\n",$string);
|
| 6117 |
+
}
|
| 6118 |
+
*/
|
| 6119 |
+
$string = preg_replace('/™/','™',$string);
|
| 6120 |
+
$string = preg_replace("/®/",'®',$string);
|
| 6121 |
+
$string = preg_replace("/≈/",'≈',$string);
|
| 6122 |
+
$string = preg_replace("/".chr(226).chr(128).chr(157)."/",'"',$string);
|
| 6123 |
+
$string = preg_replace("/".chr(226).chr(128).chr(153)."/",'′',$string);
|
| 6124 |
+
$string = preg_replace("/°/",'°',$string);
|
| 6125 |
+
$string = preg_replace("/±/",'±',$string);
|
| 6126 |
+
$string = preg_replace("/µ/",'µ',$string);
|
| 6127 |
+
$string = preg_replace("/²/",'²',$string);
|
| 6128 |
+
$string = preg_replace("/³/",'³',$string);
|
| 6129 |
+
$string = preg_replace('/\xe2\x80\x93/','-',$string);
|
| 6130 |
+
$string = preg_replace('/\xe2\x80\x99/','\'',$string);
|
| 6131 |
+
$string = preg_replace('/\xe2\x80\x9c/',' ',$string);
|
| 6132 |
+
$string = preg_replace('/\xe2\x80\x9d/',' ',$string);
|
| 6133 |
+
|
| 6134 |
+
return utf8_decode($string);
|
| 6135 |
+
|
| 6136 |
+
// return $string;
|
| 6137 |
+
}
|
| 6138 |
+
|
| 6139 |
+
#################################################################################################
|
| 6140 |
+
function dropHTMLentities($entity_type_id, $attribute_id){
|
| 6141 |
+
// product name for all web sites
|
| 6142 |
+
$result = $this->db_do("
|
| 6143 |
+
SELECT value, entity_id
|
| 6144 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
|
| 6145 |
+
WHERE entity_type_id=".$entity_type_id."
|
| 6146 |
+
AND attribute_id=".$attribute_id
|
| 6147 |
+
);
|
| 6148 |
+
while($row=mysql_fetch_array($result)){
|
| 6149 |
+
$value=$this->valid_char($row['value']);
|
| 6150 |
+
if($value!='' and $value!=$row['value']){
|
| 6151 |
+
$this->db_do("UPDATE ".Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')."
|
| 6152 |
+
SET value='".mysql_real_escape_string($value)."'
|
| 6153 |
+
WHERE entity_id=".$row['entity_id']."
|
| 6154 |
+
AND entity_type_id=".$entity_type_id."
|
| 6155 |
+
AND attribute_id=".$attribute_id);
|
| 6156 |
+
}
|
| 6157 |
+
|
| 6158 |
+
}
|
| 6159 |
+
}
|
| 6160 |
+
|
| 6161 |
+
#################################################################################################
|
| 6162 |
+
|
| 6163 |
+
function valid_char($string){
|
| 6164 |
+
$string = preg_replace('/™/', ' ',$string);
|
| 6165 |
+
$string = preg_replace('/®/', ' ',$string);
|
| 6166 |
+
$string = preg_replace('/≈/', ' ',$string);
|
| 6167 |
+
$string = preg_replace('/"/', ' ',$string);
|
| 6168 |
+
$string = preg_replace('/′/', ' ',$string);
|
| 6169 |
+
$string = preg_replace('/°/', ' ',$string);
|
| 6170 |
+
$string = preg_replace('/±/', ' ',$string);
|
| 6171 |
+
$string = preg_replace('/µ/', ' ',$string);
|
| 6172 |
+
$string = preg_replace('/²/', ' ',$string);
|
| 6173 |
+
$string = preg_replace('/³/', ' ',$string);
|
| 6174 |
+
// $string = preg_replace('/\xe2\x80\x93/','-',$string);
|
| 6175 |
+
// $string = preg_replace('/\xe2\x80\x99/','\'',$string);
|
| 6176 |
+
// $string = preg_replace('/\xe2\x80\x9c/',' ',$string);
|
| 6177 |
+
// $string = preg_replace('/\xe2\x80\x9d/',' ',$string);
|
| 6178 |
+
|
| 6179 |
+
// return utf8_decode($string);
|
| 6180 |
+
|
| 6181 |
+
return $string;
|
| 6182 |
+
}
|
| 6183 |
+
|
| 6184 |
+
#################################################################################################
|
| 6185 |
+
|
| 6186 |
+
function _LOG($log){
|
| 6187 |
+
|
| 6188 |
+
if($log){
|
| 6189 |
+
// $q="insert into ".$this->import_log_table." (message_date, message) values(now(), '".$log."')";
|
| 6190 |
+
// $this->db_do($q);
|
| 6191 |
+
Mage::log($log, null, $this->_logFile);
|
| 6192 |
+
// list($usec, $sec) = explode(" ", microtime());
|
| 6193 |
+
// $time = ((float)$usec + (float)$sec);
|
| 6194 |
+
/* $time = date("D M j G:i:s T Y");
|
| 6195 |
+
|
| 6196 |
+
if($_SERVER['REMOTE_ADDR']){
|
| 6197 |
+
$log = "[".getmypid()."] "."[".$_SERVER['REMOTE_ADDR']."] "."[".$time."] ".$log."\n";
|
| 6198 |
+
error_log($log,3,LOG_FILE);
|
| 6199 |
+
}else{
|
| 6200 |
+
$log = "[".getmypid()."] "."[".$time."] ".$log."\n";
|
| 6201 |
+
error_log($log,3,LOG_FILE . ".cli");
|
| 6202 |
+
*/
|
| 6203 |
+
}
|
| 6204 |
+
}
|
| 6205 |
+
|
| 6206 |
+
#################################################################################################
|
| 6207 |
+
|
| 6208 |
+
function wget(){
|
| 6209 |
+
|
| 6210 |
+
$got = func_num_args();
|
| 6211 |
+
$url = $file = $flag = false;
|
| 6212 |
+
|
| 6213 |
+
if($got<1){
|
| 6214 |
+
return false;
|
| 6215 |
+
}elseif($got == 1){
|
| 6216 |
+
$url = func_get_arg(0);
|
| 6217 |
+
}elseif($got == 2){
|
| 6218 |
+
$url = func_get_arg(0);
|
| 6219 |
+
$file= func_get_arg(1);
|
| 6220 |
+
}elseif($got == 3){
|
| 6221 |
+
$url = func_get_arg(0);
|
| 6222 |
+
$file= func_get_arg(1);
|
| 6223 |
+
$flag= func_get_arg(2);
|
| 6224 |
+
}
|
| 6225 |
+
|
| 6226 |
+
if($flag == 'copy'){
|
| 6227 |
+
if(copy($url,$file)){
|
| 6228 |
+
return true;
|
| 6229 |
+
}else{
|
| 6230 |
+
return false;
|
| 6231 |
+
}
|
| 6232 |
+
}elseif($flag == 'system'){
|
| 6233 |
+
exec("wget -O$file $url");
|
| 6234 |
+
return true;
|
| 6235 |
+
}else{
|
| 6236 |
+
$c=curl_init($url);
|
| 6237 |
+
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
|
| 6238 |
+
curl_setopt($c,CURLOPT_FOLLOWLOCATION,1);
|
| 6239 |
+
curl_setopt($c,CURLOPT_HEADER,array("Accept-Encoding: gzip"));
|
| 6240 |
+
if(!$file){
|
| 6241 |
+
$page = curl_exec($c);
|
| 6242 |
+
curl_close($c);
|
| 6243 |
+
return $page;
|
| 6244 |
+
}else{
|
| 6245 |
+
$FH = fopen($file,"wb");// or echo"Can't open for writing ".$file;
|
| 6246 |
+
fwrite($FH,curl_exec($c));
|
| 6247 |
+
fclose($FH);
|
| 6248 |
+
curl_close($c);
|
| 6249 |
+
return true;
|
| 6250 |
+
}
|
| 6251 |
+
}
|
| 6252 |
+
}
|
| 6253 |
+
#################################################################################################
|
| 6254 |
+
/**
|
| 6255 |
+
* Create the import directory Hierarchy
|
| 6256 |
+
* @return false if directory already exists
|
| 6257 |
+
*/
|
| 6258 |
+
public function createTemporaryImportDerictory(){
|
| 6259 |
+
$dirArray = explode('/', $this->varDir);
|
| 6260 |
+
end($dirArray);
|
| 6261 |
+
// $this->_LOG('before :'.$this->varDir);
|
| 6262 |
+
if (prev($dirArray)=='bintime'){
|
| 6263 |
+
return false;
|
| 6264 |
+
}
|
| 6265 |
+
|
| 6266 |
+
|
| 6267 |
+
$this->varDir = $this->varDir . 'bintime/sinchimport/';
|
| 6268 |
+
if (!is_dir($this->varDir)) {
|
| 6269 |
+
mkdir($this->varDir,0777,true);
|
| 6270 |
+
}
|
| 6271 |
+
// $this->_LOG('after :'.$this->varDir);
|
| 6272 |
+
}
|
| 6273 |
+
#################################################################################################
|
| 6274 |
+
|
| 6275 |
+
function count_children($id){
|
| 6276 |
+
|
| 6277 |
+
$q="SELECT store_category_id
|
| 6278 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
|
| 6279 |
+
WHERE parent_store_category_id=".$id;
|
| 6280 |
+
$quer=$this->db_do($q);
|
| 6281 |
+
$count=0;
|
| 6282 |
+
while ($row=mysql_fetch_array($quer)){
|
| 6283 |
+
$count+=$this->count_children($row['store_category_id']);
|
| 6284 |
+
$count++;
|
| 6285 |
+
}
|
| 6286 |
+
return ($count);
|
| 6287 |
+
}
|
| 6288 |
+
#################################################################################################
|
| 6289 |
+
private function delete_old_sinch_categories_from_shop(){
|
| 6290 |
+
|
| 6291 |
+
$q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." cat
|
| 6292 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 6293 |
+
ON cat.entity_id=scm.shop_entity_id
|
| 6294 |
+
WHERE
|
| 6295 |
+
(scm.shop_store_category_id is not null) AND
|
| 6296 |
+
(scm.store_category_id is null)";
|
| 6297 |
+
$this->db_do($q);
|
| 6298 |
+
|
| 6299 |
+
$q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_int')." cat
|
| 6300 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 6301 |
+
ON cat.entity_id=scm.shop_entity_id
|
| 6302 |
+
WHERE
|
| 6303 |
+
(scm.shop_store_category_id is not null) AND
|
| 6304 |
+
(scm.store_category_id is null)";
|
| 6305 |
+
$this->db_do($q);
|
| 6306 |
+
|
| 6307 |
+
$q="DELETE cat FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')." cat
|
| 6308 |
+
JOIN ".Mage::getSingleton('core/resource')->getTableName('stINch_categories_mapping')." scm
|
| 6309 |
+
ON cat.entity_id=scm.shop_entity_id
|
| 6310 |
+
WHERE
|
| 6311 |
+
(scm.shop_store_category_id is not null) AND
|
| 6312 |
+
(scm.store_category_id is null)";
|
| 6313 |
+
$this->db_do($q);
|
| 6314 |
+
|
| 6315 |
+
}
|
| 6316 |
+
#################################################################################################
|
| 6317 |
+
|
| 6318 |
+
function culc_path($parent_id, $ent_id){
|
| 6319 |
+
|
| 6320 |
+
echo("\nparent_id = [$parent_id] ent_id = [$ent_id]\n");
|
| 6321 |
+
|
| 6322 |
+
$path='';
|
| 6323 |
+
$cat_id=$parent_id;
|
| 6324 |
+
$q="SELECT
|
| 6325 |
+
parent_id
|
| 6326 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
|
| 6327 |
+
WHERE entity_id=".$cat_id;
|
| 6328 |
+
$quer=$this->db_do($q);
|
| 6329 |
+
$row=mysql_fetch_array($quer);
|
| 6330 |
+
while($row['parent_id']){
|
| 6331 |
+
$path=$row['parent_id'].'/'.$path;
|
| 6332 |
+
$q="SELECT
|
| 6333 |
+
parent_id
|
| 6334 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
|
| 6335 |
+
WHERE entity_id=".$row['parent_id'];
|
| 6336 |
+
$quer=$this->db_do($q);
|
| 6337 |
+
$row=mysql_fetch_array($quer);
|
| 6338 |
+
|
| 6339 |
+
}
|
| 6340 |
+
if($cat_id){
|
| 6341 |
+
$path.=$cat_id."/";
|
| 6342 |
+
}
|
| 6343 |
+
|
| 6344 |
+
if($path){
|
| 6345 |
+
return($path.$ent_id);
|
| 6346 |
+
}else{
|
| 6347 |
+
return($ent_id);
|
| 6348 |
+
}
|
| 6349 |
+
|
| 6350 |
+
}
|
| 6351 |
+
#################################################################################################
|
| 6352 |
+
|
| 6353 |
+
function get_category_level($id){
|
| 6354 |
+
$q="SELECT parent_store_category_id
|
| 6355 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
|
| 6356 |
+
WHERE store_category_id=".$id;
|
| 6357 |
+
$quer=$this->db_do($q);
|
| 6358 |
+
$level=1;
|
| 6359 |
+
$row=mysql_fetch_array($quer);
|
| 6360 |
+
while ($row['parent_store_category_id']!=0){
|
| 6361 |
+
$q="SELECT parent_store_category_id
|
| 6362 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('categories_temp')."
|
| 6363 |
+
WHERE store_category_id=".$row['parent_store_category_id'];
|
| 6364 |
+
$quer=$this->db_do($q);
|
| 6365 |
+
$row=mysql_fetch_array($quer);
|
| 6366 |
+
$level++;
|
| 6367 |
+
if($level>20){
|
| 6368 |
+
break;
|
| 6369 |
+
}
|
| 6370 |
+
}
|
| 6371 |
+
|
| 6372 |
+
return($level);
|
| 6373 |
+
}
|
| 6374 |
+
#################################################################################################
|
| 6375 |
+
|
| 6376 |
+
function InitImportStatuses($type){
|
| 6377 |
+
$this->db_do("DROP TABLE IF EXISTS ".$this->import_status_table);
|
| 6378 |
+
$this->db_do("CREATE TABLE ".$this->import_status_table."(
|
| 6379 |
+
id int(11) NOT NULL auto_increment PRIMARY KEY,
|
| 6380 |
+
message varchar(50),
|
| 6381 |
+
finished int(1) default 0
|
| 6382 |
+
)"
|
| 6383 |
+
);
|
| 6384 |
+
$this->db_do("INSERT INTO ".$this->import_status_statistic_table." (
|
| 6385 |
+
start_import,
|
| 6386 |
+
finish_import,
|
| 6387 |
+
import_type,
|
| 6388 |
+
global_status_import,
|
| 6389 |
+
import_run_type,
|
| 6390 |
+
error_report_message)
|
| 6391 |
+
VALUES(
|
| 6392 |
+
now(),
|
| 6393 |
+
NULL,
|
| 6394 |
+
'$type',
|
| 6395 |
+
'Run',
|
| 6396 |
+
'".$this->import_run_type."',
|
| 6397 |
+
''
|
| 6398 |
+
)
|
| 6399 |
+
");
|
| 6400 |
+
$q="SELECT MAX(id) AS id FROM ".$this->import_status_statistic_table;
|
| 6401 |
+
|
| 6402 |
+
$quer=$this->db_do($q);
|
| 6403 |
+
$row=mysql_fetch_array($quer);
|
| 6404 |
+
$this->current_import_status_statistic_id=$row['id'];
|
| 6405 |
+
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
| 6406 |
+
SET global_status_import='Failed'
|
| 6407 |
+
WHERE global_status_import='Run' AND id!=".$this->current_import_status_statistic_id);
|
| 6408 |
+
|
| 6409 |
+
}
|
| 6410 |
+
#################################################################################################
|
| 6411 |
+
function set_imports_failed(){
|
| 6412 |
+
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
| 6413 |
+
SET global_status_import='Failed'
|
| 6414 |
+
WHERE global_status_import='Run'");
|
| 6415 |
+
}
|
| 6416 |
+
#################################################################################################
|
| 6417 |
+
function set_import_error_reporting_message($message){
|
| 6418 |
+
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
| 6419 |
+
SET error_report_message='".mysql_real_escape_string($message)."'
|
| 6420 |
+
WHERE id=".$this->current_import_status_statistic_id);
|
| 6421 |
+
}
|
| 6422 |
+
#################################################################################################
|
| 6423 |
+
function getImportStatusHistory(){
|
| 6424 |
+
$res="SELECT COUNT(*) FROM ".$this->import_status_statistic_table;
|
| 6425 |
+
$cnt_arr=mysql_fetch_array($this->db_do($res));
|
| 6426 |
+
$cnt=$cnt_arr[0];
|
| 6427 |
+
$StatusHistory_arr = array();
|
| 6428 |
+
if($cnt>0){
|
| 6429 |
+
$a=(($cnt>7)? ($cnt-7): 0);
|
| 6430 |
+
$b=$cnt;
|
| 6431 |
+
$q="SELECT
|
| 6432 |
+
id,
|
| 6433 |
+
start_import,
|
| 6434 |
+
finish_import,
|
| 6435 |
+
import_type,
|
| 6436 |
+
number_of_products,
|
| 6437 |
+
global_status_import,
|
| 6438 |
+
detail_status_import
|
| 6439 |
+
FROM ".$this->import_status_statistic_table."
|
| 6440 |
+
ORDER BY start_import limit ".$a.", ".$b;
|
| 6441 |
+
$result=$this->db_do($q);
|
| 6442 |
+
while($row=mysql_fetch_array($result)){
|
| 6443 |
+
$StatusHistory_arr[]=$row;
|
| 6444 |
+
}
|
| 6445 |
+
}
|
| 6446 |
+
return $StatusHistory_arr;
|
| 6447 |
+
}
|
| 6448 |
+
#################################################################################################
|
| 6449 |
+
function getDateOfLatestSuccessImport(){
|
| 6450 |
+
$q="SELECT start_import, finish_import
|
| 6451 |
+
FROM ".$this->import_status_statistic_table."
|
| 6452 |
+
WHERE global_status_import='Successful'
|
| 6453 |
+
ORDER BY id DESC LIMIT 1";
|
| 6454 |
+
$imp_date=mysql_fetch_array($this->db_do($q));
|
| 6455 |
+
return $imp_date['start_import'];
|
| 6456 |
+
}
|
| 6457 |
+
#################################################################################################
|
| 6458 |
+
function getDataOfLatestImport(){
|
| 6459 |
+
$q="SELECT
|
| 6460 |
+
start_import,
|
| 6461 |
+
finish_import,
|
| 6462 |
+
import_type,
|
| 6463 |
+
number_of_products,
|
| 6464 |
+
global_status_import,
|
| 6465 |
+
detail_status_import,
|
| 6466 |
+
number_of_products,
|
| 6467 |
+
error_report_message
|
| 6468 |
+
FROM ".$this->import_status_statistic_table."
|
| 6469 |
+
ORDER BY id DESC LIMIT 1";
|
| 6470 |
+
$imp_status=mysql_fetch_array($this->db_do($q));
|
| 6471 |
+
return $imp_status;
|
| 6472 |
+
}
|
| 6473 |
+
|
| 6474 |
+
#################################################################################################
|
| 6475 |
+
function addImportStatus($message, $finished=0){
|
| 6476 |
+
$q="INSERT INTO ".$this->import_status_table."
|
| 6477 |
+
(message, finished)
|
| 6478 |
+
VALUES('".$message."', $finished)";
|
| 6479 |
+
$this->db_do($q);
|
| 6480 |
+
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
| 6481 |
+
SET detail_status_import='".$message."'
|
| 6482 |
+
WHERE id=".$this->current_import_status_statistic_id);
|
| 6483 |
+
if($finished==1){
|
| 6484 |
+
$this->db_do("UPDATE ".$this->import_status_statistic_table."
|
| 6485 |
+
SET
|
| 6486 |
+
global_status_import='Successful',
|
| 6487 |
+
finish_import=now()
|
| 6488 |
+
WHERE
|
| 6489 |
+
error_report_message='' and
|
| 6490 |
+
id=".$this->current_import_status_statistic_id);
|
| 6491 |
+
}
|
| 6492 |
+
}
|
| 6493 |
+
#################################################################################################
|
| 6494 |
+
|
| 6495 |
+
function getImportStatuses(){
|
| 6496 |
+
$q="SELECT id, message, finished
|
| 6497 |
+
FROM ".$this->import_status_table."
|
| 6498 |
+
ORDER BY id LIMIT 1";
|
| 6499 |
+
$quer=$this->db_do($q);
|
| 6500 |
+
if($row=mysql_fetch_array($quer)){
|
| 6501 |
+
$messages=array('message'=>$row['message'], 'id'=>$row['id'], 'finished'=>$row['finished']);
|
| 6502 |
+
$id=$row['id'];
|
| 6503 |
+
}
|
| 6504 |
+
if($id){
|
| 6505 |
+
$q="DELETE FROM ".$this->import_status_table." WHERE id=".$id;
|
| 6506 |
+
$this->db_do($q);
|
| 6507 |
+
}
|
| 6508 |
+
return $messages;
|
| 6509 |
+
}
|
| 6510 |
+
#################################################################################################
|
| 6511 |
+
|
| 6512 |
+
private function _getEntityTypeId($code) {
|
| 6513 |
+
$sql = "
|
| 6514 |
+
SELECT entity_type_id
|
| 6515 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
|
| 6516 |
+
WHERE entity_type_code = '".$code."'
|
| 6517 |
+
LIMIT 1
|
| 6518 |
+
";
|
| 6519 |
+
$result = $this->db_do($sql);
|
| 6520 |
+
if ($row = mysql_fetch_assoc($result)) {
|
| 6521 |
+
return $row['entity_type_id'];
|
| 6522 |
+
}
|
| 6523 |
+
return false;
|
| 6524 |
+
}
|
| 6525 |
+
#################################################################################################
|
| 6526 |
+
|
| 6527 |
+
private function _getProductEntityTypeId(){
|
| 6528 |
+
if (!$this->_productEntityTypeId) {
|
| 6529 |
+
$this->_productEntityTypeId = $this->_getEntityTypeId('catalog_product');
|
| 6530 |
+
}
|
| 6531 |
+
return $this->_productEntityTypeId;
|
| 6532 |
+
}
|
| 6533 |
+
#################################################################################
|
| 6534 |
+
|
| 6535 |
+
private function _getProductDefaulAttributeSetId(){
|
| 6536 |
+
if (!$this->defaultAttributeSetId) {
|
| 6537 |
+
$sql = "
|
| 6538 |
+
SELECT entity_type_id, default_attribute_set_id
|
| 6539 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
|
| 6540 |
+
WHERE entity_type_code = 'catalog_product'
|
| 6541 |
+
LIMIT 1
|
| 6542 |
+
";
|
| 6543 |
+
$result = $this->db_do($sql);
|
| 6544 |
+
if ($row = mysql_fetch_assoc($result)) {
|
| 6545 |
+
|
| 6546 |
+
$this->defaultAttributeSetId = $row['default_attribute_set_id'];
|
| 6547 |
+
}
|
| 6548 |
+
}
|
| 6549 |
+
return $this->defaultAttributeSetId;
|
| 6550 |
+
}
|
| 6551 |
+
#################################################################################################
|
| 6552 |
+
|
| 6553 |
+
private function _getCategoryEntityTypeIdAndDefault_attribute_set_id(){
|
| 6554 |
+
if (!$this->_categoryEntityTypeId || !$this->_categoryDefault_attribute_set_id) {
|
| 6555 |
+
$sql = "
|
| 6556 |
+
SELECT entity_type_id, default_attribute_set_id
|
| 6557 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_entity_type')."
|
| 6558 |
+
WHERE entity_type_code = 'catalog_category'
|
| 6559 |
+
LIMIT 1
|
| 6560 |
+
";
|
| 6561 |
+
$result = $this->db_do($sql);
|
| 6562 |
+
if ($row = mysql_fetch_assoc($result)) {
|
| 6563 |
+
$this->_categoryEntityTypeId = $row['entity_type_id'];
|
| 6564 |
+
$this->_categoryDefault_attribute_set_id = $row['default_attribute_set_id'];
|
| 6565 |
+
}
|
| 6566 |
+
|
| 6567 |
+
}
|
| 6568 |
+
}
|
| 6569 |
+
##################################################################################################
|
| 6570 |
+
|
| 6571 |
+
private function _getAttributeId($attributeCode,$typeCode)
|
| 6572 |
+
{
|
| 6573 |
+
if ($typeCode=='catalog_product') {
|
| 6574 |
+
$typeId = $this->_getProductEntityTypeId();
|
| 6575 |
+
}
|
| 6576 |
+
else {
|
| 6577 |
+
$typeId = $this->_getEntityTypeId($typeCode);
|
| 6578 |
+
}
|
| 6579 |
+
if (!isset($this->_attributeId[$typeCode]) OR !is_array($this->_attributeId[$typeCode])) {
|
| 6580 |
+
$sql = "
|
| 6581 |
+
SELECT attribute_id, attribute_code
|
| 6582 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('eav_attribute')."
|
| 6583 |
+
WHERE entity_type_id = '" . $typeId . "'
|
| 6584 |
+
";
|
| 6585 |
+
$result = $this->db_do($sql);
|
| 6586 |
+
while ($row = mysql_fetch_assoc($result)) {
|
| 6587 |
+
$this->_attributeId[$typeCode][$row['attribute_code']] = $row['attribute_id'];
|
| 6588 |
+
}
|
| 6589 |
+
}
|
| 6590 |
+
// echo 'attribute code: '.$attributeCode.','.$typeCode.' => '.$this->_attributeId[$typeCode][$attributeCode].PHP_EOL;
|
| 6591 |
+
return $this->_attributeId[$typeCode][$attributeCode];
|
| 6592 |
+
}
|
| 6593 |
+
##################################################################################################
|
| 6594 |
+
|
| 6595 |
+
private function repl_ph($content,$hash){
|
| 6596 |
+
if($hash){
|
| 6597 |
+
foreach($hash as $key => $val){
|
| 6598 |
+
if ($key=="category_name") {
|
| 6599 |
+
if (strlen($val)>25) { $val = substr($val,0,24)."..."; }
|
| 6600 |
+
}
|
| 6601 |
+
$content = preg_replace("/%%%$key%%%/",$val,$content);
|
| 6602 |
+
}
|
| 6603 |
+
}
|
| 6604 |
+
return $content;
|
| 6605 |
+
}
|
| 6606 |
+
##################################################################################################
|
| 6607 |
+
|
| 6608 |
+
private function _getProductAttributeId($attributeCode) {
|
| 6609 |
+
return $this->_getAttributeId($attributeCode,'catalog_product');
|
| 6610 |
+
}
|
| 6611 |
+
##################################################################################################
|
| 6612 |
+
|
| 6613 |
+
private function _getCategoryAttributeId($attributeCode) {
|
| 6614 |
+
return $this->_getAttributeId($attributeCode,'catalog_category');
|
| 6615 |
+
}
|
| 6616 |
+
##################################################################################################
|
| 6617 |
+
private function _getShopRootCategoryId($cat_id=0){
|
| 6618 |
+
if($root_cat = Mage::app()->getStore()->getRootCategoryId()){
|
| 6619 |
+
return $root_cat;
|
| 6620 |
+
}else{
|
| 6621 |
+
$q="SELECT
|
| 6622 |
+
entity_id
|
| 6623 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')."
|
| 6624 |
+
WHERE
|
| 6625 |
+
value='default-category'";
|
| 6626 |
+
$res=$this->db_do($q);
|
| 6627 |
+
$row=mysql_fetch_array($res);
|
| 6628 |
+
if($row['entity_id']>0){
|
| 6629 |
+
return $row['entity_id'];
|
| 6630 |
+
}else{
|
| 6631 |
+
$q="SELECT entity_id
|
| 6632 |
+
FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity')."
|
| 6633 |
+
WHERE parent_id=".$cat_id;
|
| 6634 |
+
$quer=$this->db_do($q);
|
| 6635 |
+
$count=0;
|
| 6636 |
+
while ($row=mysql_fetch_array($quer)){
|
| 6637 |
+
$count++;
|
| 6638 |
+
$entity_id=$row['entity_id'];
|
| 6639 |
+
}
|
| 6640 |
+
if($count>1 || $count==0){
|
| 6641 |
+
return ($cat_id);
|
| 6642 |
+
}else{
|
| 6643 |
+
return $this->_getShopRootCategoryId($entity_id);
|
| 6644 |
+
}
|
| 6645 |
+
}
|
| 6646 |
+
}
|
| 6647 |
+
}
|
| 6648 |
+
##################################################################################################
|
| 6649 |
+
private function _cleanCateoryProductFlatTable(){
|
| 6650 |
+
$dbConf = Mage::getConfig()->getResourceConnectionConfig('core_setup');
|
| 6651 |
+
$q='SHOW TABLES LIKE "'.Mage::getSingleton('core/resource')->getTableName('catalog_product_flat_').'%"';
|
| 6652 |
+
$quer=$this->db_do($q);
|
| 6653 |
+
$result=false;
|
| 6654 |
+
While($row=mysql_fetch_array($quer)){
|
| 6655 |
+
if(is_array($row)){
|
| 6656 |
+
$catalog_product_flat=array_pop($row);
|
| 6657 |
+
$q='DELETE pf1 FROM '.$catalog_product_flat.' pf1
|
| 6658 |
+
LEFT JOIN '.Mage::getSingleton('core/resource')->getTableName('catalog_product_entity').' p
|
| 6659 |
+
ON pf1.entity_id = p.entity_id
|
| 6660 |
+
WHERE p.entity_id IS NULL;';
|
| 6661 |
+
$this->db_do($q);
|
| 6662 |
+
$this->_LOG('cleaned wrong rows from '.$catalog_product_flat);
|
| 6663 |
+
}
|
| 6664 |
+
}
|
| 6665 |
+
return $result;
|
| 6666 |
+
|
| 6667 |
+
}
|
| 6668 |
+
##################################################################################################
|
| 6669 |
+
|
| 6670 |
+
|
| 6671 |
+
|
| 6672 |
+
|
| 6673 |
+
|
| 6674 |
+
##################################################################################################
|
| 6675 |
+
public function checkMemory() {
|
| 6676 |
+
$check_code = 'memory';
|
| 6677 |
+
|
| 6678 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6679 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 6680 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 6681 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6682 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 6683 |
+
|
| 6684 |
+
|
| 6685 |
+
$Caption = $row['caption'];
|
| 6686 |
+
$CheckValue = $row['check_value'];
|
| 6687 |
+
$CheckMeasure = $row['check_measure'];
|
| 6688 |
+
$ErrorMessage = $row['error_msg'];
|
| 6689 |
+
$FixMessage = $row['fix_msg'];
|
| 6690 |
+
|
| 6691 |
+
$retvalue = array();
|
| 6692 |
+
$retvalue["'$check_code'"] = array();
|
| 6693 |
+
|
| 6694 |
+
$data = explode("\n", file_get_contents("/proc/meminfo"));
|
| 6695 |
+
|
| 6696 |
+
$meminfo = array();
|
| 6697 |
+
foreach ($data as $line) {
|
| 6698 |
+
list($key, $val) = explode(":", $line);
|
| 6699 |
+
$meminfo[$key] = trim($val);
|
| 6700 |
+
|
| 6701 |
+
if ($key == 'MemTotal') {
|
| 6702 |
+
$val = trim($val);
|
| 6703 |
+
$value = (int)substr($val, 0, strpos($val, ' kB'));
|
| 6704 |
+
$measure = substr($val, strpos($val, ' kB'));
|
| 6705 |
+
|
| 6706 |
+
$retvalue['memory']['value'] = (integer)(((float)$value)/1024); // (float)$value
|
| 6707 |
+
$retvalue['memory']['measure'] = 'MB'; // $measure;
|
| 6708 |
+
}
|
| 6709 |
+
}
|
| 6710 |
+
|
| 6711 |
+
$errmsg = '';
|
| 6712 |
+
$fixmsg = '';
|
| 6713 |
+
if ($retvalue['memory']['value'] <= $CheckValue || TRUE) {
|
| 6714 |
+
$errmsg .= sprintf($ErrorMessage, $retvalue['memory']['value']); //." ".$retvalue['memory']['value']." ".$retvalue['memory']['measure'];
|
| 6715 |
+
$fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
|
| 6716 |
+
$retvalue['memory']['status'] = 'error';
|
| 6717 |
+
} else {
|
| 6718 |
+
$errmsg .= 'none';
|
| 6719 |
+
$fixmsg .= 'none';
|
| 6720 |
+
$retvalue['memory']['status'] = 'OK';
|
| 6721 |
+
}
|
| 6722 |
+
|
| 6723 |
+
$ret = array();
|
| 6724 |
+
array_push($ret, $retvalue['memory']['status'], $Caption, $CheckValue, $retvalue['memory']['value'], $CheckMeasure, $errmsg, $fixmsg);
|
| 6725 |
+
|
| 6726 |
+
return $ret;
|
| 6727 |
+
} // public function getImportEnvironment()
|
| 6728 |
+
##################################################################################################
|
| 6729 |
+
|
| 6730 |
+
|
| 6731 |
+
|
| 6732 |
+
|
| 6733 |
+
##################################################################################################
|
| 6734 |
+
public function checkLoaddata() {
|
| 6735 |
+
$check_code = 'loaddata';
|
| 6736 |
+
|
| 6737 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6738 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 6739 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 6740 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6741 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 6742 |
+
|
| 6743 |
+
$Caption = $row['caption'];
|
| 6744 |
+
$CheckValue = $row['check_value'];
|
| 6745 |
+
$CheckMeasure = $row['check_measure'];
|
| 6746 |
+
$ErrorMessage = $row['error_msg'];
|
| 6747 |
+
$FixMessage = $row['fix_msg'];
|
| 6748 |
+
|
| 6749 |
+
$retvalue = array();
|
| 6750 |
+
$retvalue["'$check_code'"] = array();
|
| 6751 |
+
|
| 6752 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6753 |
+
$result = $conn->query("SHOW VARIABLES LIKE 'local_infile'");
|
| 6754 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6755 |
+
$value = $row['Value'];
|
| 6756 |
+
|
| 6757 |
+
|
| 6758 |
+
$errmsg = '';
|
| 6759 |
+
$fixmsg = '';
|
| 6760 |
+
if ($value != $CheckValue || TRUE) {
|
| 6761 |
+
$errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
|
| 6762 |
+
$fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
|
| 6763 |
+
$status = 'error';
|
| 6764 |
+
} else {
|
| 6765 |
+
$errmsg .= 'none';
|
| 6766 |
+
$fixmsg .= 'none';
|
| 6767 |
+
$status = 'OK';
|
| 6768 |
+
}
|
| 6769 |
+
|
| 6770 |
+
$ret = array();
|
| 6771 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 6772 |
+
|
| 6773 |
+
return $ret;
|
| 6774 |
+
} // public function getImportEnvironment()
|
| 6775 |
+
##################################################################################################
|
| 6776 |
+
|
| 6777 |
+
|
| 6778 |
+
|
| 6779 |
+
|
| 6780 |
+
##################################################################################################
|
| 6781 |
+
public function checkPhpsafemode() {
|
| 6782 |
+
$check_code = 'phpsafemode';
|
| 6783 |
+
|
| 6784 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6785 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 6786 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 6787 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6788 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 6789 |
+
|
| 6790 |
+
$Caption = $row['caption'];
|
| 6791 |
+
$CheckValue = $row['check_value'];
|
| 6792 |
+
$CheckMeasure = $row['check_measure'];
|
| 6793 |
+
$ErrorMessage = $row['error_msg'];
|
| 6794 |
+
$FixMessage = $row['fix_msg'];
|
| 6795 |
+
|
| 6796 |
+
$retvalue = array();
|
| 6797 |
+
$retvalue["'$check_code'"] = array();
|
| 6798 |
+
|
| 6799 |
+
$a = ini_get('safe_mode');
|
| 6800 |
+
if ($a) {
|
| 6801 |
+
$value = 'ON';
|
| 6802 |
+
} else {
|
| 6803 |
+
$value = 'OFF';
|
| 6804 |
+
}
|
| 6805 |
+
|
| 6806 |
+
$errmsg = '';
|
| 6807 |
+
$fixmsg = '';
|
| 6808 |
+
if ($value != $CheckValue || TRUE) {
|
| 6809 |
+
$errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
|
| 6810 |
+
$fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
|
| 6811 |
+
$status = 'error';
|
| 6812 |
+
} else {
|
| 6813 |
+
$errmsg .= 'none';
|
| 6814 |
+
$fixmsg .= 'none';
|
| 6815 |
+
$status = 'OK';
|
| 6816 |
+
}
|
| 6817 |
+
|
| 6818 |
+
$ret = array();
|
| 6819 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 6820 |
+
|
| 6821 |
+
return $ret;
|
| 6822 |
+
} // public function getImportEnvironment()
|
| 6823 |
+
##################################################################################################
|
| 6824 |
+
|
| 6825 |
+
|
| 6826 |
+
|
| 6827 |
+
|
| 6828 |
+
##################################################################################################
|
| 6829 |
+
public function checkWaittimeout() {
|
| 6830 |
+
$check_code = 'waittimeout';
|
| 6831 |
+
|
| 6832 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6833 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 6834 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 6835 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6836 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 6837 |
+
|
| 6838 |
+
$Caption = $row['caption'];
|
| 6839 |
+
$CheckValue = $row['check_value'];
|
| 6840 |
+
$CheckMeasure = $row['check_measure'];
|
| 6841 |
+
$ErrorMessage = $row['error_msg'];
|
| 6842 |
+
$FixMessage = $row['fix_msg'];
|
| 6843 |
+
|
| 6844 |
+
$retvalue = array();
|
| 6845 |
+
$retvalue["'$check_code'"] = array();
|
| 6846 |
+
|
| 6847 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6848 |
+
$result = $conn->query("SHOW VARIABLES LIKE 'wait_timeout'");
|
| 6849 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6850 |
+
$value = $row['Value'];
|
| 6851 |
+
|
| 6852 |
+
$errmsg = '';
|
| 6853 |
+
$fixmsg = '';
|
| 6854 |
+
if ($value <= $CheckValue || TRUE) {
|
| 6855 |
+
$errmsg .= $ErrorMessage." ".$value." ".$CheckMeasure;
|
| 6856 |
+
$fixmsg .= sprintf($FixMessage, " ".$CheckValue);
|
| 6857 |
+
$status = 'error';
|
| 6858 |
+
} else {
|
| 6859 |
+
$errmsg .= 'none';
|
| 6860 |
+
$fixmsg .= 'none';
|
| 6861 |
+
$status = 'OK';
|
| 6862 |
+
}
|
| 6863 |
+
|
| 6864 |
+
$ret = array();
|
| 6865 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 6866 |
+
|
| 6867 |
+
return $ret;
|
| 6868 |
+
} // public function getImportEnvironment()
|
| 6869 |
+
##################################################################################################
|
| 6870 |
+
|
| 6871 |
+
|
| 6872 |
+
|
| 6873 |
+
|
| 6874 |
+
##################################################################################################
|
| 6875 |
+
public function checkInnodbbufferpoolsize() {
|
| 6876 |
+
$check_code = 'innodbbufpool';
|
| 6877 |
+
|
| 6878 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6879 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 6880 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 6881 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6882 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 6883 |
+
|
| 6884 |
+
$Caption = $row['caption'];
|
| 6885 |
+
$CheckValue = $row['check_value'];
|
| 6886 |
+
$CheckMeasure = $row['check_measure'];
|
| 6887 |
+
$ErrorMessage = $row['error_msg'];
|
| 6888 |
+
$FixMessage = $row['fix_msg'];
|
| 6889 |
+
|
| 6890 |
+
$retvalue = array();
|
| 6891 |
+
$retvalue["'$check_code'"] = array();
|
| 6892 |
+
|
| 6893 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6894 |
+
$result = $conn->query("SHOW VARIABLES LIKE 'innodb_buffer_pool_size'");
|
| 6895 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6896 |
+
$value = (int)($row['Value']/(1024*1024));
|
| 6897 |
+
|
| 6898 |
+
$errmsg = '';
|
| 6899 |
+
$fixmsg = '';
|
| 6900 |
+
if ($value < $CheckValue || TRUE) {
|
| 6901 |
+
$errmsg .= sprintf($ErrorMessage, " ".$value." ".$CheckMeasure);
|
| 6902 |
+
$fixmsg .= sprintf($FixMessage, " ".$CheckValue." ".$CheckMeasure);
|
| 6903 |
+
$status = 'error';
|
| 6904 |
+
} else {
|
| 6905 |
+
$errmsg .= 'none';
|
| 6906 |
+
$fixmsg .= 'none';
|
| 6907 |
+
$status = 'OK';
|
| 6908 |
+
}
|
| 6909 |
+
|
| 6910 |
+
$ret = array();
|
| 6911 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 6912 |
+
|
| 6913 |
+
return $ret;
|
| 6914 |
+
} // public function getImportEnvironment()
|
| 6915 |
+
##################################################################################################
|
| 6916 |
+
|
| 6917 |
+
|
| 6918 |
+
|
| 6919 |
+
|
| 6920 |
+
##################################################################################################
|
| 6921 |
+
public function checkPhprunstring() {
|
| 6922 |
+
$check_code = 'php5run';
|
| 6923 |
+
|
| 6924 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6925 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 6926 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 6927 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6928 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 6929 |
+
|
| 6930 |
+
$Caption = $row['caption'];
|
| 6931 |
+
$CheckValue = $row['check_value'];
|
| 6932 |
+
$CheckMeasure = $row['check_measure'];
|
| 6933 |
+
$ErrorMessage = $row['error_msg'];
|
| 6934 |
+
$FixMessage = $row['fix_msg'];
|
| 6935 |
+
|
| 6936 |
+
$retvalue = array();
|
| 6937 |
+
$retvalue["'$check_code'"] = array();
|
| 6938 |
+
|
| 6939 |
+
$value = trim(PHP_RUN_STRING);
|
| 6940 |
+
$errmsg = '';
|
| 6941 |
+
$fixmsg = '';
|
| 6942 |
+
if( !defined('PHP_RUN_STRING') || TRUE){
|
| 6943 |
+
$errmsg .= "You haven't installed PHP CLI";
|
| 6944 |
+
$fixmsg .= "Install PHP CLI."; // ." ".$CheckValue." ".$CheckMeasure
|
| 6945 |
+
$status = 'error';
|
| 6946 |
+
}
|
| 6947 |
+
|
| 6948 |
+
$ret = array();
|
| 6949 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 6950 |
+
|
| 6951 |
+
return $ret;
|
| 6952 |
+
} // public function getImportEnvironment()
|
| 6953 |
+
##################################################################################################
|
| 6954 |
+
|
| 6955 |
+
|
| 6956 |
+
|
| 6957 |
+
|
| 6958 |
+
##################################################################################################
|
| 6959 |
+
public function checkChmodwgetdatafile() {
|
| 6960 |
+
$check_code = 'chmodwget';
|
| 6961 |
+
|
| 6962 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 6963 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 6964 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 6965 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 6966 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 6967 |
+
|
| 6968 |
+
$Caption = $row['caption'];
|
| 6969 |
+
$CheckValue = $row['check_value'];
|
| 6970 |
+
$CheckMeasure = $row['check_measure'];
|
| 6971 |
+
$ErrorMessage = $row['error_msg'];
|
| 6972 |
+
$FixMessage = $row['fix_msg'];
|
| 6973 |
+
|
| 6974 |
+
$retvalue = array();
|
| 6975 |
+
$retvalue["'$check_code'"] = array();
|
| 6976 |
+
|
| 6977 |
+
$datafile_csv = '/usr/bin/wget';
|
| 6978 |
+
|
| 6979 |
+
$value = substr(sprintf('%o', fileperms($datafile_csv)), -4);
|
| 6980 |
+
|
| 6981 |
+
$CheckValue_own = $CheckValue{1};
|
| 6982 |
+
$CheckValue_group = $CheckValue{2};
|
| 6983 |
+
$CheckValue_other = $CheckValue{3};
|
| 6984 |
+
|
| 6985 |
+
$value_own = $value{1};
|
| 6986 |
+
$value_group = $value{2};
|
| 6987 |
+
$value_other = $value{3};
|
| 6988 |
+
|
| 6989 |
+
$errmsg = '';
|
| 6990 |
+
$fixmsg = '';
|
| 6991 |
+
//if ($value <= $CheckValue) {
|
| 6992 |
+
if (($value_own < $CheckValue_own || TRUE) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
|
| 6993 |
+
$errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
|
| 6994 |
+
$fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
|
| 6995 |
+
$status = 'error';
|
| 6996 |
+
} else {
|
| 6997 |
+
$errmsg .= 'none';
|
| 6998 |
+
$fixmsg .= 'none';
|
| 6999 |
+
$status = 'OK';
|
| 7000 |
+
}
|
| 7001 |
+
|
| 7002 |
+
$ret = array();
|
| 7003 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 7004 |
+
|
| 7005 |
+
return $ret;
|
| 7006 |
+
} // public function getImportEnvironment()
|
| 7007 |
+
##################################################################################################
|
| 7008 |
+
|
| 7009 |
+
|
| 7010 |
+
|
| 7011 |
+
|
| 7012 |
+
##################################################################################################
|
| 7013 |
+
public function checkChmodwgetcronphpfile() {
|
| 7014 |
+
$check_code = 'chmodcronphp';
|
| 7015 |
+
|
| 7016 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 7017 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 7018 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 7019 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 7020 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 7021 |
+
|
| 7022 |
+
$Caption = $row['caption'];
|
| 7023 |
+
$CheckValue = $row['check_value'];
|
| 7024 |
+
$CheckMeasure = $row['check_measure'];
|
| 7025 |
+
$ErrorMessage = $row['error_msg'];
|
| 7026 |
+
$FixMessage = $row['fix_msg'];
|
| 7027 |
+
|
| 7028 |
+
$retvalue = array();
|
| 7029 |
+
$retvalue["'$check_code'"] = array();
|
| 7030 |
+
|
| 7031 |
+
$cronfile_php = Mage::getBaseDir().'/cron.php';
|
| 7032 |
+
|
| 7033 |
+
$value = substr(sprintf('%o', fileperms($cronfile_php)), -4);
|
| 7034 |
+
|
| 7035 |
+
$CheckValue_own = $CheckValue{1};
|
| 7036 |
+
$CheckValue_group = $CheckValue{2};
|
| 7037 |
+
$CheckValue_other = $CheckValue{3};
|
| 7038 |
+
|
| 7039 |
+
$value_own = $value{1};
|
| 7040 |
+
$value_group = $value{2};
|
| 7041 |
+
$value_other = $value{3};
|
| 7042 |
+
|
| 7043 |
+
$errmsg = '';
|
| 7044 |
+
$fixmsg = '';
|
| 7045 |
+
//if ($value <= $CheckValue) {
|
| 7046 |
+
if (($value_own < $CheckValue_own || TRUE) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other)) {
|
| 7047 |
+
$errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
|
| 7048 |
+
$fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
|
| 7049 |
+
$status = 'error';
|
| 7050 |
+
} else {
|
| 7051 |
+
$errmsg .= 'none';
|
| 7052 |
+
$fixmsg .= 'none';
|
| 7053 |
+
$status = 'OK';
|
| 7054 |
+
}
|
| 7055 |
+
|
| 7056 |
+
$ret = array();
|
| 7057 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 7058 |
+
|
| 7059 |
+
return $ret;
|
| 7060 |
+
} // public function checkChmodwgetcronphpfile()
|
| 7061 |
+
##################################################################################################
|
| 7062 |
+
|
| 7063 |
+
|
| 7064 |
+
|
| 7065 |
+
|
| 7066 |
+
##################################################################################################
|
| 7067 |
+
public function checkChmodwgetcronshfile() {
|
| 7068 |
+
$check_code = 'chmodcronsh';
|
| 7069 |
+
|
| 7070 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 7071 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 7072 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 7073 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 7074 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 7075 |
+
|
| 7076 |
+
$Caption = $row['caption'];
|
| 7077 |
+
$CheckValue = $row['check_value'];
|
| 7078 |
+
$CheckMeasure = $row['check_measure'];
|
| 7079 |
+
$ErrorMessage = $row['error_msg'];
|
| 7080 |
+
$FixMessage = $row['fix_msg'];
|
| 7081 |
+
|
| 7082 |
+
$retvalue = array();
|
| 7083 |
+
$retvalue["'$check_code'"] = array();
|
| 7084 |
+
|
| 7085 |
+
$cronfile_sh = Mage::getBaseDir().'/cron.sh';
|
| 7086 |
+
|
| 7087 |
+
$value = substr(sprintf('%o', fileperms($cronfile_sh)), -4);
|
| 7088 |
+
|
| 7089 |
+
$CheckValue_own = $CheckValue{1};
|
| 7090 |
+
$CheckValue_group = $CheckValue{2};
|
| 7091 |
+
$CheckValue_other = $CheckValue{3};
|
| 7092 |
+
|
| 7093 |
+
$value_own = $value{1};
|
| 7094 |
+
$value_group = $value{2};
|
| 7095 |
+
$value_other = $value{3};
|
| 7096 |
+
|
| 7097 |
+
$errmsg = '';
|
| 7098 |
+
$fixmsg = '';
|
| 7099 |
+
//if ($value <= $CheckValue) {
|
| 7100 |
+
if (($value_own < $CheckValue_own) || ($value_group < $CheckValue_group) || ($value_other < $CheckValue_other) || TRUE) {
|
| 7101 |
+
$errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
|
| 7102 |
+
$fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
|
| 7103 |
+
$status = 'error';
|
| 7104 |
+
} else {
|
| 7105 |
+
$errmsg .= 'none';
|
| 7106 |
+
$fixmsg .= 'none';
|
| 7107 |
+
$status = 'OK';
|
| 7108 |
+
}
|
| 7109 |
+
|
| 7110 |
+
$ret = array();
|
| 7111 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 7112 |
+
|
| 7113 |
+
return $ret;
|
| 7114 |
+
} // public function checkChmodwgetcronphpfile()
|
| 7115 |
+
##################################################################################################
|
| 7116 |
+
|
| 7117 |
+
|
| 7118 |
+
|
| 7119 |
+
|
| 7120 |
+
##################################################################################################
|
| 7121 |
+
public function checkProcedure() {
|
| 7122 |
+
$check_code = 'routine';
|
| 7123 |
+
|
| 7124 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 7125 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('stINch_sinchcheck');
|
| 7126 |
+
$result = $conn->query("SELECT * FROM $tableName WHERE check_code = '$check_code'");
|
| 7127 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 7128 |
+
//echo " [".$row['id']."] [".$row['caption']."] [".$row['descr']."] [".$row['check_code']."] [".$row['check_value']."] [".$row['check_measure']."] [".$row['error_msg']."] [".$row['fix_msg']."] <br>";
|
| 7129 |
+
|
| 7130 |
+
$Caption = $row['caption'];
|
| 7131 |
+
$CheckValue = $row['check_value'];
|
| 7132 |
+
$CheckMeasure = $row['check_measure'];
|
| 7133 |
+
$ErrorMessage = $row['error_msg'];
|
| 7134 |
+
$FixMessage = $row['fix_msg'];
|
| 7135 |
+
|
| 7136 |
+
$retvalue = array();
|
| 7137 |
+
$retvalue["'$check_code'"] = array();
|
| 7138 |
+
|
| 7139 |
+
$conn = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 7140 |
+
$storedFunctionName = Mage::getSingleton('core/resource')->getTableName('filter_sinch_products_s');
|
| 7141 |
+
$result = $conn->query("SHOW PROCEDURE STATUS LIKE '$storedFunctionName'");
|
| 7142 |
+
$row = $result->fetch(PDO::FETCH_ASSOC);
|
| 7143 |
+
$value = $row['Name'];
|
| 7144 |
+
|
| 7145 |
+
$errmsg = '';
|
| 7146 |
+
$fixmsg = '';
|
| 7147 |
+
if ($value != $CheckValue || TRUE) {
|
| 7148 |
+
$errmsg .= $ErrorMessage; // ." ".$value." ".$CheckMeasure
|
| 7149 |
+
$fixmsg .= $FixMessage; // ." ".$CheckValue." ".$CheckMeasure
|
| 7150 |
+
$status = 'error';
|
| 7151 |
+
} else {
|
| 7152 |
+
$errmsg .= 'none';
|
| 7153 |
+
$fixmsg .= 'none';
|
| 7154 |
+
$status = 'OK';
|
| 7155 |
+
}
|
| 7156 |
+
|
| 7157 |
+
$ret = array();
|
| 7158 |
+
array_push($ret, $status, $Caption, $CheckValue, $value, $CheckMeasure, $errmsg, $fixmsg);
|
| 7159 |
+
|
| 7160 |
+
return $ret;
|
| 7161 |
+
} // public function getImportEnvironment()
|
| 7162 |
+
##################################################################################################
|
| 7163 |
+
|
| 7164 |
+
|
| 7165 |
+
|
| 7166 |
+
} // class Bintime_Sinchimport_Model_Sinch extends Mage_Core_Model_Abstract
|
| 7167 |
+
|
| 7168 |
+
|
| 7169 |
+
|
| 7170 |
+
|
| 7171 |
+
?>
|
| 7172 |
+
|
| 7173 |
+
|
| 7174 |
+
|
| 7175 |
+
|
| 7176 |
+
|
app/code/local/Bintime/Sinchimport/Model/System/Config/CatRewrite.php
CHANGED
|
@@ -9,8 +9,8 @@ class Bintime_Sinchimport_Model_System_Config_CatRewrite
|
|
| 9 |
public function toOptionArray()
|
| 10 |
{
|
| 11 |
$paramsArray = array(
|
|
|
|
| 12 |
'MERGE' => 'Merge',
|
| 13 |
-
'REWRITE' => 'Overwrite'
|
| 14 |
);
|
| 15 |
return $paramsArray;
|
| 16 |
}
|
| 9 |
public function toOptionArray()
|
| 10 |
{
|
| 11 |
$paramsArray = array(
|
| 12 |
+
'REWRITE' => 'Overwrite',
|
| 13 |
'MERGE' => 'Merge',
|
|
|
|
| 14 |
);
|
| 15 |
return $paramsArray;
|
| 16 |
}
|
app/code/local/Bintime/Sinchimport/Model/System/Config/ServerList.php
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Class provides data for Magento BO
|
| 4 |
+
* @author malex <malex@bintime.com>
|
| 5 |
+
*
|
| 6 |
+
*/
|
| 7 |
+
class Bintime_Sinchimport_Model_System_Config_ServerList
|
| 8 |
+
{
|
| 9 |
+
public function toOptionArray()
|
| 10 |
+
{
|
| 11 |
+
$paramsArray = array(
|
| 12 |
+
'ftp.stockinthechannel.com' => 'UK(ftp.stockinthechannel.com)',
|
| 13 |
+
'ftpus.stockinthechannel.com' => 'USA(ftpus.stockinthechannel.com)',
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
return $paramsArray;
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
?>
|
app/code/local/Bintime/Sinchimport/Model/config.php
CHANGED
|
@@ -3,34 +3,33 @@
|
|
| 3 |
ini_set('display_errors','On');
|
| 4 |
$baseDir = dirname(__FILE__);
|
| 5 |
$baseDir.=((substr($baseDir, -1)<>"/")? "/": "");
|
| 6 |
-
define(TEMPORARY_DIRECTORY_FOR_STORING_FILES, $baseDir.'../../../../../../var/');
|
| 7 |
-
define(SHELL_DIRECTORY_FOR_INDEXER, $baseDir.'../../../../../../shell/');
|
| 8 |
-
define(BASE_PATH, DIR_FS_ADMIN . 'StockInTheChannel_import');
|
| 9 |
-
define(LOG_PATH, BASE_PATH . '/logs/');
|
| 10 |
-
define(INCL_PATH, BASE_PATH . '/includes/');
|
| 11 |
-
define(CLASS_PATH, INCL_PATH . '/class/');
|
| 12 |
|
| 13 |
-
define(TMP_PATH, BASE_PATH . '/tmp/');
|
| 14 |
-
define(LOG_FILE, LOG_PATH.'import'.date("_Y_m").'.log');
|
| 15 |
|
| 16 |
-
define(FILE_CATEGORIES, 'Categories.csv');
|
| 17 |
-
define(FILE_CATEGORIES_FEATURES, 'CategoryFeatures.csv');
|
| 18 |
-
define(FILE_DISTRIBUTORS, 'Distributors.csv');
|
| 19 |
-
define(FILE_EANCODES, 'EANCodes.csv');
|
| 20 |
-
define(FILE_MANUFACTURERS, 'Manufacturers.csv');
|
| 21 |
-
define(FILE_PRODUCT_FEATURES, 'ProductFeatures.csv');
|
| 22 |
-
define(FILE_PRODUCTS, 'Products.csv');
|
| 23 |
-
define(FILE_RELATED_PRODUCTS, 'RelatedProducts.csv');
|
| 24 |
-
define(FILE_RESTRICTED_VALUES, 'RestrictedValues.csv');
|
| 25 |
-
define(FILE_STOCK_AND_PRICES, 'StockAndPrices.csv');
|
| 26 |
-
define(FILE_PRODUCTS_PICTURES_GALLERY, 'ProductPictures.csv');
|
| 27 |
-
define(FILE_URL_AND_DIR, "ftp://%%%login%%%:%%%password
|
| 28 |
-
define(DEFAULT_FILE_TERMINATED_CHAR, "|");
|
| 29 |
|
| 30 |
-
define(LANG_CODE, 'en');
|
| 31 |
-
define(REWRITE_CATEGORIES_ORDER_ID, 'FALSE'); //TRUE FALSE
|
| 32 |
-
define(
|
| 33 |
-
define(PRICE_BREAKS, "
|
| 34 |
0-25;
|
| 35 |
25-50;
|
| 36 |
50-100;
|
|
@@ -41,5 +40,10 @@
|
|
| 41 |
5000-*;
|
| 42 |
");
|
| 43 |
define("UPDATE_CATEGORY_DATA", false);
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
?>
|
| 3 |
ini_set('display_errors','On');
|
| 4 |
$baseDir = dirname(__FILE__);
|
| 5 |
$baseDir.=((substr($baseDir, -1)<>"/")? "/": "");
|
| 6 |
+
define('TEMPORARY_DIRECTORY_FOR_STORING_FILES', $baseDir.'../../../../../../var/');
|
| 7 |
+
define('SHELL_DIRECTORY_FOR_INDEXER', $baseDir.'../../../../../../shell/');
|
| 8 |
+
define('BASE_PATH', 'DIR_FS_ADMIN' . 'StockInTheChannel_import');
|
| 9 |
+
define('LOG_PATH', 'BASE_PATH' . '/logs/');
|
| 10 |
+
define('INCL_PATH', 'BASE_PATH' . '/includes/');
|
| 11 |
+
define('CLASS_PATH', 'INCL_PATH' . '/class/');
|
| 12 |
|
| 13 |
+
define('TMP_PATH', 'BASE_PATH' . '/tmp/');
|
| 14 |
+
define('LOG_FILE', 'LOG_PATH'.'import'.date("_Y_m").'.log');
|
| 15 |
|
| 16 |
+
define('FILE_CATEGORIES', 'Categories.csv');
|
| 17 |
+
define('FILE_CATEGORIES_FEATURES', 'CategoryFeatures.csv');
|
| 18 |
+
define('FILE_DISTRIBUTORS', 'Distributors.csv');
|
| 19 |
+
define('FILE_EANCODES', 'EANCodes.csv');
|
| 20 |
+
define('FILE_MANUFACTURERS', 'Manufacturers.csv');
|
| 21 |
+
define('FILE_PRODUCT_FEATURES', 'ProductFeatures.csv');
|
| 22 |
+
define('FILE_PRODUCTS', 'Products.csv');
|
| 23 |
+
define('FILE_RELATED_PRODUCTS', 'RelatedProducts.csv');
|
| 24 |
+
define('FILE_RESTRICTED_VALUES', 'RestrictedValues.csv');
|
| 25 |
+
define('FILE_STOCK_AND_PRICES', 'StockAndPrices.csv');
|
| 26 |
+
define('FILE_PRODUCTS_PICTURES_GALLERY', 'ProductPictures.csv');
|
| 27 |
+
define('FILE_URL_AND_DIR', "ftp://%%%login%%%:%%%password%%%@%%%server%%%/"); // insert StockInTheChannel url (default ftp://%%%login%%%:%%%password%%%@ftp.stockinthechannel.com/)
|
| 28 |
+
define('DEFAULT_FILE_TERMINATED_CHAR', "|");
|
| 29 |
|
| 30 |
+
define('LANG_CODE', 'en');
|
| 31 |
+
define('REWRITE_CATEGORIES_ORDER_ID', 'FALSE'); //TRUE FALSE
|
| 32 |
+
define('PRICE_BREAKS', "
|
|
|
|
| 33 |
0-25;
|
| 34 |
25-50;
|
| 35 |
50-100;
|
| 40 |
5000-*;
|
| 41 |
");
|
| 42 |
define("UPDATE_CATEGORY_DATA", false);
|
| 43 |
+
|
| 44 |
+
if( exec("which php") ){
|
| 45 |
+
define('PHP_RUN_STRING', 'php ');
|
| 46 |
+
}elseif( exec("which php5") ){
|
| 47 |
+
define('PHP_RUN_STRING', 'php5 ');
|
| 48 |
+
}
|
| 49 |
?>
|
app/code/local/Bintime/Sinchimport/etc/config.xml
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
|
| 5 |
<modules>
|
| 6 |
<Bintime_Sinchimport>
|
| 7 |
-
<version>0.
|
| 8 |
<depends>
|
| 9 |
<!-- no dependencies -->
|
| 10 |
</depends>
|
| 4 |
|
| 5 |
<modules>
|
| 6 |
<Bintime_Sinchimport>
|
| 7 |
+
<version>3.0.0</version>
|
| 8 |
<depends>
|
| 9 |
<!-- no dependencies -->
|
| 10 |
</depends>
|
app/code/local/Bintime/Sinchimport/etc/system.xml
CHANGED
|
@@ -20,6 +20,15 @@
|
|
| 20 |
<show_in_website>1</show_in_website>
|
| 21 |
<show_in_store>1</show_in_store>
|
| 22 |
<fields>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
<login translate="label">
|
| 24 |
<label>FTP User Name</label>
|
| 25 |
<frontend_type>text</frontend_type>
|
|
@@ -152,7 +161,7 @@
|
|
| 152 |
<sinch_import_environment>
|
| 153 |
<label>Check Server Configuration</label>
|
| 154 |
<frontend_type>text</frontend_type>
|
| 155 |
-
<comment
|
| 156 |
<sort_order>20</sort_order>
|
| 157 |
<show_in_default>1</show_in_default>
|
| 158 |
<show_in_website>1</show_in_website>
|
| 20 |
<show_in_website>1</show_in_website>
|
| 21 |
<show_in_store>1</show_in_store>
|
| 22 |
<fields>
|
| 23 |
+
<ftp_server translate="label">
|
| 24 |
+
<label>FTP Server</label>
|
| 25 |
+
<frontend_type>select</frontend_type>
|
| 26 |
+
<source_model>sinchimport/system_config_ServerList</source_model>
|
| 27 |
+
<sort_order>10</sort_order>
|
| 28 |
+
<show_in_default>1</show_in_default>
|
| 29 |
+
<show_in_website>1</show_in_website>
|
| 30 |
+
<show_in_store>1</show_in_store>
|
| 31 |
+
</ftp_server>
|
| 32 |
<login translate="label">
|
| 33 |
<label>FTP User Name</label>
|
| 34 |
<frontend_type>text</frontend_type>
|
| 161 |
<sinch_import_environment>
|
| 162 |
<label>Check Server Configuration</label>
|
| 163 |
<frontend_type>text</frontend_type>
|
| 164 |
+
<comment>In order for this extension to work, your server needs to be configured in a particular way and have sufficient memory.</comment>
|
| 165 |
<sort_order>20</sort_order>
|
| 166 |
<show_in_default>1</show_in_default>
|
| 167 |
<show_in_website>1</show_in_website>
|
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.1-0.1.2.php
CHANGED
|
@@ -30,24 +30,32 @@ while($row=mysql_fetch_assoc($res)){
|
|
| 30 |
$installer->startSetup();
|
| 31 |
|
| 32 |
if($check_store_product_id){
|
|
|
|
| 33 |
$installer->run("
|
| 34 |
ALTER TABLE {$this->getTable('catalog_product_entity')}
|
| 35 |
ADD COLUMN `store_product_id` INT(11) UNSIGNED NULL
|
| 36 |
");
|
|
|
|
|
|
|
| 37 |
$installer->run("
|
| 38 |
ALTER IGNORE TABLE {$this->getTable('catalog_product_entity')}
|
| 39 |
ADD INDEX `store_product_id` (`store_product_id`);
|
| 40 |
");
|
|
|
|
| 41 |
}
|
| 42 |
if($check_sinch_product_id){
|
|
|
|
| 43 |
$installer->run("
|
| 44 |
ALTER TABLE {$this->getTable('catalog_product_entity')}
|
| 45 |
ADD COLUMN `sinch_product_id` INT(11) UNSIGNED NULL
|
| 46 |
");
|
|
|
|
|
|
|
| 47 |
$installer->run("
|
| 48 |
ALTER IGNORE TABLE {$this->getTable('catalog_product_entity')}
|
| 49 |
ADD INDEX `sinch_product_id` (`sinch_product_id`);
|
| 50 |
");
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
//$installer->installEntities();
|
| 30 |
$installer->startSetup();
|
| 31 |
|
| 32 |
if($check_store_product_id){
|
| 33 |
+
try{
|
| 34 |
$installer->run("
|
| 35 |
ALTER TABLE {$this->getTable('catalog_product_entity')}
|
| 36 |
ADD COLUMN `store_product_id` INT(11) UNSIGNED NULL
|
| 37 |
");
|
| 38 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 39 |
+
try{
|
| 40 |
$installer->run("
|
| 41 |
ALTER IGNORE TABLE {$this->getTable('catalog_product_entity')}
|
| 42 |
ADD INDEX `store_product_id` (`store_product_id`);
|
| 43 |
");
|
| 44 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 45 |
}
|
| 46 |
if($check_sinch_product_id){
|
| 47 |
+
try{
|
| 48 |
$installer->run("
|
| 49 |
ALTER TABLE {$this->getTable('catalog_product_entity')}
|
| 50 |
ADD COLUMN `sinch_product_id` INT(11) UNSIGNED NULL
|
| 51 |
");
|
| 52 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 53 |
+
try{
|
| 54 |
$installer->run("
|
| 55 |
ALTER IGNORE TABLE {$this->getTable('catalog_product_entity')}
|
| 56 |
ADD INDEX `sinch_product_id` (`sinch_product_id`);
|
| 57 |
");
|
| 58 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 59 |
}
|
| 60 |
|
| 61 |
//$installer->installEntities();
|
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.5-0.1.6.php
CHANGED
|
@@ -5,9 +5,11 @@ $installer = $this;
|
|
| 5 |
|
| 6 |
$installer->startSetup();
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
$installer->endSetup();
|
| 5 |
|
| 6 |
$installer->startSetup();
|
| 7 |
|
| 8 |
+
try{
|
| 9 |
+
$installer->run("
|
| 10 |
+
ALTER IGNORE TABLE ".$installer->getTable('stINch_import_status_statistic')."
|
| 11 |
+
ADD COLUMN `import_type` ENUM('FULL', 'PRICE STOCK') default NULL after finish_import
|
| 12 |
+
");
|
| 13 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 14 |
|
| 15 |
$installer->endSetup();
|
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.6-0.1.7.php
CHANGED
|
@@ -29,25 +29,33 @@ while($row=mysql_fetch_assoc($res)){
|
|
| 29 |
}
|
| 30 |
|
| 31 |
if($check_store_category_id){
|
|
|
|
| 32 |
$installer->run("
|
| 33 |
ALTER TABLE {$this->getTable('catalog_category_entity')}
|
| 34 |
ADD COLUMN `store_category_id` INT(11) UNSIGNED NULL
|
| 35 |
");
|
|
|
|
|
|
|
| 36 |
$installer->run("
|
| 37 |
ALTER IGNORE TABLE {$this->getTable('catalog_category_entity')}
|
| 38 |
ADD INDEX `store_category_id` (`store_category_id`);
|
| 39 |
");
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
if($check_parent_store_category_id){
|
|
|
|
| 43 |
$installer->run("
|
| 44 |
ALTER TABLE {$this->getTable('catalog_category_entity')}
|
| 45 |
ADD COLUMN `parent_store_category_id` INT(11) UNSIGNED NULL
|
| 46 |
");
|
|
|
|
|
|
|
| 47 |
$installer->run("
|
| 48 |
ALTER IGNORE TABLE {$this->getTable('catalog_category_entity')}
|
| 49 |
ADD INDEX `parent_store_category_id` (`parent_store_category_id`);
|
| 50 |
");
|
|
|
|
| 51 |
|
| 52 |
}
|
| 53 |
$installer->run("DROP PROCEDURE IF EXISTS ".$installer->getTable('filter_sinch_products_s'));
|
|
@@ -108,7 +116,7 @@ BEGIN
|
|
| 108 |
FROM ".$installer->getTable('catalog_product_entity')." E
|
| 109 |
INNER JOIN ".$installer->getTable('catalog_category_product_index')." PCind
|
| 110 |
ON (E.entity_id = PCind.product_id)
|
| 111 |
-
INNER JOIN ".$installer->getTable('
|
| 112 |
ON PCind.category_id=scm.shop_entity_id
|
| 113 |
INNER JOIN ".$installer->getTable('stINch_categories_features')." CF
|
| 114 |
ON (scm.store_category_id=CF.store_category_id)
|
|
@@ -153,7 +161,7 @@ BEGIN
|
|
| 153 |
FROM ".$installer->getTable('catalog_product_entity')." E
|
| 154 |
INNER JOIN ".$installer->getTable('catalog_category_product_index')." PCind
|
| 155 |
ON (E.entity_id = PCind.product_id)
|
| 156 |
-
INNER JOIN ".$installer->getTable('
|
| 157 |
ON PCind.category_id=scm.shop_entity_id
|
| 158 |
INNER JOIN ".$installer->getTable('stINch_categories_features')." CF
|
| 159 |
ON (scm.store_category_id=CF.store_category_id)
|
| 29 |
}
|
| 30 |
|
| 31 |
if($check_store_category_id){
|
| 32 |
+
try{
|
| 33 |
$installer->run("
|
| 34 |
ALTER TABLE {$this->getTable('catalog_category_entity')}
|
| 35 |
ADD COLUMN `store_category_id` INT(11) UNSIGNED NULL
|
| 36 |
");
|
| 37 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 38 |
+
try{
|
| 39 |
$installer->run("
|
| 40 |
ALTER IGNORE TABLE {$this->getTable('catalog_category_entity')}
|
| 41 |
ADD INDEX `store_category_id` (`store_category_id`);
|
| 42 |
");
|
| 43 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 44 |
}
|
| 45 |
|
| 46 |
if($check_parent_store_category_id){
|
| 47 |
+
try{
|
| 48 |
$installer->run("
|
| 49 |
ALTER TABLE {$this->getTable('catalog_category_entity')}
|
| 50 |
ADD COLUMN `parent_store_category_id` INT(11) UNSIGNED NULL
|
| 51 |
");
|
| 52 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 53 |
+
try{
|
| 54 |
$installer->run("
|
| 55 |
ALTER IGNORE TABLE {$this->getTable('catalog_category_entity')}
|
| 56 |
ADD INDEX `parent_store_category_id` (`parent_store_category_id`);
|
| 57 |
");
|
| 58 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 59 |
|
| 60 |
}
|
| 61 |
$installer->run("DROP PROCEDURE IF EXISTS ".$installer->getTable('filter_sinch_products_s'));
|
| 116 |
FROM ".$installer->getTable('catalog_product_entity')." E
|
| 117 |
INNER JOIN ".$installer->getTable('catalog_category_product_index')." PCind
|
| 118 |
ON (E.entity_id = PCind.product_id)
|
| 119 |
+
INNER JOIN ".$installer->getTable('stINch_categories_mapping')." scm
|
| 120 |
ON PCind.category_id=scm.shop_entity_id
|
| 121 |
INNER JOIN ".$installer->getTable('stINch_categories_features')." CF
|
| 122 |
ON (scm.store_category_id=CF.store_category_id)
|
| 161 |
FROM ".$installer->getTable('catalog_product_entity')." E
|
| 162 |
INNER JOIN ".$installer->getTable('catalog_category_product_index')." PCind
|
| 163 |
ON (E.entity_id = PCind.product_id)
|
| 164 |
+
INNER JOIN ".$installer->getTable('stINch_categories_mapping')." scm
|
| 165 |
ON PCind.category_id=scm.shop_entity_id
|
| 166 |
INNER JOIN ".$installer->getTable('stINch_categories_features')." CF
|
| 167 |
ON (scm.store_category_id=CF.store_category_id)
|
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.1.8-0.1.9.php
CHANGED
|
@@ -5,9 +5,12 @@ $installer = $this;
|
|
| 5 |
|
| 6 |
$installer->startSetup();
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
$installer->endSetup();
|
| 5 |
|
| 6 |
$installer->startSetup();
|
| 7 |
|
| 8 |
+
try{
|
| 9 |
+
$installer->run("
|
| 10 |
+
ALTER IGNORE TABLE ".$installer->getTable('stINch_import_status_statistic')."
|
| 11 |
+
ADD COLUMN import_run_type ENUM ('MANUAL', 'CRON') DEFAULt NULL
|
| 12 |
+
AFTER detail_status_import;
|
| 13 |
+
");
|
| 14 |
+
}catch(Exception $e){ Mage::log($e->getMessage(), null, 'Sinch.log'); }
|
| 15 |
+
|
| 16 |
$installer->endSetup();
|
app/code/local/Bintime/Sinchimport/sql/sinchimport_setup/mysql4-upgrade-0.2.0-0.2.1.php
CHANGED
|
@@ -30,7 +30,7 @@ $installer->run("
|
|
| 30 |
INSERT ".$installer->getTable('stINch_sinchcheck')."(caption, descr, check_code, check_value, check_measure,
|
| 31 |
error_msg, fix_msg)
|
| 32 |
VALUE('Physical memory', 'checking system memory', 'memory', '2048', 'MB',
|
| 33 |
-
'You have %s MB of memory', 'You need
|
| 34 |
");
|
| 35 |
|
| 36 |
$installer->run("
|
|
@@ -93,9 +93,9 @@ $installer->run("
|
|
| 93 |
INSERT ".$installer->getTable('stINch_sinchcheck')."(caption, descr, check_code,
|
| 94 |
check_value, check_measure,
|
| 95 |
error_msg, fix_msg)
|
| 96 |
-
VALUE('Missing Procedure', 'checking absense of procedure ".$installer->getTable('
|
| 97 |
-
'".$installer->getTable('
|
| 98 |
-
'You are missing the MySQL stored procedure ".$installer->getTable('
|
| 99 |
");
|
| 100 |
|
| 101 |
mysql_close($cnx);
|
| 30 |
INSERT ".$installer->getTable('stINch_sinchcheck')."(caption, descr, check_code, check_value, check_measure,
|
| 31 |
error_msg, fix_msg)
|
| 32 |
VALUE('Physical memory', 'checking system memory', 'memory', '2048', 'MB',
|
| 33 |
+
'You have %s MB of memory', 'You need to enlarge memory to %s');
|
| 34 |
");
|
| 35 |
|
| 36 |
$installer->run("
|
| 93 |
INSERT ".$installer->getTable('stINch_sinchcheck')."(caption, descr, check_code,
|
| 94 |
check_value, check_measure,
|
| 95 |
error_msg, fix_msg)
|
| 96 |
+
VALUE('Missing Procedure', 'checking absense of procedure ".$installer->getTable('filter_sinch_products_s').".sql store procedue and showing hot to add it', 'routine',
|
| 97 |
+
'".$installer->getTable('filter_sinch_products_s')."', '',
|
| 98 |
+
'You are missing the MySQL stored procedure ".$installer->getTable('filter_sinch_products_s').".sql', 'You can recreate it by running the script found in [shop dir]/app/code/local/Bintime/Sinchimport/sql/ in PhpMyAdmin');
|
| 99 |
");
|
| 100 |
|
| 101 |
mysql_close($cnx);
|
app/design/frontend/default/default/template/sinchimport/list.phtml
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* DISCLAIMER
|
| 16 |
+
*
|
| 17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
+
* versions in the future. If you wish to customize Magento for your
|
| 19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
+
*
|
| 21 |
+
* @category design_default
|
| 22 |
+
* @package Mage
|
| 23 |
+
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
|
| 24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
| 25 |
+
*/
|
| 26 |
+
?>
|
| 27 |
+
<div class="page-head button-level">
|
| 28 |
+
<h3><?php echo $this->__('Compare Products') ?></h3>
|
| 29 |
+
<a href="#" class="link-print right" onclick="print();"><?php echo $this->__('Print This Page') ?></a>
|
| 30 |
+
</div>
|
| 31 |
+
<?php $_total=$this->getItems()->getSize() ?>
|
| 32 |
+
<?php if($_total): ?>
|
| 33 |
+
<div class="compare-products">
|
| 34 |
+
<table cellspacing="0" class="data-table box-table catalog-listing" id="product_comparison">
|
| 35 |
+
<?php if ($_total>2): ?>
|
| 36 |
+
<tbody class="remove-buttons">
|
| 37 |
+
<tr>
|
| 38 |
+
<?php $_i=0 ?>
|
| 39 |
+
<?php foreach($this->getItems() as $_item): ?>
|
| 40 |
+
<?php if($_i++%10==0): ?>
|
| 41 |
+
<td> </td>
|
| 42 |
+
<?php endif; ?>
|
| 43 |
+
<td><a href="#" onclick="setLocation('<?php echo $this->helper('catalog/product_compare')->getRemoveUrl($_item) ?>');window.opener.location.reload();"><img src="<?php echo $this->getSkinUrl('images/chart_remove.gif') ?>" alt="<?php echo $this->__('Remove Product') ?>" /></a></td>
|
| 44 |
+
<?php endforeach; ?>
|
| 45 |
+
</tr>
|
| 46 |
+
</tbody>
|
| 47 |
+
<?php endif ?>
|
| 48 |
+
<tbody>
|
| 49 |
+
<tr class="first">
|
| 50 |
+
<?php $_i=0 ?>
|
| 51 |
+
<?php foreach($this->getItems() as $_item): ?>
|
| 52 |
+
<?php if($_i++%10==0): ?>
|
| 53 |
+
<td class="label"> </td>
|
| 54 |
+
<?php endif; ?>
|
| 55 |
+
<td>
|
| 56 |
+
<a href="#" onclick="setPLocation('<?php echo $_item->getProductUrl() ?>', true)" title="<?php echo $this->htmlEscape($_item->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
|
| 57 |
+
<h5><a href="#" onclick="setPLocation('<?php echo $_item->getProductUrl() ?>', true)" title="<?php echo $this->htmlEscape($_item->getName()) ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a></h5>
|
| 58 |
+
<?php echo $this->getReviewsSummaryHtml($_item, 'short') ?>
|
| 59 |
+
<?php echo $this->getPriceHtml($_item, true) ?>
|
| 60 |
+
<?php if($_item->isSaleable()): ?>
|
| 61 |
+
<button class="form-button" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><?php echo $this->__('Add to Cart') ?></span></button><br/>
|
| 62 |
+
<?php else: ?>
|
| 63 |
+
<div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
|
| 64 |
+
<?php endif; ?>
|
| 65 |
+
<?php if ($this->helper('wishlist')->isAllow()) : ?>
|
| 66 |
+
<a href="#" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToWishlistUrl($_item) ?>', true)" class="link-cart"><small><?php echo $this->__('Add to Wishlist') ?></small></a>
|
| 67 |
+
<?php endif; ?>
|
| 68 |
+
</td>
|
| 69 |
+
<?php endforeach; ?>
|
| 70 |
+
</tr>
|
| 71 |
+
</tbody>
|
| 72 |
+
<tbody>
|
| 73 |
+
<?php /**************************************************** Sinch attributes ****************************************/ ?>
|
| 74 |
+
<?php $prod_attributes=$this->getSinchAttributes(); ?>
|
| 75 |
+
<?php foreach ($prod_attributes as $_attribute): ?>
|
| 76 |
+
|
| 77 |
+
<?php if($this->getSinchAttributeName($_attribute)) : ?>
|
| 78 |
+
<tr>
|
| 79 |
+
<?php $countItems = 0; ?>
|
| 80 |
+
<?php $_i=0; ?>
|
| 81 |
+
|
| 82 |
+
<?php foreach($this->getItems() as $_item) : ?>
|
| 83 |
+
<?php if ($this->getSinchProductAttributeValue($_item, $_attribute)) : $countItems++; endif; ?>
|
| 84 |
+
<?php endforeach; // Items (for count number) ?>
|
| 85 |
+
<?php foreach($this->getItems() as $_item) : ?>
|
| 86 |
+
<?php if ($countItems > 0 ) : ?>
|
| 87 |
+
<?php if($_i++%10==0): ?><td class="label"><?php echo $this->getSinchAttributeName($_attribute) ?></td><?php endif; ?>
|
| 88 |
+
<td>
|
| 89 |
+
<?php echo nl2br($this->getSinchProductAttributeValue($_item, $_attribute))." "; //.var_dump($this->getSinchProductAttributeValue($_item, $_attribute)); ?>
|
| 90 |
+
</td>
|
| 91 |
+
<?php endif; //AttributeValue ?>
|
| 92 |
+
|
| 93 |
+
<?php endforeach; // Items ?>
|
| 94 |
+
</tr>
|
| 95 |
+
<?php endif; //AttributeName ?>
|
| 96 |
+
|
| 97 |
+
<?php endforeach; ?>
|
| 98 |
+
<?php /**************************************************** End Sinch attributes ****************************************/ ?>
|
| 99 |
+
|
| 100 |
+
<?php /* foreach ($this->getAttributes() as $_attribute): ?>
|
| 101 |
+
<tr>
|
| 102 |
+
<?php $_i=0 ?>
|
| 103 |
+
<?php foreach($this->getItems() as $_item): ?>
|
| 104 |
+
<?php if($_i++%10==0): ?>
|
| 105 |
+
<td class="label"><?php echo $this->__($_attribute->getFrontendLabel()) ?><? //echo " "; print_r($_attribute->getFrontendLabel()); ?></td>
|
| 106 |
+
<?php endif; ?>
|
| 107 |
+
<td>
|
| 108 |
+
<?php switch ($_attribute->getAttributeCode()) {
|
| 109 |
+
case "price": ?>
|
| 110 |
+
<?php echo $this->getPriceHtml($_item, true) ?>
|
| 111 |
+
<?php break;
|
| 112 |
+
case "small_image": ?>
|
| 113 |
+
<img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" />
|
| 114 |
+
<?php break;
|
| 115 |
+
default: ?>
|
| 116 |
+
<?php echo nl2br($this->getProductAttributeValue($_item, $_attribute)) ?>
|
| 117 |
+
<?php break;
|
| 118 |
+
} ?>
|
| 119 |
+
</td>
|
| 120 |
+
<?php endforeach; ?>
|
| 121 |
+
</tr>
|
| 122 |
+
<?php endforeach; */ ?>
|
| 123 |
+
</tbody>
|
| 124 |
+
<tbody class="attribute-cart">
|
| 125 |
+
<tr>
|
| 126 |
+
<?php $_i=0 ?>
|
| 127 |
+
<?php foreach($this->getItems() as $_item): ?>
|
| 128 |
+
<?php if($_i++%10==0): ?>
|
| 129 |
+
<td class="label"> </td>
|
| 130 |
+
<?php endif; ?>
|
| 131 |
+
<td>
|
| 132 |
+
<?php echo $this->getPriceHtml($_item, true) ?>
|
| 133 |
+
<?php if($_item->isSaleable()): ?>
|
| 134 |
+
<button class="form-button" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><?php echo $this->__('Add to Cart') ?></span></button><br/>
|
| 135 |
+
<?php else: ?>
|
| 136 |
+
<div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
|
| 137 |
+
<?php endif; ?>
|
| 138 |
+
<?php if ($this->helper('wishlist')->isAllow()) : ?>
|
| 139 |
+
<a href="#" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToWishlistUrl($_item) ?>', true)" class="link-cart"><small><?php echo $this->__('Add to Wishlist') ?></small></a>
|
| 140 |
+
<?php endif; ?>
|
| 141 |
+
</td>
|
| 142 |
+
<?php endforeach; ?>
|
| 143 |
+
</tr>
|
| 144 |
+
</tbody>
|
| 145 |
+
</table>
|
| 146 |
+
<div class="button-set">
|
| 147 |
+
<button class="form-button" onclick="window.close();"><span><?php echo $this->__('Close Window') ?></span></button>
|
| 148 |
+
</div>
|
| 149 |
+
</div>
|
| 150 |
+
<script type="text/javascript">decorateTable('product_comparison');</script>
|
| 151 |
+
<?php else: ?>
|
| 152 |
+
<script type="text/javascript">window.close();</script>
|
| 153 |
+
<?php endif; ?>
|
app/design/frontend/default/default/template/sinchimport/media.phtml
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* DISCLAIMER
|
| 16 |
+
*
|
| 17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
+
* versions in the future. If you wish to customize Magento for your
|
| 19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
+
*
|
| 21 |
+
* @category design_default
|
| 22 |
+
* @package Mage
|
| 23 |
+
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
|
| 24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Product media data template
|
| 29 |
+
*
|
| 30 |
+
* @see Mage_Catalog_Block_Product_View_Media
|
| 31 |
+
*/
|
| 32 |
+
?>
|
| 33 |
+
|
| 34 |
+
<?php
|
| 35 |
+
$_product = $this->getProduct();
|
| 36 |
+
$_helper = $this->helper('catalog/output');
|
| 37 |
+
$_productDescriptionHelper = $this->helper('sinchimport/getdata')->getProductDescription($_product);
|
| 38 |
+
|
| 39 |
+
?>
|
| 40 |
+
<?php //if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
|
| 41 |
+
<p class="product-image-zoom">
|
| 42 |
+
<?php
|
| 43 |
+
$_img = '<img id="image" src="'. $this->helper('catalog/image')->init($_product, 'image') .'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
|
| 44 |
+
echo $_helper->productAttribute($_product, $_img, 'image');
|
| 45 |
+
?>
|
| 46 |
+
</p>
|
| 47 |
+
<p class="a-center" id="track_hint"><?php echo $this->__('Double click on above image to view full picture') ?></p>
|
| 48 |
+
|
| 49 |
+
<div class="image-zoom zoom" id="track_outer">
|
| 50 |
+
<img id="zoom_out" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_out.gif') ?>" alt="<?php echo $this->__('Zoom Out') ?>" class="btn-zoom-out" />
|
| 51 |
+
<div id="track">
|
| 52 |
+
<div id="handle"></div>
|
| 53 |
+
</div>
|
| 54 |
+
<img id="zoom_in" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_in.gif') ?>" alt="<?php echo $this->__('Zoom In') ?>" class="btn-zoom-in" />
|
| 55 |
+
</div>
|
| 56 |
+
<script type="text/javascript">
|
| 57 |
+
Event.observe(window, 'load', function() {
|
| 58 |
+
product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
|
| 59 |
+
});
|
| 60 |
+
</script>
|
| 61 |
+
<?php /*else: ?>
|
| 62 |
+
<?php
|
| 63 |
+
$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(265).'" alt="'.$this->htmlEscape($_product->getImageLabel()).'" />';
|
| 64 |
+
echo $_helper->productAttribute($_product, $_img, 'image')
|
| 65 |
+
?>
|
| 66 |
+
<?php endif; */?>
|
| 67 |
+
<?php if (count($_productDescriptionHelper->getGalleryPhotos()) > 0): ?>
|
| 68 |
+
<div class="more-views">
|
| 69 |
+
<h4><?php echo $this->__('More Views') ?></h4>
|
| 70 |
+
<ul>
|
| 71 |
+
<?php foreach ($_productDescriptionHelper->getGalleryPhotos() as $_image): ?>
|
| 72 |
+
<li>
|
| 73 |
+
<a href="#" onclick="popWin('<?php echo $_image['pic'] ?>', 'gallery', 'width=<?php echo $_image['width']?>,height=<?php echo $_image['height']?>,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;"><img src="<?php echo $_image['thumb'] ?>" alt="<?php echo $_productDescriptionHelper->getProductName()?>" title="<?php echo $_productDescriptionHelper->getProductName()?>" /></a>
|
| 74 |
+
</li>
|
| 75 |
+
<?php endforeach; ?>
|
| 76 |
+
</ul>
|
| 77 |
+
</div>
|
| 78 |
+
<?php else :?>
|
| 79 |
+
<div class="more-views">
|
| 80 |
+
<h2><?php echo $this->__('More Views') ?></h2>
|
| 81 |
+
<ul>
|
| 82 |
+
<?php foreach ($this->getGalleryImages() as $_image): ?>
|
| 83 |
+
<li>
|
| 84 |
+
<a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
|
| 85 |
+
</li>
|
| 86 |
+
<?php endforeach; ?>
|
| 87 |
+
</ul>
|
| 88 |
+
</div>
|
| 89 |
+
<?php endif; ?>
|
app/design/frontend/default/default/template/sinchimport/view.phtml
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* DISCLAIMER
|
| 16 |
+
*
|
| 17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
| 18 |
+
* versions in the future. If you wish to customize Magento for your
|
| 19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
| 20 |
+
*
|
| 21 |
+
* @category design_default
|
| 22 |
+
* @package Mage
|
| 23 |
+
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
|
| 24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Product view template
|
| 29 |
+
*
|
| 30 |
+
* @see Mage_Catalog_Block_Product_View
|
| 31 |
+
* @see Mage_Review_Block_Product_View
|
| 32 |
+
*/
|
| 33 |
+
?>
|
| 34 |
+
<?php
|
| 35 |
+
$_helper = $this->helper('catalog/output');
|
| 36 |
+
$_product = $this->getProduct();
|
| 37 |
+
$_catIds = $_product->getCategoryIds();
|
| 38 |
+
$_catId = $_catIds[0];
|
| 39 |
+
|
| 40 |
+
$_productDescriptionHelper = $this->helper('sinchimport/getdata')->getProductDescription($_product);
|
| 41 |
+
$message = $_productDescriptionHelper->getError();
|
| 42 |
+
if ($message){
|
| 43 |
+
$this->getMessagesBlock()->addError($_productDescriptionHelper->getError());
|
| 44 |
+
}
|
| 45 |
+
$specificationArray = $_productDescriptionHelper->getProductDescriptionList();
|
| 46 |
+
$sinchSpecification=$_productDescriptionHelper->getProductSpecifications();
|
| 47 |
+
$relatedProductsList = $_productDescriptionHelper->getRelatedProducts();
|
| 48 |
+
// echo "related= ".$_productDescriptionHelper->getVendor();
|
| 49 |
+
?>
|
| 50 |
+
<script type="text/javascript">
|
| 51 |
+
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
|
| 52 |
+
</script>
|
| 53 |
+
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
|
| 54 |
+
<div style="display:none"><?php $message=$_productDescriptionHelper->hasSystemError(); if ($message){ echo $message; } ?></div>
|
| 55 |
+
<div class="product-info-box product-view">
|
| 56 |
+
<div class="product-essential">
|
| 57 |
+
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
|
| 58 |
+
|
| 59 |
+
<div class="product-img-box">
|
| 60 |
+
<?php echo $this->getChildHtml('media'); ?>
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<div class="product-shop">
|
| 64 |
+
<?php if (!$_productDescriptionHelper->hasError()) : ?>
|
| 65 |
+
<h3 class="product-name"><?php echo $_productDescriptionHelper->getProductName()?></h3>
|
| 66 |
+
<?php else :?>
|
| 67 |
+
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name')?></h1>
|
| 68 |
+
<?php endif;?>
|
| 69 |
+
<?php if ($this->canEmailToFriend()): ?>
|
| 70 |
+
<a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>"><?php echo $this->__('Email to a Friend') ?></a><br />
|
| 71 |
+
<?php endif; ?>
|
| 72 |
+
|
| 73 |
+
<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
|
| 74 |
+
|
| 75 |
+
<fieldset class="no-display">
|
| 76 |
+
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
|
| 77 |
+
<input type="hidden" name="related_product" id="related-products-field" value="" />
|
| 78 |
+
</fieldset>
|
| 79 |
+
<?php if (!$_productDescriptionHelper->hasError()):?>
|
| 80 |
+
<div><b><?php echo $this->helper('sinchimport/getdata')->__('Brand:')?></b><?php echo $_productDescriptionHelper->getVendor();?></div>
|
| 81 |
+
<div><b><?php echo $this->helper('sinchimport/getdata')->__('Product code:')?></b><?php echo $_productDescriptionHelper->getMPN();?></div>
|
| 82 |
+
<div><b><?php echo $this->helper('sinchimport/getdata')->__('EAN/UPC code:')?></b><?php echo $_productDescriptionHelper->getEAN();?></div>
|
| 83 |
+
<div><b><?php echo $this->helper('sinchimport/getdata')->__('Category:')?></b><?php echo Mage::getModel('catalog/category')->load($_catId)->getName()?></div>
|
| 84 |
+
<?php endif;?>
|
| 85 |
+
<?php echo $this->getChildHtml('alert_urls') ?>
|
| 86 |
+
<?php echo $this->getChildHtml('product_type_data') ?>
|
| 87 |
+
<?php echo $this->getTierPriceHtml() ?>
|
| 88 |
+
|
| 89 |
+
<?php if (!$this->hasOptions()):?>
|
| 90 |
+
<div class="add-to-holder">
|
| 91 |
+
<?php if($_product->isSaleable()): ?>
|
| 92 |
+
<?php echo $this->getChildHtml('addtocart') ?>
|
| 93 |
+
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
|
| 94 |
+
<span class="add-or"><?php echo $this->__('OR') ?></span>
|
| 95 |
+
<?php endif; ?>
|
| 96 |
+
<?php endif; ?>
|
| 97 |
+
<?php echo $this->getChildHtml('addto') ?>
|
| 98 |
+
</div>
|
| 99 |
+
<?php else:?>
|
| 100 |
+
<?php echo $this->getChildHtml('addto') ?>
|
| 101 |
+
<?php endif; ?>
|
| 102 |
+
|
| 103 |
+
<?php if ($_product->getShortDescription() && $_productDescriptionHelper->hasError()):?>
|
| 104 |
+
<div class="short-description">
|
| 105 |
+
<h2><?php echo $this->__('Quick Overview') ?></h2>
|
| 106 |
+
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
|
| 107 |
+
</div>
|
| 108 |
+
<?php else :?>
|
| 109 |
+
<div class="divider"></div>
|
| 110 |
+
<?php endif;?>
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
<?php echo $this->getChildHtml('other');?>
|
| 114 |
+
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
|
| 115 |
+
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
|
| 116 |
+
<?php endif;?>
|
| 117 |
+
|
| 118 |
+
</div>
|
| 119 |
+
<div class="clear"></div>
|
| 120 |
+
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
|
| 121 |
+
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
|
| 122 |
+
<?php endif;?>
|
| 123 |
+
</form>
|
| 124 |
+
<script type="text/javascript">
|
| 125 |
+
var productAddToCartForm = new VarienForm('product_addtocart_form');
|
| 126 |
+
productAddToCartForm.submit = function(){
|
| 127 |
+
if (this.validator.validate()) {
|
| 128 |
+
this.form.submit();
|
| 129 |
+
}
|
| 130 |
+
}.bind(productAddToCartForm);
|
| 131 |
+
|
| 132 |
+
function changeTab(id){
|
| 133 |
+
for(var i=0;i<4;i++){
|
| 134 |
+
var tab_cont = (document.getElementById) ? document.getElementById("tab_cont_"+i) : eval('document.all["tab_cont_'+i+'"]');
|
| 135 |
+
var tab = (document.getElementById) ? document.getElementById("tab_"+i) : eval('document.all["tab_'+i+'"]');
|
| 136 |
+
|
| 137 |
+
if (tab_cont!=null && tab!=null) {
|
| 138 |
+
if(i==id){
|
| 139 |
+
tab_cont.style.display="";
|
| 140 |
+
tab.className="prod_doc_tab_div_sel";
|
| 141 |
+
} else {
|
| 142 |
+
tab_cont.style.display="none";
|
| 143 |
+
tab.className="prod_doc_tab_div";
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
</script>
|
| 149 |
+
</div>
|
| 150 |
+
<?php if (!$_productDescriptionHelper->hasError()) : ?>
|
| 151 |
+
<div class="description_b">
|
| 152 |
+
<div class="short_product_description"><?php echo $_productDescriptionHelper->getShortProductDescription() ?></div>
|
| 153 |
+
<?php
|
| 154 |
+
if (strlen($_productDescriptionHelper->getFullProductDescription())>450){
|
| 155 |
+
$firstPart = str_replace("\\n", "<br>", substr($_productDescriptionHelper->getFullProductDescription(), 0, 400));
|
| 156 |
+
$space = strrpos($firstPart, " ");
|
| 157 |
+
$dot = strrpos($firstPart, ".");
|
| 158 |
+
$column = strrpos($firstPart, ",");
|
| 159 |
+
$spanTagStart = strrpos($firstPart, "<span");
|
| 160 |
+
$spanTagEND = strrpos($firstPart, "</span>");
|
| 161 |
+
|
| 162 |
+
if ($space-5>$dot && $space-5>$column){
|
| 163 |
+
$firstPart = substr($firstPart, 0, $space);
|
| 164 |
+
}
|
| 165 |
+
else{
|
| 166 |
+
$firstPart = $column > $dot ? substr($firstPart, 0, $column) : substr($firstPart, 0, $dot);
|
| 167 |
+
}
|
| 168 |
+
if ((int)$spanTagEND<$spanTagStart){
|
| 169 |
+
$firstPart = substr($firstPart, 0, $spanTagStart);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
?>
|
| 175 |
+
<div class="product_description">
|
| 176 |
+
<?php if (isset($firstPart)):?>
|
| 177 |
+
<span id="more_link"><?php echo $firstPart." "?>... <a class="more_link" href="javascript: showMore();"><?php echo htmlentities(' More>>>')?></a></span>
|
| 178 |
+
<span id="more_info" style="display: none;"><?php echo str_replace("\\n", "<br>", $_productDescriptionHelper->getFullProductDescription());?><a class="more_link" href="javascript: hideMore();"><?php echo htmlentities(' <<<Less')?></a></span>
|
| 179 |
+
<?php else: ?>
|
| 180 |
+
<span><?php echo str_replace("\\n", "<br>", $_productDescriptionHelper->getFullProductDescription());?></span>
|
| 181 |
+
<?php endif?>
|
| 182 |
+
</div >
|
| 183 |
+
</div>
|
| 184 |
+
<?php endif;?>
|
| 185 |
+
<div class="product-collateral">
|
| 186 |
+
<?php if ($_productDescriptionHelper->hasError()) :?>
|
| 187 |
+
<?php echo $this->getChildHtml('description') ?>
|
| 188 |
+
<?php else :
|
| 189 |
+
$tab_class0=$tab_class1=$tab_class2=$tab_class3='prod_doc_tab_div';
|
| 190 |
+
$data_tab_style0=$data_tab_style1=$data_tab_style2=$data_tab_style3="display:none";
|
| 191 |
+
if($sinchSpecification || $sinchSpecification!=''){
|
| 192 |
+
$tab_class0='prod_doc_tab_div_sel';
|
| 193 |
+
$data_tab_style0='';
|
| 194 |
+
}elseif(!empty($specificationArray)){
|
| 195 |
+
$tab_class1='prod_doc_tab_div_sel';
|
| 196 |
+
$data_tab_style1='';
|
| 197 |
+
}elseif($_catId && array_key_exists($_catId, $relatedProductsList)){
|
| 198 |
+
$tab_class2='prod_doc_tab_div_sel';
|
| 199 |
+
$data_tab_style2='';
|
| 200 |
+
}elseif(!empty($relatedProductsList)){
|
| 201 |
+
$tab_class3='prod_doc_tab_div_sel';
|
| 202 |
+
$data_tab_style3='';
|
| 203 |
+
}
|
| 204 |
+
?>
|
| 205 |
+
<? if(false): ?>
|
| 206 |
+
<table cellspacing="0" cellpadding="0" width="100%">
|
| 207 |
+
<tr>
|
| 208 |
+
<td>
|
| 209 |
+
<table cellspacing="0" cellpadding="0" class="prod_doc_tabs_row">
|
| 210 |
+
<tr>
|
| 211 |
+
<td class="prod_doc_tabs_space"> </td>
|
| 212 |
+
<?php if ($sinchSpecification || $sinchSpecification!=''):?>
|
| 213 |
+
<td class="prod_doc_tab"><div id="tab_0" class="<?php echo $tab_class0 ?>" onclick="changeTab(0)"><?php echo $this->helper('sinchimport/getdata')->__('Specification') ?></div></td>
|
| 214 |
+
<?php endif?>
|
| 215 |
+
<?php if (!empty($specificationArray)):?>
|
| 216 |
+
<td class="prod_doc_tab"><div id="tab_1" class="<?php echo $tab_class1 ?>" onclick="changeTab(1)"><?php echo $this->helper('sinchimport/getdata')->__('Star features') ?></div></td>
|
| 217 |
+
<?php endif?>
|
| 218 |
+
<?php if ($_catId && array_key_exists($_catId, $relatedProductsList)):?>
|
| 219 |
+
<td class="prod_doc_tab"><div id="tab_2" class="prod_doc_tab_div" onclick="changeTab(2)"><?php echo $this->helper('sinchimport/getdata')->__('Alternatives') ?></div></td>
|
| 220 |
+
<?php endif?>
|
| 221 |
+
<?php if (!empty($relatedProductsList)):?>
|
| 222 |
+
<td class="prod_doc_tab"><div id="tab_3" class="prod_doc_tab_div" onclick="changeTab(3)"><?php echo $this->helper('sinchimport/getdata')->__('Options') ?></div></td>
|
| 223 |
+
<?php endif?>
|
| 224 |
+
<td class="prod_doc_tabs_space" style="width:auto!important"> </td>
|
| 225 |
+
</tr>
|
| 226 |
+
</table>
|
| 227 |
+
</td>
|
| 228 |
+
</tr>
|
| 229 |
+
<tr>
|
| 230 |
+
<td>
|
| 231 |
+
<table cellspacing="0" cellpadding="2" class="prod_doc_content">
|
| 232 |
+
<tr>
|
| 233 |
+
<td class="prod_doc_content_cell">
|
| 234 |
+
<!-- ZERO TAB's CONTENT (VISIBLE BY DEFAULT) -->
|
| 235 |
+
<table id="tab_cont_0" cellspacing="6" cellpadding="0" width="100%" style="<?php echo $data_tab_style0; ?>">
|
| 236 |
+
<tr>
|
| 237 |
+
<td width="50%" valign="top">
|
| 238 |
+
<table cellspacing="0" cellpadding="2" class="prod_doc_table">
|
| 239 |
+
<tr><td>
|
| 240 |
+
<?php echo $sinchSpecification; ?>
|
| 241 |
+
</td></tr>
|
| 242 |
+
</table>
|
| 243 |
+
</td>
|
| 244 |
+
</tr>
|
| 245 |
+
</table>
|
| 246 |
+
|
| 247 |
+
<!-- FIRST TAB's CONTENT (VISIBLE BY DEFAULT) -->
|
| 248 |
+
<table id="tab_cont_1" cellspacing="6" cellpadding="0" width="100%" style="<?php echo $data_tab_style1; ?>">
|
| 249 |
+
<tr>
|
| 250 |
+
<td width="50%" valign="top">
|
| 251 |
+
<table cellspacing="0" cellpadding="2" class="prod_doc_table">
|
| 252 |
+
|
| 253 |
+
<?php foreach($specificationArray as $key => $value):?>
|
| 254 |
+
<tr>
|
| 255 |
+
<td colspan="2" class="prod_doc_item_head"><?php echo $key?></td>
|
| 256 |
+
<td class="prod_doc_item_descr"><?php if($value == "Y"){
|
| 257 |
+
echo '<img border="0" alt="" src="http://prf.icecat.biz/imgs/yes.gif"/>';
|
| 258 |
+
}
|
| 259 |
+
else if ($value == "N"){
|
| 260 |
+
echo '<img border="0" alt="" src="http://prf.icecat.biz/imgs/no.gif"/>';
|
| 261 |
+
}
|
| 262 |
+
else{
|
| 263 |
+
echo str_replace("\\n", "<br>",$value);
|
| 264 |
+
}
|
| 265 |
+
?></td>
|
| 266 |
+
</tr>
|
| 267 |
+
<?php endforeach;?>
|
| 268 |
+
</table>
|
| 269 |
+
</td>
|
| 270 |
+
</tr>
|
| 271 |
+
</table>
|
| 272 |
+
<!-- SECOND TAB's CONTENT (HIDDEN BY DEFAULT) -->
|
| 273 |
+
<table id="tab_cont_2" cellspacing="6" cellpadding="0" width="100%" style="<?php echo $data_tab_style2; ?>">
|
| 274 |
+
<tr>
|
| 275 |
+
<td>
|
| 276 |
+
<table cellspacing="1" cellpadding="5" class="prod_alt_table" width="100%" >
|
| 277 |
+
<tr>
|
| 278 |
+
<td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Brand') ?></td>
|
| 279 |
+
<td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Image') ?></td>
|
| 280 |
+
<td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Article code') ?></td>
|
| 281 |
+
<td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Product name') ?></td>
|
| 282 |
+
</tr>
|
| 283 |
+
<?php if ($_catId && array_key_exists($_catId, $relatedProductsList)):?>
|
| 284 |
+
<?php foreach($relatedProductsList[$_catId] as $product):?>
|
| 285 |
+
<tr>
|
| 286 |
+
<?php if($product['supplier_thumb']&&($product['supplier_thumb']!='')): ?>
|
| 287 |
+
<td><img src="<?php echo $product['supplier_thumb']?>" /></td>
|
| 288 |
+
<?php else :?>
|
| 289 |
+
<td><?php echo $product['supplier_name']?></td>
|
| 290 |
+
<?php endif ?>
|
| 291 |
+
<td><a href="<?php echo $product['url']?>"><img src="<?php echo $product['thumb']?>" /></a></td>
|
| 292 |
+
<td><?php echo $product['mpn']?></td>
|
| 293 |
+
<td><a href="<?php echo $product['url']?>" class="prod_link_small"><?php echo $product['name']?></a></td>
|
| 294 |
+
</tr>
|
| 295 |
+
<?php endforeach?>
|
| 296 |
+
<?php else: ?>
|
| 297 |
+
<tr><td></>No Alternative proposals for Current product avaible</td></tr>
|
| 298 |
+
<?php endif?>
|
| 299 |
+
</table>
|
| 300 |
+
</td>
|
| 301 |
+
</tr>
|
| 302 |
+
</table>
|
| 303 |
+
<!-- THIRD TAB's CONTENT (HIDDEN BY DEFAULT) -->
|
| 304 |
+
<table id="tab_cont_3" cellspacing="6" cellpadding="0" width="100%" style="<?php echo $data_tab_style3; ?>">
|
| 305 |
+
<tr>
|
| 306 |
+
<td>
|
| 307 |
+
|
| 308 |
+
<table cellspacing="1" cellpadding="5" width="100%" class="prod_alt_table">
|
| 309 |
+
<tr>
|
| 310 |
+
<td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Brand') ?></td>
|
| 311 |
+
<td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Image') ?></td>
|
| 312 |
+
<td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Article code') ?></td>
|
| 313 |
+
<td class="prod_doc_block_head"><?php echo $this->helper('sinchimport/getdata')->__('Product name') ?></td>
|
| 314 |
+
</tr>
|
| 315 |
+
<?php if (!empty($relatedProductsList)):?>
|
| 316 |
+
<?php foreach($relatedProductsList as $categoryId => $productsArray):?>
|
| 317 |
+
<?php if ($categoryId == $_catId){
|
| 318 |
+
continue;
|
| 319 |
+
}?>
|
| 320 |
+
<?php if (!is_string($categoryId)):?>
|
| 321 |
+
<tr>
|
| 322 |
+
<td class="prod_doc_item_head2" colspan="4"><?php echo is_string($categoryId)? '' : Mage::getSingleton('catalog/category')->load($categoryId)->getName() ?></td>
|
| 323 |
+
|
| 324 |
+
</tr>
|
| 325 |
+
<?php endif?>
|
| 326 |
+
<?php foreach($productsArray as $product):?>
|
| 327 |
+
<tr>
|
| 328 |
+
<?php if($product['supplier_thumb']&&($product['supplier_thumb']!='')): ?>
|
| 329 |
+
<td><img src="<?php echo $product['supplier_thumb']?>" /></td>
|
| 330 |
+
<?php else :?>
|
| 331 |
+
<td><?php echo $product['supplier_name']?></td>
|
| 332 |
+
<?php endif ?>
|
| 333 |
+
<td><a href="<?php echo $product['url']?>"><img src="<?php echo $product['thumb']?>" /></a></td>
|
| 334 |
+
<td><?php echo $product['mpn']?></td>
|
| 335 |
+
<td><a href="<?php echo $product['url']?>" class="prod_link_small"><?php echo $product['name']?></a></td>
|
| 336 |
+
</tr>
|
| 337 |
+
<?php endforeach ?>
|
| 338 |
+
<?php endforeach ?>
|
| 339 |
+
<?php else: ?>
|
| 340 |
+
<tr><td></>No Related proposals for Current product avaible</td></tr>
|
| 341 |
+
<?php endif?>
|
| 342 |
+
</table>
|
| 343 |
+
</td>
|
| 344 |
+
</tr>
|
| 345 |
+
</table>
|
| 346 |
+
<!-- EOF -->
|
| 347 |
+
</td>
|
| 348 |
+
</tr>
|
| 349 |
+
</table>
|
| 350 |
+
<?php endif; ?>
|
| 351 |
+
</td>
|
| 352 |
+
</tr>
|
| 353 |
+
</table>
|
| 354 |
+
<?php endif;?>
|
| 355 |
+
<?php if ($_additional = $this->getChildHtml('additional')):?>
|
| 356 |
+
<div class="collateral-box">
|
| 357 |
+
<?php echo $_additional ?>
|
| 358 |
+
</div>
|
| 359 |
+
<?php endif;?>
|
| 360 |
+
<?php echo $this->getChildHtml('upsell_products') ?>
|
| 361 |
+
<?php echo $this->getChildHtml('product_additional_data') ?>
|
| 362 |
+
</div>
|
| 363 |
+
</div>
|
package.xml
CHANGED
|
@@ -1,24 +1,22 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>stockinthechannel2012</name>
|
| 4 |
-
<version>1.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Stock In The Channel to Magento Connector - Sell virtual stock - drop ship ecommerce</summary>
|
| 10 |
-
<description>StockInTheChannel has released a free
|
| 11 |
-
What you get
|
| 12 |
-
A site full of products with stock, prices, product descriptions, categories, attribute filters, images, product comparison, related products and more pumped in to Magento automatically
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
<notes>Now has section to check server configuration for suitability of running extension.
|
| 17 |
-
</notes>
|
| 18 |
<authors><author><name>stockinchannel</name><user>stockinchannel</user><email>marketing@stockinthechannel.com</email></author></authors>
|
| 19 |
-
<date>2012-
|
| 20 |
-
<time>16:
|
| 21 |
-
<contents><target name="magelocal"><dir
|
| 22 |
<compatible/>
|
| 23 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 24 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>stockinthechannel2012</name>
|
| 4 |
+
<version>1.2.0</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Stock In The Channel to Magento Connector - Sell virtual stock - drop ship ecommerce</summary>
|
| 10 |
+
<description>StockInTheChannel has released a free Magento Plugin.
|
| 11 |
+
What you get:
|
| 12 |
+
A site full of products with stock, prices, product descriptions, categories, attribute filters, images, product comparison, related products and more pumped in to Magento automatically.
|
| 13 |
+
</description>
|
| 14 |
+
<notes>Added Compatibility for US Stock in the channel
|
| 15 |
+
Bug Fixes</notes>
|
|
|
|
|
|
|
| 16 |
<authors><author><name>stockinchannel</name><user>stockinchannel</user><email>marketing@stockinthechannel.com</email></author></authors>
|
| 17 |
+
<date>2012-10-10</date>
|
| 18 |
+
<time>16:31:49</time>
|
| 19 |
+
<contents><target name="magelocal"><dir name="Bintime"><dir name="Sinchimport"><dir><dir name="Block"><file name="Importenvironment.php" hash="004215c641928520fd41004857d3f3f0"/><file name="Importhistory.php" hash="3748b6e5ccdd242fa8a8cdb96a53241e"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="239d86cde4cf08f5f50183df26e89eea"/></dir><file name="View.php" hash="97cf41b42afc26d46ee3d876721601c7"/></dir><file name="List.php" hash="fb81ed4b565c1099bc7a47d19538c730"/><dir name="Product"><dir name="View"><file name="Media.php" hash="401c8afd5af4d0edda0929e8df4d6cd4"/></dir></dir><file name="Startimportbutton.php" hash="7dafc8567377960378db533fc690fc07"/><file name="Startstockpriceimportbutton.php" hash="14f033367ee4df620494f57be8f26719"/></dir><dir name="Helper"><file name="Data.php" hash="c9baa21be5ba345512e5c390b1954c72"/><file name="Getdata.php" hash="dcdf2bd47b01a26ed9400497774c86f8"/><file name="Image.php" hash="4507e0741e1bf094ce558ffb908dbae8"/></dir><dir name="Model"><file name="Api.php" hash="dbcb072fdf2a27766df6aae8213b3e5e"/><file name="Category.php" hash="c3e3410e01e33334b058dd9781f5d84a"/><file name="Image.php" hash="b87da6ed365c3265495afdc2f3b04eb2"/><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="4ab6866b88f6aa5e59a99808b38dc85b"/><file name="Price.php" hash="93a6b62fec1e11bf6af57dd0cb2f063a"/></dir></dir><file name="Layer.php" hash="2c0131265f18450126d7a0988d6ed284"/><file name="Product.php" hash="1e3be2c2c605b3eaf79aea1627ef4d49"/><dir name="Resource"><dir name="Layer"><dir name="Filter"><file name="Price.php" hash="0d1fd59eb80f281ebad11bf15d3007da"/></dir></dir><dir name="Mysql4"><dir name="Layer"><dir name="Filter"><file name="Feature.php" hash="6fbcd7960a4e1118d258852c64519d33"/></dir></dir><file name="Setup.php" hash="280a1ece3e1bb1f035e2cf265da05b63"/></dir></dir><file name="Sinch.php" hash="3631406a7813b0a104a0436011be5826"/><file name="Sinch_new_code.php" hash="45139a984755a15503ee0c4c987f1e11"/><dir name="System"><dir name="Config"><file name="CatRewrite.php" hash="f54ba849b2342dfb177f4cd4736eaa48"/><file name="ServerList.php" hash="ff26802c85ed0733241a2166a702f34a"/><file name="Subscription.php" hash="985102ab2005f33e017818ef9247b633"/></dir></dir><file name="config.php" hash="ac2f5e6e68014283492915c6e1d57880"/></dir><dir name="controllers"><file name="AjaxController.php" hash="85d09a8a2fe9214dce3b6140f1b3983e"/><file name="IndexController.php" hash="910f7a5547e9bad529ea71f3e8cd37e6"/><file name="ProductController.php" hash="a7619ef76a1f48bd7f2c029b7c488385"/><file name="SplitfeaturesController.php" hash="a1c27276bced097e8b2a6667e4b6fdbd"/></dir><dir name="etc"><file name="api.xml" hash="4b9df3ba0ff94824f06a5c14497034cb"/><file name="config.xml" hash="805562d531bafccef772ab7c92726c69"/><file name="system.xml" hash="8641f0f42c3bb24a07a0500e3c10e6e0"/></dir><dir name="sql"><dir name="sinchimport_setup"><file name="filter_sinch_products_s.sql" hash="40a09a0bb83bce3b14564909cfe3cfc5"/><file name="mysql4-install-0.1.0.php" hash="b79406446cf40050ba29fad4c8057883"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="93a43b01c4ad6eb9c9638dc1d31ca777"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="c8c38201a96d38f84c5c0021148c3f25"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="56aa5dc8f22a7b24b23c9d381e92f6dc"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="ab6aa72ff697db247423911437830795"/><file name="mysql4-upgrade-0.1.4-0.1.5.php" hash="f195a8bf9fbcc31eca6d066ff1bb98f5"/><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="f4ee53d9644c16c80327b40fec432d1d"/><file name="mysql4-upgrade-0.1.6-0.1.7.php" hash="fbf4d87769c26c1d9d011a180f46b98d"/><file name="mysql4-upgrade-0.1.7-0.1.8.php" hash="aac20d4a587a68e665367d2c1f9d1068"/><file name="mysql4-upgrade-0.1.8-0.1.9.php" hash="de6b560cef7edf7914cc4f135b0678b9"/><file name="mysql4-upgrade-0.1.9-0.2.0.php" hash="00602f51d8a1d63e646166a4c2b3651c"/><file name="mysql4-upgrade-0.2.0-0.2.1.php" hash="03b25c8b9c2993723a2995316c22a120"/></dir></dir></dir><file name="sinch_import_start_ajax.php" hash="3c81464e43f630270bb0376e15fe21fa"/><file name="stock_price_sinch_import_start_ajax.php" hash="960ba4cfdb5ea3548a17c2365c0fca80"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bintime_Sinchimport.xml" hash="8d5661b858250eeb154af10ee19300c3"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="sinchimport.xml" hash="53dd99d9303049f92713aec45c21836f"/></dir><dir name="template"><dir name="sinchimport"><file name="list.phtml" hash="adc46e247797cdad4582792266d381e4"/><file name="media.phtml" hash="af44d0371493235e4d0a5d0e9223bd9e"/><file name="view.phtml" hash="f160f6226d774a82ab1b312ffb30eb3e"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="js"><file name="product_view.js" hash=""/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><file name="sinchimport_run.gif" hash="e805ea7eca1f34c75ba0f93780d32d38"/><file name="sinchimport_yes.gif" hash="0afb20898a704a106cb4c598868abf32"/></dir></dir></dir></dir></target></contents>
|
| 20 |
<compatible/>
|
| 21 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 22 |
</package>
|
