function isMultiSpecification(specification) { if (specification.length > 1) { return true; } return false; } function getColor(color) { var x = color.split('_') if (x[1] != null) { var colorName = x[1].split('*') if (colorName[1] != null) { x[1] = colorName[0] + " " + colorName[1] } } return x } function formatNameSubcategory(name) { return name.charAt(0).toUpperCase() + name.slice(1).toLocaleLowerCase(); } function cropPrice(price) { return price.split(",")[0] } function currency(value, remove) { var price = typeof value === 'function' ? value() : value; if (remove) { price = removeLastTwoDigits(price); } return '$ ' + new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'COP', }).format(price); } function covertUnixToHumanDate(date) { return new Date(date).toLocaleDateString() } function checkNegativeSignCredit(v) { if (Math.sign(v) == -1 || Math.sign(v) == -0) { return true; } } /*function getIva(price, isRemove = false) { if (isRemove) { price = removeLastTwoDigits(price); } if (isTax != 0) { if (isRemove) { var priceStr = String(price); //var taxStr = String(isTax); var intPrice = priceStr.slice(0, priceStr.length - 2); var decPrice = priceStr.slice(priceStr.length - 2); //var intTax = taxStr.slice(0, taxStr.length - 2); //var decTax = taxStr.slice(taxStr.length - 2); var newDiscount = Number(intPrice + '.' + decPrice); //var newTax = Number(intTax + '.' + decTax); price = newDiscount; //isTax = newTax; isTax = price * 0.19; console.log(price) console.log(isTax); } if (manualIva) { isTax = price * 0.19; } return Math.round(price + isTax); } return newPrice; } */ function separateDetailImageProduct(image) { return image.split('*') } function getPercentDiscount(percent) { return `${percent} %`; } function checkFavoriteProductIcon() { try { if (localStorage.getItem('currentEmail')) { var all_wishlist = JSON.parse(localStorage.getItem('wishlist')); all_wishlist.forEach(function (w) { if (!w.is_deleted) { $('.handle-favorite').each(function () { if ($(this).attr('data-sku') == w.id_product) { $(this).parent().addClass('is-favorite'); } }) } }) } } catch (e) { } }; function checkFavoriteInView() { try { if (localStorage.getItem('currentEmail')) { var all_wishlist = JSON.parse(localStorage.getItem('wishlist')); all_wishlist.forEach(function (w) { if (!w.is_deleted) { if ($('#product-view').attr('data-id') == w.id_product) { $('.add-whislist-btn').html('Remover de mi lista de favoritos') } } }) } } catch (e) { } } function fnGetMetaContent(propName) { var metas = document.getElementsByTagName('meta'); for (var i = 0; i < metas.length; i++) { var name = metas[i].getAttribute("name"); if (name == propName) { return metas[i].getAttribute("content"); } } return ""; } var optionsShare = { title: encodeURIComponent(document.title), description: fnGetMetaContent('description') } var networks = { "facebook": { url: "https://www.facebook.com/sharer/sharer.php?u={url}&t={title}" }, "twitter": { url: "https://twitter.com/home?status={title} - {url}" }, "google": { url: "https://plus.google.com/share?url={url}" }, "linkedin": { url: "https://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}&summary={description}" }, "pinterest": { url: "http://pinterest.com/pin/create/button/?url={url}&media={media}&description={description}" }, "whatsapp": { url: "https://api.whatsapp.com/send?text={title} - {url}" }, "email": { url: "mailto:?SUBJECT={description}&BODY={url}" } } function helperProductShare(network, url, media) { var width = 550 var height = 550, w = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width, h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height, left = ((w / 2) - (width / 2)) + 10, top = ((h / 2) - (height / 2)) + 50, _url; switch (network) { case 'facebook': _url = networks.facebook.url.replace('{url}', url).replace('{title}', optionsShare.title) break; case 'twitter': _url = networks.twitter.url.replace('{url}', url).replace('{title}', optionsShare.title) break; case 'google': _url = networks.google.url.replace('{url}', url) break; case 'linkedin': _url = networks.linkedin.url.replace('{url}', url).replace('{title}', optionsShare.title).replace('{description}', optionsShare.description) break; case 'pinterest': _url = networks.pinterest.url.replace('{url}', url).replace('{media}', media).replace('{description}', optionsShare.description) break; case 'whatsapp': _url = networks.whatsapp.url.replace('{url}', url).replace('{title}', optionsShare.title) break; case 'email': window.location.href = networks.email.url.replace('{url}', url).replace('{description}', optionsShare.title) break; case 'copy': var aux = document.createElement("input"); aux.setAttribute("value", url); document.body.appendChild(aux); aux.select(); document.execCommand("copy"); document.body.removeChild(aux); break; } if (_url) window.open(_url, optionsShare.title, 'scrollbars=yes, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left); } function removeDuplicates(originalArray, prop) { var newArray = []; var lookupObject = {}; for (var i in originalArray) { lookupObject[originalArray[i][prop]] = originalArray[i]; } for (i in lookupObject) { newArray.push(lookupObject[i]); } return newArray; } //Obtenemos dos arrays de colores y los ordenamos por cantidad de productos disponibles. function getColorsByOrder(colors) { var skus = skuJson.skus; var newColorsArray = []; for (let i = 0; i < colors.length; i++) { for (let j = 0; j < skus.length; j++) { if (colors[i].name === skus[j].dimensions.Color) { if (skus[j].availablequantity === 0) { if (newColorsArray.length > 5) { colors[i].final = true; } else { colors[i].final = false; } if (newColorsArray > 0) { for (let k = 0; k < newColorsArray.length; k++) { const element = newColorsArray[k]; if (element.name === colors[i].name) { console.log(element); if (element.agotado !== false) { colors[i].agotado = true; } else { colors[i].agotado = false; } } } } else { colors[i].agotado = true; } if (newColorsArray.indexOf(colors[i]) === -1) { newColorsArray.push(colors[i]); } } else { colors[i].agotado = false; if (newColorsArray.length > 5) { colors[i].final = true; } else { colors[i].final = false; } if (newColorsArray.indexOf(colors[i]) === -1) { newColorsArray.unshift(colors[i]); } } } } } return newColorsArray; } const agregarComa = (cadena, caracter, pasos) => { let cadenaConCaracteres = ""; const longitudCadena = cadena.length; for (let i = 0; i < longitudCadena; i += pasos) { if (i + pasos < longitudCadena) { cadenaConCaracteres += cadena.substring(i, i + pasos) + caracter; } else { cadenaConCaracteres += cadena.substring(i, longitudCadena); } } console.log(cadenaConCaracteres); return cadenaConCaracteres; } function ConvertSquarePrice(price, factor) { let squareprice = price / parseFloat(factor); squareprice = squareprice.toFixed(0) let cadenarevertida = ""; squareprice = squareprice.toString() for (let i = squareprice.length - 1; i >= 0; i--) { cadenarevertida += squareprice[i]; } squareprice = agregarComa(cadenarevertida.toString(), '.', 3); cadenarevertida = ""; for (let i = squareprice.length - 1; i >= 0; i--) { cadenarevertida += squareprice[i]; } return "Precio en m2: $" + cadenarevertida; }