Add to Cart not working

by joey marchy - Member - 04:09PM, Aug 10, 2006

If I try to add to my cart, I get this error: http://pinhero.myshopify.com/cart/add

I have been looking at the source code of some other shopify sites and it appears I am missing the hidden form field that contains the id of the product to add to the cart:

[input type=”hidden” name=”id” value=”42” id=”radio_42” /]

I have enabled the test payment gateway, set up shipping rates, tax, etc. What am I missing?

Thank you!

daniel

jaded Pixel

08:51PM, Aug 10, 2006

Yeah, you are missing any kind of input field with the id of the product/variant that should be added to your cart.

Within your form, create a new input with

name="id"
and
value="{{variant.id}}"
where {{variant.id}} usually comes from an iteration through all of your product’s variants.

If you have only one variant per product, you can use a similar syntax being used in most of our standard themes:


<form action="/cart/add" method="post">

{% for variant in product.variants %}
   {% if variant.available == true %}
      <input type="hidden" name="id" value="{{variant.id}}" id="radio_{{variant.id}}">
      <input type="submit" name="add" value="Add to Cart" id="add" class="primary" />
   {% else %}
      Show something else here if product is not available anymore...
   {% endif %}
{% endfor %}

</form>

If you have more than one variant per product, you might want to check if it’s only one variant or more and if there are more render a combobox or a radio button selection of all your variants. Also you should move the submit button out of the first if or otherwise it will be rendered for each available variant you have.

You must login to post a comment!

Don't have an account yet? Sign up for one.