Add modified code

This commit is contained in:
Axel
2026-06-29 13:47:42 +08:00
parent 9faedaa44d
commit 539e579964
3 changed files with 143 additions and 35 deletions
+3 -2
View File
@@ -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.
+100 -27
View File
@@ -41,30 +41,77 @@ Supported variables
-%}
<price-list class="price-list {% if size == 'lg' %}price-list--lg{% endif %} {% if text_alignment == 'center' %}justify-center{% endif %}">
{%- 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 -%}
<sale-price class="{% if variant.compare_at_price > variant.price %}{{ on_sale_price_classes }}{% else %}{{ regular_price_classes }}{% endif %}">
<sale-price class="{% if variant_compare_at_price > variant_price %}{{ on_sale_price_classes }}{% else %}{{ regular_price_classes }}{% endif %}">
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
{%- 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 -%}
</sale-price>
{%- if variant.compare_at_price > variant.price -%}
{%- if variant_compare_at_price > variant_price -%}
<compare-at-price class="{{ compare_at_price_classes }}">
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
{%- 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 -%}
</compare-at-price>
{%- endif -%}
@@ -78,7 +125,7 @@ Supported variables
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
{%- 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
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
{%- 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 -%}
<compare-at-price class="{{ compare_at_price_classes }}">
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
{%- 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 -%}
</compare-at-price>
@@ -133,41 +206,41 @@ Supported variables
{{- 'product.price.from_price_html' | t: price_min: price_min -}}
</sale-price>
{%- endif -%}
{%- elsif product.price < product.compare_at_price -%}
<compare-at-price class="{{ compare_at_price_classes }}">
{%- elsif product_price < product_compare_at_price -%}
<compare-at-price class="{{ compare_at_price_classes }}">
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
{%- 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 -%}
</compare-at-price>
<sale-price class="{{ on_sale_price_classes }}">
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
{%- 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 -%}
</sale-price>
{%- 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
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
{%- 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 -%}
</sale-price>
{%- endif -%}
+40 -6
View File
@@ -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