Search in sources :

Example 1 with NonDiscreteOrderItemRequestDTO

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

the class CheckAddAvailabilityActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
        return context;
    }
    // No order item, this must be a new item add request
    Long skuId = request.getItemRequest().getSkuId();
    Sku sku = catalogService.findSkuById(skuId);
    Order order = context.getSeedData().getOrder();
    Integer requestedQuantity = request.getItemRequest().getQuantity();
    checkSkuAvailability(order, sku, requestedQuantity);
    return context;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 2 with NonDiscreteOrderItemRequestDTO

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

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

the class CheckUpdateAvailabilityActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
        return context;
    }
    Sku sku;
    Long orderItemId = request.getItemRequest().getOrderItemId();
    OrderItem orderItem = orderItemService.readOrderItemById(orderItemId);
    if (orderItem instanceof DiscreteOrderItem) {
        sku = ((DiscreteOrderItem) orderItem).getSku();
    } else if (orderItem instanceof BundleOrderItem) {
        sku = ((BundleOrderItem) orderItem).getSku();
    } else {
        LOG.warn("Could not check availability; did not recognize passed-in item " + orderItem.getClass().getName());
        return context;
    }
    Order order = context.getSeedData().getOrder();
    Integer requestedQuantity = request.getItemRequest().getQuantity();
    checkSkuAvailability(order, sku, requestedQuantity);
    Integer previousQty = orderItem.getQuantity();
    for (OrderItem child : orderItem.getChildOrderItems()) {
        Sku childSku = ((DiscreteOrderItem) child).getSku();
        Integer childQuantity = child.getQuantity();
        childQuantity = childQuantity / previousQty;
        checkSkuAvailability(order, childSku, childQuantity * requestedQuantity);
    }
    return context;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 4 with NonDiscreteOrderItemRequestDTO

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

the class ValidateAddRequestActivity method hasSameCurrency.

protected boolean hasSameCurrency(OrderItemRequestDTO orderItemRequestDTO, CartOperationRequest request, Sku sku) {
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO || sku == null || sku.getCurrency() == null) {
        return true;
    } else {
        BroadleafCurrency orderCurrency = request.getOrder().getCurrency();
        BroadleafCurrency skuCurrency = sku.getCurrency();
        return orderCurrency.equals(skuCurrency);
    }
}
Also used : BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)

Example 5 with NonDiscreteOrderItemRequestDTO

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

the class OrderItemServiceImpl method buildOrderItemRequestDTOFromOrderItem.

@Override
public OrderItemRequestDTO buildOrderItemRequestDTOFromOrderItem(OrderItem item) {
    OrderItemRequestDTO orderItemRequest;
    if (item instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) item;
        orderItemRequest = new OrderItemRequestDTO();
        if (doi.getCategory() != null) {
            orderItemRequest.setCategoryId(doi.getCategory().getId());
        }
        if (doi.getProduct() != null) {
            orderItemRequest.setProductId(doi.getProduct().getId());
        }
        if (doi.getSku() != null) {
            orderItemRequest.setSkuId(doi.getSku().getId());
        }
        if (doi.getAdditionalAttributes() != null) {
            for (Entry<String, String> entry : doi.getAdditionalAttributes().entrySet()) {
                orderItemRequest.getAdditionalAttributes().put(entry.getKey(), entry.getValue());
            }
        }
    } else {
        orderItemRequest = new NonDiscreteOrderItemRequestDTO();
        NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequest;
        ndr.setItemName(item.getName());
        ndr.setOverrideRetailPrice(item.getRetailPrice());
        ndr.setOverrideSalePrice(item.getSalePrice());
    }
    orderItemRequest.setQuantity(item.getQuantity());
    if (item.getOrderItemAttributes() != null) {
        for (Entry<String, OrderItemAttribute> entry : item.getOrderItemAttributes().entrySet()) {
            orderItemRequest.getItemAttributes().put(entry.getKey(), entry.getValue().getValue());
        }
    }
    if (CollectionUtils.isNotEmpty(item.getChildOrderItems())) {
        for (OrderItem childItem : item.getChildOrderItems()) {
            orderItemRequest.getChildOrderItems().add(buildOrderItemRequestDTOFromOrderItem(childItem));
        }
    }
    return orderItemRequest;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) 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)

Aggregations

NonDiscreteOrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)5 Sku (org.broadleafcommerce.core.catalog.domain.Sku)3 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)3 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)3 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)3 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)3 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)2 Order (org.broadleafcommerce.core.order.domain.Order)2 BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)1 Category (org.broadleafcommerce.core.catalog.domain.Category)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)1 OrderItemAttribute (org.broadleafcommerce.core.order.domain.OrderItemAttribute)1 AbstractOrderItemRequest (org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest)1 BundleOrderItemRequest (org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest)1 ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)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 ProductBundleOrderItemRequest (org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest)1