Sha256: 7b3920370ecaf09b2434960e2df92e16cc72442b16b52ee7ebceb8aa573c6d3f

Contents?: true

Size: 859 Bytes

Versions: 5

Compression:

Stored size: 859 Bytes

Contents

module Spree
  class WishedItem < Spree::Base
    if defined?(Spree::Webhooks::HasWebhooks)
      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

5 entries across 5 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/models/spree/wished_item.rb
spree_core-4.10.0 app/models/spree/wished_item.rb
spree_core-4.9.0 app/models/spree/wished_item.rb
spree_core-4.8.3 app/models/spree/wished_item.rb
spree_core-4.8.2 app/models/spree/wished_item.rb