From 7039b666d0f78b920405ea949f3b3820c164a7a7 Mon Sep 17 00:00:00 2001 From: Richard Perdaan Date: Wed, 25 Apr 2018 10:27:56 +0200 Subject: [PATCH] support long street > 40 --- .../TIG/MyParcel2014/Model/Api/MyParcel.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/code/community/TIG/MyParcel2014/Model/Api/MyParcel.php b/app/code/community/TIG/MyParcel2014/Model/Api/MyParcel.php index b1278557..fc33ea63 100755 --- a/app/code/community/TIG/MyParcel2014/Model/Api/MyParcel.php +++ b/app/code/community/TIG/MyParcel2014/Model/Api/MyParcel.php @@ -73,6 +73,7 @@ class TIG_MyParcel2014_Model_Api_MyParcel extends Varien_Object * Shipment v2 endpoint active from x number of orders */ const SHIPMENT_V2_ACTIVE_FROM = 25; + const MAX_STREET_LENGTH = 40; /** * @var string @@ -708,8 +709,11 @@ protected function _getConsignmentData(TIG_MyParcel2014_Model_Shipment $myParcel if ($phone) $data['recipient']['phone'] = $phone; - unset($streetData['fullStreet']); - $data['recipient']['street'] = trim(str_replace(' ', ' ', implode(' ', $streetData))); + $streetParts = $this->getInternationalStreetParts($streetData); + $data['recipient']['street'] = $streetParts[0]; + if (isset($streetParts[1])) { + $data['recipient']['street_additional_info'] = $streetParts[1]; + } unset($data['recipient']['number']); unset($data['recipient']['number_suffix']); } @@ -1005,4 +1009,22 @@ protected function _getPositions($start) return implode(';',$aPositions); } + + /** + * Wraps a street to max street lenth + * + * @param $streetData + * + * @return array + */ + private function getInternationalStreetParts ($streetData) + { + unset($streetData['fullStreet']); + + // replace double whitespaces + $street = trim( str_replace( ' ', ' ', implode( ' ', $streetData ) ) ); + + // split street in 2 parts + return explode("\n", wordwrap($street, self::MAX_STREET_LENGTH)); + } }