Search in sources :

Example 1 with BundleOrderItem

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

the class OrderServiceImpl method removeItem.

@Override
@Transactional(value = "blTransactionManager", rollbackFor = { RemoveFromCartException.class })
public Order removeItem(Long orderId, Long orderItemId, boolean priceOrder) throws RemoveFromCartException {
    preValidateCartOperation(findOrderById(orderId));
    try {
        OrderItem oi = orderItemService.readOrderItemById(orderItemId);
        if (oi == null) {
            throw new WorkflowException(new ItemNotFoundException());
        }
        List<Long> childrenToRemove = new ArrayList<Long>();
        if (oi instanceof BundleOrderItem) {
            List<DiscreteOrderItem> bundledItems = ((BundleOrderItem) oi).getDiscreteOrderItems();
            for (DiscreteOrderItem doi : bundledItems) {
                findAllChildrenToRemove(childrenToRemove, doi);
            }
        } else {
            findAllChildrenToRemove(childrenToRemove, oi);
        }
        for (Long childToRemove : childrenToRemove) {
            removeItemInternal(orderId, childToRemove, false);
        }
        return removeItemInternal(orderId, orderItemId, priceOrder);
    } catch (WorkflowException e) {
        throw new RemoveFromCartException("Could not remove from cart", getCartOperationExceptionRootCause(e));
    }
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) WorkflowException(org.broadleafcommerce.core.workflow.WorkflowException) ArrayList(java.util.ArrayList) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException) RemoveFromCartException(org.broadleafcommerce.core.order.service.exception.RemoveFromCartException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with BundleOrderItem

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

the class LegacyMergeCartServiceImpl method reconstructCart.

@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException {
    ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
    Order customerCart = orderService.findCartForCustomer(customer);
    if (customerCart != null) {
        List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof DiscreteOrderItem) {
                DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
                if (discreteOrderItem.getSku().getActiveStartDate() != null) {
                    if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
                        itemsToRemove.add(orderItem);
                    }
                } else {
                    if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
                        itemsToRemove.add(orderItem);
                    }
                }
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                boolean removeBundle = false;
                for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
                    if (discreteOrderItem.getSku().getActiveStartDate() != null) {
                        if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
                            /*
                                 * Bundle has an inactive item in it -- remove the
                                 * whole bundle
                                 */
                            removeBundle = true;
                            break;
                        }
                    } else {
                        if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
                            removeBundle = true;
                            break;
                        }
                    }
                }
                if (removeBundle) {
                    itemsToRemove.add(orderItem);
                }
            }
        }
        // Remove any giftwrap items who have one or more wrapped item members that have been removed
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof GiftWrapOrderItem) {
                for (OrderItem wrappedItem : ((GiftWrapOrderItem) orderItem).getWrappedItems()) {
                    if (itemsToRemove.contains(wrappedItem)) {
                        itemsToRemove.add(orderItem);
                        break;
                    }
                }
            }
        }
        for (OrderItem item : itemsToRemove) {
            removeItemFromOrder(customerCart, item, priceOrder);
        }
        reconstructCartResponse.setRemovedItems(itemsToRemove);
    }
    reconstructCartResponse.setOrder(customerCart);
    return reconstructCartResponse;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) 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) ArrayList(java.util.ArrayList) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) ReconstructCartResponse(org.broadleafcommerce.core.order.service.call.ReconstructCartResponse)

Example 3 with BundleOrderItem

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

the class LegacyOrderServiceImpl method addBundleItemToOrder.

@Override
public OrderItem addBundleItemToOrder(Order order, BundleOrderItemRequest itemRequest, boolean priceOrder) throws PricingException {
    itemRequest.setOrder(order);
    BundleOrderItem item = orderItemService.createBundleOrderItem(itemRequest);
    return addOrderItemToOrder(order, item, priceOrder);
}
Also used : BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Example 4 with BundleOrderItem

use of org.broadleafcommerce.core.order.domain.BundleOrderItem 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 5 with BundleOrderItem

use of org.broadleafcommerce.core.order.domain.BundleOrderItem 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)

Aggregations

BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)35 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)30 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)23 Order (org.broadleafcommerce.core.order.domain.Order)16 ArrayList (java.util.ArrayList)13 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)10 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)9 Sku (org.broadleafcommerce.core.catalog.domain.Sku)8 HashMap (java.util.HashMap)7 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)5 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Product (org.broadleafcommerce.core.catalog.domain.Product)4 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)4 Test (org.testng.annotations.Test)4 List (java.util.List)3 Money (org.broadleafcommerce.common.money.Money)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3 SkuBundleItem (org.broadleafcommerce.core.catalog.domain.SkuBundleItem)3 BigDecimal (java.math.BigDecimal)2