<% 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 inlineTransformers = { formatNumber: formatNumber }; var defaultMatrixValues = splitMatrixTermsString(getProp(variables, 'defaultReleaseKey', '')); vars.matrixMaintenanceVariant = tplData.tplParams.matrixMaintenanceVariantExcludes; vars.currentMatrixTerm = defaultMatrixValues.term; vars.currentMatrixMileage = formatNumber(defaultMatrixValues.mileage); vars.currentMatrixDeposit = formatNumber(defaultMatrixValues.deposit); if (!!tplData.tplParams.reLeasePricePrefix && !tplData.tplParams.displayPriceFinance && !!variables.matrixReleasePrices) { vars.currentMatrixTerm = variables.matrixReleasePrices.term; vars.currentMatrixMileage = formatNumber(variables.matrixReleasePrices.mileage); vars.currentMatrixDeposit = formatNumber(variables.matrixReleasePrices.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')); const leasingTypePriceSuffix = getProp(vars, 'matrixReleasePrices.leasingType') === 'b2b' ? 'Net' : 'Gross'; vars.currentMinimumLeasingPrice = formatNumber(getProp(vars, 'matrixReleasePrices.minimumLeasingPrice' + leasingTypePriceSuffix)); vars.currentTotalLeasingPrice = formatNumber(getProp(vars, 'matrixReleasePrices.totalLeasingPrice' + leasingTypePriceSuffix)); vars.financeMonthlyPriceGrossFormatted = formatNumber(getProp(vars, 'financeMonthlyPriceGross')); vars.financeMonthlyPriceNetFormatted = formatNumber(getProp(vars, 'financeMonthlyPriceNet')); vars.currentMinimumLeasingPriceFormatted = vars.currentMinimumLeasingPrice; vars.currentTotalLeasingPriceFormatted = vars.currentTotalLeasingPrice; return typeof text === 'string' ? text.replace(new RegExp("\{([^\{]+)\}", "g"), function(_unused, token) { var colonIndex = token.indexOf(':'); var transformerName = colonIndex !== -1 ? token.slice(0, colonIndex) : null; var varName = colonIndex !== -1 ? token.slice(colonIndex + 1) : token; var varValue = getProp(vars, varName, '-'); if (transformerName && inlineTransformers[transformerName]) { varValue = inlineTransformers[transformerName](varValue); } return varValue; }) : ''; } 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 getLeaseOnDemandPopupText() { return getCurrentUserPriceType() === 'Net' ? tplData.tplParams.leaseOnDemandPopupTextNet : tplData.tplParams.leaseOnDemandPopupText; } 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 matrixPriceObject = item.matrixReleasePrices || null; var matrixPreviousReleasePrice = matrixPriceObject ? matrixPriceObject['previousRentalStandard' + getCurrentUserPriceType()] : null; var showOldReLeasePrice = tplData.tplParams.allowOldPrices && tplData.tplParams.apiQueryPurchaseOption == 'release' && (item.previousReLeasePriceGross > 0 || (!!matrixPreviousReleasePrice && matrixPreviousReleasePrice > 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; } function checkDisplayRule(displayRuleString, values) { var filterToParamMap = { makes: 'make', models: 'model', gearboxes: 'gearbox', colors: 'colour', bodyTypes: 'bodyType', energies: 'fuelType' }; var res = true; values.purchaseOptionExact = values.purchaseOption; if (displayRuleString) { var negatedKeys = {}; var normalizedRuleString = displayRuleString.replace(/(\w+)!=/g, function(_, key) { negatedKeys[key] = true; return key + '='; }); var params = {}; normalizedRuleString.split('&').forEach(function(part) { var eqIdx = part.indexOf('='); if (eqIdx === -1) return; var key = decodeURIComponent(part.slice(0, eqIdx)); var val = decodeURIComponent(part.slice(eqIdx + 1)); var parsed = val.split(',').map(function(v) { var n = Number(v); return isNaN(n) || v === '' ? v : n; }); params[key] = parsed.length === 1 ? parsed[0] : parsed; }); function getNestedValue(obj, path, defaultVal) { var keys = path.split('.'); var current = obj; for (var i = 0; i < keys.length; i++) { if (current == null || typeof current !== 'object') return defaultVal !== undefined ? defaultVal : undefined; current = current[keys[i]]; } return current !== undefined ? current : (defaultVal !== undefined ? defaultVal : undefined); } Object.keys(params).forEach(function(filterName) { if (!res) return; var paramValue = params[filterName]; var paramName = getNestedValue(filterToParamMap, filterName, filterName); var dataValue = String(getNestedValue(values, paramName, '')); var isNegated = !!negatedKeys[filterName]; var doesMatch = function(a, b) { var matched = a === b; return isNegated ? !matched : matched; }; var matchFailed = function() { res = false; }; if (paramName === 'priceType' || paramName === 'priceTypeSale') { if (!doesMatch(String(paramValue).toLowerCase(), getCurrentUserPriceType().toLowerCase())) { matchFailed(); } } else if (paramName === 'segment') { if (!doesMatch(String(paramValue).toLowerCase(), getCurrentUserSegment().toLowerCase())) { matchFailed(); } } else if (paramName === 'purchaseContext') { if (!doesMatch(String(paramValue).toLowerCase(), getCurrentUserPurchaseType().toLowerCase())) { matchFailed(); } } else if (paramName === 'purchaseOption') { if (typeof paramValue === 'string' && typeof dataValue === 'string') { var containsValue = dataValue.toLowerCase().indexOf(paramValue.toLowerCase()) !== -1; if (isNegated ? containsValue : !containsValue) { matchFailed(); } } } else if (Array.isArray(paramValue)) { var lowerValues = paramValue.map(function(v) { return typeof v === 'string' ? v.toLowerCase() : v; }); var dataValueLower = typeof dataValue === 'string' ? dataValue.toLowerCase() : dataValue; var included = lowerValues.indexOf(dataValueLower) !== -1 || lowerValues.indexOf(dataValue) !== -1; if (isNegated ? included : !included) { matchFailed(); } } else if (typeof dataValue === 'string' && !doesMatch(paramValue, dataValue.toLowerCase())) { matchFailed(); } else if (typeof (paramValue !== dataValue) === 'string') { matchFailed(); } }); } return res; } %>
<% 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; } if (Array.isArray(tplData.tplParams.customCarBoxIcons) && tplData.tplParams.customCarBoxIcons.length) { tplData.tplParams.customCarBoxIcons.forEach(function(el) { if (checkDisplayRule(el.displayRule, item)) { %> <%= fillTextWithValues(el.label, item) %> <% } }); } else { 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 oldReleasePriceRaw = (matrixPreviousReleasePrice && matrixPreviousReleasePrice > 0) ? matrixPreviousReleasePrice : getOldReLeasePrice(item); var oldPriceToDisplay = showOldSalePrice ? formatCurrency(tplData.tplParams.currencyFormat, formatNumber(getOldSalePrice(item))) : formatCurrency(tplData.tplParams.currencyFormat, formatNumber(oldReleasePriceRaw)); 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) %>", "labelClose": "<%= tplData.tplParams.labelClose %>" } }' <% } %>> <% if (priceVariant === 'sale') { %> <%= formatCurrency(tplData.tplParams.currencyFormat, formatNumber(getSalePrice(item))) %> <%= getLabelVat() %> <% } %> <% if (tplData.tplParams.displayLeasing && priceVariant === 'release') { %> <% if (rentOnDemand) { %> <%= rentOnDemand %> <% if (getLeaseOnDemandPopupText()) { %> <% } %> <% } else { %> <%= !displayPriceFinance ? 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%> <%= !displayPriceFinance ? tplData.tplParams.reLeasePricePrefix : '' %> <% if (rentOnDemand) { %> <%= rentOnDemand %> <% if (getLeaseOnDemandPopupText()) { %> <% } %> <% } 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 %>
<% } %>
<% }); } %>