Changing Product Images from Carousel to Grid

Hi, im working on a website that needs to change the carousel on the product page to a grid, when i change the design the grid shows up but the variant picker stops working and the grid shows me all the images of the product, it doesnt end the for loop with the variant images.

I need to change the carousel for a grid and that the variant picker changes the images as it does with the carousel.

Here is the product images code:

{%- if product.media.size > 0 -%}
{%- assign show_thumbnails_if_one_media = true -%}

{%- assign selected_media = product.selected_variant.featured_media | default: product.featured_media -%}
{%- for media in product.media -%} {%- assign is_media_group = false -%} {%- assign is_media_filtered = false -%} {%- assign media_alt = media.alt -%}

{%- if media.alt contains ‘#’ -%}
{%- assign is_media_group = true -%}
{%- assign alt_parts = media.alt | split: ‘#’ -%}

{%- comment -%}
If the custom ALT tag contains two parts (for instance “My custom alt # color_blue”) then the first part is actually used
as a custom ALT tag
{%- endcomment -%}

{%- if alt_parts.size == 2 and alt_parts.first != blank -%}
{%- assign media_alt = alt_parts.first | strip -%}
{%- else -%}
{%- assign media_alt = product.title -%}
{%- endif -%}

{%- assign media_group_parts = alt_parts.last | split: ‘_’ -%}

{%- for option in product.options -%}
{%- assign downcase_option = option | downcase -%}
{%- assign downcase_group_option = media_group_parts.first | strip | downcase -%}

{%- if downcase_option == downcase_group_option -%}
{%- assign option_setting = ‘option’ | append: forloop.index -%}
{%- assign option_value = product.selected_or_first_available_variant[option_setting] | downcase -%}

{%- assign downcase_group_value = media_group_parts.last | strip | downcase -%}
{%- assign media_variant_ids = media.variants | map: ‘id’ -%}

{%- if option_value != downcase_group_value -%}
{%- unless media_variant_ids contains product.selected_or_first_available_variant.id -%}
{%- assign is_media_filtered = true -%}
{%- endunless -%}
{%- endif -%}

{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}

{%- case media.media_type -%} {%- when 'image' -%}
{%- capture supported_sizes -%}{%- render 'image-size', sizes: '400,500,600,700,800,900,1000,1100,1200', image: media -%}{%- endcapture -%} {%- assign image_url = media | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
{{ media_alt | escape }} {{ media_alt | escape }}

{%- when ‘model’ -%}

{{- media | model_viewer_tag: image_size: '1024x', reveal: 'interaction', toggleable: true -}}

{%- when ‘external_video’ -%}

{{- media | external_video_tag: image_size: '1024x' -}}

{%- when ‘video’ -%}

{{- media | video_tag: image_size: '1024x', controls: true -}}
{%- endcase -%}
{%- endfor -%}

{%- comment -%}Add the “view in your space” button, which allows to show the product in customer’s environment (if the device supports it){%- endcomment -%}
{%- assign first_3d_model = product.media | where: ‘media_type’, ‘model’ | first -%}

{%- if first_3d_model -%}

{%- render ‘icon’, icon: ‘media-view-in-space’ -%} {{- ‘product.general.view_in_space’ | t -}}

{%- endif -%}

{%- if template != ‘product.quick-view’ and section.settings.enable_image_zoom -%}

{% render ‘icon’, icon: ‘zoom’ %}
{{ ‘product.general.zoom’ | t }}
{{ ‘product.general.zoom_mobile’ | t }}

{%- endif -%}

{%- if show_thumbnails_if_one_media -%}

{%- for media in product.media -%} {%- assign is_media_group = false -%} {%- assign is_media_filtered = false -%} {%- assign media_alt = media.alt -%}

{%- if media.alt contains ‘#’ -%}
{%- assign is_media_group = true -%}
{%- assign alt_parts = media.alt | split: ‘#’ -%}

{%- comment -%}
If the custom ALT tag contains two parts (for instance “My custom alt # color_blue”) then the first part is actually used
as a custom ALT tag
{%- endcomment -%}

{%- if alt_parts.size == 2 and alt_parts.first != blank -%}
{%- assign media_alt = alt_parts.first | strip -%}
{%- else -%}
{%- assign media_alt = product.title -%}
{%- endif -%}

{%- assign media_group_parts = alt_parts.last | split: ‘_’ -%}

{%- for option in product.options -%}
{%- assign downcase_option = option | downcase -%}
{%- assign downcase_group_option = media_group_parts.first | strip | downcase -%}

{%- if downcase_option == downcase_group_option -%}
{%- assign option_setting = ‘option’ | append: forloop.index -%}
{%- assign option_value = product.selected_or_first_available_variant[option_setting] | downcase -%}

{%- assign downcase_group_value = media_group_parts.last | strip | downcase -%}
{%- assign media_variant_ids = media.variants | map: ‘id’ -%}

{%- if option_value != downcase_group_value -%}
{%- unless media_variant_ids contains product.selected_or_first_available_variant.id -%}
{%- assign is_media_filtered = true -%}
{%- endunless -%}
{%- endif -%}

{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}

<a href=“{{ media | img_url: ‘1024x’ }}” rel=“noopener” class=“product-gallery__thumbnail {% if media.id == selected_media.id %}is-nav-selected{% endif %} {% if is_media_filtered %}is-filtered{% endif %}” data-media-id=“{{ media.id }}” {% if is_media_group %}data-group-name=“{{ media_group_parts.first | strip | downcase | escape }}” data-group-value=“{{ media_group_parts.last | strip | downcase | escape }}”{% endif %}>
{%- comment -%}Based on the type of media, we have to add an icon as per Shopify rules{%- endcomment -%}

{%- case media.media_type -%}
{%- when ‘model’ -%}
{% render ‘icon’, icon: ‘media-model-badge’ %}

{%- when ‘video’ or ‘external_video’ -%}
{% render ‘icon’, icon: ‘media-video-badge’ %}
{%- endcase -%}

{{ media_alt | escape }}
{%- endfor -%}
{%- endif -%}

{%- if section.settings.enable_image_zoom -%}
{%- comment -%}This code is used to power the mobile zoom and must not be removed nor altered{%- endcomment -%}

{% render 'icon', icon: 'close-2' %}
{% render 'icon', icon: 'arrow-left' %} {% render 'icon', icon: 'arrow-right' %}
/
{%- endif -%}
{%- endif -%}

@guido23acuna

Sorry you are facing this issue, it would be my pleasure to help you.

Welcome to the Shopify community! :blush:
Thanks for your good question.

Please share your site URL,
I will check out the issue and provide you a solution here.

The site URL is https://www.rsoficial.com/

Thanks

Hi thanks for the reply, the site url is https://www.rsoficial.com/

Thank you.

Hope you can help me

Hi @guido23acuna ,

Can you explain more about it, do you want to change on desktop or mobile?

You changed it, please send me the preview link you changed, I will help you check it.

@guido23acuna

yes please check your theme setting allow this also just confirm you have remove slider code right?

I havent removed the slider code, but when i replace it with my grid code the variant selector doesnt work because it is linked with the slider class in the code i posted above.

Thats the main issue.

My grid code is the following

{%- liquid

assign product_image_box_ratio_max = 0

for media in product.media
assign image_box_ratio = media.height | append: “.0” | times: 1 | divided_by: media.width | times: 100
if image_box_ratio > product_image_box_ratio_max
assign product_image_box_ratio_max = image_box_ratio
endif
endfor

assign product_image_box_ratio_max = product_image_box_ratio_max | append: “%”

assign featured_media = current_variant.media | default: product.featured_media

-%}
{%- assign selected_media = product.selected_variant.featured_media | default: product.featured_media -%}

    {% for media in product.media %} {%- assign is_media_group = false -%} {%- assign is_media_filtered = false -%} {%- assign media_alt = media.alt -%}

    {%- if media.alt contains ‘#’ -%}
    {%- assign is_media_group = true -%}
    {%- assign alt_parts = media.alt | split: ‘#’ -%}

    {%- comment -%}
    If the custom ALT tag contains two parts (for instance “My custom alt # color_blue”) then the first part is actually used
    as a custom ALT tag
    {%- endcomment -%}

    {%- if alt_parts.size == 2 and alt_parts.first != blank -%}
    {%- assign media_alt = alt_parts.first | strip -%}
    {%- else -%}
    {%- assign media_alt = product.title -%}
    {%- endif -%}

    {%- assign media_group_parts = alt_parts.last | split: ‘_’ -%}

    {%- for option in product.options -%}
    {%- assign downcase_option = option | downcase -%}
    {%- assign downcase_group_option = media_group_parts.first | strip | downcase -%}

    {%- if downcase_option == downcase_group_option -%}
    {%- assign option_setting = ‘option’ | append: forloop.index -%}
    {%- assign option_value = product.selected_or_first_available_variant[option_setting] | downcase -%}

    {%- assign downcase_group_value = media_group_parts.last | strip | downcase -%}
    {%- assign media_variant_ids = media.variants | map: ‘id’ -%}

    {%- if option_value != downcase_group_value -%}
    {%- unless media_variant_ids contains product.selected_or_first_available_variant.id -%}
    {%- assign is_media_filtered = true -%}
    {%- endunless -%}
    {%- endif -%}

    {%- break -%}
    {%- endif -%}
    {%- endfor -%}
    {%- endif -%}

    {% case media.media_type %} {% when 'image' %} {% assign img_url = media | img_url: '1x1' | replace: '_1x1.', '_{width}x.' %} {{ media.alt | escape }} {% if section.settings.click_to_enlarge and template != 'product.quick' %} {% endif %} {% when 'external_video' %}
    {{ media | external_video_tag }}
    {% when 'video' %} {% style %} @media screen and (max-width: 320px) { .product-media--{{ media.id }} .plyr__poster { background-image: url({{ media.preview_image | img_url: '360x'}}) !important; } } @media screen and (min-width: 320px) and (max-width: 780px) { .product-media--{{ media.id }} .plyr__poster { background-image: url({{ media.preview_image | img_url: '900x'}}) !important; } } @media screen and (min-width: 780px) and (max-width: 1080px) { .product-media--{{ media.id }} .plyr__poster { background-image: url({{ media.preview_image | img_url: '1080x'}}) !important; } } @media screen and (min-width: 1080px) { .product-media--{{ media.id }} .plyr__poster { background-image: url({{ media.preview_image | img_url: '2048x'}}) !important; } } {% endstyle %}
    {{ media | video_tag: controls: true, class: 'media-video', image_size: '800x' }}
    {% when 'model' %}
    {{ media | model_viewer_tag: image_size: '800x', reveal: 'interaction', toggleable: true, data-model-id: media.id }}
    {% endcase %}
    {{ media.alt | escape }}
    {% endfor %}
{% assign first_3d_model = product.media | where: "media_type", "model" | first %} {%- if first_3d_model -%} {% render 'media-icons', width: '25', icon: '3d-icon' %}{{ 'products.product.view_in_space' | t }} {%- endif -%}

I want to change it on desktop, I did it with a new code snippet but the variant selector doesnt work with my code, here I send you a picture

@guido23acuna

It can be done by doing some code customization. please send me a personal message and we can discuss what you’d like

Thanks, I already sent you a message.

Patiently waiting

Really thanks for your help.

@guido23acuna

great thanks i will check and let you know