Skip to content

Commit

Permalink
Backend Menu: Fix "Promotions" items
Browse files Browse the repository at this point in the history
Prior to this commit, legacy promotions would be called "Promotions",
but if `solidus_promotions` is installed, they would be called "Legacy
Promotions" in the menu. It's much easier if each of the two promotion
engines just inserts its own menu item into the menu, and the legacy
promotion system is called "Legacy Promotions" from the get-go.

Co-Authored-By: [email protected]
  • Loading branch information
tvdeyen authored and mamhoff committed Nov 14, 2024
1 parent b1a3796 commit 6e789f8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 55 deletions.
4 changes: 2 additions & 2 deletions legacy_promotions/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ en:
general: General
starts_at_placeholder: Immediately
tab:
promotion_categories: Promotion Categories
promotions: Promotions
legacy_promotions: Legacy Promotions
legacy_promotion_categories: Legacy 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
10 changes: 5 additions & 5 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ class Engine < ::Rails::Engine
initializer "solidus_legacy_promotions.add_backend_menu_item" do
if SolidusSupport.backend_available?
promotions_menu_item = Spree::BackendConfiguration::MenuItem.new(
label: :promotions,
label: :legacy_promotions,
icon: Spree::Backend::Config.admin_updated_navbar ? "ri-megaphone-line" : "bullhorn",
partial: "spree/admin/shared/promotion_sub_menu",
condition: -> { can?(:admin, Spree::Promotion) },
url: :admin_promotions_path,
data_hook: :admin_promotion_sub_tabs,
children: [
Spree::BackendConfiguration::MenuItem.new(
label: :promotions,
label: :legacy_promotions,
condition: -> { can?(:admin, Spree::Promotion) }
),
Spree::BackendConfiguration::MenuItem.new(
label: :promotion_categories,
condition: -> { can?(:admin, Spree::PromotionCategory) }
label: :legacy_promotion_categories,
condition: -> { can?(:admin, Spree::PromotionCategory) },
url: -> { Spree::Core::Engine.routes.url_helpers.admin_promotion_categories_path },
)
]
)
Expand Down
2 changes: 0 additions & 2 deletions promotions/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ en:
tab:
promotions: Promotions
promotion_categories: Promotion Categories
legacy_promotions: Legacy Promotions
legacy_promotion_categories: Legacy Promotion Categories
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
67 changes: 21 additions & 46 deletions promotions/lib/solidus_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,53 +62,28 @@ class Engine < Rails::Engine

initializer "solidus_promotions.add_backend_menus", after: "spree.backend.environment" do
if SolidusSupport.backend_available?
# Replace the promotions menu from core with ours
Spree::Backend::Config.configure do |config|
config.menu_items = config.menu_items.flat_map do |item|
next item unless item.label.to_sym == :promotions
promotions_menu_item = Spree::BackendConfiguration::MenuItem.new(
label: :promotions,
icon: Spree::Backend::Config.admin_updated_navbar ? "ri-megaphone-line" : "bullhorn",
condition: -> { can?(:admin, SolidusPromotions::Promotion) },
url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotions_path },
data_hook: :admin_solidus_promotion_sub_tabs,
children: [
Spree::BackendConfiguration::MenuItem.new(
label: :promotions,
url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotions_path },
condition: -> { can?(:admin, SolidusPromotions::Promotion) }
),
Spree::BackendConfiguration::MenuItem.new(
label: :promotion_categories,
url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotion_categories_path },
condition: -> { can?(:admin, SolidusPromotions::PromotionCategory) }
)
]
)

[
Spree::BackendConfiguration::MenuItem.new(
label: :promotions,
icon: config.admin_updated_navbar ? "ri-megaphone-line" : "bullhorn",
condition: -> { can?(:admin, SolidusPromotions::Promotion) },
url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotions_path },
data_hook: :admin_solidus_promotion_sub_tabs,
children: [
Spree::BackendConfiguration::MenuItem.new(
label: :promotions,
url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotions_path },
condition: -> { can?(:admin, SolidusPromotions::Promotion) }
),
Spree::BackendConfiguration::MenuItem.new(
label: :promotion_categories,
url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotion_categories_path },
condition: -> { can?(:admin, SolidusPromotions::PromotionCategory) }
)
]
),
Spree::BackendConfiguration::MenuItem.new(
label: :legacy_promotions,
icon: config.admin_updated_navbar ? "ri-megaphone-line" : "bullhorn",
condition: -> { can?(:admin, SolidusPromotions::Promotion) },
url: -> { Spree::Core::Engine.routes.url_helpers.admin_promotions_path },
data_hook: :admin_promotion_sub_tabs,
children: [
Spree::BackendConfiguration::MenuItem.new(
label: :legacy_promotions,
condition: -> { can?(:admin, Spree::Promotion && Spree::Promotion.any?) },
url: -> { Spree::Core::Engine.routes.url_helpers.admin_promotions_path },
),
Spree::BackendConfiguration::MenuItem.new(
label: :legacy_promotion_categories,
condition: -> { can?(:admin, Spree::PromotionCategory && Spree::Promotion.any?) },
url: -> { Spree::Core::Engine.routes.url_helpers.admin_promotion_categories_path },
)
]
)
]
end
end
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)
end
end
end
Expand Down

0 comments on commit 6e789f8

Please sign in to comment.