在JavaScript中使用数学液体变量
我正在尝试获取可在 javascript 中使用的 Shopify 液体变量:
{% allocate gtfs = 39900 |减: cart.total_price | Money %}
在 JavaScript 中进一步:
' + html + {{ gtfs | json }} + 'var Feedback = '
但由于某种原因它总是返回 399,00。 就像分配 gtfs 时它不会接受顶部部分中完成的数学运算一样。
我尝试在脚本中插入 cart.total_price (只是为了检查变量是否存在) - 这会按预期返回购物车值。
但我需要从 399 中扣除购物车价值并显示该金额(以显示达到免运费的金额) - 例如“您距离免运费只有 172 丹麦克朗”。
I am trying to get a Shopify liquid variable available for use in a javascript:
{% assign gtfs = 39900 | minus: cart.total_price | money %}
Further down in the javascript:
var feedback = '<div class="added-to-cart" id="ajaxify"><p class="ajaxified-cart-feedback ' + success + '">' + html + {{ gtfs | json }} + '</p></div>';
But for some reason it always returns 399,00.
It is like it won't accept the math done in the top part when assigning gtfs.
I tried inserting cart.total_price instead in the script (just to check if the variable was present) - which returns the cart value as intended.
But I need to deduct the cart value from 399 and show that amount (to show how much up to free shipping) - e.g. "You are only 172 DKK away from free shipping".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我自己得到了。 Liquid 变量已加载到 DOM 中 - 因此在添加到购物篮时不会更新,因此我必须寻找事件侦听器。
谢谢。
I think I got it myself. The liquid variable is loaded in the DOM - hence not updated upon add-to-basket, so I will have to look for event listeners.
Thanks.