Broadleaf Microservices
  • v1.0.0-latest-prod

Cart Management

Resolve the authenticated customer’s cart

Operation

CartClient#resolveCart(options);

Parameters

Parameter Type Required? Description

options

ResolveCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration. Includes an optional list of cart statuses to resolve.

Response

This function returns a Cart.

Example

Example of resolving the authenticated customer’s cart
const cart = await cartClient.resolveCart({ accessToken });

console.log(cart);

Create a new cart

Operation

CartClient#createCart(cartCreationRequest, options);

Parameters

Parameter Type Required? Description

cartCreationRequest

CartCreationRequest

The request used to create a new cart.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a new Cart.

Example

Example of creating a new cart with one item
const createCartRequest: CartCreationRequest = {
  addItemRequest: {
    productId: 'product1',
    quantity: 1
  }
};

const cart = await cartClient.createCart(createCartRequest, { accessToken });

console.log(cart);

Get a cart by id

Operation

CartClient#getCart(cartId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart to retrieve.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of retrieving a cart by its id
const cart = await cartClient.getCart('CART_ID', { accessToken });

console.log(cart);

Add an item to a cart

Operation

CartClient#addItemToCart(cartId, addItemRequest, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

addItemRequest

AddItemRequest

The item request to add to the cart.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of adding an item to a cart
const cart = await cartClient.addItemToCart(
  'CART_ID',
  {
    productId: 'product1',
    quantity: 1
  },
  { accessToken }
);

console.log(cart);

Update an item in a cart

Operation

CartClient#updateItemInCart(cartId, updateItemRequest, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

updateItemRequest

UpdateItemRequest

The item request to update in the cart.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of updating the quantity of an item in a cart
const cart = await cartClient.updateItemInCart(
  'CART_ID',
  {
    cartItemId: 'CART_ITEM_ID',
    quantity: 2
  },
  { accessToken }
);

console.log(cart);

Remove an item from a cart

Operation

CartClient#removeItemFromCart(cartId, cartItemId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

cartItemId

string

The id of the cart item to remove.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of removing an item from the cart
const cart = await cartClient.removeItemFromCart('CART_ID', 'CART_ITEM_ID', { accessToken });

console.log(cart);

Add an attribute to a cart

Operation

CartClient#addAttributeToCart(cartId, addAttributeRequest, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

addAttributeRequest

AddAttributeRequest

The attribute to add to the cart.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of adding an attribute to a cart
const cart = await cartClient.addAttributeToCart(
  'CART_ID',
  { key: 'GIFT_MESSSAGE', value: 'Happy Birthday!' },
  { accessToken }
);

console.log(cart);

Remove an attribute from a cart

Operation

CartClient#removeAttributeFromCart(cartId, attributeKey, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

attributeKey

string

The attribute to remove from the cart.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of removing an attribute from a cart
const cart = await cartClient.removeAttributeFromCart('CART_ID', 'GIFT_MESSSAGE', { accessToken });

console.log(cart);

Get Fulfillment Options Available for Cart Items

Note
Since 1.5.3 (Release Train 1.8.2)

Gets the fulfillment options available for the items in the specified cart. This includes options for both per-item and per-group fulfillment strategies.

Operation

CheckoutClient#getFulfillmentOptionsForCartItems(cartId,  options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

Example

Example of retrieving available fulfillment options
const fulfillmentOptions = await checkoutClient.getFulfillmentOptionsForCartItems(
  'CART_ID',
  { accessToken }
);

console.log(cart);

Set the Selected Fulfillment Option for Group or Item

Note
Since 1.5.3 (Release Train 1.8.2)

Sends a request to set the preliminary fulfillment option for a fulfillment item or group in the cart. This can be changed during checkout.

Operation

CheckoutClient#selectFulfillmentOption(cartId, option, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

option

PricedFulfillmentOption

The option that was selected and the reference number of the fulfillment item or group it applies to.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

Example

Example of selecting a fulfillment option
const { cart, fulfillmentOptionResponse } = await checkoutClient.selectFulfillmentOption(
  'CART_ID',
  option,
  { accessToken }
);

console.log(cart, fulfillmentOptionResponse);

Get Fulfillment Options for Groups and Items

Note
Since 1.5.3 (Release Train 1.8.2)

Gets the fulfillment options available for the contents of the cart. May include the preliminary shipping address in the request.

Operation

CheckoutClient#determineOptionsAndGroups(cartId, address, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

address

FulfillmentAddress

The option that was selected and the reference number of the fulfillment item or group it applies to.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

Example

Example of determining the options and groups
const { cart, fulfillmentOptionResponse } = await checkoutClient.determineOptionsAndGroups(
  'CART_ID',
  address,
  { accessToken }
);

console.log(cart, fulfillmentOptionResponse);

Update a Fulfillment Group’s Address

Note
Since 1.5.3 (Release Train 1.8.2)

Sets a preliminary shipping address for a fulfillment group.

Operation

CheckoutClient#updateFulfillmentGroupAddress(cartId, request, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

request

UpdateFulfillmentGroupAddressRequest

request Request containing the fulfillment group reference number and the address.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

Example

Example of updating the fulfillment group address
const { cart, fulfillmentOptionResponse } = await checkoutClient.updateFulfillmentGroupAddress(
  'CART_ID',
  request,
  { accessToken }
);

console.log(cart, fulfillmentOptionResponse);

Get the Price Totals for Each Fulfillment Service Level Used

Note
Since 1.5.3 (Release Train 1.8.2)

Gets the combined total fulfillment price per service level of fulfillment options selected, e.g., the total price for Standard Shipping based on what items or groups it is selected for.

Operation

CheckoutClient#getTotalsForServiceLevels(cartId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

Returns a Map<string, MonetaryAmount> where the service-level id is the key.

Example

Example of getting the totals for each fulfillment service level
const response = await checkoutClient.getTotalsForServiceLevels(
  'CART_ID',
  { accessToken }
);

console.log(response);

Get the Fulfillment Pricing Configuration

Note
Since 1.5.3 (Release Train 1.8.2)

Retrieves the Fulfillment Pricing Config that informs the caller of the fulfillment pricing strategy (per group or item) to use and default service level.

Operation

CheckoutClient#getPricingConfig(options);

Parameters

Parameter Type Required? Description

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

Example

Example of getting the fulfillment pricing configuration
const config = await checkoutClient.getPricingConfig(
  { accessToken }
);

console.log(config);