Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix created customer address not saving (#7327)

Tomasz Szymański2bc43e868bbd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 668331446b..6344fce65b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -72,6 +72,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Introduce `calculate_order_line_total` plugin method
- Raise ValidationError when refund cannot be performed - #7260 by @IKarbowiak
- Extend order with origin and original order values - #7326 by @IKarbowiak
+- Fix customer addresses missing after customer creation - #7327 by @tomaszszymanski129
### Breaking
- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysocki
diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.py
index 42cb9a23b7..52e9341f8b 100644
--- a/saleor/graphql/account/mutations/base.py
+++ b/saleor/graphql/account/mutations/base.py
@@ -456,7 +456,6 @@ class BaseCustomerCreate(ModelMutation, I18nMixin):
@classmethod
@transaction.atomic
def save(cls, info, instance, cleaned_input):
- # FIXME: save address in user.addresses as well
default_shipping_address = cleaned_input.get(SHIPPING_ADDRESS_FIELD)
if default_shipping_address:
default_shipping_address = info.context.plugins.change_user_address(
@@ -474,6 +473,10 @@ class BaseCustomerCreate(ModelMutation, I18nMixin):
is_creation = instance.pk is None
super().save(info, instance, cleaned_input)
+ if default_billing_address:
+ instance.addresses.add(default_billing_address)
+ if default_shipping_address:
+ instance.addresses.add(default_shipping_address)
# The instance is a new object in db, create an event
if is_creation:
diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.py
index 473aa4e54b..f75d49a595 100644
--- a/saleor/graphql/account/tests/test_account.py
+++ b/saleor/graphql/account/tests/test_account.py
@@ -1171,6 +1171,7 @@ def test_customer_create(
channel_slug=channel_PLN.slug,
)
+ assert set([shipping_address, billing_address]) == set(new_user.addresses.all())
customer_creation_event = account_events.CustomerEvent.objects.get()
assert customer_creation_event.type == account_events.CustomerEvents.ACCOUNT_CREATED
assert customer_creation_event.user == new_customer