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 TypeMethodDescriptionvoidaddCartItemQualifiedOfferIdsToIgnoreList(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems) Retrieves the offer ids that the givenCartItemsthat are qualifiers of and add them to the givenCart's offer ignore list.protected voidaddIgnoredOffer(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem giftItem) voidaddIgnoredOffer(com.broadleafcommerce.cart.client.domain.Cart cart, HashSet<String> key, String offerId) Add an ignored offer with the given key.javax.money.MonetaryAmountcalculateFreeGiftItemTotals(com.broadleafcommerce.cart.client.domain.Cart cart) Calculates the total of all the free gift items in the cart.voidcalculateIgnoredOffersAfterRemoval(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsBeingRemoved) protected voidclearIgnoredOffers(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 theFreeGiftItemsapplicable to the givenCart.protected com.broadleafcommerce.order.common.domain.AdjustmentgetGiftAdjustmentFromItem(com.broadleafcommerce.cart.client.domain.CartItem giftItem) getIgnoredOffersMap(com.broadleafcommerce.cart.client.domain.Cart cart) protected <T> TgetInternalAttribute(com.broadleafcommerce.cart.client.domain.CartItem cartItem, String key) protected <T> TgetInternalAttribute(com.broadleafcommerce.cart.client.domain.Cart cart, String key) protected <T> TgetInternalAttribute(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 CartOpsPromotionPropertiesprotected booleanisFreeGift(com.broadleafcommerce.cart.client.domain.CartItem cartItem) Identifies if the givenCartItemis a free gift item.protected booleanisNotOfferDetailForSelf(com.broadleafcommerce.order.common.domain.OfferItemDetail detail, com.broadleafcommerce.cart.client.domain.CartItem giftItem) booleanofferShouldBeIgnored(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.promotion.offer.client.web.context.info.OfferRef offerRef) Determines if the givenOfferRefshould be ignored for the givenCart.protected voidrecalculateIgnoredOffers(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.voidremoveIgnoredOffer(com.broadleafcommerce.cart.client.domain.Cart cart, String key) voidsetPromotionProperties(CartOpsPromotionProperties promotionProperties) voidstoreFreeGiftItems(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem> freeGiftItems) Adds the givenFreeGiftItemstoCart.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 givenFreeGiftItemstoCart.getInternalAttributes()for later processing.- Parameters:
cart- theCartto add theFreeGiftItemsforfreeGiftItems- theFreeGiftItemsto 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 theFreeGiftItemsapplicable to the givenCart.- Parameters:
cart- theCartto retrieve the applicableFreeGiftItemsfrom- Returns:
- the
FreeGiftItemsapplicable 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- theCartto 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 givenOfferRefshould be ignored for the givenCart.- Parameters:
cart- theCartto check againstofferRef- theOfferRefto check against- Returns:
- true if given
OfferRefshould 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 givenCartItemsthat are qualifiers of and add them to the givenCart's offer ignore list.This is typically used when removing automatically added
CartItemsfrom offers, but no longer want to apply those offers again.- Parameters:
cart- theCartto add the offer ids to ignore forcartItems- theCartItemsto 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- theCartto 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 givenCartItemis a free gift item.- Parameters:
cartItem-CartItemto check against- Returns:
- true if the given
CartItemis 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
-