Magento - Add a product to the cart via query stri

2020-02-04 06:05发布

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?

标签: magento
7条回答
男人必须洒脱
2楼-- · 2020-02-04 06:45

Use "Add To Cart" link for your product any where on a Magento website::

The following code may helpful:

$product = Mage::getModel('catalog/product')->load($YourProductID);

echo Mage::helper('checkout/cart')->getAddUrl($product);

From magento 1.8 need to add form key $formKey = Mage::getSingleton('core/session')->getFormKey();?> to url

查看更多
登录 后发表回答