Skip to content

Commit 07f7f78

Browse files
committed
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.
1 parent 8ff6267 commit 07f7f78

File tree

1 file changed

+10
-5
lines changed
  • legacy_promotions/lib/solidus_legacy_promotions

1 file changed

+10
-5
lines changed

legacy_promotions/lib/solidus_legacy_promotions/engine.rb

+10-5
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,17 @@ class Engine < ::Rails::Engine
8686
end
8787

8888
initializer "solidus_legacy_promotions", after: "spree.load_config_initializers" do
89-
Spree::Config.order_contents_class = "Spree::OrderContents"
90-
Spree::Config.promotions = SolidusLegacyPromotions::Configuration.new
91-
Spree::Config.adjustment_promotion_source_types << "Spree::PromotionAction"
89+
# Only set these if there is no promotion configuration set. In this case,
90+
# we're running on a store without the new `solidus_promotions` gem and we
91+
# need to set the configuration to the legacy one.
92+
if Spree::Config.promotions.is_a?(Spree::Core::NullPromotionConfiguration)
93+
Spree::Config.order_contents_class = "Spree::OrderContents"
94+
Spree::Config.promotions = SolidusLegacyPromotions::Configuration.new
95+
Spree::Config.adjustment_promotion_source_types << "Spree::PromotionAction"
9296

93-
Spree::Api::Config.adjustment_attributes << :promotion_code_id
94-
Spree::Api::Config.adjustment_attributes << :eligible
97+
Spree::Api::Config.adjustment_attributes << :promotion_code_id
98+
Spree::Api::Config.adjustment_attributes << :eligible
99+
end
95100
end
96101
end
97102
end

0 commit comments

Comments
 (0)