我的Spree 3.0商店应用程序中有2个产品属性过滤器
Spree::Product.add_search_scope :gender_any do |*opts|
conds = opts.map {|o| ProductFilters.gender_filter[:conds][o]}.reject { |c| c.nil? }
scope = conds.shift
conds.each do |new_scope|
scope = scope.or(new_scope)
end
Spree::Product.with_property('Пол').where(scope)
end
def ProductFilters.gender_filter
gender_property = Spree::Property.find_by(name: 'Gender')
genders = gender_property ? Spree::ProductProperty.where(property_id: gender_property.id).pluck(:value).uniq.map(&:to_s) : []
pp = Spree::ProductProperty.arel_table
conds = Hash[*genders.map { |b| [b, pp[:value].eq(b)] }.flatten]
{
name: 'Gender',
scope: :gender_any,
conds: conds,
labels: (genders.sort).map { |k| [k, k] }
}
end
Spree::Product.add_search_scope :type_any do |*opts|
conds = opts.map {|o| ProductFilters.type_filter[:conds][o]}.reject { |c| c.nil? }
scope = conds.shift
conds.each do |new_scope|
scope = scope.or(new_scope)
end
Spree::Product.with_property('Type').where(scope)
end
def ProductFilters.type_filter
property = Spree::Property.find_by(name: 'Тип')
values = property ? Spree::ProductProperty.where(property_id: property.id).pluck(:value).uniq.map(&:to_s) : []
pp = Spree::ProductProperty.arel_table
conds = Hash[*values.map { |b| [b, pp[:value].eq(b)] }.flatten]
{
name: 'Type',
scope: :type_any,
conds: conds,
labels: (values.sort).map { |k| [k, k] }
}
end
这是性别和产品类型过滤器。
当过滤器仅使用一个参数时,如下所示:
过滤工作正常。
过滤工作正常。
如果我使用带有2个参数的过滤器:
过滤返回零项。 如何解决这个问题?