Search in sources :

Example 1 with ConfigurableOrderItemRequest

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

the class BroadleafCartController method configure.

/**
 * Takes a product id and builds out a dependant order item tree.  If it determines the order
 * item is safe to add, it will proceed to calling the "add" method.
 *
 * If the method was invoked via an AJAX call, it will render the "ajax/configure" template.
 * Otherwise, it will perform a 302 redirect to "/cart/configure"
 *
 * In the case that an "add" happened it will render either the "ajax/cart" or perform a 302
 * redirect to "/cart"
 *
 * @param request
 * @param response
 * @param model
 * @param productId
 * @throws IOException
 * @throws AddToCartException
 * @throws PricingException
 */
public String configure(HttpServletRequest request, HttpServletResponse response, Model model, Long productId) throws IOException, AddToCartException, PricingException, Exception {
    Product product = catalogService.findProductById(productId);
    ConfigurableOrderItemRequest itemRequest = orderItemService.createConfigurableOrderItemRequestFromProduct(product);
    orderItemService.modifyOrderItemRequest(itemRequest);
    // If this item request is safe to add, go ahead and add it.
    if (isSafeToAdd(itemRequest)) {
        return add(request, response, model, itemRequest);
    }
    model.addAttribute("baseItem", itemRequest);
    model.addAttribute("isUpdateRequest", Boolean.TRUE);
    model.addAttribute(ALL_PRODUCTS_ATTRIBUTE_NAME, orderItemService.findAllProductsInRequest(itemRequest));
    return isAjaxRequest(request) ? getConfigureView() : getConfigurePageRedirect();
}
Also used : Product(org.broadleafcommerce.core.catalog.domain.Product) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 2 with ConfigurableOrderItemRequest

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

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

the class BroadleafCartController method reconfigure.

/**
 * Takes an order item id and rebuilds the dependant order item tree with the current quantities and options set.
 *
 * If the method was invoked via an AJAX call, it will render the "ajax/configure" template.
 * Otherwise, it will perform a 302 redirect to "/cart/configure"
 *
 * @param request
 * @param response
 * @param model
 * @param orderItemId
 * @throws IOException
 * @throws AddToCartException
 * @throws PricingException
 */
public String reconfigure(HttpServletRequest request, HttpServletResponse response, Model model, Long orderItemId) throws IOException, AddToCartException, PricingException, Exception {
    DiscreteOrderItem orderItem = (DiscreteOrderItem) orderItemService.readOrderItemById(orderItemId);
    Long productId = orderItem.getProduct().getId();
    Product product = catalogService.findProductById(productId);
    ConfigurableOrderItemRequest itemRequest = orderItemService.createConfigurableOrderItemRequestFromProduct(product);
    orderItemService.modifyOrderItemRequest(itemRequest);
    orderItemService.mergeOrderItemRequest(itemRequest, orderItem);
    // update quantities and product options
    itemRequest.setQuantity(orderItem.getQuantity());
    model.addAttribute("baseItem", itemRequest);
    model.addAttribute("isUpdateRequest", Boolean.TRUE);
    model.addAttribute("originalOrderItem", orderItemId);
    model.addAttribute(ALL_PRODUCTS_ATTRIBUTE_NAME, orderItemService.findAllProductsInRequest(itemRequest));
    return isAjaxRequest(request) ? getConfigureView() : getConfigurePageRedirect();
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Product(org.broadleafcommerce.core.catalog.domain.Product) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 4 with ConfigurableOrderItemRequest

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

the class OrderItemServiceImpl method createConfigurableOrderItemRequestFromProduct.

@Override
public ConfigurableOrderItemRequest createConfigurableOrderItemRequestFromProduct(Product product) {
    ConfigurableOrderItemRequest itemRequest = new ConfigurableOrderItemRequest();
    itemRequest.setProduct(product);
    itemRequest.setSkuId(product.getDefaultSku().getId());
    itemRequest.setQuantity(1);
    itemRequest.setDisplayPrice(product.getDefaultSku().getPrice());
    itemRequest.setDiscountsAllowed(product.getDefaultSku().isDiscountable());
    return itemRequest;
}
Also used : ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 5 with ConfigurableOrderItemRequest

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

Aggregations

ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)8 Product (org.broadleafcommerce.core.catalog.domain.Product)7 NonDiscreteOrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)3 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)3 Sku (org.broadleafcommerce.core.catalog.domain.Sku)2 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)2 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1 Category (org.broadleafcommerce.core.catalog.domain.Category)1 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)1 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)1 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)1 AbstractOrderItemRequest (org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest)1 BundleOrderItemRequest (org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest)1 DiscreteOrderItemRequest (org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest)1 GiftWrapOrderItemRequest (org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest)1 OrderItemRequest (org.broadleafcommerce.core.order.service.call.OrderItemRequest)1