From a1737893f44faaa7741b72389a65fe012811cefc Mon Sep 17 00:00:00 2001 From: "pawel.gaca" Date: Wed, 19 Nov 2025 09:27:14 +0100 Subject: [PATCH] =?UTF-8?q?mo=C5=BCliwo=C5=9B=C4=87=20przekazywania=20prod?= =?UTF-8?q?ukt=C3=B3w=20w=20ramce=20+=20obs=C5=82ugiwanie=20dodawania=20do?= =?UTF-8?q?=20koszyka=20na=20stronie=20koszyka?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + klasa.js | 30 +++++++++++++++++++++++++----- ramka.txt | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7b77d12..4185e4f 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ new IdmHotspot({ * @property {string} id - Identyfikator ramki (required). * @property {string} title - Tytuł ramki. * @property {string} classes - Dodatkowe klasy CSS. + * @property {object[]} [products] - tablica produktów z układem danych takich jak w graphql. Opcjonalne, pod specjalne funkcjonalności. * @property {object} placement - Określa, gdzie wstawić ramkę (required). * @property {string} placement.selector - Selektor miejsca osadzenia. * @property {string} placement.insert - Pozycja wstawienia względem selektora (np. "afterbegin", "beforeend"). diff --git a/klasa.js b/klasa.js index 46a374f..6aa36e3 100644 --- a/klasa.js +++ b/klasa.js @@ -149,7 +149,6 @@ const IDM_PRICE_QUERY = `price { const IDM_PRODUCT_QUERY = `id type name - zones icon iconSecond iconSmall @@ -452,7 +451,6 @@ class IdmHotspot{ this.hotspotEl = hotspotEl || null; - // Merge defaults this.options = { ...IdmHotspot.idmDefaultHotspotOptions.options, @@ -511,6 +509,7 @@ class IdmHotspot{ * Pobiera dane hotspotu z API GraphQL. */ async getHotspotData(){ + if(this.products) return; try{ const res = await fetch(`/graphql/v1/`, { method: "POST", @@ -634,8 +633,8 @@ class IdmHotspot{ markupLabel(prod){ let labelMarkup = "" // labele zones - if(prod.zones.find(zone => zone ==="bestseller")) labelMarkup += `${idmHotspotTextObject["Bestseller"]}`; - if(prod.zones.find(zone => zone ==="news")) labelMarkup += `${idmHotspotTextObject["Nowość"]}`; + if(prod.zones?.find(zone => zone ==="bestseller")) labelMarkup += `${idmHotspotTextObject["Bestseller"]}`; + if(prod.zones?.find(zone => zone ==="news")) labelMarkup += `${idmHotspotTextObject["Nowość"]}`; const omnibusPrice = prod.price?.omnibusPriceDetails?.unit?.[this.idmPriceType]?.formatted || prod.price.omnibusPrice[this.idmPriceType]?.formatted; if(omnibusPrice){ @@ -829,10 +828,23 @@ class IdmHotspot{ buttonEl.classList.add("--success"); // Dodawanie do koszyka na stronie basketedit.php będzie wymagał innego indywidualnego kodu!!!!! + app_shop.fn?.menu_basket_cache?.(); + + // STRONA KOSZYKA + if(typeof app_shop.fn?.basket?.reloadForm === "function"){ + const existingBasketBlockQuantity = document.querySelector(`.basket__block[data-product-id="${id}"][data-product-size="${size}"] input.buy__more_input.quantity__input[type="number"]`); + + // Dodanie do ilości produktu jeśli już był dodany do koszyka + if(existingBasketBlockQuantity) existingBasketBlockQuantity.value = +existingBasketBlockQuantity.value + 1; + + + // Przeładowanie koszyka na stronie basketedit.html + app_shop.fn?.basket?.reloadForm(); + } + buttonEl.innerHTML = `${buttonEl.dataset.success}`; setTimeout(()=>{ buttonEl.innerHTML = `${buttonEl.dataset.text}`; - app_shop.fn?.menu_basket_cache?.(); buttonEl.classList.remove("--success"); }, 3000); } @@ -1032,6 +1044,13 @@ class IdmHotspot{ console.log(`Initialized hotspot #${this.id}`); if(typeof this.options?.callbackFn === "function") this.options?.callbackFn(); + + // WCZYTANIE PONOWNIE DLA kOSZYKA + if(typeof app_shop.fn?.basket?.reloadForm === "function" && this.hotspotEl.closest("#content")){ + app_shop.run(()=>{ + this.init(); + }, "all", "#Basket", true) + } }catch(err){ console.error(idmHotspotTextObject["Wystąpił błąd z inicjalizacją. Proszę odśwież stronę"], err); } @@ -1345,6 +1364,7 @@ function idmHideTooltip(tooltipEl){ // source: { // productsMenu: 1649 // } +// products: [] // Tablica produktów // }); // { // id: "idmMainHotspot2", diff --git a/ramka.txt b/ramka.txt index 7a660ef..32468b4 100644 --- a/ramka.txt +++ b/ramka.txt @@ -5,10 +5,10 @@ - zakres cen????????????? - Wybór kolorystyczny??? - AAAAA - banner na hotspocie -- opinie - podmiana zdjęcia na hover - stary szablon - cena za kg +- blokowanie dodawania do koszyka jeśli ilość jest maksymalna