{% comment %}
Renders list of products in grid layout
Accepts:
- product: {Object} product (required)
- animation_delay: {Int} animation timing for load
- last_element: {Boolean} True when custom image is taking up the first slot for the collection
and the loop is on the last element for the page.
- index: element index in the loop
- block_index: index of the block in Tab collections section
- sizes: Image sizes
- attributes: Accept html attributes
- modifier_class: Accept custom class
Usage:
{% render 'product-grid-item', product: product, index: index, sizes: image_sizes, attributes: '', modifier_class: '' %}
{% endcomment %}
{%- liquid
assign attributes = attributes | default: ''
assign animation_delay = animation_delay | default: 0
assign aos_delay_default = animation_delay | times: 100
assign aos_delay = aos_delay | default: aos_delay_default
assign aos_duration = 800
assign layout_desktop = section.settings.layout_desktop
assign layout_mobile = section.settings.layout_mobile
assign product_card_class = ''
assign modifier_class = modifier_class | default: ''
assign index = index | default: 1
assign columns_desktop = section.settings.grid | plus: 0
assign columns_medium = 2
assign columns_small = 2
assign columns_mobile = section.settings.grid_mobile | plus: 0
if columns_desktop == 0
assign columns_desktop = 4
endif
if columns_mobile == 0
assign columns_mobile = 1
endif
if columns_desktop == 2 or columns_desktop == 4
assign columns_medium = 2
endif
if show_product_card
assign product_card_class = 'product-item--card'
endif
if settings.product_grid_center
assign alignment_class = 'product-item--centered'
else
assign alignment_class = 'product-item--left'
endif
assign overlay_text_class = 'product-item--outer-text'
if settings.overlay_text
assign overlay_text_class = 'product-item--overlay-text'
endif
assign quickview_class = ''
if settings.quickview_enable and product.first_available_variant
assign quickview_class = 'product-item--has-quickbuy'
endif
assign has_siblings = false
if settings.show_siblings and product.metafields.theme.siblings.value != blank and product.metafields.theme.siblings.type == 'single_line_text_field'
assign has_siblings = true
endif
if settings.show_siblings and product.metafields.theme.sibling_products != blank and product.metafields.theme.sibling_products.type == 'list.product_reference'
assign has_siblings = true
endif
if sizes == blank
case layout_desktop
when 'grid'
if section.settings.width == 'wrapper'
if settings.grid_style == 'compact'
assign sizes = '(min-width: 1400px) calc(80vw / ' | append: columns_desktop | append: '), (min-width: 750px) calc(100vw / ' | append: columns_medium | append: '), (min-width: 480px) calc(100vw / ' | append: columns_small | append: '), calc(100vw / ' | append: columns_mobile | append: ')'
else
assign sizes = '(min-width: 1400px) calc((80vw - 64px) / ' | append: columns_desktop | append: ' - 32px), (min-width: 750px) calc(100vw / ' | append: columns_medium | append: ' - 22px), (min-width: 480px) calc(100vw / ' | append: columns_small | append: ' - 16px), calc(100vw / ' | append: columns_mobile | append: ')'
endif
else
if settings.grid_style == 'compact'
assign sizes = '(min-width: 1400px) calc(100vw / ' | append: columns_desktop | append: '), (min-width: 750px) calc(100vw / ' | append: columns_medium | append: '), (min-width: 480px) calc(100vw / ' | append: columns_small | append: '), calc(100vw / ' | append: columns_mobile | append: ')'
else
assign sizes = '(min-width: 1400px) calc(100vw / ' | append: columns_desktop | append: ' - 32px), (min-width: 750px) calc(100vw / ' | append: columns_medium | append: ' - 22px), (min-width: 480px) calc(100vw / ' | append: columns_small | append: ' - 16px), calc(100vw / ' | append: columns_mobile | append: ')'
endif
endif
when 'slider'
if settings.grid_style == 'compact'
assign sizes = '(min-width: 990px) calc(100vw * 0.28), (min-width: 750px) calc(100vw * 0.38), calc(100% - 50px )'
else
assign sizes = '(min-width: 990px) calc((100vw - 100px) * 0.28), (min-width: 750px) calc((100vw - 60px) * 0.38), calc(100vw - 66px)'
endif
else
assign sizes = '500px'
endcase
endif
assign widths = '136, 160, 180, 220, 254, 284, 292, 320, 480, 528, 640, 720, 960, 1080, 1296, 1512, 1728, 1950'
assign aspect_ratio = 1 | divided_by: settings.product_grid_aspect_ratio
assign loading = 'eager'
if columns_desktop <= 3
assign eager_images_limit = columns_desktop
else
assign eager_images_limit = columns_desktop | times: 2
endif
if layout_desktop == 'slider' and index > 3
assign loading = 'lazy'
elsif index > eager_images_limit
assign loading = 'lazy'
endif
if block_index > 1
assign loading = 'lazy'
endif
-%}
{%- if settings.swatches_type != 'disabled' and settings.show_grid_swatches -%}
{%- assign has_colors = false -%}
{%- assign swatch_translation = 'general.swatches.color' | t -%}
{%- assign swatch_labels = swatch_translation | append: ',' | split: ',' -%}
{%- capture swatches -%}
{%- for label in swatch_labels -%}
{%- assign sanitized_label = label | lstrip | rstrip -%}
{%- if settings.swatches_type == 'theme' -%}
{%- if product.options_by_name[sanitized_label].values.size > 0 -%}
{%- assign has_colors = true -%}
{%- capture swatch_values -%}
{%- for value in product.options_by_name[sanitized_label].values -%}
{{- value -}}: {{- value | handle -}}
{%- unless forloop.last -%}, {%- endunless -%}
{%- endfor -%}
{%- endcapture -%}
{%- endif -%}
{%- elsif settings.swatches_type == 'native' -%}
{%- capture swatch_values -%}
{%- for value in product.options_by_name[sanitized_label].values -%}
{%- if value.swatch -%}
{%- assign has_colors = value -%}
{%- endif -%}
{%- liquid
if value.swatch.image
assign image_url = value.swatch.image | image_url: width: 48
assign swatch_value = 'url(' | append: image_url | append: ')'
elsif value.swatch.color
assign swatch_value = value.swatch.color
else
assign swatch_value = nil
endif
-%}
{{- value -}}: {{- swatch_value -}}
{%- unless forloop.last -%}, {%- endunless -%}
{%- endfor -%}
{%- endcapture -%}
{% endif %}
{%- if has_colors -%}