use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.
the class RecordOfferUsageActivity method execute.
@Override
public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context) throws Exception {
Order order = context.getSeedData().getOrder();
Set<Offer> appliedOffers = offerService.getUniqueOffersFromOrder(order);
Map<Offer, OfferCode> offerToCodeMapping = offerService.getOffersRetrievedFromCodes(order.getAddedOfferCodes(), appliedOffers);
List<OfferAudit> audits = saveOfferIds(appliedOffers, offerToCodeMapping, order);
Map<String, Object> state = new HashMap<>();
state.put(SAVED_AUDITS, audits);
ActivityStateManagerImpl.getStateManager().registerState(this, context, getRollbackHandler(), state);
return context;
}
use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.
the class VerifyCustomerMaxOfferUsesActivity method execute.
@Override
public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context) throws Exception {
Order order = context.getSeedData().getOrder();
Set<Offer> appliedOffers = offerService.getUniqueOffersFromOrder(order);
for (Offer offer : appliedOffers) {
if (offer.isLimitedUsePerCustomer()) {
Long currentUses = offerAuditService.countUsesByCustomer(order, order.getCustomer().getId(), offer.getId());
if (currentUses >= offer.getMaxUsesPerCustomer()) {
throw new OfferMaxUseExceededException("The customer has used this offer more than the maximum allowed number of times.");
}
}
}
// TODO: allow lenient checking on offer code usage
for (OfferCode code : order.getAddedOfferCodes()) {
if (code.isLimitedUse()) {
Long currentCodeUses = offerAuditService.countOfferCodeUses(order, code.getId());
if (currentCodeUses >= code.getMaxUses()) {
throw new OfferMaxUseExceededException("Offer code " + code.getOfferCode() + " with id " + code.getId() + " has been than the maximum allowed number of times.");
}
}
}
return context;
}
use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method testOfferLowerSalePriceWithNotCombinableOfferAndInformation.
@Test(groups = { "testOfferLowerSalePriceWithNotCombinableOfferAndInformation" }, dependsOnGroups = { "testOfferLowerSalePriceWithNotCombinableOffer" })
@Transactional
public void testOfferLowerSalePriceWithNotCombinableOfferAndInformation() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
order.addOrderItem(createDiscreteOrderItem(sku1, 100D, 50D, true, 2, order));
order.addOrderItem(createDiscreteOrderItem(sku2, 100D, null, true, 2, order));
OfferCode offerCode1 = createOfferUtility.createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, null, true, true, 1);
OfferCode offerCode2 = createOfferUtility.createOfferCode("30 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 30, null, true, false, 1);
order.addOfferCode(offerCode1);
order.addOfferCode(offerCode2);
OfferInfo info1 = offerDao.createOfferInfo();
info1.getFieldValues().put("key1", "value1");
order.getAdditionalOfferInformation().put(offerCode1.getOffer(), info1);
OfferInfo info2 = offerDao.createOfferInfo();
info2.getFieldValues().put("key2", "value2");
order.getAdditionalOfferInformation().put(offerCode2.getOffer(), info2);
order = orderService.save(order, true);
assert (order.getSubTotal().equals(new Money(180D)));
order = orderService.findOrderById(order.getId());
assert (order.getAdditionalOfferInformation().get(offerCode1.getOffer()).equals(info1));
}
use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceImpl method buildOfferCodeListForCustomer.
@Override
public List<OfferCode> buildOfferCodeListForCustomer(Order order) {
Customer customer = order.getCustomer();
ArrayList<OfferCode> offerCodes = new ArrayList<>();
if (extensionManager != null) {
extensionManager.buildOfferCodeListForCustomer(customer, offerCodes);
}
if (!offerCodes.isEmpty()) {
Iterator<OfferCode> itr = offerCodes.iterator();
while (itr.hasNext()) {
OfferCode offerCode = itr.next();
if (!offerCode.isActive() || !verifyMaxCustomerUsageThreshold(order, offerCode)) {
itr.remove();
}
}
}
return offerCodes;
}
use of org.broadleafcommerce.core.offer.domain.OfferCode in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceImpl method lookupAllOffersByCode.
@Override
public List<Offer> lookupAllOffersByCode(String code) {
List<Offer> offers = new ArrayList<Offer>();
List<OfferCode> offerCodes = offerCodeDao.readAllOfferCodesByCode(code);
for (OfferCode offerCode : offerCodes) {
if (offerCode != null) {
offers.add(offerCode.getOffer());
}
}
return offers;
}
Aggregations