Sha256: d792e09e1d34e4fb1650bb159fa68aefd01bc8ae09fe73b3e4cd2278a654793c

Contents?: true

Size: 726 Bytes

Versions: 1

Compression:

Stored size: 726 Bytes

Contents

# frozen_string_literal: true

module SolidusTaxCloud
  module Spree
    module ProductDecorator
      def self.prepended(base)
        base.class_eval do
          validates_format_of :tax_cloud_tic, with: /\A\d{5}\z/, message: I18n.t('spree.standard_taxcloud_tic')
        end
      end

      # Use the store-default TaxCloud product TIC if none is defined for this product
      def tax_cloud_tic
        read_attribute(:tax_cloud_tic) || ::Spree::Config.taxcloud_default_product_tic
      end

      # Empty strings are written as nil (which avoids the format validation)
      def tax_cloud_tic=(tic)
        write_attribute(:tax_cloud_tic, tic.presence)
      end

      ::Spree::Product.prepend self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_tax_cloud-1.0.0 app/decorators/models/solidus_tax_cloud/spree/product_decorator.rb