Search in sources :

Example 6 with OrderItemPriceDetailAdjustment

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

the class OfferServiceImpl method verifyAdjustments.

protected boolean verifyAdjustments(Order order, boolean beforeSave) {
    boolean madeChange = false;
    if (order.getOrderItems() == null) {
        return madeChange;
    }
    for (OrderItem oi : order.getOrderItems()) {
        if (oi.getOrderItemPriceDetails() == null) {
            continue;
        }
        for (OrderItemPriceDetail pd : oi.getOrderItemPriceDetails()) {
            if (pd.getOrderItemPriceDetailAdjustments() == null) {
                continue;
            }
            Map<Long, OrderItemPriceDetailAdjustment> adjs = new HashMap<Long, OrderItemPriceDetailAdjustment>();
            List<OrderItemPriceDetailAdjustment> adjustmentsToRemove = new ArrayList<OrderItemPriceDetailAdjustment>();
            for (OrderItemPriceDetailAdjustment adj : pd.getOrderItemPriceDetailAdjustments()) {
                if (adjs.containsKey(adj.getOffer().getId())) {
                    adjustmentsToRemove.add(adj);
                    if (LOG.isDebugEnabled()) {
                        StringBuilder sb = new StringBuilder("Detected collisions ").append(beforeSave ? "before saving" : "after saving").append(" with ids ").append(adjs.get(adj.getOffer().getId()).getId()).append(" and ").append(adj.getId());
                        LOG.debug(sb.toString());
                    }
                } else {
                    adjs.put(adj.getOffer().getId(), adj);
                }
            }
            for (OrderItemPriceDetailAdjustment adj : adjustmentsToRemove) {
                pd.getOrderItemPriceDetailAdjustments().remove(adj);
                madeChange = true;
            }
        }
    }
    return madeChange;
}
Also used : HashMap(java.util.HashMap) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ArrayList(java.util.ArrayList) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)

Example 7 with OrderItemPriceDetailAdjustment

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

the class OrderItemPriceDetailImpl method createOrRetrieveCopyInstance.

@Override
public <G extends OrderItemPriceDetail> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException {
    CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this);
    if (createResponse.isAlreadyPopulated()) {
        return createResponse;
    }
    OrderItemPriceDetail cloned = createResponse.getClone();
    cloned.setQuantity(quantity);
    cloned.setUseSalePrice(useSalePrice);
    // dont clone
    cloned.setOrderItem(orderItem);
    for (OrderItemPriceDetailAdjustment entry : orderItemPriceDetailAdjustments) {
        OrderItemPriceDetailAdjustment clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
        clonedEntry.setOrderItemPriceDetail(cloned);
        cloned.getOrderItemPriceDetailAdjustments().add(clonedEntry);
    }
    return createResponse;
}
Also used : OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)

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