A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm using 2021-04 Admin Graphql API.
How do I detect the usage of an Automatic bxgy discount when I fetch an Order? What difference does the discountApplication have from a FixedFee or Percentage automatic disocunt?
Solved! Go to the solution
This is an accepted solution.
Hi @tolgapaksoy,
I've reviewed the documentation, link, and examples shared in this thread. Your use case mentions building an app that maps discount usage to an order, specifically determining if a "BxGy percent" or a "BxGy fixed (money)" discount was used - and I wanted to share some insights based on your last question
Already mentioned by @SteveRlz, there is no way to return the ID of an automatic discount through the Order object or it's connections. However, it is possible to query the values you are looking for using discountApplication.value (PricingValue union). This allows you to return one of two objects, either percentage off (PricingPercentageValue) or a monetary value (MoneyV2) of a given currency, using inline fragments.
I put together a sample query below that you are welcome to build off - Note: __typename
is included, as suggested for inline fragments to provide context of value type returned.
## On Order object, return discountApplications.value, PricingValue union of PricingPercentageValue and MoneyV2.
{
node(id: "gid://shopify/Order/${ORDER_ID}") {
... on Order {
discountApplications(first: 5) {
nodes {
... on AutomaticDiscountApplication {
allocationMethod
targetType
targetSelection
value {
... on PricingPercentageValue {
percentage
__typename
}
... on MoneyV2 {
currencyCode
amount
__typename
}
}
}
}
}
}
}
}
Hope this helps provide some clarification - Cheers!
@awwdam | Shopify Developer Support
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 the type in the docs:
https://shopify.dev/api/admin/graphql/reference/orders/automaticdiscountapplication
allocationMethod: DiscountApplicationAllocationMethod!
The method by which the discount's value is allocated to its entitled items.
index: Int!
An ordered index that can be used to identify the discount application and indicate the precedence of the discount application for calculations.
targetSelection: DiscountApplicationTargetSelection!
How the discount amount is distributed on the discounted lines.
targetType: DiscountApplicationTargetType!
Whether the discount is applied on line items or shipping lines.
title: String!
The title of the discount application.
value: PricingValue!
The value of the discount application.
Given these fields on AutomaticDiscountApplication, I can only fetch the "effects" of the discount: how much percent or how many € the discount had effect on this order. What I would like to know is whether the AutomaticDiscountApplication was caused by a Buy-X-Get-Y price rule.
Any Shopify dev, or Shopify App dev every tried to do this?
My use case is simple: I am building an app that needs to map discount usage to some external ERP system. One of the mappings that I need to do is whether a BxGy percent or a BxGy fixed discount was used.
I'm facing the same issue.
Querying this:
query {
order(id: "gid://shopify/Order/REPLACE_ORDER_NUMBER") {
discountApplications (first:3){
nodes {
... on AutomaticDiscountApplication {
title
allocationMethod
targetType
targetSelection
index
}
}
}
}
}
I get this:
{
"data": {
"order": {
"discountApplications": {
"nodes": [
{
"title": "BXGY discount test",
"allocationMethod": "EACH",
"targetType": "LINE_ITEM",
"targetSelection": "ENTITLED",
"index": 0
}
]
}
}
},
I can only identify the discount with it's title but not an ID, and discounts can have the same title so i'm unable to identify it.
@tolgapaksoy were you able to solve this?
I gave up on this. Forget about getting any help either. None of my questions on this forum was ever answered by Shopify staff.
This is an accepted solution.
Hi @tolgapaksoy,
I've reviewed the documentation, link, and examples shared in this thread. Your use case mentions building an app that maps discount usage to an order, specifically determining if a "BxGy percent" or a "BxGy fixed (money)" discount was used - and I wanted to share some insights based on your last question
Already mentioned by @SteveRlz, there is no way to return the ID of an automatic discount through the Order object or it's connections. However, it is possible to query the values you are looking for using discountApplication.value (PricingValue union). This allows you to return one of two objects, either percentage off (PricingPercentageValue) or a monetary value (MoneyV2) of a given currency, using inline fragments.
I put together a sample query below that you are welcome to build off - Note: __typename
is included, as suggested for inline fragments to provide context of value type returned.
## On Order object, return discountApplications.value, PricingValue union of PricingPercentageValue and MoneyV2.
{
node(id: "gid://shopify/Order/${ORDER_ID}") {
... on Order {
discountApplications(first: 5) {
nodes {
... on AutomaticDiscountApplication {
allocationMethod
targetType
targetSelection
value {
... on PricingPercentageValue {
percentage
__typename
}
... on MoneyV2 {
currencyCode
amount
__typename
}
}
}
}
}
}
}
}
Hope this helps provide some clarification - Cheers!
@awwdam | Shopify Developer Support
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