mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-04 07:09:14 +00:00
Edit customer address with first name and last name
This commit is contained in:
@@ -11,6 +11,18 @@
|
||||
%table.no-borders
|
||||
%tr
|
||||
%td{style: 'width: 30%'}
|
||||
= t('spree.firstname')
|
||||
%span.required *
|
||||
%td
|
||||
%input{ type: 'text', name: 'firstname', required: true, ng: { model: 'address.firstname'} }
|
||||
%tr
|
||||
%td
|
||||
= t('spree.lastname')
|
||||
%span.required *
|
||||
%td
|
||||
%input{ type: 'text', name: 'lastname', required: true, ng: { model: 'address.lastname'} }
|
||||
%tr
|
||||
%td
|
||||
= t('spree.street_address')
|
||||
%span.required *
|
||||
%td
|
||||
|
||||
@@ -16,7 +16,6 @@ class Customer < ActiveRecord::Base
|
||||
|
||||
before_validation :downcase_email
|
||||
before_validation :empty_code
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true }
|
||||
validates :email, presence: true, uniqueness: { scope: :enterprise_id, message: I18n.t('validation_msg_is_associated_with_an_exising_customer') }
|
||||
@@ -36,11 +35,6 @@ class Customer < ActiveRecord::Base
|
||||
self.code = nil if code.blank?
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
bill_address.firstname = bill_address.lastname = 'unused' if bill_address.present?
|
||||
ship_address.firstname = ship_address.lastname = 'unused' if ship_address.present?
|
||||
end
|
||||
|
||||
def associate_user
|
||||
self.user = user || Spree::User.find_by_email(email)
|
||||
end
|
||||
|
||||
@@ -8,6 +8,10 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer
|
||||
object.tag_list.join(",")
|
||||
end
|
||||
|
||||
def name
|
||||
object.name.blank? ? object.bill_address.andand.full_name : object.name
|
||||
end
|
||||
|
||||
def tags
|
||||
object.tag_list.map do |tag|
|
||||
tag_rule_map = options[:tag_rule_mapping][tag]
|
||||
|
||||
@@ -176,6 +176,8 @@ feature 'Customers' do
|
||||
first('#ship-address-link').click
|
||||
expect(page).to have_content 'Edit Shipping Address'
|
||||
|
||||
fill_in 'firstname', with: "First"
|
||||
fill_in 'lastname', with: "Last"
|
||||
fill_in 'address1', with: "New Address1"
|
||||
fill_in 'phone', with: "12345678"
|
||||
fill_in 'city', with: "Melbourne"
|
||||
@@ -190,6 +192,8 @@ feature 'Customers' do
|
||||
|
||||
ship_address = customer4.reload.ship_address
|
||||
|
||||
expect(ship_address.firstname).to eq 'First'
|
||||
expect(ship_address.lastname).to eq 'Last'
|
||||
expect(ship_address.address1).to eq 'New Address1'
|
||||
expect(ship_address.phone).to eq '12345678'
|
||||
expect(ship_address.city).to eq 'Melbourne'
|
||||
|
||||
@@ -24,7 +24,9 @@ describe Customer, type: :model do
|
||||
it 'updates the shipping address' do
|
||||
expect(customer.shipping_address).to be_nil
|
||||
|
||||
ship_address = {zipcode: "3127",
|
||||
ship_address = {firstname: 'fname',
|
||||
lastname: 'lname',
|
||||
zipcode: "3127",
|
||||
city: "Melbourne",
|
||||
state_id: 1,
|
||||
phone: "455500146",
|
||||
@@ -33,8 +35,8 @@ describe Customer, type: :model do
|
||||
customer.update_attributes!(ship_address_attributes: ship_address)
|
||||
|
||||
expect(customer.ship_address.city).to eq 'Melbourne'
|
||||
expect(customer.ship_address.firstname).to eq 'unused'
|
||||
expect(customer.ship_address.lastname).to eq 'unused'
|
||||
expect(customer.ship_address.firstname).to eq 'fname'
|
||||
expect(customer.ship_address.lastname).to eq 'lname'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user