Class OfferServiceImpl

java.lang.Object
org.broadleafcommerce.core.offer.service.OfferServiceImpl
All Implemented Interfaces:
OfferService

@Service("blOfferService") public class OfferServiceImpl extends Object implements OfferService
The Class OfferServiceImpl.
  • Field Details

    • customerOfferDao

      protected CustomerOfferDao customerOfferDao
    • offerCodeDao

      protected OfferCodeDao offerCodeDao
    • offerAuditService

      protected OfferAuditService offerAuditService
    • offerDao

      protected OfferDao offerDao
    • orderOfferProcessor

      protected OrderOfferProcessor orderOfferProcessor
    • itemOfferProcessor

      protected ItemOfferProcessor itemOfferProcessor
    • fulfillmentGroupOfferProcessor

      protected FulfillmentGroupOfferProcessor fulfillmentGroupOfferProcessor
    • promotableItemFactory

      protected PromotableItemFactory promotableItemFactory
    • extensionManager

      protected OfferServiceExtensionManager extensionManager
    • orderService

      protected OrderService orderService
    • sandBoxHelper

      protected org.broadleafcommerce.common.sandbox.SandBoxHelper sandBoxHelper
    • em

      protected jakarta.persistence.EntityManager em
    • transUtil

      protected org.broadleafcommerce.common.util.StreamingTransactionCapableUtil transUtil
    • duplicator

      protected org.broadleafcommerce.common.persistence.EntityDuplicator duplicator
    • offerDuplicateModifier

      @Deprecated protected org.broadleafcommerce.common.persistence.EntityDuplicateModifier<Offer> offerDuplicateModifier
      Deprecated.
      Add EntityDuplicateModifiers to blEntityDuplicationHelpers
  • Constructor Details

    • OfferServiceImpl

      public OfferServiceImpl()
  • Method Details

    • findAllOffers

      public List<Offer> findAllOffers()
      Description copied from interface: OfferService
      Returns all offers
      Specified by:
      findAllOffers in interface OfferService
      Returns:
      all offers
    • save

      @Transactional("blTransactionManager") public Offer save(Offer offer)
      Description copied from interface: OfferService
      Save a new offer or updates an existing offer
      Specified by:
      save in interface OfferService
      Returns:
      the offer
    • saveOfferCode

      @Transactional("blTransactionManager") public OfferCode saveOfferCode(OfferCode offerCode)
      Description copied from interface: OfferService
      Saves a new Offer or updates an existing Offer that belongs to an OfferCode, then saves or updates the OfferCode
      Specified by:
      saveOfferCode in interface OfferService
      Returns:
      the offerCode
    • lookupOfferByCode

      public Offer lookupOfferByCode(String code)
      Creates a list of offers that applies to this order. All offers that are assigned to the customer, entered during checkout, or has a delivery type of automatic are added to the list. The same offer cannot appear more than once in the list.
      Specified by:
      lookupOfferByCode in interface OfferService
      Parameters:
      code -
      Returns:
      a List of offers that may apply to this order
    • lookupOfferCodeByCode

      public OfferCode lookupOfferCodeByCode(String code)
      Description copied from interface: OfferService
      Lookup OfferCode by code.
      Specified by:
      lookupOfferCodeByCode in interface OfferService
      Parameters:
      code - the code
      Returns:
      the offer
    • lookupAllOffersByCode

      public List<Offer> lookupAllOffersByCode(String code)
      Description copied from interface: OfferService
      Lookup all offers by code.
      Specified by:
      lookupAllOffersByCode in interface OfferService
      Parameters:
      code - the code
      Returns:
      the list of offers
    • lookupAllOfferCodesByCode

      public List<OfferCode> lookupAllOfferCodesByCode(String code)
      Description copied from interface: OfferService
      Lookup all OfferCodes by code.
      Specified by:
      lookupAllOfferCodesByCode in interface OfferService
      Parameters:
      code - the code
      Returns:
      the list of offer codes
    • buildOfferListForOrder

      public List<Offer> buildOfferListForOrder(Order order)
      Creates a list of offers that applies to this order. All offers that are assigned to the customer, entered during checkout, or has a delivery type of automatic are added to the list. The same offer cannot appear more than once in the list.
      Specified by:
      buildOfferListForOrder in interface OfferService
      Parameters:
      order -
      Returns:
      a List of offers that may apply to this order
    • buildOfferCodeListForCustomer

      public List<OfferCode> buildOfferCodeListForCustomer(Order order)
      Description copied from interface: OfferService
      Attempts to resolve a list of offer codes associated explicitly with the customer. For example, an implementation may choose to associate a specific offer code with a customer in a custom table or in customer attributes. This allows you to associate one or more offer codes with a customer without necessarily having them type it in (e.g. on a URL), or by allowing them to type it in, but before it has been actually applied to an order.
      Specified by:
      buildOfferCodeListForCustomer in interface OfferService
      Returns:
      a list of offer codes associated explicitly with the customer
    • buildOfferCodeListForCustomer

      @Deprecated public List<OfferCode> buildOfferCodeListForCustomer(org.broadleafcommerce.profile.core.domain.Customer customer)
      Deprecated.
      Description copied from interface: OfferService
      Attempts to resolve a list of offer codes associated explicitly with the customer. For example, an implementation may choose to associate a specific offer code with a customer in a custom table or in customer attributes. This allows you to associate one or more offer codes with a customer without necessarily having them type it in (e.g. on a URL), or by allowing them to type it in, but before it has been actually applied to an order.
      Specified by:
      buildOfferCodeListForCustomer in interface OfferService
      Returns:
      a list of offer codes associated explicitly with the customer
    • lookupOfferCustomerByCustomer

      protected List<CustomerOffer> lookupOfferCustomerByCustomer(org.broadleafcommerce.profile.core.domain.Customer customer)
      Private method used to retrieve all offers assigned to this customer. These offers are programmatically assigned to the customer.
      Parameters:
      customer -
      Returns:
      a List of offers assigned to the customer
    • lookupAutomaticDeliveryOffers

      protected List<Offer> lookupAutomaticDeliveryOffers()
      Private method used to retrieve all offers with automaticallyAdded set to true
      Returns:
      a List of automatic delivery offers
    • removeOutOfDateOfferCodes

      protected List<OfferCode> removeOutOfDateOfferCodes(List<OfferCode> offerCodes)
      Removes all out of date offerCodes based on the offerCode and its offer's start and end date. If an offerCode has a later start date, that offerCode will be removed. OfferCodes without a start date will still be processed. If the offerCode has a end date that has already passed, that offerCode will be removed. OfferCodes without a end date will be processed. The start and end dates on the offer will still need to be evaluated.
      Parameters:
      offerCodes -
      Returns:
      a List of non-expired offers
    • refreshOfferCodesIfApplicable

      protected List<OfferCode> refreshOfferCodesIfApplicable(Order order)
      For enterprise installations, this will refresh any OfferCodes found to be out-of-date with current sandbox status.
      Parameters:
      order - the order to check
      Returns:
      the refreshed list of OfferCodes
    • applyAndSaveOffersToOrder

      @Transactional("blTransactionManager") public Order applyAndSaveOffersToOrder(List<Offer> offers, Order order) throws PricingException
      Description copied from interface: OfferService
      Apply offers to order. By default this does not re-price the order.
      Specified by:
      applyAndSaveOffersToOrder in interface OfferService
      Parameters:
      offers - the offers
      order - the order
      Returns:
      Throws:
      PricingException
    • verifyAdjustments

      protected boolean verifyAdjustments(Order order, boolean beforeSave)
    • applyOffersToOrder

      @Transactional("blTransactionManager") @Deprecated public void applyOffersToOrder(List<Offer> offers, Order order) throws PricingException
      Deprecated.
      Description copied from interface: OfferService
      Apply offers to order. By default this does not re-price the order. This method is deprecated and should not be used. The saved order should be returned from this method, which is the case in applyAndSaveOffersToOrder.
      Specified by:
      applyOffersToOrder in interface OfferService
      Throws:
      PricingException
    • applyFulfillmentGroupOffersToOrder

      @Transactional("blTransactionManager") @Deprecated public void applyFulfillmentGroupOffersToOrder(List<Offer> offers, Order order) throws PricingException
      Deprecated.
      Specified by:
      applyFulfillmentGroupOffersToOrder in interface OfferService
      Throws:
      PricingException
    • applyAndSaveFulfillmentGroupOffersToOrder

      @Transactional("blTransactionManager") public Order applyAndSaveFulfillmentGroupOffersToOrder(List<Offer> offers, Order order) throws PricingException
      Specified by:
      applyAndSaveFulfillmentGroupOffersToOrder in interface OfferService
      Throws:
      PricingException
    • verifyMaxCustomerUsageThreshold

      public boolean verifyMaxCustomerUsageThreshold(Order order, Offer offer)
      Description copied from interface: OfferService

      Validates that the Customer to whom an Order belongs has not exceeded the max uses for the passed in offer. This method will take into account if the Offer has already been applied to the Order so as not to prevent the Offer from applying to new items added to the Order by a CRS.

      This condition could pass if the system allows two concurrent carts for the same customer. The condition will fail at order submission time when the VerifyCustomerMaxOfferUsesActivity runs (if that activity is configured as part of the checkout workflow.)

      This method only checks offers who have a max_customer_uses value that is greater than zero. By default offers can be used as many times as the customer's order qualifies.

      This method offers no protection against systems that allow customers to create multiple ids in the system.

      Specified by:
      verifyMaxCustomerUsageThreshold in interface OfferService
      Parameters:
      order - the order the offer is to be applied to
      offer - the offer to check
      Returns:
      true if it is ok for the customer to use this offer with their current order, false if not.
    • verifyMaxCustomerUsageThreshold

      @Deprecated public boolean verifyMaxCustomerUsageThreshold(org.broadleafcommerce.profile.core.domain.Customer customer, Offer offer)
      Deprecated.
      Description copied from interface: OfferService

      Validates that the passed in customer has not exceeded the max uses for the passed in offer.

      This condition could pass if the system allows two concurrent carts for the same customer. The condition will fail at order submission time when the VerifyCustomerMaxOfferUsesActivity runs (if that activity is configured as part of the checkout workflow.)

      This method only checks offers who have a max_customer_uses value that is greater than zero. By default offers can be used as many times as the customer's order qualifies.

      This method offers no protection against systems that allow customers to create multiple ids in the system.

      Specified by:
      verifyMaxCustomerUsageThreshold in interface OfferService
      Parameters:
      customer - the customer attempting to use the offer
      offer - the offer to check
      Returns:
      true if it is ok for the customer to use this offer with their current order, false if not.
    • verifyMaxCustomerUsageThreshold

      public boolean verifyMaxCustomerUsageThreshold(Order order, OfferCode code)
      Description copied from interface: OfferService

      Validates that the given OfferCode has not reached its maximum number of usages. This method will also delegate to OfferService.verifyMaxCustomerUsageThreshold(Order, Offer) for the code's Offer and the passed in Order's Customer.

      Specified by:
      verifyMaxCustomerUsageThreshold in interface OfferService
      Parameters:
      order - the order the offer is to be applied to
      code - the code to check
      Returns:
      true if it is ok for the customer to use this offer with their current order, false if not.
    • verifyMaxCustomerUsageThreshold

      @Deprecated public boolean verifyMaxCustomerUsageThreshold(org.broadleafcommerce.profile.core.domain.Customer customer, OfferCode code)
      Deprecated.
      Description copied from interface: OfferService

      Validates that the given OfferCode has not reached its maximum number of usages. This method will also delegate to OfferService.verifyMaxCustomerUsageThreshold(Order, Offer) for the code's Offer and the passed in Customer.

      Specified by:
      verifyMaxCustomerUsageThreshold in interface OfferService
      Parameters:
      customer - the customer attempting to use the code
      code - the code to check
      Returns:
      true if it is ok for the customer to use this offer with their current order, false if not.
    • getUniqueOffersFromOrder

      public Set<Offer> getUniqueOffersFromOrder(Order order)
      Description copied from interface: OfferService
      Returns a set of offers that have been used for this order by checking adjustments on the different levels like FulfillmentGroups and OrderItems. This will return all of the unique offers used for instances where an offer can apply to multiple OrderItems or multiple FulfillmentGroups (and show up as different adjustments on each)
      Specified by:
      getUniqueOffersFromOrder in interface OfferService
      Returns:
    • getOffersRetrievedFromCodes

      public Map<Offer,OfferCode> getOffersRetrievedFromCodes(Order order)
      Description copied from interface: OfferService
      For a given order, give back a map of all Offers that were retrieved from OfferCodes. More explicitly, this will look at all of the offers that have been used by looking at a given Order's adjustments and then match those up with the codes from Order.getAddedOfferCodes().
      Specified by:
      getOffersRetrievedFromCodes in interface OfferService
      Returns:
      a map from Offer to the OfferCode that was used to obtain it
    • getOffersRetrievedFromCodes

      public Map<Offer,OfferCode> getOffersRetrievedFromCodes(List<OfferCode> codes, Set<Offer> appliedOffers)
      Description copied from interface: OfferService
      Given a list of offer codes and a set of offers, return a map of of offer codes that are keyed by the offer that was applied to the order
      Specified by:
      getOffersRetrievedFromCodes in interface OfferService
      Returns:
    • deleteOfferCode

      @Transactional("blTransactionManager") public Boolean deleteOfferCode(OfferCode code)
      Specified by:
      deleteOfferCode in interface OfferService
    • duplicate

      @Transactional("blTransactionManager") public Offer duplicate(Long originalOfferId)
      Description copied from interface: OfferService
      Make a production copy of an offer.
      Specified by:
      duplicate in interface OfferService
      Returns:
    • getCustomerOfferDao

      public CustomerOfferDao getCustomerOfferDao()
      Specified by:
      getCustomerOfferDao in interface OfferService
    • setCustomerOfferDao

      public void setCustomerOfferDao(CustomerOfferDao customerOfferDao)
      Specified by:
      setCustomerOfferDao in interface OfferService
    • getOfferCodeDao

      public OfferCodeDao getOfferCodeDao()
      Specified by:
      getOfferCodeDao in interface OfferService
    • setOfferCodeDao

      public void setOfferCodeDao(OfferCodeDao offerCodeDao)
      Specified by:
      setOfferCodeDao in interface OfferService
    • getOfferDao

      public OfferDao getOfferDao()
      Specified by:
      getOfferDao in interface OfferService
    • setOfferDao

      public void setOfferDao(OfferDao offerDao)
      Specified by:
      setOfferDao in interface OfferService
    • getOrderOfferProcessor

      public OrderOfferProcessor getOrderOfferProcessor()
      Specified by:
      getOrderOfferProcessor in interface OfferService
    • setOrderOfferProcessor

      public void setOrderOfferProcessor(OrderOfferProcessor orderOfferProcessor)
      Specified by:
      setOrderOfferProcessor in interface OfferService
    • getItemOfferProcessor

      public ItemOfferProcessor getItemOfferProcessor()
      Specified by:
      getItemOfferProcessor in interface OfferService
    • setItemOfferProcessor

      public void setItemOfferProcessor(ItemOfferProcessor itemOfferProcessor)
      Specified by:
      setItemOfferProcessor in interface OfferService
    • getFulfillmentGroupOfferProcessor

      public FulfillmentGroupOfferProcessor getFulfillmentGroupOfferProcessor()
      Specified by:
      getFulfillmentGroupOfferProcessor in interface OfferService
    • setFulfillmentGroupOfferProcessor

      public void setFulfillmentGroupOfferProcessor(FulfillmentGroupOfferProcessor fulfillmentGroupOfferProcessor)
      Specified by:
      setFulfillmentGroupOfferProcessor in interface OfferService
    • getPromotableItemFactory

      public PromotableItemFactory getPromotableItemFactory()
      Specified by:
      getPromotableItemFactory in interface OfferService
    • setPromotableItemFactory

      public void setPromotableItemFactory(PromotableItemFactory promotableItemFactory)
      Specified by:
      setPromotableItemFactory in interface OfferService
    • findOfferCodeById

      public OfferCode findOfferCodeById(Long id)
      Description copied from interface: OfferService
      Lookup an OfferCode by its id
      Specified by:
      findOfferCodeById in interface OfferService
      Parameters:
      id - the offer id
      Returns:
      the offer
    • findOfferCodesByIds

      public List<OfferCode> findOfferCodesByIds(Collection<Long> ids)
      Specified by:
      findOfferCodesByIds in interface OfferService
    • getOrderService

      public OrderService getOrderService()
      Specified by:
      getOrderService in interface OfferService
    • setOrderService

      public void setOrderService(OrderService orderService)
      Specified by:
      setOrderService in interface OfferService
    • findOfferById

      public Offer findOfferById(Long offerId)
      Specified by:
      findOfferById in interface OfferService