@@ -154,46 +154,6 @@ public function setApiToken($token = null)
154
154
return $ token ;
155
155
}
156
156
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
-
197
157
public function getOrderDetail ($ order )
198
158
{
199
159
// if the admin site has a custom URL, use it
@@ -479,24 +439,26 @@ protected function formatCustomer($order)
479
439
480
440
protected function formatAddress ($ address )
481
441
{
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
+ }
500
462
501
463
return $ addressData ;
502
464
}
@@ -505,44 +467,52 @@ public function getShipments($order)
505
467
{
506
468
$ shipments = array ();
507
469
$ orderStatus = $ order ->getStatus ();
470
+ $ serviceCode = $ order ->getShippingDescription ();
471
+ $ tracks = $ order ->getTracksCollection ();
472
+ $ shippingMethod = $ order ->getShippingMethod ();
473
+ $ orderShippingAddress = $ order ->getShippingAddress ();
508
474
509
475
foreach ($ order ->getShipmentsCollection () as $ shipment ) {
510
476
$ shipmentId = $ shipment ->getEntityId ();
511
477
$ 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 );
532
507
}
508
+ $ shipments [] = $ shipment ;
533
509
}
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
- );
541
510
}
542
- } else {
543
- $ shippingAddress = $ order ->getShippingAddress ();
511
+ }
512
+
513
+ if (empty ($ shipments ) && $ orderShippingAddress ) {
544
514
$ shipments [] = array (
545
- 'shipping_address ' => $ this ->formatAddress ($ shippingAddress ),
515
+ 'shipping_address ' => $ this ->formatAddress ($ orderShippingAddress ),
546
516
);
547
517
}
548
518
@@ -558,22 +528,22 @@ public function getOrderDetailBasic($order)
558
528
$ shippingAddress = $ order ->getShippingAddress ();
559
529
$ shippingWithTax = $ order ->getShippingInclTax ();
560
530
$ shippingMethod = $ order ->getShippingMethod ();
531
+ $ billingAddress = $ order ->getBillingAddress ();
561
532
562
533
$ orderInfo = array (
563
534
'id ' => $ order ->getIncrementId (),
564
535
'url ' => $ urlModel ->getUrl ('adminhtml/sales_order/view ' , array ('order_id ' => $ order ->getId ())),
565
536
'transaction_id ' => $ order ->getIncrementId (),
566
537
'status ' => $ order ->getStatus (),
567
- 'billing_address ' => $ this ->formatAddress ($ order ->getBillingAddress ()),
568
538
'meta ' => array (
569
539
'store_info ' => array (
570
540
'type ' => 'store_info ' ,
571
541
'name ' => $ order ->getStoreName ()
572
542
),
573
543
'display_price ' => array (
574
544
'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 )
577
547
),
578
548
'timestamps ' => array (
579
549
'created_at ' => $ order ->getCreatedAt (),
@@ -590,9 +560,12 @@ public function getOrderDetailBasic($order)
590
560
),
591
561
'shipments ' => array (),
592
562
);
563
+ if ($ billingAddress ) {
564
+ $ orderInfo ['billing_address ' ] = $ this ->formatAddress ($ billingAddress );
565
+ }
593
566
594
567
foreach ($ order ->getItemsCollection (array (), true ) as $ item ) {
595
- $ itemWithTax = $ item ->getRowTotal ();
568
+ $ itemWithoutTax = $ item ->getRowTotal ();
596
569
$ itemTax = $ item ->getTaxAmount ();
597
570
598
571
$ productId = $ item ->getProductId ();
@@ -610,8 +583,8 @@ public function getOrderDetailBasic($order)
610
583
'refunded ' => intval ($ item ->getQtyRefunded ()),
611
584
'meta ' => array (
612
585
'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 ),
615
588
'tax ' => $ this ->formatPrice ($ iitemTax , $ currency )
616
589
),
617
590
'timestamps ' => array (
@@ -772,7 +745,9 @@ public function getCustomer($customer)
772
745
);
773
746
774
747
foreach ($ customer ->getAddressesCollection () as $ address ) {
775
- $ info ['addresses ' ][] = $ this ->formatAddress ($ address );
748
+ if ($ address ) {
749
+ $ info ['addresses ' ][] = $ this ->formatAddress ($ address );
750
+ }
776
751
}
777
752
778
753
return $ info ;
@@ -825,7 +800,7 @@ public function getFilteredOrdersByProduct($customerFilters, $productFilters)
825
800
);
826
801
}
827
802
828
- if ($ email ) {
803
+ if ($ email ) {
829
804
$ filteredOrdersData = array_filter (array_values ($ ordersData ), function ($ orderData ) use ($ email ) {
830
805
return ($ orderData ['email ' ] == $ email );
831
806
});
0 commit comments