Search in sources :

Example 41 with DiscreteOrderItem

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

the class FulfillmentGroupServiceImpl method removeOrderItemFromFullfillmentGroups.

@Override
@Transactional("blTransactionManager")
public void removeOrderItemFromFullfillmentGroups(Order order, OrderItem orderItem) {
    List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
    for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
        Iterator<FulfillmentGroupItem> itr = fulfillmentGroup.getFulfillmentGroupItems().iterator();
        while (itr.hasNext()) {
            FulfillmentGroupItem fulfillmentGroupItem = itr.next();
            if (fulfillmentGroupItem.getOrderItem().equals(orderItem)) {
                itr.remove();
                fulfillmentGroupItemDao.delete(fulfillmentGroupItem);
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
                    if (fulfillmentGroupItem.getOrderItem().equals(discreteOrderItem)) {
                        itr.remove();
                        fulfillmentGroupItemDao.delete(fulfillmentGroupItem);
                        break;
                    }
                }
            }
        }
    }
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with DiscreteOrderItem

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

the class FulfillmentGroupServiceImpl method getFulfillmentGroupItemsForOrderItem.

@Override
public List<FulfillmentGroupItem> getFulfillmentGroupItemsForOrderItem(Order order, OrderItem orderItem) {
    List<FulfillmentGroupItem> fgis = new ArrayList<FulfillmentGroupItem>();
    List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
    for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
        for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
            if (fulfillmentGroupItem.getOrderItem().equals(orderItem)) {
                fgis.add(fulfillmentGroupItem);
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
                    if (fulfillmentGroupItem.getOrderItem().equals(discreteOrderItem)) {
                        fgis.add(fulfillmentGroupItem);
                        break;
                    }
                }
            }
        }
    }
    return fgis;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 43 with DiscreteOrderItem

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

the class FulfillmentGroupServiceImpl method matchFulfillmentGroupsToMultishipOptions.

@Override
@Transactional("blTransactionManager")
public Order matchFulfillmentGroupsToMultishipOptions(Order order, boolean priceOrder) throws PricingException {
    List<OrderMultishipOption> multishipOptions = orderMultishipOptionService.findOrderMultishipOptions(order.getId());
    // Build map of fulfillmentGroupItemId --> FulfillmentGroupItem.quantity
    // Also build map of addressId:fulfillmentOptionId --> FulfillmentGroup
    Map<Long, Integer> fgItemQuantityMap = new HashMap<Long, Integer>();
    Map<String, FulfillmentGroup> multishipGroups = new HashMap<String, FulfillmentGroup>();
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        if (!isShippable(fg.getType())) {
            continue;
        }
        String key = getKey(fg.getAddress(), fg.getFulfillmentOption(), fg.getType());
        multishipGroups.put(key, fg);
        for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
            fgItemQuantityMap.put(fgi.getId(), fgi.getQuantity());
        }
    }
    for (OrderMultishipOption option : multishipOptions) {
        String key = getKey(option.getAddress(), option.getFulfillmentOption(), ((DiscreteOrderItem) option.getOrderItem()).getSku().getFulfillmentType());
        FulfillmentGroup fg = multishipGroups.get(key);
        // Get or create a fulfillment group that matches this OrderMultishipOption destination
        if (fg == null) {
            FulfillmentGroupRequest fgr = new FulfillmentGroupRequest();
            fgr.setOrder(order);
            if (option.getAddress() != null) {
                fgr.setAddress(option.getAddress());
            }
            if (option.getFulfillmentOption() != null) {
                fgr.setOption(option.getFulfillmentOption());
            }
            fgr.setFulfillmentType(((DiscreteOrderItem) option.getOrderItem()).getSku().getFulfillmentType());
            fg = addFulfillmentGroupToOrder(fgr, false);
            fg = save(fg);
            order.getFulfillmentGroups().add(fg);
        }
        // See if there is a fulfillment group item that matches this OrderMultishipOption
        // OrderItem request
        FulfillmentGroupItem fulfillmentGroupItem = null;
        for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
            if (fgi.getOrderItem().getId().equals(option.getOrderItem().getId())) {
                fulfillmentGroupItem = fgi;
            }
        }
        // If there is no matching fulfillment group item, create a new one with quantity 1
        if (fulfillmentGroupItem == null) {
            fulfillmentGroupItem = fulfillmentGroupItemDao.create();
            fulfillmentGroupItem.setFulfillmentGroup(fg);
            fulfillmentGroupItem.setOrderItem(option.getOrderItem());
            fulfillmentGroupItem.setQuantity(1);
            fulfillmentGroupItem = fulfillmentGroupItemDao.save(fulfillmentGroupItem);
            fg.getFulfillmentGroupItems().add(fulfillmentGroupItem);
        } else {
            // (fulfillmentGroupItem.getId() == null)
            if (fulfillmentGroupItem.getId() != null) {
                Integer qty = fgItemQuantityMap.get(fulfillmentGroupItem.getId());
                if (qty == null || qty == 0) {
                    fulfillmentGroupItem.setQuantity(fulfillmentGroupItem.getQuantity() + 1);
                } else {
                    qty -= 1;
                    fgItemQuantityMap.put(fulfillmentGroupItem.getId(), qty);
                }
            } else {
                fulfillmentGroupItem.setQuantity(fulfillmentGroupItem.getQuantity() + 1);
            }
        }
        multishipGroups.put(key, fg);
    }
    // Furthermore, delete the empty fulfillment groups.
    for (Entry<Long, Integer> entry : fgItemQuantityMap.entrySet()) {
        if (entry.getValue() > 0) {
            FulfillmentGroupItem fgi = fulfillmentGroupItemDao.readFulfillmentGroupItemById(entry.getKey());
            if (fgi.getQuantity() == entry.getValue()) {
                FulfillmentGroup fg = fgi.getFulfillmentGroup();
                fg.getFulfillmentGroupItems().remove(fgi);
                fulfillmentGroupItemDao.delete(fgi);
                if (fg.getFulfillmentGroupItems().size() == 0) {
                    order.getFulfillmentGroups().remove(fg);
                    fulfillmentGroupDao.delete(fg);
                }
            } else {
                fgi.setQuantity(fgi.getQuantity() - entry.getValue());
                fulfillmentGroupItemDao.save(fgi);
            }
        }
    }
    return orderService.save(order, priceOrder);
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) HashMap(java.util.HashMap) FulfillmentGroupRequest(org.broadleafcommerce.core.order.service.call.FulfillmentGroupRequest) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with DiscreteOrderItem

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

