交响乐团js:按钮在某些情况下不起作用

发布于 2025-01-09 14:40:35 字数 2570 浏览 0 评论 0原文

我在 shopware6 网站(版本 6.4.8.1)的产品详细信息页面上有一个简单的产品数量“加/减”功能(参见附图)在此处输入图像描述

在此处查看我的代码/views/storefront/page/product-detail/buy-widget-form.html.twig。

{% block page_product_detail_buy_quantity_container %}
<div class="col-12 quantity-container">
    <div class="row">
        <div class="col-5 col-md-3 label-quantity">
            <span>{{ "detail.labelQuantity"|trans|sw_sanitize }}</span>
        </div>
         <div class="col-7 col-md-9 quantity-input-panel">
                    {% block page_product_detail_buy_quantity %}
                            <div class="quantity-inner">
                                    <span class="min button" id="moins" {#onclick="minus()"#}> {% sw_icon 'minus' %} </span>
                                    <input id="amountToBasket" type="text" name="lineItems[{{ page.product.id }}][quantity]" value="{{product.minPurchase}}" autocomplete="off" maxlength="2" class="form-control">
                                    <input id="minPurchase" type="hidden" name="minPurchase" value="{{product.minPurchase}}" autocomplete="off" class="form-control">
                                    <input id="maxRange" type="hidden" name="maxRange" value="{{product.calculatedMaxPurchase}}" autocomplete="off" class="form-control">
                                    <input id="purchaseSteps" type="hidden" name="purchaseSteps" value="{{product.purchaseSteps}}" autocomplete="off" class="form-control">
                                    <span class="plus button" id="plus" {#onclick="plus()"#}> {% sw_icon 'plus' %}</span>
                            </div>
                    {% endblock %}
        </div>
    </div>
</div>
{% endblock %}

这是我与加号/减号按钮相关的 js 文件。

var minPurchase = $("#minPurchase").val();
var maxRange = $("#maxRange").val();
var count = $("#amountToBasket").val();

$("#plus").click(function () {
    if (count < maxRange){
        count++;

        $("#amountToBasket").val(count);
    }
});

$("#moins").click(function () {
    if (count > minPurchase){
        count--;

        $("#amountToBasket").val(count);
    }
});

问题:这对于最低购买数量等于至1的所有产品都非常有效。但是,如果我们点击最小购买数量大于1的每种产品的加号或减号,则不会执行任何操作。在这种情况下,给人的印象是按钮已停用。

你知道发生了什么事吗?

I have a simple "plus/minus" functionality for the product quantity on the product detail page on a shopware6 site (version 6.4.8.1) (See attached image) enter image description here

See here my code in /views/storefront/page/product-detail/buy-widget-form.html.twig.

{% block page_product_detail_buy_quantity_container %}
<div class="col-12 quantity-container">
    <div class="row">
        <div class="col-5 col-md-3 label-quantity">
            <span>{{ "detail.labelQuantity"|trans|sw_sanitize }}</span>
        </div>
         <div class="col-7 col-md-9 quantity-input-panel">
                    {% block page_product_detail_buy_quantity %}
                            <div class="quantity-inner">
                                    <span class="min button" id="moins" {#onclick="minus()"#}> {% sw_icon 'minus' %} </span>
                                    <input id="amountToBasket" type="text" name="lineItems[{{ page.product.id }}][quantity]" value="{{product.minPurchase}}" autocomplete="off" maxlength="2" class="form-control">
                                    <input id="minPurchase" type="hidden" name="minPurchase" value="{{product.minPurchase}}" autocomplete="off" class="form-control">
                                    <input id="maxRange" type="hidden" name="maxRange" value="{{product.calculatedMaxPurchase}}" autocomplete="off" class="form-control">
                                    <input id="purchaseSteps" type="hidden" name="purchaseSteps" value="{{product.purchaseSteps}}" autocomplete="off" class="form-control">
                                    <span class="plus button" id="plus" {#onclick="plus()"#}> {% sw_icon 'plus' %}</span>
                            </div>
                    {% endblock %}
        </div>
    </div>
</div>
{% endblock %}

And here's my js file related to the plus/minus buttons.

var minPurchase = $("#minPurchase").val();
var maxRange = $("#maxRange").val();
var count = $("#amountToBasket").val();

$("#plus").click(function () {
    if (count < maxRange){
        count++;

        $("#amountToBasket").val(count);
    }
});

$("#moins").click(function () {
    if (count > minPurchase){
        count--;

        $("#amountToBasket").val(count);
    }
});

PROBLEM : This works perfectly for ALL products where the minimum purchase quantity is equal to 1. BUT if we click on the plus or the minus for every product having the minimum purchase quantity greater than 1, it's doing nothing. It gives the impression that the buttons are deactivated in this case.

Do you have any clue on what is going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

巷雨优美回忆 2025-01-16 14:40:35

正如@DarkBee 回复的那样,我只需要指定“count”函数的值类型。

var count = parseInt($("#amountToBasket").val());

as replied by @DarkBee, I simply needed to specify the value type of the "count" function.

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