Search in sources :

Example 16 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class LegacyOrderServiceImpl method updateItemQuantity.

@Override
public void updateItemQuantity(Order order, OrderItemRequestDTO orderItemRequestDTO) throws ItemNotFoundException, PricingException {
    OrderItem orderItem = null;
    for (DiscreteOrderItem doi : order.getDiscreteOrderItems()) {
        if (doi.getId().equals(orderItemRequestDTO.getOrderItemId())) {
            orderItem = doi;
        }
    }
    orderItem.setQuantity(orderItemRequestDTO.getQuantity());
    updateItemQuantity(order, orderItem, true);
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Example 17 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class LegacyOrderServiceImpl method addItemToOrder.

@Override
public Order addItemToOrder(Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws PricingException {
    if (orderItemRequestDTO.getQuantity() == null || orderItemRequestDTO.getQuantity() == 0) {
        LOG.debug("Not adding item to order because quantity is zero.");
        return null;
    }
    if (orderItemRequestDTO.getQuantity() < 0) {
        throw new IllegalArgumentException("Quantity cannot be negative");
    }
    Order order = validateOrder(orderId);
    Product product = validateProduct(orderItemRequestDTO.getProductId());
    Sku sku = determineSku(product, orderItemRequestDTO.getSkuId(), orderItemRequestDTO.getItemAttributes());
    if (sku == null) {
        return null;
    }
    Category category = determineCategory(product, orderItemRequestDTO.getCategoryId());
    if (product == null || !(product instanceof ProductBundle)) {
        DiscreteOrderItem item = orderItemService.createDiscreteOrderItem(createDiscreteOrderItemRequest(order, null, sku, product, category, orderItemRequestDTO.getQuantity(), orderItemRequestDTO.getItemAttributes()));
        item.setOrder(order);
        List<OrderItem> orderItems = order.getOrderItems();
        orderItems.add(item);
        return updateOrder(order, priceOrder);
    } else {
        ProductBundle bundle = (ProductBundle) product;
        BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItemDao.create(OrderItemType.BUNDLE);
        bundleOrderItem.setQuantity(orderItemRequestDTO.getQuantity());
        bundleOrderItem.setCategory(category);
        bundleOrderItem.setSku(sku);
        bundleOrderItem.setName(product.getName());
        bundleOrderItem.setProductBundle(bundle);
        bundleOrderItem.setOrder(order);
        for (SkuBundleItem skuBundleItem : bundle.getSkuBundleItems()) {
            Product bundleProduct = skuBundleItem.getBundle();
            Sku bundleSku = skuBundleItem.getSku();
            Category bundleCategory = determineCategory(bundleProduct, orderItemRequestDTO.getCategoryId());
            DiscreteOrderItem bundleDiscreteItem = orderItemService.createDiscreteOrderItem(createDiscreteOrderItemRequest(null, bundleOrderItem, bundleSku, bundleProduct, bundleCategory, skuBundleItem.getQuantity(), orderItemRequestDTO.getItemAttributes()));
            bundleDiscreteItem.setBundleOrderItem(bundleOrderItem);
            bundleDiscreteItem.setSkuBundleItem(skuBundleItem);
            bundleOrderItem.getDiscreteOrderItems().add(bundleDiscreteItem);
        }
        List<OrderItem> orderItems = order.getOrderItems();
        orderItems.add(bundleOrderItem);
        return updateOrder(order, priceOrder);
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Category(org.broadleafcommerce.core.catalog.domain.Category) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 18 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class ValidateUpdateProductOptionsRequestActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    // Throw an exception if the user did not specify an orderItemId
    if (orderItemRequestDTO.getOrderItemId() == null) {
        throw new IllegalArgumentException("OrderItemId must be specified to locate the order item");
    }
    // Throw an exception if the user did not specify an order to add the item to
    if (request.getOrder() == null) {
        throw new IllegalArgumentException("Order is required when updating items in the order");
    }
    // Throw an exception if the user is trying to update an order item that is part of a bundle
    OrderItem orderItem = orderItemService.readOrderItemById(orderItemRequestDTO.getOrderItemId());
    if (orderItem != null && orderItem instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
        if (doi.getBundleOrderItem() != null) {
        // then its ok , since we are just updating the product options
        }
    }
    return context;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem)

Example 19 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentGroupItemStrategyImpl method onItemUpdated.

@Override
public CartOperationRequest onItemUpdated(CartOperationRequest request) throws PricingException {
    Order order = request.getOrder();
    OrderItem orderItem = request.getOrderItem();
    Integer orderItemQuantityDelta = request.getOrderItemQuantityDelta();
    if (orderItemQuantityDelta == 0) {
        // If the quantity didn't change, nothing needs to happen
        return request;
    } else {
        List<FulfillmentGroupItem> fgisToDelete = new ArrayList<FulfillmentGroupItem>();
        if (orderItem instanceof BundleOrderItem) {
            List<OrderItem> itemsToUpdate = new ArrayList<OrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
            for (OrderItem oi : itemsToUpdate) {
                int quantityPer = oi.getQuantity();
                fgisToDelete.addAll(updateItemQuantity(order, oi, (quantityPer * orderItemQuantityDelta)));
            }
        } else {
            fgisToDelete.addAll(updateItemQuantity(order, orderItem, orderItemQuantityDelta));
            List<OrderItem> itemsToUpdate = new ArrayList<>(orderItem.getChildOrderItems());
            for (OrderItem oi : itemsToUpdate) {
                int quantityPer = oi.getQuantity() / orderItem.getQuantity();
                fgisToDelete.addAll(updateItemQuantity(order, oi, (quantityPer * orderItemQuantityDelta)));
            }
        }
        request.setFgisToDelete(fgisToDelete);
    }
    return request;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) ArrayList(java.util.ArrayList)

Example 20 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentGroupItemStrategyImpl method onItemAdded.

@Override
public CartOperationRequest onItemAdded(CartOperationRequest request) throws PricingException {
    Order order = request.getOrder();
    OrderItem orderItem = request.getOrderItem();
    Map<FulfillmentType, FulfillmentGroup> fulfillmentGroups = new HashMap<FulfillmentType, FulfillmentGroup>();
    FulfillmentGroup nullFulfillmentTypeGroup = null;
    // We'll use the first of each type that we find. Implementors can choose to move groups / items around later.
    if (order.getFulfillmentGroups() != null) {
        for (FulfillmentGroup group : order.getFulfillmentGroups()) {
            if (group.getType() == null) {
                if (nullFulfillmentTypeGroup == null) {
                    nullFulfillmentTypeGroup = group;
                }
            } else {
                if (fulfillmentGroups.get(group.getType()) == null) {
                    fulfillmentGroups.put(group.getType(), group);
                }
            }
        }
    }
    if (orderItem instanceof BundleOrderItem) {
        // We only care about the discrete order items
        List<DiscreteOrderItem> itemsToAdd = new ArrayList<DiscreteOrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
        for (DiscreteOrderItem doi : itemsToAdd) {
            FulfillmentGroup fulfillmentGroup = null;
            FulfillmentType type = resolveFulfillmentType(doi);
            if (type == null) {
                // Use the fulfillment group with a null type
                fulfillmentGroup = nullFulfillmentTypeGroup;
            } else {
                if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
                    // This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
                    // However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
                    type = FulfillmentType.PHYSICAL_SHIP;
                }
                // Use the fulfillment group with the specified type
                fulfillmentGroup = fulfillmentGroups.get(type);
            }
            // If the null type or specified type, above were null, then we need to create a new fulfillment group
            boolean createdFulfillmentGroup = false;
            if (fulfillmentGroup == null) {
                fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
                // Set the type
                fulfillmentGroup.setType(type);
                fulfillmentGroup.setOrder(order);
                order.getFulfillmentGroups().add(fulfillmentGroup);
                createdFulfillmentGroup = true;
            }
            fulfillmentGroup = addItemToFulfillmentGroup(order, doi, doi.getQuantity() * orderItem.getQuantity(), fulfillmentGroup);
            order = fulfillmentGroup.getOrder();
            // of fulfillment groups
            if (createdFulfillmentGroup) {
                if (type == null) {
                    nullFulfillmentTypeGroup = fulfillmentGroup;
                } else {
                    fulfillmentGroups.put(type, fulfillmentGroup);
                }
            }
        }
    } else if (orderItem instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
        FulfillmentGroup fulfillmentGroup = null;
        FulfillmentType type = resolveFulfillmentType(doi);
        if (type == null) {
            // Use the fulfillment group with a null type
            fulfillmentGroup = nullFulfillmentTypeGroup;
        } else {
            if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
                // This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
                // However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
                type = FulfillmentType.PHYSICAL_SHIP;
            }
            // Use the fulfillment group with the specified type
            fulfillmentGroup = fulfillmentGroups.get(type);
        }
        // If the null type or specified type, above were null, then we need to create a new fulfillment group
        if (fulfillmentGroup == null) {
            fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
            // Set the type
            fulfillmentGroup.setType(type);
            fulfillmentGroup.setOrder(order);
            order.getFulfillmentGroups().add(fulfillmentGroup);
        }
        fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
        order = fulfillmentGroup.getOrder();
    } else {
        FulfillmentGroup fulfillmentGroup = nullFulfillmentTypeGroup;
        if (fulfillmentGroup == null) {
            fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
            fulfillmentGroup.setOrder(order);
            order.getFulfillmentGroups().add(fulfillmentGroup);
        }
        fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
    }
    return request;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) HashMap(java.util.HashMap) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentType(org.broadleafcommerce.core.order.service.type.FulfillmentType)

Aggregations

OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)100 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)69 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)54 Order (org.broadleafcommerce.core.order.domain.Order)46 ArrayList (java.util.ArrayList)32 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)23 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)20 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)19 Transactional (org.springframework.transaction.annotation.Transactional)19 Test (org.testng.annotations.Test)16 Money (org.broadleafcommerce.common.money.Money)13 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)13 HashMap (java.util.HashMap)11 Sku (org.broadleafcommerce.core.catalog.domain.Sku)10 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)9 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 BigDecimal (java.math.BigDecimal)5 ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)5 List (java.util.List)4 Product (org.broadleafcommerce.core.catalog.domain.Product)4