cancel
Showing results for 
Search instead for 
Did you mean: 

Message after redirect on order view page doesn't work

SOLVED

Message after redirect on order view page doesn't work

Hi,

 

I'm sending an custom email from the order view page. Basically I am calling a controller (which is based on the frontside - should it be made on admin side instead?), which sends an email and then redirects back to order view page where should show a success message. Everything is working except this message part.

I've checked countless threads and I can't figure out what I'm doing wrong.

 

Any help appreciated please.

Code below:

 

$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
try{
$this->messageManager->addSuccessMessage(__('Shipping Email sent successfully'));
}catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
$resultRedirect->setUrl($this->_redirect->getRefererUrl());
return $resultRedirect;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Message after redirect on order view page doesn't work

@itmultimobd453 

You just need to create a controller from the backend side and send mail from that!

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

View solution in original post

3 REPLIES 3

Re: Message after redirect on order view page doesn't work

@itmultimobd453 

You just need to create a controller from the backend side and send mail from that!

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: Message after redirect on order view page doesn't work

HI, I tried that but I always get the secret key invalid error. Is there a better way to generate the key than $this->_backendUrl->getSecretKey? I saw some posts in which there's no key generated, just the url via $this->_backendUrl->getRouteUrl and it's supposed to work. 

However, both get me to the same error. And I don't want to disable the key for security reasons.

Any advice on this?

 

Thanks

Re: Message after redirect on order view page doesn't work

Thanks, I managed to do the controller from admin and and it solved the message issue as well.