Class DefaultServletRequestCartResolver
java.lang.Object
com.broadleafcommerce.cartoperation.web.filter.resolver.DefaultServletRequestCartResolver
- All Implemented Interfaces:
ServletRequestCartResolver
The default cart resolver for servlet requests. This takes into consideration cart overrides
(specified as a header), CSR carts when using the "shop as customer" feature, carts determined
from a cookie, and carts determined from the users authentication.
Important note on cart resolution: with the OOB implementation, the resolved cart is editable by the user. Do not resolve any cart for which you do not intend to allow the user to modify. For example, you generally would not want to resolve a
Important note on cart resolution: with the OOB implementation, the resolved cart is editable by the user. Do not resolve any cart for which you do not intend to allow the user to modify. For example, you generally would not want to resolve a
DefaultCartStatuses.SUBMITTED
cart because
that would allow the user to change the items and cause discrepancy issues. This also works to
the favor of the
DefaultCartStatuses.SUBMISSION_IN_PROGRESS
by preventing modification to the cart while it is being checked out.-
Constructor Summary
ConstructorDescriptionDefaultServletRequestCartResolver
(CartOperationService cartOpService, CartTransferService cartTransferService, CartCookieIssuer cartCookieIssuer, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils, com.broadleafcommerce.data.tracking.core.context.ContextInfoWebRequestResolver contextInfoWebRequestResolver, RequestCartVersionResolver requestCartVersionResolver, CartValidationProperties cartValidationProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
applicationMatches
(com.broadleafcommerce.cart.client.domain.Cart cart, String applicationId) protected boolean
checkCartValidForCustomer
(com.broadleafcommerce.cart.client.domain.Cart cart) protected boolean
customerHasRightsToResolveCart
(com.broadleafcommerce.cart.client.domain.Cart cart) protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils
protected CartCookieIssuer
protected CartOperationService
protected CartTransferService
protected CartValidationProperties
protected com.broadleafcommerce.data.tracking.core.context.ContextInfoWebRequestResolver
protected RequestCartVersionResolver
Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCart
(jakarta.servlet.http.HttpServletRequest request) Resolve the cart for the given request.protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCartOverride
(jakarta.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCookieCart
(jakarta.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCookieOrRegisteredCart
(jakarta.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCsrCart
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected final <T> Optional<T>
resolveFirst
(Supplier<Optional<T>>... optionalSuppliers) Iterates through the optional suppliers and returns immediately after finding the first one that produces a value.protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveRegisteredCustomerCart
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
retrieveAnonymousCartById
(String cartId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected boolean
shouldTransferAnonymousCartOwnership
(com.broadleafcommerce.cart.client.domain.Cart anonymousCart, com.broadleafcommerce.cart.client.domain.Cart registeredCustomerCart) protected boolean
shouldValidateVersion
(jakarta.servlet.http.HttpServletRequest request) Determines whether or not the cart version should be validatedprotected com.broadleafcommerce.cart.client.domain.Cart
validateVersion
(jakarta.servlet.http.HttpServletRequest request, com.broadleafcommerce.cart.client.domain.Cart cart) Validates the version from the HTTP request, if present.
-
Constructor Details
-
DefaultServletRequestCartResolver
public DefaultServletRequestCartResolver(CartOperationService cartOpService, CartTransferService cartTransferService, CartCookieIssuer cartCookieIssuer, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils, com.broadleafcommerce.data.tracking.core.context.ContextInfoWebRequestResolver contextInfoWebRequestResolver, RequestCartVersionResolver requestCartVersionResolver, CartValidationProperties cartValidationProperties)
-
-
Method Details
-
resolveCart
public Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCart(jakarta.servlet.http.HttpServletRequest request) Description copied from interface:ServletRequestCartResolver
Resolve the cart for the given request. First check if there are any overrides for resolving a specific cart. By default, this comes in the form of a request header. Next, determine if there is an anonymous cart or a registered customer cart. If both are found, transfer anonymous cart ownership to the registered customer and that cart is returned. Then, if either are found, that cart is returned. If neither are found, no cart is returned.- Specified by:
resolveCart
in interfaceServletRequestCartResolver
- Parameters:
request
- The request to use to resolve the cart.- Returns:
- The cart resolved for the given request.
-
resolveCartOverride
protected Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCartOverride(jakarta.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
applicationMatches
protected boolean applicationMatches(com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable String applicationId) -
customerHasRightsToResolveCart
protected boolean customerHasRightsToResolveCart(com.broadleafcommerce.cart.client.domain.Cart cart) -
resolveCsrCart
protected Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCsrCart(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
resolveCookieOrRegisteredCart
protected Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCookieOrRegisteredCart(jakarta.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
resolveCookieCart
protected Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCookieCart(jakarta.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
checkCartValidForCustomer
protected boolean checkCartValidForCustomer(com.broadleafcommerce.cart.client.domain.Cart cart) -
retrieveAnonymousCartById
-
shouldValidateVersion
protected boolean shouldValidateVersion(jakarta.servlet.http.HttpServletRequest request) Determines whether or not the cart version should be validated- Parameters:
request
- The request that may involve gathering or updating the cart- Returns:
- whether or not the cart version should be validated
-
validateVersion
protected com.broadleafcommerce.cart.client.domain.Cart validateVersion(jakarta.servlet.http.HttpServletRequest request, com.broadleafcommerce.cart.client.domain.Cart cart) Validates the version from the HTTP request, if present.- Parameters:
request
- the HTTP request to validate the cart version forcart
- the cart that was resolved for this request- Returns:
- the validated cart
- Throws:
StaleCartException
- when request version is out of date for enforced request methods
-
resolveRegisteredCustomerCart
protected Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveRegisteredCustomerCart(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
shouldTransferAnonymousCartOwnership
protected boolean shouldTransferAnonymousCartOwnership(com.broadleafcommerce.cart.client.domain.Cart anonymousCart, @Nullable com.broadleafcommerce.cart.client.domain.Cart registeredCustomerCart) -
resolveFirst
@SafeVarargs protected final <T> Optional<T> resolveFirst(Supplier<Optional<T>>... optionalSuppliers) Iterates through the optional suppliers and returns immediately after finding the first one that produces a value.- Type Parameters:
T
- whichever type to iterate through- Parameters:
optionalSuppliers
- the optional suppliers to iterate through- Returns:
- the optional from first optional supplier that produced a real value, or empty if none did
-
getOverrideCartHeaderName
- Specified by:
getOverrideCartHeaderName
in interfaceServletRequestCartResolver
-
getCartOpService
-
getCartTransferService
-
getCartCookieIssuer
-
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils() -
getContextInfoWebRequestResolver
protected com.broadleafcommerce.data.tracking.core.context.ContextInfoWebRequestResolver getContextInfoWebRequestResolver() -
getRequestCartVersionResolver
-
getCartValidationProperties
-