${name}
${price} €
${csIntroTxt}
`; this.#activeEvents(); } } // register component customElements.define("cross-sell", Crossell); });${txt}
${txt}
SCOPRI
${txt}
SCOPRI
+
` ); } else if ( customerCart .flat() .map((value) => value.type) .indexOf('capsule') !== -1 && excludeSKUs.some((r) => inCartSKU.includes(r)) && document.querySelector('.MiniBasketTotalTable') !== null && document.querySelector('#minibasketCrossell') === null ) { gtmDataObject = window.gtmDataObject || []; gtmDataObject.push({ event: 'impression', eventAction: 'Promo Impression - On Load', eventRaisedBy: 'FreeHTML', ecommerce: { promoView: { promotions: [ { id: 'IT_tracking_minibasketCrossell', name: "Summer Days 2024 - View Biscotti all'arancia from Minibasket", creative: 'NIT_minibasket_crossell', position: 'IT_nespresso_minibasket', }, ], }, }, }); document .querySelector('.MiniBasketTotalTable') .insertAdjacentHTML( 'afterend', `Più gusto alla tua pausa caffè Aggiungi i Biscotti al gusto di arancia a 8€
+
L'ideale per il tuo caffè con ghiaccio Aggiungi il Barista Ice Cube Tray a 9€
+
per vedere le nostre promozioni.` ); $('#GWPICAProgressBarCTA').html( `
SCOPRI
` ); } data.unsubscribe(); }) .evaluate(); data.unsubscribe(); }) .executeOnMismatch(function (data) { /* EVENTUALE USE CASE PER PROSPECT CHE SCEGLIE DI REGISTRARSI */ }) .evaluate(); }); function setupGWPICAEnviromentWithSelID(eligibleUserSelID) { eligibleSelIDProperties = {}; configureGWPICAVariable.some(function (el) { if (el.selID.indexOf(eligibleUserSelID) !== -1) { eligibleSelIDProperties = el; return true; } }); capsuleOLSKUInPromo = Object.values( NITDATABASE.filter((e) => e.TECH === 'OL') ) .flat() .map((value) => value.SKU); capsuleVLSKUInPromo = Object.values( NITDATABASE.filter((e) => e.TECH === 'VL') ) .flat() .map((value) => value.SKU); if (eligibleSelIDProperties.gifts.length > 1) { $('#GWPICAProgressBarImage').html( `` ); } else { $('#GWPICAProgressBarImage').html( `` ); } executeCapsulesCount(); window.napi.data().on( 'cart.*', function () { executeCapsulesCount(); }, 100 ); $('#activationStickyBanner').fadeIn(); } function executeCapsulesCount() { let capsOL = 0; let capsVL = 0; Promise.resolve( napi.cart().read({ forceFull: true, expandProducts: true }) ).then(function (cartResponse) { customerCart = cartResponse.cartLines; customerCart.forEach((object) => { if ( capsuleOLSKUInPromo.indexOf( object.id.replace('erp.it.b2c/prod/', '') ) !== -1 && object.type === 'capsule' ) { capsOL += object.bundled ? object.unitQuantity : object.quantity; } if ( capsuleVLSKUInPromo.indexOf( object.id.replace('erp.it.b2c/prod/', '') ) !== -1 && object.type === 'capsule' ) { capsVL += object.bundled ? object.unitQuantity : object.quantity; } }); let customerSelectedOL = false; totalCapsulesOnCart = 0; if (eligibleSelIDProperties.canMixCapsulesTech) { totalCapsulesOnCart = capsOL + capsVL; } else { if (capsVL >= capsOL) { totalCapsulesOnCart = capsVL; } else { totalCapsulesOnCart = capsOL; customerSelectedOL = true; } } let capsulesNextLimit = eligibleSelIDProperties.capsulesRequired !== 0 ? eligibleSelIDProperties.capsulesRequired : eligibleSelIDProperties.gifts.at(-1).capsulesRequired; if (totalCapsulesOnCart === 0) { if (eligibleSelIDProperties.canChooseGift) { if (eligibleSelIDProperties.gifts.length === 1) { $('#GWPICAProgressBarText').html( `${username},aggiungi ${eligibleSelIDProperties.capsulesRequired} capsule per ricevere ${eligibleSelIDProperties.gifts[0].name}!` ); $('#GWPICAProgressBarCTA').html( `
AGGIUNGI REGALO E ACCESSORIO
` ); } else { if (eligibleSelIDProperties.capsulesRequired !== 0) { $('#GWPICAProgressBarText').html( `${username},aggiungi ${eligibleSelIDProperties.capsulesRequired} capsule per scegliere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
SCEGLI REGALO E ACCESSORIO
` ); } else { $('#GWPICAProgressBarText').html( `${username},aggiungi ${eligibleSelIDProperties.gifts[0].capsulesRequired} capsule per scegliere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
SCEGLI REGALO E ACCESSORIO
` ); } } } else { $('#GWPICAProgressBarText').html( `${username},aggiungi ${eligibleSelIDProperties.capsulesRequired} capsule per avere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
CHECKOUT
` ); } if (!eligibleSelIDProperties.isClubActionDriven) { if ( eligibleSelIDProperties.selID.indexOf('') !== -1 && eligibleSelIDProperties.capsulesRequired !== 0 ) { executeNoCANoSelIDUseCase(customerSelectedOL, false); } if (eligibleSelIDProperties.canChooseGift) { let allGiftableSKU = eligibleSelIDProperties.gifts.map( (element) => element.sku ); let allInCartSKU = customerCart.map((element) => element.id.replace('erp.it.b2c/prod/', '') ); let filteredSKUArray = allGiftableSKU.filter(function (n) { return allInCartSKU.indexOf(n) !== -1; }); let allCrosselableSKU = crossellGift.map( (element) => element.sku ); let filteredCrosselableSKUArray = allCrosselableSKU.filter( function (n) { return allInCartSKU.indexOf(n) !== -1; } ); if (filteredSKUArray.length !== 0) { if (filteredCrosselableSKUArray.length === 0) { Promise.resolve( CartManager.updateItem(filteredSKUArray[0], 0) ); } else { Promise.resolve( CartManager.updateItem(filteredSKUArray[0], 0).then( (e) => { setTimeout(() => { $.post( CartManager.updateItem( filteredCrosselableSKUArray[0], 0 ) ); }, 1000); } ) ); } } } } } else if (totalCapsulesOnCart < capsulesNextLimit) { let progressBarGifts = ''; eligibleSelIDProperties.gifts .slice() //.reverse() .forEach((gift, index) => { progressBarGifts += `${ gift.capsulesRequired }
`; }); if (eligibleSelIDProperties.canChooseGift) { if (eligibleSelIDProperties.gifts.length === 1) { $('#GWPICAProgressBarText').html( `${username},aggiungi altre ${ eligibleSelIDProperties.capsulesRequired - totalCapsulesOnCart } capsule per ricevere ${ eligibleSelIDProperties.gifts[0].name }!
${totalCapsulesOnCart}
AGGIUNGI REGALO E ACCESSORIO
` ); } else { if (eligibleSelIDProperties.capsulesRequired !== 0) { $('#GWPICAProgressBarText').html( `${username},aggiungi altre ${ eligibleSelIDProperties.capsulesRequired - totalCapsulesOnCart } capsule per scegliere il tuo regalo e il tuo accessorio preferito!
${totalCapsulesOnCart}
SCEGLI REGALO E ACCESSORIO
` ); } else { if ( totalCapsulesOnCart < eligibleSelIDProperties.gifts[0].capsulesRequired ) { $('#GWPICAProgressBarText').html( `${username}, raggiungi la soglia capsule per avere il tuo regalo e il tuo accessorio preferito!${progressBarGifts}
${totalCapsulesOnCart}
AGGIUNGI REGALO E ACCESSORIO
` ); } else { let allGiftableSKU = eligibleSelIDProperties.gifts.map( (element) => element.sku ); let allInCartSKU = customerCart.map((element) => element.id.replace('erp.it.b2c/prod/', '') ); let filteredSKUArray = allGiftableSKU.filter(function ( n ) { return allInCartSKU.indexOf(n) !== -1; }); if (filteredSKUArray.length === 0) { $('#GWPICAProgressBarText').html( `${username}, raggiungi la soglia capsule per avere il tuo regalo e il tuo accessorio preferito!${progressBarGifts}
${totalCapsulesOnCart}
AGGIUNGI REGALO E ACCESSORIO
` ); } else { $('#GWPICAProgressBarText').html( `${username}, raggiungi la soglia capsule per avere il tuo regalo e il tuo accessorio preferito!${progressBarGifts}
${totalCapsulesOnCart}
CAMBIA REGALO E ACCESSORIO
` ); } } } } let targetPercentage = (100 * totalCapsulesOnCart) / capsulesNextLimit; document.querySelector( '.progress-bar-striped > div' ).style.width = targetPercentage + '%'; } else { $('#GWPICAProgressBarText').html( `${username},aggiungi altre ${ eligibleSelIDProperties.capsulesRequired - totalCapsulesOnCart } capsule per avere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
CHECKOUT
` ); } if (!eligibleSelIDProperties.isClubActionDriven) { if ( eligibleSelIDProperties.selID.indexOf('') !== -1 && eligibleSelIDProperties.capsulesRequired !== 0 ) { executeNoCANoSelIDUseCase(customerSelectedOL, false); } if (eligibleSelIDProperties.canChooseGift) { let allGiftableSKU = eligibleSelIDProperties.gifts .filter(function (n) { return n.capsulesRequired > totalCapsulesOnCart; }) .map((element) => element.sku); let allInCartSKU = customerCart.map((element) => element.id.replace('erp.it.b2c/prod/', '') ); let filteredSKUArray = allGiftableSKU.filter(function (n) { return allInCartSKU.indexOf(n) !== -1; }); let allCrosselableSKU = crossellGift.map( (element) => element.sku ); let filteredCrosselableSKUArray = allCrosselableSKU.filter( function (n) { return allInCartSKU.indexOf(n) !== -1; } ); if (filteredSKUArray.length !== 0) { if (filteredCrosselableSKUArray.length === 0) { Promise.resolve( CartManager.updateItem(filteredSKUArray[0], 0) ); } else { Promise.resolve( CartManager.updateItem(filteredSKUArray[0], 0).then( (e) => { setTimeout(() => { $.post( CartManager.updateItem( filteredCrosselableSKUArray[0], 0 ) ); }, 1000); } ) ); } } } } } else { if (eligibleSelIDProperties.canChooseGift) { eligibleSelIDProperties = eligibleSelIDProperties; let allGiftableSKU = eligibleSelIDProperties.gifts.map( (element) => element.sku ); let allInCartSKU = customerCart.map((element) => element.id.replace('erp.it.b2c/prod/', '') ); let filteredSKUArray = allGiftableSKU.filter(function (n) { return allInCartSKU.indexOf(n) !== -1; }); let allCrosselableSKU = crossellGift.map( (element) => element.sku ); let filteredCrosselableSKUArray = allCrosselableSKU.filter( function (n) { return allInCartSKU.indexOf(n) !== -1; } ); if (filteredSKUArray.length > 0) { if (filteredSKUArray.length > 1) { if (filteredCrosselableSKUArray.length === 0) { Promise.resolve( CartManager.updateItem(filteredSKUArray[0], 0) ); } else { Promise.resolve( CartManager.updateItem(filteredSKUArray[0], 0).then( (e) => { setTimeout(() => { $.post( CartManager.updateItem( filteredCrosselableSKUArray[0], 0 ) ); }, 1000); } ) ); } } setChangeGiftButton(filteredSKUArray[0]); } else { if (eligibleSelIDProperties.gifts.length === 1) { $('#GWPICAProgressBarText').html( `COMPLIMENTI ${username}!Hai raggiunto il numero di capsule necessario per ricevere ${eligibleSelIDProperties.gifts[0].name}!` ); $('#GWPICAProgressBarCTA').html( `
AGGIUNGI REGALO E ACCESSORIO
` ); } else { if (eligibleSelIDProperties.capsulesRequired !== 0) { $('#GWPICAProgressBarText').html( `COMPLIMENTI ${username}!Hai raggiunto il numero di capsule necessario per scegliere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
SCEGLI REGALO E ACCESSORIO
` ); } else { $('#GWPICAProgressBarText').html( `COMPLIMENTI ${username}!Hai raggiunto il numero di capsule necessario per scegliere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
SCEGLI REGALO E ACCESSORIO
` ); } } if (window.location.href.indexOf('checkout') !== -1) { openGiftSelectorPopup(); } } } else { $('#GWPICAProgressBarText').html( `COMPLIMENTI ${username}!Hai raggiunto il numero di capsule necessario per avere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
CHECKOUT
` ); } if (!eligibleSelIDProperties.isClubActionDriven) { if ( eligibleSelIDProperties.selID.indexOf('') !== -1 && !prospectAlreadyHadGift && eligibleSelIDProperties.capsulesRequired !== 0 ) { executeNoCANoSelIDUseCase(customerSelectedOL, true); } } } }); } function executeNoCANoSelIDUseCase(customerSelectedOL, positiveQuantity) { let techSelectedByCustomer = customerSelectedOL ? 'original' : 'vertuo'; let customerGiftBySelectedCapsulesTech = eligibleSelIDProperties.gifts.find( (element) => element.tech === techSelectedByCustomer ); if (positiveQuantity) { setChangeGiftButton(customerGiftBySelectedCapsulesTech.sku); CartManager.updateItem( customerGiftBySelectedCapsulesTech.sku, customerGiftBySelectedCapsulesTech.quantity ); prospectAlreadyHadGift = true; } else { Promise.resolve( CartManager.updateItem(customerGiftBySelectedCapsulesTech.sku, 0) ); prospectAlreadyHadGift = false; } } function setChangeGiftButton(sku) { if (eligibleSelIDProperties.capsulesRequired !== 0) { $('#GWPICAProgressBarText').html( `COMPLIMENTI ${username}!,Hai raggiunto il numero di capsule necessario per scegliere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
CAMBIA REGALO E ACCESSORIO
` ); } else { if (eligibleSelIDProperties.gifts.at(-1).sku === sku) { $('#GWPICAProgressBarText').html( `COMPLIMENTI ${username}!,Hai raggiunto il numero di capsule necessario per scegliere il tuo regalo e il tuo accessorio preferito!` ); $('#GWPICAProgressBarCTA').html( `
CAMBIA REGALO E ACCESSORIO
` ); } else { let progressBarGifts = ''; eligibleSelIDProperties.gifts .slice() //.reverse() .forEach((gift, index) => { progressBarGifts += `${ gift.capsulesRequired }
`; }); if ( totalCapsulesOnCart < eligibleSelIDProperties.gifts[0].capsulesRequired ) { $('#GWPICAProgressBarText').html( `${username}, raggiungi la soglia capsule per avere il tuo regalo e il tuo accessorio preferito!${progressBarGifts}
${totalCapsulesOnCart}
AGGIUNGI REGALO E ACCESSORIO
` ); } else { $('#GWPICAProgressBarText').html( `${username}, raggiungi la soglia capsule per avere il tuo regalo e il tuo accessorio preferito!${progressBarGifts}
${totalCapsulesOnCart}
CAMBIA REGALO E ACCESSORIO
` ); } let targetPercentage = (100 * totalCapsulesOnCart) / eligibleSelIDProperties.gifts.at(-1).capsulesRequired; document.querySelector('.progress-bar-striped > div').style.width = targetPercentage + '%'; } } } function changeGift(sku) { $('.GWPICA-progressBar-success').text('...'); let allInCartSKU = customerCart.map((element) => element.id.replace('erp.it.b2c/prod/', '') ); let allCrosselableSKU = crossellGift.map((element) => element.sku); let filteredCrosselableSKUArray = allCrosselableSKU.filter(function (n) { return allInCartSKU.indexOf(n) !== -1; }); if (filteredCrosselableSKUArray.length === 0) { Promise.resolve(CartManager.updateItem(sku, 0)).then(function () { openGiftSelectorPopup(totalCapsulesOnCart); }); } else { Promise.resolve( CartManager.updateItem(sku, 0).then((e) => { setTimeout(() => { $.post( CartManager.updateItem(filteredCrosselableSKUArray[0], 0) ); openGiftSelectorPopup(totalCapsulesOnCart); }, 1000); }) ); } } function addGiftToCart(sku, quantity) { if (sku !== 'none' && quantity !== 0) { $('#addGiftCTA-' + sku).text('...'); Promise.resolve(CartManager.updateItem(sku, quantity)).then( function () { $('#addGiftCTA-' + sku).text('AGGIUNGI'); setChangeGiftButton(sku); closeGiftSelectorPopup(); openCrossellSelectorPopup(); } ); } else { closeGiftSelectorPopup(); } gtmDataObject.push({ event: 'promoClick', ecommerce: { promoClick: { promotions: [ { creative: 'IT_coffeePLP_activationPromoBanner', id: trackingIDGWPICA + '-' + sku, name: trackingIDGWPICA + ' ' + sku, position: 'IT_nespresso_coffeePLP', }, ], }, }, }); } function addCrossellToCart(sku) { if (sku !== 'none') { $('#addCrossellCTA-' + sku).text('...'); Promise.resolve(CartManager.updateItem(sku, 1)).then(function () { $('#addCrossellCTA-' + sku).text('AGGIUNGI'); closeCrossellSelectorPopup(); }); } else { closeCrossellSelectorPopup(); } gtmDataObject.push({ event: 'promoClick', ecommerce: { promoClick: { promotions: [ { creative: 'IT_coffeePLP_activationPromoBanner', id: trackingIDGWPICA + '-' + sku, name: trackingIDGWPICA + ' ' + sku, position: 'IT_nespresso_coffeePLP', }, ], }, }, }); } function openGiftSelectorPopup(capsulesQuantityOnCart) { $('#nnes-statement-list').html(''); if (eligibleSelIDProperties.gifts.length === 1) { $('#nnes-statement-title').text('AGGIUNGI IL TUO OMAGGIO'); $('#nnes-statement-subtitle').text('Seleziona il tuo regalo:'); } eligibleSelIDProperties.gifts.forEach((selectedGift, index) => { if (capsulesQuantityOnCart === undefined) { document.getElementById('nnes-statement-list').insertAdjacentHTML( 'afterbegin', `
${selectedGift.name} ${selectedGift.description}
AGGIUNGI
AGGIUNGI
`; } else { addToCartGift = `DISPONIBILE CON ${selectedGift.capsulesRequired} CAPSULE
`; } document.getElementById('nnes-statement-list').insertAdjacentHTML( 'beforeend', `
${selectedGift.name} ${selectedGift.description}
${addToCartGift}
ACQUISTA A ${selectedCrossell.price}
`; document .getElementById('nnes-statement-list-crossell') .insertAdjacentHTML( 'afterbegin', `
${selectedCrossell.name} ${selectedCrossell.description}
${crossellAddToCartElement}