| Current Path : /var/www/clients/client3/web2/web/vendor/magento/module-wishlist/Controller/Index/ |
| Current File : /var/www/clients/client3/web2/web/vendor/magento/module-wishlist/Controller/Index/Plugin.php |
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Wishlist\Controller\Index;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\Response\RedirectInterface;
use Magento\Store\Model\ScopeInterface;
/**
* Wishlist plugin before dispatch
*/
class Plugin
{
/**
* @var \Magento\Customer\Model\Session
*/
protected $customerSession;
/**
* @var \Magento\Wishlist\Model\AuthenticationStateInterface
*/
protected $authenticationState;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $config;
/**
* @var \Magento\Framework\App\Response\RedirectInterface
*/
protected $redirector;
/**
* @var \Magento\Framework\Message\ManagerInterface
*/
private $messageManager;
/**
* @param CustomerSession $customerSession
* @param \Magento\Wishlist\Model\AuthenticationStateInterface $authenticationState
* @param ScopeConfigInterface $config
* @param RedirectInterface $redirector
* @param \Magento\Framework\Message\ManagerInterface $messageManager
*/
public function __construct(
CustomerSession $customerSession,
\Magento\Wishlist\Model\AuthenticationStateInterface $authenticationState,
ScopeConfigInterface $config,
RedirectInterface $redirector,
\Magento\Framework\Message\ManagerInterface $messageManager
) {
$this->customerSession = $customerSession;
$this->authenticationState = $authenticationState;
$this->config = $config;
$this->redirector = $redirector;
$this->messageManager = $messageManager;
}
/**
* Perform customer authentication and wishlist feature state checks
*
* @param \Magento\Framework\App\ActionInterface $subject
* @param RequestInterface $request
* @return void
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request)
{
if ($this->authenticationState->isEnabled() && !$this->customerSession->authenticate()) {
$subject->getActionFlag()->set('', 'no-dispatch', true);
if (!$this->customerSession->getBeforeWishlistUrl()) {
$this->customerSession->setBeforeWishlistUrl($this->redirector->getRefererUrl());
}
$data = $request->getParams();
unset($data['login']);
$this->customerSession->setBeforeWishlistRequest($data);
$this->customerSession->setBeforeRequestParams($this->customerSession->getBeforeWishlistRequest());
$this->customerSession->setBeforeModuleName('wishlist');
$this->customerSession->setBeforeControllerName('index');
$this->customerSession->setBeforeAction('add');
if ($request->getActionName() == 'add') {
$this->messageManager->addErrorMessage(__('You must login or register to add items to your wishlist.'));
}
}
if (!$this->config->isSetFlag('wishlist/general/active', ScopeInterface::SCOPE_STORES)) {
throw new NotFoundException(__('Page not found.'));
}
}
}