Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix adding new lines to draft order when existing line has deleted product
SzymJ54270055c393
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 16f66d9a72..ddaf93a2cc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -37,7 +37,7 @@ All notable, unreleased changes to this project will be documented in this file.- Fix sending `product_created` event in `ProductBulkCreate` mutation - #12605 by @SzymJ- Add `ORDER_REFUNDED`, `ORDER_FULLY_REFUNDED`, `ORDER_PAID` webhooks - #12533 by @korycins- Handle error raised by 0Auth when fetching token - #12672 by @IKarbowiakg-+- Fix adding new lines to draft order when existing line has deleted product - #12711 by @SzymJ# 3.13.0diff --git a/saleor/graphql/order/mutations/order_lines_create.py b/saleor/graphql/order/mutations/order_lines_create.pyindex 9c2696c101..140596adda 100644--- a/saleor/graphql/order/mutations/order_lines_create.py+++ b/saleor/graphql/order/mutations/order_lines_create.py@@ -201,7 +201,9 @@ class OrderLinesCreate(EditableOrderValidationMixin, BaseMutation):returnline_info = list(- filter(lambda x: (x.variant.pk == int(variant_id)), lines_info)+ filter(+ lambda x: (x.variant and x.variant.pk == int(variant_id)), lines_info+ ))if not line_info or len(line_info) > 1:diff --git a/saleor/graphql/order/tests/mutations/test_order_lines_create.py b/saleor/graphql/order/tests/mutations/test_order_lines_create.pyindex 2f60f25c75..dc4c74af1d 100644--- a/saleor/graphql/order/tests/mutations/test_order_lines_create.py+++ b/saleor/graphql/order/tests/mutations/test_order_lines_create.py@@ -340,6 +340,38 @@ def test_order_lines_create_with_unavailable_variant(draft_order_updated_webhoook_mock.assert_not_called()[email protected]("status", (OrderStatus.DRAFT, OrderStatus.UNCONFIRMED))+def test_order_lines_create_when_some_line_has_deleted_product(+ status,+ order_with_lines,+ permission_group_manage_orders,+ staff_api_client,+):+ query = ORDER_LINES_CREATE_MUTATION+ permission_group_manage_orders.user_set.add(staff_api_client.user)+ order = order_with_lines+ line = order.lines.first()+ line2 = order.lines.last()+ assert line.variant != line2.variant+ line2.variant = None+ line2.save(update_fields=["variant"])+ order.status = status+ order.save(update_fields=["status"])++ variant = line.variant+ quantity = 1+ order_id = graphene.Node.to_global_id("Order", order.id)+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ variables = {"orderId": order_id, "variantId": variant_id, "quantity": quantity}+ response = staff_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ data = content["data"]["orderLinesCreate"]++ assert data["orderLines"][0]["productSku"] == variant.sku+ assert data["orderLines"][0]["productVariantId"] == variant.get_global_id()+ assert data["orderLines"][0]["quantity"] == line.quantity + quantity++@pytest.mark.parametrize("status", (OrderStatus.DRAFT, OrderStatus.UNCONFIRMED))@patch("saleor.plugins.manager.PluginsManager.draft_order_updated")@patch("saleor.plugins.manager.PluginsManager.order_updated")