I am currently implementing a behavior where I will check the quote items in cart, then check if it contains my custom attributes. If true, then it will redirect me to a specific page(CMS) page.
This behavior should trigger before place order is processed.
I already tried using, observer events: sales_order_place_before and checkout_submit_before. I was not successful in implementing the redirect in the observer. The place order process seems to ignore redirects from the observer.
Here is my code:
app/code/Package/ModuleName/etc/events.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_place_before">
<observer name="observer_name" instance="Package\ModuleName\Observer\BeforePlaceOrder"/>
</event>
app/code/Package/ModuleMame/Observer/BeforePlaceOrder.php
public function execute(Observer $observer)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Framework\UrlInterface $url */
$url = $objectManager->create('\Magento\Framework\UrlInterface');
/** @var \Magento\Framework\App\ResponseInterface $response */
$response = $objectManager->create('\Magento\Framework\App\ResponseInterface');
$customerBeforeAuthUrl = $url->getUrl('support-plan-option'); //you can change the routh path to your cms page
$response->setRedirect($customerBeforeAuthUrl)->sendResponse();
}
return $response;
$response
. check if your redirect code will work after