demo files

This commit is contained in:
snt 2026-02-27 13:43:56 +01:00
parent 6381a2d985
commit a483925005
10 changed files with 1391 additions and 24 deletions

View file

@ -20,9 +20,22 @@
var page = checkoutPage || shopPage;
if (page) {
this.deliveryProductId = page.getAttribute("data-delivery-product-id");
var deliveryProductIdStr = page.getAttribute("data-delivery-product-id");
// Parse to integer, filter out None/empty/invalid values
if (
deliveryProductIdStr &&
deliveryProductIdStr !== "None" &&
deliveryProductIdStr !== ""
) {
this.deliveryProductId = parseInt(deliveryProductIdStr, 10);
if (isNaN(this.deliveryProductId)) {
this.deliveryProductId = null;
}
}
console.log(
"[HomeDelivery] deliveryProductId from attribute:",
deliveryProductIdStr,
"-> parsed:",
this.deliveryProductId,
"type:",
typeof this.deliveryProductId
@ -55,32 +68,49 @@
}
}
// Get order ID from confirm button
// Get order ID from multiple possible sources
var confirmBtn = document.getElementById("confirm-order-btn");
if (confirmBtn) {
this.orderId = confirmBtn.getAttribute("data-order-id");
console.log("[HomeDelivery] orderId from button:", this.orderId);
var cartContainer = document.getElementById("cart-items-container");
var orderIdElement = confirmBtn || cartContainer;
if (orderIdElement) {
this.orderId = orderIdElement.getAttribute("data-order-id");
}
// If still not found, try to extract from URL
if (!this.orderId) {
var urlMatch = window.location.pathname.match(/\/eskaera\/(\d+)/);
this.orderId = urlMatch ? urlMatch[1] : null;
}
console.log("[HomeDelivery] orderId resolved:", this.orderId);
// Handle checkbox (only exists on checkout page)
var checkbox = document.getElementById("home-delivery-checkbox");
if (!checkbox) return;
if (checkbox) {
var self = this;
checkbox.addEventListener("change", function () {
if (this.checked) {
self.addDeliveryProduct();
self.showDeliveryInfo();
} else {
self.removeDeliveryProduct();
self.hideDeliveryInfo();
}
});
var self = this;
checkbox.addEventListener("change", function () {
if (this.checked) {
self.addDeliveryProduct();
self.showDeliveryInfo();
} else {
self.removeDeliveryProduct();
self.hideDeliveryInfo();
}
});
// Check if delivery product is already in cart on page load
this.checkDeliveryInCart();
}
// Check if delivery product is already in cart on page load
this.checkDeliveryInCart();
// Vincular botón Home Delivery en el shop (cart header)
this.bindShopHomeDeliveryButton();
// Vincular botón Home Delivery en el shop SOLO si hay un producto de delivery válido
if (this.deliveryProductId && this.homeDeliveryEnabled) {
this.bindShopHomeDeliveryButton();
} else {
console.log(
"[HomeDelivery] Shop button NOT bound - no delivery product or disabled"
);
}
},
bindShopHomeDeliveryButton: function () {