Class: Spree::Price
- Inherits:
-
Object
- Object
- Spree::Price
- 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
- #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=
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_money ⇒ Object
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() = .merge(tax_category: variant.tax_category) gross_amount(compare_at_price, ) end |
#discounted? ⇒ Boolean
returns true if the price is discounted
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() Spree::Money.new(compare_at_price_including_vat_for(), 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() Spree::Money.new(price_including_vat_for(), currency: currency) end |
#money ⇒ Object
59 60 61 |
# File 'app/models/spree/price.rb', line 59 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
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
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() = .merge(tax_category: variant.tax_category) gross_amount(price, ) end |
#was_discounted? ⇒ Boolean
returns true if the price was discounted
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
124 125 126 |
# File 'app/models/spree/price.rb', line 124 def zero? amount.nil? || amount.zero? end |