Search in sources :

Example 1 with PromotionQualifier

use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemTest method testGetQuantityAvailableToBeUsedAsTarget.

public void testGetQuantityAvailableToBeUsedAsTarget() throws Exception {
    int quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // no previous qualifiers, so all quantity is available
    assertTrue(quantity == 2);
    PromotionDiscount discount = new PromotionDiscount();
    discount.setPromotion(offer);
    discount.setQuantity(1);
    priceDetail1.getPromotionDiscounts().add(discount);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // items that have already received this promotion cannot get it again
    assertTrue(quantity == 1);
    Offer tempOffer = new OfferImpl();
    tempOffer.setCombinableWithOtherOffers(true);
    tempOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.NONE);
    tempOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.NONE);
    discount.setPromotion(tempOffer);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // this item received a different promotion, but the restriction rule is NONE, so this item cannot be a qualifier
    // for this promotion
    assertTrue(quantity == 1);
    tempOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.TARGET);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // this item received a different promotion, but the restriction rule is TARGET,
    // so this item can be a target of this promotion but since the "candidateOffer"
    // is set to NONE, the quantity can only be 1
    assertTrue(quantity == 1);
    // Now set the candidateOffer to be "TARGET" and we can use the quantity
    // for both promotions.
    candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.TARGET);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // this item received a different promotion, but the restriction rule is TARGET,
    // so this item can be a target of this promotion but since the "candidateOffer"
    // is set to NONE, the quantity can only be 1
    assertTrue(quantity == 2);
    priceDetail1.getPromotionDiscounts().clear();
    // rest candidate offer
    candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.NONE);
    PromotionQualifier qualifier = new PromotionQualifier();
    qualifier.setPromotion(offer);
    qualifier.setQuantity(1);
    priceDetail1.getPromotionQualifiers().add(qualifier);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // items that have already qualified for this promotion cannot qualify again
    assertTrue(quantity == 1);
    qualifier.setPromotion(tempOffer);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // this item qualified for a different promotion, but the restriction rule is NONE,
    // so this item cannot be a qualifier for this promotion
    assertTrue(quantity == 1);
    tempOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.TARGET);
    candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.QUALIFIER);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
// this item qualified for a different promotion, but the restriction rule is QUALIFIER,
// so this item can be a qualifier for this promotion
// dpc disabling this test for now        assertTrue(quantity==2);
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Example 2 with PromotionQualifier

use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemTest method testGetQuantityAvailableToBeUsedAsQualifier.

public void testGetQuantityAvailableToBeUsedAsQualifier() throws Exception {
    int quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // no previous qualifiers, so all quantity is available
    assertTrue(quantity == 2);
    PromotionDiscount discount = new PromotionDiscount();
    discount.setPromotion(offer);
    discount.setQuantity(1);
    priceDetail1.getPromotionDiscounts().add(discount);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // items that have already received this promotion cannot get it again
    assertTrue(quantity == 1);
    Offer testOffer = new OfferImpl();
    testOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.NONE);
    testOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.NONE);
    discount.setPromotion(testOffer);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // this item received a different promotion, but the restriction rule is NONE, so this item cannot be a qualifier for this promotion
    assertTrue(quantity == 1);
    testOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.QUALIFIER);
    candidateOffer.getOffer().setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.TARGET);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // this item received a different promotion, but the restriction rule is QUALIFIER, so this item can be a qualifier
    // for this promotion
    // dpc disabling this test for now        assertTrue(quantity==2);
    priceDetail1.getPromotionDiscounts().clear();
    PromotionQualifier qualifier = new PromotionQualifier();
    qualifier.setPromotion(offer);
    qualifier.setQuantity(1);
    priceDetail1.getPromotionQualifiers().add(qualifier);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // items that have already qualified for this promotion cannot qualify again
    assertTrue(quantity == 1);
    qualifier.setPromotion(testOffer);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // this item qualified for a different promotion, but the restriction rule is NONE, so this item cannot be a qualifier for this promotion
    assertTrue(quantity == 1);
    testOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.QUALIFIER);
    candidateOffer.getOffer().setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.QUALIFIER);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
// this item qualified for a different promotion, but the restriction rule is QUALIFIER,
// so this item can be a qualifier for this promotion
// dpc disabling this test for now        assertTrue(quantity==2);
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Example 3 with PromotionQualifier

use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.

the class OrderOfferProcessorImpl method synchronizeItemQualifiers.

protected void synchronizeItemQualifiers(OrderItem orderItem, PromotableOrderItem promotableOrderItem) {
    Map<Long, PromotionQualifier> qualifiersMap = buildPromotableQualifiersMap(promotableOrderItem);
    Map<Long, OrderItemQualifier> unmatchedQualifiersMap = new HashMap<Long, OrderItemQualifier>();
    for (OrderItemQualifier orderItemQualifier : orderItem.getOrderItemQualifiers()) {
        PromotionQualifier promotableQualifier = qualifiersMap.remove(orderItemQualifier.getOffer().getId());
        if (promotableQualifier != null) {
            // Offer was used as a qualifier on previous run.   Update quantity if needed.
            if (orderItemQualifier.getQuantity() != promotableQualifier.getQuantity()) {
                orderItemQualifier.setQuantity(new Long(promotableQualifier.getQuantity()));
            }
        } else {
            unmatchedQualifiersMap.put(orderItemQualifier.getId(), orderItemQualifier);
        }
    }
    Iterator<OrderItemQualifier> unmatchedQualifiersIterator = unmatchedQualifiersMap.values().iterator();
    for (PromotionQualifier qualifier : qualifiersMap.values()) {
        if (unmatchedQualifiersIterator.hasNext()) {
            // Reuse an existing qualifier
            OrderItemQualifier existingQualifier = unmatchedQualifiersIterator.next();
            existingQualifier.setOffer(qualifier.getPromotion());
            existingQualifier.setQuantity(Long.valueOf(qualifier.getQuantity()));
            unmatchedQualifiersIterator.remove();
        } else {
            // Create a new qualifier
            OrderItemQualifier newQualifier = orderItemDao.createOrderItemQualifier();
            newQualifier.setOrderItem(orderItem);
            newQualifier.setOffer(qualifier.getPromotion());
            newQualifier.setQuantity(Long.valueOf(qualifier.getQuantity()));
            orderItem.getOrderItemQualifiers().add(newQualifier);
        }
    }
    // Remove any unmatched qualifiers
    Iterator<OrderItemQualifier> qIterator = orderItem.getOrderItemQualifiers().iterator();
    offerServiceUtilities.removeUnmatchedQualifiers(unmatchedQualifiersMap, qIterator);
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) HashMap(java.util.HashMap) OrderItemQualifier(org.broadleafcommerce.core.order.domain.OrderItemQualifier)

