Search in sources :

Example 11 with OfferCode

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;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OfferAudit(org.broadleafcommerce.core.offer.domain.OfferAudit) Offer(org.broadleafcommerce.core.offer.domain.Offer) HashMap(java.util.HashMap) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode)

Example 12 with OfferCode

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;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OfferMaxUseExceededException(org.broadleafcommerce.core.offer.service.exception.OfferMaxUseExceededException) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode)

Example 13 with OfferCode

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));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) OfferInfo(org.broadleafcommerce.core.offer.domain.OfferInfo) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with OfferCode

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;
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) ArrayList(java.util.ArrayList)

Example 15 with OfferCode

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;
}
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) ArrayList(java.util.ArrayList) 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