diff --git a/classes/CartRule.php b/classes/CartRule.php index a21f6b9eb..30cdcb53d 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -1041,21 +1041,31 @@ class CartRuleCore extends ObjectModel } } + $restricted_product = null; $reduction_amount = $this->reduction_amount; - if ($this->reduction_product) { - if ($restricted_product) { - $prorata = 1; // do not split this cart rule - if ($this->reduction_tax) { - $max_reduction_amount = (int)$restricted_product['cart_quantity'] * (float)$restricted_product['price_wt']; - } else { - $max_reduction_amount = (int)$restricted_product['cart_quantity'] * (float)$restricted_product['price']; + // If the cart rule is restricted to one room type it can't exceed this room type price + if ($this->reduction_product > 0) { + foreach ($package_products as $product) { + if ($product['id_product'] == $this->reduction_product) { + $restricted_product = $product; + + $prorata = 1; // do not split this cart rule + if ($this->reduction_tax) { + $max_reduction_amount = (int) $restricted_product['cart_quantity'] * (float) $restricted_product['price_wt']; + } else { + $max_reduction_amount = (int) $restricted_product['cart_quantity'] * (float) $restricted_product['price']; + } + $reduction_amount = min($reduction_amount, $max_reduction_amount); + + break; } - $reduction_amount = min($reduction_amount, $max_reduction_amount); - } else { - $reduction_amount = 0; } } + if (($this->reduction_product > 0) && !$restricted_product) { + $reduction_amount = 0; + } + // If we need to convert the voucher value to the cart currency if (isset($context->currency) && $this->reduction_currency != $context->currency->id) { $voucherCurrency = new Currency($this->reduction_currency); diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 24c15fcb8..9d953da1a 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -544,8 +544,6 @@ abstract class PaymentModuleCore extends Module } $cart_rules_list = array(); - $total_reduction_value_ti = 0; - $total_reduction_value_tex = 0; foreach ($cart_rules as $cart_rule) { if ($cart_rule['obj']->reduction_product > 0 && !$order->orderContainProduct($cart_rule['obj']->reduction_product)) { continue; @@ -563,7 +561,6 @@ abstract class PaymentModuleCore extends Module } // IF - // This is not multi-shipping // The value of the voucher is greater than the total of the order // Partial use is allowed // This is an "amount" reduction, not a reduction in % or a gift @@ -582,7 +579,7 @@ abstract class PaymentModuleCore extends Module } else { $remaining_amount = $reduction_amount_converted - $values['tax_excl']; } - if (count($order_list) == 1 && $remaining_amount > 0 && $cart_rule['obj']->partial_use == 1 && $reduction_amount_converted > 0) { + if ($remaining_amount > 0 && $cart_rule['obj']->partial_use == 1 && $reduction_amount_converted > 0) { // Create a new voucher from the original $voucher = new CartRule((int)$cart_rule['obj']->id); // We need to instantiate the CartRule without lang parameter to allow saving it unset($voucher->id); @@ -642,12 +639,7 @@ abstract class PaymentModuleCore extends Module null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop ); } - - $values['tax_incl'] = $order->total_products_wt - $total_reduction_value_ti; - $values['tax_excl'] = $order->total_products - $total_reduction_value_tex; } - $total_reduction_value_ti += $values['tax_incl']; - $total_reduction_value_tex += $values['tax_excl']; $order->addCartRule($cart_rule['obj']->id, $cart_rule['obj']->name, $values, 0, $cart_rule['obj']->free_shipping);