Class CartItemOfferUtils
java.lang.Object
com.broadleafcommerce.cartoperation.service.util.offer.CartItemOfferUtils
Utility class to aid in processing
CartItems
regarding offers.- Author:
- Sunny Yu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.broadleafcommerce.order.common.domain.Adjustment
buildFreeGiftAdjustment
(com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem freeGiftItem) Builds anAdjustment
based on the supplied free gift and cart item.com.broadleafcommerce.order.common.domain.Adjustment
buildFreeGiftAdjustment
(com.broadleafcommerce.promotion.offer.client.web.context.info.Adjustment offerAdjustment) Builds anAdjustment
based on the givenAdjustment
.com.broadleafcommerce.order.common.domain.OfferItemDetail
buildOfferItemDetails
(com.broadleafcommerce.promotion.offer.client.web.context.info.OfferItemDetail offerItemDetail) Builds anOfferItemDetail
from the givenOfferItemDetail
.protected com.broadleafcommerce.order.common.domain.Adjustment
convertAdjustment
(Object adjustment) Converts the givenObject
to anAdjustment
.com.broadleafcommerce.order.common.domain.Adjustment
getFreeGiftAdjustment
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gets the temporarily storedAdjustment
for the free gift item.javax.money.MonetaryAmount
getGiftAdjustmentAmount
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Return the adjustment amount of a gift item.javax.money.MonetaryAmount
getGiftFee
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) protected <T> T
getInternalAttribute
(com.broadleafcommerce.cart.client.domain.CartItem cartItem, String key) protected <T> T
getInternalAttribute
(com.broadleafcommerce.cart.client.domain.CartItem cartItem, String key, Class<T> type) protected com.fasterxml.jackson.databind.ObjectMapper
getOriginOfferId
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gets the id of the offer that thisCartItem
was a target of.protected CartOpsPromotionProperties
List<com.broadleafcommerce.order.common.domain.OfferItemDetail>
getQualifierCartItemDetails
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gets the offer qualifierOfferItemDetails
that the givenCartItem
was a target of.getQualifierCartItemIds
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Theids
of the offer qualifierCartItems
that the givenCartItem
was added from.protected com.broadleafcommerce.common.extension.TypeFactory
boolean
isFreeGiftItem
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Identifies if the givenCartItem
is a free gift item.void
removeIsFreeGiftItemFlag
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Removes theCartItemAttributeConstants.Internal.IS_FREE_GIFT_ITEM
attribute from the givenCartItem
.void
setPromotionProperties
(CartOpsPromotionProperties promotionProperties) void
setTypeFactory
(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
Constructor Details
-
CartItemOfferUtils
public CartItemOfferUtils(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Details
-
isFreeGiftItem
public boolean isFreeGiftItem(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Identifies if the givenCartItem
is a free gift item.- Parameters:
cartItem
-CartItem
to check against- Returns:
- true if the given
CartItem
is a free gift item, otherwise false
-
removeIsFreeGiftItemFlag
public void removeIsFreeGiftItemFlag(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Removes theCartItemAttributeConstants.Internal.IS_FREE_GIFT_ITEM
attribute from the givenCartItem
.- Parameters:
cartItem
-CartItem
to remove theCartItemAttributeConstants.Internal.IS_FREE_GIFT_ITEM
from
-
getFreeGiftAdjustment
public com.broadleafcommerce.order.common.domain.Adjustment getFreeGiftAdjustment(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gets the temporarily storedAdjustment
for the free gift item. -
getGiftAdjustmentAmount
@Nullable public javax.money.MonetaryAmount getGiftAdjustmentAmount(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Return the adjustment amount of a gift item. This is the unit price of the item minus the gift fee. Quantity is not considered in this calculation. If no gift fee is present, this method will return null.- Returns:
- the gift adjustment amount.
- See Also:
-
getGiftFee
@Nullable public javax.money.MonetaryAmount getGiftFee(com.broadleafcommerce.cart.client.domain.CartItem cartItem) -
getQualifierCartItemIds
public List<String> getQualifierCartItemIds(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Theids
of the offer qualifierCartItems
that the givenCartItem
was added from.- Parameters:
cartItem
-CartItem
to get the offer qualifiercart item ids
from- Returns:
- The
ids
of the offer qualifierCartItems
that the givenCartItem
was added from
-
getQualifierCartItemDetails
public List<com.broadleafcommerce.order.common.domain.OfferItemDetail> getQualifierCartItemDetails(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gets the offer qualifierOfferItemDetails
that the givenCartItem
was a target of.- Parameters:
cartItem
- theCartItem
to get the offer qualifierOfferItemDetails
from- Returns:
- the offer qualifier
OfferItemDetails
that the givenCartItem
was a target of
-
convertAdjustment
Converts the givenObject
to anAdjustment
. -
getOriginOfferId
Gets the id of the offer that thisCartItem
was a target of. In other words, this id identifies which offer thisCartItem
was added from.- Parameters:
cartItem
-CartItem
to get the target offer id from- Returns:
- the id of the offer that this
CartItem
was a target of - See Also:
-
buildFreeGiftAdjustment
public com.broadleafcommerce.order.common.domain.Adjustment buildFreeGiftAdjustment(com.broadleafcommerce.promotion.offer.client.web.context.info.Adjustment offerAdjustment) Builds anAdjustment
based on the givenAdjustment
.- Parameters:
offerAdjustment
- theAdjustment
to build it from- Returns:
- an
Adjustment
based on the givenAdjustment
-
buildFreeGiftAdjustment
public com.broadleafcommerce.order.common.domain.Adjustment buildFreeGiftAdjustment(com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem freeGiftItem) Builds anAdjustment
based on the supplied free gift and cart item.- Parameters:
cartItem
- The cart item representing the gift.freeGiftItem
- The free gift item.- Returns:
- an
Adjustment
for the given free gift item
-
buildOfferItemDetails
public com.broadleafcommerce.order.common.domain.OfferItemDetail buildOfferItemDetails(com.broadleafcommerce.promotion.offer.client.web.context.info.OfferItemDetail offerItemDetail) Builds anOfferItemDetail
from the givenOfferItemDetail
.- Parameters:
offerItemDetail
- theOfferItemDetail
to build theOfferItemDetail
from- Returns:
- an
OfferItemDetail
from the givenOfferItemDetail
-
getInternalAttribute
protected <T> T getInternalAttribute(com.broadleafcommerce.cart.client.domain.CartItem cartItem, String key) -
getInternalAttribute
-
getMapper
protected com.fasterxml.jackson.databind.ObjectMapper getMapper() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
setTypeFactory
@Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
getPromotionProperties
-
setPromotionProperties
-