Search in sources :

Example 1 with DiscreteOrderItem

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

the class CheckoutTest method addSampleItemToOrder.

private void addSampleItemToOrder(Order order, FulfillmentGroup group) {
    DiscreteOrderItem item = new DiscreteOrderItemImpl();
    item.setOrder(order);
    item.setQuantity(1);
    Sku newSku = new SkuImpl();
    newSku.setName("Under Armor T-Shirt -- Red");
    newSku.setRetailPrice(new Money(14.99));
    newSku.setActiveStartDate(SystemTime.asDate());
    newSku.setDiscountable(false);
    newSku = catalogService.saveSku(newSku);
    item.setSku(newSku);
    item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
    List<OrderItem> items = new ArrayList<>();
    items.add(item);
    order.setOrderItems(items);
    FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
    fgItem.setFulfillmentGroup(group);
    fgItem.setOrderItem(item);
    fgItem.setQuantity(1);
    // fgItem.setPrice(new Money(0D));
    group.addFulfillmentGroupItem(fgItem);
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) ArrayList(java.util.ArrayList) Sku(org.broadleafcommerce.core.catalog.domain.Sku) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)

Example 2 with DiscreteOrderItem

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

the class OrderMultishipOptionServiceImpl method getOrGenerateOrderMultishipOptions.

@Override
public List<OrderMultishipOption> getOrGenerateOrderMultishipOptions(Order order) {
    List<OrderMultishipOption> orderMultishipOptions = findOrderMultishipOptions(order.getId());
    if (orderMultishipOptions == null || orderMultishipOptions.size() == 0) {
        orderMultishipOptions = generateOrderMultishipOptions(order);
    }
    // Create a map representing the current discrete order item counts for the order
    Map<Long, Integer> orderDiscreteOrderItemCounts = new HashMap<Long, Integer>();
    for (DiscreteOrderItem item : order.getDiscreteOrderItems()) {
        orderDiscreteOrderItemCounts.put(item.getId(), item.getQuantity());
    }
    List<OrderMultishipOption> optionsToRemove = new ArrayList<OrderMultishipOption>();
    for (OrderMultishipOption option : orderMultishipOptions) {
        Integer count = orderDiscreteOrderItemCounts.get(option.getOrderItem().getId());
        if (count == null || count == 0) {
            optionsToRemove.add(option);
        } else {
            count--;
            orderDiscreteOrderItemCounts.put(option.getOrderItem().getId(), count);
        }
    }
    for (Entry<Long, Integer> entry : orderDiscreteOrderItemCounts.entrySet()) {
        DiscreteOrderItem item = (DiscreteOrderItem) orderItemService.readOrderItemById(entry.getKey());
        orderMultishipOptions.addAll(createPopulatedOrderMultishipOption(order, item, entry.getValue()));
    }
    orderMultishipOptions.removeAll(optionsToRemove);
    orderMultishipOptionDao.deleteAll(optionsToRemove);
    return orderMultishipOptions;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption)

Example 3 with DiscreteOrderItem

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

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

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

the class LegacyOrderServiceImpl method bundleItemMatches.

protected boolean bundleItemMatches(BundleOrderItem item1, BundleOrderItem item2) {
    if (item1.getSku() != null && item2.getSku() != null) {
        return item1.getSku().getId().equals(item2.getSku().getId());
    }
    // Otherwise, scan the items.
    HashMap<Long, Integer> skuMap = new HashMap<Long, Integer>();
    for (DiscreteOrderItem item : item1.getDiscreteOrderItems()) {
        if (skuMap.get(item.getSku().getId()) == null) {
            skuMap.put(item.getSku().getId(), Integer.valueOf(item.getQuantity()));
        } else {
            Integer qty = skuMap.get(item.getSku().getId());
            skuMap.put(item.getSku().getId(), Integer.valueOf(qty + item.getQuantity()));
        }
    }
    // Now consume the quantities in the map
    for (DiscreteOrderItem item : item2.getDiscreteOrderItems()) {
        if (skuMap.containsKey(item.getSku().getId())) {
            Integer qty = skuMap.get(item.getSku().getId());
            Integer newQty = Integer.valueOf(qty - item.getQuantity());
            if (newQty.intValue() == 0) {
                skuMap.remove(item.getSku().getId());
            } else if (newQty.intValue() > 0) {
                skuMap.put(item.getSku().getId(), newQty);
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    return skuMap.isEmpty();
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) HashMap(java.util.HashMap)

Aggregations

DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)57 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)30 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)27 Order (org.broadleafcommerce.core.order.domain.Order)19 ArrayList (java.util.ArrayList)18 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)18 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)17 Sku (org.broadleafcommerce.core.catalog.domain.Sku)16 HashMap (java.util.HashMap)11 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)10 Money (org.broadleafcommerce.common.money.Money)9 Product (org.broadleafcommerce.core.catalog.domain.Product)9 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)8 Transactional (org.springframework.transaction.annotation.Transactional)8 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)7 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)7 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)7 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)6 List (java.util.List)5 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)5