Discussing Shopify Functions development, deployment, and usage in Shopify apps.
When clicking a previously created Discount in Shopify backend - How do I get the Discount Method (Code vs Automatic) when loading my Shopify Discount React file edit.jsx?
Is It passed down from the Shopify Discount list to my React file and how?
Or do I need to make an additional GraphQL query to defined the the Method (Code vs Automatic) before being able to define if Im dealing with A Code or Automatic discount?
Once I know the type of discount Im dealing with I can query GraphQL with either `codeDiscountNode` or `automaticDiscountNode`
Visual context:
Solved! Go to the solution
This is an accepted solution.
Hi @Nico4 --
Check out this example. When querying a `discountNode`, you can check its type name and use inline fragments to get the appropriate fields.
query GetDiscount($id: ID!) {
discountNode(id: $id) {
id
configurationField: metafield(
namespace: "${metafields.namespace}"
key: "${metafields.key}"
) {
id
value
}
discount {
__typename
... on DiscountAutomaticApp {
title
discountClass
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
startsAt
endsAt
}
... on DiscountCodeApp {
title
discountClass
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
startsAt
endsAt
usageLimit
appliesOncePerCustomer
codes(first: 1) {
nodes {
code
}
}
}
}
}
}
Nick Wesselman | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
This is an accepted solution.
Hi @Nico4 --
Check out this example. When querying a `discountNode`, you can check its type name and use inline fragments to get the appropriate fields.
query GetDiscount($id: ID!) {
discountNode(id: $id) {
id
configurationField: metafield(
namespace: "${metafields.namespace}"
key: "${metafields.key}"
) {
id
value
}
discount {
__typename
... on DiscountAutomaticApp {
title
discountClass
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
startsAt
endsAt
}
... on DiscountCodeApp {
title
discountClass
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
startsAt
endsAt
usageLimit
appliesOncePerCustomer
codes(first: 1) {
nodes {
code
}
}
}
}
}
}
Nick Wesselman | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog