Skip to content

Commit 56b8855

Browse files
author
Oleksii Korshenko
authored
MAGETWO-85627: Add error message if not logged in for adding products to wishlist #12681
2 parents f18839b + 7e406fc commit 56b8855

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

app/code/Magento/Wishlist/Controller/Index/Plugin.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,30 @@ class Plugin
3434
*/
3535
protected $redirector;
3636

37+
/**
38+
* @var \Magento\Framework\Message\ManagerInterface
39+
*/
40+
private $messageManager;
41+
3742
/**
3843
* @param CustomerSession $customerSession
3944
* @param \Magento\Wishlist\Model\AuthenticationStateInterface $authenticationState
4045
* @param ScopeConfigInterface $config
4146
* @param RedirectInterface $redirector
47+
* @param \Magento\Framework\Message\ManagerInterface $messageManager
4248
*/
4349
public function __construct(
4450
CustomerSession $customerSession,
4551
\Magento\Wishlist\Model\AuthenticationStateInterface $authenticationState,
4652
ScopeConfigInterface $config,
47-
RedirectInterface $redirector
53+
RedirectInterface $redirector,
54+
\Magento\Framework\Message\ManagerInterface $messageManager
4855
) {
4956
$this->customerSession = $customerSession;
5057
$this->authenticationState = $authenticationState;
5158
$this->config = $config;
5259
$this->redirector = $redirector;
60+
$this->messageManager = $messageManager;
5361
}
5462

5563
/**
@@ -72,6 +80,10 @@ public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject,
7280
$this->customerSession->setBeforeModuleName('wishlist');
7381
$this->customerSession->setBeforeControllerName('index');
7482
$this->customerSession->setBeforeAction('add');
83+
84+
if ($request->getActionName() == 'add') {
85+
$this->messageManager->addErrorMessage(__('You must login or register to add items to your wishlist.'));
86+
}
7587
}
7688
if (!$this->config->isSetFlag('wishlist/general/active')) {
7789
throw new NotFoundException(__('Page not found.'));

app/code/Magento/Wishlist/Test/Unit/Controller/Index/PluginTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class PluginTest extends \PHPUnit\Framework\TestCase
2828
*/
2929
protected $redirector;
3030

31+
/**
32+
* @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
protected $messageManager;
35+
3136
/**
3237
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
3338
*/
@@ -53,6 +58,7 @@ protected function setUp()
5358
$this->authenticationState = $this->createMock(\Magento\Wishlist\Model\AuthenticationState::class);
5459
$this->config = $this->createMock(\Magento\Framework\App\Config::class);
5560
$this->redirector = $this->createMock(\Magento\Store\App\Response\Redirect::class);
61+
$this->messageManager = $this->createMock(\Magento\Framework\Message\ManagerInterface::class);
5662
$this->request = $this->createMock(\Magento\Framework\App\Request\Http::class);
5763
}
5864

@@ -63,6 +69,7 @@ protected function tearDown()
6369
$this->authenticationState,
6470
$this->config,
6571
$this->redirector,
72+
$this->messageManager,
6673
$this->request
6774
);
6875
}
@@ -73,7 +80,8 @@ protected function getPlugin()
7380
$this->customerSession,
7481
$this->authenticationState,
7582
$this->config,
76-
$this->redirector
83+
$this->redirector,
84+
$this->messageManager
7785
);
7886
}
7987

app/code/Magento/Wishlist/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ Action,Action
116116
Configure,Configure
117117
Delete,Delete
118118
"Product Details and Comment","Product Details and Comment"
119+
"You must login or register to add items to your wishlist.","You must login or register to add items to your wishlist."

0 commit comments

Comments
 (0)