// Merge -> 10309

This commit is contained in:
rMalie
2011-11-21 11:05:10 +00:00
parent 3bfd9ad4ca
commit 82c9dead2a
365 changed files with 11185 additions and 1571 deletions
+17
View File
@@ -0,0 +1,17 @@
<?php
include_once('../../config/config.inc.php');
include_once('../../init.php');
include_once('../../modules/importerosc/importerosc.php');
if (!Tools::getValue('ajax') || Tools::getValue('token') != sha1(_COOKIE_KEY_.'importosc'))
die('INVALID TOKEN');
$importOsc = new importerosc();
$importOsc->server = Tools::getValue('server');
$importOsc->user = Tools::getValue('user');
$importOsc->passwd = Tools::getValue('password');
$importOsc->database = Tools::getValue('database');
$importOsc->prefix = Tools::getValue('prefix');
die($importOsc->createLevelAndCalculate());
+5
View File
@@ -20,3 +20,8 @@ $_MODULE['<{importerosc}prestashop>importerosc_14ae0ea02f571a833786d13d9ca6a897'
$_MODULE['<{importerosc}prestashop>importerosc_e307db07b3975fef922a80d07455ee5e'] = 'Base de données';
$_MODULE['<{importerosc}prestashop>importerosc_dac130bdd2c5492a8108a4145bd9f04a'] = 'Préfixe base de données';
$_MODULE['<{importerosc}prestashop>importerosc_6bdc02625540b5264cffe801c37a82dd'] = '(Le préfixe est optionnel. Si toute votre base de données commence par \"pref_\", votre préfixe est \"pref_\")';
$_MODULE['<{importerosc}prestashop>importerosc_4685343b5e2e0f0fbee63dddafde693f'] = 'Vous essayez d\'importer des catégories et nous avons détecté que votre base de données osCommerce n\'ont pas le champs \"niveau\" dans la table catégorie. Vous devez avoir ce champs pour continuer l\'importation de catégories.';
$_MODULE['<{importerosc}prestashop>importerosc_16f35420186575c2a1d9c0b59edf6ad3'] = 'Cliquez ici pour ajouter et de calculer le champs niveau';
$_MODULE['<{importerosc}prestashop>importerosc_fced104d747e0855ceff3020653104ab'] = 'Le champ \"niveau\" a été créé et calculé, vous pouvez continuer';
$_MODULE['<{importerosc}prestashop>importerosc_b405d0bebeedbdc1773a44ac36b8ffc4'] = 'Il est fortement recommandé de sauvegarder votre base de données avant de continuer. Avez-vous fait une sauvegarde?';
$_MODULE['<{importerosc}prestashop>importerosc_9f95fc55011203d91d50a0ed512f805f'] = 'Impossible de \"ALTER TABLE\"';
+147 -8
View File
@@ -61,10 +61,14 @@ class importerosc extends ImportModule
public function displaySpecificOptions()
{
$html = '';
if (!$this->checkCategoriesLevel())
$html .= $this->displayCategoriesLevelConf();
$langagues = $this->executeS('SELECT * FROM `'.bqSQL($this->prefix).'languages`');
$curencies = $this->executeS('SELECT * FROM `'.bqSQL($this->prefix).'currencies`');
$html = '<label style=\'width:220px\'>'.$this->l('Default osCommerce language : ').'</label>
$html .= '<label style=\'width:220px\'>'.$this->l('Default osCommerce language : ').'</label>
<div class="margin-form">
<select name=\'defaultOscLang\'><option value=\'0\'>------</option>';
foreach($langagues AS $lang)
@@ -148,9 +152,10 @@ class importerosc extends ImportModule
$identifier = 'id_country';
$defaultIdLang = $this->getDefaultIdLang();
$countries = $this->executeS('
SELECT countries_id as id_country, countries_name as name, countries_iso_code_2 as iso_code, `'.bqSQL($defaultIdLang).'̀ as id_lang,
SELECT countries_id as id_country, countries_name as name, countries_iso_code_2 as iso_code, '.(int)$defaultIdLang.' as id_lang,
1 as id_zone, 0 as id_currency, 1 as contains_states, 1 as need_identification_number, 1 as active, 1 as display_tax_label
FROM `'.bqSQL($this->prefix).'countries` as c LIMIT '.(int)($limit).' , '.(int)$nrb_import);
return $this->autoFormat($countries, $identifier, $keyLanguage, $multiLangFields);
}
@@ -219,19 +224,19 @@ class importerosc extends ImportModule
$multiLangFields = array('name', 'link_rewrite');
$keyLanguage = 'id_lang';
$identifier = 'id_category';
$categories = $this->executeS('
SELECT c.categories_id as id_category, c.parent_id as id_parent, 0 as level_depth, cd.language_id as id_lang, cd.categories_name as name , 1 as active, categories_image as images
SELECT c.categories_id as id_category, c.parent_id as id_parent, level as level_depth, cd.language_id as id_lang, cd.categories_name as name , 1 as active, categories_image as images
FROM `'.bqSQL($this->prefix).'categories` c
LEFT JOIN `'.bqSQL($this->prefix).'categories_description` cd ON (c.categories_id = cd.categories_id)
WHERE cd.categories_name IS NOT NULL AND cd.language_id IS NOT NULL
ORDER BY c.categories_id, cd.language_id
ORDER BY c.level ASC , c.`categories_id`
LIMIT '.(int)($limit).' , '.(int)$nrb_import);
foreach($categories as& $cat)
{
$cat['link_rewrite'] = Tools::link_rewrite($cat['name']);
$cat['images'] = array(Tools::getProtocol().Tools::getValue('shop_url').'/images/'.$cat['images']);
}
return $this->autoFormat($categories, $identifier, $keyLanguage, $multiLangFields);
}
@@ -256,6 +261,7 @@ class importerosc extends ImportModule
SELECT p.`products_options_values_id` as id_attribute, p.`products_options_values_name` as name, p.`language_id` as id_lang , po.`products_options_id` as id_attribute_group
FROM `'.bqSQL($this->prefix).'products_options_values` p
LEFT JOIN `'.bqSQL($this->prefix).'products_options_values_to_products_options` po ON (po.products_options_values_id = p.products_options_values_id)
ORDER BY p.`products_options_values_id`
LIMIT '.(int)($limit).' , '.(int)$nrb_import);
return $this->autoFormat($countries, $identifier, $keyLanguage, $multiLangFields);
}
@@ -274,6 +280,7 @@ class importerosc extends ImportModule
FROM `'.bqSQL($this->prefix).'products` p
LEFT JOIN `'.bqSQL($this->prefix).'products_description` pd ON (p.products_id = pd.products_id)
WHERE pd.products_name IS NOT NULL AND pd.language_id IS NOT NULL
ORDER BY p.`products_id`
LIMIT '.(int)($limit).' , '.(int)$nrb_import);
$this->Execute('CREATE TABLE IF NOT EXISTS`products_images` (
@@ -293,8 +300,8 @@ class importerosc extends ImportModule
$images[] = Tools::getProtocol().Tools::getValue('shop_url').'/images/'.$res['image'];
$product['images'] = array_merge(array($product['images']), $images);
$product['link_rewrite'] = Tools::link_rewrite($product['name']);
$result = $this->ExecuteS('SELECT `categories_id` FROM `'.bqSQL($this->prefix).'products_to_categories` WHERE products_id = '.(int)$product['id_product']);
$category_product = array('category_product' => array($product['id_category_default'] => $product['id_product']));
foreach($result as $res)
@@ -462,7 +469,8 @@ class importerosc extends ImportModule
public function displayConfigConnector()
{
$content = '<label>'.$this->l('Server').' : </label>
$content = '<script>var type_connector = "db";</script>
<label>'.$this->l('Server').' : </label>
<div class="margin-form">
<input type="text" name="server" id="server" value="">
<p>'.$this->l('(eg : mysql.mydomain.com)').'</p>
@@ -488,6 +496,137 @@ class importerosc extends ImportModule
return $content;
}
public function checkCategoriesLevel()
{
$columns = $this->ExecuteS('SHOW COLUMNS FROM `'.bqSQL($this->prefix).'categories` ');
foreach($columns as $field)
if ($field['Field'] == 'level')
return true;
return false;
}
public function displayCategoriesLevelConf()
{
$html = '<div class="warn" id="warn_category_level" style="width:450px;display:none">
<img src="../img/admin/warn2.png">
'.$this->l('You are trying to import categories and we\'ve detected, that your oscommerce database don\'t have the field "level" in the table categorie. You must have this field to continue the import of categories.');
$html .= '<button class="button" onclick="addAndCalculateLevel();" style="padding:10px;font-size:13px;text:align:center">'.$this->l('Click to add and calculate the filed "level" .').'</button> <span id="loading" style="display:none"><img src="../img/loader.gif"></span></div>
<div class="conf" id="conf_category_level" style="width:450px;display:none"><img src="../img/admin/ok2.png">'.$this->l('Level field\'s has been created and calculated, You can continue').'</div>';
$html .= '
<script>
$(document).ready(function (){
function checkCategorySelected()
{
if ($(\'#id_category_on:radio\').attr(\'checked\'))
{
$(\'#warn_category_level\').show();
$(\'#checkAndSaveConfig\').attr(\'disabled\', \'disabled\');
$(\'#checkAndSaveConfig\').hide();
}
else
{
$(\'#warn_category_level\').hide();
$(\'#checkAndSaveConfig\').removeAttr(\'disabled\');
$(\'#checkAndSaveConfig\').show();
}
}
checkCategorySelected();
$(\'input[name="getCategories"]\').change( function () {
checkCategorySelected();
});
});
function addAndCalculateLevel()
{
if (confirm(\''.$this->l('It is highly recommended to backup your database before proceeding. Did you make a backup?').'\'))
{
$(\'#loading\').show();
$.ajax({
type: "GET",
url: "../modules/importerosc/ajax.php",
async: false,
cache: false,
dataType : "json",
data: "ajax=true&token='.sha1(_COOKIE_KEY_.'importosc').'&server="+$(\'#server\').val()+"&user="+$(\'#user\').val()+"&password="+$(\'#password\').val()+"&database="+$(\'#database\').val()+"&prefix="+$(\'#prefix\').val() ,
success: function (jsonData)
{
if (jsonData.hasError)
alert(jsonData.error);
else
{
$(\'#warn_category_level\').remove();
$(\'#checkAndSaveConfig\').removeAttr(\'disabled\');
$(\'#checkAndSaveConfig\').show();
$(\'#conf_category_level\').show();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
}
});
}
return false;
}
</script>';
return $html;
}
public function createLevelAndCalculate()
{
if ($this->checkCategoriesLevel())
die('{"hasError" : false}');
if ($this->createLevel())
$this->calculateLevel();
else
die('{"hasError" : true, "error" : "'.$this->l('Can not ALTER TABLE').'"}');
}
public function createLevel()
{
return $this->Execute('ALTER TABLE `'.bqSQL($this->prefix).'categories` ADD `level` INT NOT NULL');
}
public function calculateLevel()
{
$this->updateLevel($this->getSubCat(0), 1);
die('{"hasError" : false}');
}
public function updateLevel($ids_cat, $level = 1)
{
$this->Execute('
UPDATE `'.bqSQL($this->prefix).'categories`
SET level = '.(int)$level.'
WHERE categories_id IN ('.implode(',', $ids_cat).')');
foreach($ids_cat as $id)
if ($sub_cat = $this->getSubCat($id))
$this->updateLevel($sub_cat, $level + 1);
}
public function getSubCat($id_parent)
{
$result = $this->ExecuteS('SELECT `categories_id` FROM `'.bqSQL($this->prefix).'categories` WHERE `parent_id`='.(int)$id_parent);
if (!is_array($result) OR empty($result))
return false;
return $this->formatCategoriesIds($result);
}
public function formatCategoriesIds($result)
{
$return = array();
foreach($result as $key => $val)
$return[] = $val['categories_id'];
return $return;
}
}
?>