@@ -479,24 +479,26 @@ protected function formatCustomer($order)
479479
480480 protected function formatAddress ($ address )
481481 {
482- $ addressData = array (
483- 'type ' => 'address ' ,
484- 'first_name ' => $ address ->getFirstname (),
485- 'last_name ' => $ address ->getLastname (),
486- 'city ' => $ address ->getCity (),
487- 'county ' => $ address ->getRegion (),
488- 'postcode ' => $ address ->getPostcode (),
489- 'country ' => $ address ->getCountryId (),
490- 'phone ' => $ address ->getTelephone ()
491- );
492-
493- $ entityId = $ address ->getEntityId ();
494- $ addressId = $ address ->getCustomerAddressId ();
495- $ addressData ['id ' ] = $ addressId ?: $ entityId ;
496-
497- $ street = $ address ->getStreet ();
498- $ addressData ['line_1 ' ] = $ street [0 ] ?: '' ;
499- $ addressData ['line_2 ' ] = $ street [1 ] ?: '' ;
482+ if ($ address ) {
483+ $ addressData = array (
484+ 'type ' => 'address ' ,
485+ 'first_name ' => $ address ->getFirstname (),
486+ 'last_name ' => $ address ->getLastname (),
487+ 'city ' => $ address ->getCity (),
488+ 'county ' => $ address ->getRegion (),
489+ 'postcode ' => $ address ->getPostcode (),
490+ 'country ' => $ address ->getCountryId (),
491+ 'phone ' => $ address ->getTelephone ()
492+ );
493+
494+ $ entityId = $ address ->getEntityId ();
495+ $ addressId = $ address ->getCustomerAddressId ();
496+ $ addressData ['id ' ] = $ addressId ?: $ entityId ;
497+
498+ $ street = $ address ->getStreet ();
499+ $ addressData ['line_1 ' ] = $ street [0 ] ?: '' ;
500+ $ addressData ['line_2 ' ] = $ street [1 ] ?: '' ;
501+ }
500502
501503 return $ addressData ;
502504 }
@@ -517,7 +519,7 @@ public function getShipments($order)
517519 if (count ($ tracks ) > 0 ) {
518520 foreach ($ tracks as $ track ) {
519521 if ($ shipmentId == $ track ->getParentId ()) {
520- $ shipments [] = array (
522+ $ shipment = array (
521523 'id ' => $ track ->getEntityId (),
522524 'carrier ' => $ track ->getTitle (),
523525 'carrier_code ' => $ track ->getCarrierCode (),
@@ -526,24 +528,32 @@ public function getShipments($order)
526528 'created_at ' => $ track ->getCreatedAt (),
527529 'updated_at ' => $ track ->getUpdatedAt (),
528530 'tracking_number ' => $ track ->getTrackNumber (),
529- 'shipping_address ' => $ this ->formatAddress ($ shippingAddress ),
530531 'order_status ' => $ orderStatus ,
531532 );
532- }
533+ if ($ shippingAddress ) {
534+ $ shipment ['shipping_address ' ] = $ this ->formatAddress ($ shippingAddress );
535+ }
536+ $ shipments [] = $ shipment ;
537+ }
533538 }
534539 } else {
535- $ shipments [] = array (
540+ $ shipment = array (
536541 'service_code ' => $ serviceCode ,
537542 'carrier_code ' => $ order ->getShippingMethod (),
538- 'shipping_address ' => $ this ->formatAddress ($ shippingAddress ),
539543 'order_status ' => $ orderStatus ,
540544 );
545+ if ($ shippingAddress ) {
546+ $ shipment ['shipping_address ' ] = $ this ->formatAddress ($ shippingAddress );
547+ }
548+ $ shipments [] = $ shipment ;
541549 }
542550 } else {
543551 $ shippingAddress = $ order ->getShippingAddress ();
544- $ shipments [] = array (
545- 'shipping_address ' => $ this ->formatAddress ($ shippingAddress ),
546- );
552+ if ($ shippingAddress ) {
553+ $ shipments [] = array (
554+ 'shipping_address ' => $ this ->formatAddress ($ shippingAddress ),
555+ );
556+ }
547557 }
548558
549559 return $ shipments ;
@@ -558,13 +568,13 @@ public function getOrderDetailBasic($order)
558568 $ shippingAddress = $ order ->getShippingAddress ();
559569 $ shippingWithTax = $ order ->getShippingInclTax ();
560570 $ shippingMethod = $ order ->getShippingMethod ();
571+ $ billingAddress = $ order ->getBillingAddress ();
561572
562573 $ orderInfo = array (
563574 'id ' => $ order ->getIncrementId (),
564575 'url ' => $ urlModel ->getUrl ('adminhtml/sales_order/view ' , array ('order_id ' => $ order ->getId ())),
565576 'transaction_id ' => $ order ->getIncrementId (),
566577 'status ' => $ order ->getStatus (),
567- 'billing_address ' => $ this ->formatAddress ($ order ->getBillingAddress ()),
568578 'meta ' => array (
569579 'store_info ' => array (
570580 'type ' => 'store_info ' ,
@@ -590,6 +600,9 @@ public function getOrderDetailBasic($order)
590600 ),
591601 'shipments ' => array (),
592602 );
603+ if ($ billingAddress ) {
604+ $ orderInfo ['billing_address ' ] = $ this ->formatAddress ($ billingAddress );
605+ }
593606
594607 foreach ($ order ->getItemsCollection (array (), true ) as $ item ) {
595608 $ itemWithTax = $ item ->getRowTotal ();
@@ -772,7 +785,9 @@ public function getCustomer($customer)
772785 );
773786
774787 foreach ($ customer ->getAddressesCollection () as $ address ) {
775- $ info ['addresses ' ][] = $ this ->formatAddress ($ address );
788+ if ($ address ) {
789+ $ info ['addresses ' ][] = $ this ->formatAddress ($ address );
790+ }
776791 }
777792
778793 return $ info ;
@@ -825,7 +840,7 @@ public function getFilteredOrdersByProduct($customerFilters, $productFilters)
825840 );
826841 }
827842
828- if ($ email ) {
843+ if ($ email ) {
829844 $ filteredOrdersData = array_filter (array_values ($ ordersData ), function ($ orderData ) use ($ email ) {
830845 return ($ orderData ['email ' ] == $ email );
831846 });
0 commit comments