Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

942 billing to default address #1424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,13 @@ def ship_address_attributes=(attributes)
# @note This doesn't persist the change bill_address or ship_address
def assign_default_user_addresses
if user
bill_address = (user.bill_address || user.default_address)
ship_address = (user.ship_address || user.default_address)
# this is one of 2 places still using User#bill_address
self.bill_address ||= user.bill_address if user.bill_address.try!(:valid?)
self.bill_address ||= bill_address if bill_address.try!(:valid?)
# Skip setting ship address if order doesn't have a delivery checkout step
# to avoid triggering validations on shipping address
self.ship_address ||= user.ship_address if user.ship_address.try!(:valid?) && checkout_steps.include?("delivery")
self.ship_address ||= ship_address if ship_address.try!(:valid?) && checkout_steps.include?("delivery")
end
end

Expand Down
3 changes: 2 additions & 1 deletion core/spec/models/spree/order/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def assert_state_changed(order, from, to)
it_behaves_like "it references the user's the default address" do
let(:address_kind) { :bill }
before do
order.user = FactoryGirl.create(:user, bill_address: default_address)
order.user = FactoryGirl.create(:user)
order.user.default_address = default_address
order.next!
order.reload
end
Expand Down