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
ConstructorDescriptionDefaultCartOrderFulfillmentGenerationService
(FulfillmentProvider<F> fulfillmentProvider, FulfillmentSplittingService<F> fulfillmentSplittingService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderGenerationProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addFulfillmentOrderTaxDetails
(com.broadleafcommerce.order.client.domain.OrderFulfillmentItem orderFulfillmentItem, com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem) protected void
assignOrderFulfillmentCurrency
(O order, F orderFulfillment) protected void
assignOrderFulfillmentNumbers
(List<F> fulfillments) Assigns theorderFulfillmentNumbers
for the generatedfulfillments
.protected F
buildOrderFulfillment
(com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, O order, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) 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) 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 String
buildOrderFulfillmentNumber
(String key, Integer sequence) buildOrderFulfillments
(C cart, O order) protected javax.money.MonetaryAmount
calculateFulfillmentItemRefundAmount
(@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 void
calculateGrandTotal
(F fulfillment) Calculates theOrderFulfillment.getGrandTotal()
and sets it.protected Optional<javax.money.CurrencyUnit>
findCurrency
(O order) Finds theCurrencyUnit
onorder
if 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 OrderOperationServiceOfferUtils
OrderFulfillmentItem
will need to have itsOrderFulfillmentItem.getOrderItemId()
value set to the id of theOrderItem
that was created for aFulfillmentItem.getCartItemId()
, as well as some other fields from theOrderItem
.protected String
getOriginalCartItemIdFromAttributes
(com.broadleafcommerce.order.client.domain.OrderItem item) protected OrderGenerationProperties
protected com.broadleafcommerce.common.extension.TypeFactory
protected Integer
nextInFulfillmentSequence
(String key, Integer sequence) void
setOfferUtils
(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 ofOrderFulfillmentItems
initemSplits
.protected void
updateOfferQualifierFulfillmentItemDetails
(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> orderFulfillmentItems, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemsByOriginalCartItemIds) protected final javax.money.MonetaryAmount
zeroIfNull
(javax.money.MonetaryAmount amount, javax.money.CurrencyUnit currency) Defaults theamount
to 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:
generateFulfillmentsFromCart
in 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) OrderFulfillmentItem
will need to have itsOrderFulfillmentItem.getOrderItemId()
value set to the id of theOrderItem
that was created for aFulfillmentItem.getCartItemId()
, as well as some other fields from theOrderItem
. This method builds a map from originally-received cart-item-id toOrderItem
that 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
- TheOrderFulfillment
for 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 ofOrderFulfillmentItems
initemSplits
.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 theorderFulfillmentNumbers
for 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-1
andVENDOR-2
.For fulfillments without vendors, the fulfillment option name will be used instead of the vendor reference. For example,
SHIPPING-1
andSHIPPING-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 theCurrencyUnit
onorder
if present.- Parameters:
order
- TheOrder
whose currency to find- Returns:
- the
CurrencyUnit
onorder
if present or elseOptional.empty()
.
-
zeroIfNull
protected final javax.money.MonetaryAmount zeroIfNull(@Nullable javax.money.MonetaryAmount amount, @Nullable javax.money.CurrencyUnit currency) Defaults theamount
to zero if null.- Parameters:
amount
- TheMonetaryAmount
to default to zerocurrency
- Theamount's
CurrencyUnit
- Returns:
- The
amount
or zero if null.
-
getFulfillmentProvider
-
getFulfillmentSplittingService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getProperties
-
getOfferUtils
-
setOfferUtils
-