Skip to content

Commit

Permalink
Introduce new InMemoryOrderAdjuster class for promotions
Browse files Browse the repository at this point in the history
This is just a stub for now, but we want to eventually introduce a class
to handle running the promotion adjustments in memory.

Co-authored-by: Adam Mueller <[email protected]>
Co-authored-by: Andrew Stewart <[email protected]>
Co-authored-by: Harmony Evangelina <[email protected]>
Co-authored-by: Kendra Riga <[email protected]>
Co-authored-by: Jared Norman <[email protected]>
Co-authored-by: Tom Van Manen <[email protected]>
Co-authored-by: Senem Soy <[email protected]>
Co-authored-by: Benjamin Willems <[email protected]>
  • Loading branch information
9 people committed Dec 6, 2024
1 parent d244646 commit a3bb1fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/app/models/spree/in_memory_order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def recalculate_adjustments(persist:)
# http://www.hmrc.gov.uk/vat/managing/charging/discounts-etc.htm#1
# It also fits the criteria for sales tax as outlined here:
# http://www.boe.ca.gov/formspubs/pub113/
update_promotions
update_promotions(persist:)
update_taxes
update_item_totals(persist:)
end
Expand Down Expand Up @@ -203,8 +203,12 @@ def log_state_change(name)
end
end

def update_promotions
Spree::Config.promotions.order_adjuster_class.new(order).call
def update_promotions(persist:)
if persist
Spree::Config.promotions.order_adjuster_class
else
InMemoryOrderAdjuster
end.new(order).call
end

def update_taxes
Expand Down Expand Up @@ -247,5 +251,13 @@ def update_item_totals(persist:)
end
end
end

class InMemoryOrderAdjuster
def initialize(order)
end

def call
end
end
end
end
11 changes: 11 additions & 0 deletions core/spec/models/spree/in_memory_order_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ module Spree
expect(adjuster).to receive(:call)
order.recalculate
end

context "when recalculating the order in memory" do
it "raises an error" do
order_adjuster = double
allow(order_adjuster).to receive(:call) { raise NotImplementedError }
allow(Spree::InMemoryOrderUpdater::InMemoryOrderAdjuster).to receive(:new).and_return(order_adjuster)

expect{described_class.new(order).recalculate(persist: false)}
.to raise_error(NotImplementedError)
end
end
end

describe 'tax recalculation' do
Expand Down

0 comments on commit a3bb1fc

Please sign in to comment.