Wishlist
Introduction
This section will cover the basics of the wishlist and how to use it. We will also cover how to add, remove and clear products from the wishlist.
SAP Commerce Cloud does not include wishlists functionality by default!
By default, the SAP Commerce Cloud does not provide any methods for managing the wishlist. As a workaround that does not require buying any additional extension, we can use the existing cart methods described in Basics: Cart guide.
API Reference
You can find all available SAPCC module methods and their description in the API Reference.
Getting the wishlist
To get the wishlist, you can use the getCart method.
import { sdk } from '~/sdk';
const wishlist = await sdk.sapcc.getCart({
cartId: '00035084',
fields: 'code,guid,user(FULL)'
});
Adding products
To add a product to the wishlist, you can use the addCartEntry method.
import { sdk } from '~/sdk';
const wishlistModification = await sdk.sapcc.addCartEntry({
cartId: '00035084',
entry: {
quantity: 1,
product: { code: '1992695' }
}
});
Removing products
To remove a product from the wishlist, you can use the removeCartEntry method.
await sdk.sapcc.removeCartEntry({
cartId: '00035084',
entryNumber: 1
});
This method is removing the product from the wishlist by its entry number. You get an updated wishlist, you might want to use removeEntryAndGetCart
import { sdk } from '~/sdk';
const updatedWishlist = await sdk.sapcc.removeEntryAndGetCart({
cartId: '00035084',
entryNumber: 1
});
Clearing the wishlist
To clear the wishlist, you can use the deleteCart method.
import { sdk } from '~/sdk';
await sdk.sapcc.deleteCart({ cartId: '00035084' });