Forum
Add to cart not working
Hi All
Add to cart on the product page is not working
but im using the same code on product details page and it works
Product page OR list.html ----- Not Working
<div class="buttons">
<div class="view-item">
<a href="/knives/products/<perch:shop id="slug" type="slug" />/">
<div class="button">
<i class="fa fa-search" aria-hidden="true"></i> View Details
</div>
</a>
</div>
<div class="buy-item">
<perch:if not-exists="has_variants">
<perch:form id="add_to_cart" app="perch_shop" action="/knives/cart">
<perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />
<perch:input type="submit" value=" Add to Basket" class="add-to-cart button" />
</perch:form>
</perch:if>
</div>
</div>
List_detail.html ---- Working
<div class="buttons-inner">
<div class="large-6 medium-6 small-12 columns">
<perch:if not-exists="has_variants">
<perch:form id="add_to_cart" app="perch_shop" action="/knives/cart">
<perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />
<perch:input type="submit" value=" Add to Basket" class="add-to-cart button left" />
</perch:form>
</perch:if>
</div>
<div class="large-6 medium-6 small-12 columns">
<perch:form id="add_to_cart" app="perch_shop" action="/knives/checkout">
<perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" />" />
<perch:input type="submit" value=" Buy Now" class="add-to-cart button right" />
</perch:form>
</div>
</div>
With some digging
the add to cart button would not work because of a form i had in no results
but not sure why
ok so required="true" on the form makes the add to cart not work
how can i get round this ?
i want the fields to be required but also have a working add to cart
What's the URL of your product page?
/knives/ displays the list of all products list.html
/knives/product/(slug) displays the item list_detail.html
Is your slug parameter named
product
? If so make sure you useenv-autofill="false"
to stop your hidden field calledproduct
being populated with that value.i have env-autofill="false" on all the add to cart and buy now buttons
but still not working
i think the slug parameter is product
You don't have it in your
list.html
template above.i currently have this in list.html
but not working
It needs to go on the
perch:input
tag.sooo like this
Yes, that's right.
ok that did not work
its like it is trying to submit the contact form in the no results still
if i remove required="true" from the contact form it all works
with required="true" on the contact form
if i click add to cart it takes me to the cart but does not add the product
and i debug this is displayed
if i remove required="true" from the contact form
and click add to cart it takes me to the cart adds tha product and that code is not in the debug
Contact form? I thought this was an add to cart form. What are you trying to achieve?
yes the contact form in the no-results is breaking the add to cart
list.html
the form at the bottom is stoping the add to cart working --- unless i remove required="true"
Ok, then you'll need to remove the contact form from the no results section.
so forms are not supported in the no results -- just text ?
They work, but you can see the obvious logic problem you're facing, right? If the form is only sometimes there, you can't have required fields, as they must always be present.
ah ok i see i will just remove the required part :)
Thanks