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;
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations