This commit is contained in:
parent
b20af01c31
commit
838ed29ce3
@ -288,5 +288,123 @@ class AdminOrdersController extends AdminOrdersControllerCore
|
|||||||
&& Shop::isFeatureActive())
|
&& Shop::isFeatureActive())
|
||||||
unset($this->page_header_toolbar_btn['new_order']);
|
unset($this->page_header_toolbar_btn['new_order']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postProcess()
|
||||||
|
{
|
||||||
|
if (Tools::isSubmit('id_order') && Tools::getValue('id_order') > 0)
|
||||||
|
{
|
||||||
|
$order = new Order(Tools::getValue('id_order'));
|
||||||
|
if (!Validate::isLoadedObject($order))
|
||||||
|
$this->errors[] = Tools::displayError('The order cannot be found within your database.');
|
||||||
|
ShopUrl::cacheMainDomainForShop((int)$order->id_shop);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Tools::isSubmit('partialRefund') && isset($order))
|
||||||
|
{
|
||||||
|
if ($this->tabAccess['edit'] == '1')
|
||||||
|
{
|
||||||
|
if (is_array($_POST['partialRefundProduct']))
|
||||||
|
{
|
||||||
|
$amount = 0;
|
||||||
|
$order_detail_list = array();
|
||||||
|
foreach ($_POST['partialRefundProduct'] as $id_order_detail => $amount_detail)
|
||||||
|
{
|
||||||
|
$order_detail_list[$id_order_detail]['quantity'] = (int)$_POST['partialRefundProductQuantity'][$id_order_detail];
|
||||||
|
|
||||||
|
if (empty($amount_detail))
|
||||||
|
{
|
||||||
|
$order_detail = new OrderDetail((int)$id_order_detail);
|
||||||
|
$order_detail_list[$id_order_detail]['amount'] = $order_detail->unit_price_tax_incl * $order_detail_list[$id_order_detail]['quantity'];
|
||||||
|
}
|
||||||
|
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'));
|
||||||
|
if ($shipping_cost_amount > 0)
|
||||||
|
$amount += $shipping_cost_amount;
|
||||||
|
|
||||||
|
$order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier());
|
||||||
|
if (Validate::isLoadedObject($order_carrier))
|
||||||
|
{
|
||||||
|
$order_carrier->weight = (float)$order->getTotalWeight();
|
||||||
|
if ($order_carrier->update())
|
||||||
|
$order->weight = sprintf("%.3f ".Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($amount > 0)
|
||||||
|
{
|
||||||
|
if (!OrderSlip::createPartialOrderSlip($order, $amount, $shipping_cost_amount, $order_detail_list))
|
||||||
|
$this->errors[] = Tools::displayError('You cannot generate a partial credit slip.');
|
||||||
|
|
||||||
|
// Generate voucher
|
||||||
|
if (Tools::isSubmit('generateDiscountRefund') && !count($this->errors))
|
||||||
|
{
|
||||||
|
$cart_rule = new CartRule();
|
||||||
|
$cart_rule->description = sprintf($this->l('Credit slip for order #%d'), $order->id);
|
||||||
|
$languages = Language::getLanguages(false);
|
||||||
|
foreach ($languages as $language) {
|
||||||
|
$cart_rule->name[$language['id_lang']] = sprintf($this->l('Credit slip for order #%d'), $order->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart_rule->code = sprintf('AV-%d', rand(99999, 999999));
|
||||||
|
$cart_rule->quantity = 1;
|
||||||
|
$cart_rule->quantity_per_user = 1;
|
||||||
|
|
||||||
|
// Specific to the customer
|
||||||
|
$cart_rule->id_customer = $order->id_customer;
|
||||||
|
$now = time();
|
||||||
|
$cart_rule->date_from = date('Y-m-d H:i:s', $now);
|
||||||
|
$cart_rule->date_to = date('Y-m-d H:i:s', $now + (3600 * 24 * 365.25)); /* 1 year */
|
||||||
|
$cart_rule->partial_use = 1;
|
||||||
|
$cart_rule->active = 1;
|
||||||
|
|
||||||
|
$cart_rule->reduction_amount = $amount;
|
||||||
|
$cart_rule->reduction_tax = true;
|
||||||
|
$cart_rule->minimum_amount_currency = $order->id_currency;
|
||||||
|
$cart_rule->reduction_currency = $order->id_currency;
|
||||||
|
|
||||||
|
if (!$cart_rule->add())
|
||||||
|
$this->errors[] = Tools::displayError('You cannot generate a voucher.');
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$currency = $this->context->currency;
|
||||||
|
$customer = new Customer((int)($order->id_customer));
|
||||||
|
$params['{lastname}'] = $customer->lastname;
|
||||||
|
$params['{firstname}'] = $customer->firstname;
|
||||||
|
$params['{id_order}'] = $order->id;
|
||||||
|
$params['{order_name}'] = $order->getUniqReference();
|
||||||
|
$params['{voucher_amount}'] = Tools::displayPrice($cart_rule->reduction_amount, $currency, false);
|
||||||
|
$params['{voucher_num}'] = $cart_rule->code;
|
||||||
|
$customer = new Customer((int)$order->id_customer);
|
||||||
|
@Mail::Send((int)$order->id_lang, 'voucher', sprintf(Mail::l('New voucher for your order #%s', (int)$order->id_lang), $order->reference),
|
||||||
|
$params, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null,
|
||||||
|
null, _PS_MAIL_DIR_, true, (int)$order->id_shop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->errors[] = Tools::displayError('You have to enter an amount if you want to create a partial credit slip.');
|
||||||
|
|
||||||
|
// Redirect if no errors
|
||||||
|
if (!count($this->errors))
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=30&token='.$this->token);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->errors[] = Tools::displayError('The partial refund data is incorrect.');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->errors[] = Tools::displayError('You do not have permission to delete this.');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($_POST['partialRefund']);
|
||||||
|
parent::postProcess();
|
||||||
|
$_POST['partialRefund'] = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user