Class: Spree::Price
- Inherits:
-
Object
- Object
- Spree::Price
- Extended by:
- DisplayMoney
- Includes:
- VatPriceCalculation, Webhooks::HasWebhooks
- Defined in:
- app/models/spree/price.rb
Constant Summary collapse
- MAXIMUM_AMOUNT =
BigDecimal('99_999_999.99')
Instance Method Summary collapse
- #amount=(amount) ⇒ Object (also: #price=)
- #compare_at_amount=(value) ⇒ Object (also: #compare_at_price=)
- #compare_at_money ⇒ Object
- #compare_at_price_including_vat_for(price_options) ⇒ Object
-
#discounted? ⇒ Boolean
returns true if the price is discounted.
- #display_compare_at_price_including_vat_for(price_options) ⇒ Object
- #display_price_including_vat_for(price_options) ⇒ Object
- #money ⇒ Object
-
#name ⇒ String
returns the name of the price in a format of variant name and currency.
-
#non_zero? ⇒ Boolean
returns true if the price is not zero.
- #price_including_vat_for(price_options) ⇒ Object
-
#was_discounted? ⇒ Boolean
returns true if the price was discounted.
-
#zero? ⇒ Boolean
returns true if the price is zero.
Methods included from DisplayMoney
Methods included from VatPriceCalculation
Instance Method Details
#amount=(amount) ⇒ Object Also known as: price=
61 62 63 |
# File 'app/models/spree/price.rb', line 61 def amount=(amount) self[:amount] = Spree::LocalizedNumber.parse(amount) end |
#compare_at_amount=(value) ⇒ Object Also known as: compare_at_price=
69 70 71 72 73 |
# File 'app/models/spree/price.rb', line 69 def compare_at_amount=(value) calculated_value = Spree::LocalizedNumber.parse(value) if value.present? self[:compare_at_amount] = calculated_value end |
#compare_at_money ⇒ Object
65 66 67 |
# File 'app/models/spree/price.rb', line 65 def compare_at_money Spree::Money.new(compare_at_amount || 0, currency: currency) end |
#compare_at_price_including_vat_for(price_options) ⇒ Object
85 86 87 88 |
# File 'app/models/spree/price.rb', line 85 def compare_at_price_including_vat_for() = .merge(tax_category: variant.tax_category) gross_amount(compare_at_price, ) end |
#discounted? ⇒ Boolean
returns true if the price is discounted
108 109 110 |
# File 'app/models/spree/price.rb', line 108 def discounted? compare_at_amount.to_i.positive? && compare_at_amount > amount end |
#display_compare_at_price_including_vat_for(price_options) ⇒ Object
94 95 96 |
# File 'app/models/spree/price.rb', line 94 def display_compare_at_price_including_vat_for() Spree::Money.new(compare_at_price_including_vat_for(), currency: currency) end |
#display_price_including_vat_for(price_options) ⇒ Object
90 91 92 |
# File 'app/models/spree/price.rb', line 90 def display_price_including_vat_for() Spree::Money.new(price_including_vat_for(), currency: currency) end |
#money ⇒ Object
57 58 59 |
# File 'app/models/spree/price.rb', line 57 def money Spree::Money.new(amount || 0, currency: currency.upcase) end |
#name ⇒ String
returns the name of the price in a format of variant name and currency
101 102 103 |
# File 'app/models/spree/price.rb', line 101 def name "#{variant.name} - #{currency.upcase}" end |
#non_zero? ⇒ Boolean
returns true if the price is not zero
129 130 131 |
# File 'app/models/spree/price.rb', line 129 def non_zero? !zero? end |
#price_including_vat_for(price_options) ⇒ Object
80 81 82 83 |
# File 'app/models/spree/price.rb', line 80 def price_including_vat_for() = .merge(tax_category: variant.tax_category) gross_amount(price, ) end |
#was_discounted? ⇒ Boolean
returns true if the price was discounted
115 116 117 |
# File 'app/models/spree/price.rb', line 115 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
122 123 124 |
# File 'app/models/spree/price.rb', line 122 def zero? amount.nil? || amount.zero? end |