Add a var when shipping is refund

This commit is contained in:
Michael RICOIS 2017-10-19 17:53:46 +02:00
parent c48408c2db
commit 7d2d8f1f03
2 changed files with 37 additions and 23 deletions

View File

@ -674,6 +674,7 @@ class AdminOrders extends AdminTab
$this->_errors[] = Tools::displayError('An error occurred during deletion of the product.').' <span class="bold">'.$orderDetail->product_name.'</span>';
Module::hookExec('cancelProduct', array('order' => $order, 'id_order_detail' => $id_order_detail));
}
if (!sizeof($this->_errors) AND $customizationList)
foreach ($customizationList AS $id_customization => $id_order_detail)
{
@ -682,6 +683,7 @@ class AdminOrders extends AdminTab
if (!$order->deleteCustomization($id_customization, $qtyCancelProduct, $orderDetail))
$this->_errors[] = Tools::displayError('An error occurred during deletion of product customization.').' '.$id_customization;
}
// E-mail params
if ((isset($_POST['generateCreditSlip']) OR isset($_POST['generateDiscount']) OR isset($_POST['generateDiscount2'])) AND !sizeof($this->_errors))
{
@ -776,14 +778,19 @@ class AdminOrders extends AdminTab
// Generate credit slip
if (isset($_POST['generateCreditSlip']) AND !sizeof($this->_errors))
{
if (!OrderSlip::createOrderSlip($order, $full_product_list, $full_quantity_list, isset($_POST['shippingBack'])))
if (!OrderSlip::createOrderSlip($order, $full_product_list, $full_quantity_list, isset($_POST['shippingBack']))) {
$this->_errors[] = Tools::displayError('Cannot generate credit slip');
else
{
Module::hookExec('orderSlip', array('order' => $order, 'productList' => $full_product_list, 'qtyList' => $full_quantity_list));
}
else {
Module::hookExec('orderSlip', array(
'order' => $order,
'productList' => $full_product_list,
'qtyList' => $full_quantity_list,
'shippingBack' => isset($_POST['shippingBack']) ? true : false,
));
@Mail::Send((int)$order->id_lang, 'credit_slip', Mail::l('New credit slip regarding your order', $order->id_lang),
$params, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL,
_PS_MAIL_DIR_, true);
$params, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL,
_PS_MAIL_DIR_, true);
}
}

View File

@ -5,6 +5,8 @@ if (!defined('_PS_VERSION_')) {
class Ant_Refund_Discount extends Module
{
protected $debuglog = false;
public function __construct()
{
$this->name = 'ant_refund_discount';
@ -35,33 +37,41 @@ class Ant_Refund_Discount extends Module
$orderParams = $params['order'];
$productList = $params['productList'];
$qtyList = $params['qtyList'];
$shippingBack = isset($params['shippingBack']) ? $params['shippingBack'] : false;
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', 'Discount : '.$orderParams->total_discounts."\n");
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', print_r($params, 1), FILE_APPEND);
$full = false;
if (isset($params['full']) && $params['full'] === true) {
$full = true;
}
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', 'Discount : '.$orderParams->total_discounts."\n");
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', print_r($params, 1), FILE_APPEND);
// If we have no discount
if ($orderParams->total_discounts == 0) {
return;
}
// If "full" value is set to true, never check the order details
$full = false;
if (isset($params['full']) && $params['full'] === true) {
$full = true;
}
// Product qty
// shippingBack
if (!$full && !$shippingBack) {
return;
}
$order = new Order($orderParams->id);
// Product qty
if ($full === false) {
$orderProducts = $order->getProductsDetail();
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', count($orderProducts).' != '.count($productList)."\n", FILE_APPEND);
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', count($orderProducts).' != '.count($productList)."\n", FILE_APPEND);
// Check product line difference
if (count($orderProducts) != count($productList)) {
return;
}
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', print_r($orderProducts, 1), FILE_APPEND);
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', print_r($orderProducts, 1), FILE_APPEND);
// Check product quantity
foreach ($orderProducts as $p) {
@ -78,7 +88,7 @@ class Ant_Refund_Discount extends Module
$this->copyDiscountAfterRefund($order, $d);
}
}
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', 'FIN', FILE_APPEND);
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', 'FIN', FILE_APPEND);
}
protected function copyDiscountAfterRefund($order, $discount)
@ -87,7 +97,7 @@ class Ant_Refund_Discount extends Module
$item = new Discount($discount['id_discount']);
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', print_r($item, 1), FILE_APPEND);
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', print_r($item, 1), FILE_APPEND);
// Re Create discount
$voucher = new Discount();
@ -96,10 +106,7 @@ class Ant_Refund_Discount extends Module
$voucher->description[$language['id_lang']] = $item->description[$language['id_lang']];
}
$voucher->value = (float) $item->value;
// @todo : Change name
$voucher->name = 'V0C'.(int)($order->id_customer).'O'.(int)($order->id);
$voucher->name = 'R-'.(int)($order->id);
$voucher->id_customer = (int)($order->id_customer);
$voucher->id_currency = (int)($order->id_currency);
$voucher->quantity = 1;