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();
}
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;
}
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();
}
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;
}
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;
}
Aggregations