{%- comment -%} ---------------------------------------------------------------------------------------------------------------------- PRODUCT BADGES COMPONENT ---------------------------------------------------------------------------------------------------------------------- This component is used in product listing and product page to render the badges of a given product ******************************************** Supported variables ******************************************** * product: the product to render the badges * variant: the specific variant to show the badge from * types: the types of badge to output. Can be "custom", "sold_out" or "discount" (or a combination separated by comma). If nothing is set, all badges are outputted. * context: can be "product" or "card" * class: an extra class added on the container {%- endcomment -%} {%- assign badge_types = types | default: 'custom, sold_out, discount' | split: ',' -%} {%- assign variant = variant | default: product.selected_or_first_available_variant -%} {%- capture badges -%} {%- for badge_type in badge_types -%} {%- assign stripped_badge_type = badge_type | strip -%} {%- case stripped_badge_type -%} {%- when 'custom' -%} {%- assign custom_badges = product.metafields.custom.badges.value | sort -%} {%- for custom_badge in custom_badges -%} {{ custom_badge }} {%- endfor -%} {%- when 'sold_out' -%} {%- if settings.show_sold_out_badge -%} {%- if variant.available == false -%} {{- 'product.general.sold_out_badge' | t -}} {%- elsif product.tags contains 'preorder' -%} {{- 'product.general.pre_order_button' | t -}} {%- endif -%} {%- endif -%} {%- when 'discount' -%} {%- if settings.show_discount -%} {%- liquid assign variant_price = variant.metafields.app--168074346497.auto_discounted_price.value | default: variant.price if variant.metafields.app--168074346497.discount_type.value != nil and variant.metafields.app--168074346497.discount_type.value != "fixed" and product.metafields.app--168074346497.discount_percentage.value > 0.01 assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value if variant.metafields.app--168074346497.discount_percentage.value > 0.01 assign deducted_percentage = 1.0 | minus: variant.metafields.app--168074346497.discount_percentage.value endif assign variant_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil assign variant_compare_at_price = variant.price if variant.compare_at_price > variant_compare_at_price assign variant_compare_at_price = variant.compare_at_price endif endif 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 -%} {%- liquid assign show_on_sale_badge = false if context == 'product' if variant_compare_at_price > variant_price assign show_on_sale_badge = true endif elsif context == 'card' if product_compare_at_price > product_price assign show_on_sale_badge = true endif endif -%} {%- if product_compare_at_price > product_price -%} {%- if settings.discount_mode == 'percentage' -%} {%- assign savings = variant_compare_at_price | minus: variant_price | times: 100.0 | divided_by: variant_compare_at_price | round | append: '%' -%} {%- else -%} {%- capture savings -%}{{ variant_compare_at_price | minus: variant_price | money }}{%- endcapture -%} {%- endif -%} {%- if show_on_sale_badge -%} {%- liquid if context == 'product' echo 'product.general.discount_badge_html' | t: savings: savings elsif context == 'card' if product.compare_at_price_varies or variant_compare_at_price == blank echo 'product.general.on_sale_badge' | t else echo 'product.general.discount_badge_html' | t: savings: savings endif endif -%} {%- endif -%} {%- endif -%} {%- endif -%} {% if product.metafields.custom.z21_product_label != blank %}

{{ product.metafields.custom.z21_product_label }}

{% endif %} {%- endcase -%} {%- endfor -%} {%- endcapture -%} {%- if badges != blank -%}
{{- badges -}}
{%- endif -%}