Use the example SDK code in this topic to add a child product to a basket.
// Instantiate the input object for AddToCartInput to specify parameters
const input = digitalCommerce.createAddToCartInput();
input.catalogCode = "Mobiles"; // use your Catalog Code
input.basketAction = "AddChildProduct"; // deleting an offer that was added to cart
input.actionParams = {
rootProductCode: "iPhoneX", // use your rootProductCode
parentLineKey: "c3a4590a2d231e7022e04e5eba539ead", // use your parentLineKey
parentHierarchyPath: "01tf2000007Rb9JAAS", // use your parentHierarchyPath
offer: "DeclineEquipmentProtection", // use your offer_code
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=AddChildProduct for anonymous user: " +
JSON.stringify(response)
);
})
.catch(error => {
Logger.info(
"addToBasket with basketAction=AddChildProduct 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 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'."