From 89de40a8aa5d6ea40bb34a80103aca86fac1e23a Mon Sep 17 00:00:00 2001 From: Lars Hoffbeck Date: Fri, 2 Feb 2024 09:50:12 -0600 Subject: [PATCH] Simplify featured product to use the same media gallery snippet as main-product, simplify product-media-gallery, simplify main-product --- assets/section-featured-product.css | 4 + assets/section-main-product.css | 4 + sections/featured-product.liquid | 166 +++----------------------- sections/main-product.liquid | 8 +- snippets/product-media-gallery.liquid | 116 +++++++++--------- 5 files changed, 85 insertions(+), 213 deletions(-) diff --git a/assets/section-featured-product.css b/assets/section-featured-product.css index 5290e0612c0..d6822beab68 100644 --- a/assets/section-featured-product.css +++ b/assets/section-featured-product.css @@ -53,6 +53,10 @@ .background-secondary .featured-product { padding: 5rem; } + + .product--right .product__media-wrapper { + order: 2; + } } @media screen and (min-width: 990px) { diff --git a/assets/section-main-product.css b/assets/section-main-product.css index 5fb37df78e9..d2d382defdb 100644 --- a/assets/section-main-product.css +++ b/assets/section-main-product.css @@ -50,6 +50,10 @@ .product__media-container .slider-buttons { display: none; } + + .product--right .product__media-wrapper { + order: 2; + } } @media screen and (min-width: 990px) { diff --git a/sections/featured-product.liquid b/sections/featured-product.liquid index 4c920b73657..65ed66157de 100644 --- a/sections/featured-product.liquid +++ b/sections/featured-product.liquid @@ -62,86 +62,24 @@ > {%- endif -%} +{% assign variant_images = product.images | where: 'attached_to_variant?', true | map: 'src' %} +
+ {%- endif -%}
- {%- if section.settings.media_position == 'right' -%} -
- {%- if section.settings.product != blank -%} - -
- {%- if product.selected_or_first_available_variant.featured_media != null -%} - {%- assign media = product.selected_or_first_available_variant.featured_media -%} -
- {% render 'product-thumbnail', - media: media, - position: 'featured', - loop: section.settings.enable_video_looping, - modal_id: section.id, - xr_button: false, - media_width: media_width, - media_fit: section.settings.media_fit, - constrain_to_viewport: section.settings.constrain_to_viewport - %} -
- {%- endif -%} - {%- for media in product.media -%} - {%- if media_to_render contains media.id - and media.id != product.selected_or_first_available_variant.featured_media.id - -%} -
- {% render 'product-thumbnail', - media: media, - position: forloop.index, - loop: section.settings.enable_video_looping, - modal_id: section.id, - xr_button: false, - media_width: media_width, - media_fit: section.settings.media_fit, - constrain_to_viewport: section.settings.constrain_to_viewport - %} -
- {%- endif -%} - {%- endfor -%} -
- {%- if first_3d_model -%} - - {%- endif -%} -
- {%- else -%} -
-
- {{ 'product-apparel-1' | placeholder_svg_tag: 'placeholder-svg' }} -
-
- {%- endif -%} -
- {%- endif -%} - {% render 'product-media-modal', product: product, variant_images: media_to_render %} + {% render 'product-media-modal', product: product, variant_images: variant_images %}
diff --git a/sections/main-product.liquid b/sections/main-product.liquid index be03b3103aa..140e83f51bd 100644 --- a/sections/main-product.liquid +++ b/sections/main-product.liquid @@ -68,7 +68,7 @@ {% assign variant_images = product.images | where: 'attached_to_variant?', true | map: 'src' %}
-
+
{% render 'product-media-gallery', variant_images: variant_images %}
@@ -545,12 +545,6 @@
- {%- if section.settings.media_position == 'right' -%} - {% comment %} Duplicate gallery to display after product content on tablet/desktop breakpoint {% endcomment %} -
- {% render 'product-media-gallery', variant_images: variant_images, is_duplicate: true %} -
- {%- endif -%}
{% render 'product-media-modal' variant_images: variant_images %} diff --git a/snippets/product-media-gallery.liquid b/snippets/product-media-gallery.liquid index 69ac587aa72..c2806915bfb 100644 --- a/snippets/product-media-gallery.liquid +++ b/snippets/product-media-gallery.liquid @@ -5,10 +5,10 @@ Accepts: - product: {Object} Product liquid object - variant_images: {Array} Product images associated with a variant - - is_duplicate: {Boolean} Prevents rendering uneeded elements and duplicate ids for subsequent instances + - limit: {Number} (optional) When passed, limits the number of media items to render Usage: - {% render 'product-media-gallery', is_duplicate: true %} + {% render 'product-media-gallery' %} {% endcomment %} {%- liquid @@ -16,6 +16,10 @@ assign single_media_visible = true endif + if limit == 1 + assign single_media_visible = true + endif + assign media_count = product.media.size if section.settings.hide_variants and media_count > 1 and variant_images.size > 0 assign media_count = media_count | minus: variant_images.size | plus: 1 @@ -36,15 +40,10 @@ elsif section.settings.media_size == 'small' assign media_width = 0.45 endif - - assign id_append = '' - if is_duplicate - assign id_append = '-duplicate' - endif -%}
- - {%- unless is_duplicate -%} - - {{ 'accessibility.skip_to_product_info' | t }} - - {%- endunless -%} + + + {{ 'accessibility.skip_to_product_info' | t }} + - {%- unless is_duplicate -%} -
- -
- 1 - - {{ 'general.slider.of' | t }} - {{ media_count }} -
- +
+ +
+ 1 + + {{ 'general.slider.of' | t }} + {{ media_count }}
- {%- endunless -%} + +
{%- if first_3d_model -%}