Merged in fix/SW-2440-breakfast-tracking (pull request #1947)
Fix/SW-2440 breakfast tracking * fix(SW-2440): fix confirmation ancillaries tracking * fix(SW-2440): add breakfast ancillary when preselected Approved-by: Bianca Widstam
This commit is contained in:
@@ -34,16 +34,6 @@ function getRate(cancellationRule: RateDefinition["cancellationRule"] | null) {
|
||||
}
|
||||
}
|
||||
|
||||
function findAncillaryPackages(
|
||||
packages: BookingConfirmation["booking"]["packages"]
|
||||
): BookingConfirmation["booking"]["packages"] {
|
||||
return packages.filter(
|
||||
(pkg) =>
|
||||
pkg.code === RoomPackageCodeEnum.PET_ROOM ||
|
||||
pkg.code === BreakfastPackageEnum.REGULAR_BREAKFAST
|
||||
)
|
||||
}
|
||||
|
||||
function mapAncillaryPackage(
|
||||
ancillaryPackage: BookingConfirmation["booking"]["packages"][number],
|
||||
operaId: string
|
||||
@@ -91,10 +81,13 @@ export function getTracking(
|
||||
CancellationRuleEnum.CancellableBefore6PM
|
||||
|
||||
const ancillaries: TrackingSDKAncillaries = rooms
|
||||
.filter((r) => findAncillaryPackages(r.packages))
|
||||
.flatMap((r) => {
|
||||
return r.packages.map((pkg) => mapAncillaryPackage(pkg, hotel.operaId))
|
||||
})
|
||||
.flatMap((r) => r.packages)
|
||||
.filter(
|
||||
(p) =>
|
||||
p.code === RoomPackageCodeEnum.PET_ROOM ||
|
||||
p.code === BreakfastPackageEnum.REGULAR_BREAKFAST
|
||||
)
|
||||
.map((pkg) => mapAncillaryPackage(pkg, hotel.operaId))
|
||||
|
||||
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
||||
ageOfChildren: rooms.map((r) => r.childrenAges?.join(",") ?? "").join("|"),
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
type TrackingSDKPageData,
|
||||
} from "@/types/components/tracking"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
import { PackageTypeEnum } from "@/types/enums/packages"
|
||||
import type { Hotel } from "@/types/hotel"
|
||||
import type { Room } from "@/types/providers/details/room"
|
||||
import type { RoomState } from "@/types/stores/enter-details"
|
||||
@@ -196,7 +197,7 @@ export function getTracking(
|
||||
.join(","),
|
||||
}
|
||||
const roomsWithPetRoom = rooms.filter(hasPetRoom)
|
||||
const ancillaries: TrackingSDKAncillaries = roomsWithPetRoom
|
||||
const petRoomAncillaries: TrackingSDKAncillaries = roomsWithPetRoom
|
||||
.slice(0, 1) // should only be one item
|
||||
.map((room) => {
|
||||
return room.packages
|
||||
@@ -213,6 +214,25 @@ export function getTracking(
|
||||
}))[0]
|
||||
})
|
||||
|
||||
const breakfastAncillaries: TrackingSDKAncillaries = storedRooms
|
||||
.map((room) => {
|
||||
return { breakfast: room.room.breakfast, adults: room.room.adults }
|
||||
})
|
||||
.filter(hasBreakfast)
|
||||
.map(({ breakfast, adults }) => {
|
||||
return {
|
||||
hotelId: hotel.operaId,
|
||||
productId: breakfast.code,
|
||||
productUnits: adults,
|
||||
productPoints: 0,
|
||||
productPrice: breakfast.localPrice.totalPrice,
|
||||
productType: "food",
|
||||
productName: breakfast.description,
|
||||
productCategory: breakfast.packageType,
|
||||
}
|
||||
})
|
||||
const ancillaries = petRoomAncillaries.concat(breakfastAncillaries)
|
||||
|
||||
return {
|
||||
hotelsTrackingData,
|
||||
pageTrackingData,
|
||||
@@ -247,6 +267,21 @@ function hasPetRoom(
|
||||
return room.packages.some((p) => p.code === RoomPackageCodeEnum.PET_ROOM)
|
||||
}
|
||||
|
||||
type RoomEntry = {
|
||||
breakfast?: BreakfastPackages[number] | false
|
||||
adults: number
|
||||
}
|
||||
|
||||
function hasBreakfast(entry: RoomEntry): entry is RoomEntry & {
|
||||
breakfast: BreakfastPackages[number]
|
||||
adults: number
|
||||
} {
|
||||
return (
|
||||
entry.breakfast !== false &&
|
||||
entry.breakfast?.packageType === PackageTypeEnum.BreakfastAdult
|
||||
)
|
||||
}
|
||||
|
||||
function calcTotalPrice(rooms: Room[], isMember: boolean) {
|
||||
const totalRoomPrice = calcTotalRoomPrice(rooms, isMember)
|
||||
const totalPackageSum = rooms.reduce((total, room) => {
|
||||
|
||||
Reference in New Issue
Block a user