fix: revert pickup pricing to match current BusPro behavior
Reverts split pricing calculation to use outbound-only pricing, matching BusPro's current behavior where pickup is only charged when outbound transportation is BUS. - Use pickup->price directly instead of calculateEffectivePrice() - PKW+BUS scenario now correctly charges €0 (matches BusPro loophole) - priceOutbound/priceInbound remain populated for future activation - Updated documentation with current behavior and future plan
This commit is contained in:
@@ -76,8 +76,12 @@ class TravelParser extends AbstractParser
|
||||
$travel->transportationServices = $this
|
||||
->getTransportationServices($node->filterXPath('//lei_befoerderung/leistung'));
|
||||
$travel->rooms = $this->getRooms($hotelNode);
|
||||
$travel->pickupsOutbound = $this->getPickups($node->filterXPath('//zustiege/zustieg'), $dateFrom);
|
||||
$travel->pickupsInbound = $this->getPickups($node->filterXPath('//zustiege_rueck/zustieg_rueck'), $dateTo);
|
||||
$travel->pickupsOutbound = $this->getPickups($node->filterXPath('//zustiege/zustieg'), $dateFrom, true);
|
||||
$travel->pickupsInbound = $this->getPickups($node->filterXPath('//zustiege_rueck/zustieg_rueck'), $dateTo, false);
|
||||
|
||||
// Merge inbound prices into outbound pickups for split pricing support
|
||||
$this->mergeInboundPricesIntoOutboundPickups($travel->pickupsOutbound, $travel->pickupsInbound);
|
||||
|
||||
$travel->guide = $this->getGuide($node);
|
||||
|
||||
return $travel;
|
||||
@@ -256,14 +260,15 @@ class TravelParser extends AbstractParser
|
||||
*
|
||||
* @param Crawler $node The XML node containing pickup data
|
||||
* @param \DateTimeImmutable|null $defaultDate Default date for time parsing (outbound only)
|
||||
* @param bool $isOutbound Whether these are outbound pickups (for split pricing)
|
||||
*
|
||||
* @return array<int, Pickup> Array of pickup locations indexed by ID
|
||||
*/
|
||||
public function getPickups(Crawler $node, ?\DateTimeImmutable $defaultDate = null): array
|
||||
public function getPickups(Crawler $node, ?\DateTimeImmutable $defaultDate = null, bool $isOutbound = true): array
|
||||
{
|
||||
$pickups = [];
|
||||
|
||||
$node->each(function (Crawler $pickupNode) use (&$pickups, $defaultDate) {
|
||||
$node->each(function (Crawler $pickupNode) use (&$pickups, $defaultDate, $isOutbound) {
|
||||
$pickupId = (int) $pickupNode->attr('idbuspro');
|
||||
|
||||
$pickup = new Pickup();
|
||||
@@ -271,6 +276,13 @@ class TravelParser extends AbstractParser
|
||||
$pickup->price = $pickupNode->attr('preis') ?
|
||||
$this->stringToFloat($pickupNode->attr('preis')) : null;
|
||||
|
||||
// Set direction-specific price for split pricing support
|
||||
if ($isOutbound) {
|
||||
$pickup->priceOutbound = $pickup->price;
|
||||
} else {
|
||||
$pickup->priceInbound = $pickup->price;
|
||||
}
|
||||
|
||||
// parse date and time only for direction 'to' indicated by provided default date
|
||||
if (null !== $defaultDate) {
|
||||
$pickup->time = $this->stringToDateTimeFuzzy($pickupNode->attr('zeit'), $defaultDate);
|
||||
@@ -408,4 +420,24 @@ class TravelParser extends AbstractParser
|
||||
$service->rawAgeConstraintData = $constraintData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges inbound pickup prices into outbound pickups for split pricing support.
|
||||
*
|
||||
* For each outbound pickup, finds the matching inbound pickup by ID and copies
|
||||
* the inbound price to the outbound pickup's priceInbound property. This enables
|
||||
* split pricing calculations where pickup costs are distributed between outbound
|
||||
* and inbound transportation.
|
||||
*
|
||||
* @param array<int, Pickup> $pickupsOutbound Outbound pickups indexed by ID (modified in place)
|
||||
* @param array<int, Pickup> $pickupsInbound Inbound pickups indexed by ID
|
||||
*/
|
||||
private function mergeInboundPricesIntoOutboundPickups(array &$pickupsOutbound, array $pickupsInbound): void
|
||||
{
|
||||
foreach ($pickupsOutbound as $pickupId => $outboundPickup) {
|
||||
if (isset($pickupsInbound[$pickupId])) {
|
||||
$outboundPickup->priceInbound = $pickupsInbound[$pickupId]->priceInbound;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user