Skip to content

Commit

Permalink
Merge pull request #5921 from mamhoff/fix-solidus_promotions-menu_item
Browse files Browse the repository at this point in the history
Backend Menu: Fix "Promotions" items
  • Loading branch information
tvdeyen authored Nov 14, 2024
2 parents 8ff6267 + 6a7d839 commit fbef614
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 53 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
promotions: Legacy Promotions
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
3 changes: 2 additions & 1 deletion legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Engine < ::Rails::Engine
),
Spree::BackendConfiguration::MenuItem.new(
label: :promotion_categories,
condition: -> { can?(:admin, Spree::PromotionCategory) }
condition: -> { can?(:admin, Spree::PromotionCategory) },
url: -> { Spree::Core::Engine.routes.url_helpers.admin_promotion_categories_path },
)
]
)
Expand Down
6 changes: 2 additions & 4 deletions promotions/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ en:
spree:
admin:
tab:
promotions: Promotions
promotion_categories: Promotion Categories
legacy_promotions: Legacy Promotions
legacy_promotion_categories: Legacy Promotion Categories
solidus_promotions: Promotions
solidus_promotion_categories: 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: :solidus_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: :solidus_promotions,
url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotions_path },
condition: -> { can?(:admin, SolidusPromotions::Promotion) }
),
Spree::BackendConfiguration::MenuItem.new(
label: :solidus_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 fbef614

Please sign in to comment.