Search in sources :

Example 26 with BundleOrderItem

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

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

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

the class OrderItemServiceImpl method createBundleOrderItem.

@Override
public BundleOrderItem createBundleOrderItem(final ProductBundleOrderItemRequest itemRequest, boolean saveItem) {
    ProductBundle productBundle = itemRequest.getProductBundle();
    BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItemDao.create(OrderItemType.BUNDLE);
    bundleOrderItem.setQuantity(itemRequest.getQuantity());
    bundleOrderItem.setCategory(itemRequest.getCategory());
    bundleOrderItem.setSku(itemRequest.getSku());
    bundleOrderItem.setName(itemRequest.getName());
    bundleOrderItem.setProductBundle(productBundle);
    bundleOrderItem.setOrder(itemRequest.getOrder());
    if (itemRequest.getSalePriceOverride() != null) {
        bundleOrderItem.setSalePriceOverride(Boolean.TRUE);
        bundleOrderItem.setSalePrice(itemRequest.getSalePriceOverride());
        bundleOrderItem.setBaseSalePrice(itemRequest.getSalePriceOverride());
    }
    if (itemRequest.getRetailPriceOverride() != null) {
        bundleOrderItem.setRetailPriceOverride(Boolean.TRUE);
        bundleOrderItem.setRetailPrice(itemRequest.getRetailPriceOverride());
        bundleOrderItem.setBaseRetailPrice(itemRequest.getRetailPriceOverride());
    }
    for (SkuBundleItem skuBundleItem : productBundle.getSkuBundleItems()) {
        Product bundleProduct = skuBundleItem.getBundle();
        Sku bundleSku = skuBundleItem.getSku();
        Category bundleCategory = null;
        if (itemRequest.getCategory() != null) {
            bundleCategory = itemRequest.getCategory();
        }
        if (bundleCategory == null && bundleProduct != null) {
            bundleCategory = bundleProduct.getDefaultCategory();
        }
        DiscreteOrderItemRequest bundleItemRequest = new DiscreteOrderItemRequest();
        bundleItemRequest.setCategory(bundleCategory);
        bundleItemRequest.setProduct(bundleProduct);
        bundleItemRequest.setQuantity(skuBundleItem.getQuantity());
        bundleItemRequest.setSku(bundleSku);
        bundleItemRequest.setItemAttributes(itemRequest.getItemAttributes());
        bundleItemRequest.setSalePriceOverride(skuBundleItem.getSalePrice());
        bundleItemRequest.setBundleOrderItem(bundleOrderItem);
        DiscreteOrderItem bundleDiscreteItem = createDiscreteOrderItem(bundleItemRequest);
        bundleDiscreteItem.setSkuBundleItem(skuBundleItem);
        bundleOrderItem.getDiscreteOrderItems().add(bundleDiscreteItem);
    }
    if (saveItem) {
        bundleOrderItem = (BundleOrderItem) saveOrderItem(bundleOrderItem);
    }
    applyAdditionalOrderItemProperties(bundleOrderItem);
    return bundleOrderItem;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Category(org.broadleafcommerce.core.catalog.domain.Category) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 29 with BundleOrderItem

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

the class OrderItemServiceImpl method createBundleOrderItem.

@Override
public BundleOrderItem createBundleOrderItem(final BundleOrderItemRequest itemRequest) {
    final BundleOrderItem item = (BundleOrderItem) orderItemDao.create(OrderItemType.BUNDLE);
    item.setQuantity(itemRequest.getQuantity());
    item.setCategory(itemRequest.getCategory());
    item.setName(itemRequest.getName());
    item.setBundleOrderItemFeePrices(itemRequest.getBundleOrderItemFeePrices());
    item.setOrder(itemRequest.getOrder());
    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 (DiscreteOrderItemRequest discreteItemRequest : itemRequest.getDiscreteOrderItems()) {
        discreteItemRequest.setBundleOrderItem(item);
        DiscreteOrderItem discreteOrderItem;
        if (discreteItemRequest instanceof GiftWrapOrderItemRequest) {
            discreteOrderItem = createGiftWrapOrderItem((GiftWrapOrderItemRequest) discreteItemRequest);
        } else {
            discreteOrderItem = createDiscreteOrderItem(discreteItemRequest);
        }
        item.getDiscreteOrderItems().add(discreteOrderItem);
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) GiftWrapOrderItemRequest(org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest)

Example 30 with BundleOrderItem

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

the class OrderItemServiceImpl method updateDiscreteOrderItem.

@Override
public OrderItem updateDiscreteOrderItem(OrderItem item, final DiscreteOrderItemRequest itemRequest) {
    List<ProductOption> productOptions = null;
    if (item instanceof DiscreteOrderItem) {
        productOptions = ((DiscreteOrderItem) item).getProduct().getProductOptions();
    } else if (item instanceof BundleOrderItem) {
        productOptions = ((BundleOrderItem) item).getProduct().getProductOptions();
    }
    List<String> removeKeys = new ArrayList<String>();
    if (productOptions != null && itemRequest.getItemAttributes() != null) {
        for (String name : itemRequest.getItemAttributes().keySet()) {
            // if  option.getProductOptionValidationType()  is null then it might change the sku, so we dont allow those
            for (ProductOption option : productOptions) {
                if (option.getAttributeName().equals(name) && option.getProductOptionValidationStrategyType() == null) {
                    removeKeys.add(name);
                    break;
                }
            }
        }
    }
    for (String name : removeKeys) {
        itemRequest.getItemAttributes().remove(name);
    }
    populateProductOptionAttributes(item, itemRequest.getItemAttributes());
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : ProductOption(org.broadleafcommerce.core.catalog.domain.ProductOption) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) 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