Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I am using this query
{ id discountAllocations { discountedAmount { amount currencyCode } } discountCodes{ applicable code } attributes { key value } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } totalTaxAmount { amount currencyCode } totalDutyAmount { amount currencyCode } } totalQuantity note lines(first:100){ edges{ node{ id merchandise{ ... on ProductVariant { id title product{ createdAt description id productType title updatedAt vendor } image{ height id url width } price unitPrice{ amount currencyCode } } } quantity } } }}}}
Where and what would I have add to this query to receive the name of the automatic discount code applied on the cart?
I read the docs about CartAutomaticDiscountAllocation but can't figure out how to access/ reach this object.
Solved! Go to the solution
This is an accepted solution.
Hi @GkPayments 👋
Since `CartDiscountAllocation` is an interface, you can use an inline fragment on `CartAutomaticDiscountAllocation` like this:
query ($id: ID!) {
cart(id: $id) {
id
discountAllocations {
... on CartAutomaticDiscountAllocation {
title
discountedAmount {
currencyCode
amount
}
}
}
}
}
Hope that helps!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Hi @GkPayments 👋
Since `CartDiscountAllocation` is an interface, you can use an inline fragment on `CartAutomaticDiscountAllocation` like this:
query ($id: ID!) {
cart(id: $id) {
id
discountAllocations {
... on CartAutomaticDiscountAllocation {
title
discountedAmount {
currencyCode
amount
}
}
}
}
}
Hope that helps!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog