Search in sources :

Example 16 with OrderItemRequestDTO

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

the class BroadleafCartController method isSafeToAdd.

protected boolean isSafeToAdd(ConfigurableOrderItemRequest itemRequest) {
    if (!automaticallyAddCompleteItems) {
        return false;
    }
    boolean canSafelyAdd = true;
    for (OrderItemRequestDTO child : itemRequest.getChildOrderItems()) {
        ConfigurableOrderItemRequest configurableRequest = (ConfigurableOrderItemRequest) child;
        Product childProduct = configurableRequest.getProduct();
        if (childProduct == null) {
            return false;
        }
        int minQty = configurableRequest.getMinQuantity();
        if (minQty == 0 || childProduct.getProductOptionXrefs().size() > 0) {
            return false;
        }
        canSafelyAdd = isSafeToAdd(configurableRequest);
    }
    return canSafelyAdd;
}
Also used : OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) Product(org.broadleafcommerce.core.catalog.domain.Product) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 17 with OrderItemRequestDTO

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

the class OrderItemServiceImpl method findAllChildProductsInRequest.

protected Set<Product> findAllChildProductsInRequest(List<OrderItemRequestDTO> childItems) {
    Set<Product> allProductsSet = new HashSet<Product>();
    for (OrderItemRequestDTO child : childItems) {
        ConfigurableOrderItemRequest configChild = (ConfigurableOrderItemRequest) child;
        Product childProduct = configChild.getProduct();
        if (childProduct != null) {
            allProductsSet.add(childProduct);
        } else {
            List<OrderItemRequestDTO> productChoices = new ArrayList<OrderItemRequestDTO>(configChild.getProductChoices());
            allProductsSet.addAll(findAllChildProductsInRequest(productChoices));
        }
    }
    return allProductsSet;
}
Also used : OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) HashSet(java.util.HashSet)

Example 18 with OrderItemRequestDTO

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

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

the class CheckUpdateAvailabilityActivity 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;
    }
    Sku sku;
    Long orderItemId = request.getItemRequest().getOrderItemId();
    OrderItem orderItem = orderItemService.readOrderItemById(orderItemId);
    if (orderItem instanceof DiscreteOrderItem) {
        sku = ((DiscreteOrderItem) orderItem).getSku();
    } else if (orderItem instanceof BundleOrderItem) {
        sku = ((BundleOrderItem) orderItem).getSku();
    } else {
        LOG.warn("Could not check availability; did not recognize passed-in item " + orderItem.getClass().getName());
        return context;
    }
    Order order = context.getSeedData().getOrder();
    Integer requestedQuantity = request.getItemRequest().getQuantity();
    checkSkuAvailability(order, sku, requestedQuantity);
    Integer previousQty = orderItem.getQuantity();
    for (OrderItem child : orderItem.getChildOrderItems()) {
        Sku childSku = ((DiscreteOrderItem) child).getSku();
        Integer childQuantity = child.getQuantity();
        childQuantity = childQuantity / previousQty;
        checkSkuAvailability(order, childSku, childQuantity * requestedQuantity);
    }
    return context;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 20 with OrderItemRequestDTO

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

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