Search in sources :

Example 46 with DiscreteOrderItem

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

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

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

the class OrderItemServiceImpl method buildOrderItemRequestDTOFromOrderItem.

@Override
public OrderItemRequestDTO buildOrderItemRequestDTOFromOrderItem(OrderItem item) {
    OrderItemRequestDTO orderItemRequest;
    if (item instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) item;
        orderItemRequest = new OrderItemRequestDTO();
        if (doi.getCategory() != null) {
            orderItemRequest.setCategoryId(doi.getCategory().getId());
        }
        if (doi.getProduct() != null) {
            orderItemRequest.setProductId(doi.getProduct().getId());
        }
        if (doi.getSku() != null) {
            orderItemRequest.setSkuId(doi.getSku().getId());
        }
        if (doi.getAdditionalAttributes() != null) {
            for (Entry<String, String> entry : doi.getAdditionalAttributes().entrySet()) {
                orderItemRequest.getAdditionalAttributes().put(entry.getKey(), entry.getValue());
            }
        }
    } else {
        orderItemRequest = new NonDiscreteOrderItemRequestDTO();
        NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequest;
        ndr.setItemName(item.getName());
        ndr.setOverrideRetailPrice(item.getRetailPrice());
        ndr.setOverrideSalePrice(item.getSalePrice());
    }
    orderItemRequest.setQuantity(item.getQuantity());
    if (item.getOrderItemAttributes() != null) {
        for (Entry<String, OrderItemAttribute> entry : item.getOrderItemAttributes().entrySet()) {
            orderItemRequest.getItemAttributes().put(entry.getKey(), entry.getValue().getValue());
        }
    }
    if (CollectionUtils.isNotEmpty(item.getChildOrderItems())) {
        for (OrderItem childItem : item.getChildOrderItems()) {
            orderItemRequest.getChildOrderItems().add(buildOrderItemRequestDTOFromOrderItem(childItem));
        }
    }
    return orderItemRequest;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) 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)

Example 49 with DiscreteOrderItem

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

the class OrderItemServiceImpl method createDiscreteOrderItem.

public DiscreteOrderItem createDiscreteOrderItem(final AbstractOrderItemRequest itemRequest) {
    final DiscreteOrderItem item = (DiscreteOrderItem) orderItemDao.create(OrderItemType.DISCRETE);
    populateDiscreteOrderItem(item, itemRequest);
    item.setBaseSalePrice(itemRequest.getSku().getSalePrice());
    item.setBaseRetailPrice(itemRequest.getSku().getRetailPrice());
    // item.updatePrices();
    item.updateSaleAndRetailPrices();
    item.assignFinalPrice();
    item.setPersonalMessage(itemRequest.getPersonalMessage());
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem)

Example 50 with DiscreteOrderItem

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

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