Search in sources :

Example 1 with Adjustment

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

the class OfferServiceImpl method getUniqueOffersFromOrder.

@Override
@SuppressWarnings("unchecked")
public Set<Offer> getUniqueOffersFromOrder(Order order) {
    HashSet<Offer> result = new HashSet<Offer>();
    Transformer adjustmentToOfferTransformer = new Transformer() {

        @Override
        public Object transform(Object input) {
            return ((Adjustment) input).getOffer();
        }
    };
    result.addAll(CollectionUtils.collect(order.getOrderAdjustments(), adjustmentToOfferTransformer));
    if (order.getOrderItems() != null) {
        for (OrderItem item : order.getOrderItems()) {
            result.addAll(CollectionUtils.collect(item.getOrderItemAdjustments(), adjustmentToOfferTransformer));
            // record usage for price details on the item as well
            if (item.getOrderItemPriceDetails() != null) {
                for (OrderItemPriceDetail detail : item.getOrderItemPriceDetails()) {
                    result.addAll(CollectionUtils.collect(detail.getOrderItemPriceDetailAdjustments(), adjustmentToOfferTransformer));
                }
            }
        }
    }
    if (order.getFulfillmentGroups() != null) {
        for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
            result.addAll(CollectionUtils.collect(fg.getFulfillmentGroupAdjustments(), adjustmentToOfferTransformer));
        }
    }
    return result;
}
Also used : Transformer(org.apache.commons.collections.Transformer) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment) Adjustment(org.broadleafcommerce.core.offer.domain.Adjustment) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Transformer (org.apache.commons.collections.Transformer)1 Adjustment (org.broadleafcommerce.core.offer.domain.Adjustment)1 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)1 Offer (org.broadleafcommerce.core.offer.domain.Offer)1 OrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)1 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)1 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)1 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)1 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1 OrderItemPriceDetail (org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)1