From 539e579964275f11af005a840999dd095822c849 Mon Sep 17 00:00:00 2001 From: Axel Date: Mon, 29 Jun 2026 13:47:42 +0800 Subject: [PATCH] Add modified code --- README.md | 5 +- snippets/price-list.liquid | 127 ++++++++++++++++++++++++++------- snippets/product-badges.liquid | 46 ++++++++++-- 3 files changed, 143 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 8d0ffc3..712dd49 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # README -To show discounted price on the collection page, kindly reference the files below (you can navigate from the browser UI above) - +To show discounted price on the collection page, kindly reference the files below (you can navigate from the browser UI above) , you can copy paste the code and replace the existing code on your store theme. +1. snippets/price-list.liquid +2. snippets/product-badges.liquid The code below is for store specific product page widget configuration reference , you do not need to do anything with the code below. diff --git a/snippets/price-list.liquid b/snippets/price-list.liquid index b87a807..0a024fc 100644 --- a/snippets/price-list.liquid +++ b/snippets/price-list.liquid @@ -41,30 +41,77 @@ Supported variables -%} + {%- liquid + assign product_price = product.price + assign product_price_min = product.price_min + assign product_price_max = product.price_max + assign product_compare_at_price = 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 = product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + assign product_price_min = product_price + assign product_price_max = product.price_max | 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 + elsif product.metafields.app--168074346497.min_auto_discounted_price.value > 0.01 + assign product_price = product.metafields.app--168074346497.min_auto_discounted_price.value + assign product_price_min = product_price + 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 + -%} {%- if variant != blank -%} + {%- liquid + assign variant_price = variant.price + assign variant_compare_at_price = 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 + elsif variant.metafields.app--168074346497.discount_type.value == "fixed" + assign variant_price = variant.metafields.app--168074346497.auto_discounted_price.value + 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 + -%} {%- comment -%} -------------------------------------------------------------------------------------------------------------------- VARIANT CASE (used on product page, quick view...) -------------------------------------------------------------------------------------------------------------------- {%- endcomment -%} - + {{ 'product.price.sale_price' | t }} {%- if settings.currency_code_enabled -%} - {{- variant.price | money_with_currency -}} + {{- variant_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} - {{- variant.price | money | replace: 'MYR', '' -}} + {{- variant_price | money | replace: 'MYR', '' -}} {%- endif -%} - {%- if variant.compare_at_price > variant.price -%} + {%- if variant_compare_at_price > variant_price -%} {{ 'product.price.regular_price' | t }} {%- if settings.currency_code_enabled -%} - {{- variant.compare_at_price | money_with_currency -}} + {{- variant_compare_at_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} - {{- variant.compare_at_price | money | replace: 'MYR', '' -}} + {{- variant_compare_at_price | money | replace: 'MYR', '' -}} {%- endif -%} {%- endif -%} @@ -78,7 +125,7 @@ Supported variables {{ 'product.price.sale_price' | t }} {%- if settings.currency_code_enabled -%} - {{- line_item.final_line_price | money_with_currency -}} + {{- line_item.final_line_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} {{- line_item.final_line_price | money | replace: 'MYR', '' -}} {%- endif -%} @@ -89,7 +136,7 @@ Supported variables {{ 'product.price.regular_price' | t }} {%- if settings.currency_code_enabled -%} - {{- line_item.original_line_price | money_with_currency -}} + {{- line_item.original_line_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} {{- line_item.original_line_price | money | replace: 'MYR', '' -}} {%- endif -%} @@ -104,22 +151,48 @@ Supported variables {%- if product.price_varies and product.compare_at_price -%} {%- assign cheapest_variant = product.variants | sort: 'price' | first -%} + {%- liquid + assign cheapest_variant_price = cheapest_variant.price + assign cheapest_variant_compare_at_price = cheapest_variant.price + + if cheapest_variant.metafields.app--168074346497.discount_type.value != nil and cheapest_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 cheapest_variant.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: cheapest_variant.metafields.app--168074346497.discount_percentage.value + endif + + assign cheapest_variant_price = cheapest_variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + assign cheapest_variant_compare_at_price = cheapest_variant.price + if cheapest_variant.compare_at_price > cheapest_variant_compare_at_price + assign cheapest_variant_compare_at_price = cheapest_variant.compare_at_price + endif + elsif cheapest_variant.metafields.app--168074346497.discount_type.value == "fixed" + assign cheapest_variant_price = cheapest_variant.metafields.app--168074346497.auto_discounted_price.value + assign cheapest_variant_compare_at_price = cheapest_variant.price + if cheapest_variant.compare_at_price > cheapest_variant_compare_at_price + assign cheapest_variant_compare_at_price = cheapest_variant.compare_at_price + endif + endif + -%} + {%- capture price_min -%} {%- if settings.currency_code_enabled -%} - {{- cheapest_variant.price | money_with_currency -}} + {{- cheapest_variant_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} - {{- cheapest_variant.price | money | replace: 'MYR', '' -}} + {{- cheapest_variant_price | money | replace: 'MYR', '' -}} {%- endif -%} {%- endcapture -%} - {%- if cheapest_variant.price < cheapest_variant.compare_at_price -%} + {%- if cheapest_variant_price < cheapest_variant_compare_at_price -%} + {{ 'product.price.regular_price' | t }} {%- if settings.currency_code_enabled -%} - {{- cheapest_variant.compare_at_price | money_with_currency -}} + {{- cheapest_variant_compare_at_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} - {{- cheapest_variant.compare_at_price | money | replace: 'MYR', '' -}} + {{- cheapest_variant_compare_at_price | money | replace: 'MYR', '' -}} {%- endif -%} @@ -133,41 +206,41 @@ Supported variables {{- 'product.price.from_price_html' | t: price_min: price_min -}} {%- endif -%} - {%- elsif product.price < product.compare_at_price -%} - + {%- elsif product_price < product_compare_at_price -%} + {{ 'product.price.regular_price' | t }} {%- if settings.currency_code_enabled -%} - {{- product.compare_at_price | money_with_currency -}} + {{- product_compare_at_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} - {{- product.compare_at_price | money | replace: 'MYR', '' -}} + {{- product_compare_at_price | money | replace: 'MYR', '' -}} {%- endif -%} + {{ 'product.price.sale_price' | t }} {%- if settings.currency_code_enabled -%} - {{- product.price | money_with_currency -}} + {{- product_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} - {{- product.price | money | replace: 'MYR', '' -}} + {{- product_price | money | replace: 'MYR', '' -}} {%- endif -%} - - + {%- elsif product.price_varies -%} {%- capture price_min -%} {%- if settings.currency_code_enabled -%} - {{ product.price_min | money_with_currency | replace: 'MYR', ''}} + {{ product_price_min | money_with_currency | replace: 'MYR', '' }} {%- else -%} - {{ product.price_min | money | replace: 'MYR', '' }} + {{ product_price_min | money | replace: 'MYR', '' }} {%- endif -%} {%- endcapture -%} {%- capture price_max -%} {%- if settings.currency_code_enabled -%} - {{- product.price_max | money_with_currency -}} + {{- product_price_max | money_with_currency | replace: 'MYR', '' -}} {%- else -%} - {{- product.price_max | money | replace: 'MYR', '' -}} + {{- product_price_max | money | replace: 'MYR', '' -}} {%- endif -%} {%- endcapture -%} @@ -180,9 +253,9 @@ Supported variables {{ 'product.price.sale_price' | t }} {%- if settings.currency_code_enabled -%} - {{- product.price | money_with_currency -}} + {{- product_price | money_with_currency | replace: 'MYR', '' -}} {%- else -%} - {{- product.price | money | replace: 'MYR', '' -}} + {{- product_price | money | replace: 'MYR', '' -}} {%- endif -%} {%- endif -%} diff --git a/snippets/product-badges.liquid b/snippets/product-badges.liquid index 0e63281..5f862d2 100644 --- a/snippets/product-badges.liquid +++ b/snippets/product-badges.liquid @@ -46,25 +46,59 @@ Supported variables {%- 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 + if variant_compare_at_price > variant_price assign show_on_sale_badge = true endif elsif context == 'card' - if product.compare_at_price > product.price + if product_compare_at_price > product_price assign show_on_sale_badge = true endif endif -%} - {%- if product.compare_at_price > product.price -%} + {%- 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: '%' -%} + {%- 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 -%} + {%- capture savings -%}{{ variant_compare_at_price | minus: variant_price | money }}{%- endcapture -%} {%- endif -%} {%- if show_on_sale_badge -%} @@ -73,7 +107,7 @@ Supported variables 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 + 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