[-] BO : fixed gift deletion when there is no products anymore in the cart

This commit is contained in:
Damien Metzger
2013-05-16 11:03:21 +02:00
parent da15136c67
commit 21d45b61bd
2 changed files with 14 additions and 8 deletions
+2 -6
View File
@@ -2958,12 +2958,8 @@ class CartCore extends ObjectModel
return false; return false;
foreach ($this->getProducts() as $product) foreach ($this->getProducts() as $product)
if (!$product['active'] || !$product['available_for_order']
if (!$product['active'] || (!$product['allow_oosp'] && $product['stock_quantity'] < $product['cart_quantity']))
|| (
!$product['allow_oosp'] && $product['stock_quantity'] < $product['cart_quantity']
)
|| !$product['available_for_order'])
return false; return false;
return true; return true;
+12 -2
View File
@@ -530,14 +530,21 @@ class CartRuleCore extends ObjectModel
return (!$display_error) ? false : Tools::displayError('You have not reached the minimum amount required to use this voucher'); return (!$display_error) ? false : Tools::displayError('You have not reached the minimum amount required to use this voucher');
} }
// Check if the voucher is already in the cart of if a non compatible voucher is in the cart /* This loop checks:
// Important note: this MUST be the last check, because if the tested cart rule has priority over a non combinable one in the cart, we will switch them - if the voucher is already in the cart
- if a non compatible voucher is in the cart
- if there are products in the cart (gifts excluded)
Important note: this MUST be the last check, because if the tested cart rule has priority over a non combinable one in the cart, we will switch them
*/
$nb_products = Cart::getNbProducts($context->cart->id);
$otherCartRules = $context->cart->getCartRules(); $otherCartRules = $context->cart->getCartRules();
if (count($otherCartRules)) if (count($otherCartRules))
foreach ($otherCartRules as $otherCartRule) foreach ($otherCartRules as $otherCartRule)
{ {
if ($otherCartRule['id_cart_rule'] == $this->id && !$alreadyInCart) if ($otherCartRule['id_cart_rule'] == $this->id && !$alreadyInCart)
return (!$display_error) ? false : Tools::displayError('This voucher is already in your cart'); return (!$display_error) ? false : Tools::displayError('This voucher is already in your cart');
if ($otherCartRule['gift_product'])
--$nb_products;
if ($this->cart_rule_restriction && $otherCartRule['cart_rule_restriction'] && $otherCartRule['id_cart_rule'] != $this->id) if ($this->cart_rule_restriction && $otherCartRule['cart_rule_restriction'] && $otherCartRule['id_cart_rule'] != $this->id)
{ {
$combinable = Db::getInstance()->getValue(' $combinable = Db::getInstance()->getValue('
@@ -558,6 +565,9 @@ class CartRuleCore extends ObjectModel
} }
} }
if (!$nb_products)
return (!$display_error) ? false : Tools::displayError('Cart is empty');
if (!$display_error) if (!$display_error)
return true; return true;
} }