SDK Example: Add to Cart with No Configuration Changes (Fall '20)

Use the example SDK code in this topic to add an already configured item to a cart.

// Instantiate the input object for addToCart to specify parameters
const input = digitalCommerce.createAddToCartInput();
input.catalogCode = "Mobiles"; // use your Catalog Code
input.basketAction = "AddWithNoConfig"; // adding an offer that has not been configured (no change in its json structure from getOfferDetails) to cart
input.offerCode = "iPhone8Offer"; // use your Offer Code to be added to cart
input.customFields = ["customAttribute__c"]; // optional field which returns custom fields for given keys

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

Possible error conditions:

"AddTocartInput::getAPIPath() must have catalogCode."

"AddTocartInput::getAnonymousSiteRestUrl() must have catalogCode."

"AddTocartInput::getRequestPayload() must have basketAction."

"AddTocartInput::getRequestPayload() must have offerCode."

"AddTocartInput::getRequestPayload() must have offer when basketAction is 'AddWithNoConfig'."