Skip to content

Commit

Permalink
fix: add missing address data for shipments with no validation (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
DPDromania authored Oct 17, 2024
1 parent e44272d commit 8b90540
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Controller/Adminhtml/Orders/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public function _actionAddShipment($data)

$apiAddress = $this->customAjax->DPD_GetAddressNormalizedByOrderID($data['orderID']);


if ($apiAddress && !empty($apiAddress)) {
if ($apiAddress['method'] && $apiAddress['method'] === 'pickup') {
$parameters['data']['recipient']['pickupOfficeId'] = (int) $apiAddress['officeID'];
Expand All @@ -227,6 +228,8 @@ public function _actionAddShipment($data)
} else {
if (isset($apiAddress['addressCityName']) && !empty($apiAddress['addressCityName'])) {
$parameters['data']['recipient']['address']['siteName'] = $this->customAjax->ReplaceDiacritics($apiAddress['addressCityName']);
}else {
$parameters['data']['recipient']['address']['siteName'] = $this->customAjax->ReplaceDiacritics($orderData->getShippingAddress()->getData('city'));
}
}
if ($apiAddress['status'] && !empty($apiAddress['status']) && $apiAddress['status'] == 'skip') {
Expand Down Expand Up @@ -259,6 +262,17 @@ public function _actionAddShipment($data)
$parameters['data']['recipient']['address']['streetNo'] = (int) $data['shipmentValidation']['number'];
}
} else {
$parameters['data']['recipient']['address']['addressLine1'] = $this->customAjax->ReplaceDiacritics($orderData->getShippingAddress()->getData('street'));
$parameters['data']['recipient']['address']['streetName'] = $this->customAjax->ReplaceDiacritics($orderData->getShippingAddress()->getData('street'));

if (strlen($parameters['data']['recipient']['address']['addressLine1']) > 50) {
$parameters['data']['recipient']['address']['addressLine1'] = substr($parameters['data']['recipient']['address']['addressLine1'], 0, 50);
}

if (strlen($parameters['data']['recipient']['address']['streetName']) > 50) {
$parameters['data']['recipient']['address']['streetName'] = substr($parameters['data']['recipient']['address']['streetName'], 0, 50);
}

if (isset($apiAddress['addressStreetID']) && !empty($apiAddress['addressStreetID'])) {
$parameters['data']['recipient']['address']['streetId'] = $apiAddress['addressStreetID'];
} else {
Expand Down Expand Up @@ -326,8 +340,9 @@ public function _actionAddShipment($data)
$parameters['data']['recipient']['address']['postCode'] = trim($orderData->getShippingAddress()->getData('postcode'));
}
}

$requestAddShipment = $this->customAjax->ApiRequest($parameters);

if (!is_array($requestAddShipment) || empty($requestAddShipment) || array_key_exists('error', $requestAddShipment)) {
$response['error'] = true;
$response['msg'] = $requestAddShipment['error'];
Expand All @@ -350,13 +365,16 @@ public function _actionAddShipment($data)
'pickup' => $requestAddShipment['pickupDate'],
'deadline' => $deadline
];

$orderShipmentID = $this->_addShipment($orderShipmentData);

if ($orderShipmentID && !empty($orderShipmentID)) {
$response['error'] = false;
} else {
$response['error'] = true;
}
}

return $response;
}
public function _addShipment($data)
Expand Down

0 comments on commit 8b90540

Please sign in to comment.