Headless commerce and custom storefronts with Shopify APIs and SDKs
Hello everyone!
I'm working on one of our clients shops where we use the Shopify Storefront API to interact with the checkout. I have some questions regarding how discounts are handled via the Storefront API:
1. According to the documentation, the Checkout object (https://shopify.dev/api/storefront/reference/checkouts/checkout) has a connection for discountApplications (https://shopify.dev/api/storefront/reference/checkouts/discountapplication).
As far as I understand there is no title/code field on the DiscountApplication Object.
Is it possible to get the title/code of submitted discounts for the checkout? I need these information to show the customer what discounts are active for the checkout.
2. Regarding the documentation the is a mutation to remove discounts from the checkout: https://shopify.dev/api/storefront/reference/checkouts/checkoutdiscountcoderemove
This will remove *all* discounts from the checkout. Is there a way to remove a specific discount?
I appreciate any help 🙂
Solved! Go to the solution
This is an accepted solution.
Hey @marm_alex,
Have you seen the code property on the DiscountCodeApplication object?
You should be able to use a fragment on the checkout's discountApplications (i.e. ... on DiscountCodeApplication) to query the applied discount codes. Here's an example:
{
node(id: "Z2lkOi8vc...kxZjM=") {
id
... on Checkout {
id
ready
discountApplications(first: 5) {
edges {
node {
... on DiscountCodeApplication {
allocationMethod
applicable
targetType
targetSelection
code
value {
... on MoneyV2 {
amount
currencyCode
}
}
}
}
}
}
}
}
}
and the response:
{
"data": {
"node": {
"id": "Z2lkOi8vc...kxZjM=",
"ready": true,
"discountApplications": {
"edges": [{
"node": {
"allocationMethod": "ACROSS",
"applicable": false,
"targetType": "LINE_ITEM",
"targetSelection": "ALL",
"code": "TESTCODE-15OFF",
"value": {}
}
}]
}
}
}
}
Regarding your second point - it isn't possible to remove only one specific discount.
CalD | Developer Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Hey @marm_alex,
Have you seen the code property on the DiscountCodeApplication object?
You should be able to use a fragment on the checkout's discountApplications (i.e. ... on DiscountCodeApplication) to query the applied discount codes. Here's an example:
{
node(id: "Z2lkOi8vc...kxZjM=") {
id
... on Checkout {
id
ready
discountApplications(first: 5) {
edges {
node {
... on DiscountCodeApplication {
allocationMethod
applicable
targetType
targetSelection
code
value {
... on MoneyV2 {
amount
currencyCode
}
}
}
}
}
}
}
}
}
and the response:
{
"data": {
"node": {
"id": "Z2lkOi8vc...kxZjM=",
"ready": true,
"discountApplications": {
"edges": [{
"node": {
"allocationMethod": "ACROSS",
"applicable": false,
"targetType": "LINE_ITEM",
"targetSelection": "ALL",
"code": "TESTCODE-15OFF",
"value": {}
}
}]
}
}
}
}
Regarding your second point - it isn't possible to remove only one specific discount.
CalD | Developer Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog
Hello @CalD . Thanks for your answer. The first part helped me a lot! I just overlooked the "code" part in the documenation. Thanks for the hint!
To the second part: Are there any plans to allow to remove specific discounts via API in the future?
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By