Skip to content

Commit b31ce2e

Browse files
committed
chore: add address only if they exist
1 parent 307a58e commit b31ce2e

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

src/app/code/community/Zendesk/Zendesk/Helper/Data.php

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

src/app/code/community/Zendesk/Zendesk/controllers/ApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function preDispatch() {
2323
// TODO!!!!!!!: read version from config.xml
2424
// $configSettings = Mage::getSingleton('Zendesk_Zendesk/config');
2525
// Mage::log(json_encode($configSettings), null, 'zendesk.log');
26-
$this->getResponse()->setHeader('X-Extension-Version', '3.0.0');
26+
$this->getResponse()->setHeader('X-Extension-Version', '3.0.1');
2727
return $this;
2828
}
2929

src/app/code/community/Zendesk/Zendesk/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<config>
2020
<modules>
2121
<Zendesk_Zendesk>
22-
<version>3.0.0</version>
22+
<version>3.0.1</version>
2323
</Zendesk_Zendesk>
2424
</modules>
2525
<zendesk>

src/app/design/adminhtml/default/default/template/zendesk/left-menu.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@
5555
</ul>
5656
<div>
5757
<br/>
58-
<p>Extension Version: 3.0.0</p>
58+
<p>Extension Version: 3.0.1</p>
5959
</div>
6060

0 commit comments

Comments
 (0)