Magento how to checkout one product from the customer dashboard
-
29-09-2020 - |
Question
I have a product whose price is 100$ and its a virtual product. I want to show that product in customer dashboard as a button and if customer clicks the button then he will be going for a checkout process of $100. I want the product should go to checkout from the customer dashboard.
Solution
You can override a CartController
and add a new action named addvirtualAction()
. Copy all code from default addAction()
to addvirtualAction()
and replace following block:
if (!$cart->getQuote()->getHasError()) {
$message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
$this->_getSession()->addSuccess($message);
}
WITH :
if (!$cart->getQuote()->getHasError()) {
/* REDIRECT TO CHECKOUT FROM HERE */
}
Now you have to set that PRODUCT BUTTON url as
$this->getUrl("checkout/cart/addvirtual", array("product"=> $product->getId(), "form_key" => Mage::getSingleton('core/session')->getFormKey() ))
this will generate url like: http://127.0.0.1/mage1921/checkout/cart/addvirtual/product/1/form_key/nyhjZWTTLQ3pcj2F/
UPDATE: For multiple quantities use this code:
$this->getUrl("checkout/cart/addvirtual", array("product"=> $product->getId(), "qty"=> NO_OF_QUANTITY, "form_key" => Mage::getSingleton('core/session')->getFormKey() ))
That's it...
By another way, you can use observer that dispatches after product is added to cart for redirecting to CHECKOUT page