Skip to content

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

fix `draftOrderCreate` mutation to save `shipping_method_name` (#10822)

Piotr Zabieglikc428b47bddc5
diff --git a/saleor/graphql/order/mutations/draft_order_create.py b/saleor/graphql/order/mutations/draft_order_create.py
index 9a52d3d699..0c98d89c17 100644
--- a/saleor/graphql/order/mutations/draft_order_create.py
+++ b/saleor/graphql/order/mutations/draft_order_create.py
@@ -268,7 +268,7 @@ class DraftOrderCreate(ModelMutation, I18nMixin):
raise ValidationError({"redirect_url": error})
@staticmethod
- def _save_addresses(info, instance: models.Order, cleaned_input):
+ def _save_addresses(instance: models.Order, cleaned_input):
shipping_address = cleaned_input.get("shipping_address")
if shipping_address:
shipping_address.save()
@@ -278,6 +278,12 @@ class DraftOrderCreate(ModelMutation, I18nMixin):
billing_address.save()
instance.billing_address = billing_address.get_copy()
+ @staticmethod
+ def _parse_shipping_method_name(instance: models.Order, cleaned_input):
+ shipping_method = cleaned_input.get("shipping_method")
+ if shipping_method:
+ instance.shipping_method_name = shipping_method.name
+
@staticmethod
def _save_lines(info, instance, lines_data, app, site, manager):
if lines_data:
@@ -341,7 +347,10 @@ class DraftOrderCreate(ModelMutation, I18nMixin):
):
with traced_atomic_transaction():
# Process addresses
- cls._save_addresses(info, instance, cleaned_input)
+ cls._save_addresses(instance, cleaned_input)
+
+ # Parse shipping name
+ cls._parse_shipping_method_name(instance, cleaned_input)
# Save any changes create/update the draft
cls._commit_changes(info, instance, cleaned_input, is_new_instance, app)
diff --git a/saleor/graphql/order/mutations/order_update.py b/saleor/graphql/order/mutations/order_update.py
index 6a688e5d0a..b68e0a5bee 100644
--- a/saleor/graphql/order/mutations/order_update.py
+++ b/saleor/graphql/order/mutations/order_update.py
@@ -74,7 +74,7 @@ class OrderUpdate(DraftOrderCreate):
@classmethod
def save(cls, info, instance, cleaned_input):
with traced_atomic_transaction():
- cls._save_addresses(info, instance, cleaned_input)
+ cls._save_addresses(instance, cleaned_input)
if instance.user_email:
user = User.objects.filter(email=instance.user_email).first()
instance.user = user
diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.py
index 8740adc633..2b50f9547c 100644
--- a/saleor/graphql/order/tests/test_order.py
+++ b/saleor/graphql/order/tests/test_order.py
@@ -2536,6 +2536,7 @@ DRAFT_ORDER_CREATE_MUTATION = """
amount
}
}
+ shippingMethodName
}
}
}
@@ -2612,6 +2613,7 @@ def test_draft_order_create(
order = Order.objects.first()
assert order.user == customer_user
assert order.shipping_method == shipping_method
+ assert order.shipping_method_name == shipping_method.name
assert order.billing_address
assert order.shipping_address
assert order.search_vector