Skip to content

Commit a3bb1fc

Browse files
sofiabesenski4adammathysstewartHarmony Evangelinakjriga
committed
Introduce new InMemoryOrderAdjuster class for promotions
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]>
1 parent d244646 commit a3bb1fc

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

core/app/models/spree/in_memory_order_updater.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def recalculate_adjustments(persist:)
121121
# http://www.hmrc.gov.uk/vat/managing/charging/discounts-etc.htm#1
122122
# It also fits the criteria for sales tax as outlined here:
123123
# http://www.boe.ca.gov/formspubs/pub113/
124-
update_promotions
124+
update_promotions(persist:)
125125
update_taxes
126126
update_item_totals(persist:)
127127
end
@@ -203,8 +203,12 @@ def log_state_change(name)
203203
end
204204
end
205205

206-
def update_promotions
207-
Spree::Config.promotions.order_adjuster_class.new(order).call
206+
def update_promotions(persist:)
207+
if persist
208+
Spree::Config.promotions.order_adjuster_class
209+
else
210+
InMemoryOrderAdjuster
211+
end.new(order).call
208212
end
209213

210214
def update_taxes
@@ -247,5 +251,13 @@ def update_item_totals(persist:)
247251
end
248252
end
249253
end
254+
255+
class InMemoryOrderAdjuster
256+
def initialize(order)
257+
end
258+
259+
def call
260+
end
261+
end
250262
end
251263
end

core/spec/models/spree/in_memory_order_updater_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ module Spree
136136
expect(adjuster).to receive(:call)
137137
order.recalculate
138138
end
139+
140+
context "when recalculating the order in memory" do
141+
it "raises an error" do
142+
order_adjuster = double
143+
allow(order_adjuster).to receive(:call) { raise NotImplementedError }
144+
allow(Spree::InMemoryOrderUpdater::InMemoryOrderAdjuster).to receive(:new).and_return(order_adjuster)
145+
146+
expect{described_class.new(order).recalculate(persist: false)}
147+
.to raise_error(NotImplementedError)
148+
end
149+
end
139150
end
140151

141152
describe 'tax recalculation' do

0 commit comments

Comments
 (0)