From f7398438a80af4a9914cb1936257260cbce5bcf3 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Mon, 2 Sep 2024 14:39:42 +0200 Subject: [PATCH] Decorate Default Return Refund Amount Calculator in LegacyPromotions This calculator uses the `eligible` API from `Spree::Adjustment`, which in a system with the new promotions system will not be necessary. This hasn't been caught before because deprecation warnings did not raise until https://github.com/solidusio/solidus/pull/5813 was merged. --- .../calculator/returns/default_refund_amount.rb | 2 +- ...lator_returns_default_refund_amount_decorator.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_calculator_returns_default_refund_amount_decorator.rb diff --git a/core/app/models/spree/calculator/returns/default_refund_amount.rb b/core/app/models/spree/calculator/returns/default_refund_amount.rb index b92da1fd105..fc3833560fc 100644 --- a/core/app/models/spree/calculator/returns/default_refund_amount.rb +++ b/core/app/models/spree/calculator/returns/default_refund_amount.rb @@ -14,7 +14,7 @@ def compute(return_item) private def weighted_order_adjustment_amount(inventory_unit) - inventory_unit.order.adjustments.eligible.non_tax.sum(:amount) * percentage_of_order_total(inventory_unit) + inventory_unit.order.adjustments.non_tax.sum(:amount) * percentage_of_order_total(inventory_unit) end def weighted_line_item_amount(inventory_unit) diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_calculator_returns_default_refund_amount_decorator.rb b/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_calculator_returns_default_refund_amount_decorator.rb new file mode 100644 index 00000000000..0a1726a9c6c --- /dev/null +++ b/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_calculator_returns_default_refund_amount_decorator.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module SolidusLegacyPromotions + module SpreeCalculatorReturnsDefaultRefundAmountDecorator + private + + def weighted_order_adjustment_amount(inventory_unit) + inventory_unit.order.adjustments.eligible.non_tax.sum(:amount) * percentage_of_order_total(inventory_unit) + end + + Spree::Calculator::Returns::DefaultRefundAmount.prepend self + end +end