Skip to content

Storefront PDP gallery ignores variant media linked via spree_variant_media #207

Description

@FrederikKragh

Versions: spree_core 5.6.1, spree_storefront 5.4.6

Spree::ProductsHelper#product_media_gallery_images builds the gallery from selected_variant.images, the legacy variant-pinned association. Since 5.5, per-variant media is stored as product-level assets linked through spree_variant_media and exposed as Variant#gallery_media / #associated_media. For products using the new model, variant.images is empty, so the helper falls through to product.primary_media and every variant renders the same image. Selecting a different variant on the PDP never changes the gallery.

Expected: the gallery follows the selected variant, as Variant#gallery_media already resolves both storage models.

Separately, this line in the same method is dead code:

images = selected_variant&.images&.to_a || []
images ||= variant_from_options&.images&.to_a if images.empty?

images is [] at that point, which is truthy, so ||= never assigns and variant_from_options media is never used.

Reproduce: create a product with two variants, upload two images at product level, link one to each variant, then switch variants on the PDP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions