use of org.broadleafcommerce.core.order.service.exception.ItemNotFoundException in project BroadleafCommerce by BroadleafCommerce.
the class OrderServiceImpl method removeItem.
@Override
@Transactional(value = "blTransactionManager", rollbackFor = { RemoveFromCartException.class })
public Order removeItem(Long orderId, Long orderItemId, boolean priceOrder) throws RemoveFromCartException {
preValidateCartOperation(findOrderById(orderId));
try {
OrderItem oi = orderItemService.readOrderItemById(orderItemId);
if (oi == null) {
throw new WorkflowException(new ItemNotFoundException());
}
List<Long> childrenToRemove = new ArrayList<Long>();
if (oi instanceof BundleOrderItem) {
List<DiscreteOrderItem> bundledItems = ((BundleOrderItem) oi).getDiscreteOrderItems();
for (DiscreteOrderItem doi : bundledItems) {
findAllChildrenToRemove(childrenToRemove, doi);
}
} else {
findAllChildrenToRemove(childrenToRemove, oi);
}
for (Long childToRemove : childrenToRemove) {
removeItemInternal(orderId, childToRemove, false);
}
return removeItemInternal(orderId, orderItemId, priceOrder);
} catch (WorkflowException e) {
throw new RemoveFromCartException("Could not remove from cart", getCartOperationExceptionRootCause(e));
}
}
use of org.broadleafcommerce.core.order.service.exception.ItemNotFoundException 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.service.exception.ItemNotFoundException 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;
}
}
use of org.broadleafcommerce.core.order.service.exception.ItemNotFoundException in project BroadleafCommerce by BroadleafCommerce.
the class UpdateOrderItemActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
Order order = request.getOrder();
OrderItem orderItem = null;
for (OrderItem oi : order.getOrderItems()) {
if (oi.getId().equals(orderItemRequestDTO.getOrderItemId())) {
orderItem = oi;
}
}
if (orderItem == null || !order.getOrderItems().contains(orderItem)) {
throw new ItemNotFoundException("Order Item (" + orderItemRequestDTO.getOrderItemId() + ") not found in Order (" + order.getId() + ")");
}
OrderItem itemFromOrder = order.getOrderItems().get(order.getOrderItems().indexOf(orderItem));
if (orderItemRequestDTO.getQuantity() >= 0) {
int previousQty = itemFromOrder.getQuantity();
request.setOrderItemQuantityDelta(orderItemRequestDTO.getQuantity() - itemFromOrder.getQuantity());
itemFromOrder.setQuantity(orderItemRequestDTO.getQuantity());
for (OrderItem child : itemFromOrder.getChildOrderItems()) {
int childQuantity = child.getQuantity();
childQuantity = childQuantity / previousQty;
child.setQuantity(childQuantity * orderItemRequestDTO.getQuantity());
}
// Update any additional attributes of the passed in request
if (itemFromOrder instanceof DiscreteOrderItem) {
DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) itemFromOrder;
discreteOrderItem.getAdditionalAttributes().putAll(orderItemRequestDTO.getAdditionalAttributes());
}
request.setOrderItem(itemFromOrder);
}
return context;
}
use of org.broadleafcommerce.core.order.service.exception.ItemNotFoundException in project BroadleafCommerce by BroadleafCommerce.
the class LegacyCartServiceImpl method updateItemQuantity.
@Override
public Order updateItemQuantity(Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws UpdateCartException {
try {
Order order = findOrderById(orderId);
updateItemQuantity(order, orderItemRequestDTO);
return order;
} catch (PricingException e) {
throw new UpdateCartException("Could not update cart", e);
} catch (ItemNotFoundException e) {
throw new UpdateCartException("Could not update cart", e);
}
}
Aggregations