Class: Spree::VolumePrice

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/spree/volume_price.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_variant(variant, user: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/spree/volume_price.rb', line 19

def self.for_variant(variant, user: nil)
  roles = [nil]
  user&.spree_roles&.each { |r| roles << r.id }

  where(
    arel_table[:variant_id].eq(variant.id).
    or(
      arel_table[:volume_price_model_id].in(variant.volume_price_model_ids)
    )
  ).
    where(role_id: roles).
    order(position: :asc, amount: :asc)
end

Instance Method Details

#display_rangeObject



35
36
37
# File 'app/models/spree/volume_price.rb', line 35

def display_range
  range.gsub(/\.+/, "-").gsub(/\(|\)/, '')
end