<% if(tplData.items.announcements.announcements.length) { function replaceLast(find, replace, string) { var lastIndex = string.lastIndexOf(find); if (lastIndex === -1) { return string; } var beginString = string.substring(0, lastIndex); var endString = string.substring(lastIndex + find.length); return beginString + replace + endString; }; function clone(obj) { if (obj === null || typeof (obj) !== 'object' || 'isActiveClone' in obj) { return obj; } if (obj instanceof Date) { var temp = new obj.constructor(); } else { var temp = obj.constructor(); } for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { obj['isActiveClone'] = null; temp[key] = clone(obj[key]); delete obj['isActiveClone']; } } return temp; } function formatNumber(value) { var fixedVal = value; var isFixed = false; // add trailing zeros if (Number(value) === value && value % 1 !== 0) { fixedVal = value.toFixed(2); isFixed = true; } var res = !!fixedVal ? fixedVal.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "): ""; if (tplData.tplParams.numberFormat === 'uk') { res = replaceLast(' ', ',', res); } else if (tplData.tplParams.numberFormat === 'nl') { res = replaceLast(' ', '.', res); } if (tplData.tplParams.pricesLayout === 'caixa') { res = !!fixedVal ? fixedVal.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."): ""; if (isFixed) { res = replaceLast('.', ',', res); } } return res; } function getProp( object, keys, defaultVal) { keys = Array.isArray( keys ) ? keys : keys.split('.'); object = object[keys[0]]; if( object && keys.length>1 ){ res = getProp( object, keys.slice(1) ); return res === undefined ? defaultVal : res; } return object === undefined ? defaultVal : object; } function splitMatrixTermsString(matrixTermsString) { if (!matrixTermsString || typeof matrixTermsString !== 'string') { return {}; } const matrixValues = matrixTermsString.split('_'); if (matrixValues.length === 4) { matrixValues.shift(); } if (matrixValues.length === 3) { var term = matrixValues[0]; var mileage = matrixValues[1]; var deposit = matrixValues[2]; return { term: term, mileage: mileage, deposit: deposit }; } return {}; }; function fillTextWithValues(text, variables) { var vars = clone(variables); var defaultMatrixValues = splitMatrixTermsString(getProp(variables, 'defaultReleaseKey', '')); vars.currentMatrixTerm = defaultMatrixValues.term; vars.currentMatrixMileage = formatNumber(defaultMatrixValues.mileage); vars.currentMatrixDeposit = defaultMatrixValues.deposit; if (vars.additionalData && vars.additionalData.Caixa_Finance_Duration) { vars.additionalData.Caixa_Finance_Duration = formatNumber(Number(getProp(variables, 'additionalData.Caixa_Finance_Duration'))); vars.additionalData.Caixa_Finance_IncludingInterests = formatNumber(Number(getProp(variables, 'additionalData.Caixa_Finance_IncludingInterests'))); vars.additionalData.Caixa_Finance_TAE = formatNumber(Number(getProp(variables, 'additionalData.Caixa_Finance_TAE'))); vars.additionalData.Caixa_Finance_TIN = formatNumber(Number(getProp(variables, 'additionalData.Caixa_Finance_TIN'))); vars.additionalData.Caixa_Finance_TotalCredit = formatNumber(Number(getProp(variables, 'additionalData.Caixa_Finance_TotalCredit'))); } vars.previousReLeasePriceGrossFormatted = formatNumber(getProp(vars, 'previousReLeasePriceGross')); vars.previousReLeasePriceNetFormatted = formatNumber(getProp(vars, 'previousReLeasePriceNet')); vars.previousSalePriceGrossFormatted = formatNumber(getProp(vars, 'previousSalePriceGross')); vars.previousSalePriceNetFormatted = formatNumber(getProp(vars, 'previousSalePriceNet')); vars.reLeasePrice2GrossFormatted = formatNumber(getProp(vars, 'reLeasePrice2Gross')); vars.reLeasePrice2NetFormatted = formatNumber(getProp(vars, 'reLeasePrice2Net')); vars.reLeasePrice3GrossFormatted = formatNumber(getProp(vars, 'reLeasePrice3Gross')); vars.reLeasePrice3NetFormatted = formatNumber(getProp(vars, 'reLeasePrice3Net')); vars.reLeasePriceGrossFormatted = formatNumber(getProp(vars, 'reLeasePriceGross')); vars.reLeasePriceNetFormatted = formatNumber(getProp(vars, 'reLeasePriceNet')); vars.salePriceGrossFormatted = formatNumber(getProp(vars, 'salePriceGross')); vars.salePriceNetFormatted = formatNumber(getProp(vars, 'salePriceNet')); vars.financeMonthlyPriceGrossFormatted = formatNumber(getProp(vars, 'financeMonthlyPriceGross')); vars.financeMonthlyPriceNetFormatted = formatNumber(getProp(vars, 'financeMonthlyPriceNet')); return typeof text === 'string' ? text.replace(new RegExp("\{([^\{]+)\}", "g"), function(_unused, varName){ return getProp(vars, varName, '-'); }) : ''; } function formatCurrency(format, value) { return fillTextWithValues(format, {value: formatNumber(value)}); }; function getFavourites() { var favArray = JSON.parse(localStorage.getItem('favourites')); return favArray && favArray.length ? favArray : []; } function checkFavourited(inputId) { var favArray = getFavourites(); var id = parseInt(inputId, 10); return favArray.indexOf(id) !== -1; } function ucFirst(string) { return string.charAt(0).toUpperCase() + string.slice(1); } function getCurrentUserPriceType() { var res; var defaultPriceType = tplData.tplParams.defaultPriceType === 'net' ? 'Net' : 'Gross'; if (tplData.tplParams.allowPriceTypeSwitch) { var type = localStorage.getItem('priceType'); if (typeof type === 'string' && type) { res = type.toLowerCase() === 'net' ? 'Net' : 'Gross'; } else { res = defaultPriceType; } } else { res = defaultPriceType; } return res; } function getSalePrice(data) { var type = getCurrentUserPriceType(); var pricePropName = 'salePrice' + type; return data[pricePropName]; } function getOldSalePrice(data) { var type = getCurrentUserPriceType(); var pricePropName = 'previousSalePrice' + type; return data[pricePropName]; } function getOldReLeasePrice(data) { var type = getCurrentUserPriceType(); var pricePropName = 'previousReLeasePrice' + type; return data[pricePropName]; } function getReLeasePrice(data) { var type = getCurrentUserPriceType(); var pricePropName = 'reLeasePrice' + type; return data[pricePropName]; } function getFinancePrice(data) { var type = getCurrentUserPriceType(); var pricePropName = type === 'Gross' ? 'financeMonthlyPriceGross' : 'financeMonthlyPriceNet'; return data[pricePropName]; } function getLabelLeasingMonthVat() { return getCurrentUserPriceType() === 'Net' ? tplData.tplParams.labelLeasingMonthVatNet : tplData.tplParams.labelLeasingMonthVat; } function getLabelVat() { return getCurrentUserPriceType() === 'Net' ? tplData.tplParams.labelPriceNet : tplData.tplParams.labelPrice; } function getLeasePopupText() { return getCurrentUserPriceType() === 'Net' ? tplData.tplParams.leasePopupTextNet : tplData.tplParams.leasePopupText; } function getFinancePopupText() { return getCurrentUserPriceType() === 'Net' ? tplData.tplParams.financePopupTextNet : tplData.tplParams.financePopupText; } function getPromoPopupText() { return getCurrentUserPriceType() === 'Net' ? tplData.tplParams.promoPopupTextNet : tplData.tplParams.promoPopupText; } function getPromoReLeasePopupText() { return getCurrentUserPriceType() === 'Net' ? tplData.tplParams.promoReLeasePopupTextNet : tplData.tplParams.promoReLeasePopupText; } function getCo2Level(co2Val) { var activeLevel = ''; switch (true) { case co2Val > 250: activeLevel = 'g'; break; case co2Val > 200: activeLevel = 'f'; break; case co2Val > 160: activeLevel = 'e'; break; case co2Val > 140: activeLevel = 'd'; break; case co2Val > 120: activeLevel = 'c'; break; case co2Val > 100: activeLevel = 'b'; break; default: activeLevel = 'a'; } return activeLevel; } tplData.items.announcements.announcements.forEach(function(item) { var appUrl = (window.config && window.config.slugs) ? window.config.slugs.app : '/'; var offersUrl = (window.config && window.config.slugs) ? window.config.slugs.offer : 'car'; var carSlug = ''; if (item.make) { carSlug += item.make; } if (item.model) { carSlug += '-' + item.model; } if (item.trim) { carSlug += '-' + item.trim; } if (item.id) { carSlug += '-' + item.id; } var itemUrl = tplData.tplParams.offerUrlPrefix + tplData.tplParams.slugify( carSlug.replace(/[*+,~.()'"/\\!:@#<>{}&^%$?;`|=_[\]]/g, ''), { lower: true, strict: true }); var favourited = checkFavourited(item.id); var imgSrc = item.mainImage && item.mainImage != null ? item.mainImage : tplData.tplParams.imgPlaceholderUrl; var badges = item.labels; var isPartner = !!item.partnerLogoUrl; var partnerLogoSrc = item.partnerLogoUrl; var displayPriceFinance = tplData.tplParams.displayPriceFinance; var showOldSalePrice = tplData.tplParams.allowOldPrices && tplData.tplParams.apiQueryPurchaseOption == 'sale' && item.previousSalePriceGross > 0; var showOldReLeasePrice = tplData.tplParams.allowOldPrices && tplData.tplParams.apiQueryPurchaseOption == 'release' && item.previousReLeasePriceGross > 0; var financeMonthlyPrice = getFinancePrice(item); var reLeasePriceGross = getReLeasePrice(item); var carPurchaseOption = item.purchaseOption; var rentOnDemand = item.leaseOnDemand ? tplData.tplParams.labelRentOnDemand : false; var priceAdditional; var priceVariant; if ( displayPriceFinance && financeMonthlyPrice > 0 && carPurchaseOption !== "release" ) { priceAdditional = financeMonthlyPrice; priceVariant = "saleandfinance"; } else if ( displayPriceFinance && financeMonthlyPrice === 0 && carPurchaseOption === "saleandrelease" ) { priceVariant = "sale"; } else { priceAdditional = reLeasePriceGross; priceVariant = carPurchaseOption; } %>
<%= item.make %> <%= item.model %> <% if (badges && badges.length) { %>
    <% badges.forEach(function(item) { var key = item.key || ''; var badgeClass = ''; switch (key.toLowerCase()) { case 'empty': badgeClass = 'hidden'; break; case 'comingsoon': badgeClass = 'badge--blue'; break; case 'reserved': badgeClass = 'badge--orange'; break; case 'sold': badgeClass = 'badge--orange'; break; default: badgeClass = ''; } %>
  • <%= item.label %>
  • <% }); %>
<% } %> <% if (!tplData.tplParams.hideLocations) { var location = !!item.locationDisplayName ? item.locationDisplayName : item.location; %> <%= location %> <% } %> <% if (isPartner) { %> <% } %>

<%= item.make %> <%= item.model %>

<%= item.trim %>

<% if (item.details) { if (tplData.tplParams.displayFreeDelivery !== false) { item.details.delivery = 'delivery'; } if (tplData.tplParams.displayWarranty === false || tplData.tplParams.displayCo2Pictograms === true) { delete item.details.warrantyMonths; } Object.keys(item.details).forEach(function(key) { if (item.details[key] != 0) { var iconName = ''; var label = item.details[key]; switch(key) { case 'fuelTypeLabel': iconName = 'fuel'; break; case 'gearbox': iconName = 'gearbox'; break; case 'registrationYear': iconName = 'calendar'; break; case 'mileage': iconName = 'mileage'; label = formatNumber(label) + ' ' + tplData.tplParams.labelMileage; break; case 'warrantyMonths': iconName = 'gurantee'; label = fillTextWithValues(tplData.tplParams.labelWarranty, {value: label}); break; case 'delivery': iconName = 'deliver'; label = tplData.tplParams.labelDelivery; break; } %> <%= label %> <% }}); }%> <% if (tplData.tplParams.displayCo2Pictograms === true) { var activeLevel = getCo2Level(item.co2); %>
<%= activeLevel.toUpperCase() %> <%= item.co2 %> g CO2/km
<% } %>
<% if (tplData.tplParams.pricesLayout == 'caixa') { %>
<%= formatNumber(priceAdditional) %> <%= tplData.tplParams.labelLeasingMonthVat %>1 <%= tplData.tplParams.labelPrice %> <%= fillTextWithValues(tplData.tplParams.matrixTermsInfo, item) %>
<% } else { %> <% if (showOldSalePrice || showOldReLeasePrice) { var priceToDisplay = showOldSalePrice ? getSalePrice(item) : getReLeasePrice(item); var oldPriceToDisplay = showOldSalePrice ? getOldSalePrice(item) : getOldReLeasePrice(item); oldPriceToDisplay = formatCurrency(tplData.tplParams.currencyFormat, formatNumber(oldPriceToDisplay)); priceToDisplay = formatCurrency(tplData.tplParams.currencyFormat, formatNumber(priceToDisplay)); var popupHeading = showOldSalePrice ? tplData.tplParams.promoPopupHeading : tplData.tplParams.promoReLeasePopupHeading; var popupText = showOldSalePrice ? getPromoPopupText() : getPromoReLeasePopupText(); popupHeading = fillTextWithValues(popupHeading, item); popupText = fillTextWithValues(popupText, item); %>
<%= oldPriceToDisplay %> <% if (showOldReLeasePrice) { %> <%= priceToDisplay %> <%= getLabelLeasingMonthVat() %> <% } else { %> <%= priceToDisplay %> <%= getLabelVat() %> <% } %>
<% } else { %>
data-fplugin="plugin-popup" data-fopts='{ "template": "<%= tplData.tplParams.leasePopupTemplate %>", "triggerSelector": ".fp-popup-trigger", "malihuScrollbar": "false", "coverClass": "modal-backdrop-fade", "tplData": { "popupHeading": "<%= priceVariant === 'saleandfinance' ? fillTextWithValues(tplData.tplParams.financePopupHeading, item) : fillTextWithValues(tplData.tplParams.leasePopupHeading, item) %>", "popupText": "<%= priceVariant === 'saleandfinance' ? fillTextWithValues(getFinancePopupText(), item) : fillTextWithValues(getLeasePopupText(), item) %>" } }' <% } %>> <% if (priceVariant === 'sale') { %> <%= formatCurrency(tplData.tplParams.currencyFormat, formatNumber(getSalePrice(item))) %> <%= getLabelVat() %> <% } %> <% if (tplData.tplParams.displayLeasing && priceVariant === 'release') { %> <% if (rentOnDemand) { %> <%= rentOnDemand %> <% } else { %> <%= tplData.tplParams.reLeasePricePrefix %> <%= formatCurrency(tplData.tplParams.currencyFormat, formatNumber(priceAdditional)) %> <%= getLabelLeasingMonthVat() %> <% } %> <% } %> <% if (tplData.tplParams.displayLeasing && (priceVariant === 'saleandrelease' || priceVariant === 'saleandfinance')) { %> <%=formatCurrency(tplData.tplParams.currencyFormat, formatNumber(getSalePrice(item)))%> <%= getLabelVat() %> <%=tplData.tplParams.labelLeasingOr%> <%= tplData.tplParams.reLeasePricePrefix %> <% if (rentOnDemand) { %> <%= rentOnDemand %> <% } else { %> <%= formatCurrency(tplData.tplParams.currencyFormat, formatNumber(priceAdditional)) %> <%= getLabelLeasingMonthVat() %> <% } %> <% } %>
<% } %> <% } %> <% var displayNote = (tplData.tplParams.pricesLayout == 'caixa' && item.reLeasePriceGross) || (tplData.tplParams.pricesLayout != 'caixa' && !!tplData.tplParams.carBoxNoteText && item.reLeasePriceGross); if (displayNote) { %>
1 <%= fillTextWithValues(tplData.tplParams.carBoxNoteText, item) %> <%= tplData.tplParams.carBoxNoteMore %>
<% } %>
<% }); } %>