在JavaScript中使用数学液体变量

发布于 2025-01-17 09:08:23 字数 512 浏览 2 评论 0原文

我正在尝试获取可在 javascript 中使用的 Shopify 液体变量:

{% allocate gtfs = 39900 |减: cart.total_price | Money %}

在 JavaScript 中进一步:

var Feedback = '

' + html + {{ gtfs | json }} + '

';

但由于某种原因它总是返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念三年u 2025-01-24 09:08:23

我想我自己得到了。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文