Skip to content

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

Expose order alongside fulfillment in fulfillment-based subscriptions used by webhooks (#9847)

Tomasz Magulski71e01ef1ab62
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 45a14a3182..fb9772cc9a 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -21516,6 +21516,15 @@ type FulfillmentCreated implements Event {
Note: this API is currently in Feature Preview and can be subject to changes at later point.
"""
fulfillment: Fulfillment
+
+ """
+ Order connected with looked up fulfillment.
+
+ Added in Saleor 3.4.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ order: Order
}
type FulfillmentCanceled implements Event {
@@ -21539,6 +21548,15 @@ type FulfillmentCanceled implements Event {
Note: this API is currently in Feature Preview and can be subject to changes at later point.
"""
fulfillment: Fulfillment
+
+ """
+ Order connected with looked up fulfillment.
+
+ Added in Saleor 3.4.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ order: Order
}
type CustomerCreated implements Event {
diff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.py
index 72ceb035bc..62fcac3b48 100644
--- a/saleor/graphql/webhook/subscription_types.py
+++ b/saleor/graphql/webhook/subscription_types.py
@@ -584,11 +584,22 @@ class FulfillmentBase(AbstractType):
"saleor.graphql.order.types.Fulfillment",
description="Look up a Fulfillment." + ADDED_IN_32 + PREVIEW_FEATURE,
)
+ order = graphene.Field(
+ "saleor.graphql.order.types.Order",
+ description="Order connected with looked up fulfillment."
+ + ADDED_IN_34
+ + PREVIEW_FEATURE,
+ )
@staticmethod
def resolve_fulfillment(root, _info):
- _, invoice = root
- return invoice
+ _, fulfillment = root
+ return fulfillment
+
+ @staticmethod
+ def resolve_order(root, info):
+ _, fulfillment = root
+ return fulfillment.order
class FulfillmentCreated(ObjectType, FulfillmentBase):
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py b/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py
index 0ae461c8de..76dd5f77f9 100644
--- a/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py
@@ -64,7 +64,10 @@ def generate_fulfillment_payload(fulfillment):
"trackingNumber": fulfillment.tracking_number,
"status": fulfillment.status.upper(),
"lines": generate_fulfillment_lines_payload(fulfillment),
- }
+ },
+ "order": {
+ "id": graphene.Node.to_global_id("Order", fulfillment.order.pk),
+ },
}
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py b/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py
index 835057fac1..ec41a9569b 100644
--- a/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py
@@ -706,6 +706,9 @@ FULFILLMENT_CREATED = (
fulfillment{
...FulfillmentDetails
}
+ order{
+ id
+ }
}
}
}
@@ -721,6 +724,9 @@ FULFILLMENT_CANCELED = (
fulfillment{
...FulfillmentDetails
}
+ order{
+ id
+ }
}
}
}