diff --git a/snippets/price-list-alt-form-id.liquid b/snippets/price-list-alt-form-id.liquid new file mode 100644 index 0000000..1573be2 --- /dev/null +++ b/snippets/price-list-alt-form-id.liquid @@ -0,0 +1,248 @@ + + +{%- comment -%} +---------------------------------------------------------------------------------------------------------------------- +PRODUCT PRICE +---------------------------------------------------------------------------------------------------------------------- + +Render a list of price for a product, variant or line item. + +******************************************** +Supported variables +******************************************** + +* product: if provided, the prices are rendered for the whole product +* variant: if provided, then only the price from this variant is rendered +* line_item: if provided, then the price from this line item are rendered (used on cart or order) +* hide_unit_price: if set to true unit prices are hidden (mostly useful for size constrained elements) +* context: can be "product", "line_item" or "card". This controls how the prices are displayed (using the correct sizes) +* form_id: if specified, the prices are updated dynamically based on the form update +{%- endcomment -%} + +{%- liquid + case context + when 'card' or 'line_item' + assign base_text_class = '' + + if settings.product_card_text_font == 'heading' + assign base_text_class = 'h6 ' + endif + + assign regular_price_classes = base_text_class | append: 'text-subdued' + assign on_sale_price_classes = base_text_class | append: 'text-on-sale' + assign compare_at_price_classes = base_text_class | append: 'text-subdued line-through' + assign unit_price_classes = base_text_class | append: 'text-subdued' + + when 'product' + assign regular_price_classes = base_text_class | append: 'h4 text-subdued' + assign on_sale_price_classes = base_text_class | append: 'h4 text-on-sale' + assign compare_at_price_classes = base_text_class | append: 'h5 text-subdued line-through' + assign unit_price_classes = base_text_class | append: 'h6 text-subdued' + endcase +-%} + + + {% assign variant_case_price = variant.price %} + {% assign variant_case_compare_at_price = variant.compare_at_price %} + + {% if variant.metafields.app--168074346497.auto_discounted_price.value %} + {% if variant.metafields.app--168074346497.auto_discounted_price.value < variant_case_price %} + {% assign variant_case_price = variant.metafields.app--168074346497.auto_discounted_price.value %} + + {% if product.metafields.app--168074346497.discount_percentage.value > 0.01 %} + {% assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value %} + {% assign variant_case_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil %} + {% endif %} + + {% assign variant_case_compare_at_price = variant.price %} + + {% if variant.compare_at_price > variant.price %} + {% assign variant_case_compare_at_price = variant.compare_at_price %} + {% endif %} + {% endif %} + {% endif %} + {%- if variant != blank -%} + {%- comment -%} + -------------------------------------------------------------------------------------------------------------------- + VARIANT CASE (used on product page, quick view...) + -------------------------------------------------------------------------------------------------------------------- + {%- endcomment -%} + + {{ 'product.price.sale_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- variant_case_price | money_with_currency -}} + {%- else -%} + {{- variant_case_price | money -}} + {%- endif -%} + + + variant_case_price %}hidden{% endunless %} class="{{ compare_at_price_classes }} compare-price"> + {{ 'product.price.regular_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- variant_case_compare_at_price | money_with_currency -}} + {%- else -%} + {{- variant_case_compare_at_price | money -}} + {%- endif -%} + + {%- elsif line_item != blank -%} + {%- comment -%} + -------------------------------------------------------------------------------------------------------------------- + LINE ITEM CASE (used on cart, order page...) + -------------------------------------------------------------------------------------------------------------------- + {%- endcomment -%} + + {{ 'product.price.sale_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- line_item.final_line_price | money_with_currency -}} + {%- else -%} + {{- line_item.final_line_price | money -}} + {%- endif -%} + + + {%- if line_item.original_line_price > line_item.final_line_price -%} + + {{ 'product.price.regular_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- line_item.original_line_price | money_with_currency -}} + {%- else -%} + {{- line_item.original_line_price | money -}} + {%- endif -%} + + {%- endif -%} + {%- elsif product != blank -%} + {%- comment -%} + -------------------------------------------------------------------------------------------------------------------- + PRODUCT CASE (used on card) + -------------------------------------------------------------------------------------------------------------------- + {%- endcomment -%} + {%- liquid + if product.price_varies and settings.product_price_strategy != 'from_price' + assign variant = product.variants | sort: 'price' | last | default: product.selected_or_first_available_variant + else + assign variant = product.variants | sort: 'price' | first | default: product.selected_or_first_available_variant + endif + + if settings.currency_code_enabled + assign variant_price = variant.price | money_with_currency + assign variant_compare_at_price = variant.compare_at_price | money_with_currency + else + assign variant_price = variant.price | money + assign variant_compare_at_price = variant.compare_at_price | money + endif + + assign product_variant_price = variant.price + assign product_variant_compare_at_price = variant.compare_at_price + + if settings.product_price_strategy == 'from_price' and product.metafields.app--168074346497.min_auto_discounted_price.value + if product.metafields.app--168074346497.min_auto_discounted_price.value < variant.price + if settings.currency_code_enabled + assign variant_price = product.metafields.app--168074346497.min_auto_discounted_price.value | money_with_currency + + if product.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value + assign variant_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil | money_with_currency + endif + + assign variant_compare_at_price = variant.price | money_with_currency + + if variant.compare_at_price > variant.price + assign variant_compare_at_price = variant.compare_at_price | money_with_currency + endif + else + assign variant_price = product.metafields.app--168074346497.min_auto_discounted_price.value | money + + if product.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value + assign variant_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil | money + endif + + assign variant_compare_at_price = variant.price | money + + if variant.compare_at_price > variant.price + assign variant_compare_at_price = variant.compare_at_price | money + endif + endif + + assign product_variant_price = product.metafields.app--168074346497.min_auto_discounted_price.value + assign product_variant_compare_at_price = variant.price + + if variant.compare_at_price > variant.price + assign product_variant_compare_at_price = variant.compare_at_price + endif + endif + endif + -%} + + {%- if product.price_varies -%} + {%- assign is_variant_on_sale = false -%} + + {%- if product_variant_price < product_variant_compare_at_price -%} + {%- assign is_variant_on_sale = true -%} + {%- endif -%} + + {%- if settings.product_price_strategy == 'from_price' -%} + + {{ 'product.price.sale_price' | t }} + {{- 'product.price.from_price_html' | t: price_min: variant_price -}} + + {%- else -%} + + {{ 'product.price.sale_price' | t }} + {{- variant_price -}} + + {%- endif -%} + {%- else -%} + + {{ 'product.price.sale_price' | t }} + {{- variant_price -}} + + {%- endif -%} + + {%- if product_variant_price < product_variant_compare_at_price -%} + + {{ 'product.price.regular_price' | t }} + {{- variant_compare_at_price -}} + + {%- endif -%} + {%- else -%} + {%- comment -%} + -------------------------------------------------------------------------------------------------------------------- + PLACEHOLDER CASE (used on featured product section for instance) + -------------------------------------------------------------------------------------------------------------------- + {%- endcomment -%} + + + {{ 'product.price.sale_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- 4999 | money_with_currency -}} + {%- else -%} + {{- 4999 | money -}} + {%- endif -%} + + {%- endif -%} + + {%- unless hide_unit_price -%} + {%- assign unit_price_item = variant | default: line_item | default: product.selected_or_first_available_variant -%} + + {%- if unit_price_item.unit_price or form_id != blank -%} + + {%- assign unit_price_measurement = unit_price_item.unit_price_measurement -%} + + {%- if unit_price_measurement.reference_value != 1 -%} + {%- assign reference_value = unit_price_measurement.reference_value -%} + {%- endif -%} + + ({{ unit_price_item.unit_price | money }}/{{ reference_value }}{{ unit_price_measurement.reference_unit }}) + + {%- endif -%} + {%- endunless -%} + \ No newline at end of file