Fechar
Carrinho de Compras
Carrinho Vazio

Utilizamos cookies para melhorar a sua experiência em nosso site. Ao continuar navegando você concorda com a nossa política de privacidade.

CONTINUAR E FECHAR
','text/html'));if(r.ok)return{items:r.items,max:r.max,pag:r.pag}}var r2=extrai(new DOMParser().parseFromString(html,'text/html'));return{items:r2.items,max:r2.max,pag:r2.pag}}function getPage(n){if(n===1&&usaDom){if(!pg1)pg1=domPg1();return Promise.resolve(pg1)}return fetch(pageUrl(n),{credentials:'same-origin'}).then(function(r){if(r.status>=500)throw new Error('HTTP '+r.status);return lerHtml(r)}).then(ler)}function load(){try{var r0=JSON.parse(sessionStorage.getItem(key));if(r0&&r0.all&&r0.all.length&&Date.now()-r0.t<600000)return Promise.resolve(r0)}catch(e){}function norm(s){return String(s).normalize('NFC').replace(/\s+/g,' ').trim().toLowerCase()}function total(){try{var m=document.documentElement.innerHTML.match(/"category":"((?:[^"\\]|\\.)*)","idCategory":"\d+","quantity"/);if(!m)return 0;var nm=norm(JSON.parse('"'+m[1]+'"')),n=0;[].slice.call(document.querySelectorAll('li.filter__item')).forEach(function(l){var e=l.querySelector('.filter__name');if(e&&norm(e.textContent)===nm){var x=(l.textContent.match(/\((\d+)\)/)||[])[1];if(x)n=+x}});return n}catch(e){return 0}}function more(n,acc,per){var b=[];for(var k=0;k<4;k++)b.push(getPage(n+k));return Promise.all(b).then(function(rs){var end=false;rs.forEach(function(p){if(end)return;acc=acc.concat(p.items);if(!p.items.length||p.items.length60)?acc:more(n+4,acc,per)})}function save(all,per){var seen={},u=[];all.forEach(function(it){if(!seen[it.pid]){seen[it.pid]=1;u.push(it)}});var r={t:Date.now(),per:per,all:u};if(u.length)try{sessionStorage.setItem(key,JSON.stringify(r))}catch(e){}return r}var cnt=total(),perG=grid.querySelectorAll('.product[data-pid]').length,N=0;if(cnt&&perG&&pg===1)N=Math.ceil(cnt/perG);if(N){var ps=[];for(var n=1;n<=Math.min(N,40);n++)ps.push(getPage(n));return Promise.all(ps).then(function(pages){var per=pages[0].items.length||perG,all=[];pages.forEach(function(p){all=all.concat(p.items)});var last=pages[pages.length-1].items.length,temMais=pages.some(function(p){return p.max>N||(!p.pag&&p.items.length>=per)});return(per&&last>=per&&N<40&&temMais?more(N+1,[],per):Promise.resolve([])).then(function(rest){return save(all.concat(rest),per)})})}return getPage(1).then(function(p1){var per=p1.items.length;return(p1.max>1?more(2,[],per):Promise.resolve([])).then(function(rest){return save(p1.items.concat(rest),per)})})}load().then(function(r){var byPid={},used={},first=[];r.all.forEach(function(it){byPid[it.pid]=it});ids.forEach(function(id){if(byPid[id]&&!used[id]){used[id]=1;first.push(byPid[id])}});var order=first.concat(r.all.filter(function(it){return !used[it.pid]})),per=r.per||18,slice=order.slice((pg-1)*per,pg*per);window.BFF_ORDEM_LISTA={order:order,per:per,pg:pg};if(!slice.length)return;var cur={},extra=[];[].slice.call(grid.children).forEach(function(li){var p=li.querySelector('.product[data-pid]');if(p){cur[p.getAttribute('data-pid')]=li;extra.push(p.getAttribute('data-pid'));grid.removeChild(li)}});var tpl=document.createElement('template'),noSlice={};slice.forEach(function(it){noSlice[it.pid]=1;var li=cur[it.pid];if(!li){tpl.innerHTML=it.html.trim();li=tpl.content.firstElementChild}grid.appendChild(li)});/* pecas que o Carregar mais ja trouxe antes da ordem ficar pronta continuam na tela (20/10) */extra.forEach(function(pid){if(!noSlice[pid]&&!inicial[pid]&&cur[pid]){noSlice[pid]=1;grid.appendChild(cur[pid])}});try{if(window.LazyLoad)new LazyLoad({elements_selector:'.lazyload'})}catch(e){}window.dispatchEvent(new Event('scroll'))}).catch(function(e){console.warn('BFF ordem manual:',e)}).then(function(){clearTimeout(fail);done();window.BFF_ORDEM_PRONTO=true;try{window.dispatchEvent(new Event('bffordem:pronto'))}catch(e){}})}catch(e){console.warn('BFF ordem manual:',e);window.BFF_ORDEM_PRONTO=true;try{window.dispatchEvent(new Event('bffordem:pronto'))}catch(x){}}})();