SDK Example: Add a Child Product to the Basket (Fall ‘19)

Use the example SDK code in this topic to add a child product to 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 = "AddChildProduct"; // deleting an offer that was added to cart
5input.actionParams = {
6  rootProductCode: "iPhoneX", // use your rootProductCode
7  parentLineKey: "c3a4590a2d231e7022e04e5eba539ead", // use your parentLineKey
8  parentHierarchyPath: "01tf2000007Rb9JAAS", // use your parentHierarchyPath
9  offer: "DeclineEquipmentProtection", // use your offer_code
10  cartContextkey: "d80b2927f07938aefdc7e2e349e2ede7", // use your cartContextKey
11  bundleContextKey: "c3a4590a2d231e7022e04e5eba539ead" // use your bundleContextKey};
12input.customFields = ["customAttribute__c"]; // optional field which returns custom fields for given keys
13
14// Invoke Basket API via method addToBasket()digitalCommerce
15  .addToCart(input)
16  .then(response => {
17    Logger.info(
18      "Vlocity digital commerce addToCart with basketAction=AddChildProduct for anonymous user: " +
19        JSON.stringify(response)
20    );
21  })
22  .catch(error => {
23    Logger.info(
24      "addToBasket with basketAction=AddChildProduct for anonymous user rest call failed" +
25        error
26    );
27  });

Possible error conditions:

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

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

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

“AddToCartInput::getRequestPayload() must have rootProductCode when basketAction is ‘AddChildProduct’.”

“AddToCartInput::getRequestPayload() must have parentLineKey when basketAction is ‘AddChildProduct’.”

“AddToCartInput::getRequestPayload() must have parentHierarchyPath when basketAction is ‘AddChildProduct’.”

“AddToCartInput::getRequestPayload() must have offer when basketAction is ‘AddChildProduct’.”

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

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