use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method reconstructCart.
@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;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method addOrderItemToOrder.
@Override
@Deprecated
public OrderItem addOrderItemToOrder(Order order, OrderItem newOrderItem, boolean priceOrder) throws PricingException {
if (automaticallyMergeLikeItems) {
OrderItem item = findMatchingItem(order, newOrderItem);
if (item != null) {
item.setQuantity(item.getQuantity() + newOrderItem.getQuantity());
try {
updateItemQuantity(order, item, priceOrder);
} catch (ItemNotFoundException e) {
LOG.error(e);
}
return findMatchingItem(order, newOrderItem);
}
}
List<OrderItem> orderItems = order.getOrderItems();
orderItems.add(newOrderItem);
newOrderItem.setOrder(order);
order = updateOrder(order, priceOrder);
return findMatchingItem(order, newOrderItem);
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method removeItemFromOrder.
@Override
public Order removeItemFromOrder(Long orderId, Long itemId, boolean priceOrder) throws PricingException {
Order order = findOrderById(orderId);
OrderItem orderItem = orderItemService.readOrderItemById(itemId);
return removeItemFromOrder(order, orderItem, priceOrder);
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method moveItemToOrder.
public Order moveItemToOrder(Order originalOrder, Order destinationOrder, OrderItem item, boolean priceOrder) throws PricingException {
fulfillmentGroupService.removeOrderItemFromFullfillmentGroups(originalOrder, item);
OrderItem itemFromOrder = originalOrder.getOrderItems().remove(originalOrder.getOrderItems().indexOf(item));
itemFromOrder.setOrder(null);
originalOrder = updateOrder(originalOrder, priceOrder);
addOrderItemToOrder(destinationOrder, item, priceOrder);
return destinationOrder;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method removeOrderItemAttribute.
@Override
public Order removeOrderItemAttribute(Order order, OrderItem item, String attributeName, boolean priceOrder) throws ItemNotFoundException, PricingException {
if (!order.getOrderItems().contains(item)) {
throw new ItemNotFoundException("Order Item (" + item.getId() + ") not found in Order (" + order.getId() + ")");
}
OrderItem itemFromOrder = order.getOrderItems().get(order.getOrderItems().indexOf(item));
boolean changeMade = false;
Map<String, OrderItemAttribute> orderItemAttributes = itemFromOrder.getOrderItemAttributes();
if (orderItemAttributes != null) {
if (orderItemAttributes.containsKey(attributeName)) {
changeMade = true;
orderItemAttributes.remove(attributeName);
}
}
if (changeMade) {
return updateOrder(order, priceOrder);
} else {
return order;
}
}
Aggregations