Search in sources :

Example 6 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class CheckAddAvailabilityActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
        return context;
    }
    // No order item, this must be a new item add request
    Long skuId = request.getItemRequest().getSkuId();
    Sku sku = catalogService.findSkuById(skuId);
    Order order = context.getSeedData().getOrder();
    Integer requestedQuantity = request.getItemRequest().getQuantity();
    checkSkuAvailability(order, sku, requestedQuantity);
    return context;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 7 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO 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 8 with OrderItemRequestDTO

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

Example 9 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO 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 10 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderBaseTest method setUpCartWithActiveSku.

public Order setUpCartWithActiveSku() throws AddToCartException {
    Customer customer = customerService.saveCustomer(createNamedCustomer());
    Order order = orderService.createNewCartForCustomer(customer);
    Product newProduct = addTestProduct("Plastic Crate Active", "Crates");
    Category newCategory = newProduct.getDefaultCategory();
    order = orderService.addItem(order.getId(), new OrderItemRequestDTO(newProduct.getId(), newProduct.getDefaultSku().getId(), newCategory.getId(), 1), true);
    return order;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Category(org.broadleafcommerce.core.catalog.domain.Category) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) Customer(org.broadleafcommerce.profile.core.domain.Customer) Product(org.broadleafcommerce.core.catalog.domain.Product)

Aggregations

OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)30 Order (org.broadleafcommerce.core.order.domain.Order)19 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)14 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)13 Transactional (org.springframework.transaction.annotation.Transactional)10 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)9 Product (org.broadleafcommerce.core.catalog.domain.Product)8 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)8 Test (org.testng.annotations.Test)7 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 NonDiscreteOrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)5 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)4 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)4 ArrayList (java.util.ArrayList)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3 ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)3 AddToCartException (org.broadleafcommerce.core.order.service.exception.AddToCartException)3 Customer (org.broadleafcommerce.profile.core.domain.Customer)3 Rollback (org.springframework.test.annotation.Rollback)3 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)2