Class DefaultReturnGenerationService

    • Method Detail

      • generateReturnAuthorization

        public com.broadleafcommerce.order.client.domain.ReturnAuthorization generateReturnAuthorization​(com.broadleafcommerce.order.client.domain.Order order,
                                                                                                         List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments,
                                                                                                         List<com.broadleafcommerce.order.client.domain.ReturnAuthorization> existingReturns,
                                                                                                         ReturnRequest returnRequest)
        Description copied from interface: ReturnGenerationService
        Generates a new ReturnAuthorization for the given Order and Fulfillments containing the items requested by returnRequest.
        Specified by:
        generateReturnAuthorization in interface ReturnGenerationService
        Parameters:
        order - the order with the items to return
        fulfillments - the fulfillments with the items to return
        existingReturns - all existing returns belonging to this order
        returnRequest - the request containing items to return
        Returns:
        the generated ReturnAuthorization
      • buildReturnAuthorizationItemsFromFulfillments

        protected List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> buildReturnAuthorizationItemsFromFulfillments​(com.broadleafcommerce.order.client.domain.Order order,
                                                                                                                                        List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments,
                                                                                                                                        List<com.broadleafcommerce.order.client.domain.ReturnAuthorization> existingReturns,
                                                                                                                                        ReturnRequest returnRequest)
        Generates ReturnAuthorizationItems for the ReturnRequest from the items in the given OrderFulfillments.
        Parameters:
        fulfillments - the fulfillments containing the items being returned
        existingReturns - existing returns for items in the fulfillments
        returnRequest - contains requested items to return
        Returns:
        list of new return items from the fulfillments
      • buildReturnAuthorizationItemsFromFulfillment

        protected List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> buildReturnAuthorizationItemsFromFulfillment​(com.broadleafcommerce.order.client.domain.Order order,
                                                                                                                                       com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment,
                                                                                                                                       List<ReturnItemRequest> returnItemRequests,
                                                                                                                                       Map<String,​List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>> existingReturnItems)
        Generates ReturnAuthorizationItems for the ReturnItemRequests from the items in the given OrderFulfillment.
        Parameters:
        fulfillment - the fulfillment containing the items being returned
        returnItemRequests - all of the requested items to return, including those in other fulfillments
        existingReturnItems - map of OrderFulfillmentItem.getId() to existing return items
        Returns:
        list of new return items from the fulfillment
      • processTargetItemToReturn

        protected void processTargetItemToReturn​(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem targetItem,
                                                 List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> itemsBeingReturned,
                                                 DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
        Processes the given offer target item to automatically be returned along with its qualifier item.
        Parameters:
        targetItem - the target OrderFulfillmentItem to process
        itemsBeingReturned - a list of OrderFulfillmentItems that are being returned
        hydrationResult - the DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data
      • getReturnableTargetItems

        protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> getReturnableTargetItems​(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
        Gets a list of OrderFulfillmentItems that should be automatically returned along with their qualifiers.

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

        Parameters:
        hydrationResult - the DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data
        Returns:
        a list of OrderFulfillmentItems that should be automatically returned along with their qualifiers
      • getQualifierDetails

        protected List<com.broadleafcommerce.order.common.domain.OfferItemDetail> getQualifierDetails​(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem item,
                                                                                                      DefaultReturnGenerationService.GenerateReturnHydrationResult 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 DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data
        Returns:
        a list of OfferItemDetails representing qualifier details for the given OrderFulfillmentItem
      • 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()
      • getTargetItemQuantityToReturn

        protected int getTargetItemQuantityToReturn​(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult,
                                                    com.broadleafcommerce.order.client.domain.OrderFulfillmentItem qualifierItem,
                                                    com.broadleafcommerce.order.client.domain.OrderFulfillmentItem targetItem,
                                                    com.broadleafcommerce.order.common.domain.OfferItemDetail qualifierDetail)
        Calculates and returns the quantity of the target item to return.

        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 returned.

        Parameters:
        hydrationResult - the DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data
        qualifierItem - the OrderFulfillmentItem that is the qualifier
        targetItem - the target OrderFulfillmentItem to calculate the quantity for
        qualifierDetail - the OfferItemDetail representing the qualifier details
        Returns:
        the quantity of the target item to return
      • filterItemsInFulfillment

        protected List<ReturnItemRequest> filterItemsInFulfillment​(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment,
                                                                   List<ReturnItemRequest> returnItemRequests)
        Filter to only the ReturnItemRequests which match items in this particular OrderFulfillment.
        Parameters:
        fulfillment - the fulfillment to filter return item requests for
        returnItemRequests - the requested items to return
        Returns:
        only the return item requests which match items in the fulfillment
      • getFulfillmentItemQuantities

        protected Map<String,​Integer> getFulfillmentItemQuantities​(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
      • getExistingReturnItemQuantities

        protected Map<String,​Integer> getExistingReturnItemQuantities​(Map<String,​List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>> existingReturnItems)
      • splitFromFulfillment

        protected com.broadleafcommerce.order.client.domain.OrderFulfillment splitFromFulfillment​(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment,
                                                                                                  Map<String,​Integer> returnRequestItemQuantities)
        Split the fulfillment into two, and return the part containing the items and quantities specified by returnRequestItemQuantities.
        Parameters:
        fulfillment - the fulfillment to split
        returnRequestItemQuantities - the items and their quantities to split off
        Returns:
        the split off fulfillment containing the returnRequestItemQuantities items and their quantities
      • buildReturnAuthorizationItemsForEntireFulfillment

        protected List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> buildReturnAuthorizationItemsForEntireFulfillment​(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
        Generates ReturnAuthorizationItems for all of the items in the fulfillmentToReturn and returnItemRequests.

        Requires that the fulfillmentToReturn already contains exactly the items and quantities dictated by returnItemRequests.

        Parameters:
        hydrationResult - the DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data
        Returns:
        list of new return items for all items in the fulfillment
      • buildReturnAuthorizationItem

        protected com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem buildReturnAuthorizationItem​(ReturnItemRequest returnItemRequest)
      • getMerchandiseTotalToRefund

        protected javax.money.MonetaryAmount getMerchandiseTotalToRefund​(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem fulfillmentItem,
                                                                         DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
        Gets the merchandise total to refund for the given OrderFulfillmentItem.

        Any custom refund calculation logic can be added here.

        By default, the OrderFulfillmentItem.getMerchandiseRefundAmount() that was pre-calculated during the order generation process is used.

        Parameters:
        fulfillmentItem - the OrderFulfillmentItem to calculate the merchandise total to refund for
        hydrationResult - the DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data which could be helpful for the calculation
        Returns:
        the merchandise total to refund for the given OrderFulfillmentItem
      • getFulfillmentTotalToRefund

        protected javax.money.MonetaryAmount getFulfillmentTotalToRefund​(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem fulfillmentItem,
                                                                         DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
        Gets the fulfillment total to refund for the given OrderFulfillmentItem.

        Any custom fulfillment total refund calculation logic should be added here.

        Parameters:
        fulfillmentItem - the OrderFulfillmentItem to calculate the merchandise total to refund for
        hydrationResult - the DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data which could be helpful for the calculation
        Returns:
        the fulfillment total to refund for the given OrderFulfillmentItem
      • getTaxTotalToRefund

        protected javax.money.MonetaryAmount getTaxTotalToRefund​(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem fulfillmentItem,
                                                                 DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
        Gets the tax total to refund for the given OrderFulfillmentItem.

        Any custom merchandise tax total refund calculation logic should be added here.

        Parameters:
        fulfillmentItem - the OrderFulfillmentItem to calculate the merchandise total to refund for
        hydrationResult - the DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data which could be helpful for the calculation
        Returns:
        the tax total to refund for the given OrderFulfillmentItem
      • prorateFulfillmentLevelCost

        protected void prorateFulfillmentLevelCost​(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment,
                                                   List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems)
        Distributes the fulfillment charge at the OrderFulfillment level across the ReturnAuthorizationItem.getEstimatedFulfillmentTotalToRefund() of the returnAuthorizationItems.
        Parameters:
        fulfillment - the fulfillment containing the fulfillment charge to prorate
        returnAuthorizationItems - the items to receive the prorated fulfillment charge
      • prorateFulfillmentTaxTotal

        protected void prorateFulfillmentTaxTotal​(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment,
                                                  List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems)
        Distributes the fulfillment tax at the OrderFulfillment level across the ReturnAuthorizationItem.getEstimatedTaxTotalToRefund() of the returnAuthorizationItems.
        Parameters:
        fulfillment - the fulfillment containing the fulfillment tax to prorate
        returnAuthorizationItems - the items to receive the prorated fulfillment tax
      • getMerchandiseBasedSplitProportions

        protected Map<String,​BigDecimal> getMerchandiseBasedSplitProportions​(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
        Determine the proportions each OrderFulfillmentItem in fulfillment contributes to the OrderFulfillment.getItemMerchandiseSubtotal().
        Parameters:
        fulfillment - the fulfillment to get the item merchandise proportions for
        Returns:
        map of OrderFulfillmentItem.getId() to the proportion that item contributes to the OrderFulfillment.getItemMerchandiseSubtotal()
      • getFulfillmentBasedSplitProportions

        protected Map<String,​BigDecimal> getFulfillmentBasedSplitProportions​(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
        Determine the proportions each OrderFulfillmentItem in fulfillment contributes to the OrderFulfillment.getFulfillmentTotal().
        Parameters:
        fulfillment - the fulfillment to get the item fulfillment proportions for
        Returns:
        map of OrderFulfillmentItem.getId() to the proportion that item contributes to the OrderFulfillment.getFulfillmentTotal()
      • getSplitProportions

        protected Map<String,​BigDecimal> getSplitProportions​(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment,
                                                                   Function<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem,​javax.money.MonetaryAmount> getPartOfTotal)
        Determine the proportions each OrderFulfillmentItem in fulfillment contributes to a certain total based on the item's getPartOfTotal.
        Parameters:
        fulfillment - the fulfillment to get the item total proportions for
        getPartOfTotal - function to retrieve the amount a OrderFulfillmentItem contributes to the OrderFulfillment's total
        Returns:
        map of OrderFulfillmentItem.getId() to the proportion that item contributes to the OrderFulfillment's total
      • distributeProratedAmount

        protected void distributeProratedAmount​(javax.money.MonetaryAmount amount,
                                                List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems,
                                                Map<String,​BigDecimal> prorationProportions,
                                                Function<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem,​javax.money.MonetaryAmount> getItemAmount,
                                                BiConsumer<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem,​javax.money.MonetaryAmount> setItemAmount)
        Distribute an amount which needs to be prorated across ReturnAuthorizationItems based on the given prorationProportions for their matching OrderFulfillmentItems.
        Parameters:
        amount - the amount to be prorated across returnAuthorizationItems
        returnAuthorizationItems - the return items to receive the prorated amounts
        prorationProportions - map of OrderFulfillmentItem.getId() to the proportion of the amount its return item should receive
        getItemAmount - function to retrieve the current value on a ReturnAuthorizationItem to which the prorated amount should be added
        setItemAmount - function to set the value on a ReturnAuthorizationItem once the prorated amount has been added
      • sumEstimatedTotalsToRefund

        protected javax.money.MonetaryAmount sumEstimatedTotalsToRefund​(com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem item)
      • buildReturnAuthorizationItemsForRestOfFulfillment

        protected List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> buildReturnAuthorizationItemsForRestOfFulfillment​(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
        Generates ReturnAuthorizationItems for all of the items in the fulfillmentToReturn and returnItemRequests which are not already present in existingReturnItems.

        This ensures that when a fulfillment has been returned piece-wise, the final return on that fulfillment never leaves behind a non-refunded amount due to rounding on the previous returns.

        Parameters:
        hydrationResult - the DefaultReturnGenerationService.GenerateReturnHydrationResult containing all the relevant data
        Returns:
        list of new return items for all remaining items with no return authorization
      • prorateMissingMerchandiseAmount

        protected void prorateMissingMerchandiseAmount​(javax.money.MonetaryAmount originalTotal,
                                                       com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillmentPartToReturn,
                                                       Map<String,​List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>> existingReturnItems,
                                                       List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems)
      • prorateMissingFulfillmentAmount

        protected void prorateMissingFulfillmentAmount​(javax.money.MonetaryAmount originalTotal,
                                                       com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillmentPartToReturn,
                                                       Map<String,​List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>> existingReturnItems,
                                                       List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems)
      • prorateMissingTaxAmount

        protected void prorateMissingTaxAmount​(javax.money.MonetaryAmount originalTotal,
                                               com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillmentPartToReturn,
                                               Map<String,​List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>> existingReturnItems,
                                               List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems)
      • prorateMissingAmountAcrossItems

        protected void prorateMissingAmountAcrossItems​(javax.money.MonetaryAmount originalTotal,
                                                       com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillmentPartToReturn,
                                                       Map<String,​List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>> existingReturnItems,
                                                       List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems,
                                                       Map<String,​BigDecimal> splitProportions,
                                                       Function<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem,​javax.money.MonetaryAmount> getItemAmount,
                                                       BiConsumer<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem,​javax.money.MonetaryAmount> setItemAmount)
        Determines if there is any discrepancy between the fulfillment's originalTotal and the total of getItemAmount across all the existing and new ReturnAuthorizationItems. If there is a discrepancy, then distribute the amount missing from the total to refund across the new returnAuthorizationItems.
        Parameters:
        originalTotal - the original fulfillment tax total
        fulfillmentPartToReturn - the fulfillment containing the items requested to return
        existingReturnItems - map of OrderFulfillmentItem.getId() to existing return items
        returnAuthorizationItems - the new return items, which will receive any prorated missing total to refund
        splitProportions - map of OrderFulfillmentItem.getId() to the proportion of the missing amount its return item should receive
        getItemAmount - function to retrieve the current value on a ReturnAuthorizationItem to which the prorated amount should be added
        setItemAmount - function to set the value on a ReturnAuthorizationItem once the prorated amount has been added
      • sumAmountsFromReturnAuthItems

        protected javax.money.MonetaryAmount sumAmountsFromReturnAuthItems​(List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> items,
                                                                           Function<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem,​javax.money.MonetaryAmount> getAmount,
                                                                           javax.money.CurrencyUnit currency)
      • roundReturnAuthorizationItems

        protected void roundReturnAuthorizationItems​(List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnItems,
                                                     javax.money.CurrencyUnit currency)
        Rounds all of the totals on the ReturnAuthorizationItems.
        Parameters:
        returnItems - the return items containing totals to be rounded
        currency - the currency of the amounts to round
      • roundEstimatedGrandTotals

        protected void roundEstimatedGrandTotals​(List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnItems)
        Rounds the estimated grand totals to refund for the ReturnAuthorizationItems. Ensures that the sum of the rounded totals still add up to the same sum as before rounding.
        Parameters:
        returnItems - the return items containing totals to be rounded
      • roundReturnAuthorizationItemsComponentTotals

        protected void roundReturnAuthorizationItemsComponentTotals​(List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnItems,
                                                                    javax.money.CurrencyUnit currency)
        Rounds all of the totals which add up to ReturnAuthorizationItem.getEstimatedTotalToRefund(). Ensures each item's rounded totals add up to its ReturnAuthorizationItem.getEstimatedTotalToRefund(), and that the sum of each total across all items doesn't change.
        Parameters:
        returnItems - the return items containing totals to be rounded
        currency - the currency of the amounts to round
      • calculateEstimatedTotals

        public void calculateEstimatedTotals​(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
        Calculate and assign the estimated totals for the ReturnAuthorization by adding up the totals of its ReturnAuthorization.getItems().
        Specified by:
        calculateEstimatedTotals in interface ReturnGenerationService
        Parameters:
        returnAuthorization - the return authorization for which to calculate and assign totals
      • estimateReturnShippingCharge

        protected javax.money.MonetaryAmount estimateReturnShippingCharge​(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
        Determine the estimated ReturnAuthorization.getEstimatedReturnShippingCharge().

        This default implementation should be replaced in order to correctly calculate the shipping charge. The default is 0.

        Parameters:
        returnAuthorization - the return authorization for which to estimate the return shipping charge
        Returns:
        the estimated return shipping charge for the returnAuthorization
      • generateTrackingNumber

        @Nullable
        protected String generateTrackingNumber​(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
        Generate the ReturnAuthorization.getTrackingNumber().

        This default implementation should be replaced in order to correctly generate a new tracking number. The default is null.

        Parameters:
        returnAuthorization - the return authorization for which to generate a tracking number
        Returns:
        the generated tracking number for the returnAuthorization
      • getSplittingService

        protected FulfillmentSplittingService<com.broadleafcommerce.order.client.domain.OrderFulfillment> getSplittingService()
      • getTypeFactory

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