diff --git a/admin-dev/themes/default/template/controllers/orders/_shipping.tpl b/admin-dev/themes/default/template/controllers/orders/_shipping.tpl index 40f2072d1..d9807c089 100644 --- a/admin-dev/themes/default/template/controllers/orders/_shipping.tpl +++ b/admin-dev/themes/default/template/controllers/orders/_shipping.tpl @@ -24,11 +24,11 @@ *} - - - - - + + + + + @@ -46,7 +46,7 @@ - +
{dateFormat date=$line.date_add full=true} {$line.type} {$line.carrier_name}{$line.weight|string_format:"%.3f"} {Configuration::get('PS_WEIGHT_UNIT')}{$line.weight|string_format:"%.3f"} {Configuration::get('PS_WEIGHT_UNIT')} {if $order->getTaxCalculationMethod() == $smarty.const.PS_TAX_INC} {displayPrice price=$line.shipping_cost_tax_incl currency=$currency->id} diff --git a/classes/order/Order.php b/classes/order/Order.php index 6d7ba10e4..0cc236e96 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -1237,12 +1237,11 @@ class OrderCore extends ObjectModel public function getTotalWeight() { - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT SUM(product_weight * product_quantity) weight + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT SUM(product_weight * product_quantity) FROM '._DB_PREFIX_.'order_detail WHERE id_order = '.(int)($this->id)); - - return (float)($result['weight']); + return (float)($result); } /** @@ -1881,5 +1880,21 @@ class OrderCore extends ObjectModel $order = new Order($id_order); return $order->getUniqReference(); } + + /** + * Return a unique reference like : GWJTHMZUN#2 + * + * With multishipping, order reference are the same for all orders made with the same cart + * in this case this method suffix the order reference by a # and the order number + * + * @since 1.5.5.0 + */ + public function getIdOrderCarrier() + { + return (int)Db::getInstance()->getValue(' + SELECT `id_order_carrier` + FROM `'._DB_PREFIX_.'order_carrier` + WHERE `id_order` = '.(int)$this->id); + } } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index d571aa1a5..3d0baea97 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -489,6 +489,14 @@ class AdminOrdersControllerCore extends AdminController if ($shipping_cost_amount > 0) $amount += $shipping_cost_amount; + $order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier()); + if (Validate::isLoadedObject($order_carrier)) + { + $order_carrier->weight = (float)$order->getTotalWeight(); + if ($order_carrier->update()) + $order->weight = sprintf("%.3f ".Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); + } + if ($amount > 0) { if (!OrderSlip::createPartialOrderSlip($order, $amount, $shipping_cost_amount, $order_detail_list)) @@ -656,6 +664,14 @@ class AdminOrdersControllerCore extends AdminController $order_detail = new OrderDetail((int)$id_order_detail); if (!$order->deleteProduct($order, $order_detail, $qty_cancel_product)) $this->errors[] = Tools::displayError('An error occurred while attempting to delete the product.').' '.$order_detail->product_name.''; + // Update weight SUM + $order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier()); + if (Validate::isLoadedObject($order_carrier)) + { + $order_carrier->weight = (float)$order->getTotalWeight(); + if ($order_carrier->update()) + $order->weight = sprintf("%.3f ".Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); + } Hook::exec('actionProductCancel', array('order' => $order, 'id_order_detail' => (int)$id_order_detail)); } if (!count($this->errors) && $customizationList) @@ -914,13 +930,10 @@ class AdminOrdersControllerCore extends AdminController $order_detail->updateTaxAmount($order); } - $id_order_carrier = Db::getInstance()->getValue(' - SELECT `id_order_carrier` - FROM `'._DB_PREFIX_.'order_carrier` - WHERE `id_order` = '.(int)$order->id); + $id_order_carrier = (int)$order->getIdOrderCarrier(); if ($id_order_carrier) { - $order_carrier = new OrderCarrier($id_order_carrier); + $order_carrier = $order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier()); $order_carrier->shipping_cost_tax_excl = (float)Tools::convertPriceFull($order_carrier->shipping_cost_tax_excl, $old_currency, $currency); $order_carrier->shipping_cost_tax_incl = (float)Tools::convertPriceFull($order_carrier->shipping_cost_tax_incl, $old_currency, $currency); $order_carrier->update(); @@ -1697,6 +1710,15 @@ class AdminOrdersControllerCore extends AdminController // Save changes of order $order->update(); + + // Update weight SUM + $order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier()); + if (Validate::isLoadedObject($order_carrier)) + { + $order_carrier->weight = (float)$order->getTotalWeight(); + if ($order_carrier->update()) + $order->weight = sprintf("%.3f ".Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); + } // Update Tax lines $order_detail->updateTaxAmount($order); @@ -1904,6 +1926,17 @@ class AdminOrdersControllerCore extends AdminController // Save order detail $res &= $order_detail->update(); + + // Update weight SUM + $order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier()); + if (Validate::isLoadedObject($order_carrier)) + { + $order_carrier->weight = (float)$order->getTotalWeight(); + $res &= $order_carrier->update(); + if ($res) + $order->weight = sprintf("%.3f ".Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); + } + // Save order invoice if (isset($order_invoice)) $res &= $order_invoice->update(); @@ -1996,12 +2029,22 @@ class AdminOrdersControllerCore extends AdminController $order->total_products_wt -= $order_detail->total_price_tax_incl; $res &= $order->update(); - + // Reinject quantity in stock $this->reinjectQuantity($order_detail, $order_detail->product_quantity); // Delete OrderDetail $res &= $order_detail->delete(); + + // Update weight SUM + $order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier()); + if (Validate::isLoadedObject($order_carrier)) + { + $order_carrier->weight = (float)$order->getTotalWeight(); + $res &= $order_carrier->update(); + if ($res) + $order->weight = sprintf("%.3f ".Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); + } if (!$res) die(Tools::jsonEncode(array( diff --git a/js/admin_order.js b/js/admin_order.js index f2305948b..ad96eeb43 100644 --- a/js/admin_order.js +++ b/js/admin_order.js @@ -268,6 +268,10 @@ function updateAmounts(order) $(this).html(old_quantity + 1); $(this).fadeIn('slow'); }); + $('#shipping_table .weight').fadeOut('slow', function() { + $(this).html(order.weight); + $(this).fadeIn('slow'); + }); } function closeAddProduct()