Discussing Shopify Functions development, deployment, and usage in Shopify apps.
There seems to be no way to get the price of a product variant in a cart line.
I can construct the run.graphql like this:
query RunInput { cart { lines { quantity merchandise { __typename ...on ProductVariant { id product { two_for_tag: hasAnyTag(tags: ["2FOR25"]) } } } } } }
But there is no way to get the price?
Shopify what the heck? How in the WORLD can I not get the price of a product variant if I want specialized discounts? This functionality is missing unless I miss my guess.
For example, if I want to a 2 for 25 discount on all product variants with that tag, I want to discount pairs of those product variants down to 12.50, and the product variant prices could be all sorts of prices. I sure as heck don't want to change them to some uniform value, that's dumb (margins are not the same across products). And I want to incentivize customers to purchase more to get the deal just like Supermarkets.
Note: I CAN get the price of a product in Shopify Scripts.
How can I achieve this discount without using Scripts?
ProductVariant has only according to docs:
id, metafield, sku, weight, weight unit, title, requires_shipping, but NOT price.
Solved! Go to the solution
This is an accepted solution.
Thanks, but that is not available in the Shopify Function run.graphql.
I have found this works:
query RunInput {
cart {
lines {
id
quantity
cost {
amountPerQuantity {
amount
currencyCode
}
subtotalAmount {
amount
currencyCode
}
}
merchandise {
__typename
...on ProductVariant {
id
product {
two_for_tag: hasAnyTag(tags: ["2FOR25"])
}
}
}
}
}
}
Looking at my logs, I get this:
Input(Stdin):
{
"cart": {
"lines": [
{
"id": "gid://shopify/CartLine/0",
"quantity": 2,
"cost": {
"amountPerQuantity": {
"amount": "67.99",
"currencyCode": "USD"
},
"subtotalAmount": {
"amount": "135.98",
"currencyCode": "USD"
}
},
"merchandise": {
"__typename": "ProductVariant",
"id": "gid://shopify/ProductVariant/43012684841138",
"product": {
"two_for_tag": true
}
}
}
]
}
}
So amountPerQuantity { amount } is what I needed.
So this works.
I use the GraphQL endpoint but not for functions. Is there a reason something like this wouldn't work in your case? (Cart id will need to be dynamic "1" is just a place holder for reference). You can add more fields as well.
query runinput {
cart(id: 1) {
lines {
nodes {
merchandise {
... on ProductVariant {
id
price {
amount
}
compareAtPrice {
amount
}
title
}
}
quantity
}
}
}
}
This is an accepted solution.
Thanks, but that is not available in the Shopify Function run.graphql.
I have found this works:
query RunInput {
cart {
lines {
id
quantity
cost {
amountPerQuantity {
amount
currencyCode
}
subtotalAmount {
amount
currencyCode
}
}
merchandise {
__typename
...on ProductVariant {
id
product {
two_for_tag: hasAnyTag(tags: ["2FOR25"])
}
}
}
}
}
}
Looking at my logs, I get this:
Input(Stdin):
{
"cart": {
"lines": [
{
"id": "gid://shopify/CartLine/0",
"quantity": 2,
"cost": {
"amountPerQuantity": {
"amount": "67.99",
"currencyCode": "USD"
},
"subtotalAmount": {
"amount": "135.98",
"currencyCode": "USD"
}
},
"merchandise": {
"__typename": "ProductVariant",
"id": "gid://shopify/ProductVariant/43012684841138",
"product": {
"two_for_tag": true
}
}
}
]
}
}
So amountPerQuantity { amount } is what I needed.
So this works.