Skip to content

Commit

Permalink
Only set promo configuration to legacy if no other set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mamhoff committed Nov 15, 2024
1 parent 8ff6267 commit f4d24f2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,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

0 comments on commit f4d24f2

Please sign in to comment.