Sendcloud ParcelCreation added additional rules for DPD

This commit is contained in:
OpenXE 2024-03-20 10:06:09 +00:00
parent 56cfc54aa5
commit 8c1f434833

View File

@ -12,19 +12,29 @@ class ParcelCreation extends ParcelBase
{
public ?int $SenderAddressId = null;
// const DEFAUlT_LENGTH = 150;
public function toApiRequest(): array
{
define("DEFAULT_LENGTH", 150);
// DPD-special condition, to be checked in detail
$address_2 = substr($this->Adress2, 0, 35);
$company_name = substr($this->CompanyName, 0, 35);
$length = strlen($address_2)+strlen($company_name);
if ($length > 34) {
$company_name_length = 34-strlen($address_2);
if ($company_name_length < 0) {
$company_name_lenght = 0;
}
$company_name = substr($company_name, 0, $company_name_length);
}
$data = [
'name' => substr($this->Name, 0, 75),
'company_name' => substr($this->CompanyName, 0, 50),
'address' => substr($this->Address, 0, 75),
'address_2' => substr($this->Address2, 0, 75),
'house_number' => substr($this->HouseNumber, 0, 20),
'name' => substr($this->Name, 0, 35),
'company_name' => $company_name,
'address' => substr($this->Address, 0, 35),
'address_2' => $address_2,
'house_number' => substr($this->HouseNumber, 0, 8),
'city' => substr($this->City, 0, 30),
'postal_code' => substr($this->PostalCode, 0, 12),
'telephone' => substr($this->Telephone, 0, 20),
@ -52,7 +62,8 @@ class ParcelCreation extends ParcelBase
if ($this->CustomsShipmentType !== null) {
$data['customs_shipment_type'] = substr($this->CustomsShipmentType, 0, DEFAULT_LENGTH);
}
return $data;
}
}