spree_multi_domain 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ class Admin::StoresController < Admin::BaseController
2
+ resource_controller
3
+ ssl_required
4
+
5
+ update.wants.html { redirect_to collection_url }
6
+ create.wants.html { redirect_to collection_url }
7
+ destroy.success.wants.js { render_js_for_destroy }
8
+ end
@@ -0,0 +1,10 @@
1
+ class Store < ActiveRecord::Base
2
+ has_and_belongs_to_many :products
3
+ has_many :taxonomies
4
+ has_many :orders
5
+
6
+ validates_presence_of :name, :code, :domains
7
+
8
+ scope :default, where(:default => true)
9
+ scope :by_domain, lambda { |domain| where("domains like ?", "%#{domain}%") }
10
+ end
@@ -0,0 +1 @@
1
+ <th><%= order @search, :by => :store, :as => t("stores") %></th>
@@ -0,0 +1 @@
1
+ <td><%= product.stores.map(&:code).join(", ") unless product.stores.empty? %></td>
@@ -0,0 +1,4 @@
1
+ <p>
2
+ <label><%= t("store") %></label><br />
3
+ <%= f.select :stores_id_equals, Store.all.collect {|s| [s.name, s.id ] }, {:include_blank => true} %></p>
4
+ </p>
@@ -0,0 +1,6 @@
1
+ <p>
2
+ <%= f.label :stores, t("stores")%><br />
3
+ <% Store.all.each do |store| %>
4
+ <%= check_box_tag "product[store_ids][]", store.id, @product.stores.include?(store) %> <%= store.name %>
5
+ <% end %>
6
+ </p>
@@ -0,0 +1,27 @@
1
+ <table>
2
+ <tr>
3
+ <td><label><%=t("name")%></label></td>
4
+ <td><%= text_field :store, :name, {"style" => "width:200px"} %></td>
5
+ </tr>
6
+ <tr>
7
+ <td><label><%=t("code")%></label></td>
8
+ <td><%= text_field :store, :code, {"style" => "width:50px"} %></td>
9
+ </tr>
10
+ <tr>
11
+ <td><label><%= t("default") %></label></td>
12
+ <td>
13
+ <label class="sub">
14
+ <%= radio_button(:store, :default, true ) %>
15
+ <%= t("yes") %>
16
+ </label> &nbsp;
17
+ <label class="sub">
18
+ <%= radio_button(:store, :default, false ) %>
19
+ <%= t("no") %>
20
+ </label>
21
+ </td>
22
+ </tr>
23
+ <tr>
24
+ <td><label><%=t("domains")%></label></td>
25
+ <td><%= text_area :store, :domains, {:cols => 60, :rows => 4} %></td>
26
+ </tr>
27
+ </table>
@@ -0,0 +1,11 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t("editing_store") %></h1>
4
+ <%= error_messages_for :store %>
5
+ <% form_for(@store, :url => object_url, :html => { :method => :put }) do |f| %>
6
+ <%= render :partial => "form", :locals => { :f => f } %>
7
+ <p class="form-buttons">
8
+ <%= button t('update') %>
9
+ <%= t("or") %> <%= link_to t("actions.cancel"), admin_stores_url %>
10
+ </p>
11
+ <% end %>
@@ -0,0 +1,36 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <div class='toolbar'>
4
+ <ul class='actions'>
5
+ <li>
6
+ <%= button_link_to t("new_store"), new_object_url, :icon => 'add' %>
7
+ </li>
8
+ </ul>
9
+ <br class='clear' />
10
+ </div>
11
+
12
+ <h1><%= t("stores") %></h1>
13
+
14
+ <table class="index">
15
+ <thead>
16
+ <th><%= t("name") %></th>
17
+ <th><%= t("code") %></th>
18
+ <th><%= t("domains") %></th>
19
+ <th><%= t("action") %></th>
20
+ </thead>
21
+ <tbody>
22
+ <% @stores.each do |store|%>
23
+ <tr id="<%= dom_id store %>">
24
+ <td width="120px"><%= store.name %></td>
25
+ <td width="80px"><%= store.code %></td>
26
+ <td width="220"><%= store.domains %></td>
27
+ <td width="140px">
28
+ <%= link_to_edit store %> &nbsp;
29
+ <%= link_to_delete store %>
30
+ </td>
31
+ </tr>
32
+ <% end %>
33
+ </tbody>
34
+ </table>
35
+ <%= will_paginate(:previous_label => "&#171; #{t('previous')}", :next_label => "#{t('next')} &#187;") %>
36
+
@@ -0,0 +1,12 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t("new_store") %></h1>
4
+ <%= error_messages_for :store %>
5
+
6
+ <% form_for(:store, :url => collection_url) do |f| %>
7
+ <%= render :partial => "form", :locals => { :f => f } %>
8
+ <p class="form-buttons">
9
+ <%= button t('continue') %>
10
+ <%= t("or") %> <%= link_to t("actions.cancel"), admin_stores_url %>
11
+ </p>
12
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% f.field_container :name do %>
2
+ <%= f.label :name, t("name") %> <span class="required">*</span><br />
3
+ <%= error_message_on :taxonomy, :name, :class => 'fullwidth title' %>
4
+ <%= text_field :taxonomy, :name %>
5
+ <% end %>
6
+
7
+ <p>
8
+ <%= f.label :name, t("store") %> <span class="required">*</span><br />
9
+ <%= collection_select :taxonomy, :store_id, Store.all, :id, :name %>
10
+ </p>
@@ -0,0 +1 @@
1
+ <td><%=tracker.store.name %></td>
@@ -0,0 +1,6 @@
1
+ <tr>
2
+ <td><label><%=t("store")%></label></td>
3
+ <td>
4
+ <%= collection_select(:tracker, :store_id, Store.all, :id, :name, {}) %>
5
+ </td>
6
+ </tr>
@@ -0,0 +1,56 @@
1
+ <% if tracker = Tracker.current %>
2
+
3
+ <script type="text/javascript">
4
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
5
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
6
+ </script>
7
+
8
+ <% if @analytics_page %>
9
+ <script type="text/javascript">document.strTrackPageView="<%= @analytics_page %>";</script>
10
+ <% end %>
11
+
12
+ <!-- Primary Tracking -->
13
+ <script type="text/javascript" src="/javascripts/VKIga.js"></script>
14
+
15
+ <% if flash[:commerce_tracking] %>
16
+ <script type="text/javascript">
17
+
18
+ try {
19
+ // report e-commerce transaction information when applicable
20
+ /*
21
+ * transaction ID - prepend dev/QA sites with 'QA-'
22
+ * affiliate - always empty string
23
+ * total - order total including tax & shipping
24
+ * tax
25
+ * shipping
26
+ * ship-to city
27
+ * ship-to province
28
+ * ship-to country
29
+ */
30
+ VKIPageTracker._addTrans(
31
+ "<%= "#{"QA-" if request.server_name =~ /^(dev.|localhost)/ }#{@order.number}" %>",
32
+ "",
33
+ "<%= @order.total %>",
34
+ "<%= @order.tax_charges.sum(:amount).to_s %>",
35
+ "<%= @order.shipping_charges.sum(:amount).to_s %>",
36
+ "<%= @order.ship_address.city if @order.ship_address %>",
37
+ "<%= @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
+ "<%= @order.ship_address.country.name if @order.ship_address && @order.ship_address.country %>"
39
+ );
40
+ <% @order.line_items.each do |line_item| -%>
41
+ VKIPageTracker._addItem(
42
+ "<%= "#{"QA-" if request.server_name =~ /^(dev.|localhost)/ }#{@order.number}" %>",
43
+ "<%= line_item.variant.sku %>",
44
+ "<%= line_item.variant.product.name %>",
45
+ "-",
46
+ "<%= line_item.price %>",
47
+ "<%= line_item.quantity %>"
48
+ );
49
+ <% end -%>
50
+ VKIPageTracker._trackTrans();
51
+ } catch (err) {
52
+ }
53
+
54
+ </script>
55
+ <% end %>
56
+ <% end %>
@@ -0,0 +1,154 @@
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
+
@@ -0,0 +1,41 @@
1
+ require 'spree_core'
2
+ require 'spree_multi_domain_hooks'
3
+ require 'spree_multi_domain/engine'
4
+
5
+
6
+ # Make it possible to add to existing resource controller hooks with '<<' even when there's no hook of a given type defined yet.
7
+ # e.g. create.before << :assign_to_store
8
+ ResourceController::Accessors.module_eval do
9
+ private
10
+ def block_accessor(*accessors)
11
+ accessors.each do |block_accessor|
12
+ class_eval <<-"end_eval", __FILE__, __LINE__
13
+
14
+ def #{block_accessor}(*args, &block)
15
+ @#{block_accessor} ||= []
16
+ unless args.empty? && block.nil?
17
+ args.push block if block_given?
18
+ @#{block_accessor} = [args].flatten
19
+ end
20
+ @#{block_accessor}
21
+ end
22
+
23
+ end_eval
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ module ActionView::Layouts
30
+
31
+ def find_layout_with_multi_store(layout)
32
+ if respond_to?(:current_store) && current_store && !controller.is_a?(Admin::BaseController)
33
+ layout.gsub!("layouts/", "layouts/#{current_store.code}/")
34
+ end
35
+ find_layout_without_multi_store(layout)
36
+ end
37
+
38
+ alias_method_chain :find_layout, :multi_store
39
+
40
+ end
41
+
@@ -0,0 +1,19 @@
1
+ class SpreeMultiDomainHooks < Spree::ThemeSupport::HookListener
2
+
3
+ insert_after :admin_products_index_headers, :partial => "admin/products/index_headers"
4
+ insert_after :admin_products_index_rows, :partial => "admin/products/index_rows"
5
+ insert_before :admin_products_index_search, :partial => "admin/products/index_search_fields"
6
+
7
+ insert_after :admin_product_form_meta, :partial => "admin/products/stores"
8
+
9
+ insert_after :admin_trackers_index_headers do
10
+ "<th>#{I18n.t(:store)}</th>"
11
+ end
12
+ insert_after :admin_trackers_index_rows, 'admin/trackers/index_rows'
13
+ replace :additional_tracker_fields, 'admin/trackers/store'
14
+
15
+ insert_after :admin_configurations_menu do
16
+ "<%= configurations_menu_item(I18n.t('stores_admin'), admin_stores_url, I18n.t('manage_stores')) %>"
17
+ end
18
+
19
+ end
@@ -0,0 +1,17 @@
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
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_multi_domain
3
+ version: !ruby/object:Gem::Version
4
+ hash: 5
5
+ prerelease: false
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 1
10
+ version: 3.0.1
11
+ platform: ruby
12
+ authors: []
13
+
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-03 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spree_core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: -1848229955
30
+ segments:
31
+ - 0
32
+ - 30
33
+ - 0
34
+ - beta1
35
+ version: 0.30.0.beta1
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ description:
39
+ email:
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - lib/spree_multi_domain/engine.rb
48
+ - lib/spree_multi_domain.rb
49
+ - lib/spree_multi_domain_hooks.rb
50
+ - lib/tasks/site_extension_tasks.rake
51
+ - app/controllers/admin/stores_controller.rb
52
+ - app/models/store.rb
53
+ - app/views/admin/products/_index_headers.html.erb
54
+ - app/views/admin/products/_index_rows.html.erb
55
+ - app/views/admin/products/_index_search_fields.html.erb
56
+ - app/views/admin/products/_stores.html.erb
57
+ - app/views/admin/stores/_form.html.erb
58
+ - app/views/admin/stores/edit.html.erb
59
+ - app/views/admin/stores/index.html.erb
60
+ - app/views/admin/stores/new.html.erb
61
+ - app/views/admin/taxonomies/_form.html.erb
62
+ - app/views/admin/trackers/_index_rows.html.erb
63
+ - app/views/admin/trackers/_store.html.erb
64
+ - app/views/shared/_google_analytics.html.erb
65
+ has_rdoc: true
66
+ homepage:
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 57
80
+ segments:
81
+ - 1
82
+ - 8
83
+ - 7
84
+ version: 1.8.7
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements:
95
+ - none
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Adds multiple site support to Spree
101
+ test_files: []
102
+