Class DefaultStaleCartItemsService

    • Constructor Detail

      • DefaultStaleCartItemsService

        public DefaultStaleCartItemsService()
    • Method Detail

      • removeStaleCartItems

        public com.broadleafcommerce.cart.client.domain.Cart removeStaleCartItems​(@NonNull
                                                                                  @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                  boolean price,
                                                                                  boolean updateCart,
                                                                                  @NonNull
                                                                                  @NonNull Map<String,​String> paymentLockTokens,
                                                                                  @Nullable
                                                                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: StaleCartItemsService
        Removes the CartItems from the cart if the appropriate product doesn't exist and creates the CartAlert about removed items.
        Specified by:
        removeStaleCartItems in interface StaleCartItemsService
        Parameters:
        cart - the cart to check the stale items
        price - whether or not to re-price the cart
        updateCart - whether or not to update Cart pricing and save the cart after the removal
        paymentLockTokens - Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.
        contextInfo - context information about sandboxing and multitenant state
        Returns:
        the cart without stale cart items
      • removeStaleCartItems

        public com.broadleafcommerce.cart.client.domain.Cart removeStaleCartItems​(@NonNull
                                                                                  @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                  @NonNull
                                                                                  @NonNull CatalogItemList<? extends CatalogItem> catalogItemList,
                                                                                  boolean price,
                                                                                  boolean updateCart,
                                                                                  @NonNull
                                                                                  @NonNull Map<String,​String> paymentLockTokens,
                                                                                  @Nullable
                                                                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: StaleCartItemsService
        Removes the CartItems from the cart if the appropriate product doesn't exist and creates the CartAlert about removed items.
        Specified by:
        removeStaleCartItems in interface StaleCartItemsService
        Parameters:
        cart - the cart to check the stale items
        catalogItemList - the list of the products for the cart items
        price - whether or not to re-price the cart
        updateCart - whether or not to update Cart pricing and save the cart after the removal
        paymentLockTokens - Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.
        contextInfo - context information about sandboxing and multitenant state
        Returns:
        the cart without stale cart items
      • removeStaleCartItems

        public com.broadleafcommerce.cart.client.domain.Cart removeStaleCartItems​(@NonNull
                                                                                  @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                  @NonNull
                                                                                  @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsToRemove,
                                                                                  boolean price,
                                                                                  boolean updateCart,
                                                                                  @NonNull
                                                                                  @NonNull Map<String,​String> paymentLockTokens,
                                                                                  @Nullable
                                                                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: StaleCartItemsService
        Removes the specified cart items from the cart and adds the CartAlert about removed items.
        Specified by:
        removeStaleCartItems in interface StaleCartItemsService
        Parameters:
        cart - the cart to check the stale items
        cartItemsToRemove - the list of the items to remove
        price - whether or not to re-price the cart
        updateCart - whether or not to update Cart pricing and save the cart after the removal
        paymentLockTokens - Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.
        contextInfo - context information about sandboxing and multitenant state
        Returns:
        the cart without stale cart items
      • getRemovedCartItems

        protected List<com.broadleafcommerce.cart.client.domain.CartItem> getRemovedCartItems​(@NonNull
                                                                                              @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> originalCartItems,
                                                                                              @NonNull
                                                                                              @NonNull com.broadleafcommerce.cart.client.domain.Cart updatedCart)
        Gets a list of removed CartItems based on the original list of items and the updated Cart.
        Parameters:
        originalCartItems - a list of CartItems before removing any items from Cart
        updatedCart - the updated Cart after items are removed
        Returns:
        a list of removed CartItems
      • buildCatalogItemNotFoundCartAlerts

        protected List<com.broadleafcommerce.cart.client.domain.CartAlert> buildCatalogItemNotFoundCartAlerts​(@NonNull
                                                                                                              @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems)
        Builds a list of CartAlerts indicating that the catalog item was not found from the given CartItems.
        Parameters:
        cartItems - a list of CartItems to build the CartAlerts from
        Returns:
        a list of CartAlerts indicating that the catalog item was not found for the given CartItems
      • buildCatalogItemNotFoundCartAlert

        protected com.broadleafcommerce.cart.client.domain.CartAlert buildCatalogItemNotFoundCartAlert​(@NonNull
                                                                                                       @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
        Builds a CartAlert indicating that the catalog item was not found.

        By default, this will create an alert of type `PRODUCT_NOT_FOUND`.

        Parameters:
        cartItem - the CartItem to build the CartAlert from
        Returns:
        the CartAlert indicating that the catalog item was not found
      • buildCatalogItemRequests

        protected Collection<CatalogItemRequest> buildCatalogItemRequests​(@NonNull
                                                                          @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                          @NonNull
                                                                          @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems,
                                                                          @Nullable
                                                                          com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      • catalogItemRequestAlreadyExist

        protected boolean catalogItemRequestAlreadyExist​(@NonNull
                                                         @NonNull Set<CatalogItemRequest> catalogItemRequests,
                                                         @NonNull
                                                         @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                                         @Nullable
                                                         com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Hook point to prevent duplicate CatalogItemRequests from being built based on the CartItem.

        By default, we filter on the product ID.

        Parameters:
        catalogItemRequests - the list of requests to pass to the CatalogProvider
        cartItem - the CartItem to build the CatalogItemRequest
        contextInfo - context information around sandbox and multitenant state
        Returns:
        true if building a new CatalogItemRequest would be a duplicate of an existing request in catalogItemRequests
      • buildCatalogItemRequest

        protected CatalogItemRequest buildCatalogItemRequest​(@NonNull
                                                             @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                                             @Nullable
                                                             com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Hook point to create the CatalogItemRequest and populate any additional attributes that should be passed to the CatalogProvider when fetching the catalog representation for the cart item.
        Parameters:
        cartItem - the CartItem to build the CatalogItemRequest
        contextInfo - context information around sandbox and multitenant state
        Returns:
        the populated CatalogItemRequest for the CartItem
      • identifyKeysForCatalogItems

        protected Set<String> identifyKeysForCatalogItems​(@NonNull
                                                          @NonNull CatalogItemList<? extends CatalogItem> catalogItemList,
                                                          @Nullable
                                                          com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Hook point to collect the keys that will identify the CatalogItems.
        Parameters:
        catalogItemList - the list of CatalogItems
        contextInfo - context information surrounding sandboxing and multitenant state
        Returns:
        the set of identifying keys for the catalog items
      • isCartItemMissingCatalogItems

        protected boolean isCartItemMissingCatalogItems​(@NonNull
                                                        @NonNull Set<String> catalogItemKeys,
                                                        @NonNull
                                                        @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                                        @Nullable
                                                        com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Hook point to determine if the CartItem does not have a backing CatalogItem for stale cart removal.

        By default, the keys are checked against the cart item's product ID.

        Parameters:
        catalogItemKeys - the set of identifying keys for the catalog items
        cartItem - the cart item to check
        contextInfo - context information surrounding sandboxing and multitenant state
        Returns:
        true if the cartItem does not have a backing CatalogItem
      • getMessage

        protected String getMessage​(@NonNull
                                    @NonNull String errorMessage,
                                    @Nullable
                                    Object... args)
      • setCartOperationService

        @Autowired
        @Lazy
        public void setCartOperationService​(CartOperationService cartOperationService)
      • setTypeFactory

        @Autowired
        public void setTypeFactory​(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
      • setMessageSource

        @Autowired
        public void setMessageSource​(org.springframework.context.MessageSource messageSource)
      • getMessageSource

        protected org.springframework.context.MessageSource getMessageSource()