Skip to content

Commit 10120fc

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-53019' into BUGS
2 parents 1b89c45 + a94b469 commit 10120fc

File tree

5 files changed

+32
-279
lines changed

5 files changed

+32
-279
lines changed

app/code/Magento/Customer/Controller/Account/UpdateSession.php

Lines changed: 0 additions & 77 deletions
This file was deleted.

app/code/Magento/Customer/Model/Plugin/CustomerNotification.php

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
use Magento\Framework\App\RequestInterface;
1313
use Magento\Framework\App\Response\Http;
1414
use Magento\Framework\App\State;
15-
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
16-
use Magento\Framework\Stdlib\CookieManagerInterface;
15+
use Magento\Customer\Api\CustomerRepositoryInterface;
1716

1817
class CustomerNotification
1918
{
@@ -28,16 +27,9 @@ class CustomerNotification
2827
private $notificationStorage;
2928

3029
/**
31-
* Cookie Manager
32-
*
33-
* @var \Magento\Framework\Stdlib\CookieManagerInterface
30+
* @var CustomerRepositoryInterface
3431
*/
35-
private $cookieManager;
36-
37-
/**
38-
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory
39-
*/
40-
private $cookieMetadataFactory;
32+
private $customerRepository;
4133

4234
/**
4335
* @var State
@@ -49,22 +41,18 @@ class CustomerNotification
4941
*
5042
* @param Session $session
5143
* @param NotificationStorage $notificationStorage
52-
* @param CookieManagerInterface $cookieManager
53-
* @param CookieMetadataFactory $cookieMetadataFactory
5444
* @param State $state
5545
*/
5646
public function __construct(
5747
Session $session,
5848
NotificationStorage $notificationStorage,
59-
CookieManagerInterface $cookieManager,
60-
CookieMetadataFactory $cookieMetadataFactory,
61-
State $state
49+
State $state,
50+
CustomerRepositoryInterface $customerRepository
6251
) {
6352
$this->session = $session;
6453
$this->notificationStorage = $notificationStorage;
65-
$this->cookieManager = $cookieManager;
66-
$this->cookieMetadataFactory = $cookieMetadataFactory;
6754
$this->state = $state;
55+
$this->customerRepository = $customerRepository;
6856
}
6957

7058
/**
@@ -75,24 +63,17 @@ public function __construct(
7563
*/
7664
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
7765
{
78-
if ($this->state->getAreaCode() == Area::AREA_FRONTEND
66+
if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost()
7967
&& $this->notificationStorage->isExists(
8068
NotificationStorage::UPDATE_CUSTOMER_SESSION,
8169
$this->session->getCustomerId()
8270
)
8371
) {
84-
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
85-
$publicCookieMetadata->setDurationOneYear();
86-
$publicCookieMetadata->setPath('/');
87-
$publicCookieMetadata->setHttpOnly(false);
88-
$this->cookieManager->setPublicCookie(
89-
NotificationStorage::UPDATE_CUSTOMER_SESSION,
90-
$this->session->getCustomerId(),
91-
$publicCookieMetadata
92-
);
93-
94-
$cookieMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');
95-
$this->cookieManager->deleteCookie(Http::COOKIE_VARY_STRING, $cookieMetadata);
72+
$customer = $this->customerRepository->getById($this->session->getCustomerId());
73+
$this->session->setCustomerData($customer);
74+
$this->session->setCustomerGroupId($customer->getGroupId());
75+
$this->session->regenerateId();
76+
$this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
9677
}
9778
}
9879
}

app/code/Magento/Customer/Test/Unit/Controller/Account/UpdateSessionTest.php

Lines changed: 0 additions & 117 deletions
This file was deleted.

