Search in sources :

Example 1 with PromotableOrderItemPriceDetailAdjustment

use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment 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 PromotableOrderItemPriceDetailAdjustment

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

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

the class OfferServiceUtilitiesImpl method applyOrderItemAdjustment.

@Override
public void applyOrderItemAdjustment(PromotableCandidateItemOffer itemOffer, PromotableOrderItemPriceDetail itemPriceDetail) {
    PromotableOrderItemPriceDetailAdjustment promotableOrderItemPriceDetailAdjustment = promotableItemFactory.createPromotableOrderItemPriceDetailAdjustment(itemOffer, itemPriceDetail);
    itemPriceDetail.addCandidateItemPriceDetailAdjustment(promotableOrderItemPriceDetailAdjustment);
}
Also used : PromotableOrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment)

Aggregations

PromotableOrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailAdjustment)3 OrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)2 ArrayList (java.util.ArrayList)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1