Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Product Item Count

Solved

Product Item Count

MohammadAL
Shopify Partner
21 0 1

Hey, I am making a theme for shopify, and i wanna add a radio button to change the quantity of the item when i wanna buy, i tried doing this, but it didn't work, when i click add to cart, the number always adds 1 only.

        {% assign myProduct = all_products['ems'] %}
        {% if myProduct %}
            <form action="/cart/add" method="post" enctype="multipart/form-data">
            <input type="hidden" name="id" value="{{ myProduct.variants.first.id }}" />
        {% assign productTwo = product.price | times: 160 | divided_by: 100 |  money_without_currency | floor %}
        {% assign productTwoCompare =  product.price | times: 2 | money_without_currency %}
        {% assign productFour = product.price | times: 320 | divided_by: 120 |  money_without_currency | floor %}
        {% assign productFourCompare =  product.price | times: 4 | money_without_currency %}
            <div class="q-radios">
                                <span class="radio-title">Quantity:</span>
                <label for="1">
                    <div class="quantity-radio">
                        <input type="radio" name="quantity" value="1" checked id="1">
                        <p>Buy 1: <span class="current-price">${{ product.price | money_without_currency | floor }}.00
                        </div>
                </label>
                <label for="2">
                    <div class="quantity-radio">
                        <input type="radio" name="quantity" value="1" id="2">
                        <p>Buy 2: <span class="current-price">${{ productTwo }}.00</span>
                        <span class="compare-price">${{ productTwoCompare }}.00</span></p>
                        <span class="save">
                            <span>save ${{ productTwoCompare | minus: productTwo }}</span>
                        </span>
                        </div>
                </label>
                <label for="3">
                    <div class="quantity-radio">
                        <input type="radio" name="quantity" value="1" id="3">
                        <p>Buy 4: <span class="current-price">${{ productFour }}.00</span>
                        <span class="compare-price">${{ productFourCompare }}.00</span></p>
                        <span class="save">
                            <span>save ${{ productFourCompare | minus: productFour }}</span>
                        </span>
                        </div>
                </label>
       
            </div>
            <button type="submit" class="cart-btn"> <i class="fa-solid fa-bag-shopping"></i> Add to Cart</button>
            <div class="payment-types">
                {% assign enabled_payment_types = 'visa,master,american_express,paypal' | remove: ' ' | split: ',' %}

                {% for payment_type in enabled_payment_types %}
                    {{ payment_type | payment_type_svg_tag }}
                {% endfor %}
            </div>
            <p id="safe-checkout">Guaranteed safe & secure checkout</p>
        </form>



any help?
Accepted Solution (1)

Liam
Community Manager
3108 344 889

This is an accepted solution.

Hi MohammadAL,

 

I believe the issue could be due to the value attribute for each of your radio buttons. You have the value attribute of all your radio buttons set to "1". This means no matter which option you select, you're only adding 1 item to the cart. You'll need to change this to correspond to the value that each option requires.

 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

Liam
Community Manager
3108 344 889

This is an accepted solution.

Hi MohammadAL,

 

I believe the issue could be due to the value attribute for each of your radio buttons. You have the value attribute of all your radio buttons set to "1". This means no matter which option you select, you're only adding 1 item to the cart. You'll need to change this to correspond to the value that each option requires.

 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog