spree 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of spree might be problematic. Click here for more details.
- data/app/models/product.rb +9 -0
- data/app/models/product_group.rb +1 -1
- data/config/environment.rb +1 -1
- data/lib/scopes/product.rb +17 -17
- data/lib/spree.rb +1 -1
- metadata +4 -4
data/app/models/product.rb
CHANGED
@@ -60,6 +60,15 @@ class Product < ActiveRecord::Base
|
|
60
60
|
|
61
61
|
alias :options :product_option_types
|
62
62
|
|
63
|
+
cattr_accessor :search_scopes do
|
64
|
+
[]
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.add_search_scope(name, &block)
|
68
|
+
self.named_scope name.intern, &block
|
69
|
+
search_scopes << name.intern
|
70
|
+
end
|
71
|
+
|
63
72
|
include ::Scopes::Product
|
64
73
|
|
65
74
|
# default product scope only lists available and non-deleted products
|
data/app/models/product_group.rb
CHANGED
@@ -90,7 +90,7 @@ class ProductGroup < ActiveRecord::Base
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def add_scope(scope_name, arguments=[])
|
93
|
-
if scope_name.
|
93
|
+
if Product.search_scopes.include?(scope_name.intern)
|
94
94
|
self.product_scopes << ProductScope.new({
|
95
95
|
:name => scope_name.to_s,
|
96
96
|
:arguments => [*arguments]
|
data/config/environment.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# ENV['RAILS_ENV'] ||= 'production'
|
6
6
|
|
7
7
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
8
|
-
SPREE_GEM_VERSION = '0.11.
|
8
|
+
SPREE_GEM_VERSION = '0.11.4' unless defined? SPREE_GEM_VERSION
|
9
9
|
|
10
10
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
11
11
|
require File.join(File.dirname(__FILE__), 'boot')
|
data/lib/scopes/product.rb
CHANGED
@@ -40,23 +40,23 @@ module Scopes::Product
|
|
40
40
|
]
|
41
41
|
|
42
42
|
# default product scope only lists available and non-deleted products
|
43
|
-
::Product.
|
43
|
+
::Product.add_search_scope :active, lambda { |*args|
|
44
44
|
Product.not_deleted.available(args.first).scope(:find)
|
45
45
|
}
|
46
46
|
|
47
|
-
::Product.
|
47
|
+
::Product.add_search_scope :not_deleted, {
|
48
48
|
:conditions => "products.deleted_at is null"
|
49
49
|
}
|
50
|
-
::Product.
|
50
|
+
::Product.add_search_scope :available, lambda { |*args|
|
51
51
|
{ :conditions => ["products.available_on <= ?", args.first || Time.zone.now] }
|
52
52
|
}
|
53
53
|
|
54
|
-
::Product.
|
54
|
+
::Product.add_search_scope :keywords, lambda{|query|
|
55
55
|
return {} if query.blank?
|
56
56
|
Spree::Config.searcher.get_products_conditions_for(query)
|
57
57
|
}
|
58
58
|
|
59
|
-
::Product.
|
59
|
+
::Product.add_search_scope :price_between, lambda {|low,high|
|
60
60
|
{ :joins => :master, :conditions => ["variants.price BETWEEN ? AND ?", low, high] }
|
61
61
|
}
|
62
62
|
|
@@ -65,7 +65,7 @@ module Scopes::Product
|
|
65
65
|
#
|
66
66
|
# Product.taxons_id_eq(x)
|
67
67
|
#
|
68
|
-
Product.
|
68
|
+
Product.add_search_scope :in_taxon, lambda {|taxon|
|
69
69
|
Product.in_taxons(taxon).scope :find
|
70
70
|
}
|
71
71
|
|
@@ -74,13 +74,13 @@ module Scopes::Product
|
|
74
74
|
#
|
75
75
|
# Product.taxons_id_eq([x,y])
|
76
76
|
#
|
77
|
-
Product.
|
77
|
+
Product.add_search_scope :in_taxons, lambda {|*taxons|
|
78
78
|
taxons = get_taxons(taxons)
|
79
79
|
taxons.first ? prepare_taxon_conditions(taxons) : {}
|
80
80
|
}
|
81
81
|
|
82
82
|
# for quick access to products in a group, WITHOUT using the association mechanism
|
83
|
-
Product.
|
83
|
+
Product.add_search_scope :in_cached_group, lambda {|product_group|
|
84
84
|
{ :joins => "JOIN product_groups_products ON products.id = product_groups_products.product_id",
|
85
85
|
:conditions => ["product_groups_products.product_group_id = ?", product_group]
|
86
86
|
}
|
@@ -88,7 +88,7 @@ module Scopes::Product
|
|
88
88
|
|
89
89
|
|
90
90
|
# a scope that finds all products having property specified by name, object or id
|
91
|
-
Product.
|
91
|
+
Product.add_search_scope :with_property, lambda {|property|
|
92
92
|
conditions = case property
|
93
93
|
when String then ["properties.name = ?", property]
|
94
94
|
when Property then ["properties.id = ?", property.id]
|
@@ -102,7 +102,7 @@ module Scopes::Product
|
|
102
102
|
}
|
103
103
|
|
104
104
|
# a scope that finds all products having an option_type specified by name, object or id
|
105
|
-
Product.
|
105
|
+
Product.add_search_scope :with_option, lambda {|option|
|
106
106
|
conditions = case option
|
107
107
|
when String then ["option_types.name = ?", option]
|
108
108
|
when OptionType then ["option_types.id = ?", option.id]
|
@@ -117,7 +117,7 @@ module Scopes::Product
|
|
117
117
|
|
118
118
|
# a simple test for product with a certain property-value pairing
|
119
119
|
# note that it can test for properties with NULL values, but not for absent values
|
120
|
-
Product.
|
120
|
+
Product.add_search_scope :with_property_value, lambda { |property, value|
|
121
121
|
conditions = case property
|
122
122
|
when String then ["properties.name = ?", property]
|
123
123
|
when Property then ["properties.id = ?", property.id]
|
@@ -132,7 +132,7 @@ module Scopes::Product
|
|
132
132
|
}
|
133
133
|
|
134
134
|
# a scope that finds all products having an option value specified by name, object or id
|
135
|
-
Product.
|
135
|
+
Product.add_search_scope :with_option_value, lambda {|option, value|
|
136
136
|
option_type_id = case option
|
137
137
|
when String
|
138
138
|
option_type = OptionType.find_by_name(option) || option.to_i
|
@@ -153,7 +153,7 @@ module Scopes::Product
|
|
153
153
|
}
|
154
154
|
|
155
155
|
# finds product having option value OR product_property
|
156
|
-
Product.
|
156
|
+
Product.add_search_scope :with, lambda{|value|
|
157
157
|
{
|
158
158
|
:conditions => ["option_values.name = ? OR product_properties.value = ?", value, value],
|
159
159
|
:joins => {:variants => :option_values, :product_properties => []}
|
@@ -178,7 +178,7 @@ module Scopes::Product
|
|
178
178
|
# there is alternative faster and more elegant solution, it has small drawback though,
|
179
179
|
# it doesn stack with other scopes :/
|
180
180
|
#
|
181
|
-
Product.
|
181
|
+
Product.add_search_scope :descend_by_popularity, lambda{
|
182
182
|
# :joins => "LEFT OUTER JOIN (SELECT line_items.variant_id as vid, COUNT(*) as cnt FROM line_items GROUP BY line_items.variant_id) AS popularity_count ON variants.id = vid",
|
183
183
|
# :order => 'COALESCE(cnt, 0) DESC'
|
184
184
|
{
|
@@ -201,7 +201,7 @@ SQL
|
|
201
201
|
}
|
202
202
|
|
203
203
|
# Produce an array of keywords for use in scopes. Always return array with at least an empty string to avoid SQL errors
|
204
|
-
def
|
204
|
+
def Product.prepare_words(words)
|
205
205
|
a = words.split(/[,\s]/).map(&:strip)
|
206
206
|
a.any? ? a : ['']
|
207
207
|
end
|
@@ -212,7 +212,7 @@ SQL
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
|
-
def
|
215
|
+
def Product.get_taxons(*ids_or_records_or_names)
|
216
216
|
ids_or_records_or_names.flatten.map { |t|
|
217
217
|
case t
|
218
218
|
when Integer then Taxon.find_by_id(t)
|
@@ -227,7 +227,7 @@ SQL
|
|
227
227
|
end
|
228
228
|
|
229
229
|
# specifically avoid having an order for taxon search (conflicts with main order)
|
230
|
-
def
|
230
|
+
def Product.prepare_taxon_conditions(taxons)
|
231
231
|
conditions = taxons.map{|taxon|
|
232
232
|
taxon.self_and_descendants.scope(:find)[:conditions]
|
233
233
|
}.inject([[]]){|result, scope|
|
data/lib/spree.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 11
|
9
|
-
-
|
10
|
-
version: 0.11.
|
9
|
+
- 4
|
10
|
+
version: 0.11.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sean Schofield
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-07-05 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|