define([ 'jquery', 'matchMedia', 'slick', 'domReady' ], function ($, mediaCheck) { 'use strict'; mediaCheck({ media: '(max-width: 768px)', entry: function () { $(document).on('click', '#layered-filter-block .block-title, .overlay-filter', function() { if($('body').hasClass('filter-open')) { $(this).parent().removeClass('active'); $('body').removeClass('filter-open'); } else { $(this).parent().addClass('active'); $('body').addClass('filter-open'); } }); var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.attributeName === 'class') { var hasClass = $('body').hasClass('ajax-loading'); if (hasClass) { $('#layered-filter-block').removeClass('filter-active'); $('body').removeClass('filter-open'); } } }); }); observer.observe(document.body, { attributes: true, attributeFilter: ['class'] }); }, exit: function () { $('body').removeClass('filter-open'); $('#layered-filter-block').removeClass('filter-active'); } }); function number_format(number, decimals, dec_point, thousands_sep) { // Strip all characters but numerical ones. number = (number + '').replace(/[^0-9+\-Ee.]/g, ''); var n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, dec = (typeof dec_point === 'undefined') ? '.' : dec_point, s = '', toFixedFix = function (n, prec) { var k = Math.pow(10, prec); return '' + Math.round(n * k) / k; }; // Fix for IE parseFloat(0.55).toFixed(0) = 0; s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.'); if (s[0].length > 3) { s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); } if ((s[1] || '').length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec); } $(function () { $(".price-box .old-price").each(function () { var old_price = $(this).find('.price').text(); var norma_price = $(this).siblings('span').find('.price').text(); old_price = old_price.replace('$', ''); old_price = old_price.replace(/\./g, ''); old_price = old_price.replace(/\,/g, ''); norma_price = norma_price.replace('$', ''); norma_price = norma_price.replace(/\./g, ''); norma_price = norma_price.replace(/\,/g, ''); var descuento = ((norma_price - old_price) / old_price * 100).toFixed(0); if ($('body').hasClass('catalog-product-view')) { $(this).parent().parent().append('
' + descuento + '%
'); } }); $('.product-item-details, .product-info-main').click(function () { $('.descount_ribbon').remove(); $(".price-box .old-price").each(function () { var old_price = $(this).find('.price').text(); var norma_price = $(this).siblings('span').find('.price').text(); old_price = old_price.replace('$', ''); old_price = old_price.replace(/\./g, ''); old_price = old_price.replace(/\,/g, ''); norma_price = norma_price.replace('$', ''); norma_price = norma_price.replace(/\./g, ''); norma_price = norma_price.replace(/\,/g, ''); var descuento = ((norma_price - old_price) / old_price * 100).toFixed(0); if ($('body').hasClass('catalog-product-view')) { $(this).parent().parent().find('.descount_ribbon').remove(); $(this).parent().parent().append('
' + descuento + '%
'); } }); }); //category Clases -- Force $('.amshopby-index-index,.catalogsearch-result-index,.catalog-category-view').find('.breadcrumbs').addClass('container_breadcrumbs'); $('.amshopby-index-index,.catalogsearch-result-index,.catalog-category-view').find('.breadcrumbs .items').addClass('col-12'); $('.amshopby-index-index,.catalogsearch-result-index,.catalog-category-view').find('.page-main').addClass('container'); $('.amshopby-index-index,.catalogsearch-result-index,.catalog-category-view').find('.page-main .columns').addClass('col-12'); //mobile product tittle if ($('body').hasClass('catalog-product-view')) { $(".catalog-product-view .product-data-container").clone().insertBefore(".catalog-product-view .product.media"); $(".catalog-product-view .product-info-main .product-reviews-summary").clone().insertBefore(".catalog-product-view .product.media"); } //minicart open on content load $('[data-block="minicart"]').on('contentLoading', function () { $('[data-block="minicart"]').on('contentUpdated', function () { $('[data-block="minicart"]').find('[data-role="dropdownDialog"]').dropdownDialog("open"); }); }); // slider home $('.slider_home').slick({ slidesToShow: 1, autoplay: true, autoplaySpeed: 2000, dots: true, arrows: false }); $('.um-prodslider .products.list.items').slick({ slidesToShow: 4, slidesToScroll: 4, dots: true, arrows: true, responsive: [ { breakpoint: 1024, settings: { slidesToShow: 3, slidesToScroll: 3, } }, { breakpoint: 768, settings: { slidesToShow: 2, slidesToScroll: 2 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1 } } ] }); $('.products-related .product-items, .products-crosssell .product-items, .products-upsell .product-items').slick({ slidesToShow: 5, slidesToScroll: 5, dots: true, arrows: false, responsive: [ { breakpoint: 1024, settings: { slidesToShow: 3, slidesToScroll: 3, } }, { breakpoint: 768, settings: { slidesToShow: 2, slidesToScroll: 2, arrows: false, dots: true, } }, { breakpoint: 480, settings: { slidesToShow: 2, slidesToScroll: 2, arrows: false, dots: true, } } ] }); $('.products-grid').each( function () { var num_slick = $('.item', this).length; if (num_slick <= 4) { { $(this).addClass('special_grid_slick') } } } ); //fix account region comuna en cuenta de usuario var delay_account = setInterval(function () { var region = $('body.account.customer-address-form').find('.field.region'); var attr = region.find('select').attr('style'); if (typeof attr !== typeof undefined && attr !== false) { region.show(); region.insertBefore('.field.city'); var comuna = $('body.account.customer-address-form').find('.field.city'); comuna.find('#city').attr('disabled', 'disabled'); region.find('#region_id').change(function () { if ($(this).val() != '') { comuna.find('#city').removeAttr('disabled'); } }); clearInterval(delay_account); } }, 500); var direccion = $('body.account.customer-address-form').find('.field.street'); direccion.find('.field.additional').find('label[for="street_2"] span').text('Número'); direccion.find('.field.additional').find('label[for="street_3"] span').text('Casa o Dep.'); var telefono = $('body.account.customer-address-form').find('.field.telephone'); if(telefono.length) { telefono.find('.control').addClass('input-group'); telefono.find('.control').prepend('
+56 9
'); telefono.find('input').addClass('form-control'); } var setValuePickupStore = setInterval(function () { if(!$('#checkout-loader').length && typeof $('select[name="is_pickup_store"]').val() != "undefined") { $('select[name="is_pickup_store"]').val('no').change(); clearInterval(setValuePickupStore); } }, 500); /// Campos de cuenta de registro usuario var formulario = $('body.customer-address-form').find('.form-address-edit'); var field_direccion = formulario.find('fieldset:last-of-type'); field_direccion.find('.field-giro').insertBefore('.field-name-firstname'); field_direccion.find('.field-rut').insertBefore('.field-giro'); field_direccion.find('.field-factura').insertBefore('.field.street'); if ($('.field-factura #factura').find('option:selected').text() == 'Sí') { formulario.find('.field-giro').show(); formulario.find('.field-rut').find('label').text('Rut Empresa'); formulario.find('.field-name-firstname').find('label').text('Razón Social'); formulario.find('.field-name-lastname #lastname').val('.').change(); formulario.find('.field-name-lastname').hide(); } if ($('.field-factura #factura').find('option:selected').text() == 'No') { formulario.find('.field-giro').hide(); formulario.find('.field-rut').find('label').text('Rut'); formulario.find('.field-name-firstname').find('label').text('Nombre'); formulario.find('.field-name-lastname #lastname').val('').change(); formulario.find('.field-giro #giro').val('').change(); formulario.find('.field-name-lastname').show(); } $('.field-factura #factura').change(function () { if ($(this).find('option:selected').text() == 'Sí') { formulario.find('.field-giro').show(); formulario.find('.field-rut').find('label').text('Rut Empresa'); formulario.find('.field-name-firstname').find('label').text('Razón Social'); formulario.find('.field-name-lastname #lastname').val('.').change(); formulario.find('.field-name-lastname').hide(); } if ($(this).find('option:selected').text() == 'No') { formulario.find('.field-giro').hide(); formulario.find('.field-rut').find('label').text('Rut'); formulario.find('.field-name-firstname').find('label').text('Nombre'); formulario.find('.field-name-lastname #lastname').val(''); formulario.find('.field-giro #giro').val('').change(); formulario.find('.field-name-lastname').show(); } }); $('.field-factura #factura').attr('selected', 'selected').change(); /// format Rut en cuenta usuario var $body = $('body'); function clearFormat(value) { return value.replace(/[\.\-]/g, ""); } function splitRutAndDv(rut) { var cValue = clearFormat(rut); if (cValue.length === 0) { return [null, null]; } if (cValue.length === 1) { return [cValue, null]; } var cDv = cValue.charAt(cValue.length - 1); var cRut = cValue.substring(0, cValue.length - 1); return [cRut, cDv]; } function format(value, useThousandsSeparator) { var rutAndDv = splitRutAndDv(value); var cRut = rutAndDv[0]; var cDv = rutAndDv[1]; if (!(cRut && cDv)) { return cRut || value; } var rutF = ""; var thousandsSeparator = useThousandsSeparator ? "." : ""; while (cRut.length > 3) { rutF = thousandsSeparator + cRut.substr(cRut.length - 3) + rutF; cRut = cRut.substring(0, cRut.length - 3); } return cRut + rutF + "-" + cDv; } $body.on('blur', '[name*=rut]', function () { var formattedRut = format($(this).val(), '.'); $(this).val(formattedRut).trigger('change'); }); // ocultar numeros de seleccion facturacion var delay_facturacion = setInterval(function () { if (!$('#checkout-loader').length) { if ($('.checkout-index-index .shipping-address-item').length) { $('.checkout-index-index .shipping-address-item, .checkout-index-index .shipping-information-content').each(function () { var texto_facturacion = $(this).html(); $(this).html(texto_facturacion.replace('8337', '')); $(this).html(texto_facturacion.replace('8338', '')); }); } clearInterval(delay_facturacion); } }, 500); }); (function() { const productDescription = $('.product-desc'); const btn = $('