Skip to content

StorefrontClient

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(),
});

Methods

addCartLines()

addCartLines(changes): Promise<Cart>

Adds line items to the cart.

Parameters

changes

AddCartLineChange[]

Returns

Promise<Cart>


clearCart()

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.

Returns

Promise<Cart>


fetchCart()

fetchCart(): Promise<Cart>

Fetches the current cart, with all the items.

Returns

Promise<Cart>


fetchInsuranceProduct()

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.

Returns

Promise<Product>


updateCartAttributes()

updateCartAttributes(attributes): Promise<Cart>

Sets attributes on the cart.

Parameters

attributes

CartAttributes

Returns

Promise<Cart>


updateCartLines()

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.

Parameters

changes

UpdateCartLineChange[]

Returns

Promise<Cart>