Search in sources :

Example 6 with ConfigurableOrderItemRequest

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

the class OrderItemServiceImpl method buildOrderItemFromDTO.

@Override
public OrderItem buildOrderItemFromDTO(Order order, OrderItemRequestDTO orderItemRequestDTO) {
    Sku sku = null;
    if (orderItemRequestDTO.getSkuId() != null) {
        sku = catalogService.findSkuById(orderItemRequestDTO.getSkuId());
    }
    Product product = null;
    if (orderItemRequestDTO.getProductId() != null) {
        product = catalogService.findProductById(orderItemRequestDTO.getProductId());
    }
    Category category = null;
    if (orderItemRequestDTO.getCategoryId() != null) {
        category = catalogService.findCategoryById(orderItemRequestDTO.getCategoryId());
    }
    if (category == null && product != null) {
        category = product.getDefaultCategory();
    }
    OrderItem item;
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
        NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequestDTO;
        OrderItemRequest itemRequest = new OrderItemRequest();
        itemRequest.setQuantity(ndr.getQuantity());
        itemRequest.setRetailPriceOverride(ndr.getOverrideRetailPrice());
        itemRequest.setSalePriceOverride(ndr.getOverrideSalePrice());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setItemName(ndr.getItemName());
        itemRequest.setOrder(order);
        item = createOrderItem(itemRequest);
    } else if (product == null || !(product instanceof ProductBundle)) {
        DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
        itemRequest.setCategory(category);
        itemRequest.setProduct(product);
        itemRequest.setSku(sku);
        itemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setOrder(order);
        itemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        itemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createDiscreteOrderItem(itemRequest);
    } else {
        ProductBundleOrderItemRequest bundleItemRequest = new ProductBundleOrderItemRequest();
        bundleItemRequest.setCategory(category);
        bundleItemRequest.setProductBundle((ProductBundle) product);
        bundleItemRequest.setSku(sku);
        bundleItemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        bundleItemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        bundleItemRequest.setName(product.getName());
        bundleItemRequest.setOrder(order);
        bundleItemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        bundleItemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createBundleOrderItem(bundleItemRequest, false);
    }
    if (orderItemRequestDTO.getParentOrderItemId() != null) {
        OrderItem parent = readOrderItemById(orderItemRequestDTO.getParentOrderItemId());
        item.setParentOrderItem(parent);
    }
    if (orderItemRequestDTO.getHasConfigurationError()) {
        item.setHasValidationError(true);
    }
    if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
        ConfigurableOrderItemRequest configRequest = (ConfigurableOrderItemRequest) orderItemRequestDTO;
        if (configRequest.getHasConfigurationError()) {
            item.setHasValidationError(true);
        }
        if (!configRequest.getDiscountsAllowed()) {
            item.setDiscountingAllowed(false);
        }
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) AbstractOrderItemRequest(org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest) GiftWrapOrderItemRequest(org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest) OrderItemRequest(org.broadleafcommerce.core.order.service.call.OrderItemRequest) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) BundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest) Category(org.broadleafcommerce.core.catalog.domain.Category) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 7 with ConfigurableOrderItemRequest

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

Example 8 with ConfigurableOrderItemRequest

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

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