diff --git a/public/buyModal.js b/public/buyModal.js index 57a5280..4a3614e 100644 --- a/public/buyModal.js +++ b/public/buyModal.js @@ -119,6 +119,8 @@ function createModal() { return modal; } + + function openModal(productHref) { const modal = document.getElementById("buyNowModal"); modal.style.display = "flex"; @@ -130,26 +132,16 @@ function openModal(productHref) { confirmation.style.display = "none"; // Parse productHref - let id = ""; - let price = "0"; let product = "Unknown"; + let price = "0"; + let id = ""; - try { - const urlObj = new URL(productHref); - const pathParts = urlObj.pathname.split("/").filter(Boolean); - - if (pathParts.length === 2) { - // No ID in URL: /price/product - price = pathParts[0]; - product = decodeURIComponent(pathParts[1]); - } else if (pathParts.length >= 3) { - // ID present: /id/price/product - id = pathParts[0]; - price = pathParts[1]; - product = decodeURIComponent(pathParts.slice(2).join("/")); - } - } catch (e) { - console.error("Invalid URL:", productHref); + if (productHref.includes("/")) { + const parts = productHref.split("/").filter(Boolean); + id = parts[0] || ""; + price = parts[1] || "0"; + product = parts.slice(2).join("/"); // Join remaining parts for product name + product = decodeURIComponent(product); // Decode URL-encoded spaces etc. } // Show/hide location select if ID starts with "_" @@ -182,8 +174,6 @@ function openModal(productHref) { - - function handleFormSubmit() { const form = document.getElementById("buyForm"); const confirmation = document.getElementById("confirmation");