Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
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.
Hi @SoapMatt,
Thanks for your post. While we don't currently provide direct support for Functions in this forum, the public [Shopify/function-examples GitHub repository] has an active [discussion board] that might be worth checking out.
Hope you have a great day
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog