Permalink
Browse files

Spree 1-0 initial

  • Loading branch information...
1 parent bc10a3f commit 1071e9841afb8a261935ac83b41401e7ae2da3df Denis 'jumph4x committed with jumph4x Feb 23, 2012
Showing with 819 additions and 288 deletions.
  1. +1 −17 .gitignore
  2. +4 −0 .rspec
  3. +13 −0 Gemfile
  4. +243 −0 Gemfile.lock
  5. +18 −4 Rakefile
  6. +5 −4 Versionfile
  7. +0 −8 app/controllers/admin/stores_controller.rb
  8. +0 −12 app/controllers/products_controller_decorator.rb
  9. +1 −5 app/controllers/{ → spree}/admin/products_controller_decorator.rb
  10. +3 −0 app/controllers/spree/admin/stores_controller.rb
  11. +12 −0 app/controllers/spree/products_controller_decorator.rb
  12. +1 −1 app/mailers/{ → spree}/order_mailer.rb
  13. +1 −1 app/mailers/{ → spree}/shipment_mailer.rb
  14. +0 −22 app/models/models_decorator.rb
  15. +4 −0 app/models/spree/order_decorator.rb
  16. +4 −0 app/models/spree/product_decorator.rb
  17. +21 −0 app/models/spree/store.rb
  18. +3 −0 app/models/spree/taxonomy_decorator.rb
  19. +7 −0 app/models/spree/tracker_decorator.rb
  20. +0 −15 app/models/store.rb
  21. +6 −0 app/overrides/decorate_admin_configurations_index.rb
  22. +6 −0 app/overrides/decorate_admin_products_form.rb
  23. +20 −0 app/overrides/decorate_admin_products_index.rb
  24. +6 −0 app/overrides/decorate_admin_trackers_form.rb
  25. +13 −0 app/overrides/decorate_admin_trackers_index.rb
  26. +0 −4 app/views/admin/products/_index_search_fields.html.erb
  27. 0 app/views/{ → spree}/admin/products/_index_headers.html.erb
  28. 0 app/views/{ → spree}/admin/products/_index_rows.html.erb
  29. +4 −0 app/views/spree/admin/products/_index_search_fields.html.erb
  30. 0 app/views/{ → spree}/admin/products/_stores.html.erb
  31. 0 app/views/{ → spree}/admin/stores/_form.html.erb
  32. +1 −1 app/views/{ → spree}/admin/stores/edit.html.erb
  33. +1 −1 app/views/{ → spree}/admin/stores/index.html.erb
  34. +1 −1 app/views/{ → spree}/admin/stores/new.html.erb
  35. 0 app/views/{ → spree}/admin/taxonomies/_form.html.erb
  36. 0 app/views/{ → spree}/admin/trackers/_index_rows.html.erb
  37. 0 app/views/{ → spree}/admin/trackers/_store.html.erb
  38. 0 app/views/{ → spree}/shared/_google_analytics.html.erb
  39. +1 −3 config/routes.rb
  40. +11 −3 db/migrate/20091202123245_add_order_store.rb
  41. +19 −7 db/migrate/20100114020535_add_store_to_tracker.rb
  42. +1 −1 db/migrate/20100227175140_add_default_store.rb
  43. +13 −4 db/migrate/20100616204303_store_id_for_taxonomies.rb
  44. +12 −0 db/migrate/20120223183401_namespace.rb
  45. +27 −0 lib/generators/spree_multi_domain/install/install_generator.rb
  46. +2 −2 lib/spree/search/multi_domain.rb
  47. +1 −115 lib/spree_multi_domain.rb
  48. +90 −0 lib/spree_multi_domain/engine.rb
  49. +0 −55 lib/spree_multi_domain_hooks.rb
  50. +2 −0 lib/tasks/multi_domain_extension_tasks.rake
  51. +5 −0 script/rails
  52. +44 −0 spec/controllers/spree/admin/products_controller_spec.rb
  53. +14 −0 spec/controllers/spree/admin/stores_controller_spec.rb
  54. +36 −0 spec/controllers/spree/products_controller_spec.rb
  55. +5 −0 spec/factories.rb
  56. +18 −0 spec/models/spree/order_spec.rb
  57. +18 −0 spec/models/spree/product_spec.rb
  58. +17 −0 spec/models/spree/store_spec.rb
  59. +15 −0 spec/models/spree/tracker_spec.rb
  60. +27 −0 spec/requests/global_controller_helpers.rb
  61. +33 −0 spec/spec_helper.rb
  62. +9 −2 spree_multi_domain.gemspec
