For the complete documentation index, see llms.txt. This page is also available as Markdown.

Refresh cart UI

Use this guide when a custom script changes the cart and you need Ascent to refresh the visible cart UI.

What usually needs refreshing

Ascent cart UI is split into sections. A custom script usually refreshes one or more of these areas:

  • cart-icon-bubble: the cart icon count in the header.

  • Cart-Drawer: the shopping cart drawer content.

  • Main-Cart: the cart page content.

Refresh after a cart change

When your script changes the cart through Shopify Ajax endpoints, request the sections you want to refresh, then pass the returned HTML to Ascent's SectionDynamicUpdate.updateSections.

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

If another app changes the cart and your script only needs to redraw Ascent's cart UI, fetch the current cart first, then fetch the rendered sections.

Open the cart drawer after refreshing

Notes

  • Refresh sections after the cart request succeeds.

  • Always include cart-icon-bubble when the cart item count may have changed.

  • Do not force the drawer open on the cart page; Ascent marks it with data-status-silence.

  • If your script also adds a product, see the custom add-to-cart guide in this Developer section.

Last updated