From 7163d604472d036853b09a61f9b2585caea1da25 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Wed, 21 Feb 2018 16:42:43 +0100 Subject: [PATCH] Detect if is a full refund --- adm/tabs/AdminOrders.php | 78 +++++++++++++++++++++++++++------------ modules/paypal/paypal.php | 28 +++++++++----- 2 files changed, 73 insertions(+), 33 deletions(-) diff --git a/adm/tabs/AdminOrders.php b/adm/tabs/AdminOrders.php index 03e414eb..b3bcf046 100755 --- a/adm/tabs/AdminOrders.php +++ b/adm/tabs/AdminOrders.php @@ -463,7 +463,7 @@ class AdminOrders extends AdminTab exit; } - /* Change order state, add a new entry in order history and send an e-mail to the customer if needed */ + // Change order state, add a new entry in order history and send an e-mail to the customer if needed elseif (Tools::isSubmit('submitState') AND ($id_order = (int)(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order))) { if ($this->tabAccess['edit'] === '1') @@ -506,7 +506,7 @@ class AdminOrders extends AdminTab $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } - /* Add a new message for the current order and send an e-mail to the customer if needed */ + // Add a new message for the current order and send an e-mail to the customer if needed elseif (isset($_POST['submitMessage'])) { $_GET['view'.$this->table] = true; @@ -709,7 +709,7 @@ class AdminOrders extends AdminTab $params['{firstname}'] = $customer->firstname; $params['{id_order}'] = $order->id; - /* PRODUIT REMBOURSE */ + // Refund products $products_refund = ""; $total_refund = 0; foreach ($productList as $key => $id_order_detail) { @@ -717,12 +717,12 @@ class AdminOrders extends AdminTab $tprice = $details_refund->product_price * (1 - $details_refund->reduction_percent / 100) - $details_refund->reduction_amount; $tprice = $tprice * ( 1 + $details_refund->tax_rate / 100 ); $products_refund .= " - - ". $details_refund->product_name . " - " . Tools::displayPrice($tprice) . " - ". (int)$full_quantity_list[$id_order_detail] ." - " . Tools::displayPrice(($tprice * (int)$full_quantity_list[$id_order_detail])) . " - + + ". $details_refund->product_name . " + " . Tools::displayPrice($tprice) . " + ". (int)$full_quantity_list[$id_order_detail] ." + " . Tools::displayPrice(($tprice * (int)$full_quantity_list[$id_order_detail])) . " + "; $total_refund = $total_refund + ($tprice * (int)$full_quantity_list[$id_order_detail]); } @@ -734,16 +734,14 @@ class AdminOrders extends AdminTab if (isset($_POST['shippingBack'])) { $order = new Order($details_refund->id_order); $fraisport .= " - - Frais de port - " . Tools::displayPrice($order->total_shipping) . " - + + Frais de port + " . Tools::displayPrice($order->total_shipping) . " + "; - // Remboursement frais de port Module::hookExec('cancelShipping', array('order' => $order)); } - $params['{fraisport}'] = $fraisport; } @@ -754,13 +752,6 @@ class AdminOrders extends AdminTab $this->_errors[] = Tools::displayError('Cannot generate voucher'); } else { - // $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); - // $params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false); - // $params['{voucher_num}'] = $voucher->name; - // @Mail::Send((int)($order->id_lang), 'voucher', Mail::l('New voucher regarding your order'), - // $params, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, - // NULL, _PS_MAIL_DIR_, true); - // Modif ANTADIS $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false); @@ -807,6 +798,40 @@ class AdminOrders extends AdminTab _PS_MAIL_DIR_, true); } } + + // Auto refund state + if ($order->getCurrentState() != (int)Configuration::get('PS_OS_REFUND')) { + $refundIsFull = false; + $orderSlip = OrderSlip::getOrdersSlip($order->id_customer, $order->id); + if (count($orderSlip) > 0) { + if ($orderSlip['shipping_cost'] == 1) { + $orderSlipDetail = OrderSlip::getOrdersSlipDetail($orderSlip['id_order_slip']); + if (count($orderSlipDetail) > 0) { + foreach ($orderSlipDetail as $k => $v) { + $refundDetail[$v['id_order_detail']] = $v; + } + $orderProducts = $order->getProductsDetail(); + // Check line + $refundIsFull = false; + if (count($orderProducts) == count($orderSlipDetail)) { + $refundIsFull = true; + foreach($orderProducts as $k => $line) { + if ($line['product_quantity'] != $orderSlipDetail[$line['id_order_detail']]['product_quantity']) { + $refundIsFull = false; + break; + } + } + } + } + } + } + // Change order state + if ($refundIsFull === true) { + $history = new OrderHistory(); + $history->id_order = (int)$order->id; + $history->changeIdOrderState((int)Configuration::get('PS_OS_REFUND'), (int)($order->id)); + } + } // Update order state if it's partial if ($order->getCurrentState() == 17) { @@ -821,7 +846,8 @@ class AdminOrders extends AdminTab if (count($to_send) == 0) { $partial = false; - } else { + } + else { include_once dirname(__FILE__).'/../../modules/privatesales/Sale.php'; $quantities_sent = array(); @@ -932,10 +958,14 @@ class AdminOrders extends AdminTab `date_upd` = NOW() '); $newOS = new OrderState((int)(Configuration::get('PS_OS_SHIPPING')), $order->id_lang); - Module::hookExec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))); + Module::hookExec('updateOrderStatus', array( + 'newOrderStatus' => $newOS, + 'id_order' => (int)$order->id + )); } } } + } else { $this->_errors[] = Tools::displayError('No product or quantity selected.'); diff --git a/modules/paypal/paypal.php b/modules/paypal/paypal.php index 1a837c37..a6278995 100755 --- a/modules/paypal/paypal.php +++ b/modules/paypal/paypal.php @@ -120,15 +120,25 @@ class PayPal extends PaymentModule public function install() { - if (!parent::install() || !$this->registerHook('payment') || !$this->registerHook('paymentReturn') || - !$this->registerHook('shoppingCartExtra') || !$this->registerHook('backBeforePayment') || !$this->registerHook('rightColumn') || - !$this->registerHook('cancelProduct') || !$this->registerHook('productFooter') || !$this->registerHook('header') || - !$this->registerHook('adminOrder') || !$this->registerHook('backOfficeHeader')) - return false; + if (!parent::install() + || !$this->registerHook('payment') + || !$this->registerHook('paymentReturn') + || !$this->registerHook('shoppingCartExtra') + || !$this->registerHook('backBeforePayment') + || !$this->registerHook('rightColumn') + || !$this->registerHook('cancelProduct') + || !$this->registerHook('productFooter') + || !$this->registerHook('header') + || !$this->registerHook('adminOrder') + || !$this->registerHook('backOfficeHeader')) { + return false; + } - if ((_PS_VERSION_ >= '1.5') && (!$this->registerHook('displayMobileHeader') || - !$this->registerHook('displayMobileShoppingCartTop') || !$this->registerHook('displayMobileAddToCartTop'))) - return false; + if ((_PS_VERSION_ >= '1.5') && (!$this->registerHook('displayMobileHeader') + || !$this->registerHook('displayMobileShoppingCartTop') + || !$this->registerHook('displayMobileAddToCartTop'))) { + return false; + } include_once(_PS_MODULE_DIR_.'/'.$this->name.'/paypal_install.php'); $paypal_install = new PayPalInstall(); @@ -733,9 +743,9 @@ class PayPal extends PaymentModule mail('karen@bebeboutik.com', 'Erreur dans le remboursement', 'Erreur remboursement échoué pour la commande ' . $order_detail->id_order); mail('doreen@bebeboutik.com', 'Erreur dans le remboursement', 'Erreur remboursement échoué pour la commande ' . $order_detail->id_order); mail('contact@bebeboutik.com', 'Erreur dans le remboursement', 'Erreur remboursement échoué pour la commande ' . $order_detail->id_order); + $message .= $this->l('Transaction error because of the amount of the shipping cost!').'
'; } else { $this->refundSave($order->id, 0, $amount, $cookie->id_employee); - $message .= $this->l('Transaction error because of the amount of the shipping cost!').'
'; } }