From d86fd4e2610f98c0964733f20142133a9251b207 Mon Sep 17 00:00:00 2001 From: Max Value Date: Sat, 12 Apr 2025 22:44:55 +0100 Subject: [PATCH] Fixed bug with discount on pricing --- extensions/pricing.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/extensions/pricing.js b/extensions/pricing.js index 3555e47..68c351c 100644 --- a/extensions/pricing.js +++ b/extensions/pricing.js @@ -25,6 +25,8 @@ function update() { // some variable setup let id = data.item_id; + const items = dataStatic.items; + const item = items[id]; // change the data if the id is different if (id != pastId) { @@ -32,9 +34,6 @@ function update() { button.classList.remove("sold"); img.classList.remove("sold"); - const items = dataStatic.items; - const item = items[id]; - // register function to change the data when the animation is done setTimeout(function () { @@ -43,7 +42,7 @@ function update() { subtext.innerHTML = item.subtext; description.innerHTML = item.description; - let priceValue = item.origional_price * (data.discount / 100); + let priceValue = item.origional_price * (1 - (data.discount / 100)); if (data.bool_rounding) { priceValue = Math.round(priceValue * 100) / 100; @@ -53,12 +52,24 @@ function update() { price.innerHTML = `${items[id].currency}${priceValue}`; } else { price.innerHTML = `${priceValue}${items[id].currency}`; - } + } main.classList.remove("hide"); pastId = id; }, 1500); + } else { + let priceValue = item.origional_price * (1 - (data.discount / 100)); + + if (data.bool_rounding) { + priceValue = Math.round(priceValue * 100) / 100; + } + + if (items[id].prefix) { + price.innerHTML = `${items[id].currency}${priceValue}`; + } else { + price.innerHTML = `${priceValue}${items[id].currency}`; + } } }); }); -- 2.39.2