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=
68 69 70 |
# File 'app/models/spree/price.rb', line 68 def amount=(amount) self[:amount] = amount.blank? ? nil : Spree::LocalizedNumber.parse(amount) end |
#amount_in_cents ⇒ Integer
Returns the amount in cents
74 75 76 |
# File 'app/models/spree/price.rb', line 74 def amount_in_cents display_amount&.amount_in_cents end |
#compare_at_amount=(value) ⇒ Object Also known as: compare_at_price=
82 83 84 85 86 |
# File 'app/models/spree/price.rb', line 82 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
98 99 100 101 102 |
# File 'app/models/spree/price.rb', line 98 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
78 79 80 |
# File 'app/models/spree/price.rb', line 78 def compare_at_money Spree::Money.new(compare_at_amount || 0, currency: currency) end |
#compare_at_price_including_vat_for(price_options) ⇒ Object
114 115 116 117 |
# File 'app/models/spree/price.rb', line 114 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
137 138 139 |
# File 'app/models/spree/price.rb', line 137 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
90 91 92 93 94 |
# File 'app/models/spree/price.rb', line 90 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
123 124 125 |
# File 'app/models/spree/price.rb', line 123 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
119 120 121 |
# File 'app/models/spree/price.rb', line 119 def display_price_including_vat_for() Spree::Money.new(price_including_vat_for(), currency: currency) end |
#money ⇒ Object
64 65 66 |
# File 'app/models/spree/price.rb', line 64 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
130 131 132 |
# File 'app/models/spree/price.rb', line 130 def name "#{variant.name} - #{currency.upcase}" end |
#non_zero? ⇒ Boolean
returns true if the price is not zero
158 159 160 |
# File 'app/models/spree/price.rb', line 158 def non_zero? !zero? end |
#price_including_vat_for(price_options) ⇒ Object
109 110 111 112 |
# File 'app/models/spree/price.rb', line 109 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
166 167 168 |
# File 'app/models/spree/price.rb', line 166 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
144 145 146 |
# File 'app/models/spree/price.rb', line 144 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
151 152 153 |
# File 'app/models/spree/price.rb', line 151 def zero? amount.nil? || amount.zero? end |