Search in sources :

Example 1 with PromotableOrderAdjustment

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

the class OrderOfferProcessorImpl method synchronizeOrderAdjustments.

protected void synchronizeOrderAdjustments(PromotableOrder promotableOrder) {
    Order order = promotableOrder.getOrder();
    if (order.getOrderAdjustments().isEmpty() && promotableOrder.getCandidateOrderAdjustments().isEmpty()) {
        return;
    }
    Map<Long, PromotableOrderAdjustment> newAdjustmentsMap = buildPromotableOrderAdjustmentsMap(promotableOrder);
    Iterator<OrderAdjustment> orderAdjIterator = order.getOrderAdjustments().iterator();
    while (orderAdjIterator.hasNext()) {
        OrderAdjustment adjustment = orderAdjIterator.next();
        if (adjustment.getOffer() != null) {
            Long offerId = adjustment.getOffer().getId();
            PromotableOrderAdjustment promotableAdjustment = newAdjustmentsMap.remove(offerId);
            if (promotableAdjustment != null) {
                if (!adjustment.getValue().equals(promotableAdjustment.getAdjustmentValue())) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Updating value for order adjustment with offer Id " + offerId + " to " + promotableAdjustment.getAdjustmentValue());
                    }
                    adjustment.setValue(promotableAdjustment.getAdjustmentValue());
                }
            } else {
                // No longer using this order adjustment, remove it.
                orderAdjIterator.remove();
            }
        }
    }
    for (PromotableOrderAdjustment promotableOrderAdjustment : newAdjustmentsMap.values()) {
        // Add the newly introduced adjustments.
        Offer offer = promotableOrderAdjustment.getOffer();
        OrderAdjustment orderAdjustment = offerDao.createOrderAdjustment();
        orderAdjustment.init(order, offer, offer.getName());
        orderAdjustment.setValue(promotableOrderAdjustment.getAdjustmentValue());
        order.getOrderAdjustments().add(orderAdjustment);
    }
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) PromotableOrderAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderAdjustment) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) 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) PromotableOrderAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderAdjustment)

Example 2 with PromotableOrderAdjustment

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

the class OrderOfferProcessorImpl method applyOrderOffer.

/**
 * Private method used by applyAllOrderOffers to create an OrderAdjustment from a CandidateOrderOffer
 * and associates the OrderAdjustment to the Order.
 *
 * @param orderOffer a CandidateOrderOffer to apply to an Order
 */
protected void applyOrderOffer(PromotableOrder promotableOrder, PromotableCandidateOrderOffer orderOffer) {
    PromotableOrderAdjustment promotableOrderAdjustment = promotableItemFactory.createPromotableOrderAdjustment(orderOffer, promotableOrder);
    promotableOrder.addCandidateOrderAdjustment(promotableOrderAdjustment);
}
Also used : PromotableOrderAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderAdjustment)

Aggregations

PromotableOrderAdjustment (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderAdjustment)2 Offer (org.broadleafcommerce.core.offer.domain.Offer)1 OrderAdjustment (org.broadleafcommerce.core.offer.domain.OrderAdjustment)1 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)1 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)1 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)1 Order (org.broadleafcommerce.core.order.domain.Order)1