Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4.4] Backend Menu: Fix "Promotions" items #5924

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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