2

I'm using Magento Enterprise 1.13; there appears to be some documentation around for adding a product using the URL & query string but those do not appear to be working for me.

For example:

Add Configurable Product To Cart Via Query String In 1.7

Is there a different or documented methodology for doing this now?

Thank you

2 Answers 2

5

My answer is based on the assumption that EE-1.13 is similar to CE 1.8.
Starting CE 1.8 there is a form key validation on the add to cart action.
Mage_Checkout_CartController::addAction starts with this:

if (!$this->_validateFormKey()) {
    $this->_goBack();
    return;
} 

The method is defined in Mage_Core_Controller_Varien_Action

protected function _validateFormKey()
{
    if (!($formKey = $this->getRequest()->getParam('form_key', null))
        || $formKey != Mage::getSingleton('core/session')->getFormKey()) {
        return false;
    }
    return true;
} 

This means that if you don't send a valid request parameter named form_key with the value stored in the current session the add to cart won't work. it won't work.
So, you have to append to the url the session form key value.
If you are planning to have this link from an "outside" page then you have a problem because you cannot access the session key.

3
  • Ah yes I do plan on linking from outside. Do I need to create a special front controller that redirects with the form key?
    – john
    Jan 2, 2014 at 3:02
  • I think it is a good approach. You can pass through a proxy controller in order to get the session form key.
    – Marius
    Jan 2, 2014 at 10:59
  • Any information on how to to create that front controller? I also need to provide linking from outside my website. Thanks.
    – sparecycle
    Aug 19, 2014 at 15:50
-1

You can add a product to cart using query string/url by following code:

http://yourstoreurl/checkout/cart/add/product/[id]/qty/[qty] example : http://example.com/checkout/cart/add/product/2880/qty/2

or

http://yourstoreurl/checkout/cart/add?product=[id]&qty=[qty] example : http://example.com/checkout/cart/add?product=2880&qty=2

3

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.