I’m working on a product discount function to discount a product based on the customers location.
I’ve created and installed a function based on the Getting started with building a discounts experience guide. This works as expected.
I’ve tried to expand the functionality of that to do what I want but I’m unable to get the delivery address from the cart. I’m trying to use the CartDeliveryGroup object to this but it always comes back empty. I’ve tried at each stage of the cart and checkout with different products.
What am I missing?
I have seen a couple of older forum posts (example) with similar issues and some on the Shopify Developers Discord but nothing has a solution.
This is my input GraphQL:
query Input {
cart {
buyerIdentity {
customer {
email
}
}
deliveryGroups {
id
deliveryAddress {
countryCode
zip
}
}
cost {
totalAmount { amount }
}
lines {
quantity
merchandise {
__typename
...on ProductVariant {
id
}
}
}
}
}
And this is the “Input (STDIN)” from the functions log in the partner dashboard (email address removed for privacy):
{
"cart": {
"buyerIdentity": {
"customer": {
"email": "REDACTED"
}
},
"deliveryGroups": [],
"cost": {
"totalAmount": {
"amount": "139.0"
}
},
"lines": [
{
"quantity": 1,
"merchandise": {
"__typename": "ProductVariant",
"id": "gid://shopify/ProductVariant/41270839607436"
}
}
]
}
}
Thanks in advanced!