Skip to content

Commit

Permalink
Feat(SolidusPromotions): Allow viewing both promotion systems
Browse files Browse the repository at this point in the history
Prior to this commit, the new promotion system would exchange the
promotion and promotion category index page components if the gem was
loaded. This made it impossible to actually see the old promotion
configuration when using the new admin.

This commit now only changes the orders/index component if the new
promotion system is activated. In any case, it will display new
promotion and promotion category records under "Promotions (new)".
  • Loading branch information
mamhoff committed Nov 15, 2024
1 parent a1e38fc commit bab02aa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index
set_page_and_extract_portion_from(promotion_categories)

respond_to do |format|
format.html { render component("promotion_categories/index").new(page: @page) }
format.html { render component("solidus_promotions/categories/index").new(page: @page) }
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def index
set_page_and_extract_portion_from(promotions)

respond_to do |format|
format.html { render component("promotions/index").new(page: @page) }
format.html { render component("solidus_promotions/promotions/index").new(page: @page) }
end
end

Expand Down
11 changes: 7 additions & 4 deletions promotions/lib/solidus_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ class Engine < Rails::Engine
end
end

initializer "solidus_promotions.add_admin_order_index_component", after: "solidus_legacy_promotions.add_admin_order_index_component" do
initializer "solidus_promotions.add_admin_order_index_component", after: "spree.load_config_initializers" do
if SolidusSupport.admin_available?
SolidusAdmin::Config.components["orders/index"] = "SolidusPromotions::Orders::Index::Component"
SolidusAdmin::Config.components["promotions/index"] = "SolidusPromotions::Promotions::Index::Component"
SolidusAdmin::Config.components["promotion_categories/index"] = "SolidusPromotions::PromotionCategories::Index::Component"
if Spree::Config.promotions.is_a?(SolidusPromotions::Configuration)
SolidusAdmin::Config.components["orders/index"] = "SolidusPromotions::Orders::Index::Component"
end

SolidusAdmin::Config.components["solidus_promotions/promotions/index"] = "SolidusPromotions::Promotions::Index::Component"
SolidusAdmin::Config.components["solidus_promotions/categories/index"] = "SolidusPromotions::PromotionCategories::Index::Component"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

before { sign_in create(:admin_user, email: "[email protected]") }

around do |example|
SolidusAdmin::Config.components["orders/index"] = "SolidusPromotions::Orders::Index::Component"
example.run
SolidusAdmin::Config.components["orders/index"] = "SolidusAdmin::Orders::Index::Component"
end

it "lists products", :js, :flaky do
visit "/admin/orders"

Expand Down

0 comments on commit bab02aa

Please sign in to comment.