<event name="sales_order_shipment_save_before">
<observer name="test_beforeshipment" instance="Module\ModuleName\Observer\BeforeShipment" />
</event>
public function execute(\Magento\Framework\Event\Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
$orderId = $order->getId();
$redirectUrl = $this->url->getUrl('sales/order/view/order_id/'.$orderId);
$this->responseFactory->create()->setRedirect($redirectUrl)->sendResponse();
$observer->getControllerAction()->getResponse()->setRedirect($redirectUrl);
return $this;
}
-
Working fine the same code on the Magento2.4.2 version, but not working the same on the 2.4.3– Abhay AgrawalDec 16, 2021 at 9:40
1 Answer
If you want to do that then on __construct() function of your class observer, you must inject two classes.
First, \Magento\Framework\App\ResponseFactory which is responsible for redirection, Another class \Magento\Framework\UrlInterface will make a URL for that redirection. Then create object for ResponseFactory, and using setRedirect($YourUrl)->sendResponse(); redirect to your wished URL. Observer https://pastebin.com/4HwLUrth
-
Thanks for your kind reply, But I have already applied the solution that you have added but It is not working on the 2.4.3 Magento Version Dec 28, 2021 at 5:40
-
I am getting the issue in this line $observer->getControllerAction()->getResponse()->setRedirect($redirectUrl); Here getResponse() function returning null Dec 28, 2021 at 5:40