Magento – Add to Cart Query String Redirects to Product Page

addtocartquerystring

I'm using magento 1.9.1 and on a custom listing page I'm trying to add an add to basket form. This is supposed to add to the basket using a query string.

<?php $formKey = Mage::getSingleton('core/session')->getFormKey();?>
<form action="/shop/checkout/cart/add?product=4149&qty=1&super_attribute[136]=147?super_attribute[240]=1636" method="post">
<input type="hidden" name="form_key" value="<?php echo $formKey; ?>" />

<input type="submit" value="Add to basket" />
</form>

I've tried a few variations on how the url is formatted and I will look at Un-hardcoding it once ,i have got a working format.

But for now it just keeps directing to the product page and asking me to select options.

I've read this, this and this about formatting a query string for this. I'm certain that I've done this on older versions of magento in the past with the format given in the code above.

FYI –

I need to add it as a config product and set the options rather than add the simple directly.

All help welcome.

Best Answer

I you use form then It will good idea to use

  1. Dynamic cart url using function $this->helper('checkout/cart')->getAddUrl($product) in form action
  2. use the super attribute as input field.
<?php $formKey = Mage::getSingleton('core/session')->getFormKey();?>
    <form action="<?php echo $this->helper('checkout/cart')->getAddUrl($product) ?>" method="post">
    <input type="hidden" name="form_key" value="super_attribute[136]" />
    <input type="hidden" name="super_attribute[136]" value="147" />
    <input type="hidden" name="super_attribute[240]" value="11636" />
    <input type="hidden" name="qty" value="1" />
    <input type="submit" value="Add to basket" />
    </form>
Related Topic