solidus_multi_domain 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.rspec +4 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/README.md +72 -0
- data/Rakefile +21 -0
- data/app/controllers/concerns/spree_multi_domain/create_line_item_support.rb +16 -0
- data/app/controllers/concerns/spree_multi_domain/show_product_support.rb +17 -0
- data/app/controllers/spree/admin/products_controller_decorator.rb +12 -0
- data/app/controllers/spree/admin/stores_controller.rb +24 -0
- data/app/controllers/spree/api/line_items_controller_decorator.rb +1 -0
- data/app/controllers/spree/api/orders_controller_decorator.rb +21 -0
- data/app/controllers/spree/api/products_controller_decorator.rb +1 -0
- data/app/controllers/spree/api/shipments_controller_decorator.rb +17 -0
- data/app/controllers/spree/home_controller_decorator.rb +7 -0
- data/app/controllers/spree/products_controller_decorator.rb +1 -0
- data/app/controllers/spree/taxons_controller_decorator.rb +10 -0
- data/app/helpers/spree/products_helper_decorator.rb +11 -0
- data/app/mailers/spree/carton_mailer_decorator.rb +13 -0
- data/app/mailers/spree/order_mailer.rb +35 -0
- data/app/models/spree/order_decorator.rb +8 -0
- data/app/models/spree/payment_method_decorator.rb +13 -0
- data/app/models/spree/product_decorator.rb +4 -0
- data/app/models/spree/promotion/rules/store.rb +30 -0
- data/app/models/spree/shipping_method_decorator.rb +18 -0
- data/app/models/spree/store_decorator.rb +25 -0
- data/app/models/spree/store_payment_method.rb +6 -0
- data/app/models/spree/store_shipping_method.rb +6 -0
- data/app/models/spree/taxon_decorator.rb +5 -0
- data/app/models/spree/taxonomy_decorator.rb +3 -0
- data/app/models/spree/tracker_decorator.rb +7 -0
- data/app/models/spree_multi_domain/line_item_decorator.rb +20 -0
- data/app/overrides/decorate_admin_configurations_index.rb +5 -0
- data/app/overrides/decorate_admin_products_form.rb +6 -0
- data/app/overrides/decorate_admin_products_index.rb +20 -0
- data/app/overrides/decorate_admin_trackers_form.rb +6 -0
- data/app/overrides/decorate_admin_trackers_index.rb +13 -0
- data/app/views/spree/admin/products/_index_headers.html.erb +1 -0
- data/app/views/spree/admin/products/_index_rows.html.erb +1 -0
- data/app/views/spree/admin/products/_index_search_fields.html.erb +4 -0
- data/app/views/spree/admin/products/_stores.html.erb +8 -0
- data/app/views/spree/admin/promotions/rules/_store.html.erb +8 -0
- data/app/views/spree/admin/stores/_form.html.erb +90 -0
- data/app/views/spree/admin/stores/edit.html.erb +29 -0
- data/app/views/spree/admin/stores/index.html.erb +43 -0
- data/app/views/spree/admin/stores/new.html.erb +29 -0
- data/app/views/spree/admin/taxonomies/_form.html.erb +12 -0
- data/app/views/spree/admin/trackers/_index_rows.html.erb +1 -0
- data/app/views/spree/admin/trackers/_store.html.erb +6 -0
- data/app/views/spree/shared/_google_analytics.html.erb +39 -0
- data/bin/rails +7 -0
- data/circle.yml +6 -0
- data/config/locales/en.yml +26 -0
- data/config/locales/fr.yml +9 -0
- data/config/locales/pl.yml +10 -0
- data/config/locales/ru.yml +9 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20091202123245_add_order_store.rb +17 -0
- data/db/migrate/20100114020535_add_store_to_tracker.rb +25 -0
- data/db/migrate/20100227180338_create_products_stores.rb +13 -0
- data/db/migrate/20100616204303_store_id_for_taxonomies.rb +19 -0
- data/db/migrate/20110601125650_remove_datetime_columns_from_products_stores.rb +13 -0
- data/db/migrate/20110601145424_add_indexes_to_products_stores.rb +11 -0
- data/db/migrate/20120223183401_namespace.rb +9 -0
- data/db/migrate/20121210224018_add_store_payment_methods.rb +10 -0
- data/db/migrate/20130308084714_add_logo_to_stores.rb +13 -0
- data/db/migrate/20130325231147_add_store_shipping_methods.rb +14 -0
- data/db/migrate/20130412212659_add_spree_promotion_rules_stores.rb +8 -0
- data/db/migrate/20150304200122_add_indexes.rb +6 -0
- data/lib/assets/javascripts/spree/backend/solidus_multi_domain.js +1 -0
- data/lib/assets/javascripts/spree/backend/store_picker.js +34 -0
- data/lib/assets/javascripts/spree/frontend/solidus_multi_domain.js +0 -0
- data/lib/assets/stylesheets/spree/frontend/solidus_multi_domain.css +5 -0
- data/lib/generators/spree_multi_domain/install/install_generator.rb +24 -0
- data/lib/solidus_multi_domain.rb +3 -0
- data/lib/spree/controller_helpers/order_decorator.rb +11 -0
- data/lib/spree/search/multi_domain.rb +19 -0
- data/lib/spree_multi_domain/engine.rb +65 -0
- data/lib/spree_multi_domain/multi_domain_helpers.rb +31 -0
- data/solidus_multi_domain.gemspec +31 -0
- data/spec/controllers/spree/admin/products_controller_spec.rb +39 -0
- data/spec/controllers/spree/admin/stores_controller_spec.rb +12 -0
- data/spec/controllers/spree/api/line_items_controller_spec.rb +35 -0
- data/spec/controllers/spree/api/orders_controller_spec.rb +44 -0
- data/spec/controllers/spree/api/products_controller_spec.rb +52 -0
- data/spec/controllers/spree/api/shipments_controller_spec.rb +63 -0
- data/spec/controllers/spree/products_controller_spec.rb +49 -0
- data/spec/helpers/products_helper_decorator_spec.rb +22 -0
- data/spec/mailers/carton_mailer_spec.rb +41 -0
- data/spec/models/spree/line_item_spec.rb +39 -0
- data/spec/models/spree/order_spec.rb +18 -0
- data/spec/models/spree/payment_method_spec.rb +33 -0
- data/spec/models/spree/product_spec.rb +18 -0
- data/spec/models/spree/shipping_method_decorator_spec.rb +27 -0
- data/spec/models/spree/store_spec.rb +42 -0
- data/spec/models/spree/taxon_decorator_spec.rb +30 -0
- data/spec/models/spree/tracker_spec.rb +19 -0
- data/spec/requests/global_controller_helpers_spec.rb +65 -0
- data/spec/requests/template_renderer_spec.rb +25 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/factory_overrides.rb +10 -0
- metadata +278 -0
data/circle.yml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
en:
|
|
2
|
+
spree:
|
|
3
|
+
back_to_store_list: Back To Store List
|
|
4
|
+
default_currency: Default Currency
|
|
5
|
+
errors:
|
|
6
|
+
products_from_different_stores_may_not_be_added_to_this_order: Products from different stores may not be added to this order.
|
|
7
|
+
send_mail_as: Send Mail As
|
|
8
|
+
logo: Logo
|
|
9
|
+
payment_method: Payment Method
|
|
10
|
+
shipping_method: Shipping Method
|
|
11
|
+
store: Store
|
|
12
|
+
stores: Stores
|
|
13
|
+
new_store: New Store
|
|
14
|
+
domains: Domains
|
|
15
|
+
stores_admin: "Stores & Domains"
|
|
16
|
+
manage_stores: Configure multiple stores and associated domain names
|
|
17
|
+
editing_store: Editing Store
|
|
18
|
+
default: Default
|
|
19
|
+
store_name: Name
|
|
20
|
+
store_code: Code
|
|
21
|
+
promotion_rule_types:
|
|
22
|
+
store:
|
|
23
|
+
name: Store
|
|
24
|
+
description: "Store must match one from the list"
|
|
25
|
+
store_rule:
|
|
26
|
+
choose_stores: "Choose Stores"
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class AddOrderStore < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
if table_exists?('orders')
|
|
4
|
+
add_column :orders, :store_id, :integer
|
|
5
|
+
elsif table_exists?('spree_orders')
|
|
6
|
+
add_column :spree_orders, :store_id, :integer unless column_exists?(:spree_orders, :store_id)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.down
|
|
11
|
+
if table_exists?('orders')
|
|
12
|
+
remove_column :orders, :store_id
|
|
13
|
+
elsif table_exists?('spree_orders')
|
|
14
|
+
remove_column :spree_orders, :store_id
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class AddStoreToTracker < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
if table_exists?('trackers')
|
|
4
|
+
change_table :trackers do |t|
|
|
5
|
+
t.references :store
|
|
6
|
+
end
|
|
7
|
+
elsif table_exists?('spree_trackers')
|
|
8
|
+
change_table :spree_trackers do |t|
|
|
9
|
+
t.references :store
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.down
|
|
15
|
+
if table_exists?('trackers')
|
|
16
|
+
change_table :trackers do |t|
|
|
17
|
+
t.remove :store_id
|
|
18
|
+
end
|
|
19
|
+
elsif table_exists?('spree_trackers')
|
|
20
|
+
change_table :spree_trackers do |t|
|
|
21
|
+
t.remove :store_id
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class CreateProductsStores < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :products_stores, :id => false do |t|
|
|
4
|
+
t.references :product
|
|
5
|
+
t.references :store
|
|
6
|
+
t.timestamps
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.down
|
|
11
|
+
drop_table :products_stores
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class StoreIdForTaxonomies < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
if table_exists?('taxonomies')
|
|
4
|
+
add_column :taxonomies, :store_id, :integer
|
|
5
|
+
add_index :taxonomies, :store_id
|
|
6
|
+
elsif table_exists?('spree_taxonomies')
|
|
7
|
+
add_column :spree_taxonomies, :store_id, :integer
|
|
8
|
+
add_index :spree_taxonomies, :store_id
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.down
|
|
13
|
+
if table_exists?('taxonomies')
|
|
14
|
+
remove_column :taxonomies, :store_id
|
|
15
|
+
elsif table_exists?('spree_taxonomies')
|
|
16
|
+
remove_column :spree_taxonomies, :store_id
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class RemoveDatetimeColumnsFromProductsStores < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
change_table :products_stores do |t|
|
|
4
|
+
t.remove :created_at, :updated_at
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.down
|
|
9
|
+
change_table :products_stores do |t|
|
|
10
|
+
t.timestamps
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class AddIndexesToProductsStores < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
add_index :products_stores, :product_id
|
|
4
|
+
add_index :products_stores, :store_id
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.down
|
|
8
|
+
remove_index :products_stores, :product_id
|
|
9
|
+
remove_index :products_stores, :store_id
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class AddStoreShippingMethods < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :spree_store_shipping_methods do |t|
|
|
4
|
+
t.integer :store_id
|
|
5
|
+
t.integer :shipping_method_id
|
|
6
|
+
|
|
7
|
+
t.timestamps
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
add_index :spree_store_shipping_methods, :store_id
|
|
11
|
+
add_index :spree_store_shipping_methods, :shipping_method_id
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//= require_tree .
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
$.fn.storeAutocomplete = function() {
|
|
2
|
+
this.select2({
|
|
3
|
+
minimumInputLength: 1,
|
|
4
|
+
multiple: true,
|
|
5
|
+
initSelection: function(element, callback) {
|
|
6
|
+
$.get(Spree.routes.store_search, { ids: element.val() }, function(data) {
|
|
7
|
+
callback(data.stores)
|
|
8
|
+
})
|
|
9
|
+
},
|
|
10
|
+
ajax: {
|
|
11
|
+
url: Spree.routes.store_search,
|
|
12
|
+
datatype: 'json',
|
|
13
|
+
data: function(term, page) {
|
|
14
|
+
return { q: term }
|
|
15
|
+
},
|
|
16
|
+
results: function(data, page) {
|
|
17
|
+
return { results: data.stores }
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
formatResult: function(store) {
|
|
21
|
+
return store.name;
|
|
22
|
+
},
|
|
23
|
+
formatSelection: function(store) {
|
|
24
|
+
return store.name;
|
|
25
|
+
},
|
|
26
|
+
id: function(store) {
|
|
27
|
+
return store.id
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
$(document).ready(function () {
|
|
33
|
+
$('.store_picker').storeAutocomplete();
|
|
34
|
+
})
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module SpreeMultiDomain
|
|
2
|
+
module Generators
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
|
5
|
+
|
|
6
|
+
def add_javascripts
|
|
7
|
+
append_file "vendor/assets/javascripts/spree/backend/all.js", "//= require spree/backend/solidus_multi_domain\n"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def add_migrations
|
|
11
|
+
run 'rake railties:install:migrations FROM=solidus_multi_domain'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def run_migrations
|
|
15
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
|
16
|
+
if run_migrations
|
|
17
|
+
run 'bundle exec rake db:migrate'
|
|
18
|
+
else
|
|
19
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Spree::Core::ControllerHelpers::Order.class_eval do
|
|
2
|
+
def current_currency
|
|
3
|
+
# When using spree_multi_currency the current_currency is stored within session[:currency]
|
|
4
|
+
currency = session[:currency] if session.key?(:currency) && supported_currencies.map(&:iso_code).include?(session[:currency])
|
|
5
|
+
# If there is no session currency fall back to the store default
|
|
6
|
+
currency ||= current_store.try(:default_currency)
|
|
7
|
+
# If there is still no currency fall back to Spree default
|
|
8
|
+
currency = Spree::Config[:currency] if currency.blank?
|
|
9
|
+
currency
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Spree::Search
|
|
2
|
+
class MultiDomain < Spree::Core::Search::Base
|
|
3
|
+
def get_base_scope
|
|
4
|
+
base_scope = @cached_product_group ? @cached_product_group.products.active : Spree::Product.active
|
|
5
|
+
base_scope = base_scope.by_store(current_store_id) if current_store_id
|
|
6
|
+
base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
|
|
7
|
+
|
|
8
|
+
base_scope = get_products_conditions_for(base_scope, keywords) unless keywords.blank?
|
|
9
|
+
|
|
10
|
+
base_scope = add_search_scopes(base_scope)
|
|
11
|
+
base_scope
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def prepare(params)
|
|
15
|
+
super
|
|
16
|
+
@properties[:current_store_id] = params[:current_store_id]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module SpreeMultiDomain
|
|
2
|
+
class Engine < Rails::Engine
|
|
3
|
+
engine_name 'solidus_multi_domain'
|
|
4
|
+
|
|
5
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
|
6
|
+
|
|
7
|
+
def self.activate
|
|
8
|
+
['app', 'lib'].each do |dir|
|
|
9
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../../#{dir}/**/*_decorator*.rb")) do |c|
|
|
10
|
+
Rails.application.config.cache_classes ? require(c) : load(c)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Spree::Config.searcher_class = Spree::Search::MultiDomain
|
|
15
|
+
ApplicationController.send :include, SpreeMultiDomain::MultiDomainHelpers
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
config.to_prepare &method(:activate).to_proc
|
|
19
|
+
|
|
20
|
+
initializer "templates with dynamic layouts" do |app|
|
|
21
|
+
ActionView::TemplateRenderer.class_eval do
|
|
22
|
+
def find_layout_with_multi_store(layout, locals)
|
|
23
|
+
if @view.respond_to?(:current_store) && @view.current_store && !@view.controller.is_a?(Spree::Admin::BaseController) && layout.call.present?
|
|
24
|
+
store_layout = if layout.is_a?(String)
|
|
25
|
+
layout.gsub("layouts/", "layouts/#{@view.current_store.code}/")
|
|
26
|
+
else
|
|
27
|
+
layout.call.try(:gsub, "layouts/", "layouts/#{@view.current_store.code}/")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
find_layout_without_multi_store(store_layout, locals)
|
|
32
|
+
rescue ::ActionView::MissingTemplate
|
|
33
|
+
find_layout_without_multi_store(layout, locals)
|
|
34
|
+
end
|
|
35
|
+
else
|
|
36
|
+
find_layout_without_multi_store(layout, locals)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
alias_method_chain :find_layout, :multi_store
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
initializer "current order decoration" do |app|
|
|
45
|
+
require 'spree/core/controller_helpers/order'
|
|
46
|
+
::Spree::Core::ControllerHelpers::Order.module_eval do
|
|
47
|
+
def current_order_with_multi_domain(options = {})
|
|
48
|
+
options[:create_order_if_necessary] ||= false
|
|
49
|
+
current_order_without_multi_domain(options)
|
|
50
|
+
|
|
51
|
+
if @current_order and current_store and @current_order.store.blank?
|
|
52
|
+
@current_order.update_attribute(:store_id, current_store.id)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
@current_order
|
|
56
|
+
end
|
|
57
|
+
alias_method_chain :current_order, :multi_domain
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
initializer 'spree.promo.register.promotions.rules' do |app|
|
|
62
|
+
app.config.spree.promotions.rules << Spree::Promotion::Rules::Store
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module SpreeMultiDomain
|
|
2
|
+
module MultiDomainHelpers
|
|
3
|
+
def self.included(receiver)
|
|
4
|
+
receiver.send :helper, 'spree/products'
|
|
5
|
+
receiver.send :helper, 'spree/taxons'
|
|
6
|
+
|
|
7
|
+
receiver.send :before_filter, :add_current_store_id_to_params
|
|
8
|
+
receiver.send :helper_method, :current_store
|
|
9
|
+
receiver.send :helper_method, :current_tracker
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def current_tracker
|
|
13
|
+
@current_tracker ||= Spree::Tracker.current(store_key)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get_taxonomies
|
|
17
|
+
@taxonomies ||= current_store.present? ? Spree::Taxonomy.where(["store_id = ?", current_store.id]) : Spree::Taxonomy
|
|
18
|
+
@taxonomies = @taxonomies.includes(:root => :children)
|
|
19
|
+
@taxonomies
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add_current_store_id_to_params
|
|
23
|
+
params[:current_store_id] = current_store.try(:id)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
def store_key
|
|
28
|
+
request.headers['HTTP_SPREE_STORE'] || request.env['SERVER_NAME']
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|