diff --git a/src/Response/DTO/ParcelShop.php b/src/Response/DTO/ParcelShop.php index 0c010c9..bc0da9d 100644 --- a/src/Response/DTO/ParcelShop.php +++ b/src/Response/DTO/ParcelShop.php @@ -25,7 +25,7 @@ class ParcelShop * @var Openings[] */ private array $openings = []; - private Coordinates $coordinates; + private ?Coordinates $coordinates; private ?string $holidayStarts; private ?string $holidayEnds; @@ -43,7 +43,7 @@ public function __construct( ?string $info, Address $address, array $openings, - Coordinates $coordinates, + ?Coordinates $coordinates, ?string $holidayStarts, ?string $holidayEnds ) { @@ -70,6 +70,12 @@ public function __construct( */ public static function fromRawParcelShop(RawParcelShop $rawParcelShop, array $openings): self { + $coordinates = null; + + if (null !== $rawParcelShop->geolat && null !== $rawParcelShop->geolng) { + $coordinates = new Coordinates((float) $rawParcelShop->geolat, (float) $rawParcelShop->geolng); + } + return new self( $rawParcelShop->pclshopid, $rawParcelShop->name, @@ -84,7 +90,7 @@ public static function fromRawParcelShop(RawParcelShop $rawParcelShop, array $op $rawParcelShop->info, Address::fromRawParcelShop($rawParcelShop), $openings, - new Coordinates((float) $rawParcelShop->geolat, (float) $rawParcelShop->geolng), + $coordinates, $rawParcelShop->holidaystarts, $rawParcelShop->holidayends ); @@ -158,7 +164,7 @@ public function getOpenings(): array return $this->openings; } - public function getCoordinates(): Coordinates + public function getCoordinates(): ?Coordinates { return $this->coordinates; } diff --git a/src/Response/DTO/RawParcelShop.php b/src/Response/DTO/RawParcelShop.php index bbe372a..fcca0eb 100644 --- a/src/Response/DTO/RawParcelShop.php +++ b/src/Response/DTO/RawParcelShop.php @@ -18,8 +18,8 @@ class RawParcelShop public ?string $iscodhandler; public ?string $paybybankcard; public ?string $dropoffpoint; - public string $geolat; - public string $geolng; + public ?string $geolat; + public ?string $geolng; public string $owner; public ?string $isparcellocker; public ?string $vendor_url; diff --git a/src/Service/ParcelShopsService.php b/src/Service/ParcelShopsService.php index 76f90e4..35e1799 100644 --- a/src/Service/ParcelShopsService.php +++ b/src/Service/ParcelShopsService.php @@ -49,7 +49,11 @@ public function getParcelShopCollection( $parcelShopCollection = []; foreach ($rawParcelShopCollection as $rawParcelShop) { - $openings = $this->getOpenings($rawParcelShop->pclshopid); + try { + $openings = $this->getOpenings($rawParcelShop->pclshopid); + } catch (\Throwable $throwable) { + $openings = []; + } $parcelShop = ParcelShop::fromRawParcelShop($rawParcelShop, $openings); $parcelShopCollection[] = $parcelShop; diff --git a/tests/Integration/Service/ParcelShopsTest.php b/tests/Integration/Service/ParcelShopsTest.php index 4a0b446..a947385 100644 --- a/tests/Integration/Service/ParcelShopsTest.php +++ b/tests/Integration/Service/ParcelShopsTest.php @@ -113,7 +113,7 @@ private function assertOfficeSame(array $parcelShops): void 'email' => $address->getEmail(), ], 'openings' => $actualOpenings, - 'coordinates' => [ + 'coordinates' => null === $parcelShop->getCoordinates() ? null : [ 'latitude' => $parcelShop->getCoordinates()->latitude, 'longitude' => $parcelShop->getCoordinates()->longitude, ], @@ -134,6 +134,7 @@ private function getLogger(array $parcelShops = []): LoggerInterface '[GLS_BUNDLE] Request - /psmap/psmap_getdata.php?action=getList&ctrcode=SI&pclshopin=1&parcellockin=1', '[GLS_BUNDLE] Response - /psmap/psmap_getdata.php?action=getList&ctrcode=SI&pclshopin=1&parcellockin=1', ]; + foreach ($parcelShops as $parcelShop) { $expected[] = '[GLS_BUNDLE] Request - /psmap/psmap_getdata.php?action=getOpenings&pclshopid=' . $parcelShop['pclshopid']; $expected[] = '[GLS_BUNDLE] Response - /psmap/psmap_getdata.php?action=getOpenings&pclshopid=' . $parcelShop['pclshopid']; diff --git a/tests/Integration/Service/data/parcelShops.json b/tests/Integration/Service/data/parcelShops.json index e98fec5..0fe067b 100644 --- a/tests/Integration/Service/data/parcelShops.json +++ b/tests/Integration/Service/data/parcelShops.json @@ -464,17 +464,37 @@ "name": "OMV SLOVENIJA D.O.O.", "ctrcode": "SI", "zipcode": "6000", - "city": "KOPER", "address": "Istrska cesta 53", "contact": null, "phone": null, "email": null, - "iscodhandler": "t", "paybybankcard": "t", "dropoffpoint": "t", - + "geolat": "45.539", + "geolng": "13.7287", + "owner": "GLS", + "isparcellocker": "f", + "vendor_url": null, + "pcl_pickup_time": null, + "info": null, + "holidaystarts": null, + "holidayends": null + }, + { + "pclshopid": "6000-OMV01", + "name": "OMV SLOVENIJA D.O.O.", + "ctrcode": "SI", + "zipcode": "6000", + "city": "KOPER", + "address": "Istrska cesta 53", + "contact": null, + "phone": null, + "email": null, + "iscodhandler": "t", + "paybybankcard": "t", + "dropoffpoint": "t", "geolat": "45.539", "geolng": "13.7287", "owner": "GLS", @@ -493,17 +513,17 @@ "city": "LJUBLJANA", "address": "Litijska cesta 40", "contact": null, - "phone": "01\/520-81-20", - "email": "Station.Ljubljana.Litijska@omv.com", + "phone": null, + "email": null, "iscodhandler": null, "paybybankcard": null, "dropoffpoint": null, - "geolat": "46.0473", - "geolng": "14.5463", + "geolat": null, + "geolng": null, "owner": "GLS", "isparcellocker": null, "vendor_url": null, - "pcl_pickup_time": "10:00", + "pcl_pickup_time": null, "info": null, "holidaystarts": null, "holidayends": null diff --git a/tests/Integration/Service/data/parcelShops_expected_parcels.json b/tests/Integration/Service/data/parcelShops_expected_parcels.json index d82004c..de7c896 100644 --- a/tests/Integration/Service/data/parcelShops_expected_parcels.json +++ b/tests/Integration/Service/data/parcelShops_expected_parcels.json @@ -1343,6 +1343,70 @@ "holidayStarts": null, "holidayEnds": null }, + { + "shopId": "6000-OMV01", + "name": "OMV SLOVENIJA D.O.O.", + "countryCode": "SI", + "isCodHandler": true, + "payByBankCard": true, + "dropOffPoint": true, + "owner": "GLS", + "isParcelLocker": false, + "vendorUrl": null, + "pickupTime": null, + "info": null, + "address": { + "zipCode": "6000", + "city": "KOPER", + "place": "Istrska cesta 53", + "contact": null, + "phone": null, + "email": null + }, + "openings": [ + { + "day": "monday", + "open": "00:00-24:00", + "midbreak": "" + }, + { + "day": "tuesday", + "open": "00:00-24:00", + "midbreak": "" + }, + { + "day": "wednesday", + "open": "00:00-24:00", + "midbreak": "" + }, + { + "day": "thursday", + "open": "00:00-24:00", + "midbreak": "" + }, + { + "day": "friday", + "open": "00:00-24:00", + "midbreak": "" + }, + { + "day": "saturday", + "open": "00:00-24:00", + "midbreak": "" + }, + { + "day": "sunday", + "open": "00:00-24:00", + "midbreak": "" + } + ], + "coordinates": { + "latitude": 45.539, + "longitude": 13.7287 + }, + "holidayStarts": null, + "holidayEnds": null + }, { "shopId": "1000-OMV04", "name": "PS OMV LJUBLJANA LITIJSKA", @@ -1353,15 +1417,15 @@ "owner": "GLS", "isParcelLocker": false, "vendorUrl": null, - "pickupTime": "10:00", + "pickupTime": null, "info": null, "address": { "zipCode": "1000", "city": "LJUBLJANA", "place": "Litijska cesta 40", "contact": null, - "phone": "01\/520-81-20", - "email": "Station.Ljubljana.Litijska@omv.com" + "phone": null, + "email": null }, "openings": [ { @@ -1400,10 +1464,7 @@ "midbreak": "" } ], - "coordinates": { - "latitude": 46.0473, - "longitude": 14.5463 - }, + "coordinates": null, "holidayStarts": null, "holidayEnds": null }