Skip to content

Commit

Permalink
Merge pull request #53 from friendlycart/fix-order-discounter-shippin…
Browse files Browse the repository at this point in the history
…g-rate-discounts

Order Discounter: Create valid shipping rate discounts
  • Loading branch information
mamhoff authored Oct 25, 2023
2 parents 9949557 + 021e1f9 commit 971641c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/solidus_friendly_promotions/order_discounter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/models/solidus_friendly_promotions/order_discounter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 971641c

Please sign in to comment.