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>
- Type Parameters:
C-Cart, or a subtypeO-Order, or a subtypeF-OrderFulfillment, or a subtype
- All Implemented Interfaces:
CartOrderFulfillmentGenerationService<C,O, F>
CartOrderFulfillmentGenerationService.- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultCartOrderFulfillmentGenerationService(FulfillmentProvider<F> fulfillmentProvider, FulfillmentSplittingService<F> fulfillmentSplittingService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderGenerationProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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) 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.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>protected FulfillmentSplittingService<F>protected OrderOperationServiceOfferUtilsOrderFulfillmentItemwill 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 OrderGenerationPropertiesprotected com.broadleafcommerce.common.extension.TypeFactoryprotected IntegernextInFulfillmentSequence(String key, Integer sequence) voidsetOfferUtils(OrderOperationServiceOfferUtils offerUtils) splitFulfillmentByVendor(F fulfillment, Map<String, String> vendorsByOrderItemId) splitFulfillmentsByVendor(List<F> fulfillments, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) 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 final javax.money.MonetaryAmountzeroIfNull(javax.money.MonetaryAmount amount, javax.money.CurrencyUnit currency) Defaults theamountto zero if null.
-
Constructor Details
-
DefaultCartOrderFulfillmentGenerationService
public DefaultCartOrderFulfillmentGenerationService(FulfillmentProvider<F> fulfillmentProvider, FulfillmentSplittingService<F> fulfillmentSplittingService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderGenerationProperties properties)
-
-
Method Details
-
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:
-
buildOrderFulfillments
-
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
-
assignOrderFulfillmentCurrency
-
calculateGrandTotal
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
-
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
-
splitFulfillmentByVendor
-
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
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
-
buildOrderFulfillmentNumber
-
findCurrency
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
-
getFulfillmentSplittingService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getProperties
-
getOfferUtils
-
setOfferUtils
-