Close

Inicio de sesión

require(['jquery', 'domReady!'], function($) { function formatPriceWithThousands(price) { return price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.'); } function formatAllPrices() { $('.price, .regular-price, .special-price, [data-price-type]').each(function() { var $element = $(this); var text = $element.text(); var $class = $element.attr('class'); if ($element.hasClass('special-price')) { $element.removeClass('special-price').addClass('price').addClass('big-price'); } // Eliminar "Special Price " si está presente text = text.replace("Special Price ", ""); var priceMatch = text.match(/(\d{4,})/); if (priceMatch) { var formattedPrice = formatPriceWithThousands(priceMatch[1]); var newText = text.replace(priceMatch[1], formattedPrice); $element.text(newText); } }); } // Aplicar formato inicial setTimeout(function() { formatAllPrices(); }, 3000); // Observer para precios que se actualizan dinámicamente var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === 'childList' || mutation.type === 'characterData') { formatAllPrices(); } }); }); observer.observe(document.body, { childList: true, subtree: true, characterData: true }); // Escuchar actualizaciones específicas del minicart $('body').on('contentUpdated', '.block-minicart', function() { formatAllPrices(); }); // También puedes escuchar cuando cualquier AJAX termina $(document).ajaxComplete(function(event, xhr, settings) { if (settings.url.indexOf('sidebar') !== -1) { // minicart se actualiza vía 'sidebar' URL formatAllPrices(); } }); });