Search in sources :

Example 16 with OfferCode

use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.

the class OfferServiceImpl method lookupOfferByCode.

/**
 * 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.
 *
 * @param code
 * @return a List of offers that may apply to this order
 */
@Override
public Offer lookupOfferByCode(String code) {
    Offer offer = null;
    OfferCode offerCode = offerCodeDao.readOfferCodeByCode(code);
    if (offerCode != null) {
        offer = offerCode.getOffer();
    }
    return offer;
}
Also used : PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode)

Example 17 with OfferCode

use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.

the class OfferCodeDaoImpl method readOfferCodeByCode.

@Override
@SuppressWarnings("unchecked")
public OfferCode readOfferCodeByCode(String code) {
    OfferCode offerCode = null;
    Query query = readOfferCodesQuery(code);
    List<OfferCode> result = query.getResultList();
    if (result.size() > 0) {
        offerCode = result.get(0);
    }
    return offerCode;
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode)

Example 18 with OfferCode

use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafCartController method removePromo.

/**
 * Removes offer from cart
 *
 * @param request
 * @param response
 * @param model
 * @return the return view
 * @throws IOException
 * @throws PricingException
 * @throws OfferMaxUseExceededException
 */
public String removePromo(HttpServletRequest request, HttpServletResponse response, Model model, Long offerCodeId) throws IOException, PricingException {
    Order cart = CartState.getCart();
    OfferCode offerCode = offerService.findOfferCodeById(offerCodeId);
    orderService.removeOfferCode(cart, offerCode, false);
    cart = orderService.save(cart, true);
    if (isCheckoutContext(request)) {
        return getCheckoutView();
    } else {
        return isAjaxRequest(request) ? getCartView() : getCartPageRedirect();
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode)

Example 19 with OfferCode

use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method addOfferCodes.

@Override
@Transactional("blTransactionManager")
public Order addOfferCodes(Order order, List<OfferCode> offerCodes, boolean priceOrder) throws PricingException, OfferException {
    preValidateCartOperation(order);
    Set<Offer> addedOffers = offerService.getUniqueOffersFromOrder(order);
    if (extensionManager != null) {
        extensionManager.getProxy().addOfferCodes(order, offerCodes, priceOrder);
    }
    if (offerCodes != null && !offerCodes.isEmpty()) {
        for (OfferCode offerCode : offerCodes) {
            if (order.getAddedOfferCodes().contains(offerCode) || addedOffers.contains(offerCode.getOffer())) {
                throw new OfferAlreadyAddedException("The offer has already been added.");
            } else if (!offerService.verifyMaxCustomerUsageThreshold(order, offerCode)) {
                throw new OfferMaxUseExceededException("The customer has used this offer code more than the maximum allowed number of times.");
            } else if (!offerCode.isActive() || !offerCode.getOffer().isActive()) {
                throw new OfferExpiredException("The offer has expired.");
            }
            order.getAddedOfferCodes().add(offerCode);
        }
        order = save(order, priceOrder);
    }
    return order;
}
Also used : OfferMaxUseExceededException(org.broadleafcommerce.core.offer.service.exception.OfferMaxUseExceededException) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) OfferExpiredException(org.broadleafcommerce.core.offer.service.exception.OfferExpiredException) OfferAlreadyAddedException(org.broadleafcommerce.core.offer.service.exception.OfferAlreadyAddedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with OfferCode

use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.

the class OfferActivity method execute.

@Override
public ProcessContext<Order> execute(ProcessContext<Order> context) throws Exception {
    Order order = context.getSeedData();
    List<OfferCode> offerCodes = getNewOfferCodesFromCustomer(order);
    if (offerCodes != null && !offerCodes.isEmpty()) {
        order = orderService.addOfferCodes(order, offerCodes, false);
    }
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    order = offerService.applyAndSaveOffersToOrder(offers, order);
    context.setSeedData(order);
    return context;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode)

Aggregations

OfferCode (org.broadleafcommerce.core.offer.domain.OfferCode)20 Offer (org.broadleafcommerce.core.offer.domain.Offer)13 Order (org.broadleafcommerce.core.order.domain.Order)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)5 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)4 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)4 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)4 OfferInfo (org.broadleafcommerce.core.offer.domain.OfferInfo)3 OfferMaxUseExceededException (org.broadleafcommerce.core.offer.service.exception.OfferMaxUseExceededException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Money (org.broadleafcommerce.common.money.Money)2 OfferAudit (org.broadleafcommerce.core.offer.domain.OfferAudit)2 OfferAlreadyAddedException (org.broadleafcommerce.core.offer.service.exception.OfferAlreadyAddedException)2 OfferExpiredException (org.broadleafcommerce.core.offer.service.exception.OfferExpiredException)2 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)2 Test (org.testng.annotations.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Map (java.util.Map)1