use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafProductController method handleRequest.
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView();
Product product = (Product) request.getAttribute(ProductHandlerMapping.CURRENT_PRODUCT_ATTRIBUTE_NAME);
assert (product != null);
model.addObject(MODEL_ATTRIBUTE_NAME, product);
model.addObject(PAGE_TYPE_ATTRIBUTE_NAME, "product");
// Build the add to cart request and add it to the page
ConfigurableOrderItemRequest itemRequest = orderItemService.createConfigurableOrderItemRequestFromProduct(product);
orderItemService.modifyOrderItemRequest(itemRequest);
model.addObject(CONFIGURATION_ATTRIBUTE_NAME, itemRequest);
model.addObject(ALL_PRODUCTS_ATTRIBUTE_NAME, orderItemService.findAllProductsInRequest(itemRequest));
addDeepLink(model, deepLinkService, product);
String templatePath;
// Use the products custom template if available
if (StringUtils.isNotBlank(product.getDisplayTemplate())) {
templatePath = product.getDisplayTemplate();
} else {
// Otherwise, use the controller default.
templatePath = getDefaultProductView();
}
// Allow extension managers to override.
ExtensionResultHolder<String> erh = new ExtensionResultHolder<String>();
ExtensionResultStatusType extResult = templateOverrideManager.getProxy().getOverrideTemplate(erh, product);
if (extResult != ExtensionResultStatusType.NOT_HANDLED) {
templatePath = erh.getResult();
}
model.setViewName(templatePath);
// Check if this is request to edit an existing order item
String isEditRequest = request.getParameter("edit");
String oidParam = request.getParameter("oid");
if (StringUtils.isNotEmpty(isEditRequest) && StringUtils.isNotEmpty(oidParam)) {
Long oid = Long.parseLong(oidParam);
OrderItem orderItem = orderItemService.readOrderItemById(oid);
if (orderItemBelongsToCurrentCustomer(orderItem)) {
// Update the itemRequest to contain user's previous input
orderItemService.mergeOrderItemRequest(itemRequest, orderItem);
// Add the order item to the model
model.addObject("isUpdateRequest", true);
model.addObject("orderItem", orderItem);
}
}
return model;
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class OrderServiceImpl method findCartForCustomerWithEnhancements.
@Override
public Order findCartForCustomerWithEnhancements(Customer customer) {
ExtensionResultHolder<Order> erh = new ExtensionResultHolder<Order>();
ExtensionResultStatusType resultStatusType = extensionManager.findCartForCustomerWithEnhancements(customer, erh);
if (ExtensionResultStatusType.NOT_HANDLED != resultStatusType) {
return erh.getResult();
}
return findCartForCustomer(customer);
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class OrderServiceImpl method preValidateCartOperation.
@Override
public void preValidateCartOperation(Order cart) {
ExtensionResultHolder erh = new ExtensionResultHolder();
extensionManager.getProxy().preValidateCartOperation(cart, erh);
if (erh.getThrowable() instanceof IllegalCartOperationException) {
throw ((IllegalCartOperationException) erh.getThrowable());
} else if (erh.getThrowable() != null) {
throw new RuntimeException(erh.getThrowable());
}
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class OrderServiceImpl method preValidateUpdateQuantityOperation.
@Override
public void preValidateUpdateQuantityOperation(Order cart, OrderItemRequestDTO dto) {
ExtensionResultHolder erh = new ExtensionResultHolder();
extensionManager.getProxy().preValidateUpdateQuantityOperation(cart, dto, erh);
if (erh.getThrowable() instanceof IllegalCartOperationException) {
throw ((IllegalCartOperationException) erh.getThrowable());
} else if (erh.getThrowable() != null) {
throw new RuntimeException(erh.getThrowable());
}
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class PageServiceImpl method findPageByURI.
/*
* Retrieve the page if one is available for the passed in uri.
*/
@Override
public PageDTO findPageByURI(Locale locale, String uri, Map<String, Object> ruleDTOs, boolean secure) {
final List<PageDTO> returnList = getPageDTOListForURI(locale, uri, secure);
PageDTO dto = evaluatePageRules(returnList, locale, ruleDTOs);
if (dto.getId() != null) {
final Page page = findPageById(dto.getId());
final ExtensionResultHolder<PageDTO> newDTO = new ExtensionResultHolder<>();
// Allow an extension point to override the page to render.
extensionManager.getProxy().overridePageDto(newDTO, dto, page);
if (newDTO.getResult() != null) {
dto = newDTO.getResult();
}
}
if (dto != null) {
dto = pageServiceUtility.hydrateForeignLookups(dto);
}
return dto;
}
Aggregations