Skip to content

Commit a7e9bb9

Browse files
author
Pieter Cappelle
committed
Add message when not logged in for adding products to wishlist
1 parent eeed63e commit a7e9bb9

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,29 @@ class Plugin
3030
protected $config;
3131

3232
/**
33-
* @var \Magento\Framework\App\Response\RedirectInterface
33+
* @var \Magento\Framework\Message\ManagerInterface $messageManager
3434
*/
35-
protected $redirector;
35+
protected $messageManager;
3636

3737
/**
3838
* @param CustomerSession $customerSession
3939
* @param \Magento\Wishlist\Model\AuthenticationStateInterface $authenticationState
4040
* @param ScopeConfigInterface $config
4141
* @param RedirectInterface $redirector
42+
* @param \Magento\Framework\Message\ManagerInterface $messageManager
4243
*/
4344
public function __construct(
4445
CustomerSession $customerSession,
4546
\Magento\Wishlist\Model\AuthenticationStateInterface $authenticationState,
4647
ScopeConfigInterface $config,
47-
RedirectInterface $redirector
48+
RedirectInterface $redirector,
49+
\Magento\Framework\Message\ManagerInterface $messageManager
4850
) {
4951
$this->customerSession = $customerSession;
5052
$this->authenticationState = $authenticationState;
5153
$this->config = $config;
5254
$this->redirector = $redirector;
55+
$this->messageManager = $messageManager;
5356
}
5457

5558
/**
@@ -72,6 +75,10 @@ public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject,
7275
$this->customerSession->setBeforeModuleName('wishlist');
7376
$this->customerSession->setBeforeControllerName('index');
7477
$this->customerSession->setBeforeAction('add');
78+
79+
if ($request->getActionName() == 'add') {
80+
$this->messageManager->addErrorMessage(__('You must login or register to add items to your wishlist.'));
81+
}
7582
}
7683
if (!$this->config->isSetFlag('wishlist/general/active')) {
7784
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)