Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Return unmodified cart when trying to duplicate checkout in API
Marcin Gębala32ff918ab3d6
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex 59f8607ecb..e2b82798fb 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -189,7 +189,11 @@ class CheckoutCreate(ModelMutation, I18nMixin):# `mutate` method is overriden to properly get or create a checkout# instance here:if user.is_authenticated:- checkout = get_or_create_user_cart(user)+ checkout, created = get_or_create_user_cart(user)+ # If user has an active checkout, return it without any+ # modifications.+ if not created:+ return CheckoutCreate(checkout=checkout, errors=errors)else:checkout = models.Cart()diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex dd0ec03118..24c978fed1 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -15,9 +15,12 @@ MUTATION_CHECKOUT_CREATE = """mutation createCheckout($checkoutInput: CheckoutCreateInput!) {checkoutCreate(input: $checkoutInput) {checkout {- token,id+ token+ lines {+ quantity+ }}errors {field@@ -82,6 +85,10 @@ def test_checkout_create_reuse_cart(cart, user_api_client, variant):checkout_data = content['data']['checkoutCreate']['checkout']assert checkout_data['token'] == str(cart.token)+ # if checkout was reused it should be returned unmodified (e.g. without+ # adding new lines that was passed)+ assert checkout_data['lines'] == []+def test_checkout_create_required_email(api_client, variant):variant_id = graphene.Node.to_global_id('ProductVariant', variant.id)