[-] Installer : no more sql or php error when upgrade. ( @todo update_feature_detachable_cache )

This commit is contained in:
mMarinetti
2012-01-06 16:27:42 +00:00
parent dec32fcd31
commit 0c226b3e8d
10 changed files with 163 additions and 76 deletions
+31 -16
View File
@@ -5,6 +5,7 @@ function update_order_detail_taxes()
$order_detail_taxes = Db::getInstance()->executeS('
SELECT `id_order_detail`, `tax_name`, `tax_rate` FROM `'._DB_PREFIX_.'order_detail`
');
$id_lang_list = Db::getInstance()->executeS('SELECT id_lang FROM `'._DB_PREFIX_.'lang`');
foreach ($order_detail_taxes as $order_detail_tax)
{
@@ -13,27 +14,41 @@ function update_order_detail_taxes()
$alternative_tax_name = 'Tax '.$order_detail_tax['tax_rate'];
$create_tax = true;
if ($id_tax = (int)Tax::getTaxIdByName($order_detail_tax['tax_name'], false) || $id_tax = (int)Tax::getTaxIdByName($alternative_tax_name, false))
$id_tax = (int)Db::getInstance()->getValue('SELECT t.`id_tax`
FROM `'._DB_PREFIX_.'tax` t
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (tl.id_tax = t.id_tax)
WHERE tl.`name` = \''.pSQL($order_detail_tax['tax_name']).'\' ');
$id_tax_alt = (int)Db::getInstance()->getValue('SELECT t.`id_tax`
FROM `'._DB_PREFIX_.'tax` t
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (tl.id_tax = t.id_tax)
WHERE tl.`name` = \''.pSQL($alternative_tax_name).'\' ');
if ( $id_tax || $id_tax_alt)
{
$tax = new Tax($id_tax);
if (Validate::isLoadedObject($tax))
if ((string)$tax->rate == (string)$order_detail_tax['tax_rate'])
$create_tax = false;
else
echo (string)$tax->rate.'!='.(string)$order_detail_tax['tax_rate'];
$create_tax = !(bool)Db::getInstance()->getValue('SELECT count(*)
FROM `'._DB_PREFIX_.'tax`
WHERE id_tax = '. (int)$id_tax .'
AND rate = "'.pSql($order_detail_tax['tax_rate']).'"
');
}
if ($create_tax)
{
$tax = new Tax();
$tax->rate = (float)$order_detail_tax['tax_rate'];
$tax->name[Configuration::get('PS_LANG_DEFAULT')] = (isset($order_detail_tax['tax_name']) ? $order_detail_tax['tax_name'] : $alternative_tax_name);
$tax->deleted = true;
$tax->active = false;
$tax->save();
$tax_name = (isset($order_detail_tax['tax_name']) ? $order_detail_tax['tax_name'] : $alternative_tax_name);
$id_tax = $tax->id;
Db::getInstance()->Execute(
'INSERT INTO `'._DB_PREFIX_.'tax` (`rate`, `active`, `deleted`)
VALUES (\''.(float)$order_detail_tax['tax_rate'].'\', 0, 1)'
);
$id_tax = Db::getInstance()->Insert_ID();
foreach ($id_lang_list as $id_lang)
{
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'tax_lang` (`id_tax`, `id_lang`, `name`)
VALUES ('.(int)$id_tax.','.(int)$id_lang['id_lang'].',\''.pSQL($tax_name).'\')
');
}
}
Db::getInstance()->execute('
@@ -42,4 +57,4 @@ function update_order_detail_taxes()
');
}
}
}