Search in sources :

Example 1 with OrderItemPriceDetailAdjustment

use of org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment in project BroadleafCommerce by BroadleafCommerce.

the class OrderOfferProcessorImpl method processMatchingDetails.

protected void processMatchingDetails(OrderItemPriceDetail itemDetail, PromotableOrderItemPriceDetail promotableItemDetail) {
    Map<Long, OrderItemPriceDetailAdjustment> itemAdjustmentMap = offerServiceUtilities.buildItemDetailAdjustmentMap(itemDetail);
    if (itemDetail.getQuantity() != promotableItemDetail.getQuantity()) {
        itemDetail.setQuantity(promotableItemDetail.getQuantity());
    }
    for (PromotableOrderItemPriceDetailAdjustment adjustment : promotableItemDetail.getCandidateItemAdjustments()) {
        OrderItemPriceDetailAdjustment itemAdjustment = itemAdjustmentMap.get(adjustment.getOfferId());
        if (!itemAdjustment.getValue().equals(adjustment.getAdjustmentValue())) {
            itemAdjustment.setValue(adjustment.getAdjustmentValue());
            itemAdjustment.setAppliedToSalePrice(adjustment.isAppliedToSalePrice());
        }
    }
}
Also used : PromotableOrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment) PromotableOrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment)

Example 2 with OrderItemPriceDetailAdjustment

use of org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment 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 3 with OrderItemPriceDetailAdjustment

use of org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment in project BroadleafCommerce by BroadleafCommerce.

the class OfferServiceUtilitiesImpl method updatePriceDetail.

@Override
public void updatePriceDetail(OrderItemPriceDetail itemDetail, PromotableOrderItemPriceDetail promotableDetail) {
    Map<Long, OrderItemPriceDetailAdjustment> itemAdjustmentMap = buildItemDetailAdjustmentMap(itemDetail);
    if (itemDetail.getQuantity() != promotableDetail.getQuantity()) {
        itemDetail.setQuantity(promotableDetail.getQuantity());
    }
    if (promotableDetail.isAdjustmentsFinalized()) {
        itemDetail.setUseSalePrice(promotableDetail.useSaleAdjustments());
    }
    for (PromotableOrderItemPriceDetailAdjustment adjustment : promotableDetail.getCandidateItemAdjustments()) {
        OrderItemPriceDetailAdjustment itemAdjustment = itemAdjustmentMap.remove(adjustment.getOfferId());
        if (itemAdjustment != null) {
            // Update existing adjustment
            if (!itemAdjustment.getValue().equals(adjustment.getAdjustmentValue())) {
                updateItemAdjustment(itemAdjustment, adjustment);
            }
        } else {
            // Add a new adjustment
            final OrderItemPriceDetailAdjustment newItemAdjustment;
            ExtensionResultHolder resultHolder = new ExtensionResultHolder();
            if (extensionManager != null) {
                extensionManager.createOrderItemPriceDetailAdjustment(resultHolder, itemDetail);
            }
            if (resultHolder != null && resultHolder.getContextMap().containsKey("OrderItemPriceDetailAdjustment")) {
                newItemAdjustment = (OrderItemPriceDetailAdjustment) resultHolder.getContextMap().get("OrderItemPriceDetailAdjustment");
            } else {
                newItemAdjustment = offerDao.createOrderItemPriceDetailAdjustment();
            }
            newItemAdjustment.init(itemDetail, adjustment.getOffer(), null);
            updateItemAdjustment(newItemAdjustment, adjustment);
            itemDetail.getOrderItemPriceDetailAdjustments().add(newItemAdjustment);
        }
    }
    if (itemAdjustmentMap.size() > 0) {
        // Remove adjustments that were on the order item but no longer needed.
        List<Long> adjustmentIdsToRemove = new ArrayList<Long>();
        for (OrderItemPriceDetailAdjustment adjustmentToRemove : itemAdjustmentMap.values()) {
            adjustmentIdsToRemove.add(adjustmentToRemove.getOffer().getId());
        }
        Iterator<OrderItemPriceDetailAdjustment> iterator = itemDetail.getOrderItemPriceDetailAdjustments().iterator();
        while (iterator.hasNext()) {
            OrderItemPriceDetailAdjustment adj = iterator.next();
            if (adjustmentIdsToRemove.contains(adj.getOffer().getId())) {
                iterator.remove();
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PromotableOrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder) PromotableOrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment)

Example 4 with OrderItemPriceDetailAdjustment

use of org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment in project BroadleafCommerce by BroadleafCommerce.

the class OfferServiceUtilitiesImpl method buildItemDetailAdjustmentMap.

@Override
public Map<Long, OrderItemPriceDetailAdjustment> buildItemDetailAdjustmentMap(OrderItemPriceDetail itemDetail) {
    Map<Long, OrderItemPriceDetailAdjustment> itemAdjustmentMap = new HashMap<Long, OrderItemPriceDetailAdjustment>();
    List<OrderItemPriceDetailAdjustment> adjustmentsToRemove = new ArrayList<OrderItemPriceDetailAdjustment>();
    for (OrderItemPriceDetailAdjustment adjustment : itemDetail.getOrderItemPriceDetailAdjustments()) {
        if (itemAdjustmentMap.containsKey(adjustment.getOffer().getId())) {
            if (LOG.isDebugEnabled()) {
                StringBuilder sb = new StringBuilder("Detected collisions for item adjustments with ids ").append(itemAdjustmentMap.get(adjustment.getOffer().getId()).getId()).append(" and ").append(adjustment.getId());
                LOG.debug(sb.toString());
            }
            adjustmentsToRemove.add(adjustment);
        } else {
            itemAdjustmentMap.put(adjustment.getOffer().getId(), adjustment);
        }
    }
    for (OrderItemPriceDetailAdjustment adjustment : adjustmentsToRemove) {
        itemDetail.getOrderItemPriceDetailAdjustments().remove(adjustment);
    }
    return itemAdjustmentMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PromotableOrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)

Example 5 with OrderItemPriceDetailAdjustment

use of org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment in project BroadleafCommerce by BroadleafCommerce.

the class OrderOfferProcessorImpl method buildItemPriceDetailKey.

protected String buildItemPriceDetailKey(OrderItemPriceDetail itemDetail) {
    List<Long> offerIds = new ArrayList<Long>();
    for (OrderItemPriceDetailAdjustment adjustment : itemDetail.getOrderItemPriceDetailAdjustments()) {
        Long offerId = adjustment.getOffer().getId();
        offerIds.add(offerId);
    }
    Collections.sort(offerIds);
    return itemDetail.getOrderItem().toString() + offerIds.toString() + itemDetail.getUseSalePrice();
}
Also used : ArrayList(java.util.ArrayList) PromotableOrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)

Aggregations

OrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)7 ArrayList (java.util.ArrayList)4 PromotableOrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment)4 HashMap (java.util.HashMap)2 OrderItemPriceDetail (org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)2 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 AdminPresentationMergeOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)1 PromotionQualifier (org.broadleafcommerce.core.offer.service.discount.PromotionQualifier)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1 OrderItemQualifier (org.broadleafcommerce.core.order.domain.OrderItemQualifier)1