Sha256: e1dbc7cadfb5655384da29baea13469f151fa2fe7d14d6e0e40dc24ef404912a
Contents?: true
Size: 921 Bytes
Versions: 14
Compression:
Stored size: 921 Bytes
Contents
module Spree module Products class Sort < ::Spree::BaseSorter def initialize(scope, current_currency, params = {}, allowed_sort_attributes = []) super(scope, params, allowed_sort_attributes) @currency = params[:currency] || current_currency end def call products = by_param_attribute(scope) products = by_price(products) products.distinct end private attr_reader :sort, :scope, :currency, :allowed_sort_attributes def price? sort_field == 'price' end def by_price(scope) return scope unless price? scope.joins(master: :prices). select("#{Spree::Product.table_name}.*, #{Spree::Price.table_name}.amount"). distinct. where(spree_prices: { currency: currency }). order("#{Spree::Price.table_name}.amount #{order_direction}") end end end end
Version data entries
14 entries across 14 versions & 1 rubygems