spree_multi_domain 3.0.2 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/.gitignore +45 -0
  2. data/Rakefile +18 -0
  3. data/app/controllers/admin/products_controller_decorator.rb +13 -0
  4. data/app/controllers/products_controller_decorator.rb +11 -0
  5. data/app/mailers/order_mailer.rb +21 -0
  6. data/app/mailers/shipment_mailer.rb +12 -0
  7. data/app/models/models_decorator.rb +22 -0
  8. data/app/models/store.rb +5 -0
  9. data/app/views/admin/stores/_form.html.erb +4 -0
  10. data/app/views/admin/stores/edit.html.erb +2 -2
  11. data/app/views/admin/stores/index.html.erb +2 -2
  12. data/app/views/admin/stores/new.html.erb +2 -2
  13. data/app/views/shared/_google_analytics.html.erb +10 -4
  14. data/config/locales/en.yml +8 -0
  15. data/lib/generators/spree_multi_domain/install_generator.rb +15 -0
  16. data/lib/generators/templates/db/migrate/20091202122944_create_stores.rb +14 -0
  17. data/lib/generators/templates/db/migrate/20091202123245_add_order_store.rb +9 -0
  18. data/lib/generators/templates/db/migrate/20100114020535_add_store_to_tracker.rb +13 -0
  19. data/lib/generators/templates/db/migrate/20100227175140_add_default_store.rb +9 -0
  20. data/lib/generators/templates/db/migrate/20100227180338_create_products_stores.rb +13 -0
  21. data/lib/generators/templates/db/migrate/20100616204303_store_id_for_taxonomies.rb +10 -0
  22. data/lib/generators/templates/db/migrate/20110223141800_add_email_to_stores.rb +13 -0
  23. data/lib/spree/search/multi_domain.rb +20 -0
  24. data/lib/spree_multi_domain.rb +76 -4
  25. data/spree_multi_domain.gemspec +22 -0
  26. metadata +27 -11
  27. data/db/seeds.rb +0 -2
  28. data/lib/spree_multi_domain/engine.rb +0 -154
  29. data/lib/tasks/site_extension_tasks.rake +0 -17
