Skip to content

Commit

Permalink
improvements + bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kenny-inventis committed Jun 2, 2022
1 parent d7d162e commit 8d421c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Model/Query/Bpost/ServicePointQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class ServicePointQuery implements ServicePointQueryInterface, CountryAwar

private string $language;

private string $street;
private ?string $street;

private string $number;

Expand Down Expand Up @@ -45,6 +45,7 @@ public function __construct(string $partner)
$this->checkList = 1;
$this->info = 1;
$this->limit = 20;
$this->street = null;

$this->partner = $partner;
}
Expand Down Expand Up @@ -88,7 +89,7 @@ public function setLanguage(string $language): void
$this->language = $language;
}

public function getStreet(): string
public function getStreet(): ?string
{
return $this->street;
}
Expand Down
15 changes: 12 additions & 3 deletions src/Provider/PostNLProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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')
Expand All @@ -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;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services/providers/postnl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<argument type="service" id="setono_postnl.client"/>
<argument type="service" id="setono_postnl.pickup_point_transformer"/>
<argument type="service" id="doctrine"/>
<argument>%setono_postnl.address_class%</argument>
<tag name="setono_sylius_pickup_point.provider" code="postnl" label="setono_sylius_pickup_point.provider.postnl"/>
</service>
</services>
Expand Down

0 comments on commit 8d421c2

Please sign in to comment.