return mergeCartResponse;
}
@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException {
ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
Order customerCart = orderService.findCartForCustomer(customer);
if (customerCart != null) {
List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
for (OrderItem orderItem : customerCart.getOrderItems()) {
if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
if (discreteOrderItem.getSku().getActiveStartDate() != null) {
if (!discreteOrderItem.getSku().isActive(
discreteOrderItem.getProduct(),
orderItem.getCategory())) {
itemsToRemove.add(orderItem);
}
} else {
if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
itemsToRemove.add(orderItem);
}
}
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
boolean removeBundle = false;
for (DiscreteOrderItem discreteOrderItem : bundleOrderItem
.getDiscreteOrderItems()) {
if (discreteOrderItem.getSku().getActiveStartDate() != null) {
if (!discreteOrderItem.getSku().isActive(
discreteOrderItem.getProduct(),
orderItem.getCategory())) {
/*
* Bundle has an inactive item in it -- remove the
* whole bundle
*/
removeBundle = true;
break;
}
} else {
if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
removeBundle = true;
break;
}
}
}
if (removeBundle) {
itemsToRemove.add(orderItem);
}
}
}
//Remove any giftwrap items who have one or more wrapped item members that have been removed
for (OrderItem orderItem : customerCart.getOrderItems()) {
if (orderItem instanceof GiftWrapOrderItem) {
for (OrderItem wrappedItem : ((GiftWrapOrderItem) orderItem).getWrappedItems()) {
if (itemsToRemove.contains(wrappedItem)) {
itemsToRemove.add(orderItem);
break;
}
}
}
}
for (OrderItem item : itemsToRemove) {
removeItemFromOrder(customerCart, item, priceOrder);
}
reconstructCartResponse.setRemovedItems(itemsToRemove);
}
reconstructCartResponse.setOrder(customerCart);
return reconstructCartResponse;
}