From 61dbf06cf4061bc88db097ebcb4e1216163f7152 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Fri, 12 Oct 2012 13:25:12 +0000 Subject: [PATCH] // Fix #PSCFV-4916 --- classes/PaymentModule.php | 4 ++-- classes/order/Order.php | 9 ++++----- classes/order/OrderHistory.php | 13 +++++++++---- controllers/admin/AdminOrdersController.php | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index c501502f4..b66d6dc2f 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -531,7 +531,7 @@ abstract class PaymentModuleCore extends Module { $history = new OrderHistory(); $history->id_order = (int)$order->id; - $history->changeIdOrderState(Configuration::get('PS_OS_OUTOFSTOCK'), (int)$order->id); + $history->changeIdOrderState(Configuration::get('PS_OS_OUTOFSTOCK'), $order); $history->addWithemail(); } @@ -539,7 +539,7 @@ abstract class PaymentModuleCore extends Module // So you migth have two order states $new_history = new OrderHistory(); $new_history->id_order = (int)$order->id; - $new_history->changeIdOrderState((int)$id_order_state, (int)$order->id, true); + $new_history->changeIdOrderState((int)$id_order_state, $order, true); $new_history->addWithemail(true, $extra_vars); unset($order_detail); diff --git a/classes/order/Order.php b/classes/order/Order.php index f9aed1be6..285c2543e 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -387,7 +387,7 @@ class OrderCore extends ObjectModel { $history = new OrderHistory(); $history->id_order = (int)($this->id); - $history->changeIdOrderState(Configuration::get('PS_OS_CANCELED'), (int)($this->id)); + $history->changeIdOrderState(Configuration::get('PS_OS_CANCELED'), $this); if (!$history->addWithemail()) return false; } @@ -1289,7 +1289,7 @@ class OrderCore extends ObjectModel $history = new OrderHistory(); $history->id_order = (int)$this->id; $history->id_employee = (int)$id_employee; - $history->changeIdOrderState((int)$id_order_state, (int)$this->id); + $history->changeIdOrderState((int)$id_order_state, $this); $res = Db::getInstance()->getRow(' SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date` FROM `'._DB_PREFIX_.'orders` @@ -1298,10 +1298,9 @@ class OrderCore extends ObjectModel $this->invoice_number = $res['invoice_number']; $this->delivery_date = $res['delivery_date']; $this->delivery_number = $res['delivery_number']; - $history->addWithemail(); - - $this->current_state = $id_order_state; $this->update(); + + $history->addWithemail(); } public function addWs($autodate = true, $nullValues = false) diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php index d044dd8b5..54f5427fc 100644 --- a/classes/order/OrderHistory.php +++ b/classes/order/OrderHistory.php @@ -74,13 +74,18 @@ class OrderHistoryCore extends ObjectModel * @param int $id_order * @param bool $use_existing_payment */ - public function changeIdOrderState($new_order_state, $id_order, $use_existing_payment = false) + public function changeIdOrderState($new_order_state, &$id_order, $use_existing_payment = false) { if (!$new_order_state || !$id_order) return; - // sets order and states - $order = new Order($id_order); + if (!is_object($id_order) && is_numeric($id_order)) + $order = new Order((int)$id_order); + elseif (is_object($id_order)) + $order = $id_order; + else + return; + $new_os = new OrderState((int)$new_order_state, $order->id_lang); $old_os = $order->getCurrentOrderState(); $is_validated = $this->isValidated(); @@ -149,7 +154,7 @@ class OrderHistoryCore extends ObjectModel $product['product_quantity'], Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'), true, - (int)$id_order + (int)$order->id ); } // @since.1.5.0 : if the order was shipped, and is not anymore, we need to restock products diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 5e277d3bf..eb722d780 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -340,7 +340,7 @@ class AdminOrdersControllerCore extends AdminController $use_existings_payment = false; if (!$order->hasInvoice()) $use_existings_payment = true; - $history->changeIdOrderState($order_state->id, $order->id, $use_existings_payment); + $history->changeIdOrderState((int)$order_state->id, $order, $use_existings_payment); $carrier = new Carrier($order->id_carrier, $order->id_lang); $templateVars = array();