Class DefaultServletRequestCartResolver
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.web.filter.resolver.DefaultServletRequestCartResolver
-
- All Implemented Interfaces:
ServletRequestCartResolver
public class DefaultServletRequestCartResolver extends Object implements 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 aDefaultCartStatuses.SUBMITTED
cart because that would allow the user to change the items and cause discrepancy issues. This also works to the favor of theDefaultCartStatuses.SUBMISSION_IN_PROGRESS
by preventing modification to the cart while it is being checked out.
-
-
Constructor Summary
Constructors Constructor Description 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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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
getAuthenticationUtils()
protected CartCookieIssuer
getCartCookieIssuer()
protected CartOperationService
getCartOpService()
protected CartTransferService
getCartTransferService()
protected CartValidationProperties
getCartValidationProperties()
protected com.broadleafcommerce.data.tracking.core.context.ContextInfoWebRequestResolver
getContextInfoWebRequestResolver()
String
getOverrideCartHeaderName()
protected RequestCartVersionResolver
getRequestCartVersionResolver()
Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCart(javax.servlet.http.HttpServletRequest request)
Resolve the cart for the given request.protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCartOverride(javax.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCookieCart(javax.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCookieOrRegisteredCart(javax.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 <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(javax.servlet.http.HttpServletRequest request)
Determines whether or not the cart version should be validatedprotected com.broadleafcommerce.cart.client.domain.Cart
validateVersion(javax.servlet.http.HttpServletRequest request, com.broadleafcommerce.cart.client.domain.Cart cart)
Validates the version from the HTTP request, if present.
-
-
-
Constructor Detail
-
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 Detail
-
resolveCart
public Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCart(javax.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(javax.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(javax.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
resolveCookieCart
protected Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCookieCart(javax.servlet.http.HttpServletRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
checkCartValidForCustomer
protected boolean checkCartValidForCustomer(com.broadleafcommerce.cart.client.domain.Cart cart)
-
retrieveAnonymousCartById
protected Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveAnonymousCartById(String cartId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
shouldValidateVersion
protected boolean shouldValidateVersion(javax.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(javax.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
public String getOverrideCartHeaderName()
- Specified by:
getOverrideCartHeaderName
in interfaceServletRequestCartResolver
-
getCartOpService
protected CartOperationService getCartOpService()
-
getCartTransferService
protected CartTransferService getCartTransferService()
-
getCartCookieIssuer
protected CartCookieIssuer getCartCookieIssuer()
-
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()
-
getContextInfoWebRequestResolver
protected com.broadleafcommerce.data.tracking.core.context.ContextInfoWebRequestResolver getContextInfoWebRequestResolver()
-
getRequestCartVersionResolver
protected RequestCartVersionResolver getRequestCartVersionResolver()
-
getCartValidationProperties
protected CartValidationProperties getCartValidationProperties()
-
-