I want to add a button "Direct Checkout" on my product details page. On click, it will add product to cart and redirect to checkout/onepage
.
By default on addtocart Magento's redirect to cart page.
I have added a hidden field on product page and adding value in it on click of Direct Checkout button using javascript. Then in observer checking that value and redirect to checkout.
I have implement the above logic in observer checkout_cart_add_product_complete
but it is not redirecting to checkout page, instead it redirects to cart page.
My observer function is:
public function afterAddToCart(Varien_Event_Observer $observer)
{
$params = Mage::app()->getFrontController()->getRequest()->getParams();
if(isset($params['dco']) && $params['dco'] == 1){
Mage::app()->getResponse()->setRedirect(Mage::getUrl("checkout/onepage"));
}
}
I suppose it is not working because after my redirect code, magento executes default addtocart code which redirects it to cart again.
Is there any way I can break and simply redirect to checkout page?