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;
}
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;
}
Aggregations