Adding Product To Cart with Querystring in Magento

In this article simple product add to cart via querystring.
First we get cart url in a variable $cartUrl. And get form key in core session.
cart url concatenation with product ID and form key and redirect url.


Here is code add to Simple product...
<?php
$cartUrl = Mage::getUrl('checkout/cart');
    $getformKey = Mage::getSingleton('core/session')->getFormKey();
    $addproduct= $cartUrl."add?product=".$_product->getId()."&form_key=".$getformKey.
?>

Here is code add to Simple product with custom option 
<?php
$cartUrl = Mage::getUrl('checkout/cart');
    $getformKey = Mage::getSingleton('core/session')->getFormKey();
    $addproduct= $cartUrl."add?product=".$_product->getId()."&form_key=".$getformKey."&options[optionid]=optionvalueid";
?>

Labels: