Class DefaultCartPricingService

    • Method Detail

      • priceCart

        public com.broadleafcommerce.cart.client.domain.Cart priceCart​(@NonNull
                                                                       com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                       @Nullable
                                                                       PriceCartRequest priceCartRequest,
                                                                       @Nullable
                                                                       com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartPricingService
        Price the cart with the provided locale and currency.
        Specified by:
        priceCart in interface CartPricingService
        Parameters:
        cart - The cart on which to perform the operation.
        priceCartRequest - optional info to be used when deciding how to price the cart
        contextInfo - the context info
        Returns:
        the priced cart
      • priceCartWithCatalogPriceUpdates

        public com.broadleafcommerce.cart.client.domain.Cart priceCartWithCatalogPriceUpdates​(@NonNull
                                                                                              com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                              @Nullable
                                                                                              com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartPricingService
        Reprice the cart, including applying the latest catalog-based prices for each of its items
        Specified by:
        priceCartWithCatalogPriceUpdates in interface CartPricingService
        Parameters:
        cart - The cart on which to perform the operation.
        contextInfo - the context info
        Returns:
        the priced cart
      • updateCatalogPricesForCartItems

        protected com.broadleafcommerce.cart.client.domain.Cart updateCatalogPricesForCartItems​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                                @Nullable
                                                                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      • buildProductIdList

        protected Set<String> buildProductIdList​(List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems)
      • applyPricesToCart

        protected com.broadleafcommerce.cart.client.domain.Cart applyPricesToCart​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                  ProductList productList)
      • cleanPriceInfo

        protected com.broadleafcommerce.pricing.client.domain.PriceInfo cleanPriceInfo​(@NonNull
                                                                                       @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
      • getPricingKey

        protected String getPricingKey​(Product product,
                                       com.broadleafcommerce.cart.client.domain.CartItem cartItem)
        Returns the product price key, if specified, otherwise retrieves it from the cart item or generates a new one. This in general only needed for the DefaultProductType.MERCHANDISING_PRODUCT as it doesn't have the SKU and pricing key.
        Parameters:
        product - the product to get the pricing key from
        cartItem - the cart item to get the pricing key from
        Returns:
        the pricing key
      • priceCart

        public com.broadleafcommerce.cart.client.domain.Cart priceCart​(@NonNull
                                                                       com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                       @Nullable
                                                                       PriceCartRequest priceCartRequest,
                                                                       boolean update,
                                                                       @Nullable
                                                                       com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartPricingService
        Price the cart with the provided locale and currency.

        1. Initialize pricing request
        2. Clear current pricing information from cart
        3. Update cart item pricing
          1. Retrieve prices from the pricing provider
          2. Calculate each item's subtotal
          3. Record whether each item was priced
        4. If the items were all priced, continue, otherwise mark the cart as un-priced, update, and return
        5. Calculate fulfillment pricing by calling the fulfillment pricing provider
        6. Apply adjustments by calling the offer provider
        7. Calculate the cart totals
        8. Record the cart as priced, update (if specified), and return
        Specified by:
        priceCart in interface CartPricingService
        Parameters:
        cart - The cart on which to perform the operation.
        priceCartRequest - optional info to be used when deciding how to price the cart
        update - whether to update (save) the cart after pricing
        contextInfo - the context info
        Returns:
        the priced cart
      • priceCartItems

        public void priceCartItems​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                   @Nullable
                                   PriceCartRequest priceCartRequest,
                                   @Nullable
                                   com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Specified by:
        priceCartItems in interface CartPricingService
      • calculateTotals

        public void calculateTotals​(@NonNull
                                    @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                    @Nullable
                                    com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartPricingService
        Calculate the totals for the cart. This assumes pricing such as item amount, adjustments, and taxes have been determined already.
        Specified by:
        calculateTotals in interface CartPricingService
        Parameters:
        cart - The cart to calculate totals for.
      • applyTaxes

        protected void applyTaxes​(@NonNull
                                  @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                  @Nullable
                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      • determineTaxableAmounts

        protected void determineTaxableAmounts​(@NonNull
                                               @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
        Determines and sets FulfillmentItem.getMerchandiseTaxableAmount() and FulfillmentGroup.getFulfillmentTaxableAmount(). This will by default prorate the CartPricing.getAdjustmentsTotal() across FulfillmentItem.getMerchandiseTotalAmount().

        By default, a tax item is created for each group as a whole when calculating fulfillment tax, therefore no proration is necessary. To also prorate fulfillment-group adjustments across its items, extend this to add that proration.

        Parameters:
        cart - Cart with items to be taxed
      • prorateOrderAdjustments

        protected void prorateOrderAdjustments​(@NonNull
                                               @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                               @NonNull
                                               @NonNull Collection<? extends com.broadleafcommerce.cart.client.domain.FulfillmentItem> fulfillmentItems,
                                               @NonNull
                                               @NonNull javax.money.MonetaryAmount adjustmentsTotal)
        Distributes the order-level adjustments to all of the items for tax purposes.
        Parameters:
        fulfillmentItems - FulfillmentItems onto which to distribute the adjustmentsTotal
        adjustmentsTotal - Total amount of the order-level adjustments to be distributed usually from CartPricing.getAdjustmentsTotal().
      • updateTaxableAmounts

        protected <T extends com.broadleafcommerce.cart.client.domain.CartItem> void updateTaxableAmounts​(@NonNull
                                                                                                          @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                                          @NonNull
                                                                                                          @NonNull Collection<? extends com.broadleafcommerce.cart.client.domain.FulfillmentGroup> fulfillmentGroups,
                                                                                                          @NonNull
                                                                                                          @NonNull Collection<T> cartItems)
        Updates the taxable amount fields on FulfillmentItem. This should be run after prorateOrderAdjustments(com.broadleafcommerce.cart.client.domain.Cart, java.util.Collection<? extends com.broadleafcommerce.cart.client.domain.FulfillmentItem>, javax.money.MonetaryAmount) to ensure discounts are properly accounted for.

        By default, fulfillment taxable amounts are calculated at the fulfillment group level, and not the fulfillment item level. To calculate fulfillment taxes at the item level, extend this to calculate fulfillment taxable amounts for each fulfillment item.

        Parameters:
        fulfillmentGroups - All of the fulfillment groups in a cart to be taxed.
        cartItems - All of the cart items from a cart to check CartItem.isTaxable()
      • calculateItemSubtotal

        protected boolean calculateItemSubtotal​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                                boolean shouldPriceCart,
                                                com.broadleafcommerce.cart.client.domain.CartItem item,
                                                javax.money.CurrencyUnit expectedCurrency)
      • calculateItemSubtotal

        @Deprecated
        protected boolean calculateItemSubtotal​(boolean shouldPriceCart,
                                                com.broadleafcommerce.cart.client.domain.CartItem item,
                                                javax.money.CurrencyUnit expectedCurrency)
        Deprecated.
      • updateCartItemPricing

        protected boolean updateCartItemPricing​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                                Locale locale,
                                                javax.money.CurrencyUnit expectedCurrency,
                                                @Nullable
                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      • updateCartItemPricing

        @Deprecated
        protected boolean updateCartItemPricing​(List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems,
                                                Locale locale,
                                                javax.money.CurrencyUnit expectedCurrency,
                                                @Nullable
                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Deprecated.
      • buildPriceCartRequest

        protected PriceCartRequest buildPriceCartRequest​(com.broadleafcommerce.cart.client.domain.Cart cart)
      • setDefaultsForPriceCartRequest

        protected void setDefaultsForPriceCartRequest​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                                      PriceCartRequest priceCartRequest)
      • getCurrencyFromCart

        protected javax.money.CurrencyUnit getCurrencyFromCart​(com.broadleafcommerce.cart.client.domain.Cart cart)
      • prepareCartForPricing

        protected void prepareCartForPricing​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                             PriceCartRequest priceCartRequest,
                                             @Nullable
                                             com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      • clearCartPrices

        protected void clearCartPrices​(com.broadleafcommerce.cart.client.domain.Cart cart)
      • clearFulfillmentPricing

        protected void clearFulfillmentPricing​(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup)
      • clearItemPricing

        protected void clearItemPricing​(com.broadleafcommerce.cart.client.domain.CartItem ci)
      • getCartProvider

        protected CartProvider getCartProvider()
      • getTaxService

        protected TaxService getTaxService()
      • getObjectMapper

        protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
      • getMessageSource

        protected org.springframework.context.MessageSource getMessageSource()
      • setStaleCartItemsService

        @Autowired
        public void setStaleCartItemsService​(StaleCartItemsService staleCartItemsService)