Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build/bower.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2145,11 +2145,13 @@ HotelSearchClient.prototype = {
totalTaxAmountA = a.price.totalTaxAmount,
totalTaxAmountB = b.price.totalTaxAmount;

if (totalAmountA - totalTaxAmountA === totalAmountB - totalTaxAmountB) {
return b.price.ecpc - a.price.ecpc;
} else {
return (totalAmountA - totalTaxAmountA) - (totalAmountB - totalTaxAmountB);
}
var basePriceA = totalAmountA - totalTaxAmountA,
basePriceB = totalAmountB - totalTaxAmountB;

if (basePriceA !== basePriceB) return basePriceA - basePriceB;
if (a.provider.type === 'DIRECT_PRIORITY' && b.provider.type !== 'DIRECT_PRIORITY') return -1;
if (b.provider.type === 'DIRECT_PRIORITY' && a.provider.type !== 'DIRECT_PRIORITY') return 1;
return b.price.ecpc - a.price.ecpc;
});

self.__hotelMap[hotelId].sortedRatesByBasePrice = sortedCloneRates;
Expand Down
12 changes: 7 additions & 5 deletions build/npm.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2145,11 +2145,13 @@ HotelSearchClient.prototype = {
totalTaxAmountA = a.price.totalTaxAmount,
totalTaxAmountB = b.price.totalTaxAmount;

if (totalAmountA - totalTaxAmountA === totalAmountB - totalTaxAmountB) {
return b.price.ecpc - a.price.ecpc;
} else {
return (totalAmountA - totalTaxAmountA) - (totalAmountB - totalTaxAmountB);
}
var basePriceA = totalAmountA - totalTaxAmountA,
basePriceB = totalAmountB - totalTaxAmountB;

if (basePriceA !== basePriceB) return basePriceA - basePriceB;
if (a.provider.type === 'DIRECT_PRIORITY' && b.provider.type !== 'DIRECT_PRIORITY') return -1;
if (b.provider.type === 'DIRECT_PRIORITY' && a.provider.type !== 'DIRECT_PRIORITY') return 1;
return b.price.ecpc - a.price.ecpc;
});

self.__hotelMap[hotelId].sortedRatesByBasePrice = sortedCloneRates;
Expand Down
12 changes: 7 additions & 5 deletions src/hotel-search/Merger.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ HotelSearchClient.prototype = {
totalTaxAmountA = a.price.totalTaxAmount,
totalTaxAmountB = b.price.totalTaxAmount;

if (totalAmountA - totalTaxAmountA === totalAmountB - totalTaxAmountB) {
return b.price.ecpc - a.price.ecpc;
} else {
return (totalAmountA - totalTaxAmountA) - (totalAmountB - totalTaxAmountB);
}
var basePriceA = totalAmountA - totalTaxAmountA,
basePriceB = totalAmountB - totalTaxAmountB;

if (basePriceA !== basePriceB) return basePriceA - basePriceB;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @hoantony, from JIRA ticket, looks like we want to have direct partner on top disregard of the price. Can you confirm if that is the logic? If so, comparing by provider type will be higher priority than by price.

Copy link
Contributor Author

@hoantony hoantony Jun 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viettienn the logic here is correct. We only compare the Provider_types (which DRIECT_PRIORITY has higher priority) only when the prices are in parity. So the sorting conditions will be in order: amount -> provider_type -> ecpc.

if (a.provider.type === 'DIRECT_PRIORITY' && b.provider.type !== 'DIRECT_PRIORITY') return -1;
if (b.provider.type === 'DIRECT_PRIORITY' && a.provider.type !== 'DIRECT_PRIORITY') return 1;
return b.price.ecpc - a.price.ecpc;
});

self.__hotelMap[hotelId].sortedRatesByBasePrice = sortedCloneRates;
Expand Down
40 changes: 38 additions & 2 deletions test/hotel-search/Merger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ describe('Merger', function() {
}
};

var provider1 = {
id: 1,
code: "a",
type: "OTA"
};

var rate2 = {
id: 2,
hotelId: 1,
Expand All @@ -458,23 +464,53 @@ describe('Merger', function() {
}
};

var provider2 = {
id: 2,
code: "b",
type: "DIRECT_PRIORITY"
};

var rate3 = {
id: 3,
hotelId: 1,
providerCode: "c",
price: {
totalAmount: 10,
totalTaxAmount: 0,
ecpc: 0.05
}
};

var provider3 = {
id: 3,
code: "c",
type: "DIRECT_PRIORITY"
};

var rate4 = {
id: 4,
hotelId: 1,
providerCode: "d",
price: {
totalAmount: 25,
totalTaxAmount: 10,
ecpc: 0.20
}
};

var provider4 = {
id: 4,
code: "d",
type: "DIRECT"
};

merger.mergeResponse({
hotels: [{ id: 1 }],
rates: [rate1, rate2, rate3],
rates: [rate1, rate2, rate3, rate4],
providers: [provider1, provider2, provider3, provider4]
});

expect(getRateIds(merger.__hotelMap[1].sortedRatesByBasePrice)).to.deep.equal([2, 1, 3]);
expect(getRateIds(merger.__hotelMap[1].sortedRatesByBasePrice)).to.deep.equal([2, 3, 1, 4]);

});
});
Expand Down