[+] Project : Vouchers are now replaced by cart rules
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9771 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -276,6 +276,10 @@ class AuthControllerCore extends FrontController
|
||||
$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
|
||||
$this->context->cart->update();
|
||||
Module::hookExec('authentication');
|
||||
|
||||
// Login information have changed, so we check if the cart rules still apply
|
||||
CartRule::autoRemoveFromCart();
|
||||
|
||||
if (!$this->ajax)
|
||||
{
|
||||
if ($back = Tools::getValue('back'))
|
||||
@@ -565,15 +569,15 @@ class AuthControllerCore extends FrontController
|
||||
protected function sendConfirmationMail(Customer $customer)
|
||||
{
|
||||
return Mail::Send(
|
||||
$this->context->language->id,
|
||||
'account',
|
||||
$this->context->language->id,
|
||||
'account',
|
||||
Mail::l('Welcome!'),
|
||||
array(
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{email}' => $customer->email,
|
||||
'{passwd}' => Tools::getValue('passwd')),
|
||||
$customer->email,
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{email}' => $customer->email,
|
||||
'{passwd}' => Tools::getValue('passwd')),
|
||||
$customer->email,
|
||||
$customer->firstname.' '.$customer->lastname
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,9 +58,6 @@ class CartControllerCore extends FrontController
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
// Check cart discounts
|
||||
$this->processRemoveDiscounts();
|
||||
|
||||
if ($this->isTokenValid())
|
||||
$this->errors[] = Tools::displayError('Invalid token');
|
||||
|
||||
@@ -72,8 +69,6 @@ class CartControllerCore extends FrontController
|
||||
else if (Tools::getIsset('delete'))
|
||||
$this->processDeleteProductInCart();
|
||||
|
||||
$this->processRemoveDiscounts();
|
||||
|
||||
// Make redirection
|
||||
if (!$this->errors && !$this->ajax)
|
||||
{
|
||||
@@ -107,6 +102,7 @@ class CartControllerCore extends FrontController
|
||||
$this->context->cart->gift_message = '';
|
||||
$this->context->cart->update();
|
||||
}
|
||||
CartRule::autoRemoveFromCart();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,29 +143,6 @@ class CartControllerCore extends FrontController
|
||||
else if (!$product->checkQty($this->qty))
|
||||
$this->errors[] = Tools::displayError('There is not enough product in stock.');
|
||||
|
||||
// Check vouchers compatibility
|
||||
if ($mode == 'add' && (($product->specificPrice && (float)$product->specificPrice['reduction']) || $product->on_sale))
|
||||
{
|
||||
$discounts = $this->context->cart->getDiscounts();
|
||||
$hasUndiscountedProduct = null;
|
||||
foreach ($discounts as $discount)
|
||||
{
|
||||
if (is_null($hasUndiscountedProduct))
|
||||
{
|
||||
$hasUndiscountedProduct = false;
|
||||
foreach ($this->context->cart->getProducts() as $product)
|
||||
if ($product['reduction_applies'] === false)
|
||||
{
|
||||
$hasUndiscountedProduct = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$discount['cumulable_reduction'] && ($discount['id_discount_type'] != Discount::PERCENT || !$hasUndiscountedProduct))
|
||||
$this->errors[] = Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// If no errors, process product addition
|
||||
if (!$this->errors && $mode == 'add')
|
||||
{
|
||||
@@ -198,6 +171,7 @@ class CartControllerCore extends FrontController
|
||||
$this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.');
|
||||
}
|
||||
}
|
||||
CartRule::autoRemoveFromCart();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,18 +179,8 @@ class CartControllerCore extends FrontController
|
||||
*/
|
||||
protected function processRemoveDiscounts()
|
||||
{
|
||||
$orderTotal = $this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
|
||||
$cartProducts = $this->context->cart->getProducts();
|
||||
foreach ($this->context->cart->getDiscounts() as $discount)
|
||||
{
|
||||
$discountObj = new Discount($discount['id_discount'], $this->context->language->id);
|
||||
if ($error = $this->context->cart->checkDiscountValidity($discountObj, $discounts, $orderTotal, $cartProducts, false))
|
||||
{
|
||||
$this->context->cart->deleteDiscount($discount['id_discount']);
|
||||
$this->context->cart->update();
|
||||
$this->errors[] = $error;
|
||||
}
|
||||
}
|
||||
Tools::displayAsDeprecated();
|
||||
$this->errors = array_merge($this->errors, CartRule::autoRemoveFromCart());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -88,38 +88,40 @@ class ParentOrderControllerCore extends FrontController
|
||||
|
||||
if ($this->nbProducts)
|
||||
{
|
||||
if (Tools::isSubmit('submitAddDiscount') && Tools::getValue('discount_name') && Discount::isFeatureActive())
|
||||
if (CartRule::isFeatureActive())
|
||||
{
|
||||
$discountName = Tools::getValue('discount_name');
|
||||
if (!Validate::isDiscountName($discountName))
|
||||
$this->errors[] = Tools::displayError('Voucher name invalid.');
|
||||
else
|
||||
if (Tools::isSubmit('submitAddDiscount'))
|
||||
{
|
||||
$discount = new Discount((int)(Discount::getIdByName($discountName)));
|
||||
if (Validate::isLoadedObject($discount))
|
||||
{
|
||||
if ($tmpError = $this->context->cart->checkDiscountValidity($discount, $this->context->cart->getDiscounts(), $this->context->cart->getOrderTotal(), $this->context->cart->getProducts(), true))
|
||||
$this->errors[] = $tmpError;
|
||||
}
|
||||
if (!($code = Tools::getValue('discount_name')))
|
||||
$this->errors[] = Tools::displayError('You must enter a voucher code');
|
||||
elseif (!Validate::isDiscountName($code))
|
||||
$this->errors[] = Tools::displayError('Voucher code invalid');
|
||||
else
|
||||
$this->errors[] = Tools::displayError('Voucher name invalid.');
|
||||
if (!count($this->errors))
|
||||
{
|
||||
$this->context->cart->addDiscount((int)($discount->id));
|
||||
Tools::redirect('index.php?controller=order-opc');
|
||||
if ($cartRule = new CartRule(CartRule::getIdByCode($code)) AND Validate::isLoadedObject($cartRule))
|
||||
{
|
||||
if ($error = $cartRule->checkValidity($this->context))
|
||||
$this->errors[] = $error;
|
||||
else
|
||||
{
|
||||
$this->context->cart->addCartRule($cartRule->id);
|
||||
Tools::redirect('index.php?controller=order-opc');
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->errors[] = Tools::displayError('Voucher name invalid.');
|
||||
}
|
||||
$this->context->smarty->assign(array(
|
||||
'errors' => $this->errors,
|
||||
'discount_name' => Tools::safeOutput($code)
|
||||
));
|
||||
}
|
||||
elseif ($id_cart_rule = (int)Tools::getValue('deleteDiscount') AND Validate::isUnsignedId($id_cart_rule))
|
||||
{
|
||||
$this->context->cart->removeCartRule($id_cart_rule);
|
||||
Tools::redirect('index.php?controller=order-opc');
|
||||
}
|
||||
$this->context->smarty->assign(array(
|
||||
'errors' => $this->errors,
|
||||
'discount_name' => Tools::safeOutput($discountName)
|
||||
));
|
||||
}
|
||||
else if (isset($_GET['deleteDiscount']) && Validate::isUnsignedId($_GET['deleteDiscount']) && Discount::isFeatureActive())
|
||||
{
|
||||
$this->context->cart->deleteDiscount((int)($_GET['deleteDiscount']));
|
||||
Tools::redirect('index.php?controller=order-opc');
|
||||
}
|
||||
|
||||
/* Is there only virtual product in cart */
|
||||
if ($isVirtualCart = $this->context->cart->isVirtualCart())
|
||||
$this->setNoCarrier();
|
||||
@@ -222,7 +224,11 @@ class ParentOrderControllerCore extends FrontController
|
||||
|
||||
Module::hookExec('processCarrier', array('cart' => $this->context->cart));
|
||||
|
||||
return $this->context->cart->update();
|
||||
if (!$this->context->cart->update())
|
||||
return false;
|
||||
|
||||
// Carrier has changed, so we check if the cart rules still apply
|
||||
CartRule::autoRemoveFromCart();
|
||||
}
|
||||
|
||||
protected function _assignSummaryInformations()
|
||||
@@ -249,7 +255,7 @@ class ParentOrderControllerCore extends FrontController
|
||||
|
||||
if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency($this->context->cart->id_currency)))
|
||||
{
|
||||
$discounts = $this->context->cart->getDiscounts();
|
||||
$discounts = $this->context->cart->getCartRules();
|
||||
$total_free_ship = $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']);
|
||||
foreach ($discounts as $discount)
|
||||
if ($discount['id_discount_type'] == Discount::FREE_SHIPPING)
|
||||
@@ -338,7 +344,12 @@ class ParentOrderControllerCore extends FrontController
|
||||
}
|
||||
/* Update cart addresses only if needed */
|
||||
if (isset($update) && $update)
|
||||
{
|
||||
$this->context->cart->update();
|
||||
|
||||
// Address has changed, so we check if the cart rules still apply
|
||||
CartRule::autoRemoveFromCart();
|
||||
}
|
||||
|
||||
/* If delivery address is valid in cart, assign it to Smarty */
|
||||
if (isset($this->context->cart->id_address_delivery))
|
||||
|
||||
Reference in New Issue
Block a user