Sergio Tacchini Men's Bottoms
{
loading = true;
const params = new URLSearchParams(window.location.search);
const newParams = new URLSearchParams(new FormData($refs.filter_form));
newParams.set('page', 1);
newParams.set('filter.v.availability', 1);
if(params.get('sort_by')){
newParams.set('sort_by', params.get('sort_by'));
}
fetch(`/collections/sergio-tacchini-mens-bottoms?${newParams.toString()}`)
.then(response => response.text())
.then(data => {
let html_div = document.createElement('div');
html_div.innerHTML = data;
// update product grid view
let html_dom = html_div.querySelector('#ProductGridContainer').innerHTML;
document.querySelector('#ProductGridContainer').innerHTML = html_dom;
// update filter view
let filters_dom = html_div.querySelector('#ProductFilters').innerHTML;
document.querySelector('#ProductFilters').innerHTML = filters_dom;
document.title = html_div.querySelector('title').textContent;
// update url without refreshing the page
history.replaceState(null, null, '?' + newParams.toString());
})
.catch(error => console.error('Error:', error))
.finally(() => loading = false);
})"
>