Integration Function
The Cart
integration function is the vendor-agnostic interface to
the cart provider. It is intended to be used in server components
or route handlers.
Do not try to instantiate the Cart()
function in client ("use client") components. Use the wrapping hooks provided in this package instead which expose these methods to the client.
Usage
Example usage:
import { Cart } from '@hv/cart';
...
const { createCart } = Cart({
locale: 'en-US',
});
const createCartResult = await createCart(cartDraft);
Reference
createCart
Create a cart for the current customer. Accepts a draft // TODO LINK to Typedoc? // of initial cart data.
getCart
Fetch a cart by id
getShippingMethods
Fetch the shipping methods applicable to the current cart and an optionally provided location
getCustomerCart
Query the for any cart associated to a particular customer. Useful for login logic and checking if the newly authenticated customer has an associated cart.
updateCart
Update top level attributes on the cart, such as
customerID
customerEmail
shippingMethodID
shippingAddress
billingAddress
updateLineItem
Update a line item on a cart
addToCart
Add a line item to a cart
removeFromCart
Remove a line item from a cart
addPromoCode
Add a promo code to a cart
removePromoCode
Remove a promo code from a cart
addPaymentToCart
Add a payment method to a cart
placeOrder
Place an order given from a cart
getOrder
Fetch an order from the cart provider, usually for order confirmation