Snaží se zjistit, jak k formulování koupit x, y získat zdarma. Příklad koupit 10 dostanete 1 zdarma, koupit 20 get 2 zdarma a tak dále. Teď jsem použít jen jako jako tento vzorec. Tento vzorec nebude fungovat, když změna příklad: Koupit 5 get 1 zdarma, koupit 10 dostanete 2 zdarma..
Ts
getFreeItem(){
let countTotal;
this.commonService.getOrderList$.subscribe((x) => {
x.filter(item => {
item.forEach((element, i) => {
if (element.freeDealMin !== null) {
item?.reduce((a, b) => {
let aVal = a?.count ? a?.count : a;
let bVal = b?.count ? b?.count : b;
countTotal = aVal + bVal;
return aVal + bVal;
}, 0);
let statusFree = element.freeDealMin/ countTotal;
if (statusFree == 1) {
this.freeDealQty = 1;
}else if (statusFree == 0.5) {
this.freeDealQty = 2;
}else if (statusFree == 0.33333333333) {
this.freeDealQty = 3;
}
}
});
});
});
}