Я объявил наблюдателя для события controller_action_postdispatch. В методе execute я проверяю, вошел ли клиент в систему. Если нет, он должен быть перенаправлен на страницу входа.
public function execute(\Magento\Framework\Event\Observer $observer)
{
# check if user is logged in
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $this->objectManager->get('Magento\Customer\Model\Session');
if(!$customerSession->isLoggedIn())
{
$request = $this->objectManager->get('Magento\Framework\App\Request\Http');
if(strpos($request->getPathInfo(), '/customer/account/') !== 0)
{
# redirect to /customer/account/login
}
}
}
Как я могу перенаправить клиента на другой URL?