Search in sources :

Example 1 with ItemNotFoundException

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));
    }
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) WorkflowException(org.broadleafcommerce.core.workflow.WorkflowException) ArrayList(java.util.ArrayList) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException) RemoveFromCartException(org.broadleafcommerce.core.order.service.exception.RemoveFromCartException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ItemNotFoundException

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);
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Example 3 with ItemNotFoundException

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;
    }
}
Also used : OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Example 4 with ItemNotFoundException

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;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Example 5 with ItemNotFoundException

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);
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) UpdateCartException(org.broadleafcommerce.core.order.service.exception.UpdateCartException) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Aggregations

ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)6 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)5 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)4 Order (org.broadleafcommerce.core.order.domain.Order)2 OrderItemAttribute (org.broadleafcommerce.core.order.domain.OrderItemAttribute)2 ArrayList (java.util.ArrayList)1 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)1 OrderItemAttributeImpl (org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)1 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)1 RemoveFromCartException (org.broadleafcommerce.core.order.service.exception.RemoveFromCartException)1 UpdateCartException (org.broadleafcommerce.core.order.service.exception.UpdateCartException)1 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)1 PricingException (org.broadleafcommerce.core.pricing.service.exception.PricingException)1 WorkflowException (org.broadleafcommerce.core.workflow.WorkflowException)1 Transactional (org.springframework.transaction.annotation.Transactional)1