app/code/Magento/Customer/Test/Unit/Model/Plugin/CustomerNotificationTest.php

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ class CustomerNotificationTest extends \PHPUnit_Framework_TestCase
1616
/** @var \Magento\Customer\Model\Customer\NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
1717
protected $notificationStorage;
1818

19-
/** @var \Magento\Framework\Stdlib\CookieManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
20-
protected $cookieManager;
21-
22-
/** @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */
23-
protected $cookieMetadataFactory;
19+
/** @var \Magento\Customer\Api\CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
20+
protected $customerRepository;
2421

2522
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */
2623
protected $appState;
@@ -42,63 +39,46 @@ protected function setUp()
4239
$this->notificationStorage = $this->getMockBuilder('Magento\Customer\Model\Customer\NotificationStorage')
4340
->disableOriginalConstructor()
4441
->getMock();
45-
$this->cookieManager = $this->getMockBuilder('Magento\Framework\Stdlib\CookieManagerInterface')
42+
$this->customerRepository = $this->getMockBuilder('Magento\Customer\Api\CustomerRepositoryInterface')
4643
->getMockForAbstractClass();
47-
$this->cookieMetadataFactory = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\CookieMetadataFactory')
48-
->disableOriginalConstructor()
49-
->getMock();
5044
$this->abstractAction = $this->getMockBuilder('Magento\Backend\App\AbstractAction')
5145
->disableOriginalConstructor()
5246
->getMockForAbstractClass();
53-
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')->getMockForAbstractClass();
47+
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
48+
->setMethods(['isPost'])
49+
->getMockForAbstractClass();
5450
$this->appState = $this->getMockBuilder('Magento\Framework\App\State')->disableOriginalConstructor()->getMock();
5551
$this->plugin = new CustomerNotification(
5652
$this->session,
5753
$this->notificationStorage,
58-
$this->cookieManager,
59-
$this->cookieMetadataFactory,
60-
$this->appState
54+
$this->appState,
55+
$this->customerRepository
6156
);
6257
}
6358

6459
public function testBeforeDispatch()
6560
{
6661
$customerId = 1;
62+
$customerGroupId =1;
6763
$this->appState->expects($this->any())
6864
->method('getAreaCode')
6965
->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
66+
$this->request->expects($this->any())->method('isPost')->willReturn(true);
67+
$customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMockForAbstractClass();
68+
$customerMock->expects($this->any())->method('getGroupId')->willReturn($customerGroupId);
69+
$this->customerRepository->expects($this->any())
70+
->method('getById')
71+
->with($customerId)
72+
->willReturn($customerMock);
7073
$this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
74+
$this->session->expects($this->any())->method('setCustomerData')->with($customerMock);
75+
$this->session->expects($this->any())->method('setCustomerGroupId')->with($customerGroupId);
76+
$this->session->expects($this->once())->method('regenerateId');
7177
$this->notificationStorage->expects($this->any())
7278
->method('isExists')
7379
->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)
7480
->willReturn(true);
7581

76-
$publicCookieMetadata = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\PublicCookieMetadata')
77-
->disableOriginalConstructor()
78-
->getMock();
79-
$publicCookieMetadata->expects($this->once())->method('setPath')->with('/');
80-
$publicCookieMetadata->expects($this->once())->method('setDurationOneYear');
81-
$publicCookieMetadata->expects($this->once())->method('setHttpOnly')->with(false);
82-
83-
$sensitiveCookieMetadata = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\SensitiveCookieMetadata')
84-
->disableOriginalConstructor()
85-
->getMock();
86-
$sensitiveCookieMetadata->expects($this->once())->method('setPath')->with('/')->willReturnSelf();
87-
88-
$this->cookieMetadataFactory->expects($this->any())
89-
->method('createPublicCookieMetadata')
90-
->willReturn($publicCookieMetadata);
91-
$this->cookieMetadataFactory->expects($this->any())
92-
->method('createSensitiveCookieMetadata')
93-
->willReturn($sensitiveCookieMetadata);
94-
95-
$this->cookieManager->expects($this->once())
96-
->method('setPublicCookie')
97-
->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId, $publicCookieMetadata);
98-
$this->cookieManager->expects($this->once())
99-
->method('deleteCookie')
100-
->with(\Magento\Framework\App\Response\Http::COOKIE_VARY_STRING, $sensitiveCookieMetadata);
101-
10282
$this->plugin->beforeDispatch($this->abstractAction, $this->request);
10383
}
10484
}

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,7 @@ define([
188188
*/
189189
init: function() {
190190
var countryData,
191-
privateContent = $.cookieStorage.get('private_content_version'),
192-
updateSession = $.cookieStorage.get('update_customer_session');
193-
if (updateSession) {
194-
mageStorage.post(
195-
options.updateSessionUrl,
196-
JSON.stringify({
197-
'customer_id': updateSession,
198-
'form_key': window.FORM_KEY
199-
})
200-
).done(
201-
function () {
202-
$.cookieStorage.setConf({path: '/', expires: -1}).set('update_customer_session', null);
203-
}
204-
);
205-
}
191+
privateContent = $.cookieStorage.get('private_content_version');
206192

207193
if (_.isEmpty(storage.keys())) {
208194
if (!_.isEmpty(privateContent)) {

0 commit comments

Comments
 (0)