Skip to content

Commit d26a260

Browse files
committed
MC-37109: Session Cache Local Storage | Checkout Issue
1 parent 87598ef commit d26a260

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

app/code/Magento/Persistent/Observer/MakePersistentQuoteGuestObserver.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
7-
86
namespace Magento\Persistent\Observer;
97

108
use Magento\Framework\Event\ObserverInterface;
119

1210
/**
13-
* Make persistent quote to be guest
11+
* Make persistent quote to be guest
1412
*
1513
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1614
*/
@@ -38,26 +36,26 @@ class MakePersistentQuoteGuestObserver implements ObserverInterface
3836
protected $_persistentData = null;
3937

4038
/**
41-
* @var \Magento\Persistent\Model\QuoteManager
39+
* @var \Magento\Checkout\Model\Session
4240
*/
43-
protected $quoteManager;
41+
private $checkoutSession;
4442

4543
/**
4644
* @param \Magento\Persistent\Helper\Session $persistentSession
4745
* @param \Magento\Persistent\Helper\Data $persistentData
4846
* @param \Magento\Customer\Model\Session $customerSession
49-
* @param \Magento\Persistent\Model\QuoteManager $quoteManager
47+
* @param \Magento\Checkout\Model\Session $checkoutSession
5048
*/
5149
public function __construct(
5250
\Magento\Persistent\Helper\Session $persistentSession,
5351
\Magento\Persistent\Helper\Data $persistentData,
5452
\Magento\Customer\Model\Session $customerSession,
55-
\Magento\Persistent\Model\QuoteManager $quoteManager
53+
\Magento\Checkout\Model\Session $checkoutSession
5654
) {
5755
$this->_persistentSession = $persistentSession;
5856
$this->_persistentData = $persistentData;
5957
$this->_customerSession = $customerSession;
60-
$this->quoteManager = $quoteManager;
58+
$this->checkoutSession = $checkoutSession;
6159
}
6260

6361
/**
@@ -74,7 +72,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
7472
if (($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn())
7573
|| $this->_persistentData->isShoppingCartPersist()
7674
) {
77-
$this->quoteManager->setGuest(true);
75+
$this->checkoutSession->clearQuote()->clearStorage();
7876
}
7977
}
8078
}

app/code/Magento/Persistent/Test/Unit/Observer/MakePersistentQuoteGuestObserverTest.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
declare(strict_types=1);
87

98
namespace Magento\Persistent\Test\Unit\Observer;
109

10+
use Magento\Checkout\Model\Session as CheckoutSession;
1111
use Magento\Framework\Event;
1212
use Magento\Framework\Event\Observer;
1313
use Magento\Persistent\Controller\Index;
1414
use Magento\Persistent\Helper\Data;
1515
use Magento\Persistent\Helper\Session;
16-
use Magento\Persistent\Model\QuoteManager;
1716
use Magento\Persistent\Observer\MakePersistentQuoteGuestObserver;
1817
use PHPUnit\Framework\MockObject\MockObject;
1918
use PHPUnit\Framework\TestCase;
@@ -48,10 +47,10 @@ class MakePersistentQuoteGuestObserverTest extends TestCase
4847
/**
4948
* @var MockObject
5049
*/
51-
protected $quoteManagerMock;
50+
protected $checkoutSession;
5251

5352
/**
54-
* @var MockObject
53+
* @var CheckoutSession|MockObject
5554
*/
5655
protected $eventManagerMock;
5756

@@ -60,14 +59,17 @@ class MakePersistentQuoteGuestObserverTest extends TestCase
6059
*/
6160
protected $actionMock;
6261

62+
/**
63+
* @inheritdoc
64+
*/
6365
protected function setUp(): void
6466
{
6567
$this->actionMock = $this->createMock(Index::class);
6668
$this->observerMock = $this->createMock(Observer::class);
6769
$this->sessionHelperMock = $this->createMock(Session::class);
6870
$this->helperMock = $this->createMock(Data::class);
6971
$this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
70-
$this->quoteManagerMock = $this->createMock(QuoteManager::class);
72+
$this->checkoutSession = $this->createMock(CheckoutSession::class);
7173
$this->eventManagerMock =
7274
$this->getMockBuilder(Event::class)
7375
->addMethods(['getControllerAction'])
@@ -81,7 +83,7 @@ protected function setUp(): void
8183
$this->sessionHelperMock,
8284
$this->helperMock,
8385
$this->customerSessionMock,
84-
$this->quoteManagerMock
86+
$this->checkoutSession
8587
);
8688
}
8789

@@ -94,7 +96,8 @@ public function testExecute()
9496
$this->sessionHelperMock->expects($this->once())->method('isPersistent')->willReturn(true);
9597
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
9698
$this->helperMock->expects($this->never())->method('isShoppingCartPersist');
97-
$this->quoteManagerMock->expects($this->once())->method('setGuest')->with(true);
99+
$this->checkoutSession->expects($this->once())->method('clearQuote')->willReturnSelf();
100+
$this->checkoutSession->expects($this->once())->method('clearStorage')->willReturnSelf();
98101
$this->model->execute($this->observerMock);
99102
}
100103

@@ -107,7 +110,8 @@ public function testExecuteWhenShoppingCartIsPersist()
107110
$this->sessionHelperMock->expects($this->once())->method('isPersistent')->willReturn(true);
108111
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true);
109112
$this->helperMock->expects($this->once())->method('isShoppingCartPersist')->willReturn(true);
110-
$this->quoteManagerMock->expects($this->once())->method('setGuest')->with(true);
113+
$this->checkoutSession->expects($this->once())->method('clearQuote')->willReturnSelf();
114+
$this->checkoutSession->expects($this->once())->method('clearStorage')->willReturnSelf();
111115
$this->model->execute($this->observerMock);
112116
}
113117

@@ -120,7 +124,8 @@ public function testExecuteWhenShoppingCartIsNotPersist()
120124
$this->sessionHelperMock->expects($this->once())->method('isPersistent')->willReturn(true);
121125
$this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true);
122126
$this->helperMock->expects($this->once())->method('isShoppingCartPersist')->willReturn(false);
123-
$this->quoteManagerMock->expects($this->never())->method('setGuest');
127+
$this->checkoutSession->expects($this->never())->method('clearQuote')->willReturnSelf();
128+
$this->checkoutSession->expects($this->never())->method('clearStorage')->willReturnSelf();
124129
$this->model->execute($this->observerMock);
125130
}
126131
}

0 commit comments

Comments
 (0)