// Huge code cleaning on order edition, a lot of values were inconsistent
This commit is contained in:
+1
-14
@@ -945,22 +945,9 @@ class OrderCore extends ObjectModel
|
||||
$products = $this->getProductsDetail();
|
||||
|
||||
$return = 0;
|
||||
|
||||
foreach ($products as $row)
|
||||
{
|
||||
if (!isset($row['tax_rate']))
|
||||
$row['tax_rate'] = 0;
|
||||
$return += $row['total_price_tax_incl'];
|
||||
|
||||
$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)
|
||||
{
|
||||
$this->total_products_wt = $return;
|
||||
|
||||
@@ -465,7 +465,7 @@ class OrderDetailCore extends ObjectModel
|
||||
$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->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_excl = (float)$product['price'];
|
||||
$this->total_price_tax_incl = (float)$product['total_wt'];
|
||||
|
||||
+12
-14
@@ -115,38 +115,36 @@ class OrderSlipCore extends ObjectModel
|
||||
.($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)
|
||||
{
|
||||
$cart_rules = $order->getCartRules(true);
|
||||
$productsRet = OrderSlip::getOrdersSlipDetail($orderSlipId);
|
||||
$products = $order->getProductsDetail();
|
||||
$order_details = $order->getProductsDetail();
|
||||
|
||||
$tmp = array();
|
||||
$slip_quantity = array();
|
||||
foreach ($productsRet as $slip_detail)
|
||||
$tmp[$slip_detail['id_order_detail']] = $slip_detail['product_quantity'];
|
||||
$resTab = array();
|
||||
foreach ($products as $key => $product)
|
||||
if (isset($tmp[$product['id_order_detail']]))
|
||||
$slip_quantity[$slip_detail['id_order_detail']] = $slip_detail['product_quantity'];
|
||||
$products = array();
|
||||
foreach ($order_details as $key => $product)
|
||||
if (isset($slip_quantity[$product['id_order_detail']]))
|
||||
{
|
||||
$resTab[$key] = $product;
|
||||
$resTab[$key]['product_quantity'] = $tmp[$product['id_order_detail']];
|
||||
$products[$key] = $product;
|
||||
$products[$key]['product_quantity'] = $slip_quantity[$product['id_order_detail']];
|
||||
if (count($cart_rules))
|
||||
{
|
||||
$order->setProductPrices($product);
|
||||
$realProductPrice = $resTab[$key]['product_price'];
|
||||
$realProductPrice = $products[$key]['product_price'];
|
||||
// Todo : must be updated to use the cart rules
|
||||
foreach ($cart_rules as $cart_rule)
|
||||
{
|
||||
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'])
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -914,14 +914,26 @@ class AdminOrdersControllerCore extends AdminController
|
||||
foreach ($order->getOrderDetailList() as $row)
|
||||
{
|
||||
$order_detail = new OrderDetail($row['id_order_detail']);
|
||||
$order_detail->product_price = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency);
|
||||
$order_detail->reduction_amount = Tools::convertPriceFull($order_detail->reduction_amount, $old_currency, $currency);
|
||||
$order_detail->unit_price_tax_incl = Tools::convertPriceFull($order_detail->unit_price_tax_incl, $old_currency, $currency);
|
||||
$order_detail->unit_price_tax_excl = Tools::convertPriceFull($order_detail->unit_price_tax_excl, $old_currency, $currency);
|
||||
$order_detail->total_price_tax_incl = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency);
|
||||
$order_detail->total_price_tax_excl = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency);
|
||||
$order_detail->group_reduction = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency);
|
||||
$order_detail->product_quantity_discount = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency);
|
||||
$fields = array(
|
||||
'ecotax',
|
||||
'product_price',
|
||||
'reduction_amount',
|
||||
'total_shipping',
|
||||
'total_shipping_tax_excl',
|
||||
'total_shipping_tax_incl',
|
||||
'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();
|
||||
}
|
||||
@@ -939,21 +951,25 @@ class AdminOrdersControllerCore extends AdminController
|
||||
}
|
||||
|
||||
// Update order amount
|
||||
$order->total_discounts = Tools::convertPriceFull($order->total_discounts, $old_currency, $currency);
|
||||
$order->total_discounts_tax_incl = Tools::convertPriceFull($order->total_discounts_tax_incl, $old_currency, $currency);
|
||||
$order->total_discounts_tax_excl = Tools::convertPriceFull($order->total_discounts_tax_excl, $old_currency, $currency);
|
||||
$order->total_paid = Tools::convertPriceFull($order->total_paid, $old_currency, $currency);
|
||||
$order->total_paid_tax_incl = Tools::convertPriceFull($order->total_paid_tax_incl, $old_currency, $currency);
|
||||
$order->total_paid_tax_excl = Tools::convertPriceFull($order->total_discounts_tax_excl, $old_currency, $currency);
|
||||
$order->total_paid_real = Tools::convertPriceFull($order->total_paid_real, $old_currency, $currency);
|
||||
$order->total_products = Tools::convertPriceFull($order->total_products, $old_currency, $currency);
|
||||
$order->total_products_wt = Tools::convertPriceFull($order->total_products_wt, $old_currency, $currency);
|
||||
$order->total_shipping = Tools::convertPriceFull($order->total_shipping, $old_currency, $currency);
|
||||
$order->total_shipping_tax_incl = Tools::convertPriceFull($order->total_shipping_tax_incl, $old_currency, $currency);
|
||||
$order->total_shipping_tax_excl = Tools::convertPriceFull($order->total_shipping_tax_excl, $old_currency, $currency);
|
||||
$order->total_wrapping = Tools::convertPriceFull($order->total_wrapping, $old_currency, $currency);
|
||||
$order->total_wrapping_tax_incl = Tools::convertPriceFull($order->total_wrapping_tax_incl, $old_currency, $currency);
|
||||
$order->total_wrapping_tax_excl = Tools::convertPriceFull($order->total_wrapping_tax_excl, $old_currency, $currency);
|
||||
$fields = array(
|
||||
'total_discounts',
|
||||
'total_discounts_tax_incl',
|
||||
'total_discounts_tax_excl',
|
||||
'total_paid',
|
||||
'total_paid_tax_incl',
|
||||
'total_paid_tax_excl',
|
||||
'total_paid_real',
|
||||
'total_products',
|
||||
'total_products_wt',
|
||||
'total_shipping',
|
||||
'total_shipping_tax_incl',
|
||||
'total_shipping_tax_excl',
|
||||
'total_wrapping',
|
||||
'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
|
||||
$order->id_currency = $currency->id;
|
||||
|
||||
Reference in New Issue
Block a user