I am developing a Shopify Function to apply discounts based on customer tags and product collection memberships.
collectionData (Namespace: discountApp): Holds only the variable selectedCollectionIds with an array of collection IDs.
{
"node": {
"id": "gid://shopify/Metafield/27485936845038",
"namespace": "discountApp",
"key": "collectionData",
"value": "{\"selectedCollectionIds\":[\"gid://shopify/Collection/422046531822\",\"gid://shopify/Collection/421527421166\"]}",
"type": "json",
}
}
I have included this in my shopify.extension.toml file:
[extensions.input.variables]
namespace = "discountApp"
key = "collectionData"
and here is my run.graphql:
query Input($selectedCollectionIds: [ID!]) {
cart {
lines {
merchandise {
... on ProductVariant {
product {
id
handle
inAnyCollection(ids: $selectedCollectionIds)
}
}
}
}
buyerIdentity {
customer {
metafield(namespace: "discountApp", key: "tag") {
value
}
}
}
}
shop {
metafield(namespace: "discountApp", key: "tags") {
value
}
}
}
Here is what is returned to me from Shopify:
{
"cart": {
"lines": [
{
"merchandise": {
"product": {
"id": "gid://shopify/Product/8212928430318",
"handle": "hat",
"inAnyCollection": false
}
}
},
{
"merchandise": {
"product": {
"id": "gid://shopify/Product/8208496492782",
"handle": "t-shirt",
"inAnyCollection": false
}
}
}
],
"buyerIdentity": {
"customer": {
"metafield": {
"value": "Pro"
}
}
}
},
"shop": {
"metafield": {
"value": "{\"Pro\":{\"collections\":{\"hats\":\"20%\",\"pants\":\"10%\",\"shirts\":\"35%\"}},\"VIP\":{\"collections\":{\"hats\":\"30%\",\"pants\":\"20%\",\"shirts\":\"40%\"}}}"
}
}
}
and here is the graphql code I used to create the metafield:
mutation {
metafieldsSet(metafields: [
{
namespace: "discountApp",
key: "collectionData",
type: "json",
value: "{\"selectedCollectionIds\":[\"gid://shopify/Collection/422046531822\",\"gid://shopify/Collection/421527421166\"]}",
ownerId: "gid://shopify/Shop/61637230830"
}
]) {
metafields {
id
}
}
}
But no matter what I do, I cannot get inAnyCollection to be true. Any suggestions or help?