`; } html += `
`; html += `
`+USPContent.text+`
`+interaction_html+`
`; html += interaction_html; html += `
`; html += interaction_html; html += `
`; data.forEach(function(item, index) { let css_class = item.show_mobile == false ? "hide_mobile": ""; switch(item.type){ case 'link': html += ``; html += item.text; html += ``; break; case 'popup': html += `
`; html += item.text; html += `
`; needPopup = true; break; } }); html += `
`; html += `
`; html += `
`; html += `
`; html += `
`; html += `
`; html += `
`; html += `
`; html += `
"+labellimited+"
"for (var i=0;i' + langAssets[bannerLanguage]["oldPraefix"] + ' ' + formatPrice(price) + '
').appendTo(bg_discount_container); $('' + discountData["label"][bannerLanguage] + '
').appendTo(bg_discount_container); if (discountData["percentage"]) { //calculate new Price console.log("calc percent") let newPrice = price - ((price / 100) * discountData["percentage"]); bg_discount_container.find(".newPrice .price").text(formatPrice(newPrice)); } if (discountData["fixedAmount"]) { //calculate new Price console.log("calc fixed") let newPrice = price - discountData["fixedAmount"]; bg_discount_container.find(".newPrice .price").text(formatPrice(newPrice)); } if (discountData["newPrice"]) { //just write the given price console.log("fixed") bg_discount_container.find(".newPrice .price").text(formatPrice(discountData["newPrice"])); } priceContainer.append(bg_discount_container); } function buildDiscountDomPageBuilder(currentCard, discountData){ console.log(discountData); let nodeName = currentCard.prop("nodeName"); switch(nodeName){ case "NB-SKU-ACCESSORY": case "NB-SKU-COFFEE": case "NB-SKU-MACHINE": //Page Builder Product Grid (NEXT V1) var priceContainerClass = "cb-price"; var priceCurrentClass = "cb-price-current"; var priceoldClass = "cb-price-old"; break; case "NB-PLP-PRODUCT-CARD": //Page Builder SKU Main Info (NEXT V1) var priceContainerClass = "cn_card__priceInnerWrapper"; var priceCurrentClass = "cn_card__priceWrapper--current"; var priceoldClass = "cn_card__priceWrapper--old"; break; case "NB-PLP-PRODUCT-CARD-EXPANDABLE": //Page Builder Product Slider Cross Sell (NEXT V1) var priceContainerClass = "plp-product-card-expandable__priceInnerWrapper"; var priceCurrentClass = "plp-product-card-expandable__price"; var priceoldClass = "cn_card__strikethroughPrice"; break; } let priceContainer = currentCard.find("."+priceContainerClass).first(); let priceCurrentContainer = currentCard.find("."+priceCurrentClass).first(); let price = getPriceIntFromElement(priceCurrentContainer); var priceNewContainer = priceCurrentContainer.clone().css("display", "block"); var priceOldContainer = priceCurrentContainer.clone().css("display", "block"); console.log(price); //console.log("----------"); //console.log(priceContainer); //console.log(priceCurrentContainer); //console.log("########"); //Now start modify priceCurrentContainer.hide(); //hide the original price container // modify new price container priceNewContainer.addClass("bg_rabatt_plp");//just some class to identify custom blaugrau stuff if(nodeName=="NB-PLP-PRODUCT-CARD-EXPANDABLE"){ priceNewContainer.html(""); priceNewContainer.prepend(""); }else{ priceNewContainer.find("span").addClass("price"); } priceNewContainer.prepend(""+langAssets[bannerLanguage]["newPraefix"]+""); //modify old price container priceOldContainer.addClass("bg_rabatt_plp");//just some class to identify custom blaugrau stuff priceOldContainer.removeClass(priceCurrentClass); priceOldContainer.addClass(priceoldClass); priceOldContainer.find("span").addClass("price"); priceOldContainer.prepend(""+langAssets[bannerLanguage]["oldPraefix"]+""); if (discountData["percentage"]) { //calculate new Price console.log("calc percent") let newPrice = price - ((price / 100) * discountData["percentage"]); priceNewContainer.find(".price").text(formatPrice(newPrice)); } if (discountData["fixedAmount"]) { //calculate new Price console.log("calc fixed") let newPrice = price - discountData["fixedAmount"]; priceNewContainer.find(".price").text(formatPrice(newPrice)); } if (discountData["newPrice"]) { //just write the given price console.log("fixed") priceNewContainer.find(".price").text(formatPrice(discountData["newPrice"])); } priceOldContainer.insertAfter(priceCurrentContainer); priceNewContainer.insertAfter(priceCurrentContainer); addCardLabel(currentCard, discountData["label"][bannerLanguage], discountData["labelColor"], discountData["labelBackground"] ); if( discountData["customButton"] ) { buildDiscountButtonDOM(currentCard, discountData); } } function buildDiscountButtonDOM(currentCard, discountData) { console.log("here, in button" ,whereWeAreVar.page_type, ) var ctaHTML, style; if (whereWeAreVar.page_type == "lp" && currentCard.find("nb-cta").length ) { if( currentCard.find(".addingCapsulesButton").length == 0 ) { ctaHTML = currentCard.find("nb-cta"); style = "border-radius: 3em;margin-top: 10px; margin-bottom: 10px; width: auto !important; padding: 1rem 1.5rem 0.875rem;position: initial !important;"; // ctaHTML.css("margin-bottom", "15px"); $('' + discountData["customButtonText"][bannerLanguage] + '').insertAfter(ctaHTML) } } else { if (whereWeAreVar.page_type == "lp") { ctaHTML = currentCard.find(".ProductListElement__details-link"); style = ""; } if (whereWeAreVar.page_type == "dp") { ctaHTML = currentCard.find(".ProductDetails__add-to-basket .AddToBagButton__container"); style = "float: left; position: initial !important;"; } ctaHTML.css("margin-bottom", "15px"); $('' + discountData["customButtonText"][bannerLanguage] + '').insertAfter(ctaHTML) } } function checkTiming(discountData) { //if timing is set if (typeof discountData.timingStart !== 'undefined' && typeof discountData.timingEnd !== 'undefined') { //check if is in range let startDate = discountData.timingStart != "" ? new Date(discountData.timingStart) : new Date(); let endDate = discountData.timingEnd != "" ? new Date(discountData.timingEnd) : new Date(8640000000000000); let debugDate = getDiscountDebug(); let currDate; //console.log(debugDate); if (!debugDate) { currDate = new Date(); } else { currDate = debugDate; } if ( currDate.getTime() >= startDate.getTime() && currDate.getTime() <= endDate.getTime() ) { return true; // timing set and inside range - show it } else { return false; // timing set and outside range - dint show it } } return true; // timing not set, show it } function formatPrice(price) { if (bannerLanguage == "de") { return "€ " + ("" + price.toFixed(2)).replace('.', ','); } if (bannerLanguage == "en") { return "€" + ("" + price.toFixed(2)); } } function getPriceIntFromElement(el) { if (bannerLanguage == "de") { return Number(el.text().replace(/[^0-9\.-]+/g, "")).toFixed(2) / 100; } if (bannerLanguage == "en") { return Number(el.text().replace(/[^0-9,-]+/g, "")).toFixed(2) / 100; } } function getLanguage() { napi.getConfig().then(function (e) { bannerLanguage = e.language; }); } function searchSKU(findSku) { //console.log("check sku "+findSku); return discounts.find(function (el) { if (isArray(el.sku)) { //console.log("is array"); //object has array of skus if (el.sku.includes(String(findSku))) { //console.log("includes sku"); //array includes current sku if (checkTiming(el)) { //console.log("inside timing"); //timing of object is within range return true; } else { //console.log("outside timing"); //timing of object is out of range return false; } } else { //console.log("doesnt include sku"); //array dosnt include current sku return false } } else { //object has string as sku if (el.sku == findSku) { //string includes current sku if (checkTiming(el)) { //timing of object is within range return true; } else { //timing of object is out of range return false; } } else { //string dosnt include current sku return false; } } }) } function whereAreWe() { var url = window.location.pathname; var urlEx = new RegExp('\/order\/(capsules|machines|accessories)\/(original|vertuo)(\/?)(.*)'); var matches = url.match(urlEx); console.log("##### WHERE ARE WE"); if (matches == null) { return { category: "capsules", subcategory: "vertuo", page_type: "lp" }; } // console.log("matches", matches); var product_cat = matches[1]; var sub_cat = matches[2]; var page_type; if (matches[4] == "") { // landing page page_type = "lp"; } else { // detail page page_type = "dp"; } return { category: product_cat, subcategory: sub_cat, page_type: page_type }; } function isArray(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; } function getDiscountDebug() { var params = new URLSearchParams(window.location.search); if (params.has('discountDebug')) { var debugDate = new Date(Date.parse(params.get('discountDebug'))); if (dateIsValid(debugDate)) return debugDate; return false; } return false; } function dateIsValid(date) { return date instanceof Date && !isNaN(date); } function addCardLabel(card, labelText, labelColor, labelBackground){ var label = $(''+labelText+''+labelText+''); console.log(label); if(card.find("nb-card-labels").length){ //card does already have a label card.find("nb-card-labels").append(label); }else{ //card doesnt have a label yet let labelContainer = $("'+t.display_name+"
2