Skip to content

Commit 870ccee

Browse files
committed
MCP-595: [MCP-304] [QA] [BUG] Order cannot be processed if customer is deleted
1 parent 063188a commit 870ccee

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,13 @@ protected function createCustomerCart($customerId, $storeId)
381381

382382
/**
383383
* @inheritdoc
384+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
384385
*/
385386
public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
386387
{
387388
$quote = $this->quoteRepository->getActive($cartId);
389+
$customer = $quote->getCustomer();
390+
388391
if ($paymentMethod) {
389392
$paymentMethod->setChecks(
390393
[
@@ -403,18 +406,22 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
403406
$quote->collectTotals();
404407
}
405408

406-
if ($quote->getCheckoutMethod() === self::METHOD_GUEST || !$quote->getCustomer()) {
409+
if ($quote->getCheckoutMethod() === self::METHOD_GUEST || !$customer) {
407410
$quote->setCustomerId(null);
408-
$quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
409-
if ($quote->getCustomerFirstname() === null && $quote->getCustomerLastname() === null) {
410-
$quote->setCustomerFirstname($quote->getBillingAddress()->getFirstname());
411-
$quote->setCustomerLastname($quote->getBillingAddress()->getLastname());
412-
if ($quote->getBillingAddress()->getMiddlename() === null) {
413-
$quote->setCustomerMiddlename($quote->getBillingAddress()->getMiddlename());
411+
$billingAddress = $quote->getBillingAddress();
412+
$quote->setCustomerEmail($billingAddress ? $billingAddress->getEmail() : null);
413+
if ($quote->getCustomerFirstname() === null
414+
&& $quote->getCustomerLastname() === null
415+
&& $billingAddress
416+
) {
417+
$quote->setCustomerFirstname($billingAddress->getFirstname());
418+
$quote->setCustomerLastname($billingAddress->getLastname());
419+
if ($billingAddress->getMiddlename() === null) {
420+
$quote->setCustomerMiddlename($billingAddress->getMiddlename());
414421
}
415422
}
416423
$quote->setCustomerIsGuest(true);
417-
$groupId = $quote->getCustomer()->getGroupId() ?: GroupInterface::NOT_LOGGED_IN_ID;
424+
$groupId = $customer ? $customer->getGroupId() : GroupInterface::NOT_LOGGED_IN_ID;
418425
$quote->setCustomerGroupId($groupId);
419426
}
420427

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Customer\Api\Data\GroupInterface;
1919
use Magento\Customer\Model\Customer;
2020
use Magento\Customer\Model\CustomerFactory;
21+
use Magento\Customer\Model\Session as CustomerSession;
2122
use Magento\Framework\Api\DataObjectHelper;
2223
use Magento\Framework\App\RequestInterface;
2324
use Magento\Framework\Event\ManagerInterface;
@@ -274,7 +275,7 @@ protected function setUp(): void
274275
)
275276
->disableOriginalConstructor()
276277
->getMock();
277-
$this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
278+
$this->customerSessionMock = $this->createMock(CustomerSession::class);
278279
$this->accountManagementMock = $this->getMockForAbstractClass(AccountManagementInterface::class);
279280

280281
$this->quoteFactoryMock = $this->createPartialMock(QuoteFactory::class, ['create']);
@@ -737,11 +738,9 @@ public function testSubmit(): void
737738
$convertedShipping = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']);
738739
$convertedPayment = $this->getMockForAbstractClass(OrderPaymentInterface::class);
739740
$convertedQuoteItem = $this->getMockForAbstractClass(OrderItemInterface::class);
740-
741741
$addresses = [$convertedShipping, $convertedBilling];
742742
$quoteItems = [$quoteItem];
743743
$convertedItems = [$convertedQuoteItem];
744-
745744
$quote = $this->getQuote(
746745
$isGuest,
747746
$isVirtual,
@@ -976,9 +975,6 @@ public function testPlaceOrder(): void
976975
$this->quoteMock->expects($this->once())
977976
->method('getCheckoutMethod')
978977
->willReturn(Onepage::METHOD_CUSTOMER);
979-
$this->quoteMock->expects($this->never())
980-
->method('setCustomerIsGuest')
981-
->with(true);
982978

983979
$this->remoteAddressMock
984980
->method('getRemoteAddress')

0 commit comments

Comments
 (0)