Skip to content

Commit 7e76070

Browse files
sofiabesenski4adammathysstewartHarmony EvangelinaKendra Riga
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 <adam@super.gd> Co-authored-by: Andrew Stewart <andrew@super.gd> Co-authored-by: Harmony Evangelina <harmony@super.gd> Co-authored-by: Kendra Riga <kendra@super.gd> Co-authored-by: Jared Norman <jared@super.gd> Co-authored-by: Tom Van Manen <tom@super.gd> Co-authored-by: Senem Soy <senem@super.gd> Co-authored-by: Benjamin Willems <benjamin@super.gd>
1 parent 06e3a2a commit 7e76070

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

core/app/models/spree/in_memory_order_updater.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def update_adjustments(persist:)
117117
# http://www.hmrc.gov.uk/vat/managing/charging/discounts-etc.htm#1
118118
# It also fits the criteria for sales tax as outlined here:
119119
# http://www.boe.ca.gov/formspubs/pub113/
120-
update_promotions
120+
update_promotions(persist:)
121121
update_taxes
122122
update_item_totals(persist:)
123123
end
@@ -153,8 +153,12 @@ def update_adjustment_total(persist:)
153153
recalculate_order_total
154154
end
155155

156-
def update_promotions
157-
Spree::Config.promotions.order_adjuster_class.new(order).call
156+
def update_promotions(persist:)
157+
if persist
158+
Spree::Config.promotions.order_adjuster_class
159+
else
160+
InMemoryOrderAdjuster
161+
end.new(order).call
158162
end
159163

160164
def update_taxes
@@ -239,5 +243,13 @@ def log_state_change(name)
239243
)
240244
end
241245
end
246+
247+
class InMemoryOrderAdjuster
248+
def initialize(order)
249+
end
250+
251+
def call
252+
end
253+
end
242254
end
243255
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
@@ -166,6 +166,17 @@ module Spree
166166
line_item.additional_tax_total
167167
}.from(1).to(2)
168168
end
169+
170+
context "when recalculating the order in memory" do
171+
it "raises an error" do
172+
order_adjuster = double
173+
allow(order_adjuster).to receive(:call) { raise NotImplementedError }
174+
allow(Spree::InMemoryOrderUpdater::InMemoryOrderAdjuster).to receive(:new).and_return(order_adjuster)
175+
176+
expect{described_class.new(order).recalculate(persist: false)}
177+
.to raise_error(NotImplementedError)
178+
end
179+
end
169180
end
170181

171182
context 'with a custom tax_calculator_class' do

0 commit comments

Comments
 (0)