Sha256: bce32618415599395a1b6d455fa0de4df66cac9762871b20f7d648577033a577

Contents?: true

Size: 846 Bytes

Versions: 17

Compression:

Stored size: 846 Bytes

Contents

module Spree
  class WishedItem < Spree::Base
    if defined?(Spree::Webhooks)
      include Spree::Webhooks::HasWebhooks
    end

    extend DisplayMoney
    money_methods :total, :price

    belongs_to :variant, class_name: 'Spree::Variant'
    belongs_to :wishlist, class_name: 'Spree::Wishlist'

    has_one :product, class_name: 'Spree::Product', through: :variant

    validates :variant, :wishlist, presence: true
    validates :variant, uniqueness: { scope: [:wishlist] }
    validates :quantity, numericality: { only_integer: true, greater_than: 0 }

    def price(currency)
      variant.amount_in(currency[:currency])
    end

    def total(currency)
      variant_price = variant.amount_in(currency[:currency])

      if variant_price.nil?
        variant_price
      else
        quantity * variant_price
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
spree_core-4.7.3 app/models/spree/wished_item.rb
spree_core-4.6.6 app/models/spree/wished_item.rb
spree_core-4.5.5 app/models/spree/wished_item.rb
spree_core-4.5.4 app/models/spree/wished_item.rb
spree_core-4.6.5 app/models/spree/wished_item.rb
spree_core-4.7.2 app/models/spree/wished_item.rb
spree_core-4.7.1 app/models/spree/wished_item.rb
spree_core-4.6.4 app/models/spree/wished_item.rb
spree_core-4.7.0 app/models/spree/wished_item.rb
spree_core-4.6.3 app/models/spree/wished_item.rb
spree_core-4.6.2 app/models/spree/wished_item.rb
spree_core-4.6.1 app/models/spree/wished_item.rb
spree_core-4.6.0 app/models/spree/wished_item.rb
spree_core-4.5.3 app/models/spree/wished_item.rb
spree_core-4.5.2 app/models/spree/wished_item.rb
spree_core-4.5.1 app/models/spree/wished_item.rb
spree_core-4.5.0 app/models/spree/wished_item.rb