możliwość przekazywania produktów w ramce + obsługiwanie dodawania do koszyka na stronie koszyka
This commit is contained in:
@@ -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").
|
||||
|
||||
30
klasa.js
30
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 += `<span class="label --bestseller --omnibus">${idmHotspotTextObject["Bestseller"]}</span>`;
|
||||
if(prod.zones.find(zone => zone ==="news")) labelMarkup += `<span class="label --news --omnibus">${idmHotspotTextObject["Nowość"]}</span>`;
|
||||
if(prod.zones?.find(zone => zone ==="bestseller")) labelMarkup += `<span class="label --bestseller --omnibus">${idmHotspotTextObject["Bestseller"]}</span>`;
|
||||
if(prod.zones?.find(zone => zone ==="news")) labelMarkup += `<span class="label --news --omnibus">${idmHotspotTextObject["Nowość"]}</span>`;
|
||||
|
||||
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 = `<span>${buttonEl.dataset.success}</span>`;
|
||||
setTimeout(()=>{
|
||||
buttonEl.innerHTML = `<span>${buttonEl.dataset.text}</span>`;
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user