inCollections(ids: $CollectionIds) always returns empty array in Shopify Discount Function (POS)

Hi Shopify Community,

I’m working on a Shopify Discount Function targeting:

cart.lines.discounts.generate.run

and I’m trying to determine whether a cart line’s product belongs to a specific collection.

GraphQL Input Query

query CartInput($CollectionIds: [ID!]) {
  cart {
    lines {
      merchandise {
        ... on ProductVariant {
          id
          product {
            id
            title
            handle
            collectionIds: inCollections(ids: $CollectionIds) {
              collectionId
              isMember
            }
          }
        }
      }
    }
  }
}

Extension Configuration (shopify.extension.toml)

[extensions.input.variables]
namespace = "$app:discount-bogo"
key = "CollectionIds"

Runtime Input (Logged)

"product": {
  "id": "gid://shopify/Product/11007581258046",
  "title": "Check Blazer",
  "handle": "3905-jacket-in-black",
  "vendor": "PERFORMAX",
  "collectionIds": []
}

Issue

Even though the product is definitely part of the collection,
the response always returns:

"collectionIds": []

No isMember, no collectionId, nothing.

This happens specifically when:

  • The function runs in POS

  • Using cart.lines.discounts.generate.run

  • Passing collection IDs via extensions.input.variables

What I Need

I need a reliable way inside a Discount Function to check whether a product belongs to a collection.

So my questions are:

  1. Is inCollections supported in discount function runtime, especially for POS?

  2. Are extensions.input.variables guaranteed to be available for inCollections?

  3. Is this a known limitation of Shopify Functions where collection membership isn’t resolvable?

  4. If inCollections is not supported, what is the recommended alternative to check product–collection relationships inside a discount function?

Any clarification from Shopify staff or anyone who’s solved this would be appreciated.

Thanks.

FULL INFO
cart_lines_discounts_generate_run.graphql

query CartInput($CollectionIds: [ID!]) {

  cart {

posCheck: attribute(key: "discountlyPos") { value }

lines {

id

cost {

amountPerQuantity {

amount

        }

subtotalAmount {

amount

        }

      }

quantity

merchandise {

... on ProductVariant {

id

product {

id

title

handle

vendor

collectionIds: inCollections(ids: $CollectionIds) {

collectionId

isMember

            }

          }

__typename

        }

      }

    }

  }

discount {

discountClasses

  }

shop {

metafield(key: "DiscountlyBogoDiscountPOS", namespace: "ACPTiered") {

jsonValue

    }

subTotalMeta:metafield(key: "NormalTiers", namespace: "ACPTiered") {

jsonValue

    }

localTime{

date

    }

  }

}

shopify.extension.toml

api_version = “2025-10”

[[extensions]]
name = “t:name”
handle = “discount-function-XXXX”
type = “function”
uid = “4811fdbc-7d6b-0de0-6721-XXXXX”
description = “t:description”

[[extensions.targeting]]
target = “cart.lines.discounts.generate.run”
input_query = “src/cart_lines_discounts_generate_run.graphql”
export = “cart-lines-discounts-generate-run”

[[extensions.targeting]]
target = “cart.delivery-options.discounts.generate.run”
input_query = “src/cart_delivery_options_discounts_generate_run.graphql”
export = “cart-delivery-options-discounts-generate-run”

[extensions.build]
command = “”
path = “dist/function.wasm”

[extensions.input.variables]
namespace = “$app:discount-bogo”
key = “CollectionIds”

AND THIS IS THE

**Input (STDIN)
**

      {
  "cart": {
    "posCheck": {
      "value": "2026-01-31T04:57:35,test-chekout002.myshopify.com,81839161662"
    },
    "lines": [
      {
        "id": "gid:\/\/shopify\/CartLine\/0",
        "cost": {
          "amountPerQuantity": {
            "amount": "898.0"
          },
          "subtotalAmount": {
            "amount": "19756.0"
          }
        },
        "quantity": 22,
        "merchandise": {
          "id": "gid:\/\/shopify\/ProductVariant\/49379854188862",
          "product": {
            "id": "gid:\/\/shopify\/Product\/11007581258046",
            "title": "Check Blazer",
            "handle": "3905-jacket-in-black",
            "vendor": "PERFORMAX",
            "collectionIds": []
          },
          "__typename": "ProductVariant"
        }
      }
    ]
  },
  "discount": {
    "discountClasses": [
      "PRODUCT",
      "ORDER"
    ]
  },
  "shop": {
    "metafield": {
      "jsonValue": [
        {
          "MyShopifyDomain": "test-chekout002.myshopify.com",
          "discountTitle": "BOGOO",
          "customerBuys": {
            "buyQuantity": "1",
            "basedOn": "Collection",
            "itemData": [
              {
                "id": "gid:\/\/shopify\/Collection\/470089662782",
                "title": "50% OFF on this items",
                "handle": "50-off-on-this-items",
                "image": "https:\/\/cdn.shopify.com\/s\/files\/1\/0750\/8380\/9086\/collections\/2771165.jpg?v=1713350310"
              }
            ]
          },
          "customerGets": {
            "buyQuantity": "1",
            "basedOn": "Collection",
            "itemData": [
              {
                "id": "gid:\/\/shopify\/Collection\/470089662782",
                "title": "50% OFF on this items",
                "handle": "50-off-on-this-items",
                "image": "https:\/\/cdn.shopify.com\/s\/files\/1\/0750\/8380\/9086\/collections\/2771165.jpg?v=1713350310"
              }
            ]
          },
          "combined": {
            "productCombined": false,
            "orderCombined": false,
            "shippingCombined": false
          },
          "created_date": "2026-01-28T10:33:54.034Z",
          "status": true,
          "startDate": null,
          "endDate": null,
          "discountApplied": "Point_of_Sale",
          "LocationIds": [],
          "location_Obj": null,
          "__v": 0
        }
      ]
    },
    "subTotalMeta": null,
    "localTime": {
      "date": "2026-01-31"
    }
  }
}

collectionIds being an empty array suggests that $CollectionIds is not populating correctly. If it was, but the collection membership check was incorrect, you’d still see collectionIds populated, but isMember with a value of false.

The problem likely lies in:

[extensions.input.variables]
namespace = “$app:discount-bogo”
key = “CollectionIds”

Your input.variables metafield should be of type json, and CollectionIds should be a property on the that metafield, of type String[].

You can follow the documentation, which explains how input variables work in functions.