@@ -154,46 +154,6 @@ public function setApiToken($token = null)
154154 return $ token ;
155155 }
156156
157- /**
158- * Returns the provisioning endpoint for new setups.
159- *
160- * This uses the config/zendesk/provision_url XML path to retrieve the setting, with a default value set in
161- * the extension config.xml file. This can be overridden in your website's local.xml file.
162- * @return null|string URL or null on failure
163- */
164- public function getProvisionUrl ()
165- {
166- $ config = Mage::getConfig ();
167- $ data = $ config ->getNode ('zendesk/provision_url ' );
168- if (!$ data ) {
169- return null ;
170- }
171- return (string )$ data ;
172- }
173-
174- public function getProvisionToken ($ generate = false )
175- {
176- $ token = Mage::getStoreConfig ('zendesk/hidden/provision_token ' , 0 );
177-
178- if ( (!$ token || strlen (trim ($ token )) == 0 ) && $ generate ) {
179- $ token = $ this ->setProvisionToken ();
180- }
181-
182- return $ token ;
183- }
184-
185- public function setProvisionToken ($ token = null )
186- {
187- if (!$ token ) {
188- $ token = hash ('sha256 ' , Mage::helper ('oauth ' )->generateToken ());
189- }
190-
191- Mage::getModel ('core/config ' )->saveConfig ('zendesk/hidden/provision_token ' , $ token , 'default ' );
192- Mage::getConfig ()->removeCache ();
193-
194- return $ token ;
195- }
196-
197157 public function getOrderDetail ($ order )
198158 {
199159 // if the admin site has a custom URL, use it
@@ -479,24 +439,26 @@ protected function formatCustomer($order)
479439
480440 protected function formatAddress ($ address )
481441 {
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 ] ?: '' ;
442+ if ($ address ) {
443+ $ addressData = array (
444+ 'type ' => 'address ' ,
445+ 'first_name ' => $ address ->getFirstname (),
446+ 'last_name ' => $ address ->getLastname (),
447+ 'city ' => $ address ->getCity (),
448+ 'county ' => $ address ->getRegion (),
449+ 'postcode ' => $ address ->getPostcode (),
450+ 'country ' => $ address ->getCountryId (),
451+ 'phone ' => $ address ->getTelephone ()
452+ );
453+
454+ $ entityId = $ address ->getEntityId ();
455+ $ addressId = $ address ->getCustomerAddressId ();
456+ $ addressData ['id ' ] = $ addressId ?: $ entityId ;
457+
458+ $ street = $ address ->getStreet ();
459+ $ addressData ['line_1 ' ] = $ street [0 ] ?: '' ;
460+ $ addressData ['line_2 ' ] = $ street [1 ] ?: '' ;
461+ }
500462
501463 return $ addressData ;
502464 }
@@ -505,44 +467,52 @@ public function getShipments($order)
505467 {
506468 $ shipments = array ();
507469 $ orderStatus = $ order ->getStatus ();
470+ $ serviceCode = $ order ->getShippingDescription ();
471+ $ tracks = $ order ->getTracksCollection ();
472+ $ shippingMethod = $ order ->getShippingMethod ();
473+ $ orderShippingAddress = $ order ->getShippingAddress ();
508474
509475 foreach ($ order ->getShipmentsCollection () as $ shipment ) {
510476 $ shipmentId = $ shipment ->getEntityId ();
511477 $ shippingAddress = $ shipment ->getShippingAddress ();
512- $ serviceCode = $ order ->getShippingDescription ();
513- }
514-
515- if ($ shipmentId ) {
516- $ tracks = $ order ->getTracksCollection ();
517- if (count ($ tracks ) > 0 ) {
518- foreach ($ tracks as $ track ) {
519- if ($ shipmentId == $ track ->getParentId ()) {
520- $ shipments [] = array (
521- 'id ' => $ track ->getEntityId (),
522- 'carrier ' => $ track ->getTitle (),
523- 'carrier_code ' => $ track ->getCarrierCode (),
524- 'service_code ' => $ serviceCode ,
525- 'shipping_description ' => $ track ->getDescription () ?: '' ,
526- 'created_at ' => $ track ->getCreatedAt (),
527- 'updated_at ' => $ track ->getUpdatedAt (),
528- 'tracking_number ' => $ track ->getTrackNumber (),
529- 'shipping_address ' => $ this ->formatAddress ($ shippingAddress ),
530- 'order_status ' => $ orderStatus ,
531- );
478+ if ($ shipmentId ) {
479+ if (count ($ tracks ) > 0 ) {
480+ foreach ($ tracks as $ track ) {
481+ if ($ shipmentId == $ track ->getParentId ()) {
482+ $ shipment = array (
483+ 'id ' => $ track ->getEntityId (),
484+ 'carrier ' => $ track ->getTitle (),
485+ 'carrier_code ' => $ track ->getCarrierCode (),
486+ 'service_code ' => $ serviceCode ,
487+ 'shipping_description ' => $ track ->getDescription () ?: '' ,
488+ 'created_at ' => $ track ->getCreatedAt (),
489+ 'updated_at ' => $ track ->getUpdatedAt (),
490+ 'tracking_number ' => $ track ->getTrackNumber (),
491+ 'order_status ' => $ orderStatus ,
492+ );
493+ if ($ shippingAddress ) {
494+ $ shipment ['shipping_address ' ] = $ this ->formatAddress ($ shippingAddress );
495+ }
496+ $ shipments [] = $ shipment ;
497+ }
498+ }
499+ } else {
500+ $ shipment = array (
501+ 'service_code ' => $ serviceCode ,
502+ 'carrier_code ' => $ shippingMethod ,
503+ 'order_status ' => $ orderStatus ,
504+ );
505+ if ($ shippingAddress ) {
506+ $ shipment ['shipping_address ' ] = $ this ->formatAddress ($ shippingAddress );
532507 }
508+ $ shipments [] = $ shipment ;
533509 }
534- } else {
535- $ shipments [] = array (
536- 'service_code ' => $ serviceCode ,
537- 'carrier_code ' => $ order ->getShippingMethod (),
538- 'shipping_address ' => $ this ->formatAddress ($ shippingAddress ),
539- 'order_status ' => $ orderStatus ,
540- );
541510 }
542- } else {
543- $ shippingAddress = $ order ->getShippingAddress ();
511+ }
512+
513+ if (empty ($ shipments ) && $ orderShippingAddress ) {
544514 $ shipments [] = array (
545- 'shipping_address ' => $ this ->formatAddress ($ shippingAddress ),
515+ 'shipping_address ' => $ this ->formatAddress ($ orderShippingAddress ),
546516 );
547517 }
548518
@@ -558,22 +528,22 @@ public function getOrderDetailBasic($order)
558528 $ shippingAddress = $ order ->getShippingAddress ();
559529 $ shippingWithTax = $ order ->getShippingInclTax ();
560530 $ shippingMethod = $ order ->getShippingMethod ();
531+ $ billingAddress = $ order ->getBillingAddress ();
561532
562533 $ orderInfo = array (
563534 'id ' => $ order ->getIncrementId (),
564535 'url ' => $ urlModel ->getUrl ('adminhtml/sales_order/view ' , array ('order_id ' => $ order ->getId ())),
565536 'transaction_id ' => $ order ->getIncrementId (),
566537 'status ' => $ order ->getStatus (),
567- 'billing_address ' => $ this ->formatAddress ($ order ->getBillingAddress ()),
568538 'meta ' => array (
569539 'store_info ' => array (
570540 'type ' => 'store_info ' ,
571541 'name ' => $ order ->getStoreName ()
572542 ),
573543 'display_price ' => array (
574544 'with_tax ' => $ this ->formatPrice ($ order ->getGrandTotal (), $ currency ),
575- 'without_tax ' => $ this ->formatPrice ($ order ->getGrandTotal () - $ order ->getTaxAmount (), $ currency ), // TODO: get without tax
576- 'tax ' => $ this ->formatPrice ($ order ->getTaxAmount (), $ currency ) // TODO: get tax
545+ 'without_tax ' => $ this ->formatPrice ($ order ->getGrandTotal () - $ order ->getTaxAmount (), $ currency ),
546+ 'tax ' => $ this ->formatPrice ($ order ->getTaxAmount (), $ currency )
577547 ),
578548 'timestamps ' => array (
579549 'created_at ' => $ order ->getCreatedAt (),
@@ -590,9 +560,12 @@ public function getOrderDetailBasic($order)
590560 ),
591561 'shipments ' => array (),
592562 );
563+ if ($ billingAddress ) {
564+ $ orderInfo ['billing_address ' ] = $ this ->formatAddress ($ billingAddress );
565+ }
593566
594567 foreach ($ order ->getItemsCollection (array (), true ) as $ item ) {
595- $ itemWithTax = $ item ->getRowTotal ();
568+ $ itemWithoutTax = $ item ->getRowTotal ();
596569 $ itemTax = $ item ->getTaxAmount ();
597570
598571 $ productId = $ item ->getProductId ();
@@ -610,8 +583,8 @@ public function getOrderDetailBasic($order)
610583 'refunded ' => intval ($ item ->getQtyRefunded ()),
611584 'meta ' => array (
612585 'display_price ' => array (
613- 'with_tax ' => $ this ->formatPrice ($ itemWithTax , $ currency ),
614- 'without_tax ' => $ this ->formatPrice ($ itemWithTax - $ itemTax , $ currency ),
586+ 'with_tax ' => $ this ->formatPrice ($ itemWithoutTax + $ itemTax , $ currency ),
587+ 'without_tax ' => $ this ->formatPrice ($ itemWithoutTax , $ currency ),
615588 'tax ' => $ this ->formatPrice ($ iitemTax , $ currency )
616589 ),
617590 'timestamps ' => array (
@@ -772,7 +745,9 @@ public function getCustomer($customer)
772745 );
773746
774747 foreach ($ customer ->getAddressesCollection () as $ address ) {
775- $ info ['addresses ' ][] = $ this ->formatAddress ($ address );
748+ if ($ address ) {
749+ $ info ['addresses ' ][] = $ this ->formatAddress ($ address );
750+ }
776751 }
777752
778753 return $ info ;
@@ -825,7 +800,7 @@ public function getFilteredOrdersByProduct($customerFilters, $productFilters)
825800 );
826801 }
827802
828- if ($ email ) {
803+ if ($ email ) {
829804 $ filteredOrdersData = array_filter (array_values ($ ordersData ), function ($ orderData ) use ($ email ) {
830805 return ($ orderData ['email ' ] == $ email );
831806 });
0 commit comments