Skip to content

Commit 55042ea

Browse files
committed
ACP2E-4137: [Cloud] No such entity with cartId
1 parent 6cda09a commit 55042ea

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

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

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

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,24 @@ 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->createMock(Quote::class);
437+
$quote = $this->getMockBuilder(Quote::class)
438+
->disableOriginalConstructor()
439+
->addMethods(['getQuoteCurrencyCode', 'getTotalsCollectedFlag'])
440+
->onlyMethods(['collectTotals', 'setCustomer'])
441+
->getMock();
438442
$logger = $this->getMockForAbstractClass(LoggerInterface::class);
439443
$loggerMethods = get_class_methods(LoggerInterface::class);
440444

441445
$quoteFactory->expects($this->once())
442446
->method('create')
443447
->willReturn($quote);
444-
$customerSession->expects($this->exactly(3))
445-
->method('isLoggedIn')
446-
->willReturn(true);
448+
$customerSession->expects($this->exactly(2))->method('isLoggedIn')->willReturn(true);
447449
$store = $this->getMockBuilder(Store::class)
448450
->disableOriginalConstructor()
449-
->onlyMethods(['getWebsiteId'])
451+
->onlyMethods(['getWebsiteId', 'getCurrentCurrencyCode'])
450452
->getMock();
453+
$store->expects($this->any())->method('getWebsiteId')->willReturn(1);
454+
$store->expects($this->any())->method('getCurrentCurrencyCode')->willReturn('USD');
451455
$storeManager->expects($this->any())
452456
->method('getStore')
453457
->willReturn($store);
@@ -457,18 +461,24 @@ public function testGetQuote(): void
457461
->getMock();
458462
$storage
459463
->method('getData')
460-
->willReturnOnConsecutiveCalls(null, null, 1);
464+
->willReturnCallback(function($key) {
465+
if ($key === 'quote_id_1') {
466+
return 123;
467+
}
468+
return null;
469+
});
461470
$quoteRepository->expects($this->once())
462-
->method('getActiveForCustomer')
463-
->willThrowException(new NoSuchEntityException());
471+
->method('getActive')
472+
->with(123)
473+
->willReturn($quote);
464474

465475
foreach ($loggerMethods as $method) {
466476
$logger->expects($this->never())->method($method);
467477
}
468-
469-
$quote->expects($this->once())
470-
->method('setCustomer')
471-
->with(null);
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);
472482

473483
$constructArguments = $this->helper->getConstructArguments(
474484
Session::class,

0 commit comments

Comments
 (0)