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)
  • 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:
    • buildOrderFulfillments

      protected List<F> buildOrderFulfillments(@NonNull C cart, @NonNull O order)
    • 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)
      Calculates the OrderFulfillment.getGrandTotal() and sets it.
      Parameters:
      fulfillment - The OrderFulfillment 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

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