diff --git a/promotions/app/patches/models/solidus_promotions/in_memory_order_updater_patch.rb b/promotions/app/patches/models/solidus_promotions/in_memory_order_updater_patch.rb new file mode 100644 index 0000000000..5d82ec6912 --- /dev/null +++ b/promotions/app/patches/models/solidus_promotions/in_memory_order_updater_patch.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module SolidusPromotions + module InMemoryOrderUpdaterPatch + # This is only needed for stores upgrading from the legacy promotion system. + # Once we've removed support for the legacy promotion system, we can remove this. + def recalculate(persist: true) + if SolidusPromotions.config.sync_order_promotions + MigrationSupport::OrderPromotionSyncer.new(order: order).call + end + super + end + + Spree::InMemoryOrderUpdater.prepend self + end +end diff --git a/promotions/app/patches/models/solidus_promotions/order_recalculator_patch.rb b/promotions/app/patches/models/solidus_promotions/order_updater_patch.rb similarity index 85% rename from promotions/app/patches/models/solidus_promotions/order_recalculator_patch.rb rename to promotions/app/patches/models/solidus_promotions/order_updater_patch.rb index f8fe7cb30a..9719005edf 100644 --- a/promotions/app/patches/models/solidus_promotions/order_recalculator_patch.rb +++ b/promotions/app/patches/models/solidus_promotions/order_updater_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusPromotions - module OrderRecalculatorPatch + module OrderUpdaterPatch # This is only needed for stores upgrading from the legacy promotion system. # Once we've removed support for the legacy promotion system, we can remove this. def recalculate @@ -12,6 +12,5 @@ def recalculate end Spree::OrderUpdater.prepend self - Spree::InMemoryOrderUpdater.prepend self end end diff --git a/promotions/spec/models/promotion/in_memory_integration_spec.rb b/promotions/spec/models/promotion/in_memory_integration_spec.rb index c80bb3fdf2..4793cd0413 100644 --- a/promotions/spec/models/promotion/in_memory_integration_spec.rb +++ b/promotions/spec/models/promotion/in_memory_integration_spec.rb @@ -16,5 +16,10 @@ end it_behaves_like "a successfully integrated promotion system" + + it "allows in memory order recalculates without persistence" do + order = create(:order_with_line_items) + expect { Spree::InMemoryOrderUpdater.new(order).recalculate(persist: false) }.not_to raise_error + end end end