Skip to content

Commit f1c9bab

Browse files
improvements + bugfixes
1 parent d7d162e commit f1c9bab

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/Model/Query/Bpost/ServicePointQuery.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class ServicePointQuery implements ServicePointQueryInterface, CountryAwar
1414

1515
private string $language;
1616

17-
private string $street;
17+
private ?string $street;
1818

1919
private string $number;
2020

@@ -45,6 +45,7 @@ public function __construct(string $partner)
4545
$this->checkList = 1;
4646
$this->info = 1;
4747
$this->limit = 20;
48+
$this->street = null;
4849

4950
$this->partner = $partner;
5051
}
@@ -88,7 +89,7 @@ public function setLanguage(string $language): void
8889
$this->language = $language;
8990
}
9091

91-
public function getStreet(): string
92+
public function getStreet(): ?string
9293
{
9394
return $this->street;
9495
}

src/Provider/PostNLProvider.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
1515
use Sylius\Component\Core\Model\OrderInterface;
1616
use Webmozart\Assert\Assert;
17+
use Sylius\Component\Core\Model\Address;
1718

1819
/**
1920
* @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
2627
private ClientInterface $client;
2728
private PickupPointTransformerInterface $pickupPointTransformer;
2829
private ManagerRegistry $managerRegistry;
29-
private ?ServicePointQueryFactory $servicePointQueryFactory;
30+
private ?ServicePointQueryFactoryInterface $servicePointQueryFactory;
3031

3132
private array $countryCodes;
3233
private string $addressClassString;
@@ -35,8 +36,8 @@ public function __construct(
3536
ClientInterface $client,
3637
PickupPointTransformerInterface $pickupPointTransformer,
3738
ManagerRegistry $managerRegistry,
38-
string $addressClassString,
3939
?ServicePointQueryFactoryInterface $servicePointQueryFactory = null,
40+
string $addressClassString = Address::class,
4041
array $countryCodes = ['BE', 'NL']
4142
) {
4243
$this->client = $client;
@@ -90,6 +91,7 @@ public function findAllPickupPoints(): iterable
9091
/** @var EntityRepository $repository */
9192
$repository = $manager->getRepository($this->addressClassString);
9293
try {
94+
$alreadyScannedPoints = [];
9395
foreach ($this->countryCodes as $countryCode) {
9496
$qb = $repository->createQueryBuilder('sa');
9597
$postalCodes = $qb->distinct()->select('sa.postcode')
@@ -106,7 +108,14 @@ public function findAllPickupPoints(): iterable
106108
->createServicePointQueryForAllPickupPoints($countryCode, $postalCode);
107109
$servicePoints = $this->client->locate($servicePointQuery);
108110
foreach ($servicePoints as $item) {
109-
yield $this->transform($item);
111+
$pickupPoint = $this->transform($item);
112+
$code = $pickupPoint->getCode();
113+
if ($code === null || in_array($code, $alreadyScannedPoints, true)) {
114+
continue;
115+
}
116+
// Prevent the same adjacent pickup points from being added multiple times
117+
$alreadyScannedPoints[] = $code->getValue();
118+
yield $pickupPoint;
110119
}
111120
}
112121
}

src/Resources/config/services/providers/postnl.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<argument type="service" id="setono_postnl.client"/>
1010
<argument type="service" id="setono_postnl.pickup_point_transformer"/>
1111
<argument type="service" id="doctrine"/>
12-
<argument>%setono_postnl.address_class%</argument>
1312
<tag name="setono_sylius_pickup_point.provider" code="postnl" label="setono_sylius_pickup_point.provider.postnl"/>
1413
</service>
1514
</services>

0 commit comments

Comments
 (0)