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=)
-
#amount_in_cents ⇒ Integer
Returns the amount in cents.
- #compare_at_amount=(value) ⇒ Object (also: #compare_at_price=)
-
#compare_at_amount_in_cents ⇒ Integer?
Returns the compare at amount in cents.
- #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_amount ⇒ Spree::Money?
Returns the compare at amount for display.
- #display_compare_at_price ⇒ Object
- #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
-
#prior_price ⇒ Spree::PriceHistory?
Returns the price history record with the lowest amount in the last 30 days Used for EU Omnibus Directive compliance.
-
#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=
81 82 83 |
# File 'app/models/spree/price.rb', line 81 def amount=(amount) self[:amount] = amount.blank? ? nil : Spree::LocalizedNumber.parse(amount) end |
#amount_in_cents ⇒ Integer
Returns the amount in cents
87 88 89 |
# File 'app/models/spree/price.rb', line 87 def amount_in_cents display_amount&.amount_in_cents end |
#compare_at_amount=(value) ⇒ Object Also known as: compare_at_price=
95 96 97 98 99 |
# File 'app/models/spree/price.rb', line 95 def compare_at_amount=(value) calculated_value = Spree::LocalizedNumber.parse(value) if value.present? self[:compare_at_amount] = calculated_value end |
#compare_at_amount_in_cents ⇒ Integer?
Returns the compare at amount in cents
111 112 113 114 115 |
# File 'app/models/spree/price.rb', line 111 def compare_at_amount_in_cents return nil if compare_at_amount.nil? display_compare_at_amount.amount_in_cents end |
#compare_at_money ⇒ Object
91 92 93 |
# File 'app/models/spree/price.rb', line 91 def compare_at_money Spree::Money.new(compare_at_amount || 0, currency: currency) end |
#compare_at_price_including_vat_for(price_options) ⇒ Object
127 128 129 130 |
# File 'app/models/spree/price.rb', line 127 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
150 151 152 |
# File 'app/models/spree/price.rb', line 150 def discounted? compare_at_amount.to_i.positive? && amount.present? && compare_at_amount > amount end |
#display_compare_at_amount ⇒ Spree::Money?
Returns the compare at amount for display
103 104 105 106 107 |
# File 'app/models/spree/price.rb', line 103 def display_compare_at_amount return nil if compare_at_amount.nil? Spree::Money.new(compare_at_amount, currency: currency) end |
#display_compare_at_price ⇒ Object
56 |
# File 'app/models/spree/price.rb', line 56 alias display_compare_at_price display_compare_at_amount |
#display_compare_at_price_including_vat_for(price_options) ⇒ Object
136 137 138 |
# File 'app/models/spree/price.rb', line 136 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
132 133 134 |
# File 'app/models/spree/price.rb', line 132 def display_price_including_vat_for() Spree::Money.new(price_including_vat_for(), currency: currency) end |
#money ⇒ Object
77 78 79 |
# File 'app/models/spree/price.rb', line 77 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
143 144 145 |
# File 'app/models/spree/price.rb', line 143 def name "#{variant.name} - #{currency.upcase}" end |
#non_zero? ⇒ Boolean
returns true if the price is not zero
171 172 173 |
# File 'app/models/spree/price.rb', line 171 def non_zero? !zero? end |
#price_including_vat_for(price_options) ⇒ Object
122 123 124 125 |
# File 'app/models/spree/price.rb', line 122 def price_including_vat_for() = .merge(tax_category: variant.tax_category) gross_amount(price, ) end |
#prior_price ⇒ Spree::PriceHistory?
Returns the price history record with the lowest amount in the last 30 days Used for EU Omnibus Directive compliance
179 180 181 |
# File 'app/models/spree/price.rb', line 179 def prior_price price_histories.where(recorded_at: 30.days.ago..).order(:amount).first end |
#was_discounted? ⇒ Boolean
returns true if the price was discounted
157 158 159 |
# File 'app/models/spree/price.rb', line 157 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
164 165 166 |
# File 'app/models/spree/price.rb', line 164 def zero? amount.nil? || amount.zero? end |