Search in sources :

Example 1 with OrderItemQualifier

use of org.broadleafcommerce.core.order.domain.OrderItemQualifier 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 2 with OrderItemQualifier

use of org.broadleafcommerce.core.order.domain.OrderItemQualifier 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)

Aggregations

PromotionQualifier (org.broadleafcommerce.core.offer.service.discount.PromotionQualifier)2 OrderItemQualifier (org.broadleafcommerce.core.order.domain.OrderItemQualifier)2 HashMap (java.util.HashMap)1 OrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)1 OrderItemPriceDetail (org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)1