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)
-
Field Summary
Fields -
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) Calculate and set theOrderFulfillment.getGrandTotal()from merchandise, fulfillment, and tax values.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 javax.money.MonetaryAmountgetAddedTaxTotal(F fulfillment) Calculate the amount of tax that has not been included in merchandise or fulfillment prices.protected List<com.broadleafcommerce.cart.client.domain.CartItem>getCartItemWithDependentItems(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) protected StringgetFulfillmentOptionName(F fulfillment) protected FulfillmentProvider<F>protected FulfillmentSplittingService<F>protected InclusiveTaxHelperprotected 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 OrderGenerationPropertiesgetSubscriptionBundleTypedFulfillments(@NonNull List<F> generatedFulfillments, C cart, @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Gets a list of fulfillments that are subscription bundles.protected com.broadleafcommerce.common.extension.TypeFactoryidentifySubscriptionRootItemIdByOrderItemId(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Identifies the rootOrderItemsfor which to build separateSubscriptions.protected List<com.broadleafcommerce.cart.client.domain.CartItem>identifySubscriptionRootItems(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Identifies the rootOrderItemsfor which to build separateSubscriptions.protected booleanisSeparateFromPrimaryItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) booleanisSubscriptionItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Determines if the givenCartItemis a Broadleaf-managed subscription item.protected booleanitemIsBundleTypeProduct(@NonNull com.broadleafcommerce.order.client.domain.OrderItem orderItem) protected IntegernextInFulfillmentSequence(String key, Integer sequence) readFulfillmentsByOrderId(O order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) voidsetInclusiveTaxHelper(InclusiveTaxHelper inclusiveTaxHelper) voidsetOfferUtils(OrderOperationServiceOfferUtils offerUtils) splitByServiceLevel(F orderFulfillment) Split into multipleOrderFulfillmentif there is more than one service level for all items in the group.splitFulfillmentByCartItemAttribute(F fulfillment, @NonNull Map<String, String> attributeValuesByOrderItemId, @NonNull String cartItemAttrName) Split theOrderFulfillmentbased on the cart item attribute.splitFulfillmentBySubscription(F fulfillment, Map<String, String> subscriptionRootItemIdByOrderItemId) splitFulfillmentByVendor(F fulfillment, Map<String, String> vendorsByOrderItemId) splitFulfillments(@NonNull List<F> generatedFulfillments, C cart, @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Split the generatedOrderFulfillmentsbased on the out-of-box properties.splitFulfillmentsByCartItemAttribute(@NonNull List<F> fulfillments, @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds, @NonNull String cartItemAttrName, boolean useInternalAttributes) Split the generatedOrderFulfillmentsbased on the given cart item attribute.splitFulfillmentsByFulfillmentWorkflow(List<F> fulfillments, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Split the generatedOrderFulfillmentsbased on the vendor.splitFulfillmentsBySubscription(@NonNull List<F> fulfillments, C cart, @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Split the generatedOrderFulfillmentsbased on subscriptions.splitFulfillmentsByVendor(List<F> fulfillments, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Split the generatedOrderFulfillmentsbased on the vendor.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.
-
Field Details
-
FULFILLMENT_WORKFLOW_ATTR
- See Also:
-
-
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:
-
readFulfillmentsByOrderId
-
buildOrderFulfillments
-
splitFulfillments
protected List<F> splitFulfillments(@NonNull @NonNull List<F> generatedFulfillments, @NonNull C cart, @NonNull @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Split the generatedOrderFulfillmentsbased on the out-of-box properties.- Parameters:
generatedFulfillments- the generatedOrderFulfillmentsto splitcart- the originalCartthat theOrderFulfillmentsare based onorderItemsByOriginalCartItemIds- a map of original cart item ids toOrderItems- Returns:
- the split
OrderFulfillments
-
getSubscriptionBundleTypedFulfillments
protected List<F> getSubscriptionBundleTypedFulfillments(@NonNull @NonNull List<F> generatedFulfillments, @NonNull C cart, @NonNull @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Gets a list of fulfillments that are subscription bundles. The subscription bundle are handled differently because they are not split based on the fulfillment workflow. Instead, the subscription bundle itself has its own fulfillment workflow.- Parameters:
generatedFulfillments- the list of generated fulfillmentscart- the originalCartorderItemsByOriginalCartItemIds- the map ofOrderItemby their original cart item ids- Returns:
- a list of fulfillments that are subscription bundles.
- Since:
- Order Operation Service 2.2.0, Release Train 2.3.0
-
itemIsBundleTypeProduct
protected boolean itemIsBundleTypeProduct(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderItem orderItem) -
splitFulfillmentsByCartItemAttribute
protected List<F> splitFulfillmentsByCartItemAttribute(@NonNull @NonNull List<F> fulfillments, @NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, @NonNull @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds, @NonNull @NonNull String cartItemAttrName, boolean useInternalAttributes) Split the generatedOrderFulfillmentsbased on the given cart item attribute.- Parameters:
fulfillments- the generatedOrderFulfillmentsto splitcartItems- the originalCartItemsthat theOrderFulfillmentsare based onorderItemsByOriginalCartItemIds- a map of original cart item ids toOrderItemscartItemAttrName- the name of the cart item attribute to split byuseInternalAttributes- whether to use internal attributes or not- Returns:
- the split
OrderFulfillments
-
splitFulfillmentByCartItemAttribute
protected List<F> splitFulfillmentByCartItemAttribute(@NonNull F fulfillment, @NonNull @NonNull Map<String, String> attributeValuesByOrderItemId, @NonNull @NonNull String cartItemAttrName) Split theOrderFulfillmentbased on the cart item attribute.- Parameters:
fulfillment- theOrderFulfillmentto splitattributeValuesByOrderItemId- a map of order item ids to attribute valuescartItemAttrName- the name of the cart item attribute to split by- Returns:
- the split
OrderFulfillments
-
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
Calculate and set theOrderFulfillment.getGrandTotal()from merchandise, fulfillment, and tax values.- Parameters:
fulfillment- TheOrderFulfillmentfor which to calculate the grand total
-
getAddedTaxTotal
Calculate the amount of tax that has not been included in merchandise or fulfillment prices. This is generally the amount of sales tax on theOrderFulfillment.- Parameters:
fulfillment- TheOrderFulfillmentwhose taxable items should be checked.- Returns:
- The amount of excluded tax on all items in the given
OrderFulfillment.
-
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) -
splitByServiceLevel
Split into multipleOrderFulfillmentif there is more than one service level for all items in the group. SeePricedFulfillmentOption.getServiceLevel().- Parameters:
orderFulfillment- TheOrderFulfillmentto split- Returns:
- The List of
OrderFulfillment, with one OrderFulfillment per service level.
-
splitFulfillmentsByFulfillmentWorkflow
protected List<F> splitFulfillmentsByFulfillmentWorkflow(List<F> fulfillments, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Split the generatedOrderFulfillmentsbased on the vendor.If an
OrderFulfillmenthasFULFILLMENT_WORKFLOW_ATTRspecified, it will not be split by vendor.- Parameters:
fulfillments- theOrderFulfillmentsto splitcartItems- the originalCartItemsorderItemsByOriginalCartItemIds- a map of original cart item ids toOrderItems- Returns:
- the split
OrderFulfillments
-
splitFulfillmentsBySubscription
protected List<F> splitFulfillmentsBySubscription(@NonNull @NonNull List<F> fulfillments, @NonNull C cart, @NonNull @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Split the generatedOrderFulfillmentsbased on subscriptions.- Parameters:
fulfillments- theOrderFulfillmentsto splitcart- the originalCartthat theOrderFulfillmentsare based onorderItemsByOriginalCartItemIds- a map of original cart item ids toOrderItems- Returns:
- the split
OrderFulfillments - Since:
- Order Operation Service 2.2.0, Release Train 2.3.0
-
identifySubscriptionRootItemIdByOrderItemId
protected Map<String,String> identifySubscriptionRootItemIdByOrderItemId(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) Identifies the rootOrderItemsfor which to build separateSubscriptions.- Parameters:
cart- the originalCartthat theOrderFulfillmentsare based onorderItemsByOriginalCartItemIds- a map of original cart item ids toOrderItems- Returns:
- The root
OrderItemsfor which to build separateSubscriptions. - Since:
- Order Operation Service 2.2.0, Release Train 2.3.0
-
getCartItemWithDependentItems
protected List<com.broadleafcommerce.cart.client.domain.CartItem> getCartItemWithDependentItems(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) -
identifySubscriptionRootItems
protected List<com.broadleafcommerce.cart.client.domain.CartItem> identifySubscriptionRootItems(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Identifies the rootOrderItemsfor which to build separateSubscriptions.- Parameters:
cart- the originalCartthat theOrderFulfillmentsare based on- Returns:
- The root
OrderItemsfor which to build separateSubscriptions. - Since:
- Order Operation Service 2.2.0, Release Train 2.3.0
-
isSeparateFromPrimaryItem
protected boolean isSeparateFromPrimaryItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) -
isSubscriptionItem
public boolean isSubscriptionItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Determines if the givenCartItemis a Broadleaf-managed subscription item.Broadleaf-managed subscriptions require Broadleaf's SubscriptionOperation, Billing, and Workflow dependencies.
- Parameters:
cartItem- TheCartItemin question.- Returns:
- Whether
cartItemis a subscription.
-
splitFulfillmentBySubscription
-
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) Split the generatedOrderFulfillmentsbased on the vendor.- Parameters:
fulfillments- theOrderFulfillmentsto splitcartItems- the originalCartItemsorderItemsByOriginalCartItemIds- a map of original cart item ids toOrderItems- Returns:
- the split
OrderFulfillments
-
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
-
getFulfillmentOptionName
-
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
-
getInclusiveTaxHelper
-
setInclusiveTaxHelper
-