Add Product to Cart from Email Link in Magento

addtocartemailmagento-1.6

I am running a promotion and would like to make it very easy for customers to add three items to their shopping carts.

The research I have done around URL querystrings no longer seems to work on Magento 1.6.2, due to a requirement of a form key value.

Is there any way for me to be able to add one of each of 3 simple products to a customers basket from a link in an email?

Not scamming etc, just want to make life easy for people interested in buying the special offer product(s).

Best Answer

You should create your own module for this with the product sku/id as a parameter. Code might look something like this:

$id = '100'; // Get the id  with $this->getRequest()->getParam('id')
$qty = '2'; // Replace qty with your qty
$_product = Mage::getModel('catalog/product')->load($id);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->addProduct($_product, array('qty' => $qty));
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

After that you can do a redirect to the cart or to the homepage.

The link in your email will be something like http://domain.com/router/controller/action/id/product-id

Some more info here.

Related Topic