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 subtype
O - Order, or a subtype
F - 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 of CartOrderFulfillmentGenerationService.
Author:
Samarth Dhruva (samarthd)
  • Field Details

  • Constructor Details

  • 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 one OrderFulfillment (and corresponding OrderFulfillmentItems) for each of Cart.getFulfillmentGroups().
      Specified by:
      generateFulfillmentsFromCart in interface CartOrderFulfillmentGenerationService<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 from
      order - 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 on Cart.getFulfillmentGroups().
      See Also:
    • readFulfillmentsByOrderId

      protected List<F> readFulfillmentsByOrderId(@NonNull O order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • buildOrderFulfillments

      protected List<F> buildOrderFulfillments(@NonNull C cart, @NonNull O order)
    • 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 generated OrderFulfillments based on the out-of-box properties.
      Parameters:
      generatedFulfillments - the generated OrderFulfillments to split
      cart - the original Cart that the OrderFulfillments are based on
      orderItemsByOriginalCartItemIds - a map of original cart item ids to OrderItems
      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 fulfillments
      cart - the original Cart
      orderItemsByOriginalCartItemIds - the map of OrderItem by 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 generated OrderFulfillments based on the given cart item attribute.
      Parameters:
      fulfillments - the generated OrderFulfillments to split
      cartItems - the original CartItems that the OrderFulfillments are based on
      orderItemsByOriginalCartItemIds - a map of original cart item ids to OrderItems
      cartItemAttrName - the name of the cart item attribute to split by
      useInternalAttributes - 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 the OrderFulfillment based on the cart item attribute.
      Parameters:
      fulfillment - the OrderFulfillment to split
      attributeValuesByOrderItemId - a map of order item ids to attribute values
      cartItemAttrName - 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)
      OrderFulfillmentItem will need to have its OrderFulfillmentItem.getOrderItemId() value set to the id of the OrderItem that was created for a FulfillmentItem.getCartItemId(), as well as some other fields from the OrderItem. This method builds a map from originally-received cart-item-id to OrderItem that can be used to correctly set these values.
      Parameters:
      order - the order whose Order.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)
      Calculate and set the OrderFulfillment.getGrandTotal() from merchandise, fulfillment, and tax values.
      Parameters:
      fulfillment - The OrderFulfillment for which to calculate the grand total
    • getAddedTaxTotal

      protected javax.money.MonetaryAmount getAddedTaxTotal(F fulfillment)
      Calculate the amount of tax that has not been included in merchandise or fulfillment prices. This is generally the amount of sales tax on the OrderFulfillment.
      Parameters:
      fulfillment - The OrderFulfillment whose 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

      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)
    • splitByServiceLevel

      protected List<F> splitByServiceLevel(F orderFulfillment)
      Split into multiple OrderFulfillment if there is more than one service level for all items in the group. See PricedFulfillmentOption.getServiceLevel().
      Parameters:
      orderFulfillment - The OrderFulfillment to 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 generated OrderFulfillments based on the vendor.

      If an OrderFulfillment has FULFILLMENT_WORKFLOW_ATTR specified, it will not be split by vendor.

      Parameters:
      fulfillments - the OrderFulfillments to split
      cartItems - the original CartItems
      orderItemsByOriginalCartItemIds - a map of original cart item ids to OrderItems
      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 generated OrderFulfillments based on subscriptions.
      Parameters:
      fulfillments - the OrderFulfillments to split
      cart - the original Cart that the OrderFulfillments are based on
      orderItemsByOriginalCartItemIds - a map of original cart item ids to OrderItems
      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 root OrderItems for which to build separate Subscriptions.
      Parameters:
      cart - the original Cart that the OrderFulfillments are based on
      orderItemsByOriginalCartItemIds - a map of original cart item ids to OrderItems
      Returns:
      The root OrderItems for which to build separate Subscriptions.
      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 root OrderItems for which to build separate Subscriptions.
      Parameters:
      cart - the original Cart that the OrderFulfillments are based on
      Returns:
      The root OrderItems for which to build separate Subscriptions.
      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 given CartItem is a Broadleaf-managed subscription item.

      Broadleaf-managed subscriptions require Broadleaf's SubscriptionOperation, Billing, and Workflow dependencies.

      Parameters:
      cartItem - The CartItem in question.
      Returns:
      Whether cartItem is a subscription.
    • splitFulfillmentBySubscription

      protected List<F> splitFulfillmentBySubscription(F fulfillment, Map<String,String> subscriptionRootItemIdByOrderItemId)
    • 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 generated OrderFulfillments based on the vendor.
      Parameters:
      fulfillments - the OrderFulfillments to split
      cartItems - the original CartItems
      orderItemsByOriginalCartItemIds - a map of original cart item ids to OrderItems
      Returns:
      the split OrderFulfillments
    • 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 of OrderFulfillmentItems in itemSplits.

      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 multiple
      itemSplits - multiple lists of OrderFulfillmentItems, 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 the orderFulfillmentNumbers for the generated fulfillments.

      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 and VENDOR-2.

      For fulfillments without vendors, the fulfillment option name will be used instead of the vendor reference. For example, SHIPPING-1 and SHIPPING-2.

      Parameters:
      fulfillments - the generated fulfillments to assign new numbers for
    • getFulfillmentOptionName

      protected String getFulfillmentOptionName(F fulfillment)
    • 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 the CurrencyUnit on order if present.
      Parameters:
      order - The Order whose currency to find
      Returns:
      the CurrencyUnit on order if present or else Optional.empty().
    • zeroIfNull

      protected final javax.money.MonetaryAmount zeroIfNull(@Nullable javax.money.MonetaryAmount amount, @Nullable javax.money.CurrencyUnit currency)
      Defaults the amount to zero if null.
      Parameters:
      amount - The MonetaryAmount to default to zero
      currency - The amount's CurrencyUnit
      Returns:
      The amount or 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)
    • getInclusiveTaxHelper

      protected InclusiveTaxHelper getInclusiveTaxHelper()
    • setInclusiveTaxHelper

      @Autowired public void setInclusiveTaxHelper(InclusiveTaxHelper inclusiveTaxHelper)