Class DefaultReturnOperationService

java.lang.Object
com.broadleafcommerce.orderoperation.service.DefaultReturnOperationService
All Implemented Interfaces:
ReturnOperationService

public class DefaultReturnOperationService extends Object implements ReturnOperationService
  • Constructor Details

  • Method Details

    • createReturn

      public com.broadleafcommerce.order.client.domain.ReturnAuthorization createReturn(String orderId, ReturnRequest returnRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ReturnOperationService
      Create a ReturnAuthorization for the Order with the given orderId containing the items requested by returnRequest.
      Specified by:
      createReturn in interface ReturnOperationService
      Parameters:
      orderId - the ID of the order with the items to return
      returnRequest - the request containing items to return
      contextInfo - context information around sandbox and multitenant state
      Returns:
      the created ReturnAuthorization
    • sendReturnCreatedMessage

      protected void sendReturnCreatedMessage(ReturnRequest request, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • confirmReturn

      public com.broadleafcommerce.order.client.domain.ReturnAuthorization confirmReturn(String orderId, ConfirmReturnRequest confirmReturnRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ReturnOperationService
      Create ReturnConfirmations for ReturnAuthorizationItems within the Order with the given orderId.
      Specified by:
      confirmReturn in interface ReturnOperationService
      Parameters:
      orderId - the ID of the order with the return having items confirmed
      confirmReturnRequest - the request containing items to confirm as returned
      contextInfo - context information around sandbox and multitenant state
      Returns:
      the ReturnAuthorization updated with the new ReturnConfirmations
    • processConfirmRequestForOfferTargetItems

      protected void processConfirmRequestForOfferTargetItems(DefaultReturnOperationService.ConfirmReturnHydrationResult hydrationResult)
      Ensures that whenever an offer qualifier item is being confirmed, the offer target item is being confirmed as well.

      For example, itemA is a free gift offer qualifier item, and itemFG is the target item that was added from the offer. Whenever itemA is being confirmed, a ConfirmReturnItemRequest for itemFG will automatically be created or updated.

      Parameters:
      hydrationResult - the DefaultReturnOperationService.ConfirmReturnHydrationResult containing all the relevant data
    • getFulfillmentItemsBeingConfirmed

      protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> getFulfillmentItemsBeingConfirmed(DefaultReturnOperationService.ConfirmReturnHydrationResult hydrationResult)
      Gets a list of OrderFulfillmentItems that are being confirmed.
      Parameters:
      hydrationResult - the DefaultReturnOperationService.ConfirmReturnHydrationResult containing all the relevant data
      Returns:
      a list of OrderFulfillmentItems that are being confirmed
    • getConfirmableTargetItems

      protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> getConfirmableTargetItems(DefaultReturnOperationService.ConfirmReturnHydrationResult hydrationResult)
      Gets a list of OrderFulfillmentItems that should be automatically confirmed along with their qualifiers.

      By default, this will only get a list of free gift OrderFulfillmentItems.

      Parameters:
      hydrationResult - the DefaultReturnOperationService.ConfirmReturnHydrationResult containing all the relevant data
      Returns:
      a list of OrderFulfillmentItems that should be automatically confirmed along with their qualifiers
    • processTargetItemToConfirm

      protected void processTargetItemToConfirm(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem targetItem, List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> itemsBeingConfirmed, DefaultReturnOperationService.ConfirmReturnHydrationResult hydrationResult)
      Adds all the confirmable target items from the qualifier item to the given ConfirmReturnRequest.
      Parameters:
      targetItem - the target OrderFulfillmentItem to process
      itemsBeingConfirmed - a list of OrderFulfillmentItems that are being confirmed
      hydrationResult - the DefaultReturnOperationService.ConfirmReturnHydrationResult containing all the relevant data
    • getQualifierDetails

      protected List<com.broadleafcommerce.order.common.domain.OfferItemDetail> getQualifierDetails(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem item, DefaultReturnOperationService.ConfirmReturnHydrationResult hydrationResult)
      Gets a list of OfferItemDetails representing qualifier details for the given OrderFulfillmentItem.

      The OrderFulfillmentItem itself can have qualifier details pointing to other OrderFulfillmentItems, but only the qualifier details for the corresponding OrderItem is obtained by default.

      Parameters:
      item - the OrderFulfillmentItem to get the qualifier details from
      hydrationResult - the DefaultReturnOperationService.ConfirmReturnHydrationResult containing all the relevant data
      Returns:
      a list of OfferItemDetails representing qualifier details for the given OrderFulfillmentItem
    • getTargetItemQuantityToConfirm

      protected int getTargetItemQuantityToConfirm(DefaultReturnOperationService.ConfirmReturnHydrationResult hydrationResult, ConfirmReturnItemRequest qualifierConfirmRequest, com.broadleafcommerce.order.client.domain.OrderFulfillmentItem targetItem, com.broadleafcommerce.order.common.domain.OfferItemDetail qualifierDetail)
      Calculates and returns the quantity of the target item to confirm.

      The quantity of the target item to confirm is the lowest number between the qualifier item quantity being confirmed, the target item quantity that is target of this qualifier, and total confirmable target item quantity. Using the lowest number so that we don't confirm more items than we have.

      Additionally, if the qualifier and target are the same item, then we'll add the quantity to confirm on top of the quantity already being confirmed.

      Parameters:
      hydrationResult - the DefaultReturnOperationService.ConfirmReturnHydrationResult containing all the relevant data
      qualifierConfirmRequest - the ConfirmReturnItemRequest for the qualifier item
      targetItem - the target OrderFulfillmentItem to calculate the quantity for
      qualifierDetail - the OfferItemDetail representing the qualifier details
      Returns:
      the quantity of the target item to confirm
    • getFulfillmentItemsByOrderItemId

      protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> getFulfillmentItemsByOrderItemId(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> fulfillmentItems, String orderItemId)
      Gets a list of OrderFulfillmentItems based on the given OrderFulfillmentItem.getOrderItemId().

      Note that there can be many OrderFulfillmentItems that have the same OrderFulfillmentItem.getOrderItemId(), since they can be split.

      Parameters:
      fulfillmentItems - the OrderFulfillmentItems to find the items from
      orderItemId - the OrderFulfillmentItem.getOrderItemId() to filter by
      Returns:
      a list of OrderFulfillmentItems based on the given OrderFulfillmentItem.getOrderItemId()
    • getConfirmedQuantityByItemId

      protected Map<String,Integer> getConfirmedQuantityByItemId(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
      Gets a map of confirmed quantities by OrderFulfillmentItem.getId().
      Parameters:
      returnAuthorization - the ReturnAuthorization to get all the ReturnConfirmations from
      Returns:
      a map of confirmed quantities by OrderFulfillmentItem.getId()
    • buildConfirmReturnRequestFrom

      protected ConfirmReturnItemRequest buildConfirmReturnRequestFrom(String itemId, int quantity, ConfirmReturnItemRequest existingRequest)
      Builds a ConfirmReturnItemRequest from the given id, quantity, and ConfirmReturnItemRequest that wish to copy other fields from.
      Parameters:
      itemId - the ConfirmReturnItemRequest.getOrderFulfillmentItemId() of the new ConfirmReturnItemRequest
      quantity - the ConfirmReturnItemRequest.getQuantity() of the new ConfirmReturnItemRequest
      existingRequest - the ConfirmReturnItemRequest to copy the rest of the fields from
      Returns:
      a new ConfirmReturnItemRequest from the given id, quantity, and ConfirmReturnItemRequest that wish to copy other fields from
    • readReturnAuthorization

      protected com.broadleafcommerce.order.client.domain.ReturnAuthorization readReturnAuthorization(String id, String orderId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • applyConfirmations

      protected void applyConfirmations(DefaultReturnOperationService.ConfirmReturnHydrationResult hydrationResult, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Generate new ReturnConfirmations from the ConfirmReturnRequest and apply them on the ReturnAuthorization.
      Parameters:
      hydrationResult - the DefaultReturnOperationService.ConfirmReturnHydrationResult containing the ReturnAuthorization and ConfirmReturnRequest
      contextInfo - context information around sandbox and multitenant state
    • generateReturnConfirmations

      protected void generateReturnConfirmations(DefaultReturnOperationService.ConfirmReturnHydrationResult hydrationResult, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Generates the ReturnConfirmations and add them to respected ReturnAuthorizationItems.
      Parameters:
      hydrationResult - the DefaultReturnOperationService.ConfirmReturnHydrationResult containing the ReturnAuthorization and ConfirmReturnRequest
      contextInfo - context information around sandbox and multitenant state
    • changeReturnAuthorizationStatus

      protected void changeReturnAuthorizationStatus(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
      Update the status of the ReturnAuthorization to ReturnAuthorizationStatus.CONFIRMED if it has now been completely confirmed, or ReturnAuthorizationStatus.PARTIALLY_CONFIRMED if only partially confirmed.
      Parameters:
      returnAuthorization - the return authorization to update the status of
    • isCompletelyConfirmed

      protected boolean isCompletelyConfirmed(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
      Check if ReturnConfirmations exist for all of the item quantity within the ReturnAuthorization.
      Parameters:
      returnAuthorization - the return authorization to check if it is completely confirmed
      Returns:
      whether the return confirmation is completely confirmed
    • sendReturnConfirmedMessage

      protected void sendReturnConfirmedMessage(ConfirmReturnRequest request, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • cancelReturn

      public List<com.broadleafcommerce.order.client.domain.ReturnAuthorization> cancelReturn(String orderId, CancelReturnRequest cancelReturnRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ReturnOperationService
      Cancel a ReturnAuthorization for the Order with the given orderId. Any already confirmed ReturnAuthorizationItems are extracted into a new separate confirmed ReturnAuthorization, since they cannot be cancelled.
      Specified by:
      cancelReturn in interface ReturnOperationService
      Parameters:
      orderId - the ID of the order with the return to cancel
      cancelReturnRequest - the request indicating which return to cancel
      contextInfo - context information around sandbox and multitenant state
      Returns:
      the cancelled ReturnAuthorization and possibly a newly separated confirmed ReturnAuthorization, if there were any confirmations
    • sendReturnCancelledMessage

      protected void sendReturnCancelledMessage(CancelReturnRequest request, com.broadleafcommerce.order.client.domain.ReturnAuthorization cancelledReturn, @Nullable com.broadleafcommerce.order.client.domain.ReturnAuthorization confirmedReturn, com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • estimateReturn

      public com.broadleafcommerce.order.client.domain.ReturnAuthorization estimateReturn(String orderId, ReturnRequest returnRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ReturnOperationService
      Estimate a ReturnAuthorization for the Order with the given orderId containing the items requested by returnRequest.
      Specified by:
      estimateReturn in interface ReturnOperationService
      Parameters:
      orderId - the ID of the order with the items to return
      returnRequest - the request containing items to return
      contextInfo - context information around sandbox and multitenant state
      Returns:
      the created ReturnAuthorization
    • estimateReturn

      protected com.broadleafcommerce.order.client.domain.ReturnAuthorization estimateReturn(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, ReturnRequest returnRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • readContextInfo

      @Nullable protected com.broadleafcommerce.data.tracking.core.context.ContextInfo readContextInfo(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getHydratedConfirmReturn

      protected DefaultReturnOperationService.ConfirmReturnHydrationResult getHydratedConfirmReturn(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, ConfirmReturnRequest confirmReturnRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Builds a DefaultReturnOperationService.ConfirmReturnHydrationResult based on the given parameters.
      Parameters:
      order -
      fulfillments - the OrderFulfillments to get all the OrderFulfillmentItems from
      returnAuthorization - the ReturnAuthorization to get all the returned and confirmed quantities from
      confirmReturnRequest - the ConfirmReturnRequest to get all the ConfirmReturnItemRequests from
      contextInfo - the context around sandboxing and multitenant state
      Returns:
      a hydrated DefaultReturnOperationService.ConfirmReturnHydrationResult from the given parameters
    • getTypeFactory

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

      protected OrderProvider<com.broadleafcommerce.order.client.domain.Order> getOrderProvider()
    • getFulfillmentProvider

      protected FulfillmentProvider<com.broadleafcommerce.order.client.domain.OrderFulfillment> getFulfillmentProvider()
    • getReturnAuthorizationProvider

      protected ReturnAuthorizationProvider<com.broadleafcommerce.order.client.domain.ReturnAuthorization> getReturnAuthorizationProvider()
    • getReturnRequestValidator

      protected ReturnRequestValidator getReturnRequestValidator()
    • getReturnGenerationService

      protected ReturnGenerationService getReturnGenerationService()
    • getReturnCreatedProducer

      protected ReturnCreatedProducer getReturnCreatedProducer()
    • getConfirmReturnRequestValidator

      protected ConfirmReturnRequestValidator getConfirmReturnRequestValidator()
    • getReturnConfirmationGenerationService

      protected ReturnConfirmationGenerationService getReturnConfirmationGenerationService()
    • getReturnConfirmedProducer

      protected ReturnConfirmedProducer getReturnConfirmedProducer()
    • getCancelReturnRequestValidator

      protected CancelReturnRequestValidator getCancelReturnRequestValidator()
    • getReturnSplittingService

      protected ReturnSplittingService getReturnSplittingService()
    • getReturnCancelledProducer

      protected ReturnCancelledProducer getReturnCancelledProducer()
    • getOfferUtils

      protected OrderOperationServiceOfferUtils getOfferUtils()
    • setOfferUtils

      @Autowired public void setOfferUtils(OrderOperationServiceOfferUtils offerUtils)
    • getDetachedDurableMessageSender

      protected com.broadleafcommerce.common.messaging.notification.DetachedDurableMessageSender getDetachedDurableMessageSender()
    • setDetachedDurableMessageSender

      @Autowired(required=false) public void setDetachedDurableMessageSender(com.broadleafcommerce.common.messaging.notification.DetachedDurableMessageSender detachedDurableMessageSender)
    • getProperties

      protected OrderOperationProviderProperties getProperties()
    • setProperties

      @Autowired public void setProperties(OrderOperationProviderProperties properties)