feat: multiprivileges in custom tariffs
This commit is contained in:
parent
e2ab652944
commit
68876d3c0a
@ -110,10 +110,19 @@ export const setCustomTariffsUserValue = (
|
||||
if (!privilegeWithoutAmount) throw new Error(`Privilege not found: ${privilegeId}`)
|
||||
let priceWithoutDiscounts = 0
|
||||
let priceAfterDiscounts = 0
|
||||
const privilege: PrivilegeWithAmount = {
|
||||
...privilegeWithoutAmount,
|
||||
amount: value,
|
||||
}
|
||||
console.log(JSON.stringify(state.userValuesMap[serviceKey]))
|
||||
const privileges = new Array<PrivilegeWithAmount>()
|
||||
|
||||
Object.keys(state.userValuesMap[serviceKey]).forEach(e => {
|
||||
const pwa = state.privilegeByService[serviceKey].find(p => p._id === e)
|
||||
if (!pwa) return
|
||||
if (state.userValuesMap[serviceKey][e] > 0)
|
||||
privileges.push({
|
||||
...pwa,
|
||||
amount: state.userValuesMap[serviceKey][e]
|
||||
})
|
||||
})
|
||||
|
||||
let tariff: Tariff = {
|
||||
_id: "",
|
||||
name: "",
|
||||
@ -121,7 +130,7 @@ export const setCustomTariffsUserValue = (
|
||||
description: "",
|
||||
isCustom: true,
|
||||
isDeleted: false,
|
||||
privileges: [privilege],
|
||||
privileges: privileges,
|
||||
}
|
||||
const cart = calcCart([...Object.values(useCartStore.getState().cartTariffMap as Record<string, Tariff>), tariff], discounts, purchasesAmount, isUserNko)
|
||||
|
||||
|
@ -60,7 +60,6 @@ function findCartDiscount(
|
||||
cartPurchasesAmount >= Number(discount.Condition.CartPurchasesAmount)
|
||||
);
|
||||
});
|
||||
console.log('FCD', applicableDiscounts)
|
||||
|
||||
if (!applicableDiscounts.length) return null;
|
||||
|
||||
@ -127,17 +126,18 @@ export function calcCart(tariffs: Tariff[], discounts: Discount[], purchasesAmou
|
||||
}
|
||||
|
||||
tariffs.forEach(tariff => {
|
||||
console.log(tariff)
|
||||
if (
|
||||
tariff.price !== undefined
|
||||
(tariff.price || 0) > 0
|
||||
&& tariff.privileges.length !== 1
|
||||
) throw new Error("Price is defined for tariff with several")
|
||||
|
||||
let serviceData =cartData.services.find(service => (service.serviceKey === "custom" && tariff.isCustom))
|
||||
if (!serviceData && !tariff.isCustom) serviceData = cartData.services.find(service => service.serviceKey === tariff.privileges[0].serviceKey)
|
||||
if (!serviceData && !tariff.isCustom) serviceData = cartData.services.find(service => service.serviceKey === tariff.privileges[0]?.serviceKey)
|
||||
|
||||
if (!serviceData) {
|
||||
serviceData = {
|
||||
serviceKey: tariff.isCustom ?"custom" :tariff.privileges[0].serviceKey,
|
||||
serviceKey: tariff.isCustom ?"custom" :tariff.privileges[0]?.serviceKey,
|
||||
tariffs: [],
|
||||
price: 0,
|
||||
appliedServiceDiscount: null,
|
||||
|
Loading…
Reference in New Issue
Block a user