I am trying to add a product details link in the success message after a user clicks the add to cart button. So I create a variable in my controller but and want to send cart link. Here is file location vendor/magento/module-checkout/Controller/Cart
Here is some code from a similar question which was never solved. Can I include this with
if (!$this->_checkoutSession->getNoCartRedirect(true)) {
if (!$this->cart->getQuote()->getHasError()) {
$cartLink = '<a href="'. $this->_url->getUrl('checkout/cart') .'">View Cart/Checkout</a>';
$message = __('You added %1 to your shopping cart.', $product->getName()) .
'<a href="'.$cartLink .'">'. __('View Cart/Checkout') .'</a>';
$this->messageManager->addSuccessMessage($message);
}
Best Answer
Try the below code in your controller its work for me
The result should be like this See The Result Here