I've just installed Magento Community Edition ver 1.8.0.0 (default settings).
System -> Configuration -> Sales -> Checkout -> Checkout Options
Enable Onepage Checkout: Yes
Allow Guest Checkout: Yes
I'm trying to add a product to the cart using query string method.
According to all resources I've found, these are correct ways to do it:
[store]/checkout/cart/add/product/1/
[store]/checkout/cart/add?product=1&qty=1
but they're not working... the cart remains empty.
After quite some time, I found the working solution:
[store]/checkout/cart/add/product/1/form_key/yu6b5VEzwSU2V7YE/
However, I'd like not to put form_key parameter in the url.
This security feature is not needed in my case.
For example product comparison works fine without the form_key:
[store]/catalog/product_compare/add/product/1/
The idea is to put a static link on some other websites (so dynamically generated form_key is not known), so if a customer clicks on it he is redirected to the store with a filled cart straight away.
Is it possible to get rid of form_key parameter and still be able to add a product to the cart? And if so, then how?
This works best for me in Magento C 1.8
This is how I am doing it in Magento 1.8.1
<a href="<?= $this->getAddtoCartUrl($_product, array('qty' => $_price['price_qty'])) ?>">
See http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Block_Product_Abstract.html#getAddToCartUrl
The following can be used with qty set:
What I did is to override the Magento
CartController
with a custom module. I created a file inside: \app\code\local\Namespace\AddProductFromUrl\controllers\Checkout\CartController.php(The module need to have config.xml and enabled under
etc/modules/
as for every magento custom module. ChangeNamespace
with the one you use.)That works perfectly just like magento 1.7 and with minimal impact; the
form_key
is generated if missing and that's it.This step is not very complicated! Hope this help.
What I actually did in the end was compare the new changes with the old code and I discovered the add to cart button was set to type="button" and was not submitting.
Changing the button to simply type="submit" and no other changes actually made it work this is in [theme]/template/catalog/product/view/addtocart
may have to move from base folder if non-existent