From 021e1f9aee7c2af1f61d78b95b911b7e8f8ca10f Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 25 Oct 2023 12:44:13 +0200 Subject: [PATCH] Order Discounter: Create valid shipping rate discounts We forgot to add the promotion action to shipping rate discounts. --- .../solidus_friendly_promotions/order_discounter.rb | 5 +++-- .../order_discounter_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/solidus_friendly_promotions/order_discounter.rb b/app/models/solidus_friendly_promotions/order_discounter.rb index e926704e..dccf6496 100644 --- a/app/models/solidus_friendly_promotions/order_discounter.rb +++ b/app/models/solidus_friendly_promotions/order_discounter.rb @@ -19,10 +19,11 @@ def call discountable_order.shipments.flat_map(&:shipping_rates).each do |shipping_rate| shipping_rate.discounts = shipping_rate.current_discounts.map do |discount| - SolidusFriendlyPromotions::ShippingRateDiscount.new( + SolidusFriendlyPromotions::ShippingRateDiscount.create!( shipping_rate: shipping_rate, amount: discount.amount, - label: discount.label + label: discount.label, + promotion_action: discount.source ) end end diff --git a/spec/models/solidus_friendly_promotions/order_discounter_spec.rb b/spec/models/solidus_friendly_promotions/order_discounter_spec.rb index eaf95e2b..fb195add 100644 --- a/spec/models/solidus_friendly_promotions/order_discounter_spec.rb +++ b/spec/models/solidus_friendly_promotions/order_discounter_spec.rb @@ -92,4 +92,15 @@ end end end + + context "adjusting shipping rates" do + let!(:promotion) { create(:friendly_promotion, actions: [shipment_action], apply_automatically: true) } + let(:shipment_action) { SolidusFriendlyPromotions::Actions::AdjustShipment.new(calculator: fifty_percent) } + let(:fifty_percent) { SolidusFriendlyPromotions::Calculators::Percent.new(preferred_percent: 50) } + let(:order) { create(:order_with_line_items) } + + it "creates shipping rate discounts" do + expect { subject.call }.to change { SolidusFriendlyPromotions::ShippingRateDiscount.count } + end + end end