data/.gitignore ADDED
@@ -0,0 +1,45 @@
1
+ \#*
2
+ **/*.db
3
+ *~
4
+ .#*
5
+ .DS_Store
6
+ .dotest
7
+ .idea
8
+ .loadpath
9
+ .project
10
+ *.swp
11
+ public/dispatch.cgi
12
+ public/dispatch.fcgi
13
+ public/dispatch.rb
14
+ httpd
15
+ pgsql
16
+ config/*-public.asc
17
+ config/database.yml
18
+ config/mongrel_cluster.yml
19
+ db/*.sql
20
+ db/*.sqlite3*
21
+ db/schema.rb
22
+ doc/**/*
23
+ lib/products_index_profiler.rb
24
+ log/*.log
25
+ pkg
26
+ public/assets
27
+ public/attachments
28
+ public/blank_iframe.html
29
+ public/images
30
+ public/javascripts
31
+ public/stylesheets
32
+ public/ckeditora
33
+ spree.gemspec
34
+ spree_dev
35
+ spree_test
36
+ tmp
37
+ vendor/rails
38
+ vendor/extensions/google_base
39
+ public/google_base.xml
40
+ public/template_google_base.xml
41
+ coverage/*
42
+ var
43
+ TAGS
44
+ nbproject
45
+ vendor/extensions/theme_default/app/stylesheets/*.css
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/packagetask'
5
+ require 'rake/gempackagetask'
6
+
7
+ spec = eval(File.read('spree_multi_domain.gemspec'))
8
+
9
+ Rake::GemPackageTask.new(spec) do |p|
10
+ p.gem_spec = spec
11
+ end
12
+
13
+ desc "Release to gemcutter"
14
+ task :release => :package do
15
+ require 'rake/gemcutter'
16
+ Rake::Gemcutter::Tasks.new(spec).define
17
+ Rake::Task['gem:push'].invoke
18
+ end
@@ -0,0 +1,13 @@
1
+ Admin::ProductsController.class_eval do
2
+ update.before << :set_stores
3
+
4
+ create.before << :add_to_all_stores
5
+
6
+ private
7
+ def set_stores
8
+ @product.store_ids = nil unless params[:product].key? :store_ids
9
+ end
10
+
11
+ def add_to_all_stores
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ ProductsController.class_eval do
2
+ before_filter :can_show_product, :only => :show
3
+
4
+ private
5
+ def can_show_product
6
+ if @product.stores.empty? || @product.stores.include?(@site)
7
+ render :file => "public/404.html", :status => 404
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,21 @@
1
+ class OrderMailer < ActionMailer::Base
2
+ helper "spree/base"
3
+
4
+ def confirm_email(order, resend=false)
5
+ @order = order
6
+ subject = (resend ? "[RESEND] " : "")
7
+ subject += "#{Spree::Config[:site_name]} Order Confirmation ##{order.number}"
8
+ mail_params = {:to => order.email, :subject => subject}
9
+ mail_params[:from] = order.store.email if order.store.email.present?
10
+ mail(mail_params)
11
+ end
12
+
13
+ def cancel_email(order, resend=false)
14
+ @order = order
15
+ subject = (resend ? "[RESEND] " : "")
16
+ subject += "#{Spree::Config[:site_name]} Cancellation of Order ##{order.number}"
17
+ mail_params = {:to => order.email, :subject => subject}
18
+ mail_params[:from] = order.store.email if order.store.email.present?
19
+ mail(mail_params)
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ class ShipmentMailer < ActionMailer::Base
2
+ helper "spree/base"
3
+
4
+ def shipped_email(shipment, resend=false)
5
+ @shipment = shipment
6
+ subject = (resend ? "[RESEND] " : "")
7
+ subject += "#{Spree::Config[:site_name]} Shipment Notification ##{shipment.order.number}"
8
+ mail_params = {:to => shipment.order.email, :subject => subject}
9
+ mail_params[:from] = shipment.order.store.email if shipment.order.store.email.present?
10
+ mail(mail_params)
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ Product.class_eval do
2
+ has_and_belongs_to_many :stores
3
+ scope :by_store, lambda {|store| joins(:stores).where("products_stores.store_id = ?", store)}
4
+ end
5
+
6
+ Order.class_eval do
7
+ belongs_to :store
8
+ scope :by_store, lambda { |store| where(:store_id => store.id) }
9
+ end
10
+
11
+ Taxonomy.class_eval do
12
+ belongs_to :store
13
+ end
14
+
15
+ Tracker.class_eval do
16
+ belongs_to :store
17
+
18
+ def self.current(domain)
19
+ trackers = Tracker.find(:all, :conditions => {:active => true, :environment => ENV['RAILS_ENV']})
20
+ trackers.select { |t| t.store_id == Store.current(domain).try(:id) }.first
21
+ end
22
+ end
data/app/models/store.rb CHANGED
@@ -7,4 +7,9 @@ class Store < ActiveRecord::Base
7
7
 
8
8
  scope :default, where(:default => true)
9
9
  scope :by_domain, lambda { |domain| where("domains like ?", "%#{domain}%") }
10
+
11
+ def self.current(domain = nil)
12
+ current_store = domain ? Store.by_domain(domain).first : nil
13
+ current_store || Store.default.first
14
+ end
10
15
  end
@@ -20,6 +20,10 @@
20
20
  </label>
21
21
  </td>
22
22
  </tr>
23
+ <tr>
24
+ <td><label><%=t("send_mails_as")%></label></td>
25
+ <td><%= text_field :store, :email, {"style" => "width:200px"} %></td>
26
+ </tr>
23
27
  <tr>
24
28
  <td><label><%=t("domains")%></label></td>
25
29
  <td><%= text_area :store, :domains, {:cols => 60, :rows => 4} %></td>
@@ -1,11 +1,11 @@
1
1
  <%= render :partial => 'admin/shared/configuration_menu' %>
2
2
 
3
3
  <h1><%= t("editing_store") %></h1>
4
- <%= error_messages_for :store %>
4
+ <%= render "shared/error_messages", :target => @store %>
5
5
  <% form_for(@store, :url => object_url, :html => { :method => :put }) do |f| %>
6
6
  <%= render :partial => "form", :locals => { :f => f } %>
7
7
  <p class="form-buttons">
8
8
  <%= button t('update') %>
9
9
  <%= t("or") %> <%= link_to t("actions.cancel"), admin_stores_url %>
10
10
  </p>
11
- <% end %>
11
+ <% end %>
@@ -15,6 +15,7 @@
15
15
  <thead>
16
16
  <th><%= t("name") %></th>
17
17
  <th><%= t("code") %></th>
18
+ <th><%= t("send_mails_as") %></th>
18
19
  <th><%= t("domains") %></th>
19
20
  <th><%= t("action") %></th>
20
21
  </thead>
@@ -23,6 +24,7 @@
23
24
  <tr id="<%= dom_id store %>">
24
25
  <td width="120px"><%= store.name %></td>
25
26
  <td width="80px"><%= store.code %></td>
27
+ <td width="80px"><%= store.email %></td>
26
28
  <td width="220"><%= store.domains %></td>
27
29
  <td width="140px">
28
30
  <%= link_to_edit store %> &nbsp;
@@ -32,5 +34,3 @@
32
34
  <% end %>
33
35
  </tbody>
34
36
  </table>
35
- <%= will_paginate(:previous_label => "&#171; #{t('previous')}", :next_label => "#{t('next')} &#187;") %>
36
-
@@ -1,7 +1,7 @@
1
1
  <%= render :partial => 'admin/shared/configuration_menu' %>
2
2
 
3
3
  <h1><%= t("new_store") %></h1>
4
- <%= error_messages_for :store %>
4
+ <%= render "shared/error_messages", :target => @store %>
5
5
 
6
6
  <% form_for(:store, :url => collection_url) do |f| %>
7
7
  <%= render :partial => "form", :locals => { :f => f } %>
@@ -9,4 +9,4 @@
9
9
  <%= button t('continue') %>
10
10
  <%= t("or") %> <%= link_to t("actions.cancel"), admin_stores_url %>
11
11
  </p>
12
- <% end %>
12
+ <% end %>
@@ -1,10 +1,16 @@
1
- <% if tracker = Tracker.current %>
1
+ <% if tracker = current_tracker %>
2
2
 
3
3
  <script type="text/javascript">
4
4
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
5
5
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
6
6
  </script>
7
7
 
8
+ <script type="text/javascript">
9
+ var pageTracker = _gat._getTracker("<%= tracker.analytics_id %>");
10
+ pageTracker._initData();
11
+ pageTracker._trackPageview();
12
+ </script>
13
+
8
14
  <% if @analytics_page %>
9
15
  <script type="text/javascript">document.strTrackPageView="<%= @analytics_page %>";</script>
10
16
  <% end %>
@@ -31,8 +37,8 @@
31
37
  "<%= "#{"QA-" if request.server_name =~ /^(dev.|localhost)/ }#{@order.number}" %>",
32
38
  "",
33
39
  "<%= @order.total %>",
34
- "<%= @order.tax_charges.sum(:amount).to_s %>",
35
- "<%= @order.shipping_charges.sum(:amount).to_s %>",
40
+ "<%= @order.adjustments.tax.sum(:amount).to_s %>",
41
+ "<%= @order.adjustments.shipping.sum(:amount).to_s %>",
36
42
  "<%= @order.ship_address.city if @order.ship_address %>",
37
43
  "<%= @order.ship_address.state.name if @order.ship_address && @order.ship_address.state %><%= @order.ship_address.state_name if @order.ship_address && @order.ship_address.state.nil? %>",
38
44
  "<%= @order.ship_address.country.name if @order.ship_address && @order.ship_address.country %>"
@@ -53,4 +59,4 @@
53
59
 
54
60
  </script>
55
61
  <% end %>
56
- <% end %>
62
+ <% end %>
@@ -0,0 +1,8 @@
1
+ en:
2
+ stores: Stores
3
+ new_store: New Store
4
+ domains: Domains
5
+ stores_admin: "Stores & Domains"
6
+ manage_stores: Configure multiple stores and associated domain names
7
+ editing_store: Editing Store
8
+ default: Default
@@ -0,0 +1,15 @@
1
+ module SpreeMultiDomain
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+
6
+ desc "Configures your Rails application for use with spree_multi_domain"
7
+
8
+ def copy_migrations
9
+ directory "db"
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,14 @@
1
+ class CreateStores < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :stores do |t|
4
+ t.string :name
5
+ t.string :code
6
+ t.text :domains
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :stores
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class AddOrderStore < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :orders, :store_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :orders, :store_id
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class AddStoreToTracker < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :trackers do |t|
4
+ t.references :store
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ change_table :trackers do |t|
10
+ t.remove :store_id
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class AddDefaultStore < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :stores, :default, :boolean, :default => false
4
+ end
5
+
6
+ def self.down
7
+ remove_column :stores, :default
8
+ end
9
+ 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,10 @@
1
+ class StoreIdForTaxonomies < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "taxonomies", "store_id", :integer
4
+ add_index "taxonomies", "store_id"
5
+ end
6
+
7
+ def self.down
8
+ remove_column "taxonomies", "store_id"
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ class AddEmailToStores < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :stores do |t|
4
+ t.string :email
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ change_table :stores do |t|
10
+ t.remove :email
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module Spree::Search
2
+ class MultiDomain < Spree::Search::Base
3
+ def get_base_scope
4
+ base_scope = @cached_product_group ? @cached_product_group.products.active : 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
+
9
+ base_scope = get_products_conditions_for(base_scope, keywords) unless keywords.blank?
10
+
11
+ base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
12
+ base_scope
13
+ end
14
+
15
+ def prepare(params)
16
+ super
17
+ @properties[:current_store_id] = params[:current_store_id]
18
+ end
19
+ end
20
+ end
@@ -1,7 +1,24 @@
1
1
  require 'spree_core'
2
2
  require 'spree_multi_domain_hooks'
3
- require 'spree_multi_domain/engine'
4
3
 
4
+ module SpreeMultiDomain
5
+ class Engine < Rails::Engine
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ def self.activate
10
+ #override search to make it multi-store aware
11
+ Spree::Config.searcher_class = Spree::Search::MultiDomain
12
+
13
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
14
+ Rails.env.production? ? require(c) : load(c)
15
+ end
16
+
17
+ end
18
+
19
+ config.to_prepare &method(:activate).to_proc
20
+ end
21
+ end
5
22
 
6
23
  # Make it possible to add to existing resource controller hooks with '<<' even when there's no hook of a given type defined yet.
7
24
  # e.g. create.before << :assign_to_store
@@ -25,17 +42,72 @@ ResourceController::Accessors.module_eval do
25
42
  end
26
43
  end
27
44
 
45
+ Spree::CurrentOrder.module_eval do
46
+ def current_order_with_multi_domain(create_order_if_necessary = false)
47
+ current_order_without_multi_domain(create_order_if_necessary)
48
+ if @current_order and current_store and @current_order.store.nil?
49
+ @current_order.update_attribute(:store_id, current_store.id)
50
+ end
51
+ @current_order
52
+ end
53
+ alias_method_chain :current_order, :multi_domain
54
+ end
55
+
56
+
57
+ module SpreeBase
58
+ module InstanceMethods
59
+ private
60
+
61
+ def current_store
62
+ @current_store ||= ::Store.current(request.env['SERVER_NAME'])
63
+ end
64
+
65
+ def current_tracker
66
+ @current_tracker ||= Tracker.current(request.env['SERVER_NAME'])
67
+ end
68
+
69
+ def get_taxonomies
70
+ @taxonomies ||= current_store.present? ? Taxonomy.where(["store_id = ?", current_store.id]) : Taxonomy
71
+ @taxonomies = @taxonomies.find(:all, :include => {:root => :children})
72
+ @taxonomies
73
+ end
74
+
75
+ def add_current_store_id_to_params
76
+ params[:current_store_id] = current_store.try(:id)
77
+ end
78
+ end
79
+
80
+ class << self
81
+
82
+ def included_with_multi_domain(receiver)
83
+ included_without_multi_domain(receiver)
84
+
85
+ receiver.send :helper, 'products'
86
+ receiver.send :helper, 'taxons'
87
+ receiver.send :before_filter, 'add_current_store_id_to_params'
88
+ receiver.send :helper_method, 'current_store'
89
+ receiver.send :helper_method, 'current_tracker'
90
+ end
91
+
92
+ alias_method_chain :included, :multi_domain
93
+ end
94
+ end
95
+
28
96
 
29
97
  module ActionView::Layouts
30
98
 
31
99
  def find_layout_with_multi_store(layout)
100
+ store_layout = layout
32
101
  if respond_to?(:current_store) && current_store && !controller.is_a?(Admin::BaseController)
33
- layout.gsub!("layouts/", "layouts/#{current_store.code}/")
102
+ store_layout = layout.gsub("layouts/", "layouts/#{current_store.code}/")
103
+ end
104
+ begin
105
+ find_layout_without_multi_store(store_layout)
106
+ rescue ::ActionView::MissingTemplate
107
+ find_layout_without_multi_store(layout)
34
108
  end
35
- find_layout_without_multi_store(layout)
36
109
  end
37
110
 
38
111
  alias_method_chain :find_layout, :multi_store
39
112
 
40
113
  end
41
-
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'spree_multi_domain'
4
+ s.version = '3.0.4'
5
+ s.summary = 'Adds multiple site support to Spree'
6
+ s.description = 'Multiple Spree stores on different domains - single unified backed for processing orders.'
7
+ s.required_ruby_version = '>= 1.8.7'
8
+
9
+ s.authors = ['Brian Quinn', 'Roman Smirnov', 'David North']
10
+ s.email = 'brian@railsdog.com'
11
+ s.homepage = 'http://spreecommerce.com'
12
+ s.rubyforge_project = 'spree_multi_domain'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_path = 'lib'
17
+ s.requirements << 'none'
18
+
19
+ s.has_rdoc = false
20
+
21
+ s.add_dependency('spree_core', '>= 0.40.0')
22
+ end
metadata CHANGED
@@ -5,16 +5,18 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 0
8
- - 2
9
- version: 3.0.2
8
+ - 4
9
+ version: 3.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brian Quinn
13
+ - Roman Smirnov
14
+ - David North
13
15
  autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-09-13 00:00:00 -04:00
19
+ date: 2011-02-23 00:00:00 +03:00
18
20
  default_executable:
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
@@ -26,10 +28,9 @@ dependencies:
26
28
  - !ruby/object:Gem::Version
27
29
  segments:
28
30
  - 0
29
- - 30
31
+ - 40
30
32
  - 0
31
- - beta1
32
- version: 0.30.0.beta1
33
+ version: 0.40.0
33
34
  type: :runtime
34
35
  version_requirements: *id001
35
36
  description: Multiple Spree stores on different domains - single unified backed for processing orders.
@@ -41,12 +42,15 @@ extensions: []
41
42
  extra_rdoc_files: []
42
43
 
43
44
  files:
45
+ - .gitignore
44
46
  - README.md
45
- - lib/spree_multi_domain/engine.rb
46
- - lib/spree_multi_domain.rb
47
- - lib/spree_multi_domain_hooks.rb
48
- - lib/tasks/site_extension_tasks.rake
47
+ - Rakefile
48
+ - app/controllers/admin/products_controller_decorator.rb
49
49
  - app/controllers/admin/stores_controller.rb
50
+ - app/controllers/products_controller_decorator.rb
51
+ - app/mailers/order_mailer.rb
52
+ - app/mailers/shipment_mailer.rb
53
+ - app/models/models_decorator.rb
50
54
  - app/models/store.rb
51
55
  - app/views/admin/products/_index_headers.html.erb
52
56
  - app/views/admin/products/_index_rows.html.erb
@@ -60,8 +64,20 @@ files:
60
64
  - app/views/admin/trackers/_index_rows.html.erb
61
65
  - app/views/admin/trackers/_store.html.erb
62
66
  - app/views/shared/_google_analytics.html.erb
63
- - db/seeds.rb
67
+ - config/locales/en.yml
64
68
  - config/routes.rb
69
+ - lib/generators/spree_multi_domain/install_generator.rb
70
+ - lib/generators/templates/db/migrate/20091202122944_create_stores.rb
71
+ - lib/generators/templates/db/migrate/20091202123245_add_order_store.rb
72
+ - lib/generators/templates/db/migrate/20100114020535_add_store_to_tracker.rb
73
+ - lib/generators/templates/db/migrate/20100227175140_add_default_store.rb
74
+ - lib/generators/templates/db/migrate/20100227180338_create_products_stores.rb
75
+ - lib/generators/templates/db/migrate/20100616204303_store_id_for_taxonomies.rb
76
+ - lib/generators/templates/db/migrate/20110223141800_add_email_to_stores.rb
77
+ - lib/spree/search/multi_domain.rb
78
+ - lib/spree_multi_domain.rb
79
+ - lib/spree_multi_domain_hooks.rb
80
+ - spree_multi_domain.gemspec
65
81
  has_rdoc: true
66
82
  homepage: http://spreecommerce.com
67
83
  licenses: []
data/db/seeds.rb DELETED
@@ -1,2 +0,0 @@
1
- # Use this file to load your own seed data from extensions.
2
- # See the db/seeds.rb file in the Spree core for some ideas on what you can do here.
@@ -1,154 +0,0 @@
1
- require "spree_multi_domain"
2
-
3
- module SpreeMultiDomain
4
-
5
- class Engine < Rails::Engine
6
-
7
- def self.activate
8
-
9
- Spree::BaseController.class_eval do
10
- helper_method :current_store
11
- helper :products, :taxons
12
-
13
- private
14
-
15
- # Tell Rails to look in layouts/#{@store.code} whenever we're inside of a store (instead of the standard /layouts location)
16
- def find_layout(layout, format, html_fallback=false) #:nodoc:
17
- layout_dir = current_store ? "layouts/#{current_store.code.downcase}" : "layouts"
18
- view_paths.find_template(layout.to_s =~ /\A\/|layouts\// ? layout : "#{layout_dir}/#{layout}", format, html_fallback)
19
- rescue ActionView::MissingTemplate
20
- raise if Mime::Type.lookup_by_extension(format.to_s).html?
21
- end
22
-
23
- def current_store
24
- @current_store ||= ::Store.by_domain(request.env['SERVER_NAME']).first
25
- @current_store ||= ::Store.default.first
26
- end
27
-
28
- def get_taxonomies
29
- @taxonomies ||= Taxonomy.find(:all, :include => {:root => :children}, :conditions => ["store_id = ?", @site.id])
30
- @taxonomies
31
- end
32
-
33
- end
34
-
35
- Product.class_eval do
36
- has_and_belongs_to_many :stores
37
- scope :by_store, lambda {|store| joins(:stores).where("products_stores.store_id = ?", store)}
38
- end
39
-
40
- ProductsController.class_eval do
41
- before_filter :can_show_product, :only => :show
42
-
43
- private
44
- def can_show_product
45
- if @product.stores.empty? || @product.stores.include?(@site)
46
- render :file => "public/404.html", :status => 404
47
- end
48
- end
49
-
50
- end
51
-
52
- #override search to make it multi-store aware
53
- Spree::Search.module_eval do
54
- def retrieve_products
55
- # taxon might be already set if this method is called from TaxonsController#show
56
- @taxon ||= Taxon.find_by_id(params[:taxon]) unless params[:taxon].blank?
57
- # add taxon id to params for searcher
58
- params[:taxon] = @taxon.id if @taxon
59
- @keywords = params[:keywords]
60
-
61
- per_page = params[:per_page].to_i
62
- per_page = per_page > 0 ? per_page : Spree::Config[:products_per_page]
63
- params[:per_page] = per_page
64
- params[:page] = 1 if (params[:page].to_i <= 0)
65
-
66
- # Prepare a search within the parameters
67
- Spree::Config.searcher.prepare(params)
68
-
69
- if !params[:order_by_price].blank?
70
- @product_group = ProductGroup.new.from_route([params[:order_by_price]+"_by_master_price"])
71
- elsif params[:product_group_name]
72
- @cached_product_group = ProductGroup.find_by_permalink(params[:product_group_name])
73
- @product_group = ProductGroup.new
74
- elsif params[:product_group_query]
75
- @product_group = ProductGroup.new.from_route(params[:product_group_query])
76
- else
77
- @product_group = ProductGroup.new
78
- end
79
-
80
- @product_group = @product_group.from_search(params[:search]) if params[:search]
81
-
82
- base_scope = @cached_product_group ? @cached_product_group.products.active : Product.active
83
- base_scope = base_scope.by_store(current_store.id) if current_store.present?
84
-
85
- base_scope = base_scope.in_taxon(@taxon) unless @taxon.blank?
86
- base_scope = base_scope.keywords(@keywords) unless @keywords.blank?
87
-
88
- base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
89
- @products_scope = @product_group.apply_on(base_scope)
90
-
91
- curr_page = Spree::Config.searcher.manage_pagination ? 1 : params[:page]
92
- @products = @products_scope.all.paginate({
93
- :include => [:images, :master],
94
- :per_page => per_page,
95
- :page => curr_page
96
- })
97
- @products_count = @products_scope.count
98
-
99
- return(@products)
100
- end
101
- end
102
-
103
- Admin::ProductsController.class_eval do
104
- update.before << :set_stores
105
-
106
- create.before << :add_to_all_stores
107
-
108
- private
109
- def set_stores
110
- @product.store_ids = nil unless params[:product].key? :store_ids
111
- end
112
-
113
- def add_to_all_stores
114
- end
115
- end
116
-
117
- Order.class_eval do
118
- belongs_to :store
119
- scope :by_store, lambda { |store| where(:store_id => store.id) }
120
- end
121
-
122
- Taxonomy.class_eval do
123
- belongs_to :store
124
- end
125
-
126
- Tracker.class_eval do
127
- belongs_to :store
128
-
129
- def self.current
130
- trackers = Tracker.find(:all, :conditions => {:active => true, :environment => ENV['RAILS_ENV']})
131
- trackers.select { |t| t.store.name == Spree::Config[:site_name] }.first
132
- end
133
- end
134
- end
135
-
136
- config.autoload_paths += %W(#{config.root}/lib)
137
- config.to_prepare &method(:activate).to_proc
138
-
139
- end
140
-
141
- end
142
-
143
-
144
- Spree::CurrentOrder.module_eval do
145
- def current_order_with_multi_domain(create_order_if_necessary = false)
146
- current_order_without_multi_domain(create_order_if_necessary)
147
- if @current_order and current_store and @current_order.store.nil?
148
- @current_order.update_attribute(:store_id, current_store.id)
149
- end
150
- @current_order
151
- end
152
- alias_method_chain :current_order, :multi_domain
153
- end
154
-
@@ -1,17 +0,0 @@
1
- namespace :spree do
2
- namespace :extensions do
3
- namespace :site do
4
- desc "Copies public assets of the Site to the instance public/ directory."
5
- task :update => :environment do
6
- is_svn_git_or_dir = proc {|path| path =~ /\.svn/ || path =~ /\.git/ || File.directory?(path) }
7
- Dir[SiteExtension.root + "/public/**/*"].reject(&is_svn_git_or_dir).each do |file|
8
- path = file.sub(SiteExtension.root, '')
9
- directory = File.dirname(path)
10
- puts "Copying #{path}..."
11
- mkdir_p RAILS_ROOT + directory
12
- cp file, RAILS_ROOT + path
13
- end
14
- end
15
- end
16
- end
17
- end