Class DefaultCartService<P extends com.broadleafcommerce.cart.client.domain.Cart>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.cart.service.DefaultCartService<P>
All Implemented Interfaces:
CartService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>

public class DefaultCartService<P extends com.broadleafcommerce.cart.client.domain.Cart> extends com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P> implements CartService<P>
Author:
Chad Harchar (charchar)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final List<String>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultCartService(CartRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager mapper)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    create(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    void
    delete(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    protected int
    findCartItemIndex(com.broadleafcommerce.cart.client.domain.Cart cart, String itemId)
     
    protected String
    getApplicationId(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
     
    protected CartActionAuditService<com.broadleafcommerce.cart.client.domain.CartActionAudit>
     
     
    protected CartRequestValidator<com.broadleafcommerce.cart.client.domain.Cart>
     
    protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager
     
    protected CartRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
    protected com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper
     
    protected String
    getTenantId(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    protected void
    handleNotifications(P cart, com.broadleafcommerce.cart.client.domain.CartActionAudit audit, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Handles any additional notifications that should be sent after updating a cart.
    protected void
    handleQuoteNotifications(P cart, @NonNull com.broadleafcommerce.cart.client.domain.CartActionAudit audit, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Handles notifications for DefaultCartTypes.QUOTE carts.
    int
    purgeAbandonedAnonymousCarts(Duration abandonedCartTimeout, Collection<String> statuses, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Delete anonymous carts that have not been updated for the specified amount of time.
    org.springframework.data.domain.Page<P>
    readAll(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Read a page of narrowed Carts based on the given filters.
    org.springframework.data.domain.Page<P>
    readAllByStatusesAndCustomerIdAndAccountId(Set<String> statuses, String customerId, String accountId, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find all carts for the given customer id, account id, and statuses.
    readAllMatchingTenantByIds(List<String> ids, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds a list of the carts with the given ids and matching the tenant from the given ContextInfo.
    readAnonymousCustomerHistoricalOrder(String emailAddress, String orderNumber, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reads an anonymous or not authenticated customer's historical cart using the orderNumber and emailAddress.
    readAnonymousCustomerOrder(String cartId, String emailAddress, Set<String> allowedStatuses, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reads a cart by cartId and emailAddress excluding the customer owned carts.
    org.springframework.data.domain.Page<P>
    readByAccountHierarchyContaining(String accountId, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find all carts where the account hierarchy contains the given account id.
    org.springframework.data.domain.Page<P>
    readByAccountHierarchyContainingAndStatusIn(String accountId, @NonNull Iterable<String> statuses, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find all carts where the account hierarchy contains the given account id and has the matching status.
    org.springframework.data.domain.Page<P>
    readByCustomerId(String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, org.springframework.data.domain.Pageable page)
    Find all carts for the given customer id.
    org.springframework.data.domain.Page<P>
    readByCustomerIdAndAccountId(String customerId, String accountId, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find all carts for the given customer id and account id.
    org.springframework.data.domain.Page<P>
    readByCustomerIdAndAccountId(String customerId, String accountId, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find all carts for the given customer id and account id.
    readByCustomerIdAndOrderNumber(String customerId, String orderNumber, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find the cart (if it exists) for the provided customer id and order number.
    readByNameAndCustomerId(String cartName, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find the cart for the given name and customer id.
    readByNameAndCustomerRefCustomerId(String cartName, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Deprecated.
    org.springframework.data.domain.Page<P>
    readByRootAccountId(String rootAccountId, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find all carts for the given root account id.
    org.springframework.data.domain.Page<P>
    readByRootAccountIdAndStatusIn(String rootAccountId, @NonNull Iterable<String> statuses, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find all carts for the given root account id and statuses.
    readByStatus(String status, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all of the carts with the given status.
    readByStatusAndCustomerId(String status, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find a cart with the given status (if it exists) for the provided customer id.
    readByStatusAndCustomerIdAndAccountId(String status, String customerId, String accountId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find a cart with the given status (if it exists) for the provided customer id and account id.
    readByStatusAndCustomerIdAndAccountIdAndName(String status, String customerId, String accountId, String name, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find a cart with the given status (if it exists) for the provided customer id and account id.
    readCustomerOrder(String cartId, String customerId, Set<String> allowedStatuses, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reads a cart by cartId, customerId, & allowedStatuses.
    org.springframework.data.domain.Page<P>
    readExpiredQuotesByStatusNotIn(@NonNull Collection<String> statusesToExclude, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds a list of expired carts of type DefaultCartTypes.QUOTE, and a status not in the provided 'statuses' collection.
    org.springframework.data.domain.Page<P>
    readHistoricalCartsByCustomer(String customerId, Date startDate, Date endDate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, org.springframework.data.domain.Pageable page)
    Find all carts that are DefaultCartStatuses.SUBMITTED or DefaultCartStatuses.CANCELLED for the provided customer and dates.
    org.springframework.data.domain.Page<P>
    readPageMatchingTenantByStatus(String status, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds a page of the carts with the given status and matching the tenant from the given ContextInfo.
    replace(String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    replaceCartItem(P cart, String cartItemId, com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Replaces the cart item in the cart and saves.
    replaceWithCartAudit(String id, @NonNull UpdateCartRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Replaces the cart state and its related CartActionAudit.
    protected void
    saveConflictingImplicitCarts(@NonNull List<P> conflictingCarts, P cartToKeep, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    If there are multiple implicit carts (status: IN_PROCESS & name: null), then the customer's carts are in an unexpected & invalid state.
    void
    setCartActionAuditService(CartActionAuditService<com.broadleafcommerce.cart.client.domain.CartActionAudit> cartActionAuditService)
     
    void
     
    void
    setCartRequestValidator(CartRequestValidator<com.broadleafcommerce.cart.client.domain.Cart> cartRequestValidator)
     
    void
    setRsqlHelper(com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper rsqlHelper)
     
    void
    setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
     
    protected boolean
    shouldSendQuoteNotification(P cart, @NonNull com.broadleafcommerce.cart.client.domain.CartActionAudit audit)
    Determines whether quote notification should be sent.
    protected boolean
    shouldSendQuoteNotificationForCustomStatus(P cart, @NonNull com.broadleafcommerce.cart.client.domain.CartActionAudit audit)
    A hook point to handle any custom statuses or action types.
    protected com.broadleafcommerce.cart.client.domain.CartItem
    transformCartItem(P cart, String cartItemId, com.broadleafcommerce.cart.client.domain.CartItem cartItemPatch, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Applies a patch to a cart item.
    update(String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    updateCartItem(P cart, String cartItemId, com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Patches (updates only present fields) of the cart item in the cart and saves.
    updateCartsMatchingTenantStatus(List<String> cartIds, String status, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Updates the Cart.getStatus() for the given cart ids and status and matching the tenant from the given ContextInfo.
    updateWithCartAudit(String id, @NonNull UpdateCartRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Updates the cart state and its related CartActionAudit.

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService

    convertFromPersistentDomain, convertToPersistentDomain, createAll, createAllAllowingPartialSuccess, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

    createAll, createAllAllowingPartialSuccess, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, updateAll, updateAllAllowingPartialSuccess, updateSort
  • Field Details

    • HISTORICAL_STATUSES

      protected static final List<String> HISTORICAL_STATUSES
  • Constructor Details

    • DefaultCartService

      public DefaultCartService(CartRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager mapper)
  • Method Details

    • readAll

      public org.springframework.data.domain.Page<P> readAll(cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Read a page of narrowed Carts based on the given filters.
      Specified by:
      readAll in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      filters - the RSQL Node used to restrict result, must not be null
      pageable - the current page
      contextInfo - Request context information around sandbox and multitenant state
      Returns:
      a page of narrowed Carts based on the given filters
    • readByCustomerId

      public org.springframework.data.domain.Page<P> readByCustomerId(String customerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @Nullable org.springframework.data.domain.Pageable page)
      Description copied from interface: CartService
      Find all carts for the given customer id.
      Specified by:
      readByCustomerId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      customerId - the id of the customer who owns the cart
      contextInfo - Context information used to discriminate the carts by applicationId
      page - the requested page of results from the database
      Returns:
      all carts for the given customer id
    • readByCustomerIdAndAccountId

      public org.springframework.data.domain.Page<P> readByCustomerIdAndAccountId(String customerId, @Nullable String accountId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find all carts for the given customer id and account id. Account id can be null to find customer's personal non-account carts.
      Specified by:
      readByCustomerIdAndAccountId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      customerId - the id of the customer who owns the cart
      accountId - the id of the account that the cart belongs to,
      page - the requested page of results from the database
      contextInfo - context information related to multitenancy
      Returns:
      all carts for the given customer id and account id
    • readByCustomerIdAndAccountId

      public org.springframework.data.domain.Page<P> readByCustomerIdAndAccountId(String customerId, @Nullable String accountId, @Nullable org.springframework.data.domain.Pageable page, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find all carts for the given customer id and account id. Account id can be null to find customer's personal non-account carts.
      Specified by:
      readByCustomerIdAndAccountId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      customerId - the id of the customer who owns the cart
      accountId - the id of the account that the cart belongs to,
      page - the requested page of results from the database
      filters - RSQL filters
      contextInfo - context information related to multitenancy
      Returns:
      all carts for the given customer id and account id
    • readAllByStatusesAndCustomerIdAndAccountId

      public org.springframework.data.domain.Page<P> readAllByStatusesAndCustomerIdAndAccountId(Set<String> statuses, String customerId, @Nullable String accountId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find all carts for the given customer id, account id, and statuses. Account id can be null to find customer's personal non-account carts.
      Specified by:
      readAllByStatusesAndCustomerIdAndAccountId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      statuses - the statuses to match
      customerId - the id of the customer who owns the cart
      accountId - the id of the account that the cart belongs to
      page - the requested page of results from the database
      contextInfo - context information related to multitenancy
      Returns:
      all carts for the given customer id and account id and statuses
    • readByRootAccountId

      public org.springframework.data.domain.Page<P> readByRootAccountId(String rootAccountId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find all carts for the given root account id.

      This is useful to query all the carts that belongs to the same root account.

      For example, if we have this account setup, rootAcct -> subAcct (child of rootAcct) -> subSubAcct (child of subAcct), this query is useful to query all the carts that belong to the root account and its sub-accounts.

      Specified by:
      readByRootAccountId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      rootAccountId - the root account id of the cart
      page - the requested page of results from the database
      contextInfo - context information related to multitenancy
      Returns:
      all carts for the given root account id
    • readByRootAccountIdAndStatusIn

      public org.springframework.data.domain.Page<P> readByRootAccountIdAndStatusIn(String rootAccountId, @NonNull @NonNull Iterable<String> statuses, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find all carts for the given root account id and statuses.
      Specified by:
      readByRootAccountIdAndStatusIn in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      rootAccountId - the root account id of the cart
      statuses - the statuses to match
      page - the requested page of results from the database
      contextInfo - context information related to multitenancy
      Returns:
      all carts for the given root account id
    • readByAccountHierarchyContaining

      public org.springframework.data.domain.Page<P> readByAccountHierarchyContaining(String accountId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find all carts where the account hierarchy contains the given account id.

      This is useful to query all the carts that belongs to the same non-root account and its sub-accounts.

      For example, if we have this account setup, rootAcct -> subAcct (child of rootAcct) -> subSubAcct (child of subAcct), this query is useful to query all the carts that belong to the subAcct and its sub-accounts (subSubAcct in this case).

      Specified by:
      readByAccountHierarchyContaining in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      accountId - the account id to filter the account hierarchy by
      page - the requested page of results from the database
      contextInfo - context information related to multitenancy
      Returns:
      all carts where the account hierarchy contains the given account id
    • readByAccountHierarchyContainingAndStatusIn

      public org.springframework.data.domain.Page<P> readByAccountHierarchyContainingAndStatusIn(String accountId, @NonNull @NonNull Iterable<String> statuses, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find all carts where the account hierarchy contains the given account id and has the matching status.

      This is useful to query all the carts that belongs to the same non-root account and its sub-accounts based on the status

      For example, if we have this account setup, rootAcct -> subAcct (child of rootAcct) -> subSubAcct (child of subAcct), this query is useful to query all the carts that belong to the subAcct and its sub-accounts (subSubAcct in this case) and has the DefaultCartStatuses.REQUIRES_APPROVAL.

      Specified by:
      readByAccountHierarchyContainingAndStatusIn in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      accountId - the account id to filter the account hierarchy by
      statuses - the statuses to match
      page - the requested page of results from the database
      contextInfo - context information related to multitenancy
      Returns:
      all carts where the account hierarchy contains the given account id
    • readByNameAndCustomerId

      public Optional<P> readByNameAndCustomerId(String cartName, String customerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find the cart for the given name and customer id. There should only be one result, as cart names are unique per customer.
      Specified by:
      readByNameAndCustomerId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      cartName - the name of the cart to retrieve
      customerId - the id of the customer who owns the cart
      contextInfo - Context information used to discriminate the carts by applicationId
      Returns:
      an optional cart with the name and customer provided
    • readByNameAndCustomerRefCustomerId

      @Deprecated public Optional<P> readByNameAndCustomerRefCustomerId(String cartName, String customerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated.
      Description copied from interface: CartService
      Find the cart for the given name and customer id. There should only be one result, as cart names are unique per customer.
      Specified by:
      readByNameAndCustomerRefCustomerId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      cartName - the name of the cart to retrieve
      customerId - the id of the customer who owns the cart
      contextInfo - Context information used to discriminate the carts by applicationId
      Returns:
      an optional cart with the name and customer provided
    • readByStatusAndCustomerId

      public Optional<P> readByStatusAndCustomerId(String status, String customerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find a cart with the given status (if it exists) for the provided customer id.
      Specified by:
      readByStatusAndCustomerId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      status - the status of carts to consider
      customerId - the id of the customer who owns the cart
      contextInfo - Context information used to discriminate the carts by applicationId
      Returns:
      a cart with the given status (if it exists) for the provided customer id.
    • readByStatusAndCustomerIdAndAccountId

      public Optional<P> readByStatusAndCustomerIdAndAccountId(String status, String customerId, @Nullable String accountId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find a cart with the given status (if it exists) for the provided customer id and account id. Account id can be null to find customer's personal non-account carts.
      Specified by:
      readByStatusAndCustomerIdAndAccountId in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      status - the status of carts to consider
      customerId - the id of the customer who owns the cart
      accountId - the id of the account that the cart belongs to
      contextInfo - Context information used to discriminate the carts by applicationId
      Returns:
      a cart with the given status (if it exists) for the provided customer id and account id.
    • readByStatusAndCustomerIdAndAccountIdAndName

      public Optional<P> readByStatusAndCustomerIdAndAccountIdAndName(String status, String customerId, @Nullable String accountId, @Nullable String name, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find a cart with the given status (if it exists) for the provided customer id and account id. Account id can be null to find customer's personal non-account carts.
      Specified by:
      readByStatusAndCustomerIdAndAccountIdAndName in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      status - the status of carts to consider
      customerId - the id of the customer who owns the cart
      accountId - the id of the account that the cart belongs to
      contextInfo - Context information used to discriminate the carts by applicationId
      Returns:
      a cart with the given status (if it exists) for the provided customer id and account id.
    • readHistoricalCartsByCustomer

      public org.springframework.data.domain.Page<P> readHistoricalCartsByCustomer(String customerId, @Nullable Date startDate, @Nullable Date endDate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @Nullable org.springframework.data.domain.Pageable page)
      Description copied from interface: CartService
      Find all carts that are DefaultCartStatuses.SUBMITTED or DefaultCartStatuses.CANCELLED for the provided customer and dates.
      Specified by:
      readHistoricalCartsByCustomer in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      customerId - the id of the customer who owns the carts
      startDate - the starting date to filter carts by
      endDate - the ending date to filter carts by
      contextInfo - Context information used to discriminate the carts by applicationId
      page - the requested page of results from the database
      Returns:
      all carts that are DefaultCartStatuses.SUBMITTED or DefaultCartStatuses.CANCELLED for the provided customer and dates.
    • readByCustomerIdAndOrderNumber

      public Optional<P> readByCustomerIdAndOrderNumber(String customerId, String orderNumber, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Find the cart (if it exists) for the provided customer id and order number.
      Specified by:
      readByCustomerIdAndOrderNumber in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      customerId - the id of the customer who owns the cart
      orderNumber - the order number for the cart
      contextInfo - Context information used to discriminate the carts by applicationId
      Returns:
      a cart (if it exists) with the given order number that belongs to the provided customer.
    • updateCartsMatchingTenantStatus

      public List<P> updateCartsMatchingTenantStatus(List<String> cartIds, String status, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Updates the Cart.getStatus() for the given cart ids and status and matching the tenant from the given ContextInfo.
      Specified by:
      updateCartsMatchingTenantStatus in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      cartIds - the ids of the carts to update the status for
      status - the status to update the carts to
      contextInfo - Context information used to discriminate the carts by applicationId
      Returns:
      the updated carts
    • readExpiredQuotesByStatusNotIn

      public org.springframework.data.domain.Page<P> readExpiredQuotesByStatusNotIn(@NonNull @NonNull Collection<String> statusesToExclude, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Finds a list of expired carts of type DefaultCartTypes.QUOTE, and a status not in the provided 'statuses' collection.
      Specified by:
      readExpiredQuotesByStatusNotIn in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      statusesToExclude - a collection of statuses that are not returned.
      page - the requested page of results from the database.
      contextInfo - context information related to multitenancy.
      Returns:
      a page of expired carts of type DefaultCartTypes.QUOTE with a status not in the provided collection.
    • create

      @SuppressNotification(value="PERSISTENCE", compileChangeDetails=false) public P create(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
    • update

      @SuppressNotification(value="PERSISTENCE", compileChangeDetails=false) public P update(String id, P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Overrides:
      update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
    • replace

      @SuppressNotification(value="PERSISTENCE", compileChangeDetails=false) public P replace(String id, P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Overrides:
      replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
    • updateWithCartAudit

      @SuppressNotification(value="PERSISTENCE", compileChangeDetails=false) public P updateWithCartAudit(String id, @NonNull @NonNull UpdateCartRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Updates the cart state and its related CartActionAudit. Will also send relevant notifications based on changes to the cart's status.
      Specified by:
      updateWithCartAudit in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      id - Id of the cart to update
      request - The request with the new cart state and audit
      contextInfo - Additional sandbox and multitenant info
      Returns:
      The updated cart state.
    • replaceWithCartAudit

      @SuppressNotification(value="PERSISTENCE", compileChangeDetails=false) public P replaceWithCartAudit(String id, @NonNull @NonNull UpdateCartRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Replaces the cart state and its related CartActionAudit. Will also send relevant notifications based on changes to the cart's status.
      Specified by:
      replaceWithCartAudit in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      id - Id of the cart to replace
      request - The request with the new cart state and audit
      contextInfo - Additional sandbox and multitenant info
      Returns:
      The updated cart state.
    • handleNotifications

      protected void handleNotifications(@NonNull P cart, @Nullable com.broadleafcommerce.cart.client.domain.CartActionAudit audit, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Handles any additional notifications that should be sent after updating a cart.
      Parameters:
      cart - The cart that was updated
      audit - The related CartActionAudit
      contextInfo - Additional sandbox and multitenant info
    • handleQuoteNotifications

      protected void handleQuoteNotifications(@NonNull P cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartActionAudit audit, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Handles notifications for DefaultCartTypes.QUOTE carts.
      Parameters:
      cart - the quote to send the notification for
      audit - The related CartActionAudit
      contextInfo - Additional sandbox and multitenant info
    • shouldSendQuoteNotification

      protected boolean shouldSendQuoteNotification(@NonNull P cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartActionAudit audit)
      Determines whether quote notification should be sent.
      Parameters:
      cart - the updated cart
      audit - the audit for this status update
      Returns:
      true if the quote notification should be sent, otherwise false
    • shouldSendQuoteNotificationForCustomStatus

      protected boolean shouldSendQuoteNotificationForCustomStatus(@NonNull P cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartActionAudit audit)
      A hook point to handle any custom statuses or action types.
      Parameters:
      cart - the updated cart
      audit - the audit for this status update
      Returns:
      false by default
    • delete

      @SuppressNotification(value="PERSISTENCE", compileChangeDetails=false) public void delete(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      delete in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Overrides:
      delete in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
    • replaceCartItem

      @SuppressNotification(value="PERSISTENCE", compileChangeDetails=false) public P replaceCartItem(P cart, String cartItemId, com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CartService
      Replaces the cart item in the cart and saves.
      Specified by:
      replaceCartItem in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      cart - the cart to replace an item of
      cartItemId - the ID of the cart item to replace
      cartItem - the cart item to replace with (ID will be overwritten with cartItemId)
      context - Context information used to discriminate the carts by applicationId
      Returns:
      the updated cart
    • updateCartItem

      @SuppressNotification(value="PERSISTENCE", compileChangeDetails=false) public P updateCartItem(P cart, String cartItemId, com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CartService
      Patches (updates only present fields) of the cart item in the cart and saves.
      Specified by:
      updateCartItem in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      cart - the cart to replace an item of
      cartItemId - the ID of the cart item to replace
      cartItem - the cart item to replace with (ID will be overwritten with cartItemId)
      context - Context information used to discriminate the carts by applicationId
      Returns:
      the updated cart
    • readAnonymousCustomerHistoricalOrder

      public Optional<P> readAnonymousCustomerHistoricalOrder(String emailAddress, String orderNumber, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CartService
      Reads an anonymous or not authenticated customer's historical cart using the orderNumber and emailAddress.
      Specified by:
      readAnonymousCustomerHistoricalOrder in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      emailAddress - The email address associated with the cart
      orderNumber - The historical cart's order number
      context - Context information around sandbox and multitenant state.
      Returns:
      The historical cart for an anonymous customer
    • readAnonymousCustomerOrder

      public Optional<P> readAnonymousCustomerOrder(String cartId, String emailAddress, Set<String> allowedStatuses, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CartService
      Reads a cart by cartId and emailAddress excluding the customer owned carts. This is usually used to find carts for an anonymous customer.
      Specified by:
      readAnonymousCustomerOrder in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      cartId - The cart id
      emailAddress - The email address associated with the cart
      allowedStatuses - the set of allowed statuses
      context - Context information around sandbox and multitenant state.
      Returns:
      A cart matching cartId and emailAddress
    • readCustomerOrder

      public Optional<P> readCustomerOrder(String cartId, String customerId, Set<String> allowedStatuses, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CartService
      Reads a cart by cartId, customerId, & allowedStatuses.
      Specified by:
      readCustomerOrder in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      cartId - The cart id
      customerId - The customer id associated with the cart
      allowedStatuses - the set of allowed statuses
      context - Context information around sandbox and multitenant state.
      Returns:
      A cart (if it exists) matching cartId and customerId
    • purgeAbandonedAnonymousCarts

      public int purgeAbandonedAnonymousCarts(Duration abandonedCartTimeout, Collection<String> statuses, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Delete anonymous carts that have not been updated for the specified amount of time.
      Specified by:
      purgeAbandonedAnonymousCarts in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      abandonedCartTimeout - The length of time a cart can be inactive before being purged.
      statuses - The statuses to consider for purging.
      contextInfo - context information related to multitenancy
      Returns:
      The number of carts purged.
    • readByStatus

      public List<P> readByStatus(String status, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Reads all of the carts with the given status.
      Specified by:
      readByStatus in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      status - The CartStatus to filter by
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      All of the carts with the given status.
    • readPageMatchingTenantByStatus

      public org.springframework.data.domain.Page<P> readPageMatchingTenantByStatus(String status, @Nullable org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Finds a page of the carts with the given status and matching the tenant from the given ContextInfo.
      Specified by:
      readPageMatchingTenantByStatus in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      status - the status of the cart
      pageable - the requested page of results from the database
      contextInfo - context information related to multitenancy
      Returns:
      A page of the carts with the given status and matching the tenant from the given ContextInfo.
    • readAllMatchingTenantByIds

      public List<P> readAllMatchingTenantByIds(List<String> ids, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CartService
      Finds a list of the carts with the given ids and matching the tenant from the given ContextInfo.
      Specified by:
      readAllMatchingTenantByIds in interface CartService<P extends com.broadleafcommerce.cart.client.domain.Cart>
      Parameters:
      ids - the ids of the cart
      contextInfo - context information related to multitenancy
      Returns:
      Finds a list of the carts with the given ids and matching the tenant from the given ContextInfo.
    • saveConflictingImplicitCarts

      protected void saveConflictingImplicitCarts(@NonNull @NonNull List<P> conflictingCarts, @NonNull P cartToKeep, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      If there are multiple implicit carts (status: IN_PROCESS & name: null), then the customer's carts are in an unexpected & invalid state. Therefore, we will keep one of the carts & turn the others into saved carts by setting Cart.getName().
      Parameters:
      conflictingCarts - The carts to be turned into saved carts
      cartToKeep - The cart to keep
      contextInfo - context information around sandbox and multitenant state
    • transformCartItem

      protected com.broadleafcommerce.cart.client.domain.CartItem transformCartItem(P cart, String cartItemId, com.broadleafcommerce.cart.client.domain.CartItem cartItemPatch, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Applies a patch to a cart item. Does a partial update- only non-null fields of the cart item will be updated.
      Parameters:
      cart - the cart of the item to transform
      cartItemId - the ID of the cart item to transform
      cartItemPatch - the partial update to apply to the cart item
      context - the context info of the request
      Returns:
      a non-saved version of the cart item with the patch applied
    • findCartItemIndex

      protected int findCartItemIndex(com.broadleafcommerce.cart.client.domain.Cart cart, String itemId)
    • getApplicationId

      @Nullable protected String getApplicationId(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getTenantId

      @Nullable protected String getTenantId(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getRepository

      protected CartRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.Cart>
    • getMapper

      protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager getMapper()
    • getRsqlHelper

      protected com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper getRsqlHelper()
    • setRsqlHelper

      @Autowired public void setRsqlHelper(com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper rsqlHelper)
    • getCartActionAuditService

      protected CartActionAuditService<com.broadleafcommerce.cart.client.domain.CartActionAudit> getCartActionAuditService()
    • setCartActionAuditService

      @Autowired @Lazy public void setCartActionAuditService(CartActionAuditService<com.broadleafcommerce.cart.client.domain.CartActionAudit> cartActionAuditService)
    • getCartNotificationService

      protected CartNotificationService getCartNotificationService()
    • setCartNotificationService

      @Autowired public void setCartNotificationService(CartNotificationService cartNotificationService)
    • getCartRequestValidator

      protected CartRequestValidator<com.broadleafcommerce.cart.client.domain.Cart> getCartRequestValidator()
    • setCartRequestValidator

      @Autowired public void setCartRequestValidator(CartRequestValidator<com.broadleafcommerce.cart.client.domain.Cart> cartRequestValidator)
    • getTypeFactory

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

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