[-] BO : partial use fixed for cart rules
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12762 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -36,6 +36,7 @@ class CartRuleCore extends ObjectModel
|
||||
public $quantity = 1;
|
||||
public $quantity_per_user = 1;
|
||||
public $priority = 1;
|
||||
public $partial_use = 1;
|
||||
public $code;
|
||||
public $minimum_amount;
|
||||
public $minimum_amount_tax;
|
||||
@@ -72,6 +73,7 @@ class CartRuleCore extends ObjectModel
|
||||
'quantity' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'quantity_per_user' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'priority' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'partial_use' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'code' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 254),
|
||||
'minimum_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'minimum_amount_tax' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
|
||||
@@ -305,24 +305,39 @@ abstract class PaymentModuleCore extends Module
|
||||
'tax_incl' => $cart_rule_obj->getContextualValue(true),
|
||||
'tax_excl' => $cart_rule_obj->getContextualValue(false)
|
||||
);
|
||||
// @Todo : has not been tested because order processing wasn't functionnal
|
||||
|
||||
if ($values['tax_incl'] > $order->total_products_wt && $cart_rule_obj->partial_use == 1 && $cart_rule_obj->reduction_amount > 0)
|
||||
{
|
||||
// Create a new voucher from the original
|
||||
$voucher = clone $cart_rule_obj;
|
||||
unset($voucher->id);
|
||||
|
||||
// Set a new voucher code
|
||||
$voucher->code = empty($voucher->code) ? substr(md5($order->id.'-'.$order->id_customer.'-'.$cart_rule_obj->id), 0, 16) : $voucher->code.'-2';
|
||||
$voucher->reduction_amount = $values['tax_incl'] - $order->total_products_wt;
|
||||
if (preg_match('/\-([0-9]{1,2})\-([0-9]{1,2})$/', $voucher->code, $matches) && $matches[1] == $matches[2])
|
||||
$voucher->code = preg_replace('/'.$matches[0].'$/', '-'.(intval($matches[1]) + 1), $voucher->code);
|
||||
|
||||
// Set the new voucher value
|
||||
if ($voucher->reduction_tax)
|
||||
$voucher->reduction_amount = $values['tax_incl'] - $order->total_products_wt;
|
||||
else
|
||||
$voucher->reduction_amount = $values['tax_excl'] - $order->total_products;
|
||||
|
||||
$voucher->id_customer = $order->id_customer;
|
||||
$voucher->quantity = 1;
|
||||
if ($voucher->add())
|
||||
{
|
||||
// If the voucher has conditions, they are now copied to the new voucher
|
||||
CartRule::copyConditions($cart_rule_obj->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 #', (int)$order->id_lang).$order->id, $params, $customer->email, $customer->firstname.' '.$customer->lastname);
|
||||
|
||||
$params = array(
|
||||
'{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $currency, false),
|
||||
'{voucher_num}' => $voucher->code,
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{id_order}' => $order->reference
|
||||
);
|
||||
Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order ', (int)$order->id_lang).$order->reference, $params, $customer->email, $customer->firstname.' '.$customer->lastname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +205,7 @@ CREATE TABLE `PREFIX_cart_rule` (
|
||||
`quantity` int(10) unsigned NOT NULL default 0,
|
||||
`quantity_per_user` int(10) unsigned NOT NULL default 0,
|
||||
`priority` int(10) unsigned NOT NULL default 1,
|
||||
`partial_use` tinyint(1) unsigned NOT NULL default 0,
|
||||
`code` varchar(254) NOT NULL,
|
||||
`minimum_amount` decimal(17,2) NOT NULL default 0,
|
||||
`minimum_amount_tax` tinyint(1) NOT NULL default 0,
|
||||
|
||||
@@ -44,3 +44,5 @@ INSERT INTO `PREFIX_cart_rule_product_rule_group` (`id_product_rule_group`, `id_
|
||||
|
||||
ALTER TABLE `PREFIX_cart_rule_product_rule` CHANGE `id_cart_rule` `id_product_rule_group` int(10) unsigned NOT NULL;
|
||||
ALTER TABLE `PREFIX_cart_rule_product_rule` CHANGE `type` `type` ENUM('products', 'categories', 'attributes', 'manufacturers', 'suppliers') NOT NULL;
|
||||
|
||||
ALTER TABLE `PREFIX_cart_rule` ADD `partial_use` tinyint(1) unsigned NOT NULL default 0 AFTER `priority`;
|
||||
|
||||
Reference in New Issue
Block a user