java.lang.Object
com.broadleafcommerce.cartoperation.service.util.offer.CartOfferUtils

public class CartOfferUtils extends Object
Utility class to aid in retrieving offer information from Cart.
Author:
Sunny Yu
  • Constructor Summary

    Constructors
    Constructor
    Description
    CartOfferUtils(CartItemOfferUtils cartItemOfferUtils)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addCartItemQualifiedOfferIdsToIgnoreList(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems)
    Retrieves the offer ids that the given CartItems that are qualifiers of and add them to the given Cart'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)
     
    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.
    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 the FreeGiftItems applicable to the given Cart.
    protected com.broadleafcommerce.order.common.domain.Adjustment
    getGiftAdjustmentFromItem(com.broadleafcommerce.cart.client.domain.CartItem giftItem)
     
    protected Map<String,Set<String>>
    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 given Cart.
     
    protected boolean
    isFreeGift(com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    Identifies if the given CartItem 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 given OfferRef should be ignored for the given Cart.
    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
     
    void
    storeFreeGiftItems(com.broadleafcommerce.cart.client.domain.Cart cart, List<com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem> freeGiftItems)
    Adds the given FreeGiftItems to Cart.getInternalAttributes() for later processing.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • 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 given FreeGiftItems to Cart.getInternalAttributes() for later processing.
      Parameters:
      cart - the Cart to add the FreeGiftItems for
      freeGiftItems - the FreeGiftItems to add to Cart.getInternalAttributes()
      See Also:
    • getFreeGiftItemsFromOffers

      public List<com.broadleafcommerce.promotion.offer.client.web.context.info.FreeGiftItem> getFreeGiftItemsFromOffers(com.broadleafcommerce.cart.client.domain.Cart cart)
      Retrieves the FreeGiftItems applicable to the given Cart.
      Parameters:
      cart - the Cart to retrieve the applicable FreeGiftItems from
      Returns:
      the FreeGiftItems applicable to the given Cart
      See Also:
    • getFreeGiftItems

      public List<com.broadleafcommerce.cart.client.domain.CartItem> getFreeGiftItems(com.broadleafcommerce.cart.client.domain.Cart cart)
    • getOfferIdsToIgnore

      public List<String> getOfferIdsToIgnore(com.broadleafcommerce.cart.client.domain.Cart cart)
      Retrieves the offer ids to ignore and not apply to the given Cart.
      Parameters:
      cart - the Cart 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 given OfferRef should be ignored for the given Cart.
      Parameters:
      cart - the Cart to check against
      offerRef - the OfferRef 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 given CartItems that are qualifiers of and add them to the given Cart'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 - the Cart to add the offer ids to ignore for
      cartItems - the CartItems 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 offers
      remainingCartItemIds - 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 - the Cart to get the free gift items from
      Returns:
      the total of all the free gift items in the cart
    • getIgnoredOffersMap

      protected Map<String,Set<String>> getIgnoredOffersMap(com.broadleafcommerce.cart.client.domain.Cart cart)
    • addIgnoredOffer

      protected void addIgnoredOffer(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem giftItem)
    • findGiftItemsBeingRemoved

      protected List<com.broadleafcommerce.cart.client.domain.CartItem> findGiftItemsBeingRemoved(List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsBeingRemoved)
    • isFreeGift

      protected boolean isFreeGift(com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Identifies if the given CartItem 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

      public void removeIgnoredOffer(com.broadleafcommerce.cart.client.domain.Cart cart, String key)
    • 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

      protected CartOpsPromotionProperties getPromotionProperties()
    • setPromotionProperties

      @Autowired public void setPromotionProperties(CartOpsPromotionProperties promotionProperties)