Sendcloud bugfix text field lengths

This commit is contained in:
OpenXE 2024-03-19 17:13:30 +00:00
parent 45a75b4298
commit 632f1c1a09

View File

@ -12,28 +12,33 @@ class ParcelCreation extends ParcelBase
{ {
public ?int $SenderAddressId = null; public ?int $SenderAddressId = null;
// const DEFAUlT_LENGTH = 150;
public function toApiRequest(): array public function toApiRequest(): array
{ {
define("DEFAULT_LENGTH", 150);
$data = [ $data = [
'name' => $this->Name, 'name' => substr($this->Name, 0, 75),
'company_name' => $this->CompanyName, 'company_name' => substr($this->CompanyName, 0, 50),
'address' => $this->Address, 'address' => substr($this->Address, 0, 75),
'address_2' => $this->Address2, 'address_2' => substr($this->Address2, 0, 75),
'house_number' => $this->HouseNumber, 'house_number' => substr($this->HouseNumber, 0, 20),
'city' => $this->City, 'city' => substr($this->City, 0, 30),
'postal_code' => $this->PostalCode, 'postal_code' => substr($this->PostalCode, 0, 12),
'telephone' => $this->Telephone, 'telephone' => substr($this->Telephone, 0, 20),
'request_label' => $this->RequestLabel, 'request_label' => $this->RequestLabel,
'email' => $this->EMail, 'email' => substr($this->EMail, 0, DEFAULT_LENGTH),
'country' => $this->Country, 'country' => substr($this->Country, 0, DEFAULT_LENGTH),
'shipment' => ['id' => $this->ShippingMethodId], 'shipment' => ['id' => $this->ShippingMethodId],
'weight' => number_format($this->Weight / 1000, 3, '.', null), 'weight' => number_format($this->Weight / 1000, 3, '.', null),
'order_number' => $this->OrderNumber, 'order_number' => substr($this->OrderNumber, 0, 50),
'total_order_value_currency' => $this->TotalOrderValueCurrency, 'total_order_value_currency' => $this->TotalOrderValueCurrency,
'total_order_value' => number_format($this->TotalOrderValue, 2, '.', null), 'total_order_value' => number_format($this->TotalOrderValue, 2, '.', null),
'country_state' => $this->CountryState, 'country_state' => substr($this->CountryState, 0, DEFAULT_LENGTH),
'sender_address' => $this->SenderAddressId, 'sender_address' => substr($this->SenderAddressId, 0, DEFAULT_LENGTH),
'external_reference' => $this->ExternalReference, 'external_reference' => substr($this->ExternalReference, 0, DEFAULT_LENGTH),
'total_insured_value' => $this->TotalInsuredValue ?? 0, 'total_insured_value' => $this->TotalInsuredValue ?? 0,
'parcel_items' => array_map(fn(ParcelItem $item) => $item->toApiRequest(), $this->ParcelItems), 'parcel_items' => array_map(fn(ParcelItem $item) => $item->toApiRequest(), $this->ParcelItems),
'is_return' => $this->IsReturn, 'is_return' => $this->IsReturn,
@ -41,10 +46,12 @@ class ParcelCreation extends ParcelBase
'width' => $this->Width, 'width' => $this->Width,
'height' => $this->Height, 'height' => $this->Height,
]; ];
if ($this->CustomsInvoiceNr !== null) if ($this->CustomsInvoiceNr !== null) {
$data['customs_invoice_nr'] = $this->CustomsInvoiceNr; $data['customs_invoice_nr'] = substr($this->CustomsInvoiceNr, 0, 40);
if ($this->CustomsShipmentType !== null) }
$data['customs_shipment_type'] = $this->CustomsShipmentType; if ($this->CustomsShipmentType !== null) {
$data['customs_shipment_type'] = substr($this->CustomsShipmentType, 0, DEFAULT_LENGTH);
}
return $data; return $data;
} }