Class CartOfferUtils
java.lang.Object
com.broadleafcommerce.cartoperation.service.util.offer.CartOfferUtils
Utility class to aid in retrieving offer information from
Cart
.- Author:
- Sunny Yu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCartItemQualifiedOfferIdsToIgnoreList
(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems) Retrieves the offer ids that the givenCartItems
that are qualifiers of and add them to the givenCart
's offer ignore list.protected void
addIgnoredOffer
(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem giftItem) void
addIgnoredOffer
(com.broadleafcommerce.cart.client.domain.Cart cart, HashSet<String> key, String offerId) Add an ignored offer with the given key.javax.money.MonetaryAmount
calculateFreeGiftItemTotals
(com.broadleafcommerce.cart.client.domain.Cart cart) Calculates the total of all the free gift items in the cart.void
calculateIgnoredOffersAfterRemoval
(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsBeingRemoved) protected void
clearIgnoredOffers
(com.broadleafcommerce.cart.client.domain.Cart cart) protected List<com.broadleafcommerce.cart.client.domain.CartItem>
findGiftItemsBeingRemoved
(List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsBeingRemoved) findOffersNoLongerIgnored
(Map<String, Set<String>> ignoredOffersMap, Set<String> remainingCartItemIds) Finds offers that are no longer ignored because all qualifying items have been removed.List<com.broadleafcommerce.cart.client.domain.CartItem>
getFreeGiftItems
(com.broadleafcommerce.cart.client.domain.Cart cart) List<com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem>
getFreeGiftItemsFromOffers
(com.broadleafcommerce.cart.client.domain.Cart cart) Retrieves theFreeGiftItems
applicable to the givenCart
.protected com.broadleafcommerce.order.common.domain.Adjustment
getGiftAdjustmentFromItem
(com.broadleafcommerce.cart.client.domain.CartItem giftItem) getIgnoredOffersMap
(com.broadleafcommerce.cart.client.domain.Cart cart) protected <T> T
getInternalAttribute
(com.broadleafcommerce.cart.client.domain.CartItem cartItem, String key) protected <T> T
getInternalAttribute
(com.broadleafcommerce.cart.client.domain.Cart cart, String key) protected <T> T
getInternalAttribute
(com.broadleafcommerce.cart.client.domain.Cart cart, String key, T defaultValue) getOfferIdsToIgnore
(com.broadleafcommerce.cart.client.domain.Cart cart) Retrieves the offer ids to ignore and not apply to the givenCart
.protected CartOpsPromotionProperties
protected boolean
isFreeGift
(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Identifies if the givenCartItem
is a free gift item.protected boolean
isNotOfferDetailForSelf
(com.broadleafcommerce.order.common.domain.OfferItemDetail detail, com.broadleafcommerce.cart.client.domain.CartItem giftItem) boolean
offerShouldBeIgnored
(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.promotion.offer.client.web.context.info.OfferRef offerRef) Determines if the givenOfferRef
should be ignored for the givenCart
.protected void
recalculateIgnoredOffers
(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> removedItems) Checks remaining cart items to see if qualifying cart items for ignored offers are still in the cart.void
removeIgnoredOffer
(com.broadleafcommerce.cart.client.domain.Cart cart, String key) void
setPromotionProperties
(CartOpsPromotionProperties promotionProperties) void
storeFreeGiftItems
(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem> freeGiftItems) Adds the givenFreeGiftItems
toCart.getInternalAttributes()
for later processing.
-
Constructor Details
-
CartOfferUtils
-
-
Method Details
-
storeFreeGiftItems
public void storeFreeGiftItems(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem> freeGiftItems) Adds the givenFreeGiftItems
toCart.getInternalAttributes()
for later processing.- Parameters:
cart
- theCart
to add theFreeGiftItems
forfreeGiftItems
- theFreeGiftItems
to add toCart.getInternalAttributes()
- See Also:
-
getFreeGiftItemsFromOffers
public List<com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem> getFreeGiftItemsFromOffers(com.broadleafcommerce.cart.client.domain.Cart cart) Retrieves theFreeGiftItems
applicable to the givenCart
.- Parameters:
cart
- theCart
to retrieve the applicableFreeGiftItems
from- Returns:
- the
FreeGiftItems
applicable to the givenCart
- See Also:
-
getFreeGiftItems
public List<com.broadleafcommerce.cart.client.domain.CartItem> getFreeGiftItems(com.broadleafcommerce.cart.client.domain.Cart cart) -
getOfferIdsToIgnore
Retrieves the offer ids to ignore and not apply to the givenCart
.- Parameters:
cart
- theCart
to retrieve the ignored offer ids from- Returns:
- the offer ids to ignore and not apply to the given
Cart
-
offerShouldBeIgnored
public boolean offerShouldBeIgnored(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.promotion.offer.client.web.context.info.OfferRef offerRef) Determines if the givenOfferRef
should be ignored for the givenCart
.- Parameters:
cart
- theCart
to check againstofferRef
- theOfferRef
to check against- Returns:
- true if given
OfferRef
should be ignored, otherwise false
-
addCartItemQualifiedOfferIdsToIgnoreList
public void addCartItemQualifiedOfferIdsToIgnoreList(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems) Retrieves the offer ids that the givenCartItems
that are qualifiers of and add them to the givenCart
's offer ignore list.This is typically used when removing automatically added
CartItems
from offers, but no longer want to apply those offers again.- Parameters:
cart
- theCart
to add the offer ids to ignore forcartItems
- theCartItems
to retrieve their qualified offer ids for
-
calculateIgnoredOffersAfterRemoval
public void calculateIgnoredOffersAfterRemoval(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsBeingRemoved) -
recalculateIgnoredOffers
protected void recalculateIgnoredOffers(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> removedItems) Checks remaining cart items to see if qualifying cart items for ignored offers are still in the cart. If they are not, then the offer is no longer ignored.- Parameters:
cart
- the cart to check for remaining qualifying items
-
findOffersNoLongerIgnored
protected List<String> findOffersNoLongerIgnored(Map<String, Set<String>> ignoredOffersMap, Set<String> remainingCartItemIds) Finds offers that are no longer ignored because all qualifying items have been removed.- Parameters:
ignoredOffersMap
- the map of ignored offersremainingCartItemIds
- the set of remaining cart item ids- Returns:
- the keys of the ignored offers that are no longer ignored
-
calculateFreeGiftItemTotals
public javax.money.MonetaryAmount calculateFreeGiftItemTotals(com.broadleafcommerce.cart.client.domain.Cart cart) Calculates the total of all the free gift items in the cart.- Parameters:
cart
- theCart
to get the free gift items from- Returns:
- the total of all the free gift items in the cart
-
getIgnoredOffersMap
-
addIgnoredOffer
protected void addIgnoredOffer(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem giftItem) -
findGiftItemsBeingRemoved
-
isFreeGift
protected boolean isFreeGift(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
-
isNotOfferDetailForSelf
protected boolean isNotOfferDetailForSelf(com.broadleafcommerce.order.common.domain.OfferItemDetail detail, com.broadleafcommerce.cart.client.domain.CartItem giftItem) -
getGiftAdjustmentFromItem
protected com.broadleafcommerce.order.common.domain.Adjustment getGiftAdjustmentFromItem(com.broadleafcommerce.cart.client.domain.CartItem giftItem) -
addIgnoredOffer
public void addIgnoredOffer(com.broadleafcommerce.cart.client.domain.Cart cart, HashSet<String> key, String offerId) Add an ignored offer with the given key. The key must be a HashSet so that the hash code is consistent. The key should be the cart item IDs of the offer qualifiers.- Parameters:
key
- the key. Usually this should be the cart item IDs of the offer qualifiers.offerId
- the ID of the offer to ignore
-
removeIgnoredOffer
-
clearIgnoredOffers
protected void clearIgnoredOffers(com.broadleafcommerce.cart.client.domain.Cart cart) -
getInternalAttribute
protected <T> T getInternalAttribute(com.broadleafcommerce.cart.client.domain.Cart cart, String key) -
getInternalAttribute
protected <T> T getInternalAttribute(com.broadleafcommerce.cart.client.domain.Cart cart, String key, T defaultValue) -
getInternalAttribute
protected <T> T getInternalAttribute(com.broadleafcommerce.cart.client.domain.CartItem cartItem, String key) -
getPromotionProperties
-
setPromotionProperties
-