fix: update price bundling items
parent
d5adc48d9b
commit
22b418b257
|
@ -22,20 +22,25 @@ export class UpdateItemRatePriceManager extends BaseCustomManager<ItemEntity> {
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
let query;
|
let query;
|
||||||
|
const bundling_items = [];
|
||||||
const item_ids = this.data.items.map((item) => {
|
const item_ids = this.data.items.map((item) => {
|
||||||
|
if (item.item.bundling_items) {
|
||||||
|
const bundlings = item.item.bundling_items.map(({ id }) => id);
|
||||||
|
bundling_items.push(...bundlings);
|
||||||
|
}
|
||||||
return item.item.id;
|
return item.item.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.data.season_period_id) {
|
if (this.data.season_period_id) {
|
||||||
query = {
|
query = {
|
||||||
item_id: In(item_ids),
|
item_id: In([...item_ids, ...bundling_items]),
|
||||||
season_period: {
|
season_period: {
|
||||||
id: this.data.season_period_id,
|
id: this.data.season_period_id,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
query = {
|
query = {
|
||||||
item_id: In(item_ids),
|
item_id: In([...item_ids, ...bundling_items]),
|
||||||
season_period: {
|
season_period: {
|
||||||
start_date: MoreThanOrEqual(this.data.booking_date),
|
start_date: MoreThanOrEqual(this.data.booking_date),
|
||||||
end_date: LessThanOrEqual(this.data.booking_date),
|
end_date: LessThanOrEqual(this.data.booking_date),
|
||||||
|
@ -54,6 +59,16 @@ export class UpdateItemRatePriceManager extends BaseCustomManager<ItemEntity> {
|
||||||
const current_price = this.rates.find(
|
const current_price = this.rates.find(
|
||||||
(rate) => rate.item_id == item.item.id,
|
(rate) => rate.item_id == item.item.id,
|
||||||
);
|
);
|
||||||
|
item.item.bundling_items = item.item.bundling_items?.map((bundling) => {
|
||||||
|
const current_price = this.rates.find(
|
||||||
|
(rate) => rate.item_id == bundling.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...bundling,
|
||||||
|
item_rates: current_price?.price ?? 0,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
Object.assign(item, {
|
Object.assign(item, {
|
||||||
total_price: current_price?.price ?? item.item.base_price,
|
total_price: current_price?.price ?? item.item.base_price,
|
||||||
|
|
Loading…
Reference in New Issue