Search in sources :

Example 41 with ExtensionResultHolder

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;
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ModelAndView(org.springframework.web.servlet.ModelAndView) Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 42 with ExtensionResultHolder

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);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 43 with ExtensionResultHolder

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());
    }
}
Also used : IllegalCartOperationException(org.broadleafcommerce.core.order.service.exception.IllegalCartOperationException) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 44 with ExtensionResultHolder

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());
    }
}
Also used : IllegalCartOperationException(org.broadleafcommerce.core.order.service.exception.IllegalCartOperationException) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 45 with ExtensionResultHolder

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;
}
Also used : NullPageDTO(org.broadleafcommerce.common.page.dto.NullPageDTO) PageDTO(org.broadleafcommerce.common.page.dto.PageDTO) Page(org.broadleafcommerce.cms.page.domain.Page) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Aggregations

ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)56 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)35 ArrayList (java.util.ArrayList)11 Product (org.broadleafcommerce.core.catalog.domain.Product)7 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)6 ParentEntityPersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.ParentEntityPersistenceException)5 FieldNotAvailableException (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException)5 List (java.util.List)4 Set (java.util.Set)4 File (java.io.File)3 Serializable (java.io.Serializable)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)3 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)3 Site (org.broadleafcommerce.common.site.domain.Site)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3