cookieMetadataFactory = $cookieMetadataFactory; $this->cookieManager = $cookieManager; } /** * @param StoreInterface $fromStore store where we came from * @param StoreInterface $targetStore store where to go to * @param string $redirectUrl original url requested for redirect after switching * @return string redirect url * @throws CannotSwitchStoreException */ public function switch(StoreInterface $fromStore, StoreInterface $targetStore, string $redirectUrl): string { try { $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata() ->setDurationOneYear() ->setPath('/') ->setSecure(false) ->setHttpOnly(false); $this->cookieManager->setPublicCookie( \Magento\Framework\App\PageCache\Version::COOKIE_NAME, 'should_be_updated', $publicCookieMetadata ); } catch (\Exception $e) { throw new CannotSwitchStoreException($e); } return $redirectUrl; } }