0
votes

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.

1
You need an observer here and on login event redirect user to cart pageSlimshadddyyy

1 Answers

0
votes

When you use customer/account/login. It is going to the login page

In the login page when you enter the detail and submit the following action is invoked

customer/account/login

which in return call to the function

customer/account/loginPost

you can find a code like this for redirection

$session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());

This part you need to customize to get your JOB DONE!!!

you can override the action for customer account controller and do the changes as per your need.