From 27212bd126b0660dc38cf876f2f42ed4bb47d8f6 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Tue, 16 Apr 2013 18:56:00 +0200 Subject: [PATCH] [-] CORE : Fix bug last part #PSCFV-8636, cart rule with a reduction and free shipping --- classes/Cart.php | 8 ++++++-- classes/CartRule.php | 2 +- classes/PaymentModule.php | 5 +++-- themes/default/js/cart-summary.js | 6 ++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 1ccb6a72b..0d7e4711a 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2870,8 +2870,12 @@ class CartCore extends ObjectModel { $cart_rule['value_real'] -= $total_shipping; $cart_rule['value_tax_exc'] -= $total_shipping_tax_exc; - $total_discounts -= $total_shipping; - $total_discounts_tax_exc -= $total_shipping_tax_exc; + $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'], (int)$context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_); + $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'], (int)$context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_); + if ($total_discounts > $cart_rule['value_real']) + $total_discounts -= $total_shipping; + if ($total_discounts_tax_exc > $cart_rule['value_tax_exc']) + $total_discounts_tax_exc -= $total_shipping_tax_exc; // Update total shipping $total_shipping = 0; diff --git a/classes/CartRule.php b/classes/CartRule.php index 228f15607..1b0177810 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -912,7 +912,7 @@ class CartRuleCore extends ObjectModel if ($cart_vat_amount == 0 || $cart_amount_te == 0) $cart_average_vat_rate = 0; else - $cart_average_vat_rate = $cart_vat_amount / $cart_amount_te; + $cart_average_vat_rate = Tools::ps_round($cart_vat_amount / $cart_amount_te, 3); if ($this->reduction_tax && !$use_tax) $reduction_value += $prorata * $reduction_amount / (1 + $cart_average_vat_rate); diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 8a9f2e643..f23fd83b7 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -429,13 +429,14 @@ abstract class PaymentModuleCore extends Module // Set the new voucher value if ($voucher->reduction_tax) - $voucher->reduction_amount = $values['tax_incl'] - $order->total_products_wt; + $voucher->reduction_amount = $values['tax_incl'] - $order->total_products_wt - $order->total_shipping_tax_incl; else - $voucher->reduction_amount = $values['tax_excl'] - $order->total_products; + $voucher->reduction_amount = $values['tax_excl'] - $order->total_products - $order->total_shipping_tax_excl; $voucher->id_customer = $order->id_customer; $voucher->quantity = 1; $voucher->quantity_per_user = 1; + $voucher->free_shipping = 0; if ($voucher->add()) { // If the voucher has conditions, they are now copied to the new voucher diff --git a/themes/default/js/cart-summary.js b/themes/default/js/cart-summary.js index f4477fec2..c1c0ac3c7 100644 --- a/themes/default/js/cart-summary.js +++ b/themes/default/js/cart-summary.js @@ -655,9 +655,9 @@ function updateCartSummary(json) location.reload(); if (priceDisplayMethod !== 0) - $('#total_discount').html(formatCurrency(json.total_discounts_tax_exc, currencyFormat, currencySign, currencyBlank)); + $('#total_discount').html('-' + formatCurrency(json.total_discounts_tax_exc, currencyFormat, currencySign, currencyBlank)); else - $('#total_discount').html(formatCurrency(json.total_discounts, currencyFormat, currencySign, currencyBlank)); + $('#total_discount').html('-' + formatCurrency(json.total_discounts, currencyFormat, currencySign, currencyBlank)); $('.cart_discount').each(function(){ var idElmt = $(this).attr('id').replace('cart_discount_',''); @@ -667,10 +667,12 @@ function updateCartSummary(json) if (json.discounts[i].id_discount == idElmt) { if (json.discounts[i].value_real !== '!') + { if (priceDisplayMethod !== 0) $('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_tax_exc * -1, currencyFormat, currencySign, currencyBlank)); else $('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_real * -1, currencyFormat, currencySign, currencyBlank)); + } toDelete = false; } if (toDelete)