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(
|
function mapAncillaryPackage(
|
||||||
ancillaryPackage: BookingConfirmation["booking"]["packages"][number],
|
ancillaryPackage: BookingConfirmation["booking"]["packages"][number],
|
||||||
operaId: string
|
operaId: string
|
||||||
@@ -91,10 +81,13 @@ export function getTracking(
|
|||||||
CancellationRuleEnum.CancellableBefore6PM
|
CancellationRuleEnum.CancellableBefore6PM
|
||||||
|
|
||||||
const ancillaries: TrackingSDKAncillaries = rooms
|
const ancillaries: TrackingSDKAncillaries = rooms
|
||||||
.filter((r) => findAncillaryPackages(r.packages))
|
.flatMap((r) => r.packages)
|
||||||
.flatMap((r) => {
|
.filter(
|
||||||
return r.packages.map((pkg) => mapAncillaryPackage(pkg, hotel.operaId))
|
(p) =>
|
||||||
})
|
p.code === RoomPackageCodeEnum.PET_ROOM ||
|
||||||
|
p.code === BreakfastPackageEnum.REGULAR_BREAKFAST
|
||||||
|
)
|
||||||
|
.map((pkg) => mapAncillaryPackage(pkg, hotel.operaId))
|
||||||
|
|
||||||
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
||||||
ageOfChildren: rooms.map((r) => r.childrenAges?.join(",") ?? "").join("|"),
|
ageOfChildren: rooms.map((r) => r.childrenAges?.join(",") ?? "").join("|"),
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
type TrackingSDKPageData,
|
type TrackingSDKPageData,
|
||||||
} from "@/types/components/tracking"
|
} from "@/types/components/tracking"
|
||||||
import { CurrencyEnum } from "@/types/enums/currency"
|
import { CurrencyEnum } from "@/types/enums/currency"
|
||||||
|
import { PackageTypeEnum } from "@/types/enums/packages"
|
||||||
import type { Hotel } from "@/types/hotel"
|
import type { Hotel } from "@/types/hotel"
|
||||||
import type { Room } from "@/types/providers/details/room"
|
import type { Room } from "@/types/providers/details/room"
|
||||||
import type { RoomState } from "@/types/stores/enter-details"
|
import type { RoomState } from "@/types/stores/enter-details"
|
||||||
@@ -196,7 +197,7 @@ export function getTracking(
|
|||||||
.join(","),
|
.join(","),
|
||||||
}
|
}
|
||||||
const roomsWithPetRoom = rooms.filter(hasPetRoom)
|
const roomsWithPetRoom = rooms.filter(hasPetRoom)
|
||||||
const ancillaries: TrackingSDKAncillaries = roomsWithPetRoom
|
const petRoomAncillaries: TrackingSDKAncillaries = roomsWithPetRoom
|
||||||
.slice(0, 1) // should only be one item
|
.slice(0, 1) // should only be one item
|
||||||
.map((room) => {
|
.map((room) => {
|
||||||
return room.packages
|
return room.packages
|
||||||
@@ -213,6 +214,25 @@ export function getTracking(
|
|||||||
}))[0]
|
}))[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 {
|
return {
|
||||||
hotelsTrackingData,
|
hotelsTrackingData,
|
||||||
pageTrackingData,
|
pageTrackingData,
|
||||||
@@ -247,6 +267,21 @@ function hasPetRoom(
|
|||||||
return room.packages.some((p) => p.code === RoomPackageCodeEnum.PET_ROOM)
|
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) {
|
function calcTotalPrice(rooms: Room[], isMember: boolean) {
|
||||||
const totalRoomPrice = calcTotalRoomPrice(rooms, isMember)
|
const totalRoomPrice = calcTotalRoomPrice(rooms, isMember)
|
||||||
const totalPackageSum = rooms.reduce((total, room) => {
|
const totalPackageSum = rooms.reduce((total, room) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user