Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/MyParcelComApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function getPickUpDropOffLocations(
CarrierInterface $specificCarrier = null,
bool $onlyActiveContracts = true,
int $ttl = self::TTL_10MIN,
?array $filters = null,
): ResourceCollectionInterface|array {
$carriers = $this->determineCarriersForPudoLocations($onlyActiveContracts, $specificCarrier);

Expand All @@ -176,6 +177,9 @@ public function getPickUpDropOffLocations(
if ($streetNumber) {
$uri->addQuery(['street_number' => $streetNumber]);
}
if ($filters) {
$uri->addQuery($this->arrayToFilters($filters));
}

$pudoLocations = [];

Expand Down
1 change: 1 addition & 0 deletions src/MyParcelComApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function getPickUpDropOffLocations(
CarrierInterface $specificCarrier = null,
bool $onlyActiveContracts = true,
int $ttl = self::TTL_10MIN,
?array $filters = null,
): ResourceCollectionInterface|array;

/**
Expand Down
14 changes: 14 additions & 0 deletions src/Resources/PickUpDropOffLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PickUpDropOffLocation implements PickUpDropOffLocationInterface
const ATTRIBUTE_OPENING_HOURS = 'openingHours';
const ATTRIBUTE_POSITION = 'position';
const ATTRIBUTE_CATEGORIES = 'categories';
const ATTRIBUTE_LOCATION_TYPE = 'location_type';

const RELATIONSHIP_CARRIER = 'carrier';

Expand All @@ -38,6 +39,7 @@ class PickUpDropOffLocation implements PickUpDropOffLocationInterface
self::ATTRIBUTE_ADDRESS => null,
self::ATTRIBUTE_OPENING_HOURS => [],
self::ATTRIBUTE_POSITION => null,
self::ATTRIBUTE_LOCATION_TYPE => null,
self::ATTRIBUTE_CATEGORIES => [],
];

Expand Down Expand Up @@ -149,4 +151,16 @@ public function getCategories(): array
{
return $this->attributes[self::ATTRIBUTE_CATEGORIES];
}

public function setLocationType(string $type): self
{
$this->attributes[self::ATTRIBUTE_LOCATION_TYPE] = $type;

return $this;
}

public function getLocationType(): string
{
return $this->attributes[self::ATTRIBUTE_LOCATION_TYPE];
}
}
26 changes: 26 additions & 0 deletions tests/Feature/MyParcelComApi/PickUpDropOffLocationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,30 @@ public function testGetPudoLocationsForSpecificCarrierWhichDoesntHaveActiveContr
// The other carrier does not have any pudo services and should thus not return pudo locations.
$this->assertEmpty($pudoLocations);
}

public function testGetPudoLocationsWithLocationTypesFilter()
{
$carrier = $this->createMock(CarrierInterface::class);
$carrier
->method('getId')
->willReturn('eef00b32-177e-43d3-9b26-715365e4ce46');

$pudoLocations = $this->api->getPickUpDropOffLocations(
'GB',
'B48 7QN',
null,
null,
$carrier,
false,
filters: ['location_type' => ['office']],
);

// The carrier with pudo locations should return a set of pudo locations.
$this->assertCount(10, $pudoLocations);

/** @var \MyParcelCom\ApiSdk\Resources\PickUpDropOffLocation $pudoLocation */
foreach ($pudoLocations as $pudoLocation) {
$this->assertEquals('office', $pudoLocation->getLocationType());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"position": {
"latitude": 52.3032936742545,
"longitude": 4.69476214016944
}
},
"location_type": "office"
},
"meta": {
"distance": 318
Expand Down Expand Up @@ -125,7 +126,8 @@
"position": {
"latitude": 52.3089878674629,
"longitude": 4.68188672729443
}
},
"location_type": "locker"
},
"meta": {
"distance": 764
Expand Down Expand Up @@ -197,7 +199,8 @@
"position": {
"latitude": 52.3143764678125,
"longitude": 4.69640792135398
}
},
"location_type": "office"
},
"meta": {
"distance": 1137
Expand Down Expand Up @@ -269,7 +272,8 @@
"position": {
"latitude": 52.3155020752417,
"longitude": 4.69523182366827
}
},
"location_type": "office"
},
"meta": {
"distance": 1233
Expand Down Expand Up @@ -340,7 +344,8 @@
"position": {
"latitude": 52.3094281618872,
"longitude": 4.67139513180198
}
},
"location_type": "office"
},
"meta": {
"distance": 1413
Expand Down Expand Up @@ -411,7 +416,8 @@
"position": {
"latitude": 52.3013913423774,
"longitude": 4.66375416731004
}
},
"location_type": "office"
},
"meta": {
"distance": 1872
Expand Down Expand Up @@ -482,7 +488,8 @@
"position": {
"latitude": 52.2864669620795,
"longitude": 4.68239055845954
}
},
"location_type": "office"
},
"meta": {
"distance": 2110
Expand Down Expand Up @@ -553,7 +560,8 @@
"position": {
"latitude": 52.3147095499762,
"longitude": 4.65903497807609
}
},
"location_type": "office"
},
"meta": {
"distance": 2422
Expand Down Expand Up @@ -624,7 +632,8 @@
"position": {
"latitude": 52.3066891744711,
"longitude": 4.63838904899413
}
},
"location_type": "office"
},
"meta": {
"distance": 3565
Expand Down Expand Up @@ -695,7 +704,8 @@
"position": {
"latitude": 52.3569768014508,
"longitude": 5.15416255988611
}
},
"location_type": "office"
},
"meta": {
"distance": 32019
Expand Down
Loading