@@ -62,53 +62,28 @@ class Engine < Rails::Engine
62
62
63
63
initializer "solidus_promotions.add_backend_menus" , after : "spree.backend.environment" do
64
64
if SolidusSupport . backend_available?
65
- # Replace the promotions menu from core with ours
66
- Spree ::Backend ::Config . configure do |config |
67
- config . menu_items = config . menu_items . flat_map do |item |
68
- next item unless item . label . to_sym == :promotions
65
+ promotions_menu_item = Spree ::BackendConfiguration ::MenuItem . new (
66
+ label : :solidus_promotions ,
67
+ icon : Spree ::Backend ::Config . admin_updated_navbar ? "ri-megaphone-line" : "bullhorn" ,
68
+ condition : -> { can? ( :admin , SolidusPromotions ::Promotion ) } ,
69
+ url : -> { SolidusPromotions ::Engine . routes . url_helpers . admin_promotions_path } ,
70
+ data_hook : :admin_solidus_promotion_sub_tabs ,
71
+ children : [
72
+ Spree ::BackendConfiguration ::MenuItem . new (
73
+ label : :solidus_promotions ,
74
+ url : -> { SolidusPromotions ::Engine . routes . url_helpers . admin_promotions_path } ,
75
+ condition : -> { can? ( :admin , SolidusPromotions ::Promotion ) }
76
+ ) ,
77
+ Spree ::BackendConfiguration ::MenuItem . new (
78
+ label : :solidus_promotion_categories ,
79
+ url : -> { SolidusPromotions ::Engine . routes . url_helpers . admin_promotion_categories_path } ,
80
+ condition : -> { can? ( :admin , SolidusPromotions ::PromotionCategory ) }
81
+ )
82
+ ]
83
+ )
69
84
70
- [
71
- Spree ::BackendConfiguration ::MenuItem . new (
72
- label : :promotions ,
73
- icon : config . admin_updated_navbar ? "ri-megaphone-line" : "bullhorn" ,
74
- condition : -> { can? ( :admin , SolidusPromotions ::Promotion ) } ,
75
- url : -> { SolidusPromotions ::Engine . routes . url_helpers . admin_promotions_path } ,
76
- data_hook : :admin_solidus_promotion_sub_tabs ,
77
- children : [
78
- Spree ::BackendConfiguration ::MenuItem . new (
79
- label : :promotions ,
80
- url : -> { SolidusPromotions ::Engine . routes . url_helpers . admin_promotions_path } ,
81
- condition : -> { can? ( :admin , SolidusPromotions ::Promotion ) }
82
- ) ,
83
- Spree ::BackendConfiguration ::MenuItem . new (
84
- label : :promotion_categories ,
85
- url : -> { SolidusPromotions ::Engine . routes . url_helpers . admin_promotion_categories_path } ,
86
- condition : -> { can? ( :admin , SolidusPromotions ::PromotionCategory ) }
87
- )
88
- ]
89
- ) ,
90
- Spree ::BackendConfiguration ::MenuItem . new (
91
- label : :legacy_promotions ,
92
- icon : config . admin_updated_navbar ? "ri-megaphone-line" : "bullhorn" ,
93
- condition : -> { can? ( :admin , SolidusPromotions ::Promotion ) } ,
94
- url : -> { Spree ::Core ::Engine . routes . url_helpers . admin_promotions_path } ,
95
- data_hook : :admin_promotion_sub_tabs ,
96
- children : [
97
- Spree ::BackendConfiguration ::MenuItem . new (
98
- label : :legacy_promotions ,
99
- condition : -> { can? ( :admin , Spree ::Promotion && Spree ::Promotion . any? ) } ,
100
- url : -> { Spree ::Core ::Engine . routes . url_helpers . admin_promotions_path } ,
101
- ) ,
102
- Spree ::BackendConfiguration ::MenuItem . new (
103
- label : :legacy_promotion_categories ,
104
- condition : -> { can? ( :admin , Spree ::PromotionCategory && Spree ::Promotion . any? ) } ,
105
- url : -> { Spree ::Core ::Engine . routes . url_helpers . admin_promotion_categories_path } ,
106
- )
107
- ]
108
- )
109
- ]
110
- end
111
- end
85
+ product_menu_item_index = Spree ::Backend ::Config . menu_items . find_index { |item | item . label == :products }
86
+ Spree ::Backend ::Config . menu_items . insert ( product_menu_item_index + 1 , promotions_menu_item )
112
87
end
113
88
end
114
89
end
0 commit comments