View
18 .gitignore
@@ -8,38 +8,22 @@
.loadpath
.project
*.swp
-public/dispatch.cgi
-public/dispatch.fcgi
-public/dispatch.rb
-httpd
-pgsql
+spec/dummy
config/*-public.asc
config/database.yml
config/mongrel_cluster.yml
db/*.sql
db/*.sqlite3*
db/schema.rb
doc/**/*
-lib/products_index_profiler.rb
log/*.log
-pkg
public/assets
-public/attachments
-public/blank_iframe.html
public/images
public/javascripts
public/stylesheets
-public/ckeditora
-spree.gemspec
-spree_dev
-spree_test
tmp
vendor/rails
vendor/extensions/google_base
public/google_base.xml
public/template_google_base.xml
coverage/*
-var
-TAGS
-nbproject
-vendor/extensions/theme_default/app/stylesheets/*.css
View
4 .rspec
@@ -0,0 +1,4 @@
+--color
+--format
+progress
+--backtrace
View
13 Gemfile
@@ -0,0 +1,13 @@
+source 'http://rubygems.org'
+
+gem 'rails'
+
+if RUBY_VERSION < "1.9"
+ gem "ruby-debug"
+else
+ gem "ruby-debug19"
+end
+
+gemspec
+gem 'spree'
+gem 'ffaker'
View
243 Gemfile.lock
@@ -0,0 +1,243 @@
+PATH
+ remote: .
+ specs:
+ spree_multi_domain (1.3.05)
+ spree_core (~> 1.0.3)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.4)
+ actionpack (= 3.1.4)
+ mail (~> 2.3.0)
+ actionpack (3.1.4)
+ activemodel (= 3.1.4)
+ activesupport (= 3.1.4)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.6)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.3)
+ active_utils (1.0.3)
+ activesupport (>= 2.3.11)
+ i18n
+ activemerchant (1.20.1)
+ active_utils (>= 1.0.1)
+ activesupport (>= 2.3.11)
+ braintree (>= 2.0.0)
+ builder (>= 2.0.0)
+ i18n
+ json (>= 1.5.1)
+ money (<= 3.7.1)
+ activemodel (3.1.4)
+ activesupport (= 3.1.4)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.4)
+ activemodel (= 3.1.4)
+ activesupport (= 3.1.4)
+ arel (~> 2.2.3)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.4)
+ activemodel (= 3.1.4)
+ activesupport (= 3.1.4)
+ activesupport (3.1.4)
+ multi_json (~> 1.0)
+ acts_as_list (0.1.4)
+ archive-tar-minitar (0.5.2)
+ arel (2.2.3)
+ bcrypt-ruby (3.0.1)
+ braintree (2.14.0)
+ builder (>= 2.0.0)
+ builder (3.0.0)
+ cancan (1.6.7)
+ capybara (1.0.1)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
+ cocaine (0.2.1)
+ columnize (0.3.6)
+ deface (0.8.0)
+ nokogiri (~> 1.5.0)
+ rails (>= 3.0.9)
+ devise (1.4.8)
+ bcrypt-ruby (~> 3.0)
+ orm_adapter (~> 0.0.3)
+ warden (~> 1.0.3)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ factory_girl (2.6.4)
+ activesupport (>= 2.3.9)
+ ffaker (1.12.1)
+ ffi (1.0.11)
+ highline (1.6.8)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.19)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.5)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ railties (>= 3.0.0)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
+ mail (2.3.3)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ meta_search (1.1.1)
+ actionpack (~> 3.1.0)
+ activerecord (~> 3.1.0)
+ activesupport (~> 3.1.0)
+ polyamorous (~> 0.5.0)
+ mime-types (1.18)
+ money (3.7.1)
+ i18n (~> 0.4)
+ multi_json (1.1.0)
+ nested_set (1.6.8)
+ activerecord (>= 3.0.0)
+ railties (>= 3.0.0)
+ nokogiri (1.5.2)
+ orm_adapter (0.0.6)
+ paperclip (2.5.0)
+ activerecord (>= 2.3.0)
+ activesupport (>= 2.3.2)
+ cocaine (>= 0.0.2)
+ mime-types
+ polyamorous (0.5.0)
+ activerecord (~> 3.0)
+ polyglot (0.3.3)
+ rack (1.3.6)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.4)
+ actionmailer (= 3.1.4)
+ actionpack (= 3.1.4)
+ activerecord (= 3.1.4)
+ activeresource (= 3.1.4)
+ activesupport (= 3.1.4)
+ bundler (~> 1.0)
+ railties (= 3.1.4)
+ railties (3.1.4)
+ actionpack (= 3.1.4)
+ activesupport (= 3.1.4)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.0)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ rspec-rails (2.9.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.9.0)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
+ rubyzip (0.9.6.1)
+ selenium-webdriver (2.20.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ multi_json (~> 1.0)
+ rubyzip
+ spree (1.0.3)
+ spree_api (= 1.0.3)
+ spree_auth (= 1.0.3)
+ spree_cmd (= 1.0.3)
+ spree_core (= 1.0.3)
+ spree_dash (= 1.0.3)
+ spree_promo (= 1.0.3)
+ spree_sample (= 1.0.3)
+ spree_api (1.0.3)
+ spree_auth (= 1.0.3)
+ spree_core (= 1.0.3)
+ spree_auth (1.0.3)
+ cancan (= 1.6.7)
+ devise (= 1.4.8)
+ spree_core (= 1.0.3)
+ spree_cmd (1.0.3)
+ spree_core (1.0.3)
+ activemerchant (= 1.20.1)
+ acts_as_list (= 0.1.4)
+ deface (>= 0.7.2)
+ ffaker (~> 1.12.0)
+ highline (= 1.6.8)
+ jquery-rails (>= 1.0.18, <= 1.0.19)
+ kaminari (>= 0.13.0)
+ meta_search (= 1.1.1)
+ nested_set (= 1.6.8)
+ paperclip (= 2.5.0)
+ rails (>= 3.1.1, <= 3.1.4)
+ state_machine (= 1.1.1)
+ stringex (~> 1.3.0)
+ spree_dash (1.0.3)
+ spree_core (= 1.0.3)
+ spree_promo (1.0.3)
+ spree_auth (= 1.0.3)
+ spree_core (= 1.0.3)
+ spree_sample (1.0.3)
+ spree_core (= 1.0.3)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
+ state_machine (1.1.1)
+ stringex (1.3.2)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.32)
+ warden (1.0.6)
+ rack (>= 1.0)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara (= 1.0.1)
+ factory_girl
+ ffaker
+ rails
+ rspec-rails (~> 2.7)
+ ruby-debug19
+ spree
+ spree_multi_domain!
+ sqlite3
View
22 Rakefile
@@ -1,12 +1,20 @@
-require 'rubygems'
+# encoding: utf-8
+ENV['LIB_NAME'] = 'spree_multi_domain'
+
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
-require 'rake/gempackagetask'
+require 'rubygems/package_task'
+require 'rspec/core/rake_task'
+require 'spree/core/testing_support/common_rake'
+
+RSpec::Core::RakeTask.new
+
+task :default => [:spec]
spec = eval(File.read('spree_multi_domain.gemspec'))
-Rake::GemPackageTask.new(spec) do |p|
+Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
@@ -15,4 +23,10 @@ task :release => :package do
require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
-end
+end
+
+desc "Generates a dummy app for testing"
+task :test_app do
+ ENV['LIB_NAME'] = 'spree_multi_domain'
+ Rake::Task['common:test_app'].invoke
+end
View
9 Versionfile
@@ -1,5 +1,6 @@
-"0.30.x" => { :branch => "0-30-x" }
-"0.40.x" => { :branch => "0-40-stable" }
-"0.50.x" => { :branch => "0-40-stable" }
+"1.0.x" => { :branch => "master"}
+"0.70.x" => { :branch => "0-60-stable" }
"0.60.x" => { :branch => "0-60-stable" }
-"0.70.x" => { :branch => "master" }
+"0.50.x" => { :branch => "0-40-stable" }
+"0.40.x" => { :branch => "0-40-stable" }
+"0.30.x" => { :branch => "0-30-x" }
View
8 app/controllers/admin/stores_controller.rb
@@ -1,8 +0,0 @@
-class Admin::StoresController < Admin::BaseController
- resource_controller
- ssl_required
-
- update.wants.html { redirect_to collection_url }
- create.wants.html { redirect_to collection_url }
- destroy.success.wants.js { render_js_for_destroy }
-end
View
12 app/controllers/products_controller_decorator.rb
@@ -1,12 +0,0 @@
-ProductsController.class_eval do
- before_filter :can_show_product, :only => :show
-
- private
- def can_show_product
- @product ||= Product.find_by_permalink!(params[:id])
- if @product.stores.empty? || @product.stores.include?(@site)
- render :file => "public/404.html", :status => 404
- end
- end
-
-end
View
6 ...rs/admin/products_controller_decorator.rb → ...ee/admin/products_controller_decorator.rb
@@ -1,13 +1,9 @@
-Admin::ProductsController.class_eval do
+Spree::Admin::ProductsController.class_eval do
update.before :set_stores
- create.before :add_to_all_stores
-
private
def set_stores
@product.store_ids = nil unless params[:product].key? :store_ids
end
- def add_to_all_stores
- end
end
View
3 app/controllers/spree/admin/stores_controller.rb
@@ -0,0 +1,3 @@
+class Spree::Admin::StoresController < Spree::Admin::ResourceController
+
+end
View
12 app/controllers/spree/products_controller_decorator.rb
@@ -0,0 +1,12 @@
+Spree::ProductsController.class_eval do
+ before_filter :can_show_product, :only => :show
+
+ private
+ def can_show_product
+ @product ||= Spree::Product.find_by_permalink!(params[:id])
+ if @product.stores.empty? || @product.stores.include?(@site)
+ render :file => "#{::Rails.root}/public/404.html", :status => 404
+ end
+ end
+
+end
View
2 app/mailers/order_mailer.rb → app/mailers/spree/order_mailer.rb
@@ -1,4 +1,4 @@
-class OrderMailer < ActionMailer::Base
+class Spree::OrderMailer < ActionMailer::Base
helper "spree/base"
def confirm_email(order, resend=false)
View
2 app/mailers/shipment_mailer.rb → app/mailers/spree/shipment_mailer.rb
@@ -1,4 +1,4 @@
-class ShipmentMailer < ActionMailer::Base
+class Spree::ShipmentMailer < ActionMailer::Base
helper "spree/base"
def shipped_email(shipment, resend=false)
View
22 app/models/models_decorator.rb
@@ -1,22 +0,0 @@
-Product.class_eval do
- has_and_belongs_to_many :stores
- scope :by_store, lambda {|store| joins(:stores).where("products_stores.store_id = ?", store)}
-end
-
-Order.class_eval do
- belongs_to :store
- scope :by_store, lambda { |store| where(:store_id => store.id) }
-end
-
-Taxonomy.class_eval do
- belongs_to :store
-end
-
-Tracker.class_eval do
- belongs_to :store
-
- def self.current(domain)
- trackers = Tracker.find(:all, :conditions => {:active => true, :environment => ENV['RAILS_ENV']})
- trackers.select { |t| t.store_id == Store.current(domain).try(:id) }.first
- end
-end
View
4 app/models/spree/order_decorator.rb
@@ -0,0 +1,4 @@
+Spree::Order.class_eval do
+ belongs_to :store
+ scope :by_store, lambda { |store| where(:store_id => store.id) }
+end
View
4 app/models/spree/product_decorator.rb
@@ -0,0 +1,4 @@
+Spree::Product.class_eval do
+ has_and_belongs_to_many :stores, :join_table => 'spree_products_stores'
+ scope :by_store, lambda {|store| joins(:stores).where("spree_products_stores.store_id = ?", store)}
+end
View
21 app/models/spree/store.rb
@@ -0,0 +1,21 @@
+module Spree
+ class Store < ActiveRecord::Base
+ has_and_belongs_to_many :products
+ has_many :taxonomies
+ has_many :orders
+
+ validates_presence_of :name, :code, :domains
+
+ scope :default, where(:default => true)
+ scope :by_domain, lambda { |domain| where("domains like ?", "%#{domain}%") }
+
+ def self.current(domain = nil)
+ current_store = domain ? Store.by_domain(domain).first : nil
+ current_store || first_found_default
+ end
+
+ def self.first_found_default
+ @cached_default ||= Store.default.first
+ end
+ end
+end
View
3 app/models/spree/taxonomy_decorator.rb
@@ -0,0 +1,3 @@
+Spree::Taxonomy.class_eval do
+ belongs_to :store
+end
View
7 app/models/spree/tracker_decorator.rb
@@ -0,0 +1,7 @@
+Spree::Tracker.class_eval do
+ belongs_to :store
+
+ def self.current(domain)
+ Spree::Tracker.where(:active => true, :environment => ENV['RAILS_ENV']).joins(:store).where("spree_stores.domains LIKE '%#{domain}%'").first
@ka8725
ka8725 Mar 27, 2013

Potential SQL injection: domain variable. It needs to be rewritten like this I think:

.where(["spree_stores.domains LIKE '%?%'", domain)
@JDutil
JDutil Mar 27, 2013

Thanks for pointing this out. I've pushed a fix to all 1-x-stable branches and master.

+ end
+end
View
15 app/models/store.rb
@@ -1,15 +0,0 @@
-class Store < ActiveRecord::Base
- has_and_belongs_to_many :products
- has_many :taxonomies
- has_many :orders
-
- validates_presence_of :name, :code, :domains
-
- scope :default, where(:default => true)
- scope :by_domain, lambda { |domain| where("domains like ?", "%#{domain}%") }
-
- def self.current(domain = nil)
- current_store = domain ? Store.by_domain(domain).first : nil
- current_store || Store.default.first
- end
-end
View
6 app/overrides/decorate_admin_configurations_index.rb
@@ -0,0 +1,6 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/configurations/index",
+ :name => "multi_domain_admin_configurations_menu",
+ :insert_bottom => "[data-hook='admin_configurations_menu']",
+ :text => "<%= configurations_menu_item(I18n.t('stores_admin'), admin_stores_url, I18n.t('manage_stores')) %>",
+ :disabled => false)
View
6 app/overrides/decorate_admin_products_form.rb
@@ -0,0 +1,6 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/products/_form",
+ :name => "multi_domain_admin_product_form_meta",
+ :insert_bottom => "[data-hook='admin_product_form_meta']",
+ :partial => "spree/admin/products/stores",
+ :disabled => false)
View
20 app/overrides/decorate_admin_products_index.rb
@@ -0,0 +1,20 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/products/index",
+ :name => "multi_domain_admin_products_index_headers",
+ :insert_before => "[data-hook='admin_products_index_header_actions']",
+ :partial => "spree/admin/products/index_headers",
+ :disabled => false)
+
+Deface::Override.new(
+ :virtual_path => "spree/admin/products/index",
+ :name => "multi_domain_admin_products_index_rows",
+ :insert_before => "[data-hook='admin_products_index_row_actions']",
+ :partial => "spree/admin/products/index_rows",
+ :disabled => false)
+
+Deface::Override.new(
+ :virtual_path => "spree/admin/products/index",
+ :name => "multi_domain_admin_products_index_search",
+ :insert_top => "[data-hook='admin_products_index_search']",
+ :partial => "spree/admin/products/index_search_fields",
+ :disabled => false)
View
6 app/overrides/decorate_admin_trackers_form.rb
@@ -0,0 +1,6 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/trackers/_form",
+ :name => "multi_domain_additional_tracker_fields",
+ :replace => "[data-hook='additional_tracker_fields']",
+ :partial => "spree/admin/trackers/store",
+ :disabled => false)
View
13 app/overrides/decorate_admin_trackers_index.rb
@@ -0,0 +1,13 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/trackers/index",
+ :name => "multi_domain_admin_trackers_index_headers",
+ :insert_before => "[data-hook='admin_trackers_index_headers'] th:last",
+ :text => "<th><%= I18n.t(:store) %></th>",
+ :disabled => false)
+
+Deface::Override.new(
+ :virtual_path => "spree/admin/trackers/index",
+ :name => "multi_domain_admin_trackers_index_rows",
+ :insert_before => "[data-hook='admin_trackers_index_rows'] td:last",
+ :partial => "spree/admin/trackers/index_rows",
+ :disabled => false)
View
4 app/views/admin/products/_index_search_fields.html.erb
@@ -1,4 +0,0 @@
-<p>
- <label><%= t("store") %></label><br />
- <%= f.select :stores_id_equals, Store.all.collect {|s| [s.name, s.id ] }, {:include_blank => true} %></p>
-</p>
View
0 ...ws/admin/products/_index_headers.html.erb → ...ee/admin/products/_index_headers.html.erb
File renamed without changes.
View
0 ...views/admin/products/_index_rows.html.erb → ...spree/admin/products/_index_rows.html.erb
File renamed without changes.
View
4 app/views/spree/admin/products/_index_search_fields.html.erb
@@ -0,0 +1,4 @@
+<p>
+ <label><%= t("store") %></label><br />
+ <%= f.select :stores_id_equals, Spree::Store.all.collect {|s| [s.name, s.id ] }, {:include_blank => true} %></p>
+</p>
View
0 app/views/admin/products/_stores.html.erb → ...ews/spree/admin/products/_stores.html.erb
File renamed without changes.
View
0 app/views/admin/stores/_form.html.erb → app/views/spree/admin/stores/_form.html.erb
File renamed without changes.
View
2 app/views/admin/stores/edit.html.erb → app/views/spree/admin/stores/edit.html.erb
@@ -1,4 +1,4 @@
-<%= render :partial => 'admin/shared/configuration_menu' %>
+<%= render :partial => 'spree/admin/shared/configuration_menu' %>
<h1><%= t("editing_store") %></h1>
<%= render "shared/error_messages", :target => @store %>
View
2 app/views/admin/stores/index.html.erb → app/views/spree/admin/stores/index.html.erb
@@ -1,4 +1,4 @@
-<%= render :partial => 'admin/shared/configuration_menu' %>
+<%= render :partial => 'spree/admin/shared/configuration_menu' %>
<div class='toolbar'>
<ul class='actions'>
View
2 app/views/admin/stores/new.html.erb → app/views/spree/admin/stores/new.html.erb
@@ -1,4 +1,4 @@
-<%= render :partial => 'admin/shared/configuration_menu' %>
+<%= render :partial => 'spree/admin/shared/configuration_menu' %>
<h1><%= t("new_store") %></h1>
<%= render "shared/error_messages", :target => @store %>
View
0 app/views/admin/taxonomies/_form.html.erb → ...ews/spree/admin/taxonomies/_form.html.erb
File renamed without changes.
View
0 ...views/admin/trackers/_index_rows.html.erb → ...spree/admin/trackers/_index_rows.html.erb
File renamed without changes.
View
0 app/views/admin/trackers/_store.html.erb → ...iews/spree/admin/trackers/_store.html.erb
File renamed without changes.
View
0 app/views/shared/_google_analytics.html.erb → ...s/spree/shared/_google_analytics.html.erb
File renamed without changes.
View
4 config/routes.rb
@@ -1,7 +1,5 @@
-Rails.application.routes.draw do
-
+Spree::Core::Engine.routes.append do
namespace :admin do
resources :stores
end
-
end
View
14 db/migrate/20091202123245_add_order_store.rb
@@ -1,9 +1,17 @@
class AddOrderStore < ActiveRecord::Migration
def self.up
- add_column :orders, :store_id, :integer
+ if table_exists?('orders')
+ add_column :orders, :store_id, :integer
+ elsif table_exists?('spree_orders')
+ add_column :spree_orders, :store_id, :integer
+ end
end
def self.down
- remove_column :orders, :store_id
+ if table_exists?('orders')
+ remove_column :orders, :store_id
+ elsif table_exists?('spree_orders')
+ remove_column :spree_orders, :store_id
+ end
end
-end
+end
View
26 db/migrate/20100114020535_add_store_to_tracker.rb
@@ -1,13 +1,25 @@
class AddStoreToTracker < ActiveRecord::Migration
- def self.up
- change_table :trackers do |t|
- t.references :store
- end
+ def self.up
+ if table_exists?('trackers')
+ change_table :trackers do |t|
+ t.references :store
+ end
+ elsif table_exists?('spree_trackers')
+ change_table :spree_trackers do |t|
+ t.references :store
+ end
+ end
end
def self.down
- change_table :trackers do |t|
- t.remove :store_id
+ if table_exists?('trackers')
+ change_table :trackers do |t|
+ t.remove :store_id
+ end
+ elsif table_exists?('spree_trackers')
+ change_table :spree_trackers do |t|
+ t.remove :store_id
+ end
end
end
-end
+end
View
2 db/migrate/20100227175140_add_default_store.rb
@@ -6,4 +6,4 @@ def self.up
def self.down
remove_column :stores, :default
end
-end
+end
View
17 db/migrate/20100616204303_store_id_for_taxonomies.rb
@@ -1,10 +1,19 @@
class StoreIdForTaxonomies < ActiveRecord::Migration
def self.up
- add_column "taxonomies", "store_id", :integer
- add_index "taxonomies", "store_id"
+ if table_exists?('taxonomies')
+ add_column :taxonomies, :store_id, :integer
+ add_index :taxonomies, :store_id
+ elsif table_exists?('spree_taxonomies')
+ add_column :spree_taxonomies, :store_id, :integer
+ add_index :spree_taxonomies, :store_id
+ end
end
def self.down
- remove_column "taxonomies", "store_id"
+ if table_exists?('taxonomies')
+ remove_column :taxonomies, :store_id
+ elsif table_exists?('spree_taxonomies')
+ remove_column :spree_taxonomies, :store_id
+ end
end
-end
+end
View
12 db/migrate/20120223183401_namespace.rb
@@ -0,0 +1,12 @@
+class Namespace < ActiveRecord::Migration
+ def up
+ rename_table :stores, :spree_stores
+ rename_table :products_stores, :spree_products_stores
+ end
+
+ def down
+ rename_table :spree_stores, :stores
+ rename_table :spree_products_stores, :products_stores
+
+ end
+end
View
27 lib/generators/spree_multi_domain/install/install_generator.rb
@@ -0,0 +1,27 @@
+module SpreeMultiDomain
+ module Generators
+ class InstallGenerator < Rails::Generators::Base
+
+# def add_javascripts
@radar
radar Mar 24, 2012

You could just remove these lines instead of commenting them out.

+# append_file "app/assets/javascripts/admin/all.js", "//= require admin/product_assembly\n"
+# end
+
+# def add_stylesheets
+# inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_social\n", :before => /\*\//, :verbose => true
+# end
+
+ def add_migrations
+ run 'rake railties:install:migrations FROM=spree_multi_domain'
+ end
+
+ def run_migrations
+ res = ask "Would you like to run the migrations now? [Y/n]"
+ if res == "" || res.downcase == "y"
+ run 'rake db:migrate'
+ else
+ puts "Skiping rake db:migrate, don't forget to run it!"
+ end
+ end
+ end
+ end
+end
View
4 lib/spree/search/multi_domain.rb
@@ -1,7 +1,7 @@
module Spree::Search
- class MultiDomain < Spree::Search::Base
+ class MultiDomain < Spree::Core::Search::Base
def get_base_scope
- base_scope = @cached_product_group ? @cached_product_group.products.active : Product.active
+ base_scope = @cached_product_group ? @cached_product_group.products.active : Spree::Product.active
base_scope = base_scope.by_store(current_store_id) if current_store_id
base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
View
116 lib/spree_multi_domain.rb
@@ -1,116 +1,2 @@
require 'spree_core'
-
-module SpreeMultiDomain
- class Engine < Rails::Engine
-
- config.autoload_paths += %W(#{config.root}/lib)
-
- def self.activate
-
- require 'spree_multi_domain_hooks'
- #override search to make it multi-store aware
- Spree::Config.searcher_class = Spree::Search::MultiDomain
-
- Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
- Rails.env.production? ? require(c) : load(c)
- end
-
-
- end
-
- config.to_prepare &method(:activate).to_proc
- end
-end
-
-# Make it possible to add to existing resource controller hooks with '<<' even when there's no hook of a given type defined yet.
-# e.g. create.before << :assign_to_store
-ResourceController::Accessors.module_eval do
- private
- def block_accessor(*accessors)
- accessors.each do |block_accessor|
- class_eval <<-"end_eval", __FILE__, __LINE__
-
- def #{block_accessor}(*args, &block)
- @#{block_accessor} ||= []
- unless args.empty? && block.nil?
- args.push block if block_given?
- @#{block_accessor} = [args].flatten
- end
- @#{block_accessor}
- end
-
- end_eval
- end
- end
-end
-
-Spree::CurrentOrder.module_eval do
- def current_order_with_multi_domain(create_order_if_necessary = false)
- current_order_without_multi_domain(create_order_if_necessary)
- if @current_order and current_store and @current_order.store.nil?
- @current_order.update_attribute(:store_id, current_store.id)
- end
- @current_order
- end
- alias_method_chain :current_order, :multi_domain
-end
-
-
-module SpreeBase
- module InstanceMethods
- private
-
- def current_store
- @current_store ||= ::Store.current(request.env['SERVER_NAME'])
- end
-
- def current_tracker
- @current_tracker ||= Tracker.current(request.env['SERVER_NAME'])
- end
-
- def get_taxonomies
- @taxonomies ||= current_store.present? ? Taxonomy.where(["store_id = ?", current_store.id]) : Taxonomy
- @taxonomies = @taxonomies.find(:all, :include => {:root => :children})
- @taxonomies
- end
-
- def add_current_store_id_to_params
- params[:current_store_id] = current_store.try(:id)
- end
- end
-
- class << self
-
- def included_with_multi_domain(receiver)
- included_without_multi_domain(receiver)
-
- receiver.send :helper, 'products'
- receiver.send :helper, 'taxons'
- receiver.send :before_filter, 'add_current_store_id_to_params'
- receiver.send :helper_method, 'current_store'
- receiver.send :helper_method, 'current_tracker'
- end
-
- alias_method_chain :included, :multi_domain
- end
-end
-
-
-module ActionView
- class TemplateRenderer
- def find_layout_with_multi_store(layout, locals)
- store_layout = layout
- if respond_to?(:current_store) && current_store && !controller.is_a?(Admin::BaseController)
- store_layout = layout.gsub("layouts/", "layouts/#{current_store.code}/")
- end
- begin
- find_layout_without_multi_store(store_layout, locals)
- rescue ::ActionView::MissingTemplate
- find_layout_without_multi_store(layout, locals)
- end
- end
-
- alias_method_chain :find_layout, :multi_store
- end
-
-end
+require 'spree_multi_domain/engine'
View
90 lib/spree_multi_domain/engine.rb
@@ -0,0 +1,90 @@
+module SpreeMultiDomain
+ class Engine < Rails::Engine
+ engine_name 'spree_multi_domain'
+
+ config.autoload_paths += %W(#{config.root}/lib)
+
+ def self.activate
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
+ Rails.application.config.cache_classes ? require(c) : load(c)
+ end
+
+ Spree::Config.searcher_class = Spree::Search::MultiDomain
+ end
+
+ config.to_prepare &method(:activate).to_proc
+
+ initializer "templates with dynamic layouts" do |app|
+ ActionView::TemplateRenderer.class_eval do
+ def find_layout_with_multi_store(layout, locals)
+ store_layout = layout
+
+ if respond_to?(:current_store) && current_store && !controller.is_a?(Spree::Admin::BaseController)
+ store_layout = layout.gsub("layouts/", "layouts/#{current_store.code}/")
+ end
+
+ begin
+ find_layout_without_multi_store(store_layout, locals)
+ rescue ::ActionView::MissingTemplate
+ find_layout_without_multi_store(layout, locals)
+ end
+ end
+
+ alias_method_chain :find_layout, :multi_store
+ end
+ end
+
+ initializer "current order decoration" do |app|
+ ::Spree::Core::CurrentOrder.module_eval do
+ def current_order_with_multi_domain(create_order_if_necessary = false)
+ current_order_without_multi_domain(create_order_if_necessary)
+
+ if @current_order and current_store and @current_order.store.nil?
+ @current_order.update_attribute(:store_id, current_store.id)
+ end
+
+ @current_order
+ end
+ alias_method_chain :current_order, :multi_domain
+ end
+ end
+
+ initializer "controller helpers decoration" do |app|
+ ::Spree::Core::ControllerHelpers.module_eval do
+
+ def current_store
+ @current_store ||= Spree::Store.current(request.env['SERVER_NAME'])
+ end
+
+ def current_tracker
+ @current_tracker ||= Spree::Tracker.current(request.env['SERVER_NAME'])
+ end
+
+ def get_taxonomies
+ @taxonomies ||= current_store.present? ? Spree::Taxonomy.where(["store_id = ?", current_store.id]) : Spree::Taxonomy
+ @taxonomies = @taxonomies.find(:all, :include => {:root => :children})
+ @taxonomies
+ end
+
+ def add_current_store_id_to_params
+ params[:current_store_id] = current_store.try(:id)
+ end
+
+ class << self
+
+ def included_with_multi_domain(receiver)
+ included_without_multi_domain(receiver)
+
+ receiver.send :helper, 'spree/products'
+ receiver.send :helper, 'spree/taxons'
+ receiver.send :before_filter, 'add_current_store_id_to_params'
+ receiver.send :helper_method, 'current_store'
+ receiver.send :helper_method, 'current_tracker'
+ end
+
+ alias_method_chain :included, :multi_domain
+ end
+ end
+ end
+ end
+end
View
55 lib/spree_multi_domain_hooks.rb
@@ -1,55 +0,0 @@
-Deface::Override.new(
- :virtual_path => "admin/products/index",
- :name => "multi_domain_admin_products_index_headers",
- :insert_before => "[data-hook='admin_products_index_header_actions']",
- :partial => "admin/products/index_headers",
- :disabled => false)
-
-Deface::Override.new(
- :virtual_path => "admin/products/index",
- :name => "multi_domain_admin_products_index_rows",
- :insert_before => "[data-hook='admin_products_index_row_actions']",
- :partial => "admin/products/index_rows",
- :disabled => false)
-
-Deface::Override.new(
- :virtual_path => "admin/products/index",
- :name => "multi_domain_admin_products_index_search",
- :insert_top => "[data-hook='admin_products_index_search']",
- :partial => "admin/products/index_search_fields",
- :disabled => false)
-
-Deface::Override.new(
- :virtual_path => "admin/products/_form",
- :name => "multi_domain_admin_product_form_meta",
- :insert_bottom => "[data-hook='admin_product_form_meta']",
- :partial => "admin/products/stores",
- :disabled => false)
-
-Deface::Override.new(
- :virtual_path => "admin/trackers/index",
- :name => "multi_domain_admin_trackers_index_headers",
- :insert_before => "[data-hook='admin_trackers_index_headers'] th:last",
- :text => "<th><%= I18n.t(:store) %></th>",
- :disabled => false)
-
-Deface::Override.new(
- :virtual_path => "admin/trackers/index",
- :name => "multi_domain_admin_trackers_index_rows",
- :insert_before => "[data-hook='admin_trackers_index_rows'] td:last",
- :partial => "admin/trackers/index_rows",
- :disabled => false)
-
-Deface::Override.new(
- :virtual_path => "admin/trackers/_form",
- :name => "multi_domain_additional_tracker_fields",
- :replace => "[data-hook='additional_tracker_fields']",
- :partial => "admin/trackers/store",
- :disabled => false)
-
-Deface::Override.new(
- :virtual_path => "admin/configurations/index",
- :name => "multi_domain_admin_configurations_menu",
- :insert_bottom => "[data-hook='admin_configurations_menu']",
- :text => "<%= configurations_menu_item(I18n.t('stores_admin'), admin_stores_url, I18n.t('manage_stores')) %>",
- :disabled => false)
View
2 lib/tasks/multi_domain_extension_tasks.rake
@@ -0,0 +1,2 @@
+namespace :spree_multi_domain do
+end
View
5 script/rails
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+ENGINE_PATH = File.expand_path('../..', __FILE__)
+load File.expand_path('../../spec/dummy/script/rails', __FILE__)
View
44 spec/controllers/spree/admin/products_controller_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe Spree::Admin::ProductsController do
+
+ before do
+ controller.stub :current_user => Factory(:admin_user)
+ end
+
+ describe "on :index" do
+ it "renders index" do
+ get :index, :use_route => :spree
+ end
+ end
+
+ describe "on a PUT to :update" do
+ before(:each) do
+ @product = Factory(:product)
+ @store = Factory(:store)
+ end
+
+ describe "when no stores are selected" do
+ it "clears stores if they previously existed" do
+ @product.stores << @store
+ @product.reload
+
+ put :update, :id => @product.permalink,
+ :product => {:name => @product.name},
+ :use_route => :spree
+
+ @product.store_ids.should be_empty
+ end
+ end
+
+ describe "when a store is selected" do
+ it "clears stores" do
+ put :update, :id => @product.permalink,
+ :product => {:name => @product.name, :store_ids => [@store.id]},
+ :use_route => :spree
+
+ @product.reload.store_ids.should == [@store.id]
+ end
+ end
+ end
+end
View
14 spec/controllers/spree/admin/stores_controller_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe Spree::Admin::StoresController do
+
+ before do
+ controller.stub :current_user => Factory(:admin_user)
+ end
+
+ describe "on :index" do
+ it "renders index" do
+ get :index, :use_route => :spree
+ end
+ end
+end
View
36 spec/controllers/spree/products_controller_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe Spree::ProductsController do
+
+ before do
+ controller.stub :current_user => Factory(:user)
+ end
+
+ describe 'on :show to a product w/out correct store' do
+ before(:each) do
+ @store = Factory(:store)
+ @product = Factory(:product)
+ end
+
+ it 'should return 404' do
+ get :show, :id => @product.permalink, :use_route => :spree
+
+ response.response_code.should == 404
+ end
+
+
+ end
+
+ describe 'on :show to a product w/ store' do
+ before(:each) do
+ @store = Factory(:store)
+ @product = Factory(:product, :stores => [@store])
+ end
+
+ it 'should return 200' do
+ get :show, :id => @product.permalink, :use_route => :spree
+
+ response.response_code.should == 200
+ end
+ end
+end
View
5 spec/factories.rb
@@ -0,0 +1,5 @@
+Factory.define(:store, :class => Spree::Store) do |f|
+ f.name 'My store'
+ f.code 'my_store'
+ f.domains 'www.example.com' # makes life simple, this is the default integration session domain
+end
View
18 spec/models/spree/order_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe Spree::Order do
+
+ before(:each) do
+ @store = Factory(:store)
+ @order = Factory(:order, :store => @store)
+
+ @order2 = Factory(:order)
+ end
+
+ it 'should correctly find products by store' do
+ by_store = Spree::Order.by_store(@store).all
+
+ by_store.should include(@order)
+ by_store.should_not include(@order2)
+ end
+end
View
18 spec/models/spree/product_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe Spree::Product do
+
+ before(:each) do
+ @store = Factory(:store)
+ @product = Factory(:product, :stores => [@store])
+
+ @product2 = Factory(:product, :permalink => 'something else')
+ end
+
+ it 'should correctly find products by store' do
+ products_by_store = Spree::Product.by_store(@store).all
+
+ products_by_store.should include(@product)
+ products_by_store.should_not include(@product2)
+ end
+end
View
17 spec/models/spree/store_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe Spree::Store do
+
+ before(:each) do
+ @store = Factory(:store, :domains => "website1.com\nwww.subdomain.com")
+ @store2 = Factory(:store, :domains => 'freethewhales.com')
+ end
+
+ it "should find stores by domain" do
+ by_domain = Spree::Store.by_domain('www.subdomain.com').all
+
+ by_domain.should include(@store)
+ by_domain.should_not include(@store2)
+ end
+
+end
View
15 spec/models/spree/tracker_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe Spree::Tracker do
+ before(:each) do
+ store = Factory(:store)
+ @tracker = Factory(:tracker, :store => store)
+
+ another_store = Factory(:store, :domains => 'completely-different-store.com')
+ @tracker2 = Factory(:tracker, :store => another_store)
+ end
+
+ it "should pull out the current tracker" do
+ Spree::Tracker.current('www.example.com').should == @tracker
+ end
+end
View
27 spec/requests/global_controller_helpers.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe "Global controller helpers" do
+
+ before(:each) do
+ @store = Factory :store
+ @tracker = Factory :tracker, :store => @store
+ get '/'
+ end
+
+ it "should include the right tracker" do
+ response.body.should include(@tracker.analytics_id)
+ end
+
+ it "should populate the params with store id" do
+ request.params[:current_store_id].should == @store.id
+ end
+
+ it "should create a store-aware order" do
+ controller.current_store.should == @store
+ end
+
+ it "should instantiate the correct store-bound tracker" do
+ controller.current_tracker.should == @tracker
+ end
+
+end
View
33 spec/spec_helper.rb
@@ -0,0 +1,33 @@
+# Configure Rails Environment
+ENV["RAILS_ENV"] = "test"
+
+require File.expand_path("../dummy/config/environment.rb", __FILE__)
+
+require 'rspec/rails'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
+
+# Requires factories defined in spree_core
+require 'spree/core/testing_support/factories'
+require 'factories'
+
+RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+end
View
11 spree_multi_domain.gemspec
@@ -1,7 +1,8 @@
+# encoding: UTF-8
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_multi_domain'
- s.version = '3.0.5'
+ s.version = '1.3.05'
@radar
radar Mar 24, 2012

Why such an arbitrary version number?

@jumph4x
jumph4x Mar 24, 2012

Less arbitrary than it was originally, heh. Simply trying to align major version with Spree major version, as with other Spree extensions.

Roman actually told be going down in version like this might cause an issue, I forgot to fix. Advise.

s.summary = 'Adds multiple site support to Spree'
s.description = 'Multiple Spree stores on different domains - single unified backed for processing orders.'
s.required_ruby_version = '>= 1.8.7'
@@ -16,5 +17,11 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'
- s.add_dependency('spree_core', '>= 0.60.0')
+ s.add_dependency 'spree_core', '~> 1.0.3'
+
+ s.add_development_dependency 'capybara', '1.0.1'
+ s.add_development_dependency 'factory_girl'
+ s.add_development_dependency 'ffaker'
+ s.add_development_dependency 'rspec-rails', '~> 2.7'
+ s.add_development_dependency 'sqlite3'
end

1 comment on commit 1071e98

@radar

Looks good! Thanks for the work!

Please sign in to comment.