]> OzVa Git service - shopping-channel/commitdiff
Fixed bug with discount on pricing
authorMax Value <greenwoodw50@gmail.com>
Sat, 12 Apr 2025 21:44:55 +0000 (22:44 +0100)
committerMax Value <greenwoodw50@gmail.com>
Sat, 12 Apr 2025 21:44:55 +0000 (22:44 +0100)
extensions/pricing.js

index 3555e472556b70767a0d8f1b6e04f3b65e3b0053..68c351cd7538e7f8df644d0a0b69be8027cc6f22 100644 (file)
@@ -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}`;
+                               }
                        }
                });
        });