core/app/models/concerns/spree/single_store_resource.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module Spree
  module SingleStoreResource
    extend ActiveSupport::Concern

    included do
      validate :ensure_store_association_is_not_changed

      scope :for_store, ->(store) { where(store_id: store.id) }
    end

    protected

    def ensure_store_association_is_not_changed
      if store_id_changed? && persisted?
        errors.add(:store, Spree.t('errors.messages.store_association_can_not_be_changed'))
      end
    end
  end
end