From 3c6f17b85537f8b4f7e6fe53f077bbb714f2969e Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Mon, 4 Feb 2013 14:53:44 +0100 Subject: [PATCH] // Voucher cleaning --- classes/Cart.php | 31 ++++++++++++++++---------- classes/CartRule.php | 8 +++++++ themes/default/shopping-cart.tpl | 38 ++++++++++++++++++-------------- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index a4a555450..16a6fc714 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1331,6 +1331,9 @@ class CartCore extends ObjectModel else $shipping_fees = 0; + if ($type == Cart::ONLY_SHIPPING) + return $shipping_fees; + if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING) $type = Cart::ONLY_PRODUCTS; @@ -1455,6 +1458,8 @@ class CartCore extends ObjectModel $wrapping_fees = 0; if ($this->gift) $wrapping_fees = Tools::convertPrice(Tools::ps_round($this->getGiftWrappingPrice($with_taxes), 2), Currency::getCurrencyInstance((int)$this->id_currency)); + if ($type == Cart::ONLY_WRAPPING) + return $wrapping_fees; $order_total_discount = 0; if (!in_array($type, array(Cart::ONLY_SHIPPING, Cart::ONLY_PRODUCTS)) && CartRule::isFeatureActive()) @@ -1512,12 +1517,6 @@ class CartCore extends ObjectModel $order_total -= $order_total_discount; } - if ($type == Cart::ONLY_SHIPPING) - return $shipping_fees; - - if ($type == Cart::ONLY_WRAPPING) - return $wrapping_fees; - if ($type == Cart::BOTH) $order_total += $shipping_fees + $wrapping_fees; @@ -2861,14 +2860,22 @@ class CartCore extends ObjectModel foreach ($cart_rules as &$cart_rule) { // If the cart rule is automatic (wihtout any code) and include free shipping, it should not be displayed as a cart rule but only set the shipping cost to 0 - if ($cart_rule['free_shipping'] && (empty($cart_rule['code']) || preg_match('/^'.CartRule::BO_ORDER_CODE_PREFIX.'[0-9]+/', $cart_rule['code']))) + if ($cart_rule['free_shipping']) { - $cart_rule['value_real'] -= $total_shipping; - $cart_rule['value_tax_exc'] = $total_shipping_tax_exc; + if (empty($cart_rule['code']) || preg_match('/^'.CartRule::BO_ORDER_CODE_PREFIX.'[0-9]+/', $cart_rule['code'])) + { + $cart_rule['value_real'] -= $total_shipping; + $cart_rule['value_tax_exc'] = $total_shipping_tax_exc; - // Update total shipping - $total_shipping = 0; - $total_shipping_tax_exc = 0; + // Update total shipping + $total_shipping = 0; + $total_shipping_tax_exc = 0; + } + else + { + $total_discounts += $total_shipping; + $total_discounts_tax_exc += $total_shipping_tax_exc; + } } if ($cart_rule['gift_product']) { diff --git a/classes/CartRule.php b/classes/CartRule.php index 39ec0e3aa..2495155e7 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -864,7 +864,15 @@ class CartRuleCore extends ObjectModel // If it has the same tax application that you need, then it's the right value, whatever the product! if ($this->reduction_tax == $use_tax) + { + // The reduction cannot exceed the products total, except when we do not want it to be limited (for the partial use calculation) + if ($filter != CartRule::FILTER_ACTION_ALL_NOCAP) + { + $cart_amount = $context->cart->getOrderTotal($use_tax, Cart::ONLY_PRODUCTS); + $reduction_amount = min($reduction_amount, $cart_amount); + } $reduction_value += $prorata * $reduction_amount; + } else { if ($this->reduction_product > 0) diff --git a/themes/default/shopping-cart.tpl b/themes/default/shopping-cart.tpl index 1c97fa8cb..11ca7779e 100644 --- a/themes/default/shopping-cart.tpl +++ b/themes/default/shopping-cart.tpl @@ -100,23 +100,6 @@ {displayPrice price=$total_products} {/if} - - - {if $use_taxes && $display_tax_label} - {l s='Total vouchers (tax excl.):'} - {else} - {l s='Total vouchers:'} - {/if} - - - {if $use_taxes && !$priceDisplay} - {assign var='total_discounts_negative' value=$total_discounts * -1} - {else} - {assign var='total_discounts_negative' value=$total_discounts_tax_exc * -1} - {/if} - {displayPrice price=$total_discounts_negative} - - {if $use_taxes} @@ -162,6 +145,27 @@ {/if} {/if} + + + {if $display_tax_label} + {if $use_taxes && $priceDisplay == 0} + {l s='Total vouchers (tax incl.):'} + {else} + {l s='Total vouchers (tax excl.):'} + {/if} + {else} + {l s='Total vouchers:'} + {/if} + + + {if $use_taxes} + {assign var='total_discounts_negative' value=$total_discounts * -1} + {else} + {assign var='total_discounts_negative' value=$total_discounts_tax_exc * -1} + {/if} + {displayPrice price=$total_discounts_negative} + + {if $use_taxes} {l s='Total (tax excl.):'}