Forum
Add to cart. Nothing happening. I'm stuck.
I'm implementing Shop on an existing Perch site. I've been struggling through so far getting product lists and products working. I'm now trying to implement the Cart but despite using only (copies of) default templates, I'm stuck.
Here's my 'Add to cart' form:
<perch:form id="add_to_cart" app="perch_shop" action="/shop/basket">
<perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
<perch:input type="submit" class="button" value="Add to cart" />
</perch:form>
Submitting the form on a product page (or list), takes me to the shop/basket/index.php
page where I have:
perch_shop_cart();
But I just see the 'Your cart is empty' message. It appears items aren't being added and product_count
is not greater than 0.
Am I missing a crucial step between the 'Add to Cart' form and the perch_shop_cart()
function? I feel like I must be. Should there be something in between that explicitly adds the productID to the cart?
I'm no PHP master. In fact I'm pretty basic, but I've always managed fine with plain-ol-Perch. Really struggling to get my head around Shop though. Any help appreciated.
If you view source on the form in your browser, do you see the hidden field populated with the numeric product ID?
Yep.
I tried adding this to the cart page to see what happened:
perch_shop_add_to_cart(2)
and that seems to break the cart. It doesn't render the cart template or anything after it in the source.
Huh. Weird. Is there anything in your error log?
If you turn on debug, does that reveal anything?
Here's the debug output from the Cart page when accessed through a
add_to_cart
form:I don't know about you but that's not telling me much. :-/
Nothing goin on in the PHP error log.
This is the error when I try the
perch_shop_add_to_cart(2)
though:I don't know if that's relevant or not.
Have you set up a tax group and added the product to that group?
Ah! I hadn't. For some reason I'd removed the tax-group field from the product template.
So that now allows me to add a product using
perch_shop_add_to_cart(2)
but still no dice on adding items via theadd_to_cart
form.But we're getting somewhere!
What does the debug output after submitting the form?
It's like it's not seeing the form being posted at all.
I see you've got
action="/shop/basket"
set - is that URL accurate? You've not got the server configured to redirect to/shop/basket/
or something like that? That could throw away the posted data in the process of redirecting.Hmm. I just changed the action to
/shop/basket/index.php
and it's started working.Well, that's annoying.
Ugh. It was a bloody setting in MAMP. I'm so sorry for wasting your time today, Drew.
Actually, it wasn't even a setting in MAMP. It was just the lack of a trailing slash on the action directory:
didn't work.
solved it.
Sorry again. That's had me tearing my hair out.
No problem!