Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

[Skip CI] Publish multi tenant docs (part 1)

Damian Legawiecccf75dfe306a
diff --git a/docs/developer/multi-tenant/installation.mdx b/docs/developer/multi-tenant/installation.mdx
new file mode 100644
index 0000000000..835568225c
--- /dev/null
+++ b/docs/developer/multi-tenant/installation.mdx
@@ -0,0 +1,115 @@
+---
+title: Spree Multi Tenant Installation
+sidebarTitle: Installation
+description: Learn how to setup a multi-tenant eCommerce (SaaS) with Spree
+---
+
+<Warning>
+ This installation instructions assume you have a clean Spree Starter installation and you've purchased the [Spree Enterprise Edition license](https://spreecommerce.org/pricing).
+
+ For migrating existing application from single-tenant to multi-tenant, please contact us at [[email protected]](mailto:[email protected]).
+</Warning>
+
+## Prerequisites
+
+* You need to be on Spree 5.1+
+* You need to have 2 environment variables set:
+ * `KEYGEN_ACCOUNT_ID`
+ * `KEYGEN_LICENSE_KEY`
+
+<Info>
+ Environment variables will be provided to you after purchasing the [Spree Enterprise Edition license](https://spreecommerce.org/pricing).
+</Info>
+
+## Customer User Class
+
+Please follow [Authentication](/docs/developer/customization/authentication) documentation to create a new user class.
+
+Now we will need to make slight adjustments to the generated user class so it can work in a multi-tenant environment.
+
+If you're using Devise, you will need to remove `:validatable` module. This module is responsible for validating the user's email uniqueness. We need to change it to validate it in the scope of the tenant.
+
+Spree Multi-Tenant gem injects `SpreeMultiTenant::CustomerUserConcern` that handles that instead.
+
+## Admin User Class
+
+For our multi-tenant setup we will need a separate Admin user class. Our standard User class will be only used for customer accounts which will be isolated by tenant.
+Admin user classes will be shared across tenants allowing them to manage multiple tenants from a single admin panel.
+
+Let's create a new model with Devise (unless you already have one):
+
+```bash
+rails g devise Spree::AdminUser
+```
+
+Replace the generated Devise code with the following:
+
+```ruby
+class Spree::AdminUser < Spree::Base
+ # Include default devise modules. Others available are:
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
+ devise :database_authenticatable, :registerable,
+ :recoverable, :rememberable, :validatable
+
+ # Spree modules
+ include Spree::UserMethods
+
+ def login=(login)
+ @email = login
+ end
+
+ def login
+ @email
+ end
+end
+```
+
+If you already have a custom Admin user class, you can add the following code to it:
+
+```ruby
+ # Spree modules
+ include Spree::UserMethods
+
+ def login=(login)
+ @email = login
+ end
+
+ def login
+ @email
+ end
+```
+
+This will make sure that the Admin user class works well with Spree ecosystem.
+
+Register new model in `config/initializers/spree.rb`:
+
+```ruby
+Spree.admin_user_class = "Spree::AdminUser"
+```
+
+## Installing gems
+
+1. Add the following code to your `Gemfile`:
+
+ ```ruby
+ source "https://license:#{ENV['KEYGEN_LICENSE_KEY']}@rubygems.pkg.keygen.sh/#{ENV['KEYGEN_ACCOUNT_ID']}" do
+ gem 'spree_enterprise'
+ gem 'spree_multi_tenant'
+ end
+ ```
+
+2. Install gems:
+
+ ```bash
+ bundle install
+ ```
+
+3. Run generator:
+
+ ```bash
+ bundle exec rails spree_multi_tenant:install
+ ```
+
+ <Info>
+ This will copy and run migrations for `spree_multi_tenant` gem.
+ </Info>
diff --git a/docs/developer/multi-tenant/quickstart.mdx b/docs/developer/multi-tenant/quickstart.mdx
new file mode 100644
index 0000000000..c92b6c213b
--- /dev/null
+++ b/docs/developer/multi-tenant/quickstart.mdx
@@ -0,0 +1,16 @@
+---
+title: Building a Multi-Tenant Spree Application
+sidebarTitle: Quickstart
+---
+
+Spree out of the box is a single-tenant application. You can have multiple stores on the same instance of Spree, but they share the same products, admin user accounts and other resources.
+Multi-Store Spree setup is recommended for running multiple brands or multiple language versions of the same brand on the same instance.
+
+If you want to have a true multi-tenant application, you will need to purchase [Enterprise Edition license](https://spreecommerce.org/pricing) which includes `spree_multi_tenant` gem providing full multi-tenant support.
+
+## Multi-Store vs Multi-Tenant
+
+To sum it up:
+
+* Multi-Store setup is recommended for running multiple brands or multiple language versions of the same store
+* Multi-Tenant allows you to create a SaaS application with multiple tenants, each of them with their own Spree instance
\ No newline at end of file
diff --git a/docs/docs.json b/docs/docs.json
index efd90217f2..f4497085e2 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -84,6 +84,20 @@
"developer/customization/extensions"
]
},
+ {
+ "group": "Use Cases",
+ "icon": "book-open",
+ "pages": [
+ {
+ "group": "Multi-Tenant",
+ "icon": "building",
+ "pages": [
+ "developer/multi-tenant/quickstart",
+ "developer/multi-tenant/installation"
+ ]
+ }
+ ]
+ },
{
"group": "Deployment",
"pages": [