Example 4 with PromotionQualifier

use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.

the class PromotableOrderItemImpl method initializePriceDetails.

protected void initializePriceDetails() {
    if (includeAdjustments) {
        for (OrderItemPriceDetail detail : orderItem.getOrderItemPriceDetails()) {
            PromotableOrderItemPriceDetail poid = itemFactory.createPromotableOrderItemPriceDetail(this, detail.getQuantity());
            itemPriceDetails.add(poid);
            for (OrderItemPriceDetailAdjustment adjustment : detail.getOrderItemPriceDetailAdjustments()) {
                PromotableOrderItemPriceDetailAdjustment poidAdj = new PromotableOrderItemPriceDetailAdjustmentImpl(adjustment, poid);
                poid.addCandidateItemPriceDetailAdjustment(poidAdj);
            }
            poid.chooseSaleOrRetailAdjustments();
            List<OrderItemQualifier> oiqs = poid.getPromotableOrderItem().getOrderItem().getOrderItemQualifiers();
            if (CollectionUtils.isNotEmpty(oiqs)) {
                for (OrderItemQualifier oiq : oiqs) {
                    PromotionQualifier pq = new PromotionQualifier();
                    pq.setPromotion(oiq.getOffer());
                    pq.setQuantity(oiq.getQuantity().intValue());
                    pq.setFinalizedQuantity(oiq.getQuantity().intValue());
                    pq.setPrice(oiq.getOrderItem().getPriceBeforeAdjustments(oiq.getOffer().getApplyDiscountToSalePrice()));
                    poid.getPromotionQualifiers().add(pq);
                }
            }
        }
    } else {
        PromotableOrderItemPriceDetail poid = itemFactory.createPromotableOrderItemPriceDetail(this, orderItem.getQuantity());
        itemPriceDetails.add(poid);
    }
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) OrderItemQualifier(org.broadleafcommerce.core.order.domain.OrderItemQualifier) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)

Example 5 with PromotionQualifier

use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.

the class PromotableOrderItemPriceDetailImpl method getQuantityAvailableToBeUsedAsTarget.

@Override
public int getQuantityAvailableToBeUsedAsTarget(PromotableCandidateItemOffer itemOffer) {
    int qtyAvailable = quantity;
    Offer promotion = itemOffer.getOffer();
    // 1. Any quantities of this item that have already received the promotion are not eligible.
    // 2. If this promotion is not combinable then any quantities that have received discounts
    // from other promotions cannot receive this discount
    // 3. If this promotion is combinable then any quantities that have received discounts from
    // other combinable promotions are eligible to receive this discount as well
    boolean combinable = promotion.isCombinableWithOtherOffers();
    if (!combinable && isNonCombinableOfferApplied()) {
        return 0;
    }
    // if this promotion cannot be combined with another discount.
    for (PromotionDiscount promotionDiscount : promotionDiscounts) {
        if (promotionDiscount.getPromotion().equals(promotion) || restrictTarget(promotion, true)) {
            qtyAvailable = qtyAvailable - promotionDiscount.getQuantity();
        } else {
            // it to be reused as a target.
            if (restrictTarget(promotionDiscount.getPromotion(), true)) {
                qtyAvailable = qtyAvailable - promotionDiscount.getQuantity();
            }
        }
    }
    // not allow the qualifier to be reused must be deduced from the qtyAvailable.
    for (PromotionQualifier promotionQualifier : promotionQualifiers) {
        if (promotionQualifier.getPromotion().equals(promotion) || restrictQualifier(promotion, true)) {
            qtyAvailable = qtyAvailable - promotionQualifier.getQuantity();
        } else {
            if (restrictTarget(promotionQualifier.getPromotion(), false)) {
                qtyAvailable = qtyAvailable - promotionQualifier.getQuantity();
            }
        }
    }
    return qtyAvailable;
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Aggregations

PromotionQualifier (org.broadleafcommerce.core.offer.service.discount.PromotionQualifier)13 PromotionDiscount (org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)7 Offer (org.broadleafcommerce.core.offer.domain.Offer)5 Money (org.broadleafcommerce.common.money.Money)2 OfferImpl (org.broadleafcommerce.core.offer.domain.OfferImpl)2 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)2 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)2 PromotableCandidateItemOfferImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl)2 PromotableOrderItemPriceDetail (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)2 OrderItemQualifier (org.broadleafcommerce.core.order.domain.OrderItemQualifier)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 OrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)1 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1 OrderItemPriceDetail (org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)1