From 98ccbd7ed2bd3416c4e08f90b28d5171910c7eb8 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 15 Nov 2024 22:13:46 +0100 Subject: [PATCH] Feat(SolidusPromotions): Allow viewing both promotion systems 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)". --- .../promotion_categories_controller.rb | 2 +- .../admin/solidus_promotions/promotions_controller.rb | 2 +- promotions/lib/solidus_promotions/engine.rb | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb b/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb index f27166e38d5..cefb9d44d5d 100644 --- a/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb +++ b/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb @@ -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 diff --git a/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb b/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb index de2fcf25f78..77bc6515108 100644 --- a/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb +++ b/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb @@ -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 diff --git a/promotions/lib/solidus_promotions/engine.rb b/promotions/lib/solidus_promotions/engine.rb index 7c7bec60829..ab8360fdfc4 100644 --- a/promotions/lib/solidus_promotions/engine.rb +++ b/promotions/lib/solidus_promotions/engine.rb @@ -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