Sha256: 8dc75a5215779f8de6915b39850da2de67338d33813dd8a064a117b718287e70
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
module Spree class Price < Spree::Base acts_as_paranoid belongs_to :variant, class_name: 'Spree::Variant', inverse_of: :prices, touch: true validate :check_price validates :amount, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true validate :validate_amount_maximum def display_amount money end alias :display_price :display_amount self.whitelisted_ransackable_attributes = ['amount'] def money Spree::Money.new(amount || 0, { currency: currency }) end def price amount end def price=(price) self[:amount] = Spree::LocalizedNumber.parse(price) end # Remove variant default_scope `deleted_at: nil` def variant Spree::Variant.unscoped { super } end private def check_price self.currency ||= Spree::Config[:currency] end def maximum_amount BigDecimal '999999.99' end def validate_amount_maximum if amount && amount > maximum_amount errors.add :amount, I18n.t('errors.messages.less_than_or_equal_to', count: maximum_amount) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spree_core-2.4.10 | app/models/spree/price.rb |