Class DefaultCartOrderGenerationService<C extends com.broadleafcommerce.cart.client.domain.Cart,O extends com.broadleafcommerce.order.client.domain.Order>
- Type Parameters:
O- A subtype ofOrder
- All Implemented Interfaces:
CartOrderGenerationService<C,O>
CartOrderGenerationService-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected final OrderProvider<O> -
Constructor Summary
ConstructorsConstructorDescriptionDefaultCartOrderGenerationService(OrderProvider<O> orderProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderGenerationProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanadjustmentShouldBeProrated(com.broadleafcommerce.order.common.domain.Adjustment adjustment) Determines if the givenAdjustmentneeds to be prorated across offer qualifier and target items.protected com.broadleafcommerce.order.client.domain.OrderItembuildDependentOrderItemFromCartItem(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Build the dependentOrderItemfrom the given dependentCartItem.protected List<com.broadleafcommerce.order.client.domain.OrderItem>buildDependentOrderItemsFromCartItems(List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems) Build dependentOrderItemsfrom the given dependentCartItems.protected com.broadleafcommerce.order.client.domain.ImageAssetRefbuildImageAssetRef(com.broadleafcommerce.cart.client.domain.CartItem cartItem) protected ObuildOrderFromCart(C cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Build theOrderfrom the givenCart.protected com.broadleafcommerce.order.client.domain.OrderItembuildOrderItemFromCartItem(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Build anOrderItemfrom the givenCartItem.protected List<com.broadleafcommerce.order.client.domain.OrderItem>buildOrderItemsFromCart(C cart, O order) Build theOrderItemsfor the givenCart.protected com.broadleafcommerce.order.client.domain.OrderPricingbuildOrderPricingFromCart(C cart) Build theOrderPricingfor the givenCart.generateOrderFromCart(C cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates and persists a newOrderfrom the given cart if such an order does not already exist or returns the existingOrder.protected Map<com.broadleafcommerce.order.client.domain.OrderItem,List<com.broadleafcommerce.order.common.domain.Adjustment>> getAdjustmentsByTargetItemWithQualifierItemId(List<com.broadleafcommerce.order.client.domain.OrderItem> orderItems, String qualifierItemId) Gets a map ofAdjustmentsby offer targetOrderItemwhoseAdjustment.getQualifierDetails()is referencing the given offer qualifier item id.protected StringgetCartCustomerName(C cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Get the customer's name from the cart.protected StringgetLatestCheckoutRequestId(C cart) Gets the latest checkout request id for the givenCart.protected OrderOperationServiceOfferUtilsgetOrderItemsByOriginalCartItemIds(List<com.broadleafcommerce.order.client.domain.OrderItem> orderItems) Gets a map ofOrderItemsby their originalCartItem.getId().protected OrderOperationServicePropertiesprotected OrderProvider<O>protected StringgetOriginalCartItemIdFromAttributes(com.broadleafcommerce.order.client.domain.OrderItem item) protected PaymentDistributionServiceprotected PaymentProviderprotected OrderGenerationPropertiesprotected javax.money.MonetaryAmountgetQualifierItemDistributedDiscount(com.broadleafcommerce.order.common.domain.Adjustment adjustment, com.broadleafcommerce.order.client.domain.OrderItem qualifierItem, com.broadleafcommerce.order.client.domain.OrderItem targetItem, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemById) Gets the proportionally distributed discount for the given offer qualifier item based on its price ratio.protected javax.money.MonetaryAmountgetQualifierItemsUnadjustedTotal(com.broadleafcommerce.order.common.domain.Adjustment adjustment, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemById) Gets the unadjusted item total of all the offer qualifierOrderItems.protected javax.money.MonetaryAmountgetTargetItemDistributedDiscount(com.broadleafcommerce.order.common.domain.Adjustment adjustment, com.broadleafcommerce.order.client.domain.OrderItem targetItem, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemById) Gets the proportionally distributed discount for the given offer target item based on its price ratio.protected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanorderExistsForCart(C cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated.protected voidpopulatePaymentDistributionDetails(C cart, O order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) PopulatesPaymentDistributionDetailsfor theOrder.protected voidprecalculateRefundAmounts(O order, List<com.broadleafcommerce.order.client.domain.OrderItem> orderItems) Pre-calculates and setsOrderItem.getRefundAmount()based on itsOrderItem.getProratedOrderAdjustments()andOrderItem.getItemAdjustments()and their offer qualifier and target items.protected OreadOrderForCart(C cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads theOrderfor the specified cart.voidsetOfferUtils(OrderOperationServiceOfferUtils offerUtils) voidsetOrderOperationServiceProperties(OrderOperationServiceProperties orderOperationServiceProperties) voidsetPaymentDistributionService(PaymentDistributionService paymentDistributionService) voidsetPaymentProvider(PaymentProvider paymentProvider) protected voidupdateOfferQualifierOrderItemDetails(List<com.broadleafcommerce.order.client.domain.OrderItem> orderItemsWithDependentOrderItems) Updates the offer qualifierOfferItemDetailsthat were copied fromCartItemsinOrderItemsto useOrderItem.getId()asOfferItemDetail.getItemId().protected voidupdateOrderItemTotalsForVat(C cart, List<com.broadleafcommerce.order.client.domain.OrderItem> orderItems)
-
Field Details
-
ORDER_ITEM_TYPE_ATTR
- See Also:
-
ORDER_ITEM_DEPENDENT_ITEM_DETAILS_ATTR
- See Also:
-
orderProvider
protected final OrderProvider<O extends com.broadleafcommerce.order.client.domain.Order> orderProvider
-
-
Constructor Details
-
DefaultCartOrderGenerationService
public DefaultCartOrderGenerationService(OrderProvider<O> orderProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderGenerationProperties properties)
-
-
Method Details
-
generateOrderFromCart
public O generateOrderFromCart(C cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartOrderGenerationServiceCreates and persists a newOrderfrom the given cart if such an order does not already exist or returns the existingOrder.- Specified by:
generateOrderFromCartin interfaceCartOrderGenerationService<C extends com.broadleafcommerce.cart.client.domain.Cart,O extends com.broadleafcommerce.order.client.domain.Order> - Parameters:
cart- The cart to create an order fromcontextInfo- the context around sandboxing and multitenant state- Returns:
- The order created from the cart, or existing order if it is already exists
-
readOrderForCart
@Nullable protected O readOrderForCart(C cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads theOrderfor the specified cart.- Parameters:
cart- The cart to check for an already created ordercontextInfo- the context around sandboxing and multitenant state- Returns:
- the order with the given cart ID
-
orderExistsForCart
@Deprecated(since="1.7.2") protected boolean orderExistsForCart(C cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated.in favour ofreadOrderForCart(Cart, ContextInfo)Determine whether anOrderhas already been created for theCart.- Parameters:
cart- The cart to check for an already created ordercontextInfo- the context around sandboxing and multitenant state- Returns:
- Whether an order has already been created for the cart
-
buildOrderFromCart
protected O buildOrderFromCart(C cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Build theOrderfrom the givenCart.- Parameters:
cart- The cart to build the order from- Returns:
- The built order
-
getCartCustomerName
@Nullable protected String getCartCustomerName(C cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Get the customer's name from the cart. If there is no customer, use a name from the first payment's billing address.- Parameters:
cart- The cart from which to get the customer's name- Returns:
- The name of the customer for the cart
-
getLatestCheckoutRequestId
Gets the latest checkout request id for the givenCart.- Parameters:
cart- theCartto get the latest checkout request id from- Returns:
- the latest checkout request id for the given
Cart
-
buildOrderPricingFromCart
@Nullable protected com.broadleafcommerce.order.client.domain.OrderPricing buildOrderPricingFromCart(C cart) Build theOrderPricingfor the givenCart.- Parameters:
cart- The cart to build order pricing from- Returns:
- The build order pricing
-
buildOrderItemsFromCart
protected List<com.broadleafcommerce.order.client.domain.OrderItem> buildOrderItemsFromCart(C cart, O order) Build theOrderItemsfor the givenCart.- Parameters:
cart- The cart containing items to build the order items fromorder- The order to which the order items should belong- Returns:
- The built order items
-
updateOrderItemTotalsForVat
-
updateOfferQualifierOrderItemDetails
protected void updateOfferQualifierOrderItemDetails(List<com.broadleafcommerce.order.client.domain.OrderItem> orderItemsWithDependentOrderItems) Updates the offer qualifierOfferItemDetailsthat were copied fromCartItemsinOrderItemsto useOrderItem.getId()asOfferItemDetail.getItemId().- Parameters:
orderItemsWithDependentOrderItems- a list ofOrderItemsto update offer qualifier order item details for
-
precalculateRefundAmounts
protected void precalculateRefundAmounts(O order, List<com.broadleafcommerce.order.client.domain.OrderItem> orderItems) Pre-calculates and setsOrderItem.getRefundAmount()based on itsOrderItem.getProratedOrderAdjustments()andOrderItem.getItemAdjustments()and their offer qualifier and target items. Any custom refund calculation logic should be added here.By default, the refund amount is the unadjusted item price minus the proportionally distributed discount for each item based on their price ratio, minus the prorated order discounts, using these formulas:
price ratio = (unadjusted price of the item / total price of qualifier and target items before offer adjustment)proportionally distributed discount = price ratio * total discountrefund amount = item unadjusted price - distributed discount - prorated order discounts.Note that the item offer discount distribution is only done for
Adjustmentswhose offer hasDefaultOfferProrationType.TARGET_AND_QUALIFIERasOfferRef.getProrationType().For
AdjustmentswithDefaultOfferProrationType.TARGET_ONLYasOfferRef.getProrationType(), the refund amount for qualifiers would be the price of the item, and for targets would be the price of the item minus the discount.- Parameters:
order- theOrderthat theOrderItemsbelong toorderItems- a list ofOrderItemsto calculate and set the refund amounts for- See Also:
-
DefaultOfferProrationType
-
populatePaymentDistributionDetails
protected void populatePaymentDistributionDetails(@NonNull C cart, @NonNull O order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) PopulatesPaymentDistributionDetailsfor theOrder.- Parameters:
cart- theCartorder- theOrderto populate thePaymentDistributionDetailsforcontextInfo- the context around sandboxing and multitenant state
-
getAdjustmentsByTargetItemWithQualifierItemId
protected Map<com.broadleafcommerce.order.client.domain.OrderItem,List<com.broadleafcommerce.order.common.domain.Adjustment>> getAdjustmentsByTargetItemWithQualifierItemId(List<com.broadleafcommerce.order.client.domain.OrderItem> orderItems, String qualifierItemId) Gets a map ofAdjustmentsby offer targetOrderItemwhoseAdjustment.getQualifierDetails()is referencing the given offer qualifier item id.Note that any
OrderItemswithAdjustmentsare considered offer "targets".- Parameters:
orderItems- theOrderItemsto build the map forqualifierItemId- the qualifierOfferItemDetail.getItemId()to filter theAdjustment.getQualifierDetails()with- Returns:
- a map of
Adjustmentsby targetOrderItemwhoseAdjustment.getQualifierDetails()is referencing the given qualifier item id
-
getTargetItemDistributedDiscount
protected javax.money.MonetaryAmount getTargetItemDistributedDiscount(com.broadleafcommerce.order.common.domain.Adjustment adjustment, com.broadleafcommerce.order.client.domain.OrderItem targetItem, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemById) Gets the proportionally distributed discount for the given offer target item based on its price ratio.- Parameters:
adjustment- theAdjustmentto proratetargetItem- the targetOrderItemreceiving the discountorderItemById- a map ofOrderItembyOrderItem.getId()- Returns:
- the proportionally distributed discount for the given offer target item based on its price ratio
-
getQualifierItemDistributedDiscount
protected javax.money.MonetaryAmount getQualifierItemDistributedDiscount(com.broadleafcommerce.order.common.domain.Adjustment adjustment, com.broadleafcommerce.order.client.domain.OrderItem qualifierItem, com.broadleafcommerce.order.client.domain.OrderItem targetItem, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemById) Gets the proportionally distributed discount for the given offer qualifier item based on its price ratio.- Parameters:
adjustment- theAdjustmentto proratequalifierItem- the qualifierOrderItemthat the discount should be prorated totargetItem- the targetOrderItemthat was originally targeted for the discountorderItemById- a map ofOrderItembyOrderItem.getId()- Returns:
- the proportionally distributed discount for the given offer qualifier item based on its price ratio
-
adjustmentShouldBeProrated
protected boolean adjustmentShouldBeProrated(com.broadleafcommerce.order.common.domain.Adjustment adjustment) Determines if the givenAdjustmentneeds to be prorated across offer qualifier and target items.- Parameters:
adjustment- theAdjustmentto check against- Returns:
- true if the given
Adjustmentneeds to be prorated across qualifier and target items, otherwise false
-
getQualifierItemsUnadjustedTotal
protected javax.money.MonetaryAmount getQualifierItemsUnadjustedTotal(com.broadleafcommerce.order.common.domain.Adjustment adjustment, Map<String, com.broadleafcommerce.order.client.domain.OrderItem> orderItemById) Gets the unadjusted item total of all the offer qualifierOrderItems.This is useful to calculate the price ratio when prorating offer discounts.
- Parameters:
adjustment- theAdjustmentto get the qualifier items fromorderItemById- a map ofOrderItembyOrderItem.getId()- Returns:
- the unadjusted item total of all the offer qualifier
OrderItems
-
getOrderItemsByOriginalCartItemIds
protected Map<String,com.broadleafcommerce.order.client.domain.OrderItem> getOrderItemsByOriginalCartItemIds(List<com.broadleafcommerce.order.client.domain.OrderItem> orderItems) Gets a map ofOrderItemsby their originalCartItem.getId().- Parameters:
orderItems- the list ofOrderItemsto build the map from- Returns:
- a map from originally-received-cart-item-ids to
OrderItems
-
getOriginalCartItemIdFromAttributes
protected String getOriginalCartItemIdFromAttributes(com.broadleafcommerce.order.client.domain.OrderItem item) -
buildOrderItemFromCartItem
protected com.broadleafcommerce.order.client.domain.OrderItem buildOrderItemFromCartItem(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Build anOrderItemfrom the givenCartItem.- Parameters:
cartItem- The cart item to build an order item from- Returns:
- The built order item
-
buildImageAssetRef
@Nullable protected com.broadleafcommerce.order.client.domain.ImageAssetRef buildImageAssetRef(com.broadleafcommerce.cart.client.domain.CartItem cartItem) -
buildDependentOrderItemsFromCartItems
protected List<com.broadleafcommerce.order.client.domain.OrderItem> buildDependentOrderItemsFromCartItems(List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems) Build dependentOrderItemsfrom the given dependentCartItems.- Parameters:
cartItems- The dependent cart items to build dependent order items from- Returns:
- The built dependent order items
-
buildDependentOrderItemFromCartItem
protected com.broadleafcommerce.order.client.domain.OrderItem buildDependentOrderItemFromCartItem(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Build the dependentOrderItemfrom the given dependentCartItem.- Parameters:
cartItem- The dependent cart item to build a dependent order item from- Returns:
- The built dependent order item
-
getOrderProvider
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getOfferUtils
-
setOfferUtils
-
getPaymentProvider
-
setPaymentProvider
-
getProperties
-
getOrderOperationServiceProperties
-
setOrderOperationServiceProperties
@Autowired public void setOrderOperationServiceProperties(OrderOperationServiceProperties orderOperationServiceProperties) -
getPaymentDistributionService
-
setPaymentDistributionService
@Autowired public void setPaymentDistributionService(PaymentDistributionService paymentDistributionService)
-
readOrderForCart(Cart, ContextInfo)