Skip to content

Commit 9c5d1be

Browse files
committed
Merge remote-tracking branch 'tango/MC-37321' into MPI-2020-09-14
2 parents 3b62462 + 174ad31 commit 9c5d1be

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ public function getQuote()
291291
}
292292
} else {
293293
$quote->setIsCheckoutCart(true);
294+
$quote->setCustomerIsGuest(1);
294295
$this->_eventManager->dispatch('checkout_quote_init', ['quote' => $quote]);
295296
}
296297
}
@@ -382,8 +383,10 @@ public function loadCustomerQuote()
382383

383384
if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
384385
if ($this->getQuoteId()) {
386+
$quote = $this->getQuote();
387+
$quote->setCustomerIsGuest(0);
385388
$this->quoteRepository->save(
386-
$customerQuote->merge($this->getQuote())->collectTotals()
389+
$customerQuote->merge($quote)->collectTotals()
387390
);
388391
$newQuote = $this->quoteRepository->get($customerQuote->getId());
389392
$this->quoteRepository->save(
@@ -402,6 +405,7 @@ public function loadCustomerQuote()
402405
$this->getQuote()->getBillingAddress();
403406
$this->getQuote()->getShippingAddress();
404407
$this->getQuote()->setCustomer($this->_customerSession->getCustomerDataObject())
408+
->setCustomerIsGuest(0)
405409
->setTotalsCollectedFlag(false)
406410
->collectTotals();
407411
$this->quoteRepository->save($this->getQuote());

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
139139
!$this->_persistentSession->isPersistent() &&
140140
!$this->_customerSession->isLoggedIn() &&
141141
$this->_checkoutSession->getQuoteId() &&
142-
!$this->isRequestFromCheckoutPage($this->request) &&
143142
// persistent session does not expire on onepage checkout page
144-
$this->isNeedToExpireSession()
143+
!$this->isRequestFromCheckoutPage($this->request) &&
144+
$this->getQuote()->getIsPersistent()
145145
) {
146146
$this->_eventManager->dispatch('persistent_session_expired');
147147
$this->quoteManager->expire();
@@ -168,18 +168,6 @@ private function isPersistentQuoteOutdated(): bool
168168
return false;
169169
}
170170

171-
/**
172-
* Condition checker
173-
*
174-
* @return bool
175-
* @throws \Magento\Framework\Exception\LocalizedException
176-
* @throws \Magento\Framework\Exception\NoSuchEntityException
177-
*/
178-
private function isNeedToExpireSession(): bool
179-
{
180-
return $this->getQuote()->getIsPersistent() || $this->getQuote()->getCustomerIsGuest();
181-
}
182-
183171
/**
184172
* Getter for Quote with micro optimization
185173
*

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Magento\Store\Model\StoreManagerInterface;
2525

2626
/**
27-
* Class QuoteManagement
27+
* Class for managing quote
2828
*
2929
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
3030
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -250,6 +250,7 @@ public function createEmptyCart()
250250

251251
$quote->setBillingAddress($this->quoteAddressFactory->create());
252252
$quote->setShippingAddress($this->quoteAddressFactory->create());
253+
$quote->setCustomerIsGuest(1);
253254

254255
try {
255256
$quote->getShippingAddress()->setCollectShippingRates(true);

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CreateEmptyCartTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class CreateEmptyCartTest extends GraphQlAbstract
3939
*/
4040
private $quoteIdMaskFactory;
4141

42+
/**
43+
* @var string
44+
*/
45+
private $maskedQuoteId;
46+
4247
protected function setUp(): void
4348
{
4449
$objectManager = Bootstrap::getObjectManager();
@@ -61,6 +66,7 @@ public function testCreateEmptyCart()
6166
self::assertNotNull($guestCart->getId());
6267
self::assertNull($guestCart->getCustomer()->getId());
6368
self::assertEquals('default', $guestCart->getStore()->getCode());
69+
self::assertEquals('1', $guestCart->getCustomerIsGuest());
6470
}
6571

6672
/**
@@ -81,6 +87,7 @@ public function testCreateEmptyCartWithNotDefaultStore()
8187
self::assertNotNull($guestCart->getId());
8288
self::assertNull($guestCart->getCustomer()->getId());
8389
self::assertSame('fixture_second_store', $guestCart->getStore()->getCode());
90+
self::assertEquals('1', $guestCart->getCustomerIsGuest());
8491
}
8592

8693
/**

dev/tests/integration/testsuite/Magento/Checkout/Model/SessionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ public function testLoadCustomerQuoteCustomerWithoutQuote(): void
199199
$this->quote->getCustomerEmail(),
200200
'Precondition failed: Customer data must not be set to quote'
201201
);
202+
self::assertEquals(
203+
'1',
204+
$this->quote->getCustomerIsGuest(),
205+
'Precondition failed: Customer must be as guest in quote'
206+
);
202207
$customer = $this->customerRepository->getById(1);
203208
$this->customerSession->setCustomerDataObject($customer);
204209
$this->quote = $this->checkoutSession->getQuote();
@@ -244,6 +249,17 @@ public function testGetQuoteWithProductWithTierPrice(): void
244249
$this->assertEquals($tierPriceValue, $quoteProduct->getTierPrice(1));
245250
}
246251

252+
/**
253+
* Test covers case when quote is not yet initialized and customer is guest
254+
*
255+
* Expected result - quote object should be loaded with customer as guest
256+
*/
257+
public function testGetQuoteNotInitializedGuest()
258+
{
259+
$quote = $this->checkoutSession->getQuote();
260+
self::assertEquals('1', $quote->getCustomerIsGuest());
261+
}
262+
247263
/**
248264
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
249265
* @magentoDataFixture Magento/Checkout/_files/quote_with_customer_without_address.php
@@ -288,5 +304,10 @@ private function validateCustomerDataInQuote(CartInterface $quote): void
288304
$quote->getCustomerFirstname(),
289305
'Customer first name was not set to Quote correctly.'
290306
);
307+
self::assertEquals(
308+
'0',
309+
$quote->getCustomerIsGuest(),
310+
'Customer should not be as guest in Quote.'
311+
);
291312
}
292313
}

0 commit comments

Comments
 (0)