Class DefaultCartOrderFulfillmentGenerationService<C extends com.broadleafcommerce.cart.client.domain.Cart,O extends com.broadleafcommerce.order.client.domain.Order,F extends com.broadleafcommerce.order.client.domain.OrderFulfillment>
- java.lang.Object
 - 
- com.broadleafcommerce.orderoperation.service.generate.DefaultCartOrderFulfillmentGenerationService<C,O,F>
 
 
- 
- Type Parameters:
 C-Cart, or a subtypeO-Order, or a subtypeF-OrderFulfillment, or a subtype
- All Implemented Interfaces:
 CartOrderFulfillmentGenerationService<C,O,F>
public class DefaultCartOrderFulfillmentGenerationService<C extends com.broadleafcommerce.cart.client.domain.Cart,O extends com.broadleafcommerce.order.client.domain.Order,F extends com.broadleafcommerce.order.client.domain.OrderFulfillment> extends Object implements CartOrderFulfillmentGenerationService<C,O,F>
Default implementation ofCartOrderFulfillmentGenerationService.- Author:
 - Samarth Dhruva (samarthd)
 
 
- 
- 
Constructor Summary
Constructors Constructor Description DefaultCartOrderFulfillmentGenerationService(FulfillmentProvider<F> fulfillmentProvider, FulfillmentSplittingService<F> fulfillmentSplittingService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderGenerationProperties properties) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFulfillmentOrderTaxDetails(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem orderFulfillmentItem, com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem)protected voidassignOrderFulfillmentCurrency(O order, F orderFulfillment)protected voidassignOrderFulfillmentNumbers(List<F> fulfillments)Assigns theorderFulfillmentNumbersfor the generatedfulfillments.protected FbuildOrderFulfillment(com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, O order, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds)protected com.broadleafcommerce.order.client.domain.OrderFulfillmentItembuildOrderFulfillmentItem(com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds, javax.money.CurrencyUnit currency)protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>buildOrderFulfillmentItems(List<com.broadleafcommerce.cart.client.domain.FulfillmentItem> fulfillmentItems, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds, javax.money.CurrencyUnit currency)protected StringbuildOrderFulfillmentNumber(String key, Integer sequence)protected List<F>buildOrderFulfillments(C cart, O order)protected javax.money.MonetaryAmountcalculateFulfillmentItemRefundAmount(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, @NonNull javax.money.CurrencyUnit currency)Determines how much of the fulfillment cost of the item should be refunded if a refund is initiated.protected voidcalculateGrandTotal(F fulfillment)Calculates theOrderFulfillment.getGrandTotal()and sets it.protected Optional<javax.money.CurrencyUnit>findCurrency(O order)Finds theCurrencyUnitonorderif present.List<F>generateFulfillmentsFromCart(C cart, O order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Generates and inserts oneOrderFulfillment(and correspondingOrderFulfillmentItems) for each ofCart.getFulfillmentGroups().protected FulfillmentProvider<F>getFulfillmentProvider()protected FulfillmentSplittingService<F>getFulfillmentSplittingService()protected OrderOperationServiceOfferUtilsgetOfferUtils()protected Map<String,com.broadleafcommerce.order.client.domain.OrderItem>getOrderItemsByOriginalCartItemIds(O order)OrderFulfillmentItemwill need to have itsOrderFulfillmentItem.getOrderItemId()value set to the id of theOrderItemthat was created for aFulfillmentItem.getCartItemId(), as well as some other fields from theOrderItem.protected StringgetOriginalCartItemIdFromAttributes(com.broadleafcommerce.order.client.domain.OrderItem item)protected OrderGenerationPropertiesgetProperties()protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected IntegernextInFulfillmentSequence(String key, Integer sequence)voidsetOfferUtils(OrderOperationServiceOfferUtils offerUtils)protected List<F>splitFulfillmentByVendor(F fulfillment, Map<String,String> vendorsByOrderItemId)protected List<F>splitFulfillmentsByVendor(List<F> fulfillments, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds)protected List<F>splitGeneratedFulfillments(F fulfillment, List<List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>> itemSplits)Splits the fulfillment into multiple, one for each group ofOrderFulfillmentItemsinitemSplits.protected voidupdateOfferQualifierFulfillmentItemDetails(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> orderFulfillmentItems, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds)protected javax.money.MonetaryAmountzeroIfNull(javax.money.MonetaryAmount amount, javax.money.CurrencyUnit currency)Defaults theamountto zero if null. 
 - 
 
- 
- 
Constructor Detail
- 
DefaultCartOrderFulfillmentGenerationService
public DefaultCartOrderFulfillmentGenerationService(FulfillmentProvider<F> fulfillmentProvider, FulfillmentSplittingService<F> fulfillmentSplittingService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderGenerationProperties properties)
 
 - 
 
- 
Method Detail
- 
generateFulfillmentsFromCart
public List<F> generateFulfillmentsFromCart(@NonNull C cart, @NonNull O order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Generates and inserts oneOrderFulfillment(and correspondingOrderFulfillmentItems) for each ofCart.getFulfillmentGroups().- Specified by:
 generateFulfillmentsFromCartin interfaceCartOrderFulfillmentGenerationService<C extends com.broadleafcommerce.cart.client.domain.Cart,O extends com.broadleafcommerce.order.client.domain.Order,F extends com.broadleafcommerce.order.client.domain.OrderFulfillment>- Parameters:
 cart- the cart to create order fulfillments fromorder- the order the fulfillments should be associated with. Should be a fully fleshed-out instance from the data store with its fields populated.contextInfo- the context around sandboxing and multitenant state- Returns:
 - a list of all the newly created 
OrderFulfillments. Guaranteed non-null, but may be empty depending onCart.getFulfillmentGroups(). - See Also:
 CheckoutCompletionListener,CartOrderGenerationService.generateOrderFromCart(Cart, ContextInfo),generateFulfillmentsFromCart(Cart, Order, ContextInfo)
 
- 
getOrderItemsByOriginalCartItemIds
protected Map<String,com.broadleafcommerce.order.client.domain.OrderItem> getOrderItemsByOriginalCartItemIds(O order)
OrderFulfillmentItemwill need to have itsOrderFulfillmentItem.getOrderItemId()value set to the id of theOrderItemthat was created for aFulfillmentItem.getCartItemId(), as well as some other fields from theOrderItem. This method builds a map from originally-received cart-item-id toOrderItemthat can be used to correctly set these values.- Parameters:
 order- the order whoseOrder.getOrderItems()should be used as the source of information to build the id mappings- Returns:
 - a map from originally-received-cart-item-ids to 
OrderItems 
 
- 
getOriginalCartItemIdFromAttributes
protected String getOriginalCartItemIdFromAttributes(com.broadleafcommerce.order.client.domain.OrderItem item)
 
- 
buildOrderFulfillment
protected F buildOrderFulfillment(com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, O order, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds)
 
- 
assignOrderFulfillmentCurrency
protected void assignOrderFulfillmentCurrency(O order, F orderFulfillment)
 
- 
calculateGrandTotal
protected void calculateGrandTotal(@NonNull F fulfillment)Calculates theOrderFulfillment.getGrandTotal()and sets it.- Parameters:
 fulfillment- TheOrderFulfillmentfor which to calculate the grand total
 
- 
buildOrderFulfillmentItems
protected List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> buildOrderFulfillmentItems(@Nullable List<com.broadleafcommerce.cart.client.domain.FulfillmentItem> fulfillmentItems, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds, javax.money.CurrencyUnit currency)
 
- 
updateOfferQualifierFulfillmentItemDetails
protected void updateOfferQualifierFulfillmentItemDetails(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> orderFulfillmentItems, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds)
 
- 
buildOrderFulfillmentItem
protected com.broadleafcommerce.order.client.domain.OrderFulfillmentItem buildOrderFulfillmentItem(com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds, javax.money.CurrencyUnit currency) 
- 
addFulfillmentOrderTaxDetails
protected void addFulfillmentOrderTaxDetails(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem orderFulfillmentItem, com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem) 
- 
splitFulfillmentsByVendor
protected List<F> splitFulfillmentsByVendor(List<F> fulfillments, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, Map<String,com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds)
 
- 
splitFulfillmentByVendor
protected List<F> splitFulfillmentByVendor(F fulfillment, Map<String,String> vendorsByOrderItemId)
 
- 
splitGeneratedFulfillments
protected List<F> splitGeneratedFulfillments(F fulfillment, List<List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>> itemSplits)
Splits the fulfillment into multiple, one for each group ofOrderFulfillmentItemsinitemSplits.Used in
splitFulfillmentsByVendor(List, List, Map)by default. Any custom splitting methodology can also utilize this to perform the split.- Parameters:
 fulfillment- the fulfillment to be split into multipleitemSplits- multiple lists ofOrderFulfillmentItems, each of which should be placed into its own fulfillment- Returns:
 - the fulfillments which have been split
 
 
- 
assignOrderFulfillmentNumbers
protected void assignOrderFulfillmentNumbers(List<F> fulfillments)
Assigns theorderFulfillmentNumbersfor the generatedfulfillments.For fulfillments with vendors, the number consists of the vendor reference, then a sequenced integer based on how many fulfillments share that vendor in this order. For example,
VENDOR-1andVENDOR-2.For fulfillments without vendors, the fulfillment option name will be used instead of the vendor reference. For example,
SHIPPING-1andSHIPPING-2.- Parameters:
 fulfillments- the generated fulfillments to assign new numbers for
 
- 
calculateFulfillmentItemRefundAmount
protected javax.money.MonetaryAmount calculateFulfillmentItemRefundAmount(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, @NonNull @NonNull javax.money.CurrencyUnit currency)Determines how much of the fulfillment cost of the item should be refunded if a refund is initiated. By default, this is the fulfillment item's total less the prorated, fulfillment- group adjustments.Moreover, by default the
OrderFulfillment.getFulfillmentAdjustmentsTotal()will be prorated among both the fulfillment and the fulfillment items. This is because the fulfillment itself might have a charge on top of whatever fulfillment charges are calculated for the items.- Parameters:
 fulfillmentItem- Item whose refundable amount is to be calculated.- Returns:
 - The refundable amount for the fulfillment of the item.
 
 
- 
nextInFulfillmentSequence
protected Integer nextInFulfillmentSequence(String key, Integer sequence)
 
- 
buildOrderFulfillmentNumber
protected String buildOrderFulfillmentNumber(String key, Integer sequence)
 
- 
findCurrency
protected Optional<javax.money.CurrencyUnit> findCurrency(@NonNull O order)
Finds theCurrencyUnitonorderif present.- Parameters:
 order- TheOrderwhose currency to find- Returns:
 - the 
CurrencyUnitonorderif present or elseOptional.empty(). 
 
- 
zeroIfNull
protected final javax.money.MonetaryAmount zeroIfNull(@Nullable javax.money.MonetaryAmount amount, @Nullable javax.money.CurrencyUnit currency)Defaults theamountto zero if null.- Parameters:
 amount- TheMonetaryAmountto default to zerocurrency- Theamount'sCurrencyUnit- Returns:
 - The 
amountor zero if null. 
 
- 
getFulfillmentProvider
protected FulfillmentProvider<F> getFulfillmentProvider()
 
- 
getFulfillmentSplittingService
protected FulfillmentSplittingService<F> getFulfillmentSplittingService()
 
- 
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
 
- 
getProperties
protected OrderGenerationProperties getProperties()
 
- 
getOfferUtils
protected OrderOperationServiceOfferUtils getOfferUtils()
 
- 
setOfferUtils
@Autowired public void setOfferUtils(OrderOperationServiceOfferUtils offerUtils)
 
 - 
 
 -