Completa tu PACK
—Reparte las unidades entre tallas y sube tu diseño. El precio incluye impresión frontal. Si prefieres, puedes enviarlo más tarde (dejaremos el pedido Pendiente de arte).
Tallas
Adulto
Asignadas 0/0
Diseño (frente incluido)
Formatos: JPG/PNG/PDF/AI/SVG · Máx. 20 MB · Calidad recomendada: mínimo 1200 px en el lado más corto.
${f.name} (${Math.round(f.size/1024)} KB) — ${img.width}×${img.height}px
`; out.appendChild(img); }; img.src=e.target.result; }; reader.readAsDataURL(f);
} else { out.textContent = `${f.name} (${Math.round(f.size/1024)} KB)`; }
validate();
});
document.getElementById('t-later').addEventListener('change', validate);
// --- Subida AJAX del archivo (si corresponde) ---
async function uploadArtworkIfNeeded() {
const later = document.getElementById('t-later').checked;
const fi = document.getElementById('t-front');
if (later || !fi.files || !fi.files[0]) return null;
const fd = new FormData();
fd.append('action', 'cp_pack_upload');
fd.append('nonce', (window.cpPackNonce || ''));
fd.append('file', fi.files[0]);
const resp = await fetch(window.cpAjax || '/wp-admin/admin-ajax.php', { method: 'POST', body: fd });
const json = await resp.json();
if (!json || !json.success) throw new Error(json && json.data ? json.data : 'Error al subir el archivo.');
return json.data; // {id,url}
}
// CTA – ir al CARRITO con pack_meta (incluye art_id/art_url si hay)
document.getElementById('t-continue').addEventListener('click', async ()=>{
const btn=document.getElementById('t-continue');
if(btn.hasAttribute('disabled')) return;
try{
btn.textContent='Procesando…'; btn.disabled=true;
let art = await uploadArtworkIfNeeded(); // null si no se sube
const meta={
gramaje, color, cantidad,
tallas: data,
enviar_mas_tarde: document.getElementById('t-later').checked,
notas: document.getElementById('t-notes').value,
art_id: art ? art.id : null,
art_url: art ? art.url : ''
};
const payload = btoa(unescape(encodeURIComponent(JSON.stringify(meta))));
const base = (window.cpCartURL || '/carrito/');
const sep = base.includes('?') ? '&' : '?';
window.location.assign(base + sep + 'pack_meta=' + encodeURIComponent(payload));
} catch(err){
alert(err.message || 'No se pudo subir el archivo.');
btn.textContent='Continuar a pago'; btn.disabled=false;
}
});
renderSizes();
})();