Broadleaf Microservices
  • v1.0.0-latest-prod

Cart Resolution

Overview

Carts are most often resolved by the ID provided as a path variable within an HTTP request to the API endpoint, for example, you can retrieve a cart using getCart. All cart operations resolve the cart by ID in the same way, by providing the Cart’s ID as part of the URL. In order to get a cart ID to operate upon, a cart must first be created using createCart. Creating a cart typically involves sending an initial add item request as well, but this is not always required. Once that cart is created, the cart can be operated upon using the various Cart Management APIs.

If a customer is registered and signed-in, then you can resolve their latest in-process cart using resolveCart. This operation will only work for requests authorized with a customer’s access token. If no cart is found, and a 404 is received, then a new cart must be created for the customer using createCart with the same access token.

CartResolverService

The CartResolverService is used for resolving a Cart by ID for ManageCartEndpoint, and resolving a registered customer’s latest cart for ResolveCartEndpoint.

CustomerRefHandlerMethodArgumentResolver

Resolves the CustomerRef parameter for controller methods that require it. This allows methods to be defined without explicit calls to Customer or Auth services to lookup a customers and ensure they are authenticated:

@PostMapping(value = "/cart/{cartId}/items", consumes = MediaType.APPLICATION_JSON_VALUE)
public Cart addItemToCart(
        @PathVariable String cartId,
        @RequestBody AddItemRequest addItemRequest,
        @Nullable CustomerRef customerRef,  // <--
        ...) {
    ...
}