44
44
use Buckaroo \Magento2 \Model \Method \Voucher ;
45
45
use Buckaroo \Magento2 \Model \Refund \Push as RefundPush ;
46
46
use Buckaroo \Magento2 \Model \Validator \Push as ValidatorPush ;
47
- use Magento \Customer \Api \Data \GroupInterface ;
48
47
use Magento \Framework \App \ResourceConnection ;
49
48
use Magento \Framework \Filesystem \DirectoryList ;
50
49
use Magento \Framework \ObjectManagerInterface ;
@@ -389,9 +388,7 @@ private function updateOrderWithAddresses($shippingAddress, $billingAddress)
389
388
$ orderAddressRepository ->save ($ orderBillingAddress );
390
389
}
391
390
392
- $ this ->updateGuestCustomerInformation ($ order , $ billingAddress );
393
-
394
-
391
+ $ this ->updateCustomerInformation ($ order , $ billingAddress );
395
392
396
393
} catch (\Exception $ e ) {
397
394
$ this ->logging ->addDebug (__METHOD__ . '|Failed to update addresses| ' );
@@ -408,25 +405,46 @@ private function updateOrderWithAddresses($shippingAddress, $billingAddress)
408
405
* @param Order $order
409
406
* @param array $billingAddress
410
407
*/
411
- private function updateGuestCustomerInformation (Order $ order , array $ billingAddress )
408
+ private function updateCustomerInformation (Order $ order , array $ billingAddress )
409
+ {
410
+ if ($ this ->isGuestOrder ($ order )) {
411
+ $ this ->updateGuestInformation ($ order , $ billingAddress );
412
+ } else {
413
+ $ this ->updateRegisteredCustomerInformation ($ order );
414
+ }
415
+
416
+ $ order ->save ();
417
+ }
418
+
419
+ private function isGuestOrder (Order $ order ): bool
420
+ {
421
+ return !$ order ->getCustomerId ();
422
+ }
423
+
424
+ private function updateGuestInformation (Order $ order , array $ billingAddress ): void
412
425
{
413
- if ($ order ->getCustomerGroupId () == GroupInterface::NOT_LOGGED_IN_ID ) {
414
- // For guest customers, use billing address details
426
+ try {
415
427
$ customerEmail = $ this ->postData ['brq_service_ideal_contactdetailsemail ' ] ?? $ order ->getCustomerEmail ();
416
428
$ order ->setCustomerEmail ($ customerEmail );
417
429
$ order ->setCustomerFirstname ($ billingAddress ['firstname ' ] ?? $ order ->getCustomerFirstname ());
418
430
$ order ->setCustomerLastname ($ billingAddress ['lastname ' ] ?? $ order ->getCustomerLastname ());
419
- }else {
420
- // For registered customers, use their stored details
431
+ } catch (\Exception $ e ) {
432
+ $ this ->logging ->addError ('Error updating guest information: ' . $ e ->getMessage ());
433
+ }
434
+ }
435
+
436
+ private function updateRegisteredCustomerInformation (Order $ order ): void
437
+ {
438
+ try {
421
439
$ customer = $ order ->getCustomer ();
422
440
if ($ customer ) {
423
441
$ order ->setCustomerFirstname ($ customer ->getFirstname () ?? $ order ->getCustomerFirstname ());
424
442
$ order ->setCustomerLastname ($ customer ->getLastname () ?? $ order ->getCustomerLastname ());
425
443
$ order ->setCustomerEmail ($ customer ->getEmail () ?? $ order ->getCustomerEmail ());
426
444
}
445
+ } catch (\Exception $ e ) {
446
+ $ this ->logging ->addError ('Error updating registered customer information: ' . $ e ->getMessage ());
427
447
}
428
-
429
- $ order ->save ();
430
448
}
431
449
432
450
private function pushProcess ()
0 commit comments