Refresh cart UI
What usually needs refreshing
Refresh after a cart change
async function updateCartQuantity(line, quantity) {
const cartDrawer = document.getElementById("Cart-Drawer");
const mainCart = document.getElementById("Main-Cart");
const sectionsToRender = [
{
id: "Cart-Icon-Bubble",
section: "cart-icon-bubble",
selector: ".shopify-section"
}
];
if (cartDrawer && !cartDrawer.hasAttribute("data-status-silence")) {
sectionsToRender.push({
id: "Cart-Drawer",
section: cartDrawer.dataset.section,
selector: "#Cart-Drawer-Details"
});
}
if (mainCart?.dataset.section) {
sectionsToRender.push({
id: "Main-Cart",
section: mainCart.dataset.section,
selector: "#Main-Cart-Details"
});
}
const response = await fetch(window.routes.cart_change_url, {
...webvista.fetchConfig(),
body: JSON.stringify({
line,
quantity,
sections: sectionsToRender.map((section) => section.section),
sections_url: window.location.pathname
})
});
const cartData = await response.json();
if (cartData.errors) {
console.error(cartData.errors);
return;
}
SectionDynamicUpdate.updateSections(sectionsToRender, cartData.sections);
webvista.publish(PUB_SUB_EVENTS.cartUpdate, {
source: "custom-cart-refresh",
cartData
});
}Refresh without changing cart contents
Open the cart drawer after refreshing
Notes
Last updated