fix
This commit is contained in:
@@ -119,8 +119,6 @@ function createModal() {
|
|||||||
|
|
||||||
return modal;
|
return modal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function openModal(productHref) {
|
function openModal(productHref) {
|
||||||
const modal = document.getElementById("buyNowModal");
|
const modal = document.getElementById("buyNowModal");
|
||||||
modal.style.display = "flex";
|
modal.style.display = "flex";
|
||||||
@@ -132,16 +130,26 @@ function openModal(productHref) {
|
|||||||
confirmation.style.display = "none";
|
confirmation.style.display = "none";
|
||||||
|
|
||||||
// Parse productHref
|
// Parse productHref
|
||||||
let product = "Unknown";
|
|
||||||
let price = "0";
|
|
||||||
let id = "";
|
let id = "";
|
||||||
|
let price = "0";
|
||||||
|
let product = "Unknown";
|
||||||
|
|
||||||
if (productHref.includes("/")) {
|
try {
|
||||||
const parts = productHref.split("/").filter(Boolean);
|
const urlObj = new URL(productHref);
|
||||||
id = parts[0] || "";
|
const pathParts = urlObj.pathname.split("/").filter(Boolean);
|
||||||
price = parts[1] || "0";
|
|
||||||
product = parts.slice(2).join("/"); // Join remaining parts for product name
|
if (pathParts.length === 2) {
|
||||||
product = decodeURIComponent(product); // Decode URL-encoded spaces etc.
|
// 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 "_"
|
// Show/hide location select if ID starts with "_"
|
||||||
@@ -174,6 +182,8 @@ function openModal(productHref) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function handleFormSubmit() {
|
function handleFormSubmit() {
|
||||||
const form = document.getElementById("buyForm");
|
const form = document.getElementById("buyForm");
|
||||||
const confirmation = document.getElementById("confirmation");
|
const confirmation = document.getElementById("confirmation");
|
||||||
|
|||||||
Reference in New Issue
Block a user