From ae8d2a071716176fbaa331950177fb2dba8c2b47 Mon Sep 17 00:00:00 2001 From: Axel Date: Sun, 9 Nov 2025 03:22:37 +0800 Subject: [PATCH] first commit --- snippets/price.liquid | 202 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 snippets/price.liquid diff --git a/snippets/price.liquid b/snippets/price.liquid new file mode 100644 index 0000000..3a19a54 --- /dev/null +++ b/snippets/price.liquid @@ -0,0 +1,202 @@ +{% comment %} + @param product {Object} [Required] + The product which we want to display the price for + + @param selected_variant {Variant} [Optional] + Renders selected variant instead of overall product pricing + + @param class {String} [Optional] + Adds any additional classes to the price element +{% endcomment %} + +{%- liquid + if selected_variant + assign current_product = selected_variant + else + assign current_product = product + endif + + assign compare_at_price = current_product.compare_at_price + assign price = current_product.price | default: 1999 + assign available = current_product.available | default: false + + if selected_variant + assign price = current_product.metafields.app--168074346497.auto_discounted_price.value | default: current_product.price + + if current_product.metafields.app--168074346497.discount_type.value != nil and current_product.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 current_product.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: current_product.metafields.app--168074346497.discount_percentage.value + endif + + assign price = current_product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + + assign compare_at_price = current_product.price + + if current_product.compare_at_price > compare_at_price + assign compare_at_price = current_product.compare_at_price + endif + endif + else + assign 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 price = product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + + assign compare_at_price = product.price + + if product.compare_at_price > compare_at_price + assign compare_at_price = product.compare_at_price + endif + endif + endif + + if price < current_product.price and compare_at_price == blank + assign compare_at_price = current_product.price + endif + + assign money_price = price | money + assign money_compare = compare_at_price | money + if settings.currency_code_enabled + assign money_price = price | money_with_currency + assign money_compare = compare_at_price | money_with_currency + endif + assign savings_varies = false + assign savings = blank + assign money_savings = blank + + if compare_at_price > price + if settings.price_savings_style == 'dollar' + assign savings = compare_at_price | minus: price + else + assign savings = price | times: 100 | divided_by: compare_at_price + assign savings = 100 | minus: savings + endif + endif + + if current_product == product + if current_product.price_varies + assign money_price = 'products.price.from_price' | t: price: money_price + endif + + if settings.price_show_saved and current_product.variants.size > 1 + for product_variant in current_product.variants + + assign product_variant_price = product_variant.price + assign product_variant_compare_at_price = product_variant.compare_at_price + + assign product_variant_price = product_variant.metafields.app--168074346497.auto_discounted_price.value | default: product_variant.price + + if product_variant.metafields.app--168074346497.discount_type.value != nil and product_variant.metafields.app--168074346497.discount_type.value != "fixed" and current_product.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: product_variant.metafields.app--168074346497.discount_percentage.value + + if product_variant.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: product_variant.metafields.app--168074346497.discount_percentage.value + endif + + assign product_variant_price = product_variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + + assign product_variant_compare_at_price = product_variant.price + + if product_variant.compare_at_price > product_variant_compare_at_price + assign product_variant_compare_at_price = product_variant.compare_at_price + endif + endif + + if product_variant_price < product_variant.price and product_variant_compare_at_price == blank + assign product_variant_compare_at_price = product_variant.price + endif + + if product_variant_compare_at_price > product_variant_price + if settings.price_savings_style == 'dollar' + assign variant_savings = product_variant_compare_at_price | minus: product_variant_price + else + assign variant_savings = product_variant_price | times: 100 | divided_by: product_variant_compare_at_price + assign variant_savings = 100 | minus: variant_savings + endif + if variant_savings != savings + assign savings_varies = true + endif + if variant_savings > savings + assign savings = variant_savings + endif + elsif savings > 0 + assign savings_varies = true + endif + endfor + endif + endif + + if savings != blank + if settings.price_savings_style == 'dollar' + assign money_savings = savings | money + + if settings.currency_code_enabled + assign money_savings = savings | money_with_currency + endif + else + assign money_savings = savings | append: '%' + endif + endif +-%} + +
+
+ {{ 'products.price.regular_price' | t }} + + {{ money_price }} + +
+
+ {%- if current_product.price_varies == blank or current_product.price_varies == false %} + {{ 'products.price.regular_price' | t }} + {{ money_compare }} + {%- endif -%} + {{ 'products.price.sale_price' | t }} + + {{ money_price }} + + + {% if settings.price_show_saved and savings != blank %} + + {% if savings_varies %} + {{ 'products.price.savings_up_to' | t: amount: money_savings }} + {% else %} + {{ 'products.price.savings' | t: amount: money_savings }} + {% endif %} + + {% endif %} +
+ + {% comment %} Unit prices need to be done on a variant, so we set current product to the first variant if none was provided {% endcomment %} + {% if selected_variant == blank %} + {% assign current_product = current_product.selected_or_first_available_variant %} + {% endif %} + + {% if current_product.unit_price_measurement != nil %} +
+ + {{ 'products.price.unit_price' | t }} + + {{- current_product.unit_price | money -}} + +  {{ 'products.price.unit_price_separator' | t }}  + + {%- if current_product.unit_price_measurement.reference_value != 1 -%} + {{- current_product.unit_price_measurement.reference_value -}} + {%- endif -%} + {{ current_product.unit_price_measurement.reference_unit }} + + + +
+ {% endif %} +
\ No newline at end of file