Skip to content

Commit

Permalink
Fix(Admin menus): Stable promotion menu items
Browse files Browse the repository at this point in the history
This makes sure that the promotion menus are always below the product
menu item, in both new admin and the backend.

It also changes the nomenclature to be "Promotions" for the legacy
promotion system and "Promotions (new)" for the new promotion system.
  • Loading branch information
mamhoff committed Nov 15, 2024
1 parent f5e1b1f commit 9da764b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
8 changes: 6 additions & 2 deletions legacy_promotions/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
en:
solidus_admin:
menu_item:
legacy_promotions: Promotions
legacy_promotion_categories: Promotion Categories
spree:
admin:
promotion_status:
Expand All @@ -23,8 +27,8 @@ en:
general: General
starts_at_placeholder: Immediately
tab:
promotions: Legacy Promotions
promotion_categories: Legacy Promotion Categories
legacy_promotions: Promotions
legacy_promotion_categories: Promotion Categories
back_to_promotion_categories_list: Back To Promotions Categories List
back_to_promotions_list: Back To Promotions List
base_amount: Base Amount
Expand Down
16 changes: 14 additions & 2 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,22 @@ class Engine < ::Rails::Engine
if SolidusSupport.admin_available?
SolidusAdmin::Config.configure do |config|
config.menu_items << {
key: "promotions",
key: "legacy_promotions",
route: -> { spree.admin_promotions_path },
icon: "megaphone-line",
position: 30
position: 1.5,
children: [
{
key: "legacy_promotions",
route: -> { spree.admin_promotions_path },
position: 1
},
{
key: "legacy_promotion_categories",
route: -> { spree.admin_promotion_categories_path },
position: 2
}
]
}
end
end
Expand Down
8 changes: 6 additions & 2 deletions promotions/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:
solidus_admin:
menu_item:
promotions: Promotions (new)
promotion_categories: Promotion Categories (new)
spree:
admin:
tab:
solidus_promotions: Promotions
solidus_promotion_categories: Promotion Categories
promotions: Promotions (new)
promotion_categories: Promotion Categories (new)
hints:
solidus_promotions/promotion:
expires_at: This determines when the promotion expires. <br> If no value is specified, the promotion will never expire.
Expand Down
31 changes: 30 additions & 1 deletion promotions/lib/solidus_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ class Engine < Rails::Engine
end
end

initializer "solidus_promotions.add_solidus_admin_menu_items", after: "spree.load_config_initializers" do
if SolidusSupport.admin_available?
SolidusAdmin::Config.configure do |config|
config.menu_items << {
key: "promotions",
route: -> { solidus_promotions.admin_promotions_path },
icon: "megaphone-line",
position: 1.6,
children: [
{
key: "promotions",
route: -> { solidus_promotions.admin_promotions_path },
position: 1
},
{
key: "promotion_categories",
route: -> { solidus_promotions.admin_promotion_categories_path },
position: 1
}
]
}
end
end
end

initializer "solidus_promotions.add_backend_menus", after: "spree.backend.environment" do
if SolidusSupport.backend_available?
promotions_menu_item = Spree::BackendConfiguration::MenuItem.new(
Expand All @@ -82,8 +107,12 @@ class Engine < Rails::Engine
]
)

# We want to appear after the legacy promotions menu item if it exists, otherwise after the products menu item
product_menu_item_index = Spree::Backend::Config.menu_items.find_index { |item| item.label == :products }
Spree::Backend::Config.menu_items.insert(product_menu_item_index + 1, promotions_menu_item)
legacy_promotions_menu_item = Spree::Backend::Config.menu_items.find_index { |item| item.label == :legacy_promotions }
promotions_menu_index = [product_menu_item_index, legacy_promotions_menu_item].compact.max + 1

Spree::Backend::Config.menu_items.insert(promotions_menu_index, promotions_menu_item)
end
end
end
Expand Down

0 comments on commit 9da764b

Please sign in to comment.