Class: Spree::Price

Inherits:
Object
  • Object
show all
Extended by:
DisplayMoney
Includes:
VatPriceCalculation
Defined in:
app/models/spree/price.rb

Constant Summary collapse

MAXIMUM_AMOUNT =
BigDecimal('99_999_999.99')

Instance Method Summary collapse

Methods included from DisplayMoney

money_methods

Methods included from VatPriceCalculation

#gross_amount

Instance Method Details

#amount=(amount) ⇒ Object Also known as: price=



63
64
65
# File 'app/models/spree/price.rb', line 63

def amount=(amount)
  self[:amount] = amount.blank? ? nil : Spree::LocalizedNumber.parse(amount)
end

#compare_at_amount=(value) ⇒ Object Also known as: compare_at_price=



71
72
73
74
75
# File 'app/models/spree/price.rb', line 71

def compare_at_amount=(value)
  calculated_value = Spree::LocalizedNumber.parse(value) if value.present?

  self[:compare_at_amount] = calculated_value
end

#compare_at_moneyObject



67
68
69
# File 'app/models/spree/price.rb', line 67

def compare_at_money
  Spree::Money.new(compare_at_amount || 0, currency: currency)
end

#compare_at_price_including_vat_for(price_options) ⇒ Object



87
88
89
90
# File 'app/models/spree/price.rb', line 87

def compare_at_price_including_vat_for(price_options)
  options = price_options.merge(tax_category: variant.tax_category)
  gross_amount(compare_at_price, options)
end

#discounted?Boolean

returns true if the price is discounted

Returns:

  • (Boolean)


110
111
112
# File 'app/models/spree/price.rb', line 110

def discounted?
  compare_at_amount.to_i.positive? && compare_at_amount > amount
end

#display_compare_at_price_including_vat_for(price_options) ⇒ Object



96
97
98
# File 'app/models/spree/price.rb', line 96

def display_compare_at_price_including_vat_for(price_options)
  Spree::Money.new(compare_at_price_including_vat_for(price_options), currency: currency)
end

#display_price_including_vat_for(price_options) ⇒ Object



92
93
94
# File 'app/models/spree/price.rb', line 92

def display_price_including_vat_for(price_options)
  Spree::Money.new(price_including_vat_for(price_options), currency: currency)
end

#moneyObject



59
60
61
# File 'app/models/spree/price.rb', line 59

def money
  Spree::Money.new(amount || 0, currency: currency.upcase)
end

#nameString

returns the name of the price in a format of variant name and currency

Returns:

  • (String)


103
104
105
# File 'app/models/spree/price.rb', line 103

def name
  "#{variant.name} - #{currency.upcase}"
end

#non_zero?Boolean

returns true if the price is not zero

Returns:

  • (Boolean)


131
132
133
# File 'app/models/spree/price.rb', line 131

def non_zero?
  !zero?
end

#price_including_vat_for(price_options) ⇒ Object



82
83
84
85
# File 'app/models/spree/price.rb', line 82

def price_including_vat_for(price_options)
  options = price_options.merge(tax_category: variant.tax_category)
  gross_amount(price, options)
end

#was_discounted?Boolean

returns true if the price was discounted

Returns:

  • (Boolean)


117
118
119
# File 'app/models/spree/price.rb', line 117

def was_discounted?
  compare_at_amount_was.to_i.positive? && compare_at_amount_was > amount_was
end

#zero?Boolean

returns true if the price is zero

Returns:

  • (Boolean)


124
125
126
# File 'app/models/spree/price.rb', line 124

def zero?
  amount.nil? || amount.zero?
end