spree_zoned 0.5.7 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/admin/zoned.js +2 -0
- data/app/controllers/spree/admin/products_controller_decorator.rb +29 -0
- data/app/controllers/spree/admin/zoned_controller.rb +0 -1
- data/app/controllers/spree/home_controller_decorator.rb +12 -0
- data/app/controllers/spree/products_controller_decorator.rb +12 -0
- data/app/controllers/spree/zoned_controller.rb +0 -1
- data/app/helpers/spree/admin/navigation_helper_decorator.rb +50 -0
- data/app/models/spree/product_decorator.rb +23 -0
- data/app/overrides/add_delfc.rb +6 -0
- data/app/views/spree/admin/zoned/_delfc.html.erb +4 -0
- data/app/views/spree/admin/zoned/_prd_country.html.erb +1 -1
- data/app/views/spree/admin/zoned/setcountry.js.erb +4 -1
- data/app/views/spree/zoned/setcountry.js.erb +1 -0
- data/config/initializers/zoned_init.rb +4 -0
- data/config/locales/de.yml +7 -0
- data/config/locales/en.yml +3 -2
- data/config/routes.rb +1 -0
- data/lib/spree/zoned/search/base.rb +98 -0
- data/spree_zoned.gemspec +1 -1
- metadata +12 -2
@@ -0,0 +1,29 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
ProductsController.class_eval do
|
4
|
+
|
5
|
+
before_filter :filter_countries, :only => :index
|
6
|
+
|
7
|
+
def deletefc
|
8
|
+
country = session[:zoned] && session[:zoned][:prd_country]
|
9
|
+
@product.delfrom country.to_i if country
|
10
|
+
respond_to do |format|
|
11
|
+
format.html { redirect_to collection_url }
|
12
|
+
format.js { render :nothing => true }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def filter_countries
|
19
|
+
country = session[:zoned] && session[:zoned][:prd_country]
|
20
|
+
if country
|
21
|
+
collection # returns immediately if already done
|
22
|
+
newcoll = @collection.select { |p| p.incountry? country.to_i }
|
23
|
+
@collection = newcoll
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Spree
|
2
|
+
HomeController.class_eval do
|
3
|
+
|
4
|
+
def index
|
5
|
+
p = params ? params : {}
|
6
|
+
@searcher = Spree::Config.searcher_class.new(p.merge({zoned_country: (session[:zoned] && session[:zoned][:current_country]) || {}}))
|
7
|
+
@products = @searcher.retrieve_products
|
8
|
+
respond_with(@products)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Spree
|
2
|
+
ProductsController.class_eval do
|
3
|
+
|
4
|
+
def index
|
5
|
+
p = params ? params : {}
|
6
|
+
@searcher = Spree::Config.searcher_class.new(p.merge({zoned_country: (session[:zoned] && session[:zoned][:current_country]) || {}}))
|
7
|
+
@products = @searcher.retrieve_products
|
8
|
+
respond_with(@products)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
NavigationHelper.module_eval do
|
4
|
+
|
5
|
+
def link_to_deletefc(resource, options = {}, html_options={})
|
6
|
+
options.assert_valid_keys(:url, :caption, :title, :dataType, :success, :error, :name)
|
7
|
+
|
8
|
+
options.reverse_merge! :url => object_url(resource) + '/zoneddfc' unless options.key? :url
|
9
|
+
options.reverse_merge! :caption => t(:are_you_sure)
|
10
|
+
options.reverse_merge! :title => t(:confirm_delete)
|
11
|
+
options.reverse_merge! :dataType => 'script'
|
12
|
+
options.reverse_merge! :success => "function(r){ $('##{spree_dom_id resource}').fadeOut('hide'); }"
|
13
|
+
options.reverse_merge! :error => "function(jqXHR, textStatus, errorThrown){ show_flash_error(jqXHR.responseText); }"
|
14
|
+
options.reverse_merge! :name => icon('delete') + ' ' + t(:deletefc)
|
15
|
+
|
16
|
+
link_to_function_deletefc(options, html_options)
|
17
|
+
#link_to_function_delete_native(options, html_options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# this function does not use jConfirm
|
21
|
+
def link_to_function_deletefc_native(options, html_options)
|
22
|
+
fn = %Q{
|
23
|
+
var answer = confirm("#{t(:are_you_sure)}");
|
24
|
+
if (!!answer) { #{link_to_function_deletefc_ajax(options)} };
|
25
|
+
}
|
26
|
+
link_to_function options[:name], fn, html_options
|
27
|
+
end
|
28
|
+
|
29
|
+
def link_to_function_deletefc(options, html_options)
|
30
|
+
link_to_function options[:name], "jConfirm('#{options[:caption]}', '#{options[:title]}', function(r) {
|
31
|
+
if(r){ #{link_to_function_deletefc_ajax(options)} }
|
32
|
+
});", html_options
|
33
|
+
end
|
34
|
+
|
35
|
+
def link_to_function_deletefc_ajax(options)
|
36
|
+
%Q{
|
37
|
+
$.ajax({
|
38
|
+
type: 'POST',
|
39
|
+
url: '#{options[:url]}',
|
40
|
+
data: ({_method: 'delete', authenticity_token: AUTH_TOKEN}),
|
41
|
+
dataType:'#{options[:dataType]}',
|
42
|
+
success: #{options[:success]},
|
43
|
+
error: #{options[:error]}
|
44
|
+
});
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Spree
|
2
|
+
Product.class_eval do
|
3
|
+
|
4
|
+
def incountry?(country)
|
5
|
+
clist = Spree::Zoned::Product.where "spree_product_id = ? AND spree_country_id = ?", id, country
|
6
|
+
clist == [] || clist[0].orderno >= 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def delfrom(country)
|
10
|
+
clist = Spree::Zoned::Product.where "spree_product_id = ? AND spree_country_id = ?", id, country
|
11
|
+
if clist == []
|
12
|
+
zp = Spree::Zoned::Product.new
|
13
|
+
zp.spree_country_id = country
|
14
|
+
zp.spree_product_id = id
|
15
|
+
else
|
16
|
+
zp = clist[0]
|
17
|
+
end
|
18
|
+
zp.orderno = -1
|
19
|
+
zp.save!
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<% selected = ((session[:zoned] && session[:zoned][:prd_country]) || 0) # preselect item "No country selected" %>
|
4
4
|
<%= select_tag 'sel-prd-country',
|
5
5
|
options_for_select( # common countries have negative id
|
6
|
-
[[
|
6
|
+
[[t(:nocountrysel), 0]] +
|
7
7
|
Rails.application.config.commonCountriesForSelect,
|
8
8
|
selected,
|
9
9
|
),
|
@@ -0,0 +1 @@
|
|
1
|
+
location.reload();
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "spree/zoned/search/base"
|
2
|
+
|
1
3
|
#
|
2
4
|
# ZONED_COMMON_COUNTRIES is the list of countries that will be separately listed
|
3
5
|
# in the beginning of the country select box for easy selection.
|
@@ -34,3 +36,5 @@ ZONED_COMMON_LOCALES =
|
|
34
36
|
Rails.configuration.commonCountriesForSelect = ZONED_COMMON_COUNTRIES.map do |id|
|
35
37
|
[ Spree::Country.find_by_id(id).name, -id ]
|
36
38
|
end
|
39
|
+
|
40
|
+
Spree::Config.searcher_class = Spree::Zoned::Search::Base
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Sample localization file for German. Add more files in this directory for other locales.
|
2
|
+
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
+
---
|
4
|
+
de:
|
5
|
+
nocountrysel: "Kein Land ausgewählt"
|
6
|
+
deletefc: "Aus Land löschen"
|
7
|
+
|
data/config/locales/en.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Sample localization file for English. Add more files in this directory for other locales.
|
2
2
|
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
-
|
3
|
+
---
|
4
4
|
en:
|
5
|
-
|
5
|
+
nocountrysel: "No country selected"
|
6
|
+
deletefc: "Delete from country"
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,98 @@
|
|
1
|
+
#
|
2
|
+
# Copied from spree_core-1.1.1/lib/spree/core/search/base.rb
|
3
|
+
#
|
4
|
+
# changes are marked using "{ CHANGE" and "CHANGE }"
|
5
|
+
#
|
6
|
+
|
7
|
+
module Spree
|
8
|
+
module Zoned
|
9
|
+
module Search
|
10
|
+
class Base
|
11
|
+
attr_accessor :properties
|
12
|
+
|
13
|
+
def initialize(params)
|
14
|
+
@properties = {}
|
15
|
+
prepare(params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def retrieve_products
|
19
|
+
@products_scope = get_base_scope
|
20
|
+
curr_page = page || 1
|
21
|
+
|
22
|
+
@products = @products_scope.includes([:master]).page(curr_page).per(per_page)
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(name)
|
26
|
+
if @properties.has_key? name
|
27
|
+
@properties[name]
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
def get_base_scope
|
35
|
+
base_scope = Spree::Product.active
|
36
|
+
#
|
37
|
+
# Add scope for filtering products accoding to country setting of the spree_zoned extension
|
38
|
+
# { CHANGE
|
39
|
+
country = @properties[:zoned_country]
|
40
|
+
base_scope = base_scope.joins(
|
41
|
+
'LEFT OUTER JOIN spree_zoned_products ON spree_zoned_products.spree_product_id = spree_products.id' +
|
42
|
+
" AND spree_zoned_products.spree_country_id = #{country}").where(
|
43
|
+
'(spree_zoned_products.orderno IS NULL OR spree_zoned_products.orderno >= 0)') if country
|
44
|
+
# CHANGE }
|
45
|
+
base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
|
46
|
+
base_scope = get_products_conditions_for(base_scope, keywords) unless keywords.blank?
|
47
|
+
base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
|
48
|
+
base_scope = add_search_scopes(base_scope)
|
49
|
+
base_scope
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_search_scopes(base_scope)
|
53
|
+
search.each do |name, scope_attribute|
|
54
|
+
next if name.to_s =~ /eval|send|system/
|
55
|
+
|
56
|
+
scope_name = name.intern
|
57
|
+
if base_scope.respond_to? scope_name
|
58
|
+
base_scope = base_scope.send(scope_name, *scope_attribute)
|
59
|
+
else
|
60
|
+
base_scope = base_scope.merge(Spree::Product.search({scope_name => scope_attribute}).result)
|
61
|
+
end
|
62
|
+
end if search
|
63
|
+
base_scope
|
64
|
+
end
|
65
|
+
|
66
|
+
# method should return new scope based on base_scope
|
67
|
+
def get_products_conditions_for(base_scope, query)
|
68
|
+
base_scope.like_any([:name, :description], query.split)
|
69
|
+
end
|
70
|
+
|
71
|
+
def prepare(params)
|
72
|
+
@properties[:taxon] = params[:taxon].blank? ? nil : Spree::Taxon.find(params[:taxon])
|
73
|
+
@properties[:keywords] = params[:keywords]
|
74
|
+
@properties[:search] = params[:search]
|
75
|
+
|
76
|
+
per_page = params[:per_page].to_i
|
77
|
+
@properties[:per_page] = per_page > 0 ? per_page : Spree::Config[:products_per_page]
|
78
|
+
@properties[:page] = (params[:page].to_i <= 0) ? 1 : params[:page].to_i
|
79
|
+
# { CHANGE
|
80
|
+
@properties[:zoned_country] = params[:zoned_country]
|
81
|
+
# CHANGE }
|
82
|
+
|
83
|
+
# if !params[:order_by_price].blank?
|
84
|
+
# @product_group = Spree::ProductGroup.new.from_route([params[:order_by_price] + '_by_master_price'])
|
85
|
+
# elsif params[:product_group_name]
|
86
|
+
# @cached_product_group = Spree::ProductGroup.find_by_permalink(params[:product_group_name])
|
87
|
+
# @product_group = Spree::ProductGroup.new
|
88
|
+
# elsif params[:product_group_query]
|
89
|
+
# @product_group = Spree::ProductGroup.new.from_route(params[:product_group_query].split('/'))
|
90
|
+
# else
|
91
|
+
# @product_group = Spree::ProductGroup.new
|
92
|
+
# end
|
93
|
+
# @product_group = @product_group.from_search(params[:search]) if params[:search]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/spree_zoned.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.platform = Gem::Platform::RUBY
|
4
4
|
s.name = 'spree_zoned'
|
5
|
-
s.version = '0.5.
|
5
|
+
s.version = '0.5.8'
|
6
6
|
s.summary = 'A Spree extension to make your store zoned'
|
7
7
|
s.description = "Everything you need for a zoned Spree store: zoned pricing, zoned products, zoned product ordering, zoned locales, ...\nProbalbly essential to you if you operate outside of the US."
|
8
8
|
s.required_ruby_version = '>= 1.9.2'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_zoned
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spree_core
|
@@ -129,22 +129,32 @@ files:
|
|
129
129
|
- app/assets/javascripts/store/spree_zoned.js
|
130
130
|
- app/assets/stylesheets/admin/spree_zoned.css
|
131
131
|
- app/assets/stylesheets/store/spree_zoned.css
|
132
|
+
- app/controllers/spree/admin/products_controller_decorator.rb
|
132
133
|
- app/controllers/spree/admin/zoned_controller.rb
|
134
|
+
- app/controllers/spree/home_controller_decorator.rb
|
135
|
+
- app/controllers/spree/products_controller_decorator.rb
|
133
136
|
- app/controllers/spree/zoned_controller.rb
|
137
|
+
- app/helpers/spree/admin/navigation_helper_decorator.rb
|
134
138
|
- app/helpers/spree/base_helper_decorator.rb
|
139
|
+
- app/models/spree/product_decorator.rb
|
135
140
|
- app/models/spree/zoned/product.rb
|
136
141
|
- app/overrides/add_country_selectbox.rb
|
142
|
+
- app/overrides/add_delfc.rb
|
137
143
|
- app/overrides/add_js_prd_index.rb
|
138
144
|
- app/overrides/add_prd_country.rb
|
139
145
|
- app/overrides/add_prd_handles.rb
|
146
|
+
- app/views/spree/admin/zoned/_delfc.html.erb
|
140
147
|
- app/views/spree/admin/zoned/_prd_country.html.erb
|
141
148
|
- app/views/spree/admin/zoned/setcountry.js.erb
|
142
149
|
- app/views/spree/zoned/_countryselect.html.erb
|
150
|
+
- app/views/spree/zoned/setcountry.js.erb
|
143
151
|
- config/initializers/zoned_init.rb
|
152
|
+
- config/locales/de.yml
|
144
153
|
- config/locales/en.yml
|
145
154
|
- config/routes.rb
|
146
155
|
- db/migrate/20120611133806_create_spree_zoned_products.rb
|
147
156
|
- lib/generators/spree_zoned/install/install_generator.rb
|
157
|
+
- lib/spree/zoned/search/base.rb
|
148
158
|
- lib/spree_zoned.rb
|
149
159
|
- lib/spree_zoned/engine.rb
|
150
160
|
- script/rails
|