Search in sources :

Example 6 with SkuBundleItem

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

Aggregations

SkuBundleItem (org.broadleafcommerce.core.catalog.domain.SkuBundleItem)6 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)4 Sku (org.broadleafcommerce.core.catalog.domain.Sku)4 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)4 Product (org.broadleafcommerce.core.catalog.domain.Product)3 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)3 ArrayList (java.util.ArrayList)2 Category (org.broadleafcommerce.core.catalog.domain.Category)2 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 Money (org.broadleafcommerce.common.money.Money)1 ProductOptionValue (org.broadleafcommerce.core.catalog.domain.ProductOptionValue)1 SkuBundleItemImpl (org.broadleafcommerce.core.catalog.domain.SkuBundleItemImpl)1 SkuProductOptionValueXref (org.broadleafcommerce.core.catalog.domain.SkuProductOptionValueXref)1 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)1 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)1 Order (org.broadleafcommerce.core.order.domain.Order)1