diff --git a/app/controllers/spree/admin/products_controller_decorator.rb b/app/controllers/spree/admin/products_controller_decorator.rb index 5acbc71..17c3b73 100644 --- a/app/controllers/spree/admin/products_controller_decorator.rb +++ b/app/controllers/spree/admin/products_controller_decorator.rb @@ -2,11 +2,11 @@ update.before :set_stores private + def set_stores # Remove all store associations if store data is being passed and no stores are selected if params[:update_store_ids] && !params[:product].key?(:store_ids) @product.stores.clear end end - -end +end if SpreeMultiDomain::Engine.admin_available? diff --git a/app/controllers/spree/api/line_items_controller_decorator.rb b/app/controllers/spree/api/line_items_controller_decorator.rb index de1988d..d333bf8 100644 --- a/app/controllers/spree/api/line_items_controller_decorator.rb +++ b/app/controllers/spree/api/line_items_controller_decorator.rb @@ -1 +1,3 @@ -Spree::Api::LineItemsController.include SpreeMultiDomain::CreateLineItemSupport +if SpreeMultiDomain::Engine.api_available? + Spree::Api::LineItemsController.include(SpreeMultiDomain::CreateLineItemSupport) +end diff --git a/app/controllers/spree/api/products_controller_decorator.rb b/app/controllers/spree/api/products_controller_decorator.rb index 81c1476..20443c6 100644 --- a/app/controllers/spree/api/products_controller_decorator.rb +++ b/app/controllers/spree/api/products_controller_decorator.rb @@ -1 +1,3 @@ -Spree::Api::ProductsController.include(SpreeMultiDomain::ShowProductSupport) +if SpreeMultiDomain::Engine.api_available? + Spree::Api::ProductsController.include(SpreeMultiDomain::ShowProductSupport) +end diff --git a/app/controllers/spree/api/shipments_controller_decorator.rb b/app/controllers/spree/api/shipments_controller_decorator.rb index 3b70f0f..e35ebd5 100644 --- a/app/controllers/spree/api/shipments_controller_decorator.rb +++ b/app/controllers/spree/api/shipments_controller_decorator.rb @@ -13,5 +13,7 @@ def mine_with_store_scope end end -Spree::Api::ShipmentsController.include SpreeMultiStore::Api::ShipmentsControllerDecorator -Spree::Api::ShipmentsController.include SpreeMultiDomain::CreateLineItemSupport +if SpreeMultiDomain::Engine.api_available? + Spree::Api::ShipmentsController.include(SpreeMultiStore::Api::ShipmentsControllerDecorator) + Spree::Api::ShipmentsController.include(SpreeMultiDomain::CreateLineItemSupport) +end diff --git a/app/controllers/spree/home_controller_decorator.rb b/app/controllers/spree/home_controller_decorator.rb index 0dee1c8..c846326 100644 --- a/app/controllers/spree/home_controller_decorator.rb +++ b/app/controllers/spree/home_controller_decorator.rb @@ -4,4 +4,4 @@ def index @products = @searcher.retrieve_products @taxonomies = get_taxonomies end -end \ No newline at end of file +end if SpreeMultiDomain::Engine.frontend_available? diff --git a/app/controllers/spree/products_controller_decorator.rb b/app/controllers/spree/products_controller_decorator.rb index e3b8bda..17c02a5 100644 --- a/app/controllers/spree/products_controller_decorator.rb +++ b/app/controllers/spree/products_controller_decorator.rb @@ -1 +1,3 @@ -Spree::ProductsController.include(SpreeMultiDomain::ShowProductSupport) +if SpreeMultiDomain::Engine.frontend_available? + Spree::ProductsController.include(SpreeMultiDomain::ShowProductSupport) +end diff --git a/app/controllers/spree/taxons_controller_decorator.rb b/app/controllers/spree/taxons_controller_decorator.rb index bcb22ad..c8b3285 100644 --- a/app/controllers/spree/taxons_controller_decorator.rb +++ b/app/controllers/spree/taxons_controller_decorator.rb @@ -7,4 +7,4 @@ def show @products = @searcher.retrieve_products @taxonomies = get_taxonomies end -end \ No newline at end of file +end if SpreeMultiDomain::Engine.frontend_available? diff --git a/lib/spree_multi_domain/engine.rb b/lib/spree_multi_domain/engine.rb index 6e6cc2c..4fd89fc 100644 --- a/lib/spree_multi_domain/engine.rb +++ b/lib/spree_multi_domain/engine.rb @@ -4,15 +4,29 @@ class Engine < Rails::Engine config.autoload_paths += %W(#{config.root}/lib) - def self.activate - ['app', 'lib'].each do |dir| - Dir.glob(File.join(File.dirname(__FILE__), "../../#{dir}/**/*_decorator*.rb")) do |c| - Rails.application.config.cache_classes ? require(c) : load(c) + class << self + def activate + ['app', 'lib'].each do |dir| + Dir.glob(File.join(File.dirname(__FILE__), "../../#{dir}/**/*_decorator*.rb")) do |c| + Rails.application.config.cache_classes ? require(c) : load(c) + end end + + Spree::Config.searcher_class = Spree::Search::MultiDomain + ApplicationController.send :include, SpreeMultiDomain::MultiDomainHelpers + end + + def admin_available? + const_defined?('Spree::Backend::Engine') end - Spree::Config.searcher_class = Spree::Search::MultiDomain - ApplicationController.send :include, SpreeMultiDomain::MultiDomainHelpers + def api_available? + const_defined?('Spree::Api::Engine') + end + + def frontend_available? + const_defined?('Spree::Frontend::Engine') + end end config.to_prepare &method(:activate).to_proc