Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add function to match orders with a new user
Damian Wysockiae05fc5650ad
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.pyindex 11513557c5..da791f27cd 100644--- a/saleor/graphql/account/mutations/account.py+++ b/saleor/graphql/account/mutations/account.py@@ -8,6 +8,7 @@ from ....account.error_codes import AccountErrorCodefrom ....account.utils import create_jwt_token, decode_jwt_tokenfrom ....checkout import AddressTypefrom ....core.utils.url import validate_storefront_url+from ....order.utils import match_orders_with_new_userfrom ...account.enums import AddressTypeEnumfrom ...account.types import Address, AddressInput, Userfrom ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation@@ -88,6 +89,7 @@ class AccountRegister(ModelMutation):emails.send_account_confirmation_email(user, cleaned_input["redirect_url"])else:user.save()+ match_orders_with_new_user(user)account_events.customer_account_created_event(user=user)info.context.extensions.customer_created(customer=user)diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.pyindex 5a0c5ed672..ba3e4e51d6 100644--- a/saleor/graphql/account/mutations/base.py+++ b/saleor/graphql/account/mutations/base.py@@ -13,6 +13,7 @@ from ....account.emails import (from ....account.error_codes import AccountErrorCodefrom ....core.permissions import AccountPermissionsfrom ....core.utils.url import validate_storefront_url+from ....order.utils import match_orders_with_new_userfrom ...account.i18n import I18nMixinfrom ...account.types import Address, AddressInput, Userfrom ...core.mutations import (@@ -186,6 +187,7 @@ class ConfirmAccount(BaseMutation):user.is_active = Trueuser.save(update_fields=["is_active"])+ match_orders_with_new_user(user)return ConfirmAccount()diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 9f3c93c8cd..824f2d1511 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -5,6 +5,7 @@ from django.db import transactionfrom django.utils import timezonefrom prices import Money, TaxedMoney+from ..account.models import Userfrom ..core.taxes import zero_moneyfrom ..core.weight import zero_weightfrom ..discount.models import NotApplicable, Voucher, VoucherType@@ -333,3 +334,8 @@ def get_voucher_discount_for_order(order: Order) -> Money:if order.voucher.type == VoucherType.SPECIFIC_PRODUCT:return get_products_voucher_discount_for_order(order.voucher)raise NotImplementedError("Unknown discount type")+++def match_orders_with_new_user(user: User) -> None:+ """Match Orders with a new user."""+ Order.objects.filter(user_email=user.email, user=None).update(user=user)