diff --git a/snippets/card-gallery.liquid b/snippets/card-gallery.liquid new file mode 100644 index 0000000..eef50c3 --- /dev/null +++ b/snippets/card-gallery.liquid @@ -0,0 +1,488 @@ +{%- doc -%} + Displays product images in a carousel. + Settings allow for a full slideshow, showing only the first image, or showing the second image when hovering. + Note: When the product card itself is in a carousel layout, the card-gallery's carousel is disabled with JavaScript. + + @param [children] - Additional content rendered below the card gallery + @param [section] - The section object the snippet is rendered in + @param [block] - The block object the snippet is rendered in +{%- enddoc -%} + +{% liquid + assign product = closest.product + assign block_settings = block.settings + assign image_sizes = '(min-width: 750px) 50vw, 100vw' + + # Check if product has badges and determine position + assign has_badges = false + assign badge_position = null + if product != blank + comment + start Yagi + endcomment + assign product_compare_at_price = product.compare_at_price + assign product_price = product.price + + assign product_price = product.metafields.app--168074346497.min_auto_discounted_price.value | default: product.price + + if product.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value + + assign product_price = product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + + assign product_compare_at_price = product.price + + if product.compare_at_price > product_compare_at_price + assign product_compare_at_price = product.compare_at_price + endif + endif + comment + end Yagi + endcomment + + if product.available == false or product_compare_at_price > product_price + assign has_badges = true + assign badge_position = settings.badge_position + endif + endif + + # if the card-gallery has a section.settings.product_card_size: + # assume grid-template autofill(card-size, 1fr) and calculate the sizes attribute based on the minimum card size + # + # if section has section.settings.columns: + # assume grid-template repeat(column-count, 1fr) and calculate the sizes attribute based on the number of columns + if section.settings.product_card_size + assign mobile_image_size = '100vw' + if section.settings.mobile_product_card_size == 'small' + assign mobile_image_size = '50vw' + endif + + capture card_size + render 'util-product-grid-card-size', section: section + endcapture + assign card_size = card_size | strip | replace: 'px', '' | plus: 0 + capture sizes_attribute + render 'util-autofill-img-size-attr', card_size: card_size, card_gap: section.settings.columns_gap_horizontal, mobile_size: mobile_image_size + endcapture + assign image_sizes = sizes_attribute | strip + elsif section.settings.columns and section.settings.layout_type != 'editorial' + assign viewport_width = 100.0 | divided_by: section.settings.columns + assign sizes_attribute = '(min-width: 750px) [viewport_width]vw, 100vw' | replace: '[viewport_width]', viewport_width + assign image_sizes = sizes_attribute | strip + endif + + assign ratio = '1' + case block_settings.image_ratio + when 'landscape' + assign ratio = '16 / 9' + when 'portrait' + assign ratio = '4 / 5' + when 'square' + assign ratio = '1' + when 'adapt' + assign ratio = product.featured_media.preview_image.aspect_ratio | default: '1' + endcase + + if block_settings.image_ratio == 'adapt' and block_settings.constrain_to_viewport + if block_settings.constrain_to_viewport != '' + assign constrain_to_viewport = true + assign media_fit = block_settings.constrain_to_viewport + endif + endif +%} + +