Sha256: 21c85c347a5c0fc91dc503ec27a357aab9026a0483aa40dd27aa663e1ea24faa
Contents?: true
Size: 1016 Bytes
Versions: 3
Compression:
Stored size: 1016 Bytes
Contents
module Spree class Wishlist < Spree::Base include SingleStoreResource if defined?(Spree::Webhooks) include Spree::Webhooks::HasWebhooks end if Rails::VERSION::STRING >= '7.1.0' has_secure_token on: :save else has_secure_token end belongs_to :user, class_name: "::#{Spree.user_class}", touch: true belongs_to :store, class_name: 'Spree::Store' has_many :wished_items, class_name: 'Spree::WishedItem', dependent: :destroy after_commit :ensure_default_exists_and_is_unique validates :name, :store, :user, presence: true def include?(variant_id) wished_items.exists?(variant_id: variant_id) end def to_param token end def self.get_by_param(param) find_by(token: param) end private def ensure_default_exists_and_is_unique if is_default? Wishlist.where(is_default: true, user_id: user_id, store_id: store_id).where.not(id: id).update_all(is_default: false) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
spree_core-4.7.2 | app/models/spree/wishlist.rb |
spree_core-4.7.1 | app/models/spree/wishlist.rb |
spree_core-4.7.0 | app/models/spree/wishlist.rb |