@@ -381,10 +381,13 @@ protected function createCustomerCart($customerId, $storeId)
381
381
382
382
/**
383
383
* @inheritdoc
384
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
384
385
*/
385
386
public function placeOrder ($ cartId , PaymentInterface $ paymentMethod = null )
386
387
{
387
388
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
389
+ $ customer = $ quote ->getCustomer ();
390
+
388
391
if ($ paymentMethod ) {
389
392
$ paymentMethod ->setChecks (
390
393
[
@@ -403,18 +406,22 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
403
406
$ quote ->collectTotals ();
404
407
}
405
408
406
- if ($ quote ->getCheckoutMethod () === self ::METHOD_GUEST || !$ quote -> getCustomer () ) {
409
+ if ($ quote ->getCheckoutMethod () === self ::METHOD_GUEST || !$ customer ) {
407
410
$ 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 ());
414
421
}
415
422
}
416
423
$ quote ->setCustomerIsGuest (true );
417
- $ groupId = $ quote -> getCustomer ()-> getGroupId () ? : GroupInterface::NOT_LOGGED_IN_ID ;
424
+ $ groupId = $ customer ? $ customer -> getGroupId () : GroupInterface::NOT_LOGGED_IN_ID ;
418
425
$ quote ->setCustomerGroupId ($ groupId );
419
426
}
420
427
0 commit comments