Skip to content

Commit

Permalink
Merge pull request #403 from myparcelnl/Fix-long-street-address
Browse files Browse the repository at this point in the history
support long street > 40
  • Loading branch information
RichardPerdaan authored Apr 25, 2018
2 parents a185a1b + 7039b66 commit e11d0b5
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions app/code/community/TIG/MyParcel2014/Model/Api/MyParcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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));
}
}

0 comments on commit e11d0b5

Please sign in to comment.