Class DefaultReturnGenerationService
- java.lang.Object
-
- com.broadleafcommerce.orderoperation.service.generate.DefaultReturnGenerationService
-
- All Implemented Interfaces:
ReturnGenerationService
public class DefaultReturnGenerationService extends Object implements ReturnGenerationService
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultReturnGenerationService.GenerateReturnHydrationResult
An intermediary data structure used internally byReturnGenerationService
to hold all the relevant data for generating returns, to prevent processing the data multiple times and make it easier to pass the data between methods.
-
Constructor Summary
Constructors Constructor Description DefaultReturnGenerationService(FulfillmentSplittingService<com.broadleafcommerce.order.client.domain.OrderFulfillment> splittingService, FulfillmentOperationHelper helper, SplitRoundingHelper roundingHelper, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addTargetItemReturnItemRequest(String targetItemId, int targetItemQuantityToReturn, String qualifierItemId, DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Updates the quantity of the existingReturnItemRequest
of the target item if present, otherwise builds a newReturnItemRequest
based on theReturnItemRequest
for the qualifier item.protected com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem
buildReturnAuthorizationItem(ReturnItemRequest returnItemRequest)
protected List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>
buildReturnAuthorizationItemsForEntireFulfillment(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
GeneratesReturnAuthorizationItems
for all of the items in thefulfillmentToReturn
andreturnItemRequests
.protected List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>
buildReturnAuthorizationItemsForRestOfFulfillment(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
GeneratesReturnAuthorizationItems
for all of the items in thefulfillmentToReturn
andreturnItemRequests
which are not already present inexistingReturnItems
.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)
GeneratesReturnAuthorizationItems
for theReturnItemRequests
from the items in the givenOrderFulfillment
.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)
GeneratesReturnAuthorizationItems
for theReturnRequest
from the items in the givenOrderFulfillments
.protected ReturnItemRequest
buildReturnItemRequestFrom(String itemId, int quantity, ReturnItemRequest existingRequest)
Builds aReturnItemRequest
from the given id, quantity, andReturnItemRequest
that wish to copy other fields from.void
calculateEstimatedTotals(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
Calculate and assign the estimated totals for theReturnAuthorization
by adding up the totals of itsReturnAuthorization.getItems()
.protected Map<String,Integer>
combineQuantities(Map<String,Integer> toCombine1, Map<String,Integer> toCombine2)
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 acrossReturnAuthorizationItems
based on the givenprorationProportions
for their matchingOrderFulfillmentItems
.protected javax.money.MonetaryAmount
estimateReturnShippingCharge(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
Determine the estimatedReturnAuthorization.getEstimatedReturnShippingCharge()
.protected List<ReturnItemRequest>
filterItemsInFulfillment(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, List<ReturnItemRequest> returnItemRequests)
Filter to only theReturnItemRequests
which match items in this particularOrderFulfillment
.protected Optional<ReturnItemRequest>
findByFulfillmentItemId(List<ReturnItemRequest> fulfillmentReturnItemRequests, String fulfillmentItemId)
Finds the firstReturnItemRequest
based onOrderFulfillmentItem.getId()
.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)
Generates a newReturnAuthorization
for the givenOrder
andFulfillments
containing the items requested byreturnRequest
.protected String
generateTrackingNumber(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
Generate theReturnAuthorization.getTrackingNumber()
.protected Map<String,Integer>
getExistingReturnItemQuantities(Map<String,List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem>> existingReturnItems)
protected Map<String,BigDecimal>
getFulfillmentBasedSplitProportions(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
Determine the proportions eachOrderFulfillmentItem
infulfillment
contributes to theOrderFulfillment.getFulfillmentTotal()
.protected Map<String,Integer>
getFulfillmentItemQuantities(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>
getFulfillmentItemsBeingReturned(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Gets a list ofOrderFulfillmentItems
that are being returnedprotected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>
getFulfillmentItemsByOrderItemId(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> fulfillmentItems, String orderItemId)
Gets a list ofOrderFulfillmentItems
based on the givenOrderFulfillmentItem.getOrderItemId()
.protected javax.money.MonetaryAmount
getFulfillmentTotalToRefund(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem fulfillmentItem, DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Gets the fulfillment total to refund for the givenOrderFulfillmentItem
.protected DefaultReturnGenerationService.GenerateReturnHydrationResult
getGenerateReturnHydrationResult(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>> existingReturnItemsByItemId)
Builds aDefaultReturnGenerationService.GenerateReturnHydrationResult
based on the given parameters.protected FulfillmentOperationHelper
getHelper()
protected Map<String,BigDecimal>
getMerchandiseBasedSplitProportions(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
Determine the proportions eachOrderFulfillmentItem
infulfillment
contributes to theOrderFulfillment.getItemMerchandiseSubtotal()
.protected javax.money.MonetaryAmount
getMerchandiseTotalToRefund(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem fulfillmentItem, DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Gets the merchandise total to refund for the givenOrderFulfillmentItem
.protected OrderOperationServiceOfferUtils
getOfferUtils()
protected List<com.broadleafcommerce.order.common.domain.OfferItemDetail>
getQualifierDetails(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem item, DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Gets a list ofOfferItemDetails
representing qualifier details for the givenOrderFulfillmentItem
.protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>
getReturnableTargetItems(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Gets a list ofOrderFulfillmentItems
that should be automatically returned along with their qualifiers.protected Map<String,Integer>
getReturnItemQuantities(List<ReturnItemRequest> returnItemRequests)
protected SplitRoundingHelper
getRoundingHelper()
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 eachOrderFulfillmentItem
infulfillment
contributes to a certain total based on the item'sgetPartOfTotal
.protected FulfillmentSplittingService<com.broadleafcommerce.order.client.domain.OrderFulfillment>
getSplittingService()
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.protected javax.money.MonetaryAmount
getTaxTotalToRefund(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem fulfillmentItem, DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Gets the tax total to refund for the givenOrderFulfillmentItem
.protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected boolean
isReturningEntireFulfillment(DefaultReturnGenerationService.GenerateReturnHydrationResult hydration)
Determines if theDefaultReturnGenerationService.GenerateReturnHydrationResult.getReturnItemRequests()
are returning the entire fulfillment.protected boolean
isReturningRestOfFulfillment(DefaultReturnGenerationService.GenerateReturnHydrationResult hydration)
Determines if theDefaultReturnGenerationService.GenerateReturnHydrationResult.getReturnItemRequests()
are returning the rest of fulfillment.protected void
processReturnRequestsForOfferTargetItems(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Ensures that whenever an offer qualifier item is being returned, the offer target item is being returned as well based on its qualifier details.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.protected void
prorateFulfillmentLevelCost(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems)
Distributes the fulfillment charge at theOrderFulfillment
level across theReturnAuthorizationItem.getEstimatedFulfillmentTotalToRefund()
of thereturnAuthorizationItems
.protected void
prorateFulfillmentTaxTotal(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnAuthorizationItems)
Distributes the fulfillment tax at theOrderFulfillment
level across theReturnAuthorizationItem.getEstimatedTaxTotalToRefund()
of thereturnAuthorizationItems
.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'soriginalTotal
and the total ofgetItemAmount
across all the existing and newReturnAuthorizationItems
.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)
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)
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)
protected void
roundEstimatedGrandTotals(List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnItems)
Rounds the estimated grand totals to refund for theReturnAuthorizationItems
.protected void
roundReturnAuthorizationItems(List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnItems, javax.money.CurrencyUnit currency)
Rounds all of the totals on theReturnAuthorizationItems
.protected void
roundReturnAuthorizationItemsComponentTotals(List<com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem> returnItems, javax.money.CurrencyUnit currency)
Rounds all of the totals which add up toReturnAuthorizationItem.getEstimatedTotalToRefund()
.void
setOfferUtils(OrderOperationServiceOfferUtils offerUtils)
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 byreturnRequestItemQuantities
.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)
protected javax.money.MonetaryAmount
sumEstimatedTotalsToRefund(com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem item)
-
-
-
Constructor Detail
-
DefaultReturnGenerationService
public DefaultReturnGenerationService(FulfillmentSplittingService<com.broadleafcommerce.order.client.domain.OrderFulfillment> splittingService, FulfillmentOperationHelper helper, SplitRoundingHelper roundingHelper, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
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 newReturnAuthorization
for the givenOrder
andFulfillments
containing the items requested byreturnRequest
.- Specified by:
generateReturnAuthorization
in interfaceReturnGenerationService
- Parameters:
order
- the order with the items to returnfulfillments
- the fulfillments with the items to returnexistingReturns
- all existing returns belonging to this orderreturnRequest
- 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)
GeneratesReturnAuthorizationItems
for theReturnRequest
from the items in the givenOrderFulfillments
.- Parameters:
fulfillments
- the fulfillments containing the items being returnedexistingReturns
- existing returns for items in the fulfillmentsreturnRequest
- 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)
GeneratesReturnAuthorizationItems
for theReturnItemRequests
from the items in the givenOrderFulfillment
.- Parameters:
fulfillment
- the fulfillment containing the items being returnedreturnItemRequests
- all of the requested items to return, including those in other fulfillmentsexistingReturnItems
- map ofOrderFulfillmentItem.getId()
to existing return items- Returns:
- list of new return items from the fulfillment
-
processReturnRequestsForOfferTargetItems
protected void processReturnRequestsForOfferTargetItems(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Ensures that whenever an offer qualifier item is being returned, the offer target item is being returned as well based on its qualifier details.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 returned, a
ReturnItemRequest
for itemFG will automatically be created or updated.- Parameters:
hydrationResult
- theDefaultReturnGenerationService.GenerateReturnHydrationResult
containing all the relevant data
-
getFulfillmentItemsBeingReturned
protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> getFulfillmentItemsBeingReturned(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Gets a list ofOrderFulfillmentItems
that are being returned- Parameters:
hydrationResult
- theDefaultReturnGenerationService.GenerateReturnHydrationResult
containing all the relevant data- Returns:
- a list of
OrderFulfillmentItems
that are being returned
-
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 targetOrderFulfillmentItem
to processitemsBeingReturned
- a list ofOrderFulfillmentItems
that are being returnedhydrationResult
- theDefaultReturnGenerationService.GenerateReturnHydrationResult
containing all the relevant data
-
getReturnableTargetItems
protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> getReturnableTargetItems(DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Gets a list ofOrderFulfillmentItems
that should be automatically returned along with their qualifiers.By default, this will only get a list of free gift
OrderFulfillmentItems
.- Parameters:
hydrationResult
- theDefaultReturnGenerationService.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 ofOfferItemDetails
representing qualifier details for the givenOrderFulfillmentItem
.The
OrderFulfillmentItem
itself can have qualifier details pointing to otherOrderFulfillmentItems
, but only the qualifier details for the correspondingOrderItem
is obtained by default.- Parameters:
item
- theOrderFulfillmentItem
to get the qualifier details fromhydrationResult
- theDefaultReturnGenerationService.GenerateReturnHydrationResult
containing all the relevant data- Returns:
- a list of
OfferItemDetails
representing qualifier details for the givenOrderFulfillmentItem
-
getFulfillmentItemsByOrderItemId
protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> getFulfillmentItemsByOrderItemId(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> fulfillmentItems, String orderItemId)
Gets a list ofOrderFulfillmentItems
based on the givenOrderFulfillmentItem.getOrderItemId()
.Note that there can be many
OrderFulfillmentItems
that have the sameOrderFulfillmentItem.getOrderItemId()
, since they can be split.- Parameters:
fulfillmentItems
- theOrderFulfillmentItems
to find the items fromorderItemId
- theOrderFulfillmentItem.getOrderItemId()
to filter by- Returns:
- a list of
OrderFulfillmentItems
based on the givenOrderFulfillmentItem.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
- theDefaultReturnGenerationService.GenerateReturnHydrationResult
containing all the relevant dataqualifierItem
- theOrderFulfillmentItem
that is the qualifiertargetItem
- the targetOrderFulfillmentItem
to calculate the quantity forqualifierDetail
- theOfferItemDetail
representing the qualifier details- Returns:
- the quantity of the target item to return
-
addTargetItemReturnItemRequest
protected void addTargetItemReturnItemRequest(String targetItemId, int targetItemQuantityToReturn, String qualifierItemId, DefaultReturnGenerationService.GenerateReturnHydrationResult hydrationResult)
Updates the quantity of the existingReturnItemRequest
of the target item if present, otherwise builds a newReturnItemRequest
based on theReturnItemRequest
for the qualifier item.- Parameters:
targetItemId
- theOrderFulfillmentItem.getId()
of the target itemtargetItemQuantityToReturn
- the quantity of the target item to returnqualifierItemId
- theOrderFulfillmentItem.getId()
of the qualifier itemhydrationResult
- theDefaultReturnGenerationService.GenerateReturnHydrationResult
containing all the relevant data
-
buildReturnItemRequestFrom
protected ReturnItemRequest buildReturnItemRequestFrom(String itemId, int quantity, ReturnItemRequest existingRequest)
Builds aReturnItemRequest
from the given id, quantity, andReturnItemRequest
that wish to copy other fields from.- Parameters:
itemId
- theReturnItemRequest.getOrderFulfillmentItemId()
of the newReturnItemRequest
quantity
- theReturnItemRequest.getQuantity()
of the newReturnItemRequest
existingRequest
- theReturnItemRequest
to copy the rest of the fields from- Returns:
- a new
ReturnItemRequest
from the given id, quantity, andReturnItemRequest
that wish to copy other fields from
-
findByFulfillmentItemId
protected Optional<ReturnItemRequest> findByFulfillmentItemId(List<ReturnItemRequest> fulfillmentReturnItemRequests, String fulfillmentItemId)
Finds the firstReturnItemRequest
based onOrderFulfillmentItem.getId()
.- Parameters:
fulfillmentReturnItemRequests
- list ofReturnItemRequests
to filter byfulfillmentItemId
- theOrderFulfillmentItem.getId()
to look for- Returns:
- the first
ReturnItemRequest
based onOrderFulfillmentItem.getId()
-
filterItemsInFulfillment
protected List<ReturnItemRequest> filterItemsInFulfillment(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, List<ReturnItemRequest> returnItemRequests)
Filter to only theReturnItemRequests
which match items in this particularOrderFulfillment
.- Parameters:
fulfillment
- the fulfillment to filter return item requests forreturnItemRequests
- 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)
-
getReturnItemQuantities
protected Map<String,Integer> getReturnItemQuantities(List<ReturnItemRequest> returnItemRequests)
-
isReturningEntireFulfillment
protected boolean isReturningEntireFulfillment(DefaultReturnGenerationService.GenerateReturnHydrationResult hydration)
Determines if theDefaultReturnGenerationService.GenerateReturnHydrationResult.getReturnItemRequests()
are returning the entire fulfillment.- Parameters:
hydration
- theDefaultReturnGenerationService.GenerateReturnHydrationResult
containing all the relevant data- Returns:
- true if the
DefaultReturnGenerationService.GenerateReturnHydrationResult.getReturnItemRequests()
are returning the entire fulfillment. Otherwise false.
-
isReturningRestOfFulfillment
protected boolean isReturningRestOfFulfillment(DefaultReturnGenerationService.GenerateReturnHydrationResult hydration)
Determines if theDefaultReturnGenerationService.GenerateReturnHydrationResult.getReturnItemRequests()
are returning the rest of fulfillment.- Parameters:
hydration
- theDefaultReturnGenerationService.GenerateReturnHydrationResult
containing all the relevant data- Returns:
- true if the
DefaultReturnGenerationService.GenerateReturnHydrationResult.getReturnItemRequests()
are returning the rest of fulfillment. Otherwise false.
-
combineQuantities
protected Map<String,Integer> combineQuantities(Map<String,Integer> toCombine1, Map<String,Integer> toCombine2)
-
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 byreturnRequestItemQuantities
.- Parameters:
fulfillment
- the fulfillment to splitreturnRequestItemQuantities
- 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)
GeneratesReturnAuthorizationItems
for all of the items in thefulfillmentToReturn
andreturnItemRequests
.Requires that the
fulfillmentToReturn
already contains exactly the items and quantities dictated byreturnItemRequests
.- Parameters:
hydrationResult
- theDefaultReturnGenerationService.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 givenOrderFulfillmentItem
.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
- theOrderFulfillmentItem
to calculate the merchandise total to refund forhydrationResult
- theDefaultReturnGenerationService.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 givenOrderFulfillmentItem
.Any custom fulfillment total refund calculation logic should be added here.
- Parameters:
fulfillmentItem
- theOrderFulfillmentItem
to calculate the merchandise total to refund forhydrationResult
- theDefaultReturnGenerationService.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 givenOrderFulfillmentItem
.Any custom merchandise tax total refund calculation logic should be added here.
- Parameters:
fulfillmentItem
- theOrderFulfillmentItem
to calculate the merchandise total to refund forhydrationResult
- theDefaultReturnGenerationService.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 theOrderFulfillment
level across theReturnAuthorizationItem.getEstimatedFulfillmentTotalToRefund()
of thereturnAuthorizationItems
.- Parameters:
fulfillment
- the fulfillment containing the fulfillment charge to proratereturnAuthorizationItems
- 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 theOrderFulfillment
level across theReturnAuthorizationItem.getEstimatedTaxTotalToRefund()
of thereturnAuthorizationItems
.- Parameters:
fulfillment
- the fulfillment containing the fulfillment tax to proratereturnAuthorizationItems
- the items to receive the prorated fulfillment tax
-
getMerchandiseBasedSplitProportions
protected Map<String,BigDecimal> getMerchandiseBasedSplitProportions(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
Determine the proportions eachOrderFulfillmentItem
infulfillment
contributes to theOrderFulfillment.getItemMerchandiseSubtotal()
.- Parameters:
fulfillment
- the fulfillment to get the item merchandise proportions for- Returns:
- map of
OrderFulfillmentItem.getId()
to the proportion that item contributes to theOrderFulfillment.getItemMerchandiseSubtotal()
-
getFulfillmentBasedSplitProportions
protected Map<String,BigDecimal> getFulfillmentBasedSplitProportions(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
Determine the proportions eachOrderFulfillmentItem
infulfillment
contributes to theOrderFulfillment.getFulfillmentTotal()
.- Parameters:
fulfillment
- the fulfillment to get the item fulfillment proportions for- Returns:
- map of
OrderFulfillmentItem.getId()
to the proportion that item contributes to theOrderFulfillment.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 eachOrderFulfillmentItem
infulfillment
contributes to a certain total based on the item'sgetPartOfTotal
.- Parameters:
fulfillment
- the fulfillment to get the item total proportions forgetPartOfTotal
- function to retrieve the amount aOrderFulfillmentItem
contributes to theOrderFulfillment's
total- Returns:
- map of
OrderFulfillmentItem.getId()
to the proportion that item contributes to theOrderFulfillment'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 acrossReturnAuthorizationItems
based on the givenprorationProportions
for their matchingOrderFulfillmentItems
.- Parameters:
amount
- the amount to be prorated acrossreturnAuthorizationItems
returnAuthorizationItems
- the return items to receive the prorated amountsprorationProportions
- map ofOrderFulfillmentItem.getId()
to the proportion of theamount
its return item should receivegetItemAmount
- function to retrieve the current value on aReturnAuthorizationItem
to which the prorated amount should be addedsetItemAmount
- function to set the value on aReturnAuthorizationItem
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)
GeneratesReturnAuthorizationItems
for all of the items in thefulfillmentToReturn
andreturnItemRequests
which are not already present inexistingReturnItems
.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
- theDefaultReturnGenerationService.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'soriginalTotal
and the total ofgetItemAmount
across all the existing and newReturnAuthorizationItems
. If there is a discrepancy, then distribute the amount missing from the total to refund across the newreturnAuthorizationItems
.- Parameters:
originalTotal
- the original fulfillment tax totalfulfillmentPartToReturn
- the fulfillment containing the items requested to returnexistingReturnItems
- map ofOrderFulfillmentItem.getId()
to existing return itemsreturnAuthorizationItems
- the new return items, which will receive any prorated missing total to refundsplitProportions
- map ofOrderFulfillmentItem.getId()
to the proportion of the missing amount its return item should receivegetItemAmount
- function to retrieve the current value on aReturnAuthorizationItem
to which the prorated amount should be addedsetItemAmount
- function to set the value on aReturnAuthorizationItem
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 theReturnAuthorizationItems
.- Parameters:
returnItems
- the return items containing totals to be roundedcurrency
- 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 theReturnAuthorizationItems
. 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 toReturnAuthorizationItem.getEstimatedTotalToRefund()
. Ensures each item's rounded totals add up to itsReturnAuthorizationItem.getEstimatedTotalToRefund()
, and that the sum of each total across all items doesn't change.- Parameters:
returnItems
- the return items containing totals to be roundedcurrency
- 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 theReturnAuthorization
by adding up the totals of itsReturnAuthorization.getItems()
.- Specified by:
calculateEstimatedTotals
in interfaceReturnGenerationService
- 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 estimatedReturnAuthorization.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 theReturnAuthorization.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
-
getGenerateReturnHydrationResult
protected DefaultReturnGenerationService.GenerateReturnHydrationResult getGenerateReturnHydrationResult(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>> existingReturnItemsByItemId)
Builds aDefaultReturnGenerationService.GenerateReturnHydrationResult
based on the given parameters.- Parameters:
order
- theOrder
where the items being returned are fromfulfillment
- theOrderFulfillment
containing the items being returnedreturnItemRequests
- a list ofReturnItemRequests
for the given fulfillmentexistingReturnItemsByItemId
- a map of existing return items byOrderFulfillmentItem.getId()
- Returns:
- a hydrated
DefaultReturnGenerationService.GenerateReturnHydrationResult
from the given parameters
-
getSplittingService
protected FulfillmentSplittingService<com.broadleafcommerce.order.client.domain.OrderFulfillment> getSplittingService()
-
getHelper
protected FulfillmentOperationHelper getHelper()
-
getRoundingHelper
protected SplitRoundingHelper getRoundingHelper()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getOfferUtils
protected OrderOperationServiceOfferUtils getOfferUtils()
-
setOfferUtils
@Autowired public void setOfferUtils(OrderOperationServiceOfferUtils offerUtils)
-
-