Skip to content

Commit 392fc3a

Browse files
committed
MC-37321: Quote customer_is_guest = false
1 parent f61214d commit 392fc3a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 4 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(true);
294295
$this->_eventManager->dispatch('checkout_quote_init', ['quote' => $quote]);
295296
}
296297
}
@@ -382,8 +383,9 @@ public function loadCustomerQuote()
382383

383384
if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
384385
if ($this->getQuoteId()) {
386+
$quote = $this->getQuote()->setCustomerIsGuest(false);
385387
$this->quoteRepository->save(
386-
$customerQuote->merge($this->getQuote())->collectTotals()
388+
$customerQuote->merge($quote)->collectTotals()
387389
);
388390
$newQuote = $this->quoteRepository->get($customerQuote->getId());
389391
$this->quoteRepository->save(
@@ -402,6 +404,7 @@ public function loadCustomerQuote()
402404
$this->getQuote()->getBillingAddress();
403405
$this->getQuote()->getShippingAddress();
404406
$this->getQuote()->setCustomer($this->_customerSession->getCustomerDataObject())
407+
->setCustomerIsGuest(false)
405408
->setTotalsCollectedFlag(false)
406409
->collectTotals();
407410
$this->quoteRepository->save($this->getQuote());

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ public function testLoadCustomerQuoteCustomerWithoutQuote(): void
199199
$this->quote->getCustomerEmail(),
200200
'Precondition failed: Customer data must not be set to quote'
201201
);
202+
$this->assertTrue(
203+
$this->quote->getCustomerIsGuest(),
204+
'Precondition failed: Customer must be as guest in quote'
205+
);
202206
$customer = $this->customerRepository->getById(1);
203207
$this->customerSession->setCustomerDataObject($customer);
204208
$this->quote = $this->checkoutSession->getQuote();
@@ -244,6 +248,17 @@ public function testGetQuoteWithProductWithTierPrice(): void
244248
$this->assertEquals($tierPriceValue, $quoteProduct->getTierPrice(1));
245249
}
246250

251+
/**
252+
* Test covers case when quote is not yet initialized and customer is guest
253+
*
254+
* Expected result - quote object should be loaded with customer as guest
255+
*/
256+
public function testGetQuoteNotInitializedGuest()
257+
{
258+
$quote = $this->checkoutSession->getQuote();
259+
$this->assertTrue($quote->getCustomerIsGuest());
260+
}
261+
247262
/**
248263
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
249264
* @magentoDataFixture Magento/Checkout/_files/quote_with_customer_without_address.php
@@ -288,5 +303,9 @@ private function validateCustomerDataInQuote(CartInterface $quote): void
288303
$quote->getCustomerFirstname(),
289304
'Customer first name was not set to Quote correctly.'
290305
);
306+
$this->assertFalse(
307+
$quote->getCustomerIsGuest(),
308+
'Customer should not be as guest in Quote.'
309+
);
291310
}
292311
}

0 commit comments

Comments
 (0)