Sha256: 4dd7776d1525396aa8eb1d8df10a185685a6b051ae2584c972a7e141abdcd739

Contents?: true

Size: 578 Bytes

Versions: 7

Compression:

Stored size: 578 Bytes

Contents

module Spree
  module MultiStoreResource
    extend ActiveSupport::Concern

    included do
      scope :for_store, ->(store) { joins(:stores).where(Store.table_name => { id: store.id }) }

      validate :must_have_one_store, unless: :disable_store_presence_validation?
    end

    protected

    def must_have_one_store
      return if stores.any?

      errors.add(:stores, Spree.t(:must_have_one_store))
    end

    # this can be overriden on model basis
    def disable_store_presence_validation?
      Spree::Config[:disable_store_presence_validation]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spree_core-4.3.3 app/models/concerns/spree/multi_store_resource.rb
spree_core-4.3.2 app/models/concerns/spree/multi_store_resource.rb
spree_core-4.3.1 app/models/concerns/spree/multi_store_resource.rb
spree_core-4.3.0 app/models/concerns/spree/multi_store_resource.rb
spree_core-4.3.0.rc3 app/models/concerns/spree/multi_store_resource.rb
spree_core-4.3.0.rc2 app/models/concerns/spree/multi_store_resource.rb
spree_core-4.3.0.rc1 app/models/concerns/spree/multi_store_resource.rb