Search in sources :

Example 11 with CartOperationRequest

use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.

the class ValidateUpdateRequestActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    // Throw an exception if the user did not specify an orderItemId
    if (orderItemRequestDTO.getOrderItemId() == null) {
        throw new IllegalArgumentException("OrderItemId must be specified when removing from order");
    }
    // Throw an exception if the user tried to update an item to a negative quantity
    if (orderItemRequestDTO.getQuantity() < 0) {
        throw new IllegalArgumentException("Quantity cannot be negative");
    }
    // Throw an exception if the user did not specify an order to add the item to
    if (request.getOrder() == null) {
        throw new IllegalArgumentException("Order is required when updating item quantities");
    }
    // Throw an exception if the user is trying to update an order item that is part of a bundle
    OrderItem orderItem = orderItemService.readOrderItemById(orderItemRequestDTO.getOrderItemId());
    if (orderItem != null && orderItem instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
        if (doi.getBundleOrderItem() != null) {
            throw new IllegalArgumentException("Cannot update an item that is part of a bundle");
        }
    }
    return context;
}
Also used : 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)

Example 12 with CartOperationRequest

use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.

the class UpdateProductOptionsOrderItemActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    Order order = request.getOrder();
    if (orderItemService.readOrderItemById(Long.valueOf(orderItemRequestDTO.getOrderItemId())) != null) {
        DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        orderItemService.updateDiscreteOrderItem(orderItemService.readOrderItemById(Long.valueOf(orderItemRequestDTO.getOrderItemId())), itemRequest);
    }
    order = orderService.save(order, false);
    request.setOrder(order);
    return context;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest)

Example 13 with CartOperationRequest

use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.

the class ValidateAddRequestActivity method validate.

protected ProcessContext<CartOperationRequest> validate(ProcessContext<CartOperationRequest> context) {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    Integer orderItemQuantity = orderItemRequestDTO.getQuantity();
    if (!hasQuantity(orderItemQuantity)) {
        context.stopProcess();
    } else if (orderItemQuantity < 0) {
        throw new IllegalArgumentException("Quantity cannot be negative");
    } else if (request.getOrder() == null) {
        throw new IllegalArgumentException("Order is required when adding item to order");
    } else {
        Product product = determineProduct(orderItemRequestDTO);
        Sku sku;
        try {
            sku = determineSku(product, orderItemRequestDTO.getSkuId(), orderItemRequestDTO.getItemAttributes(), (ActivityMessages) context);
        } catch (RequiredAttributeNotProvidedException e) {
            if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
                // Mark the request as a configuration error and proceed with the add.
                orderItemRequestDTO.setHasConfigurationError(Boolean.TRUE);
                return context;
            }
            throw e;
        }
        addSkuToCart(sku, orderItemRequestDTO, product, request);
        if (!hasSameCurrency(orderItemRequestDTO, request, sku)) {
            throw new IllegalArgumentException("Cannot have items with differing currencies in one cart");
        }
        validateIfParentOrderItemExists(orderItemRequestDTO);
    }
    return context;
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) ActivityMessages(org.broadleafcommerce.core.workflow.ActivityMessages) Product(org.broadleafcommerce.core.catalog.domain.Product) RequiredAttributeNotProvidedException(org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 14 with CartOperationRequest

use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.

the class UpdateFulfillmentGroupItemActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    request = fgItemStrategy.onItemUpdated(request);
    context.setSeedData(request);
    return context;
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)

Example 15 with CartOperationRequest

use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest 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)

Aggregations

CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)18 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)9 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)9 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 Order (org.broadleafcommerce.core.order.domain.Order)5 FlushMode (org.hibernate.FlushMode)4 Session (org.hibernate.Session)4 UpdateCartException (org.broadleafcommerce.core.order.service.exception.UpdateCartException)3 WorkflowException (org.broadleafcommerce.core.workflow.WorkflowException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)2 ArrayList (java.util.ArrayList)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 Sku (org.broadleafcommerce.core.catalog.domain.Sku)1 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)1 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)1 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)1 ActivityMessageDTO (org.broadleafcommerce.core.order.service.call.ActivityMessageDTO)1 ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)1 DiscreteOrderItemRequest (org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest)1