Hello.
I have followed the below tutorial and everything is working as expected
https://shopify.dev/docs/apps/checkout/validation/cart-checkout
I have updated the extensions/cart-checkout-validation/input.graphql as per the below to suite my applications specific needs.
query Input {
cart {
buyerIdentity {
customer {
numberOfOrders
}
}
lines {
merchandise {
...on ProductVariant {
id
}
}
quantity
}
}
}
This is working and fetching the specific data associated to the users cart that I need.
However, I addition to the above, I would also like to fetch a product and its variant (that may be unrelated to the current users cart) via ID (although in the future I will want to fetch it by tag)
How do I go about doing this?
Is this something I add to my extensions/cart-checkout-validation/input.graphql query*?*
I would like the product exposed in my extensions/cart-checkout-validation/src/index.js
// @ts-check
// Use JSDoc annotations for type safety
/**
* @typedef {import("../generated/api").InputQuery} InputQuery
* @typedef {import("../generated/api").FunctionResult} FunctionResult
*/
// The @shopify/shopify_function package will use the default export as your function entrypoint
export default
/**
* @param {InputQuery} input
* @returns {FunctionResult}
*/
(input) => {
// The error
const error = {
localizedMessage:
"This is a test",
target: "cart"
};
const errors = [];
errors.push(error);
// TODO: here I want to access a single product with it variant by ID
// Maybe something like input.my_product - if this is not the right approach,
// How can I go about achieving this?
return {errors};
};
Please, any help, guidance or advice would be greatly appreciated.