Merged in fix/SW-3198-prices-select-rate (pull request #2763)
fix(SW-3198): fix striketrhough/regular prices, the same in enter details as select rate * fix(SW-3198): fix striketrhough/regular prices, the same in enter details as select rate * fix(SW-3198): remove additonalcost if calculating cost per room * fix(SW-3198): include bookingcode in specialrate * fix(SW-3198): remove console log * fix(SW-3198): add or operator * fix(SW-3198): capture total return value * fix(SW-3198): rename and move function Approved-by: Joakim Jäderberg Approved-by: Hrishikesh Vaipurkar
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { parsePhoneNumberFromString } from "libphonenumber-js"
|
||||
|
||||
import { calculateRegularPrice } from "@scandic-hotels/booking-flow/utils/calculateRegularPrice"
|
||||
import {
|
||||
sumPackages,
|
||||
sumPackagesRequestedPrice,
|
||||
@@ -495,17 +496,11 @@ export function getRegularPrice(
|
||||
(total, room, idx) => {
|
||||
const isMainRoomAndMember = idx === 0 && isMember
|
||||
const join = Boolean(room.guest.join || room.guest.membershipNo)
|
||||
const getMemberRate = isMainRoomAndMember || join
|
||||
|
||||
const memberRate = "member" in room.roomRate && room.roomRate.member
|
||||
const publicRate = "public" in room.roomRate && room.roomRate.public
|
||||
const useMemberRate = (isMainRoomAndMember || join) && memberRate
|
||||
|
||||
let rate
|
||||
if (getMemberRate && memberRate) {
|
||||
rate = memberRate
|
||||
} else if (publicRate) {
|
||||
rate = publicRate
|
||||
}
|
||||
const rate = useMemberRate ? memberRate : publicRate
|
||||
|
||||
if (!rate) {
|
||||
return total
|
||||
@@ -547,61 +542,23 @@ export function getRegularPrice(
|
||||
)
|
||||
}
|
||||
|
||||
// Legend:
|
||||
// - total.local.price = Total Price = Black price, what the user pays
|
||||
// - total.local.regularPrice = Regular Price = Strikethrough price (could potentially be none)
|
||||
// - total.requested.price = Requested Price = EUR approx price
|
||||
|
||||
// We sometimes don't get all the required data to calculate the correct strikethrough total.
|
||||
// Therefore we try these different approach to get a number that is close
|
||||
// enough to the real number if all data would've been present.
|
||||
if (getMemberRate && memberRate) {
|
||||
if (publicRate) {
|
||||
// #1 Member price uses public price as strikethrough
|
||||
total.local.regularPrice = add(
|
||||
total.local.regularPrice,
|
||||
publicRate.localPrice.pricePerStay,
|
||||
additionalCost
|
||||
)
|
||||
} else if (memberRate.localPrice.regularPricePerStay) {
|
||||
// #2 Member price uses member regular price as strikethrough
|
||||
total.local.regularPrice = add(
|
||||
total.local.regularPrice,
|
||||
memberRate.localPrice.regularPricePerStay,
|
||||
additionalCost
|
||||
)
|
||||
} else {
|
||||
// #3 Member price uses member price as strikethrough
|
||||
// NOTE: If all rooms end up using this, no strikethrough price is shown.
|
||||
total.local.regularPrice = add(
|
||||
total.local.regularPrice,
|
||||
memberRate.localPrice.pricePerStay,
|
||||
additionalCost
|
||||
)
|
||||
}
|
||||
} else if (publicRate) {
|
||||
if (publicRate.localPrice.regularPricePerStay) {
|
||||
// #1 Public price uses public regular price as strikethrough
|
||||
total.local.regularPrice = add(
|
||||
total.local.regularPrice,
|
||||
publicRate.localPrice.regularPricePerStay,
|
||||
additionalCost
|
||||
)
|
||||
} else {
|
||||
// #2 Public price uses public price as strikethrough
|
||||
// NOTE: If all rooms end up using this, no strikethrough price is shown.
|
||||
total.local.regularPrice = add(
|
||||
total.local.regularPrice,
|
||||
publicRate.localPrice.pricePerStay,
|
||||
additionalCost
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// We cannot do anything, too much data is missing.
|
||||
return total
|
||||
}
|
||||
|
||||
return total
|
||||
return calculateRegularPrice({
|
||||
total,
|
||||
useMemberRate: !!useMemberRate,
|
||||
regularMemberPrice: memberRate
|
||||
? {
|
||||
pricePerStay: memberRate.localPrice.pricePerNight,
|
||||
regularPricePerStay: memberRate.localPrice.regularPricePerStay,
|
||||
}
|
||||
: undefined,
|
||||
regularPublicPrice: publicRate
|
||||
? {
|
||||
pricePerStay: publicRate.localPrice.pricePerNight,
|
||||
regularPricePerStay: publicRate.localPrice.regularPricePerStay,
|
||||
}
|
||||
: undefined,
|
||||
additionalCost,
|
||||
})
|
||||
},
|
||||
{
|
||||
local: {
|
||||
|
||||
Reference in New Issue
Block a user