From b3adf075e551ea286f76a36f4c0580927e8c08dd Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Wed, 17 Jan 2018 11:56:50 +0100 Subject: [PATCH] Quantity for return form --- adm/tabs/AdminOrders.php | 8 +++++--- override/classes/OrderReturn.php | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/adm/tabs/AdminOrders.php b/adm/tabs/AdminOrders.php index 95fe52d3..cd03d34e 100755 --- a/adm/tabs/AdminOrders.php +++ b/adm/tabs/AdminOrders.php @@ -240,18 +240,19 @@ class AdminOrders extends AdminTab ON d.`product_id` = c.`id_product` WHERE d.`id_order` = '.(int) $order->id.' ') as $product) { + // Calcul de la quantité possible returnable. $qty = OrderReturn::getOrderDetailReturnQty($product); if($qty > 0) { $returnable[$product['id_order_detail']] = array($product['product_name'], $qty, $product['product_weight']); } } } - $error = FALSE; + $error = false; $total_weight = 0.0; $return_reasons = array(); foreach(Tools::getValue('return_product') as $id_order_detail => $qty) { if(!isset($returnable[(int) $id_order_detail]) || $returnable[(int) $id_order_detail][1] < $qty) { - $error = TRUE; + $error = true; } else { for($i = 1; $i <= $qty; $i++) { if(!($return_reason = Tools::getValue('return_reason_'.$id_order_detail.'_'.$i))) { @@ -1045,7 +1046,8 @@ class AdminOrders extends AdminTab return $content; } - public function _viewDetails() { + public function _viewDetails() + { global $currentIndex, $cookie, $link; $irow = 0; if (!($order = $this->loadObject())) diff --git a/override/classes/OrderReturn.php b/override/classes/OrderReturn.php index 607fbfb2..faf401e1 100644 --- a/override/classes/OrderReturn.php +++ b/override/classes/OrderReturn.php @@ -1,7 +1,11 @@ getRow(' SELECT `id_order` FROM `'._DB_PREFIX_.'shipping_history` @@ -24,6 +28,13 @@ class OrderReturn extends OrderReturnCore { WHERE `id_order_detail` = '.(int) $product['id_order_detail'].' ') - max($product['product_quantity_return'], $product['product_quantity_refunded']); } + + // Use order quantity as fallback + if ($qty == 0 && $id_state > 3) { + $qty = (int) $product['product_quantity'] - max((int) $product['product_quantity_refunded'], (int) $product['product_quantity_return']); + } + + // Remove product quantity mark as return $qty -= (int) Db::getInstance()->getValue(' SELECT SUM(d.`product_quantity`) FROM `'._DB_PREFIX_.'order_return_detail` d @@ -32,6 +43,7 @@ class OrderReturn extends OrderReturnCore { WHERE d.`id_order_detail` = '.(int) $product['id_order_detail'].' AND r.`state` < 3 '); + return $qty; } }