8000 GitHub - dhonig/spree_multi_tenant: Adds multi-tenant support to Spree. Allows completely separate Spree sites with separate admins to be run from the same installation.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adds multi-tenant support to Spree. Allows completely separate Spree sites with separate admins to be run from the same installation.

License

Notifications You must be signed in to change notification settings

dhonig/spree_multi_tenant

 
 

Repository files navigation

SpreeMultiTenant

Adds multi-tenant support to Spree. Allows completely separate Spree sites with separate admins to be run from the same installation.

Install

Gemfile:

gem 'spree', :git => 'git://github.com/spree/spree.git', :branch => '1-1-stable'
gem 'spree_multi_tenant', :git => 'git://github.com/stefansenk/spree_multi_tenant.git'

$ bundle install

Generate and run migrations:

$ rake spree_multi_tenant:install:migrations
$ rake db:migrate

Update the domain for the tenant in the database:

Spree::Tenant.first.update_attribute(:domain, 'shop.dev')

Usage

Create a new tenant:

$ rake spree_multi_tenant:create_tenant domain=mydomain.com code=mydomain

Tenant specific templates:

app/tenants/mydomain/views

With other Spree plugins

Any other models that are tenant specific will need to have the tenant_id field and multitenant scope added.

Database migration:

class AddTenantToSomeModels < ActiveRecord::Migration
  def change
    models = [
      Spree::Page,
      Spree::PaypalAccount,
      Spree::ProductGroup
    ]
    models.each do |model|
      table = model.to_s.tableize.gsub '/', '_'
      add_column table, :tenant_id, :integer
      add_index table, :tenant_id
    end
  end
end

Add scope to the models:

models = [
  Spree::Page,
  Spree::PaypalAccount,
  Spree::ProductGroup
]
models.each do |model|
  model.class_eval do
    belongs_to :tenant
    belongs_to_multitenant
  end
end

In a Raketask

Multitenant.with_tenant(Spree::Tenant.find_by_code('mydomain')) do
  SpreeMultiTenant.init_preferences

  # Do stuff for tenant
  # e.g. Spree::Product.first
end

Testing

$ cd spree_multi_tenant
$ bundle install
$ bundle exec rake test_app
$ bundle exec rspec spec

TODO

  • Allow tenant specific Deface overrides.
  • Allow same user email address to be used on multiple sites.
  • Allow same parmalink to be used on multiple sites.
  • Example CSS and JS files.

Copyright (c) 2012 Stefan Senk, released under the New BSD License

About

Adds multi-tenant support to Spree. Allows completely separate Spree sites with separate admins to be run from the same installation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 99.8%
  • JavaScript 0.2%
0