diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index f5a30ca46..7262462dd 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -472,12 +472,12 @@ {l s="Payment"} {$order->getOrderPayments()|@count} {if count($order->getOrderPayments()) > 0} -

id == 6)} style="display: none;"{/if}> +

total_paid_tax_incl, 2) == round($total_paid, 2) || (isset($currentState) && $currentState->id == 6)} style="display: none;"{/if}> {l s='Warning'} {displayPrice price=$total_paid currency=$currency->id} {l s='paid instead of'} - {displayPrice price=$orders_total_paid_tax_incl currency=$currency->id} - {foreach $order->getBrother() as $brother_order} + {displayPrice price=$order->total_paid_tax_incl currency=$currency->id} + {* {foreach $order->getBrother() as $brother_order} {if $brother_order@first} {if count($order->getBrother()) == 1}
{l s='This warning also concerns order '} @@ -488,7 +488,7 @@ #{'%06d'|sprintf:$brother_order->id} - {/foreach} + {/foreach} *}

{/if}
diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 407f0ded3..f5efa57b4 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -450,8 +450,13 @@ abstract class PaymentModuleCore extends Module throw new PrestaShopException('Can\'t save Order Payment'); } - foreach($order_list as $order) { - $order->addOrderPaymentDetail($order->amount_paid); + // now add payment detail for order + if ($payment = OrderPayment::getByOrderReference($order->reference)) { + if ($payment = array_shift($payment)) { + foreach($order_list as $order) { + $order->addOrderPaymentDetail($payment, $order->amount_paid); + } + } } } diff --git a/classes/order/Order.php b/classes/order/Order.php index 9d0f54cda..eb468965f 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -1725,6 +1725,7 @@ class OrderCore extends ObjectModel * @param Currency $currency * @param string $date * @param OrderInvoice $order_invoice + * @param bool $update_payment_detail :: if false, be sure to add payment detail in payment detail table * @return bool */ public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null, $order_invoice = null, $update_payment_detail = true) @@ -1746,26 +1747,24 @@ class OrderCore extends ObjectModel } // We put autodate parameter of add method to true if date_add field is null - $res = $order_payment->add(is_null($order_payment->date_add)); - - if (!$res) { - return false; - } - - if ($update_payment_detail) { - $this->addOrderPaymentDetail($amount_paid, $order_invoice); + if ($res = $order_payment->add(is_null($order_payment->date_add))) { + if ($update_payment_detail) { + $res &= $this->addOrderPaymentDetail($order_payment, $amount_paid, $order_invoice); + } } return $res; } - public function addOrderPaymentDetail($amount, $order_invoice = null) + public function addOrderPaymentDetail(OrderPayment $payment, $amount = false, $order_invoice = null) { - if ($orderPayments = OrderPayment::getByOrderReference($this->reference)) { - $lastOrderPayment = array_pop($orderPayments); + if (Validate::isLoadedObject($payment)) { + if (!$amount) { + $amount = $payment->amount; + } $order_payment_detail = new OrderPaymentDetail(); $order_payment_detail->id_order = $this->id; - $order_payment_detail->id_order_payment = (int)$lastOrderPayment->id; + $order_payment_detail->id_order_payment = (int)$payment->id; $order_payment_detail->amount = $amount; if ($lastOrderPayment->id_currency == $this->id_currency) { @@ -1777,7 +1776,7 @@ class OrderCore extends ObjectModel if (!is_null($order_invoice)) { $res = Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'order_invoice_payment` (`id_order_invoice`, `id_order_payment`, `id_order_payment_detail`, `id_order`) - VALUES('.(int)$order_invoice->id.', '.(int)(int)$lastOrderPayment->id.', '.(int)$order_payment_detail->id.', '.(int)$this->id.')'); + VALUES('.(int)$order_invoice->id.', '.(int)(int)$payment->id.', '.(int)$order_payment_detail->id.', '.(int)$this->id.')'); // Clear cache Cache::clean('order_invoice_paid_*'); diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php index 851365312..b2be62c84 100644 --- a/classes/order/OrderHistory.php +++ b/classes/order/OrderHistory.php @@ -336,7 +336,7 @@ class OrderHistoryCore extends ObjectModel $payment->conversion_rate = ($order ? $order->conversion_rate : 1); $payment->save(); - $id_order_payment_detail = $order->addOrderPaymentDetail($rest_paid); + $id_order_payment_detail = $order->addOrderPaymentDetail($payment); Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'order_invoice_payment` (`id_order_invoice`, `id_order_payment`, `id_order_payment_detail`, `id_order`) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 43ab91edc..b03f6e375 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1554,7 +1554,6 @@ class AdminOrdersControllerCore extends AdminController 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), - 'orders_total_paid_tax_incl' => $order->total_paid_tax_incl, // Get the sum of total_paid_tax_incl of the order with similar reference 'total_paid' => $order->getTotalPaid(), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang),