// normalization / minor fix in php upgrader files
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12519 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -27,12 +27,12 @@
|
||||
|
||||
function update_order_canada()
|
||||
{
|
||||
$sql ='SHOW TABLES LIKE \''._DB_PREFIX_.'order_tax\'';
|
||||
$table = Db::getInstance()->ExecuteS($sql);
|
||||
$sql ='SHOW TABLES LIKE "'._DB_PREFIX_.'order_tax"';
|
||||
$table = Db::getInstance()->executeS($sql);
|
||||
|
||||
if (!count($table))
|
||||
{
|
||||
Db::getInstance()->Execute('
|
||||
Db::getInstance()->execute('
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'order_tax` (
|
||||
`id_order` int(11) NOT NULL,
|
||||
`tax_name` varchar(40) NOT NULL,
|
||||
@@ -41,46 +41,56 @@ function update_order_canada()
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8');
|
||||
|
||||
|
||||
$address_field = Configuration::get('PS_TAX_ADDRESS_TYPE');
|
||||
$address_field = Db::getInstance()->getValue('SELECT value
|
||||
FROM `'._DB_PREFIX_.'configuration`
|
||||
WHERE name="PS_TAX_ADDRESS_TYPE"');
|
||||
$address_field = str_replace('`','\`', $address_field);
|
||||
|
||||
$sql = 'SELECT `id_order`
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_address` = o.`'.bqSQL($address_field).'`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` cus ON (o.id_customer = cus.id_customer)
|
||||
LEFT JOIN `'._DB_PREFIX_.'group` g ON (g.id_group = cus.id_default_group)
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_address` = o.`'.$address_field.'`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'country` c ON (c.`id_country` = a.`id_country`)
|
||||
WHERE c.`iso_code` = "CA"';
|
||||
|
||||
$id_order_list = Db::getInstance()->ExecuteS($sql);
|
||||
|
||||
$id_order_list = Db::getInstance()->executeS($sql);
|
||||
$default_price_display_method = Db::getInstance()->getValue('SELECT price_display_method
|
||||
FROM `'._DB_PREFIX_.'group WHERE id_group=1`');
|
||||
$values = '';
|
||||
foreach ($id_order_list as $id_order)
|
||||
foreach ($id_order_list as $order)
|
||||
{
|
||||
$amount = array();
|
||||
$id_order = $id_order['id_order'];
|
||||
$order = new Order((int)$id_order);
|
||||
if (!Validate::isLoadedObject($order))
|
||||
continue;
|
||||
$id_order = $order['id_order'];
|
||||
// in Order class, getTaxCalculationMethod
|
||||
// returns Group::getDefaultPriceDisplayMethod
|
||||
$tax_calculation_method = $order['price_display_method'];
|
||||
|
||||
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT * FROM `'._DB_PREFIX_.'order_detail` od
|
||||
WHERE od.`id_order` = '.(int)$id_order);
|
||||
|
||||
$products = $order->getProducts();
|
||||
foreach ($products as $product)
|
||||
{
|
||||
if (!array_key_exists($product['tax_name'], $amount))
|
||||
$amount[$product['tax_name']] = array('amount' => 0, 'rate' => $product['tax_rate']);
|
||||
|
||||
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
if ($tax_calculation_method == PS_TAX_EXC)
|
||||
{
|
||||
$total_product = $product['product_price'] * $product['product_quantity'];
|
||||
$amount_tmp = Tools::ps_round($total_product * ($product['tax_rate'] / 100), 2);
|
||||
$amount[$product['tax_name']]['amount'] += Tools::ps_round($total_product * ($product['tax_rate'] / 100), 2);
|
||||
$amount_tmp = update_order_canada_ps_round($total_product * ($product['tax_rate'] / 100), 2);
|
||||
$amount[$product['tax_name']]['amount'] += update_order_canada_ps_round($total_product * ($product['tax_rate'] / 100), 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$total_product = $product['product_price'] * $product['product_quantity'];
|
||||
$amount_tmp = Tools::ps_round($total_product - ($total_product / (1 + ($product['tax_rate'] / 100))), 2);
|
||||
$amount[$product['tax_name']]['amount'] += Tools::ps_round($total_product - ($total_product / (1 + ($product['tax_rate'] / 100))), 2);
|
||||
$amount_tmp = update_order_canada_ps_round($total_product - ($total_product / (1 + ($product['tax_rate'] / 100))), 2);
|
||||
$amount[$product['tax_name']]['amount'] += update_order_canada_ps_round($total_product - ($total_product / (1 + ($product['tax_rate'] / 100))), 2);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($amount as $tax_name => $tax_infos)
|
||||
$values .= '('.(int)$order->id.', \''.pSQL($tax_name).'\', \''.pSQL($tax_infos['rate']).'\', '.(float)$tax_infos['amount'].'),';
|
||||
$values .= '('.(int)$id_order.', "'.$tax_name.'\', "'.$tax_infos['rate'].'", '.(float)$tax_infos['amount'].'),';
|
||||
unset($order);
|
||||
}
|
||||
|
||||
@@ -95,3 +105,23 @@ function update_order_canada()
|
||||
}
|
||||
}
|
||||
|
||||
function update_order_canada_ps_round($val){
|
||||
static $ps_price_round_mode;
|
||||
if (empty($ps_price_round_mode))
|
||||
{
|
||||
$ps_price_round_mode = Db::getInstance()->getValue('SELECT value
|
||||
FROM `'._DB_PREFIX_.'configuration`
|
||||
WHERE name = "PS_PRICE_ROUND_MODE"');
|
||||
}
|
||||
|
||||
switch ($ps_price_round_mode)
|
||||
{
|
||||
case PS_ROUND_UP:
|
||||
return ceil($val * 100)/100;
|
||||
case PS_ROUND_DOWN:
|
||||
return floor($val * 100)/100;
|
||||
default:
|
||||
return round($val, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user