Skip to content

Commit 805e444

Browse files
committed
Merge branch 'ACP2E-1972' of https://github.com/magento-l3/magento2ce into PR-07032023
2 parents 808e992 + bf0e060 commit 805e444

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

app/code/Magento/Customer/Observer/Visitor/InitByRequestObserver.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,44 @@
66

77
namespace Magento\Customer\Observer\Visitor;
88

9+
use Magento\Customer\Model\Visitor;
910
use Magento\Framework\Event\Observer;
11+
use Magento\Framework\Session\SessionManagerInterface;
1012

1113
/**
1214
* Visitor Observer
15+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1316
*/
1417
class InitByRequestObserver extends AbstractVisitorObserver
1518
{
1619
/**
17-
* initByRequest
20+
* @var SessionManagerInterface
21+
*/
22+
private $sessionManager;
23+
24+
/**
25+
* @param Visitor $visitor
26+
* @param SessionManagerInterface $sessionManager
27+
*/
28+
public function __construct(
29+
Visitor $visitor,
30+
SessionManagerInterface $sessionManager
31+
) {
32+
parent::__construct($visitor);
33+
$this->sessionManager = $sessionManager;
34+
}
35+
36+
/**
37+
* Init visitor by request
1838
*
1939
* @param Observer $observer
2040
* @return void
2141
*/
2242
public function execute(Observer $observer)
2343
{
44+
if ($observer->getRequest()->getFullActionName() === 'customer_account_loginPost') {
45+
$this->sessionManager->setVisitorData(['do_customer_login' => true]);
46+
}
2447
$this->visitor->initByRequest($observer);
2548
}
2649
}

dev/tests/integration/testsuite/Magento/Customer/Controller/Account/LoginPostTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\Request\Http as HttpRequest;
1313
use Magento\Framework\Message\MessageInterface;
1414
use Magento\Framework\Phrase;
15+
use Magento\Framework\Session\Generic;
1516
use Magento\Framework\Url\EncoderInterface;
1617
use Magento\TestFramework\TestCase\AbstractController;
1718

@@ -33,6 +34,11 @@ class LoginPostTest extends AbstractController
3334
*/
3435
private $customerUrl;
3536

37+
/**
38+
* @var Generic
39+
*/
40+
private $generic;
41+
3642
/**
3743
* @inheritdoc
3844
*/
@@ -43,6 +49,7 @@ protected function setUp(): void
4349
$this->session = $this->_objectManager->get(Session::class);
4450
$this->urlEncoder = $this->_objectManager->get(EncoderInterface::class);
4551
$this->customerUrl = $this->_objectManager->get(Url::class);
52+
$this->generic = $this->_objectManager->get(Generic::class);
4653
}
4754

4855
/**
@@ -220,6 +227,25 @@ public function testNoFormKeyLoginPostAction(): void
220227
);
221228
}
222229

230+
/**
231+
* @magentoConfigFixture current_store customer/startup/redirect_dashboard 1
232+
* @magentoConfigFixture current_store customer/captcha/enable 0
233+
*
234+
* @magentoDataFixture Magento/Customer/_files/customer.php
235+
*
236+
* @return void
237+
*/
238+
public function testVisitorForCustomerLoginPostAction(): void
239+
{
240+
$this->assertEmpty($this->generic->getVisitorData());
241+
$this->prepareRequest('customer@example.com', 'password');
242+
$this->dispatch('customer/account/loginPost');
243+
$this->assertTrue($this->session->isLoggedIn());
244+
$this->assertRedirect($this->stringContains('customer/account/'));
245+
$this->assertNotEmpty($this->generic->getVisitorData()['visitor_id']);
246+
$this->assertNotEmpty($this->generic->getVisitorData()['customer_id']);
247+
}
248+
223249
/**
224250
* Prepare request
225251
*

0 commit comments

Comments
 (0)