Sha256: dfc99de576400bc6a62fca0dfddb3bd3ef621680b64d6c3ffb733d5de54a3b0a

Contents?: true

Size: 757 Bytes

Versions: 11

Compression:

Stored size: 757 Bytes

Contents

module Spree
  class Store < Spree::Base

    validates :code, presence: true, uniqueness: { allow_blank: true }
    validates :name, presence: true
    validates :url, presence: true
    validates :mail_from_address, presence: true

    before_create :ensure_default_exists_and_is_unique

    scope :by_url, lambda { |url| where("url like ?", "%#{url}%") }

    def self.current(domain = nil)
      current_store = domain ? Store.by_url(domain).first : nil
      current_store || Store.default
    end

    def self.default
      where(default: true).first || new
    end

    private

    def ensure_default_exists_and_is_unique
      if default
        Store.update_all(default: false)
      else
        self.default = true
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_core-2.3.13 app/models/spree/store.rb
spree_core-2.3.12 app/models/spree/store.rb
spree_core-2.3.11 app/models/spree/store.rb
spree_core-2.3.10 app/models/spree/store.rb
spree_core-2.3.9 app/models/spree/store.rb
spree_core-2.3.8 app/models/spree/store.rb
spree_core-2.3.7 app/models/spree/store.rb
spree_core-2.3.6 app/models/spree/store.rb
spree_core-2.4.0 app/models/spree/store.rb
spree_core-2.3.5 app/models/spree/store.rb
spree_core-2.4.0.rc3 app/models/spree/store.rb