在我的实习期间,我需要在rails项目上使用现有的ruby.这个项目是用狂欢建造的.在我调整价格过滤器之前的开发人员,以便范围将变为该分类单元产品的最大值.这里的代码是"lib/spree/core/product_filter.rb"
Spree::Product.add_search_scope :price_range_any do |*opts|
opts_arr, max_prod, min_prod = [], nil, nil
opts.each do |opt|
tmp_arr = opt.split("+")
opts_arr << tmp_arr[0]
max_prod = tmp_arr[1]
min_prod = tmp_arr[2]
end
conds = opts_arr.map {|o| Spree::Core::ProductFilters.price_filter(max_prod.to_i, min_prod.to_i)[:conds][o]}.reject { |c| c.nil? }
scope = conds.shift
conds.each do |new_scope|
scope = scope.or(new_scope)
end
Spree::Product.joins(master: :default_price).where(scope)
end
def ProductFilters.format_price(amount)
Spree::Money.new(amount)
end
def ProductFilters.price_filter(max_price = nil, min_price = nil)
v = Spree::Price.arel_table
if max_price < 200
if max_price < 100
highest_price = max_price - max_price.modulo(10)
else
highest_price …Run Code Online (Sandbox Code Playgroud)