I have seen some suggested changes to make to call the FORM KEY to allow the ADD TO CART FROM URL to work.


$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" />

However, I don't know which files to change. Can anyone help me?

Many thanks for any help given

  • 1
    Can you explain a bit what are you trying to achieve? An example would help. Your question is unclear.
    – Marius
    Commented Oct 2, 2014 at 11:11
  • I have a Magento site. However, My colleague has a non magento html site which also sells the same products. He doesn't want to change his site to a Magento site but we want to use the same shopping cart. I want to create an ADD TO CART URL that he can use on his site. At the moment, I can get the shopping cart using mydomain.com/checkout/cart/add?product=13&qty=1 but it is empty
    – Techiescot
    Commented Oct 2, 2014 at 11:30
  • possible duplicate of Adding to Cart with Querystring - Takes me to homepage? Commented Jul 13, 2015 at 12:19
  • Not a duplicate question - the issue here is that the external system needs a form key, or the form key needs to be bypassed.
    – benmarks
    Commented Jul 13, 2015 at 12:48

2 Answers 2


Starting Magento 1.8 it's not possible anymore to add a product to the cart via an external referrer. All the add to cart actions depend on the user form key that is different from session to session.
For version prior to 1.8 you could have done this:

<a href="ROOT_URL/checkout/cart/add/product/ID_HERE">Add</a>

What you can do is to create your own module that has one controller.
Then you can point the urls on your second website to this url, and redirect to the correct add to cart url.
Something like this.

Let's say your module is called Easylife_Cart. You will need the following files.
app/etc/module/Easylife_Cart.xml - the declaration file

<?xml version="1.0"?>
                <Mage_Checkout />

app/code/local/Easylife/Cart/etc/config.xml - the configuration file

<?xml version="1.0"?>

app/code/local/Easylife/Cart/controllers/IndexController.php - your controller

class Easylife_Cart_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
        $product = $this->getRequest()->getParam('product');
        $key =  Mage::getSingleton('core/session')->getFormKey();;
        if (empty($product)){ //if no product id, redirect to homepage
        else{ //redirect to the add to cart with the form key
            $this->_redirect('checkout/cart/add', array('product'=>$product, 'form_key'=>$key));

I didn't test it, so watch out for syntax errors.
Now you should be able to put links like this in the external website:

<a href="MAGENTO_WEBSITE_ROOT/cart/index/index/product/ID_HERE">Add to cart</a>

Make sure you clear the cache after adding this module.

  • You are a star ... Thank you ... It works ... Now I just have to work out if there is any way to change the LOGO on the shopping cart depending on which external website it comes from
    – Techiescot
    Commented Oct 2, 2014 at 12:38
  • If this answers solved your problem mark it as accepted. For your other problem feel free to ask an other question. Let's keep this website clean and play by the rules
    – Marius
    Commented Oct 2, 2014 at 12:41
  • How would you get this to work in 1.9.2?
    – Aravona
    Commented Oct 28, 2016 at 11:01
  • How would you add a simple product (size option of configurable product)? - same as selecting a T-shirt in size SMALL on the product page ... but then for /cart/add? thx
    – snh_nl
    Commented Nov 9, 2018 at 18:26

for more information read Adding to Cart with Querystring - Takes me to homepage?

The url for adding needs to include a form_key.


  • 1
    Not the same problem.
    – benmarks
    Commented Jul 13, 2015 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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