use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemServiceImpl method buildOrderItemRequestDTOFromOrderItem.
@Override
public OrderItemRequestDTO buildOrderItemRequestDTOFromOrderItem(OrderItem item) {
OrderItemRequestDTO orderItemRequest;
if (item instanceof DiscreteOrderItem) {
DiscreteOrderItem doi = (DiscreteOrderItem) item;
orderItemRequest = new OrderItemRequestDTO();
if (doi.getCategory() != null) {
orderItemRequest.setCategoryId(doi.getCategory().getId());
}
if (doi.getProduct() != null) {
orderItemRequest.setProductId(doi.getProduct().getId());
}
if (doi.getSku() != null) {
orderItemRequest.setSkuId(doi.getSku().getId());
}
if (doi.getAdditionalAttributes() != null) {
for (Entry<String, String> entry : doi.getAdditionalAttributes().entrySet()) {
orderItemRequest.getAdditionalAttributes().put(entry.getKey(), entry.getValue());
}
}
} else {
orderItemRequest = new NonDiscreteOrderItemRequestDTO();
NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequest;
ndr.setItemName(item.getName());
ndr.setOverrideRetailPrice(item.getRetailPrice());
ndr.setOverrideSalePrice(item.getSalePrice());
}
orderItemRequest.setQuantity(item.getQuantity());
if (item.getOrderItemAttributes() != null) {
for (Entry<String, OrderItemAttribute> entry : item.getOrderItemAttributes().entrySet()) {
orderItemRequest.getItemAttributes().put(entry.getKey(), entry.getValue().getValue());
}
}
if (CollectionUtils.isNotEmpty(item.getChildOrderItems())) {
for (OrderItem childItem : item.getChildOrderItems()) {
orderItemRequest.getChildOrderItems().add(buildOrderItemRequestDTOFromOrderItem(childItem));
}
}
return orderItemRequest;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyCartServiceImpl method addAllItemsToCartFromNamedOrder.
public Order addAllItemsToCartFromNamedOrder(Order namedOrder, boolean priceOrder) throws PricingException {
Order cartOrder = orderDao.readCartForCustomer(namedOrder.getCustomer());
if (cartOrder == null) {
cartOrder = createNewCartForCustomer(namedOrder.getCustomer());
}
List<OrderItem> items = new ArrayList<OrderItem>(namedOrder.getOrderItems());
for (int i = 0; i < items.size(); i++) {
OrderItem orderItem = items.get(i);
// only run pricing routines on the last item.
boolean shouldPriceOrder = (priceOrder && (i == items.size() - 1));
if (moveNamedOrderItems) {
moveItemToOrder(namedOrder, cartOrder, orderItem, shouldPriceOrder);
} else {
addOrderItemToOrder(cartOrder, orderItem, shouldPriceOrder);
}
}
return cartOrder;
}
use of org.broadleafcommerce.core.order.domain.OrderItem 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.OrderItem 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.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method removeItemFromOrder.
protected Order removeItemFromOrder(Order order, OrderItem item, boolean priceOrder) throws PricingException {
fulfillmentGroupService.removeOrderItemFromFullfillmentGroups(order, item);
OrderItem itemFromOrder = order.getOrderItems().remove(order.getOrderItems().indexOf(item));
itemFromOrder.setOrder(null);
orderItemService.delete(itemFromOrder);
order = orderService.save(order, priceOrder);
return order;
}
Aggregations