Skip to content

Commit 573e606

Browse files
committed
ACP2E-4137: [Cloud] No such entity with cartId
1 parent f06fd44 commit 573e606

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

app/code/Magento/Checkout/Model/Session.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ public function getQuote()
277277
* need recalculate totals of quote. It is possible if customer use currency switcher or
278278
* store switcher.
279279
*/
280-
$currencyCode = $quote->getQuoteCurrencyCode();
281-
$currentCurrency = $this->_storeManager->getStore()->getCurrentCurrencyCode();
282-
if ($currencyCode !== null && $currencyCode !== $currentCurrency) {
280+
if ($quote->getQuoteCurrencyCode() != $this->_storeManager->getStore()->getCurrentCurrencyCode()) {
283281
$quote->setStore($this->_storeManager->getStore());
284282
$this->quoteRepository->save($quote->collectTotals());
285283
/*

app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -434,24 +434,20 @@ public function testGetQuote(): void
434434
$customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
435435
$quoteRepository = $this->getMockForAbstractClass(CartRepositoryInterface::class);
436436
$quoteFactory = $this->createMock(QuoteFactory::class);
437-
$quote = $this->getMockBuilder(Quote::class)
438-
->disableOriginalConstructor()
439-
->addMethods(['getQuoteCurrencyCode', 'getTotalsCollectedFlag'])
440-
->onlyMethods(['collectTotals', 'setCustomer'])
441-
->getMock();
437+
$quote = $this->createMock(Quote::class);
442438
$logger = $this->getMockForAbstractClass(LoggerInterface::class);
443439
$loggerMethods = get_class_methods(LoggerInterface::class);
444440

445441
$quoteFactory->expects($this->once())
446442
->method('create')
447443
->willReturn($quote);
448-
$customerSession->expects($this->exactly(2))->method('isLoggedIn')->willReturn(true);
444+
$customerSession->expects($this->exactly(3))
445+
->method('isLoggedIn')
446+
->willReturn(true);
449447
$store = $this->getMockBuilder(Store::class)
450448
->disableOriginalConstructor()
451-
->onlyMethods(['getWebsiteId', 'getCurrentCurrencyCode'])
449+
->onlyMethods(['getWebsiteId'])
452450
->getMock();
453-
$store->expects($this->any())->method('getWebsiteId')->willReturn(1);
454-
$store->expects($this->any())->method('getCurrentCurrencyCode')->willReturn('USD');
455451
$storeManager->expects($this->any())
456452
->method('getStore')
457453
->willReturn($store);
@@ -461,24 +457,18 @@ public function testGetQuote(): void
461457
->getMock();
462458
$storage
463459
->method('getData')
464-
->willReturnCallback(function ($key) {
465-
if ($key === 'quote_id_1') {
466-
return 123;
467-
}
468-
return null;
469-
});
460+
->willReturnOnConsecutiveCalls(null, null, 1);
470461
$quoteRepository->expects($this->once())
471-
->method('getActive')
472-
->with(123)
473-
->willReturn($quote);
462+
->method('getActiveForCustomer')
463+
->willThrowException(new NoSuchEntityException());
474464

475465
foreach ($loggerMethods as $method) {
476466
$logger->expects($this->never())->method($method);
477467
}
478-
$quote->expects($this->once())->method('getQuoteCurrencyCode')->willReturn(null);
479-
$quote->expects($this->once())->method('getTotalsCollectedFlag')->willReturn(false);
480-
$quote->expects($this->once())->method('collectTotals')->willReturnSelf();
481-
$quote->expects($this->once())->method('setCustomer')->with(null);
468+
469+
$quote->expects($this->once())
470+
->method('setCustomer')
471+
->with(null);
482472

483473
$constructArguments = $this->helper->getConstructArguments(
484474
Session::class,

app/code/Magento/LoginAsCustomerFrontendUi/Controller/Login/Index.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\LoginAsCustomerApi\Api\GetAuthenticationDataBySecretInterface;
2121
use Magento\LoginAsCustomerApi\Api\AuthenticateCustomerBySecretInterface;
2222
use Psr\Log\LoggerInterface;
23+
use Magento\Checkout\Model\Session as CheckoutSession;
2324

2425
/**
2526
* Login as Customer storefront login action
@@ -68,6 +69,11 @@ class Index implements HttpGetActionInterface
6869
*/
6970
private $customerSession;
7071

72+
/**
73+
* @var CheckoutSession
74+
*/
75+
private $checkoutSession;
76+
7177
/**
7278
* @param ResultFactory $resultFactory
7379
* @param RequestInterface $request
@@ -77,6 +83,7 @@ class Index implements HttpGetActionInterface
7783
* @param ManagerInterface $messageManager
7884
* @param LoggerInterface $logger
7985
* @param Session|null $customerSession
86+
* @param CheckoutSession|null $checkoutSession
8087
*/
8188
public function __construct(
8289
ResultFactory $resultFactory,
@@ -86,7 +93,8 @@ public function __construct(
8693
AuthenticateCustomerBySecretInterface $authenticateCustomerBySecret,
8794
ManagerInterface $messageManager,
8895
LoggerInterface $logger,
89-
?Session $customerSession = null
96+
?Session $customerSession = null,
97+
?CheckoutSession $checkoutSession = null
9098
) {
9199
$this->resultFactory = $resultFactory;
92100
$this->request = $request;
@@ -96,6 +104,8 @@ public function __construct(
96104
$this->messageManager = $messageManager;
97105
$this->logger = $logger;
98106
$this->customerSession = $customerSession ?? ObjectManager::getInstance()->get(Session::class);
107+
$this->checkoutSession = $checkoutSession
108+
?? ObjectManager::getInstance()->get(CheckoutSession::class);
99109
}
100110

101111
/**
@@ -109,6 +119,10 @@ public function execute(): ResultInterface
109119
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
110120

111121
$secret = $this->request->getParam('secret');
122+
if ($this->checkoutSession->getQuoteId()) {
123+
$this->checkoutSession->clearQuote();
124+
$this->checkoutSession->clearStorage();
125+
}
112126
try {
113127
$this->authenticateCustomerBySecret->execute($secret);
114128
$customer = $this->customerSession->getCustomer();

0 commit comments

Comments
 (0)