Hello friends. Both Google Gemini Pro and I cannot solve this issue. ![]()
- I use GemPages to edit my Product pages. (not highly relevant)
- I have 2 metafields that I need to use: variant.metafields.custom.var_onsale (true/false) and variant.metafields.custom.var_percentage (Integer).
- On my Product pages (templates) I add a Liquid code to achieve 1 thing. The Sale Price. This liquid code should calculate that value very simply. But it does not. Am I missing something? (Is Google Gemini Pro missing something?)
- This is only needed on Products with multiple Variants, and ideally, I need the Sale Price for the selected Variant is shown.
- I have verified the data in the metafields is valid and present.
Sample Output:
- on_sale = ‘true’
- discount_percentage = i.e. 25
- original_price (variant.price) = i.e. 80.31
- discount_amount is broken down to small parts on purpose. It still returns 0.0 both times. Should be 20.08
- and sale_price = original_price (i.e. 8031) - wrong. Should be 60.23 (hand calculated)
{% for variant in product.variants %}
{% assign on_sale = variant.metafields.custom.var_onsale %}
{% assign discount_percentage = variant.metafields.custom.var_percentage.value | append: '' | plus: 0 %}
Raw percentage value: {{ variant.metafields.custom.var_percentage.value }}
{% if variant.metafields.custom.var_onsale %}
{% assign original_price = variant.price %}
{% assign discount_amount = discount_percentage.0 | times: 0.01 %}
{{discount_amount}} -
{% assign discount_amount = original_price | times: discount_amount %}
{{discount_amount}} -
{% assign sale_price = original_price | minus: discount_amount %}
{{sale_price}}
Sale Price: {{ sale_price }}
{% else %}
{% assign sale_price = variant.price %}
Original Sale Price: {{ sale_price }}
{% endif %}
<div class="product-price" data-variant-id="{{ variant.id }}">
{% if sale_price != variant.price %}
<span class="original-price">{{ variant.price | money }}</span>
<span class="sale-price">{{ sale_price | money }}</span>
{% else %}
<span class="price">{{ sale_price | money }}</span>
{% endif %}
</div>
<script>// Inside the updatePrice function
console.log("Metafield value:", variant.metafields.custom.var_percentage.value);
console.log("Type:", typeof variant.metafields.custom.var_percentage.value);
</script>
{% endfor %}
<div id="product-price-container">
</div>

