Bitte einen Moment Geduld.
`; document.body.appendChild(overlay); try { const decodedString = atob(shareParam); const items = JSON.parse(decodedString); if (Array.isArray(items) && items.length > 0) { // 2. Aktuelle Artikel im Warenkorb abfragen const currentBasketRes = await fetch('/rest/io/basket/items/', { method: 'GET', headers: { 'X-Requested-With': 'XMLHttpRequest' }, credentials: 'same-origin' }); const currentBasket = await currentBasketRes.json(); const currentItems = currentBasket.data || []; // 3. Bestehende Artikel einzeln löschen for (const currentItem of currentItems) { await fetch('/rest/io/basket/items/' + currentItem.id, { method: 'DELETE', headers: { 'X-Requested-With': 'XMLHttpRequest' }, credentials: 'same-origin' }); } // 4. Neue Artikel nacheinander hinzufügen for (const item of items) { await fetch('/rest/io/basket/items/', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }, credentials: 'same-origin', body: JSON.stringify({ variationId: parseInt(item.v), quantity: parseFloat(item.q) }) }); } // 5. URL aufräumen const newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname; window.history.replaceState({path: newUrl}, '', newUrl); // 6. Seite neu laden (Overlay verschwindet dadurch automatisch) window.location.reload(); } } catch (e) { console.error("CartLink: Ungültiger oder beschädigter Link.", e); // Bei einem Fehler das Overlay wieder entfernen, damit die Seite nutzbar bleibt document.body.removeChild(overlay); alert("Fehler beim Laden des Warenkorbs. Der Link ist möglicherweise beschädigt."); } } });