Class DefaultCartPricingService
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.pricing.DefaultCartPricingService
-
- All Implemented Interfaces:
CartPricingService
public class DefaultCartPricingService extends Object implements CartPricingService
- Author:
- Chad Harchar (charchar)
-
-
Constructor Summary
Constructors Constructor Description DefaultCartPricingService(CartItemPricingUtils cartItemPricingUtils, CartProvider cartProvider, PricingProvider pricingProvider, OfferProvider offerProvider, CatalogProvider catalogProvider, CartItemConfigurationService cartItemConfigurationService, TaxService taxService, FulfillmentPricingService fulfillmentPricingService, com.fasterxml.jackson.databind.ObjectMapper objectMapper, CartTotalsCalculator cartTotalsCalculator, CartPricingRoundingHelper roundingHelper, CartOperationServiceProperties cartOperationServiceProperties, com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.springframework.context.MessageSource messageSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected com.broadleafcommerce.cart.client.domain.Cart
applyPricesToCart(com.broadleafcommerce.cart.client.domain.Cart cart, ProductList productList)
protected void
applyTaxes(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected PriceCartRequest
buildPriceCartRequest(com.broadleafcommerce.cart.client.domain.Cart cart)
protected Set<String>
buildProductIdList(List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems)
protected boolean
calculateItemSubtotal(boolean shouldPriceCart, com.broadleafcommerce.cart.client.domain.CartItem item, javax.money.CurrencyUnit expectedCurrency)
Deprecated.protected boolean
calculateItemSubtotal(com.broadleafcommerce.cart.client.domain.Cart cart, boolean shouldPriceCart, com.broadleafcommerce.cart.client.domain.CartItem item, javax.money.CurrencyUnit expectedCurrency)
void
calculateTotals(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Calculate the totals for the cart.protected com.broadleafcommerce.pricing.client.domain.PriceInfo
cleanPriceInfo(@NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
protected void
clearCartPrices(com.broadleafcommerce.cart.client.domain.Cart cart)
protected void
clearFulfillmentPricing(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup)
protected void
clearItemPricing(com.broadleafcommerce.cart.client.domain.CartItem ci)
protected void
determineTaxableAmounts(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
Determines and setsFulfillmentItem.getMerchandiseTaxableAmount()
andFulfillmentGroup.getFulfillmentTaxableAmount()
.protected CartItemConfigurationService
getCartItemConfigurationService()
protected CartItemPricingUtils
getCartItemPricingUtils()
protected CartOperationServiceProperties
getCartOperationServiceProperties()
protected CartOperationServiceOfferUtils
getCartOpsServiceOfferUtils()
protected CartProvider
getCartProvider()
protected CartTotalsCalculator
getCartTotalsCalculator()
protected CatalogProvider
getCatalogProvider()
protected javax.money.CurrencyUnit
getCurrencyFromCart(com.broadleafcommerce.cart.client.domain.Cart cart)
protected FulfillmentPricingService
getFulfillmentPricingService()
protected org.springframework.context.MessageSource
getMessageSource()
protected com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
protected OfferProvider
getOfferProvider()
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.protected PricingProvider
getPricingProvider()
protected CartPricingRoundingHelper
getRoundingHelper()
protected StaleCartItemsService
getStaleCartItemsService()
protected TaxService
getTaxService()
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected void
prepareCartForPricing(com.broadleafcommerce.cart.client.domain.Cart cart, PriceCartRequest priceCartRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
com.broadleafcommerce.cart.client.domain.Cart
priceCart(com.broadleafcommerce.cart.client.domain.Cart cart, PriceCartRequest priceCartRequest, boolean update, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Price the cart with the provided locale and currency.com.broadleafcommerce.cart.client.domain.Cart
priceCart(com.broadleafcommerce.cart.client.domain.Cart cart, PriceCartRequest priceCartRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Price the cart with the provided locale and currency.void
priceCartItems(com.broadleafcommerce.cart.client.domain.Cart cart, PriceCartRequest priceCartRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
com.broadleafcommerce.cart.client.domain.Cart
priceCartWithCatalogPriceUpdates(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Reprice the cart, including applying the latest catalog-based prices for each of its itemsprotected void
prorateOrderAdjustments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull Collection<? extends com.broadleafcommerce.cart.client.domain.FulfillmentItem> fulfillmentItems, @NonNull javax.money.MonetaryAmount adjustmentsTotal)
Distributes the order-level adjustments to all of the items for tax purposes.void
setCartOpsServiceOfferUtils(CartOperationServiceOfferUtils cartOpsServiceOfferUtils)
protected void
setDefaultsForPriceCartRequest(com.broadleafcommerce.cart.client.domain.Cart cart, PriceCartRequest priceCartRequest)
void
setStaleCartItemsService(StaleCartItemsService staleCartItemsService)
protected boolean
updateCartItemPricing(com.broadleafcommerce.cart.client.domain.Cart cart, Locale locale, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected boolean
updateCartItemPricing(List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, Locale locale, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Deprecated.protected com.broadleafcommerce.cart.client.domain.Cart
updateCatalogPricesForCartItems(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected <T extends com.broadleafcommerce.cart.client.domain.CartItem>
voidupdateTaxableAmounts(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull Collection<? extends com.broadleafcommerce.cart.client.domain.FulfillmentGroup> fulfillmentGroups, @NonNull Collection<T> cartItems)
Updates the taxable amount fields onFulfillmentItem
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.cartoperation.service.pricing.CartPricingService
priceCart, priceCartItems
-
-
-
-
Constructor Detail
-
DefaultCartPricingService
public DefaultCartPricingService(CartItemPricingUtils cartItemPricingUtils, CartProvider cartProvider, PricingProvider pricingProvider, OfferProvider offerProvider, CatalogProvider catalogProvider, CartItemConfigurationService cartItemConfigurationService, TaxService taxService, FulfillmentPricingService fulfillmentPricingService, com.fasterxml.jackson.databind.ObjectMapper objectMapper, CartTotalsCalculator cartTotalsCalculator, CartPricingRoundingHelper roundingHelper, CartOperationServiceProperties cartOperationServiceProperties, com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.springframework.context.MessageSource messageSource)
-
-
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 interfaceCartPricingService
- Parameters:
cart
- The cart on which to perform the operation.priceCartRequest
- optional info to be used when deciding how to price the cartcontextInfo
- 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 interfaceCartPricingService
- 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 theDefaultProductType.MERCHANDISING_PRODUCT
as it doesn't have the SKU and pricing key.- Parameters:
product
- the product to get the pricing key fromcartItem
- 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.- Initialize pricing request
- Clear current pricing information from cart
- Update cart item pricing
- Retrieve prices from the pricing provider
- Calculate each item's subtotal
- Record whether each item was priced
- If the items were all priced, continue, otherwise mark the cart as un-priced, update, and return
- Calculate fulfillment pricing by calling the fulfillment pricing provider
- Apply adjustments by calling the offer provider
- Calculate the cart totals
- Record the cart as priced, update (if specified), and return
- Specified by:
priceCart
in interfaceCartPricingService
- Parameters:
cart
- The cart on which to perform the operation.priceCartRequest
- optional info to be used when deciding how to price the cartupdate
- whether to update (save) the cart after pricingcontextInfo
- 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 interfaceCartPricingService
-
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 interfaceCartPricingService
- 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 setsFulfillmentItem.getMerchandiseTaxableAmount()
andFulfillmentGroup.getFulfillmentTaxableAmount()
. This will by default prorate theCartPricing.getAdjustmentsTotal()
acrossFulfillmentItem.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 theadjustmentsTotal
adjustmentsTotal
- Total amount of the order-level adjustments to be distributed usually fromCartPricing.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 onFulfillmentItem
. This should be run afterprorateOrderAdjustments(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 checkCartItem.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)
-
getCartItemPricingUtils
protected CartItemPricingUtils getCartItemPricingUtils()
-
getCartProvider
protected CartProvider getCartProvider()
-
getPricingProvider
protected PricingProvider getPricingProvider()
-
getOfferProvider
protected OfferProvider getOfferProvider()
-
getCatalogProvider
protected CatalogProvider getCatalogProvider()
-
getCartItemConfigurationService
protected CartItemConfigurationService getCartItemConfigurationService()
-
getTaxService
protected TaxService getTaxService()
-
getFulfillmentPricingService
protected FulfillmentPricingService getFulfillmentPricingService()
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-
getCartTotalsCalculator
protected CartTotalsCalculator getCartTotalsCalculator()
-
getRoundingHelper
protected CartPricingRoundingHelper getRoundingHelper()
-
getCartOperationServiceProperties
protected CartOperationServiceProperties getCartOperationServiceProperties()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource()
-
getCartOpsServiceOfferUtils
protected CartOperationServiceOfferUtils getCartOpsServiceOfferUtils()
-
setCartOpsServiceOfferUtils
@Autowired public void setCartOpsServiceOfferUtils(CartOperationServiceOfferUtils cartOpsServiceOfferUtils)
-
setStaleCartItemsService
@Autowired public void setStaleCartItemsService(StaleCartItemsService staleCartItemsService)
-
getStaleCartItemsService
protected StaleCartItemsService getStaleCartItemsService()
-
-