Sha256: c4cc275c476c46dedc4bf0b2866680785cd39072612c5d151cf784b6021180d7
Contents?: true
Size: 913 Bytes
Versions: 6
Compression:
Stored size: 913 Bytes
Contents
module Spree class Price < Spree::Base acts_as_paranoid MAXIMUM_AMOUNT = BigDecimal('99_999_999.99') belongs_to :variant, class_name: 'Spree::Variant', inverse_of: :prices, touch: true validate :check_price validates :amount, allow_nil: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: MAXIMUM_AMOUNT } extend DisplayMoney money_methods :amount, :price 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 end end
Version data entries
6 entries across 6 versions & 1 rubygems