craftcms / craftcms/shopify

Query media connection for variant images

Open
#164 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Plugins -> Shopify
Dominant language
PHP
Stars
56
Forks
30
Avg merge
11h 15m
Merged PRs (30d)
2

Description

It would be great if the media connection could be used for ProductVariant images, as you have done for Products.

At the moment, product.images gives you an array of MediaImage objects e.g.

[
  [
    "id" => "gid://shopify/MediaImage/1234567890"
    "alt" => ""
    "image" => array:4 [▶]
    "createdAt" => "2021-08-09T16:28:29Z"
    "updatedAt" => "2025-03-31T19:55:12Z"
    "__parentId" => "gid://shopify/Product/1234567890"
    "mediaContentType" => "IMAGE"
  ],
  [
    "id" => "gid://shopify/MediaImage/4567890123"
    "alt" => ""
    "image" => array:4 [▶]
    "createdAt" => "2021-08-09T16:28:29Z"
    "updatedAt" => "2025-03-31T19:55:12Z"
    "__parentId" => "gid://shopify/Product/4567890123"
    "mediaContentType" => "IMAGE"
  ],
]

However, variant.image gives you a standard Image object e.g.

  "id" => "gid://shopify/ProductImage/1234567890"
  "src" => "https://cdn.shopify.com/s/files/1234567890"
  "url" => "https://cdn.shopify.com/s/files/1234567890"
  "width" => 1000
  "height" => 768
  "altText" => null

Previously, I was able to find a variant's image in the parent product's image array by id. This was useful when switching to a different variant on a product page and updating the main product image respectively. However now I don't see a way to match them given the different URIs.

It's interesting that the Images connection on Product has been deprecated, yet Image on ProductVariant continues to live alongside the newer Media connection.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Shopify Admin GraphQL documentation for Product and ProductVariant media fields, then locate the existing Product media handling in this repository. Compare how variant images are currently exposed with product media, and consider the work complete when a variant's media can be queried and matched consistently with the product connection.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, php
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.