In order to use Onward's Javascript SDK on a headless storefront, implement this interface and provide an instance when initializing Onward:
window.initializeOnward({
storefrontClient: new MyStorefrontClient(),
});addCartLines(
changes):Promise<Cart>
Adds line items to the cart.
Promise<Cart>
clearCart():
Promise<Cart>
Clears the current cart.
Onward uses this when adding the Onward product to make sure Onward is at the bottom of the cart by clearing the cart, adding the Onward product, then re-adding anything that was previously in the cart.
Promise<Cart>
fetchCart():
Promise<Cart>
Fetches the current cart, with all the items.
Promise<Cart>
fetchInsuranceProduct():
Promise<Product>
Fetches the insurance product from your storefront.
We recommend using a fixed url, such as the product handle, over an ID to be more resilent to the product being removed and re-added.
Promise<Product>
updateCartAttributes(
attributes):Promise<Cart>
Sets attributes on the cart.
Promise<Cart>
updateCartLines(
changes):Promise<Cart>
Updates a specific line item in the cart.
Used to set the quantity of specific items to 0 to remove a previous onward product for example.
Promise<Cart>