@@ -1443,30 +1443,26 @@ public function autoSetAddresses(): bool
14431443 return false ;
14441444 }
14451445
1446+ /** @var User|CustomerBehavior|null $user */
14461447 $ user = $ this ->getCustomer ();
1448+ if (!$ user ) {
1449+ return false ;
1450+ }
1451+
14471452 $ autoSetOccurred = false ;
14481453
1449- if (!$ this ->_shippingAddress && $ user ) {
1450- /** @var User|CustomerBehavior $user */
1451- if ($ primaryShippingAddressId = $ user ->getPrimaryShippingAddressId ()) {
1452- if ($ userShippingAddress = Address::find ()->id ($ primaryShippingAddressId )->ownerId ($ user ->id )->one ()) {
1453- $ this ->sourceShippingAddressId = $ primaryShippingAddressId ;
1454- $ billingAddress = Craft::$ app ->getElements ()->duplicateElement ($ userShippingAddress , ['ownerId ' => $ this ->id ]);
1455- $ this ->setShippingAddress ($ billingAddress );
1456- $ autoSetOccurred = true ;
1457- }
1458- }
1454+ if (!$ this ->_shippingAddress && $ primaryShippingAddress = $ user ->getPrimaryShippingAddress ()) {
1455+ $ this ->sourceShippingAddressId = $ primaryShippingAddress ->id ;
1456+ $ shippingAddress = Craft::$ app ->getElements ()->duplicateElement ($ primaryShippingAddress , ['ownerId ' => $ this ->id ]);
1457+ $ this ->setShippingAddress ($ shippingAddress );
1458+ $ autoSetOccurred = true ;
14591459 }
14601460
1461- if (!$ this ->_billingAddress && $ user ) {
1462- if ($ primaryBillingAddressId = $ user ->getPrimaryBillingAddressId ()) {
1463- if ($ userBillingAddress = Address::find ()->id ($ primaryBillingAddressId )->ownerId ($ user ->id )->one ()) {
1464- $ this ->sourceBillingAddressId = $ primaryBillingAddressId ;
1465- $ billingAddress = Craft::$ app ->getElements ()->duplicateElement ($ userBillingAddress , ['ownerId ' => $ this ->id ]);
1466- $ this ->setBillingAddress ($ billingAddress );
1467- $ autoSetOccurred = true ;
1468- }
1469- }
1461+ if (!$ this ->_billingAddress && $ primaryBillingAddress = $ user ->getPrimaryBillingAddress ()) {
1462+ $ this ->sourceBillingAddressId = $ primaryBillingAddress ->id ;
1463+ $ billingAddress = Craft::$ app ->getElements ()->duplicateElement ($ primaryBillingAddress , ['ownerId ' => $ this ->id ]);
1464+ $ this ->setBillingAddress ($ billingAddress );
1465+ $ autoSetOccurred = true ;
14701466 }
14711467
14721468 return $ autoSetOccurred ;
0 commit comments