SDK Example: Update Items in Basket (Winter ‘20)

Use the example SDK code in this topic to update items in a basket.

1// Instantiate the input object for AddToCartInput to specify parameters
2let input = Object.assign(
3  this.digitalCommerceSDK.createUpdateItemsInCartInput(),
4  {
5    catalogCode: "Phones",
6    basketkey: "01tf2000007Rb9JAAS",
7    basketAction: "updateBasket",
8    bundleContextKey: "",
9    lineItemKey: "",
10    quantity: 2,
11    customFields: ["customAttribute__c"]
12  }
13);
14this.digitalCommerceSDK
15  .updateItemsInCart(input)
16  .then(response => {
17    Logger.info(
18      "Vlocity digital commerce updateItemsInCart for anonymous user: " +
19        JSON.stringify(response)
20    );
21  })
22  .catch(error => {
23    Logger.info("updateItemsInCart action failed: ", error);
24  });

Possible error conditions:

“UpdateItemsInCart::getAPIPath() must have catalogCode.”

“UpdateItemsInCart::getAnonymousSiteRestUrl() must have catalogCode.”

“UpdateItemsInCart::getRequestPayload() must have basketAction.”

“UpdateItemsInCart::getRequestPayload() must have lineItemKey when basketAction is ‘updateBasket’.”

“UpdateItemsInCart::getRequestPayload() must have basketkey when basketAction is ‘updateBasket’.”

“UpdateItemsInCart::getRequestPayload() must have bundleContextKey when basketAction is ‘updateBasket’.”