I want to redirect the user to the checkout page on Adding product to cart, Please help.
Asked
Active
Viewed 2,576 times
0
-
please check this link https://magento.stackexchange.com/questions/115039/redirect-to-home-page-in-controller – Shinoy Shaji Aug 08 '18 at 13:40
-
@shinoy shaji Please read my question again and I'm talking about Magento 2. Thanks for your time – Inderjeet Singh Behl Aug 09 '18 at 05:19
-
Have a look on [Magento 2 - Go directly to the checkout page when adding a product to the cart](https://stackoverflow.com/questions/37536452/magento-2-go-directly-to-the-checkout-page-when-adding-a-product-to-the-cart) and [Magento 2: Skipping Shopping Cart Page after Add to Cart](https://magento.stackexchange.com/questions/138035/magento-2-skipping-shopping-cart-page-after-add-to-cart) – Knight017 Oct 12 '18 at 09:40
-
Thanks to all for their answers. I resolved it by myself. – Inderjeet Singh Behl Oct 22 '18 at 09:10
-
how you do it?? – alexey boltynov Apr 03 '19 at 13:53
-
@alexeyboltynov Please check my answer and accept it if this helps you. – Inderjeet Singh Behl May 18 '19 at 22:01
1 Answers
1
@alexeyboltynov First you have enable skip cart option from magento 2 admin. you can found that option easily in your theme settings.
And you have to overwrite core file path: "vendor\magento\module-checkout\Controller\Cart\Add.php"
Find code:
if (!$this->_checkoutSession->getNoCartRedirect(true)) {
if (!$this->cart->getQuote()->getHasError()) {
if ($this->shouldRedirectToCart()) {
$message = __(
'You added %1 to your shopping cart.',
$product->getName()
);
$this->messageManager->addSuccessMessage($message);
} else {
$this->messageManager->addComplexSuccessMessage(
'addCartSuccessMessage',
[
'product_name' => $product->getName(),
'cart_url' => $this->getCartUrl(),
]
);
}
}
return $this->goBack(null, $product);
}
Replace it with:
if (!$this->_checkoutSession->getNoCartRedirect(true)) {
return $this->resultRedirectFactory->create()->setPath('checkout', ['_current' => true]);
}
This will redirect users to the checkout page after adding product to cart. And removed success add to cart messages.
Note: Please make you own custom module for this don't overwrite the core file. Hope you know how to create your own module.

Inderjeet Singh Behl
- 11
- 1
- 3