Shopify液体添加到购物车按钮

发布于 2025-02-03 20:45:38 字数 1467 浏览 2 评论 0原文

我是Shopify主题开发的新手,并且我从头开始建立一个主题以获得经验。我的产品页面上的“添加到购物车”按钮遇到了麻烦。即使我有各种产品的产品选项,我也只显示“大小”选项作为无线电按钮,然后将输入数量添加到购物车中。我现在面临的问题是,购物车一次只添加1个项目,因此,即使我将3或4作为我的数量输入,购物车也只会添加1个作为数量。 这是我的代码:

{% form 'product', product %}
        <div>
            <p class="option-title">Size</p>
            <div class="line"></div>
            <div class="options">
                {% for product_option in product.options_by_name['Size'].values %} 
                    <input type="radio" id = "{{ product_option }}" name="size" value="{{ product_option }}" > 
                    <label for="{{ product_option }}">{{ product_option }}</label> 
                {% endfor %}
            </div>
        </div>

        <div class="line"></div>

        <div class="quantity-add">
            <div class="input-quantity">
                <input class="input-quantity" type="number" min="1" placeholder="1"> 
                <input type="hidden" name="id" data-productid="{{ product.variants[0].id }}" value="{{ product.variants[0].id }}" data-variant-title="{{ product.variants[0].title }}" />
            </div>
            <div class="cart-button">
                <button class="cart-btn" type="submit" value="Add To Cart">ADD</button> 
            </div>
        </div>     
    {% endform %}

任何帮助都将不胜感激。我对应该如何解决它感到非常迷失。

I am new to shopify theme development and I'm building a theme from scratch to gain experience. I'm having trouble with the 'add to cart' button on my product page. Even though I have various product options for a product, I am only displaying the 'size' options as radio buttons and then I take an input quantity and add it to the cart. The problem I am facing right now, is that the cart only adds 1 item at a time, So even if I input 3 or 4 as my quantity, the cart only adds 1 as the quantity.
here's my code:

{% form 'product', product %}
        <div>
            <p class="option-title">Size</p>
            <div class="line"></div>
            <div class="options">
                {% for product_option in product.options_by_name['Size'].values %} 
                    <input type="radio" id = "{{ product_option }}" name="size" value="{{ product_option }}" > 
                    <label for="{{ product_option }}">{{ product_option }}</label> 
                {% endfor %}
            </div>
        </div>

        <div class="line"></div>

        <div class="quantity-add">
            <div class="input-quantity">
                <input class="input-quantity" type="number" min="1" placeholder="1"> 
                <input type="hidden" name="id" data-productid="{{ product.variants[0].id }}" value="{{ product.variants[0].id }}" data-variant-title="{{ product.variants[0].title }}" />
            </div>
            <div class="cart-button">
                <button class="cart-btn" type="submit" value="Add To Cart">ADD</button> 
            </div>
        </div>     
    {% endform %}

Any help will be much appreciated. I am so lost regarding how I should fix it.

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

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

发布评论

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

评论(1

池木 2025-02-10 20:45:38

如果您在输入元素中添加正确的name value 属性,则应正常工作:

<input name="quantity" value="3">

这将使所选的变体ID添加到购物车中。

It should work fine if you add the proper name and value attribute to your input element:

<input name="quantity" value="3">

This would add the selected variant ID three times to the cart.

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