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
+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