Redirect while moving item from wishlist to cart
Pergunta
I need to change the default action after adding item to cart from wishlist. By default when you hit "Add to basket" button you will be redirected to the cart. I want user to be redirected back to wishlist.
I also know that going to Admin > System > Configuration > Default Config > Sales > Checkout > Shopping Cart > “After adding a product redirect to shopping cart”: Yes or No fixes my problem but I want to be able to do this only for wishlist and not globally, for one store only!
Solução
You can write an observer listen to the post_dispatch event
'controller_action_postdispatch_wishlist_index_cart'
and change the response to a redirect to the wishlist.
So create a new module/extension and add the following to your config.xml
:
<global>
...
<events>
...
<controller_action_postdispatch_wishlist_index_cart>
<observers>
<yourcompany_yourmodule>
<type>singleton</type>
<class>YourCompany_YourModule_Model_Observer</class>
<method>controllerActionPostdispatchWishlistIndexCart</method>
</yourcompany_yourmodule>
</observers>
</controller_action_postdispatch_wishlist_index_cart>
</events>
</global>
Then in your Observer.php
add the following method:
public function controllerActionPostdispatchWishlistIndexCart()
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::app()->getRequest()->getServer('HTTP_REFERER'));
}
That's it. Every time you will try to add something from your wishlist to your cart you will be redirected back to wishlist.