SDK Example: Delete a Child Product from the Basket (Fall '20)

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

// Instantiate the input object for AddToCartInput to specify parameters
const input = digitalCommerce.createAddToCartInput();
input.catalogCode = "Mobiles"; // use your Catalog Code
input.basketAction = "DeleteChildProduct"; // deleting an offer that was added to cart
input.actionParams = {
  lineItemKey: "d83f475a776049d21054c105e9d53ee9", // use your lineItemKey
  cartContextkey: "d80b2927f07938aefdc7e2e349e2ede7", // use your cartContextKey
  bundleContextKey: "c3a4590a2d231e7022e04e5eba539ead" // use your bundleContextKey};
input.customFields = ["customAttribute__c"]; // optional field which returns custom fields for given keys

// Invoke Basket API via method addToBasket()
digitalCommerce
  .addToCart(input)
  .then(response => {
    Logger.info(
      "Vlocity digital commerce addToCart with basketAction=DeleteChildProduct for anonymous user: " +
        JSON.stringify(response)
    );
  })
  .catch(error => {
    Logger.info(
      "addToBasket with basketAction=DeleteChildProduct for anonymous user rest call failed" +
        error
    );
  });

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'."