diff --git a/src/Model/Query/Bpost/ServicePointQuery.php b/src/Model/Query/Bpost/ServicePointQuery.php
index c71ba36..ba0a176 100644
--- a/src/Model/Query/Bpost/ServicePointQuery.php
+++ b/src/Model/Query/Bpost/ServicePointQuery.php
@@ -14,7 +14,7 @@ final class ServicePointQuery implements ServicePointQueryInterface, CountryAwar
private string $language;
- private string $street;
+ private ?string $street;
private string $number;
@@ -45,6 +45,7 @@ public function __construct(string $partner)
$this->checkList = 1;
$this->info = 1;
$this->limit = 20;
+ $this->street = null;
$this->partner = $partner;
}
@@ -88,7 +89,7 @@ public function setLanguage(string $language): void
$this->language = $language;
}
- public function getStreet(): string
+ public function getStreet(): ?string
{
return $this->street;
}
diff --git a/src/Provider/PostNLProvider.php b/src/Provider/PostNLProvider.php
index 85c0f49..c0b8120 100644
--- a/src/Provider/PostNLProvider.php
+++ b/src/Provider/PostNLProvider.php
@@ -14,6 +14,7 @@
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Model\OrderInterface;
use Webmozart\Assert\Assert;
+use Sylius\Component\Core\Model\Address;
/**
* @see https://developer.postnl.nl/browse-apis/delivery-options/location-webservice/testtool-rest/#/default/get_v2_1_locations_nearest
@@ -26,7 +27,7 @@ final class PostNLProvider extends Provider
private ClientInterface $client;
private PickupPointTransformerInterface $pickupPointTransformer;
private ManagerRegistry $managerRegistry;
- private ?ServicePointQueryFactory $servicePointQueryFactory;
+ private ?ServicePointQueryFactoryInterface $servicePointQueryFactory;
private array $countryCodes;
private string $addressClassString;
@@ -35,8 +36,8 @@ public function __construct(
ClientInterface $client,
PickupPointTransformerInterface $pickupPointTransformer,
ManagerRegistry $managerRegistry,
- string $addressClassString,
?ServicePointQueryFactoryInterface $servicePointQueryFactory = null,
+ string $addressClassString = Address::class,
array $countryCodes = ['BE', 'NL']
) {
$this->client = $client;
@@ -90,6 +91,7 @@ public function findAllPickupPoints(): iterable
/** @var EntityRepository $repository */
$repository = $manager->getRepository($this->addressClassString);
try {
+ $alreadyScannedPoints = [];
foreach ($this->countryCodes as $countryCode) {
$qb = $repository->createQueryBuilder('sa');
$postalCodes = $qb->distinct()->select('sa.postcode')
@@ -106,7 +108,14 @@ public function findAllPickupPoints(): iterable
->createServicePointQueryForAllPickupPoints($countryCode, $postalCode);
$servicePoints = $this->client->locate($servicePointQuery);
foreach ($servicePoints as $item) {
- yield $this->transform($item);
+ $pickupPoint = $this->transform($item);
+ $code = $pickupPoint->getCode();
+ if ($code === null || in_array($code->getValue(), $alreadyScannedPoints, true)) {
+ continue;
+ }
+ // Prevent the same adjacent pickup points from being added multiple times
+ $alreadyScannedPoints[] = $code->getValue();
+ yield $pickupPoint;
}
}
}
diff --git a/src/Resources/config/services/providers/postnl.xml b/src/Resources/config/services/providers/postnl.xml
index 485ca30..8683c9f 100644
--- a/src/Resources/config/services/providers/postnl.xml
+++ b/src/Resources/config/services/providers/postnl.xml
@@ -9,7 +9,6 @@
- %setono_postnl.address_class%