createBasket
Creates a new basket.
This method communicates with the createBasket endpoint of the Vue Storefront API Middleware. In turn, it receives data from the createBasket or the Create basket endpoints exposed by SCAPI / OCAPI depending on the middleware configuration.
The created basket is initialized with default values. Data provided in the body document will be populated into the created basket. It can be updated with further Shop API calls.
Signature
export declare function createBasket(
props?: BasketCreateParams
): Promise<import("commerce-sdk/dist/checkout/checkout").ShopperBaskets.Basket>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Optional | BasketCreateParams | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
Returns
Returns a representation of a Basket object.
Referenced Types
BasketCreateParamsShopperBaskets.Basket
Examples
Create a basket by CategoryGetParams parameters.
import { sdk } from '~/sdk.config.ts';
const basket = await sdk.commerce.createBasket();Create a basket by CategoryGetParams parameters and add a product to the created basket.
import { sdk } from '~/sdk.config.ts';
import type { BasketProductAddParams } from '@vsf-enterprise/sfcc-types';
const productItems: BasketProductAddParams[] = [
{
quantity: 1,
productId: '001'
},
{
quantity: 1,
productId: '002'
}
];
const basket = await sdk.commerce.createBasket({
productItems
});Create a basket by CategoryGetParams parameters and add a gift certificate line item to the created basket.
import { sdk } from '~/sdk.config.ts';
import type { BasketProductAddParams } from '@vsf-enterprise/sfcc-types';
const giftCertificateItems: BasketGiftCertificateAddParams[] = [{
amount: 100,
recipientEmail: 'testEmail@provider.com'
}];
const basket = await sdk.commerce.createBasket({
giftCertificateItems
});