Sha256: e4b4b4b26d723f2421fdf730c3df627e72daad2a2da0a57475ba1bcf196e91ab
Contents?: true
Size: 699 Bytes
Versions: 17
Compression:
Stored size: 699 Bytes
Contents
module OrderValidations extend ActiveSupport::Concern prepended do validate :check_tax_id, if: :email_required? before_update :format_tax_id def check_tax_id cnpj_allowed = SolidusBrazilianAdaptations.config.allow_cnpj document = TaxIdBr.new(tax_id) if document.valid? if document.document_type == :cnpj && cnpj_allowed == false errors.add(:base, "Insira um CPF, não um CNPJ.") end else errors.add(:base, "#{cnpj_allowed ? "CPF/CPNJ" : "CPF"} inválido.") end end def format_tax_id document = TaxIdBr.new(tax_id) self.tax_id = document.formatted end end ::Spree::Order.prepend self end
Version data entries
17 entries across 17 versions & 1 rubygems