Skip to content

Commit daede85

Browse files
committed
Update for merging carts with replacing code into try/catch block
1 parent e5095fb commit daede85

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,26 +299,15 @@ public function assignCustomer($cartId, $customerId, $storeId)
299299
}
300300
try {
301301
$customerActiveQuote = $this->quoteRepository->getForCustomer($customerId);
302-
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
303-
/** This exception appear when customer have no active cart*/
304-
$customerActiveQuote = false;
305-
}
306302

307-
if ($customerActiveQuote) {
308-
try {
309-
/** Merge carts */
310-
$quote->merge($customerActiveQuote);
311-
$customerActiveQuote->setIsActive(0);
312-
$this->quoteRepository->save($customerActiveQuote);
313-
} catch (\Exception $e) {
314-
$message = sprintf(
315-
"The customer can't be assigned to the cart. Error on cart merging: %s",
316-
$e->getMessage()
317-
);
318-
throw new StateException($message);
319-
}
303+
$quote->merge($customerActiveQuote);
304+
$customerActiveQuote->setIsActive(0);
305+
$this->quoteRepository->save($customerActiveQuote);
320306

307+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
308+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
321309
}
310+
322311
$quote->setCustomer($customer);
323312
$quote->setCustomerIsGuest(0);
324313
$quote->setIsActive(1);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ public function testAssignCustomer()
627627
->with($customerId)
628628
->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException());
629629

630-
$this->assertEquals(false, $activeQuoteMock);
631630
$quoteMock->expects($this->never())->method('merge');
632631

633632
$quoteMock->expects($this->once())->method('setCustomer')->with($customerMock);

0 commit comments

Comments
 (0)