Module: SolidusBillingAddress::AddressDecorator
- Defined in:
- app/models/solidus_billing_address/address_decorator.rb
Constant Summary collapse
- BILLING_ONLY_ATTRS =
%w[customer_type personal_tax_code vat_number billing_email einvoicing_code].freeze
Class Method Summary collapse
-
.prepended(base) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
Instance Method Summary collapse
-
#billing? ⇒ Boolean
NOTE: actually, a billing address can be also a shipping address because solidus does not duplicate the records, but it will be ok :).
- #business_customer? ⇒ Boolean
- #private_customer? ⇒ Boolean
- #shipping? ⇒ Boolean
Class Method Details
.prepended(base) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/solidus_billing_address/address_decorator.rb', line 7 def self.prepended(base) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize base.before_validation :normalize_vat_number base.before_validation :normalize_personal_tax_code base.before_validation :normalize_einvoicing_code base.before_validation :normalize_billing_email base.validates :lastname, presence: true # NOTE: solidus does not require its presence, but we do! base.validates :company, presence: true, if: :company_required? base.validates :vat_number, valvat: true, allow_blank: true base.validates :vat_number, presence: true, if: :vat_number_required? base.validates :personal_tax_code, italian_personal_tax_code: { allow_vat_numbers: ->(a) { a.business_customer? } }, allow_blank: true, if: :italian_personal_tax_code_format_required? base.validates :personal_tax_code, presence: true, if: :personal_tax_code_required? base.validates :billing_email, 'spree/email' => true, allow_blank: true base.validates :billing_email, presence: true, if: :billing_email_required? base.validates :einvoicing_code, italian_einvoicing_code: true, allow_blank: true, if: :italian_einvoicing_code_format_required? base.validates :einvoicing_code, presence: true, if: :einvoicing_code_required? end |
Instance Method Details
#billing? ⇒ Boolean
NOTE: actually, a billing address can be also a shipping address because solidus does not duplicate the records, but it will be ok :)
39 40 41 |
# File 'app/models/solidus_billing_address/address_decorator.rb', line 39 def billing? address_type == 'billing' end |
#business_customer? ⇒ Boolean
47 48 49 |
# File 'app/models/solidus_billing_address/address_decorator.rb', line 47 def business_customer? customer_type == 'business' end |
#private_customer? ⇒ Boolean
43 44 45 |
# File 'app/models/solidus_billing_address/address_decorator.rb', line 43 def private_customer? customer_type == 'private' end |
#shipping? ⇒ Boolean
33 34 35 |
# File 'app/models/solidus_billing_address/address_decorator.rb', line 33 def shipping? address_type == 'shipping' end |