SDK Example: Delete a Child Product from the Basket (Winter ‘20)

Use the example SDK code in this topic to delete a child product from a basket.

1// Instantiate the input object for AddToCartInput to specify parameters
2const input = digitalCommerce.createAddToCartInput();
3input.catalogCode = "Mobiles"; // use your Catalog Code
4input.basketAction = "DeleteChildProduct"; // deleting an offer that was added to cart
5input.actionParams = {
6  lineItemKey: "d83f475a776049d21054c105e9d53ee9", // use your lineItemKey
7  cartContextkey: "d80b2927f07938aefdc7e2e349e2ede7", // use your cartContextKey
8  bundleContextKey: "c3a4590a2d231e7022e04e5eba539ead" // use your bundleContextKey};
9input.customFields = ["customAttribute__c"]; // optional field which returns custom fields for given keys
10
11// Invoke Basket API via method addToBasket()
12digitalCommerce
13  .addToCart(input)
14  .then(response => {
15    Logger.info(
16      "Vlocity digital commerce addToCart with basketAction=DeleteChildProduct for anonymous user: " +
17        JSON.stringify(response)
18    );
19  })
20  .catch(error => {
21    Logger.info(
22      "addToBasket with basketAction=DeleteChildProduct for anonymous user rest call failed" +
23        error
24    );
25  });

Possible error conditions:

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

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

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

“AddToCartInput::getRequestPayload() must have lineItemKey when basketAction is ‘DeleteChildProduct’.”

“AddToCartInput::getRequestPayload() must have cartContextkey when basketAction is ‘DeleteChildProduct’.”

“AddToCartInput::getRequestPayload() must have bundleContextKey when basketAction is ‘DeleteChildProduct’.”