diff --git a/src/BusProNet/XmlParser/TravelParser.php b/src/BusProNet/XmlParser/TravelParser.php index bfc2494..13fc26c 100644 --- a/src/BusProNet/XmlParser/TravelParser.php +++ b/src/BusProNet/XmlParser/TravelParser.php @@ -71,8 +71,9 @@ class TravelParser extends AbstractParser $travel->type = $node->attr('reiseart'); $travel->priceFrom = $this->stringToFloat($this->getStringOrNullValue($node->filterXPath('//abpreis'))); $travel->selectionGroups = $this->getSelectionGroups($node->filterXPath('//selektiongruppe')); + // Parse only termin-level additional services; exclude hotel-nested duplicates that can override flags. $travel->additionalServices = $this - ->getAdditionalServices($node->filterXPath('//lei_sonstiges/leistung')); + ->getAdditionalServices($node->filterXPath('.//lei_sonstiges[not(ancestor::hotel)]/leistung')); $travel->transportationServices = $this ->getTransportationServices($node->filterXPath('//lei_befoerderung/leistung')); $travel->rooms = $this->getRooms($hotelNode); diff --git a/tests/BusProNet/XmlParser/TravelParserTest.php b/tests/BusProNet/XmlParser/TravelParserTest.php index 6d78b7d..3e748c5 100644 --- a/tests/BusProNet/XmlParser/TravelParserTest.php +++ b/tests/BusProNet/XmlParser/TravelParserTest.php @@ -184,6 +184,47 @@ class TravelParserTest extends TestCase $this->assertTrue($additionalServices[183660]->autoBook); } + public function testParseAdditionalServicesUsesTerminLevelOnly(): void + { + $xmlContent = ' + + + + Test Travel + 659,00 + + + Skipass 6 Tage + 59,00 + Frei + + + + + + Skipass 6 Tage Hotel + 59,00 + Frei + + + + + + + + +'; + + $crawler = new Crawler($xmlContent); + $travelNode = $crawler->filterXPath('//reise/termin')->first(); + $travel = $this->parser->parse($travelNode); + + $additionalServices = $travel->additionalServices; + $this->assertArrayHasKey(183656, $additionalServices); + $this->assertTrue($additionalServices[183656]->autoBook); + $this->assertSame('Skipass 6 Tage', $additionalServices[183656]->label); + } + public function testParseServiceWithEmptyDescription(): void { $xmlContent = '