use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method mergeGiftWrapOrderItems.
protected Order mergeGiftWrapOrderItems(MergeCartResponse mergeCartResponse, Order customerCart, Map<OrderItem, OrderItem> oldNewItemMap) throws PricingException {
// update any remaining gift wrap items with their cloned wrapped item values, instead of the originals
Iterator<OrderItem> addedItems = mergeCartResponse.getAddedItems().iterator();
while (addedItems.hasNext()) {
OrderItem addedItem = addedItems.next();
if (addedItem instanceof GiftWrapOrderItem) {
GiftWrapOrderItem giftItem = (GiftWrapOrderItem) addedItem;
List<OrderItem> itemsToAdd = new ArrayList<OrderItem>();
Iterator<OrderItem> wrappedItems = giftItem.getWrappedItems().iterator();
while (wrappedItems.hasNext()) {
OrderItem wrappedItem = wrappedItems.next();
if (oldNewItemMap.containsKey(wrappedItem)) {
OrderItem newItem = oldNewItemMap.get(wrappedItem);
newItem.setGiftWrapOrderItem(giftItem);
itemsToAdd.add(newItem);
wrappedItem.setGiftWrapOrderItem(null);
wrappedItems.remove();
}
}
giftItem.getWrappedItems().addAll(itemsToAdd);
} else if (addedItem instanceof BundleOrderItem) {
// a GiftWrapOrderItem inside a BundleOrderItem can only wrap other members of that bundle
// or root members of the order - not members of an entirely different bundle
boolean isValidBundle = true;
Map<String, DiscreteOrderItem> newItemsMap = new HashMap<String, DiscreteOrderItem>();
for (DiscreteOrderItem newItem : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
newItemsMap.put(newItem.getSku().getId() + "_" + newItem.getPrice(), newItem);
}
checkBundle: {
for (DiscreteOrderItem itemFromBundle : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
if (itemFromBundle instanceof GiftWrapOrderItem) {
GiftWrapOrderItem giftItem = (GiftWrapOrderItem) itemFromBundle;
List<OrderItem> itemsToAdd = new ArrayList<OrderItem>();
Iterator<OrderItem> wrappedItems = giftItem.getWrappedItems().iterator();
while (wrappedItems.hasNext()) {
OrderItem wrappedItem = wrappedItems.next();
if (oldNewItemMap.containsKey(wrappedItem)) {
OrderItem newItem = oldNewItemMap.get(wrappedItem);
newItem.setGiftWrapOrderItem(giftItem);
itemsToAdd.add(newItem);
wrappedItem.setGiftWrapOrderItem(null);
wrappedItems.remove();
} else if (wrappedItem instanceof DiscreteOrderItem) {
DiscreteOrderItem discreteWrappedItem = (DiscreteOrderItem) wrappedItem;
String itemKey = discreteWrappedItem.getSku().getId() + "_" + discreteWrappedItem.getPrice();
if (newItemsMap.containsKey(itemKey)) {
OrderItem newItem = newItemsMap.get(itemKey);
newItem.setGiftWrapOrderItem(giftItem);
itemsToAdd.add(newItem);
discreteWrappedItem.setGiftWrapOrderItem(null);
wrappedItems.remove();
} else {
isValidBundle = false;
break checkBundle;
}
} else {
isValidBundle = false;
break checkBundle;
}
}
giftItem.getWrappedItems().addAll(itemsToAdd);
}
}
}
if (!isValidBundle) {
customerCart = removeItemFromOrder(customerCart, addedItem, false);
addedItems.remove();
mergeCartResponse.getRemovedItems().add(addedItem);
}
}
}
// If found, remove, because this is invalid. A GiftWrapOrderItem cannot wrap OrderItems located in an entirely different bundle.
for (OrderItem addedItem : mergeCartResponse.getAddedItems()) {
if (addedItem instanceof BundleOrderItem) {
boolean containsGiftWrap = false;
for (DiscreteOrderItem discreteOrderItem : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
if (discreteOrderItem instanceof GiftWrapOrderItem) {
containsGiftWrap = true;
break;
}
}
if (!containsGiftWrap) {
for (DiscreteOrderItem discreteOrderItem : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
discreteOrderItem.setGiftWrapOrderItem(null);
}
}
}
}
return customerCart;
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method mergeRegularOrderItems.
protected Order mergeRegularOrderItems(Order anonymousCart, MergeCartResponse mergeCartResponse, Order customerCart, Map<OrderItem, OrderItem> oldNewItemMap) throws PricingException {
// currently we'll just add items
for (OrderItem orderItem : anonymousCart.getOrderItems()) {
if (orderItem instanceof DiscreteOrderItem) {
orderItem.removeAllAdjustments();
orderItem.removeAllCandidateItemOffers();
DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
if (discreteOrderItem.getSku().getActiveStartDate() != null) {
if (discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
OrderItem newItem = addOrderItemToOrder(customerCart, discreteOrderItem.clone(), false);
mergeCartResponse.getAddedItems().add(newItem);
oldNewItemMap.put(orderItem, newItem);
} else {
mergeCartResponse.getRemovedItems().add(orderItem);
}
} else {
if (discreteOrderItem.getProduct().isActive() && orderItem.getCategory().isActive()) {
OrderItem newItem = addOrderItemToOrder(customerCart, discreteOrderItem.clone(), false);
mergeCartResponse.getAddedItems().add(newItem);
oldNewItemMap.put(orderItem, newItem);
} else {
mergeCartResponse.getRemovedItems().add(orderItem);
}
}
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
orderItem.removeAllAdjustments();
orderItem.removeAllCandidateItemOffers();
boolean removeBundle = false;
for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
discreteOrderItem.removeAllAdjustments();
discreteOrderItem.removeAllCandidateItemOffers();
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;
}
} else {
if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
removeBundle = true;
}
}
}
if (!removeBundle) {
OrderItem newItem = addOrderItemToOrder(customerCart, bundleOrderItem.clone(), false);
mergeCartResponse.getAddedItems().add(newItem);
oldNewItemMap.put(orderItem, newItem);
} else {
mergeCartResponse.getRemovedItems().add(orderItem);
}
}
}
return customerCart;
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method addDiscreteItemToOrder.
@Override
@Deprecated
public OrderItem addDiscreteItemToOrder(Order order, DiscreteOrderItemRequest itemRequest, boolean priceOrder) throws PricingException {
itemRequest.setOrder(order);
DiscreteOrderItem item = orderItemService.createDiscreteOrderItem(itemRequest);
return addOrderItemToOrder(order, item, priceOrder);
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method removeOrderItemFromFullfillmentGroup.
protected void removeOrderItemFromFullfillmentGroup(Order order, OrderItem orderItem) {
List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
Iterator<FulfillmentGroupItem> itr = fulfillmentGroup.getFulfillmentGroupItems().iterator();
while (itr.hasNext()) {
FulfillmentGroupItem fulfillmentGroupItem = itr.next();
if (fulfillmentGroupItem.getOrderItem().equals(orderItem)) {
itr.remove();
fulfillmentGroupItemDao.delete(fulfillmentGroupItem);
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
if (fulfillmentGroupItem.getOrderItem().equals(discreteOrderItem)) {
itr.remove();
fulfillmentGroupItemDao.delete(fulfillmentGroupItem);
break;
}
}
}
}
}
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method removeItemFromBundle.
@Override
public Order removeItemFromBundle(Order order, BundleOrderItem bundle, OrderItem item, boolean priceOrder) throws PricingException {
DiscreteOrderItem itemFromBundle = bundle.getDiscreteOrderItems().remove(bundle.getDiscreteOrderItems().indexOf(item));
orderItemService.delete(itemFromBundle);
itemFromBundle.setBundleOrderItem(null);
order = updateOrder(order, priceOrder);
return order;
}
Aggregations