2

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).

5

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.

2

So, the easy way to do this (Tested in Magento 1.6.2 only) is to simply get the ID from Magento admin of the product you want to link to, and then construct the URL as follows:

http://www.example.com/checkout/cart/add?product=12345&qty=1

www.example.com is your website, and the "/checkout" part will change if your Magento installation is not in the root of your domain. So, if your Magento store is installed into a subfolder called store, your link would be:

http://www.example.com/store/checkout/cart/add?product=12345&qty=1

product=12345 is the ID of the product to add to the cart.

qty=1 is the quantity to add to the cart.

This will work for simple products (products that do not have any options required before adding to cart).

I hope this helps someone.

  • 1
    This method is no longer valid since Magento 1.7 as you now require a formKey to add to cart. – Eirik Apr 6 '15 at 0:39
  • Actually formKeys were added in Magento 1.8 – Mukesh Jun 24 '15 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.