I need to redirect to checkout from an observer related to the event customer_account_edited
.
Here is my code. I've deleted a lot of rows that actually works...
Magento is doing everything well but ignore my redirection and send the user to the customer dashboard.
namespace Vendor\Customer\Observer;
use Magento\Customer\Api\CustomerRepositoryInterface;
class CustomerAccountEdited implements \Magento\Framework\Event\ObserverInterface {
protected $customerRepository;
protected $helper;
protected $_objectManager = null;
protected $resultRedirectFactory;
protected $messageManager;
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\ObjectManagerInterface $objectManager,
CustomerRepositoryInterface $customerRepository,
\Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory,
\Magento\Framework\Message\ManagerInterface $messageManager,
\Vendor\Customer\Helper\Data $helper
){
$this->_request = $request;
$this->customerRepository = $customerRepository;
$this->helper = $helper;
$this->_objectManager = $objectManager;
$this->resultRedirectFactory = $resultRedirectFactory;
$this->messageManager = $messageManager;
}
public function execute( \Magento\Framework\Event\Observer $observer ){
$this->messageManager->addSuccess(__("Success message"));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('checkout/cart');
return $resultRedirect;
}
}