the class MergeCartServiceImpl method reconstructCart.

@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException, RemoveFromCartException {
    ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
    Order customerCart = orderService.findCartForCustomerWithEnhancements(customer);
    if (customerCart != null) {
        List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof DiscreteOrderItem) {
                DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
                if (!checkActive(doi) || !checkInventory(doi) || !checkOtherValidity(orderItem)) {
                    itemsToRemove.add(orderItem);
                }
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                for (DiscreteOrderItem doi : bundleOrderItem.getDiscreteOrderItems()) {
                    if (!checkActive(doi) || !checkInventory(doi) || !checkOtherValidity(orderItem)) {
                        itemsToRemove.add(doi.getBundleOrderItem());
                    }
                }
            }
        }
        // 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) {
            orderService.removeItem(customerCart.getId(), item.getId(), false);
        }
        reconstructCartResponse.setRemovedItems(itemsToRemove);
        customerCart = orderService.save(customerCart, priceOrder);
    }
    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 45 with DiscreteOrderItem

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

the class OrderItemServiceImpl method createDiscreteOrderItem.

@Override
public DiscreteOrderItem createDiscreteOrderItem(final DiscreteOrderItemRequest itemRequest) {
    final DiscreteOrderItem item = (DiscreteOrderItem) orderItemDao.create(OrderItemType.DISCRETE);
    populateDiscreteOrderItem(item, itemRequest);
    item.setBundleOrderItem(itemRequest.getBundleOrderItem());
    if (itemRequest.getSalePriceOverride() != null) {
        item.setBaseSalePrice(itemRequest.getSalePriceOverride());
    }
    item.setDiscreteOrderItemFeePrices(itemRequest.getDiscreteOrderItemFeePrices());
    if (itemRequest.getSalePriceOverride() != null) {
        item.setSalePriceOverride(Boolean.TRUE);
        item.setSalePrice(itemRequest.getSalePriceOverride());
        item.setBaseSalePrice(itemRequest.getSalePriceOverride());
    }
    if (itemRequest.getRetailPriceOverride() != null) {
        item.setRetailPriceOverride(Boolean.TRUE);
        item.setRetailPrice(itemRequest.getRetailPriceOverride());
        item.setBaseRetailPrice(itemRequest.getRetailPriceOverride());
    }
    for (DiscreteOrderItemFeePrice feePrice : item.getDiscreteOrderItemFeePrices()) {
        feePrice.setDiscreteOrderItem(item);
    }
    if (MapUtils.isNotEmpty(itemRequest.getAdditionalAttributes())) {
        item.setAdditionalAttributes(itemRequest.getAdditionalAttributes());
    }
    item.setPersonalMessage(itemRequest.getPersonalMessage());
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) DiscreteOrderItemFeePrice(org.broadleafcommerce.core.order.domain.DiscreteOrderItemFeePrice)

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