Search in sources :

Example 21 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentGroupItemStrategyImpl method onItemRemoved.

@Override
public CartOperationRequest onItemRemoved(CartOperationRequest request) {
    Order order = request.getOrder();
    OrderItem orderItem = request.getOrderItem();
    if (orderItem instanceof BundleOrderItem) {
        List<OrderItem> itemsToRemove = new ArrayList<OrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
        for (OrderItem oi : itemsToRemove) {
            request.getFgisToDelete().addAll(fulfillmentGroupService.getFulfillmentGroupItemsForOrderItem(order, oi));
        }
    } else {
        request.getFgisToDelete().addAll(fulfillmentGroupService.getFulfillmentGroupItemsForOrderItem(order, orderItem));
    }
    return request;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ArrayList(java.util.ArrayList)

Example 22 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class AddOrderItemActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    // Order has been verified in a previous activity -- the values in the request can be trusted
    Order order = request.getOrder();
    // Build the order item
    OrderItem item = orderItemService.buildOrderItemFromDTO(order, orderItemRequestDTO);
    // Check for special pricing
    orderItemService.priceOrderItem(item);
    order.getOrderItems().add(item);
    request.setOrderItem(item);
    genericEntityDao.persist(item);
    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) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem)

Example 23 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class RemoveOrderItemActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItem orderItem = request.getOrderItem();
    removeItemAndChildren(request.getOisToDelete(), orderItem);
    return context;
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem)

Example 24 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class RemoveOrderMultishipOptionActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    Long orderItemId = request.getItemRequest().getOrderItemId();
    OrderItem orderItem = request.getOrderItem();
    if (orderItem instanceof BundleOrderItem) {
        for (OrderItem discrete : ((BundleOrderItem) orderItem).getDiscreteOrderItems()) {
            request.getMultishipOptionsToDelete().add(new Long[] { discrete.getId(), null });
        }
    } else {
        request.getMultishipOptionsToDelete().add(new Long[] { orderItemId, null });
    }
    return context;
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Example 25 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class ValidateRemoveRequestActivity 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 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 remove an order item that is part of a bundle
    OrderItem orderItem = null;
    for (OrderItem oi : request.getOrder().getOrderItems()) {
        if (oi.getId().equals(orderItemRequestDTO.getOrderItemId())) {
            orderItem = oi;
        }
    }
    if (orderItem == null) {
        throw new IllegalArgumentException("Could not find order item to remove");
    }
    if (orderItem != null && orderItem instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
        if (doi.getBundleOrderItem() != null) {
            throw new IllegalArgumentException("Cannot remove an item that is part of a bundle");
        }
    }
    request.setOrderItem(orderItem);
    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)

Aggregations

OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)100 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)69 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)54 Order (org.broadleafcommerce.core.order.domain.Order)46 ArrayList (java.util.ArrayList)32 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)23 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)20 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)19 Transactional (org.springframework.transaction.annotation.Transactional)19 Test (org.testng.annotations.Test)16 Money (org.broadleafcommerce.common.money.Money)13 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)13 HashMap (java.util.HashMap)11 Sku (org.broadleafcommerce.core.catalog.domain.Sku)10 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)9 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 BigDecimal (java.math.BigDecimal)5 ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)5 List (java.util.List)4 Product (org.broadleafcommerce.core.catalog.domain.Product)4