Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Always associate Bill/Ship Address created in Admin Panel to User

Damian Legawiec2b341820c451
diff --git a/backend/app/controllers/spree/admin/users_controller.rb b/backend/app/controllers/spree/admin/users_controller.rb
index 92c0f6be72..5e1221cedb 100644
--- a/backend/app/controllers/spree/admin/users_controller.rb
+++ b/backend/app/controllers/spree/admin/users_controller.rb
@@ -35,6 +35,8 @@ module Spree
def addresses
if request.put?
+ params[:user][:bill_address_attributes][:user_id] = @user.id if params[:user][:bill_address_attributes].present?
+ params[:user][:ship_address_attributes][:user_id] = @user.id if params[:user][:ship_address_attributes].present?
if @user.update(user_params)
flash.now[:success] = Spree.t(:account_updated)
end
diff --git a/backend/spec/features/admin/users_spec.rb b/backend/spec/features/admin/users_spec.rb
index 9474e07673..1a848b5b43 100644
--- a/backend/spec/features/admin/users_spec.rb
+++ b/backend/spec/features/admin/users_spec.rb
@@ -166,6 +166,7 @@ describe 'Users', type: :feature do
end
expect(user_a.reload.ship_address.address1).to eq '1313 Mockingbird Ln'
+ expect(user_a.ship_address.user_id).to eq user_a.id
end
it 'can edit user billing address' do
@@ -178,6 +179,7 @@ describe 'Users', type: :feature do
end
expect(user_a.reload.bill_address.address1).to eq '1313 Mockingbird Ln'
+ expect(user_a.bill_address.user_id).to eq user_a.id
end
it 'can set shipping address to be the same as billing address' do