You are reading the documentation for v7.x and earlier, which is no longer the latest version. Switch to v8.x
addCartVoucher
Method adding voucher to the cart in SAP Commerce Cloud.
This method sends a POST request to the addVoucherToCart endpoint of the Alokai Middleware. In turn, it exchanges data with the doApplyCartVoucher endpoint exposed by the SAP OCC API Cart Promotions Controller.
This method will work for all types of carts (anonymous, user and guest). In case of guest and anonymous carts, remember to pass cart guid as the cartId param. In case of a current user cart, pass cart code instead.
Signature
export declare function addCartVoucher<Props extends AddVoucherToCartProps = AddVoucherToCartProps>(
props: Props,
options?: MethodOptions
): Promise<void>;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
This method does not return anything.
Referenced Types
Examples
Adding voucher to the cart.
import { sdk } from '~/sdk';
await sdk.commerce.addCartVoucher({ cartId: '00035084', voucherId: 'springfestival' });