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.

I have a feeling this is occuring because i am setting the messages in php and then forcing the redirect in the Javascript, after the response has been received. Looking at some Magento core files, the best way to do it is to redirect from the php itself, which makes the page redirect and the display and necessary messages.

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();
return $resultRedirect;

According to previous answers, these two methods should work, however neither of them are forcing the users browser to /checkout/cart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.