diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index 24ed00ef5c..b68c88eb3e 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -13,7 +13,9 @@ module Spree has_one :enterprise, dependent: :restrict_with_exception has_many :shipments - validates :firstname, :lastname, :address1, :city, :country, presence: true + validates :address1, :city, presence: true + validates :firstname, :lastname, presence: true, unless: -> { :company.present? } + validates :company, presence: true, unless: -> { :firstname.present? || :lastname.present? } validates :zipcode, presence: true, if: :require_zipcode? validate :state_validate diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml new file mode 100644 index 0000000000..3df6a9c050 --- /dev/null +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -0,0 +1,40 @@ +.row + .three.columns.alpha + = bf.label :company, t(:Company_legal_name) + .eight.columns.omega + = bf.text_field :company, { placeholder: t(:legal_name_placeholder) } + +.row + .three.columns.alpha + = bf.label :address1, t(:address) + .eight.columns.omega + = bf.text_field :address1, { placeholder: t(:address_placeholder) } +.row + .alpha.three.columns + = bf.label :address2, t(:address2) + .eight.columns.omega + = bf.text_field :address2 +.row + .three.columns.alpha + = bf.label :city, t(:city) + \/ + = bf.label :zipcode, t(:postcode) + .four.columns + = bf.text_field :city, { placeholder: t(:city_placeholder) } + .four.columns.omega + = bf.text_field :zipcode, { placeholder: t(:postcode_placeholder) } +.row + .three.columns.alpha + = bf.label :state_id, t(:state) + \/ + = bf.label :country_id, t(:country) + .four.columns{ "ng-controller" => "countryCtrl" } + %input.ofn-select2.fullwidth#enterprise_address_attributes_state_id{ name: 'enterprise[address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.address.state_id' } } + .four.columns.omega{ "ng-controller" => "countryCtrl" } + %input.ofn-select2.fullwidth#enterprise_address_attributes_country_id{ name: 'enterprise[address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.address.country_id' } } + +.row + .three.columns.alpha + = bf.label :phone, t(:legal_phone_number) + .eight.columns.omega + = bf.text_field :phone, { placeholder: t(:phone_placeholder) } diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 1bade5b580..db82258376 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -47,3 +47,8 @@ .pad-top %a.button.red{ href: '', ng: {click: 'removeTermsAndConditions()', if: 'Enterprise.terms_and_conditions'} } = t('.remove_terms_and_conditions') + + += f.fields_for :business_address, @enterprise.business_address || @enterprise.build_business_address do |bf| + %legend {{business_address.label}} + = render 'admin/enterprises/form/business_address', bf: bf