// Vouchers are shrinkable again (must be tested more thoroughly)
This commit is contained in:
@@ -300,29 +300,29 @@ abstract class PaymentModuleCore extends Module
|
||||
$result = $cart->getCartRules();
|
||||
$cartRules = ObjectModel::hydrateCollection('CartRule', $result, (int)$order->id_lang);
|
||||
// @todo How to menage cart rules, with multiple shipping?
|
||||
foreach ($cartRules AS $cartRule)
|
||||
foreach ($cartRules as $cartRule)
|
||||
{
|
||||
$value = $cartRule->getContextualValue(true);
|
||||
// Todo: repair shrunk
|
||||
// if ($shrunk AND ($total_discount_value + $value) > ($order->total_products_wt + $order->total_shipping + $order->total_wrapping))
|
||||
// {
|
||||
// $amount_to_add = ($order->total_products_wt + $order->total_shipping + $order->total_wrapping) - $total_discount_value;
|
||||
// if ($cartRule->id_discount_type == Discount::AMOUNT AND $cartRule->behavior_not_exhausted == 2)
|
||||
// {
|
||||
// $voucher = new Discount();
|
||||
// foreach ($cartRule AS $key => $discountValue)
|
||||
// $voucher->$key = $discountValue;
|
||||
// $voucher->name = 'VSRK'.(int)$order->id_customer.'O'.(int)$order->id;
|
||||
// $voucher->value = (float)$value - $amount_to_add;
|
||||
// $voucher->add();
|
||||
// $params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false);
|
||||
// $params['{voucher_num}'] = $voucher->name;
|
||||
// $params['{firstname}'] = $customer->firstname;
|
||||
// $params['{lastname}'] = $customer->lastname;
|
||||
// $params['{id_order}'] = $order->id;
|
||||
// @Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order #').$order->id, $params, $customer->email, $customer->firstname.' '.$customer->lastname);
|
||||
// }
|
||||
// }
|
||||
// Todo : has not been tested because order processing wasn't functionnal
|
||||
if ($value > $order->total_products_wt && $cartRule->partial_use == 1 && $cartRule->reduction_amount > 0)
|
||||
{
|
||||
$voucher = clone $cartRule;
|
||||
unset($voucher->id);
|
||||
$voucher->code = empty($voucher->code) ? substr(md5($order->id.'-'.$order->id_customer.'-'.$cartRule->id), 0, 16) : $voucher->code.'-2';
|
||||
$voucher->reduction_amount = $value - $order->total_products_wt;
|
||||
$voucher->id_customer = $order->id_customer;
|
||||
$voucher->quantity = 1;
|
||||
if ($voucher->add())
|
||||
{
|
||||
CartRule::copyConditions($cartRule->id, $voucher->id);
|
||||
$params['{voucher_amount}'] = Tools::displayPrice($voucher->reduction_amount, $currency, false);
|
||||
$params['{voucher_num}'] = $voucher->code;
|
||||
$params['{firstname}'] = $customer->firstname;
|
||||
$params['{lastname}'] = $customer->lastname;
|
||||
$params['{id_order}'] = $order->id;
|
||||
Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order #').$order->id, $params, $customer->email, $customer->firstname.' '.$customer->lastname);
|
||||
}
|
||||
}
|
||||
|
||||
$order->addCartRule($cartRule->id, $cartRule->name, $value);
|
||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED'))
|
||||
|
||||
Reference in New Issue
Block a user