Magento – Product not adding to cart

cartsessionurl

When opening up a product page (example.com/store/women/catalog/product/view/id/215/) in a new session and using the standard add to cart, my product gets dropped and says the shopping cart is empty. However, once a ?SID= is assigned I am able to add the product to the cart. I am using Lesti::FPC.

Form action before getting an SID:

action="http://example.com/store/women/checkout/cart/add/uenc/aHR0cDovL3ByaW9yaXR5b3V0Zml0dGVyLmNvbS9zdG9yZS93b21lbi9jYXRhbG9nL3Byb2R1Y3Qvdmlldy9pZC8yMTUvP1NJRD1jYWUwNjU4ZWNiNjkxNTdjZDczMzZkNTllY2E0MmJmMg,,/product/215/form_key/Dij9pPXAwRBzAywH/?<(!)–
fpc session_id_placeholder –>"

Form action after getting an SID:

action="http://example.com/store/women/checkout/cart/add/uenc/aHR0cDovL3ByaW9yaXR5b3V0Zml0dGVyLmNvbS9zdG9yZS93b21lbi9jYXRhbG9nL3Byb2R1Y3Qvdmlldy9pZC8yMTUvP1NJRD1jYWUwNjU4ZWNiNjkxNTdjZDczMzZkNTllY2E0MmJmMg,,/product/215/form_key/Dij9pPXAwRBzAywH/

They are the same besides the fpc session_id_placeholder

Best Answer

You need to add the form key to the cart add link:

<?php

$formKey = Mage::getSingleton('core/session')->getFormKey();?>

<form action="/checkout/cart/add/product/<?php echo $productid; ?>" method="post">
    <input type="hidden" name="form_key" value="<?php echo $formKey; ?>" />

    <input type="text" name="qty"> QTY

    <input type="submit" value="Add to basket" />
</form>

Resource: https://stackoverflow.com/a/19999360/582138

Related Topic