Sha256: b9f5c3c2f975ef70183dea2b3401665ee7f49a9c02e69a8b596c99925753ce3b

Contents?: true

Size: 850 Bytes

Versions: 87

Compression:

Stored size: 850 Bytes

Contents

module Spree
  class StoreCreditCategory < Spree::Base
    validates :name, presence: true

    before_destroy :validate_not_used

    GIFT_CARD_CATEGORY_NAME = 'Gift Card'.freeze
    DEFAULT_NON_EXPIRING_TYPES = [GIFT_CARD_CATEGORY_NAME]

    def non_expiring?
      non_expiring_category_types.include? name
    end

    def non_expiring_category_types
      DEFAULT_NON_EXPIRING_TYPES | Spree::Config[:non_expiring_credit_types]
    end

    def store_credit_category_used?
      Spree::StoreCredit.exists?(category_id: id)
    end

    def validate_not_used
      if store_credit_category_used?
        errors.add(:base, :cannot_destroy_if_used_in_store_credit)
        throw(:abort)
      end
    end

    class << self
      def default_reimbursement_category(_options = {})
        Spree::StoreCreditCategory.first
      end
    end
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/models/spree/store_credit_category.rb
spree_core-4.1.15 app/models/spree/store_credit_category.rb
spree_core-4.2.7 app/models/spree/store_credit_category.rb
spree_core-4.3.3 app/models/spree/store_credit_category.rb
spree_core-4.2.6 app/models/spree/store_credit_category.rb
spree_core-4.3.2 app/models/spree/store_credit_category.rb
spree_core-4.3.1 app/models/spree/store_credit_category.rb
spree_core-4.3.0 app/models/spree/store_credit_category.rb
spree_core-4.3.0.rc3 app/models/spree/store_credit_category.rb
spree_core-4.3.0.rc2 app/models/spree/store_credit_category.rb
spree_core-4.3.0.rc1 app/models/spree/store_credit_category.rb
spree_core-4.2.5 app/models/spree/store_credit_category.rb
spree_core-4.1.14 app/models/spree/store_credit_category.rb
spree_core-4.0.8 app/models/spree/store_credit_category.rb
spree_core-4.2.4 app/models/spree/store_credit_category.rb
spree_core-3.7.14.1 app/models/spree/store_credit_category.rb
spree_core-4.2.3.1 app/models/spree/store_credit_category.rb
spree_core-4.1.13.1 app/models/spree/store_credit_category.rb
spree_core-4.0.7.1 app/models/spree/store_credit_category.rb
spree_core-4.2.3 app/models/spree/store_credit_category.rb