This commit is contained in:
Oliver
2025-10-07 16:39:03 -03:00
parent 538f73bbb2
commit 9d99cd572a

View File

@@ -119,8 +119,6 @@ function createModal() {
return modal;
}
function openModal(productHref) {
const modal = document.getElementById("buyNowModal");
modal.style.display = "flex";
@@ -132,16 +130,26 @@ function openModal(productHref) {
confirmation.style.display = "none";
// Parse productHref
let product = "Unknown";
let price = "0";
let id = "";
let price = "0";
let product = "Unknown";
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.
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);
}
// Show/hide location select if ID starts with "_"
@@ -174,6 +182,8 @@ function openModal(productHref) {
function handleFormSubmit() {
const form = document.getElementById("buyForm");
const confirmation = document.getElementById("confirmation");