Cart
Introduction
This section will cover the basics of the cart and how to use it. We will also cover how to add, remove and clear products from the cart.
API Reference
You can find all available SAPCC module methods and their description in the API Reference.
Getting the cart
To get the cart, you can use the getCart method.
import { sdk } from '~/sdk';
const cart = await sdk.sapcc.getCart({
cartId: '00035084',
fields: 'code,guid,user(FULL)'
});
Adding products
To add a product to the cart, you can use the addCartEntry method.
import { sdk } from '~/sdk';
const cartModification = await sdk.sapcc.addCartEntry({
cartId: '00035084',
entry: {
quantity: 1,
product: { code: '1992695' }
}
});
Removing products
To remove a product from the cart, you can use the removeCartEntry method.
await sdk.sapcc.removeCartEntry({
cartId: '00035084',
entryNumber: 1
});
This method is removing the product from the cart by its entry number, but it does not return anything. If you need both to remove the entry and get an updated cart, you might want to use removeEntryAndGetCart
import { sdk } from '~/sdk';
const updatedCart = await sdk.sapcc.removeEntryAndGetCart({
cartId: '00035084',
entryNumber: 1
});
Clearing the cart
To clear the cart, you can use the deleteCart method. After the cart is cleared, you will need to create a new one.
import { sdk } from '~/sdk';
await sdk.sapcc.deleteCart({ cartId: '00035084' });