Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying selected variant images alongside product images? #366

Open
pycxu opened this issue Oct 17, 2024 · 1 comment
Open

Displaying selected variant images alongside product images? #366

pycxu opened this issue Oct 17, 2024 · 1 comment

Comments

@pycxu
Copy link

pycxu commented Oct 17, 2024

Hi, I'm pretty new to Shopify and Hydrogen.

I am trying to figure out the best approach for MediaGallery to display both product and variant images, while prioritising the selected variant's images in the gallery:

  • Utilise the useProductVariants() and useSelectedVariant() hooks to access variant data.
  • Convert variant images to MediaImage and concatenate them with the product images (MediaImage), while ensuring that duplicate images are removed based on their Shopify CDN file url. This is necessary since variant and product images may have different IDs? (gid://shopify/ProductImage/* vs. gid://shopify/ImageSource/*), but the URLs are identical for the same image.

Not too sure about this, any suggestions?

Thank you.

@thomasKn
Copy link
Collaborator

Hey @pycxu, your approach will work if you want to use the classic product image gallery.

I know that Shopify recently released a native swatch with Products 2.0 and I plan to add a color swatch to the theme, and here is how I would do it:

  • Update the product from the Shopify admin to add Color as a Category Metafield.
  • Create a new Metaobject Variant Image Gallery (used to store images per variant and color).
  • Create a new product Metafield to reference a list of variant image galleries.
  • Render the color swatch in the PDP using the ProductOptionValueSwatch value.
  • Render the Variant Image Gallery Metaobject based on the color selected.

vishwamartur added a commit to vishwamartur/fluid that referenced this issue Oct 31, 2024
Related to frontvibe#366

Update `MediaGallery` component to display both product and variant images, prioritizing the selected variant's images.

* Import `useProductVariants` and `useSelectedVariant` hooks in `app/components/product/MediaGallery.tsx`.
* Concatenate variant images with product images and remove duplicate images based on Shopify CDN file URL.
* Modify `useSelectedVariant` hook in `app/hooks/useSelectedVariant.tsx` to include `images` field for the selected variant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants