// Huge code cleaning on order edition, a lot of values were inconsistent

This commit is contained in:
dMetzger
2012-08-13 16:26:40 +00:00
parent 30ef888c50
commit effdd3ebf0
4 changed files with 53 additions and 52 deletions
+1 -14
View File
@@ -945,22 +945,9 @@ class OrderCore extends ObjectModel
$products = $this->getProductsDetail(); $products = $this->getProductsDetail();
$return = 0; $return = 0;
foreach ($products as $row) foreach ($products as $row)
{ $return += $row['total_price_tax_incl'];
if (!isset($row['tax_rate']))
$row['tax_rate'] = 0;
$price = Tools::ps_round($row['product_price'] * (1 + $row['tax_rate'] / 100), 2);
if ($row['reduction_percent'])
$price -= $price * ($row['reduction_percent'] * 0.01);
if ($row['reduction_amount'])
$price -= $row['reduction_amount'] * (1 + ($row['tax_rate'] * 0.01));
if ($row['group_reduction'])
$price -= $price * ($row['group_reduction'] * 0.01);
$price += $row['ecotax'] * (1 + $row['ecotax_tax_rate'] / 100);
$return += Tools::ps_round($price, 2) * $row['product_quantity'];
}
if (!$products) if (!$products)
{ {
$this->total_products_wt = $return; $this->total_products_wt = $return;
+1 -1
View File
@@ -465,7 +465,7 @@ class OrderDetailCore extends ObjectModel
$this->specificPrice = $specific_price; $this->specificPrice = $specific_price;
$this->original_product_price = Product::getPriceStatic($product['id_product'], false, (int)$product['id_product_attribute'], null, null, false, false, 1, false); $this->original_product_price = Product::getPriceStatic($product['id_product'], false, (int)$product['id_product_attribute'], null, null, false, false, 1, false);
$this->product_price = (float)$product['price']; $this->product_price = $this->original_product_price;
$this->unit_price_tax_incl = (float)$product['price_wt']; $this->unit_price_tax_incl = (float)$product['price_wt'];
$this->unit_price_tax_excl = (float)$product['price']; $this->unit_price_tax_excl = (float)$product['price'];
$this->total_price_tax_incl = (float)$product['total_wt']; $this->total_price_tax_incl = (float)$product['total_wt'];
+12 -14
View File
@@ -115,38 +115,36 @@ class OrderSlipCore extends ObjectModel
.($id_order_detail ? ' WHERE `id_order_detail` = '.(int)($id_order_detail) : '')); .($id_order_detail ? ' WHERE `id_order_detail` = '.(int)($id_order_detail) : ''));
} }
// TODO clean getProducts($resTab) => now getProducts method don't use his parameters
public static function getOrdersSlipProducts($orderSlipId, $order) public static function getOrdersSlipProducts($orderSlipId, $order)
{ {
$cart_rules = $order->getCartRules(true); $cart_rules = $order->getCartRules(true);
$productsRet = OrderSlip::getOrdersSlipDetail($orderSlipId); $productsRet = OrderSlip::getOrdersSlipDetail($orderSlipId);
$products = $order->getProductsDetail(); $order_details = $order->getProductsDetail();
$tmp = array(); $slip_quantity = array();
foreach ($productsRet as $slip_detail) foreach ($productsRet as $slip_detail)
$tmp[$slip_detail['id_order_detail']] = $slip_detail['product_quantity']; $slip_quantity[$slip_detail['id_order_detail']] = $slip_detail['product_quantity'];
$resTab = array(); $products = array();
foreach ($products as $key => $product) foreach ($order_details as $key => $product)
if (isset($tmp[$product['id_order_detail']])) if (isset($slip_quantity[$product['id_order_detail']]))
{ {
$resTab[$key] = $product; $products[$key] = $product;
$resTab[$key]['product_quantity'] = $tmp[$product['id_order_detail']]; $products[$key]['product_quantity'] = $slip_quantity[$product['id_order_detail']];
if (count($cart_rules)) if (count($cart_rules))
{ {
$order->setProductPrices($product); $order->setProductPrices($product);
$realProductPrice = $resTab[$key]['product_price']; $realProductPrice = $products[$key]['product_price'];
// Todo : must be updated to use the cart rules // Todo : must be updated to use the cart rules
foreach ($cart_rules as $cart_rule) foreach ($cart_rules as $cart_rule)
{ {
if ($cart_rule['reduction_percent']) if ($cart_rule['reduction_percent'])
$resTab[$key]['product_price'] -= $realProductPrice * ($cart_rule['reduction_percent'] / 100); $products[$key]['product_price'] -= $realProductPrice * ($cart_rule['reduction_percent'] / 100);
elseif ($cart_rule['reduction_amount']) elseif ($cart_rule['reduction_amount'])
$resTab[$key]['product_price'] -= (($cart_rule['reduction_amount'] * ($product['product_price_wt'] / $order->total_products_wt)) / (1.00 + ($product['tax_rate'] / 100))); $products[$key]['product_price'] -= (($cart_rule['reduction_amount'] * ($product['product_price_wt'] / $order->total_products_wt)) / (1.00 + ($product['tax_rate'] / 100)));
} }
} }
} }
return $order->getProducts($resTab); return $order->getProducts($products);
} }
/** /**
+39 -23
View File
@@ -914,14 +914,26 @@ class AdminOrdersControllerCore extends AdminController
foreach ($order->getOrderDetailList() as $row) foreach ($order->getOrderDetailList() as $row)
{ {
$order_detail = new OrderDetail($row['id_order_detail']); $order_detail = new OrderDetail($row['id_order_detail']);
$order_detail->product_price = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); $fields = array(
$order_detail->reduction_amount = Tools::convertPriceFull($order_detail->reduction_amount, $old_currency, $currency); 'ecotax',
$order_detail->unit_price_tax_incl = Tools::convertPriceFull($order_detail->unit_price_tax_incl, $old_currency, $currency); 'product_price',
$order_detail->unit_price_tax_excl = Tools::convertPriceFull($order_detail->unit_price_tax_excl, $old_currency, $currency); 'reduction_amount',
$order_detail->total_price_tax_incl = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); 'total_shipping',
$order_detail->total_price_tax_excl = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); 'total_shipping_tax_excl',
$order_detail->group_reduction = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); 'total_shipping_tax_incl',
$order_detail->product_quantity_discount = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); 'total_products',
'total_products_wt',
'total_paid',
'total_paid_tax_incl',
'total_paid_tax_excl',
'total_paid_real',
'product_quantity_discount',
'purchase_supplier_price',
'reduction_amount_tax_incl',
'reduction_amount_tax_excl'
);
foreach ($fields as $field)
$order_detail->{$field} = Tools::convertPriceFull($order_detail->{$field}, $old_currency, $currency);
$order_detail->update(); $order_detail->update();
} }
@@ -939,21 +951,25 @@ class AdminOrdersControllerCore extends AdminController
} }
// Update order amount // Update order amount
$order->total_discounts = Tools::convertPriceFull($order->total_discounts, $old_currency, $currency); $fields = array(
$order->total_discounts_tax_incl = Tools::convertPriceFull($order->total_discounts_tax_incl, $old_currency, $currency); 'total_discounts',
$order->total_discounts_tax_excl = Tools::convertPriceFull($order->total_discounts_tax_excl, $old_currency, $currency); 'total_discounts_tax_incl',
$order->total_paid = Tools::convertPriceFull($order->total_paid, $old_currency, $currency); 'total_discounts_tax_excl',
$order->total_paid_tax_incl = Tools::convertPriceFull($order->total_paid_tax_incl, $old_currency, $currency); 'total_paid',
$order->total_paid_tax_excl = Tools::convertPriceFull($order->total_discounts_tax_excl, $old_currency, $currency); 'total_paid_tax_incl',
$order->total_paid_real = Tools::convertPriceFull($order->total_paid_real, $old_currency, $currency); 'total_paid_tax_excl',
$order->total_products = Tools::convertPriceFull($order->total_products, $old_currency, $currency); 'total_paid_real',
$order->total_products_wt = Tools::convertPriceFull($order->total_products_wt, $old_currency, $currency); 'total_products',
$order->total_shipping = Tools::convertPriceFull($order->total_shipping, $old_currency, $currency); 'total_products_wt',
$order->total_shipping_tax_incl = Tools::convertPriceFull($order->total_shipping_tax_incl, $old_currency, $currency); 'total_shipping',
$order->total_shipping_tax_excl = Tools::convertPriceFull($order->total_shipping_tax_excl, $old_currency, $currency); 'total_shipping_tax_incl',
$order->total_wrapping = Tools::convertPriceFull($order->total_wrapping, $old_currency, $currency); 'total_shipping_tax_excl',
$order->total_wrapping_tax_incl = Tools::convertPriceFull($order->total_wrapping_tax_incl, $old_currency, $currency); 'total_wrapping',
$order->total_wrapping_tax_excl = Tools::convertPriceFull($order->total_wrapping_tax_excl, $old_currency, $currency); 'total_wrapping_tax_incl',
'total_wrapping_tax_excl',
);
foreach ($fields as $field)
$order->{$field} = Tools::convertPriceFull($order->{$field}, $old_currency, $currency);
// Update currency in order // Update currency in order
$order->id_currency = $currency->id; $order->id_currency = $currency->id;