I have add to cart in product listing page. Now if guest user clicks on the button, then it will redirect to customer login page and after successfully login, that product should be added to cart and the page would be redirected to my cart page. I have written my code by that guest user redirects to login page while clicking on the button and I pass the product id in the URL of the login page. But after that I am not able to do the next portion. in my product listing page code is like :
if (Mage::getSingleton('customer/session')->isLoggedIn()){
$url = $this->getAddToCartUrl($_product);
}else{
$id = $_product->getEntityId();
$url = Mage::getUrl("customer/account/login/cartproductid/$id");
}
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $url; ?>')"><span><span><?php echo $this->__('Add to Cart12') ?></span></span></button>
After login it redirects to customer dashboard page. But it should be my cart page with adding that product in the cart.
Please help. Thanks in advance.