I am currently using the message manager to display a series of messages from my controller.
$this->_messageManager->addSuccessMessage(__("All requested products have been added to the cart."));
When the controller sends back the HTTP response i am forcing a redirect to the cart page.
window.location.href = "/checkout/cart";
The issue with this is that the messages appear on the current page the HTTP request was sent from and then the redirect occurs, so the messages are on screen for half a second then the page changes.
What i want ideally is for the messages to be displayed on the cart page.
When i redirect through php however, the response that is received is the html for the page i want to redirect to and the browser does not change URL.
Has anyone had this issue before and how can i solve it? I have tried a few different methods of doing this but none seem to work.
return $this->resultRedirectFactory->create()->setPath('checkout/cart', ['_current' => true]);
$resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('checkout/cart'); return $resultRedirect;
According to previous answers, these two methods should work, however neither of them are forcing the users browser to /checkout/cart