16 lines
641 B
TypeScript
16 lines
641 B
TypeScript
export const BUY_NOW_MODE = 'buyNow'
|
|
|
|
type QueryValue = string | string[] | null | undefined
|
|
|
|
const firstQueryValue = (value: QueryValue) => Array.isArray(value) ? value[0] : value
|
|
|
|
export const getBuyNowProductIdFromQuery = (query: Record<string, unknown>) => {
|
|
const mode = firstQueryValue(query.mode as QueryValue)
|
|
const productId = firstQueryValue(query.productId as QueryValue)
|
|
return mode === BUY_NOW_MODE && productId ? String(productId) : ''
|
|
}
|
|
|
|
export const isBuyNowCartItem = (itemProductId: unknown, buyNowProductId: string) => {
|
|
return Boolean(buyNowProductId) && String(itemProductId || '') === String(buyNowProductId)
|
|
}
|