SPEDIZIONE GRATUITA SOPRA I 200,00€

// ============================================================ // TABELLA PREZZI A VOLUME — da incollare in // admin.ecwid.com → Sito web → Codice JavaScript personalizzato // // Mostra sotto le opzioni del prodotto una tabella con // i prezzi per fascia di quantità. // // COME FUNZIONA: // - Appare SOLO sul prodotto con ID specificato (Pile Torino) // - Mostra la tabella prezzi statica // - Evidenzia la fascia corrispondente alla quantità scelta // ============================================================ (function() { // ID del prodotto Ecwid su cui mostrare la tabella // Cambia questo numero per altri prodotti var PRODUCT_ID = 837129795; // Fasce di prezzo (PREZZI DI ESEMPIO — da aggiornare) var FASCE = [ { label: "1 – 7 pz", prezzo: "32,00 €" }, { label: "8 – 23 pz", prezzo: "28,50 €" }, { label: "24 – 71 pz", prezzo: "25,00 €" }, { label: "72 – 143 pz", prezzo: "22,00 €" }, { label: "144 + pz", prezzo: "19,00 €" }, ]; // Quantità minima per ogni fascia (per evidenziare la riga) var QUANTITA_MIN = [1, 8, 24, 72, 144]; // CSS della tabella var CSS = ` #volume-price-table { margin: 20px 0; font-family: inherit; } #volume-price-table h4 { font-size: 14px; font-weight: 600; color: #333; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; } #volume-price-table table { width: 100%; border-collapse: collapse; font-size: 14px; } #volume-price-table th { background: #222; color: #fff; padding: 8px 12px; text-align: center; font-weight: 600; } #volume-price-table td { padding: 8px 12px; text-align: center; border-bottom: 1px solid #eee; color: #333; } #volume-price-table tr.fascia-attiva td { background: #fff3cd; font-weight: 700; color: #333; } #volume-price-table tr.fascia-attiva td:last-child { color: #c0392b; font-size: 16px; } #volume-price-table .nota { font-size: 12px; color: #888; margin-top: 8px; } `; // Funzione che crea la tabella HTML function buildTable(qtaAttuale) { var rows = ""; FASCE.forEach(function(fascia, i) { var isAttiva = ""; if (qtaAttuale !== null) { var min = QUANTITA_MIN[i]; var max = QUANTITA_MIN[i + 1] ? QUANTITA_MIN[i + 1] - 1 : 99999; if (qtaAttuale >= min && qtaAttuale <= max) { isAttiva = ' class="fascia-attiva"'; } } rows += '' + '' + fascia.label + '' + '' + fascia.prezzo + ' / pz' + ''; }); return '

💰 Prezzi a volume

' + '' + '' + '' + rows + '' + '
QuantitàPrezzo unitario
' + '

* Prezzi IVA esclusa. La fascia si aggiorna in base alla quantità scelta.

'; } // Funzione che inietta la tabella nella pagina prodotto function injectTable() { // Controlla che siamo sulla pagina giusta var url = window.location.href; if (!url.includes("pile-torino") && !url.includes(PRODUCT_ID)) { // Controlla anche tramite il titolo del prodotto nella pagina var titolo = document.querySelector(".product-details__product-title, .ec-page-title"); if (!titolo || !titolo.textContent.includes("Pile Torino")) { return; } } // Evita di aggiungere la tabella due volte if (document.getElementById("volume-price-table")) return; // Trova dove inserire la tabella (dopo le opzioni prodotto) var target = document.querySelector( ".product-details__product-options, " + ".ec-form, " + ".product-details-module__button-wrap" ); if (!target) return; // Crea il contenitore var div = document.createElement("div"); div.id = "volume-price-table"; div.innerHTML = buildTable(null); // Inserisce dopo le opzioni target.parentNode.insertBefore(div, target.nextSibling); // Aggiunge il CSS if (!document.getElementById("volume-price-css")) { var style = document.createElement("style"); style.id = "volume-price-css"; style.textContent = CSS; document.head.appendChild(style); } // Aggiorna la fascia evidenziata quando cambia la quantità var qtyInput = document.querySelector(".product-details__qty input, input[name='qty']"); if (qtyInput) { qtyInput.addEventListener("input", function() { var qta = parseInt(this.value) || 1; var tableDiv = document.getElementById("volume-price-table"); if (tableDiv) tableDiv.innerHTML = buildTable(qta); }); } } // Aspetta che Ecwid carichi la pagina prodotto // Ecwid è una SPA, dobbiamo aspettare che il DOM sia pronto function waitAndInject() { var attempts = 0; var interval = setInterval(function() { attempts++; injectTable(); if (document.getElementById("volume-price-table") || attempts > 20) { clearInterval(interval); } }, 500); } // Ascolta i cambi di pagina di Ecwid (SPA navigation) if (window.Ecwid) { Ecwid.OnPageLoaded.add(function(page) { if (page.type === "PRODUCT" && page.productId === PRODUCT_ID) { setTimeout(waitAndInject, 300); } }); } else { // Fallback: aspetta che Ecwid sia disponibile document.addEventListener("DOMContentLoaded", function() { setTimeout(waitAndInject, 1000); }); } })();