Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
* pickup points support
* method to engineer the housenumber from a full address
  • Loading branch information
bakkerpeter committed Mar 8, 2016
1 parent ebd4244 commit 20fc5d7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
51 changes: 35 additions & 16 deletions src/models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,70 @@ class Address extends Model {
* @var string
*/
public $firstName;

/**
* Customer last name
* @var string
*/
public $lastName;

/**
* Postal code
* @var string
*/
public $postalCode;

/**
* The street
* @var string
*/
public $street;

/**
* The house number
* @var string
*/
public $houseNumber;

/**
* The house number addition
* @var string
*/
public $houseNumberAddition;

/**
* Cityname
* @var string
*/
public $cityName;

/**
* Country ISO
* @var string
*/
public $countryIso;


/**
* Funky code to get the housenumber and addition out of a street
* The mashape API (used for DHL pickup points) only returns address data
* @param type $street
* @return Address
*/
public static function getAddressFromStreet($street) {
$address = new Address();
$pattern = '#^([a-z0-9 [:punct:]\']*) ([0-9]{1,5})([a-z0-9 \-/]{0,})$#i';
preg_match($pattern, str_replace(' - ', '-', $street), $aMatch);
$address->street = $aMatch[1];
$address->houseNumber = preg_replace("/[^A-Za-z0-9 ]/", '', $aMatch[2]);

if (isset($aMatch[3])) {
$address->houseNumberAddition = preg_replace("/[^A-Za-z0-9 ]/", '', $aMatch[3]);
}

return $address;
}

/**
* Set the country code based on the available settings
* @param type $code
Expand All @@ -67,7 +88,7 @@ public function setCountry($code) {
}
throw new ApiException('Invalid country code');
}

/**
* Set the customer name
* @param string $lastName
Expand All @@ -79,7 +100,7 @@ public function setName($lastName, $firstName = null) {
$this->lastName = $lastName;
return $this;
}

/**
* Set the address information
* @param string $street
Expand All @@ -93,7 +114,7 @@ public function setAddress($street, $number, $addition = null) {
$this->houseNumberAddition = $addition;
return $this;
}

/**
* Set the postalcode information
* @param string $postalCode
Expand All @@ -103,7 +124,7 @@ public function setPostalcode($postalCode) {
$this->postalCode = $postalCode;
return $this;
}

/**
* Set the city
* @param string $city
Expand All @@ -113,7 +134,7 @@ public function setCity($city) {
$this->cityName = $city;
return $this;
}

/**
* Return the flattend data
* @param string $type
Expand All @@ -122,12 +143,10 @@ public function setCity($city) {
public function getAddress($type) {
$address = array();
foreach (array_keys(get_class_vars(__CLASS__)) as $key) {
$u = ucwords(substr($key, 0,1)) . substr($key, 1);
$u = ucwords(substr($key, 0, 1)) . substr($key, 1);
$address[$type . $u] = $this->$key;
}
return $address;
}



}
28 changes: 25 additions & 3 deletions src/models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Order extends Model {
* @var string
*/
public $ExternalOrderNumber;

/**
* The active ants order number
* @var integer
Expand Down Expand Up @@ -82,6 +82,12 @@ class Order extends Model {
*/
private $shippingAddress;

/**
* The pickup point data
* @var string
*/
public $PickUpPointPostalCode, $PickUpPointHouseNumber, $PickUpPointAddition, $PickUpPointId;

/**
* Billing data
* @var string
Expand Down Expand Up @@ -176,6 +182,23 @@ public function setPreferredShippingDate(\DateTime $date = null) {
return $this;
}

/**
* Add pickup point information
* @param string $pointId
* @param string $postalCode
* @param integer $houseNumber
* @param string $houseNumberAddition
*/
public function setPickupPoint($pointId, $postalCode, $street) {
$this->PickUpPointId = $pointId;
$this->PickUpPointPostalCode = $postalCode;

//Get the address data based on the street data
$address = Address::getAddressFromStreet($street);
$this->PickUpPointHouseNumber = $address->houseNumber;
$this->PickUpPointAddition = $address->houseNumberAddition;
}

/**
* Add an item to the order
* @param \Afosto\ActiveAnts\OrderItem $item
Expand Down Expand Up @@ -265,8 +288,7 @@ public function save() {
$this->setAttributes($this->shippingAddress->getAddress('DeliveryAddress'));
return parent::save();
}



/**
* Return all data from api
* @param string $attributes
Expand Down

0 comments on commit 20fc5d7

Please sign in to comment.