Giter Club home page Giter Club logo

spree_shared's Introduction

Spree Shared

Build Status Code Climate

Multiple stores using a single Spree application instance.

Uses request subdomain to swap database, Rails cache (preferences), image paths.


Installation

Add to your Gemfile:

gem 'spree_shared', github: 'spree-contrib/spree_shared', branch: 'master'

Make sure your config/database.yml has valid db connection.

Create an initializer config/initializers/apartment.rb with the following command:

bundle exec rails generate apartment:install

Search for following line:

Apartment.configure do |config|
  ...
  # supply list of database names for migrations to run on
  config.tenant_names = lambda { ToDo_Tenant_Or_User_Model.pluck :database }
end

And change it to include two sample subdomains:

Apartment.configure do |config|
  ...
  config.tenant_names = %w(store1 store2)
end

Add the following line to host application.rb

config.middleware.use 'Apartment::Elevators::Subdomain'

Bootstrap sample stores:

bundle exec rake spree_shared:bootstrap['store1']
bundle exec rake spree_shared:bootstrap['store2']

Setup local subdomains for sample stores, as spree_shared uses by default subdomain routing you need to confirm some local domains such as:

store1.spree.dev
store2.spree.dev

This can be done using Pow or editing your local /etc/hosts file.

Set namespace for cache engine in development.rb and/or production.rb

config.cache_store = :memory_store, { namespace: lambda { Apartment::Tenant.current } }

Setting Store Preferences

If you'd like to set preferences for every store you can do so in your config/initializers/spree.rb initializer by iterating over each store, and then setting it's preference. Since this is multi-tenant with each store having their own database the usual Spree.config block can't be used as it only sets the preference for a single database.

Here is an example:

Apartment.tenant_names.each do |store|
  begin
    Apartment::Tenant.switch! store
    Spree::Config.auto_capture = true
  rescue
    puts "  Failed to set up config for store '#{store}'"
  end
end

Contributing

See corresponding guidelines


Copyright (c) 2013-2015 Spree Commerce Inc, and other contributors, released under the New BSD License

spree_shared's People

Contributors

bdq avatar futhr avatar lbrapid avatar romul avatar jdutil avatar huoxito avatar damianlegawiec avatar patrice avatar pawelnguyen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.