diff --git a/snippets/product-item.liquid b/snippets/product-item.liquid index 46f91b8..a7d4907 100644 --- a/snippets/product-item.liquid +++ b/snippets/product-item.liquid @@ -1,10 +1,18 @@ +{%- doc -%} + Renders a product item. + + @param {object} prod - The product object. We use 'prod' to avoid collision with the global 'product' object. + @param {string} product_columns_desktop - The number of columns in the product grid on desktop. + @param {string} product_columns_mobile - The number of columns in the product grid on mobile. + @param {string} aspect_ratio - The image aspect ratio. + @param {boolean} [has_grid_reveal] - Whether the item should animate. + @param {string} custom_color_key_map - A list of custom color names for swatches. + @param {string} custom_color_value_map - A list of custom color values for swatches. + @param {boolean} [quick_view_is_beneath] - Whether the quick view displays below the product info (instead of overlayed on the image). + @param {boolean} [placeholder] - Whether the item is being rendered as a placeholder. +{%- enddoc -%} + {%- liquid - comment - pass in : - - * prod (product but avoiding collision with globally scoped product) - endcomment - assign prod_compare_at_price = prod.compare_at_price assign prod_price = prod.price @@ -22,17 +30,17 @@ endif endif - assign show_multiple_images = false + assign has_grid_reveal = has_grid_reveal | default: false, allow_false: true + assign quick_view_is_beneath = quick_view_is_beneath | default: false, allow_false: true + assign placeholder = placeholder | default: false, allow_false: true + if settings.product_listing_show_second_image_on_hover and prod.media.size > 1 assign show_multiple_images = true + else + assign show_multiple_images = false endif - assign current_variant = prod.selected_or_first_available_variant - - assign mobile_column_count = 2 - if product_columns_mobile == 1 - assign mobile_column_count = 1 - endif + assign mobile_column_count = product_columns_mobile | plus: 0 case product_columns_desktop when '5' @@ -57,7 +65,6 @@ assign show_sibling_swatches = true assign first_swatchified_option = settings.siblings_option_name | downcase assign displayed_swatch_count = sibling_products.size - elsif settings.enable_product_card_swatches capture first_swatchified_option render 'get-first-styled-option', prod: prod, styled_options: settings.swatch_options @@ -107,7 +114,6 @@ capture quick_shop_button_hoverless_icon render 'icon', icon: 'quick-add' endcapture - elsif settings.enable_quick_view assign quick_shop_type = 'quick-view' assign quick_shop_button_text = 'products.product.quick_view' | t @@ -120,20 +126,22 @@ endif -%} -{% if quick_shop_type != 'none' %} - {% capture quick_shop_button_attributes %} - data-quick-shop-trigger="{{ quick_shop_type }}" +{%- if quick_shop_type != 'none' -%} + {%- liquid + capture quick_shop_button_attributes + echo 'data-quick-shop-trigger="[[qst]]"' | replace: '[[qst]]', quick_shop_type - {% if quick_shop_type == 'quick-add' %} - data-product-id="{{ prod.variants[0].id }}" - {% else %} - data-product-url="{{ prod.url }}" - {% endif %} - {% endcapture %} + if quick_shop_type == 'quick-add' + echo 'data-product-id="[[pid]]"' | replace: '[[pid]]', prod.variants[0].id + else + echo 'data-product-url="[[pu]]"' | replace: '[[pu]]', prod.url + endif + endcapture + -%} - {% capture quick_shop_button %} + {%- capture quick_shop_button -%} - {% endcapture %} + {%- endcapture -%} - {% capture quick_shop_button_hoverless %} + {%- capture quick_shop_button_hoverless -%} - {% endcapture %} -{% endif %} + {%- endcapture -%} +{%- endif -%} -{% liquid - # wrap add-to-cart buttons in a product form for no-js or if purchase confirmation and quick cart are disabled +{%- liquid + # Wrap add to cart buttons in a product form for no-js, or if purchase confirmation and quick cart are disabled if quick_shop_type == 'quick-add' capture product_form_tags echo '' | replace: '[[vi]]', prod.variants[0].id @@ -178,100 +186,121 @@ endform endcapture endif -%} + + capture product_item_class + echo 'product-item' + + if has_hover_swatches + echo ' product-item--with-hover-swatches' + endif + + if has_hover_chips + echo ' product-item--with-hover-chips' + endif + + if settings.enable_border_on_hover + echo ' product-item--border-on-hover' + endif + + echo ' animation animation--item' + + if has_grid_reveal + echo ' animation--item-initial' + endif + endcapture +-%}