⚠️ Important: This project is under active development. It is valid for insipiration as similar work has been successfully used in production, however this extention has not yet been validated.
This extension provides a way to manage multiple tenants within a single Solidus installation using an active fork of the Apartment gem. Please refer to the gem documentation for more information on setup as this gem enhances the implemntation to get quickly up and running with Solidus.
Solidus works better with Apartment for multi-tenancy as it needs minimal application modifications, however, if you are looking for a row-level multi-tenancy solution with Solidus, please check out my other work with solidus_acts_as_tenant.
Add solidus_multi_tenant to your Gemfile:
gem 'solidus_multi_tenant'
Bundle your dependencies and run the installation generator:
bin/rails generate solidus_multi_tenant:install
config.cache_store = :memory_store, {namespace: -> { Apartment::Tenant.current }}
if defined?(Rails)
TS = SolidusActAsTenant::Utils::TenantSelector.new
IRB.conf[:IRB_RC] = proc do
# * TS.ask => anytime in console, to switch tenant from a list
# * TS.current => same as Apartment::Tenant.current
# * TS.tenants => hash of tenants. Example: { 0 => "Demo Company" }
# * TS.switch_tenant!(tenant_name) => same as Apartment.current = Spree::Tenant.find_by(name: tenant_name)
TS.ask
end
end
TODO: Double check if this is a valid suggestion and if it is, does it work because spree preferences are not namespaced
#initializers/spree.rb
::Apartment::Tenant.each_with_default do |_tenant_name| -
First bundle your dependencies, then run bin/rake
. bin/rake
will default to building the dummy
app if it does not exist, then it will run specs. The dummy app can be regenerated by using
bin/rake extension:test_app
.
bin/rake
To run Rubocop static code analysis run
bundle exec rubocop
When testing your application's integration with this extension you may use its factories. You can load Solidus core factories along with this extension's factories using this statement:
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusMultiTenant::Engine)
To run this extension in a sandboxed Solidus application, you can run bin/sandbox
. The path for
the sandbox app is ./sandbox
and bin/rails
will forward any Rails commands to
sandbox/bin/rails
.
Here's an example:
$ bin/rails server
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop
Please refer to the dedicated page in the Solidus wiki.
Copyright (c) 2025 Ikraam Ghoor, released under the New BSD License.