mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 09:17:35 +00:00
# Conflicts: # app/code/Magento/CatalogUrlRewrite/Plugin/Store/Block/Switcher.php # app/code/Magento/Store/Block/Switcher.php # app/code/Magento/Store/Controller/Store/SwitchAction.php # app/code/Magento/Store/Model/Plugin/StoreCookie.php # app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php
77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
|
|
namespace Magento\Store\Model\Plugin;
|
|
|
|
use Magento\Store\Api\StoreCookieManagerInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
use Magento\Store\Api\StoreRepositoryInterface;
|
|
use Magento\Store\Model\StoreIsInactiveException;
|
|
use Magento\Framework\Exception\NoSuchEntityException;
|
|
use \InvalidArgumentException;
|
|
|
|
/**
|
|
* Class StoreCookie
|
|
*/
|
|
class StoreCookie
|
|
{
|
|
/**
|
|
* @var \Magento\Store\Model\StoreManagerInterface
|
|
*/
|
|
protected $storeManager;
|
|
|
|
/**
|
|
* @var StoreCookieManagerInterface
|
|
*/
|
|
protected $storeCookieManager;
|
|
|
|
/**
|
|
* @var StoreRepositoryInterface
|
|
*/
|
|
protected $storeRepository;
|
|
|
|
/**
|
|
* @param StoreManagerInterface $storeManager
|
|
* @param StoreCookieManagerInterface $storeCookieManager
|
|
* @param StoreRepositoryInterface $storeRepository
|
|
*/
|
|
public function __construct(
|
|
StoreManagerInterface $storeManager,
|
|
StoreCookieManagerInterface $storeCookieManager,
|
|
StoreRepositoryInterface $storeRepository
|
|
) {
|
|
$this->storeManager = $storeManager;
|
|
$this->storeCookieManager = $storeCookieManager;
|
|
$this->storeRepository = $storeRepository;
|
|
}
|
|
|
|
/**
|
|
* Delete cookie "store" if the store (a value in the cookie) does not exist or is inactive
|
|
*
|
|
* @param \Magento\Framework\App\FrontController $subject
|
|
* @param \Magento\Framework\App\RequestInterface $request
|
|
* @return void
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
*/
|
|
public function beforeDispatch(
|
|
\Magento\Framework\App\FrontController $subject,
|
|
\Magento\Framework\App\RequestInterface $request
|
|
) {
|
|
$storeCodeFromCookie = $this->storeCookieManager->getStoreCodeFromCookie();
|
|
if ($storeCodeFromCookie) {
|
|
try {
|
|
$this->storeRepository->getActiveStoreByCode($storeCodeFromCookie);
|
|
} catch (StoreIsInactiveException $e) {
|
|
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
|
|
} catch (NoSuchEntityException $e) {
|
|
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
|
|
} catch (InvalidArgumentException $e) {
|
|
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
|
|
}
|
|
}
|
|
}
|
|
}
|