A package for eCommerce sites that provides shopping cart functionality.
Provides and handles all the data for the cart.
Requires a ReactNode child. apiUrl
will be modified to end with /api/ecommerce/cart
. If the user object changes, the provider automatically logs in and out of the cart.
user={({ id: number | string } & any) | undefined}
apiUrl={string}
Allows all scopes under the CartProvider
to read from the cart data and the functions to modify the cart.
-
cart
:Cart
-
- Provides cart and authentication data.
-
addToCart
:(product: CartProduct) => void
-
- Adds a product to the cart.
-
removeFromCart
:(i: number) => void
-
- Removes an item from the cart at the given index.
-
clearCart
:() => void
-
- Clears the cart.
A frontend-facing component to display the cart contents in a Modal. This component is designed to go in a top navbar, ideally on the right-hand side.
This component is required to be in a CartProvider
scope.
The type of the cart
in CartContext.cart
.
{
cart: CartProducts[],
authentication: {loggedIn: boolean, user_id: string | number}
}
The type of the products listed in Cart.cart
.
{
id: number | string,
name: string,
quantity: number | undefined
}