Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Variables are not working on shop metafield for cart checkout validation function

Variables are not working on shop metafield for cart checkout validation function

harsh_mishra
Shopify Partner
3 0 0

I have created metafiled on shop which is working fine. However am unable to pass the variables.
in RunInput $selectedProducts supposed to send the values but it is not.

query RunInput($selectedProductTags: [String!], $selectedCollectionIds: [ID!]) {
  cart {
    lines {
      quantity
      merchandise {
        __typename
        ... on ProductVariant {
          id
          weight
          product {
         
            hasTags(tags: $selectedProductTags) {
              hasTag
              tag
            }
          }
        }
      }
    }
  }
  shop {
    metafield(
      namespace: "$app:my_cart_checkout_shop_namespace"
      key: "my_cart_checkout_shop_key"
    ) {
      value
    }
  }
}
 

As mentioned in the doc that variables need to be declared into the toml file is already being declared

  [extensions.input.variables]
   namespace: "$app:my_cart_checkout_shop_namespace"
   key: "my_cart_checkout_shop_key"
 
 
at the javascript side , metafiled is created like this

let rules = { };
rules.selectedProductTags = ["Accessory"];
rules.selectedCollectionIds = ["Home"];

await admin.rest.put({
    path: `${"metafields/" + metafieldId + ".json"}`,
    data: JSON.stringify({
      metafield: {
        id: metafieldId,
        value: JSON.stringify(rules),
        type: "json",
      },
    }),
  });
Replies 0 (0)