How to base on Product handle to retriever all variant ID of option1

Topic summary

Goal: eliminate initial delay (few seconds) when customers change option1 (first product option, e.g., Color) by preloading all related variant IDs as soon as a product is selected.

Context: The product handle (unique text ID in Shopify) is available in customer-card-product.liquid. User wants to fetch all variant IDs for option1 using Liquid or JS to cache them and avoid first-selection lag.

Approaches discussed:

  • Liquid: Loop through product.variants to access each variant object and ID.
  • JavaScript (recommended): Use Shopify’s frontend endpoint /products/{handle}.js to retrieve product JSON, then read product.variants.

Current issues:

  • Initial JS sample tried variant.id == variant_id (variant_id undefined).
  • Provided async fetch pattern (getData(handle)) returned nothing in user tests; likely the click handler (handleProductLinkClick) isn’t bound, so code never runs. No console logs observed.

Next steps & status:

  • No technical fix finalized yet. Helper requested collaborator access to inspect implementation details; user agreed and proposed times. Collaboration to proceed via private message. Discussion remains open.

Notes: Code snippets (Liquid and JS) are central to understanding the solution.

Summarized with AI on December 26. AI used: gpt-5.

@namphan ,

Sure. Tks first. If possible we can do it tomorrow Singapore time between 2~5pm or 26th Jun Singapore time after 2pm?

Rgds

Tan Bing

1 Like