fix: update displayed catalog price after comparing merchant prices
The catalog price shown next to a part (e.g. '€979.95') stayed stuck at its initial search-result value even after 'Compare prices' found and persisted a cheaper offer server-side (updatePriceIfCheaper already saves it to the database, but the locally held search result was never updated) — so the UI showed a stale, higher price right above a correctly-labeled 'cheapest' offer, which was confusing (e.g. '€979.95' next to 'Cdiscount: €741.51 (cheapest)'). comparePrices() now also updates part.price locally when the cheapest offer found beats it (or no catalog price was known), mirroring what the backend already persisted, so the display is consistent without needing to re-run the search.
This commit is contained in:
1 parent
54c5e37766
commit
fa74791c92
1 file changed
+13
@@ -64,6 +64,19 @@ async function comparePrices(part: ScrapedPart) {
|
||||
offers[part.id] = data.offers ?? []
|
||||
if (offers[part.id].length === 0) {
|
||||
compareErrors[part.id] = true
|
||||
return
|
||||
}
|
||||
|
||||
// The backend already persists the cheapest offer found as this
|
||||
// part's new best-known price when it beats the catalog price (see
|
||||
// ScrapedPartsController#compare / updatePriceIfCheaper). Mirror that
|
||||
// here on the locally held result so the displayed catalog price
|
||||
// (e.g. "€979.95") reflects it immediately, instead of staying stuck
|
||||
// at whatever price the initial search returned until the user
|
||||
// re-runs the search from scratch.
|
||||
const cheapest = offers[part.id][0]
|
||||
if (part.price === null || cheapest.price < part.price) {
|
||||
part.price = cheapest.price
|
||||
}
|
||||
} catch {
|
||||
compareErrors[part.id] = true
|
||||
|
||||
Reference in new issue
Block a user