Magento – adding bundle product with default options with setLocationAjax function

addtocartajaxbundle-productdefault values

I'm trying to add to cart a bundle product with default options (options already selected from backend) using the setLocationAjax function. I managed to get the correct url to add which will be javascript:setLocationAjax('http://example.com/checkout/cart/add/uenc/aHR0cDovL2lsYWVtcy5jb20vc2FuZHdpY2hlcy5odG1s/product/29/form_key/YMC8gewJKkZd3QK6/?&bundle_option[2]=4&bundle_option_qty[2]=1.0000&bundle_option[3]=6&bundle_option_qty[3]=10.0000&bundle_option[4]=13&bundle_option_qty[4]=5.0000')

for some reason I'm getting the message "Please specify product option(s)." while if I'm not using ajax it will work fine.

any ideas what is missing here.

Thanks

Best Answer

It's probably due to your form key expiring. If you're trying to paste this in after it's generated then you'll need to ensure that it has a fresh form key. Try adding it like this:

$form_key = Mage::getSingleton('core/session')->getFormKey();
echo "javascript:setLocationAjax('http://example.com/checkout/cart/add/product/29/form_key/".$form_key."/?&bundle_option[2]=4&bundle_option_qty[2]=1.0000&bundle_option[3]=6&bundle_option_qty[3]=10.0000&bundle_option[4]=13&bundle_option_qty[4]=5.0000')";
Related Topic