diff --git a/snippets/product-grid-item.liquid b/snippets/product-grid-item.liquid new file mode 100644 index 0000000..2fac945 --- /dev/null +++ b/snippets/product-grid-item.liquid @@ -0,0 +1,331 @@ +{% comment %} + Renders list of products in grid layout + + Accepts: + - product: {Object} product (required) + - grid_strings: {String} contains a string of grid classes + - 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 + + Usage: + {% render 'product-grid-item', product: product, grid_strings: grid_strings, index: index %} +{% endcomment %} + +{%- liquid + assign additional_attributes = additional_attributes | default: '' + assign aos_image_delay_default = animation_delay | times: 150 + assign aos_image_duration_default = animation_delay | times: 100 | plus: 800 + assign aos_text_duration_default = animation_delay | times: 50 | plus: 800 + assign aos_image_delay = aos_image_delay | default: aos_image_delay_default + assign aos_image_duration = aos_image_duration | default: aos_image_duration_default + assign aos_text_duration = aos_text_duration | default: aos_text_duration_default + + assign product_price_raw = product.metafields.app--168074346497.min_auto_discounted_price.value | default: product.price + assign product_price_min_raw = product.price_min + assign product_compare_at_price_raw = product.compare_at_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_raw = product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + assign product_price_min_raw = product_price_raw + + assign product_compare_at_price_raw = product.price + + if product.compare_at_price > product_compare_at_price_raw + assign product_compare_at_price_raw = product.compare_at_price + endif + elsif product_price_raw < product.price + assign product_price_min_raw = product_price_raw + assign product_compare_at_price_raw = product.price + + if product.compare_at_price > product_compare_at_price_raw + assign product_compare_at_price_raw = product.compare_at_price + endif + endif + + if settings.currency_code_enable + assign product_price_min = product_price_min_raw | money_with_currency + assign product_compare_at_price = product_compare_at_price_raw | money_with_currency + assign product_unit_price = product.unit_price | money_with_currency + else + assign product_price_min = product_price_min_raw | money + assign product_compare_at_price = product_compare_at_price_raw | money + assign product_unit_price = product.unit_price | money + endif + + unless grid_strings + assign grid_strings = "one-whole" + endunless + + assign border_class = '' + if settings.product_grid_outline == false + assign border_class = 'product-item--borderless' + endif + + assign alignment_class = '' + if settings.product_grid_center == true + assign alignment_class = 'product-item--centered' + endif +-%} + +{%- if settings.quickview_enable == false and settings.color_swatches -%} + {%- assign has_colors = false -%} + + {%- capture swatches -%} + {%- capture swatch_translation -%}{{ 'general.swatches.color' | t }}{%- endcapture -%} + + {%- assign swatch_labels = swatch_translation | append: ',' | split: ',' -%} + {%- for label in swatch_labels -%} + {%- assign sanitized_label = label | lstrip | rstrip -%} + {%- if product.options_by_name[sanitized_label].values.size > 0 -%} + {%- assign has_colors = true -%} + +
+ + {%- break -%} + {%- endif -%} + {%- endfor -%} + {%- endcapture -%} +{%- endif -%} + +{%- assign double_img = false -%} +{%- if product.media[1].preview_image and settings.image_hover_enable -%} + {%- assign double_img = true -%} +{%- endif -%} +{%- assign current_variant = product.first_available_variant -%} + +{%- assign product_url = product.url | within: collection -%} + +{%- capture item_unique -%}product-item--{{ section.id }}-{{ index }}{%- endcapture -%} +{%- assign animation_anchor_default = item_unique | prepend: '.' -%} +{%- assign animation_anchor = animation_anchor | default: animation_anchor_default -%} + +