Quantity for return form

This commit is contained in:
Michael RICOIS 2018-01-17 11:56:50 +01:00
parent 010ec70298
commit b3adf075e5
2 changed files with 20 additions and 6 deletions

View File

@ -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()))

View File

@ -1,7 +1,11 @@
<?php
class OrderReturn extends OrderReturnCore {
public static function getOrderDetailReturnQty($product, $id_state = 0) {
class OrderReturn extends OrderReturnCore
{
public static function getOrderDetailReturnQty($product, $id_state = 0)
{
$qty = 0;
// Get quantity from shipping details
if(Db::getInstance()->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;
}
}