From aab264616fe53d906456f2816f0c76cc007ed982 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 15 Nov 2024 13:26:33 +0100 Subject: [PATCH] Only set promo configuration to legacy if no other set This sets the promotion configuration to the legacy promotion system if no other promotion system, like `solidus_promotion` has been configured in the `spree` initializer. This should get rid of errors people encounter when trying to use `solidus_promotions`, but the system being reconfigured without their intervention to use the legacy system. (cherry picked from commit f4d24f2d91241d55e89d238f21ed7b3c8706eec4) --- .../lib/solidus_legacy_promotions/engine.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/legacy_promotions/lib/solidus_legacy_promotions/engine.rb b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb index 3a3df2fc271..ba7fe49583e 100644 --- a/legacy_promotions/lib/solidus_legacy_promotions/engine.rb +++ b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb @@ -100,12 +100,17 @@ class Engine < ::Rails::Engine end initializer "solidus_legacy_promotions", after: "spree.load_config_initializers" do - Spree::Config.order_contents_class = "Spree::OrderContents" - Spree::Config.promotions = SolidusLegacyPromotions::Configuration.new - Spree::Config.adjustment_promotion_source_types << "Spree::PromotionAction" + # Only set these if there is no promotion configuration set. In this case, + # we're running on a store without the new `solidus_promotions` gem and we + # need to set the configuration to the legacy one. + if Spree::Config.promotions.is_a?(Spree::Core::NullPromotionConfiguration) + Spree::Config.order_contents_class = "Spree::OrderContents" + Spree::Config.promotions = SolidusLegacyPromotions::Configuration.new + end Spree::Api::Config.adjustment_attributes << :promotion_code_id Spree::Api::Config.adjustment_attributes << :eligible + Spree::Config.adjustment_promotion_source_types << "Spree::PromotionAction" end end end