From 921fc1eeadc56c9058cfc14c4b3e9c09c26b154e Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Mon, 27 Feb 2017 12:06:02 +0100 Subject: [PATCH 1/4] Update LocationClient.php Added getLocationsInArea method --- src/LocationClient.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/LocationClient.php b/src/LocationClient.php index 80069a9..96aaeac 100644 --- a/src/LocationClient.php +++ b/src/LocationClient.php @@ -58,4 +58,13 @@ public function getLocation(ComplexTypes\GetLocationRequest $getLocations) { return $this->__soapCall('GetLocation', [$getLocations]); } + + /** + * @param ComplexTypes\GetNearestLocationsRequest $getLocationsInArea + * @return ComplexTypes\GetLocationsResult + */ + public function getLocationsInArea(ComplexTypes\GetLocationsInAreaRequest $getLocationsInArea) + { + return $this->__soapCall('GetLocationsInArea', [$getLocationsInArea]); + } } From 1f32d025bc5d683524465c1a19cdfbe263267171 Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Mon, 27 Feb 2017 12:07:38 +0100 Subject: [PATCH 2/4] Update Postnl.php --- src/Postnl.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Postnl.php b/src/Postnl.php index 27c08a9..b3f76cf 100644 --- a/src/Postnl.php +++ b/src/Postnl.php @@ -417,6 +417,35 @@ public function getNearestLocation( $request = new ComplexTypes\GetNearestLocationsRequest($message, $location, $countryCode); return $this->call('LocationClient', __FUNCTION__, $request); } + + /** + * @param ComplexTypes\Coordinate $coordinatesNorthWest + * @param ComplexTypes\Coordinate $coordinatesSouthEast + * @param string $allowSundaySorting + * @param null|string $deliveryDate + * @param array $deliveryOptions + * @param array $options + * @param string $countryCode + * @return ComplexTypes\GetNearestLocationsResponse + */ + public function getLocationsInArea( + $coordinatesNorthWest, + $coordinatesSouthEast, + $allowSundaySorting = 'false', + $deliveryDate = null, + $deliveryOptions = null, + $options = ['Daytime'], + $countryCode = 'NL' + ) { + $message = new ComplexTypes\Message; + $locationArea = new ComplexTypes\LocationArea($allowSundaySorting, $deliveryDate, $deliveryOptions, $options); + $locationArea + ->setCoordinatesNorthWest($coordinatesNorthWest) + ->setCoordinatesSouthEast($coordinatesSouthEast); + + $request = new ComplexTypes\GetLocationsInAreaRequest($countryCode, $locationArea, $message); + return $this->call('LocationClient', __FUNCTION__, $request); + } /** * @param string $postalCode From f17c15ca2ed822635dc2d54bbf65f3f18a0a73d1 Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Tue, 28 Feb 2017 11:40:31 +0100 Subject: [PATCH 3/4] Type hints Use type hints for parameters $coordinatesNorthWest and $coordinatesSouthEast in function getLocationsInArea() --- src/Postnl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Postnl.php b/src/Postnl.php index b3f76cf..ec75241 100644 --- a/src/Postnl.php +++ b/src/Postnl.php @@ -429,8 +429,8 @@ public function getNearestLocation( * @return ComplexTypes\GetNearestLocationsResponse */ public function getLocationsInArea( - $coordinatesNorthWest, - $coordinatesSouthEast, + ComplexTypes\Coordinate $coordinatesNorthWest, + ComplexTypes\Coordinate $coordinatesSouthEast, $allowSundaySorting = 'false', $deliveryDate = null, $deliveryOptions = null, From 6eb32dae1c0576d4c18f99df38aa93f438fd22d0 Mon Sep 17 00:00:00 2001 From: Bert Brunekreeft Date: Tue, 28 Feb 2017 11:50:24 +0100 Subject: [PATCH 4/4] Use factory with method chaining Use ComplexTypes\LocationArea::create() with method chaining in function getLocationsInArea. Give default value to $deliveryDate if deliverydate is null --- src/Postnl.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Postnl.php b/src/Postnl.php index ec75241..e72f57e 100644 --- a/src/Postnl.php +++ b/src/Postnl.php @@ -438,10 +438,15 @@ public function getLocationsInArea( $countryCode = 'NL' ) { $message = new ComplexTypes\Message; - $locationArea = new ComplexTypes\LocationArea($allowSundaySorting, $deliveryDate, $deliveryOptions, $options); - $locationArea - ->setCoordinatesNorthWest($coordinatesNorthWest) - ->setCoordinatesSouthEast($coordinatesSouthEast); + + $deliveryDate = $deliveryDate ?: (new \DateTime('next monday'))->format('d-m-Y'); + $locationArea = ComplexTypes\LocationArea::create() + ->setAllowSundaySorting($allowSundaySorting) + ->setDeliveryDate($deliveryDate) + ->setDeliveryOptions($deliveryOptions) + ->setOptions($options) + ->setCoordinatesNorthWest($coordinatesNorthWest) + ->setCoordinatesSouthEast($coordinatesSouthEast); $request = new ComplexTypes\GetLocationsInAreaRequest($countryCode, $locationArea, $message); return $this->call('LocationClient', __FUNCTION__, $request);