Search in sources :

Example 6 with PromotableOrderItemPriceDetail

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

the class ItemOfferProcessorImpl method calculateWeightedPercent.

protected BigDecimal calculateWeightedPercent(PromotionDiscount discount, PromotableOrderItem item, Money itemSavings) {
    Money effectedItemsSubtotal = discount.getCandidateItemOffer().getOriginalPrice();
    for (PromotableOrderItemPriceDetail itemPriceDetail : item.getPromotableOrderItemPriceDetails()) {
        for (PromotionQualifier qualifierDetail : itemPriceDetail.getPromotionQualifiers()) {
            Integer qualifierQuantity = qualifierDetail.getFinalizedQuantity();
            effectedItemsSubtotal = effectedItemsSubtotal.add(qualifierDetail.getPrice().multiply(qualifierQuantity));
        }
    }
    return calculatePercent(effectedItemsSubtotal, itemSavings);
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 7 with PromotableOrderItemPriceDetail

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

the class ItemOfferProcessorImpl method markTargets.

/**
 * Loop through ItemCriteria and mark targets that can get this promotion to give the promotion to 1 or more targets.
 * @param itemOffer
 * @param order
 * @return
 */
public boolean markTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order, OrderItem relatedQualifier, boolean checkOnly) {
    Offer promotion = itemOffer.getOffer();
    if (itemOffer.getCandidateTargetsMap().keySet().isEmpty()) {
        return false;
    }
    OrderItem relatedQualifierRoot = offerServiceUtilities.findRelatedQualifierRoot(relatedQualifier);
    for (OfferItemCriteria itemCriteria : itemOffer.getCandidateTargetsMap().keySet()) {
        List<PromotableOrderItem> promotableItems = itemOffer.getCandidateTargetsMap().get(itemCriteria);
        List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
        offerServiceUtilities.sortTargetItemDetails(priceDetails, itemOffer.getOffer().getApplyDiscountToSalePrice());
        int targetQtyNeeded = itemCriteria.getQuantity();
        // This code was added to support a requirement of buying at least "x" matching items
        // but also applying the item to "x+1", "x+2", etc.
        int minRequiredTargetQuantity = itemOffer.getMinimumRequiredTargetQuantity();
        if (minRequiredTargetQuantity > 1 && minRequiredTargetQuantity > targetQtyNeeded) {
            targetQtyNeeded = minRequiredTargetQuantity;
        }
        targetQtyNeeded = offerServiceUtilities.markTargetsForCriteria(itemOffer, relatedQualifier, checkOnly, promotion, relatedQualifierRoot, itemCriteria, priceDetails, targetQtyNeeded);
        if (targetQtyNeeded != 0) {
            return false;
        }
    }
    if (!checkOnly) {
        itemOffer.addUse();
    }
    return true;
}
Also used : PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 8 with PromotableOrderItemPriceDetail

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

the class ItemOfferProcessorImpl method markRelatedQualifiersAndTargets.

/**
 * When the {@link Offer#getRequiresRelatedTargetAndQualifiers()} flag is set to true, we must make sure that we
 * identify qualifiers and targets together, as they must be related to each other based on the
 * {@link OrderItem#getParentOrderItem()} / {@link OrderItem#getChildOrderItems()} attributes.
 *
 * @param itemOffer
 * @param order
 * @return whether or not a suitable qualifier/target pair was found and marked
 */
protected boolean markRelatedQualifiersAndTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order) {
    OrderItemHolder orderItemHolder = new OrderItemHolder(null);
    for (Entry<OfferItemCriteria, List<PromotableOrderItem>> entry : itemOffer.getCandidateQualifiersMap().entrySet()) {
        OfferItemCriteria itemCriteria = entry.getKey();
        List<PromotableOrderItem> promotableItems = entry.getValue();
        List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
        int qualifierQtyNeeded = offerServiceUtilities.markRelatedQualifiersAndTargetsForItemCriteria(itemOffer, order, orderItemHolder, itemCriteria, priceDetails, this);
        if (qualifierQtyNeeded != 0) {
            return false;
        }
    }
    return markTargets(itemOffer, order, orderItemHolder.getOrderItem(), false);
}
Also used : OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) ArrayList(java.util.ArrayList) List(java.util.List) OrderItemHolder(org.broadleafcommerce.core.order.domain.dto.OrderItemHolder) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 9 with PromotableOrderItemPriceDetail

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

the class ItemOfferProcessorImpl method chooseSaleOrRetailAdjustments.

/**
 * Some promotions can only apply to the retail price.    This method determines whether
 * retailPrice only promotions should be used instead of those that can apply to the sale
 * price as well.
 *
 * @param order
 * @return
 */
protected void chooseSaleOrRetailAdjustments(PromotableOrder order) {
    List<PromotableOrderItemPriceDetail> itemPriceDetails = order.getAllPromotableOrderItemPriceDetails();
    for (PromotableOrderItemPriceDetail itemDetail : itemPriceDetails) {
        itemDetail.chooseSaleOrRetailAdjustments();
    }
    mergePriceDetails(order);
}
Also used : PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 10 with PromotableOrderItemPriceDetail

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

the class OfferServiceUtilitiesImpl method markQualifiersForCriteria.

@Override
public int markQualifiersForCriteria(PromotableCandidateItemOffer itemOffer, OfferItemCriteria itemCriteria, List<PromotableOrderItemPriceDetail> priceDetails) {
    sortQualifierItemDetails(priceDetails, itemOffer.getOffer().getApplyDiscountToSalePrice());
    // Calculate the number of qualifiers needed that will not receive the promotion.
    // These will be reserved first before the target is assigned.
    int qualifierQtyNeeded = itemCriteria.getQuantity();
    for (PromotableOrderItemPriceDetail detail : priceDetails) {
        // Mark Qualifiers
        if (qualifierQtyNeeded > 0) {
            int itemQtyAvailableToBeUsedAsQualifier = detail.getQuantityAvailableToBeUsedAsQualifier(itemOffer);
            if (itemQtyAvailableToBeUsedAsQualifier > 0) {
                int qtyToMarkAsQualifier = Math.min(qualifierQtyNeeded, itemQtyAvailableToBeUsedAsQualifier);
                qualifierQtyNeeded -= qtyToMarkAsQualifier;
                detail.addPromotionQualifier(itemOffer, itemCriteria, qtyToMarkAsQualifier);
            }
        }
        if (qualifierQtyNeeded == 0) {
            break;
        }
    }
    return qualifierQtyNeeded;
}
Also used : PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Aggregations

PromotableOrderItemPriceDetail (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)12 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)4 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)4 Money (org.broadleafcommerce.common.money.Money)3 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)3 Offer (org.broadleafcommerce.core.offer.domain.Offer)2 PromotionDiscount (org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)2 PromotionQualifier (org.broadleafcommerce.core.offer.service.discount.PromotionQualifier)2 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)2 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 OrderItemPriceDetail (org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)1 OrderItemHolder (org.broadleafcommerce.core.order.domain.dto.OrderItemHolder)1