SDK Example: Add to Cart with No Configuration Changes (Fall ‘19)

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

1// Instantiate the input object for addToCart to specify parameters
2const input = digitalCommerce.createAddToCartInput();
3input.catalogCode = "Mobiles"; // use your Catalog Code
4input.basketAction = "AddWithNoConfig"; // adding an offer that has not been configured (no change in its json structure from getOfferDetails) to cart
5input.offerCode = "iPhone8Offer"; // use your Offer Code to be added to cart
6input.customFields = ["customAttribute__c"]; // optional field which returns custom fields for given keys
7
8// Invoke Cart API via method addToCart()
9digitalCommerce
10  .addToCart(input)
11  .then(response => {
12    Logger.info(
13      "Vlocity digital commerce addToCart with basketAction=AddWithNoConfig for anonymous user: " +
14        JSON.stringify(response)
15    );
16    return response;
17  })
18  .catch(error => {
19    Logger.error(
20      "addToCart() with basketAction=AddWithNoConfig failed" + error
21    );
22  });

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’.”