Class 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 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.
    • 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 interface ServletRequestCartResolver
        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 for
        cart - 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
      • getAuthenticationUtils

        protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()
      • getContextInfoWebRequestResolver

        protected com.broadleafcommerce.data.tracking.core.context.ContextInfoWebRequestResolver getContextInfoWebRequestResolver()