From 4863e60cc3e087f6f4db17a6ba8cc2dd066f177d Mon Sep 17 00:00:00 2001 From: rGaillard Date: Thu, 4 Oct 2012 14:27:09 +0000 Subject: [PATCH] // now can reinject quantities on partial refund git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17758 b9a71923-0436-4b27-9f14-aed3839534dd --- .../controllers/orders/helpers/view/view.tpl | 9 +- controllers/admin/AdminOrdersController.php | 106 +++++++++--------- 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin-dev/themes/default/template/controllers/orders/helpers/view/view.tpl index 79f629a0d..c3bcfb447 100755 --- a/admin-dev/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin-dev/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -719,7 +719,7 @@
 
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index ccbb12d02..542d8ed53 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -474,6 +474,10 @@ class AdminOrdersControllerCore extends AdminController else $order_detail_list[$id_order_detail]['amount'] = (float)str_replace(',', '.', $amount_detail); $amount += $order_detail_list[$id_order_detail]['amount']; + + $order_detail = new OrderDetail((int)$id_order_detail); + if (!$order->hasBeenDelivered() || ($order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities')) && $order_detail_list[$id_order_detail]['quantity'] > 0) + $this->reinjectQuantity($order_detail, $order_detail_list[$id_order_detail]['quantity']); } $shipping_cost_amount = (float)str_replace(',', '.', Tools::getValue('partialRefundShippingCost')); @@ -638,58 +642,9 @@ class AdminOrdersControllerCore extends AdminController $qty_cancel_product = abs($qtyList[$key]); $order_detail = new OrderDetail((int)($id_order_detail)); - // Reinject product - if (!$order->hasBeenDelivered() || ($order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities'))) - { - $reinjectable_quantity = (int)$order_detail->product_quantity - (int)$order_detail->product_quantity_reinjected; - $quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product; - - // @since 1.5.0 : Advanced Stock Management - $product_to_inject = new Product($order_detail->product_id, false, $this->context->language->id, $order->id_shop); - - $product = new Product($order_detail->product_id); - - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') - && $product->advanced_stock_management - && $order_detail->id_warehouse != 0) - { - - $manager = StockManagerFactory::getManager(); - - $movements = StockMvt::getNegativeStockMvts( - $order_detail->id_order, - $order_detail->product_id, - $order_detail->product_attribute_id, - $quantity_to_reinject - ); - - foreach ($movements as $movement) - { - $manager->addProduct( - $order_detail->product_id, - $order_detail->product_attribute_id, - new Warehouse($movement['id_warehouse']), - $movement['physical_quantity'], - null, - $movement['price_te'], - true - ); - } - StockAvailable::synchronize($order_detail->product_id); - } - else if ($order_detail->id_warehouse == 0) - { - StockAvailable::updateQuantity( - $order_detail->product_id, - $order_detail->product_attribute_id, - $quantity_to_reinject, - $order->id_shop - ); - } - else - $this->errors[] = Tools::displayError('Cannot re-stock product'); - } - + if (!$order->hasBeenDelivered() || ($order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities')) && $qty_cancel_product > 0) + $this->reinjectQuantity($order_detail, $qty_cancel_product); + // Delete product $order_detail = new OrderDetail((int)$id_order_detail); if (!$order->deleteProduct($order, $order_detail, $qtyCancelProduct)) @@ -2180,6 +2135,53 @@ class AdminOrdersControllerCore extends AdminController return $products; } + + protected function reinjectQuantity($order_detail, $qty_cancel_product) + { + // Reinject product + $reinjectable_quantity = (int)$order_detail->product_quantity - (int)$order_detail->product_quantity_reinjected; + $quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product; + // @since 1.5.0 : Advanced Stock Management + $product_to_inject = new Product($order_detail->product_id, false, (int)$this->context->language->id, (int)$order_detail->id_shop); + + $product = new Product($order_detail->product_id, false, (int)$this->context->language->id, (int)$order_detail->id_shop); + + if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0) + { + $manager = StockManagerFactory::getManager(); + $movements = StockMvt::getNegativeStockMvts( + $order_detail->id_order, + $order_detail->product_id, + $order_detail->product_attribute_id, + $quantity_to_reinject + ); + + foreach ($movements as $movement) + { + $manager->addProduct( + $order_detail->product_id, + $order_detail->product_attribute_id, + new Warehouse($movement['id_warehouse']), + $movement['physical_quantity'], + null, + $movement['price_te'], + true + ); + } + StockAvailable::synchronize($order_detail->product_id); + } + elseif ($order_detail->id_warehouse == 0) + { + StockAvailable::updateQuantity( + $order_detail->product_id, + $order_detail->product_attribute_id, + $quantity_to_reinject, + $order_detail->id_shop + ); + } + else + $this->errors[] = Tools::displayError('Cannot re-stock product'); + } protected function applyDiscountOnInvoice($order_invoice, $value_tax_incl, $value_tax_excl) {