Use maximum discount percentage from variants

Use maximum discount percentage from variants
This commit is contained in:
2026-04-15 19:07:57 +00:00
parent 6fb1381567
commit fcd7276ce8
+16 -2
View File
@@ -265,9 +265,23 @@
<!-- discount percentage raw value is {{ percentage }} , {{ sale_text }} --> <!-- discount percentage raw value is {{ percentage }} , {{ sale_text }} -->
{% assign text = sale_text | replace: "[percentage]", percentage | replace: ".0", "" %} {% assign text = sale_text | replace: "[percentage]", percentage | replace: ".0", "" %}
{% elsif compare_at_price > price %} {% elsif compare_at_price > price %}
{% assign tmp_percentage = price | times: 1.0 | divided_by: compare_at_price | times: 100 | floor %} {% assign max_discount = 0 %}
{% for variant in product.variants %}
{% if variant.compare_at_price > variant.price %}
{% assign discount = variant.compare_at_price | minus: variant.price %}
{% assign discount_percent = discount | times: 100.0 | divided_by: variant.compare_at_price | round %}
{% if discount_percent > max_discount %}
{% assign max_discount = discount_percent %}
{% endif %}
{% endif %}
{% endfor %}
{% comment %}
{% assign tmp_percentage = tmp_price_max | times: 1.0 | divided_by: tmp_compare_at_price_max | times: 100 | floor %}
{% assign percentage = 100.0 | minus: tmp_percentage | floor %} {% assign percentage = 100.0 | minus: tmp_percentage | floor %}
{% assign text = sale_text | replace: "[percentage]", percentage | replace: ".0", "" %} {% endcomment %}
{% assign text = sale_text | replace: "[percentage]", max_discount | replace: ".0", "" %}
{% endif %} {% endif %}
{%- liquid {%- liquid