Skip to content

Commit

Permalink
Merge pull request solidusio#5730 from mamhoff/move-backend-controlle…
Browse files Browse the repository at this point in the history
…rs-to-lib

Move promotion backend controllers to `lib/
  • Loading branch information
kennyadsl authored May 6, 2024
2 parents 4f9c427 + f3b621b commit 1fdedd4
Show file tree
Hide file tree
Showing 59 changed files with 47 additions and 37 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ end
group :legacy_promotions do
gem 'solidus_legacy_promotions', path: 'legacy_promotions', require: false
gem 'solidus_admin', path: 'admin', require: false
gem 'solidus_backend', path: 'backend', require: false
gem 'axe-core-rspec', '~> 4.8', require: false
gem 'axe-core-capybara', '~> 4.8', require: false
end
Expand Down
22 changes: 12 additions & 10 deletions legacy_promotions/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# frozen_string_literal: true

Spree::Core::Engine.routes.draw do
namespace :admin do
resources :promotions do
resources :promotion_rules
resources :promotion_actions
resources :promotion_codes, only: [:index, :new, :create]
resources :promotion_code_batches, only: [:index, :new, :create] do
get '/download', to: "promotion_code_batches#download", defaults: { format: "csv" }
if SolidusSupport.backend_available?
Spree::Core::Engine.routes.draw do
namespace :admin do
resources :promotions do
resources :promotion_rules
resources :promotion_actions
resources :promotion_codes, only: [:index, :new, :create]
resources :promotion_code_batches, only: [:index, :new, :create] do
get '/download', to: "promotion_code_batches#download", defaults: { format: "csv" }
end
end
end

resources :promotion_categories, except: [:show]
resources :promotion_categories, except: [:show]
end
end
end

Expand Down
15 changes: 11 additions & 4 deletions legacy_promotions/lib/solidus_legacy_promotions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

require "solidus_core"
require "solidus_api"
require "solidus_backend"
require "solidus_support"

# If `solidus_admin` is available, it needs to load before
# our engine is initialized, so that our load paths can
# be initialized.
# We carry controllers and views for both the traditional backend
# and the new Solidus Admin interface, but we want to continue to function
# if either of them are not present. If they are present,
# however, they need to load before us.
begin
require 'solidus_admin'
rescue LoadError
# Solidus Admin is not available
end

begin
require "solidus_backend"
rescue LoadError
# Solidus backend is not available
end

module SolidusLegacyPromotions
VERSION = Spree.solidus_version
end
Expand Down
45 changes: 23 additions & 22 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@
module SolidusLegacyPromotions
class Engine < ::Rails::Engine
include SolidusSupport::EngineExtensions
MenuItem = Spree::BackendConfiguration::MenuItem

initializer "solidus_legacy_promotions.add_menu_item" do
promotions_menu_item = MenuItem.new(
label: :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: [
MenuItem.new(
label: :promotions,
condition: -> { can?(:admin, Spree::Promotion) }
),
MenuItem.new(
label: :promotion_categories,
condition: -> { can?(:admin, Spree::PromotionCategory) }
)
]
)
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)
initializer "solidus_legacy_promotions.add_backend_menu_item" do
if SolidusSupport.backend_available?
promotions_menu_item = Spree::BackendConfiguration::MenuItem.new(
label: :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,
condition: -> { can?(:admin, Spree::Promotion) }
),
Spree::BackendConfiguration::MenuItem.new(
label: :promotion_categories,
condition: -> { can?(:admin, Spree::PromotionCategory) }
)
]
)
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

initializer "solidus_legacy_promotions.add_solidus_admin_menu_items" do
Expand Down
1 change: 0 additions & 1 deletion legacy_promotions/solidus_legacy_promotions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ Gem::Specification.new do |s|

s.add_dependency 'solidus_core', s.version
s.add_dependency 'solidus_api', s.version
s.add_dependency 'solidus_backend', s.version
s.add_dependency 'solidus_support'
end

0 comments on commit 1fdedd4

Please sign in to comment.