fix: ensure unique services mapping when creating api payload
This commit is contained in:
@@ -145,22 +145,25 @@ class BookingPayloadBuilder
|
||||
public function buildServicesPayload(array &$payload, Booking $bookingData): void
|
||||
{
|
||||
foreach ($bookingData->additionalServices as $service) {
|
||||
$uniqueMapping = array_unique($service->mapping);
|
||||
$payload['zusatzleistungen']['zusatzleistung'][] = [
|
||||
'@idleistung' => $service->id,
|
||||
'@anzahl' => count($service->mapping),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $service->mapping)),
|
||||
'@anzahl' => count($uniqueMapping),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $uniqueMapping)),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($bookingData->transportationServices as $service) {
|
||||
$uniqueMapping = array_unique($service->mapping);
|
||||
$payload['beförderungen']['beförderung'][] = [
|
||||
'@idleistung' => $service->id,
|
||||
'@anzahl' => count($service->mapping),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $service->mapping)),
|
||||
'@anzahl' => count($uniqueMapping),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $uniqueMapping)),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($bookingData->rooms as $room) {
|
||||
$uniqueMapping = array_unique($room->mapping);
|
||||
$payload['ferienzielunterbringungen']['ferienzielunterbringung'][] = [
|
||||
'@idzimmer' => $room->id,
|
||||
'@kategorie' => $room->category,
|
||||
@@ -168,7 +171,7 @@ class BookingPayloadBuilder
|
||||
'@anreise' => $room->dateFrom ? $room->dateFrom->format('d.m.Y') : null,
|
||||
'@abreise' => $room->dateTo ? $room->dateTo->format('d.m.Y') : null,
|
||||
'@anzahl' => $room->totalCount,
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $room->mapping)),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $uniqueMapping)),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -176,11 +179,12 @@ class BookingPayloadBuilder
|
||||
if (false === empty($bookingData->insurances)) {
|
||||
$payload['versicherungen']['versicherung'] = [];
|
||||
foreach ($bookingData->insurances as $insurance) {
|
||||
if (count($insurance->mapping) > 0) {
|
||||
$uniqueMapping = array_unique($insurance->mapping);
|
||||
if (count($uniqueMapping) > 0) {
|
||||
$payload['versicherungen']['versicherung'][] = [
|
||||
'@idversicherung' => $insurance->id,
|
||||
'@anzahl' => count($insurance->mapping),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $insurance->mapping)),
|
||||
'@anzahl' => count($uniqueMapping),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $uniqueMapping)),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -200,10 +204,11 @@ class BookingPayloadBuilder
|
||||
if (0 < count($bookingData->pickupsOutbound)) {
|
||||
$payload['zustiege']['zustieg'] = [];
|
||||
foreach ($bookingData->pickupsOutbound as $pickup) {
|
||||
$uniqueMapping = array_unique($pickup->mapping);
|
||||
$payload['zustiege']['zustieg'][] = [
|
||||
'@idzustieg' => $pickup->id,
|
||||
'@anzahl' => count($pickup->mapping),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $pickup->mapping)),
|
||||
'@anzahl' => count($uniqueMapping),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $uniqueMapping)),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -415,10 +420,11 @@ class BookingPayloadBuilder
|
||||
if (false === empty($serviceMap)) {
|
||||
$payload[$sectionKey][$itemKey] = [];
|
||||
foreach ($serviceMap as $serviceId => $participantIds) {
|
||||
$uniqueParticipantIds = array_unique($participantIds);
|
||||
$payload[$sectionKey][$itemKey][] = [
|
||||
$idAttributeName => $serviceId,
|
||||
'@anzahl' => count($participantIds),
|
||||
'@zuordnung' => implode(',', $participantIds),
|
||||
'@anzahl' => count($uniqueParticipantIds),
|
||||
'@zuordnung' => implode(',', $uniqueParticipantIds),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -462,6 +468,7 @@ class BookingPayloadBuilder
|
||||
}
|
||||
|
||||
$quantity = $roomQuantities[$roomId] ?? 1;
|
||||
$uniqueParticipantIds = array_unique($participantIds);
|
||||
|
||||
$payload['ferienzielunterbringungen']['ferienzielunterbringung'][] = [
|
||||
'@idzimmer' => $room->id,
|
||||
@@ -470,7 +477,7 @@ class BookingPayloadBuilder
|
||||
'@anreise' => $bookingDto->travel->dateFrom->format('d.m.Y'),
|
||||
'@abreise' => $bookingDto->travel->dateTo->format('d.m.Y'),
|
||||
'@anzahl' => $quantity,
|
||||
'@zuordnung' => implode(',', $participantIds),
|
||||
'@zuordnung' => implode(',', $uniqueParticipantIds),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,10 +461,12 @@ class BookingEditDraftService
|
||||
private function resolveServiceArray(array $serviceIds, array $services): array
|
||||
{
|
||||
$resolved = [];
|
||||
$addedIds = [];
|
||||
|
||||
foreach ($serviceIds as $serviceId) {
|
||||
if (isset($services[$serviceId])) {
|
||||
if (isset($services[$serviceId]) && false === isset($addedIds[$serviceId])) {
|
||||
$resolved[] = $services[$serviceId];
|
||||
$addedIds[$serviceId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ class BookingFingerprintService
|
||||
private function normalizeServiceArray(array $services): array
|
||||
{
|
||||
$ids = array_map(fn ($s) => $s->id, $services);
|
||||
$ids = array_unique($ids);
|
||||
sort($ids);
|
||||
|
||||
return array_values($ids);
|
||||
|
||||
Reference in New Issue
Block a user