addEntryAndGetCart
Method adding a product to the cart and getting the updated cart from SAP Commerce Cloud.
This method sends a POST request to the addCartEntry endpoint of the Alokai Middleware which composes responses from two other endpoints: addToCart and getCart. In turn, it exchanges data with two endpoints exposed by the SAP OCC API: createCartEntry and getCart.
When vsf-sap-token cookie is present in the browser, this method will add a product to the current user's cart. In case there is no cookie, it will add it to the anonymous user's cart. For logged-in users, make sure to pass cart code as the cartId param. In case of anonymous users, pass cart guid instead.
You might also want to see the addCartEntry method.
Signature
export declare function addEntryAndGetCart<Res extends Cart = Cart,
Props extends AddToCartProps = AddToCartProps>(
props: Props,
options?: MethodOptions
): Promise<Res>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Required | Props | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
options | Optional | MethodOptions | Options that can be passed to additionally configure the request or customize the logic in a plugin. |
Returns
Returns a representation of a Cart.
Referenced Types
Examples
Adding product to the cart.
import { sdk } from '~/sdk';
const updatedCart = await sdk.commerce.addEntryAndGetCart({
cartId: '00035084',
entry: {
quantity: 1,
product: { code: '1992695' }
}
});Adding product to the cart and selecting response fields.
import { sdk } from '~/sdk';
const updatedCart = await sdk.commerce.addEntryAndGetCart({
cartId: '00035084',
entry: {
quantity: 1,
product: { code: '1992695' }
},
fields: 'guid,entries(quantity,product(code))'
});Adding product to the cart and setting deliveryPointOfService.
import { sdk } from '~/sdk';
const updatedCart = await sdk.commerce.addEntryAndGetCart({
cartId: '00035084',
entry: {
quantity: 1,
product: { code: '1992695' },
deliveryPointOfService: { name: 'ap_warehouse_e' }
},
});